Change Ordering of Gossipsub Registration (#3330)

* fix ordering

* Add comment
This commit is contained in:
Nishant Das 2019-08-27 20:53:22 +05:30 committed by Raul Jordan
parent 701c70ae3b
commit ca0f61bf24

View File

@ -71,6 +71,21 @@ func (s *Service) Start() {
return
}
s.host = h
// TODO(3147): Add gossip sub options
// Gossipsub registration is done before we add in any new peers
// due to libp2p's gossipsub implementation not taking into
// account previously added peers when creating the gossipsub
// object.
gs, err := pubsub.NewGossipSub(s.ctx, s.host)
if err != nil {
s.startupErr = err
log.WithError(err).Error("Failed to start pubsub")
return
}
s.pubsub = gs
if s.cfg.BootstrapNodeAddr != "" && !s.cfg.NoDiscovery {
listener, err := startDiscoveryV5(ipAddr, privKey, s.cfg)
if err != nil {
@ -83,6 +98,8 @@ func (s *Service) Start() {
go s.listenForNewNodes()
}
s.started = true
if len(s.cfg.StaticPeers) > 0 {
addrs, err := manyMultiAddrsFromString(s.cfg.StaticPeers)
if err != nil {
@ -91,20 +108,7 @@ func (s *Service) Start() {
s.connectWithAllPeers(addrs)
}
// TODO(3147): Add gossip sub options
gs, err := pubsub.NewGossipSub(s.ctx, s.host)
if err != nil {
s.startupErr = err
log.WithError(err).Error("Failed to start pubsub")
return
}
s.pubsub = gs
s.started = true
registerMetrics(s)
multiAddrs := s.host.Network().ListenAddresses()
logIP4Addr(s.host.ID(), multiAddrs...)
}