Skip to content

Commit

Permalink
fix(network): enabling peer exchange for bootstrappers (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre authored Oct 24, 2023
1 parent a1c9ec1 commit c97d8da
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 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
12 changes: 10 additions & 2 deletions network/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sync"

lp2pps "github.com/libp2p/go-libp2p-pubsub"
pubsub "github.com/libp2p/go-libp2p-pubsub"
lp2phost "github.com/libp2p/go-libp2p/core/host"
"github.com/pactus-project/pactus/util/logger"
)
Expand All @@ -21,9 +22,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 := []pubsub.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
2 changes: 1 addition & 1 deletion network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ 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)
Expand Down

0 comments on commit c97d8da

Please sign in to comment.