diff options
Diffstat (limited to 'src/rps/gnunet-service-rps.c')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 1325 |
1 files changed, 559 insertions, 766 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index eb47903e0..1f155b14f 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013-2015 GNUnet e.V. | 3 | Copyright (C) 2013-2015 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -70,7 +68,14 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
70 | */ | 68 | */ |
71 | static struct GNUNET_PeerIdentity own_identity; | 69 | static struct GNUNET_PeerIdentity own_identity; |
72 | 70 | ||
71 | static int in_shutdown = GNUNET_NO; | ||
73 | 72 | ||
73 | /** | ||
74 | * @brief Port used for cadet. | ||
75 | * | ||
76 | * Don't compute multiple times through making it global | ||
77 | */ | ||
78 | static struct GNUNET_HashCode port; | ||
74 | 79 | ||
75 | /*********************************************************************** | 80 | /*********************************************************************** |
76 | * Old gnunet-service-rps_peers.c | 81 | * Old gnunet-service-rps_peers.c |
@@ -79,7 +84,7 @@ static struct GNUNET_PeerIdentity own_identity; | |||
79 | /** | 84 | /** |
80 | * Set a peer flag of given peer context. | 85 | * Set a peer flag of given peer context. |
81 | */ | 86 | */ |
82 | #define set_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask)) | 87 | #define SET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask)) |
83 | 88 | ||
84 | /** | 89 | /** |
85 | * Get peer flag of given peer context. | 90 | * Get peer flag of given peer context. |
@@ -90,12 +95,7 @@ static struct GNUNET_PeerIdentity own_identity; | |||
90 | /** | 95 | /** |
91 | * Unset flag of given peer context. | 96 | * Unset flag of given peer context. |
92 | */ | 97 | */ |
93 | #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)) |
94 | |||
95 | /** | ||
96 | * Set a channel flag of given channel context. | ||
97 | */ | ||
98 | #define set_channel_flag(channel_flags, mask) ((*channel_flags) |= (mask)) | ||
99 | 99 | ||
100 | /** | 100 | /** |
101 | * Get channel flag of given channel context. | 101 | * Get channel flag of given channel context. |
@@ -160,6 +160,11 @@ struct PendingMessage | |||
160 | }; | 160 | }; |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * @brief Context for a channel | ||
164 | */ | ||
165 | struct ChannelCtx; | ||
166 | |||
167 | /** | ||
163 | * Struct used to keep track of other peer's status | 168 | * Struct used to keep track of other peer's status |
164 | * | 169 | * |
165 | * This is stored in a multipeermap. | 170 | * This is stored in a multipeermap. |
@@ -177,22 +182,12 @@ struct PeerContext | |||
177 | /** | 182 | /** |
178 | * Channel open to client. | 183 | * Channel open to client. |
179 | */ | 184 | */ |
180 | struct GNUNET_CADET_Channel *send_channel; | 185 | struct ChannelCtx *send_channel_ctx; |
181 | |||
182 | /** | ||
183 | * Flags to the sending channel | ||
184 | */ | ||
185 | uint32_t *send_channel_flags; | ||
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Channel open from client. | 188 | * Channel open from client. |
189 | */ | 189 | */ |
190 | struct GNUNET_CADET_Channel *recv_channel; // unneeded? | 190 | struct ChannelCtx *recv_channel_ctx; |
191 | |||
192 | /** | ||
193 | * Flags to the receiving channel | ||
194 | */ | ||
195 | uint32_t *recv_channel_flags; | ||
196 | 191 | ||
197 | /** | 192 | /** |
198 | * Array of pending operations on this peer. | 193 | * Array of pending operations on this peer. |
@@ -239,7 +234,7 @@ struct PeerContext | |||
239 | 234 | ||
240 | /** | 235 | /** |
241 | * This is pobably followed by 'statistical' data (when we first saw | 236 | * This is pobably followed by 'statistical' data (when we first saw |
242 | * him, how did we get his ID, how many pushes (in a timeinterval), | 237 | * it, how did we get its ID, how many pushes (in a timeinterval), |
243 | * ...) | 238 | * ...) |
244 | */ | 239 | */ |
245 | }; | 240 | }; |
@@ -261,6 +256,35 @@ struct PeersIteratorCls | |||
261 | }; | 256 | }; |
262 | 257 | ||
263 | /** | 258 | /** |
259 | * @brief Context for a channel | ||
260 | */ | ||
261 | struct ChannelCtx | ||
262 | { | ||
263 | /** | ||
264 | * @brief Meant to be used in a DLL | ||
265 | */ | ||
266 | struct ChannelCtx *next; | ||
267 | struct ChannelCtx *prev; | ||
268 | |||
269 | /** | ||
270 | * @brief The channel itself | ||
271 | */ | ||
272 | struct GNUNET_CADET_Channel *channel; | ||
273 | |||
274 | /** | ||
275 | * @brief The peer context associated with the channel | ||
276 | */ | ||
277 | struct PeerContext *peer_ctx; | ||
278 | |||
279 | /** | ||
280 | * @brief When channel destruction needs to be delayed (because it is called | ||
281 | * from within the cadet routine of another channel destruction) this task | ||
282 | * refers to the respective _SCHEDULER_Task. | ||
283 | */ | ||
284 | struct GNUNET_SCHEDULER_Task *destruction_task; | ||
285 | }; | ||
286 | |||
287 | /** | ||
264 | * @brief Hashmap of valid peers. | 288 | * @brief Hashmap of valid peers. |
265 | */ | 289 | */ |
266 | static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; | 290 | static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; |
@@ -287,7 +311,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *peer_map; | |||
287 | static struct GNUNET_CADET_Handle *cadet_handle; | 311 | static struct GNUNET_CADET_Handle *cadet_handle; |
288 | 312 | ||
289 | 313 | ||
290 | |||
291 | /** | 314 | /** |
292 | * @brief Get the #PeerContext associated with a peer | 315 | * @brief Get the #PeerContext associated with a peer |
293 | * | 316 | * |
@@ -308,8 +331,28 @@ get_peer_ctx (const struct GNUNET_PeerIdentity *peer) | |||
308 | return ctx; | 331 | return ctx; |
309 | } | 332 | } |
310 | 333 | ||
311 | int | 334 | /** |
312 | Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer); | 335 | * @brief Check whether we have information about the given peer. |
336 | * | ||
337 | * FIXME probably deprecated. Make this the new _online. | ||
338 | * | ||
339 | * @param peer peer in question | ||
340 | * | ||
341 | * @return #GNUNET_YES if peer is known | ||
342 | * #GNUNET_NO if peer is not knwon | ||
343 | */ | ||
344 | static int | ||
345 | check_peer_known (const struct GNUNET_PeerIdentity *peer) | ||
346 | { | ||
347 | if (NULL != peer_map) | ||
348 | { | ||
349 | return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); | ||
350 | } else | ||
351 | { | ||
352 | return GNUNET_NO; | ||
353 | } | ||
354 | } | ||
355 | |||
313 | 356 | ||
314 | /** | 357 | /** |
315 | * @brief Create a new #PeerContext and insert it into the peer map | 358 | * @brief Create a new #PeerContext and insert it into the peer map |
@@ -324,12 +367,10 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer) | |||
324 | struct PeerContext *ctx; | 367 | struct PeerContext *ctx; |
325 | int ret; | 368 | int ret; |
326 | 369 | ||
327 | GNUNET_assert (GNUNET_NO == Peers_check_peer_known (peer)); | 370 | GNUNET_assert (GNUNET_NO == check_peer_known (peer)); |
328 | 371 | ||
329 | ctx = GNUNET_new (struct PeerContext); | 372 | ctx = GNUNET_new (struct PeerContext); |
330 | ctx->peer_id = *peer; | 373 | ctx->peer_id = *peer; |
331 | ctx->send_channel_flags = GNUNET_new (uint32_t); | ||
332 | ctx->recv_channel_flags = GNUNET_new (uint32_t); | ||
333 | ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, | 374 | ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, |
334 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 375 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
335 | GNUNET_assert (GNUNET_OK == ret); | 376 | GNUNET_assert (GNUNET_OK == ret); |
@@ -347,18 +388,13 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer) | |||
347 | static struct PeerContext * | 388 | static struct PeerContext * |
348 | create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer) | 389 | create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer) |
349 | { | 390 | { |
350 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 391 | if (GNUNET_NO == check_peer_known (peer)) |
351 | { | 392 | { |
352 | return create_peer_ctx (peer); | 393 | return create_peer_ctx (peer); |
353 | } | 394 | } |
354 | return get_peer_ctx (peer); | 395 | return get_peer_ctx (peer); |
355 | } | 396 | } |
356 | 397 | ||
357 | void | ||
358 | Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags); | ||
359 | |||
360 | void | ||
361 | Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags); | ||
362 | 398 | ||
363 | /** | 399 | /** |
364 | * @brief Check whether we have a connection to this @a peer | 400 | * @brief Check whether we have a connection to this @a peer |
@@ -370,27 +406,27 @@ Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlag | |||
370 | * @return #GNUNET_YES if we are connected | 406 | * @return #GNUNET_YES if we are connected |
371 | * #GNUNET_NO otherwise | 407 | * #GNUNET_NO otherwise |
372 | */ | 408 | */ |
373 | int | 409 | static int |
374 | Peers_check_connected (const struct GNUNET_PeerIdentity *peer) | 410 | check_connected (const struct GNUNET_PeerIdentity *peer) |
375 | { | 411 | { |
376 | const struct PeerContext *peer_ctx; | 412 | struct PeerContext *peer_ctx; |
377 | 413 | ||
378 | /* If we don't know about this peer we don't know whether it's online */ | 414 | /* If we don't know about this peer we don't know whether it's online */ |
379 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 415 | if (GNUNET_NO == check_peer_known (peer)) |
380 | { | 416 | { |
381 | return GNUNET_NO; | 417 | return GNUNET_NO; |
382 | } | 418 | } |
383 | /* Get the context */ | 419 | /* Get the context */ |
384 | peer_ctx = get_peer_ctx (peer); | 420 | peer_ctx = get_peer_ctx (peer); |
385 | /* If we have no channel to this peer we don't know whether it's online */ | 421 | /* If we have no channel to this peer we don't know whether it's online */ |
386 | if ( (NULL == peer_ctx->send_channel) && | 422 | if ( (NULL == peer_ctx->send_channel_ctx) && |
387 | (NULL == peer_ctx->recv_channel) ) | 423 | (NULL == peer_ctx->recv_channel_ctx) ) |
388 | { | 424 | { |
389 | Peers_unset_peer_flag (peer, Peers_ONLINE); | 425 | UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
390 | return GNUNET_NO; | 426 | return GNUNET_NO; |
391 | } | 427 | } |
392 | /* Otherwise (if we have a channel, we know that it's online */ | 428 | /* Otherwise (if we have a channel, we know that it's online */ |
393 | Peers_set_peer_flag (peer, Peers_ONLINE); | 429 | SET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
394 | return GNUNET_YES; | 430 | return GNUNET_YES; |
395 | } | 431 | } |
396 | 432 | ||
@@ -499,6 +535,8 @@ add_valid_peer (const struct GNUNET_PeerIdentity *peer) | |||
499 | return ret; | 535 | return ret; |
500 | } | 536 | } |
501 | 537 | ||
538 | static void | ||
539 | remove_pending_message (struct PendingMessage *pending_msg, int cancel); | ||
502 | 540 | ||
503 | /** | 541 | /** |
504 | * @brief Set the peer flag to living and | 542 | * @brief Set the peer flag to living and |
@@ -527,12 +565,12 @@ set_peer_live (struct PeerContext *peer_ctx) | |||
527 | GNUNET_i2s (&peer_ctx->peer_id)); | 565 | GNUNET_i2s (&peer_ctx->peer_id)); |
528 | // TODO wait until cadet sets mq->cancel_impl | 566 | // TODO wait until cadet sets mq->cancel_impl |
529 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | 567 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); |
530 | GNUNET_free (peer_ctx->liveliness_check_pending); | 568 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); |
531 | peer_ctx->liveliness_check_pending = NULL; | 569 | peer_ctx->liveliness_check_pending = NULL; |
532 | } | 570 | } |
533 | 571 | ||
534 | (void) add_valid_peer (peer); | 572 | (void) add_valid_peer (peer); |
535 | set_peer_flag (peer_ctx, Peers_ONLINE); | 573 | SET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
536 | 574 | ||
537 | /* Call pending operations */ | 575 | /* Call pending operations */ |
538 | for (i = 0; i < peer_ctx->num_pending_ops; i++) | 576 | for (i = 0; i < peer_ctx->num_pending_ops; i++) |
@@ -569,6 +607,46 @@ handle_peer_pull_reply (void *cls, | |||
569 | 607 | ||
570 | /* End declaration of handlers */ | 608 | /* End declaration of handlers */ |
571 | 609 | ||
610 | /** | ||
611 | * @brief Allocate memory for a new channel context and insert it into DLL | ||
612 | * | ||
613 | * @param peer_ctx context of the according peer | ||
614 | * | ||
615 | * @return The channel context | ||
616 | */ | ||
617 | static struct ChannelCtx * | ||
618 | add_channel_ctx (struct PeerContext *peer_ctx) | ||
619 | { | ||
620 | struct ChannelCtx *channel_ctx; | ||
621 | channel_ctx = GNUNET_new (struct ChannelCtx); | ||
622 | channel_ctx->peer_ctx = peer_ctx; | ||
623 | return channel_ctx; | ||
624 | } | ||
625 | |||
626 | |||
627 | /** | ||
628 | * @brief Free memory and NULL pointers. | ||
629 | * | ||
630 | * @param channel_ctx The channel context. | ||
631 | */ | ||
632 | static void | ||
633 | remove_channel_ctx (struct ChannelCtx *channel_ctx) | ||
634 | { | ||
635 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | ||
636 | |||
637 | if (channel_ctx == peer_ctx->send_channel_ctx) | ||
638 | { | ||
639 | GNUNET_free (channel_ctx); | ||
640 | peer_ctx->send_channel_ctx = NULL; | ||
641 | peer_ctx->mq = NULL; | ||
642 | } | ||
643 | else if (channel_ctx == peer_ctx->recv_channel_ctx) | ||
644 | { | ||
645 | GNUNET_free (channel_ctx); | ||
646 | peer_ctx->recv_channel_ctx = NULL; | ||
647 | } | ||
648 | } | ||
649 | |||
572 | 650 | ||
573 | /** | 651 | /** |
574 | * @brief Get the channel of a peer. If not existing, create. | 652 | * @brief Get the channel of a peer. If not existing, create. |
@@ -580,7 +658,6 @@ struct GNUNET_CADET_Channel * | |||
580 | get_channel (const struct GNUNET_PeerIdentity *peer) | 658 | get_channel (const struct GNUNET_PeerIdentity *peer) |
581 | { | 659 | { |
582 | struct PeerContext *peer_ctx; | 660 | struct PeerContext *peer_ctx; |
583 | struct GNUNET_HashCode port; | ||
584 | struct GNUNET_PeerIdentity *ctx_peer; | 661 | struct GNUNET_PeerIdentity *ctx_peer; |
585 | /* There exists a copy-paste-clone in run() */ | 662 | /* There exists a copy-paste-clone in run() */ |
586 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 663 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
@@ -605,28 +682,27 @@ get_channel (const struct GNUNET_PeerIdentity *peer) | |||
605 | 682 | ||
606 | 683 | ||
607 | peer_ctx = get_peer_ctx (peer); | 684 | peer_ctx = get_peer_ctx (peer); |
608 | if (NULL == peer_ctx->send_channel) | 685 | if (NULL == peer_ctx->send_channel_ctx) |
609 | { | 686 | { |
610 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 687 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
611 | "Trying to establish channel to peer %s\n", | 688 | "Trying to establish channel to peer %s\n", |
612 | GNUNET_i2s (peer)); | 689 | GNUNET_i2s (peer)); |
613 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS, | ||
614 | strlen (GNUNET_APPLICATION_PORT_RPS), | ||
615 | &port); | ||
616 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); | 690 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); |
617 | *ctx_peer = *peer; | 691 | *ctx_peer = *peer; |
618 | peer_ctx->send_channel = | 692 | peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx); |
693 | peer_ctx->send_channel_ctx->channel = | ||
619 | GNUNET_CADET_channel_create (cadet_handle, | 694 | GNUNET_CADET_channel_create (cadet_handle, |
620 | (struct GNUNET_PeerIdentity *) ctx_peer, /* context */ | 695 | peer_ctx->send_channel_ctx, /* context */ |
621 | peer, | 696 | peer, |
622 | &port, | 697 | &port, |
623 | GNUNET_CADET_OPTION_RELIABLE, | 698 | GNUNET_CADET_OPTION_RELIABLE, |
624 | NULL, /* WindowSize handler */ | 699 | NULL, /* WindowSize handler */ |
625 | cleanup_destroyed_channel, /* Disconnect handler */ | 700 | &cleanup_destroyed_channel, /* Disconnect handler */ |
626 | cadet_handlers); | 701 | cadet_handlers); |
627 | } | 702 | } |
628 | GNUNET_assert (NULL != peer_ctx->send_channel); | 703 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx); |
629 | return peer_ctx->send_channel; | 704 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel); |
705 | return peer_ctx->send_channel_ctx->channel; | ||
630 | } | 706 | } |
631 | 707 | ||
632 | 708 | ||
@@ -653,56 +729,6 @@ get_mq (const struct GNUNET_PeerIdentity *peer) | |||
653 | return peer_ctx->mq; | 729 | return peer_ctx->mq; |
654 | } | 730 | } |
655 | 731 | ||
656 | |||
657 | /** | ||
658 | * @brief This is called in response to the first message we sent as a | ||
659 | * liveliness check. | ||
660 | * | ||
661 | * @param cls #PeerContext of peer with pending liveliness check | ||
662 | */ | ||
663 | static void | ||
664 | mq_liveliness_check_successful (void *cls) | ||
665 | { | ||
666 | struct PeerContext *peer_ctx = cls; | ||
667 | |||
668 | if (NULL != peer_ctx->liveliness_check_pending) | ||
669 | { | ||
670 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
671 | "Liveliness check for peer %s was successfull\n", | ||
672 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
673 | GNUNET_free (peer_ctx->liveliness_check_pending); | ||
674 | peer_ctx->liveliness_check_pending = NULL; | ||
675 | set_peer_live (peer_ctx); | ||
676 | } | ||
677 | } | ||
678 | |||
679 | /** | ||
680 | * Issue a check whether peer is live | ||
681 | * | ||
682 | * @param peer_ctx the context of the peer | ||
683 | */ | ||
684 | static void | ||
685 | check_peer_live (struct PeerContext *peer_ctx) | ||
686 | { | ||
687 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
688 | "Get informed about peer %s getting live\n", | ||
689 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
690 | |||
691 | struct GNUNET_MQ_Handle *mq; | ||
692 | struct GNUNET_MQ_Envelope *ev; | ||
693 | |||
694 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); | ||
695 | peer_ctx->liveliness_check_pending = GNUNET_new (struct PendingMessage); | ||
696 | peer_ctx->liveliness_check_pending->ev = ev; | ||
697 | peer_ctx->liveliness_check_pending->peer_ctx = peer_ctx; | ||
698 | peer_ctx->liveliness_check_pending->type = "Check liveliness"; | ||
699 | mq = get_mq (&peer_ctx->peer_id); | ||
700 | GNUNET_MQ_notify_sent (ev, | ||
701 | mq_liveliness_check_successful, | ||
702 | peer_ctx); | ||
703 | GNUNET_MQ_send (mq, ev); | ||
704 | } | ||
705 | |||
706 | /** | 732 | /** |
707 | * @brief Add an envelope to a message passed to mq to list of pending messages | 733 | * @brief Add an envelope to a message passed to mq to list of pending messages |
708 | * | 734 | * |
@@ -757,6 +783,54 @@ remove_pending_message (struct PendingMessage *pending_msg, int cancel) | |||
757 | 783 | ||
758 | 784 | ||
759 | /** | 785 | /** |
786 | * @brief This is called in response to the first message we sent as a | ||
787 | * liveliness check. | ||
788 | * | ||
789 | * @param cls #PeerContext of peer with pending liveliness check | ||
790 | */ | ||
791 | static void | ||
792 | mq_liveliness_check_successful (void *cls) | ||
793 | { | ||
794 | struct PeerContext *peer_ctx = cls; | ||
795 | |||
796 | if (NULL != peer_ctx->liveliness_check_pending) | ||
797 | { | ||
798 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
799 | "Liveliness check for peer %s was successfull\n", | ||
800 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
801 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); | ||
802 | peer_ctx->liveliness_check_pending = NULL; | ||
803 | set_peer_live (peer_ctx); | ||
804 | } | ||
805 | } | ||
806 | |||
807 | /** | ||
808 | * Issue a check whether peer is live | ||
809 | * | ||
810 | * @param peer_ctx the context of the peer | ||
811 | */ | ||
812 | static void | ||
813 | check_peer_live (struct PeerContext *peer_ctx) | ||
814 | { | ||
815 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
816 | "Get informed about peer %s getting live\n", | ||
817 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
818 | |||
819 | struct GNUNET_MQ_Handle *mq; | ||
820 | struct GNUNET_MQ_Envelope *ev; | ||
821 | |||
822 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); | ||
823 | peer_ctx->liveliness_check_pending = | ||
824 | insert_pending_message (&peer_ctx->peer_id, ev, "Check liveliness"); | ||
825 | mq = get_mq (&peer_ctx->peer_id); | ||
826 | GNUNET_MQ_notify_sent (ev, | ||
827 | mq_liveliness_check_successful, | ||
828 | peer_ctx); | ||
829 | GNUNET_MQ_send (mq, ev); | ||
830 | } | ||
831 | |||
832 | |||
833 | /** | ||
760 | * @brief Check whether function of type #PeerOp was already scheduled | 834 | * @brief Check whether function of type #PeerOp was already scheduled |
761 | * | 835 | * |
762 | * The array with pending operations will probably never grow really big, so | 836 | * The array with pending operations will probably never grow really big, so |
@@ -782,8 +856,155 @@ check_operation_scheduled (const struct GNUNET_PeerIdentity *peer, | |||
782 | return GNUNET_NO; | 856 | return GNUNET_NO; |
783 | } | 857 | } |
784 | 858 | ||
785 | int | 859 | |
786 | Peers_remove_peer (const struct GNUNET_PeerIdentity *peer); | 860 | /** |
861 | * @brief Callback for scheduler to destroy a channel | ||
862 | * | ||
863 | * @param cls Context of the channel | ||
864 | */ | ||
865 | static void | ||
866 | destroy_channel (struct ChannelCtx *channel_ctx) | ||
867 | { | ||
868 | struct GNUNET_CADET_Channel *channel; | ||
869 | |||
870 | if (NULL != channel_ctx->destruction_task) | ||
871 | { | ||
872 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); | ||
873 | channel_ctx->destruction_task = NULL; | ||
874 | } | ||
875 | GNUNET_assert (channel_ctx->channel != NULL); | ||
876 | channel = channel_ctx->channel; | ||
877 | channel_ctx->channel = NULL; | ||
878 | GNUNET_CADET_channel_destroy (channel); | ||
879 | remove_channel_ctx (channel_ctx); | ||
880 | } | ||
881 | |||
882 | |||
883 | /** | ||
884 | * @brief Destroy a cadet channel. | ||
885 | * | ||
886 | * This satisfies the function signature of #GNUNET_SCHEDULER_TaskCallback. | ||
887 | * | ||
888 | * @param cls | ||
889 | */ | ||
890 | static void | ||
891 | destroy_channel_cb (void *cls) | ||
892 | { | ||
893 | struct ChannelCtx *channel_ctx = cls; | ||
894 | |||
895 | channel_ctx->destruction_task = NULL; | ||
896 | destroy_channel (channel_ctx); | ||
897 | } | ||
898 | |||
899 | |||
900 | /** | ||
901 | * @brief Schedule the destruction of a channel for immediately afterwards. | ||
902 | * | ||
903 | * In case a channel is to be destroyed from within the callback to the | ||
904 | * destruction of another channel (send channel), we cannot call | ||
905 | * GNUNET_CADET_channel_destroy directly, but need to use this scheduling | ||
906 | * construction. | ||
907 | * | ||
908 | * @param channel_ctx channel to be destroyed. | ||
909 | */ | ||
910 | static void | ||
911 | schedule_channel_destruction (struct ChannelCtx *channel_ctx) | ||
912 | { | ||
913 | GNUNET_assert (NULL == | ||
914 | channel_ctx->destruction_task); | ||
915 | GNUNET_assert (NULL != | ||
916 | channel_ctx->channel); | ||
917 | channel_ctx->destruction_task = | ||
918 | GNUNET_SCHEDULER_add_now (&destroy_channel_cb, | ||
919 | channel_ctx); | ||
920 | } | ||
921 | |||
922 | |||
923 | /** | ||
924 | * @brief Remove peer | ||
925 | * | ||
926 | * @param peer the peer to clean | ||
927 | * @return #GNUNET_YES if peer was removed | ||
928 | * #GNUNET_NO otherwise | ||
929 | */ | ||
930 | static int | ||
931 | destroy_peer (struct PeerContext *peer_ctx) | ||
932 | { | ||
933 | GNUNET_assert (NULL != peer_ctx); | ||
934 | GNUNET_assert (NULL != peer_map); | ||
935 | if (GNUNET_NO == | ||
936 | GNUNET_CONTAINER_multipeermap_contains (peer_map, | ||
937 | &peer_ctx->peer_id)) | ||
938 | { | ||
939 | return GNUNET_NO; | ||
940 | } | ||
941 | SET_PEER_FLAG (peer_ctx, Peers_TO_DESTROY); | ||
942 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
943 | "Going to remove peer %s\n", | ||
944 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
945 | UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); | ||
946 | |||
947 | /* Clear list of pending operations */ | ||
948 | // TODO this probably leaks memory | ||
949 | // ('only' the cls to the function. Not sure what to do with it) | ||
950 | GNUNET_array_grow (peer_ctx->pending_ops, | ||
951 | peer_ctx->num_pending_ops, | ||
952 | 0); | ||
953 | /* Remove all pending messages */ | ||
954 | while (NULL != peer_ctx->pending_messages_head) | ||
955 | { | ||
956 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
957 | "Removing unsent %s\n", | ||
958 | peer_ctx->pending_messages_head->type); | ||
959 | /* Cancle pending message, too */ | ||
960 | if ( (NULL != peer_ctx->liveliness_check_pending) && | ||
961 | (0 == memcmp (peer_ctx->pending_messages_head, | ||
962 | peer_ctx->liveliness_check_pending, | ||
963 | sizeof (struct PendingMessage))) ) | ||
964 | { | ||
965 | // TODO this may leak memory | ||
966 | peer_ctx->liveliness_check_pending = NULL; | ||
967 | } | ||
968 | remove_pending_message (peer_ctx->pending_messages_head, | ||
969 | GNUNET_YES); | ||
970 | } | ||
971 | |||
972 | /* If we are still waiting for notification whether this peer is live | ||
973 | * cancel the according task */ | ||
974 | if (NULL != peer_ctx->liveliness_check_pending) | ||
975 | { | ||
976 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
977 | "Removing pending liveliness check for peer %s\n", | ||
978 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
979 | // TODO wait until cadet sets mq->cancel_impl | ||
980 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | ||
981 | remove_pending_message (peer_ctx->liveliness_check_pending, | ||
982 | GNUNET_YES); | ||
983 | peer_ctx->liveliness_check_pending = NULL; | ||
984 | } | ||
985 | |||
986 | if (NULL != peer_ctx->send_channel_ctx) | ||
987 | { | ||
988 | /* This is possibly called from within channel destruction */ | ||
989 | schedule_channel_destruction (peer_ctx->send_channel_ctx); | ||
990 | } | ||
991 | if (NULL != peer_ctx->recv_channel_ctx) | ||
992 | { | ||
993 | /* This is possibly called from within channel destruction */ | ||
994 | schedule_channel_destruction (peer_ctx->recv_channel_ctx); | ||
995 | } | ||
996 | |||
997 | if (GNUNET_YES != | ||
998 | GNUNET_CONTAINER_multipeermap_remove_all (peer_map, | ||
999 | &peer_ctx->peer_id)) | ||
1000 | { | ||
1001 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1002 | "removing peer from peer_map failed\n"); | ||
1003 | } | ||
1004 | GNUNET_free (peer_ctx); | ||
1005 | return GNUNET_YES; | ||
1006 | } | ||
1007 | |||
787 | 1008 | ||
788 | /** | 1009 | /** |
789 | * Iterator over hash map entries. Deletes all contexts of peers. | 1010 | * Iterator over hash map entries. Deletes all contexts of peers. |
@@ -799,7 +1020,7 @@ peermap_clear_iterator (void *cls, | |||
799 | const struct GNUNET_PeerIdentity *key, | 1020 | const struct GNUNET_PeerIdentity *key, |
800 | void *value) | 1021 | void *value) |
801 | { | 1022 | { |
802 | Peers_remove_peer (key); | 1023 | destroy_peer (get_peer_ctx (key)); |
803 | return GNUNET_YES; | 1024 | return GNUNET_YES; |
804 | } | 1025 | } |
805 | 1026 | ||
@@ -1043,14 +1264,12 @@ restore_valid_peers () | |||
1043 | * @param cadet_h cadet handle | 1264 | * @param cadet_h cadet handle |
1044 | * @param own_id own peer identity | 1265 | * @param own_id own peer identity |
1045 | */ | 1266 | */ |
1046 | void | 1267 | static void |
1047 | Peers_initialise (char* fn_valid_peers, | 1268 | initialise_peers (char* fn_valid_peers, |
1048 | struct GNUNET_CADET_Handle *cadet_h, | 1269 | struct GNUNET_CADET_Handle *cadet_h) |
1049 | const struct GNUNET_PeerIdentity *own_id) | ||
1050 | { | 1270 | { |
1051 | filename_valid_peers = GNUNET_strdup (fn_valid_peers); | 1271 | filename_valid_peers = GNUNET_strdup (fn_valid_peers); |
1052 | cadet_handle = cadet_h; | 1272 | cadet_handle = cadet_h; |
1053 | own_identity = *own_id; | ||
1054 | peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 1273 | peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
1055 | valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 1274 | valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
1056 | restore_valid_peers (); | 1275 | restore_valid_peers (); |
@@ -1058,14 +1277,14 @@ Peers_initialise (char* fn_valid_peers, | |||
1058 | 1277 | ||
1059 | 1278 | ||
1060 | /** | 1279 | /** |
1061 | * @brief Delete storage of peers that was created with #Peers_initialise () | 1280 | * @brief Delete storage of peers that was created with #initialise_peers () |
1062 | */ | 1281 | */ |
1063 | void | 1282 | static void |
1064 | Peers_terminate () | 1283 | peers_terminate () |
1065 | { | 1284 | { |
1066 | if (GNUNET_SYSERR == | 1285 | if (GNUNET_SYSERR == |
1067 | GNUNET_CONTAINER_multipeermap_iterate (peer_map, | 1286 | GNUNET_CONTAINER_multipeermap_iterate (peer_map, |
1068 | peermap_clear_iterator, | 1287 | &peermap_clear_iterator, |
1069 | NULL)) | 1288 | NULL)) |
1070 | { | 1289 | { |
1071 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1290 | LOG (GNUNET_ERROR_TYPE_WARNING, |
@@ -1075,7 +1294,9 @@ Peers_terminate () | |||
1075 | peer_map = NULL; | 1294 | peer_map = NULL; |
1076 | store_valid_peers (); | 1295 | store_valid_peers (); |
1077 | GNUNET_free (filename_valid_peers); | 1296 | GNUNET_free (filename_valid_peers); |
1297 | filename_valid_peers = NULL; | ||
1078 | GNUNET_CONTAINER_multipeermap_destroy (valid_peers); | 1298 | GNUNET_CONTAINER_multipeermap_destroy (valid_peers); |
1299 | valid_peers = NULL; | ||
1079 | } | 1300 | } |
1080 | 1301 | ||
1081 | 1302 | ||
@@ -1109,9 +1330,9 @@ valid_peer_iterator (void *cls, | |||
1109 | * @return the number of key value pairs processed, | 1330 | * @return the number of key value pairs processed, |
1110 | * #GNUNET_SYSERR if it aborted iteration | 1331 | * #GNUNET_SYSERR if it aborted iteration |
1111 | */ | 1332 | */ |
1112 | int | 1333 | static int |
1113 | Peers_get_valid_peers (PeersIterator iterator, | 1334 | get_valid_peers (PeersIterator iterator, |
1114 | void *it_cls) | 1335 | void *it_cls) |
1115 | { | 1336 | { |
1116 | struct PeersIteratorCls *cls; | 1337 | struct PeersIteratorCls *cls; |
1117 | int ret; | 1338 | int ret; |
@@ -1136,14 +1357,12 @@ Peers_get_valid_peers (PeersIterator iterator, | |||
1136 | * @param peer the new #GNUNET_PeerIdentity | 1357 | * @param peer the new #GNUNET_PeerIdentity |
1137 | * | 1358 | * |
1138 | * @return #GNUNET_YES if peer was inserted | 1359 | * @return #GNUNET_YES if peer was inserted |
1139 | * #GNUNET_NO otherwise (if peer was already known or | 1360 | * #GNUNET_NO otherwise |
1140 | * peer was #own_identity) | ||
1141 | */ | 1361 | */ |
1142 | int | 1362 | static int |
1143 | Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) | 1363 | insert_peer (const struct GNUNET_PeerIdentity *peer) |
1144 | { | 1364 | { |
1145 | if ( (GNUNET_YES == Peers_check_peer_known (peer)) || | 1365 | if (GNUNET_YES == check_peer_known (peer)) |
1146 | (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) ) | ||
1147 | { | 1366 | { |
1148 | return GNUNET_NO; /* We already know this peer - nothing to do */ | 1367 | return GNUNET_NO; /* We already know this peer - nothing to do */ |
1149 | } | 1368 | } |
@@ -1151,8 +1370,30 @@ Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) | |||
1151 | return GNUNET_YES; | 1370 | return GNUNET_YES; |
1152 | } | 1371 | } |
1153 | 1372 | ||
1154 | int | 1373 | |
1155 | Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags); | 1374 | /** |
1375 | * @brief Check whether flags on a peer are set. | ||
1376 | * | ||
1377 | * @param peer the peer to check the flag of | ||
1378 | * @param flags the flags to check | ||
1379 | * | ||
1380 | * @return #GNUNET_SYSERR if peer is not known | ||
1381 | * #GNUNET_YES if all given flags are set | ||
1382 | * #GNUNET_NO otherwise | ||
1383 | */ | ||
1384 | static int | ||
1385 | check_peer_flag (const struct GNUNET_PeerIdentity *peer, | ||
1386 | enum Peers_PeerFlags flags) | ||
1387 | { | ||
1388 | struct PeerContext *peer_ctx; | ||
1389 | |||
1390 | if (GNUNET_NO == check_peer_known (peer)) | ||
1391 | { | ||
1392 | return GNUNET_SYSERR; | ||
1393 | } | ||
1394 | peer_ctx = get_peer_ctx (peer); | ||
1395 | return check_peer_flag_set (peer_ctx, flags); | ||
1396 | } | ||
1156 | 1397 | ||
1157 | /** | 1398 | /** |
1158 | * @brief Try connecting to a peer to see whether it is online | 1399 | * @brief Try connecting to a peer to see whether it is online |
@@ -1161,22 +1402,18 @@ Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl | |||
1161 | * | 1402 | * |
1162 | * @param peer the peer whose liveliness is to be checked | 1403 | * @param peer the peer whose liveliness is to be checked |
1163 | * @return #GNUNET_YES if peer had to be inserted | 1404 | * @return #GNUNET_YES if peer had to be inserted |
1164 | * #GNUNET_NO otherwise (if peer was already known or | 1405 | * #GNUNET_NO otherwise |
1165 | * peer was #own_identity) | ||
1166 | */ | 1406 | */ |
1167 | int | 1407 | static int |
1168 | Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) | 1408 | issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) |
1169 | { | 1409 | { |
1170 | struct PeerContext *peer_ctx; | 1410 | struct PeerContext *peer_ctx; |
1171 | int ret; | 1411 | int ret; |
1172 | 1412 | ||
1173 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) | 1413 | ret = insert_peer (peer); |
1174 | { | ||
1175 | return GNUNET_NO; | ||
1176 | } | ||
1177 | ret = Peers_insert_peer (peer); | ||
1178 | peer_ctx = get_peer_ctx (peer); | 1414 | peer_ctx = get_peer_ctx (peer); |
1179 | if (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) | 1415 | if ( (GNUNET_NO == check_peer_flag (peer, Peers_ONLINE)) && |
1416 | (NULL == peer_ctx->liveliness_check_pending) ) | ||
1180 | { | 1417 | { |
1181 | check_peer_live (peer_ctx); | 1418 | check_peer_live (peer_ctx); |
1182 | } | 1419 | } |
@@ -1197,8 +1434,8 @@ Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) | |||
1197 | * #GNUNET_NO if peer is NOT removable | 1434 | * #GNUNET_NO if peer is NOT removable |
1198 | * #GNUNET_SYSERR if peer is not known | 1435 | * #GNUNET_SYSERR if peer is not known |
1199 | */ | 1436 | */ |
1200 | int | 1437 | static int |
1201 | Peers_check_removable (const struct GNUNET_PeerIdentity *peer) | 1438 | check_removable (const struct GNUNET_PeerIdentity *peer) |
1202 | { | 1439 | { |
1203 | struct PeerContext *peer_ctx; | 1440 | struct PeerContext *peer_ctx; |
1204 | 1441 | ||
@@ -1208,7 +1445,7 @@ Peers_check_removable (const struct GNUNET_PeerIdentity *peer) | |||
1208 | } | 1445 | } |
1209 | 1446 | ||
1210 | peer_ctx = get_peer_ctx (peer); | 1447 | peer_ctx = get_peer_ctx (peer); |
1211 | if ( (NULL != peer_ctx->recv_channel) || | 1448 | if ( (NULL != peer_ctx->recv_channel_ctx) || |
1212 | (NULL != peer_ctx->pending_messages_head) || | 1449 | (NULL != peer_ctx->pending_messages_head) || |
1213 | (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) ) | 1450 | (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) ) |
1214 | { | 1451 | { |
@@ -1217,239 +1454,6 @@ Peers_check_removable (const struct GNUNET_PeerIdentity *peer) | |||
1217 | return GNUNET_YES; | 1454 | return GNUNET_YES; |
1218 | } | 1455 | } |
1219 | 1456 | ||
1220 | uint32_t * | ||
1221 | Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer, | ||
1222 | enum Peers_ChannelRole role); | ||
1223 | |||
1224 | int | ||
1225 | Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags); | ||
1226 | |||
1227 | /** | ||
1228 | * @brief Remove peer | ||
1229 | * | ||
1230 | * @param peer the peer to clean | ||
1231 | * @return #GNUNET_YES if peer was removed | ||
1232 | * #GNUNET_NO otherwise | ||
1233 | */ | ||
1234 | int | ||
1235 | Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | ||
1236 | { | ||
1237 | struct PeerContext *peer_ctx; | ||
1238 | uint32_t *channel_flag; | ||
1239 | |||
1240 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) | ||
1241 | { | ||
1242 | return GNUNET_NO; | ||
1243 | } | ||
1244 | |||
1245 | peer_ctx = get_peer_ctx (peer); | ||
1246 | set_peer_flag (peer_ctx, Peers_TO_DESTROY); | ||
1247 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1248 | "Going to remove peer %s\n", | ||
1249 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
1250 | Peers_unset_peer_flag (peer, Peers_ONLINE); | ||
1251 | |||
1252 | GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); | ||
1253 | while (NULL != peer_ctx->pending_messages_head) | ||
1254 | { | ||
1255 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1256 | "Removing unsent %s\n", | ||
1257 | peer_ctx->pending_messages_head->type); | ||
1258 | /* Cancle pending message, too */ | ||
1259 | remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES); | ||
1260 | } | ||
1261 | /* If we are still waiting for notification whether this peer is live | ||
1262 | * cancel the according task */ | ||
1263 | if (NULL != peer_ctx->liveliness_check_pending) | ||
1264 | { | ||
1265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1266 | "Removing pending liveliness check for peer %s\n", | ||
1267 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
1268 | // TODO wait until cadet sets mq->cancel_impl | ||
1269 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | ||
1270 | GNUNET_free (peer_ctx->liveliness_check_pending); | ||
1271 | peer_ctx->liveliness_check_pending = NULL; | ||
1272 | } | ||
1273 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING); | ||
1274 | if (NULL != peer_ctx->send_channel && | ||
1275 | GNUNET_YES != Peers_check_channel_flag (channel_flag, Peers_CHANNEL_DESTROING)) | ||
1276 | { | ||
1277 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1278 | "Destroying send channel\n"); | ||
1279 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); | ||
1280 | peer_ctx->send_channel = NULL; | ||
1281 | peer_ctx->mq = NULL; | ||
1282 | } | ||
1283 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_RECEIVING); | ||
1284 | if (NULL != peer_ctx->recv_channel && | ||
1285 | GNUNET_YES != Peers_check_channel_flag (channel_flag, Peers_CHANNEL_DESTROING)) | ||
1286 | { | ||
1287 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1288 | "Destroying recv channel\n"); | ||
1289 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); | ||
1290 | peer_ctx->recv_channel = NULL; | ||
1291 | } | ||
1292 | |||
1293 | GNUNET_free (peer_ctx->send_channel_flags); | ||
1294 | GNUNET_free (peer_ctx->recv_channel_flags); | ||
1295 | |||
1296 | if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove_all (peer_map, &peer_ctx->peer_id)) | ||
1297 | { | ||
1298 | LOG (GNUNET_ERROR_TYPE_WARNING, "removing peer from peer_map failed\n"); | ||
1299 | } | ||
1300 | GNUNET_free (peer_ctx); | ||
1301 | return GNUNET_YES; | ||
1302 | } | ||
1303 | |||
1304 | |||
1305 | /** | ||
1306 | * @brief set flags on a given peer. | ||
1307 | * | ||
1308 | * @param peer the peer to set flags on | ||
1309 | * @param flags the flags | ||
1310 | */ | ||
1311 | void | ||
1312 | Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags) | ||
1313 | { | ||
1314 | struct PeerContext *peer_ctx; | ||
1315 | |||
1316 | peer_ctx = get_peer_ctx (peer); | ||
1317 | set_peer_flag (peer_ctx, flags); | ||
1318 | } | ||
1319 | |||
1320 | |||
1321 | /** | ||
1322 | * @brief unset flags on a given peer. | ||
1323 | * | ||
1324 | * @param peer the peer to unset flags on | ||
1325 | * @param flags the flags | ||
1326 | */ | ||
1327 | void | ||
1328 | Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags) | ||
1329 | { | ||
1330 | struct PeerContext *peer_ctx; | ||
1331 | |||
1332 | peer_ctx = get_peer_ctx (peer); | ||
1333 | unset_peer_flag (peer_ctx, flags); | ||
1334 | } | ||
1335 | |||
1336 | |||
1337 | /** | ||
1338 | * @brief Check whether flags on a peer are set. | ||
1339 | * | ||
1340 | * @param peer the peer to check the flag of | ||
1341 | * @param flags the flags to check | ||
1342 | * | ||
1343 | * @return #GNUNET_SYSERR if peer is not known | ||
1344 | * #GNUNET_YES if all given flags are set | ||
1345 | * #GNUNET_NO otherwise | ||
1346 | */ | ||
1347 | int | ||
1348 | Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags) | ||
1349 | { | ||
1350 | struct PeerContext *peer_ctx; | ||
1351 | |||
1352 | if (GNUNET_NO == Peers_check_peer_known (peer)) | ||
1353 | { | ||
1354 | return GNUNET_SYSERR; | ||
1355 | } | ||
1356 | peer_ctx = get_peer_ctx (peer); | ||
1357 | return check_peer_flag_set (peer_ctx, flags); | ||
1358 | } | ||
1359 | |||
1360 | |||
1361 | /** | ||
1362 | * @brief set flags on a given channel. | ||
1363 | * | ||
1364 | * @param channel the channel to set flags on | ||
1365 | * @param flags the flags | ||
1366 | */ | ||
1367 | void | ||
1368 | Peers_set_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags) | ||
1369 | { | ||
1370 | set_channel_flag (channel_flags, flags); | ||
1371 | } | ||
1372 | |||
1373 | |||
1374 | /** | ||
1375 | * @brief unset flags on a given channel. | ||
1376 | * | ||
1377 | * @param channel the channel to unset flags on | ||
1378 | * @param flags the flags | ||
1379 | */ | ||
1380 | void | ||
1381 | Peers_unset_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags) | ||
1382 | { | ||
1383 | unset_channel_flag (channel_flags, flags); | ||
1384 | } | ||
1385 | |||
1386 | |||
1387 | /** | ||
1388 | * @brief Check whether flags on a channel are set. | ||
1389 | * | ||
1390 | * @param channel the channel to check the flag of | ||
1391 | * @param flags the flags to check | ||
1392 | * | ||
1393 | * @return #GNUNET_YES if all given flags are set | ||
1394 | * #GNUNET_NO otherwise | ||
1395 | */ | ||
1396 | int | ||
1397 | Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags) | ||
1398 | { | ||
1399 | return check_channel_flag_set (channel_flags, flags); | ||
1400 | } | ||
1401 | |||
1402 | /** | ||
1403 | * @brief Get the flags for the channel in @a role for @a peer. | ||
1404 | * | ||
1405 | * @param peer Peer to get the channel flags for. | ||
1406 | * @param role Role of channel to get flags for | ||
1407 | * | ||
1408 | * @return The flags. | ||
1409 | */ | ||
1410 | uint32_t * | ||
1411 | Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer, | ||
1412 | enum Peers_ChannelRole role) | ||
1413 | { | ||
1414 | const struct PeerContext *peer_ctx; | ||
1415 | |||
1416 | peer_ctx = get_peer_ctx (peer); | ||
1417 | if (Peers_CHANNEL_ROLE_SENDING == role) | ||
1418 | { | ||
1419 | return peer_ctx->send_channel_flags; | ||
1420 | } | ||
1421 | else if (Peers_CHANNEL_ROLE_RECEIVING == role) | ||
1422 | { | ||
1423 | return peer_ctx->recv_channel_flags; | ||
1424 | } | ||
1425 | else | ||
1426 | { | ||
1427 | GNUNET_assert (0); | ||
1428 | } | ||
1429 | } | ||
1430 | |||
1431 | /** | ||
1432 | * @brief Check whether we have information about the given peer. | ||
1433 | * | ||
1434 | * FIXME probably deprecated. Make this the new _online. | ||
1435 | * | ||
1436 | * @param peer peer in question | ||
1437 | * | ||
1438 | * @return #GNUNET_YES if peer is known | ||
1439 | * #GNUNET_NO if peer is not knwon | ||
1440 | */ | ||
1441 | int | ||
1442 | Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer) | ||
1443 | { | ||
1444 | if (NULL != peer_map) | ||
1445 | { | ||
1446 | return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); | ||
1447 | } else | ||
1448 | { | ||
1449 | return GNUNET_NO; | ||
1450 | } | ||
1451 | } | ||
1452 | |||
1453 | 1457 | ||
1454 | /** | 1458 | /** |
1455 | * @brief Check whether @a peer is actually a peer. | 1459 | * @brief Check whether @a peer is actually a peer. |
@@ -1461,8 +1465,8 @@ Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer) | |||
1461 | * @return #GNUNET_YES if peer is valid | 1465 | * @return #GNUNET_YES if peer is valid |
1462 | * #GNUNET_NO if peer is not valid | 1466 | * #GNUNET_NO if peer is not valid |
1463 | */ | 1467 | */ |
1464 | int | 1468 | static int |
1465 | Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer) | 1469 | check_peer_valid (const struct GNUNET_PeerIdentity *peer) |
1466 | { | 1470 | { |
1467 | return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); | 1471 | return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); |
1468 | } | 1472 | } |
@@ -1475,10 +1479,10 @@ Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer) | |||
1475 | * | 1479 | * |
1476 | * @param peer the peer to establish channel to | 1480 | * @param peer the peer to establish channel to |
1477 | */ | 1481 | */ |
1478 | void | 1482 | static void |
1479 | Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer) | 1483 | indicate_sending_intention (const struct GNUNET_PeerIdentity *peer) |
1480 | { | 1484 | { |
1481 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | 1485 | GNUNET_assert (GNUNET_YES == check_peer_known (peer)); |
1482 | (void) get_channel (peer); | 1486 | (void) get_channel (peer); |
1483 | } | 1487 | } |
1484 | 1488 | ||
@@ -1492,13 +1496,13 @@ Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer) | |||
1492 | * @return #GNUNET_YES if peer has the intention to send | 1496 | * @return #GNUNET_YES if peer has the intention to send |
1493 | * #GNUNET_NO otherwise | 1497 | * #GNUNET_NO otherwise |
1494 | */ | 1498 | */ |
1495 | int | 1499 | static int |
1496 | Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) | 1500 | check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) |
1497 | { | 1501 | { |
1498 | const struct PeerContext *peer_ctx; | 1502 | const struct PeerContext *peer_ctx; |
1499 | 1503 | ||
1500 | peer_ctx = get_peer_ctx (peer); | 1504 | peer_ctx = get_peer_ctx (peer); |
1501 | if (NULL != peer_ctx->recv_channel) | 1505 | if (NULL != peer_ctx->recv_channel_ctx) |
1502 | { | 1506 | { |
1503 | return GNUNET_YES; | 1507 | return GNUNET_YES; |
1504 | } | 1508 | } |
@@ -1516,13 +1520,14 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) | |||
1516 | * @return initial channel context for the channel | 1520 | * @return initial channel context for the channel |
1517 | * (can be NULL -- that's not an error) | 1521 | * (can be NULL -- that's not an error) |
1518 | */ | 1522 | */ |
1519 | void * | 1523 | static void * |
1520 | Peers_handle_inbound_channel (void *cls, | 1524 | handle_inbound_channel (void *cls, |
1521 | struct GNUNET_CADET_Channel *channel, | 1525 | struct GNUNET_CADET_Channel *channel, |
1522 | const struct GNUNET_PeerIdentity *initiator) | 1526 | const struct GNUNET_PeerIdentity *initiator) |
1523 | { | 1527 | { |
1524 | struct PeerContext *peer_ctx; | 1528 | struct PeerContext *peer_ctx; |
1525 | struct GNUNET_PeerIdentity *ctx_peer; | 1529 | struct GNUNET_PeerIdentity *ctx_peer; |
1530 | struct ChannelCtx *channel_ctx; | ||
1526 | 1531 | ||
1527 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1532 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1528 | "New channel was established to us (Peer %s).\n", | 1533 | "New channel was established to us (Peer %s).\n", |
@@ -1533,19 +1538,21 @@ Peers_handle_inbound_channel (void *cls, | |||
1533 | set_peer_live (peer_ctx); | 1538 | set_peer_live (peer_ctx); |
1534 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); | 1539 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); |
1535 | *ctx_peer = *initiator; | 1540 | *ctx_peer = *initiator; |
1541 | channel_ctx = add_channel_ctx (peer_ctx); | ||
1542 | channel_ctx->channel = channel; | ||
1536 | /* We only accept one incoming channel per peer */ | 1543 | /* We only accept one incoming channel per peer */ |
1537 | if (GNUNET_YES == Peers_check_peer_send_intention (initiator)) | 1544 | if (GNUNET_YES == check_peer_send_intention (initiator)) |
1538 | { | 1545 | { |
1539 | set_channel_flag (peer_ctx->recv_channel_flags, | 1546 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1540 | Peers_CHANNEL_ESTABLISHED_TWICE); | 1547 | "Already got one receive channel. Destroying old one.\n"); |
1541 | //GNUNET_CADET_channel_destroy (channel); | 1548 | GNUNET_break_op (0); |
1542 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); | 1549 | destroy_channel (peer_ctx->recv_channel_ctx); |
1543 | peer_ctx->recv_channel = channel; | 1550 | peer_ctx->recv_channel_ctx = channel_ctx; |
1544 | /* return the channel context */ | 1551 | /* return the channel context */ |
1545 | return ctx_peer; | 1552 | return channel_ctx; |
1546 | } | 1553 | } |
1547 | peer_ctx->recv_channel = channel; | 1554 | peer_ctx->recv_channel_ctx = channel_ctx; |
1548 | return ctx_peer; | 1555 | return channel_ctx; |
1549 | } | 1556 | } |
1550 | 1557 | ||
1551 | 1558 | ||
@@ -1557,17 +1564,17 @@ Peers_handle_inbound_channel (void *cls, | |||
1557 | * @return #GNUNET_YES if a sending channel towards that peer exists | 1564 | * @return #GNUNET_YES if a sending channel towards that peer exists |
1558 | * #GNUNET_NO otherwise | 1565 | * #GNUNET_NO otherwise |
1559 | */ | 1566 | */ |
1560 | int | 1567 | static int |
1561 | Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) | 1568 | check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) |
1562 | { | 1569 | { |
1563 | struct PeerContext *peer_ctx; | 1570 | struct PeerContext *peer_ctx; |
1564 | 1571 | ||
1565 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 1572 | if (GNUNET_NO == check_peer_known (peer)) |
1566 | { /* If no such peer exists, there is no channel */ | 1573 | { /* If no such peer exists, there is no channel */ |
1567 | return GNUNET_NO; | 1574 | return GNUNET_NO; |
1568 | } | 1575 | } |
1569 | peer_ctx = get_peer_ctx (peer); | 1576 | peer_ctx = get_peer_ctx (peer); |
1570 | if (NULL == peer_ctx->send_channel) | 1577 | if (NULL == peer_ctx->send_channel_ctx) |
1571 | { | 1578 | { |
1572 | return GNUNET_NO; | 1579 | return GNUNET_NO; |
1573 | } | 1580 | } |
@@ -1576,44 +1583,6 @@ Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) | |||
1576 | 1583 | ||
1577 | 1584 | ||
1578 | /** | 1585 | /** |
1579 | * @brief check whether the given channel is the sending channel of the given | ||
1580 | * peer | ||
1581 | * | ||
1582 | * @param peer the peer in question | ||
1583 | * @param channel the channel to check for | ||
1584 | * @param role either #Peers_CHANNEL_ROLE_SENDING, or | ||
1585 | * #Peers_CHANNEL_ROLE_RECEIVING | ||
1586 | * | ||
1587 | * @return #GNUNET_YES if the given chennel is the sending channel of the peer | ||
1588 | * #GNUNET_NO otherwise | ||
1589 | */ | ||
1590 | int | ||
1591 | Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer, | ||
1592 | const struct GNUNET_CADET_Channel *channel, | ||
1593 | enum Peers_ChannelRole role) | ||
1594 | { | ||
1595 | const struct PeerContext *peer_ctx; | ||
1596 | |||
1597 | if (GNUNET_NO == Peers_check_peer_known (peer)) | ||
1598 | { | ||
1599 | return GNUNET_NO; | ||
1600 | } | ||
1601 | peer_ctx = get_peer_ctx (peer); | ||
1602 | if ( (Peers_CHANNEL_ROLE_SENDING == role) && | ||
1603 | (channel == peer_ctx->send_channel) ) | ||
1604 | { | ||
1605 | return GNUNET_YES; | ||
1606 | } | ||
1607 | if ( (Peers_CHANNEL_ROLE_RECEIVING == role) && | ||
1608 | (channel == peer_ctx->recv_channel) ) | ||
1609 | { | ||
1610 | return GNUNET_YES; | ||
1611 | } | ||
1612 | return GNUNET_NO; | ||
1613 | } | ||
1614 | |||
1615 | |||
1616 | /** | ||
1617 | * @brief Destroy the send channel of a peer e.g. stop indicating a sending | 1586 | * @brief Destroy the send channel of a peer e.g. stop indicating a sending |
1618 | * intention to another peer | 1587 | * intention to another peer |
1619 | * | 1588 | * |
@@ -1625,114 +1594,26 @@ Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer, | |||
1625 | * @return #GNUNET_YES if channel was destroyed | 1594 | * @return #GNUNET_YES if channel was destroyed |
1626 | * #GNUNET_NO otherwise | 1595 | * #GNUNET_NO otherwise |
1627 | */ | 1596 | */ |
1628 | int | 1597 | static int |
1629 | Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer) | 1598 | destroy_sending_channel (const struct GNUNET_PeerIdentity *peer) |
1630 | { | 1599 | { |
1631 | struct PeerContext *peer_ctx; | 1600 | struct PeerContext *peer_ctx; |
1632 | 1601 | ||
1633 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 1602 | if (GNUNET_NO == check_peer_known (peer)) |
1634 | { | 1603 | { |
1635 | return GNUNET_NO; | 1604 | return GNUNET_NO; |
1636 | } | 1605 | } |
1637 | peer_ctx = get_peer_ctx (peer); | 1606 | peer_ctx = get_peer_ctx (peer); |
1638 | if (NULL != peer_ctx->send_channel) | 1607 | if (NULL != peer_ctx->send_channel_ctx) |
1639 | { | 1608 | { |
1640 | set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_CLEAN); | 1609 | destroy_channel (peer_ctx->send_channel_ctx); |
1641 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); | 1610 | (void) check_connected (peer); |
1642 | peer_ctx->send_channel = NULL; | ||
1643 | peer_ctx->mq = NULL; | ||
1644 | (void) Peers_check_connected (peer); | ||
1645 | return GNUNET_YES; | 1611 | return GNUNET_YES; |
1646 | } | 1612 | } |
1647 | return GNUNET_NO; | 1613 | return GNUNET_NO; |
1648 | } | 1614 | } |
1649 | 1615 | ||
1650 | /** | 1616 | /** |
1651 | * This is called when a channel is destroyed. | ||
1652 | * | ||
1653 | * @param cls The closure | ||
1654 | * @param channel The channel being closed | ||
1655 | */ | ||
1656 | void | ||
1657 | Peers_cleanup_destroyed_channel (void *cls, | ||
1658 | const struct GNUNET_CADET_Channel *channel) | ||
1659 | { | ||
1660 | struct GNUNET_PeerIdentity *peer = cls; | ||
1661 | struct PeerContext *peer_ctx; | ||
1662 | |||
1663 | if (GNUNET_NO == Peers_check_peer_known (peer)) | ||
1664 | {/* We don't want to implicitly create a context that we're about to kill */ | ||
1665 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1666 | "channel (%s) without associated context was destroyed\n", | ||
1667 | GNUNET_i2s (peer)); | ||
1668 | return; | ||
1669 | } | ||
1670 | peer_ctx = get_peer_ctx (peer); | ||
1671 | |||
1672 | /* If our peer issued the destruction of the channel, the #Peers_TO_DESTROY | ||
1673 | * flag will be set. In this case simply make sure that the channels are | ||
1674 | * cleaned. */ | ||
1675 | /* FIXME This distinction seems to be redundant */ | ||
1676 | if (Peers_check_peer_flag (peer, Peers_TO_DESTROY)) | ||
1677 | {/* We initiatad the destruction of this particular peer */ | ||
1678 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1679 | "Peer is in the process of being destroyed\n"); | ||
1680 | if (channel == peer_ctx->send_channel) | ||
1681 | { | ||
1682 | peer_ctx->send_channel = NULL; | ||
1683 | peer_ctx->mq = NULL; | ||
1684 | } | ||
1685 | else if (channel == peer_ctx->recv_channel) | ||
1686 | { | ||
1687 | peer_ctx->recv_channel = NULL; | ||
1688 | } | ||
1689 | |||
1690 | if (NULL != peer_ctx->send_channel) | ||
1691 | { | ||
1692 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); | ||
1693 | peer_ctx->send_channel = NULL; | ||
1694 | peer_ctx->mq = NULL; | ||
1695 | } | ||
1696 | if (NULL != peer_ctx->recv_channel) | ||
1697 | { | ||
1698 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); | ||
1699 | peer_ctx->recv_channel = NULL; | ||
1700 | } | ||
1701 | /* Set the #Peers_ONLINE flag accordingly */ | ||
1702 | (void) Peers_check_connected (peer); | ||
1703 | return; | ||
1704 | } | ||
1705 | |||
1706 | else | ||
1707 | { /* We did not initiate the destruction of this peer */ | ||
1708 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1709 | "Peer is NOT in the process of being destroyed\n"); | ||
1710 | if (channel == peer_ctx->send_channel) | ||
1711 | { /* Something (but us) killd the channel - clean up peer */ | ||
1712 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1713 | "send channel (%s) was destroyed - cleaning up\n", | ||
1714 | GNUNET_i2s (peer)); | ||
1715 | peer_ctx->send_channel = NULL; | ||
1716 | peer_ctx->mq = NULL; | ||
1717 | } | ||
1718 | else if (channel == peer_ctx->recv_channel) | ||
1719 | { /* Other peer doesn't want to send us messages anymore */ | ||
1720 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1721 | "Peer %s destroyed recv channel - cleaning up channel\n", | ||
1722 | GNUNET_i2s (peer)); | ||
1723 | peer_ctx->recv_channel = NULL; | ||
1724 | } | ||
1725 | else | ||
1726 | { | ||
1727 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1728 | "unknown channel (%s) was destroyed\n", | ||
1729 | GNUNET_i2s (peer)); | ||
1730 | } | ||
1731 | } | ||
1732 | (void) Peers_check_connected (peer); | ||
1733 | } | ||
1734 | |||
1735 | /** | ||
1736 | * @brief Send a message to another peer. | 1617 | * @brief Send a message to another peer. |
1737 | * | 1618 | * |
1738 | * Keeps track about pending messages so they can be properly removed when the | 1619 | * Keeps track about pending messages so they can be properly removed when the |
@@ -1742,10 +1623,10 @@ Peers_cleanup_destroyed_channel (void *cls, | |||
1742 | * @param ev envelope of the message | 1623 | * @param ev envelope of the message |
1743 | * @param type type of the message | 1624 | * @param type type of the message |
1744 | */ | 1625 | */ |
1745 | void | 1626 | static void |
1746 | Peers_send_message (const struct GNUNET_PeerIdentity *peer, | 1627 | send_message (const struct GNUNET_PeerIdentity *peer, |
1747 | struct GNUNET_MQ_Envelope *ev, | 1628 | struct GNUNET_MQ_Envelope *ev, |
1748 | const char *type) | 1629 | const char *type) |
1749 | { | 1630 | { |
1750 | struct PendingMessage *pending_msg; | 1631 | struct PendingMessage *pending_msg; |
1751 | struct GNUNET_MQ_Handle *mq; | 1632 | struct GNUNET_MQ_Handle *mq; |
@@ -1772,18 +1653,14 @@ Peers_send_message (const struct GNUNET_PeerIdentity *peer, | |||
1772 | * @return #GNUNET_YES if the operation was scheduled | 1653 | * @return #GNUNET_YES if the operation was scheduled |
1773 | * #GNUNET_NO otherwise | 1654 | * #GNUNET_NO otherwise |
1774 | */ | 1655 | */ |
1775 | int | 1656 | static int |
1776 | Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer, | 1657 | schedule_operation (const struct GNUNET_PeerIdentity *peer, |
1777 | const PeerOp peer_op) | 1658 | const PeerOp peer_op) |
1778 | { | 1659 | { |
1779 | struct PeerPendingOp pending_op; | 1660 | struct PeerPendingOp pending_op; |
1780 | struct PeerContext *peer_ctx; | 1661 | struct PeerContext *peer_ctx; |
1781 | 1662 | ||
1782 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) | 1663 | GNUNET_assert (GNUNET_YES == check_peer_known (peer)); |
1783 | { | ||
1784 | return GNUNET_NO; | ||
1785 | } | ||
1786 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | ||
1787 | 1664 | ||
1788 | //TODO if LIVE/ONLINE execute immediately | 1665 | //TODO if LIVE/ONLINE execute immediately |
1789 | 1666 | ||
@@ -1800,24 +1677,6 @@ Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer, | |||
1800 | return GNUNET_NO; | 1677 | return GNUNET_NO; |
1801 | } | 1678 | } |
1802 | 1679 | ||
1803 | /** | ||
1804 | * @brief Get the recv_channel of @a peer. | ||
1805 | * Needed to correctly handle (call #GNUNET_CADET_receive_done()) incoming | ||
1806 | * messages. | ||
1807 | * | ||
1808 | * @param peer The peer to get the recv_channel from. | ||
1809 | * | ||
1810 | * @return The recv_channel. | ||
1811 | */ | ||
1812 | struct GNUNET_CADET_Channel * | ||
1813 | Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer) | ||
1814 | { | ||
1815 | struct PeerContext *peer_ctx; | ||
1816 | |||
1817 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | ||
1818 | peer_ctx = get_peer_ctx (peer); | ||
1819 | return peer_ctx->recv_channel; | ||
1820 | } | ||
1821 | /*********************************************************************** | 1680 | /*********************************************************************** |
1822 | * /Old gnunet-service-rps_peers.c | 1681 | * /Old gnunet-service-rps_peers.c |
1823 | ***********************************************************************/ | 1682 | ***********************************************************************/ |
@@ -2273,16 +2132,16 @@ insert_in_view (const struct GNUNET_PeerIdentity *peer) | |||
2273 | { | 2132 | { |
2274 | int online; | 2133 | int online; |
2275 | 2134 | ||
2276 | online = Peers_check_peer_flag (peer, Peers_ONLINE); | 2135 | online = check_peer_flag (peer, Peers_ONLINE); |
2277 | if ( (GNUNET_NO == online) || | 2136 | if ( (GNUNET_NO == online) || |
2278 | (GNUNET_SYSERR == online) ) /* peer is not even known */ | 2137 | (GNUNET_SYSERR == online) ) /* peer is not even known */ |
2279 | { | 2138 | { |
2280 | (void) Peers_issue_peer_liveliness_check (peer); | 2139 | (void) issue_peer_liveliness_check (peer); |
2281 | (void) Peers_schedule_operation (peer, insert_in_view_op); | 2140 | (void) schedule_operation (peer, insert_in_view_op); |
2282 | return GNUNET_NO; | 2141 | return GNUNET_NO; |
2283 | } | 2142 | } |
2284 | /* Open channel towards peer to keep connection open */ | 2143 | /* Open channel towards peer to keep connection open */ |
2285 | Peers_indicate_sending_intention (peer); | 2144 | indicate_sending_intention (peer); |
2286 | return View_put (peer); | 2145 | return View_put (peer); |
2287 | } | 2146 | } |
2288 | 2147 | ||
@@ -2475,8 +2334,11 @@ send_pull_reply (const struct GNUNET_PeerIdentity *peer_id, | |||
2475 | GNUNET_memcpy (&out_msg[1], peer_ids, | 2334 | GNUNET_memcpy (&out_msg[1], peer_ids, |
2476 | send_size * sizeof (struct GNUNET_PeerIdentity)); | 2335 | send_size * sizeof (struct GNUNET_PeerIdentity)); |
2477 | 2336 | ||
2478 | Peers_send_message (peer_id, ev, "PULL REPLY"); | 2337 | send_message (peer_id, ev, "PULL REPLY"); |
2479 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); | 2338 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); |
2339 | // TODO check with send intention: as send_channel is used/opened we indicate | ||
2340 | // a sending intention without intending it. | ||
2341 | // -> clean peer afterwards? | ||
2480 | } | 2342 | } |
2481 | 2343 | ||
2482 | 2344 | ||
@@ -2523,10 +2385,10 @@ insert_in_sampler (void *cls, | |||
2523 | if (0 < RPS_sampler_count_id (prot_sampler, peer)) | 2385 | if (0 < RPS_sampler_count_id (prot_sampler, peer)) |
2524 | { | 2386 | { |
2525 | /* Make sure we 'know' about this peer */ | 2387 | /* Make sure we 'know' about this peer */ |
2526 | (void) Peers_issue_peer_liveliness_check (peer); | 2388 | (void) issue_peer_liveliness_check (peer); |
2527 | /* Establish a channel towards that peer to indicate we are going to send | 2389 | /* Establish a channel towards that peer to indicate we are going to send |
2528 | * messages to it */ | 2390 | * messages to it */ |
2529 | //Peers_indicate_sending_intention (peer); | 2391 | //indicate_sending_intention (peer); |
2530 | } | 2392 | } |
2531 | #ifdef TO_FILE | 2393 | #ifdef TO_FILE |
2532 | num_observed_peers++; | 2394 | num_observed_peers++; |
@@ -2558,10 +2420,10 @@ static void | |||
2558 | got_peer (const struct GNUNET_PeerIdentity *peer) | 2420 | got_peer (const struct GNUNET_PeerIdentity *peer) |
2559 | { | 2421 | { |
2560 | /* If we did not know this peer already, insert it into sampler and view */ | 2422 | /* If we did not know this peer already, insert it into sampler and view */ |
2561 | if (GNUNET_YES == Peers_issue_peer_liveliness_check (peer)) | 2423 | if (GNUNET_YES == issue_peer_liveliness_check (peer)) |
2562 | { | 2424 | { |
2563 | Peers_schedule_operation (peer, insert_in_sampler); | 2425 | schedule_operation (peer, insert_in_sampler); |
2564 | Peers_schedule_operation (peer, insert_in_view_op); | 2426 | schedule_operation (peer, insert_in_view_op); |
2565 | } | 2427 | } |
2566 | } | 2428 | } |
2567 | 2429 | ||
@@ -2576,17 +2438,17 @@ static int | |||
2576 | check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer) | 2438 | check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer) |
2577 | { | 2439 | { |
2578 | /* struct GNUNET_CADET_Channel *channel; */ | 2440 | /* struct GNUNET_CADET_Channel *channel; */ |
2579 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 2441 | if (GNUNET_NO == check_peer_known (peer)) |
2580 | { | 2442 | { |
2581 | return GNUNET_NO; | 2443 | return GNUNET_NO; |
2582 | } | 2444 | } |
2583 | if (GNUNET_YES == Peers_check_sending_channel_exists (peer)) | 2445 | if (GNUNET_YES == check_sending_channel_exists (peer)) |
2584 | { | 2446 | { |
2585 | if ( (0 < RPS_sampler_count_id (prot_sampler, peer)) || | 2447 | if ( (0 < RPS_sampler_count_id (prot_sampler, peer)) || |
2586 | (GNUNET_YES == View_contains_peer (peer)) || | 2448 | (GNUNET_YES == View_contains_peer (peer)) || |
2587 | (GNUNET_YES == CustomPeerMap_contains_peer (push_map, peer)) || | 2449 | (GNUNET_YES == CustomPeerMap_contains_peer (push_map, peer)) || |
2588 | (GNUNET_YES == CustomPeerMap_contains_peer (pull_map, peer)) || | 2450 | (GNUNET_YES == CustomPeerMap_contains_peer (pull_map, peer)) || |
2589 | (GNUNET_YES == Peers_check_peer_flag (peer, Peers_PULL_REPLY_PENDING))) | 2451 | (GNUNET_YES == check_peer_flag (peer, Peers_PULL_REPLY_PENDING))) |
2590 | { /* If we want to keep the connection to peer open */ | 2452 | { /* If we want to keep the connection to peer open */ |
2591 | return GNUNET_YES; | 2453 | return GNUNET_YES; |
2592 | } | 2454 | } |
@@ -2609,7 +2471,7 @@ remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
2609 | CustomPeerMap_remove_peer (push_map, peer); | 2471 | CustomPeerMap_remove_peer (push_map, peer); |
2610 | RPS_sampler_reinitialise_by_value (prot_sampler, peer); | 2472 | RPS_sampler_reinitialise_by_value (prot_sampler, peer); |
2611 | RPS_sampler_reinitialise_by_value (client_sampler, peer); | 2473 | RPS_sampler_reinitialise_by_value (client_sampler, peer); |
2612 | Peers_remove_peer (peer); | 2474 | destroy_peer (get_peer_ctx (peer)); |
2613 | } | 2475 | } |
2614 | 2476 | ||
2615 | 2477 | ||
@@ -2630,19 +2492,19 @@ clean_peer (const struct GNUNET_PeerIdentity *peer) | |||
2630 | GNUNET_i2s (peer)); | 2492 | GNUNET_i2s (peer)); |
2631 | #ifdef ENABLE_MALICIOUS | 2493 | #ifdef ENABLE_MALICIOUS |
2632 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer)) | 2494 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer)) |
2633 | (void) Peers_destroy_sending_channel (peer); | 2495 | (void) destroy_sending_channel (peer); |
2634 | #else /* ENABLE_MALICIOUS */ | 2496 | #else /* ENABLE_MALICIOUS */ |
2635 | (void) Peers_destroy_sending_channel (peer); | 2497 | (void) destroy_sending_channel (peer); |
2636 | #endif /* ENABLE_MALICIOUS */ | 2498 | #endif /* ENABLE_MALICIOUS */ |
2637 | } | 2499 | } |
2638 | 2500 | ||
2639 | if ( (GNUNET_NO == Peers_check_peer_send_intention (peer)) && | 2501 | if ( (GNUNET_NO == check_peer_send_intention (peer)) && |
2640 | (GNUNET_NO == View_contains_peer (peer)) && | 2502 | (GNUNET_NO == View_contains_peer (peer)) && |
2641 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && | 2503 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && |
2642 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && | 2504 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && |
2643 | (0 == RPS_sampler_count_id (prot_sampler, peer)) && | 2505 | (0 == RPS_sampler_count_id (prot_sampler, peer)) && |
2644 | (0 == RPS_sampler_count_id (client_sampler, peer)) && | 2506 | (0 == RPS_sampler_count_id (client_sampler, peer)) && |
2645 | (GNUNET_NO != Peers_check_removable (peer)) ) | 2507 | (GNUNET_NO != check_removable (peer)) ) |
2646 | { /* We can safely remove this peer */ | 2508 | { /* We can safely remove this peer */ |
2647 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2509 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2648 | "Going to remove peer %s\n", | 2510 | "Going to remove peer %s\n", |
@@ -2652,6 +2514,7 @@ clean_peer (const struct GNUNET_PeerIdentity *peer) | |||
2652 | } | 2514 | } |
2653 | } | 2515 | } |
2654 | 2516 | ||
2517 | |||
2655 | /** | 2518 | /** |
2656 | * @brief This is called when a channel is destroyed. | 2519 | * @brief This is called when a channel is destroyed. |
2657 | * | 2520 | * |
@@ -2668,105 +2531,23 @@ static void | |||
2668 | cleanup_destroyed_channel (void *cls, | 2531 | cleanup_destroyed_channel (void *cls, |
2669 | const struct GNUNET_CADET_Channel *channel) | 2532 | const struct GNUNET_CADET_Channel *channel) |
2670 | { | 2533 | { |
2671 | struct GNUNET_PeerIdentity *peer = cls; | 2534 | struct ChannelCtx *channel_ctx = cls; |
2672 | uint32_t *channel_flag; | 2535 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
2673 | struct PeerContext *peer_ctx; | 2536 | |
2674 | 2537 | // What should be done here: | |
2675 | GNUNET_assert (NULL != peer); | 2538 | // * cleanup everything related to the channel |
2676 | 2539 | // * memory | |
2677 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 2540 | // * remove peer if necessary |
2678 | { /* We don't know a context to that peer */ | 2541 | channel_ctx->channel = NULL; |
2679 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2542 | if (peer_ctx->recv_channel_ctx == channel_ctx) |
2680 | "channel (%s) without associated context was destroyed\n", | ||
2681 | GNUNET_i2s (peer)); | ||
2682 | GNUNET_free (peer); | ||
2683 | return; | ||
2684 | } | ||
2685 | |||
2686 | peer_ctx = get_peer_ctx (peer); | ||
2687 | if (GNUNET_YES == Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_RECEIVING)) | ||
2688 | { | 2543 | { |
2689 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2544 | remove_channel_ctx (channel_ctx); |
2690 | "Callback on destruction of recv-channel was called (%s)\n", | ||
2691 | GNUNET_i2s (peer)); | ||
2692 | set_channel_flag (peer_ctx->recv_channel_flags, Peers_CHANNEL_DESTROING); | ||
2693 | } else if (GNUNET_YES == Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_SENDING)) | ||
2694 | { | ||
2695 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2696 | "Callback on destruction of send-channel was called (%s)\n", | ||
2697 | GNUNET_i2s (peer)); | ||
2698 | set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_DESTROING); | ||
2699 | } else { | ||
2700 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2701 | "Channel to be destroyed has is neither sending nor receiving role\n"); | ||
2702 | } | ||
2703 | |||
2704 | if (GNUNET_YES == Peers_check_peer_flag (peer, Peers_TO_DESTROY)) | ||
2705 | { /* We are in the middle of removing that peer from our knowledge. In this | ||
2706 | case simply make sure that the channels are cleaned. */ | ||
2707 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2708 | to_file (file_name_view_log, | ||
2709 | "-%s\t(cleanup channel, ourself)", | ||
2710 | GNUNET_i2s_full (peer)); | ||
2711 | GNUNET_free (peer); | ||
2712 | return; | ||
2713 | } | ||
2714 | |||
2715 | if (GNUNET_YES == | ||
2716 | Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_SENDING)) | ||
2717 | { /* Channel used for sending was destroyed */ | ||
2718 | /* Possible causes of channel destruction: | ||
2719 | * - ourselves -> cleaning send channel -> clean context | ||
2720 | * - other peer -> peer probably went down -> remove | ||
2721 | */ | ||
2722 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING); | ||
2723 | if (GNUNET_YES == Peers_check_channel_flag (channel_flag, Peers_CHANNEL_CLEAN)) | ||
2724 | { /* We are about to clean the sending channel. Clean the respective | ||
2725 | * context */ | ||
2726 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2727 | GNUNET_free (peer); | ||
2728 | return; | ||
2729 | } | ||
2730 | else | ||
2731 | { /* Other peer destroyed our sending channel that he is supposed to keep | ||
2732 | * open. It probably went down. Remove it from our knowledge. */ | ||
2733 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2734 | remove_peer (peer); | ||
2735 | GNUNET_free (peer); | ||
2736 | return; | ||
2737 | } | ||
2738 | } | 2545 | } |
2739 | else if (GNUNET_YES == | 2546 | else if (peer_ctx->send_channel_ctx == channel_ctx) |
2740 | Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_RECEIVING)) | ||
2741 | { /* Channel used for receiving was destroyed */ | ||
2742 | /* Possible causes of channel destruction: | ||
2743 | * - ourselves -> peer tried to establish channel twice -> clean context | ||
2744 | * - other peer -> peer doesn't want to send us data -> clean | ||
2745 | */ | ||
2746 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_RECEIVING); | ||
2747 | if (GNUNET_YES == | ||
2748 | Peers_check_channel_flag (channel_flag, Peers_CHANNEL_ESTABLISHED_TWICE)) | ||
2749 | { /* Other peer tried to establish a channel to us twice. We do not accept | ||
2750 | * that. Clean the context. */ | ||
2751 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2752 | GNUNET_free (peer); | ||
2753 | return; | ||
2754 | } | ||
2755 | else | ||
2756 | { /* Other peer doesn't want to send us data anymore. We are free to clean | ||
2757 | * it. */ | ||
2758 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2759 | clean_peer (peer); | ||
2760 | GNUNET_free (peer); | ||
2761 | return; | ||
2762 | } | ||
2763 | } | ||
2764 | else | ||
2765 | { | 2547 | { |
2766 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2548 | remove_channel_ctx (channel_ctx); |
2767 | "Destroyed channel is neither sending nor receiving channel\n"); | 2549 | remove_peer (&peer_ctx->peer_id); |
2768 | } | 2550 | } |
2769 | GNUNET_free (peer); | ||
2770 | } | 2551 | } |
2771 | 2552 | ||
2772 | /*********************************************************************** | 2553 | /*********************************************************************** |
@@ -2893,7 +2674,6 @@ client_respond (void *cls, | |||
2893 | GNUNET_memcpy (&out_msg[1], | 2674 | GNUNET_memcpy (&out_msg[1], |
2894 | peer_ids, | 2675 | peer_ids, |
2895 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 2676 | num_peers * sizeof (struct GNUNET_PeerIdentity)); |
2896 | GNUNET_free (peer_ids); | ||
2897 | 2677 | ||
2898 | cli_ctx = reply_cls->cli_ctx; | 2678 | cli_ctx = reply_cls->cli_ctx; |
2899 | GNUNET_assert (NULL != cli_ctx); | 2679 | GNUNET_assert (NULL != cli_ctx); |
@@ -3026,8 +2806,6 @@ handle_client_seed (void *cls, | |||
3026 | 2806 | ||
3027 | num_peers = ntohl (msg->num_peers); | 2807 | num_peers = ntohl (msg->num_peers); |
3028 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 2808 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
3029 | //peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | ||
3030 | //GNUNET_memcpy (peers, &msg[1], num_peers * sizeof (struct GNUNET_PeerIdentity)); | ||
3031 | 2809 | ||
3032 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2810 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3033 | "Client seeded peers:\n"); | 2811 | "Client seeded peers:\n"); |
@@ -3042,9 +2820,6 @@ handle_client_seed (void *cls, | |||
3042 | 2820 | ||
3043 | got_peer (&peers[i]); | 2821 | got_peer (&peers[i]); |
3044 | } | 2822 | } |
3045 | |||
3046 | ////GNUNET_free (peers); | ||
3047 | |||
3048 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 2823 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
3049 | } | 2824 | } |
3050 | 2825 | ||
@@ -3162,12 +2937,12 @@ static void | |||
3162 | handle_peer_check (void *cls, | 2937 | handle_peer_check (void *cls, |
3163 | const struct GNUNET_MessageHeader *msg) | 2938 | const struct GNUNET_MessageHeader *msg) |
3164 | { | 2939 | { |
3165 | const struct GNUNET_PeerIdentity *peer = cls; | 2940 | const struct ChannelCtx *channel_ctx = cls; |
2941 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | ||
3166 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2942 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3167 | "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); | 2943 | "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); |
3168 | 2944 | ||
3169 | GNUNET_break_op (Peers_check_peer_known (peer)); | 2945 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3170 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); | ||
3171 | } | 2946 | } |
3172 | 2947 | ||
3173 | /** | 2948 | /** |
@@ -3183,7 +2958,8 @@ static void | |||
3183 | handle_peer_push (void *cls, | 2958 | handle_peer_push (void *cls, |
3184 | const struct GNUNET_MessageHeader *msg) | 2959 | const struct GNUNET_MessageHeader *msg) |
3185 | { | 2960 | { |
3186 | const struct GNUNET_PeerIdentity *peer = cls; | 2961 | const struct ChannelCtx *channel_ctx = cls; |
2962 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | ||
3187 | 2963 | ||
3188 | // (check the proof of work (?)) | 2964 | // (check the proof of work (?)) |
3189 | 2965 | ||
@@ -3211,6 +2987,10 @@ handle_peer_push (void *cls, | |||
3211 | tmp_att_peer); | 2987 | tmp_att_peer); |
3212 | add_peer_array_to_set (peer, 1, att_peer_set); | 2988 | add_peer_array_to_set (peer, 1, att_peer_set); |
3213 | } | 2989 | } |
2990 | else | ||
2991 | { | ||
2992 | GNUNET_free (tmp_att_peer); | ||
2993 | } | ||
3214 | } | 2994 | } |
3215 | 2995 | ||
3216 | 2996 | ||
@@ -3223,8 +3003,8 @@ handle_peer_push (void *cls, | |||
3223 | /* Add the sending peer to the push_map */ | 3003 | /* Add the sending peer to the push_map */ |
3224 | CustomPeerMap_put (push_map, peer); | 3004 | CustomPeerMap_put (push_map, peer); |
3225 | 3005 | ||
3226 | GNUNET_break_op (Peers_check_peer_known (peer)); | 3006 | GNUNET_break_op (check_peer_known (peer)); |
3227 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); | 3007 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3228 | } | 3008 | } |
3229 | 3009 | ||
3230 | 3010 | ||
@@ -3240,7 +3020,8 @@ static void | |||
3240 | handle_peer_pull_request (void *cls, | 3020 | handle_peer_pull_request (void *cls, |
3241 | const struct GNUNET_MessageHeader *msg) | 3021 | const struct GNUNET_MessageHeader *msg) |
3242 | { | 3022 | { |
3243 | struct GNUNET_PeerIdentity *peer = cls; | 3023 | const struct ChannelCtx *channel_ctx = cls; |
3024 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | ||
3244 | const struct GNUNET_PeerIdentity *view_array; | 3025 | const struct GNUNET_PeerIdentity *view_array; |
3245 | 3026 | ||
3246 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); | 3027 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); |
@@ -3262,8 +3043,8 @@ handle_peer_pull_request (void *cls, | |||
3262 | } | 3043 | } |
3263 | #endif /* ENABLE_MALICIOUS */ | 3044 | #endif /* ENABLE_MALICIOUS */ |
3264 | 3045 | ||
3265 | GNUNET_break_op (Peers_check_peer_known (peer)); | 3046 | GNUNET_break_op (check_peer_known (peer)); |
3266 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); | 3047 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3267 | view_array = View_get_as_array (); | 3048 | view_array = View_get_as_array (); |
3268 | send_pull_reply (peer, view_array, View_size ()); | 3049 | send_pull_reply (peer, view_array, View_size ()); |
3269 | } | 3050 | } |
@@ -3300,10 +3081,11 @@ check_peer_pull_reply (void *cls, | |||
3300 | return GNUNET_SYSERR; | 3081 | return GNUNET_SYSERR; |
3301 | } | 3082 | } |
3302 | 3083 | ||
3303 | if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) | 3084 | if (GNUNET_YES != check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) |
3304 | { | 3085 | { |
3305 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3086 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3306 | "Received a pull reply from a peer we didn't request one from!\n"); | 3087 | "Received a pull reply from a peer (%s) we didn't request one from!\n", |
3088 | GNUNET_i2s (sender)); | ||
3307 | GNUNET_break_op (0); | 3089 | GNUNET_break_op (0); |
3308 | return GNUNET_SYSERR; | 3090 | return GNUNET_SYSERR; |
3309 | } | 3091 | } |
@@ -3320,8 +3102,9 @@ static void | |||
3320 | handle_peer_pull_reply (void *cls, | 3102 | handle_peer_pull_reply (void *cls, |
3321 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) | 3103 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) |
3322 | { | 3104 | { |
3105 | const struct ChannelCtx *channel_ctx = cls; | ||
3106 | const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id; | ||
3323 | const struct GNUNET_PeerIdentity *peers; | 3107 | const struct GNUNET_PeerIdentity *peers; |
3324 | struct GNUNET_PeerIdentity *sender = cls; | ||
3325 | uint32_t i; | 3108 | uint32_t i; |
3326 | #ifdef ENABLE_MALICIOUS | 3109 | #ifdef ENABLE_MALICIOUS |
3327 | struct AttackedPeer *tmp_att_peer; | 3110 | struct AttackedPeer *tmp_att_peer; |
@@ -3359,9 +3142,7 @@ handle_peer_pull_reply (void *cls, | |||
3359 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, | 3142 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, |
3360 | &peers[i]) | 3143 | &peers[i]) |
3361 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, | 3144 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, |
3362 | &peers[i]) | 3145 | &peers[i])) |
3363 | && 0 != GNUNET_CRYPTO_cmp_peer_identity (&peers[i], | ||
3364 | &own_identity)) | ||
3365 | { | 3146 | { |
3366 | tmp_att_peer = GNUNET_new (struct AttackedPeer); | 3147 | tmp_att_peer = GNUNET_new (struct AttackedPeer); |
3367 | tmp_att_peer->peer_id = peers[i]; | 3148 | tmp_att_peer->peer_id = peers[i]; |
@@ -3373,29 +3154,25 @@ handle_peer_pull_reply (void *cls, | |||
3373 | continue; | 3154 | continue; |
3374 | } | 3155 | } |
3375 | #endif /* ENABLE_MALICIOUS */ | 3156 | #endif /* ENABLE_MALICIOUS */ |
3376 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, | 3157 | /* Make sure we 'know' about this peer */ |
3377 | &peers[i])) | 3158 | (void) insert_peer (&peers[i]); |
3378 | { | ||
3379 | /* Make sure we 'know' about this peer */ | ||
3380 | (void) Peers_insert_peer (&peers[i]); | ||
3381 | 3159 | ||
3382 | if (GNUNET_YES == Peers_check_peer_valid (&peers[i])) | 3160 | if (GNUNET_YES == check_peer_valid (&peers[i])) |
3383 | { | 3161 | { |
3384 | CustomPeerMap_put (pull_map, &peers[i]); | 3162 | CustomPeerMap_put (pull_map, &peers[i]); |
3385 | } | 3163 | } |
3386 | else | 3164 | else |
3387 | { | 3165 | { |
3388 | Peers_schedule_operation (&peers[i], insert_in_pull_map); | 3166 | schedule_operation (&peers[i], insert_in_pull_map); |
3389 | (void) Peers_issue_peer_liveliness_check (&peers[i]); | 3167 | (void) issue_peer_liveliness_check (&peers[i]); |
3390 | } | ||
3391 | } | 3168 | } |
3392 | } | 3169 | } |
3393 | 3170 | ||
3394 | Peers_unset_peer_flag (sender, Peers_PULL_REPLY_PENDING); | 3171 | UNSET_PEER_FLAG (get_peer_ctx (sender), Peers_PULL_REPLY_PENDING); |
3395 | clean_peer (sender); | 3172 | clean_peer (sender); |
3396 | 3173 | ||
3397 | GNUNET_break_op (Peers_check_peer_known (sender)); | 3174 | GNUNET_break_op (check_peer_known (sender)); |
3398 | GNUNET_CADET_receive_done (Peers_get_recv_channel (sender)); | 3175 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3399 | } | 3176 | } |
3400 | 3177 | ||
3401 | 3178 | ||
@@ -3458,16 +3235,16 @@ send_pull_request (const struct GNUNET_PeerIdentity *peer) | |||
3458 | { | 3235 | { |
3459 | struct GNUNET_MQ_Envelope *ev; | 3236 | struct GNUNET_MQ_Envelope *ev; |
3460 | 3237 | ||
3461 | GNUNET_assert (GNUNET_NO == Peers_check_peer_flag (peer, | 3238 | GNUNET_assert (GNUNET_NO == check_peer_flag (peer, |
3462 | Peers_PULL_REPLY_PENDING)); | 3239 | Peers_PULL_REPLY_PENDING)); |
3463 | Peers_set_peer_flag (peer, Peers_PULL_REPLY_PENDING); | 3240 | SET_PEER_FLAG (get_peer_ctx (peer), Peers_PULL_REPLY_PENDING); |
3464 | 3241 | ||
3465 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3242 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3466 | "Going to send PULL REQUEST to peer %s.\n", | 3243 | "Going to send PULL REQUEST to peer %s.\n", |
3467 | GNUNET_i2s (peer)); | 3244 | GNUNET_i2s (peer)); |
3468 | 3245 | ||
3469 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); | 3246 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); |
3470 | Peers_send_message (peer, ev, "PULL REQUEST"); | 3247 | send_message (peer, ev, "PULL REQUEST"); |
3471 | GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO); | 3248 | GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO); |
3472 | } | 3249 | } |
3473 | 3250 | ||
@@ -3487,7 +3264,7 @@ send_push (const struct GNUNET_PeerIdentity *peer_id) | |||
3487 | GNUNET_i2s (peer_id)); | 3264 | GNUNET_i2s (peer_id)); |
3488 | 3265 | ||
3489 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); | 3266 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); |
3490 | Peers_send_message (peer_id, ev, "PUSH"); | 3267 | send_message (peer_id, ev, "PUSH"); |
3491 | GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO); | 3268 | GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO); |
3492 | } | 3269 | } |
3493 | 3270 | ||
@@ -3589,6 +3366,7 @@ handle_client_act_malicious (void *cls, | |||
3589 | 3366 | ||
3590 | num_mal_peers_sent = ntohl (msg->num_peers) - 1; | 3367 | num_mal_peers_sent = ntohl (msg->num_peers) - 1; |
3591 | num_mal_peers_old = num_mal_peers; | 3368 | num_mal_peers_old = num_mal_peers; |
3369 | GNUNET_assert (GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent); | ||
3592 | GNUNET_array_grow (mal_peers, | 3370 | GNUNET_array_grow (mal_peers, |
3593 | num_mal_peers, | 3371 | num_mal_peers, |
3594 | num_mal_peers + num_mal_peers_sent); | 3372 | num_mal_peers + num_mal_peers_sent); |
@@ -3610,9 +3388,9 @@ handle_client_act_malicious (void *cls, | |||
3610 | &msg->attacked_peer, | 3388 | &msg->attacked_peer, |
3611 | sizeof (struct GNUNET_PeerIdentity)); | 3389 | sizeof (struct GNUNET_PeerIdentity)); |
3612 | /* Set the flag of the attacked peer to valid to avoid problems */ | 3390 | /* Set the flag of the attacked peer to valid to avoid problems */ |
3613 | if (GNUNET_NO == Peers_check_peer_known (&attacked_peer)) | 3391 | if (GNUNET_NO == check_peer_known (&attacked_peer)) |
3614 | { | 3392 | { |
3615 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3393 | (void) issue_peer_liveliness_check (&attacked_peer); |
3616 | } | 3394 | } |
3617 | 3395 | ||
3618 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3396 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -3702,8 +3480,8 @@ do_mal_round (void *cls) | |||
3702 | * Send as many pushes to the attacked peer as possible | 3480 | * Send as many pushes to the attacked peer as possible |
3703 | * That is one push per round as it will ignore more. | 3481 | * That is one push per round as it will ignore more. |
3704 | */ | 3482 | */ |
3705 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3483 | (void) issue_peer_liveliness_check (&attacked_peer); |
3706 | if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_ONLINE)) | 3484 | if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE)) |
3707 | send_push (&attacked_peer); | 3485 | send_push (&attacked_peer); |
3708 | } | 3486 | } |
3709 | 3487 | ||
@@ -3712,10 +3490,10 @@ do_mal_round (void *cls) | |||
3712 | { /* Combined attack */ | 3490 | { /* Combined attack */ |
3713 | 3491 | ||
3714 | /* Send PUSH to attacked peers */ | 3492 | /* Send PUSH to attacked peers */ |
3715 | if (GNUNET_YES == Peers_check_peer_known (&attacked_peer)) | 3493 | if (GNUNET_YES == check_peer_known (&attacked_peer)) |
3716 | { | 3494 | { |
3717 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3495 | (void) issue_peer_liveliness_check (&attacked_peer); |
3718 | if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_ONLINE)) | 3496 | if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE)) |
3719 | { | 3497 | { |
3720 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3498 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3721 | "Goding to send push to attacked peer (%s)\n", | 3499 | "Goding to send push to attacked peer (%s)\n", |
@@ -3723,7 +3501,7 @@ do_mal_round (void *cls) | |||
3723 | send_push (&attacked_peer); | 3501 | send_push (&attacked_peer); |
3724 | } | 3502 | } |
3725 | } | 3503 | } |
3726 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3504 | (void) issue_peer_liveliness_check (&attacked_peer); |
3727 | 3505 | ||
3728 | /* The maximum of pushes we're going to send this round */ | 3506 | /* The maximum of pushes we're going to send this round */ |
3729 | num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, | 3507 | num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, |
@@ -3821,10 +3599,8 @@ do_round (void *cls) | |||
3821 | for (i = 0; i < a_peers; i++) | 3599 | for (i = 0; i < a_peers; i++) |
3822 | { | 3600 | { |
3823 | peer = view_array[permut[i]]; | 3601 | peer = view_array[permut[i]]; |
3824 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) // TODO | 3602 | // FIXME if this fails schedule/loop this for later |
3825 | { // FIXME if this fails schedule/loop this for later | 3603 | send_push (&peer); |
3826 | send_push (&peer); | ||
3827 | } | ||
3828 | } | 3604 | } |
3829 | 3605 | ||
3830 | /* Send PULL requests */ | 3606 | /* Send PULL requests */ |
@@ -3842,8 +3618,7 @@ do_round (void *cls) | |||
3842 | for (i = first_border; i < second_border; i++) | 3618 | for (i = first_border; i < second_border; i++) |
3843 | { | 3619 | { |
3844 | peer = view_array[permut[i]]; | 3620 | peer = view_array[permut[i]]; |
3845 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer) && | 3621 | if ( GNUNET_NO == check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) |
3846 | GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) // TODO | ||
3847 | { // FIXME if this fails schedule/loop this for later | 3622 | { // FIXME if this fails schedule/loop this for later |
3848 | send_pull_request (&peer); | 3623 | send_pull_request (&peer); |
3849 | } | 3624 | } |
@@ -3940,7 +3715,6 @@ do_round (void *cls) | |||
3940 | "-%s", | 3715 | "-%s", |
3941 | GNUNET_i2s_full (&peers_to_clean[i])); | 3716 | GNUNET_i2s_full (&peers_to_clean[i])); |
3942 | clean_peer (&peers_to_clean[i]); | 3717 | clean_peer (&peers_to_clean[i]); |
3943 | //peer_destroy_channel_send (sender); | ||
3944 | } | 3718 | } |
3945 | 3719 | ||
3946 | GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0); | 3720 | GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0); |
@@ -3996,7 +3770,6 @@ do_round (void *cls) | |||
3996 | GNUNET_i2s (update_peer)); | 3770 | GNUNET_i2s (update_peer)); |
3997 | insert_in_sampler (NULL, update_peer); | 3771 | insert_in_sampler (NULL, update_peer); |
3998 | clean_peer (update_peer); /* This cleans only if it is not in the view */ | 3772 | clean_peer (update_peer); /* This cleans only if it is not in the view */ |
3999 | //peer_destroy_channel_send (sender); | ||
4000 | } | 3773 | } |
4001 | 3774 | ||
4002 | for (i = 0; i < CustomPeerMap_size (pull_map); i++) | 3775 | for (i = 0; i < CustomPeerMap_size (pull_map); i++) |
@@ -4007,7 +3780,6 @@ do_round (void *cls) | |||
4007 | insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i)); | 3780 | insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i)); |
4008 | /* This cleans only if it is not in the view */ | 3781 | /* This cleans only if it is not in the view */ |
4009 | clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i)); | 3782 | clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i)); |
4010 | //peer_destroy_channel_send (sender); | ||
4011 | } | 3783 | } |
4012 | 3784 | ||
4013 | 3785 | ||
@@ -4110,6 +3882,8 @@ shutdown_task (void *cls) | |||
4110 | struct ClientContext *client_ctx; | 3882 | struct ClientContext *client_ctx; |
4111 | struct ReplyCls *reply_cls; | 3883 | struct ReplyCls *reply_cls; |
4112 | 3884 | ||
3885 | in_shutdown = GNUNET_YES; | ||
3886 | |||
4113 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3887 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4114 | "RPS is going down\n"); | 3888 | "RPS is going down\n"); |
4115 | 3889 | ||
@@ -4129,42 +3903,48 @@ shutdown_task (void *cls) | |||
4129 | reply_cls); | 3903 | reply_cls); |
4130 | GNUNET_free (reply_cls); | 3904 | GNUNET_free (reply_cls); |
4131 | } | 3905 | } |
4132 | GNUNET_CONTAINER_DLL_remove (cli_ctx_head, cli_ctx_tail, client_ctx); | 3906 | GNUNET_CONTAINER_DLL_remove (cli_ctx_head, |
3907 | cli_ctx_tail, | ||
3908 | client_ctx); | ||
4133 | GNUNET_free (client_ctx); | 3909 | GNUNET_free (client_ctx); |
4134 | } | 3910 | } |
4135 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle); | 3911 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle); |
4136 | GNUNET_PEERINFO_disconnect (peerinfo_handle); | 3912 | GNUNET_PEERINFO_disconnect (peerinfo_handle); |
4137 | 3913 | peerinfo_handle = NULL; | |
4138 | if (NULL != do_round_task) | 3914 | if (NULL != do_round_task) |
4139 | { | 3915 | { |
4140 | GNUNET_SCHEDULER_cancel (do_round_task); | 3916 | GNUNET_SCHEDULER_cancel (do_round_task); |
4141 | do_round_task = NULL; | 3917 | do_round_task = NULL; |
4142 | } | 3918 | } |
4143 | 3919 | ||
4144 | Peers_terminate (); | 3920 | peers_terminate (); |
4145 | 3921 | ||
4146 | GNUNET_NSE_disconnect (nse); | 3922 | GNUNET_NSE_disconnect (nse); |
4147 | RPS_sampler_destroy (prot_sampler); | 3923 | RPS_sampler_destroy (prot_sampler); |
4148 | RPS_sampler_destroy (client_sampler); | 3924 | RPS_sampler_destroy (client_sampler); |
4149 | GNUNET_CADET_close_port (cadet_port); | 3925 | GNUNET_CADET_close_port (cadet_port); |
4150 | GNUNET_CADET_disconnect (cadet_handle); | 3926 | GNUNET_CADET_disconnect (cadet_handle); |
3927 | cadet_handle = NULL; | ||
4151 | View_destroy (); | 3928 | View_destroy (); |
4152 | CustomPeerMap_destroy (push_map); | 3929 | CustomPeerMap_destroy (push_map); |
4153 | CustomPeerMap_destroy (pull_map); | 3930 | CustomPeerMap_destroy (pull_map); |
4154 | if (NULL != stats) | 3931 | if (NULL != stats) |
4155 | { | 3932 | { |
4156 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 3933 | GNUNET_STATISTICS_destroy (stats, |
3934 | GNUNET_NO); | ||
4157 | stats = NULL; | 3935 | stats = NULL; |
4158 | } | 3936 | } |
4159 | #ifdef ENABLE_MALICIOUS | 3937 | #ifdef ENABLE_MALICIOUS |
4160 | struct AttackedPeer *tmp_att_peer; | 3938 | struct AttackedPeer *tmp_att_peer; |
4161 | /* it is ok to free this const during shutdown: */ | 3939 | /* it is ok to free this const during shutdown: */ |
4162 | GNUNET_free ((char *) file_name_view_log); | 3940 | GNUNET_free ((char *) file_name_view_log); |
4163 | #ifdef TO_FILE | 3941 | #ifdef TO_FILE |
4164 | GNUNET_free ((char *) file_name_observed_log); | 3942 | GNUNET_free ((char *) file_name_observed_log); |
4165 | GNUNET_CONTAINER_multipeermap_destroy (observed_unique_peers); | 3943 | GNUNET_CONTAINER_multipeermap_destroy (observed_unique_peers); |
4166 | #endif /* TO_FILE */ | 3944 | #endif /* TO_FILE */ |
4167 | GNUNET_array_grow (mal_peers, num_mal_peers, 0); | 3945 | GNUNET_array_grow (mal_peers, |
3946 | num_mal_peers, | ||
3947 | 0); | ||
4168 | if (NULL != mal_peer_set) | 3948 | if (NULL != mal_peer_set) |
4169 | GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set); | 3949 | GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set); |
4170 | if (NULL != att_peer_set) | 3950 | if (NULL != att_peer_set) |
@@ -4172,9 +3952,12 @@ shutdown_task (void *cls) | |||
4172 | while (NULL != att_peers_head) | 3952 | while (NULL != att_peers_head) |
4173 | { | 3953 | { |
4174 | tmp_att_peer = att_peers_head; | 3954 | tmp_att_peer = att_peers_head; |
4175 | GNUNET_CONTAINER_DLL_remove (att_peers_head, att_peers_tail, tmp_att_peer); | 3955 | GNUNET_CONTAINER_DLL_remove (att_peers_head, |
3956 | att_peers_tail, | ||
3957 | tmp_att_peer); | ||
3958 | GNUNET_free (tmp_att_peer); | ||
4176 | } | 3959 | } |
4177 | #endif /* ENABLE_MALICIOUS */ | 3960 | #endif /* ENABLE_MALICIOUS */ |
4178 | } | 3961 | } |
4179 | 3962 | ||
4180 | 3963 | ||
@@ -4221,6 +4004,7 @@ client_disconnect_cb (void *cls, | |||
4221 | { | 4004 | { |
4222 | struct ClientContext *cli_ctx = internal_cls; | 4005 | struct ClientContext *cli_ctx = internal_cls; |
4223 | 4006 | ||
4007 | (void) cls; | ||
4224 | GNUNET_assert (client == cli_ctx->client); | 4008 | GNUNET_assert (client == cli_ctx->client); |
4225 | if (NULL == client) | 4009 | if (NULL == client) |
4226 | {/* shutdown task - destroy all clients */ | 4010 | {/* shutdown task - destroy all clients */ |
@@ -4248,29 +4032,31 @@ run (void *cls, | |||
4248 | const struct GNUNET_CONFIGURATION_Handle *c, | 4032 | const struct GNUNET_CONFIGURATION_Handle *c, |
4249 | struct GNUNET_SERVICE_Handle *service) | 4033 | struct GNUNET_SERVICE_Handle *service) |
4250 | { | 4034 | { |
4251 | char* fn_valid_peers; | 4035 | char *fn_valid_peers; |
4252 | struct GNUNET_HashCode port; | ||
4253 | 4036 | ||
4254 | GNUNET_log_setup ("rps", GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), NULL); | 4037 | (void) cls; |
4038 | (void) service; | ||
4039 | GNUNET_log_setup ("rps", | ||
4040 | GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), | ||
4041 | NULL); | ||
4255 | cfg = c; | 4042 | cfg = c; |
4256 | |||
4257 | |||
4258 | /* Get own ID */ | 4043 | /* Get own ID */ |
4259 | GNUNET_CRYPTO_get_peer_identity (cfg, &own_identity); // TODO check return value | 4044 | GNUNET_CRYPTO_get_peer_identity (cfg, |
4045 | &own_identity); // TODO check return value | ||
4260 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4046 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
4261 | "STARTING SERVICE (rps) for peer [%s]\n", | 4047 | "STARTING SERVICE (rps) for peer [%s]\n", |
4262 | GNUNET_i2s (&own_identity)); | 4048 | GNUNET_i2s (&own_identity)); |
4263 | #ifdef ENABLE_MALICIOUS | 4049 | #ifdef ENABLE_MALICIOUS |
4264 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 4050 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4265 | "Malicious execution compiled in.\n"); | 4051 | "Malicious execution compiled in.\n"); |
4266 | #endif /* ENABLE_MALICIOUS */ | 4052 | #endif /* ENABLE_MALICIOUS */ |
4267 | |||
4268 | |||
4269 | 4053 | ||
4270 | /* Get time interval from the configuration */ | 4054 | /* Get time interval from the configuration */ |
4271 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "RPS", | 4055 | if (GNUNET_OK != |
4272 | "ROUNDINTERVAL", | 4056 | GNUNET_CONFIGURATION_get_value_time (cfg, |
4273 | &round_interval)) | 4057 | "RPS", |
4058 | "ROUNDINTERVAL", | ||
4059 | &round_interval)) | ||
4274 | { | 4060 | { |
4275 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 4061 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
4276 | "RPS", "ROUNDINTERVAL"); | 4062 | "RPS", "ROUNDINTERVAL"); |
@@ -4349,15 +4135,22 @@ run (void *cls, | |||
4349 | &port); | 4135 | &port); |
4350 | cadet_port = GNUNET_CADET_open_port (cadet_handle, | 4136 | cadet_port = GNUNET_CADET_open_port (cadet_handle, |
4351 | &port, | 4137 | &port, |
4352 | &Peers_handle_inbound_channel, /* Connect handler */ | 4138 | &handle_inbound_channel, /* Connect handler */ |
4353 | NULL, /* cls */ | 4139 | NULL, /* cls */ |
4354 | NULL, /* WindowSize handler */ | 4140 | NULL, /* WindowSize handler */ |
4355 | cleanup_destroyed_channel, /* Disconnect handler */ | 4141 | &cleanup_destroyed_channel, /* Disconnect handler */ |
4356 | cadet_handlers); | 4142 | cadet_handlers); |
4143 | if (NULL == cadet_port) | ||
4144 | { | ||
4145 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
4146 | "Cadet port `%s' is already in use.\n", | ||
4147 | GNUNET_APPLICATION_PORT_RPS); | ||
4148 | GNUNET_assert (0); | ||
4149 | } | ||
4357 | 4150 | ||
4358 | 4151 | ||
4359 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | 4152 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); |
4360 | Peers_initialise (fn_valid_peers, cadet_handle, &own_identity); | 4153 | initialise_peers (fn_valid_peers, cadet_handle); |
4361 | GNUNET_free (fn_valid_peers); | 4154 | GNUNET_free (fn_valid_peers); |
4362 | 4155 | ||
4363 | /* Initialise sampler */ | 4156 | /* Initialise sampler */ |
@@ -4380,7 +4173,7 @@ run (void *cls, | |||
4380 | // TODO send push/pull to each of those peers? | 4173 | // TODO send push/pull to each of those peers? |
4381 | // TODO read stored valid peers from last run | 4174 | // TODO read stored valid peers from last run |
4382 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); | 4175 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); |
4383 | Peers_get_valid_peers (valid_peers_iterator, NULL); | 4176 | get_valid_peers (valid_peers_iterator, NULL); |
4384 | 4177 | ||
4385 | peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, | 4178 | peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, |
4386 | GNUNET_NO, | 4179 | GNUNET_NO, |