Fix session_id type.

This commit is contained in:
levlam 2023-05-14 23:00:56 +03:00
parent f29774acc6
commit a395337265
6 changed files with 16 additions and 16 deletions

View File

@ -129,10 +129,10 @@ bool AuthData::is_valid_inbound_msg_id(uint64 message_id, double now) const {
return server_time - 300 < id_time && id_time < server_time + 30; return server_time - 300 < id_time && id_time < server_time + 30;
} }
Status AuthData::check_packet(int64 session_id, uint64 message_id, double now, bool &time_difference_was_updated) { Status AuthData::check_packet(uint64 session_id, uint64 message_id, double now, bool &time_difference_was_updated) {
// Client is to check that the session_id field in the decrypted message indeed equals to that of an active session // Client is to check that the session_id field in the decrypted message indeed equals to that of an active session
// created by the client. // created by the client.
if (get_session_id() != static_cast<uint64>(session_id)) { if (get_session_id() != session_id) {
return Status::Error(PSLICE() << "Receive packet from different session " << session_id << " in session " return Status::Error(PSLICE() << "Receive packet from different session " << session_id << " in session "
<< get_session_id()); << get_session_id());
} }

View File

@ -245,7 +245,7 @@ class AuthData {
bool is_valid_inbound_msg_id(uint64 message_id, double now) const; bool is_valid_inbound_msg_id(uint64 message_id, double now) const;
Status check_packet(int64 session_id, uint64 message_id, double now, bool &time_difference_was_updated); Status check_packet(uint64 session_id, uint64 message_id, double now, bool &time_difference_was_updated);
Status check_update(uint64 message_id) { Status check_update(uint64 message_id) {
return updates_duplicate_checker_.check(message_id); return updates_duplicate_checker_.check(message_id);

View File

@ -54,7 +54,7 @@ class RawConnectionDefault final : public RawConnection {
return transport_->get_type(); return transport_->get_type();
} }
size_t send_crypto(const Storer &storer, int64 session_id, int64 salt, const AuthKey &auth_key, size_t send_crypto(const Storer &storer, uint64 session_id, int64 salt, const AuthKey &auth_key,
uint64 quick_ack_token) final { uint64 quick_ack_token) final {
PacketInfo info; PacketInfo info;
info.version = 2; info.version = 2;
@ -299,7 +299,7 @@ class RawConnectionHttp final : public RawConnection {
return mtproto::TransportType{mtproto::TransportType::Http, 0, mtproto::ProxySecret()}; return mtproto::TransportType{mtproto::TransportType::Http, 0, mtproto::ProxySecret()};
} }
size_t send_crypto(const Storer &storer, int64 session_id, int64 salt, const AuthKey &auth_key, size_t send_crypto(const Storer &storer, uint64 session_id, int64 salt, const AuthKey &auth_key,
uint64 quick_ack_token) final { uint64 quick_ack_token) final {
PacketInfo info; PacketInfo info;
info.version = 2; info.version = 2;

View File

@ -48,7 +48,7 @@ class RawConnection {
virtual bool can_send() const = 0; virtual bool can_send() const = 0;
virtual TransportType get_transport_type() const = 0; virtual TransportType get_transport_type() const = 0;
virtual size_t send_crypto(const Storer &storer, int64 session_id, int64 salt, const AuthKey &auth_key, virtual size_t send_crypto(const Storer &storer, uint64 session_id, int64 salt, const AuthKey &auth_key,
uint64 quick_ack_token) = 0; uint64 quick_ack_token) = 0;
virtual uint64 send_no_crypto(const Storer &storer) = 0; virtual uint64 send_no_crypto(const Storer &storer) = 0;

View File

@ -110,20 +110,20 @@ ConnectionCreator::ClientInfo::ClientInfo() {
mtproto_error_flood_control.add_limit(8, 3); mtproto_error_flood_control.add_limit(8, 3);
} }
int64 ConnectionCreator::ClientInfo::extract_session_id() { uint64 ConnectionCreator::ClientInfo::extract_session_id() {
if (!session_ids_.empty()) { if (!session_ids_.empty()) {
auto res = *session_ids_.begin(); auto res = *session_ids_.begin();
session_ids_.erase(session_ids_.begin()); session_ids_.erase(session_ids_.begin());
return res; return res;
} }
int64 res = 0; uint64 res = 0;
while (res == 0) { while (res == 0) {
res = Random::secure_int64(); res = Random::secure_uint64();
} }
return res; return res;
} }
void ConnectionCreator::ClientInfo::add_session_id(int64 session_id) { void ConnectionCreator::ClientInfo::add_session_id(uint64 session_id) {
if (session_id != 0) { if (session_id != 0) {
session_ids_.insert(session_id); session_ids_.insert(session_id);
} }
@ -934,7 +934,7 @@ void ConnectionCreator::client_create_raw_connection(Result<ConnectionData> r_co
string debug_str, uint32 network_generation) { string debug_str, uint32 network_generation) {
unique_ptr<mtproto::AuthData> auth_data; unique_ptr<mtproto::AuthData> auth_data;
uint64 auth_data_generation{0}; uint64 auth_data_generation{0};
int64 session_id{0}; uint64 session_id{0};
if (check_mode) { if (check_mode) {
auto it = clients_.find(hash); auto it = clients_.find(hash);
CHECK(it != clients_.end()); CHECK(it != clients_.end());
@ -992,7 +992,7 @@ void ConnectionCreator::client_set_timeout_at(ClientInfo &client, double wakeup_
} }
void ConnectionCreator::client_add_connection(uint32 hash, Result<unique_ptr<mtproto::RawConnection>> r_raw_connection, void ConnectionCreator::client_add_connection(uint32 hash, Result<unique_ptr<mtproto::RawConnection>> r_raw_connection,
bool check_flag, uint64 auth_data_generation, int64 session_id) { bool check_flag, uint64 auth_data_generation, uint64 session_id) {
auto &client = clients_[hash]; auto &client = clients_[hash];
client.add_session_id(session_id); client.add_session_id(session_id);
CHECK(client.pending_connections > 0); CHECK(client.pending_connections > 0);

View File

@ -142,8 +142,8 @@ class ConnectionCreator final : public NetQueryCallback {
int32 next_delay_ = 1; int32 next_delay_ = 1;
}; };
ClientInfo(); ClientInfo();
int64 extract_session_id(); uint64 extract_session_id();
void add_session_id(int64 session_id); void add_session_id(uint64 session_id);
Backoff backoff; Backoff backoff;
FloodControlStrict sanity_flood_control; FloodControlStrict sanity_flood_control;
@ -163,7 +163,7 @@ class ConnectionCreator final : public NetQueryCallback {
DcId dc_id; DcId dc_id;
bool allow_media_only{false}; bool allow_media_only{false};
bool is_media{false}; bool is_media{false};
std::set<int64> session_ids_; std::set<uint64> session_ids_;
unique_ptr<mtproto::AuthData> auth_data; unique_ptr<mtproto::AuthData> auth_data;
uint64 auth_data_generation{0}; uint64 auth_data_generation{0};
}; };
@ -223,7 +223,7 @@ class ConnectionCreator final : public NetQueryCallback {
mtproto::TransportType transport_type, uint32 hash, string debug_str, mtproto::TransportType transport_type, uint32 hash, string debug_str,
uint32 network_generation); uint32 network_generation);
void client_add_connection(uint32 hash, Result<unique_ptr<mtproto::RawConnection>> r_raw_connection, bool check_flag, void client_add_connection(uint32 hash, Result<unique_ptr<mtproto::RawConnection>> r_raw_connection, bool check_flag,
uint64 auth_data_generation, int64 session_id); uint64 auth_data_generation, uint64 session_id);
void client_set_timeout_at(ClientInfo &client, double wakeup_at); void client_set_timeout_at(ClientInfo &client, double wakeup_at);
void on_proxy_resolved(Result<IPAddress> ip_address, bool dummy); void on_proxy_resolved(Result<IPAddress> ip_address, bool dummy);