diff --git a/c/opendht.cpp b/c/opendht.cpp index 10d0ff443ea8ff3d5055a17e8b44033cd0f6cf51..9a1d7e6a8ae650032b186158e1ae7715eb0841d6 100644 --- a/c/opendht.cpp +++ b/c/opendht.cpp @@ -344,6 +344,7 @@ int dht_runner_run_config(dht_runner* r, in_port_t port, const dht_runner_config config.push_token = conf->push_token ? std::string(conf->push_token) : std::string{}; config.push_topic = conf->push_topic ? std::string(conf->push_topic) : std::string{}; config.push_platform = conf->push_platform ? std::string(conf->push_platform) : std::string{}; + config.proxy_user_agent = conf->proxy_user_agent ? std::string(conf->proxy_user_agent) : std::string{}; config.peer_discovery = conf->peer_discovery; config.peer_publish = conf->peer_publish; diff --git a/c/opendht_c.h b/c/opendht_c.h index 47d14b0ec9c32e020d51cd8f0ca9e1d35eb703ff..dc87ec16ec9cf31c48419fea23d46860b99c85cd 100644 --- a/c/opendht_c.h +++ b/c/opendht_c.h @@ -148,6 +148,7 @@ struct OPENDHT_PUBLIC dht_runner_config { const char* push_token; const char* push_topic; const char* push_platform; + const char* proxy_user_agent; bool peer_discovery; bool peer_publish; dht_certificate* server_ca; diff --git a/include/opendht/dht_proxy_client.h b/include/opendht/dht_proxy_client.h index 626593849f79c1adbcfbc45012bc51a20f4e4f58..0535f1005b8fd30f9692ccc4bd1f1db6c1a0d9ae 100644 --- a/include/opendht/dht_proxy_client.h +++ b/include/opendht/dht_proxy_client.h @@ -53,9 +53,14 @@ public: DhtProxyClient(); explicit DhtProxyClient( - std::shared_ptr<crypto::Certificate> serverCA, crypto::Identity clientIdentity, - std::function<void()> loopSignal, const std::string& serverHost, - const std::string& pushClientId = "", std::shared_ptr<Logger> logger = {}); + std::shared_ptr<crypto::Certificate> serverCA, + crypto::Identity clientIdentity, + std::function<void()> loopSignal, + const std::string& serverHost, + const std::string& pushClientId = "", + const std::string& userAgent = "", + std::shared_ptr<Logger> logger = {} + ); void setHeaderFields(http::Request& request); @@ -354,6 +359,7 @@ private: //std::pair<std::string, std::string> serverHostService_; std::string pushClientId_; std::string pushSessionId_; + std::string userAgent_ {"OpenDHT"}; mutable std::mutex lockCurrentProxyInfos_; NodeStatus statusIpv4_ {NodeStatus::Disconnected}; diff --git a/include/opendht/dhtrunner.h b/include/opendht/dhtrunner.h index 2eac68b948098f1d2615ca752af4a08c0dbb0215..abfec2dbbdcd84760c440ac8e39715d25f3662b4 100644 --- a/include/opendht/dhtrunner.h +++ b/include/opendht/dhtrunner.h @@ -64,6 +64,7 @@ public: std::string push_token {}; std::string push_topic {}; std::string push_platform {}; + std::string proxy_user_agent {}; bool peer_discovery {false}; bool peer_publish {false}; std::shared_ptr<dht::crypto::Certificate> server_ca; diff --git a/python/opendht.pyx b/python/opendht.pyx index 26bac2af388e965e3aaef15ee316b6326c6dfb3f..bc23ae3cdda5f9e4bde009a4a576dfc099e9515e 100644 --- a/python/opendht.pyx +++ b/python/opendht.pyx @@ -500,12 +500,13 @@ cdef class DhtConfig(object): def setRateLimit(self, ssize_t max_req_per_sec, ssize_t max_peer_req_per_sec): self._config.dht_config.node_config.max_req_per_sec = max_req_per_sec self._config.dht_config.node_config.max_peer_req_per_sec = max_peer_req_per_sec - def setProxyInfo(self, str proxy_server, str push_node_id="", str push_token="", str push_topic="", str push_platform="", Certificate server_ca = Certificate()): + def setProxyInfo(self, str proxy_server, str push_node_id="", str push_token="", str push_topic="", str push_platform="", str user_agent="", Certificate server_ca = Certificate()): self._config.proxy_server = proxy_server.encode() self._config.push_node_id = push_node_id.encode() self._config.push_token = push_token.encode() self._config.push_topic = push_topic.encode() self._config.push_platform = push_platform.encode() + self._config.proxy_user_agent = user_agent.encode() self._config.server_ca = server_ca._cert def setPeerDiscovery(self, bool peer_discovery, bool peer_publish): self._config.peer_discovery = peer_discovery diff --git a/python/opendht_cpp.pxd b/python/opendht_cpp.pxd index 7b73f16c1c0053bbf2e4e761d2c10e076acbd0e1..3b88d51dbe66f416d6e55f58800d3819d61d65fe 100644 --- a/python/opendht_cpp.pxd +++ b/python/opendht_cpp.pxd @@ -246,6 +246,7 @@ cdef extern from "opendht/dhtrunner.h" namespace "dht": string push_token string push_topic string push_platform + string proxy_user_agent bool peer_discovery bool peer_publish shared_ptr[Certificate] server_ca diff --git a/rust/src/dhtrunner.rs b/rust/src/dhtrunner.rs index 1292fce5626f96af338f23af080017c7a5f0ea98..687ce82a2647d5b3e43d58d882569e5776dc7ead 100644 --- a/rust/src/dhtrunner.rs +++ b/rust/src/dhtrunner.rs @@ -49,6 +49,7 @@ impl DhtRunnerConfig { push_token: ptr::null(), push_topic: ptr::null(), push_platform: ptr::null(), + proxy_user_agent: ptr::null(), peer_discovery: false, peer_publish: false, server_ca: ptr::null_mut(), @@ -84,6 +85,10 @@ impl DhtRunnerConfig { self.push_platform = CString::new(push_platform).unwrap().into_raw(); } + pub fn set_proxy_user_agent(&mut self, proxy_user_agent: &str) { + self.proxy_user_agent = CString::new(proxy_user_agent).unwrap().into_raw(); + } + pub fn set_identity(&mut self, certificate: Box<DhtCertificate>, privatekey: Box<PrivateKey>) { self.dht_config.id.privatekey = Box::into_raw(privatekey); self.dht_config.id.certificate = Box::into_raw(certificate); diff --git a/rust/src/ffi.rs b/rust/src/ffi.rs index 3ae928c59a9e79879c09a6729c78b32b97857cfd..fb50b03a061b84ee8a2d20a6cbf3c9e486472ccb 100644 --- a/rust/src/ffi.rs +++ b/rust/src/ffi.rs @@ -120,6 +120,7 @@ pub struct DhtRunnerConfig pub push_token: *const c_char, pub push_topic: *const c_char, pub push_platform: *const c_char, + pub proxy_user_agent: *const c_char, pub peer_discovery: bool, pub peer_publish: bool, pub server_ca: *mut DhtCertificate, diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index 314463ef096601d334643b7f0984d0d922d85719..f2dc8c3a4fc8b2b219ca0997e007df675119399c 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -108,11 +108,13 @@ 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, std::shared_ptr<dht::Logger> logger) + const std::string& pushClientId, const std::string& userAgent, std::shared_ptr<dht::Logger> logger) : DhtInterface(logger) , proxyUrl_(serverHost) , clientIdentity_(clientIdentity), serverCertificate_(serverCA) - , pushClientId_(pushClientId), pushSessionId_(getRandomSessionId()) + , pushClientId_(pushClientId) + , pushSessionId_(getRandomSessionId()) + , userAgent_(userAgent) , loopSignal_(signal) , jsonReader_(Json::CharReaderBuilder{}.newCharReader()) { @@ -484,7 +486,7 @@ DhtProxyClient::buildRequest(const std::string& target) request->set_certificate_authority(serverCertificate_); if (clientIdentity_.first and clientIdentity_.second) request->set_identity(clientIdentity_); - request->set_header_field(restinio::http_field_t::user_agent, "RESTinio client"); + request->set_header_field(restinio::http_field_t::user_agent, userAgent_); return request; } diff --git a/src/dhtrunner.cpp b/src/dhtrunner.cpp index b30092c0665ffaf5925b3bc4298376f393c04ce0..439c8c9fc02eded40d916a96062a7be6750861eb 100644 --- a/src/dhtrunner.cpp +++ b/src/dhtrunner.cpp @@ -1120,7 +1120,7 @@ DhtRunner::enableProxy(bool proxify) cv.notify_all(); } }, - config_.proxy_server, config_.push_node_id, logger_); + 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())