diff --git a/cmd/waku/flags.go b/cmd/waku/flags.go index e60a498d6..071c3f840 100644 --- a/cmd/waku/flags.go +++ b/cmd/waku/flags.go @@ -177,13 +177,13 @@ var ( Destination: &options.CircuitRelay, EnvVars: []string{"WAKUNODE2_CIRCUIT_RELAY"}, }) - ForceUnreachable = altsrc.NewBoolFlag(&cli.BoolFlag{ - Name: "unreachable", - Usage: "Force the node to be unreachable. WARNING: This flag is created for testing circuit relay and is not meant to be used in production", - Value: false, + ForceReachability = altsrc.NewStringFlag(&cli.StringFlag{ + Name: "force-reachability", + Usage: "Force the node reachability. WARNING: This flag is created for testing circuit relay and is not meant to be used in production. Use 'public' or 'private'", + Value: "", Hidden: true, - Destination: &options.ForceUnreachable, - EnvVars: []string{"WAKUNODE2_UNREACHABLE"}, + Destination: &options.ForceReachability, + EnvVars: []string{"WAKUNODE2_REACHABILITY"}, }) ResourceScalingMemoryPercent = altsrc.NewFloat64Flag(&cli.Float64Flag{ Name: "resource-scaling-memory-percentage", diff --git a/cmd/waku/main.go b/cmd/waku/main.go index c260fb9bf..9c93b3f03 100644 --- a/cmd/waku/main.go +++ b/cmd/waku/main.go @@ -42,7 +42,7 @@ func main() { ExtMultiaddresses, ShowAddresses, CircuitRelay, - ForceUnreachable, + ForceReachability, ResourceScalingMemoryPercent, ResourceScalingFDPercent, LogLevel, diff --git a/cmd/waku/node.go b/cmd/waku/node.go index e0d0fbf63..0f5e68732 100644 --- a/cmd/waku/node.go +++ b/cmd/waku/node.go @@ -170,10 +170,18 @@ func Execute(options NodeOptions) { libp2pOpts = append(libp2pOpts, libp2p.EnableRelayService()) } - if options.ForceUnreachable { - logger.Warn("node forced to be unreachable!") - libp2pOpts = append(libp2pOpts, libp2p.EnableRelay(), libp2p.ForceReachabilityPrivate()) + if options.ForceReachability != "" { + libp2pOpts = append(libp2pOpts, libp2p.EnableRelay()) nodeOpts = append(nodeOpts, node.WithCircuitRelayParams(2*time.Second, 2*time.Second)) + if options.ForceReachability == "private" { + logger.Warn("node forced to be unreachable!") + libp2pOpts = append(libp2pOpts, libp2p.ForceReachabilityPrivate()) + } else if options.ForceReachability == "public" { + logger.Warn("node forced to be publicly reachable!") + libp2pOpts = append(libp2pOpts, libp2p.ForceReachabilityPublic()) + } else { + failOnErr(errors.New("invalid reachability value"), "Reachability") + } } if options.UserAgent != "" { diff --git a/cmd/waku/options.go b/cmd/waku/options.go index e1bd026f3..904bdd55a 100644 --- a/cmd/waku/options.go +++ b/cmd/waku/options.go @@ -157,7 +157,7 @@ type NodeOptions struct { AdvertiseAddresses []multiaddr.Multiaddr ShowAddresses bool CircuitRelay bool - ForceUnreachable bool + ForceReachability string ResourceScalingMemoryPercent float64 ResourceScalingFDPercent float64 LogLevel string