]> Sergey Matveev's repositories - btrtrc.git/commitdiff
dht: Add PublicIP to config to secure node ID
authorMatt Joiner <anacrolix@gmail.com>
Mon, 3 Aug 2015 14:37:16 +0000 (00:37 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 3 Aug 2015 14:37:16 +0000 (00:37 +1000)
dht/dht.go

index 5db6adb4c236d3e44811d2d29b46b6ef29fecd0e..e269350f24ad662fe43a868c601aeb68a0bbdd00 100644 (file)
@@ -71,6 +71,8 @@ type ServerConfig struct {
        // Initial IP blocklist to use. Applied before serving and bootstrapping
        // begins.
        IPBlocklist *iplist.IPList
+       // Used to secure the server's ID. Defaults to the Conn's LocalAddr().
+       PublicIP net.IP
 }
 
 type ServerStats struct {
@@ -564,7 +566,14 @@ func (s *Server) setDefaults() (err error) {
                if len(id) != 20 {
                        panic(len(id))
                }
-               secureNodeId(id[:], util.AddrIP(s.socket.LocalAddr()))
+               publicIP := func() net.IP {
+                       if s.config.PublicIP != nil {
+                               return s.config.PublicIP
+                       } else {
+                               return missinggo.AddrIP(s.socket.LocalAddr())
+                       }
+               }()
+               secureNodeId(id[:], publicIP)
                s.id = string(id[:])
        }
        s.nodes = make(map[string]*node, maxNodes)