2020-04-24 21:05:39 +02:00
|
|
|
// The Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) The Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2020 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.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_M_ACQUIRE_H
|
|
|
|
|
2020-11-19 21:29:53 +01:00
|
|
|
namespace ircd::m
|
|
|
|
{
|
|
|
|
struct acquire;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ircd::m::acquire
|
|
|
|
:instance_list<ircd::m::acquire>
|
2020-04-24 21:05:39 +02:00
|
|
|
{
|
|
|
|
struct opts;
|
2020-11-19 21:29:53 +01:00
|
|
|
struct result;
|
2020-04-24 21:05:39 +02:00
|
|
|
|
2020-11-19 21:29:53 +01:00
|
|
|
static log::log log;
|
2020-04-24 21:05:39 +02:00
|
|
|
|
2020-11-19 21:29:53 +01:00
|
|
|
const struct opts &opts;
|
2020-11-20 20:10:46 +01:00
|
|
|
vm::opts head_vmopts;
|
|
|
|
vm::opts history_vmopts;
|
2020-11-21 01:10:25 +01:00
|
|
|
vm::opts state_vmopts;
|
2020-11-19 21:29:53 +01:00
|
|
|
std::list<result> fetching;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool full() const noexcept;
|
|
|
|
bool handle(result &);
|
|
|
|
bool handle();
|
|
|
|
|
|
|
|
bool started(const event::id &) const;
|
2020-11-20 20:10:46 +01:00
|
|
|
bool start(const event::id &, const string_view &, const bool &, const size_t &, const vm::opts *const &);
|
|
|
|
bool submit(const event::id &, const string_view &, const bool &, const size_t &, const vm::opts *const &);
|
2020-11-19 21:29:53 +01:00
|
|
|
|
|
|
|
bool fetch_head(const m::event &, const int64_t &);
|
|
|
|
void acquire_head();
|
|
|
|
|
2020-11-20 20:10:46 +01:00
|
|
|
bool fetch_history(event::idx &);
|
|
|
|
void acquire_history();
|
|
|
|
|
2020-11-21 01:10:25 +01:00
|
|
|
bool fetch_state(const m::event::id &, const string_view &);
|
|
|
|
void acquire_state();
|
|
|
|
|
2020-11-19 21:29:53 +01:00
|
|
|
public:
|
|
|
|
acquire(const struct opts &);
|
|
|
|
acquire(const acquire &) = delete;
|
|
|
|
acquire &operator=(const acquire &) = delete;
|
|
|
|
~acquire() noexcept;
|
2020-04-24 21:05:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::m::acquire::opts
|
|
|
|
{
|
2020-11-20 20:10:46 +01:00
|
|
|
/// Room apropos; note that the event_id in this structure may have some
|
|
|
|
/// effect on the result after deducing other options instead of defaults.
|
2020-11-07 14:12:48 +01:00
|
|
|
m::room room;
|
|
|
|
|
|
|
|
/// Optional remote host first considered as the target for operations in
|
|
|
|
/// case caller has better information for what will most likely succeed.
|
2020-04-24 21:05:39 +02:00
|
|
|
string_view hint;
|
|
|
|
|
2020-11-07 14:12:48 +01:00
|
|
|
/// For diagnostic and special use; forces remote operations through the
|
|
|
|
/// hint, and fails them if the hint is insufficient.
|
2020-04-24 21:05:39 +02:00
|
|
|
bool hint_only {false};
|
2020-05-10 04:01:25 +02:00
|
|
|
|
2020-11-20 20:10:46 +01:00
|
|
|
/// Perform head acquisition. Setting to false will disable the ability
|
|
|
|
/// to reconnoiter the latest events from remote servers. Note that setting
|
|
|
|
/// a depth ceiling effectively makes this false.
|
2020-11-07 14:12:48 +01:00
|
|
|
bool head {true};
|
|
|
|
|
2020-11-20 20:10:46 +01:00
|
|
|
/// Perform history acquisition. Setting this to false disables operations
|
|
|
|
/// which fill in gaps in the timeline below the head.
|
|
|
|
bool history {true};
|
|
|
|
|
|
|
|
/// Perform state acquisition. Setting this to false may result in an
|
|
|
|
/// acquisition that is missing state events and subject to inconsistency
|
|
|
|
/// from the ABA problem etc.
|
|
|
|
bool state {true};
|
2020-11-07 14:12:48 +01:00
|
|
|
|
2020-11-19 21:29:53 +01:00
|
|
|
/// Provide a viewport size; generally obtained from the eponymous conf
|
|
|
|
/// item and used for initial backfill
|
|
|
|
size_t viewport_size {0};
|
|
|
|
|
2020-11-07 14:12:48 +01:00
|
|
|
/// Depthwise window of acquisition; concentrate on specific depth window
|
|
|
|
pair<int64_t> depth {0, 0};
|
|
|
|
|
2020-11-19 21:29:53 +01:00
|
|
|
/// Won't fetch missing of ref outside this range.
|
|
|
|
pair<event::idx> ref {0, -1UL};
|
|
|
|
|
|
|
|
/// Avoids filling gaps with a depth sounding outside of the range
|
|
|
|
pair<size_t> gap {0, -1UL};
|
2020-11-07 14:12:48 +01:00
|
|
|
|
|
|
|
/// The number of rounds the algorithm runs for.
|
2020-11-18 23:29:59 +01:00
|
|
|
size_t rounds {-1UL};
|
2020-05-10 04:01:25 +02:00
|
|
|
|
2020-11-07 14:12:48 +01:00
|
|
|
/// Total event limit over all operations.
|
|
|
|
size_t fetch_max {-1UL};
|
2020-06-13 05:52:32 +02:00
|
|
|
|
2020-11-07 14:12:48 +01:00
|
|
|
/// Limit the number of requests in flight at any given time.
|
|
|
|
size_t fetch_width {128};
|
2020-11-20 20:10:46 +01:00
|
|
|
|
2020-11-21 04:49:06 +01:00
|
|
|
/// Fetch attempt cap passed to m::fetch, because the default there is
|
|
|
|
/// unlimited and that's usually a waste of time in practice.
|
|
|
|
size_t attempt_max {16};
|
|
|
|
|
2020-11-20 20:10:46 +01:00
|
|
|
/// Default vm::opts to be used during eval; some options are
|
|
|
|
/// unconditionally overriden to perform some evals. Use caution, setting
|
|
|
|
/// options may cause results not expected from this interface.
|
|
|
|
vm::opts vmopts;
|
2020-11-19 21:29:53 +01:00
|
|
|
};
|
2020-11-18 23:29:59 +01:00
|
|
|
|
2020-11-19 21:29:53 +01:00
|
|
|
struct ircd::m::acquire::result
|
|
|
|
{
|
2020-11-20 20:10:46 +01:00
|
|
|
const m::vm::opts *vmopts {nullptr};
|
2020-11-19 21:29:53 +01:00
|
|
|
ctx::future<fetch::result> future;
|
|
|
|
event::id::buf event_id;
|
2020-04-24 21:05:39 +02:00
|
|
|
};
|