2018-09-05 08:27:01 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
// Fetch unit state
|
2018-10-23 18:13:48 +02:00
|
|
|
namespace ircd::m::fetch
|
2018-09-05 08:27:01 +02:00
|
|
|
{
|
2019-04-12 12:13:40 +02:00
|
|
|
struct request; // m/fetch.h
|
2019-04-30 22:57:12 +02:00
|
|
|
struct evaltab;
|
2018-09-05 08:27:01 +02:00
|
|
|
|
2019-04-11 06:16:00 +02:00
|
|
|
extern ctx::dock dock;
|
|
|
|
extern std::set<request, std::less<>> requests;
|
2019-04-12 12:13:40 +02:00
|
|
|
extern std::multimap<room::id, request *> rooms;
|
2019-04-11 06:16:00 +02:00
|
|
|
extern std::deque<decltype(requests)::iterator> complete;
|
|
|
|
extern ctx::context eval_context;
|
|
|
|
extern ctx::context request_context;
|
2018-10-23 18:13:48 +02:00
|
|
|
extern hookfn<vm::eval &> hook;
|
2019-06-06 02:12:02 +02:00
|
|
|
extern conf::item<size_t> requests_max;
|
2019-04-26 14:28:18 +02:00
|
|
|
extern conf::item<seconds> auth_timeout;
|
2019-04-15 20:37:13 +02:00
|
|
|
extern conf::item<seconds> timeout;
|
2019-04-12 05:53:57 +02:00
|
|
|
extern conf::item<bool> enable;
|
2019-07-27 00:39:23 +02:00
|
|
|
extern log::log log;
|
2018-10-23 18:13:48 +02:00
|
|
|
|
2019-07-18 00:30:57 +02:00
|
|
|
static bool operator<(const request &a, const request &b) noexcept;
|
|
|
|
static bool operator<(const request &a, const string_view &b) noexcept;
|
|
|
|
static bool operator<(const string_view &a, const request &b) noexcept;
|
|
|
|
|
2019-04-15 20:37:13 +02:00
|
|
|
static bool timedout(const request &, const time_t &now);
|
2019-04-12 12:13:40 +02:00
|
|
|
static string_view select_origin(request &, const string_view &);
|
|
|
|
static string_view select_random_origin(request &);
|
|
|
|
static void finish(request &);
|
|
|
|
static void retry(request &);
|
2019-04-12 14:29:12 +02:00
|
|
|
static bool start(request &, m::v1::event::opts &);
|
|
|
|
static bool start(request &);
|
2019-04-12 12:13:40 +02:00
|
|
|
static bool handle(request &);
|
|
|
|
|
2019-04-11 06:16:00 +02:00
|
|
|
static void eval_handle(const decltype(requests)::iterator &);
|
|
|
|
static void eval_handle();
|
|
|
|
static void eval_worker();
|
|
|
|
static void request_handle(const decltype(requests)::iterator &);
|
|
|
|
static void request_handle();
|
2019-04-12 22:03:08 +02:00
|
|
|
static size_t request_cleanup();
|
2019-04-11 06:16:00 +02:00
|
|
|
static void request_worker();
|
2019-04-22 21:28:45 +02:00
|
|
|
|
2019-05-17 17:18:31 +02:00
|
|
|
template<class... args> static bool submit(const event::id &, const room::id &, const size_t &bufsz = 8_KiB, args&&...);
|
|
|
|
|
2019-04-30 22:57:12 +02:00
|
|
|
static void hook_handle_prev(const event &, vm::eval &, evaltab &, const room &);
|
|
|
|
static void hook_handle_auth(const event &, vm::eval &, evaltab &, const room &);
|
|
|
|
static void hook_handle(const event &, vm::eval &);
|
2019-04-22 21:28:45 +02:00
|
|
|
|
2018-10-23 18:13:48 +02:00
|
|
|
static void init();
|
|
|
|
static void fini();
|
2018-09-05 08:27:01 +02:00
|
|
|
}
|
|
|
|
|
2019-04-30 22:57:12 +02:00
|
|
|
struct ircd::m::fetch::evaltab
|
|
|
|
{
|
|
|
|
size_t auth_count {0};
|
|
|
|
size_t auth_exists {0};
|
|
|
|
size_t prev_count {0};
|
|
|
|
size_t prev_exists {0};
|
|
|
|
size_t prev_fetching {0};
|
|
|
|
size_t prev_fetched {0};
|
|
|
|
};
|