aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/dial.go
diff options
context:
space:
mode:
authorDmitry Shulyak <yashulyak@gmail.com>2018-02-21 22:03:26 +0800
committerFelix Lange <fjl@users.noreply.github.com>2018-02-21 22:03:26 +0800
commit14c76371bab105a99c796a652df86df3e3e7d958 (patch)
tree02573d4df4ec95f2113dc72a40bb89685607a516 /p2p/dial.go
parent7d578246632c15b15c615d66ccfbd99edd2642c6 (diff)
downloadgo-tangerine-14c76371bab105a99c796a652df86df3e3e7d958.tar
go-tangerine-14c76371bab105a99c796a652df86df3e3e7d958.tar.gz
go-tangerine-14c76371bab105a99c796a652df86df3e3e7d958.tar.bz2
go-tangerine-14c76371bab105a99c796a652df86df3e3e7d958.tar.lz
go-tangerine-14c76371bab105a99c796a652df86df3e3e7d958.tar.xz
go-tangerine-14c76371bab105a99c796a652df86df3e3e7d958.tar.zst
go-tangerine-14c76371bab105a99c796a652df86df3e3e7d958.zip
p2p: when peer is removed remove it also from dial history (#16060)
This change removes a peer information from dialing history when peer is removed from static list. It allows to force a server to re-dial concrete peer if it is needed. In our case we are running geth node on mobile devices, and it is common for a network connection to flap on mobile. Almost every time it flaps or network connection is changed from cellular to wifi peers are disconnected with read timeout. And usually it takes 30 seconds (default expiration timeout) to recover connection with static peers after connectivity is restored. This change allows us to reconnect with peers almost immediately and it seems harmless enough.
Diffstat (limited to 'p2p/dial.go')
-rw-r--r--p2p/dial.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/p2p/dial.go b/p2p/dial.go
index f5ff2c211..d8feceb9f 100644
--- a/p2p/dial.go
+++ b/p2p/dial.go
@@ -154,6 +154,9 @@ func (s *dialstate) addStatic(n *discover.Node) {
func (s *dialstate) removeStatic(n *discover.Node) {
// This removes a task so future attempts to connect will not be made.
delete(s.static, n.ID)
+ // This removes a previous dial timestamp so that application
+ // can force a server to reconnect with chosen peer immediately.
+ s.hist.remove(n.ID)
}
func (s *dialstate) newTasks(nRunning int, peers map[discover.NodeID]*Peer, now time.Time) []task {
@@ -390,6 +393,16 @@ func (h dialHistory) min() pastDial {
}
func (h *dialHistory) add(id discover.NodeID, exp time.Time) {
heap.Push(h, pastDial{id, exp})
+
+}
+func (h *dialHistory) remove(id discover.NodeID) bool {
+ for i, v := range *h {
+ if v.id == id {
+ heap.Remove(h, i)
+ return true
+ }
+ }
+ return false
}
func (h dialHistory) contains(id discover.NodeID) bool {
for _, v := range h {