mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
headers: unify API across build options
This commit is contained in:
1 parent
bd9496e2ba
commit
e274ffd83b
8 files changed
+67
-90
No files matched your search
@@ -290,10 +290,8 @@ public:
|
||||
|
||||
std::vector<SockAddr> getPublicAddress(sa_family_t family = 0);
|
||||
|
||||
#if OPENDHT_PUSH_NOTIFICATIONS
|
||||
void pushNotificationReceived(const std::map<std::string, std::string>&) {}
|
||||
void resubscribe(const unsigned) {}
|
||||
#endif // OPENDHT_PUSH_NOTIFICATIONS
|
||||
void resubscribe(unsigned) {}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -228,7 +228,6 @@ public:
|
||||
DHT_LOG.setFilter(f);
|
||||
}
|
||||
|
||||
#if OPENDHT_PUSH_NOTIFICATIONS
|
||||
virtual void setPushNotificationToken(const std::string&) {};
|
||||
|
||||
/**
|
||||
@@ -240,8 +239,7 @@ public:
|
||||
* Refresh a listen via a token
|
||||
* @param token
|
||||
*/
|
||||
virtual void resubscribe(const unsigned token) = 0;
|
||||
#endif // OPENDHT_PUSH_NOTIFICATIONS
|
||||
virtual void resubscribe(unsigned token) = 0;
|
||||
|
||||
protected:
|
||||
bool logFilerEnable_ {};
|
||||
|
||||
@@ -51,12 +51,7 @@ public:
|
||||
* @note if the server fails to start (if port is already used or reserved),
|
||||
* it will fails silently
|
||||
*/
|
||||
DhtProxyServer(std::shared_ptr<DhtRunner> dht,
|
||||
in_port_t port = 8000.
|
||||
#if OPENDHT_PUSH_NOTIFICATIONS
|
||||
, const std::string& pushServer = ""
|
||||
#endif // OPENDHT_PUSH_NOTIFICATIONS
|
||||
);
|
||||
DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port = 8000, const std::string& pushServer = "");
|
||||
virtual ~DhtProxyServer();
|
||||
|
||||
DhtProxyServer(const DhtProxyServer& other) = delete;
|
||||
|
||||
+28
-34
@@ -20,7 +20,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
//#include "securedht.h"
|
||||
#include "infohash.h"
|
||||
#include "value.h"
|
||||
#include "callbacks.h"
|
||||
@@ -37,10 +36,6 @@
|
||||
#include <queue>
|
||||
#include <chrono>
|
||||
|
||||
#if OPENDHT_PROXY_CLIENT
|
||||
#include "dht_proxy_client.h"
|
||||
#endif // OPENDHT_PROXY_CLIENT
|
||||
|
||||
namespace dht {
|
||||
|
||||
struct Node;
|
||||
@@ -58,6 +53,13 @@ class OPENDHT_PUBLIC DhtRunner {
|
||||
public:
|
||||
typedef std::function<void(NodeStatus, NodeStatus)> StatusCallback;
|
||||
|
||||
struct Config {
|
||||
SecureDhtConfig dht_config;
|
||||
bool threaded;
|
||||
std::string proxy_server;
|
||||
std::string push_node_id;
|
||||
};
|
||||
|
||||
DhtRunner();
|
||||
virtual ~DhtRunner();
|
||||
|
||||
@@ -299,13 +301,6 @@ public:
|
||||
void registerCertificate(std::shared_ptr<crypto::Certificate> cert);
|
||||
void setLocalCertificateStore(CertificateStoreQuery&& query_method);
|
||||
|
||||
struct Config {
|
||||
SecureDhtConfig dht_config;
|
||||
bool threaded;
|
||||
std::string proxy_server;
|
||||
std::string push_node_id;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param port: Local port to bind. Both IPv4 and IPv6 will be tried (ANY).
|
||||
* @param identity: RSA key pair to use for cryptographic operations.
|
||||
@@ -377,13 +372,14 @@ public:
|
||||
*/
|
||||
void join();
|
||||
|
||||
#if OPENDHT_PROXY_CLIENT
|
||||
void setProxyServer(const std::string& proxy, const std::string& pushNodeId = "") {
|
||||
#if OPENDHT_PROXY_CLIENT
|
||||
if (config_.proxy_server == proxy and config_.push_node_id == pushNodeId)
|
||||
return;
|
||||
config_.proxy_server = proxy;
|
||||
config_.push_node_id = pushNodeId;
|
||||
enableProxy(use_proxy and not config_.proxy_server.empty());
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,12 +389,8 @@ public:
|
||||
*/
|
||||
void enableProxy(bool proxify);
|
||||
|
||||
#endif // OPENDHT_PROXY_CLIENT
|
||||
#if OPENDHT_PROXY_SERVER
|
||||
void forwardAllMessages(bool forward);
|
||||
#endif // OPENDHT_PROXY_SERVER
|
||||
/* Push notification methods */
|
||||
|
||||
#if OPENDHT_PUSH_NOTIFICATIONS
|
||||
/**
|
||||
* Updates the push notification device token
|
||||
*/
|
||||
@@ -412,8 +404,10 @@ public:
|
||||
* Refresh a listen via a token
|
||||
* @param token
|
||||
*/
|
||||
void resubscribe(const unsigned token);
|
||||
#endif // OPENDHT_PUSH_NOTIFICATIONS
|
||||
void resubscribe(unsigned token);
|
||||
|
||||
/* Proxy server mothods */
|
||||
void forwardAllMessages(bool forward);
|
||||
|
||||
private:
|
||||
static constexpr std::chrono::seconds BOOTSTRAP_PERIOD {10};
|
||||
@@ -433,7 +427,18 @@ private:
|
||||
return std::max(status4, status6);
|
||||
}
|
||||
|
||||
/** Local DHT instance */
|
||||
std::unique_ptr<SecureDht> dht_;
|
||||
|
||||
/** Proxy client instance */
|
||||
std::unique_ptr<SecureDht> dht_via_proxy_;
|
||||
|
||||
/** true if we are currently using a proxy */
|
||||
std::atomic_bool use_proxy {false};
|
||||
|
||||
/** Current configuration */
|
||||
Config config_;
|
||||
|
||||
/**
|
||||
* reset dht clients
|
||||
*/
|
||||
@@ -442,21 +447,7 @@ private:
|
||||
* @return the current active DHT
|
||||
*/
|
||||
SecureDht* activeDht() const;
|
||||
#if OPENDHT_PROXY_CLIENT
|
||||
/**
|
||||
* true if we are currently using a proxy
|
||||
*/
|
||||
std::atomic_bool use_proxy {false};
|
||||
/**
|
||||
* The current proxy client
|
||||
*/
|
||||
std::unique_ptr<SecureDht> dht_via_proxy_;
|
||||
Config config_;
|
||||
|
||||
#if OPENDHT_PUSH_NOTIFICATIONS
|
||||
std::string pushToken_;
|
||||
#endif
|
||||
#endif // OPENDHT_PROXY_CLIENT
|
||||
/**
|
||||
* Store current listeners and translates global tokens for each client.
|
||||
*/
|
||||
@@ -503,6 +494,9 @@ private:
|
||||
int s4 {-1}, s6 {-1};
|
||||
SockAddr bound4 {};
|
||||
SockAddr bound6 {};
|
||||
|
||||
/** Push notification token */
|
||||
std::string pushToken_;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -293,21 +293,14 @@ public:
|
||||
dht_->connectivityChanged();
|
||||
}
|
||||
|
||||
#if OPENDHT_PROXY_CLIENT
|
||||
#if OPENDHT_PUSH_NOTIFICATIONS
|
||||
void setPushNotificationToken(const std::string& token = "") {
|
||||
dht_->setPushNotificationToken(token);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if OPENDHT_PROXY_SERVER
|
||||
void forwardAllMessages(bool forward) {
|
||||
forward_all_ = forward;
|
||||
}
|
||||
#endif //OPENDHT_PROXY_SERVER
|
||||
|
||||
#if OPENDHT_PUSH_NOTIFICATIONS
|
||||
/**
|
||||
* Call linked callback with push_notification
|
||||
* @param notification to process
|
||||
@@ -322,7 +315,6 @@ public:
|
||||
void resubscribe(const unsigned token) {
|
||||
dht_->resubscribe(token);
|
||||
}
|
||||
#endif // OPENDHT_PUSH_NOTIFICATIONS
|
||||
|
||||
void setLoggers(LogMethod error = NOLOG, LogMethod warn = NOLOG, LogMethod debug = NOLOG)
|
||||
{
|
||||
@@ -360,9 +352,7 @@ private:
|
||||
|
||||
std::uniform_int_distribution<Value::Id> rand_id {};
|
||||
|
||||
#if OPENDHT_PROXY_SERVER
|
||||
std::atomic_bool forward_all_ {false};
|
||||
#endif //OPENDHT_PROXY_SERVER
|
||||
};
|
||||
|
||||
const ValueType CERTIFICATE_TYPE = {
|
||||
|
||||
Reference in new issue
Block a user