Merge pull request #1142 from rlan35/rj_fork2

Revert "fix cpu issues at networkinfo service"
pull/1144/head
Rongjian Lan 6 years ago committed by GitHub
commit 348977d746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      api/service/networkinfo/service.go

@ -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:

Loading…
Cancel
Save