SPDY: remove SPDY/3 support

This commit is contained in:
Jeff Pinner 2014-02-18 12:03:32 -08:00 committed by Trustin Lee
parent 527347094a
commit a3bff7b89e
6 changed files with 33 additions and 70 deletions

View File

@ -38,7 +38,6 @@ public abstract class SpdyOrHttpChooser implements ChannelUpstreamHandler {
public enum SelectedProtocol {
SpdyVersion3_1,
SpdyVersion3,
HttpVersion1_1,
HttpVersion1_0,
None
@ -73,9 +72,6 @@ public abstract class SpdyOrHttpChooser implements ChannelUpstreamHandler {
case None:
// Not done with choosing the protocol, so just return here for now,
return;
case SpdyVersion3:
addSpdyHandlers(ctx, SpdyVersion.SPDY_3);
break;
case SpdyVersion3_1:
addSpdyHandlers(ctx, SpdyVersion.SPDY_3_1);
break;
@ -126,10 +122,9 @@ public abstract class SpdyOrHttpChooser implements ChannelUpstreamHandler {
/**
* Create the {@link ChannelUpstreamHandler} that is responsible for handling the {@link HttpRequest}'s
* when the {@link SelectedProtocol} was {@link SelectedProtocol#SpdyVersion3} or
* {@link SelectedProtocol#SpdyVersion3_1}.
* when the {@link SelectedProtocol} was {@link SelectedProtocol#SpdyVersion3_1}.
*
* Bye default this method will just delecate to {@link #createHttpRequestHandlerForHttp()}, but
* By default this method will just delecate to {@link #createHttpRequestHandlerForHttp()}, but
* sub-classes may override this to change the behaviour.
*/
protected ChannelUpstreamHandler createHttpRequestHandlerForSpdy() {

View File

@ -63,7 +63,6 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
private final boolean server;
private final int minorVersion;
private final boolean sessionFlowControl;
/**
* Creates a new session handler.
@ -80,7 +79,6 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
}
this.server = server;
minorVersion = spdyVersion.getMinorVersion();
sessionFlowControl = spdyVersion.useSessionFlowControl();
}
@Override
@ -116,26 +114,24 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg;
int streamId = spdyDataFrame.getStreamId();
if (sessionFlowControl) {
int deltaWindowSize = -1 * spdyDataFrame.getData().readableBytes();
int newSessionWindowSize =
spdySession.updateReceiveWindowSize(SPDY_SESSION_STREAM_ID, deltaWindowSize);
int deltaWindowSize = -1 * spdyDataFrame.getData().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, e.getChannel(), e.getRemoteAddress(), SpdySessionStatus.PROTOCOL_ERROR);
return;
}
// Check if session window size is reduced beyond allowable lower bound
if (newSessionWindowSize < 0) {
issueSessionError(ctx, e.getChannel(), e.getRemoteAddress(), 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);
Channels.write(
ctx, Channels.future(e.getChannel()), spdyWindowUpdateFrame, e.getRemoteAddress());
}
// 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);
Channels.write(
ctx, Channels.future(e.getChannel()), spdyWindowUpdateFrame, e.getRemoteAddress());
}
// Check if we received a data frame for a Stream-ID which is not open
@ -167,7 +163,6 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
*/
// Update receive window size
int deltaWindowSize = -1 * spdyDataFrame.getData().readableBytes();
int newWindowSize = spdySession.updateReceiveWindowSize(streamId, deltaWindowSize);
// Window size can become negative if we sent a SETTINGS frame that reduces the
@ -192,10 +187,10 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
// 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);
Channels.write(
ctx, Channels.future(e.getChannel()), spdyWindowUpdateFrame, e.getRemoteAddress());
}
@ -480,11 +475,8 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
synchronized (flowControlLock) {
int dataLength = spdyDataFrame.getData().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
@ -493,9 +485,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
} 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);
@ -525,9 +515,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
} 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 leaves the transfer window in a corrupt state.
@ -770,7 +758,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
private void updateSendWindowSize(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);
}
@ -785,7 +773,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
SpdyDataFrame spdyDataFrame = (SpdyDataFrame) e.getMessage();
int dataFrameSize = spdyDataFrame.getData().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));
}
@ -793,11 +781,9 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
// 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);
// The transfer window size is pre-decremented when sending a data frame downstream.
// Close the session on write failures that leaves the transfer window in a corrupt state.
@ -821,9 +807,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
} 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);

View File

@ -16,17 +16,14 @@
package org.jboss.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 minorVerison;
private final boolean sessionFlowControl;
private SpdyVersion(int version, int minorVersion, boolean sessionFlowControl) {
private SpdyVersion(int version, int minorVersion) {
this.version = version;
this.minorVerison = minorVersion;
this.sessionFlowControl = sessionFlowControl;
}
int getVersion() {
@ -36,8 +33,4 @@ public enum SpdyVersion {
int getMinorVersion() {
return minorVerison;
}
boolean useSessionFlowControl() {
return sessionFlowControl;
}
}

View File

@ -147,7 +147,6 @@ public abstract class AbstractSocketSpdyEchoTest {
@Test
public void testSpdyEcho() throws Throwable {
testSpdyEcho(SpdyVersion.SPDY_3);
testSpdyEcho(SpdyVersion.SPDY_3_1);
}

View File

@ -42,7 +42,6 @@ public class SpdyFrameDecoderTest {
@Test
public void testTooLargeHeaderNameOnSynStreamRequest() throws Exception {
testTooLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3);
testTooLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3_1);
}
@ -94,7 +93,6 @@ public class SpdyFrameDecoderTest {
@Test
public void testLargeHeaderNameOnSynStreamRequest() throws Exception {
testLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3);
testLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3_1);
}

View File

@ -200,37 +200,31 @@ public class SpdySessionHandlerTest {
@Test
public void testSpdyClientSessionHandler() {
testSpdySessionHandler(SpdyVersion.SPDY_3, false);
testSpdySessionHandler(SpdyVersion.SPDY_3_1, false);
}
@Test
public void testSpdyClientSessionHandlerPing() {
testSpdySessionHandlerPing(SpdyVersion.SPDY_3, false);
testSpdySessionHandlerPing(SpdyVersion.SPDY_3_1, false);
}
@Test
public void testSpdyClientSessionHandlerGoAway() {
testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3, false);
testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3_1, false);
}
@Test
public void testSpdyServerSessionHandler() {
testSpdySessionHandler(SpdyVersion.SPDY_3, true);
testSpdySessionHandler(SpdyVersion.SPDY_3_1, true);
}
@Test
public void testSpdyServerSessionHandlerPing() {
testSpdySessionHandlerPing(SpdyVersion.SPDY_3, true);
testSpdySessionHandlerPing(SpdyVersion.SPDY_3_1, true);
}
@Test
public void testSpdyServerSessionHandlerGoAway() {
testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3, true);
testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3_1, true);
}