mirror of https://github.com/status-im/go-waku.git
feat: ext-ip
This commit is contained in:
parent
38741caca0
commit
9b7ad40b06
|
@ -147,9 +147,16 @@ var (
|
|||
Destination: &options.NAT, // TODO: accept none,any,upnp,extaddr
|
||||
EnvVars: []string{"WAKUNODE2_NAT"},
|
||||
})
|
||||
AdvertiseAddress = cliutils.NewGenericFlagMultiValue(&cli.GenericFlag{
|
||||
IPAddress = altsrc.NewStringFlag(&cli.StringFlag{
|
||||
Name: "ext-ip", // This was added so js-waku test don't fail
|
||||
Usage: "Set external IP address",
|
||||
Value: "",
|
||||
Destination: &options.ExtIP,
|
||||
EnvVars: []string{"WAKUNODE2_EXT_IP"},
|
||||
})
|
||||
ExtMultiaddresses = cliutils.NewGenericFlagMultiValue(&cli.GenericFlag{
|
||||
Name: "ext-multiaddr",
|
||||
Usage: "External address to advertise to other nodes. Ooverrides --address and --ws-address flags. Option may be repeated",
|
||||
Usage: "External address to advertise to other nodes. Overrides --address and --ws-address flags. Option may be repeated",
|
||||
Value: &cliutils.MultiaddrSlice{
|
||||
Values: &options.AdvertiseAddresses,
|
||||
},
|
||||
|
|
|
@ -37,7 +37,8 @@ func main() {
|
|||
KeepAlive,
|
||||
PersistPeers,
|
||||
NAT,
|
||||
AdvertiseAddress,
|
||||
IPAddress,
|
||||
ExtMultiaddresses,
|
||||
ShowAddresses,
|
||||
LogLevel,
|
||||
LogEncoding,
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
|
@ -119,6 +120,14 @@ func Execute(options Options) {
|
|||
nodeOpts = append(nodeOpts, node.WithDns4Domain(options.Dns4DomainName))
|
||||
}
|
||||
|
||||
if options.ExtIP != "" {
|
||||
ip := net.ParseIP(options.ExtIP)
|
||||
if ip == nil {
|
||||
failOnErr(errors.New("invalid IP address"), "could not set external IP address")
|
||||
}
|
||||
nodeOpts = append(nodeOpts, node.WithExternalIP(ip))
|
||||
}
|
||||
|
||||
libp2pOpts := node.DefaultLibP2POptions
|
||||
if len(options.AdvertiseAddresses) == 0 {
|
||||
libp2pOpts = append(libp2pOpts, libp2p.NATPortMap()) // Attempt to open ports using uPNP for NATed hosts.)
|
||||
|
|
|
@ -159,6 +159,7 @@ type Options struct {
|
|||
LogEncoding string
|
||||
LogOutput string
|
||||
NAT string
|
||||
ExtIP string
|
||||
PersistPeers bool
|
||||
UserAgent string
|
||||
PProf bool
|
||||
|
|
|
@ -220,6 +220,31 @@ func WithAdvertiseAddresses(advertiseAddrs ...ma.Multiaddr) WakuNodeOption {
|
|||
}
|
||||
}
|
||||
|
||||
// WithExternalIP is a WakuNodeOption that allows overriding the advertised external IP used in the waku node with custom value
|
||||
func WithExternalIP(ip net.IP) WakuNodeOption {
|
||||
return func(params *WakuNodeParameters) error {
|
||||
params.addressFactory = func(inputAddr []multiaddr.Multiaddr) (addresses []multiaddr.Multiaddr) {
|
||||
component := "/ip4/"
|
||||
if ip.To4() == nil && ip.To16() != nil {
|
||||
component = "/ip6/"
|
||||
}
|
||||
|
||||
hostAddrMA, err := multiaddr.NewMultiaddr(component + ip.String())
|
||||
if err != nil {
|
||||
panic("Could not build external IP")
|
||||
}
|
||||
|
||||
for _, addr := range inputAddr {
|
||||
_, rest := multiaddr.SplitFirst(addr)
|
||||
addresses = append(addresses, hostAddrMA.Encapsulate(rest))
|
||||
}
|
||||
|
||||
return addresses
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithMultiaddress is a WakuNodeOption that configures libp2p to listen on a list of multiaddresses
|
||||
func WithMultiaddress(addresses []multiaddr.Multiaddr) WakuNodeOption {
|
||||
return func(params *WakuNodeParameters) error {
|
||||
|
|
Loading…
Reference in New Issue