26#include <boost/dynamic_bitset.hpp>
27#include <boost/utility.hpp>
28#include <boost/random.hpp>
93 private boost::noncopyable
173 static_assert((std::numeric_limits<flow_port_sans_overflow_t>::is_integer
174 == std::numeric_limits<flow_port_t>::is_integer)
175 && (std::numeric_limits<flow_port_sans_overflow_t>::is_signed
176 == std::numeric_limits<flow_port_t>::is_signed)
178 "flow_port_sans_overflow_t must be similar to flow_port_t but with larger max value.");
Convenience class that simply stores a Logger and/or Component passed into a constructor; and returns...
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
Internal net_flow class that maintains the available Flow-protocol port space, somewhat similarly to ...
static const size_t S_NUM_EPHEMERAL_PORTS
Total number of "ephemeral" ports (ones reserved at random with reserve_ephemeral_port()).
static const size_t S_MAX_RECENT_EPHEMERAL_PORTS
The maximum size of m_recent_ephemeral_ports.
flow_port_t reserve_port(flow_port_t port, Error_code *err_code)
Reserve the specified service port, or reserve_ephemeral_port() if the specified port is S_PORT_ANY.
Bit_set m_service_ports
Current service port set.
flow_port_t reserve_ephemeral_port(Error_code *err_code)
Reserve a randomly chosen available ephemeral port.
static const flow_port_t S_FIRST_SERVICE_PORT
The port number of the lowest service port.
boost::dynamic_bitset<> Bit_set
Short-hand for bit set of arbitary length, representing a port set (each bit is a port; 1 open,...
void return_port(flow_port_t port, Error_code *err_code)
Return a previously reserved port (of any type).
static const flow_port_t S_FIRST_EPHEMERAL_PORT
The port number of the lowest ephemeral port.
Bit_set m_ephemeral_and_recent_ephemeral_ports
Set representing the union of the set of current reserved ephemeral ports and the set of the last up-...
static bool is_service_port(flow_port_t port)
Returns true if and only if the given port is a service port (as opposed to ephemeral or S_PORT_ANY).
Port_space(log::Logger *logger)
Constructs the Port_space with all ports available.
size_t find_available_port_bit_idx(const Bit_set &ports)
Helper method that, given a reference to a bit set representing available ports (1 available,...
static const size_t S_NUM_SERVICE_PORTS
Total number of "service" ports (ones that can be reserved by number with reserve_port()).
std::queue< flow_port_t > m_recent_ephemeral_ports
A FIFO of recently used but currently available ephemeral ports.
Random_generator m_rnd_generator
Random number generator for picking ports.
Bit_set m_ephemeral_ports
Current ephemeral port set; indexing analogous to m_service_ports but starting at S_FIRST_EPHEMERAL_P...
static const size_t S_NUM_PORTS
Total number of ports in the port space, including S_PORT_ANY.
util::Rnd_gen_uniform_range_base::Random_generator Random_generator
Random number generator.
uint32_t flow_port_sans_overflow_t
A type same as flow_port_t but larger, useful when doing arithmetic that might hit overflow in corner...
Flow module containing the API and implementation of the Flow network protocol, a TCP-inspired stream...
uint16_t flow_port_t
Logical Flow port type (analogous to a UDP/TCP port in spirit but in no way relevant to UDP/TCP).
boost::system::error_code Error_code
Short-hand for a boost.system error code (which basically encapsulates an integer/enum error code and...