berty / go-libp2p-tor-transport

🚧 WIP: tor transport for libp2p
Apache License 2.0
53 stars 7 forks source link
berty ipfs libp2p onion privacy tor

go-libp2p-tor-transport

Go tor transport is a go-libp2p transport targeting mainly *nix platform.

WIP

This transport is in very early stages (PoC) many of features enumerated here are just targets.

You can follow the process of the 1.0 here.

Usage :

import (
  "context"

  tor "berty.tech/go-libp2p-tor-transport"
  config "berty.tech/go-libp2p-tor-transport/config"
  libp2p "github.com/libp2p/go-libp2p"
)

func main() {
  builder, err := tor.NewBuilder( // Create a builder
    config.EnableEmbeded,         // Use the embeded tor instance.
  )
  c(err)
  host, err := libp2p.New(        // Create a libp2p node
    context.Background(),
    libp2p.Transport(builder),    // Use the builder to create a transport instance (you can't reuse the same builder after that).
  )
  c(err)
}

func c(err error) { // Used to check error in this example, replace by whatever you want.
  if err != nil {
    panic(err)
  }
}

With config :

import (
  "context"
  "time"

  tor "berty.tech/go-libp2p-tor-transport"
  config "berty.tech/go-libp2p-tor-transport/config"
  libp2p "github.com/libp2p/go-libp2p"
)

func main() {
  builder, err := tor.NewBuilder(        // NewBuilder can accept some `config.Configurator`
    config.AllowTcpDial,                 // Some Configurator are already ready to use.
    config.SetSetupTimeout(time.Minute), // Some require a parameter, in this case it's a function that will return a Configurator.
    config.SetBinaryPath("/usr/bin/tor"),
  )
  // Evrything else is as previously shown.
  c(err)
  hostWithConfig, err := libp2p.New(
    context.Background(),
    libp2p.Transport(builder),
  )
  c(err)
}

func c(err error) {
  if err != nil {
    panic(err)
  }
}

Support

This transport target *nix (Linux, OSX, IOS, Android, ...), it also can be built for windows but many of the attack reduction mesures will not be present (on windows potentialy un encrypted traffic will transit through the loopback, also some tor control port are gonna be exposed.).

Tor Provider Compatibility

You can use 3 different provider :

Running Mode