fix: multiaddress format was incorrect when using ws (#90)

This commit is contained in:
Richard Ramos 2021-10-18 08:38:01 -04:00 committed by GitHub
parent e482075fa9
commit eadd018ce5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View File

@ -29,7 +29,7 @@ func TestBasicSendingReceiving(t *testing.T) {
wakuNode, err := node.New(ctx, wakuNode, err := node.New(ctx,
node.WithPrivateKey(prvKey), node.WithPrivateKey(prvKey),
node.WithHostAddress([]net.Addr{hostAddr}), node.WithHostAddress([]*net.TCPAddr{hostAddr}),
node.WithWakuRelay(), node.WithWakuRelay(),
) )
require.NoError(t, err) require.NoError(t, err)

View File

@ -88,14 +88,14 @@ func Execute(options Options) {
nodeOpts := []node.WakuNodeOption{ nodeOpts := []node.WakuNodeOption{
node.WithPrivateKey(prvKey), node.WithPrivateKey(prvKey),
node.WithHostAddress([]net.Addr{hostAddr}), node.WithHostAddress([]*net.TCPAddr{hostAddr}),
node.WithKeepAlive(time.Duration(options.KeepAlive) * time.Second), node.WithKeepAlive(time.Duration(options.KeepAlive) * time.Second),
} }
if options.AdvertiseAddress != "" { if options.AdvertiseAddress != "" {
advertiseAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", options.AdvertiseAddress, options.Port)) advertiseAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", options.AdvertiseAddress, options.Port))
failOnErr(err, "invalid advertise address") failOnErr(err, "invalid advertise address")
nodeOpts = append(nodeOpts, node.WithAdvertiseAddress([]net.Addr{advertiseAddr}, options.EnableWS, options.WSPort)) nodeOpts = append(nodeOpts, node.WithAdvertiseAddress([]*net.TCPAddr{advertiseAddr}, options.EnableWS, options.WSPort))
} }
if options.EnableWS { if options.EnableWS {

View File

@ -60,7 +60,7 @@ func (w WakuNodeParameters) Identity() config.Option {
} }
// WithHostAddress is a WakuNodeOption that configures libp2p to listen on a list of net endpoint addresses // WithHostAddress is a WakuNodeOption that configures libp2p to listen on a list of net endpoint addresses
func WithHostAddress(hostAddr []net.Addr) WakuNodeOption { func WithHostAddress(hostAddr []*net.TCPAddr) WakuNodeOption {
return func(params *WakuNodeParameters) error { return func(params *WakuNodeParameters) error {
var multiAddresses []ma.Multiaddr var multiAddresses []ma.Multiaddr
for _, addr := range hostAddr { for _, addr := range hostAddr {
@ -78,7 +78,7 @@ func WithHostAddress(hostAddr []net.Addr) WakuNodeOption {
} }
// WithAdvertiseAddress is a WakuNodeOption that allows overriding the addresses used in the waku node with custom values // WithAdvertiseAddress is a WakuNodeOption that allows overriding the addresses used in the waku node with custom values
func WithAdvertiseAddress(addressesToAdvertise []net.Addr, enableWS bool, wsPort int) WakuNodeOption { func WithAdvertiseAddress(addressesToAdvertise []*net.TCPAddr, enableWS bool, wsPort int) WakuNodeOption {
return func(params *WakuNodeParameters) error { return func(params *WakuNodeParameters) error {
params.addressFactory = func([]ma.Multiaddr) []ma.Multiaddr { params.addressFactory = func([]ma.Multiaddr) []ma.Multiaddr {
var result []multiaddr.Multiaddr var result []multiaddr.Multiaddr
@ -86,7 +86,7 @@ func WithAdvertiseAddress(addressesToAdvertise []net.Addr, enableWS bool, wsPort
addr, _ := manet.FromNetAddr(adv) addr, _ := manet.FromNetAddr(adv)
result = append(result, addr) result = append(result, addr)
if enableWS { if enableWS {
wsMa, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d/ws", adv, wsPort)) wsMa, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d/ws", adv.IP.String(), wsPort))
result = append(result, wsMa) result = append(result, wsMa)
} }
} }