torsvc: Added new module to house Tor functions

This commit adds a new module named 'torsvc' which houses all Tor
functionality in an attempt to isolate it and make it reusable in
other projecs. Some additional tweaks were made to config.go and
to the bootstrapper.
This commit is contained in:
nsa
2017-10-24 22:02:29 -04:00
committed by Olaoluwa Osuntokun
parent e2142c778f
commit e132ad8433
5 changed files with 205 additions and 154 deletions

View File

@@ -246,8 +246,9 @@ type DNSSeedBootstrapper struct {
// in the tuple is a special A record that we'll query in order to
// receive the IP address of the current authoritative DNS server for
// the network seed.
dnsSeeds [][2]string
lookupFns []interface{}
dnsSeeds [][2]string
lookupHost func(string) ([]string, error)
lookupSRV func(string, string, string) (string, []*net.SRV, error)
}
// A compile time assertion to ensure that DNSSeedBootstrapper meets the
@@ -261,10 +262,13 @@ var _ NetworkPeerBootstrapper = (*ChannelGraphBootstrapper)(nil)
// used as a fallback for manual TCP resolution in the case of an error
// receiving the UDP response. The second host should return a single A record
// with the IP address of the authoritative name server.
func NewDNSSeedBootstrapper(seeds [][2]string, lookupFns []interface{}) (NetworkPeerBootstrapper, error) {
func NewDNSSeedBootstrapper(seeds [][2]string, lookupHost func(string) ([]string, error),
lookupSRV func(string, string, string) (string, []*net.SRV, error)) (
NetworkPeerBootstrapper, error) {
return &DNSSeedBootstrapper{
dnsSeeds: seeds,
lookupFns: lookupFns,
dnsSeeds: seeds,
lookupHost: lookupHost,
lookupSRV: lookupSRV,
}, nil
}
@@ -351,7 +355,7 @@ search:
// keys of nodes. We use the lndLookupSRV function for
// this task.
primarySeed := dnsSeedTuple[0]
_, addrs, err := d.lookupFns[1].(func(string, string, string) (string, []*net.SRV, error))("nodes", "tcp", primarySeed)
_, addrs, err := d.lookupSRV("nodes", "tcp", primarySeed)
if err != nil {
log.Tracef("Unable to lookup SRV records via " +
"primary seed, falling back to secondary")
@@ -390,7 +394,7 @@ search:
// key. We use the lndLookup function for this
// task.
bechNodeHost := nodeSrv.Target
addrs, err := d.lookupFns[0].(func(string) ([]string, error))(bechNodeHost)
addrs, err := d.lookupHost(bechNodeHost)
if err != nil {
return nil, err
}