Skip to content

Commit

Permalink
Fix RemoteConnectionInitEvent is called before ConnectionInitEvent is…
Browse files Browse the repository at this point in the history
… called
  • Loading branch information
acrylic-style committed May 14, 2022
1 parent c54ecbc commit 67e7d17
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "net.azisaba.simpleProxy"
version = "1.1.3-SNAPSHOT"
version = "1.1.3"

extra.set("log4jVersion", "2.17.2")

Expand Down
4 changes: 3 additions & 1 deletion proxy/src/main/java/net/azisaba/simpleProxy/proxy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 67e7d17

Please sign in to comment.