mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2024-11-24 12:25:39 +01:00
parent
bb07aaebb8
commit
f09da91810
@ -96,7 +96,7 @@ dependencies {
|
||||
implementation("org.jline:jline-terminal-jansi:3.23.0")
|
||||
implementation("org.slf4j:slf4j-api:$slf4jVer")
|
||||
|
||||
val ktorVersion = "2.3.0"
|
||||
val ktorVersion = "2.3.2"
|
||||
implementation("io.ktor:ktor-network-tls-certificates-jvm:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-websockets:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-netty-jvm:$ktorVersion")
|
||||
|
@ -21,7 +21,7 @@ class BackEndInit(val connectionData: ConnectionData, val proxyUri: URI?, val pr
|
||||
val user = UserConnectionImpl(ch, true)
|
||||
val pipeline = ProtocolPipelineImpl(user)
|
||||
val version = connectionData.backServerVer!!
|
||||
val isLegacy = LegacyProtocolVersion.protocolCompare(version, ProtocolVersion.v_1_6_4.version) <= 0
|
||||
val isLegacy = LegacyProtocolVersion.protocolCompare(version, LegacyProtocolVersion.r1_6_4.version) <= 0
|
||||
|
||||
if (isLegacy) {
|
||||
pipeline.add(PreNettyBaseProtocol.INSTANCE)
|
||||
|
@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit
|
||||
|
||||
object ProtocolDetector {
|
||||
val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val loader = CacheLoader.from<InetSocketAddress, CompletableFuture<ProtocolVersion>> { address ->
|
||||
val loader = CacheLoader.from<InetSocketAddress, CompletableFuture<ProtocolVersion>> { address ->
|
||||
val future = CompletableFuture<ProtocolVersion>()
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
@ -78,9 +78,17 @@ object ProtocolDetector {
|
||||
future
|
||||
}
|
||||
|
||||
private val SERVER_VER = CacheBuilder.newBuilder()
|
||||
private val versionCache = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(VIAaaSConfig.protocolDetectorCache.toLong(), TimeUnit.SECONDS)
|
||||
.build(loader)
|
||||
|
||||
fun detectVersion(address: InetSocketAddress): CompletableFuture<ProtocolVersion> = SERVER_VER[address]
|
||||
fun detectVersion(address: InetSocketAddress): CompletableFuture<ProtocolVersion> {
|
||||
val future = versionCache[address]
|
||||
future.whenComplete { _, throwable ->
|
||||
if (throwable != null) {
|
||||
versionCache.invalidate(address)
|
||||
}
|
||||
}
|
||||
return future
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user