GNUnet 0.22.2
testing_api_topology.c File Reference
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include "testing_api_topology.h"
#include "testing_cmds.h"
Include dependency graph for testing_api_topology.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
 
#define CONNECT_ADDRESS_TEMPLATE   "%s-192.168.15.%u"
 
#define ROUTER_CONNECT_ADDRESS_TEMPLATE   "%s-92.68.150.%u"
 
#define KNOWN_CONNECT_ADDRESS_TEMPLATE   "%s-92.68.151.%u"
 
#define PREFIX_TCP   "tcp"
 
#define PREFIX_UDP   "udp"
 
#define PREFIX_TCP_NATTED   "tcp_natted"
 
#define PREFIX_UDP_NATTED   "udp_natted"
 

Functions

static int log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
 A helper function to log information about individual nodes. More...
 
static int log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
 Helper function to log information about namespaces. More...
 
static int log_topo (const struct GNUNET_TESTING_NetjailTopology *topology)
 Helper function to log the configuration in case of a problem with configuration. More...
 
static void get_node_info (unsigned int num, const struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailNode **node_ex, struct GNUNET_TESTING_NetjailNamespace **namespace_ex, struct GNUNET_TESTING_NodeConnection **node_connections_ex)
 This function extracts information about a specific node from the topology. More...
 
struct GNUNET_TESTING_NetjailNodeGNUNET_TESTING_get_node (unsigned int num, struct GNUNET_TESTING_NetjailTopology *topology)
 Get a node from the topology. More...
 
struct GNUNET_TESTING_NodeConnectionGNUNET_TESTING_get_connections (unsigned int num, const struct GNUNET_TESTING_NetjailTopology *topology)
 Get the connections to other nodes for a specific node. More...
 
static int free_value_cb (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
static int free_subnets_cb (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
static int free_carriers_cb (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
void GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology)
 Deallocate memory of the struct GNUNET_TESTING_NetjailTopology. More...
 
unsigned int GNUNET_TESTING_calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection, struct GNUNET_TESTING_NetjailTopology *topology)
 Deallocate memory of the struct GNUNET_TESTING_NetjailTopology. More...
 
char * GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, const char *prefix)
 Get the address for a specific communicator from a connection. More...
 
unsigned int GNUNET_TESTING_get_additional_connects (unsigned int num, struct GNUNET_TESTING_NetjailTopology *topology)
 Get the number of unintentional additional connections the node waits for. More...
 
char * GNUNET_TESTING_get_plugin_from_topo (struct GNUNET_TESTING_NetjailTopology *njt, const char *my_node_id)
 Get the global plugin name form the topology file. More...
 
static void create_subnet_peers (struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailSubnet *subnet)
 
static void create_subnets (struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailCarrier *carrier)
 
static void create_peers (struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailCarrier *carrier)
 
struct GNUNET_TESTING_NetjailTopologyGNUNET_TESTING_get_topo_from_string_ (const char *input)
 Parse the topology data. More...
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "testing-api", __VA_ARGS__)

Definition at line 39 of file testing_api_topology.c.

◆ CONNECT_ADDRESS_TEMPLATE

#define CONNECT_ADDRESS_TEMPLATE   "%s-192.168.15.%u"

Definition at line 41 of file testing_api_topology.c.

◆ ROUTER_CONNECT_ADDRESS_TEMPLATE

#define ROUTER_CONNECT_ADDRESS_TEMPLATE   "%s-92.68.150.%u"

Definition at line 43 of file testing_api_topology.c.

◆ KNOWN_CONNECT_ADDRESS_TEMPLATE

#define KNOWN_CONNECT_ADDRESS_TEMPLATE   "%s-92.68.151.%u"

Definition at line 45 of file testing_api_topology.c.

◆ PREFIX_TCP

#define PREFIX_TCP   "tcp"

Definition at line 47 of file testing_api_topology.c.

◆ PREFIX_UDP

#define PREFIX_UDP   "udp"

Definition at line 49 of file testing_api_topology.c.

◆ PREFIX_TCP_NATTED

#define PREFIX_TCP_NATTED   "tcp_natted"

Definition at line 51 of file testing_api_topology.c.

◆ PREFIX_UDP_NATTED

#define PREFIX_UDP_NATTED   "udp_natted"

Definition at line 53 of file testing_api_topology.c.

Function Documentation

◆ log_nodes()

