diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2019-01-30 00:39:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-30 00:39:20 +0800 |
commit | f0c6f921408d97251b1b554a7ea83d020c70a2da (patch) | |
tree | 06d91c1eb9e183859c72da2593dfd3eb098bf594 /p2p/discover/table_util_test.go | |
parent | 74c38902ecec507675e1e9033500addc87e4b7b0 (diff) | |
download | go-tangerine-f0c6f921408d97251b1b554a7ea83d020c70a2da.tar go-tangerine-f0c6f921408d97251b1b554a7ea83d020c70a2da.tar.gz go-tangerine-f0c6f921408d97251b1b554a7ea83d020c70a2da.tar.bz2 go-tangerine-f0c6f921408d97251b1b554a7ea83d020c70a2da.tar.lz go-tangerine-f0c6f921408d97251b1b554a7ea83d020c70a2da.tar.xz go-tangerine-f0c6f921408d97251b1b554a7ea83d020c70a2da.tar.zst go-tangerine-f0c6f921408d97251b1b554a7ea83d020c70a2da.zip |
p2p/discover, p2p/enode: rework endpoint proof handling, packet logging (#18963)
This change resolves multiple issues around handling of endpoint proofs.
The proof is now done separately for each IP and completing the proof
requires a matching ping hash.
Also remove waitping because it's equivalent to sleep. waitping was
slightly more efficient, but that may cause issues with findnode if
packets are reordered and the remote end sees findnode before pong.
Logging of received packets was hitherto done after handling the packet,
which meant that sent replies were logged before the packet that
generated them. This change splits up packet handling into 'preverify'
and 'handle'. The error from 'preverify' is logged, but 'handle' happens
after the message is logged. This fixes the order. Packet logs now
contain the node ID.
Diffstat (limited to 'p2p/discover/table_util_test.go')
-rw-r--r-- | p2p/discover/table_util_test.go | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/p2p/discover/table_util_test.go b/p2p/discover/table_util_test.go index d41519452..3ce582b99 100644 --- a/p2p/discover/table_util_test.go +++ b/p2p/discover/table_util_test.go @@ -83,6 +83,23 @@ func fillBucket(tab *Table, n *node) (last *node) { return b.entries[bucketSize-1] } +// fillTable adds nodes the table to the end of their corresponding bucket +// if the bucket is not full. The caller must not hold tab.mutex. +func fillTable(tab *Table, nodes []*node) { + tab.mutex.Lock() + defer tab.mutex.Unlock() + + for _, n := range nodes { + if n.ID() == tab.self().ID() { + continue // don't add self + } + b := tab.bucket(n.ID()) + if len(b.entries) < bucketSize { + tab.bumpOrAdd(b, n) + } + } +} + type pingRecorder struct { mu sync.Mutex dead, pinged map[enode.ID]bool @@ -109,10 +126,6 @@ func (t *pingRecorder) findnode(toid enode.ID, toaddr *net.UDPAddr, target encPu return nil, nil } -func (t *pingRecorder) waitping(from enode.ID) error { - return nil // remote always pings -} - func (t *pingRecorder) ping(toid enode.ID, toaddr *net.UDPAddr) error { t.mu.Lock() defer t.mu.Unlock() |