From 97f120330b6cf4ae2b19aa30128243db448892a4 Mon Sep 17 00:00:00 2001 From: Jeff Pinner Date: Tue, 18 Feb 2014 12:18:00 -0800 Subject: [PATCH] SPDY: remove SPDY/3 support --- .../handler/codec/spdy/SpdyOrHttpChooser.java | 9 +-- .../codec/spdy/SpdySessionHandler.java | 72 ++++++++----------- .../netty/handler/codec/spdy/SpdyVersion.java | 11 +-- .../codec/spdy/SpdyFrameDecoderTest.java | 2 - .../codec/spdy/SpdySessionHandlerTest.java | 12 ---- .../spdy/server/SpdyServerProvider.java | 2 +- .../transport/socket/SocketSpdyEchoTest.java | 5 -- 7 files changed, 33 insertions(+), 80 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyOrHttpChooser.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyOrHttpChooser.java index 6f1e356b56..3ebb94fbbc 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyOrHttpChooser.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyOrHttpChooser.java @@ -25,9 +25,8 @@ import io.netty.handler.codec.http.HttpRequestDecoder; import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.ssl.SslHandler; -import java.util.List; - import javax.net.ssl.SSLEngine; +import java.util.List; /** * {@link ChannelHandler} which is responsible to setup the {@link ChannelPipeline} either for HTTP or SPDY. This offers @@ -38,7 +37,6 @@ public abstract class SpdyOrHttpChooser extends ByteToMessageDecoder { // TODO: Replace with generic NPN handler public enum SelectedProtocol { - SPDY_3("spdy/3"), SPDY_3_1("spdy/3.1"), HTTP_1_1("http/1.1"), HTTP_1_0("http/1.0"), @@ -111,9 +109,6 @@ public abstract class SpdyOrHttpChooser extends ByteToMessageDecoder { case UNKNOWN: // Not done with choosing the protocol, so just return here for now, return false; - case SPDY_3: - addSpdyHandlers(ctx, SpdyVersion.SPDY_3); - break; case SPDY_3_1: addSpdyHandlers(ctx, SpdyVersion.SPDY_3_1); break; @@ -160,7 +155,7 @@ public abstract class SpdyOrHttpChooser extends ByteToMessageDecoder { /** * Create the {@link ChannelHandler} that is responsible for handling the http responses when the - * {@link SelectedProtocol} was {@link SelectedProtocol#SPDY_3} or {@link SelectedProtocol#SPDY_3_1}. + * when the {@link SelectedProtocol} was {@link SelectedProtocol#SPDY_3_1}. * * By default this getMethod will just delecate to {@link #createHttpRequestHandlerForHttp()}, but sub-classes may * override this to change the behaviour. diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java index cd71d930ce..d579a3a987 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java @@ -61,7 +61,6 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { private final boolean server; private final int minorVersion; - private final boolean sessionFlowControl; /** * Creates a new session handler. @@ -78,7 +77,6 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { } this.server = server; minorVersion = version.getMinorVersion(); - sessionFlowControl = version.useSessionFlowControl(); } @Override @@ -110,25 +108,23 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg; int streamId = spdyDataFrame.getStreamId(); - if (sessionFlowControl) { - int deltaWindowSize = -1 * spdyDataFrame.content().readableBytes(); - int newSessionWindowSize = - spdySession.updateReceiveWindowSize(SPDY_SESSION_STREAM_ID, deltaWindowSize); + int deltaWindowSize = -1 * spdyDataFrame.content().readableBytes(); + int newSessionWindowSize = + spdySession.updateReceiveWindowSize(SPDY_SESSION_STREAM_ID, deltaWindowSize); - // Check if session window size is reduced beyond allowable lower bound - if (newSessionWindowSize < 0) { - issueSessionError(ctx, SpdySessionStatus.PROTOCOL_ERROR); - return; - } + // Check if session window size is reduced beyond allowable lower bound + if (newSessionWindowSize < 0) { + issueSessionError(ctx, SpdySessionStatus.PROTOCOL_ERROR); + return; + } - // Send a WINDOW_UPDATE frame if less than half the session window size remains - if (newSessionWindowSize <= initialReceiveWindowSize / 2) { - deltaWindowSize = initialReceiveWindowSize - newSessionWindowSize; - spdySession.updateReceiveWindowSize(SPDY_SESSION_STREAM_ID, deltaWindowSize); - SpdyWindowUpdateFrame spdyWindowUpdateFrame = - new DefaultSpdyWindowUpdateFrame(SPDY_SESSION_STREAM_ID, deltaWindowSize); - ctx.writeAndFlush(spdyWindowUpdateFrame); - } + // Send a WINDOW_UPDATE frame if less than half the session window size remains + if (newSessionWindowSize <= initialReceiveWindowSize / 2) { + int sessionDeltaWindowSize = initialReceiveWindowSize - newSessionWindowSize; + spdySession.updateReceiveWindowSize(SPDY_SESSION_STREAM_ID, sessionDeltaWindowSize); + SpdyWindowUpdateFrame spdyWindowUpdateFrame = + new DefaultSpdyWindowUpdateFrame(SPDY_SESSION_STREAM_ID, sessionDeltaWindowSize); + ctx.writeAndFlush(spdyWindowUpdateFrame); } // Check if we received a data frame for a Stream-ID which is not open @@ -165,7 +161,6 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { */ // Update receive window size - int deltaWindowSize = -1 * spdyDataFrame.content().readableBytes(); int newWindowSize = spdySession.updateReceiveWindowSize(streamId, deltaWindowSize); // Window size can become negative if we sent a SETTINGS frame that reduces the @@ -191,10 +186,10 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { // Send a WINDOW_UPDATE frame if less than half the stream window size remains if (newWindowSize <= initialReceiveWindowSize / 2 && !spdyDataFrame.isLast()) { - deltaWindowSize = initialReceiveWindowSize - newWindowSize; - spdySession.updateReceiveWindowSize(streamId, deltaWindowSize); + int streamDeltaWindowSize = initialReceiveWindowSize - newWindowSize; + spdySession.updateReceiveWindowSize(streamId, streamDeltaWindowSize); SpdyWindowUpdateFrame spdyWindowUpdateFrame = - new DefaultSpdyWindowUpdateFrame(streamId, deltaWindowSize); + new DefaultSpdyWindowUpdateFrame(streamId, streamDeltaWindowSize); ctx.writeAndFlush(spdyWindowUpdateFrame); } @@ -478,11 +473,8 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { synchronized (flowControlLock) { int dataLength = spdyDataFrame.content().readableBytes(); int sendWindowSize = spdySession.getSendWindowSize(streamId); - - if (sessionFlowControl) { - int sessionSendWindowSize = spdySession.getSendWindowSize(SPDY_SESSION_STREAM_ID); - sendWindowSize = Math.min(sendWindowSize, sessionSendWindowSize); - } + int sessionSendWindowSize = spdySession.getSendWindowSize(SPDY_SESSION_STREAM_ID); + sendWindowSize = Math.min(sendWindowSize, sessionSendWindowSize); if (sendWindowSize <= 0) { // Stream is stalled -- enqueue Data frame and return @@ -491,9 +483,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { } else if (sendWindowSize < dataLength) { // Stream is not stalled but we cannot send the entire frame spdySession.updateSendWindowSize(streamId, -1 * sendWindowSize); - if (sessionFlowControl) { - spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * sendWindowSize); - } + spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * sendWindowSize); // Create a partial data frame whose length is the current window size SpdyDataFrame partialDataFrame = new DefaultSpdyDataFrame(streamId, @@ -517,9 +507,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { } else { // Window size is large enough to send entire data frame spdySession.updateSendWindowSize(streamId, -1 * dataLength); - if (sessionFlowControl) { - spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * dataLength); - } + spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * dataLength); // The transfer window size is pre-decremented when sending a data frame downstream. // Close the session on write failures that leave the transfer window in a corrupt state. @@ -758,7 +746,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { private void updateSendWindowSize(final ChannelHandlerContext ctx, int streamId, int deltaWindowSize) { synchronized (flowControlLock) { int newWindowSize = spdySession.updateSendWindowSize(streamId, deltaWindowSize); - if (sessionFlowControl && streamId != SPDY_SESSION_STREAM_ID) { + if (streamId != SPDY_SESSION_STREAM_ID) { int sessionSendWindowSize = spdySession.getSendWindowSize(SPDY_SESSION_STREAM_ID); newWindowSize = Math.min(newWindowSize, sessionSendWindowSize); } @@ -773,7 +761,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { SpdyDataFrame spdyDataFrame = pendingWrite.spdyDataFrame; int dataFrameSize = spdyDataFrame.content().readableBytes(); int writeStreamId = spdyDataFrame.getStreamId(); - if (sessionFlowControl && streamId == SPDY_SESSION_STREAM_ID) { + if (streamId == SPDY_SESSION_STREAM_ID) { newWindowSize = Math.min(newWindowSize, spdySession.getSendWindowSize(writeStreamId)); } @@ -781,11 +769,9 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { // Window size is large enough to send entire data frame spdySession.removePendingWrite(writeStreamId); newWindowSize = spdySession.updateSendWindowSize(writeStreamId, -1 * dataFrameSize); - if (sessionFlowControl) { - int sessionSendWindowSize = - spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * dataFrameSize); - newWindowSize = Math.min(newWindowSize, sessionSendWindowSize); - } + int sessionSendWindowSize = + spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * dataFrameSize); + newWindowSize = Math.min(newWindowSize, sessionSendWindowSize); // Close the local side of the stream if this is the last frame if (spdyDataFrame.isLast()) { @@ -805,9 +791,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter { } else { // We can send a partial frame spdySession.updateSendWindowSize(writeStreamId, -1 * newWindowSize); - if (sessionFlowControl) { - spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * newWindowSize); - } + spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * newWindowSize); // Create a partial data frame whose length is the current window size SpdyDataFrame partialDataFrame = new DefaultSpdyDataFrame(writeStreamId, diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyVersion.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyVersion.java index f3adac287c..efea59e331 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyVersion.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyVersion.java @@ -16,17 +16,14 @@ package io.netty.handler.codec.spdy; public enum SpdyVersion { - SPDY_3 (3, 0, false), - SPDY_3_1 (3, 1, true); + SPDY_3_1 (3, 1); private final int version; private final int minorVersion; - private final boolean sessionFlowControl; - private SpdyVersion(int version, int minorVersion, boolean sessionFlowControl) { + private SpdyVersion(int version, int minorVersion) { this.version = version; this.minorVersion = minorVersion; - this.sessionFlowControl = sessionFlowControl; } int getVersion() { @@ -36,8 +33,4 @@ public enum SpdyVersion { int getMinorVersion() { return minorVersion; } - - boolean useSessionFlowControl() { - return sessionFlowControl; - } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyFrameDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyFrameDecoderTest.java index c4bb9ce286..bb583820f4 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyFrameDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyFrameDecoderTest.java @@ -50,7 +50,6 @@ public class SpdyFrameDecoderTest { @Test public void testTooLargeHeaderNameOnSynStreamRequest() throws Exception { - testTooLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3); testTooLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3_1); } @@ -108,7 +107,6 @@ public class SpdyFrameDecoderTest { @Test public void testLargeHeaderNameOnSynStreamRequest() throws Exception { - testLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3); testLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3_1); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java index 9e13f49a51..1ef29b842e 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java @@ -282,48 +282,36 @@ public class SpdySessionHandlerTest { @Test public void testSpdyClientSessionHandler() { - logger.info("Running: testSpdyClientSessionHandler v3"); - testSpdySessionHandler(SpdyVersion.SPDY_3, false); logger.info("Running: testSpdyClientSessionHandler v3.1"); testSpdySessionHandler(SpdyVersion.SPDY_3_1, false); } @Test public void testSpdyClientSessionHandlerPing() { - logger.info("Running: testSpdyClientSessionHandlerPing v3"); - testSpdySessionHandlerPing(SpdyVersion.SPDY_3, false); logger.info("Running: testSpdyClientSessionHandlerPing v3.1"); testSpdySessionHandlerPing(SpdyVersion.SPDY_3_1, false); } @Test public void testSpdyClientSessionHandlerGoAway() { - logger.info("Running: testSpdyClientSessionHandlerGoAway v3"); - testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3, false); logger.info("Running: testSpdyClientSessionHandlerGoAway v3.1"); testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3_1, false); } @Test public void testSpdyServerSessionHandler() { - logger.info("Running: testSpdyServerSessionHandler v3"); - testSpdySessionHandler(SpdyVersion.SPDY_3, true); logger.info("Running: testSpdyServerSessionHandler v3.1"); testSpdySessionHandler(SpdyVersion.SPDY_3_1, true); } @Test public void testSpdyServerSessionHandlerPing() { - logger.info("Running: testSpdyServerSessionHandlerPing v3"); - testSpdySessionHandlerPing(SpdyVersion.SPDY_3, true); logger.info("Running: testSpdyServerSessionHandlerPing v3.1"); testSpdySessionHandlerPing(SpdyVersion.SPDY_3_1, true); } @Test public void testSpdyServerSessionHandlerGoAway() { - logger.info("Running: testSpdyServerSessionHandlerGoAway v3"); - testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3, true); logger.info("Running: testSpdyServerSessionHandlerGoAway v3.1"); testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3_1, true); } diff --git a/example/src/main/java/io/netty/example/spdy/server/SpdyServerProvider.java b/example/src/main/java/io/netty/example/spdy/server/SpdyServerProvider.java index d6292093a5..e8f5ff2eba 100644 --- a/example/src/main/java/io/netty/example/spdy/server/SpdyServerProvider.java +++ b/example/src/main/java/io/netty/example/spdy/server/SpdyServerProvider.java @@ -46,7 +46,7 @@ public class SpdyServerProvider implements ServerProvider { @Override public List protocols() { - return Arrays.asList("spdy/3.1", "spdy/3", "http/1.1"); + return Arrays.asList("spdy/3.1", "http/1.1"); } @Override diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java index 7e24bf13d1..333a97e646 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java @@ -149,10 +149,6 @@ public class SocketSpdyEchoTest extends AbstractSocketTest { @Test(timeout = 15000) public void testSpdyEcho() throws Throwable { - version = SpdyVersion.SPDY_3; - logger.info("Testing against SPDY v3"); - run(); - version = SpdyVersion.SPDY_3_1; logger.info("Testing against SPDY v3.1"); run(); @@ -162,7 +158,6 @@ public class SocketSpdyEchoTest extends AbstractSocketTest { ByteBuf frames; switch (version) { - case SPDY_3: case SPDY_3_1: frames = createFrames(3); break;