Merge pull request #65 from uqbar-dao/dr/nits

clean up dirty printouts, update some comments
This commit is contained in:
dr-frmr 2023-11-15 19:55:00 -05:00 committed by GitHub
commit 34155ced40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 41 deletions

View File

@ -51,10 +51,6 @@ const REVEAL_IP: bool = true;
#[tokio::main]
async fn main() {
// For use with https://github.com/tokio-rs/console
// console_subscriber::init();
// DEMO ONLY: remove all CLI arguments
let matches = Command::new("Uqbar")
.version("0.1.0")
.author("Uqbar DAO")
@ -111,13 +107,13 @@ async fn main() {
// encryptor handles end-to-end encryption for client messages
let (encryptor_sender, encryptor_receiver): (MessageSender, MessageReceiver) =
mpsc::channel(ENCRYPTOR_CHANNEL_CAPACITY);
// terminal receives prints via this channel, all other modules send prints
let (print_sender, print_receiver): (PrintSender, PrintReceiver) =
mpsc::channel(TERMINAL_CHANNEL_CAPACITY);
// optional llm extension
#[cfg(feature = "llm")]
let (llm_sender, llm_receiver): (MessageSender, MessageReceiver) =
mpsc::channel(LLM_CHANNEL_CAPACITY);
// terminal receives prints via this channel, all other modules send prints
let (print_sender, print_receiver): (PrintSender, PrintReceiver) =
mpsc::channel(TERMINAL_CHANNEL_CAPACITY);
// fs config in .env file (todo add -- arguments cleanly (with clap?))
dotenv::dotenv().ok();
@ -220,17 +216,10 @@ async fn main() {
} => (our, decoded_keyfile, encoded_keyfile),
};
println!(
"saving encrypted networking keys to {}/.keys",
home_directory_path
);
fs::write(format!("{}/.keys", home_directory_path), encoded_keyfile)
.await
.unwrap();
println!("registration complete!");
// the boolean flag determines whether the runtime module is *public* or not,
// where public means that any process can always message it.
let runtime_extensions = vec![
@ -294,12 +283,6 @@ async fn main() {
.expect("fs load failed!");
let _ = kill_tx.send(true);
let _ = print_sender
.send(Printout {
verbosity: 0,
content: format!("our networking public key: {}", our.networking_key),
})
.await;
/*
* the kernel module will handle our userspace processes and receives

View File

@ -39,6 +39,12 @@ pub async fn networking(
match &our.ws_routing {
None => {
// indirect node: run the indirect networking strategy
print_tx
.send(Printout {
verbosity: 0,
content: "going online as an indirect node".to_string(),
})
.await?;
indirect_networking(
our,
our_ip,
@ -70,6 +76,12 @@ pub async fn networking(
));
}
};
print_tx
.send(Printout {
verbosity: 0,
content: "going online as a direct node".to_string(),
})
.await?;
direct_networking(
our,
our_ip,
@ -106,6 +118,9 @@ async fn indirect_networking(
let mut pending_connections = JoinSet::<(NodeId, Result<()>)>::new();
let mut peer_message_queues = HashMap::<NodeId, Vec<KernelMessage>>::new();
// some initial delay as we wait for QNS data to be piped in from qns_indexer
let mut router_reconnect_delay = std::time::Duration::from_secs(2);
loop {
tokio::select! {
// 1. receive messages from kernel and send out over connections,
@ -190,7 +205,8 @@ async fn indirect_networking(
// 3. periodically attempt to connect to any allowed routers that we
// are not connected to -- TODO do some exponential backoff if a router
// is not responding.
_ = time::sleep(time::Duration::from_secs(5)) => {
_ = time::sleep(router_reconnect_delay) => {
router_reconnect_delay = std::time::Duration::from_secs(4);
tokio::spawn(connect_to_routers(
our.clone(),
our_ip.clone(),

@ -1 +1 @@
Subproject commit 27f49cb6140121049068fb52546527fd79492c6d
Subproject commit 7120168626f4e9b09008844174c63fc30af8711f

View File

@ -282,13 +282,14 @@ async fn handle_boot(
Ok(response)
}
/// this is NOT our real identity info, rather, it is the
/// information used in a possible new node registration.
async fn handle_info(
ip: String,
our_arc: Arc<Mutex<Option<Identity>>>,
networking_keypair_arc: Arc<Mutex<Option<Document>>>,
keyfile_arc: Arc<Mutex<Option<Vec<u8>>>>,
) -> Result<impl Reply, Rejection> {
// 1. Generate networking keys
let (public_key, serialized_networking_keypair) = keygen::generate_networking_key();
*networking_keypair_arc.lock().unwrap() = Some(serialized_networking_keypair);
@ -302,12 +303,9 @@ async fn handle_info(
}
};
// 2. set our...
// TODO: if IP is localhost, assign a router...
// TODO: if IP is localhost, don't allow registration as direct
let ws_port = http_server::find_open_port(9000).await.unwrap();
// this is NOT our real identity. it's stuff we give to the frontend
// to match on
let our = Identity {
networking_key: format!("0x{}", public_key),
name: username,

View File

@ -111,12 +111,13 @@ pub async fn terminal(
terminal::SetTitle(format!("{}@{}", our.name, "uqbar"))
)?;
// print initial splash screen
println!(
"\x1b[38;5;128m{}\x1b[0m",
format_args!(
r#"
let (mut win_cols, mut win_rows) = terminal::size().unwrap();
// print initial splash screen, large if there's room, small otherwise
if win_cols >= 93 {
println!(
"\x1b[38;5;128m{}\x1b[0m",
format_args!(
r#"
,, UU
s# lUL UU !p
!UU lUL UU !UUlb
@ -137,22 +138,42 @@ pub async fn terminal(
`" lUL UU '^ 888 {}
"" 888 version {}
"#,
our.name, version
)
);
networking public key: {}
"#,
our.name, version, our.networking_key,
)
);
} else {
println!(
"\x1b[38;5;128m{}\x1b[0m",
format_args!(
r#"
888
888
888
888 888 .d88888 88888b. 8888b. 888d888
888 888 d88" 888 888 "88b "88b 888P"
888 888 888 888 888 888 .d888888 888
Y88b 888 Y88b 888 888 d88P 888 888 888
"Y88888 "Y88888 88888P" "Y888888 888
888
888 {}
888 version {}
networking pubkey: {}
"#,
our.name, version, our.networking_key,
)
);
}
enable_raw_mode()?;
let mut reader = EventStream::new();
let mut current_line = format!("{} > ", our.name);
let prompt_len: usize = our.name.len() + 3;
let (mut win_cols, mut win_rows) = terminal::size().unwrap();
let mut cursor_col: u16 = prompt_len.try_into().unwrap();
let mut line_col: usize = cursor_col as usize;
let mut in_step_through: bool = false;
// TODO add more verbosity levels as needed?
// defaulting to TRUE for now, as we are BUIDLING
// DEMO: default to false
let mut verbose_mode: bool = false;
let mut search_mode: bool = false;
let mut search_depth: usize = 0;