Skip to content

About

C#/.NET Tor HTTP client

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

C#/.NET Onion HTTP Client Library

A simple HTTP client that routes requests through The Onion Router (Tor) protocol using automatically-managed local Tor proxies.

Requirements

  • .NET 10.0 or later

  • Tor Expert Bundle installed:

    • macOS (using Homebrew): brew install tor
    • Ubuntu: sudo apt install tor
    • Windows: Currently not supported

    Note: Do not start the Tor service. Each Tor HTTP client (class TorHttpClient instance) will automatically manage its own Tor proxy.

Configuration

Create a Tor control password by running tor --hash-password <YOUR_PLAIN_TEXT_PASSWORD>.

Create torrc-defaults file in the same directory as the executable with the following content:

SOCKSPort 9050
ControlPort 9051
HashedControlPassword <YOUR_HASHED_PASSWORD>

Create onionhttpclient.secrets.json in the same directory as the executable with the following content:

{
    "Tor": {
        "ControlPassword": "<YOUR_PLAIN_TEXT_PASSWORD>"
    }
}

Usage

Single Tor HTTP Client (class TorHttpClient)

Manages an internal HTTP client and Tor service.

using Kokoabim.OnionHttpClient;

hostBuilder.AddOnionHttpClient();
// --- OR ---
serviceCollection.AddOnionHttpClient();

...

var httpClientSettings = new HttpClientInstanceSettings()
{
    ...
};

var torSettings = new TorInstanceSettings();

using var torHttpClient = services.GetRequiredService<ITorHttpClient>();
await torHttpClient.InitializeAsync(httpClientSettings, torSettings);

var response = await torHttpClient.GetResponseAsync(...);
// --- OR ---
var response = await torHttpClient.SendAsync(...);

...

await torHttpClient.DisconnectAsync();

Multi Tor HTTP Client (class MultiTorHttpClient)

Manages multiple internal HTTP clients and Tor services and balances requests between them.

using Kokoabim.OnionHttpClient;

hostBuilder.AddOnionHttpClient();
// --- OR ---
serviceCollection.AddOnionHttpClient();

...

var multiTorHttpClientSettings = new MultiTorHttpClientSettings
{
    BalanceStrategy = MultiTorHttpClientBalanceStrategy.RoundRobin,
    ClientCount = 2,
    ...
};

var httpClientCommonSettings = new HttpClientCommonSettings()
{
    ...
};

using var multiTorHttpClient = services.GetRequiredService<IMultiTorHttpClient>();
await multiTorHttpClient.InitializeAsync(multiTorHttpClientSettings, httpClientCommonSettings);

var response = await multiTorHttpClient.GetResponseAsync(...);
// --- OR ---
var response = await multiTorHttpClient.SendAsync(...);

...

await multiTorHttpClient.DisconnectAsync();

About

C#/.NET Tor HTTP client

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages