dnetview/ util: added missing file

This commit is contained in:
lunar-mining
2022-04-26 18:31:29 +02:00
parent fcbc935fd9
commit f741f02a60
4 changed files with 54 additions and 5 deletions

50
bin/dnetview/src/util.rs Normal file
View File

@@ -0,0 +1,50 @@
use crate::model::Session;
use darkfi::{util::serial, Result};
use rand::{thread_rng, Rng};
pub fn make_node_id(node_name: &String) -> Result<String> {
Ok(serial::serialize_hex(node_name))
}
pub fn make_session_id(node_id: String, session: &Session) -> Result<String> {
let mut num = 0_u64;
match session {
Session::Inbound => {
for i in ['i', 'n'] {
num += i as u64;
}
}
Session::Outbound => {
for i in ['o', 'u', 't'] {
num += i as u64;
}
}
Session::Manual => {
for i in ['m', 'a', 'n'] {
num += i as u64;
}
}
}
for i in node_id.chars() {
num += i as u64
}
Ok(serial::serialize_hex(&num))
}
pub fn make_connect_id(id: u64) -> Result<String> {
Ok(serial::serialize_hex(&id))
}
// we use a random id for empty connections
pub fn generate_id() -> Result<String> {
let mut rng = thread_rng();
let id: u32 = rng.gen();
Ok(serial::serialize_hex(&id))
}
//pub fn is_empty_outbound(slots: Vec<Slot>) -> bool {
// return slots.iter().all(|slot| slot.is_empty);
//}

View File

@@ -63,7 +63,7 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
let rpc_listener_taks =
executor_cloned.spawn(listen_and_serve(server_config, rpc_interface, executor.clone()));
let net_settings = settings.net;
let net_settings = settings.net;
//
//Raft

View File

@@ -29,4 +29,3 @@ pub struct Args {
#[structopt(short, parse(from_occurrences))]
pub verbose: u8,
}

View File

@@ -46,7 +46,7 @@ impl Default for Settings {
pub struct SettingsOpt {
/// P2P accept address
#[structopt(long = "accept")]
pub inbound: Option<SocketAddr>,
pub inbound: Option<SocketAddr>,
/// Connection slots
#[structopt(long = "slots", default_value = "0")]
@@ -56,11 +56,11 @@ pub struct SettingsOpt {
#[structopt(long)]
pub external_addr: Option<SocketAddr>,
/// Peer nodes to connect to
/// Peer nodes to connect to
#[structopt(long)]
pub peers: Vec<SocketAddr>,
/// Seed nodes to connect to
/// Seed nodes to connect to
#[structopt(long)]
pub seeds: Vec<SocketAddr>,