@@ -22,6 +22,7 @@ bitflags::bitflags! {
22
22
#[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
23
23
pub ( crate ) struct ConnectionFlags : u8 {
24
24
const SETTINGS_PROCESSED = 0b0000_0001 ;
25
+ const UNKNOWN_STREAMS = 0b0000_0010 ;
25
26
const DISCONNECT_WHEN_READY = 0b0000_1000 ;
26
27
const SECURE = 0b0001_0000 ;
27
28
const STREAM_REFUSED = 0b0010_0000 ;
@@ -62,7 +63,13 @@ struct ConnectionState {
62
63
}
63
64
64
65
impl Connection {
65
- pub ( crate ) fn new ( io : IoRef , codec : Codec , config : Config , secure : bool ) -> Self {
66
+ pub ( crate ) fn new (
67
+ io : IoRef ,
68
+ codec : Codec ,
69
+ config : Config ,
70
+ secure : bool ,
71
+ skip_streams : bool ,
72
+ ) -> Self {
66
73
// send preface
67
74
if !config. is_server ( ) {
68
75
let _ = io. with_write_buf ( |buf| buf. extend_from_slice ( & consts:: PREFACE ) ) ;
@@ -94,6 +101,15 @@ impl Connection {
94
101
95
102
let remote_frame_size = Cell :: new ( codec. send_frame_size ( ) ) ;
96
103
104
+ let mut flags = if secure {
105
+ ConnectionFlags :: SECURE
106
+ } else {
107
+ ConnectionFlags :: empty ( )
108
+ } ;
109
+ if !skip_streams {
110
+ flags. insert ( ConnectionFlags :: UNKNOWN_STREAMS ) ;
111
+ }
112
+
97
113
let state = Rc :: new ( ConnectionState {
98
114
codec,
99
115
remote_frame_size,
@@ -113,11 +129,7 @@ impl Connection {
113
129
local_pending_reset : Default :: default ( ) ,
114
130
remote_window_sz : Cell :: new ( frame:: DEFAULT_INITIAL_WINDOW_SIZE ) ,
115
131
error : Cell :: new ( None ) ,
116
- flags : Cell :: new ( if secure {
117
- ConnectionFlags :: SECURE
118
- } else {
119
- ConnectionFlags :: empty ( )
120
- } ) ,
132
+ flags : Cell :: new ( flags) ,
121
133
} ) ;
122
134
let con = Connection ( state) ;
123
135
@@ -408,7 +420,9 @@ impl Connection {
408
420
}
409
421
410
422
// Add ids to pending queue
411
- self . 0 . local_pending_reset . add ( id, & self . 0 . local_config ) ;
423
+ if flags. contains ( ConnectionFlags :: UNKNOWN_STREAMS ) {
424
+ self . 0 . local_pending_reset . add ( id, & self . 0 . local_config ) ;
425
+ }
412
426
}
413
427
414
428
pub ( crate ) fn recv_half ( & self ) -> RecvHalfConnection {
@@ -420,6 +434,12 @@ impl Connection {
420
434
}
421
435
}
422
436
437
+ impl ConnectionState {
438
+ fn err_unknown_streams ( & self ) -> bool {
439
+ self . flags . get ( ) . contains ( ConnectionFlags :: UNKNOWN_STREAMS )
440
+ }
441
+ }
442
+
423
443
impl RecvHalfConnection {
424
444
pub ( crate ) fn tag ( & self ) -> & ' static str {
425
445
self . 0 . io . tag ( )
@@ -455,8 +475,9 @@ impl RecvHalfConnection {
455
475
frm : Headers ,
456
476
) -> Result < Option < ( StreamRef , Message ) > , Either < ConnectionError , StreamErrorInner > > {
457
477
let id = frm. stream_id ( ) ;
478
+ let is_server = self . 0 . local_config . is_server ( ) ;
458
479
459
- if self . 0 . local_config . is_server ( ) && !id. is_client_initiated ( ) {
480
+ if is_server && !id. is_client_initiated ( ) {
460
481
return Err ( Either :: Left ( ConnectionError :: InvalidStreamId (
461
482
"Invalid id in received headers frame" ,
462
483
) ) ) ;
@@ -467,7 +488,9 @@ impl RecvHalfConnection {
467
488
Ok ( item) => Ok ( item. map ( move |msg| ( stream, msg) ) ) ,
468
489
Err ( kind) => Err ( Either :: Right ( StreamErrorInner :: new ( stream, kind) ) ) ,
469
490
}
470
- } else if !self . 0 . local_config . is_server ( ) && self . 0 . local_pending_reset . is_pending ( id) {
491
+ } else if !is_server
492
+ && ( !self . 0 . err_unknown_streams ( ) || self . 0 . local_pending_reset . is_pending ( id) )
493
+ {
471
494
// if client and no stream, then it was closed
472
495
self . encode ( frame:: Reset :: new ( id, frame:: Reason :: STREAM_CLOSED ) ) ;
473
496
Ok ( None )
@@ -543,7 +566,9 @@ impl RecvHalfConnection {
543
566
Ok ( item) => Ok ( item. map ( move |msg| ( stream, msg) ) ) ,
544
567
Err ( kind) => Err ( Either :: Right ( StreamErrorInner :: new ( stream, kind) ) ) ,
545
568
}
546
- } else if self . 0 . local_pending_reset . is_pending ( frm. stream_id ( ) ) {
569
+ } else if !self . 0 . err_unknown_streams ( )
570
+ || self . 0 . local_pending_reset . is_pending ( frm. stream_id ( ) )
571
+ {
547
572
self . encode ( frame:: Reset :: new (
548
573
frm. stream_id ( ) ,
549
574
frame:: Reason :: STREAM_CLOSED ,
@@ -684,11 +709,17 @@ impl RecvHalfConnection {
684
709
. map_err ( |kind| Either :: Right ( StreamErrorInner :: new ( stream, kind) ) )
685
710
} else if self . 0 . local_pending_reset . is_pending ( frm. stream_id ( ) ) {
686
711
Ok ( ( ) )
687
- } else {
712
+ } else if self . 0 . err_unknown_streams ( ) {
688
713
log:: trace!( "Unknown WINDOW_UPDATE {:?}" , frm) ;
689
714
Err ( Either :: Left ( ConnectionError :: UnknownStream (
690
715
"WINDOW_UPDATE" ,
691
716
) ) )
717
+ } else {
718
+ self . encode ( frame:: Reset :: new (
719
+ frm. stream_id ( ) ,
720
+ frame:: Reason :: STREAM_CLOSED ,
721
+ ) ) ;
722
+ Ok ( ( ) )
692
723
}
693
724
}
694
725
@@ -724,9 +755,11 @@ impl RecvHalfConnection {
724
755
) ) )
725
756
} else if self . 0 . local_pending_reset . remove ( id) {
726
757
self . update_rst_count ( )
727
- } else {
758
+ } else if self . 0 . err_unknown_streams ( ) {
728
759
self . update_rst_count ( ) ?;
729
760
Err ( Either :: Left ( ConnectionError :: UnknownStream ( "RST_STREAM" ) ) )
761
+ } else {
762
+ Ok ( ( ) )
730
763
}
731
764
}
732
765
0 commit comments