mirror of
https://github.com/uqbar-dao/nectar.git
synced 2025-01-07 01:56:31 +03:00
move routers into default json file
This commit is contained in:
parent
2780785e6c
commit
d9a6fa8380
@ -9,24 +9,6 @@ use tokio::sync::mpsc;
|
|||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use wasmtime::{Config, Engine, WasmBacktraceDetails};
|
use wasmtime::{Config, Engine, WasmBacktraceDetails};
|
||||||
|
|
||||||
/// TEMP IMPORT, crate::net::?????
|
|
||||||
/// Must be parsed from message pack vector.
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub enum NetActions {
|
|
||||||
KnsUpdate(KnsUpdate),
|
|
||||||
KnsBatchUpdate(Vec<KnsUpdate>),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct KnsUpdate {
|
|
||||||
pub name: String, // actual username / domain name
|
|
||||||
pub owner: String,
|
|
||||||
pub node: String, // hex namehash of node
|
|
||||||
pub public_key: String,
|
|
||||||
pub ip: String,
|
|
||||||
pub port: u16,
|
|
||||||
pub routers: Vec<String>,
|
|
||||||
}
|
|
||||||
use lib::types::core::{self as t, STATE_PROCESS_ID, VFS_PROCESS_ID};
|
use lib::types::core::{self as t, STATE_PROCESS_ID, VFS_PROCESS_ID};
|
||||||
|
|
||||||
/// Manipulate a single process.
|
/// Manipulate a single process.
|
||||||
@ -690,6 +672,7 @@ pub async fn kernel(
|
|||||||
home_directory_path: String,
|
home_directory_path: String,
|
||||||
contract_address: String,
|
contract_address: String,
|
||||||
runtime_extensions: Vec<(t::ProcessId, t::MessageSender, bool)>,
|
runtime_extensions: Vec<(t::ProcessId, t::MessageSender, bool)>,
|
||||||
|
routers: Vec<crate::net::KnsUpdate>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut config = Config::new();
|
let mut config = Config::new();
|
||||||
config.cache_config_load_default().unwrap();
|
config.cache_config_load_default().unwrap();
|
||||||
@ -846,57 +829,6 @@ pub async fn kernel(
|
|||||||
.await
|
.await
|
||||||
.expect("fatal: kernel event loop died");
|
.expect("fatal: kernel event loop died");
|
||||||
// sending hard coded routers into networking for bootstrapped rpc
|
// sending hard coded routers into networking for bootstrapped rpc
|
||||||
let kns_updates = vec![
|
|
||||||
KnsUpdate {
|
|
||||||
name: "default-router-1.os".to_string(),
|
|
||||||
owner: "who?".to_string(),
|
|
||||||
node: "0x".to_string(),
|
|
||||||
public_key: "0xb1b1cf23c89f651aac3e5fd4decb04aa177ab0ec8ce5f1d3877b90bb6f5779db"
|
|
||||||
.to_string(),
|
|
||||||
ip: "147.135.114.167".to_string(),
|
|
||||||
port: 9002,
|
|
||||||
routers: vec![],
|
|
||||||
},
|
|
||||||
KnsUpdate {
|
|
||||||
name: "default-router-2.os".to_string(),
|
|
||||||
owner: "who?".to_string(),
|
|
||||||
node: "0x".to_string(),
|
|
||||||
public_key: "0xab9f1a996db3a4e1dbcd31d765daedeb3af9af4f570c0968463b5be3a7d1e992"
|
|
||||||
.to_string(),
|
|
||||||
ip: "147.135.114.167".to_string(),
|
|
||||||
port: 9003,
|
|
||||||
routers: vec![],
|
|
||||||
},
|
|
||||||
KnsUpdate {
|
|
||||||
name: "default-router-3.os".to_string(),
|
|
||||||
owner: "who?".to_string(),
|
|
||||||
node: "0x".to_string(),
|
|
||||||
public_key: "0x536e30785e64dd0349a697285af365b5ed7c4d300010139261cfc4dbdd5b254b"
|
|
||||||
.to_string(),
|
|
||||||
ip: "147.135.114.167".to_string(),
|
|
||||||
port: 9004,
|
|
||||||
routers: vec![],
|
|
||||||
},
|
|
||||||
// I want to use ben.eth
|
|
||||||
// --rpc-node ben.eth
|
|
||||||
// first index and then change
|
|
||||||
// no-rpc
|
|
||||||
// settings -> rpc from router-01 -> ben.eth
|
|
||||||
KnsUpdate {
|
|
||||||
name: "jugodenaranja.os".to_string(),
|
|
||||||
owner: "who?".to_string(),
|
|
||||||
node: "0x".to_string(),
|
|
||||||
public_key: "0xf8a3e9667756306a0a25894a8cfe053dc9e7f34e6a61b8d65e92b79f77e05dff"
|
|
||||||
.to_string(),
|
|
||||||
ip: "this should not be parsed.".to_string(),
|
|
||||||
port: 0,
|
|
||||||
routers: vec![
|
|
||||||
"0xb35eb347deb896bc3fb6132a07fca1601f83462385ed11e835c24c33ba4ef73d".to_string(),
|
|
||||||
"0xd827ae579fafa604af79fbed977e8abe048497f10885c6473dfd343a3b7b4458".to_string(),
|
|
||||||
"0x96e36331c8f0882f2c0c46c13b15d812def04fe8606d503bc0e2be39db26486a".to_string(),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
send_to_loop
|
send_to_loop
|
||||||
.send(t::KernelMessage {
|
.send(t::KernelMessage {
|
||||||
id: rand::random(),
|
id: rand::random(),
|
||||||
@ -912,7 +844,7 @@ pub async fn kernel(
|
|||||||
message: t::Message::Request(t::Request {
|
message: t::Message::Request(t::Request {
|
||||||
inherit: false,
|
inherit: false,
|
||||||
expects_response: None,
|
expects_response: None,
|
||||||
body: rmp_serde::to_vec(&NetActions::KnsBatchUpdate(kns_updates)).unwrap(),
|
body: rmp_serde::to_vec(&crate::net::NetActions::KnsBatchUpdate(routers)).unwrap(),
|
||||||
metadata: None,
|
metadata: None,
|
||||||
capabilities: vec![],
|
capabilities: vec![],
|
||||||
}),
|
}),
|
||||||
|
@ -24,7 +24,7 @@ mod state;
|
|||||||
mod terminal;
|
mod terminal;
|
||||||
mod timer;
|
mod timer;
|
||||||
mod vfs;
|
mod vfs;
|
||||||
//
|
|
||||||
const EVENT_LOOP_CHANNEL_CAPACITY: usize = 10_000;
|
const EVENT_LOOP_CHANNEL_CAPACITY: usize = 10_000;
|
||||||
const EVENT_LOOP_DEBUG_CHANNEL_CAPACITY: usize = 50;
|
const EVENT_LOOP_DEBUG_CHANNEL_CAPACITY: usize = 50;
|
||||||
const TERMINAL_CHANNEL_CAPACITY: usize = 32;
|
const TERMINAL_CHANNEL_CAPACITY: usize = 32;
|
||||||
@ -45,6 +45,9 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|||||||
#[cfg(not(feature = "simulation-mode"))]
|
#[cfg(not(feature = "simulation-mode"))]
|
||||||
const REVEAL_IP: bool = true;
|
const REVEAL_IP: bool = true;
|
||||||
|
|
||||||
|
/// default routers as a fallbac
|
||||||
|
const DEFAULT_ROUTERS: &str = include_str!("../default_routers.json");
|
||||||
|
|
||||||
async fn serve_register_fe(
|
async fn serve_register_fe(
|
||||||
home_directory_path: &str,
|
home_directory_path: &str,
|
||||||
our_ip: String,
|
our_ip: String,
|
||||||
@ -384,6 +387,24 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// read in default routers .json file
|
||||||
|
type KnsUpdate = crate::net::KnsUpdate;
|
||||||
|
let routers: Vec<KnsUpdate> =
|
||||||
|
match fs::read_to_string(format!("{}/.routers", home_directory_path)).await {
|
||||||
|
Ok(contents) => serde_json::from_str(&contents).unwrap(),
|
||||||
|
Err(_) => {
|
||||||
|
let routers: Vec<KnsUpdate> = serde_json::from_str(DEFAULT_ROUTERS).unwrap();
|
||||||
|
// should we dump them into a .routers file?
|
||||||
|
// fs::write(
|
||||||
|
// format!("{}/.routers", home_directory_path),
|
||||||
|
// serde_json::to_string(&routers).unwrap(),
|
||||||
|
// )
|
||||||
|
// .await
|
||||||
|
// .unwrap();
|
||||||
|
routers
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// the boolean flag determines whether the runtime module is *public* or not,
|
// the boolean flag determines whether the runtime module is *public* or not,
|
||||||
// where public means that any process can always message it.
|
// where public means that any process can always message it.
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
@ -464,6 +485,7 @@ async fn main() {
|
|||||||
home_directory_path.clone(),
|
home_directory_path.clone(),
|
||||||
contract_address.to_string(),
|
contract_address.to_string(),
|
||||||
runtime_extensions,
|
runtime_extensions,
|
||||||
|
routers,
|
||||||
));
|
));
|
||||||
#[cfg(not(feature = "simulation-mode"))]
|
#[cfg(not(feature = "simulation-mode"))]
|
||||||
tasks.spawn(net::networking(
|
tasks.spawn(net::networking(
|
||||||
|
@ -19,7 +19,7 @@ mod types;
|
|||||||
#[cfg(not(feature = "simulation-mode"))]
|
#[cfg(not(feature = "simulation-mode"))]
|
||||||
mod utils;
|
mod utils;
|
||||||
#[cfg(not(feature = "simulation-mode"))]
|
#[cfg(not(feature = "simulation-mode"))]
|
||||||
use crate::net::{types::*, utils::*};
|
pub use crate::net::{types::*, utils::*};
|
||||||
#[cfg(not(feature = "simulation-mode"))]
|
#[cfg(not(feature = "simulation-mode"))]
|
||||||
use lib::types::core::*;
|
use lib::types::core::*;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user