This commit is contained in:
wujiawei
2024-09-28 16:44:05 +08:00
parent dd6daa5421
commit 0493c1ce5e
33 changed files with 211 additions and 35 deletions

View File

@ -32,4 +32,8 @@ public class InternalNetworkPermeateRealServer {
* 访问端口
*/
private Integer visitorPort;
/**
* 是否是ssl
*/
private Boolean isSsl;
}

View File

@ -5,6 +5,7 @@ import lombok.Setter;
import java.util.Arrays;
@Deprecated
@Setter
@Getter
public class NettyMsg {

View File

@ -14,7 +14,7 @@ import java.nio.charset.StandardCharsets;
@Getter
public class NettyProxyMsg {
// body 长度 type 1 clientId 4 clientTargetIp 4 clientTargetPort 4 visitorPort 4 visitorId 4 data 4
public static final int bodyLength = 1 + 4 + 4 + 4 + 4 + 4 + 4;
public static final int bodyLength = 1 + 1 + 4 + 4 + 4 + 4 + 4 + 4;
/**
@ -25,6 +25,13 @@ public class NettyProxyMsg {
*/
private byte type;
/**
* 是否是ssl
* byte 长度 1
* 1 true
* 0 false
*/
private byte isSsl = 0;
/**
* 客户端ID
* byte[] 长度 4
@ -110,4 +117,23 @@ public class NettyProxyMsg {
}
public Boolean isSsl() {
return isSsl == 1;
}
public void isSsl(Boolean isSsl) {
if (isSsl) {
this.isSsl = 1;
} else {
this.isSsl = 0;
}
}
public byte getIsSsl() {
return isSsl;
}
public void setIsSsl(byte isSsl) {
this.isSsl = isSsl;
}
}

View File

@ -109,6 +109,8 @@ public class NettyProxyMsgDecoder extends LengthFieldBasedFrameDecoder {
int bodyLength = in.readInt();
byte type = in.readByte();
nettyProxyMsg.setType(type);
byte isSsl = in.readByte();
nettyProxyMsg.setIsSsl(isSsl);
int clientIdLength = in.readInt();
byte[] clientIdBytes = new byte[clientIdLength];

View File

@ -23,6 +23,7 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
// body 长度 type 1 clientId 4 clientTargetIp 4 clientTargetPort 4 visitorPort 4 visitorId 4 data 4
int bodyLength = NettyProxyMsg.bodyLength;
byte typeBytes = msg.getType();
byte isSsl = msg.getIsSsl();
byte[] clientIdBytes = msg.getClientId();
byte[] clientTargetIpBytes = msg.getClientTargetIp();
byte[] clientTargetPortBytes = msg.getClientTargetPort();
@ -30,7 +31,6 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
byte[] visitorIdBytes = msg.getVisitorId();
byte[] msgDataBytes = msg.getData();
if (clientIdBytes != null) {
bodyLength += clientIdBytes.length;
}
@ -54,6 +54,7 @@ public class NettyProxyMsgEncoder extends MessageToByteEncoder<NettyProxyMsg> {
out.writeInt(bodyLength);
out.writeByte(typeBytes);
out.writeByte(isSsl);
// 防止数据读错位置 clientId
if (clientIdBytes != null) {