Skip to content

Commit

Permalink
fix(network): enabling peer exchange for bootstrappers (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre committed Oct 24, 2023
1 parent d1db90f commit 7cc66cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 0 additions & 2 deletions network/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ func newDHTService(ctx context.Context, host lp2phost.Host, protocolID lp2pcore.
opts := []lp2pdht.Option{
lp2pdht.Mode(mode),
lp2pdht.ProtocolPrefix(protocolID),
lp2pdht.DisableProviders(),
lp2pdht.DisableValues(),
lp2pdht.BootstrapPeers(bootsrapAddrs...),
}

Expand Down
11 changes: 9 additions & 2 deletions network/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ type gossipService struct {
}

func newGossipService(ctx context.Context, host lp2phost.Host, eventCh chan Event,
logger *logger.SubLogger,
config *Config, logger *logger.SubLogger,
) *gossipService {
pubsub, err := lp2pps.NewGossipSub(ctx, host)
opts := []lp2pps.Option{}

if config.Bootstrapper {
// enable Peer eXchange on bootstrappers
opts = append(opts, lp2pps.WithPeerExchange(true))
}

pubsub, err := lp2pps.NewGossipSub(ctx, host, opts...)
if err != nil {
logger.Panic("unable to start Gossip service", "error", err)
return nil
Expand Down
6 changes: 4 additions & 2 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,14 @@ func newNetwork(networkName string, conf *Config, opts []lp2p.Option) (*network,

n.dht = newDHTService(n.ctx, n.host, kadProtocolID, conf, n.logger)
n.stream = newStreamService(ctx, n.host, streamProtocolID, relayAddrs, n.eventChannel, n.logger)
n.gossip = newGossipService(ctx, n.host, n.eventChannel, n.logger)
n.gossip = newGossipService(ctx, n.host, n.eventChannel, conf, n.logger)
n.notifee = newNotifeeService(n.host, n.eventChannel, n.logger, streamProtocolID)

n.host.Network().Notify(n.notifee)

n.logger.Info("network setup", "id", n.host.ID(), "address", conf.Listens)
n.logger.Info("network setup", "id", n.host.ID(),
"address", conf.Listens,
"bootstrapper", conf.Bootstrapper)

return n, nil
}
Expand Down

0 comments on commit 7cc66cf

Please sign in to comment.