mirror of https://github.com/status-im/go-waku.git
parent
1c75c89790
commit
1bffa35dfa
|
@ -230,12 +230,12 @@ func WithExternalIP(ip net.IP) WakuNodeOption {
|
|||
params.addressFactory = func(inputAddr []multiaddr.Multiaddr) (addresses []multiaddr.Multiaddr) {
|
||||
addresses = append(addresses, inputAddr...)
|
||||
|
||||
component := "/ip4/"
|
||||
if ip.To4() == nil && ip.To16() != nil {
|
||||
component = "/ip6/"
|
||||
ipType := "/ip4/"
|
||||
if utils.IsIPv6(ip.String()) {
|
||||
ipType = "/ip6/"
|
||||
}
|
||||
|
||||
hostAddrMA, err := multiaddr.NewMultiaddr(component + ip.String())
|
||||
hostAddrMA, err := multiaddr.NewMultiaddr(ipType + ip.String())
|
||||
if err != nil {
|
||||
panic("Could not build external IP")
|
||||
}
|
||||
|
|
|
@ -57,7 +57,18 @@ func enodeToMultiAddr(node *enode.Node) (multiaddr.Multiaddr, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", node.IP(), node.TCP(), peerID))
|
||||
ipType := "ip4"
|
||||
portNumber := node.TCP()
|
||||
if utils.IsIPv6(node.IP().String()) {
|
||||
ipType = "ip6"
|
||||
var port enr.TCP6
|
||||
if err := node.Record().Load(&port); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
portNumber = int(port)
|
||||
}
|
||||
|
||||
return multiaddr.NewMultiaddr(fmt.Sprintf("/%s/%s/tcp/%d/p2p/%s", ipType, node.IP(), portNumber, peerID))
|
||||
}
|
||||
|
||||
// Multiaddress is used to extract all the multiaddresses that are part of a ENR record
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func IsIPv4(str string) bool {
|
||||
ip := net.ParseIP(str)
|
||||
return ip != nil && !strings.Contains(str, ":")
|
||||
}
|
||||
|
||||
func IsIPv6(str string) bool {
|
||||
ip := net.ParseIP(str)
|
||||
return ip != nil && strings.Contains(str, ":")
|
||||
}
|
Loading…
Reference in New Issue