Sending continuous stream of packets in a loop.

This commit is contained in:
Dave Hrycyszyn
2019-12-02 13:50:57 +00:00
parent 92eb260313
commit bea04cf738
+21 -12
View File
@@ -4,24 +4,33 @@ use tokio::prelude::*;
use crate::clients::mix::MixClient;
use crate::clients::directory::DirectoryClient;
use std::time::{ Duration};
use tokio::time::{interval_at, Instant};
#[tokio::main]
async fn main() {
let message = "Hello, Sphinx!".as_bytes().to_vec();
let start = Instant::now() + Duration::from_nanos(1000);
let mut interval = interval_at(start, Duration::from_nanos(1000));
let mut i = 0;
loop {
interval.tick().await;
let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec();
// set up the route
let directory = DirectoryClient::new();
let route = directory.get_mixes();
let destination = directory.get_destination();
let delays = sphinx::header::delays::generate(2);
// set up the route
let directory = DirectoryClient::new();
let route = directory.get_mixes();
let destination = directory.get_destination();
let delays = sphinx::header::delays::generate(2);
// build the packet
let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap();
// build the packet
let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap();
// send to mixnet
let mix_client = MixClient::new();
let result = mix_client.send(packet, route.first().unwrap()).await;
println!("packet sent");
// send to mixnet
let mix_client = MixClient::new();
let result = mix_client.send(packet, route.first().unwrap()).await;
println!("packet sent: {:?}", i);
i += 1;
}
}