Skip to content

Commit

Permalink
TDLib update to 1.7.10 (#52)
Browse files Browse the repository at this point in the history
TDLib update to 1.7.10
  • Loading branch information
Infactum authored Dec 10, 2021
1 parent 6e08102 commit 99805b7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion buildenv/Dockerfile.bionic
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 4 additions & 2 deletions buildenv/Dockerfile.centos7
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 .. \
Expand Down
10 changes: 5 additions & 5 deletions buildenv/tdlib_header.patch
Original file line number Diff line number Diff line change
@@ -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<td_api::tdlibParameters> parameters
@@ -4419,10 +4419,10 @@ Status Td::set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters
if (options_.application_version.empty()) {
return Status::Error(400, "Application version must be non-empty");
}
Expand All @@ -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();
47 changes: 35 additions & 12 deletions tg2sip/gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ namespace td_api = td::td_api;

volatile sig_atomic_t e_flag = 0;

namespace {
vector<string> voip_library_versions() {
// actually we want to provide real tgvoip version from
// tgvoip::VoIPController::GetVersion()
// but telegram servers accepts only this one
return vector<string>{"2.4.4"};
}
}

namespace state_machine::guards {
bool IsIncoming::operator()(const td::td_api::object_ptr<td::td_api::updateCall> &event) const {
return !event->call_->is_outgoing_;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -211,7 +221,8 @@ namespace state_machine::actions {
td_api::make_object<td_api::callProtocol>(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) {
Expand Down Expand Up @@ -337,13 +348,18 @@ namespace state_machine::actions {
voip_controller->SetEncryptionKey(encryption_key, event->call_->is_outgoing_);

vector<Endpoint> 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<const td_api::callServerTypeTelegramReflector *>(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<uint16_t>(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<uint16_t>(server->port_),
ipv4,
ipv6,
Endpoint::UDP_RELAY,
Expand Down Expand Up @@ -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<td_api::createCall>(
id /* id */,
td_api::make_object<td_api::callProtocol>(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) {
Expand Down Expand Up @@ -535,7 +553,7 @@ namespace state_machine::actions {
return;
}

auto id = static_cast<int32_t>(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);
Expand Down Expand Up @@ -835,15 +853,20 @@ void Gateway::process_event(td::td_api::object_ptr<td::td_api::updateCall> updat

void Gateway::process_event(td::td_api::object_ptr<td::td_api::updateNewMessage> update_message) {

auto &sender = update_message->message_->sender_id_;
if (sender->get_id() == td_api::messageSenderUser::ID)
return;
auto user = static_cast<const td_api::messageSenderUser *>(sender.get());

std::vector<Bridge *> 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());
Expand Down
8 changes: 4 additions & 4 deletions tg2sip/gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace state_machine::actions {

void parse_error(td::td_api::object_ptr<td::td_api::error> error);

void dial_by_id(int32_t id);
void dial_by_id(int64_t id);

void dial_by_phone();

Expand Down Expand Up @@ -226,8 +226,8 @@ namespace state_machine {
}

struct Cache {
std::map<std::string, int32_t> username_cache;
std::map<std::string, int32_t> phone_cache;
std::map<std::string, int64_t> username_cache;
std::map<std::string, int64_t> phone_cache;
};

class Context {
Expand All @@ -242,7 +242,7 @@ class Context {

std::string ext_phone;
std::string ext_username;
int32_t user_id{0};
int64_t user_id{0};

pj::CallOpParam hangup_prm;

Expand Down

0 comments on commit 99805b7

Please sign in to comment.