MCPcopy Create free account
hub / github.com/TelegramMessenger/cocoon / outbound_connection_ready

Method outbound_connection_ready

runners/BaseRunner.cpp:586–646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

584}
585
586void BaseRunner::outbound_connection_ready(TcpClient::ConnectionId connection_id, TcpClient::TargetId target_id,
587 const RemoteAppType &remote_app_type, const td::Bits256 &remote_app_hash,
588 const td::Bits256 &verified_by) {
589 LOG(INFO) << "outbound connection ready: connection_id=" << connection_id << " target_id=" << target_id;
590
591 if (remote_app_type == remote_app_type_key_manager()) {
592 if (check_image_hashes()) {
593 if (!runner_config_ || !runner_config_->root_contract_config) {
594 fail_connection(connection_id, td::Status::Error("cannot verify key manager connection"));
595 return;
596 }
597 if (runner_config_->root_contract_config->key_manager_image_hash() != remote_app_hash) {
598 fail_connection(connection_id, td::Status::Error("wrong key manager image hash"));
599 return;
600 }
601 }
602 {
603 auto S = check_verification_key(remote_app_type, verified_by);
604 if (S.is_error()) {
605 return fail_connection(connection_id, std::move(S));
606 }
607 }
608
609 if (target_id != key_manager_socket_id_) {
610 fail_connection(connection_id, td::Status::Error("wrong key manager target id"));
611 return;
612 }
613
614 if (key_manager_connection_id_ > 0) {
615 fail_connection(key_manager_connection_id_, td::Status::Error("created newer connection"));
616 }
617
618 key_manager_connection_id_ = connection_id;
619 auto conn = std::make_unique<KeyManagerOutboundConnection>(this, remote_app_type, remote_app_hash, verified_by,
620 connection_id, role_);
621
622 auto it2 = all_connections_.emplace(connection_id, std::move(conn)).first;
623 LOG(DEBUG) << "sending connected to created outbound connection";
624 it2->second->start_up();
625 return;
626 }
627
628 auto it = proxy_targets_.find(target_id);
629 if (it == proxy_targets_.end()) {
630 LOG(INFO) << "failing created outbound connection: unknown proxy target " << target_id;
631 close_connection(connection_id);
632 return;
633 }
634 auto proxy_conn =
635 allocate_proxy_outbound_connection(connection_id, target_id, remote_app_type, remote_app_hash, verified_by);
636 if (!proxy_conn) {
637 LOG(INFO) << "failing created outbound connection: rejected by application";
638 close_connection(connection_id);
639 return;
640 }
641 auto it2 = all_connections_.emplace(connection_id, std::move(proxy_conn)).first;
642
643 LOG(DEBUG) << "sending connected to created outbound connection";

Callers

nothing calls this directly

Calls 3

connectedMethod · 0.80
start_upMethod · 0.45

Tested by

no test coverage detected