Skip to content

Commit 5aaa374

Browse files
committed
Handshake completed
1 parent 4ab28ed commit 5aaa374

3 files changed

Lines changed: 70 additions & 11 deletions

File tree

‎neqo-transport/src/connection.rs‎

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,9 @@ pub struct Connection {
8686
scid: Vec<u8>,
8787
dcid: Vec<u8>,
8888
// TODO(ekr@rtfm.com): Prioritized generators, rather than a vec
89-
<<<<<<< HEAD
90-
send_epoch: Epoch,
91-
recv_epoch: Epoch,
92-
crypto_stream_out: [TxBuffer; 4],
93-
crypto_stream_in:
94-
=======
9589
send_epoch: u16,
9690
recv_epoch: u16,
9791
crypto_streams: [CryptoStream; 4],
98-
>>>>>>> Server emits handshake messages
9992
generators: Vec<FrameGenerator>,
10093
deadline: u64,
10194
max_data: u64,
@@ -216,6 +209,9 @@ impl Connection {
216209
// Imprint on the remote parameters.
217210
self.dcid = dcid.clone();
218211
}
212+
State::Handshaking => {
213+
// No-op.
214+
}
219215
_ => unimplemented!(),
220216
}
221217

@@ -527,7 +523,7 @@ fn generate_crypto_frames(
527523
) -> Option<Frame> {
528524
if let Some((offset, data)) = conn.crypto_streams[epoch as usize]
529525
.tx
530-
.next_bytes(mode, remaining)
526+
.next_bytes(mode, now, remaining)
531527
{
532528
return Some(Frame::Crypto {
533529
offset,
@@ -560,6 +556,52 @@ mod tests {
560556
// SH -> 0
561557
let res = client.process(res.0, 0).unwrap();
562558
assert_eq!(None, res.0);
559+
560+
// 0 -> EE.
561+
let res = server.process(None, 0).unwrap();
562+
assert_ne!(None, res.0);
563+
assert_eq!(0, res.1);
564+
debug!("Output={:?}", res.0);
565+
566+
// EE -> 0
567+
let res = client.process(res.0, 0).unwrap();
568+
assert_eq!(None, res.0);
569+
570+
// 0 -> CERT.
571+
let res = server.process(None, 0).unwrap();
572+
assert_ne!(None, res.0);
573+
assert_eq!(0, res.1);
574+
debug!("Output={:?}", res.0);
575+
576+
// CERT -> 0
577+
let res = client.process(res.0, 0).unwrap();
578+
assert_eq!(None, res.0);
579+
580+
// 0 -> CV.
581+
let res = server.process(None, 0).unwrap();
582+
assert_ne!(None, res.0);
583+
assert_eq!(0, res.1);
584+
debug!("Output={:?}", res.0);
585+
586+
// CV -> 0
587+
let res = client.process(res.0, 0).unwrap();
588+
assert_eq!(None, res.0);
589+
590+
// 0 -> FIN.
591+
let res = server.process(None, 0).unwrap();
592+
assert_ne!(None, res.0);
593+
assert_eq!(0, res.1);
594+
debug!("Output={:?}", res.0);
595+
596+
// FIN -> FIN
597+
let res = client.process(res.0, 0).unwrap();
598+
assert_ne!(None, res.0);
599+
assert_eq!(0, res.1);
600+
debug!("Output={:?}", res.0);
601+
602+
// FIN -> 0
603+
let res = server.process(res.0, 0).unwrap();
604+
assert_eq!(None, res.0);
563605
}
564606

565607
}

‎neqo-transport/src/nss_stub.rs‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ use std::collections::linked_list::LinkedList;
99
use std::ops::{Deref, DerefMut};
1010
use std::string::String;
1111

12-
#[derive(PartialEq, Debug)]
12+
#[derive(Debug)]
1313
pub struct HandshakeMessage {
1414
name: String,
1515
epoch: u16,
1616
client: bool,
1717
}
1818

19+
// TODO(ekr@rtfm.com): Temporary override for PartialEq until we fix the epochs.
20+
impl PartialEq for HandshakeMessage {
21+
fn eq(&self, other: &HandshakeMessage) -> bool {
22+
self.name == other.name && self.client == other.client
23+
}
24+
}
25+
1926
lazy_static! {
2027
pub static ref HANDSHAKE_MESSAGES: [HandshakeMessage; 7] = [
2128
HandshakeMessage {
@@ -108,7 +115,9 @@ impl SecretAgent {
108115
}
109116

110117
// Now generate our output.
111-
while HANDSHAKE_MESSAGES[self.next].client == self.client {
118+
while self.next < HANDSHAKE_MESSAGES.len()
119+
&& HANDSHAKE_MESSAGES[self.next].client == self.client
120+
{
112121
let m = self.send_message(&HANDSHAKE_MESSAGES[self.next]);
113122
debug!("Sending message: {:?}", HANDSHAKE_MESSAGES[self.next]);
114123
output.recs.push_back(SslRecord {
@@ -118,6 +127,11 @@ impl SecretAgent {
118127
self.next += 1;
119128
}
120129

130+
debug!("handshake_raw() completed");
131+
132+
if self.next == HANDSHAKE_MESSAGES.len() {
133+
info!("Handshake completed");
134+
}
121135
Ok((HandshakeState {}, output))
122136
}
123137

‎neqo-transport/src/stream.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl TxBuffer {
6565
data: Vec::from(buf),
6666
state: TxChunkState::Unsent,
6767
});
68+
self.offset += buf.len() as u64;
6869
len
6970
}
7071

@@ -77,16 +78,18 @@ impl TxBuffer {
7778
None
7879
}
7980

80-
pub fn next_bytes(&mut self, _mode: TxMode, l: usize) -> Option<(u64, Vec<u8>)> {
81+
pub fn next_bytes(&mut self, _mode: TxMode, now: u64, l: usize) -> Option<(u64, Vec<u8>)> {
8182
// TODO(ekr@rtfm.com): Send a slice that fits in |l|.
8283
// First try to find some unsent stuff.
8384
if let Some(c) = self.find_first_chunk_by_state(TxChunkState::Unsent) {
8485
let d = c.data.to_vec();
86+
c.state = TxChunkState::Sent(now);
8587
Some((c.offset, d))
8688
}
8789
// How about some lost stuff.
8890
else if let Some(c) = self.find_first_chunk_by_state(TxChunkState::Lost) {
8991
let d = c.data.to_vec();
92+
c.state = TxChunkState::Sent(now);
9093
Some((c.offset, d))
9194
} else {
9295
None

0 commit comments

Comments
 (0)