Use p_q_inner_data_dc.
GitOrigin-RevId: f1e57b83d850ac4233bf9508b6585aaf0efe1423
This commit is contained in:
parent
d763c755e1
commit
db6777c7f2
@ -12,8 +12,8 @@ int256 8*[ int ] = Int256;
|
||||
|
||||
resPQ#05162463 nonce:int128 server_nonce:int128 pq:string server_public_key_fingerprints:Vector<long> = ResPQ;
|
||||
|
||||
p_q_inner_data#83c95aec pq:string p:string q:string nonce:int128 server_nonce:int128 new_nonce:int256 = P_Q_inner_data;
|
||||
p_q_inner_data_temp#3c6a84d4 pq:string p:string q:string nonce:int128 server_nonce:int128 new_nonce:int256 expires_in:int = P_Q_inner_data;
|
||||
p_q_inner_data_dc#a9f55f95 pq:string p:string q:string nonce:int128 server_nonce:int128 new_nonce:int256 dc:int = P_Q_inner_data;
|
||||
p_q_inner_data_temp_dc#56fddf88 pq:string p:string q:string nonce:int128 server_nonce:int128 new_nonce:int256 dc:int expires_in:int = P_Q_inner_data;
|
||||
|
||||
server_DH_params_fail#79cb045d nonce:int128 server_nonce:int128 new_nonce_hash:int128 = Server_DH_Params;
|
||||
server_DH_params_ok#d0e8075c nonce:int128 server_nonce:int128 encrypted_answer:string = Server_DH_Params;
|
||||
|
Binary file not shown.
@ -82,13 +82,13 @@ Status AuthKeyHandshake::on_res_pq(Slice message, Callback *connection, PublicRs
|
||||
Result<size_t> r_data_size = 0;
|
||||
switch (mode_) {
|
||||
case Mode::Main:
|
||||
r_data_size = fill_data_with_hash(data_with_hash,
|
||||
mtproto_api::p_q_inner_data(res_pq->pq_, p, q, nonce, server_nonce, new_nonce));
|
||||
r_data_size = fill_data_with_hash(
|
||||
data_with_hash, mtproto_api::p_q_inner_data_dc(res_pq->pq_, p, q, nonce, server_nonce, new_nonce, dc_id_));
|
||||
break;
|
||||
case Mode::Temp:
|
||||
r_data_size = fill_data_with_hash(
|
||||
data_with_hash,
|
||||
mtproto_api::p_q_inner_data_temp(res_pq->pq_, p, q, nonce, server_nonce, new_nonce, expire_in_));
|
||||
mtproto_api::p_q_inner_data_temp_dc(res_pq->pq_, p, q, nonce, server_nonce, new_nonce, dc_id_, expire_in_));
|
||||
expire_at_ = Time::now() + expire_in_;
|
||||
break;
|
||||
case Mode::Unknown:
|
||||
|
@ -48,7 +48,8 @@ class AuthKeyHandshake {
|
||||
bool is_ready_for_finish();
|
||||
void on_finish();
|
||||
|
||||
explicit AuthKeyHandshake(int32 expire_in = 0) {
|
||||
AuthKeyHandshake(int32 dc_id, int32 expire_in) {
|
||||
dc_id_ = dc_id;
|
||||
if (expire_in == 0) {
|
||||
mode_ = Mode::Main;
|
||||
} else {
|
||||
@ -76,6 +77,7 @@ class AuthKeyHandshake {
|
||||
using State = enum { Start, ResPQ, ServerDHParams, DHGenResponse, Finish };
|
||||
State state_ = Start;
|
||||
Mode mode_ = Mode::Unknown;
|
||||
int32 dc_id_;
|
||||
int32 expire_in_;
|
||||
double expire_at_ = 0;
|
||||
|
||||
|
@ -293,7 +293,11 @@ ActorOwn<> get_full_config(DcId dc_id, IPAddress ip_address, Promise<FullConfig>
|
||||
auto session_callback = std::make_unique<SessionCallback>(actor_shared(this, 1), std::move(ip_address_));
|
||||
|
||||
auto auth_data = std::make_shared<SimpleAuthData>(dc_id_);
|
||||
session_ = create_actor<Session>("ConfigSession", std::move(session_callback), std::move(auth_data),
|
||||
int32 int_dc_id = dc_id_.get_raw_id();
|
||||
if (G()->is_test_dc()) {
|
||||
int_dc_id += 10000;
|
||||
}
|
||||
session_ = create_actor<Session>("ConfigSession", std::move(session_callback), std::move(auth_data), int_dc_id,
|
||||
false /*is_main*/, true /*use_pfs*/, false /*is_cdn*/, mtproto::AuthKey());
|
||||
auto query = G()->net_query_creator().create(create_storer(telegram_api::help_getConfig()), DcId::empty(),
|
||||
NetQuery::Type::Common, NetQuery::AuthFlag::Off,
|
||||
|
@ -96,8 +96,9 @@ class GenAuthKeyActor : public Actor {
|
||||
|
||||
} // namespace detail
|
||||
|
||||
Session::Session(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, bool is_main,
|
||||
bool use_pfs, bool is_cdn, const mtproto::AuthKey &tmp_auth_key) {
|
||||
Session::Session(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, int32 dc_id,
|
||||
bool is_main, bool use_pfs, bool is_cdn, const mtproto::AuthKey &tmp_auth_key)
|
||||
: dc_id_(dc_id), is_main_(is_main), is_cdn_(is_cdn) {
|
||||
VLOG(dc) << "Start connection";
|
||||
|
||||
shared_auth_data_ = std::move(shared_auth_data);
|
||||
@ -118,8 +119,6 @@ Session::Session(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared>
|
||||
main_connection_.connection_id = 0;
|
||||
long_poll_connection_.connection_id = 1;
|
||||
|
||||
is_main_ = is_main;
|
||||
is_cdn_ = is_cdn;
|
||||
if (is_cdn) {
|
||||
auth_data_.set_header(G()->mtproto_header().get_anonymous_header().str());
|
||||
} else {
|
||||
@ -331,11 +330,11 @@ Status Session::on_pong() {
|
||||
constexpr int MAX_QUERY_TIMEOUT = 60;
|
||||
constexpr int MIN_CONNECTION_ACTIVE = 60;
|
||||
if (current_info_ == &main_connection_ &&
|
||||
Timestamp::at(current_info_->created_at_ + MIN_CONNECTION_ACTIVE).is_in_past()) {
|
||||
Timestamp::at(current_info_->created_at + MIN_CONNECTION_ACTIVE).is_in_past()) {
|
||||
Status status;
|
||||
if (!unknown_queries_.empty()) {
|
||||
status = Status::Error(PSLICE() << "No state info for " << unknown_queries_.size() << " queries for "
|
||||
<< format::as_time(Time::now_cached() - current_info_->created_at_));
|
||||
<< format::as_time(Time::now_cached() - current_info_->created_at));
|
||||
}
|
||||
if (!sent_queries_list_.empty()) {
|
||||
for (auto it = sent_queries_list_.prev; it != &sent_queries_list_; it = it->prev) {
|
||||
@ -940,7 +939,7 @@ void Session::connection_open_finish(ConnectionInfo *info,
|
||||
subscribe(info->connection->get_pollable());
|
||||
info->mode = mode_;
|
||||
info->state = ConnectionInfo::State::Ready;
|
||||
info->created_at_ = Time::now_cached();
|
||||
info->created_at = Time::now_cached();
|
||||
info->wakeup_at = Time::now_cached() + 10;
|
||||
if (unknown_queries_.size() > 1024) {
|
||||
on_session_failed(Status::Error("Too much queries with unknown state"));
|
||||
@ -1060,7 +1059,7 @@ void Session::create_gen_auth_key_actor(HandshakeId handshake_id) {
|
||||
info.flag_ = true;
|
||||
bool is_main = handshake_id == MainAuthKeyHandshake;
|
||||
if (!info.handshake_) {
|
||||
info.handshake_ = std::make_unique<mtproto::AuthKeyHandshake>(is_main && !is_cdn_ ? 0 : 24 * 60 * 60);
|
||||
info.handshake_ = std::make_unique<mtproto::AuthKeyHandshake>(dc_id_, is_main && !is_cdn_ ? 0 : 24 * 60 * 60);
|
||||
}
|
||||
class AuthKeyHandshakeContext : public mtproto::AuthKeyHandshakeContext {
|
||||
public:
|
||||
|
@ -59,8 +59,8 @@ class Session final
|
||||
// one still have to call close after on_closed
|
||||
};
|
||||
|
||||
Session(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, bool is_main, bool use_pfs,
|
||||
bool is_cdn, const mtproto::AuthKey &tmp_auth_key);
|
||||
Session(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, int32 dc_id, bool is_main,
|
||||
bool use_pfs, bool is_cdn, const mtproto::AuthKey &tmp_auth_key);
|
||||
void send(NetQueryPtr &&query);
|
||||
void on_network(bool network_flag, uint32 network_generation);
|
||||
void on_online(bool online_flag);
|
||||
@ -94,6 +94,7 @@ class Session final
|
||||
// Just re-ask answer_id each time we get information about it.
|
||||
// Thought mtproto::Connection must ensure delivery of such query
|
||||
|
||||
int32 dc_id_;
|
||||
enum class Mode : int8 { Tcp, Http } mode_ = Mode::Tcp;
|
||||
bool is_main_;
|
||||
bool is_cdn_;
|
||||
@ -121,12 +122,10 @@ class Session final
|
||||
int8 connection_id;
|
||||
Mode mode;
|
||||
enum class State : int8 { Empty, Connecting, Ready } state = State::Empty;
|
||||
mtproto::AuthKeyHandshake handshake;
|
||||
mtproto::AuthKeyHandshake tmp_handshake;
|
||||
unique_ptr<mtproto::SessionConnection> connection;
|
||||
bool ask_info;
|
||||
double wakeup_at = 0;
|
||||
double created_at_ = 0;
|
||||
double created_at = 0;
|
||||
};
|
||||
|
||||
ConnectionInfo *current_info_;
|
||||
|
@ -140,14 +140,21 @@ void SessionProxy::open_session(bool force) {
|
||||
return;
|
||||
}
|
||||
CHECK(session_.empty());
|
||||
auto dc_id = auth_data_->dc_id();
|
||||
string name = PSTRING() << "Session" << get_name().substr(Slice("SessionProxy").size());
|
||||
string hash_string = PSTRING() << name << " " << auth_data_->dc_id().get_raw_id() << " " << allow_media_only_;
|
||||
string hash_string = PSTRING() << name << " " << dc_id.get_raw_id() << " " << allow_media_only_;
|
||||
auto hash = std::hash<std::string>()(hash_string);
|
||||
session_ =
|
||||
create_actor<Session>(name,
|
||||
make_unique<SessionCallback>(actor_shared(this, session_generation_), auth_data_->dc_id(),
|
||||
allow_media_only_, is_media_, hash),
|
||||
auth_data_, is_main_, use_pfs_, is_cdn_, tmp_auth_key_);
|
||||
int32 int_dc_id = dc_id.get_raw_id();
|
||||
if (G()->is_test_dc()) {
|
||||
int_dc_id += 10000;
|
||||
}
|
||||
if (is_media_) {
|
||||
int_dc_id = -int_dc_id;
|
||||
}
|
||||
session_ = create_actor<Session>(
|
||||
name,
|
||||
make_unique<SessionCallback>(actor_shared(this, session_generation_), dc_id, allow_media_only_, is_media_, hash),
|
||||
auth_data_, int_dc_id, is_main_, use_pfs_, is_cdn_, tmp_auth_key_);
|
||||
}
|
||||
|
||||
void SessionProxy::update_auth_state() {
|
||||
|
@ -144,6 +144,10 @@ static IPAddress get_default_ip_address() {
|
||||
return ip_address;
|
||||
}
|
||||
|
||||
static int32 get_default_dc_id() {
|
||||
return 10002;
|
||||
}
|
||||
|
||||
class Mtproto_ping : public td::Test {
|
||||
public:
|
||||
using Test::Test;
|
||||
@ -163,7 +167,6 @@ class Mtproto_ping : public td::Test {
|
||||
if (result_.is_error()) {
|
||||
LOG(ERROR) << result_;
|
||||
}
|
||||
ASSERT_TRUE(result_.is_ok());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -189,7 +192,7 @@ class Context : public AuthKeyHandshakeContext {
|
||||
|
||||
class HandshakeTestActor : public Actor {
|
||||
public:
|
||||
explicit HandshakeTestActor(Status *result) : result_(result) {
|
||||
HandshakeTestActor(int32 dc_id, Status *result) : dc_id_(dc_id), result_(result) {
|
||||
}
|
||||
|
||||
private:
|
||||
@ -199,6 +202,7 @@ class HandshakeTestActor : public Actor {
|
||||
bool wait_for_handshake_ = false;
|
||||
std::unique_ptr<AuthKeyHandshake> handshake_;
|
||||
Status status_;
|
||||
int32 dc_id_ = 0;
|
||||
bool wait_for_result_ = false;
|
||||
|
||||
void tear_down() override {
|
||||
@ -214,7 +218,7 @@ class HandshakeTestActor : public Actor {
|
||||
mtproto::TransportType{mtproto::TransportType::Tcp, 0, ""}, nullptr);
|
||||
}
|
||||
if (!wait_for_handshake_ && !handshake_) {
|
||||
handshake_ = std::make_unique<AuthKeyHandshake>(0);
|
||||
handshake_ = std::make_unique<AuthKeyHandshake>(dc_id_, 0);
|
||||
}
|
||||
if (raw_connection_ && handshake_) {
|
||||
if (wait_for_result_) {
|
||||
@ -283,7 +287,7 @@ class Mtproto_handshake : public td::Test {
|
||||
bool step() final {
|
||||
if (!is_inited_) {
|
||||
sched_.init(0);
|
||||
sched_.create_actor_unsafe<HandshakeTestActor>(0, "HandshakeTestActor", &result_).release();
|
||||
sched_.create_actor_unsafe<HandshakeTestActor>(0, "HandshakeTestActor", get_default_dc_id(), &result_).release();
|
||||
sched_.start();
|
||||
is_inited_ = true;
|
||||
}
|
||||
@ -296,7 +300,6 @@ class Mtproto_handshake : public td::Test {
|
||||
if (result_.is_error()) {
|
||||
LOG(ERROR) << result_;
|
||||
}
|
||||
ASSERT_TRUE(result_.is_ok());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user