From 6ff21071051b97b023c0f0568fe062e7ad704a19 Mon Sep 17 00:00:00 2001 From: zees-dev Date: Sun, 15 Sep 2024 03:47:23 +1200 Subject: [PATCH] config option for enabling p2p relay; defaults to true --- host/config.go | 9 +++++++++ host/host.go | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/host/config.go b/host/config.go index c1593c9d..cf9eea6d 100644 --- a/host/config.go +++ b/host/config.go @@ -17,6 +17,7 @@ var defaultConfig = Config{ Websocket: false, BootNodesReachabilityCheckInterval: 1 * time.Minute, MustReachBootNodes: defaultMustReachBootNodes, + EnableP2PRelay: true, } // Config represents the Host configuration. @@ -39,6 +40,7 @@ type Config struct { BootNodesReachabilityCheckInterval time.Duration MustReachBootNodes bool DisableResourceLimits bool + EnableP2PRelay bool } // WithPrivateKey specifies the private key for the Host. @@ -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 + } +} diff --git a/host/host.go b/host/host.go index 7f79f627..f5755340 100644 --- a/host/host.go +++ b/host/host.go @@ -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{