From 99805b7db6d69e64dc1d16697d5cc9ee8d96009c Mon Sep 17 00:00:00 2001 From: Infactum Date: Fri, 10 Dec 2021 15:22:19 +0300 Subject: [PATCH] TDLib update to 1.7.10 (#52) TDLib update to 1.7.10 --- CMakeLists.txt | 2 +- buildenv/Dockerfile.bionic | 3 ++- buildenv/Dockerfile.centos7 | 6 +++-- buildenv/tdlib_header.patch | 10 ++++---- tg2sip/gateway.cpp | 47 +++++++++++++++++++++++++++---------- tg2sip/gateway.h | 8 +++---- 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53972ae..8507dbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ add_subdirectory(libtgvoip) find_package(PkgConfig REQUIRED) find_package(Threads REQUIRED) -find_package(Td 1.6.0 REQUIRED) +find_package(Td 1.7.10 REQUIRED) find_package(spdlog 0.17 REQUIRED) pkg_check_modules(PJSIP libpjproject>=2.8 REQUIRED) pkg_check_modules(OPUS opus REQUIRED) diff --git a/buildenv/Dockerfile.bionic b/buildenv/Dockerfile.bionic index 480e682..2028f7a 100644 --- a/buildenv/Dockerfile.bionic +++ b/buildenv/Dockerfile.bionic @@ -14,9 +14,10 @@ RUN wget https://cmake.org/files/v3.18/cmake-3.18.0-Linux-x86_64.sh \ COPY tdlib_header.patch / COPY tdlib_threadname.patch / +# TDLib 1.7.10 RUN git clone https://github.com/tdlib/td.git \ && cd td \ - && git reset --hard v1.6.0 \ + && git reset --hard a53cb30e99f937cfd64e0266fa558785a184a553 \ && git apply /tdlib_header.patch \ && git apply /tdlib_threadname.patch \ && mkdir build \ diff --git a/buildenv/Dockerfile.centos7 b/buildenv/Dockerfile.centos7 index ae847e2..88562ca 100644 --- a/buildenv/Dockerfile.centos7 +++ b/buildenv/Dockerfile.centos7 @@ -20,10 +20,11 @@ RUN wget https://cmake.org/files/v3.18/cmake-3.18.0-Linux-x86_64.sh \ COPY tdlib_header.patch / COPY tdlib_threadname.patch / +# TDLib 1.7.10 RUN source /opt/rh/devtoolset-7/enable \ && git clone https://github.com/tdlib/td.git \ && cd td \ - && git reset --hard v1.6.0 \ + && git reset --hard a53cb30e99f937cfd64e0266fa558785a184a553 \ && git apply /tdlib_header.patch \ && git apply /tdlib_threadname.patch \ && mkdir build \ @@ -57,9 +58,10 @@ RUN source /opt/rh/devtoolset-7/enable \ && rm -rf spdlog RUN source /opt/rh/devtoolset-7/enable \ - && git clone --recursive https://github.com/linuxdeploy/linuxdeploy.git \ + && git clone https://github.com/linuxdeploy/linuxdeploy.git \ && cd linuxdeploy \ && git checkout 557bad2241df2c33972c7e6bdbf0c528cee27cc8 \ + && git submodule update --init --recursive \ && mkdir build \ && cd build \ && export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig && cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_CIMG=0 .. \ diff --git a/buildenv/tdlib_header.patch b/buildenv/tdlib_header.patch index 0f74916..79cdaf1 100644 --- a/buildenv/tdlib_header.patch +++ b/buildenv/tdlib_header.patch @@ -1,8 +1,8 @@ diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp -index eafec324..3cce46f5 100644 +index 0cbcde9c..50e05ffa 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp -@@ -4899,10 +4899,10 @@ Status Td::set_parameters(td_api::object_ptr parameters +@@ -4419,10 +4419,10 @@ Status Td::set_parameters(td_api::object_ptr parameters if (options_.application_version.empty()) { return Status::Error(400, "Application version must be non-empty"); } @@ -14,6 +14,6 @@ index eafec324..3cce46f5 100644 + // options_.application_version += ", TDLib "; + // options_.application_version += TDLIB_VERSION; + // } - options_.language_pack = ""; - options_.language_code = ""; - options_.parameters = ""; + options_.language_pack = string(); + options_.language_code = string(); + options_.parameters = string(); diff --git a/tg2sip/gateway.cpp b/tg2sip/gateway.cpp index bf32e03..0e79fcb 100755 --- a/tg2sip/gateway.cpp +++ b/tg2sip/gateway.cpp @@ -25,6 +25,15 @@ namespace td_api = td::td_api; volatile sig_atomic_t e_flag = 0; +namespace { + vector voip_library_versions() { + // actually we want to provide real tgvoip version from + // tgvoip::VoIPController::GetVersion() + // but telegram servers accepts only this one + return vector{"2.4.4"}; + } +} + namespace state_machine::guards { bool IsIncoming::operator()(const td::td_api::object_ptr &event) const { return !event->call_->is_outgoing_; @@ -108,6 +117,7 @@ namespace state_machine::actions { ctx.tg_call_id, /* call_id_ */ false, /* is_disconnected_ */ 0, /* duration_ */ + false, /* is_video_ */ ctx.tg_call_id /*connection_id */ )).get(); @@ -211,7 +221,8 @@ namespace state_machine::actions { td_api::make_object(settings.udp_p2p(), settings.udp_reflector(), CALL_PROTO_MIN_LAYER, - tgvoip::VoIPController::GetConnectionMaxLayer()) + tgvoip::VoIPController::GetConnectionMaxLayer(), + voip_library_versions()) )).get(); if (response->get_id() == td_api::error::ID) { @@ -337,13 +348,18 @@ namespace state_machine::actions { voip_controller->SetEncryptionKey(encryption_key, event->call_->is_outgoing_); vector endpoints; - for (const auto &connection : state.connections_) { + for (const auto &server : state.servers_) { + if (server->type_->get_id() != td_api::callServerTypeTelegramReflector::ID) + continue; + + auto reflector = static_cast(server->type_.get()); + unsigned char peer_tag[16]; - memcpy(peer_tag, connection->peer_tag_.c_str(), 16); - auto ipv4 = IPv4Address(connection->ip_); - auto ipv6 = IPv6Address(connection->ipv6_); - endpoints.emplace_back(Endpoint(connection->id_, - static_cast(connection->port_), + memcpy(peer_tag, reflector->peer_tag_.c_str(), 16); + auto ipv4 = IPv4Address(server->ip_address_); + auto ipv6 = IPv6Address(server->ipv6_address_); + endpoints.emplace_back(Endpoint(server->id_, + static_cast(server->port_), ipv4, ipv6, Endpoint::UDP_RELAY, @@ -419,12 +435,14 @@ namespace state_machine::actions { } } - void DialTg::dial_by_id(int32_t id) { + void DialTg::dial_by_id(int64_t id) { auto response = tg_client_->send_query_async(td_api::make_object( id /* id */, td_api::make_object(settings_->udp_p2p(), settings_->udp_reflector(), CALL_PROTO_MIN_LAYER, - tgvoip::VoIPController::GetConnectionMaxLayer())) + tgvoip::VoIPController::GetConnectionMaxLayer(), + voip_library_versions()), + false /* is_video_ */) ).get(); if (response->get_id() == td_api::error::ID) { @@ -535,7 +553,7 @@ namespace state_machine::actions { return; } - auto id = static_cast(chat->id_); + auto id = chat->id_; DEBUG(logger_, "[{}] adding id {} for {} to username cache", ctx_->id(), id, ctx_->ext_username); cache_->username_cache.emplace(ctx_->ext_username, id); dial_by_id(id); @@ -835,15 +853,20 @@ void Gateway::process_event(td::td_api::object_ptr updat void Gateway::process_event(td::td_api::object_ptr update_message) { + auto &sender = update_message->message_->sender_id_; + if (sender->get_id() == td_api::messageSenderUser::ID) + return; + auto user = static_cast(sender.get()); + std::vector matches; for (auto bridge : bridges) { - if (bridge->ctx->user_id == update_message->message_->sender_user_id_) { + if (bridge->ctx->user_id == user->user_id_) { matches.emplace_back(bridge); } } if (matches.size() > 1) { - logger_->error("ambiguous message from {}", update_message->message_->sender_user_id_); + logger_->error("ambiguous message from {}", user->user_id_); return; } else if (matches.size() == 1) { TRACE(logger_, "routing message to ctx {}", matches[0]->ctx->id()); diff --git a/tg2sip/gateway.h b/tg2sip/gateway.h index a6ad5df..5c01a99 100755 --- a/tg2sip/gateway.h +++ b/tg2sip/gateway.h @@ -170,7 +170,7 @@ namespace state_machine::actions { void parse_error(td::td_api::object_ptr error); - void dial_by_id(int32_t id); + void dial_by_id(int64_t id); void dial_by_phone(); @@ -226,8 +226,8 @@ namespace state_machine { } struct Cache { - std::map username_cache; - std::map phone_cache; + std::map username_cache; + std::map phone_cache; }; class Context { @@ -242,7 +242,7 @@ public: std::string ext_phone; std::string ext_username; - int32_t user_id{0}; + int64_t user_id{0}; pj::CallOpParam hangup_prm;