Generated
+1225
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -11,7 +11,8 @@ clap = "2.33.0"
|
||||
curve25519-dalek = "1.2.3"
|
||||
hex = "0.4.0"
|
||||
futures = "0.3.1"
|
||||
nym-client = { path = "../nym-client" }
|
||||
rand = "0.7.2"
|
||||
sfw-provider-requests = { path = "./sfw-provider-requests" }
|
||||
sphinx = { path = "../sphinx" }
|
||||
tokio = { version = "0.2.4", features = ["full"] }
|
||||
tokio = { version = "0.2.4", features = ["full"] }
|
||||
|
||||
+9
-1
@@ -1,9 +1,11 @@
|
||||
use crate::provider::presence;
|
||||
use crate::provider::ServiceProvider;
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
use std::thread;
|
||||
|
||||
mod provider;
|
||||
|
||||
@@ -121,8 +123,14 @@ fn run(matches: &ArgMatches) {
|
||||
client_socket_address
|
||||
);
|
||||
|
||||
// Start sending presence notifications in a separate thread
|
||||
thread::spawn(|| {
|
||||
let notifier = presence::Notifier::new();
|
||||
notifier.run();
|
||||
});
|
||||
|
||||
// make sure our socket_address is equal to our predefined-hardcoded value
|
||||
assert_eq!("127.0.0.1:8081", mix_socket_address.to_string());
|
||||
// assert_eq!("127.0.0.1:8081", mix_socket_address.to_string());
|
||||
|
||||
let provider = ServiceProvider::new(
|
||||
mix_socket_address,
|
||||
|
||||
+3
-9
@@ -13,14 +13,13 @@ use crate::provider::storage::ClientStorage;
|
||||
|
||||
mod client_handling;
|
||||
mod mix_handling;
|
||||
pub mod presence;
|
||||
mod storage;
|
||||
|
||||
|
||||
// TODO: if we ever create config file, this should go there
|
||||
const STORED_MESSAGE_FILENAME_LENGTH: usize = 16;
|
||||
const MESSAGE_RETRIEVAL_LIMIT: usize = 2;
|
||||
|
||||
|
||||
pub struct ServiceProvider {
|
||||
mix_network_address: SocketAddr,
|
||||
client_network_address: SocketAddr,
|
||||
@@ -162,17 +161,16 @@ impl ServiceProvider {
|
||||
futures::future::join(self.start_mixnet_listening(), self.start_client_listening()).await
|
||||
}
|
||||
|
||||
|
||||
pub fn start_listening(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Create the runtime, probably later move it to Provider struct itself?
|
||||
// TODO: figure out the difference between Runtime and Handle
|
||||
let mut rt = Runtime::new()?;
|
||||
// let mut h = rt.handle();
|
||||
// let mut h = rt.handle();
|
||||
|
||||
// Spawn the root task
|
||||
rt.block_on(async {
|
||||
let future_results = self.start_listeners().await;
|
||||
assert!(future_results.0.is_ok() && future_results.1.is_ok())
|
||||
assert!(future_results.0.is_ok() && future_results.1.is_ok());
|
||||
});
|
||||
|
||||
// this line in theory should never be reached as the runtime should be permanently blocked on listeners
|
||||
@@ -180,7 +178,3 @@ impl ServiceProvider {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
use nym_client::clients::directory;
|
||||
use nym_client::clients::directory::DirectoryClient;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use nym_client::clients::directory::presence::MixProviderPresence;
|
||||
|
||||
use nym_client::clients::directory::requests::presence_providers_post::PresenceMixProviderPoster;
|
||||
|
||||
pub struct Notifier {
|
||||
pub net_client: directory::Client,
|
||||
presence: MixProviderPresence,
|
||||
}
|
||||
|
||||
impl Notifier {
|
||||
pub fn new() -> Notifier {
|
||||
let config = directory::Config {
|
||||
base_url: "https://directory.nymtech.net/".to_string(),
|
||||
};
|
||||
let net_client = directory::Client::new(config);
|
||||
let presence = MixProviderPresence {
|
||||
host: "halpin.org:6666".to_string(),
|
||||
pub_key: "superkey".to_string(),
|
||||
registered_clients: vec![],
|
||||
};
|
||||
Notifier {
|
||||
net_client,
|
||||
presence,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn notify(&self) {
|
||||
self.net_client
|
||||
.presence_providers_post
|
||||
.post(&self.presence)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn run(&self) {
|
||||
loop {
|
||||
self.notify();
|
||||
thread::sleep(Duration::from_secs(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user