My Project 1.7.4
C++ Distributed Hash Table
callbacks.h
1/*
2 * Copyright (C) 2014-2017 Savoir-faire Linux Inc.
3 * Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
4 * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com>
5 * Sébastien Blin <sebastien.blin@savoirfairelinux.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include "infohash.h"
24#include "value.h"
25
26#include <vector>
27#include <memory>
28#include <functional>
29
30#ifdef OPENDHT_JSONCPP
31#include <json/json.h>
32#endif
33
34namespace dht {
35
36struct Node;
37
41enum class NodeStatus {
42 Disconnected, // 0 nodes
43 Connecting, // 1+ nodes
44 Connected // 1+ good nodes
45};
46
47struct OPENDHT_PUBLIC NodeStats {
48 unsigned good_nodes {0},
49 dubious_nodes {0},
50 cached_nodes {0},
51 incoming_nodes {0};
52 unsigned table_depth {0};
53 unsigned getKnownNodes() const { return good_nodes + dubious_nodes; }
54 std::string toString() const;
55
56#ifdef OPENDHT_JSONCPP
60 Json::Value toJson() const;
61 NodeStats() {};
62 explicit NodeStats(const Json::Value& v);
63#endif
64
65 MSGPACK_DEFINE_MAP(good_nodes, dubious_nodes, cached_nodes, incoming_nodes, table_depth)
66};
67
68struct OPENDHT_PUBLIC NodeInfo {
69 InfoHash id;
70 InfoHash node_id;
71 NodeStats ipv4;
72 NodeStats ipv6;
73
74#ifdef OPENDHT_JSONCPP
78 Json::Value toJson() const;
79 NodeInfo() {};
80 explicit NodeInfo(const Json::Value& v);
81#endif
82
83 MSGPACK_DEFINE_MAP(id, node_id, ipv4, ipv6)
84};
85
89struct OPENDHT_PUBLIC Config {
92
98 NetId network;
99
102
105};
106
110struct OPENDHT_PUBLIC SecureDhtConfig
111{
112 Config node_config;
113 crypto::Identity id;
114};
115
116static constexpr size_t DEFAULT_STORAGE_LIMIT {1024 * 1024 * 64};
117
118using ValuesExport = std::pair<InfoHash, Blob>;
119
120using QueryCallback = std::function<bool(const std::vector<std::shared_ptr<FieldValueIndex>>& fields)>;
121using GetCallback = std::function<bool(const std::vector<std::shared_ptr<Value>>& values)>;
122using ValueCallback = std::function<bool(const std::vector<std::shared_ptr<Value>>& values, bool expired)>;
123using GetCallbackSimple = std::function<bool(std::shared_ptr<Value> value)>;
124using ShutdownCallback = std::function<void()>;
125
126using CertificateStoreQuery = std::function<std::vector<std::shared_ptr<crypto::Certificate>>(const InfoHash& pk_id)>;
127
128typedef bool (*GetCallbackRaw)(std::shared_ptr<Value>, void *user_data);
129
130OPENDHT_PUBLIC GetCallbackSimple bindGetCb(GetCallbackRaw raw_cb, void* user_data);
131OPENDHT_PUBLIC GetCallback bindGetCb(GetCallbackSimple cb);
132
133using DoneCallback = std::function<void(bool success, const std::vector<std::shared_ptr<Node>>& nodes)>;
134typedef void (*DoneCallbackRaw)(bool, std::vector<std::shared_ptr<Node>>*, void *user_data);
135typedef void (*ShutdownCallbackRaw)(void *user_data);
136typedef void (*DoneCallbackSimpleRaw)(bool, void *user_data);
137typedef bool (*FilterRaw)(const Value&, void *user_data);
138
139using DoneCallbackSimple = std::function<void(bool success)>;
140
141OPENDHT_PUBLIC ShutdownCallback bindShutdownCb(ShutdownCallbackRaw shutdown_cb_raw, void* user_data);
142OPENDHT_PUBLIC DoneCallback bindDoneCb(DoneCallbackSimple donecb);
143OPENDHT_PUBLIC DoneCallback bindDoneCb(DoneCallbackRaw raw_cb, void* user_data);
144OPENDHT_PUBLIC DoneCallbackSimple bindDoneCbSimple(DoneCallbackSimpleRaw raw_cb, void* user_data);
145OPENDHT_PUBLIC Value::Filter bindFilterRaw(FilterRaw raw_filter, void* user_data);
146
147}
Definition: callbacks.h:34
NodeStatus
Definition: callbacks.h:41
bool is_bootstrap
Definition: callbacks.h:101
NetId network
Definition: callbacks.h:98
InfoHash node_id
Definition: callbacks.h:91
bool maintain_storage
Definition: callbacks.h:104
Definition: node.h:47