rippled
Loading...
Searching...
No Matches
IPEndpointCommon.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2017 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/basics/random.h>
21#include <xrpl/beast/net/IPEndpoint.h>
22
23namespace beast {
24namespace IP {
25
26inline Endpoint
27randomEP(bool v4 = true)
28{
29 using namespace ripple;
30 auto dv4 = []() -> AddressV4::bytes_type {
31 return {
32 {static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
33 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
34 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
35 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX))}};
36 };
37 auto dv6 = []() -> AddressV6::bytes_type {
38 return {
39 {static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
40 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
41 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
42 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
43 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
44 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
45 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
46 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
47 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
48 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
49 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
50 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
51 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
52 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
53 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX)),
54 static_cast<std::uint8_t>(rand_int<int>(1, UINT8_MAX))}};
55 };
56 return Endpoint{
57 v4 ? Address{AddressV4{dv4()}} : Address{AddressV6{dv6()}},
58 rand_int<std::uint16_t>(1, UINT16_MAX)};
59}
60
61} // namespace IP
62} // namespace beast
A version-independent IP address and port combination.
Definition IPEndpoint.h:38
boost::asio::ip::address_v6 AddressV6
Definition IPAddressV6.h:30
Endpoint randomEP(bool v4=true)
boost::asio::ip::address_v4 AddressV4
Definition IPAddressV4.h:30
boost::asio::ip::address Address
Definition IPAddress.h:39
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25