udp代理优化.

This commit is contained in:
aoshiguchen
2023-09-23 10:56:45 +08:00
parent 35327cc9a5
commit 3cf64596c6
3 changed files with 12 additions and 3 deletions
@@ -41,6 +41,8 @@ public class UdpVisitorChannelHandler extends SimpleChannelInboundHandler<Datagr
// ctx.channel().close();
return;
}
proxyChannel.attr(Constants.SENDER).set(datagramPacket.sender());
String targetIp = proxyChannel.attr(Constants.TARGET_IP).get();
int targetPort = proxyChannel.attr(Constants.TARGET_PORT).get();
Integer proxyResponses = proxyChannel.attr(Constants.PROXY_RESPONSES).get();
@@ -35,9 +35,13 @@ public class UdpProxyMessageTransferHandler implements ProxyMessageHandler {
Channel visitorChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
if (null != visitorChannel) {
InetSocketAddress address = new InetSocketAddress(udpBaseInfo.getVisitorIp(), udpBaseInfo.getVisitorPort());
ByteBuf byteBuf = Unpooled.copiedBuffer(proxyMessage.getData());
visitorChannel.writeAndFlush(new DatagramPacket(byteBuf, address));
// InetSocketAddress address = new InetSocketAddress(udpBaseInfo.getVisitorIp(), udpBaseInfo.getVisitorPort());
// ByteBuf byteBuf = Unpooled.copiedBuffer(proxyMessage.getData());
// visitorChannel.writeAndFlush(new DatagramPacket(byteBuf, address));
InetSocketAddress address = ctx.channel().attr(Constants.SENDER).get();
if (null != address) {
visitorChannel.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(proxyMessage.getData()), address));
}
// 增加流量计数(TODO 如果UDP映射服务端端口修改,这个似乎不准)
Integer licenseId = visitorChannel.attr(Constants.LICENSE_ID).get();