diff options
author | Felföldi Zsolt <zsfelfoldi@gmail.com> | 2018-02-09 01:06:31 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-02-09 01:06:31 +0800 |
commit | c4712bf96bc1bae4a5ad4600e9719e4a74bde7d5 (patch) | |
tree | 9b1faeb171246e07d9b43c97671e1b5f94510740 /p2p/discv5/net.go | |
parent | 2b4c7e9b37958984525ba63f2ec637662b384090 (diff) | |
download | dexon-c4712bf96bc1bae4a5ad4600e9719e4a74bde7d5.tar dexon-c4712bf96bc1bae4a5ad4600e9719e4a74bde7d5.tar.gz dexon-c4712bf96bc1bae4a5ad4600e9719e4a74bde7d5.tar.bz2 dexon-c4712bf96bc1bae4a5ad4600e9719e4a74bde7d5.tar.lz dexon-c4712bf96bc1bae4a5ad4600e9719e4a74bde7d5.tar.xz dexon-c4712bf96bc1bae4a5ad4600e9719e4a74bde7d5.tar.zst dexon-c4712bf96bc1bae4a5ad4600e9719e4a74bde7d5.zip |
p2p/discv5: fix multiple discovery issues (#16036)
* p2p/discv5: add query delay, fix node address update logic, retry refresh if empty
* p2p/discv5: remove unnecessary ping before topic query
* p2p/discv5: do not filter local address from topicNodes
* p2p/discv5: remove canQuery()
* p2p/discv5: gofmt
Diffstat (limited to 'p2p/discv5/net.go')
-rw-r--r-- | p2p/discv5/net.go | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/p2p/discv5/net.go b/p2p/discv5/net.go index f9baf126f..52c677b62 100644 --- a/p2p/discv5/net.go +++ b/p2p/discv5/net.go @@ -565,11 +565,8 @@ loop: if lookupChn := searchInfo[res.target.topic].lookupChn; lookupChn != nil { lookupChn <- net.ticketStore.radius[res.target.topic].converged } - net.ticketStore.searchLookupDone(res.target, res.nodes, func(n *Node) []byte { - net.ping(n, n.addr()) - return n.pingEcho - }, func(n *Node, topic Topic) []byte { - if n.state == known { + net.ticketStore.searchLookupDone(res.target, res.nodes, func(n *Node, topic Topic) []byte { + if n.state != nil && n.state.canQuery { return net.conn.send(n, topicQueryPacket, topicQuery{Topic: topic}) // TODO: set expiration } else { if n.state == unknown { @@ -633,15 +630,20 @@ loop: } net.refreshResp <- refreshDone case <-refreshDone: - log.Trace("<-net.refreshDone") - refreshDone = nil - list := searchReqWhenRefreshDone - searchReqWhenRefreshDone = nil - go func() { - for _, req := range list { - net.topicSearchReq <- req - } - }() + log.Trace("<-net.refreshDone", "table size", net.tab.count) + if net.tab.count != 0 { + refreshDone = nil + list := searchReqWhenRefreshDone + searchReqWhenRefreshDone = nil + go func() { + for _, req := range list { + net.topicSearchReq <- req + } + }() + } else { + refreshDone = make(chan struct{}) + net.refresh(refreshDone) + } } } log.Trace("loop stopped") @@ -751,7 +753,15 @@ func (net *Network) internNodeFromNeighbours(sender *net.UDPAddr, rn rpcNode) (n return n, err } if !n.IP.Equal(rn.IP) || n.UDP != rn.UDP || n.TCP != rn.TCP { - err = fmt.Errorf("metadata mismatch: got %v, want %v", rn, n) + if n.state == known { + // reject address change if node is known by us + err = fmt.Errorf("metadata mismatch: got %v, want %v", rn, n) + } else { + // accept otherwise; this will be handled nicer with signed ENRs + n.IP = rn.IP + n.UDP = rn.UDP + n.TCP = rn.TCP + } } return n, err } |