headers: unify API across build options

This commit is contained in:
Adrien Béraud committed 2018-01-31 18:07:43 +01:00
1 parent bd9496e2ba
commit e274ffd83b
8 files changed
+67 -90

No files matched your search

+7 -9
View File
@@ -37,19 +37,17 @@ using namespace std::placeholders;
namespace dht {
DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port
#if OPENDHT_PUSH_NOTIFICATIONS
, const std::string& pushServer
#endif // OPENDHT_PUSH_NOTIFICATIONS
)
: dht_(dht)
#if OPENDHT_PUSH_NOTIFICATIONS
, pushServer_(pushServer)
#endif // OPENDHT_PUSH_NOTIFICATIONS
DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port , const std::string& pushServer)
: dht_(dht) , pushServer_(pushServer)
{
// NOTE in c++14, use make_unique
service_ = std::unique_ptr<restbed::Service>(new restbed::Service());
#if !OPENDHT_PUSH_NOTIFICATIONS
if (not pushServer.empty())
std::cerr << "Push server defined but built OpenDHT built without push notification support" << std::endl;
#endif
server_thread = std::thread([this, port]() {
// Create endpoints
auto resource = std::make_shared<restbed::Resource>();
+19 -12
View File
@@ -21,6 +21,10 @@
#include "dhtrunner.h"
#include "securedht.h"
#if OPENDHT_PROXY_CLIENT
#include "dht_proxy_client.h"
#endif
#ifndef _WIN32
#include <unistd.h>
#else
@@ -92,8 +96,8 @@ DhtRunner::run(const SockAddr& local4, const SockAddr& local6, DhtRunner::Config
#if OPENDHT_PROXY_CLIENT
config_ = config;
enableProxy(not config_.proxy_server.empty());
#endif
enableProxy(not config.proxy_server.empty());
running = true;
if (not config.threaded)
@@ -863,10 +867,10 @@ DhtRunner::activeDht() const
#endif // OPENDHT_PROXY_CLIENT
}
#if OPENDHT_PROXY_CLIENT
void
DhtRunner::enableProxy(bool proxify)
{
#if OPENDHT_PROXY_CLIENT
if (dht_via_proxy_) {
dht_via_proxy_->shutdown({});
}
@@ -908,51 +912,54 @@ DhtRunner::enableProxy(bool proxify)
});
}
}
#else
if (proxify)
std::cerr << "DHT proxy requested but OpenDHT built without proxy support." << std::endl;
#endif
}
#if OPENDHT_PUSH_NOTIFICATIONS
/**
* Updates the push notification device token
*/
void
DhtRunner::setPushNotificationToken(const std::string& token) {
#if OPENDHT_PROXY_CLIENT && OPENDHT_PUSH_NOTIFICATIONS
pushToken_ = token;
if (dht_via_proxy_)
dht_via_proxy_->setPushNotificationToken(token);
#endif
}
#endif // OPENDHT_PUSH_NOTIFICATIONS
#endif // OPENDHT_PROXY_CLIENT
#if OPENDHT_PROXY_SERVER
void
DhtRunner::forwardAllMessages(bool forward)
{
#if OPENDHT_PROXY_SERVER
#if OPENDHT_PROXY_CLIENT
if (dht_via_proxy_)
dht_via_proxy_->forwardAllMessages(forward);
#endif // OPENDHT_PROXY_CLIENT
if (dht_)
dht_->forwardAllMessages(forward);
}
#endif // OPENDHT_PROXY_SERVER
#if OPENDHT_PUSH_NOTIFICATIONS && OPENDHT_PROXY_CLIENT
}
void
DhtRunner::pushNotificationReceived(const std::map<std::string, std::string>& data) const
{
#if OPENDHT_PROXY_CLIENT && OPENDHT_PUSH_NOTIFICATIONS
if (dht_via_proxy_)
dht_via_proxy_->pushNotificationReceived(data);
#endif
}
void
DhtRunner::resubscribe(const unsigned token)
DhtRunner::resubscribe(unsigned token)
{
#if OPENDHT_PROXY_CLIENT && OPENDHT_PUSH_NOTIFICATIONS
if (dht_via_proxy_)
dht_via_proxy_->resubscribe(token);
#endif
}
#endif // OPENDHT_PUSH_NOTIFICATIONS && OPENDHT_PROXY_CLIENT
}