Skip to content

Commit

Permalink
close channel only for tcp
Browse files Browse the repository at this point in the history
  • Loading branch information
TongxiJi committed Jul 1, 2018
1 parent 7c6d46c commit 0823087
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/main/java/cn/wowspeeder/encryption/CryptBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ protected void setIV(byte[] iv, boolean isEncrypt) {
}

if (isEncrypt) {
_encryptIV = new byte[_ivLength];
System.arraycopy(iv, 0, _encryptIV, 0, _ivLength);
try {
_encryptIV = new byte[_ivLength];
System.arraycopy(iv, 0, _encryptIV, 0, _ivLength);
encCipher = getCipher(isEncrypt);
ParametersWithIV parameterIV = new ParametersWithIV(
new KeyParameter(_key.getEncoded()), _encryptIV);
Expand All @@ -56,9 +56,9 @@ protected void setIV(byte[] iv, boolean isEncrypt) {
logger.info(e.toString());
}
} else {
_decryptIV = new byte[_ivLength];
System.arraycopy(iv, 0, _decryptIV, 0, _ivLength);
try {
_decryptIV = new byte[_ivLength];
System.arraycopy(iv, 0, _decryptIV, 0, _ivLength);
decCipher = getCipher(isEncrypt);
ParametersWithIV parameterIV = new ParametersWithIV(
new KeyParameter(_key.getEncoded()), _decryptIV);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/cn/wowspeeder/ss/SSCipherDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> list)
ICrypt _crypt = ctx.channel().attr(SSCommon.CIPHER).get();
byte[] data = CryptUtil.decrypt(_crypt, msg);
if (data == null) {
ctx.close();
if (!ctx.channel().attr(SSCommon.IS_UDP).get()) {
ctx.close();
}
return;
}
list.add(msg.retain().clear().writeBytes(data));//
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/cn/wowspeeder/ss/SSProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)
SSAddrRequest addrRequest = SSAddrRequest.getAddrRequest(msg);
if (addrRequest == null) {
logger.error("failed to get address request from {}", ctx.channel().attr(SSCommon.CLIENT).get().getHostString());
ctx.close();
if (!ctx.channel().attr(SSCommon.IS_UDP).get()) {
ctx.close();
}
return;
}
logger.debug(ctx.channel().id().toString() + " addressType = " + addrRequest.addressType() + ",host = " + addrRequest.host() + ",port = " + addrRequest.port() + ",dataBuff = "
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/cn/wowspeeder/ss/SSTcpProxyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
proxyClient
.connect(clientRecipient)
.addListener((ChannelFutureListener) future -> {
if (future.isSuccess()) {
try {
try {
if (future.isSuccess()) {
logger.debug("channel id {}, {}<->{}<->{} connect {}", clientCtx.channel().id().toString(), clientCtx.channel().remoteAddress().toString(), future.channel().localAddress().toString(), clientRecipient.toString(), future.isSuccess());
remoteChannel = future.channel();
if (clientBuffs != null) {
Expand All @@ -108,11 +108,11 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
}
clientBuffs = null;
}
} catch (Exception e) {
} else {
logger.error("channel id {}, {}<->{} connect {},cause {}", clientCtx.channel().id().toString(), clientCtx.channel().remoteAddress().toString(), clientRecipient.toString(), future.isSuccess(), future.cause());
proxyChannelClose();
}
} else {
logger.error("channel id {}, {}<->{} connect {},cause {}", clientCtx.channel().id().toString(), clientCtx.channel().remoteAddress().toString(), clientRecipient.toString(), future.isSuccess(), future.cause());
} catch (Exception e) {
proxyChannelClose();
}
});
Expand Down Expand Up @@ -169,7 +169,7 @@ private void proxyChannelClose() {
clientChannel = null;
}
} catch (Exception e) {
logger.error("close channel error", e);
// logger.error("close channel error", e);
}
}
}

0 comments on commit 0823087

Please sign in to comment.