Skip to content

Commit 82f0bd9

Browse files
committed
p2p/discover: code review fixes
1 parent d0a2e65 commit 82f0bd9

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎p2p/discover/node.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/ethereum/go-ethereum/rlp"
1919
)
2020

21+
const nodeIDBits = 512
22+
2123
// Node represents a host on the network.
2224
type Node struct {
2325
ID NodeID
@@ -135,7 +137,7 @@ func (n *Node) DecodeRLP(s *rlp.Stream) (err error) {
135137

136138
// NodeID is a unique identifier for each node.
137139
// The node identifier is a marshaled elliptic curve public key.
138-
type NodeID [512 / 8]byte
140+
type NodeID [nodeIDBits / 8]byte
139141

140142
// NodeID prints as a long hexadecimal number.
141143
func (n NodeID) String() string {

‎p2p/discover/table.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
)
1515

1616
const (
17-
alpha = 3 // Kademlia concurrency factor
18-
bucketSize = 16 // Kademlia bucket size
19-
nBuckets = len(NodeID{})*8 + 1 // Number of buckets
17+
alpha = 3 // Kademlia concurrency factor
18+
bucketSize = 16 // Kademlia bucket size
19+
nBuckets = nodeIDBits + 1 // Number of buckets
2020
)
2121

2222
type Table struct {
@@ -100,7 +100,7 @@ func (tab *Table) Lookup(target NodeID) []*Node {
100100
tab.mutex.Unlock()
101101

102102
for {
103-
// ask the closest nodes that we haven't asked yet
103+
// ask the alpha closest nodes that we haven't asked yet
104104
for i := 0; i < len(result.entries) && pendingQueries < alpha; i++ {
105105
n := result.entries[i]
106106
if !asked[n.ID] {

‎p2p/discover/udp.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var (
2828
const (
2929
respTimeout = 300 * time.Millisecond
3030
sendTimeout = 300 * time.Millisecond
31-
expiration = 3 * time.Second
31+
expiration = 20 * time.Second
3232

3333
refreshInterval = 1 * time.Hour
3434
)
@@ -185,7 +185,7 @@ func (t *udp) findnode(to *Node, target NodeID) ([]*Node, error) {
185185
nodes = append(nodes, n)
186186
}
187187
}
188-
return nreceived == bucketSize
188+
return nreceived >= bucketSize
189189
})
190190

191191
t.send(to, findnodePacket, findnode{

0 commit comments

Comments
 (0)