Skip to content

Commit 99805b7

Browse files
authored
TDLib update to 1.7.10 (#52)
TDLib update to 1.7.10
1 parent 6e08102 commit 99805b7

File tree

6 files changed

+51
-25
lines changed

6 files changed

+51
-25
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_subdirectory(libtgvoip)
77

88
find_package(PkgConfig REQUIRED)
99
find_package(Threads REQUIRED)
10-
find_package(Td 1.6.0 REQUIRED)
10+
find_package(Td 1.7.10 REQUIRED)
1111
find_package(spdlog 0.17 REQUIRED)
1212
pkg_check_modules(PJSIP libpjproject>=2.8 REQUIRED)
1313
pkg_check_modules(OPUS opus REQUIRED)

buildenv/Dockerfile.bionic

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ RUN wget https://cmake.org/files/v3.18/cmake-3.18.0-Linux-x86_64.sh \
1414
COPY tdlib_header.patch /
1515
COPY tdlib_threadname.patch /
1616

17+
# TDLib 1.7.10
1718
RUN git clone https://github.com/tdlib/td.git \
1819
&& cd td \
19-
&& git reset --hard v1.6.0 \
20+
&& git reset --hard a53cb30e99f937cfd64e0266fa558785a184a553 \
2021
&& git apply /tdlib_header.patch \
2122
&& git apply /tdlib_threadname.patch \
2223
&& mkdir build \

buildenv/Dockerfile.centos7

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ RUN wget https://cmake.org/files/v3.18/cmake-3.18.0-Linux-x86_64.sh \
2020
COPY tdlib_header.patch /
2121
COPY tdlib_threadname.patch /
2222

23+
# TDLib 1.7.10
2324
RUN source /opt/rh/devtoolset-7/enable \
2425
&& git clone https://github.com/tdlib/td.git \
2526
&& cd td \
26-
&& git reset --hard v1.6.0 \
27+
&& git reset --hard a53cb30e99f937cfd64e0266fa558785a184a553 \
2728
&& git apply /tdlib_header.patch \
2829
&& git apply /tdlib_threadname.patch \
2930
&& mkdir build \
@@ -57,9 +58,10 @@ RUN source /opt/rh/devtoolset-7/enable \
5758
&& rm -rf spdlog
5859

5960
RUN source /opt/rh/devtoolset-7/enable \
60-
&& git clone --recursive https://github.com/linuxdeploy/linuxdeploy.git \
61+
&& git clone https://github.com/linuxdeploy/linuxdeploy.git \
6162
&& cd linuxdeploy \
6263
&& git checkout 557bad2241df2c33972c7e6bdbf0c528cee27cc8 \
64+
&& git submodule update --init --recursive \
6365
&& mkdir build \
6466
&& cd build \
6567
&& export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig && cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_CIMG=0 .. \

buildenv/tdlib_header.patch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp
2-
index eafec324..3cce46f5 100644
2+
index 0cbcde9c..50e05ffa 100644
33
--- a/td/telegram/Td.cpp
44
+++ b/td/telegram/Td.cpp
5-
@@ -4899,10 +4899,10 @@ Status Td::set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters
5+
@@ -4419,10 +4419,10 @@ Status Td::set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters
66
if (options_.application_version.empty()) {
77
return Status::Error(400, "Application version must be non-empty");
88
}
@@ -14,6 +14,6 @@ index eafec324..3cce46f5 100644
1414
+ // options_.application_version += ", TDLib ";
1515
+ // options_.application_version += TDLIB_VERSION;
1616
+ // }
17-
options_.language_pack = "";
18-
options_.language_code = "";
19-
options_.parameters = "";
17+
options_.language_pack = string();
18+
options_.language_code = string();
19+
options_.parameters = string();

tg2sip/gateway.cpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ namespace td_api = td::td_api;
2525

2626
volatile sig_atomic_t e_flag = 0;
2727

28+
namespace {
29+
vector<string> voip_library_versions() {
30+
// actually we want to provide real tgvoip version from
31+
// tgvoip::VoIPController::GetVersion()
32+
// but telegram servers accepts only this one
33+
return vector<string>{"2.4.4"};
34+
}
35+
}
36+
2837
namespace state_machine::guards {
2938
bool IsIncoming::operator()(const td::td_api::object_ptr<td::td_api::updateCall> &event) const {
3039
return !event->call_->is_outgoing_;
@@ -108,6 +117,7 @@ namespace state_machine::actions {
108117
ctx.tg_call_id, /* call_id_ */
109118
false, /* is_disconnected_ */
110119
0, /* duration_ */
120+
false, /* is_video_ */
111121
ctx.tg_call_id /*connection_id */
112122
)).get();
113123

@@ -211,7 +221,8 @@ namespace state_machine::actions {
211221
td_api::make_object<td_api::callProtocol>(settings.udp_p2p(),
212222
settings.udp_reflector(),
213223
CALL_PROTO_MIN_LAYER,
214-
tgvoip::VoIPController::GetConnectionMaxLayer())
224+
tgvoip::VoIPController::GetConnectionMaxLayer(),
225+
voip_library_versions())
215226
)).get();
216227

