Merge branch 'main' into hf/towards-a-working-spawn

This commit is contained in:
bitful-pannul 2023-10-11 20:18:45 +03:00
commit 1344984f94
12 changed files with 77 additions and 71 deletions

7
Cargo.lock generated
View File

@ -525,14 +525,16 @@ dependencies = [
[[package]]
name = "chrono"
version = "0.4.30"
version = "0.4.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877"
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"serde",
"wasm-bindgen",
"windows-targets",
]
@ -4829,6 +4831,7 @@ dependencies = [
"bytes",
"cap-std",
"chacha20poly1305",
"chrono",
"cita_trie",
"crossterm",
"digest 0.10.7",

View File

@ -21,6 +21,7 @@ blake3 = "1.4.1"
bytes = "1.4.0"
cap-std = "2.0.0"
chacha20poly1305 = "0.10.1"
chrono = "0.4.31"
cita_trie = "4.0.0"
crossterm = { version = "0.26.1", features = ["event-stream", "bracketed-paste"] }
digest = "0.10"

View File

@ -31,7 +31,7 @@ If you do not receive QNS updates in terminal, it's a sign that the default publ
Also, make sure not to use the same home directory for two nodes at once! You can use any name for the home directory.
```bash
cargo +nightly run --release home
cargo +nightly run --release home --rpc wss://eth-sepolia.g.alchemy.com/v2/<your-api-key>
```
On boot you will be prompted to navigate to `localhost:8080`. Make sure your eth wallet is connected to the Sepolia test network. Login should be very straightforward, just submit the transactions and follow the flow.

View File

@ -526,42 +526,42 @@ impl Guest for Component {
}
};
if !auth_success {
print_to_terminal(1, "http_bindings: failure to authenticate");
let proxy_path = message_json["proxy_path"].as_str();
// if !auth_success {
// print_to_terminal(1, "http_bindings: failure to authenticate");
// let proxy_path = message_json["proxy_path"].as_str();
let redirect_path: String = match proxy_path {
Some(pp) => {
form_urlencoded::byte_serialize(pp.as_bytes()).collect()
}
None => {
form_urlencoded::byte_serialize(path.as_bytes()).collect()
}
};
// let redirect_path: String = match proxy_path {
// Some(pp) => {
// form_urlencoded::byte_serialize(pp.as_bytes()).collect()
// }
// None => {
// form_urlencoded::byte_serialize(path.as_bytes()).collect()
// }
// };
let location = match proxy_path {
Some(_) => format!(
"/http-proxy/serve/{}/login?redirect={}",
&our.node, redirect_path
),
None => format!("/login?redirect={}", redirect_path),
};
// let location = match proxy_path {
// Some(_) => format!(
// "/http-proxy/serve/{}/login?redirect={}",
// &our.node, redirect_path
// ),
// None => format!("/login?redirect={}", redirect_path),
// };
send_http_response(
302,
{
let mut headers = HashMap::new();
headers.insert(
"Content-Type".to_string(),
"text/html".to_string(),
);
headers.insert("Location".to_string(), location);
headers
},
"Auth cookie not valid".as_bytes().to_vec(),
);
continue;
}
// send_http_response(
// 302,
// {
// let mut headers = HashMap::new();
// headers.insert(
// "Content-Type".to_string(),
// "text/html".to_string(),
// );
// headers.insert("Location".to_string(), location);
// headers
// },
// "Auth cookie not valid".as_bytes().to_vec(),
// );
// continue;
// }
}
if bound_path.local_only && !address.starts_with("127.0.0.1:") {

View File

@ -8,6 +8,7 @@ use hex;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::collections::HashMap;
use std::string::FromUtf8Error;
#[allow(dead_code)]
mod process_lib;
@ -259,23 +260,17 @@ impl UqProcess for Component {
// bindings::print_to_terminal(0, format!("qns_indexer: got NodeRegistered event: {:?}", e).as_str());
let node = &e.topics[1];
let decoded =
NodeRegistered::decode_data(&decode_hex_to_vec(&e.data), true)
.unwrap();
let name = dnswire_decode(decoded.0);
// bindings::print_to_terminal(0, format!("qns_indexer: NODE1: {:?}", node).as_str());
// bindings::print_to_terminal(0, format!("qns_indexer: NAME: {:?}", name.to_string()).as_str());
let decoded = NodeRegistered::decode_data(&decode_hex_to_vec(&e.data), true).unwrap();
let Ok(name) = dnswire_decode(decoded.0.clone()) else {
bindings::print_to_terminal(0, &format!("qns_indexer: failed to decode name: {:?}", decoded.0));
continue;
};
state.names.insert(node.to_string(), name);
}
WsChanged::SIGNATURE_HASH => {
// bindings::print_to_terminal(0, format!("qns_indexer: got WsChanged event: {:?}", e).as_str());
let node = &e.topics[1];
// bindings::print_to_terminal(0, format!("qns_indexer: NODE2: {:?}", node.to_string()).as_str());
let decoded =
WsChanged::decode_data(&decode_hex_to_vec(&e.data), true).unwrap();
let decoded = WsChanged::decode_data(&decode_hex_to_vec(&e.data), true).unwrap();
let public_key = hex::encode(decoded.0);
let ip = decoded.1;
let port = decoded.2;
@ -291,12 +286,10 @@ impl UqProcess for Component {
})
.collect::<Vec<String>>();
let name = state.names.get(node).unwrap();
// bindings::print_to_terminal(0, format!("qns_indexer: NAME: {:?}", name).as_str());
// bindings::print_to_terminal(0, format!("qns_indexer: DECODED: {:?}", decoded).as_str());
// bindings::print_to_terminal(0, format!("qns_indexer: PUB KEY: {:?}", public_key).as_str());
// bindings::print_to_terminal(0, format!("qns_indexer: IP PORT: {:?} {:?}", ip, port).as_str());
// bindings::print_to_terminal(0, format!("qns_indexer: ROUTERS: {:?}", routers).as_str());
let Some(name) = state.names.get(node) else {
bindings::print_to_terminal(0, &format!("qns_indexer: failed to find name for node during WsChanged: {:?}", node));
continue;
};
let update = QnsUpdate {
name: name.clone(),
@ -378,7 +371,7 @@ fn hex_to_u64(hex: &str) -> Result<u64, std::num::ParseIntError> {
u64::from_str_radix(without_prefix, 16)
}
fn dnswire_decode(wire_format_bytes: Vec<u8>) -> String {
fn dnswire_decode(wire_format_bytes: Vec<u8>) -> Result<String, FromUtf8Error> {
let mut i = 0;
let mut result = Vec::new();
@ -396,12 +389,12 @@ fn dnswire_decode(wire_format_bytes: Vec<u8>) -> String {
let flat: Vec<_> = result.into_iter().flatten().collect();
let name = String::from_utf8(flat).unwrap();
let name = String::from_utf8(flat)?;
// Remove the trailing '.' if it exists (it should always exist)
if name.ends_with('.') {
name[0..name.len() - 1].to_string()
Ok(name[0..name.len()-1].to_string())
} else {
name
Ok(name)
}
}

View File

@ -1,13 +1,13 @@
{
"files": {
"main.css": "/static/css/main.9b4dbe66.css",
"main.js": "/static/js/main.f54b619d.js",
"main.js": "/static/js/main.321651c6.js",
"index.html": "/index.html",
"main.9b4dbe66.css.map": "/static/css/main.9b4dbe66.css.map",
"main.f54b619d.js.map": "/static/js/main.f54b619d.js.map"
"main.321651c6.js.map": "/static/js/main.321651c6.js.map"
},
"entrypoints": [
"static/css/main.9b4dbe66.css",
"static/js/main.f54b619d.js"
"static/js/main.321651c6.js"
]
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
use crate::types::*;
use anyhow::Result;
use chrono::{Datelike, Local, Timelike};
use crossterm::{
cursor,
event::{
@ -188,7 +189,8 @@ pub async fn terminal(
// aaa
prints = print_rx.recv() => match prints {
Some(printout) => {
let _ = writeln!(log_writer, "{}", printout.content);
let now = Local::now();
let _ = writeln!(log_writer, "{} {}", now.to_rfc2822(), printout.content);
if match printout.verbosity {
0 => false,
1 => !verbose_mode,
@ -200,7 +202,14 @@ pub async fn terminal(
execute!(
stdout,
cursor::MoveTo(0, win_rows - 1),
terminal::Clear(ClearType::CurrentLine)
terminal::Clear(ClearType::CurrentLine),
Print(format!("{} {}/{} {:02}:{:02} ",
now.weekday(),
now.month(),
now.day(),
now.hour(),
now.minute(),
)),
)?;
for line in printout.content.lines() {
execute!(