| 290 | */ |
| 291 | |
| 292 | void ClientRunner::receive_message(TcpClient::ConnectionId connection_id, td::BufferSlice query) { |
| 293 | auto magic = get_tl_magic(query); |
| 294 | LOG(DEBUG) << "received message with magic = " << magic; |
| 295 | switch (magic) { |
| 296 | case cocoon_api::client_queryAnswerEx::ID: |
| 297 | case cocoon_api::client_queryAnswerPartEx::ID: |
| 298 | case cocoon_api::client_queryAnswerErrorEx::ID: { |
| 299 | auto R = cocoon::fetch_tl_object<cocoon_api::client_QueryAnswerEx>(std::move(query), true); |
| 300 | if (R.is_error()) { |
| 301 | LOG(ERROR) << "received malformed message from proxy: " << R.move_as_error(); |
| 302 | return; |
| 303 | } |
| 304 | auto obj = R.move_as_ok(); |
| 305 | td::Bits256 request_id; |
| 306 | cocoon_api::downcast_call(*obj, [&](auto &e) { request_id = e.request_id_; }); |
| 307 | auto it = running_queries_.find(request_id); |
| 308 | if (it != running_queries_.end()) { |
| 309 | td::actor::send_closure(it->second, &ClientRunningRequest::process_answer_ex, std::move(obj)); |
| 310 | } |
| 311 | return; |
| 312 | } |
| 313 | case cocoon_api::proxy_signedPayment::ID: { |
| 314 | auto R = cocoon::fetch_tl_object<cocoon_api::proxy_signedPayment>(std::move(query), true); |
| 315 | if (R.is_error()) { |
| 316 | LOG(ERROR) << "received malformed message from proxy: " << R.move_as_error(); |
| 317 | return; |
| 318 | } |
| 319 | auto conn = static_cast<ClientProxyConnection *>(get_connection(connection_id)); |
| 320 | if (conn) { |
| 321 | auto proxy = conn->proxy(); |
| 322 | proxy->process_signed_payment_data(*R.move_as_ok()); |
| 323 | } |
| 324 | return; |
| 325 | } |
| 326 | case cocoon_api::proxy_clientRequestPayment::ID: { |
| 327 | auto R = cocoon::fetch_tl_object<cocoon_api::proxy_clientRequestPayment>(std::move(query), true); |
| 328 | if (R.is_error()) { |
| 329 | LOG(ERROR) << "received malformed message from proxy: " << R.move_as_error(); |
| 330 | return; |
| 331 | } |
| 332 | auto obj = R.move_as_ok(); |
| 333 | auto conn = static_cast<ClientProxyConnection *>(get_connection(connection_id)); |
| 334 | if (conn) { |
| 335 | auto proxy = conn->proxy(); |
| 336 | proxy->update_tokens_used(obj->max_tokens_); |
| 337 | proxy->update_tokens_committed_to_db(obj->db_tokens_); |
| 338 | proxy->process_signed_payment_data(*obj->signed_payment_); |
| 339 | } |
| 340 | return; |
| 341 | } |
| 342 | default: |
| 343 | LOG(ERROR) << "dropping received message: received message with unknown magic " << td::format::as_hex(magic); |
| 344 | return; |
| 345 | }; |
| 346 | } |
| 347 | |
| 348 | void ClientRunner::receive_http_request(http::HttpCallback::RequestType request_type, |
| 349 | std::vector<std::pair<std::string, std::string>> headers, std::string path, |
nothing calls this directly
no test coverage detected