Rearrange sources (#4997)

This commit is contained in:
Pretty Printer
2024-06-20 09:22:15 -05:00
committed by John Freeman
parent 2e902dee53
commit e416ee72ca
994 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,117 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_NET_IPADDRESS_H_INCLUDED
#define BEAST_NET_IPADDRESS_H_INCLUDED
#include <ripple/beast/hash/hash_append.h>
#include <ripple/beast/hash/uhash.h>
#include <ripple/beast/net/IPAddressV4.h>
#include <ripple/beast/net/IPAddressV6.h>
#include <boost/asio/ip/address.hpp>
#include <boost/functional/hash.hpp>
#include <cassert>
#include <cstdint>
#include <ios>
#include <sstream>
#include <string>
#include <typeinfo>
//------------------------------------------------------------------------------
namespace beast {
namespace IP {
using Address = boost::asio::ip::address;
/** Returns the address represented as a string. */
inline std::string
to_string(Address const& addr)
{
return addr.to_string();
}
/** Returns `true` if this is a loopback address. */
inline bool
is_loopback(Address const& addr)
{
return addr.is_loopback();
}
/** Returns `true` if the address is unspecified. */
inline bool
is_unspecified(Address const& addr)
{
return addr.is_unspecified();
}
/** Returns `true` if the address is a multicast address. */
inline bool
is_multicast(Address const& addr)
{
return addr.is_multicast();
}
/** Returns `true` if the address is a private unroutable address. */
inline bool
is_private(Address const& addr)
{
return (addr.is_v4()) ? is_private(addr.to_v4()) : is_private(addr.to_v6());
}
/** Returns `true` if the address is a public routable address. */
inline bool
is_public(Address const& addr)
{
return (addr.is_v4()) ? is_public(addr.to_v4()) : is_public(addr.to_v6());
}
} // namespace IP
//------------------------------------------------------------------------------
template <class Hasher>
void
hash_append(Hasher& h, beast::IP::Address const& addr) noexcept
{
using beast::hash_append;
if (addr.is_v4())
hash_append(h, addr.to_v4().to_bytes());
else if (addr.is_v6())
hash_append(h, addr.to_v6().to_bytes());
else
assert(false);
}
} // namespace beast
namespace boost {
template <>
struct hash<::beast::IP::Address>
{
explicit hash() = default;
std::size_t
operator()(::beast::IP::Address const& addr) const
{
return ::beast::uhash<>{}(addr);
}
};
} // namespace boost
#endif

View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_NET_IPADDRESSCONVERSION_H_INCLUDED
#define BEAST_NET_IPADDRESSCONVERSION_H_INCLUDED
#include <ripple/beast/net/IPEndpoint.h>
#include <sstream>
#include <boost/asio.hpp>
namespace beast {
namespace IP {
/** Convert to Endpoint.
The port is set to zero.
*/
Endpoint
from_asio(boost::asio::ip::address const& address);
/** Convert to Endpoint. */
Endpoint
from_asio(boost::asio::ip::tcp::endpoint const& endpoint);
/** Convert to asio::ip::address.
The port is ignored.
*/
boost::asio::ip::address
to_asio_address(Endpoint const& endpoint);
/** Convert to asio::ip::tcp::endpoint. */
boost::asio::ip::tcp::endpoint
to_asio_endpoint(Endpoint const& endpoint);
} // namespace IP
} // namespace beast
namespace beast {
// DEPRECATED
struct IPAddressConversion
{
explicit IPAddressConversion() = default;
static IP::Endpoint
from_asio(boost::asio::ip::address const& address)
{
return IP::from_asio(address);
}
static IP::Endpoint
from_asio(boost::asio::ip::tcp::endpoint const& endpoint)
{
return IP::from_asio(endpoint);
}
static boost::asio::ip::address
to_asio_address(IP::Endpoint const& address)
{
return IP::to_asio_address(address);
}
static boost::asio::ip::tcp::endpoint
to_asio_endpoint(IP::Endpoint const& address)
{
return IP::to_asio_endpoint(address);
}
};
} // namespace beast
#endif

View File

@@ -0,0 +1,53 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_NET_IPADDRESSV4_H_INCLUDED
#define BEAST_NET_IPADDRESSV4_H_INCLUDED
#include <ripple/beast/hash/hash_append.h>
#include <boost/asio/ip/address_v4.hpp>
#include <cstdint>
#include <functional>
#include <ios>
#include <string>
#include <utility>
namespace beast {
namespace IP {
using AddressV4 = boost::asio::ip::address_v4;
/** Returns `true` if the address is a private unroutable address. */
bool
is_private(AddressV4 const& addr);
/** Returns `true` if the address is a public routable address. */
bool
is_public(AddressV4 const& addr);
/** Returns the address class for the given address.
@note Class 'D' represents multicast addresses (224.*.*.*).
*/
char
get_class(AddressV4 const& address);
} // namespace IP
} // namespace beast
#endif

View File

@@ -0,0 +1,47 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_NET_IPADDRESSV6_H_INCLUDED
#define BEAST_NET_IPADDRESSV6_H_INCLUDED
#include <boost/asio/ip/address_v6.hpp>
#include <cassert>
#include <cstdint>
#include <functional>
#include <ios>
#include <string>
#include <utility>
namespace beast {
namespace IP {
using AddressV6 = boost::asio::ip::address_v6;
/** Returns `true` if the address is a private unroutable address. */
bool
is_private(AddressV6 const& addr);
/** Returns `true` if the address is a public routable address. */
bool
is_public(AddressV6 const& addr);
} // namespace IP
} // namespace beast
#endif

View File

@@ -0,0 +1,243 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_NET_IPENDPOINT_H_INCLUDED
#define BEAST_NET_IPENDPOINT_H_INCLUDED
#include <ripple/beast/hash/hash_append.h>
#include <ripple/beast/hash/uhash.h>
#include <ripple/beast/net/IPAddress.h>
#include <cstdint>
#include <ios>
#include <optional>
#include <string>
namespace beast {
namespace IP {
using Port = std::uint16_t;
/** A version-independent IP address and port combination. */
class Endpoint
{
public:
/** Create an unspecified endpoint. */
Endpoint();
/** Create an endpoint from the address and optional port. */
explicit Endpoint(Address const& addr, Port port = 0);
/** Create an Endpoint from a string.
If the port is omitted, the endpoint will have a zero port.
@return An optional endpoint; will be `std::nullopt` on failure
*/
static std::optional<Endpoint>
from_string_checked(std::string const& s);
static Endpoint
from_string(std::string const& s);
/** Returns a string representing the endpoint. */
std::string
to_string() const;
/** Returns the port number on the endpoint. */
Port
port() const
{
return m_port;
}
/** Returns a new Endpoint with a different port. */
Endpoint
at_port(Port port) const
{
return Endpoint(m_addr, port);
}
/** Returns the address portion of this endpoint. */
Address const&
address() const
{
return m_addr;
}
/** Convenience accessors for the address part. */
/** @{ */
bool
is_v4() const
{
return m_addr.is_v4();
}
bool
is_v6() const
{
return m_addr.is_v6();
}
AddressV4 const
to_v4() const
{
return m_addr.to_v4();
}
AddressV6 const
to_v6() const
{
return m_addr.to_v6();
}
/** @} */
/** Arithmetic comparison. */
/** @{ */
friend bool
operator==(Endpoint const& lhs, Endpoint const& rhs);
friend bool
operator<(Endpoint const& lhs, Endpoint const& rhs);
friend bool
operator!=(Endpoint const& lhs, Endpoint const& rhs)
{
return !(lhs == rhs);
}
friend bool
operator>(Endpoint const& lhs, Endpoint const& rhs)
{
return rhs < lhs;
}
friend bool
operator<=(Endpoint const& lhs, Endpoint const& rhs)
{
return !(lhs > rhs);
}
friend bool
operator>=(Endpoint const& lhs, Endpoint const& rhs)
{
return !(rhs > lhs);
}
/** @} */
template <class Hasher>
friend void
hash_append(Hasher& h, Endpoint const& endpoint)
{
using ::beast::hash_append;
hash_append(h, endpoint.m_addr, endpoint.m_port);
}
private:
Address m_addr;
Port m_port;
};
//------------------------------------------------------------------------------
// Properties
/** Returns `true` if the endpoint is a loopback address. */
inline bool
is_loopback(Endpoint const& endpoint)
{
return is_loopback(endpoint.address());
}
/** Returns `true` if the endpoint is unspecified. */
inline bool
is_unspecified(Endpoint const& endpoint)
{
return is_unspecified(endpoint.address());
}
/** Returns `true` if the endpoint is a multicast address. */
inline bool
is_multicast(Endpoint const& endpoint)
{
return is_multicast(endpoint.address());
}
/** Returns `true` if the endpoint is a private unroutable address. */
inline bool
is_private(Endpoint const& endpoint)
{
return is_private(endpoint.address());
}
/** Returns `true` if the endpoint is a public routable address. */
inline bool
is_public(Endpoint const& endpoint)
{
return is_public(endpoint.address());
}
//------------------------------------------------------------------------------
/** Returns the endpoint represented as a string. */
inline std::string
to_string(Endpoint const& endpoint)
{
return endpoint.to_string();
}
/** Output stream conversion. */
template <typename OutputStream>
OutputStream&
operator<<(OutputStream& os, Endpoint const& endpoint)
{
os << to_string(endpoint);
return os;
}
/** Input stream conversion. */
std::istream&
operator>>(std::istream& is, Endpoint& endpoint);
} // namespace IP
} // namespace beast
//------------------------------------------------------------------------------
namespace std {
/** std::hash support. */
template <>
struct hash<::beast::IP::Endpoint>
{
explicit hash() = default;
std::size_t
operator()(::beast::IP::Endpoint const& endpoint) const
{
return ::beast::uhash<>{}(endpoint);
}
};
} // namespace std
namespace boost {
/** boost::hash support. */
template <>
struct hash<::beast::IP::Endpoint>
{
explicit hash() = default;
std::size_t
operator()(::beast::IP::Endpoint const& endpoint) const
{
return ::beast::uhash<>{}(endpoint);
}
};
} // namespace boost
#endif