feat: force reachability (#778)

This commit is contained in:
richΛrd 2023-09-28 16:08:40 -04:00 committed by GitHub
parent 7f466c1d99
commit 88d69ebccd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 11 deletions

View File

@ -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",

View File

@ -42,7 +42,7 @@ func main() {
ExtMultiaddresses,
ShowAddresses,
CircuitRelay,
ForceUnreachable,
ForceReachability,
ResourceScalingMemoryPercent,
ResourceScalingFDPercent,
LogLevel,

View File

@ -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 != "" {

View File

@ -157,7 +157,7 @@ type NodeOptions struct {
AdvertiseAddresses []multiaddr.Multiaddr
ShowAddresses bool
CircuitRelay bool
ForceUnreachable bool
ForceReachability string
ResourceScalingMemoryPercent float64
ResourceScalingFDPercent float64
LogLevel string