From 2eb9059cf78a294a0ef772f1f25babf4a660f3cd Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 5 Feb 2018 18:32:52 -0800 Subject: [PATCH] torsvc: add support for stream isolation In this commit, we extend the TorDial function and add a new attribute to the TorProxyNet struct to allow the caller to opt for stream isolation or not. Using stream isolation, we ensure that each new connection uses a distinct circuit. --- torsvc/net.go | 8 +++++++- torsvc/torsvc.go | 13 ++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/torsvc/net.go b/torsvc/net.go index 0a5576fd..859189ac 100644 --- a/torsvc/net.go +++ b/torsvc/net.go @@ -39,6 +39,12 @@ type TorProxyNet struct { // This is used for an outbound-only mode, so the node will not listen for // incoming connections TorSocks string + + // StreamIsolation is a bool that determines if we should force the + // creation of a new circuit for this connection. If true, then this + // means that our traffic may be harder to correlate as each connection + // will now use a distinct circuit. + StreamIsolation bool } // Dial on the Tor network uses the torsvc TorDial() function, and requires @@ -47,7 +53,7 @@ func (t *TorProxyNet) Dial(network, address string) (net.Conn, error) { if network != "tcp" { return nil, fmt.Errorf("Cannot dial non-tcp network via Tor") } - return TorDial(address, t.TorSocks) + return TorDial(address, t.TorSocks, t.StreamIsolation) } // LookupHost on Tor network uses the torsvc TorLookupHost function. diff --git a/torsvc/torsvc.go b/torsvc/torsvc.go index 7325000c..29369373 100644 --- a/torsvc/torsvc.go +++ b/torsvc/torsvc.go @@ -44,9 +44,16 @@ var ( ) // TorDial returns a connection to a remote peer via Tor's socks proxy. Only -// TCP is supported over Tor. -func TorDial(address, socksPort string) (net.Conn, error) { - p := &socks.Proxy{Addr: localhost + ":" + socksPort} +// TCP is supported over Tor. The final argument determines if we should force +// stream isolation for this new connection. If we do, then this means this new +// connection will use a fresh circuit, rather than possibly re-using an +// existing circuit. +func TorDial(address, socksPort string, streamIsolation bool) (net.Conn, error) { + p := &socks.Proxy{ + Addr: localhost + ":" + socksPort, + TorIsolation: streamIsolation, + } + return p.Dial("tcp", address) }