Skip to content

Commit

Permalink
Make Connection::pmtu a method
Browse files Browse the repository at this point in the history
It can vary based on ipv4 or ipv6, or if we ever implemenet PMTUD (#243).

fixes #199
  • Loading branch information
Andy Grover committed Oct 14, 2019
1 parent be7bcaa commit 2e8e223
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions neqo-transport/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ pub struct Connection {
connection_ids: HashMap<u64, (Vec<u8>, [u8; 16])>, // (sequence number, (connection id, reset token))
pub(crate) send_streams: SendStreams,
pub(crate) recv_streams: RecvStreams,
pmtu: usize,
pub(crate) flow_mgr: Rc<RefCell<FlowMgr>>,
loss_recovery: LossRecovery,
loss_recovery_state: LossRecoveryState,
Expand Down Expand Up @@ -422,7 +421,6 @@ impl Connection {
connection_ids: HashMap::new(),
send_streams: SendStreams::default(),
recv_streams: RecvStreams::default(),
pmtu: 1280,
flow_mgr: Rc::new(RefCell::new(FlowMgr::default())),
loss_recovery: LossRecovery::new(),
loss_recovery_state: LossRecoveryState::default(),
Expand All @@ -432,6 +430,14 @@ impl Connection {
}
}

fn pmtu(&self) -> usize {
match &self.paths {
Some(path) if path.local.is_ipv4() => 1252,
Some(_) => 1232, // IPv6
None => 1280,
}
}

/// Set the connection ID that was originally chosen by the client.
pub(crate) fn original_connection_id(&mut self, odcid: &ConnectionId) {
assert_eq!(self.role, Role::Server);
Expand Down Expand Up @@ -1001,7 +1007,7 @@ impl Connection {
match &self.state {
State::Init | State::WaitInitial | State::Handshaking | State::Connected => {
loop {
let remaining = self.pmtu - out_bytes.len() - encoder.len();
let remaining = self.pmtu() - out_bytes.len() - encoder.len();

// Check sources in turn for available frames
if let Some((frame, token)) = self
Expand All @@ -1019,8 +1025,8 @@ impl Connection {
if let Some(t) = token {
tokens.push(t);
}
assert!(encoder.len() <= self.pmtu);
if out_bytes.len() + encoder.len() == self.pmtu {
assert!(encoder.len() <= self.pmtu());
if out_bytes.len() + encoder.len() == self.pmtu() {
// No more space for frames.
break;
}
Expand Down Expand Up @@ -1106,7 +1112,7 @@ impl Connection {
let mut packet = encode_packet(tx, &hdr, &encoder);
dump_packet(self, "TX ->", &hdr, &encoder);
out_bytes.append(&mut packet);
if out_bytes.len() >= self.pmtu {
if out_bytes.len() >= self.pmtu() {
break;
}
}
Expand Down

0 comments on commit 2e8e223

Please sign in to comment.