2019-10-01 05:50:58 +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.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_M_HOMESERVER_H
|
|
|
|
|
|
|
|
namespace ircd::m
|
|
|
|
{
|
|
|
|
struct homeserver;
|
|
|
|
|
|
|
|
IRCD_M_EXCEPTION(error, NOT_MY_HOMESERVER, http::NOT_FOUND)
|
|
|
|
IRCD_M_EXCEPTION(error, NOT_A_HOMESERVER, http::SERVICE_UNAVAILABLE)
|
|
|
|
|
|
|
|
string_view origin(const homeserver &);
|
|
|
|
string_view server_name(const homeserver &);
|
|
|
|
|
|
|
|
bool origin(const homeserver &, const string_view &);
|
|
|
|
bool server_name(const homeserver &, const string_view &);
|
|
|
|
|
|
|
|
string_view public_key_id(const homeserver &);
|
|
|
|
const ed25519::sk &secret_key(const homeserver &);
|
|
|
|
|
|
|
|
bool for_each(const std::function<bool (homeserver &)> &);
|
|
|
|
|
2019-10-04 22:39:55 +02:00
|
|
|
bool my_origin(const string_view &origin);
|
|
|
|
bool myself(const m::user::id &);
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
homeserver &my(const string_view &origin);
|
|
|
|
homeserver &my(); // primary
|
|
|
|
|
|
|
|
user::id me(const string_view &origin);
|
|
|
|
user::id me(); // primary
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ircd::m::homeserver
|
2023-02-06 03:47:31 +01:00
|
|
|
:instance_map<string_view, homeserver, std::less<>>
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
|
|
|
struct key;
|
|
|
|
struct cert;
|
|
|
|
struct opts;
|
2019-10-04 21:48:54 +02:00
|
|
|
struct conf;
|
2019-10-01 05:50:58 +02:00
|
|
|
|
|
|
|
/// Internal state; use m::my().
|
|
|
|
static homeserver *primary;
|
|
|
|
|
|
|
|
/// Options from the user.
|
|
|
|
const struct opts *opts;
|
|
|
|
|
|
|
|
/// Federation key related.
|
|
|
|
std::unique_ptr<struct key> key;
|
|
|
|
|
|
|
|
/// Database
|
|
|
|
std::shared_ptr<dbs::init> database;
|
|
|
|
|
2022-06-13 23:04:56 +02:00
|
|
|
/// An inscription of `\@ircd:network.name` to root various references to
|
2019-10-01 05:50:58 +02:00
|
|
|
/// a user representing the server.
|
|
|
|
m::user::id::buf self;
|
|
|
|
|
2019-10-04 21:48:54 +02:00
|
|
|
/// Configuration
|
|
|
|
std::unique_ptr<struct conf> conf;
|
|
|
|
|
2020-03-17 00:44:12 +01:00
|
|
|
/// Requested modules.
|
2020-05-10 04:56:20 +02:00
|
|
|
struct modules
|
|
|
|
:std::vector<string_view>
|
|
|
|
{
|
|
|
|
using std::vector<string_view>::vector;
|
|
|
|
~modules() noexcept;
|
|
|
|
}
|
|
|
|
modules;
|
2019-10-01 05:50:58 +02:00
|
|
|
|
2020-08-24 13:06:16 +02:00
|
|
|
void bootstrap();
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
homeserver(const struct opts *const &);
|
|
|
|
~homeserver() noexcept;
|
|
|
|
|
|
|
|
/// Factory to create homeserver with single procedure for shlib purposes.
|
|
|
|
static homeserver *init(const struct opts *);
|
|
|
|
static void fini(homeserver *) noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::m::homeserver::key
|
|
|
|
{
|
2019-10-03 21:15:23 +02:00
|
|
|
/// Current secret key path
|
|
|
|
std::string secret_key_path;
|
2019-10-01 05:50:58 +02:00
|
|
|
|
|
|
|
/// Current federation public key instance
|
|
|
|
ed25519::pk public_key;
|
|
|
|
|
2019-10-03 21:15:23 +02:00
|
|
|
/// Current federation secret key instance
|
|
|
|
ed25519::sk secret_key;
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
/// Current federation public key base64
|
|
|
|
std::string public_key_b64;
|
|
|
|
|
|
|
|
/// Current ed25519:ident string
|
|
|
|
std::string public_key_id;
|
|
|
|
|
2019-10-04 22:21:56 +02:00
|
|
|
/// Current verify_keys (json::object) (m::keys)
|
|
|
|
std::string verify_keys;
|
|
|
|
|
2019-10-04 21:48:54 +02:00
|
|
|
key(const struct opts &);
|
2019-10-01 05:50:58 +02:00
|
|
|
key() = default;
|
|
|
|
};
|
|
|
|
|
2019-10-04 21:48:54 +02:00
|
|
|
struct ircd::m::homeserver::conf
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
2019-10-04 21:48:54 +02:00
|
|
|
/// !conf:origin
|
|
|
|
m::room::id::buf room_id;
|
|
|
|
|
|
|
|
/// Convenience
|
|
|
|
m::room room;
|
|
|
|
|
|
|
|
/// Register the conf item init callback //TODO: XXX
|
|
|
|
decltype(ircd::conf::on_init)::callback item_init;
|
|
|
|
|
|
|
|
/// Register the !conf room item message hook.
|
|
|
|
hookfn<vm::eval &> conf_updated;
|
|
|
|
|
|
|
|
// Interface
|
|
|
|
bool get(const string_view &key, const std::function<void (const string_view &)> &) const;
|
|
|
|
event::id::buf set(const string_view &key, const string_view &val) const;
|
|
|
|
|
|
|
|
size_t defaults(const string_view &prefix = {}) const;
|
|
|
|
size_t load(const string_view &prefix = {}) const;
|
|
|
|
size_t store(const string_view &prefix = {}, const bool &force = false) const;
|
|
|
|
|
|
|
|
conf(const struct opts &);
|
2019-10-01 05:50:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::m::homeserver::opts
|
|
|
|
{
|
2022-06-13 23:04:56 +02:00
|
|
|
/// Network name. This is the mxid hostpart (i.e `\@user:origin`).
|
2019-10-01 05:50:58 +02:00
|
|
|
string_view origin;
|
|
|
|
|
|
|
|
/// This server's name. This is the unique domain-name of this server
|
|
|
|
/// participating in the cluster to serve the origin. The servername may
|
|
|
|
/// be the origin itself; otherwise, SRV/well-known indirection is required
|
|
|
|
/// to reach the servername starting from the origin.
|
|
|
|
string_view server_name;
|
2020-05-10 09:05:52 +02:00
|
|
|
|
|
|
|
/// When instantiating a homeserver with a fresh database, the file found
|
|
|
|
/// at this path can supplement for any initial bootstrapping. This vector
|
|
|
|
/// may contain additional events as well; the server will continue its
|
|
|
|
/// operation after having processed these events.
|
|
|
|
string_view bootstrap_vector_path;
|
2020-09-16 18:08:05 +02:00
|
|
|
|
|
|
|
/// Whether to run initial backfill jobs after startup.
|
|
|
|
bool backfill {true};
|
2020-10-27 10:54:07 +01:00
|
|
|
|
|
|
|
/// Whether to permit automatic execution of managed apps.
|
|
|
|
bool autoapps {true};
|
2019-10-01 05:50:58 +02:00
|
|
|
};
|