static int log_nodes ( void *  cls,
const struct GNUNET_ShortHashCode id,
void *  value 
)
static

A helper function to log information about individual nodes.

Parameters
clsThis is not used actually.
idThe key of this value in the map.
valueA struct GNUNET_TESTING_NetjailNode which holds information about a node. return GNUNET_YES to continue with iterating, GNUNET_NO otherwise.

Definition at line 65 of file testing_api_topology.c.

68{
69 struct GNUNET_TESTING_NetjailNode *node = value;
70 struct GNUNET_TESTING_NodeConnection *pos_connection;
71 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
72
74 "plugin: %s space: %u node: %u global: %u\n",
75 node->plugin,
76 node->namespace_n,
77 node->node_n,
78 node->is_global);
79
80 for (pos_connection = node->node_connections_head; NULL != pos_connection;
81 pos_connection = pos_connection->next)
82 {
83
85 "namespace_n: %u node_n: %u node_type: %u\n",
86 pos_connection->namespace_n,
87 pos_connection->node_n,
88 pos_connection->node_type);
89
90 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
91 pos_prefix =
92 pos_prefix->next)
93 {
95 "prefix: %s\n",
96 pos_prefix->address_prefix);
97 }
98 }
99 return GNUNET_YES;
100}
static char * value
Value of the record to add/remove.
@ GNUNET_YES
@ GNUNET_ERROR_TYPE_DEBUG
Protocol address prefix für a connection between nodes.
struct GNUNET_TESTING_AddressPrefix * next
Pointer to the next prefix in the DLL.
char * address_prefix
The address prefix.
Node in the netjail topology.
unsigned int namespace_n
The number of the subnet this node is running in.
struct GNUNET_TESTING_NodeConnection * node_connections_head
Head of the DLL with the connections which shall be established to other nodes.
unsigned int is_global
Flag indicating if this node is a global known node.
char * plugin
Plugin for the test case to be run on this node.
unsigned int node_n
The number of this node in the subnet.
Connection to another node.
struct GNUNET_TESTING_NodeConnection * next
Pointer to the next connection in the DLL.
unsigned int node_n
The number of the node this connection points to.
unsigned int namespace_n
The number of the subnet of the node this connection points to.
struct GNUNET_TESTING_AddressPrefix * address_prefixes_head
Head of the DLL with the address prefixes for the protocols this node is reachable.
enum GNUNET_TESTING_NodeType node_type
The type of the node this connection points to.
#define LOG(kind,...)

References GNUNET_TESTING_AddressPrefix::address_prefix, GNUNET_TESTING_NodeConnection::address_prefixes_head, GNUNET_ERROR_TYPE_DEBUG, GNUNET_YES, GNUNET_TESTING_NetjailNode::is_global, LOG, GNUNET_TESTING_NodeConnection::namespace_n, GNUNET_TESTING_NetjailNode::namespace_n, GNUNET_TESTING_AddressPrefix::next, GNUNET_TESTING_NodeConnection::next, GNUNET_TESTING_NetjailNode::node_connections_head, GNUNET_TESTING_NodeConnection::node_n, GNUNET_TESTING_NetjailNode::node_n, GNUNET_TESTING_NodeConnection::node_type, GNUNET_TESTING_NetjailNode::plugin, and value.

Referenced by log_namespaces(), and log_topo().

Here is the caller graph for this function:

◆ log_namespaces()

static int log_namespaces ( void *  cls,
const struct GNUNET_ShortHashCode id,
void *  value 
)
static

Helper function to log information about namespaces.

Parameters
clsThis is not used actually.
idThe key of this value in the map.
valueA struct GNUNET_TESTING_NetjailNamespace which holds information about a subnet. return GNUNET_YES to continue with iterating, GNUNET_NO otherwise.

Definition at line 112 of file testing_api_topology.c.

