sneurlax / libtor

Bundle and run Tor inside your own project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

libtor

MagicalBitcoin/libtor as a multi-platform Flutter FFI plugin for bundling Tor in a Flutter app. Based on libtor.

Getting started

Install cargo ndk

cargo install cargo-ndk

Install dependencies

sudo apt install git build-essential cmake llvm clang pkg-config cargo rustc libssl-dev libc6-dev-i386
cargo install --force cbindgen

Run build scripts

Linux

Run build script

cd scripts/linux
./build_all.sh

Android

Run the NDK setup and build scripts

cd scripts/android
./install_ndk.sh
./build_all.sh

Development notes

To generate libtor/libtor.h: flutter pub run ffigen --config ffigen.yaml

Flutter FFI plugin template

libtor is a Rust crate for bundling inside your project a fully-running Tor daemon. It exposes a nicer interface to operate it compared to the bare-bones version, libtor-sys. If you need further instructions on how to build or cross-compile the project, you should refer to the libtor-sys README.md.

libtor makes it easier for projects on multiple platforms to use Tor without depending on the user to configure complex proxy settings from other external software.

Example

use libtor::{Tor, TorFlag, TorAddress, HiddenServiceVersion};

Tor::new()
    .flag(TorFlag::DataDirectory("/tmp/tor-rust".into()))
    .flag(TorFlag::SocksPort(19050))
    .flag(TorFlag::HiddenServiceDir("/tmp/tor-rust/hs-dir".into()))
    .flag(TorFlag::HiddenServiceVersion(HiddenServiceVersion::V3))
    .flag(TorFlag::HiddenServicePort(TorAddress::Port(8000), None.into()))
    .start()?;

Since Tor uses internally some static variables to keep its state, keep in mind that you can't start more than one Tor instance per process.

Supported platforms

The currently supported platforms are:

  • Linux (tested on Fedora 30 and Ubuntu Xenial)
  • Android through the NDK
  • MacOS
  • iOS
  • Windows cross-compiled from Linux with mingw

Coming Soon ™️:

  • Windows (natively built)

Dependencies

The following dependencies are needed:

  • openssl
  • pkg-config
  • file
  • the "usual" C build tools: a compiler, automake, autoconf

About

Bundle and run Tor inside your own project

License:MIT License


Languages

Language:Rust 34.8%Language:C++ 25.3%Language:CMake 20.6%Language:Dart 10.3%Language:Shell 4.1%Language:Ruby 2.4%Language:C 1.2%Language:Swift 1.1%Language:Kotlin 0.1%Language:Objective-C 0.0%