From bad8bdfe135dfb0334c460c2d6965ba8cd701b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <> Date: Mon, 6 Nov 2023 21:55:08 -0500 Subject: [PATCH] python: support 'permanent' argument for put --- python/opendht.pyx | 4 ++-- python/opendht_cpp.pxd | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/python/opendht.pyx b/python/opendht.pyx index 1dcfc773..6b4af8ff 100644 --- a/python/opendht.pyx +++ b/python/opendht.pyx @@ -587,7 +587,7 @@ cdef class DhtRunner(_WithID): while pending > 0: lock.wait() return res - def put(self, InfoHash key, Value val, done_cb=None): + def put(self, InfoHash key, Value val, done_cb=None, permanent=False): """Publish a new value on the DHT at key. key -- the DHT key where to put the value @@ -597,7 +597,7 @@ cdef class DhtRunner(_WithID): if done_cb: cb_obj = {'done':done_cb} ref.Py_INCREF(cb_obj) - self.thisptr.get().put(key._infohash, val._value, cpp.bindDoneCb(done_callback, cb_obj)) + self.thisptr.get().put(key._infohash, val._value, cpp.bindDoneCb(done_callback, cb_obj), cpp.time_point.max(), permanent) else: lock = threading.Condition() pending = 0 diff --git a/python/opendht_cpp.pxd b/python/opendht_cpp.pxd index 4b9bd41a..e2c4e74a 100644 --- a/python/opendht_cpp.pxd +++ b/python/opendht_cpp.pxd @@ -26,7 +26,7 @@ from libc.string cimport const_char, const_uchar ctypedef uint16_t in_port_t ctypedef unsigned short int sa_family_t; -cdef extern from "" namespace "std::chrono" nogil: +cdef extern from "" namespace "std::chrono" nogil: cdef cppclass duration[ulong]: duration() except + @@ -59,6 +59,13 @@ cdef extern from "" namespace "std" nogil: bool valid() const shared_future[T] share() +cdef extern from "opendht/utils.h" namespace "dht": + cdef cppclass time_point: + @staticmethod + time_point min() const + @staticmethod + time_point max() const + cdef extern from "opendht/infohash.h" namespace "dht": cdef cppclass InfoHash: InfoHash() except + @@ -254,7 +261,7 @@ cdef extern from "opendht/dhtrunner.h" namespace "dht": string getRoutingTablesLog(sa_family_t af) const string getSearchesLog(sa_family_t af) const void get(InfoHash key, GetCallback get_cb, DoneCallback done_cb, nullptr_t f, Where w) - void put(InfoHash key, shared_ptr[Value] val, DoneCallback done_cb) + void put(InfoHash key, shared_ptr[Value] val, DoneCallback done_cb, time_point created, bool permanent) ListenToken listen(InfoHash key, ValueCallback get_cb) void cancelListen(InfoHash key, SharedListenToken token) vector[unsigned] getNodeMessageStats(bool i)