diff --git a/benchmark/bench_actor.cpp b/benchmark/bench_actor.cpp index 6f49c7aad..63cc1fca3 100644 --- a/benchmark/bench_actor.cpp +++ b/benchmark/bench_actor.cpp @@ -58,8 +58,7 @@ class RingBench final : public td::Benchmark { } else { // TODO: it is three times faster than send_event // maybe send event could be further optimized? - ::td::Scheduler::instance()->hack(static_cast>(next_actor), - td::Event::raw(static_cast(n - 1))); + next_actor.get_actor_unsafe()->raw_event(td::Event::raw(static_cast(n - 1)).data); } } else if (type == 4) { send_lambda(next_actor, [n, ptr = next_actor.get_actor_unsafe()] { ptr->pass(n - 1); }); diff --git a/td/mtproto/AuthData.cpp b/td/mtproto/AuthData.cpp index aede7d3b6..dedca5031 100644 --- a/td/mtproto/AuthData.cpp +++ b/td/mtproto/AuthData.cpp @@ -100,7 +100,7 @@ std::vector AuthData::get_future_salts() const { int64 AuthData::next_message_id(double now) { double server_time = get_server_time(now); - int64 t = static_cast(server_time * (1ll << 32)); + auto t = static_cast(server_time * (1ll << 32)); // randomize lower bits for clocks with low precision // TODO(perf) do not do this for systems with good precision?.. diff --git a/td/mtproto/CryptoStorer.h b/td/mtproto/CryptoStorer.h index 67763c6dc..ead442f7f 100644 --- a/td/mtproto/CryptoStorer.h +++ b/td/mtproto/CryptoStorer.h @@ -192,8 +192,9 @@ class CryptoImpl { public: CryptoImpl(const vector &to_send, Slice header, vector &&to_ack, int64 ping_id, int ping_timeout, int max_delay, int max_after, int max_wait, int future_salt_n, vector get_info, - vector resend, vector cancel, bool destroy_key, AuthData *auth_data, uint64 *container_id, - uint64 *get_info_id, uint64 *resend_id, uint64 *ping_message_id, uint64 *parent_message_id) + vector resend, const vector &cancel, bool destroy_key, AuthData *auth_data, + uint64 *container_id, uint64 *get_info_id, uint64 *resend_id, uint64 *ping_message_id, + uint64 *parent_message_id) : query_storer_(to_send, header) , ack_empty_(to_ack.empty()) , ack_storer_(!ack_empty_, mtproto_api::msgs_ack(std::move(to_ack)), auth_data) @@ -206,7 +207,7 @@ class CryptoImpl { , resend_storer_(resend_not_empty_, mtproto_api::msg_resend_req(std::move(resend)), auth_data, true) , cancel_not_empty_(!cancel.empty()) , cancel_cnt_(static_cast(cancel.size())) - , cancel_storer_(cancel_not_empty_, std::move(cancel), auth_data, true) + , cancel_storer_(cancel_not_empty_, cancel, auth_data, true) , destroy_key_storer_(destroy_key, mtproto_api::destroy_auth_key(), auth_data, true) , tmp_storer_(query_storer_, ack_storer_) , tmp2_storer_(tmp_storer_, http_wait_storer_) diff --git a/td/mtproto/Handshake.cpp b/td/mtproto/Handshake.cpp index 23b32e758..79fd9a716 100644 --- a/td/mtproto/Handshake.cpp +++ b/td/mtproto/Handshake.cpp @@ -95,7 +95,8 @@ Status AuthKeyHandshake::on_res_pq(Slice message, Callback *connection, PublicRs } auto rsa_key = r_rsa_key.move_as_ok(); - string p, q; + string p; + string q; if (pq_factorize(res_pq->pq_, &p, &q) == -1) { return Status::Error("Failed to factorize"); } @@ -129,7 +130,7 @@ Status AuthKeyHandshake::on_res_pq(Slice message, Callback *connection, PublicRs string aes_key(32, '\0'); Random::secure_bytes(MutableSlice(aes_key)); - string data_with_hash = data + sha256(aes_key + data); + string data_with_hash = PSTRING() << data << sha256(aes_key + data); std::reverse(data_with_hash.begin(), data_with_hash.begin() + data.size()); string decrypted_data(256, '\0'); diff --git a/td/mtproto/Handshake.h b/td/mtproto/Handshake.h index 435350d94..b3979ed20 100644 --- a/td/mtproto/Handshake.h +++ b/td/mtproto/Handshake.h @@ -97,7 +97,7 @@ class AuthKeyHandshake { static string store_object(const mtproto_api::Object &object); void send(Callback *connection, const Storer &storer); - void do_send(Callback *connection, const Storer &storer); + static void do_send(Callback *connection, const Storer &storer); Status on_start(Callback *connection) TD_WARN_UNUSED_RESULT; Status on_res_pq(Slice message, Callback *connection, PublicRsaKeyInterface *public_rsa_key) TD_WARN_UNUSED_RESULT; diff --git a/td/mtproto/HandshakeConnection.h b/td/mtproto/HandshakeConnection.h index f7760ce05..49ef722b0 100644 --- a/td/mtproto/HandshakeConnection.h +++ b/td/mtproto/HandshakeConnection.h @@ -65,7 +65,7 @@ class HandshakeConnection final } Status on_raw_packet(const PacketInfo &packet_info, BufferSlice packet) final { - if (packet_info.no_crypto_flag == false) { + if (!packet_info.no_crypto_flag) { return Status::Error("Expected not encrypted packet"); } diff --git a/td/mtproto/Ping.cpp b/td/mtproto/Ping.cpp index b3dadcc7c..f92368c50 100644 --- a/td/mtproto/Ping.cpp +++ b/td/mtproto/Ping.cpp @@ -19,7 +19,7 @@ namespace td { namespace mtproto { -ActorOwn<> create_ping_actor(string debug, unique_ptr raw_connection, unique_ptr auth_data, +ActorOwn<> create_ping_actor(Slice actor_name, unique_ptr raw_connection, unique_ptr auth_data, Promise> promise, ActorShared<> parent) { class PingActor final : public Actor { public: @@ -99,7 +99,7 @@ ActorOwn<> create_ping_actor(string debug, unique_ptr raw_connect } } }; - return ActorOwn<>(create_actor(PSLICE() << "PingActor<" << debug << ">", std::move(raw_connection), + return ActorOwn<>(create_actor(PSLICE() << "PingActor<" << actor_name << ">", std::move(raw_connection), std::move(auth_data), std::move(promise), std::move(parent))); } diff --git a/td/mtproto/Ping.h b/td/mtproto/Ping.h index 7dc9aa4e0..25aded068 100644 --- a/td/mtproto/Ping.h +++ b/td/mtproto/Ping.h @@ -17,7 +17,7 @@ namespace td { namespace mtproto { -ActorOwn<> create_ping_actor(string debug, unique_ptr raw_connection, unique_ptr auth_data, +ActorOwn<> create_ping_actor(Slice actor_name, unique_ptr raw_connection, unique_ptr auth_data, Promise> promise, ActorShared<> parent); } // namespace mtproto diff --git a/td/mtproto/RawConnection.cpp b/td/mtproto/RawConnection.cpp index d26f48a1d..2e4ec5dad 100644 --- a/td/mtproto/RawConnection.cpp +++ b/td/mtproto/RawConnection.cpp @@ -37,7 +37,7 @@ class RawConnectionDefault final : public RawConnection { public: RawConnectionDefault(SocketFd socket_fd, TransportType transport_type, unique_ptr stats_callback) : socket_fd_(std::move(socket_fd)) - , transport_(create_transport(transport_type)) + , transport_(create_transport(std::move(transport_type))) , stats_callback_(std::move(stats_callback)) { transport_->init(&socket_fd_.input_buffer(), &socket_fd_.output_buffer()); } diff --git a/td/mtproto/RawConnection.h b/td/mtproto/RawConnection.h index 1afd78372..98cee88e0 100644 --- a/td/mtproto/RawConnection.h +++ b/td/mtproto/RawConnection.h @@ -48,7 +48,7 @@ class RawConnection { virtual bool can_send() const = 0; virtual TransportType get_transport_type() const = 0; virtual void send_crypto(const Storer &storer, int64 session_id, int64 salt, const AuthKey &auth_key, - uint64 quick_ack_token = 0) = 0; + uint64 quick_ack_token) = 0; virtual uint64 send_no_crypto(const Storer &storer) = 0; virtual PollableFdInfo &get_poll_info() = 0; diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index 228edae56..f69d01c11 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -893,7 +893,8 @@ void SessionConnection::flush_packet() { } } - size_t send_till = 0, send_size = 0; + size_t send_till = 0; + size_t send_size = 0; // send at most 1020 queries, of total size 2^15 // don't send anything if have no salt if (has_salt) { diff --git a/td/mtproto/SessionConnection.h b/td/mtproto/SessionConnection.h index 3da23a4fc..3661378b5 100644 --- a/td/mtproto/SessionConnection.h +++ b/td/mtproto/SessionConnection.h @@ -212,7 +212,8 @@ class SessionConnection final }; } - Status parse_message(TlParser &parser, MsgInfo *info, Slice *packet, bool crypto_flag = true) TD_WARN_UNUSED_RESULT; + static Status parse_message(TlParser &parser, MsgInfo *info, Slice *packet, + bool crypto_flag = true) TD_WARN_UNUSED_RESULT; Status parse_packet(TlParser &parser) TD_WARN_UNUSED_RESULT; Status on_packet_container(const MsgInfo &info, Slice packet) TD_WARN_UNUSED_RESULT; Status on_packet_rpc_result(const MsgInfo &info, Slice packet) TD_WARN_UNUSED_RESULT; diff --git a/td/mtproto/TcpTransport.cpp b/td/mtproto/TcpTransport.cpp index 98760aa1e..2570403dd 100644 --- a/td/mtproto/TcpTransport.cpp +++ b/td/mtproto/TcpTransport.cpp @@ -272,8 +272,8 @@ void ObfuscatedTransport::do_write_tls(BufferBuilder &&builder) { do_write(builder.extract()); } -void ObfuscatedTransport::do_write(BufferSlice &&slice) { - output_->append(std::move(slice)); +void ObfuscatedTransport::do_write(BufferSlice &&message) { + output_->append(std::move(message)); } } // namespace tcp diff --git a/td/mtproto/TcpTransport.h b/td/mtproto/TcpTransport.h index 2d188bbd8..4a2b918d9 100644 --- a/td/mtproto/TcpTransport.h +++ b/td/mtproto/TcpTransport.h @@ -128,8 +128,8 @@ class OldTransport final : public IStreamTransport { class ObfuscatedTransport final : public IStreamTransport { public: - ObfuscatedTransport(int16 dc_id, const ProxySecret &secret) - : dc_id_(dc_id), secret_(secret), impl_(secret_.use_random_padding()) { + ObfuscatedTransport(int16 dc_id, ProxySecret secret) + : dc_id_(dc_id), secret_(std::move(secret)), impl_(secret_.use_random_padding()) { } Result read_next(BufferSlice *message, uint32 *quick_ack) final TD_WARN_UNUSED_RESULT; @@ -172,6 +172,7 @@ class ObfuscatedTransport final : public IStreamTransport { TransportType get_type() const final { return TransportType{TransportType::ObfuscatedTcp, dc_id_, secret_}; } + bool use_random_padding() const final { return secret_.use_random_padding(); } diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index c10c22acf..08b4e439c 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -396,7 +396,7 @@ void ConnectionCreator::ping_proxy_socket_fd(IPAddress ip_address, SocketFd sock auto raw_connection = mtproto::RawConnection::create(ip_address, std::move(socket_fd), std::move(transport_type), nullptr); children_[token] = { - false, create_ping_actor(std::move(debug_str), std::move(raw_connection), nullptr, + false, create_ping_actor(debug_str, std::move(raw_connection), nullptr, PromiseCreator::lambda([promise = std::move(promise)]( Result> result) mutable { if (result.is_error()) { diff --git a/tdactor/td/actor/PromiseFuture.h b/tdactor/td/actor/PromiseFuture.h index 938267eb3..ba474cc9e 100644 --- a/tdactor/td/actor/PromiseFuture.h +++ b/tdactor/td/actor/PromiseFuture.h @@ -184,35 +184,29 @@ class SafePromise; template class Promise; -constexpr std::false_type is_promise_interface(...) { - return {}; -} +constexpr std::false_type is_promise_interface(...); + template -constexpr std::true_type is_promise_interface(const PromiseInterface &promise) { - return {}; -} +constexpr std::true_type is_promise_interface(const PromiseInterface &promise); + template -constexpr std::true_type is_promise_interface(const Promise &promise) { - return {}; -} +constexpr std::true_type is_promise_interface(const Promise &promise); template constexpr bool is_promise_interface() { return decltype(is_promise_interface(std::declval()))::value; } -constexpr std::false_type is_promise_interface_ptr(...) { - return {}; -} +constexpr std::false_type is_promise_interface_ptr(...); + template -constexpr std::true_type is_promise_interface_ptr(const unique_ptr &promise) { - return {}; -} +constexpr std::true_type is_promise_interface_ptr(const unique_ptr &promise); template constexpr bool is_promise_interface_ptr() { return decltype(is_promise_interface_ptr(std::declval()))::value; } + template ::value, bool> has_t = false> auto lambda_promise(F &&f) { return detail::LambdaPromise>>, std::decay_t>( diff --git a/tdactor/td/actor/impl/Actor.h b/tdactor/td/actor/impl/Actor.h index b29ee5452..4cf204ffe 100644 --- a/tdactor/td/actor/impl/Actor.h +++ b/tdactor/td/actor/impl/Actor.h @@ -52,7 +52,7 @@ inline void Actor::do_stop() { CHECK(empty()); } inline bool Actor::has_timeout() const { - return Scheduler::instance()->has_actor_timeout(this); + return get_info()->get_heap_node()->in_heap(); } inline double Actor::get_timeout() const { return Scheduler::instance()->get_actor_timeout(this); diff --git a/tdactor/td/actor/impl/EventFull-decl.h b/tdactor/td/actor/impl/EventFull-decl.h index f270ee857..a3d41c3a0 100644 --- a/tdactor/td/actor/impl/EventFull-decl.h +++ b/tdactor/td/actor/impl/EventFull-decl.h @@ -45,7 +45,7 @@ class EventFull { data_.link_token = actor_ref.token(); } template - EventFull(ActorId actor_id, Event &&data) : actor_id_(actor_id), data_(std::move(data)) { + EventFull(ActorId actor_id, Event &&data) : actor_id_(std::move(actor_id)), data_(std::move(data)) { } ActorId<> actor_id_; diff --git a/tdactor/td/actor/impl/Scheduler-decl.h b/tdactor/td/actor/impl/Scheduler-decl.h index 0e3fa3b03..daa988580 100644 --- a/tdactor/td/actor/impl/Scheduler-decl.h +++ b/tdactor/td/actor/impl/Scheduler-decl.h @@ -107,9 +107,6 @@ class Scheduler { template void send(ActorRef actor_ref, Event &&event); - void hack(const ActorId<> &actor_id, Event &&event) { - actor_id.get_actor_unsafe()->raw_event(event.data); - } void before_tail_send(const ActorId<> &actor_id); static void subscribe(PollableFd fd, PollFlags flags = PollFlags::ReadWrite()); @@ -125,7 +122,6 @@ class Scheduler { void start_migrate_actor(Actor *actor, int32 dest_sched_id); void finish_migrate_actor(Actor *actor); - bool has_actor_timeout(const Actor *actor) const; double get_actor_timeout(const Actor *actor) const; void set_actor_timeout_in(Actor *actor, double timeout); void set_actor_timeout_at(Actor *actor, double timeout_at); @@ -176,7 +172,6 @@ class Scheduler { void do_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id); void start_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id); - bool has_actor_timeout(const ActorInfo *actor_info) const; double get_actor_timeout(const ActorInfo *actor_info) const; void set_actor_timeout_in(ActorInfo *actor_info, double timeout); void set_actor_timeout_at(ActorInfo *actor_info, double timeout_at); diff --git a/tdactor/td/actor/impl/Scheduler.h b/tdactor/td/actor/impl/Scheduler.h index 2356f6d1c..47780e760 100644 --- a/tdactor/td/actor/impl/Scheduler.h +++ b/tdactor/td/actor/impl/Scheduler.h @@ -299,9 +299,6 @@ inline void Scheduler::finish_migrate_actor(Actor *actor) { register_migrated_actor(actor->get_info()); } -inline bool Scheduler::has_actor_timeout(const Actor *actor) const { - return has_actor_timeout(actor->get_info()); -} inline double Scheduler::get_actor_timeout(const Actor *actor) const { return get_actor_timeout(actor->get_info()); } @@ -315,11 +312,6 @@ inline void Scheduler::cancel_actor_timeout(Actor *actor) { cancel_actor_timeout(actor->get_info()); } -inline bool Scheduler::has_actor_timeout(const ActorInfo *actor_info) const { - const HeapNode *heap_node = actor_info->get_heap_node(); - return heap_node->in_heap(); -} - inline void Scheduler::cancel_actor_timeout(ActorInfo *actor_info) { HeapNode *heap_node = actor_info->get_heap_node(); if (heap_node->in_heap()) { diff --git a/tddb/td/db/SqliteKeyValue.h b/tddb/td/db/SqliteKeyValue.h index b44537d48..1d920aaa0 100644 --- a/tddb/td/db/SqliteKeyValue.h +++ b/tddb/td/db/SqliteKeyValue.h @@ -35,10 +35,6 @@ class SqliteKeyValue { Status init_with_connection(SqliteDb connection, string table_name) TD_WARN_UNUSED_RESULT; - Result try_regenerate_index() TD_WARN_UNUSED_RESULT { - return false; - } - void close() { *this = SqliteKeyValue(); } @@ -118,7 +114,7 @@ class SqliteKeyValue { SqliteStatement get_by_prefix_stmt_; SqliteStatement get_by_prefix_rare_stmt_; - string next_prefix(Slice prefix); + static string next_prefix(Slice prefix); }; } // namespace td diff --git a/tddb/td/db/SqliteKeyValueAsync.cpp b/tddb/td/db/SqliteKeyValueAsync.cpp index 3f59b2b81..796d02282 100644 --- a/tddb/td/db/SqliteKeyValueAsync.cpp +++ b/tddb/td/db/SqliteKeyValueAsync.cpp @@ -44,6 +44,7 @@ class SqliteKeyValueAsync final : public SqliteKeyValueAsyncInterface { public: explicit Impl(std::shared_ptr kv_safe) : kv_safe_(std::move(kv_safe)) { } + void set(string key, string value, Promise<> promise) { auto it = buffer_.find(key); if (it != buffer_.end()) { @@ -57,6 +58,7 @@ class SqliteKeyValueAsync final : public SqliteKeyValueAsyncInterface { cnt_++; do_flush(false /*force*/); } + void erase(string key, Promise<> promise) { auto it = buffer_.find(key); if (it != buffer_.end()) { @@ -70,6 +72,7 @@ class SqliteKeyValueAsync final : public SqliteKeyValueAsyncInterface { cnt_++; do_flush(false /*force*/); } + void erase_by_prefix(string key_prefix, Promise<> promise) { do_flush(true /*force*/); kv_->erase_by_prefix(key_prefix); diff --git a/tddb/td/db/TQueue.cpp b/tddb/td/db/TQueue.cpp index 70095eb93..52335504a 100644 --- a/tddb/td/db/TQueue.cpp +++ b/tddb/td/db/TQueue.cpp @@ -68,7 +68,7 @@ bool EventId::operator<(const EventId &other) const { return id_ < other.id_; } -StringBuilder &operator<<(StringBuilder &string_builder, const EventId id) { +StringBuilder &operator<<(StringBuilder &string_builder, EventId id) { return string_builder << "EventId{" << id.value() << "}"; } diff --git a/tddb/td/db/TQueue.h b/tddb/td/db/TQueue.h index 6301e20ba..8e84ae9a9 100644 --- a/tddb/td/db/TQueue.h +++ b/tddb/td/db/TQueue.h @@ -117,7 +117,7 @@ class TQueue { virtual void close(Promise<> promise) = 0; }; -StringBuilder &operator<<(StringBuilder &string_builder, const TQueue::EventId id); +StringBuilder &operator<<(StringBuilder &string_builder, TQueue::EventId id); struct BinlogEvent; @@ -131,7 +131,7 @@ class TQueueBinlog final : public TQueue::StorageCallback { void set_binlog(std::shared_ptr binlog) { binlog_ = std::move(binlog); } - virtual void close(Promise<> promise) final; + void close(Promise<> promise) final; private: std::shared_ptr binlog_; @@ -143,7 +143,7 @@ class TQueueMemoryStorage final : public TQueue::StorageCallback { uint64 push(QueueId queue_id, const RawEvent &event) final; void pop(uint64 log_event_id) final; void replay(TQueue &q) const; - virtual void close(Promise<> promise) final; + void close(Promise<> promise) final; private: uint64 next_log_event_id_{1}; diff --git a/tddb/td/db/binlog/Binlog.cpp b/tddb/td/db/binlog/Binlog.cpp index fb2e4bcab..9e5215ca8 100644 --- a/tddb/td/db/binlog/Binlog.cpp +++ b/tddb/td/db/binlog/Binlog.cpp @@ -54,7 +54,7 @@ struct AesCtrEncryptionEvent { BufferSlice iv_; BufferSlice key_hash_; - BufferSlice generate_key(const DbKey &db_key) { + BufferSlice generate_key(const DbKey &db_key) const { CHECK(!db_key.is_empty()); BufferSlice key(key_size()); size_t iteration_count = kdf_iteration_count(); @@ -64,7 +64,8 @@ struct AesCtrEncryptionEvent { pbkdf2_sha256(db_key.data(), key_salt_.as_slice(), narrow_cast(iteration_count), key.as_slice()); return key; } - BufferSlice generate_hash(Slice key) { + + static BufferSlice generate_hash(Slice key) { BufferSlice hash(hash_size()); hmac_sha256(key, "cucumbers everywhere", hash.as_slice()); return hash; @@ -354,11 +355,13 @@ void Binlog::do_event(BinlogEvent &&event) { key = encryption_event.generate_key(db_key_); } - if (encryption_event.generate_hash(key.as_slice()).as_slice() != encryption_event.key_hash_.as_slice()) { + if (detail::AesCtrEncryptionEvent::generate_hash(key.as_slice()).as_slice() != + encryption_event.key_hash_.as_slice()) { CHECK(state_ == State::Load); if (!old_db_key_.is_empty()) { key = encryption_event.generate_key(old_db_key_); - if (encryption_event.generate_hash(key.as_slice()).as_slice() != encryption_event.key_hash_.as_slice()) { + if (detail::AesCtrEncryptionEvent::generate_hash(key.as_slice()).as_slice() != + encryption_event.key_hash_.as_slice()) { info_.wrong_password = true; } } else { @@ -610,7 +613,7 @@ void Binlog::reset_encryption() { key = event.generate_key(db_key_); } - event.key_hash_ = event.generate_hash(key.as_slice()); + event.key_hash_ = EncryptionEvent::generate_hash(key.as_slice()); do_event(BinlogEvent( BinlogEvent::create_raw(0, BinlogEvent::ServiceTypes::AesCtrEncryption, 0, create_default_storer(event)), @@ -722,7 +725,7 @@ string Binlog::debug_get_binlog_data(int64 begin_offset, int64 end_offset) { SCOPE_EXIT { fd_.lock(FileFd::LockFlags::Write, path_, 1).ensure(); }; - size_t expected_data_length = narrow_cast(end_offset - begin_offset); + auto expected_data_length = narrow_cast(end_offset - begin_offset); string data(expected_data_length, '\0'); auto r_data_size = fd.pread(data, begin_offset); if (r_data_size.is_error()) { diff --git a/tddb/td/db/binlog/Binlog.h b/tddb/td/db/binlog/Binlog.h index d9ebe1038..1cc50c13e 100644 --- a/tddb/td/db/binlog/Binlog.h +++ b/tddb/td/db/binlog/Binlog.h @@ -154,7 +154,7 @@ class Binlog { bool need_sync_{false}; enum class State { Empty, Load, Reindex, Run } state_{State::Empty}; - Result open_binlog(const string &path, int32 flags); + static Result open_binlog(const string &path, int32 flags); size_t flush_events_buffer(bool force); void do_add_event(BinlogEvent &&event); void do_event(BinlogEvent &&event); diff --git a/tddb/td/db/binlog/BinlogInterface.h b/tddb/td/db/binlog/BinlogInterface.h index 21fe53451..20d156661 100644 --- a/tddb/td/db/binlog/BinlogInterface.h +++ b/tddb/td/db/binlog/BinlogInterface.h @@ -66,7 +66,7 @@ class BinlogInterface { virtual void force_sync(Promise<> promise) = 0; virtual void force_flush() = 0; - virtual void change_key(DbKey db_key, Promise<> promise = Promise<>()) = 0; + virtual void change_key(DbKey db_key, Promise<> promise) = 0; virtual uint64 next_id() = 0; virtual uint64 next_id(int32 shift) = 0; diff --git a/tdnet/td/net/GetHostByNameActor.cpp b/tdnet/td/net/GetHostByNameActor.cpp index 227780287..c966103c9 100644 --- a/tdnet/td/net/GetHostByNameActor.cpp +++ b/tdnet/td/net/GetHostByNameActor.cpp @@ -62,7 +62,7 @@ class GoogleDnsResolver final : public Actor { } TRY_RESULT(answer, get_json_object_field(json_value.get_object(), "Answer", JsonValue::Type::Array, false)); auto &array = answer.get_array(); - if (array.size() == 0) { + if (array.empty()) { return Status::Error("Failed to parse DNS result: Answer is an empty array"); } if (array[0].type() != JsonValue::Type::Object) { diff --git a/tdnet/td/net/HttpChunkedByteFlow.cpp b/tdnet/td/net/HttpChunkedByteFlow.cpp index c56fb2d87..7123c1727 100644 --- a/tdnet/td/net/HttpChunkedByteFlow.cpp +++ b/tdnet/td/net/HttpChunkedByteFlow.cpp @@ -62,7 +62,7 @@ bool HttpChunkedByteFlow::loop() { if (len_ == 0) { if (input_->size() < 2) { - need_size = 2; + set_need_size(2); break; } input_->advance(2); diff --git a/tdnet/td/net/HttpConnectionBase.cpp b/tdnet/td/net/HttpConnectionBase.cpp index c12782b2d..ff61ee9ab 100644 --- a/tdnet/td/net/HttpConnectionBase.cpp +++ b/tdnet/td/net/HttpConnectionBase.cpp @@ -184,7 +184,7 @@ void HttpConnectionBase::loop() { } if (state_ == State::Close) { LOG_IF(INFO, fd_.need_flush_write()) << "Close nonempty connection"; - LOG_IF(INFO, want_read && (fd_.input_buffer().size() > 0 || current_query_->type_ != HttpQuery::Type::Empty)) + LOG_IF(INFO, want_read && (!fd_.input_buffer().empty() || current_query_->type_ != HttpQuery::Type::Empty)) << "Close connection while reading request/response"; return stop(); } diff --git a/tdnet/td/net/SslStream.h b/tdnet/td/net/SslStream.h index c3e9bbd3d..5a1a40671 100644 --- a/tdnet/td/net/SslStream.h +++ b/tdnet/td/net/SslStream.h @@ -26,7 +26,7 @@ class SslStream { enum class VerifyPeer { On, Off }; static Result create(CSlice host, CSlice cert_file = CSlice(), VerifyPeer verify_peer = VerifyPeer::On, - bool check_ip_address_as_host = false); + bool use_ip_address_as_host = false); ByteFlowInterface &read_byte_flow(); ByteFlowInterface &write_byte_flow(); diff --git a/tdutils/generate/generate_mime_types_gperf.cpp b/tdutils/generate/generate_mime_types_gperf.cpp index 4a424814e..6bb64903b 100644 --- a/tdutils/generate/generate_mime_types_gperf.cpp +++ b/tdutils/generate/generate_mime_types_gperf.cpp @@ -116,7 +116,7 @@ int main(int argc, char *argv[]) { std::vector extensions; while (!extensions_string.empty()) { - extensions.push_back(""); + extensions.emplace_back(); std::tie(extensions.back(), extensions_string) = split(extensions_string); } assert(!extensions.empty()); diff --git a/tdutils/td/utils/BigNum.cpp b/tdutils/td/utils/BigNum.cpp index 09612aacb..adf70c53c 100644 --- a/tdutils/td/utils/BigNum.cpp +++ b/tdutils/td/utils/BigNum.cpp @@ -70,6 +70,9 @@ BigNum::BigNum(const BigNum &other) : BigNum() { } BigNum &BigNum::operator=(const BigNum &other) { + if (this == &other) { + return *this; + } CHECK(impl_ != nullptr); CHECK(other.impl_ != nullptr); BIGNUM *result = BN_copy(impl_->big_num, other.impl_->big_num); diff --git a/tdutils/td/utils/BufferedUdp.h b/tdutils/td/utils/BufferedUdp.h index 924ba791d..6e70b6832 100644 --- a/tdutils/td/utils/BufferedUdp.h +++ b/tdutils/td/utils/BufferedUdp.h @@ -79,8 +79,8 @@ class UdpReader { } } Status read_once(UdpSocketFd &fd, VectorQueue &queue) TD_WARN_UNUSED_RESULT { - for (size_t i = 0; i < messages_.size(); i++) { - CHECK(messages_[i].data.size() == 2048); + for (auto &message : messages_) { + CHECK(message.data.size() == 2048); } size_t cnt = 0; auto status = fd.receive_messages(messages_, cnt); diff --git a/tdutils/td/utils/Gzip.cpp b/tdutils/td/utils/Gzip.cpp index 3281e5849..a2fc6037d 100644 --- a/tdutils/td/utils/Gzip.cpp +++ b/tdutils/td/utils/Gzip.cpp @@ -189,7 +189,7 @@ BufferSlice gzencode(Slice s, double max_compression_ratio) { gzip.init_encode().ensure(); gzip.set_input(s); gzip.close_input(); - size_t max_size = static_cast(static_cast(s.size()) * max_compression_ratio); + auto max_size = static_cast(static_cast(s.size()) * max_compression_ratio); BufferWriter message{max_size}; gzip.set_output(message.prepare_append()); auto r_state = gzip.run(); diff --git a/tdutils/td/utils/Heap.h b/tdutils/td/utils/Heap.h index c9bbbd901..68f557705 100644 --- a/tdutils/td/utils/Heap.h +++ b/tdutils/td/utils/Heap.h @@ -38,7 +38,7 @@ class KHeap { } KeyT get_key(const HeapNode *node) const { - size_t pos = static_cast(node->pos_); + auto pos = static_cast(node->pos_); CHECK(pos < array_.size()); return array_[pos].key_; } @@ -62,7 +62,7 @@ class KHeap { } void fix(KeyT key, HeapNode *node) { - size_t pos = static_cast(node->pos_); + auto pos = static_cast(node->pos_); CHECK(pos < array_.size()); KeyT old_key = array_[pos].key_; array_[pos].key_ = key; @@ -74,7 +74,7 @@ class KHeap { } void erase(HeapNode *node) { - size_t pos = static_cast(node->pos_); + auto pos = static_cast(node->pos_); node->remove(); CHECK(pos < array_.size()); erase(pos); diff --git a/tdutils/td/utils/Hints.cpp b/tdutils/td/utils/Hints.cpp index a583fb483..e5c03954e 100644 --- a/tdutils/td/utils/Hints.cpp +++ b/tdutils/td/utils/Hints.cpp @@ -150,7 +150,7 @@ void Hints::add_search_results(vector &results, const string &word, vector Hints::search_word(const string &word) const { vector results; add_search_results(results, word, translit_word_to_keys_); - for (auto w : get_word_transliterations(word, true)) { + for (const auto &w : get_word_transliterations(word, true)) { add_search_results(results, w, word_to_keys_); } diff --git a/tdutils/td/utils/HttpUrl.cpp b/tdutils/td/utils/HttpUrl.cpp index 0b8f4f21b..f30497257 100644 --- a/tdutils/td/utils/HttpUrl.cpp +++ b/tdutils/td/utils/HttpUrl.cpp @@ -168,7 +168,7 @@ Result parse_url(Slice url, HttpUrl::Protocol default_protocol) { } // all other symbols aren't allowed - unsigned char uc = static_cast(c); + auto uc = static_cast(c); if (uc >= 128) { // but we allow plain UTF-8 symbols continue; diff --git a/tdutils/td/utils/JsonBuilder.cpp b/tdutils/td/utils/JsonBuilder.cpp index c0ac51776..2872b50a1 100644 --- a/tdutils/td/utils/JsonBuilder.cpp +++ b/tdutils/td/utils/JsonBuilder.cpp @@ -394,7 +394,7 @@ Result do_json_decode(Parser &parser, int32 max_depth) { case '{': { parser.skip('{'); parser.skip_whitespaces(); - std::vector > res; + std::vector> res; if (parser.try_skip('}')) { return JsonValue::make_object(std::move(res)); } @@ -408,7 +408,7 @@ Result do_json_decode(Parser &parser, int32 max_depth) { return Status::Error("':' expected"); } TRY_RESULT(value, do_json_decode(parser, max_depth - 1)); - res.emplace_back(std::move(key), std::move(value)); + res.emplace_back(key, std::move(value)); parser.skip_whitespaces(); if (parser.try_skip('}')) { diff --git a/tdutils/td/utils/ScopeGuard.h b/tdutils/td/utils/ScopeGuard.h index 30d964972..900906b20 100644 --- a/tdutils/td/utils/ScopeGuard.h +++ b/tdutils/td/utils/ScopeGuard.h @@ -42,11 +42,11 @@ class LambdaGuard final : public Guard { } LambdaGuard &operator=(LambdaGuard &&other) = delete; - void dismiss() override { + void dismiss() final { dismissed_ = true; } - ~LambdaGuard() override { + ~LambdaGuard() final { if (!dismissed_) { func_(); } diff --git a/tdutils/td/utils/TsCerr.h b/tdutils/td/utils/TsCerr.h index 8ef4942e3..06416e49a 100644 --- a/tdutils/td/utils/TsCerr.h +++ b/tdutils/td/utils/TsCerr.h @@ -26,8 +26,8 @@ class TsCerr { private: static std::atomic_flag lock_; - void enterCritical(); - void exitCritical(); + static void enterCritical(); + static void exitCritical(); }; } // namespace td diff --git a/tdutils/td/utils/TsFileLog.cpp b/tdutils/td/utils/TsFileLog.cpp index 51ca4d54e..bdb54e5a1 100644 --- a/tdutils/td/utils/TsFileLog.cpp +++ b/tdutils/td/utils/TsFileLog.cpp @@ -99,7 +99,7 @@ class TsFileLog final : public LogInterface { Result> TsFileLog::create(string path, int64 rotate_threshold, bool redirect_stderr) { auto res = make_unique(); - TRY_STATUS(res->init(path, rotate_threshold, redirect_stderr)); + TRY_STATUS(res->init(std::move(path), rotate_threshold, redirect_stderr)); return std::move(res); } diff --git a/tdutils/td/utils/Variant.h b/tdutils/td/utils/Variant.h index d1e7fc6fa..502c7df03 100644 --- a/tdutils/td/utils/Variant.h +++ b/tdutils/td/utils/Variant.h @@ -121,6 +121,9 @@ class Variant { return *this; } Variant &operator=(const Variant &other) { + if (this == &other) { + return *this; + } clear(); other.visit([&](auto &&value) { this->init_empty(std::forward(value)); }); return *this; diff --git a/tdutils/td/utils/crypto.h b/tdutils/td/utils/crypto.h index 0fc608c11..714620060 100644 --- a/tdutils/td/utils/crypto.h +++ b/tdutils/td/utils/crypto.h @@ -139,7 +139,7 @@ class Sha256State { void feed(Slice data); - void extract(MutableSlice dest, bool destroy = false); + void extract(MutableSlice output, bool destroy = false); private: class Impl; diff --git a/tdutils/td/utils/logging.cpp b/tdutils/td/utils/logging.cpp index 87920dcbe..ebb528df8 100644 --- a/tdutils/td/utils/logging.cpp +++ b/tdutils/td/utils/logging.cpp @@ -219,6 +219,9 @@ class DefaultLog final : public LogInterface { case VERBOSITY_NAME(INFO): color = Slice("\x1b[1;36m"); // cyan break; + default: + // no color + break; } Slice no_color("\x1b[0m"); if (!slice.empty() && slice.back() == '\n') { diff --git a/tdutils/td/utils/misc.cpp b/tdutils/td/utils/misc.cpp index fc33710f1..98dd015a4 100644 --- a/tdutils/td/utils/misc.cpp +++ b/tdutils/td/utils/misc.cpp @@ -16,7 +16,7 @@ namespace td { char *str_dup(Slice str) { - char *res = static_cast(std::malloc(str.size() + 1)); + auto *res = static_cast(std::malloc(str.size() + 1)); if (res == nullptr) { return nullptr; } diff --git a/tdutils/td/utils/port/UdpSocketFd.cpp b/tdutils/td/utils/port/UdpSocketFd.cpp index 971dcbf70..2c65c459d 100644 --- a/tdutils/td/utils/port/UdpSocketFd.cpp +++ b/tdutils/td/utils/port/UdpSocketFd.cpp @@ -79,6 +79,7 @@ class UdpSocketReceiveHelper { sockaddr_storage addr_; WSABUF buf_; }; + class UdpSocketSendHelper { public: void to_native(const UdpMessage &message, WSAMSG &message_header) { @@ -295,7 +296,7 @@ class UdpSocketFdImpl final : private Iocp::Callback { VLOG(fd) << get_native_fd() << " on receive " << size; CHECK(is_receive_active_); is_receive_active_ = false; - receive_helper_.from_native(receive_message_, size, to_receive_); + UdpSocketReceiveHelper::from_native(receive_message_, size, to_receive_); receive_buffer_.confirm_read((to_receive_.data.size() + 7) & ~7); { auto lock = lock_.lock(); @@ -502,7 +503,7 @@ class UdpSocketFdImpl { auto recvmsg_res = detail::skip_eintr([&] { return recvmsg(native_fd, &message_header, flags); }); auto recvmsg_errno = errno; if (recvmsg_res >= 0) { - helper.from_native(message_header, recvmsg_res, message); + UdpSocketReceiveHelper::from_native(message_header, recvmsg_res, message); is_received = true; return Status::OK(); } @@ -719,7 +720,7 @@ class UdpSocketFdImpl { if (recvmmsg_res >= 0) { cnt = narrow_cast(recvmmsg_res); for (size_t i = 0; i < cnt; i++) { - helpers[i].from_native(headers[i].msg_hdr, headers[i].msg_len, messages[i]); + UdpSocketReceiveHelper::from_native(headers[i].msg_hdr, headers[i].msg_len, messages[i]); } return Status::OK(); } diff --git a/tdutils/td/utils/port/uname.cpp b/tdutils/td/utils/port/uname.cpp index 6aa8a01d0..34a5c7525 100644 --- a/tdutils/td/utils/port/uname.cpp +++ b/tdutils/td/utils/port/uname.cpp @@ -49,7 +49,7 @@ static string read_os_name(CSlice os_version_file_path, CSlice prefix, CSlice su auto end_pos = r_file.ok().find(suffix.c_str(), begin_pos); if (end_pos != string::npos) { auto os_version = trim(r_file.ok().substr(begin_pos, end_pos - begin_pos)); - if (os_version.find("\n") == string::npos) { + if (os_version.find('\n') == string::npos) { return os_version; } } diff --git a/tdutils/td/utils/queue.h b/tdutils/td/utils/queue.h index c0f419084..4d3f336eb 100644 --- a/tdutils/td/utils/queue.h +++ b/tdutils/td/utils/queue.h @@ -150,7 +150,7 @@ class SPSCBlockQueue { } }; -template > +template > class SPSCChainQueue { public: using ValueType = T; @@ -308,10 +308,10 @@ class BackoffQueue : public QueueT { } }; -template > +template > using InfBackoffQueue = BackoffQueue; -template > +template > class PollQueue final : public QueueT { public: using ValueType = T; diff --git a/tdutils/td/utils/tests.cpp b/tdutils/td/utils/tests.cpp index ecb14a968..dddad7c75 100644 --- a/tdutils/td/utils/tests.cpp +++ b/tdutils/td/utils/tests.cpp @@ -64,10 +64,11 @@ class RegressionTesterImpl final : public RegressionTester { unlink(db_path).ignore(); } - RegressionTesterImpl(string db_path, string db_cache_dir) : db_path_(db_path), db_cache_dir_(db_cache_dir) { - load_db(db_path).ignore(); + RegressionTesterImpl(string db_path, string db_cache_dir) + : db_path_(std::move(db_path)), db_cache_dir_(std::move(db_cache_dir)) { + load_db(db_path_).ignore(); if (db_cache_dir_.empty()) { - db_cache_dir_ = PathView(db_path).without_extension().str() + ".cache/"; + db_cache_dir_ = PathView(db_path_).without_extension().str() + ".cache/"; } mkdir(db_cache_dir_).ensure(); } @@ -120,7 +121,7 @@ class RegressionTesterImpl final : public RegressionTester { void save_db(StringBuilder &sb) { sb << magic() << "\n"; - for (auto it : tests_) { + for (const auto &it : tests_) { sb << it.second; } } @@ -171,7 +172,7 @@ void TestsRunner::add_test(string name, std::function()> test) LOG(FATAL) << "Test name collision " << name; } } - tests_.emplace_back(name, TestInfo{std::move(test), nullptr}); + tests_.emplace_back(std::move(name), TestInfo{std::move(test), nullptr}); } void TestsRunner::add_substr_filter(string str) { diff --git a/tdutils/td/utils/tests.h b/tdutils/td/utils/tests.h index ec8377db5..10bca6010 100644 --- a/tdutils/td/utils/tests.h +++ b/tdutils/td/utils/tests.h @@ -122,7 +122,7 @@ template class RegisterTest { public: explicit RegisterTest(string name, TestsRunner &runner = TestsRunner::get_default()) { - runner.add_test(name, [] { return make_unique(); }); + runner.add_test(std::move(name), [] { return make_unique(); }); } }; diff --git a/tdutils/td/utils/unicode.cpp b/tdutils/td/utils/unicode.cpp index 42bbf62c4..b5e7892fa 100644 --- a/tdutils/td/utils/unicode.cpp +++ b/tdutils/td/utils/unicode.cpp @@ -1200,8 +1200,9 @@ static uint32 binary_search_ranges(const int32 (&ranges)[N], uint32 code) { return 0; } - int32 code_int = static_cast(code); - size_t l = 0, r = N; + auto code_int = static_cast(code); + size_t l = 0; + size_t r = N; while (l < r) { size_t m = ((l + r + 2) >> 2) << 1; if (ranges[m] <= code_int) { diff --git a/test/mtproto.cpp b/test/mtproto.cpp index c0b66e126..7bee6b377 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -612,7 +612,7 @@ class FastPingTestActor final : public Actor { } iteration_++; fast_ping_ = create_ping_actor( - "", std::move(connection_), std::move(auth_data), + td::Slice(), std::move(connection_), std::move(auth_data), PromiseCreator::lambda([self = actor_id(this)](Result> r_raw_connection) { send_closure(self, &FastPingTestActor::got_raw_connection, std::move(r_raw_connection)); }),