diff options
author | Julius Bünger <buenger@mytum.de> | 2015-01-18 23:16:15 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-01-18 23:16:15 +0000 |
commit | 81b7ddce7d96f7538af501fa1da032cceb89d84a (patch) | |
tree | 6917302bb133e553d431428e98e2a4cf8700af9c | |
parent | 40b9ab5648303db3af346bafa1bc26e7605a20ff (diff) | |
download | gnunet-81b7ddce7d96f7538af501fa1da032cceb89d84a.tar.gz gnunet-81b7ddce7d96f7538af501fa1da032cceb89d84a.zip |
check if peer we open a channel to is live
-rw-r--r-- | src/include/gnunet_protocols.h | 15 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps.c | 106 |
2 files changed, 86 insertions, 35 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 6a77ca589..fad279405 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -2664,6 +2664,15 @@ extern "C" | |||
2664 | */ | 2664 | */ |
2665 | #define GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY 952 | 2665 | #define GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY 952 |
2666 | 2666 | ||
2667 | /** | ||
2668 | * RPS Hello message. Sent directly after other peer established connection to | ||
2669 | * the first peer indicating that it is online and communication over this | ||
2670 | * channel is now possible. | ||
2671 | * | ||
2672 | * This might contain a pow over the sender id | ||
2673 | */ | ||
2674 | #define GNUNET_MESSAGE_TYPE_RPS_PP_HELLO 953 | ||
2675 | |||
2667 | 2676 | ||
2668 | 2677 | ||
2669 | /* Client-Service Messages */ | 2678 | /* Client-Service Messages */ |
@@ -2671,17 +2680,17 @@ extern "C" | |||
2671 | /** | 2680 | /** |
2672 | * RPS CS REQUEST Message for the Client to request (a) random peer(s) | 2681 | * RPS CS REQUEST Message for the Client to request (a) random peer(s) |
2673 | */ | 2682 | */ |
2674 | #define GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST 953 | 2683 | #define GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST 954 |
2675 | 2684 | ||
2676 | /** | 2685 | /** |
2677 | * RPS CS REPLY Message for the Server to send (a) random peer(s) | 2686 | * RPS CS REPLY Message for the Server to send (a) random peer(s) |
2678 | */ | 2687 | */ |
2679 | #define GNUNET_MESSAGE_TYPE_RPS_CS_REPLY 954 | 2688 | #define GNUNET_MESSAGE_TYPE_RPS_CS_REPLY 955 |
2680 | 2689 | ||
2681 | /** | 2690 | /** |
2682 | * RPS CS SEED Message for the Client to seed peers into rps | 2691 | * RPS CS SEED Message for the Client to seed peers into rps |
2683 | */ | 2692 | */ |
2684 | #define GNUNET_MESSAGE_TYPE_RPS_CS_SEED 955 | 2693 | #define GNUNET_MESSAGE_TYPE_RPS_CS_SEED 956 |
2685 | 2694 | ||
2686 | 2695 | ||
2687 | /*******************************************************************************/ | 2696 | /*******************************************************************************/ |
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 86b5d7443..b3932ba22 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -109,12 +109,17 @@ struct client_ctx | |||
109 | /** | 109 | /** |
110 | * Used to keep track in what lists single peerIDs are. | 110 | * Used to keep track in what lists single peerIDs are. |
111 | */ | 111 | */ |
112 | enum in_list_flag // probably unneeded | 112 | enum PeerFlags |
113 | { | 113 | { |
114 | in_other_sampler_list = 0x1, | 114 | IN_OTHER_SAMPLER_LIST = 0x01, // unneeded? |
115 | in_other_gossip_list = 0x2, // unneeded? | 115 | IN_OTHER_GOSSIP_LIST = 0x02, // unneeded? |
116 | in_own_sampler_list = 0x4, | 116 | IN_OWN_SAMPLER_LIST = 0x04, // unneeded? |
117 | in_own_gossip_list = 0x8 // unneeded? | 117 | IN_OWN_GOSSIP_LIST = 0x08, // unneeded? |
118 | |||
119 | /** | ||
120 | * We set this bit when we receive a hello in response to opening a channel. | ||
121 | */ | ||
122 | IS_LIVE = 0x10 | ||
118 | }; | 123 | }; |
119 | 124 | ||
120 | /** | 125 | /** |
@@ -127,7 +132,7 @@ struct PeerContext | |||
127 | /** | 132 | /** |
128 | * In own gossip/sampler list, in other's gossip/sampler list | 133 | * In own gossip/sampler list, in other's gossip/sampler list |
129 | */ | 134 | */ |
130 | uint32_t in_flags; // unneeded? | 135 | uint32_t peer_flags; |
131 | 136 | ||
132 | /** | 137 | /** |
133 | * Message queue open to client | 138 | * Message queue open to client |
@@ -137,12 +142,12 @@ struct PeerContext | |||
137 | /** | 142 | /** |
138 | * Channel open to client. | 143 | * Channel open to client. |
139 | */ | 144 | */ |
140 | struct GNUNET_CADET_Channel *to_channel; | 145 | struct GNUNET_CADET_Channel *send_channel; |
141 | 146 | ||
142 | /** | 147 | /** |
143 | * Channel open from client. | 148 | * Channel open from client. |
144 | */ | 149 | */ |
145 | struct GNUNET_CADET_Channel *from_channel; // unneeded | 150 | struct GNUNET_CADET_Channel *recv_channel; // unneeded? |
146 | 151 | ||
147 | /** | 152 | /** |
148 | * This is pobably followed by 'statistical' data (when we first saw | 153 | * This is pobably followed by 'statistical' data (when we first saw |
@@ -388,10 +393,10 @@ get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNE | |||
388 | else | 393 | else |
389 | { | 394 | { |
390 | ctx = GNUNET_new (struct PeerContext); | 395 | ctx = GNUNET_new (struct PeerContext); |
391 | ctx->in_flags = 0; | 396 | ctx->peer_flags = 0; |
392 | ctx->mq = NULL; | 397 | ctx->mq = NULL; |
393 | ctx->to_channel = NULL; | 398 | ctx->send_channel = NULL; |
394 | ctx->from_channel = NULL; | 399 | ctx->recv_channel = NULL; |
395 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 400 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
396 | } | 401 | } |
397 | return ctx; | 402 | return ctx; |
@@ -407,16 +412,16 @@ get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET | |||
407 | struct PeerContext *ctx; | 412 | struct PeerContext *ctx; |
408 | 413 | ||
409 | ctx = get_peer_ctx (peer_map, peer); | 414 | ctx = get_peer_ctx (peer_map, peer); |
410 | if (NULL == ctx->to_channel) | 415 | if (NULL == ctx->send_channel) |
411 | { | 416 | { |
412 | ctx->to_channel = GNUNET_CADET_channel_create (cadet_handle, NULL, peer, | 417 | ctx->send_channel = GNUNET_CADET_channel_create (cadet_handle, NULL, peer, |
413 | GNUNET_RPS_CADET_PORT, | 418 | GNUNET_RPS_CADET_PORT, |
414 | GNUNET_CADET_OPTION_RELIABLE); | 419 | GNUNET_CADET_OPTION_RELIABLE); |
415 | // do I have to explicitly put it in the peer_map? | 420 | // do I have to explicitly put it in the peer_map? |
416 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, | 421 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, |
417 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 422 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
418 | } | 423 | } |
419 | return ctx->to_channel; | 424 | return ctx->send_channel; |
420 | } | 425 | } |
421 | 426 | ||
422 | 427 | ||
@@ -435,7 +440,7 @@ get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_Peer | |||
435 | if (NULL == ctx->mq) | 440 | if (NULL == ctx->mq) |
436 | { | 441 | { |
437 | (void) get_channel (peer_map, peer_id); | 442 | (void) get_channel (peer_map, peer_id); |
438 | ctx->mq = GNUNET_CADET_mq_create (ctx->to_channel); | 443 | ctx->mq = GNUNET_CADET_mq_create (ctx->send_channel); |
439 | //do I have to explicitly put it in the peer_map? | 444 | //do I have to explicitly put it in the peer_map? |
440 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer_id, ctx, | 445 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer_id, ctx, |
441 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 446 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
@@ -722,7 +727,8 @@ handle_peer_pull_request (void *cls, | |||
722 | struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; | 727 | struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; |
723 | 728 | ||
724 | 729 | ||
725 | peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (channel, GNUNET_CADET_OPTION_PEER); | 730 | peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (channel, |
731 | GNUNET_CADET_OPTION_PEER); | ||
726 | // FIXME wait for cadet to change this function | 732 | // FIXME wait for cadet to change this function |
727 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 733 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
728 | "PULL REQUEST from peer %s received, going to send %u peers\n", | 734 | "PULL REQUEST from peer %s received, going to send %u peers\n", |
@@ -754,7 +760,7 @@ handle_peer_pull_request (void *cls, | |||
754 | * @param channel_ctx The context associated with this channel | 760 | * @param channel_ctx The context associated with this channel |
755 | * @param msg The message header | 761 | * @param msg The message header |
756 | */ | 762 | */ |
757 | static int | 763 | static int |
758 | handle_peer_pull_reply (void *cls, | 764 | handle_peer_pull_reply (void *cls, |
759 | struct GNUNET_CADET_Channel *channel, | 765 | struct GNUNET_CADET_Channel *channel, |
760 | void **channel_ctx, | 766 | void **channel_ctx, |
@@ -797,6 +803,31 @@ handle_peer_pull_reply (void *cls, | |||
797 | 803 | ||
798 | 804 | ||
799 | /** | 805 | /** |
806 | * Handle Hello message from other peer. | ||
807 | */ | ||
808 | static int | ||
809 | handle_peer_hello (void *cls, | ||
810 | struct GNUNET_CADET_Channel *channel, | ||
811 | void **channel_ctx, | ||
812 | const struct GNUNET_MessageHeader *msg) | ||
813 | { | ||
814 | const struct GNUNET_PeerIdentity *peer; | ||
815 | struct PeerContext *peer_ctx; | ||
816 | |||
817 | peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (channel, | ||
818 | GNUNET_CADET_OPTION_PEER); | ||
819 | // FIXME wait for cadet to change this function | ||
820 | |||
821 | LOG (GNUNET_ERROR_TYPE_DEBUG, "HELLO received from %s\n", GNUNET_i2s (peer)); | ||
822 | |||
823 | peer_ctx = get_peer_ctx (peer_map, peer); | ||
824 | peer_ctx->peer_flags |= IS_LIVE; | ||
825 | |||
826 | return GNUNET_OK; | ||
827 | } | ||
828 | |||
829 | |||
830 | /** | ||
800 | * Send out PUSHes and PULLs. | 831 | * Send out PUSHes and PULLs. |
801 | * | 832 | * |
802 | * This is executed regylary. | 833 | * This is executed regylary. |
@@ -886,7 +917,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
886 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 917 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, |
887 | push_list_size); | 918 | push_list_size); |
888 | gossip_list[i] = push_list[r_index]; | 919 | gossip_list[i] = push_list[r_index]; |
889 | // TODO change the in_flags accordingly | 920 | // TODO change the peer_flags accordingly |
890 | } | 921 | } |
891 | 922 | ||
892 | second_border = first_border + round (beta * gossip_list_size); | 923 | second_border = first_border + round (beta * gossip_list_size); |
@@ -896,7 +927,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
896 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 927 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, |
897 | pull_list_size); | 928 | pull_list_size); |
898 | gossip_list[i] = pull_list[r_index]; | 929 | gossip_list[i] = pull_list[r_index]; |
899 | // TODO change the in_flags accordingly | 930 | // TODO change the peer_flags accordingly |
900 | } | 931 | } |
901 | 932 | ||
902 | for ( i = second_border ; i < gossip_list_size ; i++ ) | 933 | for ( i = second_border ; i < gossip_list_size ; i++ ) |
@@ -904,7 +935,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
904 | /* Update gossip list with peers from history */ | 935 | /* Update gossip list with peers from history */ |
905 | peer = RPS_sampler_get_n_rand_peers_ (1); | 936 | peer = RPS_sampler_get_n_rand_peers_ (1); |
906 | gossip_list[i] = *peer; | 937 | gossip_list[i] = *peer; |
907 | // TODO change the in_flags accordingly | 938 | // TODO change the peer_flags accordingly |
908 | } | 939 | } |
909 | 940 | ||
910 | } | 941 | } |
@@ -984,14 +1015,14 @@ removeCB (void *cls, const struct GNUNET_PeerIdentity *id) | |||
984 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, id)) | 1015 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, id)) |
985 | { | 1016 | { |
986 | ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, id); | 1017 | ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, id); |
987 | if (NULL != ctx->to_channel) | 1018 | if (NULL != ctx->send_channel) |
988 | { | 1019 | { |
989 | if (NULL != ctx->mq) | 1020 | if (NULL != ctx->mq) |
990 | { | 1021 | { |
991 | GNUNET_MQ_destroy (ctx->mq); | 1022 | GNUNET_MQ_destroy (ctx->mq); |
992 | } | 1023 | } |
993 | // may already be freed at shutdown of cadet | 1024 | // may already be freed at shutdown of cadet |
994 | //GNUNET_CADET_channel_destroy (ctx->to_channel); | 1025 | //GNUNET_CADET_channel_destroy (ctx->send_channel); |
995 | } | 1026 | } |
996 | // TODO cleanup peer | 1027 | // TODO cleanup peer |
997 | (void) GNUNET_CONTAINER_multipeermap_remove_all (peer_map, id); | 1028 | (void) GNUNET_CONTAINER_multipeermap_remove_all (peer_map, id); |
@@ -1063,11 +1094,11 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
1063 | if ( NULL != peer_ctx->mq) | 1094 | if ( NULL != peer_ctx->mq) |
1064 | GNUNET_MQ_destroy (peer_ctx->mq); | 1095 | GNUNET_MQ_destroy (peer_ctx->mq); |
1065 | 1096 | ||
1066 | if ( NULL != peer_ctx->to_channel) | 1097 | if ( NULL != peer_ctx->send_channel) |
1067 | GNUNET_CADET_channel_destroy (peer_ctx->to_channel); | 1098 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); |
1068 | 1099 | ||
1069 | if ( NULL != peer_ctx->from_channel) | 1100 | if ( NULL != peer_ctx->recv_channel) |
1070 | GNUNET_CADET_channel_destroy (peer_ctx->from_channel); | 1101 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); |
1071 | 1102 | ||
1072 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_remove_all (peer_map, key)) | 1103 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_remove_all (peer_map, key)) |
1073 | LOG (GNUNET_ERROR_TYPE_WARNING, "removing peer from peer_map failed\n"); | 1104 | LOG (GNUNET_ERROR_TYPE_WARNING, "removing peer from peer_map failed\n"); |
@@ -1140,23 +1171,32 @@ handle_inbound_channel (void *cls, | |||
1140 | uint32_t port, | 1171 | uint32_t port, |
1141 | enum GNUNET_CADET_ChannelOption options) | 1172 | enum GNUNET_CADET_ChannelOption options) |
1142 | { | 1173 | { |
1174 | struct GNUNET_MQ_Envelope *ev; | ||
1175 | struct GNUNET_MQ_Handle *mq; | ||
1143 | struct PeerContext *ctx; | 1176 | struct PeerContext *ctx; |
1144 | 1177 | ||
1145 | LOG (GNUNET_ERROR_TYPE_DEBUG, "New channel was established to us (Peer %s).\n", GNUNET_i2s (initiator)); | 1178 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1179 | "New channel was established to us (Peer %s).\n", | ||
1180 | GNUNET_i2s (initiator)); | ||
1181 | |||
1182 | GNUNET_assert (NULL != channel); | ||
1146 | 1183 | ||
1147 | GNUNET_assert ( NULL != channel ); | 1184 | /* Send hello message to other peer */ |
1185 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_HELLO); | ||
1186 | mq = get_mq (peer_map, initiator); | ||
1187 | GNUNET_MQ_send (mq, ev); | ||
1148 | 1188 | ||
1149 | // we might not even store the from_channel | 1189 | // we might not even store the recv_channel |
1150 | 1190 | ||
1151 | ctx = get_peer_ctx (peer_map, initiator); | 1191 | ctx = get_peer_ctx (peer_map, initiator); |
1152 | if (NULL != ctx->from_channel) | 1192 | if (NULL != ctx->recv_channel) |
1153 | { | 1193 | { |
1154 | ctx->from_channel = channel; | 1194 | ctx->recv_channel = channel; |
1155 | } | 1195 | } |
1156 | 1196 | ||
1157 | // FIXME there might already be an established channel | 1197 | // FIXME there might already be an established channel |
1158 | 1198 | ||
1159 | //ctx->in_flags = in_other_gossip_list; | 1199 | //ctx->peer_flags = IN_OTHER_GOSSIP_LIST; |
1160 | ctx->mq = NULL; // TODO create mq? | 1200 | ctx->mq = NULL; // TODO create mq? |
1161 | 1201 | ||
1162 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, initiator, ctx, | 1202 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, initiator, ctx, |
@@ -1319,6 +1359,8 @@ run (void *cls, | |||
1319 | {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, | 1359 | {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, |
1320 | sizeof (struct GNUNET_MessageHeader)}, | 1360 | sizeof (struct GNUNET_MessageHeader)}, |
1321 | {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0}, | 1361 | {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0}, |
1362 | {&handle_peer_hello , GNUNET_MESSAGE_TYPE_RPS_PP_HELLO , | ||
1363 | sizeof (struct GNUNET_MessageHeader)}, | ||
1322 | {NULL, 0, 0} | 1364 | {NULL, 0, 0} |
1323 | }; | 1365 | }; |
1324 | 1366 | ||