Search in sources :

Example 16 with GoAwayFrame

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;
}
Also used : ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)

Example 17 with GoAwayFrame

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteBuffer(java.nio.ByteBuffer) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)

Example 18 with GoAwayFrame

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());
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

Example 19 with GoAwayFrame

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());
}
Also used : GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 20 with GoAwayFrame

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());
}
Also used : GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Aggregations

GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)27 Test (org.junit.Test)25 DataWrapper (org.webpieces.data.api.DataWrapper)18 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)11 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)7 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)7 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)5 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)4 MockStreamRef (org.webpieces.httpfrontend2.api.mock2.MockStreamRef)3 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)3 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)2 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)2 ByteBuffer (java.nio.ByteBuffer)2 ResponseStream (org.webpieces.frontend2.api.ResponseStream)2 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)2 CancelReasonCode (com.webpieces.http2.api.dto.error.CancelReasonCode)1