mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
ircd::net: Eliminate the legacy canon_port/canon_service defaults.
ircd:Ⓜ️ Move canon_port/canon_service into matrix lib.
This commit is contained in:
parent
bb8e40debc
commit
a46bf7dcbe
7 changed files with 51 additions and 56 deletions
|
@ -39,6 +39,9 @@ namespace ircd::m
|
|||
|
||||
IRCD_OVERLOAD(generate)
|
||||
|
||||
extern const uint16_t canon_port;
|
||||
extern const string_view canon_service;
|
||||
|
||||
extern struct log::log log;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,11 +25,10 @@ namespace ircd::net
|
|||
|
||||
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 = canon_port);
|
||||
std::string canonize(const hostport &, const uint16_t &port = canon_port);
|
||||
|
||||
string_view canonize(const mutable_buffer &out, const hostport &, const uint16_t &port = 0);
|
||||
std::string canonize(const hostport &, const uint16_t &port = 0);
|
||||
std::ostream &operator<<(std::ostream &, const hostport &);
|
||||
}
|
||||
|
||||
|
@ -56,14 +55,14 @@ struct ircd::net::hostport
|
|||
{
|
||||
IRCD_OVERLOAD(verbatim)
|
||||
|
||||
string_view host {"0.0.0.0"};
|
||||
string_view service {canon_service};
|
||||
uint16_t port {canon_port};
|
||||
string_view host;
|
||||
string_view service;
|
||||
uint16_t port {0};
|
||||
|
||||
explicit operator bool() const;
|
||||
bool operator!() const;
|
||||
|
||||
hostport(const string_view &host, const string_view &service, const uint16_t &port = canon_port);
|
||||
hostport(const string_view &host, const string_view &service, const uint16_t &port);
|
||||
hostport(const string_view &host, const uint16_t &port);
|
||||
hostport(const string_view &amalgam);
|
||||
hostport(const string_view &amalgam, verbatim_t);
|
||||
|
@ -72,16 +71,23 @@ struct ircd::net::hostport
|
|||
|
||||
/// Creates a host:service pair from a hostname and a service name string.
|
||||
/// When passed to net::dns() this will indicate SRV resolution. If no
|
||||
/// SRV record is found
|
||||
/// TODO: todo: the servce is translated into its proper port.
|
||||
/// TODO: now: the port 8448 is used with the hostname.
|
||||
/// SRV record is found.
|
||||
inline
|
||||
ircd::net::hostport::hostport(const string_view &host,
|
||||
const string_view &service,
|
||||
const uint16_t &port)
|
||||
:host{rfc3986::host(host)}
|
||||
,service{service}
|
||||
,port{port}
|
||||
:host
|
||||
{
|
||||
rfc3986::host(host)
|
||||
}
|
||||
,service
|
||||
{
|
||||
service
|
||||
}
|
||||
,port
|
||||
{
|
||||
port
|
||||
}
|
||||
{}
|
||||
|
||||
/// Creates a host:port pair from a hostname and a port number. When
|
||||
|
@ -102,7 +108,7 @@ ircd::net::hostport::operator
|
|||
bool()
|
||||
const
|
||||
{
|
||||
return net::host(*this) != net::host(hostport{});
|
||||
return bool(host);
|
||||
}
|
||||
|
||||
inline bool
|
||||
|
|
34
ircd/net.cc
34
ircd/net.cc
|
@ -4380,18 +4380,6 @@ const
|
|||
// net/hostport.h
|
||||
//
|
||||
|
||||
decltype(ircd::net::canon_port)
|
||||
ircd::net::canon_port
|
||||
{
|
||||
8448
|
||||
};
|
||||
|
||||
decltype(ircd::net::canon_service)
|
||||
ircd::net::canon_service
|
||||
{
|
||||
"matrix"
|
||||
};
|
||||
|
||||
/// Creates a host:service or host:port pair from the single string literally
|
||||
/// containing the colon deliminated values. If the suffix is a port number
|
||||
/// then the behavior for the port number constructor applies; if a service
|
||||
|
@ -4407,28 +4395,12 @@ ircd::net::hostport::hostport(const string_view &amalgam)
|
|||
rfc3986::port(amalgam)
|
||||
}
|
||||
{
|
||||
// When the amalgam has no port
|
||||
if(amalgam == host)
|
||||
{
|
||||
// set the port to the canon_port; port=0 is bad
|
||||
port = port?: canon_port;
|
||||
return;
|
||||
}
|
||||
|
||||
// or a valid integer port
|
||||
if(port)
|
||||
// When the amalgam has no port || a valid integer port
|
||||
if(amalgam == host || port)
|
||||
return;
|
||||
|
||||
// When the port is actually a service string
|
||||
const auto service
|
||||
{
|
||||
rsplit(amalgam, ':').second
|
||||
};
|
||||
|
||||
if(service)
|
||||
this->service = service;
|
||||
else
|
||||
this->port = canon_port;
|
||||
this->service = rsplit(amalgam, ':').second;
|
||||
}
|
||||
|
||||
ircd::net::hostport::hostport(const string_view &amalgam,
|
||||
|
|
|
@ -936,7 +936,9 @@ try
|
|||
|
||||
const auto &port
|
||||
{
|
||||
net::port(hp) != canon_port? net::port(hp) : uint16_t(53)
|
||||
net::port(hp)?
|
||||
net::port(hp):
|
||||
uint16_t(53)
|
||||
};
|
||||
|
||||
const ipport ipp
|
||||
|
|
|
@ -579,11 +579,11 @@ ircd::server::peer::peer(const net::hostport &hostport,
|
|||
}
|
||||
,service
|
||||
{
|
||||
// hostport arguments with a port of 0 or net::canon_port (8448) are
|
||||
// normal; if the port is such, and if we are supplied a service string
|
||||
// an SRV query will be performed. For other port numbers, we ignore any
|
||||
// service string and SRV won't be resolved.
|
||||
!net::port(hostport) || net::port(hostport) == net::canon_port?
|
||||
// hostport arguments with a port of 0 are normal; if the port is such,
|
||||
// and if we are supplied a service string an SRV query will be performed.
|
||||
// For other port numbers, we ignore any service string and SRV won't be
|
||||
// resolved.
|
||||
!net::port(hostport)?
|
||||
net::service(hostport):
|
||||
string_view{}
|
||||
}
|
||||
|
|
|
@ -949,7 +949,7 @@ ircd::m::self::my_host(const string_view &name)
|
|||
bool
|
||||
ircd::m::self::host(const string_view &other)
|
||||
{
|
||||
assert(net::canon_port == 8448);
|
||||
assert(m::canon_port == 8448);
|
||||
const net::hostport other_host{other};
|
||||
for(const auto &[my_network, hs_p] : homeserver::map)
|
||||
if(match(my_network, other))
|
||||
|
@ -966,17 +966,17 @@ noexcept
|
|||
// port() is 0 when the origin has no port (and implies 8448)
|
||||
const auto my_port
|
||||
{
|
||||
port(a)?: 8448
|
||||
port(a)?: m::canon_port
|
||||
};
|
||||
|
||||
// If my_host has a non-canonical port number, then the argument must
|
||||
// also have the same port number, or there is no possible match.
|
||||
if(my_port != net::canon_port)
|
||||
if(my_port != m::canon_port)
|
||||
return my_port == port(b) && host(a) == host(b);
|
||||
|
||||
// Since my host is on the canonical port, if other host has some
|
||||
// different port number, there is no possible match.
|
||||
if(port(b) != net::canon_port)
|
||||
if(port(b) != m::canon_port)
|
||||
return false;
|
||||
|
||||
// Both myself and input are using 8448; now the name has to match.
|
||||
|
|
|
@ -27,6 +27,18 @@ ircd::m::log
|
|||
"m", 'm'
|
||||
};
|
||||
|
||||
decltype(ircd::m::canon_port)
|
||||
ircd::m::canon_port
|
||||
{
|
||||
8448
|
||||
};
|
||||
|
||||
decltype(ircd::m::canon_service)
|
||||
ircd::m::canon_service
|
||||
{
|
||||
"matrix"
|
||||
};
|
||||
|
||||
/// This is an ordered list for loading and unloading modules. This is not the
|
||||
/// solution I really want at all so consider it temporary. Modules are loaded
|
||||
/// in the order of the lines and unloaded in reverse order.
|
||||
|
|
Loading…
Reference in a new issue