Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: force reachability #778

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cmd/waku/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,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: "reachability",
chaitanyaprem marked this conversation as resolved.
Show resolved Hide resolved
richard-ramos marked this conversation as resolved.
Show resolved Hide resolved
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",
Expand Down
2 changes: 1 addition & 1 deletion cmd/waku/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
ExtMultiaddresses,
ShowAddresses,
CircuitRelay,
ForceUnreachable,
ForceReachability,
ResourceScalingMemoryPercent,
ResourceScalingFDPercent,
LogLevel,
Expand Down
14 changes: 11 additions & 3 deletions cmd/waku/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/waku/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type NodeOptions struct {
AdvertiseAddresses []multiaddr.Multiaddr
ShowAddresses bool
CircuitRelay bool
ForceUnreachable bool
ForceReachability string
ResourceScalingMemoryPercent float64
ResourceScalingFDPercent float64
LogLevel string
Expand Down