dht_interface.h
/*
* Copyright (C) 2014-2017 Savoir-faire Linux Inc.
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "infohash.h"
#include "log_enable.h"
namespace dht {
class OPENDHT_PUBLIC DhtInterface {
public:
DhtInterface() = default;
virtual ~DhtInterface() = default;
// [[deprecated]]
using Status = NodeStatus;
// [[deprecated]]
using NodeExport = dht::NodeExport;
virtual NodeStatus getStatus(sa_family_t af) const = 0;
virtual NodeStatus getStatus() const = 0;
virtual const InfoHash& getNodeId() const = 0;
virtual void shutdown(ShutdownCallback cb) = 0;
virtual bool isRunning(sa_family_t af = 0) const = 0;
virtual void registerType(const ValueType& type) = 0;
virtual const ValueType& getType(ValueType::Id type_id) const = 0;
virtual void insertNode(const InfoHash& id, const SockAddr&) = 0;
virtual void insertNode(const InfoHash& id, const sockaddr* sa, socklen_t salen) = 0;
virtual void insertNode(const NodeExport& n) = 0;
virtual void pingNode(const sockaddr*, socklen_t, DoneCallbackSimple&& cb={}) = 0;
virtual time_point periodic(const uint8_t *buf, size_t buflen, const SockAddr&) = 0;
virtual time_point periodic(const uint8_t *buf, size_t buflen, const sockaddr* from, socklen_t fromlen) = 0;
virtual void get(const InfoHash& key, GetCallback cb, DoneCallback donecb={}, Value::Filter&& f={}, Where&& w = {}) = 0;
virtual void get(const InfoHash& key, GetCallback cb, DoneCallbackSimple donecb={}, Value::Filter&& f={}, Where&& w = {}) = 0;
virtual void get(const InfoHash& key, GetCallbackSimple cb, DoneCallback donecb={}, Value::Filter&& f={}, Where&& w = {}) = 0;
virtual void get(const InfoHash& key, GetCallbackSimple cb, DoneCallbackSimple donecb, Value::Filter&& f={}, Where&& w = {}) = 0;
virtual void query(const InfoHash& key, QueryCallback cb, DoneCallback done_cb = {}, Query&& q = {}) = 0;
virtual void query(const InfoHash& key, QueryCallback cb, DoneCallbackSimple done_cb = {}, Query&& q = {}) = 0;
virtual std::vector<Sp<Value>> getLocal(const InfoHash& key, Value::Filter f = Value::AllFilter()) const = 0;
virtual Sp<Value> getLocalById(const InfoHash& key, Value::Id vid) 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 put(const InfoHash& key,
const Sp<Value>& v,
DoneCallbackSimple cb,
time_point created=time_point::max(),
bool permanent = false) = 0;
virtual void put(const InfoHash& key,
Value&& v,
DoneCallback cb=nullptr,
time_point created=time_point::max(),
bool permanent = false) = 0;
virtual void put(const InfoHash& key,
Value&& v,
DoneCallbackSimple cb,
time_point created=time_point::max(),
bool permanent = false) = 0;
virtual std::vector<Sp<Value>> getPut(const InfoHash&) = 0;
virtual Sp<Value> getPut(const InfoHash&, const Value::Id&) = 0;
virtual bool cancelPut(const InfoHash&, const Value::Id&) = 0;
virtual size_t listen(const InfoHash&, GetCallback, Value::Filter={}, Where w = {}) = 0;
virtual size_t listen(const InfoHash& key, GetCallbackSimple cb, Value::Filter f={}, Where w = {}) = 0;
virtual size_t listen(const InfoHash&, ValueCallback, Value::Filter={}, Where w = {}) = 0;
virtual bool cancelListen(const InfoHash&, size_t token) = 0;
virtual void connectivityChanged(sa_family_t) = 0;
virtual void connectivityChanged() = 0;
virtual std::vector<NodeExport> exportNodes() = 0;
virtual std::vector<ValuesExport> exportValues() const = 0;
virtual void importValues(const std::vector<ValuesExport>&) = 0;
virtual NodeStats getNodesStats(sa_family_t af) const = 0;
virtual std::string getStorageLog() const = 0;
virtual std::string getStorageLog(const InfoHash&) const = 0;
virtual std::string getRoutingTablesLog(sa_family_t) const = 0;
virtual std::string getSearchesLog(sa_family_t) const = 0;
virtual std::string getSearchLog(const InfoHash&, sa_family_t af = AF_UNSPEC) const = 0;
virtual void dumpTables() const = 0;
virtual std::vector<unsigned> getNodeMessageStats(bool in = false) = 0;
virtual void setStorageLimit(size_t limit = DEFAULT_STORAGE_LIMIT) = 0;
virtual std::pair<size_t, size_t> getStoreSize() const = 0;
virtual std::vector<SockAddr> getPublicAddress(sa_family_t family = 0) = 0;
virtual void setLoggers(LogMethod error = NOLOG, LogMethod warn = NOLOG, LogMethod debug = NOLOG)
{
DHT_LOG.DEBUG = debug;
DHT_LOG.WARN = warn;
DHT_LOG.ERR = error;
}
virtual void setLogFilter(const InfoHash& f)
{
DHT_LOG.setFilter(f);
}
virtual void setPushNotificationToken(const std::string&) {};
virtual void pushNotificationReceived(const std::map<std::string, std::string>& data) = 0;
protected:
bool logFilerEnable_ {};
InfoHash logFiler_ {};
Logger DHT_LOG;
};
} // namespace dht
dht::DhtInterface
Definition: dht_interface.h:26
dht::DhtInterface::insertNode
virtual void insertNode(const InfoHash &id, const SockAddr &)=0
dht::DhtInterface::get
virtual void get(const InfoHash &key, GetCallback cb, DoneCallback donecb={}, Value::Filter &&f={}, Where &&w={})=0
dht::DhtInterface::setLogFilter
virtual void setLogFilter(const InfoHash &f)
Definition: dht_interface.h:227
dht::DhtInterface::setLoggers
virtual void setLoggers(LogMethod error=NOLOG, LogMethod warn=NOLOG, LogMethod debug=NOLOG)
Definition: dht_interface.h:217
dht::DhtInterface::getStatus
virtual NodeStatus getStatus(sa_family_t af) const =0
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::getPut
virtual Sp< Value > getPut(const InfoHash &, const Value::Id &)=0
dht::DhtInterface::exportNodes
virtual std::vector< NodeExport > exportNodes()=0
dht::DhtInterface::setStorageLimit
virtual void setStorageLimit(size_t limit=DEFAULT_STORAGE_LIMIT)=0
dht::DhtInterface::isRunning
virtual bool isRunning(sa_family_t af=0) const =0
dht::DhtInterface::getLocalById
virtual Sp< Value > getLocalById(const InfoHash &key, Value::Id vid) const =0
dht::DhtInterface::getPut
virtual std::vector< Sp< Value > > getPut(const InfoHash &)=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::pushNotificationReceived
virtual void pushNotificationReceived(const std::map< std::string, std::string > &data)=0
dht::DhtInterface::shutdown
virtual void shutdown(ShutdownCallback cb)=0
dht::DhtInterface::getLocal
virtual std::vector< Sp< Value > > getLocal(const InfoHash &key, Value::Filter f=Value::AllFilter()) const =0
dht::DhtInterface::cancelPut
virtual bool cancelPut(const InfoHash &, const Value::Id &)=0
dht::Hash< HASH_LEN >
dht::SockAddr
Definition: sockaddr.h:55
dht::Value::Filter
Definition: value.h:150
dht
Definition: callbacks.h:34
dht::NOLOG
void NOLOG(char const *, va_list)
Definition: log_enable.h:38
dht::NodeStatus
NodeStatus
Definition: callbacks.h:41
dht::LogMethod
Definition: log_enable.h:43
dht::NodeExport
Definition: infohash.h:363
dht::NodeStats
Definition: callbacks.h:47
dht::Query
Describes a query destined to another peer.
Definition: value.h:864
dht::ValueType
Definition: value.h:79
dht::Value
Definition: value.h:135
dht::Where
Serializable dht::Value filter.
Definition: value.h:740