Skip to content
Snippets Groups Projects
Commit eb90fffb authored by Adrien Béraud's avatar Adrien Béraud
Browse files

update for API changes

parent 041e280b
No related branches found
No related tags found
No related merge requests found
......@@ -85,12 +85,13 @@ GetCallback bindGetCb(GetCallbackSimple cb);
using DoneCallback = std::function<void(bool success, const std::vector<std::shared_ptr<Node>>& nodes)>;
typedef void (*DoneCallbackRaw)(bool, std::vector<std::shared_ptr<Node>>*, void *user_data);
typedef void (*ShutdownCallbackRaw)(void *user_data);
typedef void (*DoneCallbackSimpleRaw)(bool, void *user_data);
using DoneCallbackSimple = std::function<void(bool success)>;
ShutdownCallback bindShutdownCb(ShutdownCallbackRaw shutdown_cb_raw, void* user_data);
DoneCallback bindDoneCb(DoneCallbackSimple donecb);
DoneCallback bindDoneCb(DoneCallbackRaw raw_cb, void* user_data);
DoneCallbackSimple bindDoneCbSimple(DoneCallbackSimpleRaw raw_cb, void* user_data);
}
......@@ -169,11 +169,11 @@ public:
/**
* Lookup a key for a value.
*/
void lookup(Key k, LookupCallback cb = {}, Dht::DoneCallbackSimple doneCb = {}, bool exact_match = true);
void lookup(Key k, LookupCallback cb = {}, DoneCallbackSimple doneCb = {}, bool exact_match = true);
/**
* Adds an entry into the index.
*/
void insert(Key k, Value v, Dht::DoneCallbackSimple cb = {});
void insert(Key k, Value v, DoneCallbackSimple cb = {});
private:
class Cache {
......@@ -314,7 +314,7 @@ private:
*/
void lookupStep(Prefix k, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
std::shared_ptr<std::vector<std::shared_ptr<Value>>> vals, LookupCallback cb,
Dht::DoneCallbackSimple done_cb, std::shared_ptr<unsigned> max_common_prefix_len,
DoneCallbackSimple done_cb, std::shared_ptr<unsigned> max_common_prefix_len,
int start = -1, bool all_values = false);
/**
......
......@@ -296,13 +296,13 @@ cdef class DhtRunner(_WithID):
def shutdown(self, shutdown_cb=None):
cb_obj = {'shutdown':shutdown_cb}
ref.Py_INCREF(cb_obj)
self.thisptr.shutdown(cpp.bindShutdownCb(shutdown_callback, <void*>cb_obj))
self.thisptr.get().shutdown(cpp.bindShutdownCb(shutdown_callback, <void*>cb_obj))
def enableLogging(self):
cpp.enableLogging(self.thisptr[0])
cpp.enableLogging(self.thisptr.get()[0])
def disableLogging(self):
cpp.disableLogging(self.thisptr[0])
cpp.disableLogging(self.thisptr.get()[0])
def enableFileLogging(self, str path):
cpp.enableFileLogging(self.thisptr[0], path)
cpp.enableFileLogging(self.thisptr.get()[0], path)
def isRunning(self):
return self.thisptr.get().isRunning()
def getStorageLog(self):
......@@ -330,7 +330,7 @@ cdef class DhtRunner(_WithID):
if get_cb:
cb_obj = {'get':get_cb, 'done':done_cb}
ref.Py_INCREF(cb_obj)
self.thisptr.get(key._infohash, cpp.bindGetCb(get_callback, <void*>cb_obj), cpp.bindDoneCb(done_callback, <void*>cb_obj))
self.thisptr.get().get(key._infohash, cpp.bindGetCb(get_callback, <void*>cb_obj), cpp.bindDoneCb(done_callback, <void*>cb_obj))
else:
lock = threading.Condition()
pending = 0
......@@ -360,7 +360,7 @@ cdef class DhtRunner(_WithID):
if done_cb:
cb_obj = {'done':done_cb}
ref.Py_INCREF(cb_obj)
self.thisptr.put(key._infohash, val._value, cpp.bindDoneCb(done_callback, <void*>cb_obj))
self.thisptr.get().put(key._infohash, val._value, cpp.bindDoneCb(done_callback, <void*>cb_obj))
else:
lock = threading.Condition()
pending = 0
......@@ -384,7 +384,7 @@ cdef class DhtRunner(_WithID):
t._cb['cb'] = cb_obj
# avoid the callback being destructed if the token is destroyed
ref.Py_INCREF(cb_obj)
t._t = self.thisptr.listen(t._h, cpp.bindGetCb(get_callback, <void*>cb_obj)).share()
t._t = self.thisptr.get().listen(t._h, cpp.bindGetCb(get_callback, <void*>cb_obj)).share()
return t
def cancelListen(self, ListenToken token):
self.thisptr.get().cancelListen(token._h, token._t)
......@@ -429,7 +429,7 @@ cdef class Pht(object):
self.thisptr.lookup(
cppk,
cpp.Pht.bindLookupCb(lookup_callback, <void*>cb_obj),
cpp.Dht.bindDoneCbSimple(done_callback_simple, <void*>cb_obj)
cpp.bindDoneCbSimple(done_callback_simple, <void*>cb_obj)
)
def insert(self, key, IndexValue value, done_cb=None):
"""Add an index entry to the Index.
......@@ -449,6 +449,6 @@ cdef class Pht(object):
self.thisptr.insert(
cppk,
val,
cpp.Dht.bindDoneCbSimple(done_callback_simple, <void*>cb_obj)
cpp.bindDoneCbSimple(done_callback_simple, <void*>cb_obj)
)
......@@ -105,19 +105,21 @@ cdef extern from "opendht/callbacks.h" namespace "dht":
ctypedef void (*ShutdownCallbackRaw)(void *user_data)
ctypedef bool (*GetCallbackRaw)(shared_ptr[Value] values, void *user_data)
ctypedef void (*DoneCallbackRaw)(bool done, vector[shared_ptr[Node]]* nodes, void *user_data)
ctypedef void (*DoneCallbackSimpleRaw)(bool done, void *user_data)
cppclass ShutdownCallback:
ShutdownCallback() except +
cppclass GetCallback:
GetCallback() except +
#GetCallback(GetCallbackRaw cb, void *user_data) except +
cppclass DoneCallback:
DoneCallback() except +
#DoneCallback(DoneCallbackRaw, void *user_data) except +
cppclass DoneCallbackSimple:
DoneCallbackSimple() except +
cdef ShutdownCallback bindShutdownCb(ShutdownCallbackRaw cb, void *user_data)
cdef GetCallback bindGetCb(GetCallbackRaw cb, void *user_data)
cdef DoneCallback bindDoneCb(DoneCallbackRaw cb, void *user_data)
cdef DoneCallbackSimple bindDoneCbSimple(DoneCallbackSimpleRaw cb, void *user_data)
cppclass Config:
InfoHash node_id
......@@ -171,8 +173,8 @@ cdef extern from "opendht/indexation/pht.h" namespace "dht::indexation":
cppclass LookupCallback:
LookupCallback() except +
Pht(string, shared_ptr[DhtRunner]) except +
void lookup(IndexKey k, LookupCallback cb, Dht.DoneCallbackSimple doneCb);
void insert(IndexKey k, IndexValue v, Dht.DoneCallbackSimple cb)
void lookup(IndexKey k, LookupCallback cb, DoneCallbackSimple doneCb);
void insert(IndexKey k, IndexValue v, DoneCallbackSimple cb)
@staticmethod
LookupCallback bindLookupCb(LookupCallbackRaw cb, void *user_data)
......@@ -47,4 +47,12 @@ bindDoneCb(DoneCallbackRaw raw_cb, void* user_data)
};
}
DoneCallbackSimple
bindDoneCbSimple(DoneCallbackSimpleRaw raw_cb, void* user_data) {
if (not raw_cb) return {};
return [=](bool success) {
raw_cb(success, user_data);
};
}
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ constexpr std::chrono::minutes Pht::Cache::NODE_EXPIRE_TIME;
void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
std::shared_ptr<std::vector<std::shared_ptr<Value>>> vals,
LookupCallback cb, Dht::DoneCallbackSimple done_cb,
LookupCallback cb, DoneCallbackSimple done_cb,
std::shared_ptr<unsigned> max_common_prefix_len, int start, bool all_values)
{
struct node_lookup_result {
......@@ -135,7 +135,7 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
}
}
void Pht::lookup(Key k, Pht::LookupCallback cb, Dht::DoneCallbackSimple done_cb, bool exact_match) {
void Pht::lookup(Key k, Pht::LookupCallback cb, DoneCallbackSimple done_cb, bool exact_match) {
auto values = std::make_shared<std::vector<std::shared_ptr<Value>>>();
auto prefix = linearize(k);
auto lo = std::make_shared<int>(0);
......@@ -165,7 +165,7 @@ void Pht::updateCanary(Prefix p) {
}
}
void Pht::insert(Key k, Value v, Dht::DoneCallbackSimple done_cb) {
void Pht::insert(Key k, Value v, DoneCallbackSimple done_cb) {
Prefix kp = linearize(k);
auto lo = std::make_shared<int>(0);
......
......@@ -142,9 +142,9 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, std::map<std::string, dht::indexa
} else if (op == "log") {
params.log = !params.log;
if (params.log)
log::enableLogging(dht);
log::enableLogging(*dht);
else
log::disableLogging(dht);
log::disableLogging(*dht);
continue;
}
......@@ -206,9 +206,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, std::map<std::string, dht::indexa
}, dht::Query {std::move(rem)});
}
else if (op == "l") {
std::string rem;
std::getline(iss, rem);
dht.listen(id, [](std::shared_ptr<Value> value) {
dht->listen(id, [](std::shared_ptr<Value> value) {
std::cout << "Listen: found value:" << std::endl;
std::cout << "\t" << *value << std::endl;
return true;
......@@ -338,9 +336,9 @@ main(int argc, char **argv)
if (params.log) {
if (not params.logfile.empty())
log::enableFileLogging(dht, params.logfile);
log::enableFileLogging(*dht, params.logfile);
else
log::enableLogging(dht);
log::enableLogging(*dht);
}
if (not params.bootstrap.first.empty()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment