diff options
Diffstat (limited to 'src/testing/testing_group.c')
-rw-r--r-- | src/testing/testing_group.c | 5809 |
1 files changed, 2914 insertions, 2895 deletions
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 9bf24882c..723afd456 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -88,9 +88,11 @@ enum PeerLists | |||
88 | * in a certain topology. | 88 | * in a certain topology. |
89 | */ | 89 | */ |
90 | typedef unsigned int | 90 | typedef unsigned int |
91 | (*GNUNET_TESTING_ConnectionProcessor)(struct GNUNET_TESTING_PeerGroup * pg, | 91 | (*GNUNET_TESTING_ConnectionProcessor) (struct GNUNET_TESTING_PeerGroup * pg, |
92 | unsigned int first, unsigned int second, | 92 | unsigned int first, |
93 | enum PeerLists list, unsigned int check); | 93 | unsigned int second, |
94 | enum PeerLists list, | ||
95 | unsigned int check); | ||
94 | 96 | ||
95 | /** | 97 | /** |
96 | * Context for handling churning a peer group | 98 | * Context for handling churning a peer group |
@@ -1015,10 +1017,10 @@ struct ProgressMeter | |||
1015 | */ | 1017 | */ |
1016 | static void | 1018 | static void |
1017 | hash_from_uid (uint32_t uid, GNUNET_HashCode * hash) | 1019 | hash_from_uid (uint32_t uid, GNUNET_HashCode * hash) |
1018 | { | 1020 | { |
1019 | memset (hash, 0, sizeof (GNUNET_HashCode)); | 1021 | memset (hash, 0, sizeof (GNUNET_HashCode)); |
1020 | *((uint32_t *) hash) = uid; | 1022 | *((uint32_t *) hash) = uid; |
1021 | } | 1023 | } |
1022 | 1024 | ||
1023 | /** | 1025 | /** |
1024 | * Convert hash code to unique ID. | 1026 | * Convert hash code to unique ID. |
@@ -1028,15 +1030,15 @@ hash_from_uid (uint32_t uid, GNUNET_HashCode * hash) | |||
1028 | */ | 1030 | */ |
1029 | static void | 1031 | static void |
1030 | uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid) | 1032 | uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid) |
1031 | { | 1033 | { |
1032 | memcpy (uid, hash, sizeof (uint32_t)); | 1034 | memcpy (uid, hash, sizeof (uint32_t)); |
1033 | } | 1035 | } |
1034 | #endif | 1036 | #endif |
1035 | 1037 | ||
1036 | #if USE_SEND_HELLOS | 1038 | #if USE_SEND_HELLOS |
1037 | static struct GNUNET_CORE_MessageHandler no_handlers[] = | 1039 | static struct GNUNET_CORE_MessageHandler no_handlers[] = { |
1038 | { | 1040 | {NULL, 0, 0} |
1039 | { NULL, 0, 0}}; | 1041 | }; |
1040 | #endif | 1042 | #endif |
1041 | 1043 | ||
1042 | /** | 1044 | /** |
@@ -1050,20 +1052,21 @@ static struct GNUNET_CORE_MessageHandler no_handlers[] = | |||
1050 | * @return the progress meter | 1052 | * @return the progress meter |
1051 | */ | 1053 | */ |
1052 | static struct ProgressMeter * | 1054 | static struct ProgressMeter * |
1053 | create_meter(unsigned int total, char * start_string, int print) | 1055 | create_meter (unsigned int total, char *start_string, int print) |
1054 | { | 1056 | { |
1055 | struct ProgressMeter *ret; | 1057 | struct ProgressMeter *ret; |
1056 | ret = GNUNET_malloc(sizeof(struct ProgressMeter)); | 1058 | |
1059 | ret = GNUNET_malloc (sizeof (struct ProgressMeter)); | ||
1057 | ret->print = print; | 1060 | ret->print = print; |
1058 | ret->total = total; | 1061 | ret->total = total; |
1059 | ret->modnum = total / 4; | 1062 | ret->modnum = total / 4; |
1060 | if (ret->modnum == 0) /* Divide by zero check */ | 1063 | if (ret->modnum == 0) /* Divide by zero check */ |
1061 | ret->modnum = 1; | 1064 | ret->modnum = 1; |
1062 | ret->dotnum = (total / 50) + 1; | 1065 | ret->dotnum = (total / 50) + 1; |
1063 | if (start_string != NULL) | 1066 | if (start_string != NULL) |
1064 | ret->startup_string = GNUNET_strdup(start_string); | 1067 | ret->startup_string = GNUNET_strdup (start_string); |
1065 | else | 1068 | else |
1066 | ret->startup_string = GNUNET_strdup(""); | 1069 | ret->startup_string = GNUNET_strdup (""); |
1067 | 1070 | ||
1068 | return ret; | 1071 | return ret; |
1069 | } | 1072 | } |
@@ -1077,27 +1080,27 @@ create_meter(unsigned int total, char * start_string, int print) | |||
1077 | * GNUNET_NO if more items expected | 1080 | * GNUNET_NO if more items expected |
1078 | */ | 1081 | */ |
1079 | static int | 1082 | static int |
1080 | update_meter(struct ProgressMeter *meter) | 1083 | update_meter (struct ProgressMeter *meter) |
1081 | { | 1084 | { |
1082 | if (meter->print == GNUNET_YES) | 1085 | if (meter->print == GNUNET_YES) |
1086 | { | ||
1087 | if (meter->completed % meter->modnum == 0) | ||
1083 | { | 1088 | { |
1084 | if (meter->completed % meter->modnum == 0) | 1089 | if (meter->completed == 0) |
1085 | { | 1090 | { |
1086 | if (meter->completed == 0) | 1091 | fprintf (stdout, "%sProgress: [0%%", meter->startup_string); |
1087 | { | 1092 | } |
1088 | fprintf (stdout, "%sProgress: [0%%", meter->startup_string); | 1093 | else |
1089 | } | 1094 | fprintf (stdout, "%d%%", (int) (((float) meter->completed |
1090 | else | 1095 | / meter->total) * 100)); |
1091 | fprintf (stdout, "%d%%", (int) (((float) meter->completed | ||
1092 | / meter->total) * 100)); | ||
1093 | } | ||
1094 | else if (meter->completed % meter->dotnum == 0) | ||
1095 | fprintf (stdout, "."); | ||
1096 | |||
1097 | if (meter->completed + 1 == meter->total) | ||
1098 | fprintf (stdout, "%d%%]\n", 100); | ||
1099 | fflush (stdout); | ||
1100 | } | 1096 | } |
1097 | else if (meter->completed % meter->dotnum == 0) | ||
1098 | fprintf (stdout, "."); | ||
1099 | |||
1100 | if (meter->completed + 1 == meter->total) | ||
1101 | fprintf (stdout, "%d%%]\n", 100); | ||
1102 | fflush (stdout); | ||
1103 | } | ||
1101 | meter->completed++; | 1104 | meter->completed++; |
1102 | 1105 | ||
1103 | if (meter->completed == meter->total) | 1106 | if (meter->completed == meter->total) |
@@ -1116,7 +1119,7 @@ update_meter(struct ProgressMeter *meter) | |||
1116 | * GNUNET_SYSERR on error | 1119 | * GNUNET_SYSERR on error |
1117 | */ | 1120 | */ |
1118 | static int | 1121 | static int |
1119 | reset_meter(struct ProgressMeter *meter) | 1122 | reset_meter (struct ProgressMeter *meter) |
1120 | { | 1123 | { |
1121 | if (meter == NULL) | 1124 | if (meter == NULL) |
1122 | return GNUNET_SYSERR; | 1125 | return GNUNET_SYSERR; |
@@ -1131,7 +1134,7 @@ reset_meter(struct ProgressMeter *meter) | |||
1131 | * @param meter the meter to free | 1134 | * @param meter the meter to free |
1132 | */ | 1135 | */ |
1133 | static void | 1136 | static void |
1134 | free_meter(struct ProgressMeter *meter) | 1137 | free_meter (struct ProgressMeter *meter) |
1135 | { | 1138 | { |
1136 | GNUNET_free_non_null (meter->startup_string); | 1139 | GNUNET_free_non_null (meter->startup_string); |
1137 | GNUNET_free (meter); | 1140 | GNUNET_free (meter); |
@@ -1147,14 +1150,13 @@ free_meter(struct ProgressMeter *meter) | |||
1147 | * known topology, GNUNET_NO if not | 1150 | * known topology, GNUNET_NO if not |
1148 | */ | 1151 | */ |
1149 | int | 1152 | int |
1150 | GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, | 1153 | GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology, |
1151 | const char *topology_string) | 1154 | const char *topology_string) |
1152 | { | 1155 | { |
1153 | /** | 1156 | /** |
1154 | * Strings representing topologies in enum | 1157 | * Strings representing topologies in enum |
1155 | */ | 1158 | */ |
1156 | static const char *topology_strings[] = | 1159 | static const char *topology_strings[] = { |
1157 | { | ||
1158 | /** | 1160 | /** |
1159 | * A clique (everyone connected to everyone else). | 1161 | * A clique (everyone connected to everyone else). |
1160 | */ | 1162 | */ |
@@ -1211,20 +1213,22 @@ GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, | |||
1211 | */ | 1213 | */ |
1212 | "FROM_FILE", | 1214 | "FROM_FILE", |
1213 | 1215 | ||
1214 | NULL }; | 1216 | NULL |
1217 | }; | ||
1215 | 1218 | ||
1216 | int curr = 0; | 1219 | int curr = 0; |
1220 | |||
1217 | if (topology_string == NULL) | 1221 | if (topology_string == NULL) |
1218 | return GNUNET_NO; | 1222 | return GNUNET_NO; |
1219 | while (topology_strings[curr] != NULL) | 1223 | while (topology_strings[curr] != NULL) |
1224 | { | ||
1225 | if (strcasecmp (topology_strings[curr], topology_string) == 0) | ||
1220 | { | 1226 | { |
1221 | if (strcasecmp (topology_strings[curr], topology_string) == 0) | 1227 | *topology = curr; |
1222 | { | 1228 | return GNUNET_YES; |
1223 | *topology = curr; | ||
1224 | return GNUNET_YES; | ||
1225 | } | ||
1226 | curr++; | ||
1227 | } | 1229 | } |
1230 | curr++; | ||
1231 | } | ||
1228 | *topology = GNUNET_TESTING_TOPOLOGY_NONE; | 1232 | *topology = GNUNET_TESTING_TOPOLOGY_NONE; |
1229 | return GNUNET_NO; | 1233 | return GNUNET_NO; |
1230 | } | 1234 | } |
@@ -1239,15 +1243,14 @@ GNUNET_TESTING_topology_get(enum GNUNET_TESTING_Topology *topology, | |||
1239 | * topology option, GNUNET_NO if not | 1243 | * topology option, GNUNET_NO if not |
1240 | */ | 1244 | */ |
1241 | int | 1245 | int |
1242 | GNUNET_TESTING_topology_option_get( | 1246 | GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption |
1243 | enum GNUNET_TESTING_TopologyOption *topology_option, | 1247 | *topology_option, |
1244 | const char *topology_string) | 1248 | const char *topology_string) |
1245 | { | 1249 | { |
1246 | /** | 1250 | /** |
1247 | * Options for connecting a topology as strings. | 1251 | * Options for connecting a topology as strings. |
1248 | */ | 1252 | */ |
1249 | static const char *topology_option_strings[] = | 1253 | static const char *topology_option_strings[] = { |
1250 | { | ||
1251 | /** | 1254 | /** |
1252 | * Try to connect all peers specified in the topology. | 1255 | * Try to connect all peers specified in the topology. |
1253 | */ | 1256 | */ |
@@ -1283,20 +1286,21 @@ GNUNET_TESTING_topology_option_get( | |||
1283 | */ | 1286 | */ |
1284 | "CONNECT_NONE", | 1287 | "CONNECT_NONE", |
1285 | 1288 | ||
1286 | NULL }; | 1289 | NULL |
1290 | }; | ||
1287 | int curr = 0; | 1291 | int curr = 0; |
1288 | 1292 | ||
1289 | if (topology_string == NULL) | 1293 | if (topology_string == NULL) |
1290 | return GNUNET_NO; | 1294 | return GNUNET_NO; |
1291 | while (NULL != topology_option_strings[curr]) | 1295 | while (NULL != topology_option_strings[curr]) |
1296 | { | ||
1297 | if (strcasecmp (topology_option_strings[curr], topology_string) == 0) | ||
1292 | { | 1298 | { |
1293 | if (strcasecmp (topology_option_strings[curr], topology_string) == 0) | 1299 | *topology_option = curr; |
1294 | { | 1300 | return GNUNET_YES; |
1295 | *topology_option = curr; | ||
1296 | return GNUNET_YES; | ||
1297 | } | ||
1298 | curr++; | ||
1299 | } | 1301 | } |
1302 | curr++; | ||
1303 | } | ||
1300 | *topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_NONE; | 1304 | *topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_NONE; |
1301 | return GNUNET_NO; | 1305 | return GNUNET_NO; |
1302 | } | 1306 | } |
@@ -1312,8 +1316,8 @@ GNUNET_TESTING_topology_option_get( | |||
1312 | * @param value value of the option | 1316 | * @param value value of the option |
1313 | */ | 1317 | */ |
1314 | static void | 1318 | static void |
1315 | update_config(void *cls, const char *section, const char *option, | 1319 | update_config (void *cls, const char *section, const char *option, |
1316 | const char *value) | 1320 | const char *value) |
1317 | { | 1321 | { |
1318 | struct UpdateContext *ctx = cls; | 1322 | struct UpdateContext *ctx = cls; |
1319 | unsigned int ival; | 1323 | unsigned int ival; |
@@ -1327,58 +1331,61 @@ update_config(void *cls, const char *section, const char *option, | |||
1327 | GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); | 1331 | GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); |
1328 | 1332 | ||
1329 | if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) | 1333 | if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) |
1330 | { | 1334 | { |
1331 | if ((ival != 0) && (GNUNET_YES | 1335 | if ((ival != 0) && (GNUNET_YES |
1332 | != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", | 1336 | != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, |
1333 | single_variable))) | 1337 | "testing", |
1334 | { | 1338 | single_variable))) |
1335 | GNUNET_snprintf (cval, sizeof(cval), "%u", ctx->nport++); | 1339 | { |
1336 | value = cval; | 1340 | GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++); |
1337 | } | 1341 | value = cval; |
1338 | else if ((ival != 0) && (GNUNET_YES | 1342 | } |
1339 | == GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing", | 1343 | else if ((ival != 0) && (GNUNET_YES |
1340 | single_variable)) | 1344 | == GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, |
1341 | && GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", | 1345 | "testing", |
1342 | per_host_variable, | 1346 | single_variable)) |
1343 | &num_per_host)) | 1347 | && GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", |
1344 | { | 1348 | per_host_variable, |
1345 | GNUNET_snprintf (cval, sizeof(cval), "%u", ival + ctx->fdnum | 1349 | &num_per_host)) |
1346 | % num_per_host); | 1350 | { |
1347 | value = cval; | 1351 | GNUNET_snprintf (cval, sizeof (cval), "%u", ival + ctx->fdnum |
1348 | } | 1352 | % num_per_host); |
1349 | 1353 | value = cval; | |
1350 | /* FIXME: REMOVE FOREVER HACK HACK HACK */ | 1354 | } |
1351 | if (0 == strcasecmp (section, "transport-tcp")) | 1355 | |
1352 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, "ADVERTISED_PORT", value); | 1356 | /* FIXME: REMOVE FOREVER HACK HACK HACK */ |
1353 | } | 1357 | if (0 == strcasecmp (section, "transport-tcp")) |
1358 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, | ||
1359 | "ADVERTISED_PORT", value); | ||
1360 | } | ||
1354 | 1361 | ||
1355 | if (0 == strcmp (option, "UNIXPATH")) | 1362 | if (0 == strcmp (option, "UNIXPATH")) |
1363 | { | ||
1364 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, | ||
1365 | "testing", | ||
1366 | single_variable)) | ||
1356 | { | 1367 | { |
1357 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, | 1368 | GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u", |
1358 | "testing", | 1369 | section, ctx->upnum++); |
1359 | single_variable)) | 1370 | value = uval; |
1360 | { | ||
1361 | GNUNET_snprintf (uval, sizeof(uval), "/tmp/test-service-%s-%u", | ||
1362 | section, ctx->upnum++); | ||
1363 | value = uval; | ||
1364 | } | ||
1365 | else if ((GNUNET_YES | ||
1366 | == GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", | ||
1367 | per_host_variable, | ||
1368 | &num_per_host)) | ||
1369 | && (num_per_host > 0)) | ||
1370 | |||
1371 | { | ||
1372 | GNUNET_snprintf (uval, sizeof(uval), "/tmp/test-service-%s-%u", | ||
1373 | section, ctx->fdnum % num_per_host); | ||
1374 | value = uval; | ||
1375 | } | ||
1376 | } | 1371 | } |
1372 | else if ((GNUNET_YES | ||
1373 | == GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", | ||
1374 | per_host_variable, | ||
1375 | &num_per_host)) | ||
1376 | && (num_per_host > 0)) | ||
1377 | 1377 | ||
1378 | if ((0 == strcmp (option, "HOSTNAME")) && (ctx->hostname != NULL)) | ||
1379 | { | 1378 | { |
1380 | value = ctx->hostname; | 1379 | GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u", |
1380 | section, ctx->fdnum % num_per_host); | ||
1381 | value = uval; | ||
1381 | } | 1382 | } |
1383 | } | ||
1384 | |||
1385 | if ((0 == strcmp (option, "HOSTNAME")) && (ctx->hostname != NULL)) | ||
1386 | { | ||
1387 | value = ctx->hostname; | ||
1388 | } | ||
1382 | GNUNET_free (single_variable); | 1389 | GNUNET_free (single_variable); |
1383 | GNUNET_free (per_host_variable); | 1390 | GNUNET_free (per_host_variable); |
1384 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, option, value); | 1391 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, option, value); |
@@ -1402,9 +1409,9 @@ update_config(void *cls, const char *section, const char *option, | |||
1402 | * @return new configuration, NULL on error | 1409 | * @return new configuration, NULL on error |
1403 | */ | 1410 | */ |
1404 | static struct GNUNET_CONFIGURATION_Handle * | 1411 | static struct GNUNET_CONFIGURATION_Handle * |
1405 | make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, | 1412 | make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, |
1406 | uint16_t * port, uint32_t * upnum, const char *hostname, | 1413 | uint16_t * port, uint32_t * upnum, const char *hostname, |
1407 | uint32_t * fdnum) | 1414 | uint32_t * fdnum) |
1408 | { | 1415 | { |
1409 | struct UpdateContext uc; | 1416 | struct UpdateContext uc; |
1410 | uint16_t orig; | 1417 | uint16_t orig; |
@@ -1424,98 +1431,101 @@ make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, | |||
1424 | 1431 | ||
1425 | GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); | 1432 | GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); |
1426 | if (uc.nport >= HIGH_PORT) | 1433 | if (uc.nport >= HIGH_PORT) |
1427 | { | 1434 | { |
1428 | *port = orig; | 1435 | *port = orig; |
1429 | GNUNET_CONFIGURATION_destroy (uc.ret); | 1436 | GNUNET_CONFIGURATION_destroy (uc.ret); |
1430 | return NULL; | 1437 | return NULL; |
1431 | } | 1438 | } |
1432 | 1439 | ||
1433 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", | 1440 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", |
1434 | "skew_variance", | 1441 | "skew_variance", |
1435 | &skew_variance)) | 1442 | &skew_variance)) |
1436 | && (skew_variance > 0)) | 1443 | && (skew_variance > 0)) |
1437 | { | 1444 | { |
1438 | skew_offset = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, skew_variance + 1); | 1445 | skew_offset = |
1439 | actual_offset = skew_offset - GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, skew_variance + 1); | 1446 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1440 | /* Min is -skew_variance, Max is skew_variance */ | 1447 | skew_variance + 1); |
1441 | skew_offset = skew_variance + actual_offset; /* Normal distribution around 0 */ | 1448 | actual_offset = |
1442 | GNUNET_CONFIGURATION_set_value_number(uc.ret, "testing", "skew_offset", skew_offset); | 1449 | skew_offset - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1443 | } | 1450 | skew_variance + 1); |
1451 | /* Min is -skew_variance, Max is skew_variance */ | ||
1452 | skew_offset = skew_variance + actual_offset; /* Normal distribution around 0 */ | ||
1453 | GNUNET_CONFIGURATION_set_value_number (uc.ret, "testing", "skew_offset", | ||
1454 | skew_offset); | ||
1455 | } | ||
1444 | 1456 | ||
1445 | if (GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "control_host", | 1457 | if (GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "control_host", |
1446 | &control_host) == GNUNET_OK) | 1458 | &control_host) == GNUNET_OK) |
1447 | { | 1459 | { |
1448 | if (hostname != NULL) | 1460 | if (hostname != NULL) |
1449 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host, | 1461 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host, |
1450 | hostname); | 1462 | hostname); |
1451 | else | 1463 | else |
1452 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", control_host); | 1464 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", control_host); |
1453 | 1465 | ||
1454 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "ACCEPT_FROM", | 1466 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "ACCEPT_FROM", |
1455 | allowed_hosts); | 1467 | allowed_hosts); |
1456 | 1468 | ||
1457 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "ACCEPT_FROM", | 1469 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "ACCEPT_FROM", |
1458 | allowed_hosts); | 1470 | allowed_hosts); |
1459 | 1471 | ||
1460 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", | 1472 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", |
1461 | "ACCEPT_FROM", allowed_hosts); | 1473 | "ACCEPT_FROM", allowed_hosts); |
1462 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM", | 1474 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM", |
1463 | allowed_hosts); | 1475 | allowed_hosts); |
1464 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", | 1476 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", |
1465 | "ACCEPT_FROM", allowed_hosts); | 1477 | "ACCEPT_FROM", allowed_hosts); |
1466 | 1478 | ||
1467 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", ""); | 1479 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", ""); |
1468 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH", | 1480 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH", ""); |
1469 | ""); | 1481 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "UNIXPATH", ""); |
1470 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "UNIXPATH", ""); | 1482 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "UNIXPATH", |
1471 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "UNIXPATH", | 1483 | ""); |
1472 | ""); | 1484 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "UNIXPATH", ""); |
1473 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "UNIXPATH", ""); | 1485 | |
1474 | 1486 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", | |
1475 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "USE_LOCALADDR", | 1487 | "USE_LOCALADDR", "YES"); |
1476 | "YES"); | 1488 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", |
1477 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "USE_LOCALADDR", | 1489 | "USE_LOCALADDR", "YES"); |
1478 | "YES"); | 1490 | GNUNET_free_non_null (control_host); |
1479 | GNUNET_free_non_null (control_host); | 1491 | GNUNET_free (allowed_hosts); |
1480 | GNUNET_free (allowed_hosts); | 1492 | } |
1481 | } | ||
1482 | 1493 | ||
1483 | /* arm needs to know to allow connections from the host on which it is running, | 1494 | /* arm needs to know to allow connections from the host on which it is running, |
1484 | * otherwise gnunet-arm is unable to connect to it in some instances */ | 1495 | * otherwise gnunet-arm is unable to connect to it in some instances */ |
1485 | if (hostname != NULL) | 1496 | if (hostname != NULL) |
1486 | { | 1497 | { |
1487 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", hostname); | 1498 | GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1;", hostname); |
1488 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO", | 1499 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO", hostname); |
1489 | hostname); | 1500 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS", |
1490 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS", | 1501 | hostname); |
1491 | hostname); | 1502 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS", |
1492 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS", | 1503 | hostname); |
1493 | hostname); | 1504 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO", |
1494 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO", | 1505 | "YES"); |
1495 | "YES"); | 1506 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", |
1496 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "USE_LOCALADDR", | 1507 | "USE_LOCALADDR", "YES"); |
1497 | "YES"); | 1508 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", |
1498 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "USE_LOCALADDR", | 1509 | "USE_LOCALADDR", "YES"); |
1499 | "YES"); | 1510 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "arm", "ACCEPT_FROM", |
1500 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "arm", "ACCEPT_FROM", | 1511 | allowed_hosts); |
1501 | allowed_hosts); | 1512 | GNUNET_free (allowed_hosts); |
1502 | GNUNET_free (allowed_hosts); | 1513 | } |
1503 | } | ||
1504 | else | 1514 | else |
1505 | { | 1515 | { |
1506 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "USE_LOCALADDR", | 1516 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", |
1507 | "YES"); | 1517 | "USE_LOCALADDR", "YES"); |
1508 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", "USE_LOCALADDR", | 1518 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", |
1509 | "YES"); | 1519 | "USE_LOCALADDR", "YES"); |
1510 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO", | 1520 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "BINDTO", |
1511 | "127.0.0.1"); | 1521 | "127.0.0.1"); |
1512 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS", | 1522 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "INTERNAL_ADDRESS", |
1513 | "127.0.0.1"); | 1523 | "127.0.0.1"); |
1514 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS", | 1524 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS", |
1515 | "127.0.0.1"); | 1525 | "127.0.0.1"); |
1516 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO", | 1526 | GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO", |
1517 | "YES"); | 1527 | "YES"); |
1518 | } | 1528 | } |
1519 | 1529 | ||
1520 | *port = (uint16_t) uc.nport; | 1530 | *port = (uint16_t) uc.nport; |
1521 | *upnum = uc.upnum; | 1531 | *upnum = uc.upnum; |
@@ -1537,10 +1547,12 @@ make_config(const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, | |||
1537 | * | 1547 | * |
1538 | */ | 1548 | */ |
1539 | static unsigned int | 1549 | static unsigned int |
1540 | remove_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | 1550 | remove_connections (struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, |
1541 | unsigned int second, enum PeerLists list, unsigned int check) | 1551 | unsigned int second, enum PeerLists list, |
1552 | unsigned int check) | ||
1542 | { | 1553 | { |
1543 | int removed; | 1554 | int removed; |
1555 | |||
1544 | #if OLD | 1556 | #if OLD |
1545 | struct PeerConnection **first_list; | 1557 | struct PeerConnection **first_list; |
1546 | struct PeerConnection **second_list; | 1558 | struct PeerConnection **second_list; |
@@ -1560,7 +1572,7 @@ remove_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1560 | removed = 0; | 1572 | removed = 0; |
1561 | #if OLD | 1573 | #if OLD |
1562 | switch (list) | 1574 | switch (list) |
1563 | { | 1575 | { |
1564 | case ALLOWED: | 1576 | case ALLOWED: |
1565 | first_list = &pg->peers[first].allowed_peers_head; | 1577 | first_list = &pg->peers[first].allowed_peers_head; |
1566 | second_list = &pg->peers[second].allowed_peers_head; | 1578 | second_list = &pg->peers[second].allowed_peers_head; |
@@ -1586,51 +1598,55 @@ remove_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1586 | second_tail = &pg->peers[second].connect_peers_working_set_tail; | 1598 | second_tail = &pg->peers[second].connect_peers_working_set_tail; |
1587 | break; | 1599 | break; |
1588 | default: | 1600 | default: |
1589 | GNUNET_break(0); | 1601 | GNUNET_break (0); |
1590 | return 0; | 1602 | return 0; |
1591 | } | 1603 | } |
1592 | 1604 | ||
1593 | first_iter = *first_list; | 1605 | first_iter = *first_list; |
1594 | while (first_iter != NULL) | 1606 | while (first_iter != NULL) |
1607 | { | ||
1608 | if (first_iter->index == second) | ||
1595 | { | 1609 | { |
1596 | if (first_iter->index == second) | 1610 | GNUNET_CONTAINER_DLL_remove (*first_list, *first_tail, first_iter); |
1597 | { | 1611 | GNUNET_free (first_iter); |
1598 | GNUNET_CONTAINER_DLL_remove(*first_list, *first_tail, first_iter); | 1612 | removed++; |
1599 | GNUNET_free(first_iter); | 1613 | break; |
1600 | removed++; | ||
1601 | break; | ||
1602 | } | ||
1603 | first_iter = first_iter->next; | ||
1604 | } | 1614 | } |
1615 | first_iter = first_iter->next; | ||
1616 | } | ||
1605 | 1617 | ||
1606 | second_iter = *second_list; | 1618 | second_iter = *second_list; |
1607 | while (second_iter != NULL) | 1619 | while (second_iter != NULL) |
1620 | { | ||
1621 | if (second_iter->index == first) | ||
1608 | { | 1622 | { |
1609 | if (second_iter->index == first) | 1623 | GNUNET_CONTAINER_DLL_remove (*second_list, *second_tail, second_iter); |
1610 | { | 1624 | GNUNET_free (second_iter); |
1611 | GNUNET_CONTAINER_DLL_remove(*second_list, *second_tail, second_iter); | 1625 | removed++; |
1612 | GNUNET_free(second_iter); | 1626 | break; |
1613 | removed++; | ||
1614 | break; | ||
1615 | } | ||
1616 | second_iter = second_iter->next; | ||
1617 | } | 1627 | } |
1628 | second_iter = second_iter->next; | ||
1629 | } | ||
1618 | #else | 1630 | #else |
1619 | if (GNUNET_YES == | 1631 | if (GNUNET_YES == |
1620 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].blacklisted_peers, | 1632 | GNUNET_CONTAINER_multihashmap_contains (pg-> |
1621 | &hash_second)) | 1633 | peers[first].blacklisted_peers, |
1622 | { | 1634 | &hash_second)) |
1623 | GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[first].blacklisted_peers, | 1635 | { |
1624 | &hash_second); | 1636 | GNUNET_CONTAINER_multihashmap_remove_all (pg-> |
1625 | } | 1637 | peers[first].blacklisted_peers, |
1638 | &hash_second); | ||
1639 | } | ||
1626 | 1640 | ||
1627 | if (GNUNET_YES == | 1641 | if (GNUNET_YES == |
1628 | GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].blacklisted_peers, | 1642 | GNUNET_CONTAINER_multihashmap_contains (pg-> |
1629 | &hash_first)) | 1643 | peers[second].blacklisted_peers, |
1630 | { | 1644 | &hash_first)) |
1631 | GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[second].blacklisted_peers, | 1645 | { |
1632 | &hash_first); | 1646 | GNUNET_CONTAINER_multihashmap_remove_all (pg-> |
1633 | } | 1647 | peers[second].blacklisted_peers, |
1648 | &hash_first); | ||
1649 | } | ||
1634 | #endif | 1650 | #endif |
1635 | 1651 | ||
1636 | return removed; | 1652 | return removed; |
@@ -1650,8 +1666,8 @@ remove_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1650 | * | 1666 | * |
1651 | */ | 1667 | */ |
1652 | static unsigned int | 1668 | static unsigned int |
1653 | add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | 1669 | add_connections (struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, |
1654 | unsigned int second, enum PeerLists list, unsigned int check) | 1670 | unsigned int second, enum PeerLists list, unsigned int check) |
1655 | { | 1671 | { |
1656 | int added; | 1672 | int added; |
1657 | int add_first; | 1673 | int add_first; |
@@ -1667,7 +1683,7 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1667 | struct PeerConnection **second_tail; | 1683 | struct PeerConnection **second_tail; |
1668 | 1684 | ||
1669 | switch (list) | 1685 | switch (list) |
1670 | { | 1686 | { |
1671 | case ALLOWED: | 1687 | case ALLOWED: |
1672 | first_list = &pg->peers[first].allowed_peers_head; | 1688 | first_list = &pg->peers[first].allowed_peers_head; |
1673 | second_list = &pg->peers[second].allowed_peers_head; | 1689 | second_list = &pg->peers[second].allowed_peers_head; |
@@ -1693,56 +1709,56 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1693 | second_tail = &pg->peers[second].connect_peers_working_set_tail; | 1709 | second_tail = &pg->peers[second].connect_peers_working_set_tail; |
1694 | break; | 1710 | break; |
1695 | default: | 1711 | default: |
1696 | GNUNET_break(0); | 1712 | GNUNET_break (0); |
1697 | return 0; | 1713 | return 0; |
1698 | } | 1714 | } |
1699 | 1715 | ||
1700 | add_first = GNUNET_YES; | 1716 | add_first = GNUNET_YES; |
1701 | add_second = GNUNET_YES; | 1717 | add_second = GNUNET_YES; |
1702 | 1718 | ||
1703 | if (check == GNUNET_YES) | 1719 | if (check == GNUNET_YES) |
1720 | { | ||
1721 | first_iter = *first_list; | ||
1722 | while (first_iter != NULL) | ||
1704 | { | 1723 | { |
1705 | first_iter = *first_list; | 1724 | if (first_iter->index == second) |
1706 | while (first_iter != NULL) | 1725 | { |
1707 | { | 1726 | add_first = GNUNET_NO; |
1708 | if (first_iter->index == second) | 1727 | break; |
1709 | { | 1728 | } |
1710 | add_first = GNUNET_NO; | 1729 | first_iter = first_iter->next; |
1711 | break; | 1730 | } |
1712 | } | ||
1713 | first_iter = first_iter->next; | ||
1714 | } | ||
1715 | 1731 | ||
1716 | second_iter = *second_list; | 1732 | second_iter = *second_list; |
1717 | while (second_iter != NULL) | 1733 | while (second_iter != NULL) |
1718 | { | 1734 | { |
1719 | if (second_iter->index == first) | 1735 | if (second_iter->index == first) |
1720 | { | 1736 | { |
1721 | add_second = GNUNET_NO; | 1737 | add_second = GNUNET_NO; |
1722 | break; | 1738 | break; |
1723 | } | 1739 | } |
1724 | second_iter = second_iter->next; | 1740 | second_iter = second_iter->next; |
1725 | } | ||
1726 | } | 1741 | } |
1742 | } | ||
1727 | 1743 | ||
1728 | added = 0; | 1744 | added = 0; |
1729 | if (add_first) | 1745 | if (add_first) |
1730 | { | 1746 | { |
1731 | new_first = GNUNET_malloc (sizeof (struct PeerConnection)); | 1747 | new_first = GNUNET_malloc (sizeof (struct PeerConnection)); |
1732 | new_first->index = second; | 1748 | new_first->index = second; |
1733 | GNUNET_CONTAINER_DLL_insert(*first_list, *first_tail, new_first); | 1749 | GNUNET_CONTAINER_DLL_insert (*first_list, *first_tail, new_first); |
1734 | pg->peers[first].num_connections++; | 1750 | pg->peers[first].num_connections++; |
1735 | added++; | 1751 | added++; |
1736 | } | 1752 | } |
1737 | 1753 | ||
1738 | if (add_second) | 1754 | if (add_second) |
1739 | { | 1755 | { |
1740 | new_second = GNUNET_malloc (sizeof (struct PeerConnection)); | 1756 | new_second = GNUNET_malloc (sizeof (struct PeerConnection)); |
1741 | new_second->index = first; | 1757 | new_second->index = first; |
1742 | GNUNET_CONTAINER_DLL_insert(*second_list, *second_tail, new_second); | 1758 | GNUNET_CONTAINER_DLL_insert (*second_list, *second_tail, new_second); |
1743 | pg->peers[second].num_connections++; | 1759 | pg->peers[second].num_connections++; |
1744 | added++; | 1760 | added++; |
1745 | } | 1761 | } |
1746 | 1762 | ||
1747 | return added; | 1763 | return added; |
1748 | } | 1764 | } |
@@ -1764,8 +1780,8 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, | |||
1764 | * @return the number of connections created | 1780 | * @return the number of connections created |
1765 | */ | 1781 | */ |
1766 | static unsigned int | 1782 | static unsigned int |
1767 | create_scale_free(struct GNUNET_TESTING_PeerGroup *pg, | 1783 | create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, |
1768 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 1784 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
1769 | { | 1785 | { |
1770 | 1786 | ||
1771 | unsigned int total_connections; | 1787 | unsigned int total_connections; |
@@ -1781,31 +1797,31 @@ create_scale_free(struct GNUNET_TESTING_PeerGroup *pg, | |||
1781 | total_connections = proc (pg, 0, 1, list, GNUNET_YES); | 1797 | total_connections = proc (pg, 0, 1, list, GNUNET_YES); |
1782 | 1798 | ||
1783 | for (outer_count = 1; outer_count < pg->total; outer_count++) | 1799 | for (outer_count = 1; outer_count < pg->total; outer_count++) |
1784 | { | 1800 | { |
1785 | previous_total_connections = total_connections; | 1801 | previous_total_connections = total_connections; |
1786 | for (i = 0; i < outer_count; i++) | 1802 | for (i = 0; i < outer_count; i++) |
1787 | { | 1803 | { |
1788 | probability = pg->peers[i].num_connections | 1804 | probability = pg->peers[i].num_connections |
1789 | / (double) previous_total_connections; | 1805 | / (double) previous_total_connections; |
1790 | random | 1806 | random |
1791 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1807 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1792 | UINT64_MAX)) | 1808 | UINT64_MAX)) |
1793 | / ((double) UINT64_MAX); | 1809 | / ((double) UINT64_MAX); |
1794 | #if VERBOSE_TESTING | 1810 | #if VERBOSE_TESTING |
1795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1811 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1796 | "Considering connecting peer %d to peer %d\n", | 1812 | "Considering connecting peer %d to peer %d\n", |
1797 | outer_count, i); | 1813 | outer_count, i); |
1798 | #endif | 1814 | #endif |
1799 | if (random < probability) | 1815 | if (random < probability) |
1800 | { | 1816 | { |
1801 | #if VERBOSE_TESTING | 1817 | #if VERBOSE_TESTING |
1802 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1818 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1803 | "Connecting peer %d to peer %d\n", outer_count, i); | 1819 | "Connecting peer %d to peer %d\n", outer_count, i); |
1804 | #endif | 1820 | #endif |
1805 | total_connections += proc (pg, outer_count, i, list, GNUNET_YES); | 1821 | total_connections += proc (pg, outer_count, i, list, GNUNET_YES); |
1806 | } | 1822 | } |
1807 | } | ||
1808 | } | 1823 | } |
1824 | } | ||
1809 | 1825 | ||
1810 | return total_connections; | 1826 | return total_connections; |
1811 | } | 1827 | } |
@@ -1838,9 +1854,9 @@ create_scale_free(struct GNUNET_TESTING_PeerGroup *pg, | |||
1838 | * | 1854 | * |
1839 | */ | 1855 | */ |
1840 | static unsigned int | 1856 | static unsigned int |
1841 | create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, | 1857 | create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg, |
1842 | GNUNET_TESTING_ConnectionProcessor proc, | 1858 | GNUNET_TESTING_ConnectionProcessor proc, |
1843 | enum PeerLists list) | 1859 | enum PeerLists list) |
1844 | { | 1860 | { |
1845 | unsigned int i, j; | 1861 | unsigned int i, j; |
1846 | int nodeToConnect; | 1862 | int nodeToConnect; |
@@ -1855,32 +1871,30 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, | |||
1855 | unsigned int useAnd; | 1871 | unsigned int useAnd; |
1856 | int connect_attempts; | 1872 | int connect_attempts; |
1857 | 1873 | ||
1858 | logNModifier = 0.5; /* FIXME: default value? */ | 1874 | logNModifier = 0.5; /* FIXME: default value? */ |
1859 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 1875 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
1860 | "PERCENTAGE", | 1876 | "PERCENTAGE", |
1861 | &p_string)) | 1877 | &p_string)) |
1862 | { | 1878 | { |
1863 | if (sscanf (p_string, "%lf", &logNModifier) != 1) | 1879 | if (sscanf (p_string, "%lf", &logNModifier) != 1) |
1864 | GNUNET_log ( | 1880 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1865 | GNUNET_ERROR_TYPE_WARNING, | 1881 | _ |
1866 | _ | 1882 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1867 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1883 | p_string, "LOGNMODIFIER", "TESTING"); |
1868 | p_string, "LOGNMODIFIER", "TESTING"); | 1884 | GNUNET_free (p_string); |
1869 | GNUNET_free (p_string); | 1885 | } |
1870 | } | 1886 | probability = 0.5; /* FIXME: default percentage? */ |
1871 | probability = 0.5; /* FIXME: default percentage? */ | ||
1872 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 1887 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
1873 | "PROBABILITY", | 1888 | "PROBABILITY", |
1874 | &p_string)) | 1889 | &p_string)) |
1875 | { | 1890 | { |
1876 | if (sscanf (p_string, "%lf", &probability) != 1) | 1891 | if (sscanf (p_string, "%lf", &probability) != 1) |
1877 | GNUNET_log ( | 1892 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1878 | GNUNET_ERROR_TYPE_WARNING, | 1893 | _ |
1879 | _ | 1894 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1880 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1895 | p_string, "PERCENTAGE", "TESTING"); |
1881 | p_string, "PERCENTAGE", "TESTING"); | 1896 | GNUNET_free (p_string); |
1882 | GNUNET_free (p_string); | 1897 | } |
1883 | } | ||
1884 | natLog = log (pg->total); | 1898 | natLog = log (pg->total); |
1885 | connsPerPeer = ceil (natLog * logNModifier); | 1899 | connsPerPeer = ceil (natLog * logNModifier); |
1886 | 1900 | ||
@@ -1893,59 +1907,57 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, | |||
1893 | smallWorldConnections = 0; | 1907 | smallWorldConnections = 0; |
1894 | connect_attempts = 0; | 1908 | connect_attempts = 0; |
1895 | for (i = 0; i < pg->total; i++) | 1909 | for (i = 0; i < pg->total; i++) |
1910 | { | ||
1911 | useAnd = 0; | ||
1912 | max = i + connsPerPeer / 2; | ||
1913 | min = i - connsPerPeer / 2; | ||
1914 | |||
1915 | if (max > pg->total - 1) | ||
1896 | { | 1916 | { |
1897 | useAnd = 0; | 1917 | max = max - pg->total; |
1898 | max = i + connsPerPeer / 2; | 1918 | useAnd = 1; |
1899 | min = i - connsPerPeer / 2; | 1919 | } |
1900 | 1920 | ||
1901 | if (max > pg->total - 1) | 1921 | if (min < 0) |
1902 | { | 1922 | { |
1903 | max = max - pg->total; | 1923 | min = pg->total - 1 + min; |
1904 | useAnd = 1; | 1924 | useAnd = 1; |
1905 | } | 1925 | } |
1906 | 1926 | ||
1907 | if (min < 0) | 1927 | for (j = 0; j < connsPerPeer / 2; j++) |
1928 | { | ||
1929 | random | ||
1930 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1931 | UINT64_MAX) | ||
1932 | / ((double) UINT64_MAX)); | ||
1933 | if (random < probability) | ||
1934 | { | ||
1935 | /* Connect to uniformly selected random peer */ | ||
1936 | randomPeer | ||
1937 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total); | ||
1938 | while ((((randomPeer < max) && (randomPeer > min)) && (useAnd | ||
1939 | == 0)) || | ||
1940 | (((randomPeer > min) || (randomPeer < max)) && (useAnd == 1))) | ||
1908 | { | 1941 | { |
1909 | min = pg->total - 1 + min; | 1942 | randomPeer |
1910 | useAnd = 1; | 1943 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1944 | pg->total); | ||
1911 | } | 1945 | } |
1912 | 1946 | smallWorldConnections += proc (pg, i, randomPeer, list, GNUNET_YES); | |
1913 | for (j = 0; j < connsPerPeer / 2; j++) | 1947 | } |
1948 | else | ||
1949 | { | ||
1950 | nodeToConnect = i + j + 1; | ||
1951 | if (nodeToConnect > pg->total - 1) | ||
1914 | { | 1952 | { |
1915 | random | 1953 | nodeToConnect = nodeToConnect - pg->total; |
1916 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1917 | UINT64_MAX) | ||
1918 | / ((double) UINT64_MAX)); | ||
1919 | if (random < probability) | ||
1920 | { | ||
1921 | /* Connect to uniformly selected random peer */ | ||
1922 | randomPeer | ||
1923 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1924 | pg->total); | ||
1925 | while ((((randomPeer < max) && (randomPeer > min)) && (useAnd | ||
1926 | == 0)) || (((randomPeer > min) || (randomPeer < max)) | ||
1927 | && (useAnd == 1))) | ||
1928 | { | ||
1929 | randomPeer | ||
1930 | = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1931 | pg->total); | ||
1932 | } | ||
1933 | smallWorldConnections += proc (pg, i, randomPeer, list, | ||
1934 | GNUNET_YES); | ||
1935 | } | ||
1936 | else | ||
1937 | { | ||
1938 | nodeToConnect = i + j + 1; | ||
1939 | if (nodeToConnect > pg->total - 1) | ||
1940 | { | ||
1941 | nodeToConnect = nodeToConnect - pg->total; | ||
1942 | } | ||
1943 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | ||
1944 | } | ||
1945 | } | 1954 | } |
1946 | 1955 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | |
1956 | } | ||
1947 | } | 1957 | } |
1948 | 1958 | ||
1959 | } | ||
1960 | |||
1949 | connect_attempts += smallWorldConnections; | 1961 | connect_attempts += smallWorldConnections; |
1950 | 1962 | ||
1951 | return connect_attempts; | 1963 | return connect_attempts; |
@@ -1964,9 +1976,9 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, | |||
1964 | * | 1976 | * |
1965 | */ | 1977 | */ |
1966 | static unsigned int | 1978 | static unsigned int |
1967 | create_nated_internet(struct GNUNET_TESTING_PeerGroup *pg, | 1979 | create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, |
1968 | GNUNET_TESTING_ConnectionProcessor proc, | 1980 | GNUNET_TESTING_ConnectionProcessor proc, |
1969 | enum PeerLists list) | 1981 | enum PeerLists list) |
1970 | { | 1982 | { |
1971 | unsigned int outer_count, inner_count; | 1983 | unsigned int outer_count, inner_count; |
1972 | unsigned int cutoff; | 1984 | unsigned int cutoff; |
@@ -1974,38 +1986,37 @@ create_nated_internet(struct GNUNET_TESTING_PeerGroup *pg, | |||
1974 | double nat_percentage; | 1986 | double nat_percentage; |
1975 | char *p_string; | 1987 | char *p_string; |
1976 | 1988 | ||
1977 | nat_percentage = 0.6; /* FIXME: default percentage? */ | 1989 | nat_percentage = 0.6; /* FIXME: default percentage? */ |
1978 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 1990 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
1979 | "PERCENTAGE", | 1991 | "PERCENTAGE", |
1980 | &p_string)) | 1992 | &p_string)) |
1981 | { | 1993 | { |
1982 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) | 1994 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) |
1983 | GNUNET_log ( | 1995 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1984 | GNUNET_ERROR_TYPE_WARNING, | 1996 | _ |
1985 | _ | 1997 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
1986 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 1998 | p_string, "PERCENTAGE", "TESTING"); |
1987 | p_string, "PERCENTAGE", "TESTING"); | 1999 | GNUNET_free (p_string); |
1988 | GNUNET_free (p_string); | 2000 | } |
1989 | } | ||
1990 | 2001 | ||
1991 | cutoff = (unsigned int) (nat_percentage * pg->total); | 2002 | cutoff = (unsigned int) (nat_percentage * pg->total); |
1992 | connect_attempts = 0; | 2003 | connect_attempts = 0; |
1993 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2004 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2005 | { | ||
2006 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
1994 | { | 2007 | { |
1995 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | 2008 | if ((outer_count > cutoff) || (inner_count > cutoff)) |
1996 | { | 2009 | { |
1997 | if ((outer_count > cutoff) || (inner_count > cutoff)) | ||
1998 | { | ||
1999 | #if VERBOSE_TESTING | 2010 | #if VERBOSE_TESTING |
2000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2011 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2001 | "Connecting peer %d to peer %d\n", | 2012 | "Connecting peer %d to peer %d\n", |
2002 | outer_count, inner_count); | 2013 | outer_count, inner_count); |
2003 | #endif | 2014 | #endif |
2004 | connect_attempts += proc (pg, outer_count, inner_count, list, | 2015 | connect_attempts += proc (pg, outer_count, inner_count, list, |
2005 | GNUNET_YES); | 2016 | GNUNET_YES); |
2006 | } | 2017 | } |
2007 | } | ||
2008 | } | 2018 | } |
2019 | } | ||
2009 | return connect_attempts; | 2020 | return connect_attempts; |
2010 | } | 2021 | } |
2011 | 2022 | ||
@@ -2023,9 +2034,9 @@ create_nated_internet(struct GNUNET_TESTING_PeerGroup *pg, | |||
2023 | * | 2034 | * |
2024 | */ | 2035 | */ |
2025 | static unsigned int | 2036 | static unsigned int |
2026 | create_nated_internet_copy(struct GNUNET_TESTING_PeerGroup *pg, | 2037 | create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg, |
2027 | GNUNET_TESTING_ConnectionProcessor proc, | 2038 | GNUNET_TESTING_ConnectionProcessor proc, |
2028 | enum PeerLists list) | 2039 | enum PeerLists list) |
2029 | { | 2040 | { |
2030 | unsigned int outer_count, inner_count; | 2041 | unsigned int outer_count, inner_count; |
2031 | unsigned int cutoff; | 2042 | unsigned int cutoff; |
@@ -2035,52 +2046,51 @@ create_nated_internet_copy(struct GNUNET_TESTING_PeerGroup *pg, | |||
2035 | unsigned int count; | 2046 | unsigned int count; |
2036 | struct ProgressMeter *conn_meter; | 2047 | struct ProgressMeter *conn_meter; |
2037 | 2048 | ||
2038 | nat_percentage = 0.6; /* FIXME: default percentage? */ | 2049 | nat_percentage = 0.6; /* FIXME: default percentage? */ |
2039 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 2050 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2040 | "PERCENTAGE", | 2051 | "PERCENTAGE", |
2041 | &p_string)) | 2052 | &p_string)) |
2042 | { | 2053 | { |
2043 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) | 2054 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) |
2044 | GNUNET_log ( | 2055 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2045 | GNUNET_ERROR_TYPE_WARNING, | 2056 | _ |
2046 | _ | 2057 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2047 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 2058 | p_string, "PERCENTAGE", "TESTING"); |
2048 | p_string, "PERCENTAGE", "TESTING"); | 2059 | GNUNET_free (p_string); |
2049 | GNUNET_free (p_string); | 2060 | } |
2050 | } | ||
2051 | 2061 | ||
2052 | cutoff = (unsigned int) (nat_percentage * pg->total); | 2062 | cutoff = (unsigned int) (nat_percentage * pg->total); |
2053 | count = 0; | 2063 | count = 0; |
2054 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2064 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2065 | { | ||
2066 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
2055 | { | 2067 | { |
2056 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | 2068 | if ((outer_count > cutoff) || (inner_count > cutoff)) |
2057 | { | 2069 | { |
2058 | if ((outer_count > cutoff) || (inner_count > cutoff)) | 2070 | count++; |
2059 | { | 2071 | } |
2060 | count++; | ||
2061 | } | ||
2062 | } | ||
2063 | } | 2072 | } |
2073 | } | ||
2064 | conn_meter = create_meter (count, "NAT COPY", GNUNET_YES); | 2074 | conn_meter = create_meter (count, "NAT COPY", GNUNET_YES); |
2065 | connect_attempts = 0; | 2075 | connect_attempts = 0; |
2066 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2076 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2077 | { | ||
2078 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
2067 | { | 2079 | { |
2068 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | 2080 | if ((outer_count > cutoff) || (inner_count > cutoff)) |
2069 | { | 2081 | { |
2070 | if ((outer_count > cutoff) || (inner_count > cutoff)) | ||
2071 | { | ||
2072 | #if VERBOSE_TESTING | 2082 | #if VERBOSE_TESTING |
2073 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2083 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2074 | "Connecting peer %d to peer %d\n", | 2084 | "Connecting peer %d to peer %d\n", |
2075 | outer_count, inner_count); | 2085 | outer_count, inner_count); |
2076 | #endif | 2086 | #endif |
2077 | connect_attempts += proc (pg, outer_count, inner_count, list, | 2087 | connect_attempts += proc (pg, outer_count, inner_count, list, |
2078 | GNUNET_YES); | 2088 | GNUNET_YES); |
2079 | add_connections (pg, outer_count, inner_count, ALLOWED, GNUNET_NO); | 2089 | add_connections (pg, outer_count, inner_count, ALLOWED, GNUNET_NO); |
2080 | update_meter (conn_meter); | 2090 | update_meter (conn_meter); |
2081 | } | 2091 | } |
2082 | } | ||
2083 | } | 2092 | } |
2093 | } | ||
2084 | free_meter (conn_meter); | 2094 | free_meter (conn_meter); |
2085 | 2095 | ||
2086 | return connect_attempts; | 2096 | return connect_attempts; |
@@ -2100,8 +2110,9 @@ create_nated_internet_copy(struct GNUNET_TESTING_PeerGroup *pg, | |||
2100 | * | 2110 | * |
2101 | */ | 2111 | */ |
2102 | static unsigned int | 2112 | static unsigned int |
2103 | create_small_world(struct GNUNET_TESTING_PeerGroup *pg, | 2113 | create_small_world (struct GNUNET_TESTING_PeerGroup *pg, |
2104 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2114 | GNUNET_TESTING_ConnectionProcessor proc, |
2115 | enum PeerLists list) | ||
2105 | { | 2116 | { |
2106 | unsigned int i, j, k; | 2117 | unsigned int i, j, k; |
2107 | unsigned int square; | 2118 | unsigned int square; |
@@ -2120,62 +2131,60 @@ create_small_world(struct GNUNET_TESTING_PeerGroup *pg, | |||
2120 | unsigned int small_world_it; | 2131 | unsigned int small_world_it; |
2121 | char *p_string; | 2132 | char *p_string; |
2122 | int connect_attempts; | 2133 | int connect_attempts; |
2134 | |||
2123 | square = floor (sqrt (pg->total)); | 2135 | square = floor (sqrt (pg->total)); |
2124 | rows = square; | 2136 | rows = square; |
2125 | cols = square; | 2137 | cols = square; |
2126 | 2138 | ||
2127 | percentage = 0.5; /* FIXME: default percentage? */ | 2139 | percentage = 0.5; /* FIXME: default percentage? */ |
2128 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 2140 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2129 | "PERCENTAGE", | 2141 | "PERCENTAGE", |
2130 | &p_string)) | 2142 | &p_string)) |
2131 | { | 2143 | { |
2132 | if (sscanf (p_string, "%lf", &percentage) != 1) | 2144 | if (sscanf (p_string, "%lf", &percentage) != 1) |
2133 | GNUNET_log ( | 2145 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2134 | GNUNET_ERROR_TYPE_WARNING, | ||
2135 | _ | ||
2136 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | ||
2137 | p_string, "PERCENTAGE", "TESTING"); | ||
2138 | GNUNET_free (p_string); | ||
2139 | } | ||
2140 | if (percentage < 0.0) | ||
2141 | { | ||
2142 | GNUNET_log ( | ||
2143 | GNUNET_ERROR_TYPE_WARNING, | ||
2144 | _ | 2146 | _ |
2145 | ("Invalid value `%s' for option `%s' in section `%s': got %f, needed value greater than 0\n"), | 2147 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2146 | "PERCENTAGE", "TESTING", percentage); | 2148 | p_string, "PERCENTAGE", "TESTING"); |
2147 | percentage = 0.5; | 2149 | GNUNET_free (p_string); |
2148 | } | 2150 | } |
2149 | probability = 0.5; /* FIXME: default percentage? */ | 2151 | if (percentage < 0.0) |
2152 | { | ||
2153 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2154 | _ | ||
2155 | ("Invalid value `%s' for option `%s' in section `%s': got %f, needed value greater than 0\n"), | ||
2156 | "PERCENTAGE", "TESTING", percentage); | ||
2157 | percentage = 0.5; | ||
2158 | } | ||
2159 | probability = 0.5; /* FIXME: default percentage? */ | ||
2150 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 2160 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2151 | "PROBABILITY", | 2161 | "PROBABILITY", |
2152 | &p_string)) | 2162 | &p_string)) |
2153 | { | 2163 | { |
2154 | if (sscanf (p_string, "%lf", &probability) != 1) | 2164 | if (sscanf (p_string, "%lf", &probability) != 1) |
2155 | GNUNET_log ( | 2165 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2156 | GNUNET_ERROR_TYPE_WARNING, | 2166 | _ |
2157 | _ | 2167 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2158 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 2168 | p_string, "PROBABILITY", "TESTING"); |
2159 | p_string, "PROBABILITY", "TESTING"); | 2169 | GNUNET_free (p_string); |
2160 | GNUNET_free (p_string); | 2170 | } |
2161 | } | ||
2162 | if (square * square != pg->total) | 2171 | if (square * square != pg->total) |
2172 | { | ||
2173 | while (rows * cols < pg->total) | ||
2163 | { | 2174 | { |
2164 | while (rows * cols < pg->total) | 2175 | if (toggle % 2 == 0) |
2165 | { | 2176 | rows++; |
2166 | if (toggle % 2 == 0) | 2177 | else |
2167 | rows++; | 2178 | cols++; |
2168 | else | ||
2169 | cols++; | ||
2170 | 2179 | ||
2171 | toggle++; | 2180 | toggle++; |
2172 | } | ||
2173 | } | 2181 | } |
2182 | } | ||
2174 | #if VERBOSE_TESTING | 2183 | #if VERBOSE_TESTING |
2175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2176 | _ | 2185 | _ |
2177 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), | 2186 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), |
2178 | rows, cols); | 2187 | rows, cols); |
2179 | #endif | 2188 | #endif |
2180 | 2189 | ||
2181 | connect_attempts = 0; | 2190 | connect_attempts = 0; |
@@ -2185,36 +2194,36 @@ create_small_world(struct GNUNET_TESTING_PeerGroup *pg, | |||
2185 | * to the first in the row to maintain topology. | 2194 | * to the first in the row to maintain topology. |
2186 | */ | 2195 | */ |
2187 | for (i = 0; i < pg->total; i++) | 2196 | for (i = 0; i < pg->total; i++) |
2188 | { | 2197 | { |
2189 | /* First connect to the node to the right */ | 2198 | /* First connect to the node to the right */ |
2190 | if (((i + 1) % cols != 0) && (i + 1 != pg->total)) | 2199 | if (((i + 1) % cols != 0) && (i + 1 != pg->total)) |
2191 | nodeToConnect = i + 1; | 2200 | nodeToConnect = i + 1; |
2192 | else if (i + 1 == pg->total) | 2201 | else if (i + 1 == pg->total) |
2193 | nodeToConnect = rows * cols - cols; | 2202 | nodeToConnect = rows * cols - cols; |
2194 | else | 2203 | else |
2195 | nodeToConnect = i - cols + 1; | 2204 | nodeToConnect = i - cols + 1; |
2196 | |||
2197 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | ||
2198 | 2205 | ||
2199 | if (i < cols) | 2206 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); |
2200 | { | ||
2201 | nodeToConnect = (rows * cols) - cols + i; | ||
2202 | if (nodeToConnect >= pg->total) | ||
2203 | nodeToConnect -= cols; | ||
2204 | } | ||
2205 | else | ||
2206 | nodeToConnect = i - cols; | ||
2207 | 2207 | ||
2208 | if (nodeToConnect < pg->total) | 2208 | if (i < cols) |
2209 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | 2209 | { |
2210 | nodeToConnect = (rows * cols) - cols + i; | ||
2211 | if (nodeToConnect >= pg->total) | ||
2212 | nodeToConnect -= cols; | ||
2210 | } | 2213 | } |
2214 | else | ||
2215 | nodeToConnect = i - cols; | ||
2216 | |||
2217 | if (nodeToConnect < pg->total) | ||
2218 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | ||
2219 | } | ||
2211 | natLog = log (pg->total); | 2220 | natLog = log (pg->total); |
2212 | #if VERBOSE_TESTING > 2 | 2221 | #if VERBOSE_TESTING > 2 |
2213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2214 | _("natural log of %d is %d, will run %d iterations\n"), | 2223 | _("natural log of %d is %d, will run %d iterations\n"), |
2215 | pg->total, natLog, (int) (natLog * percentage)); | 2224 | pg->total, natLog, (int) (natLog * percentage)); |
2216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2217 | _("Total connections added thus far: %u!\n"), connect_attempts); | 2226 | _("Total connections added thus far: %u!\n"), connect_attempts); |
2218 | #endif | 2227 | #endif |
2219 | smallWorldConnections = 0; | 2228 | smallWorldConnections = 0; |
2220 | small_world_it = (unsigned int) (natLog * percentage); | 2229 | small_world_it = (unsigned int) (natLog * percentage); |
@@ -2222,42 +2231,41 @@ create_small_world(struct GNUNET_TESTING_PeerGroup *pg, | |||
2222 | small_world_it = 1; | 2231 | small_world_it = 1; |
2223 | GNUNET_assert (small_world_it > 0 && small_world_it < (unsigned int) -1); | 2232 | GNUNET_assert (small_world_it > 0 && small_world_it < (unsigned int) -1); |
2224 | for (i = 0; i < small_world_it; i++) | 2233 | for (i = 0; i < small_world_it; i++) |
2234 | { | ||
2235 | for (j = 0; j < pg->total; j++) | ||
2225 | { | 2236 | { |
2226 | for (j = 0; j < pg->total; j++) | 2237 | /* Determine the row and column of node at position j on the 2d torus */ |
2238 | node1Row = j / cols; | ||
2239 | node1Col = j - (node1Row * cols); | ||
2240 | for (k = 0; k < pg->total; k++) | ||
2241 | { | ||
2242 | /* Determine the row and column of node at position k on the 2d torus */ | ||
2243 | node2Row = k / cols; | ||
2244 | node2Col = k - (node2Row * cols); | ||
2245 | /* Simple Cartesian distance */ | ||
2246 | distance = abs (node1Row - node2Row) + abs (node1Col - node2Col); | ||
2247 | if (distance > 1) | ||
2227 | { | 2248 | { |
2228 | /* Determine the row and column of node at position j on the 2d torus */ | 2249 | /* Calculate probability as 1 over the square of the distance */ |
2229 | node1Row = j / cols; | 2250 | probability = 1.0 / (distance * distance); |
2230 | node1Col = j - (node1Row * cols); | 2251 | /* Choose a random value between 0 and 1 */ |
2231 | for (k = 0; k < pg->total; k++) | 2252 | random |
2232 | { | 2253 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
2233 | /* Determine the row and column of node at position k on the 2d torus */ | 2254 | UINT64_MAX)) |
2234 | node2Row = k / cols; | 2255 | / ((double) UINT64_MAX); |
2235 | node2Col = k - (node2Row * cols); | 2256 | /* If random < probability, then connect the two nodes */ |
2236 | /* Simple Cartesian distance */ | 2257 | if (random < probability) |
2237 | distance = abs (node1Row - node2Row) + abs (node1Col - node2Col); | 2258 | smallWorldConnections += proc (pg, j, k, list, GNUNET_YES); |
2238 | if (distance > 1) | 2259 | |
2239 | { | ||
2240 | /* Calculate probability as 1 over the square of the distance */ | ||
2241 | probability = 1.0 / (distance * distance); | ||
2242 | /* Choose a random value between 0 and 1 */ | ||
2243 | random | ||
2244 | = ((double) GNUNET_CRYPTO_random_u64 ( | ||
2245 | GNUNET_CRYPTO_QUALITY_WEAK, | ||
2246 | UINT64_MAX)) | ||
2247 | / ((double) UINT64_MAX); | ||
2248 | /* If random < probability, then connect the two nodes */ | ||
2249 | if (random < probability) | ||
2250 | smallWorldConnections += proc (pg, j, k, list, GNUNET_YES); | ||
2251 | |||
2252 | } | ||
2253 | } | ||
2254 | } | 2260 | } |
2261 | } | ||
2255 | } | 2262 | } |
2263 | } | ||
2256 | connect_attempts += smallWorldConnections; | 2264 | connect_attempts += smallWorldConnections; |
2257 | #if VERBOSE_TESTING > 2 | 2265 | #if VERBOSE_TESTING > 2 |
2258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2259 | _("Total connections added for small world: %d!\n"), | 2267 | _("Total connections added for small world: %d!\n"), |
2260 | smallWorldConnections); | 2268 | smallWorldConnections); |
2261 | #endif | 2269 | #endif |
2262 | return connect_attempts; | 2270 | return connect_attempts; |
2263 | } | 2271 | } |
@@ -2275,8 +2283,9 @@ create_small_world(struct GNUNET_TESTING_PeerGroup *pg, | |||
2275 | * | 2283 | * |
2276 | */ | 2284 | */ |
2277 | static unsigned int | 2285 | static unsigned int |
2278 | create_erdos_renyi(struct GNUNET_TESTING_PeerGroup *pg, | 2286 | create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, |
2279 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2287 | GNUNET_TESTING_ConnectionProcessor proc, |
2288 | enum PeerLists list) | ||
2280 | { | 2289 | { |
2281 | double temp_rand; | 2290 | double temp_rand; |
2282 | unsigned int outer_count; | 2291 | unsigned int outer_count; |
@@ -2285,40 +2294,38 @@ create_erdos_renyi(struct GNUNET_TESTING_PeerGroup *pg, | |||
2285 | double probability; | 2294 | double probability; |
2286 | char *p_string; | 2295 | char *p_string; |
2287 | 2296 | ||
2288 | probability = 0.5; /* FIXME: default percentage? */ | 2297 | probability = 0.5; /* FIXME: default percentage? */ |
2289 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", | 2298 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", |
2290 | "PROBABILITY", | 2299 | "PROBABILITY", |
2291 | &p_string)) | 2300 | &p_string)) |
2292 | { | 2301 | { |
2293 | if (sscanf (p_string, "%lf", &probability) != 1) | 2302 | if (sscanf (p_string, "%lf", &probability) != 1) |
2294 | GNUNET_log ( | 2303 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2295 | GNUNET_ERROR_TYPE_WARNING, | 2304 | _ |
2296 | _ | 2305 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), |
2297 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | 2306 | p_string, "PROBABILITY", "TESTING"); |
2298 | p_string, "PROBABILITY", "TESTING"); | 2307 | GNUNET_free (p_string); |
2299 | GNUNET_free (p_string); | 2308 | } |
2300 | } | ||
2301 | connect_attempts = 0; | 2309 | connect_attempts = 0; |
2302 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2310 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2311 | { | ||
2312 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
2303 | { | 2313 | { |
2304 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | 2314 | temp_rand |
2305 | { | 2315 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
2306 | temp_rand | 2316 | UINT64_MAX)) |
2307 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 2317 | / ((double) UINT64_MAX); |
2308 | UINT64_MAX)) | ||
2309 | / ((double) UINT64_MAX); | ||
2310 | #if VERBOSE_TESTING | 2318 | #if VERBOSE_TESTING |
2311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2312 | _("rand is %f probability is %f\n"), temp_rand, | 2320 | _("rand is %f probability is %f\n"), temp_rand, probability); |
2313 | probability); | 2321 | #endif |
2314 | #endif | 2322 | if (temp_rand < probability) |
2315 | if (temp_rand < probability) | 2323 | { |
2316 | { | 2324 | connect_attempts += proc (pg, outer_count, inner_count, list, |
2317 | connect_attempts += proc (pg, outer_count, inner_count, list, | 2325 | GNUNET_YES); |
2318 | GNUNET_YES); | 2326 | } |
2319 | } | ||
2320 | } | ||
2321 | } | 2327 | } |
2328 | } | ||
2322 | 2329 | ||
2323 | return connect_attempts; | 2330 | return connect_attempts; |
2324 | } | 2331 | } |
@@ -2338,8 +2345,8 @@ create_erdos_renyi(struct GNUNET_TESTING_PeerGroup *pg, | |||
2338 | * | 2345 | * |
2339 | */ | 2346 | */ |
2340 | static unsigned int | 2347 | static unsigned int |
2341 | create_2d_torus(struct GNUNET_TESTING_PeerGroup *pg, | 2348 | create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg, |
2342 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2349 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2343 | { | 2350 | { |
2344 | unsigned int i; | 2351 | unsigned int i; |
2345 | unsigned int square; | 2352 | unsigned int square; |
@@ -2356,22 +2363,22 @@ create_2d_torus(struct GNUNET_TESTING_PeerGroup *pg, | |||
2356 | cols = square; | 2363 | cols = square; |
2357 | 2364 | ||
2358 | if (square * square != pg->total) | 2365 | if (square * square != pg->total) |
2366 | { | ||
2367 | while (rows * cols < pg->total) | ||
2359 | { | 2368 | { |
2360 | while (rows * cols < pg->total) | 2369 | if (toggle % 2 == 0) |
2361 | { | 2370 | rows++; |
2362 | if (toggle % 2 == 0) | 2371 | else |
2363 | rows++; | 2372 | cols++; |
2364 | else | ||
2365 | cols++; | ||
2366 | 2373 | ||
2367 | toggle++; | 2374 | toggle++; |
2368 | } | ||
2369 | } | 2375 | } |
2376 | } | ||
2370 | #if VERBOSE_TESTING | 2377 | #if VERBOSE_TESTING |
2371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2372 | _ | 2379 | _ |
2373 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), | 2380 | ("Connecting nodes in 2d torus topology: %u rows %u columns\n"), |
2374 | rows, cols); | 2381 | rows, cols); |
2375 | #endif | 2382 | #endif |
2376 | /* Rows and columns are all sorted out, now iterate over all nodes and connect each | 2383 | /* Rows and columns are all sorted out, now iterate over all nodes and connect each |
2377 | * to the node to its right and above. Once this is over, we'll have our torus! | 2384 | * to the node to its right and above. Once this is over, we'll have our torus! |
@@ -2379,41 +2386,41 @@ create_2d_torus(struct GNUNET_TESTING_PeerGroup *pg, | |||
2379 | * to the first in the row to maintain topology. | 2386 | * to the first in the row to maintain topology. |
2380 | */ | 2387 | */ |
2381 | for (i = 0; i < pg->total; i++) | 2388 | for (i = 0; i < pg->total; i++) |
2382 | { | 2389 | { |
2383 | /* First connect to the node to the right */ | 2390 | /* First connect to the node to the right */ |
2384 | if (((i + 1) % cols != 0) && (i + 1 != pg->total)) | 2391 | if (((i + 1) % cols != 0) && (i + 1 != pg->total)) |
2385 | nodeToConnect = i + 1; | 2392 | nodeToConnect = i + 1; |
2386 | else if (i + 1 == pg->total) | 2393 | else if (i + 1 == pg->total) |
2387 | nodeToConnect = rows * cols - cols; | 2394 | nodeToConnect = rows * cols - cols; |
2388 | else | 2395 | else |
2389 | nodeToConnect = i - cols + 1; | 2396 | nodeToConnect = i - cols + 1; |
2390 | #if VERBOSE_TESTING | 2397 | #if VERBOSE_TESTING |
2391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2392 | "Connecting peer %d to peer %d\n", i, nodeToConnect); | 2399 | "Connecting peer %d to peer %d\n", i, nodeToConnect); |
2393 | #endif | 2400 | #endif |
2394 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | 2401 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); |
2395 | 2402 | ||
2396 | /* Second connect to the node immediately above */ | 2403 | /* Second connect to the node immediately above */ |
2397 | if (i < cols) | 2404 | if (i < cols) |
2398 | { | 2405 | { |
2399 | nodeToConnect = (rows * cols) - cols + i; | 2406 | nodeToConnect = (rows * cols) - cols + i; |
2400 | if (nodeToConnect >= pg->total) | 2407 | if (nodeToConnect >= pg->total) |
2401 | nodeToConnect -= cols; | 2408 | nodeToConnect -= cols; |
2402 | } | 2409 | } |
2403 | else | 2410 | else |
2404 | nodeToConnect = i - cols; | 2411 | nodeToConnect = i - cols; |
2405 | 2412 | ||
2406 | if (nodeToConnect < pg->total) | 2413 | if (nodeToConnect < pg->total) |
2407 | { | 2414 | { |
2408 | #if VERBOSE_TESTING | 2415 | #if VERBOSE_TESTING |
2409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2410 | "Connecting peer %d to peer %d\n", i, nodeToConnect); | 2417 | "Connecting peer %d to peer %d\n", i, nodeToConnect); |
2411 | #endif | 2418 | #endif |
2412 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); | 2419 | connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); |
2413 | } | ||
2414 | |||
2415 | } | 2420 | } |
2416 | 2421 | ||
2422 | } | ||
2423 | |||
2417 | return connect_attempts; | 2424 | return connect_attempts; |
2418 | } | 2425 | } |
2419 | 2426 | ||
@@ -2432,31 +2439,31 @@ create_2d_torus(struct GNUNET_TESTING_PeerGroup *pg, | |||
2432 | * | 2439 | * |
2433 | */ | 2440 | */ |
2434 | static unsigned int | 2441 | static unsigned int |
2435 | create_clique(struct GNUNET_TESTING_PeerGroup *pg, | 2442 | create_clique (struct GNUNET_TESTING_PeerGroup *pg, |
2436 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list, | 2443 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list, |
2437 | unsigned int check) | 2444 | unsigned int check) |
2438 | { | 2445 | { |
2439 | unsigned int outer_count; | 2446 | unsigned int outer_count; |
2440 | unsigned int inner_count; | 2447 | unsigned int inner_count; |
2441 | int connect_attempts; | 2448 | int connect_attempts; |
2442 | struct ProgressMeter *conn_meter; | 2449 | struct ProgressMeter *conn_meter; |
2450 | |||
2443 | connect_attempts = 0; | 2451 | connect_attempts = 0; |
2444 | 2452 | ||
2445 | conn_meter = create_meter ((((pg->total * pg->total) + pg->total) / 2) | 2453 | conn_meter = create_meter ((((pg->total * pg->total) + pg->total) / 2) |
2446 | - pg->total, "Create Clique ", GNUNET_NO); | 2454 | - pg->total, "Create Clique ", GNUNET_NO); |
2447 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 2455 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
2456 | { | ||
2457 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
2448 | { | 2458 | { |
2449 | for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) | ||
2450 | { | ||
2451 | #if VERBOSE_TESTING | 2459 | #if VERBOSE_TESTING |
2452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2460 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2453 | "Connecting peer %d to peer %d\n", | 2461 | "Connecting peer %d to peer %d\n", outer_count, inner_count); |
2454 | outer_count, inner_count); | ||
2455 | #endif | 2462 | #endif |
2456 | connect_attempts += proc (pg, outer_count, inner_count, list, check); | 2463 | connect_attempts += proc (pg, outer_count, inner_count, list, check); |
2457 | update_meter (conn_meter); | 2464 | update_meter (conn_meter); |
2458 | } | ||
2459 | } | 2465 | } |
2466 | } | ||
2460 | reset_meter (conn_meter); | 2467 | reset_meter (conn_meter); |
2461 | free_meter (conn_meter); | 2468 | free_meter (conn_meter); |
2462 | return connect_attempts; | 2469 | return connect_attempts; |
@@ -2475,19 +2482,17 @@ create_clique(struct GNUNET_TESTING_PeerGroup *pg, | |||
2475 | * GNUNET_NO if not. | 2482 | * GNUNET_NO if not. |
2476 | */ | 2483 | */ |
2477 | static int | 2484 | static int |
2478 | unblacklist_iterator (void *cls, | 2485 | unblacklist_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2479 | const GNUNET_HashCode * key, | 2486 | { |
2480 | void *value) | 2487 | struct UnblacklistContext *un_ctx = cls; |
2481 | { | 2488 | uint32_t second_pos; |
2482 | struct UnblacklistContext *un_ctx = cls; | ||
2483 | uint32_t second_pos; | ||
2484 | 2489 | ||
2485 | uid_from_hash (key, &second_pos); | 2490 | uid_from_hash (key, &second_pos); |
2486 | 2491 | ||
2487 | unblacklist_connections(un_ctx->pg, un_ctx->first_uid, second_pos); | 2492 | unblacklist_connections (un_ctx->pg, un_ctx->first_uid, second_pos); |
2488 | 2493 | ||
2489 | return GNUNET_YES; | 2494 | return GNUNET_YES; |
2490 | } | 2495 | } |
2491 | #endif | 2496 | #endif |
2492 | 2497 | ||
2493 | #if !OLD | 2498 | #if !OLD |
@@ -2510,6 +2515,7 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2510 | unsigned int count; | 2515 | unsigned int count; |
2511 | unsigned int total; | 2516 | unsigned int total; |
2512 | struct PeerConnection *iter; | 2517 | struct PeerConnection *iter; |
2518 | |||
2513 | #if !OLD | 2519 | #if !OLD |
2514 | struct UnblacklistContext un_ctx; | 2520 | struct UnblacklistContext un_ctx; |
2515 | 2521 | ||
@@ -2517,25 +2523,23 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2517 | #endif | 2523 | #endif |
2518 | total = 0; | 2524 | total = 0; |
2519 | for (count = 0; count < pg->total - 1; count++) | 2525 | for (count = 0; count < pg->total - 1; count++) |
2520 | { | 2526 | { |
2521 | #if OLD | 2527 | #if OLD |
2522 | iter = pg->peers[count].allowed_peers_head; | 2528 | iter = pg->peers[count].allowed_peers_head; |
2523 | while (iter != NULL) | 2529 | while (iter != NULL) |
2524 | { | 2530 | { |
2525 | remove_connections (pg, count, iter->index, BLACKLIST, GNUNET_YES); | 2531 | remove_connections (pg, count, iter->index, BLACKLIST, GNUNET_YES); |
2526 | //unblacklist_connections(pg, count, iter->index); | 2532 | //unblacklist_connections(pg, count, iter->index); |
2527 | iter = iter->next; | 2533 | iter = iter->next; |
2528 | } | 2534 | } |
2529 | #else | 2535 | #else |
2530 | un_ctx.first_uid = count; | 2536 | un_ctx.first_uid = count; |
2531 | total += GNUNET_CONTAINER_multihashmap_iterate(pg->peers[count].allowed_peers, | 2537 | total += |
2532 | &unblacklist_iterator, | 2538 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[count].allowed_peers, |
2533 | &un_ctx); | 2539 | &unblacklist_iterator, &un_ctx); |
2534 | #endif | 2540 | #endif |
2535 | } | 2541 | } |
2536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unblacklisted %u peers\n", total); |
2537 | "Unblacklisted %u peers\n", | ||
2538 | total); | ||
2539 | return total; | 2543 | return total; |
2540 | } | 2544 | } |
2541 | #endif | 2545 | #endif |
@@ -2553,8 +2557,8 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2553 | * | 2557 | * |
2554 | */ | 2558 | */ |
2555 | static unsigned int | 2559 | static unsigned int |
2556 | create_line(struct GNUNET_TESTING_PeerGroup *pg, | 2560 | create_line (struct GNUNET_TESTING_PeerGroup *pg, |
2557 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2561 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2558 | { | 2562 | { |
2559 | unsigned int count; | 2563 | unsigned int count; |
2560 | unsigned int connect_attempts; | 2564 | unsigned int connect_attempts; |
@@ -2562,14 +2566,13 @@ create_line(struct GNUNET_TESTING_PeerGroup *pg, | |||
2562 | connect_attempts = 0; | 2566 | connect_attempts = 0; |
2563 | /* Connect each peer to the next highest numbered peer */ | 2567 | /* Connect each peer to the next highest numbered peer */ |
2564 | for (count = 0; count < pg->total - 1; count++) | 2568 | for (count = 0; count < pg->total - 1; count++) |
2565 | { | 2569 | { |
2566 | #if VERBOSE_TESTING | 2570 | #if VERBOSE_TESTING |
2567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2568 | "Connecting peer %d to peer %d\n", | 2572 | "Connecting peer %d to peer %d\n", count, count + 1); |
2569 | count, count + 1); | ||
2570 | #endif | 2573 | #endif |
2571 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); | 2574 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); |
2572 | } | 2575 | } |
2573 | 2576 | ||
2574 | return connect_attempts; | 2577 | return connect_attempts; |
2575 | } | 2578 | } |
@@ -2588,8 +2591,8 @@ create_line(struct GNUNET_TESTING_PeerGroup *pg, | |||
2588 | * | 2591 | * |
2589 | */ | 2592 | */ |
2590 | static unsigned int | 2593 | static unsigned int |
2591 | create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename, | 2594 | create_from_file (struct GNUNET_TESTING_PeerGroup *pg, char *filename, |
2592 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2595 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2593 | { | 2596 | { |
2594 | int connect_attempts; | 2597 | int connect_attempts; |
2595 | unsigned int first_peer_index; | 2598 | unsigned int first_peer_index; |
@@ -2606,23 +2609,22 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename, | |||
2606 | GNUNET_DISK_fn_write (filename, NULL, 0, GNUNET_DISK_PERM_USER_READ); | 2609 | GNUNET_DISK_fn_write (filename, NULL, 0, GNUNET_DISK_PERM_USER_READ); |
2607 | 2610 | ||
2608 | if ((0 != STAT (filename, &frstat)) || (frstat.st_size == 0)) | 2611 | if ((0 != STAT (filename, &frstat)) || (frstat.st_size == 0)) |
2609 | { | 2612 | { |
2610 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2613 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2611 | "Could not open file `%s' specified for topology!", filename); | 2614 | "Could not open file `%s' specified for topology!", filename); |
2612 | return connect_attempts; | 2615 | return connect_attempts; |
2613 | } | 2616 | } |
2614 | 2617 | ||
2615 | data = GNUNET_malloc_large (frstat.st_size); | 2618 | data = GNUNET_malloc_large (frstat.st_size); |
2616 | GNUNET_assert(data != NULL); | 2619 | GNUNET_assert (data != NULL); |
2617 | if (frstat.st_size != GNUNET_DISK_fn_read (filename, data, frstat.st_size)) | 2620 | if (frstat.st_size != GNUNET_DISK_fn_read (filename, data, frstat.st_size)) |
2618 | { | 2621 | { |
2619 | GNUNET_log ( | 2622 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2620 | GNUNET_ERROR_TYPE_ERROR, | 2623 | "Could not read file %s specified for host list, ending test!", |
2621 | "Could not read file %s specified for host list, ending test!", | 2624 | filename); |
2622 | filename); | 2625 | GNUNET_free (data); |
2623 | GNUNET_free (data); | 2626 | return connect_attempts; |
2624 | return connect_attempts; | 2627 | } |
2625 | } | ||
2626 | 2628 | ||
2627 | buf = data; | 2629 | buf = data; |
2628 | count = 0; | 2630 | count = 0; |
@@ -2631,88 +2633,90 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename, | |||
2631 | /* Each subsequent line should contain this format PEER_INDEX:OTHER_PEER_INDEX[,...] */ | 2633 | /* Each subsequent line should contain this format PEER_INDEX:OTHER_PEER_INDEX[,...] */ |
2632 | curr_state = NUM_PEERS; | 2634 | curr_state = NUM_PEERS; |
2633 | while (count < frstat.st_size - 1) | 2635 | while (count < frstat.st_size - 1) |
2636 | { | ||
2637 | if ((buf[count] == '\n') || (buf[count] == ' ')) | ||
2634 | { | 2638 | { |
2635 | if ((buf[count] == '\n') || (buf[count] == ' ')) | 2639 | count++; |
2636 | { | 2640 | continue; |
2637 | count++; | 2641 | } |
2638 | continue; | ||
2639 | } | ||
2640 | 2642 | ||
2641 | switch (curr_state) | 2643 | switch (curr_state) |
2642 | { | 2644 | { |
2643 | case NUM_PEERS: | 2645 | case NUM_PEERS: |
2644 | errno = 0; | 2646 | errno = 0; |
2645 | total_peers = strtoul(&buf[count], NULL, 10); | 2647 | total_peers = strtoul (&buf[count], NULL, 10); |
2646 | if (errno != 0) | 2648 | if (errno != 0) |
2647 | { | 2649 | { |
2648 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2650 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2649 | "Failed to read number of peers from topology file!\n"); | 2651 | "Failed to read number of peers from topology file!\n"); |
2650 | GNUNET_free (data); | 2652 | GNUNET_free (data); |
2651 | return connect_attempts; | 2653 | return connect_attempts; |
2652 | } | 2654 | } |
2653 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2655 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2654 | "Read %u total peers in topology\n", total_peers); | 2656 | "Read %u total peers in topology\n", total_peers); |
2655 | GNUNET_assert(total_peers == pg->total); | 2657 | GNUNET_assert (total_peers == pg->total); |
2656 | curr_state = PEER_INDEX; | 2658 | curr_state = PEER_INDEX; |
2657 | while ((buf[count] != '\n') && (count < frstat.st_size - 1)) | 2659 | while ((buf[count] != '\n') && (count < frstat.st_size - 1)) |
2658 | count++; | 2660 | count++; |
2659 | count++; | 2661 | count++; |
2660 | break; | 2662 | break; |
2661 | case PEER_INDEX: | 2663 | case PEER_INDEX: |
2662 | errno = 0; | 2664 | errno = 0; |
2663 | first_peer_index = strtoul(&buf[count], NULL, 10); | 2665 | first_peer_index = strtoul (&buf[count], NULL, 10); |
2664 | if (errno != 0) | 2666 | if (errno != 0) |
2665 | { | 2667 | { |
2666 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2668 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2667 | "Failed to read peer index from topology file!\n"); | 2669 | "Failed to read peer index from topology file!\n"); |
2668 | GNUNET_free (data); | 2670 | GNUNET_free (data); |
2669 | return connect_attempts; | 2671 | return connect_attempts; |
2670 | } | 2672 | } |
2671 | while ((buf[count] != ':') && (count < frstat.st_size - 1)) | 2673 | while ((buf[count] != ':') && (count < frstat.st_size - 1)) |
2672 | count++; | 2674 | count++; |
2673 | count++; | 2675 | count++; |
2674 | curr_state = OTHER_PEER_INDEX; | 2676 | curr_state = OTHER_PEER_INDEX; |
2675 | break; | 2677 | break; |
2676 | case COLON: | 2678 | case COLON: |
2677 | if (1 == sscanf (&buf[count], ":")) | 2679 | if (1 == sscanf (&buf[count], ":")) |
2678 | curr_state = OTHER_PEER_INDEX; | 2680 | curr_state = OTHER_PEER_INDEX; |
2679 | count++; | 2681 | count++; |
2680 | break; | 2682 | break; |
2681 | case OTHER_PEER_INDEX: | 2683 | case OTHER_PEER_INDEX: |
2682 | errno = 0; | 2684 | errno = 0; |
2683 | second_peer_index = strtoul(&buf[count], NULL, 10); | 2685 | second_peer_index = strtoul (&buf[count], NULL, 10); |
2684 | if (errno != 0) | 2686 | if (errno != 0) |
2685 | { | 2687 | { |
2686 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2688 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2687 | "Failed to peer index from topology file!\n"); | 2689 | "Failed to peer index from topology file!\n"); |
2688 | GNUNET_free (data); | 2690 | GNUNET_free (data); |
2689 | return connect_attempts; | 2691 | return connect_attempts; |
2690 | } | 2692 | } |
2691 | /* Assume file is written with first peer 1, but array index is 0 */ | 2693 | /* Assume file is written with first peer 1, but array index is 0 */ |
2692 | connect_attempts += proc (pg, first_peer_index - 1, second_peer_index | 2694 | connect_attempts += proc (pg, first_peer_index - 1, second_peer_index |
2693 | - 1, list, GNUNET_YES); | 2695 | - 1, list, GNUNET_YES); |
2694 | while ((buf[count] != '\n') && (buf[count] != ',') && (count | 2696 | while ((buf[count] != '\n') && (buf[count] != ',') && (count |
2695 | < frstat.st_size - 1)) | 2697 | < |
2696 | count++; | 2698 | frstat.st_size - |
2697 | if (buf[count] == '\n') | 2699 | 1)) |
2698 | { | 2700 | count++; |
2699 | curr_state = PEER_INDEX; | 2701 | if (buf[count] == '\n') |
2700 | } | 2702 | { |
2701 | else if (buf[count] != ',') | 2703 | curr_state = PEER_INDEX; |
2702 | { | 2704 | } |
2703 | curr_state = OTHER_PEER_INDEX; | 2705 | else if (buf[count] != ',') |
2704 | } | 2706 | { |
2705 | count++; | 2707 | curr_state = OTHER_PEER_INDEX; |
2706 | break; | 2708 | } |
2707 | default: | 2709 | count++; |
2708 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2710 | break; |
2709 | "Found bad data in topology file while in state %d!\n", | 2711 | default: |
2710 | curr_state); | 2712 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2711 | GNUNET_break(0); | 2713 | "Found bad data in topology file while in state %d!\n", |
2712 | GNUNET_free (data); | 2714 | curr_state); |
2713 | return connect_attempts; | 2715 | GNUNET_break (0); |
2714 | } | 2716 | GNUNET_free (data); |
2717 | return connect_attempts; | ||
2715 | } | 2718 | } |
2719 | } | ||
2716 | GNUNET_free (data); | 2720 | GNUNET_free (data); |
2717 | return connect_attempts; | 2721 | return connect_attempts; |
2718 | } | 2722 | } |
@@ -2730,8 +2734,8 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename, | |||
2730 | * | 2734 | * |
2731 | */ | 2735 | */ |
2732 | static unsigned int | 2736 | static unsigned int |
2733 | create_ring(struct GNUNET_TESTING_PeerGroup *pg, | 2737 | create_ring (struct GNUNET_TESTING_PeerGroup *pg, |
2734 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 2738 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
2735 | { | 2739 | { |
2736 | unsigned int count; | 2740 | unsigned int count; |
2737 | int connect_attempts; | 2741 | int connect_attempts; |
@@ -2740,13 +2744,13 @@ create_ring(struct GNUNET_TESTING_PeerGroup *pg, | |||
2740 | 2744 | ||
2741 | /* Connect each peer to the next highest numbered peer */ | 2745 | /* Connect each peer to the next highest numbered peer */ |
2742 | for (count = 0; count < pg->total - 1; count++) | 2746 | for (count = 0; count < pg->total - 1; count++) |
2743 | { | 2747 | { |
2744 | #if VERBOSE_TESTING | 2748 | #if VERBOSE_TESTING |
2745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2746 | "Connecting peer %d to peer %d\n", count, count + 1); | 2750 | "Connecting peer %d to peer %d\n", count, count + 1); |
2747 | #endif | 2751 | #endif |
2748 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); | 2752 | connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); |
2749 | } | 2753 | } |
2750 | 2754 | ||
2751 | /* Connect the last peer to the first peer */ | 2755 | /* Connect the last peer to the first peer */ |
2752 | connect_attempts += proc (pg, pg->total - 1, 0, list, GNUNET_YES); | 2756 | connect_attempts += proc (pg, pg->total - 1, 0, list, GNUNET_YES); |
@@ -2774,31 +2778,31 @@ create_ring(struct GNUNET_TESTING_PeerGroup *pg, | |||
2774 | */ | 2778 | */ |
2775 | static int | 2779 | static int |
2776 | friend_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 2780 | friend_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2777 | { | 2781 | { |
2778 | FILE *temp_friend_handle = cls; | 2782 | FILE *temp_friend_handle = cls; |
2779 | struct GNUNET_TESTING_Daemon *peer = value; | 2783 | struct GNUNET_TESTING_Daemon *peer = value; |
2780 | struct GNUNET_PeerIdentity *temppeer; | 2784 | struct GNUNET_PeerIdentity *temppeer; |
2781 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | 2785 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; |
2782 | 2786 | ||
2783 | temppeer = &peer->id; | 2787 | temppeer = &peer->id; |
2784 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); | 2788 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); |
2785 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); | 2789 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); |
2786 | 2790 | ||
2787 | return GNUNET_YES; | 2791 | return GNUNET_YES; |
2788 | } | 2792 | } |
2789 | 2793 | ||
2790 | struct BlacklistContext | 2794 | struct BlacklistContext |
2791 | { | 2795 | { |
2792 | /* | 2796 | /* |
2793 | * The (open) file handle to write to | 2797 | * The (open) file handle to write to |
2794 | */ | 2798 | */ |
2795 | FILE *temp_file_handle; | 2799 | FILE *temp_file_handle; |
2796 | 2800 | ||
2797 | /* | 2801 | /* |
2798 | * The transport that this peer will be blacklisted on. | 2802 | * The transport that this peer will be blacklisted on. |
2799 | */ | 2803 | */ |
2800 | char *transport; | 2804 | char *transport; |
2801 | }; | 2805 | }; |
2802 | 2806 | ||
2803 | /** | 2807 | /** |
2804 | * Iterator for writing blacklist data to appropriate files. | 2808 | * Iterator for writing blacklist data to appropriate files. |
@@ -2811,20 +2815,21 @@ struct BlacklistContext | |||
2811 | */ | 2815 | */ |
2812 | static int | 2816 | static int |
2813 | blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 2817 | blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
2814 | { | 2818 | { |
2815 | struct BlacklistContext *blacklist_ctx = cls; | 2819 | struct BlacklistContext *blacklist_ctx = cls; |
2816 | struct GNUNET_TESTING_Daemon *peer = value; | 2820 | struct GNUNET_TESTING_Daemon *peer = value; |
2817 | struct GNUNET_PeerIdentity *temppeer; | 2821 | struct GNUNET_PeerIdentity *temppeer; |
2818 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | 2822 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; |
2819 | 2823 | ||
2820 | temppeer = &peer->id; | 2824 | temppeer = &peer->id; |
2821 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); | 2825 | GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc); |
2822 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Writing entry %s:%s to file\n", blacklist_ctx->transport, (char *) &peer_enc); | 2826 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing entry %s:%s to file\n", |
2823 | fprintf (blacklist_ctx->temp_file_handle, "%s:%s\n", | 2827 | blacklist_ctx->transport, (char *) &peer_enc); |
2824 | blacklist_ctx->transport, (char *) &peer_enc); | 2828 | fprintf (blacklist_ctx->temp_file_handle, "%s:%s\n", blacklist_ctx->transport, |
2829 | (char *) &peer_enc); | ||
2825 | 2830 | ||
2826 | return GNUNET_YES; | 2831 | return GNUNET_YES; |
2827 | } | 2832 | } |
2828 | #endif | 2833 | #endif |
2829 | 2834 | ||
2830 | /* | 2835 | /* |
@@ -2835,7 +2840,7 @@ blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
2835 | * @param pg the peer group we are dealing with | 2840 | * @param pg the peer group we are dealing with |
2836 | */ | 2841 | */ |
2837 | static int | 2842 | static int |
2838 | create_and_copy_friend_files(struct GNUNET_TESTING_PeerGroup *pg) | 2843 | create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) |
2839 | { | 2844 | { |
2840 | FILE *temp_friend_handle; | 2845 | FILE *temp_friend_handle; |
2841 | unsigned int pg_iter; | 2846 | unsigned int pg_iter; |
@@ -2843,6 +2848,7 @@ create_and_copy_friend_files(struct GNUNET_TESTING_PeerGroup *pg) | |||
2843 | struct GNUNET_OS_Process **procarr; | 2848 | struct GNUNET_OS_Process **procarr; |
2844 | char *arg; | 2849 | char *arg; |
2845 | char *mytemp; | 2850 | char *mytemp; |
2851 | |||
2846 | #if NOT_STUPID | 2852 | #if NOT_STUPID |
2847 | enum GNUNET_OS_ProcessStatusType type; | 2853 | enum GNUNET_OS_ProcessStatusType type; |
2848 | unsigned long return_code; | 2854 | unsigned long return_code; |
@@ -2858,147 +2864,137 @@ create_and_copy_friend_files(struct GNUNET_TESTING_PeerGroup *pg) | |||
2858 | #endif | 2864 | #endif |
2859 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); | 2865 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); |
2860 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 2866 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
2861 | { | 2867 | { |
2862 | mytemp = GNUNET_DISK_mktemp ("friends"); | 2868 | mytemp = GNUNET_DISK_mktemp ("friends"); |
2863 | GNUNET_assert (mytemp != NULL); | 2869 | GNUNET_assert (mytemp != NULL); |
2864 | temp_friend_handle = fopen (mytemp, "wt"); | 2870 | temp_friend_handle = fopen (mytemp, "wt"); |
2865 | GNUNET_assert (temp_friend_handle != NULL); | 2871 | GNUNET_assert (temp_friend_handle != NULL); |
2866 | #if OLD | 2872 | #if OLD |
2867 | conn_iter = pg->peers[pg_iter].allowed_peers_head; | 2873 | conn_iter = pg->peers[pg_iter].allowed_peers_head; |
2868 | while (conn_iter != NULL) | 2874 | while (conn_iter != NULL) |
2869 | { | 2875 | { |
2870 | GNUNET_CRYPTO_hash_to_enc ( | 2876 | GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon-> |
2871 | &pg->peers[conn_iter->index].daemon->id.hashPubKey, | 2877 | id.hashPubKey, &peer_enc); |
2872 | &peer_enc); | 2878 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); |
2873 | fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); | 2879 | conn_iter = conn_iter->next; |
2874 | conn_iter = conn_iter->next; | 2880 | } |
2875 | } | ||
2876 | #else | 2881 | #else |
2877 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, | 2882 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, |
2878 | &friend_file_iterator, | 2883 | &friend_file_iterator, |
2879 | temp_friend_handle); | 2884 | temp_friend_handle); |
2880 | #endif | 2885 | #endif |
2881 | fclose (temp_friend_handle); | 2886 | fclose (temp_friend_handle); |
2882 | 2887 | ||
2883 | if (GNUNET_OK | 2888 | if (GNUNET_OK |
2884 | != GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter]. | 2889 | != |
2885 | daemon->cfg, | 2890 | GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg, |
2886 | "PATHS", "SERVICEHOME", | 2891 | "PATHS", "SERVICEHOME", |
2887 | &temp_service_path)) | 2892 | &temp_service_path)) |
2888 | { | 2893 | { |
2889 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2894 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2890 | _("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), | 2895 | _ |
2891 | "SERVICEHOME", "PATHS"); | 2896 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), |
2892 | if (UNLINK (mytemp) != 0) | 2897 | "SERVICEHOME", "PATHS"); |
2893 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 2898 | if (UNLINK (mytemp) != 0) |
2894 | "unlink", | 2899 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", mytemp); |
2895 | mytemp); | 2900 | GNUNET_free (mytemp); |
2896 | GNUNET_free (mytemp); | 2901 | break; |
2897 | break; | 2902 | } |
2898 | } | ||
2899 | 2903 | ||
2900 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ | 2904 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ |
2901 | { | 2905 | { |
2902 | GNUNET_asprintf (&arg, "%s/friends", temp_service_path); | 2906 | GNUNET_asprintf (&arg, "%s/friends", temp_service_path); |
2903 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", | 2907 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", |
2904 | mytemp, arg, NULL); | 2908 | mytemp, arg, NULL); |
2905 | GNUNET_assert(procarr[pg_iter] != NULL); | 2909 | GNUNET_assert (procarr[pg_iter] != NULL); |
2906 | #if VERBOSE_TESTING | 2910 | #if VERBOSE_TESTING |
2907 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2911 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2908 | "Copying file with command cp %s %s\n", | 2912 | "Copying file with command cp %s %s\n", mytemp, arg); |
2909 | mytemp, | ||
2910 | arg); | ||
2911 | #endif | 2913 | #endif |
2912 | ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ | 2914 | ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ |
2913 | GNUNET_OS_process_close (procarr[pg_iter]); | 2915 | GNUNET_OS_process_close (procarr[pg_iter]); |
2914 | GNUNET_free (arg); | 2916 | GNUNET_free (arg); |
2915 | } | 2917 | } |
2916 | else /* Remote, scp the file to the correct place */ | 2918 | else /* Remote, scp the file to the correct place */ |
2917 | { | 2919 | { |
2918 | if (NULL != pg->peers[pg_iter].daemon->username) | 2920 | if (NULL != pg->peers[pg_iter].daemon->username) |
2919 | GNUNET_asprintf (&arg, "%s@%s:%s/friends", | 2921 | GNUNET_asprintf (&arg, "%s@%s:%s/friends", |
2920 | pg->peers[pg_iter].daemon->username, | 2922 | pg->peers[pg_iter].daemon->username, |
2921 | pg->peers[pg_iter].daemon->hostname, | 2923 | pg->peers[pg_iter].daemon->hostname, |
2922 | temp_service_path); | 2924 | temp_service_path); |
2923 | else | 2925 | else |
2924 | GNUNET_asprintf (&arg, "%s:%s/friends", | 2926 | GNUNET_asprintf (&arg, "%s:%s/friends", |
2925 | pg->peers[pg_iter].daemon->hostname, | 2927 | pg->peers[pg_iter].daemon->hostname, |
2926 | temp_service_path); | 2928 | temp_service_path); |
2927 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", | 2929 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", |
2928 | mytemp, arg, NULL); | 2930 | mytemp, arg, NULL); |
2929 | GNUNET_assert(procarr[pg_iter] != NULL); | 2931 | GNUNET_assert (procarr[pg_iter] != NULL); |
2930 | ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ | 2932 | ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ |
2931 | GNUNET_OS_process_close (procarr[pg_iter]); | 2933 | GNUNET_OS_process_close (procarr[pg_iter]); |
2932 | if (ret != GNUNET_OK) | 2934 | if (ret != GNUNET_OK) |
2933 | { | 2935 | { |
2934 | /* FIXME: free contents of 'procarr' array */ | 2936 | /* FIXME: free contents of 'procarr' array */ |
2935 | GNUNET_free (procarr); | 2937 | GNUNET_free (procarr); |
2936 | GNUNET_free (temp_service_path); | 2938 | GNUNET_free (temp_service_path); |
2937 | GNUNET_free (mytemp); | 2939 | GNUNET_free (mytemp); |
2938 | GNUNET_free (arg); | 2940 | GNUNET_free (arg); |
2939 | return ret; | 2941 | return ret; |
2940 | } | 2942 | } |
2941 | procarr[pg_iter] = NULL; | 2943 | procarr[pg_iter] = NULL; |
2942 | #if VERBOSE_TESTING | 2944 | #if VERBOSE_TESTING |
2943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2945 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2944 | "Copying file with command scp %s %s\n", | 2946 | "Copying file with command scp %s %s\n", mytemp, arg); |
2945 | mytemp, | ||
2946 | arg); | ||
2947 | #endif | 2947 | #endif |
2948 | GNUNET_free (arg); | 2948 | GNUNET_free (arg); |
2949 | } | ||
2950 | GNUNET_free (temp_service_path); | ||
2951 | GNUNET_free (mytemp); | ||
2952 | } | 2949 | } |
2950 | GNUNET_free (temp_service_path); | ||
2951 | GNUNET_free (mytemp); | ||
2952 | } | ||
2953 | 2953 | ||
2954 | #if NOT_STUPID | 2954 | #if NOT_STUPID |
2955 | count = 0; | 2955 | count = 0; |
2956 | ret = GNUNET_SYSERR; | 2956 | ret = GNUNET_SYSERR; |
2957 | while ((count < max_wait) && (ret != GNUNET_OK)) | 2957 | while ((count < max_wait) && (ret != GNUNET_OK)) |
2958 | { | ||
2959 | ret = GNUNET_OK; | ||
2960 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
2958 | { | 2961 | { |
2959 | ret = GNUNET_OK; | ||
2960 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
2961 | { | ||
2962 | #if VERBOSE_TESTING | 2962 | #if VERBOSE_TESTING |
2963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2964 | "Checking copy status of file %d\n", | 2964 | "Checking copy status of file %d\n", pg_iter); |
2965 | pg_iter); | ||
2966 | #endif | ||
2967 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ | ||
2968 | { | ||
2969 | if (GNUNET_OS_process_status | ||
2970 | (procarr[pg_iter], &type, &return_code) != GNUNET_OK) | ||
2971 | { | ||
2972 | ret = GNUNET_SYSERR; | ||
2973 | } | ||
2974 | else if ((type != GNUNET_OS_PROCESS_EXITED) | ||
2975 | || (return_code != 0)) | ||
2976 | { | ||
2977 | ret = GNUNET_SYSERR; | ||
2978 | } | ||
2979 | else | ||
2980 | { | ||
2981 | GNUNET_OS_process_close (procarr[pg_iter]); | ||
2982 | procarr[pg_iter] = NULL; | ||
2983 | #if VERBOSE_TESTING | ||
2984 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2985 | "File %d copied\n", | ||
2986 | pg_iter); | ||
2987 | #endif | 2965 | #endif |
2988 | } | 2966 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ |
2989 | } | 2967 | { |
2968 | if (GNUNET_OS_process_status | ||
2969 | (procarr[pg_iter], &type, &return_code) != GNUNET_OK) | ||
2970 | { | ||
2971 | ret = GNUNET_SYSERR; | ||
2990 | } | 2972 | } |
2991 | count++; | 2973 | else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0)) |
2992 | if (ret == GNUNET_SYSERR) | ||
2993 | { | 2974 | { |
2994 | /* FIXME: why sleep here? -CG */ | 2975 | ret = GNUNET_SYSERR; |
2995 | sleep (1); | 2976 | } |
2977 | else | ||
2978 | { | ||
2979 | GNUNET_OS_process_close (procarr[pg_iter]); | ||
2980 | procarr[pg_iter] = NULL; | ||
2981 | #if VERBOSE_TESTING | ||
2982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "File %d copied\n", pg_iter); | ||
2983 | #endif | ||
2996 | } | 2984 | } |
2985 | } | ||
2986 | } | ||
2987 | count++; | ||
2988 | if (ret == GNUNET_SYSERR) | ||
2989 | { | ||
2990 | /* FIXME: why sleep here? -CG */ | ||
2991 | sleep (1); | ||
2997 | } | 2992 | } |
2993 | } | ||
2998 | 2994 | ||
2999 | #if VERBOSE_TESTING | 2995 | #if VERBOSE_TESTING |
3000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2996 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3001 | _("Finished copying all friend files!\n")); | 2997 | _("Finished copying all friend files!\n")); |
3002 | #endif | 2998 | #endif |
3003 | #endif | 2999 | #endif |
3004 | GNUNET_free (procarr); | 3000 | GNUNET_free (procarr); |
@@ -3014,8 +3010,8 @@ create_and_copy_friend_files(struct GNUNET_TESTING_PeerGroup *pg) | |||
3014 | * @param transports space delimited list of transports to blacklist | 3010 | * @param transports space delimited list of transports to blacklist |
3015 | */ | 3011 | */ |
3016 | static int | 3012 | static int |
3017 | create_and_copy_blacklist_files(struct GNUNET_TESTING_PeerGroup *pg, | 3013 | create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, |
3018 | const char *transports) | 3014 | const char *transports) |
3019 | { | 3015 | { |
3020 | FILE *temp_file_handle; | 3016 | FILE *temp_file_handle; |
3021 | unsigned int pg_iter; | 3017 | unsigned int pg_iter; |
@@ -3032,6 +3028,7 @@ create_and_copy_blacklist_files(struct GNUNET_TESTING_PeerGroup *pg, | |||
3032 | unsigned int i; | 3028 | unsigned int i; |
3033 | char *pos; | 3029 | char *pos; |
3034 | char *temp_transports; | 3030 | char *temp_transports; |
3031 | |||
3035 | #if OLD | 3032 | #if OLD |
3036 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; | 3033 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc; |
3037 | struct PeerConnection *conn_iter; | 3034 | struct PeerConnection *conn_iter; |
@@ -3041,155 +3038,149 @@ create_and_copy_blacklist_files(struct GNUNET_TESTING_PeerGroup *pg, | |||
3041 | 3038 | ||
3042 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); | 3039 | procarr = GNUNET_malloc (sizeof (struct GNUNET_OS_Process *) * pg->total); |
3043 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3040 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3044 | { | 3041 | { |
3045 | mytemp = GNUNET_DISK_mktemp ("blacklist"); | 3042 | mytemp = GNUNET_DISK_mktemp ("blacklist"); |
3046 | GNUNET_assert (mytemp != NULL); | 3043 | GNUNET_assert (mytemp != NULL); |
3047 | temp_file_handle = fopen (mytemp, "wt"); | 3044 | temp_file_handle = fopen (mytemp, "wt"); |
3048 | GNUNET_assert (temp_file_handle != NULL); | 3045 | GNUNET_assert (temp_file_handle != NULL); |
3049 | temp_transports = GNUNET_strdup (transports); | 3046 | temp_transports = GNUNET_strdup (transports); |
3050 | #if !OLD | 3047 | #if !OLD |
3051 | blacklist_ctx.temp_file_handle = temp_file_handle; | 3048 | blacklist_ctx.temp_file_handle = temp_file_handle; |
3052 | #endif | 3049 | #endif |
3053 | transport_len = strlen (temp_transports) + 1; | 3050 | transport_len = strlen (temp_transports) + 1; |
3054 | pos = NULL; | 3051 | pos = NULL; |
3055 | 3052 | ||
3056 | for (i = 0; i < transport_len; i++) | 3053 | for (i = 0; i < transport_len; i++) |
3057 | { | 3054 | { |
3058 | if ((temp_transports[i] == ' ') && (pos == NULL)) | 3055 | if ((temp_transports[i] == ' ') && (pos == NULL)) |
3059 | continue; /* At start of string (whitespace) */ | 3056 | continue; /* At start of string (whitespace) */ |
3060 | else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */ | 3057 | else if ((temp_transports[i] == ' ') || (temp_transports[i] == '\0')) /* At end of string */ |
3061 | { | 3058 | { |
3062 | temp_transports[i] = '\0'; | 3059 | temp_transports[i] = '\0'; |
3063 | #if OLD | 3060 | #if OLD |
3064 | conn_iter = pg->peers[pg_iter].blacklisted_peers_head; | 3061 | conn_iter = pg->peers[pg_iter].blacklisted_peers_head; |
3065 | while (conn_iter != NULL) | 3062 | while (conn_iter != NULL) |
3066 | { | 3063 | { |
3067 | GNUNET_CRYPTO_hash_to_enc ( | 3064 | GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon-> |
3068 | &pg->peers[conn_iter->index].daemon->id.hashPubKey, | 3065 | id.hashPubKey, &peer_enc); |
3069 | &peer_enc); | 3066 | fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc); |
3070 | fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc); | 3067 | conn_iter = conn_iter->next; |
3071 | conn_iter = conn_iter->next; | ||
3072 | } | ||
3073 | #else | ||
3074 | blacklist_ctx.transport = pos; | ||
3075 | (void) GNUNET_CONTAINER_multihashmap_iterate (pg-> | ||
3076 | peers | ||
3077 | [pg_iter].blacklisted_peers, | ||
3078 | &blacklist_file_iterator, | ||
3079 | &blacklist_ctx); | ||
3080 | #endif | ||
3081 | pos = NULL; | ||
3082 | } /* At beginning of actual string */ | ||
3083 | else if (pos == NULL) | ||
3084 | { | ||
3085 | pos = &temp_transports[i]; | ||
3086 | } | ||
3087 | } | 3068 | } |
3069 | #else | ||
3070 | blacklist_ctx.transport = pos; | ||
3071 | (void) GNUNET_CONTAINER_multihashmap_iterate (pg->peers | ||
3072 | [pg_iter].blacklisted_peers, | ||
3073 | &blacklist_file_iterator, | ||
3074 | &blacklist_ctx); | ||
3075 | #endif | ||
3076 | pos = NULL; | ||
3077 | } /* At beginning of actual string */ | ||
3078 | else if (pos == NULL) | ||
3079 | { | ||
3080 | pos = &temp_transports[i]; | ||
3081 | } | ||
3082 | } | ||
3088 | 3083 | ||
3089 | GNUNET_free (temp_transports); | 3084 | GNUNET_free (temp_transports); |
3090 | fclose (temp_file_handle); | 3085 | fclose (temp_file_handle); |
3091 | 3086 | ||
3092 | if (GNUNET_OK | 3087 | if (GNUNET_OK |
3093 | != GNUNET_CONFIGURATION_get_value_string ( | 3088 | != |
3094 | pg->peers[pg_iter]. daemon->cfg, | 3089 | GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg, |
3095 | "PATHS", "SERVICEHOME", | 3090 | "PATHS", "SERVICEHOME", |
3096 | &temp_service_path)) | 3091 | &temp_service_path)) |
3097 | { | 3092 | { |
3098 | GNUNET_log ( | 3093 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3099 | GNUNET_ERROR_TYPE_WARNING, | 3094 | _ |
3100 | _ | 3095 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), |
3101 | ("No `%s' specified in peer configuration in section `%s', cannot copy friends file!\n"), | 3096 | "SERVICEHOME", "PATHS"); |
3102 | "SERVICEHOME", "PATHS"); | 3097 | if (UNLINK (mytemp) != 0) |
3103 | if (UNLINK (mytemp) != 0) | 3098 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", mytemp); |
3104 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", | 3099 | GNUNET_free (mytemp); |
3105 | mytemp); | 3100 | break; |
3106 | GNUNET_free (mytemp); | 3101 | } |
3107 | break; | ||
3108 | } | ||
3109 | 3102 | ||
3110 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ | 3103 | if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ |
3111 | { | 3104 | { |
3112 | GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); | 3105 | GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); |
3113 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", | 3106 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", |
3114 | mytemp, arg, NULL); | 3107 | mytemp, arg, NULL); |
3115 | #if VERBOSE_TESTING | 3108 | #if VERBOSE_TESTING |
3116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3117 | _("Copying file with command cp %s %s\n"), mytemp, arg); | 3110 | _("Copying file with command cp %s %s\n"), mytemp, arg); |
3118 | #endif | 3111 | #endif |
3119 | 3112 | ||
3120 | GNUNET_free (arg); | 3113 | GNUNET_free (arg); |
3121 | } | 3114 | } |
3122 | else /* Remote, scp the file to the correct place */ | 3115 | else /* Remote, scp the file to the correct place */ |
3123 | { | 3116 | { |
3124 | if (NULL != pg->peers[pg_iter].daemon->username) | 3117 | if (NULL != pg->peers[pg_iter].daemon->username) |
3125 | GNUNET_asprintf (&arg, "%s@%s:%s/blacklist", | 3118 | GNUNET_asprintf (&arg, "%s@%s:%s/blacklist", |
3126 | pg->peers[pg_iter].daemon->username, | 3119 | pg->peers[pg_iter].daemon->username, |
3127 | pg->peers[pg_iter].daemon->hostname, | 3120 | pg->peers[pg_iter].daemon->hostname, |
3128 | temp_service_path); | 3121 | temp_service_path); |
3129 | else | 3122 | else |
3130 | GNUNET_asprintf (&arg, "%s:%s/blacklist", | 3123 | GNUNET_asprintf (&arg, "%s:%s/blacklist", |
3131 | pg->peers[pg_iter].daemon->hostname, | 3124 | pg->peers[pg_iter].daemon->hostname, |
3132 | temp_service_path); | 3125 | temp_service_path); |
3133 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", | 3126 | procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", |
3134 | mytemp, arg, NULL); | 3127 | mytemp, arg, NULL); |
3135 | GNUNET_assert(procarr[pg_iter] != NULL); | 3128 | GNUNET_assert (procarr[pg_iter] != NULL); |
3136 | GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */ | 3129 | GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */ |
3137 | 3130 | ||
3138 | #if VERBOSE_TESTING | 3131 | #if VERBOSE_TESTING |
3139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3140 | _("Copying file with command scp %s %s\n"), mytemp, | 3133 | _("Copying file with command scp %s %s\n"), mytemp, arg); |
3141 | arg); | ||
3142 | #endif | 3134 | #endif |
3143 | GNUNET_free (arg); | 3135 | GNUNET_free (arg); |
3144 | } | ||
3145 | GNUNET_free (temp_service_path); | ||
3146 | GNUNET_free (mytemp); | ||
3147 | } | 3136 | } |
3137 | GNUNET_free (temp_service_path); | ||
3138 | GNUNET_free (mytemp); | ||
3139 | } | ||
3148 | 3140 | ||
3149 | count = 0; | 3141 | count = 0; |
3150 | ret = GNUNET_SYSERR; | 3142 | ret = GNUNET_SYSERR; |
3151 | while ((count < max_wait) && (ret != GNUNET_OK)) | 3143 | while ((count < max_wait) && (ret != GNUNET_OK)) |
3144 | { | ||
3145 | ret = GNUNET_OK; | ||
3146 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
3152 | { | 3147 | { |
3153 | ret = GNUNET_OK; | ||
3154 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
3155 | { | ||
3156 | #if VERBOSE_TESTING | 3148 | #if VERBOSE_TESTING |
3157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3158 | _("Checking copy status of file %d\n"), pg_iter); | 3150 | _("Checking copy status of file %d\n"), pg_iter); |
3159 | #endif | ||
3160 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ | ||
3161 | { | ||
3162 | if (GNUNET_OS_process_status (procarr[pg_iter], &type, | ||
3163 | &return_code) != GNUNET_OK) | ||
3164 | { | ||
3165 | ret = GNUNET_SYSERR; | ||
3166 | } | ||
3167 | else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0)) | ||
3168 | { | ||
3169 | ret = GNUNET_SYSERR; | ||
3170 | } | ||
3171 | else | ||
3172 | { | ||
3173 | GNUNET_OS_process_close (procarr[pg_iter]); | ||
3174 | procarr[pg_iter] = NULL; | ||
3175 | #if VERBOSE_TESTING | ||
3176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3177 | _("File %d copied\n"), pg_iter); | ||
3178 | #endif | 3151 | #endif |
3179 | } | 3152 | if (procarr[pg_iter] != NULL) /* Check for already completed! */ |
3180 | } | 3153 | { |
3154 | if (GNUNET_OS_process_status (procarr[pg_iter], &type, | ||
3155 | &return_code) != GNUNET_OK) | ||
3156 | { | ||
3157 | ret = GNUNET_SYSERR; | ||
3181 | } | 3158 | } |
3182 | count++; | 3159 | else if ((type != GNUNET_OS_PROCESS_EXITED) || (return_code != 0)) |
3183 | if (ret == GNUNET_SYSERR) | ||
3184 | { | 3160 | { |
3185 | /* FIXME: why sleep here? -CG */ | 3161 | ret = GNUNET_SYSERR; |
3186 | sleep (1); | ||
3187 | } | 3162 | } |
3163 | else | ||
3164 | { | ||
3165 | GNUNET_OS_process_close (procarr[pg_iter]); | ||
3166 | procarr[pg_iter] = NULL; | ||
3167 | #if VERBOSE_TESTING | ||
3168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("File %d copied\n"), pg_iter); | ||
3169 | #endif | ||
3170 | } | ||
3171 | } | ||
3172 | } | ||
3173 | count++; | ||
3174 | if (ret == GNUNET_SYSERR) | ||
3175 | { | ||
3176 | /* FIXME: why sleep here? -CG */ | ||
3177 | sleep (1); | ||
3188 | } | 3178 | } |
3179 | } | ||
3189 | 3180 | ||
3190 | #if VERBOSE_TESTING | 3181 | #if VERBOSE_TESTING |
3191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3192 | _("Finished copying all blacklist files!\n")); | 3183 | _("Finished copying all blacklist files!\n")); |
3193 | #endif | 3184 | #endif |
3194 | GNUNET_free (procarr); | 3185 | GNUNET_free (procarr); |
3195 | return ret; | 3186 | return ret; |
@@ -3197,7 +3188,7 @@ create_and_copy_blacklist_files(struct GNUNET_TESTING_PeerGroup *pg, | |||
3197 | 3188 | ||
3198 | /* Forward Declaration */ | 3189 | /* Forward Declaration */ |
3199 | static void | 3190 | static void |
3200 | schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 3191 | schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
3201 | 3192 | ||
3202 | /** | 3193 | /** |
3203 | * Choose a random peer's next connection to create, and | 3194 | * Choose a random peer's next connection to create, and |
@@ -3206,7 +3197,7 @@ schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
3206 | * @param ct_ctx the overall connection context | 3197 | * @param ct_ctx the overall connection context |
3207 | */ | 3198 | */ |
3208 | static void | 3199 | static void |
3209 | preschedule_connect(struct GNUNET_TESTING_PeerGroup *pg) | 3200 | preschedule_connect (struct GNUNET_TESTING_PeerGroup *pg) |
3210 | { | 3201 | { |
3211 | struct ConnectTopologyContext *ct_ctx = &pg->ct_ctx; | 3202 | struct ConnectTopologyContext *ct_ctx = &pg->ct_ctx; |
3212 | struct PeerConnection *connection_iter; | 3203 | struct PeerConnection *connection_iter; |
@@ -3227,14 +3218,18 @@ preschedule_connect(struct GNUNET_TESTING_PeerGroup *pg) | |||
3227 | connect_context->second_index = connection_iter->index; | 3218 | connect_context->second_index = connection_iter->index; |
3228 | connect_context->ct_ctx = ct_ctx; | 3219 | connect_context->ct_ctx = ct_ctx; |
3229 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); | 3220 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); |
3230 | GNUNET_CONTAINER_DLL_remove(pg->peers[random_peer].connect_peers_head, pg->peers[random_peer].connect_peers_tail, connection_iter); | 3221 | GNUNET_CONTAINER_DLL_remove (pg->peers[random_peer].connect_peers_head, |
3231 | GNUNET_free(connection_iter); | 3222 | pg->peers[random_peer].connect_peers_tail, |
3223 | connection_iter); | ||
3224 | GNUNET_free (connection_iter); | ||
3232 | ct_ctx->remaining_connections--; | 3225 | ct_ctx->remaining_connections--; |
3233 | } | 3226 | } |
3234 | 3227 | ||
3235 | #if USE_SEND_HELLOS | 3228 | #if USE_SEND_HELLOS |
3236 | /* Forward declaration */ | 3229 | /* Forward declaration */ |
3237 | static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 3230 | static void schedule_send_hellos (void *cls, |
3231 | const struct GNUNET_SCHEDULER_TaskContext | ||
3232 | *tc); | ||
3238 | 3233 | ||
3239 | /** | 3234 | /** |
3240 | * Close connections and free the hello context. | 3235 | * Close connections and free the hello context. |
@@ -3244,26 +3239,27 @@ static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskC | |||
3244 | */ | 3239 | */ |
3245 | static void | 3240 | static void |
3246 | free_hello_context (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3241 | free_hello_context (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3242 | { | ||
3243 | struct SendHelloContext *send_hello_context = cls; | ||
3244 | |||
3245 | if (send_hello_context->peer->daemon->server != NULL) | ||
3247 | { | 3246 | { |
3248 | struct SendHelloContext *send_hello_context = cls; | 3247 | GNUNET_CORE_disconnect (send_hello_context->peer->daemon->server); |
3249 | if (send_hello_context->peer->daemon->server != NULL) | 3248 | send_hello_context->peer->daemon->server = NULL; |
3250 | { | 3249 | } |
3251 | GNUNET_CORE_disconnect(send_hello_context->peer->daemon->server); | 3250 | if (send_hello_context->peer->daemon->th != NULL) |
3252 | send_hello_context->peer->daemon->server = NULL; | 3251 | { |
3253 | } | 3252 | GNUNET_TRANSPORT_disconnect (send_hello_context->peer->daemon->th); |
3254 | if (send_hello_context->peer->daemon->th != NULL) | 3253 | send_hello_context->peer->daemon->th = NULL; |
3255 | { | ||
3256 | GNUNET_TRANSPORT_disconnect(send_hello_context->peer->daemon->th); | ||
3257 | send_hello_context->peer->daemon->th = NULL; | ||
3258 | } | ||
3259 | if (send_hello_context->core_connect_task != GNUNET_SCHEDULER_NO_TASK) | ||
3260 | { | ||
3261 | GNUNET_SCHEDULER_cancel(send_hello_context->core_connect_task); | ||
3262 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; | ||
3263 | } | ||
3264 | send_hello_context->pg->outstanding_connects--; | ||
3265 | GNUNET_free(send_hello_context); | ||
3266 | } | 3254 | } |
3255 | if (send_hello_context->core_connect_task != GNUNET_SCHEDULER_NO_TASK) | ||
3256 | { | ||
3257 | GNUNET_SCHEDULER_cancel (send_hello_context->core_connect_task); | ||
3258 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; | ||
3259 | } | ||
3260 | send_hello_context->pg->outstanding_connects--; | ||
3261 | GNUNET_free (send_hello_context); | ||
3262 | } | ||
3267 | 3263 | ||
3268 | /** | 3264 | /** |
3269 | * For peers that haven't yet connected, notify | 3265 | * For peers that haven't yet connected, notify |
@@ -3273,40 +3269,41 @@ free_hello_context (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3273 | * @param tc scheduler context | 3269 | * @param tc scheduler context |
3274 | */ | 3270 | */ |
3275 | static void | 3271 | static void |
3276 | notify_remaining_connections_failed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3272 | notify_remaining_connections_failed (void *cls, |
3277 | { | 3273 | const struct GNUNET_SCHEDULER_TaskContext |
3278 | struct SendHelloContext *send_hello_context = cls; | 3274 | *tc) |
3279 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | 3275 | { |
3280 | struct PeerConnection *connection; | 3276 | struct SendHelloContext *send_hello_context = cls; |
3277 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | ||
3278 | struct PeerConnection *connection; | ||
3281 | 3279 | ||
3282 | GNUNET_CORE_disconnect(send_hello_context->peer->daemon->server); | 3280 | GNUNET_CORE_disconnect (send_hello_context->peer->daemon->server); |
3283 | send_hello_context->peer->daemon->server = NULL; | 3281 | send_hello_context->peer->daemon->server = NULL; |
3284 | 3282 | ||
3285 | connection = send_hello_context->peer->connect_peers_head; | 3283 | connection = send_hello_context->peer->connect_peers_head; |
3286 | 3284 | ||
3287 | while (connection != NULL) | 3285 | while (connection != NULL) |
3288 | { | 3286 | { |
3289 | if (pg->notify_connection != NULL) | 3287 | if (pg->notify_connection != NULL) |
3290 | { | 3288 | { |
3291 | pg->notify_connection(pg->notify_connection_cls, | 3289 | pg->notify_connection (pg->notify_connection_cls, &send_hello_context->peer->daemon->id, &pg->peers[connection->index].daemon->id, 0, /* FIXME */ |
3292 | &send_hello_context->peer->daemon->id, | 3290 | send_hello_context->peer->daemon->cfg, |
3293 | &pg->peers[connection->index].daemon->id, | 3291 | pg->peers[connection->index].daemon->cfg, |
3294 | 0, /* FIXME */ | 3292 | send_hello_context->peer->daemon, |
3295 | send_hello_context->peer->daemon->cfg, | 3293 | pg->peers[connection->index].daemon, |
3296 | pg->peers[connection->index].daemon->cfg, | 3294 | "Peers failed to connect (timeout)"); |
3297 | send_hello_context->peer->daemon, | 3295 | } |
3298 | pg->peers[connection->index].daemon, | 3296 | GNUNET_CONTAINER_DLL_remove (send_hello_context->peer->connect_peers_head, |
3299 | "Peers failed to connect (timeout)"); | 3297 | send_hello_context->peer->connect_peers_tail, |
3300 | } | 3298 | connection); |
3301 | GNUNET_CONTAINER_DLL_remove(send_hello_context->peer->connect_peers_head, send_hello_context->peer->connect_peers_tail, connection); | 3299 | GNUNET_free (connection); |
3302 | GNUNET_free(connection); | 3300 | connection = connection->next; |
3303 | connection = connection->next; | 3301 | } |
3304 | } | 3302 | GNUNET_SCHEDULER_add_now (&free_hello_context, send_hello_context); |
3305 | GNUNET_SCHEDULER_add_now(&free_hello_context, send_hello_context); | ||
3306 | #if BAD | 3303 | #if BAD |
3307 | other_peer = &pg->peers[connection->index]; | 3304 | other_peer = &pg->peers[connection->index]; |
3308 | #endif | 3305 | #endif |
3309 | } | 3306 | } |
3310 | 3307 | ||
3311 | /** | 3308 | /** |
3312 | * For peers that haven't yet connected, send | 3309 | * For peers that haven't yet connected, send |
@@ -3316,37 +3313,48 @@ notify_remaining_connections_failed (void *cls, const struct GNUNET_SCHEDULER_Ta | |||
3316 | * @param tc scheduler context | 3313 | * @param tc scheduler context |
3317 | */ | 3314 | */ |
3318 | static void | 3315 | static void |
3319 | send_core_connect_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3316 | send_core_connect_requests (void *cls, |
3320 | { | 3317 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
3321 | struct SendHelloContext *send_hello_context = cls; | 3318 | { |
3322 | struct PeerConnection *conn; | 3319 | struct SendHelloContext *send_hello_context = cls; |
3323 | GNUNET_assert(send_hello_context->peer->daemon->server != NULL); | 3320 | struct PeerConnection *conn; |
3324 | 3321 | ||
3325 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; | 3322 | GNUNET_assert (send_hello_context->peer->daemon->server != NULL); |
3326 | 3323 | ||
3327 | send_hello_context->connect_attempts++; | 3324 | send_hello_context->core_connect_task = GNUNET_SCHEDULER_NO_TASK; |
3328 | if (send_hello_context->connect_attempts < send_hello_context->pg->ct_ctx.connect_attempts) | ||
3329 | { | ||
3330 | conn = send_hello_context->peer->connect_peers_head; | ||
3331 | while (conn != NULL) | ||
3332 | { | ||
3333 | GNUNET_CORE_peer_request_connect(send_hello_context->peer->daemon->server, | ||
3334 | &send_hello_context->pg->peers[conn->index].daemon->id, | ||
3335 | NULL, | ||
3336 | NULL); | ||
3337 | conn = conn->next; | ||
3338 | } | ||
3339 | 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) , | ||
3340 | &send_core_connect_requests, | ||
3341 | send_hello_context); | ||
3342 | } | ||
3343 | else | ||
3344 | { | ||
3345 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Timeout before all connections created, marking rest as failed!\n"); | ||
3346 | GNUNET_SCHEDULER_add_now(¬ify_remaining_connections_failed, send_hello_context); | ||
3347 | } | ||
3348 | 3325 | ||
3326 | send_hello_context->connect_attempts++; | ||
3327 | if (send_hello_context->connect_attempts < | ||
3328 | send_hello_context->pg->ct_ctx.connect_attempts) | ||
3329 | { | ||
3330 | conn = send_hello_context->peer->connect_peers_head; | ||
3331 | while (conn != NULL) | ||
3332 | { | ||
3333 | GNUNET_CORE_peer_request_connect (send_hello_context->peer-> | ||
3334 | daemon->server, | ||
3335 | &send_hello_context->pg-> | ||
3336 | peers[conn->index].daemon->id, NULL, | ||
3337 | NULL); | ||
3338 | conn = conn->next; | ||
3339 | } | ||
3340 | send_hello_context->core_connect_task = | ||
3341 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide | ||
3342 | (send_hello_context->pg-> | ||
3343 | ct_ctx.connect_timeout, | ||
3344 | send_hello_context->pg-> | ||
3345 | ct_ctx.connect_attempts), | ||
3346 | &send_core_connect_requests, | ||
3347 | send_hello_context); | ||
3349 | } | 3348 | } |
3349 | else | ||
3350 | { | ||
3351 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
3352 | "Timeout before all connections created, marking rest as failed!\n"); | ||
3353 | GNUNET_SCHEDULER_add_now (¬ify_remaining_connections_failed, | ||
3354 | send_hello_context); | ||
3355 | } | ||
3356 | |||
3357 | } | ||
3350 | 3358 | ||
3351 | /** | 3359 | /** |
3352 | * Success, connection is up. Signal client our success. | 3360 | * Success, connection is up. Signal client our success. |
@@ -3361,96 +3369,101 @@ send_core_connect_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext | |||
3361 | */ | 3369 | */ |
3362 | static void | 3370 | static void |
3363 | core_connect_notify (void *cls, | 3371 | core_connect_notify (void *cls, |
3364 | const struct GNUNET_PeerIdentity *peer, | 3372 | const struct GNUNET_PeerIdentity *peer, |
3365 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 3373 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
3366 | { | 3374 | { |
3367 | struct SendHelloContext *send_hello_context = cls; | 3375 | struct SendHelloContext *send_hello_context = cls; |
3368 | struct PeerConnection *connection; | 3376 | struct PeerConnection *connection; |
3369 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | 3377 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; |
3378 | |||
3370 | #if BAD | 3379 | #if BAD |
3371 | struct PeerData *other_peer; | 3380 | struct PeerData *other_peer; |
3372 | #endif | 3381 | #endif |
3373 | #if DEBUG_TESTING | 3382 | #if DEBUG_TESTING |
3374 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3383 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3375 | "Connected peer %s to peer %s\n", | 3384 | "Connected peer %s to peer %s\n", |
3376 | ctx->d1->shortname, GNUNET_i2s(peer)); | 3385 | ctx->d1->shortname, GNUNET_i2s (peer)); |
3377 | #endif | 3386 | #endif |
3378 | 3387 | ||
3379 | if (0 == memcmp(&send_hello_context->peer->daemon->id, peer, sizeof(struct GNUNET_PeerIdentity))) | 3388 | if (0 == |
3389 | memcmp (&send_hello_context->peer->daemon->id, peer, | ||
3390 | sizeof (struct GNUNET_PeerIdentity))) | ||
3380 | return; | 3391 | return; |
3381 | 3392 | ||
3382 | connection = send_hello_context->peer->connect_peers_head; | 3393 | connection = send_hello_context->peer->connect_peers_head; |
3383 | #if BAD | 3394 | #if BAD |
3384 | other_peer = NULL; | 3395 | other_peer = NULL; |
3385 | #endif | 3396 | #endif |
3386 | 3397 | ||
3387 | while ((connection != NULL) && | 3398 | while ((connection != NULL) && |
3388 | (0 != memcmp(&pg->peers[connection->index].daemon->id, peer, sizeof(struct GNUNET_PeerIdentity)))) | 3399 | (0 != |
3389 | { | 3400 | memcmp (&pg->peers[connection->index].daemon->id, peer, |
3390 | connection = connection->next; | 3401 | sizeof (struct GNUNET_PeerIdentity)))) |
3391 | } | 3402 | { |
3403 | connection = connection->next; | ||
3404 | } | ||
3392 | 3405 | ||
3393 | if (connection == NULL) | 3406 | if (connection == NULL) |
3394 | { | 3407 | { |
3395 | 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); | 3408 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3396 | } | 3409 | "Connected peer %s to %s, not in list (no problem(?))\n", |
3397 | else | 3410 | GNUNET_i2s (peer), send_hello_context->peer->daemon->shortname); |
3398 | { | 3411 | } |
3412 | else | ||
3413 | { | ||
3399 | #if BAD | 3414 | #if BAD |
3400 | other_peer = &pg->peers[connection->index]; | 3415 | other_peer = &pg->peers[connection->index]; |
3401 | #endif | 3416 | #endif |
3402 | if (pg->notify_connection != NULL) | 3417 | if (pg->notify_connection != NULL) |
3403 | { | 3418 | { |
3404 | pg->notify_connection(pg->notify_connection_cls, | 3419 | pg->notify_connection (pg->notify_connection_cls, &send_hello_context->peer->daemon->id, peer, 0, /* FIXME */ |
3405 | &send_hello_context->peer->daemon->id, | 3420 | send_hello_context->peer->daemon->cfg, |
3406 | peer, | 3421 | pg->peers[connection->index].daemon->cfg, |
3407 | 0, /* FIXME */ | 3422 | send_hello_context->peer->daemon, |
3408 | send_hello_context->peer->daemon->cfg, | 3423 | pg->peers[connection->index].daemon, NULL); |
3409 | pg->peers[connection->index].daemon->cfg, | 3424 | } |
3410 | send_hello_context->peer->daemon, | 3425 | GNUNET_CONTAINER_DLL_remove (send_hello_context->peer->connect_peers_head, |
3411 | pg->peers[connection->index].daemon, | 3426 | send_hello_context->peer->connect_peers_tail, |
3412 | NULL); | 3427 | connection); |
3413 | } | 3428 | GNUNET_free (connection); |
3414 | GNUNET_CONTAINER_DLL_remove(send_hello_context->peer->connect_peers_head, send_hello_context->peer->connect_peers_tail, connection); | 3429 | } |
3415 | GNUNET_free(connection); | ||
3416 | } | ||
3417 | 3430 | ||
3418 | #if BAD | 3431 | #if BAD |
3419 | /* Notify of reverse connection and remove from other peers list of outstanding */ | 3432 | /* Notify of reverse connection and remove from other peers list of outstanding */ |
3420 | if (other_peer != NULL) | 3433 | if (other_peer != NULL) |
3434 | { | ||
3435 | connection = other_peer->connect_peers_head; | ||
3436 | while ((connection != NULL) && | ||
3437 | (0 != | ||
3438 | memcmp (&send_hello_context->peer->daemon->id, | ||
3439 | &pg->peers[connection->index].daemon->id, | ||
3440 | sizeof (struct GNUNET_PeerIdentity)))) | ||
3441 | { | ||
3442 | connection = connection->next; | ||
3443 | } | ||
3444 | if (connection != NULL) | ||
3445 | { | ||
3446 | if (pg->notify_connection != NULL) | ||
3421 | { | 3447 | { |
3422 | connection = other_peer->connect_peers_head; | 3448 | pg->notify_connection (pg->notify_connection_cls, peer, &send_hello_context->peer->daemon->id, 0, /* FIXME */ |
3423 | while ((connection != NULL) && | 3449 | pg->peers[connection->index].daemon->cfg, |
3424 | (0 != memcmp(&send_hello_context->peer->daemon->id, &pg->peers[connection->index].daemon->id, sizeof(struct GNUNET_PeerIdentity)))) | 3450 | send_hello_context->peer->daemon->cfg, |
3425 | { | 3451 | pg->peers[connection->index].daemon, |
3426 | connection = connection->next; | 3452 | send_hello_context->peer->daemon, NULL); |
3427 | } | ||
3428 | if (connection != NULL) | ||
3429 | { | ||
3430 | if (pg->notify_connection != NULL) | ||
3431 | { | ||
3432 | pg->notify_connection(pg->notify_connection_cls, | ||
3433 | peer, | ||
3434 | &send_hello_context->peer->daemon->id, | ||
3435 | 0, /* FIXME */ | ||
3436 | pg->peers[connection->index].daemon->cfg, | ||
3437 | send_hello_context->peer->daemon->cfg, | ||
3438 | pg->peers[connection->index].daemon, | ||
3439 | send_hello_context->peer->daemon, | ||
3440 | NULL); | ||
3441 | } | ||
3442 | |||
3443 | GNUNET_CONTAINER_DLL_remove(other_peer->connect_peers_head, other_peer->connect_peers_tail, connection); | ||
3444 | GNUNET_free(connection); | ||
3445 | } | ||
3446 | } | 3453 | } |
3454 | |||
3455 | GNUNET_CONTAINER_DLL_remove (other_peer->connect_peers_head, | ||
3456 | other_peer->connect_peers_tail, connection); | ||
3457 | GNUNET_free (connection); | ||
3458 | } | ||
3459 | } | ||
3447 | #endif | 3460 | #endif |
3448 | 3461 | ||
3449 | if (send_hello_context->peer->connect_peers_head == NULL) | 3462 | if (send_hello_context->peer->connect_peers_head == NULL) |
3450 | { | 3463 | { |
3451 | GNUNET_SCHEDULER_add_now(&free_hello_context, send_hello_context); | 3464 | GNUNET_SCHEDULER_add_now (&free_hello_context, send_hello_context); |
3452 | } | ||
3453 | } | 3465 | } |
3466 | } | ||
3454 | 3467 | ||
3455 | /** | 3468 | /** |
3456 | * Notify of a successful connection to the core service. | 3469 | * Notify of a successful connection to the core service. |
@@ -3462,16 +3475,14 @@ core_connect_notify (void *cls, | |||
3462 | */ | 3475 | */ |
3463 | void | 3476 | void |
3464 | core_init (void *cls, | 3477 | core_init (void *cls, |
3465 | struct GNUNET_CORE_Handle * server, | 3478 | struct GNUNET_CORE_Handle *server, |
3466 | const struct GNUNET_PeerIdentity * | 3479 | const struct GNUNET_PeerIdentity *my_identity, |
3467 | my_identity, | 3480 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
3468 | const struct | 3481 | { |
3469 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | 3482 | struct SendHelloContext *send_hello_context = cls; |
3470 | publicKey) | 3483 | |
3471 | { | 3484 | send_hello_context->core_ready = GNUNET_YES; |
3472 | struct SendHelloContext *send_hello_context = cls; | 3485 | } |
3473 | send_hello_context->core_ready = GNUNET_YES; | ||
3474 | } | ||
3475 | 3486 | ||
3476 | /** | 3487 | /** |
3477 | * Function called once a hello has been sent | 3488 | * Function called once a hello has been sent |
@@ -3483,55 +3494,58 @@ core_init (void *cls, | |||
3483 | */ | 3494 | */ |
3484 | static void | 3495 | static void |
3485 | hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3496 | hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3497 | { | ||
3498 | struct SendHelloContext *send_hello_context = cls; | ||
3499 | |||
3500 | //unsigned int pg_iter; | ||
3501 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
3486 | { | 3502 | { |
3487 | struct SendHelloContext *send_hello_context = cls; | 3503 | GNUNET_free (send_hello_context); |
3488 | //unsigned int pg_iter; | 3504 | return; |
3489 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 3505 | } |
3490 | { | ||
3491 | GNUNET_free(send_hello_context); | ||
3492 | return; | ||
3493 | } | ||
3494 | 3506 | ||
3495 | send_hello_context->pg->remaining_hellos--; | 3507 | send_hello_context->pg->remaining_hellos--; |
3496 | #if DEBUG_TESTING | 3508 | #if DEBUG_TESTING |
3497 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sent HELLO, have %d remaining!\n", send_hello_context->pg->remaining_hellos); | 3509 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Sent HELLO, have %d remaining!\n", |
3510 | send_hello_context->pg->remaining_hellos); | ||
3498 | #endif | 3511 | #endif |
3499 | if (send_hello_context->peer_pos == NULL) /* All HELLOs (for this peer!) have been transmitted! */ | 3512 | if (send_hello_context->peer_pos == NULL) /* All HELLOs (for this peer!) have been transmitted! */ |
3500 | { | 3513 | { |
3501 | #if DEBUG_TESTING | 3514 | #if DEBUG_TESTING |
3502 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All hellos for this peer sent, disconnecting transport!\n"); | 3515 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3503 | #endif | 3516 | "All hellos for this peer sent, disconnecting transport!\n"); |
3504 | GNUNET_assert(send_hello_context->peer->daemon->th != NULL); | 3517 | #endif |
3505 | GNUNET_TRANSPORT_disconnect(send_hello_context->peer->daemon->th); | 3518 | GNUNET_assert (send_hello_context->peer->daemon->th != NULL); |
3506 | send_hello_context->peer->daemon->th = NULL; | 3519 | GNUNET_TRANSPORT_disconnect (send_hello_context->peer->daemon->th); |
3507 | 3520 | send_hello_context->peer->daemon->th = NULL; | |
3508 | /*if (send_hello_context->pg->remaining_hellos == 0) | 3521 | |
3509 | { | 3522 | /*if (send_hello_context->pg->remaining_hellos == 0) |
3510 | for (pg_iter = 0; pg_iter < send_hello_context->pg->max_outstanding_connections; pg_iter++) | 3523 | * { |
3511 | { | 3524 | * for (pg_iter = 0; pg_iter < send_hello_context->pg->max_outstanding_connections; pg_iter++) |
3512 | preschedule_connect(&send_hello_context->pg->ct_ctx); | 3525 | * { |
3513 | } | 3526 | * preschedule_connect(&send_hello_context->pg->ct_ctx); |
3514 | } | 3527 | * } |
3515 | */ | 3528 | * } |
3516 | GNUNET_assert (send_hello_context->peer->daemon->server == NULL); | 3529 | */ |
3517 | send_hello_context->peer->daemon->server = GNUNET_CORE_connect(send_hello_context->peer->cfg, | 3530 | GNUNET_assert (send_hello_context->peer->daemon->server == NULL); |
3518 | 1, | 3531 | send_hello_context->peer->daemon->server = |
3519 | send_hello_context, | 3532 | GNUNET_CORE_connect (send_hello_context->peer->cfg, 1, |
3520 | &core_init, | 3533 | send_hello_context, &core_init, |
3521 | &core_connect_notify, | 3534 | &core_connect_notify, NULL, NULL, NULL, GNUNET_NO, |
3522 | NULL, | 3535 | NULL, GNUNET_NO, no_handlers); |
3523 | NULL, | 3536 | |
3524 | NULL, GNUNET_NO, | 3537 | send_hello_context->core_connect_task = |
3525 | NULL, GNUNET_NO, | 3538 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide |
3526 | no_handlers); | 3539 | (send_hello_context->pg-> |
3527 | 3540 | ct_ctx.connect_timeout, | |
3528 | 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), | 3541 | send_hello_context->pg-> |
3529 | &send_core_connect_requests, | 3542 | ct_ctx.connect_attempts), |
3530 | send_hello_context); | 3543 | &send_core_connect_requests, |
3531 | } | 3544 | send_hello_context); |
3532 | else | ||
3533 | GNUNET_SCHEDULER_add_now(&schedule_send_hellos, send_hello_context); | ||
3534 | } | 3545 | } |
3546 | else | ||
3547 | GNUNET_SCHEDULER_add_now (&schedule_send_hellos, send_hello_context); | ||
3548 | } | ||
3535 | 3549 | ||
3536 | /** | 3550 | /** |
3537 | * Connect to a peer, give it all the HELLO's of those peers | 3551 | * Connect to a peer, give it all the HELLO's of those peers |
@@ -3539,59 +3553,63 @@ hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3539 | * | 3553 | * |
3540 | * @param ct_ctx the overall connection context | 3554 | * @param ct_ctx the overall connection context |
3541 | */ | 3555 | */ |
3542 | static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3556 | static void |
3543 | { | 3557 | schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3544 | struct SendHelloContext *send_hello_context = cls; | 3558 | { |
3545 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | 3559 | struct SendHelloContext *send_hello_context = cls; |
3560 | struct GNUNET_TESTING_PeerGroup *pg = send_hello_context->pg; | ||
3546 | 3561 | ||
3547 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 3562 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
3548 | { | 3563 | { |
3549 | GNUNET_free(send_hello_context); | 3564 | GNUNET_free (send_hello_context); |
3550 | return; | 3565 | return; |
3551 | } | 3566 | } |
3552 | 3567 | ||
3553 | GNUNET_assert(send_hello_context->peer_pos != NULL); /* All of the HELLO sends to be scheduled have been scheduled! */ | 3568 | GNUNET_assert (send_hello_context->peer_pos != NULL); /* All of the HELLO sends to be scheduled have been scheduled! */ |
3554 | 3569 | ||
3555 | if (((send_hello_context->peer->daemon->th == NULL) && | 3570 | if (((send_hello_context->peer->daemon->th == NULL) && |
3556 | (pg->outstanding_connects > pg->max_outstanding_connections)) || | 3571 | (pg->outstanding_connects > pg->max_outstanding_connections)) || |
3557 | (pg->stop_connects == GNUNET_YES)) | 3572 | (pg->stop_connects == GNUNET_YES)) |
3558 | { | 3573 | { |
3559 | #if VERBOSE_TESTING > 2 | 3574 | #if VERBOSE_TESTING > 2 |
3560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3561 | _ | 3576 | _ |
3562 | ("Delaying connect, we have too many outstanding connections!\n")); | 3577 | ("Delaying connect, we have too many outstanding connections!\n")); |
3563 | #endif | 3578 | #endif |
3564 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 3579 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
3565 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), | 3580 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
3566 | &schedule_send_hellos, send_hello_context); | 3581 | &schedule_send_hellos, send_hello_context); |
3567 | } | 3582 | } |
3568 | else | 3583 | else |
3569 | { | 3584 | { |
3570 | #if VERBOSE_TESTING > 2 | 3585 | #if VERBOSE_TESTING > 2 |
3571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3572 | _("Creating connection, outstanding_connections is %d\n"), | 3587 | _("Creating connection, outstanding_connections is %d\n"), |
3573 | outstanding_connects); | 3588 | outstanding_connects); |
3574 | #endif | 3589 | #endif |
3575 | if (send_hello_context->peer->daemon->th == NULL) | 3590 | if (send_hello_context->peer->daemon->th == NULL) |
3576 | { | 3591 | { |
3577 | pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */ | 3592 | pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */ |
3578 | send_hello_context->peer->daemon->th | 3593 | send_hello_context->peer->daemon->th |
3579 | = GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL, | 3594 | = GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL, |
3580 | send_hello_context, NULL, NULL, NULL); | 3595 | send_hello_context, NULL, NULL, NULL); |
3581 | } | 3596 | } |
3582 | #if DEBUG_TESTING | 3597 | #if DEBUG_TESTING |
3583 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3598 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3584 | _("Offering Hello of peer %s to peer %s\n"), | 3599 | _("Offering Hello of peer %s to peer %s\n"), |
3585 | send_hello_context->peer->daemon->shortname, pg->peers[send_hello_context->peer_pos->index].daemon->shortname); | 3600 | send_hello_context->peer->daemon->shortname, |
3586 | #endif | 3601 | pg->peers[send_hello_context->peer_pos->index]. |
3587 | GNUNET_TRANSPORT_offer_hello(send_hello_context->peer->daemon->th, | 3602 | daemon->shortname); |
3588 | (const struct GNUNET_MessageHeader *)pg->peers[send_hello_context->peer_pos->index].daemon->hello, | 3603 | #endif |
3589 | &hello_sent_callback, | 3604 | GNUNET_TRANSPORT_offer_hello (send_hello_context->peer->daemon->th, |
3590 | send_hello_context); | 3605 | (const struct GNUNET_MessageHeader *) |
3591 | send_hello_context->peer_pos = send_hello_context->peer_pos->next; | 3606 | pg->peers[send_hello_context->peer_pos-> |
3592 | GNUNET_assert(send_hello_context->peer->daemon->th != NULL); | 3607 | index].daemon->hello, |
3593 | } | 3608 | &hello_sent_callback, send_hello_context); |
3609 | send_hello_context->peer_pos = send_hello_context->peer_pos->next; | ||
3610 | GNUNET_assert (send_hello_context->peer->daemon->th != NULL); | ||
3594 | } | 3611 | } |
3612 | } | ||
3595 | #endif | 3613 | #endif |
3596 | 3614 | ||
3597 | /** | 3615 | /** |
@@ -3599,14 +3617,14 @@ static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskC | |||
3599 | * happen instead of flooding all testing daemons with requests to connect. | 3617 | * happen instead of flooding all testing daemons with requests to connect. |
3600 | */ | 3618 | */ |
3601 | static void | 3619 | static void |
3602 | internal_connect_notify(void *cls, const struct GNUNET_PeerIdentity *first, | 3620 | internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first, |
3603 | const struct GNUNET_PeerIdentity *second, | 3621 | const struct GNUNET_PeerIdentity *second, |
3604 | uint32_t distance, | 3622 | uint32_t distance, |
3605 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, | 3623 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, |
3606 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, | 3624 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, |
3607 | struct GNUNET_TESTING_Daemon *first_daemon, | 3625 | struct GNUNET_TESTING_Daemon *first_daemon, |
3608 | struct GNUNET_TESTING_Daemon *second_daemon, | 3626 | struct GNUNET_TESTING_Daemon *second_daemon, |
3609 | const char *emsg) | 3627 | const char *emsg) |
3610 | { | 3628 | { |
3611 | struct ConnectContext *connect_ctx = cls; | 3629 | struct ConnectContext *connect_ctx = cls; |
3612 | struct ConnectTopologyContext *ct_ctx = connect_ctx->ct_ctx; | 3630 | struct ConnectTopologyContext *ct_ctx = connect_ctx->ct_ctx; |
@@ -3627,33 +3645,41 @@ internal_connect_notify(void *cls, const struct GNUNET_PeerIdentity *first, | |||
3627 | #endif | 3645 | #endif |
3628 | 3646 | ||
3629 | while ((connection != NULL) && (0 | 3647 | while ((connection != NULL) && (0 |
3630 | != memcmp (first, &pg->peers[connection->index].daemon->id, | 3648 | != memcmp (first, |
3631 | sizeof(struct GNUNET_PeerIdentity)))) | 3649 | &pg->peers[connection-> |
3632 | { | 3650 | index].daemon->id, |
3633 | connection = connection->next; | 3651 | sizeof (struct |
3634 | } | 3652 | GNUNET_PeerIdentity)))) |
3653 | { | ||
3654 | connection = connection->next; | ||
3655 | } | ||
3635 | 3656 | ||
3636 | if (connection != NULL) /* Can safely remove! */ | 3657 | if (connection != NULL) /* Can safely remove! */ |
3637 | { | 3658 | { |
3638 | GNUNET_assert (0 < ct_ctx->remaining_connections); | 3659 | GNUNET_assert (0 < ct_ctx->remaining_connections); |
3639 | ct_ctx->remaining_connections--; | 3660 | ct_ctx->remaining_connections--; |
3640 | if (pg->notify_connection != NULL) /* Notify of reverse connection */ | 3661 | if (pg->notify_connection != NULL) /* Notify of reverse connection */ |
3641 | pg->notify_connection (pg->notify_connection_cls, second, first, | 3662 | pg->notify_connection (pg->notify_connection_cls, second, first, |
3642 | distance, second_cfg, first_cfg, second_daemon, | 3663 | distance, second_cfg, first_cfg, second_daemon, |
3643 | first_daemon, emsg); | 3664 | first_daemon, emsg); |
3644 | 3665 | ||
3645 | GNUNET_CONTAINER_DLL_remove(pg->peers[connect_ctx->second_index].connect_peers_head, pg->peers[connect_ctx->second_index].connect_peers_tail, connection); | 3666 | GNUNET_CONTAINER_DLL_remove (pg-> |
3646 | GNUNET_free(connection); | 3667 | peers[connect_ctx-> |
3647 | } | 3668 | second_index].connect_peers_head, |
3669 | pg->peers[connect_ctx-> | ||
3670 | second_index].connect_peers_tail, | ||
3671 | connection); | ||
3672 | GNUNET_free (connection); | ||
3673 | } | ||
3648 | 3674 | ||
3649 | if (ct_ctx->remaining_connections == 0) | 3675 | if (ct_ctx->remaining_connections == 0) |
3676 | { | ||
3677 | if (ct_ctx->notify_connections_done != NULL) | ||
3650 | { | 3678 | { |
3651 | if (ct_ctx->notify_connections_done != NULL) | 3679 | ct_ctx->notify_connections_done (ct_ctx->notify_cls, NULL); |
3652 | { | 3680 | ct_ctx->notify_connections_done = NULL; |
3653 | ct_ctx->notify_connections_done (ct_ctx->notify_cls, NULL); | ||
3654 | ct_ctx->notify_connections_done = NULL; | ||
3655 | } | ||
3656 | } | 3681 | } |
3682 | } | ||
3657 | else | 3683 | else |
3658 | preschedule_connect (pg); | 3684 | preschedule_connect (pg); |
3659 | 3685 | ||
@@ -3662,7 +3688,7 @@ internal_connect_notify(void *cls, const struct GNUNET_PeerIdentity *first, | |||
3662 | first_cfg, second_cfg, first_daemon, second_daemon, | 3688 | first_cfg, second_cfg, first_daemon, second_daemon, |
3663 | emsg); | 3689 | emsg); |
3664 | 3690 | ||
3665 | GNUNET_free(connect_ctx); | 3691 | GNUNET_free (connect_ctx); |
3666 | } | 3692 | } |
3667 | 3693 | ||
3668 | /** | 3694 | /** |
@@ -3673,49 +3699,49 @@ internal_connect_notify(void *cls, const struct GNUNET_PeerIdentity *first, | |||
3673 | * @param tc the task runtime context | 3699 | * @param tc the task runtime context |
3674 | */ | 3700 | */ |
3675 | static void | 3701 | static void |
3676 | schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3702 | schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
3677 | { | 3703 | { |
3678 | struct ConnectContext *connect_context = cls; | 3704 | struct ConnectContext *connect_context = cls; |
3679 | struct GNUNET_TESTING_PeerGroup *pg = connect_context->ct_ctx->pg; | 3705 | struct GNUNET_TESTING_PeerGroup *pg = connect_context->ct_ctx->pg; |
3680 | 3706 | ||
3681 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 3707 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
3682 | return; | 3708 | return; |
3683 | 3709 | ||
3684 | if ((pg->outstanding_connects > pg->max_outstanding_connections) | 3710 | if ((pg->outstanding_connects > pg->max_outstanding_connections) |
3685 | || (pg->stop_connects == GNUNET_YES)) | 3711 | || (pg->stop_connects == GNUNET_YES)) |
3686 | { | 3712 | { |
3687 | #if VERBOSE_TESTING | 3713 | #if VERBOSE_TESTING |
3688 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3714 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3689 | _ | 3715 | _ |
3690 | ("Delaying connect, we have too many outstanding connections!\n")); | 3716 | ("Delaying connect, we have too many outstanding connections!\n")); |
3691 | #endif | 3717 | #endif |
3692 | GNUNET_SCHEDULER_add_delayed ( | 3718 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
3693 | GNUNET_TIME_relative_multiply ( | 3719 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
3694 | GNUNET_TIME_UNIT_MILLISECONDS, | 3720 | &schedule_connect, connect_context); |
3695 | 100), | 3721 | } |
3696 | &schedule_connect, connect_context); | ||
3697 | } | ||
3698 | else | 3722 | else |
3699 | { | 3723 | { |
3700 | #if VERBOSE_TESTING | 3724 | #if VERBOSE_TESTING |
3701 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3725 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3702 | _("Creating connection, outstanding_connections is %d (max %d)\n"), | 3726 | _ |
3703 | pg->outstanding_connects, pg->max_outstanding_connections); | 3727 | ("Creating connection, outstanding_connections is %d (max %d)\n"), |
3704 | #endif | 3728 | pg->outstanding_connects, pg->max_outstanding_connections); |
3705 | pg->outstanding_connects++; | 3729 | #endif |
3706 | pg->total_connects_scheduled++; | 3730 | pg->outstanding_connects++; |
3707 | GNUNET_TESTING_daemons_connect ( | 3731 | pg->total_connects_scheduled++; |
3708 | pg->peers[connect_context->first_index].daemon, | 3732 | GNUNET_TESTING_daemons_connect (pg-> |
3709 | pg->peers[connect_context->second_index].daemon, | 3733 | peers[connect_context->first_index].daemon, |
3710 | connect_context->ct_ctx->connect_timeout, | 3734 | pg->peers[connect_context-> |
3711 | connect_context->ct_ctx->connect_attempts, | 3735 | second_index].daemon, |
3736 | connect_context->ct_ctx->connect_timeout, | ||
3737 | connect_context->ct_ctx->connect_attempts, | ||
3712 | #if USE_SEND_HELLOS | 3738 | #if USE_SEND_HELLOS |
3713 | GNUNET_NO, | 3739 | GNUNET_NO, |
3714 | #else | 3740 | #else |
3715 | GNUNET_YES, | 3741 | GNUNET_YES, |
3716 | #endif | 3742 | #endif |
3717 | &internal_connect_notify, connect_context); /* FIXME: free connect context! */ | 3743 | &internal_connect_notify, connect_context); /* FIXME: free connect context! */ |
3718 | } | 3744 | } |
3719 | } | 3745 | } |
3720 | 3746 | ||
3721 | #if !OLD | 3747 | #if !OLD |
@@ -3731,20 +3757,20 @@ schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3731 | */ | 3757 | */ |
3732 | static int | 3758 | static int |
3733 | connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 3759 | connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
3734 | { | 3760 | { |
3735 | struct ConnectTopologyContext *ct_ctx = cls; | 3761 | struct ConnectTopologyContext *ct_ctx = cls; |
3736 | struct PeerData *first = ct_ctx->first; | 3762 | struct PeerData *first = ct_ctx->first; |
3737 | struct GNUNET_TESTING_Daemon *second = value; | 3763 | struct GNUNET_TESTING_Daemon *second = value; |
3738 | struct ConnectContext *connect_context; | 3764 | struct ConnectContext *connect_context; |
3739 | 3765 | ||
3740 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); | 3766 | connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); |
3741 | connect_context->first = first->daemon; | 3767 | connect_context->first = first->daemon; |
3742 | connect_context->second = second; | 3768 | connect_context->second = second; |
3743 | connect_context->ct_ctx = ct_ctx; | 3769 | connect_context->ct_ctx = ct_ctx; |
3744 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); | 3770 | GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); |
3745 | 3771 | ||
3746 | return GNUNET_YES; | 3772 | return GNUNET_YES; |
3747 | } | 3773 | } |
3748 | #endif | 3774 | #endif |
3749 | 3775 | ||
3750 | #if !OLD | 3776 | #if !OLD |
@@ -3760,16 +3786,16 @@ connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
3760 | */ | 3786 | */ |
3761 | static int | 3787 | static int |
3762 | copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 3788 | copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
3763 | { | 3789 | { |
3764 | struct PeerData *first = cls; | 3790 | struct PeerData *first = cls; |
3765 | 3791 | ||
3766 | GNUNET_assert (GNUNET_OK == | 3792 | GNUNET_assert (GNUNET_OK == |
3767 | GNUNET_CONTAINER_multihashmap_put (first->connect_peers, key, | 3793 | GNUNET_CONTAINER_multihashmap_put (first->connect_peers, key, |
3768 | value, | 3794 | value, |
3769 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3795 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
3770 | 3796 | ||
3771 | return GNUNET_YES; | 3797 | return GNUNET_YES; |
3772 | } | 3798 | } |
3773 | #endif | 3799 | #endif |
3774 | 3800 | ||
3775 | /** | 3801 | /** |
@@ -3779,42 +3805,41 @@ copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
3779 | * @param pg the peer group | 3805 | * @param pg the peer group |
3780 | */ | 3806 | */ |
3781 | static int | 3807 | static int |
3782 | copy_allowed_topology(struct GNUNET_TESTING_PeerGroup *pg) | 3808 | copy_allowed_topology (struct GNUNET_TESTING_PeerGroup *pg) |
3783 | { | 3809 | { |
3784 | unsigned int pg_iter; | 3810 | unsigned int pg_iter; |
3785 | int ret; | 3811 | int ret; |
3786 | int total; | 3812 | int total; |
3813 | |||
3787 | #if OLD | 3814 | #if OLD |
3788 | struct PeerConnection *iter; | 3815 | struct PeerConnection *iter; |
3789 | #endif | 3816 | #endif |
3790 | total = 0; | 3817 | total = 0; |
3791 | ret = 0; | 3818 | ret = 0; |
3792 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3819 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3793 | { | 3820 | { |
3794 | #if OLD | 3821 | #if OLD |
3795 | iter = pg->peers[pg_iter].allowed_peers_head; | 3822 | iter = pg->peers[pg_iter].allowed_peers_head; |
3796 | while (iter != NULL) | 3823 | while (iter != NULL) |
3797 | { | 3824 | { |
3798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3799 | "Creating connection between %d and %d\n", pg_iter, | 3826 | "Creating connection between %d and %d\n", pg_iter, |
3800 | iter->index); | 3827 | iter->index); |
3801 | total += add_connections (pg, pg_iter, iter->index, CONNECT, | 3828 | total += add_connections (pg, pg_iter, iter->index, CONNECT, GNUNET_YES); |
3802 | GNUNET_YES); | 3829 | //total += add_actual_connections(pg, pg_iter, iter->index); |
3803 | //total += add_actual_connections(pg, pg_iter, iter->index); | 3830 | iter = iter->next; |
3804 | iter = iter->next; | 3831 | } |
3805 | } | ||
3806 | #else | 3832 | #else |
3807 | ret = | 3833 | ret = |
3808 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | 3834 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, |
3809 | peers[pg_iter].allowed_peers, | 3835 | ©_topology_iterator, |
3810 | ©_topology_iterator, | 3836 | &pg->peers[pg_iter]); |
3811 | &pg->peers[pg_iter]); | ||
3812 | #endif | 3837 | #endif |
3813 | if (GNUNET_SYSERR == ret) | 3838 | if (GNUNET_SYSERR == ret) |
3814 | return GNUNET_SYSERR; | 3839 | return GNUNET_SYSERR; |
3815 | 3840 | ||
3816 | total = total + ret; | 3841 | total = total + ret; |
3817 | } | 3842 | } |
3818 | 3843 | ||
3819 | return total; | 3844 | return total; |
3820 | } | 3845 | } |
@@ -3832,11 +3857,11 @@ copy_allowed_topology(struct GNUNET_TESTING_PeerGroup *pg) | |||
3832 | * @return the number of connections that will be attempted | 3857 | * @return the number of connections that will be attempted |
3833 | */ | 3858 | */ |
3834 | static int | 3859 | static int |
3835 | connect_topology(struct GNUNET_TESTING_PeerGroup *pg, | 3860 | connect_topology (struct GNUNET_TESTING_PeerGroup *pg, |
3836 | struct GNUNET_TIME_Relative connect_timeout, | 3861 | struct GNUNET_TIME_Relative connect_timeout, |
3837 | unsigned int connect_attempts, | 3862 | unsigned int connect_attempts, |
3838 | GNUNET_TESTING_NotifyCompletion notify_callback, | 3863 | GNUNET_TESTING_NotifyCompletion notify_callback, |
3839 | void *notify_cls) | 3864 | void *notify_cls) |
3840 | { | 3865 | { |
3841 | unsigned int pg_iter; | 3866 | unsigned int pg_iter; |
3842 | unsigned int total; | 3867 | unsigned int total; |
@@ -3854,19 +3879,19 @@ connect_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3854 | pg->ct_ctx.pg = pg; | 3879 | pg->ct_ctx.pg = pg; |
3855 | 3880 | ||
3856 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3881 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3857 | { | 3882 | { |
3858 | #if OLD | 3883 | #if OLD |
3859 | connection_iter = pg->peers[pg_iter].connect_peers_head; | 3884 | connection_iter = pg->peers[pg_iter].connect_peers_head; |
3860 | while (connection_iter != NULL) | 3885 | while (connection_iter != NULL) |
3861 | { | 3886 | { |
3862 | connection_iter = connection_iter->next; | 3887 | connection_iter = connection_iter->next; |
3863 | total++; | 3888 | total++; |
3864 | } | 3889 | } |
3865 | #else | 3890 | #else |
3866 | total += | 3891 | total += |
3867 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); | 3892 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].connect_peers); |
3868 | #endif | 3893 | #endif |
3869 | } | 3894 | } |
3870 | 3895 | ||
3871 | if (total == 0) | 3896 | if (total == 0) |
3872 | return total; | 3897 | return total; |
@@ -3879,18 +3904,18 @@ connect_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3879 | /* First give all peers the HELLO's of other peers (connect to first peer's transport service, give HELLO's of other peers, continue...) */ | 3904 | /* First give all peers the HELLO's of other peers (connect to first peer's transport service, give HELLO's of other peers, continue...) */ |
3880 | pg->remaining_hellos = total; | 3905 | pg->remaining_hellos = total; |
3881 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 3906 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
3882 | { | 3907 | { |
3883 | send_hello_context = GNUNET_malloc(sizeof(struct SendHelloContext)); | 3908 | send_hello_context = GNUNET_malloc (sizeof (struct SendHelloContext)); |
3884 | send_hello_context->peer = &pg->peers[pg_iter]; | 3909 | send_hello_context->peer = &pg->peers[pg_iter]; |
3885 | send_hello_context->peer_pos = pg->peers[pg_iter].connect_peers_head; | 3910 | send_hello_context->peer_pos = pg->peers[pg_iter].connect_peers_head; |
3886 | send_hello_context->pg = pg; | 3911 | send_hello_context->pg = pg; |
3887 | GNUNET_SCHEDULER_add_now(&schedule_send_hellos, send_hello_context); | 3912 | GNUNET_SCHEDULER_add_now (&schedule_send_hellos, send_hello_context); |
3888 | } | 3913 | } |
3889 | #else | 3914 | #else |
3890 | for (pg_iter = 0; pg_iter < pg->max_outstanding_connections; pg_iter++) | 3915 | for (pg_iter = 0; pg_iter < pg->max_outstanding_connections; pg_iter++) |
3891 | { | 3916 | { |
3892 | preschedule_connect (pg); | 3917 | preschedule_connect (pg); |
3893 | } | 3918 | } |
3894 | #endif | 3919 | #endif |
3895 | return total; | 3920 | return total; |
3896 | 3921 | ||
@@ -3918,10 +3943,10 @@ connect_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3918 | * connected to each other | 3943 | * connected to each other |
3919 | */ | 3944 | */ |
3920 | unsigned int | 3945 | unsigned int |
3921 | GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | 3946 | GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, |
3922 | enum GNUNET_TESTING_Topology topology, | 3947 | enum GNUNET_TESTING_Topology topology, |
3923 | enum GNUNET_TESTING_Topology restrict_topology, | 3948 | enum GNUNET_TESTING_Topology restrict_topology, |
3924 | const char *restrict_transports) | 3949 | const char *restrict_transports) |
3925 | { | 3950 | { |
3926 | int ret; | 3951 | int ret; |
3927 | 3952 | ||
@@ -3934,20 +3959,18 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3934 | 3959 | ||
3935 | #if !OLD | 3960 | #if !OLD |
3936 | unsigned int i; | 3961 | unsigned int i; |
3962 | |||
3937 | for (i = 0; i < pg->total; i++) | 3963 | for (i = 0; i < pg->total; i++) |
3938 | { | 3964 | { |
3939 | pg->peers[i].allowed_peers = | 3965 | pg->peers[i].allowed_peers = GNUNET_CONTAINER_multihashmap_create (100); |
3940 | GNUNET_CONTAINER_multihashmap_create (100); | 3966 | pg->peers[i].connect_peers = GNUNET_CONTAINER_multihashmap_create (100); |
3941 | pg->peers[i].connect_peers = | 3967 | pg->peers[i].blacklisted_peers = GNUNET_CONTAINER_multihashmap_create (100); |
3942 | GNUNET_CONTAINER_multihashmap_create (100); | 3968 | pg->peers[i].pg = pg; |
3943 | pg->peers[i].blacklisted_peers = | 3969 | } |
3944 | GNUNET_CONTAINER_multihashmap_create (100); | ||
3945 | pg->peers[i].pg = pg; | ||
3946 | } | ||
3947 | #endif | 3970 | #endif |
3948 | 3971 | ||
3949 | switch (topology) | 3972 | switch (topology) |
3950 | { | 3973 | { |
3951 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 3974 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
3952 | #if VERBOSE_TESTING | 3975 | #if VERBOSE_TESTING |
3953 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n")); | 3976 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n")); |
@@ -3957,14 +3980,14 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3957 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 3980 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
3958 | #if VERBOSE_TESTING | 3981 | #if VERBOSE_TESTING |
3959 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3960 | _("Creating small world (ring) topology\n")); | 3983 | _("Creating small world (ring) topology\n")); |
3961 | #endif | 3984 | #endif |
3962 | num_connections = create_small_world_ring (pg, &add_connections, ALLOWED); | 3985 | num_connections = create_small_world_ring (pg, &add_connections, ALLOWED); |
3963 | break; | 3986 | break; |
3964 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 3987 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
3965 | #if VERBOSE_TESTING | 3988 | #if VERBOSE_TESTING |
3966 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3989 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3967 | _("Creating small world (2d-torus) topology\n")); | 3990 | _("Creating small world (2d-torus) topology\n")); |
3968 | #endif | 3991 | #endif |
3969 | num_connections = create_small_world (pg, &add_connections, ALLOWED); | 3992 | num_connections = create_small_world (pg, &add_connections, ALLOWED); |
3970 | break; | 3993 | break; |
@@ -3982,8 +4005,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3982 | break; | 4005 | break; |
3983 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 4006 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
3984 | #if VERBOSE_TESTING | 4007 | #if VERBOSE_TESTING |
3985 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4008 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating Erdos-Renyi topology\n")); |
3986 | _("Creating Erdos-Renyi topology\n")); | ||
3987 | #endif | 4009 | #endif |
3988 | num_connections = create_erdos_renyi (pg, &add_connections, ALLOWED); | 4010 | num_connections = create_erdos_renyi (pg, &add_connections, ALLOWED); |
3989 | break; | 4011 | break; |
@@ -3995,22 +4017,20 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
3995 | break; | 4017 | break; |
3996 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 4018 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
3997 | #if VERBOSE_TESTING | 4019 | #if VERBOSE_TESTING |
3998 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating Scale Free topology\n")); |
3999 | _("Creating Scale Free topology\n")); | ||
4000 | #endif | 4021 | #endif |
4001 | num_connections = create_scale_free (pg, &add_connections, ALLOWED); | 4022 | num_connections = create_scale_free (pg, &add_connections, ALLOWED); |
4002 | break; | 4023 | break; |
4003 | case GNUNET_TESTING_TOPOLOGY_LINE: | 4024 | case GNUNET_TESTING_TOPOLOGY_LINE: |
4004 | #if VERBOSE_TESTING | 4025 | #if VERBOSE_TESTING |
4005 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4006 | _("Creating straight line topology\n")); | 4027 | _("Creating straight line topology\n")); |
4007 | #endif | 4028 | #endif |
4008 | num_connections = create_line (pg, &add_connections, ALLOWED); | 4029 | num_connections = create_line (pg, &add_connections, ALLOWED); |
4009 | break; | 4030 | break; |
4010 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: | 4031 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: |
4011 | #if VERBOSE_TESTING | 4032 | #if VERBOSE_TESTING |
4012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4033 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating topology from file!\n")); |
4013 | _("Creating topology from file!\n")); | ||
4014 | #endif | 4034 | #endif |
4015 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing", | 4035 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing", |
4016 | "topology_file", | 4036 | "topology_file", |
@@ -4018,50 +4038,50 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4018 | num_connections = create_from_file (pg, filename, &add_connections, | 4038 | num_connections = create_from_file (pg, filename, &add_connections, |
4019 | ALLOWED); | 4039 | ALLOWED); |
4020 | else | 4040 | else |
4021 | { | 4041 | { |
4022 | GNUNET_log ( | 4042 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4023 | GNUNET_ERROR_TYPE_WARNING, | 4043 | "Missing configuration option TESTING:TOPOLOGY_FILE for creating topology from file!\n"); |
4024 | "Missing configuration option TESTING:TOPOLOGY_FILE for creating topology from file!\n"); | 4044 | num_connections = 0; |
4025 | num_connections = 0; | 4045 | } |
4026 | } | ||
4027 | break; | 4046 | break; |
4028 | case GNUNET_TESTING_TOPOLOGY_NONE: | 4047 | case GNUNET_TESTING_TOPOLOGY_NONE: |
4029 | #if VERBOSE_TESTING | 4048 | #if VERBOSE_TESTING |
4030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4049 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4031 | _ | 4050 | _ |
4032 | ("Creating no allowed topology (all peers can connect at core level)\n")); | 4051 | ("Creating no allowed topology (all peers can connect at core level)\n")); |
4033 | #endif | 4052 | #endif |
4034 | num_connections = pg->total * pg->total; /* Clique is allowed! */ | 4053 | num_connections = pg->total * pg->total; /* Clique is allowed! */ |
4035 | break; | 4054 | break; |
4036 | default: | 4055 | default: |
4037 | num_connections = 0; | 4056 | num_connections = 0; |
4038 | break; | 4057 | break; |
4039 | } | 4058 | } |
4040 | 4059 | ||
4041 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", | 4060 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", |
4042 | "F2F")) | 4061 | "F2F")) |
4062 | { | ||
4063 | ret = create_and_copy_friend_files (pg); | ||
4064 | if (ret != GNUNET_OK) | ||
4043 | { | 4065 | { |
4044 | ret = create_and_copy_friend_files (pg); | ||
4045 | if (ret != GNUNET_OK) | ||
4046 | { | ||
4047 | #if VERBOSE_TESTING | 4066 | #if VERBOSE_TESTING |
4048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4067 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4049 | _("Failed during friend file copying!\n")); | 4068 | _("Failed during friend file copying!\n")); |
4050 | #endif | 4069 | #endif |
4051 | return GNUNET_SYSERR; | 4070 | return GNUNET_SYSERR; |
4052 | } | 4071 | } |
4053 | else | 4072 | else |
4054 | { | 4073 | { |
4055 | #if VERBOSE_TESTING | 4074 | #if VERBOSE_TESTING |
4056 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4057 | _("Friend files created/copied successfully!\n")); | 4076 | _("Friend files created/copied successfully!\n")); |
4058 | #endif | 4077 | #endif |
4059 | } | ||
4060 | } | 4078 | } |
4079 | } | ||
4061 | 4080 | ||
4062 | /* Use the create clique method to initially set all connections as blacklisted. */ | 4081 | /* Use the create clique method to initially set all connections as blacklisted. */ |
4063 | if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology | 4082 | if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology |
4064 | != GNUNET_TESTING_TOPOLOGY_FROM_FILE)) | 4083 | != |
4084 | GNUNET_TESTING_TOPOLOGY_FROM_FILE)) | ||
4065 | create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO); | 4085 | create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO); |
4066 | else | 4086 | else |
4067 | return num_connections; | 4087 | return num_connections; |
@@ -4069,11 +4089,11 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4069 | unblacklisted_connections = 0; | 4089 | unblacklisted_connections = 0; |
4070 | /* Un-blacklist connections as per the topology specified */ | 4090 | /* Un-blacklist connections as per the topology specified */ |
4071 | switch (restrict_topology) | 4091 | switch (restrict_topology) |
4072 | { | 4092 | { |
4073 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 4093 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
4074 | #if VERBOSE_TESTING | 4094 | #if VERBOSE_TESTING |
4075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4076 | _("Blacklisting all but clique topology\n")); | 4096 | _("Blacklisting all but clique topology\n")); |
4077 | #endif | 4097 | #endif |
4078 | unblacklisted_connections = create_clique (pg, &remove_connections, | 4098 | unblacklisted_connections = create_clique (pg, &remove_connections, |
4079 | BLACKLIST, GNUNET_NO); | 4099 | BLACKLIST, GNUNET_NO); |
@@ -4081,7 +4101,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4081 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 4101 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
4082 | #if VERBOSE_TESTING | 4102 | #if VERBOSE_TESTING |
4083 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4084 | _("Blacklisting all but small world (ring) topology\n")); | 4104 | _("Blacklisting all but small world (ring) topology\n")); |
4085 | #endif | 4105 | #endif |
4086 | unblacklisted_connections = create_small_world_ring (pg, | 4106 | unblacklisted_connections = create_small_world_ring (pg, |
4087 | &remove_connections, | 4107 | &remove_connections, |
@@ -4090,8 +4110,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4090 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 4110 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
4091 | #if VERBOSE_TESTING | 4111 | #if VERBOSE_TESTING |
4092 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4093 | _ | 4113 | _("Blacklisting all but small world (2d-torus) topology\n")); |
4094 | ("Blacklisting all but small world (2d-torus) topology\n")); | ||
4095 | #endif | 4114 | #endif |
4096 | unblacklisted_connections = create_small_world (pg, &remove_connections, | 4115 | unblacklisted_connections = create_small_world (pg, &remove_connections, |
4097 | BLACKLIST); | 4116 | BLACKLIST); |
@@ -4099,7 +4118,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4099 | case GNUNET_TESTING_TOPOLOGY_RING: | 4118 | case GNUNET_TESTING_TOPOLOGY_RING: |
4100 | #if VERBOSE_TESTING | 4119 | #if VERBOSE_TESTING |
4101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4102 | _("Blacklisting all but ring topology\n")); | 4121 | _("Blacklisting all but ring topology\n")); |
4103 | #endif | 4122 | #endif |
4104 | unblacklisted_connections | 4123 | unblacklisted_connections |
4105 | = create_ring (pg, &remove_connections, BLACKLIST); | 4124 | = create_ring (pg, &remove_connections, BLACKLIST); |
@@ -4107,7 +4126,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4107 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 4126 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: |
4108 | #if VERBOSE_TESTING | 4127 | #if VERBOSE_TESTING |
4109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4110 | _("Blacklisting all but 2d torus topology\n")); | 4129 | _("Blacklisting all but 2d torus topology\n")); |
4111 | #endif | 4130 | #endif |
4112 | unblacklisted_connections = create_2d_torus (pg, &remove_connections, | 4131 | unblacklisted_connections = create_2d_torus (pg, &remove_connections, |
4113 | BLACKLIST); | 4132 | BLACKLIST); |
@@ -4115,7 +4134,7 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4115 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 4134 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
4116 | #if VERBOSE_TESTING | 4135 | #if VERBOSE_TESTING |
4117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4118 | _("Blacklisting all but Erdos-Renyi topology\n")); | 4137 | _("Blacklisting all but Erdos-Renyi topology\n")); |
4119 | #endif | 4138 | #endif |
4120 | unblacklisted_connections = create_erdos_renyi (pg, &remove_connections, | 4139 | unblacklisted_connections = create_erdos_renyi (pg, &remove_connections, |
4121 | BLACKLIST); | 4140 | BLACKLIST); |
@@ -4123,44 +4142,44 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4123 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 4142 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
4124 | #if VERBOSE_TESTING | 4143 | #if VERBOSE_TESTING |
4125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4126 | _("Blacklisting all but InterNAT topology\n")); | 4145 | _("Blacklisting all but InterNAT topology\n")); |
4127 | #endif | 4146 | #endif |
4128 | 4147 | ||
4129 | #if TOPOLOGY_HACK | 4148 | #if TOPOLOGY_HACK |
4130 | for (off = 0; off < pg->total; off++) | 4149 | for (off = 0; off < pg->total; off++) |
4150 | { | ||
4151 | conn_iter = pg->peers[off].allowed_peers_head; | ||
4152 | while (conn_iter != NULL) | ||
4131 | { | 4153 | { |
4132 | conn_iter = pg->peers[off].allowed_peers_head; | 4154 | temp_conn = conn_iter->next; |
4133 | while (conn_iter != NULL) | 4155 | GNUNET_free (conn_iter); |
4134 | { | 4156 | conn_iter = temp_conn; |
4135 | temp_conn = conn_iter->next; | ||
4136 | GNUNET_free(conn_iter); | ||
4137 | conn_iter = temp_conn; | ||
4138 | } | ||
4139 | pg->peers[off].allowed_peers_head = NULL; | ||
4140 | pg->peers[off].allowed_peers_tail = NULL; | ||
4141 | |||
4142 | conn_iter = pg->peers[off].connect_peers_head; | ||
4143 | while (conn_iter != NULL) | ||
4144 | { | ||
4145 | temp_conn = conn_iter->next; | ||
4146 | GNUNET_free(conn_iter); | ||
4147 | conn_iter = temp_conn; | ||
4148 | } | ||
4149 | pg->peers[off].connect_peers_head = NULL; | ||
4150 | pg->peers[off].connect_peers_tail = NULL; | ||
4151 | } | 4157 | } |
4158 | pg->peers[off].allowed_peers_head = NULL; | ||
4159 | pg->peers[off].allowed_peers_tail = NULL; | ||
4160 | |||
4161 | conn_iter = pg->peers[off].connect_peers_head; | ||
4162 | while (conn_iter != NULL) | ||
4163 | { | ||
4164 | temp_conn = conn_iter->next; | ||
4165 | GNUNET_free (conn_iter); | ||
4166 | conn_iter = temp_conn; | ||
4167 | } | ||
4168 | pg->peers[off].connect_peers_head = NULL; | ||
4169 | pg->peers[off].connect_peers_tail = NULL; | ||
4170 | } | ||
4152 | unblacklisted_connections | 4171 | unblacklisted_connections |
4153 | = create_nated_internet_copy (pg, &remove_connections, BLACKLIST); | 4172 | = create_nated_internet_copy (pg, &remove_connections, BLACKLIST); |
4154 | #else | 4173 | #else |
4155 | unblacklisted_connections = | 4174 | unblacklisted_connections = |
4156 | create_nated_internet (pg, &remove_connections, BLACKLIST); | 4175 | create_nated_internet (pg, &remove_connections, BLACKLIST); |
4157 | #endif | 4176 | #endif |
4158 | 4177 | ||
4159 | break; | 4178 | break; |
4160 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 4179 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
4161 | #if VERBOSE_TESTING | 4180 | #if VERBOSE_TESTING |
4162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4163 | _("Blacklisting all but Scale Free topology\n")); | 4182 | _("Blacklisting all but Scale Free topology\n")); |
4164 | #endif | 4183 | #endif |
4165 | unblacklisted_connections = create_scale_free (pg, &remove_connections, | 4184 | unblacklisted_connections = create_scale_free (pg, &remove_connections, |
4166 | BLACKLIST); | 4185 | BLACKLIST); |
@@ -4168,35 +4187,35 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4168 | case GNUNET_TESTING_TOPOLOGY_LINE: | 4187 | case GNUNET_TESTING_TOPOLOGY_LINE: |
4169 | #if VERBOSE_TESTING | 4188 | #if VERBOSE_TESTING |
4170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4171 | _("Blacklisting all but straight line topology\n")); | 4190 | _("Blacklisting all but straight line topology\n")); |
4172 | #endif | 4191 | #endif |
4173 | unblacklisted_connections | 4192 | unblacklisted_connections |
4174 | = create_line (pg, &remove_connections, BLACKLIST); | 4193 | = create_line (pg, &remove_connections, BLACKLIST); |
4175 | default: | 4194 | default: |
4176 | break; | 4195 | break; |
4177 | } | 4196 | } |
4178 | 4197 | ||
4179 | if ((unblacklisted_connections > 0) && (restrict_transports != NULL)) | 4198 | if ((unblacklisted_connections > 0) && (restrict_transports != NULL)) |
4199 | { | ||
4200 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'\n", | ||
4201 | restrict_transports); | ||
4202 | ret = create_and_copy_blacklist_files (pg, restrict_transports); | ||
4203 | if (ret != GNUNET_OK) | ||
4180 | { | 4204 | { |
4181 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'\n", | ||
4182 | restrict_transports); | ||
4183 | ret = create_and_copy_blacklist_files (pg, restrict_transports); | ||
4184 | if (ret != GNUNET_OK) | ||
4185 | { | ||
4186 | #if VERBOSE_TESTING | 4205 | #if VERBOSE_TESTING |
4187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4188 | _("Failed during blacklist file copying!\n")); | 4207 | _("Failed during blacklist file copying!\n")); |
4189 | #endif | 4208 | #endif |
4190 | return 0; | 4209 | return 0; |
4191 | } | 4210 | } |
4192 | else | 4211 | else |
4193 | { | 4212 | { |
4194 | #if VERBOSE_TESTING | 4213 | #if VERBOSE_TESTING |
4195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4196 | _("Blacklist files created/copied successfully!\n")); | 4215 | _("Blacklist files created/copied successfully!\n")); |
4197 | #endif | 4216 | #endif |
4198 | } | ||
4199 | } | 4217 | } |
4218 | } | ||
4200 | return num_connections; | 4219 | return num_connections; |
4201 | } | 4220 | } |
4202 | 4221 | ||
@@ -4212,38 +4231,38 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4212 | */ | 4231 | */ |
4213 | static int | 4232 | static int |
4214 | random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 4233 | random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
4234 | { | ||
4235 | struct RandomContext *random_ctx = cls; | ||
4236 | double random_number; | ||
4237 | uint32_t second_pos; | ||
4238 | GNUNET_HashCode first_hash; | ||
4239 | |||
4240 | random_number = | ||
4241 | ((double) | ||
4242 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
4243 | UINT64_MAX)) / ((double) UINT64_MAX); | ||
4244 | if (random_number < random_ctx->percentage) | ||
4215 | { | 4245 | { |
4216 | struct RandomContext *random_ctx = cls; | 4246 | GNUNET_assert (GNUNET_OK == |
4217 | double random_number; | 4247 | GNUNET_CONTAINER_multihashmap_put (random_ctx-> |
4218 | uint32_t second_pos; | 4248 | first->connect_peers_working_set, |
4219 | GNUNET_HashCode first_hash; | 4249 | key, value, |
4220 | random_number = | 4250 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
4221 | ((double) | 4251 | } |
4222 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
4223 | UINT64_MAX)) / ((double) UINT64_MAX); | ||
4224 | if (random_number < random_ctx->percentage) | ||
4225 | { | ||
4226 | GNUNET_assert (GNUNET_OK == | ||
4227 | GNUNET_CONTAINER_multihashmap_put (random_ctx-> | ||
4228 | first->connect_peers_working_set, | ||
4229 | key, value, | ||
4230 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4231 | } | ||
4232 | 4252 | ||
4233 | /* Now we have considered this particular connection, remove it from the second peer so it's not double counted */ | 4253 | /* Now we have considered this particular connection, remove it from the second peer so it's not double counted */ |
4234 | uid_from_hash (key, &second_pos); | 4254 | uid_from_hash (key, &second_pos); |
4235 | hash_from_uid (random_ctx->first_uid, &first_hash); | 4255 | hash_from_uid (random_ctx->first_uid, &first_hash); |
4236 | GNUNET_assert (random_ctx->pg->total > second_pos); | 4256 | GNUNET_assert (random_ctx->pg->total > second_pos); |
4237 | GNUNET_assert (GNUNET_YES == | 4257 | GNUNET_assert (GNUNET_YES == |
4238 | GNUNET_CONTAINER_multihashmap_remove (random_ctx-> | 4258 | GNUNET_CONTAINER_multihashmap_remove (random_ctx->pg->peers |
4239 | pg->peers | 4259 | [second_pos].connect_peers, |
4240 | [second_pos].connect_peers, | 4260 | &first_hash, |
4241 | &first_hash, | 4261 | random_ctx-> |
4242 | random_ctx-> | 4262 | first->daemon)); |
4243 | first->daemon)); | ||
4244 | 4263 | ||
4245 | return GNUNET_YES; | 4264 | return GNUNET_YES; |
4246 | } | 4265 | } |
4247 | 4266 | ||
4248 | /** | 4267 | /** |
4249 | * Iterator for adding at least X peers to a peers connection set. | 4268 | * Iterator for adding at least X peers to a peers connection set. |
@@ -4256,49 +4275,48 @@ random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
4256 | */ | 4275 | */ |
4257 | static int | 4276 | static int |
4258 | minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 4277 | minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
4259 | { | 4278 | { |
4260 | struct MinimumContext *min_ctx = cls; | 4279 | struct MinimumContext *min_ctx = cls; |
4261 | uint32_t second_pos; | 4280 | uint32_t second_pos; |
4262 | GNUNET_HashCode first_hash; | 4281 | GNUNET_HashCode first_hash; |
4263 | unsigned int i; | 4282 | unsigned int i; |
4264 | 4283 | ||
4265 | if (GNUNET_CONTAINER_multihashmap_size | 4284 | if (GNUNET_CONTAINER_multihashmap_size |
4266 | (min_ctx->first->connect_peers_working_set) < min_ctx->num_to_add) | 4285 | (min_ctx->first->connect_peers_working_set) < min_ctx->num_to_add) |
4286 | { | ||
4287 | for (i = 0; i < min_ctx->num_to_add; i++) | ||
4288 | { | ||
4289 | if (min_ctx->pg_array[i] == min_ctx->current) | ||
4267 | { | 4290 | { |
4268 | for (i = 0; i < min_ctx->num_to_add; i++) | 4291 | GNUNET_assert (GNUNET_OK == |
4269 | { | 4292 | GNUNET_CONTAINER_multihashmap_put |
4270 | if (min_ctx->pg_array[i] == min_ctx->current) | 4293 | (min_ctx->first->connect_peers_working_set, key, |
4271 | { | ||
4272 | GNUNET_assert (GNUNET_OK == | ||
4273 | GNUNET_CONTAINER_multihashmap_put | ||
4274 | (min_ctx->first->connect_peers_working_set, key, | ||
4275 | value, | 4294 | value, |
4276 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 4295 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
4277 | uid_from_hash (key, &second_pos); | 4296 | uid_from_hash (key, &second_pos); |
4278 | hash_from_uid (min_ctx->first_uid, &first_hash); | 4297 | hash_from_uid (min_ctx->first_uid, &first_hash); |
4279 | GNUNET_assert (min_ctx->pg->total > second_pos); | 4298 | GNUNET_assert (min_ctx->pg->total > second_pos); |
4280 | GNUNET_assert (GNUNET_OK == | 4299 | GNUNET_assert (GNUNET_OK == |
4281 | GNUNET_CONTAINER_multihashmap_put (min_ctx-> | 4300 | GNUNET_CONTAINER_multihashmap_put (min_ctx->pg->peers |
4282 | pg->peers | 4301 | [second_pos].connect_peers_working_set, |
4283 | [second_pos].connect_peers_working_set, | 4302 | &first_hash, |
4284 | &first_hash, | 4303 | min_ctx->first-> |
4285 | min_ctx->first-> | 4304 | daemon, |
4286 | daemon, | 4305 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
4287 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 4306 | /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */ |
4288 | /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */ | 4307 | GNUNET_assert (GNUNET_YES == |
4289 | GNUNET_assert (GNUNET_YES == | 4308 | GNUNET_CONTAINER_multihashmap_remove |
4290 | GNUNET_CONTAINER_multihashmap_remove | 4309 | (min_ctx->pg->peers[second_pos].connect_peers, |
4291 | (min_ctx->pg->peers[second_pos].connect_peers, | ||
4292 | &first_hash, min_ctx->first->daemon)); | 4310 | &first_hash, min_ctx->first->daemon)); |
4293 | } | ||
4294 | } | ||
4295 | min_ctx->current++; | ||
4296 | return GNUNET_YES; | ||
4297 | } | 4311 | } |
4298 | else | 4312 | } |
4299 | return GNUNET_NO; /* We can stop iterating, we have enough peers! */ | 4313 | min_ctx->current++; |
4300 | 4314 | return GNUNET_YES; | |
4301 | } | 4315 | } |
4316 | else | ||
4317 | return GNUNET_NO; /* We can stop iterating, we have enough peers! */ | ||
4318 | |||
4319 | } | ||
4302 | 4320 | ||
4303 | /** | 4321 | /** |
4304 | * Iterator for adding peers to a connection set based on a depth first search. | 4322 | * Iterator for adding peers to a connection set based on a depth first search. |
@@ -4311,41 +4329,40 @@ minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
4311 | */ | 4329 | */ |
4312 | static int | 4330 | static int |
4313 | dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | 4331 | dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
4314 | { | 4332 | { |
4315 | struct DFSContext *dfs_ctx = cls; | 4333 | struct DFSContext *dfs_ctx = cls; |
4316 | GNUNET_HashCode first_hash; | 4334 | GNUNET_HashCode first_hash; |
4317 | |||
4318 | if (dfs_ctx->current == dfs_ctx->chosen) | ||
4319 | { | ||
4320 | GNUNET_assert (GNUNET_OK == | ||
4321 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> | ||
4322 | first->connect_peers_working_set, | ||
4323 | key, value, | ||
4324 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4325 | uid_from_hash (key, &dfs_ctx->second_uid); | ||
4326 | hash_from_uid (dfs_ctx->first_uid, &first_hash); | ||
4327 | GNUNET_assert (GNUNET_OK == | ||
4328 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> | ||
4329 | pg->peers | ||
4330 | [dfs_ctx->second_uid].connect_peers_working_set, | ||
4331 | &first_hash, | ||
4332 | dfs_ctx-> | ||
4333 | first->daemon, | ||
4334 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4335 | GNUNET_assert (GNUNET_YES == | ||
4336 | GNUNET_CONTAINER_multihashmap_remove (dfs_ctx-> | ||
4337 | pg->peers | ||
4338 | [dfs_ctx->second_uid].connect_peers, | ||
4339 | &first_hash, | ||
4340 | dfs_ctx-> | ||
4341 | first->daemon)); | ||
4342 | /* Can't remove second from first yet because we are currently iterating, hence the return value in the DFSContext! */ | ||
4343 | return GNUNET_NO; /* We have found our peer, don't iterate more */ | ||
4344 | } | ||
4345 | 4335 | ||
4346 | dfs_ctx->current++; | 4336 | if (dfs_ctx->current == dfs_ctx->chosen) |
4347 | return GNUNET_YES; | 4337 | { |
4338 | GNUNET_assert (GNUNET_OK == | ||
4339 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> | ||
4340 | first->connect_peers_working_set, | ||
4341 | key, value, | ||
4342 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4343 | uid_from_hash (key, &dfs_ctx->second_uid); | ||
4344 | hash_from_uid (dfs_ctx->first_uid, &first_hash); | ||
4345 | GNUNET_assert (GNUNET_OK == | ||
4346 | GNUNET_CONTAINER_multihashmap_put (dfs_ctx->pg->peers | ||
4347 | [dfs_ctx-> | ||
4348 | second_uid].connect_peers_working_set, | ||
4349 | &first_hash, | ||
4350 | dfs_ctx->first->daemon, | ||
4351 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4352 | GNUNET_assert (GNUNET_YES == | ||
4353 | GNUNET_CONTAINER_multihashmap_remove (dfs_ctx-> | ||
4354 | pg->peers | ||
4355 | [dfs_ctx->second_uid].connect_peers, | ||
4356 | &first_hash, | ||
4357 | dfs_ctx-> | ||
4358 | first->daemon)); | ||
4359 | /* Can't remove second from first yet because we are currently iterating, hence the return value in the DFSContext! */ | ||
4360 | return GNUNET_NO; /* We have found our peer, don't iterate more */ | ||
4348 | } | 4361 | } |
4362 | |||
4363 | dfs_ctx->current++; | ||
4364 | return GNUNET_YES; | ||
4365 | } | ||
4349 | #endif | 4366 | #endif |
4350 | 4367 | ||
4351 | /** | 4368 | /** |
@@ -4356,10 +4373,11 @@ dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value) | |||
4356 | * @param percentage what percent of total connections to make | 4373 | * @param percentage what percent of total connections to make |
4357 | */ | 4374 | */ |
4358 | void | 4375 | void |
4359 | choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg, | 4376 | choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg, |
4360 | double percentage) | 4377 | double percentage) |
4361 | { | 4378 | { |
4362 | uint32_t pg_iter; | 4379 | uint32_t pg_iter; |
4380 | |||
4363 | #if OLD | 4381 | #if OLD |
4364 | struct PeerConnection *conn_iter; | 4382 | struct PeerConnection *conn_iter; |
4365 | double random_number; | 4383 | double random_number; |
@@ -4368,56 +4386,55 @@ choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg, | |||
4368 | #endif | 4386 | #endif |
4369 | 4387 | ||
4370 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4388 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4371 | { | 4389 | { |
4372 | #if OLD | 4390 | #if OLD |
4373 | conn_iter = pg->peers[pg_iter].connect_peers_head; | 4391 | conn_iter = pg->peers[pg_iter].connect_peers_head; |
4374 | while (conn_iter != NULL) | 4392 | while (conn_iter != NULL) |
4375 | { | 4393 | { |
4376 | random_number | 4394 | random_number |
4377 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 4395 | = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
4378 | UINT64_MAX)) | 4396 | UINT64_MAX)) |
4379 | / ((double) UINT64_MAX); | 4397 | / ((double) UINT64_MAX); |
4380 | if (random_number < percentage) | 4398 | if (random_number < percentage) |
4381 | { | 4399 | { |
4382 | add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, | 4400 | add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, |
4383 | GNUNET_YES); | 4401 | GNUNET_YES); |
4384 | } | 4402 | } |
4385 | conn_iter = conn_iter->next; | 4403 | conn_iter = conn_iter->next; |
4386 | } | 4404 | } |
4387 | #else | 4405 | #else |
4388 | random_ctx.first_uid = pg_iter; | 4406 | random_ctx.first_uid = pg_iter; |
4389 | random_ctx.first = &pg->peers[pg_iter]; | 4407 | random_ctx.first = &pg->peers[pg_iter]; |
4390 | random_ctx.percentage = percentage; | 4408 | random_ctx.percentage = percentage; |
4391 | random_ctx.pg = pg; | 4409 | random_ctx.pg = pg; |
4392 | pg->peers[pg_iter].connect_peers_working_set | 4410 | pg->peers[pg_iter].connect_peers_working_set |
4393 | = GNUNET_CONTAINER_multihashmap_create (pg->total); | 4411 | = GNUNET_CONTAINER_multihashmap_create (pg->total); |
4394 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, | 4412 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, |
4395 | &random_connect_iterator, | 4413 | &random_connect_iterator, |
4396 | &random_ctx); | 4414 | &random_ctx); |
4397 | /* Now remove the old connections */ | 4415 | /* Now remove the old connections */ |
4398 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 4416 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers); |
4399 | peers[pg_iter].connect_peers); | 4417 | /* And replace with the random set */ |
4400 | /* And replace with the random set */ | 4418 | pg->peers[pg_iter].connect_peers |
4401 | pg->peers[pg_iter].connect_peers | 4419 | = pg->peers[pg_iter].connect_peers_working_set; |
4402 | = pg->peers[pg_iter].connect_peers_working_set; | ||
4403 | #endif | 4420 | #endif |
4404 | } | 4421 | } |
4405 | 4422 | ||
4406 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4423 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4407 | { | 4424 | { |
4408 | conn_iter = pg->peers[pg_iter].connect_peers_head; | 4425 | conn_iter = pg->peers[pg_iter].connect_peers_head; |
4409 | while (pg->peers[pg_iter].connect_peers_head != NULL) | 4426 | while (pg->peers[pg_iter].connect_peers_head != NULL) |
4410 | remove_connections (pg, pg_iter, | 4427 | remove_connections (pg, pg_iter, |
4411 | pg->peers[pg_iter].connect_peers_head->index, | 4428 | pg->peers[pg_iter].connect_peers_head->index, |
4412 | CONNECT, GNUNET_YES); | 4429 | CONNECT, GNUNET_YES); |
4413 | 4430 | ||
4414 | pg->peers[pg_iter].connect_peers_head | 4431 | pg->peers[pg_iter].connect_peers_head |
4415 | = pg->peers[pg_iter].connect_peers_working_set_head; | 4432 | = pg->peers[pg_iter].connect_peers_working_set_head; |
4416 | pg->peers[pg_iter].connect_peers_tail | 4433 | pg->peers[pg_iter].connect_peers_tail |
4417 | = pg->peers[pg_iter].connect_peers_working_set_tail; | 4434 | = pg->peers[pg_iter].connect_peers_working_set_tail; |
4418 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; | 4435 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; |
4419 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; | 4436 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; |
4420 | } | 4437 | } |
4421 | } | 4438 | } |
4422 | 4439 | ||
4423 | /** | 4440 | /** |
@@ -4428,76 +4445,76 @@ choose_random_connections(struct GNUNET_TESTING_PeerGroup *pg, | |||
4428 | * @return the number of elements in the list | 4445 | * @return the number of elements in the list |
4429 | */ | 4446 | */ |
4430 | static unsigned int | 4447 | static unsigned int |
4431 | count_connections(struct PeerConnection *conn_list) | 4448 | count_connections (struct PeerConnection *conn_list) |
4432 | { | 4449 | { |
4433 | struct PeerConnection *iter; | 4450 | struct PeerConnection *iter; |
4434 | unsigned int count; | 4451 | unsigned int count; |
4452 | |||
4435 | count = 0; | 4453 | count = 0; |
4436 | iter = conn_list; | 4454 | iter = conn_list; |
4437 | while (iter != NULL) | 4455 | while (iter != NULL) |
4438 | { | 4456 | { |
4439 | iter = iter->next; | 4457 | iter = iter->next; |
4440 | count++; | 4458 | count++; |
4441 | } | 4459 | } |
4442 | return count; | 4460 | return count; |
4443 | } | 4461 | } |
4444 | 4462 | ||
4445 | static unsigned int | 4463 | static unsigned int |
4446 | count_workingset_connections(struct GNUNET_TESTING_PeerGroup *pg) | 4464 | count_workingset_connections (struct GNUNET_TESTING_PeerGroup *pg) |
4447 | { | 4465 | { |
4448 | unsigned int count; | 4466 | unsigned int count; |
4449 | unsigned int pg_iter; | 4467 | unsigned int pg_iter; |
4468 | |||
4450 | #if OLD | 4469 | #if OLD |
4451 | struct PeerConnection *conn_iter; | 4470 | struct PeerConnection *conn_iter; |
4452 | #endif | 4471 | #endif |
4453 | count = 0; | 4472 | count = 0; |
4454 | 4473 | ||
4455 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4474 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4456 | { | 4475 | { |
4457 | #if OLD | 4476 | #if OLD |
4458 | conn_iter = pg->peers[pg_iter].connect_peers_working_set_head; | 4477 | conn_iter = pg->peers[pg_iter].connect_peers_working_set_head; |
4459 | while (conn_iter != NULL) | 4478 | while (conn_iter != NULL) |
4460 | { | 4479 | { |
4461 | count++; | 4480 | count++; |
4462 | conn_iter = conn_iter->next; | 4481 | conn_iter = conn_iter->next; |
4463 | } | 4482 | } |
4464 | #else | 4483 | #else |
4465 | count += | 4484 | count += |
4466 | GNUNET_CONTAINER_multihashmap_size (pg-> | 4485 | GNUNET_CONTAINER_multihashmap_size (pg->peers |
4467 | peers | 4486 | [pg_iter].connect_peers_working_set); |
4468 | [pg_iter].connect_peers_working_set); | ||
4469 | #endif | 4487 | #endif |
4470 | } | 4488 | } |
4471 | 4489 | ||
4472 | return count; | 4490 | return count; |
4473 | } | 4491 | } |
4474 | 4492 | ||
4475 | static unsigned int | 4493 | static unsigned int |
4476 | count_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg) | 4494 | count_allowed_connections (struct GNUNET_TESTING_PeerGroup *pg) |
4477 | { | 4495 | { |
4478 | unsigned int count; | 4496 | unsigned int count; |
4479 | unsigned int pg_iter; | 4497 | unsigned int pg_iter; |
4498 | |||
4480 | #if OLD | 4499 | #if OLD |
4481 | struct PeerConnection *conn_iter; | 4500 | struct PeerConnection *conn_iter; |
4482 | #endif | 4501 | #endif |
4483 | 4502 | ||
4484 | count = 0; | 4503 | count = 0; |
4485 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4504 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4486 | { | 4505 | { |
4487 | #if OLD | 4506 | #if OLD |
4488 | conn_iter = pg->peers[pg_iter].allowed_peers_head; | 4507 | conn_iter = pg->peers[pg_iter].allowed_peers_head; |
4489 | while (conn_iter != NULL) | 4508 | while (conn_iter != NULL) |
4490 | { | 4509 | { |
4491 | count++; | 4510 | count++; |
4492 | conn_iter = conn_iter->next; | 4511 | conn_iter = conn_iter->next; |
4493 | } | 4512 | } |
4494 | #else | 4513 | #else |
4495 | count += | 4514 | count += |
4496 | GNUNET_CONTAINER_multihashmap_size (pg-> | 4515 | GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].allowed_peers); |
4497 | peers | ||
4498 | [pg_iter].allowed_peers); | ||
4499 | #endif | 4516 | #endif |
4500 | } | 4517 | } |
4501 | 4518 | ||
4502 | return count; | 4519 | return count; |
4503 | } | 4520 | } |
@@ -4510,7 +4527,7 @@ count_allowed_connections(struct GNUNET_TESTING_PeerGroup *pg) | |||
4510 | * @param num how many connections at least should each peer have (if possible)? | 4527 | * @param num how many connections at least should each peer have (if possible)? |
4511 | */ | 4528 | */ |
4512 | static void | 4529 | static void |
4513 | choose_minimum(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | 4530 | choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) |
4514 | { | 4531 | { |
4515 | #if !OLD | 4532 | #if !OLD |
4516 | struct MinimumContext minimum_ctx; | 4533 | struct MinimumContext minimum_ctx; |
@@ -4519,113 +4536,110 @@ choose_minimum(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4519 | unsigned int temp_list_size; | 4536 | unsigned int temp_list_size; |
4520 | unsigned int i; | 4537 | unsigned int i; |
4521 | unsigned int count; | 4538 | unsigned int count; |
4522 | uint32_t random; /* Random list entry to connect peer to */ | 4539 | uint32_t random; /* Random list entry to connect peer to */ |
4523 | #endif | 4540 | #endif |
4524 | uint32_t pg_iter; | 4541 | uint32_t pg_iter; |
4525 | 4542 | ||
4526 | #if OLD | 4543 | #if OLD |
4527 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4544 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4545 | { | ||
4546 | temp_list_size = count_connections (pg->peers[pg_iter].connect_peers_head); | ||
4547 | if (temp_list_size == 0) | ||
4528 | { | 4548 | { |
4529 | temp_list_size | 4549 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4530 | = count_connections (pg->peers[pg_iter].connect_peers_head); | 4550 | "Peer %d has 0 connections!?!?\n", pg_iter); |
4531 | if (temp_list_size == 0) | 4551 | break; |
4532 | { | ||
4533 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
4534 | "Peer %d has 0 connections!?!?\n", pg_iter); | ||
4535 | break; | ||
4536 | } | ||
4537 | for (i = 0; i < num; i++) | ||
4538 | { | ||
4539 | random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
4540 | temp_list_size); | ||
4541 | conn_iter = pg->peers[pg_iter].connect_peers_head; | ||
4542 | for (count = 0; count < random; count++) | ||
4543 | conn_iter = conn_iter->next; | ||
4544 | /* We now have a random connection, connect it! */ | ||
4545 | GNUNET_assert(conn_iter != NULL); | ||
4546 | add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, | ||
4547 | GNUNET_YES); | ||
4548 | } | ||
4549 | } | 4552 | } |
4550 | #else | 4553 | for (i = 0; i < num; i++) |
4551 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
4552 | { | 4554 | { |
4553 | pg->peers[pg_iter].connect_peers_working_set = | 4555 | random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
4554 | GNUNET_CONTAINER_multihashmap_create (num); | 4556 | temp_list_size); |
4557 | conn_iter = pg->peers[pg_iter].connect_peers_head; | ||
4558 | for (count = 0; count < random; count++) | ||
4559 | conn_iter = conn_iter->next; | ||
4560 | /* We now have a random connection, connect it! */ | ||
4561 | GNUNET_assert (conn_iter != NULL); | ||
4562 | add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, GNUNET_YES); | ||
4555 | } | 4563 | } |
4564 | } | ||
4565 | #else | ||
4566 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
4567 | { | ||
4568 | pg->peers[pg_iter].connect_peers_working_set = | ||
4569 | GNUNET_CONTAINER_multihashmap_create (num); | ||
4570 | } | ||
4556 | 4571 | ||
4557 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4572 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4558 | { | 4573 | { |
4559 | minimum_ctx.first_uid = pg_iter; | 4574 | minimum_ctx.first_uid = pg_iter; |
4560 | minimum_ctx.pg_array = | 4575 | minimum_ctx.pg_array = |
4561 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | 4576 | GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, |
4562 | GNUNET_CONTAINER_multihashmap_size | 4577 | GNUNET_CONTAINER_multihashmap_size |
4563 | (pg->peers[pg_iter].connect_peers)); | 4578 | (pg->peers[pg_iter].connect_peers)); |
4564 | minimum_ctx.first = &pg->peers[pg_iter]; | 4579 | minimum_ctx.first = &pg->peers[pg_iter]; |
4565 | minimum_ctx.pg = pg; | 4580 | minimum_ctx.pg = pg; |
4566 | minimum_ctx.num_to_add = num; | 4581 | minimum_ctx.num_to_add = num; |
4567 | minimum_ctx.current = 0; | 4582 | minimum_ctx.current = 0; |
4568 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, | 4583 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, |
4569 | &minimum_connect_iterator, | 4584 | &minimum_connect_iterator, |
4570 | &minimum_ctx); | 4585 | &minimum_ctx); |
4571 | } | 4586 | } |
4572 | 4587 | ||
4573 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4588 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4574 | { | 4589 | { |
4575 | /* Remove the "old" connections */ | 4590 | /* Remove the "old" connections */ |
4576 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 4591 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers); |
4577 | peers[pg_iter].connect_peers); | 4592 | /* And replace with the working set */ |
4578 | /* And replace with the working set */ | 4593 | pg->peers[pg_iter].connect_peers = |
4579 | pg->peers[pg_iter].connect_peers = | 4594 | pg->peers[pg_iter].connect_peers_working_set; |
4580 | pg->peers[pg_iter].connect_peers_working_set; | 4595 | } |
4581 | } | ||
4582 | #endif | 4596 | #endif |
4583 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4597 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4598 | { | ||
4599 | while (pg->peers[pg_iter].connect_peers_head != NULL) | ||
4584 | { | 4600 | { |
4585 | while (pg->peers[pg_iter].connect_peers_head != NULL) | 4601 | conn_iter = pg->peers[pg_iter].connect_peers_head; |
4586 | { | 4602 | GNUNET_CONTAINER_DLL_remove (pg->peers[pg_iter].connect_peers_head, |
4587 | conn_iter = pg->peers[pg_iter].connect_peers_head; | 4603 | pg->peers[pg_iter].connect_peers_tail, |
4588 | GNUNET_CONTAINER_DLL_remove(pg->peers[pg_iter].connect_peers_head, | 4604 | conn_iter); |
4589 | pg->peers[pg_iter].connect_peers_tail, | 4605 | GNUNET_free (conn_iter); |
4590 | conn_iter); | 4606 | /*remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES); */ |
4591 | GNUNET_free(conn_iter); | 4607 | } |
4592 | /*remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES);*/ | 4608 | |
4593 | } | 4609 | pg->peers[pg_iter].connect_peers_head |
4594 | 4610 | = pg->peers[pg_iter].connect_peers_working_set_head; | |
4595 | pg->peers[pg_iter].connect_peers_head | 4611 | pg->peers[pg_iter].connect_peers_tail |
4596 | = pg->peers[pg_iter].connect_peers_working_set_head; | 4612 | = pg->peers[pg_iter].connect_peers_working_set_tail; |
4597 | pg->peers[pg_iter].connect_peers_tail | 4613 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; |
4598 | = pg->peers[pg_iter].connect_peers_working_set_tail; | 4614 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; |
4599 | pg->peers[pg_iter].connect_peers_working_set_head = NULL; | 4615 | } |
4600 | pg->peers[pg_iter].connect_peers_working_set_tail = NULL; | ||
4601 | } | ||
4602 | } | 4616 | } |
4603 | 4617 | ||
4604 | #if !OLD | 4618 | #if !OLD |
4605 | struct FindClosestContext | 4619 | struct FindClosestContext |
4606 | { | 4620 | { |
4607 | /** | 4621 | /** |
4608 | * The currently known closest peer. | 4622 | * The currently known closest peer. |
4609 | */ | 4623 | */ |
4610 | struct GNUNET_TESTING_Daemon *closest; | 4624 | struct GNUNET_TESTING_Daemon *closest; |
4611 | 4625 | ||
4612 | /** | 4626 | /** |
4613 | * The info for the peer we are adding connections for. | 4627 | * The info for the peer we are adding connections for. |
4614 | */ | 4628 | */ |
4615 | struct PeerData *curr_peer; | 4629 | struct PeerData *curr_peer; |
4616 | 4630 | ||
4617 | /** | 4631 | /** |
4618 | * The distance (bits) between the current | 4632 | * The distance (bits) between the current |
4619 | * peer and the currently known closest. | 4633 | * peer and the currently known closest. |
4620 | */ | 4634 | */ |
4621 | unsigned int closest_dist; | 4635 | unsigned int closest_dist; |
4622 | 4636 | ||
4623 | /** | 4637 | /** |
4624 | * The offset of the closest known peer in | 4638 | * The offset of the closest known peer in |
4625 | * the peer group. | 4639 | * the peer group. |
4626 | */ | 4640 | */ |
4627 | unsigned int closest_num; | 4641 | unsigned int closest_num; |
4628 | }; | 4642 | }; |
4629 | 4643 | ||
4630 | /** | 4644 | /** |
4631 | * Iterator over hash map entries of the allowed | 4645 | * Iterator over hash map entries of the allowed |
@@ -4641,29 +4655,29 @@ struct FindClosestContext | |||
4641 | */ | 4655 | */ |
4642 | static int | 4656 | static int |
4643 | find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | 4657 | find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) |
4658 | { | ||
4659 | struct FindClosestContext *closest_ctx = cls; | ||
4660 | struct GNUNET_TESTING_Daemon *daemon = value; | ||
4661 | |||
4662 | if (((closest_ctx->closest == NULL) || | ||
4663 | (GNUNET_CRYPTO_hash_matching_bits | ||
4664 | (&daemon->id.hashPubKey, | ||
4665 | &closest_ctx->curr_peer->daemon->id.hashPubKey) > | ||
4666 | closest_ctx->closest_dist)) | ||
4667 | && (GNUNET_YES != | ||
4668 | GNUNET_CONTAINER_multihashmap_contains (closest_ctx-> | ||
4669 | curr_peer->connect_peers, | ||
4670 | key))) | ||
4644 | { | 4671 | { |
4645 | struct FindClosestContext *closest_ctx = cls; | 4672 | closest_ctx->closest_dist = |
4646 | struct GNUNET_TESTING_Daemon *daemon = value; | ||
4647 | |||
4648 | if (((closest_ctx->closest == NULL) || | ||
4649 | (GNUNET_CRYPTO_hash_matching_bits | ||
4650 | (&daemon->id.hashPubKey, | ||
4651 | &closest_ctx->curr_peer->daemon->id.hashPubKey) > | ||
4652 | closest_ctx->closest_dist)) | ||
4653 | && (GNUNET_YES != | ||
4654 | GNUNET_CONTAINER_multihashmap_contains (closest_ctx-> | ||
4655 | curr_peer->connect_peers, | ||
4656 | key))) | ||
4657 | { | ||
4658 | closest_ctx->closest_dist = | ||
4659 | GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey, | 4673 | GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey, |
4660 | &closest_ctx->curr_peer->daemon-> | 4674 | &closest_ctx->curr_peer->daemon-> |
4661 | id.hashPubKey); | 4675 | id.hashPubKey); |
4662 | closest_ctx->closest = daemon; | 4676 | closest_ctx->closest = daemon; |
4663 | uid_from_hash (key, &closest_ctx->closest_num); | 4677 | uid_from_hash (key, &closest_ctx->closest_num); |
4664 | } | ||
4665 | return GNUNET_YES; | ||
4666 | } | 4678 | } |
4679 | return GNUNET_YES; | ||
4680 | } | ||
4667 | 4681 | ||
4668 | /** | 4682 | /** |
4669 | * From the set of connections possible, choose at num connections per | 4683 | * From the set of connections possible, choose at num connections per |
@@ -4678,36 +4692,34 @@ find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value) | |||
4678 | */ | 4692 | */ |
4679 | void | 4693 | void |
4680 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, | 4694 | add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, |
4681 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) | 4695 | GNUNET_TESTING_ConnectionProcessor proc, enum PeerLists list) |
4682 | { | 4696 | { |
4683 | #if OLD | 4697 | #if OLD |
4684 | 4698 | ||
4685 | #else | 4699 | #else |
4686 | struct FindClosestContext closest_ctx; | 4700 | struct FindClosestContext closest_ctx; |
4687 | #endif | 4701 | #endif |
4688 | uint32_t pg_iter; | 4702 | uint32_t pg_iter; |
4689 | uint32_t i; | 4703 | uint32_t i; |
4690 | 4704 | ||
4691 | for (i = 0; i < num; i++) /* Each time find a closest peer (from those available) */ | 4705 | for (i = 0; i < num; i++) /* Each time find a closest peer (from those available) */ |
4706 | { | ||
4707 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
4708 | { | ||
4709 | closest_ctx.curr_peer = &pg->peers[pg_iter]; | ||
4710 | closest_ctx.closest = NULL; | ||
4711 | closest_ctx.closest_dist = 0; | ||
4712 | closest_ctx.closest_num = 0; | ||
4713 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].allowed_peers, | ||
4714 | &find_closest_peers, &closest_ctx); | ||
4715 | if (closest_ctx.closest != NULL) | ||
4692 | { | 4716 | { |
4693 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4717 | GNUNET_assert (closest_ctx.closest_num < pg->total); |
4694 | { | 4718 | proc (pg, pg_iter, closest_ctx.closest_num, list); |
4695 | closest_ctx.curr_peer = &pg->peers[pg_iter]; | ||
4696 | closest_ctx.closest = NULL; | ||
4697 | closest_ctx.closest_dist = 0; | ||
4698 | closest_ctx.closest_num = 0; | ||
4699 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | ||
4700 | peers[pg_iter].allowed_peers, | ||
4701 | &find_closest_peers, | ||
4702 | &closest_ctx); | ||
4703 | if (closest_ctx.closest != NULL) | ||
4704 | { | ||
4705 | GNUNET_assert (closest_ctx.closest_num < pg->total); | ||
4706 | proc (pg, pg_iter, closest_ctx.closest_num, list); | ||
4707 | } | ||
4708 | } | ||
4709 | } | 4719 | } |
4720 | } | ||
4710 | } | 4721 | } |
4722 | } | ||
4711 | #endif | 4723 | #endif |
4712 | 4724 | ||
4713 | /** | 4725 | /** |
@@ -4719,13 +4731,14 @@ add_closest (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num, | |||
4719 | * @param num how many connections at least should each peer have (if possible)? | 4731 | * @param num how many connections at least should each peer have (if possible)? |
4720 | */ | 4732 | */ |
4721 | void | 4733 | void |
4722 | perform_dfs(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | 4734 | perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) |
4723 | { | 4735 | { |
4724 | uint32_t pg_iter; | 4736 | uint32_t pg_iter; |
4725 | uint32_t dfs_count; | 4737 | uint32_t dfs_count; |
4726 | uint32_t starting_peer; | 4738 | uint32_t starting_peer; |
4727 | uint32_t least_connections; | 4739 | uint32_t least_connections; |
4728 | uint32_t random_connection; | 4740 | uint32_t random_connection; |
4741 | |||
4729 | #if OLD | 4742 | #if OLD |
4730 | unsigned int temp_count; | 4743 | unsigned int temp_count; |
4731 | struct PeerConnection *peer_iter; | 4744 | struct PeerConnection *peer_iter; |
@@ -4738,118 +4751,115 @@ perform_dfs(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4738 | starting_peer = 0; | 4751 | starting_peer = 0; |
4739 | dfs_count = 0; | 4752 | dfs_count = 0; |
4740 | while ((count_workingset_connections (pg) < num * pg->total) | 4753 | while ((count_workingset_connections (pg) < num * pg->total) |
4741 | && (count_allowed_connections (pg) > 0)) | 4754 | && (count_allowed_connections (pg) > 0)) |
4755 | { | ||
4756 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | ||
4742 | { | 4757 | { |
4743 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | 4758 | least_connections = -1; /* Set to very high number */ |
4759 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
4760 | { | ||
4761 | temp_count | ||
4762 | = | ||
4763 | count_connections (pg-> | ||
4764 | peers[pg_iter].connect_peers_working_set_head); | ||
4765 | if (temp_count < least_connections) | ||
4744 | { | 4766 | { |
4745 | least_connections = -1; /* Set to very high number */ | 4767 | starting_peer = pg_iter; |
4746 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4768 | least_connections = temp_count; |
4747 | { | ||
4748 | temp_count | ||
4749 | = count_connections ( | ||
4750 | pg->peers[pg_iter].connect_peers_working_set_head); | ||
4751 | if (temp_count < least_connections) | ||
4752 | { | ||
4753 | starting_peer = pg_iter; | ||
4754 | least_connections = temp_count; | ||
4755 | } | ||
4756 | } | ||
4757 | } | 4769 | } |
4770 | } | ||
4771 | } | ||
4758 | 4772 | ||
4759 | temp_count | 4773 | temp_count |
4760 | = count_connections (pg->peers[starting_peer].connect_peers_head); | 4774 | = count_connections (pg->peers[starting_peer].connect_peers_head); |
4761 | if (temp_count == 0) | 4775 | if (temp_count == 0) |
4762 | continue; /* FIXME: infinite loop? */ | 4776 | continue; /* FIXME: infinite loop? */ |
4763 | 4777 | ||
4764 | random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 4778 | random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
4765 | temp_count); | 4779 | temp_count); |
4766 | temp_count = 0; | 4780 | temp_count = 0; |
4767 | peer_iter = pg->peers[starting_peer].connect_peers_head; | 4781 | peer_iter = pg->peers[starting_peer].connect_peers_head; |
4768 | while (temp_count < random_connection) | 4782 | while (temp_count < random_connection) |
4769 | { | 4783 | { |
4770 | peer_iter = peer_iter->next; | 4784 | peer_iter = peer_iter->next; |
4771 | temp_count++; | 4785 | temp_count++; |
4772 | } | ||
4773 | GNUNET_assert(peer_iter != NULL); | ||
4774 | add_connections (pg, starting_peer, peer_iter->index, WORKING_SET, | ||
4775 | GNUNET_NO); | ||
4776 | remove_connections (pg, starting_peer, peer_iter->index, CONNECT, | ||
4777 | GNUNET_YES); | ||
4778 | starting_peer = peer_iter->index; | ||
4779 | dfs_count++; | ||
4780 | } | 4786 | } |
4787 | GNUNET_assert (peer_iter != NULL); | ||
4788 | add_connections (pg, starting_peer, peer_iter->index, WORKING_SET, | ||
4789 | GNUNET_NO); | ||
4790 | remove_connections (pg, starting_peer, peer_iter->index, CONNECT, | ||
4791 | GNUNET_YES); | ||
4792 | starting_peer = peer_iter->index; | ||
4793 | dfs_count++; | ||
4794 | } | ||
4781 | 4795 | ||
4782 | #else | 4796 | #else |
4783 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4797 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4784 | { | 4798 | { |
4785 | pg->peers[pg_iter].connect_peers_working_set = | 4799 | pg->peers[pg_iter].connect_peers_working_set = |
4786 | GNUNET_CONTAINER_multihashmap_create (num); | 4800 | GNUNET_CONTAINER_multihashmap_create (num); |
4787 | } | 4801 | } |
4788 | 4802 | ||
4789 | starting_peer = 0; | 4803 | starting_peer = 0; |
4790 | dfs_count = 0; | 4804 | dfs_count = 0; |
4791 | while ((count_workingset_connections (pg) < num * pg->total) | 4805 | while ((count_workingset_connections (pg) < num * pg->total) |
4792 | && (count_allowed_connections (pg) > 0)) | 4806 | && (count_allowed_connections (pg) > 0)) |
4807 | { | ||
4808 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | ||
4793 | { | 4809 | { |
4794 | if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ | 4810 | least_connections = -1; /* Set to very high number */ |
4795 | { | 4811 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) |
4796 | least_connections = -1; /* Set to very high number */ | 4812 | { |
4797 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4813 | if (GNUNET_CONTAINER_multihashmap_size |
4798 | { | 4814 | (pg->peers[pg_iter].connect_peers_working_set) < least_connections) |
4799 | if (GNUNET_CONTAINER_multihashmap_size | ||
4800 | (pg->peers[pg_iter].connect_peers_working_set) < | ||
4801 | least_connections) | ||
4802 | { | ||
4803 | starting_peer = pg_iter; | ||
4804 | least_connections = | ||
4805 | GNUNET_CONTAINER_multihashmap_size (pg-> | ||
4806 | peers | ||
4807 | [pg_iter].connect_peers_working_set); | ||
4808 | } | ||
4809 | } | ||
4810 | } | ||
4811 | |||
4812 | if (GNUNET_CONTAINER_multihashmap_size (pg->peers[starting_peer].connect_peers) == 0) /* Ensure there is at least one peer left to connect! */ | ||
4813 | { | 4815 | { |
4814 | dfs_count = 0; | 4816 | starting_peer = pg_iter; |
4815 | continue; | 4817 | least_connections = |
4818 | GNUNET_CONTAINER_multihashmap_size (pg->peers | ||
4819 | [pg_iter].connect_peers_working_set); | ||
4816 | } | 4820 | } |
4817 | 4821 | } | |
4818 | /* Choose a random peer from the chosen peers set of connections to add */ | ||
4819 | dfs_ctx.chosen = | ||
4820 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
4821 | GNUNET_CONTAINER_multihashmap_size | ||
4822 | (pg->peers[starting_peer].connect_peers)); | ||
4823 | dfs_ctx.first_uid = starting_peer; | ||
4824 | dfs_ctx.first = &pg->peers[starting_peer]; | ||
4825 | dfs_ctx.pg = pg; | ||
4826 | dfs_ctx.current = 0; | ||
4827 | |||
4828 | GNUNET_CONTAINER_multihashmap_iterate (pg-> | ||
4829 | peers | ||
4830 | [starting_peer].connect_peers, | ||
4831 | &dfs_connect_iterator, &dfs_ctx); | ||
4832 | /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */ | ||
4833 | hash_from_uid (dfs_ctx.second_uid, &second_hash); | ||
4834 | GNUNET_assert (GNUNET_YES == | ||
4835 | GNUNET_CONTAINER_multihashmap_remove (pg->peers | ||
4836 | [starting_peer].connect_peers, | ||
4837 | &second_hash, | ||
4838 | pg-> | ||
4839 | peers | ||
4840 | [dfs_ctx.second_uid].daemon)); | ||
4841 | starting_peer = dfs_ctx.second_uid; | ||
4842 | } | 4822 | } |
4843 | 4823 | ||
4844 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | 4824 | if (GNUNET_CONTAINER_multihashmap_size (pg->peers[starting_peer].connect_peers) == 0) /* Ensure there is at least one peer left to connect! */ |
4845 | { | 4825 | { |
4846 | /* Remove the "old" connections */ | 4826 | dfs_count = 0; |
4847 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 4827 | continue; |
4848 | peers[pg_iter].connect_peers); | ||
4849 | /* And replace with the working set */ | ||
4850 | pg->peers[pg_iter].connect_peers = | ||
4851 | pg->peers[pg_iter].connect_peers_working_set; | ||
4852 | } | 4828 | } |
4829 | |||
4830 | /* Choose a random peer from the chosen peers set of connections to add */ | ||
4831 | dfs_ctx.chosen = | ||
4832 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
4833 | GNUNET_CONTAINER_multihashmap_size | ||
4834 | (pg->peers[starting_peer].connect_peers)); | ||
4835 | dfs_ctx.first_uid = starting_peer; | ||
4836 | dfs_ctx.first = &pg->peers[starting_peer]; | ||
4837 | dfs_ctx.pg = pg; | ||
4838 | dfs_ctx.current = 0; | ||
4839 | |||
4840 | GNUNET_CONTAINER_multihashmap_iterate (pg->peers | ||
4841 | [starting_peer].connect_peers, | ||
4842 | &dfs_connect_iterator, &dfs_ctx); | ||
4843 | /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */ | ||
4844 | hash_from_uid (dfs_ctx.second_uid, &second_hash); | ||
4845 | GNUNET_assert (GNUNET_YES == | ||
4846 | GNUNET_CONTAINER_multihashmap_remove (pg->peers | ||
4847 | [starting_peer].connect_peers, | ||
4848 | &second_hash, | ||
4849 | pg-> | ||
4850 | peers | ||
4851 | [dfs_ctx.second_uid].daemon)); | ||
4852 | starting_peer = dfs_ctx.second_uid; | ||
4853 | } | ||
4854 | |||
4855 | for (pg_iter = 0; pg_iter < pg->total; pg_iter++) | ||
4856 | { | ||
4857 | /* Remove the "old" connections */ | ||
4858 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers); | ||
4859 | /* And replace with the working set */ | ||
4860 | pg->peers[pg_iter].connect_peers = | ||
4861 | pg->peers[pg_iter].connect_peers_working_set; | ||
4862 | } | ||
4853 | #endif | 4863 | #endif |
4854 | } | 4864 | } |
4855 | 4865 | ||
@@ -4857,30 +4867,30 @@ perform_dfs(struct GNUNET_TESTING_PeerGroup *pg, unsigned int num) | |||
4857 | * Internal callback for topology information for a particular peer. | 4867 | * Internal callback for topology information for a particular peer. |
4858 | */ | 4868 | */ |
4859 | static void | 4869 | static void |
4860 | internal_topology_callback(void *cls, const struct GNUNET_PeerIdentity *peer, | 4870 | internal_topology_callback (void *cls, const struct GNUNET_PeerIdentity *peer, |
4861 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 4871 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
4862 | { | 4872 | { |
4863 | struct CoreContext *core_ctx = cls; | 4873 | struct CoreContext *core_ctx = cls; |
4864 | struct TopologyIterateContext *iter_ctx = core_ctx->iter_context; | 4874 | struct TopologyIterateContext *iter_ctx = core_ctx->iter_context; |
4865 | 4875 | ||
4866 | if (peer == NULL) /* Either finished, or something went wrong */ | 4876 | if (peer == NULL) /* Either finished, or something went wrong */ |
4867 | { | 4877 | { |
4868 | iter_ctx->completed++; | 4878 | iter_ctx->completed++; |
4869 | iter_ctx->connected--; | 4879 | iter_ctx->connected--; |
4870 | /* One core context allocated per iteration, must free! */ | 4880 | /* One core context allocated per iteration, must free! */ |
4871 | GNUNET_free (core_ctx); | 4881 | GNUNET_free (core_ctx); |
4872 | } | 4882 | } |
4873 | else | 4883 | else |
4874 | { | 4884 | { |
4875 | iter_ctx->topology_cb (iter_ctx->cls, &core_ctx->daemon->id, peer, NULL); | 4885 | iter_ctx->topology_cb (iter_ctx->cls, &core_ctx->daemon->id, peer, NULL); |
4876 | } | 4886 | } |
4877 | 4887 | ||
4878 | if (iter_ctx->completed == iter_ctx->total) | 4888 | if (iter_ctx->completed == iter_ctx->total) |
4879 | { | 4889 | { |
4880 | iter_ctx->topology_cb (iter_ctx->cls, NULL, NULL, NULL); | 4890 | iter_ctx->topology_cb (iter_ctx->cls, NULL, NULL, NULL); |
4881 | /* Once all are done, free the iteration context */ | 4891 | /* Once all are done, free the iteration context */ |
4882 | GNUNET_free (iter_ctx); | 4892 | GNUNET_free (iter_ctx); |
4883 | } | 4893 | } |
4884 | } | 4894 | } |
4885 | 4895 | ||
4886 | /** | 4896 | /** |
@@ -4888,45 +4898,43 @@ internal_topology_callback(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4888 | * schedule for some time in the future. | 4898 | * schedule for some time in the future. |
4889 | */ | 4899 | */ |
4890 | static void | 4900 | static void |
4891 | schedule_get_topology(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 4901 | schedule_get_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
4892 | { | 4902 | { |
4893 | struct CoreContext *core_context = cls; | 4903 | struct CoreContext *core_context = cls; |
4894 | struct TopologyIterateContext *topology_context = | 4904 | struct TopologyIterateContext *topology_context = |
4895 | (struct TopologyIterateContext *) core_context->iter_context; | 4905 | (struct TopologyIterateContext *) core_context->iter_context; |
4896 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 4906 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
4897 | return; | 4907 | return; |
4898 | 4908 | ||
4899 | if (topology_context->connected | 4909 | if (topology_context->connected |
4900 | > topology_context->pg->max_outstanding_connections) | 4910 | > topology_context->pg->max_outstanding_connections) |
4901 | { | 4911 | { |
4902 | #if VERBOSE_TESTING > 2 | 4912 | #if VERBOSE_TESTING > 2 |
4903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4904 | _ | 4914 | _ |
4905 | ("Delaying connect, we have too many outstanding connections!\n")); | 4915 | ("Delaying connect, we have too many outstanding connections!\n")); |
4906 | #endif | 4916 | #endif |
4907 | GNUNET_SCHEDULER_add_delayed ( | 4917 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
4908 | GNUNET_TIME_relative_multiply ( | 4918 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
4909 | GNUNET_TIME_UNIT_MILLISECONDS, | 4919 | &schedule_get_topology, core_context); |
4910 | 100), | 4920 | } |
4911 | &schedule_get_topology, core_context); | ||
4912 | } | ||
4913 | else | 4921 | else |
4914 | { | 4922 | { |
4915 | #if VERBOSE_TESTING > 2 | 4923 | #if VERBOSE_TESTING > 2 |
4916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4917 | _("Creating connection, outstanding_connections is %d\n"), | 4925 | _("Creating connection, outstanding_connections is %d\n"), |
4918 | outstanding_connects); | 4926 | outstanding_connects); |
4919 | #endif | 4927 | #endif |
4920 | topology_context->connected++; | 4928 | topology_context->connected++; |
4921 | 4929 | ||
4922 | if (GNUNET_OK != GNUNET_CORE_iterate_peers (core_context->daemon->cfg, | 4930 | if (GNUNET_OK != GNUNET_CORE_iterate_peers (core_context->daemon->cfg, |
4923 | &internal_topology_callback, | 4931 | &internal_topology_callback, |
4924 | core_context)) | 4932 | core_context)) |
4925 | { | 4933 | { |
4926 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Topology iteration failed.\n"); | 4934 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Topology iteration failed.\n"); |
4927 | internal_topology_callback (core_context, NULL, NULL); | 4935 | internal_topology_callback (core_context, NULL, NULL); |
4928 | } | ||
4929 | } | 4936 | } |
4937 | } | ||
4930 | } | 4938 | } |
4931 | 4939 | ||
4932 | /** | 4940 | /** |
@@ -4934,8 +4942,8 @@ schedule_get_topology(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
4934 | * all connections that each currently has. | 4942 | * all connections that each currently has. |
4935 | */ | 4943 | */ |
4936 | void | 4944 | void |
4937 | GNUNET_TESTING_get_topology(struct GNUNET_TESTING_PeerGroup *pg, | 4945 | GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, |
4938 | GNUNET_TESTING_NotifyTopology cb, void *cls) | 4946 | GNUNET_TESTING_NotifyTopology cb, void *cls) |
4939 | { | 4947 | { |
4940 | struct TopologyIterateContext *topology_context; | 4948 | struct TopologyIterateContext *topology_context; |
4941 | struct CoreContext *core_ctx; | 4949 | struct CoreContext *core_ctx; |
@@ -4949,23 +4957,23 @@ GNUNET_TESTING_get_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4949 | topology_context->pg = pg; | 4957 | topology_context->pg = pg; |
4950 | total_count = 0; | 4958 | total_count = 0; |
4951 | for (i = 0; i < pg->total; i++) | 4959 | for (i = 0; i < pg->total; i++) |
4960 | { | ||
4961 | if (pg->peers[i].daemon->running == GNUNET_YES) | ||
4952 | { | 4962 | { |
4953 | if (pg->peers[i].daemon->running == GNUNET_YES) | 4963 | /* Allocate one core context per core we need to connect to */ |
4954 | { | 4964 | core_ctx = GNUNET_malloc (sizeof (struct CoreContext)); |
4955 | /* Allocate one core context per core we need to connect to */ | 4965 | core_ctx->daemon = pg->peers[i].daemon; |
4956 | core_ctx = GNUNET_malloc (sizeof (struct CoreContext)); | 4966 | /* Set back pointer to topology iteration context */ |
4957 | core_ctx->daemon = pg->peers[i].daemon; | 4967 | core_ctx->iter_context = topology_context; |
4958 | /* Set back pointer to topology iteration context */ | 4968 | GNUNET_SCHEDULER_add_now (&schedule_get_topology, core_ctx); |
4959 | core_ctx->iter_context = topology_context; | 4969 | total_count++; |
4960 | GNUNET_SCHEDULER_add_now (&schedule_get_topology, core_ctx); | ||
4961 | total_count++; | ||
4962 | } | ||
4963 | } | 4970 | } |
4971 | } | ||
4964 | if (total_count == 0) | 4972 | if (total_count == 0) |
4965 | { | 4973 | { |
4966 | cb (cls, NULL, NULL, "Cannot iterate over topology, no running peers!"); | 4974 | cb (cls, NULL, NULL, "Cannot iterate over topology, no running peers!"); |
4967 | GNUNET_free (topology_context); | 4975 | GNUNET_free (topology_context); |
4968 | } | 4976 | } |
4969 | else | 4977 | else |
4970 | topology_context->total = total_count; | 4978 | topology_context->total = total_count; |
4971 | return; | 4979 | return; |
@@ -4985,8 +4993,8 @@ GNUNET_TESTING_get_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4985 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 4993 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
4986 | */ | 4994 | */ |
4987 | static int | 4995 | static int |
4988 | internal_stats_callback(void *cls, const char *subsystem, const char *name, | 4996 | internal_stats_callback (void *cls, const char *subsystem, const char *name, |
4989 | uint64_t value, int is_persistent) | 4997 | uint64_t value, int is_persistent) |
4990 | { | 4998 | { |
4991 | struct StatsCoreContext *core_context = cls; | 4999 | struct StatsCoreContext *core_context = cls; |
4992 | struct StatsIterateContext *stats_context = | 5000 | struct StatsIterateContext *stats_context = |
@@ -5004,7 +5012,7 @@ internal_stats_callback(void *cls, const char *subsystem, const char *name, | |||
5004 | * was canceled or not (we don't care) | 5012 | * was canceled or not (we don't care) |
5005 | */ | 5013 | */ |
5006 | static void | 5014 | static void |
5007 | internal_stats_cont(void *cls, int success) | 5015 | internal_stats_cont (void *cls, int success) |
5008 | { | 5016 | { |
5009 | struct StatsCoreContext *core_context = cls; | 5017 | struct StatsCoreContext *core_context = cls; |
5010 | struct StatsIterateContext *stats_context = | 5018 | struct StatsIterateContext *stats_context = |
@@ -5014,10 +5022,10 @@ internal_stats_cont(void *cls, int success) | |||
5014 | stats_context->completed++; | 5022 | stats_context->completed++; |
5015 | 5023 | ||
5016 | if (stats_context->completed == stats_context->total) | 5024 | if (stats_context->completed == stats_context->total) |
5017 | { | 5025 | { |
5018 | stats_context->cont (stats_context->cls, GNUNET_YES); | 5026 | stats_context->cont (stats_context->cls, GNUNET_YES); |
5019 | GNUNET_free (stats_context); | 5027 | GNUNET_free (stats_context); |
5020 | } | 5028 | } |
5021 | 5029 | ||
5022 | if (core_context->stats_handle != NULL) | 5030 | if (core_context->stats_handle != NULL) |
5023 | GNUNET_STATISTICS_destroy (core_context->stats_handle, GNUNET_NO); | 5031 | GNUNET_STATISTICS_destroy (core_context->stats_handle, GNUNET_NO); |
@@ -5030,55 +5038,53 @@ internal_stats_cont(void *cls, int success) | |||
5030 | * schedule for some time in the future. | 5038 | * schedule for some time in the future. |
5031 | */ | 5039 | */ |
5032 | static void | 5040 | static void |
5033 | schedule_get_statistics(void *cls, | 5041 | schedule_get_statistics (void *cls, |
5034 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 5042 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
5035 | { | 5043 | { |
5036 | struct StatsCoreContext *core_context = cls; | 5044 | struct StatsCoreContext *core_context = cls; |
5037 | struct StatsIterateContext *stats_context = | 5045 | struct StatsIterateContext *stats_context = |
5038 | (struct StatsIterateContext *) core_context->iter_context; | 5046 | (struct StatsIterateContext *) core_context->iter_context; |
5039 | 5047 | ||
5040 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 5048 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
5041 | return; | 5049 | return; |
5042 | 5050 | ||
5043 | if (stats_context->connected > stats_context->pg->max_outstanding_connections) | 5051 | if (stats_context->connected > stats_context->pg->max_outstanding_connections) |
5044 | { | 5052 | { |
5045 | #if VERBOSE_TESTING > 2 | 5053 | #if VERBOSE_TESTING > 2 |
5046 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5054 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5047 | _ | 5055 | _ |
5048 | ("Delaying connect, we have too many outstanding connections!\n")); | 5056 | ("Delaying connect, we have too many outstanding connections!\n")); |
5049 | #endif | 5057 | #endif |
5050 | GNUNET_SCHEDULER_add_delayed ( | 5058 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
5051 | GNUNET_TIME_relative_multiply ( | 5059 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
5052 | GNUNET_TIME_UNIT_MILLISECONDS, | 5060 | &schedule_get_statistics, core_context); |
5053 | 100), | 5061 | } |
5054 | &schedule_get_statistics, core_context); | ||
5055 | } | ||
5056 | else | 5062 | else |
5057 | { | 5063 | { |
5058 | #if VERBOSE_TESTING > 2 | 5064 | #if VERBOSE_TESTING > 2 |
5059 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5065 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5060 | _("Creating connection, outstanding_connections is %d\n"), | 5066 | _("Creating connection, outstanding_connections is %d\n"), |
5061 | outstanding_connects); | 5067 | outstanding_connects); |
5062 | #endif | 5068 | #endif |
5063 | 5069 | ||
5064 | stats_context->connected++; | 5070 | stats_context->connected++; |
5065 | core_context->stats_handle | 5071 | core_context->stats_handle |
5066 | = GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg); | 5072 | = GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg); |
5067 | if (core_context->stats_handle == NULL) | 5073 | if (core_context->stats_handle == NULL) |
5068 | { | 5074 | { |
5069 | internal_stats_cont (core_context, GNUNET_NO); | 5075 | internal_stats_cont (core_context, GNUNET_NO); |
5070 | return; | 5076 | return; |
5071 | } | 5077 | } |
5072 | 5078 | ||
5073 | core_context->stats_get_handle | 5079 | core_context->stats_get_handle |
5074 | = GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL, | 5080 | = GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL, |
5075 | GNUNET_TIME_relative_get_forever (), | 5081 | GNUNET_TIME_relative_get_forever (), |
5076 | &internal_stats_cont, | 5082 | &internal_stats_cont, |
5077 | &internal_stats_callback, core_context); | 5083 | &internal_stats_callback, core_context); |
5078 | if (core_context->stats_get_handle == NULL) | 5084 | if (core_context->stats_get_handle == NULL) |
5079 | internal_stats_cont (core_context, GNUNET_NO); | 5085 | internal_stats_cont (core_context, GNUNET_NO); |
5080 | 5086 | ||
5081 | } | 5087 | } |
5082 | } | 5088 | } |
5083 | 5089 | ||
5084 | struct DuplicateStats | 5090 | struct DuplicateStats |
@@ -5106,18 +5112,19 @@ struct DuplicateStats | |||
5106 | * GNUNET_NO if not (and we may have added it to the list) | 5112 | * GNUNET_NO if not (and we may have added it to the list) |
5107 | */ | 5113 | */ |
5108 | static int | 5114 | static int |
5109 | stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, | 5115 | stats_check_existing (struct GNUNET_TESTING_PeerGroup *pg, |
5110 | struct PeerData *specific_peer, | 5116 | struct PeerData *specific_peer, |
5111 | struct DuplicateStats **stats_list) | 5117 | struct DuplicateStats **stats_list) |
5112 | { | 5118 | { |
5113 | struct DuplicateStats *pos; | 5119 | struct DuplicateStats *pos; |
5114 | char *unix_domain_socket; | 5120 | char *unix_domain_socket; |
5115 | unsigned long long port; | 5121 | unsigned long long port; |
5116 | char *to_match; | 5122 | char *to_match; |
5123 | |||
5117 | if (GNUNET_YES | 5124 | if (GNUNET_YES |
5118 | != GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing", | 5125 | != GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing", |
5119 | "single_statistics_per_host")) | 5126 | "single_statistics_per_host")) |
5120 | return GNUNET_NO; /* Each peer has its own statistics instance, do nothing! */ | 5127 | return GNUNET_NO; /* Each peer has its own statistics instance, do nothing! */ |
5121 | 5128 | ||
5122 | pos = *stats_list; | 5129 | pos = *stats_list; |
5123 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg, | 5130 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg, |
@@ -5129,10 +5136,10 @@ stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, | |||
5129 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg, | 5136 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg, |
5130 | "statistics", "port", | 5137 | "statistics", "port", |
5131 | &port)) | 5138 | &port)) |
5132 | { | 5139 | { |
5133 | GNUNET_free(unix_domain_socket); | 5140 | GNUNET_free (unix_domain_socket); |
5134 | return GNUNET_NO; | 5141 | return GNUNET_NO; |
5135 | } | 5142 | } |
5136 | 5143 | ||
5137 | if (specific_peer->daemon->hostname != NULL) | 5144 | if (specific_peer->daemon->hostname != NULL) |
5138 | GNUNET_asprintf (&to_match, "%s%s%llu", specific_peer->daemon->hostname, | 5145 | GNUNET_asprintf (&to_match, "%s%s%llu", specific_peer->daemon->hostname, |
@@ -5141,15 +5148,15 @@ stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, | |||
5141 | GNUNET_asprintf (&to_match, "%s%llu", unix_domain_socket, port); | 5148 | GNUNET_asprintf (&to_match, "%s%llu", unix_domain_socket, port); |
5142 | 5149 | ||
5143 | while (pos != NULL) | 5150 | while (pos != NULL) |
5151 | { | ||
5152 | if (0 == strcmp (to_match, pos->unique_string)) | ||
5144 | { | 5153 | { |
5145 | if (0 == strcmp (to_match, pos->unique_string)) | 5154 | GNUNET_free (unix_domain_socket); |
5146 | { | 5155 | GNUNET_free (to_match); |
5147 | GNUNET_free (unix_domain_socket); | 5156 | return GNUNET_YES; |
5148 | GNUNET_free (to_match); | ||
5149 | return GNUNET_YES; | ||
5150 | } | ||
5151 | pos = pos->next; | ||
5152 | } | 5157 | } |
5158 | pos = pos->next; | ||
5159 | } | ||
5153 | pos = GNUNET_malloc (sizeof (struct DuplicateStats)); | 5160 | pos = GNUNET_malloc (sizeof (struct DuplicateStats)); |
5154 | pos->unique_string = to_match; | 5161 | pos->unique_string = to_match; |
5155 | pos->next = *stats_list; | 5162 | pos->next = *stats_list; |
@@ -5169,10 +5176,10 @@ stats_check_existing(struct GNUNET_TESTING_PeerGroup *pg, | |||
5169 | * | 5176 | * |
5170 | */ | 5177 | */ |
5171 | void | 5178 | void |
5172 | GNUNET_TESTING_get_statistics(struct GNUNET_TESTING_PeerGroup *pg, | 5179 | GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, |
5173 | GNUNET_STATISTICS_Callback cont, | 5180 | GNUNET_STATISTICS_Callback cont, |
5174 | GNUNET_TESTING_STATISTICS_Iterator proc, | 5181 | GNUNET_TESTING_STATISTICS_Iterator proc, |
5175 | void *cls) | 5182 | void *cls) |
5176 | { | 5183 | { |
5177 | struct StatsIterateContext *stats_context; | 5184 | struct StatsIterateContext *stats_context; |
5178 | struct StatsCoreContext *core_ctx; | 5185 | struct StatsCoreContext *core_ctx; |
@@ -5180,6 +5187,7 @@ GNUNET_TESTING_get_statistics(struct GNUNET_TESTING_PeerGroup *pg, | |||
5180 | unsigned int total_count; | 5187 | unsigned int total_count; |
5181 | struct DuplicateStats *stats_list; | 5188 | struct DuplicateStats *stats_list; |
5182 | struct DuplicateStats *pos; | 5189 | struct DuplicateStats *pos; |
5190 | |||
5183 | stats_list = NULL; | 5191 | stats_list = NULL; |
5184 | 5192 | ||
5185 | /* Allocate a single stats iteration context */ | 5193 | /* Allocate a single stats iteration context */ |
@@ -5191,34 +5199,37 @@ GNUNET_TESTING_get_statistics(struct GNUNET_TESTING_PeerGroup *pg, | |||
5191 | total_count = 0; | 5199 | total_count = 0; |
5192 | 5200 | ||
5193 | for (i = 0; i < pg->total; i++) | 5201 | for (i = 0; i < pg->total; i++) |
5194 | { | 5202 | { |
5195 | if ((pg->peers[i].daemon->running == GNUNET_YES) && (GNUNET_NO | 5203 | if ((pg->peers[i].daemon->running == GNUNET_YES) && (GNUNET_NO |
5196 | == stats_check_existing (pg, &pg->peers[i], &stats_list))) | 5204 | == |
5197 | { | 5205 | stats_check_existing |
5198 | /* Allocate one core context per core we need to connect to */ | 5206 | (pg, &pg->peers[i], |
5199 | core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext)); | 5207 | &stats_list))) |
5200 | core_ctx->daemon = pg->peers[i].daemon; | 5208 | { |
5201 | /* Set back pointer to topology iteration context */ | 5209 | /* Allocate one core context per core we need to connect to */ |
5202 | core_ctx->iter_context = stats_context; | 5210 | core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext)); |
5203 | GNUNET_SCHEDULER_add_now (&schedule_get_statistics, core_ctx); | 5211 | core_ctx->daemon = pg->peers[i].daemon; |
5204 | total_count++; | 5212 | /* Set back pointer to topology iteration context */ |
5205 | } | 5213 | core_ctx->iter_context = stats_context; |
5214 | GNUNET_SCHEDULER_add_now (&schedule_get_statistics, core_ctx); | ||
5215 | total_count++; | ||
5206 | } | 5216 | } |
5217 | } | ||
5207 | 5218 | ||
5208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
5209 | "Retrieving stats from %u total instances.\n", total_count); | 5220 | "Retrieving stats from %u total instances.\n", total_count); |
5210 | stats_context->total = total_count; | 5221 | stats_context->total = total_count; |
5211 | if (stats_list != NULL) | 5222 | if (stats_list != NULL) |
5223 | { | ||
5224 | pos = stats_list; | ||
5225 | while (pos != NULL) | ||
5212 | { | 5226 | { |
5213 | pos = stats_list; | 5227 | GNUNET_free (pos->unique_string); |
5214 | while (pos != NULL) | 5228 | stats_list = pos->next; |
5215 | { | 5229 | GNUNET_free (pos); |
5216 | GNUNET_free (pos->unique_string); | 5230 | pos = stats_list->next; |
5217 | stats_list = pos->next; | ||
5218 | GNUNET_free (pos); | ||
5219 | pos = stats_list->next; | ||
5220 | } | ||
5221 | } | 5231 | } |
5232 | } | ||
5222 | return; | 5233 | return; |
5223 | } | 5234 | } |
5224 | 5235 | ||
@@ -5228,7 +5239,7 @@ GNUNET_TESTING_get_statistics(struct GNUNET_TESTING_PeerGroup *pg, | |||
5228 | * @param pg the peer group to stop connecting | 5239 | * @param pg the peer group to stop connecting |
5229 | */ | 5240 | */ |
5230 | void | 5241 | void |
5231 | GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg) | 5242 | GNUNET_TESTING_stop_connections (struct GNUNET_TESTING_PeerGroup *pg) |
5232 | { | 5243 | { |
5233 | pg->stop_connects = GNUNET_YES; | 5244 | pg->stop_connects = GNUNET_YES; |
5234 | } | 5245 | } |
@@ -5239,7 +5250,7 @@ GNUNET_TESTING_stop_connections(struct GNUNET_TESTING_PeerGroup *pg) | |||
5239 | * @param pg the peer group to resume connecting | 5250 | * @param pg the peer group to resume connecting |
5240 | */ | 5251 | */ |
5241 | void | 5252 | void |
5242 | GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg) | 5253 | GNUNET_TESTING_resume_connections (struct GNUNET_TESTING_PeerGroup *pg) |
5243 | { | 5254 | { |
5244 | pg->stop_connects = GNUNET_NO; | 5255 | pg->stop_connects = GNUNET_NO; |
5245 | } | 5256 | } |
@@ -5267,18 +5278,17 @@ GNUNET_TESTING_resume_connections(struct GNUNET_TESTING_PeerGroup *pg) | |||
5267 | * @return the number of connections that will be attempted, GNUNET_SYSERR on error | 5278 | * @return the number of connections that will be attempted, GNUNET_SYSERR on error |
5268 | */ | 5279 | */ |
5269 | int | 5280 | int |
5270 | GNUNET_TESTING_connect_topology( | 5281 | GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, |
5271 | struct GNUNET_TESTING_PeerGroup *pg, | 5282 | enum GNUNET_TESTING_Topology topology, |
5272 | enum GNUNET_TESTING_Topology topology, | 5283 | enum GNUNET_TESTING_TopologyOption options, |
5273 | enum GNUNET_TESTING_TopologyOption options, | 5284 | double option_modifier, |
5274 | double option_modifier, | 5285 | struct GNUNET_TIME_Relative connect_timeout, |
5275 | struct GNUNET_TIME_Relative connect_timeout, | 5286 | unsigned int connect_attempts, |
5276 | unsigned int connect_attempts, | 5287 | GNUNET_TESTING_NotifyCompletion |
5277 | GNUNET_TESTING_NotifyCompletion notify_callback, | 5288 | notify_callback, void *notify_cls) |
5278 | void *notify_cls) | ||
5279 | { | 5289 | { |
5280 | switch (topology) | 5290 | switch (topology) |
5281 | { | 5291 | { |
5282 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 5292 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
5283 | #if VERBOSE_TOPOLOGY | 5293 | #if VERBOSE_TOPOLOGY |
5284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -5349,17 +5359,17 @@ GNUNET_TESTING_connect_topology( | |||
5349 | break; | 5359 | break; |
5350 | default: | 5360 | default: |
5351 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ | 5361 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ |
5352 | ("Unknown topology specification, can't connect peers!\n")); | 5362 | ("Unknown topology specification, can't connect peers!\n")); |
5353 | return GNUNET_SYSERR; | 5363 | return GNUNET_SYSERR; |
5354 | } | 5364 | } |
5355 | 5365 | ||
5356 | switch (options) | 5366 | switch (options) |
5357 | { | 5367 | { |
5358 | case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM: | 5368 | case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM: |
5359 | #if VERBOSE_TOPOLOGY | 5369 | #if VERBOSE_TOPOLOGY |
5360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ | 5370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ |
5361 | ("Connecting random subset (%'.2f percent) of possible peers\n"), 100 | 5371 | ("Connecting random subset (%'.2f percent) of possible peers\n"), |
5362 | * option_modifier); | 5372 | 100 * option_modifier); |
5363 | #endif | 5373 | #endif |
5364 | choose_random_connections (pg, option_modifier); | 5374 | choose_random_connections (pg, option_modifier); |
5365 | break; | 5375 | break; |
@@ -5374,7 +5384,7 @@ GNUNET_TESTING_connect_topology( | |||
5374 | case GNUNET_TESTING_TOPOLOGY_OPTION_DFS: | 5384 | case GNUNET_TESTING_TOPOLOGY_OPTION_DFS: |
5375 | #if VERBOSE_TOPOLOGY | 5385 | #if VERBOSE_TOPOLOGY |
5376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ | 5386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ |
5377 | ("Using DFS to connect a minimum of %u peers each (if possible)\n"), | 5387 | ("Using DFS to connect a minimum of %u peers each (if possible)\n"), |
5378 | (unsigned int) option_modifier); | 5388 | (unsigned int) option_modifier); |
5379 | #endif | 5389 | #endif |
5380 | #if FIXME | 5390 | #if FIXME |
@@ -5384,12 +5394,11 @@ GNUNET_TESTING_connect_topology( | |||
5384 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: | 5394 | case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: |
5385 | #if VERBOSE_TOPOLOGY | 5395 | #if VERBOSE_TOPOLOGY |
5386 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ | 5396 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ |
5387 | ("Finding additional %u closest peers each (if possible)\n"), | 5397 | ("Finding additional %u closest peers each (if possible)\n"), |
5388 | (unsigned int) option_modifier); | 5398 | (unsigned int) option_modifier); |
5389 | #endif | 5399 | #endif |
5390 | #if FIXME | 5400 | #if FIXME |
5391 | add_closest (pg, (unsigned int) option_modifier, | 5401 | add_closest (pg, (unsigned int) option_modifier, &add_connections, CONNECT); |
5392 | &add_connections, CONNECT); | ||
5393 | #endif | 5402 | #endif |
5394 | break; | 5403 | break; |
5395 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: | 5404 | case GNUNET_TESTING_TOPOLOGY_OPTION_NONE: |
@@ -5398,7 +5407,7 @@ GNUNET_TESTING_connect_topology( | |||
5398 | break; | 5407 | break; |
5399 | default: | 5408 | default: |
5400 | break; | 5409 | break; |
5401 | } | 5410 | } |
5402 | 5411 | ||
5403 | return connect_topology (pg, connect_timeout, connect_attempts, | 5412 | return connect_topology (pg, connect_timeout, connect_attempts, |
5404 | notify_callback, notify_cls); | 5413 | notify_callback, notify_cls); |
@@ -5413,14 +5422,15 @@ GNUNET_TESTING_connect_topology( | |||
5413 | * @return the number of current ssh connections to the host | 5422 | * @return the number of current ssh connections to the host |
5414 | */ | 5423 | */ |
5415 | static unsigned int | 5424 | static unsigned int |
5416 | count_outstanding_at_host(const char *hostname, | 5425 | count_outstanding_at_host (const char *hostname, |
5417 | struct GNUNET_TESTING_PeerGroup *pg) | 5426 | struct GNUNET_TESTING_PeerGroup *pg) |
5418 | { | 5427 | { |
5419 | struct OutstandingSSH *pos; | 5428 | struct OutstandingSSH *pos; |
5429 | |||
5420 | pos = pg->ssh_head; | 5430 | pos = pg->ssh_head; |
5421 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) | 5431 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) |
5422 | pos = pos->next; | 5432 | pos = pos->next; |
5423 | GNUNET_assert(pos != NULL); | 5433 | GNUNET_assert (pos != NULL); |
5424 | return pos->outstanding; | 5434 | return pos->outstanding; |
5425 | } | 5435 | } |
5426 | 5436 | ||
@@ -5432,14 +5442,15 @@ count_outstanding_at_host(const char *hostname, | |||
5432 | * | 5442 | * |
5433 | */ | 5443 | */ |
5434 | static void | 5444 | static void |
5435 | increment_outstanding_at_host(const char *hostname, | 5445 | increment_outstanding_at_host (const char *hostname, |
5436 | struct GNUNET_TESTING_PeerGroup *pg) | 5446 | struct GNUNET_TESTING_PeerGroup *pg) |
5437 | { | 5447 | { |
5438 | struct OutstandingSSH *pos; | 5448 | struct OutstandingSSH *pos; |
5449 | |||
5439 | pos = pg->ssh_head; | 5450 | pos = pg->ssh_head; |
5440 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) | 5451 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) |
5441 | pos = pos->next; | 5452 | pos = pos->next; |
5442 | GNUNET_assert(pos != NULL); | 5453 | GNUNET_assert (pos != NULL); |
5443 | pos->outstanding++; | 5454 | pos->outstanding++; |
5444 | } | 5455 | } |
5445 | 5456 | ||
@@ -5451,14 +5462,15 @@ increment_outstanding_at_host(const char *hostname, | |||
5451 | * | 5462 | * |
5452 | */ | 5463 | */ |
5453 | static void | 5464 | static void |
5454 | decrement_outstanding_at_host(const char *hostname, | 5465 | decrement_outstanding_at_host (const char *hostname, |
5455 | struct GNUNET_TESTING_PeerGroup *pg) | 5466 | struct GNUNET_TESTING_PeerGroup *pg) |
5456 | { | 5467 | { |
5457 | struct OutstandingSSH *pos; | 5468 | struct OutstandingSSH *pos; |
5469 | |||
5458 | pos = pg->ssh_head; | 5470 | pos = pg->ssh_head; |
5459 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) | 5471 | while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0)) |
5460 | pos = pos->next; | 5472 | pos = pos->next; |
5461 | GNUNET_assert(pos != NULL); | 5473 | GNUNET_assert (pos != NULL); |
5462 | pos->outstanding--; | 5474 | pos->outstanding--; |
5463 | } | 5475 | } |
5464 | 5476 | ||
@@ -5473,10 +5485,11 @@ decrement_outstanding_at_host(const char *hostname, | |||
5473 | * @param emsg error message (NULL on success) | 5485 | * @param emsg error message (NULL on success) |
5474 | */ | 5486 | */ |
5475 | static void | 5487 | static void |
5476 | internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | 5488 | internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id, |
5477 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 5489 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5478 | { | 5490 | { |
5479 | struct InternalStartContext *internal_context = cls; | 5491 | struct InternalStartContext *internal_context = cls; |
5492 | |||
5480 | internal_context->peer->pg->starting--; | 5493 | internal_context->peer->pg->starting--; |
5481 | internal_context->peer->pg->started++; | 5494 | internal_context->peer->pg->started++; |
5482 | if (internal_context->hostname != NULL) | 5495 | if (internal_context->hostname != NULL) |
@@ -5486,11 +5499,11 @@ internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
5486 | internal_context->hostkey_callback (internal_context->hostkey_cls, id, d, | 5499 | internal_context->hostkey_callback (internal_context->hostkey_cls, id, d, |
5487 | emsg); | 5500 | emsg); |
5488 | else if (internal_context->peer->pg->started | 5501 | else if (internal_context->peer->pg->started |
5489 | == internal_context->peer->pg->total) | 5502 | == internal_context->peer->pg->total) |
5490 | { | 5503 | { |
5491 | internal_context->peer->pg->started = 0; /* Internal startup may use this counter! */ | 5504 | internal_context->peer->pg->started = 0; /* Internal startup may use this counter! */ |
5492 | GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg); | 5505 | GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg); |
5493 | } | 5506 | } |
5494 | } | 5507 | } |
5495 | 5508 | ||
5496 | /** | 5509 | /** |
@@ -5505,11 +5518,12 @@ internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
5505 | * @param emsg error message (NULL on success) | 5518 | * @param emsg error message (NULL on success) |
5506 | */ | 5519 | */ |
5507 | static void | 5520 | static void |
5508 | internal_startup_callback(void *cls, const struct GNUNET_PeerIdentity *id, | 5521 | internal_startup_callback (void *cls, const struct GNUNET_PeerIdentity *id, |
5509 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 5522 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
5510 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 5523 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5511 | { | 5524 | { |
5512 | struct InternalStartContext *internal_context = cls; | 5525 | struct InternalStartContext *internal_context = cls; |
5526 | |||
5513 | internal_context->peer->pg->starting--; | 5527 | internal_context->peer->pg->starting--; |
5514 | if (internal_context->hostname != NULL) | 5528 | if (internal_context->hostname != NULL) |
5515 | decrement_outstanding_at_host (internal_context->hostname, | 5529 | decrement_outstanding_at_host (internal_context->hostname, |
@@ -5520,38 +5534,35 @@ internal_startup_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
5520 | } | 5534 | } |
5521 | 5535 | ||
5522 | static void | 5536 | static void |
5523 | internal_continue_startup(void *cls, | 5537 | internal_continue_startup (void *cls, |
5524 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 5538 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
5525 | { | 5539 | { |
5526 | struct InternalStartContext *internal_context = cls; | 5540 | struct InternalStartContext *internal_context = cls; |
5527 | 5541 | ||
5528 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 5542 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
5529 | { | 5543 | { |
5530 | return; | 5544 | return; |
5531 | } | 5545 | } |
5532 | 5546 | ||
5533 | if ((internal_context->peer->pg->starting | 5547 | if ((internal_context->peer->pg->starting |
5534 | < internal_context->peer->pg->max_concurrent_ssh) | 5548 | < internal_context->peer->pg->max_concurrent_ssh) |
5535 | || ((internal_context->hostname != NULL) | 5549 | || ((internal_context->hostname != NULL) |
5536 | && (count_outstanding_at_host (internal_context->hostname, | 5550 | && (count_outstanding_at_host (internal_context->hostname, |
5537 | internal_context->peer->pg) | 5551 | internal_context->peer->pg) |
5538 | < internal_context->peer->pg->max_concurrent_ssh))) | 5552 | < internal_context->peer->pg->max_concurrent_ssh))) |
5539 | { | 5553 | { |
5540 | if (internal_context->hostname != NULL) | 5554 | if (internal_context->hostname != NULL) |
5541 | increment_outstanding_at_host (internal_context->hostname, | 5555 | increment_outstanding_at_host (internal_context->hostname, |
5542 | internal_context->peer->pg); | 5556 | internal_context->peer->pg); |
5543 | internal_context->peer->pg->starting++; | 5557 | internal_context->peer->pg->starting++; |
5544 | GNUNET_TESTING_daemon_continue_startup (internal_context->peer->daemon); | 5558 | GNUNET_TESTING_daemon_continue_startup (internal_context->peer->daemon); |
5545 | } | 5559 | } |
5546 | else | 5560 | else |
5547 | { | 5561 | { |
5548 | GNUNET_SCHEDULER_add_delayed ( | 5562 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
5549 | GNUNET_TIME_relative_multiply ( | 5563 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
5550 | GNUNET_TIME_UNIT_MILLISECONDS, | 5564 | &internal_continue_startup, internal_context); |
5551 | 100), | 5565 | } |
5552 | &internal_continue_startup, | ||
5553 | internal_context); | ||
5554 | } | ||
5555 | } | 5566 | } |
5556 | 5567 | ||
5557 | /** | 5568 | /** |
@@ -5566,9 +5577,9 @@ internal_continue_startup(void *cls, | |||
5566 | * | 5577 | * |
5567 | */ | 5578 | */ |
5568 | void | 5579 | void |
5569 | churn_start_callback(void *cls, const struct GNUNET_PeerIdentity *id, | 5580 | churn_start_callback (void *cls, const struct GNUNET_PeerIdentity *id, |
5570 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 5581 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
5571 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 5582 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5572 | { | 5583 | { |
5573 | struct ChurnRestartContext *startup_ctx = cls; | 5584 | struct ChurnRestartContext *startup_ctx = cls; |
5574 | struct ChurnContext *churn_ctx = startup_ctx->churn_ctx; | 5585 | struct ChurnContext *churn_ctx = startup_ctx->churn_ctx; |
@@ -5578,59 +5589,58 @@ churn_start_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
5578 | 5589 | ||
5579 | error_message = NULL; | 5590 | error_message = NULL; |
5580 | if (emsg != NULL) | 5591 | if (emsg != NULL) |
5581 | { | 5592 | { |
5582 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 5593 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
5583 | "Churn stop callback failed with error `%s'\n", emsg); | 5594 | "Churn stop callback failed with error `%s'\n", emsg); |
5584 | churn_ctx->num_failed_start++; | 5595 | churn_ctx->num_failed_start++; |
5585 | } | 5596 | } |
5586 | else | 5597 | else |
5587 | { | 5598 | { |
5588 | churn_ctx->num_to_start--; | 5599 | churn_ctx->num_to_start--; |
5589 | } | 5600 | } |
5590 | 5601 | ||
5591 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) | 5602 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) |
5592 | + (churn_ctx->num_to_start - churn_ctx->num_failed_start); | 5603 | + (churn_ctx->num_to_start - churn_ctx->num_failed_start); |
5593 | 5604 | ||
5594 | if (total_left == 0) | 5605 | if (total_left == 0) |
5595 | { | 5606 | { |
5596 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) | 5607 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) |
5597 | GNUNET_asprintf ( | 5608 | GNUNET_asprintf (&error_message, |
5598 | &error_message, | 5609 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", |
5599 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", | 5610 | churn_ctx->num_failed_start, churn_ctx->num_failed_stop); |
5600 | churn_ctx->num_failed_start, | 5611 | churn_ctx->cb (churn_ctx->cb_cls, error_message); |
5601 | churn_ctx->num_failed_stop); | 5612 | GNUNET_free_non_null (error_message); |
5602 | churn_ctx->cb (churn_ctx->cb_cls, error_message); | 5613 | GNUNET_free (churn_ctx); |
5603 | GNUNET_free_non_null (error_message); | 5614 | GNUNET_free (startup_ctx); |
5604 | GNUNET_free (churn_ctx); | 5615 | } |
5605 | GNUNET_free (startup_ctx); | ||
5606 | } | ||
5607 | } | 5616 | } |
5608 | 5617 | ||
5609 | static void | 5618 | static void |
5610 | schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 5619 | schedule_churn_restart (void *cls, |
5620 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
5611 | { | 5621 | { |
5612 | struct PeerRestartContext *peer_restart_ctx = cls; | 5622 | struct PeerRestartContext *peer_restart_ctx = cls; |
5613 | struct ChurnRestartContext *startup_ctx = peer_restart_ctx->churn_restart_ctx; | 5623 | struct ChurnRestartContext *startup_ctx = peer_restart_ctx->churn_restart_ctx; |
5614 | 5624 | ||
5615 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) | 5625 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) |
5616 | GNUNET_SCHEDULER_add_delayed ( | 5626 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
5617 | GNUNET_TIME_relative_multiply ( | 5627 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
5618 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
5619 | 100), | ||
5620 | &schedule_churn_restart, peer_restart_ctx); | 5628 | &schedule_churn_restart, peer_restart_ctx); |
5621 | else | 5629 | else |
5622 | { | 5630 | { |
5623 | if (startup_ctx->churn_ctx->service != NULL) | 5631 | if (startup_ctx->churn_ctx->service != NULL) |
5624 | GNUNET_TESTING_daemon_start_stopped_service (peer_restart_ctx->daemon, | 5632 | GNUNET_TESTING_daemon_start_stopped_service (peer_restart_ctx->daemon, |
5625 | startup_ctx->churn_ctx->service, | 5633 | startup_ctx-> |
5626 | startup_ctx->timeout, | 5634 | churn_ctx->service, |
5627 | &churn_start_callback, startup_ctx); | 5635 | startup_ctx->timeout, |
5628 | else | 5636 | &churn_start_callback, |
5629 | GNUNET_TESTING_daemon_start_stopped (peer_restart_ctx->daemon, | 5637 | startup_ctx); |
5630 | startup_ctx->timeout, | 5638 | else |
5631 | &churn_start_callback, startup_ctx); | 5639 | GNUNET_TESTING_daemon_start_stopped (peer_restart_ctx->daemon, |
5632 | GNUNET_free (peer_restart_ctx); | 5640 | startup_ctx->timeout, |
5633 | } | 5641 | &churn_start_callback, startup_ctx); |
5642 | GNUNET_free (peer_restart_ctx); | ||
5643 | } | ||
5634 | } | 5644 | } |
5635 | 5645 | ||
5636 | /** | 5646 | /** |
@@ -5645,98 +5655,95 @@ schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5645 | * | 5655 | * |
5646 | */ | 5656 | */ |
5647 | void | 5657 | void |
5648 | service_start_callback(void *cls, | 5658 | service_start_callback (void *cls, |
5649 | const struct GNUNET_PeerIdentity *id, | 5659 | const struct GNUNET_PeerIdentity *id, |
5650 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 5660 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
5651 | struct GNUNET_TESTING_Daemon *d, | 5661 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
5652 | const char *emsg) | ||
5653 | { | 5662 | { |
5654 | struct ServiceStartContext *startup_ctx = (struct ServiceStartContext *)cls; | 5663 | struct ServiceStartContext *startup_ctx = (struct ServiceStartContext *) cls; |
5655 | 5664 | ||
5656 | if (emsg != NULL) | 5665 | if (emsg != NULL) |
5657 | { | 5666 | { |
5658 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 5667 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
5659 | "Service start failed with error `%s'\n", emsg); | 5668 | "Service start failed with error `%s'\n", emsg); |
5660 | } | 5669 | } |
5661 | 5670 | ||
5662 | startup_ctx->outstanding--; | 5671 | startup_ctx->outstanding--; |
5663 | startup_ctx->remaining--; | 5672 | startup_ctx->remaining--; |
5664 | 5673 | ||
5665 | if (startup_ctx->remaining == 0) | 5674 | if (startup_ctx->remaining == 0) |
5666 | { | 5675 | { |
5667 | startup_ctx->cb (startup_ctx->cb_cls, NULL); | 5676 | startup_ctx->cb (startup_ctx->cb_cls, NULL); |
5668 | GNUNET_free (startup_ctx->service); | 5677 | GNUNET_free (startup_ctx->service); |
5669 | GNUNET_free (startup_ctx); | 5678 | GNUNET_free (startup_ctx); |
5670 | } | 5679 | } |
5671 | } | 5680 | } |
5672 | 5681 | ||
5673 | static void | 5682 | static void |
5674 | schedule_service_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 5683 | schedule_service_start (void *cls, |
5684 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
5675 | { | 5685 | { |
5676 | struct PeerServiceStartContext *peer_ctx = cls; | 5686 | struct PeerServiceStartContext *peer_ctx = cls; |
5677 | struct ServiceStartContext *startup_ctx = peer_ctx->start_ctx; | 5687 | struct ServiceStartContext *startup_ctx = peer_ctx->start_ctx; |
5678 | 5688 | ||
5679 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) | 5689 | if (startup_ctx->outstanding > startup_ctx->pg->max_concurrent_ssh) |
5680 | GNUNET_SCHEDULER_add_delayed ( | 5690 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
5681 | GNUNET_TIME_relative_multiply ( | 5691 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
5682 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
5683 | 100), | ||
5684 | &schedule_service_start, peer_ctx); | 5692 | &schedule_service_start, peer_ctx); |
5685 | else | 5693 | else |
5686 | { | 5694 | { |
5687 | 5695 | ||
5688 | GNUNET_TESTING_daemon_start_service (peer_ctx->daemon, | 5696 | GNUNET_TESTING_daemon_start_service (peer_ctx->daemon, |
5689 | startup_ctx->service, | 5697 | startup_ctx->service, |
5690 | startup_ctx->timeout, | 5698 | startup_ctx->timeout, |
5691 | &service_start_callback, startup_ctx); | 5699 | &service_start_callback, startup_ctx); |
5692 | GNUNET_free (peer_ctx); | 5700 | GNUNET_free (peer_ctx); |
5693 | } | 5701 | } |
5694 | } | 5702 | } |
5695 | 5703 | ||
5696 | 5704 | ||
5697 | static void | 5705 | static void |
5698 | internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 5706 | internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
5699 | { | 5707 | { |
5700 | struct InternalStartContext *internal_context = cls; | 5708 | struct InternalStartContext *internal_context = cls; |
5701 | 5709 | ||
5702 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 5710 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
5703 | { | 5711 | { |
5704 | return; | 5712 | return; |
5705 | } | 5713 | } |
5706 | 5714 | ||
5707 | if ((internal_context->peer->pg->starting | 5715 | if ((internal_context->peer->pg->starting |
5708 | < internal_context->peer->pg->max_concurrent_ssh) | 5716 | < internal_context->peer->pg->max_concurrent_ssh) |
5709 | || ((internal_context->hostname != NULL) | 5717 | || ((internal_context->hostname != NULL) |
5710 | && (count_outstanding_at_host (internal_context->hostname, | 5718 | && (count_outstanding_at_host (internal_context->hostname, |
5711 | internal_context->peer->pg) | 5719 | internal_context->peer->pg) |
5712 | < internal_context->peer->pg->max_concurrent_ssh))) | 5720 | < internal_context->peer->pg->max_concurrent_ssh))) |
5713 | { | 5721 | { |
5714 | if (internal_context->hostname != NULL) | 5722 | if (internal_context->hostname != NULL) |
5715 | increment_outstanding_at_host (internal_context->hostname, | 5723 | increment_outstanding_at_host (internal_context->hostname, |
5716 | internal_context->peer->pg); | 5724 | internal_context->peer->pg); |
5717 | internal_context->peer->pg->starting++; | 5725 | internal_context->peer->pg->starting++; |
5718 | internal_context->peer->daemon | 5726 | internal_context->peer->daemon |
5719 | = GNUNET_TESTING_daemon_start (internal_context->peer->cfg, | 5727 | = GNUNET_TESTING_daemon_start (internal_context->peer->cfg, |
5720 | internal_context->timeout, | 5728 | internal_context->timeout, |
5721 | GNUNET_NO, | 5729 | GNUNET_NO, |
5722 | internal_context->hostname, | 5730 | internal_context->hostname, |
5723 | internal_context->username, | 5731 | internal_context->username, |
5724 | internal_context->sshport, | 5732 | internal_context->sshport, |
5725 | internal_context->hostkey, | 5733 | internal_context->hostkey, |
5726 | &internal_hostkey_callback, | 5734 | &internal_hostkey_callback, |
5727 | internal_context, | 5735 | internal_context, |
5728 | &internal_startup_callback, | 5736 | &internal_startup_callback, |
5729 | internal_context); | 5737 | internal_context); |
5730 | } | 5738 | } |
5731 | else | 5739 | else |
5732 | { | 5740 | { |
5733 | GNUNET_SCHEDULER_add_delayed ( | 5741 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
5734 | GNUNET_TIME_relative_multiply ( | 5742 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
5735 | GNUNET_TIME_UNIT_MILLISECONDS, | 5743 | &internal_start, internal_context); |
5736 | 100), | 5744 | } |
5737 | &internal_start, internal_context); | ||
5738 | } | ||
5739 | } | 5745 | } |
5746 | |||
5740 | #if USE_START_HELPER | 5747 | #if USE_START_HELPER |
5741 | 5748 | ||
5742 | struct PeerStartHelperContext | 5749 | struct PeerStartHelperContext |
@@ -5757,40 +5764,41 @@ check_peers_started (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5757 | unsigned int i; | 5764 | unsigned int i; |
5758 | GNUNET_TESTING_NotifyDaemonRunning cb; | 5765 | GNUNET_TESTING_NotifyDaemonRunning cb; |
5759 | 5766 | ||
5760 | if (GNUNET_NO == GNUNET_OS_process_status (helper->proc, &type, &code)) /* Still running, wait some more! */ | 5767 | if (GNUNET_NO == GNUNET_OS_process_status (helper->proc, &type, &code)) /* Still running, wait some more! */ |
5761 | { | 5768 | { |
5762 | GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_EXEC_WAIT, &check_peers_started, helper); | 5769 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, |
5770 | &check_peers_started, helper); | ||
5763 | return; | 5771 | return; |
5764 | } | 5772 | } |
5765 | 5773 | ||
5766 | helper->pg->starting--; | 5774 | helper->pg->starting--; |
5767 | if (helper->pg->starting == 0) /* All peers have finished starting! */ | 5775 | if (helper->pg->starting == 0) /* All peers have finished starting! */ |
5768 | { | 5776 | { |
5769 | /* Call the peer started callback for each peer, set proper FSM state (?) */ | 5777 | /* Call the peer started callback for each peer, set proper FSM state (?) */ |
5770 | for (i = 0; i < helper->pg->total; i++) | 5778 | for (i = 0; i < helper->pg->total; i++) |
5771 | { | 5779 | { |
5772 | cb = helper->pg->peers[i].daemon->cb; | 5780 | cb = helper->pg->peers[i].daemon->cb; |
5773 | helper->pg->peers[i].daemon->cb = NULL; | 5781 | helper->pg->peers[i].daemon->cb = NULL; |
5774 | helper->pg->peers[i].daemon->running = GNUNET_YES; | 5782 | helper->pg->peers[i].daemon->running = GNUNET_YES; |
5775 | helper->pg->peers[i].daemon->phase = SP_START_DONE; | 5783 | helper->pg->peers[i].daemon->phase = SP_START_DONE; |
5776 | if (NULL != cb) | 5784 | if (NULL != cb) |
5777 | { | 5785 | { |
5778 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | 5786 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) |
5779 | cb (helper->pg->peers[i].daemon->cb_cls, | 5787 | cb (helper->pg->peers[i].daemon->cb_cls, |
5780 | &helper->pg->peers[i].daemon->id, | 5788 | &helper->pg->peers[i].daemon->id, |
5781 | helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon, | 5789 | helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon, |
5782 | "Failed to execute peerStartHelper.pl, or return code bad!"); | 5790 | "Failed to execute peerStartHelper.pl, or return code bad!"); |
5783 | else | 5791 | else |
5784 | cb (helper->pg->peers[i].daemon->cb_cls, | 5792 | cb (helper->pg->peers[i].daemon->cb_cls, |
5785 | &helper->pg->peers[i].daemon->id, | 5793 | &helper->pg->peers[i].daemon->id, |
5786 | helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon, | 5794 | helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon, |
5787 | NULL); | 5795 | NULL); |
5788 | 5796 | ||
5789 | } | 5797 | } |
5790 | 5798 | ||
5791 | } | ||
5792 | } | 5799 | } |
5793 | GNUNET_OS_process_close(helper->proc); | 5800 | } |
5801 | GNUNET_OS_process_close (helper->proc); | ||
5794 | } | 5802 | } |
5795 | 5803 | ||
5796 | static void | 5804 | static void |
@@ -5800,20 +5808,26 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5800 | char *baseservicehome; | 5808 | char *baseservicehome; |
5801 | char *tempdir; | 5809 | char *tempdir; |
5802 | char *arg; | 5810 | char *arg; |
5811 | |||
5803 | /* ssh user@host peerStartHelper /path/to/basedirectory */ | 5812 | /* ssh user@host peerStartHelper /path/to/basedirectory */ |
5804 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (helper->pg->cfg, "PATHS", "SERVICEHOME", | 5813 | GNUNET_assert (GNUNET_OK == |
5805 | &baseservicehome)); | 5814 | GNUNET_CONFIGURATION_get_value_string (helper->pg->cfg, |
5806 | GNUNET_asprintf(&tempdir, "%s/%s/", baseservicehome, helper->host->hostname); | 5815 | "PATHS", "SERVICEHOME", |
5816 | &baseservicehome)); | ||
5817 | GNUNET_asprintf (&tempdir, "%s/%s/", baseservicehome, helper->host->hostname); | ||
5807 | if (NULL != helper->host->username) | 5818 | if (NULL != helper->host->username) |
5808 | GNUNET_asprintf (&arg, "%s@%s", helper->host->username, helper->host->hostname); | 5819 | GNUNET_asprintf (&arg, "%s@%s", helper->host->username, |
5820 | helper->host->hostname); | ||
5809 | else | 5821 | else |
5810 | GNUNET_asprintf (&arg, "%s", helper->host->hostname); | 5822 | GNUNET_asprintf (&arg, "%s", helper->host->hostname); |
5811 | 5823 | ||
5812 | /* FIXME: Doesn't support ssh_port option! */ | 5824 | /* FIXME: Doesn't support ssh_port option! */ |
5813 | helper->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, | 5825 | helper->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, |
5814 | "peerStartHelper.pl", tempdir, NULL); | 5826 | "peerStartHelper.pl", tempdir, NULL); |
5815 | GNUNET_assert(helper->proc != NULL); | 5827 | GNUNET_assert (helper->proc != NULL); |
5816 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "starting peers with cmd ssh %s %s %s\n", arg, "peerStartHelper.pl", tempdir); | 5828 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
5829 | "starting peers with cmd ssh %s %s %s\n", arg, | ||
5830 | "peerStartHelper.pl", tempdir); | ||
5817 | GNUNET_SCHEDULER_add_now (&check_peers_started, helper); | 5831 | GNUNET_SCHEDULER_add_now (&check_peers_started, helper); |
5818 | GNUNET_free (tempdir); | 5832 | GNUNET_free (tempdir); |
5819 | GNUNET_free (baseservicehome); | 5833 | GNUNET_free (baseservicehome); |
@@ -5829,56 +5843,61 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5829 | * | 5843 | * |
5830 | */ | 5844 | */ |
5831 | void | 5845 | void |
5832 | GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg) | 5846 | GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg) |
5833 | { | 5847 | { |
5834 | unsigned int i; | 5848 | unsigned int i; |
5835 | 5849 | ||
5836 | #if USE_START_HELPER | 5850 | #if USE_START_HELPER |
5837 | if ((pg->num_hosts > 0) && (pg->hostkey_data != NULL)) | 5851 | if ((pg->num_hosts > 0) && (pg->hostkey_data != NULL)) |
5852 | { | ||
5853 | struct PeerStartHelperContext *helper; | ||
5854 | |||
5855 | pg->starting = pg->num_hosts; | ||
5856 | for (i = 0; i < pg->num_hosts; i++) | ||
5838 | { | 5857 | { |
5839 | struct PeerStartHelperContext *helper; | 5858 | helper = GNUNET_malloc (sizeof (struct PeerStartHelperContext)); |
5840 | pg->starting = pg->num_hosts; | 5859 | helper->pg = pg; |
5841 | for (i = 0; i < pg->num_hosts; i++) | 5860 | helper->host = &pg->hosts[i]; |
5842 | { | 5861 | GNUNET_SCHEDULER_add_now (&start_peer_helper, helper); |
5843 | helper = GNUNET_malloc(sizeof(struct PeerStartHelperContext)); | ||
5844 | helper->pg = pg; | ||
5845 | helper->host = &pg->hosts[i]; | ||
5846 | GNUNET_SCHEDULER_add_now(&start_peer_helper, helper); | ||
5847 | } | ||
5848 | } | 5862 | } |
5863 | } | ||
5849 | else | 5864 | else |
5865 | { | ||
5866 | pg->starting = 0; | ||
5867 | for (i = 0; i < pg->total; i++) | ||
5850 | { | 5868 | { |
5851 | pg->starting = 0; | 5869 | GNUNET_SCHEDULER_add_now (&internal_continue_startup, |
5852 | for (i = 0; i < pg->total; i++) | 5870 | &pg->peers[i].internal_context); |
5853 | { | ||
5854 | GNUNET_SCHEDULER_add_now (&internal_continue_startup, | ||
5855 | &pg->peers[i].internal_context); | ||
5856 | } | ||
5857 | } | 5871 | } |
5872 | } | ||
5858 | #else | 5873 | #else |
5859 | pg->starting = 0; | 5874 | pg->starting = 0; |
5860 | for (i = 0; i < pg->total; i++) | 5875 | for (i = 0; i < pg->total; i++) |
5861 | { | 5876 | { |
5862 | GNUNET_SCHEDULER_add_now (&internal_continue_startup, | 5877 | GNUNET_SCHEDULER_add_now (&internal_continue_startup, |
5863 | &pg->peers[i].internal_context); | 5878 | &pg->peers[i].internal_context); |
5864 | } | 5879 | } |
5865 | #endif | 5880 | #endif |
5866 | } | 5881 | } |
5867 | 5882 | ||
5868 | #if USE_START_HELPER | 5883 | #if USE_START_HELPER |
5869 | static void | 5884 | static void |
5870 | call_hostkey_callbacks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 5885 | call_hostkey_callbacks (void *cls, |
5886 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
5871 | { | 5887 | { |
5872 | struct GNUNET_TESTING_PeerGroup *pg = cls; | 5888 | struct GNUNET_TESTING_PeerGroup *pg = cls; |
5873 | unsigned int i; | 5889 | unsigned int i; |
5890 | |||
5874 | for (i = 0; i < pg->total; i++) | 5891 | for (i = 0; i < pg->total; i++) |
5875 | { | 5892 | { |
5876 | if (pg->peers[i].internal_context.hostkey_callback != NULL) | 5893 | if (pg->peers[i].internal_context.hostkey_callback != NULL) |
5877 | pg->peers[i].internal_context.hostkey_callback (pg->peers[i].internal_context.hostkey_cls, | 5894 | pg->peers[i].internal_context.hostkey_callback (pg->peers |
5878 | &pg->peers[i].daemon->id, | 5895 | [i]. |
5879 | pg->peers[i].daemon, | 5896 | internal_context.hostkey_cls, |
5880 | NULL); | 5897 | &pg->peers[i].daemon->id, |
5881 | } | 5898 | pg->peers[i].daemon, |
5899 | NULL); | ||
5900 | } | ||
5882 | 5901 | ||
5883 | if (pg->peers[0].internal_context.hostkey_callback == NULL) | 5902 | if (pg->peers[0].internal_context.hostkey_callback == NULL) |
5884 | GNUNET_TESTING_daemons_continue_startup (pg); | 5903 | GNUNET_TESTING_daemons_continue_startup (pg); |
@@ -5913,18 +5932,18 @@ call_hostkey_callbacks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
5913 | * @return NULL on error, otherwise handle to control peer group | 5932 | * @return NULL on error, otherwise handle to control peer group |
5914 | */ | 5933 | */ |
5915 | struct GNUNET_TESTING_PeerGroup * | 5934 | struct GNUNET_TESTING_PeerGroup * |
5916 | GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | 5935 | GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
5917 | unsigned int total, | 5936 | unsigned int total, |
5918 | unsigned int max_concurrent_connections, | 5937 | unsigned int max_concurrent_connections, |
5919 | unsigned int max_concurrent_ssh, | 5938 | unsigned int max_concurrent_ssh, |
5920 | struct GNUNET_TIME_Relative timeout, | 5939 | struct GNUNET_TIME_Relative timeout, |
5921 | GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback, | 5940 | GNUNET_TESTING_NotifyHostkeyCreated |
5922 | void *hostkey_cls, | 5941 | hostkey_callback, void *hostkey_cls, |
5923 | GNUNET_TESTING_NotifyDaemonRunning cb, | 5942 | GNUNET_TESTING_NotifyDaemonRunning cb, |
5924 | void *cb_cls, | 5943 | void *cb_cls, |
5925 | GNUNET_TESTING_NotifyConnection connect_callback, | 5944 | GNUNET_TESTING_NotifyConnection connect_callback, |
5926 | void *connect_callback_cls, | 5945 | void *connect_callback_cls, |
5927 | const struct GNUNET_TESTING_Host *hostnames) | 5946 | const struct GNUNET_TESTING_Host *hostnames) |
5928 | { | 5947 | { |
5929 | struct GNUNET_TESTING_PeerGroup *pg; | 5948 | struct GNUNET_TESTING_PeerGroup *pg; |
5930 | const struct GNUNET_TESTING_Host *hostpos; | 5949 | const struct GNUNET_TESTING_Host *hostpos; |
@@ -5952,10 +5971,10 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5952 | 5971 | ||
5953 | username = NULL; | 5972 | username = NULL; |
5954 | if (0 == total) | 5973 | if (0 == total) |
5955 | { | 5974 | { |
5956 | GNUNET_break (0); | 5975 | GNUNET_break (0); |
5957 | return NULL; | 5976 | return NULL; |
5958 | } | 5977 | } |
5959 | 5978 | ||
5960 | upnum = 0; | 5979 | upnum = 0; |
5961 | fdnum = 0; | 5980 | fdnum = 0; |
@@ -5969,227 +5988,225 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
5969 | pg->max_outstanding_connections = max_concurrent_connections; | 5988 | pg->max_outstanding_connections = max_concurrent_connections; |
5970 | pg->max_concurrent_ssh = max_concurrent_ssh; | 5989 | pg->max_concurrent_ssh = max_concurrent_ssh; |
5971 | if (NULL != hostnames) | 5990 | if (NULL != hostnames) |
5991 | { | ||
5992 | off = 0; | ||
5993 | hostpos = hostnames; | ||
5994 | while (hostpos != NULL) | ||
5972 | { | 5995 | { |
5973 | off = 0; | 5996 | hostpos = hostpos->next; |
5974 | hostpos = hostnames; | 5997 | off++; |
5975 | while (hostpos != NULL) | 5998 | } |
5976 | { | 5999 | pg->hosts = GNUNET_malloc (off * sizeof (struct HostData)); |
5977 | hostpos = hostpos->next; | 6000 | off = 0; |
5978 | off++; | ||
5979 | } | ||
5980 | pg->hosts = GNUNET_malloc (off * sizeof (struct HostData)); | ||
5981 | off = 0; | ||
5982 | |||
5983 | hostpos = hostnames; | ||
5984 | while (hostpos != NULL) | ||
5985 | { | ||
5986 | pg->hosts[off].minport = LOW_PORT; | ||
5987 | pg->hosts[off].hostname = GNUNET_strdup (hostpos->hostname); | ||
5988 | if (hostpos->username != NULL) | ||
5989 | pg->hosts[off].username = GNUNET_strdup (hostpos->username); | ||
5990 | pg->hosts[off].sshport = hostpos->port; | ||
5991 | hostpos = hostpos->next; | ||
5992 | off++; | ||
5993 | } | ||
5994 | 6001 | ||
5995 | if (off == 0) | 6002 | hostpos = hostnames; |
5996 | { | 6003 | while (hostpos != NULL) |
5997 | pg->hosts = NULL; | 6004 | { |
5998 | } | 6005 | pg->hosts[off].minport = LOW_PORT; |
5999 | hostcnt = off; | 6006 | pg->hosts[off].hostname = GNUNET_strdup (hostpos->hostname); |
6000 | minport = 0; | 6007 | if (hostpos->username != NULL) |
6001 | pg->num_hosts = off; | 6008 | pg->hosts[off].username = GNUNET_strdup (hostpos->username); |
6009 | pg->hosts[off].sshport = hostpos->port; | ||
6010 | hostpos = hostpos->next; | ||
6011 | off++; | ||
6002 | } | 6012 | } |
6003 | else | 6013 | |
6014 | if (off == 0) | ||
6004 | { | 6015 | { |
6005 | hostcnt = 0; | 6016 | pg->hosts = NULL; |
6006 | minport = LOW_PORT; | ||
6007 | } | 6017 | } |
6018 | hostcnt = off; | ||
6019 | minport = 0; | ||
6020 | pg->num_hosts = off; | ||
6021 | } | ||
6022 | else | ||
6023 | { | ||
6024 | hostcnt = 0; | ||
6025 | minport = LOW_PORT; | ||
6026 | } | ||
6008 | 6027 | ||
6009 | /* Create the servicehome directory for each remote peer */ | 6028 | /* Create the servicehome directory for each remote peer */ |
6010 | GNUNET_assert(GNUNET_OK == | 6029 | GNUNET_assert (GNUNET_OK == |
6011 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", | 6030 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", |
6012 | &baseservicehome)); | 6031 | "SERVICEHOME", |
6032 | &baseservicehome)); | ||
6013 | for (i = 0; i < pg->num_hosts; i++) | 6033 | for (i = 0; i < pg->num_hosts; i++) |
6034 | { | ||
6035 | ssh_entry = GNUNET_malloc (sizeof (struct OutstandingSSH)); | ||
6036 | ssh_entry->hostname = pg->hosts[i].hostname; /* Don't free! */ | ||
6037 | GNUNET_CONTAINER_DLL_insert (pg->ssh_head, pg->ssh_tail, ssh_entry); | ||
6038 | GNUNET_asprintf (&tmpdir, "%s/%s", baseservicehome, pg->hosts[i].hostname); | ||
6039 | if (NULL != pg->hosts[i].username) | ||
6040 | GNUNET_asprintf (&arg, "%s@%s", pg->hosts[i].username, | ||
6041 | pg->hosts[i].hostname); | ||
6042 | else | ||
6043 | GNUNET_asprintf (&arg, "%s", pg->hosts[i].hostname); | ||
6044 | if (pg->hosts[i].sshport != 0) | ||
6014 | { | 6045 | { |
6015 | ssh_entry = GNUNET_malloc(sizeof(struct OutstandingSSH)); | 6046 | GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport); |
6016 | ssh_entry->hostname = pg->hosts[i].hostname; /* Don't free! */ | 6047 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P", |
6017 | GNUNET_CONTAINER_DLL_insert(pg->ssh_head, pg->ssh_tail, ssh_entry); | 6048 | ssh_port_str, |
6018 | GNUNET_asprintf(&tmpdir, "%s/%s", baseservicehome, pg->hosts[i].hostname); | ||
6019 | if (NULL != pg->hosts[i].username) | ||
6020 | GNUNET_asprintf (&arg, "%s@%s", pg->hosts[i].username, | ||
6021 | pg->hosts[i].hostname); | ||
6022 | else | ||
6023 | GNUNET_asprintf (&arg, "%s", pg->hosts[i].hostname); | ||
6024 | if (pg->hosts[i].sshport != 0) | ||
6025 | { | ||
6026 | GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport); | ||
6027 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P", | ||
6028 | ssh_port_str, | ||
6029 | #if !DEBUG_TESTING | 6049 | #if !DEBUG_TESTING |
6030 | "-q", | 6050 | "-q", |
6031 | #endif | 6051 | #endif |
6032 | arg, "mkdir -p", tmpdir, | 6052 | arg, "mkdir -p", tmpdir, NULL); |
6033 | NULL); | ||
6034 | } | ||
6035 | else | ||
6036 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, | ||
6037 | "mkdir -p", tmpdir, NULL); | ||
6038 | GNUNET_assert(proc != NULL); | ||
6039 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
6040 | "Creating remote dir with command ssh %s %s %s\n", arg, | ||
6041 | " mkdir -p ", tmpdir); | ||
6042 | GNUNET_free(tmpdir); | ||
6043 | GNUNET_free(arg); | ||
6044 | GNUNET_OS_process_wait (proc); | ||
6045 | GNUNET_OS_process_close(proc); | ||
6046 | } | 6053 | } |
6047 | GNUNET_free(baseservicehome); | 6054 | else |
6055 | proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, | ||
6056 | "mkdir -p", tmpdir, NULL); | ||
6057 | GNUNET_assert (proc != NULL); | ||
6058 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
6059 | "Creating remote dir with command ssh %s %s %s\n", arg, | ||
6060 | " mkdir -p ", tmpdir); | ||
6061 | GNUNET_free (tmpdir); | ||
6062 | GNUNET_free (arg); | ||
6063 | GNUNET_OS_process_wait (proc); | ||
6064 | GNUNET_OS_process_close (proc); | ||
6065 | } | ||
6066 | GNUNET_free (baseservicehome); | ||
6048 | baseservicehome = NULL; | 6067 | baseservicehome = NULL; |
6049 | 6068 | ||
6050 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", | 6069 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", |
6051 | "HOSTKEYSFILE", | 6070 | "HOSTKEYSFILE", |
6052 | &hostkeys_file)) | 6071 | &hostkeys_file)) |
6072 | { | ||
6073 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) | ||
6074 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6075 | _("Could not read hostkeys file!\n")); | ||
6076 | else | ||
6053 | { | 6077 | { |
6054 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) | 6078 | /* Check hostkey file size, read entire thing into memory */ |
6055 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6079 | fd = GNUNET_DISK_file_open (hostkeys_file, |
6056 | _("Could not read hostkeys file!\n")); | 6080 | GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); |
6057 | else | 6081 | if (NULL == fd) |
6082 | { | ||
6083 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
6084 | "open", hostkeys_file); | ||
6085 | GNUNET_free (hostkeys_file); | ||
6086 | for (i = 0; i < pg->num_hosts; i++) | ||
6058 | { | 6087 | { |
6059 | /* Check hostkey file size, read entire thing into memory */ | 6088 | GNUNET_free (pg->hosts[i].hostname); |
6060 | fd = GNUNET_DISK_file_open (hostkeys_file, | 6089 | GNUNET_free_non_null (pg->hosts[i].username); |
6061 | GNUNET_DISK_OPEN_READ, | ||
6062 | GNUNET_DISK_PERM_NONE); | ||
6063 | if (NULL == fd) | ||
6064 | { | ||
6065 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
6066 | "open", | ||
6067 | hostkeys_file); | ||
6068 | GNUNET_free (hostkeys_file); | ||
6069 | for (i=0;i<pg->num_hosts;i++) | ||
6070 | { | ||
6071 | GNUNET_free (pg->hosts[i].hostname); | ||
6072 | GNUNET_free_non_null (pg->hosts[i].username); | ||
6073 | } | ||
6074 | GNUNET_free (pg->peers); | ||
6075 | GNUNET_free (pg->hosts); | ||
6076 | GNUNET_free (pg); | ||
6077 | return NULL; | ||
6078 | } | ||
6079 | |||
6080 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, | ||
6081 | GNUNET_YES)) | ||
6082 | fs = 0; | ||
6083 | |||
6084 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6085 | "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", | ||
6086 | fs, HOSTKEYFILESIZE); | ||
6087 | |||
6088 | if (0 != (fs % HOSTKEYFILESIZE)) | ||
6089 | { | ||
6090 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6091 | "File size %llu seems incorrect for hostkeys...\n", | ||
6092 | fs); | ||
6093 | } | ||
6094 | else | ||
6095 | { | ||
6096 | total_hostkeys = fs / HOSTKEYFILESIZE; | ||
6097 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6098 | "Will read %llu hostkeys from file\n", | ||
6099 | total_hostkeys); | ||
6100 | pg->hostkey_data = GNUNET_malloc_large (fs); | ||
6101 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs)); | ||
6102 | } | ||
6103 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd)); | ||
6104 | } | 6090 | } |
6105 | GNUNET_free(hostkeys_file); | 6091 | GNUNET_free (pg->peers); |
6092 | GNUNET_free (pg->hosts); | ||
6093 | GNUNET_free (pg); | ||
6094 | return NULL; | ||
6095 | } | ||
6096 | |||
6097 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES)) | ||
6098 | fs = 0; | ||
6099 | |||
6100 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6101 | "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", | ||
6102 | fs, HOSTKEYFILESIZE); | ||
6103 | |||
6104 | if (0 != (fs % HOSTKEYFILESIZE)) | ||
6105 | { | ||
6106 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6107 | "File size %llu seems incorrect for hostkeys...\n", fs); | ||
6108 | } | ||
6109 | else | ||
6110 | { | ||
6111 | total_hostkeys = fs / HOSTKEYFILESIZE; | ||
6112 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6113 | "Will read %llu hostkeys from file\n", total_hostkeys); | ||
6114 | pg->hostkey_data = GNUNET_malloc_large (fs); | ||
6115 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs)); | ||
6116 | } | ||
6117 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
6106 | } | 6118 | } |
6119 | GNUNET_free (hostkeys_file); | ||
6120 | } | ||
6107 | 6121 | ||
6108 | for (off = 0; off < total; off++) | 6122 | for (off = 0; off < total; off++) |
6123 | { | ||
6124 | if (hostcnt > 0) | ||
6109 | { | 6125 | { |
6110 | if (hostcnt > 0) | 6126 | hostname = pg->hosts[off % hostcnt].hostname; |
6111 | { | 6127 | username = pg->hosts[off % hostcnt].username; |
6112 | hostname = pg->hosts[off % hostcnt].hostname; | 6128 | sshport = pg->hosts[off % hostcnt].sshport; |
6113 | username = pg->hosts[off % hostcnt].username; | 6129 | pcfg = make_config (cfg, off, &pg->hosts[off % hostcnt].minport, |
6114 | sshport = pg->hosts[off % hostcnt].sshport; | 6130 | &upnum, hostname, &fdnum); |
6115 | pcfg = make_config (cfg, off, &pg->hosts[off % hostcnt].minport, | 6131 | } |
6116 | &upnum, hostname, &fdnum); | 6132 | else |
6117 | } | 6133 | { |
6118 | else | 6134 | hostname = NULL; |
6119 | { | 6135 | username = NULL; |
6120 | hostname = NULL; | 6136 | sshport = 0; |
6121 | username = NULL; | 6137 | pcfg = make_config (cfg, off, &minport, &upnum, hostname, &fdnum); |
6122 | sshport = 0; | 6138 | } |
6123 | pcfg = make_config (cfg, off, &minport, &upnum, hostname, &fdnum); | ||
6124 | } | ||
6125 | 6139 | ||
6126 | if (NULL == pcfg) | 6140 | if (NULL == pcfg) |
6127 | { | 6141 | { |
6128 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6142 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6129 | _("Could not create configuration for peer number %u on `%s'!\n"), | 6143 | _ |
6130 | off, | 6144 | ("Could not create configuration for peer number %u on `%s'!\n"), |
6131 | hostname == NULL ? "localhost" : hostname); | 6145 | off, hostname == NULL ? "localhost" : hostname); |
6132 | continue; | 6146 | continue; |
6133 | } | 6147 | } |
6134 | 6148 | ||
6135 | if (GNUNET_YES | 6149 | if (GNUNET_YES |
6136 | == GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", | 6150 | == GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", |
6137 | "SERVICEHOME", | 6151 | "SERVICEHOME", |
6138 | &baseservicehome)) | 6152 | &baseservicehome)) |
6139 | { | 6153 | { |
6140 | if (hostname != NULL) | 6154 | if (hostname != NULL) |
6141 | GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome, hostname, off); | 6155 | GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome, |
6142 | else | 6156 | hostname, off); |
6143 | GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off); | ||
6144 | GNUNET_free (baseservicehome); | ||
6145 | baseservicehome = NULL; | ||
6146 | } | ||
6147 | else | 6157 | else |
6148 | { | 6158 | GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off); |
6149 | tmpdir = getenv ("TMPDIR"); | 6159 | GNUNET_free (baseservicehome); |
6150 | tmpdir = tmpdir ? tmpdir : "/tmp"; | 6160 | baseservicehome = NULL; |
6151 | if (hostname != NULL) | 6161 | } |
6152 | GNUNET_asprintf (&newservicehome, "%s/%s/%s/%d/", tmpdir, hostname, | 6162 | else |
6153 | "gnunet-testing-test-test", off); | 6163 | { |
6154 | else | 6164 | tmpdir = getenv ("TMPDIR"); |
6155 | GNUNET_asprintf (&newservicehome, "%s/%s/%d/", tmpdir, | 6165 | tmpdir = tmpdir ? tmpdir : "/tmp"; |
6156 | "gnunet-testing-test-test", off); | 6166 | if (hostname != NULL) |
6157 | } | 6167 | GNUNET_asprintf (&newservicehome, "%s/%s/%s/%d/", tmpdir, hostname, |
6158 | GNUNET_CONFIGURATION_set_value_string (pcfg, "PATHS", "SERVICEHOME", | 6168 | "gnunet-testing-test-test", off); |
6159 | newservicehome); | 6169 | else |
6160 | GNUNET_free (newservicehome); | 6170 | GNUNET_asprintf (&newservicehome, "%s/%s/%d/", tmpdir, |
6161 | pg->peers[off].cfg = pcfg; | 6171 | "gnunet-testing-test-test", off); |
6162 | pg->peers[off].pg = pg; | 6172 | } |
6163 | pg->peers[off].internal_context.peer = &pg->peers[off]; | 6173 | GNUNET_CONFIGURATION_set_value_string (pcfg, "PATHS", "SERVICEHOME", |
6164 | pg->peers[off].internal_context.timeout = timeout; | 6174 | newservicehome); |
6165 | pg->peers[off].internal_context.hostname = hostname; | 6175 | GNUNET_free (newservicehome); |
6166 | pg->peers[off].internal_context.username = username; | 6176 | pg->peers[off].cfg = pcfg; |
6167 | pg->peers[off].internal_context.sshport = sshport; | 6177 | pg->peers[off].pg = pg; |
6168 | if (pg->hostkey_data != NULL) | 6178 | pg->peers[off].internal_context.peer = &pg->peers[off]; |
6169 | pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off | 6179 | pg->peers[off].internal_context.timeout = timeout; |
6170 | * HOSTKEYFILESIZE]; | 6180 | pg->peers[off].internal_context.hostname = hostname; |
6171 | pg->peers[off].internal_context.hostkey_callback = hostkey_callback; | 6181 | pg->peers[off].internal_context.username = username; |
6172 | pg->peers[off].internal_context.hostkey_cls = hostkey_cls; | 6182 | pg->peers[off].internal_context.sshport = sshport; |
6173 | pg->peers[off].internal_context.start_cb = cb; | 6183 | if (pg->hostkey_data != NULL) |
6174 | pg->peers[off].internal_context.start_cb_cls = cb_cls; | 6184 | pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off |
6185 | * | ||
6186 | HOSTKEYFILESIZE]; | ||
6187 | pg->peers[off].internal_context.hostkey_callback = hostkey_callback; | ||
6188 | pg->peers[off].internal_context.hostkey_cls = hostkey_cls; | ||
6189 | pg->peers[off].internal_context.start_cb = cb; | ||
6190 | pg->peers[off].internal_context.start_cb_cls = cb_cls; | ||
6175 | #if !USE_START_HELPER | 6191 | #if !USE_START_HELPER |
6176 | GNUNET_SCHEDULER_add_now (&internal_start, | 6192 | GNUNET_SCHEDULER_add_now (&internal_start, |
6177 | &pg->peers[off].internal_context); | 6193 | &pg->peers[off].internal_context); |
6178 | #else | 6194 | #else |
6179 | if ((pg->hostkey_data != NULL) && (hostcnt > 0)) | 6195 | if ((pg->hostkey_data != NULL) && (hostcnt > 0)) |
6180 | { | 6196 | { |
6181 | pg->peers[off].daemon | 6197 | pg->peers[off].daemon |
6182 | = GNUNET_TESTING_daemon_start (pcfg, | 6198 | = GNUNET_TESTING_daemon_start (pcfg, |
6183 | timeout, | 6199 | timeout, |
6184 | GNUNET_YES, | 6200 | GNUNET_YES, |
6185 | hostname, | 6201 | hostname, |
6186 | username, | 6202 | username, |
6187 | sshport, | 6203 | sshport, |
6188 | pg->peers[off].internal_context.hostkey, | 6204 | pg->peers[off]. |
6189 | &internal_hostkey_callback, | 6205 | internal_context.hostkey, |
6190 | &pg->peers[off].internal_context, | 6206 | &internal_hostkey_callback, |
6191 | &internal_startup_callback, | 6207 | &pg->peers[off].internal_context, |
6192 | &pg->peers[off].internal_context); | 6208 | &internal_startup_callback, |
6209 | &pg->peers[off].internal_context); | ||
6193 | /** | 6210 | /** |
6194 | * At this point, given that we had a hostkeyfile, | 6211 | * At this point, given that we had a hostkeyfile, |
6195 | * we can call the hostkey callback! | 6212 | * we can call the hostkey callback! |
@@ -6199,95 +6216,94 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
6199 | * then set pg->whatever_phase for each peer and let them | 6216 | * then set pg->whatever_phase for each peer and let them |
6200 | * enter the fsm to get the HELLO's for peers and start connecting. | 6217 | * enter the fsm to get the HELLO's for peers and start connecting. |
6201 | */ | 6218 | */ |
6202 | } | 6219 | } |
6203 | else | 6220 | else |
6204 | { | 6221 | { |
6205 | GNUNET_SCHEDULER_add_now (&internal_start, | 6222 | GNUNET_SCHEDULER_add_now (&internal_start, |
6206 | &pg->peers[off].internal_context); | 6223 | &pg->peers[off].internal_context); |
6207 | } | 6224 | } |
6208 | 6225 | ||
6209 | #endif | 6226 | #endif |
6210 | } | 6227 | } |
6211 | 6228 | ||
6212 | #if USE_START_HELPER /* Now the peergroup has been set up, hostkeys and configs written to files. */ | 6229 | #if USE_START_HELPER /* Now the peergroup has been set up, hostkeys and configs written to files. */ |
6213 | if ((pg->hostkey_data != NULL) && (hostcnt > 0)) | 6230 | if ((pg->hostkey_data != NULL) && (hostcnt > 0)) |
6231 | { | ||
6232 | for (off = 0; off < hostcnt; off++) | ||
6214 | { | 6233 | { |
6215 | for (off = 0; off < hostcnt; off++) | ||
6216 | { | ||
6217 | 6234 | ||
6218 | if (hostcnt > 0) | 6235 | if (hostcnt > 0) |
6219 | { | 6236 | { |
6220 | hostname = pg->hosts[off % hostcnt].hostname; | 6237 | hostname = pg->hosts[off % hostcnt].hostname; |
6221 | username = pg->hosts[off % hostcnt].username; | 6238 | username = pg->hosts[off % hostcnt].username; |
6222 | sshport = pg->hosts[off % hostcnt].sshport; | 6239 | sshport = pg->hosts[off % hostcnt].sshport; |
6223 | } | 6240 | } |
6224 | else | 6241 | else |
6225 | { | 6242 | { |
6226 | hostname = NULL; | 6243 | hostname = NULL; |
6227 | username = NULL; | 6244 | username = NULL; |
6228 | sshport = 0; | 6245 | sshport = 0; |
6229 | } | 6246 | } |
6230 | |||
6231 | if (GNUNET_YES | ||
6232 | == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", | ||
6233 | "SERVICEHOME", | ||
6234 | &baseservicehome)) | ||
6235 | { | ||
6236 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "baseservice home is %s\n", baseservicehome); | ||
6237 | if (hostname != NULL) | ||
6238 | GNUNET_asprintf (&newservicehome, "%s/%s/", baseservicehome, hostname); | ||
6239 | else | ||
6240 | GNUNET_asprintf (&newservicehome, "%s/", baseservicehome); | ||
6241 | GNUNET_free (baseservicehome); | ||
6242 | baseservicehome = NULL; | ||
6243 | } | ||
6244 | else | ||
6245 | { | ||
6246 | tmpdir = getenv ("TMPDIR"); | ||
6247 | tmpdir = tmpdir ? tmpdir : "/tmp"; | ||
6248 | if (hostname != NULL) | ||
6249 | GNUNET_asprintf (&newservicehome, "%s/%s/%s/", tmpdir, hostname, | ||
6250 | "gnunet-testing-test-test"); | ||
6251 | else | ||
6252 | GNUNET_asprintf (&newservicehome, "%s/%s/", tmpdir, | ||
6253 | "gnunet-testing-test-test", off); | ||
6254 | } | ||
6255 | |||
6256 | if (NULL != username) | ||
6257 | GNUNET_asprintf (&arg, | ||
6258 | "%s@%s:%s", | ||
6259 | username, | ||
6260 | pg->hosts[off].hostname, | ||
6261 | newservicehome); | ||
6262 | else | ||
6263 | GNUNET_asprintf (&arg, | ||
6264 | "%s:%s", | ||
6265 | pg->hosts[off].hostname, | ||
6266 | newservicehome); | ||
6267 | |||
6268 | /* FIXME: Doesn't support ssh_port option! */ | ||
6269 | proc = GNUNET_OS_start_process (NULL, NULL, | ||
6270 | "rsync", | ||
6271 | "rsync", "-r", newservicehome, arg, NULL); | ||
6272 | 6247 | ||
6273 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6248 | if (GNUNET_YES |
6274 | "copying directory with command rsync -r %s %s\n", | 6249 | == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", |
6275 | newservicehome, arg); | 6250 | "SERVICEHOME", |
6276 | GNUNET_free(newservicehome); | 6251 | &baseservicehome)) |
6277 | GNUNET_free (arg); | 6252 | { |
6278 | if (NULL == proc) | 6253 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "baseservice home is %s\n", |
6279 | { | 6254 | baseservicehome); |
6280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 6255 | if (hostname != NULL) |
6281 | _("Could not start `%s' process to copy configuration directory.\n"), | 6256 | GNUNET_asprintf (&newservicehome, "%s/%s/", baseservicehome, |
6282 | "scp"); | 6257 | hostname); |
6283 | GNUNET_assert(0); | 6258 | else |
6284 | } | 6259 | GNUNET_asprintf (&newservicehome, "%s/", baseservicehome); |
6285 | GNUNET_OS_process_wait (proc); | 6260 | GNUNET_free (baseservicehome); |
6286 | GNUNET_OS_process_close (proc); | 6261 | baseservicehome = NULL; |
6287 | } | 6262 | } |
6288 | /* Now all the configuration files and hostkeys are copied to the remote host. Call the hostkey callback for each peer! */ | 6263 | else |
6289 | GNUNET_SCHEDULER_add_now (&call_hostkey_callbacks, pg); | 6264 | { |
6265 | tmpdir = getenv ("TMPDIR"); | ||
6266 | tmpdir = tmpdir ? tmpdir : "/tmp"; | ||
6267 | if (hostname != NULL) | ||
6268 | GNUNET_asprintf (&newservicehome, "%s/%s/%s/", tmpdir, hostname, | ||
6269 | "gnunet-testing-test-test"); | ||
6270 | else | ||
6271 | GNUNET_asprintf (&newservicehome, "%s/%s/", tmpdir, | ||
6272 | "gnunet-testing-test-test", off); | ||
6273 | } | ||
6274 | |||
6275 | if (NULL != username) | ||
6276 | GNUNET_asprintf (&arg, | ||
6277 | "%s@%s:%s", | ||
6278 | username, pg->hosts[off].hostname, newservicehome); | ||
6279 | else | ||
6280 | GNUNET_asprintf (&arg, | ||
6281 | "%s:%s", pg->hosts[off].hostname, newservicehome); | ||
6282 | |||
6283 | /* FIXME: Doesn't support ssh_port option! */ | ||
6284 | proc = GNUNET_OS_start_process (NULL, NULL, | ||
6285 | "rsync", | ||
6286 | "rsync", "-r", newservicehome, arg, NULL); | ||
6287 | |||
6288 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
6289 | "copying directory with command rsync -r %s %s\n", | ||
6290 | newservicehome, arg); | ||
6291 | GNUNET_free (newservicehome); | ||
6292 | GNUNET_free (arg); | ||
6293 | if (NULL == proc) | ||
6294 | { | ||
6295 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
6296 | _ | ||
6297 | ("Could not start `%s' process to copy configuration directory.\n"), | ||
6298 | "scp"); | ||
6299 | GNUNET_assert (0); | ||
6300 | } | ||
6301 | GNUNET_OS_process_wait (proc); | ||
6302 | GNUNET_OS_process_close (proc); | ||
6290 | } | 6303 | } |
6304 | /* Now all the configuration files and hostkeys are copied to the remote host. Call the hostkey callback for each peer! */ | ||
6305 | GNUNET_SCHEDULER_add_now (&call_hostkey_callbacks, pg); | ||
6306 | } | ||
6291 | #endif | 6307 | #endif |
6292 | return pg; | 6308 | return pg; |
6293 | } | 6309 | } |
@@ -6297,8 +6313,8 @@ GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
6297 | * offsetting operation. | 6313 | * offsetting operation. |
6298 | */ | 6314 | */ |
6299 | struct GNUNET_TESTING_Daemon * | 6315 | struct GNUNET_TESTING_Daemon * |
6300 | GNUNET_TESTING_daemon_get(struct GNUNET_TESTING_PeerGroup *pg, | 6316 | GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, |
6301 | unsigned int position) | 6317 | unsigned int position) |
6302 | { | 6318 | { |
6303 | if (position < pg->total) | 6319 | if (position < pg->total) |
6304 | return pg->peers[position].daemon; | 6320 | return pg->peers[position].daemon; |
@@ -6315,17 +6331,17 @@ GNUNET_TESTING_daemon_get(struct GNUNET_TESTING_PeerGroup *pg, | |||
6315 | * @return the daemon on success, or NULL if no such peer identity is found | 6331 | * @return the daemon on success, or NULL if no such peer identity is found |
6316 | */ | 6332 | */ |
6317 | struct GNUNET_TESTING_Daemon * | 6333 | struct GNUNET_TESTING_Daemon * |
6318 | GNUNET_TESTING_daemon_get_by_id(struct GNUNET_TESTING_PeerGroup *pg, | 6334 | GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg, |
6319 | struct GNUNET_PeerIdentity *peer_id) | 6335 | struct GNUNET_PeerIdentity *peer_id) |
6320 | { | 6336 | { |
6321 | unsigned int i; | 6337 | unsigned int i; |
6322 | 6338 | ||
6323 | for (i = 0; i < pg->total; i++) | 6339 | for (i = 0; i < pg->total; i++) |
6324 | { | 6340 | { |
6325 | if (0 == memcmp (&pg->peers[i].daemon->id, peer_id, | 6341 | if (0 == memcmp (&pg->peers[i].daemon->id, peer_id, |
6326 | sizeof(struct GNUNET_PeerIdentity))) | 6342 | sizeof (struct GNUNET_PeerIdentity))) |
6327 | return pg->peers[i].daemon; | 6343 | return pg->peers[i].daemon; |
6328 | } | 6344 | } |
6329 | return NULL; | 6345 | return NULL; |
6330 | } | 6346 | } |
6331 | 6347 | ||
@@ -6340,33 +6356,34 @@ GNUNET_TESTING_daemon_get_by_id(struct GNUNET_TESTING_PeerGroup *pg, | |||
6340 | * @param emsg NULL on success | 6356 | * @param emsg NULL on success |
6341 | */ | 6357 | */ |
6342 | static void | 6358 | static void |
6343 | restart_callback(void *cls, const struct GNUNET_PeerIdentity *id, | 6359 | restart_callback (void *cls, const struct GNUNET_PeerIdentity *id, |
6344 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 6360 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
6345 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 6361 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
6346 | { | 6362 | { |
6347 | struct RestartContext *restart_context = cls; | 6363 | struct RestartContext *restart_context = cls; |
6348 | 6364 | ||
6349 | if (emsg == NULL) | 6365 | if (emsg == NULL) |
6350 | { | 6366 | { |
6351 | restart_context->peers_restarted++; | 6367 | restart_context->peers_restarted++; |
6352 | } | 6368 | } |
6353 | else | 6369 | else |
6354 | { | 6370 | { |
6355 | restart_context->peers_restart_failed++; | 6371 | restart_context->peers_restart_failed++; |
6356 | } | 6372 | } |
6357 | 6373 | ||
6358 | if (restart_context->peers_restarted == restart_context->peer_group->total) | 6374 | if (restart_context->peers_restarted == restart_context->peer_group->total) |
6359 | { | 6375 | { |
6360 | restart_context->callback (restart_context->callback_cls, NULL); | 6376 | restart_context->callback (restart_context->callback_cls, NULL); |
6361 | GNUNET_free (restart_context); | 6377 | GNUNET_free (restart_context); |
6362 | } | 6378 | } |
6363 | else if (restart_context->peers_restart_failed | 6379 | else if (restart_context->peers_restart_failed |
6364 | + restart_context->peers_restarted == restart_context->peer_group->total) | 6380 | + restart_context->peers_restarted == |
6365 | { | 6381 | restart_context->peer_group->total) |
6366 | restart_context->callback (restart_context->callback_cls, | 6382 | { |
6367 | "Failed to restart peers!"); | 6383 | restart_context->callback (restart_context->callback_cls, |
6368 | GNUNET_free (restart_context); | 6384 | "Failed to restart peers!"); |
6369 | } | 6385 | GNUNET_free (restart_context); |
6386 | } | ||
6370 | 6387 | ||
6371 | } | 6388 | } |
6372 | 6389 | ||
@@ -6379,7 +6396,7 @@ restart_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
6379 | * | 6396 | * |
6380 | */ | 6397 | */ |
6381 | static void | 6398 | static void |
6382 | churn_stop_callback(void *cls, const char *emsg) | 6399 | churn_stop_callback (void *cls, const char *emsg) |
6383 | { | 6400 | { |
6384 | struct ShutdownContext *shutdown_ctx = cls; | 6401 | struct ShutdownContext *shutdown_ctx = cls; |
6385 | struct ChurnContext *churn_ctx = shutdown_ctx->cb_cls; | 6402 | struct ChurnContext *churn_ctx = shutdown_ctx->cb_cls; |
@@ -6390,34 +6407,32 @@ churn_stop_callback(void *cls, const char *emsg) | |||
6390 | shutdown_ctx->outstanding--; | 6407 | shutdown_ctx->outstanding--; |
6391 | 6408 | ||
6392 | if (emsg != NULL) | 6409 | if (emsg != NULL) |
6393 | { | 6410 | { |
6394 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6411 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6395 | "Churn stop callback failed with error `%s'\n", emsg); | 6412 | "Churn stop callback failed with error `%s'\n", emsg); |
6396 | churn_ctx->num_failed_stop++; | 6413 | churn_ctx->num_failed_stop++; |
6397 | } | 6414 | } |
6398 | else | 6415 | else |
6399 | { | 6416 | { |
6400 | churn_ctx->num_to_stop--; | 6417 | churn_ctx->num_to_stop--; |
6401 | } | 6418 | } |
6402 | 6419 | ||
6403 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) | 6420 | total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) |
6404 | + (churn_ctx->num_to_start - churn_ctx->num_failed_start); | 6421 | + (churn_ctx->num_to_start - churn_ctx->num_failed_start); |
6405 | 6422 | ||
6406 | if (total_left == 0) | 6423 | if (total_left == 0) |
6424 | { | ||
6425 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) | ||
6407 | { | 6426 | { |
6408 | if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) | 6427 | GNUNET_asprintf (&error_message, |
6409 | { | 6428 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", |
6410 | GNUNET_asprintf ( | 6429 | churn_ctx->num_failed_start, churn_ctx->num_failed_stop); |
6411 | &error_message, | ||
6412 | "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", | ||
6413 | churn_ctx->num_failed_start, | ||
6414 | churn_ctx->num_failed_stop); | ||
6415 | } | ||
6416 | churn_ctx->cb (churn_ctx->cb_cls, error_message); | ||
6417 | GNUNET_free_non_null (error_message); | ||
6418 | GNUNET_free (churn_ctx); | ||
6419 | GNUNET_free (shutdown_ctx); | ||
6420 | } | 6430 | } |
6431 | churn_ctx->cb (churn_ctx->cb_cls, error_message); | ||
6432 | GNUNET_free_non_null (error_message); | ||
6433 | GNUNET_free (churn_ctx); | ||
6434 | GNUNET_free (shutdown_ctx); | ||
6435 | } | ||
6421 | } | 6436 | } |
6422 | 6437 | ||
6423 | /** | 6438 | /** |
@@ -6428,18 +6443,19 @@ churn_stop_callback(void *cls, const char *emsg) | |||
6428 | * @return the number of currently running peers in the peer group | 6443 | * @return the number of currently running peers in the peer group |
6429 | */ | 6444 | */ |
6430 | unsigned int | 6445 | unsigned int |
6431 | GNUNET_TESTING_daemons_running(struct GNUNET_TESTING_PeerGroup *pg) | 6446 | GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg) |
6432 | { | 6447 | { |
6433 | unsigned int i; | 6448 | unsigned int i; |
6434 | unsigned int running = 0; | 6449 | unsigned int running = 0; |
6450 | |||
6435 | for (i = 0; i < pg->total; i++) | 6451 | for (i = 0; i < pg->total; i++) |
6452 | { | ||
6453 | if (pg->peers[i].daemon->running == GNUNET_YES) | ||
6436 | { | 6454 | { |
6437 | if (pg->peers[i].daemon->running == GNUNET_YES) | 6455 | GNUNET_assert (running != -1); |
6438 | { | 6456 | running++; |
6439 | GNUNET_assert (running != -1); | ||
6440 | running++; | ||
6441 | } | ||
6442 | } | 6457 | } |
6458 | } | ||
6443 | return running; | 6459 | return running; |
6444 | } | 6460 | } |
6445 | 6461 | ||
@@ -6451,37 +6467,36 @@ GNUNET_TESTING_daemons_running(struct GNUNET_TESTING_PeerGroup *pg) | |||
6451 | * to calling gnunet-arm N times all at once). | 6467 | * to calling gnunet-arm N times all at once). |
6452 | */ | 6468 | */ |
6453 | static void | 6469 | static void |
6454 | schedule_churn_shutdown_task(void *cls, | 6470 | schedule_churn_shutdown_task (void *cls, |
6455 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 6471 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
6456 | { | 6472 | { |
6457 | struct PeerShutdownContext *peer_shutdown_ctx = cls; | 6473 | struct PeerShutdownContext *peer_shutdown_ctx = cls; |
6458 | struct ShutdownContext *shutdown_ctx; | 6474 | struct ShutdownContext *shutdown_ctx; |
6459 | struct ChurnContext *churn_ctx; | 6475 | struct ChurnContext *churn_ctx; |
6476 | |||
6460 | GNUNET_assert (peer_shutdown_ctx != NULL); | 6477 | GNUNET_assert (peer_shutdown_ctx != NULL); |
6461 | shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; | 6478 | shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; |
6462 | GNUNET_assert (shutdown_ctx != NULL); | 6479 | GNUNET_assert (shutdown_ctx != NULL); |
6463 | churn_ctx = (struct ChurnContext *) shutdown_ctx->cb_cls; | 6480 | churn_ctx = (struct ChurnContext *) shutdown_ctx->cb_cls; |
6464 | if (shutdown_ctx->outstanding > churn_ctx->pg->max_concurrent_ssh) | 6481 | if (shutdown_ctx->outstanding > churn_ctx->pg->max_concurrent_ssh) |
6465 | GNUNET_SCHEDULER_add_delayed ( | 6482 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
6466 | GNUNET_TIME_relative_multiply ( | 6483 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
6467 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
6468 | 100), | ||
6469 | &schedule_churn_shutdown_task, | 6484 | &schedule_churn_shutdown_task, |
6470 | peer_shutdown_ctx); | 6485 | peer_shutdown_ctx); |
6471 | else | 6486 | else |
6472 | { | 6487 | { |
6473 | shutdown_ctx->outstanding++; | 6488 | shutdown_ctx->outstanding++; |
6474 | if (churn_ctx->service != NULL) | 6489 | if (churn_ctx->service != NULL) |
6475 | GNUNET_TESTING_daemon_stop_service (peer_shutdown_ctx->daemon, | 6490 | GNUNET_TESTING_daemon_stop_service (peer_shutdown_ctx->daemon, |
6476 | churn_ctx->service, | 6491 | churn_ctx->service, |
6477 | shutdown_ctx->timeout, shutdown_ctx->cb, | 6492 | shutdown_ctx->timeout, |
6478 | shutdown_ctx); | 6493 | shutdown_ctx->cb, shutdown_ctx); |
6479 | else | 6494 | else |
6480 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, | 6495 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, |
6481 | shutdown_ctx->timeout, shutdown_ctx->cb, | 6496 | shutdown_ctx->timeout, shutdown_ctx->cb, |
6482 | shutdown_ctx, GNUNET_NO, GNUNET_YES); | 6497 | shutdown_ctx, GNUNET_NO, GNUNET_YES); |
6483 | GNUNET_free (peer_shutdown_ctx); | 6498 | GNUNET_free (peer_shutdown_ctx); |
6484 | } | 6499 | } |
6485 | } | 6500 | } |
6486 | 6501 | ||
6487 | 6502 | ||
@@ -6507,11 +6522,11 @@ schedule_churn_shutdown_task(void *cls, | |||
6507 | * @param cb_cls closure for cb | 6522 | * @param cb_cls closure for cb |
6508 | */ | 6523 | */ |
6509 | void | 6524 | void |
6510 | GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg, | 6525 | GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, |
6511 | char *service, | 6526 | char *service, |
6512 | unsigned int voff, unsigned int von, | 6527 | unsigned int voff, unsigned int von, |
6513 | struct GNUNET_TIME_Relative timeout, | 6528 | struct GNUNET_TIME_Relative timeout, |
6514 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | 6529 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
6515 | { | 6530 | { |
6516 | struct ChurnContext *churn_ctx; | 6531 | struct ChurnContext *churn_ctx; |
6517 | struct ShutdownContext *shutdown_ctx; | 6532 | struct ShutdownContext *shutdown_ctx; |
@@ -6538,73 +6553,75 @@ GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg, | |||
6538 | running = 0; | 6553 | running = 0; |
6539 | stopped = 0; | 6554 | stopped = 0; |
6540 | 6555 | ||
6541 | if ((von == 0) && (voff == 0)) /* No peers at all? */ | 6556 | if ((von == 0) && (voff == 0)) /* No peers at all? */ |
6542 | { | 6557 | { |
6543 | cb (cb_cls, NULL); | 6558 | cb (cb_cls, NULL); |
6544 | return; | 6559 | return; |
6545 | } | 6560 | } |
6546 | 6561 | ||
6547 | for (i = 0; i < pg->total; i++) | 6562 | for (i = 0; i < pg->total; i++) |
6563 | { | ||
6564 | if (service == NULL) | ||
6548 | { | 6565 | { |
6549 | if (service == NULL) | 6566 | if (pg->peers[i].daemon->running == GNUNET_YES) |
6550 | { | 6567 | { |
6551 | if (pg->peers[i].daemon->running == GNUNET_YES) | 6568 | GNUNET_assert (running != -1); |
6552 | { | 6569 | running++; |
6553 | GNUNET_assert (running != -1); | 6570 | } |
6554 | running++; | ||
6555 | } | ||
6556 | else | ||
6557 | { | ||
6558 | GNUNET_assert (stopped != -1); | ||
6559 | stopped++; | ||
6560 | } | ||
6561 | } | ||
6562 | else | 6571 | else |
6563 | { | 6572 | { |
6564 | /* FIXME: make churned services a list! */ | 6573 | GNUNET_assert (stopped != -1); |
6565 | pos = pg->peers[i].daemon->churned_services; | 6574 | stopped++; |
6566 | /* FIXME: while (pos != NULL) */ | 6575 | } |
6567 | if (pos != NULL) | 6576 | } |
6568 | { | 6577 | else |
6578 | { | ||
6579 | /* FIXME: make churned services a list! */ | ||
6580 | pos = pg->peers[i].daemon->churned_services; | ||
6581 | /* FIXME: while (pos != NULL) */ | ||
6582 | if (pos != NULL) | ||
6583 | { | ||
6569 | #if FIXME | 6584 | #if FIXME |
6570 | if (0 == strcasecmp(pos, service)) | 6585 | if (0 == strcasecmp (pos, service)) |
6571 | { | 6586 | { |
6572 | 6587 | ||
6573 | break; | 6588 | break; |
6574 | } | ||
6575 | #endif | ||
6576 | GNUNET_assert (stopped != -1); | ||
6577 | stopped++; | ||
6578 | /* FIXME: pos = pos->next; */ | ||
6579 | } | ||
6580 | if (pos == NULL) | ||
6581 | { | ||
6582 | GNUNET_assert (running != -1); | ||
6583 | running++; | ||
6584 | } | ||
6585 | } | 6589 | } |
6590 | #endif | ||
6591 | GNUNET_assert (stopped != -1); | ||
6592 | stopped++; | ||
6593 | /* FIXME: pos = pos->next; */ | ||
6594 | } | ||
6595 | if (pos == NULL) | ||
6596 | { | ||
6597 | GNUNET_assert (running != -1); | ||
6598 | running++; | ||
6599 | } | ||
6586 | } | 6600 | } |
6601 | } | ||
6587 | 6602 | ||
6588 | if (voff > running) | 6603 | if (voff > running) |
6589 | { | 6604 | { |
6590 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6605 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6591 | "Trying to stop more peers (%d) than are currently running (%d)!\n", voff, running); | 6606 | "Trying to stop more peers (%d) than are currently running (%d)!\n", |
6592 | cb (cb_cls, "Trying to stop more peers than are currently running!"); | 6607 | voff, running); |
6593 | return; | 6608 | cb (cb_cls, "Trying to stop more peers than are currently running!"); |
6594 | } | 6609 | return; |
6610 | } | ||
6595 | 6611 | ||
6596 | if (von > stopped) | 6612 | if (von > stopped) |
6597 | { | 6613 | { |
6598 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6614 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6599 | "Trying to start more peers (%d) than are currently stopped (%d)!\n", von, stopped); | 6615 | "Trying to start more peers (%d) than are currently stopped (%d)!\n", |
6600 | cb (cb_cls, "Trying to start more peers than are currently stopped!"); | 6616 | von, stopped); |
6601 | return; | 6617 | cb (cb_cls, "Trying to start more peers than are currently stopped!"); |
6602 | } | 6618 | return; |
6619 | } | ||
6603 | 6620 | ||
6604 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); | 6621 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); |
6605 | 6622 | ||
6606 | if (service != NULL) | 6623 | if (service != NULL) |
6607 | churn_ctx->service = GNUNET_strdup(service); | 6624 | churn_ctx->service = GNUNET_strdup (service); |
6608 | running_arr = NULL; | 6625 | running_arr = NULL; |
6609 | if (running > 0) | 6626 | if (running > 0) |
6610 | running_arr = GNUNET_malloc (running * sizeof (unsigned int)); | 6627 | running_arr = GNUNET_malloc (running * sizeof (unsigned int)); |
@@ -6635,87 +6652,88 @@ GNUNET_TESTING_daemons_churn(struct GNUNET_TESTING_PeerGroup *pg, | |||
6635 | churn_ctx->pg = pg; | 6652 | churn_ctx->pg = pg; |
6636 | 6653 | ||
6637 | for (i = 0; i < pg->total; i++) | 6654 | for (i = 0; i < pg->total; i++) |
6655 | { | ||
6656 | if (service == NULL) | ||
6638 | { | 6657 | { |
6639 | if (service == NULL) | 6658 | if (pg->peers[i].daemon->running == GNUNET_YES) |
6640 | { | 6659 | { |
6641 | if (pg->peers[i].daemon->running == GNUNET_YES) | 6660 | GNUNET_assert ((running_arr != NULL) && (total_running > running)); |
6642 | { | 6661 | running_arr[running] = i; |
6643 | GNUNET_assert ((running_arr != NULL) && (total_running > running)); | 6662 | running++; |
6644 | running_arr[running] = i; | 6663 | } |
6645 | running++; | ||
6646 | } | ||
6647 | else | ||
6648 | { | ||
6649 | GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped)); | ||
6650 | stopped_arr[stopped] = i; | ||
6651 | stopped++; | ||
6652 | } | ||
6653 | } | ||
6654 | else | 6664 | else |
6655 | { | 6665 | { |
6656 | /* FIXME: make churned services a list! */ | 6666 | GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped)); |
6657 | pos = pg->peers[i].daemon->churned_services; | 6667 | stopped_arr[stopped] = i; |
6658 | /* FIXME: while (pos != NULL) */ | 6668 | stopped++; |
6659 | if (pos != NULL) | 6669 | } |
6660 | { | 6670 | } |
6661 | GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped)); | 6671 | else |
6662 | stopped_arr[stopped] = i; | 6672 | { |
6663 | stopped++; | 6673 | /* FIXME: make churned services a list! */ |
6664 | /* FIXME: pos = pos->next; */ | 6674 | pos = pg->peers[i].daemon->churned_services; |
6665 | } | 6675 | /* FIXME: while (pos != NULL) */ |
6666 | if (pos == NULL) | 6676 | if (pos != NULL) |
6667 | { | 6677 | { |
6668 | GNUNET_assert ((running_arr != NULL) && (total_running > running)); | 6678 | GNUNET_assert ((stopped_arr != NULL) && (total_stopped > stopped)); |
6669 | running_arr[running] = i; | 6679 | stopped_arr[stopped] = i; |
6670 | running++; | 6680 | stopped++; |
6671 | } | 6681 | /* FIXME: pos = pos->next; */ |
6672 | } | 6682 | } |
6683 | if (pos == NULL) | ||
6684 | { | ||
6685 | GNUNET_assert ((running_arr != NULL) && (total_running > running)); | ||
6686 | running_arr[running] = i; | ||
6687 | running++; | ||
6688 | } | ||
6673 | } | 6689 | } |
6690 | } | ||
6674 | 6691 | ||
6675 | GNUNET_assert (running >= voff); | 6692 | GNUNET_assert (running >= voff); |
6676 | if (voff > 0) | 6693 | if (voff > 0) |
6677 | { | 6694 | { |
6678 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); | 6695 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); |
6679 | shutdown_ctx->cb = &churn_stop_callback; | 6696 | shutdown_ctx->cb = &churn_stop_callback; |
6680 | shutdown_ctx->cb_cls = churn_ctx; | 6697 | shutdown_ctx->cb_cls = churn_ctx; |
6681 | shutdown_ctx->total_peers = voff; | 6698 | shutdown_ctx->total_peers = voff; |
6682 | shutdown_ctx->timeout = timeout; | 6699 | shutdown_ctx->timeout = timeout; |
6683 | } | 6700 | } |
6684 | 6701 | ||
6685 | for (i = 0; i < voff; i++) | 6702 | for (i = 0; i < voff; i++) |
6686 | { | 6703 | { |
6687 | #if DEBUG_CHURN | 6704 | #if DEBUG_CHURN |
6688 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", running_arr[running_permute[i]]); | 6705 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", |
6689 | #endif | 6706 | running_arr[running_permute[i]]); |
6690 | GNUNET_assert (running_arr != NULL); | 6707 | #endif |
6691 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); | 6708 | GNUNET_assert (running_arr != NULL); |
6692 | peer_shutdown_ctx->daemon | 6709 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); |
6693 | = pg->peers[running_arr[running_permute[i]]].daemon; | 6710 | peer_shutdown_ctx->daemon |
6694 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; | 6711 | = pg->peers[running_arr[running_permute[i]]].daemon; |
6695 | GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task, | 6712 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; |
6696 | peer_shutdown_ctx); | 6713 | GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task, peer_shutdown_ctx); |
6697 | } | 6714 | } |
6698 | 6715 | ||
6699 | GNUNET_assert (stopped >= von); | 6716 | GNUNET_assert (stopped >= von); |
6700 | if (von > 0) | 6717 | if (von > 0) |
6701 | { | 6718 | { |
6702 | churn_startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext)); | 6719 | churn_startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext)); |
6703 | churn_startup_ctx->churn_ctx = churn_ctx; | 6720 | churn_startup_ctx->churn_ctx = churn_ctx; |
6704 | churn_startup_ctx->timeout = timeout; | 6721 | churn_startup_ctx->timeout = timeout; |
6705 | churn_startup_ctx->pg = pg; | 6722 | churn_startup_ctx->pg = pg; |
6706 | } | 6723 | } |
6707 | for (i = 0; i < von; i++) | 6724 | for (i = 0; i < von; i++) |
6708 | { | 6725 | { |
6709 | #if DEBUG_CHURN | 6726 | #if DEBUG_CHURN |
6710 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", stopped_arr[stopped_permute[i]]); | 6727 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", |
6711 | #endif | 6728 | stopped_arr[stopped_permute[i]]); |
6712 | GNUNET_assert (stopped_arr != NULL); | 6729 | #endif |
6713 | peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext)); | 6730 | GNUNET_assert (stopped_arr != NULL); |
6714 | peer_restart_ctx->churn_restart_ctx = churn_startup_ctx; | 6731 | peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext)); |
6715 | peer_restart_ctx->daemon | 6732 | peer_restart_ctx->churn_restart_ctx = churn_startup_ctx; |
6716 | = pg->peers[stopped_arr[stopped_permute[i]]].daemon; | 6733 | peer_restart_ctx->daemon |
6717 | GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx); | 6734 | = pg->peers[stopped_arr[stopped_permute[i]]].daemon; |
6718 | } | 6735 | GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx); |
6736 | } | ||
6719 | 6737 | ||
6720 | GNUNET_free_non_null (running_arr); | 6738 | GNUNET_free_non_null (running_arr); |
6721 | GNUNET_free_non_null (stopped_arr); | 6739 | GNUNET_free_non_null (stopped_arr); |
@@ -6745,26 +6763,28 @@ GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg, | |||
6745 | struct PeerServiceStartContext *peer_start_ctx; | 6763 | struct PeerServiceStartContext *peer_start_ctx; |
6746 | unsigned int i; | 6764 | unsigned int i; |
6747 | 6765 | ||
6748 | GNUNET_assert(service != NULL); | 6766 | GNUNET_assert (service != NULL); |
6749 | 6767 | ||
6750 | start_ctx = GNUNET_malloc(sizeof(struct ServiceStartContext)); | 6768 | start_ctx = GNUNET_malloc (sizeof (struct ServiceStartContext)); |
6751 | start_ctx->pg = pg; | 6769 | start_ctx->pg = pg; |
6752 | start_ctx->remaining = pg->total; | 6770 | start_ctx->remaining = pg->total; |
6753 | start_ctx->cb = cb; | 6771 | start_ctx->cb = cb; |
6754 | start_ctx->cb_cls = cb_cls; | 6772 | start_ctx->cb_cls = cb_cls; |
6755 | start_ctx->service = GNUNET_strdup(service); | 6773 | start_ctx->service = GNUNET_strdup (service); |
6756 | start_ctx->timeout = timeout; | 6774 | start_ctx->timeout = timeout; |
6757 | 6775 | ||
6758 | for (i = 0; i < pg->total; i++) | 6776 | for (i = 0; i < pg->total; i++) |
6759 | { | 6777 | { |
6760 | #if DEBUG_START | 6778 | #if DEBUG_START |
6761 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up service %s on peer %d!\n", service, stopped_arr[stopped_permute[i]]); | 6779 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6780 | "Starting up service %s on peer %d!\n", service, | ||
6781 | stopped_arr[stopped_permute[i]]); | ||
6762 | #endif | 6782 | #endif |
6763 | peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext)); | 6783 | peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext)); |
6764 | peer_start_ctx->start_ctx = start_ctx; | 6784 | peer_start_ctx->start_ctx = start_ctx; |
6765 | peer_start_ctx->daemon = pg->peers[i].daemon; | 6785 | peer_start_ctx->daemon = pg->peers[i].daemon; |
6766 | GNUNET_SCHEDULER_add_now (&schedule_service_start, peer_start_ctx); | 6786 | GNUNET_SCHEDULER_add_now (&schedule_service_start, peer_start_ctx); |
6767 | } | 6787 | } |
6768 | } | 6788 | } |
6769 | 6789 | ||
6770 | /** | 6790 | /** |
@@ -6775,27 +6795,27 @@ GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg, | |||
6775 | * @param callback_cls closure for the callback function | 6795 | * @param callback_cls closure for the callback function |
6776 | */ | 6796 | */ |
6777 | void | 6797 | void |
6778 | GNUNET_TESTING_daemons_restart(struct GNUNET_TESTING_PeerGroup *pg, | 6798 | GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, |
6779 | GNUNET_TESTING_NotifyCompletion callback, | 6799 | GNUNET_TESTING_NotifyCompletion callback, |
6780 | void *callback_cls) | 6800 | void *callback_cls) |
6781 | { | 6801 | { |
6782 | struct RestartContext *restart_context; | 6802 | struct RestartContext *restart_context; |
6783 | unsigned int off; | 6803 | unsigned int off; |
6784 | 6804 | ||
6785 | if (pg->total > 0) | 6805 | if (pg->total > 0) |
6786 | { | 6806 | { |
6787 | restart_context = GNUNET_malloc (sizeof (struct RestartContext)); | 6807 | restart_context = GNUNET_malloc (sizeof (struct RestartContext)); |
6788 | restart_context->peer_group = pg; | 6808 | restart_context->peer_group = pg; |
6789 | restart_context->peers_restarted = 0; | 6809 | restart_context->peers_restarted = 0; |
6790 | restart_context->callback = callback; | 6810 | restart_context->callback = callback; |
6791 | restart_context->callback_cls = callback_cls; | 6811 | restart_context->callback_cls = callback_cls; |
6792 | 6812 | ||
6793 | for (off = 0; off < pg->total; off++) | 6813 | for (off = 0; off < pg->total; off++) |
6794 | { | 6814 | { |
6795 | GNUNET_TESTING_daemon_restart (pg->peers[off].daemon, | 6815 | GNUNET_TESTING_daemon_restart (pg->peers[off].daemon, |
6796 | &restart_callback, restart_context); | 6816 | &restart_callback, restart_context); |
6797 | } | ||
6798 | } | 6817 | } |
6818 | } | ||
6799 | } | 6819 | } |
6800 | 6820 | ||
6801 | 6821 | ||
@@ -6810,47 +6830,47 @@ GNUNET_TESTING_daemons_restart(struct GNUNET_TESTING_PeerGroup *pg, | |||
6810 | * @param cb_cls closure for cb | 6830 | * @param cb_cls closure for cb |
6811 | */ | 6831 | */ |
6812 | void | 6832 | void |
6813 | GNUNET_TESTING_daemons_vary(struct GNUNET_TESTING_PeerGroup *pg, | 6833 | GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, |
6814 | unsigned int offset, int desired_status, | 6834 | unsigned int offset, int desired_status, |
6815 | struct GNUNET_TIME_Relative timeout, | 6835 | struct GNUNET_TIME_Relative timeout, |
6816 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | 6836 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
6817 | { | 6837 | { |
6818 | struct ShutdownContext *shutdown_ctx; | 6838 | struct ShutdownContext *shutdown_ctx; |
6819 | struct ChurnRestartContext *startup_ctx; | 6839 | struct ChurnRestartContext *startup_ctx; |
6820 | struct ChurnContext *churn_ctx; | 6840 | struct ChurnContext *churn_ctx; |
6821 | 6841 | ||
6822 | if (GNUNET_NO == desired_status) | 6842 | if (GNUNET_NO == desired_status) |
6843 | { | ||
6844 | if (NULL != pg->peers[offset].daemon) | ||
6823 | { | 6845 | { |
6824 | if (NULL != pg->peers[offset].daemon) | 6846 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); |
6825 | { | 6847 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); |
6826 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); | 6848 | churn_ctx->num_to_start = 0; |
6827 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); | 6849 | churn_ctx->num_to_stop = 1; |
6828 | churn_ctx->num_to_start = 0; | 6850 | churn_ctx->cb = cb; |
6829 | churn_ctx->num_to_stop = 1; | 6851 | churn_ctx->cb_cls = cb_cls; |
6830 | churn_ctx->cb = cb; | 6852 | shutdown_ctx->cb_cls = churn_ctx; |
6831 | churn_ctx->cb_cls = cb_cls; | 6853 | GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, timeout, |
6832 | shutdown_ctx->cb_cls = churn_ctx; | 6854 | &churn_stop_callback, shutdown_ctx, |
6833 | GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, timeout, | 6855 | GNUNET_NO, GNUNET_YES); |
6834 | &churn_stop_callback, shutdown_ctx, | ||
6835 | GNUNET_NO, GNUNET_YES); | ||
6836 | } | ||
6837 | } | 6856 | } |
6857 | } | ||
6838 | else if (GNUNET_YES == desired_status) | 6858 | else if (GNUNET_YES == desired_status) |
6839 | { | 6859 | { |
6840 | if (NULL == pg->peers[offset].daemon) | 6860 | if (NULL == pg->peers[offset].daemon) |
6841 | { | 6861 | { |
6842 | startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext)); | 6862 | startup_ctx = GNUNET_malloc (sizeof (struct ChurnRestartContext)); |
6843 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); | 6863 | churn_ctx = GNUNET_malloc (sizeof (struct ChurnContext)); |
6844 | churn_ctx->num_to_start = 1; | 6864 | churn_ctx->num_to_start = 1; |
6845 | churn_ctx->num_to_stop = 0; | 6865 | churn_ctx->num_to_stop = 0; |
6846 | churn_ctx->cb = cb; | 6866 | churn_ctx->cb = cb; |
6847 | churn_ctx->cb_cls = cb_cls; | 6867 | churn_ctx->cb_cls = cb_cls; |
6848 | startup_ctx->churn_ctx = churn_ctx; | 6868 | startup_ctx->churn_ctx = churn_ctx; |
6849 | GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon, | 6869 | GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon, |
6850 | timeout, &churn_start_callback, | 6870 | timeout, &churn_start_callback, |
6851 | startup_ctx); | 6871 | startup_ctx); |
6852 | } | ||
6853 | } | 6872 | } |
6873 | } | ||
6854 | else | 6874 | else |
6855 | GNUNET_break (0); | 6875 | GNUNET_break (0); |
6856 | } | 6876 | } |
@@ -6863,7 +6883,7 @@ GNUNET_TESTING_daemons_vary(struct GNUNET_TESTING_PeerGroup *pg, | |||
6863 | * @param emsg NULL on success | 6883 | * @param emsg NULL on success |
6864 | */ | 6884 | */ |
6865 | static void | 6885 | static void |
6866 | internal_shutdown_callback(void *cls, const char *emsg) | 6886 | internal_shutdown_callback (void *cls, const char *emsg) |
6867 | { | 6887 | { |
6868 | struct PeerShutdownContext *peer_shutdown_ctx = cls; | 6888 | struct PeerShutdownContext *peer_shutdown_ctx = cls; |
6869 | struct ShutdownContext *shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; | 6889 | struct ShutdownContext *shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; |
@@ -6876,44 +6896,46 @@ internal_shutdown_callback(void *cls, const char *emsg) | |||
6876 | shutdown_ctx->pg); | 6896 | shutdown_ctx->pg); |
6877 | 6897 | ||
6878 | if (emsg == NULL) | 6898 | if (emsg == NULL) |
6879 | { | 6899 | { |
6880 | shutdown_ctx->peers_down++; | 6900 | shutdown_ctx->peers_down++; |
6881 | } | 6901 | } |
6882 | else | 6902 | else |
6883 | { | 6903 | { |
6884 | #if VERBOSE_TESTING | 6904 | #if VERBOSE_TESTING |
6885 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "internal_shutdown_callback", | 6905 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "internal_shutdown_callback", |
6886 | "Failed to stop a peer: %s\n", emsg); | 6906 | "Failed to stop a peer: %s\n", emsg); |
6887 | #endif | 6907 | #endif |
6888 | shutdown_ctx->peers_failed++; | 6908 | shutdown_ctx->peers_failed++; |
6889 | } | 6909 | } |
6890 | 6910 | ||
6891 | if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down | 6911 | if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down |
6892 | + shutdown_ctx->peers_failed == shutdown_ctx->total_peers)) | 6912 | + shutdown_ctx->peers_failed == |
6893 | { | 6913 | shutdown_ctx->total_peers)) |
6894 | if (shutdown_ctx->peers_failed > 0) | 6914 | { |
6895 | shutdown_ctx->cb (shutdown_ctx->cb_cls, | 6915 | if (shutdown_ctx->peers_failed > 0) |
6896 | "Not all peers successfully shut down!"); | 6916 | shutdown_ctx->cb (shutdown_ctx->cb_cls, |
6897 | else | 6917 | "Not all peers successfully shut down!"); |
6898 | shutdown_ctx->cb (shutdown_ctx->cb_cls, NULL); | 6918 | else |
6919 | shutdown_ctx->cb (shutdown_ctx->cb_cls, NULL); | ||
6899 | 6920 | ||
6900 | GNUNET_free (shutdown_ctx->pg->peers); | 6921 | GNUNET_free (shutdown_ctx->pg->peers); |
6901 | GNUNET_free_non_null(shutdown_ctx->pg->hostkey_data); | 6922 | GNUNET_free_non_null (shutdown_ctx->pg->hostkey_data); |
6902 | for (off = 0; off < shutdown_ctx->pg->num_hosts; off++) | 6923 | for (off = 0; off < shutdown_ctx->pg->num_hosts; off++) |
6903 | { | 6924 | { |
6904 | GNUNET_free (shutdown_ctx->pg->hosts[off].hostname); | 6925 | GNUNET_free (shutdown_ctx->pg->hosts[off].hostname); |
6905 | GNUNET_free_non_null (shutdown_ctx->pg->hosts[off].username); | 6926 | GNUNET_free_non_null (shutdown_ctx->pg->hosts[off].username); |
6906 | } | ||
6907 | GNUNET_free_non_null (shutdown_ctx->pg->hosts); | ||
6908 | while (NULL != (ssh_pos = shutdown_ctx->pg->ssh_head)) | ||
6909 | { | ||
6910 | GNUNET_CONTAINER_DLL_remove(shutdown_ctx->pg->ssh_head, shutdown_ctx->pg->ssh_tail, ssh_pos); | ||
6911 | GNUNET_free(ssh_pos); | ||
6912 | } | ||
6913 | GNUNET_free (shutdown_ctx->pg); | ||
6914 | GNUNET_free (shutdown_ctx); | ||
6915 | } | 6927 | } |
6916 | GNUNET_free(peer_shutdown_ctx); | 6928 | GNUNET_free_non_null (shutdown_ctx->pg->hosts); |
6929 | while (NULL != (ssh_pos = shutdown_ctx->pg->ssh_head)) | ||
6930 | { | ||
6931 | GNUNET_CONTAINER_DLL_remove (shutdown_ctx->pg->ssh_head, | ||
6932 | shutdown_ctx->pg->ssh_tail, ssh_pos); | ||
6933 | GNUNET_free (ssh_pos); | ||
6934 | } | ||
6935 | GNUNET_free (shutdown_ctx->pg); | ||
6936 | GNUNET_free (shutdown_ctx); | ||
6937 | } | ||
6938 | GNUNET_free (peer_shutdown_ctx); | ||
6917 | } | 6939 | } |
6918 | 6940 | ||
6919 | 6941 | ||
@@ -6925,7 +6947,8 @@ internal_shutdown_callback(void *cls, const char *emsg) | |||
6925 | * to calling gnunet-arm N times all at once). | 6947 | * to calling gnunet-arm N times all at once). |
6926 | */ | 6948 | */ |
6927 | static void | 6949 | static void |
6928 | schedule_shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 6950 | schedule_shutdown_task (void *cls, |
6951 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
6929 | { | 6952 | { |
6930 | struct PeerShutdownContext *peer_shutdown_ctx = cls; | 6953 | struct PeerShutdownContext *peer_shutdown_ctx = cls; |
6931 | struct ShutdownContext *shutdown_ctx; | 6954 | struct ShutdownContext *shutdown_ctx; |
@@ -6939,19 +6962,19 @@ schedule_shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
6939 | && (count_outstanding_at_host (peer_shutdown_ctx->daemon->hostname, | 6962 | && (count_outstanding_at_host (peer_shutdown_ctx->daemon->hostname, |
6940 | shutdown_ctx->pg) | 6963 | shutdown_ctx->pg) |
6941 | < shutdown_ctx->pg->max_concurrent_ssh))) | 6964 | < shutdown_ctx->pg->max_concurrent_ssh))) |
6942 | { | 6965 | { |
6943 | if (peer_shutdown_ctx->daemon->hostname != NULL) | 6966 | if (peer_shutdown_ctx->daemon->hostname != NULL) |
6944 | increment_outstanding_at_host (peer_shutdown_ctx->daemon->hostname, | 6967 | increment_outstanding_at_host (peer_shutdown_ctx->daemon->hostname, |
6945 | shutdown_ctx->pg); | 6968 | shutdown_ctx->pg); |
6946 | shutdown_ctx->outstanding++; | 6969 | shutdown_ctx->outstanding++; |
6947 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, | 6970 | GNUNET_TESTING_daemon_stop (peer_shutdown_ctx->daemon, |
6948 | shutdown_ctx->timeout, | 6971 | shutdown_ctx->timeout, |
6949 | &internal_shutdown_callback, peer_shutdown_ctx, | 6972 | &internal_shutdown_callback, peer_shutdown_ctx, |
6950 | shutdown_ctx->delete_files, GNUNET_NO); | 6973 | shutdown_ctx->delete_files, GNUNET_NO); |
6951 | } | 6974 | } |
6952 | else | 6975 | else |
6953 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 6976 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
6954 | 100), | 6977 | (GNUNET_TIME_UNIT_MILLISECONDS, 100), |
6955 | &schedule_shutdown_task, peer_shutdown_ctx); | 6978 | &schedule_shutdown_task, peer_shutdown_ctx); |
6956 | 6979 | ||
6957 | } | 6980 | } |
@@ -6987,71 +7010,67 @@ GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
6987 | temphost = NULL; | 7010 | temphost = NULL; |
6988 | data = NULL; | 7011 | data = NULL; |
6989 | if (hostfile != NULL) | 7012 | if (hostfile != NULL) |
7013 | { | ||
7014 | if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) | ||
7015 | GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ | ||
7016 | | GNUNET_DISK_PERM_USER_WRITE); | ||
7017 | if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) | ||
6990 | { | 7018 | { |
6991 | if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) | 7019 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
6992 | GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ | 7020 | "Could not open file specified for host list, ending test!"); |
6993 | | GNUNET_DISK_PERM_USER_WRITE); | 7021 | GNUNET_free (hostfile); |
6994 | if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) | 7022 | return NULL; |
6995 | { | 7023 | } |
6996 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
6997 | "Could not open file specified for host list, ending test!"); | ||
6998 | GNUNET_free(hostfile); | ||
6999 | return NULL; | ||
7000 | } | ||
7001 | 7024 | ||
7002 | data = GNUNET_malloc_large (frstat.st_size); | 7025 | data = GNUNET_malloc_large (frstat.st_size); |
7003 | GNUNET_assert(data != NULL); | 7026 | GNUNET_assert (data != NULL); |
7004 | if (frstat.st_size | 7027 | if (frstat.st_size != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size)) |
7005 | != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size)) | 7028 | { |
7006 | { | 7029 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
7007 | GNUNET_log ( | 7030 | "Could not read file %s specified for host list, ending test!", |
7008 | GNUNET_ERROR_TYPE_ERROR, | 7031 | hostfile); |
7009 | "Could not read file %s specified for host list, ending test!", | 7032 | GNUNET_free (hostfile); |
7010 | hostfile); | 7033 | GNUNET_free (data); |
7011 | GNUNET_free (hostfile); | 7034 | return NULL; |
7012 | GNUNET_free (data); | 7035 | } |
7013 | return NULL; | ||
7014 | } | ||
7015 | 7036 | ||
7016 | GNUNET_free_non_null(hostfile); | 7037 | GNUNET_free_non_null (hostfile); |
7017 | 7038 | ||
7018 | buf = data; | 7039 | buf = data; |
7019 | count = 0; | 7040 | count = 0; |
7020 | while (count < frstat.st_size - 1) | 7041 | while (count < frstat.st_size - 1) |
7042 | { | ||
7043 | count++; | ||
7044 | if (((data[count] == '\n')) && (buf != &data[count])) | ||
7045 | { | ||
7046 | data[count] = '\0'; | ||
7047 | temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host)); | ||
7048 | ret = sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd", | ||
7049 | &temphost->username, &temphost->hostname, | ||
7050 | &temphost->port); | ||
7051 | if (3 == ret) | ||
7052 | { | ||
7053 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
7054 | "Successfully read host %s, port %d and user %s from file\n", | ||
7055 | temphost->hostname, temphost->port, temphost->username); | ||
7056 | } | ||
7057 | else | ||
7021 | { | 7058 | { |
7022 | count++; | 7059 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
7023 | if (((data[count] == '\n')) && (buf != &data[count])) | 7060 | "Error reading line `%s' in hostfile\n", buf); |
7024 | { | 7061 | GNUNET_free (temphost); |
7025 | data[count] = '\0'; | 7062 | buf = &data[count + 1]; |
7026 | temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host)); | 7063 | continue; |
7027 | ret = sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd", | ||
7028 | &temphost->username, &temphost->hostname, | ||
7029 | &temphost->port); | ||
7030 | if (3 == ret) | ||
7031 | { | ||
7032 | GNUNET_log ( | ||
7033 | GNUNET_ERROR_TYPE_DEBUG, | ||
7034 | "Successfully read host %s, port %d and user %s from file\n", | ||
7035 | temphost->hostname, temphost->port, | ||
7036 | temphost->username); | ||
7037 | } | ||
7038 | else | ||
7039 | { | ||
7040 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
7041 | "Error reading line `%s' in hostfile\n", buf); | ||
7042 | GNUNET_free(temphost); | ||
7043 | buf = &data[count + 1]; | ||
7044 | continue; | ||
7045 | } | ||
7046 | temphost->next = hosts; | ||
7047 | hosts = temphost; | ||
7048 | buf = &data[count + 1]; | ||
7049 | } | ||
7050 | else if ((data[count] == '\n') || (data[count] == '\0')) | ||
7051 | buf = &data[count + 1]; | ||
7052 | } | 7064 | } |
7065 | temphost->next = hosts; | ||
7066 | hosts = temphost; | ||
7067 | buf = &data[count + 1]; | ||
7068 | } | ||
7069 | else if ((data[count] == '\n') || (data[count] == '\0')) | ||
7070 | buf = &data[count + 1]; | ||
7053 | } | 7071 | } |
7054 | GNUNET_free_non_null(data); | 7072 | } |
7073 | GNUNET_free_non_null (data); | ||
7055 | 7074 | ||
7056 | return hosts; | 7075 | return hosts; |
7057 | } | 7076 | } |
@@ -7065,13 +7084,14 @@ GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
7065 | * @param cb_cls closure for cb | 7084 | * @param cb_cls closure for cb |
7066 | */ | 7085 | */ |
7067 | void | 7086 | void |
7068 | GNUNET_TESTING_daemons_stop(struct GNUNET_TESTING_PeerGroup *pg, | 7087 | GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, |
7069 | struct GNUNET_TIME_Relative timeout, | 7088 | struct GNUNET_TIME_Relative timeout, |
7070 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | 7089 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
7071 | { | 7090 | { |
7072 | unsigned int off; | 7091 | unsigned int off; |
7073 | struct ShutdownContext *shutdown_ctx; | 7092 | struct ShutdownContext *shutdown_ctx; |
7074 | struct PeerShutdownContext *peer_shutdown_ctx; | 7093 | struct PeerShutdownContext *peer_shutdown_ctx; |
7094 | |||
7075 | #if OLD | 7095 | #if OLD |
7076 | struct PeerConnection *conn_iter; | 7096 | struct PeerConnection *conn_iter; |
7077 | struct PeerConnection *temp_conn; | 7097 | struct PeerConnection *temp_conn; |
@@ -7081,8 +7101,8 @@ GNUNET_TESTING_daemons_stop(struct GNUNET_TESTING_PeerGroup *pg, | |||
7081 | 7101 | ||
7082 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); | 7102 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); |
7083 | shutdown_ctx->delete_files = GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, | 7103 | shutdown_ctx->delete_files = GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, |
7084 | "TESTING", | 7104 | "TESTING", |
7085 | "DELETE_FILES"); | 7105 | "DELETE_FILES"); |
7086 | shutdown_ctx->cb = cb; | 7106 | shutdown_ctx->cb = cb; |
7087 | shutdown_ctx->cb_cls = cb_cls; | 7107 | shutdown_ctx->cb_cls = cb_cls; |
7088 | shutdown_ctx->total_peers = pg->total; | 7108 | shutdown_ctx->total_peers = pg->total; |
@@ -7091,60 +7111,59 @@ GNUNET_TESTING_daemons_stop(struct GNUNET_TESTING_PeerGroup *pg, | |||
7091 | /* shtudown_ctx->outstanding = 0; */ | 7111 | /* shtudown_ctx->outstanding = 0; */ |
7092 | 7112 | ||
7093 | for (off = 0; off < pg->total; off++) | 7113 | for (off = 0; off < pg->total; off++) |
7094 | { | 7114 | { |
7095 | GNUNET_assert (NULL != pg->peers[off].daemon); | 7115 | GNUNET_assert (NULL != pg->peers[off].daemon); |
7096 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); | 7116 | peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); |
7097 | peer_shutdown_ctx->daemon = pg->peers[off].daemon; | 7117 | peer_shutdown_ctx->daemon = pg->peers[off].daemon; |
7098 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; | 7118 | peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; |
7099 | GNUNET_SCHEDULER_add_now (&schedule_shutdown_task, peer_shutdown_ctx); | 7119 | GNUNET_SCHEDULER_add_now (&schedule_shutdown_task, peer_shutdown_ctx); |
7100 | 7120 | ||
7101 | if (NULL != pg->peers[off].cfg) | 7121 | if (NULL != pg->peers[off].cfg) |
7102 | { | 7122 | { |
7103 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); | 7123 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); |
7104 | pg->peers[off].cfg = NULL; | 7124 | pg->peers[off].cfg = NULL; |
7105 | } | 7125 | } |
7106 | #if OLD | 7126 | #if OLD |
7107 | conn_iter = pg->peers[off].allowed_peers_head; | 7127 | conn_iter = pg->peers[off].allowed_peers_head; |
7108 | while (conn_iter != NULL) | 7128 | while (conn_iter != NULL) |
7109 | { | 7129 | { |
7110 | temp_conn = conn_iter->next; | 7130 | temp_conn = conn_iter->next; |
7111 | GNUNET_free(conn_iter); | 7131 | GNUNET_free (conn_iter); |
7112 | conn_iter = temp_conn; | 7132 | conn_iter = temp_conn; |
7113 | } | 7133 | } |
7114 | 7134 | ||
7115 | conn_iter = pg->peers[off].connect_peers_head; | 7135 | conn_iter = pg->peers[off].connect_peers_head; |
7116 | while (conn_iter != NULL) | 7136 | while (conn_iter != NULL) |
7117 | { | 7137 | { |
7118 | temp_conn = conn_iter->next; | 7138 | temp_conn = conn_iter->next; |
7119 | GNUNET_free(conn_iter); | 7139 | GNUNET_free (conn_iter); |
7120 | conn_iter = temp_conn; | 7140 | conn_iter = temp_conn; |
7121 | } | 7141 | } |
7122 | 7142 | ||
7123 | conn_iter = pg->peers[off].blacklisted_peers_head; | 7143 | conn_iter = pg->peers[off].blacklisted_peers_head; |
7124 | while (conn_iter != NULL) | 7144 | while (conn_iter != NULL) |
7125 | { | 7145 | { |
7126 | temp_conn = conn_iter->next; | 7146 | temp_conn = conn_iter->next; |
7127 | GNUNET_free(conn_iter); | 7147 | GNUNET_free (conn_iter); |
7128 | conn_iter = temp_conn; | 7148 | conn_iter = temp_conn; |
7129 | } | 7149 | } |
7130 | 7150 | ||
7131 | conn_iter = pg->peers[off].connect_peers_working_set_head; | 7151 | conn_iter = pg->peers[off].connect_peers_working_set_head; |
7132 | while (conn_iter != NULL) | 7152 | while (conn_iter != NULL) |
7133 | { | 7153 | { |
7134 | temp_conn = conn_iter->next; | 7154 | temp_conn = conn_iter->next; |
7135 | GNUNET_free(conn_iter); | 7155 | GNUNET_free (conn_iter); |
7136 | conn_iter = temp_conn; | 7156 | conn_iter = temp_conn; |
7137 | } | 7157 | } |
7138 | #else | 7158 | #else |
7139 | if (pg->peers[off].allowed_peers != NULL) | 7159 | if (pg->peers[off].allowed_peers != NULL) |
7140 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers); | 7160 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers); |
7141 | if (pg->peers[off].connect_peers != NULL) | 7161 | if (pg->peers[off].connect_peers != NULL) |
7142 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers); | 7162 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].connect_peers); |
7143 | if (pg->peers[off].blacklisted_peers != NULL) | 7163 | if (pg->peers[off].blacklisted_peers != NULL) |
7144 | GNUNET_CONTAINER_multihashmap_destroy (pg-> | 7164 | GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].blacklisted_peers); |
7145 | peers[off].blacklisted_peers); | ||
7146 | #endif | 7165 | #endif |
7147 | } | 7166 | } |
7148 | } | 7167 | } |
7149 | 7168 | ||
7150 | /* end of testing_group.c */ | 7169 | /* end of testing_group.c */ |