diff --git a/build.gradle.kts b/build.gradle.kts index 6e478f7..c742c32 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "net.azisaba.simpleProxy" -version = "1.1.3-SNAPSHOT" +version = "1.1.3" extra.set("log4jVersion", "2.17.2") diff --git a/proxy/src/main/java/net/azisaba/simpleProxy/proxy/Main.java b/proxy/src/main/java/net/azisaba/simpleProxy/proxy/Main.java index 1621d31..9480ab7 100644 --- a/proxy/src/main/java/net/azisaba/simpleProxy/proxy/Main.java +++ b/proxy/src/main/java/net/azisaba/simpleProxy/proxy/Main.java @@ -19,7 +19,9 @@ public static void main(String[] args) { private static void preload() { try { - Class.forName("net.azisaba.simpleProxy.api.event.proxy.ProxyShutdownEvent"); // avoid stuck on shutdown when jar is replaced + // avoid stuck on shutdown when jar is replaced + Class.forName("net.azisaba.simpleProxy.api.event.proxy.ProxyShutdownEvent"); + Class.forName("org.apache.logging.log4j.core.async.InternalAsyncUtil"); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } diff --git a/proxy/src/main/java/net/azisaba/simpleProxy/proxy/connection/MessageForwarder.java b/proxy/src/main/java/net/azisaba/simpleProxy/proxy/connection/MessageForwarder.java index e8a75a5..809779f 100644 --- a/proxy/src/main/java/net/azisaba/simpleProxy/proxy/connection/MessageForwarder.java +++ b/proxy/src/main/java/net/azisaba/simpleProxy/proxy/connection/MessageForwarder.java @@ -33,6 +33,7 @@ public class MessageForwarder extends ChannelInboundHandlerAdapter { * The address which the user is connecting from. */ protected SocketAddress sourceAddress; + protected boolean active = false; boolean deactivated = false; boolean isRemoteActive = false; @@ -50,25 +51,23 @@ public void channelActive(@NotNull ChannelHandlerContext ctx) throws Exception { if (ProxyConfigInstance.debug) { LOGGER.info("Forwarder: Established connection: " + ctx.channel()); } + active = true; } - @Override - public void handlerAdded(ChannelHandlerContext ctx) throws Exception { - if (ctx.channel().isActive()) { - // handler added while the channel is active (added by plugin) - ctx.read(); + public void activate() { + if (!active) { + channel.read(); if (ProxyConfigInstance.debug) { - LOGGER.info("Forwarder: Established connection: " + ctx.channel()); - } - if (remote == null && !remoteConnecting) { - remoteConnecting = true; - ChannelFuture future = ProxyInstance.getInstance() - .getConnectionListener() - .connect(this, remoteServerInfo); - remote = future.channel(); + LOGGER.info("Forwarder: Established connection: " + channel); } } - super.handlerAdded(ctx); + if (remote == null && !remoteConnecting) { + remoteConnecting = true; + ChannelFuture future = ProxyInstance.getInstance() + .getConnectionListener() + .connect(this, remoteServerInfo); + remote = future.channel(); + } } @Override @@ -103,13 +102,7 @@ public void channelRead(@NotNull ChannelHandlerContext ctx, @NotNull Object msg) super.channelRead(ctx, msg); return; } - if (remote == null && !remoteConnecting) { - remoteConnecting = true; - ChannelFuture future = ProxyInstance.getInstance() - .getConnectionListener() - .connect(this, remoteServerInfo); - remote = future.channel(); - } + activate(); if (remote == null || !remote.isActive()) { if (msg instanceof ByteBuf) { queue.add(((ByteBuf) msg).copy());