Skip to content

Commit 98f71a9

Browse files
committed
Send empty updates on Session creating to initialize it.
1 parent 42b1b82 commit 98f71a9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

td/mtproto/AuthData.h

+14
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,20 @@ class AuthData {
6767
void set_main_auth_key(AuthKey auth_key) {
6868
main_auth_key_ = std::move(auth_key);
6969
}
70+
7071
void break_main_auth_key() {
7172
main_auth_key_.break_key();
7273
}
74+
7375
const AuthKey &get_main_auth_key() const {
7476
// CHECK(has_main_auth_key());
7577
return main_auth_key_;
7678
}
79+
7780
bool has_main_auth_key() const {
7881
return !main_auth_key_.empty();
7982
}
83+
8084
bool need_main_auth_key() const {
8185
return !has_main_auth_key();
8286
}
@@ -85,12 +89,15 @@ class AuthData {
8589
CHECK(!auth_key.empty());
8690
tmp_auth_key_ = std::move(auth_key);
8791
}
92+
8893
const AuthKey &get_tmp_auth_key() const {
8994
return tmp_auth_key_;
9095
}
96+
9197
bool was_tmp_auth_key() const {
9298
return use_pfs() && !tmp_auth_key_.empty();
9399
}
100+
94101
bool need_tmp_auth_key(double now, double refresh_margin) const {
95102
if (!use_pfs()) {
96103
return false;
@@ -103,12 +110,15 @@ class AuthData {
103110
}
104111
return false;
105112
}
113+
106114
void drop_main_auth_key() {
107115
main_auth_key_ = AuthKey();
108116
}
117+
109118
void drop_tmp_auth_key() {
110119
tmp_auth_key_ = AuthKey();
111120
}
121+
112122
bool has_tmp_auth_key(double now) const {
113123
if (!use_pfs()) {
114124
return false;
@@ -128,6 +138,7 @@ class AuthData {
128138
}
129139
return get_main_auth_key();
130140
}
141+
131142
bool has_auth_key(double now) const {
132143
if (use_pfs()) {
133144
return has_tmp_auth_key(now);
@@ -138,6 +149,7 @@ class AuthData {
138149
bool get_auth_flag() const {
139150
return main_auth_key_.auth_flag();
140151
}
152+
141153
void set_auth_flag(bool auth_flag) {
142154
main_auth_key_.set_auth_flag(auth_flag);
143155
if (!auth_flag) {
@@ -148,6 +160,7 @@ class AuthData {
148160
bool get_bind_flag() const {
149161
return !use_pfs() || tmp_auth_key_.auth_flag();
150162
}
163+
151164
void on_bind() {
152165
CHECK(use_pfs());
153166
tmp_auth_key_.set_auth_flag(true);
@@ -184,6 +197,7 @@ class AuthData {
184197
void set_session_id(uint64 session_id) {
185198
session_id_ = session_id;
186199
}
200+
187201
uint64 get_session_id() const {
188202
CHECK(session_id_ != 0);
189203
return session_id_;

td/telegram/net/SessionProxy.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ class SessionCallback final : public Session::Callback {
4848
void on_failed() final {
4949
send_closure(parent_, &SessionProxy::on_failed);
5050
}
51+
5152
void on_closed() final {
5253
send_closure(parent_, &SessionProxy::on_closed);
5354
}
55+
5456
void request_raw_connection(unique_ptr<mtproto::AuthData> auth_data,
5557
Promise<unique_ptr<mtproto::RawConnection>> promise) final {
5658
send_closure(G()->connection_creator(), &ConnectionCreator::request_raw_connection, dc_id_, allow_media_only_,
@@ -224,7 +226,7 @@ void SessionProxy::open_session(bool force) {
224226
CHECK(session_.empty());
225227
auto dc_id = auth_data_->dc_id();
226228
string name = PSTRING() << "Session" << get_name().substr(Slice("SessionProxy").size());
227-
string hash_string = PSTRING() << name << " " << dc_id.get_raw_id() << " " << allow_media_only_;
229+
string hash_string = PSTRING() << name << ' ' << dc_id.get_raw_id() << ' ' << allow_media_only_;
228230
auto hash = Hash<string>()(hash_string);
229231
int32 raw_dc_id = dc_id.get_raw_id();
230232
int32 int_dc_id = raw_dc_id;
@@ -234,6 +236,10 @@ void SessionProxy::open_session(bool force) {
234236
if (allow_media_only_ && !is_cdn_) {
235237
int_dc_id = -int_dc_id;
236238
}
239+
if (is_main_ && use_pfs_ && !tmp_auth_key_.empty()) {
240+
send_closure_later(G()->td(), &Td::on_update, telegram_api::make_object<telegram_api::updates>(),
241+
tmp_auth_key_.id());
242+
}
237243
session_ = create_actor<Session>(
238244
name,
239245
make_unique<SessionCallback>(actor_shared(this, session_generation_), dc_id, allow_media_only_, is_media_, hash),

0 commit comments

Comments
 (0)