Commit aa98d98b authored by Matt Joiner's avatar Matt Joiner

Fix SecureNodeId, it needs a pointer to the array

parent 6950c49f
......@@ -116,6 +116,6 @@ func MakeDeterministicNodeID(public net.Addr) (id [20]byte) {
h := crypto.SHA1.New()
h.Write([]byte(public.String()))
h.Sum(id[:0:20])
SecureNodeId(id, missinggo.AddrIP(public))
SecureNodeId(&id, missinggo.AddrIP(public))
return
}
......@@ -32,7 +32,7 @@ func crcIP(ip net.IP, rand uint8) uint32 {
// Makes a node ID secure, in-place. The ID is 20 raw bytes.
// http://www.libtorrent.org/dht_sec.html
func SecureNodeId(id [20]byte, ip net.IP) {
func SecureNodeId(id *[20]byte, ip net.IP) {
crc := crcIP(ip, id[19])
id[0] = byte(crc >> 24 & 0xff)
id[1] = byte(crc >> 16 & 0xff)
......
......@@ -49,7 +49,7 @@ func TestDHTSec(t *testing.T) {
assert.Equal(t, case_.valid, secure, "%v", case_)
if !secure {
// It's not secure, so secure it in place and then check it again.
SecureNodeId(id, ip)
SecureNodeId(&id, ip)
assert.True(t, NodeIdSecure(id, ip), "%v", case_)
}
}
......
......@@ -100,7 +100,7 @@ func NewServer(c *ServerConfig) (s *Server, err error) {
if missinggo.IsZeroValue(c.NodeId) {
c.NodeId = RandomNodeID()
if !c.NoSecurity {
SecureNodeId(c.NodeId, c.PublicIP)
SecureNodeId(&c.NodeId, c.PublicIP)
}
}
// if missinggo.IsEmptyValue(c.NodeId) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment