|
|
@ -48,9 +48,6 @@ const ( |
|
|
|
|
|
|
|
|
|
|
|
// register to bootnode every ticker
|
|
|
|
// register to bootnode every ticker
|
|
|
|
dhtTicker = 6 * time.Hour |
|
|
|
dhtTicker = 6 * time.Hour |
|
|
|
|
|
|
|
|
|
|
|
// wait for peerinfo.
|
|
|
|
|
|
|
|
peerInfoWait = time.Second |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// New returns role conversion service.
|
|
|
|
// New returns role conversion service.
|
|
|
@ -164,10 +161,7 @@ func (s *Service) DoService() { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
tick := time.NewTicker(dhtTicker) |
|
|
|
tick := time.NewTicker(dhtTicker) |
|
|
|
peerInfoTick := time.NewTicker(peerInfoWait) |
|
|
|
|
|
|
|
for { |
|
|
|
for { |
|
|
|
select { |
|
|
|
|
|
|
|
case <-peerInfoTick.C: |
|
|
|
|
|
|
|
select { |
|
|
|
select { |
|
|
|
case peer := <-s.peerInfo: |
|
|
|
case peer := <-s.peerInfo: |
|
|
|
if peer.ID != s.Host.GetP2PHost().ID() && len(peer.ID) > 0 { |
|
|
|
if peer.ID != s.Host.GetP2PHost().ID() && len(peer.ID) > 0 { |
|
|
@ -194,17 +188,12 @@ func (s *Service) DoService() { |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if ip != "" { |
|
|
|
|
|
|
|
p := p2p.Peer{IP: ip, Port: port, PeerID: peer.ID, Addrs: peer.Addrs} |
|
|
|
p := p2p.Peer{IP: ip, Port: port, PeerID: peer.ID, Addrs: peer.Addrs} |
|
|
|
utils.GetLogInstance().Info("Notify peerChan", "peer", p) |
|
|
|
utils.GetLogInstance().Info("Notify peerChan", "peer", p) |
|
|
|
if s.peerChan != nil { |
|
|
|
if s.peerChan != nil { |
|
|
|
s.peerChan <- p |
|
|
|
s.peerChan <- p |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
utils.GetLogInstance().Info("Got no peer from peerInfo") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case <-s.stopChan: |
|
|
|
case <-s.stopChan: |
|
|
|
return |
|
|
|
return |
|
|
|
case <-tick.C: |
|
|
|
case <-tick.C: |
|
|
|