diff --git a/include/opendht/dht_proxy_server.h b/include/opendht/dht_proxy_server.h index 31c46916..e49f7077 100644 --- a/include/opendht/dht_proxy_server.h +++ b/include/opendht/dht_proxy_server.h @@ -275,13 +275,13 @@ private: RequestStatus options(restinio::request_handle_t request, restinio::router::route_params_t params); -#ifdef OPENDHT_PUSH_NOTIFICATIONS struct PushSessionContext { std::mutex lock; std::string sessionId; PushSessionContext(const std::string& id) : sessionId(id) {} }; +#ifdef OPENDHT_PUSH_NOTIFICATIONS PushType getTypeFromString(const std::string& type); std::string getDefaultTopic(PushType type); @@ -350,9 +350,9 @@ private: * @param expired A boolean indicating whether the push listen request has expired. * @return true. */ - bool handlePushListen(const InfoHash infoHash, const std::string pushToken, - PushType type, const std::string clientId, - const std::shared_ptr sessionCtx, const std::string topic, + bool handlePushListen(const InfoHash& infoHash, const std::string& pushToken, + PushType type, const std::string& clientId, + const std::shared_ptr& sessionCtx, const std::string& topic, const std::vector>& values, bool expired); #endif //OPENDHT_PUSH_NOTIFICATIONS diff --git a/src/dht_proxy_server.cpp b/src/dht_proxy_server.cpp index 9fb72802..fc97e67c 100644 --- a/src/dht_proxy_server.cpp +++ b/src/dht_proxy_server.cpp @@ -404,10 +404,12 @@ DhtProxyServer::loadState(Is& is, size_t size) { for (auto& listener : listeners.second) { // start listening listener.internalToken = dht_->listen(listeners.first, - std::bind(&DhtProxyServer::handlePushListen, this, - listeners.first, pushListener.first, listener.type, - listener.clientId, listener.sessionCtx, listener.topic, - std::placeholders::_1, std::placeholders::_2)); + [this, infoHash=listeners.first, pushToken=pushListener.first, type=listener.type, + clientId=listener.clientId, sessionCtx = listener.sessionCtx, topic=listener.topic] + (const std::vector>& values, bool expired) { + return this->handlePushListen(infoHash, pushToken, type, clientId, sessionCtx, topic, values, expired); + } + ); // expire notify listener.expireNotifyTimer = std::make_unique(io_context(), listener.expiration - proxy::OP_MARGIN); auto jsonProvider = [infoHash = listeners.first.toString(), clientId = listener.clientId, sessionCtx = listener.sessionCtx](){ @@ -901,10 +903,12 @@ DhtProxyServer::subscribe(restinio::request_handle_t request, // Add listen on dht if (logger_) logger_->d("[proxy:server] [subscribe %s] new", infoHash.toString().c_str()); - listener.internalToken = dht_->listen(infoHash, std::bind(&DhtProxyServer::handlePushListen, this, - infoHash, pushToken, type, clientId, - listener.sessionCtx, topic, - std::placeholders::_1, std::placeholders::_2)); + listener.internalToken = dht_->listen(infoHash, + [this, infoHash, pushToken, type, clientId, sessionCtx = listener.sessionCtx, topic] + (const std::vector>& values, bool expired) { + return this->handlePushListen(infoHash, pushToken, type, clientId, sessionCtx, topic, values, expired); + } + ); // Send response header auto response = initHttpResponse(request->create_response()); response.set_body("{}\n"); @@ -1010,8 +1014,8 @@ DhtProxyServer::handleCancelPushListen(const asio::error_code &ec, const std::st } bool -DhtProxyServer::handlePushListen(const InfoHash infoHash, const std::string pushToken, PushType type, const std::string clientId, - const std::shared_ptr sessionCtx, const std::string topic, +DhtProxyServer::handlePushListen(const InfoHash& infoHash, const std::string& pushToken, PushType type, const std::string& clientId, + const std::shared_ptr& sessionCtx, const std::string& topic, const std::vector>& values, bool expired) { Json::Value json;