115{
116 struct GNUNET_TESTING_NetjailNamespace *namespace = value;
117
119 &log_nodes,
120 NULL);
121 return GNUNET_YES;
122}
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
static int log_nodes(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
A helper function to log information about individual nodes.

References GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_YES, log_nodes(), and value.

Referenced by log_topo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_topo()

static int log_topo ( const struct GNUNET_TESTING_NetjailTopology topology)
static

Helper function to log the configuration in case of a problem with configuration.

Parameters
topologyThe struct GNUNET_TESTING_NetjailTopology holding the configuration information.

Definition at line 131 of file testing_api_topology.c.

132{
134 "plugin: %s spaces: %u nodes: %u known: %u\n",
135 topology->plugin,
136 topology->namespaces_n,
137 topology->nodes_m,
138 topology->nodes_x);
139
141 log_namespaces, NULL);
143 NULL);
144 return GNUNET_YES;
145}
struct GNUNET_CONTAINER_MultiShortmap * map_globals
Hash map containing the global known nodes which are not natted.
char * plugin
Default plugin for the test case to be run on nodes.
unsigned int nodes_m
Number of nodes per subnet.
unsigned int nodes_x
Number of global known nodes.
unsigned int namespaces_n
Number of subnets.
struct GNUNET_CONTAINER_MultiShortmap * map_namespaces
Hash map containing the subnets (for natted nodes) of the topology.
static int log_namespaces(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
Helper function to log information about namespaces.

References GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_YES, LOG, log_namespaces(), log_nodes(), GNUNET_TESTING_NetjailTopology::map_globals, GNUNET_TESTING_NetjailTopology::map_namespaces, GNUNET_TESTING_NetjailTopology::namespaces_n, GNUNET_TESTING_NetjailTopology::nodes_m, GNUNET_TESTING_NetjailTopology::nodes_x, and GNUNET_TESTING_NetjailTopology::plugin.

Referenced by get_node_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_node_info()

static void get_node_info ( unsigned int  num,
const struct GNUNET_TESTING_NetjailTopology topology,
struct GNUNET_TESTING_NetjailNode **  node_ex,
struct GNUNET_TESTING_NetjailNamespace **  namespace_ex,
struct GNUNET_TESTING_NodeConnection **  node_connections_ex 
)
static

This function extracts information about a specific node from the topology.

Parameters
numThe global index number of the node.
[out]node_exA struct GNUNET_TESTING_NetjailNode with information about the node.
[out]namespace_exA struct GNUNET_TESTING_NetjailNamespace with information about the namespace the node is in or NULL, if the node is a global node.
[out]node_connections_exA struct GNUNET_TESTING_NodeConnection with information about the connection of this node to other nodes.

Definition at line 159 of file testing_api_topology.c.

164{
165 struct GNUNET_ShortHashCode hkey;
166 struct GNUNET_HashCode hc;
167 unsigned int namespace_n;
168 unsigned int node_m;
169 struct GNUNET_TESTING_NetjailNode *node;
170 struct GNUNET_TESTING_NetjailNamespace *namespace;
171 struct GNUNET_TESTING_NodeConnection *node_connections = NULL;
172
173 log_topo (topology);
175 "num: %u \n",
176 num);
177 if (topology->nodes_x >= num)
178 {
179
180 GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
181 memcpy (&hkey,
182 &hc,
183 sizeof (hkey));
185 &hkey);
186 if (NULL != node)
187 {
188 *node_ex = node;
189 *node_connections_ex = node->node_connections_head;
190 }
191 }
192 else
193 {
194 namespace_n = (unsigned int) ceil ((double) (num - topology->nodes_x)
195 / topology->nodes_m);
197 "ceil num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
198 num,
199 topology->nodes_x,
200 topology->nodes_m,
203 memcpy (&hkey,
204 &hc,
205 sizeof (hkey));
206 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
207 &hkey);
208 if (NULL != namespace)
209 {
210 node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
211 GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
212 memcpy (&hkey,
213 &hc,
214 sizeof (hkey));
215 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
216 &hkey);
217 if (NULL != node)
218 {
220 "node additional_connects: %u %p\n",
222 node);
223 node_connections = node->node_connections_head;
224 }
225 *node_ex = node;
226 *namespace_ex = namespace;
227 *node_connections_ex = node_connections;
228 }
229 }
230}
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
A 512-bit hashcode.
A 256-bit hashcode.
unsigned int additional_connects
The number of unintentional additional connections this node waits for.
struct GNUNET_TESTING_NetjailNode * node
The node which establish the connection.
static int log_topo(const struct GNUNET_TESTING_NetjailTopology *topology)
Helper function to log the configuration in case of a problem with configuration.

References GNUNET_TESTING_NetjailNode::additional_connects, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, consensus-simulation::int, LOG, log_topo(), GNUNET_TESTING_NetjailTopology::map_globals, GNUNET_TESTING_NodeConnection::namespace_n, GNUNET_TESTING_NodeConnection::node, GNUNET_TESTING_NetjailNode::node_connections_head, GNUNET_TESTING_NetjailTopology::nodes_m, and GNUNET_TESTING_NetjailTopology::nodes_x.