217228
if (response->get_id() == td_api::error::ID) {
@@ -337,13 +348,18 @@ namespace state_machine::actions {
337348
voip_controller->SetEncryptionKey(encryption_key, event->call_->is_outgoing_);
338349

339350
vector<Endpoint> endpoints;
340-
for (const auto &connection : state.connections_) {
351+
for (const auto &server : state.servers_) {
352+
if (server->type_->get_id() != td_api::callServerTypeTelegramReflector::ID)
353+
continue;
354+
355+
auto reflector = static_cast<const td_api::callServerTypeTelegramReflector *>(server->type_.get());
356+
341357
unsigned char peer_tag[16];
342-
memcpy(peer_tag, connection->peer_tag_.c_str(), 16);
343-
auto ipv4 = IPv4Address(connection->ip_);
344-
auto ipv6 = IPv6Address(connection->ipv6_);
345-
endpoints.emplace_back(Endpoint(connection->id_,
346-
static_cast<uint16_t>(connection->port_),
358+
memcpy(peer_tag, reflector->peer_tag_.c_str(), 16);
359+
auto ipv4 = IPv4Address(server->ip_address_);
360+
auto ipv6 = IPv6Address(server->ipv6_address_);
361+
endpoints.emplace_back(Endpoint(server->id_,
362+
static_cast<uint16_t>(server->port_),
347363
ipv4,
348364
ipv6,
349365
Endpoint::UDP_RELAY,
@@ -419,12 +435,14 @@ namespace state_machine::actions {
419435
}
420436
}
421437

422-
void DialTg::dial_by_id(int32_t id) {
438+
void DialTg::dial_by_id(int64_t id) {
423439
auto response = tg_client_->send_query_async(td_api::make_object<td_api::createCall>(
424440
id /* id */,
425441
td_api::make_object<td_api::callProtocol>(settings_->udp_p2p(), settings_->udp_reflector(),
426442
CALL_PROTO_MIN_LAYER,
427-
tgvoip::VoIPController::GetConnectionMaxLayer()))
443+
tgvoip::VoIPController::GetConnectionMaxLayer(),
444+
voip_library_versions()),
445+
false /* is_video_ */)
428446
).get();
429447

430448
if (response->get_id() == td_api::error::ID) {
@@ -535,7 +553,7 @@ namespace state_machine::actions {
535553
return;
536554
}
537555

538-
auto id = static_cast<int32_t>(chat->id_);
556+
auto id = chat->id_;
539557
DEBUG(logger_, "[{}] adding id {} for {} to username cache", ctx_->id(), id, ctx_->ext_username);
540558
cache_->username_cache.emplace(ctx_->ext_username, id);
541559
dial_by_id(id);
@@ -835,15 +853,20 @@ void Gateway::process_event(td::td_api::object_ptr<td::td_api::updateCall> updat
835853

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

856+
auto &sender = update_message->message_->sender_id_;
857+
if (sender->get_id() == td_api::messageSenderUser::ID)
858+
return;
859+
auto user = static_cast<const td_api::messageSenderUser *>(sender.get());
860+
838861
std::vector<Bridge *> matches;
839862
for (auto bridge : bridges) {
840-
if (bridge->ctx->user_id == update_message->message_->sender_user_id_) {
863+
if (bridge->ctx->user_id == user->user_id_) {
841864
matches.emplace_back(bridge);
842865
}
843866
}
844867

845868
if (matches.size() > 1) {
846-
logger_->error("ambiguous message from {}", update_message->message_->sender_user_id_);
869+
logger_->error("ambiguous message from {}", user->user_id_);
847870
return;
848871
} else if (matches.size() == 1) {
849872
TRACE(logger_, "routing message to ctx {}", matches[0]->ctx->id());

tg2sip/gateway.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ namespace state_machine::actions {
170170

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

173-
void dial_by_id(int32_t id);
173+
void dial_by_id(int64_t id);
174174

175175
void dial_by_phone();
176176

@@ -226,8 +226,8 @@ namespace state_machine {
226226
}
227227

228228
struct Cache {
229-
std::map<std::string, int32_t> username_cache;
230-
std::map<std::string, int32_t> phone_cache;
229+
std::map<std::string, int64_t> username_cache;
230+
std::map<std::string, int64_t> phone_cache;
231231
};
232232

233233
class Context {
@@ -242,7 +242,7 @@ class Context {
242242

243243
std::string ext_phone;
244244
std::string ext_username;
245-
int32_t user_id{0};
245+
int64_t user_id{0};
246246

247247
pj::CallOpParam hangup_prm;
248248

0 commit comments

Comments
 (0)