0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 07:20:55 +01:00

ircd:Ⓜ️:fed: Refactor all interfaces using abstract request.

This commit is contained in:
Jason Volk 2020-03-07 17:15:58 -08:00
parent c0a5a7a89e
commit 55ffdddc6a
23 changed files with 627 additions and 945 deletions

View file

@ -17,27 +17,28 @@ namespace ircd::m::fed
};
struct ircd::m::fed::backfill
:server::request
:request
{
struct opts;
explicit operator json::object() const
{
return json::object{in.content};
return json::object
{
in.content
};
}
backfill(const room::id &, const mutable_buffer &, opts);
backfill(const room::id &,
const mutable_buffer &,
opts);
backfill() = default;
};
struct ircd::m::fed::backfill::opts
:request::opts
{
net::hostport remote;
string_view event_id;
size_t limit {64};
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {true};
};

View file

@ -17,25 +17,16 @@ namespace ircd::m::fed
};
struct ircd::m::fed::event
:server::request
:request
{
struct opts;
explicit operator json::object() const;
explicit operator m::event() const;
event(const m::event::id &, const mutable_buffer &, opts);
event() = default;
};
event(const m::event::id &,
const mutable_buffer &,
opts);
struct ircd::m::fed::event::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {false};
event() = default;
};
inline

View file

@ -17,7 +17,7 @@ namespace ircd::m::fed
};
struct ircd::m::fed::event_auth
:server::request
:request
{
struct opts;
@ -31,17 +31,16 @@ struct ircd::m::fed::event_auth
return object["auth_chain"];
}
event_auth(const m::room::id &, const m::event::id &, const mutable_buffer &, opts);
event_auth(const m::room::id &,
const m::event::id &,
const mutable_buffer &,
opts);
event_auth() = default;
};
struct ircd::m::fed::event_auth::opts
:request::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {true};
bool ids_only {false};
};

View file

@ -11,14 +11,17 @@
#pragma once
#define HAVE_IRCD_M_FED_H
/// Federation Interface
namespace ircd::m::fed
{
net::hostport matrix_service(net::hostport);
string_view fetch_well_known(const mutable_buffer &out, const string_view &origin);
id::event::buf fetch_head(const id::room &room_id, const string_view &remote, const id::user &);
id::event::buf fetch_head(const id::room &room_id, const string_view &remote);
}
#include "request.h"
#include "version.h"
#include "key.h"
#include "query.h"

View file

@ -17,34 +17,41 @@ namespace ircd::m::fed
};
struct ircd::m::fed::frontfill
:server::request
:request
{
struct opts;
using span = std::pair<m::event::id, m::event::id>;
using vector = vector_view<const m::event::id>;
using ranges = std::pair<vector, vector>;
static const_buffer make_content(const mutable_buffer &, const ranges &, const opts &);
static const_buffer make_content(const mutable_buffer &, const ranges &, const opts &);
explicit operator json::array() const
{
const json::object content{in.content};
return content.get("events");
const json::object content
{
in.content
};
return content["events"];
}
frontfill(const room::id &, const ranges &, const mutable_buffer &, opts);
frontfill(const room::id &, const span &, const mutable_buffer &, opts);
frontfill(const room::id &,
const ranges &,
const mutable_buffer &,
opts);
frontfill(const room::id &,
const span &,
const mutable_buffer &,
opts);
frontfill() = default;
};
struct ircd::m::fed::frontfill::opts
:request::opts
{
net::hostport remote;
size_t limit {64};
uint64_t min_depth {0};
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {true};
};

View file

@ -17,25 +17,20 @@ namespace ircd::m::fed::groups
};
struct ircd::m::fed::groups::publicised
:server::request
:request
{
struct opts;
operator json::object() const
explicit operator json::object() const
{
return json::object{in.content};
return json::object
{
in.content
};
}
publicised(const string_view &, const vector_view<const id::user> &, const mutable_buffer &, opts);
publicised(const string_view &,
const vector_view<const id::user> &,
const mutable_buffer &,
opts);
publicised() = default;
};
struct ircd::m::fed::groups::publicised::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {false};
};