Referenced by GNUNET_TESTING_get_additional_connects(), GNUNET_TESTING_get_connections(), and GNUNET_TESTING_get_node().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_node()

struct GNUNET_TESTING_NetjailNode * GNUNET_TESTING_get_node ( unsigned int  num,
struct GNUNET_TESTING_NetjailTopology topology 
)

Get a node from the topology.

Parameters
numThe specific node we want the connections for.
topologyThe topology we get the connections from.
Returns
The connections of the node.

Definition at line 241 of file testing_api_topology.c.

243{
244 struct GNUNET_TESTING_NetjailNode *node;
245 struct GNUNET_TESTING_NetjailNamespace *namespace;
246 struct GNUNET_TESTING_NodeConnection *node_connections;
247
248 get_node_info (num, topology, &node, &namespace, &node_connections);
249
250 return node;
251
252}
static void get_node_info(unsigned int num, const struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailNode **node_ex, struct GNUNET_TESTING_NetjailNamespace **namespace_ex, struct GNUNET_TESTING_NodeConnection **node_connections_ex)
This function extracts information about a specific node from the topology.

References get_node_info(), and GNUNET_TESTING_NodeConnection::node.

Here is the call graph for this function:

◆ GNUNET_TESTING_get_connections()

struct GNUNET_TESTING_NodeConnection * GNUNET_TESTING_get_connections ( unsigned int  num,
const struct GNUNET_TESTING_NetjailTopology topology 
)

Get the connections to other nodes for a specific node.

Parameters
numThe specific node we want the connections for.
topologyThe topology we get the connections from.
Returns
The connections of the node.

Definition at line 263 of file testing_api_topology.c.

266{
267 struct GNUNET_TESTING_NetjailNode *node;
268 struct GNUNET_TESTING_NetjailNamespace *namespace;
269 struct GNUNET_TESTING_NodeConnection *node_connections;
270
272 "get_connections\n");
273
274 get_node_info (num, topology, &node, &namespace, &node_connections);
275
276 return node_connections;
277}

References get_node_info(), GNUNET_ERROR_TYPE_DEBUG, LOG, and GNUNET_TESTING_NodeConnection::node.

Referenced by backchannel_check_run(), and connect_peers_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_value_cb()

static int free_value_cb ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 281 of file testing_api_topology.c.

284{
285 (void) cls;
286
288
289 return GNUNET_OK;
290}
@ GNUNET_OK
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free, GNUNET_OK, and value.

Referenced by free_carriers_cb(), free_subnets_cb(), and GNUNET_TESTING_free_topology().

Here is the caller graph for this function:

◆ free_subnets_cb()

static int free_subnets_cb ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 294 of file testing_api_topology.c.

297{
298 struct GNUNET_TESTING_NetjailSubnet *subnet = value;
299 (void) cls;
300
303 NULL);
304
305 GNUNET_free (subnet);
306
307 return GNUNET_OK;
308}
struct GNUNET_CONTAINER_MultiShortmap * peers
Hash map containing peers.
static int free_value_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)

References free_value_cb(), GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_free, GNUNET_OK, GNUNET_TESTING_NetjailSubnet::peers, and value.

Referenced by free_carriers_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_carriers_cb()

static int free_carriers_cb ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 312 of file testing_api_topology.c.

315{
316 struct GNUNET_TESTING_NetjailCarrier *carrier = value;
317 (void) cls;
318
321 NULL);
324 NULL);
325
326 GNUNET_free (carrier);
327
328 return GNUNET_OK;
329}
struct GNUNET_CONTAINER_MultiShortmap * subnets
Hash map containing subnets.
struct GNUNET_CONTAINER_MultiShortmap * peers
Hash map containing peers.
static int free_subnets_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)

References free_subnets_cb(), free_value_cb(), GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_free, GNUNET_OK, GNUNET_TESTING_NetjailCarrier::peers, GNUNET_TESTING_NetjailCarrier::subnets, and value.

Referenced by GNUNET_TESTING_free_topology().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_free_topology()

void GNUNET_TESTING_free_topology ( struct GNUNET_TESTING_NetjailTopology topology)

Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.

