2018-06-03 19:02:19 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
2019-08-28 00:03:44 +02:00
|
|
|
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
2018-06-03 19:02:19 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2019-08-28 00:03:44 +02:00
|
|
|
namespace ircd::m::fetch
|
|
|
|
{
|
2019-08-31 10:53:58 +02:00
|
|
|
static bool operator==(const opts &a, const opts &b) noexcept;
|
|
|
|
static bool operator==(const request &a, const opts &b) noexcept;
|
|
|
|
static bool operator==(const opts &a, const request &b) noexcept;
|
|
|
|
static bool operator==(const request &a, const request &b) noexcept;
|
|
|
|
static bool operator<(const opts &a, const opts &b) noexcept;
|
2019-08-30 03:30:47 +02:00
|
|
|
static bool operator<(const request &a, const opts &b) noexcept;
|
|
|
|
static bool operator<(const opts &a, const request &b) noexcept;
|
2019-08-31 10:53:58 +02:00
|
|
|
static bool operator<(const request &a, const request &b) noexcept;
|
2019-08-28 00:03:44 +02:00
|
|
|
|
|
|
|
extern ctx::dock dock;
|
|
|
|
extern ctx::mutex requests_mutex;
|
|
|
|
extern std::set<request, std::less<>> requests;
|
|
|
|
extern ctx::context request_context;
|
2019-09-16 21:12:43 +02:00
|
|
|
extern conf::item<size_t> backfill_limit_default;
|
2019-08-28 00:03:44 +02:00
|
|
|
extern conf::item<size_t> requests_max;
|
|
|
|
extern conf::item<seconds> timeout;
|
|
|
|
extern conf::item<bool> enable;
|
|
|
|
extern log::log log;
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
static bool timedout(const request &, const system_point &now);
|
|
|
|
static void _check_event(const request &, const m::event &);
|
2019-08-28 02:36:14 +02:00
|
|
|
static void check_response(const request &, const json::object &);
|
2019-08-28 00:03:44 +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-08-30 03:30:47 +02:00
|
|
|
static bool start(request &, const string_view &remote);
|
2019-08-28 00:03:44 +02:00
|
|
|
static bool start(request &);
|
2019-08-30 03:30:47 +02:00
|
|
|
static void handle_result(request &);
|
2019-08-28 00:03:44 +02:00
|
|
|
static bool handle(request &);
|
|
|
|
|
2019-09-04 02:05:52 +02:00
|
|
|
static bool request_handle(const decltype(requests)::iterator &);
|
2019-08-28 00:03:44 +02:00
|
|
|
static void request_handle();
|
|
|
|
static size_t request_cleanup();
|
|
|
|
static void request_worker();
|
|
|
|
}
|
2018-06-03 19:02:19 +02:00
|
|
|
|
2019-07-27 00:39:23 +02:00
|
|
|
decltype(ircd::m::fetch::log)
|
|
|
|
ircd::m::fetch::log
|
|
|
|
{
|
2019-08-01 04:40:18 +02:00
|
|
|
"m.fetch"
|
2019-07-27 00:39:23 +02:00
|
|
|
};
|
|
|
|
|
2019-04-12 05:53:57 +02:00
|
|
|
decltype(ircd::m::fetch::enable)
|
|
|
|
ircd::m::fetch::enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fetch.enable" },
|
2019-04-23 22:27:53 +02:00
|
|
|
{ "default", true },
|
2019-04-12 05:53:57 +02:00
|
|
|
};
|
|
|
|
|
2019-04-15 20:37:13 +02:00
|
|
|
decltype(ircd::m::fetch::timeout)
|
|
|
|
ircd::m::fetch::timeout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fetch.timeout" },
|
2019-04-26 14:28:18 +02:00
|
|
|
{ "default", 5L },
|
|
|
|
};
|
|
|
|
|
2019-06-06 02:12:02 +02:00
|
|
|
decltype(ircd::m::fetch::requests_max)
|
|
|
|
ircd::m::fetch::requests_max
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fetch.requests.max" },
|
|
|
|
{ "default", 256L },
|
|
|
|
};
|
|
|
|
|
2019-09-16 21:12:43 +02:00
|
|
|
decltype(ircd::m::fetch::backfill_limit_default)
|
|
|
|
ircd::m::fetch::backfill_limit_default
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fetch.backfill.limit.default" },
|
|
|
|
{ "default", 96L },
|
|
|
|
};
|
|
|
|
|
2020-03-16 21:37:46 +01:00
|
|
|
decltype(ircd::m::fetch::dock)
|
|
|
|
ircd::m::fetch::dock;
|
2019-04-11 06:16:00 +02:00
|
|
|
|
|
|
|
decltype(ircd::m::fetch::requests)
|
|
|
|
ircd::m::fetch::requests;
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
decltype(ircd::m::fetch::requests_mutex)
|
|
|
|
ircd::m::fetch::requests_mutex;
|
|
|
|
|
2020-03-16 21:37:46 +01:00
|
|
|
decltype(ircd::m::fetch::request_context)
|
|
|
|
ircd::m::fetch::request_context
|
|
|
|
{
|
|
|
|
"m.fetch.req",
|
|
|
|
1_MiB,
|
|
|
|
&request_worker,
|
|
|
|
context::POST
|
|
|
|
};
|
2019-04-11 06:16:00 +02:00
|
|
|
|
2019-04-22 21:32:54 +02:00
|
|
|
//
|
|
|
|
// init
|
|
|
|
//
|
|
|
|
|
2019-09-28 06:18:07 +02:00
|
|
|
ircd::m::fetch::init::init()
|
2019-04-22 21:32:54 +02:00
|
|
|
{
|
2020-03-16 21:37:46 +01:00
|
|
|
assert(requests.empty());
|
2019-04-22 21:32:54 +02:00
|
|
|
}
|
|
|
|
|
2019-09-28 06:18:07 +02:00
|
|
|
ircd::m::fetch::init::~init()
|
|
|
|
noexcept
|
2019-04-22 21:32:54 +02:00
|
|
|
{
|
|
|
|
request_context.terminate();
|
|
|
|
request_context.join();
|
|
|
|
requests.clear();
|
|
|
|
assert(requests.empty());
|
2019-04-26 13:00:58 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 06:16:00 +02:00
|
|
|
//
|
2019-08-28 04:34:46 +02:00
|
|
|
// <ircd/m/fetch.h>
|
2019-04-11 06:16:00 +02:00
|
|
|
//
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
ircd::ctx::future<ircd::m::fetch::result>
|
|
|
|
ircd::m::fetch::start(opts opts)
|
|
|
|
{
|
|
|
|
assert(opts.room_id && opts.event_id);
|
2020-05-12 06:32:48 +02:00
|
|
|
if(unlikely(run::level == run::level::QUIT))
|
|
|
|
throw m::UNAVAILABLE
|
|
|
|
{
|
|
|
|
"Cannot start fetch requests at this time."
|
|
|
|
};
|
2019-08-30 03:30:47 +02:00
|
|
|
|
|
|
|
// in case requests are started before runlevel RUN they are stalled here
|
2020-03-16 21:11:00 +01:00
|
|
|
run::barrier<m::UNAVAILABLE>
|
|
|
|
{
|
|
|
|
"The fetch unit is unavailable to start requests."
|
|
|
|
};
|
2019-04-12 23:15:06 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
// in case the fetch unit has reached capacity the context will yield.
|
2019-08-27 00:12:43 +02:00
|
|
|
dock.wait([]
|
|
|
|
{
|
|
|
|
return count() < size_t(requests_max);
|
|
|
|
});
|
2019-06-06 02:12:02 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
// the state in this unit is primarily driven by the fetch::context; in
|
|
|
|
// some cases it may want to prevent others from changing this state until
|
|
|
|
// it's ready to accept.
|
|
|
|
std::unique_lock lock
|
|
|
|
{
|
|
|
|
requests_mutex
|
|
|
|
};
|
|
|
|
|
|
|
|
const scope_notify dock
|
|
|
|
{
|
|
|
|
fetch::dock
|
|
|
|
};
|
|
|
|
|
|
|
|
auto it
|
|
|
|
{
|
|
|
|
requests.lower_bound(opts)
|
|
|
|
};
|
|
|
|
|
2019-09-01 08:21:42 +02:00
|
|
|
const bool exists
|
2019-08-30 03:30:47 +02:00
|
|
|
{
|
2019-09-01 08:21:42 +02:00
|
|
|
it != end(requests) && *it == opts
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(!exists || it->opts.room_id == opts.room_id);
|
|
|
|
if(!exists)
|
|
|
|
it = requests.emplace_hint(it, opts);
|
2019-08-30 03:30:47 +02:00
|
|
|
|
|
|
|
auto &request
|
|
|
|
{
|
|
|
|
const_cast<fetch::request &>(*it)
|
|
|
|
};
|
|
|
|
|
|
|
|
ctx::future<result> ret
|
|
|
|
{
|
|
|
|
request.promise
|
|
|
|
};
|
|
|
|
|
2019-09-01 08:21:42 +02:00
|
|
|
if(!exists)
|
|
|
|
start(request);
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
return ret;
|
2019-04-12 13:02:09 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 03:50:17 +02:00
|
|
|
size_t
|
|
|
|
ircd::m::fetch::count()
|
|
|
|
{
|
2019-07-21 02:01:34 +02:00
|
|
|
return requests.size();
|
|
|
|
}
|
2019-06-05 03:50:17 +02:00
|
|
|
|
2019-07-21 02:01:34 +02:00
|
|
|
bool
|
2019-08-30 03:30:47 +02:00
|
|
|
ircd::m::fetch::exists(const opts &opts)
|
2019-07-21 02:01:34 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
return requests.count(opts);
|
2019-06-05 03:50:17 +02:00
|
|
|
}
|
|
|
|
|
2019-04-12 13:02:09 +02:00
|
|
|
bool
|
|
|
|
ircd::m::fetch::for_each(const std::function<bool (request &)> &closure)
|
|
|
|
{
|
|
|
|
for(auto &request : requests)
|
|
|
|
if(!closure(const_cast<fetch::request &>(request)))
|
2019-03-27 21:44:33 +01:00
|
|
|
return false;
|
2018-09-05 08:27:01 +02:00
|
|
|
|
2019-03-27 21:44:33 +01:00
|
|
|
return true;
|
2018-09-05 08:27:01 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::m::fetch::reflect(const op &op)
|
2019-05-17 17:18:31 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
switch(op)
|
2019-05-17 17:18:31 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
case op::noop: return "noop";
|
2019-08-30 04:29:40 +02:00
|
|
|
case op::auth: return "auth";
|
2019-08-30 06:48:47 +02:00
|
|
|
case op::event: return "event";
|
|
|
|
case op::backfill: return "backfill";
|
2019-05-17 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
return "?????";
|
2019-05-17 17:18:31 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
//
|
|
|
|
// internal
|
|
|
|
//
|
|
|
|
|
2019-04-11 06:16:00 +02:00
|
|
|
//
|
|
|
|
// request worker
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::fetch::request_worker()
|
|
|
|
try
|
|
|
|
{
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
dock.wait([]
|
|
|
|
{
|
|
|
|
return std::any_of(begin(requests), end(requests), []
|
2019-08-27 00:12:43 +02:00
|
|
|
(const auto &request)
|
2019-04-11 06:16:00 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
return !request.finished;
|
2019-04-11 06:16:00 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
request_handle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "fetch request worker :%s",
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
void
|
|
|
|
ircd::m::fetch::request_handle()
|
2019-04-11 08:29:56 +02:00
|
|
|
{
|
2019-08-27 00:12:43 +02:00
|
|
|
std::unique_lock lock
|
2019-04-11 08:29:56 +02:00
|
|
|
{
|
2019-08-27 00:12:43 +02:00
|
|
|
requests_mutex
|
|
|
|
};
|
2019-04-12 22:03:08 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
const scope_notify notify
|
|
|
|
{
|
|
|
|
fetch::dock
|
|
|
|
};
|
|
|
|
|
|
|
|
static const auto dereferencer{[]
|
|
|
|
(auto &it) -> server::request &
|
|
|
|
{
|
2019-09-09 02:11:28 +02:00
|
|
|
// If the request doesn't have a server::request future attached
|
|
|
|
// during this pass we reference this default constructed static
|
|
|
|
// instance which when_any() will treat as a no-op.
|
|
|
|
static server::request request_skip;
|
2019-09-04 07:14:53 +02:00
|
|
|
auto &request(mutable_cast(*it));
|
2019-09-09 02:11:28 +02:00
|
|
|
return request.future?
|
|
|
|
*request.future:
|
|
|
|
request_skip;
|
2019-08-30 03:30:47 +02:00
|
|
|
}};
|
2019-04-11 08:29:56 +02:00
|
|
|
|
2019-04-11 06:16:00 +02:00
|
|
|
auto next
|
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
ctx::when_any(requests.begin(), requests.end(), dereferencer)
|
2019-04-11 06:16:00 +02:00
|
|
|
};
|
|
|
|
|
2019-09-04 02:05:52 +02:00
|
|
|
bool timedout{true};
|
2019-04-11 06:16:00 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
const unlock_guard unlock
|
|
|
|
{
|
|
|
|
lock
|
|
|
|
};
|
|
|
|
|
2019-09-04 02:05:52 +02:00
|
|
|
timedout = !next.wait(seconds(timeout), std::nothrow);
|
2019-08-27 00:12:43 +02:00
|
|
|
};
|
2019-04-11 06:16:00 +02:00
|
|
|
|
2019-09-04 02:05:52 +02:00
|
|
|
if(likely(!timedout))
|
2019-04-11 06:16:00 +02:00
|
|
|
{
|
2019-09-04 02:05:52 +02:00
|
|
|
const auto it
|
|
|
|
{
|
|
|
|
next.get()
|
|
|
|
};
|
2019-04-11 06:16:00 +02:00
|
|
|
|
2019-09-04 02:05:52 +02:00
|
|
|
if(it != end(requests))
|
|
|
|
if(!request_handle(it))
|
|
|
|
return;
|
|
|
|
}
|
2019-04-11 06:16:00 +02:00
|
|
|
|
2019-09-04 02:05:52 +02:00
|
|
|
request_cleanup();
|
2019-04-11 06:16:00 +02:00
|
|
|
}
|
|
|
|
|
2019-09-04 02:05:52 +02:00
|
|
|
bool
|
2019-04-11 06:16:00 +02:00
|
|
|
ircd::m::fetch::request_handle(const decltype(requests)::iterator &it)
|
|
|
|
{
|
|
|
|
auto &request
|
|
|
|
{
|
2019-09-04 02:05:52 +02:00
|
|
|
mutable_cast(*it)
|
2019-04-11 06:16:00 +02:00
|
|
|
};
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
if(!request.finished)
|
|
|
|
if(!handle(request))
|
2019-09-04 02:05:52 +02:00
|
|
|
return false;
|
2019-04-11 06:16:00 +02:00
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
requests.erase(it);
|
2019-09-04 02:05:52 +02:00
|
|
|
return true;
|
2019-04-11 06:16:00 +02:00
|
|
|
}
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
size_t
|
|
|
|
ircd::m::fetch::request_cleanup()
|
2019-09-04 02:05:52 +02:00
|
|
|
try
|
2019-04-11 06:16:00 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
const auto now
|
|
|
|
{
|
|
|
|
ircd::now<system_point>()
|
|
|
|
};
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
size_t ret(0);
|
|
|
|
for(auto it(begin(requests)); it != end(requests); ++it)
|
2019-04-11 06:16:00 +02:00
|
|
|
{
|
2019-09-04 02:05:52 +02:00
|
|
|
auto &request(mutable_cast(*it));
|
2019-08-27 00:12:43 +02:00
|
|
|
if(!request.started)
|
|
|
|
start(request);
|
2019-04-11 08:29:56 +02:00
|
|
|
|
2019-09-04 02:05:52 +02:00
|
|
|
else if(!request.finished && timedout(request, now))
|
2019-08-27 00:12:43 +02:00
|
|
|
retry(request);
|
|
|
|
}
|
2019-04-11 06:16:00 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
auto it(begin(requests)); while(it != end(requests))
|
2019-04-11 06:16:00 +02:00
|
|
|
{
|
2019-09-04 02:05:52 +02:00
|
|
|
auto &request(mutable_cast(*it));
|
2019-08-30 03:30:47 +02:00
|
|
|
if(!!request.finished)
|
2019-08-27 00:12:43 +02:00
|
|
|
{
|
|
|
|
it = requests.erase(it);
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
else ++it;
|
|
|
|
}
|
2019-04-12 12:36:03 +02:00
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
return ret;
|
2019-04-11 06:16:00 +02:00
|
|
|
}
|
2019-09-04 02:05:52 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "request_cleanup(): %s",
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2019-04-11 06:16:00 +02:00
|
|
|
|
2018-09-05 08:27:01 +02:00
|
|
|
//
|
|
|
|
// fetch::request
|
|
|
|
//
|
|
|
|
|
2019-04-12 14:29:12 +02:00
|
|
|
bool
|
2019-09-16 21:21:20 +02:00
|
|
|
ircd::m::fetch::start(request &request)
|
|
|
|
try
|
2018-09-05 08:27:01 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
assert(!request.finished);
|
2019-08-30 04:28:37 +02:00
|
|
|
if(!request.started && !request.origin)
|
|
|
|
request.origin = request.opts.hint;
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
if(!request.started)
|
2019-08-30 03:30:47 +02:00
|
|
|
request.started = ircd::now<system_point>();
|
2019-08-27 00:12:43 +02:00
|
|
|
|
2019-04-16 02:18:31 +02:00
|
|
|
if(!request.origin)
|
|
|
|
select_random_origin(request);
|
2019-08-27 00:12:43 +02:00
|
|
|
|
2019-09-16 21:21:20 +02:00
|
|
|
for(; request.origin; select_random_origin(request))
|
2019-08-27 00:12:43 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
if(start(request, request.origin))
|
2019-08-27 00:12:43 +02:00
|
|
|
return true;
|
2019-04-16 02:18:31 +02:00
|
|
|
|
2019-09-16 21:21:20 +02:00
|
|
|
if(request.attempted.size() > request.opts.attempt_limit - 1UL)
|
|
|
|
break;
|
2019-08-27 00:12:43 +02:00
|
|
|
}
|
|
|
|
|
2019-09-16 21:36:38 +02:00
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"Cannot find any server to fetch %s in %s in %zu attempts",
|
|
|
|
string_view{request.opts.event_id},
|
|
|
|
string_view{request.opts.room_id},
|
|
|
|
request.attempted.size(),
|
|
|
|
};
|
2019-08-27 00:12:43 +02:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
assert(!request.finished);
|
|
|
|
request.eptr = std::current_exception();
|
|
|
|
finish(request);
|
|
|
|
return false;
|
2018-09-05 08:27:01 +02:00
|
|
|
}
|
|
|
|
|
2019-04-12 14:29:12 +02:00
|
|
|
bool
|
2019-04-12 12:13:40 +02:00
|
|
|
ircd::m::fetch::start(request &request,
|
2019-08-30 03:30:47 +02:00
|
|
|
const string_view &remote)
|
2019-04-12 14:29:12 +02:00
|
|
|
try
|
2018-09-05 08:27:01 +02:00
|
|
|
{
|
2020-05-12 06:32:48 +02:00
|
|
|
assert(!request.finished);
|
2019-09-11 03:02:26 +02:00
|
|
|
if(unlikely(run::level != run::level::RUN))
|
|
|
|
throw m::UNAVAILABLE
|
|
|
|
{
|
2020-05-12 06:32:48 +02:00
|
|
|
"Cannot start fetch requests in runlevel."
|
2019-09-11 03:02:26 +02:00
|
|
|
};
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
request.last = ircd::now<system_point>();
|
2019-04-12 12:13:40 +02:00
|
|
|
if(!request.started)
|
2019-08-30 03:30:47 +02:00
|
|
|
request.started = request.last;
|
2018-09-05 08:27:01 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
switch(request.opts.op)
|
2018-09-05 08:27:01 +02:00
|
|
|
{
|
2019-08-30 06:48:47 +02:00
|
|
|
case op::noop:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case op::auth:
|
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
fed::event_auth::opts opts;
|
2019-08-30 06:48:47 +02:00
|
|
|
opts.remote = remote;
|
2020-03-06 04:35:20 +01:00
|
|
|
request.future = std::make_unique<fed::event_auth>
|
2019-08-30 06:48:47 +02:00
|
|
|
(
|
|
|
|
request.opts.room_id,
|
|
|
|
request.opts.event_id,
|
|
|
|
request.buf,
|
|
|
|
std::move(opts)
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
case op::event:
|
2019-07-14 02:18:53 +02:00
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
fed::event::opts opts;
|
2019-08-30 03:30:47 +02:00
|
|
|
opts.remote = remote;
|
2020-03-06 04:35:20 +01:00
|
|
|
request.future = std::make_unique<fed::event>
|
2019-08-30 03:30:47 +02:00
|
|
|
(
|
|
|
|
request.opts.event_id,
|
|
|
|
request.buf,
|
|
|
|
std::move(opts)
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-30 06:48:47 +02:00
|
|
|
case op::backfill:
|
2019-08-30 04:29:40 +02:00
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
fed::backfill::opts opts;
|
2019-08-30 04:29:40 +02:00
|
|
|
opts.remote = remote;
|
2019-09-16 21:12:43 +02:00
|
|
|
opts.limit = request.opts.backfill_limit;
|
|
|
|
opts.limit = opts.limit?: size_t(backfill_limit_default);
|
2019-08-30 06:48:47 +02:00
|
|
|
opts.event_id = request.opts.event_id;
|
2020-03-06 04:35:20 +01:00
|
|
|
request.future = std::make_unique<fed::backfill>
|
2019-08-30 04:29:40 +02:00
|
|
|
(
|
|
|
|
request.opts.room_id,
|
|
|
|
request.buf,
|
|
|
|
std::move(opts)
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2019-07-14 02:18:53 +02:00
|
|
|
}
|
2019-04-11 06:16:00 +02:00
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
log, "Starting %s request for %s in %s from '%s'",
|
|
|
|
reflect(request.opts.op),
|
|
|
|
string_view{request.opts.event_id},
|
|
|
|
string_view{request.opts.room_id},
|
2019-04-12 12:13:40 +02:00
|
|
|
string_view{request.origin},
|
2019-04-11 06:16:00 +02:00
|
|
|
};
|
2019-04-12 12:13:40 +02:00
|
|
|
|
|
|
|
dock.notify_all();
|
2019-04-12 14:29:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
2019-09-11 03:02:26 +02:00
|
|
|
catch(const m::UNAVAILABLE &e)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
2020-03-09 17:40:05 +01:00
|
|
|
catch(const ctx::interrupted &e)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
2019-04-24 04:08:12 +02:00
|
|
|
catch(const http::error &e)
|
2019-04-12 14:29:12 +02:00
|
|
|
{
|
2020-03-09 17:29:17 +01:00
|
|
|
log::derror
|
2019-04-12 23:26:10 +02:00
|
|
|
{
|
2020-03-09 17:29:17 +01:00
|
|
|
log, "Starting %s request for %s in %s to '%s' :%s %s",
|
2019-08-30 03:30:47 +02:00
|
|
|
reflect(request.opts.op),
|
|
|
|
string_view{request.opts.event_id},
|
|
|
|
string_view{request.opts.room_id},
|
2019-04-24 04:08:12 +02:00
|
|
|
string_view{request.origin},
|
|
|
|
e.what(),
|
|
|
|
e.content,
|
2019-04-12 23:26:10 +02:00
|
|
|
};
|
|
|
|
|
2019-04-24 04:08:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-09 17:29:17 +01:00
|
|
|
catch(const server::error &e)
|
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
log, "Starting %s request for %s in %s to '%s' :%s",
|
|
|
|
reflect(request.opts.op),
|
|
|
|
string_view{request.opts.event_id},
|
|
|
|
string_view{request.opts.room_id},
|
|
|
|
string_view{request.origin},
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-24 04:08:12 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2020-03-09 17:29:17 +01:00
|
|
|
log::error
|
2019-04-12 14:29:12 +02:00
|
|
|
{
|
2020-03-09 17:29:17 +01:00
|
|
|
log, "Starting %s request for %s in %s to '%s' :%s",
|
2019-08-30 03:30:47 +02:00
|
|
|
reflect(request.opts.op),
|
|
|
|
string_view{request.opts.event_id},
|
|
|
|
string_view{request.opts.room_id},
|
2019-04-12 14:29:12 +02:00
|
|
|
string_view{request.origin},
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return false;
|
2018-09-05 08:27:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
2019-04-12 12:13:40 +02:00
|
|
|
ircd::m::fetch::select_random_origin(request &request)
|
2018-09-05 08:27:01 +02:00
|
|
|
{
|
|
|
|
const m::room::origins origins
|
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
request.opts.room_id
|
2018-09-05 08:27:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// copies randomly selected origin into the attempted set.
|
2019-04-12 12:13:40 +02:00
|
|
|
const auto closure{[&request]
|
2018-09-05 08:27:01 +02:00
|
|
|
(const string_view &origin)
|
|
|
|
{
|
2019-04-12 12:13:40 +02:00
|
|
|
select_origin(request, origin);
|
2018-09-05 08:27:01 +02:00
|
|
|
}};
|
|
|
|
|
|
|
|
// Tests if origin is potentially viable
|
2019-04-12 12:13:40 +02:00
|
|
|
const auto proffer{[&request]
|
2018-09-05 08:27:01 +02:00
|
|
|
(const string_view &origin)
|
|
|
|
{
|
2018-10-01 22:59:17 +02:00
|
|
|
// Don't want to request from myself.
|
|
|
|
if(my_host(origin))
|
|
|
|
return false;
|
|
|
|
|
2018-09-05 08:27:01 +02:00
|
|
|
// Don't want to use a peer we already tried and failed with.
|
2019-04-12 12:13:40 +02:00
|
|
|
if(request.attempted.count(origin))
|
2018-09-05 08:27:01 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Don't want to use a peer marked with an error by ircd::server
|
2020-04-26 04:52:24 +02:00
|
|
|
if(fed::errant(origin))
|
2018-09-05 08:27:01 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}};
|
|
|
|
|
2019-04-25 15:45:03 +02:00
|
|
|
request.origin = {};
|
2019-09-16 21:36:38 +02:00
|
|
|
origins.random(closure, proffer);
|
2019-04-12 12:13:40 +02:00
|
|
|
return request.origin;
|
2018-09-05 08:27:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
2019-04-12 12:13:40 +02:00
|
|
|
ircd::m::fetch::select_origin(request &request,
|
|
|
|
const string_view &origin)
|
2018-09-05 08:27:01 +02:00
|
|
|
{
|
|
|
|
const auto iit
|
|
|
|
{
|
2019-04-12 12:13:40 +02:00
|
|
|
request.attempted.emplace(std::string{origin})
|
2018-09-05 08:27:01 +02:00
|
|
|
};
|
|
|
|
|
2019-04-12 12:13:40 +02:00
|
|
|
request.origin = *iit.first;
|
|
|
|
return request.origin;
|
2018-09-05 08:27:01 +02:00
|
|
|
}
|
|
|
|
|
2018-10-23 18:13:48 +02:00
|
|
|
bool
|
2019-04-12 12:13:40 +02:00
|
|
|
ircd::m::fetch::handle(request &request)
|
2018-09-05 08:27:01 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
if(likely(request.future))
|
|
|
|
handle_result(request);
|
2019-04-11 06:16:00 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
if(!request.eptr)
|
|
|
|
finish(request);
|
|
|
|
else
|
|
|
|
retry(request);
|
2019-08-28 02:36:14 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
return !!request.finished;
|
|
|
|
}
|
2019-08-28 02:36:14 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
void
|
|
|
|
ircd::m::fetch::handle_result(request &request)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto code
|
2018-09-05 08:27:01 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
request.future->get()
|
|
|
|
};
|
2019-04-11 06:16:00 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
const string_view &content
|
|
|
|
{
|
|
|
|
request.future->in.content
|
|
|
|
};
|
2018-09-05 08:27:01 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
check_response(request, content);
|
|
|
|
|
|
|
|
char pbuf[48];
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "Received %u %s good %s %s in %s from '%s' %s",
|
|
|
|
uint(code),
|
|
|
|
status(code),
|
|
|
|
reflect(request.opts.op),
|
|
|
|
string_view{request.opts.event_id},
|
|
|
|
string_view{request.opts.room_id},
|
|
|
|
string_view{request.origin},
|
|
|
|
pretty(pbuf, iec(size(content))),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
request.eptr = std::current_exception();
|
2018-10-23 18:13:48 +02:00
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
log::derror
|
|
|
|
{
|
2019-09-08 00:10:28 +02:00
|
|
|
log, "%s error for %s %s in %s :%s",
|
|
|
|
string_view{request.origin},
|
2019-08-30 03:30:47 +02:00
|
|
|
reflect(request.opts.op),
|
|
|
|
string_view{request.opts.event_id},
|
|
|
|
string_view{request.opts.room_id},
|
|
|
|
what(request.eptr),
|
|
|
|
};
|
2018-09-05 08:27:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-04-12 12:13:40 +02:00
|
|
|
ircd::m::fetch::retry(request &request)
|
2018-09-05 08:27:01 +02:00
|
|
|
try
|
|
|
|
{
|
2019-04-16 00:26:52 +02:00
|
|
|
assert(!request.finished);
|
2019-08-30 03:30:47 +02:00
|
|
|
assert(!!request.started && !!request.last);
|
2019-08-27 00:12:43 +02:00
|
|
|
|
2019-09-04 07:14:53 +02:00
|
|
|
if(request.future)
|
|
|
|
{
|
|
|
|
server::cancel(*request.future);
|
|
|
|
request.future.reset(nullptr);
|
|
|
|
}
|
|
|
|
|
2019-04-12 12:13:40 +02:00
|
|
|
request.eptr = std::exception_ptr{};
|
|
|
|
request.origin = {};
|
|
|
|
start(request);
|
2018-09-05 08:27:01 +02:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
2019-04-12 12:13:40 +02:00
|
|
|
request.eptr = std::current_exception();
|
|
|
|
finish(request);
|
2018-06-03 19:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-04-12 12:13:40 +02:00
|
|
|
ircd::m::fetch::finish(request &request)
|
2018-09-05 08:27:01 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
request.finished = ircd::now<system_point>();
|
2019-08-27 00:12:43 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, request.eptr? log::DERROR: log::DEBUG,
|
2019-09-03 02:47:59 +02:00
|
|
|
"Finished %s in %s started:%ld finished:%d attempted:%zu abandon:%b %s%s",
|
2019-08-30 03:30:47 +02:00
|
|
|
string_view{request.opts.event_id},
|
|
|
|
string_view{request.opts.room_id},
|
2019-09-03 02:47:59 +02:00
|
|
|
duration_cast<seconds>(tse(request.started)).count(),
|
|
|
|
duration_cast<seconds>(tse(request.finished)).count(),
|
2019-08-27 00:12:43 +02:00
|
|
|
request.attempted.size(),
|
|
|
|
!request.promise,
|
|
|
|
request.eptr? " :" : "",
|
|
|
|
what(request.eptr),
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!request.promise)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(request.eptr)
|
|
|
|
{
|
|
|
|
request.promise.set_exception(std::move(request.eptr));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
result res;
|
|
|
|
res.buf = std::move(request.future->in.dynamic);
|
|
|
|
res.content = res.buf;
|
|
|
|
request.promise.set_value(std::move(res));
|
2018-09-05 08:27:01 +02:00
|
|
|
}
|
2019-04-12 12:13:40 +02:00
|
|
|
|
2019-08-28 02:36:14 +02:00
|
|
|
namespace ircd::m::fetch
|
|
|
|
{
|
2019-08-30 06:48:47 +02:00
|
|
|
static void check_response__backfill(const request &, const json::object &);
|
|
|
|
static void check_response__event(const request &, const json::object &);
|
|
|
|
static void check_response__auth(const request &, const json::object &);
|
|
|
|
|
2019-08-28 02:36:14 +02:00
|
|
|
extern conf::item<bool> check_event_id;
|
|
|
|
extern conf::item<bool> check_conforms;
|
2020-03-08 22:09:59 +01:00
|
|
|
extern conf::item<bool> check_signature;
|
2019-08-28 02:36:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
decltype(ircd::m::fetch::check_event_id)
|
|
|
|
ircd::m::fetch::check_event_id
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fetch.check.event_id" },
|
|
|
|
{ "default", true },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::fetch::check_conforms)
|
|
|
|
ircd::m::fetch::check_conforms
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fetch.check.conforms" },
|
|
|
|
{ "default", false },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::fetch::check_signature)
|
|
|
|
ircd::m::fetch::check_signature
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fetch.check.signature" },
|
|
|
|
{ "default", true },
|
|
|
|
{ "description",
|
|
|
|
|
|
|
|
R"(
|
|
|
|
false - Signatures of events will not be checked by the fetch unit (they
|
|
|
|
are still checked normally during evaluation; this conf item does not
|
|
|
|
disable event signature verification for the server).
|
|
|
|
|
|
|
|
true - Signatures of events will be checked by the fetch unit such that
|
|
|
|
bogus responses allow the fetcher to try the next server. This check might
|
|
|
|
not occur in all cases. It will only occur if the server has the public
|
|
|
|
key already; fetch unit worker contexts cannot be blocked trying to obtain
|
|
|
|
unknown keys from remote hosts.
|
|
|
|
)"},
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::fetch::check_response(const request &request,
|
|
|
|
const json::object &response)
|
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
switch(request.opts.op)
|
|
|
|
{
|
2019-08-30 06:48:47 +02:00
|
|
|
case op::backfill:
|
|
|
|
return check_response__backfill(request, response);
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
case op::event:
|
|
|
|
return check_response__event(request, response);
|
|
|
|
|
2019-08-30 04:29:40 +02:00
|
|
|
case op::auth:
|
|
|
|
return check_response__auth(request, response);
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
case op::noop:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::panic
|
|
|
|
{
|
|
|
|
"Unchecked response; fetch op:%u",
|
|
|
|
uint(request.opts.op),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-30 04:29:40 +02:00
|
|
|
void
|
|
|
|
ircd::m::fetch::check_response__auth(const request &request,
|
|
|
|
const json::object &response)
|
|
|
|
{
|
|
|
|
const json::array &auth_chain
|
|
|
|
{
|
|
|
|
response.at("auth_chain")
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const json::object &auth_event : auth_chain)
|
|
|
|
{
|
|
|
|
event::id::buf event_id;
|
|
|
|
const m::event event
|
|
|
|
{
|
|
|
|
event_id, auth_event
|
|
|
|
};
|
|
|
|
|
|
|
|
_check_event(request, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
void
|
|
|
|
ircd::m::fetch::check_response__event(const request &request,
|
|
|
|
const json::object &response)
|
|
|
|
{
|
|
|
|
const json::array &pdus
|
|
|
|
{
|
|
|
|
response.at("pdus")
|
|
|
|
};
|
|
|
|
|
2019-08-28 02:36:14 +02:00
|
|
|
const m::event event
|
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
pdus.at(0), request.opts.event_id
|
2019-08-28 02:36:14 +02:00
|
|
|
};
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
_check_event(request, event);
|
|
|
|
}
|
|
|
|
|
2019-08-30 06:48:47 +02:00
|
|
|
void
|
|
|
|
ircd::m::fetch::check_response__backfill(const request &request,
|
|
|
|
const json::object &response)
|
|
|
|
{
|
|
|
|
const json::array &pdus
|
|
|
|
{
|
|
|
|
response.at("pdus")
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const json::object &event : pdus)
|
|
|
|
{
|
|
|
|
event::id::buf event_id;
|
|
|
|
const m::event _event
|
|
|
|
{
|
|
|
|
event_id, event
|
|
|
|
};
|
|
|
|
|
|
|
|
_check_event(request, _event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
void
|
|
|
|
ircd::m::fetch::_check_event(const request &request,
|
|
|
|
const m::event &event)
|
|
|
|
{
|
2019-08-28 02:36:14 +02:00
|
|
|
if(check_event_id && !m::check_id(event))
|
|
|
|
{
|
|
|
|
event::id::buf buf;
|
|
|
|
const m::event &claim
|
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
buf, event.source
|
2019-08-28 02:36:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
throw ircd::error
|
|
|
|
{
|
|
|
|
"event::id claim:%s != sought:%s",
|
|
|
|
string_view{claim.event_id},
|
2019-08-30 03:30:47 +02:00
|
|
|
string_view{request.opts.event_id},
|
2019-08-28 02:36:14 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if(check_conforms)
|
|
|
|
{
|
|
|
|
thread_local char buf[128];
|
|
|
|
const m::event::conforms conforms
|
|
|
|
{
|
|
|
|
event
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view failures
|
|
|
|
{
|
|
|
|
conforms.string(buf)
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(failures || conforms.clean());
|
|
|
|
if(!conforms.clean())
|
|
|
|
throw ircd::error
|
|
|
|
{
|
|
|
|
"Non-conforming event in response :%s",
|
|
|
|
failures,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-14 23:21:01 +02:00
|
|
|
// only check signature for v1 events
|
|
|
|
if(check_signature && request.opts.event_id.version() == "1")
|
2019-08-28 02:36:14 +02:00
|
|
|
{
|
|
|
|
const string_view &server
|
|
|
|
{
|
|
|
|
!json::get<"origin"_>(event)?
|
|
|
|
user::id(at<"sender"_>(event)).host():
|
|
|
|
string_view(json::get<"origin"_>(event))
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::object &signatures
|
|
|
|
{
|
2019-09-14 23:18:51 +02:00
|
|
|
at<"signatures"_>(event).at(server)
|
2019-08-28 02:36:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const json::string &key_id
|
|
|
|
{
|
|
|
|
!signatures.empty()?
|
|
|
|
signatures.begin()->first:
|
|
|
|
string_view{},
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!key_id)
|
|
|
|
throw ircd::error
|
|
|
|
{
|
|
|
|
"Cannot find any keys for '%s' in event.signatures",
|
|
|
|
server,
|
|
|
|
};
|
|
|
|
|
|
|
|
if(m::keys::cache::has(server, key_id))
|
|
|
|
if(!verify(event, server))
|
|
|
|
throw ircd::error
|
|
|
|
{
|
|
|
|
"Signature verification failed."
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 20:37:13 +02:00
|
|
|
bool
|
|
|
|
ircd::m::fetch::timedout(const request &request,
|
2019-08-30 03:30:47 +02:00
|
|
|
const system_point &now)
|
2019-04-15 20:37:13 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
assert(!!request.started && !request.finished && !!request.last);
|
|
|
|
return request.last + seconds(timeout) < now;
|
2019-04-15 20:37:13 +02:00
|
|
|
}
|
|
|
|
|
2019-04-12 12:13:40 +02:00
|
|
|
bool
|
2019-08-31 10:53:58 +02:00
|
|
|
ircd::m::fetch::operator<(const request &a, const request &b)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return a.opts < b.opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::m::fetch::operator<(const opts &a, const request &b)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return a < b.opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::m::fetch::operator<(const request &a, const opts &b)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return a.opts < b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::m::fetch::operator<(const opts &a, const opts &b)
|
|
|
|
noexcept
|
|
|
|
{
|
2019-09-04 07:14:53 +02:00
|
|
|
if(uint(a.op) < uint(b.op))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
else if(uint(a.op) > uint(b.op))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
else if(a.room_id < b.room_id)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
else if(a.room_id > b.room_id)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
else if(a.event_id < b.event_id)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
else if(a.event_id > b.event_id)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
assert(operator==(a, b));
|
|
|
|
return false;
|
2019-08-31 10:53:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::m::fetch::operator==(const request &a, const request &b)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return a.opts == b.opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::m::fetch::operator==(const opts &a, const request &b)
|
2019-04-12 12:13:40 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2019-08-31 10:53:58 +02:00
|
|
|
return a == b.opts;
|
2019-04-12 12:13:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-08-31 10:53:58 +02:00
|
|
|
ircd::m::fetch::operator==(const request &a, const opts &b)
|
2019-04-12 12:13:40 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2019-08-31 10:53:58 +02:00
|
|
|
return a.opts == b;
|
2019-04-12 12:13:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-08-31 10:53:58 +02:00
|
|
|
ircd::m::fetch::operator==(const opts &a, const opts &b)
|
2019-04-12 12:13:40 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2019-08-31 10:53:58 +02:00
|
|
|
return uint(a.op) == uint(b.op) &&
|
|
|
|
a.event_id == b.event_id &&
|
|
|
|
a.room_id == b.room_id;
|
2019-04-12 12:13:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// request::request
|
|
|
|
//
|
|
|
|
|
2019-08-30 03:30:47 +02:00
|
|
|
ircd::m::fetch::request::request(const fetch::opts &opts)
|
|
|
|
:opts
|
2019-04-12 12:13:40 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
opts
|
2019-04-12 12:13:40 +02:00
|
|
|
}
|
2019-08-30 03:30:47 +02:00
|
|
|
,buf
|
2019-08-27 00:12:43 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
opts.bufsz?: 16_KiB
|
2019-08-27 00:12:43 +02:00
|
|
|
}
|
2019-08-30 03:30:47 +02:00
|
|
|
,event_id
|
|
|
|
{
|
|
|
|
opts.event_id
|
|
|
|
}
|
|
|
|
,room_id
|
2019-08-27 00:12:43 +02:00
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
opts.room_id
|
2019-08-27 00:12:43 +02:00
|
|
|
}
|
|
|
|
{
|
2019-08-30 03:30:47 +02:00
|
|
|
this->opts.event_id = this->event_id;
|
|
|
|
this->opts.room_id = this->room_id;
|
2019-08-27 00:12:43 +02:00
|
|
|
}
|
2019-09-03 23:43:34 +02:00
|
|
|
|
|
|
|
ircd::m::fetch::request::~request()
|
|
|
|
noexcept
|
|
|
|
{
|
2019-09-04 02:05:52 +02:00
|
|
|
//TODO: bad things unless this first here
|
|
|
|
future.reset(nullptr);
|
2019-09-03 23:43:34 +02:00
|
|
|
}
|