Skip to content
Snippets Groups Projects
Commit ead21d24 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Adrien Béraud
Browse files

proxyserver: add application bundle id option

parent 53de63e8
Branches
Tags
No related merge requests found
...@@ -65,6 +65,7 @@ using RequestStatus = restinio::request_handling_status_t; ...@@ -65,6 +65,7 @@ using RequestStatus = restinio::request_handling_status_t;
struct ProxyServerConfig { struct ProxyServerConfig {
in_port_t port {8000}; in_port_t port {8000};
std::string pushServer {}; std::string pushServer {};
std::string bundleId {};
std::string persistStatePath {}; std::string persistStatePath {};
dht::crypto::Identity identity {}; dht::crypto::Identity identity {};
}; };
...@@ -275,6 +276,7 @@ private: ...@@ -275,6 +276,7 @@ private:
#ifdef OPENDHT_PUSH_NOTIFICATIONS #ifdef OPENDHT_PUSH_NOTIFICATIONS
PushType getTypeFromString(const std::string& type); PushType getTypeFromString(const std::string& type);
const std::string& getDefaultTopic(PushType type);
/** /**
* Subscribe to push notifications for an iOS or Android device. * Subscribe to push notifications for an iOS or Android device.
* Method: SUBSCRIBE "/{InfoHash: .*}" * Method: SUBSCRIBE "/{InfoHash: .*}"
...@@ -419,6 +421,7 @@ private: ...@@ -419,6 +421,7 @@ private:
mutable std::atomic<time_point> lastStatsReset_ {time_point::min()}; mutable std::atomic<time_point> lastStatsReset_ {time_point::min()};
std::string pushServer_; std::string pushServer_;
std::string bundleId_;
#ifdef OPENDHT_PUSH_NOTIFICATIONS #ifdef OPENDHT_PUSH_NOTIFICATIONS
struct Listener { struct Listener {
......
...@@ -205,7 +205,8 @@ DhtProxyServer::DhtProxyServer(const std::shared_ptr<DhtRunner>& dht, ...@@ -205,7 +205,8 @@ DhtProxyServer::DhtProxyServer(const std::shared_ptr<DhtRunner>& dht,
dht_(dht), persistPath_(config.persistStatePath), logger_(logger), dht_(dht), persistPath_(config.persistStatePath), logger_(logger),
printStatsTimer_(std::make_unique<asio::steady_timer>(*ioContext_, 3s)), printStatsTimer_(std::make_unique<asio::steady_timer>(*ioContext_, 3s)),
connListener_(std::make_shared<ConnectionListener>(std::bind(&DhtProxyServer::onConnectionClosed, this, std::placeholders::_1))), connListener_(std::make_shared<ConnectionListener>(std::bind(&DhtProxyServer::onConnectionClosed, this, std::placeholders::_1))),
pushServer_(config.pushServer) pushServer_(config.pushServer),
bundleId_(config.bundleId)
{ {
if (not dht_) if (not dht_)
throw std::invalid_argument("A DHT instance must be provided"); throw std::invalid_argument("A DHT instance must be provided");
...@@ -760,6 +761,20 @@ DhtProxyServer::getTypeFromString(const std::string& type) { ...@@ -760,6 +761,20 @@ DhtProxyServer::getTypeFromString(const std::string& type) {
return PushType::None; return PushType::None;
} }
const std::string&
DhtProxyServer::getDefaultTopic(PushType type) {
if (bundleId_.empty()) {
return {};
}
if (type == PushType::iOSLegacy) {
return bundleId_ + ".voip";
}
if (type == PushType::iOS) {
return bundleId_;
}
return {};
}
RequestStatus RequestStatus
DhtProxyServer::subscribe(restinio::request_handle_t request, DhtProxyServer::subscribe(restinio::request_handle_t request,
restinio::router::route_params_t params) restinio::router::route_params_t params)
...@@ -788,6 +803,9 @@ DhtProxyServer::subscribe(restinio::request_handle_t request, ...@@ -788,6 +803,9 @@ DhtProxyServer::subscribe(restinio::request_handle_t request,
} }
auto type = getTypeFromString(root["platform"].asString()); auto type = getTypeFromString(root["platform"].asString());
auto topic = root["topic"].asString(); auto topic = root["topic"].asString();
if (topic.empty()) {
topic = getDefaultTopic(type);
}
auto clientId = root["client_id"].asString(); auto clientId = root["client_id"].asString();
auto sessionId = root["session_id"].asString(); auto sessionId = root["session_id"].asString();
...@@ -1188,6 +1206,9 @@ DhtProxyServer::put(restinio::request_handle_t request, ...@@ -1188,6 +1206,9 @@ DhtProxyServer::put(restinio::request_handle_t request,
pput.pushToken = pushToken; pput.pushToken = pushToken;
pput.clientId = clientId; pput.clientId = clientId;
pput.type = getTypeFromString(platform); pput.type = getTypeFromString(platform);
if (topic.empty()) {
topic = getDefaultTopic(pput.type);
}
pput.topic = topic; pput.topic = topic;
pput.sessionCtx = std::make_shared<PushSessionContext>(sessionId); pput.sessionCtx = std::make_shared<PushSessionContext>(sessionId);
// notify push listen expire // notify push listen expire
......
...@@ -43,7 +43,7 @@ void print_version() { ...@@ -43,7 +43,7 @@ void print_version() {
} }
void print_usage() { void print_usage() {
std::cout << "Usage: dhtnode [-v [-l logfile]] [-i] [-d] [-n network_id] [-p local_port] [-b bootstrap_host[:port]] [--proxyserver local_port] [--proxyserverssl local_port]" << std::endl << std::endl; std::cout << "Usage: dhtnode [-v [-l logfile]] [-i] [-d] [-n network_id] [-p local_port] [-b bootstrap_host[:port]] [--proxyserver local_port] [--proxyserverssl local_port] [--bundleid bundleid]" << std::endl << std::endl;
print_info(); print_info();
} }
...@@ -550,6 +550,7 @@ main(int argc, char **argv) ...@@ -550,6 +550,7 @@ main(int argc, char **argv)
#ifdef OPENDHT_PROXY_SERVER #ifdef OPENDHT_PROXY_SERVER
ProxyServerConfig serverConfig; ProxyServerConfig serverConfig;
serverConfig.pushServer = params.pushserver; serverConfig.pushServer = params.pushserver;
serverConfig.bundleId = params.bundle_id;
if (params.proxyserverssl and params.proxy_id.first and params.proxy_id.second){ if (params.proxyserverssl and params.proxy_id.first and params.proxy_id.second){
serverConfig.identity = params.proxy_id; serverConfig.identity = params.proxy_id;
serverConfig.port = params.proxyserverssl; serverConfig.port = params.proxyserverssl;
......
...@@ -133,6 +133,7 @@ struct dht_params { ...@@ -133,6 +133,7 @@ struct dht_params {
std::string proxyclient {}; std::string proxyclient {};
std::string pushserver {}; std::string pushserver {};
std::string devicekey {}; std::string devicekey {};
std::string bundle_id {};
std::string persist_path {}; std::string persist_path {};
dht::crypto::Identity id {}; dht::crypto::Identity id {};
dht::crypto::Identity proxy_id {}; dht::crypto::Identity proxy_id {};
...@@ -229,6 +230,7 @@ static const constexpr struct option long_options[] = { ...@@ -229,6 +230,7 @@ static const constexpr struct option long_options[] = {
{"proxyclient", required_argument, nullptr, 'C'}, {"proxyclient", required_argument, nullptr, 'C'},
{"pushserver", required_argument, nullptr, 'y'}, {"pushserver", required_argument, nullptr, 'y'},
{"devicekey", required_argument, nullptr, 'z'}, {"devicekey", required_argument, nullptr, 'z'},
{"bundleid", required_argument, nullptr, 'u'},
{"version", no_argument , nullptr, 'V'}, {"version", no_argument , nullptr, 'V'},
{nullptr, 0 , nullptr, 0} {nullptr, 0 , nullptr, 0}
}; };
...@@ -336,6 +338,9 @@ parseArgs(int argc, char **argv) { ...@@ -336,6 +338,9 @@ parseArgs(int argc, char **argv) {
case 'k': case 'k':
privkey = optarg; privkey = optarg;
break; break;
case 'u':
params.bundle_id = optarg;
break;
case 'K': case 'K':
proxy_privkey = optarg; proxy_privkey = optarg;
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment