diff options
author | Felix Lange <fjl@twurst.com> | 2015-02-12 18:59:52 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-02-13 18:39:31 +0800 |
commit | 82f0bd9009d8d577c86e800e9673a1972117113d (patch) | |
tree | 9ff7257fa03b2b17650c9453d121a27937e36af9 /p2p | |
parent | d0a2e655c9599f462bb20bd49bc69b8e1e330a21 (diff) | |
download | go-tangerine-82f0bd9009d8d577c86e800e9673a1972117113d.tar.gz go-tangerine-82f0bd9009d8d577c86e800e9673a1972117113d.tar.zst go-tangerine-82f0bd9009d8d577c86e800e9673a1972117113d.zip |
p2p/discover: code review fixes
Diffstat (limited to 'p2p')
-rw-r--r-- | p2p/discover/node.go | 4 | ||||
-rw-r--r-- | p2p/discover/table.go | 8 | ||||
-rw-r--r-- | p2p/discover/udp.go | 4 |
3 files changed, 9 insertions, 7 deletions
diff --git a/p2p/discover/node.go b/p2p/discover/node.go index a49a2f547..c6d2e9766 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -18,6 +18,8 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) +const nodeIDBits = 512 + // Node represents a host on the network. type Node struct { ID NodeID @@ -135,7 +137,7 @@ func (n *Node) DecodeRLP(s *rlp.Stream) (err error) { // NodeID is a unique identifier for each node. // The node identifier is a marshaled elliptic curve public key. -type NodeID [512 / 8]byte +type NodeID [nodeIDBits / 8]byte // NodeID prints as a long hexadecimal number. func (n NodeID) String() string { diff --git a/p2p/discover/table.go b/p2p/discover/table.go index 1ff2c90d9..e3bec9328 100644 --- a/p2p/discover/table.go +++ b/p2p/discover/table.go @@ -14,9 +14,9 @@ import ( ) const ( - alpha = 3 // Kademlia concurrency factor - bucketSize = 16 // Kademlia bucket size - nBuckets = len(NodeID{})*8 + 1 // Number of buckets + alpha = 3 // Kademlia concurrency factor + bucketSize = 16 // Kademlia bucket size + nBuckets = nodeIDBits + 1 // Number of buckets ) type Table struct { @@ -100,7 +100,7 @@ func (tab *Table) Lookup(target NodeID) []*Node { tab.mutex.Unlock() for { - // ask the closest nodes that we haven't asked yet + // ask the alpha closest nodes that we haven't asked yet for i := 0; i < len(result.entries) && pendingQueries < alpha; i++ { n := result.entries[i] if !asked[n.ID] { diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index 4ad5d9cc4..1f91641f3 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -28,7 +28,7 @@ var ( const ( respTimeout = 300 * time.Millisecond sendTimeout = 300 * time.Millisecond - expiration = 3 * time.Second + expiration = 20 * time.Second refreshInterval = 1 * time.Hour ) @@ -185,7 +185,7 @@ func (t *udp) findnode(to *Node, target NodeID) ([]*Node, error) { nodes = append(nodes, n) } } - return nreceived == bucketSize + return nreceived >= bucketSize }) t.send(to, findnodePacket, findnode{ |