mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-19 00:15:19 +00:00
perf[proxy]: don't send any packet when the tunnel buffer is full
This commit is contained in:
1 parent
1cfe5ab433
commit
e690d3f224
3 files changed
+24
-11
No files matched your search
@@ -67,16 +67,12 @@ public class TunnelProtocolServer2Client {
|
|||||||
|
|
||||||
|
|
||||||
public void write(ByteBuf out) {
|
public void write(ByteBuf out) {
|
||||||
try {
|
out.ensureWritable(22);
|
||||||
out.ensureWritable(22);
|
out.writerIndex(PacketService.PACKET_HEAD_LENGTH);
|
||||||
out.writerIndex(PacketService.PACKET_HEAD_LENGTH);
|
ByteBufUtils.writeLong(out, sid);
|
||||||
ByteBufUtils.writeLong(out, sid);
|
ByteBufUtils.writeLong(out, uid);
|
||||||
ByteBufUtils.writeLong(out, uid);
|
out.writeBytes(retainedByteBuf);
|
||||||
out.writeBytes(retainedByteBuf);
|
NetContext.getPacketService().writeHeaderBefore(out);
|
||||||
NetContext.getPacketService().writeHeaderBefore(out);
|
|
||||||
} finally {
|
|
||||||
ReferenceCountUtil.release(retainedByteBuf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// -----------------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageCodec;
|
import io.netty.handler.codec.ByteToMessageCodec;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -34,6 +36,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class ProxyCodecHandler extends ByteToMessageCodec<TunnelProtocolServer2Client> {
|
public class ProxyCodecHandler extends ByteToMessageCodec<TunnelProtocolServer2Client> {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ProxyCodecHandler.class);
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
|
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
|
||||||
@@ -57,11 +61,20 @@ public class ProxyCodecHandler extends ByteToMessageCodec<TunnelProtocolServer2C
|
|||||||
|
|
||||||
if (CollectionUtils.isEmpty(TunnelServer.tunnels)) {
|
if (CollectionUtils.isEmpty(TunnelServer.tunnels)) {
|
||||||
in.readSlice(length);
|
in.readSlice(length);
|
||||||
|
logger.warn("Tunnel server has no tunnels");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tunnel = RandomUtils.randomEle(TunnelServer.tunnels);
|
var tunnel = RandomUtils.randomEle(TunnelServer.tunnels);
|
||||||
if (!SessionUtils.isActive(tunnel)) {
|
if (!SessionUtils.isActive(tunnel)) {
|
||||||
in.readSlice(length);
|
in.readSlice(length);
|
||||||
|
logger.warn("Tunnel server has no active tunnels");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tunnel.isWritable()) {
|
||||||
|
in.readSlice(length);
|
||||||
|
logger.warn("Tunnel server has no writable tunnels");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,11 @@ public class TunnelServerCodecHandler extends ByteToMessageCodec<TunnelProtocolS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encode(ChannelHandlerContext ctx, TunnelProtocolServer2Client tunnelProtocol, ByteBuf out) {
|
protected void encode(ChannelHandlerContext ctx, TunnelProtocolServer2Client tunnelProtocol, ByteBuf out) {
|
||||||
tunnelProtocol.write(out);
|
try {
|
||||||
|
tunnelProtocol.write(out);
|
||||||
|
} finally {
|
||||||
|
ReferenceCountUtil.release(tunnelProtocol.getRetainedByteBuf());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user