From: Matt Joiner Date: Mon, 3 Aug 2015 14:37:16 +0000 (+1000) Subject: dht: Add PublicIP to config to secure node ID X-Git-Tag: v1.0.0~1094 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=6afaa816bfcdcc15268c884154e209ceb46ab55c;p=btrtrc.git dht: Add PublicIP to config to secure node ID --- diff --git a/dht/dht.go b/dht/dht.go index 5db6adb4..e269350f 100644 --- a/dht/dht.go +++ b/dht/dht.go @@ -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)