From b055467e9ce866f069fa8e5365315114292049cc Mon Sep 17 00:00:00 2001 From: cheatfate Date: Sat, 27 Oct 2018 17:19:58 +0300 Subject: [PATCH] Fix for nim-eth-p2p. --- asyncdispatch2/transports/common.nim | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/asyncdispatch2/transports/common.nim b/asyncdispatch2/transports/common.nim index d16a74c..7190354 100644 --- a/asyncdispatch2/transports/common.nim +++ b/asyncdispatch2/transports/common.nim @@ -6,10 +6,9 @@ # Licensed under either of # Apache License, version 2.0, (LICENSE-APACHEv2) # MIT license (LICENSE-MIT) -from net import IpAddressFamily, IpAddress, `$`, parseIpAddress -import os, strutils, nativesockets +import os, strutils, nativesockets, net import ../asyncloop -export IpAddressFamily +export net when defined(windows): import winlean @@ -351,6 +350,20 @@ proc toSAddr*(address: TransportAddress, sa: var Sockaddr_storage, else: discard +proc address*(ta: TransportAddress): IpAddress = + ## Converts ``TransportAddress`` to ``net.IpAddress`` object. + ## + ## Note its impossible to convert ``TransportAddress`` of ``Unix`` family, + ## because ``IpAddress`` supports only IPv4, IPv6 addresses. + if ta.family == AddressFamily.IPv4: + result = IpAddress(family: IpAddressFamily.IPv4) + result.address_v4 = ta.address_v4 + elif ta.family == AddressFamily.IPv6: + result = IpAddress(family: IpAddressFamily.IPv6) + result.address_v6 = ta.address_v6 + else: + raise newException(ValueError, "IpAddress supports only IPv4/IPv6!") + proc resolveTAddress*(address: string, family = AddressFamily.IPv4): seq[TransportAddress] = ## Resolve string representation of ``address``.