Parameters
topologyThe GNUNET_TESTING_NetjailTopology to be deallocated.

Definition at line 338 of file testing_api_topology.c.

339{
342 NULL);
345 NULL);
346 GNUNET_free (topology->plugin);
347 GNUNET_free (topology);
348}
struct GNUNET_CONTAINER_MultiShortmap * carriers
Hash map containing the carriers.
struct GNUNET_CONTAINER_MultiShortmap * backbone_peers
Hash map containing the carriers.
static int free_carriers_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)

References GNUNET_TESTING_NetjailTopology::backbone_peers, GNUNET_TESTING_NetjailTopology::carriers, free_carriers_cb(), free_value_cb(), GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_free, and GNUNET_TESTING_NetjailTopology::plugin.

Referenced by cleanup(), do_shutdown_later(), and netjail_exec_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_calculate_num()

unsigned int GNUNET_TESTING_calculate_num ( struct GNUNET_TESTING_NodeConnection node_connection,
struct GNUNET_TESTING_NetjailTopology topology 
)

Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.

Calculate the unique id identifying a node from a given connection.

Parameters
topologyThe GNUNET_TESTING_NetjailTopology to be deallocated.

void GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology) { GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces, &free_namespaces_cb, NULL); GNUNET_CONTAINER_multishortmap_destroy (topology->map_namespaces); GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &free_nodes_cb, NULL); GNUNET_CONTAINER_multishortmap_destroy (topology->map_globals); GNUNET_free (topology->plugin); GNUNET_free (topology); }

Definition at line 373 of file testing_api_topology.c.

376{
377 unsigned int n, m, num;
378
379 n = node_connection->namespace_n;
380 m = node_connection->node_n;
381
382 if (0 == n)
383 num = m;
384 else
385 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
386
387 return num;
388}
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:103

References m, GNUNET_TESTING_NodeConnection::namespace_n, GNUNET_TESTING_NodeConnection::node_n, GNUNET_TESTING_NetjailTopology::nodes_m, and GNUNET_TESTING_NetjailTopology::nodes_x.

Referenced by connect_peers_run(), and notify_connect().

Here is the caller graph for this function:

◆ GNUNET_TESTING_get_address()

char * GNUNET_TESTING_get_address ( struct GNUNET_TESTING_NodeConnection connection,
const char *  prefix 
)

Get the address for a specific communicator from a connection.

Parameters
connectionThe connection we like to have the address from.
prefixThe communicator protocol prefix.
Returns
The address of the communicator.

Definition at line 399 of file testing_api_topology.c.

401{
402 struct GNUNET_TESTING_NetjailNode *node;
403 char *addr;
404 const char *template;
405 unsigned int node_n;
406
408 "get address prefix: %s node_n: %u\n",
409 prefix,
410 connection->node_n);
411
412 node = connection->node;
413 if (connection->namespace_n == node->namespace_n)
414 {
415 template = CONNECT_ADDRESS_TEMPLATE;
416 node_n = connection->node_n;
417 }
418 else if (0 == connection->namespace_n)
419 {
421 node_n = connection->node_n;
422 }
423 else if (1 == connection->node_n)
424 {
426 node_n = connection->namespace_n;
427 }
428 else
429 {
430 return NULL;
431 }
432
433 if (0 == strcmp (PREFIX_TCP, prefix) ||
434 0 == strcmp (PREFIX_UDP, prefix) ||
435 0 == strcmp (PREFIX_UDP_NATTED, prefix) ||
436 0 == strcmp (PREFIX_TCP_NATTED, prefix))
437 {
438 GNUNET_asprintf (&addr,
439 template,
440 prefix,
441 node_n);
442 }
443 else
444 {
445 GNUNET_assert (0);
446 }
447
448 return addr;
449}
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:65
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define PREFIX_UDP_NATTED
#define PREFIX_TCP
#define PREFIX_TCP_NATTED
#define CONNECT_ADDRESS_TEMPLATE
#define PREFIX_UDP
#define KNOWN_CONNECT_ADDRESS_TEMPLATE
#define ROUTER_CONNECT_ADDRESS_TEMPLATE

