0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 14:08:56 +02:00

ircd::net: Improve remote construction; hostport/ipport related.

This commit is contained in:
Jason Volk 2018-01-10 01:20:16 -08:00
parent b801993309
commit 76e16e4d80
4 changed files with 18 additions and 21 deletions

View file

@ -26,6 +26,8 @@ namespace ircd::net
{
struct hostport;
uint16_t port(const hostport &);
const auto &host(const hostport &);
auto &host(hostport &);
@ -83,3 +85,11 @@ ircd::net::host(const hostport &hp)
{
return hp.host;
}
inline uint16_t
ircd::net::port(const hostport &hp)
{
return hp.portnum? hp.portnum:
hp.port? lex_cast<uint16_t>(hp.port):
0;
}

View file

@ -96,6 +96,7 @@ ircd::net::ipport::ipport(const uint32_t &ip,
const uint16_t &p)
{
std::get<TYPE>(*this) = false;
host6(*this) = 0;
host4(*this) = ip;
port(*this) = p;
}

View file

@ -53,7 +53,11 @@ struct ircd::net::remote
:ipport{ipp}
{}
remote(const hostport &hp);
explicit remote(const hostport &hostport)
:ipport{uint32_t(0), net::port(hostport)}
,hostname{net::host(hostport)}
{}
remote() = default;
friend std::ostream &operator<<(std::ostream &, const remote &);

View file

@ -2254,22 +2254,6 @@ ircd::net::string(const mutable_buffer &buf,
}
}
//
// remote
//
ircd::net::remote::remote(const hostport &hostport)
:ipport
{
resolve(hostport)
}
,hostname
{
hostport.host
}
{
}
///////////////////////////////////////////////////////////////////////////////
//
// net/ipport.h
@ -2421,9 +2405,7 @@ ircd::net::string(const mutable_buffer &buf,
{
fmt::sprintf
{
buf, "%s:%s",
hp.host,
hp.portnum? lex_cast(hp.portnum) : hp.port
buf, "%s:%u", host(hp), port(hp)
}
};
@ -2444,7 +2426,7 @@ ircd::net::string(const ip::address &addr)
std::string
ircd::net::string(const ip::tcp::endpoint &ep)
{
std::string ret(256, char{});
std::string ret(128, char{});
const auto addr{string(net::addr(ep))};
const auto data{const_cast<char *>(ret.data())};
ret.resize(snprintf(data, ret.size(), "%s:%u", addr.c_str(), port(ep)));