Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2021-12-03 00:40:25 +01:00
commit 9a71c1f0ca
18 changed files with 62 additions and 37 deletions

View File

@ -35,12 +35,14 @@ struct TestActor final : public td::Actor {
td::int32 TestActor::actor_count_;
namespace td {
template <>
class td::ActorTraits<TestActor> {
class ActorTraits<TestActor> {
public:
static constexpr bool need_context = false;
static constexpr bool need_start_up = true;
};
} // namespace td
class CreateActorBench final : public td::Benchmark {
td::ConcurrentScheduler scheduler_;

View File

@ -3737,7 +3737,7 @@ updateChatVideoChat chat_id:int53 video_chat:videoChat = Update;
//@description The value of the default disable_notification parameter, used when a message is sent to the chat, was changed @chat_id Chat identifier @default_disable_notification The new default_disable_notification value
updateChatDefaultDisableNotification chat_id:int53 default_disable_notification:Bool = Update;
//@description Incoming messages were read or number of unread messages has been changed @chat_id Chat identifier @last_read_inbox_message_id Identifier of the last read incoming message @unread_count The number of unread messages left in the chat
//@description Incoming messages were read or the number of unread messages has been changed @chat_id Chat identifier @last_read_inbox_message_id Identifier of the last read incoming message @unread_count The number of unread messages left in the chat
updateChatReadInbox chat_id:int53 last_read_inbox_message_id:int53 unread_count:int32 = Update;
//@description Outgoing messages were read @chat_id Chat identifier @last_read_outbox_message_id Identifier of last read outgoing message
@ -4189,7 +4189,7 @@ getFile file_id:int32 = File;
//@remote_file_id Remote identifier of the file to get @file_type File type; pass null if unknown
getRemoteFile remote_file_id:string file_type:FileType = File;
//@description Loads more chats from a chat list. The loaded chats and their positions in the chat list will be sent through updates. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. Returns a 404 error if all chats has been loaded
//@description Loads more chats from a chat list. The loaded chats and their positions in the chat list will be sent through updates. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. Returns a 404 error if all chats have been loaded
//@chat_list The chat list in which to load chats; pass null to load chats from the main chat list
//@limit The maximum number of chats to be loaded. For optimal performance, the number of loaded chats is chosen by TDLib and can be smaller than the specified limit, even if the end of the list is not reached
loadChats chat_list:ChatList limit:int32 = Ok;
@ -5137,7 +5137,7 @@ setGroupCallParticipantVolumeLevel group_call_id:int32 participant_id:MessageSen
//@is_hand_raised Pass true if the user's hand needs to be raised. Only self hand can be raised. Requires groupCall.can_be_managed group call flag to lower other's hand
toggleGroupCallParticipantIsHandRaised group_call_id:int32 participant_id:MessageSender is_hand_raised:Bool = Ok;
//@description Loads more participants of a group call. The loaded participants will be received through updates. Use the field groupCall.loaded_all_participants to check whether all participants has already been loaded
//@description Loads more participants of a group call. The loaded participants will be received through updates. Use the field groupCall.loaded_all_participants to check whether all participants have already been loaded
//@group_call_id Group call identifier. The group call must be previously received through getGroupCall and must be joined or being joined
//@limit The maximum number of participants to load; up to 100
loadGroupCallParticipants group_call_id:int32 limit:int32 = Ok;

View File

@ -16,7 +16,7 @@ struct PacketInfo {
enum { Common, EndToEnd } type = Common;
uint64 auth_key_id{0};
uint32 message_ack{0};
UInt128 message_key{};
UInt128 message_key;
uint64 salt{0};
uint64 session_id{0};

View File

@ -193,7 +193,7 @@ class ObfuscatedTransport final : public IStreamTransport {
// TODO: use ByteFlow?
// One problem is that BufferedFd owns output_buffer_
// The other problem is that first 56 bytes must be sent unencrypted.
UInt256 output_key_{};
UInt256 output_key_;
AesCtrState output_state_;
ChainBufferWriter *output_ = nullptr;

View File

@ -189,7 +189,7 @@ FileId AnimationsManager::on_get_animation(unique_ptr<Animation> new_animation,
a->file_name = std::move(new_animation->file_name);
}
if (a->dimensions != new_animation->dimensions) {
LOG(DEBUG) << "Animation " << file_id << " dimensions has changed";
LOG(DEBUG) << "Animation " << file_id << " dimensions have changed";
a->dimensions = new_animation->dimensions;
}
if (a->duration != new_animation->duration) {
@ -523,7 +523,7 @@ void AnimationsManager::reload_saved_animations(bool force) {
void AnimationsManager::repair_saved_animations(Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(400, "Bots has no saved animations"));
return promise.set_error(Status::Error(400, "Bots have no saved animations"));
}
repair_saved_animations_queries_.push_back(std::move(promise));

View File

@ -62,6 +62,7 @@ AuthManager::AuthManager(int32 api_id, const string &api_hash, ActorShared<> par
LOG(WARNING) << "Continue to log out";
update_state(State::LoggingOut);
} else if (auth_str == "destroy") {
LOG(WARNING) << "Continue to destroy auth keys";
update_state(State::DestroyingKeys);
} else {
if (!load_state()) {
@ -74,7 +75,8 @@ void AuthManager::start_up() {
if (state_ == State::LoggingOut) {
send_log_out_query();
} else if (state_ == State::DestroyingKeys) {
destroy_auth_keys();
G()->net_query_dispatcher().destroy_auth_keys(
PromiseCreator::lambda([](Unit) { send_closure_later(G()->td(), &Td::destroy); }, PromiseCreator::Ignore()));
}
}
void AuthManager::tear_down() {

View File

@ -174,8 +174,8 @@ void FileReferenceManager::merge(NodeId to_node_id, NodeId from_node_id) {
auto &from = from_it->second;
VLOG(file_references) << "Merge " << to.file_source_ids.size() << " and " << from.file_source_ids.size()
<< " sources of files " << to_node_id << " and " << from_node_id;
CHECK(!to.query || to.query->proxy.empty());
CHECK(!from.query || from.query->proxy.empty());
CHECK(!to.query || to.query->proxy.is_empty());
CHECK(!from.query || from.query->proxy.is_empty());
if (to.query || from.query) {
if (!to.query) {
to.query = make_unique<Query>();
@ -184,7 +184,7 @@ void FileReferenceManager::merge(NodeId to_node_id, NodeId from_node_id) {
if (from.query) {
combine(to.query->promises, std::move(from.query->promises));
to.query->active_queries += from.query->active_queries;
from.query->proxy = {to_node_id, to.query->generation};
from.query->proxy = Destination(to_node_id, to.query->generation);
}
}
to.file_source_ids.merge(std::move(from.file_source_ids));
@ -226,7 +226,7 @@ void FileReferenceManager::run_node(NodeId node_id) {
return;
}
auto file_source_id = node.file_source_ids.next();
send_query({node_id, node.query->generation}, file_source_id);
send_query(Destination(node_id, node.query->generation), file_source_id);
}
void FileReferenceManager::send_query(Destination dest, FileSourceId file_source_id) {
@ -326,7 +326,7 @@ FileReferenceManager::Destination FileReferenceManager::on_query_result(Destinat
query->active_queries--;
CHECK(query->active_queries >= 0);
if (!query->proxy.empty()) {
if (!query->proxy.is_empty()) {
query->active_queries -= sub;
CHECK(query->active_queries >= 0);
auto new_proxy = on_query_result(query->proxy, file_source_id, std::move(status), query->active_queries);

View File

@ -78,11 +78,15 @@ class FileReferenceManager final : public Actor {
private:
struct Destination {
bool empty() const {
return node_id.empty();
}
NodeId node_id;
int64 generation{0};
Destination() = default;
Destination(NodeId node_id, int64 generation) : node_id(node_id), generation(generation) {
}
bool is_empty() const {
return node_id.empty();
}
};
struct Query {
std::vector<Promise<>> promises;

View File

@ -2996,7 +2996,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
if (need_message_changed_warning && need_message_text_changed_warning(old_, new_) &&
old_->text.entities.size() <= MAX_CUSTOM_ENTITIES_COUNT &&
need_message_entities_changed_warning(old_->text.entities, new_->text.entities)) {
LOG(WARNING) << "Entities has changed in " << get_content_object(old_content) << ". New content is "
LOG(WARNING) << "Entities have changed in " << get_content_object(old_content) << ". New content is "
<< get_content_object(new_content);
}
need_update = true;

View File

@ -667,17 +667,17 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
int32 limit = min(query.limit, static_cast<int32>(message_ids.size()));
double delta = static_cast<double>(message_ids.size()) / limit;
vector<MessagesDbMessagePosition> positions;
positions.reserve(limit);
MessagesDbMessagePositions positions;
positions.total_count = static_cast<int32>(message_ids.size());
positions.positions.reserve(limit);
for (int32 i = 0; i < limit; i++) {
auto position = static_cast<int32>((i + 0.5) * delta);
auto message_id = message_ids[position];
TRY_RESULT(message, get_message({query.dialog_id, message_id}));
auto date = get_message_info(message).second;
positions.push_back(MessagesDbMessagePosition{position, date, message_id});
positions.positions.push_back(MessagesDbMessagePosition{position, date, message_id});
}
return MessagesDbMessagePositions{static_cast<int32>(message_ids.size()), std::move(positions)};
return positions;
}
Result<vector<MessagesDbDialogMessage>> get_messages(MessagesDbMessagesQuery query) final {

View File

@ -66,8 +66,8 @@ struct MessagesDbGetDialogSparseMessagePositionsQuery {
};
struct MessagesDbMessagePosition {
int32 position{0};
int32 date{0};
int32 position;
int32 date;
MessageId message_id;
};

View File

@ -27911,7 +27911,7 @@ vector<Notification> MessagesManager::get_message_notifications_from_database_fo
bool is_correct = true;
if (notification_id.get() >= from_notification_id.get()) {
// possible if two messages has the same notification_id
// possible if two messages have the same notification_id
LOG(ERROR) << "Have nonmonotonic notification identifiers: " << d->dialog_id << " " << m->message_id << " "
<< notification_id << " " << from_message_id << " " << from_notification_id;
is_correct = false;
@ -35045,7 +35045,9 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
}
auto folder_ptr = get_dialog_folder(d->folder_id);
CHECK(folder_ptr != nullptr);
LOG_CHECK(folder_ptr != nullptr) << is_inited_ << ' ' << G()->close_flag() << ' ' << dialog_id << ' ' << d->folder_id
<< ' ' << is_loaded_from_database << ' ' << td_->auth_manager_->is_authorized()
<< ' ' << td_->auth_manager_->was_authorized() << ' ' << source;
auto &folder = *folder_ptr;
if (old_date == new_date) {
if (new_order == DEFAULT_ORDER) {

View File

@ -2047,7 +2047,7 @@ FileId StickersManager::on_get_sticker(unique_ptr<Sticker> new_sticker, bool rep
} else if (replace) {
CHECK(s->file_id == file_id);
if (s->dimensions != new_sticker->dimensions && new_sticker->dimensions.width != 0) {
LOG(DEBUG) << "Sticker " << file_id << " dimensions has changed";
LOG(DEBUG) << "Sticker " << file_id << " dimensions have changed";
s->dimensions = new_sticker->dimensions;
}
if (s->set_id != new_sticker->set_id && new_sticker->set_id.is_valid()) {
@ -6131,7 +6131,7 @@ void StickersManager::reload_recent_stickers(bool is_attached, bool force) {
void StickersManager::repair_recent_stickers(bool is_attached, Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(400, "Bots has no recent stickers"));
return promise.set_error(Status::Error(400, "Bots have no recent stickers"));
}
repair_recent_stickers_queries_[is_attached].push_back(std::move(promise));
@ -6536,7 +6536,7 @@ void StickersManager::reload_favorite_stickers(bool force) {
void StickersManager::repair_favorite_stickers(Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
return promise.set_error(Status::Error(400, "Bots has no favorite stickers"));
return promise.set_error(Status::Error(400, "Bots have no favorite stickers"));
}
repair_favorite_stickers_queries_.push_back(std::move(promise));

View File

@ -127,7 +127,7 @@ void PhotoRemoteFileLocation::AsKey::store(StorerT &storer) const {
storer.store_slice(unique);
break;
case PhotoSizeSource::Type::StickerSetThumbnailVersion: // 13 bytes
// sticker set thumbnails has no photo_id or document_id
// sticker set thumbnails have no photo_id or document_id
storer.store_slice(unique);
break;
default:

View File

@ -47,7 +47,7 @@ class FileUploader final : public FileLoader {
FileType file_type_ = FileType::Temp;
std::vector<UInt256> iv_map_;
UInt256 iv_{};
UInt256 iv_;
string generate_iv_;
int64 generate_offset_ = 0;
int64 next_offset_ = 0;

View File

@ -201,6 +201,10 @@ void Session::start_up() {
send_closure(session_, &Session::on_online, online_flag);
return session_.is_alive();
}
bool on_logging_out(bool logging_out_flag) final {
send_closure(session_, &Session::on_logging_out, logging_out_flag);
return session_.is_alive();
}
private:
ActorId<Session> session_;
@ -235,9 +239,15 @@ void Session::on_online(bool online_flag) {
loop();
}
void Session::on_logging_out(bool logging_out_flag) {
logging_out_flag_ = logging_out_flag;
connection_online_update(true);
loop();
}
void Session::connection_online_update(bool force) {
bool new_connection_online_flag =
online_flag_ && (has_queries() || last_activity_timestamp_ + 10 > Time::now_cached() || is_main_);
bool new_connection_online_flag = (online_flag_ || logging_out_flag_) &&
(has_queries() || last_activity_timestamp_ + 10 > Time::now_cached() || is_main_);
if (connection_online_flag_ == new_connection_online_flag && !force) {
return;
}

View File

@ -69,9 +69,9 @@ class Session final
Session(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, int32 raw_dc_id, int32 dc_id,
bool is_main, bool use_pfs, bool is_cdn, bool need_destroy, const mtproto::AuthKey &tmp_auth_key,
const vector<mtproto::ServerSalt> &server_salts);
void send(NetQueryPtr &&query);
void on_network(bool network_flag, uint32 network_generation);
void on_online(bool online_flag);
void close();
private:
@ -111,6 +111,7 @@ class Session final
bool was_on_network_ = false;
bool network_flag_ = false;
bool online_flag_ = false;
bool logging_out_flag_ = false;
bool connection_online_flag_ = false;
uint32 network_generation_ = 0;
uint64 being_binded_tmp_auth_key_id_ = 0;
@ -195,6 +196,10 @@ class Session final
Status on_pong() final;
void on_network(bool network_flag, uint32 network_generation);
void on_online(bool online_flag);
void on_logging_out(bool logging_out_flag);
void on_auth_key_updated() final;
void on_tmp_auth_key_updated() final;
void on_server_salt_updated() final;

View File

@ -134,7 +134,7 @@ class Binlog {
// AesCtrEncryption
BufferSlice aes_ctr_key_salt_;
UInt256 aes_ctr_key_{};
UInt256 aes_ctr_key_;
AesCtrState aes_ctr_state_;
bool byte_flow_flag_ = false;