aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_topology.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-10-27 13:42:08 +0000
committerChristian Grothoff <christian@grothoff.org>2015-10-27 13:42:08 +0000
commit8d9e724fe53ec6ddb0a02c2c981ea8ff1379f727 (patch)
tree00a66c4d85b0a9c640af29b3f303b341bebed5d7 /src/testbed/testbed_api_topology.c
parent3d3109aa4c8c25d9292e9e94d878121af0084d07 (diff)
downloadgnunet-8d9e724fe53ec6ddb0a02c2c981ea8ff1379f727.tar.gz
gnunet-8d9e724fe53ec6ddb0a02c2c981ea8ff1379f727.zip
-indentation, doxygen, etc.
Diffstat (limited to 'src/testbed/testbed_api_topology.c')
-rw-r--r--src/testbed/testbed_api_topology.c98
1 files changed, 55 insertions, 43 deletions
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c
index 1bfc9955d..1f67176cd 100644
--- a/src/testbed/testbed_api_topology.c
+++ b/src/testbed/testbed_api_topology.c
@@ -217,12 +217,12 @@ struct TopologyContext
217 * The type of this context 217 * The type of this context
218 */ 218 */
219 enum { 219 enum {
220 220
221 /** 221 /**
222 * Type for underlay topology 222 * Type for underlay topology
223 */ 223 */
224 TOPOLOGYCONTEXT_TYPE_UNDERLAY = 0, 224 TOPOLOGYCONTEXT_TYPE_UNDERLAY = 0,
225 225
226 /** 226 /**
227 * Type for overlay topology 227 * Type for overlay topology
228 */ 228 */
@@ -475,7 +475,7 @@ make_link (unsigned int offset, uint32_t A, uint32_t B,
475 { 475 {
476 struct TopologyContextOverlay *overlay; 476 struct TopologyContextOverlay *overlay;
477 struct OverlayLink *olink; 477 struct OverlayLink *olink;
478 478
479 overlay = &tc->u.overlay; 479 overlay = &tc->u.overlay;
480 GNUNET_assert (offset < tc->link_array_size); 480 GNUNET_assert (offset < tc->link_array_size);
481 olink = &overlay->link_array[offset]; 481 olink = &overlay->link_array[offset];
@@ -490,7 +490,7 @@ make_link (unsigned int offset, uint32_t A, uint32_t B,
490 { 490 {
491 struct TopologyContextUnderlay *underlay; 491 struct TopologyContextUnderlay *underlay;
492 struct UnderlayLink *ulink; 492 struct UnderlayLink *ulink;
493 493
494 underlay = &tc->u.underlay; 494 underlay = &tc->u.underlay;
495 GNUNET_assert (offset < tc->link_array_size); 495 GNUNET_assert (offset < tc->link_array_size);
496 ulink = &underlay->link_array[offset]; 496 ulink = &underlay->link_array[offset];
@@ -518,7 +518,7 @@ gen_topo_line (struct TopologyContext *tc)
518 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 518 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
519 { 519 {
520 struct TopologyContextOverlay *overlay; 520 struct TopologyContextOverlay *overlay;
521 521
522 overlay = &tc->u.overlay; 522 overlay = &tc->u.overlay;
523 overlay->link_array = 523 overlay->link_array =
524 GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size); 524 GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
@@ -527,7 +527,7 @@ gen_topo_line (struct TopologyContext *tc)
527 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 527 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
528 { 528 {
529 struct TopologyContextUnderlay *underlay; 529 struct TopologyContextUnderlay *underlay;
530 530
531 underlay = &tc->u.underlay; 531 underlay = &tc->u.underlay;
532 underlay->link_array = 532 underlay->link_array =
533 GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size); 533 GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
@@ -564,7 +564,7 @@ gen_topo_ring (struct TopologyContext *tc)
564 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 564 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
565 { 565 {
566 struct TopologyContextUnderlay *underlay; 566 struct TopologyContextUnderlay *underlay;
567 567
568 underlay = &tc->u.underlay; 568 underlay = &tc->u.underlay;
569 underlay->link_array = 569 underlay->link_array =
570 GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) * 570 GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) *
@@ -656,7 +656,7 @@ gen_topo_2dtorus (struct TopologyContext *tc)
656 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 656 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
657 { 657 {
658 struct TopologyContextOverlay *overlay; 658 struct TopologyContextOverlay *overlay;
659 659
660 overlay = &tc->u.overlay; 660 overlay = &tc->u.overlay;
661 overlay->link_array = 661 overlay->link_array =
662 GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size); 662 GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
@@ -714,11 +714,13 @@ gen_topo_2dtorus (struct TopologyContext *tc)
714 * 714 *
715 * @param tc the topology context 715 * @param tc the topology context
716 * @param links the number of random links to establish 716 * @param links the number of random links to establish
717 * @param append GNUNET_YES to add links to existing link array; GNUNET_NO to 717 * @param append #GNUNET_YES to add links to existing link array; #GNUNET_NO to
718 * create a new link array 718 * create a new link array
719 */ 719 */
720static void 720static void
721gen_topo_random (struct TopologyContext *tc, unsigned int links, int append) 721gen_topo_random (struct TopologyContext *tc,
722 unsigned int links,
723 int append)
722{ 724{
723 unsigned int cnt; 725 unsigned int cnt;
724 unsigned int index; 726 unsigned int index;
@@ -802,7 +804,9 @@ gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
802 * network 804 * network
803 */ 805 */
804static void 806static void
805gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m) 807gen_topo_scale_free (struct TopologyContext *tc,
808 uint16_t cap,
809 uint8_t m)
806{ 810{
807 unsigned int *deg; 811 unsigned int *deg;
808 unsigned int *etab; 812 unsigned int *etab;
@@ -903,9 +907,9 @@ gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m)
903 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 907 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
904 { 908 {
905 struct TopologyContextOverlay *overlay; 909 struct TopologyContextOverlay *overlay;
906 910
907 overlay = &tc->u.overlay; 911 overlay = &tc->u.overlay;
908 overlay->link_array = 912 overlay->link_array =
909 GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * tc->link_array_size); 913 GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * tc->link_array_size);
910 } 914 }
911 break; 915 break;
@@ -929,7 +933,8 @@ gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m)
929 * @param filename the filename of the file containing topology data 933 * @param filename the filename of the file containing topology data
930 */ 934 */
931static void 935static void
932gen_topo_from_file (struct TopologyContext *tc, const char *filename) 936gen_topo_from_file (struct TopologyContext *tc,
937 const char *filename)
933{ 938{
934 char *data; 939 char *data;
935 char *end; 940 char *end;
@@ -957,20 +962,24 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
957 status = GNUNET_SYSERR; 962 status = GNUNET_SYSERR;
958 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 963 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
959 { 964 {
960 LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s not found\n"), filename); 965 LOG (GNUNET_ERROR_TYPE_ERROR,
966 _("Topology file %s not found\n"),
967 filename);
961 return; 968 return;
962 } 969 }
963 if (GNUNET_OK != 970 if (GNUNET_OK !=
964 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) 971 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
965 { 972 {
966 LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s has no data\n"), 973 LOG (GNUNET_ERROR_TYPE_ERROR,
974 _("Topology file %s has no data\n"),
967 filename); 975 filename);
968 return; 976 return;
969 } 977 }
970 data = GNUNET_malloc (fs); 978 data = GNUNET_malloc (fs);
971 if (fs != GNUNET_DISK_fn_read (filename, data, fs)) 979 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
972 { 980 {
973 LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s cannot be read\n"), 981 LOG (GNUNET_ERROR_TYPE_ERROR,
982 _("Topology file %s cannot be read\n"),
974 filename); 983 filename);
975 goto _exit; 984 goto _exit;
976 } 985 }
@@ -1048,9 +1057,9 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
1048 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 1057 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1049 { 1058 {
1050 struct TopologyContextOverlay *overlay; 1059 struct TopologyContextOverlay *overlay;
1051 1060
1052 overlay = &tc->u.overlay; 1061 overlay = &tc->u.overlay;
1053 overlay->link_array = 1062 overlay->link_array =
1054 GNUNET_realloc (overlay->link_array, 1063 GNUNET_realloc (overlay->link_array,
1055 sizeof (struct OverlayLink) * tc->link_array_size); 1064 sizeof (struct OverlayLink) * tc->link_array_size);
1056 } 1065 }
@@ -1058,7 +1067,7 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
1058 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 1067 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1059 { 1068 {
1060 struct TopologyContextUnderlay *underlay; 1069 struct TopologyContextUnderlay *underlay;
1061 1070
1062 underlay = &tc->u.underlay; 1071 underlay = &tc->u.underlay;
1063 underlay->link_array = 1072 underlay->link_array =
1064 GNUNET_realloc (underlay->link_array, 1073 GNUNET_realloc (underlay->link_array,
@@ -1071,7 +1080,8 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
1071 } 1080 }
1072 else 1081 else
1073 LOG (GNUNET_ERROR_TYPE_WARNING, 1082 LOG (GNUNET_ERROR_TYPE_WARNING,
1074 _("Ignoring to connect peer %u to peer %u\n"), peer_id, 1083 _("Ignoring to connect peer %u to peer %u\n"),
1084 peer_id,
1075 other_peer_id); 1085 other_peer_id);
1076 while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs)) 1086 while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs))
1077 offset++; 1087 offset++;
@@ -1091,14 +1101,15 @@ _exit:
1091 GNUNET_free (data); 1101 GNUNET_free (data);
1092 if (GNUNET_OK != status) 1102 if (GNUNET_OK != status)
1093 { 1103 {
1094 LOG (GNUNET_ERROR_TYPE_WARNING, "Removing link data read from the file\n"); 1104 LOG (GNUNET_ERROR_TYPE_WARNING,
1105 "Removing link data read from the file\n");
1095 tc->link_array_size = 0; 1106 tc->link_array_size = 0;
1096 switch (tc->type) 1107 switch (tc->type)
1097 { 1108 {
1098 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 1109 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1099 { 1110 {
1100 struct TopologyContextOverlay *overlay; 1111 struct TopologyContextOverlay *overlay;
1101 1112
1102 overlay = &tc->u.overlay; 1113 overlay = &tc->u.overlay;
1103 GNUNET_free_non_null (overlay->link_array); 1114 GNUNET_free_non_null (overlay->link_array);
1104 overlay->link_array = NULL; 1115 overlay->link_array = NULL;
@@ -1107,7 +1118,7 @@ _exit:
1107 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 1118 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1108 { 1119 {
1109 struct TopologyContextUnderlay *underlay; 1120 struct TopologyContextUnderlay *underlay;
1110 1121
1111 underlay = &tc->u.underlay; 1122 underlay = &tc->u.underlay;
1112 GNUNET_free_non_null (underlay->link_array); 1123 GNUNET_free_non_null (underlay->link_array);
1113 underlay->link_array = NULL; 1124 underlay->link_array = NULL;
@@ -1129,7 +1140,7 @@ gen_topo_clique (struct TopologyContext *tc)
1129 unsigned int cnt; 1140 unsigned int cnt;
1130 unsigned int offset; 1141 unsigned int offset;
1131 unsigned int neighbour; 1142 unsigned int neighbour;
1132 1143
1133 tc->link_array_size = tc->num_peers * (tc->num_peers - 1); 1144 tc->link_array_size = tc->num_peers * (tc->num_peers - 1);
1134 switch (tc->type) 1145 switch (tc->type)
1135 { 1146 {
@@ -1138,8 +1149,8 @@ gen_topo_clique (struct TopologyContext *tc)
1138 struct TopologyContextOverlay *overlay; 1149 struct TopologyContextOverlay *overlay;
1139 1150
1140 overlay = &tc->u.overlay; 1151 overlay = &tc->u.overlay;
1141 overlay->link_array = GNUNET_malloc (sizeof (struct OverlayLink) * 1152 overlay->link_array = GNUNET_new_array (tc->link_array_size,
1142 tc->link_array_size); 1153 struct OverlayLink);
1143 } 1154 }
1144 break; 1155 break;
1145 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 1156 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
@@ -1147,8 +1158,8 @@ gen_topo_clique (struct TopologyContext *tc)
1147 struct TopologyContextUnderlay *underlay; 1158 struct TopologyContextUnderlay *underlay;
1148 1159
1149 underlay = &tc->u.underlay; 1160 underlay = &tc->u.underlay;
1150 underlay->link_array = GNUNET_malloc (sizeof (struct UnderlayLink) * 1161 underlay->link_array = GNUNET_new_array (tc->link_array_size,
1151 tc->link_array_size); 1162 struct UnderlayLink);
1152 } 1163 }
1153 } 1164 }
1154 offset = 0; 1165 offset = 0;
@@ -1169,8 +1180,8 @@ gen_topo_clique (struct TopologyContext *tc)
1169 * Configure overall network topology to have a particular shape. 1180 * Configure overall network topology to have a particular shape.
1170 * 1181 *
1171 * @param op_cls closure argument to give with the operation event 1182 * @param op_cls closure argument to give with the operation event
1172 * @param num_peers number of peers in 'peers' 1183 * @param num_peers number of peers in @a peers
1173 * @param peers array of 'num_peers' with the peers to configure 1184 * @param peers array of @a num_peers with the peers to configure
1174 * @param topo desired underlay topology to use 1185 * @param topo desired underlay topology to use
1175 * @param ap topology-specific options 1186 * @param ap topology-specific options
1176 * @return handle to the operation, NULL if configuring the topology 1187 * @return handle to the operation, NULL if configuring the topology
@@ -1194,8 +1205,8 @@ GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1194 * Configure overall network topology to have a particular shape. 1205 * Configure overall network topology to have a particular shape.
1195 * 1206 *
1196 * @param op_cls closure argument to give with the operation event 1207 * @param op_cls closure argument to give with the operation event
1197 * @param num_peers number of peers in 'peers' 1208 * @param num_peers number of peers in @a peers
1198 * @param peers array of 'num_peers' with the peers to configure 1209 * @param peers array of @a num_peers with the peers to configure
1199 * @param topo desired underlay topology to use 1210 * @param topo desired underlay topology to use
1200 * @param ... topology-specific options 1211 * @param ... topology-specific options
1201 * @return handle to the operation, NULL if configuring the topology 1212 * @return handle to the operation, NULL if configuring the topology
@@ -1220,8 +1231,8 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1220 * 1231 *
1221 * @param op_cls closure argument to give with the peer connect operation events 1232 * @param op_cls closure argument to give with the peer connect operation events
1222 * generated through this function 1233 * generated through this function
1223 * @param num_peers number of peers in 'peers' 1234 * @param num_peers number of peers in @a peers
1224 * @param peers array of 'num_peers' with the peers to configure 1235 * @param peers array of @a num_peers with the peers to configure
1225 * @param max_connections the maximums number of overlay connections that will 1236 * @param max_connections the maximums number of overlay connections that will
1226 * be made to achieve the given topology 1237 * be made to achieve the given topology
1227 * @param comp_cb the completion callback to call when the topology generation 1238 * @param comp_cb the completion callback to call when the topology generation
@@ -1339,7 +1350,8 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1339 GNUNET_TESTBED_operation_queue_insert_ 1350 GNUNET_TESTBED_operation_queue_insert_
1340 (c->opq_parallel_topology_config_operations, op); 1351 (c->opq_parallel_topology_config_operations, op);
1341 GNUNET_TESTBED_operation_begin_wait_ (op); 1352 GNUNET_TESTBED_operation_begin_wait_ (op);
1342 LOG (GNUNET_ERROR_TYPE_DEBUG, "Generated %u connections\n", 1353 LOG (GNUNET_ERROR_TYPE_DEBUG,
1354 "Generated %u connections\n",
1343 tc->link_array_size); 1355 tc->link_array_size);
1344 if (NULL != max_connections) 1356 if (NULL != max_connections)
1345 *max_connections = tc->link_array_size; 1357 *max_connections = tc->link_array_size;
@@ -1399,8 +1411,8 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1399 * @param topology where to write the retrieved topology 1411 * @param topology where to write the retrieved topology
1400 * @param topology_string The string to attempt to 1412 * @param topology_string The string to attempt to
1401 * get a configuration value from 1413 * get a configuration value from
1402 * @return GNUNET_YES if topology string matched a 1414 * @return #GNUNET_YES if topology string matched a
1403 * known topology, GNUNET_NO if not 1415 * known topology, #GNUNET_NO if not
1404 */ 1416 */
1405int 1417int
1406GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, 1418GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
@@ -1444,14 +1456,14 @@ GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology)
1444 * generated 1456 * generated
1445 * @param proc the underlay link processor callback. Will be called for each 1457 * @param proc the underlay link processor callback. Will be called for each
1446 * underlay link generated unless a previous call to this callback 1458 * underlay link generated unless a previous call to this callback
1447 * returned GNUNET_SYSERR. Cannot be NULL. 1459 * returned #GNUNET_SYSERR. Cannot be NULL.
1448 * @param cls closure for proc 1460 * @param cls closure for @a proc
1449 * @param ... variable arguments denoting the topology and its parameters. They 1461 * @param ... variable arguments denoting the topology and its parameters. They
1450 * should start with the type of topology to generate followed by their 1462 * should start with the type of topology to generate followed by their
1451 * options. 1463 * options.
1452 * @return GNUNET_OK if underlay link generation is successful; GNUNET_SYSERR 1464 * @return #GNUNET_OK if underlay link generation is successful; #GNUNET_SYSERR
1453 * upon error in generating the underlay or if any calls to the 1465 * upon error in generating the underlay or if any calls to the
1454 * underlay link processor returned GNUNET_SYSERR 1466 * underlay link processor returned #GNUNET_SYSERR
1455 */ 1467 */
1456int 1468int
1457GNUNET_TESTBED_underlay_construct_ (int num_peers, 1469GNUNET_TESTBED_underlay_construct_ (int num_peers,
@@ -1466,7 +1478,7 @@ GNUNET_TESTBED_underlay_construct_ (int num_peers,
1466 enum GNUNET_TESTBED_TopologyOption topology; 1478 enum GNUNET_TESTBED_TopologyOption topology;
1467 unsigned int cnt; 1479 unsigned int cnt;
1468 int ret; 1480 int ret;
1469 1481
1470 GNUNET_assert (NULL != proc); 1482 GNUNET_assert (NULL != proc);
1471 ret = GNUNET_OK; 1483 ret = GNUNET_OK;
1472 memset (&tc, 0, sizeof (tc)); 1484 memset (&tc, 0, sizeof (tc));