aboutsummaryrefslogtreecommitdiffstats
path: root/dex/handler.go
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2019-01-31 19:40:39 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:57 +0800
commit07bb51fb817b0e8db9453b185a3684c95a494342 (patch)
tree0b70dd8c1f190bdee7c778a971fb46297766fe5f /dex/handler.go
parent2e939de0678b7ef8da6a0306270e0ef126a8df01 (diff)
downloaddexon-07bb51fb817b0e8db9453b185a3684c95a494342.tar
dexon-07bb51fb817b0e8db9453b185a3684c95a494342.tar.gz
dexon-07bb51fb817b0e8db9453b185a3684c95a494342.tar.bz2
dexon-07bb51fb817b0e8db9453b185a3684c95a494342.tar.lz
dexon-07bb51fb817b0e8db9453b185a3684c95a494342.tar.xz
dexon-07bb51fb817b0e8db9453b185a3684c95a494342.tar.zst
dexon-07bb51fb817b0e8db9453b185a3684c95a494342.zip
p2p, dex: rework connection management (#183)
* p2p, dex: rework connection management * dex: refresh our node record periodically * dex: don't send new record event if no new record
Diffstat (limited to 'dex/handler.go')
-rw-r--r--dex/handler.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/dex/handler.go b/dex/handler.go
index df5516f62..490e1ec33 100644
--- a/dex/handler.go
+++ b/dex/handler.go
@@ -38,6 +38,7 @@ import (
"errors"
"fmt"
"math"
+ "math/rand"
"net"
"sync"
"sync/atomic"
@@ -304,10 +305,6 @@ func (pm *ProtocolManager) Start(srvr p2pServer, maxPeers int) {
}
-func (pm *ProtocolManager) addSelfRecord() {
- pm.nodeTable.AddRecords([]*enr.Record{pm.srvr.Self().Record()})
-}
-
func (pm *ProtocolManager) Stop() {
log.Info("Stopping Ethereum protocol")
@@ -1177,10 +1174,27 @@ func (pm *ProtocolManager) finalizedBlockBroadcastLoop() {
}
func (pm *ProtocolManager) recordBroadcastLoop() {
+ r := rand.New(rand.NewSource(time.Now().Unix()))
+ t := time.NewTimer(0)
+ defer t.Stop()
+
for {
select {
case event := <-pm.recordsCh:
pm.BroadcastRecords(event.Records)
+ pm.peers.Refresh()
+
+ case <-t.C:
+ record := pm.srvr.Self().Record()
+ log.Debug("refresh our node record", "seq", record.Seq())
+ pm.nodeTable.AddRecords([]*enr.Record{record})
+
+ // Log current peers connection status.
+ pm.peers.Status()
+
+ // Reset timer.
+ d := 1*time.Minute + time.Duration(r.Int63n(60))*time.Second
+ t.Reset(d)
// Err() channel will be closed when unsubscribing.
case <-pm.recordsSub.Err():