port is returned as string instead of integer
Closed this issue · 4 comments
Hello - due to recent attepts to integrate 3box, IPFS and IPLD into native-react we fell over an issue with multiaddr, which causes the native socket component to fault.
The issue in question is:
Line 346 in 2bb0f1d
The return value of port here is string, as the input type is a string.
- Can we add a parseInt() for the port here?
- Are there cases where the port does not contain the port number?
Refer:
libp2p/js-libp2p-tcp#108
Thanks!
Chris
Are there cases where the port does not contain the port number?
As the logic is pretty crude, if a multiaddr is provided that doesn't have the port at the correct position or at all, it's possible for a non numerical string to be returned, so parseInt would return NaN
.
Well, is NaN
applicable, or should we fall back on if NaN
then return port string?
The nodejs API will do one of two things. It returns the address object, or a string indicating a unix path, https://nodejs.org/api/net.html#net_server_address.
Ideally our implementation would match this, but I think we can ignore the unix path component for now, as we have another method to directly get a unix path.
IMO, if we get NaN when doing parseInt
we should throw an error, because anything else is likely going to result in the consuming code failing anyway. Any non numerical port is invalid and likely means we're trying to get a node address from a multiaddr that doesn't have one.