2018-01-22 12:32:15 +01: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.
|
|
|
|
|
2022-06-19 22:46:33 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// fed/hierarchy.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::fed::hierarchy::hierarchy(const room::id &room_id,
|
|
|
|
const mutable_buffer &buf_,
|
|
|
|
opts opts)
|
|
|
|
:request{[&]
|
|
|
|
{
|
|
|
|
assert(!!opts.remote);
|
|
|
|
|
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
|
|
|
|
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
|
|
|
{
|
|
|
|
thread_local char ridbuf[768];
|
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
|
|
|
buf, "/_matrix/federation/v1/hierarchy/%s?suggested_only=%s",
|
|
|
|
url::encode(ridbuf, room_id),
|
|
|
|
lex_cast(opts.suggested_only),
|
|
|
|
};
|
|
|
|
|
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return request
|
|
|
|
{
|
|
|
|
buf, std::move(opts)
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-28 10:00:08 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/groups.h
|
2018-03-28 10:00:08 +02:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::groups::publicised::publicised(const string_view &node,
|
|
|
|
const vector_view<const id::user> &user_ids,
|
|
|
|
const mutable_buffer &buf_,
|
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-03-28 10:00:08 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!opts.remote))
|
2019-05-27 02:44:12 +02:00
|
|
|
opts.remote = node;
|
2018-03-28 10:00:08 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-03-28 10:00:08 +02:00
|
|
|
json::get<"uri"_>(opts.request) = "/_matrix/federation/v1/get_groups_publicised";
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "POST";
|
2018-03-28 10:00:08 +02:00
|
|
|
|
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
const string_view user_ids_
|
|
|
|
{
|
|
|
|
json::stringify(buf, user_ids.data(), user_ids.data() + user_ids.size())
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(!defined(json::get<"content"_>(opts.request)));
|
|
|
|
json::get<"content"_>(opts.request) = stringify(buf, json::members
|
|
|
|
{
|
|
|
|
{ "user_ids", user_ids_ }
|
|
|
|
});
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-03-28 10:00:08 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-03-28 10:00:08 +02:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-22 19:05:45 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/send.h
|
2018-01-22 19:05:45 +01:00
|
|
|
//
|
|
|
|
|
2018-01-23 20:43:04 +01:00
|
|
|
void
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::send::response::for_each_pdu(const pdus_closure &closure)
|
2018-01-23 20:43:04 +01:00
|
|
|
const
|
|
|
|
{
|
|
|
|
const json::object &pdus
|
|
|
|
{
|
|
|
|
this->get("pdus")
|
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
for(const auto &[event_id, error] : pdus)
|
2018-01-23 20:43:04 +01:00
|
|
|
closure(event_id, error);
|
|
|
|
}
|
|
|
|
|
2020-04-02 05:37:51 +02:00
|
|
|
ircd::m::fed::send::send(const txn::array &pdu,
|
|
|
|
const txn::array &edu,
|
|
|
|
const mutable_buffer &buf_,
|
|
|
|
opts opts)
|
|
|
|
:send{[&]
|
|
|
|
{
|
|
|
|
assert(!!opts.remote);
|
|
|
|
|
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
const string_view &content
|
|
|
|
{
|
|
|
|
txn::create(buf, pdu, edu)
|
|
|
|
};
|
|
|
|
|
|
|
|
consume(buf, size(content));
|
|
|
|
const string_view &txnid
|
|
|
|
{
|
|
|
|
txn::create_id(buf, content)
|
|
|
|
};
|
|
|
|
|
|
|
|
consume(buf, size(txnid));
|
|
|
|
return send
|
|
|
|
{
|
|
|
|
txnid, content, buf, std::move(opts)
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::send::send(const string_view &txnid,
|
|
|
|
const const_buffer &content,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
|
|
|
assert(!!opts.remote);
|
|
|
|
|
|
|
|
assert(!size(opts.out.content));
|
|
|
|
assert(!defined(json::get<"content"_>(opts.request)));
|
2020-03-08 02:15:58 +01:00
|
|
|
json::get<"content"_>(opts.request) = json::object
|
|
|
|
{
|
|
|
|
content
|
|
|
|
};
|
2018-01-22 19:05:45 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "PUT";
|
2018-01-22 19:05:45 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char txnidbuf[256];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
2020-10-02 00:50:16 +02:00
|
|
|
buf, "/_matrix/federation/v1/send/%s",
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(txnidbuf, txnid),
|
2018-01-22 19:05:45 +01:00
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-01-22 19:05:45 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-01-22 19:05:45 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-06 03:35:48 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// fed/rooms.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::fed::rooms::complexity::complexity(const m::id::room &room_id,
|
|
|
|
const mutable_buffer &buf_,
|
|
|
|
opts opts)
|
|
|
|
:request{[&]
|
|
|
|
{
|
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = room_id.host();
|
|
|
|
|
|
|
|
window_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
|
|
|
{
|
|
|
|
thread_local char ridbuf[768];
|
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
|
|
|
buf, "/_matrix/federation/unstable/rooms/%s/complexity",
|
|
|
|
url::encode(ridbuf, room_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
|
|
|
|
|
|
|
return request
|
|
|
|
{
|
|
|
|
buf, std::move(opts)
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-08 22:27:18 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/public_rooms.h
|
2018-04-08 22:27:18 +02:00
|
|
|
//
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
ircd::m::fed::public_rooms::public_rooms(const string_view &remote,
|
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-04-08 22:27:18 +02:00
|
|
|
{
|
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = remote;
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
2020-05-29 10:23:19 +02:00
|
|
|
json::get<"method"_>(opts.request) = "POST";
|
2018-04-08 22:27:18 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-04-08 22:27:18 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char query[2048], tpid[1024], since[1024];
|
2018-04-08 22:27:18 +02:00
|
|
|
std::stringstream qss;
|
|
|
|
pubsetbuf(qss, query);
|
|
|
|
|
2020-05-29 10:23:19 +02:00
|
|
|
if(json::get<"method"_>(opts.request) == "GET")
|
|
|
|
{
|
|
|
|
if(opts.since)
|
|
|
|
qss << "&since="
|
|
|
|
<< url::encode(since, opts.since);
|
2018-04-08 22:27:18 +02:00
|
|
|
|
2020-05-29 10:23:19 +02:00
|
|
|
if(opts.third_party_instance_id)
|
|
|
|
qss << "&third_party_instance_id="
|
|
|
|
<< url::encode(tpid, opts.third_party_instance_id);
|
|
|
|
}
|
2018-04-08 22:27:18 +02:00
|
|
|
|
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/federation/v1/publicRooms?limit=%zu%s%s",
|
2018-04-08 22:27:18 +02:00
|
|
|
opts.limit,
|
2020-05-29 10:23:19 +02:00
|
|
|
opts.include_all_networks?
|
|
|
|
"&include_all_networks=true"_sv:
|
|
|
|
string_view{},
|
2018-04-08 22:27:18 +02:00
|
|
|
view(qss, query)
|
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-04-08 22:27:18 +02:00
|
|
|
}
|
|
|
|
|
2020-05-29 10:23:19 +02:00
|
|
|
if(likely(!defined(json::get<"content"_>(opts.request))))
|
|
|
|
{
|
|
|
|
json::stack out{buf};
|
|
|
|
json::stack::object top{out};
|
|
|
|
if(likely(json::get<"method"_>(opts.request) == "POST"))
|
|
|
|
{
|
|
|
|
if(opts.limit)
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "limit", json::value
|
|
|
|
{
|
|
|
|
long(opts.limit)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(opts.include_all_networks)
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "include_all_networks", json::value
|
|
|
|
{
|
|
|
|
opts.include_all_networks
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(opts.third_party_instance_id)
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "third_party_instance_id", json::value
|
|
|
|
{
|
|
|
|
opts.third_party_instance_id
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(opts.search_term)
|
|
|
|
{
|
|
|
|
json::stack::object filter
|
|
|
|
{
|
|
|
|
top, "filter"
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
filter, "generic_search_term", opts.search_term
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
top.~object();
|
|
|
|
json::get<"content"_>(opts.request) = out.completed();
|
|
|
|
consume(buf, size(string_view(json::get<"content"_>(opts.request))));
|
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-04-08 22:27:18 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-04-08 22:27:18 +02:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-04 03:43:17 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/frontfill.h
|
2018-06-04 03:43:17 +02:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::frontfill::frontfill(const room::id &room_id,
|
|
|
|
const span &span,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2018-06-04 03:43:17 +02:00
|
|
|
:frontfill
|
|
|
|
{
|
|
|
|
room_id,
|
|
|
|
ranges { vector(&span.first, 1), vector(&span.second, 1) },
|
|
|
|
buf,
|
|
|
|
std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::frontfill::frontfill(const room::id &room_id,
|
|
|
|
const ranges &pair,
|
|
|
|
const mutable_buffer &buf_,
|
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-06-04 03:43:17 +02:00
|
|
|
{
|
|
|
|
assert(!!opts.remote);
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "POST";
|
2018-06-04 03:43:17 +02:00
|
|
|
|
2020-10-03 11:27:41 +02:00
|
|
|
mutable_buffer buf{buf_};
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-06-04 03:43:17 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char ridbuf[768];
|
2018-06-04 03:43:17 +02:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2020-10-03 11:29:57 +02:00
|
|
|
buf, "/_matrix/federation/v1/get_missing_events/%s",
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(ridbuf, room_id)
|
2018-06-04 03:43:17 +02:00
|
|
|
};
|
2020-03-08 02:15:58 +01:00
|
|
|
|
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-06-04 03:43:17 +02:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"content"_>(opts.request))))
|
2018-06-04 03:43:17 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
json::get<"content"_>(opts.request) = json::object
|
|
|
|
{
|
2020-10-03 11:27:41 +02:00
|
|
|
make_content(buf, pair, opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
};
|
2020-10-03 11:27:41 +02:00
|
|
|
|
|
|
|
consume(buf, size(string_view(json::get<"content"_>(opts.request))));
|
2018-06-04 03:43:17 +02:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-06-04 03:43:17 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-06-04 03:43:17 +02:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::const_buffer
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::frontfill::make_content(const mutable_buffer &buf,
|
|
|
|
const ranges &pair,
|
|
|
|
const opts &opts)
|
2018-06-04 03:43:17 +02:00
|
|
|
{
|
|
|
|
json::stack out{buf};
|
|
|
|
{
|
|
|
|
// note: This object must be in abc order
|
|
|
|
json::stack::object top{out};
|
2020-10-03 10:39:02 +02:00
|
|
|
|
|
|
|
// earliest
|
2018-06-04 03:43:17 +02:00
|
|
|
{
|
2020-10-03 10:39:02 +02:00
|
|
|
json::stack::array array
|
|
|
|
{
|
|
|
|
top, "earliest_events"
|
|
|
|
};
|
|
|
|
|
2018-06-04 03:43:17 +02:00
|
|
|
for(const auto &id : pair.first)
|
2020-10-03 10:39:02 +02:00
|
|
|
if(likely(id))
|
|
|
|
array.append(id);
|
2018-06-04 03:43:17 +02:00
|
|
|
}
|
2020-10-03 10:39:02 +02:00
|
|
|
|
|
|
|
// latest
|
2018-06-04 03:43:17 +02:00
|
|
|
{
|
2020-10-03 10:39:02 +02:00
|
|
|
json::stack::array array
|
|
|
|
{
|
|
|
|
top, "latest_events"
|
|
|
|
};
|
|
|
|
|
2018-06-04 03:43:17 +02:00
|
|
|
for(const auto &id : pair.second)
|
2020-10-03 10:39:02 +02:00
|
|
|
if(likely(id))
|
|
|
|
array.append(id);
|
2018-06-04 03:43:17 +02:00
|
|
|
}
|
2020-10-03 10:39:02 +02:00
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "limit", json::value
|
|
|
|
{
|
|
|
|
int64_t(opts.limit)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "min_depth", json::value
|
|
|
|
{
|
|
|
|
int64_t(opts.min_depth)
|
|
|
|
}
|
|
|
|
};
|
2018-06-04 03:43:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return out.completed();
|
|
|
|
}
|
|
|
|
|
2018-01-22 12:32:15 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/backfill.h
|
2018-01-22 12:32:15 +01:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::backfill::backfill(const room::id &room_id,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2018-04-06 11:30:26 +02:00
|
|
|
m::event::id::buf event_id_buf;
|
2018-01-22 12:32:15 +01:00
|
|
|
if(!opts.event_id)
|
|
|
|
{
|
2020-11-06 02:58:17 +01:00
|
|
|
event_id_buf = m::room::head::fetch::one(room_id, opts.remote);
|
2018-04-06 11:30:26 +02:00
|
|
|
opts.event_id = event_id_buf;
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = room_id.host();
|
2018-01-22 12:32:15 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
2018-01-22 12:32:15 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char ridbuf[768], eidbuf[768];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2023-01-09 04:16:28 +01:00
|
|
|
buf, "/_matrix/federation/v1/backfill/%s?limit=%zu&v=%s",
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(ridbuf, room_id),
|
2018-01-26 21:20:02 +01:00
|
|
|
opts.limit,
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(eidbuf, opts.event_id),
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/state.h
|
2018-01-22 12:32:15 +01:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::state::state(const room::id &room_id,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = room_id.host();
|
2018-01-22 12:32:15 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
2018-01-22 12:32:15 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2020-05-01 17:51:55 +02:00
|
|
|
thread_local char eidbuf[768], eidqbuf[768];
|
|
|
|
const string_view event_id_query{fmt::sprintf
|
|
|
|
{
|
|
|
|
eidqbuf, "event_id=%s",
|
|
|
|
opts.event_id?
|
|
|
|
url::encode(eidbuf, opts.event_id):
|
|
|
|
string_view{}
|
|
|
|
}};
|
|
|
|
|
|
|
|
thread_local char ridbuf[768];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2023-01-09 04:16:28 +01:00
|
|
|
buf, "/_matrix/federation/v1/%s/%s?%s%s%s",
|
2020-05-01 17:51:55 +02:00
|
|
|
opts.ids_only? "state_ids"_sv : "state"_sv,
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(ridbuf, room_id),
|
2020-05-01 17:51:55 +02:00
|
|
|
opts.event_id?
|
|
|
|
event_id_query:
|
|
|
|
string_view{},
|
|
|
|
opts.event_id && opts.ids_only?
|
|
|
|
"&"_sv:
|
|
|
|
string_view{},
|
|
|
|
opts.ids_only?
|
|
|
|
"auth_chain_ids=0"_sv:
|
|
|
|
string_view{}
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-16 23:24:56 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/query_auth.h
|
2019-02-16 23:24:56 +01:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::query_auth::query_auth(const m::room::id &room_id,
|
|
|
|
const m::event::id &event_id,
|
|
|
|
const json::object &content,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2019-02-16 23:24:56 +01:00
|
|
|
{
|
2020-03-07 22:10:20 +01:00
|
|
|
if(!opts.remote && event_id.version() == "1")
|
2019-02-16 23:24:56 +01:00
|
|
|
opts.remote = event_id.host();
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"content"_>(opts.request))))
|
2019-02-16 23:24:56 +01:00
|
|
|
json::get<"content"_>(opts.request) = content;
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "POST";
|
2019-02-16 23:24:56 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2019-02-16 23:24:56 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char ridbuf[768], eidbuf[768];
|
2019-02-16 23:24:56 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/federation/v1/query_auth/%s/%s",
|
2019-02-16 23:24:56 +01:00
|
|
|
url::encode(ridbuf, room_id),
|
|
|
|
url::encode(eidbuf, event_id),
|
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2019-02-16 23:24:56 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
assert(!!opts.remote);
|
|
|
|
return request
|
2019-02-16 23:24:56 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2019-02-16 23:24:56 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-08 20:27:59 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/event_auth.h
|
2018-04-08 20:27:59 +02:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::event_auth::event_auth(const m::room::id &room_id,
|
|
|
|
const m::event::id &event_id,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-04-08 20:27:59 +02:00
|
|
|
{
|
2020-03-07 22:10:20 +01:00
|
|
|
if(!opts.remote && event_id.version() == "1")
|
2018-04-08 20:27:59 +02:00
|
|
|
opts.remote = event_id.host();
|
|
|
|
|
2020-03-07 22:10:20 +01:00
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = room_id.host();
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
2018-04-08 20:27:59 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-04-08 20:27:59 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char ridbuf[768], eidbuf[768];
|
2019-04-25 02:23:28 +02:00
|
|
|
if(opts.ids_only)
|
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2023-01-09 04:16:28 +01:00
|
|
|
buf, "/_matrix/federation/v1/state_ids/%s?event_id=%s&pdu_ids=0",
|
2019-04-25 02:23:28 +02:00
|
|
|
url::encode(ridbuf, room_id),
|
|
|
|
url::encode(eidbuf, event_id),
|
|
|
|
};
|
|
|
|
else
|
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2020-12-10 14:30:30 +01:00
|
|
|
buf, "/_matrix/federation/v1/event_auth/%s/%s%s",
|
2019-04-25 02:23:28 +02:00
|
|
|
url::encode(ridbuf, room_id),
|
|
|
|
url::encode(eidbuf, event_id),
|
2020-12-10 14:30:30 +01:00
|
|
|
opts.ids?
|
|
|
|
"?auth_chain=0&auth_chain_ids=1"_sv:
|
|
|
|
string_view{},
|
2019-04-25 02:23:28 +02:00
|
|
|
};
|
2018-04-08 20:27:59 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-04-08 20:27:59 +02:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
assert(!!opts.remote);
|
|
|
|
return request
|
2018-04-08 20:27:59 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-04-08 20:27:59 +02:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-06-20 03:12:09 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// fed/event_near.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::fed::event_near::event_near(const m::room::id &room_id,
|
|
|
|
const mutable_buffer &buf_,
|
|
|
|
const int64_t ts,
|
|
|
|
opts opts)
|
|
|
|
:request{[&]
|
|
|
|
{
|
|
|
|
const auto _ts
|
|
|
|
{
|
|
|
|
ts != 0?
|
|
|
|
std::abs(ts):
|
|
|
|
now<milliseconds>().count()
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto dir
|
|
|
|
{
|
|
|
|
ts <= 0? 'b': 'f'
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = room_id.host();
|
|
|
|
|
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
|
|
|
|
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
|
|
|
{
|
|
|
|
thread_local char ridbuf[768];
|
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
|
|
|
buf, "/_matrix/federation/unstable/org.matrix.msc3030/timestamp_to_event/%s?ts=%lu&dir=%c",
|
|
|
|
url::encode(ridbuf, room_id),
|
|
|
|
uint64_t(_ts),
|
|
|
|
dir,
|
|
|
|
};
|
|
|
|
|
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!!opts.remote);
|
|
|
|
return request
|
|
|
|
{
|
|
|
|
buf, std::move(opts)
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-22 12:32:15 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/event.h
|
2018-01-22 12:32:15 +01:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::event::event(const m::event::id &event_id,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2020-03-07 22:10:20 +01:00
|
|
|
if(!opts.remote && event_id.version() == "1")
|
2018-01-22 12:32:15 +01:00
|
|
|
opts.remote = event_id.host();
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
2018-01-22 12:32:15 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char eidbuf[768];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2023-01-09 04:16:28 +01:00
|
|
|
buf, "/_matrix/federation/v1/event/%s",
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(eidbuf, event_id),
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
assert(!!opts.remote);
|
|
|
|
return request
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-01-22 19:05:45 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-03 21:58:18 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/invite.h
|
2018-04-03 21:58:18 +02:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::invite::invite(const room::id &room_id,
|
|
|
|
const id::event &event_id,
|
|
|
|
const json::object &content,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-04-03 21:58:18 +02:00
|
|
|
{
|
|
|
|
assert(!size(opts.out.content));
|
|
|
|
assert(!defined(json::get<"content"_>(opts.request)));
|
2020-03-08 02:15:58 +01:00
|
|
|
json::get<"content"_>(opts.request) = content;
|
2018-04-03 21:58:18 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "PUT";
|
2018-04-03 21:58:18 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-04-03 21:58:18 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char ridbuf[768], eidbuf[768];
|
2018-04-03 21:58:18 +02:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/federation/v1/invite/%s/%s",
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(ridbuf, room_id),
|
|
|
|
url::encode(eidbuf, event_id)
|
2018-04-03 21:58:18 +02:00
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2019-07-12 05:32:32 +02:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
assert(!!opts.remote);
|
|
|
|
return request
|
2019-07-12 05:32:32 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2019-07-12 05:32:32 +02:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/invite2.h
|
2019-07-12 05:32:32 +02:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::invite2::invite2(const room::id &room_id,
|
|
|
|
const id::event &event_id,
|
|
|
|
const json::object &content,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2019-07-12 05:32:32 +02:00
|
|
|
{
|
|
|
|
assert(!size(opts.out.content));
|
2020-03-08 02:15:58 +01:00
|
|
|
assert(!defined(json::get<"content"_>(opts.request)));
|
|
|
|
json::get<"content"_>(opts.request) = content;
|
2019-07-12 05:32:32 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "PUT";
|
2019-07-12 05:32:32 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2019-07-12 05:32:32 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char ridbuf[768], eidbuf[768];
|
2019-07-12 05:32:32 +02:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/federation/v2/invite/%s/%s",
|
2019-07-12 05:32:32 +02:00
|
|
|
url::encode(ridbuf, room_id),
|
|
|
|
url::encode(eidbuf, event_id)
|
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-04-03 21:58:18 +02:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
assert(!!opts.remote);
|
|
|
|
return request
|
2018-04-03 21:58:18 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-04-03 21:58:18 +02:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-22 19:05:45 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/send_join.h
|
2018-01-22 19:05:45 +01:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::send_join::send_join(const room::id &room_id,
|
|
|
|
const id::event &event_id,
|
|
|
|
const const_buffer &content,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
|
|
|
assert(!!opts.remote);
|
|
|
|
|
|
|
|
assert(!size(opts.out.content));
|
|
|
|
assert(!defined(json::get<"content"_>(opts.request)));
|
2020-03-08 02:15:58 +01:00
|
|
|
json::get<"content"_>(opts.request) = json::object
|
|
|
|
{
|
|
|
|
content
|
|
|
|
};
|
2018-01-22 19:05:45 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "PUT";
|
2018-01-22 19:05:45 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char ridbuf[768], uidbuf[768];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
2023-03-03 22:47:05 +01:00
|
|
|
buf, "/_matrix/federation/v2/send_%s/%s/%s?omit_members=%s",
|
2022-06-20 03:13:15 +02:00
|
|
|
opts.knock? "knock"_sv: "join"_sv,
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(ridbuf, room_id),
|
2023-03-03 22:47:05 +01:00
|
|
|
url::encode(uidbuf, event_id),
|
|
|
|
opts.omit_members? "true": "false",
|
2018-01-22 19:05:45 +01:00
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-01-22 19:05:45 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/make_join.h
|
2018-01-22 12:32:15 +01:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::make_join::make_join(const room::id &room_id,
|
|
|
|
const id::user &user_id_,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = room_id.host();
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
2018-01-22 12:32:15 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2019-04-11 14:14:44 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
id::user::buf user_id_buf;
|
|
|
|
const id::user &user_id
|
2019-04-11 14:14:44 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
user_id_?: id::user
|
|
|
|
{
|
|
|
|
user_id_buf, id::generate, my_host()
|
|
|
|
}
|
|
|
|
};
|
2019-04-11 14:14:44 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char ridbuf[768], uidbuf[768];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2022-06-20 03:13:15 +02:00
|
|
|
buf, "/_matrix/federation/v1/make_%s/%s/%s"
|
2020-03-17 06:36:03 +01:00
|
|
|
"?ver=1"
|
|
|
|
"&ver=2"
|
|
|
|
"&ver=3"
|
|
|
|
"&ver=4"
|
|
|
|
"&ver=5"
|
|
|
|
"&ver=6"
|
|
|
|
"&ver=7"
|
|
|
|
"&ver=8"
|
2022-06-18 02:22:14 +02:00
|
|
|
"&ver=9"
|
|
|
|
"&ver=10"
|
|
|
|
"&ver=11"
|
|
|
|
"&ver=12"
|
|
|
|
"&ver=13"
|
|
|
|
"&ver=14"
|
|
|
|
"&ver=15"
|
|
|
|
"&ver=16"
|
2020-03-19 07:00:32 +01:00
|
|
|
"&ver=org.matrix.msc2432"
|
2022-06-20 03:13:15 +02:00
|
|
|
,opts.knock? "knock"_sv: "join"_sv
|
2020-03-17 06:36:03 +01:00
|
|
|
,url::encode(ridbuf, room_id)
|
|
|
|
,url::encode(uidbuf, user_id)
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-04-03 03:24:57 +02:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-04-03 03:24:57 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-04-03 03:24:57 +02:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/user_keys.h
|
2018-04-03 03:24:57 +02:00
|
|
|
//
|
|
|
|
|
2019-02-08 06:40:32 +01:00
|
|
|
//
|
|
|
|
// query
|
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::query::query(const m::user::id &user_id,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2019-02-07 09:11:03 +01:00
|
|
|
:query
|
|
|
|
{
|
|
|
|
user_id,
|
|
|
|
string_view{},
|
|
|
|
buf,
|
|
|
|
std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::query::query(const m::user::id &user_id,
|
|
|
|
const string_view &device_id,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2019-02-07 09:11:03 +01:00
|
|
|
:query
|
|
|
|
{
|
|
|
|
user_devices
|
|
|
|
{
|
|
|
|
user_id, vector_view<const string_view>
|
|
|
|
{
|
|
|
|
&device_id, !empty(device_id)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
buf,
|
|
|
|
std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::query::query(const user_devices &v,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2019-02-07 09:11:03 +01:00
|
|
|
:query
|
|
|
|
{
|
|
|
|
vector_view<const user_devices>
|
|
|
|
{
|
|
|
|
&v, 1
|
|
|
|
},
|
|
|
|
buf,
|
|
|
|
std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::query::query(const users_devices &v,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2019-07-30 20:30:44 +02:00
|
|
|
:query{[&v, &buf, &opts]
|
2019-02-07 09:11:03 +01:00
|
|
|
{
|
2019-02-08 06:40:32 +01:00
|
|
|
const json::object &content
|
|
|
|
{
|
2019-07-30 21:12:26 +02:00
|
|
|
make_content(buf, v)
|
2019-02-08 06:40:32 +01:00
|
|
|
};
|
|
|
|
|
2019-07-30 20:30:44 +02:00
|
|
|
return query
|
2019-02-07 09:11:03 +01:00
|
|
|
{
|
2019-02-08 06:40:32 +01:00
|
|
|
content, buf + size(string_view(content)), std::move(opts)
|
2019-02-07 09:11:03 +01:00
|
|
|
};
|
2019-07-30 20:30:44 +02:00
|
|
|
}()}
|
|
|
|
{
|
2019-02-07 09:11:03 +01:00
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::query::query(const users_devices_map &m,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2019-07-30 21:12:26 +02:00
|
|
|
:query{[&m, &buf, &opts]
|
2019-02-21 23:57:45 +01:00
|
|
|
{
|
|
|
|
const json::object &content
|
|
|
|
{
|
2019-07-30 21:12:26 +02:00
|
|
|
make_content(buf, m)
|
2019-02-21 23:57:45 +01:00
|
|
|
};
|
|
|
|
|
2019-07-30 20:30:44 +02:00
|
|
|
return query
|
2019-02-21 23:57:45 +01:00
|
|
|
{
|
|
|
|
content, buf + size(string_view(content)), std::move(opts)
|
|
|
|
};
|
2019-07-30 20:30:44 +02:00
|
|
|
}()}
|
|
|
|
{
|
2019-02-21 23:57:45 +01:00
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::query::query(const json::object &content,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2019-02-07 08:16:35 +01:00
|
|
|
{
|
|
|
|
assert(!!opts.remote);
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "POST";
|
2019-02-07 08:16:35 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2019-02-07 08:16:35 +01:00
|
|
|
json::get<"uri"_>(opts.request) = "/_matrix/federation/v1/user/keys/query";
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"content"_>(opts.request))))
|
2019-02-07 09:11:03 +01:00
|
|
|
json::get<"content"_>(opts.request) = content;
|
2019-02-07 08:16:35 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2019-02-07 08:16:35 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2019-02-07 08:16:35 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-07-30 21:12:26 +02:00
|
|
|
ircd::json::object
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::query::make_content(const mutable_buffer &buf,
|
|
|
|
const users_devices &v)
|
2019-07-30 21:12:26 +02:00
|
|
|
{
|
|
|
|
json::stack out{buf};
|
|
|
|
{
|
|
|
|
json::stack::object top{out};
|
|
|
|
json::stack::object device_keys
|
|
|
|
{
|
|
|
|
top, "device_keys"
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto &[user_id, devices] : v)
|
|
|
|
{
|
|
|
|
json::stack::array array
|
|
|
|
{
|
|
|
|
device_keys, user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto &device_id : devices)
|
|
|
|
array.append(device_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out.completed();
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::json::object
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::query::make_content(const mutable_buffer &buf,
|
|
|
|
const users_devices_map &m)
|
2019-07-30 21:12:26 +02:00
|
|
|
{
|
|
|
|
json::stack out{buf};
|
|
|
|
{
|
|
|
|
json::stack::object top{out};
|
|
|
|
json::stack::object device_keys
|
|
|
|
{
|
|
|
|
top, "device_keys"
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto &[user_id, devices] : m)
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
device_keys, user_id, devices
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return out.completed();
|
|
|
|
}
|
|
|
|
|
2019-02-08 06:40:32 +01:00
|
|
|
//
|
|
|
|
// claim
|
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::claim::claim(const m::user::id &user_id,
|
|
|
|
const string_view &device_id,
|
|
|
|
const string_view &algorithm,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2019-02-08 06:40:32 +01:00
|
|
|
:claim
|
|
|
|
{
|
|
|
|
user_id,
|
|
|
|
device
|
|
|
|
{
|
|
|
|
device_id, algorithm
|
|
|
|
},
|
|
|
|
buf,
|
|
|
|
std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::claim::claim(const m::user::id &user_id,
|
|
|
|
const device &device,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2019-02-08 06:40:32 +01:00
|
|
|
:claim
|
|
|
|
{
|
|
|
|
user_devices
|
|
|
|
{
|
|
|
|
user_id, { &device, 1 }
|
|
|
|
},
|
|
|
|
buf,
|
|
|
|
std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::claim::claim(const user_devices &ud,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2019-02-08 06:40:32 +01:00
|
|
|
:claim
|
|
|
|
{
|
|
|
|
vector_view<const user_devices>
|
|
|
|
{
|
|
|
|
&ud, 1
|
|
|
|
},
|
|
|
|
buf,
|
|
|
|
std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::claim::claim(const users_devices &v,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2019-07-30 20:30:44 +02:00
|
|
|
:claim{[&v, &buf, &opts]
|
2019-02-08 06:40:32 +01:00
|
|
|
{
|
2019-02-22 01:46:23 +01:00
|
|
|
const json::object &content
|
|
|
|
{
|
2019-07-30 21:12:26 +02:00
|
|
|
make_content(buf, v)
|
2019-02-22 01:46:23 +01:00
|
|
|
};
|
|
|
|
|
2019-07-30 20:30:44 +02:00
|
|
|
return claim
|
2019-02-22 01:46:23 +01:00
|
|
|
{
|
|
|
|
content, buf + size(string_view(content)), std::move(opts)
|
|
|
|
};
|
2019-07-30 20:30:44 +02:00
|
|
|
}()}
|
|
|
|
{
|
2019-02-22 01:46:23 +01:00
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::claim::claim(const users_devices_map &m,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2019-07-30 21:12:26 +02:00
|
|
|
:claim{[&m, &buf, &opts]
|
2019-02-22 01:46:23 +01:00
|
|
|
{
|
2019-02-08 06:40:32 +01:00
|
|
|
const json::object &content
|
|
|
|
{
|
2019-07-30 21:12:26 +02:00
|
|
|
make_content(buf, m)
|
2019-02-08 06:40:32 +01:00
|
|
|
};
|
|
|
|
|
2019-07-30 20:30:44 +02:00
|
|
|
return claim
|
2019-02-08 06:40:32 +01:00
|
|
|
{
|
|
|
|
content, buf + size(string_view(content)), std::move(opts)
|
|
|
|
};
|
2019-07-30 20:30:44 +02:00
|
|
|
}()}
|
|
|
|
{
|
2019-02-08 06:40:32 +01:00
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::claim::claim(const json::object &content,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2019-02-07 08:16:35 +01:00
|
|
|
{
|
|
|
|
assert(!!opts.remote);
|
|
|
|
|
2020-04-01 03:06:36 +02:00
|
|
|
assert(!defined(json::get<"content"_>(opts.request)));
|
|
|
|
json::get<"content"_>(opts.request) = content;
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
2019-02-07 08:16:35 +01:00
|
|
|
json::get<"method"_>(opts.request) = "POST";
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
|
|
|
json::get<"uri"_>(opts.request) = "/_matrix/federation/v1/user/keys/claim";
|
2019-02-07 08:16:35 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2019-02-07 08:16:35 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2019-02-07 08:16:35 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-07-30 21:12:26 +02:00
|
|
|
ircd::json::object
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::claim::make_content(const mutable_buffer &buf,
|
|
|
|
const users_devices &v)
|
2019-07-30 21:12:26 +02:00
|
|
|
{
|
|
|
|
json::stack out{buf};
|
|
|
|
{
|
|
|
|
json::stack::object top{out};
|
|
|
|
json::stack::object one_time_keys
|
|
|
|
{
|
|
|
|
top, "one_time_keys"
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto &[user_id, devices] : v)
|
|
|
|
{
|
|
|
|
json::stack::object user
|
|
|
|
{
|
|
|
|
one_time_keys, user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto &[device_id, algorithm_name] : devices)
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
user, device_id, algorithm_name
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out.completed();
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::json::object
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::keys::claim::make_content(const mutable_buffer &buf,
|
|
|
|
const users_devices_map &v)
|
2019-07-30 21:12:26 +02:00
|
|
|
{
|
|
|
|
json::stack out{buf};
|
|
|
|
{
|
|
|
|
json::stack::object top{out};
|
|
|
|
json::stack::object one_time_keys
|
|
|
|
{
|
|
|
|
top, "one_time_keys"
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto &[user_id, devices] : v)
|
|
|
|
{
|
|
|
|
json::stack::object user
|
|
|
|
{
|
|
|
|
one_time_keys, user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto &[device_id, algorithm_name] : devices)
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
user, device_id, algorithm_name
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out.completed();
|
|
|
|
}
|
|
|
|
|
2019-02-08 06:04:52 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/user.h
|
2019-02-08 06:04:52 +01:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::user::devices::devices(const id::user &user_id,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-04-03 03:24:57 +02:00
|
|
|
{
|
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = user_id.host();
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
2018-04-03 03:24:57 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-04-03 03:24:57 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
thread_local char uidbuf[768];
|
2018-04-03 03:24:57 +02:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/federation/v1/user/devices/%s",
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(uidbuf, user_id)
|
2018-04-03 03:24:57 +02:00
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
2018-02-19 23:34:34 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2018-02-25 08:53:32 +01:00
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/query.h
|
2018-02-25 08:53:32 +01:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
namespace ircd::m::fed
|
2018-02-25 08:53:32 +01:00
|
|
|
{
|
|
|
|
thread_local char query_arg_buf[1024];
|
2018-03-09 18:39:56 +01:00
|
|
|
thread_local char query_url_buf[1024];
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::query::directory::directory(const id::room_alias &room_alias,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2018-02-25 08:53:32 +01:00
|
|
|
:query
|
|
|
|
{
|
|
|
|
"directory",
|
|
|
|
fmt::sprintf
|
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
query_arg_buf, "room_alias=%s",
|
|
|
|
url::encode(query_url_buf, room_alias)
|
2018-02-25 08:53:32 +01:00
|
|
|
},
|
|
|
|
buf,
|
2018-02-27 06:43:02 +01:00
|
|
|
std::move(opts)
|
2018-02-25 08:53:32 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::query::profile::profile(const id::user &user_id,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2018-02-25 08:53:32 +01:00
|
|
|
:query
|
|
|
|
{
|
|
|
|
"profile",
|
|
|
|
fmt::sprintf
|
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
query_arg_buf, "user_id=%s",
|
|
|
|
url::encode(query_url_buf, user_id)
|
2018-02-25 08:53:32 +01:00
|
|
|
},
|
|
|
|
buf,
|
2018-02-27 06:43:02 +01:00
|
|
|
std::move(opts)
|
2018-02-25 08:53:32 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::query::profile::profile(const id::user &user_id,
|
|
|
|
const string_view &field,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2018-02-25 09:28:55 +01:00
|
|
|
:query
|
|
|
|
{
|
|
|
|
"profile",
|
|
|
|
fmt::sprintf
|
|
|
|
{
|
|
|
|
query_arg_buf, "user_id=%s%s%s",
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(query_url_buf, string_view{user_id}),
|
2020-03-08 02:15:58 +01:00
|
|
|
!empty(field)? "&field="_sv: string_view{},
|
2018-02-25 09:28:55 +01:00
|
|
|
field
|
|
|
|
},
|
|
|
|
buf,
|
2018-02-27 06:43:02 +01:00
|
|
|
std::move(opts)
|
2018-02-25 09:28:55 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::query::query(const string_view &type,
|
|
|
|
const string_view &args,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-02-25 08:53:32 +01:00
|
|
|
{
|
|
|
|
assert(!!opts.remote);
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
2018-02-25 08:53:32 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-02-25 08:53:32 +01:00
|
|
|
{
|
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/federation/v1/query/%s%s%s",
|
2018-02-25 08:53:32 +01:00
|
|
|
type,
|
2020-03-08 02:15:58 +01:00
|
|
|
args? "?"_sv: string_view{},
|
2018-02-25 08:53:32 +01:00
|
|
|
args
|
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-02-25 08:53:32 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-02-25 08:53:32 +01:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-02-25 08:53:32 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-07 23:46:53 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/key.h
|
2018-05-07 23:46:53 +02:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::key::keys::keys(const string_view &server_name,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2018-05-11 11:02:46 +02:00
|
|
|
:keys
|
|
|
|
{
|
|
|
|
server_key{server_name, ""}, buf, std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::key::keys::keys(const server_key &server_key,
|
2020-03-08 02:15:58 +01:00
|
|
|
const mutable_buffer &buf_,
|
2020-03-06 04:35:20 +01:00
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-05-08 00:28:58 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
const auto &[server_name, key_id]
|
|
|
|
{
|
|
|
|
server_key
|
|
|
|
};
|
2018-05-08 00:28:58 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!opts.remote))
|
|
|
|
opts.remote = server_name;
|
2018-05-08 00:28:58 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
2018-05-08 00:28:58 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-05-11 11:02:46 +02:00
|
|
|
{
|
|
|
|
if(!empty(key_id))
|
|
|
|
{
|
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2023-02-22 21:20:23 +01:00
|
|
|
buf, "/_matrix/key/v2/server/%s",
|
2020-03-08 02:15:58 +01:00
|
|
|
key_id
|
2018-05-11 11:02:46 +02:00
|
|
|
};
|
2020-03-08 02:15:58 +01:00
|
|
|
|
|
|
|
consume(buf, size(json::get<"uri"_>(opts.request)));
|
2018-05-11 11:02:46 +02:00
|
|
|
}
|
2023-02-22 21:20:23 +01:00
|
|
|
else json::get<"uri"_>(opts.request) = "/_matrix/key/v2/server";
|
2018-05-11 11:02:46 +02:00
|
|
|
}
|
2018-05-08 00:28:58 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-05-08 00:28:58 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-05-08 00:28:58 +02:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
namespace ircd::m::fed
|
2018-05-07 23:46:53 +02:00
|
|
|
{
|
|
|
|
static const_buffer
|
|
|
|
_make_server_keys(const vector_view<const key::server_key> &,
|
|
|
|
const mutable_buffer &);
|
|
|
|
}
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::key::query::query(const vector_view<const server_key> &keys,
|
|
|
|
const mutable_buffer &buf_,
|
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
2018-05-07 23:46:53 +02:00
|
|
|
{
|
|
|
|
assert(!!opts.remote);
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "POST";
|
2018-05-07 23:46:53 +02:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
2018-05-07 23:46:53 +02:00
|
|
|
json::get<"uri"_>(opts.request) = "/_matrix/key/v2/query";
|
|
|
|
|
|
|
|
window_buffer buf{buf_};
|
2020-03-08 02:15:58 +01:00
|
|
|
if(likely(!defined(json::get<"content"_>(opts.request))))
|
2018-05-07 23:46:53 +02:00
|
|
|
{
|
|
|
|
buf([&keys](const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
return _make_server_keys(keys, buf);
|
|
|
|
});
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
json::get<"content"_>(opts.request) = json::object
|
|
|
|
{
|
|
|
|
buf.completed()
|
|
|
|
};
|
2018-05-07 23:46:53 +02:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
return request
|
2018-05-07 23:46:53 +02:00
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, std::move(opts)
|
2018-05-07 23:46:53 +02:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static ircd::const_buffer
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::_make_server_keys(const vector_view<const key::server_key> &keys,
|
|
|
|
const mutable_buffer &buf)
|
2018-05-07 23:46:53 +02:00
|
|
|
{
|
|
|
|
json::stack out{buf};
|
2019-05-09 02:36:13 +02:00
|
|
|
json::stack::object top{out};
|
|
|
|
json::stack::object server_keys
|
2018-05-07 23:46:53 +02:00
|
|
|
{
|
2019-05-09 02:36:13 +02:00
|
|
|
top, "server_keys"
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto &[server_name, key_id] : keys)
|
|
|
|
{
|
|
|
|
json::stack::object server_object
|
2018-05-07 23:46:53 +02:00
|
|
|
{
|
2019-05-09 02:36:13 +02:00
|
|
|
server_keys, server_name
|
|
|
|
};
|
|
|
|
|
|
|
|
if(key_id)
|
|
|
|
{
|
|
|
|
json::stack::object key_object
|
2018-05-07 23:46:53 +02:00
|
|
|
{
|
2019-05-09 02:36:13 +02:00
|
|
|
server_object, key_id
|
2018-05-08 00:28:58 +02:00
|
|
|
};
|
2019-05-09 02:36:13 +02:00
|
|
|
|
|
|
|
//json::stack::member mvut
|
|
|
|
//{
|
|
|
|
// key_object, "minimum_valid_until_ts", json::value(0L)
|
|
|
|
//};
|
2018-05-07 23:46:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 02:36:13 +02:00
|
|
|
server_keys.~object();
|
|
|
|
top.~object();
|
2018-05-07 23:46:53 +02:00
|
|
|
return out.completed();
|
|
|
|
}
|
|
|
|
|
2018-02-25 08:53:32 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2018-02-19 23:34:34 +01:00
|
|
|
//
|
2020-03-06 04:35:20 +01:00
|
|
|
// fed/version.h
|
2018-02-19 23:34:34 +01:00
|
|
|
//
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::version::version(const mutable_buffer &buf,
|
|
|
|
opts opts)
|
2020-03-08 02:15:58 +01:00
|
|
|
:request{[&]
|
|
|
|
{
|
|
|
|
assert(!!opts.remote);
|
|
|
|
|
|
|
|
if(likely(!defined(json::get<"method"_>(opts.request))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
|
|
|
|
|
|
|
if(likely(!defined(json::get<"uri"_>(opts.request))))
|
|
|
|
json::get<"uri"_>(opts.request) = "/_matrix/federation/v1/version";
|
|
|
|
|
|
|
|
return request
|
|
|
|
{
|
|
|
|
buf, std::move(opts)
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// fed/request.h
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// request::request
|
|
|
|
//
|
|
|
|
|
2020-03-08 04:01:59 +01:00
|
|
|
ircd::m::fed::request::request(const mutable_buffer &buf_,
|
2020-03-08 02:15:58 +01:00
|
|
|
opts &&opts)
|
2018-02-19 23:34:34 +01:00
|
|
|
:server::request{[&]
|
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
// Requestor must always provide a remote by this point.
|
2018-02-19 23:34:34 +01:00
|
|
|
assert(!!opts.remote);
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
// Requestor must always generate a uri by this point
|
|
|
|
assert(defined(json::get<"uri"_>(opts.request)));
|
|
|
|
|
|
|
|
// Default the origin to my primary homeserver
|
|
|
|
if(likely(!defined(json::get<"origin"_>(opts.request))))
|
2018-02-19 23:34:34 +01:00
|
|
|
json::get<"origin"_>(opts.request) = my_host();
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
// Default the destination to the remote origin
|
|
|
|
if(likely(!defined(json::get<"destination"_>(opts.request))))
|
|
|
|
json::get<"destination"_>(opts.request) = opts.remote;
|
2018-02-19 23:34:34 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
// Set the outgoing HTTP content from the request's content field.
|
|
|
|
if(likely(defined(json::get<"content"_>(opts.request))))
|
|
|
|
opts.out.content = json::get<"content"_>(opts.request);
|
|
|
|
|
|
|
|
// Allows for the reverse to ensure these values are set.
|
|
|
|
if(!defined(json::get<"content"_>(opts.request)))
|
|
|
|
json::get<"content"_>(opts.request) = json::object{opts.out.content};
|
|
|
|
|
|
|
|
// Defaults the method as a convenience if none specified.
|
|
|
|
if(!defined(json::get<"method"_>(opts.request)))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
2018-02-19 23:34:34 +01:00
|
|
|
|
2020-03-08 04:01:59 +01:00
|
|
|
// Perform well-known query; note that we hijack the user's buffer to make
|
|
|
|
// this query and receive the result at the front of it. When there's no
|
|
|
|
// well-known this fails silently by just returning the input (likely).
|
2020-04-26 23:53:00 +02:00
|
|
|
const string_view &target
|
2020-03-08 04:01:59 +01:00
|
|
|
{
|
2020-10-14 15:59:30 +02:00
|
|
|
fed::server(buf_, opts.remote, opts.wkopts)
|
2020-03-08 04:01:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Devote the remaining buffer for HTTP as otherwise intended.
|
|
|
|
const mutable_buffer buf
|
|
|
|
{
|
2020-04-26 23:53:00 +02:00
|
|
|
buf_ + size(target)
|
|
|
|
};
|
|
|
|
|
|
|
|
const net::hostport remote
|
|
|
|
{
|
|
|
|
target
|
2020-03-08 04:01:59 +01:00
|
|
|
};
|
|
|
|
|
2020-10-03 10:19:32 +02:00
|
|
|
// Note that we override the HTTP Host header with the well-known
|
|
|
|
// remote; otherwise default is the destination above which may differ.
|
|
|
|
const http::header addl_headers[]
|
2020-03-08 04:01:59 +01:00
|
|
|
{
|
2020-10-03 10:19:32 +02:00
|
|
|
{ "Host", service(remote)? host(remote): target }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Generate the request head including the X-Matrix into buffer.
|
|
|
|
opts.out.head = opts.request(buf, addl_headers);
|
2018-02-19 23:34:34 +01:00
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
// Setup some buffering features which can optimize the server::request
|
2018-02-19 23:34:34 +01:00
|
|
|
if(!size(opts.in))
|
|
|
|
{
|
2018-04-06 07:45:04 +02:00
|
|
|
opts.in.head = buf + size(opts.out.head);
|
2018-04-06 09:21:32 +02:00
|
|
|
opts.in.content = opts.dynamic?
|
|
|
|
mutable_buffer{}: // server::request will allocate new mem
|
|
|
|
opts.in.head; // server::request will auto partition
|
2018-02-19 23:34:34 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
// Launch the request
|
2018-02-19 23:34:34 +01:00
|
|
|
return server::request
|
|
|
|
{
|
2020-04-26 23:53:00 +02:00
|
|
|
remote,
|
2020-03-06 05:10:55 +01:00
|
|
|
std::move(opts.out),
|
|
|
|
std::move(opts.in),
|
|
|
|
opts.sopts
|
2018-02-19 23:34:34 +01:00
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
2018-04-06 07:11:46 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2020-03-08 02:15:58 +01:00
|
|
|
// fed/fed.h
|
2018-04-06 07:11:46 +02:00
|
|
|
//
|
|
|
|
|
2020-04-26 04:40:46 +02:00
|
|
|
namespace ircd::m::fed
|
|
|
|
{
|
|
|
|
template<class closure>
|
|
|
|
static decltype(auto)
|
|
|
|
with_server(const string_view &,
|
2020-10-15 06:56:28 +02:00
|
|
|
const well_known::opts &,
|
2020-04-26 04:40:46 +02:00
|
|
|
closure &&);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class closure>
|
|
|
|
decltype(auto)
|
2020-10-15 06:56:28 +02:00
|
|
|
ircd::m::fed::with_server(const string_view &name,
|
|
|
|
const well_known::opts &opts,
|
2020-04-26 04:40:46 +02:00
|
|
|
closure&& c)
|
|
|
|
{
|
|
|
|
char buf[rfc3986::DOMAIN_BUFSIZE];
|
|
|
|
const auto remote
|
|
|
|
{
|
2020-10-15 06:56:28 +02:00
|
|
|
server(buf, name, opts)
|
2020-04-26 04:40:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return c(remote);
|
|
|
|
}
|
|
|
|
|
2020-10-16 09:37:56 +02:00
|
|
|
/// Perform operations to prepare for a request to remote server. This may
|
|
|
|
/// initiate the resolution of server names and establish links. This call
|
|
|
|
/// returns quickly, but we make no guarantee for all cases; this will yield
|
|
|
|
/// the ircd::ctx for local cache queries, etc.
|
|
|
|
bool
|
|
|
|
ircd::m::fed::prelink(const string_view &name)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
well_known::opts opts;
|
|
|
|
string_view target{name};
|
|
|
|
net::hostport remote{target};
|
|
|
|
char buf[rfc3986::DOMAIN_BUFSIZE];
|
|
|
|
ctx::future<string_view> server_name
|
|
|
|
{
|
|
|
|
!port(remote)?
|
|
|
|
well_known::get(buf, host(remote), opts):
|
|
|
|
ctx::future<string_view>{ctx::already, name}
|
|
|
|
};
|
|
|
|
|
|
|
|
// well-known resolution has now been dispatched asynchronously.
|
|
|
|
// If we get an immediate result from cache we can proceed past
|
|
|
|
// here, otherwise we don't wait. When the future goes out of
|
|
|
|
// scope the well-known worker still completes the request and
|
|
|
|
// caches the result (i.e prefetch behavior).
|
|
|
|
if(!server_name.wait(seconds(0), std::nothrow))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//TODO: split and reuse fed::server()
|
|
|
|
target = string_view{server_name};
|
|
|
|
remote = target;
|
|
|
|
if(!port(remote) && !service(remote))
|
|
|
|
{
|
|
|
|
service(remote) = m::canon_service;
|
|
|
|
target = net::canonize(buf, remote);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resolves DNS and establishes TCP asynchronously once we have a
|
|
|
|
// peer name. This returns false if the peer has a cached error.
|
|
|
|
if(!server::prelink(target))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch(const ctx::interrupted &)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-15 06:56:28 +02:00
|
|
|
/// Manually force the clearing of cached errors for remote server to
|
|
|
|
/// allow another attempt. Note that not all possible cached errors may
|
|
|
|
/// be cleared by this.
|
2020-04-26 04:40:46 +02:00
|
|
|
bool
|
2020-10-15 06:56:28 +02:00
|
|
|
ircd::m::fed::clear_error(const string_view &name)
|
2020-04-26 04:40:46 +02:00
|
|
|
{
|
2020-10-15 06:56:28 +02:00
|
|
|
well_known::opts opts;
|
|
|
|
opts.request = false;
|
|
|
|
opts.expired = true;
|
|
|
|
return with_server(name, opts, []
|
2020-04-26 04:40:46 +02:00
|
|
|
(const auto &remote)
|
|
|
|
{
|
|
|
|
return server::errclear(remote);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-15 06:56:28 +02:00
|
|
|
/// avail() reports that a remote server is resolved and ready to take
|
|
|
|
/// requests; a network connection is just not established.
|
2020-04-26 04:40:46 +02:00
|
|
|
bool
|
2020-10-15 06:56:28 +02:00
|
|
|
ircd::m::fed::avail(const string_view &name)
|
2020-04-26 04:40:46 +02:00
|
|
|
{
|
2020-10-15 06:56:28 +02:00
|
|
|
well_known::opts opts;
|
|
|
|
opts.request = false;
|
|
|
|
opts.expired = true;
|
|
|
|
return with_server(name, opts, []
|
2020-04-26 04:40:46 +02:00
|
|
|
(const auto &remote)
|
|
|
|
{
|
|
|
|
return server::avail(remote);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-15 06:56:28 +02:00
|
|
|
/// linked() reports that we are actively and currently engaged with the remote
|
|
|
|
/// server over the network; requests are likely to succeed.
|
2020-04-26 04:40:46 +02:00
|
|
|
bool
|
2020-10-15 06:56:28 +02:00
|
|
|
ircd::m::fed::linked(const string_view &name)
|
2020-04-26 04:40:46 +02:00
|
|
|
{
|
2020-10-15 06:56:28 +02:00
|
|
|
well_known::opts opts;
|
|
|
|
opts.request = false;
|
|
|
|
opts.expired = true;
|
|
|
|
return with_server(name, opts, []
|
2020-04-26 04:40:46 +02:00
|
|
|
(const auto &remote)
|
|
|
|
{
|
2020-10-15 06:56:28 +02:00
|
|
|
return server::linked(remote);
|
2020-04-26 04:40:46 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-15 06:56:28 +02:00
|
|
|
/// errant() reports that contacting the remote server is known to not work.
|
|
|
|
/// False during nominal operation, including before any contact has been
|
|
|
|
/// attempted or after all cached errors have expired.
|
2020-04-26 04:40:46 +02:00
|
|
|
bool
|
2020-10-15 06:56:28 +02:00
|
|
|
ircd::m::fed::errant(const string_view &name)
|
2020-04-26 04:40:46 +02:00
|
|
|
{
|
2020-10-15 06:56:28 +02:00
|
|
|
well_known::opts opts;
|
|
|
|
opts.request = false;
|
|
|
|
opts.expired = true;
|
|
|
|
return with_server(name, opts, []
|
2020-04-26 04:40:46 +02:00
|
|
|
(const auto &remote)
|
|
|
|
{
|
2020-10-15 06:56:28 +02:00
|
|
|
return server::errant(remote);
|
2020-04-26 04:40:46 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-15 06:56:28 +02:00
|
|
|
/// exists() reports that contact has been made with the remote server. This
|
|
|
|
/// does not indicate success or failure for prior or active engagements.
|
2020-04-26 04:40:46 +02:00
|
|
|
bool
|
2020-10-15 06:56:28 +02:00
|
|
|
ircd::m::fed::exists(const string_view &name)
|
2020-04-26 04:40:46 +02:00
|
|
|
{
|
2020-10-15 06:56:28 +02:00
|
|
|
well_known::opts opts;
|
|
|
|
opts.request = false;
|
|
|
|
opts.expired = true;
|
|
|
|
return with_server(name, opts, []
|
2020-04-26 04:40:46 +02:00
|
|
|
(const auto &remote)
|
|
|
|
{
|
2020-10-15 06:56:28 +02:00
|
|
|
return server::exists(remote);
|
2020-04-26 04:40:46 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-26 23:53:00 +02:00
|
|
|
ircd::string_view
|
2020-04-26 04:40:46 +02:00
|
|
|
ircd::m::fed::server(const mutable_buffer &buf,
|
2020-10-15 06:56:28 +02:00
|
|
|
const string_view &name,
|
2020-10-14 15:59:30 +02:00
|
|
|
const well_known::opts &opts)
|
2020-04-26 04:40:46 +02:00
|
|
|
{
|
|
|
|
net::hostport remote
|
|
|
|
{
|
2020-10-15 06:56:28 +02:00
|
|
|
name
|
2020-04-26 04:40:46 +02:00
|
|
|
};
|
|
|
|
|
2020-04-26 23:53:00 +02:00
|
|
|
string_view target
|
|
|
|
{
|
2020-10-15 10:33:14 +02:00
|
|
|
name
|
2020-04-26 23:53:00 +02:00
|
|
|
};
|
|
|
|
|
2020-10-15 10:33:14 +02:00
|
|
|
if(!port(remote))
|
|
|
|
target = string_view
|
|
|
|
{
|
|
|
|
well_known::get(buf, host(remote), opts)
|
|
|
|
};
|
|
|
|
|
2020-04-26 23:53:00 +02:00
|
|
|
remote = target;
|
|
|
|
if(!port(remote) && !service(remote))
|
|
|
|
{
|
|
|
|
service(remote) = m::canon_service;
|
|
|
|
target = net::canonize(buf, remote);
|
|
|
|
}
|
2020-04-26 04:40:46 +02:00
|
|
|
|
2020-04-26 23:53:00 +02:00
|
|
|
return target;
|
2020-04-26 04:40:46 +02:00
|
|
|
}
|