并发优化,不兼容以前的客户端

master
fengfei 7 years ago
parent b398ec123d
commit 0814561759
  1. 4
      proxy-client/src/main/java/org/fengfei/lanproxy/client/handlers/ClientChannelHandler.java
  2. 4
      proxy-client/src/main/java/org/fengfei/lanproxy/client/handlers/RealServerChannelHandler.java
  3. 13
      proxy-protocol/src/main/java/org/fengfei/lanproxy/protocol/ProxyMessage.java
  4. 6
      proxy-server/src/main/java/org/fengfei/lanproxy/server/handlers/ServerChannelHandler.java
  5. 4
      proxy-server/src/main/java/org/fengfei/lanproxy/server/handlers/UserChannelHandler.java

@ -49,10 +49,10 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
case ProxyMessage.TYPE_DISCONNECT:
handleDisconnectMessage(ctx, proxyMessage);
break;
case ProxyMessage.TYPE_TRANSFER:
case ProxyMessage.P_TYPE_TRANSFER:
handleTransferMessage(ctx, proxyMessage);
break;
case ProxyMessage.TYPE_WRITE_CONTROL:
case ProxyMessage.C_TYPE_WRITE_CONTROL:
handleWriteControlMessage(ctx, proxyMessage);
break;
default:

@ -30,7 +30,7 @@ public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBu
buf.readBytes(bytes);
String userId = ClientChannelMannager.getRealServerChannelUserId(realServerChannel);
ProxyMessage proxyMessage = new ProxyMessage();
proxyMessage.setType(ProxyMessage.TYPE_TRANSFER);
proxyMessage.setType(ProxyMessage.P_TYPE_TRANSFER);
proxyMessage.setUri(userId);
proxyMessage.setData(bytes);
channel.writeAndFlush(proxyMessage);
@ -67,7 +67,7 @@ public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBu
Channel channel = ClientChannelMannager.getCmdChannel();
if (channel != null) {
ProxyMessage proxyMessage = new ProxyMessage();
proxyMessage.setType(ProxyMessage.TYPE_WRITE_CONTROL);
proxyMessage.setType(ProxyMessage.C_TYPE_WRITE_CONTROL);
proxyMessage.setUri(userId);
proxyMessage.setData(realServerChannel.isWritable() ? new byte[] { 0x01 } : new byte[] { 0x00 });
channel.writeAndFlush(proxyMessage);

@ -14,10 +14,10 @@ public class ProxyMessage {
public static final byte TYPE_HEARTBEAT = 0x07;
/** 认证消息,检测clientKey是否正确 */
public static final byte TYPE_AUTH = 0x01;
public static final byte C_TYPE_AUTH = 0x01;
/** 保活确认消息 */
public static final byte TYPE_ACK = 0x02;
// /** 保活确认消息 */
// public static final byte TYPE_ACK = 0x02;
/** 代理后端服务器建立连接消息 */
public static final byte TYPE_CONNECT = 0x03;
@ -26,10 +26,10 @@ public class ProxyMessage {
public static final byte TYPE_DISCONNECT = 0x04;
/** 代理数据传输 */
public static final byte TYPE_TRANSFER = 0x05;
public static final byte P_TYPE_TRANSFER = 0x05;
/** 用户与代理服务器以及代理客户端与真实服务器连接是否可写状态同步 */
public static final byte TYPE_WRITE_CONTROL = 0x06;
public static final byte C_TYPE_WRITE_CONTROL = 0x06;
/** 消息类型 */
private byte type;
@ -77,8 +77,7 @@ public class ProxyMessage {
@Override
public String toString() {
return "ProxyMessage [type=" + type + ", serialNumber=" + serialNumber + ", uri=" + uri + ", data="
+ Arrays.toString(data) + "]";
return "ProxyMessage [type=" + type + ", serialNumber=" + serialNumber + ", uri=" + uri + ", data=" + Arrays.toString(data) + "]";
}
}

@ -32,7 +32,7 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
case ProxyMessage.TYPE_HEARTBEAT:
handleHeartbeatMessage(ctx, proxyMessage);
break;
case ProxyMessage.TYPE_AUTH:
case ProxyMessage.C_TYPE_AUTH:
handleAuthMessage(ctx, proxyMessage);
break;
case ProxyMessage.TYPE_CONNECT:
@ -41,10 +41,10 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
case ProxyMessage.TYPE_DISCONNECT:
handleDisconnectMessage(ctx, proxyMessage);
break;
case ProxyMessage.TYPE_TRANSFER:
case ProxyMessage.P_TYPE_TRANSFER:
handleTransferMessage(ctx, proxyMessage);
break;
case ProxyMessage.TYPE_WRITE_CONTROL:
case ProxyMessage.C_TYPE_WRITE_CONTROL:
handleWriteControlMessage(ctx, proxyMessage);
break;
default:

@ -42,7 +42,7 @@ public class UserChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
buf.readBytes(bytes);
String userId = ProxyChannelManager.getUserChannelUserId(userChannel);
ProxyMessage proxyMessage = new ProxyMessage();
proxyMessage.setType(ProxyMessage.TYPE_TRANSFER);
proxyMessage.setType(ProxyMessage.P_TYPE_TRANSFER);
proxyMessage.setUri(userId);
proxyMessage.setData(bytes);
proxyChannel.writeAndFlush(proxyMessage);
@ -124,7 +124,7 @@ public class UserChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
// 通知代理客户端,用户连接可写状态
String userId = ProxyChannelManager.getUserChannelUserId(userChannel);
ProxyMessage proxyMessage = new ProxyMessage();
proxyMessage.setType(ProxyMessage.TYPE_WRITE_CONTROL);
proxyMessage.setType(ProxyMessage.C_TYPE_WRITE_CONTROL);
proxyMessage.setUri(userId);
proxyMessage.setData(userChannel.isWritable() ? new byte[] { 0x01 } : new byte[] { 0x00 });
cmdChannel.writeAndFlush(proxyMessage);

Loading…
Cancel
Save