0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-28 23:08:20 +02:00

modules/m_room_server_acl: Optimize implementation IO.

This commit is contained in:
Jason Volk 2019-05-25 23:08:17 -07:00
parent efb80c51e5
commit 6baff99607
2 changed files with 44 additions and 21 deletions

View file

@ -37,10 +37,11 @@ struct ircd::m::room::server_acl
static conf::item<bool> enable_send; // request destination
m::room room;
json::object content;
event::idx event_idx {0};
mutable json::object content;
bool view(const view_closure &) const;
bool pass(const string_view &server) const;
public:
bool exists() const;

View file

@ -156,28 +156,21 @@ IRCD_MODULE_EXPORT
ircd::m::room::server_acl::operator()(const string_view &server)
const
{
// c2s 13.29.1 rules:
bool ret;
const auto closure{[this, &server, &ret]
(const json::object &content)
{
// Set the content reference here so only one actual IO is made to
// fetch the m.room.server_acl content for all queries.
const scope_restore this_content
{
this->content, content
};
// 1. If there is no m.room.server_acl event in the room state, allow.
if(!exists())
return true;
ret = this->pass(server);
}};
// 2. If the server name is an IP address (v4 or v6) literal, and
// allow_ip_literals is present and false, deny.
if(getbool("allow_ip_literals") == false)
if(rfc3986::valid(std::nothrow, rfc3986::parser::ip_remote, server))
return false;
// 3. If the server name matches an entry in the deny list, deny.
if(match("deny", server))
return false;
// 4. If the server name matches an entry in the allow list, allow.
if(match("allow", server))
return true;
// 5. Otherwise, deny.
return false;
return !view(closure) || ret;
}
bool
@ -306,6 +299,35 @@ const
return content || event_idx;
}
bool
IRCD_MODULE_EXPORT
ircd::m::room::server_acl::pass(const string_view &server)
const
{
// c2s 13.29.1 rules
// 1. If there is no m.room.server_acl event in the room state, allow.
if(!exists())
return true;
// 2. If the server name is an IP address (v4 or v6) literal, and
// allow_ip_literals is present and false, deny.
if(getbool("allow_ip_literals") == false)
if(rfc3986::valid(std::nothrow, rfc3986::parser::ip_remote, server))
return false;
// 3. If the server name matches an entry in the deny list, deny.
if(match("deny", server))
return false;
// 4. If the server name matches an entry in the allow list, allow.
if(match("allow", server))
return true;
// 5. Otherwise, deny.
return false;
}
bool
IRCD_MODULE_EXPORT
ircd::m::room::server_acl::view(const view_closure &closure)