0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd::client: Simplify instance_multimap related; keep state for local/remote addrs in client.

This commit is contained in:
Jason Volk 2018-09-29 16:51:11 -07:00
parent a220891800
commit 0c25852109
2 changed files with 19 additions and 21 deletions

View file

@ -23,7 +23,7 @@ namespace ircd
/// Remote party connecting to our daemon to make requests.
struct ircd::client
:std::enable_shared_from_this<client>
,ircd::instance_multimap<net::ipport, client>
,ircd::instance_multimap<net::ipport, client, net::ipport::cmp_ip>
{
struct init;
struct conf;
@ -37,7 +37,7 @@ struct ircd::client
static uint64_t ctr; // monotonic
static void create(const std::shared_ptr<socket> &);
static size_t count(net::ipport remote);
static size_t count(const net::ipport &remote); // cmp is by IP only, not port
static void terminate_all();
static void interrupt_all();
static void close_all();
@ -48,6 +48,7 @@ struct ircd::client
unique_buffer<mutable_buffer> head_buffer;
unique_buffer<mutable_buffer> content_buffer;
std::shared_ptr<socket> sock;
net::ipport local;
uint64_t id {++ctr};
ctx::ctx *reqctx {nullptr};
ircd::timer timer;
@ -73,8 +74,8 @@ struct ircd::client
client &operator=(const client &) = delete;
~client() noexcept;
friend ipport remote(const client &);
friend ipport local(const client &);
friend const ipport &remote(const client &);
friend const ipport &local(const client &);
};
/// Confs can be attached to individual clients to change their behavior

View file

@ -107,8 +107,8 @@ ircd::client::ctr
// Linkage for the container of all active clients for iteration purposes.
template<>
decltype(ircd::util::instance_multimap<ircd::net::ipport, ircd::client>::map)
ircd::util::instance_multimap<ircd::net::ipport, ircd::client>::map
decltype(ircd::util::instance_multimap<ircd::net::ipport, ircd::client, ircd::net::ipport::cmp_ip>::map)
ircd::util::instance_multimap<ircd::net::ipport, ircd::client, ircd::net::ipport::cmp_ip>::map
{};
//
@ -252,9 +252,8 @@ ircd::client::create(const std::shared_ptr<socket> &sock)
}
size_t
ircd::client::count(net::ipport remote)
ircd::client::count(const net::ipport &remote)
{
std::get<remote.PORT>(remote) = 0;
return client::map.count(remote);
}
@ -289,22 +288,16 @@ ircd::read(client &client,
return base;
}
ircd::ipport
const ircd::ipport &
ircd::local(const client &client)
{
if(!client.sock)
return {};
return net::local_ipport(*client.sock);
return client.local;
}
ircd::ipport
const ircd::ipport &
ircd::remote(const client &client)
{
if(!client.sock)
return {};
return net::remote_ipport(*client.sock);
return client.it->first;
}
//
@ -594,7 +587,7 @@ ircd::client::client(std::shared_ptr<socket> sock)
{
assert(bool(sock));
const auto &ep(sock->remote());
return { ep.address(), 0 };
return { ep.address(), ep.port() };
}()}
,head_buffer
{
@ -604,6 +597,10 @@ ircd::client::client(std::shared_ptr<socket> sock)
{
std::move(sock)
}
,local
{
net::local_ipport(*this->sock)
}
{
assert(size(head_buffer) >= 8_KiB);
}
@ -991,8 +988,8 @@ const
{
buf, "client[%lu] local[%s] remote[%s] socket(%p)",
id,
string(locbuf, local(*this)),
string(rembuf, remote(*this)),
string(locbuf, ircd::local(*this)),
string(rembuf, ircd::remote(*this)),
sock.get()
};
}