My Project: /home/noptrix/ba/blackarch/packages/opendht-c/src/opendht/include/opendht/dht_interface.h Source File

My Project 3.7.7 C++ Distributed Hash Table

Loading...
Searching...
No Matches
dht_interface.h
1// Copyright (c) 2014-2026 Savoir-faire Linux Inc.
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include "infohash.h"
6#include "logger.h"
7#include "node_export.h"
8
9#include <queue>
10
11namespace dht {
12
13namespace net {
14class DatagramSocket;
15}
16
17 class OPENDHT_PUBLIC DhtInterface
18{
19public:
20 DhtInterface() = default;
21 DhtInterface(const std::shared_ptr<Logger>& l)
22 : logger_(l)
23 {}
24 virtual ~DhtInterface() = default;
25
26 // [[deprecated]]
27 using Status = NodeStatus;
28 // [[deprecated]]
29 using NodeExport = dht::NodeExport;
30
34 virtual NodeStatus updateStatus(sa_family_t af) { return getStatus(af); }
35 virtual NodeStatus getStatus(sa_family_t af) const = 0;
36 virtual NodeStatus getStatus() const = 0;
37
38 void addOnConnectedCallback(std::function<void()> cb) { onConnectCallbacks_.emplace(std::move(cb)); }
39 virtual void setOnPublicAddressChanged(PublicAddressChangedCb) {}
40
41 virtual net::DatagramSocket* getSocket() const { return {}; }
42
46 virtual const InfoHash& getNodeId() const = 0;
47
53 virtual void shutdown(ShutdownCallback cb, bool stop = false) = 0;
54
61 virtual bool isRunning(sa_family_t af = 0) const = 0;
62
63 virtual void registerType(const ValueType& type) = 0;
64
65 virtual const ValueType& getType(ValueType::Id type_id) const = 0;
66
67 virtual void addBootstrap(const std::string& /*host*/, const std::string& /*service*/) {};
68 virtual void clearBootstrap() {};
69
75 virtual void insertNode(const InfoHash& id, const SockAddr&) = 0;
76 virtual void insertNode(const NodeExport& n) = 0;
77
78 virtual void pingNode(SockAddr, DoneCallbackSimple&& cb = {}) = 0;
79
80 virtual time_point periodic(const uint8_t* buf, size_t buflen, SockAddr, const time_point& now) = 0;
81 virtual time_point periodic(
82 const uint8_t* buf, size_t buflen, const sockaddr* from, socklen_t fromlen, const time_point& now)
83 = 0;
84
95 virtual void get(
96 const InfoHash& key, GetCallback cb, DoneCallback donecb = {}, Value::Filter&& f = {}, Where&& w = {})
97 = 0;
98 virtual void get(
99 const InfoHash& key, GetCallback cb, DoneCallbackSimple donecb = {}, Value::Filter&& f = {}, Where&& w = {})
100 = 0;
101 virtual void get(
102 const InfoHash& key, GetCallbackSimple cb, DoneCallback donecb = {}, Value::Filter&& f = {}, Where&& w = {})
103 = 0;
104 virtual void get(
105 const InfoHash& key, GetCallbackSimple cb, DoneCallbackSimple donecb, Value::Filter&& f = {}, Where&& w = {})
106 = 0;
107
118 virtual void query(const InfoHash& key, QueryCallback cb, DoneCallback done_cb = {}, Query&& q = {}) = 0;
119 virtual void query(const InfoHash& key, QueryCallback cb, DoneCallbackSimple done_cb = {}, Query&& q = {}) = 0;
120
124 virtual std::vector<Sp<Value>> getLocal(const InfoHash& key, const Value::Filter& f = {}) const = 0;
125
129 virtual Sp<Value> getLocalById(const InfoHash& key, Value::Id vid) const = 0;
130
137 virtual void put(const InfoHash& key,
138 Sp<Value>,
139 DoneCallback cb = nullptr,
140 time_point created = time_point::max(),
141 bool permanent = false)
142 = 0;
143 virtual void put(const InfoHash& key,
144 const Sp<Value>& v,
145 DoneCallbackSimple cb,
146 time_point created = time_point::max(),
147 bool permanent = false)
148 = 0;
149 virtual void put(const InfoHash& key,
150 Value&& v,
151 DoneCallback cb = nullptr,
152 time_point created = time_point::max(),
153 bool permanent = false)
154 = 0;
155 virtual void put(const InfoHash& key,
156 Value&& v,
157 DoneCallbackSimple cb,
158 time_point created = time_point::max(),
159 bool permanent = false)
160 = 0;
161
165 virtual std::vector<Sp<Value>> getPut(const InfoHash&) const = 0;
166
170 virtual Sp<Value> getPut(const InfoHash&, const Value::Id&) const = 0;
171
176 virtual bool cancelPut(const InfoHash&, const Value::Id&) = 0;
177
185 virtual size_t listen(const InfoHash&, GetCallback, Value::Filter = {}, Where w = {}) = 0;
186 virtual size_t listen(const InfoHash& key, GetCallbackSimple cb, Value::Filter f = {}, Where w = {}) = 0;
187 virtual size_t listen(const InfoHash&, ValueCallback, Value::Filter = {}, Where w = {}) = 0;
188
189 virtual bool cancelListen(const InfoHash&, size_t token) = 0;
190
196 virtual void connectivityChanged(sa_family_t) = 0;
197 virtual void connectivityChanged() = 0;
198
203 virtual std::vector<NodeExport> exportNodes() const = 0;
204
205 virtual std::vector<ValuesExport> exportValues() const = 0;
206 virtual void importValues(const std::vector<ValuesExport>&) = 0;
207
208 virtual NodeStats getNodesStats(sa_family_t af) const = 0;
209
210 virtual std::string getStorageLog() const = 0;
211 virtual std::string getStorageLog(const InfoHash&) const = 0;
212
213 virtual std::string getRoutingTablesLog(sa_family_t) const = 0;
214 virtual std::string getSearchesLog(sa_family_t) const = 0;
215 virtual std::string getSearchLog(const InfoHash&, sa_family_t af = AF_UNSPEC) const = 0;
216
217 virtual void dumpTables() const = 0;
218 virtual std::vector<unsigned> getNodeMessageStats(bool in = false) = 0;
219
223 virtual void setStorageLimit(size_t limit = 0) = 0;
224 virtual size_t getStorageLimit() const = 0;
225
229 virtual void setLocalStorageLimit(size_t limit = 0) = 0;
230 virtual size_t getLocalStorageLimit() const = 0;
231
236 virtual std::pair<size_t, size_t> getStoreSize() const = 0;
237
238 virtual std::pair<size_t, size_t> getLocalStoreSize() const = 0;
239
240 virtual std::vector<SockAddr> getPublicAddress(sa_family_t family = 0) = 0;
241
242 virtual void setLogger(const std::shared_ptr<Logger>& l) { logger_ = l; }
243
247 virtual void setLogFilter(const InfoHash& f)
248 {
249 if (logger_)
250 logger_->setFilter(f);
251 }
252
253 virtual void setPushNotificationToken(const std::string&) {};
254
255 virtual void setPushNotificationTopic(const std::string&) {};
256 virtual void setPushNotificationPlatform(const std::string&) {};
257
262 virtual PushNotificationResult pushNotificationReceived(const std::map<std::string, std::string>& data) = 0;
263
264protected:
265 std::shared_ptr<Logger> logger_ {};
266 std::queue<std::function<void()>> onConnectCallbacks_ {};
267};
268
269} // namespace dht
dht::DhtInterface::insertNode
virtual void insertNode(const InfoHash &id, const SockAddr &)=0
dht::DhtInterface::getPut
virtual Sp< Value > getPut(const InfoHash &, const Value::Id &) const =0
dht::DhtInterface::getLocal
virtual std::vector< Sp< Value > > getLocal(const InfoHash &key, const Value::Filter &f={}) const =0
dht::DhtInterface::get
virtual void get(const InfoHash &key, GetCallback cb, DoneCallback donecb={}, Value::Filter &&f={}, Where &&w={})=0
dht::DhtInterface::getPut
virtual std::vector< Sp< Value > > getPut(const InfoHash &) const =0
dht::DhtInterface::setLogFilter
virtual void setLogFilter(const InfoHash &f)
Definition dht_interface.h:247
dht::DhtInterface::put
virtual void put(const InfoHash &key, Sp< Value >, DoneCallback cb=nullptr, time_point created=time_point::max(), bool permanent=false)=0
dht::DhtInterface::connectivityChanged
virtual void connectivityChanged(sa_family_t)=0
dht::DhtInterface::query
virtual void query(const InfoHash &key, QueryCallback cb, DoneCallback done_cb={}, Query &&q={})=0
dht::DhtInterface::isRunning
virtual bool isRunning(sa_family_t af=0) const =0
dht::DhtInterface::shutdown
virtual void shutdown(ShutdownCallback cb, bool stop=false)=0
dht::DhtInterface::pushNotificationReceived
virtual PushNotificationResult pushNotificationReceived(const std::map< std::string, std::string > &data)=0
dht::DhtInterface::setStorageLimit
virtual void setStorageLimit(size_t limit=0)=0
dht::DhtInterface::getLocalById
virtual Sp< Value > getLocalById(const InfoHash &key, Value::Id vid) const =0
dht::DhtInterface::listen
virtual size_t listen(const InfoHash &, GetCallback, Value::Filter={}, Where w={})=0
dht::DhtInterface::getNodeId
virtual const InfoHash & getNodeId() const =0
dht::DhtInterface::getStoreSize
virtual std::pair< size_t, size_t > getStoreSize() const =0
dht::DhtInterface::updateStatus
virtual NodeStatus updateStatus(sa_family_t af)
Definition dht_interface.h:34
dht::DhtInterface::setLocalStorageLimit
virtual void setLocalStorageLimit(size_t limit=0)=0
dht::DhtInterface::exportNodes
virtual std::vector< NodeExport > exportNodes() const =0
dht::DhtInterface::cancelPut
virtual bool cancelPut(const InfoHash &, const Value::Id &)=0
dht::SockAddr
Definition sockaddr.h:47
dht::Value::Filter
Definition value.h:166
dht::net::DatagramSocket
Definition network_utils.h:49
dht
Definition callbacks.h:17
dht::NodeStatus
NodeStatus
Definition callbacks.h:24
dht::NodeExport
Definition node_export.h:15
dht::NodeStats
Definition callbacks.h:38
dht::Query
Describes a query destined to another peer.
Definition value.h:988
dht::ValueType
Definition value.h:83
dht::Value
Definition value.h:150
dht::Where
Serializable dht::Value filter.
Definition value.h:850