Skip to content

Commit 6024078

Browse files
committed
Updated types in YamuxFrameInner from i32 to u32
1 parent 9de6770 commit 6024078

File tree

2 files changed

+12
-38
lines changed

2 files changed

+12
-38
lines changed

p2p/src/network/yamux/p2p_network_yamux_reducer.rs

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl P2pNetworkYamuxState {
8989
}
9090
}
9191
1 => {
92-
let difference = i32::from_be_bytes(b);
92+
let difference = u32::from_be_bytes(b);
9393
let frame = YamuxFrame {
9494
flags,
9595
stream_id,
@@ -100,7 +100,7 @@ impl P2pNetworkYamuxState {
100100
continue;
101101
}
102102
2 => {
103-
let opaque = i32::from_be_bytes(b);
103+
let opaque = u32::from_be_bytes(b);
104104
let frame = YamuxFrame {
105105
flags,
106106
stream_id,
@@ -224,7 +224,9 @@ impl P2pNetworkYamuxState {
224224
.streams
225225
.entry(frame.stream_id)
226226
.or_insert_with(YamuxStreamState::incoming);
227-
stream.update_window(false, *difference);
227+
228+
stream.window_theirs = stream.window_theirs.saturating_add(*difference);
229+
228230
if *difference > 0 {
229231
// have some fresh space in the window
230232
// try send as many frames as can
@@ -348,16 +350,9 @@ impl P2pNetworkYamuxState {
348350
});
349351
}
350352
}
351-
YamuxFrameInner::WindowUpdate { difference } => {
352-
if *difference < 0 {
353-
let error =
354-
P2pNetworkConnectionError::YamuxBadWindowUpdate(frame.stream_id);
355-
dispatcher.push(P2pNetworkSchedulerAction::Error { addr, error });
356-
} else {
357-
while let Some(frame) = pending_outgoing.pop_front() {
358-
dispatcher
359-
.push(P2pNetworkYamuxAction::OutgoingFrame { addr, frame });
360-
}
353+
YamuxFrameInner::WindowUpdate { .. } => {
354+
while let Some(frame) = pending_outgoing.pop_front() {
355+
dispatcher.push(P2pNetworkYamuxAction::OutgoingFrame { addr, frame });
361356
}
362357
}
363358
_ => {}
@@ -412,7 +407,7 @@ impl P2pNetworkYamuxState {
412407
// }
413408
}
414409
YamuxFrameInner::WindowUpdate { difference } => {
415-
stream.update_window(true, *difference);
410+
stream.window_ours = stream.window_ours.saturating_add(*difference);
416411
}
417412
_ => {}
418413
}
@@ -479,24 +474,3 @@ impl P2pNetworkYamuxState {
479474
}
480475
}
481476
}
482-
483-
impl YamuxStreamState {
484-
pub fn update_window(&mut self, ours: bool, difference: i32) {
485-
let window = if ours {
486-
&mut self.window_ours
487-
} else {
488-
&mut self.window_theirs
489-
};
490-
if difference < 0 {
491-
let decreasing = (-difference) as u32;
492-
if *window < decreasing {
493-
*window = 0;
494-
} else {
495-
*window = (*window).wrapping_sub(decreasing);
496-
}
497-
} else {
498-
let increasing = difference as u32;
499-
*window = (*window).wrapping_add(increasing);
500-
}
501-
}
502-
}

p2p/src/network/yamux/p2p_network_yamux_state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ bitflags::bitflags! {
9595
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
9696
pub struct YamuxPing {
9797
pub stream_id: StreamId,
98-
pub opaque: i32,
98+
pub opaque: u32,
9999
pub response: bool,
100100
}
101101

@@ -227,8 +227,8 @@ impl YamuxFrame {
227227
#[derive(Serialize, Deserialize, Debug, Clone)]
228228
pub enum YamuxFrameInner {
229229
Data(Data),
230-
WindowUpdate { difference: i32 },
231-
Ping { opaque: i32 },
230+
WindowUpdate { difference: u32 },
231+
Ping { opaque: u32 },
232232
GoAway(Result<(), YamuxSessionError>),
233233
}
234234

0 commit comments

Comments
 (0)