mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-11 03:13:51 +00:00
feat: construct new virtual session
This commit is contained in:
1 parent
53ab3796a5
commit
75d186923c
6 files changed
+20
-4
No files matched your search
@@ -9,7 +9,7 @@
|
||||
<active>true</active>
|
||||
<protocol>http</protocol>
|
||||
<host>127.0.0.1</host>
|
||||
<port>10808</port>
|
||||
<port>10809</port>
|
||||
</proxy>
|
||||
</proxies>
|
||||
|
||||
|
||||
@@ -52,6 +52,11 @@ public class TunnelClient extends AbstractClient<SocketChannel> {
|
||||
|
||||
public Object attachment;
|
||||
|
||||
public DecodedPacketInfo(long sid, Object packet, Object attachment) {
|
||||
this.sid = sid;
|
||||
this.packet = packet;
|
||||
this.attachment = attachment;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
package com.zfoo.net.core.proxy.handler;
|
||||
|
||||
import com.zfoo.net.NetContext;
|
||||
import com.zfoo.net.core.proxy.TunnelClient;
|
||||
import com.zfoo.net.core.proxy.TunnelProtocolServer2Client;
|
||||
import com.zfoo.net.core.proxy.TunnelServer;
|
||||
import com.zfoo.net.packet.PacketService;
|
||||
@@ -59,7 +60,7 @@ public class TunnelClientCodecHandler extends ByteToMessageCodec<TunnelProtocolS
|
||||
|
||||
var sid = ByteBufUtils.readLong(sliceByteBuf);
|
||||
var packetInfo = NetContext.getPacketService().read(sliceByteBuf);
|
||||
out.add(packetInfo);
|
||||
out.add(new TunnelClient.DecodedPacketInfo(sid, packetInfo.getPacket(), packetInfo.getAttachment()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.zfoo.net.NetContext;
|
||||
import com.zfoo.net.core.proxy.TunnelClient;
|
||||
import com.zfoo.net.handler.BaseRouteHandler;
|
||||
import com.zfoo.net.packet.DecodedPacketInfo;
|
||||
import com.zfoo.net.session.Session;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
@@ -40,7 +41,9 @@ public class TunnelClientRouteHandler extends BaseRouteHandler {
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||
var decodedPacketInfo = (TunnelClient.DecodedPacketInfo) msg;
|
||||
var session = new Session(decodedPacketInfo.sid, ctx.channel(), 0);
|
||||
NetContext.getRouter().receive(session, decodedPacketInfo.packet, decodedPacketInfo.attachment);
|
||||
|
||||
DecodedPacketInfo decodedPacketInfo = (DecodedPacketInfo) msg;
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ public class TunnelServerCodecHandler extends ByteToMessageCodec<TunnelProtocolS
|
||||
var messageType = sliceByteBuf.readByte();
|
||||
if (messageType == -1) {
|
||||
TunnelServer.tunnels.add(ctx.channel());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Session implements Closeable {
|
||||
/**
|
||||
* The globally unique ID of the session and the negative sid are allowed
|
||||
*/
|
||||
private long sid = ATOMIC_LONG.incrementAndGet();
|
||||
private long sid;
|
||||
|
||||
private Channel channel;
|
||||
|
||||
@@ -52,8 +52,14 @@ public class Session implements Closeable {
|
||||
throw new IllegalArgumentException("channel cannot be empty");
|
||||
}
|
||||
this.channel = channel;
|
||||
this.sid = ATOMIC_LONG.incrementAndGet();
|
||||
}
|
||||
|
||||
public Session(long sid, Channel channel, long uid) {
|
||||
this.sid = sid;
|
||||
this.channel = channel;
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
Reference in new issue
Block a user