From 6baf089bb45e9b7b78b365b92e590f46664690f2 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 25 Sep 2019 11:47:46 -0600 Subject: [PATCH] move tomultiaddr to wire.nim --- libp2p/transports/tcptransport.nim | 16 ---------------- libp2p/wire.nim | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index abbaa7eb0..83ff4cfda 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 1b7dc7256..7c4a325de 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!")