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;
}
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());
}
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());
}
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);
}
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);
}
Aggregations