diff --git a/include/opendht/dht_proxy_client.h b/include/opendht/dht_proxy_client.h index 3afa8af60dd8ac5d881e472af9f70c0bcd4daf2b..6b9f66558ec4cae0c95087ea2486c29c67129c74 100644 --- a/include/opendht/dht_proxy_client.h +++ b/include/opendht/dht_proxy_client.h @@ -53,9 +53,9 @@ public: DhtProxyClient(); explicit DhtProxyClient( - std::shared_ptr<dht::crypto::Certificate> serverCA, dht::crypto::Identity clientIdentity, + std::shared_ptr<crypto::Certificate> serverCA, crypto::Identity clientIdentity, std::function<void()> loopSignal, const std::string& serverHost, - const std::string& pushClientId = "", std::shared_ptr<dht::Logger> logger = {}); + const std::string& pushClientId = "", std::shared_ptr<Logger> logger = {}); void setHeaderFields(http::Request& request); @@ -404,7 +404,7 @@ private: #endif // OPENDHT_PUSH_NOTIFICATIONS Json::StreamWriterBuilder jsonBuilder_; - Json::CharReaderBuilder jsonReaderBuilder_; + std::unique_ptr<Json::CharReader> jsonReader_; std::shared_ptr<dht::Logger> logger_; std::shared_ptr<http::Request> buildRequest(const std::string& target = {}); diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index db112190e4334bd9bf99fc2c730424a54e5c30dd..3cfb68ae8c7f39767bc6ba4f0a85db577630181a 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -99,16 +99,15 @@ 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) - : - clientIdentity_(clientIdentity), serverCertificate_(serverCA), - pushClientId_(pushClientId), loopSignal_(signal), logger_(logger) + : proxyUrl_(serverHost) + , clientIdentity_(clientIdentity), serverCertificate_(serverCA) + , pushClientId_(pushClientId), loopSignal_(signal) + , jsonReader_(Json::CharReaderBuilder{}.newCharReader()) + , logger_(logger) { - // build http client - proxyUrl_ = serverHost; - jsonBuilder_["commentStyle"] = "None"; jsonBuilder_["indentation"] = ""; - if (logger_){ + if (logger_) { if (serverCertificate_) logger_->d("[proxy:client] using ca certificate for ssl:\n%s", serverCertificate_->toString(false/*chain*/).c_str()); @@ -320,8 +319,7 @@ DhtProxyClient::get(const InfoHash& key, GetCallback cb, DoneCallback donecb, Va std::string err; Json::Value json; const auto& line = b.line(); - auto reader = std::unique_ptr<Json::CharReader>(jsonReaderBuilder_.newCharReader()); - if (!reader->parse(line.data(), line.data() + line.size(), &json, &err)){ + if (!jsonReader_->parse(line.data(), line.data() + line.size(), &json, &err)){ opstate->ok.store(false); return; } @@ -615,8 +613,7 @@ DhtProxyClient::queryProxyInfo(std::shared_ptr<InfoState> infoState, sa_family_t } else { std::string err; Json::Value proxyInfos; - auto reader = std::unique_ptr<Json::CharReader>(jsonReaderBuilder_.newCharReader()); - if (!reader->parse(response.body.data(), response.body.data() + response.body.size(), &proxyInfos, &err)){ + if (!jsonReader_->parse(response.body.data(), response.body.data() + response.body.size(), &proxyInfos, &err)){ onProxyInfos(Json::Value{}, family); return; } @@ -964,8 +961,7 @@ DhtProxyClient::sendListen(const restinio::http_request_header_t header, std::string err; Json::Value json; const auto& line = b.line(); - auto reader = std::unique_ptr<Json::CharReader>(jsonReaderBuilder_.newCharReader()); - if (!reader->parse(line.data(), line.data() + line.size(), &json, &err)){ + if (!jsonReader_->parse(line.data(), line.data() + line.size(), &json, &err)){ opstate->ok.store(false); return; }