p2p/discover: code review fixes
This commit is contained in:
parent
d0a2e655c9
commit
82f0bd9009
@ -18,6 +18,8 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const nodeIDBits = 512
|
||||||
|
|
||||||
// Node represents a host on the network.
|
// Node represents a host on the network.
|
||||||
type Node struct {
|
type Node struct {
|
||||||
ID NodeID
|
ID NodeID
|
||||||
@ -135,7 +137,7 @@ func (n *Node) DecodeRLP(s *rlp.Stream) (err error) {
|
|||||||
|
|
||||||
// NodeID is a unique identifier for each node.
|
// NodeID is a unique identifier for each node.
|
||||||
// The node identifier is a marshaled elliptic curve public key.
|
// 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.
|
// NodeID prints as a long hexadecimal number.
|
||||||
func (n NodeID) String() string {
|
func (n NodeID) String() string {
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
alpha = 3 // Kademlia concurrency factor
|
alpha = 3 // Kademlia concurrency factor
|
||||||
bucketSize = 16 // Kademlia bucket size
|
bucketSize = 16 // Kademlia bucket size
|
||||||
nBuckets = len(NodeID{})*8 + 1 // Number of buckets
|
nBuckets = nodeIDBits + 1 // Number of buckets
|
||||||
)
|
)
|
||||||
|
|
||||||
type Table struct {
|
type Table struct {
|
||||||
@ -100,7 +100,7 @@ func (tab *Table) Lookup(target NodeID) []*Node {
|
|||||||
tab.mutex.Unlock()
|
tab.mutex.Unlock()
|
||||||
|
|
||||||
for {
|
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++ {
|
for i := 0; i < len(result.entries) && pendingQueries < alpha; i++ {
|
||||||
n := result.entries[i]
|
n := result.entries[i]
|
||||||
if !asked[n.ID] {
|
if !asked[n.ID] {
|
||||||
|
@ -28,7 +28,7 @@ var (
|
|||||||
const (
|
const (
|
||||||
respTimeout = 300 * time.Millisecond
|
respTimeout = 300 * time.Millisecond
|
||||||
sendTimeout = 300 * time.Millisecond
|
sendTimeout = 300 * time.Millisecond
|
||||||
expiration = 3 * time.Second
|
expiration = 20 * time.Second
|
||||||
|
|
||||||
refreshInterval = 1 * time.Hour
|
refreshInterval = 1 * time.Hour
|
||||||
)
|
)
|
||||||
@ -185,7 +185,7 @@ func (t *udp) findnode(to *Node, target NodeID) ([]*Node, error) {
|
|||||||
nodes = append(nodes, n)
|
nodes = append(nodes, n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nreceived == bucketSize
|
return nreceived >= bucketSize
|
||||||
})
|
})
|
||||||
|
|
||||||
t.send(to, findnodePacket, findnode{
|
t.send(to, findnodePacket, findnode{
|
||||||
|
Loading…
Reference in New Issue
Block a user