diff options
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 155 |
1 files changed, 103 insertions, 52 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index e3bbf7167..f317e924f 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -17,7 +17,6 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | |||
21 | /** | 20 | /** |
22 | * @file transport/gnunet-service-transport.c | 21 | * @file transport/gnunet-service-transport.c |
23 | * @brief main for gnunet-service-transport | 22 | * @brief main for gnunet-service-transport |
@@ -41,6 +40,7 @@ | |||
41 | #include "gnunet-service-transport_manipulation.h" | 40 | #include "gnunet-service-transport_manipulation.h" |
42 | #include "transport.h" | 41 | #include "transport.h" |
43 | 42 | ||
43 | |||
44 | /** | 44 | /** |
45 | * Information we need for an asynchronous session kill. | 45 | * Information we need for an asynchronous session kill. |
46 | */ | 46 | */ |
@@ -73,18 +73,45 @@ struct SessionKiller | |||
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | /** | ||
77 | * We track active blacklist checks in a DLL so we can cancel them if | ||
78 | * necessary. We typically check against the blacklist a few times | ||
79 | * during connection setup, as the check is asynchronous and the | ||
80 | * blacklist may change its mind before the connection goes fully up. | ||
81 | * Similarly, the session may die during the asynchronous check, so | ||
82 | * we use this list to then cancel ongoing checks. | ||
83 | */ | ||
76 | struct BlacklistCheckContext | 84 | struct BlacklistCheckContext |
77 | { | 85 | { |
86 | /** | ||
87 | * We keep these in a DLL. | ||
88 | */ | ||
78 | struct BlacklistCheckContext *prev; | 89 | struct BlacklistCheckContext *prev; |
79 | 90 | ||
91 | /** | ||
92 | * We keep these in a DLL. | ||
93 | */ | ||
80 | struct BlacklistCheckContext *next; | 94 | struct BlacklistCheckContext *next; |
81 | 95 | ||
96 | /** | ||
97 | * Handle with the blacklist subsystem. | ||
98 | */ | ||
82 | struct GST_BlacklistCheck *blc; | 99 | struct GST_BlacklistCheck *blc; |
83 | 100 | ||
101 | /** | ||
102 | * The address we are checking. | ||
103 | */ | ||
84 | struct GNUNET_HELLO_Address *address; | 104 | struct GNUNET_HELLO_Address *address; |
85 | 105 | ||
106 | /** | ||
107 | * Session associated with the address (or NULL). | ||
108 | */ | ||
86 | struct Session *session; | 109 | struct Session *session; |
87 | 110 | ||
111 | /** | ||
112 | * Message to process in the continuation if the | ||
113 | * blacklist check is ok, can be NULL. | ||
114 | */ | ||
88 | struct GNUNET_MessageHeader *msg; | 115 | struct GNUNET_MessageHeader *msg; |
89 | 116 | ||
90 | }; | 117 | }; |
@@ -152,12 +179,16 @@ static struct SessionKiller *sk_tail; | |||
152 | static struct GNUNET_ATS_InterfaceScanner *is; | 179 | static struct GNUNET_ATS_InterfaceScanner *is; |
153 | 180 | ||
154 | /** | 181 | /** |
155 | * FIXME | 182 | * Head of DLL of blacklist checks we have pending for |
183 | * incoming sessions and/or SYN requests. We may | ||
184 | * want to move this into the blacklist-logic at some | ||
185 | * point. | ||
156 | */ | 186 | */ |
157 | struct BlacklistCheckContext *bc_head; | 187 | struct BlacklistCheckContext *bc_head; |
158 | 188 | ||
159 | /** | 189 | /** |
160 | * FIXME | 190 | * Tail of DLL of blacklist checks we have pending for |
191 | * incoming sessions and/or SYN requests. | ||
161 | */ | 192 | */ |
162 | struct BlacklistCheckContext *bc_tail; | 193 | struct BlacklistCheckContext *bc_tail; |
163 | 194 | ||
@@ -202,7 +233,8 @@ transmit_our_hello (void *cls, | |||
202 | * @param hello new HELLO | 233 | * @param hello new HELLO |
203 | */ | 234 | */ |
204 | static void | 235 | static void |
205 | process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) | 236 | process_hello_update (void *cls, |
237 | const struct GNUNET_MessageHeader *hello) | ||
206 | { | 238 | { |
207 | GST_clients_broadcast (hello, GNUNET_NO); | 239 | GST_clients_broadcast (hello, GNUNET_NO); |
208 | GST_neighbours_iterate (&transmit_our_hello, (void *) hello); | 240 | GST_neighbours_iterate (&transmit_our_hello, (void *) hello); |
@@ -268,20 +300,24 @@ process_payload (const struct GNUNET_HELLO_Address *address, | |||
268 | * @param tc scheduler context | 300 | * @param tc scheduler context |
269 | */ | 301 | */ |
270 | static void | 302 | static void |
271 | kill_session_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 303 | kill_session_task (void *cls, |
304 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
272 | { | 305 | { |
273 | struct SessionKiller *sk = cls; | 306 | struct SessionKiller *sk = cls; |
274 | 307 | ||
275 | sk->task = NULL; | 308 | sk->task = NULL; |
276 | GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); | 309 | GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); |
277 | sk->plugin->disconnect_session (sk->plugin->cls, sk->session); | 310 | sk->plugin->disconnect_session (sk->plugin->cls, sk->session); |
278 | GNUNET_free(sk); | 311 | GNUNET_free(sk); |
279 | } | 312 | } |
280 | 313 | ||
281 | 314 | ||
282 | /** | 315 | /** |
283 | * FIXME. Also, consider moving the "bc_*" logic into | 316 | * Cancel all blacklist checks that are pending for the given address and session. |
284 | * blacklist.h? | 317 | * NOTE: Consider moving the "bc_*" logic into blacklist.h? |
318 | * | ||
319 | * @param address address to remove from check | ||
320 | * @param sesssion session that must match to remove for check | ||
285 | */ | 321 | */ |
286 | static void | 322 | static void |
287 | cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address, | 323 | cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address, |
@@ -298,7 +334,9 @@ cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address, | |||
298 | (0 == GNUNET_HELLO_address_cmp(blctx->address, address)) && | 334 | (0 == GNUNET_HELLO_address_cmp(blctx->address, address)) && |
299 | (blctx->session == session)) | 335 | (blctx->session == session)) |
300 | { | 336 | { |
301 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); | 337 | GNUNET_CONTAINER_DLL_remove (bc_head, |
338 | bc_tail, | ||
339 | blctx); | ||
302 | if (NULL != blctx->blc) | 340 | if (NULL != blctx->blc) |
303 | { | 341 | { |
304 | GST_blacklist_test_cancel (blctx->blc); | 342 | GST_blacklist_test_cancel (blctx->blc); |
@@ -361,35 +399,37 @@ connect_bl_check_cont (void *cls, | |||
361 | { | 399 | { |
362 | struct BlacklistCheckContext *blctx = cls; | 400 | struct BlacklistCheckContext *blctx = cls; |
363 | 401 | ||
364 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); | 402 | GNUNET_CONTAINER_DLL_remove (bc_head, |
403 | bc_tail, | ||
404 | blctx); | ||
365 | blctx->blc = NULL; | 405 | blctx->blc = NULL; |
366 | |||
367 | if (GNUNET_OK == result) | 406 | if (GNUNET_OK == result) |
368 | { | 407 | { |
369 | /* Blacklist allows to speak to this peer, forward SYN to neighbours */ | 408 | /* Blacklist allows to speak to this peer, forward SYN to neighbours */ |
370 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 409 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
371 | "Received SYN message from peer `%s' with `%s' %p\n", | 410 | "Received SYN message from peer `%s' at `%s'\n", |
372 | GNUNET_i2s (peer), | 411 | GNUNET_i2s (peer), |
373 | GST_plugins_a2s (blctx->address), | 412 | GST_plugins_a2s (blctx->address)); |
374 | blctx->session); | ||
375 | |||
376 | if (GNUNET_OK != | 413 | if (GNUNET_OK != |
377 | GST_neighbours_handle_session_syn (blctx->msg, | 414 | GST_neighbours_handle_session_syn (blctx->msg, |
378 | &blctx->address->peer)) | 415 | &blctx->address->peer)) |
379 | { | 416 | { |
380 | cancel_pending_blacklist_checks (blctx->address, blctx->session); | 417 | cancel_pending_blacklist_checks (blctx->address, |
381 | kill_session (blctx->address->transport_name, blctx->session); | 418 | blctx->session); |
419 | kill_session (blctx->address->transport_name, | ||
420 | blctx->session); | ||
382 | } | 421 | } |
383 | } | 422 | } |
384 | else | 423 | else |
385 | { | 424 | { |
386 | /* Blacklist denies to speak to this peer */ | 425 | /* Blacklist denies to speak to this peer */ |
387 | 426 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | |
388 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 427 | "Discarding SYN message from `%s' due to denied blacklist check\n", |
389 | "Discarding SYN message from `%s' due to denied blacklist check\n", | 428 | GNUNET_i2s (peer)); |
390 | GNUNET_i2s (peer)); | 429 | cancel_pending_blacklist_checks (blctx->address, |
391 | cancel_pending_blacklist_checks (blctx->address, blctx->session); | 430 | blctx->session); |
392 | kill_session (blctx->address->transport_name, blctx->session); | 431 | kill_session (blctx->address->transport_name, |
432 | blctx->session); | ||
393 | } | 433 | } |
394 | 434 | ||
395 | if (NULL != blctx->address) | 435 | if (NULL != blctx->address) |
@@ -429,7 +469,7 @@ GST_receive_callback (void *cls, | |||
429 | goto end; | 469 | goto end; |
430 | type = ntohs (message->type); | 470 | type = ntohs (message->type); |
431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
432 | "Received Message with type %u from peer `%s'\n", | 472 | "Received message with type %u from peer `%s'\n", |
433 | type, | 473 | type, |
434 | GNUNET_i2s (&address->peer)); | 474 | GNUNET_i2s (&address->peer)); |
435 | 475 | ||
@@ -485,11 +525,17 @@ GST_receive_callback (void *cls, | |||
485 | blctx->address = GNUNET_HELLO_address_copy (address); | 525 | blctx->address = GNUNET_HELLO_address_copy (address); |
486 | blctx->session = session; | 526 | blctx->session = session; |
487 | blctx->msg = GNUNET_malloc (ntohs(message->size)); | 527 | blctx->msg = GNUNET_malloc (ntohs(message->size)); |
488 | memcpy (blctx->msg, message, ntohs(message->size)); | 528 | memcpy (blctx->msg, |
489 | GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, blctx); | 529 | message, |
490 | if (NULL != (blc = GST_blacklist_test_allowed (&address->peer, NULL, | 530 | ntohs (message->size)); |
491 | &connect_bl_check_cont, | 531 | GNUNET_CONTAINER_DLL_insert (bc_head, |
492 | blctx))) | 532 | bc_tail, |
533 | blctx); | ||
534 | if (NULL != | ||
535 | (blc = GST_blacklist_test_allowed (&address->peer, | ||
536 | NULL, | ||
537 | &connect_bl_check_cont, | ||
538 | blctx))) | ||
493 | { | 539 | { |
494 | blctx->blc = blc; | 540 | blctx->blc = blc; |
495 | } | 541 | } |
@@ -619,11 +665,8 @@ plugin_env_session_end (void *cls, | |||
619 | } | 665 | } |
620 | GNUNET_assert (strlen (address->transport_name) > 0); | 666 | GNUNET_assert (strlen (address->transport_name) > 0); |
621 | 667 | ||
622 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
623 | "Notification from plugin `%s' about terminated %s session %p from peer `%s' address `%s'\n", | 669 | "Notification from plugin about terminated session %p from peer `%s' address `%s'\n", |
624 | address->transport_name, | ||
625 | GNUNET_HELLO_address_check_option (address, | ||
626 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound", | ||
627 | session, | 670 | session, |
628 | GNUNET_i2s (&address->peer), | 671 | GNUNET_i2s (&address->peer), |
629 | GST_plugins_a2s (address)); | 672 | GST_plugins_a2s (address)); |
@@ -719,6 +762,15 @@ plugin_env_session_start_bl_check_cont (void *cls, | |||
719 | kill_session (blctx->address->transport_name, | 762 | kill_session (blctx->address->transport_name, |
720 | blctx->session); | 763 | blctx->session); |
721 | } | 764 | } |
765 | else if (GNUNET_YES != | ||
766 | GNUNET_HELLO_address_check_option (blctx->address, | ||
767 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | ||
768 | { | ||
769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
770 | "Informing verifier about inbound session's address `%s'\n", | ||
771 | GST_plugins_a2s (blctx->address)); | ||
772 | GST_validation_handle_address (blctx->address); | ||
773 | } | ||
722 | GNUNET_HELLO_address_free (blctx->address); | 774 | GNUNET_HELLO_address_free (blctx->address); |
723 | GNUNET_free (blctx); | 775 | GNUNET_free (blctx); |
724 | } | 776 | } |
@@ -754,35 +806,34 @@ plugin_env_session_start (void *cls, | |||
754 | return; | 806 | return; |
755 | } | 807 | } |
756 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 808 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
757 | "Notification from plugin `%s' about new %s session %p from peer `%s' address `%s'\n", | 809 | "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n", |
758 | address->transport_name, | 810 | address->transport_name, |
759 | GNUNET_HELLO_address_check_option (address, | ||
760 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound", | ||
761 | session, | 811 | session, |
762 | GNUNET_i2s (&address->peer), | 812 | GNUNET_i2s (&address->peer), |
763 | GST_plugins_a2s (address)); | 813 | GST_plugins_a2s (address)); |
764 | if ( (GNUNET_YES == | 814 | if (GNUNET_YES == |
765 | GNUNET_HELLO_address_check_option (address, | 815 | GNUNET_HELLO_address_check_option (address, |
766 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) || | 816 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) |
767 | (GNUNET_NO == | ||
768 | GST_ats_is_known (address, NULL) ) ) | ||
769 | { | 817 | { |
770 | /* inbound is always new, but outbound MAY already be known, but | 818 | /* inbound is always new, but outbound MAY already be known, but |
771 | for example for UNIX, we have symmetric connections and thus we | 819 | for example for UNIX, we have symmetric connections and thus we |
772 | may not know the address yet; add if necessary! */ | 820 | may not know the address yet; add if necessary! */ |
773 | GST_ats_add_address (address, | 821 | GST_ats_add_inbound_address (address, |
774 | session, | 822 | session, |
775 | ats, | 823 | ats, |
776 | ats_count); | 824 | ats_count); |
777 | } | 825 | } |
778 | else | 826 | else |
779 | { | 827 | { |
780 | GST_ats_new_session (address, | 828 | if (GNUNET_YES == |
781 | session); | 829 | GST_ats_is_known (address, |
782 | GST_ats_update_metrics (address, | 830 | session)) |
783 | session, | 831 | { |
784 | ats, | 832 | GST_ats_update_metrics (address, |
785 | ats_count); | 833 | session, |
834 | ats, | ||
835 | ats_count); | ||
836 | } | ||
786 | } | 837 | } |
787 | /* Do blacklist check if communication with this peer is allowed */ | 838 | /* Do blacklist check if communication with this peer is allowed */ |
788 | blctx = GNUNET_new (struct BlacklistCheckContext); | 839 | blctx = GNUNET_new (struct BlacklistCheckContext); |