fixing various compilation errors

This commit is contained in:
Simon Désaulniers authored and Adrien Béraud committed 2016-05-02 15:25:14 -04:00
1 parent 17216afe0f
commit 4b13fcac70
11 files changed
+112 -95

No files matched your search

+2
View File
@@ -32,6 +32,7 @@ list (APPEND opendht_SOURCES
src/infohash.cpp
src/crypto.cpp
src/default_types.cpp
src/node.cpp
src/value.cpp
src/dht.cpp
src/network_engine.cpp
@@ -51,6 +52,7 @@ list (APPEND opendht_HEADERS
include/opendht/crypto.h
include/opendht/infohash.h
include/opendht/default_types.h
include/opendht/node.h
include/opendht/value.h
include/opendht/dht.h
include/opendht/network_engine.h
+1
View File
@@ -20,6 +20,7 @@
#pragma once
#include "opendht/dht.h"
#include "opendht/node.h"
#include "opendht/value.h"
#include "opendht/infohash.h"
#include "opendht/securedht.h"
+7 -2
View File
@@ -197,6 +197,11 @@ public:
};
static constexpr InfoHash zeroes;
static constexpr InfoHash ones;
static constexpr InfoHash zeroes {};
static constexpr InfoHash ones = {std::array<uint8_t, HASH_LEN>{{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
}}};
}
+14 -8
View File
@@ -60,16 +60,16 @@ public:
static const std::string PUT_INVALID_ID; /* invalid id in "put" request */
DhtProtocolException(uint16_t code, const std::string& msg="", InfoHash failing_node_id={})
: DhtException(msg), code(code), msg(msg), failing_node_id(failing_node_id) {}
: DhtException(msg), msg(msg), code(code), failing_node_id(failing_node_id) {}
std::string getMsg() const { return msg; }
uint16_t getCode() const { return code; }
const InfoHash getNodeId() const { return failing_node_id; }
private:
std::string msg;
uint16_t code;
const InfoHash failing_node_id;
std::string msg;
};
/*!
@@ -121,6 +121,9 @@ public:
time_point last_try {time_point::min()}; /* time of the last attempt to process the request. */
time_point reply_time {time_point::min()}; /* time when we received the response from the node. */
RequestStatus() {}
RequestStatus(time_point start, time_point reply_time = time_point::min())
: start(start), last_try(start), reply_time(reply_time) {}
bool expired(time_point now) const {
return reply_time < last_try && now > last_try + Node::MAX_RESPONSE_TIME;
}
@@ -237,9 +240,9 @@ public:
decltype(NetworkEngine::onGetValues) onGetValues,
decltype(NetworkEngine::onListen) onListen,
decltype(NetworkEngine::onAnnounce) onAnnounce) :
myid(info.myid), dht_socket(info.dht_socket), dht_socket6(info.dht_socket6), DHT_LOG(info.DHT_LOG),
scheduler(scheduler), onError(onError), onNewNode(onNewNode), onReportedAddr(onReportedAddr), onPing(onPing),
onFindNode(onFindNode), onGetValues(onGetValues), onListen(onListen), onAnnounce(onAnnounce)
onError(onError), onNewNode(onNewNode), onReportedAddr(onReportedAddr), onPing(onPing), onFindNode(onFindNode),
onGetValues(onGetValues), onListen(onListen), onAnnounce(onAnnounce), myid(info.myid),
dht_socket(info.dht_socket), dht_socket6(info.dht_socket6), DHT_LOG(info.DHT_LOG), scheduler(scheduler)
{
transaction_id = std::uniform_int_distribution<decltype(transaction_id)>{1}(rd_device);
}
@@ -268,7 +271,10 @@ public:
std::shared_ptr<RequestStatus>
sendPing(std::shared_ptr<Node> n, RequestCb on_done, RequestCb on_expired);
std::shared_ptr<RequestStatus>
sendPing(sockaddr* n, socklen_t salen, RequestCb on_done, RequestCb on_expired);
sendPing(sockaddr* sa, socklen_t salen, RequestCb on_done, RequestCb on_expired)
{
sendPing(std::make_shared<Node>(InfoHash {}, sa, salen), on_done, on_expired);
}
std::shared_ptr<RequestStatus>
sendFindNode(std::shared_ptr<Node> n,
const InfoHash& target,
@@ -427,7 +433,7 @@ private:
Blob &&msg,
std::function<void(std::shared_ptr<RequestStatus> req_status, uint16_t tid, ParsedMessage&&)> on_done,
std::function<void(std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool)> on_expired) :
tid(tid), msg(msg), on_done(on_done), on_expired(on_expired) {
on_done(on_done), on_expired(on_expired), tid(tid), msg(msg) {
status->node = node;
}
@@ -437,9 +443,9 @@ private:
std::function<void(std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool)> on_expired {};
const uint16_t tid {0}; /* the request id. */
Blob msg {}; /* the serialized message. */
std::shared_ptr<RequestStatus> status {}; /* the request info for DHT layer. */
unsigned attempt_count {0}; /* number of attempt to process the request. */
Blob msg {}; /* the serialized message. */
};
/**
+22 -26
View File
@@ -812,7 +812,7 @@ Dht::searchSendGetValues(Search& sr, SearchNode* pn, bool update)
}
};
auto onExpired =
[=](std::shared_ptr<NetworkEngine::RequestStatus> status, NetworkEngine::RequestAnswer&& answer) mutable {
[=](std::shared_ptr<NetworkEngine::RequestStatus>, NetworkEngine::RequestAnswer&&) mutable {
if (srp) {
searchStep(*srp);
}
@@ -896,8 +896,7 @@ Dht::searchStep(Search& sr)
searchStep(*srp);
}
},
[=](std::shared_ptr<NetworkEngine::RequestStatus> status,
NetworkEngine::RequestAnswer&& answer) mutable
[=](std::shared_ptr<NetworkEngine::RequestStatus>, NetworkEngine::RequestAnswer&&) mutable
{ /* on expired */
if (srp) {
searchStep(*srp);
@@ -940,15 +939,13 @@ Dht::searchStep(Search& sr)
{
auto srp = &sr;
network_engine->sendAnnounceValue(n.node, sr.id, *a.value, a.created, n.token,
[=](std::shared_ptr<NetworkEngine::RequestStatus> status,
NetworkEngine::RequestAnswer&& answer) mutable
[=](std::shared_ptr<NetworkEngine::RequestStatus>, NetworkEngine::RequestAnswer&&) mutable
{ /* on done */
if (srp) {
searchStep(*srp);
}
},
[=](std::shared_ptr<NetworkEngine::RequestStatus> status,
NetworkEngine::RequestAnswer&& answer) mutable
[=](std::shared_ptr<NetworkEngine::RequestStatus>, NetworkEngine::RequestAnswer&&) mutable
{ /* on expired */
if (srp) {
searchStep(*srp);
@@ -2232,11 +2229,12 @@ Dht::neighbourhoodMaintenance(RoutingTable& list)
auto sr = q->af == AF_INET ? searches4.find(id) : searches6.find(id);
auto srp = &sr->second;
network_engine->sendFindNode(n, id, want,
[=](std::shared_ptr<NetworkEngine::RequestStatus> status, NetworkEngine::RequestAnswer&& answer) mutable
[=](std::shared_ptr<NetworkEngine::RequestStatus> status,
NetworkEngine::RequestAnswer&& answer) mutable
{ /* on done */
onGetValuesDone(status, answer, srp);
},
[=](std::shared_ptr<NetworkEngine::RequestStatus> status, NetworkEngine::RequestAnswer&& answer) mutable
[=](std::shared_ptr<NetworkEngine::RequestStatus>, NetworkEngine::RequestAnswer&&) mutable
{ /* on expired */
searchStep(*srp);
}
@@ -2298,8 +2296,7 @@ Dht::bucketMaintenance(RoutingTable& list)
{ /* on done */
onGetValuesDone(status, answer, srp);
},
[=](std::shared_ptr<NetworkEngine::RequestStatus> status,
NetworkEngine::RequestAnswer&& answer) mutable
[=](std::shared_ptr<NetworkEngine::RequestStatus>, NetworkEngine::RequestAnswer&&) mutable
{ /* on expired */
searchStep(*srp);
}
@@ -2545,7 +2542,7 @@ Dht::onReportedAddr(const InfoHash& id, sockaddr* addr , socklen_t addr_length)
}
NetworkEngine::RequestAnswer
Dht::onPing(std::shared_ptr<Node> node)
Dht::onPing(std::shared_ptr<Node>)
{
return {};
}
@@ -2568,7 +2565,7 @@ Dht::onFindNode(std::shared_ptr<Node> node, InfoHash& hash, want_t want)
}
NetworkEngine::RequestAnswer
Dht::onGetValues(std::shared_ptr<Node> node, InfoHash& hash, want_t want)
Dht::onGetValues(std::shared_ptr<Node> node, InfoHash& hash, want_t)
{
NetworkEngine::RequestAnswer* answer;
DHT_LOG.DEBUG("[node %s %s] got 'get' request for %s.",
@@ -2667,7 +2664,7 @@ Dht::onListen(std::shared_ptr<Node> node, InfoHash& hash, Blob& token, size_t ri
}
void
Dht::onListenDone(std::shared_ptr<NetworkEngine::RequestStatus> status, NetworkEngine::RequestAnswer& a, Search* sr)
Dht::onListenDone(std::shared_ptr<NetworkEngine::RequestStatus> status, NetworkEngine::RequestAnswer&, Search* sr)
{
DHT_LOG.DEBUG("Got reply to listen.");
if (sr) {
@@ -2773,19 +2770,18 @@ Dht::onAnnounceDone(std::shared_ptr<NetworkEngine::RequestStatus> status, Networ
// If the value was just successfully announced, call the callback
sr->announce.erase(std::remove_if(sr->announce.begin(), sr->announce.end(),
[&](std::pair<const uint16_t, Announce>& ap) {
auto& a = ap.second;
if (!a.value || a.value->id != v->id)
return false;
auto type = getType(a.value->type);
if (sr->isAnnounced(v->id, type, now)) {
if (a.callback) {
a.callback(true, sr->getNodes());
a.callback = nullptr;
[&](Announce& a) {
if (!a.value || a.value->id != v->id)
return false;
auto type = getType(a.value->type);
if (sr->isAnnounced(v->id, type, now)) {
if (a.callback) {
a.callback(true, sr->getNodes());
a.callback = nullptr;
}
return true;
}
return true;
}
return false;
return false;
}), sr->announce.end());
}
-7
View File
@@ -30,13 +30,6 @@ extern "C" {
namespace dht {
static constexpr InfoHash zeroes {};
static constexpr InfoHash ones = {std::array<uint8_t, HASH_LEN>{{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
}}};
InfoHash::InfoHash(const std::string& hex) {
if (hex.size() < 2*HASH_LEN) {
fill(0);
+34 -28
View File
@@ -40,7 +40,7 @@ const std::string DhtProtocolException::PUT_INVALID_ID {"Put with invalid id"};
constexpr std::chrono::seconds NetworkEngine::UDP_REPLY_TIME;
const std::string NetworkEngine::my_v {"RNG1"};
const constexpr uint16_t NetworkEngine::TransId::INVALID;
static std::mt19937 rd_device {dht::crypto::random_device{}()};
std::mt19937 NetworkEngine::rd_device {dht::crypto::random_device{}()};
const NetworkEngine::TransPrefix NetworkEngine::TransPrefix::PING = {"pn"};
const NetworkEngine::TransPrefix NetworkEngine::TransPrefix::FIND_NODE = {"fn"};
@@ -141,6 +141,8 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr
case MessageType::Reply:
req->on_done(req->status, msg.tid[2], std::move(msg));
break;
default:
break;
}
} else {
auto node = onNewNode(msg.id, from, fromlen, 1);
@@ -180,15 +182,18 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr
}
break;
}
case MessageType::Listen:
case MessageType::Listen: {
if (!msg.tid.matches(TransPrefix::LISTEN, &ttid)) {
break;
break;
}
in_stats.listen++;
RequestAnswer answer = onListen(node, msg.info_hash, msg.token, msg.tid[2]);
sendListenConfirmation(from, fromlen, msg.tid);
break;
}
default:
break;
}
} catch (const std::overflow_error& e) {
DHT_LOG.ERROR("Can't send value: buffer not large enough !");
} catch (DhtProtocolException& e) {
@@ -251,14 +256,17 @@ NetworkEngine::sendPing(std::shared_ptr<Node> n, RequestCb on_done, RequestCb on
pk.pack(std::string("v")); pk.pack(my_v);
Blob b {buffer.data(), buffer.data() + buffer.size()};
Request req {tid[2], n, std::move(b), nullptr,
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool s) { /* on expired */
Request req {tid[2], n, std::move(b),
[=](std::shared_ptr<RequestStatus> req_status, uint16_t, ParsedMessage&&){
on_done(req_status, {});
},
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool) { /* on expired */
on_expired(req_status, {});
requests.erase(tid);
}
};
auto req_status = std::make_shared<RequestStatus>(req.status);
requests.emplace(std::move(req));
auto req_status = req.status;
requests.emplace(tid[2], std::make_shared<Request>(std::move(req)));
send(buffer.data(), buffer.size(), 0, (sockaddr*)&n->ss, n->sslen);
out_stats.ping++;
return std::move(req_status);
@@ -309,16 +317,16 @@ NetworkEngine::sendFindNode(std::shared_ptr<Node> n, const InfoHash& target, wan
Blob b {buffer.data(), buffer.data() + buffer.size()};
Request req {tid[2], n, std::move(b),
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, ParsedMessage&& msg) { /* on done */
[=](std::shared_ptr<RequestStatus> req_status, uint16_t, ParsedMessage&& msg) { /* on done */
on_done(req_status, deserializeNodesValues(msg));
},
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool s) { /* on expired */
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool) { /* on expired */
on_expired(req_status, {});
requests.erase(tid);
}
};
auto req_status = std::make_shared<RequestStatus>(req.status);
requests.emplace(std::move(req));
auto req_status = req.status;
requests.emplace(tid[2], std::make_shared<Request>(std::move(req)));
send(buffer.data(), buffer.size(), (n->reply_time >= scheduler->time() - UDP_REPLY_TIME) ? 0 : MSG_CONFIRM,
(sockaddr*)&n->ss, n->sslen);
out_stats.find++;
@@ -352,16 +360,16 @@ NetworkEngine::sendGetValues(std::shared_ptr<Node> n, const InfoHash& target, wa
Blob b {buffer.data(), buffer.data() + buffer.size()};
Request req {tid[2], n, std::move(b),
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, ParsedMessage&& msg) { /* on done */
[=](std::shared_ptr<RequestStatus> req_status, uint16_t, ParsedMessage&& msg) { /* on done */
on_done(req_status, deserializeNodesValues(msg));
},
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool s) { /* on expired */
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool) { /* on expired */
on_expired(req_status, {});
requests.erase(tid);
}
};
auto req_status = std::make_shared<RequestStatus>(req.status);
requests.emplace(std::move(req));
auto req_status = req.status;
requests.emplace(tid[2], std::make_shared<Request>(std::move(req)));
send(buffer.data(), buffer.size(), (n->reply_time >= scheduler->time() - UDP_REPLY_TIME) ? 0 : MSG_CONFIRM,
(sockaddr*)&n->ss, n->sslen);
out_stats.get++;
@@ -370,7 +378,7 @@ NetworkEngine::sendGetValues(std::shared_ptr<Node> n, const InfoHash& target, wa
NetworkEngine::RequestAnswer
NetworkEngine::deserializeNodesValues(ParsedMessage& msg) {
RequestAnswer req_a {msg.token, std::move(msg.values)};
RequestAnswer req_a {msg.token, std::move(msg.values), {}, {}};
if (msg.nodes4.size() % NODE4_INFO_BUF_LEN != 0 || msg.nodes6.size() % NODE6_INFO_BUF_LEN != 0) {
throw DhtProtocolException {DhtProtocolException::WRONG_NODE_INFO_BUF_LEN};
} else {
@@ -514,7 +522,6 @@ NetworkEngine::bufferNodes(sa_family_t af, const InfoHash& id, want_t want,
{
uint8_t bnodes[8 * NODE4_INFO_BUF_LEN];
uint8_t bnodes6[8 * NODE6_INFO_BUF_LEN];
size_t numnodes, numnodes6 = 0;
if (want < 0)
want = af == AF_INET ? WANT4 : WANT6;
@@ -524,15 +531,14 @@ NetworkEngine::bufferNodes(sa_family_t af, const InfoHash& id, want_t want,
for (const auto& n : closest_nodes) {
numnodes = insertClosestNode(nodes, numnodes, id, *n);
}
return numnodes;
};
if ((want & WANT4)) {
numnodes = buff(bnodes, id, nodes);
buff(bnodes, id, nodes);
}
if ((want & WANT6)) {
numnodes6 = buff(bnodes6, id, nodes6);
buff(bnodes6, id, nodes6);
}
Blob bn4(8 * NODE4_INFO_BUF_LEN), bn6(8 * NODE6_INFO_BUF_LEN);
@@ -563,16 +569,16 @@ NetworkEngine::sendListen(std::shared_ptr<Node> n, const InfoHash& infohash, con
Blob b {buffer.data(), buffer.data() + buffer.size()};
Request req {tid[2], n, std::move(b),
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, ParsedMessage&& msg) { /* on done */
[=](std::shared_ptr<RequestStatus> req_status, uint16_t, ParsedMessage&&) { /* on done */
on_done(req_status, {});
},
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool s) { /* on expired */
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool) { /* on expired */
on_expired(req_status, {});
requests.erase(tid);
}
};
auto req_status = std::make_shared<RequestStatus>(req.status);
requests.emplace(std::move(req));
auto req_status = req.status;
requests.emplace(tid[2], std::make_shared<Request>(std::move(req)));
send(buffer.data(), buffer.size(), (n->reply_time >= scheduler->time() - UDP_REPLY_TIME) ? 0 : MSG_CONFIRM,
(sockaddr*)&n->ss, n->sslen);
out_stats.listen++;
@@ -623,20 +629,20 @@ NetworkEngine::sendAnnounceValue(std::shared_ptr<Node> n, const InfoHash& infoha
Blob b {buffer.data(), buffer.data() + buffer.size()};
Request req {tid[2], n, std::move(b),
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, ParsedMessage&& msg) { /* on done */
[=](std::shared_ptr<RequestStatus> req_status, uint16_t, ParsedMessage&& msg) { /* on done */
if (msg.value_id == Value::INVALID_ID) {
DHT_LOG.DEBUG("Unknown search or announce!");
} else {
on_done(req_status, {});
}
},
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool s) { /* on expired */
[=](std::shared_ptr<RequestStatus> req_status, uint16_t tid, bool) { /* on expired */
on_expired(req_status, {});
requests.erase(tid);
}
};
auto req_status = std::make_shared<RequestStatus>(req.status);
requests.emplace(std::move(req));
auto req_status = req.status;
requests.emplace(tid[2], std::make_shared<Request>(std::move(req)));
send(buffer.data(), buffer.size(), (n->reply_time >= scheduler->time() - UDP_REPLY_TIME) ? 0 : MSG_CONFIRM,
(sockaddr*)&n->ss, n->sslen);
out_stats.put++;
+7
View File
@@ -33,6 +33,7 @@ constexpr std::chrono::minutes Node::NODE_GOOD_TIME;
constexpr std::chrono::seconds Node::MAX_RESPONSE_TIME;
/* This is our definition of a known-good node. */
bool
Node::isGood(time_point now) const
{
return
@@ -81,4 +82,10 @@ Node::received(time_point now, bool answer)
}
}
std::ostream& operator<< (std::ostream& s, const Node& h)
{
s << h.id << " " << print_addr(h.ss, h.sslen);
return s;
}
}
+20 -20
View File
@@ -75,9 +75,9 @@ SecureDht::SecureDht(int s, int s6, SecureDht::Config conf)
1
}, [this](bool ok) {
if (ok)
DHT_DEBUG("SecureDht: public key announced successfully");
DHT_LOG.DEBUG("SecureDht: public key announced successfully");
else
DHT_ERROR("SecureDht: error while announcing public key!");
DHT_LOG.ERROR("SecureDht: error while announcing public key!");
});
}
}
@@ -95,11 +95,11 @@ SecureDht::secureType(ValueType&& type)
type.storePolicy = [this,type](InfoHash id, std::shared_ptr<Value>& v, InfoHash nid, const sockaddr* a, socklen_t al) {
if (v->isSigned()) {
if (!v->owner.checkSignature(v->getToSign(), v->signature)) {
DHT_WARN("Signature verification failed");
DHT_LOG.WARN("Signature verification failed");
return false;
}
else
DHT_WARN("Signature verification succeded");
DHT_LOG.WARN("Signature verification succeded");
}
return type.storePolicy(id, v, nid, a, al);
};
@@ -107,18 +107,18 @@ SecureDht::secureType(ValueType&& type)
if (!o->isSigned())
return type.editPolicy(id, o, n, nid, a, al);
if (o->owner != n->owner) {
DHT_WARN("Edition forbidden: owner changed.");
DHT_LOG.WARN("Edition forbidden: owner changed.");
return false;
}
if (!o->owner.checkSignature(n->getToSign(), n->signature)) {
DHT_WARN("Edition forbidden: signature verification failed.");
DHT_LOG.WARN("Edition forbidden: signature verification failed.");
return false;
}
if (o->seq == n->seq) {
// If the data is exactly the same,
// it can be reannounced, possibly by someone else.
if (o->getToSign() != n->getToSign()) {
DHT_WARN("Edition forbidden: sequence number must be increasing.");
DHT_LOG.WARN("Edition forbidden: sequence number must be increasing.");
return false;
}
}
@@ -152,7 +152,7 @@ SecureDht::registerCertificate(const InfoHash& node, const Blob& data)
}
InfoHash h = crt->getPublicKey().getId();
if (node == h) {
DHT_DEBUG("Registering public key for %s", h.toString().c_str());
DHT_LOG.DEBUG("Registering public key for %s", h.toString().c_str());
auto it = nodesCertificates_.find(h);
if (it == nodesCertificates_.end())
std::tie(it, std::ignore) = nodesCertificates_.emplace(h, std::move(crt));
@@ -160,7 +160,7 @@ SecureDht::registerCertificate(const InfoHash& node, const Blob& data)
it->second = std::move(crt);
return it->second;
} else {
DHT_DEBUG("Certificate %s for node %s does not match node id !", h.toString().c_str(), node.toString().c_str());
DHT_LOG.DEBUG("Certificate %s for node %s does not match node id !", h.toString().c_str(), node.toString().c_str());
return nullptr;
}
}
@@ -177,7 +177,7 @@ SecureDht::findCertificate(const InfoHash& node, std::function<void(const std::s
{
std::shared_ptr<crypto::Certificate> b = getCertificate(node);
if (b && *b) {
DHT_DEBUG("Using public key from cache for %s", node.toString().c_str());
DHT_LOG.DEBUG("Using public key from cache for %s", node.toString().c_str());
if (cb)
cb(b);
return;
@@ -185,7 +185,7 @@ SecureDht::findCertificate(const InfoHash& node, std::function<void(const std::s
if (localQueryMethod_) {
auto res = localQueryMethod_(node);
if (not res.empty()) {
DHT_DEBUG("Registering public key from local store for %s", node.toString().c_str());
DHT_LOG.DEBUG("Registering public key from local store for %s", node.toString().c_str());
nodesCertificates_.emplace(node, res.front());
if (cb)
cb(res.front());
@@ -200,7 +200,7 @@ SecureDht::findCertificate(const InfoHash& node, std::function<void(const std::s
for (const auto& v : vals) {
if (auto cert = registerCertificate(node, v->data)) {
*found = true;
DHT_DEBUG("Found public key for %s", node.toString().c_str());
DHT_LOG.DEBUG("Found public key for %s", node.toString().c_str());
if (cb)
cb(cert);
return false;
@@ -232,7 +232,7 @@ SecureDht::getCallbackFilter(GetCallback cb, Value::Filter&& filter)
}
// Ignore values belonging to other people
} catch (const std::exception& e) {
DHT_WARN("Could not decrypt value %s : %s", v->toString().c_str(), e.what());
DHT_LOG.WARN("Could not decrypt value %s : %s", v->toString().c_str(), e.what());
}
}
// Check signed values
@@ -242,7 +242,7 @@ SecureDht::getCallbackFilter(GetCallback cb, Value::Filter&& filter)
tmpvals.push_back(v);
}
else
DHT_WARN("Signature verification failed for %s", v->toString().c_str());
DHT_LOG.WARN("Signature verification failed for %s", v->toString().c_str());
}
// Forward normal values
else {
@@ -279,19 +279,19 @@ SecureDht::putSigned(const InfoHash& hash, std::shared_ptr<Value> val, DoneCallb
// Check if we are already announcing a value
auto p = getPut(hash, val->id);
if (p && val->seq <= p->seq) {
DHT_DEBUG("Found previous value being announced.");
DHT_LOG.DEBUG("Found previous value being announced.");
val->seq = p->seq + 1;
}
// Check if data already exists on the dht
get(hash,
[val,this] (const std::vector<std::shared_ptr<Value>>& vals) {
DHT_DEBUG("Found online previous value being announced.");
DHT_LOG.DEBUG("Found online previous value being announced.");
for (const auto& v : vals) {
if (!v->isSigned())
DHT_ERROR("Existing non-signed value seems to exists at this location.");
DHT_LOG.ERROR("Existing non-signed value seems to exists at this location.");
else if (v->owner.getId() != getId())
DHT_ERROR("Existing signed value belonging to someone else seems to exists at this location.");
DHT_LOG.ERROR("Existing signed value belonging to someone else seems to exists at this location.");
else if (val->seq <= v->seq)
val->seq = v->seq + 1;
}
@@ -314,11 +314,11 @@ SecureDht::putEncrypted(const InfoHash& hash, const InfoHash& to, std::shared_pt
callback(false, {});
return;
}
DHT_WARN("Encrypting data for PK: %s", crt->getPublicKey().getId().toString().c_str());
DHT_LOG.WARN("Encrypting data for PK: %s", crt->getPublicKey().getId().toString().c_str());
try {
put(hash, encrypt(*val, crt->getPublicKey()), callback);
} catch (const std::exception& e) {
DHT_ERROR("Error putting encrypted data: %s", e.what());
DHT_LOG.ERROR("Error putting encrypted data: %s", e.what());
if (callback)
callback(false, {});
}
+4 -3
View File
@@ -18,11 +18,12 @@
*/
#include "utils.h"
#include "default_types.h"
namespace dht {
std::string
dht::print_addr(const sockaddr* sa, socklen_t slen)
print_addr(const sockaddr* sa, socklen_t slen)
{
char hbuf[NI_MAXHOST];
char sbuf[NI_MAXSERV];
@@ -40,13 +41,13 @@ dht::print_addr(const sockaddr* sa, socklen_t slen)
}
std::string
dht::print_addr(const sockaddr_storage& ss, socklen_t sslen)
print_addr(const sockaddr_storage& ss, socklen_t sslen)
{
return print_addr((const sockaddr*)&ss, sslen);
}
std::string
dht::printAddr(const Address& addr) {
printAddr(const Address& addr) {
return print_addr((const sockaddr*)&addr.first, addr.second);
}
+1 -1
View File
@@ -38,7 +38,7 @@ const std::string printTime(const std::time_t& now) {
return buf;
}
void print_node_info(const DhtRunner& dht, const dht_params& params) {
void print_node_info(const DhtRunner& dht, const dht_params&) {
std::cout << "OpenDht node " << dht.getNodeId() << " running on port " << dht.getBoundPort() << std::endl;
std::cout << "Public key ID " << dht.getId() << std::endl;
}