References CONNECT_ADDRESS_TEMPLATE, GNUNET_asprintf(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, KNOWN_CONNECT_ADDRESS_TEMPLATE, LOG, GNUNET_TESTING_NodeConnection::namespace_n, GNUNET_TESTING_NetjailNode::namespace_n, GNUNET_TESTING_NodeConnection::node, GNUNET_TESTING_NodeConnection::node_n, GNUNET_TESTING_NetjailNode::node_n, prefix, PREFIX_TCP, PREFIX_TCP_NATTED, PREFIX_UDP, PREFIX_UDP_NATTED, and ROUTER_CONNECT_ADDRESS_TEMPLATE.

Referenced by connect_peers_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_additional_connects()

unsigned int GNUNET_TESTING_get_additional_connects ( unsigned int  num,
struct GNUNET_TESTING_NetjailTopology topology 
)

Get the number of unintentional additional connections the node waits for.

Parameters
numThe specific node we want the additional connects for.
Returns
The number of additional connects

Definition at line 459 of file testing_api_topology.c.

462{
463 struct GNUNET_TESTING_NetjailNode *node;
464 struct GNUNET_TESTING_NetjailNamespace *namespace;
465 struct GNUNET_TESTING_NodeConnection *node_connections;
466
468 "get_additional_connects\n");
469
470 get_node_info (num, topology, &node, &namespace, &node_connections);
471
472 if (NULL == node)
473 {
475 "No info found for node %d\n", num);
476 return 0;
477 }
479 "node additional_connects for node %p\n",
480 node);
482 "node additional_connects: %u\n",
484
486}
@ GNUNET_ERROR_TYPE_WARNING

