Skip to content

Commit

Permalink
fix: catch exception in NettyPacketUdpDecoder and print it only in de…
Browse files Browse the repository at this point in the history
…bug mode
  • Loading branch information
Apehum committed Mar 31, 2024
1 parent d2b8590 commit b0842af
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.socket.DatagramPacket;
import io.netty.handler.codec.MessageToMessageDecoder;
import su.plo.voice.BaseVoice;
import su.plo.voice.proto.packets.udp.PacketUdp;
import su.plo.voice.proto.packets.udp.PacketUdpCodec;

Expand All @@ -13,6 +14,11 @@

public final class NettyPacketUdpDecoder extends MessageToMessageDecoder<DatagramPacket> {

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
BaseVoice.DEBUG_LOGGER.log("Failed to decode packet", cause);
}

@Override
protected void decode(ChannelHandlerContext ctx, DatagramPacket packet, List<Object> out) throws Exception {
byte[] bytes = ByteBufUtil.getBytes(packet.content());
Expand All @@ -21,11 +27,6 @@ protected void decode(ChannelHandlerContext ctx, DatagramPacket packet, List<Obj
if (!packetUdp.isPresent()) return;
PacketUdp decoded = packetUdp.get();

// if (System.currentTimeMillis() - decoded.getTimestamp() > PacketUdp.TTL) {
// System.out.println(System.currentTimeMillis() - decoded.getTimestamp());
// return;
// }

out.add(new NettyPacketUdp(packet, bytes, decoded));
}
}

0 comments on commit b0842af

Please sign in to comment.