Skip to content

Commit

Permalink
address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
neonphog committed Apr 22, 2024
1 parent 161dba7 commit 216d1c6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 45 deletions.
4 changes: 2 additions & 2 deletions rust/sbd-bench/src/c_turnover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ mod tests {
}

let start = tokio::time::Instant::now();
for _ in 0..100 {
for _ in 0..10 {
b.iter().await;
}
let elapsed = start.elapsed();

println!("{} nanos per iter", elapsed.as_nanos() / 100);
println!("{} nanos per iter", elapsed.as_nanos() / 10);
}
}
90 changes: 48 additions & 42 deletions rust/sbd-bench/src/thru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use super::*;

pub struct ThruBenchmark {
_server: SbdServer,
c1: DefaultCrypto,
s1: WsRawSend,
r1: WsRawRecv,
c2: DefaultCrypto,
s2: WsRawSend,
r2: WsRawRecv,
v1: Option<Vec<u8>>,
v2: Option<Vec<u8>>,
crypto1: DefaultCrypto,
send1: WsRawSend,
recv1: WsRawRecv,
crypto2: DefaultCrypto,
send2: WsRawSend,
recv2: WsRawRecv,
message1: Option<Vec<u8>>,
message2: Option<Vec<u8>>,
}

impl ThruBenchmark {
Expand All @@ -23,66 +23,72 @@ impl ThruBenchmark {

let server = SbdServer::new(config).await.unwrap();

let c1 = DefaultCrypto::default();
let (mut s1, mut r1) = raw_connect(c1.pub_key(), server.bind_addrs())
let crypto1 = DefaultCrypto::default();
let (mut send1, mut recv1) =
raw_connect(crypto1.pub_key(), server.bind_addrs())
.await
.unwrap();

let crypto2 = DefaultCrypto::default();
let (mut send2, mut recv2) =
raw_connect(crypto2.pub_key(), server.bind_addrs())
.await
.unwrap();

Handshake::handshake(&mut send1, &mut recv1, &crypto1)
.await
.unwrap();

let c2 = DefaultCrypto::default();
let (mut s2, mut r2) = raw_connect(c2.pub_key(), server.bind_addrs())
Handshake::handshake(&mut send2, &mut recv2, &crypto2)
.await
.unwrap();

Handshake::handshake(&mut s1, &mut r1, &c1).await.unwrap();
Handshake::handshake(&mut s2, &mut r2, &c2).await.unwrap();

Self {
_server: server,
c1,
s1,
r1,
c2,
s2,
r2,
v1: None,
v2: None,
crypto1,
send1,
recv1,
crypto2,
send2,
recv2,
message1: None,
message2: None,
}
}

pub async fn iter(&mut self) {
let Self {
c1,
s1,
r1,
c2,
s2,
r2,
v1,
v2,
crypto1,
send1,
recv1,
crypto2,
send2,
recv2,
message1,
message2,
..
} = self;

let mut b1 = v1.take().unwrap_or_else(|| vec![0xdb; 1000]);
let mut b2 = v2.take().unwrap_or_else(|| vec![0xca; 1000]);
let mut b1 = message1.take().unwrap_or_else(|| vec![0xdb; 1000]);
let mut b2 = message2.take().unwrap_or_else(|| vec![0xca; 1000]);

tokio::join!(
async {
b1[0..32].copy_from_slice(c2.pub_key());
s1.send(b1).await.unwrap();
b1[0..32].copy_from_slice(crypto2.pub_key());
send1.send(b1).await.unwrap();
},
async {
b2[0..32].copy_from_slice(c1.pub_key());
s2.send(b2).await.unwrap();
b2[0..32].copy_from_slice(crypto1.pub_key());
send2.send(b2).await.unwrap();
},
async {
let b2 = r1.recv().await.unwrap();
let b2 = recv1.recv().await.unwrap();
assert_eq!(1000, b2.len());
*v2 = Some(b2);
*message2 = Some(b2);
},
async {
let b1 = r2.recv().await.unwrap();
let b1 = recv2.recv().await.unwrap();
assert_eq!(1000, b1.len());
*v1 = Some(b1);
*message1 = Some(b1);
},
);
}
Expand Down
4 changes: 3 additions & 1 deletion spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Clients will be identified by ed25519 public key. Client sessions will be valida

Clients MUST specify exactly 1 http path item on the websocket connection url.
This item must be the base64url encoded public key that this client will be identified by.
This public key MUST be unique to this new connection.
This public key SHOULD be unique to this new connection.

### 3.2. Messages

Expand Down Expand Up @@ -65,6 +65,8 @@ the first 32 bytes will be altered to represent the peer from which the message

#### 3.2.3. Flow

- If the server is in an overload state, it MAY drop incoming tcp connections
immediately with no response even before doing any TLS handshaking.
- The server MUST send `areq` with a random nonce once for every newly opened connection.
The server MAY send any limit messages before or after this `areq`, but it MUST come before the `srdy`.
- The client MUST respond with a signature over the nonce by the private key associated with the public key
Expand Down

0 comments on commit 216d1c6

Please sign in to comment.