Search in sources :

Example 1 with FrameHeaderData

use of com.webpieces.http2parser.impl.FrameHeaderData in project webpieces by deanhiller.

the class RstStreamMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    int streamId = frameHeaderData.getStreamId();
    if (state.getFrameHeaderData().getPayloadLength() != 4)
        throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "rststream size not 4 and instead is=" + state.getFrameHeaderData().getPayloadLength());
    else if (frameHeaderData.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frameHeaderData.getStreamId(), "rst stream cannot be streamid 0 and was=" + frameHeaderData.getStreamId());
    RstStreamFrame frame = new RstStreamFrame();
    super.unmarshalFrame(state, frame);
    ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(framePayloadData);
    long errorCode = UnsignedData.getUnsignedInt(payloadByteBuffer);
    frame.setErrorCode(errorCode);
    bufferPool.releaseBuffer(payloadByteBuffer);
    return frame;
}
Also used : RstStreamFrame(com.webpieces.http2parser.api.dto.RstStreamFrame) FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 2 with FrameHeaderData

use of com.webpieces.http2parser.impl.FrameHeaderData in project webpieces by deanhiller.

the class SettingsMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper payload) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    int payloadLength = frameHeaderData.getPayloadLength();
    int streamId = frameHeaderData.getStreamId();
    SettingsFrame frame = new SettingsFrame();
    super.unmarshalFrame(state, frame);
    byte flags = state.getFrameHeaderData().getFlagsByte();
    frame.setAck((flags & 0x1) == 0x1);
    if (frame.isAck()) {
        if (payloadLength != 0) {
            throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "size of payload of a settings frame ack must be 0 but was=" + payloadLength);
        }
    } else if (payloadLength % 6 != 0) {
        throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "payload size must be a multiple of 6 but was=" + state.getFrameHeaderData().getPayloadLength());
    } else if (streamId != 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, streamId, "settings frame had stream id=" + streamId);
    ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(payload);
    List<Http2Setting> settingsList = unmarshal(payloadByteBuffer);
    frame.setSettings(settingsList);
    bufferPool.releaseBuffer(payloadByteBuffer);
    return frame;
}
Also used : SettingsFrame(com.webpieces.http2parser.api.dto.SettingsFrame) Http2Setting(com.webpieces.http2parser.api.dto.lib.Http2Setting) FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 3 with FrameHeaderData

use of com.webpieces.http2parser.impl.FrameHeaderData in project webpieces by deanhiller.

the class WindowUpdateMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper payload) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    int streamId = frameHeaderData.getStreamId();
    if (state.getFrameHeaderData().getPayloadLength() != 4)
        throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "window update size not 4 and instead is=" + state.getFrameHeaderData().getPayloadLength());
    WindowUpdateFrame frame = new WindowUpdateFrame();
    super.unmarshalFrame(state, frame);
    ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(payload);
    frame.setWindowSizeIncrement(payloadByteBuffer.getInt());
    bufferPool.releaseBuffer(payloadByteBuffer);
    if (frame.getWindowSizeIncrement() == 0)
        throw new ConnectionException(CancelReasonCode.WINDOW_SIZE_INVALID, streamId, "Window size increment cannot be 0 per http/2 spec and was");
    return frame;
}
Also used : WindowUpdateFrame(com.webpieces.http2parser.api.dto.WindowUpdateFrame) FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 4 with FrameHeaderData

use of com.webpieces.http2parser.impl.FrameHeaderData in project webpieces by deanhiller.

the class PingMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    int streamId = frameHeaderData.getStreamId();
    if (state.getFrameHeaderData().getPayloadLength() != 8)
        throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "ping size not 8 and instead is=" + state.getFrameHeaderData().getPayloadLength());
    else if (streamId != 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, streamId, "streamId on ping needs to be 0 but was=" + streamId);
    //TODO: Verify this, previous code looks like connectionlevel = false but shouldn't this be true
    PingFrame frame = new PingFrame();
    super.unmarshalFrame(state, frame);
    byte flags = state.getFrameHeaderData().getFlagsByte();
    frame.setIsPingResponse((flags & 0x1) == 0x1);
    ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(framePayloadData);
    frame.setOpaqueData(payloadByteBuffer.getLong());
    bufferPool.releaseBuffer(payloadByteBuffer);
    if (frame.getStreamId() != 0)
        throw new IllegalArgumentException("PingFrame can never be any other stream id except 0 which is already set");
    return frame;
}
Also used : PingFrame(com.webpieces.http2parser.api.dto.PingFrame) FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 5 with FrameHeaderData

use of com.webpieces.http2parser.impl.FrameHeaderData in project webpieces by deanhiller.

the class AbstractFrameMarshaller method unmarshalFrame.

public void unmarshalFrame(Http2MementoImpl state, Http2Frame frame) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    frame.setStreamId(frameHeaderData.getStreamId());
}
Also used : FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData)

Aggregations

FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)6 ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)5 ByteBuffer (java.nio.ByteBuffer)5 PingFrame (com.webpieces.http2parser.api.dto.PingFrame)1 PriorityFrame (com.webpieces.http2parser.api.dto.PriorityFrame)1 RstStreamFrame (com.webpieces.http2parser.api.dto.RstStreamFrame)1 SettingsFrame (com.webpieces.http2parser.api.dto.SettingsFrame)1 WindowUpdateFrame (com.webpieces.http2parser.api.dto.WindowUpdateFrame)1 StreamException (com.webpieces.http2parser.api.dto.error.StreamException)1 Http2Setting (com.webpieces.http2parser.api.dto.lib.Http2Setting)1 PriorityDetails (com.webpieces.http2parser.api.dto.lib.PriorityDetails)1