mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-12 22:36:49 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8399996d9 |
No files matched your search
+2
-2
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required (VERSION 3.1)
|
||||
project (opendht)
|
||||
set (opendht_VERSION_MAJOR 1)
|
||||
set (opendht_VERSION_MINOR 6.1)
|
||||
set (opendht_VERSION_MINOR 6.0)
|
||||
set (opendht_VERSION ${opendht_VERSION_MAJOR}.${opendht_VERSION_MINOR})
|
||||
set (PACKAGE_VERSION ${opendht_VERSION})
|
||||
set (VERSION "${opendht_VERSION}")
|
||||
@@ -20,7 +20,7 @@ option (OPENDHT_PROXY_SERVER "Enable DHT proxy server, use Restbed and jsoncpp"
|
||||
option (OPENDHT_PUSH_NOTIFICATIONS "Enable push notifications support" OFF)
|
||||
option (OPENDHT_PROXY_SERVER_IDENTITY "Allow clients to use the node identity" OFF)
|
||||
option (OPENDHT_PROXY_CLIENT "Enable DHT proxy client, use Restbed and jsoncpp" OFF)
|
||||
option (OPENDHT_INDEX "Build DHT indexation feature" ON)
|
||||
option (OPENDHT_INDEX "Build DHT indexation feature" OFF)
|
||||
|
||||
find_package(Doxygen)
|
||||
option (OPENDHT_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
|
||||
|
||||
@@ -100,14 +100,14 @@ for r in results:
|
||||
|
||||
IRC: join us on Freenode at [`#opendht`](https://webchat.freenode.net/?channels=%23opendht).
|
||||
|
||||
## License
|
||||
## Licence
|
||||
Copyright (C) 2014-2018 Savoir-faire Linux Inc.
|
||||
|
||||
OpenDHT is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
See COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html for the full GPLv3 license.
|
||||
See COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html for the full GPLv3 licence.
|
||||
|
||||
## Acknowledgements
|
||||
This project was originally based on https://github.com/jech/dht by Juliusz Chroboczek.
|
||||
|
||||
+1
-1
Submodule argon2 updated: 670229c849...6f5427fb67.
+5
-5
@@ -1,7 +1,7 @@
|
||||
dnl define macros
|
||||
m4_define([opendht_major_version], 1)
|
||||
m4_define([opendht_minor_version], 6)
|
||||
m4_define([opendht_patch_version], 1)
|
||||
m4_define([opendht_patch_version], 0)
|
||||
m4_define([opendht_version],
|
||||
[opendht_major_version.opendht_minor_version.opendht_patch_version])
|
||||
|
||||
@@ -25,7 +25,7 @@ AC_PROG_CXX
|
||||
AM_PROG_AR
|
||||
|
||||
dnl Check for logs
|
||||
AC_ARG_ENABLE([logs], [AS_HELP_STRING([--disable-logs], [Disable DHT logs])])
|
||||
AC_ARG_ENABLE([logs], [AS_HELP_STRING([--disable-logs], [Disble DHT logs])])
|
||||
AS_IF([test "x$enable_logs" != "xno"], [
|
||||
AC_DEFINE([OPENDHT_LOG], [true], [Define if DHT logs are enabled])
|
||||
], [
|
||||
@@ -33,9 +33,9 @@ AS_IF([test "x$enable_logs" != "xno"], [
|
||||
])
|
||||
|
||||
dnl Check for indexation
|
||||
AC_ARG_ENABLE([indexation], [AS_HELP_STRING([--disable-indexation], [Disable DHT indexation])])
|
||||
AM_CONDITIONAL(ENABLE_INDEXATION, test x$enable_indexation != "xno")
|
||||
AS_IF([test "x$enable_indexation" != "xno"], [
|
||||
AC_ARG_ENABLE([indexation], [AS_HELP_STRING([--enable-indexation], [Enable DHT indexation])])
|
||||
AM_CONDITIONAL(ENABLE_INDEXATION, test x$enable_indexation == xyes)
|
||||
AS_IF([test "x$enable_indexation" = "xyes"], [
|
||||
AC_DEFINE([OPENDHT_INDEXATION], [1], [Define if DHT indexation is enabled])
|
||||
])
|
||||
|
||||
|
||||
@@ -99,10 +99,11 @@ public:
|
||||
bool isRunning(sa_family_t af = 0) const;
|
||||
|
||||
virtual void registerType(const ValueType& type) {
|
||||
types.registerType(type);
|
||||
types[type.id] = type;
|
||||
}
|
||||
const ValueType& getType(ValueType::Id type_id) const {
|
||||
return types.getType(type_id);
|
||||
const auto& t_it = types.find(type_id);
|
||||
return (t_it == types.end()) ? ValueType::USER_DATA : t_it->second;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,7 +350,7 @@ private:
|
||||
uint64_t oldsecret {};
|
||||
|
||||
// registred types
|
||||
TypeStore types;
|
||||
std::map<ValueType::Id, ValueType> types;
|
||||
|
||||
// are we a bootstrap node ?
|
||||
// note: Any running node can be used as a bootstrap node.
|
||||
|
||||
@@ -297,7 +297,6 @@ private:
|
||||
Value::Filter filterChain;
|
||||
std::thread thread;
|
||||
unsigned callbackId;
|
||||
std::shared_ptr<bool> isCanceledViaClose; // NOTE: unused if using push notifications
|
||||
std::shared_ptr<unsigned> pushNotifToken; // NOTE: unused if not using push notifications
|
||||
};
|
||||
std::vector<Listener> listeners_;
|
||||
|
||||
@@ -109,19 +109,6 @@ struct OPENDHT_PUBLIC ValueType {
|
||||
EditPolicy editPolicy {DEFAULT_EDIT_POLICY};
|
||||
};
|
||||
|
||||
class TypeStore {
|
||||
public:
|
||||
void registerType(const ValueType& type) {
|
||||
types[type.id] = type;
|
||||
}
|
||||
const ValueType& getType(ValueType::Id type_id) const {
|
||||
const auto& t_it = types.find(type_id);
|
||||
return (t_it == types.end()) ? ValueType::USER_DATA : t_it->second;
|
||||
}
|
||||
private:
|
||||
std::map<ValueType::Id, ValueType> types {};
|
||||
};
|
||||
|
||||
/**
|
||||
* A "value" is data potentially stored on the Dht, with some metadata.
|
||||
*
|
||||
@@ -187,15 +174,6 @@ struct OPENDHT_PUBLIC Value
|
||||
return f1(v) or f2(v);
|
||||
};
|
||||
}
|
||||
std::vector<Sp<Value>> filter(const std::vector<Sp<Value>>& values) {
|
||||
if (not (*this))
|
||||
return values;
|
||||
std::vector<Sp<Value>> ret;
|
||||
for (const auto& v : values)
|
||||
if ((*this)(v))
|
||||
ret.emplace_back(v);
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
/* Sneaky functions disguised in classes */
|
||||
|
||||
@@ -811,7 +811,6 @@ Dht::listen(const InfoHash& id, GetCallback cb, Value::Filter f, Where where)
|
||||
}
|
||||
if (!newvals.empty()) {
|
||||
if (!cb(newvals)) {
|
||||
// cancelListen is useful here, because we need to cancel on IPv4 and 6
|
||||
cancelListen(id, token);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ DhtProxyClient::get(const InfoHash& key, const GetCallback& cb, DoneCallback don
|
||||
if ((not filterChain or filterChain(*value)) && cb) {
|
||||
std::lock_guard<std::mutex> lock(lockCallbacks);
|
||||
callbacks_.emplace_back([cb, value, finished]() {
|
||||
if (not *finished and not cb({value}))
|
||||
if (not cb({value}))
|
||||
*finished = true;
|
||||
});
|
||||
loopSignal_();
|
||||
@@ -445,41 +445,13 @@ DhtProxyClient::listen(const InfoHash& key, GetCallback cb, Value::Filter filter
|
||||
|
||||
Listener l;
|
||||
++listener_token_;
|
||||
auto isCanceled = std::make_shared<bool>(false);
|
||||
|
||||
// Wrap cb in another callback to avoid value duplication.
|
||||
auto vals = std::make_shared<std::map<Value::Id, Sp<Value>>>();
|
||||
auto gcb = [=](const std::vector<Sp<Value>>& values) {
|
||||
std::vector<Sp<Value>> newvals;
|
||||
for (const auto& v : values) {
|
||||
auto it = vals->find(v->id);
|
||||
if (it == vals->cend() || !(*it->second == *v))
|
||||
newvals.push_back(v);
|
||||
}
|
||||
if (!newvals.empty()) {
|
||||
if (not *isCanceled and !cb(newvals)) {
|
||||
*isCanceled = true;
|
||||
cancelListen(key, listener_token_);
|
||||
return false;
|
||||
}
|
||||
for (const auto& v : newvals) {
|
||||
auto it = vals->emplace(v->id, v);
|
||||
if (not it.second)
|
||||
it.first->second = v;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
l.key = key.toString();
|
||||
l.token = listener_token_;
|
||||
l.req = req;
|
||||
l.cb = gcb;
|
||||
l.cb = cb;
|
||||
l.callbackId = callbackId;
|
||||
l.pushNotifToken = pushNotifToken;
|
||||
l.filterChain = std::move(filterChain);
|
||||
l.isCanceledViaClose = isCanceled;
|
||||
std::weak_ptr<bool> isCanceledViaClose(l.isCanceledViaClose);
|
||||
l.thread = std::thread([=]()
|
||||
{
|
||||
auto settings = std::make_shared<restbed::Settings>();
|
||||
@@ -498,7 +470,7 @@ DhtProxyClient::listen(const InfoHash& key, GetCallback cb, Value::Filter filter
|
||||
};
|
||||
auto state = std::make_shared<State>();
|
||||
restbed::Http::async(req,
|
||||
[this, filterChain, gcb, pushNotifToken, state](const std::shared_ptr<restbed::Request>& req,
|
||||
[this, filterChain, cb, pushNotifToken, state](const std::shared_ptr<restbed::Request>& req,
|
||||
const std::shared_ptr<restbed::Response>& reply) {
|
||||
auto code = reply->get_status_code();
|
||||
if (code == 200) {
|
||||
@@ -533,11 +505,12 @@ DhtProxyClient::listen(const InfoHash& key, GetCallback cb, Value::Filter filter
|
||||
auto* char_data = reinterpret_cast<const char*>(&body[0]);
|
||||
if (reader->parse(char_data, char_data + body.size(), &json, &err)) {
|
||||
auto value = std::make_shared<Value>(json);
|
||||
if (not filterChain or filterChain(*value)) {
|
||||
if ((not filterChain or filterChain(*value)) && cb) {
|
||||
std::lock_guard<std::mutex> lock(lockCallbacks);
|
||||
callbacks_.emplace_back([gcb, value, state]() {
|
||||
if (not state->cancel and not gcb({value}))
|
||||
callbacks_.emplace_back([cb, value, state]() {
|
||||
if (not state->cancel and not cb({value})) {
|
||||
state->cancel = true;
|
||||
}
|
||||
});
|
||||
loopSignal_();
|
||||
}
|
||||
@@ -553,8 +526,7 @@ DhtProxyClient::listen(const InfoHash& key, GetCallback cb, Value::Filter filter
|
||||
state->ok = false;
|
||||
}
|
||||
}, settings).get();
|
||||
auto isCanceledNormally = isCanceledViaClose.lock();
|
||||
if (not state->ok and isCanceledNormally and not *isCanceledNormally) {
|
||||
if (not state->ok) {
|
||||
opFailed();
|
||||
}
|
||||
}
|
||||
@@ -607,7 +579,6 @@ DhtProxyClient::cancelListen(const InfoHash&, size_t token)
|
||||
// Just stop the request
|
||||
if (listener.thread.joinable()) {
|
||||
// Close connection to stop listener?
|
||||
*(listener.isCanceledViaClose) = true;
|
||||
if (listener.req)
|
||||
restbed::Http::close(listener.req);
|
||||
listener.thread.join();
|
||||
|
||||
+2
-7
@@ -176,13 +176,8 @@ Value::msgpack_unpack_body(const msgpack::object& o)
|
||||
Value::Value(Json::Value& json)
|
||||
{
|
||||
try {
|
||||
if (json.isMember("id")) {
|
||||
if (json["id"].isString()) {
|
||||
id = Value::Id(std::stoull(json["id"].asString()));
|
||||
} else {
|
||||
id = Value::Id(json["id"].asLargestUInt());
|
||||
}
|
||||
}
|
||||
if (json.isMember("id"))
|
||||
id = ValueType::Id(json["id"].asInt());
|
||||
} catch (...) { }
|
||||
if (json.isMember("cypher")) {
|
||||
auto cypherStr = json["cypher"].asString();
|
||||
|
||||
Reference in new issue
Block a user