View file

@ -17,25 +17,21 @@ namespace ircd::m::fed
};
struct ircd::m::fed::invite
:server::request
:request
{
struct opts;
explicit operator json::array() const
{
return json::array{in.content};
return json::array
{
in.content
};
}
invite(const room::id &, const id::event &, const json::object &, const mutable_buffer &, opts);
invite(const room::id &,
const id::event &,
const json::object &,
const mutable_buffer &,
opts);
invite() = default;
};
struct ircd::m::fed::invite::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {false};
};

View file

@ -17,25 +17,21 @@ namespace ircd::m::fed
};
struct ircd::m::fed::invite2
:server::request
:request
{
struct opts;
explicit operator json::object() const
{
return json::object{in.content};
return json::object
{
in.content
};
}
invite2(const room::id &, const id::event &, const json::object &, const mutable_buffer &, opts);
invite2(const room::id &,
const id::event &,
const json::object &,
const mutable_buffer &,
opts);
invite2() = default;
};
struct ircd::m::fed::invite2::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {false};
};

View file

@ -13,50 +13,56 @@
namespace ircd::m::fed::key
{
struct opts;
struct keys;
struct query;
using opts = request::opts;
using server_key = std::pair<string_view, string_view>; // server_name, key_id
};
struct ircd::m::fed::key::keys
:server::request
:request
{
using opts = key::opts;
explicit operator json::object() const
{
const json::object object{in.content};
return object;
return json::object
{
in.content
};
}
keys(const server_key &, const mutable_buffer &, opts);
keys(const string_view &server_name, const mutable_buffer &, opts);
keys(const server_key &,
const mutable_buffer &,
opts);
keys(const string_view &server_name,
const mutable_buffer &,
opts);
keys() = default;
};
struct ircd::m::fed::key::query
:server::request
:request
{
using opts = key::opts;
explicit operator json::array() const
{
const json::object object{in.content};
const json::array &server_keys{object.get("server_keys")};
const json::object object
{
in.content
};
const json::array server_keys
{
object["server_keys"]
};
return server_keys;
}
query(const vector_view<const server_key> &, const mutable_buffer &, opts);
query(const vector_view<const server_key> &,
const mutable_buffer &,
opts);
query() = default;
};
struct ircd::m::fed::key::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {false};
};

View file

@ -17,25 +17,20 @@ namespace ircd::m::fed
};
struct ircd::m::fed::make_join
:server::request
:request
{
struct opts;
operator json::object() const
explicit operator json::object() const
{
return json::object{in.content};
return json::object
{
in.content
};
}
make_join(const room::id &, const id::user &, const mutable_buffer &, opts);
make_join(const room::id &,
const id::user &,
const mutable_buffer &,
opts);
make_join() = default;
};
struct ircd::m::fed::make_join::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {false};
};

View file

@ -17,29 +17,30 @@ namespace ircd::m::fed
};
struct ircd::m::fed::public_rooms
:server::request
:request
{
struct opts;
explicit operator json::object() const
{
return json::object{in.content};
return json::object
{
in.content
};
}
public_rooms(const net::hostport &, const mutable_buffer &, opts);
public_rooms(const string_view &remote,
const mutable_buffer &,
opts);
public_rooms() = default;
};
struct ircd::m::fed::public_rooms::opts
:request::opts
{
net::hostport remote;
size_t limit {128};
string_view since;
string_view third_party_instance_id;
bool include_all_networks {true};
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {true};
};

View file

