diff --git a/rxlib/src/main/java/org/rx/net/socks/ProxyChannelIdleHandler.java b/rxlib/src/main/java/org/rx/net/socks/ProxyChannelIdleHandler.java index 6daf9c40..79a22930 100644 --- a/rxlib/src/main/java/org/rx/net/socks/ProxyChannelIdleHandler.java +++ b/rxlib/src/main/java/org/rx/net/socks/ProxyChannelIdleHandler.java @@ -19,13 +19,9 @@ public ProxyChannelIdleHandler(int readerIdleTimeSeconds, int writerIdleTimeSeco @Override protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) { Channel channel = ctx.channel(); - if (channel == null) { - return; - } - log.info("{} {} idle: {}", Sockets.protocolName(channel), channel, evt.state()); - SocksContext sc = SocksContext.ctx(channel); - if (sc.onClose != null) { + SocksContext sc = SocksContext.ctx(channel, false); + if (sc != null && sc.onClose != null) { sc.onClose.invoke(); } super.channelIdle(ctx, evt); diff --git a/rxlib/src/main/java/org/rx/net/socks/SocksContext.java b/rxlib/src/main/java/org/rx/net/socks/SocksContext.java index 6cb36f00..94214c45 100644 --- a/rxlib/src/main/java/org/rx/net/socks/SocksContext.java +++ b/rxlib/src/main/java/org/rx/net/socks/SocksContext.java @@ -33,7 +33,7 @@ public final class SocksContext extends EventArgs { private static final long serialVersionUID = 323020524764860674L; static final AttributeKey SERVER = AttributeKey.valueOf("SERVER"); - static final AttributeKey CTX = AttributeKey.valueOf("PROXY_CTX"); + private static final AttributeKey CTX = AttributeKey.valueOf("PROXY_CTX"); //ss static final AttributeKey SS_SERVER = AttributeKey.valueOf("SS_SERVER"); @@ -56,7 +56,11 @@ public static void mark(Channel inbound, Channel outbound, SocksContext sc, bool } public static SocksContext ctx(Channel channel) { - return require(channel.attr(CTX).get()); + return ctx(channel, true); + } + + public static SocksContext ctx(Channel channel, boolean throwOnEmpty) { + return throwOnEmpty ? require(channel.attr(CTX).get()) : channel.attr(CTX).get(); } //region common diff --git a/rxlib/src/test/java/org/rx/net/TestSocks.java b/rxlib/src/test/java/org/rx/net/TestSocks.java index dd7bea31..bc2d535f 100644 --- a/rxlib/src/test/java/org/rx/net/TestSocks.java +++ b/rxlib/src/test/java/org/rx/net/TestSocks.java @@ -523,7 +523,7 @@ public void ssProxy() { SocksUser usr = new SocksUser("rocky"); usr.setPassword(defPwd); usr.setMaxIpCount(-1); - SocksProxyServer backSvr = new SocksProxyServer(backConf, Authenticator.dbAuth(Collections.singletonList(usr), null)); + SocksProxyServer backSvr = new SocksProxyServer(backConf, new DefaultSocksAuthenticator(Collections.singletonList(usr))); RpcServerConfig rpcServerConf = new RpcServerConfig(new TcpServerConfig(backSrvEp.getPort() + 1)); rpcServerConf.getTcpConfig().setTransportFlags(TransportFlags.FRONTEND_COMPRESS.flags());