|
|
@ -3,7 +3,6 @@ use std::collections::HashMap; |
|
|
|
use std::io::{Read, Write}; |
|
|
|
use std::io::{Read, Write}; |
|
|
|
use std::net::{IpAddr, SocketAddr}; |
|
|
|
use std::net::{IpAddr, SocketAddr}; |
|
|
|
use std::path::{Path, PathBuf}; |
|
|
|
use std::path::{Path, PathBuf}; |
|
|
|
use std::sync::atomic::Ordering; |
|
|
|
|
|
|
|
use std::sync::{Arc, RwLock}; |
|
|
|
use std::sync::{Arc, RwLock}; |
|
|
|
use std::time::{Duration, Instant}; |
|
|
|
use std::time::{Duration, Instant}; |
|
|
|
|
|
|
|
|
|
|
@ -198,6 +197,20 @@ pub fn read_node_id(metadata_dir: &Path) -> Result<NodeID, Error> { |
|
|
|
Ok(NodeID::from_slice(&key[..]).unwrap()) |
|
|
|
Ok(NodeID::from_slice(&key[..]).unwrap()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(not(windows))] |
|
|
|
|
|
|
|
fn set_private_key_perms(path: &Path) -> Result<(), Error> { |
|
|
|
|
|
|
|
use std::os::unix::fs::PermissionsExt; |
|
|
|
|
|
|
|
let perm = std::fs::Permissions::from_mode(0o600); |
|
|
|
|
|
|
|
std::fs::set_permissions(path, perm)?; |
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(windows)] |
|
|
|
|
|
|
|
fn set_private_key_perms(_path: &Path) -> Result<(), Error> { |
|
|
|
|
|
|
|
// TODO(mediocregopher) figure out how to do this, but it's not strictly necessary
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn gen_node_key(metadata_dir: &Path) -> Result<NodeKey, Error> { |
|
|
|
pub fn gen_node_key(metadata_dir: &Path) -> Result<NodeKey, Error> { |
|
|
|
let mut key_file = metadata_dir.to_path_buf(); |
|
|
|
let mut key_file = metadata_dir.to_path_buf(); |
|
|
|
key_file.push("node_key"); |
|
|
|
key_file.push("node_key"); |
|
|
@ -222,11 +235,8 @@ pub fn gen_node_key(metadata_dir: &Path) -> Result<NodeKey, Error> { |
|
|
|
let (pubkey, key) = ed25519::gen_keypair(); |
|
|
|
let (pubkey, key) = ed25519::gen_keypair(); |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
use std::os::unix::fs::PermissionsExt; |
|
|
|
|
|
|
|
let mut f = std::fs::File::create(key_file.as_path())?; |
|
|
|
let mut f = std::fs::File::create(key_file.as_path())?; |
|
|
|
let mut perm = f.metadata()?.permissions(); |
|
|
|
set_private_key_perms(key_file.as_path())?; |
|
|
|
perm.set_mode(0o600); |
|
|
|
|
|
|
|
std::fs::set_permissions(key_file.as_path(), perm)?; |
|
|
|
|
|
|
|
f.write_all(&key[..])?; |
|
|
|
f.write_all(&key[..])?; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -890,6 +900,18 @@ impl NodeStatus { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(windows)] |
|
|
|
|
|
|
|
fn update_disk_usage( |
|
|
|
|
|
|
|
&mut self, |
|
|
|
|
|
|
|
_meta_dir: &Path, |
|
|
|
|
|
|
|
_data_dir: &DataDirEnum, |
|
|
|
|
|
|
|
_metrics: &SystemMetrics, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
// TODO(mediocregopher) it'd be nice to have this for windows too, but it seems to only be
|
|
|
|
|
|
|
|
// used for OpenTelemetry so it's not a real requirement.
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(not(windows))] |
|
|
|
fn update_disk_usage( |
|
|
|
fn update_disk_usage( |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
meta_dir: &Path, |
|
|
|
meta_dir: &Path, |
|
|
@ -897,6 +919,7 @@ impl NodeStatus { |
|
|
|
metrics: &SystemMetrics, |
|
|
|
metrics: &SystemMetrics, |
|
|
|
) { |
|
|
|
) { |
|
|
|
use nix::sys::statvfs::statvfs; |
|
|
|
use nix::sys::statvfs::statvfs; |
|
|
|
|
|
|
|
use std::sync::atomic::Ordering; |
|
|
|
let mount_avail = |path: &Path| match statvfs(path) { |
|
|
|
let mount_avail = |path: &Path| match statvfs(path) { |
|
|
|
Ok(x) => { |
|
|
|
Ok(x) => { |
|
|
|
let avail = x.blocks_available() as u64 * x.fragment_size() as u64; |
|
|
|
let avail = x.blocks_available() as u64 * x.fragment_size() as u64; |
|
|
|