Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ProxyManager): mass-importing proxies #5069

Closed
wants to merge 30 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
40d2ba2
wip(ProxyManager): import proxy modal (no file icon yet)
DataM0del Nov 22, 2024
29bb5ab
chore(integration/host.ts): enable `IN_DEV`
DataM0del Nov 22, 2024
40e82b1
wip(api/v1/proxies): add import routes
DataM0del Nov 22, 2024
5e4ff95
fix(ProxyFunctions/postImportClipboardProxy): add braces in guard cla…
DataM0del Nov 22, 2024
30d0616
fix(ProxyFunctions): rename `_requestObject` param to `requestObject`…
DataM0del Nov 22, 2024
e4dfb35
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Nov 23, 2024
38947ea
add(theme/integration/rest): importProxyFromClipboard, importProxyFro…
DataM0del Nov 24, 2024
8501a71
Merge remote-tracking branch 'origin/feat/mass-proxy-importing' into …
DataM0del Nov 24, 2024
8f105d7
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Nov 24, 2024
751af9e
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Nov 25, 2024
07a1c90
refactor(Listenable): is running (#4685)
1zun4 Nov 25, 2024
9ef8a31
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Nov 25, 2024
ca00f95
feat(FontRenderer): multi-atlas support (#4688)
superblaubeere27 Nov 25, 2024
7729501
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Nov 25, 2024
96940e2
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Nov 25, 2024
278e042
fix(importProxies): remove protocol from line
DataM0del Nov 25, 2024
55e96c1
feat(src-theme/routes/menu/proxymanager/ImportProxyModal): implement …
DataM0del Nov 25, 2024
6cd901e
fix(src-theme/routes/menu/proxymanager/ImportProxyModal): remove comm…
DataM0del Nov 25, 2024
e70c172
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Nov 26, 2024
f8a2357
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Nov 26, 2024
20a4b4e
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Nov 27, 2024
b08db20
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Nov 30, 2024
e83ffa9
Merge branch 'nextgen' of https://github.com/CCBlueX/LiquidBounce int…
DataM0del Dec 3, 2024
5667b09
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Dec 21, 2024
93a7db2
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Dec 23, 2024
f3477c9
refactor(ProxyFunctions): fix wrong path in comment
DataM0del Dec 25, 2024
5c2583f
draft(postImportFileProxy): use tinyfd
DataM0del Dec 25, 2024
5e4c92f
refactor(postImportFileProxy): implement
DataM0del Dec 26, 2024
fb6f9aa
refactor(ProxyValidator#Proxy/check): implement multiple ping servers
DataM0del Dec 26, 2024
ce0b34d
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ import kotlin.jvm.optionals.getOrNull
/**
* This is a generic Minecraft server that is used to check if a proxy is working. The server also
* responds to query requests with the client's IP address.
* Some of these are taken from https://topminecraftservers.org/
*/
private const val PING_SERVER = "ping.liquidproxy.net"
private val FALLBACK_PING_SERVERS = listOf(
"mc.hypixel.net",
"crescentkingdom.com",
"gratopia.gg",
"terranova.mc.gg",
"play.arcanecloud.net",
"ping.liquidproxy.net"
)
Comment on lines +59 to +66
Copy link
Member

@1zun4 1zun4 Dec 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we will not use this. The LiquidProxy Ping Server serves it's purpose to respond with the IP address of the proxy, without we are not able to detect the outgoing IP of a proxy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. But what about the server list idea? Aren't we supposed to reuse the server list as ping servers? because I can tell you that no one would want to join a server which shows their IP as the MOTD or the kick message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you talking about?

private const val PING_TIMEOUT = 5

class ClientConnectionTicker(private val clientConnection: ClientConnection) : EventListener {
Expand All @@ -70,69 +78,75 @@ class ClientConnectionTicker(private val clientConnection: ClientConnection) : E
* as well as update the ip information of the proxy.
*/
fun Proxy.check(success: (Proxy) -> Unit, failure: (Throwable) -> Unit) = runCatching {
logger.info("Request ping server via proxy... [$host:$port]")

val serverAddress = ServerAddress.parse(PING_SERVER)
val socketAddress: InetSocketAddress = AllowedAddressResolver.DEFAULT.resolve(serverAddress)
.map(Address::getInetSocketAddress)
.getOrNull()
?: error("Failed to resolve $PING_SERVER")
logger.info("Resolved ping server [$PING_SERVER]: $socketAddress")

val clientConnection = ClientConnection(NetworkSide.CLIENTBOUND)
val channelFuture = connect(socketAddress, false, clientConnection)
channelFuture.syncUninterruptibly()

val ticker = ClientConnectionTicker(clientConnection)
for (fallbackPingServer in FALLBACK_PING_SERVERS) {
logger.info("Request ping server via proxy... [$host:$port]")

val serverAddress = ServerAddress.parse(fallbackPingServer)
val socketAddress: InetSocketAddress = AllowedAddressResolver.DEFAULT.resolve(serverAddress)
.map(Address::getInetSocketAddress)
.getOrNull()
?: error("Failed to resolve $fallbackPingServer")
logger.info("Resolved server [$fallbackPingServer]: $socketAddress")

val clientConnection = ClientConnection(NetworkSide.CLIENTBOUND)
val channelFuture = connect(socketAddress, false, clientConnection)
channelFuture.syncUninterruptibly()

val ticker = ClientConnectionTicker(clientConnection)

val clientQueryPacketListener = object : ClientQueryPacketListener {

private var serverMetadata: ServerMetadata? = null
private var startTime = 0L

override fun onResponse(packet: QueryResponseS2CPacket) {
if (serverMetadata != null) {
if (fallbackPingServer == FALLBACK_PING_SERVERS[FALLBACK_PING_SERVERS.lastIndex]) {
failure(IllegalStateException("Received multiple responses from server"))
}
return
}

val metadata = packet.metadata()
serverMetadata = metadata
startTime = Util.getMeasuringTimeMs()
clientConnection.send(QueryPingC2SPacket(startTime))
logger.info("Proxy Metadata [$host:$port]: ${metadata.description.convertToString()}")
}

val clientQueryPacketListener = object : ClientQueryPacketListener {
override fun onPingResult(packet: PingResultS2CPacket) {
val serverMetadata = this.serverMetadata ?: error("Received ping result without metadata")
val ping = Util.getMeasuringTimeMs() - startTime
logger.info("Proxy Ping [$host:$port]: $ping ms")

private var serverMetadata: ServerMetadata? = null
private var startTime = 0L
runCatching {
val ipInfo = IpInfoApi.someoneElse(serverMetadata.description.convertToString())
[email protected] = ipInfo
logger.info("Proxy Info [$host:$port]: ${ipInfo.ip} [${ipInfo.country}, ${ipInfo.org}]")
}.onFailure { throwable ->
logger.error("Failed to update IP info for proxy [$host:$port]", throwable)
}

override fun onResponse(packet: QueryResponseS2CPacket) {
if (serverMetadata != null) {
failure(IllegalStateException("Received multiple responses from server"))
return
success(this@check)
}

val metadata = packet.metadata()
serverMetadata = metadata
startTime = Util.getMeasuringTimeMs()
clientConnection.send(QueryPingC2SPacket(startTime))
logger.info("Proxy Metadata [$host:$port]: ${metadata.description.convertToString()}")
}
override fun onDisconnected(info: DisconnectionInfo) {
EventManager.unregisterEventHandler(ticker)

override fun onPingResult(packet: PingResultS2CPacket) {
val serverMetadata = this.serverMetadata ?: error("Received ping result without metadata")
val ping = Util.getMeasuringTimeMs() - startTime
logger.info("Proxy Ping [$host:$port]: $ping ms")

runCatching {
val ipInfo = IpInfoApi.someoneElse(serverMetadata.description.convertToString())
[email protected] = ipInfo
logger.info("Proxy Info [$host:$port]: ${ipInfo.ip} [${ipInfo.country}, ${ipInfo.org}]")
}.onFailure { throwable ->
logger.error("Failed to update IP info for proxy [$host:$port]", throwable)
if (this.serverMetadata == null) {
if (fallbackPingServer == FALLBACK_PING_SERVERS[FALLBACK_PING_SERVERS.lastIndex]) {
failure(IllegalStateException("Disconnected before receiving metadata"))
}
}
}

success(this@check)
override fun isConnectionOpen() = clientConnection.isOpen
}

override fun onDisconnected(info: DisconnectionInfo) {
EventManager.unregisterEventHandler(ticker)

if (this.serverMetadata == null) {
failure(IllegalStateException("Disconnected before receiving metadata"))
}
}

override fun isConnectionOpen() = clientConnection.isOpen
clientConnection.connect(serverAddress.address, serverAddress.port, clientQueryPacketListener)
clientConnection.send(QueryRequestC2SPacket.INSTANCE)
logger.info("Sent query request via proxy [$host:$port]")
}

clientConnection.connect(serverAddress.address, serverAddress.port, clientQueryPacketListener)
clientConnection.send(QueryRequestC2SPacket.INSTANCE)
logger.info("Sent query request via proxy [$host:$port]")
}.onFailure { throwable -> failure(throwable) }

private fun Proxy.connect(
Expand Down