diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-02-24 14:20:49 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-02-24 14:20:49 +0000 |
commit | 119990aed1a3f628196d98fc1da15a1ab3f4f3a9 (patch) | |
tree | 9c0cf280bc83a57c4665553d98cc1e7b34af901f /src/testing/testing_group.c | |
parent | fd05a2037c62f378febfb5ad8b4b6f2833b27d62 (diff) | |
download | gnunet-119990aed1a3f628196d98fc1da15a1ab3f4f3a9.tar.gz gnunet-119990aed1a3f628196d98fc1da15a1ab3f4f3a9.zip |
Indent, fix removal bug
Diffstat (limited to 'src/testing/testing_group.c')
-rw-r--r-- | src/testing/testing_group.c | 3165 |
1 files changed, 1572 insertions, 1593 deletions
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 45bbcd026..f1e5ba1e5 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -1,21 +1,21 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2008, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2008, 2009 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
@@ -82,16 +82,10 @@ enum PeerLists | |||
82 | * Prototype of a function called whenever two peers would be connected | 82 | * Prototype of a function called whenever two peers would be connected |
83 | * in a certain topology. | 83 | * in a certain topology. |
84 | */ | 84 | */ |
85 | typedef unsigned int (*GNUNET_TESTING_ConnectionProcessor) (struct | 85 | typedef unsigned int |
86 | GNUNET_TESTING_PeerGroup | 86 | (*GNUNET_TESTING_ConnectionProcessor)(struct GNUNET_TESTING_PeerGroup * pg, |
87 | * pg, | 87 | unsigned int first, unsigned int second, enum PeerLists list, |
88 | unsigned int | 88 | unsigned int check); |
89 | first, | ||
90 | unsigned int | ||
91 | second, | ||
92 | enum PeerLists list, | ||
93 | unsigned int check); | ||
94 | |||
95 | 89 | ||
96 | /** | 90 | /** |
97 | * Context for handling churning a peer group | 91 | * Context for handling churning a peer group |
@@ -163,7 +157,6 @@ struct RestartContext | |||
163 | 157 | ||
164 | }; | 158 | }; |
165 | 159 | ||
166 | |||
167 | struct SendHelloContext | 160 | struct SendHelloContext |
168 | { | 161 | { |
169 | /** | 162 | /** |
@@ -197,7 +190,6 @@ struct SendHelloContext | |||
197 | GNUNET_SCHEDULER_TaskIdentifier core_connect_task; | 190 | GNUNET_SCHEDULER_TaskIdentifier core_connect_task; |
198 | }; | 191 | }; |
199 | 192 | ||
200 | |||
201 | struct ShutdownContext | 193 | struct ShutdownContext |
202 | { | 194 | { |
203 | struct GNUNET_TESTING_PeerGroup *pg; | 195 | struct GNUNET_TESTING_PeerGroup *pg; |
@@ -271,7 +263,6 @@ struct PeerRestartContext | |||
271 | struct GNUNET_TESTING_Daemon *daemon; | 263 | struct GNUNET_TESTING_Daemon *daemon; |
272 | }; | 264 | }; |
273 | 265 | ||
274 | |||
275 | struct CreateTopologyContext | 266 | struct CreateTopologyContext |
276 | { | 267 | { |
277 | 268 | ||
@@ -301,7 +292,6 @@ enum States | |||
301 | OTHER_PEER_INDEX | 292 | OTHER_PEER_INDEX |
302 | }; | 293 | }; |
303 | 294 | ||
304 | |||
305 | #if OLD | 295 | #if OLD |
306 | struct PeerConnection | 296 | struct PeerConnection |
307 | { | 297 | { |
@@ -315,7 +305,6 @@ struct PeerConnection | |||
315 | */ | 305 | */ |
316 | struct PeerConnection *next; | 306 | struct PeerConnection *next; |
317 | 307 | ||
318 | |||
319 | /* | 308 | /* |
320 | * Index of daemon in pg->peers | 309 | * Index of daemon in pg->peers |
321 | */ | 310 | */ |
@@ -518,7 +507,6 @@ struct PeerData | |||
518 | struct InternalStartContext internal_context; | 507 | struct InternalStartContext internal_context; |
519 | }; | 508 | }; |
520 | 509 | ||
521 | |||
522 | /** | 510 | /** |
523 | * Linked list of per-host data. | 511 | * Linked list of per-host data. |
524 | */ | 512 | */ |
@@ -638,7 +626,6 @@ struct StatsCoreContext | |||
638 | struct GNUNET_STATISTICS_GetHandle *stats_get_handle; | 626 | struct GNUNET_STATISTICS_GetHandle *stats_get_handle; |
639 | }; | 627 | }; |
640 | 628 | ||
641 | |||
642 | struct ConnectTopologyContext | 629 | struct ConnectTopologyContext |
643 | { | 630 | { |
644 | /** | 631 | /** |
@@ -677,7 +664,6 @@ struct ConnectTopologyContext | |||
677 | void *notify_cls; | 664 | void *notify_cls; |
678 | }; | 665 | }; |
679 | 666 | ||
680 | |||
681 | /** | 667 | /** |
682 | * Handle to a group of GNUnet peers. | 668 | * Handle to a group of GNUnet peers. |
683 | */ | 669 | */ |
@@ -832,7 +818,6 @@ struct UpdateContext | |||
832 | unsigned int fdnum; | 818 | unsigned int fdnum; |
833 | }; | 819 | }; |
834 | 820 | ||
835 | |||
836 | struct ConnectContext | 821 | struct ConnectContext |
837 | { | 822 | { |
838 | /** | 823 | /** |
@@ -987,10 +972,10 @@ struct ProgressMeter | |||
987 | */ | 972 | */ |
988 | static void | 973 | static void |
989 | hash_from_uid (uint32_t uid, GNUNET_HashCode * hash) | 974 | hash_from_uid (uint32_t uid, GNUNET_HashCode * hash) |
990 | { | 975 | { |
991 | memset (hash, 0, sizeof (GNUNET_HashCode)); | 976 | memset (hash, 0, sizeof (GNUNET_HashCode)); |
992 | *((uint32_t *) hash) = uid; | 977 | *((uint32_t *) hash) = uid; |
993 | } | 978 | } |
994 | 979 | ||
995 | /** | 980 | /** |
996 | * Convert hash code to unique ID. | 981 | * Convert hash code to unique ID. |
@@ -1000,13 +985,15 @@ hash_from_uid (uint32_t uid, GNUNET_HashCode * hash) | |||
1000 | */ | 985 | */ |
1001 | static void | 986 | static void |
1002 | uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid) | 987 | uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid) |
1003 | { | 988 | { |
1004 | memcpy (uid, hash, sizeof (uint32_t)); | 989 | memcpy (uid, hash, sizeof (uint32_t)); |
1005 | } | 990 | } |
1006 | #endif | 991 | #endif |
1007 | 992 | ||
1008 | #if USE_SEND_HELLOS | 993 | #if USE_SEND_HELLOS |
1009 | static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} }; | 994 | static struct GNUNET_CORE_MessageHandler no_handlers[] = |
995 | { | ||
996 | { NULL, 0, 0}}; | ||
1010 | #endif | 997 | #endif |
1011 | 998 | ||
1012 | /** | 999 | /** |
@@ -1053,25 +1040,25 @@ update_meter(struct ProgressMeter *meter) | |||
1053 | { | 1040 | { |
1054 | if (meter->completed == 0) | 1041 | if (meter->completed == 0) |
1055 | { | 1042 | { |
1056 | fprintf(stdout, "%sProgress: [0%%", meter->startup_string); | 1043 | fprintf (stdout, "%sProgress: [0%%", meter->startup_string); |
1057 | } | 1044 | } |
1058 | else | 1045 | else |
1059 | fprintf(stdout, "%d%%", (int) (((float) meter->completed | 1046 | fprintf (stdout, "%d%%", (int) (((float) meter->completed |
1060 | / meter->total) * 100)); | 1047 | / meter->total) * 100)); |
1061 | } | 1048 | } |
1062 | else if (meter->completed % meter->dotnum == 0) | 1049 | else if (meter->completed % meter->dotnum == 0) |
1063 | fprintf(stdout, "."); | 1050 | fprintf (stdout, "."); |
1064 | 1051 | ||
1065 | if (meter->completed + 1 == meter->total) | 1052 | if (meter->completed + 1 == meter->total) |
1066 | fprintf(stdout, "%d%%]\n", 100); | 1053 | fprintf (stdout, "%d%%]\n", 100); |
1067 | fflush(stdout); | 1054 | fflush (stdout); |
1068 | } | 1055 | } |
1069 | meter->completed++; | 1056 | meter->completed++; |
1070 | 1057 | ||
1071 | if (meter->completed == meter->total) | 1058 | if (meter->completed == meter->total) |
1072 | return GNUNET_YES; | 1059 | return GNUNET_YES; |
1073 | if (meter->completed > meter->total) | 1060 | if (meter->completed > meter->total) |
1074 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n"); | 1061 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n"); |
1075 | return GNUNET_NO; | 1062 | return GNUNET_NO; |
1076 | } | 1063 | } |
1077 | 1064 | ||
@@ -1115,71 +1102,71 @@ free_meter(struct ProgressMeter *meter) | |||
1115 | * known topology, GNUNET_NO if not | 1102 | * known topology, GNUNET_NO if not |
1116 | */ | 1103 | */ |
1117 | int | 1104 | int |
1118 | GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology, | 1105 | GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, |
1119 | const char *topology_string) | 1106 | const char *topology_string) |
1120 | { | 1107 | { |
1121 | /** | 1108 | /** |
1122 | * Strings representing topologies in enum | 1109 | * Strings representing topologies in enum |
1123 | */ | 1110 | */ |
1124 | static const char *topology_strings[] = { | 1111 | static const char *topology_strings[] = |
1125 | /** | 1112 | { |
1126 | * A clique (everyone connected to everyone else). | 1113 | /** |
1127 | */ | 1114 | * A clique (everyone connected to everyone else). |
1115 | */ | ||
1128 | "CLIQUE", | 1116 | "CLIQUE", |
1129 | 1117 | ||
1130 | /** | 1118 | /** |
1131 | * Small-world network (2d torus plus random links). | 1119 | * Small-world network (2d torus plus random links). |
1132 | */ | 1120 | */ |
1133 | "SMALL_WORLD", | 1121 | "SMALL_WORLD", |
1134 | 1122 | ||
1135 | /** | 1123 | /** |
1136 | * Small-world network (ring plus random links). | 1124 | * Small-world network (ring plus random links). |
1137 | */ | 1125 | */ |
1138 | "SMALL_WORLD_RING", | 1126 | "SMALL_WORLD_RING", |
1139 | 1127 | ||
1140 | /** | 1128 | /** |
1141 | * Ring topology. | 1129 | * Ring topology. |
1142 | */ | 1130 | */ |
1143 | "RING", | 1131 | "RING", |
1144 | 1132 | ||
1145 | /** | 1133 | /** |
1146 | * 2-d torus. | 1134 | * 2-d torus. |
1147 | */ | 1135 | */ |
1148 | "2D_TORUS", | 1136 | "2D_TORUS", |
1149 | 1137 | ||
1150 | /** | 1138 | /** |
1151 | * Random graph. | 1139 | * Random graph. |
1152 | */ | 1140 | */ |
1153 | "ERDOS_RENYI", | 1141 | "ERDOS_RENYI", |
1154 | 1142 | ||
1155 | /** | 1143 | /** |
1156 | * Certain percentage of peers are unable to communicate directly | 1144 | * Certain percentage of peers are unable to communicate directly |
1157 | * replicating NAT conditions | 1145 | * replicating NAT conditions |
1158 | */ | 1146 | */ |
1159 | "INTERNAT", | 1147 | "INTERNAT", |
1160 | 1148 | ||
1161 | /** | 1149 | /** |
1162 | * Scale free topology. | 1150 | * Scale free topology. |
1163 | */ | 1151 | */ |
1164 | "SCALE_FREE", | 1152 | "SCALE_FREE", |
1165 | 1153 | ||
1166 | /** | 1154 | /** |
1167 | * Straight line topology. | 1155 | * Straight line topology. |
1168 | */ | 1156 | */ |
1169 | "LINE", | 1157 | "LINE", |
1170 | 1158 | ||
1171 | /** | 1159 | /** |
1172 | * All peers are disconnected. | 1160 | * All peers are disconnected. |
1173 | */ | 1161 | */ |
1174 | "NONE", | 1162 | "NONE", |
1175 | 1163 | ||
1176 | /** | 1164 | /** |
1177 | * Read the topology from a file. | 1165 | * Read the topology from a file. |
1178 | */ | 1166 | */ |
1179 | "FROM_FILE", | 1167 | "FROM_FILE", |
1180 | 1168 | ||
1181 | NULL | 1169 | NULL }; |
1182 | }; | ||
1183 | 1170 | ||
1184 | int curr = 0; | 1171 | int curr = 0; |
1185 | if (topology_string == NULL) | 1172 | if (topology_string == NULL) |
@@ -1197,7 +1184,6 @@ GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology, | |||
1197 | return GNUNET_NO; | 1184 | return GNUNET_NO; |
1198 | } | 1185 | } |
1199 | 1186 | ||
1200 | |||
1201 | /** | 1187 | /** |
1202 | * Get connect topology option from string input. | 1188 | * Get connect topology option from string input. |
1203 | * | 1189 | * |
@@ -1208,51 +1194,51 @@ GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology, | |||
1208 | * topology option, GNUNET_NO if not | 1194 | * topology option, GNUNET_NO if not |
1209 | */ | 1195 | */ |
1210 | int | 1196 | int |
1211 | GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption | 1197 | GNUNET_TESTING_topology_option_get( |
1212 | *topology_option, | 1198 | enum GNUNET_TESTING_TopologyOption *topology_option, |
1213 | const char *topology_string) | 1199 | const char *topology_string) |
1214 | { | 1200 | { |
1215 | /** | 1201 | /** |
1216 | * Options for connecting a topology as strings. | 1202 | * Options for connecting a topology as strings. |
1217 | */ | 1203 | */ |
1218 | static const char *topology_option_strings[] = { | 1204 | static const char *topology_option_strings[] = |
1219 | /** | 1205 | { |
1220 | * Try to connect all peers specified in the topology. | 1206 | /** |
1221 | */ | 1207 | * Try to connect all peers specified in the topology. |
1208 | */ | ||
1222 | "CONNECT_ALL", | 1209 | "CONNECT_ALL", |
1223 | 1210 | ||
1224 | /** | 1211 | /** |
1225 | * Choose a random subset of connections to create. | 1212 | * Choose a random subset of connections to create. |
1226 | */ | 1213 | */ |
1227 | "CONNECT_RANDOM_SUBSET", | 1214 | "CONNECT_RANDOM_SUBSET", |
1228 | 1215 | ||
1229 | /** | 1216 | /** |
1230 | * Create at least X connections for each peer. | 1217 | * Create at least X connections for each peer. |
1231 | */ | 1218 | */ |
1232 | "CONNECT_MINIMUM", | 1219 | "CONNECT_MINIMUM", |
1233 | 1220 | ||
1234 | /** | 1221 | /** |
1235 | * Using a depth first search, create one connection | 1222 | * Using a depth first search, create one connection |
1236 | * per peer. If any are missed (graph disconnected) | 1223 | * per peer. If any are missed (graph disconnected) |
1237 | * start over at those peers until all have at least one | 1224 | * start over at those peers until all have at least one |
1238 | * connection. | 1225 | * connection. |
1239 | */ | 1226 | */ |
1240 | "CONNECT_DFS", | 1227 | "CONNECT_DFS", |
1241 | 1228 | ||
1242 | /** | 1229 | /** |
1243 | * Find the N closest peers to each allowed peer in the | 1230 | * Find the N closest peers to each allowed peer in the |
1244 | * topology and make sure a connection to those peers | 1231 | * topology and make sure a connection to those peers |
1245 | * exists in the connect topology. | 1232 | * exists in the connect topology. |
1246 | */ | 1233 | */ |
1247 | "CONNECT_CLOSEST", | 1234 | "CONNECT_CLOSEST", |
1248 | 1235 | ||
1249 | /** | 1236 | /** |
1250 | * No options specified. | 1237 | * No options specified. |
1251 | */ | 1238 | */ |
1252 | "CONNECT_NONE", | 1239 | "CONNECT_NONE", |
1253 | 1240 | ||
1254 | NULL | 1241 | NULL }; |
1255 | }; | ||
1256 | int curr = 0; | 1242 | int curr = 0; |
1257 | 1243 | ||
1258 | if (topology_string == NULL) | 1244 | if (topology_string == NULL) |
@@ -1281,8 +1267,8 @@ GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption | |||
1281 | * @param value value of the option | 1267 | * @param value value of the option |
1282 | */ | 1268 | */ |
1283 | static void | 1269 | static void |
1284 | update_config (void *cls, | 1270 | update_config(void *cls, const char *section, const char *option, |
1285 | const char *section, const char *option, const char *value) | 1271 | const char *value) |
1286 | { | 1272 | { |
1287 | struct UpdateContext *ctx = cls; | 1273 | struct UpdateContext *ctx = cls; |
1288 | unsigned int ival; | 1274 | unsigned int ival; |
@@ -1297,47 +1283,44 @@ update_config (void *cls, | |||
1297 | 1283 | ||
1298 | if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) | 1284 | if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) |
1299 | { | 1285 | { |
1300 | if ((ival != 0) && | 1286 | if ((ival != 0) && (GNUNET_YES |
1301 | (GNUNET_YES != | 1287 | != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", |
1302 | GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", | 1288 | single_variable))) |
1303 | single_variable))) | ||
1304 | { | 1289 | { |
1305 | GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++); | 1290 | GNUNET_snprintf (cval, sizeof(cval), "%u", ctx->nport++); |
1306 | value = cval; | 1291 | value = cval; |
1307 | } | 1292 | } |
1308 | else if ((ival != 0) && | 1293 | else if ((ival != 0) && (GNUNET_YES |
1309 | (GNUNET_YES == | 1294 | == GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", |
1310 | GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", | 1295 | single_variable)) |
1311 | single_variable)) && | 1296 | && GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", |
1312 | GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", | 1297 | per_host_variable, |
1313 | per_host_variable, | 1298 | &num_per_host)) |
1314 | &num_per_host)) | ||
1315 | { | 1299 | { |
1316 | GNUNET_snprintf (cval, sizeof (cval), "%u", ival + ctx->fdnum % num_per_host); | 1300 | GNUNET_snprintf (cval, sizeof(cval), "%u", ival + ctx->fdnum |
1301 | % num_per_host); | ||
1317 | value = cval; | 1302 | value = cval; |
1318 | } | 1303 | } |
1319 | } | 1304 | } |
1320 | 1305 | ||
1321 | if (0 == strcmp (option, "UNIXPATH")) | 1306 | if (0 == strcmp (option, "UNIXPATH")) |
1322 | { | 1307 | { |
1323 | if (GNUNET_YES != | 1308 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, |
1324 | GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", | 1309 | "testing", |
1325 | single_variable)) | 1310 | single_variable)) |
1326 | { | 1311 | { |
1327 | GNUNET_snprintf (uval, | 1312 | GNUNET_snprintf (uval, sizeof(uval), "/tmp/test-service-%s-%u", |
1328 | sizeof (uval), | 1313 | section, ctx->upnum++); |
1329 | "/tmp/test-service-%s-%u", section, ctx->upnum++); | ||
1330 | value = uval; | 1314 | value = uval; |
1331 | } | 1315 | } |
1332 | else if ((GNUNET_YES == | 1316 | else if ((GNUNET_YES |
1333 | GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", | 1317 | == GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", |
1334 | per_host_variable, | 1318 | per_host_variable, |
1335 | &num_per_host)) && (num_per_host > 0)) | 1319 | &num_per_host)) |
1320 | && (num_per_host > 0)) | ||
1336 | 1321 | ||
1337 | { | 1322 | { |
1338 | GNUNET_snprintf (uval, | 1323 | GNUNET_snprintf (uval, sizeof(uval), "/tmp/test-service-%s-%u", |
1339 | sizeof (uval), | ||
1340 | "/tmp/test-service-%s-%u", | ||
1341 | section, ctx->fdnum % num_per_host); | 1324 | section, ctx->fdnum % num_per_host); |
1342 | value = uval; | 1325 | value = uval; |
1343 | } | 1326 | } |
@@ -1352,7 +1335,6 @@ update_config (void *cls, | |||
1352 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, option, value); | 1335 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, option, value); |
1353 | } | 1336 | } |
1354 | 1337 | ||
1355 | |||
1356 | /** | 1338 | /** |
1357 | * Create a new configuration using the given configuration | 1339 | * Create a new configuration using the given configuration |
1358 | * as a template; however, each PORT in the existing cfg | 1340 | * as a template; however, each PORT in the existing cfg |
@@ -1371,11 +1353,8 @@ update_config (void *cls, | |||
1371 | * @return new configuration, NULL on error | 1353 | * @return new configuration, NULL on error |
1372 | */ | 1354 | */ |
1373 | static struct GNUNET_CONFIGURATION_Handle * | 1355 | static struct GNUNET_CONFIGURATION_Handle * |
1374 | make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1356 | make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, |
1375 | uint32_t off, | 1357 | uint16_t * port, uint32_t * upnum, const char *hostname, uint32_t * fdnum) |
1376 | uint16_t * port, | ||
1377 | uint32_t * upnum, const char *hostname, | ||
1378 | uint32_t * fdnum) | ||
1379 | { | 1358 | { |
1380 | struct UpdateContext uc; | 1359 | struct UpdateContext uc; |
1381 | uint16_t orig; | 1360 | uint16_t orig; |
@@ -1398,8 +1377,8 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1398 | return NULL; | 1377 | return NULL; |
1399 | } | 1378 | } |
1400 | 1379 | ||
1401 | if (GNUNET_CONFIGURATION_get_value_string | 1380 | if (GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "control_host", |
1402 | (cfg, "testing", "control_host", &control_host) == GNUNET_OK) | 1381 | &control_host) == GNUNET_OK) |
1403 | { | 1382 | { |
1404 | if (hostname != NULL) | 1383 | if (hostname != NULL) |
1405 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host, | 1384 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host, |
@@ -1417,34 +1396,35 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1417 | "ACCEPT_FROM", allowed_hosts); | 1396 | "ACCEPT_FROM", allowed_hosts); |
1418 | 1397 | ||
1419 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", ""); | 1398 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", ""); |
1420 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH", ""); | 1399 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH", |
1400 | ""); | ||
1421 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "UNIXPATH", ""); | 1401 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "UNIXPATH", ""); |
1422 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "UNIXPATH", ""); | 1402 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "UNIXPATH", |
1403 | ""); | ||
1423 | 1404 | ||
1424 | GNUNET_free_non_null (control_host); | 1405 | GNUNET_free_non_null (control_host); |
1425 | GNUNET_free (allowed_hosts); | 1406 | GNUNET_free (allowed_hosts); |
1426 | } | 1407 | } |
1427 | 1408 | ||
1428 | |||
1429 | /* arm needs to know to allow connections from the host on which it is running, | 1409 | /* arm needs to know to allow connections from the host on which it is running, |
1430 | * otherwise gnunet-arm is unable to connect to it in some instances */ | 1410 | * otherwise gnunet-arm is unable to connect to it in some instances */ |
1431 | if (hostname != NULL) | 1411 | if (hostname != NULL) |
1432 | { | 1412 | { |
1433 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", hostname); | 1413 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", hostname); |
1434 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", | 1414 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "BINDTO", |
1435 | "BINDTO", hostname); | 1415 | hostname); |
1436 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", | 1416 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "BINDTO", |
1437 | "BINDTO", hostname); | 1417 | hostname); |
1438 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "arm", "ACCEPT_FROM", | 1418 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "arm", "ACCEPT_FROM", |
1439 | allowed_hosts); | 1419 | allowed_hosts); |
1440 | GNUNET_free (allowed_hosts); | 1420 | GNUNET_free (allowed_hosts); |
1441 | } | 1421 | } |
1442 | else | 1422 | else |
1443 | { | 1423 | { |
1444 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", | 1424 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "BINDTO", |
1445 | "BINDTO", "127.0.0.1"); | 1425 | "127.0.0.1"); |
1446 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", | 1426 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "BINDTO", |
1447 | "BINDTO", "127.0.0.1"); | 1427 | "127.0.0.1"); |
1448 | } | 1428 | } |
1449 | 1429 | ||
1450 | *port = (uint16_t) uc.nport; | 1430 | *port = (uint16_t) uc.nport; |
@@ -1467,9 +1447,8 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1467 | * | 1447 | * |
1468 | */ | 1448 | */ |
1469 | static unsigned int | 1449 | static unsigned int |
1470 | remove_connections (struct GNUNET_TESTING_PeerGroup *pg, | 1450 | remove_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, |
1471 | unsigned int first, unsigned int second, | 1451 | unsigned int second, enum PeerLists list, unsigned int check) |
1472 | enum PeerLists list, unsigned int check) | ||
1473 | { | 1452 | { |
1474 | int removed; | 1453 | int removed; |
1475 | #if OLD | 1454 | #if OLD |
@@ -1491,7 +1470,7 @@ remove_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1491 | removed = 0; | 1470 | removed = 0; |
1492 | #if OLD | 1471 | #if OLD |
1493 | switch (list) | 1472 | switch (list) |
1494 | { | 1473 | { |
1495 | case ALLOWED: | 1474 | case ALLOWED: |
1496 | first_list = &pg->peers[first].allowed_peers_head; | 1475 | first_list = &pg->peers[first].allowed_peers_head; |
1497 | second_list = &pg->peers[second].allowed_peers_head; | 1476 | second_list = &pg->peers[second].allowed_peers_head; |
@@ -1519,7 +1498,7 @@ remove_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1519 | default: | 1498 | default: |
1520 | GNUNET_break(0); | 1499 | GNUNET_break(0); |
1521 | return 0; | 1500 | return 0; |
1522 | } | 1501 | } |
1523 | 1502 | ||
1524 | first_iter = *first_list; | 1503 | first_iter = *first_list; |
1525 | while (first_iter != NULL) | 1504 | while (first_iter != NULL) |
@@ -1549,18 +1528,18 @@ remove_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1549 | #else | 1528 | #else |
1550 | if (GNUNET_YES == | 1529 | if (GNUNET_YES == |
1551 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].blacklisted_peers, | 1530 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].blacklisted_peers, |
1552 | &hash_second)) | 1531 | &hash_second)) |
1553 | { | 1532 | { |
1554 | GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[first].blacklisted_peers, | 1533 | GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[first].blacklisted_peers, |
1555 | &hash_second); | 1534 | &hash_second); |
1556 | } | 1535 | } |
1557 | 1536 | ||
1558 | if (GNUNET_YES == | 1537 | if (GNUNET_YES == |
1559 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].blacklisted_peers, | 1538 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].blacklisted_peers, |
1560 | &hash_first)) | 1539 | &hash_first)) |
1561 | { | 1540 | { |
1562 | GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[second].blacklisted_peers, | 1541 | GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[second].blacklisted_peers, |
1563 | &hash_first); | 1542 | &hash_first); |
1564 | } | 1543 | } |
1565 | #endif | 1544 | #endif |
1566 | 1545 | ||
@@ -1581,10 +1560,8 @@ remove_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1581 | * | 1560 | * |
1582 | */ | 1561 | */ |
1583 | static unsigned int | 1562 | static unsigned int |
1584 | add_connections (struct GNUNET_TESTING_PeerGroup *pg, | 1563 | add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, |
1585 | unsigned int first, unsigned int second, | 1564 | unsigned int second, enum PeerLists list, unsigned int check) |
1586 | enum PeerLists list, | ||
1587 | unsigned int check) | ||
1588 | { | 1565 | { |
1589 | int added; | 1566 | int added; |
1590 | int add_first; | 1567 | int add_first; |
@@ -1608,7 +1585,7 @@ add_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1608 | 1585 | ||
1609 | #if OLD | 1586 | #if OLD |
1610 | switch (list) | 1587 | switch (list) |
1611 | { | 1588 | { |
1612 | case ALLOWED: | 1589 | case ALLOWED: |
1613 | first_list = &pg->peers[first].allowed_peers_head; | 1590 | first_list = &pg->peers[first].allowed_peers_head; |
1614 | second_list = &pg->peers[second].allowed_peers_head; | 1591 | second_list = &pg->peers[second].allowed_peers_head; |
@@ -1636,7 +1613,7 @@ add_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1636 | default: | 1613 | default: |
1637 | GNUNET_break(0); | 1614 | GNUNET_break(0); |
1638 | return 0; | 1615 | return 0; |
1639 | } | 1616 | } |
1640 | 1617 | ||
1641 | add_first = GNUNET_YES; | 1618 | add_first = GNUNET_YES; |
1642 | add_second = GNUNET_YES; | 1619 | add_second = GNUNET_YES; |
@@ -1668,14 +1645,14 @@ add_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1668 | #else | 1645 | #else |
1669 | if (GNUNET_NO == | 1646 | if (GNUNET_NO == |
1670 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].blacklisted_peers, | 1647 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].blacklisted_peers, |
1671 | &hash_second)) | 1648 | &hash_second)) |
1672 | { | 1649 | { |
1673 | add_first = GNUNET_YES; | 1650 | add_first = GNUNET_YES; |
1674 | } | 1651 | } |
1675 | 1652 | ||
1676 | if (GNUNET_NO == | 1653 | if (GNUNET_NO == |
1677 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].blacklisted_peers, | 1654 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].blacklisted_peers, |
1678 | &hash_first)) | 1655 | &hash_first)) |
1679 | { | 1656 | { |
1680 | add_second = GNUNET_YES; | 1657 | add_second = GNUNET_YES; |
1681 | } | 1658 | } |
@@ -1690,13 +1667,13 @@ add_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1690 | GNUNET_CONTAINER_DLL_insert(*first_list, *first_tail, new_first); | 1667 | GNUNET_CONTAINER_DLL_insert(*first_list, *first_tail, new_first); |
1691 | #else | 1668 | #else |
1692 | GNUNET_assert (GNUNET_OK == | 1669 | GNUNET_assert (GNUNET_OK == |
1693 | GNUNET_CONTAINER_multihashmap_put (pg-> | 1670 | GNUNET_CONTAINER_multihashmap_put (pg-> |
1694 | peers | 1671 | peers |
1695 | [first].blacklisted_peers, | 1672 | [first].blacklisted_peers, |
1696 | &hash_second, | 1673 | &hash_second, |
1697 | pg-> | 1674 | pg-> |
1698 | peers[second].daemon, | 1675 | peers[second].daemon, |
1699 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1676 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1700 | #endif | 1677 | #endif |
1701 | pg->peers[first].num_connections++; | 1678 | pg->peers[first].num_connections++; |
1702 | added++; | 1679 | added++; |
@@ -1710,13 +1687,13 @@ add_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1710 | GNUNET_CONTAINER_DLL_insert(*second_list, *second_tail, new_second); | 1687 | GNUNET_CONTAINER_DLL_insert(*second_list, *second_tail, new_second); |
1711 | #else | 1688 | #else |
1712 | GNUNET_assert (GNUNET_OK == | 1689 | GNUNET_assert (GNUNET_OK == |
1713 | GNUNET_CONTAINER_multihashmap_put (pg-> | 1690 | GNUNET_CONTAINER_multihashmap_put (pg-> |
1714 | peers | 1691 | peers |
1715 | [second].blacklisted_peers, | 1692 | [second].blacklisted_peers, |
1716 | &hash_first, | 1693 | &hash_first, |
1717 | pg-> | 1694 | pg-> |
1718 | peers[first].daemon, | 1695 | peers[first].daemon, |
1719 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1696 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1720 | #endif | 1697 | #endif |
1721 | pg->peers[second].num_connections++; | 1698 | pg->peers[second].num_connections++; |
1722 | added++; | 1699 | added++; |
@@ -1725,7 +1702,6 @@ add_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1725 | return added; | 1702 | return added; |
1726 | } | 1703 | } |
1727 | 1704 | ||
1728 | |||
1729 | /** | 1705 | /** |
1730 | * Scale free network construction as described in: | 1706 | * Scale free network construction as described in: |
1731 | * | 1707 | * |
@@ -1743,8 +1719,8 @@ add_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
1743 | * @return the number of connections created | 1719 | * @return the number of connections created |
1744 | */ | 1720 | */ |
1745 | static unsigned int | 1721 | static unsigned int |
1746 | create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, | 1722 | create_scale_free(struct GNUNET_TESTING_PeerGroup *pg, |
1747 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 1723 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1748 | { | 1724 | { |
1749 | 1725 | ||
1750 | unsigned int total_connections; | 1726 | unsigned int total_connections; |
@@ -1764,23 +1740,22 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, | |||
1764 | previous_total_connections = total_connections; | 1740 | previous_total_connections = total_connections; |
1765 | for (i = 0; i < outer_count; i++) | 1741 | for (i = 0; i < outer_count; i++) |
1766 | { | 1742 | { |
1767 | probability = | 1743 | probability = pg->peers[i].num_connections |
1768 | pg->peers[i].num_connections / | 1744 | / (double) previous_total_connections; |
1769 | (double) previous_total_connections; | 1745 | random |
1770 | random = | 1746 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1771 | ((double) | 1747 | UINT64_MAX)) |
1772 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1748 | / ((double) UINT64_MAX); |
1773 | UINT64_MAX)) / ((double) UINT64_MAX); | ||
1774 | #if VERBOSE_TESTING | 1749 | #if VERBOSE_TESTING |
1775 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1750 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1776 | "Considering connecting peer %d to peer %d\n", | 1751 | "Considering connecting peer %d to peer %d\n", |
1777 | outer_count, i); | 1752 | outer_count, i); |
1778 | #endif | 1753 | #endif |
1779 | if (random < probability) | 1754 | if (random < probability) |
1780 | { | 1755 | { |
1781 | #if VERBOSE_TESTING | 1756 | #if VERBOSE_TESTING |
1782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1783 | "Connecting peer %d to peer %d\n", outer_count, i); | 1758 | "Connecting peer %d to peer %d\n", outer_count, i); |
1784 | #endif | 1759 | #endif |
1785 | total_connections += proc (pg, outer_count, i, list, GNUNET_YES); | 1760 | total_connections += proc (pg, outer_count, i, list, GNUNET_YES); |
1786 | } | 1761 | } |
@@ -1818,8 +1793,8 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, | |||
1818 | * | 1793 | * |
1819 | */ | 1794 | */ |
1820 | static unsigned int | 1795 | static unsigned int |
1821 | create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, | 1796 | create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, |
1822 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 1797 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1823 | { | 1798 | { |
1824 | unsigned int i, j; | 1799 | unsigned int i, j; |
1825 | int nodeToConnect; | 1800 | int nodeToConnect; |
@@ -1834,27 +1809,27 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, | |||
1834 | unsigned int useAnd; | 1809 | unsigned int useAnd; |
1835 | int connect_attempts; | 1810 | int connect_attempts; |
1836 | 1811 | ||
1837 | logNModifier = 0.5; /* FIXME: default value? */ | 1812 | logNModifier = 0.5; /* FIXME: default value? */ |
1838 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, | 1813 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
1839 | "TESTING", | ||
1840 | "PERCENTAGE", | 1814 | "PERCENTAGE", |
1841 | &p_string)) | 1815 | &p_string)) |
1842 | { | 1816 | { |
1843 | if (sscanf (p_string, "%lf", &logNModifier) != 1) | 1817 | if (sscanf (p_string, "%lf", &logNModifier) != 1) |
1844 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1818 | GNUNET_log ( |
1819 | GNUNET_ERROR_TYPE_WARNING, | ||
1845 | _ | 1820 | _ |
1846 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1821 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1847 | p_string, "LOGNMODIFIER", "TESTING"); | 1822 | p_string, "LOGNMODIFIER", "TESTING"); |
1848 | GNUNET_free (p_string); | 1823 | GNUNET_free (p_string); |
1849 | } | 1824 | } |
1850 | probability = 0.5; /* FIXME: default percentage? */ | 1825 | probability = 0.5; /* FIXME: default percentage? */ |
1851 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, | 1826 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
1852 | "TESTING", | ||
1853 | "PROBABILITY", | 1827 | "PROBABILITY", |
1854 | &p_string)) | 1828 | &p_string)) |
1855 | { | 1829 | { |
1856 | if (sscanf (p_string, "%lf", &probability) != 1) | 1830 | if (sscanf (p_string, "%lf", &probability) != 1) |
1857 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1831 | GNUNET_log ( |
1832 | GNUNET_ERROR_TYPE_WARNING, | ||
1858 | _ | 1833 | _ |
1859 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1834 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1860 | p_string, "PERCENTAGE", "TESTING"); | 1835 | p_string, "PERCENTAGE", "TESTING"); |
@@ -1866,7 +1841,8 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, | |||
1866 | if (connsPerPeer % 2 == 1) | 1841 | if (connsPerPeer % 2 == 1) |
1867 | connsPerPeer += 1; | 1842 | connsPerPeer += 1; |
1868 | 1843 | ||
1869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Target is %d connections per peer."), connsPerPeer); | 1844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Target is %d connections per peer."), |
1845 | connsPerPeer); | ||
1870 | 1846 | ||
1871 | smallWorldConnections = 0; | 1847 | smallWorldConnections = 0; |
1872 | connect_attempts = 0; | 1848 | connect_attempts = 0; |
@@ -1890,26 +1866,26 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, | |||
1890 | 1866 | ||
1891 | for (j = 0; j < connsPerPeer / 2; j++) | 1867 | for (j = 0; j < connsPerPeer / 2; j++) |
1892 | { | 1868 | { |
1893 | random = | 1869 | random |
1894 | ((double) | 1870 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1895 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1871 | UINT64_MAX) |
1896 | UINT64_MAX) / ((double) UINT64_MAX)); | 1872 | / ((double) UINT64_MAX)); |
1897 | if (random < probability) | 1873 | if (random < probability) |
1898 | { | 1874 | { |
1899 | /* Connect to uniformly selected random peer */ | 1875 | /* Connect to uniformly selected random peer */ |
1900 | randomPeer = | 1876 | randomPeer |
1901 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1877 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1902 | pg->total); | ||
1903 | while ((((randomPeer < max) && (randomPeer > min)) | ||
1904 | && (useAnd == 0)) || (((randomPeer > min) | ||
1905 | || (randomPeer < max)) | ||
1906 | && (useAnd == 1))) | ||
1907 | { | ||
1908 | randomPeer = | ||
1909 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1910 | pg->total); | 1878 | pg->total); |
1879 | while ((((randomPeer < max) && (randomPeer > min)) && (useAnd | ||
1880 | == 0)) || (((randomPeer > min) || (randomPeer < max)) | ||
1881 | && (useAnd == 1))) | ||
1882 | { | ||
1883 | randomPeer | ||
1884 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1885 | pg->total); | ||
1911 | } | 1886 | } |
1912 | smallWorldConnections += proc (pg, i, randomPeer, list, GNUNET_YES); | 1887 | smallWorldConnections += proc (pg, i, randomPeer, list, |
1888 | GNUNET_YES); | ||
1913 | } | 1889 | } |
1914 | else | 1890 | else |
1915 | { | 1891 | { |
@@ -1942,8 +1918,8 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, | |||
1942 | * | 1918 | * |
1943 | */ | 1919 | */ |
1944 | static unsigned int | 1920 | static unsigned int |
1945 | create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, | 1921 | create_nated_internet(struct GNUNET_TESTING_PeerGroup *pg, |
1946 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 1922 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1947 | { | 1923 | { |
1948 | unsigned int outer_count, inner_count; | 1924 | unsigned int outer_count, inner_count; |
1949 | unsigned int cutoff; | 1925 | unsigned int cutoff; |
@@ -1951,14 +1927,14 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, | |||
1951 | double nat_percentage; | 1927 | double nat_percentage; |
1952 | char *p_string; | 1928 | char *p_string; |
1953 | 1929 | ||
1954 | nat_percentage = 0.6; /* FIXME: default percentage? */ | 1930 | nat_percentage = 0.6; /* FIXME: default percentage? */ |
1955 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, | 1931 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
1956 | "TESTING", | ||
1957 | "PERCENTAGE", | 1932 | "PERCENTAGE", |
1958 | &p_string)) | 1933 | &p_string)) |
1959 | { | 1934 | { |
1960 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) | 1935 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) |
1961 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1936 | GNUNET_log ( |
1937 | GNUNET_ERROR_TYPE_WARNING, | ||
1962 | _ | 1938 | _ |
1963 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1939 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1964 | p_string, "PERCENTAGE", "TESTING"); | 1940 | p_string, "PERCENTAGE", "TESTING"); |
@@ -1969,17 +1945,17 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, | |||
1969 | connect_attempts = 0; | 1945 | connect_attempts = 0; |
1970 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 1946 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
1971 | { | 1947 | { |
1972 | for (inner_count = outer_count + 1; inner_count < pg->total; | 1948 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) |
1973 | inner_count++) | ||
1974 | { | 1949 | { |
1975 | if ((outer_count > cutoff) || (inner_count > cutoff)) | 1950 | if ((outer_count > cutoff) || (inner_count > cutoff)) |
1976 | { | 1951 | { |
1977 | #if VERBOSE_TESTING | 1952 | #if VERBOSE_TESTING |
1978 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1953 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1979 | "Connecting peer %d to peer %d\n", | 1954 | "Connecting peer %d to peer %d\n", |
1980 | outer_count, inner_count); | 1955 | outer_count, inner_count); |
1981 | #endif | 1956 | #endif |
1982 | connect_attempts += proc (pg, outer_count, inner_count, list, GNUNET_YES); | 1957 | connect_attempts += proc (pg, outer_count, inner_count, list, |
1958 | GNUNET_YES); | ||
1983 | } | 1959 | } |
1984 | } | 1960 | } |
1985 | } | 1961 | } |
@@ -2000,9 +1976,8 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, | |||
2000 | * | 1976 | * |
2001 | */ | 1977 | */ |
2002 | static unsigned int | 1978 | static unsigned int |
2003 | create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg, | 1979 | create_nated_internet_copy(struct GNUNET_TESTING_PeerGroup *pg, |
2004 | GNUNET_TESTING_ConnectionProcessor proc, | 1980 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2005 | enum PeerLists list) | ||
2006 | { | 1981 | { |
2007 | unsigned int outer_count, inner_count; | 1982 | unsigned int outer_count, inner_count; |
2008 | unsigned int cutoff; | 1983 | unsigned int cutoff; |
@@ -2012,14 +1987,14 @@ create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg, | |||
2012 | unsigned int count; | 1987 | unsigned int count; |
2013 | struct ProgressMeter *conn_meter; | 1988 | struct ProgressMeter *conn_meter; |
2014 | 1989 | ||
2015 | nat_percentage = 0.6; /* FIXME: default percentage? */ | 1990 | nat_percentage = 0.6; /* FIXME: default percentage? */ |
2016 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, | 1991 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2017 | "TESTING", | ||
2018 | "PERCENTAGE", | 1992 | "PERCENTAGE", |
2019 | &p_string)) | 1993 | &p_string)) |
2020 | { | 1994 | { |
2021 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) | 1995 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) |
2022 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1996 | GNUNET_log ( |
1997 | GNUNET_ERROR_TYPE_WARNING, | ||
2023 | _ | 1998 | _ |
2024 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1999 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2025 | p_string, "PERCENTAGE", "TESTING"); | 2000 | p_string, "PERCENTAGE", "TESTING"); |
@@ -2030,8 +2005,7 @@ create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg, | |||
2030 | count = 0; | 2005 | count = 0; |
2031 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2006 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2032 | { | 2007 | { |
2033 | for (inner_count = outer_count + 1; inner_count < pg->total; | 2008 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) |
2034 | inner_count++) | ||
2035 | { | 2009 | { |
2036 | if ((outer_count > cutoff) || (inner_count > cutoff)) | 2010 | if ((outer_count > cutoff) || (inner_count > cutoff)) |
2037 | { | 2011 | { |
@@ -2039,27 +2013,27 @@ create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg, | |||
2039 | } | 2013 | } |
2040 | } | 2014 | } |
2041 | } | 2015 | } |
2042 | conn_meter = create_meter(count, "NAT COPY", GNUNET_YES); | 2016 | conn_meter = create_meter (count, "NAT COPY", GNUNET_YES); |
2043 | connect_attempts = 0; | 2017 | connect_attempts = 0; |
2044 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2018 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2045 | { | 2019 | { |
2046 | for (inner_count = outer_count + 1; inner_count < pg->total; | 2020 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) |
2047 | inner_count++) | ||
2048 | { | 2021 | { |
2049 | if ((outer_count > cutoff) || (inner_count > cutoff)) | 2022 | if ((outer_count > cutoff) || (inner_count > cutoff)) |
2050 | { | 2023 | { |
2051 | #if VERBOSE_TESTING | 2024 | #if VERBOSE_TESTING |
2052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2025 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2053 | "Connecting peer %d to peer %d\n", | 2026 | "Connecting peer %d to peer %d\n", |
2054 | outer_count, inner_count); | 2027 | outer_count, inner_count); |
2055 | #endif | 2028 | #endif |
2056 | connect_attempts += proc (pg, outer_count, inner_count, list, GNUNET_YES); | 2029 | connect_attempts += proc (pg, outer_count, inner_count, list, |
2057 | add_connections(pg, outer_count, inner_count, ALLOWED, GNUNET_NO); | 2030 | GNUNET_YES); |
2058 | update_meter(conn_meter); | 2031 | add_connections (pg, outer_count, inner_count, ALLOWED, GNUNET_NO); |
2032 | update_meter (conn_meter); | ||
2059 | } | 2033 | } |
2060 | } | 2034 | } |
2061 | } | 2035 | } |
2062 | free_meter(conn_meter); | 2036 | free_meter (conn_meter); |
2063 | 2037 | ||
2064 | return connect_attempts; | 2038 | return connect_attempts; |
2065 | } | 2039 | } |
@@ -2078,8 +2052,8 @@ create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg, | |||
2078 | * | 2052 | * |
2079 | */ | 2053 | */ |
2080 | static unsigned int | 2054 | static unsigned int |
2081 | create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | 2055 | create_small_world(struct GNUNET_TESTING_PeerGroup *pg, |
2082 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2056 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2083 | { | 2057 | { |
2084 | unsigned int i, j, k; | 2058 | unsigned int i, j, k; |
2085 | unsigned int square; | 2059 | unsigned int square; |
@@ -2102,14 +2076,14 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
2102 | rows = square; | 2076 | rows = square; |
2103 | cols = square; | 2077 | cols = square; |
2104 | 2078 | ||
2105 | percentage = 0.5; /* FIXME: default percentage? */ | 2079 | percentage = 0.5; /* FIXME: default percentage? */ |
2106 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, | 2080 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2107 | "TESTING", | ||
2108 | "PERCENTAGE", | 2081 | "PERCENTAGE", |
2109 | &p_string)) | 2082 | &p_string)) |
2110 | { | 2083 | { |
2111 | if (sscanf (p_string, "%lf", &percentage) != 1) | 2084 | if (sscanf (p_string, "%lf", &percentage) != 1) |
2112 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2085 | GNUNET_log ( |
2086 | GNUNET_ERROR_TYPE_WARNING, | ||
2113 | _ | 2087 | _ |
2114 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 2088 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2115 | p_string, "PERCENTAGE", "TESTING"); | 2089 | p_string, "PERCENTAGE", "TESTING"); |
@@ -2117,20 +2091,21 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
2117 | } | 2091 | } |
2118 | if (percentage < 0.0) | 2092 | if (percentage < 0.0) |
2119 | { | 2093 | { |
2120 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2094 | GNUNET_log ( |
2095 | GNUNET_ERROR_TYPE_WARNING, | ||
2121 | _ | 2096 | _ |
2122 | ("Invalid value `%s' for option `%s' in section `%s': got %f, needed value greater than 0\n"), | 2097 | ("Invalid value `%s' for option `%s' in section `%s': got %f, needed value greater than 0\n"), |
2123 | "PERCENTAGE", "TESTING", percentage); | 2098 | "PERCENTAGE", "TESTING", percentage); |
2124 | percentage = 0.5; | 2099 | percentage = 0.5; |
2125 | } | 2100 | } |
2126 | probability = 0.5; /* FIXME: default percentage? */ | 2101 | probability = 0.5; /* FIXME: default percentage? */ |
2127 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, | 2102 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2128 | "TESTING", | ||
2129 | "PROBABILITY", | 2103 | "PROBABILITY", |
2130 | &p_string)) | 2104 | &p_string)) |
2131 | { | 2105 | { |
2132 | if (sscanf (p_string, "%lf", &probability) != 1) | 2106 | if (sscanf (p_string, "%lf", &probability) != 1) |
2133 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2107 | GNUNET_log ( |
2108 | GNUNET_ERROR_TYPE_WARNING, | ||
2134 | _ | 2109 | _ |
2135 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 2110 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2136 | p_string, "PROBABILITY", "TESTING"); | 2111 | p_string, "PROBABILITY", "TESTING"); |
@@ -2150,9 +2125,9 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
2150 | } | 2125 | } |
2151 | #if VERBOSE_TESTING | 2126 | #if VERBOSE_TESTING |
2152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2153 | _ | 2128 | _ |
2154 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), | 2129 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), |
2155 | rows, cols); | 2130 | rows, cols); |
2156 | #endif | 2131 | #endif |
2157 | 2132 | ||
2158 | connect_attempts = 0; | 2133 | connect_attempts = 0; |
@@ -2188,10 +2163,10 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
2188 | natLog = log (pg->total); | 2163 | natLog = log (pg->total); |
2189 | #if VERBOSE_TESTING > 2 | 2164 | #if VERBOSE_TESTING > 2 |
2190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2191 | _("natural log of %d is %d, will run %d iterations\n"), | 2166 | _("natural log of %d is %d, will run %d iterations\n"), |
2192 | pg->total, natLog, (int) (natLog * percentage)); | 2167 | pg->total, natLog, (int) (natLog * percentage)); |
2193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2194 | _("Total connections added thus far: %u!\n"), connect_attempts); | 2169 | _("Total connections added thus far: %u!\n"), connect_attempts); |
2195 | #endif | 2170 | #endif |
2196 | smallWorldConnections = 0; | 2171 | smallWorldConnections = 0; |
2197 | small_world_it = (unsigned int) (natLog * percentage); | 2172 | small_world_it = (unsigned int) (natLog * percentage); |
@@ -2211,18 +2186,17 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
2211 | node2Row = k / cols; | 2186 | node2Row = k / cols; |
2212 | node2Col = k - (node2Row * cols); | 2187 | node2Col = k - (node2Row * cols); |
2213 | /* Simple Cartesian distance */ | 2188 | /* Simple Cartesian distance */ |
2214 | distance = | 2189 | distance = abs (node1Row - node2Row) + abs (node1Col - node2Col); |
2215 | abs (node1Row - node2Row) + abs (node1Col - node2Col); | ||
2216 | if (distance > 1) | 2190 | if (distance > 1) |
2217 | { | 2191 | { |
2218 | /* Calculate probability as 1 over the square of the distance */ | 2192 | /* Calculate probability as 1 over the square of the distance */ |
2219 | probability = 1.0 / (distance * distance); | 2193 | probability = 1.0 / (distance * distance); |
2220 | /* Choose a random value between 0 and 1 */ | 2194 | /* Choose a random value between 0 and 1 */ |
2221 | random = | 2195 | random |
2222 | ((double) | 2196 | = ((double) GNUNET_CRYPTO_random_u64 ( |
2223 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 2197 | GNUNET_CRYPTO_QUALITY_WEAK, |
2224 | UINT64_MAX)) / | 2198 | UINT64_MAX)) |
2225 | ((double) UINT64_MAX); | 2199 | / ((double) UINT64_MAX); |
2226 | /* If random < probability, then connect the two nodes */ | 2200 | /* If random < probability, then connect the two nodes */ |
2227 | if (random < probability) | 2201 | if (random < probability) |
2228 | smallWorldConnections += proc (pg, j, k, list, GNUNET_YES); | 2202 | smallWorldConnections += proc (pg, j, k, list, GNUNET_YES); |
@@ -2234,8 +2208,8 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
2234 | connect_attempts += smallWorldConnections; | 2208 | connect_attempts += smallWorldConnections; |
2235 | #if VERBOSE_TESTING > 2 | 2209 | #if VERBOSE_TESTING > 2 |
2236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2237 | _("Total connections added for small world: %d!\n"), | 2211 | _("Total connections added for small world: %d!\n"), |
2238 | smallWorldConnections); | 2212 | smallWorldConnections); |
2239 | #endif | 2213 | #endif |
2240 | return connect_attempts; | 2214 | return connect_attempts; |
2241 | } | 2215 | } |
@@ -2253,8 +2227,8 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, | |||
2253 | * | 2227 | * |
2254 | */ | 2228 | */ |
2255 | static unsigned int | 2229 | static unsigned int |
2256 | create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, | 2230 | create_erdos_renyi(struct GNUNET_TESTING_PeerGroup *pg, |
2257 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2231 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2258 | { | 2232 | { |
2259 | double temp_rand; | 2233 | double temp_rand; |
2260 | unsigned int outer_count; | 2234 | unsigned int outer_count; |
@@ -2263,14 +2237,14 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, | |||
2263 | double probability; | 2237 | double probability; |
2264 | char *p_string; | 2238 | char *p_string; |
2265 | 2239 | ||
2266 | probability = 0.5; /* FIXME: default percentage? */ | 2240 | probability = 0.5; /* FIXME: default percentage? */ |
2267 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, | 2241 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2268 | "TESTING", | ||
2269 | "PROBABILITY", | 2242 | "PROBABILITY", |
2270 | &p_string)) | 2243 | &p_string)) |
2271 | { | 2244 | { |
2272 | if (sscanf (p_string, "%lf", &probability) != 1) | 2245 | if (sscanf (p_string, "%lf", &probability) != 1) |
2273 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2246 | GNUNET_log ( |
2247 | GNUNET_ERROR_TYPE_WARNING, | ||
2274 | _ | 2248 | _ |
2275 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 2249 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2276 | p_string, "PROBABILITY", "TESTING"); | 2250 | p_string, "PROBABILITY", "TESTING"); |
@@ -2279,21 +2253,21 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, | |||
2279 | connect_attempts = 0; | 2253 | connect_attempts = 0; |
2280 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2254 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2281 | { | 2255 | { |
2282 | for (inner_count = outer_count + 1; inner_count < pg->total; | 2256 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) |
2283 | inner_count++) | ||
2284 | { | 2257 | { |
2285 | temp_rand = | 2258 | temp_rand |
2286 | ((double) | 2259 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
2287 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 2260 | UINT64_MAX)) |
2288 | UINT64_MAX)) / ((double) UINT64_MAX); | 2261 | / ((double) UINT64_MAX); |
2289 | #if VERBOSE_TESTING | 2262 | #if VERBOSE_TESTING |
2290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2291 | _("rand is %f probability is %f\n"), temp_rand, | 2264 | _("rand is %f probability is %f\n"), temp_rand, |
2292 | probability); | 2265 | probability); |
2293 | #endif | 2266 | #endif |
2294 | if (temp_rand < probability) | 2267 | if (temp_rand < probability) |
2295 | { | 2268 | { |
2296 | connect_attempts += proc (pg, outer_count, inner_count, list, GNUNET_YES); | 2269 | connect_attempts += proc (pg, outer_count, inner_count, list, |
2270 | GNUNET_YES); | ||
2297 | } | 2271 | } |
2298 | } | 2272 | } |
2299 | } | 2273 | } |
@@ -2316,8 +2290,8 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, | |||
2316 | * | 2290 | * |
2317 | */ | 2291 | */ |
2318 | static unsigned int | 2292 | static unsigned int |
2319 | create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, | 2293 | create_2d_torus(struct GNUNET_TESTING_PeerGroup *pg, |
2320 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2294 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2321 | { | 2295 | { |
2322 | unsigned int i; | 2296 | unsigned int i; |
2323 | unsigned int square; | 2297 | unsigned int square; |
@@ -2347,9 +2321,9 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, | |||
2347 | } | 2321 | } |
2348 | #if VERBOSE_TESTING | 2322 | #if VERBOSE_TESTING |
2349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2350 | _ | 2324 | _ |
2351 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), | 2325 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), |
2352 | rows, cols); | 2326 | rows, cols); |
2353 | #endif | 2327 | #endif |
2354 | /* Rows and columns are all sorted out, now iterate over all nodes and connect each | 2328 | /* Rows and columns are all sorted out, now iterate over all nodes and connect each |
2355 | * to the node to its right and above. Once this is over, we'll have our torus! | 2329 | * to the node to its right and above. Once this is over, we'll have our torus! |
@@ -2367,7 +2341,7 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, | |||
2367 | nodeToConnect = i - cols + 1; | 2341 | nodeToConnect = i - cols + 1; |
2368 | #if VERBOSE_TESTING | 2342 | #if VERBOSE_TESTING |
2369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2370 | "Connecting peer %d to peer %d\n", i, nodeToConnect); | 2344 | "Connecting peer %d to peer %d\n", i, nodeToConnect); |
2371 | #endif | 2345 | #endif |
2372 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | 2346 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); |
2373 | 2347 | ||
@@ -2385,7 +2359,7 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, | |||
2385 | { | 2359 | { |
2386 | #if VERBOSE_TESTING | 2360 | #if VERBOSE_TESTING |
2387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2388 | "Connecting peer %d to peer %d\n", i, nodeToConnect); | 2362 | "Connecting peer %d to peer %d\n", i, nodeToConnect); |
2389 | #endif | 2363 | #endif |
2390 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | 2364 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); |
2391 | } | 2365 | } |
@@ -2395,7 +2369,6 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, | |||
2395 | return connect_attempts; | 2369 | return connect_attempts; |
2396 | } | 2370 | } |
2397 | 2371 | ||
2398 | |||
2399 | /** | 2372 | /** |
2400 | * Create a topology given a peer group (set of running peers) | 2373 | * Create a topology given a peer group (set of running peers) |
2401 | * and a connection processor. | 2374 | * and a connection processor. |
@@ -2411,10 +2384,9 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, | |||
2411 | * | 2384 | * |
2412 | */ | 2385 | */ |
2413 | static unsigned int | 2386 | static unsigned int |
2414 | create_clique (struct GNUNET_TESTING_PeerGroup *pg, | 2387 | create_clique(struct GNUNET_TESTING_PeerGroup *pg, |
2415 | GNUNET_TESTING_ConnectionProcessor proc, | 2388 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list, |
2416 | enum PeerLists list, | 2389 | unsigned int check) |
2417 | unsigned int check) | ||
2418 | { | 2390 | { |
2419 | unsigned int outer_count; | 2391 | unsigned int outer_count; |
2420 | unsigned int inner_count; | 2392 | unsigned int inner_count; |
@@ -2422,24 +2394,25 @@ create_clique (struct GNUNET_TESTING_PeerGroup *pg, | |||
2422 | struct ProgressMeter *conn_meter; | 2394 | struct ProgressMeter *conn_meter; |
2423 | connect_attempts = 0; | 2395 | connect_attempts = 0; |
2424 | 2396 | ||
2425 | conn_meter = create_meter((((pg->total * pg->total) + pg->total) / 2) - pg->total, "Create Clique ", GNUNET_YES); | 2397 | conn_meter = create_meter ((((pg->total * pg->total) + pg->total) / 2) |
2398 | - pg->total, "Create Clique ", GNUNET_YES); | ||
2426 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2399 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2427 | { | 2400 | { |
2428 | for (inner_count = outer_count + 1; inner_count < pg->total; | 2401 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) |
2429 | inner_count++) | ||
2430 | { | 2402 | { |
2431 | #if VERBOSE_TESTING | 2403 | #if VERBOSE_TESTING |
2432 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2433 | "Connecting peer %d to peer %d\n", | 2405 | "Connecting peer %d to peer %d\n", |
2434 | outer_count, inner_count); | 2406 | outer_count, inner_count); |
2435 | #endif | 2407 | #endif |
2436 | connect_attempts += proc (pg, outer_count, inner_count, list, check); | 2408 | connect_attempts += proc (pg, outer_count, inner_count, list, check); |
2437 | update_meter(conn_meter); | 2409 | update_meter (conn_meter); |
2438 | } | 2410 | } |
2439 | } | 2411 | } |
2440 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Meter has %d left\n", conn_meter->total - conn_meter->completed); | 2412 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Meter has %d left\n", |
2441 | reset_meter(conn_meter); | 2413 | conn_meter->total - conn_meter->completed); |
2442 | free_meter(conn_meter); | 2414 | reset_meter (conn_meter); |
2415 | free_meter (conn_meter); | ||
2443 | return connect_attempts; | 2416 | return connect_attempts; |
2444 | } | 2417 | } |
2445 | 2418 | ||
@@ -2457,18 +2430,18 @@ create_clique (struct GNUNET_TESTING_PeerGroup *pg, | |||
2457 | */ | 2430 | */ |
2458 | static int | 2431 | static int |
2459 | unblacklist_iterator (void *cls, | 2432 | unblacklist_iterator (void *cls, |
2460 | const GNUNET_HashCode * key, | 2433 | const GNUNET_HashCode * key, |
2461 | void *value) | 2434 | void *value) |
2462 | { | 2435 | { |
2463 | struct UnblacklistContext *un_ctx = cls; | 2436 | struct UnblacklistContext *un_ctx = cls; |
2464 | uint32_t second_pos; | 2437 | uint32_t second_pos; |
2465 | 2438 | ||
2466 | uid_from_hash (key, &second_pos); | 2439 | uid_from_hash (key, &second_pos); |
2467 | 2440 | ||
2468 | unblacklist_connections(un_ctx->pg, un_ctx->first_uid, second_pos); | 2441 | unblacklist_connections(un_ctx->pg, un_ctx->first_uid, second_pos); |
2469 | 2442 | ||
2470 | return GNUNET_YES; | 2443 | return GNUNET_YES; |
2471 | } | 2444 | } |
2472 | #endif | 2445 | #endif |
2473 | 2446 | ||
2474 | /** | 2447 | /** |
@@ -2484,8 +2457,8 @@ unblacklist_iterator (void *cls, | |||
2484 | * | 2457 | * |
2485 | */ | 2458 | */ |
2486 | static unsigned int | 2459 | static unsigned int |
2487 | copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | 2460 | copy_allowed(struct GNUNET_TESTING_PeerGroup *pg, |
2488 | GNUNET_TESTING_ConnectionProcessor proc) | 2461 | GNUNET_TESTING_ConnectionProcessor proc) |
2489 | { | 2462 | { |
2490 | struct UnblacklistContext un_ctx; | 2463 | struct UnblacklistContext un_ctx; |
2491 | unsigned int count; | 2464 | unsigned int count; |
@@ -2501,7 +2474,7 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2501 | iter = pg->peers[count].allowed_peers_head; | 2474 | iter = pg->peers[count].allowed_peers_head; |
2502 | while (iter != NULL) | 2475 | while (iter != NULL) |
2503 | { | 2476 | { |
2504 | remove_connections(pg, count, iter->index, BLACKLIST, GNUNET_YES); | 2477 | remove_connections (pg, count, iter->index, BLACKLIST, GNUNET_YES); |
2505 | //unblacklist_connections(pg, count, iter->index); | 2478 | //unblacklist_connections(pg, count, iter->index); |
2506 | iter = iter->next; | 2479 | iter = iter->next; |
2507 | } | 2480 | } |
@@ -2509,11 +2482,10 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2509 | total += GNUNET_CONTAINER_multihashmap_iterate(pg->peers[count].allowed_peers, &unblacklist_iterator, &un_ctx); | 2482 | total += GNUNET_CONTAINER_multihashmap_iterate(pg->peers[count].allowed_peers, &unblacklist_iterator, &un_ctx); |
2510 | #endif | 2483 | #endif |
2511 | } | 2484 | } |
2512 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Unblacklisted %u peers\n", total); | 2485 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unblacklisted %u peers\n", total); |
2513 | return total; | 2486 | return total; |
2514 | } | 2487 | } |
2515 | 2488 | ||
2516 | |||
2517 | /** | 2489 | /** |
2518 | * Create a topology given a peer group (set of running peers) | 2490 | * Create a topology given a peer group (set of running peers) |
2519 | * and a connection processor. | 2491 | * and a connection processor. |
@@ -2527,8 +2499,8 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2527 | * | 2499 | * |
2528 | */ | 2500 | */ |
2529 | static unsigned int | 2501 | static unsigned int |
2530 | create_line (struct GNUNET_TESTING_PeerGroup *pg, | 2502 | create_line(struct GNUNET_TESTING_PeerGroup *pg, |
2531 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2503 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2532 | { | 2504 | { |
2533 | unsigned int count; | 2505 | unsigned int count; |
2534 | int connect_attempts; | 2506 | int connect_attempts; |
@@ -2540,7 +2512,7 @@ create_line (struct GNUNET_TESTING_PeerGroup *pg, | |||
2540 | { | 2512 | { |
2541 | #if VERBOSE_TESTING | 2513 | #if VERBOSE_TESTING |
2542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2543 | "Connecting peer %d to peer %d\n", count, count + 1); | 2515 | "Connecting peer %d to peer %d\n", count, count + 1); |
2544 | #endif | 2516 | #endif |
2545 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); | 2517 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); |
2546 | } | 2518 | } |
@@ -2562,9 +2534,8 @@ create_line (struct GNUNET_TESTING_PeerGroup *pg, | |||
2562 | * | 2534 | * |
2563 | */ | 2535 | */ |
2564 | static unsigned int | 2536 | static unsigned int |
2565 | create_from_file (struct GNUNET_TESTING_PeerGroup *pg, | 2537 | create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename, |
2566 | char *filename, | 2538 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2567 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | ||
2568 | { | 2539 | { |
2569 | int connect_attempts; | 2540 | int connect_attempts; |
2570 | unsigned int first_peer_index; | 2541 | unsigned int first_peer_index; |
@@ -2590,11 +2561,12 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, | |||
2590 | 2561 | ||
2591 | data = GNUNET_malloc_large (frstat.st_size); | 2562 | data = GNUNET_malloc_large (frstat.st_size); |
2592 | GNUNET_assert(data != NULL); | 2563 | GNUNET_assert(data != NULL); |
2593 | if (frstat.st_size != | 2564 | if (frstat.st_size != GNUNET_DISK_fn_read (filename, data, frstat.st_size)) |
2594 | GNUNET_DISK_fn_read (filename, data, frstat.st_size)) | ||
2595 | { | 2565 | { |
2596 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2566 | GNUNET_log ( |
2597 | "Could not read file %s specified for host list, ending test!", filename); | 2567 | GNUNET_ERROR_TYPE_ERROR, |
2568 | "Could not read file %s specified for host list, ending test!", | ||
2569 | filename); | ||
2598 | GNUNET_free (data); | 2570 | GNUNET_free (data); |
2599 | return connect_attempts; | 2571 | return connect_attempts; |
2600 | } | 2572 | } |
@@ -2607,70 +2579,78 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, | |||
2607 | while (count < frstat.st_size - 1) | 2579 | while (count < frstat.st_size - 1) |
2608 | { | 2580 | { |
2609 | if ((buf[count] == '\n') || (buf[count] == ' ')) | 2581 | if ((buf[count] == '\n') || (buf[count] == ' ')) |
2610 | { | 2582 | { |
2611 | count++; | 2583 | count++; |
2612 | continue; | 2584 | continue; |
2613 | } | 2585 | } |
2614 | 2586 | ||
2615 | switch (curr_state) | 2587 | switch (curr_state) |
2616 | { | 2588 | { |
2617 | case NUM_PEERS: | 2589 | case NUM_PEERS: |
2618 | if (1 != sscanf(&buf[count], "%u", &total_peers)) | 2590 | if (1 != sscanf (&buf[count], "%u", &total_peers)) |
2619 | { | 2591 | { |
2620 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to read number of peers from topology file!\n"); | 2592 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2621 | GNUNET_free_non_null(data); | 2593 | "Failed to read number of peers from topology file!\n"); |
2622 | return connect_attempts; | 2594 | GNUNET_free_non_null(data); |
2623 | } | 2595 | return connect_attempts; |
2624 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read %u total peers in topology\n", total_peers); | 2596 | } |
2625 | GNUNET_assert(total_peers == pg->total); | 2597 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2626 | curr_state = PEER_INDEX; | 2598 | "Read %u total peers in topology\n", total_peers); |
2627 | while((buf[count] != '\n') && (count < frstat.st_size - 1)) | 2599 | GNUNET_assert(total_peers == pg->total); |
2628 | count++; | 2600 | curr_state = PEER_INDEX; |
2601 | while ((buf[count] != '\n') && (count < frstat.st_size - 1)) | ||
2629 | count++; | 2602 | count++; |
2630 | break; | 2603 | count++; |
2631 | case PEER_INDEX: | 2604 | break; |
2632 | if (1 != sscanf(&buf[count], "%u", &first_peer_index)) | 2605 | case PEER_INDEX: |
2633 | { | 2606 | if (1 != sscanf (&buf[count], "%u", &first_peer_index)) |
2634 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to read peer index from topology file!\n"); | 2607 | { |
2635 | GNUNET_free_non_null(data); | 2608 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2636 | return connect_attempts; | 2609 | "Failed to read peer index from topology file!\n"); |
2637 | } | 2610 | GNUNET_free_non_null(data); |
2638 | while((buf[count] != ':') && (count < frstat.st_size - 1)) | 2611 | return connect_attempts; |
2639 | count++; | 2612 | } |
2613 | while ((buf[count] != ':') && (count < frstat.st_size - 1)) | ||
2640 | count++; | 2614 | count++; |
2615 | count++; | ||
2616 | curr_state = OTHER_PEER_INDEX; | ||
2617 | break; | ||
2618 | case COLON: | ||
2619 | if (1 == sscanf (&buf[count], ":")) | ||
2641 | curr_state = OTHER_PEER_INDEX; | 2620 | curr_state = OTHER_PEER_INDEX; |
2642 | break; | 2621 | count++; |
2643 | case COLON: | 2622 | break; |
2644 | if (1 == sscanf(&buf[count], ":")) | 2623 | case OTHER_PEER_INDEX: |
2645 | curr_state = OTHER_PEER_INDEX; | 2624 | if (1 != sscanf (&buf[count], "%u", &second_peer_index)) |
2625 | { | ||
2626 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2627 | "Failed to peer index from topology file!\n"); | ||
2628 | GNUNET_free_non_null(data); | ||
2629 | return connect_attempts; | ||
2630 | } | ||
2631 | /* Assume file is written with first peer 1, but array index is 0 */ | ||
2632 | connect_attempts += proc (pg, first_peer_index - 1, second_peer_index | ||
2633 | - 1, list, GNUNET_YES); | ||
2634 | while ((buf[count] != '\n') && (buf[count] != ',') && (count | ||
2635 | < frstat.st_size - 1)) | ||
2646 | count++; | 2636 | count++; |
2647 | break; | 2637 | if (buf[count] == '\n') |
2648 | case OTHER_PEER_INDEX: | ||
2649 | if (1 != sscanf(&buf[count], "%u", &second_peer_index)) | ||
2650 | { | ||
2651 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to peer index from topology file!\n"); | ||
2652 | GNUNET_free_non_null(data); | ||
2653 | return connect_attempts; | ||
2654 | } | ||
2655 | /* Assume file is written with first peer 1, but array index is 0 */ | ||
2656 | connect_attempts += proc (pg, first_peer_index - 1, second_peer_index - 1, list, GNUNET_YES); | ||
2657 | while((buf[count] != '\n') && (buf[count] != ',') && (count < frstat.st_size - 1)) | ||
2658 | count++; | ||
2659 | if (buf[count] == '\n') | ||
2660 | { | 2638 | { |
2661 | curr_state = PEER_INDEX; | 2639 | curr_state = PEER_INDEX; |
2662 | } | 2640 | } |
2663 | else if (buf[count] != ',') | 2641 | else if (buf[count] != ',') |
2664 | { | 2642 | { |
2665 | curr_state = OTHER_PEER_INDEX; | 2643 | curr_state = OTHER_PEER_INDEX; |
2666 | } | 2644 | } |
2667 | count++; | 2645 | count++; |
2668 | break; | 2646 | break; |
2669 | default: | 2647 | default: |
2670 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Found bad data in topology file while in state %d!\n", curr_state); | 2648 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2671 | GNUNET_break(0); | 2649 | "Found bad data in topology file while in state %d!\n", |
2672 | return connect_attempts; | 2650 | curr_state); |
2673 | } | 2651 | GNUNET_break(0); |
2652 | return connect_attempts; | ||
2653 | } | ||
2674 | 2654 | ||
2675 | } | 2655 | } |
2676 | #if 0 | 2656 | #if 0 |
@@ -2679,7 +2659,7 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, | |||
2679 | { | 2659 | { |
2680 | #if VERBOSE_TESTING | 2660 | #if VERBOSE_TESTING |
2681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2661 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2682 | "Connecting peer %d to peer %d\n", first_peer_index, second_peer_index); | 2662 | "Connecting peer %d to peer %d\n", first_peer_index, second_peer_index); |
2683 | #endif | 2663 | #endif |
2684 | connect_attempts += proc (pg, first_peer_index, second_peer_index); | 2664 | connect_attempts += proc (pg, first_peer_index, second_peer_index); |
2685 | } | 2665 | } |
@@ -2700,8 +2680,8 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, | |||
2700 | * | 2680 | * |
2701 | */ | 2681 | */ |
2702 | static unsigned int | 2682 | static unsigned int |
2703 | create_ring (struct GNUNET_TESTING_PeerGroup *pg, | 2683 | create_ring(struct GNUNET_TESTING_PeerGroup *pg, |
2704 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2684 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2705 | { | 2685 | { |
2706 | unsigned int count; | 2686 | unsigned int count; |
2707 | int connect_attempts; | 2687 | int connect_attempts; |
@@ -2713,7 +2693,7 @@ create_ring (struct GNUNET_TESTING_PeerGroup *pg, | |||
2713 | { | 2693 | { |
2714 | #if VERBOSE_TESTING | 2694 | #if VERBOSE_TESTING |
2715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2716 | "Connecting peer %d to peer %d\n", count, count + 1); | 2696 | "Connecting peer %d to peer %d\n", count, count + 1); |
2717 | #endif | 2697 | #endif |
2718 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); | 2698 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); |
2719 | } | 2699 | } |
@@ -2744,31 +2724,31 @@ create_ring (struct GNUNET_TESTING_PeerGroup *pg, | |||
2744 | */ | 2724 | */ |
2745 | static int | 2725 | static int |
2746 | friend_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 2726 | friend_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2747 | { | 2727 | { |
2748 | FILE *temp_friend_handle = cls; | 2728 | FILE *temp_friend_handle = cls; |
2749 | struct GNUNET_TESTING_Daemon *peer = value; | 2729 | struct GNUNET_TESTING_Daemon *peer = value; |
2750 | struct GNUNET_PeerIdentity *temppeer; | 2730 | struct GNUNET_PeerIdentity *temppeer; |
2751 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | 2731 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; |
2752 | 2732 | ||
2753 | temppeer = &peer->id; | 2733 | temppeer = &peer->id; |
2754 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); | 2734 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); |
2755 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); | 2735 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); |
2756 | 2736 | ||
2757 | return GNUNET_YES; | 2737 | return GNUNET_YES; |
2758 | } | 2738 | } |
2759 | 2739 | ||
2760 | struct BlacklistContext | 2740 | struct BlacklistContext |
2761 | { | 2741 | { |
2762 | /* | 2742 | /* |
2763 | * The (open) file handle to write to | 2743 | * The (open) file handle to write to |
2764 | */ | 2744 | */ |
2765 | FILE *temp_file_handle; | 2745 | FILE *temp_file_handle; |
2766 | 2746 | ||
2767 | /* | 2747 | /* |
2768 | * The transport that this peer will be blacklisted on. | 2748 | * The transport that this peer will be blacklisted on. |
2769 | */ | 2749 | */ |
2770 | char *transport; | 2750 | char *transport; |
2771 | }; | 2751 | }; |
2772 | 2752 | ||
2773 | /** | 2753 | /** |
2774 | * Iterator for writing blacklist data to appropriate files. | 2754 | * Iterator for writing blacklist data to appropriate files. |
@@ -2781,23 +2761,22 @@ struct BlacklistContext | |||
2781 | */ | 2761 | */ |
2782 | static int | 2762 | static int |
2783 | blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 2763 | blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2784 | { | 2764 | { |
2785 | struct BlacklistContext *blacklist_ctx = cls; | 2765 | struct BlacklistContext *blacklist_ctx = cls; |
2786 | struct GNUNET_TESTING_Daemon *peer = value; | 2766 | struct GNUNET_TESTING_Daemon *peer = value; |
2787 | struct GNUNET_PeerIdentity *temppeer; | 2767 | struct GNUNET_PeerIdentity *temppeer; |
2788 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | 2768 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; |
2789 | 2769 | ||
2790 | temppeer = &peer->id; | 2770 | temppeer = &peer->id; |
2791 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); | 2771 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); |
2792 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Writing entry %s:%s to file\n", blacklist_ctx->transport, (char *) &peer_enc); | 2772 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Writing entry %s:%s to file\n", blacklist_ctx->transport, (char *) &peer_enc); |
2793 | fprintf (blacklist_ctx->temp_file_handle, "%s:%s\n", | 2773 | fprintf (blacklist_ctx->temp_file_handle, "%s:%s\n", |
2794 | blacklist_ctx->transport, (char *) &peer_enc); | 2774 | blacklist_ctx->transport, (char *) &peer_enc); |
2795 | 2775 | ||
2796 | return GNUNET_YES; | 2776 | return GNUNET_YES; |
2797 | } | 2777 | } |
2798 | #endif | 2778 | #endif |
2799 | 2779 | ||
2800 | |||
2801 | /* | 2780 | /* |
2802 | * Create the friend files based on the PeerConnection's | 2781 | * Create the friend files based on the PeerConnection's |
2803 | * of each peer in the peer group, and copy the files | 2782 | * of each peer in the peer group, and copy the files |
@@ -2806,7 +2785,7 @@ blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
2806 | * @param pg the peer group we are dealing with | 2785 | * @param pg the peer group we are dealing with |
2807 | */ | 2786 | */ |
2808 | static int | 2787 | static int |
2809 | create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | 2788 | create_and_copy_friend_files(struct GNUNET_TESTING_PeerGroup *pg) |
2810 | { | 2789 | { |
2811 | FILE *temp_friend_handle; | 2790 | FILE *temp_friend_handle; |
2812 | unsigned int pg_iter; | 2791 | unsigned int pg_iter; |
@@ -2838,49 +2817,51 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2838 | conn_iter = pg->peers[pg_iter].allowed_peers_head; | 2817 | conn_iter = pg->peers[pg_iter].allowed_peers_head; |
2839 | while (conn_iter != NULL) | 2818 | while (conn_iter != NULL) |
2840 | { | 2819 | { |
2841 | GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon->id.hashPubKey, &peer_enc); | 2820 | GNUNET_CRYPTO_hash_to_enc ( |
2821 | &pg->peers[conn_iter->index].daemon->id.hashPubKey, | ||
2822 | &peer_enc); | ||
2842 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); | 2823 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); |
2843 | conn_iter = conn_iter->next; | 2824 | conn_iter = conn_iter->next; |
2844 | } | 2825 | } |
2845 | #else | 2826 | #else |
2846 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, | 2827 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, |
2847 | &friend_file_iterator, | 2828 | &friend_file_iterator, |
2848 | temp_friend_handle); | 2829 | temp_friend_handle); |
2849 | #endif | 2830 | #endif |
2850 | fclose (temp_friend_handle); | 2831 | fclose (temp_friend_handle); |
2851 | 2832 | ||
2852 | if (GNUNET_OK != | 2833 | if (GNUNET_OK |
2853 | GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter]. | 2834 | != GNUNET_CONFIGURATION_get_value_string ( |
2854 | daemon->cfg, "PATHS", | 2835 | pg->peers[pg_iter]. daemon->cfg, |
2855 | "SERVICEHOME", | 2836 | "PATHS", "SERVICEHOME", |
2856 | &temp_service_path)) | 2837 | &temp_service_path)) |
2857 | { | 2838 | { |
2858 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2839 | GNUNET_log ( |
2840 | GNUNET_ERROR_TYPE_WARNING, | ||
2859 | _ | 2841 | _ |
2860 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), | 2842 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), |
2861 | "SERVICEHOME", "PATHS"); | 2843 | "SERVICEHOME", "PATHS"); |
2862 | if (UNLINK (mytemp) != 0) | 2844 | if (UNLINK (mytemp) != 0) |
2863 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", | 2845 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", |
2864 | mytemp); | 2846 | mytemp); |
2865 | GNUNET_free (mytemp); | 2847 | GNUNET_free (mytemp); |
2866 | break; | 2848 | break; |
2867 | } | 2849 | } |
2868 | 2850 | ||
2869 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ | 2851 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ |
2870 | { | 2852 | { |
2871 | GNUNET_asprintf (&arg, "%s/friends", temp_service_path); | 2853 | GNUNET_asprintf (&arg, "%s/friends", temp_service_path); |
2872 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", | 2854 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", |
2873 | "mv", mytemp, arg, | 2855 | mytemp, arg, NULL); |
2874 | NULL); | ||
2875 | #if VERBOSE_TESTING | 2856 | #if VERBOSE_TESTING |
2876 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2857 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2877 | _("Copying file with command cp %s %s\n"), mytemp, arg); | 2858 | _("Copying file with command cp %s %s\n"), mytemp, arg); |
2878 | #endif | 2859 | #endif |
2879 | ret = GNUNET_OS_process_wait(procarr[pg_iter]); /* FIXME: schedule this, throttle! */ | 2860 | ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ |
2880 | GNUNET_OS_process_close (procarr[pg_iter]); | 2861 | GNUNET_OS_process_close (procarr[pg_iter]); |
2881 | GNUNET_free (arg); | 2862 | GNUNET_free (arg); |
2882 | } | 2863 | } |
2883 | else /* Remote, scp the file to the correct place */ | 2864 | else /* Remote, scp the file to the correct place */ |
2884 | { | 2865 | { |
2885 | if (NULL != pg->peers[pg_iter].daemon->username) | 2866 | if (NULL != pg->peers[pg_iter].daemon->username) |
2886 | GNUNET_asprintf (&arg, "%s@%s:%s/friends", | 2867 | GNUNET_asprintf (&arg, "%s@%s:%s/friends", |
@@ -2891,19 +2872,18 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2891 | GNUNET_asprintf (&arg, "%s:%s/friends", | 2872 | GNUNET_asprintf (&arg, "%s:%s/friends", |
2892 | pg->peers[pg_iter].daemon->hostname, | 2873 | pg->peers[pg_iter].daemon->hostname, |
2893 | temp_service_path); | 2874 | temp_service_path); |
2894 | procarr[pg_iter] = | 2875 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", |
2895 | GNUNET_OS_start_process (NULL, NULL, "scp", "scp", mytemp, arg, | 2876 | mytemp, arg, NULL); |
2896 | NULL); | ||
2897 | 2877 | ||
2898 | ret = GNUNET_OS_process_wait(procarr[pg_iter]); /* FIXME: schedule this, throttle! */ | 2878 | ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ |
2899 | GNUNET_OS_process_close (procarr[pg_iter]); | 2879 | GNUNET_OS_process_close (procarr[pg_iter]); |
2900 | if (ret != GNUNET_OK) | 2880 | if (ret != GNUNET_OK) |
2901 | return ret; | 2881 | return ret; |
2902 | procarr[pg_iter] = NULL; | 2882 | procarr[pg_iter] = NULL; |
2903 | #if VERBOSE_TESTING | 2883 | #if VERBOSE_TESTING |
2904 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2884 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2905 | _("Copying file with command scp %s %s\n"), mytemp, | 2885 | _("Copying file with command scp %s %s\n"), mytemp, |
2906 | arg); | 2886 | arg); |
2907 | #endif | 2887 | #endif |
2908 | GNUNET_free (arg); | 2888 | GNUNET_free (arg); |
2909 | } | 2889 | } |
@@ -2921,7 +2901,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2921 | { | 2901 | { |
2922 | #if VERBOSE_TESTING | 2902 | #if VERBOSE_TESTING |
2923 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2924 | _("Checking copy status of file %d\n"), pg_iter); | 2904 | _("Checking copy status of file %d\n"), pg_iter); |
2925 | #endif | 2905 | #endif |
2926 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ | 2906 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ |
2927 | { | 2907 | { |
@@ -2931,7 +2911,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2931 | ret = GNUNET_SYSERR; | 2911 | ret = GNUNET_SYSERR; |
2932 | } | 2912 | } |
2933 | else if ((type != GNUNET_OS_PROCESS_EXITED) | 2913 | else if ((type != GNUNET_OS_PROCESS_EXITED) |
2934 | || (return_code != 0)) | 2914 | || (return_code != 0)) |
2935 | { | 2915 | { |
2936 | ret = GNUNET_SYSERR; | 2916 | ret = GNUNET_SYSERR; |
2937 | } | 2917 | } |
@@ -2941,7 +2921,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2941 | procarr[pg_iter] = NULL; | 2921 | procarr[pg_iter] = NULL; |
2942 | #if VERBOSE_TESTING | 2922 | #if VERBOSE_TESTING |
2943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2923 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2944 | _("File %d copied\n"), pg_iter); | 2924 | _("File %d copied\n"), pg_iter); |
2945 | #endif | 2925 | #endif |
2946 | } | 2926 | } |
2947 | } | 2927 | } |
@@ -2956,14 +2936,13 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2956 | 2936 | ||
2957 | #if VERBOSE_TESTING | 2937 | #if VERBOSE_TESTING |
2958 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2938 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2959 | _("Finished copying all friend files!\n")); | 2939 | _("Finished copying all friend files!\n")); |
2960 | #endif | 2940 | #endif |
2961 | #endif | 2941 | #endif |
2962 | GNUNET_free (procarr); | 2942 | GNUNET_free (procarr); |
2963 | return ret; | 2943 | return ret; |
2964 | } | 2944 | } |
2965 | 2945 | ||
2966 | |||
2967 | /* | 2946 | /* |
2968 | * Create the blacklist files based on the PeerConnection's | 2947 | * Create the blacklist files based on the PeerConnection's |
2969 | * of each peer in the peer group, and copy the files | 2948 | * of each peer in the peer group, and copy the files |
@@ -2973,8 +2952,8 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) | |||
2973 | * @param transports space delimited list of transports to blacklist | 2952 | * @param transports space delimited list of transports to blacklist |
2974 | */ | 2953 | */ |
2975 | static int | 2954 | static int |
2976 | create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | 2955 | create_and_copy_blacklist_files(struct GNUNET_TESTING_PeerGroup *pg, |
2977 | const char *transports) | 2956 | const char *transports) |
2978 | { | 2957 | { |
2979 | FILE *temp_file_handle; | 2958 | FILE *temp_file_handle; |
2980 | unsigned int pg_iter; | 2959 | unsigned int pg_iter; |
@@ -3016,7 +2995,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
3016 | for (i = 0; i < transport_len; i++) | 2995 | for (i = 0; i < transport_len; i++) |
3017 | { | 2996 | { |
3018 | if ((temp_transports[i] == ' ') && (pos == NULL)) | 2997 | if ((temp_transports[i] == ' ') && (pos == NULL)) |
3019 | continue; /* At start of string (whitespace) */ | 2998 | continue; /* At start of string (whitespace) */ |
3020 | else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */ | 2999 | else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */ |
3021 | { | 3000 | { |
3022 | temp_transports[i] = '\0'; | 3001 | temp_transports[i] = '\0'; |
@@ -3024,7 +3003,9 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
3024 | conn_iter = pg->peers[pg_iter].blacklisted_peers_head; | 3003 | conn_iter = pg->peers[pg_iter].blacklisted_peers_head; |
3025 | while (conn_iter != NULL) | 3004 | while (conn_iter != NULL) |
3026 | { | 3005 | { |
3027 | GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon->id.hashPubKey, &peer_enc); | 3006 | GNUNET_CRYPTO_hash_to_enc ( |
3007 | &pg->peers[conn_iter->index].daemon->id.hashPubKey, | ||
3008 | &peer_enc); | ||
3028 | fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc); | 3009 | fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc); |
3029 | conn_iter = conn_iter->next; | 3010 | conn_iter = conn_iter->next; |
3030 | entry_count++; | 3011 | entry_count++; |
@@ -3032,13 +3013,13 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
3032 | #else | 3013 | #else |
3033 | blacklist_ctx.transport = pos; | 3014 | blacklist_ctx.transport = pos; |
3034 | entry_count = GNUNET_CONTAINER_multihashmap_iterate (pg-> | 3015 | entry_count = GNUNET_CONTAINER_multihashmap_iterate (pg-> |
3035 | peers | 3016 | peers |
3036 | [pg_iter].blacklisted_peers, | 3017 | [pg_iter].blacklisted_peers, |
3037 | &blacklist_file_iterator, | 3018 | &blacklist_file_iterator, |
3038 | &blacklist_ctx); | 3019 | &blacklist_ctx); |
3039 | #endif | 3020 | #endif |
3040 | pos = NULL; | 3021 | pos = NULL; |
3041 | } /* At beginning of actual string */ | 3022 | } /* At beginning of actual string */ |
3042 | else if (pos == NULL) | 3023 | else if (pos == NULL) |
3043 | { | 3024 | { |
3044 | pos = &temp_transports[i]; | 3025 | pos = &temp_transports[i]; |
@@ -3048,37 +3029,37 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
3048 | GNUNET_free (temp_transports); | 3029 | GNUNET_free (temp_transports); |
3049 | fclose (temp_file_handle); | 3030 | fclose (temp_file_handle); |
3050 | 3031 | ||
3051 | if (GNUNET_OK != | 3032 | if (GNUNET_OK |
3052 | GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter]. | 3033 | != GNUNET_CONFIGURATION_get_value_string ( |
3053 | daemon->cfg, "PATHS", | 3034 | pg->peers[pg_iter]. daemon->cfg, |
3054 | "SERVICEHOME", | 3035 | "PATHS", "SERVICEHOME", |
3055 | &temp_service_path)) | 3036 | &temp_service_path)) |
3056 | { | 3037 | { |
3057 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3038 | GNUNET_log ( |
3039 | GNUNET_ERROR_TYPE_WARNING, | ||
3058 | _ | 3040 | _ |
3059 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), | 3041 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), |
3060 | "SERVICEHOME", "PATHS"); | 3042 | "SERVICEHOME", "PATHS"); |
3061 | if (UNLINK (mytemp) != 0) | 3043 | if (UNLINK (mytemp) != 0) |
3062 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", | 3044 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", |
3063 | mytemp); | 3045 | mytemp); |
3064 | GNUNET_free (mytemp); | 3046 | GNUNET_free (mytemp); |
3065 | break; | 3047 | break; |
3066 | } | 3048 | } |
3067 | 3049 | ||
3068 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ | 3050 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ |
3069 | { | 3051 | { |
3070 | GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); | 3052 | GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); |
3071 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", | 3053 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", |
3072 | "mv", mytemp, arg, | 3054 | mytemp, arg, NULL); |
3073 | NULL); | ||
3074 | #if VERBOSE_TESTING | 3055 | #if VERBOSE_TESTING |
3075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3056 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3076 | _("Copying file with command cp %s %s\n"), mytemp, arg); | 3057 | _("Copying file with command cp %s %s\n"), mytemp, arg); |
3077 | #endif | 3058 | #endif |
3078 | 3059 | ||
3079 | GNUNET_free (arg); | 3060 | GNUNET_free (arg); |
3080 | } | 3061 | } |
3081 | else /* Remote, scp the file to the correct place */ | 3062 | else /* Remote, scp the file to the correct place */ |
3082 | { | 3063 | { |
3083 | if (NULL != pg->peers[pg_iter].daemon->username) | 3064 | if (NULL != pg->peers[pg_iter].daemon->username) |
3084 | GNUNET_asprintf (&arg, "%s@%s:%s/blacklist", | 3065 | GNUNET_asprintf (&arg, "%s@%s:%s/blacklist", |
@@ -3089,16 +3070,15 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
3089 | GNUNET_asprintf (&arg, "%s:%s/blacklist", | 3070 | GNUNET_asprintf (&arg, "%s:%s/blacklist", |
3090 | pg->peers[pg_iter].daemon->hostname, | 3071 | pg->peers[pg_iter].daemon->hostname, |
3091 | temp_service_path); | 3072 | temp_service_path); |
3092 | procarr[pg_iter] = | 3073 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", |
3093 | GNUNET_OS_start_process (NULL, NULL, "scp", "scp", mytemp, arg, | 3074 | mytemp, arg, NULL); |
3094 | NULL); | ||
3095 | 3075 | ||
3096 | GNUNET_OS_process_wait(procarr[pg_iter]); /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */ | 3076 | GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */ |
3097 | 3077 | ||
3098 | #if VERBOSE_TESTING | 3078 | #if VERBOSE_TESTING |
3099 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3079 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3100 | _("Copying file with command scp %s %s\n"), mytemp, | 3080 | _("Copying file with command scp %s %s\n"), mytemp, |
3101 | arg); | 3081 | arg); |
3102 | #endif | 3082 | #endif |
3103 | GNUNET_free (arg); | 3083 | GNUNET_free (arg); |
3104 | } | 3084 | } |
@@ -3115,17 +3095,16 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
3115 | { | 3095 | { |
3116 | #if VERBOSE_TESTING | 3096 | #if VERBOSE_TESTING |
3117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3097 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3118 | _("Checking copy status of file %d\n"), pg_iter); | 3098 | _("Checking copy status of file %d\n"), pg_iter); |
3119 | #endif | 3099 | #endif |
3120 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ | 3100 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ |
3121 | { | 3101 | { |
3122 | if (GNUNET_OS_process_status | 3102 | if (GNUNET_OS_process_status (procarr[pg_iter], &type, |
3123 | (procarr[pg_iter], &type, &return_code) != GNUNET_OK) | 3103 | &return_code) != GNUNET_OK) |
3124 | { | 3104 | { |
3125 | ret = GNUNET_SYSERR; | 3105 | ret = GNUNET_SYSERR; |
3126 | } | 3106 | } |
3127 | else if ((type != GNUNET_OS_PROCESS_EXITED) | 3107 | else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0)) |
3128 | || (return_code != 0)) | ||
3129 | { | 3108 | { |
3130 | ret = GNUNET_SYSERR; | 3109 | ret = GNUNET_SYSERR; |
3131 | } | 3110 | } |
@@ -3135,7 +3114,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
3135 | procarr[pg_iter] = NULL; | 3114 | procarr[pg_iter] = NULL; |
3136 | #if VERBOSE_TESTING | 3115 | #if VERBOSE_TESTING |
3137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3138 | _("File %d copied\n"), pg_iter); | 3117 | _("File %d copied\n"), pg_iter); |
3139 | #endif | 3118 | #endif |
3140 | } | 3119 | } |
3141 | } | 3120 | } |
@@ -3150,7 +3129,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
3150 | 3129 | ||
3151 | #if VERBOSE_TESTING | 3130 | #if VERBOSE_TESTING |
3152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3131 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3153 | _("Finished copying all blacklist files!\n")); | 3132 | _("Finished copying all blacklist files!\n")); |
3154 | #endif | 3133 | #endif |
3155 | GNUNET_free (procarr); | 3134 | GNUNET_free (procarr); |
3156 | return ret; | 3135 | return ret; |
@@ -3158,7 +3137,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, | |||
3158 | 3137 | ||
3159 | /* Forward Declaration */ | 3138 | /* Forward Declaration */ |
3160 | static void | 3139 | static void |
3161 | schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 3140 | schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
3162 | 3141 | ||
3163 | /** | 3142 | /** |
3164 | * Choose a random peer's next connection to create, and | 3143 | * Choose a random peer's next connection to create, and |
@@ -3166,7 +3145,8 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
3166 | * | 3145 | * |
3167 | * @param ct_ctx the overall connection context | 3146 | * @param ct_ctx the overall connection context |
3168 | */ | 3147 | */ |
3169 | static void preschedule_connect(struct GNUNET_TESTING_PeerGroup *pg) | 3148 | static void |
3149 | preschedule_connect(struct GNUNET_TESTING_PeerGroup *pg) | ||
3170 | { | 3150 | { |
3171 | struct ConnectTopologyContext *ct_ctx = &pg->ct_ctx; | 3151 | struct ConnectTopologyContext *ct_ctx = &pg->ct_ctx; |
3172 | struct PeerConnection *connection_iter; | 3152 | struct PeerConnection *connection_iter; |
@@ -3175,9 +3155,11 @@ static void preschedule_connect(struct GNUNET_TESTING_PeerGroup *pg) | |||
3175 | 3155 | ||
3176 | if (ct_ctx->remaining_connections == 0) | 3156 | if (ct_ctx->remaining_connections == 0) |
3177 | return; | 3157 | return; |
3178 | random_peer = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, pg->total); | 3158 | random_peer |
3159 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total); | ||
3179 | while (pg->peers[random_peer].connect_peers_head == NULL) | 3160 | while (pg->peers[random_peer].connect_peers_head == NULL) |
3180 | random_peer = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, pg->total); | 3161 | random_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
3162 | pg->total); | ||
3181 | 3163 | ||
3182 | connection_iter = pg->peers[random_peer].connect_peers_head; | 3164 | connection_iter = pg->peers[random_peer].connect_peers_head; |
3183 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); | 3165 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); |
@@ -3194,7 +3176,6 @@ static void preschedule_connect(struct GNUNET_TESTING_PeerGroup *pg) | |||
3194 | /* Forward declaration */ | 3176 | /* Forward declaration */ |
3195 | static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 3177 | static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
3196 | 3178 | ||
3197 | |||
3198 | /** | 3179 | /** |
3199 | * Close connections and free the hello context. | 3180 | * Close connections and free the hello context. |
3200 | * | 3181 | * |
@@ -3203,26 +3184,26 @@ static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskC | |||
3203 | */ | 3184 | */ |
3204 | static void | 3185 | static void |
3205 | free_hello_context (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3186 | free_hello_context (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3206 | { | 3187 | { |
3207 | struct SendHelloContext *send_hello_context = cls; | 3188 | struct SendHelloContext *send_hello_context = cls; |
3208 | if (send_hello_context->peer->daemon->server != NULL) | 3189 | if (send_hello_context->peer->daemon->server != NULL) |
3209 | { | 3190 | { |
3210 | GNUNET_CORE_disconnect(send_hello_context->peer->daemon->server); | 3191 | GNUNET_CORE_disconnect(send_hello_context->peer->daemon->server); |
3211 | send_hello_context->peer->daemon->server = NULL; | 3192 | send_hello_context->peer->daemon->server = NULL; |
3212 | } | 3193 | } |
3213 | if (send_hello_context->peer->daemon->th != NULL) | 3194 | if (send_hello_context->peer->daemon->th != NULL) |
3214 | { | 3195 | { |
3215 | GNUNET_TRANSPORT_disconnect(send_hello_context->peer->daemon->th); | 3196 | GNUNET_TRANSPORT_disconnect(send_hello_context->peer->daemon->th); |
3216 | send_hello_context->peer->daemon->th = NULL; | 3197 | send_hello_context->peer->daemon->th = NULL; |
3217 | } | 3198 | } |
3218 | if (send_hello_context->core_connect_task != GNUNET_SCHEDULER_NO_TASK) | 3199 | if (send_hello_context->core_connect_task != GNUNET_SCHEDULER_NO_TASK) |
3219 | { | 3200 | { |
3220 | GNUNET_SCHEDULER_cancel(send_hello_context->core_connect_task); | 3201 | GNUNET_SCHEDULER_cancel(send_hello_context->core_connect_task); |
3221 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; | 3202 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; |
3222 | } | 3203 | } |
3223 | send_hello_context->pg->outstanding_connects--; | 3204 | send_hello_context->pg->outstanding_connects--; |
3224 | GNUNET_free(send_hello_context); | 3205 | GNUNET_free(send_hello_context); |
3225 | } | 3206 | } |
3226 | 3207 | ||
3227 | /** | 3208 | /** |
3228 | * For peers that haven't yet connected, notify | 3209 | * For peers that haven't yet connected, notify |
@@ -3233,40 +3214,39 @@ free_hello_context (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3233 | */ | 3214 | */ |
3234 | static void | 3215 | static void |
3235 | notify_remaining_connections_failed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3216 | notify_remaining_connections_failed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3236 | { | 3217 | { |
3237 | struct SendHelloContext *send_hello_context = cls; | 3218 | struct SendHelloContext *send_hello_context = cls; |
3238 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | 3219 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; |
3239 | struct PeerConnection *connection; | 3220 | struct PeerConnection *connection; |
3240 | 3221 | ||
3241 | GNUNET_CORE_disconnect(send_hello_context->peer->daemon->server); | 3222 | GNUNET_CORE_disconnect(send_hello_context->peer->daemon->server); |
3242 | send_hello_context->peer->daemon->server = NULL; | 3223 | send_hello_context->peer->daemon->server = NULL; |
3243 | 3224 | ||
3244 | connection = send_hello_context->peer->connect_peers_head; | 3225 | connection = send_hello_context->peer->connect_peers_head; |
3245 | 3226 | ||
3246 | while (connection != NULL) | 3227 | while (connection != NULL) |
3247 | { | 3228 | { |
3248 | if (pg->notify_connection != NULL) | 3229 | if (pg->notify_connection != NULL) |
3249 | { | 3230 | { |
3250 | pg->notify_connection(pg->notify_connection_cls, | 3231 | pg->notify_connection(pg->notify_connection_cls, |
3251 | &send_hello_context->peer->daemon->id, | 3232 | &send_hello_context->peer->daemon->id, |
3252 | &pg->peers[connection->index].daemon->id, | 3233 | &pg->peers[connection->index].daemon->id, |
3253 | 0, /* FIXME */ | 3234 | 0, /* FIXME */ |
3254 | send_hello_context->peer->daemon->cfg, | 3235 | send_hello_context->peer->daemon->cfg, |
3255 | pg->peers[connection->index].daemon->cfg, | 3236 | pg->peers[connection->index].daemon->cfg, |
3256 | send_hello_context->peer->daemon, | 3237 | send_hello_context->peer->daemon, |
3257 | pg->peers[connection->index].daemon, | 3238 | pg->peers[connection->index].daemon, |
3258 | "Peers failed to connect (timeout)"); | 3239 | "Peers failed to connect (timeout)"); |
3259 | } | 3240 | } |
3260 | GNUNET_CONTAINER_DLL_remove(send_hello_context->peer->connect_peers_head, send_hello_context->peer->connect_peers_tail, connection); | 3241 | GNUNET_CONTAINER_DLL_remove(send_hello_context->peer->connect_peers_head, send_hello_context->peer->connect_peers_tail, connection); |
3261 | GNUNET_free(connection); | 3242 | GNUNET_free(connection); |
3262 | connection = connection->next; | 3243 | connection = connection->next; |
3263 | } | 3244 | } |
3264 | GNUNET_SCHEDULER_add_now(&free_hello_context, send_hello_context); | 3245 | GNUNET_SCHEDULER_add_now(&free_hello_context, send_hello_context); |
3265 | #if BAD | 3246 | #if BAD |
3266 | other_peer = &pg->peers[connection->index]; | 3247 | other_peer = &pg->peers[connection->index]; |
3267 | #endif | 3248 | #endif |
3268 | } | 3249 | } |
3269 | |||
3270 | 3250 | ||
3271 | /** | 3251 | /** |
3272 | * For peers that haven't yet connected, send | 3252 | * For peers that haven't yet connected, send |
@@ -3277,38 +3257,37 @@ notify_remaining_connections_failed (void *cls, const struct GNUNET_SCHEDULER_Ta | |||
3277 | */ | 3257 | */ |
3278 | static void | 3258 | static void |
3279 | send_core_connect_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3259 | send_core_connect_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3280 | { | 3260 | { |
3281 | struct SendHelloContext *send_hello_context = cls; | 3261 | struct SendHelloContext *send_hello_context = cls; |
3282 | struct PeerConnection *conn; | 3262 | struct PeerConnection *conn; |
3283 | GNUNET_assert(send_hello_context->peer->daemon->server != NULL); | 3263 | GNUNET_assert(send_hello_context->peer->daemon->server != NULL); |
3284 | |||
3285 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; | ||
3286 | 3264 | ||
3287 | send_hello_context->connect_attempts++; | 3265 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; |
3288 | if (send_hello_context->connect_attempts < send_hello_context->pg->ct_ctx.connect_attempts) | ||
3289 | { | ||
3290 | conn = send_hello_context->peer->connect_peers_head; | ||
3291 | while (conn != NULL) | ||
3292 | { | ||
3293 | GNUNET_CORE_peer_request_connect(send_hello_context->peer->daemon->server, | ||
3294 | GNUNET_TIME_relative_get_forever(), | ||
3295 | &send_hello_context->pg->peers[conn->index].daemon->id, | ||
3296 | NULL, | ||
3297 | NULL); | ||
3298 | conn = conn->next; | ||
3299 | } | ||
3300 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(send_hello_context->pg->ct_ctx.connect_timeout, send_hello_context->pg->ct_ctx.connect_attempts) , | ||
3301 | &send_core_connect_requests, | ||
3302 | send_hello_context); | ||
3303 | } | ||
3304 | else | ||
3305 | { | ||
3306 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Timeout before all connections created, marking rest as failed!\n"); | ||
3307 | GNUNET_SCHEDULER_add_now(¬ify_remaining_connections_failed, send_hello_context); | ||
3308 | } | ||
3309 | 3266 | ||
3310 | } | 3267 | send_hello_context->connect_attempts++; |
3268 | if (send_hello_context->connect_attempts < send_hello_context->pg->ct_ctx.connect_attempts) | ||
3269 | { | ||
3270 | conn = send_hello_context->peer->connect_peers_head; | ||
3271 | while (conn != NULL) | ||
3272 | { | ||
3273 | GNUNET_CORE_peer_request_connect(send_hello_context->peer->daemon->server, | ||
3274 | GNUNET_TIME_relative_get_forever(), | ||
3275 | &send_hello_context->pg->peers[conn->index].daemon->id, | ||
3276 | NULL, | ||
3277 | NULL); | ||
3278 | conn = conn->next; | ||
3279 | } | ||
3280 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(send_hello_context->pg->ct_ctx.connect_timeout, send_hello_context->pg->ct_ctx.connect_attempts) , | ||
3281 | &send_core_connect_requests, | ||
3282 | send_hello_context); | ||
3283 | } | ||
3284 | else | ||
3285 | { | ||
3286 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Timeout before all connections created, marking rest as failed!\n"); | ||
3287 | GNUNET_SCHEDULER_add_now(¬ify_remaining_connections_failed, send_hello_context); | ||
3288 | } | ||
3311 | 3289 | ||
3290 | } | ||
3312 | 3291 | ||
3313 | /** | 3292 | /** |
3314 | * Success, connection is up. Signal client our success. | 3293 | * Success, connection is up. Signal client our success. |
@@ -3323,96 +3302,96 @@ send_core_connect_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext | |||
3323 | */ | 3302 | */ |
3324 | static void | 3303 | static void |
3325 | core_connect_notify (void *cls, | 3304 | core_connect_notify (void *cls, |
3326 | const struct GNUNET_PeerIdentity *peer, | 3305 | const struct GNUNET_PeerIdentity *peer, |
3327 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 3306 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
3328 | { | 3307 | { |
3329 | struct SendHelloContext *send_hello_context = cls; | 3308 | struct SendHelloContext *send_hello_context = cls; |
3330 | struct PeerConnection *connection; | 3309 | struct PeerConnection *connection; |
3331 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | 3310 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; |
3332 | #if BAD | 3311 | #if BAD |
3333 | struct PeerData *other_peer; | 3312 | struct PeerData *other_peer; |
3334 | #endif | 3313 | #endif |
3335 | #if DEBUG_TESTING | 3314 | #if DEBUG_TESTING |
3336 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3315 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3337 | "Connected peer %s to peer %s\n", | 3316 | "Connected peer %s to peer %s\n", |
3338 | ctx->d1->shortname, GNUNET_i2s(peer)); | 3317 | ctx->d1->shortname, GNUNET_i2s(peer)); |
3339 | #endif | 3318 | #endif |
3340 | 3319 | ||
3341 | if (0 == memcmp(&send_hello_context->peer->daemon->id, peer, sizeof(struct GNUNET_PeerIdentity))) | 3320 | if (0 == memcmp(&send_hello_context->peer->daemon->id, peer, sizeof(struct GNUNET_PeerIdentity))) |
3342 | return; | 3321 | return; |
3343 | 3322 | ||
3344 | connection = send_hello_context->peer->connect_peers_head; | 3323 | connection = send_hello_context->peer->connect_peers_head; |
3345 | #if BAD | 3324 | #if BAD |
3346 | other_peer = NULL; | 3325 | other_peer = NULL; |
3347 | #endif | 3326 | #endif |
3348 | 3327 | ||
3349 | while ((connection != NULL) && | 3328 | while ((connection != NULL) && |
3350 | (0 != memcmp(&pg->peers[connection->index].daemon->id, peer, sizeof(struct GNUNET_PeerIdentity)))) | 3329 | (0 != memcmp(&pg->peers[connection->index].daemon->id, peer, sizeof(struct GNUNET_PeerIdentity)))) |
3351 | { | 3330 | { |
3352 | connection = connection->next; | 3331 | connection = connection->next; |
3353 | } | 3332 | } |
3354 | 3333 | ||
3355 | if (connection == NULL) | 3334 | if (connection == NULL) |
3356 | { | 3335 | { |
3357 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Connected peer %s to %s, not in list (no problem(?))\n", GNUNET_i2s(peer), send_hello_context->peer->daemon->shortname); | 3336 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Connected peer %s to %s, not in list (no problem(?))\n", GNUNET_i2s(peer), send_hello_context->peer->daemon->shortname); |
3358 | } | 3337 | } |
3359 | else | 3338 | else |
3360 | { | 3339 | { |
3361 | #if BAD | 3340 | #if BAD |
3362 | other_peer = &pg->peers[connection->index]; | 3341 | other_peer = &pg->peers[connection->index]; |
3363 | #endif | 3342 | #endif |
3364 | if (pg->notify_connection != NULL) | 3343 | if (pg->notify_connection != NULL) |
3365 | { | 3344 | { |
3366 | pg->notify_connection(pg->notify_connection_cls, | 3345 | pg->notify_connection(pg->notify_connection_cls, |
3367 | &send_hello_context->peer->daemon->id, | 3346 | &send_hello_context->peer->daemon->id, |
3368 | peer, | 3347 | peer, |
3369 | 0, /* FIXME */ | 3348 | 0, /* FIXME */ |
3370 | send_hello_context->peer->daemon->cfg, | 3349 | send_hello_context->peer->daemon->cfg, |
3371 | pg->peers[connection->index].daemon->cfg, | 3350 | pg->peers[connection->index].daemon->cfg, |
3372 | send_hello_context->peer->daemon, | 3351 | send_hello_context->peer->daemon, |
3373 | pg->peers[connection->index].daemon, | 3352 | pg->peers[connection->index].daemon, |
3374 | NULL); | 3353 | NULL); |
3375 | } | 3354 | } |
3376 | GNUNET_CONTAINER_DLL_remove(send_hello_context->peer->connect_peers_head, send_hello_context->peer->connect_peers_tail, connection); | 3355 | GNUNET_CONTAINER_DLL_remove(send_hello_context->peer->connect_peers_head, send_hello_context->peer->connect_peers_tail, connection); |
3377 | GNUNET_free(connection); | 3356 | GNUNET_free(connection); |
3378 | } | 3357 | } |
3379 | 3358 | ||
3380 | #if BAD | 3359 | #if BAD |
3381 | /* Notify of reverse connection and remove from other peers list of outstanding */ | 3360 | /* Notify of reverse connection and remove from other peers list of outstanding */ |
3382 | if (other_peer != NULL) | 3361 | if (other_peer != NULL) |
3383 | { | 3362 | { |
3384 | connection = other_peer->connect_peers_head; | 3363 | connection = other_peer->connect_peers_head; |
3385 | while ((connection != NULL) && | 3364 | while ((connection != NULL) && |
3386 | (0 != memcmp(&send_hello_context->peer->daemon->id, &pg->peers[connection->index].daemon->id, sizeof(struct GNUNET_PeerIdentity)))) | 3365 | (0 != memcmp(&send_hello_context->peer->daemon->id, &pg->peers[connection->index].daemon->id, sizeof(struct GNUNET_PeerIdentity)))) |
3387 | { | 3366 | { |
3388 | connection = connection->next; | 3367 | connection = connection->next; |
3389 | } | 3368 | } |
3390 | if (connection != NULL) | 3369 | if (connection != NULL) |
3391 | { | 3370 | { |
3392 | if (pg->notify_connection != NULL) | 3371 | if (pg->notify_connection != NULL) |
3393 | { | 3372 | { |
3394 | pg->notify_connection(pg->notify_connection_cls, | 3373 | pg->notify_connection(pg->notify_connection_cls, |
3395 | peer, | 3374 | peer, |
3396 | &send_hello_context->peer->daemon->id, | 3375 | &send_hello_context->peer->daemon->id, |
3397 | 0, /* FIXME */ | 3376 | 0, /* FIXME */ |
3398 | pg->peers[connection->index].daemon->cfg, | 3377 | pg->peers[connection->index].daemon->cfg, |
3399 | send_hello_context->peer->daemon->cfg, | 3378 | send_hello_context->peer->daemon->cfg, |
3400 | pg->peers[connection->index].daemon, | 3379 | pg->peers[connection->index].daemon, |
3401 | send_hello_context->peer->daemon, | 3380 | send_hello_context->peer->daemon, |
3402 | NULL); | 3381 | NULL); |
3403 | } | 3382 | } |
3404 | 3383 | ||
3405 | GNUNET_CONTAINER_DLL_remove(other_peer->connect_peers_head, other_peer->connect_peers_tail, connection); | 3384 | GNUNET_CONTAINER_DLL_remove(other_peer->connect_peers_head, other_peer->connect_peers_tail, connection); |
3406 | GNUNET_free(connection); | 3385 | GNUNET_free(connection); |
3407 | } | 3386 | } |
3408 | } | 3387 | } |
3409 | #endif | 3388 | #endif |
3410 | 3389 | ||
3411 | if (send_hello_context->peer->connect_peers_head == NULL) | 3390 | if (send_hello_context->peer->connect_peers_head == NULL) |
3412 | { | 3391 | { |
3413 | GNUNET_SCHEDULER_add_now(&free_hello_context, send_hello_context); | 3392 | GNUNET_SCHEDULER_add_now(&free_hello_context, send_hello_context); |
3414 | } | 3393 | } |
3415 | } | 3394 | } |
3416 | 3395 | ||
3417 | /** | 3396 | /** |
3418 | * Notify of a successful connection to the core service. | 3397 | * Notify of a successful connection to the core service. |
@@ -3424,17 +3403,16 @@ core_connect_notify (void *cls, | |||
3424 | */ | 3403 | */ |
3425 | void | 3404 | void |
3426 | core_init (void *cls, | 3405 | core_init (void *cls, |
3427 | struct GNUNET_CORE_Handle * server, | 3406 | struct GNUNET_CORE_Handle * server, |
3428 | const struct GNUNET_PeerIdentity * | 3407 | const struct GNUNET_PeerIdentity * |
3429 | my_identity, | 3408 | my_identity, |
3430 | const struct | 3409 | const struct |
3431 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | 3410 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * |
3432 | publicKey) | 3411 | publicKey) |
3433 | { | 3412 | { |
3434 | struct SendHelloContext *send_hello_context = cls; | 3413 | struct SendHelloContext *send_hello_context = cls; |
3435 | send_hello_context->core_ready = GNUNET_YES; | 3414 | send_hello_context->core_ready = GNUNET_YES; |
3436 | } | 3415 | } |
3437 | |||
3438 | 3416 | ||
3439 | /** | 3417 | /** |
3440 | * Function called once a hello has been sent | 3418 | * Function called once a hello has been sent |
@@ -3446,56 +3424,55 @@ core_init (void *cls, | |||
3446 | */ | 3424 | */ |
3447 | static void | 3425 | static void |
3448 | hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3426 | hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3449 | { | 3427 | { |
3450 | struct SendHelloContext *send_hello_context = cls; | 3428 | struct SendHelloContext *send_hello_context = cls; |
3451 | //unsigned int pg_iter; | 3429 | //unsigned int pg_iter; |
3452 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 3430 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
3453 | { | 3431 | { |
3454 | GNUNET_free(send_hello_context); | 3432 | GNUNET_free(send_hello_context); |
3455 | return; | 3433 | return; |
3456 | } | 3434 | } |
3457 | 3435 | ||
3458 | send_hello_context->pg->remaining_hellos--; | 3436 | send_hello_context->pg->remaining_hellos--; |
3459 | #if DEBUG_TESTING | 3437 | #if DEBUG_TESTING |
3460 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sent HELLO, have %d remaining!\n", send_hello_context->pg->remaining_hellos); | 3438 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sent HELLO, have %d remaining!\n", send_hello_context->pg->remaining_hellos); |
3461 | #endif | 3439 | #endif |
3462 | if (send_hello_context->peer_pos == NULL) /* All HELLOs (for this peer!) have been transmitted! */ | 3440 | if (send_hello_context->peer_pos == NULL) /* All HELLOs (for this peer!) have been transmitted! */ |
3463 | { | 3441 | { |
3464 | #if DEBUG_TESTING | 3442 | #if DEBUG_TESTING |
3465 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All hellos for this peer sent, disconnecting transport!\n"); | 3443 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All hellos for this peer sent, disconnecting transport!\n"); |
3466 | #endif | 3444 | #endif |
3467 | GNUNET_assert(send_hello_context->peer->daemon->th != NULL); | 3445 | GNUNET_assert(send_hello_context->peer->daemon->th != NULL); |
3468 | GNUNET_TRANSPORT_disconnect(send_hello_context->peer->daemon->th); | 3446 | GNUNET_TRANSPORT_disconnect(send_hello_context->peer->daemon->th); |
3469 | send_hello_context->peer->daemon->th = NULL; | 3447 | send_hello_context->peer->daemon->th = NULL; |
3470 | 3448 | ||
3471 | /*if (send_hello_context->pg->remaining_hellos == 0) | 3449 | /*if (send_hello_context->pg->remaining_hellos == 0) |
3472 | { | 3450 | { |
3473 | for (pg_iter = 0; pg_iter < send_hello_context->pg->max_outstanding_connections; pg_iter++) | 3451 | for (pg_iter = 0; pg_iter < send_hello_context->pg->max_outstanding_connections; pg_iter++) |
3474 | { | 3452 | { |
3475 | preschedule_connect(&send_hello_context->pg->ct_ctx); | 3453 | preschedule_connect(&send_hello_context->pg->ct_ctx); |
3476 | } | 3454 | } |
3477 | } | 3455 | } |
3478 | */ | 3456 | */ |
3479 | GNUNET_assert (send_hello_context->peer->daemon->server == NULL); | 3457 | GNUNET_assert (send_hello_context->peer->daemon->server == NULL); |
3480 | send_hello_context->peer->daemon->server = GNUNET_CORE_connect(send_hello_context->peer->cfg, | 3458 | send_hello_context->peer->daemon->server = GNUNET_CORE_connect(send_hello_context->peer->cfg, |
3481 | 1, | 3459 | 1, |
3482 | send_hello_context, | 3460 | send_hello_context, |
3483 | &core_init, | 3461 | &core_init, |
3484 | &core_connect_notify, | 3462 | &core_connect_notify, |
3485 | NULL, | 3463 | NULL, |
3486 | NULL, | 3464 | NULL, |
3487 | NULL, GNUNET_NO, | 3465 | NULL, GNUNET_NO, |
3488 | NULL, GNUNET_NO, | 3466 | NULL, GNUNET_NO, |
3489 | no_handlers); | 3467 | no_handlers); |
3490 | 3468 | ||
3491 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(send_hello_context->pg->ct_ctx.connect_timeout, send_hello_context->pg->ct_ctx.connect_attempts), | 3469 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(send_hello_context->pg->ct_ctx.connect_timeout, send_hello_context->pg->ct_ctx.connect_attempts), |
3492 | &send_core_connect_requests, | 3470 | &send_core_connect_requests, |
3493 | send_hello_context); | 3471 | send_hello_context); |
3494 | } | 3472 | } |
3495 | else | 3473 | else |
3496 | GNUNET_SCHEDULER_add_now(&schedule_send_hellos, send_hello_context); | 3474 | GNUNET_SCHEDULER_add_now(&schedule_send_hellos, send_hello_context); |
3497 | } | 3475 | } |
3498 | |||
3499 | 3476 | ||
3500 | /** | 3477 | /** |
3501 | * Connect to a peer, give it all the HELLO's of those peers | 3478 | * Connect to a peer, give it all the HELLO's of those peers |
@@ -3504,78 +3481,74 @@ hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3504 | * @param ct_ctx the overall connection context | 3481 | * @param ct_ctx the overall connection context |
3505 | */ | 3482 | */ |
3506 | static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3483 | static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3507 | { | 3484 | { |
3508 | struct SendHelloContext *send_hello_context = cls; | 3485 | struct SendHelloContext *send_hello_context = cls; |
3509 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | 3486 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; |
3510 | 3487 | ||
3511 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 3488 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
3512 | { | 3489 | { |
3513 | GNUNET_free(send_hello_context); | 3490 | GNUNET_free(send_hello_context); |
3514 | return; | 3491 | return; |
3515 | } | 3492 | } |
3516 | 3493 | ||
3517 | GNUNET_assert(send_hello_context->peer_pos != NULL); /* All of the HELLO sends to be scheduled have been scheduled! */ | 3494 | GNUNET_assert(send_hello_context->peer_pos != NULL); /* All of the HELLO sends to be scheduled have been scheduled! */ |
3518 | 3495 | ||
3519 | if (((send_hello_context->peer->daemon->th == NULL) && | 3496 | if (((send_hello_context->peer->daemon->th == NULL) && |
3520 | (pg->outstanding_connects > pg->max_outstanding_connections)) || | 3497 | (pg->outstanding_connects > pg->max_outstanding_connections)) || |
3521 | (pg->stop_connects == GNUNET_YES)) | 3498 | (pg->stop_connects == GNUNET_YES)) |
3522 | { | 3499 | { |
3523 | #if VERBOSE_TESTING > 2 | 3500 | #if VERBOSE_TESTING > 2 |
3524 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3525 | _ | 3502 | _ |
3526 | ("Delaying connect, we have too many outstanding connections!\n")); | 3503 | ("Delaying connect, we have too many outstanding connections!\n")); |
3527 | #endif | 3504 | #endif |
3528 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 3505 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
3529 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 3506 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
3530 | &schedule_send_hellos, send_hello_context); | 3507 | &schedule_send_hellos, send_hello_context); |
3531 | } | 3508 | } |
3532 | else | 3509 | else |
3533 | { | 3510 | { |
3534 | #if VERBOSE_TESTING > 2 | 3511 | #if VERBOSE_TESTING > 2 |
3535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3536 | _("Creating connection, outstanding_connections is %d\n"), | 3513 | _("Creating connection, outstanding_connections is %d\n"), |
3537 | outstanding_connects); | 3514 | outstanding_connects); |
3538 | #endif | 3515 | #endif |
3539 | if (send_hello_context->peer->daemon->th == NULL) | 3516 | if (send_hello_context->peer->daemon->th == NULL) |
3540 | { | 3517 | { |
3541 | pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */ | 3518 | pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */ |
3542 | send_hello_context->peer->daemon->th = GNUNET_TRANSPORT_connect(send_hello_context->peer->cfg, | 3519 | send_hello_context->peer->daemon->th = GNUNET_TRANSPORT_connect(send_hello_context->peer->cfg, |
3543 | NULL, | 3520 | NULL, |
3544 | send_hello_context, | 3521 | send_hello_context, |
3545 | NULL, | 3522 | NULL, |
3546 | NULL, | 3523 | NULL, |
3547 | NULL); | 3524 | NULL); |
3548 | } | 3525 | } |
3549 | #if DEBUG_TESTING | 3526 | #if DEBUG_TESTING |
3550 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3527 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3551 | _("Offering Hello of peer %s to peer %s\n"), | 3528 | _("Offering Hello of peer %s to peer %s\n"), |
3552 | send_hello_context->peer->daemon->shortname, pg->peers[send_hello_context->peer_pos->index].daemon->shortname); | 3529 | send_hello_context->peer->daemon->shortname, pg->peers[send_hello_context->peer_pos->index].daemon->shortname); |
3553 | #endif | 3530 | #endif |
3554 | GNUNET_TRANSPORT_offer_hello(send_hello_context->peer->daemon->th, | 3531 | GNUNET_TRANSPORT_offer_hello(send_hello_context->peer->daemon->th, |
3555 | (const struct GNUNET_MessageHeader *)pg->peers[send_hello_context->peer_pos->index].daemon->hello, | 3532 | (const struct GNUNET_MessageHeader *)pg->peers[send_hello_context->peer_pos->index].daemon->hello, |
3556 | &hello_sent_callback, | 3533 | &hello_sent_callback, |
3557 | send_hello_context); | 3534 | send_hello_context); |
3558 | send_hello_context->peer_pos = send_hello_context->peer_pos->next; | 3535 | send_hello_context->peer_pos = send_hello_context->peer_pos->next; |
3559 | GNUNET_assert(send_hello_context->peer->daemon->th != NULL); | 3536 | GNUNET_assert(send_hello_context->peer->daemon->th != NULL); |
3560 | } | 3537 | } |
3561 | } | 3538 | } |
3562 | #endif | 3539 | #endif |
3563 | 3540 | ||
3564 | |||
3565 | /** | 3541 | /** |
3566 | * Internal notification of a connection, kept so that we can ensure some connections | 3542 | * Internal notification of a connection, kept so that we can ensure some connections |
3567 | * happen instead of flooding all testing daemons with requests to connect. | 3543 | * happen instead of flooding all testing daemons with requests to connect. |
3568 | */ | 3544 | */ |
3569 | static void | 3545 | static void |
3570 | internal_connect_notify (void *cls, | 3546 | internal_connect_notify(void *cls, const struct GNUNET_PeerIdentity *first, |
3571 | const struct GNUNET_PeerIdentity *first, | 3547 | const struct GNUNET_PeerIdentity *second, uint32_t distance, |
3572 | const struct GNUNET_PeerIdentity *second, | 3548 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, |
3573 | uint32_t distance, | 3549 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, |
3574 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, | 3550 | struct GNUNET_TESTING_Daemon *first_daemon, |
3575 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, | 3551 | struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) |
3576 | struct GNUNET_TESTING_Daemon *first_daemon, | ||
3577 | struct GNUNET_TESTING_Daemon *second_daemon, | ||
3578 | const char *emsg) | ||
3579 | { | 3552 | { |
3580 | struct ConnectContext *connect_ctx = cls; | 3553 | struct ConnectContext *connect_ctx = cls; |
3581 | struct ConnectTopologyContext *ct_ctx = connect_ctx->ct_ctx; | 3554 | struct ConnectTopologyContext *ct_ctx = connect_ctx->ct_ctx; |
@@ -3593,8 +3566,9 @@ internal_connect_notify (void *cls, | |||
3593 | other_peer = NULL; | 3566 | other_peer = NULL; |
3594 | #endif | 3567 | #endif |
3595 | 3568 | ||
3596 | while ((connection != NULL) && | 3569 | while ((connection != NULL) && (0 |
3597 | (0 != memcmp(first, &pg->peers[connection->index].daemon->id, sizeof(struct GNUNET_PeerIdentity)))) | 3570 | != memcmp (first, &pg->peers[connection->index].daemon->id, |
3571 | sizeof(struct GNUNET_PeerIdentity)))) | ||
3598 | { | 3572 | { |
3599 | connection = connection->next; | 3573 | connection = connection->next; |
3600 | } | 3574 | } |
@@ -3603,9 +3577,9 @@ internal_connect_notify (void *cls, | |||
3603 | { | 3577 | { |
3604 | ct_ctx->remaining_connections--; | 3578 | ct_ctx->remaining_connections--; |
3605 | if (pg->notify_connection != NULL) /* Notify of reverse connection */ | 3579 | if (pg->notify_connection != NULL) /* Notify of reverse connection */ |
3606 | pg->notify_connection (pg->notify_connection_cls, second, first, distance, | 3580 | pg->notify_connection (pg->notify_connection_cls, second, first, |
3607 | second_cfg, first_cfg, second_daemon, first_daemon, | 3581 | distance, second_cfg, first_cfg, second_daemon, |
3608 | emsg); | 3582 | first_daemon, emsg); |
3609 | 3583 | ||
3610 | GNUNET_CONTAINER_DLL_remove(pg->peers[connect_ctx->second_index].connect_peers_head, pg->peers[connect_ctx->second_index].connect_peers_tail, connection); | 3584 | GNUNET_CONTAINER_DLL_remove(pg->peers[connect_ctx->second_index].connect_peers_head, pg->peers[connect_ctx->second_index].connect_peers_tail, connection); |
3611 | GNUNET_free(connection); | 3585 | GNUNET_free(connection); |
@@ -3617,7 +3591,7 @@ internal_connect_notify (void *cls, | |||
3617 | ct_ctx->notify_connections_done (ct_ctx->notify_cls, NULL); | 3591 | ct_ctx->notify_connections_done (ct_ctx->notify_cls, NULL); |
3618 | } | 3592 | } |
3619 | else | 3593 | else |
3620 | preschedule_connect(pg); | 3594 | preschedule_connect (pg); |
3621 | 3595 | ||
3622 | if (pg->notify_connection != NULL) | 3596 | if (pg->notify_connection != NULL) |
3623 | pg->notify_connection (pg->notify_connection_cls, first, second, distance, | 3597 | pg->notify_connection (pg->notify_connection_cls, first, second, distance, |
@@ -3627,7 +3601,6 @@ internal_connect_notify (void *cls, | |||
3627 | GNUNET_free(connect_ctx); | 3601 | GNUNET_free(connect_ctx); |
3628 | } | 3602 | } |
3629 | 3603 | ||
3630 | |||
3631 | /** | 3604 | /** |
3632 | * Either delay a connection (because there are too many outstanding) | 3605 | * Either delay a connection (because there are too many outstanding) |
3633 | * or schedule it for right now. | 3606 | * or schedule it for right now. |
@@ -3636,7 +3609,7 @@ internal_connect_notify (void *cls, | |||
3636 | * @param tc the task runtime context | 3609 | * @param tc the task runtime context |
3637 | */ | 3610 | */ |
3638 | static void | 3611 | static void |
3639 | schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3612 | schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3640 | { | 3613 | { |
3641 | struct ConnectContext *connect_context = cls; | 3614 | struct ConnectContext *connect_context = cls; |
3642 | struct GNUNET_TESTING_PeerGroup *pg = connect_context->ct_ctx->pg; | 3615 | struct GNUNET_TESTING_PeerGroup *pg = connect_context->ct_ctx->pg; |
@@ -3644,37 +3617,40 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3644 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 3617 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
3645 | return; | 3618 | return; |
3646 | 3619 | ||
3647 | if ((pg->outstanding_connects > pg->max_outstanding_connections) || (pg->stop_connects == GNUNET_YES)) | 3620 | if ((pg->outstanding_connects > pg->max_outstanding_connections) |
3621 | || (pg->stop_connects == GNUNET_YES)) | ||
3648 | { | 3622 | { |
3649 | #if VERBOSE_TESTING | 3623 | #if VERBOSE_TESTING |
3650 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3624 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3651 | _ | 3625 | _ |
3652 | ("Delaying connect, we have too many outstanding connections!\n")); | 3626 | ("Delaying connect, we have too many outstanding connections!\n")); |
3653 | #endif | 3627 | #endif |
3654 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 3628 | GNUNET_SCHEDULER_add_delayed ( |
3655 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 3629 | GNUNET_TIME_relative_multiply ( |
3630 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
3631 | 100), | ||
3656 | &schedule_connect, connect_context); | 3632 | &schedule_connect, connect_context); |
3657 | } | 3633 | } |
3658 | else | 3634 | else |
3659 | { | 3635 | { |
3660 | #if VERBOSE_TESTING | 3636 | #if VERBOSE_TESTING |
3661 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3637 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3662 | _("Creating connection, outstanding_connections is %d (max %d)\n"), | 3638 | _("Creating connection, outstanding_connections is %d (max %d)\n"), |
3663 | pg->outstanding_connects, pg->max_outstanding_connections); | 3639 | pg->outstanding_connects, pg->max_outstanding_connections); |
3664 | #endif | 3640 | #endif |
3665 | pg->outstanding_connects++; | 3641 | pg->outstanding_connects++; |
3666 | pg->total_connects_scheduled++; | 3642 | pg->total_connects_scheduled++; |
3667 | GNUNET_TESTING_daemons_connect (pg->peers[connect_context->first_index].daemon, | 3643 | GNUNET_TESTING_daemons_connect ( |
3644 | pg->peers[connect_context->first_index].daemon, | ||
3668 | pg->peers[connect_context->second_index].daemon, | 3645 | pg->peers[connect_context->second_index].daemon, |
3669 | connect_context->ct_ctx->connect_timeout, | 3646 | connect_context->ct_ctx->connect_timeout, |
3670 | connect_context->ct_ctx->connect_attempts, | 3647 | connect_context->ct_ctx->connect_attempts, |
3671 | #if USE_SEND_HELLOS | 3648 | #if USE_SEND_HELLOS |
3672 | GNUNET_NO, | 3649 | GNUNET_NO, |
3673 | #else | 3650 | #else |
3674 | GNUNET_YES, | 3651 | GNUNET_YES, |
3675 | #endif | 3652 | #endif |
3676 | &internal_connect_notify, | 3653 | &internal_connect_notify, connect_context); /* FIXME: free connect context! */ |
3677 | connect_context); /* FIXME: free connect context! */ | ||
3678 | } | 3654 | } |
3679 | } | 3655 | } |
3680 | 3656 | ||
@@ -3691,20 +3667,20 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3691 | */ | 3667 | */ |
3692 | static int | 3668 | static int |
3693 | connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 3669 | connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
3694 | { | 3670 | { |
3695 | struct ConnectTopologyContext *ct_ctx = cls; | 3671 | struct ConnectTopologyContext *ct_ctx = cls; |
3696 | struct PeerData *first = ct_ctx->first; | 3672 | struct PeerData *first = ct_ctx->first; |
3697 | struct GNUNET_TESTING_Daemon *second = value; | 3673 | struct GNUNET_TESTING_Daemon *second = value; |
3698 | struct ConnectContext *connect_context; | 3674 | struct ConnectContext *connect_context; |
3699 | 3675 | ||
3700 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); | 3676 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); |
3701 | connect_context->first = first->daemon; | 3677 | connect_context->first = first->daemon; |
3702 | connect_context->second = second; | 3678 | connect_context->second = second; |
3703 | connect_context->ct_ctx = ct_ctx; | 3679 | connect_context->ct_ctx = ct_ctx; |
3704 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); | 3680 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); |
3705 | 3681 | ||
3706 | return GNUNET_YES; | 3682 | return GNUNET_YES; |
3707 | } | 3683 | } |
3708 | #endif | 3684 | #endif |
3709 | 3685 | ||
3710 | #if !OLD | 3686 | #if !OLD |
@@ -3720,16 +3696,16 @@ connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
3720 | */ | 3696 | */ |
3721 | static int | 3697 | static int |
3722 | copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 3698 | copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
3723 | { | 3699 | { |
3724 | struct PeerData *first = cls; | 3700 | struct PeerData *first = cls; |
3725 | 3701 | ||
3726 | GNUNET_assert (GNUNET_OK == | 3702 | GNUNET_assert (GNUNET_OK == |
3727 | GNUNET_CONTAINER_multihashmap_put (first->connect_peers, key, | 3703 | GNUNET_CONTAINER_multihashmap_put (first->connect_peers, key, |
3728 | value, | 3704 | value, |
3729 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3705 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
3730 | 3706 | ||
3731 | return GNUNET_YES; | 3707 | return GNUNET_YES; |
3732 | } | 3708 | } |
3733 | #endif | 3709 | #endif |
3734 | 3710 | ||
3735 | /** | 3711 | /** |
@@ -3739,7 +3715,7 @@ copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
3739 | * @param pg the peer group | 3715 | * @param pg the peer group |
3740 | */ | 3716 | */ |
3741 | static int | 3717 | static int |
3742 | copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg) | 3718 | copy_allowed_topology(struct GNUNET_TESTING_PeerGroup *pg) |
3743 | { | 3719 | { |
3744 | unsigned int pg_iter; | 3720 | unsigned int pg_iter; |
3745 | int ret; | 3721 | int ret; |
@@ -3755,17 +3731,20 @@ copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg) | |||
3755 | iter = pg->peers[pg_iter].allowed_peers_head; | 3731 | iter = pg->peers[pg_iter].allowed_peers_head; |
3756 | while (iter != NULL) | 3732 | while (iter != NULL) |
3757 | { | 3733 | { |
3758 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating connection between %d and %d\n", pg_iter, iter->index); | 3734 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3759 | total += add_connections(pg, pg_iter, iter->index, CONNECT, GNUNET_NO); | 3735 | "Creating connection between %d and %d\n", pg_iter, |
3736 | iter->index); | ||
3737 | total += add_connections (pg, pg_iter, iter->index, CONNECT, | ||
3738 | GNUNET_NO); | ||
3760 | //total += add_actual_connections(pg, pg_iter, iter->index); | 3739 | //total += add_actual_connections(pg, pg_iter, iter->index); |
3761 | iter = iter->next; | 3740 | iter = iter->next; |
3762 | } | 3741 | } |
3763 | #else | 3742 | #else |
3764 | ret = | 3743 | ret = |
3765 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | 3744 | GNUNET_CONTAINER_multihashmap_iterate (pg-> |
3766 | peers[pg_iter].allowed_peers, | 3745 | peers[pg_iter].allowed_peers, |
3767 | ©_topology_iterator, | 3746 | ©_topology_iterator, |
3768 | &pg->peers[pg_iter]); | 3747 | &pg->peers[pg_iter]); |
3769 | #endif | 3748 | #endif |
3770 | if (GNUNET_SYSERR == ret) | 3749 | if (GNUNET_SYSERR == ret) |
3771 | return GNUNET_SYSERR; | 3750 | return GNUNET_SYSERR; |
@@ -3776,7 +3755,6 @@ copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg) | |||
3776 | return total; | 3755 | return total; |
3777 | } | 3756 | } |
3778 | 3757 | ||
3779 | |||
3780 | /** | 3758 | /** |
3781 | * Connect the topology as specified by the PeerConnection's | 3759 | * Connect the topology as specified by the PeerConnection's |
3782 | * of each peer in the peer group | 3760 | * of each peer in the peer group |
@@ -3790,11 +3768,9 @@ copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg) | |||
3790 | * @return the number of connections that will be attempted | 3768 | * @return the number of connections that will be attempted |
3791 | */ | 3769 | */ |
3792 | static int | 3770 | static int |
3793 | connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | 3771 | connect_topology(struct GNUNET_TESTING_PeerGroup *pg, |
3794 | struct GNUNET_TIME_Relative connect_timeout, | 3772 | struct GNUNET_TIME_Relative connect_timeout, unsigned int connect_attempts, |
3795 | unsigned int connect_attempts, | 3773 | GNUNET_TESTING_NotifyCompletion notify_callback, void *notify_cls) |
3796 | GNUNET_TESTING_NotifyCompletion notify_callback, | ||
3797 | void *notify_cls) | ||
3798 | { | 3774 | { |
3799 | unsigned int pg_iter; | 3775 | unsigned int pg_iter; |
3800 | unsigned int total; | 3776 | unsigned int total; |
@@ -3822,7 +3798,7 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3822 | } | 3798 | } |
3823 | #else | 3799 | #else |
3824 | total += | 3800 | total += |
3825 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); | 3801 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); |
3826 | #endif | 3802 | #endif |
3827 | } | 3803 | } |
3828 | 3804 | ||
@@ -3847,14 +3823,13 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3847 | #else | 3823 | #else |
3848 | for (pg_iter = 0; pg_iter < pg->max_outstanding_connections; pg_iter++) | 3824 | for (pg_iter = 0; pg_iter < pg->max_outstanding_connections; pg_iter++) |
3849 | { | 3825 | { |
3850 | preschedule_connect(pg); | 3826 | preschedule_connect (pg); |
3851 | } | 3827 | } |
3852 | #endif | 3828 | #endif |
3853 | return total; | 3829 | return total; |
3854 | 3830 | ||
3855 | } | 3831 | } |
3856 | 3832 | ||
3857 | |||
3858 | /** | 3833 | /** |
3859 | * Takes a peer group and creates a topology based on the | 3834 | * Takes a peer group and creates a topology based on the |
3860 | * one specified. Creates a topology means generates friend | 3835 | * one specified. Creates a topology means generates friend |
@@ -3877,11 +3852,10 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3877 | * connected to each other | 3852 | * connected to each other |
3878 | */ | 3853 | */ |
3879 | unsigned int | 3854 | unsigned int |
3880 | GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | 3855 | GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, |
3881 | enum GNUNET_TESTING_Topology topology, | 3856 | enum GNUNET_TESTING_Topology topology, |
3882 | enum GNUNET_TESTING_Topology | 3857 | enum GNUNET_TESTING_Topology restrict_topology, |
3883 | restrict_topology, | 3858 | const char *restrict_transports) |
3884 | const char *restrict_transports) | ||
3885 | { | 3859 | { |
3886 | int ret; | 3860 | int ret; |
3887 | 3861 | ||
@@ -3897,114 +3871,116 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3897 | for (i = 0; i < pg->total; i++) | 3871 | for (i = 0; i < pg->total; i++) |
3898 | { | 3872 | { |
3899 | pg->peers[i].allowed_peers = | 3873 | pg->peers[i].allowed_peers = |
3900 | GNUNET_CONTAINER_multihashmap_create (100); | 3874 | GNUNET_CONTAINER_multihashmap_create (100); |
3901 | pg->peers[i].connect_peers = | 3875 | pg->peers[i].connect_peers = |
3902 | GNUNET_CONTAINER_multihashmap_create (100); | 3876 | GNUNET_CONTAINER_multihashmap_create (100); |
3903 | pg->peers[i].blacklisted_peers = | 3877 | pg->peers[i].blacklisted_peers = |
3904 | GNUNET_CONTAINER_multihashmap_create (100); | 3878 | GNUNET_CONTAINER_multihashmap_create (100); |
3905 | pg->peers[i].pg = pg; | 3879 | pg->peers[i].pg = pg; |
3906 | } | 3880 | } |
3907 | #endif | 3881 | #endif |
3908 | 3882 | ||
3909 | switch (topology) | 3883 | switch (topology) |
3910 | { | 3884 | { |
3911 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 3885 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
3912 | #if VERBOSE_TESTING | 3886 | #if VERBOSE_TESTING |
3913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n")); | 3887 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n")); |
3914 | #endif | 3888 | #endif |
3915 | num_connections = create_clique (pg, &add_connections, ALLOWED, GNUNET_NO); | 3889 | num_connections = create_clique (pg, &add_connections, ALLOWED, GNUNET_NO); |
3916 | break; | 3890 | break; |
3917 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 3891 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
3918 | #if VERBOSE_TESTING | 3892 | #if VERBOSE_TESTING |
3919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3893 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3920 | _("Creating small world (ring) topology\n")); | 3894 | _("Creating small world (ring) topology\n")); |
3921 | #endif | 3895 | #endif |
3922 | num_connections = | 3896 | num_connections = create_small_world_ring (pg, &add_connections, ALLOWED); |
3923 | create_small_world_ring (pg, &add_connections, ALLOWED); | 3897 | break; |
3924 | break; | 3898 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
3925 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | ||
3926 | #if VERBOSE_TESTING | 3899 | #if VERBOSE_TESTING |
3927 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3900 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3928 | _("Creating small world (2d-torus) topology\n")); | 3901 | _("Creating small world (2d-torus) topology\n")); |
3929 | #endif | 3902 | #endif |
3930 | num_connections = create_small_world (pg, &add_connections, ALLOWED); | 3903 | num_connections = create_small_world (pg, &add_connections, ALLOWED); |
3931 | break; | 3904 | break; |
3932 | case GNUNET_TESTING_TOPOLOGY_RING: | 3905 | case GNUNET_TESTING_TOPOLOGY_RING: |
3933 | #if VERBOSE_TESTING | 3906 | #if VERBOSE_TESTING |
3934 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating ring topology\n")); | 3907 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating ring topology\n")); |
3935 | #endif | 3908 | #endif |
3936 | num_connections = create_ring (pg, &add_connections, ALLOWED); | 3909 | num_connections = create_ring (pg, &add_connections, ALLOWED); |
3937 | break; | 3910 | break; |
3938 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 3911 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: |
3939 | #if VERBOSE_TESTING | 3912 | #if VERBOSE_TESTING |
3940 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating 2d torus topology\n")); | 3913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating 2d torus topology\n")); |
3941 | #endif | 3914 | #endif |
3942 | num_connections = create_2d_torus (pg, &add_connections, ALLOWED); | 3915 | num_connections = create_2d_torus (pg, &add_connections, ALLOWED); |
3943 | break; | 3916 | break; |
3944 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 3917 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
3945 | #if VERBOSE_TESTING | 3918 | #if VERBOSE_TESTING |
3946 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3947 | _("Creating Erdos-Renyi topology\n")); | 3920 | _("Creating Erdos-Renyi topology\n")); |
3948 | #endif | 3921 | #endif |
3949 | num_connections = create_erdos_renyi (pg, &add_connections, ALLOWED); | 3922 | num_connections = create_erdos_renyi (pg, &add_connections, ALLOWED); |
3950 | break; | 3923 | break; |
3951 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 3924 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
3952 | #if VERBOSE_TESTING | 3925 | #if VERBOSE_TESTING |
3953 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating InterNAT topology\n")); | 3926 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating InterNAT topology\n")); |
3954 | #endif | 3927 | #endif |
3955 | num_connections = create_nated_internet (pg, &add_connections, ALLOWED); | 3928 | num_connections = create_nated_internet (pg, &add_connections, ALLOWED); |
3956 | break; | 3929 | break; |
3957 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 3930 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
3958 | #if VERBOSE_TESTING | 3931 | #if VERBOSE_TESTING |
3959 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3932 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3960 | _("Creating Scale Free topology\n")); | 3933 | _("Creating Scale Free topology\n")); |
3961 | #endif | 3934 | #endif |
3962 | num_connections = create_scale_free (pg, &add_connections, ALLOWED); | 3935 | num_connections = create_scale_free (pg, &add_connections, ALLOWED); |
3963 | break; | 3936 | break; |
3964 | case GNUNET_TESTING_TOPOLOGY_LINE: | 3937 | case GNUNET_TESTING_TOPOLOGY_LINE: |
3965 | #if VERBOSE_TESTING | 3938 | #if VERBOSE_TESTING |
3966 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3939 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3967 | _("Creating straight line topology\n")); | 3940 | _("Creating straight line topology\n")); |
3968 | #endif | 3941 | #endif |
3969 | num_connections = create_line (pg, &add_connections, ALLOWED); | 3942 | num_connections = create_line (pg, &add_connections, ALLOWED); |
3970 | break; | 3943 | break; |
3971 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: | 3944 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: |
3972 | #if VERBOSE_TESTING | 3945 | #if VERBOSE_TESTING |
3973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3946 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3974 | _("Creating topology from file!\n")); | 3947 | _("Creating topology from file!\n")); |
3975 | #endif | 3948 | #endif |
3976 | if (GNUNET_OK == | 3949 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing", |
3977 | GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing", "topology_file", | 3950 | "topology_file", |
3978 | &filename)) | 3951 | &filename)) |
3979 | num_connections = create_from_file (pg, filename, &add_connections, ALLOWED); | 3952 | num_connections = create_from_file (pg, filename, &add_connections, |
3980 | else | 3953 | ALLOWED); |
3954 | else | ||
3981 | { | 3955 | { |
3982 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Missing configuration option TESTING:TOPOLOGY_FILE for creating topology from file!\n"); | 3956 | GNUNET_log ( |
3957 | GNUNET_ERROR_TYPE_WARNING, | ||
3958 | "Missing configuration option TESTING:TOPOLOGY_FILE for creating topology from file!\n"); | ||
3983 | num_connections = 0; | 3959 | num_connections = 0; |
3984 | } | 3960 | } |
3985 | break; | 3961 | break; |
3986 | case GNUNET_TESTING_TOPOLOGY_NONE: | 3962 | case GNUNET_TESTING_TOPOLOGY_NONE: |
3987 | #if VERBOSE_TESTING | 3963 | #if VERBOSE_TESTING |
3988 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3964 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3989 | _ | 3965 | _ |
3990 | ("Creating no allowed topology (all peers can connect at core level)\n")); | 3966 | ("Creating no allowed topology (all peers can connect at core level)\n")); |
3991 | #endif | 3967 | #endif |
3992 | num_connections = pg->total * pg->total; /* Clique is allowed! */ | 3968 | num_connections = pg->total * pg->total; /* Clique is allowed! */ |
3993 | break; | 3969 | break; |
3994 | default: | 3970 | default: |
3995 | num_connections = 0; | 3971 | num_connections = 0; |
3996 | break; | 3972 | break; |
3997 | } | 3973 | } |
3998 | 3974 | ||
3999 | if (GNUNET_YES == | 3975 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", |
4000 | GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F")) | 3976 | "F2F")) |
4001 | { | 3977 | { |
4002 | ret = create_and_copy_friend_files (pg); | 3978 | ret = create_and_copy_friend_files (pg); |
4003 | if (ret != GNUNET_OK) | 3979 | if (ret != GNUNET_OK) |
4004 | { | 3980 | { |
4005 | #if VERBOSE_TESTING | 3981 | #if VERBOSE_TESTING |
4006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4007 | _("Failed during friend file copying!\n")); | 3983 | _("Failed during friend file copying!\n")); |
4008 | #endif | 3984 | #endif |
4009 | return GNUNET_SYSERR; | 3985 | return GNUNET_SYSERR; |
4010 | } | 3986 | } |
@@ -4012,71 +3988,74 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
4012 | { | 3988 | { |
4013 | #if VERBOSE_TESTING | 3989 | #if VERBOSE_TESTING |
4014 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3990 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4015 | _("Friend files created/copied successfully!\n")); | 3991 | _("Friend files created/copied successfully!\n")); |
4016 | #endif | 3992 | #endif |
4017 | } | 3993 | } |
4018 | } | 3994 | } |
4019 | 3995 | ||
4020 | /* Use the create clique method to initially set all connections as blacklisted. */ | 3996 | /* Use the create clique method to initially set all connections as blacklisted. */ |
4021 | if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology != GNUNET_TESTING_TOPOLOGY_FROM_FILE)) | 3997 | if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology |
3998 | != GNUNET_TESTING_TOPOLOGY_FROM_FILE)) | ||
4022 | create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO); | 3999 | create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO); |
4023 | 4000 | ||
4024 | unblacklisted_connections = 0; | 4001 | unblacklisted_connections = 0; |
4025 | /* Un-blacklist connections as per the topology specified */ | 4002 | /* Un-blacklist connections as per the topology specified */ |
4026 | switch (restrict_topology) | 4003 | switch (restrict_topology) |
4027 | { | 4004 | { |
4028 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 4005 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
4029 | #if VERBOSE_TESTING | 4006 | #if VERBOSE_TESTING |
4030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4007 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4031 | _("Blacklisting all but clique topology\n")); | 4008 | _("Blacklisting all but clique topology\n")); |
4032 | #endif | 4009 | #endif |
4033 | unblacklisted_connections = | 4010 | unblacklisted_connections = create_clique (pg, &remove_connections, |
4034 | create_clique (pg, &remove_connections, BLACKLIST, GNUNET_NO); | 4011 | BLACKLIST, GNUNET_NO); |
4035 | break; | 4012 | break; |
4036 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 4013 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
4037 | #if VERBOSE_TESTING | 4014 | #if VERBOSE_TESTING |
4038 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4015 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4039 | _("Blacklisting all but small world (ring) topology\n")); | 4016 | _("Blacklisting all but small world (ring) topology\n")); |
4040 | #endif | 4017 | #endif |
4041 | unblacklisted_connections = | 4018 | unblacklisted_connections = create_small_world_ring (pg, |
4042 | create_small_world_ring (pg, &remove_connections, BLACKLIST); | 4019 | &remove_connections, |
4043 | break; | 4020 | BLACKLIST); |
4044 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 4021 | break; |
4022 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | ||
4045 | #if VERBOSE_TESTING | 4023 | #if VERBOSE_TESTING |
4046 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4024 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4047 | _ | 4025 | _ |
4048 | ("Blacklisting all but small world (2d-torus) topology\n")); | 4026 | ("Blacklisting all but small world (2d-torus) topology\n")); |
4049 | #endif | 4027 | #endif |
4050 | unblacklisted_connections = | 4028 | unblacklisted_connections = create_small_world (pg, &remove_connections, |
4051 | create_small_world (pg, &remove_connections, BLACKLIST); | 4029 | BLACKLIST); |
4052 | break; | 4030 | break; |
4053 | case GNUNET_TESTING_TOPOLOGY_RING: | 4031 | case GNUNET_TESTING_TOPOLOGY_RING: |
4054 | #if VERBOSE_TESTING | 4032 | #if VERBOSE_TESTING |
4055 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4033 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4056 | _("Blacklisting all but ring topology\n")); | 4034 | _("Blacklisting all but ring topology\n")); |
4057 | #endif | 4035 | #endif |
4058 | unblacklisted_connections = create_ring (pg, &remove_connections, BLACKLIST); | 4036 | unblacklisted_connections |
4059 | break; | 4037 | = create_ring (pg, &remove_connections, BLACKLIST); |
4060 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 4038 | break; |
4039 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | ||
4061 | #if VERBOSE_TESTING | 4040 | #if VERBOSE_TESTING |
4062 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4063 | _("Blacklisting all but 2d torus topology\n")); | 4042 | _("Blacklisting all but 2d torus topology\n")); |
4064 | #endif | 4043 | #endif |
4065 | unblacklisted_connections = | 4044 | unblacklisted_connections = create_2d_torus (pg, &remove_connections, |
4066 | create_2d_torus (pg, &remove_connections, BLACKLIST); | 4045 | BLACKLIST); |
4067 | break; | 4046 | break; |
4068 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 4047 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
4069 | #if VERBOSE_TESTING | 4048 | #if VERBOSE_TESTING |
4070 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4049 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4071 | _("Blacklisting all but Erdos-Renyi topology\n")); | 4050 | _("Blacklisting all but Erdos-Renyi topology\n")); |
4072 | #endif | 4051 | #endif |
4073 | unblacklisted_connections = | 4052 | unblacklisted_connections = create_erdos_renyi (pg, &remove_connections, |
4074 | create_erdos_renyi (pg, &remove_connections, BLACKLIST); | 4053 | BLACKLIST); |
4075 | break; | 4054 | break; |
4076 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 4055 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
4077 | #if VERBOSE_TESTING | 4056 | #if VERBOSE_TESTING |
4078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4057 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4079 | _("Blacklisting all but InterNAT topology\n")); | 4058 | _("Blacklisting all but InterNAT topology\n")); |
4080 | #endif | 4059 | #endif |
4081 | 4060 | ||
4082 | #if TOPOLOGY_HACK | 4061 | #if TOPOLOGY_HACK |
@@ -4102,52 +4081,54 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
4102 | pg->peers[off].connect_peers_head = NULL; | 4081 | pg->peers[off].connect_peers_head = NULL; |
4103 | pg->peers[off].connect_peers_tail = NULL; | 4082 | pg->peers[off].connect_peers_tail = NULL; |
4104 | } | 4083 | } |
4105 | unblacklisted_connections = create_nated_internet_copy(pg, &remove_connections, BLACKLIST); | 4084 | unblacklisted_connections |
4085 | = create_nated_internet_copy (pg, &remove_connections, BLACKLIST); | ||
4106 | #else | 4086 | #else |
4107 | unblacklisted_connections = | 4087 | unblacklisted_connections = |
4108 | create_nated_internet (pg, &remove_connections, BLACKLIST); | 4088 | create_nated_internet (pg, &remove_connections, BLACKLIST); |
4109 | #endif | 4089 | #endif |
4110 | 4090 | ||
4111 | break; | 4091 | break; |
4112 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 4092 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
4113 | #if VERBOSE_TESTING | 4093 | #if VERBOSE_TESTING |
4114 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4094 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4115 | _("Blacklisting all but Scale Free topology\n")); | 4095 | _("Blacklisting all but Scale Free topology\n")); |
4116 | #endif | 4096 | #endif |
4117 | unblacklisted_connections = | 4097 | unblacklisted_connections = create_scale_free (pg, &remove_connections, |
4118 | create_scale_free (pg, &remove_connections, BLACKLIST); | 4098 | BLACKLIST); |
4119 | break; | 4099 | break; |
4120 | case GNUNET_TESTING_TOPOLOGY_LINE: | 4100 | case GNUNET_TESTING_TOPOLOGY_LINE: |
4121 | #if VERBOSE_TESTING | 4101 | #if VERBOSE_TESTING |
4122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4123 | _("Blacklisting all but straight line topology\n")); | 4103 | _("Blacklisting all but straight line topology\n")); |
4124 | #endif | 4104 | #endif |
4125 | unblacklisted_connections = create_line (pg, &remove_connections, BLACKLIST); | 4105 | unblacklisted_connections |
4126 | break; | 4106 | = create_line (pg, &remove_connections, BLACKLIST); |
4127 | case GNUNET_TESTING_TOPOLOGY_NONE: /* Fall through */ | 4107 | break; |
4128 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: | 4108 | case GNUNET_TESTING_TOPOLOGY_NONE: /* Fall through */ |
4109 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: | ||
4129 | #if VERBOSE_TESTING | 4110 | #if VERBOSE_TESTING |
4130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4131 | _ | ||
4132 | ("Creating no blacklist topology (all peers can connect at transport level)\n")); | ||
4133 | #endif | ||
4134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4135 | _ | 4112 | _ |
4136 | ("Creating blacklist topology from allowed\n")); | 4113 | ("Creating no blacklist topology (all peers can connect at transport level)\n")); |
4114 | #endif | ||
4115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ | ||
4116 | ("Creating blacklist topology from allowed\n")); | ||
4137 | unblacklisted_connections = copy_allowed (pg, &remove_connections); | 4117 | unblacklisted_connections = copy_allowed (pg, &remove_connections); |
4138 | default: | 4118 | default: |
4139 | break; | 4119 | break; |
4140 | } | 4120 | } |
4141 | 4121 | ||
4142 | if ((unblacklisted_connections > 0) && (restrict_transports != NULL)) | 4122 | if ((unblacklisted_connections > 0) && (restrict_transports != NULL)) |
4143 | { | 4123 | { |
4144 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'\n", restrict_transports); | 4124 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'\n", |
4125 | restrict_transports); | ||
4145 | ret = create_and_copy_blacklist_files (pg, restrict_transports); | 4126 | ret = create_and_copy_blacklist_files (pg, restrict_transports); |
4146 | if (ret != GNUNET_OK) | 4127 | if (ret != GNUNET_OK) |
4147 | { | 4128 | { |
4148 | #if VERBOSE_TESTING | 4129 | #if VERBOSE_TESTING |
4149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4150 | _("Failed during blacklist file copying!\n")); | 4131 | _("Failed during blacklist file copying!\n")); |
4151 | #endif | 4132 | #endif |
4152 | return 0; | 4133 | return 0; |
4153 | } | 4134 | } |
@@ -4155,14 +4136,13 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
4155 | { | 4136 | { |
4156 | #if VERBOSE_TESTING | 4137 | #if VERBOSE_TESTING |
4157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4158 | _("Blacklist files created/copied successfully!\n")); | 4139 | _("Blacklist files created/copied successfully!\n")); |
4159 | #endif | 4140 | #endif |
4160 | } | 4141 | } |
4161 | } | 4142 | } |
4162 | return num_connections; | 4143 | return num_connections; |
4163 | } | 4144 | } |
4164 | 4145 | ||
4165 | |||
4166 | #if !OLD | 4146 | #if !OLD |
4167 | /** | 4147 | /** |
4168 | * Iterator for choosing random peers to connect. | 4148 | * Iterator for choosing random peers to connect. |
@@ -4175,39 +4155,38 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
4175 | */ | 4155 | */ |
4176 | static int | 4156 | static int |
4177 | random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 4157 | random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
4178 | { | 4158 | { |
4179 | struct RandomContext *random_ctx = cls; | 4159 | struct RandomContext *random_ctx = cls; |
4180 | double random_number; | 4160 | double random_number; |
4181 | uint32_t second_pos; | 4161 | uint32_t second_pos; |
4182 | GNUNET_HashCode first_hash; | 4162 | GNUNET_HashCode first_hash; |
4183 | random_number = | 4163 | random_number = |
4184 | ((double) | 4164 | ((double) |
4185 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 4165 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
4186 | UINT64_MAX)) / ((double) UINT64_MAX); | 4166 | UINT64_MAX)) / ((double) UINT64_MAX); |
4187 | if (random_number < random_ctx->percentage) | 4167 | if (random_number < random_ctx->percentage) |
4188 | { | 4168 | { |
4189 | GNUNET_assert (GNUNET_OK == | 4169 | GNUNET_assert (GNUNET_OK == |
4190 | GNUNET_CONTAINER_multihashmap_put (random_ctx-> | 4170 | GNUNET_CONTAINER_multihashmap_put (random_ctx-> |
4191 | first->connect_peers_working_set, | 4171 | first->connect_peers_working_set, |
4192 | key, value, | 4172 | key, value, |
4193 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 4173 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
4194 | } | 4174 | } |
4195 | |||
4196 | /* Now we have considered this particular connection, remove it from the second peer so it's not double counted */ | ||
4197 | uid_from_hash (key, &second_pos); | ||
4198 | hash_from_uid (random_ctx->first_uid, &first_hash); | ||
4199 | GNUNET_assert (random_ctx->pg->total > second_pos); | ||
4200 | GNUNET_assert (GNUNET_YES == | ||
4201 | GNUNET_CONTAINER_multihashmap_remove (random_ctx-> | ||
4202 | pg->peers | ||
4203 | [second_pos].connect_peers, | ||
4204 | &first_hash, | ||
4205 | random_ctx-> | ||
4206 | first->daemon)); | ||
4207 | 4175 | ||
4208 | return GNUNET_YES; | 4176 | /* Now we have considered this particular connection, remove it from the second peer so it's not double counted */ |
4209 | } | 4177 | uid_from_hash (key, &second_pos); |
4178 | hash_from_uid (random_ctx->first_uid, &first_hash); | ||
4179 | GNUNET_assert (random_ctx->pg->total > second_pos); | ||
4180 | GNUNET_assert (GNUNET_YES == | ||
4181 | GNUNET_CONTAINER_multihashmap_remove (random_ctx-> | ||
4182 | pg->peers | ||
4183 | [second_pos].connect_peers, | ||
4184 | &first_hash, | ||
4185 | random_ctx-> | ||
4186 | first->daemon)); | ||
4210 | 4187 | ||
4188 | return GNUNET_YES; | ||
4189 | } | ||
4211 | 4190 | ||
4212 | /** | 4191 | /** |
4213 | * Iterator for adding at least X peers to a peers connection set. | 4192 | * Iterator for adding at least X peers to a peers connection set. |
@@ -4220,50 +4199,49 @@ random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
4220 | */ | 4199 | */ |
4221 | static int | 4200 | static int |
4222 | minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 4201 | minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
4223 | { | 4202 | { |
4224 | struct MinimumContext *min_ctx = cls; | 4203 | struct MinimumContext *min_ctx = cls; |
4225 | uint32_t second_pos; | 4204 | uint32_t second_pos; |
4226 | GNUNET_HashCode first_hash; | 4205 | GNUNET_HashCode first_hash; |
4227 | unsigned int i; | 4206 | unsigned int i; |
4228 | |||
4229 | if (GNUNET_CONTAINER_multihashmap_size | ||
4230 | (min_ctx->first->connect_peers_working_set) < min_ctx->num_to_add) | ||
4231 | { | ||
4232 | for (i = 0; i < min_ctx->num_to_add; i++) | ||
4233 | { | ||
4234 | if (min_ctx->pg_array[i] == min_ctx->current) | ||
4235 | { | ||
4236 | GNUNET_assert (GNUNET_OK == | ||
4237 | GNUNET_CONTAINER_multihashmap_put | ||
4238 | (min_ctx->first->connect_peers_working_set, key, | ||
4239 | value, | ||
4240 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4241 | uid_from_hash (key, &second_pos); | ||
4242 | hash_from_uid (min_ctx->first_uid, &first_hash); | ||
4243 | GNUNET_assert (min_ctx->pg->total > second_pos); | ||
4244 | GNUNET_assert (GNUNET_OK == | ||
4245 | GNUNET_CONTAINER_multihashmap_put (min_ctx-> | ||
4246 | pg->peers | ||
4247 | [second_pos].connect_peers_working_set, | ||
4248 | &first_hash, | ||
4249 | min_ctx->first-> | ||
4250 | daemon, | ||
4251 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4252 | /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */ | ||
4253 | GNUNET_assert (GNUNET_YES == | ||
4254 | GNUNET_CONTAINER_multihashmap_remove | ||
4255 | (min_ctx->pg->peers[second_pos].connect_peers, | ||
4256 | &first_hash, min_ctx->first->daemon)); | ||
4257 | } | ||
4258 | } | ||
4259 | min_ctx->current++; | ||
4260 | return GNUNET_YES; | ||
4261 | } | ||
4262 | else | ||
4263 | return GNUNET_NO; /* We can stop iterating, we have enough peers! */ | ||
4264 | 4207 | ||
4265 | } | 4208 | if (GNUNET_CONTAINER_multihashmap_size |
4209 | (min_ctx->first->connect_peers_working_set) < min_ctx->num_to_add) | ||
4210 | { | ||
4211 | for (i = 0; i < min_ctx->num_to_add; i++) | ||
4212 | { | ||
4213 | if (min_ctx->pg_array[i] == min_ctx->current) | ||
4214 | { | ||
4215 | GNUNET_assert (GNUNET_OK == | ||
4216 | GNUNET_CONTAINER_multihashmap_put | ||
4217 | (min_ctx->first->connect_peers_working_set, key, | ||
4218 | value, | ||
4219 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4220 | uid_from_hash (key, &second_pos); | ||
4221 | hash_from_uid (min_ctx->first_uid, &first_hash); | ||
4222 | GNUNET_assert (min_ctx->pg->total > second_pos); | ||
4223 | GNUNET_assert (GNUNET_OK == | ||
4224 | GNUNET_CONTAINER_multihashmap_put (min_ctx-> | ||
4225 | pg->peers | ||
4226 | [second_pos].connect_peers_working_set, | ||
4227 | &first_hash, | ||
4228 | min_ctx->first-> | ||
4229 | daemon, | ||
4230 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4231 | /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */ | ||
4232 | GNUNET_assert (GNUNET_YES == | ||
4233 | GNUNET_CONTAINER_multihashmap_remove | ||
4234 | (min_ctx->pg->peers[second_pos].connect_peers, | ||
4235 | &first_hash, min_ctx->first->daemon)); | ||
4236 | } | ||
4237 | } | ||
4238 | min_ctx->current++; | ||
4239 | return GNUNET_YES; | ||
4240 | } | ||
4241 | else | ||
4242 | return GNUNET_NO; /* We can stop iterating, we have enough peers! */ | ||
4266 | 4243 | ||
4244 | } | ||
4267 | 4245 | ||
4268 | /** | 4246 | /** |
4269 | * Iterator for adding peers to a connection set based on a depth first search. | 4247 | * Iterator for adding peers to a connection set based on a depth first search. |
@@ -4276,41 +4254,41 @@ minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
4276 | */ | 4254 | */ |
4277 | static int | 4255 | static int |
4278 | dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 4256 | dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
4279 | { | 4257 | { |
4280 | struct DFSContext *dfs_ctx = cls; | 4258 | struct DFSContext *dfs_ctx = cls; |
4281 | GNUNET_HashCode first_hash; | 4259 | GNUNET_HashCode first_hash; |
4282 | 4260 | ||
4283 | if (dfs_ctx->current == dfs_ctx->chosen) | 4261 | if (dfs_ctx->current == dfs_ctx->chosen) |
4284 | { | 4262 | { |
4285 | GNUNET_assert (GNUNET_OK == | 4263 | GNUNET_assert (GNUNET_OK == |
4286 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> | 4264 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> |
4287 | first->connect_peers_working_set, | 4265 | first->connect_peers_working_set, |
4288 | key, value, | 4266 | key, value, |
4289 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 4267 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
4290 | uid_from_hash (key, &dfs_ctx->second_uid); | 4268 | uid_from_hash (key, &dfs_ctx->second_uid); |
4291 | hash_from_uid (dfs_ctx->first_uid, &first_hash); | 4269 | hash_from_uid (dfs_ctx->first_uid, &first_hash); |
4292 | GNUNET_assert (GNUNET_OK == | 4270 | GNUNET_assert (GNUNET_OK == |
4293 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> | 4271 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> |
4294 | pg->peers | 4272 | pg->peers |
4295 | [dfs_ctx->second_uid].connect_peers_working_set, | 4273 | [dfs_ctx->second_uid].connect_peers_working_set, |
4296 | &first_hash, | 4274 | &first_hash, |
4297 | dfs_ctx-> | 4275 | dfs_ctx-> |
4298 | first->daemon, | 4276 | first->daemon, |
4299 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 4277 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
4300 | GNUNET_assert (GNUNET_YES == | 4278 | GNUNET_assert (GNUNET_YES == |
4301 | GNUNET_CONTAINER_multihashmap_remove (dfs_ctx-> | 4279 | GNUNET_CONTAINER_multihashmap_remove (dfs_ctx-> |
4302 | pg->peers | 4280 | pg->peers |
4303 | [dfs_ctx->second_uid].connect_peers, | 4281 | [dfs_ctx->second_uid].connect_peers, |
4304 | &first_hash, | 4282 | &first_hash, |
4305 | dfs_ctx-> | 4283 | dfs_ctx-> |
4306 | first->daemon)); | 4284 | first->daemon)); |
4307 | /* Can't remove second from first yet because we are currently iterating, hence the return value in the DFSContext! */ | 4285 | /* Can't remove second from first yet because we are currently iterating, hence the return value in the DFSContext! */ |
4308 | return GNUNET_NO; /* We have found our peer, don't iterate more */ | 4286 | return GNUNET_NO; /* We have found our peer, don't iterate more */ |
4309 | } | 4287 | } |
4310 | 4288 | ||
4311 | dfs_ctx->current++; | 4289 | dfs_ctx->current++; |
4312 | return GNUNET_YES; | 4290 | return GNUNET_YES; |
4313 | } | 4291 | } |
4314 | #endif | 4292 | #endif |
4315 | 4293 | ||
4316 | /** | 4294 | /** |
@@ -4321,8 +4299,8 @@ dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
4321 | * @param percentage what percent of total connections to make | 4299 | * @param percentage what percent of total connections to make |
4322 | */ | 4300 | */ |
4323 | void | 4301 | void |
4324 | choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, | 4302 | choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg, |
4325 | double percentage) | 4303 | double percentage) |
4326 | { | 4304 | { |
4327 | struct RandomContext random_ctx; | 4305 | struct RandomContext random_ctx; |
4328 | uint32_t pg_iter; | 4306 | uint32_t pg_iter; |
@@ -4343,28 +4321,29 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
4343 | conn_iter = pg->peers[pg_iter].connect_peers_head; | 4321 | conn_iter = pg->peers[pg_iter].connect_peers_head; |
4344 | while (conn_iter != NULL) | 4322 | while (conn_iter != NULL) |
4345 | { | 4323 | { |
4346 | random_number = | 4324 | random_number |
4347 | ((double) | 4325 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
4348 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 4326 | UINT64_MAX)) |
4349 | UINT64_MAX)) / ((double) UINT64_MAX); | 4327 | / ((double) UINT64_MAX); |
4350 | if (random_number < percentage) | 4328 | if (random_number < percentage) |
4351 | { | 4329 | { |
4352 | add_connections(pg, pg_iter, conn_iter->index, WORKING_SET, GNUNET_YES); | 4330 | add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, |
4331 | GNUNET_YES); | ||
4353 | } | 4332 | } |
4354 | conn_iter = conn_iter->next; | 4333 | conn_iter = conn_iter->next; |
4355 | } | 4334 | } |
4356 | #else | 4335 | #else |
4357 | pg->peers[pg_iter].connect_peers_working_set = | 4336 | pg->peers[pg_iter].connect_peers_working_set = |
4358 | GNUNET_CONTAINER_multihashmap_create (pg->total); | 4337 | GNUNET_CONTAINER_multihashmap_create (pg->total); |
4359 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, | 4338 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, |
4360 | &random_connect_iterator, | 4339 | &random_connect_iterator, |
4361 | &random_ctx); | 4340 | &random_ctx); |
4362 | /* Now remove the old connections */ | 4341 | /* Now remove the old connections */ |
4363 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 4342 | GNUNET_CONTAINER_multihashmap_destroy (pg-> |
4364 | peers[pg_iter].connect_peers); | 4343 | peers[pg_iter].connect_peers); |
4365 | /* And replace with the random set */ | 4344 | /* And replace with the random set */ |
4366 | pg->peers[pg_iter].connect_peers = | 4345 | pg->peers[pg_iter].connect_peers = |
4367 | pg->peers[pg_iter].connect_peers_working_set; | 4346 | pg->peers[pg_iter].connect_peers_working_set; |
4368 | #endif | 4347 | #endif |
4369 | } | 4348 | } |
4370 | 4349 | ||
@@ -4372,16 +4351,19 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
4372 | { | 4351 | { |
4373 | conn_iter = pg->peers[pg_iter].connect_peers_head; | 4352 | conn_iter = pg->peers[pg_iter].connect_peers_head; |
4374 | while (pg->peers[pg_iter].connect_peers_head != NULL) | 4353 | while (pg->peers[pg_iter].connect_peers_head != NULL) |
4375 | remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES); | 4354 | remove_connections (pg, pg_iter, |
4376 | 4355 | pg->peers[pg_iter].connect_peers_head->index, | |
4377 | pg->peers[pg_iter].connect_peers_head = pg->peers[pg_iter].connect_peers_working_set_head; | 4356 | CONNECT, GNUNET_YES); |
4378 | pg->peers[pg_iter].connect_peers_tail = pg->peers[pg_iter].connect_peers_working_set_tail; | 4357 | |
4358 | pg->peers[pg_iter].connect_peers_head | ||
4359 | = pg->peers[pg_iter].connect_peers_working_set_head; | ||
4360 | pg->peers[pg_iter].connect_peers_tail | ||
4361 | = pg->peers[pg_iter].connect_peers_working_set_tail; | ||
4379 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; | 4362 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; |
4380 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; | 4363 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; |
4381 | } | 4364 | } |
4382 | } | 4365 | } |
4383 | 4366 | ||
4384 | |||
4385 | /** | 4367 | /** |
4386 | * Count the number of connections in a linked list of connections. | 4368 | * Count the number of connections in a linked list of connections. |
4387 | * | 4369 | * |
@@ -4390,7 +4372,7 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, | |||
4390 | * @return the number of elements in the list | 4372 | * @return the number of elements in the list |
4391 | */ | 4373 | */ |
4392 | static unsigned int | 4374 | static unsigned int |
4393 | count_connections (struct PeerConnection *conn_list) | 4375 | count_connections(struct PeerConnection *conn_list) |
4394 | { | 4376 | { |
4395 | struct PeerConnection *iter; | 4377 | struct PeerConnection *iter; |
4396 | unsigned int count; | 4378 | unsigned int count; |
@@ -4404,9 +4386,8 @@ count_connections (struct PeerConnection *conn_list) | |||
4404 | return count; | 4386 | return count; |
4405 | } | 4387 | } |
4406 | 4388 | ||
4407 | |||
4408 | static unsigned int | 4389 | static unsigned int |
4409 | count_workingset_connections (struct GNUNET_TESTING_PeerGroup *pg) | 4390 | count_workingset_connections(struct GNUNET_TESTING_PeerGroup *pg) |
4410 | { | 4391 | { |
4411 | unsigned int count; | 4392 | unsigned int count; |
4412 | unsigned int pg_iter; | 4393 | unsigned int pg_iter; |
@@ -4426,18 +4407,17 @@ count_workingset_connections (struct GNUNET_TESTING_PeerGroup *pg) | |||
4426 | } | 4407 | } |
4427 | #else | 4408 | #else |
4428 | count += | 4409 | count += |
4429 | GNUNET_CONTAINER_multihashmap_size (pg-> | 4410 | GNUNET_CONTAINER_multihashmap_size (pg-> |
4430 | peers | 4411 | peers |
4431 | [pg_iter].connect_peers_working_set); | 4412 | [pg_iter].connect_peers_working_set); |
4432 | #endif | 4413 | #endif |
4433 | } | 4414 | } |
4434 | 4415 | ||
4435 | return count; | 4416 | return count; |
4436 | } | 4417 | } |
4437 | 4418 | ||
4438 | |||
4439 | static unsigned int | 4419 | static unsigned int |
4440 | count_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg) | 4420 | count_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg) |
4441 | { | 4421 | { |
4442 | unsigned int count; | 4422 | unsigned int count; |
4443 | unsigned int pg_iter; | 4423 | unsigned int pg_iter; |
@@ -4457,16 +4437,15 @@ count_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg) | |||
4457 | } | 4437 | } |
4458 | #else | 4438 | #else |
4459 | count += | 4439 | count += |
4460 | GNUNET_CONTAINER_multihashmap_size (pg-> | 4440 | GNUNET_CONTAINER_multihashmap_size (pg-> |
4461 | peers | 4441 | peers |
4462 | [pg_iter].allowed_peers); | 4442 | [pg_iter].allowed_peers); |
4463 | #endif | 4443 | #endif |
4464 | } | 4444 | } |
4465 | 4445 | ||
4466 | return count; | 4446 | return count; |
4467 | } | 4447 | } |
4468 | 4448 | ||
4469 | |||
4470 | /** | 4449 | /** |
4471 | * From the set of connections possible, choose at least num connections per | 4450 | * From the set of connections possible, choose at least num connections per |
4472 | * peer. | 4451 | * peer. |
@@ -4475,7 +4454,7 @@ count_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg) | |||
4475 | * @param num how many connections at least should each peer have (if possible)? | 4454 | * @param num how many connections at least should each peer have (if possible)? |
4476 | */ | 4455 | */ |
4477 | static void | 4456 | static void |
4478 | choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | 4457 | choose_minimum(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) |
4479 | { | 4458 | { |
4480 | #if !OLD | 4459 | #if !OLD |
4481 | struct MinimumContext minimum_ctx; | 4460 | struct MinimumContext minimum_ctx; |
@@ -4491,54 +4470,58 @@ choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4491 | #if OLD | 4470 | #if OLD |
4492 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4471 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4493 | { | 4472 | { |
4494 | temp_list_size = count_connections(pg->peers[pg_iter].connect_peers_head); | 4473 | temp_list_size |
4474 | = count_connections (pg->peers[pg_iter].connect_peers_head); | ||
4495 | if (temp_list_size == 0) | 4475 | if (temp_list_size == 0) |
4496 | { | 4476 | { |
4497 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peer %d has 0 connections!?!?\n", pg_iter); | 4477 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4478 | "Peer %d has 0 connections!?!?\n", pg_iter); | ||
4498 | break; | 4479 | break; |
4499 | } | 4480 | } |
4500 | for (i = 0; i < num; i++) | 4481 | for (i = 0; i < num; i++) |
4501 | { | 4482 | { |
4502 | random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, temp_list_size); | 4483 | random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
4484 | temp_list_size); | ||
4503 | conn_iter = pg->peers[pg_iter].connect_peers_head; | 4485 | conn_iter = pg->peers[pg_iter].connect_peers_head; |
4504 | for (count = 0; count < random; count++) | 4486 | for (count = 0; count < random; count++) |
4505 | conn_iter = conn_iter->next; | 4487 | conn_iter = conn_iter->next; |
4506 | /* We now have a random connection, connect it! */ | 4488 | /* We now have a random connection, connect it! */ |
4507 | GNUNET_assert(conn_iter != NULL); | 4489 | GNUNET_assert(conn_iter != NULL); |
4508 | add_connections(pg, pg_iter, conn_iter->index, WORKING_SET, GNUNET_YES); | 4490 | add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, |
4491 | GNUNET_YES); | ||
4509 | } | 4492 | } |
4510 | } | 4493 | } |
4511 | #else | 4494 | #else |
4512 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4495 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4513 | { | 4496 | { |
4514 | pg->peers[pg_iter].connect_peers_working_set = | 4497 | pg->peers[pg_iter].connect_peers_working_set = |
4515 | GNUNET_CONTAINER_multihashmap_create (num); | 4498 | GNUNET_CONTAINER_multihashmap_create (num); |
4516 | } | 4499 | } |
4517 | 4500 | ||
4518 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4501 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4519 | { | 4502 | { |
4520 | minimum_ctx.first_uid = pg_iter; | 4503 | minimum_ctx.first_uid = pg_iter; |
4521 | minimum_ctx.pg_array = | 4504 | minimum_ctx.pg_array = |
4522 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | 4505 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, |
4523 | GNUNET_CONTAINER_multihashmap_size | 4506 | GNUNET_CONTAINER_multihashmap_size |
4524 | (pg->peers[pg_iter].connect_peers)); | 4507 | (pg->peers[pg_iter].connect_peers)); |
4525 | minimum_ctx.first = &pg->peers[pg_iter]; | 4508 | minimum_ctx.first = &pg->peers[pg_iter]; |
4526 | minimum_ctx.pg = pg; | 4509 | minimum_ctx.pg = pg; |
4527 | minimum_ctx.num_to_add = num; | 4510 | minimum_ctx.num_to_add = num; |
4528 | minimum_ctx.current = 0; | 4511 | minimum_ctx.current = 0; |
4529 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, | 4512 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, |
4530 | &minimum_connect_iterator, | 4513 | &minimum_connect_iterator, |
4531 | &minimum_ctx); | 4514 | &minimum_ctx); |
4532 | } | 4515 | } |
4533 | 4516 | ||
4534 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4517 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4535 | { | 4518 | { |
4536 | /* Remove the "old" connections */ | 4519 | /* Remove the "old" connections */ |
4537 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 4520 | GNUNET_CONTAINER_multihashmap_destroy (pg-> |
4538 | peers[pg_iter].connect_peers); | 4521 | peers[pg_iter].connect_peers); |
4539 | /* And replace with the working set */ | 4522 | /* And replace with the working set */ |
4540 | pg->peers[pg_iter].connect_peers = | 4523 | pg->peers[pg_iter].connect_peers = |
4541 | pg->peers[pg_iter].connect_peers_working_set; | 4524 | pg->peers[pg_iter].connect_peers_working_set; |
4542 | } | 4525 | } |
4543 | #endif | 4526 | #endif |
4544 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4527 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
@@ -4547,13 +4530,16 @@ choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4547 | { | 4530 | { |
4548 | conn_iter = pg->peers[pg_iter].connect_peers_head; | 4531 | conn_iter = pg->peers[pg_iter].connect_peers_head; |
4549 | GNUNET_CONTAINER_DLL_remove(pg->peers[pg_iter].connect_peers_head, | 4532 | GNUNET_CONTAINER_DLL_remove(pg->peers[pg_iter].connect_peers_head, |
4550 | pg->peers[pg_iter].connect_peers_tail, pg->peers[pg_iter].connect_peers_head); | 4533 | pg->peers[pg_iter].connect_peers_tail, |
4534 | conn_iter); | ||
4551 | GNUNET_free(conn_iter); | 4535 | GNUNET_free(conn_iter); |
4552 | /*remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES);*/ | 4536 | /*remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES);*/ |
4553 | } | 4537 | } |
4554 | 4538 | ||
4555 | pg->peers[pg_iter].connect_peers_head = pg->peers[pg_iter].connect_peers_working_set_head; | 4539 | pg->peers[pg_iter].connect_peers_head |
4556 | pg->peers[pg_iter].connect_peers_tail = pg->peers[pg_iter].connect_peers_working_set_tail; | 4540 | = pg->peers[pg_iter].connect_peers_working_set_head; |
4541 | pg->peers[pg_iter].connect_peers_tail | ||
4542 | = pg->peers[pg_iter].connect_peers_working_set_tail; | ||
4557 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; | 4543 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; |
4558 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; | 4544 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; |
4559 | } | 4545 | } |
@@ -4561,29 +4547,29 @@ choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4561 | 4547 | ||
4562 | #if !OLD | 4548 | #if !OLD |
4563 | struct FindClosestContext | 4549 | struct FindClosestContext |
4564 | { | 4550 | { |
4565 | /** | 4551 | /** |
4566 | * The currently known closest peer. | 4552 | * The currently known closest peer. |
4567 | */ | 4553 | */ |
4568 | struct GNUNET_TESTING_Daemon *closest; | 4554 | struct GNUNET_TESTING_Daemon *closest; |
4569 | 4555 | ||
4570 | /** | 4556 | /** |
4571 | * The info for the peer we are adding connections for. | 4557 | * The info for the peer we are adding connections for. |
4572 | */ | 4558 | */ |
4573 | struct PeerData *curr_peer; | 4559 | struct PeerData *curr_peer; |
4574 | 4560 | ||
4575 | /** | 4561 | /** |
4576 | * The distance (bits) between the current | 4562 | * The distance (bits) between the current |
4577 | * peer and the currently known closest. | 4563 | * peer and the currently known closest. |
4578 | */ | 4564 | */ |
4579 | unsigned int closest_dist; | 4565 | unsigned int closest_dist; |
4580 | 4566 | ||
4581 | /** | 4567 | /** |
4582 | * The offset of the closest known peer in | 4568 | * The offset of the closest known peer in |
4583 | * the peer group. | 4569 | * the peer group. |
4584 | */ | 4570 | */ |
4585 | unsigned int closest_num; | 4571 | unsigned int closest_num; |
4586 | }; | 4572 | }; |
4587 | 4573 | ||
4588 | /** | 4574 | /** |
4589 | * Iterator over hash map entries of the allowed | 4575 | * Iterator over hash map entries of the allowed |
@@ -4599,30 +4585,29 @@ struct FindClosestContext | |||
4599 | */ | 4585 | */ |
4600 | static int | 4586 | static int |
4601 | find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | 4587 | find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) |
4602 | { | 4588 | { |
4603 | struct FindClosestContext *closest_ctx = cls; | 4589 | struct FindClosestContext *closest_ctx = cls; |
4604 | struct GNUNET_TESTING_Daemon *daemon = value; | 4590 | struct GNUNET_TESTING_Daemon *daemon = value; |
4605 | 4591 | ||
4606 | if (((closest_ctx->closest == NULL) || | 4592 | if (((closest_ctx->closest == NULL) || |
4607 | (GNUNET_CRYPTO_hash_matching_bits | 4593 | (GNUNET_CRYPTO_hash_matching_bits |
4608 | (&daemon->id.hashPubKey, | 4594 | (&daemon->id.hashPubKey, |
4609 | &closest_ctx->curr_peer->daemon->id.hashPubKey) > | 4595 | &closest_ctx->curr_peer->daemon->id.hashPubKey) > |
4610 | closest_ctx->closest_dist)) | 4596 | closest_ctx->closest_dist)) |
4611 | && (GNUNET_YES != | 4597 | && (GNUNET_YES != |
4612 | GNUNET_CONTAINER_multihashmap_contains (closest_ctx-> | 4598 | GNUNET_CONTAINER_multihashmap_contains (closest_ctx-> |
4613 | curr_peer->connect_peers, | 4599 | curr_peer->connect_peers, |
4614 | key))) | 4600 | key))) |
4615 | { | 4601 | { |
4616 | closest_ctx->closest_dist = | 4602 | closest_ctx->closest_dist = |
4617 | GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey, | 4603 | GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey, |
4618 | &closest_ctx->curr_peer->daemon-> | 4604 | &closest_ctx->curr_peer->daemon-> |
4619 | id.hashPubKey); | 4605 | id.hashPubKey); |
4620 | closest_ctx->closest = daemon; | 4606 | closest_ctx->closest = daemon; |
4621 | uid_from_hash (key, &closest_ctx->closest_num); | 4607 | uid_from_hash (key, &closest_ctx->closest_num); |
4622 | } | 4608 | } |
4623 | return GNUNET_YES; | 4609 | return GNUNET_YES; |
4624 | } | 4610 | } |
4625 | |||
4626 | 4611 | ||
4627 | /** | 4612 | /** |
4628 | * From the set of connections possible, choose at num connections per | 4613 | * From the set of connections possible, choose at num connections per |
@@ -4637,36 +4622,36 @@ find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | |||
4637 | */ | 4622 | */ |
4638 | void | 4623 | void |
4639 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, | 4624 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, |
4640 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 4625 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
4641 | { | 4626 | { |
4642 | #if OLD | 4627 | #if OLD |
4643 | 4628 | ||
4644 | #else | 4629 | #else |
4645 | struct FindClosestContext closest_ctx; | 4630 | struct FindClosestContext closest_ctx; |
4646 | #endif | 4631 | #endif |
4647 | uint32_t pg_iter; | 4632 | uint32_t pg_iter; |
4648 | uint32_t i; | 4633 | uint32_t i; |
4649 | 4634 | ||
4650 | for (i = 0; i < num; i++) /* Each time find a closest peer (from those available) */ | 4635 | for (i = 0; i < num; i++) /* Each time find a closest peer (from those available) */ |
4651 | { | 4636 | { |
4652 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4637 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4653 | { | 4638 | { |
4654 | closest_ctx.curr_peer = &pg->peers[pg_iter]; | 4639 | closest_ctx.curr_peer = &pg->peers[pg_iter]; |
4655 | closest_ctx.closest = NULL; | 4640 | closest_ctx.closest = NULL; |
4656 | closest_ctx.closest_dist = 0; | 4641 | closest_ctx.closest_dist = 0; |
4657 | closest_ctx.closest_num = 0; | 4642 | closest_ctx.closest_num = 0; |
4658 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | 4643 | GNUNET_CONTAINER_multihashmap_iterate (pg-> |
4659 | peers[pg_iter].allowed_peers, | 4644 | peers[pg_iter].allowed_peers, |
4660 | &find_closest_peers, | 4645 | &find_closest_peers, |
4661 | &closest_ctx); | 4646 | &closest_ctx); |
4662 | if (closest_ctx.closest != NULL) | 4647 | if (closest_ctx.closest != NULL) |
4663 | { | 4648 | { |
4664 | GNUNET_assert (closest_ctx.closest_num < pg->total); | 4649 | GNUNET_assert (closest_ctx.closest_num < pg->total); |
4665 | proc (pg, pg_iter, closest_ctx.closest_num, list); | 4650 | proc (pg, pg_iter, closest_ctx.closest_num, list); |
4666 | } | 4651 | } |
4667 | } | 4652 | } |
4668 | } | 4653 | } |
4669 | } | 4654 | } |
4670 | #endif | 4655 | #endif |
4671 | 4656 | ||
4672 | /** | 4657 | /** |
@@ -4678,7 +4663,7 @@ add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, | |||
4678 | * @param num how many connections at least should each peer have (if possible)? | 4663 | * @param num how many connections at least should each peer have (if possible)? |
4679 | */ | 4664 | */ |
4680 | void | 4665 | void |
4681 | perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | 4666 | perform_dfs(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) |
4682 | { | 4667 | { |
4683 | uint32_t pg_iter; | 4668 | uint32_t pg_iter; |
4684 | uint32_t dfs_count; | 4669 | uint32_t dfs_count; |
@@ -4697,14 +4682,16 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4697 | starting_peer = 0; | 4682 | starting_peer = 0; |
4698 | dfs_count = 0; | 4683 | dfs_count = 0; |
4699 | while ((count_workingset_connections (pg) < num * pg->total) | 4684 | while ((count_workingset_connections (pg) < num * pg->total) |
4700 | && (count_allowed_connections (pg) > 0)) | 4685 | && (count_allowed_connections (pg) > 0)) |
4701 | { | 4686 | { |
4702 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | 4687 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ |
4703 | { | 4688 | { |
4704 | least_connections = -1; /* Set to very high number */ | 4689 | least_connections = -1; /* Set to very high number */ |
4705 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4690 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4706 | { | 4691 | { |
4707 | temp_count = count_connections(pg->peers[pg_iter].connect_peers_working_set_head); | 4692 | temp_count |
4693 | = count_connections ( | ||
4694 | pg->peers[pg_iter].connect_peers_working_set_head); | ||
4708 | if (temp_count < least_connections) | 4695 | if (temp_count < least_connections) |
4709 | { | 4696 | { |
4710 | starting_peer = pg_iter; | 4697 | starting_peer = pg_iter; |
@@ -4713,11 +4700,13 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4713 | } | 4700 | } |
4714 | } | 4701 | } |
4715 | 4702 | ||
4716 | temp_count = count_connections(pg->peers[starting_peer].connect_peers_head); | 4703 | temp_count |
4704 | = count_connections (pg->peers[starting_peer].connect_peers_head); | ||
4717 | if (temp_count == 0) | 4705 | if (temp_count == 0) |
4718 | continue; /* FIXME: infinite loop? */ | 4706 | continue; /* FIXME: infinite loop? */ |
4719 | 4707 | ||
4720 | random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, temp_count); | 4708 | random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
4709 | temp_count); | ||
4721 | temp_count = 0; | 4710 | temp_count = 0; |
4722 | peer_iter = pg->peers[starting_peer].connect_peers_head; | 4711 | peer_iter = pg->peers[starting_peer].connect_peers_head; |
4723 | while (temp_count < random_connection) | 4712 | while (temp_count < random_connection) |
@@ -4726,8 +4715,10 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4726 | temp_count++; | 4715 | temp_count++; |
4727 | } | 4716 | } |
4728 | GNUNET_assert(peer_iter != NULL); | 4717 | GNUNET_assert(peer_iter != NULL); |
4729 | add_connections(pg, starting_peer, peer_iter->index, WORKING_SET, GNUNET_NO); | 4718 | add_connections (pg, starting_peer, peer_iter->index, WORKING_SET, |
4730 | remove_connections(pg, starting_peer, peer_iter->index, CONNECT, GNUNET_YES); | 4719 | GNUNET_NO); |
4720 | remove_connections (pg, starting_peer, peer_iter->index, CONNECT, | ||
4721 | GNUNET_YES); | ||
4731 | starting_peer = peer_iter->index; | 4722 | starting_peer = peer_iter->index; |
4732 | dfs_count++; | 4723 | dfs_count++; |
4733 | } | 4724 | } |
@@ -4736,17 +4727,17 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4736 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4727 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4737 | { | 4728 | { |
4738 | pg->peers[pg_iter].connect_peers_working_set = | 4729 | pg->peers[pg_iter].connect_peers_working_set = |
4739 | GNUNET_CONTAINER_multihashmap_create (num); | 4730 | GNUNET_CONTAINER_multihashmap_create (num); |
4740 | } | 4731 | } |
4741 | 4732 | ||
4742 | starting_peer = 0; | 4733 | starting_peer = 0; |
4743 | dfs_count = 0; | 4734 | dfs_count = 0; |
4744 | while ((count_workingset_connections (pg) < num * pg->total) | 4735 | while ((count_workingset_connections (pg) < num * pg->total) |
4745 | && (count_allowed_connections (pg) > 0)) | 4736 | && (count_allowed_connections (pg) > 0)) |
4746 | { | 4737 | { |
4747 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | 4738 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ |
4748 | { | 4739 | { |
4749 | least_connections = -1; /* Set to very high number */ | 4740 | least_connections = -1; /* Set to very high number */ |
4750 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4741 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4751 | { | 4742 | { |
4752 | if (GNUNET_CONTAINER_multihashmap_size | 4743 | if (GNUNET_CONTAINER_multihashmap_size |
@@ -4755,14 +4746,14 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4755 | { | 4746 | { |
4756 | starting_peer = pg_iter; | 4747 | starting_peer = pg_iter; |
4757 | least_connections = | 4748 | least_connections = |
4758 | GNUNET_CONTAINER_multihashmap_size (pg-> | 4749 | GNUNET_CONTAINER_multihashmap_size (pg-> |
4759 | peers | 4750 | peers |
4760 | [pg_iter].connect_peers_working_set); | 4751 | [pg_iter].connect_peers_working_set); |
4761 | } | 4752 | } |
4762 | } | 4753 | } |
4763 | } | 4754 | } |
4764 | 4755 | ||
4765 | if (GNUNET_CONTAINER_multihashmap_size (pg->peers[starting_peer].connect_peers) == 0) /* Ensure there is at least one peer left to connect! */ | 4756 | if (GNUNET_CONTAINER_multihashmap_size (pg->peers[starting_peer].connect_peers) == 0) /* Ensure there is at least one peer left to connect! */ |
4766 | { | 4757 | { |
4767 | dfs_count = 0; | 4758 | dfs_count = 0; |
4768 | continue; | 4759 | continue; |
@@ -4770,27 +4761,27 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4770 | 4761 | ||
4771 | /* Choose a random peer from the chosen peers set of connections to add */ | 4762 | /* Choose a random peer from the chosen peers set of connections to add */ |
4772 | dfs_ctx.chosen = | 4763 | dfs_ctx.chosen = |
4773 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 4764 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
4774 | GNUNET_CONTAINER_multihashmap_size | 4765 | GNUNET_CONTAINER_multihashmap_size |
4775 | (pg->peers[starting_peer].connect_peers)); | 4766 | (pg->peers[starting_peer].connect_peers)); |
4776 | dfs_ctx.first_uid = starting_peer; | 4767 | dfs_ctx.first_uid = starting_peer; |
4777 | dfs_ctx.first = &pg->peers[starting_peer]; | 4768 | dfs_ctx.first = &pg->peers[starting_peer]; |
4778 | dfs_ctx.pg = pg; | 4769 | dfs_ctx.pg = pg; |
4779 | dfs_ctx.current = 0; | 4770 | dfs_ctx.current = 0; |
4780 | 4771 | ||
4781 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | 4772 | GNUNET_CONTAINER_multihashmap_iterate (pg-> |
4782 | peers | 4773 | peers |
4783 | [starting_peer].connect_peers, | 4774 | [starting_peer].connect_peers, |
4784 | &dfs_connect_iterator, &dfs_ctx); | 4775 | &dfs_connect_iterator, &dfs_ctx); |
4785 | /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */ | 4776 | /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */ |
4786 | hash_from_uid (dfs_ctx.second_uid, &second_hash); | 4777 | hash_from_uid (dfs_ctx.second_uid, &second_hash); |
4787 | GNUNET_assert (GNUNET_YES == | 4778 | GNUNET_assert (GNUNET_YES == |
4788 | GNUNET_CONTAINER_multihashmap_remove (pg->peers | 4779 | GNUNET_CONTAINER_multihashmap_remove (pg->peers |
4789 | [starting_peer].connect_peers, | 4780 | [starting_peer].connect_peers, |
4790 | &second_hash, | 4781 | &second_hash, |
4791 | pg-> | 4782 | pg-> |
4792 | peers | 4783 | peers |
4793 | [dfs_ctx.second_uid].daemon)); | 4784 | [dfs_ctx.second_uid].daemon)); |
4794 | starting_peer = dfs_ctx.second_uid; | 4785 | starting_peer = dfs_ctx.second_uid; |
4795 | } | 4786 | } |
4796 | 4787 | ||
@@ -4798,28 +4789,25 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4798 | { | 4789 | { |
4799 | /* Remove the "old" connections */ | 4790 | /* Remove the "old" connections */ |
4800 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 4791 | GNUNET_CONTAINER_multihashmap_destroy (pg-> |
4801 | peers[pg_iter].connect_peers); | 4792 | peers[pg_iter].connect_peers); |
4802 | /* And replace with the working set */ | 4793 | /* And replace with the working set */ |
4803 | pg->peers[pg_iter].connect_peers = | 4794 | pg->peers[pg_iter].connect_peers = |
4804 | pg->peers[pg_iter].connect_peers_working_set; | 4795 | pg->peers[pg_iter].connect_peers_working_set; |
4805 | } | 4796 | } |
4806 | #endif | 4797 | #endif |
4807 | } | 4798 | } |
4808 | 4799 | ||
4809 | |||
4810 | /** | 4800 | /** |
4811 | * Internal callback for topology information for a particular peer. | 4801 | * Internal callback for topology information for a particular peer. |
4812 | */ | 4802 | */ |
4813 | static void | 4803 | static void |
4814 | internal_topology_callback (void *cls, | 4804 | internal_topology_callback(void *cls, const struct GNUNET_PeerIdentity *peer, |
4815 | const struct GNUNET_PeerIdentity *peer, | 4805 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
4816 | const struct GNUNET_TRANSPORT_ATS_Information | ||
4817 | *atsi) | ||
4818 | { | 4806 | { |
4819 | struct CoreContext *core_ctx = cls; | 4807 | struct CoreContext *core_ctx = cls; |
4820 | struct TopologyIterateContext *iter_ctx = core_ctx->iter_context; | 4808 | struct TopologyIterateContext *iter_ctx = core_ctx->iter_context; |
4821 | 4809 | ||
4822 | if (peer == NULL) /* Either finished, or something went wrong */ | 4810 | if (peer == NULL) /* Either finished, or something went wrong */ |
4823 | { | 4811 | { |
4824 | iter_ctx->completed++; | 4812 | iter_ctx->completed++; |
4825 | iter_ctx->connected--; | 4813 | iter_ctx->connected--; |
@@ -4828,8 +4816,7 @@ internal_topology_callback (void *cls, | |||
4828 | } | 4816 | } |
4829 | else | 4817 | else |
4830 | { | 4818 | { |
4831 | iter_ctx->topology_cb (iter_ctx->cls, &core_ctx->daemon->id, | 4819 | iter_ctx->topology_cb (iter_ctx->cls, &core_ctx->daemon->id, peer, NULL); |
4832 | peer, NULL); | ||
4833 | } | 4820 | } |
4834 | 4821 | ||
4835 | if (iter_ctx->completed == iter_ctx->total) | 4822 | if (iter_ctx->completed == iter_ctx->total) |
@@ -4840,47 +4827,47 @@ internal_topology_callback (void *cls, | |||
4840 | } | 4827 | } |
4841 | } | 4828 | } |
4842 | 4829 | ||
4843 | |||
4844 | /** | 4830 | /** |
4845 | * Check running topology iteration tasks, if below max start a new one, otherwise | 4831 | * Check running topology iteration tasks, if below max start a new one, otherwise |
4846 | * schedule for some time in the future. | 4832 | * schedule for some time in the future. |
4847 | */ | 4833 | */ |
4848 | static void | 4834 | static void |
4849 | schedule_get_topology (void *cls, | 4835 | schedule_get_topology(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
4850 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
4851 | { | 4836 | { |
4852 | struct CoreContext *core_context = cls; | 4837 | struct CoreContext *core_context = cls; |
4853 | struct TopologyIterateContext *topology_context = | 4838 | struct TopologyIterateContext *topology_context = |
4854 | (struct TopologyIterateContext *) core_context->iter_context; | 4839 | (struct TopologyIterateContext *) core_context->iter_context; |
4855 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 4840 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
4856 | return; | 4841 | return; |
4857 | 4842 | ||
4858 | if (topology_context->connected > topology_context->pg->max_outstanding_connections) | 4843 | if (topology_context->connected |
4844 | > topology_context->pg->max_outstanding_connections) | ||
4859 | { | 4845 | { |
4860 | #if VERBOSE_TESTING > 2 | 4846 | #if VERBOSE_TESTING > 2 |
4861 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4847 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4862 | _ | 4848 | _ |
4863 | ("Delaying connect, we have too many outstanding connections!\n")); | 4849 | ("Delaying connect, we have too many outstanding connections!\n")); |
4864 | #endif | 4850 | #endif |
4865 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 4851 | GNUNET_SCHEDULER_add_delayed ( |
4866 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 4852 | GNUNET_TIME_relative_multiply ( |
4853 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
4854 | 100), | ||
4867 | &schedule_get_topology, core_context); | 4855 | &schedule_get_topology, core_context); |
4868 | } | 4856 | } |
4869 | else | 4857 | else |
4870 | { | 4858 | { |
4871 | #if VERBOSE_TESTING > 2 | 4859 | #if VERBOSE_TESTING > 2 |
4872 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4860 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4873 | _("Creating connection, outstanding_connections is %d\n"), | 4861 | _("Creating connection, outstanding_connections is %d\n"), |
4874 | outstanding_connects); | 4862 | outstanding_connects); |
4875 | #endif | 4863 | #endif |
4876 | topology_context->connected++; | 4864 | topology_context->connected++; |
4877 | 4865 | ||
4878 | if (GNUNET_OK != | 4866 | if (GNUNET_OK != GNUNET_CORE_iterate_peers (core_context->daemon->cfg, |
4879 | GNUNET_CORE_iterate_peers (core_context->daemon->cfg, | 4867 | &internal_topology_callback, |
4880 | &internal_topology_callback, | 4868 | core_context)) |
4881 | core_context)) | ||
4882 | { | 4869 | { |
4883 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Topology iteration failed.\n"); | 4870 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Topology iteration failed.\n"); |
4884 | internal_topology_callback (core_context, NULL, NULL); | 4871 | internal_topology_callback (core_context, NULL, NULL); |
4885 | } | 4872 | } |
4886 | } | 4873 | } |
@@ -4891,8 +4878,8 @@ schedule_get_topology (void *cls, | |||
4891 | * all connections that each currently has. | 4878 | * all connections that each currently has. |
4892 | */ | 4879 | */ |
4893 | void | 4880 | void |
4894 | GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, | 4881 | GNUNET_TESTING_get_topology(struct GNUNET_TESTING_PeerGroup *pg, |
4895 | GNUNET_TESTING_NotifyTopology cb, void *cls) | 4882 | GNUNET_TESTING_NotifyTopology cb, void *cls) |
4896 | { | 4883 | { |
4897 | struct TopologyIterateContext *topology_context; | 4884 | struct TopologyIterateContext *topology_context; |
4898 | struct CoreContext *core_ctx; | 4885 | struct CoreContext *core_ctx; |
@@ -4942,13 +4929,12 @@ GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
4942 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 4929 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
4943 | */ | 4930 | */ |
4944 | static int | 4931 | static int |
4945 | internal_stats_callback (void *cls, | 4932 | internal_stats_callback(void *cls, const char *subsystem, const char *name, |
4946 | const char *subsystem, | 4933 | uint64_t value, int is_persistent) |
4947 | const char *name, uint64_t value, int is_persistent) | ||
4948 | { | 4934 | { |
4949 | struct StatsCoreContext *core_context = cls; | 4935 | struct StatsCoreContext *core_context = cls; |
4950 | struct StatsIterateContext *stats_context = | 4936 | struct StatsIterateContext *stats_context = |
4951 | (struct StatsIterateContext *) core_context->iter_context; | 4937 | (struct StatsIterateContext *) core_context->iter_context; |
4952 | 4938 | ||
4953 | return stats_context->proc (stats_context->cls, &core_context->daemon->id, | 4939 | return stats_context->proc (stats_context->cls, &core_context->daemon->id, |
4954 | subsystem, name, value, is_persistent); | 4940 | subsystem, name, value, is_persistent); |
@@ -4962,11 +4948,11 @@ internal_stats_callback (void *cls, | |||
4962 | * was canceled or not (we don't care) | 4948 | * was canceled or not (we don't care) |
4963 | */ | 4949 | */ |
4964 | static void | 4950 | static void |
4965 | internal_stats_cont (void *cls, int success) | 4951 | internal_stats_cont(void *cls, int success) |
4966 | { | 4952 | { |
4967 | struct StatsCoreContext *core_context = cls; | 4953 | struct StatsCoreContext *core_context = cls; |
4968 | struct StatsIterateContext *stats_context = | 4954 | struct StatsIterateContext *stats_context = |
4969 | (struct StatsIterateContext *) core_context->iter_context; | 4955 | (struct StatsIterateContext *) core_context->iter_context; |
4970 | 4956 | ||
4971 | stats_context->connected--; | 4957 | stats_context->connected--; |
4972 | stats_context->completed++; | 4958 | stats_context->completed++; |
@@ -4988,12 +4974,12 @@ internal_stats_cont (void *cls, int success) | |||
4988 | * schedule for some time in the future. | 4974 | * schedule for some time in the future. |
4989 | */ | 4975 | */ |
4990 | static void | 4976 | static void |
4991 | schedule_get_statistics (void *cls, | 4977 | schedule_get_statistics(void *cls, |
4992 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 4978 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
4993 | { | 4979 | { |
4994 | struct StatsCoreContext *core_context = cls; | 4980 | struct StatsCoreContext *core_context = cls; |
4995 | struct StatsIterateContext *stats_context = | 4981 | struct StatsIterateContext *stats_context = |
4996 | (struct StatsIterateContext *) core_context->iter_context; | 4982 | (struct StatsIterateContext *) core_context->iter_context; |
4997 | 4983 | ||
4998 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 4984 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
4999 | return; | 4985 | return; |
@@ -5002,35 +4988,37 @@ schedule_get_statistics (void *cls, | |||
5002 | { | 4988 | { |
5003 | #if VERBOSE_TESTING > 2 | 4989 | #if VERBOSE_TESTING > 2 |
5004 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4990 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5005 | _ | 4991 | _ |
5006 | ("Delaying connect, we have too many outstanding connections!\n")); | 4992 | ("Delaying connect, we have too many outstanding connections!\n")); |
5007 | #endif | 4993 | #endif |
5008 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 4994 | GNUNET_SCHEDULER_add_delayed ( |
5009 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 4995 | GNUNET_TIME_relative_multiply ( |
4996 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
4997 | 100), | ||
5010 | &schedule_get_statistics, core_context); | 4998 | &schedule_get_statistics, core_context); |
5011 | } | 4999 | } |
5012 | else | 5000 | else |
5013 | { | 5001 | { |
5014 | #if VERBOSE_TESTING > 2 | 5002 | #if VERBOSE_TESTING > 2 |
5015 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5003 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5016 | _("Creating connection, outstanding_connections is %d\n"), | 5004 | _("Creating connection, outstanding_connections is %d\n"), |
5017 | outstanding_connects); | 5005 | outstanding_connects); |
5018 | #endif | 5006 | #endif |
5019 | 5007 | ||
5020 | stats_context->connected++; | 5008 | stats_context->connected++; |
5021 | core_context->stats_handle = | 5009 | core_context->stats_handle |
5022 | GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg); | 5010 | = GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg); |
5023 | if (core_context->stats_handle == NULL) | 5011 | if (core_context->stats_handle == NULL) |
5024 | { | 5012 | { |
5025 | internal_stats_cont (core_context, GNUNET_NO); | 5013 | internal_stats_cont (core_context, GNUNET_NO); |
5026 | return; | 5014 | return; |
5027 | } | 5015 | } |
5028 | 5016 | ||
5029 | core_context->stats_get_handle = | 5017 | core_context->stats_get_handle |
5030 | GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL, | 5018 | = GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL, |
5031 | GNUNET_TIME_relative_get_forever (), | 5019 | GNUNET_TIME_relative_get_forever (), |
5032 | &internal_stats_cont, &internal_stats_callback, | 5020 | &internal_stats_cont, |
5033 | core_context); | 5021 | &internal_stats_callback, core_context); |
5034 | if (core_context->stats_get_handle == NULL) | 5022 | if (core_context->stats_get_handle == NULL) |
5035 | internal_stats_cont (core_context, GNUNET_NO); | 5023 | internal_stats_cont (core_context, GNUNET_NO); |
5036 | 5024 | ||
@@ -5062,28 +5050,28 @@ struct DuplicateStats | |||
5062 | * GNUNET_NO if not (and we may have added it to the list) | 5050 | * GNUNET_NO if not (and we may have added it to the list) |
5063 | */ | 5051 | */ |
5064 | static int | 5052 | static int |
5065 | stats_check_existing (struct GNUNET_TESTING_PeerGroup *pg, | 5053 | stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, |
5066 | struct PeerData *specific_peer, | 5054 | struct PeerData *specific_peer, struct DuplicateStats **stats_list) |
5067 | struct DuplicateStats **stats_list) | ||
5068 | { | 5055 | { |
5069 | struct DuplicateStats *pos; | 5056 | struct DuplicateStats *pos; |
5070 | char *unix_domain_socket; | 5057 | char *unix_domain_socket; |
5071 | unsigned long long port; | 5058 | unsigned long long port; |
5072 | char *to_match; | 5059 | char *to_match; |
5073 | if (GNUNET_YES != | 5060 | if (GNUNET_YES |
5074 | GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing", | 5061 | != GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing", |
5075 | "single_statistics_per_host")) | 5062 | "single_statistics_per_host")) |
5076 | return GNUNET_NO; /* Each peer has its own statistics instance, do nothing! */ | 5063 | return GNUNET_NO; /* Each peer has its own statistics instance, do nothing! */ |
5077 | 5064 | ||
5078 | pos = *stats_list; | 5065 | pos = *stats_list; |
5079 | if (GNUNET_OK != | 5066 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg, |
5080 | GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg, "statistics", | 5067 | "statistics", |
5081 | "unixpath", &unix_domain_socket)) | 5068 | "unixpath", |
5069 | &unix_domain_socket)) | ||
5082 | return GNUNET_NO; | 5070 | return GNUNET_NO; |
5083 | 5071 | ||
5084 | if (GNUNET_OK != | 5072 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg, |
5085 | GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg, "statistics", | 5073 | "statistics", "port", |
5086 | "port", &port)) | 5074 | &port)) |
5087 | { | 5075 | { |
5088 | GNUNET_free(unix_domain_socket); | 5076 | GNUNET_free(unix_domain_socket); |
5089 | return GNUNET_NO; | 5077 | return GNUNET_NO; |
@@ -5118,10 +5106,9 @@ stats_check_existing (struct GNUNET_TESTING_PeerGroup *pg, | |||
5118 | * all statistics from each. | 5106 | * all statistics from each. |
5119 | */ | 5107 | */ |
5120 | void | 5108 | void |
5121 | GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, | 5109 | GNUNET_TESTING_get_statistics(struct GNUNET_TESTING_PeerGroup *pg, |
5122 | GNUNET_STATISTICS_Callback cont, | 5110 | GNUNET_STATISTICS_Callback cont, GNUNET_TESTING_STATISTICS_Iterator proc, |
5123 | GNUNET_TESTING_STATISTICS_Iterator proc, | 5111 | void *cls) |
5124 | void *cls) | ||
5125 | { | 5112 | { |
5126 | struct StatsIterateContext *stats_context; | 5113 | struct StatsIterateContext *stats_context; |
5127 | struct StatsCoreContext *core_ctx; | 5114 | struct StatsCoreContext *core_ctx; |
@@ -5141,9 +5128,8 @@ GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, | |||
5141 | 5128 | ||
5142 | for (i = 0; i < pg->total; i++) | 5129 | for (i = 0; i < pg->total; i++) |
5143 | { | 5130 | { |
5144 | if ((pg->peers[i].daemon->running == GNUNET_YES) | 5131 | if ((pg->peers[i].daemon->running == GNUNET_YES) && (GNUNET_NO |
5145 | && (GNUNET_NO == | 5132 | == stats_check_existing (pg, &pg->peers[i], &stats_list))) |
5146 | stats_check_existing (pg, &pg->peers[i], &stats_list))) | ||
5147 | { | 5133 | { |
5148 | /* Allocate one core context per core we need to connect to */ | 5134 | /* Allocate one core context per core we need to connect to */ |
5149 | core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext)); | 5135 | core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext)); |
@@ -5177,7 +5163,8 @@ GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, | |||
5177 | * | 5163 | * |
5178 | * @param pg the peer group to stop connecting | 5164 | * @param pg the peer group to stop connecting |
5179 | */ | 5165 | */ |
5180 | void GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg) | 5166 | void |
5167 | GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg) | ||
5181 | { | 5168 | { |
5182 | pg->stop_connects = GNUNET_YES; | 5169 | pg->stop_connects = GNUNET_YES; |
5183 | } | 5170 | } |
@@ -5187,7 +5174,8 @@ void GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg) | |||
5187 | * | 5174 | * |
5188 | * @param pg the peer group to resume connecting | 5175 | * @param pg the peer group to resume connecting |
5189 | */ | 5176 | */ |
5190 | void GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg) | 5177 | void |
5178 | GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg) | ||
5191 | { | 5179 | { |
5192 | pg->stop_connects = GNUNET_NO; | 5180 | pg->stop_connects = GNUNET_NO; |
5193 | } | 5181 | } |
@@ -5215,145 +5203,137 @@ void GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg) | |||
5215 | * @return the number of connections that will be attempted, GNUNET_SYSERR on error | 5203 | * @return the number of connections that will be attempted, GNUNET_SYSERR on error |
5216 | */ | 5204 | */ |
5217 | int | 5205 | int |
5218 | GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | 5206 | GNUNET_TESTING_connect_topology(struct GNUNET_TESTING_PeerGroup *pg, |
5219 | enum GNUNET_TESTING_Topology topology, | 5207 | enum GNUNET_TESTING_Topology topology, |
5220 | enum GNUNET_TESTING_TopologyOption options, | 5208 | enum GNUNET_TESTING_TopologyOption options, double option_modifier, |
5221 | double option_modifier, | 5209 | struct GNUNET_TIME_Relative connect_timeout, unsigned int connect_attempts, |
5222 | struct GNUNET_TIME_Relative connect_timeout, | 5210 | GNUNET_TESTING_NotifyCompletion notify_callback, void *notify_cls) |
5223 | unsigned int connect_attempts, | ||
5224 | GNUNET_TESTING_NotifyCompletion | ||
5225 | notify_callback, void *notify_cls) | ||
5226 | { | 5211 | { |
5227 | switch (topology) | 5212 | switch (topology) |
5228 | { | 5213 | { |
5229 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 5214 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
5230 | #if VERBOSE_TOPOLOGY | 5215 | #if VERBOSE_TOPOLOGY |
5231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5232 | _("Creating clique CONNECT topology\n")); | 5217 | _("Creating clique CONNECT topology\n")); |
5233 | #endif | 5218 | #endif |
5234 | create_clique (pg, &add_connections, CONNECT, GNUNET_NO); | 5219 | create_clique (pg, &add_connections, CONNECT, GNUNET_NO); |
5235 | break; | 5220 | break; |
5236 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 5221 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
5237 | #if VERBOSE_TOPOLOGY | 5222 | #if VERBOSE_TOPOLOGY |
5238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5239 | _("Creating small world (ring) CONNECT topology\n")); | 5224 | _("Creating small world (ring) CONNECT topology\n")); |
5240 | #endif | 5225 | #endif |
5241 | create_small_world_ring (pg, &add_connections, CONNECT); | 5226 | create_small_world_ring (pg, &add_connections, CONNECT); |
5242 | break; | 5227 | break; |
5243 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 5228 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
5244 | #if VERBOSE_TOPOLOGY | 5229 | #if VERBOSE_TOPOLOGY |
5245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5246 | _("Creating small world (2d-torus) CONNECT topology\n")); | 5231 | _("Creating small world (2d-torus) CONNECT topology\n")); |
5247 | #endif | 5232 | #endif |
5248 | create_small_world (pg, &add_connections, CONNECT); | 5233 | create_small_world (pg, &add_connections, CONNECT); |
5249 | break; | 5234 | break; |
5250 | case GNUNET_TESTING_TOPOLOGY_RING: | 5235 | case GNUNET_TESTING_TOPOLOGY_RING: |
5251 | #if VERBOSE_TOPOLOGY | 5236 | #if VERBOSE_TOPOLOGY |
5252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating ring CONNECT topology\n")); |
5253 | _("Creating ring CONNECT topology\n")); | ||
5254 | #endif | 5238 | #endif |
5255 | create_ring (pg, &add_connections, CONNECT); | 5239 | create_ring (pg, &add_connections, CONNECT); |
5256 | break; | 5240 | break; |
5257 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 5241 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: |
5258 | #if VERBOSE_TOPOLOGY | 5242 | #if VERBOSE_TOPOLOGY |
5259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5260 | _("Creating 2d torus CONNECT topology\n")); | 5244 | _("Creating 2d torus CONNECT topology\n")); |
5261 | #endif | 5245 | #endif |
5262 | create_2d_torus (pg, &add_connections, CONNECT); | 5246 | create_2d_torus (pg, &add_connections, CONNECT); |
5263 | break; | 5247 | break; |
5264 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 5248 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
5265 | #if VERBOSE_TOPOLOGY | 5249 | #if VERBOSE_TOPOLOGY |
5266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5267 | _("Creating Erdos-Renyi CONNECT topology\n")); | 5251 | _("Creating Erdos-Renyi CONNECT topology\n")); |
5268 | #endif | 5252 | #endif |
5269 | create_erdos_renyi (pg, &add_connections, CONNECT); | 5253 | create_erdos_renyi (pg, &add_connections, CONNECT); |
5270 | break; | 5254 | break; |
5271 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 5255 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
5272 | #if VERBOSE_TOPOLOGY | 5256 | #if VERBOSE_TOPOLOGY |
5273 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5274 | _("Creating InterNAT CONNECT topology\n")); | 5258 | _("Creating InterNAT CONNECT topology\n")); |
5275 | #endif | 5259 | #endif |
5276 | create_nated_internet (pg, &add_connections, CONNECT); | 5260 | create_nated_internet (pg, &add_connections, CONNECT); |
5277 | break; | 5261 | break; |
5278 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 5262 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
5279 | #if VERBOSE_TOPOLOGY | 5263 | #if VERBOSE_TOPOLOGY |
5280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5281 | _("Creating Scale Free CONNECT topology\n")); | 5265 | _("Creating Scale Free CONNECT topology\n")); |
5282 | #endif | 5266 | #endif |
5283 | create_scale_free (pg, &add_connections, CONNECT); | 5267 | create_scale_free (pg, &add_connections, CONNECT); |
5284 | break; | 5268 | break; |
5285 | case GNUNET_TESTING_TOPOLOGY_LINE: | 5269 | case GNUNET_TESTING_TOPOLOGY_LINE: |
5286 | #if VERBOSE_TOPOLOGY | 5270 | #if VERBOSE_TOPOLOGY |
5287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5288 | _("Creating straight line CONNECT topology\n")); | 5272 | _("Creating straight line CONNECT topology\n")); |
5289 | #endif | 5273 | #endif |
5290 | create_line (pg, &add_connections, CONNECT); | 5274 | create_line (pg, &add_connections, CONNECT); |
5291 | break; | 5275 | break; |
5292 | case GNUNET_TESTING_TOPOLOGY_NONE: | 5276 | case GNUNET_TESTING_TOPOLOGY_NONE: |
5293 | #if VERBOSE_TOPOLOGY | 5277 | #if VERBOSE_TOPOLOGY |
5294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating no CONNECT topology\n")); |
5295 | _("Creating no CONNECT topology\n")); | ||
5296 | #endif | 5279 | #endif |
5297 | copy_allowed_topology (pg); | 5280 | copy_allowed_topology (pg); |
5298 | break; | 5281 | break; |
5299 | default: | 5282 | default: |
5300 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 5283 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ |
5301 | _ | 5284 | ("Unknown topology specification, can't connect peers!\n")); |
5302 | ("Unknown topology specification, can't connect peers!\n")); | 5285 | return GNUNET_SYSERR; |
5303 | return GNUNET_SYSERR; | ||
5304 | } | 5286 | } |
5305 | 5287 | ||
5306 | switch (options) | 5288 | switch (options) |
5307 | { | 5289 | { |
5308 | case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM: | 5290 | case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM: |
5309 | #if VERBOSE_TOPOLOGY | 5291 | #if VERBOSE_TOPOLOGY |
5310 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ |
5311 | _ | 5293 | ("Connecting random subset (%'.2f percent) of possible peers\n"), 100 |
5312 | ("Connecting random subset (%'.2f percent) of possible peers\n"), | 5294 | * option_modifier); |
5313 | 100 * option_modifier); | ||
5314 | #endif | 5295 | #endif |
5315 | choose_random_connections (pg, option_modifier); | 5296 | choose_random_connections (pg, option_modifier); |
5316 | break; | 5297 | break; |
5317 | case GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM: | 5298 | case GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM: |
5318 | #if VERBOSE_TOPOLOGY | 5299 | #if VERBOSE_TOPOLOGY |
5319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5320 | _("Connecting a minimum of %u peers each (if possible)\n"), | 5301 | _("Connecting a minimum of %u peers each (if possible)\n"), |
5321 | (unsigned int) option_modifier); | 5302 | (unsigned int) option_modifier); |
5322 | #endif | 5303 | #endif |
5323 | choose_minimum (pg, (unsigned int) option_modifier); | 5304 | choose_minimum (pg, (unsigned int) option_modifier); |
5324 | break; | 5305 | break; |
5325 | case GNUNET_TESTING_TOPOLOGY_OPTION_DFS: | 5306 | case GNUNET_TESTING_TOPOLOGY_OPTION_DFS: |
5326 | #if VERBOSE_TOPOLOGY | 5307 | #if VERBOSE_TOPOLOGY |
5327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ |
5328 | _ | 5309 | ("Using DFS to connect a minimum of %u peers each (if possible)\n"), |
5329 | ("Using DFS to connect a minimum of %u peers each (if possible)\n"), | 5310 | (unsigned int) option_modifier); |
5330 | (unsigned int) option_modifier); | ||
5331 | #endif | 5311 | #endif |
5332 | #if FIXME | 5312 | #if FIXME |
5333 | perform_dfs (pg, (int) option_modifier); | 5313 | perform_dfs (pg, (int) option_modifier); |
5334 | #endif | 5314 | #endif |
5335 | break; | 5315 | break; |
5336 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: | 5316 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: |
5337 | #if VERBOSE_TOPOLOGY | 5317 | #if VERBOSE_TOPOLOGY |
5338 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 5318 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ |
5339 | _ | 5319 | ("Finding additional %u closest peers each (if possible)\n"), |
5340 | ("Finding additional %u closest peers each (if possible)\n"), | 5320 | (unsigned int) option_modifier); |
5341 | (unsigned int) option_modifier); | ||
5342 | #endif | 5321 | #endif |
5343 | #if FIXME | 5322 | #if FIXME |
5344 | add_closest (pg, (unsigned int) option_modifier, | 5323 | add_closest (pg, (unsigned int) option_modifier, |
5345 | &add_connections, CONNECT); | 5324 | &add_connections, CONNECT); |
5346 | #endif | 5325 | #endif |
5347 | break; | 5326 | break; |
5348 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: | 5327 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: |
5349 | break; | 5328 | break; |
5350 | case GNUNET_TESTING_TOPOLOGY_OPTION_ALL: | 5329 | case GNUNET_TESTING_TOPOLOGY_OPTION_ALL: |
5351 | break; | 5330 | break; |
5352 | default: | 5331 | default: |
5353 | break; | 5332 | break; |
5354 | } | 5333 | } |
5355 | 5334 | ||
5356 | return connect_topology (pg, connect_timeout, connect_attempts, notify_callback, notify_cls); | 5335 | return connect_topology (pg, connect_timeout, connect_attempts, |
5336 | notify_callback, notify_cls); | ||
5357 | } | 5337 | } |
5358 | 5338 | ||
5359 | /** | 5339 | /** |
@@ -5365,17 +5345,17 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
5365 | * @return the number of current ssh connections to the host | 5345 | * @return the number of current ssh connections to the host |
5366 | */ | 5346 | */ |
5367 | static unsigned int | 5347 | static unsigned int |
5368 | count_outstanding_at_host(const char *hostname, struct GNUNET_TESTING_PeerGroup *pg) | 5348 | count_outstanding_at_host(const char *hostname, |
5349 | struct GNUNET_TESTING_PeerGroup *pg) | ||
5369 | { | 5350 | { |
5370 | struct OutstandingSSH *pos; | 5351 | struct OutstandingSSH *pos; |
5371 | pos = pg->ssh_head; | 5352 | pos = pg->ssh_head; |
5372 | while ((pos != NULL) && (strcmp(pos->hostname, hostname) != 0)) | 5353 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) |
5373 | pos = pos->next; | 5354 | pos = pos->next; |
5374 | GNUNET_assert(pos != NULL); | 5355 | GNUNET_assert(pos != NULL); |
5375 | return pos->outstanding; | 5356 | return pos->outstanding; |
5376 | } | 5357 | } |
5377 | 5358 | ||
5378 | |||
5379 | /** | 5359 | /** |
5380 | * Increment the number of SSH connections to a host by one. | 5360 | * Increment the number of SSH connections to a host by one. |
5381 | * | 5361 | * |
@@ -5384,11 +5364,12 @@ count_outstanding_at_host(const char *hostname, struct GNUNET_TESTING_PeerGroup | |||
5384 | * | 5364 | * |
5385 | */ | 5365 | */ |
5386 | static void | 5366 | static void |
5387 | increment_outstanding_at_host(const char *hostname, struct GNUNET_TESTING_PeerGroup *pg) | 5367 | increment_outstanding_at_host(const char *hostname, |
5368 | struct GNUNET_TESTING_PeerGroup *pg) | ||
5388 | { | 5369 | { |
5389 | struct OutstandingSSH *pos; | 5370 | struct OutstandingSSH *pos; |
5390 | pos = pg->ssh_head; | 5371 | pos = pg->ssh_head; |
5391 | while ((pos != NULL) && (strcmp(pos->hostname, hostname) != 0)) | 5372 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) |
5392 | pos = pos->next; | 5373 | pos = pos->next; |
5393 | GNUNET_assert(pos != NULL); | 5374 | GNUNET_assert(pos != NULL); |
5394 | pos->outstanding++; | 5375 | pos->outstanding++; |
@@ -5402,17 +5383,17 @@ increment_outstanding_at_host(const char *hostname, struct GNUNET_TESTING_PeerGr | |||
5402 | * | 5383 | * |
5403 | */ | 5384 | */ |
5404 | static void | 5385 | static void |
5405 | decrement_outstanding_at_host(const char *hostname, struct GNUNET_TESTING_PeerGroup *pg) | 5386 | decrement_outstanding_at_host(const char *hostname, |
5387 | struct GNUNET_TESTING_PeerGroup *pg) | ||
5406 | { | 5388 | { |
5407 | struct OutstandingSSH *pos; | 5389 | struct OutstandingSSH *pos; |
5408 | pos = pg->ssh_head; | 5390 | pos = pg->ssh_head; |
5409 | while ((pos != NULL) && (strcmp(pos->hostname, hostname) != 0)) | 5391 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) |
5410 | pos = pos->next; | 5392 | pos = pos->next; |
5411 | GNUNET_assert(pos != NULL); | 5393 | GNUNET_assert(pos != NULL); |
5412 | pos->outstanding--; | 5394 | pos->outstanding--; |
5413 | } | 5395 | } |
5414 | 5396 | ||
5415 | |||
5416 | /** | 5397 | /** |
5417 | * Callback that is called whenever a hostkey is generated | 5398 | * Callback that is called whenever a hostkey is generated |
5418 | * for a peer. Call the real callback and decrement the | 5399 | * for a peer. Call the real callback and decrement the |
@@ -5424,22 +5405,22 @@ decrement_outstanding_at_host(const char *hostname, struct GNUNET_TESTING_PeerGr | |||
5424 | * @param emsg error message (NULL on success) | 5405 | * @param emsg error message (NULL on success) |
5425 | */ | 5406 | */ |
5426 | static void | 5407 | static void |
5427 | internal_hostkey_callback (void *cls, | 5408 | internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, |
5428 | const struct GNUNET_PeerIdentity *id, | 5409 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5429 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | ||
5430 | { | 5410 | { |
5431 | struct InternalStartContext *internal_context = cls; | 5411 | struct InternalStartContext *internal_context = cls; |
5432 | internal_context->peer->pg->starting--; | 5412 | internal_context->peer->pg->starting--; |
5433 | internal_context->peer->pg->started++; | 5413 | internal_context->peer->pg->started++; |
5434 | if (internal_context->hostname != NULL) | 5414 | if (internal_context->hostname != NULL) |
5435 | decrement_outstanding_at_host(internal_context->hostname, internal_context->peer->pg); | 5415 | decrement_outstanding_at_host (internal_context->hostname, |
5416 | internal_context->peer->pg); | ||
5436 | if (internal_context->hostkey_callback != NULL) | 5417 | if (internal_context->hostkey_callback != NULL) |
5437 | internal_context->hostkey_callback (internal_context->hostkey_cls, id, d, | 5418 | internal_context->hostkey_callback (internal_context->hostkey_cls, id, d, |
5438 | emsg); | 5419 | emsg); |
5439 | else if (internal_context->peer->pg->started == | 5420 | else if (internal_context->peer->pg->started |
5440 | internal_context->peer->pg->total) | 5421 | == internal_context->peer->pg->total) |
5441 | { | 5422 | { |
5442 | internal_context->peer->pg->started = 0; /* Internal startup may use this counter! */ | 5423 | internal_context->peer->pg->started = 0; /* Internal startup may use this counter! */ |
5443 | GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg); | 5424 | GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg); |
5444 | } | 5425 | } |
5445 | } | 5426 | } |
@@ -5456,23 +5437,23 @@ internal_hostkey_callback (void *cls, | |||
5456 | * @param emsg error message (NULL on success) | 5437 | * @param emsg error message (NULL on success) |
5457 | */ | 5438 | */ |
5458 | static void | 5439 | static void |
5459 | internal_startup_callback (void *cls, | 5440 | internal_startup_callback(void *cls, const struct GNUNET_PeerIdentity *id, |
5460 | const struct GNUNET_PeerIdentity *id, | 5441 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
5461 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 5442 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5462 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | ||
5463 | { | 5443 | { |
5464 | struct InternalStartContext *internal_context = cls; | 5444 | struct InternalStartContext *internal_context = cls; |
5465 | internal_context->peer->pg->starting--; | 5445 | internal_context->peer->pg->starting--; |
5466 | if (internal_context->hostname != NULL) | 5446 | if (internal_context->hostname != NULL) |
5467 | decrement_outstanding_at_host(internal_context->hostname, internal_context->peer->pg); | 5447 | decrement_outstanding_at_host (internal_context->hostname, |
5448 | internal_context->peer->pg); | ||
5468 | if (internal_context->start_cb != NULL) | 5449 | if (internal_context->start_cb != NULL) |
5469 | internal_context->start_cb (internal_context->start_cb_cls, id, cfg, d, | 5450 | internal_context->start_cb (internal_context->start_cb_cls, id, cfg, d, |
5470 | emsg); | 5451 | emsg); |
5471 | } | 5452 | } |
5472 | 5453 | ||
5473 | static void | 5454 | static void |
5474 | internal_continue_startup (void *cls, | 5455 | internal_continue_startup(void *cls, |
5475 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 5456 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
5476 | { | 5457 | { |
5477 | struct InternalStartContext *internal_context = cls; | 5458 | struct InternalStartContext *internal_context = cls; |
5478 | 5459 | ||
@@ -5481,25 +5462,30 @@ internal_continue_startup (void *cls, | |||
5481 | return; | 5462 | return; |
5482 | } | 5463 | } |
5483 | 5464 | ||
5484 | if ((internal_context->peer->pg->starting < internal_context->peer->pg->max_concurrent_ssh) || | 5465 | if ((internal_context->peer->pg->starting |
5485 | ((internal_context->hostname != NULL) && | 5466 | < internal_context->peer->pg->max_concurrent_ssh) |
5486 | (count_outstanding_at_host(internal_context->hostname, internal_context->peer->pg) < internal_context->peer->pg->max_concurrent_ssh))) | 5467 | || ((internal_context->hostname != NULL) |
5468 | && (count_outstanding_at_host (internal_context->hostname, | ||
5469 | internal_context->peer->pg) | ||
5470 | < internal_context->peer->pg->max_concurrent_ssh))) | ||
5487 | { | 5471 | { |
5488 | if (internal_context->hostname != NULL) | 5472 | if (internal_context->hostname != NULL) |
5489 | increment_outstanding_at_host(internal_context->hostname, internal_context->peer->pg); | 5473 | increment_outstanding_at_host (internal_context->hostname, |
5474 | internal_context->peer->pg); | ||
5490 | internal_context->peer->pg->starting++; | 5475 | internal_context->peer->pg->starting++; |
5491 | GNUNET_TESTING_daemon_continue_startup (internal_context->peer->daemon); | 5476 | GNUNET_TESTING_daemon_continue_startup (internal_context->peer->daemon); |
5492 | } | 5477 | } |
5493 | else | 5478 | else |
5494 | { | 5479 | { |
5495 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 5480 | GNUNET_SCHEDULER_add_delayed ( |
5496 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 5481 | GNUNET_TIME_relative_multiply ( |
5482 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
5483 | 100), | ||
5497 | &internal_continue_startup, | 5484 | &internal_continue_startup, |
5498 | internal_context); | 5485 | internal_context); |
5499 | } | 5486 | } |
5500 | } | 5487 | } |
5501 | 5488 | ||
5502 | |||
5503 | /** | 5489 | /** |
5504 | * Callback for informing us about a successful | 5490 | * Callback for informing us about a successful |
5505 | * or unsuccessful churn start call. | 5491 | * or unsuccessful churn start call. |
@@ -5512,10 +5498,9 @@ internal_continue_startup (void *cls, | |||
5512 | * | 5498 | * |
5513 | */ | 5499 | */ |
5514 | void | 5500 | void |
5515 | churn_start_callback (void *cls, | 5501 | churn_start_callback(void *cls, const struct GNUNET_PeerIdentity *id, |
5516 | const struct GNUNET_PeerIdentity *id, | 5502 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
5517 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 5503 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5518 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | ||
5519 | { | 5504 | { |
5520 | struct ChurnRestartContext *startup_ctx = cls; | 5505 | struct ChurnRestartContext *startup_ctx = cls; |
5521 | struct ChurnContext *churn_ctx = startup_ctx->churn_ctx; | 5506 | struct ChurnContext *churn_ctx = startup_ctx->churn_ctx; |
@@ -5537,18 +5522,17 @@ churn_start_callback (void *cls, | |||
5537 | 5522 | ||
5538 | #if DEBUG_CHURN | 5523 | #if DEBUG_CHURN |
5539 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 5524 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
5540 | "Started peer, %d left.\n", churn_ctx->num_to_start); | 5525 | "Started peer, %d left.\n", churn_ctx->num_to_start); |
5541 | #endif | 5526 | #endif |
5542 | 5527 | ||
5543 | total_left = | 5528 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) |
5544 | (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + | 5529 | + (churn_ctx->num_to_start - churn_ctx->num_failed_start); |
5545 | (churn_ctx->num_to_start - churn_ctx->num_failed_start); | ||
5546 | 5530 | ||
5547 | if (total_left == 0) | 5531 | if (total_left == 0) |
5548 | { | 5532 | { |
5549 | if ((churn_ctx->num_failed_stop > 0) | 5533 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) |
5550 | || (churn_ctx->num_failed_start > 0)) | 5534 | GNUNET_asprintf ( |
5551 | GNUNET_asprintf (&error_message, | 5535 | &error_message, |
5552 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", | 5536 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", |
5553 | churn_ctx->num_failed_start, | 5537 | churn_ctx->num_failed_start, |
5554 | churn_ctx->num_failed_stop); | 5538 | churn_ctx->num_failed_stop); |
@@ -5559,33 +5543,29 @@ churn_start_callback (void *cls, | |||
5559 | } | 5543 | } |
5560 | } | 5544 | } |
5561 | 5545 | ||
5562 | |||
5563 | static void | 5546 | static void |
5564 | schedule_churn_restart (void *cls, | 5547 | schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
5565 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
5566 | { | 5548 | { |
5567 | struct PeerRestartContext *peer_restart_ctx = cls; | 5549 | struct PeerRestartContext *peer_restart_ctx = cls; |
5568 | struct ChurnRestartContext *startup_ctx = | 5550 | struct ChurnRestartContext *startup_ctx = peer_restart_ctx->churn_restart_ctx; |
5569 | peer_restart_ctx->churn_restart_ctx; | ||
5570 | 5551 | ||
5571 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) | 5552 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) |
5572 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 5553 | GNUNET_SCHEDULER_add_delayed ( |
5573 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 5554 | GNUNET_TIME_relative_multiply ( |
5555 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
5556 | 100), | ||
5574 | &schedule_churn_restart, peer_restart_ctx); | 5557 | &schedule_churn_restart, peer_restart_ctx); |
5575 | else | 5558 | else |
5576 | { | 5559 | { |
5577 | GNUNET_TESTING_daemon_start_stopped (peer_restart_ctx->daemon, | 5560 | GNUNET_TESTING_daemon_start_stopped (peer_restart_ctx->daemon, |
5578 | startup_ctx->timeout, | 5561 | startup_ctx->timeout, |
5579 | &churn_start_callback, | 5562 | &churn_start_callback, startup_ctx); |
5580 | startup_ctx); | ||
5581 | GNUNET_free (peer_restart_ctx); | 5563 | GNUNET_free (peer_restart_ctx); |
5582 | } | 5564 | } |
5583 | } | 5565 | } |
5584 | 5566 | ||
5585 | |||
5586 | |||
5587 | static void | 5567 | static void |
5588 | internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 5568 | internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
5589 | { | 5569 | { |
5590 | struct InternalStartContext *internal_context = cls; | 5570 | struct InternalStartContext *internal_context = cls; |
5591 | 5571 | ||
@@ -5594,29 +5574,35 @@ internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5594 | return; | 5574 | return; |
5595 | } | 5575 | } |
5596 | 5576 | ||
5597 | if ((internal_context->peer->pg->starting < internal_context->peer->pg->max_concurrent_ssh) || | 5577 | if ((internal_context->peer->pg->starting |
5598 | ((internal_context->hostname != NULL) && | 5578 | < internal_context->peer->pg->max_concurrent_ssh) |
5599 | (count_outstanding_at_host(internal_context->hostname, internal_context->peer->pg) < internal_context->peer->pg->max_concurrent_ssh))) | 5579 | || ((internal_context->hostname != NULL) |
5580 | && (count_outstanding_at_host (internal_context->hostname, | ||
5581 | internal_context->peer->pg) | ||
5582 | < internal_context->peer->pg->max_concurrent_ssh))) | ||
5600 | { | 5583 | { |
5601 | if (internal_context->hostname != NULL) | 5584 | if (internal_context->hostname != NULL) |
5602 | increment_outstanding_at_host(internal_context->hostname, internal_context->peer->pg); | 5585 | increment_outstanding_at_host (internal_context->hostname, |
5586 | internal_context->peer->pg); | ||
5603 | internal_context->peer->pg->starting++; | 5587 | internal_context->peer->pg->starting++; |
5604 | internal_context->peer->daemon = | 5588 | internal_context->peer->daemon |
5605 | GNUNET_TESTING_daemon_start (internal_context->peer->cfg, | 5589 | = GNUNET_TESTING_daemon_start (internal_context->peer->cfg, |
5606 | internal_context->timeout, | 5590 | internal_context->timeout, |
5607 | internal_context->hostname, | 5591 | internal_context->hostname, |
5608 | internal_context->username, | 5592 | internal_context->username, |
5609 | internal_context->sshport, | 5593 | internal_context->sshport, |
5610 | internal_context->hostkey, | 5594 | internal_context->hostkey, |
5611 | &internal_hostkey_callback, | 5595 | &internal_hostkey_callback, |
5612 | internal_context, | 5596 | internal_context, |
5613 | &internal_startup_callback, | 5597 | &internal_startup_callback, |
5614 | internal_context); | 5598 | internal_context); |
5615 | } | 5599 | } |
5616 | else | 5600 | else |
5617 | { | 5601 | { |
5618 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 5602 | GNUNET_SCHEDULER_add_delayed ( |
5619 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 5603 | GNUNET_TIME_relative_multiply ( |
5604 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
5605 | 100), | ||
5620 | &internal_start, internal_context); | 5606 | &internal_start, internal_context); |
5621 | } | 5607 | } |
5622 | } | 5608 | } |
@@ -5629,7 +5615,7 @@ internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5629 | * | 5615 | * |
5630 | */ | 5616 | */ |
5631 | void | 5617 | void |
5632 | GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg) | 5618 | GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg) |
5633 | { | 5619 | { |
5634 | unsigned int i; | 5620 | unsigned int i; |
5635 | 5621 | ||
@@ -5651,7 +5637,7 @@ GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg) | |||
5651 | * @param cfg configuration template to use | 5637 | * @param cfg configuration template to use |
5652 | * @param total number of daemons to start | 5638 | * @param total number of daemons to start |
5653 | * @param max_concurrent_connections for testing, how many peers can | 5639 | * @param max_concurrent_connections for testing, how many peers can |
5654 | * we connect to simultaneously | 5640 | * we connect to simultaneously |
5655 | * @param max_concurrent_ssh when starting with ssh, how many ssh | 5641 | * @param max_concurrent_ssh when starting with ssh, how many ssh |
5656 | * connections will we allow at once (based on remote hosts allowed!) | 5642 | * connections will we allow at once (based on remote hosts allowed!) |
5657 | * @param timeout total time allowed for peers to start | 5643 | * @param timeout total time allowed for peers to start |
@@ -5670,18 +5656,13 @@ GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg) | |||
5670 | * @return NULL on error, otherwise handle to control peer group | 5656 | * @return NULL on error, otherwise handle to control peer group |
5671 | */ | 5657 | */ |
5672 | struct GNUNET_TESTING_PeerGroup * | 5658 | struct GNUNET_TESTING_PeerGroup * |
5673 | GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 5659 | GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, |
5674 | unsigned int total, | 5660 | unsigned int total, unsigned int max_concurrent_connections, |
5675 | unsigned int max_concurrent_connections, | 5661 | unsigned int max_concurrent_ssh, struct GNUNET_TIME_Relative timeout, |
5676 | unsigned int max_concurrent_ssh, | 5662 | GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback, void *hostkey_cls, |
5677 | struct GNUNET_TIME_Relative timeout, | 5663 | GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls, |
5678 | GNUNET_TESTING_NotifyHostkeyCreated | 5664 | GNUNET_TESTING_NotifyConnection connect_callback, |
5679 | hostkey_callback, void *hostkey_cls, | 5665 | void *connect_callback_cls, const struct GNUNET_TESTING_Host *hostnames) |
5680 | GNUNET_TESTING_NotifyDaemonRunning cb, | ||
5681 | void *cb_cls, | ||
5682 | GNUNET_TESTING_NotifyConnection | ||
5683 | connect_callback, void *connect_callback_cls, | ||
5684 | const struct GNUNET_TESTING_Host *hostnames) | ||
5685 | { | 5666 | { |
5686 | struct GNUNET_TESTING_PeerGroup *pg; | 5667 | struct GNUNET_TESTING_PeerGroup *pg; |
5687 | const struct GNUNET_TESTING_Host *hostpos; | 5668 | const struct GNUNET_TESTING_Host *hostpos; |
@@ -5764,12 +5745,12 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5764 | off = 2; | 5745 | off = 2; |
5765 | /* skip leading spaces */ | 5746 | /* skip leading spaces */ |
5766 | while ((0 != *hostnames) && (isspace ((unsigned char) *hostnames))) | 5747 | while ((0 != *hostnames) && (isspace ((unsigned char) *hostnames))) |
5767 | hostnames++; | 5748 | hostnames++; |
5768 | rpos = hostnames; | 5749 | rpos = hostnames; |
5769 | while ('\0' != *rpos) | 5750 | while ('\0' != *rpos) |
5770 | { | 5751 | { |
5771 | if (isspace ((unsigned char) *rpos)) | 5752 | if (isspace ((unsigned char) *rpos)) |
5772 | off++; | 5753 | off++; |
5773 | rpos++; | 5754 | rpos++; |
5774 | } | 5755 | } |
5775 | pg->hosts = GNUNET_malloc (off * sizeof (struct HostData)); | 5756 | pg->hosts = GNUNET_malloc (off * sizeof (struct HostData)); |
@@ -5802,7 +5783,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5802 | pg->hosts = NULL; | 5783 | pg->hosts = NULL; |
5803 | } | 5784 | } |
5804 | hostcnt = off; | 5785 | hostcnt = off; |
5805 | minport = 0; /* make gcc happy */ | 5786 | minport = 0; /* make gcc happy */ |
5806 | #endif | 5787 | #endif |
5807 | } | 5788 | } |
5808 | else | 5789 | else |
@@ -5813,7 +5794,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5813 | 5794 | ||
5814 | /* Create the servicehome directory for each remote peer */ | 5795 | /* Create the servicehome directory for each remote peer */ |
5815 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", | 5796 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", |
5816 | &baseservicehome)); | 5797 | &baseservicehome)); |
5817 | for (i = 0; i < pg->num_hosts; i++) | 5798 | for (i = 0; i < pg->num_hosts; i++) |
5818 | { | 5799 | { |
5819 | struct OutstandingSSH *ssh_entry; | 5800 | struct OutstandingSSH *ssh_entry; |
@@ -5821,32 +5802,37 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5821 | ssh_entry->hostname = pg->hosts[i].hostname; /* Don't free! */ | 5802 | ssh_entry->hostname = pg->hosts[i].hostname; /* Don't free! */ |
5822 | GNUNET_CONTAINER_DLL_insert(pg->ssh_head, pg->ssh_tail, ssh_entry); | 5803 | GNUNET_CONTAINER_DLL_insert(pg->ssh_head, pg->ssh_tail, ssh_entry); |
5823 | if (NULL != pg->hosts[i].username) | 5804 | if (NULL != pg->hosts[i].username) |
5824 | GNUNET_asprintf (&arg, "%s@%s", pg->hosts[i].username, pg->hosts[i].hostname); | 5805 | GNUNET_asprintf (&arg, "%s@%s", pg->hosts[i].username, |
5806 | pg->hosts[i].hostname); | ||
5825 | else | 5807 | else |
5826 | GNUNET_asprintf (&arg, "%s", pg->hosts[i].hostname); | 5808 | GNUNET_asprintf (&arg, "%s", pg->hosts[i].hostname); |
5827 | if (pg->hosts[i].sshport != 0) | 5809 | if (pg->hosts[i].sshport != 0) |
5828 | { | 5810 | { |
5829 | GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport); | 5811 | GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport); |
5830 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", | 5812 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P", |
5831 | "ssh", "-P", ssh_port_str, | 5813 | ssh_port_str, |
5832 | #if !DEBUG_TESTING | 5814 | #if !DEBUG_TESTING |
5833 | "-q", | 5815 | "-q", |
5834 | #endif | 5816 | #endif |
5835 | arg, "mkdir -p", baseservicehome, NULL); | 5817 | arg, "mkdir -p", baseservicehome, |
5818 | NULL); | ||
5836 | } | 5819 | } |
5837 | else | 5820 | else |
5838 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", | 5821 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, |
5839 | "ssh", arg, "mkdir -p", baseservicehome, NULL); | 5822 | "mkdir -p", baseservicehome, NULL); |
5840 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating remote dir with command ssh %s %s %s\n", arg, " mkdir -p ", baseservicehome); | 5823 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5841 | GNUNET_OS_process_wait(proc); | 5824 | "Creating remote dir with command ssh %s %s %s\n", arg, |
5825 | " mkdir -p ", baseservicehome); | ||
5826 | GNUNET_OS_process_wait (proc); | ||
5842 | } | 5827 | } |
5843 | GNUNET_free(baseservicehome); | 5828 | GNUNET_free(baseservicehome); |
5844 | 5829 | ||
5845 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "HOSTKEYSFILE", | 5830 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", |
5846 | &hostkeys_file)) | 5831 | "HOSTKEYSFILE", |
5832 | &hostkeys_file)) | ||
5847 | { | 5833 | { |
5848 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) | 5834 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) |
5849 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Couldn't read hostkeys file!\n"); | 5835 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't read hostkeys file!\n"); |
5850 | else | 5836 | else |
5851 | { | 5837 | { |
5852 | /* Check hostkey file size, read entire thing into memory */ | 5838 | /* Check hostkey file size, read entire thing into memory */ |
@@ -5858,19 +5844,26 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5858 | return NULL; | 5844 | return NULL; |
5859 | } | 5845 | } |
5860 | 5846 | ||
5861 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES)) | 5847 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, |
5848 | GNUNET_YES)) | ||
5862 | fs = 0; | 5849 | fs = 0; |
5863 | 5850 | ||
5864 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", fs, HOSTKEYFILESIZE); | 5851 | GNUNET_log ( |
5852 | GNUNET_ERROR_TYPE_WARNING, | ||
5853 | "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", | ||
5854 | fs, HOSTKEYFILESIZE); | ||
5865 | 5855 | ||
5866 | if (fs % HOSTKEYFILESIZE != 0) | 5856 | if (fs % HOSTKEYFILESIZE != 0) |
5867 | { | 5857 | { |
5868 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "File size %llu seems incorrect for hostkeys...\n", fs); | 5858 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
5859 | "File size %llu seems incorrect for hostkeys...\n", | ||
5860 | fs); | ||
5869 | } | 5861 | } |
5870 | else | 5862 | else |
5871 | { | 5863 | { |
5872 | total_hostkeys = fs / HOSTKEYFILESIZE; | 5864 | total_hostkeys = fs / HOSTKEYFILESIZE; |
5873 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Will read %llu hostkeys from file\n", total_hostkeys); | 5865 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
5866 | "Will read %llu hostkeys from file\n", total_hostkeys); | ||
5874 | pg->hostkey_data = GNUNET_malloc_large (fs); | 5867 | pg->hostkey_data = GNUNET_malloc_large (fs); |
5875 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs)); | 5868 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs)); |
5876 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd)); | 5869 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd)); |
@@ -5886,9 +5879,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5886 | hostname = pg->hosts[off % hostcnt].hostname; | 5879 | hostname = pg->hosts[off % hostcnt].hostname; |
5887 | username = pg->hosts[off % hostcnt].username; | 5880 | username = pg->hosts[off % hostcnt].username; |
5888 | sshport = pg->hosts[off % hostcnt].sshport; | 5881 | sshport = pg->hosts[off % hostcnt].sshport; |
5889 | pcfg = make_config (cfg, | 5882 | pcfg = make_config (cfg, off, &pg->hosts[off % hostcnt].minport, |
5890 | off, | ||
5891 | &pg->hosts[off % hostcnt].minport, | ||
5892 | &upnum, hostname, &fdnum); | 5883 | &upnum, hostname, &fdnum); |
5893 | } | 5884 | } |
5894 | else | 5885 | else |
@@ -5901,16 +5892,16 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5901 | 5892 | ||
5902 | if (NULL == pcfg) | 5893 | if (NULL == pcfg) |
5903 | { | 5894 | { |
5904 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 5895 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ |
5905 | _ | 5896 | ("Could not create configuration for peer number %u on `%s'!\n"), |
5906 | ("Could not create configuration for peer number %u on `%s'!\n"), | ||
5907 | off, hostname == NULL ? "localhost" : hostname); | 5897 | off, hostname == NULL ? "localhost" : hostname); |
5908 | continue; | 5898 | continue; |
5909 | } | 5899 | } |
5910 | 5900 | ||
5911 | if (GNUNET_YES == | 5901 | if (GNUNET_YES |
5912 | GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", "SERVICEHOME", | 5902 | == GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", |
5913 | &baseservicehome)) | 5903 | "SERVICEHOME", |
5904 | &baseservicehome)) | ||
5914 | { | 5905 | { |
5915 | GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off); | 5906 | GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off); |
5916 | GNUNET_free (baseservicehome); | 5907 | GNUNET_free (baseservicehome); |
@@ -5919,23 +5910,21 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5919 | { | 5910 | { |
5920 | tmpdir = getenv ("TMPDIR"); | 5911 | tmpdir = getenv ("TMPDIR"); |
5921 | tmpdir = tmpdir ? tmpdir : "/tmp"; | 5912 | tmpdir = tmpdir ? tmpdir : "/tmp"; |
5922 | GNUNET_asprintf (&newservicehome, | 5913 | GNUNET_asprintf (&newservicehome, "%s/%s/%d/", tmpdir, |
5923 | "%s/%s/%d/", | 5914 | "gnunet-testing-test-test", off); |
5924 | tmpdir, "gnunet-testing-test-test", off); | ||
5925 | } | 5915 | } |
5926 | GNUNET_CONFIGURATION_set_value_string (pcfg, | 5916 | GNUNET_CONFIGURATION_set_value_string (pcfg, "PATHS", "SERVICEHOME", |
5927 | "PATHS", | 5917 | newservicehome); |
5928 | "SERVICEHOME", newservicehome); | ||
5929 | GNUNET_free (newservicehome); | 5918 | GNUNET_free (newservicehome); |
5930 | pg->peers[off].cfg = pcfg; | 5919 | pg->peers[off].cfg = pcfg; |
5931 | #if DEFER | 5920 | #if DEFER |
5932 | /* Can we do this later? */ | 5921 | /* Can we do this later? */ |
5933 | pg->peers[off].allowed_peers = | 5922 | pg->peers[off].allowed_peers = |
5934 | GNUNET_CONTAINER_multihashmap_create (total); | 5923 | GNUNET_CONTAINER_multihashmap_create (total); |
5935 | pg->peers[off].connect_peers = | 5924 | pg->peers[off].connect_peers = |
5936 | GNUNET_CONTAINER_multihashmap_create (total); | 5925 | GNUNET_CONTAINER_multihashmap_create (total); |
5937 | pg->peers[off].blacklisted_peers = | 5926 | pg->peers[off].blacklisted_peers = |
5938 | GNUNET_CONTAINER_multihashmap_create (total); | 5927 | GNUNET_CONTAINER_multihashmap_create (total); |
5939 | 5928 | ||
5940 | #endif | 5929 | #endif |
5941 | pg->peers[off].pg = pg; | 5930 | pg->peers[off].pg = pg; |
@@ -5945,7 +5934,8 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5945 | pg->peers[off].internal_context.username = username; | 5934 | pg->peers[off].internal_context.username = username; |
5946 | pg->peers[off].internal_context.sshport = sshport; | 5935 | pg->peers[off].internal_context.sshport = sshport; |
5947 | if (pg->hostkey_data != NULL) | 5936 | if (pg->hostkey_data != NULL) |
5948 | pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off * HOSTKEYFILESIZE]; | 5937 | pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off |
5938 | * HOSTKEYFILESIZE]; | ||
5949 | pg->peers[off].internal_context.hostkey_callback = hostkey_callback; | 5939 | pg->peers[off].internal_context.hostkey_callback = hostkey_callback; |
5950 | pg->peers[off].internal_context.hostkey_cls = hostkey_cls; | 5940 | pg->peers[off].internal_context.hostkey_cls = hostkey_cls; |
5951 | pg->peers[off].internal_context.start_cb = cb; | 5941 | pg->peers[off].internal_context.start_cb = cb; |
@@ -5963,8 +5953,8 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5963 | * offsetting operation. | 5953 | * offsetting operation. |
5964 | */ | 5954 | */ |
5965 | struct GNUNET_TESTING_Daemon * | 5955 | struct GNUNET_TESTING_Daemon * |
5966 | GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, | 5956 | GNUNET_TESTING_daemon_get(struct GNUNET_TESTING_PeerGroup *pg, |
5967 | unsigned int position) | 5957 | unsigned int position) |
5968 | { | 5958 | { |
5969 | if (position < pg->total) | 5959 | if (position < pg->total) |
5970 | return pg->peers[position].daemon; | 5960 | return pg->peers[position].daemon; |
@@ -5982,16 +5972,15 @@ GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, | |||
5982 | * @return the daemon on success, or NULL if no such peer identity is found | 5972 | * @return the daemon on success, or NULL if no such peer identity is found |
5983 | */ | 5973 | */ |
5984 | struct GNUNET_TESTING_Daemon * | 5974 | struct GNUNET_TESTING_Daemon * |
5985 | GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg, | 5975 | GNUNET_TESTING_daemon_get_by_id(struct GNUNET_TESTING_PeerGroup *pg, |
5986 | struct GNUNET_PeerIdentity *peer_id) | 5976 | struct GNUNET_PeerIdentity *peer_id) |
5987 | { | 5977 | { |
5988 | unsigned int i; | 5978 | unsigned int i; |
5989 | 5979 | ||
5990 | for (i = 0; i < pg->total; i++) | 5980 | for (i = 0; i < pg->total; i++) |
5991 | { | 5981 | { |
5992 | if (0 == | 5982 | if (0 == memcmp (&pg->peers[i].daemon->id, peer_id, |
5993 | memcmp (&pg->peers[i].daemon->id, peer_id, | 5983 | sizeof(struct GNUNET_PeerIdentity))) |
5994 | sizeof (struct GNUNET_PeerIdentity))) | ||
5995 | return pg->peers[i].daemon; | 5984 | return pg->peers[i].daemon; |
5996 | } | 5985 | } |
5997 | 5986 | ||
@@ -6009,10 +5998,9 @@ GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg, | |||
6009 | * @param emsg NULL on success | 5998 | * @param emsg NULL on success |
6010 | */ | 5999 | */ |
6011 | void | 6000 | void |
6012 | restart_callback (void *cls, | 6001 | restart_callback(void *cls, const struct GNUNET_PeerIdentity *id, |
6013 | const struct GNUNET_PeerIdentity *id, | 6002 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
6014 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 6003 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
6015 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | ||
6016 | { | 6004 | { |
6017 | struct RestartContext *restart_context = cls; | 6005 | struct RestartContext *restart_context = cls; |
6018 | 6006 | ||
@@ -6030,9 +6018,8 @@ restart_callback (void *cls, | |||
6030 | restart_context->callback (restart_context->callback_cls, NULL); | 6018 | restart_context->callback (restart_context->callback_cls, NULL); |
6031 | GNUNET_free (restart_context); | 6019 | GNUNET_free (restart_context); |
6032 | } | 6020 | } |
6033 | else if (restart_context->peers_restart_failed + | 6021 | else if (restart_context->peers_restart_failed |
6034 | restart_context->peers_restarted == | 6022 | + restart_context->peers_restarted == restart_context->peer_group->total) |
6035 | restart_context->peer_group->total) | ||
6036 | { | 6023 | { |
6037 | restart_context->callback (restart_context->callback_cls, | 6024 | restart_context->callback (restart_context->callback_cls, |
6038 | "Failed to restart peers!"); | 6025 | "Failed to restart peers!"); |
@@ -6050,7 +6037,7 @@ restart_callback (void *cls, | |||
6050 | * | 6037 | * |
6051 | */ | 6038 | */ |
6052 | void | 6039 | void |
6053 | churn_stop_callback (void *cls, const char *emsg) | 6040 | churn_stop_callback(void *cls, const char *emsg) |
6054 | { | 6041 | { |
6055 | struct ShutdownContext *shutdown_ctx = cls; | 6042 | struct ShutdownContext *shutdown_ctx = cls; |
6056 | struct ChurnContext *churn_ctx = shutdown_ctx->cb_cls; | 6043 | struct ChurnContext *churn_ctx = shutdown_ctx->cb_cls; |
@@ -6073,18 +6060,17 @@ churn_stop_callback (void *cls, const char *emsg) | |||
6073 | 6060 | ||
6074 | #if DEBUG_CHURN | 6061 | #if DEBUG_CHURN |
6075 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6062 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6076 | "Stopped peer, %d left.\n", churn_ctx->num_to_stop); | 6063 | "Stopped peer, %d left.\n", churn_ctx->num_to_stop); |
6077 | #endif | 6064 | #endif |
6078 | total_left = | 6065 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) |
6079 | (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + | 6066 | + (churn_ctx->num_to_start - churn_ctx->num_failed_start); |
6080 | (churn_ctx->num_to_start - churn_ctx->num_failed_start); | ||
6081 | 6067 | ||
6082 | if (total_left == 0) | 6068 | if (total_left == 0) |
6083 | { | 6069 | { |
6084 | if ((churn_ctx->num_failed_stop > 0) | 6070 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) |
6085 | || (churn_ctx->num_failed_start > 0)) | ||
6086 | { | 6071 | { |
6087 | GNUNET_asprintf (&error_message, | 6072 | GNUNET_asprintf ( |
6073 | &error_message, | ||
6088 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", | 6074 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", |
6089 | churn_ctx->num_failed_start, | 6075 | churn_ctx->num_failed_start, |
6090 | churn_ctx->num_failed_stop); | 6076 | churn_ctx->num_failed_stop); |
@@ -6104,7 +6090,7 @@ churn_stop_callback (void *cls, const char *emsg) | |||
6104 | * @return the number of currently running peers in the peer group | 6090 | * @return the number of currently running peers in the peer group |
6105 | */ | 6091 | */ |
6106 | unsigned int | 6092 | unsigned int |
6107 | GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg) | 6093 | GNUNET_TESTING_daemons_running(struct GNUNET_TESTING_PeerGroup *pg) |
6108 | { | 6094 | { |
6109 | unsigned int i; | 6095 | unsigned int i; |
6110 | unsigned int running = 0; | 6096 | unsigned int running = 0; |
@@ -6127,8 +6113,8 @@ GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg) | |||
6127 | * to calling gnunet-arm N times all at once). | 6113 | * to calling gnunet-arm N times all at once). |
6128 | */ | 6114 | */ |
6129 | static void | 6115 | static void |
6130 | schedule_churn_shutdown_task (void *cls, | 6116 | schedule_churn_shutdown_task(void *cls, |
6131 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 6117 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
6132 | { | 6118 | { |
6133 | struct PeerShutdownContext *peer_shutdown_ctx = cls; | 6119 | struct PeerShutdownContext *peer_shutdown_ctx = cls; |
6134 | struct ShutdownContext *shutdown_ctx; | 6120 | struct ShutdownContext *shutdown_ctx; |
@@ -6136,10 +6122,12 @@ schedule_churn_shutdown_task (void *cls, | |||
6136 | GNUNET_assert (peer_shutdown_ctx != NULL); | 6122 | GNUNET_assert (peer_shutdown_ctx != NULL); |
6137 | shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; | 6123 | shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; |
6138 | GNUNET_assert (shutdown_ctx != NULL); | 6124 | GNUNET_assert (shutdown_ctx != NULL); |
6139 | churn_ctx = (struct ChurnContext *)shutdown_ctx->cb_cls; | 6125 | churn_ctx = (struct ChurnContext *) shutdown_ctx->cb_cls; |
6140 | if (shutdown_ctx->outstanding > churn_ctx->pg->max_concurrent_ssh) | 6126 | if (shutdown_ctx->outstanding > churn_ctx->pg->max_concurrent_ssh) |
6141 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 6127 | GNUNET_SCHEDULER_add_delayed ( |
6142 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 6128 | GNUNET_TIME_relative_multiply ( |
6129 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
6130 | 100), | ||
6143 | &schedule_churn_shutdown_task, | 6131 | &schedule_churn_shutdown_task, |
6144 | peer_shutdown_ctx); | 6132 | peer_shutdown_ctx); |
6145 | else | 6133 | else |
@@ -6173,12 +6161,9 @@ schedule_churn_shutdown_task (void *cls, | |||
6173 | * @param cb_cls closure for cb | 6161 | * @param cb_cls closure for cb |
6174 | */ | 6162 | */ |
6175 | void | 6163 | void |
6176 | GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | 6164 | GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg, |
6177 | unsigned int voff, | 6165 | unsigned int voff, unsigned int von, struct GNUNET_TIME_Relative timeout, |
6178 | unsigned int von, | 6166 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
6179 | struct GNUNET_TIME_Relative timeout, | ||
6180 | GNUNET_TESTING_NotifyCompletion cb, | ||
6181 | void *cb_cls) | ||
6182 | { | 6167 | { |
6183 | struct ChurnContext *churn_ctx; | 6168 | struct ChurnContext *churn_ctx; |
6184 | struct ShutdownContext *shutdown_ctx; | 6169 | struct ShutdownContext *shutdown_ctx; |
@@ -6199,7 +6184,7 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | |||
6199 | running = 0; | 6184 | running = 0; |
6200 | stopped = 0; | 6185 | stopped = 0; |
6201 | 6186 | ||
6202 | if ((von == 0) && (voff == 0)) /* No peers at all? */ | 6187 | if ((von == 0) && (voff == 0)) /* No peers at all? */ |
6203 | { | 6188 | { |
6204 | cb (cb_cls, NULL); | 6189 | cb (cb_cls, NULL); |
6205 | return; | 6190 | return; |
@@ -6249,11 +6234,11 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | |||
6249 | stopped_permute = NULL; | 6234 | stopped_permute = NULL; |
6250 | 6235 | ||
6251 | if (running > 0) | 6236 | if (running > 0) |
6252 | running_permute = | 6237 | running_permute = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, |
6253 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, running); | 6238 | running); |
6254 | if (stopped > 0) | 6239 | if (stopped > 0) |
6255 | stopped_permute = | 6240 | stopped_permute = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, |
6256 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, stopped); | 6241 | stopped); |
6257 | 6242 | ||
6258 | total_running = running; | 6243 | total_running = running; |
6259 | total_stopped = stopped; | 6244 | total_stopped = stopped; |
@@ -6296,21 +6281,21 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | |||
6296 | { | 6281 | { |
6297 | #if DEBUG_CHURN | 6282 | #if DEBUG_CHURN |
6298 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", | 6283 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", |
6299 | running_permute[i]); | 6284 | running_permute[i]); |
6300 | #endif | 6285 | #endif |
6301 | GNUNET_assert (running_arr != NULL); | 6286 | GNUNET_assert (running_arr != NULL); |
6302 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); | 6287 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); |
6303 | peer_shutdown_ctx->daemon = | 6288 | peer_shutdown_ctx->daemon |
6304 | pg->peers[running_arr[running_permute[i]]].daemon; | 6289 | = pg->peers[running_arr[running_permute[i]]].daemon; |
6305 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; | 6290 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; |
6306 | GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task, | 6291 | GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task, |
6307 | peer_shutdown_ctx); | 6292 | peer_shutdown_ctx); |
6308 | 6293 | ||
6309 | /* | 6294 | /* |
6310 | GNUNET_TESTING_daemon_stop (pg->peers[running_arr[running_permute[i]]].daemon, | 6295 | GNUNET_TESTING_daemon_stop (pg->peers[running_arr[running_permute[i]]].daemon, |
6311 | timeout, | 6296 | timeout, |
6312 | &churn_stop_callback, churn_ctx, | 6297 | &churn_stop_callback, churn_ctx, |
6313 | GNUNET_NO, GNUNET_YES); */ | 6298 | GNUNET_NO, GNUNET_YES); */ |
6314 | } | 6299 | } |
6315 | 6300 | ||
6316 | GNUNET_assert (stopped >= von); | 6301 | GNUNET_assert (stopped >= von); |
@@ -6325,17 +6310,17 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | |||
6325 | { | 6310 | { |
6326 | #if DEBUG_CHURN | 6311 | #if DEBUG_CHURN |
6327 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", | 6312 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", |
6328 | stopped_permute[i]); | 6313 | stopped_permute[i]); |
6329 | #endif | 6314 | #endif |
6330 | GNUNET_assert (stopped_arr != NULL); | 6315 | GNUNET_assert (stopped_arr != NULL); |
6331 | peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext)); | 6316 | peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext)); |
6332 | peer_restart_ctx->churn_restart_ctx = churn_startup_ctx; | 6317 | peer_restart_ctx->churn_restart_ctx = churn_startup_ctx; |
6333 | peer_restart_ctx->daemon = | 6318 | peer_restart_ctx->daemon |
6334 | pg->peers[stopped_arr[stopped_permute[i]]].daemon; | 6319 | = pg->peers[stopped_arr[stopped_permute[i]]].daemon; |
6335 | GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx); | 6320 | GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx); |
6336 | /* | 6321 | /* |
6337 | GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon, | 6322 | GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon, |
6338 | timeout, &churn_start_callback, churn_ctx); */ | 6323 | timeout, &churn_start_callback, churn_ctx); */ |
6339 | } | 6324 | } |
6340 | 6325 | ||
6341 | GNUNET_free_non_null (running_arr); | 6326 | GNUNET_free_non_null (running_arr); |
@@ -6344,7 +6329,6 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | |||
6344 | GNUNET_free_non_null (stopped_permute); | 6329 | GNUNET_free_non_null (stopped_permute); |
6345 | } | 6330 | } |
6346 | 6331 | ||
6347 | |||
6348 | /** | 6332 | /** |
6349 | * Restart all peers in the given group. | 6333 | * Restart all peers in the given group. |
6350 | * | 6334 | * |
@@ -6353,9 +6337,8 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | |||
6353 | * @param callback_cls closure for the callback function | 6337 | * @param callback_cls closure for the callback function |
6354 | */ | 6338 | */ |
6355 | void | 6339 | void |
6356 | GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, | 6340 | GNUNET_TESTING_daemons_restart(struct GNUNET_TESTING_PeerGroup *pg, |
6357 | GNUNET_TESTING_NotifyCompletion callback, | 6341 | GNUNET_TESTING_NotifyCompletion callback, void *callback_cls) |
6358 | void *callback_cls) | ||
6359 | { | 6342 | { |
6360 | struct RestartContext *restart_context; | 6343 | struct RestartContext *restart_context; |
6361 | unsigned int off; | 6344 | unsigned int off; |
@@ -6387,11 +6370,10 @@ GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, | |||
6387 | * @param cb_cls closure for cb | 6370 | * @param cb_cls closure for cb |
6388 | */ | 6371 | */ |
6389 | void | 6372 | void |
6390 | GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, | 6373 | GNUNET_TESTING_daemons_vary(struct GNUNET_TESTING_PeerGroup *pg, |
6391 | unsigned int offset, | 6374 | unsigned int offset, int desired_status, |
6392 | int desired_status, | 6375 | struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_NotifyCompletion cb, |
6393 | struct GNUNET_TIME_Relative timeout, | 6376 | void *cb_cls) |
6394 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | ||
6395 | { | 6377 | { |
6396 | struct ShutdownContext *shutdown_ctx; | 6378 | struct ShutdownContext *shutdown_ctx; |
6397 | struct ChurnRestartContext *startup_ctx; | 6379 | struct ChurnRestartContext *startup_ctx; |
@@ -6408,9 +6390,9 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, | |||
6408 | churn_ctx->cb = cb; | 6390 | churn_ctx->cb = cb; |
6409 | churn_ctx->cb_cls = cb_cls; | 6391 | churn_ctx->cb_cls = cb_cls; |
6410 | shutdown_ctx->cb_cls = churn_ctx; | 6392 | shutdown_ctx->cb_cls = churn_ctx; |
6411 | GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, | 6393 | GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, timeout, |
6412 | timeout, &churn_stop_callback, | 6394 | &churn_stop_callback, shutdown_ctx, |
6413 | shutdown_ctx, GNUNET_NO, GNUNET_YES); | 6395 | GNUNET_NO, GNUNET_YES); |
6414 | } | 6396 | } |
6415 | } | 6397 | } |
6416 | else if (GNUNET_YES == desired_status) | 6398 | else if (GNUNET_YES == desired_status) |
@@ -6433,7 +6415,6 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, | |||
6433 | GNUNET_break (0); | 6415 | GNUNET_break (0); |
6434 | } | 6416 | } |
6435 | 6417 | ||
6436 | |||
6437 | /** | 6418 | /** |
6438 | * Callback for shutting down peers in a peer group. | 6419 | * Callback for shutting down peers in a peer group. |
6439 | * | 6420 | * |
@@ -6441,7 +6422,7 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, | |||
6441 | * @param emsg NULL on success | 6422 | * @param emsg NULL on success |
6442 | */ | 6423 | */ |
6443 | void | 6424 | void |
6444 | internal_shutdown_callback (void *cls, const char *emsg) | 6425 | internal_shutdown_callback(void *cls, const char *emsg) |
6445 | { | 6426 | { |
6446 | struct ShutdownContext *shutdown_ctx = cls; | 6427 | struct ShutdownContext *shutdown_ctx = cls; |
6447 | unsigned int off; | 6428 | unsigned int off; |
@@ -6456,9 +6437,8 @@ internal_shutdown_callback (void *cls, const char *emsg) | |||
6456 | shutdown_ctx->peers_failed++; | 6437 | shutdown_ctx->peers_failed++; |
6457 | } | 6438 | } |
6458 | 6439 | ||
6459 | if ((shutdown_ctx->cb != NULL) | 6440 | if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down |
6460 | && (shutdown_ctx->peers_down + shutdown_ctx->peers_failed == | 6441 | + shutdown_ctx->peers_failed == shutdown_ctx->total_peers)) |
6461 | shutdown_ctx->total_peers)) | ||
6462 | { | 6442 | { |
6463 | if (shutdown_ctx->peers_failed > 0) | 6443 | if (shutdown_ctx->peers_failed > 0) |
6464 | shutdown_ctx->cb (shutdown_ctx->cb_cls, | 6444 | shutdown_ctx->cb (shutdown_ctx->cb_cls, |
@@ -6480,7 +6460,6 @@ internal_shutdown_callback (void *cls, const char *emsg) | |||
6480 | } | 6460 | } |
6481 | } | 6461 | } |
6482 | 6462 | ||
6483 | |||
6484 | /** | 6463 | /** |
6485 | * Task to rate limit the number of outstanding peer shutdown | 6464 | * Task to rate limit the number of outstanding peer shutdown |
6486 | * requests. This is necessary for making sure we don't do | 6465 | * requests. This is necessary for making sure we don't do |
@@ -6489,8 +6468,7 @@ internal_shutdown_callback (void *cls, const char *emsg) | |||
6489 | * to calling gnunet-arm N times all at once). | 6468 | * to calling gnunet-arm N times all at once). |
6490 | */ | 6469 | */ |
6491 | static void | 6470 | static void |
6492 | schedule_shutdown_task (void *cls, | 6471 | schedule_shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
6493 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
6494 | { | 6472 | { |
6495 | struct PeerShutdownContext *peer_shutdown_ctx = cls; | 6473 | struct PeerShutdownContext *peer_shutdown_ctx = cls; |
6496 | struct ShutdownContext *shutdown_ctx; | 6474 | struct ShutdownContext *shutdown_ctx; |
@@ -6500,8 +6478,10 @@ schedule_shutdown_task (void *cls, | |||
6500 | GNUNET_assert (shutdown_ctx != NULL); | 6478 | GNUNET_assert (shutdown_ctx != NULL); |
6501 | 6479 | ||
6502 | if (shutdown_ctx->outstanding > shutdown_ctx->pg->max_concurrent_ssh) | 6480 | if (shutdown_ctx->outstanding > shutdown_ctx->pg->max_concurrent_ssh) |
6503 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 6481 | GNUNET_SCHEDULER_add_delayed ( |
6504 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 6482 | GNUNET_TIME_relative_multiply ( |
6483 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
6484 | 100), | ||
6505 | &schedule_shutdown_task, peer_shutdown_ctx); | 6485 | &schedule_shutdown_task, peer_shutdown_ctx); |
6506 | else | 6486 | else |
6507 | { | 6487 | { |
@@ -6523,9 +6503,9 @@ schedule_shutdown_task (void *cls, | |||
6523 | * @param cb_cls closure for cb | 6503 | * @param cb_cls closure for cb |
6524 | */ | 6504 | */ |
6525 | void | 6505 | void |
6526 | GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, | 6506 | GNUNET_TESTING_daemons_stop(struct GNUNET_TESTING_PeerGroup *pg, |
6527 | struct GNUNET_TIME_Relative timeout, | 6507 | struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_NotifyCompletion cb, |
6528 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | 6508 | void *cb_cls) |
6529 | { | 6509 | { |
6530 | unsigned int off; | 6510 | unsigned int off; |
6531 | struct ShutdownContext *shutdown_ctx; | 6511 | struct ShutdownContext *shutdown_ctx; |
@@ -6589,16 +6569,15 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, | |||
6589 | } | 6569 | } |
6590 | #else | 6570 | #else |
6591 | if (pg->peers[off].allowed_peers != NULL) | 6571 | if (pg->peers[off].allowed_peers != NULL) |
6592 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers); | 6572 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers); |
6593 | if (pg->peers[off].connect_peers != NULL) | 6573 | if (pg->peers[off].connect_peers != NULL) |
6594 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers); | 6574 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers); |
6595 | if (pg->peers[off].blacklisted_peers != NULL) | 6575 | if (pg->peers[off].blacklisted_peers != NULL) |
6596 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 6576 | GNUNET_CONTAINER_multihashmap_destroy (pg-> |
6597 | peers[off].blacklisted_peers); | 6577 | peers[off].blacklisted_peers); |
6598 | #endif | 6578 | #endif |
6599 | } | 6579 | } |
6600 | 6580 | ||
6601 | } | 6581 | } |
6602 | 6582 | ||
6603 | |||
6604 | /* end of testing_group.c */ | 6583 | /* end of testing_group.c */ |