-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: implment 3 connection cookie formats
- Loading branch information
Showing
27 changed files
with
836 additions
and
855 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
/.idea/ | ||
/config.toml | ||
/data.db | ||
/.vscode/launch.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"cSpell.words": [ | ||
"byteorder", | ||
"hasher", | ||
"leechers", | ||
"nanos", | ||
"rngs", | ||
"Seedable", | ||
"thiserror", | ||
"torrust", | ||
"typenum" | ||
], | ||
"[rust]": { | ||
"editor.defaultFormatter": "matklad.rust-analyzer", // Makes the magic | ||
"editor.formatOnSave": false // Optional | ||
}, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,74 @@ | ||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; | ||
use aquatic_udp_protocol::ConnectionId; | ||
use criterion::{Criterion, criterion_group, criterion_main}; | ||
use torrust_tracker::{udp::connection_id::get_connection_id, protocol::clock::current_timestamp}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}; | ||
use std::time::Duration; | ||
|
||
use torrust_tracker::protocol::clock::{DefaultClock, Clock}; | ||
use torrust_tracker::udp::connection::client_image::{Create, KeyedImage, PlainImage, PlainHash}; | ||
use torrust_tracker::udp::connection::connection_cookie::{ | ||
ConnectionCookie, EncryptedCookie, HashedCookie, WitnessCookie, | ||
}; | ||
|
||
fn get_connection_id_old(current_time: u64, port: u16) -> ConnectionId { | ||
let time_i64 = (current_time / 3600) as i64; | ||
|
||
ConnectionId((time_i64 | port as i64) << 36) | ||
} | ||
|
||
pub fn benchmark_generate_id_with_time_and_port(bench: &mut Criterion) { | ||
pub fn benchmark_make_old_unencoded_id(bench: &mut Criterion) { | ||
let remote_address = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 117); | ||
let current_time = current_timestamp(); | ||
let current_time = DefaultClock::now(); | ||
|
||
bench.bench_function("benchmark_make_old_unencoded_id", |b| { | ||
b.iter(|| { | ||
// Inner closure, the actual test | ||
let _ = get_connection_id_old(current_time.into(), remote_address.port()); | ||
}) | ||
}); | ||
} | ||
|
||
pub fn benchmark_make_hashed_encoded_id(bench: &mut Criterion) { | ||
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); | ||
|
||
bench.bench_function("benchmark_make_hashed_encoded_id", |b| { | ||
b.iter(|| { | ||
// Inner closure, the actual test | ||
let client_image = KeyedImage::new(&socket); | ||
let _ = HashedCookie::new(client_image, Duration::new(1, 0)); | ||
}) | ||
}); | ||
} | ||
|
||
pub fn benchmark_make_witness_encoded_id(bench: &mut Criterion) { | ||
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); | ||
|
||
bench.bench_function("generate_id_with_time_and_port", |b| { | ||
bench.bench_function("benchmark_make_witness_encoded_id", |b| { | ||
b.iter(|| { | ||
// Inner closure, the actual test | ||
let _ = get_connection_id_old(current_time, remote_address.port()); | ||
let client_image = KeyedImage::new(&socket); | ||
let _ = WitnessCookie::new(client_image, Duration::new(1, 0)); | ||
}) | ||
}); | ||
} | ||
|
||
pub fn benchmark_generate_id_with_hashed_time_and_ip_and_port_and_salt(bench: &mut Criterion) { | ||
let remote_address = SocketAddr::from(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 117)); | ||
let current_time = current_timestamp(); | ||
let server_secret = [0;32]; | ||
pub fn benchmark_make_encrypted_encoded_id(bench: &mut Criterion) { | ||
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); | ||
|
||
bench.bench_function("generate_id_with_hashed_time_and_ip_and_port_and_salt", |b| { | ||
bench.bench_function("benchmark_make_encrypted_encoded_id", |b| { | ||
b.iter(|| { | ||
// Inner closure, the actual test | ||
let _ = get_connection_id(&server_secret, &remote_address, current_time); | ||
let client_image = <PlainImage as Create<PlainHash>>::new(&socket); | ||
let _ = EncryptedCookie::new(client_image, Duration::new(1, 0)); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, benchmark_generate_id_with_time_and_port, benchmark_generate_id_with_hashed_time_and_ip_and_port_and_salt); | ||
criterion_group!( | ||
benches, | ||
benchmark_make_old_unencoded_id, | ||
benchmark_make_hashed_encoded_id, | ||
benchmark_make_witness_encoded_id, | ||
benchmark_make_encrypted_encoded_id, | ||
); | ||
criterion_main!(benches); |
Oops, something went wrong.