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
|
|
|
|
}
|
|
|
|
|
|
|
|
///NOTE: instance_multimap is used because there is no instance_map yet.
|
|
|
|
struct ircd::m::homeserver
|
|
|
|
:instance_multimap<string_view, homeserver, std::less<>>
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
/// An inscription of @ircd:network.name to root various references to
|
|
|
|
/// 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.
|
|
|
|
std::vector<string_view> modules;
|
2019-10-01 05:50:58 +02:00
|
|
|
|
2019-10-03 21:15:23 +02:00
|
|
|
/// vm
|
|
|
|
std::shared_ptr<vm::init> vm;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
/// Network name. This is the mxid hostpart (i.e @user:origin).
|
|
|
|
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;
|
|
|
|
};
|