Skip to content

05nelsonm/kmp-tor

Repository files navigation

kmp-tor

badge-license badge-latest-release

badge-kotlin badge-coroutines badge-encoding badge-kmp-process badge-kmp-tor-common badge-kotlincrypto-hash badge-kotlincrypto-secure-random badge-androidx-startup

badge-platform-android badge-platform-jvm badge-platform-js-node badge-platform-linux badge-platform-ios badge-platform-macos badge-support-apple-silicon badge-support-js-ir badge-support-linux-arm

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(),
                        )  
                    },
                )
            },
        )
    },
)

Get Started

Samples

See kmp-tor-samples