diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2019-01-31 18:48:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-31 18:48:54 +0800 |
commit | a89170cfb2acd33aea99551cb9524bcdfaad96ec (patch) | |
tree | 87a777694952d52f1cd635457fe069d32b99e8bb /p2p/discover/table_util_test.go | |
parent | 43e1b7b124d2bcfba98fbe54972a35c022d85bf2 (diff) | |
download | go-tangerine-a89170cfb2acd33aea99551cb9524bcdfaad96ec.tar go-tangerine-a89170cfb2acd33aea99551cb9524bcdfaad96ec.tar.gz go-tangerine-a89170cfb2acd33aea99551cb9524bcdfaad96ec.tar.bz2 go-tangerine-a89170cfb2acd33aea99551cb9524bcdfaad96ec.tar.lz go-tangerine-a89170cfb2acd33aea99551cb9524bcdfaad96ec.tar.xz go-tangerine-a89170cfb2acd33aea99551cb9524bcdfaad96ec.tar.zst go-tangerine-a89170cfb2acd33aea99551cb9524bcdfaad96ec.zip |
p2p/discover: improve table addition code (#18974)
This change clears up confusion around the two ways in which nodes
can be added to the table.
When a neighbors packet is received as a reply to findnode, the nodes
contained in the reply are added as 'seen' entries if sufficient space
is available.
When a ping is received and the endpoint verification has taken place,
the remote node is added as a 'verified' entry or moved to the front of
the bucket if present. This also updates the node's IP address and port
if they have changed.
Diffstat (limited to 'p2p/discover/table_util_test.go')
-rw-r--r-- | p2p/discover/table_util_test.go | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/p2p/discover/table_util_test.go b/p2p/discover/table_util_test.go index 3ce582b99..e61c9e6fc 100644 --- a/p2p/discover/table_util_test.go +++ b/p2p/discover/table_util_test.go @@ -86,17 +86,8 @@ func fillBucket(tab *Table, n *node) (last *node) { // 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) - } + tab.addSeenNode(n) } } @@ -154,15 +145,6 @@ func hasDuplicates(slice []*node) bool { return false } -func contains(ns []*node, id enode.ID) bool { - for _, n := range ns { - if n.ID() == id { - return true - } - } - return false -} - func sortedByDistanceTo(distbase enode.ID, slice []*node) bool { var last enode.ID for i, e := range slice { |