2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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/mtproto/IStreamTransport.h"
|
2019-07-09 04:01:12 +02:00
|
|
|
#include "td/mtproto/ProxySecret.h"
|
2019-01-31 03:13:59 +01:00
|
|
|
#include "td/mtproto/TransportType.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/net/HttpQuery.h"
|
|
|
|
#include "td/net/HttpReader.h"
|
|
|
|
|
|
|
|
#include "td/utils/buffer.h"
|
2023-08-05 15:09:36 +02:00
|
|
|
#include "td/utils/common.h"
|
2018-09-07 02:41:21 +02:00
|
|
|
#include "td/utils/port/detail/PollableFd.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
namespace mtproto {
|
|
|
|
namespace http {
|
2018-07-27 02:54:25 +02:00
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class Transport final : public IStreamTransport {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2018-07-27 02:54:25 +02:00
|
|
|
explicit Transport(string secret) : secret_(std::move(secret)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
Result<size_t> read_next(BufferSlice *message, uint32 *quick_ack) final TD_WARN_UNUSED_RESULT;
|
|
|
|
bool support_quick_ack() const final {
|
2018-12-31 20:04:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void write(BufferWriter &&message, bool quick_ack) final;
|
|
|
|
bool can_read() const final;
|
|
|
|
bool can_write() const final;
|
|
|
|
void init(ChainBufferReader *input, ChainBufferWriter *output) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
reader_.init(input);
|
|
|
|
output_ = output;
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
size_t max_prepend_size() const final;
|
|
|
|
size_t max_append_size() const final;
|
|
|
|
TransportType get_type() const final {
|
2019-07-09 04:01:12 +02:00
|
|
|
return {TransportType::Http, 0, ProxySecret::from_raw(secret_)};
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
bool use_random_padding() const final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
2018-07-27 02:54:25 +02:00
|
|
|
string secret_;
|
2018-12-31 20:04:05 +01:00
|
|
|
HttpReader reader_;
|
|
|
|
HttpQuery http_query_;
|
2021-11-11 15:39:09 +01:00
|
|
|
ChainBufferWriter *output_ = nullptr;
|
2018-12-31 20:04:05 +01:00
|
|
|
enum { Write, Read } turn_ = Write;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace http
|
|
|
|
} // namespace mtproto
|
|
|
|
} // namespace td
|