@@ -128,7 +128,6 @@ enum SettingsHandshake { READY, TRANSMITTED, ACKED }
128128
129129 private Continuation continuation ;
130130
131- private int processedRemoteStreamId ;
132131 private EndpointDetails endpointDetails ;
133132 private boolean goAwayReceived ;
134133
@@ -422,7 +421,7 @@ public final void onInput(final ByteBuffer src) throws HttpException, IOExceptio
422421 } else {
423422 if (inputBuffer .isEndOfStream ()) {
424423 if (connState == ConnectionHandshake .ACTIVE ) {
425- final RawFrame goAway = frameFactory .createGoAway (processedRemoteStreamId , H2Error .NO_ERROR , "Unexpected end of stream" );
424+ final RawFrame goAway = frameFactory .createGoAway (streams . getLastRemoteId () , H2Error .NO_ERROR , "Unexpected end of stream" );
426425 commitFrame (goAway );
427426 }
428427 connState = ConnectionHandshake .SHUTDOWN ;
@@ -512,7 +511,7 @@ public final void onOutput() throws HttpException, IOException {
512511 streams .release (stream );
513512 it .remove ();
514513 } else {
515- if (streams .isSameSide (stream .getId ()) || stream .getId () <= processedRemoteStreamId ) {
514+ if (streams .isSameSide (stream .getId ()) || stream .getId () <= streams . getLastRemoteId () ) {
516515 liveStreams ++;
517516 }
518517 }
@@ -555,10 +554,10 @@ public final void onTimeout(final Timeout timeout) throws HttpException, IOExcep
555554
556555 final RawFrame goAway ;
557556 if (localSettingState != SettingsHandshake .ACKED ) {
558- goAway = frameFactory .createGoAway (processedRemoteStreamId , H2Error .SETTINGS_TIMEOUT ,
557+ goAway = frameFactory .createGoAway (streams . getLastRemoteId () , H2Error .SETTINGS_TIMEOUT ,
559558 "Setting timeout (" + timeout + ")" );
560559 } else {
561- goAway = frameFactory .createGoAway (processedRemoteStreamId , H2Error .NO_ERROR ,
560+ goAway = frameFactory .createGoAway (streams . getLastRemoteId () , H2Error .NO_ERROR ,
562561 "Timeout due to inactivity (" + timeout + ")" );
563562 }
564563 commitFrame (goAway );
@@ -588,7 +587,7 @@ private void executeShutdown(final ShutdownCommand shutdownCommand) throws IOExc
588587 connState = ConnectionHandshake .SHUTDOWN ;
589588 } else {
590589 if (connState .compareTo (ConnectionHandshake .ACTIVE ) <= 0 ) {
591- final RawFrame goAway = frameFactory .createGoAway (processedRemoteStreamId , H2Error .NO_ERROR , "Graceful shutdown" );
590+ final RawFrame goAway = frameFactory .createGoAway (streams . getLastRemoteId () , H2Error .NO_ERROR , "Graceful shutdown" );
592591 commitFrame (goAway );
593592 connState = streams .isEmpty () ? ConnectionHandshake .SHUTDOWN : ConnectionHandshake .GRACEFUL_SHUTDOWN ;
594593 }
@@ -608,8 +607,8 @@ private void executeRequest(final ExecutableCommand executableCommand) throws IO
608607 final H2StreamHandler streamHandler = createLocallyInitiatedStream (
609608 executableCommand , channel , httpProcessor , connMetrics );
610609
611- final H2Stream stream = new H2Stream (channel , streamHandler , false );
612- streams .add ( streamId , stream );
610+ final H2Stream stream = new H2Stream (channel , streamHandler );
611+ streams .addLocallyInitiated ( stream );
613612
614613 if (streamListener != null ) {
615614 final int initInputWindow = stream .getInputWindow ().get ();
@@ -634,8 +633,8 @@ public void executePush(final int promisedStreamId, final AsyncPushProducer push
634633 context .setEndpointDetails (getEndpointDetails ());
635634 final H2StreamHandler streamHandler = new ServerPushH2StreamHandler (
636635 channel , httpProcessor , connMetrics , pushProducer , context );
637- final H2Stream stream = new H2Stream (channel , streamHandler , false );
638- streams .add ( promisedStreamId , stream );
636+ final H2Stream stream = new H2Stream (channel , streamHandler );
637+ streams .addLocallyInitiated ( stream );
639638 }
640639
641640 public final void onException (final Exception cause ) {
@@ -662,7 +661,7 @@ public final void onException(final Exception cause) {
662661 } else {
663662 errorCode = H2Error .INTERNAL_ERROR ;
664663 }
665- final RawFrame goAway = frameFactory .createGoAway (processedRemoteStreamId , errorCode , cause .getMessage ());
664+ final RawFrame goAway = frameFactory .createGoAway (streams . getLastRemoteId () , errorCode , cause .getMessage ());
666665 commitFrame (goAway );
667666 }
668667 }
@@ -723,8 +722,6 @@ private void consumeFrame(final RawFrame frame) throws HttpException, IOExceptio
723722 throw new H2ConnectionException (H2Error .PROTOCOL_ERROR , "GOAWAY received" );
724723 }
725724
726- streams .updateLastStreamId (streamId );
727-
728725 final H2StreamChannel channel = createChannel (streamId , false );
729726 final H2StreamHandler streamHandler ;
730727 if (connState .compareTo (ConnectionHandshake .ACTIVE ) <= 0 ) {
@@ -734,11 +731,11 @@ private void consumeFrame(final RawFrame frame) throws HttpException, IOExceptio
734731 channel .markLocalClosed ();
735732 }
736733
737- stream = new H2Stream (channel , streamHandler , true );
734+ stream = new H2Stream (channel , streamHandler );
738735 if (stream .isOutputReady ()) {
739736 stream .produceOutput ();
740737 }
741- streams .add ( streamId , stream );
738+ streams .addRemotelyInitiated ( stream );
742739 } else if (stream .isLocalClosed () && stream .isRemoteClosed ()) {
743740 throw new H2ConnectionException (H2Error .STREAM_CLOSED , "Stream closed" );
744741 }
@@ -921,8 +918,6 @@ private void consumeFrame(final RawFrame frame) throws HttpException, IOExceptio
921918 throw new H2ConnectionException (H2Error .PROTOCOL_ERROR , "Stream already open: " + promisedStreamId );
922919 }
923920
924- streams .updateLastStreamId (promisedStreamId );
925-
926921 final H2StreamChannel channel = createChannel (promisedStreamId , false );
927922 final H2StreamHandler streamHandler ;
928923 if (connState .compareTo (ConnectionHandshake .ACTIVE ) <= 0 ) {
@@ -933,8 +928,8 @@ private void consumeFrame(final RawFrame frame) throws HttpException, IOExceptio
933928 channel .markLocalClosed ();
934929 }
935930
936- final H2Stream promisedStream = new H2Stream (channel , streamHandler , true );
937- streams .add ( promisedStreamId , promisedStream );
931+ final H2Stream promisedStream = new H2Stream (channel , streamHandler );
932+ streams .addRemotelyInitiated ( promisedStream );
938933
939934 try {
940935 consumePushPromiseFrame (frame , payload , promisedStream );
@@ -1019,9 +1014,6 @@ private void consumePushPromiseFrame(final RawFrame frame, final ByteBuffer payl
10191014 }
10201015 if (continuation == null ) {
10211016 final List <Header > headers = hPackDecoder .decodeHeaders (payload );
1022- if (promisedStreamId > processedRemoteStreamId ) {
1023- processedRemoteStreamId = promisedStreamId ;
1024- }
10251017 if (streamListener != null ) {
10261018 streamListener .onHeaderInput (this , promisedStreamId , headers );
10271019 }
@@ -1052,9 +1044,6 @@ private void consumeHeaderFrame(final RawFrame frame, final H2Stream stream) thr
10521044 }
10531045 if (continuation == null ) {
10541046 final List <Header > headers = decodeHeaders (payload );
1055- if (stream .isRemoteInitiated () && streamId > processedRemoteStreamId ) {
1056- processedRemoteStreamId = streamId ;
1057- }
10581047 if (streamListener != null ) {
10591048 streamListener .onHeaderInput (this , streamId , headers );
10601049 }
@@ -1073,9 +1062,6 @@ private void consumeContinuationFrame(final RawFrame frame, final H2Stream strea
10731062 continuation .copyPayload (payload );
10741063 if (frame .isFlagSet (FrameFlag .END_HEADERS )) {
10751064 final List <Header > headers = decodeHeaders (continuation .getContent ());
1076- if (stream .isRemoteInitiated () && streamId > processedRemoteStreamId ) {
1077- processedRemoteStreamId = streamId ;
1078- }
10791065 if (streamListener != null ) {
10801066 streamListener .onHeaderInput (this , streamId , headers );
10811067 }
@@ -1272,7 +1258,8 @@ void appendState(final StringBuilder buf) {
12721258 .append (", connOutputWindow=" ).append (connOutputWindow )
12731259 .append (", outputQueue=" ).append (outputQueue .size ())
12741260 .append (", streams.size=" ).append (streams .size ())
1275- .append (", processedRemoteStreamId=" ).append (processedRemoteStreamId );
1261+ .append (", streams.lastLocal=" ).append (streams .getLastLocalId ())
1262+ .append (", streams.lastRemote=" ).append (streams .getLastRemoteId ());
12761263 }
12771264
12781265 private static class Continuation {
@@ -1320,8 +1307,8 @@ H2StreamChannel createChannel(final int streamId, final boolean idle) {
13201307 return new H2StreamChannelImpl (streamId , idle , initInputWinSize , initOutputWinSize );
13211308 }
13221309
1323- void addStream (final H2Stream stream ) {
1324- streams .add (stream );
1310+ void addStream (final H2Stream stream ) throws H2ConnectionException {
1311+ streams .addLocallyInitiated (stream );
13251312 }
13261313
13271314 class H2StreamChannelImpl implements H2StreamChannel {
0 commit comments