-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
+186
−54
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 29bb5ab
chore(integration/host.ts): enable `IN_DEV`
DataM0del 40e82b1
wip(api/v1/proxies): add import routes
DataM0del 5e4ff95
fix(ProxyFunctions/postImportClipboardProxy): add braces in guard cla…
DataM0del 30d0616
fix(ProxyFunctions): rename `_requestObject` param to `requestObject`…
DataM0del e4dfb35
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del 38947ea
add(theme/integration/rest): importProxyFromClipboard, importProxyFro…
DataM0del 8501a71
Merge remote-tracking branch 'origin/feat/mass-proxy-importing' into …
DataM0del 8f105d7
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del 751af9e
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del 07a1c90
refactor(Listenable): is running (#4685)
1zun4 9ef8a31
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del ca00f95
feat(FontRenderer): multi-atlas support (#4688)
superblaubeere27 7729501
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del 96940e2
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del 278e042
fix(importProxies): remove protocol from line
DataM0del 55e96c1
feat(src-theme/routes/menu/proxymanager/ImportProxyModal): implement …
DataM0del 6cd901e
fix(src-theme/routes/menu/proxymanager/ImportProxyModal): remove comm…
DataM0del e70c172
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del f8a2357
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del 20a4b4e
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del b08db20
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del e83ffa9
Merge branch 'nextgen' of https://github.com/CCBlueX/LiquidBounce int…
DataM0del 5667b09
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del 93a7db2
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del f3477c9
refactor(ProxyFunctions): fix wrong path in comment
DataM0del 5c2583f
draft(postImportFileProxy): use tinyfd
DataM0del 5e4c92f
refactor(postImportFileProxy): implement
DataM0del fb6f9aa
refactor(ProxyValidator#Proxy/check): implement multiple ping servers
DataM0del ce0b34d
Merge branch 'CCBlueX:nextgen' into feat/mass-proxy-importing
DataM0del File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
private const val PING_TIMEOUT = 5 | ||
|
||
class ClientConnectionTicker(private val clientConnection: ClientConnection) : EventListener { | ||
|
@@ -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( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?