From e377477d2177f56dc22a8bf36dc152035547088c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=84=9E?= Date: Sun, 8 Dec 2024 15:06:46 +0800 Subject: [PATCH] up --- .../java/org/rx/net/socks/BackendRelayHandler.java | 8 ++++---- .../org/rx/net/socks/ProxyChannelIdleHandler.java | 12 +++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/rxlib/src/main/java/org/rx/net/socks/BackendRelayHandler.java b/rxlib/src/main/java/org/rx/net/socks/BackendRelayHandler.java index 312fc35d..52986787 100644 --- a/rxlib/src/main/java/org/rx/net/socks/BackendRelayHandler.java +++ b/rxlib/src/main/java/org/rx/net/socks/BackendRelayHandler.java @@ -46,11 +46,11 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { Channel outbound = ctx.channel(); SocksContext sc = SocksContext.ctx(outbound); - if (cause instanceof ProxyConnectException) { - log.warn("RELAY {}[{}] => {} thrown\n{}", outbound.remoteAddress(), outbound.localAddress(), sc.inbound.remoteAddress(), cause.getMessage()); - } else { +// if (cause instanceof ProxyConnectException) { +// log.warn("RELAY {}[{}] => {} thrown\n{}", outbound.remoteAddress(), outbound.localAddress(), sc.inbound.remoteAddress(), cause.getMessage()); +// } else { log.warn("RELAY {}[{}] => {} thrown", outbound.remoteAddress(), outbound.localAddress(), sc.inbound.remoteAddress(), cause); - } +// } Sockets.closeOnFlushed(outbound); } } 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 82f7e669..6daf9c40 100644 --- a/rxlib/src/main/java/org/rx/net/socks/ProxyChannelIdleHandler.java +++ b/rxlib/src/main/java/org/rx/net/socks/ProxyChannelIdleHandler.java @@ -1,5 +1,6 @@ package org.rx.net.socks; +import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.timeout.IdleStateEvent; import io.netty.handler.timeout.IdleStateHandler; @@ -17,12 +18,17 @@ public ProxyChannelIdleHandler(int readerIdleTimeSeconds, int writerIdleTimeSeco @SneakyThrows @Override protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) { - log.info("{} {} idle: {}", Sockets.protocolName(ctx.channel()), ctx.channel(), evt.state()); - SocksContext sc = SocksContext.ctx(ctx.channel()); + 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) { sc.onClose.invoke(); } super.channelIdle(ctx, evt); - Sockets.closeOnFlushed(ctx.channel()); + Sockets.closeOnFlushed(channel); } }