References GNUNET_TESTING_NetjailNode::additional_connects, get_node_info(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, and LOG.

Referenced by GNUNET_CORE_cmd_connect_peers(), and GNUNET_TRANSPORT_cmd_connect_peers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_plugin_from_topo()

char * GNUNET_TESTING_get_plugin_from_topo ( struct GNUNET_TESTING_NetjailTopology njt,
const char *  my_node_id 
)

Get the global plugin name form the topology file.

Definition at line 490 of file testing_api_topology.c.

493{
494 return njt->plugin;
495}
struct GNUNET_TESTING_NetjailTopology * njt
The loaded topology.

References njt, and GNUNET_TESTING_NetjailTopology::plugin.

Referenced by handle_helper_init().

Here is the caller graph for this function:

◆ create_subnet_peers()

static void create_subnet_peers ( struct GNUNET_CONFIGURATION_Handle cfg,
struct GNUNET_TESTING_NetjailTopology topology,
struct GNUNET_TESTING_NetjailSubnet subnet 
)
static

Definition at line 499 of file testing_api_topology.c.

502{
503 struct GNUNET_HashCode hc = {0};
505
506 for (int i = 0; i < subnet->number_peers; i++)
507 {
508 struct GNUNET_ShortHashCode hkey;
509 struct GNUNET_TESTING_NetjailSubnetPeer *subnet_peer = GNUNET_new (struct
511
512 topology->total++;
514 "Subnet peers -> Number of nodes: %u\n",
515 topology->total);
516 GNUNET_CRYPTO_hash (&topology->total, sizeof(topology->total), &hc);
517 memcpy (&hkey,
518 &hc,
519 sizeof (hkey));
521 &hkey,
522 subnet_peer,
524 }
525}
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
@ GNUNET_NO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
unsigned int number_peers
Number of subnet peers.
unsigned int total
Total number of namespaces in the topology.

References GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_create(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_NO, LOG, GNUNET_TESTING_NetjailSubnet::number_peers, GNUNET_TESTING_NetjailSubnet::peers, and GNUNET_TESTING_NetjailTopology::total.

Referenced by create_subnets().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_subnets()

static void create_subnets ( struct GNUNET_CONFIGURATION_Handle cfg,
struct GNUNET_TESTING_NetjailTopology topology,
struct GNUNET_TESTING_NetjailCarrier carrier 
)
static

Definition at line 529 of file testing_api_topology.c.

532{
533 struct GNUNET_HashCode hc = {0};
535
536 for (int i = 0; i < carrier->number_subnets; i++)
537 {
538 struct GNUNET_ShortHashCode hkey;
539 struct GNUNET_TESTING_NetjailSubnet *subnet = GNUNET_new (struct
541 char *section;
542
543 topology->total++;
545 "Subnets -> Number of nodes: %u\n",
546 topology->total);
547 subnet->number = topology->total;
548 subnet->index = i;
549 GNUNET_CRYPTO_hash (&topology->total, sizeof(topology->total), &hc);
550 memcpy (&hkey,
551 &hc,
552 sizeof (hkey));
554 &hkey,
555 subnet,
557 GNUNET_asprintf (&section, "CARRIER-%u-SUBNET-%u", carrier->index, i);
559 section,
560 "SUBNET_PEERS",
561 (unsigned long
562 long *) &subnet->
564 {
565 subnet->number_peers = topology->default_subnet_peers;
566 }
567
568 create_subnet_peers (cfg, topology, subnet);
569
570 GNUNET_free (section);
571 }
572}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
unsigned int number_subnets
Number of carrier subnets.
unsigned int index
Of all carriers this has index.
unsigned int number
Unique identifier this part of the topology can be identified.
unsigned int index
Of all subnets this has index.
unsigned long long default_subnet_peers
Default number of peers per subnet.
static void create_subnet_peers(struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailSubnet *subnet)

References cfg, create_subnet_peers(), GNUNET_TESTING_NetjailTopology::default_subnet_peers, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_create(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_TESTING_NetjailCarrier::index, GNUNET_TESTING_NetjailSubnet::index, LOG, GNUNET_TESTING_NetjailSubnet::number, GNUNET_TESTING_NetjailSubnet::number_peers, GNUNET_TESTING_NetjailCarrier::number_subnets, GNUNET_TESTING_NetjailCarrier::subnets, and GNUNET_TESTING_NetjailTopology::total.

Referenced by GNUNET_TESTING_get_topo_from_string_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_peers()

static void create_peers ( struct GNUNET_CONFIGURATION_Handle cfg,
struct GNUNET_TESTING_NetjailTopology topology,
struct GNUNET_TESTING_NetjailCarrier carrier 
)
static

Definition at line 576 of file testing_api_topology.c.

579{
580 struct GNUNET_HashCode hc = {0};
582
583 for (int i = 0; i < carrier->number_peers; i++)
584 {
585 struct GNUNET_ShortHashCode hkey;
586 struct GNUNET_TESTING_NetjailCarrierPeer *peer = GNUNET_new (struct
588
589 topology->total++;
591 "Carrier peers -> Number of nodes: %u\n",
592 topology->total);
593 peer->number = topology->total;
594 GNUNET_CRYPTO_hash (&topology->total, sizeof(topology->total), &hc);
595 memcpy (&hkey,
596 &hc,
597 sizeof (hkey));
599 &hkey,
600 peer,
602 // GNUNET_asprintf (&section, "CARRIER-%u-PEER-%u", carrier->index, i);
603 }
604}
unsigned int number
Unique identifier this part of the topology can be identified.
unsigned int number_peers
Number of carrier peers.

References GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_create(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_NO, LOG, GNUNET_TESTING_NetjailCarrierPeer::number, GNUNET_TESTING_NetjailCarrier::number_peers, GNUNET_TESTING_NetjailCarrier::peers, and GNUNET_TESTING_NetjailTopology::total.

Referenced by GNUNET_TESTING_get_topo_from_string_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_get_topo_from_string_()

struct GNUNET_TESTING_NetjailTopology * GNUNET_TESTING_get_topo_from_string_ ( const char *  data)

Parse the topology data.

Parameters
dataThe topology data.
Returns
The GNUNET_TESTING_NetjailTopology

Definition at line 608 of file testing_api_topology.c.

609{
611 struct GNUNET_HashCode hc = {0};
612 struct GNUNET_TESTING_NetjailTopology *topology = GNUNET_new (struct
614
615 topology->backbone_peers
617 GNUNET_NO);
618 topology->carriers
620 GNUNET_NO);
622 GNUNET_assert (NULL != topology->carriers);
623
624 if (GNUNET_OK !=
626 input,
627 strlen (input),
628 NULL))
629 {
631 _ ("Failed to parse configuration.\n"));
633 return NULL;
634 }
635 if (GNUNET_OK !=
637 "DEFAULTS",
638 "SUBNETS",
639 &topology->default_subnets))
640 {
642 "Missing default SUBNETS!\n");
643 return NULL;
644 }
646 "DEFAULTS",
647 "TESTBED_PLUGIN",
648 &topology->plugin))
649 {
651 "Missing default TESTBED_PLUGIN!\n");
652 return NULL;
653 }
655 "DEFAULTS",
656 "CARRIER_PEERS",
657 &(topology->
659 {
661 "Missing default CARRIER_PEERS!\n");
662 return NULL;
663 }
665 "DEFAULTS",
666 "SUBNET_PEERS",
667 &(topology->
669 {
671 "Missing default SUBNET_PEERS!\n");
672 return NULL;
673 }
675 "BACKBONE",
676 "CARRIERS",
677 &(topology->
678 num_carriers)))
679 {
681 "No carrier configured!\n");
682 return NULL;
683 }
685 "BACKBONE",
686 "BACKBONE_PEERS",
687 &(topology->
689 )
690 {
692 "No backbone peers configured!\n");
693 return NULL;
694 }
695 for (int i = 0; i < topology->num_backbone_peers; i++)
696 {
699 struct GNUNET_ShortHashCode hkey;
700
701 topology->total++;
703 "Backbone peers -> Number of nodes: %u\n",
704 topology->total);
705 peer->number = topology->total;
706 GNUNET_CRYPTO_hash (&topology->total, sizeof(topology->total), &hc);
707 memcpy (&hkey,
708 &hc,
709 sizeof (hkey));
711 &hkey,
712 peer,
714 }
715 GNUNET_assert (NULL != topology->carriers);
716 for (int i = 0; i < topology->num_carriers; i++)
717 {
718 struct GNUNET_TESTING_NetjailCarrier *carrier = GNUNET_new (struct
720 struct GNUNET_ShortHashCode hkey;
721 char *section;
722
723 topology->total++;
725 "Carrier -> Number of nodes: %u\n",
726 topology->total);
727 carrier->number = topology->total;
728 GNUNET_CRYPTO_hash (&topology->total, sizeof(topology->total), &hc);
729 memcpy (&hkey,
730 &hc,
731 sizeof (hkey));
732 GNUNET_assert (NULL != topology->carriers);
734 &hkey,
735 carrier,
737 GNUNET_asprintf (&section, "CARRIER-%u", i);
739 section,
740 "SUBNETS",
741 (unsigned long
742 long *) &carrier->
743 number_subnets))
744 {
745 carrier->number_subnets = topology->default_subnets;
747 "Carrier -> Default number of subnets: %u\n",
748 carrier->number_subnets);
749 }
751 "Carrier -> number of subnets: %u\n",
752 carrier->number_subnets);
754 section,
755 "CARRIER_PEERS",
756 (unsigned long
757 long *) &carrier->
758 number_peers))
759 {
760 carrier->number_peers = topology->default_carrier_peers;
762 "Carrier -> Default number of peers: %u\n",
763 carrier->number_peers);
764 }
766 "Carrier -> Default number of peers: %u\n",
767 carrier->number_peers);
768 create_peers (cfg, topology, carrier);
769 create_subnets (cfg, topology, carrier);
770
771 GNUNET_free (section);
772 }
773
775
776 return topology;
777}
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_INFO
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
unsigned int number
Unique identifier this part of the topology can be identified.
unsigned int number
Unique identifier this part of the topology can be identified.
Toplogy of our netjail setup.
unsigned long long default_subnets
Default number of subnets per carrier.
unsigned long long num_carriers
Number of carriers.
unsigned long long default_carrier_peers
Default number of peers per carrier.
unsigned long long num_backbone_peers
Default number of backbone peers.
static void create_peers(struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailCarrier *carrier)
static void create_subnets(struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_NetjailTopology *topology, struct GNUNET_TESTING_NetjailCarrier *carrier)

References _, GNUNET_TESTING_NetjailTopology::backbone_peers, GNUNET_TESTING_NetjailTopology::carriers, cfg, create_peers(), create_subnets(), GNUNET_TESTING_NetjailTopology::default_carrier_peers, GNUNET_TESTING_NetjailTopology::default_subnets, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_deserialize(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_create(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_OS_project_data_gnunet(), LOG, GNUNET_TESTING_NetjailTopology::num_backbone_peers, GNUNET_TESTING_NetjailTopology::num_carriers, GNUNET_TESTING_NetjailBackbonePeer::number, GNUNET_TESTING_NetjailCarrier::number, GNUNET_TESTING_NetjailCarrier::number_peers, GNUNET_TESTING_NetjailCarrier::number_subnets, GNUNET_TESTING_NetjailTopology::plugin, and GNUNET_TESTING_NetjailTopology::total.

Referenced by handle_helper_init(), netjail_exec_run(), and run().

Here is the call graph for this function:
Here is the caller graph for this function: