Minor improvements.
This commit is contained in:
parent
01976bed53
commit
44a186c7c1
@ -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<td::ActorId<Actor>>(next_actor),
|
||||
td::Event::raw(static_cast<td::uint32>(n - 1)));
|
||||
next_actor.get_actor_unsafe()->raw_event(td::Event::raw(static_cast<td::uint32>(n - 1)).data);
|
||||
}
|
||||
} else if (type == 4) {
|
||||
send_lambda(next_actor, [n, ptr = next_actor.get_actor_unsafe()] { ptr->pass(n - 1); });
|
||||
|
@ -100,7 +100,7 @@ std::vector<ServerSalt> AuthData::get_future_salts() const {
|
||||
|
||||
int64 AuthData::next_message_id(double now) {
|
||||
double server_time = get_server_time(now);
|
||||
int64 t = static_cast<int64>(server_time * (1ll << 32));
|
||||
auto t = static_cast<int64>(server_time * (1ll << 32));
|
||||
|
||||
// randomize lower bits for clocks with low precision
|
||||
// TODO(perf) do not do this for systems with good precision?..
|
||||
|
@ -192,8 +192,9 @@ class CryptoImpl {
|
||||
public:
|
||||
CryptoImpl(const vector<MtprotoQuery> &to_send, Slice header, vector<int64> &&to_ack, int64 ping_id, int ping_timeout,
|
||||
int max_delay, int max_after, int max_wait, int future_salt_n, vector<int64> get_info,
|
||||
vector<int64> resend, vector<int64> 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<int64> resend, const vector<int64> &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<int32>(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_)
|
||||
|
@ -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');
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
namespace td {
|
||||
namespace mtproto {
|
||||
|
||||
ActorOwn<> create_ping_actor(string debug, unique_ptr<RawConnection> raw_connection, unique_ptr<AuthData> auth_data,
|
||||
ActorOwn<> create_ping_actor(Slice actor_name, unique_ptr<RawConnection> raw_connection, unique_ptr<AuthData> auth_data,
|
||||
Promise<unique_ptr<RawConnection>> promise, ActorShared<> parent) {
|
||||
class PingActor final : public Actor {
|
||||
public:
|
||||
@ -99,7 +99,7 @@ ActorOwn<> create_ping_actor(string debug, unique_ptr<RawConnection> raw_connect
|
||||
}
|
||||
}
|
||||
};
|
||||
return ActorOwn<>(create_actor<PingActor>(PSLICE() << "PingActor<" << debug << ">", std::move(raw_connection),
|
||||
return ActorOwn<>(create_actor<PingActor>(PSLICE() << "PingActor<" << actor_name << ">", std::move(raw_connection),
|
||||
std::move(auth_data), std::move(promise), std::move(parent)));
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
namespace td {
|
||||
namespace mtproto {
|
||||
|
||||
ActorOwn<> create_ping_actor(string debug, unique_ptr<RawConnection> raw_connection, unique_ptr<AuthData> auth_data,
|
||||
ActorOwn<> create_ping_actor(Slice actor_name, unique_ptr<RawConnection> raw_connection, unique_ptr<AuthData> auth_data,
|
||||
Promise<unique_ptr<RawConnection>> promise, ActorShared<> parent);
|
||||
|
||||
} // namespace mtproto
|
||||
|
@ -37,7 +37,7 @@ class RawConnectionDefault final : public RawConnection {
|
||||
public:
|
||||
RawConnectionDefault(SocketFd socket_fd, TransportType transport_type, unique_ptr<StatsCallback> 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());
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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<size_t> 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();
|
||||
}
|
||||
|
@ -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<unique_ptr<mtproto::RawConnection>> result) mutable {
|
||||
if (result.is_error()) {
|
||||
|
@ -184,35 +184,29 @@ class SafePromise;
|
||||
template <class T = Unit>
|
||||
class Promise;
|
||||
|
||||
constexpr std::false_type is_promise_interface(...) {
|
||||
return {};
|
||||
}
|
||||
constexpr std::false_type is_promise_interface(...);
|
||||
|
||||
template <class T>
|
||||
constexpr std::true_type is_promise_interface(const PromiseInterface<T> &promise) {
|
||||
return {};
|
||||
}
|
||||
constexpr std::true_type is_promise_interface(const PromiseInterface<T> &promise);
|
||||
|
||||
template <class T>
|
||||
constexpr std::true_type is_promise_interface(const Promise<T> &promise) {
|
||||
return {};
|
||||
}
|
||||
constexpr std::true_type is_promise_interface(const Promise<T> &promise);
|
||||
|
||||
template <class F>
|
||||
constexpr bool is_promise_interface() {
|
||||
return decltype(is_promise_interface(std::declval<F>()))::value;
|
||||
}
|
||||
|
||||
constexpr std::false_type is_promise_interface_ptr(...) {
|
||||
return {};
|
||||
}
|
||||
constexpr std::false_type is_promise_interface_ptr(...);
|
||||
|
||||
template <class T>
|
||||
constexpr std::true_type is_promise_interface_ptr(const unique_ptr<T> &promise) {
|
||||
return {};
|
||||
}
|
||||
constexpr std::true_type is_promise_interface_ptr(const unique_ptr<T> &promise);
|
||||
|
||||
template <class F>
|
||||
constexpr bool is_promise_interface_ptr() {
|
||||
return decltype(is_promise_interface_ptr(std::declval<F>()))::value;
|
||||
}
|
||||
|
||||
template <class T = void, class F = void, std::enable_if_t<std::is_same<T, void>::value, bool> has_t = false>
|
||||
auto lambda_promise(F &&f) {
|
||||
return detail::LambdaPromise<detail::drop_result_t<detail::get_arg_t<std::decay_t<F>>>, std::decay_t<F>>(
|
||||
|
@ -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);
|
||||
|
@ -45,7 +45,7 @@ class EventFull {
|
||||
data_.link_token = actor_ref.token();
|
||||
}
|
||||
template <class T>
|
||||
EventFull(ActorId<T> actor_id, Event &&data) : actor_id_(actor_id), data_(std::move(data)) {
|
||||
EventFull(ActorId<T> actor_id, Event &&data) : actor_id_(std::move(actor_id)), data_(std::move(data)) {
|
||||
}
|
||||
|
||||
ActorId<> actor_id_;
|
||||
|
@ -107,9 +107,6 @@ class Scheduler {
|
||||
template <ActorSendType send_type>
|
||||
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);
|
||||
|
@ -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()) {
|
||||
|
@ -35,10 +35,6 @@ class SqliteKeyValue {
|
||||
|
||||
Status init_with_connection(SqliteDb connection, string table_name) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
Result<bool> 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
|
||||
|
@ -44,6 +44,7 @@ class SqliteKeyValueAsync final : public SqliteKeyValueAsyncInterface {
|
||||
public:
|
||||
explicit Impl(std::shared_ptr<SqliteKeyValueSafe> 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);
|
||||
|
@ -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() << "}";
|
||||
}
|
||||
|
||||
|
@ -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<BinlogT> binlog) {
|
||||
binlog_ = std::move(binlog);
|
||||
}
|
||||
virtual void close(Promise<> promise) final;
|
||||
void close(Promise<> promise) final;
|
||||
|
||||
private:
|
||||
std::shared_ptr<BinlogT> 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};
|
||||
|
@ -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<int>(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<size_t>(end_offset - begin_offset);
|
||||
auto expected_data_length = narrow_cast<size_t>(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()) {
|
||||
|
@ -154,7 +154,7 @@ class Binlog {
|
||||
bool need_sync_{false};
|
||||
enum class State { Empty, Load, Reindex, Run } state_{State::Empty};
|
||||
|
||||
Result<FileFd> open_binlog(const string &path, int32 flags);
|
||||
static Result<FileFd> 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);
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class SslStream {
|
||||
enum class VerifyPeer { On, Off };
|
||||
|
||||
static Result<SslStream> 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();
|
||||
|
@ -116,7 +116,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
std::vector<std::string> extensions;
|
||||
while (!extensions_string.empty()) {
|
||||
extensions.push_back("");
|
||||
extensions.emplace_back();
|
||||
std::tie(extensions.back(), extensions_string) = split(extensions_string);
|
||||
}
|
||||
assert(!extensions.empty());
|
||||
|
@ -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);
|
||||
|
@ -79,8 +79,8 @@ class UdpReader {
|
||||
}
|
||||
}
|
||||
Status read_once(UdpSocketFd &fd, VectorQueue<UdpMessage> &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);
|
||||
|
@ -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<size_t>(static_cast<double>(s.size()) * max_compression_ratio);
|
||||
auto max_size = static_cast<size_t>(static_cast<double>(s.size()) * max_compression_ratio);
|
||||
BufferWriter message{max_size};
|
||||
gzip.set_output(message.prepare_append());
|
||||
auto r_state = gzip.run();
|
||||
|
@ -38,7 +38,7 @@ class KHeap {
|
||||
}
|
||||
|
||||
KeyT get_key(const HeapNode *node) const {
|
||||
size_t pos = static_cast<size_t>(node->pos_);
|
||||
auto pos = static_cast<size_t>(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<size_t>(node->pos_);
|
||||
auto pos = static_cast<size_t>(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<size_t>(node->pos_);
|
||||
auto pos = static_cast<size_t>(node->pos_);
|
||||
node->remove();
|
||||
CHECK(pos < array_.size());
|
||||
erase(pos);
|
||||
|
@ -150,7 +150,7 @@ void Hints::add_search_results(vector<KeyT> &results, const string &word,
|
||||
vector<Hints::KeyT> Hints::search_word(const string &word) const {
|
||||
vector<KeyT> 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_);
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ Result<HttpUrl> parse_url(Slice url, HttpUrl::Protocol default_protocol) {
|
||||
}
|
||||
|
||||
// all other symbols aren't allowed
|
||||
unsigned char uc = static_cast<unsigned char>(c);
|
||||
auto uc = static_cast<unsigned char>(c);
|
||||
if (uc >= 128) {
|
||||
// but we allow plain UTF-8 symbols
|
||||
continue;
|
||||
|
@ -394,7 +394,7 @@ Result<JsonValue> do_json_decode(Parser &parser, int32 max_depth) {
|
||||
case '{': {
|
||||
parser.skip('{');
|
||||
parser.skip_whitespaces();
|
||||
std::vector<std::pair<MutableSlice, JsonValue> > res;
|
||||
std::vector<std::pair<MutableSlice, JsonValue>> res;
|
||||
if (parser.try_skip('}')) {
|
||||
return JsonValue::make_object(std::move(res));
|
||||
}
|
||||
@ -408,7 +408,7 @@ Result<JsonValue> 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('}')) {
|
||||
|
@ -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_();
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ class TsCerr {
|
||||
private:
|
||||
static std::atomic_flag lock_;
|
||||
|
||||
void enterCritical();
|
||||
void exitCritical();
|
||||
static void enterCritical();
|
||||
static void exitCritical();
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -99,7 +99,7 @@ class TsFileLog final : public LogInterface {
|
||||
|
||||
Result<unique_ptr<LogInterface>> TsFileLog::create(string path, int64 rotate_threshold, bool redirect_stderr) {
|
||||
auto res = make_unique<detail::TsFileLog>();
|
||||
TRY_STATUS(res->init(path, rotate_threshold, redirect_stderr));
|
||||
TRY_STATUS(res->init(std::move(path), rotate_threshold, redirect_stderr));
|
||||
return std::move(res);
|
||||
}
|
||||
|
||||
|
@ -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<decltype(value)>(value)); });
|
||||
return *this;
|
||||
|
@ -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;
|
||||
|
@ -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') {
|
||||
|
@ -16,7 +16,7 @@
|
||||
namespace td {
|
||||
|
||||
char *str_dup(Slice str) {
|
||||
char *res = static_cast<char *>(std::malloc(str.size() + 1));
|
||||
auto *res = static_cast<char *>(std::malloc(str.size() + 1));
|
||||
if (res == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -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<size_t>(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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ class SPSCBlockQueue {
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class BlockQueueT = SPSCBlockQueue<T> >
|
||||
template <class T, class BlockQueueT = SPSCBlockQueue<T>>
|
||||
class SPSCChainQueue {
|
||||
public:
|
||||
using ValueType = T;
|
||||
@ -308,10 +308,10 @@ class BackoffQueue : public QueueT {
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class QueueT = SPSCChainQueue<T> >
|
||||
template <class T, class QueueT = SPSCChainQueue<T>>
|
||||
using InfBackoffQueue = BackoffQueue<T, QueueT, detail::InfBackoff>;
|
||||
|
||||
template <class T, class QueueT = BackoffQueue<T> >
|
||||
template <class T, class QueueT = BackoffQueue<T>>
|
||||
class PollQueue final : public QueueT {
|
||||
public:
|
||||
using ValueType = T;
|
||||
|
@ -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<unique_ptr<Test>()> 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) {
|
||||
|
@ -122,7 +122,7 @@ template <class T>
|
||||
class RegisterTest {
|
||||
public:
|
||||
explicit RegisterTest(string name, TestsRunner &runner = TestsRunner::get_default()) {
|
||||
runner.add_test(name, [] { return make_unique<T>(); });
|
||||
runner.add_test(std::move(name), [] { return make_unique<T>(); });
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1200,8 +1200,9 @@ static uint32 binary_search_ranges(const int32 (&ranges)[N], uint32 code) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 code_int = static_cast<int32>(code);
|
||||
size_t l = 0, r = N;
|
||||
auto code_int = static_cast<int32>(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) {
|
||||
|
@ -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<unique_ptr<mtproto::RawConnection>> r_raw_connection) {
|
||||
send_closure(self, &FastPingTestActor::got_raw_connection, std::move(r_raw_connection));
|
||||
}),
|
||||
|
Loading…
Reference in New Issue
Block a user