Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into SIP003_DEV
Browse files Browse the repository at this point in the history
  • Loading branch information
CC-Cheunggg committed Apr 28, 2020
2 parents e1377c6 + a8e88e9 commit 25fba28
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: java
jdk:
- openjdk8
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Releases](https://img.shields.io/github/downloads/RPCheung/shadowsockets-core/total.svg)](https://github.com/RPCheung/shadowsockets-core/releases)

[![Build Status](https://travis-ci.org/RPCheung/shadowsockets-core.svg?branch=master)](https://travis-ci.org/github/RPCheung/shadowsockets-core)
## 计划

- [x] TCP隧道
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\:https://services.gradle.org/distributions/gradle-3.3-bin.zip
distributionUrl=https\:https://services.gradle.org/distributions/gradle-5.2.1-bin.zip
20 changes: 16 additions & 4 deletions src/main/java/com/cheung/shadowsocks/codec/ShadowsocksDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.netty.channel.EventLoopGroup;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.socks.SocksAddressType;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -52,21 +53,31 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ByteBuf buff = (ByteBuf) msg;
ByteBuf data = Unpooled.copiedBuffer(CryptUtil.decrypt(_crypt, buff));
CryptUtil.releaseByteBufAllRefCnt(buff);
super.channelRead(ctx, data);
try {
ByteBuf data = Unpooled.copiedBuffer(CryptUtil.decrypt(_crypt, buff));
super.channelRead(ctx, data);
} finally {
CryptUtil.releaseByteBufAllRefCnt(buff);
}
}

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf data, List<Object> out) throws Exception {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.error("decode error", cause);
ctx.close();
}

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf data, List<Object> out) throws Exception {
// 这个方法里面的 ByteBuf 会自动释放
switch (state()) {
case HOST_TYPE: {
hostType = SocksAddressType.valueOf(data.readByte());
if ((hostType != SocksAddressType.IPv4)
&& (hostType != SocksAddressType.IPv6)
&& (hostType != SocksAddressType.DOMAIN)) {
CryptUtil.releaseByteBufAllRefCnt(data);
ctx.close();
logger.error("UNKNOWN HOST TYPE.");
return;
}
Expand Down Expand Up @@ -96,6 +107,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf data, List<Object> out)
if (hostType == SocksAddressType.UNKNOWN) {
logger.error("UNKNOWN HOST TYPE.");
CryptUtil.releaseByteBufAllRefCnt(data);
ctx.close();
return;
}
checkpoint(ReadState.PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public void channelActive(ChannelHandlerContext ctx) {
ctx.channel().writeAndFlush(Unpooled.copiedBuffer(data));
}
}

}


Expand Down

0 comments on commit 25fba28

Please sign in to comment.