mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 03:51:29 +00:00
infrequently ping bootnode (#3540)
This commit is contained in:
parent
37596ac188
commit
fb8d6a4046
@ -21,7 +21,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var _ = shared.Service(&Service{})
|
var _ = shared.Service(&Service{})
|
||||||
|
|
||||||
var pollingPeriod = 1 * time.Second
|
var pollingPeriod = 1 * time.Second
|
||||||
|
var bootnodePingPeriod = 5 * time.Minute
|
||||||
var ttl = 1 * time.Hour
|
var ttl = 1 * time.Hour
|
||||||
|
|
||||||
// Service for managing peer to peer (p2p) networking.
|
// Service for managing peer to peer (p2p) networking.
|
||||||
@ -110,6 +112,7 @@ func (s *Service) Start() {
|
|||||||
s.dv5Listener = listener
|
s.dv5Listener = listener
|
||||||
|
|
||||||
go s.listenForNewNodes()
|
go s.listenForNewNodes()
|
||||||
|
go s.maintainBootnode()
|
||||||
}
|
}
|
||||||
|
|
||||||
s.started = true
|
s.started = true
|
||||||
@ -196,7 +199,28 @@ func (s *Service) listenForNewNodes() {
|
|||||||
case <-s.ctx.Done():
|
case <-s.ctx.Done():
|
||||||
log.Debug("p2p context is closed, exiting routine")
|
log.Debug("p2p context is closed, exiting routine")
|
||||||
break
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// maintainBootnode connection by infrequently pinging the bootnode ENR. If the bootnode server has
|
||||||
|
// restarted and this client pruned them from the local table, then a ping will reinsert this
|
||||||
|
// clients' ENR into the table of the bootnode again.
|
||||||
|
func (s *Service) maintainBootnode() {
|
||||||
|
if s.cfg.BootstrapNodeAddr == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ticker := time.NewTicker(bootnodePingPeriod)
|
||||||
|
bootNode := enode.MustParse(s.cfg.BootstrapNodeAddr)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
log.Debug("Pinging bootnode")
|
||||||
|
if err := s.dv5Listener.Ping(bootNode); err != nil {
|
||||||
|
log.WithError(err).Error("Failed to ping bootnode")
|
||||||
|
}
|
||||||
|
case <-s.ctx.Done():
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user