move tomultiaddr to wire.nim

This commit is contained in:
Dmitriy Ryajov 2019-09-25 11:47:46 -06:00
parent f3afe0a6ce
commit 6baf089bb4
2 changed files with 16 additions and 16 deletions

View File

@ -21,22 +21,6 @@ logScope:
type TcpTransport* = ref object of Transport type TcpTransport* = ref object of Transport
server*: StreamServer 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, proc connHandler*(t: Transport,
server: StreamServer, server: StreamServer,
client: StreamTransport, client: StreamTransport,

View File

@ -140,3 +140,19 @@ proc getLocalAddress*(sock: AsyncFD): TransportAddress =
if getsockname(SocketHandle(sock), cast[ptr SockAddr](addr saddr), if getsockname(SocketHandle(sock), cast[ptr SockAddr](addr saddr),
addr slen) == 0: addr slen) == 0:
fromSAddr(addr saddr, slen, result) 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!")