aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r--src/transport/gnunet-service-transport.c248
1 files changed, 60 insertions, 188 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 46503a5bf..7dfd994b4 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -69,53 +69,10 @@ struct SessionKiller
69 /** 69 /**
70 * The kill task. 70 * The kill task.
71 */ 71 */
72 struct GNUNET_SCHEDULER_Task * task; 72 struct GNUNET_SCHEDULER_Task *task;
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 */
84struct BlacklistCheckContext
85{
86 /**
87 * We keep these in a DLL.
88 */
89 struct BlacklistCheckContext *prev;
90
91 /**
92 * We keep these in a DLL.
93 */
94 struct BlacklistCheckContext *next;
95
96 /**
97 * Handle with the blacklist subsystem.
98 */
99 struct GST_BlacklistCheck *blc;
100
101 /**
102 * The address we are checking.
103 */
104 struct GNUNET_HELLO_Address *address;
105
106 /**
107 * Session associated with the address (or NULL).
108 */
109 struct Session *session;
110
111 /**
112 * Message to process in the continuation if the
113 * blacklist check is ok, can be NULL.
114 */
115 struct GNUNET_MessageHeader *msg;
116
117};
118
119/* globals */ 76/* globals */
120 77
121/** 78/**
@@ -178,20 +135,6 @@ static struct SessionKiller *sk_tail;
178 */ 135 */
179struct GNUNET_ATS_InterfaceScanner *GST_is; 136struct GNUNET_ATS_InterfaceScanner *GST_is;
180 137
181/**
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.
186 */
187struct BlacklistCheckContext *bc_head;
188
189/**
190 * Tail of DLL of blacklist checks we have pending for
191 * incoming sessions and/or SYN requests.
192 */
193struct BlacklistCheckContext *bc_tail;
194
195 138
196/** 139/**
197 * Transmit our HELLO message to the given (connected) neighbour. 140 * Transmit our HELLO message to the given (connected) neighbour.
@@ -323,44 +266,6 @@ kill_session_task (void *cls,
323 266
324 267
325/** 268/**
326 * Cancel all blacklist checks that are pending for the given address and session.
327 * NOTE: Consider moving the "bc_*" logic into blacklist.h?
328 *
329 * @param address address to remove from check
330 * @param sesssion session that must match to remove for check
331 */
332static void
333cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address,
334 struct Session *session)
335{
336 struct BlacklistCheckContext *blctx;
337 struct BlacklistCheckContext *next;
338
339 next = bc_head;
340 for (blctx = next; NULL != blctx; blctx = next)
341 {
342 next = blctx->next;
343 if ( (NULL != blctx->address) &&
344 (0 == GNUNET_HELLO_address_cmp(blctx->address, address)) &&
345 (blctx->session == session))
346 {
347 GNUNET_CONTAINER_DLL_remove (bc_head,
348 bc_tail,
349 blctx);
350 if (NULL != blctx->blc)
351 {
352 GST_blacklist_test_cancel (blctx->blc);
353 blctx->blc = NULL;
354 }
355 GNUNET_HELLO_address_free (blctx->address);
356 GNUNET_free_non_null (blctx->msg);
357 GNUNET_free (blctx);
358 }
359 }
360}
361
362
363/**
364 * Force plugin to terminate session due to communication 269 * Force plugin to terminate session due to communication
365 * issue. 270 * issue.
366 * 271 *
@@ -398,54 +303,49 @@ kill_session (const char *plugin_name,
398 * Black list check result for try_connect call 303 * Black list check result for try_connect call
399 * If connection to the peer is allowed request adddress and ??? 304 * If connection to the peer is allowed request adddress and ???
400 * 305 *
401 * @param cls blc_ctx bl context 306 * @param cls the message
402 * @param peer the peer 307 * @param peer the peer
308 * @param address the address
309 * @param session the session
403 * @param result the result 310 * @param result the result
404 */ 311 */
405static void 312static void
406connect_bl_check_cont (void *cls, 313connect_bl_check_cont (void *cls,
407 const struct GNUNET_PeerIdentity *peer, 314 const struct GNUNET_PeerIdentity *peer,
315 const struct GNUNET_HELLO_Address *address,
316 struct Session *session,
408 int result) 317 int result)
409{ 318{
410 struct BlacklistCheckContext *blctx = cls; 319 struct GNUNET_MessageHeader *msg = cls;
411 320
412 GNUNET_CONTAINER_DLL_remove (bc_head,
413 bc_tail,
414 blctx);
415 blctx->blc = NULL;
416 if (GNUNET_OK == result) 321 if (GNUNET_OK == result)
417 { 322 {
418 /* Blacklist allows to speak to this peer, forward SYN to neighbours */ 323 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
419 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 324 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
420 "Received SYN message from peer `%s' at `%s'\n", 325 "Received SYN message from peer `%s' at `%s'\n",
421 GNUNET_i2s (peer), 326 GNUNET_i2s (peer),
422 GST_plugins_a2s (blctx->address)); 327 GST_plugins_a2s (address));
423 if (GNUNET_OK != 328 if (GNUNET_OK !=
424 GST_neighbours_handle_session_syn (blctx->msg, 329 GST_neighbours_handle_session_syn (msg,
425 &blctx->address->peer)) 330 peer))
426 { 331 {
427 cancel_pending_blacklist_checks (blctx->address, 332 GST_blacklist_abort_matching (address,
428 blctx->session); 333 session);
429 kill_session (blctx->address->transport_name, 334 kill_session (address->transport_name,
430 blctx->session); 335 session);
431 } 336 }
337 GNUNET_free (msg);
338 return;
432 } 339 }
433 else 340 GNUNET_free (msg);
434 { 341 if (GNUNET_SYSERR == result)
435 /* Blacklist denies to speak to this peer */ 342 return; /* check was aborted, session destroyed */
436 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 343 /* Blacklist denies to speak to this peer */
437 "Discarding SYN message from `%s' due to denied blacklist check\n", 344 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
438 GNUNET_i2s (peer)); 345 "Discarding SYN message from `%s' due to denied blacklist check\n",
439 cancel_pending_blacklist_checks (blctx->address, 346 GNUNET_i2s (peer));
440 blctx->session); 347 kill_session (address->transport_name,
441 kill_session (blctx->address->transport_name, 348 session);
442 blctx->session);
443 }
444
445 if (NULL != blctx->address)
446 GNUNET_HELLO_address_free (blctx->address);
447 GNUNET_free (blctx->msg);
448 GNUNET_free (blctx);
449} 349}
450 350
451 351
@@ -470,8 +370,6 @@ GST_receive_callback (void *cls,
470{ 370{
471 const char *plugin_name = cls; 371 const char *plugin_name = cls;
472 struct GNUNET_TIME_Relative ret; 372 struct GNUNET_TIME_Relative ret;
473 struct BlacklistCheckContext *blctx;
474 struct GST_BlacklistCheck *blc;
475 uint16_t type; 373 uint16_t type;
476 374
477 ret = GNUNET_TIME_UNIT_ZERO; 375 ret = GNUNET_TIME_UNIT_ZERO;
@@ -498,8 +396,8 @@ GST_receive_callback (void *cls,
498 if (GNUNET_OK != GST_validation_handle_hello (message)) 396 if (GNUNET_OK != GST_validation_handle_hello (message))
499 { 397 {
500 GNUNET_break_op (0); 398 GNUNET_break_op (0);
501 cancel_pending_blacklist_checks (address, 399 GST_blacklist_abort_matching (address,
502 session); 400 session);
503 } 401 }
504 return ret; 402 return ret;
505 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: 403 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
@@ -512,8 +410,8 @@ GST_receive_callback (void *cls,
512 address, 410 address,
513 session)) 411 session))
514 { 412 {
515 cancel_pending_blacklist_checks (address, 413 GST_blacklist_abort_matching (address,
516 session); 414 session);
517 kill_session (plugin_name, 415 kill_session (plugin_name,
518 session); 416 session);
519 } 417 }
@@ -524,31 +422,20 @@ GST_receive_callback (void *cls,
524 GST_plugins_a2s (address)); 422 GST_plugins_a2s (address));
525 if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message)) 423 if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message))
526 { 424 {
527 GNUNET_break_op(0); 425 GNUNET_break_op (0);
528 cancel_pending_blacklist_checks (address, session); 426 GST_blacklist_abort_matching (address,
427 session);
529 kill_session (plugin_name, session); 428 kill_session (plugin_name, session);
530 } 429 }
531 break; 430 break;
532 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN: 431 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
533 /* Do blacklist check if communication with this peer is allowed */ 432 /* Do blacklist check if communication with this peer is allowed */
534 blctx = GNUNET_new (struct BlacklistCheckContext); 433 (void) GST_blacklist_test_allowed (&address->peer,
535 blctx->address = GNUNET_HELLO_address_copy (address); 434 NULL,
536 blctx->session = session; 435 &connect_bl_check_cont,
537 blctx->msg = GNUNET_malloc (ntohs(message->size)); 436 GNUNET_copy_message (message),
538 memcpy (blctx->msg, 437 address,
539 message, 438 session);
540 ntohs (message->size));
541 GNUNET_CONTAINER_DLL_insert (bc_head,
542 bc_tail,
543 blctx);
544 if (NULL !=
545 (blc = GST_blacklist_test_allowed (&address->peer,
546 NULL,
547 &connect_bl_check_cont,
548 blctx)))
549 {
550 blctx->blc = blc;
551 }
552 break; 439 break;
553 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK: 440 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
554 if (GNUNET_OK != 441 if (GNUNET_OK !=
@@ -556,7 +443,7 @@ GST_receive_callback (void *cls,
556 address, 443 address,
557 session)) 444 session))
558 { 445 {
559 cancel_pending_blacklist_checks (address, session); 446 GST_blacklist_abort_matching (address, session);
560 kill_session (plugin_name, session); 447 kill_session (plugin_name, session);
561 } 448 }
562 break; 449 break;
@@ -567,7 +454,7 @@ GST_receive_callback (void *cls,
567 session)) 454 session))
568 { 455 {
569 GNUNET_break_op(0); 456 GNUNET_break_op(0);
570 cancel_pending_blacklist_checks (address, session); 457 GST_blacklist_abort_matching (address, session);
571 kill_session (plugin_name, session); 458 kill_session (plugin_name, session);
572 } 459 }
573 break; 460 break;
@@ -684,7 +571,7 @@ plugin_env_session_end (void *cls,
684 571
685 GST_neighbours_session_terminated (&address->peer, session); 572 GST_neighbours_session_terminated (&address->peer, session);
686 GST_ats_del_session (address, session); 573 GST_ats_del_session (address, session);
687 cancel_pending_blacklist_checks (address, session); 574 GST_blacklist_abort_matching (address, session);
688 575
689 for (sk = sk_head; NULL != sk; sk = sk->next) 576 for (sk = sk_head; NULL != sk; sk = sk->next)
690 { 577 {
@@ -704,39 +591,34 @@ plugin_env_session_end (void *cls,
704 * plugin gave us a new session in #plugin_env_session_start(). If 591 * plugin gave us a new session in #plugin_env_session_start(). If
705 * connection to the peer is disallowed, kill the session. 592 * connection to the peer is disallowed, kill the session.
706 * 593 *
707 * @param cls blc_ctx bl context 594 * @param cls NULL
708 * @param peer the peer 595 * @param peer the peer
596 * @param address address associated with the request
597 * @param session session associated with the request
709 * @param result the result 598 * @param result the result
710 */ 599 */
711static void 600static void
712plugin_env_session_start_bl_check_cont (void *cls, 601plugin_env_session_start_bl_check_cont (void *cls,
713 const struct GNUNET_PeerIdentity *peer, 602 const struct GNUNET_PeerIdentity *peer,
603 const struct GNUNET_HELLO_Address *address,
604 struct Session *session,
714 int result) 605 int result)
715{ 606{
716 struct BlacklistCheckContext *blctx = cls;
717
718 GNUNET_CONTAINER_DLL_remove (bc_head,
719 bc_tail,
720 blctx);
721 blctx->blc = NULL;
722 if (GNUNET_OK != result) 607 if (GNUNET_OK != result)
723 { 608 {
724 cancel_pending_blacklist_checks (blctx->address, 609 kill_session (address->transport_name,
725 blctx->session); 610 session);
726 kill_session (blctx->address->transport_name, 611 return;
727 blctx->session);
728 } 612 }
729 else if (GNUNET_YES != 613 if (GNUNET_YES !=
730 GNUNET_HELLO_address_check_option (blctx->address, 614 GNUNET_HELLO_address_check_option (address,
731 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 615 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
732 { 616 {
733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
734 "Informing verifier about inbound session's address `%s'\n", 618 "Informing verifier about inbound session's address `%s'\n",
735 GST_plugins_a2s (blctx->address)); 619 GST_plugins_a2s (address));
736 GST_validation_handle_address (blctx->address); 620 GST_validation_handle_address (address);
737 } 621 }
738 GNUNET_HELLO_address_free (blctx->address);
739 GNUNET_free (blctx);
740} 622}
741 623
742 624
@@ -754,8 +636,6 @@ plugin_env_session_start (void *cls,
754 struct Session *session, 636 struct Session *session,
755 enum GNUNET_ATS_Network_Type scope) 637 enum GNUNET_ATS_Network_Type scope)
756{ 638{
757 struct BlacklistCheckContext *blctx;
758 struct GST_BlacklistCheck *blc;
759 struct GNUNET_ATS_Properties prop; 639 struct GNUNET_ATS_Properties prop;
760 640
761 if (NULL == address) 641 if (NULL == address)
@@ -788,20 +668,12 @@ plugin_env_session_start (void *cls,
788 &prop); 668 &prop);
789 } 669 }
790 /* Do blacklist check if communication with this peer is allowed */ 670 /* Do blacklist check if communication with this peer is allowed */
791 blctx = GNUNET_new (struct BlacklistCheckContext); 671 (void) GST_blacklist_test_allowed (&address->peer,
792 blctx->address = GNUNET_HELLO_address_copy (address); 672 address->transport_name,
793 blctx->session = session; 673 &plugin_env_session_start_bl_check_cont,
794 GNUNET_CONTAINER_DLL_insert (bc_head, 674 NULL,
795 bc_tail, 675 address,
796 blctx); 676 session);
797 if (NULL !=
798 (blc = GST_blacklist_test_allowed (&address->peer,
799 address->transport_name,
800 &plugin_env_session_start_bl_check_cont,
801 blctx)))
802 {
803 blctx->blc = blc;
804 }
805} 677}
806 678
807 679