mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-08 23:07:46 +07:00
Changed signatures for packet processing calls from Channel to ChannelHandlerContext
This commit is contained in:
@ -1,8 +1,8 @@
|
|||||||
package com.riiablo.net;
|
package com.riiablo.net;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
|
||||||
public interface PacketProcessor {
|
public interface PacketProcessor {
|
||||||
void processPacket(Channel ch, ByteBuf bb);
|
void processPacket(ChannelHandlerContext ctx, ByteBuf bb);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,6 @@ public abstract class MessageChannel implements ReliablePacketController.PacketL
|
|||||||
|
|
||||||
public interface PacketTransceiver {
|
public interface PacketTransceiver {
|
||||||
void sendPacket(ByteBuf bb);
|
void sendPacket(ByteBuf bb);
|
||||||
void receivePacket(ByteBuf bb);
|
void receivePacket(ChannelHandlerContext ctx, ByteBuf bb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,8 +120,8 @@ public class ReliableEndpoint implements Endpoint<DatagramPacket>, MessageChanne
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receivePacket(ByteBuf bb) {
|
public void receivePacket(ChannelHandlerContext ctx, ByteBuf bb) {
|
||||||
packetProcessor.processPacket(channel, bb);
|
packetProcessor.processPacket(ctx, bb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Stats stats = new Stats();
|
public static final Stats stats = new Stats();
|
||||||
|
@ -267,7 +267,7 @@ public class ReliablePacketController {
|
|||||||
if (!isStale && !isAck) {
|
if (!isStale && !isAck) {
|
||||||
if (DEBUG_RECEIVE) Log.debug(TAG, "processing packet %d", sequence);
|
if (DEBUG_RECEIVE) Log.debug(TAG, "processing packet %d", sequence);
|
||||||
ByteBuf slice = bb.readSlice(bb.readableBytes());
|
ByteBuf slice = bb.readSlice(bb.readableBytes());
|
||||||
channel.onPacketProcessed(sequence, slice);
|
channel.onPacketProcessed(ctx, sequence, slice);
|
||||||
synchronized (receivedPackets) {
|
synchronized (receivedPackets) {
|
||||||
ReceivedPacketData receivedPacketData = receivedPackets.insert(sequence);
|
ReceivedPacketData receivedPacketData = receivedPackets.insert(sequence);
|
||||||
receivedPacketData.time = time;
|
receivedPacketData.time = time;
|
||||||
@ -285,7 +285,7 @@ public class ReliablePacketController {
|
|||||||
if (DEBUG_RECEIVE) Log.debug(TAG, "acked packet %d", ackSequence);
|
if (DEBUG_RECEIVE) Log.debug(TAG, "acked packet %d", ackSequence);
|
||||||
ReliableEndpoint.stats.NUM_PACKETS_ACKED++;
|
ReliableEndpoint.stats.NUM_PACKETS_ACKED++;
|
||||||
sentPacketData.acked = true;
|
sentPacketData.acked = true;
|
||||||
channel.onAckProcessed(ackSequence);
|
channel.onAckProcessed(ctx, ackSequence);
|
||||||
|
|
||||||
float rtt = (time - sentPacketData.time) * 1000f;
|
float rtt = (time - sentPacketData.time) * 1000f;
|
||||||
if ((this.rtt == 0.0f && rtt > 0.0f) || MathUtils.isEqual(this.rtt, rtt, TOLERANCE)) {
|
if ((this.rtt == 0.0f && rtt > 0.0f) || MathUtils.isEqual(this.rtt, rtt, TOLERANCE)) {
|
||||||
@ -315,7 +315,7 @@ public class ReliablePacketController {
|
|||||||
|
|
||||||
public interface PacketListener {
|
public interface PacketListener {
|
||||||
void onPacketTransmitted(ByteBuf bb);
|
void onPacketTransmitted(ByteBuf bb);
|
||||||
void onAckProcessed(int sequence);
|
void onAckProcessed(ChannelHandlerContext ctx, int sequence);
|
||||||
void onPacketProcessed(int sequence, ByteBuf bb);
|
void onPacketProcessed(ChannelHandlerContext ctx, int sequence, ByteBuf bb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ public class ReliableMessageChannel extends MessageChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAckProcessed(int sequence) {
|
public void onAckProcessed(ChannelHandlerContext ctx, int sequence) {
|
||||||
if (DEBUG_RECEIVE) Log.debug(TAG, "onAckProcessed " + sequence);
|
if (DEBUG_RECEIVE) Log.debug(TAG, "onAckProcessed " + sequence);
|
||||||
// first, map sequence to message IDs and ack them
|
// first, map sequence to message IDs and ack them
|
||||||
OutgoingPacketSet outgoingPacket = ackBuffer.find(sequence);
|
OutgoingPacketSet outgoingPacket = ackBuffer.find(sequence);
|
||||||
@ -290,9 +290,9 @@ public class ReliableMessageChannel extends MessageChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 (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
|
// TODO: this is different from original function, see above note within #sendMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,14 +25,14 @@ public class UnreliableMessageChannel extends MessageChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAckProcessed(int sequence) {
|
public void onAckProcessed(ChannelHandlerContext ctx, int sequence) {
|
||||||
if (DEBUG_RECEIVE) Log.debug(TAG, "onAckProcessed " + sequence);
|
if (DEBUG_RECEIVE) Log.debug(TAG, "onAckProcessed " + sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 (DEBUG_RECEIVE) Log.debug(TAG, "onPacketProcessed " + sequence + " " + bb);
|
||||||
packetTransceiver.receivePacket(bb);
|
packetTransceiver.receivePacket(ctx, bb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,16 +53,16 @@ public class UnreliableOrderedMessageChannel extends MessageChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAckProcessed(int sequence) {
|
public void onAckProcessed(ChannelHandlerContext ctx, int sequence) {
|
||||||
if (DEBUG_RECEIVE) Log.debug(TAG, "onAckProcessed " + sequence);
|
if (DEBUG_RECEIVE) Log.debug(TAG, "onAckProcessed " + sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 (DEBUG_RECEIVE) Log.debug(TAG, "onPacketProcessed " + sequence + " " + bb);
|
||||||
if (sequence == nextSequence || ReliableUtils.sequenceGreaterThan(sequence, nextSequence)) {
|
if (sequence == nextSequence || ReliableUtils.sequenceGreaterThan(sequence, nextSequence)) {
|
||||||
nextSequence = (sequence + 1) & Packet.USHORT_MAX_VALUE;
|
nextSequence = (sequence + 1) & Packet.USHORT_MAX_VALUE;
|
||||||
packetTransceiver.receivePacket(bb);
|
packetTransceiver.receivePacket(ctx, bb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public class TcpEndpoint implements Endpoint<ByteBuf> {
|
|||||||
@Override
|
@Override
|
||||||
public void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) {
|
public void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) {
|
||||||
if (DEBUG_RECEIVE) Gdx.app.debug(TAG, "onMessageReceived");
|
if (DEBUG_RECEIVE) Gdx.app.debug(TAG, "onMessageReceived");
|
||||||
packetProcessor.processPacket(channel, msg);
|
packetProcessor.processPacket(ctx, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,8 +4,8 @@ import com.google.flatbuffers.FlatBufferBuilder;
|
|||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
@ -93,7 +93,7 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processPacket(Channel ch, ByteBuf bb) {
|
public void processPacket(ChannelHandlerContext ctx, ByteBuf bb) {
|
||||||
Gdx.app.debug(TAG, "Processing packet...");
|
Gdx.app.debug(TAG, "Processing packet...");
|
||||||
Gdx.app.log(TAG, ByteBufUtil.hexDump(bb));
|
Gdx.app.log(TAG, ByteBufUtil.hexDump(bb));
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ package com.riiablo.net.reliable;
|
|||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
@ -81,7 +81,7 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processPacket(Channel ch, ByteBuf bb) {
|
public void processPacket(ChannelHandlerContext ctx, ByteBuf bb) {
|
||||||
Gdx.app.debug(TAG, "Processing packet...");
|
Gdx.app.debug(TAG, "Processing packet...");
|
||||||
Gdx.app.log(TAG, ByteBufUtil.hexDump(bb));
|
Gdx.app.log(TAG, ByteBufUtil.hexDump(bb));
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ import com.google.flatbuffers.FlatBufferBuilder;
|
|||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
@ -95,7 +95,7 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processPacket(Channel ch, ByteBuf bb) {
|
public void processPacket(ChannelHandlerContext ctx, ByteBuf bb) {
|
||||||
Gdx.app.debug(TAG, "Processing packet...");
|
Gdx.app.debug(TAG, "Processing packet...");
|
||||||
Gdx.app.log(TAG, ByteBufUtil.hexDump(bb));
|
Gdx.app.log(TAG, ByteBufUtil.hexDump(bb));
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ package com.riiablo.net.tcp;
|
|||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
@ -81,7 +81,7 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processPacket(Channel ch, ByteBuf bb) {
|
public void processPacket(ChannelHandlerContext ctx, ByteBuf bb) {
|
||||||
Gdx.app.debug(TAG, "Processing packet...");
|
Gdx.app.debug(TAG, "Processing packet...");
|
||||||
Gdx.app.log(TAG, " " + ByteBufUtil.hexDump(bb));
|
Gdx.app.log(TAG, " " + ByteBufUtil.hexDump(bb));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user