From 3130a809e59c66d684f266fd5a02c6b2a82d7044 Mon Sep 17 00:00:00 2001 From: Walter Oggioni Date: Tue, 30 Dec 2025 21:53:23 +0800 Subject: [PATCH] improved logging --- rbcs-cli/native-image/native-image.properties | 2 +- .../kotlin/net/woggioni/rbcs/common/CidrTest.kt | 17 +++++++++++++++++ .../rbcs/server/handler/ProxyProtocolHandler.kt | 11 +++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 rbcs-common/src/test/kotlin/net/woggioni/rbcs/common/CidrTest.kt diff --git a/rbcs-cli/native-image/native-image.properties b/rbcs-cli/native-image/native-image.properties index 6bb0acb..68a9888 100644 --- a/rbcs-cli/native-image/native-image.properties +++ b/rbcs-cli/native-image/native-image.properties @@ -1,2 +1,2 @@ -Args=-O3 -march=x86-64-v2 --gc=serial --install-exit-handlers --initialize-at-run-time=io.netty --enable-url-protocols=jpms --initialize-at-build-time=net.woggioni.rbcs.common.RbcsUrlStreamHandlerFactory,net.woggioni.rbcs.common.RbcsUrlStreamHandlerFactory$JpmsHandler +Args=-O3 -march=x86-64-v2 --gc=serial --initialize-at-run-time=io.netty --enable-url-protocols=jpms -H:+UnlockExperimentalVMOptions -H:+SharedArenaSupport --initialize-at-build-time=net.woggioni.rbcs.common.RbcsUrlStreamHandlerFactory,net.woggioni.rbcs.common.RbcsUrlStreamHandlerFactory$JpmsHandler #-H:TraceClassInitialization=io.netty.handler.ssl.BouncyCastleAlpnSslUtils \ No newline at end of file diff --git a/rbcs-common/src/test/kotlin/net/woggioni/rbcs/common/CidrTest.kt b/rbcs-common/src/test/kotlin/net/woggioni/rbcs/common/CidrTest.kt new file mode 100644 index 0000000..5ab6d87 --- /dev/null +++ b/rbcs-common/src/test/kotlin/net/woggioni/rbcs/common/CidrTest.kt @@ -0,0 +1,17 @@ +package net.woggioni.rbcs.common + +import java.net.InetAddress +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +class CidrTest { + class CidrTest { + @Test + fun test() { + val cidr = Cidr.from("2a02:4780:12:368b::1/128") + Assertions.assertTrue { + cidr.contains(InetAddress.ofLiteral("2a02:4780:12:368b::1")) + } + } + } +} \ No newline at end of file diff --git a/rbcs-server/src/main/kotlin/net/woggioni/rbcs/server/handler/ProxyProtocolHandler.kt b/rbcs-server/src/main/kotlin/net/woggioni/rbcs/server/handler/ProxyProtocolHandler.kt index 63b9f4c..0a9860f 100644 --- a/rbcs-server/src/main/kotlin/net/woggioni/rbcs/server/handler/ProxyProtocolHandler.kt +++ b/rbcs-server/src/main/kotlin/net/woggioni/rbcs/server/handler/ProxyProtocolHandler.kt @@ -24,14 +24,21 @@ class ProxyProtocolHandler(private val trustedProxyIPs : List) : SimpleCha val sourceAddress = ctx.channel().remoteAddress() if (sourceAddress is InetSocketAddress && trustedProxyIPs.isEmpty() || - trustedProxyIPs.any { it.contains((sourceAddress as InetSocketAddress).address) }) { + trustedProxyIPs.any { it.contains((sourceAddress as InetSocketAddress).address) }.also { + if(!it && log.isTraceEnabled) { + log.trace { + "Received a proxied connection request from $sourceAddress which is not a trusted proxy address, " + + "the proxy server address will be used instead" + } + } + }) { val proxiedClientAddress = InetSocketAddress( InetAddress.ofLiteral(msg.sourceAddress()), msg.sourcePort() ) if(log.isTraceEnabled) { log.trace { - "Received proxied request from $sourceAddress forwarded for $proxiedClientAddress" + "Received proxied connection request from $sourceAddress forwarded for $proxiedClientAddress" } } ctx.channel().attr(RemoteBuildCacheServer.clientIp).set(proxiedClientAddress)