0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

ircd:Ⓜ️:fed: Add rooms::complexity request w/ console cmd.

This commit is contained in:
Jason Volk 2020-04-05 18:35:48 -07:00
parent ffdf1632f5
commit 5fe4d8c4ad
4 changed files with 118 additions and 0 deletions

View file

@ -40,6 +40,7 @@ namespace ircd::m::fed
#include "backfill.h"
#include "frontfill.h"
#include "public_rooms.h"
#include "rooms.h"
#include "send.h"
#include "groups.h"

View file

@ -0,0 +1,35 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_M_FED_ROOMS_H
namespace ircd::m::fed::rooms
{
struct complexity;
};
struct ircd::m::fed::rooms::complexity
:request
{
explicit operator json::object() const
{
return json::object
{
in.content
};
}
complexity(const m::id::room &room_id,
const mutable_buffer &,
opts);
complexity() = default;
};

View file

@ -134,6 +134,43 @@ ircd::m::fed::send::send(const string_view &txnid,
{
}
///////////////////////////////////////////////////////////////////////////////
//
// 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)
};
}()}
{
}
///////////////////////////////////////////////////////////////////////////////
//
// fed/public_rooms.h

View file

@ -12988,6 +12988,51 @@ console_cmd__fed__groups(opt &out, const string_view &line)
return true;
}
bool
console_cmd__fed__rooms__complexity(opt &out, const string_view &line)
{
const params param{line, " ",
{
"room_id", "remote"
}};
const auto room_id
{
m::room_id(param.at("room_id"))
};
const auto remote
{
param["remote"]
};
const unique_buffer<mutable_buffer> buf
{
16_KiB
};
m::fed::rooms::complexity::opts opts;
opts.remote = remote;
opts.dynamic = false;
m::fed::rooms::complexity request
{
room_id, buf, std::move(opts)
};
const auto code
{
request.get(out.timeout)
};
const json::object response
{
request
};
out << string_view{response} << std::endl;
return true;
}
bool
console_cmd__fed__head(opt &out, const string_view &line)
{