Kotlin Multiplatform support for embedding Tor into your application.
val runtime = TorRuntime.Builder(myEnvironment) {
RuntimeEvent.entries().forEach { event ->
observerStatic(event, OnEvent.Executor.Immediate) { data ->
println(data.toString())
}
}
TorEvent.entries().forEach { event ->
observerStatic(event, OnEvent.Executor.Immediate) { data ->
println(data)
}
}
config { environment ->
TorOption.SocksPort.configure { auto() }
// ...
}
required(TorEvent.ERR)
required(TorEvent.WARN)
}
// Asynchronous APIs
myScope.launch {
runtime.startDaemonAsync()
runtime.restartDaemonAsync()
runtime.executeAsync(TorCmd.Signal.NewNym)
runtime.stopDaemonAsync()
}
// Synchronous APIs (Android/Jvm/Native)
runtime.startDaemonSync()
runtime.restartDaemonSync()
runtime.executeSync(TorCmd.Signal.NewNym)
runtime.stopDaemonSync()
// Callback APIs
runtime.enqueue(
Action.StartDaemon,
OnFailure.noOp(),
OnSuccess {
runtime.enqueue(
Action.RestartDaemon,
OnFailure.noOp(),
OnSuccess {
runtime.enqueue(
TorCmd.Signal.NewNym,
OnFailure.noOp(),
OnSuccess {
runtime.enqueue(
Action.StopDaemon,
OnFailure.noOp(),
OnSuccess.noOp(),
)
},
)
},
)
},
)
-
Add runtime dependency
// build.gradle.kts val vKmpTor = "2.0.0-alpha02" dependencies { implementation("io.matthewnelson.kmp-tor:runtime:$vKmpTor") }
-
Configure tor resources
-
Configure optional service dependency
- See runtime-service
-
Refer to the API docs
See kmp-tor-samples