From 5a058be4ba14d8bc5cbee93753ae361b1afc62e2 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 19 May 2018 18:25:11 -0700 Subject: [PATCH] ircd::net: Use specific canon service/port variables. --- include/ircd/net/hostport.h | 16 ++++++++++------ ircd/net.cc | 14 +++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/ircd/net/hostport.h b/include/ircd/net/hostport.h index b6bf4f02f..d5da0be02 100644 --- a/include/ircd/net/hostport.h +++ b/include/ircd/net/hostport.h @@ -15,16 +15,20 @@ namespace ircd::net { struct hostport; + // abstraction bleed + extern const uint16_t canon_port; + extern const string_view canon_service; + const uint16_t &port(const hostport &); const string_view &host(const hostport &); const string_view &service(const hostport &); uint16_t &port(hostport &); string_view &host(hostport &); - string_view string(const mutable_buffer &out, const hostport &); - string_view canonize(const mutable_buffer &out, const hostport &, const uint16_t &port = 8448); - std::string canonize(const hostport &, const uint16_t &port = 8448); + + string_view canonize(const mutable_buffer &out, const hostport &, const uint16_t &port = canon_port); + std::string canonize(const hostport &, const uint16_t &port = canon_port); } namespace ircd @@ -49,12 +53,12 @@ namespace ircd struct ircd::net::hostport { string_view host {"0.0.0.0"}; - string_view service {"matrix"}; - uint16_t port {8448}; + string_view service {canon_service}; + uint16_t port {canon_port}; bool operator!() const; - hostport(const string_view &host, const string_view &service, const uint16_t &port = 8448); + hostport(const string_view &host, const string_view &service, const uint16_t &port = canon_port); hostport(const string_view &host, const uint16_t &port); hostport(const string_view &amalgam); hostport() = default; diff --git a/ircd/net.cc b/ircd/net.cc index 51f516ea6..efe9e0cb5 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -3644,6 +3644,18 @@ ircd::net::ipport::ipport(const boost::asio::ip::address &address, // net/hostport.h // +decltype(ircd::net::canon_port) +ircd::net::canon_port +{ + 8448 +}; + +decltype(ircd::net::canon_service) +ircd::net::canon_service +{ + "matrix" +}; + std::ostream & ircd::net::operator<<(std::ostream &s, const hostport &t) { @@ -3659,7 +3671,7 @@ ircd::net::canonize(const hostport &hp, { const size_t len { - size(host(hp)) + 6 // optimistic ':' + portnum + size(host(hp)) + 1 + 5 + 1 // optimistic ':' + portnum }; return ircd::string(len, [&hp, &port]