Add timeout
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -7,6 +7,7 @@ use rand::SeedableRng;
|
|||||||
use snow::Builder;
|
use snow::Builder;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
|
use std::time::Duration;
|
||||||
use x25519_dalek::PublicKey;
|
use x25519_dalek::PublicKey;
|
||||||
use x25519_dalek::StaticSecret;
|
use x25519_dalek::StaticSecret;
|
||||||
use zerocopy::byteorder::U32;
|
use zerocopy::byteorder::U32;
|
||||||
@@ -101,6 +102,7 @@ fn perform_handshake() -> Result<u128> {
|
|||||||
initiation[116..132].copy_from_slice(&hasher.finalize().into_bytes());
|
initiation[116..132].copy_from_slice(&hasher.finalize().into_bytes());
|
||||||
|
|
||||||
let socket = UdpSocket::bind("0.0.0.0:0")?;
|
let socket = UdpSocket::bind("0.0.0.0:0")?;
|
||||||
|
socket.set_read_timeout(Some(Duration::from_millis(100)))?;
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|
||||||
@@ -127,12 +129,19 @@ struct Record {
|
|||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let mut wtr = csv::Writer::from_writer(io::stdout());
|
let mut wtr = csv::Writer::from_writer(io::stdout());
|
||||||
|
let mut i = 0;
|
||||||
|
|
||||||
for _ in 0..SAMPLE_SIZE {
|
while i < SAMPLE_SIZE {
|
||||||
wtr.serialize(Record {
|
match perform_handshake() {
|
||||||
time: SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs(),
|
Ok(duration) => {
|
||||||
duration: perform_handshake()?,
|
wtr.serialize(Record {
|
||||||
})?;
|
time: SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs(),
|
||||||
|
duration,
|
||||||
|
})?;
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
_ => continue,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wtr.flush()?;
|
wtr.flush()?;
|
||||||
|
|||||||
Reference in New Issue
Block a user