@ -17,9 +17,8 @@ namespace ircd::m::fed
};
struct ircd::m::fed::query
:server::request
:request
{
struct opts;
struct profile;
struct directory;
struct user_devices;
@ -27,39 +26,41 @@ struct ircd::m::fed::query
explicit operator json::object() const
{
const json::object object{in.content};
return object;
return json::object
{
in.content
};
}
query(const string_view &type, const string_view &args, const mutable_buffer &, opts);
query(const string_view &type,
const string_view &args,
const mutable_buffer &,
opts);
query() = default;
};
struct ircd::m::fed::query::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {false};
opts(const net::hostport &remote)
:remote{remote}
{}
opts() = default;
};
struct ircd::m::fed::query::profile
:query
{
profile(const id::user &user_id, const string_view &field, const mutable_buffer &, opts);
profile(const id::user &user_id, const mutable_buffer &, opts);
profile(const id::user &user_id,
const string_view &field,
const mutable_buffer &,
opts);
profile(const id::user &user_id,
const mutable_buffer &,
opts);
profile() = default;
};
struct ircd::m::fed::query::directory
:query
{
directory(const id::room_alias &room_alias, const mutable_buffer &, opts);
directory(const id::room_alias &room_alias,
const mutable_buffer &,
opts);
directory() = default;
};

View file

@ -17,13 +17,15 @@ namespace ircd::m::fed
};
struct ircd::m::fed::query_auth
:server::request
:request
{
struct opts;
explicit operator json::object() const
{
const auto type(json::type(in.content));
const auto type
{
json::type(in.content)
};
return type == json::ARRAY?
json::array{in.content}.at(1): // non-spec [200, {...}]
json::object{in.content}; // spec {...}
@ -37,13 +39,3 @@ struct ircd::m::fed::query_auth
query_auth() = default;
};
struct ircd::m::fed::query_auth::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {true};
};

View file

@ -0,0 +1,60 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 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_FED_REQUEST_H
namespace ircd::m::fed
{
struct request;
}
/// Abstract request; everything goes through here.
struct ircd::m::fed::request
:server::request
{
struct opts;
request(const mutable_buffer &buf,
opts &&);
request() = default;
};
struct ircd::m::fed::request::opts
{
/// The remote server to contact. Must be specified for this request.
string_view remote;
/// The m::request structure which helps compose this request. The fields
/// of this object are eventually used to sign the request for [Fed. 12.1]
/// Request Authentication. User does not have to fill anything in here;
/// anything not provided is derived automatically, but providing these
/// fields will override that derivation.
m::request request;
/// The lower-level server::out structure used by server:: when transmitting
/// data; providing anything here is optional and will override things.
server::out out;
/// The lower-level server::in structure used by server:: when receiving
/// data; providing anything here is optional and will override things.
server::in in;
/// The lower-level server::request::opts configuration to attach to
/// this request.
const struct server::request::opts *sopts {nullptr};
/// Whether dynamic content buffering for incoming data will be used.
/// if false, the user supplied buffer handles all data sent from the
/// remote server; this is faster, but if it runs out the request is
/// canceled and an exception is thrown.
bool dynamic {true};
};

View file

@ -21,14 +21,16 @@ namespace ircd::m::fed
/// must stay in scope to complete the request until the future is resolved.
///
struct ircd::m::fed::send
:server::request
:request
{
struct opts;
struct response;
operator json::object() const
explicit operator json::object() const
{
return { in.content };
return json::object
{
in.content
};
}
send(const string_view &txnid, // transaction ID (goes in URL)
@ -39,35 +41,6 @@ struct ircd::m::fed::send
send() = default;
};
/// Options for a federation send request.
///
struct ircd::m::fed::send::opts
{
/// The remote server to contact. Must be specified for this request.
net::hostport remote;
/// The m::request structure which helps compose this request. The fields
/// of this object are eventually used to sign the request for [Fed. 12.1]
/// Request Authentication. User does not have to fill anything in here;
/// anything not provided is derived automatically, but providing these
/// fields will override that derivation.
m::request request;
/// The lower-level server::out structure used by server:: when transmitting
/// data; providing anything here is optional and will override things.
server::out out;
/// The lower-level server::in structure used by server:: when receiving
/// data; providing anything here is optional and will override things.
server::in in;
/// The lower-level server::request::opts configuration to attach to
/// this request.
const struct server::request::opts *sopts {nullptr};
bool dynamic {false};
};
/// Helper for dealing with response content from a /send/.
struct ircd::m::fed::send::response
:json::object

View file

@ -17,25 +17,21 @@ namespace ircd::m::fed
};
struct ircd::m::fed::send_join
:server::request
:request
{
struct opts;
operator json::array() const
explicit operator json::array() const
{
return json::array{in.content};
return json::array
{
in.content
};
}
send_join(const room::id &, const id::event &, const const_buffer &, const mutable_buffer &, opts);
send_join(const room::id &,
const id::event &,
const const_buffer &,
const mutable_buffer &,
opts);
send_join() = default;
};
struct ircd::m::fed::send_join::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {true};
};

