Compare commits

..
3 Commits
Author SHA1 Message Date
aoshiguchen ad32e36ba2 . 2023-12-18 10:47:55 +08:00
aoshiguchen 00fd0bab84 限速相关处理优化 2023-12-16 16:07:47 +08:00
songyinyin 8f90cf461d 原生编译:注册 netty 在 jdk 21 中新使用的类 2023-12-15 18:18:00 +08:00
6 changed files with 16 additions and 12 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
# see: https://docs.github.com/zh/actions/using-jobs/choosing-the-runner-for-a-job
# os: ['ubuntu-20.04', 'macos-12']
# os: ['ubuntu-20.04', 'macos-12']
os: ['ubuntu-20.04']
name: build - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
@@ -8,6 +8,7 @@ import org.noear.solon.aot.RuntimeNativeRegistrar;
import org.noear.solon.aot.hint.MemberCategory;
import org.noear.solon.core.AppContext;
import java.nio.ByteBuffer;
import java.util.Set;
/**
@@ -22,6 +23,11 @@ public class NeutrinoCoreRuntimeNativeRegistrar implements RuntimeNativeRegistra
metadata.registerReflection(clazz, MemberCategory.INVOKE_DECLARED_METHODS);
}
Set<Class<?>> byteBufferClasses = ClassUtil.scanPackageBySuper("java", ByteBuffer.class);
for (Class<?> clazz : byteBufferClasses) {
metadata.registerReflection(clazz, MemberCategory.INVOKE_DECLARED_METHODS);
}
metadata.registerReflection(ProxyMessage.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
metadata.registerReflection(ProxyMessage.UdpBaseInfo.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
@@ -77,8 +77,8 @@ public class ProxyConfiguration implements LifecycleBean {
}
ch.pipeline().addFirst(new BytesMetricsHandler());
// ch.pipeline().addLast(new ChannelTrafficShapingHandler(1024 * 1024 * 20, 1024 * 1024 * 20, 100, 20000));
ch.pipeline().addLast("security", new TcpVisitorSecurityChannelHandler());
ch.pipeline().addLast(new VisitorFlowLimiterChannelHandler());
ch.pipeline().addLast(new TcpVisitorSecurityChannelHandler());
ch.pipeline().addLast("flowLimiter", new VisitorFlowLimiterChannelHandler());
ch.pipeline().addLast(new TcpVisitorChannelHandler());
}
});
@@ -116,8 +116,8 @@ public class ProxyConfiguration implements LifecycleBean {
if (null != proxyConfig.getServer().getUdp().getTransferLogEnable() && proxyConfig.getServer().getUdp().getTransferLogEnable()) {
ch.pipeline().addFirst(new LoggingHandler(UdpVisitorChannelHandler.class));
}
pipeline.addLast(udpServerWorkerGroup, "security", new UdpVisitorSecurityChannelHandler());
ch.pipeline().addLast(new VisitorFlowLimiterChannelHandler());
pipeline.addLast(udpServerWorkerGroup, new UdpVisitorSecurityChannelHandler());
ch.pipeline().addLast("flowLimiter", new VisitorFlowLimiterChannelHandler());
pipeline.addLast(udpServerWorkerGroup, new UdpVisitorChannelHandler());
}
});
@@ -48,8 +48,8 @@ public class HttpProxy implements EventListener<AppLoadEndEvent> {
ch.pipeline().addFirst(new LoggingHandler(HttpProxy.class));
}
ch.pipeline().addFirst(new BytesMetricsHandler());
ch.pipeline().addLast("security", new HttpVisitorSecurityChannelHandler(proxyConfig.getServer().getTcp().getDomainName()));
ch.pipeline().addLast(new VisitorFlowLimiterChannelHandler());
ch.pipeline().addLast(new HttpVisitorSecurityChannelHandler(proxyConfig.getServer().getTcp().getDomainName()));
ch.pipeline().addLast("flowLimiter",new VisitorFlowLimiterChannelHandler());
ch.pipeline().addLast(new HttpVisitorChannelHandler());
}
});
@@ -57,8 +57,8 @@ public class HttpsProxy implements EventListener<AppLoadEndEvent> {
}
ch.pipeline().addLast(createSslHandler());
ch.pipeline().addFirst(new BytesMetricsHandler());
ch.pipeline().addLast("security", new HttpVisitorSecurityChannelHandler(proxyConfig.getServer().getTcp().getDomainName()));
ch.pipeline().addLast(new VisitorFlowLimiterChannelHandler());
ch.pipeline().addLast(new HttpVisitorSecurityChannelHandler(proxyConfig.getServer().getTcp().getDomainName()));
ch.pipeline().addLast("flowLimiter",new VisitorFlowLimiterChannelHandler());
ch.pipeline().addLast(new HttpVisitorChannelHandler());
}
});
@@ -18,8 +18,6 @@ import org.noear.solon.Solon;
*/
@Slf4j
public class VisitorFlowLimiterChannelHandler extends ChannelInboundHandlerAdapter {
private final LicenseService licenseService = Solon.context().getBean(LicenseService.class);
private final PortMappingService portMappingService = Solon.context().getBean(PortMappingService.class);
@Override
@@ -38,7 +36,7 @@ public class VisitorFlowLimiterChannelHandler extends ChannelInboundHandlerAdapt
}
if (null != upLimitRate || null != downLimitRate) {
// 如果不全为空,则需要做限速
ctx.pipeline().addAfter("security", "trafficShaping", new ChannelTrafficShapingHandler(downLimitRate == null ? 0 : downLimitRate, upLimitRate == null ? 0 : upLimitRate, 100, 600000));
ctx.pipeline().addAfter("flowLimiter", "trafficShaping", new ChannelTrafficShapingHandler(downLimitRate == null ? 0 : downLimitRate, upLimitRate == null ? 0 : upLimitRate, 100, 600000));
}
// 每个连接第一次处理之后。无论是否限速,该连接后续都不在处理,避免频繁执行影响性能