mirror of https://github.com/vacp2p/nim-libp2p.git
move tomultiaddr to wire.nim
This commit is contained in:
parent
f3afe0a6ce
commit
6baf089bb4
|
@ -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,
|
||||||
|
|
|
@ -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!")
|
||||||
|
|
Loading…
Reference in New Issue