From bdaeaf80c94c288873b269ad203e3c411d5a55ae Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 2 Apr 2015 23:35:30 +0100 Subject: [PATCH] Added BootstrapNodes to dht.ServerConfig This is beneficial to users who are running their own private trackers or have outbound connections to ports 6881 disallowed on firewalls. --- dht/announce.go | 2 +- dht/dht.go | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dht/announce.go b/dht/announce.go index 4aadd454..a179263b 100644 --- a/dht/announce.go +++ b/dht/announce.go @@ -51,7 +51,7 @@ func (s *Server) Announce(infoHash string, port int, impliedPort bool) (*Announc }() s.mu.Unlock() if len(startAddrs) == 0 { - addrs, err := bootstrapAddrs() + addrs, err := bootstrapAddrs(s.bootstrapNodes) if err != nil { return nil, err } diff --git a/dht/dht.go b/dht/dht.go index 1fb38034..b9ea3ee7 100644 --- a/dht/dht.go +++ b/dht/dht.go @@ -50,6 +50,7 @@ type Server struct { ipBlockList *iplist.IPList numConfirmedAnnounces int + bootstrapNodes []string } type dHTAddr interface { @@ -83,6 +84,8 @@ type ServerConfig struct { Conn net.PacketConn // Don't respond to queries from other nodes. Passive bool + // DHT Bootstrap nodes + BootstrapNodes []string } type ServerStats struct { @@ -142,6 +145,7 @@ func NewServer(c *ServerConfig) (s *Server, err error) { } } s.passive = c.Passive + s.bootstrapNodes = c.BootstrapNodes err = s.init() if err != nil { return @@ -967,11 +971,15 @@ func (s *Server) getPeers(addr dHTAddr, infoHash string) (t *Transaction, err er return } -func bootstrapAddrs() (addrs []*net.UDPAddr, err error) { - for _, addrStr := range []string{ - "router.utorrent.com:6881", - "router.bittorrent.com:6881", - } { +func bootstrapAddrs(nodeAddrs []string) (addrs []*net.UDPAddr, err error) { + bootstrapNodes := nodeAddrs + if len(bootstrapNodes) == 0 { + bootstrapNodes = []string{ + "router.utorrent.com:6881", + "router.bittorrent.com:6881", + } + } + for _, addrStr := range bootstrapNodes { udpAddr, err := net.ResolveUDPAddr("udp4", addrStr) if err != nil { continue @@ -985,7 +993,7 @@ func bootstrapAddrs() (addrs []*net.UDPAddr, err error) { } func (s *Server) addRootNodes() error { - addrs, err := bootstrapAddrs() + addrs, err := bootstrapAddrs(s.bootstrapNodes) if err != nil { return err } -- 2.48.1