Search in sources :

Example 1 with PingFrame

use of com.webpieces.http2.api.dto.lowlevel.PingFrame 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.http2.api.dto.lowlevel.PingFrame) FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 2 with PingFrame

use of com.webpieces.http2.api.dto.lowlevel.PingFrame in project webpieces by deanhiller.

the class TestHttp2Ping method testParsePingFrame.

@Test
public void testParsePingFrame() {
    DataWrapper data = Util.hexToBytes(getPingFrame());
    parser.parse(memento, data);
    PingFrame frame = (PingFrame) assertGood();
    Assert.assertEquals(0, frame.getStreamId());
    Assert.assertFalse(frame.isPingResponse());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PingFrame(com.webpieces.http2.api.dto.lowlevel.PingFrame) Test(org.junit.Test)

Example 3 with PingFrame

use of com.webpieces.http2.api.dto.lowlevel.PingFrame in project webpieces by deanhiller.

the class TestHttp2Ping method testParsePongFrame.

@Test
public void testParsePongFrame() {
    DataWrapper data = Util.hexToBytes(getPongFrame());
    parser.parse(memento, data);
    PingFrame frame = (PingFrame) assertGood();
    Assert.assertEquals(0, frame.getStreamId());
    Assert.assertTrue(frame.isPingResponse());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PingFrame(com.webpieces.http2.api.dto.lowlevel.PingFrame) Test(org.junit.Test)

Example 4 with PingFrame

use of com.webpieces.http2.api.dto.lowlevel.PingFrame in project webpieces by deanhiller.

the class Level7MarshalAndPing method processPing.

public XFuture<Void> processPing(PingFrame ping) {
    if (!ping.isPingResponse()) {
        PingFrame pingAck = new PingFrame();
        pingAck.setIsPingResponse(true);
        pingAck.setOpaqueData(ping.getOpaqueData());
        return sendFrameToSocket(pingAck);
    }
    XFuture<Void> future = pingFutureRef.get();
    if (future == null)
        throw new IllegalStateException(key + "bug, this should not be possible");
    // clear the value
    pingFutureRef.compareAndSet(future, null);
    future.complete(null);
    return XFuture.completedFuture(null);
}
Also used : PingFrame(com.webpieces.http2.api.dto.lowlevel.PingFrame)

Example 5 with PingFrame

use of com.webpieces.http2.api.dto.lowlevel.PingFrame in project webpieces by deanhiller.

the class PingMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    if (frame.getStreamId() != 0)
        throw new IllegalArgumentException("PingFrame can never be any other stream id except 0 which is already set");
    PingFrame ping = (PingFrame) frame;
    ByteBuffer payload = bufferPool.nextBuffer(8);
    payload.putLong(ping.getOpaqueData());
    payload.flip();
    DataWrapper dataPayload = DATA_GEN.wrapByteBuffer(payload);
    byte value = 0x0;
    if (ping.isPingResponse())
        value |= 0x1;
    return marshalFrame(frame, value, dataPayload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PingFrame(com.webpieces.http2.api.dto.lowlevel.PingFrame) ByteBuffer(java.nio.ByteBuffer)

Aggregations

PingFrame (com.webpieces.http2.api.dto.lowlevel.PingFrame)8 Test (org.junit.Test)4 DataWrapper (org.webpieces.data.api.DataWrapper)3 ByteBuffer (java.nio.ByteBuffer)2 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)1 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)1 XFuture (org.webpieces.util.futures.XFuture)1