Skip to content

Commit 1b16c59

Browse files
committed
documentation
1 parent 12c6746 commit 1b16c59

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

include/scl/net/tcp/config.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ struct ConnectionInfo {
5959
*
6060
* A NetworkConfig is needed whenever by network objects in order to establish
6161
* connections to other nodes.
62+
*
63+
* @see NetworkConfig::load
64+
* @see NetworkConfig::localhost
6265
*/
6366
class NetworkConfig {
6467
public:
@@ -76,7 +79,7 @@ class NetworkConfig {
7679
* 192.0.2.2, 5000
7780
* 192.0.2.3, 3000
7881
* $
79-
* \endcode{.unparsed}
82+
* \endcode
8083
*
8184
* The order in which parties information occurs will correspond to their
8285
* identifier in the NetworkConfig that will be created.
@@ -90,21 +93,44 @@ class NetworkConfig {
9093
* assert(me.hostname == "192.0.2.2");
9194
* assert(me.port == 5000);
9295
* @endcode
96+
*
97+
* Minor validation is performed on the file.
98+
*
99+
* @throws std::invalid_argument if \p my_id is too large.
100+
* @throws std::invalid_argument if \p filename contains an invalid row.
101+
* @throws std::invalid_argument if \p filename could not be opened.
93102
*/
94-
static NetworkConfig load(std::size_t id, const std::string& filename);
103+
static NetworkConfig load(std::size_t my_id, const std::string& filename);
95104

96105
/**
97106
* @brief Create a network config where all parties are running locally.
107+
*
108+
* Creates a network config of a specified size, where all parties have
109+
* addresses on this machine.
110+
*
111+
* @code
112+
* auto nc = NetworkConfig::localhost(3, 5, 5000);
113+
*
114+
* for (int i = 0; i < nc.networkSize(); i++) {
115+
* assert(nc.party(i).host == "127.0.0.1");
116+
* assert(nc.party(i).port == 5000 + i);
117+
* }
118+
* @endcode
119+
*
120+
* @throws std::invalid_argument if <code>my_id >= size</code>.
98121
*/
99-
static NetworkConfig localhost(std::size_t id,
122+
static NetworkConfig localhost(std::size_t my_id,
100123
std::size_t size,
101124
std::size_t port_base);
102125

103126
/**
104127
* @brief Create a network config where all parties are running locally.
128+
*
129+
* Like \ref NetworkConfig::localhost with \ref DEFAULT_LOCALHOST_PORT_OFFSET
130+
* as \p port_base.
105131
*/
106-
static NetworkConfig localhost(std::size_t id, std::size_t size) {
107-
return NetworkConfig::localhost(id, size, DEFAULT_LOCALHOST_PORT_OFFSET);
132+
static NetworkConfig localhost(std::size_t my_id, std::size_t size) {
133+
return NetworkConfig::localhost(my_id, size, DEFAULT_LOCALHOST_PORT_OFFSET);
108134
};
109135

110136
/**

src/scl/net/tcp/config.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <stdexcept>
2222
#include <string>
2323

24-
scl::NetworkConfig scl::NetworkConfig::load(std::size_t id,
24+
scl::NetworkConfig scl::NetworkConfig::load(std::size_t my_id,
2525
const std::string& filename) {
2626
std::ifstream file(filename);
2727

@@ -48,17 +48,17 @@ scl::NetworkConfig scl::NetworkConfig::load(std::size_t id,
4848
info.emplace_back(ConnectionInfo{i++, host, port});
4949
}
5050

51-
if (id >= info.size()) {
51+
if (my_id >= info.size()) {
5252
throw std::invalid_argument("invalid id");
5353
}
5454

55-
return NetworkConfig(id, info);
55+
return NetworkConfig(my_id, info);
5656
}
5757

58-
scl::NetworkConfig scl::NetworkConfig::localhost(std::size_t id,
58+
scl::NetworkConfig scl::NetworkConfig::localhost(std::size_t my_id,
5959
std::size_t size,
6060
std::size_t port_base) {
61-
if (id >= size) {
61+
if (my_id >= size) {
6262
throw std::invalid_argument("invalid id");
6363
}
6464

@@ -68,7 +68,7 @@ scl::NetworkConfig scl::NetworkConfig::localhost(std::size_t id,
6868
info.emplace_back(ConnectionInfo{i, "127.0.0.1", port});
6969
}
7070

71-
return NetworkConfig(id, info);
71+
return NetworkConfig(my_id, info);
7272
}
7373

7474
void scl::NetworkConfig::validate() {

0 commit comments

Comments
 (0)