Some cleanup + sample message sending
This commit is contained in:
+21
-41
@@ -3,13 +3,9 @@ use tokio::runtime::Runtime;
|
||||
use futures::channel::mpsc;
|
||||
use std::time::Duration;
|
||||
use crate::utils;
|
||||
use futures::{StreamExt, SinkExt, Stream, TryStreamExt};
|
||||
use futures::{StreamExt, SinkExt};
|
||||
use crate::clients::mix::MixClient;
|
||||
use sphinx::SphinxPacket;
|
||||
use futures::Future;
|
||||
use futures::future;
|
||||
use futures::task::{Context, Poll};
|
||||
use std::pin::Pin;
|
||||
use futures::select;
|
||||
|
||||
pub mod directory;
|
||||
@@ -47,11 +43,11 @@ impl MixTrafficController {
|
||||
println!("[MIX TRAFFIC CONTROL] - got a mix_message for {:?}", mix_message.0);
|
||||
// here NodeAddressBytes would be transformed into a SocketAddr with SOME library call...
|
||||
let node_net_address = "127.0.0.1:8080";
|
||||
// let send_res = mix_client.send(mix_message.1, node_net_address.parse().unwrap()).await;
|
||||
// match send_res {
|
||||
// Ok(_) => println!("We successfully sent the message!"),
|
||||
// Err(e) => eprintln!("We failed to send the message :( - {:?}", e),
|
||||
// };
|
||||
let send_res = mix_client.send(mix_message.1, node_net_address.parse().unwrap()).await;
|
||||
match send_res {
|
||||
Ok(_) => println!("We successfully sent the message!"),
|
||||
Err(e) => eprintln!("We failed to send the message :( - {:?}", e),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,29 +60,9 @@ pub struct NymClient {
|
||||
input_rx: mpsc::UnboundedReceiver<InputMessage>,
|
||||
}
|
||||
|
||||
type TripleFutureResult = (Result<(), Box<dyn std::error::Error>>, Result<(), Box<dyn std::error::Error>>, Result<(), Box<dyn std::error::Error>>);
|
||||
|
||||
//struct OutQueueFuture {
|
||||
//
|
||||
//}
|
||||
//
|
||||
//impl OutQueueFuture {
|
||||
// fn poll_data(&mut self, cx: &mut Context) -> Poll<()> {
|
||||
// use Poll::*;
|
||||
//
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//impl Future for OutQueueFuture {
|
||||
// type Output = ();
|
||||
//
|
||||
// fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
// unimplemented!()
|
||||
// }
|
||||
//}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InputMessage(Destination, Vec<u8>);
|
||||
pub struct InputMessage(pub Destination, pub Vec<u8>);
|
||||
|
||||
impl NymClient {
|
||||
pub fn new(address: DestinationAddressBytes) -> Self {
|
||||
@@ -127,7 +103,8 @@ impl NymClient {
|
||||
let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier);
|
||||
mix_tx.send(MixMessage(cover_message.0, cover_message.1)).await?;
|
||||
}
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
let delay_duration = Duration::from_secs_f64(MESSAGE_SENDING_AVERAGE_DELAY);
|
||||
tokio::time::delay_for(delay_duration).await;
|
||||
@@ -137,8 +114,8 @@ impl NymClient {
|
||||
|
||||
async fn start_provider_polling() -> Result<(), Box<dyn std::error::Error>> {
|
||||
loop {
|
||||
// println!("here I will be polling provider for messages");
|
||||
let delay_duration = Duration::from_secs_f64(10.0);
|
||||
println!("[FETCH MSG] - Polling provider...");
|
||||
let delay_duration = Duration::from_secs_f64(FETCH_MESSAGES_DELAY);
|
||||
tokio::time::delay_for(delay_duration).await;
|
||||
}
|
||||
}
|
||||
@@ -152,14 +129,14 @@ impl NymClient {
|
||||
let mut rt = Runtime::new()?;
|
||||
rt.spawn(MixTrafficController::run(mix_rx));
|
||||
|
||||
let tmp_dest = Destination::new(self.address, Default::default());
|
||||
let mut foo_tx = self.input_tx.clone();
|
||||
// just to send something after a delay to the input channel
|
||||
let foomp = Destination::new(self.address, Default::default());
|
||||
|
||||
let mut input_channel = self.input_tx.clone();
|
||||
rt.spawn(async move {
|
||||
tokio::time::delay_for(Duration::from_secs(8)).await;
|
||||
let tmp_message = vec![5, 23, 62, 6, 236];
|
||||
println!("SENDING TMP MESSAGE!");
|
||||
foo_tx.send(InputMessage(tmp_dest, tmp_message)).await.unwrap();
|
||||
let test_message = b"foomp".to_vec();
|
||||
let recipient = foomp;
|
||||
let input_message = InputMessage(recipient, test_message);
|
||||
input_channel.send(input_message).await.unwrap();
|
||||
});
|
||||
|
||||
rt.block_on(async {
|
||||
@@ -167,6 +144,9 @@ impl NymClient {
|
||||
NymClient::start_loop_cover_traffic_stream(mix_tx.clone(), Destination::new(self.address, Default::default())),
|
||||
NymClient::control_out_queue(mix_tx, self.input_rx, Destination::new(self.address, Default::default())),
|
||||
NymClient::start_provider_polling()).await;
|
||||
|
||||
// start websocket handler here
|
||||
|
||||
assert!(future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok());
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user