Skip to content

Commit

Permalink
update: add connection peer to routing table
Browse files Browse the repository at this point in the history
  • Loading branch information
yxq authored and 33cn committed Aug 3, 2021
1 parent 8542f6d commit a3d45a7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions system/p2p/dht/manage/conns.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func (s *ConnManager) MonitorAllPeers() {
defer ticker1.Stop()
ticker2 := time.NewTicker(time.Minute * 2)
defer ticker2.Stop()
ticker3 := time.NewTicker(time.Second * 5)
defer ticker3.Stop()

for {
select {
Expand All @@ -113,6 +115,8 @@ func (s *ConnManager) MonitorAllPeers() {
s.printMonitorInfo()
case <-ticker2.C:
s.procConnections()
case <- ticker3.C:
s.procRoutingTable()
}
}
}
Expand Down Expand Up @@ -149,12 +153,6 @@ func (s *ConnManager) printMonitorInfo() {
}

func (s *ConnManager) procConnections() {
for _, conn := range s.host.Network().Conns() {
remotePeer := conn.RemotePeer()
if s.routingTable.Find(remotePeer) == "" {
_, _ = s.routingTable.TryAddPeer(remotePeer, true, true)
}
}
//处理当前连接的节点问题
_, outBoundSize := s.BoundSize()
if outBoundSize > maxOutBounds || s.Size() > maxBounds {
Expand Down Expand Up @@ -189,7 +187,15 @@ func (s *ConnManager) procConnections() {
}
}
}
}

func (s *ConnManager) procRoutingTable() {
if s.routingTable.Size() > len(s.host.Network().Peers())*4/5 {
return
}
for _, pid := range s.host.Network().Peers() {
_, _ = s.routingTable.TryAddPeer(pid, true, true)
}
}

func genAddrInfo(addr string) (*peer.AddrInfo, error) {
Expand Down

0 comments on commit a3d45a7

Please sign in to comment.