diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index abbaa7e..83ff4cf 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -21,22 +21,6 @@ logScope: type TcpTransport* = ref object of Transport server*: StreamServer -proc toMultiAddr*(address: TransportAddress): MultiAddress = - ## Returns string representation of ``address``. - case address.family - of AddressFamily.IPv4: - var a = IpAddress( - family: IpAddressFamily.IPv4, - address_v4: address.address_v4 - ) - result = MultiAddress.init(a, Protocol.IPPROTO_TCP, address.port) - of AddressFamily.IPv6: - var a = IpAddress(family: IpAddressFamily.IPv6, - address_v6: address.address_v6) - result = MultiAddress.init(a, Protocol.IPPROTO_TCP, address.port) - else: - raise newException(TransportAddressError, "Invalid address for transport!") - proc connHandler*(t: Transport, server: StreamServer, client: StreamTransport, diff --git a/libp2p/wire.nim b/libp2p/wire.nim index 1b7dc72..7c4a325 100644 --- a/libp2p/wire.nim +++ b/libp2p/wire.nim @@ -140,3 +140,19 @@ proc getLocalAddress*(sock: AsyncFD): TransportAddress = if getsockname(SocketHandle(sock), cast[ptr SockAddr](addr saddr), addr slen) == 0: fromSAddr(addr saddr, slen, result) + +proc toMultiAddr*(address: TransportAddress): MultiAddress = + ## Returns string representation of ``address``. + case address.family + of AddressFamily.IPv4: + var a = IpAddress( + family: IpAddressFamily.IPv4, + address_v4: address.address_v4 + ) + result = MultiAddress.init(a, Protocol.IPPROTO_TCP, address.port) + of AddressFamily.IPv6: + var a = IpAddress(family: IpAddressFamily.IPv6, + address_v6: address.address_v6) + result = MultiAddress.init(a, Protocol.IPPROTO_TCP, address.port) + else: + raise newException(TransportAddressError, "Invalid address for transport!")