@@ -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- }
0 commit comments