OpenBazaar/go-onion-transport

Add Instructions On How to Use

Opened this issue · 9 comments

I would like to kindly request you to explain us in a few words how we can use this. Thanks !

Everything is in openbazaard.go if you want to take a look https://github.com/OpenBazaar/openbazaar-go/blob/master/openbazaard.go

Roughly it's:

  • create the transport
auth := &proxy.Auth{Password: torConfig.Password}
onionTransport, err = torOnion.NewOnionTransport("tcp4", torControl, auth, repoPath)
if err != nil {
        log.Error(err)
	return err
}
  • add a new supported transport
addrutil.SupportedTransportStrings = append(addrutil.SupportedTransportStrings, "/onion")
t, err := ma.ProtocolsWithString("/onion")
if err != nil {
	log.Error(err)
	return err
}
addrutil.SupportedTransportProtocols = append(addrutil.SupportedTransportProtocols, t)
if err != nil {
	log.Error(err)
	return err
}
  • Add the transport. This goes inside the defaultHostOption function:
network.Swarm().AddTransport(onionTransport)
  • Also make sure to listen on the onion multiaddr
bigs commented

Hopping back on this thread... I just did some work with this library for a little demo project of libp2p and found I had to do quite a bit of spelunking through the OpenBazaar codebase to get it working as expected. I'd be happy to contribute some abbreviated docs if that's of interest!

cretz commented

While we're hopping on this thread, I wrote https://github.com/cretz/bine which may be a bit easier to use and it supports statically compiled Tor.

bigs commented

@cretz That looks lovely! Would you have any interest in implementing a libp2p Transport?

Edit: Keeping in mind that this interface will shift a bit soon!

cretz commented

@bigs - Not particularly tbh. But it looks like tor.Tor almost implements it already so the work isn't hard. I figure since the iface is about to change soon it can probably wait. Also, someone should update https://github.com/multiformats/multiaddr because there are two types of onion addresses (v2 and v3) having different lengths. It's fine if it's still /onion but it can be two sizes.

@cretz so your lib compiles and installs the tor binary?

cretz commented

@cpacia - Not really. You can either point it to a Tor binary, or use https://github.com/cretz/tor-static + https://godoc.org/github.com/cretz/bine/process/embedded which
is just CGo wrapper around https://github.com/torproject/tor/blob/7fb941e9f26a1ae6b6faccea9a3e9620b8d90ef3/src/or/tor_api.h to statically link it inside the same binary as your Go app (adds about 20MB on WIndows).

Interesting. Have you tried using this on tails/whonix at all? One of the issues we've had with those OSs is their tor daemon is locked down and we can't easily communicate with it. I wonder if did this inside the Go binary if it would run with no issue on those OSs.

cretz commented

Have you tried using this on tails/whonix at all?

I have not.