Changed signatures for packet processing calls from Channel to ChannelHandlerContext

This commit is contained in:
Collin Smith
2020-06-25 17:29:20 -07:00
parent 57a8c1167e
commit dac10467fa
12 changed files with 27 additions and 27 deletions

View File

@ -1,8 +1,8 @@
package com.riiablo.net;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
public interface PacketProcessor {
void processPacket(Channel ch, ByteBuf bb);
void processPacket(ChannelHandlerContext ctx, ByteBuf bb);
}

View File

@ -37,6 +37,6 @@ public abstract class MessageChannel implements ReliablePacketController.PacketL
public interface PacketTransceiver {
void sendPacket(ByteBuf bb);
void receivePacket(ByteBuf bb);
void receivePacket(ChannelHandlerContext ctx, ByteBuf bb);
}
}

View File

@ -120,8 +120,8 @@ public class ReliableEndpoint implements Endpoint<DatagramPacket>, MessageChanne
}
@Override
public void receivePacket(ByteBuf bb) {
packetProcessor.processPacket(channel, bb);
public void receivePacket(ChannelHandlerContext ctx, ByteBuf bb) {
packetProcessor.processPacket(ctx, bb);
}
public static final Stats stats = new Stats();

View File

@ -267,7 +267,7 @@ public class ReliablePacketController {
if (!isStale && !isAck) {
if (DEBUG_RECEIVE) Log.debug(TAG, "processing packet %d", sequence);
ByteBuf slice = bb.readSlice(bb.readableBytes());
channel.onPacketProcessed(sequence, slice);
channel.onPacketProcessed(ctx, sequence, slice);
synchronized (receivedPackets) {
ReceivedPacketData receivedPacketData = receivedPackets.insert(sequence);
receivedPacketData.time = time;
@ -285,7 +285,7 @@ public class ReliablePacketController {
if (DEBUG_RECEIVE) Log.debug(TAG, "acked packet %d", ackSequence);
ReliableEndpoint.stats.NUM_PACKETS_ACKED++;
sentPacketData.acked = true;
channel.onAckProcessed(ackSequence);
channel.onAckProcessed(ctx, ackSequence);
float rtt = (time - sentPacketData.time) * 1000f;
if ((this.rtt == 0.0f && rtt > 0.0f) || MathUtils.isEqual(this.rtt, rtt, TOLERANCE)) {
@ -315,7 +315,7 @@ public class ReliablePacketController {
public interface PacketListener {
void onPacketTransmitted(ByteBuf bb);
void onAckProcessed(int sequence);
void onPacketProcessed(int sequence, ByteBuf bb);
void onAckProcessed(ChannelHandlerContext ctx, int sequence);
void onPacketProcessed(ChannelHandlerContext ctx, int sequence, ByteBuf bb);
}
}

View File

@ -256,7 +256,7 @@ public class ReliableMessageChannel extends MessageChannel {
}
@Override
public void onAckProcessed(int sequence) {
public void onAckProcessed(ChannelHandlerContext ctx, int sequence) {
if (DEBUG_RECEIVE) Log.debug(TAG, "onAckProcessed " + sequence);
// first, map sequence to message IDs and ack them
OutgoingPacketSet outgoingPacket = ackBuffer.find(sequence);
@ -290,9 +290,9 @@ public class ReliableMessageChannel extends MessageChannel {
}
@Override
public void onPacketProcessed(int sequence, ByteBuf bb) {
public void onPacketProcessed(ChannelHandlerContext ctx, int sequence, ByteBuf bb) {
if (DEBUG_RECEIVE) Log.debug(TAG, "onPacketProcessed " + sequence + " " + bb);
packetTransceiver.receivePacket(bb);
packetTransceiver.receivePacket(ctx, bb);
// TODO: this is different from original function, see above note within #sendMessage
}

View File

@ -25,14 +25,14 @@ public class UnreliableMessageChannel extends MessageChannel {
}
@Override
public void onAckProcessed(int sequence) {
public void onAckProcessed(ChannelHandlerContext ctx, int sequence) {
if (DEBUG_RECEIVE) Log.debug(TAG, "onAckProcessed " + sequence);
}
@Override
public void onPacketProcessed(int sequence, ByteBuf bb) {
public void onPacketProcessed(ChannelHandlerContext ctx, int sequence, ByteBuf bb) {
if (DEBUG_RECEIVE) Log.debug(TAG, "onPacketProcessed " + sequence + " " + bb);
packetTransceiver.receivePacket(bb);
packetTransceiver.receivePacket(ctx, bb);
}
@Override

View File

@ -53,16 +53,16 @@ public class UnreliableOrderedMessageChannel extends MessageChannel {
}
@Override
public void onAckProcessed(int sequence) {
public void onAckProcessed(ChannelHandlerContext ctx, int sequence) {
if (DEBUG_RECEIVE) Log.debug(TAG, "onAckProcessed " + sequence);
}
@Override
public void onPacketProcessed(int sequence, ByteBuf bb) {
public void onPacketProcessed(ChannelHandlerContext ctx, int sequence, ByteBuf bb) {
if (DEBUG_RECEIVE) Log.debug(TAG, "onPacketProcessed " + sequence + " " + bb);
if (sequence == nextSequence || ReliableUtils.sequenceGreaterThan(sequence, nextSequence)) {
nextSequence = (sequence + 1) & Packet.USHORT_MAX_VALUE;
packetTransceiver.receivePacket(bb);
packetTransceiver.receivePacket(ctx, bb);
}
}
}

View File

@ -34,7 +34,7 @@ public class TcpEndpoint implements Endpoint<ByteBuf> {
@Override
public void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) {
if (DEBUG_RECEIVE) Gdx.app.debug(TAG, "onMessageReceived");
packetProcessor.processPacket(channel, msg);
packetProcessor.processPacket(ctx, msg);
}
@Override

View File

@ -4,8 +4,8 @@ import com.google.flatbuffers.FlatBufferBuilder;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
@ -93,7 +93,7 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
}
@Override
public void processPacket(Channel ch, ByteBuf bb) {
public void processPacket(ChannelHandlerContext ctx, ByteBuf bb) {
Gdx.app.debug(TAG, "Processing packet...");
Gdx.app.log(TAG, ByteBufUtil.hexDump(bb));
}

View File

@ -3,8 +3,8 @@ package com.riiablo.net.reliable;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
@ -81,7 +81,7 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor {
}
@Override
public void processPacket(Channel ch, ByteBuf bb) {
public void processPacket(ChannelHandlerContext ctx, ByteBuf bb) {
Gdx.app.debug(TAG, "Processing packet...");
Gdx.app.log(TAG, ByteBufUtil.hexDump(bb));

View File

@ -4,8 +4,8 @@ import com.google.flatbuffers.FlatBufferBuilder;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
@ -95,7 +95,7 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
}
@Override
public void processPacket(Channel ch, ByteBuf bb) {
public void processPacket(ChannelHandlerContext ctx, ByteBuf bb) {
Gdx.app.debug(TAG, "Processing packet...");
Gdx.app.log(TAG, ByteBufUtil.hexDump(bb));
}

View File

@ -3,8 +3,8 @@ package com.riiablo.net.tcp;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
@ -81,7 +81,7 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor {
}
@Override
public void processPacket(Channel ch, ByteBuf bb) {
public void processPacket(ChannelHandlerContext ctx, ByteBuf bb) {
Gdx.app.debug(TAG, "Processing packet...");
Gdx.app.log(TAG, " " + ByteBufUtil.hexDump(bb));
}