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

ircd:Ⓜ️:room::origins: Add interface to count room servers online/error.

This commit is contained in:
Jason Volk 2019-07-21 19:06:43 -07:00
parent 4178f40ee1
commit b17b508c2a
2 changed files with 33 additions and 0 deletions

View file

@ -29,6 +29,8 @@ struct ircd::m::room::origins
void for_each(const closure &view) const;
bool has(const string_view &origin) const;
bool only(const string_view &origin) const;
size_t count_online() const;
size_t count_error() const;
size_t count() const;
// select an origin in the room at random; use proffer to refuse and try another.

View file

@ -3535,6 +3535,37 @@ const
return ret;
}
size_t
ircd::m::room::origins::count_error()
const
{
size_t ret{0};
for_each([&ret](const string_view &server)
{
ret += !empty(server::errmsg(server));
});
return ret;
}
size_t
ircd::m::room::origins::count_online()
const
{
ssize_t ret
{
0 - ssize_t(count_error())
};
for_each([&ret](const string_view &hostport)
{
ret += bool(server::exists(hostport));
});
assert(ret >= 0L);
return std::max(ret, 0L);
}
/// Tests if argument is the only origin in the room.
/// If a zero or more than one origins exist, returns false. If the only origin
/// in the room is the argument origin, returns true.