Add Query.h.
GitOrigin-RevId: f795d804e9d3feb4f72517dc84bd13bfe7955bc4
This commit is contained in:
parent
e0765a3c82
commit
5e2a71d8fb
@ -450,6 +450,7 @@ set(TDLIB_SOURCE
|
|||||||
td/mtproto/PacketInfo.h
|
td/mtproto/PacketInfo.h
|
||||||
td/mtproto/PacketStorer.h
|
td/mtproto/PacketStorer.h
|
||||||
td/mtproto/PingConnection.h
|
td/mtproto/PingConnection.h
|
||||||
|
td/mtproto/Query.h
|
||||||
td/mtproto/RawConnection.h
|
td/mtproto/RawConnection.h
|
||||||
td/mtproto/SessionConnection.h
|
td/mtproto/SessionConnection.h
|
||||||
td/mtproto/TcpTransport.h
|
td/mtproto/TcpTransport.h
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/mtproto/AuthData.h"
|
#include "td/mtproto/AuthData.h"
|
||||||
#include "td/mtproto/PacketStorer.h"
|
#include "td/mtproto/PacketStorer.h"
|
||||||
|
#include "td/mtproto/Query.h"
|
||||||
#include "td/mtproto/utils.h"
|
#include "td/mtproto/utils.h"
|
||||||
|
|
||||||
#include "td/mtproto/mtproto_api.h"
|
#include "td/mtproto/mtproto_api.h"
|
||||||
@ -102,7 +103,7 @@ class CancelVectorImpl {
|
|||||||
|
|
||||||
class QueryImpl {
|
class QueryImpl {
|
||||||
public:
|
public:
|
||||||
QueryImpl(const Query &query, Slice header) : query_(query), header_(header) {
|
QueryImpl(const MtprotoQuery &query, Slice header) : query_(query), header_(header) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -144,13 +145,13 @@ class QueryImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Query &query_;
|
const MtprotoQuery &query_;
|
||||||
Slice header_;
|
Slice header_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QueryVectorImpl {
|
class QueryVectorImpl {
|
||||||
public:
|
public:
|
||||||
QueryVectorImpl(const vector<Query> &to_send, Slice header) : to_send_(to_send), header_(header) {
|
QueryVectorImpl(const vector<MtprotoQuery> &to_send, Slice header) : to_send_(to_send), header_(header) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -164,7 +165,7 @@ class QueryVectorImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const vector<Query> &to_send_;
|
const vector<MtprotoQuery> &to_send_;
|
||||||
Slice header_;
|
Slice header_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -187,7 +188,7 @@ class ContainerImpl {
|
|||||||
|
|
||||||
class CryptoImpl {
|
class CryptoImpl {
|
||||||
public:
|
public:
|
||||||
CryptoImpl(const vector<Query> &to_send, Slice header, vector<int64> &&to_ack, int64 ping_id, int ping_timeout,
|
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,
|
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,
|
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)
|
uint64 *get_info_id, uint64 *resend_id, uint64 *ping_message_id, uint64 *parent_message_id)
|
||||||
|
25
td/mtproto/Query.h
Normal file
25
td/mtproto/Query.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/utils/buffer.h"
|
||||||
|
#include "td/utils/common.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace mtproto {
|
||||||
|
|
||||||
|
struct MtprotoQuery {
|
||||||
|
int64 message_id;
|
||||||
|
int32 seq_no;
|
||||||
|
BufferSlice packet;
|
||||||
|
bool gzip_flag;
|
||||||
|
uint64 invoke_after_id;
|
||||||
|
bool use_quick_ack;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace mtproto
|
||||||
|
} // namespace td
|
@ -749,7 +749,7 @@ Result<uint64> SessionConnection::send_query(BufferSlice buffer, bool gzip_flag,
|
|||||||
if (to_send_.empty()) {
|
if (to_send_.empty()) {
|
||||||
send_before(Time::now_cached() + QUERY_DELAY);
|
send_before(Time::now_cached() + QUERY_DELAY);
|
||||||
}
|
}
|
||||||
to_send_.push_back(Query{message_id, seq_no, std::move(buffer), gzip_flag, invoke_after_id, use_quick_ack});
|
to_send_.push_back(MtprotoQuery{message_id, seq_no, std::move(buffer), gzip_flag, invoke_after_id, use_quick_ack});
|
||||||
VLOG(mtproto) << "Invoke query " << message_id << " of size " << to_send_.back().packet.size() << " with seq_no "
|
VLOG(mtproto) << "Invoke query " << message_id << " of size " << to_send_.back().packet.size() << " with seq_no "
|
||||||
<< seq_no << " after " << invoke_after_id << (use_quick_ack ? " with quick ack" : "");
|
<< seq_no << " after " << invoke_after_id << (use_quick_ack ? " with quick ack" : "");
|
||||||
|
|
||||||
@ -791,7 +791,8 @@ std::pair<uint64, BufferSlice> SessionConnection::encrypted_bind(int64 perm_key,
|
|||||||
auto real_size = object_storer.store(object_packet.as_slice().ubegin());
|
auto real_size = object_storer.store(object_packet.as_slice().ubegin());
|
||||||
CHECK(size == real_size);
|
CHECK(size == real_size);
|
||||||
|
|
||||||
Query query{auth_data_->next_message_id(Time::now_cached()), 0, object_packet.as_buffer_slice(), false, 0, false};
|
MtprotoQuery query{
|
||||||
|
auth_data_->next_message_id(Time::now_cached()), 0, object_packet.as_buffer_slice(), false, 0, false};
|
||||||
PacketStorer<QueryImpl> query_storer(query, Slice());
|
PacketStorer<QueryImpl> query_storer(query, Slice());
|
||||||
|
|
||||||
PacketInfo info;
|
PacketInfo info;
|
||||||
@ -871,7 +872,7 @@ void SessionConnection::flush_packet() {
|
|||||||
send_till++;
|
send_till++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::vector<Query> queries;
|
std::vector<MtprotoQuery> queries;
|
||||||
if (send_till == to_send_.size()) {
|
if (send_till == to_send_.size()) {
|
||||||
queries = std::move(to_send_);
|
queries = std::move(to_send_);
|
||||||
} else if (send_till != 0) {
|
} else if (send_till != 0) {
|
||||||
@ -943,7 +944,7 @@ void SessionConnection::flush_packet() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (container_id != 0) {
|
if (container_id != 0) {
|
||||||
vector<uint64> ids = transform(queries, [](const Query &x) { return static_cast<uint64>(x.message_id); });
|
vector<uint64> ids = transform(queries, [](const MtprotoQuery &x) { return static_cast<uint64>(x.message_id); });
|
||||||
|
|
||||||
// some acks may be lost here. Nobody will resend them if something goes wrong with query.
|
// some acks may be lost here. Nobody will resend them if something goes wrong with query.
|
||||||
// It is mostly problem for server. We will just drop this answers in next connection
|
// It is mostly problem for server. We will just drop this answers in next connection
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "td/mtproto/RawConnection.h"
|
#include "td/mtproto/RawConnection.h"
|
||||||
#include "td/mtproto/PacketInfo.h"
|
#include "td/mtproto/PacketInfo.h"
|
||||||
#include "td/mtproto/utils.h"
|
#include "td/mtproto/Query.h"
|
||||||
|
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
@ -152,7 +152,7 @@ class SessionConnection
|
|||||||
static constexpr int HTTP_MAX_DELAY = 30; // 0.03s
|
static constexpr int HTTP_MAX_DELAY = 30; // 0.03s
|
||||||
static constexpr int TEMP_KEY_TIMEOUT = 60 * 60 * 24; // one day
|
static constexpr int TEMP_KEY_TIMEOUT = 60 * 60 * 24; // one day
|
||||||
|
|
||||||
vector<Query> to_send_;
|
vector<MtprotoQuery> to_send_;
|
||||||
vector<int64> to_ack_;
|
vector<int64> to_ack_;
|
||||||
double force_send_at_ = 0;
|
double force_send_at_ = 0;
|
||||||
|
|
||||||
|
@ -19,17 +19,6 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
namespace mtproto {
|
|
||||||
struct Query {
|
|
||||||
int64 message_id;
|
|
||||||
int32 seq_no;
|
|
||||||
BufferSlice packet;
|
|
||||||
bool gzip_flag;
|
|
||||||
uint64 invoke_after_id;
|
|
||||||
bool use_quick_ack;
|
|
||||||
};
|
|
||||||
} // namespace mtproto
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Result<typename T::ReturnType> fetch_result(Slice message, bool check_end = true) {
|
Result<typename T::ReturnType> fetch_result(Slice message, bool check_end = true) {
|
||||||
TlParser parser(message);
|
TlParser parser(message);
|
||||||
|
Loading…
Reference in New Issue
Block a user