From 29efd42de304d507fef5de998ffc6ecbc595ec37 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <>
Date: Mon, 6 Nov 2023 22:44:19 -0500
Subject: [PATCH] python: add binding for SockAddr.resolve

---
 python/opendht.pyx     | 9 +++++++++
 python/opendht_cpp.pxd | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/python/opendht.pyx b/python/opendht.pyx
index 6b4af8ff..bf4872e6 100644
--- a/python/opendht.pyx
+++ b/python/opendht.pyx
@@ -158,6 +158,15 @@ cdef class SockAddr(object):
         return self.toString().decode()
     def __repr__(self):
         return "<%s '%s'>" % (self.__class__.__name__, str(self))
+    @staticmethod
+    def resolve(str host, str service=None):
+        vals = []
+        result = cpp.SockAddr.resolve(host.encode(), service.encode() if service else b'')
+        for val in result:
+            a = SockAddr()
+            a._addr = val
+            vals.append(a)
+        return vals
 
 cdef class Node(_WithID):
     cdef shared_ptr[cpp.Node] _node
diff --git a/python/opendht_cpp.pxd b/python/opendht_cpp.pxd
index 3cc145ee..74c0a015 100644
--- a/python/opendht_cpp.pxd
+++ b/python/opendht_cpp.pxd
@@ -86,6 +86,8 @@ cdef extern from "opendht/sockaddr.h" namespace "dht":
         bool isLoopback() const
         bool isPrivate() const
         bool isUnspecified() const
+        @staticmethod
+        vector[SockAddr] resolve(string host, string service) except +
 
 ctypedef vector[uint8_t] Blob
 
-- 
GitLab