Skip to content

Commit

Permalink
proxy client: pass push parameters to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
aberaud committed Nov 6, 2024
1 parent 3c62026 commit acd0a23
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
8 changes: 5 additions & 3 deletions include/opendht/dht_proxy_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ class OPENDHT_PUBLIC DhtProxyClient final : public DhtInterface {
crypto::Identity clientIdentity,
std::function<void()> loopSignal,
const std::string& serverHost,
const std::string& pushClientId = "",
const std::string& userAgent = "",
const std::string& pushClientId = "",
const std::string& pushToken = "",
const std::string& pushTopic = "",
const std::string& pushPlatform = "",
std::shared_ptr<Logger> logger = {}
);

Expand Down Expand Up @@ -356,10 +359,9 @@ class OPENDHT_PUBLIC DhtProxyClient final : public DhtInterface {
std::string proxyUrl_;
dht::crypto::Identity clientIdentity_;
std::shared_ptr<dht::crypto::Certificate> serverCertificate_;
//std::pair<std::string, std::string> serverHostService_;
std::string userAgent_ {"OpenDHT"};
std::string pushClientId_;
std::string pushSessionId_;
std::string userAgent_ {"OpenDHT"};

mutable std::mutex lockCurrentProxyInfos_;
NodeStatus statusIpv4_ {NodeStatus::Disconnected};
Expand Down
19 changes: 15 additions & 4 deletions src/dht_proxy_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,26 @@ getRandomSessionId(size_t length = 8) {
DhtProxyClient::DhtProxyClient() {}

DhtProxyClient::DhtProxyClient(
std::shared_ptr<dht::crypto::Certificate> serverCA, dht::crypto::Identity clientIdentity,
std::function<void()> signal, const std::string& serverHost,
const std::string& pushClientId, const std::string& userAgent, std::shared_ptr<dht::Logger> logger)
std::shared_ptr<dht::crypto::Certificate> serverCA,
dht::crypto::Identity clientIdentity,
std::function<void()> signal,
const std::string& serverHost,
const std::string& userAgent,
const std::string& pushClientId,
const std::string& pushToken,
const std::string& pushTopic,
const std::string& pushPlatform,
std::shared_ptr<dht::Logger> logger
)
: DhtInterface(logger)
, proxyUrl_(serverHost)
, clientIdentity_(clientIdentity), serverCertificate_(serverCA)
, userAgent_(userAgent)
, pushClientId_(pushClientId)
, pushSessionId_(getRandomSessionId())
, userAgent_(userAgent)
, deviceKey_(pushToken)
, notificationTopic_(pushTopic)
, platform_(pushPlatform)
, loopSignal_(signal)
, jsonReader_(Json::CharReaderBuilder{}.newCharReader())
{
Expand Down
14 changes: 7 additions & 7 deletions src/dhtrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,13 +1120,13 @@ DhtRunner::enableProxy(bool proxify)
cv.notify_all();
}
},
config_.proxy_server, config_.push_node_id, config_.proxy_user_agent, logger_);
if (not config_.push_token.empty())
dht_via_proxy->setPushNotificationToken(config_.push_token);
if (not config_.push_topic.empty())
dht_via_proxy->setPushNotificationTopic(config_.push_topic);
if (not config_.push_platform.empty())
dht_via_proxy->setPushNotificationPlatform(config_.push_platform);
config_.proxy_server,
config_.proxy_user_agent,
config_.push_node_id,
config_.push_token,
config_.push_topic,
config_.push_platform,
logger_);
dht_ = std::make_unique<SecureDht>(std::move(dht_via_proxy), config_.dht_config, identityAnnouncedCb_, logger_);
// and use it
use_proxy = proxify;
Expand Down

0 comments on commit acd0a23

Please sign in to comment.