Skip to content

Commit 247c7a6

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

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

p2p/src/network/yamux/p2p_network_yamux_reducer.rs

Lines changed: 8 additions & 24 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,
@@ -348,16 +348,9 @@ impl P2pNetworkYamuxState {
348348
});
349349
}
350350
}
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-
}
351+
YamuxFrameInner::WindowUpdate { .. } => {
352+
while let Some(frame) = pending_outgoing.pop_front() {
353+
dispatcher.push(P2pNetworkYamuxAction::OutgoingFrame { addr, frame });
361354
}
362355
}
363356
_ => {}
@@ -481,22 +474,13 @@ impl P2pNetworkYamuxState {
481474
}
482475

483476
impl YamuxStreamState {
484-
pub fn update_window(&mut self, ours: bool, difference: i32) {
477+
pub fn update_window(&mut self, ours: bool, difference: u32) {
485478
let window = if ours {
486479
&mut self.window_ours
487480
} else {
488481
&mut self.window_theirs
489482
};
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-
}
483+
484+
*window = (*window).wrapping_add(difference);
501485
}
502486
}

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)