Search in sources :

Example 6 with ConnectionException

use of com.webpieces.http2parser.api.dto.error.ConnectionException 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 7 with ConnectionException

use of com.webpieces.http2parser.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class HeadersMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    HeadersFrame frame = new HeadersFrame();
    super.unmarshalFrame(state, frame);
    byte flagsByte = state.getFrameHeaderData().getFlagsByte();
    frame.setEndOfStream((flagsByte & 0x1) == 0x1);
    frame.setEndHeaders((flagsByte & 0x4) == 0x4);
    boolean isPadded = (flagsByte & 0x8) == 0x8;
    PriorityDetails priorityDetails = null;
    if ((flagsByte & 0x20) == 0x20) {
        priorityDetails = new PriorityDetails();
        frame.setPriorityDetails(priorityDetails);
    }
    DataSplit padSplit = PaddingUtil.extractPayloadAndPadding(isPadded, framePayloadData, frame.getStreamId());
    frame.setPadding(padSplit.getPadding());
    DataWrapper paddingStripped = padSplit.getPayload();
    if (priorityDetails != null) {
        //1 bit Exclusive flag, 31 bits stream dependency, and 8 bits weight = 5 bytes....
        List<? extends DataWrapper> split = dataGen.split(paddingStripped, 5);
        ByteBuffer preludeBytes = bufferPool.createWithDataWrapper(split.get(0));
        int firstInt = preludeBytes.getInt();
        priorityDetails.setStreamDependencyIsExclusive((firstInt >>> 31) == 0x1);
        int streamDependency = firstInt & 0x7FFFFFFF;
        if (streamDependency == frame.getStreamId()) {
            // Can't depend on self
            throw new ConnectionException(CancelReasonCode.BAD_STREAM_DEPENDENCY, streamDependency, "stream id=" + streamDependency + " depends on itself");
        }
        priorityDetails.setStreamDependency(streamDependency);
        priorityDetails.setWeight((short) (preludeBytes.get() & 0xFF));
        frame.setHeaderFragment(split.get(1));
        bufferPool.releaseBuffer(preludeBytes);
    } else {
        frame.setHeaderFragment(paddingStripped);
    }
    if (frame.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "headers frame had invalid stream id=" + frame.getStreamId());
    return frame;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PriorityDetails(com.webpieces.http2parser.api.dto.lib.PriorityDetails) HeadersFrame(com.webpieces.http2parser.api.dto.HeadersFrame) ByteBuffer(java.nio.ByteBuffer) DataSplit(com.webpieces.http2parser.impl.DataSplit) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 8 with ConnectionException

use of com.webpieces.http2parser.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class HeadersMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    HeadersFrame castFrame = (HeadersFrame) frame;
    if (frame.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "Headers frame cannot be streamId 0");
    int paddingSize = castFrame.getPadding().getReadableSize();
    byte value = 0x0;
    if (castFrame.isEndOfStream())
        value |= 0x1;
    if (castFrame.isEndHeaders())
        value |= 0x4;
    if (paddingSize > 0)
        value |= 0x8;
    if (castFrame.isPriority())
        value |= 0x20;
    DataWrapper preludeDW;
    PriorityDetails priorityDetails = castFrame.getPriorityDetails();
    if (priorityDetails != null) {
        preludeDW = PriorityMarshaller.marshalPriorityDetails(bufferPool, priorityDetails, frame);
    } else {
        preludeDW = dataGen.emptyWrapper();
    }
    DataWrapper unpadded = dataGen.chainDataWrappers(preludeDW, castFrame.getHeaderFragment());
    DataWrapper payload = PaddingUtil.padDataIfNeeded(unpadded, castFrame.getPadding());
    return super.marshalFrame(frame, value, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PriorityDetails(com.webpieces.http2parser.api.dto.lib.PriorityDetails) HeadersFrame(com.webpieces.http2parser.api.dto.HeadersFrame) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 9 with ConnectionException

use of com.webpieces.http2parser.api.dto.error.ConnectionException 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 10 with ConnectionException

use of com.webpieces.http2parser.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class Level6LocalFlowControl method fireDataToClient.

public CompletableFuture<Void> fireDataToClient(Stream stream, StreamMsg payload) {
    if (!(payload instanceof DataFrame))
        return notifyListener.sendPieceToApp(stream, payload);
    DataFrame f = (DataFrame) payload;
    long frameLength = f.getTransmitFrameLength();
    if (frameLength > connectionLocalWindowSize) {
        throw new ConnectionException(CancelReasonCode.FLOW_CONTROL_ERROR, logId, f.getStreamId(), "connectionLocalWindowSize too small=" + connectionLocalWindowSize + " frame len=" + frameLength + " for frame=" + f);
    } else if (frameLength > stream.getLocalWindowSize()) {
        throw new StreamException(CancelReasonCode.FLOW_CONTROL_ERROR, logId, f.getStreamId(), "connectionLocalWindowSize too small=" + connectionLocalWindowSize + " frame len=" + frameLength + " for frame=" + f);
    }
    totalSent += frameLength;
    connectionLocalWindowSize -= frameLength;
    stream.incrementLocalWindow(-frameLength);
    log.info("received framelen=" + frameLength + " newConnectionWindowSize=" + connectionLocalWindowSize + " streamSize=" + stream.getLocalWindowSize() + " totalSent=" + totalSent);
    return notifyListener.sendPieceToApp(stream, payload).thenApply(c -> updateFlowControl(frameLength, stream));
}
Also used : DataFrame(com.webpieces.http2parser.api.dto.DataFrame) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) StreamException(com.webpieces.http2parser.api.dto.error.StreamException)

Aggregations

ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)24 ByteBuffer (java.nio.ByteBuffer)8 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)5 DataWrapper (org.webpieces.data.api.DataWrapper)5 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)4 StreamException (com.webpieces.http2parser.api.dto.error.StreamException)4 HeadersFrame (com.webpieces.http2parser.api.dto.HeadersFrame)3 PriorityDetails (com.webpieces.http2parser.api.dto.lib.PriorityDetails)3 DataSplit (com.webpieces.http2parser.impl.DataSplit)3 DataTry (com.webpieces.http2engine.impl.DataTry)2 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)2 PingFrame (com.webpieces.http2parser.api.dto.PingFrame)2 PriorityFrame (com.webpieces.http2parser.api.dto.PriorityFrame)2 PushPromiseFrame (com.webpieces.http2parser.api.dto.PushPromiseFrame)2 RstStreamFrame (com.webpieces.http2parser.api.dto.RstStreamFrame)2 SettingsFrame (com.webpieces.http2parser.api.dto.SettingsFrame)2 UnknownFrame (com.webpieces.http2parser.api.dto.UnknownFrame)2 WindowUpdateFrame (com.webpieces.http2parser.api.dto.WindowUpdateFrame)2 HasHeaderFragment (com.webpieces.http2parser.api.dto.lib.HasHeaderFragment)2 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)2