2020-11-03 17:34:10 +01:00
|
|
|
//
|
2022-12-31 22:31:16 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2020-11-03 17:34:10 +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/db/KeyValueSyncInterface.h"
|
|
|
|
#include "td/db/TQueue.h"
|
|
|
|
|
|
|
|
#include "td/net/GetHostByNameActor.h"
|
|
|
|
|
2022-01-25 16:18:44 +01:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2020-11-03 17:34:10 +01:00
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/List.h"
|
|
|
|
#include "td/utils/port/IPAddress.h"
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <limits>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
class NetQueryStats;
|
2021-12-12 22:35:46 +01:00
|
|
|
} // namespace td
|
2020-11-03 17:34:10 +01:00
|
|
|
|
|
|
|
namespace telegram_bot_api {
|
|
|
|
|
|
|
|
struct SharedData {
|
|
|
|
std::atomic<td::uint64> query_count_{0};
|
2022-10-04 17:27:50 +02:00
|
|
|
std::atomic<size_t> query_list_size_{0};
|
2020-11-03 17:34:10 +01:00
|
|
|
std::atomic<int> next_verbosity_level_{-1};
|
|
|
|
|
2022-10-04 17:27:50 +02:00
|
|
|
// not thread-safe, must be used from a single thread
|
2020-11-03 17:34:10 +01:00
|
|
|
td::ListNode query_list_;
|
|
|
|
td::unique_ptr<td::KeyValueSyncInterface> webhook_db_;
|
|
|
|
td::unique_ptr<td::TQueue> tqueue_;
|
|
|
|
|
|
|
|
double unix_time_difference_{-1e100};
|
|
|
|
|
|
|
|
static constexpr size_t TQUEUE_EVENT_BUFFER_SIZE = 1000;
|
|
|
|
td::TQueue::Event event_buffer_[TQUEUE_EVENT_BUFFER_SIZE];
|
|
|
|
|
|
|
|
td::int32 get_unix_time(double now) const {
|
|
|
|
auto result = unix_time_difference_ + now;
|
|
|
|
if (result <= 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (result >= std::numeric_limits<td::int32>::max()) {
|
|
|
|
return std::numeric_limits<td::int32>::max();
|
|
|
|
}
|
|
|
|
return static_cast<td::int32>(result);
|
|
|
|
}
|
2022-11-26 23:31:00 +01:00
|
|
|
|
|
|
|
static td::int32 get_file_gc_scheduler_id() {
|
|
|
|
// the same scheduler as for file GC in Td
|
|
|
|
return 2;
|
|
|
|
}
|
2023-07-25 21:26:12 +02:00
|
|
|
|
|
|
|
static td::int32 get_client_scheduler_id() {
|
|
|
|
// the thread for ClientManager and all Clients
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static td::int32 get_watchdog_scheduler_id() {
|
|
|
|
// the thread for watchdogs
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
static td::int32 get_slow_incoming_http_scheduler_id() {
|
|
|
|
// the thread for slow incoming HTTP connections
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
static td::int32 get_slow_outgoing_http_scheduler_id() {
|
|
|
|
// the thread for slow outgoing HTTP connections
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
static td::int32 get_dns_resolver_scheduler_id() {
|
|
|
|
// the thread for DNS resolving
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
2023-07-25 21:32:05 +02:00
|
|
|
static td::int32 get_binlog_scheduler_id() {
|
|
|
|
// the thread for TQueue and webhook binlogs
|
2023-07-25 21:26:12 +02:00
|
|
|
return 9;
|
|
|
|
}
|
2023-07-25 21:32:05 +02:00
|
|
|
|
|
|
|
static td::int32 get_webhook_certificate_scheduler_id() {
|
|
|
|
// the thread for webhook certificate processing
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
static td::int32 get_thread_count() {
|
|
|
|
return 11;
|
|
|
|
}
|
2020-11-03 17:34:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ClientParameters {
|
2021-06-22 20:26:41 +02:00
|
|
|
td::string working_directory_;
|
2021-06-23 01:03:22 +02:00
|
|
|
bool allow_colon_in_filenames_ = true;
|
2021-06-22 20:26:41 +02:00
|
|
|
|
2020-11-03 17:34:10 +01:00
|
|
|
bool local_mode_ = false;
|
|
|
|
|
|
|
|
td::int32 api_id_ = 0;
|
|
|
|
td::string api_hash_;
|
|
|
|
|
2021-03-14 03:28:30 +01:00
|
|
|
td::string version_;
|
|
|
|
|
2020-11-03 17:34:10 +01:00
|
|
|
td::int32 default_max_webhook_connections_ = 0;
|
|
|
|
td::IPAddress webhook_proxy_ip_address_;
|
|
|
|
|
2020-11-21 15:38:11 +01:00
|
|
|
double start_time_ = 0;
|
2020-11-03 17:34:10 +01:00
|
|
|
|
|
|
|
td::ActorId<td::GetHostByNameActor> get_host_by_name_actor_id_;
|
|
|
|
|
|
|
|
std::shared_ptr<SharedData> shared_data_;
|
|
|
|
|
|
|
|
std::shared_ptr<td::NetQueryStats> net_query_stats_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace telegram_bot_api
|