mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 21:20:55 +00:00
Implement usage of the new Tailscale channel library.
This commit is contained in:
parent
02a5d02dad
commit
2262ceb1d1
@ -18,7 +18,7 @@ class FoundationChaosPlugin : BaseFoundationPlugin() {
|
||||
config = loadConfigurationWithDefault(
|
||||
foundation,
|
||||
ChaosConfig.serializer(),
|
||||
"heimdall.yaml"
|
||||
"chaos.yaml"
|
||||
)
|
||||
registerCommandExecutor("chaos", ChaosToggleCommand())
|
||||
}
|
||||
|
@ -2,6 +2,6 @@ package gay.pizza.foundation.core.features.persist
|
||||
|
||||
import jetbrains.exodus.entitystore.Entity
|
||||
|
||||
fun <T : Comparable<*>> Entity.setAllProperties(vararg entries: Pair<String, T>) = entries.forEach { entry ->
|
||||
fun <T : Comparable<*>> Entity.setAllProperties(vararg entries: Pair<String, T>): Unit = entries.forEach { entry ->
|
||||
setProperty(entry.first, entry.second)
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ dependencies {
|
||||
implementation(project(":common-plugin"))
|
||||
compileOnly(project(":foundation-shared"))
|
||||
implementation(libs.tailscale)
|
||||
implementation(libs.tailscale.channel)
|
||||
}
|
||||
|
||||
concreteItem {
|
||||
|
@ -1,16 +1,13 @@
|
||||
package gay.pizza.foundation.tailscale
|
||||
|
||||
import gay.pizza.tailscale.channel.ChannelCopier
|
||||
import gay.pizza.tailscale.core.Tailscale
|
||||
import gay.pizza.tailscale.core.TailscaleConn
|
||||
import gay.pizza.tailscale.core.TailscaleListener
|
||||
import org.bukkit.Server
|
||||
import java.net.InetSocketAddress
|
||||
import java.net.StandardSocketOptions
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.channels.ClosedChannelException
|
||||
import java.nio.channels.ReadableByteChannel
|
||||
import java.nio.channels.SocketChannel
|
||||
import java.nio.channels.WritableByteChannel
|
||||
|
||||
class TailscaleProxyServer(val server: Server, val tailscale: Tailscale) {
|
||||
private var minecraftServerListener: TailscaleListener? = null
|
||||
@ -34,38 +31,13 @@ class TailscaleProxyServer(val server: Server, val tailscale: Tailscale) {
|
||||
val readChannel = conn.openReadChannel()
|
||||
val writeChannel = conn.openWriteChannel()
|
||||
|
||||
fun closeAll() {
|
||||
socketChannel.close()
|
||||
readChannel.close()
|
||||
writeChannel.close()
|
||||
}
|
||||
|
||||
fun startCopyThread(name: String, from: ReadableByteChannel, to: WritableByteChannel) {
|
||||
val thread = Thread {
|
||||
try {
|
||||
while (true) {
|
||||
val buffer = ByteBuffer.allocate(2048)
|
||||
val size = from.read(buffer)
|
||||
if (size < 0) {
|
||||
break
|
||||
} else {
|
||||
buffer.flip()
|
||||
to.write(buffer)
|
||||
}
|
||||
buffer.clear()
|
||||
}
|
||||
} catch (_: ClosedChannelException) {
|
||||
} finally {
|
||||
closeAll()
|
||||
}
|
||||
}
|
||||
|
||||
thread.name = name
|
||||
thread.start()
|
||||
}
|
||||
|
||||
startCopyThread("Tailscale to Socket Pipe", readChannel, socketChannel)
|
||||
startCopyThread("Socket to Tailscale Pipe", socketChannel, writeChannel)
|
||||
val closeHandler = { socketChannel.close() }
|
||||
val tailscaleSocketCopier = ChannelCopier(readChannel, socketChannel)
|
||||
tailscaleSocketCopier.spawnCopyThread(
|
||||
"Tailscale to Socket Copier", onClose = closeHandler)
|
||||
val socketTailscaleCopier = ChannelCopier(socketChannel, writeChannel)
|
||||
socketTailscaleCopier.spawnCopyThread(
|
||||
"Socket to Tailscale Copier", onClose = closeHandler)
|
||||
}
|
||||
|
||||
fun close() {
|
||||
|
@ -73,7 +73,7 @@ dependencyResolutionManagement {
|
||||
version("postgresql", "42.5.3")
|
||||
version("exposed", "0.41.1")
|
||||
version("hikaricp", "5.0.1")
|
||||
version("libtailscale", "0.1.2-SNAPSHOT")
|
||||
version("libtailscale", "0.1.4-SNAPSHOT")
|
||||
|
||||
library("clikt", "com.github.ajalt.clikt", "clikt").versionRef("clikt")
|
||||
library("xodus-core", "org.jetbrains.xodus", "xodus-openAPI").versionRef("xodus")
|
||||
@ -93,6 +93,7 @@ dependencyResolutionManagement {
|
||||
library("exposed-java-time", "org.jetbrains.exposed", "exposed-java-time").versionRef("exposed")
|
||||
library("hikaricp", "com.zaxxer", "HikariCP").versionRef("hikaricp")
|
||||
library("tailscale", "gay.pizza.tailscale", "tailscale").versionRef("libtailscale")
|
||||
library("tailscale-channel", "gay.pizza.tailscale", "tailscale-channel").versionRef("libtailscale")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user