My Project 1.7.4
C++ Distributed Hash Table
dht_interface.h
1/*
2 * Copyright (C) 2014-2017 Savoir-faire Linux Inc.
3 * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include "infohash.h"
22#include "log_enable.h"
23
24namespace dht {
25
26class OPENDHT_PUBLIC DhtInterface {
27public:
28 DhtInterface() = default;
29 virtual ~DhtInterface() = default;
30
31 // [[deprecated]]
32 using Status = NodeStatus;
33 // [[deprecated]]
35
39 virtual NodeStatus getStatus(sa_family_t af) const = 0;
40 virtual NodeStatus getStatus() const = 0;
41
45 virtual const InfoHash& getNodeId() const = 0;
46
50 virtual void shutdown(ShutdownCallback cb) = 0;
51
58 virtual bool isRunning(sa_family_t af = 0) const = 0;
59
60 virtual void registerType(const ValueType& type) = 0;
61
62 virtual const ValueType& getType(ValueType::Id type_id) const = 0;
63
69 virtual void insertNode(const InfoHash& id, const SockAddr&) = 0;
70 virtual void insertNode(const InfoHash& id, const sockaddr* sa, socklen_t salen) = 0;
71 virtual void insertNode(const NodeExport& n) = 0;
72
73 virtual void pingNode(const sockaddr*, socklen_t, DoneCallbackSimple&& cb={}) = 0;
74
75 virtual time_point periodic(const uint8_t *buf, size_t buflen, const SockAddr&) = 0;
76 virtual time_point periodic(const uint8_t *buf, size_t buflen, const sockaddr* from, socklen_t fromlen) = 0;
77
88 virtual void get(const InfoHash& key, GetCallback cb, DoneCallback donecb={}, Value::Filter&& f={}, Where&& w = {}) = 0;
89 virtual void get(const InfoHash& key, GetCallback cb, DoneCallbackSimple donecb={}, Value::Filter&& f={}, Where&& w = {}) = 0;
90 virtual void get(const InfoHash& key, GetCallbackSimple cb, DoneCallback donecb={}, Value::Filter&& f={}, Where&& w = {}) = 0;
91 virtual void get(const InfoHash& key, GetCallbackSimple cb, DoneCallbackSimple donecb, Value::Filter&& f={}, Where&& w = {}) = 0;
92
103 virtual void query(const InfoHash& key, QueryCallback cb, DoneCallback done_cb = {}, Query&& q = {}) = 0;
104 virtual void query(const InfoHash& key, QueryCallback cb, DoneCallbackSimple done_cb = {}, Query&& q = {}) = 0;
105
109 virtual std::vector<Sp<Value>> getLocal(const InfoHash& key, Value::Filter f = Value::AllFilter()) const = 0;
110
114 virtual Sp<Value> getLocalById(const InfoHash& key, Value::Id vid) const = 0;
115
122 virtual void put(const InfoHash& key,
123 Sp<Value>,
124 DoneCallback cb=nullptr,
125 time_point created=time_point::max(),
126 bool permanent = false) = 0;
127 virtual void put(const InfoHash& key,
128 const Sp<Value>& v,
129 DoneCallbackSimple cb,
130 time_point created=time_point::max(),
131 bool permanent = false) = 0;
132 virtual void put(const InfoHash& key,
133 Value&& v,
134 DoneCallback cb=nullptr,
135 time_point created=time_point::max(),
136 bool permanent = false) = 0;
137 virtual void put(const InfoHash& key,
138 Value&& v,
139 DoneCallbackSimple cb,
140 time_point created=time_point::max(),
141 bool permanent = false) = 0;
142
146 virtual std::vector<Sp<Value>> getPut(const InfoHash&) = 0;
147
151 virtual Sp<Value> getPut(const InfoHash&, const Value::Id&) = 0;
152
157 virtual bool cancelPut(const InfoHash&, const Value::Id&) = 0;
158
166 virtual size_t listen(const InfoHash&, GetCallback, Value::Filter={}, Where w = {}) = 0;
167 virtual size_t listen(const InfoHash& key, GetCallbackSimple cb, Value::Filter f={}, Where w = {}) = 0;
168 virtual size_t listen(const InfoHash&, ValueCallback, Value::Filter={}, Where w = {}) = 0;
169
170 virtual bool cancelListen(const InfoHash&, size_t token) = 0;
171
177 virtual void connectivityChanged(sa_family_t) = 0;
178 virtual void connectivityChanged() = 0;
179
184 virtual std::vector<NodeExport> exportNodes() = 0;
185
186 virtual std::vector<ValuesExport> exportValues() const = 0;
187 virtual void importValues(const std::vector<ValuesExport>&) = 0;
188
189 virtual NodeStats getNodesStats(sa_family_t af) const = 0;
190
191 virtual std::string getStorageLog() const = 0;
192 virtual std::string getStorageLog(const InfoHash&) const = 0;
193
194 virtual std::string getRoutingTablesLog(sa_family_t) const = 0;
195 virtual std::string getSearchesLog(sa_family_t) const = 0;
196 virtual std::string getSearchLog(const InfoHash&, sa_family_t af = AF_UNSPEC) const = 0;
197
198 virtual void dumpTables() const = 0;
199 virtual std::vector<unsigned> getNodeMessageStats(bool in = false) = 0;
200
204 virtual void setStorageLimit(size_t limit = DEFAULT_STORAGE_LIMIT) = 0;
205
210 virtual std::pair<size_t, size_t> getStoreSize() const = 0;
211
212 virtual std::vector<SockAddr> getPublicAddress(sa_family_t family = 0) = 0;
213
217 virtual void setLoggers(LogMethod error = NOLOG, LogMethod warn = NOLOG, LogMethod debug = NOLOG)
218 {
219 DHT_LOG.DEBUG = debug;
220 DHT_LOG.WARN = warn;
221 DHT_LOG.ERR = error;
222 }
223
227 virtual void setLogFilter(const InfoHash& f)
228 {
229 DHT_LOG.setFilter(f);
230 }
231
232 virtual void setPushNotificationToken(const std::string&) {};
233
238 virtual void pushNotificationReceived(const std::map<std::string, std::string>& data) = 0;
239
240protected:
241 bool logFilerEnable_ {};
242 InfoHash logFiler_ {};
243 Logger DHT_LOG;
244};
245
246} // namespace dht
virtual void insertNode(const InfoHash &id, const SockAddr &)=0
virtual void get(const InfoHash &key, GetCallback cb, DoneCallback donecb={}, Value::Filter &&f={}, Where &&w={})=0
virtual void setLogFilter(const InfoHash &f)
virtual void setLoggers(LogMethod error=NOLOG, LogMethod warn=NOLOG, LogMethod debug=NOLOG)
virtual NodeStatus getStatus(sa_family_t af) const =0
virtual void put(const InfoHash &key, Sp< Value >, DoneCallback cb=nullptr, time_point created=time_point::max(), bool permanent=false)=0
virtual void connectivityChanged(sa_family_t)=0
virtual void query(const InfoHash &key, QueryCallback cb, DoneCallback done_cb={}, Query &&q={})=0
virtual Sp< Value > getPut(const InfoHash &, const Value::Id &)=0
virtual std::vector< NodeExport > exportNodes()=0
virtual void setStorageLimit(size_t limit=DEFAULT_STORAGE_LIMIT)=0
virtual bool isRunning(sa_family_t af=0) const =0
virtual Sp< Value > getLocalById(const InfoHash &key, Value::Id vid) const =0
virtual std::vector< Sp< Value > > getPut(const InfoHash &)=0
virtual size_t listen(const InfoHash &, GetCallback, Value::Filter={}, Where w={})=0
virtual const InfoHash & getNodeId() const =0
virtual std::pair< size_t, size_t > getStoreSize() const =0
virtual void pushNotificationReceived(const std::map< std::string, std::string > &data)=0
virtual void shutdown(ShutdownCallback cb)=0
virtual std::vector< Sp< Value > > getLocal(const InfoHash &key, Value::Filter f=Value::AllFilter()) const =0
virtual bool cancelPut(const InfoHash &, const Value::Id &)=0
Definition: callbacks.h:34
void NOLOG(char const *, va_list)
Definition: log_enable.h:38
NodeStatus
Definition: callbacks.h:41
Describes a query destined to another peer.
Definition: value.h:864
Serializable dht::Value filter.
Definition: value.h:740