Flow 1.0.1
Flow project: Full implementation reference.
net_flow_fwd.hpp
Go to the documentation of this file.
1/* Flow
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
19#pragma once
20
21#include "flow/common.hpp"
22#include <ostream>
23
24namespace flow::net_flow
25{
26// Types.
27
28// Find doc headers near the bodies of these compound types.
29
30class Event_set;
31class Net_env_simulator;
32class Node;
33struct Node_options;
34class Peer_socket;
35struct Peer_socket_receive_stats;
36struct Peer_socket_info;
37struct Peer_socket_options;
38class Peer_socket_send_stats;
39struct Remote_endpoint;
40class Server_socket;
41
42/// Result of a send or receive operation, used at least in stat reporting.
44{
45 /// Bytes transferred equals bytes expected.
47 /// Bytes transferred less than bytes expected.
49 /// Error occurred -- probably no bytes transferred.
50 S_ERROR
51};
52
53/// Logical Flow port type (analogous to a UDP/TCP port in spirit but in no way relevant to UDP/TCP).
54using flow_port_t = uint16_t;
55
56// Constants.
57
58/**
59 * Special Flow port value used to indicate "invalid port" or "please pick a random available ephemeral
60 * port," depending on the context. This is spiritually equivalent to TCP's port 0.
61 */
62extern const flow_port_t S_PORT_ANY;
63
64// Free functions.
65
66/**
67 * Prints string representation of given socket to given standard `ostream` and returns the
68 * latter. The representation includes the local and remote endpoints and the hex pointer value.
69 *
70 * @relatesalso Peer_socket
71 *
72 * @note `shared_ptr` forwards `ostream` output to the underlying pointer type, so this will affect `Ptr`
73 * output as well.
74 * @param os
75 * Stream to print to.
76 * @param sock
77 * Object to serialize. May be null.
78 * @return `os`.
79 */
80std::ostream& operator<<(std::ostream& os, const Peer_socket* sock);
81
82/**
83 * Prints string representation of given socket to given standard `ostream` and returns the
84 * latter. The representation includes the local endpoint and the hex pointer value.
85 *
86 * @relatesalso Server_socket
87 *
88 * @note `shared_ptr` forwards `ostream` output to the underlying pointer type, so this will affect `Ptr`
89 * output as well.
90 * @param os
91 * Stream to print to.
92 * @param serv
93 * Object to serialize. May be null.
94 * @return `os`.
95 */
96std::ostream& operator<<(std::ostream& os, const Server_socket* serv);
97
98/**
99 * Prints string representation of the stats in the given stats object to the standard `ostream` and
100 * returns the latter. The representation is multi-line but ends in no newline.
101 *
102 * @relatesalso Peer_socket_receive_stats
103 *
104 * @param os
105 * Stream to which to print.
106 * @param stats
107 * Value to serialize.
108 * @return `os`.
109 */
110std::ostream& operator<<(std::ostream& os, const Peer_socket_receive_stats& stats);
111
112/**
113 * Prints string representation of the stats in the given stats object to the standard `ostream` and
114 * returns the latter. The representation is multi-line but ends in no newline.
115 *
116 * @relatesalso Peer_socket_send_stats
117 *
118 * @param os
119 * Stream to which to print.
120 * @param stats
121 * Value to serialize.
122 * @return `os`.
123 */
124std::ostream& operator<<(std::ostream& os, const Peer_socket_send_stats& stats);
125
126/**
127 * Prints string representation of the stats in the given stats object to the standard `ostream` and
128 * returns the latter. The representation is multi-line but ends in no newline.
129 *
130 * @relatesalso Peer_socket_info
131 *
132 * @param os
133 * Stream to which to print.
134 * @param stats
135 * Value to serialize.
136 * @return `os`.
137 */
138std::ostream& operator<<(std::ostream& os, const Peer_socket_info& stats);
139
140/**
141 * Prints the name of each option in the given Node_options, along with its
142 * current value, to the given `ostream`.
143 *
144 * @param os
145 * Stream to which to serialize.
146 * @param opts
147 * Object to serialize.
148 * @return `os`.
149 */
150std::ostream& operator<<(std::ostream& os, const Node_options& opts);
151
152/**
153 * Prints the name of each option in the given Peer_socket_options, along with its
154 * current value, to the given `ostream`.
155 *
156 * @param os
157 * Stream to which to serialize.
158 * @param opts
159 * Object to serialize.
160 * @return `os`.
161 */
162std::ostream& operator<<(std::ostream& os, const Peer_socket_options& opts);
163
164/**
165 * Prints string representation of the given Remote_endpoint to the given `ostream`.
166 *
167 * @relatesalso Remote_endpoint
168 *
169 * @param os
170 * Stream to which to write.
171 * @param endpoint
172 * Endpoint to serialize.
173 * @return `os`.
174 */
175std::ostream& operator<<(std::ostream& os, const Remote_endpoint& endpoint);
176
177/**
178 * Whether `lhs` is equal to `rhs`.
179 *
180 * @relatesalso Remote_endpoint
181 * @param lhs
182 * Object to compare.
183 * @param rhs
184 * Object to compare.
185 * @return See above.
186 */
187bool operator==(const Remote_endpoint& lhs, const Remote_endpoint& rhs);
188
189/**
190 * Free function that returns `remote_endpoint.hash()`; has to be a free function named `hash_value`
191 * for boost.hash to pick it up.
192 *
193 * @relatesalso Remote_endpoint
194 *
195 * @param remote_endpoint
196 * Object to hash.
197 * @return `remote_endpoint.hash()`.
198 */
199size_t hash_value(const Remote_endpoint& remote_endpoint);
200
201} // namespace flow::net_flow
202
203
204/**
205 * Contains classes that add boost.asio integration to the main Flow-protocol
206 * classes such as net_flow::Node and net_flow::Peer_socket,
207 * so that `net_flow` sockets can be easily used in boost.asio-driven event loops, e.g., ones also performing
208 * TCP networking and scheduling timers.
209 *
210 * @see Main class net_flow::asio::Node.
211 */
212namespace flow::net_flow::asio
213{
214// Types.
215
216// Find doc headers near the bodies of these compound types.
217
218class Node;
219class Peer_socket;
220class Server_socket;
221
222// Free functions.
223
224/**
225 * Prints string representation of given socket to given standard `ostream` and returns the
226 * latter. The representation includes the local and remote endpoints and the hex pointer value.
227 *
228 * @relatesalso Peer_socket
229 *
230 * @note `shared_ptr` forwards `ostream` output to the underlying pointer type, so this will affect `Ptr`
231 * output as well.
232 * @param os
233 * Stream to print to.
234 * @param sock
235 * Object to serialize. May be null.
236 * @return `os`.
237 */
238std::ostream& operator<<(std::ostream& os, const Peer_socket* sock);
239
240/**
241 * Prints string representation of given socket to given standard `ostream` and returns the
242 * latter. The representation includes the local and remote endpoints and the hex pointer value.
243 *
244 * @relatesalso Server_socket
245 *
246 * @note `shared_ptr` forwards `ostream` output to the underlying pointer type, so this will affect `Ptr`
247 * output as well.
248 * @param os
249 * Stream to print to.
250 * @param serv
251 * Object to serialize. May be null.
252 * @return `os`.
253 */
254std::ostream& operator<<(std::ostream& os, const Server_socket* serv);
255
256} // namespace flow::net_flow::asio
A data store that keeps stats about the outgoing direction of a Peer_socket connection to another Flo...
Definition: info.hpp:286
A peer (non-server) socket operating over the Flow network protocol, with optional stream-of-bytes an...
A server socket able to listen on a single Flow port for incoming connections and return peer sockets...
Contains classes that add boost.asio integration to the main Flow-protocol classes such as net_flow::...
Definition: node.cpp:25
std::ostream & operator<<(std::ostream &os, const Peer_socket *sock)
Prints string representation of given socket to given standard ostream and returns the latter.
Flow module containing the API and implementation of the Flow network protocol, a TCP-inspired stream...
Definition: node.cpp:25
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).
size_t hash_value(const Sequence_number &seq_num)
Free function that returns seq_num.hash(); has to be a free function named hash_value for boost....
Definition: seq_num.cpp:275
bool operator==(const Remote_endpoint &lhs, const Remote_endpoint &rhs)
Whether lhs is equal to rhs.
Definition: endpoint.cpp:60
const flow_port_t S_PORT_ANY
Special Flow port value used to indicate "invalid port" or "please pick a random available ephemeral ...
Definition: port_space.cpp:33
Xfer_op_result
Result of a send or receive operation, used at least in stat reporting.
@ S_FULLY_XFERRED
Bytes transferred equals bytes expected.
@ S_PARTIALLY_XFERRED
Bytes transferred less than bytes expected.
std::ostream & operator<<(std::ostream &os, const Congestion_control_selector::Strategy_choice &strategy_choice)
Serializes a Peer_socket_options::Congestion_control_strategy_choice enum to a standard ostream – the...
Definition: cong_ctl.cpp:146
A set of low-level options affecting a single Flow Node, including Peer_socket objects and other obje...
Definition: options.hpp:449
A data store that keeps stats about the a Peer_socket connection.
Definition: info.hpp:456
A set of low-level options affecting a single Peer_socket.
Definition: options.hpp:36
A data store that keeps stats about the incoming direction of a Peer_socket connection to another Flo...
Definition: info.hpp:54
Represents the remote endpoint of a Flow-protocol connection; identifies the UDP endpoint of the remo...
Definition: endpoint.hpp:93