diff --git a/p2p/discover/node.go b/p2p/discover/node.go index 8a3854f4ef..a0fa255e69 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -22,13 +22,13 @@ import ( const nodeIDBits = 512 // nodeIDHash is the hash of a NodeID -type nodeIDHash []byte +type NodeIDHash []byte // hashNodeID generates a nodeIDHash from a NodeID by hashing it using sha3-256 -func hashNodeID(id NodeID) nodeIDHash { +func hashNodeID(id NodeID) NodeIDHash { h := sha3.NewKeccak256() h.Write(id[:]) - return nodeIDHash(h.Sum(nil)) + return NodeIDHash(h.Sum(nil)) } // Node represents a host on the network. @@ -219,7 +219,7 @@ func recoverNodeID(hash, sig []byte) (id NodeID, err error) { // distcmp compares the distances a->target and b->target. // Returns -1 if a is closer to target, 1 if b is closer to target // and 0 if they are equal. -func distcmp(target, a, b nodeIDHash) int { +func distcmp(target, a, b NodeIDHash) int { for i := range target { da := a[i] ^ target[i] db := b[i] ^ target[i] @@ -269,7 +269,7 @@ var lzcount = [256]int{ } // logdist returns the logarithmic distance between a and b, log2(a ^ b). -func logdist(a, b nodeIDHash) int { +func logdist(a, b NodeIDHash) int { lz := 0 for i := range a { diff --git a/p2p/discover/node_test.go b/p2p/discover/node_test.go index 48c7d8ac20..53afb930a0 100644 --- a/p2p/discover/node_test.go +++ b/p2p/discover/node_test.go @@ -161,7 +161,7 @@ func TestNodeID_distcmpEqual(t *testing.T) { } func TestNodeID_logdist(t *testing.T) { - logdistBig := func(a, b nodeIDHash) int { + logdistBig := func(a, b NodeIDHash) int { abig, bbig := new(big.Int).SetBytes(a[:]), new(big.Int).SetBytes(b[:]) return new(big.Int).Xor(abig, bbig).BitLen() } diff --git a/p2p/discover/table.go b/p2p/discover/table.go index 4c75f002ac..91b6ea9726 100644 --- a/p2p/discover/table.go +++ b/p2p/discover/table.go @@ -259,7 +259,7 @@ func (b *bucket) bump(id NodeID) *Node { // distance to target. type nodesByDistance struct { entries []*Node - target nodeIDHash + target NodeIDHash } // push adds the given node to the list, keeping the total size below maxElems. diff --git a/p2p/discover/table_test.go b/p2p/discover/table_test.go index 50dfc54f54..55c20361e7 100644 --- a/p2p/discover/table_test.go +++ b/p2p/discover/table_test.go @@ -184,8 +184,8 @@ type closeTest struct { Self NodeID Target NodeID - SelfHash nodeIDHash - TargetHash nodeIDHash + SelfHash NodeIDHash + TargetHash NodeIDHash All []*Node N int @@ -281,8 +281,8 @@ func hasDuplicates(slice []*Node) bool { return false } -func sortedByDistanceTo(distbase nodeIDHash, slice []*Node) bool { - var last nodeIDHash +func sortedByDistanceTo(distbase NodeIDHash, slice []*Node) bool { + var last NodeIDHash for i, e := range slice { if i > 0 && distcmp(distbase, e.idHash, last) < 0 { return false