Skip to content

Commit

Permalink
config option for enabling p2p relay; defaults to true
Browse files Browse the repository at this point in the history
  • Loading branch information
zees-dev committed Sep 14, 2024
1 parent 9eb92f8 commit 6ff2107
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions host/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var defaultConfig = Config{
Websocket: false,
BootNodesReachabilityCheckInterval: 1 * time.Minute,
MustReachBootNodes: defaultMustReachBootNodes,
EnableP2PRelay: true,
}

// Config represents the Host configuration.
Expand All @@ -39,6 +40,7 @@ type Config struct {
BootNodesReachabilityCheckInterval time.Duration
MustReachBootNodes bool
DisableResourceLimits bool
EnableP2PRelay bool
}

// WithPrivateKey specifies the private key for the Host.
Expand Down Expand Up @@ -136,3 +138,10 @@ func WithDisabledResourceLimits(b bool) func(cfg *Config) {
cfg.DisableResourceLimits = b
}
}

// EnableP2PRelay allows user to control whether the b7s can act as a p2p relayer for worker nodes
func WithEnableP2PRelay(b bool) func(cfg *Config) {
return func(cfg *Config) {
cfg.EnableP2PRelay = b
}
}
9 changes: 6 additions & 3 deletions host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ func New(log zerolog.Logger, address string, port uint, options ...func(*Config)
return nil, fmt.Errorf("could not create libp2p host: %w", err)
}

_, err = relayv2.New(h)
if err != nil {
return nil, fmt.Errorf("could not create relay: %w", err)
if cfg.EnableP2PRelay {
log.Info().Msg("enabling p2p relay...")
_, err = relayv2.New(h)
if err != nil {
return nil, fmt.Errorf("could not create relay: %w", err)
}
}

host := Host{
Expand Down

0 comments on commit 6ff2107

Please sign in to comment.