2017-10-25 22:06:26 +03:00
|
|
|
package torsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2018-01-23 06:59:15 +03:00
|
|
|
// RegularNet is an implementation of the Net interface that defines behaviour
|
|
|
|
// for Regular network connections
|
|
|
|
type RegularNet struct{}
|
2017-10-25 22:06:26 +03:00
|
|
|
|
2018-01-23 06:59:15 +03:00
|
|
|
// Dial on the regular network uses net.Dial
|
|
|
|
func (r *RegularNet) Dial(network, address string) (net.Conn, error) {
|
2017-10-25 22:06:26 +03:00
|
|
|
return net.Dial(network, address)
|
|
|
|
}
|
|
|
|
|
2018-01-23 06:59:15 +03:00
|
|
|
// LookupHost for regular network uses the net.LookupHost function
|
|
|
|
func (r *RegularNet) LookupHost(host string) ([]string, error) {
|
2017-10-25 22:06:26 +03:00
|
|
|
return net.LookupHost(host)
|
|
|
|
}
|
|
|
|
|
2018-01-23 06:59:15 +03:00
|
|
|
// LookupSRV for regular network uses net.LookupSRV function
|
|
|
|
func (r *RegularNet) LookupSRV(service, proto, name string) (string, []*net.SRV, error) {
|
2017-10-25 22:06:26 +03:00
|
|
|
return net.LookupSRV(service, proto, name)
|
|
|
|
}
|
|
|
|
|
2018-01-23 06:59:15 +03:00
|
|
|
// ResolveTCPAddr for regular network uses net.ResolveTCPAddr function
|
|
|
|
func (r *RegularNet) ResolveTCPAddr(network, address string) (*net.TCPAddr, error) {
|
2017-10-25 22:06:26 +03:00
|
|
|
return net.ResolveTCPAddr(network, address)
|
|
|
|
}
|
2018-01-23 06:59:15 +03:00
|
|
|
|
|
|
|
// TorProxyNet is an implementation of the Net interface that defines behaviour
|
|
|
|
// for Tor network connections
|
|
|
|
type TorProxyNet struct {
|
|
|
|
// TorDNS is the IP:PORT of the DNS server for Tor to use for SRV queries
|
|
|
|
TorDNS string
|
|
|
|
|
|
|
|
// TorSocks is the port which Tor's exposed SOCKS5 proxy is listening on.
|
|
|
|
// This is used for an outbound-only mode, so the node will not listen for
|
|
|
|
// incoming connections
|
|
|
|
TorSocks string
|
2018-02-06 05:32:52 +03:00
|
|
|
|
|
|
|
// 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
|
2018-01-23 06:59:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dial on the Tor network uses the torsvc TorDial() function, and requires
|
|
|
|
// that network specified be tcp because only that is supported
|
|
|
|
func (t *TorProxyNet) Dial(network, address string) (net.Conn, error) {
|
|
|
|
if network != "tcp" {
|
|
|
|
return nil, fmt.Errorf("Cannot dial non-tcp network via Tor")
|
|
|
|
}
|
2018-02-06 05:32:52 +03:00
|
|
|
return TorDial(address, t.TorSocks, t.StreamIsolation)
|
2018-01-23 06:59:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// LookupHost on Tor network uses the torsvc TorLookupHost function.
|
|
|
|
func (t *TorProxyNet) LookupHost(host string) ([]string, error) {
|
|
|
|
return TorLookupHost(host, t.TorSocks)
|
|
|
|
}
|
|
|
|
|
|
|
|
// LookupSRV on Tor network uses the torsvc TorLookupHost function.
|
|
|
|
func (t *TorProxyNet) LookupSRV(service, proto, name string) (string, []*net.SRV, error) {
|
|
|
|
return TorLookupSRV(service, proto, name, t.TorSocks, t.TorDNS)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResolveTCPAddr on Tor network uses the towsvc TorResolveTCP function, and
|
|
|
|
// requires network to be "tcp" because only "tcp" is supported
|
|
|
|
func (t *TorProxyNet) ResolveTCPAddr(network, address string) (*net.TCPAddr, error) {
|
|
|
|
if network != "tcp" {
|
|
|
|
return nil, fmt.Errorf("Cannot dial non-tcp network via Tor")
|
|
|
|
}
|
|
|
|
return TorResolveTCP(address, t.TorSocks)
|
|
|
|
}
|