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.
|
|
|
|
|
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-03-08 02:15:58 +01: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
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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))))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
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);
|
|
|
|
|
|
|
|
if(opts.since)
|
|
|
|
qss << "&since="
|
2018-12-07 01:41:47 +01:00
|
|
|
<< url::encode(since, opts.since);
|
2018-04-08 22:27:18 +02:00
|
|
|
|
|
|
|
if(opts.third_party_instance_id)
|
|
|
|
qss << "&third_party_instance_id="
|
2018-12-07 01:41:47 +01:00
|
|
|
<< 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,
|
|
|
|
opts.include_all_networks? "&include_all_networks=true" : "",
|
|
|
|
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-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-03-08 02:15:58 +01:00
|
|
|
window_buffer buf{buf_};
|
|
|
|
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-03-08 02:15:58 +01: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
|
|
|
{
|
|
|
|
buf([&pair, &opts](const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
return make_content(buf, pair, opts);
|
|
|
|
});
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
json::get<"content"_>(opts.request) = json::object
|
|
|
|
{
|
|
|
|
buf.completed()
|
|
|
|
};
|
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};
|
|
|
|
{
|
|
|
|
json::stack::member earliest{top, "earliest_events"};
|
|
|
|
json::stack::array array{earliest};
|
|
|
|
for(const auto &id : pair.first)
|
|
|
|
array.append(id);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
json::stack::member latest{top, "latest_events"};
|
|
|
|
json::stack::array array{latest};
|
|
|
|
for(const auto &id : pair.second)
|
|
|
|
array.append(id);
|
|
|
|
}
|
|
|
|
json::stack::member{top, "limit", json::value(int64_t(opts.limit))};
|
|
|
|
json::stack::member{top, "min_depth", json::value(int64_t(opts.min_depth))};
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2018-04-06 11:30:26 +02:00
|
|
|
event_id_buf = fetch_head(room_id, opts.remote);
|
|
|
|
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
|
|
|
{
|
2020-03-08 02:15:58 +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
|
|
|
{
|
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)
|
|
|
|
{
|
2018-04-06 11:30:26 +02:00
|
|
|
event_id_buf = fetch_head(room_id, opts.remote);
|
|
|
|
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
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/federation/v1/%s/%s/?event_id=%s%s",
|
2018-04-03 02:38:35 +02:00
|
|
|
opts.ids_only? "state_ids" : "state",
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(ridbuf, room_id),
|
|
|
|
url::encode(eidbuf, opts.event_id),
|
2019-04-25 02:23:28 +02:00
|
|
|
opts.ids_only? "&auth_chain_ids=0"_sv : ""_sv,
|
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
|
|
|
|
{
|
2020-03-08 02:15:58 +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-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/federation/v1/event_auth/%s/%s",
|
2019-04-25 02:23:28 +02:00
|
|
|
url::encode(ridbuf, room_id),
|
|
|
|
url::encode(eidbuf, event_id),
|
|
|
|
};
|
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
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2020-03-08 02:15:58 +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
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/federation/v1/send_join/%s/%s",
|
2018-12-07 01:41:47 +01:00
|
|
|
url::encode(ridbuf, room_id),
|
|
|
|
url::encode(uidbuf, event_id)
|
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
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/federation/v1/make_join/%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"
|
2020-03-19 07:00:32 +01:00
|
|
|
"&ver=org.matrix.msc2432"
|
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
|
|
|
|
{
|
2020-03-08 02:15:58 +01:00
|
|
|
buf, "/_matrix/key/v2/server/%s/",
|
|
|
|
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
|
|
|
}
|
|
|
|
else json::get<"uri"_>(opts.request) = "/_matrix/key/v2/server/";
|
|
|
|
}
|
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).
|
|
|
|
const string_view remote
|
|
|
|
{
|
|
|
|
// We don't query for well-known if the origin has an explicit port.
|
|
|
|
!port(net::hostport(opts.remote))?
|
|
|
|
well_known(buf_, opts.remote):
|
|
|
|
opts.remote
|
|
|
|
};
|
|
|
|
|
|
|
|
// Devote the remaining buffer for HTTP as otherwise intended.
|
|
|
|
const mutable_buffer buf
|
|
|
|
{
|
|
|
|
buf_ + size(remote)
|
|
|
|
};
|
|
|
|
|
2020-03-08 02:15:58 +01:00
|
|
|
// Generate the request head including the X-Matrix into buffer.
|
2020-03-08 04:01:59 +01:00
|
|
|
opts.out.head = opts.request(buf,
|
|
|
|
{
|
|
|
|
// Note that we override the HTTP Host header with the well-known
|
|
|
|
// remote; otherwise default is the destination above which may differ.
|
|
|
|
{ "Host", remote }
|
|
|
|
});
|
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-03-08 04:01:59 +01:00
|
|
|
matrix_service(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-03-08 04:01:59 +01:00
|
|
|
//
|
|
|
|
// fetch_head util
|
|
|
|
//
|
|
|
|
|
2018-04-10 22:20:31 +02:00
|
|
|
ircd::conf::item<ircd::milliseconds>
|
|
|
|
fetch_head_timeout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.v1.fetch_head.timeout" },
|
|
|
|
{ "default", 30 * 1000L },
|
|
|
|
};
|
|
|
|
|
2018-04-06 07:11:46 +02:00
|
|
|
ircd::m::event::id::buf
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::fetch_head(const id::room &room_id,
|
2020-03-08 02:09:09 +01:00
|
|
|
const string_view &remote)
|
2018-04-06 07:11:46 +02:00
|
|
|
{
|
2019-04-25 00:24:39 +02:00
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
// When no user_id is supplied and the room exists locally we attempt
|
|
|
|
// to find the user_id of one of our users with membership in the room.
|
|
|
|
// This satisfies synapse's requirements for whether we have access
|
|
|
|
// to the response. If user_id remains blank then make_join will later
|
|
|
|
// generate a random one from our host as well.
|
|
|
|
m::user::id::buf user_id
|
|
|
|
{
|
2019-08-14 10:01:46 +02:00
|
|
|
any_user(room, my_host(), "join")
|
2019-04-25 00:24:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Make another attempt to find an invited user because that carries some
|
|
|
|
// value (this query is not as fast as querying join memberships).
|
|
|
|
if(!user_id)
|
2019-08-14 10:01:46 +02:00
|
|
|
user_id = any_user(room, my_host(), "invite");
|
2019-04-25 00:24:39 +02:00
|
|
|
|
|
|
|
return fetch_head(room_id, remote, user_id);
|
2018-04-06 07:11:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::event::id::buf
|
2020-03-06 04:35:20 +01:00
|
|
|
ircd::m::fed::fetch_head(const id::room &room_id,
|
2020-03-08 02:09:09 +01:00
|
|
|
const string_view &remote,
|
2020-03-06 04:35:20 +01:00
|
|
|
const id::user &user_id)
|
2018-04-06 07:11:46 +02:00
|
|
|
{
|
|
|
|
const unique_buffer<mutable_buffer> buf
|
|
|
|
{
|
2020-03-08 04:36:06 +01:00
|
|
|
32_KiB
|
2018-04-06 07:11:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
make_join::opts opts;
|
|
|
|
opts.remote = remote;
|
2020-03-08 04:36:06 +01:00
|
|
|
opts.dynamic = false;
|
2018-04-06 07:11:46 +02:00
|
|
|
make_join request
|
|
|
|
{
|
2019-04-25 00:24:39 +02:00
|
|
|
room_id, user_id, buf, std::move(opts)
|
2018-04-06 07:11:46 +02:00
|
|
|
};
|
|
|
|
|
2018-04-10 22:20:31 +02:00
|
|
|
request.wait(milliseconds(fetch_head_timeout));
|
2018-04-06 07:11:46 +02:00
|
|
|
request.get();
|
|
|
|
|
|
|
|
const json::object proto
|
|
|
|
{
|
|
|
|
request.in.content
|
|
|
|
};
|
|
|
|
|
2019-01-13 01:32:17 +01:00
|
|
|
const json::object event
|
|
|
|
{
|
|
|
|
proto.at("event")
|
|
|
|
};
|
|
|
|
|
2019-07-10 16:38:19 +02:00
|
|
|
const m::event::prev prev
|
2018-04-06 07:11:46 +02:00
|
|
|
{
|
2019-07-10 16:38:19 +02:00
|
|
|
event
|
2018-04-06 07:11:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto &prev_event_id
|
|
|
|
{
|
2019-07-10 16:38:19 +02:00
|
|
|
prev.prev_event(0)
|
2018-04-06 07:11:46 +02:00
|
|
|
};
|
|
|
|
|
2019-07-10 16:38:19 +02:00
|
|
|
return prev_event_id;
|
2018-04-06 07:11:46 +02:00
|
|
|
}
|
2020-03-07 03:01:14 +01:00
|
|
|
|
2020-03-08 04:01:59 +01:00
|
|
|
//
|
|
|
|
// well-known matrix server
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::log::log
|
|
|
|
well_known_log
|
|
|
|
{
|
|
|
|
"m.well-known"
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::conf::item<ircd::seconds>
|
|
|
|
well_known_cache_default
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fed.well-known.cache.default" },
|
|
|
|
{ "default", 24 * 60 * 60L },
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::conf::item<ircd::seconds>
|
|
|
|
well_known_cache_error
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fed.well-known.cache.error" },
|
|
|
|
{ "default", 36 * 60 * 60L },
|
|
|
|
};
|
|
|
|
|
|
|
|
///NOTE: not yet used until HTTP cache headers in response are respected.
|
|
|
|
ircd::conf::item<ircd::seconds>
|
|
|
|
well_known_cache_max
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fed.well-known.cache.max" },
|
|
|
|
{ "default", 48 * 60 * 60L },
|
|
|
|
};
|
|
|
|
|
2020-03-12 02:47:17 +01:00
|
|
|
ircd::conf::item<ircd::seconds>
|
|
|
|
well_known_fetch_timeout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fed.well-known.fetch.timeout" },
|
|
|
|
{ "default", 8L },
|
|
|
|
};
|
|
|
|
|
2020-03-12 04:39:32 +01:00
|
|
|
ircd::conf::item<size_t>
|
|
|
|
well_known_fetch_redirects
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.fed.well-known.fetch.redirects" },
|
|
|
|
{ "default", 2L },
|
|
|
|
};
|
|
|
|
|
2020-03-08 04:01:59 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::m::fed::well_known(const mutable_buffer &buf,
|
|
|
|
const string_view &origin)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
static const string_view type
|
|
|
|
{
|
|
|
|
"well-known.matrix.server"
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room::id::buf room_id
|
|
|
|
{
|
|
|
|
"dns", m::my_host()
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::event::idx event_idx
|
|
|
|
{
|
|
|
|
room.get(std::nothrow, type, origin)
|
|
|
|
};
|
|
|
|
|
|
|
|
const milliseconds origin_server_ts
|
|
|
|
{
|
|
|
|
m::get<time_t>(std::nothrow, event_idx, "origin_server_ts", time_t(0))
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::object content
|
|
|
|
{
|
|
|
|
origin_server_ts > 0ms?
|
|
|
|
m::get(std::nothrow, event_idx, "content", buf):
|
|
|
|
const_buffer{}
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::string cached
|
|
|
|
{
|
2020-03-08 08:59:22 +01:00
|
|
|
content["m.server"]
|
2020-03-08 04:01:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const seconds ttl
|
|
|
|
{
|
|
|
|
content.get<time_t>("ttl", time_t(0))
|
|
|
|
};
|
|
|
|
|
|
|
|
const system_point expires
|
|
|
|
{
|
|
|
|
origin_server_ts + ttl
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool expired
|
|
|
|
{
|
|
|
|
ircd::now<system_point>() > expires
|
2020-03-08 08:59:22 +01:00
|
|
|
|| empty(cached)
|
2020-03-08 04:01:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Crucial value that will provide us with a return string for this
|
|
|
|
// function in any case. This is obtained by either using the value
|
|
|
|
// found in cache or making a network query for a new value. expired=true
|
|
|
|
// when a network query needs to be made, otherwise we can return the
|
|
|
|
// cached value. If the network query fails, this value is still defaulted
|
|
|
|
// as the origin string to return and we'll also cache that too.
|
|
|
|
assert(expired || !empty(cached));
|
|
|
|
const string_view delegated
|
|
|
|
{
|
|
|
|
expired?
|
|
|
|
fetch_well_known(buf, origin):
|
|
|
|
|
|
|
|
// Move the returned string to the front of the buffer; this overwrites
|
|
|
|
// other data fetched by the cache query to focus on just the result.
|
|
|
|
string_view
|
|
|
|
{
|
|
|
|
data(buf), move(buf, cached)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Branch on valid cache hit to return result.
|
|
|
|
if(!expired)
|
|
|
|
{
|
|
|
|
thread_local char tmbuf[48];
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
well_known_log, "%s found in cache delegated to %s event_idx:%u expires %s",
|
|
|
|
origin,
|
|
|
|
delegated,
|
|
|
|
event_idx,
|
|
|
|
timef(tmbuf, expires, localtime),
|
|
|
|
};
|
|
|
|
|
|
|
|
return delegated;
|
|
|
|
}
|
|
|
|
|
2020-03-09 17:09:36 +01:00
|
|
|
// Any time the well-known result is the same as the origin (that
|
|
|
|
// includes legitimate errors where fetch_well_known() returns the
|
|
|
|
// origin to default) we consider that an error and use the error
|
|
|
|
// TTL value. Sorry, no exponential backoff implemented yet.
|
|
|
|
const auto cache_ttl
|
|
|
|
{
|
|
|
|
origin == delegated?
|
|
|
|
seconds(well_known_cache_error).count():
|
|
|
|
seconds(well_known_cache_default).count()
|
2020-03-08 04:01:59 +01:00
|
|
|
};
|
|
|
|
|
2020-03-09 17:09:36 +01:00
|
|
|
// Write our record to the cache room; note that this doesn't really
|
2020-03-08 04:01:59 +01:00
|
|
|
// match the format of other DNS records in this room since it's a bit
|
|
|
|
// simpler, but we don't share the ircd.dns.rr type prefix anyway.
|
|
|
|
const auto cache_id
|
|
|
|
{
|
2020-03-09 17:09:36 +01:00
|
|
|
m::send(room, m::me(), type, origin, json::members
|
2020-03-08 04:01:59 +01:00
|
|
|
{
|
2020-03-09 17:09:36 +01:00
|
|
|
{ "ttl", cache_ttl },
|
|
|
|
{ "m.server", delegated },
|
2020-03-08 04:01:59 +01:00
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
well_known_log, "%s caching delegation to %s to cache in %s",
|
|
|
|
origin,
|
|
|
|
delegated,
|
|
|
|
string_view{cache_id},
|
|
|
|
};
|
|
|
|
|
|
|
|
return delegated;
|
|
|
|
}
|
|
|
|
catch(const ctx::interrupted &)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
well_known_log, "%s :%s",
|
|
|
|
origin,
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return origin;
|
|
|
|
}
|
|
|
|
|
2020-03-12 04:39:32 +01:00
|
|
|
namespace ircd::m::fed
|
|
|
|
{
|
|
|
|
static std::tuple<http::code, string_view, string_view>
|
|
|
|
fetch_well_known(const mutable_buffer &out,
|
|
|
|
const net::hostport &remote,
|
|
|
|
const string_view &url);
|
|
|
|
}
|
|
|
|
|
2020-03-07 21:53:33 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::m::fed::fetch_well_known(const mutable_buffer &buf,
|
|
|
|
const string_view &origin)
|
2020-03-07 03:01:14 +01:00
|
|
|
try
|
|
|
|
{
|
2020-03-12 04:39:32 +01:00
|
|
|
static const string_view path
|
|
|
|
{
|
|
|
|
"/.well-known/matrix/server"
|
|
|
|
};
|
|
|
|
|
|
|
|
rfc3986::uri uri;
|
|
|
|
uri.remote = origin;
|
|
|
|
uri.path = path;
|
|
|
|
json::object response;
|
|
|
|
unique_mutable_buffer carry;
|
|
|
|
for(size_t i(0); i < well_known_fetch_redirects; ++i)
|
|
|
|
{
|
|
|
|
const auto &[code, location, content]
|
|
|
|
{
|
|
|
|
fetch_well_known(buf, uri.remote, uri.path)
|
|
|
|
};
|
|
|
|
|
|
|
|
// Successful error; bail
|
|
|
|
if(code >= 400)
|
|
|
|
return origin;
|
|
|
|
|
|
|
|
// Successful result; response content handled after loop.
|
|
|
|
if(code < 300)
|
|
|
|
{
|
|
|
|
response = content;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-03-16 15:44:11 +01:00
|
|
|
// Indirection code, but no location response header
|
|
|
|
if(!location)
|
|
|
|
return origin;
|
|
|
|
|
2020-03-12 04:39:32 +01:00
|
|
|
// Redirection; carry over the new target by copying it because it's
|
|
|
|
// in the buffer which we'll be overwriting for the new request.
|
|
|
|
carry = unique_mutable_buffer{location};
|
|
|
|
uri = string_view{carry};
|
2020-03-16 15:44:11 +01:00
|
|
|
|
|
|
|
// Indirection code, bad location header.
|
|
|
|
if(!uri.path || !uri.remote)
|
|
|
|
return origin;
|
2020-03-12 04:39:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const json::string &m_server
|
2020-03-07 21:53:33 +01:00
|
|
|
{
|
2020-03-12 04:39:32 +01:00
|
|
|
response["m.server"]
|
2020-03-07 21:53:33 +01:00
|
|
|
};
|
|
|
|
|
2020-03-12 04:39:32 +01:00
|
|
|
// This construction validates we didn't get a junk string
|
|
|
|
volatile const net::hostport ret
|
|
|
|
{
|
|
|
|
m_server
|
|
|
|
};
|
|
|
|
|
|
|
|
thread_local char rembuf[rfc3986::DOMAIN_BUFSIZE * 2];
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
well_known_log, "%s query to %s found delegation to %s",
|
|
|
|
origin,
|
|
|
|
uri.remote,
|
|
|
|
m_server,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Move the returned string to the front of the buffer; this overwrites
|
|
|
|
// any other incoming content to focus on just the unquoted string.
|
|
|
|
return string_view
|
|
|
|
{
|
|
|
|
data(buf), move(buf, m_server)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const ctx::interrupted &)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
well_known_log, "%s in network query :%s",
|
|
|
|
origin,
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return a tuple of the HTTP code, any Location header, and the response
|
|
|
|
/// content. These values are unconditional if this function doesn't throw,
|
|
|
|
/// but if there's no Location header and/or content then those will be empty
|
|
|
|
/// string_view's. This function is intended to be run in a loop by the caller
|
|
|
|
/// to chase redirection. No HTTP codes will throw from here; server and
|
|
|
|
/// network errors (and others) will.
|
|
|
|
static std::tuple<ircd::http::code, ircd::string_view, ircd::string_view>
|
|
|
|
ircd::m::fed::fetch_well_known(const mutable_buffer &buf,
|
|
|
|
const net::hostport &remote,
|
|
|
|
const string_view &url)
|
|
|
|
{
|
|
|
|
// Hard target https service; do not inherit any matrix service from remote.
|
2020-03-07 21:53:33 +01:00
|
|
|
const net::hostport target
|
|
|
|
{
|
|
|
|
host(remote), "https", port(remote)
|
|
|
|
};
|
|
|
|
|
2020-03-08 04:01:59 +01:00
|
|
|
window_buffer wb{buf};
|
2020-03-07 03:01:14 +01:00
|
|
|
http::request
|
|
|
|
{
|
2020-03-12 04:39:32 +01:00
|
|
|
wb, host(target), "GET", url
|
2020-03-07 03:01:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const const_buffer out_head
|
|
|
|
{
|
|
|
|
wb.completed()
|
|
|
|
};
|
|
|
|
|
2020-03-08 04:01:59 +01:00
|
|
|
// Remaining space in buffer is used for received head; note that below
|
|
|
|
// we specify this same buffer for in.content, but that's a trick
|
|
|
|
// recognized by ircd::server to place received content directly after
|
|
|
|
// head in this buffer without any additional dynamic allocation.
|
2020-03-07 03:01:14 +01:00
|
|
|
const mutable_buffer in_head
|
|
|
|
{
|
|
|
|
buf + size(out_head)
|
|
|
|
};
|
|
|
|
|
|
|
|
server::request::opts opts;
|
2020-03-12 04:39:32 +01:00
|
|
|
opts.http_exceptions = false; // 3xx/4xx/5xx response won't throw.
|
2020-03-07 03:01:14 +01:00
|
|
|
server::request request
|
|
|
|
{
|
|
|
|
target,
|
|
|
|
{ out_head },
|
2020-03-08 04:01:59 +01:00
|
|
|
{ in_head, in_head },
|
2020-03-07 03:01:14 +01:00
|
|
|
&opts
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto code
|
|
|
|
{
|
2020-03-12 02:47:17 +01:00
|
|
|
request.get(seconds(well_known_fetch_timeout))
|
2020-03-07 03:01:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
thread_local char rembuf[rfc3986::DOMAIN_BUFSIZE * 2];
|
|
|
|
log::debug
|
|
|
|
{
|
2020-03-12 04:39:32 +01:00
|
|
|
well_known_log, "fetch from %s %s :%u %s",
|
2020-03-07 03:01:14 +01:00
|
|
|
string(rembuf, target),
|
2020-03-12 04:39:32 +01:00
|
|
|
url,
|
2020-03-07 03:01:14 +01:00
|
|
|
uint(code),
|
2020-03-12 04:39:32 +01:00
|
|
|
http::status(code)
|
2020-03-07 03:01:14 +01:00
|
|
|
};
|
|
|
|
|
2020-03-12 04:39:32 +01:00
|
|
|
const http::response::head head
|
2020-03-07 21:53:33 +01:00
|
|
|
{
|
2020-03-12 04:39:32 +01:00
|
|
|
request.in.gethead(request)
|
2020-03-07 21:53:33 +01:00
|
|
|
};
|
2020-03-12 04:39:32 +01:00
|
|
|
|
|
|
|
return
|
2020-03-07 03:01:14 +01:00
|
|
|
{
|
2020-03-12 04:39:32 +01:00
|
|
|
code,
|
|
|
|
head.location,
|
|
|
|
request.in.content,
|
2020-03-07 03:01:14 +01:00
|
|
|
};
|
|
|
|
}
|