View file

@ -17,27 +17,28 @@ namespace ircd::m::fed
};
struct ircd::m::fed::state
:server::request
:request
{
struct opts;
explicit operator json::object() const
{
return json::object{in.content};
return json::object
{
in.content
};
}
state(const room::id &, const mutable_buffer &, opts);
state(const room::id &,
const mutable_buffer &,
opts);
state() = default;
};
struct ircd::m::fed::state::opts
:request::opts
{
net::hostport remote;
string_view event_id;
bool ids_only {false};
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {true};
};

View file

@ -13,33 +13,25 @@
namespace ircd::m::fed::user
{
struct opts;
struct devices;
using opts = request::opts;
}
struct ircd::m::fed::user::devices
:server::request
:request
{
using opts = fed::user::opts;
explicit operator json::object() const
{
const json::object object{in.content};
return object;
return json::object
{
in.content
};
}
devices(const id::user &user_id, const mutable_buffer &, opts);
devices(const id::user &user_id,
const mutable_buffer &,
opts);
devices() = default;
};
struct ircd::m::fed::user::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {true};
opts() = default;
};

View file

@ -18,7 +18,7 @@ namespace ircd::m::fed::user::keys
}
struct ircd::m::fed::user::keys::query
:server::request
:request
{
using opts = fed::user::opts;
using devices = vector_view<const string_view>;
@ -31,8 +31,10 @@ struct ircd::m::fed::user::keys::query
explicit operator json::object() const
{
const json::object object{in.content};
return object;
return json::object
{
in.content
};
}
explicit
@ -65,7 +67,7 @@ struct ircd::m::fed::user::keys::query
};
struct ircd::m::fed::user::keys::claim
:server::request
:request
{
using opts = fed::user::opts;
using device = std::pair<string_view, string_view>;
@ -79,8 +81,10 @@ struct ircd::m::fed::user::keys::claim
explicit operator json::object() const
{
const json::object object{in.content};
return object;
return json::object
{
in.content
};
}
explicit

View file

@ -17,25 +17,18 @@ namespace ircd::m::fed
};
struct ircd::m::fed::version
:server::request
:request
{
struct opts;
operator json::object() const
explicit operator json::object() const
{
return json::object{in.content};
return json::object
{
in.content
};
}
version(const mutable_buffer &, opts);
version(const mutable_buffer &,
opts);
version() = default;
};
struct ircd::m::fed::version::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {false};
};

File diff suppressed because it is too large Load diff

View file

@ -272,7 +272,7 @@ get__initialsync_remote(client &client,
})
};
const net::hostport remote
const auto remote
{
server?: room.room_id.host()
};

View file

