TorApi

abstract class TorApi(source)

Abstraction for ResourceLoader.Tor.NoExec implementations to provide.

Implementations of TorApi must support restart capabilities. The only reliable way to do this with the tor C library is dynamic loading/unloading before/after each invocation of tor_run_main. This is due to static variables in tor that are never uninitialized, requiring that it be unloaded from memory via dlclose (or FreeLibrary for Windows) after tor_run_main completes and all necessary cleanup has been performed. If tor is not unloaded after completion of tor_run_main, successive calls to torRunMain run the highly probable risk of encountering a segmentation fault. The API design of TorApi was conceived with this necessity in mind.

Constructors

Link copied to clipboard
protected constructor()

Types

Link copied to clipboard
enum State : Enum<TorApi.State>

Functions

Link copied to clipboard
abstract fun state(): TorApi.State

Retrieve the current State of the TorApi implementation.

Link copied to clipboard
abstract fun terminateAndAwaitResult(): Int

Terminates tor (if it is running) and releases resources. This MUST be called before another invocation of torRunMain can be had.

Link copied to clipboard
protected abstract fun torRunMain(args: Array<String>)

Design is such that implementations must start tor in its own thread and return upon successful startup. Any errors must be thrown as the annotated exceptions and state must be reset to State.OFF.

fun torRunMain(configuration: List<String>)

Executes tor's tor_run_main function. If it does not throw, tor has been started. A following call to terminateAndAwaitResult MUST be had before calling torRunMain again.