diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/transport/gnunet-service-transport.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 2390 |
1 files changed, 1194 insertions, 1196 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 1e8f81483..5080e650e 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010-2016 GNUnet e.V. | 3 | Copyright (C) 2010-2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero 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 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your 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 | Affero 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 Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -47,7 +47,7 @@ | |||
47 | * How many messages can we have pending for a given client process | 47 | * How many messages can we have pending for a given client process |
48 | * before we start to drop incoming messages? We typically should | 48 | * before we start to drop incoming messages? We typically should |
49 | * have only one client and so this would be the primary buffer for | 49 | * have only one client and so this would be the primary buffer for |
50 | * messages, so the number should be chosen rather generously. | 50 | * messages, so the number should be chosen rather generously. |
51 | * | 51 | * |
52 | * The expectation here is that most of the time the queue is large | 52 | * The expectation here is that most of the time the queue is large |
53 | * enough so that a drop is virtually never required. Note that | 53 | * enough so that a drop is virtually never required. Note that |
@@ -61,8 +61,7 @@ | |||
61 | /** | 61 | /** |
62 | * Information we need for an asynchronous session kill. | 62 | * Information we need for an asynchronous session kill. |
63 | */ | 63 | */ |
64 | struct GNUNET_ATS_SessionKiller | 64 | struct GNUNET_ATS_SessionKiller { |
65 | { | ||
66 | /** | 65 | /** |
67 | * Kept in a DLL. | 66 | * Kept in a DLL. |
68 | */ | 67 | */ |
@@ -93,8 +92,7 @@ struct GNUNET_ATS_SessionKiller | |||
93 | /** | 92 | /** |
94 | * What type of client is the `struct TransportClient` about? | 93 | * What type of client is the `struct TransportClient` about? |
95 | */ | 94 | */ |
96 | enum ClientType | 95 | enum ClientType { |
97 | { | ||
98 | /** | 96 | /** |
99 | * We do not know yet (client is fresh). | 97 | * We do not know yet (client is fresh). |
100 | */ | 98 | */ |
@@ -130,9 +128,7 @@ struct GST_BlacklistCheck; | |||
130 | /** | 128 | /** |
131 | * Client connected to the transport service. | 129 | * Client connected to the transport service. |
132 | */ | 130 | */ |
133 | struct TransportClient | 131 | struct TransportClient { |
134 | { | ||
135 | |||
136 | /** | 132 | /** |
137 | * This is a doubly-linked list. | 133 | * This is a doubly-linked list. |
138 | */ | 134 | */ |
@@ -158,9 +154,7 @@ struct TransportClient | |||
158 | */ | 154 | */ |
159 | enum ClientType type; | 155 | enum ClientType type; |
160 | 156 | ||
161 | union | 157 | union { |
162 | { | ||
163 | |||
164 | /** | 158 | /** |
165 | * Peer identity to monitor the addresses of. | 159 | * Peer identity to monitor the addresses of. |
166 | * Zero to monitor all neighbours. Valid if | 160 | * Zero to monitor all neighbours. Valid if |
@@ -171,9 +165,7 @@ struct TransportClient | |||
171 | /** | 165 | /** |
172 | * Additional details if @e type is CT_BLACKLIST. | 166 | * Additional details if @e type is CT_BLACKLIST. |
173 | */ | 167 | */ |
174 | struct | 168 | struct { |
175 | { | ||
176 | |||
177 | /** | 169 | /** |
178 | * Blacklist check that we're currently performing (or NULL | 170 | * Blacklist check that we're currently performing (or NULL |
179 | * if we're performing one that has been cancelled). | 171 | * if we're performing one that has been cancelled). |
@@ -189,9 +181,7 @@ struct TransportClient | |||
189 | * #GNUNET_YES if we have to call receive_done for this client | 181 | * #GNUNET_YES if we have to call receive_done for this client |
190 | */ | 182 | */ |
191 | int call_receive_done; | 183 | int call_receive_done; |
192 | |||
193 | } blacklist; | 184 | } blacklist; |
194 | |||
195 | } details; | 185 | } details; |
196 | }; | 186 | }; |
197 | 187 | ||
@@ -199,9 +189,7 @@ struct TransportClient | |||
199 | /** | 189 | /** |
200 | * Context we use when performing a blacklist check. | 190 | * Context we use when performing a blacklist check. |
201 | */ | 191 | */ |
202 | struct GST_BlacklistCheck | 192 | struct GST_BlacklistCheck { |
203 | { | ||
204 | |||
205 | /** | 193 | /** |
206 | * This is a linked list. | 194 | * This is a linked list. |
207 | */ | 195 | */ |
@@ -252,8 +240,7 @@ struct GST_BlacklistCheck | |||
252 | /** | 240 | /** |
253 | * Context for address to string operations | 241 | * Context for address to string operations |
254 | */ | 242 | */ |
255 | struct AddressToStringContext | 243 | struct AddressToStringContext { |
256 | { | ||
257 | /** | 244 | /** |
258 | * This is a doubly-linked list. | 245 | * This is a doubly-linked list. |
259 | */ | 246 | */ |
@@ -274,9 +261,7 @@ struct AddressToStringContext | |||
274 | /** | 261 | /** |
275 | * Closure for #handle_send_transmit_continuation() | 262 | * Closure for #handle_send_transmit_continuation() |
276 | */ | 263 | */ |
277 | struct SendTransmitContinuationContext | 264 | struct SendTransmitContinuationContext { |
278 | { | ||
279 | |||
280 | /** | 265 | /** |
281 | * Client that made the request. | 266 | * Client that made the request. |
282 | */ | 267 | */ |
@@ -431,31 +416,31 @@ struct GNUNET_NT_InterfaceScanner *GST_is; | |||
431 | * @param may_drop #GNUNET_YES if the message can be dropped | 416 | * @param may_drop #GNUNET_YES if the message can be dropped |
432 | */ | 417 | */ |
433 | static void | 418 | static void |
434 | unicast (struct TransportClient *tc, | 419 | unicast(struct TransportClient *tc, |
435 | const struct GNUNET_MessageHeader *msg, | 420 | const struct GNUNET_MessageHeader *msg, |
436 | int may_drop) | 421 | int may_drop) |
437 | { | 422 | { |
438 | struct GNUNET_MQ_Envelope *env; | 423 | struct GNUNET_MQ_Envelope *env; |
439 | 424 | ||
440 | if ((GNUNET_MQ_get_length (tc->mq) >= MAX_PENDING) && | 425 | if ((GNUNET_MQ_get_length(tc->mq) >= MAX_PENDING) && |
441 | (GNUNET_YES == may_drop)) | 426 | (GNUNET_YES == may_drop)) |
442 | { | 427 | { |
443 | GNUNET_log ( | 428 | GNUNET_log( |
444 | GNUNET_ERROR_TYPE_DEBUG, | 429 | GNUNET_ERROR_TYPE_DEBUG, |
445 | "Dropping message of type %u and size %u, have %u/%u messages pending\n", | 430 | "Dropping message of type %u and size %u, have %u/%u messages pending\n", |
446 | ntohs (msg->type), | 431 | ntohs(msg->type), |
447 | ntohs (msg->size), | 432 | ntohs(msg->size), |
448 | GNUNET_MQ_get_length (tc->mq), | 433 | GNUNET_MQ_get_length(tc->mq), |
449 | MAX_PENDING); | 434 | MAX_PENDING); |
450 | GNUNET_STATISTICS_update (GST_stats, | 435 | GNUNET_STATISTICS_update(GST_stats, |
451 | gettext_noop ( | 436 | gettext_noop( |
452 | "# messages dropped due to slow client"), | 437 | "# messages dropped due to slow client"), |
453 | 1, | 438 | 1, |
454 | GNUNET_NO); | 439 | GNUNET_NO); |
455 | return; | 440 | return; |
456 | } | 441 | } |
457 | env = GNUNET_MQ_msg_copy (msg); | 442 | env = GNUNET_MQ_msg_copy(msg); |
458 | GNUNET_MQ_send (tc->mq, env); | 443 | GNUNET_MQ_send(tc->mq, env); |
459 | } | 444 | } |
460 | 445 | ||
461 | 446 | ||
@@ -469,17 +454,17 @@ unicast (struct TransportClient *tc, | |||
469 | * @return our `struct TransportClient` | 454 | * @return our `struct TransportClient` |
470 | */ | 455 | */ |
471 | static void * | 456 | static void * |
472 | client_connect_cb (void *cls, | 457 | client_connect_cb(void *cls, |
473 | struct GNUNET_SERVICE_Client *client, | 458 | struct GNUNET_SERVICE_Client *client, |
474 | struct GNUNET_MQ_Handle *mq) | 459 | struct GNUNET_MQ_Handle *mq) |
475 | { | 460 | { |
476 | struct TransportClient *tc; | 461 | struct TransportClient *tc; |
477 | 462 | ||
478 | tc = GNUNET_new (struct TransportClient); | 463 | tc = GNUNET_new(struct TransportClient); |
479 | tc->client = client; | 464 | tc->client = client; |
480 | tc->mq = mq; | 465 | tc->mq = mq; |
481 | GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc); | 466 | GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc); |
482 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); | 467 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); |
483 | return tc; | 468 | return tc; |
484 | } | 469 | } |
485 | 470 | ||
@@ -490,7 +475,7 @@ client_connect_cb (void *cls, | |||
490 | * @param cls the `struct BlacklistCheck*` | 475 | * @param cls the `struct BlacklistCheck*` |
491 | */ | 476 | */ |
492 | static void | 477 | static void |
493 | do_blacklist_check (void *cls); | 478 | do_blacklist_check(void *cls); |
494 | 479 | ||
495 | 480 | ||
496 | /** | 481 | /** |
@@ -503,16 +488,16 @@ do_blacklist_check (void *cls); | |||
503 | * @return #GNUNET_OK (continue to iterate) | 488 | * @return #GNUNET_OK (continue to iterate) |
504 | */ | 489 | */ |
505 | static int | 490 | static int |
506 | mark_match_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) | 491 | mark_match_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value) |
507 | { | 492 | { |
508 | struct TransportClient *tc = cls; | 493 | struct TransportClient *tc = cls; |
509 | struct SendTransmitContinuationContext *stcc = value; | 494 | struct SendTransmitContinuationContext *stcc = value; |
510 | 495 | ||
511 | if (tc == stcc->tc) | 496 | if (tc == stcc->tc) |
512 | { | 497 | { |
513 | stcc->down = GNUNET_YES; | 498 | stcc->down = GNUNET_YES; |
514 | stcc->tc = NULL; | 499 | stcc->tc = NULL; |
515 | } | 500 | } |
516 | return GNUNET_OK; | 501 | return GNUNET_OK; |
517 | } | 502 | } |
518 | 503 | ||
@@ -526,46 +511,50 @@ mark_match_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) | |||
526 | * @param app_ctx our `struct TransportClient` | 511 | * @param app_ctx our `struct TransportClient` |
527 | */ | 512 | */ |
528 | static void | 513 | static void |
529 | client_disconnect_cb (void *cls, | 514 | client_disconnect_cb(void *cls, |
530 | struct GNUNET_SERVICE_Client *client, | 515 | struct GNUNET_SERVICE_Client *client, |
531 | void *app_ctx) | 516 | void *app_ctx) |
532 | { | 517 | { |
533 | struct TransportClient *tc = app_ctx; | 518 | struct TransportClient *tc = app_ctx; |
534 | struct GST_BlacklistCheck *bc; | 519 | struct GST_BlacklistCheck *bc; |
535 | 520 | ||
536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 521 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
537 | "Client %p disconnected, cleaning up.\n", | 522 | "Client %p disconnected, cleaning up.\n", |
538 | tc); | 523 | tc); |
539 | GNUNET_CONTAINER_multipeermap_iterate (active_stccs, &mark_match_down, tc); | 524 | GNUNET_CONTAINER_multipeermap_iterate(active_stccs, &mark_match_down, tc); |
540 | for (struct AddressToStringContext *cur = a2s_head; NULL != cur; | 525 | for (struct AddressToStringContext *cur = a2s_head; NULL != cur; |
541 | cur = cur->next) | 526 | cur = cur->next) |
542 | { | 527 | { |
543 | if (cur->tc == tc) | 528 | if (cur->tc == tc) |
544 | cur->tc = NULL; | 529 | cur->tc = NULL; |
545 | } | 530 | } |
546 | GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); | 531 | GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc); |
547 | switch (tc->type) | 532 | switch (tc->type) |
548 | { | 533 | { |
549 | case CT_NONE: | 534 | case CT_NONE: |
550 | break; | 535 | break; |
551 | case CT_CORE: | 536 | |
552 | break; | 537 | case CT_CORE: |
553 | case CT_MONITOR: | 538 | break; |
554 | break; | 539 | |
555 | case CT_BLACKLIST: | 540 | case CT_MONITOR: |
556 | for (bc = bc_head; NULL != bc; bc = bc->next) | 541 | break; |
557 | { | 542 | |
558 | if (bc->bl_pos != tc) | 543 | case CT_BLACKLIST: |
559 | continue; | 544 | for (bc = bc_head; NULL != bc; bc = bc->next) |
560 | bc->bl_pos = tc->next; | 545 | { |
561 | if (NULL == bc->task) | 546 | if (bc->bl_pos != tc) |
562 | bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); | 547 | continue; |
548 | bc->bl_pos = tc->next; | ||
549 | if (NULL == bc->task) | ||
550 | bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); | ||
551 | } | ||
552 | break; | ||
553 | |||
554 | case CT_CORE_NO_HANDLERS: | ||
555 | break; | ||
563 | } | 556 | } |
564 | break; | 557 | GNUNET_free(tc); |
565 | case CT_CORE_NO_HANDLERS: | ||
566 | break; | ||
567 | } | ||
568 | GNUNET_free (tc); | ||
569 | } | 558 | } |
570 | 559 | ||
571 | 560 | ||
@@ -582,24 +571,24 @@ client_disconnect_cb (void *cls, | |||
582 | * @param bandwidth_out outbound bandwidth in NBO | 571 | * @param bandwidth_out outbound bandwidth in NBO |
583 | */ | 572 | */ |
584 | static void | 573 | static void |
585 | notify_client_about_neighbour (void *cls, | 574 | notify_client_about_neighbour(void *cls, |
586 | const struct GNUNET_PeerIdentity *peer, | 575 | const struct GNUNET_PeerIdentity *peer, |
587 | const struct GNUNET_HELLO_Address *address, | 576 | const struct GNUNET_HELLO_Address *address, |
588 | enum GNUNET_TRANSPORT_PeerState state, | 577 | enum GNUNET_TRANSPORT_PeerState state, |
589 | struct GNUNET_TIME_Absolute state_timeout, | 578 | struct GNUNET_TIME_Absolute state_timeout, |
590 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 579 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
591 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 580 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) |
592 | { | 581 | { |
593 | struct TransportClient *tc = cls; | 582 | struct TransportClient *tc = cls; |
594 | struct ConnectInfoMessage cim; | 583 | struct ConnectInfoMessage cim; |
595 | 584 | ||
596 | if (GNUNET_NO == GST_neighbours_test_connected (peer)) | 585 | if (GNUNET_NO == GST_neighbours_test_connected(peer)) |
597 | return; | 586 | return; |
598 | cim.header.size = htons (sizeof (struct ConnectInfoMessage)); | 587 | cim.header.size = htons(sizeof(struct ConnectInfoMessage)); |
599 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); | 588 | cim.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); |
600 | cim.id = *peer; | 589 | cim.id = *peer; |
601 | cim.quota_out = bandwidth_out; | 590 | cim.quota_out = bandwidth_out; |
602 | unicast (tc, &cim.header, GNUNET_NO); | 591 | unicast(tc, &cim.header, GNUNET_NO); |
603 | } | 592 | } |
604 | 593 | ||
605 | 594 | ||
@@ -612,39 +601,39 @@ notify_client_about_neighbour (void *cls, | |||
612 | * @param start the start message that was sent | 601 | * @param start the start message that was sent |
613 | */ | 602 | */ |
614 | static void | 603 | static void |
615 | handle_client_start (void *cls, const struct StartMessage *start) | 604 | handle_client_start(void *cls, const struct StartMessage *start) |
616 | { | 605 | { |
617 | struct TransportClient *tc = cls; | 606 | struct TransportClient *tc = cls; |
618 | const struct GNUNET_MessageHeader *hello; | 607 | const struct GNUNET_MessageHeader *hello; |
619 | uint32_t options; | 608 | uint32_t options; |
620 | 609 | ||
621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc); | 610 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc); |
622 | options = ntohl (start->options); | 611 | options = ntohl(start->options); |
623 | if ((0 != (1 & options)) && | 612 | if ((0 != (1 & options)) && |
624 | (0 != memcmp (&start->self, | 613 | (0 != memcmp(&start->self, |
625 | &GST_my_identity, | 614 | &GST_my_identity, |
626 | sizeof (struct GNUNET_PeerIdentity)))) | 615 | sizeof(struct GNUNET_PeerIdentity)))) |
627 | { | 616 | { |
628 | /* client thinks this is a different peer, reject */ | 617 | /* client thinks this is a different peer, reject */ |
629 | GNUNET_break (0); | 618 | GNUNET_break(0); |
630 | GNUNET_SERVICE_client_drop (tc->client); | 619 | GNUNET_SERVICE_client_drop(tc->client); |
631 | return; | 620 | return; |
632 | } | 621 | } |
633 | if (CT_NONE != tc->type) | 622 | if (CT_NONE != tc->type) |
634 | { | 623 | { |
635 | GNUNET_break (0); | 624 | GNUNET_break(0); |
636 | GNUNET_SERVICE_client_drop (tc->client); | 625 | GNUNET_SERVICE_client_drop(tc->client); |
637 | return; | 626 | return; |
638 | } | 627 | } |
639 | if (0 != (2 & options)) | 628 | if (0 != (2 & options)) |
640 | tc->type = CT_CORE; | 629 | tc->type = CT_CORE; |
641 | else | 630 | else |
642 | tc->type = CT_CORE_NO_HANDLERS; | 631 | tc->type = CT_CORE_NO_HANDLERS; |
643 | hello = GST_hello_get (); | 632 | hello = GST_hello_get(); |
644 | if (NULL != hello) | 633 | if (NULL != hello) |
645 | unicast (tc, hello, GNUNET_NO); | 634 | unicast(tc, hello, GNUNET_NO); |
646 | GST_neighbours_iterate (¬ify_client_about_neighbour, tc); | 635 | GST_neighbours_iterate(¬ify_client_about_neighbour, tc); |
647 | GNUNET_SERVICE_client_continue (tc->client); | 636 | GNUNET_SERVICE_client_continue(tc->client); |
648 | } | 637 | } |
649 | 638 | ||
650 | 639 | ||
@@ -655,7 +644,7 @@ handle_client_start (void *cls, const struct StartMessage *start) | |||
655 | * @param message the HELLO message | 644 | * @param message the HELLO message |
656 | */ | 645 | */ |
657 | static int | 646 | static int |
658 | check_client_hello (void *cls, const struct GNUNET_MessageHeader *message) | 647 | check_client_hello(void *cls, const struct GNUNET_MessageHeader *message) |
659 | { | 648 | { |
660 | return GNUNET_OK; /* FIXME: check here? */ | 649 | return GNUNET_OK; /* FIXME: check here? */ |
661 | } | 650 | } |
@@ -668,13 +657,13 @@ check_client_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
668 | * @param message the HELLO message | 657 | * @param message the HELLO message |
669 | */ | 658 | */ |
670 | static void | 659 | static void |
671 | handle_client_hello (void *cls, const struct GNUNET_MessageHeader *message) | 660 | handle_client_hello(void *cls, const struct GNUNET_MessageHeader *message) |
672 | { | 661 | { |
673 | struct TransportClient *tc = cls; | 662 | struct TransportClient *tc = cls; |
674 | 663 | ||
675 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n"); | 664 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n"); |
676 | GST_validation_handle_hello (message); | 665 | GST_validation_handle_hello(message); |
677 | GNUNET_SERVICE_client_continue (tc->client); | 666 | GNUNET_SERVICE_client_continue(tc->client); |
678 | } | 667 | } |
679 | 668 | ||
680 | 669 | ||
@@ -688,55 +677,55 @@ handle_client_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
688 | * @param bytes_on_wire bytes sent on wire | 677 | * @param bytes_on_wire bytes sent on wire |
689 | */ | 678 | */ |
690 | static void | 679 | static void |
691 | handle_send_transmit_continuation (void *cls, | 680 | handle_send_transmit_continuation(void *cls, |
692 | int success, | 681 | int success, |
693 | size_t bytes_payload, | 682 | size_t bytes_payload, |
694 | size_t bytes_on_wire) | 683 | size_t bytes_on_wire) |
695 | { | 684 | { |
696 | struct SendTransmitContinuationContext *stcc = cls; | 685 | struct SendTransmitContinuationContext *stcc = cls; |
697 | struct SendOkMessage send_ok_msg; | 686 | struct SendOkMessage send_ok_msg; |
698 | struct GNUNET_TIME_Relative delay; | 687 | struct GNUNET_TIME_Relative delay; |
699 | const struct GNUNET_HELLO_Address *addr; | 688 | const struct GNUNET_HELLO_Address *addr; |
700 | 689 | ||
701 | delay = GNUNET_TIME_absolute_get_duration (stcc->send_time); | 690 | delay = GNUNET_TIME_absolute_get_duration(stcc->send_time); |
702 | addr = GST_neighbour_get_current_address (&stcc->target); | 691 | addr = GST_neighbour_get_current_address(&stcc->target); |
703 | if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) | 692 | if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) |
704 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 693 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
705 | "It took us %s to send %u/%u bytes to %s (%d, %s)\n", | 694 | "It took us %s to send %u/%u bytes to %s (%d, %s)\n", |
706 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), | 695 | GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), |
707 | (unsigned int) bytes_payload, | 696 | (unsigned int)bytes_payload, |
708 | (unsigned int) bytes_on_wire, | 697 | (unsigned int)bytes_on_wire, |
709 | GNUNET_i2s (&stcc->target), | 698 | GNUNET_i2s(&stcc->target), |
710 | success, | 699 | success, |
711 | (NULL != addr) ? addr->transport_name : "%"); | 700 | (NULL != addr) ? addr->transport_name : "%"); |
712 | else | 701 | else |
713 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 702 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
714 | "It took us %s to send %u/%u bytes to %s (%d, %s)\n", | 703 | "It took us %s to send %u/%u bytes to %s (%d, %s)\n", |
715 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), | 704 | GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), |
716 | (unsigned int) bytes_payload, | 705 | (unsigned int)bytes_payload, |
717 | (unsigned int) bytes_on_wire, | 706 | (unsigned int)bytes_on_wire, |
718 | GNUNET_i2s (&stcc->target), | 707 | GNUNET_i2s(&stcc->target), |
719 | success, | 708 | success, |
720 | (NULL != addr) ? addr->transport_name : "%"); | 709 | (NULL != addr) ? addr->transport_name : "%"); |
721 | 710 | ||
722 | if (GNUNET_NO == stcc->down) | 711 | if (GNUNET_NO == stcc->down) |
723 | { | 712 | { |
724 | /* Only send confirmation if we are still connected */ | 713 | /* Only send confirmation if we are still connected */ |
725 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 714 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
726 | "Sending SEND_OK for transmission request %llu\n", | 715 | "Sending SEND_OK for transmission request %llu\n", |
727 | stcc->uuid); | 716 | stcc->uuid); |
728 | send_ok_msg.header.size = htons (sizeof (send_ok_msg)); | 717 | send_ok_msg.header.size = htons(sizeof(send_ok_msg)); |
729 | send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); | 718 | send_ok_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); |
730 | send_ok_msg.bytes_msg = htonl (bytes_payload); | 719 | send_ok_msg.bytes_msg = htonl(bytes_payload); |
731 | send_ok_msg.bytes_physical = htonl (bytes_on_wire); | 720 | send_ok_msg.bytes_physical = htonl(bytes_on_wire); |
732 | send_ok_msg.success = htonl (success); | 721 | send_ok_msg.success = htonl(success); |
733 | send_ok_msg.peer = stcc->target; | 722 | send_ok_msg.peer = stcc->target; |
734 | unicast (stcc->tc, &send_ok_msg.header, GNUNET_NO); | 723 | unicast(stcc->tc, &send_ok_msg.header, GNUNET_NO); |
735 | } | 724 | } |
736 | GNUNET_assert ( | 725 | GNUNET_assert( |
737 | GNUNET_OK == | 726 | GNUNET_OK == |
738 | GNUNET_CONTAINER_multipeermap_remove (active_stccs, &stcc->target, stcc)); | 727 | GNUNET_CONTAINER_multipeermap_remove(active_stccs, &stcc->target, stcc)); |
739 | GNUNET_free (stcc); | 728 | GNUNET_free(stcc); |
740 | } | 729 | } |
741 | 730 | ||
742 | 731 | ||
@@ -747,23 +736,23 @@ handle_send_transmit_continuation (void *cls, | |||
747 | * @param obm the send message that was sent | 736 | * @param obm the send message that was sent |
748 | */ | 737 | */ |
749 | static int | 738 | static int |
750 | check_client_send (void *cls, const struct OutboundMessage *obm) | 739 | check_client_send(void *cls, const struct OutboundMessage *obm) |
751 | { | 740 | { |
752 | uint16_t size; | 741 | uint16_t size; |
753 | const struct GNUNET_MessageHeader *obmm; | 742 | const struct GNUNET_MessageHeader *obmm; |
754 | 743 | ||
755 | size = ntohs (obm->header.size) - sizeof (struct OutboundMessage); | 744 | size = ntohs(obm->header.size) - sizeof(struct OutboundMessage); |
756 | if (size < sizeof (struct GNUNET_MessageHeader)) | 745 | if (size < sizeof(struct GNUNET_MessageHeader)) |
757 | { | 746 | { |
758 | GNUNET_break (0); | 747 | GNUNET_break(0); |
759 | return GNUNET_SYSERR; | 748 | return GNUNET_SYSERR; |
760 | } | 749 | } |
761 | obmm = (const struct GNUNET_MessageHeader *) &obm[1]; | 750 | obmm = (const struct GNUNET_MessageHeader *)&obm[1]; |
762 | if (size != ntohs (obmm->size)) | 751 | if (size != ntohs(obmm->size)) |
763 | { | 752 | { |
764 | GNUNET_break (0); | 753 | GNUNET_break(0); |
765 | return GNUNET_SYSERR; | 754 | return GNUNET_SYSERR; |
766 | } | 755 | } |
767 | return GNUNET_OK; | 756 | return GNUNET_OK; |
768 | } | 757 | } |
769 | 758 | ||
@@ -775,53 +764,53 @@ check_client_send (void *cls, const struct OutboundMessage *obm) | |||
775 | * @param obm the send message that was sent | 764 | * @param obm the send message that was sent |
776 | */ | 765 | */ |
777 | static void | 766 | static void |
778 | handle_client_send (void *cls, const struct OutboundMessage *obm) | 767 | handle_client_send(void *cls, const struct OutboundMessage *obm) |
779 | { | 768 | { |
780 | static unsigned long long uuid_gen; | 769 | static unsigned long long uuid_gen; |
781 | struct TransportClient *tc = cls; | 770 | struct TransportClient *tc = cls; |
782 | const struct GNUNET_MessageHeader *obmm; | 771 | const struct GNUNET_MessageHeader *obmm; |
783 | struct SendTransmitContinuationContext *stcc; | 772 | struct SendTransmitContinuationContext *stcc; |
784 | 773 | ||
785 | obmm = (const struct GNUNET_MessageHeader *) &obm[1]; | 774 | obmm = (const struct GNUNET_MessageHeader *)&obm[1]; |
786 | if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer)) | 775 | if (GNUNET_NO == GST_neighbours_test_connected(&obm->peer)) |
787 | { | 776 | { |
788 | /* not connected, not allowed to send; can happen due to asynchronous operations */ | 777 | /* not connected, not allowed to send; can happen due to asynchronous operations */ |
789 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 778 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
790 | "Could not send message to peer `%s': not connected\n", | 779 | "Could not send message to peer `%s': not connected\n", |
791 | GNUNET_i2s (&obm->peer)); | 780 | GNUNET_i2s(&obm->peer)); |
792 | GNUNET_STATISTICS_update ( | 781 | GNUNET_STATISTICS_update( |
793 | GST_stats, | 782 | GST_stats, |
794 | gettext_noop ("# bytes payload dropped (other peer was not connected)"), | 783 | gettext_noop("# bytes payload dropped (other peer was not connected)"), |
795 | ntohs (obmm->size), | 784 | ntohs(obmm->size), |
796 | GNUNET_NO); | 785 | GNUNET_NO); |
797 | GNUNET_SERVICE_client_continue (tc->client); | 786 | GNUNET_SERVICE_client_continue(tc->client); |
798 | return; | 787 | return; |
799 | } | 788 | } |
800 | GNUNET_log ( | 789 | GNUNET_log( |
801 | GNUNET_ERROR_TYPE_DEBUG, | 790 | GNUNET_ERROR_TYPE_DEBUG, |
802 | "Received SEND request %llu for `%s' and first message of type %u and total size %u\n", | 791 | "Received SEND request %llu for `%s' and first message of type %u and total size %u\n", |
803 | uuid_gen, | 792 | uuid_gen, |
804 | GNUNET_i2s (&obm->peer), | 793 | GNUNET_i2s(&obm->peer), |
805 | ntohs (obmm->type), | 794 | ntohs(obmm->type), |
806 | ntohs (obmm->size)); | 795 | ntohs(obmm->size)); |
807 | GNUNET_SERVICE_client_continue (tc->client); | 796 | GNUNET_SERVICE_client_continue(tc->client); |
808 | 797 | ||
809 | stcc = GNUNET_new (struct SendTransmitContinuationContext); | 798 | stcc = GNUNET_new(struct SendTransmitContinuationContext); |
810 | stcc->target = obm->peer; | 799 | stcc->target = obm->peer; |
811 | stcc->tc = tc; | 800 | stcc->tc = tc; |
812 | stcc->send_time = GNUNET_TIME_absolute_get (); | 801 | stcc->send_time = GNUNET_TIME_absolute_get(); |
813 | stcc->uuid = uuid_gen++; | 802 | stcc->uuid = uuid_gen++; |
814 | (void) GNUNET_CONTAINER_multipeermap_put ( | 803 | (void)GNUNET_CONTAINER_multipeermap_put( |
815 | active_stccs, | 804 | active_stccs, |
816 | &stcc->target, | 805 | &stcc->target, |
817 | stcc, | 806 | stcc, |
818 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 807 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
819 | GST_manipulation_send (&obm->peer, | 808 | GST_manipulation_send(&obm->peer, |
820 | obmm, | 809 | obmm, |
821 | ntohs (obmm->size), | 810 | ntohs(obmm->size), |
822 | GNUNET_TIME_relative_ntoh (obm->timeout), | 811 | GNUNET_TIME_relative_ntoh(obm->timeout), |
823 | &handle_send_transmit_continuation, | 812 | &handle_send_transmit_continuation, |
824 | stcc); | 813 | stcc); |
825 | } | 814 | } |
826 | 815 | ||
827 | 816 | ||
@@ -840,50 +829,50 @@ handle_client_send (void *cls, const struct OutboundMessage *obm) | |||
840 | * never #GNUNET_NO | 829 | * never #GNUNET_NO |
841 | */ | 830 | */ |
842 | static void | 831 | static void |
843 | transmit_address_to_client (void *cls, const char *buf, int res) | 832 | transmit_address_to_client(void *cls, const char *buf, int res) |
844 | { | 833 | { |
845 | struct AddressToStringContext *actx = cls; | 834 | struct AddressToStringContext *actx = cls; |
846 | struct GNUNET_MQ_Envelope *env; | 835 | struct GNUNET_MQ_Envelope *env; |
847 | struct AddressToStringResultMessage *atsm; | 836 | struct AddressToStringResultMessage *atsm; |
848 | size_t slen; | 837 | size_t slen; |
849 | 838 | ||
850 | GNUNET_assert ((GNUNET_OK == res) || (GNUNET_SYSERR == res)); | 839 | GNUNET_assert((GNUNET_OK == res) || (GNUNET_SYSERR == res)); |
851 | if (NULL == actx->tc) | 840 | if (NULL == actx->tc) |
852 | return; | 841 | return; |
853 | if (NULL == buf) | 842 | if (NULL == buf) |
854 | { | ||
855 | env = GNUNET_MQ_msg (atsm, | ||
856 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); | ||
857 | if (GNUNET_OK == res) | ||
858 | { | ||
859 | /* this was the last call, transmit */ | ||
860 | atsm->res = htonl (GNUNET_OK); | ||
861 | atsm->addr_len = htonl (0); | ||
862 | GNUNET_MQ_send (actx->tc->mq, env); | ||
863 | GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx); | ||
864 | GNUNET_free (actx); | ||
865 | return; | ||
866 | } | ||
867 | if (GNUNET_SYSERR == res) | ||
868 | { | 843 | { |
869 | /* address conversion failed, but there will be more callbacks */ | 844 | env = GNUNET_MQ_msg(atsm, |
870 | atsm->res = htonl (GNUNET_SYSERR); | 845 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); |
871 | atsm->addr_len = htonl (0); | 846 | if (GNUNET_OK == res) |
872 | GNUNET_MQ_send (actx->tc->mq, env); | 847 | { |
873 | return; | 848 | /* this was the last call, transmit */ |
849 | atsm->res = htonl(GNUNET_OK); | ||
850 | atsm->addr_len = htonl(0); | ||
851 | GNUNET_MQ_send(actx->tc->mq, env); | ||
852 | GNUNET_CONTAINER_DLL_remove(a2s_head, a2s_tail, actx); | ||
853 | GNUNET_free(actx); | ||
854 | return; | ||
855 | } | ||
856 | if (GNUNET_SYSERR == res) | ||
857 | { | ||
858 | /* address conversion failed, but there will be more callbacks */ | ||
859 | atsm->res = htonl(GNUNET_SYSERR); | ||
860 | atsm->addr_len = htonl(0); | ||
861 | GNUNET_MQ_send(actx->tc->mq, env); | ||
862 | return; | ||
863 | } | ||
874 | } | 864 | } |
875 | } | 865 | GNUNET_assert(GNUNET_OK == res); |
876 | GNUNET_assert (GNUNET_OK == res); | ||
877 | /* succesful conversion, append*/ | 866 | /* succesful conversion, append*/ |
878 | slen = strlen (buf) + 1; | 867 | slen = strlen(buf) + 1; |
879 | env = | 868 | env = |
880 | GNUNET_MQ_msg_extra (atsm, | 869 | GNUNET_MQ_msg_extra(atsm, |
881 | slen, | 870 | slen, |
882 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); | 871 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); |
883 | atsm->res = htonl (GNUNET_YES); | 872 | atsm->res = htonl(GNUNET_YES); |
884 | atsm->addr_len = htonl (slen); | 873 | atsm->addr_len = htonl(slen); |
885 | GNUNET_memcpy (&atsm[1], buf, slen); | 874 | GNUNET_memcpy(&atsm[1], buf, slen); |
886 | GNUNET_MQ_send (actx->tc->mq, env); | 875 | GNUNET_MQ_send(actx->tc->mq, env); |
887 | } | 876 | } |
888 | 877 | ||
889 | 878 | ||
@@ -895,29 +884,29 @@ transmit_address_to_client (void *cls, const char *buf, int res) | |||
895 | * @return #GNUNET_OK if @a alum is well-formed | 884 | * @return #GNUNET_OK if @a alum is well-formed |
896 | */ | 885 | */ |
897 | static int | 886 | static int |
898 | check_client_address_to_string (void *cls, | 887 | check_client_address_to_string(void *cls, |
899 | const struct AddressLookupMessage *alum) | 888 | const struct AddressLookupMessage *alum) |
900 | { | 889 | { |
901 | const char *plugin_name; | 890 | const char *plugin_name; |
902 | const char *address; | 891 | const char *address; |
903 | uint32_t address_len; | 892 | uint32_t address_len; |
904 | uint16_t size; | 893 | uint16_t size; |
905 | 894 | ||
906 | size = ntohs (alum->header.size); | 895 | size = ntohs(alum->header.size); |
907 | address_len = ntohs (alum->addrlen); | 896 | address_len = ntohs(alum->addrlen); |
908 | if (size <= sizeof (struct AddressLookupMessage) + address_len) | 897 | if (size <= sizeof(struct AddressLookupMessage) + address_len) |
909 | { | 898 | { |
910 | GNUNET_break (0); | 899 | GNUNET_break(0); |
911 | return GNUNET_SYSERR; | 900 | return GNUNET_SYSERR; |
912 | } | 901 | } |
913 | address = (const char *) &alum[1]; | 902 | address = (const char *)&alum[1]; |
914 | plugin_name = (const char *) &address[address_len]; | 903 | plugin_name = (const char *)&address[address_len]; |
915 | if ('\0' != plugin_name[size - sizeof (struct AddressLookupMessage) - | 904 | if ('\0' != plugin_name[size - sizeof(struct AddressLookupMessage) - |
916 | address_len - 1]) | 905 | address_len - 1]) |
917 | { | 906 | { |
918 | GNUNET_break (0); | 907 | GNUNET_break(0); |
919 | return GNUNET_SYSERR; | 908 | return GNUNET_SYSERR; |
920 | } | 909 | } |
921 | return GNUNET_OK; | 910 | return GNUNET_OK; |
922 | } | 911 | } |
923 | 912 | ||
@@ -929,8 +918,8 @@ check_client_address_to_string (void *cls, | |||
929 | * @param alum the resolution request | 918 | * @param alum the resolution request |
930 | */ | 919 | */ |
931 | static void | 920 | static void |
932 | handle_client_address_to_string (void *cls, | 921 | handle_client_address_to_string(void *cls, |
933 | const struct AddressLookupMessage *alum) | 922 | const struct AddressLookupMessage *alum) |
934 | { | 923 | { |
935 | struct TransportClient *tc = cls; | 924 | struct TransportClient *tc = cls; |
936 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 925 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
@@ -943,45 +932,45 @@ handle_client_address_to_string (void *cls, | |||
943 | struct GNUNET_TIME_Relative rtimeout; | 932 | struct GNUNET_TIME_Relative rtimeout; |
944 | int32_t numeric; | 933 | int32_t numeric; |
945 | 934 | ||
946 | address_len = ntohs (alum->addrlen); | 935 | address_len = ntohs(alum->addrlen); |
947 | address = (const char *) &alum[1]; | 936 | address = (const char *)&alum[1]; |
948 | plugin_name = (const char *) &address[address_len]; | 937 | plugin_name = (const char *)&address[address_len]; |
949 | rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); | 938 | rtimeout = GNUNET_TIME_relative_ntoh(alum->timeout); |
950 | numeric = ntohs (alum->numeric_only); | 939 | numeric = ntohs(alum->numeric_only); |
951 | papi = GST_plugins_printer_find (plugin_name); | 940 | papi = GST_plugins_printer_find(plugin_name); |
952 | if (NULL == papi) | 941 | if (NULL == papi) |
953 | { | 942 | { |
954 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 943 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
955 | "Failed to find plugin `%s'\n", | 944 | "Failed to find plugin `%s'\n", |
956 | plugin_name); | 945 | plugin_name); |
957 | env = GNUNET_MQ_msg (atsm, | 946 | env = GNUNET_MQ_msg(atsm, |
958 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); | 947 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); |
959 | atsm->res = htonl (GNUNET_SYSERR); | 948 | atsm->res = htonl(GNUNET_SYSERR); |
960 | atsm->addr_len = htonl (0); | 949 | atsm->addr_len = htonl(0); |
961 | GNUNET_MQ_send (tc->mq, env); | 950 | GNUNET_MQ_send(tc->mq, env); |
962 | env = GNUNET_MQ_msg (atsm, | 951 | env = GNUNET_MQ_msg(atsm, |
963 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); | 952 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); |
964 | atsm->res = htonl (GNUNET_OK); | 953 | atsm->res = htonl(GNUNET_OK); |
965 | atsm->addr_len = htonl (0); | 954 | atsm->addr_len = htonl(0); |
966 | GNUNET_MQ_send (tc->mq, env); | 955 | GNUNET_MQ_send(tc->mq, env); |
967 | return; | 956 | return; |
968 | } | 957 | } |
969 | actx = GNUNET_new (struct AddressToStringContext); | 958 | actx = GNUNET_new(struct AddressToStringContext); |
970 | actx->tc = tc; | 959 | actx->tc = tc; |
971 | GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx); | 960 | GNUNET_CONTAINER_DLL_insert(a2s_head, a2s_tail, actx); |
972 | GNUNET_SERVICE_client_disable_continue_warning (tc->client); | 961 | GNUNET_SERVICE_client_disable_continue_warning(tc->client); |
973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 962 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
974 | "Pretty-printing address of %u bytes using plugin `%s'\n", | 963 | "Pretty-printing address of %u bytes using plugin `%s'\n", |
975 | address_len, | 964 | address_len, |
976 | plugin_name); | 965 | plugin_name); |
977 | papi->address_pretty_printer (papi->cls, | 966 | papi->address_pretty_printer(papi->cls, |
978 | plugin_name, | 967 | plugin_name, |
979 | address, | 968 | address, |
980 | address_len, | 969 | address_len, |
981 | numeric, | 970 | numeric, |
982 | rtimeout, | 971 | rtimeout, |
983 | &transmit_address_to_client, | 972 | &transmit_address_to_client, |
984 | actx); | 973 | actx); |
985 | } | 974 | } |
986 | 975 | ||
987 | 976 | ||
@@ -993,7 +982,7 @@ handle_client_address_to_string (void *cls, | |||
993 | * @return composed message | 982 | * @return composed message |
994 | */ | 983 | */ |
995 | static struct PeerIterateResponseMessage * | 984 | static struct PeerIterateResponseMessage * |
996 | compose_address_iterate_response_message ( | 985 | compose_address_iterate_response_message( |
997 | const struct GNUNET_PeerIdentity *peer, | 986 | const struct GNUNET_PeerIdentity *peer, |
998 | const struct GNUNET_HELLO_Address *address) | 987 | const struct GNUNET_HELLO_Address *address) |
999 | { | 988 | { |
@@ -1003,34 +992,34 @@ compose_address_iterate_response_message ( | |||
1003 | size_t alen; | 992 | size_t alen; |
1004 | char *addr; | 993 | char *addr; |
1005 | 994 | ||
1006 | GNUNET_assert (NULL != peer); | 995 | GNUNET_assert(NULL != peer); |
1007 | if (NULL != address) | 996 | if (NULL != address) |
1008 | { | 997 | { |
1009 | tlen = strlen (address->transport_name) + 1; | 998 | tlen = strlen(address->transport_name) + 1; |
1010 | alen = address->address_length; | 999 | alen = address->address_length; |
1011 | } | 1000 | } |
1012 | else | 1001 | else |
1013 | { | 1002 | { |
1014 | tlen = 0; | 1003 | tlen = 0; |
1015 | alen = 0; | 1004 | alen = 0; |
1016 | } | 1005 | } |
1017 | size = (sizeof (struct PeerIterateResponseMessage) + alen + tlen); | 1006 | size = (sizeof(struct PeerIterateResponseMessage) + alen + tlen); |
1018 | msg = GNUNET_malloc (size); | 1007 | msg = GNUNET_malloc(size); |
1019 | msg->header.size = htons (size); | 1008 | msg->header.size = htons(size); |
1020 | msg->header.type = | 1009 | msg->header.type = |
1021 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); | 1010 | htons(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); |
1022 | msg->reserved = htonl (0); | 1011 | msg->reserved = htonl(0); |
1023 | msg->peer = *peer; | 1012 | msg->peer = *peer; |
1024 | msg->addrlen = htonl (alen); | 1013 | msg->addrlen = htonl(alen); |
1025 | msg->pluginlen = htonl (tlen); | 1014 | msg->pluginlen = htonl(tlen); |
1026 | 1015 | ||
1027 | if (NULL != address) | 1016 | if (NULL != address) |
1028 | { | 1017 | { |
1029 | msg->local_address_info = htonl ((uint32_t) address->local_info); | 1018 | msg->local_address_info = htonl((uint32_t)address->local_info); |
1030 | addr = (char *) &msg[1]; | 1019 | addr = (char *)&msg[1]; |
1031 | GNUNET_memcpy (addr, address->address, alen); | 1020 | GNUNET_memcpy(addr, address->address, alen); |
1032 | GNUNET_memcpy (&addr[alen], address->transport_name, tlen); | 1021 | GNUNET_memcpy(&addr[alen], address->transport_name, tlen); |
1033 | } | 1022 | } |
1034 | return msg; | 1023 | return msg; |
1035 | } | 1024 | } |
1036 | 1025 | ||
@@ -1039,8 +1028,7 @@ compose_address_iterate_response_message ( | |||
1039 | * Context for #send_validation_information() and | 1028 | * Context for #send_validation_information() and |
1040 | * #send_peer_information(). | 1029 | * #send_peer_information(). |
1041 | */ | 1030 | */ |
1042 | struct IterationContext | 1031 | struct IterationContext { |
1043 | { | ||
1044 | /** | 1032 | /** |
1045 | * Context to use for the transmission. | 1033 | * Context to use for the transmission. |
1046 | */ | 1034 | */ |
@@ -1070,31 +1058,31 @@ struct IterationContext | |||
1070 | * @param bandwidth_out outbound quota in NBO | 1058 | * @param bandwidth_out outbound quota in NBO |
1071 | */ | 1059 | */ |
1072 | static void | 1060 | static void |
1073 | send_peer_information (void *cls, | 1061 | send_peer_information(void *cls, |
1074 | const struct GNUNET_PeerIdentity *peer, | 1062 | const struct GNUNET_PeerIdentity *peer, |
1075 | const struct GNUNET_HELLO_Address *address, | 1063 | const struct GNUNET_HELLO_Address *address, |
1076 | enum GNUNET_TRANSPORT_PeerState state, | 1064 | enum GNUNET_TRANSPORT_PeerState state, |
1077 | struct GNUNET_TIME_Absolute state_timeout, | 1065 | struct GNUNET_TIME_Absolute state_timeout, |
1078 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 1066 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
1079 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 1067 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) |
1080 | { | 1068 | { |
1081 | struct IterationContext *pc = cls; | 1069 | struct IterationContext *pc = cls; |
1082 | struct GNUNET_MQ_Envelope *env; | 1070 | struct GNUNET_MQ_Envelope *env; |
1083 | struct PeerIterateResponseMessage *msg; | 1071 | struct PeerIterateResponseMessage *msg; |
1084 | 1072 | ||
1085 | if ((GNUNET_YES != pc->all) && (0 != memcmp (peer, &pc->id, sizeof (pc->id)))) | 1073 | if ((GNUNET_YES != pc->all) && (0 != memcmp(peer, &pc->id, sizeof(pc->id)))) |
1086 | return; | 1074 | return; |
1087 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1075 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1088 | "Sending information about `%s' using address `%s' in state `%s'\n", | 1076 | "Sending information about `%s' using address `%s' in state `%s'\n", |
1089 | GNUNET_i2s (peer), | 1077 | GNUNET_i2s(peer), |
1090 | (NULL != address) ? GST_plugins_a2s (address) : "<none>", | 1078 | (NULL != address) ? GST_plugins_a2s(address) : "<none>", |
1091 | GNUNET_TRANSPORT_ps2s (state)); | 1079 | GNUNET_TRANSPORT_ps2s(state)); |
1092 | msg = compose_address_iterate_response_message (peer, address); | 1080 | msg = compose_address_iterate_response_message(peer, address); |
1093 | msg->state = htonl (state); | 1081 | msg->state = htonl(state); |
1094 | msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout); | 1082 | msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); |
1095 | env = GNUNET_MQ_msg_copy (&msg->header); | 1083 | env = GNUNET_MQ_msg_copy(&msg->header); |
1096 | GNUNET_free (msg); | 1084 | GNUNET_free(msg); |
1097 | GNUNET_MQ_send (pc->tc->mq, env); | 1085 | GNUNET_MQ_send(pc->tc->mq, env); |
1098 | } | 1086 | } |
1099 | 1087 | ||
1100 | 1088 | ||
@@ -1106,61 +1094,61 @@ send_peer_information (void *cls, | |||
1106 | * @param msg the peer address information request | 1094 | * @param msg the peer address information request |
1107 | */ | 1095 | */ |
1108 | static void | 1096 | static void |
1109 | handle_client_monitor_peers (void *cls, const struct PeerMonitorMessage *msg) | 1097 | handle_client_monitor_peers(void *cls, const struct PeerMonitorMessage *msg) |
1110 | { | 1098 | { |
1111 | struct TransportClient *tc = cls; | 1099 | struct TransportClient *tc = cls; |
1112 | struct IterationContext pc; | 1100 | struct IterationContext pc; |
1113 | 1101 | ||
1114 | if (CT_NONE != tc->type) | 1102 | if (CT_NONE != tc->type) |
1115 | { | 1103 | { |
1116 | GNUNET_break (0); | 1104 | GNUNET_break(0); |
1117 | GNUNET_SERVICE_client_drop (tc->client); | 1105 | GNUNET_SERVICE_client_drop(tc->client); |
1118 | return; | 1106 | return; |
1119 | } | 1107 | } |
1120 | GNUNET_SERVICE_client_disable_continue_warning (tc->client); | 1108 | GNUNET_SERVICE_client_disable_continue_warning(tc->client); |
1121 | GNUNET_SERVICE_client_mark_monitor (tc->client); | 1109 | GNUNET_SERVICE_client_mark_monitor(tc->client); |
1122 | 1110 | ||
1123 | /* Send initial list */ | 1111 | /* Send initial list */ |
1124 | pc.tc = tc; | 1112 | pc.tc = tc; |
1125 | if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) | 1113 | if (0 == memcmp(&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity))) |
1126 | { | 1114 | { |
1127 | /* iterate over all neighbours */ | 1115 | /* iterate over all neighbours */ |
1128 | pc.all = GNUNET_YES; | 1116 | pc.all = GNUNET_YES; |
1129 | pc.id = msg->peer; | 1117 | pc.id = msg->peer; |
1130 | } | 1118 | } |
1131 | else | 1119 | else |
1132 | { | 1120 | { |
1133 | /* just return one neighbour */ | 1121 | /* just return one neighbour */ |
1134 | pc.all = GNUNET_NO; | 1122 | pc.all = GNUNET_NO; |
1135 | pc.id = msg->peer; | 1123 | pc.id = msg->peer; |
1136 | } | 1124 | } |
1137 | GST_neighbours_iterate (&send_peer_information, &pc); | 1125 | GST_neighbours_iterate(&send_peer_information, &pc); |
1138 | 1126 | ||
1139 | if (GNUNET_YES != ntohl (msg->one_shot)) | 1127 | if (GNUNET_YES != ntohl(msg->one_shot)) |
1140 | { | 1128 | { |
1141 | tc->details.monitor_peer = msg->peer; | 1129 | tc->details.monitor_peer = msg->peer; |
1142 | tc->type = CT_MONITOR; | 1130 | tc->type = CT_MONITOR; |
1143 | if (0 != | 1131 | if (0 != |
1144 | memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) | 1132 | memcmp(&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity))) |
1145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1133 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1146 | "Client %p started monitoring of the peer `%s'\n", | 1134 | "Client %p started monitoring of the peer `%s'\n", |
1147 | tc, | 1135 | tc, |
1148 | GNUNET_i2s (&msg->peer)); | 1136 | GNUNET_i2s(&msg->peer)); |
1149 | else | 1137 | else |
1150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1138 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1151 | "Client %p started monitoring all peers\n", | 1139 | "Client %p started monitoring all peers\n", |
1152 | tc); | 1140 | tc); |
1153 | } | 1141 | } |
1154 | else | 1142 | else |
1155 | { | 1143 | { |
1156 | struct GNUNET_MessageHeader *msg; | 1144 | struct GNUNET_MessageHeader *msg; |
1157 | struct GNUNET_MQ_Envelope *env; | 1145 | struct GNUNET_MQ_Envelope *env; |
1158 | 1146 | ||
1159 | env = | 1147 | env = |
1160 | GNUNET_MQ_msg (msg, | 1148 | GNUNET_MQ_msg(msg, |
1161 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END); | 1149 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END); |
1162 | GNUNET_MQ_send (tc->mq, env); | 1150 | GNUNET_MQ_send(tc->mq, env); |
1163 | } | 1151 | } |
1164 | } | 1152 | } |
1165 | 1153 | ||
1166 | 1154 | ||
@@ -1177,9 +1165,9 @@ handle_client_monitor_peers (void *cls, const struct PeerMonitorMessage *msg) | |||
1177 | * merely signalling that the initial iteration is over | 1165 | * merely signalling that the initial iteration is over |
1178 | */ | 1166 | */ |
1179 | static void | 1167 | static void |
1180 | plugin_session_info_cb (void *cls, | 1168 | plugin_session_info_cb(void *cls, |
1181 | struct GNUNET_ATS_Session *session, | 1169 | struct GNUNET_ATS_Session *session, |
1182 | const struct GNUNET_TRANSPORT_SessionInfo *info) | 1170 | const struct GNUNET_TRANSPORT_SessionInfo *info) |
1183 | { | 1171 | { |
1184 | struct GNUNET_MQ_Envelope *env; | 1172 | struct GNUNET_MQ_Envelope *env; |
1185 | struct TransportPluginMonitorMessage *msg; | 1173 | struct TransportPluginMonitorMessage *msg; |
@@ -1190,65 +1178,65 @@ plugin_session_info_cb (void *cls, | |||
1190 | char *name; | 1178 | char *name; |
1191 | char *addr; | 1179 | char *addr; |
1192 | 1180 | ||
1193 | if (0 == GNUNET_notification_context_get_size (plugin_nc)) | 1181 | if (0 == GNUNET_notification_context_get_size(plugin_nc)) |
1194 | { | 1182 | { |
1195 | GST_plugins_monitor_subscribe (NULL, NULL); | 1183 | GST_plugins_monitor_subscribe(NULL, NULL); |
1196 | return; | 1184 | return; |
1197 | } | 1185 | } |
1198 | if ((NULL == info) && (NULL == session)) | 1186 | if ((NULL == info) && (NULL == session)) |
1199 | { | ||
1200 | /* end of initial iteration */ | ||
1201 | if (NULL != sync_client) | ||
1202 | { | 1187 | { |
1203 | env = | 1188 | /* end of initial iteration */ |
1204 | GNUNET_MQ_msg (sync, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC); | 1189 | if (NULL != sync_client) |
1205 | GNUNET_MQ_send (sync_client->mq, env); | 1190 | { |
1206 | sync_client = NULL; | 1191 | env = |
1192 | GNUNET_MQ_msg(sync, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC); | ||
1193 | GNUNET_MQ_send(sync_client->mq, env); | ||
1194 | sync_client = NULL; | ||
1195 | } | ||
1196 | return; | ||
1207 | } | 1197 | } |
1208 | return; | 1198 | GNUNET_assert(NULL != info); |
1209 | } | 1199 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1210 | GNUNET_assert (NULL != info); | 1200 | "Plugin event for peer %s on transport %s\n", |
1211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1201 | GNUNET_i2s(&info->address->peer), |
1212 | "Plugin event for peer %s on transport %s\n", | 1202 | info->address->transport_name); |
1213 | GNUNET_i2s (&info->address->peer), | 1203 | slen = strlen(info->address->transport_name) + 1; |
1214 | info->address->transport_name); | ||
1215 | slen = strlen (info->address->transport_name) + 1; | ||
1216 | alen = info->address->address_length; | 1204 | alen = info->address->address_length; |
1217 | size = sizeof (struct TransportPluginMonitorMessage) + slen + alen; | 1205 | size = sizeof(struct TransportPluginMonitorMessage) + slen + alen; |
1218 | if (size > UINT16_MAX) | 1206 | if (size > UINT16_MAX) |
1219 | { | 1207 | { |
1220 | GNUNET_break (0); | 1208 | GNUNET_break(0); |
1221 | return; | 1209 | return; |
1222 | } | 1210 | } |
1223 | msg = GNUNET_malloc (size); | 1211 | msg = GNUNET_malloc(size); |
1224 | msg->header.size = htons (size); | 1212 | msg->header.size = htons(size); |
1225 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT); | 1213 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT); |
1226 | msg->session_state = htons ((uint16_t) info->state); | 1214 | msg->session_state = htons((uint16_t)info->state); |
1227 | msg->is_inbound = htons ((int16_t) info->is_inbound); | 1215 | msg->is_inbound = htons((int16_t)info->is_inbound); |
1228 | msg->msgs_pending = htonl (info->num_msg_pending); | 1216 | msg->msgs_pending = htonl(info->num_msg_pending); |
1229 | msg->bytes_pending = htonl (info->num_bytes_pending); | 1217 | msg->bytes_pending = htonl(info->num_bytes_pending); |
1230 | msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout); | 1218 | msg->timeout = GNUNET_TIME_absolute_hton(info->session_timeout); |
1231 | msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay); | 1219 | msg->delay = GNUNET_TIME_absolute_hton(info->receive_delay); |
1232 | msg->peer = info->address->peer; | 1220 | msg->peer = info->address->peer; |
1233 | msg->session_id = (uint64_t) (intptr_t) session; | 1221 | msg->session_id = (uint64_t)(intptr_t)session; |
1234 | msg->plugin_name_len = htons (slen); | 1222 | msg->plugin_name_len = htons(slen); |
1235 | msg->plugin_address_len = htons (alen); | 1223 | msg->plugin_address_len = htons(alen); |
1236 | name = (char *) &msg[1]; | 1224 | name = (char *)&msg[1]; |
1237 | GNUNET_memcpy (name, info->address->transport_name, slen); | 1225 | GNUNET_memcpy(name, info->address->transport_name, slen); |
1238 | addr = &name[slen]; | 1226 | addr = &name[slen]; |
1239 | GNUNET_memcpy (addr, info->address->address, alen); | 1227 | GNUNET_memcpy(addr, info->address->address, alen); |
1240 | if (NULL != sync_client) | 1228 | if (NULL != sync_client) |
1241 | { | 1229 | { |
1242 | struct GNUNET_MQ_Envelope *env; | 1230 | struct GNUNET_MQ_Envelope *env; |
1243 | 1231 | ||
1244 | env = GNUNET_MQ_msg_copy (&msg->header); | 1232 | env = GNUNET_MQ_msg_copy(&msg->header); |
1245 | GNUNET_MQ_send (sync_client->mq, env); | 1233 | GNUNET_MQ_send(sync_client->mq, env); |
1246 | } | 1234 | } |
1247 | else | 1235 | else |
1248 | { | 1236 | { |
1249 | GNUNET_notification_context_broadcast (plugin_nc, &msg->header, GNUNET_NO); | 1237 | GNUNET_notification_context_broadcast(plugin_nc, &msg->header, GNUNET_NO); |
1250 | } | 1238 | } |
1251 | GNUNET_free (msg); | 1239 | GNUNET_free(msg); |
1252 | } | 1240 | } |
1253 | 1241 | ||
1254 | 1242 | ||
@@ -1259,17 +1247,17 @@ plugin_session_info_cb (void *cls, | |||
1259 | * @param message the peer address information request | 1247 | * @param message the peer address information request |
1260 | */ | 1248 | */ |
1261 | static void | 1249 | static void |
1262 | handle_client_monitor_plugins (void *cls, | 1250 | handle_client_monitor_plugins(void *cls, |
1263 | const struct GNUNET_MessageHeader *message) | 1251 | const struct GNUNET_MessageHeader *message) |
1264 | { | 1252 | { |
1265 | struct TransportClient *tc = cls; | 1253 | struct TransportClient *tc = cls; |
1266 | 1254 | ||
1267 | GNUNET_SERVICE_client_mark_monitor (tc->client); | 1255 | GNUNET_SERVICE_client_mark_monitor(tc->client); |
1268 | GNUNET_SERVICE_client_disable_continue_warning (tc->client); | 1256 | GNUNET_SERVICE_client_disable_continue_warning(tc->client); |
1269 | GNUNET_notification_context_add (plugin_nc, tc->mq); | 1257 | GNUNET_notification_context_add(plugin_nc, tc->mq); |
1270 | GNUNET_assert (NULL == sync_client); | 1258 | GNUNET_assert(NULL == sync_client); |
1271 | sync_client = tc; | 1259 | sync_client = tc; |
1272 | GST_plugins_monitor_subscribe (&plugin_session_info_cb, NULL); | 1260 | GST_plugins_monitor_subscribe(&plugin_session_info_cb, NULL); |
1273 | } | 1261 | } |
1274 | 1262 | ||
1275 | 1263 | ||
@@ -1280,28 +1268,28 @@ handle_client_monitor_plugins (void *cls, | |||
1280 | * @param may_drop #GNUNET_YES if the message can be dropped / is payload | 1268 | * @param may_drop #GNUNET_YES if the message can be dropped / is payload |
1281 | */ | 1269 | */ |
1282 | void | 1270 | void |
1283 | GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop) | 1271 | GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, int may_drop) |
1284 | { | 1272 | { |
1285 | int done; | 1273 | int done; |
1286 | 1274 | ||
1287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1275 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1288 | "Asked to broadcast message of type %u with %u bytes\n", | 1276 | "Asked to broadcast message of type %u with %u bytes\n", |
1289 | (unsigned int) ntohs (msg->type), | 1277 | (unsigned int)ntohs(msg->type), |
1290 | (unsigned int) ntohs (msg->size)); | 1278 | (unsigned int)ntohs(msg->size)); |
1291 | done = GNUNET_NO; | 1279 | done = GNUNET_NO; |
1292 | for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) | 1280 | for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) |
1293 | { | 1281 | { |
1294 | if (CT_NONE == tc->type) | 1282 | if (CT_NONE == tc->type) |
1295 | continue; /* client not yet ready */ | 1283 | continue; /* client not yet ready */ |
1296 | if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type)) | 1284 | if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type)) |
1297 | continue; /* skip, this client does not care about payload */ | 1285 | continue; /* skip, this client does not care about payload */ |
1298 | unicast (tc, msg, may_drop); | 1286 | unicast(tc, msg, may_drop); |
1299 | done = GNUNET_YES; | 1287 | done = GNUNET_YES; |
1300 | } | 1288 | } |
1301 | if (GNUNET_NO == done) | 1289 | if (GNUNET_NO == done) |
1302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1290 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1303 | "Message of type %u not delivered, is CORE service up?\n", | 1291 | "Message of type %u not delivered, is CORE service up?\n", |
1304 | ntohs (msg->type)); | 1292 | ntohs(msg->type)); |
1305 | } | 1293 | } |
1306 | 1294 | ||
1307 | 1295 | ||
@@ -1314,7 +1302,7 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop) | |||
1314 | * @param state_timeout the time out for the state | 1302 | * @param state_timeout the time out for the state |
1315 | */ | 1303 | */ |
1316 | void | 1304 | void |
1317 | GST_clients_broadcast_peer_notification ( | 1305 | GST_clients_broadcast_peer_notification( |
1318 | const struct GNUNET_PeerIdentity *peer, | 1306 | const struct GNUNET_PeerIdentity *peer, |
1319 | const struct GNUNET_HELLO_Address *address, | 1307 | const struct GNUNET_HELLO_Address *address, |
1320 | enum GNUNET_TRANSPORT_PeerState state, | 1308 | enum GNUNET_TRANSPORT_PeerState state, |
@@ -1323,25 +1311,25 @@ GST_clients_broadcast_peer_notification ( | |||
1323 | struct GNUNET_MQ_Envelope *env; | 1311 | struct GNUNET_MQ_Envelope *env; |
1324 | struct PeerIterateResponseMessage *msg; | 1312 | struct PeerIterateResponseMessage *msg; |
1325 | 1313 | ||
1326 | msg = compose_address_iterate_response_message (peer, address); | 1314 | msg = compose_address_iterate_response_message(peer, address); |
1327 | msg->state = htonl (state); | 1315 | msg->state = htonl(state); |
1328 | msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout); | 1316 | msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); |
1329 | for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) | 1317 | for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) |
1330 | { | 1318 | { |
1331 | if (CT_MONITOR != tc->type) | 1319 | if (CT_MONITOR != tc->type) |
1332 | continue; | 1320 | continue; |
1333 | if ((0 == memcmp (&tc->details.monitor_peer, | 1321 | if ((0 == memcmp(&tc->details.monitor_peer, |
1334 | &all_zeros, | 1322 | &all_zeros, |
1335 | sizeof (struct GNUNET_PeerIdentity))) || | 1323 | sizeof(struct GNUNET_PeerIdentity))) || |
1336 | (0 == memcmp (&tc->details.monitor_peer, | 1324 | (0 == memcmp(&tc->details.monitor_peer, |
1337 | peer, | 1325 | peer, |
1338 | sizeof (struct GNUNET_PeerIdentity)))) | 1326 | sizeof(struct GNUNET_PeerIdentity)))) |
1339 | { | 1327 | { |
1340 | env = GNUNET_MQ_msg_copy (&msg->header); | 1328 | env = GNUNET_MQ_msg_copy(&msg->header); |
1341 | GNUNET_MQ_send (tc->mq, env); | 1329 | GNUNET_MQ_send(tc->mq, env); |
1330 | } | ||
1342 | } | 1331 | } |
1343 | } | 1332 | GNUNET_free(msg); |
1344 | GNUNET_free (msg); | ||
1345 | } | 1333 | } |
1346 | 1334 | ||
1347 | 1335 | ||
@@ -1355,7 +1343,7 @@ GST_clients_broadcast_peer_notification ( | |||
1355 | * @return #GNUNET_OK (continue to iterate) | 1343 | * @return #GNUNET_OK (continue to iterate) |
1356 | */ | 1344 | */ |
1357 | static int | 1345 | static int |
1358 | mark_peer_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) | 1346 | mark_peer_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value) |
1359 | { | 1347 | { |
1360 | struct SendTransmitContinuationContext *stcc = value; | 1348 | struct SendTransmitContinuationContext *stcc = value; |
1361 | 1349 | ||
@@ -1371,19 +1359,19 @@ mark_peer_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) | |||
1371 | * @param peer peer that disconnected | 1359 | * @param peer peer that disconnected |
1372 | */ | 1360 | */ |
1373 | void | 1361 | void |
1374 | GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer) | 1362 | GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer) |
1375 | { | 1363 | { |
1376 | struct DisconnectInfoMessage disconnect_msg; | 1364 | struct DisconnectInfoMessage disconnect_msg; |
1377 | 1365 | ||
1378 | GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs, | 1366 | GNUNET_CONTAINER_multipeermap_get_multiple(active_stccs, |
1379 | peer, | 1367 | peer, |
1380 | &mark_peer_down, | 1368 | &mark_peer_down, |
1381 | NULL); | 1369 | NULL); |
1382 | disconnect_msg.header.size = htons (sizeof (struct DisconnectInfoMessage)); | 1370 | disconnect_msg.header.size = htons(sizeof(struct DisconnectInfoMessage)); |
1383 | disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); | 1371 | disconnect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); |
1384 | disconnect_msg.reserved = htonl (0); | 1372 | disconnect_msg.reserved = htonl(0); |
1385 | disconnect_msg.peer = *peer; | 1373 | disconnect_msg.peer = *peer; |
1386 | GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO); | 1374 | GST_clients_broadcast(&disconnect_msg.header, GNUNET_NO); |
1387 | } | 1375 | } |
1388 | 1376 | ||
1389 | 1377 | ||
@@ -1399,27 +1387,27 @@ GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer) | |||
1399 | * @param bandwidth_out outbound quota in NBO | 1387 | * @param bandwidth_out outbound quota in NBO |
1400 | */ | 1388 | */ |
1401 | static void | 1389 | static void |
1402 | transmit_our_hello (void *cls, | 1390 | transmit_our_hello(void *cls, |
1403 | const struct GNUNET_PeerIdentity *peer, | 1391 | const struct GNUNET_PeerIdentity *peer, |
1404 | const struct GNUNET_HELLO_Address *address, | 1392 | const struct GNUNET_HELLO_Address *address, |
1405 | enum GNUNET_TRANSPORT_PeerState state, | 1393 | enum GNUNET_TRANSPORT_PeerState state, |
1406 | struct GNUNET_TIME_Absolute state_timeout, | 1394 | struct GNUNET_TIME_Absolute state_timeout, |
1407 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 1395 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
1408 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 1396 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) |
1409 | { | 1397 | { |
1410 | const struct GNUNET_MessageHeader *hello = cls; | 1398 | const struct GNUNET_MessageHeader *hello = cls; |
1411 | 1399 | ||
1412 | if (0 == memcmp (peer, &GST_my_identity, sizeof (struct GNUNET_PeerIdentity))) | 1400 | if (0 == memcmp(peer, &GST_my_identity, sizeof(struct GNUNET_PeerIdentity))) |
1413 | return; /* not to ourselves */ | 1401 | return; /* not to ourselves */ |
1414 | if (GNUNET_NO == GST_neighbours_test_connected (peer)) | 1402 | if (GNUNET_NO == GST_neighbours_test_connected(peer)) |
1415 | return; | 1403 | return; |
1416 | 1404 | ||
1417 | GST_neighbours_send (peer, | 1405 | GST_neighbours_send(peer, |
1418 | hello, | 1406 | hello, |
1419 | ntohs (hello->size), | 1407 | ntohs(hello->size), |
1420 | hello_expiration, | 1408 | hello_expiration, |
1421 | NULL, | 1409 | NULL, |
1422 | NULL); | 1410 | NULL); |
1423 | } | 1411 | } |
1424 | 1412 | ||
1425 | 1413 | ||
@@ -1430,12 +1418,12 @@ transmit_our_hello (void *cls, | |||
1430 | * @param hello new HELLO | 1418 | * @param hello new HELLO |
1431 | */ | 1419 | */ |
1432 | static void | 1420 | static void |
1433 | process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) | 1421 | process_hello_update(void *cls, const struct GNUNET_MessageHeader *hello) |
1434 | { | 1422 | { |
1435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n"); | 1423 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n"); |
1436 | GST_clients_broadcast (hello, GNUNET_NO); | 1424 | GST_clients_broadcast(hello, GNUNET_NO); |
1437 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n"); | 1425 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n"); |
1438 | GST_neighbours_iterate (&transmit_our_hello, (void *) hello); | 1426 | GST_neighbours_iterate(&transmit_our_hello, (void *)hello); |
1439 | } | 1427 | } |
1440 | 1428 | ||
1441 | 1429 | ||
@@ -1450,44 +1438,44 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) | |||
1450 | * @return how long the plugin should wait until receiving more data | 1438 | * @return how long the plugin should wait until receiving more data |
1451 | */ | 1439 | */ |
1452 | static struct GNUNET_TIME_Relative | 1440 | static struct GNUNET_TIME_Relative |
1453 | process_payload (const struct GNUNET_HELLO_Address *address, | 1441 | process_payload(const struct GNUNET_HELLO_Address *address, |
1454 | struct GNUNET_ATS_Session *session, | 1442 | struct GNUNET_ATS_Session *session, |
1455 | const struct GNUNET_MessageHeader *message) | 1443 | const struct GNUNET_MessageHeader *message) |
1456 | { | 1444 | { |
1457 | struct GNUNET_TIME_Relative ret; | 1445 | struct GNUNET_TIME_Relative ret; |
1458 | int do_forward; | 1446 | int do_forward; |
1459 | struct InboundMessage *im; | 1447 | struct InboundMessage *im; |
1460 | size_t msg_size = ntohs (message->size); | 1448 | size_t msg_size = ntohs(message->size); |
1461 | size_t size = sizeof (struct InboundMessage) + msg_size; | 1449 | size_t size = sizeof(struct InboundMessage) + msg_size; |
1462 | char buf[size] GNUNET_ALIGN; | 1450 | char buf[size] GNUNET_ALIGN; |
1463 | 1451 | ||
1464 | do_forward = GNUNET_SYSERR; | 1452 | do_forward = GNUNET_SYSERR; |
1465 | ret = GST_neighbours_calculate_receive_delay (&address->peer, | 1453 | ret = GST_neighbours_calculate_receive_delay(&address->peer, |
1466 | msg_size, | 1454 | msg_size, |
1467 | &do_forward); | 1455 | &do_forward); |
1468 | if (! GST_neighbours_test_connected (&address->peer)) | 1456 | if (!GST_neighbours_test_connected(&address->peer)) |
1469 | { | 1457 | { |
1470 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1458 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1471 | "Discarded %u bytes type %u payload from peer `%s'\n", | 1459 | "Discarded %u bytes type %u payload from peer `%s'\n", |
1472 | (unsigned int) msg_size, | 1460 | (unsigned int)msg_size, |
1473 | ntohs (message->type), | 1461 | ntohs(message->type), |
1474 | GNUNET_i2s (&address->peer)); | 1462 | GNUNET_i2s(&address->peer)); |
1475 | GNUNET_STATISTICS_update ( | 1463 | GNUNET_STATISTICS_update( |
1476 | GST_stats, | 1464 | GST_stats, |
1477 | gettext_noop ("# bytes payload discarded due to not connected peer"), | 1465 | gettext_noop("# bytes payload discarded due to not connected peer"), |
1478 | msg_size, | 1466 | msg_size, |
1479 | GNUNET_NO); | 1467 | GNUNET_NO); |
1480 | return ret; | 1468 | return ret; |
1481 | } | 1469 | } |
1482 | 1470 | ||
1483 | if (GNUNET_YES != do_forward) | 1471 | if (GNUNET_YES != do_forward) |
1484 | return ret; | 1472 | return ret; |
1485 | im = (struct InboundMessage *) buf; | 1473 | im = (struct InboundMessage *)buf; |
1486 | im->header.size = htons (size); | 1474 | im->header.size = htons(size); |
1487 | im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); | 1475 | im->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); |
1488 | im->peer = address->peer; | 1476 | im->peer = address->peer; |
1489 | GNUNET_memcpy (&im[1], message, ntohs (message->size)); | 1477 | GNUNET_memcpy(&im[1], message, ntohs(message->size)); |
1490 | GST_clients_broadcast (&im->header, GNUNET_YES); | 1478 | GST_clients_broadcast(&im->header, GNUNET_YES); |
1491 | return ret; | 1479 | return ret; |
1492 | } | 1480 | } |
1493 | 1481 | ||
@@ -1498,14 +1486,14 @@ process_payload (const struct GNUNET_HELLO_Address *address, | |||
1498 | * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill | 1486 | * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill |
1499 | */ | 1487 | */ |
1500 | static void | 1488 | static void |
1501 | kill_session_task (void *cls) | 1489 | kill_session_task(void *cls) |
1502 | { | 1490 | { |
1503 | struct GNUNET_ATS_SessionKiller *sk = cls; | 1491 | struct GNUNET_ATS_SessionKiller *sk = cls; |
1504 | 1492 | ||
1505 | sk->task = NULL; | 1493 | sk->task = NULL; |
1506 | GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); | 1494 | GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); |
1507 | sk->plugin->disconnect_session (sk->plugin->cls, sk->session); | 1495 | sk->plugin->disconnect_session(sk->plugin->cls, sk->session); |
1508 | GNUNET_free (sk); | 1496 | GNUNET_free(sk); |
1509 | } | 1497 | } |
1510 | 1498 | ||
1511 | 1499 | ||
@@ -1517,7 +1505,7 @@ kill_session_task (void *cls) | |||
1517 | * @param session session to termiante | 1505 | * @param session session to termiante |
1518 | */ | 1506 | */ |
1519 | static void | 1507 | static void |
1520 | kill_session (const char *plugin_name, struct GNUNET_ATS_Session *session) | 1508 | kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session) |
1521 | { | 1509 | { |
1522 | struct GNUNET_TRANSPORT_PluginFunctions *plugin; | 1510 | struct GNUNET_TRANSPORT_PluginFunctions *plugin; |
1523 | struct GNUNET_ATS_SessionKiller *sk; | 1511 | struct GNUNET_ATS_SessionKiller *sk; |
@@ -1525,18 +1513,18 @@ kill_session (const char *plugin_name, struct GNUNET_ATS_Session *session) | |||
1525 | for (sk = sk_head; NULL != sk; sk = sk->next) | 1513 | for (sk = sk_head; NULL != sk; sk = sk->next) |
1526 | if (sk->session == session) | 1514 | if (sk->session == session) |
1527 | return; | 1515 | return; |
1528 | plugin = GST_plugins_find (plugin_name); | 1516 | plugin = GST_plugins_find(plugin_name); |
1529 | if (NULL == plugin) | 1517 | if (NULL == plugin) |
1530 | { | 1518 | { |
1531 | GNUNET_break (0); | 1519 | GNUNET_break(0); |
1532 | return; | 1520 | return; |
1533 | } | 1521 | } |
1534 | /* need to issue disconnect asynchronously */ | 1522 | /* need to issue disconnect asynchronously */ |
1535 | sk = GNUNET_new (struct GNUNET_ATS_SessionKiller); | 1523 | sk = GNUNET_new(struct GNUNET_ATS_SessionKiller); |
1536 | sk->session = session; | 1524 | sk->session = session; |
1537 | sk->plugin = plugin; | 1525 | sk->plugin = plugin; |
1538 | sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk); | 1526 | sk->task = GNUNET_SCHEDULER_add_now(&kill_session_task, sk); |
1539 | GNUNET_CONTAINER_DLL_insert (sk_head, sk_tail, sk); | 1527 | GNUNET_CONTAINER_DLL_insert(sk_head, sk_tail, sk); |
1540 | } | 1528 | } |
1541 | 1529 | ||
1542 | 1530 | ||
@@ -1551,37 +1539,37 @@ kill_session (const char *plugin_name, struct GNUNET_ATS_Session *session) | |||
1551 | * @param result the result | 1539 | * @param result the result |
1552 | */ | 1540 | */ |
1553 | static void | 1541 | static void |
1554 | connect_bl_check_cont (void *cls, | 1542 | connect_bl_check_cont(void *cls, |
1555 | const struct GNUNET_PeerIdentity *peer, | 1543 | const struct GNUNET_PeerIdentity *peer, |
1556 | const struct GNUNET_HELLO_Address *address, | 1544 | const struct GNUNET_HELLO_Address *address, |
1557 | struct GNUNET_ATS_Session *session, | 1545 | struct GNUNET_ATS_Session *session, |
1558 | int result) | 1546 | int result) |
1559 | { | 1547 | { |
1560 | struct GNUNET_MessageHeader *msg = cls; | 1548 | struct GNUNET_MessageHeader *msg = cls; |
1561 | 1549 | ||
1562 | if (GNUNET_OK == result) | 1550 | if (GNUNET_OK == result) |
1563 | { | ||
1564 | /* Blacklist allows to speak to this peer, forward SYN to neighbours */ | ||
1565 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1566 | "Received SYN message from peer `%s' at `%s'\n", | ||
1567 | GNUNET_i2s (peer), | ||
1568 | GST_plugins_a2s (address)); | ||
1569 | if (GNUNET_OK != GST_neighbours_handle_session_syn (msg, peer)) | ||
1570 | { | 1551 | { |
1571 | GST_blacklist_abort_matching (address, session); | 1552 | /* Blacklist allows to speak to this peer, forward SYN to neighbours */ |
1572 | kill_session (address->transport_name, session); | 1553 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1554 | "Received SYN message from peer `%s' at `%s'\n", | ||
1555 | GNUNET_i2s(peer), | ||
1556 | GST_plugins_a2s(address)); | ||
1557 | if (GNUNET_OK != GST_neighbours_handle_session_syn(msg, peer)) | ||
1558 | { | ||
1559 | GST_blacklist_abort_matching(address, session); | ||
1560 | kill_session(address->transport_name, session); | ||
1561 | } | ||
1562 | GNUNET_free(msg); | ||
1563 | return; | ||
1573 | } | 1564 | } |
1574 | GNUNET_free (msg); | 1565 | GNUNET_free(msg); |
1575 | return; | ||
1576 | } | ||
1577 | GNUNET_free (msg); | ||
1578 | if (GNUNET_SYSERR == result) | 1566 | if (GNUNET_SYSERR == result) |
1579 | return; /* check was aborted, session destroyed */ | 1567 | return; /* check was aborted, session destroyed */ |
1580 | /* Blacklist denies to speak to this peer */ | 1568 | /* Blacklist denies to speak to this peer */ |
1581 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1569 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1582 | "Discarding SYN message from `%s' due to denied blacklist check\n", | 1570 | "Discarding SYN message from `%s' due to denied blacklist check\n", |
1583 | GNUNET_i2s (peer)); | 1571 | GNUNET_i2s(peer)); |
1584 | kill_session (address->transport_name, session); | 1572 | kill_session(address->transport_name, session); |
1585 | } | 1573 | } |
1586 | 1574 | ||
1587 | 1575 | ||
@@ -1599,10 +1587,10 @@ connect_bl_check_cont (void *cls, | |||
1599 | * (plugins that do not support this, can ignore the return value) | 1587 | * (plugins that do not support this, can ignore the return value) |
1600 | */ | 1588 | */ |
1601 | struct GNUNET_TIME_Relative | 1589 | struct GNUNET_TIME_Relative |
1602 | GST_receive_callback (void *cls, | 1590 | GST_receive_callback(void *cls, |
1603 | const struct GNUNET_HELLO_Address *address, | 1591 | const struct GNUNET_HELLO_Address *address, |
1604 | struct GNUNET_ATS_Session *session, | 1592 | struct GNUNET_ATS_Session *session, |
1605 | const struct GNUNET_MessageHeader *message) | 1593 | const struct GNUNET_MessageHeader *message) |
1606 | { | 1594 | { |
1607 | const char *plugin_name = cls; | 1595 | const char *plugin_name = cls; |
1608 | struct GNUNET_TIME_Relative ret; | 1596 | struct GNUNET_TIME_Relative ret; |
@@ -1611,104 +1599,115 @@ GST_receive_callback (void *cls, | |||
1611 | ret = GNUNET_TIME_UNIT_ZERO; | 1599 | ret = GNUNET_TIME_UNIT_ZERO; |
1612 | if (NULL == message) | 1600 | if (NULL == message) |
1613 | goto end; | 1601 | goto end; |
1614 | type = ntohs (message->type); | 1602 | type = ntohs(message->type); |
1615 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1603 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1616 | "Received message with type %u from peer `%s' at %s\n", | 1604 | "Received message with type %u from peer `%s' at %s\n", |
1617 | type, | 1605 | type, |
1618 | GNUNET_i2s (&address->peer), | 1606 | GNUNET_i2s(&address->peer), |
1619 | GST_plugins_a2s (address)); | 1607 | GST_plugins_a2s(address)); |
1620 | 1608 | ||
1621 | GNUNET_STATISTICS_update (GST_stats, | 1609 | GNUNET_STATISTICS_update(GST_stats, |
1622 | gettext_noop ("# bytes total received"), | 1610 | gettext_noop("# bytes total received"), |
1623 | ntohs (message->size), | 1611 | ntohs(message->size), |
1624 | GNUNET_NO); | 1612 | GNUNET_NO); |
1625 | GST_neighbours_notify_data_recv (address, message); | 1613 | GST_neighbours_notify_data_recv(address, message); |
1626 | switch (type) | 1614 | switch (type) |
1627 | { | ||
1628 | case GNUNET_MESSAGE_TYPE_HELLO_LEGACY: | ||
1629 | /* Legacy HELLO message, discard */ | ||
1630 | return ret; | ||
1631 | case GNUNET_MESSAGE_TYPE_HELLO: | ||
1632 | if (GNUNET_OK != GST_validation_handle_hello (message)) | ||
1633 | { | 1615 | { |
1634 | GNUNET_break_op (0); | 1616 | case GNUNET_MESSAGE_TYPE_HELLO_LEGACY: |
1635 | GST_blacklist_abort_matching (address, session); | 1617 | /* Legacy HELLO message, discard */ |
1636 | } | 1618 | return ret; |
1637 | return ret; | 1619 | |
1638 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: | 1620 | case GNUNET_MESSAGE_TYPE_HELLO: |
1639 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1621 | if (GNUNET_OK != GST_validation_handle_hello(message)) |
1640 | "Processing PING from `%s'\n", | 1622 | { |
1641 | GST_plugins_a2s (address)); | 1623 | GNUNET_break_op(0); |
1642 | if (GNUNET_OK != | 1624 | GST_blacklist_abort_matching(address, session); |
1643 | GST_validation_handle_ping (&address->peer, message, address, session)) | 1625 | } |
1644 | { | 1626 | return ret; |
1645 | GST_blacklist_abort_matching (address, session); | 1627 | |
1646 | kill_session (plugin_name, session); | 1628 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: |
1647 | } | 1629 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1648 | break; | 1630 | "Processing PING from `%s'\n", |
1649 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: | 1631 | GST_plugins_a2s(address)); |
1650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1632 | if (GNUNET_OK != |
1651 | "Processing PONG from `%s'\n", | 1633 | GST_validation_handle_ping(&address->peer, message, address, session)) |
1652 | GST_plugins_a2s (address)); | 1634 | { |
1653 | if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message)) | 1635 | GST_blacklist_abort_matching(address, session); |
1654 | { | 1636 | kill_session(plugin_name, session); |
1655 | GNUNET_break_op (0); | 1637 | } |
1656 | GST_blacklist_abort_matching (address, session); | 1638 | break; |
1657 | kill_session (plugin_name, session); | 1639 | |
1658 | } | 1640 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: |
1659 | break; | 1641 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1660 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN: | 1642 | "Processing PONG from `%s'\n", |
1661 | /* Do blacklist check if communication with this peer is allowed */ | 1643 | GST_plugins_a2s(address)); |
1662 | (void) GST_blacklist_test_allowed (&address->peer, | 1644 | if (GNUNET_OK != GST_validation_handle_pong(&address->peer, message)) |
1645 | { | ||
1646 | GNUNET_break_op(0); | ||
1647 | GST_blacklist_abort_matching(address, session); | ||
1648 | kill_session(plugin_name, session); | ||
1649 | } | ||
1650 | break; | ||
1651 | |||
1652 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN: | ||
1653 | /* Do blacklist check if communication with this peer is allowed */ | ||
1654 | (void)GST_blacklist_test_allowed(&address->peer, | ||
1663 | NULL, | 1655 | NULL, |
1664 | &connect_bl_check_cont, | 1656 | &connect_bl_check_cont, |
1665 | GNUNET_copy_message (message), | 1657 | GNUNET_copy_message(message), |
1666 | address, | 1658 | address, |
1667 | session); | 1659 | session); |
1668 | break; | 1660 | break; |
1669 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK: | 1661 | |
1670 | if (GNUNET_OK != | 1662 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK: |
1671 | GST_neighbours_handle_session_syn_ack (message, address, session)) | 1663 | if (GNUNET_OK != |
1672 | { | 1664 | GST_neighbours_handle_session_syn_ack(message, address, session)) |
1673 | GST_blacklist_abort_matching (address, session); | 1665 | { |
1674 | kill_session (plugin_name, session); | 1666 | GST_blacklist_abort_matching(address, session); |
1675 | } | 1667 | kill_session(plugin_name, session); |
1676 | break; | 1668 | } |
1677 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: | 1669 | break; |
1678 | if (GNUNET_OK != | 1670 | |
1679 | GST_neighbours_handle_session_ack (message, address, session)) | 1671 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: |
1680 | { | 1672 | if (GNUNET_OK != |
1681 | GNUNET_break_op (0); | 1673 | GST_neighbours_handle_session_ack(message, address, session)) |
1682 | GST_blacklist_abort_matching (address, session); | 1674 | { |
1683 | kill_session (plugin_name, session); | 1675 | GNUNET_break_op(0); |
1684 | } | 1676 | GST_blacklist_abort_matching(address, session); |
1685 | break; | 1677 | kill_session(plugin_name, session); |
1686 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: | 1678 | } |
1687 | GST_neighbours_handle_disconnect_message (&address->peer, message); | 1679 | break; |
1688 | break; | 1680 | |
1689 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA: | 1681 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: |
1690 | GST_neighbours_handle_quota_message (&address->peer, message); | 1682 | GST_neighbours_handle_disconnect_message(&address->peer, message); |
1691 | break; | 1683 | break; |
1692 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: | 1684 | |
1693 | GST_neighbours_keepalive (&address->peer, message); | 1685 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA: |
1694 | break; | 1686 | GST_neighbours_handle_quota_message(&address->peer, message); |
1695 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: | 1687 | break; |
1696 | GST_neighbours_keepalive_response (&address->peer, message); | 1688 | |
1697 | break; | 1689 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: |
1698 | default: | 1690 | GST_neighbours_keepalive(&address->peer, message); |
1699 | /* should be payload */ | 1691 | break; |
1700 | GNUNET_STATISTICS_update (GST_stats, | 1692 | |
1701 | gettext_noop ("# bytes payload received"), | 1693 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: |
1702 | ntohs (message->size), | 1694 | GST_neighbours_keepalive_response(&address->peer, message); |
1703 | GNUNET_NO); | 1695 | break; |
1704 | ret = process_payload (address, session, message); | 1696 | |
1705 | break; | 1697 | default: |
1706 | } | 1698 | /* should be payload */ |
1699 | GNUNET_STATISTICS_update(GST_stats, | ||
1700 | gettext_noop("# bytes payload received"), | ||
1701 | ntohs(message->size), | ||
1702 | GNUNET_NO); | ||
1703 | ret = process_payload(address, session, message); | ||
1704 | break; | ||
1705 | } | ||
1707 | end: | 1706 | end: |
1708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1707 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1709 | "Allowing receive from peer %s to continue in %s\n", | 1708 | "Allowing receive from peer %s to continue in %s\n", |
1710 | GNUNET_i2s (&address->peer), | 1709 | GNUNET_i2s(&address->peer), |
1711 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); | 1710 | GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); |
1712 | return ret; | 1711 | return ret; |
1713 | } | 1712 | } |
1714 | 1713 | ||
@@ -1723,7 +1722,7 @@ end: | |||
1723 | * @param address the address to add or remove | 1722 | * @param address the address to add or remove |
1724 | */ | 1723 | */ |
1725 | static void | 1724 | static void |
1726 | plugin_env_address_change_notification ( | 1725 | plugin_env_address_change_notification( |
1727 | void *cls, | 1726 | void *cls, |
1728 | int add_remove, | 1727 | int add_remove, |
1729 | const struct GNUNET_HELLO_Address *address) | 1728 | const struct GNUNET_HELLO_Address *address) |
@@ -1731,29 +1730,29 @@ plugin_env_address_change_notification ( | |||
1731 | static int addresses = 0; | 1730 | static int addresses = 0; |
1732 | 1731 | ||
1733 | if (GNUNET_YES == add_remove) | 1732 | if (GNUNET_YES == add_remove) |
1734 | { | ||
1735 | addresses++; | ||
1736 | GNUNET_STATISTICS_update (GST_stats, "# transport addresses", 1, GNUNET_NO); | ||
1737 | } | ||
1738 | else if (GNUNET_NO == add_remove) | ||
1739 | { | ||
1740 | if (0 == addresses) | ||
1741 | { | 1733 | { |
1742 | GNUNET_break (0); | 1734 | addresses++; |
1735 | GNUNET_STATISTICS_update(GST_stats, "# transport addresses", 1, GNUNET_NO); | ||
1743 | } | 1736 | } |
1744 | else | 1737 | else if (GNUNET_NO == add_remove) |
1745 | { | 1738 | { |
1746 | addresses--; | 1739 | if (0 == addresses) |
1747 | GNUNET_STATISTICS_update (GST_stats, | 1740 | { |
1748 | "# transport addresses", | 1741 | GNUNET_break(0); |
1749 | -1, | 1742 | } |
1750 | GNUNET_NO); | 1743 | else |
1744 | { | ||
1745 | addresses--; | ||
1746 | GNUNET_STATISTICS_update(GST_stats, | ||
1747 | "# transport addresses", | ||
1748 | -1, | ||
1749 | GNUNET_NO); | ||
1750 | } | ||
1751 | } | 1751 | } |
1752 | } | 1752 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1753 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1753 | "Transport now has %u addresses to communicate\n", |
1754 | "Transport now has %u addresses to communicate\n", | 1754 | addresses); |
1755 | addresses); | 1755 | GST_hello_modify_addresses(add_remove, address); |
1756 | GST_hello_modify_addresses (add_remove, address); | ||
1757 | } | 1756 | } |
1758 | 1757 | ||
1759 | 1758 | ||
@@ -1771,45 +1770,45 @@ plugin_env_address_change_notification ( | |||
1771 | * @param session which session is being destoyed | 1770 | * @param session which session is being destoyed |
1772 | */ | 1771 | */ |
1773 | static void | 1772 | static void |
1774 | plugin_env_session_end (void *cls, | 1773 | plugin_env_session_end(void *cls, |
1775 | const struct GNUNET_HELLO_Address *address, | 1774 | const struct GNUNET_HELLO_Address *address, |
1776 | struct GNUNET_ATS_Session *session) | 1775 | struct GNUNET_ATS_Session *session) |
1777 | { | 1776 | { |
1778 | struct GNUNET_ATS_SessionKiller *sk; | 1777 | struct GNUNET_ATS_SessionKiller *sk; |
1779 | 1778 | ||
1780 | if (NULL == address) | 1779 | if (NULL == address) |
1781 | { | 1780 | { |
1782 | GNUNET_break (0); | 1781 | GNUNET_break(0); |
1783 | return; | 1782 | return; |
1784 | } | 1783 | } |
1785 | if (NULL == session) | 1784 | if (NULL == session) |
1786 | { | 1785 | { |
1787 | GNUNET_break (0); | 1786 | GNUNET_break(0); |
1788 | return; | 1787 | return; |
1789 | } | 1788 | } |
1790 | GNUNET_assert (strlen (address->transport_name) > 0); | 1789 | GNUNET_assert(strlen(address->transport_name) > 0); |
1791 | 1790 | ||
1792 | GNUNET_log ( | 1791 | GNUNET_log( |
1793 | GNUNET_ERROR_TYPE_DEBUG, | 1792 | GNUNET_ERROR_TYPE_DEBUG, |
1794 | "Notification from plugin about terminated session %p from peer `%s' address `%s'\n", | 1793 | "Notification from plugin about terminated session %p from peer `%s' address `%s'\n", |
1795 | session, | 1794 | session, |
1796 | GNUNET_i2s (&address->peer), | 1795 | GNUNET_i2s(&address->peer), |
1797 | GST_plugins_a2s (address)); | 1796 | GST_plugins_a2s(address)); |
1798 | 1797 | ||
1799 | GST_neighbours_session_terminated (&address->peer, session); | 1798 | GST_neighbours_session_terminated(&address->peer, session); |
1800 | GST_ats_del_session (address, session); | 1799 | GST_ats_del_session(address, session); |
1801 | GST_blacklist_abort_matching (address, session); | 1800 | GST_blacklist_abort_matching(address, session); |
1802 | 1801 | ||
1803 | for (sk = sk_head; NULL != sk; sk = sk->next) | 1802 | for (sk = sk_head; NULL != sk; sk = sk->next) |
1804 | { | ||
1805 | if (sk->session == session) | ||
1806 | { | 1803 | { |
1807 | GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); | 1804 | if (sk->session == session) |
1808 | GNUNET_SCHEDULER_cancel (sk->task); | 1805 | { |
1809 | GNUNET_free (sk); | 1806 | GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); |
1810 | break; | 1807 | GNUNET_SCHEDULER_cancel(sk->task); |
1808 | GNUNET_free(sk); | ||
1809 | break; | ||
1810 | } | ||
1811 | } | 1811 | } |
1812 | } | ||
1813 | } | 1812 | } |
1814 | 1813 | ||
1815 | 1814 | ||
@@ -1825,7 +1824,7 @@ plugin_env_session_end (void *cls, | |||
1825 | * @param result the result | 1824 | * @param result the result |
1826 | */ | 1825 | */ |
1827 | static void | 1826 | static void |
1828 | plugin_env_session_start_bl_check_cont ( | 1827 | plugin_env_session_start_bl_check_cont( |
1829 | void *cls, | 1828 | void *cls, |
1830 | const struct GNUNET_PeerIdentity *peer, | 1829 | const struct GNUNET_PeerIdentity *peer, |
1831 | const struct GNUNET_HELLO_Address *address, | 1830 | const struct GNUNET_HELLO_Address *address, |
@@ -1833,19 +1832,19 @@ plugin_env_session_start_bl_check_cont ( | |||
1833 | int result) | 1832 | int result) |
1834 | { | 1833 | { |
1835 | if (GNUNET_OK != result) | 1834 | if (GNUNET_OK != result) |
1836 | { | 1835 | { |
1837 | kill_session (address->transport_name, session); | 1836 | kill_session(address->transport_name, session); |
1838 | return; | 1837 | return; |
1839 | } | 1838 | } |
1840 | if (GNUNET_YES != | 1839 | if (GNUNET_YES != |
1841 | GNUNET_HELLO_address_check_option (address, | 1840 | GNUNET_HELLO_address_check_option(address, |
1842 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | 1841 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) |
1843 | { | 1842 | { |
1844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1843 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1845 | "Informing verifier about inbound session's address `%s'\n", | 1844 | "Informing verifier about inbound session's address `%s'\n", |
1846 | GST_plugins_a2s (address)); | 1845 | GST_plugins_a2s(address)); |
1847 | GST_validation_handle_address (address); | 1846 | GST_validation_handle_address(address); |
1848 | } | 1847 | } |
1849 | } | 1848 | } |
1850 | 1849 | ||
1851 | 1850 | ||
@@ -1858,49 +1857,49 @@ plugin_env_session_start_bl_check_cont ( | |||
1858 | * @param scope network scope information | 1857 | * @param scope network scope information |
1859 | */ | 1858 | */ |
1860 | static void | 1859 | static void |
1861 | plugin_env_session_start (void *cls, | 1860 | plugin_env_session_start(void *cls, |
1862 | const struct GNUNET_HELLO_Address *address, | 1861 | const struct GNUNET_HELLO_Address *address, |
1863 | struct GNUNET_ATS_Session *session, | 1862 | struct GNUNET_ATS_Session *session, |
1864 | enum GNUNET_NetworkType scope) | 1863 | enum GNUNET_NetworkType scope) |
1865 | { | 1864 | { |
1866 | struct GNUNET_ATS_Properties prop; | 1865 | struct GNUNET_ATS_Properties prop; |
1867 | 1866 | ||
1868 | if (NULL == address) | 1867 | if (NULL == address) |
1869 | { | 1868 | { |
1870 | GNUNET_break (0); | 1869 | GNUNET_break(0); |
1871 | return; | 1870 | return; |
1872 | } | 1871 | } |
1873 | if (NULL == session) | 1872 | if (NULL == session) |
1874 | { | 1873 | { |
1875 | GNUNET_break (0); | 1874 | GNUNET_break(0); |
1876 | return; | 1875 | return; |
1877 | } | 1876 | } |
1878 | GNUNET_log ( | 1877 | GNUNET_log( |
1879 | GNUNET_ERROR_TYPE_INFO, | 1878 | GNUNET_ERROR_TYPE_INFO, |
1880 | "Notification from plugin `%s' about new session from peer `%s' address `%s'\n", | 1879 | "Notification from plugin `%s' about new session from peer `%s' address `%s'\n", |
1881 | address->transport_name, | 1880 | address->transport_name, |
1882 | GNUNET_i2s (&address->peer), | 1881 | GNUNET_i2s(&address->peer), |
1883 | GST_plugins_a2s (address)); | 1882 | GST_plugins_a2s(address)); |
1884 | if (GNUNET_YES == | 1883 | if (GNUNET_YES == |
1885 | GNUNET_HELLO_address_check_option (address, | 1884 | GNUNET_HELLO_address_check_option(address, |
1886 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | 1885 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) |
1887 | { | 1886 | { |
1888 | /* inbound is always new, but outbound MAY already be known, but | 1887 | /* inbound is always new, but outbound MAY already be known, but |
1889 | for example for UNIX, we have symmetric connections and thus we | 1888 | for example for UNIX, we have symmetric connections and thus we |
1890 | may not know the address yet; add if necessary! */ | 1889 | may not know the address yet; add if necessary! */ |
1891 | /* FIXME: maybe change API here so we just pass scope? */ | 1890 | /* FIXME: maybe change API here so we just pass scope? */ |
1892 | memset (&prop, 0, sizeof (prop)); | 1891 | memset(&prop, 0, sizeof(prop)); |
1893 | GNUNET_break (GNUNET_NT_UNSPECIFIED != scope); | 1892 | GNUNET_break(GNUNET_NT_UNSPECIFIED != scope); |
1894 | prop.scope = scope; | 1893 | prop.scope = scope; |
1895 | GST_ats_add_inbound_address (address, session, &prop); | 1894 | GST_ats_add_inbound_address(address, session, &prop); |
1896 | } | 1895 | } |
1897 | /* Do blacklist check if communication with this peer is allowed */ | 1896 | /* Do blacklist check if communication with this peer is allowed */ |
1898 | (void) GST_blacklist_test_allowed (&address->peer, | 1897 | (void)GST_blacklist_test_allowed(&address->peer, |
1899 | address->transport_name, | 1898 | address->transport_name, |
1900 | &plugin_env_session_start_bl_check_cont, | 1899 | &plugin_env_session_start_bl_check_cont, |
1901 | NULL, | 1900 | NULL, |
1902 | address, | 1901 | address, |
1903 | session); | 1902 | session); |
1904 | } | 1903 | } |
1905 | 1904 | ||
1906 | 1905 | ||
@@ -1916,59 +1915,58 @@ plugin_env_session_start (void *cls, | |||
1916 | * @param address address to use (for peer given in address) | 1915 | * @param address address to use (for peer given in address) |
1917 | * @param session session to use (if available) | 1916 | * @param session session to use (if available) |
1918 | * @param bandwidth_out assigned outbound bandwidth for the connection in NBO, | 1917 | * @param bandwidth_out assigned outbound bandwidth for the connection in NBO, |
1919 | * 0 to disconnect from peer | 1918 | * 0 to disconnect from peer |
1920 | * @param bandwidth_in assigned inbound bandwidth for the connection in NBO, | 1919 | * @param bandwidth_in assigned inbound bandwidth for the connection in NBO, |
1921 | * 0 to disconnect from peer | 1920 | * 0 to disconnect from peer |
1922 | * @param ats ATS information | 1921 | * @param ats ATS information |
1923 | * @param ats_count number of @a ats elements | 1922 | * @param ats_count number of @a ats elements |
1924 | */ | 1923 | */ |
1925 | static void | 1924 | static void |
1926 | ats_request_address_change (void *cls, | 1925 | ats_request_address_change(void *cls, |
1927 | const struct GNUNET_PeerIdentity *peer, | 1926 | const struct GNUNET_PeerIdentity *peer, |
1928 | const struct GNUNET_HELLO_Address *address, | 1927 | const struct GNUNET_HELLO_Address *address, |
1929 | struct GNUNET_ATS_Session *session, | 1928 | struct GNUNET_ATS_Session *session, |
1930 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 1929 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
1931 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 1930 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
1932 | { | 1931 | { |
1933 | uint32_t bw_in = ntohl (bandwidth_in.value__); | 1932 | uint32_t bw_in = ntohl(bandwidth_in.value__); |
1934 | uint32_t bw_out = ntohl (bandwidth_out.value__); | 1933 | uint32_t bw_out = ntohl(bandwidth_out.value__); |
1935 | 1934 | ||
1936 | if (NULL == peer) | 1935 | if (NULL == peer) |
1937 | { | 1936 | { |
1938 | /* ATS service died, all suggestions become invalid! | 1937 | /* ATS service died, all suggestions become invalid! |
1939 | (but we'll keep using the allocations for a little | 1938 | (but we'll keep using the allocations for a little |
1940 | while, to keep going while ATS restarts) */ | 1939 | while, to keep going while ATS restarts) */ |
1941 | /* FIXME: We should drop all | 1940 | /* FIXME: We should drop all |
1942 | connections now, as ATS won't explicitly tell | 1941 | connections now, as ATS won't explicitly tell |
1943 | us and be unaware of ongoing resource allocations! */ | 1942 | us and be unaware of ongoing resource allocations! */ |
1944 | return; | 1943 | return; |
1945 | } | 1944 | } |
1946 | /* ATS tells me to disconnect from peer */ | 1945 | /* ATS tells me to disconnect from peer */ |
1947 | if ((0 == bw_in) && (0 == bw_out)) | 1946 | if ((0 == bw_in) && (0 == bw_out)) |
1948 | { | 1947 | { |
1949 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1948 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1950 | "ATS tells me to disconnect from peer `%s'\n", | 1949 | "ATS tells me to disconnect from peer `%s'\n", |
1951 | GNUNET_i2s (peer)); | 1950 | GNUNET_i2s(peer)); |
1952 | GST_neighbours_force_disconnect (peer); | 1951 | GST_neighbours_force_disconnect(peer); |
1953 | return; | 1952 | return; |
1954 | } | 1953 | } |
1955 | GNUNET_assert (NULL != address); | 1954 | GNUNET_assert(NULL != address); |
1956 | GNUNET_STATISTICS_update (GST_stats, | 1955 | GNUNET_STATISTICS_update(GST_stats, |
1957 | "# ATS suggestions received", | 1956 | "# ATS suggestions received", |
1958 | 1, | 1957 | 1, |
1959 | GNUNET_NO); | 1958 | GNUNET_NO); |
1960 | GST_neighbours_switch_to_address (address, | 1959 | GST_neighbours_switch_to_address(address, |
1961 | session, | 1960 | session, |
1962 | bandwidth_in, | 1961 | bandwidth_in, |
1963 | bandwidth_out); | 1962 | bandwidth_out); |
1964 | } | 1963 | } |
1965 | 1964 | ||
1966 | 1965 | ||
1967 | /** | 1966 | /** |
1968 | * Closure for #test_connection_ok(). | 1967 | * Closure for #test_connection_ok(). |
1969 | */ | 1968 | */ |
1970 | struct TestConnectionContext | 1969 | struct TestConnectionContext { |
1971 | { | ||
1972 | /** | 1970 | /** |
1973 | * Is this the first neighbour we're checking? | 1971 | * Is this the first neighbour we're checking? |
1974 | */ | 1972 | */ |
@@ -1993,19 +1991,19 @@ struct TestConnectionContext | |||
1993 | * #GNUNET_NO if we must shutdown the connection | 1991 | * #GNUNET_NO if we must shutdown the connection |
1994 | */ | 1992 | */ |
1995 | static void | 1993 | static void |
1996 | confirm_or_drop_neighbour (void *cls, | 1994 | confirm_or_drop_neighbour(void *cls, |
1997 | const struct GNUNET_PeerIdentity *peer, | 1995 | const struct GNUNET_PeerIdentity *peer, |
1998 | const struct GNUNET_HELLO_Address *address, | 1996 | const struct GNUNET_HELLO_Address *address, |
1999 | struct GNUNET_ATS_Session *session, | 1997 | struct GNUNET_ATS_Session *session, |
2000 | int allowed) | 1998 | int allowed) |
2001 | { | 1999 | { |
2002 | if (GNUNET_OK == allowed) | 2000 | if (GNUNET_OK == allowed) |
2003 | return; /* we're done */ | 2001 | return; /* we're done */ |
2004 | GNUNET_STATISTICS_update (GST_stats, | 2002 | GNUNET_STATISTICS_update(GST_stats, |
2005 | gettext_noop ("# disconnects due to blacklist"), | 2003 | gettext_noop("# disconnects due to blacklist"), |
2006 | 1, | 2004 | 1, |
2007 | GNUNET_NO); | 2005 | GNUNET_NO); |
2008 | GST_neighbours_force_disconnect (peer); | 2006 | GST_neighbours_force_disconnect(peer); |
2009 | } | 2007 | } |
2010 | 2008 | ||
2011 | 2009 | ||
@@ -2022,31 +2020,31 @@ confirm_or_drop_neighbour (void *cls, | |||
2022 | * @param bandwidth_out bandwidth assigned outbound | 2020 | * @param bandwidth_out bandwidth assigned outbound |
2023 | */ | 2021 | */ |
2024 | static void | 2022 | static void |
2025 | test_connection_ok (void *cls, | 2023 | test_connection_ok(void *cls, |
2026 | const struct GNUNET_PeerIdentity *peer, | 2024 | const struct GNUNET_PeerIdentity *peer, |
2027 | const struct GNUNET_HELLO_Address *address, | 2025 | const struct GNUNET_HELLO_Address *address, |
2028 | enum GNUNET_TRANSPORT_PeerState state, | 2026 | enum GNUNET_TRANSPORT_PeerState state, |
2029 | struct GNUNET_TIME_Absolute state_timeout, | 2027 | struct GNUNET_TIME_Absolute state_timeout, |
2030 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 2028 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
2031 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 2029 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) |
2032 | { | 2030 | { |
2033 | struct TestConnectionContext *tcc = cls; | 2031 | struct TestConnectionContext *tcc = cls; |
2034 | struct GST_BlacklistCheck *bc; | 2032 | struct GST_BlacklistCheck *bc; |
2035 | 2033 | ||
2036 | bc = GNUNET_new (struct GST_BlacklistCheck); | 2034 | bc = GNUNET_new(struct GST_BlacklistCheck); |
2037 | GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); | 2035 | GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc); |
2038 | bc->peer = *peer; | 2036 | bc->peer = *peer; |
2039 | bc->address = GNUNET_HELLO_address_copy (address); | 2037 | bc->address = GNUNET_HELLO_address_copy(address); |
2040 | bc->cont = &confirm_or_drop_neighbour; | 2038 | bc->cont = &confirm_or_drop_neighbour; |
2041 | bc->cont_cls = NULL; | 2039 | bc->cont_cls = NULL; |
2042 | bc->bl_pos = tcc->tc; | 2040 | bc->bl_pos = tcc->tc; |
2043 | if (GNUNET_YES == tcc->first) | 2041 | if (GNUNET_YES == tcc->first) |
2044 | { | 2042 | { |
2045 | /* all would wait for the same client, no need to | 2043 | /* all would wait for the same client, no need to |
2046 | * create more than just the first task right now */ | 2044 | * create more than just the first task right now */ |
2047 | bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); | 2045 | bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); |
2048 | tcc->first = GNUNET_NO; | 2046 | tcc->first = GNUNET_NO; |
2049 | } | 2047 | } |
2050 | } | 2048 | } |
2051 | 2049 | ||
2052 | 2050 | ||
@@ -2059,26 +2057,26 @@ test_connection_ok (void *cls, | |||
2059 | * @param message the blacklist-init message that was sent | 2057 | * @param message the blacklist-init message that was sent |
2060 | */ | 2058 | */ |
2061 | static void | 2059 | static void |
2062 | handle_client_blacklist_init (void *cls, | 2060 | handle_client_blacklist_init(void *cls, |
2063 | const struct GNUNET_MessageHeader *message) | 2061 | const struct GNUNET_MessageHeader *message) |
2064 | { | 2062 | { |
2065 | struct TransportClient *tc = cls; | 2063 | struct TransportClient *tc = cls; |
2066 | struct TestConnectionContext tcc; | 2064 | struct TestConnectionContext tcc; |
2067 | 2065 | ||
2068 | if (CT_NONE != tc->type) | 2066 | if (CT_NONE != tc->type) |
2069 | { | 2067 | { |
2070 | GNUNET_break (0); | 2068 | GNUNET_break(0); |
2071 | GNUNET_SERVICE_client_drop (tc->client); | 2069 | GNUNET_SERVICE_client_drop(tc->client); |
2072 | return; | 2070 | return; |
2073 | } | 2071 | } |
2074 | GNUNET_SERVICE_client_mark_monitor (tc->client); | 2072 | GNUNET_SERVICE_client_mark_monitor(tc->client); |
2075 | tc->type = CT_BLACKLIST; | 2073 | tc->type = CT_BLACKLIST; |
2076 | tc->details.blacklist.call_receive_done = GNUNET_YES; | 2074 | tc->details.blacklist.call_receive_done = GNUNET_YES; |
2077 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc); | 2075 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc); |
2078 | /* confirm that all existing connections are OK! */ | 2076 | /* confirm that all existing connections are OK! */ |
2079 | tcc.tc = tc; | 2077 | tcc.tc = tc; |
2080 | tcc.first = GNUNET_YES; | 2078 | tcc.first = GNUNET_YES; |
2081 | GST_neighbours_iterate (&test_connection_ok, &tcc); | 2079 | GST_neighbours_iterate(&test_connection_ok, &tcc); |
2082 | } | 2080 | } |
2083 | 2081 | ||
2084 | 2082 | ||
@@ -2091,13 +2089,13 @@ handle_client_blacklist_init (void *cls, | |||
2091 | * @return #GNUNET_OK (continue to iterate) | 2089 | * @return #GNUNET_OK (continue to iterate) |
2092 | */ | 2090 | */ |
2093 | static int | 2091 | static int |
2094 | free_blacklist_entry (void *cls, | 2092 | free_blacklist_entry(void *cls, |
2095 | const struct GNUNET_PeerIdentity *key, | 2093 | const struct GNUNET_PeerIdentity *key, |
2096 | void *value) | 2094 | void *value) |
2097 | { | 2095 | { |
2098 | char *be = value; | 2096 | char *be = value; |
2099 | 2097 | ||
2100 | GNUNET_free_non_null (be); | 2098 | GNUNET_free_non_null(be); |
2101 | return GNUNET_OK; | 2099 | return GNUNET_OK; |
2102 | } | 2100 | } |
2103 | 2101 | ||
@@ -2109,12 +2107,12 @@ free_blacklist_entry (void *cls, | |||
2109 | * @param message containing information | 2107 | * @param message containing information |
2110 | */ | 2108 | */ |
2111 | static void | 2109 | static void |
2112 | handle_client_set_metric (void *cls, const struct TrafficMetricMessage *tm) | 2110 | handle_client_set_metric(void *cls, const struct TrafficMetricMessage *tm) |
2113 | { | 2111 | { |
2114 | struct TransportClient *tc = cls; | 2112 | struct TransportClient *tc = cls; |
2115 | 2113 | ||
2116 | GST_manipulation_set_metric (tm); | 2114 | GST_manipulation_set_metric(tm); |
2117 | GNUNET_SERVICE_client_continue (tc->client); | 2115 | GNUNET_SERVICE_client_continue(tc->client); |
2118 | } | 2116 | } |
2119 | 2117 | ||
2120 | 2118 | ||
@@ -2125,58 +2123,58 @@ handle_client_set_metric (void *cls, const struct TrafficMetricMessage *tm) | |||
2125 | * @param cls closure, unused | 2123 | * @param cls closure, unused |
2126 | */ | 2124 | */ |
2127 | static void | 2125 | static void |
2128 | shutdown_task (void *cls) | 2126 | shutdown_task(void *cls) |
2129 | { | 2127 | { |
2130 | struct AddressToStringContext *cur; | 2128 | struct AddressToStringContext *cur; |
2131 | 2129 | ||
2132 | GST_neighbours_stop (); | 2130 | GST_neighbours_stop(); |
2133 | GST_plugins_unload (); | 2131 | GST_plugins_unload(); |
2134 | GST_validation_stop (); | 2132 | GST_validation_stop(); |
2135 | GST_ats_done (); | 2133 | GST_ats_done(); |
2136 | GNUNET_ATS_scheduling_done (GST_ats); | 2134 | GNUNET_ATS_scheduling_done(GST_ats); |
2137 | GST_ats = NULL; | 2135 | GST_ats = NULL; |
2138 | GNUNET_ATS_connectivity_done (GST_ats_connect); | 2136 | GNUNET_ATS_connectivity_done(GST_ats_connect); |
2139 | GST_ats_connect = NULL; | 2137 | GST_ats_connect = NULL; |
2140 | GNUNET_NT_scanner_done (GST_is); | 2138 | GNUNET_NT_scanner_done(GST_is); |
2141 | GST_is = NULL; | 2139 | GST_is = NULL; |
2142 | while (NULL != (cur = a2s_head)) | 2140 | while (NULL != (cur = a2s_head)) |
2143 | { | 2141 | { |
2144 | GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur); | 2142 | GNUNET_CONTAINER_DLL_remove(a2s_head, a2s_tail, cur); |
2145 | GNUNET_free (cur); | 2143 | GNUNET_free(cur); |
2146 | } | 2144 | } |
2147 | if (NULL != plugin_nc) | 2145 | if (NULL != plugin_nc) |
2148 | { | 2146 | { |
2149 | GNUNET_notification_context_destroy (plugin_nc); | 2147 | GNUNET_notification_context_destroy(plugin_nc); |
2150 | plugin_nc = NULL; | 2148 | plugin_nc = NULL; |
2151 | } | 2149 | } |
2152 | GNUNET_CONTAINER_multipeermap_destroy (active_stccs); | 2150 | GNUNET_CONTAINER_multipeermap_destroy(active_stccs); |
2153 | active_stccs = NULL; | 2151 | active_stccs = NULL; |
2154 | if (NULL != blacklist) | 2152 | if (NULL != blacklist) |
2155 | { | 2153 | { |
2156 | GNUNET_CONTAINER_multipeermap_iterate (blacklist, | 2154 | GNUNET_CONTAINER_multipeermap_iterate(blacklist, |
2157 | &free_blacklist_entry, | 2155 | &free_blacklist_entry, |
2158 | NULL); | 2156 | NULL); |
2159 | GNUNET_CONTAINER_multipeermap_destroy (blacklist); | 2157 | GNUNET_CONTAINER_multipeermap_destroy(blacklist); |
2160 | blacklist = NULL; | 2158 | blacklist = NULL; |
2161 | } | 2159 | } |
2162 | GST_hello_stop (); | 2160 | GST_hello_stop(); |
2163 | GST_manipulation_stop (); | 2161 | GST_manipulation_stop(); |
2164 | 2162 | ||
2165 | if (NULL != GST_peerinfo) | 2163 | if (NULL != GST_peerinfo) |
2166 | { | 2164 | { |
2167 | GNUNET_PEERINFO_disconnect (GST_peerinfo); | 2165 | GNUNET_PEERINFO_disconnect(GST_peerinfo); |
2168 | GST_peerinfo = NULL; | 2166 | GST_peerinfo = NULL; |
2169 | } | 2167 | } |
2170 | if (NULL != GST_stats) | 2168 | if (NULL != GST_stats) |
2171 | { | 2169 | { |
2172 | GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); | 2170 | GNUNET_STATISTICS_destroy(GST_stats, GNUNET_NO); |
2173 | GST_stats = NULL; | 2171 | GST_stats = NULL; |
2174 | } | 2172 | } |
2175 | if (NULL != GST_my_private_key) | 2173 | if (NULL != GST_my_private_key) |
2176 | { | 2174 | { |
2177 | GNUNET_free (GST_my_private_key); | 2175 | GNUNET_free(GST_my_private_key); |
2178 | GST_my_private_key = NULL; | 2176 | GST_my_private_key = NULL; |
2179 | } | 2177 | } |
2180 | } | 2178 | } |
2181 | 2179 | ||
2182 | 2180 | ||
@@ -2186,7 +2184,7 @@ shutdown_task (void *cls) | |||
2186 | * @param cls the `struct GST_BlacklistCheck *` | 2184 | * @param cls the `struct GST_BlacklistCheck *` |
2187 | */ | 2185 | */ |
2188 | static void | 2186 | static void |
2189 | do_blacklist_check (void *cls) | 2187 | do_blacklist_check(void *cls) |
2190 | { | 2188 | { |
2191 | struct GST_BlacklistCheck *bc = cls; | 2189 | struct GST_BlacklistCheck *bc = cls; |
2192 | struct TransportClient *tc; | 2190 | struct TransportClient *tc; |
@@ -2195,34 +2193,34 @@ do_blacklist_check (void *cls) | |||
2195 | 2193 | ||
2196 | bc->task = NULL; | 2194 | bc->task = NULL; |
2197 | while (NULL != (tc = bc->bl_pos)) | 2195 | while (NULL != (tc = bc->bl_pos)) |
2198 | { | 2196 | { |
2199 | if (CT_BLACKLIST == tc->type) | 2197 | if (CT_BLACKLIST == tc->type) |
2200 | break; | 2198 | break; |
2201 | bc->bl_pos = tc->next; | 2199 | bc->bl_pos = tc->next; |
2202 | } | 2200 | } |
2203 | if (NULL == tc) | 2201 | if (NULL == tc) |
2204 | { | 2202 | { |
2205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2203 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2206 | "No other blacklist clients active, will allow neighbour `%s'\n", | 2204 | "No other blacklist clients active, will allow neighbour `%s'\n", |
2207 | GNUNET_i2s (&bc->peer)); | 2205 | GNUNET_i2s(&bc->peer)); |
2208 | 2206 | ||
2209 | bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK); | 2207 | bc->cont(bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK); |
2210 | GST_blacklist_test_cancel (bc); | 2208 | GST_blacklist_test_cancel(bc); |
2211 | return; | 2209 | return; |
2212 | } | 2210 | } |
2213 | if ((NULL != tc->details.blacklist.bc) || | 2211 | if ((NULL != tc->details.blacklist.bc) || |
2214 | (GNUNET_NO != tc->details.blacklist.waiting_for_reply)) | 2212 | (GNUNET_NO != tc->details.blacklist.waiting_for_reply)) |
2215 | return; /* someone else busy with this client */ | 2213 | return; /* someone else busy with this client */ |
2216 | tc->details.blacklist.bc = bc; | 2214 | tc->details.blacklist.bc = bc; |
2217 | env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY); | 2215 | env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY); |
2218 | bm->is_allowed = htonl (0); | 2216 | bm->is_allowed = htonl(0); |
2219 | bm->peer = bc->peer; | 2217 | bm->peer = bc->peer; |
2220 | GNUNET_MQ_send (tc->mq, env); | 2218 | GNUNET_MQ_send(tc->mq, env); |
2221 | if (GNUNET_YES == tc->details.blacklist.call_receive_done) | 2219 | if (GNUNET_YES == tc->details.blacklist.call_receive_done) |
2222 | { | 2220 | { |
2223 | tc->details.blacklist.call_receive_done = GNUNET_NO; | 2221 | tc->details.blacklist.call_receive_done = GNUNET_NO; |
2224 | GNUNET_SERVICE_client_continue (tc->client); | 2222 | GNUNET_SERVICE_client_continue(tc->client); |
2225 | } | 2223 | } |
2226 | tc->details.blacklist.waiting_for_reply = GNUNET_YES; | 2224 | tc->details.blacklist.waiting_for_reply = GNUNET_YES; |
2227 | } | 2225 | } |
2228 | 2226 | ||
@@ -2234,62 +2232,62 @@ do_blacklist_check (void *cls) | |||
2234 | * @param msg the blacklist-reply message that was sent | 2232 | * @param msg the blacklist-reply message that was sent |
2235 | */ | 2233 | */ |
2236 | static void | 2234 | static void |
2237 | handle_client_blacklist_reply (void *cls, const struct BlacklistMessage *msg) | 2235 | handle_client_blacklist_reply(void *cls, const struct BlacklistMessage *msg) |
2238 | { | 2236 | { |
2239 | struct TransportClient *tc = cls; | 2237 | struct TransportClient *tc = cls; |
2240 | struct GST_BlacklistCheck *bc; | 2238 | struct GST_BlacklistCheck *bc; |
2241 | 2239 | ||
2242 | if (CT_BLACKLIST != tc->type) | 2240 | if (CT_BLACKLIST != tc->type) |
2243 | { | 2241 | { |
2244 | GNUNET_break (0); | 2242 | GNUNET_break(0); |
2245 | GNUNET_SERVICE_client_drop (tc->client); | 2243 | GNUNET_SERVICE_client_drop(tc->client); |
2246 | return; | 2244 | return; |
2247 | } | 2245 | } |
2248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2246 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2249 | "Blacklist client %p sent reply for `%s'\n", | 2247 | "Blacklist client %p sent reply for `%s'\n", |
2250 | tc, | 2248 | tc, |
2251 | GNUNET_i2s (&msg->peer)); | 2249 | GNUNET_i2s(&msg->peer)); |
2252 | bc = tc->details.blacklist.bc; | 2250 | bc = tc->details.blacklist.bc; |
2253 | tc->details.blacklist.bc = NULL; | 2251 | tc->details.blacklist.bc = NULL; |
2254 | tc->details.blacklist.waiting_for_reply = GNUNET_NO; | 2252 | tc->details.blacklist.waiting_for_reply = GNUNET_NO; |
2255 | tc->details.blacklist.call_receive_done = GNUNET_YES; | 2253 | tc->details.blacklist.call_receive_done = GNUNET_YES; |
2256 | if (NULL != bc) | 2254 | if (NULL != bc) |
2257 | { | ||
2258 | /* only run this if the blacklist check has not been | ||
2259 | * cancelled in the meantime... */ | ||
2260 | GNUNET_assert (bc->bl_pos == tc); | ||
2261 | if (ntohl (msg->is_allowed) == GNUNET_SYSERR) | ||
2262 | { | ||
2263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2264 | "Blacklist check failed, peer not allowed\n"); | ||
2265 | /* For the duration of the continuation, make the ongoing | ||
2266 | check invisible (to avoid double-cancellation); then | ||
2267 | add it back again so we can re-use GST_blacklist_test_cancel() */ | ||
2268 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); | ||
2269 | bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_NO); | ||
2270 | GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); | ||
2271 | GST_blacklist_test_cancel (bc); | ||
2272 | tc->details.blacklist.call_receive_done = GNUNET_NO; | ||
2273 | GNUNET_SERVICE_client_continue (tc->client); | ||
2274 | return; | ||
2275 | } | ||
2276 | else | ||
2277 | { | 2255 | { |
2278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2256 | /* only run this if the blacklist check has not been |
2279 | "Blacklist check succeeded, continuing with checks\n"); | 2257 | * cancelled in the meantime... */ |
2280 | tc->details.blacklist.call_receive_done = GNUNET_NO; | 2258 | GNUNET_assert(bc->bl_pos == tc); |
2281 | GNUNET_SERVICE_client_continue (tc->client); | 2259 | if (ntohl(msg->is_allowed) == GNUNET_SYSERR) |
2282 | bc->bl_pos = tc->next; | 2260 | { |
2283 | bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); | 2261 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2262 | "Blacklist check failed, peer not allowed\n"); | ||
2263 | /* For the duration of the continuation, make the ongoing | ||
2264 | check invisible (to avoid double-cancellation); then | ||
2265 | add it back again so we can re-use GST_blacklist_test_cancel() */ | ||
2266 | GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc); | ||
2267 | bc->cont(bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_NO); | ||
2268 | GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc); | ||
2269 | GST_blacklist_test_cancel(bc); | ||
2270 | tc->details.blacklist.call_receive_done = GNUNET_NO; | ||
2271 | GNUNET_SERVICE_client_continue(tc->client); | ||
2272 | return; | ||
2273 | } | ||
2274 | else | ||
2275 | { | ||
2276 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2277 | "Blacklist check succeeded, continuing with checks\n"); | ||
2278 | tc->details.blacklist.call_receive_done = GNUNET_NO; | ||
2279 | GNUNET_SERVICE_client_continue(tc->client); | ||
2280 | bc->bl_pos = tc->next; | ||
2281 | bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); | ||
2282 | } | ||
2284 | } | 2283 | } |
2285 | } | ||
2286 | /* check if any other blacklist checks are waiting for this blacklister */ | 2284 | /* check if any other blacklist checks are waiting for this blacklister */ |
2287 | for (bc = bc_head; bc != NULL; bc = bc->next) | 2285 | for (bc = bc_head; bc != NULL; bc = bc->next) |
2288 | if ((bc->bl_pos == tc) && (NULL == bc->task)) | 2286 | if ((bc->bl_pos == tc) && (NULL == bc->task)) |
2289 | { | 2287 | { |
2290 | bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); | 2288 | bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); |
2291 | break; | 2289 | break; |
2292 | } | 2290 | } |
2293 | } | 2291 | } |
2294 | 2292 | ||
2295 | 2293 | ||
@@ -2300,32 +2298,32 @@ handle_client_blacklist_reply (void *cls, const struct BlacklistMessage *msg) | |||
2300 | * @param transport_name transport to blacklist for this peer, NULL for all | 2298 | * @param transport_name transport to blacklist for this peer, NULL for all |
2301 | */ | 2299 | */ |
2302 | void | 2300 | void |
2303 | GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, | 2301 | GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer, |
2304 | const char *transport_name) | 2302 | const char *transport_name) |
2305 | { | 2303 | { |
2306 | char *transport = NULL; | 2304 | char *transport = NULL; |
2307 | 2305 | ||
2308 | if (NULL != transport_name) | 2306 | if (NULL != transport_name) |
2309 | { | 2307 | { |
2310 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2308 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2311 | "Adding peer `%s' with plugin `%s' to blacklist\n", | 2309 | "Adding peer `%s' with plugin `%s' to blacklist\n", |
2312 | GNUNET_i2s (peer), | 2310 | GNUNET_i2s(peer), |
2313 | transport_name); | 2311 | transport_name); |
2314 | transport = GNUNET_strdup (transport_name); | 2312 | transport = GNUNET_strdup(transport_name); |
2315 | } | 2313 | } |
2316 | else | 2314 | else |
2317 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2315 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2318 | "Adding peer `%s' with all plugins to blacklist\n", | 2316 | "Adding peer `%s' with all plugins to blacklist\n", |
2319 | GNUNET_i2s (peer)); | 2317 | GNUNET_i2s(peer)); |
2320 | if (NULL == blacklist) | 2318 | if (NULL == blacklist) |
2321 | blacklist = | 2319 | blacklist = |
2322 | GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE, | 2320 | GNUNET_CONTAINER_multipeermap_create(TRANSPORT_BLACKLIST_HT_SIZE, |
2323 | GNUNET_NO); | 2321 | GNUNET_NO); |
2324 | 2322 | ||
2325 | GNUNET_CONTAINER_multipeermap_put (blacklist, | 2323 | GNUNET_CONTAINER_multipeermap_put(blacklist, |
2326 | peer, | 2324 | peer, |
2327 | transport, | 2325 | transport, |
2328 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 2326 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2329 | } | 2327 | } |
2330 | 2328 | ||
2331 | 2329 | ||
@@ -2336,27 +2334,27 @@ GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, | |||
2336 | * @param session session used to abort matching checks | 2334 | * @param session session used to abort matching checks |
2337 | */ | 2335 | */ |
2338 | void | 2336 | void |
2339 | GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address, | 2337 | GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address, |
2340 | struct GNUNET_ATS_Session *session) | 2338 | struct GNUNET_ATS_Session *session) |
2341 | { | 2339 | { |
2342 | struct GST_BlacklistCheck *bc; | 2340 | struct GST_BlacklistCheck *bc; |
2343 | struct GST_BlacklistCheck *n; | 2341 | struct GST_BlacklistCheck *n; |
2344 | 2342 | ||
2345 | n = bc_head; | 2343 | n = bc_head; |
2346 | while (NULL != (bc = n)) | 2344 | while (NULL != (bc = n)) |
2347 | { | ||
2348 | n = bc->next; | ||
2349 | if ((bc->session == session) && | ||
2350 | (0 == GNUNET_HELLO_address_cmp (bc->address, address))) | ||
2351 | { | 2345 | { |
2352 | bc->cont (bc->cont_cls, | 2346 | n = bc->next; |
2353 | &bc->peer, | 2347 | if ((bc->session == session) && |
2354 | bc->address, | 2348 | (0 == GNUNET_HELLO_address_cmp(bc->address, address))) |
2355 | bc->session, | 2349 | { |
2356 | GNUNET_SYSERR); | 2350 | bc->cont(bc->cont_cls, |
2357 | GST_blacklist_test_cancel (bc); | 2351 | &bc->peer, |
2352 | bc->address, | ||
2353 | bc->session, | ||
2354 | GNUNET_SYSERR); | ||
2355 | GST_blacklist_test_cancel(bc); | ||
2356 | } | ||
2358 | } | 2357 | } |
2359 | } | ||
2360 | } | 2358 | } |
2361 | 2359 | ||
2362 | 2360 | ||
@@ -2370,7 +2368,7 @@ GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address, | |||
2370 | * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches | 2368 | * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches |
2371 | */ | 2369 | */ |
2372 | static int | 2370 | static int |
2373 | test_blacklisted (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 2371 | test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
2374 | { | 2372 | { |
2375 | const char *transport_name = cls; | 2373 | const char *transport_name = cls; |
2376 | char *be = value; | 2374 | char *be = value; |
@@ -2384,21 +2382,21 @@ test_blacklisted (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
2384 | * | 2382 | * |
2385 | */ | 2383 | */ |
2386 | 2384 | ||
2387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2385 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2388 | "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n", | 2386 | "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n", |
2389 | GNUNET_i2s (key), | 2387 | GNUNET_i2s(key), |
2390 | (NULL == transport_name) ? "unspecified" : transport_name, | 2388 | (NULL == transport_name) ? "unspecified" : transport_name, |
2391 | (NULL == be) ? "all plugins" : be); | 2389 | (NULL == be) ? "all plugins" : be); |
2392 | /* all plugins for this peer were blacklisted: disallow */ | 2390 | /* all plugins for this peer were blacklisted: disallow */ |
2393 | if (NULL == value) | 2391 | if (NULL == value) |
2394 | return GNUNET_NO; | 2392 | return GNUNET_NO; |
2395 | 2393 | ||
2396 | /* blacklist check for specific transport */ | 2394 | /* blacklist check for specific transport */ |
2397 | if ((NULL != transport_name) && (NULL != value)) | 2395 | if ((NULL != transport_name) && (NULL != value)) |
2398 | { | 2396 | { |
2399 | if (0 == strcmp (transport_name, be)) | 2397 | if (0 == strcmp(transport_name, be)) |
2400 | return GNUNET_NO; /* plugin is blacklisted! */ | 2398 | return GNUNET_NO; /* plugin is blacklisted! */ |
2401 | } | 2399 | } |
2402 | return GNUNET_OK; | 2400 | return GNUNET_OK; |
2403 | } | 2401 | } |
2404 | 2402 | ||
@@ -2416,70 +2414,70 @@ test_blacklisted (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
2416 | * was made instantly and @a cont was already called | 2414 | * was made instantly and @a cont was already called |
2417 | */ | 2415 | */ |
2418 | struct GST_BlacklistCheck * | 2416 | struct GST_BlacklistCheck * |
2419 | GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, | 2417 | GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer, |
2420 | const char *transport_name, | 2418 | const char *transport_name, |
2421 | GST_BlacklistTestContinuation cont, | 2419 | GST_BlacklistTestContinuation cont, |
2422 | void *cont_cls, | 2420 | void *cont_cls, |
2423 | const struct GNUNET_HELLO_Address *address, | 2421 | const struct GNUNET_HELLO_Address *address, |
2424 | struct GNUNET_ATS_Session *session) | 2422 | struct GNUNET_ATS_Session *session) |
2425 | { | 2423 | { |
2426 | struct GST_BlacklistCheck *bc; | 2424 | struct GST_BlacklistCheck *bc; |
2427 | struct TransportClient *tc; | 2425 | struct TransportClient *tc; |
2428 | 2426 | ||
2429 | GNUNET_assert (NULL != peer); | 2427 | GNUNET_assert(NULL != peer); |
2430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2428 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2431 | "Blacklist check for peer `%s':%s\n", | 2429 | "Blacklist check for peer `%s':%s\n", |
2432 | GNUNET_i2s (peer), | 2430 | GNUNET_i2s(peer), |
2433 | (NULL != transport_name) ? transport_name : "unspecified"); | 2431 | (NULL != transport_name) ? transport_name : "unspecified"); |
2434 | 2432 | ||
2435 | /* Check local blacklist by iterating over hashmap | 2433 | /* Check local blacklist by iterating over hashmap |
2436 | * If iteration is aborted, we found a matching blacklist entry */ | 2434 | * If iteration is aborted, we found a matching blacklist entry */ |
2437 | if ((NULL != blacklist) && | 2435 | if ((NULL != blacklist) && |
2438 | (GNUNET_SYSERR == | 2436 | (GNUNET_SYSERR == |
2439 | GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, | 2437 | GNUNET_CONTAINER_multipeermap_get_multiple(blacklist, |
2440 | peer, | 2438 | peer, |
2441 | &test_blacklisted, | 2439 | &test_blacklisted, |
2442 | (void *) transport_name))) | 2440 | (void *)transport_name))) |
2443 | { | 2441 | { |
2444 | /* Disallowed by config, disapprove instantly */ | 2442 | /* Disallowed by config, disapprove instantly */ |
2445 | GNUNET_STATISTICS_update (GST_stats, | 2443 | GNUNET_STATISTICS_update(GST_stats, |
2446 | gettext_noop ("# disconnects due to blacklist"), | 2444 | gettext_noop("# disconnects due to blacklist"), |
2447 | 1, | 2445 | 1, |
2448 | GNUNET_NO); | 2446 | GNUNET_NO); |
2449 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2447 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2450 | _ ("Disallowing connection to peer `%s' on transport %s\n"), | 2448 | _("Disallowing connection to peer `%s' on transport %s\n"), |
2451 | GNUNET_i2s (peer), | 2449 | GNUNET_i2s(peer), |
2452 | (NULL != transport_name) ? transport_name : "unspecified"); | 2450 | (NULL != transport_name) ? transport_name : "unspecified"); |
2453 | if (NULL != cont) | 2451 | if (NULL != cont) |
2454 | cont (cont_cls, peer, address, session, GNUNET_NO); | 2452 | cont(cont_cls, peer, address, session, GNUNET_NO); |
2455 | return NULL; | 2453 | return NULL; |
2456 | } | 2454 | } |
2457 | 2455 | ||
2458 | for (tc = clients_head; NULL != tc; tc = tc->next) | 2456 | for (tc = clients_head; NULL != tc; tc = tc->next) |
2459 | if (CT_BLACKLIST == tc->type) | 2457 | if (CT_BLACKLIST == tc->type) |
2460 | break; | 2458 | break; |
2461 | if (NULL == tc) | 2459 | if (NULL == tc) |
2462 | { | 2460 | { |
2463 | /* no blacklist clients, approve instantly */ | 2461 | /* no blacklist clients, approve instantly */ |
2464 | if (NULL != cont) | 2462 | if (NULL != cont) |
2465 | cont (cont_cls, peer, address, session, GNUNET_OK); | 2463 | cont(cont_cls, peer, address, session, GNUNET_OK); |
2466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2464 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2467 | "Allowing connection to peer `%s' %s\n", | 2465 | "Allowing connection to peer `%s' %s\n", |
2468 | GNUNET_i2s (peer), | 2466 | GNUNET_i2s(peer), |
2469 | (NULL != transport_name) ? transport_name : ""); | 2467 | (NULL != transport_name) ? transport_name : ""); |
2470 | return NULL; | 2468 | return NULL; |
2471 | } | 2469 | } |
2472 | 2470 | ||
2473 | /* need to query blacklist clients */ | 2471 | /* need to query blacklist clients */ |
2474 | bc = GNUNET_new (struct GST_BlacklistCheck); | 2472 | bc = GNUNET_new(struct GST_BlacklistCheck); |
2475 | GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); | 2473 | GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc); |
2476 | bc->peer = *peer; | 2474 | bc->peer = *peer; |
2477 | bc->address = GNUNET_HELLO_address_copy (address); | 2475 | bc->address = GNUNET_HELLO_address_copy(address); |
2478 | bc->session = session; | 2476 | bc->session = session; |
2479 | bc->cont = cont; | 2477 | bc->cont = cont; |
2480 | bc->cont_cls = cont_cls; | 2478 | bc->cont_cls = cont_cls; |
2481 | bc->bl_pos = tc; | 2479 | bc->bl_pos = tc; |
2482 | bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); | 2480 | bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); |
2483 | return bc; | 2481 | return bc; |
2484 | } | 2482 | } |
2485 | 2483 | ||
@@ -2490,25 +2488,25 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, | |||
2490 | * @param bc check to cancel | 2488 | * @param bc check to cancel |
2491 | */ | 2489 | */ |
2492 | void | 2490 | void |
2493 | GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc) | 2491 | GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc) |
2494 | { | 2492 | { |
2495 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); | 2493 | GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc); |
2496 | if (NULL != bc->bl_pos) | 2494 | if (NULL != bc->bl_pos) |
2497 | { | ||
2498 | if ((CT_BLACKLIST == bc->bl_pos->type) && | ||
2499 | (bc->bl_pos->details.blacklist.bc == bc)) | ||
2500 | { | 2495 | { |
2501 | /* we're at the head of the queue, remove us! */ | 2496 | if ((CT_BLACKLIST == bc->bl_pos->type) && |
2502 | bc->bl_pos->details.blacklist.bc = NULL; | 2497 | (bc->bl_pos->details.blacklist.bc == bc)) |
2498 | { | ||
2499 | /* we're at the head of the queue, remove us! */ | ||
2500 | bc->bl_pos->details.blacklist.bc = NULL; | ||
2501 | } | ||
2503 | } | 2502 | } |
2504 | } | ||
2505 | if (NULL != bc->task) | 2503 | if (NULL != bc->task) |
2506 | { | 2504 | { |
2507 | GNUNET_SCHEDULER_cancel (bc->task); | 2505 | GNUNET_SCHEDULER_cancel(bc->task); |
2508 | bc->task = NULL; | 2506 | bc->task = NULL; |
2509 | } | 2507 | } |
2510 | GNUNET_free_non_null (bc->address); | 2508 | GNUNET_free_non_null(bc->address); |
2511 | GNUNET_free (bc); | 2509 | GNUNET_free(bc); |
2512 | } | 2510 | } |
2513 | 2511 | ||
2514 | 2512 | ||
@@ -2521,10 +2519,10 @@ GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc) | |||
2521 | * @param value value of the option | 2519 | * @param value value of the option |
2522 | */ | 2520 | */ |
2523 | static void | 2521 | static void |
2524 | blacklist_cfg_iter (void *cls, | 2522 | blacklist_cfg_iter(void *cls, |
2525 | const char *section, | 2523 | const char *section, |
2526 | const char *option, | 2524 | const char *option, |
2527 | const char *value) | 2525 | const char *value) |
2528 | { | 2526 | { |
2529 | unsigned int *res = cls; | 2527 | unsigned int *res = cls; |
2530 | struct GNUNET_PeerIdentity peer; | 2528 | struct GNUNET_PeerIdentity peer; |
@@ -2532,32 +2530,32 @@ blacklist_cfg_iter (void *cls, | |||
2532 | char *pos; | 2530 | char *pos; |
2533 | 2531 | ||
2534 | if (GNUNET_OK != | 2532 | if (GNUNET_OK != |
2535 | GNUNET_CRYPTO_eddsa_public_key_from_string (option, | 2533 | GNUNET_CRYPTO_eddsa_public_key_from_string(option, |
2536 | strlen (option), | 2534 | strlen(option), |
2537 | &peer.public_key)) | 2535 | &peer.public_key)) |
2538 | return; | 2536 | return; |
2539 | 2537 | ||
2540 | if ((NULL == value) || (0 == strcmp (value, ""))) | 2538 | if ((NULL == value) || (0 == strcmp(value, ""))) |
2541 | { | 2539 | { |
2542 | /* Blacklist whole peer */ | 2540 | /* Blacklist whole peer */ |
2543 | GST_blacklist_add_peer (&peer, NULL); | 2541 | GST_blacklist_add_peer(&peer, NULL); |
2544 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2542 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2545 | _ ("Adding blacklisting entry for peer `%s'\n"), | 2543 | _("Adding blacklisting entry for peer `%s'\n"), |
2546 | GNUNET_i2s (&peer)); | 2544 | GNUNET_i2s(&peer)); |
2547 | } | 2545 | } |
2548 | else | 2546 | else |
2549 | { | ||
2550 | plugs = GNUNET_strdup (value); | ||
2551 | for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " ")) | ||
2552 | { | 2547 | { |
2553 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2548 | plugs = GNUNET_strdup(value); |
2554 | _ ("Adding blacklisting entry for peer `%s':`%s'\n"), | 2549 | for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " ")) |
2555 | GNUNET_i2s (&peer), | 2550 | { |
2556 | pos); | 2551 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2557 | GST_blacklist_add_peer (&peer, pos); | 2552 | _("Adding blacklisting entry for peer `%s':`%s'\n"), |
2553 | GNUNET_i2s(&peer), | ||
2554 | pos); | ||
2555 | GST_blacklist_add_peer(&peer, pos); | ||
2556 | } | ||
2557 | GNUNET_free(plugs); | ||
2558 | } | 2558 | } |
2559 | GNUNET_free (plugs); | ||
2560 | } | ||
2561 | (*res)++; | 2559 | (*res)++; |
2562 | } | 2560 | } |
2563 | 2561 | ||
@@ -2569,23 +2567,23 @@ blacklist_cfg_iter (void *cls, | |||
2569 | * @param my_id my peer identity | 2567 | * @param my_id my peer identity |
2570 | */ | 2568 | */ |
2571 | static void | 2569 | static void |
2572 | read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg, | 2570 | read_blacklist_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg, |
2573 | const struct GNUNET_PeerIdentity *my_id) | 2571 | const struct GNUNET_PeerIdentity *my_id) |
2574 | { | 2572 | { |
2575 | char cfg_sect[512]; | 2573 | char cfg_sect[512]; |
2576 | unsigned int res = 0; | 2574 | unsigned int res = 0; |
2577 | 2575 | ||
2578 | GNUNET_snprintf (cfg_sect, | 2576 | GNUNET_snprintf(cfg_sect, |
2579 | sizeof (cfg_sect), | 2577 | sizeof(cfg_sect), |
2580 | "transport-blacklist-%s", | 2578 | "transport-blacklist-%s", |
2581 | GNUNET_i2s_full (my_id)); | 2579 | GNUNET_i2s_full(my_id)); |
2582 | GNUNET_CONFIGURATION_iterate_section_values (cfg, | 2580 | GNUNET_CONFIGURATION_iterate_section_values(cfg, |
2583 | cfg_sect, | 2581 | cfg_sect, |
2584 | &blacklist_cfg_iter, | 2582 | &blacklist_cfg_iter, |
2585 | &res); | 2583 | &res); |
2586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2584 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2587 | "Loaded %u blacklisting entries from configuration\n", | 2585 | "Loaded %u blacklisting entries from configuration\n", |
2588 | res); | 2586 | res); |
2589 | } | 2587 | } |
2590 | 2588 | ||
2591 | 2589 | ||
@@ -2597,9 +2595,9 @@ read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2597 | * @param service the initialized service | 2595 | * @param service the initialized service |
2598 | */ | 2596 | */ |
2599 | static void | 2597 | static void |
2600 | run (void *cls, | 2598 | run(void *cls, |
2601 | const struct GNUNET_CONFIGURATION_Handle *c, | 2599 | const struct GNUNET_CONFIGURATION_Handle *c, |
2602 | struct GNUNET_SERVICE_Handle *service) | 2600 | struct GNUNET_SERVICE_Handle *service) |
2603 | { | 2601 | { |
2604 | char *keyfile; | 2602 | char *keyfile; |
2605 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 2603 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
@@ -2610,70 +2608,70 @@ run (void *cls, | |||
2610 | 2608 | ||
2611 | /* setup globals */ | 2609 | /* setup globals */ |
2612 | GST_cfg = c; | 2610 | GST_cfg = c; |
2613 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, | 2611 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c, |
2614 | "PEER", | 2612 | "PEER", |
2615 | "PRIVATE_KEY", | 2613 | "PRIVATE_KEY", |
2616 | &keyfile)) | 2614 | &keyfile)) |
2617 | { | 2615 | { |
2618 | GNUNET_log ( | 2616 | GNUNET_log( |
2619 | GNUNET_ERROR_TYPE_ERROR, | 2617 | GNUNET_ERROR_TYPE_ERROR, |
2620 | _ ( | 2618 | _( |
2621 | "Transport service is lacking key configuration settings. Exiting.\n")); | 2619 | "Transport service is lacking key configuration settings. Exiting.\n")); |
2622 | GNUNET_SCHEDULER_shutdown (); | 2620 | GNUNET_SCHEDULER_shutdown(); |
2623 | return; | 2621 | return; |
2624 | } | 2622 | } |
2625 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (c, | 2623 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(c, |
2626 | "transport", | 2624 | "transport", |
2627 | "HELLO_EXPIRATION", | 2625 | "HELLO_EXPIRATION", |
2628 | &hello_expiration)) | 2626 | &hello_expiration)) |
2629 | { | 2627 | { |
2630 | hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; | 2628 | hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; |
2631 | } | 2629 | } |
2632 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 2630 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); |
2633 | GNUNET_free (keyfile); | 2631 | GNUNET_free(keyfile); |
2634 | GNUNET_assert (NULL != pk); | 2632 | GNUNET_assert(NULL != pk); |
2635 | GST_my_private_key = pk; | 2633 | GST_my_private_key = pk; |
2636 | 2634 | ||
2637 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); | 2635 | GST_stats = GNUNET_STATISTICS_create("transport", GST_cfg); |
2638 | GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg); | 2636 | GST_peerinfo = GNUNET_PEERINFO_connect(GST_cfg); |
2639 | GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, | 2637 | GNUNET_CRYPTO_eddsa_key_get_public(GST_my_private_key, |
2640 | &GST_my_identity.public_key); | 2638 | &GST_my_identity.public_key); |
2641 | GNUNET_assert (NULL != GST_my_private_key); | 2639 | GNUNET_assert(NULL != GST_my_private_key); |
2642 | 2640 | ||
2643 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2641 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2644 | "My identity is `%s'\n", | 2642 | "My identity is `%s'\n", |
2645 | GNUNET_i2s_full (&GST_my_identity)); | 2643 | GNUNET_i2s_full(&GST_my_identity)); |
2646 | 2644 | ||
2647 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 2645 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
2648 | if (NULL == GST_peerinfo) | 2646 | if (NULL == GST_peerinfo) |
2649 | { | 2647 | { |
2650 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2648 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2651 | _ ("Could not access PEERINFO service. Exiting.\n")); | 2649 | _("Could not access PEERINFO service. Exiting.\n")); |
2652 | GNUNET_SCHEDULER_shutdown (); | 2650 | GNUNET_SCHEDULER_shutdown(); |
2653 | return; | 2651 | return; |
2654 | } | 2652 | } |
2655 | 2653 | ||
2656 | max_fd_rlimit = 0; | 2654 | max_fd_rlimit = 0; |
2657 | #if HAVE_GETRLIMIT | 2655 | #if HAVE_GETRLIMIT |
2658 | { | 2656 | { |
2659 | struct rlimit r_file; | 2657 | struct rlimit r_file; |
2660 | 2658 | ||
2661 | if (0 == getrlimit (RLIMIT_NOFILE, &r_file)) | 2659 | if (0 == getrlimit(RLIMIT_NOFILE, &r_file)) |
2662 | { | 2660 | { |
2663 | max_fd_rlimit = r_file.rlim_cur; | 2661 | max_fd_rlimit = r_file.rlim_cur; |
2664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2662 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2665 | "Maximum number of open files was: %u/%u\n", | 2663 | "Maximum number of open files was: %u/%u\n", |
2666 | (unsigned int) r_file.rlim_cur, | 2664 | (unsigned int)r_file.rlim_cur, |
2667 | (unsigned int) r_file.rlim_max); | 2665 | (unsigned int)r_file.rlim_max); |
2668 | } | 2666 | } |
2669 | max_fd_rlimit = | 2667 | max_fd_rlimit = |
2670 | (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ | 2668 | (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ |
2671 | } | 2669 | } |
2672 | #endif | 2670 | #endif |
2673 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (GST_cfg, | 2671 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(GST_cfg, |
2674 | "transport", | 2672 | "transport", |
2675 | "MAX_FD", | 2673 | "MAX_FD", |
2676 | &max_fd_cfg)) | 2674 | &max_fd_cfg)) |
2677 | max_fd_cfg = max_fd_rlimit; | 2675 | max_fd_cfg = max_fd_rlimit; |
2678 | 2676 | ||
2679 | if (max_fd_cfg > max_fd_rlimit) | 2677 | if (max_fd_cfg > max_fd_rlimit) |
@@ -2683,14 +2681,14 @@ run (void *cls, | |||
2683 | if (max_fd < DEFAULT_MAX_FDS) | 2681 | if (max_fd < DEFAULT_MAX_FDS) |
2684 | max_fd = DEFAULT_MAX_FDS; | 2682 | max_fd = DEFAULT_MAX_FDS; |
2685 | 2683 | ||
2686 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2684 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2687 | "Limiting number of sockets to %u: validation %u, neighbors: %u\n", | 2685 | "Limiting number of sockets to %u: validation %u, neighbors: %u\n", |
2688 | max_fd, | 2686 | max_fd, |
2689 | (max_fd / 3), | 2687 | (max_fd / 3), |
2690 | (max_fd / 3) * 2); | 2688 | (max_fd / 3) * 2); |
2691 | 2689 | ||
2692 | friend_only = | 2690 | friend_only = |
2693 | GNUNET_CONFIGURATION_get_value_yesno (GST_cfg, "topology", "FRIENDS-ONLY"); | 2691 | GNUNET_CONFIGURATION_get_value_yesno(GST_cfg, "topology", "FRIENDS-ONLY"); |
2694 | if (GNUNET_SYSERR == friend_only) | 2692 | if (GNUNET_SYSERR == friend_only) |
2695 | friend_only = GNUNET_NO; /* According to topology defaults */ | 2693 | friend_only = GNUNET_NO; /* According to topology defaults */ |
2696 | /* start subsystems */ | 2694 | /* start subsystems */ |
@@ -2699,79 +2697,79 @@ run (void *cls, | |||
2699 | struct GNUNET_PeerIdentity dstj; | 2697 | struct GNUNET_PeerIdentity dstj; |
2700 | const char *ds = "DSTJBRRKZ8TBW3FGK6B0M5QXWT9WYNZ45H5MCV4HY7ST64Q8T9F0"; | 2698 | const char *ds = "DSTJBRRKZ8TBW3FGK6B0M5QXWT9WYNZ45H5MCV4HY7ST64Q8T9F0"; |
2701 | 2699 | ||
2702 | GNUNET_assert ( | 2700 | GNUNET_assert( |
2703 | GNUNET_OK == | 2701 | GNUNET_OK == |
2704 | GNUNET_CRYPTO_eddsa_public_key_from_string (ds, | 2702 | GNUNET_CRYPTO_eddsa_public_key_from_string(ds, |
2705 | strlen (ds), | 2703 | strlen(ds), |
2706 | &dstj.public_key)); | 2704 | &dstj.public_key)); |
2707 | GST_blacklist_add_peer (&dstj, NULL); | 2705 | GST_blacklist_add_peer(&dstj, NULL); |
2708 | } | 2706 | } |
2709 | read_blacklist_configuration (GST_cfg, &GST_my_identity); | 2707 | read_blacklist_configuration(GST_cfg, &GST_my_identity); |
2710 | GST_is = GNUNET_NT_scanner_init (); | 2708 | GST_is = GNUNET_NT_scanner_init(); |
2711 | GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg); | 2709 | GST_ats_connect = GNUNET_ATS_connectivity_init(GST_cfg); |
2712 | GST_ats = | 2710 | GST_ats = |
2713 | GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); | 2711 | GNUNET_ATS_scheduling_init(GST_cfg, &ats_request_address_change, NULL); |
2714 | GST_ats_init (); | 2712 | GST_ats_init(); |
2715 | GST_manipulation_init (); | 2713 | GST_manipulation_init(); |
2716 | GST_plugins_load (&GST_manipulation_recv, | 2714 | GST_plugins_load(&GST_manipulation_recv, |
2717 | &plugin_env_address_change_notification, | 2715 | &plugin_env_address_change_notification, |
2718 | &plugin_env_session_start, | 2716 | &plugin_env_session_start, |
2719 | &plugin_env_session_end); | 2717 | &plugin_env_session_end); |
2720 | GST_hello_start (friend_only, &process_hello_update, NULL); | 2718 | GST_hello_start(friend_only, &process_hello_update, NULL); |
2721 | GST_neighbours_start ((max_fd / 3) * 2); | 2719 | GST_neighbours_start((max_fd / 3) * 2); |
2722 | active_stccs = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); | 2720 | active_stccs = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); |
2723 | plugin_nc = GNUNET_notification_context_create (0); | 2721 | plugin_nc = GNUNET_notification_context_create(0); |
2724 | GST_validation_start ((max_fd / 3)); | 2722 | GST_validation_start((max_fd / 3)); |
2725 | } | 2723 | } |
2726 | 2724 | ||
2727 | 2725 | ||
2728 | /** | 2726 | /** |
2729 | * Define "main" method using service macro. | 2727 | * Define "main" method using service macro. |
2730 | */ | 2728 | */ |
2731 | GNUNET_SERVICE_MAIN ( | 2729 | GNUNET_SERVICE_MAIN( |
2732 | "transport", | 2730 | "transport", |
2733 | GNUNET_SERVICE_OPTION_NONE, | 2731 | GNUNET_SERVICE_OPTION_NONE, |
2734 | &run, | 2732 | &run, |
2735 | &client_connect_cb, | 2733 | &client_connect_cb, |
2736 | &client_disconnect_cb, | 2734 | &client_disconnect_cb, |
2737 | NULL, | 2735 | NULL, |
2738 | GNUNET_MQ_hd_fixed_size (client_start, | 2736 | GNUNET_MQ_hd_fixed_size(client_start, |
2739 | GNUNET_MESSAGE_TYPE_TRANSPORT_START, | 2737 | GNUNET_MESSAGE_TYPE_TRANSPORT_START, |
2740 | struct StartMessage, | 2738 | struct StartMessage, |
2741 | NULL), | 2739 | NULL), |
2742 | GNUNET_MQ_hd_var_size (client_hello, | 2740 | GNUNET_MQ_hd_var_size(client_hello, |
2743 | GNUNET_MESSAGE_TYPE_HELLO, | 2741 | GNUNET_MESSAGE_TYPE_HELLO, |
2744 | struct GNUNET_MessageHeader, | 2742 | struct GNUNET_MessageHeader, |
2745 | NULL), | 2743 | NULL), |
2746 | GNUNET_MQ_hd_var_size (client_send, | 2744 | GNUNET_MQ_hd_var_size(client_send, |
2747 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, | 2745 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, |
2748 | struct OutboundMessage, | 2746 | struct OutboundMessage, |
2749 | NULL), | 2747 | NULL), |
2750 | GNUNET_MQ_hd_var_size (client_address_to_string, | 2748 | GNUNET_MQ_hd_var_size(client_address_to_string, |
2751 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, | 2749 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, |
2752 | struct AddressLookupMessage, | 2750 | struct AddressLookupMessage, |
2753 | NULL), | 2751 | NULL), |
2754 | GNUNET_MQ_hd_fixed_size (client_monitor_peers, | 2752 | GNUNET_MQ_hd_fixed_size(client_monitor_peers, |
2755 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, | 2753 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, |
2756 | struct PeerMonitorMessage, | 2754 | struct PeerMonitorMessage, |
2757 | NULL), | 2755 | NULL), |
2758 | GNUNET_MQ_hd_fixed_size (client_blacklist_init, | 2756 | GNUNET_MQ_hd_fixed_size(client_blacklist_init, |
2759 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, | 2757 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, |
2760 | struct GNUNET_MessageHeader, | 2758 | struct GNUNET_MessageHeader, |
2761 | NULL), | 2759 | NULL), |
2762 | GNUNET_MQ_hd_fixed_size (client_blacklist_reply, | 2760 | GNUNET_MQ_hd_fixed_size(client_blacklist_reply, |
2763 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, | 2761 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, |
2764 | struct BlacklistMessage, | 2762 | struct BlacklistMessage, |
2765 | NULL), | 2763 | NULL), |
2766 | GNUNET_MQ_hd_fixed_size (client_set_metric, | 2764 | GNUNET_MQ_hd_fixed_size(client_set_metric, |
2767 | GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, | 2765 | GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, |
2768 | struct TrafficMetricMessage, | 2766 | struct TrafficMetricMessage, |
2769 | NULL), | 2767 | NULL), |
2770 | GNUNET_MQ_hd_fixed_size (client_monitor_plugins, | 2768 | GNUNET_MQ_hd_fixed_size(client_monitor_plugins, |
2771 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START, | 2769 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START, |
2772 | struct GNUNET_MessageHeader, | 2770 | struct GNUNET_MessageHeader, |
2773 | NULL), | 2771 | NULL), |
2774 | GNUNET_MQ_handler_end ()); | 2772 | GNUNET_MQ_handler_end()); |
2775 | 2773 | ||
2776 | 2774 | ||
2777 | /* end of file gnunet-service-transport.c */ | 2775 | /* end of file gnunet-service-transport.c */ |