diff --git a/src/main.rs b/src/main.rs index 5c79d5286d..d456b30431 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,14 +58,9 @@ impl<'a, T> PacketProcessor<'a, T> { async fn wait_and_forward(&self, fwd_data: ForwardingData<'a>) { let delay_duration = Duration::from_nanos(fwd_data.delay.get_value()); - // for now just hardcode some value - let delay_duration = Duration::from_secs(2); - println!("gonna wait 2 seconds!"); + println!("client says to wait for {:?}", delay_duration); tokio::time::delay_for(delay_duration).await; - println!("waited 2 seconds!"); - - -// let task = TokioDelay::new + println!("waited {:?} - time to forward the packet!", delay_duration); match fwd_data.recipient.send(fwd_data.packet.to_bytes()).await { Ok(()) => (), @@ -82,22 +77,10 @@ impl<'a, T> PacketProcessor<'a, T> { _ => return Err(MixProcessingError::ReceivedFinalHopError), }; - let next_mix = MixPeer::new(); - -// let next_mix = MixPeer::new(next_hop_address.to_vec()); + let next_mix = MixPeer::new(next_hop_address); let fwd_data = ForwardingData::new(next_packet, delay, next_mix); Ok(fwd_data) - -// match next_mix.send(next_packet.to_bytes()).await { -// Ok(()) => (), -// Err(e) => { -// println!("failed to write bytes to next mix peer. err = {:?}", e.to_string()); -// return; -// } -// } - - } } @@ -118,16 +101,16 @@ impl MixNode{ - pub fn start_listening(&self) -> Result<(), Box> { + pub fn start_listening(network_address: &str, secret_key: Scalar) -> Result<(), Box> { // Create the runtime let mut rt = Runtime::new()?; // AGAIN TEMPORARY BECAUSE LIFETIMES (and async move) - let secret_key_copy = self.secret_key; +// let secret_key_copy = self.secret_key; // Spawn the root task rt.block_on(async { - let mut listener = tokio::net::TcpListener::bind(self.network_address).await?; + let mut listener = tokio::net::TcpListener::bind(network_address).await?; loop { let (mut socket, _) = listener.accept().await?; @@ -152,7 +135,7 @@ impl MixNode{ // }; let processor = PacketProcessor::<'_,DUMMY_TEMP_TYPE>::new(); - let fwd_data = processor.process_sphinx_data_packet(buf.as_ref(), &secret_key_copy).unwrap(); + let fwd_data = processor.process_sphinx_data_packet(buf.as_ref(), &secret_key).unwrap(); processor.wait_and_forward(fwd_data).await; // // let dummy_address = b"foomp".to_vec(); @@ -186,7 +169,7 @@ impl MixNode{ fn main() { let mix = MixNode::new("127.0.0.1:8080", Default::default()); - mix.start_listening().unwrap(); + MixNode::start_listening(mix.network_address, mix.secret_key).unwrap(); } // //#[tokio::main] diff --git a/src/mix_peer.rs b/src/mix_peer.rs index 3d58d83ffd..53dada08a2 100644 --- a/src/mix_peer.rs +++ b/src/mix_peer.rs @@ -1,7 +1,7 @@ -use tokio::net::TcpStream; -use tokio::prelude::*; use std::error::Error; +use tokio::net::TcpStream; +use tokio::prelude::*; pub struct MixPeer<'a> { connection: &'a str, @@ -11,15 +11,14 @@ impl<'a> MixPeer<'a> { // for now completely ignore data we're sending. // also note that very soon next_hop_address will be changed to next_hop_metadata // pub fn new(nex_hop_address: Vec) -> MixPeer<'a> { - pub fn new() -> MixPeer<'a> { - - let next_hop_address_fixture: &'a str = "127.0.0.1:8081"; + pub fn new(next_hop_address: [u8; 32]) -> MixPeer<'a> { + let next_hop_address_fixture: &'a str = "127.0.0.1:8081"; MixPeer { connection: next_hop_address_fixture, } } - pub async fn send(&self, bytes: Vec) -> Result<(), Box>{ + pub async fn send(&self, bytes: Vec) -> Result<(), Box> { let mut stream = TcpStream::connect(self.connection).await?; stream.write_all(&bytes).await?; Ok(())