diff options
author | Julius Bünger <buenger@mytum.de> | 2015-01-17 22:08:05 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-01-17 22:08:05 +0000 |
commit | 817e9efeb43fad3d3abae6d75355b0b88da35a32 (patch) | |
tree | a9adc36b8fa40a5f2d3591a9ed03bc9e9b56f6bd /src/rps | |
parent | 515a90ff5d0c03964c0676a4a5823c5649759694 (diff) | |
download | gnunet-817e9efeb43fad3d3abae6d75355b0b88da35a32.tar.gz gnunet-817e9efeb43fad3d3abae6d75355b0b88da35a32.zip |
clean up channels to other peers correctly
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index ef90fa79c..9b37ccfe9 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -122,7 +122,7 @@ enum in_list_flag // probably unneeded | |||
122 | * | 122 | * |
123 | * This is stored in a multipeermap. | 123 | * This is stored in a multipeermap. |
124 | */ | 124 | */ |
125 | struct peer_context | 125 | struct PeerContext |
126 | { | 126 | { |
127 | /** | 127 | /** |
128 | * In own gossip/sampler list, in other's gossip/sampler list | 128 | * In own gossip/sampler list, in other's gossip/sampler list |
@@ -376,10 +376,10 @@ get_rand_peer (const struct GNUNET_PeerIdentity *peer_list, unsigned int list_si | |||
376 | /** | 376 | /** |
377 | * Get the context of a peer. If not existing, create. | 377 | * Get the context of a peer. If not existing, create. |
378 | */ | 378 | */ |
379 | struct peer_context * | 379 | struct PeerContext * |
380 | get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) | 380 | get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) |
381 | { | 381 | { |
382 | struct peer_context *ctx; | 382 | struct PeerContext *ctx; |
383 | 383 | ||
384 | if ( GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) | 384 | if ( GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) |
385 | { | 385 | { |
@@ -387,7 +387,7 @@ get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNE | |||
387 | } | 387 | } |
388 | else | 388 | else |
389 | { | 389 | { |
390 | ctx = GNUNET_new (struct peer_context); | 390 | ctx = GNUNET_new (struct PeerContext); |
391 | ctx->in_flags = 0; | 391 | ctx->in_flags = 0; |
392 | ctx->mq = NULL; | 392 | ctx->mq = NULL; |
393 | ctx->to_channel = NULL; | 393 | ctx->to_channel = NULL; |
@@ -404,7 +404,7 @@ get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNE | |||
404 | struct GNUNET_CADET_Channel * | 404 | struct GNUNET_CADET_Channel * |
405 | get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) | 405 | get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) |
406 | { | 406 | { |
407 | struct peer_context *ctx; | 407 | struct PeerContext *ctx; |
408 | 408 | ||
409 | ctx = get_peer_ctx (peer_map, peer); | 409 | ctx = get_peer_ctx (peer_map, peer); |
410 | if (NULL == ctx->to_channel) | 410 | if (NULL == ctx->to_channel) |
@@ -429,7 +429,7 @@ get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET | |||
429 | struct GNUNET_MQ_Handle * | 429 | struct GNUNET_MQ_Handle * |
430 | get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer_id) | 430 | get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer_id) |
431 | { | 431 | { |
432 | struct peer_context *ctx; | 432 | struct PeerContext *ctx; |
433 | 433 | ||
434 | ctx = get_peer_ctx (peer_map, peer_id); | 434 | ctx = get_peer_ctx (peer_map, peer_id); |
435 | if (NULL == ctx->mq) | 435 | if (NULL == ctx->mq) |
@@ -837,6 +837,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
837 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PUSH to peer %s of gossiped list.\n", GNUNET_i2s (peer)); | 837 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PUSH to peer %s of gossiped list.\n", GNUNET_i2s (peer)); |
838 | 838 | ||
839 | ev = GNUNET_MQ_msg (push_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); | 839 | ev = GNUNET_MQ_msg (push_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); |
840 | // TODO replace with GNUNET_MQ_msg_header | ||
840 | // FIXME sometimes it returns a pointer to a freed mq | 841 | // FIXME sometimes it returns a pointer to a freed mq |
841 | mq = get_mq (peer_map, peer); | 842 | mq = get_mq (peer_map, peer); |
842 | GNUNET_MQ_send (mq, ev); | 843 | GNUNET_MQ_send (mq, ev); |
@@ -859,6 +860,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
859 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PULL request to peer %s of gossiped list.\n", GNUNET_i2s (peer)); | 860 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PULL request to peer %s of gossiped list.\n", GNUNET_i2s (peer)); |
860 | 861 | ||
861 | ev = GNUNET_MQ_msg (pull_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); | 862 | ev = GNUNET_MQ_msg (pull_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); |
863 | // TODO replace with GNUNET_MQ_msg_header | ||
862 | //pull_msg = NULL; | 864 | //pull_msg = NULL; |
863 | mq = get_mq (peer_map, peer); | 865 | mq = get_mq (peer_map, peer); |
864 | GNUNET_MQ_send (mq, ev); | 866 | GNUNET_MQ_send (mq, ev); |
@@ -977,7 +979,7 @@ insertCB (void *cls, const struct GNUNET_PeerIdentity *id) | |||
977 | removeCB (void *cls, const struct GNUNET_PeerIdentity *id) | 979 | removeCB (void *cls, const struct GNUNET_PeerIdentity *id) |
978 | { | 980 | { |
979 | size_t s; | 981 | size_t s; |
980 | struct peer_context *ctx; | 982 | struct PeerContext *ctx; |
981 | 983 | ||
982 | s = RPS_sampler_count_id (id); | 984 | s = RPS_sampler_count_id (id); |
983 | if ( 1 >= s ) | 985 | if ( 1 >= s ) |
@@ -1052,6 +1054,29 @@ init_peer_cb (void *cls, | |||
1052 | 1054 | ||
1053 | 1055 | ||
1054 | /** | 1056 | /** |
1057 | * Callback used to clean the multipeermap. | ||
1058 | */ | ||
1059 | int | ||
1060 | peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | ||
1061 | { | ||
1062 | struct PeerContext *peer_ctx; | ||
1063 | |||
1064 | peer_ctx = (struct PeerContext *) value; | ||
1065 | |||
1066 | if ( NULL != peer_ctx->mq) | ||
1067 | GNUNET_MQ_destroy (peer_ctx->mq); | ||
1068 | |||
1069 | if ( NULL != peer_ctx->to_channel) | ||
1070 | GNUNET_CADET_channel_destroy (peer_ctx->to_channel); | ||
1071 | |||
1072 | if ( NULL != peer_ctx->from_channel) | ||
1073 | GNUNET_CADET_channel_destroy (peer_ctx->from_channel); | ||
1074 | |||
1075 | return GNUNET_YES; | ||
1076 | } | ||
1077 | |||
1078 | |||
1079 | /** | ||
1055 | * Task run during shutdown. | 1080 | * Task run during shutdown. |
1056 | * | 1081 | * |
1057 | * @param cls unused | 1082 | * @param cls unused |
@@ -1063,12 +1088,21 @@ shutdown_task (void *cls, | |||
1063 | { | 1088 | { |
1064 | LOG (GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n"); | 1089 | LOG (GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n"); |
1065 | 1090 | ||
1091 | uint64_t num_peers; | ||
1092 | |||
1066 | if ( NULL != do_round_task ) | 1093 | if ( NULL != do_round_task ) |
1067 | { | 1094 | { |
1068 | GNUNET_SCHEDULER_cancel (do_round_task); | 1095 | GNUNET_SCHEDULER_cancel (do_round_task); |
1069 | do_round_task = NULL; | 1096 | do_round_task = NULL; |
1070 | } | 1097 | } |
1071 | 1098 | ||
1099 | num_peers = GNUNET_CONTAINER_multipeermap_iterate (peer_map, peer_remove_cb, NULL); | ||
1100 | if (GNUNET_SYSERR == num_peers) | ||
1101 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1102 | "Iterating over peers to disconnect from them was cancelled\n"); | ||
1103 | |||
1104 | GNUNET_CONTAINER_multipeermap_destroy (peer_map); | ||
1105 | |||
1072 | GNUNET_NSE_disconnect (nse); | 1106 | GNUNET_NSE_disconnect (nse); |
1073 | GNUNET_CADET_disconnect (cadet_handle); | 1107 | GNUNET_CADET_disconnect (cadet_handle); |
1074 | GNUNET_free (own_identity); | 1108 | GNUNET_free (own_identity); |
@@ -1108,7 +1142,7 @@ handle_inbound_channel (void *cls, | |||
1108 | uint32_t port, | 1142 | uint32_t port, |
1109 | enum GNUNET_CADET_ChannelOption options) | 1143 | enum GNUNET_CADET_ChannelOption options) |
1110 | { | 1144 | { |
1111 | struct peer_context *ctx; | 1145 | struct PeerContext *ctx; |
1112 | 1146 | ||
1113 | LOG (GNUNET_ERROR_TYPE_DEBUG, "New channel was established to us (Peer %s).\n", GNUNET_i2s (initiator)); | 1147 | LOG (GNUNET_ERROR_TYPE_DEBUG, "New channel was established to us (Peer %s).\n", GNUNET_i2s (initiator)); |
1114 | 1148 | ||