diff options
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/gnunet-rps-profiler.c | 284 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps.c | 655 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_custommap.c | 2 | ||||
-rw-r--r-- | src/rps/rps-test_util.c | 80 |
4 files changed, 596 insertions, 425 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c index 16f23e86c..49714872f 100644 --- a/src/rps/gnunet-rps-profiler.c +++ b/src/rps/gnunet-rps-profiler.c | |||
@@ -49,7 +49,11 @@ static unsigned bits_needed; | |||
49 | /** | 49 | /** |
50 | * How long do we run the test? | 50 | * How long do we run the test? |
51 | */ | 51 | */ |
52 | //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 52 | static struct GNUNET_TIME_Relative duration; |
53 | |||
54 | /** | ||
55 | * When do we do a hard shutdown? | ||
56 | */ | ||
53 | static struct GNUNET_TIME_Relative timeout; | 57 | static struct GNUNET_TIME_Relative timeout; |
54 | 58 | ||
55 | 59 | ||
@@ -446,6 +450,10 @@ struct RPSPeer | |||
446 | * @brief statistics values | 450 | * @brief statistics values |
447 | */ | 451 | */ |
448 | uint64_t stats[STAT_TYPE_MAX]; | 452 | uint64_t stats[STAT_TYPE_MAX]; |
453 | /** | ||
454 | * @brief Handle for the statistics get request | ||
455 | */ | ||
456 | struct GNUNET_STATISTICS_GetHandle *h_stat_get[STAT_TYPE_MAX]; | ||
449 | }; | 457 | }; |
450 | 458 | ||
451 | /** | 459 | /** |
@@ -489,15 +497,16 @@ static unsigned int view_sizes; | |||
489 | static int ok; | 497 | static int ok; |
490 | 498 | ||
491 | /** | 499 | /** |
492 | * Identifier for the churn task that runs periodically | 500 | * Identifier for the task that runs after the test to collect results |
493 | */ | 501 | */ |
494 | static struct GNUNET_SCHEDULER_Task *post_test_task; | 502 | static struct GNUNET_SCHEDULER_Task *post_test_task; |
495 | 503 | ||
496 | /** | 504 | /** |
497 | * Identifier for the churn task that runs periodically | 505 | * Identifier for the shutdown task |
498 | */ | 506 | */ |
499 | static struct GNUNET_SCHEDULER_Task *shutdown_task; | 507 | static struct GNUNET_SCHEDULER_Task *shutdown_task; |
500 | 508 | ||
509 | |||
501 | /** | 510 | /** |
502 | * Identifier for the churn task that runs periodically | 511 | * Identifier for the churn task that runs periodically |
503 | */ | 512 | */ |
@@ -874,6 +883,75 @@ static int check_statistics_collect_completed () | |||
874 | return GNUNET_YES; | 883 | return GNUNET_YES; |
875 | } | 884 | } |
876 | 885 | ||
886 | static void | ||
887 | rps_disconnect_adapter (void *cls, | ||
888 | void *op_result); | ||
889 | |||
890 | static void | ||
891 | cancel_pending_req (struct PendingRequest *pending_req) | ||
892 | { | ||
893 | struct RPSPeer *rps_peer; | ||
894 | |||
895 | rps_peer = pending_req->rps_peer; | ||
896 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | ||
897 | rps_peer->pending_req_tail, | ||
898 | pending_req); | ||
899 | rps_peer->num_pending_reqs--; | ||
900 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
901 | "Cancelling pending rps get request\n"); | ||
902 | GNUNET_SCHEDULER_cancel (pending_req->request_task); | ||
903 | GNUNET_free (pending_req); | ||
904 | } | ||
905 | |||
906 | static void | ||
907 | cancel_request (struct PendingReply *pending_rep) | ||
908 | { | ||
909 | struct RPSPeer *rps_peer; | ||
910 | |||
911 | rps_peer = pending_rep->rps_peer; | ||
912 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, | ||
913 | rps_peer->pending_rep_tail, | ||
914 | pending_rep); | ||
915 | rps_peer->num_pending_reps--; | ||
916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
917 | "Cancelling rps get reply\n"); | ||
918 | GNUNET_RPS_request_cancel (pending_rep->req_handle); | ||
919 | GNUNET_free (pending_rep); | ||
920 | } | ||
921 | |||
922 | void | ||
923 | clean_peer (unsigned peer_index) | ||
924 | { | ||
925 | struct PendingRequest *pending_req; | ||
926 | |||
927 | while (NULL != (pending_req = rps_peers[peer_index].pending_req_head)) | ||
928 | { | ||
929 | cancel_pending_req (pending_req); | ||
930 | } | ||
931 | pending_req = rps_peers[peer_index].pending_req_head; | ||
932 | rps_disconnect_adapter (&rps_peers[peer_index], | ||
933 | &rps_peers[peer_index].rps_handle); | ||
934 | for (unsigned stat_type = STAT_TYPE_ROUNDS; | ||
935 | stat_type < STAT_TYPE_MAX; | ||
936 | stat_type++) | ||
937 | { | ||
938 | if (NULL != rps_peers[peer_index].h_stat_get[stat_type]) | ||
939 | { | ||
940 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
941 | "(%u) did not yet receive stat value for `%s'\n", | ||
942 | rps_peers[peer_index].index, | ||
943 | stat_type_2_str (stat_type)); | ||
944 | GNUNET_STATISTICS_get_cancel ( | ||
945 | rps_peers[peer_index].h_stat_get[stat_type]); | ||
946 | } | ||
947 | } | ||
948 | if (NULL != rps_peers[peer_index].op) | ||
949 | { | ||
950 | GNUNET_TESTBED_operation_done (rps_peers[peer_index].op); | ||
951 | rps_peers[peer_index].op = NULL; | ||
952 | } | ||
953 | } | ||
954 | |||
877 | /** | 955 | /** |
878 | * Task run on timeout to shut everything down. | 956 | * Task run on timeout to shut everything down. |
879 | */ | 957 | */ |
@@ -881,35 +959,55 @@ static void | |||
881 | shutdown_op (void *cls) | 959 | shutdown_op (void *cls) |
882 | { | 960 | { |
883 | unsigned int i; | 961 | unsigned int i; |
962 | struct OpListEntry *entry; | ||
884 | 963 | ||
885 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 964 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
886 | "Shutdown task scheduled, going down.\n"); | 965 | "Shutdown task scheduled, going down.\n"); |
887 | in_shutdown = GNUNET_YES; | 966 | in_shutdown = GNUNET_YES; |
967 | |||
968 | if (NULL != shutdown_task) | ||
969 | { | ||
970 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
971 | shutdown_task = NULL; | ||
972 | } | ||
888 | if (NULL != post_test_task) | 973 | if (NULL != post_test_task) |
889 | { | 974 | { |
890 | GNUNET_SCHEDULER_cancel (post_test_task); | 975 | GNUNET_SCHEDULER_cancel (post_test_task); |
976 | post_test_task = NULL; | ||
891 | } | 977 | } |
892 | if (NULL != churn_task) | 978 | if (NULL != churn_task) |
893 | { | 979 | { |
894 | GNUNET_SCHEDULER_cancel (churn_task); | 980 | GNUNET_SCHEDULER_cancel (churn_task); |
895 | churn_task = NULL; | 981 | churn_task = NULL; |
896 | } | 982 | } |
983 | entry = oplist_head; | ||
984 | while (NULL != (entry = oplist_head)) | ||
985 | { | ||
986 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
987 | "Operation still pending on shutdown (%u)\n", | ||
988 | entry->index); | ||
989 | GNUNET_TESTBED_operation_done (entry->op); | ||
990 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | ||
991 | GNUNET_free (entry); | ||
992 | } | ||
897 | for (i = 0; i < num_peers; i++) | 993 | for (i = 0; i < num_peers; i++) |
898 | { | 994 | { |
899 | if (NULL != rps_peers[i].rps_handle) | 995 | clean_peer (i); |
900 | { | ||
901 | GNUNET_RPS_disconnect (rps_peers[i].rps_handle); | ||
902 | } | ||
903 | if (NULL != rps_peers[i].op) | ||
904 | { | ||
905 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | ||
906 | } | ||
907 | } | 996 | } |
908 | } | 997 | } |
909 | 998 | ||
999 | static void | ||
1000 | trigger_shutdown (void *cls) | ||
1001 | { | ||
1002 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1003 | "Shutdown was triggerd by timeout, going down.\n"); | ||
1004 | shutdown_task = NULL; | ||
1005 | GNUNET_SCHEDULER_shutdown (); | ||
1006 | } | ||
1007 | |||
910 | 1008 | ||
911 | /** | 1009 | /** |
912 | * Task run on timeout to collect statistics and potentially shut down. | 1010 | * Task run after #duration to collect statistics and potentially shut down. |
913 | */ | 1011 | */ |
914 | static void | 1012 | static void |
915 | post_test_op (void *cls) | 1013 | post_test_op (void *cls) |
@@ -919,7 +1017,7 @@ post_test_op (void *cls) | |||
919 | post_test_task = NULL; | 1017 | post_test_task = NULL; |
920 | post_test = GNUNET_YES; | 1018 | post_test = GNUNET_YES; |
921 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1019 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
922 | "Post test task scheduled, going down.\n"); | 1020 | "Post test task scheduled.\n"); |
923 | if (NULL != churn_task) | 1021 | if (NULL != churn_task) |
924 | { | 1022 | { |
925 | GNUNET_SCHEDULER_cancel (churn_task); | 1023 | GNUNET_SCHEDULER_cancel (churn_task); |
@@ -943,7 +1041,7 @@ post_test_op (void *cls) | |||
943 | GNUNET_YES == check_statistics_collect_completed()) | 1041 | GNUNET_YES == check_statistics_collect_completed()) |
944 | { | 1042 | { |
945 | GNUNET_SCHEDULER_cancel (shutdown_task); | 1043 | GNUNET_SCHEDULER_cancel (shutdown_task); |
946 | shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL); | 1044 | shutdown_task = NULL; |
947 | GNUNET_SCHEDULER_shutdown (); | 1045 | GNUNET_SCHEDULER_shutdown (); |
948 | } | 1046 | } |
949 | } | 1047 | } |
@@ -1030,9 +1128,9 @@ info_cb (void *cb_cls, | |||
1030 | */ | 1128 | */ |
1031 | static void | 1129 | static void |
1032 | rps_connect_complete_cb (void *cls, | 1130 | rps_connect_complete_cb (void *cls, |
1033 | struct GNUNET_TESTBED_Operation *op, | 1131 | struct GNUNET_TESTBED_Operation *op, |
1034 | void *ca_result, | 1132 | void *ca_result, |
1035 | const char *emsg) | 1133 | const char *emsg) |
1036 | { | 1134 | { |
1037 | struct RPSPeer *rps_peer = cls; | 1135 | struct RPSPeer *rps_peer = cls; |
1038 | struct GNUNET_RPS_Handle *rps = ca_result; | 1136 | struct GNUNET_RPS_Handle *rps = ca_result; |
@@ -1057,7 +1155,9 @@ rps_connect_complete_cb (void *cls, | |||
1057 | return; | 1155 | return; |
1058 | } | 1156 | } |
1059 | 1157 | ||
1060 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); | 1158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1159 | "Started client successfully (%u)\n", | ||
1160 | rps_peer->index); | ||
1061 | 1161 | ||
1062 | cur_test_run.main_test (rps_peer); | 1162 | cur_test_run.main_test (rps_peer); |
1063 | } | 1163 | } |
@@ -1075,7 +1175,7 @@ rps_connect_complete_cb (void *cls, | |||
1075 | */ | 1175 | */ |
1076 | static void * | 1176 | static void * |
1077 | rps_connect_adapter (void *cls, | 1177 | rps_connect_adapter (void *cls, |
1078 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1178 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1079 | { | 1179 | { |
1080 | struct GNUNET_RPS_Handle *h; | 1180 | struct GNUNET_RPS_Handle *h; |
1081 | 1181 | ||
@@ -1167,15 +1267,26 @@ stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
1167 | */ | 1267 | */ |
1168 | static void | 1268 | static void |
1169 | rps_disconnect_adapter (void *cls, | 1269 | rps_disconnect_adapter (void *cls, |
1170 | void *op_result) | 1270 | void *op_result) |
1171 | { | 1271 | { |
1172 | struct RPSPeer *peer = cls; | 1272 | struct RPSPeer *peer = cls; |
1173 | struct GNUNET_RPS_Handle *h = op_result; | 1273 | struct GNUNET_RPS_Handle *h = op_result; |
1274 | struct PendingReply *pending_rep; | ||
1174 | 1275 | ||
1175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnect_adapter()\n"); | 1276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1277 | "disconnect_adapter (%u)\n", | ||
1278 | peer->index); | ||
1176 | GNUNET_assert (NULL != peer); | 1279 | GNUNET_assert (NULL != peer); |
1177 | GNUNET_RPS_disconnect (h); | 1280 | if (NULL != peer->rps_handle) |
1178 | peer->rps_handle = NULL; | 1281 | { |
1282 | while (NULL != (pending_rep = peer->pending_rep_head)) | ||
1283 | { | ||
1284 | cancel_request (pending_rep); | ||
1285 | } | ||
1286 | GNUNET_assert (h == peer->rps_handle); | ||
1287 | GNUNET_RPS_disconnect (h); | ||
1288 | peer->rps_handle = NULL; | ||
1289 | } | ||
1179 | } | 1290 | } |
1180 | 1291 | ||
1181 | 1292 | ||
@@ -1219,13 +1330,15 @@ default_reply_handle (void *cls, | |||
1219 | rps_peer->num_recv_ids++; | 1330 | rps_peer->num_recv_ids++; |
1220 | } | 1331 | } |
1221 | 1332 | ||
1222 | if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) | 1333 | if (GNUNET_YES != post_test) return; |
1334 | if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit) return; | ||
1335 | if (0 == evaluate()) | ||
1223 | { | 1336 | { |
1224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); | 1337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1225 | GNUNET_assert (NULL != post_test_task); | 1338 | "Test succeeded before end of duration\n"); |
1226 | GNUNET_SCHEDULER_cancel (post_test_task); | 1339 | if (NULL != post_test_task) GNUNET_SCHEDULER_cancel (post_test_task); |
1227 | post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); | 1340 | post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); |
1228 | GNUNET_assert (NULL!= post_test_task); | 1341 | GNUNET_assert (NULL != post_test_task); |
1229 | } | 1342 | } |
1230 | } | 1343 | } |
1231 | 1344 | ||
@@ -1239,13 +1352,13 @@ request_peers (void *cls) | |||
1239 | struct RPSPeer *rps_peer; | 1352 | struct RPSPeer *rps_peer; |
1240 | struct PendingReply *pending_rep; | 1353 | struct PendingReply *pending_rep; |
1241 | 1354 | ||
1242 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1243 | return; | ||
1244 | rps_peer = pending_req->rps_peer; | 1355 | rps_peer = pending_req->rps_peer; |
1245 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); | 1356 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); |
1246 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | 1357 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, |
1247 | rps_peer->pending_req_tail, | 1358 | rps_peer->pending_req_tail, |
1248 | pending_req); | 1359 | pending_req); |
1360 | rps_peer->num_pending_reqs--; | ||
1361 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) return; | ||
1249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1250 | "Requesting one peer\n"); | 1363 | "Requesting one peer\n"); |
1251 | pending_rep = GNUNET_new (struct PendingReply); | 1364 | pending_rep = GNUNET_new (struct PendingReply); |
@@ -1258,39 +1371,6 @@ request_peers (void *cls) | |||
1258 | rps_peer->pending_rep_tail, | 1371 | rps_peer->pending_rep_tail, |
1259 | pending_rep); | 1372 | pending_rep); |
1260 | rps_peer->num_pending_reps++; | 1373 | rps_peer->num_pending_reps++; |
1261 | rps_peer->num_pending_reqs--; | ||
1262 | } | ||
1263 | |||
1264 | static void | ||
1265 | cancel_pending_req (struct PendingRequest *pending_req) | ||
1266 | { | ||
1267 | struct RPSPeer *rps_peer; | ||
1268 | |||
1269 | rps_peer = pending_req->rps_peer; | ||
1270 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | ||
1271 | rps_peer->pending_req_tail, | ||
1272 | pending_req); | ||
1273 | rps_peer->num_pending_reqs--; | ||
1274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1275 | "Cancelling pending request\n"); | ||
1276 | GNUNET_SCHEDULER_cancel (pending_req->request_task); | ||
1277 | GNUNET_free (pending_req); | ||
1278 | } | ||
1279 | |||
1280 | static void | ||
1281 | cancel_request (struct PendingReply *pending_rep) | ||
1282 | { | ||
1283 | struct RPSPeer *rps_peer; | ||
1284 | |||
1285 | rps_peer = pending_rep->rps_peer; | ||
1286 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, | ||
1287 | rps_peer->pending_rep_tail, | ||
1288 | pending_rep); | ||
1289 | rps_peer->num_pending_reps--; | ||
1290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1291 | "Cancelling request\n"); | ||
1292 | GNUNET_RPS_request_cancel (pending_rep->req_handle); | ||
1293 | GNUNET_free (pending_rep); | ||
1294 | } | 1374 | } |
1295 | 1375 | ||
1296 | 1376 | ||
@@ -2261,12 +2341,6 @@ void write_final_stats (void){ | |||
2261 | stat_type < STAT_TYPE_MAX; | 2341 | stat_type < STAT_TYPE_MAX; |
2262 | stat_type++) | 2342 | stat_type++) |
2263 | { | 2343 | { |
2264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2265 | "Add to sum (%" PRIu64 ") %" PRIu64 " of stat type %u - %s\n", | ||
2266 | sums[stat_type], | ||
2267 | rps_peers[i].stats[stat_type], | ||
2268 | stat_type, | ||
2269 | stat_type_2_str (stat_type)); | ||
2270 | sums[stat_type] += rps_peers[i].stats[stat_type]; | 2344 | sums[stat_type] += rps_peers[i].stats[stat_type]; |
2271 | } | 2345 | } |
2272 | } | 2346 | } |
@@ -2312,6 +2386,8 @@ post_test_shutdown_ready_cb (void *cls, | |||
2312 | { | 2386 | { |
2313 | struct STATcls *stat_cls = (struct STATcls *) cls; | 2387 | struct STATcls *stat_cls = (struct STATcls *) cls; |
2314 | struct RPSPeer *rps_peer = stat_cls->rps_peer; | 2388 | struct RPSPeer *rps_peer = stat_cls->rps_peer; |
2389 | |||
2390 | rps_peer->h_stat_get[stat_cls->stat_type] = NULL; | ||
2315 | if (GNUNET_OK == success) | 2391 | if (GNUNET_OK == success) |
2316 | { | 2392 | { |
2317 | /* set flag that we we got the value */ | 2393 | /* set flag that we we got the value */ |
@@ -2363,6 +2439,7 @@ stat_iterator (void *cls, | |||
2363 | { | 2439 | { |
2364 | const struct STATcls *stat_cls = (const struct STATcls *) cls; | 2440 | const struct STATcls *stat_cls = (const struct STATcls *) cls; |
2365 | struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; | 2441 | struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; |
2442 | |||
2366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", | 2443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", |
2367 | //stat_type_2_str (stat_cls->stat_type), | 2444 | //stat_type_2_str (stat_cls->stat_type), |
2368 | name, | 2445 | name, |
@@ -2455,12 +2532,13 @@ void post_profiler (struct RPSPeer *rps_peer) | |||
2455 | stat_cls->stat_type = stat_type; | 2532 | stat_cls->stat_type = stat_type; |
2456 | rps_peer->file_name_stats = | 2533 | rps_peer->file_name_stats = |
2457 | store_prefix_file_name (rps_peer->peer_id, "stats"); | 2534 | store_prefix_file_name (rps_peer->peer_id, "stats"); |
2458 | GNUNET_STATISTICS_get (rps_peer->stats_h, | 2535 | rps_peer->h_stat_get[stat_type] = GNUNET_STATISTICS_get ( |
2459 | "rps", | 2536 | rps_peer->stats_h, |
2460 | stat_type_2_str (stat_type), | 2537 | "rps", |
2461 | post_test_shutdown_ready_cb, | 2538 | stat_type_2_str (stat_type), |
2462 | stat_iterator, | 2539 | post_test_shutdown_ready_cb, |
2463 | (struct STATcls *) stat_cls); | 2540 | stat_iterator, |
2541 | (struct STATcls *) stat_cls); | ||
2464 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2465 | "Requested statistics for %s (peer %" PRIu32 ")\n", | 2543 | "Requested statistics for %s (peer %" PRIu32 ")\n", |
2466 | stat_type_2_str (stat_type), | 2544 | stat_type_2_str (stat_type), |
@@ -2555,6 +2633,8 @@ test_run (void *cls, | |||
2555 | /* Connect all peers to statistics service */ | 2633 | /* Connect all peers to statistics service */ |
2556 | if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) | 2634 | if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) |
2557 | { | 2635 | { |
2636 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2637 | "Connecting to statistics service\n"); | ||
2558 | rps_peers[i].stat_op = | 2638 | rps_peers[i].stat_op = |
2559 | GNUNET_TESTBED_service_connect (NULL, | 2639 | GNUNET_TESTBED_service_connect (NULL, |
2560 | peers[i], | 2640 | peers[i], |
@@ -2569,11 +2649,12 @@ test_run (void *cls, | |||
2569 | 2649 | ||
2570 | if (NULL != churn_task) | 2650 | if (NULL != churn_task) |
2571 | GNUNET_SCHEDULER_cancel (churn_task); | 2651 | GNUNET_SCHEDULER_cancel (churn_task); |
2572 | post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL); | 2652 | post_test_task = GNUNET_SCHEDULER_add_delayed (duration, &post_test_op, NULL); |
2573 | timeout = GNUNET_TIME_relative_multiply (timeout, 1 + (0.1 * num_peers)); | 2653 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", timeout.rel_value_us/1000000); |
2574 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); | 2654 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, |
2575 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); | 2655 | &trigger_shutdown, |
2576 | 2656 | NULL); | |
2657 | GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); | ||
2577 | } | 2658 | } |
2578 | 2659 | ||
2579 | 2660 | ||
@@ -2609,7 +2690,7 @@ run (void *cls, | |||
2609 | if (0 == cur_test_run.num_requests) cur_test_run.num_requests = 5; | 2690 | if (0 == cur_test_run.num_requests) cur_test_run.num_requests = 5; |
2610 | //cur_test_run.have_churn = HAVE_CHURN; | 2691 | //cur_test_run.have_churn = HAVE_CHURN; |
2611 | cur_test_run.have_churn = HAVE_NO_CHURN; | 2692 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2612 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | 2693 | cur_test_run.have_quick_quit = HAVE_QUICK_QUIT; |
2613 | cur_test_run.have_collect_statistics = COLLECT_STATISTICS; | 2694 | cur_test_run.have_collect_statistics = COLLECT_STATISTICS; |
2614 | cur_test_run.stat_collect_flags = BIT(STAT_TYPE_ROUNDS) | | 2695 | cur_test_run.stat_collect_flags = BIT(STAT_TYPE_ROUNDS) | |
2615 | BIT(STAT_TYPE_BLOCKS) | | 2696 | BIT(STAT_TYPE_BLOCKS) | |
@@ -2632,10 +2713,38 @@ run (void *cls, | |||
2632 | /* 'Clean' directory */ | 2713 | /* 'Clean' directory */ |
2633 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); | 2714 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); |
2634 | GNUNET_DISK_directory_create ("/tmp/rps/"); | 2715 | GNUNET_DISK_directory_create ("/tmp/rps/"); |
2635 | if (0 == timeout.rel_value_us) | 2716 | if (0 == duration.rel_value_us) |
2636 | { | 2717 | { |
2637 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90); | 2718 | if (0 == timeout.rel_value_us) |
2719 | { | ||
2720 | duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90); | ||
2721 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
2722 | (90 * 1.2) + | ||
2723 | (0.01 * num_peers)); | ||
2724 | } | ||
2725 | else | ||
2726 | { | ||
2727 | duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
2728 | (timeout.rel_value_us/1000000) | ||
2729 | * 0.75); | ||
2730 | } | ||
2638 | } | 2731 | } |
2732 | else | ||
2733 | { | ||
2734 | if (0 == timeout.rel_value_us) | ||
2735 | { | ||
2736 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
2737 | ((duration.rel_value_us/1000000) | ||
2738 | * 1.2) + (0.01 * num_peers)); | ||
2739 | } | ||
2740 | } | ||
2741 | GNUNET_assert (duration.rel_value_us < timeout.rel_value_us); | ||
2742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2743 | "duration is %lus\n", | ||
2744 | duration.rel_value_us/1000000); | ||
2745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2746 | "timeout is %lus\n", | ||
2747 | timeout.rel_value_us/1000000); | ||
2639 | 2748 | ||
2640 | /* Compute number of bits for representing largest peer id */ | 2749 | /* Compute number of bits for representing largest peer id */ |
2641 | for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++) | 2750 | for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++) |
@@ -2685,6 +2794,12 @@ main (int argc, char *argv[]) | |||
2685 | gettext_noop ("number of peers to start"), | 2794 | gettext_noop ("number of peers to start"), |
2686 | &num_peers), | 2795 | &num_peers), |
2687 | 2796 | ||
2797 | GNUNET_GETOPT_option_relative_time ('d', | ||
2798 | "duration", | ||
2799 | "DURATION", | ||
2800 | gettext_noop ("duration of the profiling"), | ||
2801 | &duration), | ||
2802 | |||
2688 | GNUNET_GETOPT_option_relative_time ('t', | 2803 | GNUNET_GETOPT_option_relative_time ('t', |
2689 | "timeout", | 2804 | "timeout", |
2690 | "TIMEOUT", | 2805 | "TIMEOUT", |
@@ -2732,7 +2847,6 @@ main (int argc, char *argv[]) | |||
2732 | GNUNET_free (rps_peers); | 2847 | GNUNET_free (rps_peers); |
2733 | GNUNET_free (rps_peer_ids); | 2848 | GNUNET_free (rps_peer_ids); |
2734 | GNUNET_CONTAINER_multipeermap_destroy (peer_map); | 2849 | GNUNET_CONTAINER_multipeermap_destroy (peer_map); |
2735 | printf ("test -1\n"); | ||
2736 | return ret_value; | 2850 | return ret_value; |
2737 | } | 2851 | } |
2738 | 2852 | ||
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 5a75ac55a..21963ee42 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -68,6 +68,7 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
68 | */ | 68 | */ |
69 | static struct GNUNET_PeerIdentity own_identity; | 69 | static struct GNUNET_PeerIdentity own_identity; |
70 | 70 | ||
71 | static int in_shutdown = GNUNET_NO; | ||
71 | 72 | ||
72 | /** | 73 | /** |
73 | * @brief Port used for cadet. | 74 | * @brief Port used for cadet. |
@@ -97,11 +98,6 @@ static struct GNUNET_HashCode port; | |||
97 | #define unset_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask)) | 98 | #define unset_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask)) |
98 | 99 | ||
99 | /** | 100 | /** |
100 | * Set a channel flag of given channel context. | ||
101 | */ | ||
102 | #define set_channel_flag(channel_flags, mask) ((*channel_flags) |= (mask)) | ||
103 | |||
104 | /** | ||
105 | * Get channel flag of given channel context. | 101 | * Get channel flag of given channel context. |
106 | */ | 102 | */ |
107 | #define check_channel_flag_set(channel_flags, mask)\ | 103 | #define check_channel_flag_set(channel_flags, mask)\ |
@@ -164,6 +160,11 @@ struct PendingMessage | |||
164 | }; | 160 | }; |
165 | 161 | ||
166 | /** | 162 | /** |
163 | * @brief Context for a channel | ||
164 | */ | ||
165 | struct ChannelCtx; | ||
166 | |||
167 | /** | ||
167 | * Struct used to keep track of other peer's status | 168 | * Struct used to keep track of other peer's status |
168 | * | 169 | * |
169 | * This is stored in a multipeermap. | 170 | * This is stored in a multipeermap. |
@@ -181,22 +182,12 @@ struct PeerContext | |||
181 | /** | 182 | /** |
182 | * Channel open to client. | 183 | * Channel open to client. |
183 | */ | 184 | */ |
184 | struct GNUNET_CADET_Channel *send_channel; | 185 | struct ChannelCtx *send_channel_ctx; |
185 | |||
186 | /** | ||
187 | * Flags to the sending channel | ||
188 | */ | ||
189 | uint32_t *send_channel_flags; | ||
190 | 186 | ||
191 | /** | 187 | /** |
192 | * Channel open from client. | 188 | * Channel open from client. |
193 | */ | 189 | */ |
194 | struct GNUNET_CADET_Channel *recv_channel; // unneeded? | 190 | struct ChannelCtx *recv_channel_ctx; |
195 | |||
196 | /** | ||
197 | * Flags to the receiving channel | ||
198 | */ | ||
199 | uint32_t *recv_channel_flags; | ||
200 | 191 | ||
201 | /** | 192 | /** |
202 | * Array of pending operations on this peer. | 193 | * Array of pending operations on this peer. |
@@ -242,6 +233,11 @@ struct PeerContext | |||
242 | struct PendingMessage *pending_messages_tail; | 233 | struct PendingMessage *pending_messages_tail; |
243 | 234 | ||
244 | /** | 235 | /** |
236 | * @brief Task to destroy this context. | ||
237 | */ | ||
238 | struct GNUNET_SCHEDULER_Task *destruction_task; | ||
239 | |||
240 | /** | ||
245 | * This is pobably followed by 'statistical' data (when we first saw | 241 | * This is pobably followed by 'statistical' data (when we first saw |
246 | * it, how did we get its ID, how many pushes (in a timeinterval), | 242 | * it, how did we get its ID, how many pushes (in a timeinterval), |
247 | * ...) | 243 | * ...) |
@@ -265,6 +261,33 @@ struct PeersIteratorCls | |||
265 | }; | 261 | }; |
266 | 262 | ||
267 | /** | 263 | /** |
264 | * @brief Context for a channel | ||
265 | */ | ||
266 | struct ChannelCtx | ||
267 | { | ||
268 | /** | ||
269 | * @brief Meant to be used in a DLL | ||
270 | */ | ||
271 | struct ChannelCtx *next; | ||
272 | struct ChannelCtx *prev; | ||
273 | |||
274 | /** | ||
275 | * @brief The channel itself | ||
276 | */ | ||
277 | struct GNUNET_CADET_Channel *channel; | ||
278 | |||
279 | /** | ||
280 | * @brief The peer context associated with the channel | ||
281 | */ | ||
282 | struct PeerContext *peer_ctx; | ||
283 | |||
284 | /** | ||
285 | * @brief Scheduled task that will destroy this context | ||
286 | */ | ||
287 | struct GNUNET_SCHEDULER_Task *destruction_task; | ||
288 | }; | ||
289 | |||
290 | /** | ||
268 | * @brief Hashmap of valid peers. | 291 | * @brief Hashmap of valid peers. |
269 | */ | 292 | */ |
270 | static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; | 293 | static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; |
@@ -332,8 +355,6 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer) | |||
332 | 355 | ||
333 | ctx = GNUNET_new (struct PeerContext); | 356 | ctx = GNUNET_new (struct PeerContext); |
334 | ctx->peer_id = *peer; | 357 | ctx->peer_id = *peer; |
335 | ctx->send_channel_flags = GNUNET_new (uint32_t); | ||
336 | ctx->recv_channel_flags = GNUNET_new (uint32_t); | ||
337 | ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, | 358 | ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, |
338 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 359 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
339 | GNUNET_assert (GNUNET_OK == ret); | 360 | GNUNET_assert (GNUNET_OK == ret); |
@@ -387,8 +408,8 @@ Peers_check_connected (const struct GNUNET_PeerIdentity *peer) | |||
387 | /* Get the context */ | 408 | /* Get the context */ |
388 | peer_ctx = get_peer_ctx (peer); | 409 | peer_ctx = get_peer_ctx (peer); |
389 | /* If we have no channel to this peer we don't know whether it's online */ | 410 | /* If we have no channel to this peer we don't know whether it's online */ |
390 | if ( (NULL == peer_ctx->send_channel) && | 411 | if ( (NULL == peer_ctx->send_channel_ctx) && |
391 | (NULL == peer_ctx->recv_channel) ) | 412 | (NULL == peer_ctx->recv_channel_ctx) ) |
392 | { | 413 | { |
393 | Peers_unset_peer_flag (peer, Peers_ONLINE); | 414 | Peers_unset_peer_flag (peer, Peers_ONLINE); |
394 | return GNUNET_NO; | 415 | return GNUNET_NO; |
@@ -575,6 +596,24 @@ handle_peer_pull_reply (void *cls, | |||
575 | 596 | ||
576 | /* End declaration of handlers */ | 597 | /* End declaration of handlers */ |
577 | 598 | ||
599 | /** | ||
600 | * @brief Allocate memory for a new channel context and insert it into DLL | ||
601 | * | ||
602 | * @param peer_ctx context of the according peer | ||
603 | * | ||
604 | * @return The channel context | ||
605 | */ | ||
606 | static struct ChannelCtx * | ||
607 | add_channel_ctx (struct PeerContext *peer_ctx); | ||
608 | |||
609 | /** | ||
610 | * @brief Remove the channel context from the DLL and free the memory. | ||
611 | * | ||
612 | * @param channel_ctx The channel context. | ||
613 | */ | ||
614 | static void | ||
615 | remove_channel_ctx (struct ChannelCtx *channel_ctx); | ||
616 | |||
578 | 617 | ||
579 | /** | 618 | /** |
580 | * @brief Get the channel of a peer. If not existing, create. | 619 | * @brief Get the channel of a peer. If not existing, create. |
@@ -610,16 +649,17 @@ get_channel (const struct GNUNET_PeerIdentity *peer) | |||
610 | 649 | ||
611 | 650 | ||
612 | peer_ctx = get_peer_ctx (peer); | 651 | peer_ctx = get_peer_ctx (peer); |
613 | if (NULL == peer_ctx->send_channel) | 652 | if (NULL == peer_ctx->send_channel_ctx) |
614 | { | 653 | { |
615 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 654 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
616 | "Trying to establish channel to peer %s\n", | 655 | "Trying to establish channel to peer %s\n", |
617 | GNUNET_i2s (peer)); | 656 | GNUNET_i2s (peer)); |
618 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); | 657 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); |
619 | *ctx_peer = *peer; | 658 | *ctx_peer = *peer; |
620 | peer_ctx->send_channel = | 659 | peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx); |
660 | peer_ctx->send_channel_ctx->channel = | ||
621 | GNUNET_CADET_channel_create (cadet_handle, | 661 | GNUNET_CADET_channel_create (cadet_handle, |
622 | (struct GNUNET_PeerIdentity *) ctx_peer, /* context */ | 662 | peer_ctx->send_channel_ctx, /* context */ |
623 | peer, | 663 | peer, |
624 | &port, | 664 | &port, |
625 | GNUNET_CADET_OPTION_RELIABLE, | 665 | GNUNET_CADET_OPTION_RELIABLE, |
@@ -627,8 +667,9 @@ get_channel (const struct GNUNET_PeerIdentity *peer) | |||
627 | cleanup_destroyed_channel, /* Disconnect handler */ | 667 | cleanup_destroyed_channel, /* Disconnect handler */ |
628 | cadet_handlers); | 668 | cadet_handlers); |
629 | } | 669 | } |
630 | GNUNET_assert (NULL != peer_ctx->send_channel); | 670 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx); |
631 | return peer_ctx->send_channel; | 671 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel); |
672 | return peer_ctx->send_channel_ctx->channel; | ||
632 | } | 673 | } |
633 | 674 | ||
634 | 675 | ||
@@ -1045,12 +1086,10 @@ restore_valid_peers () | |||
1045 | */ | 1086 | */ |
1046 | void | 1087 | void |
1047 | Peers_initialise (char* fn_valid_peers, | 1088 | Peers_initialise (char* fn_valid_peers, |
1048 | struct GNUNET_CADET_Handle *cadet_h, | 1089 | struct GNUNET_CADET_Handle *cadet_h) |
1049 | const struct GNUNET_PeerIdentity *own_id) | ||
1050 | { | 1090 | { |
1051 | filename_valid_peers = GNUNET_strdup (fn_valid_peers); | 1091 | filename_valid_peers = GNUNET_strdup (fn_valid_peers); |
1052 | cadet_handle = cadet_h; | 1092 | cadet_handle = cadet_h; |
1053 | own_identity = *own_id; | ||
1054 | peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 1093 | peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
1055 | valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 1094 | valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
1056 | restore_valid_peers (); | 1095 | restore_valid_peers (); |
@@ -1136,14 +1175,12 @@ Peers_get_valid_peers (PeersIterator iterator, | |||
1136 | * @param peer the new #GNUNET_PeerIdentity | 1175 | * @param peer the new #GNUNET_PeerIdentity |
1137 | * | 1176 | * |
1138 | * @return #GNUNET_YES if peer was inserted | 1177 | * @return #GNUNET_YES if peer was inserted |
1139 | * #GNUNET_NO otherwise (if peer was already known or | 1178 | * #GNUNET_NO otherwise |
1140 | * peer was #own_identity) | ||
1141 | */ | 1179 | */ |
1142 | int | 1180 | int |
1143 | Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) | 1181 | Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) |
1144 | { | 1182 | { |
1145 | if ( (GNUNET_YES == Peers_check_peer_known (peer)) || | 1183 | if (GNUNET_YES == Peers_check_peer_known (peer)) |
1146 | (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) ) | ||
1147 | { | 1184 | { |
1148 | return GNUNET_NO; /* We already know this peer - nothing to do */ | 1185 | return GNUNET_NO; /* We already know this peer - nothing to do */ |
1149 | } | 1186 | } |
@@ -1161,8 +1198,7 @@ Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl | |||
1161 | * | 1198 | * |
1162 | * @param peer the peer whose liveliness is to be checked | 1199 | * @param peer the peer whose liveliness is to be checked |
1163 | * @return #GNUNET_YES if peer had to be inserted | 1200 | * @return #GNUNET_YES if peer had to be inserted |
1164 | * #GNUNET_NO otherwise (if peer was already known or | 1201 | * #GNUNET_NO otherwise |
1165 | * peer was #own_identity) | ||
1166 | */ | 1202 | */ |
1167 | int | 1203 | int |
1168 | Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) | 1204 | Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) |
@@ -1170,13 +1206,10 @@ Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) | |||
1170 | struct PeerContext *peer_ctx; | 1206 | struct PeerContext *peer_ctx; |
1171 | int ret; | 1207 | int ret; |
1172 | 1208 | ||
1173 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) | ||
1174 | { | ||
1175 | return GNUNET_NO; | ||
1176 | } | ||
1177 | ret = Peers_insert_peer (peer); | 1209 | ret = Peers_insert_peer (peer); |
1178 | peer_ctx = get_peer_ctx (peer); | 1210 | peer_ctx = get_peer_ctx (peer); |
1179 | if (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) | 1211 | if ( (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) && |
1212 | (NULL == peer_ctx->liveliness_check_pending) ) | ||
1180 | { | 1213 | { |
1181 | check_peer_live (peer_ctx); | 1214 | check_peer_live (peer_ctx); |
1182 | } | 1215 | } |
@@ -1208,7 +1241,7 @@ Peers_check_removable (const struct GNUNET_PeerIdentity *peer) | |||
1208 | } | 1241 | } |
1209 | 1242 | ||
1210 | peer_ctx = get_peer_ctx (peer); | 1243 | peer_ctx = get_peer_ctx (peer); |
1211 | if ( (NULL != peer_ctx->recv_channel) || | 1244 | if ( (NULL != peer_ctx->recv_channel_ctx) || |
1212 | (NULL != peer_ctx->pending_messages_head) || | 1245 | (NULL != peer_ctx->pending_messages_head) || |
1213 | (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) ) | 1246 | (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) ) |
1214 | { | 1247 | { |
@@ -1224,6 +1257,46 @@ Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer, | |||
1224 | int | 1257 | int |
1225 | Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags); | 1258 | Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags); |
1226 | 1259 | ||
1260 | static void | ||
1261 | destroy_peer (void *cls) | ||
1262 | { | ||
1263 | struct PeerContext *peer_ctx = cls; | ||
1264 | |||
1265 | GNUNET_assert (NULL != peer_ctx); | ||
1266 | peer_ctx->destruction_task = NULL; | ||
1267 | Peers_remove_peer (&peer_ctx->peer_id); | ||
1268 | } | ||
1269 | |||
1270 | static void | ||
1271 | destroy_channel (void *cls); | ||
1272 | |||
1273 | |||
1274 | static void | ||
1275 | schedule_channel_destruction (struct ChannelCtx *channel_ctx) | ||
1276 | { | ||
1277 | GNUNET_assert (NULL != channel_ctx); | ||
1278 | if (NULL != channel_ctx->destruction_task && | ||
1279 | GNUNET_NO == in_shutdown) | ||
1280 | { | ||
1281 | channel_ctx->destruction_task = | ||
1282 | GNUNET_SCHEDULER_add_now (destroy_channel, channel_ctx); | ||
1283 | } | ||
1284 | } | ||
1285 | |||
1286 | |||
1287 | static void | ||
1288 | schedule_peer_destruction (struct PeerContext *peer_ctx) | ||
1289 | { | ||
1290 | GNUNET_assert (NULL != peer_ctx); | ||
1291 | if (NULL != peer_ctx->destruction_task && | ||
1292 | GNUNET_NO == in_shutdown) | ||
1293 | { | ||
1294 | peer_ctx->destruction_task = | ||
1295 | GNUNET_SCHEDULER_add_now (destroy_peer, peer_ctx); | ||
1296 | } | ||
1297 | } | ||
1298 | |||
1299 | |||
1227 | /** | 1300 | /** |
1228 | * @brief Remove peer | 1301 | * @brief Remove peer |
1229 | * | 1302 | * |
@@ -1235,7 +1308,8 @@ int | |||
1235 | Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | 1308 | Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) |
1236 | { | 1309 | { |
1237 | struct PeerContext *peer_ctx; | 1310 | struct PeerContext *peer_ctx; |
1238 | uint32_t *channel_flag; | 1311 | |
1312 | GNUNET_assert (NULL != peer_map); | ||
1239 | 1313 | ||
1240 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) | 1314 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) |
1241 | { | 1315 | { |
@@ -1249,7 +1323,12 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1249 | GNUNET_i2s (&peer_ctx->peer_id)); | 1323 | GNUNET_i2s (&peer_ctx->peer_id)); |
1250 | Peers_unset_peer_flag (peer, Peers_ONLINE); | 1324 | Peers_unset_peer_flag (peer, Peers_ONLINE); |
1251 | 1325 | ||
1326 | /* Clear list of pending operations */ | ||
1327 | // TODO this probably leaks memory | ||
1328 | // ('only' the cls to the function. Not sure what to do with it) | ||
1252 | GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); | 1329 | GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); |
1330 | |||
1331 | /* Remove all pending messages */ | ||
1253 | while (NULL != peer_ctx->pending_messages_head) | 1332 | while (NULL != peer_ctx->pending_messages_head) |
1254 | { | 1333 | { |
1255 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1334 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1261,10 +1340,12 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1261 | peer_ctx->liveliness_check_pending, | 1340 | peer_ctx->liveliness_check_pending, |
1262 | sizeof (struct PendingMessage))) ) | 1341 | sizeof (struct PendingMessage))) ) |
1263 | { | 1342 | { |
1343 | // TODO this may leak memory | ||
1264 | peer_ctx->liveliness_check_pending = NULL; | 1344 | peer_ctx->liveliness_check_pending = NULL; |
1265 | } | 1345 | } |
1266 | remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES); | 1346 | remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES); |
1267 | } | 1347 | } |
1348 | |||
1268 | /* If we are still waiting for notification whether this peer is live | 1349 | /* If we are still waiting for notification whether this peer is live |
1269 | * cancel the according task */ | 1350 | * cancel the according task */ |
1270 | if (NULL != peer_ctx->liveliness_check_pending) | 1351 | if (NULL != peer_ctx->liveliness_check_pending) |
@@ -1277,28 +1358,40 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1277 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); | 1358 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); |
1278 | peer_ctx->liveliness_check_pending = NULL; | 1359 | peer_ctx->liveliness_check_pending = NULL; |
1279 | } | 1360 | } |
1280 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING); | 1361 | |
1281 | if (NULL != peer_ctx->send_channel && | 1362 | |
1282 | GNUNET_YES != Peers_check_channel_flag (channel_flag, Peers_CHANNEL_DESTROING)) | 1363 | /* Do we still have to wait for destruction of channels |
1364 | * or issue the destruction? */ | ||
1365 | if (NULL != peer_ctx->send_channel_ctx && | ||
1366 | NULL != peer_ctx->send_channel_ctx->destruction_task | ||
1367 | ) | ||
1283 | { | 1368 | { |
1284 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1369 | schedule_peer_destruction (peer_ctx); |
1285 | "Destroying send channel\n"); | 1370 | return GNUNET_NO; |
1286 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); | ||
1287 | peer_ctx->send_channel = NULL; | ||
1288 | peer_ctx->mq = NULL; | ||
1289 | } | 1371 | } |
1290 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_RECEIVING); | 1372 | if (NULL != peer_ctx->recv_channel_ctx && |
1291 | if (NULL != peer_ctx->recv_channel && | 1373 | NULL != peer_ctx->recv_channel_ctx->destruction_task) |
1292 | GNUNET_YES != Peers_check_channel_flag (channel_flag, Peers_CHANNEL_DESTROING)) | ||
1293 | { | 1374 | { |
1294 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1375 | schedule_peer_destruction (peer_ctx); |
1295 | "Destroying recv channel\n"); | 1376 | return GNUNET_NO; |
1296 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); | 1377 | } |
1297 | peer_ctx->recv_channel = NULL; | 1378 | if (NULL != peer_ctx->recv_channel_ctx) |
1379 | { | ||
1380 | schedule_channel_destruction (peer_ctx->recv_channel_ctx); | ||
1381 | schedule_peer_destruction (peer_ctx); | ||
1382 | return GNUNET_NO; | ||
1383 | } | ||
1384 | if (NULL != peer_ctx->send_channel_ctx) | ||
1385 | { | ||
1386 | schedule_channel_destruction (peer_ctx->send_channel_ctx); | ||
1387 | schedule_peer_destruction (peer_ctx); | ||
1388 | return GNUNET_NO; | ||
1298 | } | 1389 | } |
1299 | 1390 | ||
1300 | GNUNET_free (peer_ctx->send_channel_flags); | 1391 | if (NULL != peer_ctx->destruction_task) |
1301 | GNUNET_free (peer_ctx->recv_channel_flags); | 1392 | { |
1393 | GNUNET_SCHEDULER_cancel (peer_ctx->destruction_task); | ||
1394 | } | ||
1302 | 1395 | ||
1303 | if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove_all (peer_map, &peer_ctx->peer_id)) | 1396 | if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove_all (peer_map, &peer_ctx->peer_id)) |
1304 | { | 1397 | { |
@@ -1308,7 +1401,6 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1308 | return GNUNET_YES; | 1401 | return GNUNET_YES; |
1309 | } | 1402 | } |
1310 | 1403 | ||
1311 | |||
1312 | /** | 1404 | /** |
1313 | * @brief set flags on a given peer. | 1405 | * @brief set flags on a given peer. |
1314 | * | 1406 | * |
@@ -1364,77 +1456,6 @@ Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl | |||
1364 | return check_peer_flag_set (peer_ctx, flags); | 1456 | return check_peer_flag_set (peer_ctx, flags); |
1365 | } | 1457 | } |
1366 | 1458 | ||
1367 | |||
1368 | /** | ||
1369 | * @brief set flags on a given channel. | ||
1370 | * | ||
1371 | * @param channel the channel to set flags on | ||
1372 | * @param flags the flags | ||
1373 | */ | ||
1374 | void | ||
1375 | Peers_set_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags) | ||
1376 | { | ||
1377 | set_channel_flag (channel_flags, flags); | ||
1378 | } | ||
1379 | |||
1380 | |||
1381 | /** | ||
1382 | * @brief unset flags on a given channel. | ||
1383 | * | ||
1384 | * @param channel the channel to unset flags on | ||
1385 | * @param flags the flags | ||
1386 | */ | ||
1387 | void | ||
1388 | Peers_unset_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags) | ||
1389 | { | ||
1390 | unset_channel_flag (channel_flags, flags); | ||
1391 | } | ||
1392 | |||
1393 | |||
1394 | /** | ||
1395 | * @brief Check whether flags on a channel are set. | ||
1396 | * | ||
1397 | * @param channel the channel to check the flag of | ||
1398 | * @param flags the flags to check | ||
1399 | * | ||
1400 | * @return #GNUNET_YES if all given flags are set | ||
1401 | * #GNUNET_NO otherwise | ||
1402 | */ | ||
1403 | int | ||
1404 | Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags) | ||
1405 | { | ||
1406 | return check_channel_flag_set (channel_flags, flags); | ||
1407 | } | ||
1408 | |||
1409 | /** | ||
1410 | * @brief Get the flags for the channel in @a role for @a peer. | ||
1411 | * | ||
1412 | * @param peer Peer to get the channel flags for. | ||
1413 | * @param role Role of channel to get flags for | ||
1414 | * | ||
1415 | * @return The flags. | ||
1416 | */ | ||
1417 | uint32_t * | ||
1418 | Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer, | ||
1419 | enum Peers_ChannelRole role) | ||
1420 | { | ||
1421 | const struct PeerContext *peer_ctx; | ||
1422 | |||
1423 | peer_ctx = get_peer_ctx (peer); | ||
1424 | if (Peers_CHANNEL_ROLE_SENDING == role) | ||
1425 | { | ||
1426 | return peer_ctx->send_channel_flags; | ||
1427 | } | ||
1428 | else if (Peers_CHANNEL_ROLE_RECEIVING == role) | ||
1429 | { | ||
1430 | return peer_ctx->recv_channel_flags; | ||
1431 | } | ||
1432 | else | ||
1433 | { | ||
1434 | GNUNET_assert (0); | ||
1435 | } | ||
1436 | } | ||
1437 | |||
1438 | /** | 1459 | /** |
1439 | * @brief Check whether we have information about the given peer. | 1460 | * @brief Check whether we have information about the given peer. |
1440 | * | 1461 | * |
@@ -1505,7 +1526,7 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) | |||
1505 | const struct PeerContext *peer_ctx; | 1526 | const struct PeerContext *peer_ctx; |
1506 | 1527 | ||
1507 | peer_ctx = get_peer_ctx (peer); | 1528 | peer_ctx = get_peer_ctx (peer); |
1508 | if (NULL != peer_ctx->recv_channel) | 1529 | if (NULL != peer_ctx->recv_channel_ctx) |
1509 | { | 1530 | { |
1510 | return GNUNET_YES; | 1531 | return GNUNET_YES; |
1511 | } | 1532 | } |
@@ -1530,6 +1551,7 @@ Peers_handle_inbound_channel (void *cls, | |||
1530 | { | 1551 | { |
1531 | struct PeerContext *peer_ctx; | 1552 | struct PeerContext *peer_ctx; |
1532 | struct GNUNET_PeerIdentity *ctx_peer; | 1553 | struct GNUNET_PeerIdentity *ctx_peer; |
1554 | struct ChannelCtx *channel_ctx; | ||
1533 | 1555 | ||
1534 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1556 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1535 | "New channel was established to us (Peer %s).\n", | 1557 | "New channel was established to us (Peer %s).\n", |
@@ -1540,19 +1562,22 @@ Peers_handle_inbound_channel (void *cls, | |||
1540 | set_peer_live (peer_ctx); | 1562 | set_peer_live (peer_ctx); |
1541 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); | 1563 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); |
1542 | *ctx_peer = *initiator; | 1564 | *ctx_peer = *initiator; |
1565 | channel_ctx = add_channel_ctx (peer_ctx); | ||
1566 | channel_ctx->channel = channel; | ||
1543 | /* We only accept one incoming channel per peer */ | 1567 | /* We only accept one incoming channel per peer */ |
1544 | if (GNUNET_YES == Peers_check_peer_send_intention (initiator)) | 1568 | if (GNUNET_YES == Peers_check_peer_send_intention (initiator)) |
1545 | { | 1569 | { |
1546 | set_channel_flag (peer_ctx->recv_channel_flags, | 1570 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1547 | Peers_CHANNEL_ESTABLISHED_TWICE); | 1571 | "Already got one receive channel. Destroying old one.\n"); |
1548 | //GNUNET_CADET_channel_destroy (channel); | 1572 | GNUNET_break_op (0); |
1549 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); | 1573 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel_ctx->channel); |
1550 | peer_ctx->recv_channel = channel; | 1574 | remove_channel_ctx (peer_ctx->recv_channel_ctx); |
1575 | peer_ctx->recv_channel_ctx = channel_ctx; | ||
1551 | /* return the channel context */ | 1576 | /* return the channel context */ |
1552 | return ctx_peer; | 1577 | return channel_ctx; |
1553 | } | 1578 | } |
1554 | peer_ctx->recv_channel = channel; | 1579 | peer_ctx->recv_channel_ctx = channel_ctx; |
1555 | return ctx_peer; | 1580 | return channel_ctx; |
1556 | } | 1581 | } |
1557 | 1582 | ||
1558 | 1583 | ||
@@ -1574,7 +1599,7 @@ Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) | |||
1574 | return GNUNET_NO; | 1599 | return GNUNET_NO; |
1575 | } | 1600 | } |
1576 | peer_ctx = get_peer_ctx (peer); | 1601 | peer_ctx = get_peer_ctx (peer); |
1577 | if (NULL == peer_ctx->send_channel) | 1602 | if (NULL == peer_ctx->send_channel_ctx) |
1578 | { | 1603 | { |
1579 | return GNUNET_NO; | 1604 | return GNUNET_NO; |
1580 | } | 1605 | } |
@@ -1607,12 +1632,14 @@ Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer, | |||
1607 | } | 1632 | } |
1608 | peer_ctx = get_peer_ctx (peer); | 1633 | peer_ctx = get_peer_ctx (peer); |
1609 | if ( (Peers_CHANNEL_ROLE_SENDING == role) && | 1634 | if ( (Peers_CHANNEL_ROLE_SENDING == role) && |
1610 | (channel == peer_ctx->send_channel) ) | 1635 | (NULL != peer_ctx->send_channel_ctx) && |
1636 | (channel == peer_ctx->send_channel_ctx->channel) ) | ||
1611 | { | 1637 | { |
1612 | return GNUNET_YES; | 1638 | return GNUNET_YES; |
1613 | } | 1639 | } |
1614 | if ( (Peers_CHANNEL_ROLE_RECEIVING == role) && | 1640 | if ( (Peers_CHANNEL_ROLE_RECEIVING == role) && |
1615 | (channel == peer_ctx->recv_channel) ) | 1641 | (NULL != peer_ctx->recv_channel_ctx) && |
1642 | (channel == peer_ctx->recv_channel_ctx->channel) ) | ||
1616 | { | 1643 | { |
1617 | return GNUNET_YES; | 1644 | return GNUNET_YES; |
1618 | } | 1645 | } |
@@ -1642,18 +1669,29 @@ Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer) | |||
1642 | return GNUNET_NO; | 1669 | return GNUNET_NO; |
1643 | } | 1670 | } |
1644 | peer_ctx = get_peer_ctx (peer); | 1671 | peer_ctx = get_peer_ctx (peer); |
1645 | if (NULL != peer_ctx->send_channel) | 1672 | if (NULL != peer_ctx->send_channel_ctx) |
1646 | { | 1673 | { |
1647 | set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_CLEAN); | 1674 | schedule_channel_destruction (peer_ctx->send_channel_ctx); |
1648 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); | ||
1649 | peer_ctx->send_channel = NULL; | ||
1650 | peer_ctx->mq = NULL; | ||
1651 | (void) Peers_check_connected (peer); | 1675 | (void) Peers_check_connected (peer); |
1652 | return GNUNET_YES; | 1676 | return GNUNET_YES; |
1653 | } | 1677 | } |
1654 | return GNUNET_NO; | 1678 | return GNUNET_NO; |
1655 | } | 1679 | } |
1656 | 1680 | ||
1681 | static void | ||
1682 | destroy_channel (void *cls) | ||
1683 | { | ||
1684 | struct ChannelCtx *channel_ctx = cls; | ||
1685 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | ||
1686 | |||
1687 | GNUNET_assert (channel_ctx == peer_ctx->send_channel_ctx || | ||
1688 | channel_ctx == peer_ctx->recv_channel_ctx); | ||
1689 | |||
1690 | channel_ctx->destruction_task = NULL; | ||
1691 | GNUNET_CADET_channel_destroy (channel_ctx->channel); | ||
1692 | remove_channel_ctx (peer_ctx->send_channel_ctx); | ||
1693 | } | ||
1694 | |||
1657 | /** | 1695 | /** |
1658 | * This is called when a channel is destroyed. | 1696 | * This is called when a channel is destroyed. |
1659 | * | 1697 | * |
@@ -1664,9 +1702,9 @@ void | |||
1664 | Peers_cleanup_destroyed_channel (void *cls, | 1702 | Peers_cleanup_destroyed_channel (void *cls, |
1665 | const struct GNUNET_CADET_Channel *channel) | 1703 | const struct GNUNET_CADET_Channel *channel) |
1666 | { | 1704 | { |
1667 | struct GNUNET_PeerIdentity *peer = cls; | 1705 | struct ChannelCtx *channel_ctx = cls; |
1668 | struct PeerContext *peer_ctx; | 1706 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; |
1669 | uint32_t *channel_flag; | 1707 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
1670 | 1708 | ||
1671 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 1709 | if (GNUNET_NO == Peers_check_peer_known (peer)) |
1672 | {/* We don't want to implicitly create a context that we're about to kill */ | 1710 | {/* We don't want to implicitly create a context that we're about to kill */ |
@@ -1675,71 +1713,34 @@ Peers_cleanup_destroyed_channel (void *cls, | |||
1675 | GNUNET_i2s (peer)); | 1713 | GNUNET_i2s (peer)); |
1676 | return; | 1714 | return; |
1677 | } | 1715 | } |
1678 | peer_ctx = get_peer_ctx (peer); | ||
1679 | 1716 | ||
1680 | /* If our peer issued the destruction of the channel, the #Peers_TO_DESTROY | 1717 | /* If our peer issued the destruction of the channel, the #Peers_TO_DESTROY |
1681 | * flag will be set. In this case simply make sure that the channels are | 1718 | * flag will be set. In this case simply make sure that the channels are |
1682 | * cleaned. */ | 1719 | * cleaned. */ |
1683 | /* FIXME This distinction seems to be redundant */ | 1720 | /* The distinction seems to be redundant */ |
1684 | if (Peers_check_peer_flag (peer, Peers_TO_DESTROY)) | 1721 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1685 | {/* We initiatad the destruction of this particular peer */ | 1722 | "Peer is NOT in the process of being destroyed\n"); |
1723 | if ( (NULL != peer_ctx->send_channel_ctx) && | ||
1724 | (channel == peer_ctx->send_channel_ctx->channel) ) | ||
1725 | { /* Something (but us) killd the channel - clean up peer */ | ||
1686 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1726 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1687 | "Peer is in the process of being destroyed\n"); | 1727 | "send channel (%s) was destroyed - cleaning up\n", |
1688 | if (channel == peer_ctx->send_channel) | 1728 | GNUNET_i2s (peer)); |
1689 | { | 1729 | remove_channel_ctx (peer_ctx->send_channel_ctx); |
1690 | peer_ctx->send_channel = NULL; | ||
1691 | peer_ctx->mq = NULL; | ||
1692 | } | ||
1693 | else if (channel == peer_ctx->recv_channel) | ||
1694 | { | ||
1695 | peer_ctx->recv_channel = NULL; | ||
1696 | } | ||
1697 | |||
1698 | if (NULL != peer_ctx->send_channel) | ||
1699 | { | ||
1700 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); | ||
1701 | channel_flag = Peers_get_channel_flag (&peer_ctx->peer_id, Peers_CHANNEL_ROLE_SENDING); | ||
1702 | Peers_set_channel_flag (channel_flag, Peers_CHANNEL_DESTROING); | ||
1703 | peer_ctx->send_channel = NULL; | ||
1704 | peer_ctx->mq = NULL; | ||
1705 | } | ||
1706 | if (NULL != peer_ctx->recv_channel) | ||
1707 | { | ||
1708 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); | ||
1709 | channel_flag = Peers_get_channel_flag (&peer_ctx->peer_id, Peers_CHANNEL_ROLE_RECEIVING); | ||
1710 | Peers_set_channel_flag (channel_flag, Peers_CHANNEL_DESTROING); | ||
1711 | peer_ctx->recv_channel = NULL; | ||
1712 | } | ||
1713 | /* Set the #Peers_ONLINE flag accordingly */ | ||
1714 | (void) Peers_check_connected (peer); | ||
1715 | return; | ||
1716 | } | 1730 | } |
1717 | 1731 | else if ( (NULL != peer_ctx->recv_channel_ctx) && | |
1718 | else | 1732 | (channel == peer_ctx->recv_channel_ctx->channel) ) |
1719 | { /* We did not initiate the destruction of this peer */ | 1733 | { /* Other peer doesn't want to send us messages anymore */ |
1720 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1734 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1721 | "Peer is NOT in the process of being destroyed\n"); | 1735 | "Peer %s destroyed recv channel - cleaning up channel\n", |
1722 | if (channel == peer_ctx->send_channel) | 1736 | GNUNET_i2s (peer)); |
1723 | { /* Something (but us) killd the channel - clean up peer */ | 1737 | remove_channel_ctx (peer_ctx->send_channel_ctx); |
1724 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1738 | } |
1725 | "send channel (%s) was destroyed - cleaning up\n", | 1739 | else |
1726 | GNUNET_i2s (peer)); | 1740 | { |
1727 | peer_ctx->send_channel = NULL; | 1741 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1728 | peer_ctx->mq = NULL; | 1742 | "unknown channel (%s) was destroyed\n", |
1729 | } | 1743 | GNUNET_i2s (peer)); |
1730 | else if (channel == peer_ctx->recv_channel) | ||
1731 | { /* Other peer doesn't want to send us messages anymore */ | ||
1732 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1733 | "Peer %s destroyed recv channel - cleaning up channel\n", | ||
1734 | GNUNET_i2s (peer)); | ||
1735 | peer_ctx->recv_channel = NULL; | ||
1736 | } | ||
1737 | else | ||
1738 | { | ||
1739 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1740 | "unknown channel (%s) was destroyed\n", | ||
1741 | GNUNET_i2s (peer)); | ||
1742 | } | ||
1743 | } | 1744 | } |
1744 | (void) Peers_check_connected (peer); | 1745 | (void) Peers_check_connected (peer); |
1745 | } | 1746 | } |
@@ -1791,10 +1792,6 @@ Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer, | |||
1791 | struct PeerPendingOp pending_op; | 1792 | struct PeerPendingOp pending_op; |
1792 | struct PeerContext *peer_ctx; | 1793 | struct PeerContext *peer_ctx; |
1793 | 1794 | ||
1794 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) | ||
1795 | { | ||
1796 | return GNUNET_NO; | ||
1797 | } | ||
1798 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | 1795 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); |
1799 | 1796 | ||
1800 | //TODO if LIVE/ONLINE execute immediately | 1797 | //TODO if LIVE/ONLINE execute immediately |
@@ -1828,7 +1825,7 @@ Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer) | |||
1828 | 1825 | ||
1829 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | 1826 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); |
1830 | peer_ctx = get_peer_ctx (peer); | 1827 | peer_ctx = get_peer_ctx (peer); |
1831 | return peer_ctx->recv_channel; | 1828 | return peer_ctx->recv_channel_ctx->channel; |
1832 | } | 1829 | } |
1833 | /*********************************************************************** | 1830 | /*********************************************************************** |
1834 | * /Old gnunet-service-rps_peers.c | 1831 | * /Old gnunet-service-rps_peers.c |
@@ -2489,6 +2486,9 @@ send_pull_reply (const struct GNUNET_PeerIdentity *peer_id, | |||
2489 | 2486 | ||
2490 | Peers_send_message (peer_id, ev, "PULL REPLY"); | 2487 | Peers_send_message (peer_id, ev, "PULL REPLY"); |
2491 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); | 2488 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); |
2489 | // TODO check with send intention: as send_channel is used/opened we indicate | ||
2490 | // a sending intention without intending it. | ||
2491 | // -> clean peer afterwards? | ||
2492 | } | 2492 | } |
2493 | 2493 | ||
2494 | 2494 | ||
@@ -2621,7 +2621,7 @@ remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
2621 | CustomPeerMap_remove_peer (push_map, peer); | 2621 | CustomPeerMap_remove_peer (push_map, peer); |
2622 | RPS_sampler_reinitialise_by_value (prot_sampler, peer); | 2622 | RPS_sampler_reinitialise_by_value (prot_sampler, peer); |
2623 | RPS_sampler_reinitialise_by_value (client_sampler, peer); | 2623 | RPS_sampler_reinitialise_by_value (client_sampler, peer); |
2624 | Peers_remove_peer (peer); | 2624 | schedule_peer_destruction (get_peer_ctx (peer)); |
2625 | } | 2625 | } |
2626 | 2626 | ||
2627 | 2627 | ||
@@ -2665,6 +2665,58 @@ clean_peer (const struct GNUNET_PeerIdentity *peer) | |||
2665 | } | 2665 | } |
2666 | 2666 | ||
2667 | /** | 2667 | /** |
2668 | * @brief Allocate memory for a new channel context and insert it into DLL | ||
2669 | * | ||
2670 | * @param peer_ctx context of the according peer | ||
2671 | * | ||
2672 | * @return The channel context | ||
2673 | */ | ||
2674 | static struct ChannelCtx * | ||
2675 | add_channel_ctx (struct PeerContext *peer_ctx) | ||
2676 | { | ||
2677 | struct ChannelCtx *channel_ctx; | ||
2678 | channel_ctx = GNUNET_new (struct ChannelCtx); | ||
2679 | channel_ctx->peer_ctx = peer_ctx; | ||
2680 | return channel_ctx; | ||
2681 | } | ||
2682 | |||
2683 | /** | ||
2684 | * @brief Remove the channel context from the DLL and free the memory. | ||
2685 | * | ||
2686 | * @param channel_ctx The channel context. | ||
2687 | */ | ||
2688 | static void | ||
2689 | remove_channel_ctx (struct ChannelCtx *channel_ctx) | ||
2690 | { | ||
2691 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | ||
2692 | if (NULL != channel_ctx->destruction_task) | ||
2693 | { | ||
2694 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); | ||
2695 | } | ||
2696 | GNUNET_free (channel_ctx); | ||
2697 | |||
2698 | if (channel_ctx == peer_ctx->send_channel_ctx) | ||
2699 | { | ||
2700 | peer_ctx->send_channel_ctx = NULL; | ||
2701 | peer_ctx->mq = NULL; | ||
2702 | } | ||
2703 | else if (channel_ctx == peer_ctx->recv_channel_ctx) | ||
2704 | { | ||
2705 | peer_ctx->recv_channel_ctx = NULL; | ||
2706 | } | ||
2707 | else | ||
2708 | { | ||
2709 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2710 | "Trying to remove channel_ctx that is not associated with a peer\n"); | ||
2711 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2712 | "\trecv: %p\n", peer_ctx->recv_channel_ctx); | ||
2713 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2714 | "\tsend: %p\n", peer_ctx->send_channel_ctx); | ||
2715 | GNUNET_assert (0); | ||
2716 | } | ||
2717 | } | ||
2718 | |||
2719 | /** | ||
2668 | * @brief This is called when a channel is destroyed. | 2720 | * @brief This is called when a channel is destroyed. |
2669 | * | 2721 | * |
2670 | * Removes peer completely from our knowledge if the send_channel was destroyed | 2722 | * Removes peer completely from our knowledge if the send_channel was destroyed |
@@ -2680,8 +2732,8 @@ static void | |||
2680 | cleanup_destroyed_channel (void *cls, | 2732 | cleanup_destroyed_channel (void *cls, |
2681 | const struct GNUNET_CADET_Channel *channel) | 2733 | const struct GNUNET_CADET_Channel *channel) |
2682 | { | 2734 | { |
2683 | struct GNUNET_PeerIdentity *peer = cls; | 2735 | struct ChannelCtx *channel_ctx = cls; |
2684 | uint32_t *channel_flag; | 2736 | struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; |
2685 | struct PeerContext *peer_ctx; | 2737 | struct PeerContext *peer_ctx; |
2686 | 2738 | ||
2687 | GNUNET_assert (NULL != peer); | 2739 | GNUNET_assert (NULL != peer); |
@@ -2691,94 +2743,26 @@ cleanup_destroyed_channel (void *cls, | |||
2691 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2743 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2692 | "channel (%s) without associated context was destroyed\n", | 2744 | "channel (%s) without associated context was destroyed\n", |
2693 | GNUNET_i2s (peer)); | 2745 | GNUNET_i2s (peer)); |
2694 | GNUNET_free (peer); | 2746 | remove_channel_ctx (channel_ctx); |
2695 | return; | 2747 | return; |
2696 | } | 2748 | } |
2697 | 2749 | ||
2698 | peer_ctx = get_peer_ctx (peer); | 2750 | peer_ctx = get_peer_ctx (peer); |
2699 | if (GNUNET_YES == Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_RECEIVING)) | ||
2700 | { | ||
2701 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2702 | "Callback on destruction of recv-channel was called (%s)\n", | ||
2703 | GNUNET_i2s (peer)); | ||
2704 | set_channel_flag (peer_ctx->recv_channel_flags, Peers_CHANNEL_DESTROING); | ||
2705 | } else if (GNUNET_YES == Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_SENDING)) | ||
2706 | { | ||
2707 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2708 | "Callback on destruction of send-channel was called (%s)\n", | ||
2709 | GNUNET_i2s (peer)); | ||
2710 | set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_DESTROING); | ||
2711 | } else { | ||
2712 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2713 | "Channel to be destroyed has is neither sending nor receiving role\n"); | ||
2714 | } | ||
2715 | 2751 | ||
2716 | if (GNUNET_YES == Peers_check_peer_flag (peer, Peers_TO_DESTROY)) | 2752 | // What should be done here: |
2717 | { /* We are in the middle of removing that peer from our knowledge. In this | 2753 | // * cleanup everything related to the channel |
2718 | case simply make sure that the channels are cleaned. */ | 2754 | // * memory |
2719 | Peers_cleanup_destroyed_channel (cls, channel); | 2755 | // * remove peer if necessary |
2720 | to_file (file_name_view_log, | ||
2721 | "-%s\t(cleanup channel, ourself)", | ||
2722 | GNUNET_i2s_full (peer)); | ||
2723 | GNUNET_free (peer); | ||
2724 | return; | ||
2725 | } | ||
2726 | 2756 | ||
2727 | if (GNUNET_YES == | 2757 | if (peer_ctx->recv_channel_ctx == channel_ctx) |
2728 | Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_SENDING)) | 2758 | { |
2729 | { /* Channel used for sending was destroyed */ | 2759 | remove_channel_ctx (channel_ctx); |
2730 | /* Possible causes of channel destruction: | ||
2731 | * - ourselves -> cleaning send channel -> clean context | ||
2732 | * - other peer -> peer probably went down -> remove | ||
2733 | */ | ||
2734 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING); | ||
2735 | if (GNUNET_YES == Peers_check_channel_flag (channel_flag, Peers_CHANNEL_CLEAN)) | ||
2736 | { /* We are about to clean the sending channel. Clean the respective | ||
2737 | * context */ | ||
2738 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2739 | GNUNET_free (peer); | ||
2740 | return; | ||
2741 | } | ||
2742 | else | ||
2743 | { /* Other peer destroyed our sending channel that it is supposed to keep | ||
2744 | * open. It probably went down. Remove it from our knowledge. */ | ||
2745 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2746 | remove_peer (peer); | ||
2747 | GNUNET_free (peer); | ||
2748 | return; | ||
2749 | } | ||
2750 | } | ||
2751 | else if (GNUNET_YES == | ||
2752 | Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_RECEIVING)) | ||
2753 | { /* Channel used for receiving was destroyed */ | ||
2754 | /* Possible causes of channel destruction: | ||
2755 | * - ourselves -> peer tried to establish channel twice -> clean context | ||
2756 | * - other peer -> peer doesn't want to send us data -> clean | ||
2757 | */ | ||
2758 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_RECEIVING); | ||
2759 | if (GNUNET_YES == | ||
2760 | Peers_check_channel_flag (channel_flag, Peers_CHANNEL_ESTABLISHED_TWICE)) | ||
2761 | { /* Other peer tried to establish a channel to us twice. We do not accept | ||
2762 | * that. Clean the context. */ | ||
2763 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2764 | GNUNET_free (peer); | ||
2765 | return; | ||
2766 | } | ||
2767 | else | ||
2768 | { /* Other peer doesn't want to send us data anymore. We are free to clean | ||
2769 | * it. */ | ||
2770 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2771 | clean_peer (peer); | ||
2772 | GNUNET_free (peer); | ||
2773 | return; | ||
2774 | } | ||
2775 | } | 2760 | } |
2776 | else | 2761 | else if (peer_ctx->send_channel_ctx == channel_ctx) |
2777 | { | 2762 | { |
2778 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2763 | remove_channel_ctx (channel_ctx); |
2779 | "Destroyed channel is neither sending nor receiving channel\n"); | 2764 | remove_peer (&peer_ctx->peer_id); |
2780 | } | 2765 | } |
2781 | GNUNET_free (peer); | ||
2782 | } | 2766 | } |
2783 | 2767 | ||
2784 | /*********************************************************************** | 2768 | /*********************************************************************** |
@@ -3037,8 +3021,6 @@ handle_client_seed (void *cls, | |||
3037 | 3021 | ||
3038 | num_peers = ntohl (msg->num_peers); | 3022 | num_peers = ntohl (msg->num_peers); |
3039 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 3023 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
3040 | //peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | ||
3041 | //GNUNET_memcpy (peers, &msg[1], num_peers * sizeof (struct GNUNET_PeerIdentity)); | ||
3042 | 3024 | ||
3043 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3025 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3044 | "Client seeded peers:\n"); | 3026 | "Client seeded peers:\n"); |
@@ -3053,9 +3035,6 @@ handle_client_seed (void *cls, | |||
3053 | 3035 | ||
3054 | got_peer (&peers[i]); | 3036 | got_peer (&peers[i]); |
3055 | } | 3037 | } |
3056 | |||
3057 | ////GNUNET_free (peers); | ||
3058 | |||
3059 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 3038 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
3060 | } | 3039 | } |
3061 | 3040 | ||
@@ -3173,11 +3152,12 @@ static void | |||
3173 | handle_peer_check (void *cls, | 3152 | handle_peer_check (void *cls, |
3174 | const struct GNUNET_MessageHeader *msg) | 3153 | const struct GNUNET_MessageHeader *msg) |
3175 | { | 3154 | { |
3176 | const struct GNUNET_PeerIdentity *peer = cls; | 3155 | const struct ChannelCtx *channel_ctx = cls; |
3156 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | ||
3177 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3157 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3178 | "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); | 3158 | "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); |
3179 | 3159 | ||
3180 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); | 3160 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3181 | } | 3161 | } |
3182 | 3162 | ||
3183 | /** | 3163 | /** |
@@ -3193,7 +3173,8 @@ static void | |||
3193 | handle_peer_push (void *cls, | 3173 | handle_peer_push (void *cls, |
3194 | const struct GNUNET_MessageHeader *msg) | 3174 | const struct GNUNET_MessageHeader *msg) |
3195 | { | 3175 | { |
3196 | const struct GNUNET_PeerIdentity *peer = cls; | 3176 | const struct ChannelCtx *channel_ctx = cls; |
3177 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | ||
3197 | 3178 | ||
3198 | // (check the proof of work (?)) | 3179 | // (check the proof of work (?)) |
3199 | 3180 | ||
@@ -3238,7 +3219,7 @@ handle_peer_push (void *cls, | |||
3238 | CustomPeerMap_put (push_map, peer); | 3219 | CustomPeerMap_put (push_map, peer); |
3239 | 3220 | ||
3240 | GNUNET_break_op (Peers_check_peer_known (peer)); | 3221 | GNUNET_break_op (Peers_check_peer_known (peer)); |
3241 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); | 3222 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3242 | } | 3223 | } |
3243 | 3224 | ||
3244 | 3225 | ||
@@ -3254,7 +3235,8 @@ static void | |||
3254 | handle_peer_pull_request (void *cls, | 3235 | handle_peer_pull_request (void *cls, |
3255 | const struct GNUNET_MessageHeader *msg) | 3236 | const struct GNUNET_MessageHeader *msg) |
3256 | { | 3237 | { |
3257 | struct GNUNET_PeerIdentity *peer = cls; | 3238 | const struct ChannelCtx *channel_ctx = cls; |
3239 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | ||
3258 | const struct GNUNET_PeerIdentity *view_array; | 3240 | const struct GNUNET_PeerIdentity *view_array; |
3259 | 3241 | ||
3260 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); | 3242 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); |
@@ -3277,7 +3259,7 @@ handle_peer_pull_request (void *cls, | |||
3277 | #endif /* ENABLE_MALICIOUS */ | 3259 | #endif /* ENABLE_MALICIOUS */ |
3278 | 3260 | ||
3279 | GNUNET_break_op (Peers_check_peer_known (peer)); | 3261 | GNUNET_break_op (Peers_check_peer_known (peer)); |
3280 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); | 3262 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3281 | view_array = View_get_as_array (); | 3263 | view_array = View_get_as_array (); |
3282 | send_pull_reply (peer, view_array, View_size ()); | 3264 | send_pull_reply (peer, view_array, View_size ()); |
3283 | } | 3265 | } |
@@ -3317,7 +3299,8 @@ check_peer_pull_reply (void *cls, | |||
3317 | if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) | 3299 | if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) |
3318 | { | 3300 | { |
3319 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3301 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3320 | "Received a pull reply from a peer we didn't request one from!\n"); | 3302 | "Received a pull reply from a peer (%s) we didn't request one from!\n", |
3303 | GNUNET_i2s (sender)); | ||
3321 | GNUNET_break_op (0); | 3304 | GNUNET_break_op (0); |
3322 | return GNUNET_SYSERR; | 3305 | return GNUNET_SYSERR; |
3323 | } | 3306 | } |
@@ -3334,8 +3317,9 @@ static void | |||
3334 | handle_peer_pull_reply (void *cls, | 3317 | handle_peer_pull_reply (void *cls, |
3335 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) | 3318 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) |
3336 | { | 3319 | { |
3320 | const struct ChannelCtx *channel_ctx = cls; | ||
3321 | const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id; | ||
3337 | const struct GNUNET_PeerIdentity *peers; | 3322 | const struct GNUNET_PeerIdentity *peers; |
3338 | struct GNUNET_PeerIdentity *sender = cls; | ||
3339 | uint32_t i; | 3323 | uint32_t i; |
3340 | #ifdef ENABLE_MALICIOUS | 3324 | #ifdef ENABLE_MALICIOUS |
3341 | struct AttackedPeer *tmp_att_peer; | 3325 | struct AttackedPeer *tmp_att_peer; |
@@ -3373,9 +3357,7 @@ handle_peer_pull_reply (void *cls, | |||
3373 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, | 3357 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, |
3374 | &peers[i]) | 3358 | &peers[i]) |
3375 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, | 3359 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, |
3376 | &peers[i]) | 3360 | &peers[i])) |
3377 | && 0 != GNUNET_CRYPTO_cmp_peer_identity (&peers[i], | ||
3378 | &own_identity)) | ||
3379 | { | 3361 | { |
3380 | tmp_att_peer = GNUNET_new (struct AttackedPeer); | 3362 | tmp_att_peer = GNUNET_new (struct AttackedPeer); |
3381 | tmp_att_peer->peer_id = peers[i]; | 3363 | tmp_att_peer->peer_id = peers[i]; |
@@ -3387,21 +3369,17 @@ handle_peer_pull_reply (void *cls, | |||
3387 | continue; | 3369 | continue; |
3388 | } | 3370 | } |
3389 | #endif /* ENABLE_MALICIOUS */ | 3371 | #endif /* ENABLE_MALICIOUS */ |
3390 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, | 3372 | /* Make sure we 'know' about this peer */ |
3391 | &peers[i])) | 3373 | (void) Peers_insert_peer (&peers[i]); |
3392 | { | ||
3393 | /* Make sure we 'know' about this peer */ | ||
3394 | (void) Peers_insert_peer (&peers[i]); | ||
3395 | 3374 | ||
3396 | if (GNUNET_YES == Peers_check_peer_valid (&peers[i])) | 3375 | if (GNUNET_YES == Peers_check_peer_valid (&peers[i])) |
3397 | { | 3376 | { |
3398 | CustomPeerMap_put (pull_map, &peers[i]); | 3377 | CustomPeerMap_put (pull_map, &peers[i]); |
3399 | } | 3378 | } |
3400 | else | 3379 | else |
3401 | { | 3380 | { |
3402 | Peers_schedule_operation (&peers[i], insert_in_pull_map); | 3381 | Peers_schedule_operation (&peers[i], insert_in_pull_map); |
3403 | (void) Peers_issue_peer_liveliness_check (&peers[i]); | 3382 | (void) Peers_issue_peer_liveliness_check (&peers[i]); |
3404 | } | ||
3405 | } | 3383 | } |
3406 | } | 3384 | } |
3407 | 3385 | ||
@@ -3409,7 +3387,7 @@ handle_peer_pull_reply (void *cls, | |||
3409 | clean_peer (sender); | 3387 | clean_peer (sender); |
3410 | 3388 | ||
3411 | GNUNET_break_op (Peers_check_peer_known (sender)); | 3389 | GNUNET_break_op (Peers_check_peer_known (sender)); |
3412 | GNUNET_CADET_receive_done (Peers_get_recv_channel (sender)); | 3390 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3413 | } | 3391 | } |
3414 | 3392 | ||
3415 | 3393 | ||
@@ -3836,10 +3814,8 @@ do_round (void *cls) | |||
3836 | for (i = 0; i < a_peers; i++) | 3814 | for (i = 0; i < a_peers; i++) |
3837 | { | 3815 | { |
3838 | peer = view_array[permut[i]]; | 3816 | peer = view_array[permut[i]]; |
3839 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) // TODO | 3817 | // FIXME if this fails schedule/loop this for later |
3840 | { // FIXME if this fails schedule/loop this for later | 3818 | send_push (&peer); |
3841 | send_push (&peer); | ||
3842 | } | ||
3843 | } | 3819 | } |
3844 | 3820 | ||
3845 | /* Send PULL requests */ | 3821 | /* Send PULL requests */ |
@@ -3857,8 +3833,7 @@ do_round (void *cls) | |||
3857 | for (i = first_border; i < second_border; i++) | 3833 | for (i = first_border; i < second_border; i++) |
3858 | { | 3834 | { |
3859 | peer = view_array[permut[i]]; | 3835 | peer = view_array[permut[i]]; |
3860 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer) && | 3836 | if ( GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) |
3861 | GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) // TODO | ||
3862 | { // FIXME if this fails schedule/loop this for later | 3837 | { // FIXME if this fails schedule/loop this for later |
3863 | send_pull_request (&peer); | 3838 | send_pull_request (&peer); |
3864 | } | 3839 | } |
@@ -3955,7 +3930,6 @@ do_round (void *cls) | |||
3955 | "-%s", | 3930 | "-%s", |
3956 | GNUNET_i2s_full (&peers_to_clean[i])); | 3931 | GNUNET_i2s_full (&peers_to_clean[i])); |
3957 | clean_peer (&peers_to_clean[i]); | 3932 | clean_peer (&peers_to_clean[i]); |
3958 | //peer_destroy_channel_send (sender); | ||
3959 | } | 3933 | } |
3960 | 3934 | ||
3961 | GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0); | 3935 | GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0); |
@@ -4011,7 +3985,6 @@ do_round (void *cls) | |||
4011 | GNUNET_i2s (update_peer)); | 3985 | GNUNET_i2s (update_peer)); |
4012 | insert_in_sampler (NULL, update_peer); | 3986 | insert_in_sampler (NULL, update_peer); |
4013 | clean_peer (update_peer); /* This cleans only if it is not in the view */ | 3987 | clean_peer (update_peer); /* This cleans only if it is not in the view */ |
4014 | //peer_destroy_channel_send (sender); | ||
4015 | } | 3988 | } |
4016 | 3989 | ||
4017 | for (i = 0; i < CustomPeerMap_size (pull_map); i++) | 3990 | for (i = 0; i < CustomPeerMap_size (pull_map); i++) |
@@ -4022,7 +3995,6 @@ do_round (void *cls) | |||
4022 | insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i)); | 3995 | insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i)); |
4023 | /* This cleans only if it is not in the view */ | 3996 | /* This cleans only if it is not in the view */ |
4024 | clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i)); | 3997 | clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i)); |
4025 | //peer_destroy_channel_send (sender); | ||
4026 | } | 3998 | } |
4027 | 3999 | ||
4028 | 4000 | ||
@@ -4125,6 +4097,8 @@ shutdown_task (void *cls) | |||
4125 | struct ClientContext *client_ctx; | 4097 | struct ClientContext *client_ctx; |
4126 | struct ReplyCls *reply_cls; | 4098 | struct ReplyCls *reply_cls; |
4127 | 4099 | ||
4100 | in_shutdown = GNUNET_YES; | ||
4101 | |||
4128 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4102 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4129 | "RPS is going down\n"); | 4103 | "RPS is going down\n"); |
4130 | 4104 | ||
@@ -4369,10 +4343,17 @@ run (void *cls, | |||
4369 | NULL, /* WindowSize handler */ | 4343 | NULL, /* WindowSize handler */ |
4370 | cleanup_destroyed_channel, /* Disconnect handler */ | 4344 | cleanup_destroyed_channel, /* Disconnect handler */ |
4371 | cadet_handlers); | 4345 | cadet_handlers); |
4346 | if (NULL == cadet_port) | ||
4347 | { | ||
4348 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
4349 | "Cadet port `%s' is already in use.\n", | ||
4350 | GNUNET_APPLICATION_PORT_RPS); | ||
4351 | GNUNET_assert (0); | ||
4352 | } | ||
4372 | 4353 | ||
4373 | 4354 | ||
4374 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | 4355 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); |
4375 | Peers_initialise (fn_valid_peers, cadet_handle, &own_identity); | 4356 | Peers_initialise (fn_valid_peers, cadet_handle); |
4376 | GNUNET_free (fn_valid_peers); | 4357 | GNUNET_free (fn_valid_peers); |
4377 | 4358 | ||
4378 | /* Initialise sampler */ | 4359 | /* Initialise sampler */ |
diff --git a/src/rps/gnunet-service-rps_custommap.c b/src/rps/gnunet-service-rps_custommap.c index 42507655b..9e003eb39 100644 --- a/src/rps/gnunet-service-rps_custommap.c +++ b/src/rps/gnunet-service-rps_custommap.c | |||
@@ -213,7 +213,7 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, | |||
213 | GNUNET_assert (NULL != last_index); | 213 | GNUNET_assert (NULL != last_index); |
214 | GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index); | 214 | GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index); |
215 | GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, *index, last_p, | 215 | GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, *index, last_p, |
216 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 216 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
217 | GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *last_index); | 217 | GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *last_index); |
218 | *last_index = *index; | 218 | *last_index = *index; |
219 | } | 219 | } |
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index d47e4952f..08fe96097 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c | |||
@@ -31,6 +31,17 @@ | |||
31 | 31 | ||
32 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-test_util",__VA_ARGS__) | 32 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-test_util",__VA_ARGS__) |
33 | 33 | ||
34 | #define B2B_PAT "%c%c%c%c%c%c%c%c" | ||
35 | #define B2B(byte) \ | ||
36 | (byte & 0x80 ? '1' : '0'), \ | ||
37 | (byte & 0x40 ? '1' : '0'), \ | ||
38 | (byte & 0x20 ? '1' : '0'), \ | ||
39 | (byte & 0x10 ? '1' : '0'), \ | ||
40 | (byte & 0x08 ? '1' : '0'), \ | ||
41 | (byte & 0x04 ? '1' : '0'), \ | ||
42 | (byte & 0x02 ? '1' : '0'), \ | ||
43 | (byte & 0x01 ? '1' : '0') | ||
44 | |||
34 | #ifndef TO_FILE | 45 | #ifndef TO_FILE |
35 | #define TO_FILE | 46 | #define TO_FILE |
36 | #endif /* TO_FILE */ | 47 | #endif /* TO_FILE */ |
@@ -155,6 +166,9 @@ to_file_raw (const char *file_name, const char *buf, size_t size_buf) | |||
155 | 166 | ||
156 | return; | 167 | return; |
157 | } | 168 | } |
169 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
170 | "Wrote %u bytes raw.\n", | ||
171 | size_written); | ||
158 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | 172 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) |
159 | LOG (GNUNET_ERROR_TYPE_WARNING, | 173 | LOG (GNUNET_ERROR_TYPE_WARNING, |
160 | "Unable to close file\n"); | 174 | "Unable to close file\n"); |
@@ -180,6 +194,8 @@ to_file_raw_unaligned (const char *file_name, | |||
180 | // num_bits_buf_unaligned = bits_needed % 8; | 194 | // num_bits_buf_unaligned = bits_needed % 8; |
181 | // return; | 195 | // return; |
182 | //} | 196 | //} |
197 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
198 | "Was asked to write %u bits\n", bits_needed); | ||
183 | 199 | ||
184 | char buf_write[size_buf + 1]; | 200 | char buf_write[size_buf + 1]; |
185 | const unsigned bytes_iter = (0 != bits_needed % 8? | 201 | const unsigned bytes_iter = (0 != bits_needed % 8? |
@@ -187,6 +203,14 @@ to_file_raw_unaligned (const char *file_name, | |||
187 | bits_needed/8); | 203 | bits_needed/8); |
188 | // TODO what if no iteration happens? | 204 | // TODO what if no iteration happens? |
189 | unsigned size_buf_write = 0; | 205 | unsigned size_buf_write = 0; |
206 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
207 | "num_bits_buf_unaligned: %u\n", | ||
208 | num_bits_buf_unaligned); | ||
209 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
210 | "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n", | ||
211 | size_buf, | ||
212 | bits_needed, | ||
213 | bytes_iter); | ||
190 | buf_write[0] = buf_unaligned; | 214 | buf_write[0] = buf_unaligned; |
191 | /* Iterate over input bytes */ | 215 | /* Iterate over input bytes */ |
192 | for (unsigned i = 0; i < bytes_iter; i++) | 216 | for (unsigned i = 0; i < bytes_iter; i++) |
@@ -227,17 +251,57 @@ to_file_raw_unaligned (const char *file_name, | |||
227 | { | 251 | { |
228 | num_bits_needed_iter = 8; | 252 | num_bits_needed_iter = 8; |
229 | } | 253 | } |
254 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
255 | "number of bits needed in this iteration: %u\n", | ||
256 | num_bits_needed_iter); | ||
230 | mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1; | 257 | mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1; |
258 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
259 | "mask needed bits (current iter): "B2B_PAT"\n", | ||
260 | B2B(mask_bits_needed_iter)); | ||
261 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
262 | "Unaligned byte: "B2B_PAT" (%u bits)\n", | ||
263 | B2B(buf_unaligned), | ||
264 | num_bits_buf_unaligned); | ||
231 | byte_input = buf[i]; | 265 | byte_input = buf[i]; |
266 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
267 | "next whole input byte: "B2B_PAT"\n", | ||
268 | B2B(byte_input)); | ||
232 | byte_input &= mask_bits_needed_iter; | 269 | byte_input &= mask_bits_needed_iter; |
233 | num_bits_to_align = 8 - num_bits_buf_unaligned; | 270 | num_bits_to_align = 8 - num_bits_buf_unaligned; |
271 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
272 | "input byte, needed bits: "B2B_PAT"\n", | ||
273 | B2B(byte_input)); | ||
274 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
275 | "number of bits needed to align unaligned bit: %u\n", | ||
276 | num_bits_to_align); | ||
234 | num_bits_to_move = min (num_bits_to_align, num_bits_needed_iter); | 277 | num_bits_to_move = min (num_bits_to_align, num_bits_needed_iter); |
278 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
279 | "number of bits of new byte to move: %u\n", | ||
280 | num_bits_to_move); | ||
235 | mask_input_to_move = ((char) 1 << num_bits_to_move) - 1; | 281 | mask_input_to_move = ((char) 1 << num_bits_to_move) - 1; |
282 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
283 | "mask of bits of new byte to take for moving: "B2B_PAT"\n", | ||
284 | B2B(mask_input_to_move)); | ||
236 | bits_to_move = byte_input & mask_input_to_move; | 285 | bits_to_move = byte_input & mask_input_to_move; |
286 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
287 | "masked bits of new byte to take for moving: "B2B_PAT"\n", | ||
288 | B2B(bits_to_move)); | ||
237 | distance_shift_bits = num_bits_buf_unaligned; | 289 | distance_shift_bits = num_bits_buf_unaligned; |
290 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
291 | "distance needed to shift bits to their correct spot: %u\n", | ||
292 | distance_shift_bits); | ||
238 | bits_moving = bits_to_move << distance_shift_bits; | 293 | bits_moving = bits_to_move << distance_shift_bits; |
294 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
295 | "shifted, masked bits of new byte being moved: "B2B_PAT"\n", | ||
296 | B2B(bits_moving)); | ||
239 | byte_to_fill = buf_unaligned | bits_moving; | 297 | byte_to_fill = buf_unaligned | bits_moving; |
240 | if (num_bits_buf_unaligned + num_bits_needed_iter > 8) | 298 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
299 | "byte being filled: "B2B_PAT"\n", | ||
300 | B2B(byte_to_fill)); | ||
301 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
302 | "pending bytes: %u\n", | ||
303 | num_bits_buf_unaligned + num_bits_needed_iter); | ||
304 | if (num_bits_buf_unaligned + num_bits_needed_iter >= 8) | ||
241 | { | 305 | { |
242 | /* buf_unaligned was aligned by filling | 306 | /* buf_unaligned was aligned by filling |
243 | * -> can be written to storage */ | 307 | * -> can be written to storage */ |
@@ -246,10 +310,22 @@ to_file_raw_unaligned (const char *file_name, | |||
246 | 310 | ||
247 | /* store the leftover, unaligned bits in buffer */ | 311 | /* store the leftover, unaligned bits in buffer */ |
248 | mask_input_leftover = mask_bits_needed_iter & (~ mask_input_to_move); | 312 | mask_input_leftover = mask_bits_needed_iter & (~ mask_input_to_move); |
313 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
314 | "mask of leftover bits of new byte: "B2B_PAT"\n", | ||
315 | B2B(mask_input_leftover)); | ||
249 | byte_input_leftover = byte_input & mask_input_leftover; | 316 | byte_input_leftover = byte_input & mask_input_leftover; |
317 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
318 | "masked, leftover bits of new byte: "B2B_PAT"\n", | ||
319 | B2B(byte_input_leftover)); | ||
250 | num_bits_leftover = num_bits_needed_iter - num_bits_to_move; | 320 | num_bits_leftover = num_bits_needed_iter - num_bits_to_move; |
251 | num_bits_discard = 8 - num_bits_needed_iter; | 321 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
322 | "number of unaligned bits left: %u\n", | ||
323 | num_bits_leftover); | ||
324 | //num_bits_discard = 8 - num_bits_needed_iter; | ||
252 | byte_unaligned_new = byte_input_leftover >> num_bits_to_move; | 325 | byte_unaligned_new = byte_input_leftover >> num_bits_to_move; |
326 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
327 | "new unaligned byte: "B2B_PAT"\n", | ||
328 | B2B(byte_unaligned_new)); | ||
253 | buf_unaligned = byte_unaligned_new; | 329 | buf_unaligned = byte_unaligned_new; |
254 | num_bits_buf_unaligned = num_bits_leftover % 8; | 330 | num_bits_buf_unaligned = num_bits_leftover % 8; |
255 | } | 331 | } |