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, Destination: &options.CircuitRelay,
EnvVars: []string{"WAKUNODE2_CIRCUIT_RELAY"}, EnvVars: []string{"WAKUNODE2_CIRCUIT_RELAY"},
}) })
ForceUnreachable = altsrc.NewBoolFlag(&cli.BoolFlag{ ForceReachability = altsrc.NewStringFlag(&cli.StringFlag{
Name: "unreachable", Name: "force-reachability",
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", 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: false, Value: "",
Hidden: true, Hidden: true,
Destination: &options.ForceUnreachable, Destination: &options.ForceReachability,
EnvVars: []string{"WAKUNODE2_UNREACHABLE"}, EnvVars: []string{"WAKUNODE2_REACHABILITY"},
}) })
ResourceScalingMemoryPercent = altsrc.NewFloat64Flag(&cli.Float64Flag{ ResourceScalingMemoryPercent = altsrc.NewFloat64Flag(&cli.Float64Flag{
Name: "resource-scaling-memory-percentage", Name: "resource-scaling-memory-percentage",

View File

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

View File

@ -170,10 +170,18 @@ func Execute(options NodeOptions) {
libp2pOpts = append(libp2pOpts, libp2p.EnableRelayService()) libp2pOpts = append(libp2pOpts, libp2p.EnableRelayService())
} }
if options.ForceUnreachable { if options.ForceReachability != "" {
logger.Warn("node forced to be unreachable!") libp2pOpts = append(libp2pOpts, libp2p.EnableRelay())
libp2pOpts = append(libp2pOpts, libp2p.EnableRelay(), libp2p.ForceReachabilityPrivate())
nodeOpts = append(nodeOpts, node.WithCircuitRelayParams(2*time.Second, 2*time.Second)) 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 != "" { if options.UserAgent != "" {

View File

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