Drop session when we have to ignore a packet

GitOrigin-RevId: 2c6cc5bb4a022f0d7701cd8d7f8d3e4530191fc7
This commit is contained in:
Arseny Smirnov 2018-12-07 00:01:55 +03:00
parent c2a873db4b
commit 591bfc542f
2 changed files with 10 additions and 1 deletions

View File

@ -23,7 +23,7 @@ Status MessageIdDuplicateChecker::check(int64 message_id) {
if (saved_message_ids_.size() == MAX_SAVED_MESSAGE_IDS) {
auto oldest_message_id = *saved_message_ids_.begin();
if (message_id < oldest_message_id) {
return Status::Error(1, PSLICE() << "Ignore very old message_id " << tag("oldest message_id", oldest_message_id)
return Status::Error(2, PSLICE() << "Ignore very old message_id " << tag("oldest message_id", oldest_message_id)
<< tag("got message_id", message_id));
}
}

View File

@ -488,6 +488,11 @@ Status SessionConnection::on_slice_packet(const MsgInfo &info, Slice packet) {
// It is an update... I hope.
auto status = auth_data_->check_update(info.message_id);
if (status.is_error()) {
if (status.code() == 2) {
LOG(WARNING) << "Receive too old update: " << status;
callback_->on_session_failed(Status::Error("Receive too old update"));
return status;
}
VLOG(mtproto) << "Skip update " << info.message_id << " from " << get_name() << " created in "
<< (Time::now() - created_at_) << ": " << status;
return Status::OK();
@ -666,6 +671,10 @@ Status SessionConnection::on_raw_packet(const td::mtproto::PacketInfo &info, Buf
LOG(WARNING) << "Packet ignored " << status;
send_ack(info.message_id);
return Status::OK();
} else if (status.code() == 2) {
LOG(WARNING) << "Receive too old packet: " << status;
callback_->on_session_failed(Status::Error("Receive too old packet"));
return status;
} else {
return status;
}