feat: force unreachability (#753)

Co-authored-by: Prem Chaitanya Prathi <chaitanyaprem@gmail.com>
This commit is contained in:
richΛrd 2023-09-20 02:54:16 -04:00 committed by GitHub
parent 054bdae1de
commit 003c90fba8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 5 deletions

View File

@ -171,6 +171,14 @@ 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,
Hidden: true,
Destination: &options.ForceUnreachable,
EnvVars: []string{"WAKUNODE2_UNREACHABLE"},
})
ResourceScalingMemoryPercent = altsrc.NewFloat64Flag(&cli.Float64Flag{
Name: "resource-scaling-memory-percentage",
Usage: "Determines the percentage of total accessible memory that wil be dedicated to go-waku. A dedicated node with a lot of RAM could allocate 25% or more memory to go-waku",

View File

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

View File

@ -169,6 +169,12 @@ 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())
nodeOpts = append(nodeOpts, node.WithCircuitRelayParams(2*time.Second, 2*time.Second))
}
if options.UserAgent != "" {
libp2pOpts = append(libp2pOpts, libp2p.UserAgent(options.UserAgent))
}

View File

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

View File

@ -237,7 +237,8 @@ func New(opts ...WakuNodeOption) (*WakuNode, error) {
}()
return r
},
autorelay.WithMinInterval(2*time.Second),
autorelay.WithMinInterval(params.circuitRelayMinInterval),
autorelay.WithBootDelay(params.circuitRelayBootDelay),
))
if params.enableNTP {
@ -754,12 +755,12 @@ func (w *WakuNode) connect(ctx context.Context, info peer.AddrInfo) error {
// host.Connect adds the addresses with a TempAddressTTL
// however, identify will filter out all non IP addresses
// and expire all temporary addrs. So in the meantime, let's
// store dns4 addresses with a connectedAddressTTL, otherwise
// store dns4 addresses with a RecentlyConnectedAddrTTL, otherwise
// it will have trouble with the status fleet circuit relay addresses
// See https://github.com/libp2p/go-libp2p/issues/2550
_, err := addr.ValueForProtocol(ma.P_DNS4)
if err == nil {
w.host.Peerstore().AddAddrs(info.ID, info.Addrs, peerstore.ConnectedAddrTTL)
w.host.Peerstore().AddAddrs(info.ID, info.Addrs, peerstore.RecentlyConnectedAddrTTL)
}
}

View File

@ -55,6 +55,9 @@ type WakuNodeParameters struct {
peerstore peerstore.Peerstore
prometheusReg prometheus.Registerer
circuitRelayMinInterval time.Duration
circuitRelayBootDelay time.Duration
enableNTP bool
ntpURLs []string
@ -119,6 +122,7 @@ type WakuNodeOption func(*WakuNodeParameters) error
var DefaultWakuNodeOptions = []WakuNodeOption{
WithPrometheusRegisterer(prometheus.NewRegistry()),
WithMaxPeerConnections(50),
WithCircuitRelayParams(2*time.Second, 3*time.Minute),
}
// MultiAddresses return the list of multiaddresses configured in the node
@ -517,6 +521,14 @@ func WithSecureWebsockets(address string, port int, certPath string, keyPath str
}
}
func WithCircuitRelayParams(minInterval time.Duration, bootDelay time.Duration) WakuNodeOption {
return func(params *WakuNodeParameters) error {
params.circuitRelayBootDelay = bootDelay
params.circuitRelayMinInterval = minInterval
return nil
}
}
// Default options used in the libp2p node
var DefaultLibP2POptions = []libp2p.Option{
libp2p.ChainOptions(

View File

@ -103,7 +103,7 @@ func (pm *PeerManager) peerEventLoop(ctx context.Context) {
err := wps.AddPubSubTopic(peerID, peerEvt.Topic)
if err != nil {
pm.logger.Error("failed to add pubSubTopic for peer",
logging.HostID("peerID", peerID), zap.Error(err))
logging.HostID("peerID", peerID), zap.String("topic", peerEvt.Topic), zap.Error(err))
}
} else if peerEvt.State == relay.PEER_LEFT {
err := wps.RemovePubSubTopic(peerID, peerEvt.Topic)

View File

@ -1,6 +1,7 @@
package peerstore
import (
"errors"
"sync"
"github.com/ethereum/go-ethereum/p2p/enode"
@ -183,7 +184,11 @@ func (ps *WakuPeerstoreImpl) SetPubSubTopics(p peer.ID, topics []string) error {
func (ps *WakuPeerstoreImpl) PubSubTopics(p peer.ID) ([]string, error) {
result, err := ps.peerStore.Get(p, peerPubSubTopics)
if err != nil {
return nil, err
if errors.Is(err, peerstore.ErrNotFound) {
return nil, nil
} else {
return nil, err
}
}
return result.([]string), nil
}