Skip to content

Commit

Permalink
并发优化,不兼容以前的客户端
Browse files Browse the repository at this point in the history
  • Loading branch information
ffay committed Nov 2, 2017
1 parent b398ec1 commit 0814561
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) throws Excep
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);
Expand Down Expand Up @@ -67,7 +67,7 @@ public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exceptio
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -77,8 +77,7 @@ public void setSerialNumber(long serialNumber) {

@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) + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage
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:
Expand All @@ -41,10 +41,10 @@ protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) throws Excep
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);
Expand Down Expand Up @@ -124,7 +124,7 @@ public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exceptio
// 通知代理客户端,用户连接可写状态
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);
Expand Down

0 comments on commit 0814561

Please sign in to comment.