udp代理优化.
This commit is contained in:
@@ -25,6 +25,8 @@ package org.dromara.neutrinoproxy.core;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.util.AttributeKey;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
@@ -45,6 +47,7 @@ public interface Constants {
|
||||
|
||||
// 临时解决 udp channel被close的问题
|
||||
AttributeKey<Boolean> IS_UDP_KEY = AttributeKey.newInstance("isUdp");
|
||||
AttributeKey<InetSocketAddress> SENDER = AttributeKey.newInstance("sender");
|
||||
|
||||
|
||||
int HEADER_SIZE = 4;
|
||||
|
||||
+2
@@ -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();
|
||||
|
||||
+7
-3
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user