@ -6563,7 +6563,7 @@ console_cmd__stage__send(opt &out, const string_view &line)
"remote", "[id]"
}};
const net::hostport remote
const string_view remote
{
param.at(0)
};
@ -8926,7 +8926,7 @@ console_cmd__room__alias__cache__fetch(opt &out, const string_view &line)
param["alias"]
};
const net::hostport &remote
const auto &remote
{
param["remote"]?
param["remote"]:
@ -11559,7 +11559,7 @@ console_cmd__user__profile__fetch(opt &out, const string_view &line)
param["key"]
};
const net::hostport &remote
const auto &remote
{
param["remote"]?
param["remote"]:
@ -12692,7 +12692,7 @@ console_cmd__fed__head(opt &out, const string_view &line)
m::room_id(param.at(0))
};
const net::hostport remote
const string_view remote
{
param.at(1, room_id.host())
};
@ -12782,7 +12782,7 @@ console_cmd__fed__send(opt &out, const string_view &line)
"remote", "event_id",
}};
const net::hostport remote
const string_view remote
{
param.at(0)
};
@ -12878,7 +12878,7 @@ console_cmd__fed__sync(opt &out, const string_view &line)
m::room_id(param.at(0))
};
const net::hostport remote
const string_view remote
{
param.at(1, room_id.host())
};
@ -13003,7 +13003,7 @@ console_cmd__fed__state(opt &out, const string_view &line)
m::room_id(param.at(0))
};
const net::hostport remote
const string_view remote
{
param.at(1, room_id.host())
};
@ -13114,7 +13114,7 @@ console_cmd__fed__state_ids(opt &out, const string_view &line)
m::room_id(param.at(0))
};
const net::hostport remote
const string_view remote
{
param.at(1, room_id.host())
};
@ -13183,7 +13183,7 @@ console_cmd__fed__backfill(opt &out, const string_view &line)
m::room_id(param.at("room_id"))
};
const net::hostport remote
const string_view remote
{
param["remote"]?
param["remote"]:
@ -13280,7 +13280,7 @@ console_cmd__fed__frontfill(opt &out, const string_view &line)
m::room_id(param.at(0))
};
const net::hostport remote
const string_view remote
{
param.at(1, room_id.host())
};
@ -13350,7 +13350,7 @@ console_cmd__fed__event(opt &out, const string_view &line)
param.at(0)
};
const net::hostport &remote
const auto &remote
{
param.at(1, event_id.host())
};
@ -13448,7 +13448,7 @@ console_cmd__fed__public_rooms(opt &out, const string_view &line)
"remote", "limit", "all_networks", "3pid"
}};
const net::hostport remote
const string_view remote
{
param.at(0)
};
@ -13536,7 +13536,7 @@ console_cmd__fed__auth(opt &out, const string_view &line)
param.at(1)
};
const net::hostport remote
const string_view remote
{
param.at(2, event_id.host())
};
@ -13617,7 +13617,7 @@ console_cmd__fed__query_auth(opt &out, const string_view &line)
param.at(1)
};
const net::hostport remote
const string_view remote
{
param.at(2, event_id.host())
};
@ -13707,7 +13707,7 @@ console_cmd__fed__query__profile(opt &out, const string_view &line)
token(line, ' ', 0)
};
const net::hostport remote
const string_view remote
{
token_count(line, ' ') > 1? token(line, ' ', 1) : user_id.host()
};
@ -13748,7 +13748,7 @@ console_cmd__fed__query__directory(opt &out, const string_view &line)
token(line, ' ', 0)
};
const net::hostport remote
const string_view remote
{
token_count(line, ' ') > 1? token(line, ' ', 1) : room_alias.host()
};
@ -13794,7 +13794,7 @@ console_cmd__fed__user__devices(opt &out, const string_view &line)
param.at("user_id")
};
const net::hostport remote
const string_view remote
{
param.at("remote", user_id.host())
};
@ -13858,7 +13858,7 @@ console_cmd__fed__user__keys__query(opt &out, const string_view &line)
param.at("device_id", string_view{})
};
const net::hostport remote
const string_view remote
{
param.at("remote", user_id.host())
};
@ -13944,7 +13944,7 @@ console_cmd__fed__user__keys__claim(opt &out, const string_view &line)
param.at("algorithm")
};
const net::hostport remote
const string_view remote
{
param.at("remote", user_id.host())
};
@ -14053,10 +14053,7 @@ console_cmd__fed__key__query(opt &out, const string_view &line)
m::fed::key::opts opts;
opts.dynamic = true;
opts.remote = net::hostport
{
param.at(0)
};
opts.remote = param.at("remote");
const unique_buffer<mutable_buffer> buf{24_KiB};
m::fed::key::query request