use of com.webpieces.http2.api.dto.lowlevel.GoAwayFrame in project webpieces by deanhiller.
the class GoAwayMarshaller method unmarshal.
@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
GoAwayFrame frame = new GoAwayFrame();
super.unmarshalFrame(state, frame);
int streamId = state.getFrameHeaderData().getStreamId();
if (streamId != 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, streamId, "goaway frame had stream id=" + streamId);
List<? extends DataWrapper> split = DATA_GEN.split(framePayloadData, 8);
ByteBuffer preludeBytes = bufferPool.createWithDataWrapper(split.get(0));
long lastStreamId = UnsignedData.getUnsignedInt(preludeBytes);
long errorCode = UnsignedData.getUnsignedInt(preludeBytes);
frame.setLastStreamId(lastStreamId);
frame.setErrorCode(errorCode);
frame.setDebugData(split.get(1));
bufferPool.releaseBuffer(preludeBytes);
if (frame.getStreamId() != 0)
throw new IllegalArgumentException("GoAwayFrame can never be any other stream id except 0 which is already set");
return frame;
}
use of com.webpieces.http2.api.dto.lowlevel.GoAwayFrame in project webpieces by deanhiller.
the class GoAwayMarshaller method marshal.
@Override
public DataWrapper marshal(Http2Frame frame) {
if (frame.getStreamId() != 0)
throw new IllegalArgumentException("GoAwayFrame can never be any other stream id except 0 which is already set");
GoAwayFrame castFrame = (GoAwayFrame) frame;
long originalStreamId = castFrame.getLastStreamId();
long streamId = originalStreamId & 0x7FFFFFFF;
if (streamId != originalStreamId)
throw new RuntimeException("your lastStreamId is too large per spec. frame=" + frame);
ByteBuffer prelude = bufferPool.nextBuffer(8);
UnsignedData.putUnsignedInt(prelude, castFrame.getLastStreamId());
UnsignedData.putUnsignedInt(prelude, castFrame.getErrorCode());
prelude.flip();
DataWrapper debug = DATA_GEN.emptyWrapper();
if (castFrame.getDebugData() != null)
debug = castFrame.getDebugData();
DataWrapper payload = DATA_GEN.chainDataWrappers(DATA_GEN.wrapByteBuffer(prelude), debug);
return super.marshalFrame(frame, (byte) 0, payload);
}
use of com.webpieces.http2.api.dto.lowlevel.GoAwayFrame in project webpieces by deanhiller.
the class TestS5x1StreamStates method testSection5_1_1TooLowStreamIdAfterHighStreamId.
/**
* The identifier of a newly established stream MUST be numerically
* greater than all streams that the initiating endpoint has opened
* or reserved. This governs streams that are opened using a HEADERS
* frame and streams that are reserved using PUSH_PROMISE. An endpoint
* that receives an unexpected stream identifier MUST respond with
* a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
*
* This is in conflict with another part of the spec!!!!! and so we pretend
* the stream is closed(as in all likely hood, the stream was closed)!!!
* and do not shutdown the whole connection for a case like this.
*
* The part it is in conflict with is closed state and receiving messages
* in closed state. The only way to resolve conflict would be to KEEP around
* state that a connection is closed. SORRY, the connection is closed so we
* clean up all memory!!!
*/
@Test
public void testSection5_1_1TooLowStreamIdAfterHighStreamId() {
MockStreamWriter mockWriter = new MockStreamWriter();
XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
MockStreamRef mockStream = new MockStreamRef(futA);
mockListener.addMockStreamToReturn(mockStream);
Http2Request request1 = Http2Requests.createRequest(5, true);
mockChannel.send(request1);
mockListener.getSingleRequest();
Http2Request request = Http2Requests.createRequest(3, true);
mockChannel.send(request);
// WE DO NOT DO THIS which spec wants(or another test we have starts failing)
// we leave this here in case you want to comment back in and debug that.
// //no request comes in
// Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
// //cancel the first stream since whole connection is going down.
// Assert.assertEquals(1, mockListener.getNumCancelsThatCameIn());
//
// //remote receives goAway
// GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
// Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
// DataWrapper debugData = goAway.getDebugData();
// String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
// Assert.assertTrue(msg.contains("Bad stream id. Event stream ids not allowed in requests to a server frame="));
// Assert.assertTrue(mockChannel.isClosed());
// no request comes in
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
// we do not close the channel
Assert.assertFalse(mockListener.isClosed());
// our existing streams stays valid and open
Assert.assertFalse(mockStream.isCancelled());
// remote receives goAway
RstStreamFrame frame = (RstStreamFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.STREAM_CLOSED, frame.getKnownErrorCode());
Assert.assertTrue(!mockChannel.isClosed());
}
use of com.webpieces.http2.api.dto.lowlevel.GoAwayFrame in project webpieces by deanhiller.
the class TestS6x5SettingsFrameErrors method testSection6_5_2InitialWindowSizeTooLarge.
@Test
public void testSection6_5_2InitialWindowSizeTooLarge() {
// server's settings frame is finally coming in as well with maxConcurrent=1
String badStreamIdSettings = // length
"00 00 0C" + // type
"04" + // flags
"00" + // R + streamid
"00 00 00 00" + // setting 1 (enable push)
"00 02 00 00 00 01" + // setting 2 (initial window size)
"00 04 FF FF FF FF";
mockChannel.sendHexBack(badStreamIdSettings);
// remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.FLOW_CONTROL_ERROR, goAway.getKnownErrorCode());
Assert.assertTrue(mockChannel.isClosed());
}
use of com.webpieces.http2.api.dto.lowlevel.GoAwayFrame in project webpieces by deanhiller.
the class TestS6x5SettingsFrameErrors method testSection6_5SettingsFrameLengthMultipleNotSixOctects.
@Test
public void testSection6_5SettingsFrameLengthMultipleNotSixOctects() {
// server's settings frame is finally coming in as well with maxConcurrent=1
String badStreamIdSettings = // length
"00 00 0B" + // type
"04" + // flags
"00" + // R + streamid
"00 00 00 00" + // setting 1 (enable push)
"00 02 00 00 00 01" + // setting 2 (max streams)
"00 03 00 00 01";
mockChannel.sendHexBack(badStreamIdSettings);
// remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.FRAME_SIZE_ERROR, goAway.getKnownErrorCode());
Assert.assertTrue(mockChannel.isClosed());
}
Aggregations