diff options
Diffstat (limited to 'src/transport/tcp_connection_legacy.c')
-rw-r--r-- | src/transport/tcp_connection_legacy.c | 421 |
1 files changed, 179 insertions, 242 deletions
diff --git a/src/transport/tcp_connection_legacy.c b/src/transport/tcp_connection_legacy.c index cfb088361..999e8827a 100644 --- a/src/transport/tcp_connection_legacy.c +++ b/src/transport/tcp_connection_legacy.c | |||
@@ -41,11 +41,12 @@ | |||
41 | * is this value divided by the number of address families. | 41 | * is this value divided by the number of address families. |
42 | * Default is 5s. | 42 | * Default is 5s. |
43 | */ | 43 | */ |
44 | #define CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 44 | #define CONNECT_RETRY_TIMEOUT \ |
45 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
45 | 46 | ||
46 | 47 | ||
47 | 48 | #define LOG_STRERROR(kind, syscall) \ | |
48 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-connection", syscall) | 49 | GNUNET_log_from_strerror (kind, "util-connection", syscall) |
49 | 50 | ||
50 | 51 | ||
51 | /** | 52 | /** |
@@ -78,14 +79,13 @@ struct GNUNET_CONNECTION_TransmitHandle | |||
78 | /** | 79 | /** |
79 | * Task called on timeout. | 80 | * Task called on timeout. |
80 | */ | 81 | */ |
81 | struct GNUNET_SCHEDULER_Task * timeout_task; | 82 | struct GNUNET_SCHEDULER_Task *timeout_task; |
82 | 83 | ||
83 | /** | 84 | /** |
84 | * At what number of bytes available in the | 85 | * At what number of bytes available in the |
85 | * write buffer should the notify method be called? | 86 | * write buffer should the notify method be called? |
86 | */ | 87 | */ |
87 | size_t notify_size; | 88 | size_t notify_size; |
88 | |||
89 | }; | 89 | }; |
90 | 90 | ||
91 | 91 | ||
@@ -129,7 +129,7 @@ struct AddressProbe | |||
129 | /** | 129 | /** |
130 | * Task waiting for the connection to finish connecting. | 130 | * Task waiting for the connection to finish connecting. |
131 | */ | 131 | */ |
132 | struct GNUNET_SCHEDULER_Task * task; | 132 | struct GNUNET_SCHEDULER_Task *task; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | 135 | ||
@@ -263,7 +263,6 @@ struct GNUNET_CONNECTION_Handle | |||
263 | * Handle to subsequent connection after proxy handshake completes, | 263 | * Handle to subsequent connection after proxy handshake completes, |
264 | */ | 264 | */ |
265 | struct GNUNET_CONNECTION_Handle *proxy_handshake; | 265 | struct GNUNET_CONNECTION_Handle *proxy_handshake; |
266 | |||
267 | }; | 266 | }; |
268 | 267 | ||
269 | 268 | ||
@@ -357,9 +356,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
357 | 356 | ||
358 | addrlen = sizeof (addr); | 357 | addrlen = sizeof (addr); |
359 | sock = | 358 | sock = |
360 | GNUNET_NETWORK_socket_accept (lsock, | 359 | GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); |
361 | (struct sockaddr *) &addr, | ||
362 | &addrlen); | ||
363 | if (NULL == sock) | 360 | if (NULL == sock) |
364 | { | 361 | { |
365 | if (EAGAIN != errno) | 362 | if (EAGAIN != errno) |
@@ -375,8 +372,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
375 | 372 | ||
376 | sa = (struct sockaddr *) addr; | 373 | sa = (struct sockaddr *) addr; |
377 | v6 = (struct sockaddr_in6 *) addr; | 374 | v6 = (struct sockaddr_in6 *) addr; |
378 | if ( (AF_INET6 == sa->sa_family) && | 375 | if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) |
379 | (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)) ) | ||
380 | { | 376 | { |
381 | /* convert to V4 address */ | 377 | /* convert to V4 address */ |
382 | v4 = GNUNET_new (struct sockaddr_in); | 378 | v4 = GNUNET_new (struct sockaddr_in); |
@@ -386,9 +382,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
386 | v4->sin_len = (u_char) sizeof (struct sockaddr_in); | 382 | v4->sin_len = (u_char) sizeof (struct sockaddr_in); |
387 | #endif | 383 | #endif |
388 | GNUNET_memcpy (&v4->sin_addr, | 384 | GNUNET_memcpy (&v4->sin_addr, |
389 | &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - | 385 | &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - |
390 | sizeof (struct in_addr)], | 386 | sizeof (struct in_addr)], |
391 | sizeof (struct in_addr)); | 387 | sizeof (struct in_addr)); |
392 | v4->sin_port = v6->sin6_port; | 388 | v4->sin_port = v6->sin6_port; |
393 | uaddr = v4; | 389 | uaddr = v4; |
394 | addrlen = sizeof (struct sockaddr_in); | 390 | addrlen = sizeof (struct sockaddr_in); |
@@ -403,21 +399,18 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
403 | { | 399 | { |
404 | #if HAVE_GETPEEREID | 400 | #if HAVE_GETPEEREID |
405 | /* most BSDs */ | 401 | /* most BSDs */ |
406 | if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), | 402 | if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) |
407 | &gc.uid, | ||
408 | &gc.gid)) | ||
409 | gcp = &gc; | 403 | gcp = &gc; |
410 | #else | 404 | #else |
411 | #ifdef SO_PEERCRED | 405 | #ifdef SO_PEERCRED |
412 | /* largely traditional GNU/Linux */ | 406 | /* largely traditional GNU/Linux */ |
413 | olen = sizeof (uc); | 407 | olen = sizeof (uc); |
414 | if ( (0 == | 408 | if ((0 == getsockopt (GNUNET_NETWORK_get_fd (sock), |
415 | getsockopt (GNUNET_NETWORK_get_fd (sock), | 409 | SOL_SOCKET, |
416 | SOL_SOCKET, | 410 | SO_PEERCRED, |
417 | SO_PEERCRED, | 411 | &uc, |
418 | &uc, | 412 | &olen)) && |
419 | &olen)) && | 413 | (olen == sizeof (uc))) |
420 | (olen == sizeof (uc)) ) | ||
421 | { | 414 | { |
422 | gc.uid = uc.uid; | 415 | gc.uid = uc.uid; |
423 | gc.gid = uc.gid; | 416 | gc.gid = uc.gid; |
@@ -441,20 +434,15 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
441 | #endif | 434 | #endif |
442 | } | 435 | } |
443 | 436 | ||
444 | if ( (NULL != access_cb) && | 437 | if ((NULL != access_cb) && |
445 | (GNUNET_YES != (aret = access_cb (access_cb_cls, | 438 | (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen)))) |
446 | gcp, | ||
447 | uaddr, | ||
448 | addrlen))) ) | ||
449 | { | 439 | { |
450 | if (GNUNET_NO == aret) | 440 | if (GNUNET_NO == aret) |
451 | LOG (GNUNET_ERROR_TYPE_INFO, | 441 | LOG (GNUNET_ERROR_TYPE_INFO, |
452 | _("Access denied to `%s'\n"), | 442 | _ ("Access denied to `%s'\n"), |
453 | GNUNET_a2s (uaddr, | 443 | GNUNET_a2s (uaddr, addrlen)); |
454 | addrlen)); | ||
455 | GNUNET_break (GNUNET_OK == | 444 | GNUNET_break (GNUNET_OK == |
456 | GNUNET_NETWORK_socket_shutdown (sock, | 445 | GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); |
457 | SHUT_RDWR)); | ||
458 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 446 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
459 | GNUNET_free (uaddr); | 447 | GNUNET_free (uaddr); |
460 | return NULL; | 448 | return NULL; |
@@ -466,9 +454,8 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
466 | connection->addrlen = addrlen; | 454 | connection->addrlen = addrlen; |
467 | connection->sock = sock; | 455 | connection->sock = sock; |
468 | LOG (GNUNET_ERROR_TYPE_INFO, | 456 | LOG (GNUNET_ERROR_TYPE_INFO, |
469 | _("Accepting connection from `%s': %p\n"), | 457 | _ ("Accepting connection from `%s': %p\n"), |
470 | GNUNET_a2s (uaddr, | 458 | GNUNET_a2s (uaddr, addrlen), |
471 | addrlen), | ||
472 | connection); | 459 | connection); |
473 | return connection; | 460 | return connection; |
474 | } | 461 | } |
@@ -503,14 +490,13 @@ GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, | |||
503 | * @param errcode error code to send | 490 | * @param errcode error code to send |
504 | */ | 491 | */ |
505 | static void | 492 | static void |
506 | signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, | 493 | signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode) |
507 | int errcode) | ||
508 | { | 494 | { |
509 | GNUNET_CONNECTION_Receiver receiver; | 495 | GNUNET_CONNECTION_Receiver receiver; |
510 | 496 | ||
511 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 497 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
512 | "Receive encounters error (%s), connection closed (%p)\n", | 498 | "Receive encounters error (%s), connection closed (%p)\n", |
513 | STRERROR (errcode), | 499 | strerror (errcode), |
514 | connection); | 500 | connection); |
515 | GNUNET_assert (NULL != (receiver = connection->receiver)); | 501 | GNUNET_assert (NULL != (receiver = connection->receiver)); |
516 | connection->receiver = NULL; | 502 | connection->receiver = NULL; |
@@ -549,21 +535,18 @@ signal_receive_timeout (struct GNUNET_CONNECTION_Handle *connection) | |||
549 | * @param ecode error code (errno) | 535 | * @param ecode error code (errno) |
550 | */ | 536 | */ |
551 | static void | 537 | static void |
552 | signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, | 538 | signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, int ecode) |
553 | int ecode) | ||
554 | { | 539 | { |
555 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 540 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
556 | 541 | ||
557 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 542 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
558 | "Transmission encounterd error (%s), connection closed (%p)\n", | 543 | "Transmission encounterd error (%s), connection closed (%p)\n", |
559 | STRERROR (ecode), | 544 | strerror (ecode), |
560 | connection); | 545 | connection); |
561 | if (NULL != connection->sock) | 546 | if (NULL != connection->sock) |
562 | { | 547 | { |
563 | (void) GNUNET_NETWORK_socket_shutdown (connection->sock, | 548 | (void) GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR); |
564 | SHUT_RDWR); | 549 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); |
565 | GNUNET_break (GNUNET_OK == | ||
566 | GNUNET_NETWORK_socket_close (connection->sock)); | ||
567 | connection->sock = NULL; | 550 | connection->sock = NULL; |
568 | GNUNET_assert (NULL == connection->write_task); | 551 | GNUNET_assert (NULL == connection->write_task); |
569 | } | 552 | } |
@@ -576,12 +559,10 @@ signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, | |||
576 | return; | 559 | return; |
577 | } | 560 | } |
578 | if (NULL == connection->nth.notify_ready) | 561 | if (NULL == connection->nth.notify_ready) |
579 | return; /* nobody to tell about it */ | 562 | return; /* nobody to tell about it */ |
580 | notify = connection->nth.notify_ready; | 563 | notify = connection->nth.notify_ready; |
581 | connection->nth.notify_ready = NULL; | 564 | connection->nth.notify_ready = NULL; |
582 | notify (connection->nth.notify_ready_cls, | 565 | notify (connection->nth.notify_ready_cls, 0, NULL); |
583 | 0, | ||
584 | NULL); | ||
585 | } | 566 | } |
586 | 567 | ||
587 | 568 | ||
@@ -597,7 +578,7 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
597 | LOG (GNUNET_ERROR_TYPE_INFO, | 578 | LOG (GNUNET_ERROR_TYPE_INFO, |
598 | "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n", | 579 | "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n", |
599 | connection->hostname, | 580 | connection->hostname, |
600 | connection->port); | 581 | connection->port); |
601 | GNUNET_break (NULL == connection->ap_head); | 582 | GNUNET_break (NULL == connection->ap_head); |
602 | GNUNET_break (NULL == connection->ap_tail); | 583 | GNUNET_break (NULL == connection->ap_tail); |
603 | GNUNET_break (GNUNET_NO == connection->dns_active); | 584 | GNUNET_break (GNUNET_NO == connection->dns_active); |
@@ -608,15 +589,13 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
608 | /* signal errors for jobs that used to wait on the connection */ | 589 | /* signal errors for jobs that used to wait on the connection */ |
609 | connection->destroy_later = 1; | 590 | connection->destroy_later = 1; |
610 | if (NULL != connection->receiver) | 591 | if (NULL != connection->receiver) |
611 | signal_receive_error (connection, | 592 | signal_receive_error (connection, ECONNREFUSED); |
612 | ECONNREFUSED); | ||
613 | if (NULL != connection->nth.notify_ready) | 593 | if (NULL != connection->nth.notify_ready) |
614 | { | 594 | { |
615 | GNUNET_assert (NULL != connection->nth.timeout_task); | 595 | GNUNET_assert (NULL != connection->nth.timeout_task); |
616 | GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); | 596 | GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); |
617 | connection->nth.timeout_task = NULL; | 597 | connection->nth.timeout_task = NULL; |
618 | signal_transmit_error (connection, | 598 | signal_transmit_error (connection, ECONNREFUSED); |
619 | ECONNREFUSED); | ||
620 | } | 599 | } |
621 | if (-1 == connection->destroy_later) | 600 | if (-1 == connection->destroy_later) |
622 | { | 601 | { |
@@ -658,21 +637,21 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
658 | { | 637 | { |
659 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 638 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
660 | "Connection to `%s' succeeded! (%p)\n", | 639 | "Connection to `%s' succeeded! (%p)\n", |
661 | GNUNET_a2s (connection->addr, | 640 | GNUNET_a2s (connection->addr, connection->addrlen), |
662 | connection->addrlen), | ||
663 | connection); | 641 | connection); |
664 | /* trigger jobs that waited for the connection */ | 642 | /* trigger jobs that waited for the connection */ |
665 | if (NULL != connection->receiver) | 643 | if (NULL != connection->receiver) |
666 | { | 644 | { |
667 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 645 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
668 | "Connection succeeded, starting with receiving data (%p)\n", | 646 | "Connection succeeded, starting with receiving data (%p)\n", |
669 | connection); | 647 | connection); |
670 | GNUNET_assert (NULL == connection->read_task); | 648 | GNUNET_assert (NULL == connection->read_task); |
671 | connection->read_task = | 649 | connection->read_task = |
672 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining | 650 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( |
673 | (connection->receive_timeout), | 651 | connection->receive_timeout), |
674 | connection->sock, | 652 | connection->sock, |
675 | &receive_ready, connection); | 653 | &receive_ready, |
654 | connection); | ||
676 | } | 655 | } |
677 | if (NULL != connection->nth.notify_ready) | 656 | if (NULL != connection->nth.notify_ready) |
678 | { | 657 | { |
@@ -684,9 +663,11 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
684 | connection->nth.timeout_task = NULL; | 663 | connection->nth.timeout_task = NULL; |
685 | GNUNET_assert (connection->write_task == NULL); | 664 | GNUNET_assert (connection->write_task == NULL); |
686 | connection->write_task = | 665 | connection->write_task = |
687 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining | 666 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining ( |
688 | (connection->nth.transmit_timeout), connection->sock, | 667 | connection->nth.transmit_timeout), |
689 | &transmit_ready, connection); | 668 | connection->sock, |
669 | &transmit_ready, | ||
670 | connection); | ||
690 | } | 671 | } |
691 | } | 672 | } |
692 | 673 | ||
@@ -708,28 +689,24 @@ connect_probe_continuation (void *cls) | |||
708 | socklen_t len; | 689 | socklen_t len; |
709 | 690 | ||
710 | GNUNET_assert (NULL != ap->sock); | 691 | GNUNET_assert (NULL != ap->sock); |
711 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, | 692 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap); |
712 | connection->ap_tail, | ||
713 | ap); | ||
714 | len = sizeof (error); | 693 | len = sizeof (error); |
715 | errno = 0; | 694 | errno = 0; |
716 | error = 0; | 695 | error = 0; |
717 | tc = GNUNET_SCHEDULER_get_task_context (); | 696 | tc = GNUNET_SCHEDULER_get_task_context (); |
718 | if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || | 697 | if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || |
719 | (GNUNET_OK != | 698 | (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt (ap->sock, |
720 | GNUNET_NETWORK_socket_getsockopt (ap->sock, | 699 | SOL_SOCKET, |
721 | SOL_SOCKET, | 700 | SO_ERROR, |
722 | SO_ERROR, | 701 | &error, |
723 | &error, | 702 | &len)) || |
724 | &len)) || | 703 | (0 != error)) |
725 | (0 != error) ) | ||
726 | { | 704 | { |
727 | GNUNET_break (GNUNET_OK == | 705 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); |
728 | GNUNET_NETWORK_socket_close (ap->sock)); | ||
729 | GNUNET_free (ap); | 706 | GNUNET_free (ap); |
730 | if ( (NULL == connection->ap_head) && | 707 | if ((NULL == connection->ap_head) && |
731 | (GNUNET_NO == connection->dns_active) && | 708 | (GNUNET_NO == connection->dns_active) && |
732 | (NULL == connection->proxy_handshake) ) | 709 | (NULL == connection->proxy_handshake)) |
733 | connect_fail_continuation (connection); | 710 | connect_fail_continuation (connection); |
734 | return; | 711 | return; |
735 | } | 712 | } |
@@ -745,9 +722,7 @@ connect_probe_continuation (void *cls) | |||
745 | { | 722 | { |
746 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 723 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
747 | GNUNET_SCHEDULER_cancel (pos->task); | 724 | GNUNET_SCHEDULER_cancel (pos->task); |
748 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, | 725 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); |
749 | connection->ap_tail, | ||
750 | pos); | ||
751 | GNUNET_free (pos); | 726 | GNUNET_free (pos); |
752 | } | 727 | } |
753 | connect_success_continuation (connection); | 728 | connect_success_continuation (connection); |
@@ -774,14 +749,13 @@ try_connect_using_address (void *cls, | |||
774 | if (NULL == addr) | 749 | if (NULL == addr) |
775 | { | 750 | { |
776 | connection->dns_active = NULL; | 751 | connection->dns_active = NULL; |
777 | if ((NULL == connection->ap_head) && | 752 | if ((NULL == connection->ap_head) && (NULL == connection->sock) && |
778 | (NULL == connection->sock) && | ||
779 | (NULL == connection->proxy_handshake)) | 753 | (NULL == connection->proxy_handshake)) |
780 | connect_fail_continuation (connection); | 754 | connect_fail_continuation (connection); |
781 | return; | 755 | return; |
782 | } | 756 | } |
783 | if (NULL != connection->sock) | 757 | if (NULL != connection->sock) |
784 | return; /* already connected */ | 758 | return; /* already connected */ |
785 | GNUNET_assert (NULL == connection->addr); | 759 | GNUNET_assert (NULL == connection->addr); |
786 | /* try to connect */ | 760 | /* try to connect */ |
787 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 761 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -807,23 +781,20 @@ try_connect_using_address (void *cls, | |||
807 | default: | 781 | default: |
808 | GNUNET_break (0); | 782 | GNUNET_break (0); |
809 | GNUNET_free (ap); | 783 | GNUNET_free (ap); |
810 | return; /* not supported by us */ | 784 | return; /* not supported by us */ |
811 | } | 785 | } |
812 | ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, | 786 | ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); |
813 | SOCK_STREAM, 0); | ||
814 | if (NULL == ap->sock) | 787 | if (NULL == ap->sock) |
815 | { | 788 | { |
816 | GNUNET_free (ap); | 789 | GNUNET_free (ap); |
817 | return; /* not supported by OS */ | 790 | return; /* not supported by OS */ |
818 | } | 791 | } |
819 | LOG (GNUNET_ERROR_TYPE_INFO, | 792 | LOG (GNUNET_ERROR_TYPE_INFO, |
820 | "Trying to connect to `%s' (%p)\n", | 793 | "Trying to connect to `%s' (%p)\n", |
821 | GNUNET_a2s (ap->addr, ap->addrlen), | 794 | GNUNET_a2s (ap->addr, ap->addrlen), |
822 | connection); | 795 | connection); |
823 | if ((GNUNET_OK != | 796 | if ((GNUNET_OK != |
824 | GNUNET_NETWORK_socket_connect (ap->sock, | 797 | GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && |
825 | ap->addr, | ||
826 | ap->addrlen)) && | ||
827 | (EINPROGRESS != errno)) | 798 | (EINPROGRESS != errno)) |
828 | { | 799 | { |
829 | /* maybe refused / unsupported address, try next */ | 800 | /* maybe refused / unsupported address, try next */ |
@@ -836,14 +807,16 @@ try_connect_using_address (void *cls, | |||
836 | delay = CONNECT_RETRY_TIMEOUT; | 807 | delay = CONNECT_RETRY_TIMEOUT; |
837 | if (NULL != connection->nth.notify_ready) | 808 | if (NULL != connection->nth.notify_ready) |
838 | delay = GNUNET_TIME_relative_min (delay, | 809 | delay = GNUNET_TIME_relative_min (delay, |
839 | GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout)); | 810 | GNUNET_TIME_absolute_get_remaining ( |
811 | connection->nth.transmit_timeout)); | ||
840 | if (NULL != connection->receiver) | 812 | if (NULL != connection->receiver) |
841 | delay = GNUNET_TIME_relative_min (delay, | 813 | delay = GNUNET_TIME_relative_min (delay, |
842 | GNUNET_TIME_absolute_get_remaining (connection->receive_timeout)); | 814 | GNUNET_TIME_absolute_get_remaining ( |
815 | connection->receive_timeout)); | ||
843 | ap->task = GNUNET_SCHEDULER_add_write_net (delay, | 816 | ap->task = GNUNET_SCHEDULER_add_write_net (delay, |
844 | ap->sock, | 817 | ap->sock, |
845 | &connect_probe_continuation, | 818 | &connect_probe_continuation, |
846 | ap); | 819 | ap); |
847 | } | 820 | } |
848 | 821 | ||
849 | 822 | ||
@@ -858,25 +831,25 @@ try_connect_using_address (void *cls, | |||
858 | * @return the connection handle | 831 | * @return the connection handle |
859 | */ | 832 | */ |
860 | struct GNUNET_CONNECTION_Handle * | 833 | struct GNUNET_CONNECTION_Handle * |
861 | GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 834 | GNUNET_CONNECTION_create_from_connect ( |
862 | const char *hostname, | 835 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
863 | uint16_t port) | 836 | const char *hostname, |
837 | uint16_t port) | ||
864 | { | 838 | { |
865 | struct GNUNET_CONNECTION_Handle *connection; | 839 | struct GNUNET_CONNECTION_Handle *connection; |
866 | 840 | ||
867 | GNUNET_assert (0 < strlen (hostname)); /* sanity check */ | 841 | GNUNET_assert (0 < strlen (hostname)); /* sanity check */ |
868 | connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); | 842 | connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); |
869 | connection->cfg = cfg; | 843 | connection->cfg = cfg; |
870 | connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; | 844 | connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; |
871 | connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); | 845 | connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); |
872 | connection->port = port; | 846 | connection->port = port; |
873 | connection->hostname = GNUNET_strdup (hostname); | 847 | connection->hostname = GNUNET_strdup (hostname); |
874 | connection->dns_active = | 848 | connection->dns_active = GNUNET_RESOLVER_ip_get (connection->hostname, |
875 | GNUNET_RESOLVER_ip_get (connection->hostname, | 849 | AF_UNSPEC, |
876 | AF_UNSPEC, | 850 | CONNECT_RETRY_TIMEOUT, |
877 | CONNECT_RETRY_TIMEOUT, | 851 | &try_connect_using_address, |
878 | &try_connect_using_address, | 852 | connection); |
879 | connection); | ||
880 | return connection; | 853 | return connection; |
881 | } | 854 | } |
882 | 855 | ||
@@ -891,14 +864,15 @@ GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle | |||
891 | * @return the connection handle, NULL on systems without UNIX support | 864 | * @return the connection handle, NULL on systems without UNIX support |
892 | */ | 865 | */ |
893 | struct GNUNET_CONNECTION_Handle * | 866 | struct GNUNET_CONNECTION_Handle * |
894 | GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURATION_Handle *cfg, | 867 | GNUNET_CONNECTION_create_from_connect_to_unixpath ( |
895 | const char *unixpath) | 868 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
869 | const char *unixpath) | ||
896 | { | 870 | { |
897 | #ifdef AF_UNIX | 871 | #ifdef AF_UNIX |
898 | struct GNUNET_CONNECTION_Handle *connection; | 872 | struct GNUNET_CONNECTION_Handle *connection; |
899 | struct sockaddr_un *un; | 873 | struct sockaddr_un *un; |
900 | 874 | ||
901 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ | 875 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ |
902 | un = GNUNET_new (struct sockaddr_un); | 876 | un = GNUNET_new (struct sockaddr_un); |
903 | un->sun_family = AF_UNIX; | 877 | un->sun_family = AF_UNIX; |
904 | GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path)); | 878 | GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path)); |
@@ -907,7 +881,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
907 | int abstract; | 881 | int abstract; |
908 | 882 | ||
909 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 883 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
910 | "TESTING", | 884 | "TESTING", |
911 | "USE_ABSTRACT_SOCKETS"); | 885 | "USE_ABSTRACT_SOCKETS"); |
912 | if (GNUNET_YES == abstract) | 886 | if (GNUNET_YES == abstract) |
913 | un->sun_path[0] = '\0'; | 887 | un->sun_path[0] = '\0'; |
@@ -924,9 +898,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
924 | connection->hostname = NULL; | 898 | connection->hostname = NULL; |
925 | connection->addr = (struct sockaddr *) un; | 899 | connection->addr = (struct sockaddr *) un; |
926 | connection->addrlen = sizeof (struct sockaddr_un); | 900 | connection->addrlen = sizeof (struct sockaddr_un); |
927 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, | 901 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); |
928 | SOCK_STREAM, | ||
929 | 0); | ||
930 | if (NULL == connection->sock) | 902 | if (NULL == connection->sock) |
931 | { | 903 | { |
932 | GNUNET_free (connection->addr); | 904 | GNUNET_free (connection->addr); |
@@ -934,15 +906,13 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
934 | GNUNET_free (connection); | 906 | GNUNET_free (connection); |
935 | return NULL; | 907 | return NULL; |
936 | } | 908 | } |
937 | if ( (GNUNET_OK != | 909 | if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (connection->sock, |
938 | GNUNET_NETWORK_socket_connect (connection->sock, | 910 | connection->addr, |
939 | connection->addr, | 911 | connection->addrlen)) && |
940 | connection->addrlen)) && | 912 | (EINPROGRESS != errno)) |
941 | (EINPROGRESS != errno) ) | ||
942 | { | 913 | { |
943 | /* Just return; we expect everything to work eventually so don't fail HARD */ | 914 | /* Just return; we expect everything to work eventually so don't fail HARD */ |
944 | GNUNET_break (GNUNET_OK == | 915 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); |
945 | GNUNET_NETWORK_socket_close (connection->sock)); | ||
946 | connection->sock = NULL; | 916 | connection->sock = NULL; |
947 | return connection; | 917 | return connection; |
948 | } | 918 | } |
@@ -971,17 +941,14 @@ GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s, | |||
971 | { | 941 | { |
972 | struct GNUNET_CONNECTION_Handle *connection; | 942 | struct GNUNET_CONNECTION_Handle *connection; |
973 | 943 | ||
974 | if ( (GNUNET_OK != | 944 | if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && |
975 | GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && | 945 | (EINPROGRESS != errno)) |
976 | (EINPROGRESS != errno) ) | ||
977 | { | 946 | { |
978 | /* maybe refused / unsupported address, try next */ | 947 | /* maybe refused / unsupported address, try next */ |
979 | LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, | 948 | LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "connect"); |
980 | "connect"); | ||
981 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 949 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
982 | "Attempt to connect to `%s' failed\n", | 950 | "Attempt to connect to `%s' failed\n", |
983 | GNUNET_a2s (serv_addr, | 951 | GNUNET_a2s (serv_addr, addrlen)); |
984 | addrlen)); | ||
985 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); | 952 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
986 | return NULL; | 953 | return NULL; |
987 | } | 954 | } |
@@ -1018,13 +985,10 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, | |||
1018 | s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); | 985 | s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); |
1019 | if (NULL == s) | 986 | if (NULL == s) |
1020 | { | 987 | { |
1021 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 988 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket"); |
1022 | "socket"); | ||
1023 | return NULL; | 989 | return NULL; |
1024 | } | 990 | } |
1025 | return GNUNET_CONNECTION_connect_socket (s, | 991 | return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen); |
1026 | serv_addr, | ||
1027 | addrlen); | ||
1028 | } | 992 | } |
1029 | 993 | ||
1030 | 994 | ||
@@ -1039,12 +1003,10 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, | |||
1039 | int | 1003 | int |
1040 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) | 1004 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) |
1041 | { | 1005 | { |
1042 | if ((NULL != connection->ap_head) || | 1006 | if ((NULL != connection->ap_head) || (NULL != connection->dns_active) || |
1043 | (NULL != connection->dns_active) || | ||
1044 | (NULL != connection->proxy_handshake)) | 1007 | (NULL != connection->proxy_handshake)) |
1045 | return GNUNET_YES; /* still trying to connect */ | 1008 | return GNUNET_YES; /* still trying to connect */ |
1046 | if ( (0 != connection->destroy_later) || | 1009 | if ((0 != connection->destroy_later) || (NULL == connection->sock)) |
1047 | (NULL == connection->sock) ) | ||
1048 | return GNUNET_NO; | 1010 | return GNUNET_NO; |
1049 | return GNUNET_YES; | 1011 | return GNUNET_YES; |
1050 | } | 1012 | } |
@@ -1067,9 +1029,7 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
1067 | connection->destroy_later = -1; | 1029 | connection->destroy_later = -1; |
1068 | return; | 1030 | return; |
1069 | } | 1031 | } |
1070 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1032 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection); |
1071 | "Shutting down connection (%p)\n", | ||
1072 | connection); | ||
1073 | GNUNET_assert (NULL == connection->nth.notify_ready); | 1033 | GNUNET_assert (NULL == connection->nth.notify_ready); |
1074 | GNUNET_assert (NULL == connection->receiver); | 1034 | GNUNET_assert (NULL == connection->receiver); |
1075 | if (NULL != connection->write_task) | 1035 | if (NULL != connection->write_task) |
@@ -1098,27 +1058,21 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
1098 | { | 1058 | { |
1099 | /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */ | 1059 | /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */ |
1100 | connection->proxy_handshake->destroy_later = -1; | 1060 | connection->proxy_handshake->destroy_later = -1; |
1101 | connection->proxy_handshake = NULL; /* Not leaked ??? */ | 1061 | connection->proxy_handshake = NULL; /* Not leaked ??? */ |
1102 | } | 1062 | } |
1103 | while (NULL != (pos = connection->ap_head)) | 1063 | while (NULL != (pos = connection->ap_head)) |
1104 | { | 1064 | { |
1105 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 1065 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
1106 | GNUNET_SCHEDULER_cancel (pos->task); | 1066 | GNUNET_SCHEDULER_cancel (pos->task); |
1107 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, | 1067 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); |
1108 | connection->ap_tail, | ||
1109 | pos); | ||
1110 | GNUNET_free (pos); | 1068 | GNUNET_free (pos); |
1111 | } | 1069 | } |
1112 | if ( (NULL != connection->sock) && | 1070 | if ((NULL != connection->sock) && (GNUNET_YES != connection->persist)) |
1113 | (GNUNET_YES != connection->persist) ) | ||
1114 | { | 1071 | { |
1115 | if ((GNUNET_OK != | 1072 | if ((GNUNET_OK != |
1116 | GNUNET_NETWORK_socket_shutdown (connection->sock, | 1073 | GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) && |
1117 | SHUT_RDWR)) && | 1074 | (ENOTCONN != errno) && (ECONNRESET != errno)) |
1118 | (ENOTCONN != errno) && | 1075 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown"); |
1119 | (ECONNRESET != errno) ) | ||
1120 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, | ||
1121 | "shutdown"); | ||
1122 | } | 1076 | } |
1123 | if (NULL != connection->sock) | 1077 | if (NULL != connection->sock) |
1124 | { | 1078 | { |
@@ -1129,7 +1083,8 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
1129 | } | 1083 | } |
1130 | else | 1084 | else |
1131 | { | 1085 | { |
1132 | GNUNET_NETWORK_socket_free_memory_only_ (connection->sock); /* at least no memory leak (we deliberately | 1086 | GNUNET_NETWORK_socket_free_memory_only_ ( |
1087 | connection->sock); /* at least no memory leak (we deliberately | ||
1133 | * leak the socket in this special case) ... */ | 1088 | * leak the socket in this special case) ... */ |
1134 | } | 1089 | } |
1135 | } | 1090 | } |
@@ -1160,12 +1115,12 @@ receive_ready (void *cls) | |||
1160 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 1115 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) |
1161 | { | 1116 | { |
1162 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1117 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1163 | "Receive from `%s' encounters error: timeout (%s, %p)\n", | 1118 | "Receive from `%s' encounters error: timeout (%s, %p)\n", |
1164 | GNUNET_a2s (connection->addr, | 1119 | GNUNET_a2s (connection->addr, connection->addrlen), |
1165 | connection->addrlen), | 1120 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration ( |
1166 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout), | 1121 | connection->receive_timeout), |
1167 | GNUNET_YES), | 1122 | GNUNET_YES), |
1168 | connection); | 1123 | connection); |
1169 | signal_receive_timeout (connection); | 1124 | signal_receive_timeout (connection); |
1170 | return; | 1125 | return; |
1171 | } | 1126 | } |
@@ -1175,12 +1130,9 @@ receive_ready (void *cls) | |||
1175 | signal_receive_error (connection, ECONNREFUSED); | 1130 | signal_receive_error (connection, ECONNREFUSED); |
1176 | return; | 1131 | return; |
1177 | } | 1132 | } |
1178 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 1133 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock)); |
1179 | connection->sock)); | ||
1180 | RETRY: | 1134 | RETRY: |
1181 | ret = GNUNET_NETWORK_socket_recv (connection->sock, | 1135 | ret = GNUNET_NETWORK_socket_recv (connection->sock, buffer, connection->max); |
1182 | buffer, | ||
1183 | connection->max); | ||
1184 | if (-1 == ret) | 1136 | if (-1 == ret) |
1185 | { | 1137 | { |
1186 | if (EINTR == errno) | 1138 | if (EINTR == errno) |
@@ -1192,8 +1144,7 @@ RETRY: | |||
1192 | "receive_ready read %u/%u bytes from `%s' (%p)!\n", | 1144 | "receive_ready read %u/%u bytes from `%s' (%p)!\n", |
1193 | (unsigned int) ret, | 1145 | (unsigned int) ret, |
1194 | connection->max, | 1146 | connection->max, |
1195 | GNUNET_a2s (connection->addr, | 1147 | GNUNET_a2s (connection->addr, connection->addrlen), |
1196 | connection->addrlen), | ||
1197 | connection); | 1148 | connection); |
1198 | GNUNET_assert (NULL != (receiver = connection->receiver)); | 1149 | GNUNET_assert (NULL != (receiver = connection->receiver)); |
1199 | connection->receiver = NULL; | 1150 | connection->receiver = NULL; |
@@ -1238,22 +1189,18 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, | |||
1238 | if (NULL != connection->sock) | 1189 | if (NULL != connection->sock) |
1239 | { | 1190 | { |
1240 | connection->read_task = | 1191 | connection->read_task = |
1241 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining | 1192 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( |
1242 | (connection->receive_timeout), | 1193 | connection->receive_timeout), |
1243 | connection->sock, | 1194 | connection->sock, |
1244 | &receive_ready, | 1195 | &receive_ready, |
1245 | connection); | 1196 | connection); |
1246 | return GNUNET_OK; | 1197 | return GNUNET_OK; |
1247 | } | 1198 | } |
1248 | if ((NULL == connection->dns_active) && | 1199 | if ((NULL == connection->dns_active) && (NULL == connection->ap_head) && |
1249 | (NULL == connection->ap_head) && | ||
1250 | (NULL == connection->proxy_handshake)) | 1200 | (NULL == connection->proxy_handshake)) |
1251 | { | 1201 | { |
1252 | connection->receiver = NULL; | 1202 | connection->receiver = NULL; |
1253 | receiver (receiver_cls, | 1203 | receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); |
1254 | NULL, 0, | ||
1255 | NULL, 0, | ||
1256 | ETIMEDOUT); | ||
1257 | return GNUNET_SYSERR; | 1204 | return GNUNET_SYSERR; |
1258 | } | 1205 | } |
1259 | return GNUNET_OK; | 1206 | return GNUNET_OK; |
@@ -1297,13 +1244,11 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection) | |||
1297 | size_t size; | 1244 | size_t size; |
1298 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 1245 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
1299 | 1246 | ||
1300 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1247 | LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n"); |
1301 | "process_notify is running\n"); | ||
1302 | GNUNET_assert (NULL == connection->write_task); | 1248 | GNUNET_assert (NULL == connection->write_task); |
1303 | if (NULL == (notify = connection->nth.notify_ready)) | 1249 | if (NULL == (notify = connection->nth.notify_ready)) |
1304 | { | 1250 | { |
1305 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1251 | LOG (GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n"); |
1306 | "No one to notify\n"); | ||
1307 | return GNUNET_NO; | 1252 | return GNUNET_NO; |
1308 | } | 1253 | } |
1309 | used = connection->write_buffer_off - connection->write_buffer_pos; | 1254 | used = connection->write_buffer_off - connection->write_buffer_pos; |
@@ -1311,8 +1256,7 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection) | |||
1311 | size = connection->nth.notify_size; | 1256 | size = connection->nth.notify_size; |
1312 | if (size > avail) | 1257 | if (size > avail) |
1313 | { | 1258 | { |
1314 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1259 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n"); |
1315 | "Not enough buffer\n"); | ||
1316 | return GNUNET_NO; | 1260 | return GNUNET_NO; |
1317 | } | 1261 | } |
1318 | connection->nth.notify_ready = NULL; | 1262 | connection->nth.notify_ready = NULL; |
@@ -1327,9 +1271,9 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection) | |||
1327 | } | 1271 | } |
1328 | avail = connection->write_buffer_size - connection->write_buffer_off; | 1272 | avail = connection->write_buffer_size - connection->write_buffer_off; |
1329 | GNUNET_assert (avail >= size); | 1273 | GNUNET_assert (avail >= size); |
1330 | size = | 1274 | size = notify (connection->nth.notify_ready_cls, |
1331 | notify (connection->nth.notify_ready_cls, avail, | 1275 | avail, |
1332 | &connection->write_buffer[connection->write_buffer_off]); | 1276 | &connection->write_buffer[connection->write_buffer_off]); |
1333 | GNUNET_assert (size <= avail); | 1277 | GNUNET_assert (size <= avail); |
1334 | if (0 != size) | 1278 | if (0 != size) |
1335 | connection->write_buffer_off += size; | 1279 | connection->write_buffer_off += size; |
@@ -1358,15 +1302,12 @@ transmit_timeout (void *cls) | |||
1358 | "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", | 1302 | "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", |
1359 | connection->hostname, | 1303 | connection->hostname, |
1360 | connection->port, | 1304 | connection->port, |
1361 | GNUNET_a2s (connection->addr, | 1305 | GNUNET_a2s (connection->addr, connection->addrlen), |
1362 | connection->addrlen), | ||
1363 | connection); | 1306 | connection); |
1364 | notify = connection->nth.notify_ready; | 1307 | notify = connection->nth.notify_ready; |
1365 | GNUNET_assert (NULL != notify); | 1308 | GNUNET_assert (NULL != notify); |
1366 | connection->nth.notify_ready = NULL; | 1309 | connection->nth.notify_ready = NULL; |
1367 | notify (connection->nth.notify_ready_cls, | 1310 | notify (connection->nth.notify_ready_cls, 0, NULL); |
1368 | 0, | ||
1369 | NULL); | ||
1370 | } | 1311 | } |
1371 | 1312 | ||
1372 | 1313 | ||
@@ -1393,9 +1334,7 @@ connect_error (void *cls) | |||
1393 | connection->write_task = NULL; | 1334 | connection->write_task = NULL; |
1394 | notify = connection->nth.notify_ready; | 1335 | notify = connection->nth.notify_ready; |
1395 | connection->nth.notify_ready = NULL; | 1336 | connection->nth.notify_ready = NULL; |
1396 | notify (connection->nth.notify_ready_cls, | 1337 | notify (connection->nth.notify_ready_cls, 0, NULL); |
1397 | 0, | ||
1398 | NULL); | ||
1399 | } | 1338 | } |
1400 | 1339 | ||
1401 | 1340 | ||
@@ -1413,9 +1352,7 @@ transmit_ready (void *cls) | |||
1413 | ssize_t ret; | 1352 | ssize_t ret; |
1414 | size_t have; | 1353 | size_t have; |
1415 | 1354 | ||
1416 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1355 | LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection); |
1417 | "transmit_ready running (%p).\n", | ||
1418 | connection); | ||
1419 | GNUNET_assert (NULL != connection->write_task); | 1356 | GNUNET_assert (NULL != connection->write_task); |
1420 | connection->write_task = NULL; | 1357 | connection->write_task = NULL; |
1421 | GNUNET_assert (NULL == connection->nth.timeout_task); | 1358 | GNUNET_assert (NULL == connection->nth.timeout_task); |
@@ -1424,8 +1361,7 @@ transmit_ready (void *cls) | |||
1424 | { | 1361 | { |
1425 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1362 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1426 | "Transmit to `%s' fails, time out reached (%p).\n", | 1363 | "Transmit to `%s' fails, time out reached (%p).\n", |
1427 | GNUNET_a2s (connection->addr, | 1364 | GNUNET_a2s (connection->addr, connection->addrlen), |
1428 | connection->addrlen), | ||
1429 | connection); | 1365 | connection); |
1430 | notify = connection->nth.notify_ready; | 1366 | notify = connection->nth.notify_ready; |
1431 | GNUNET_assert (NULL != notify); | 1367 | GNUNET_assert (NULL != notify); |
@@ -1441,8 +1377,7 @@ transmit_ready (void *cls) | |||
1441 | * Hence retry. */ | 1377 | * Hence retry. */ |
1442 | goto SCHEDULE_WRITE; | 1378 | goto SCHEDULE_WRITE; |
1443 | } | 1379 | } |
1444 | if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, | 1380 | if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock)) |
1445 | connection->sock)) | ||
1446 | { | 1381 | { |
1447 | GNUNET_assert (NULL == connection->write_task); | 1382 | GNUNET_assert (NULL == connection->write_task); |
1448 | /* special circumstances (in particular, shutdown): not yet ready | 1383 | /* special circumstances (in particular, shutdown): not yet ready |
@@ -1454,7 +1389,7 @@ transmit_ready (void *cls) | |||
1454 | (connection->write_buffer_size < connection->nth.notify_size)) | 1389 | (connection->write_buffer_size < connection->nth.notify_size)) |
1455 | { | 1390 | { |
1456 | connection->write_buffer = | 1391 | connection->write_buffer = |
1457 | GNUNET_realloc (connection->write_buffer, connection->nth.notify_size); | 1392 | GNUNET_realloc (connection->write_buffer, connection->nth.notify_size); |
1458 | connection->write_buffer_size = connection->nth.notify_size; | 1393 | connection->write_buffer_size = connection->nth.notify_size; |
1459 | } | 1394 | } |
1460 | process_notify (connection); | 1395 | process_notify (connection); |
@@ -1465,13 +1400,15 @@ transmit_ready (void *cls) | |||
1465 | return; | 1400 | return; |
1466 | } | 1401 | } |
1467 | GNUNET_assert (have <= connection->write_buffer_size); | 1402 | GNUNET_assert (have <= connection->write_buffer_size); |
1468 | GNUNET_assert (have + connection->write_buffer_pos <= connection->write_buffer_size); | 1403 | GNUNET_assert (have + connection->write_buffer_pos <= |
1404 | connection->write_buffer_size); | ||
1469 | GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); | 1405 | GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); |
1470 | RETRY: | 1406 | RETRY: |
1471 | ret = | 1407 | ret = |
1472 | GNUNET_NETWORK_socket_send (connection->sock, | 1408 | GNUNET_NETWORK_socket_send (connection->sock, |
1473 | &connection->write_buffer[connection->write_buffer_pos], | 1409 | &connection |
1474 | have); | 1410 | ->write_buffer[connection->write_buffer_pos], |
1411 | have); | ||
1475 | if (-1 == ret) | 1412 | if (-1 == ret) |
1476 | { | 1413 | { |
1477 | if (EINTR == errno) | 1414 | if (EINTR == errno) |
@@ -1488,8 +1425,7 @@ RETRY: | |||
1488 | "Connection transmitted %u/%u bytes to `%s' (%p)\n", | 1425 | "Connection transmitted %u/%u bytes to `%s' (%p)\n", |
1489 | (unsigned int) ret, | 1426 | (unsigned int) ret, |
1490 | have, | 1427 | have, |
1491 | GNUNET_a2s (connection->addr, | 1428 | GNUNET_a2s (connection->addr, connection->addrlen), |
1492 | connection->addrlen), | ||
1493 | connection); | 1429 | connection); |
1494 | connection->write_buffer_pos += ret; | 1430 | connection->write_buffer_pos += ret; |
1495 | if (connection->write_buffer_pos == connection->write_buffer_off) | 1431 | if (connection->write_buffer_pos == connection->write_buffer_off) |
@@ -1498,25 +1434,25 @@ RETRY: | |||
1498 | connection->write_buffer_pos = 0; | 1434 | connection->write_buffer_pos = 0; |
1499 | connection->write_buffer_off = 0; | 1435 | connection->write_buffer_off = 0; |
1500 | } | 1436 | } |
1501 | if ( (0 == connection->write_buffer_off) && | 1437 | if ((0 == connection->write_buffer_off) && |
1502 | (NULL == connection->nth.notify_ready) ) | 1438 | (NULL == connection->nth.notify_ready)) |
1503 | return; /* all data sent! */ | 1439 | return; /* all data sent! */ |
1504 | /* not done writing, schedule more */ | 1440 | /* not done writing, schedule more */ |
1505 | SCHEDULE_WRITE: | 1441 | SCHEDULE_WRITE: |
1506 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1442 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1507 | "Re-scheduling transmit_ready (more to do) (%p).\n", | 1443 | "Re-scheduling transmit_ready (more to do) (%p).\n", |
1508 | connection); | 1444 | connection); |
1509 | have = connection->write_buffer_off - connection->write_buffer_pos; | 1445 | have = connection->write_buffer_off - connection->write_buffer_pos; |
1510 | GNUNET_assert ( (NULL != connection->nth.notify_ready) || | 1446 | GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0)); |
1511 | (have > 0) ); | ||
1512 | if (NULL == connection->write_task) | 1447 | if (NULL == connection->write_task) |
1513 | connection->write_task = | 1448 | connection->write_task = |
1514 | GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == | 1449 | GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == NULL) |
1515 | NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : | 1450 | ? GNUNET_TIME_UNIT_FOREVER_REL |
1516 | GNUNET_TIME_absolute_get_remaining | 1451 | : GNUNET_TIME_absolute_get_remaining ( |
1517 | (connection->nth.transmit_timeout), | 1452 | connection->nth.transmit_timeout), |
1518 | connection->sock, | 1453 | connection->sock, |
1519 | &transmit_ready, connection); | 1454 | &transmit_ready, |
1455 | connection); | ||
1520 | } | 1456 | } |
1521 | 1457 | ||
1522 | 1458 | ||
@@ -1535,11 +1471,12 @@ SCHEDULE_WRITE: | |||
1535 | * NULL if we are already going to notify someone else (busy) | 1471 | * NULL if we are already going to notify someone else (busy) |
1536 | */ | 1472 | */ |
1537 | struct GNUNET_CONNECTION_TransmitHandle * | 1473 | struct GNUNET_CONNECTION_TransmitHandle * |
1538 | GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, | 1474 | GNUNET_CONNECTION_notify_transmit_ready ( |
1539 | size_t size, | 1475 | struct GNUNET_CONNECTION_Handle *connection, |
1540 | struct GNUNET_TIME_Relative timeout, | 1476 | size_t size, |
1541 | GNUNET_CONNECTION_TransmitReadyNotify notify, | 1477 | struct GNUNET_TIME_Relative timeout, |
1542 | void *notify_cls) | 1478 | GNUNET_CONNECTION_TransmitReadyNotify notify, |
1479 | void *notify_cls) | ||
1543 | { | 1480 | { |
1544 | if (NULL != connection->nth.notify_ready) | 1481 | if (NULL != connection->nth.notify_ready) |
1545 | { | 1482 | { |
@@ -1557,15 +1494,13 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1557 | connection->nth.notify_size = size; | 1494 | connection->nth.notify_size = size; |
1558 | connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1495 | connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1559 | GNUNET_assert (NULL == connection->nth.timeout_task); | 1496 | GNUNET_assert (NULL == connection->nth.timeout_task); |
1560 | if ((NULL == connection->sock) && | 1497 | if ((NULL == connection->sock) && (NULL == connection->ap_head) && |
1561 | (NULL == connection->ap_head) && | 1498 | (NULL == connection->dns_active) && (NULL == connection->proxy_handshake)) |
1562 | (NULL == connection->dns_active) && | ||
1563 | (NULL == connection->proxy_handshake)) | ||
1564 | { | 1499 | { |
1565 | if (NULL != connection->write_task) | 1500 | if (NULL != connection->write_task) |
1566 | GNUNET_SCHEDULER_cancel (connection->write_task); | 1501 | GNUNET_SCHEDULER_cancel (connection->write_task); |
1567 | connection->write_task = GNUNET_SCHEDULER_add_now (&connect_error, | 1502 | connection->write_task = |
1568 | connection); | 1503 | GNUNET_SCHEDULER_add_now (&connect_error, connection); |
1569 | return &connection->nth; | 1504 | return &connection->nth; |
1570 | } | 1505 | } |
1571 | if (NULL != connection->write_task) | 1506 | if (NULL != connection->write_task) |
@@ -1577,10 +1512,11 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1577 | "Scheduling transmission (%p).\n", | 1512 | "Scheduling transmission (%p).\n", |
1578 | connection); | 1513 | connection); |
1579 | connection->write_task = | 1514 | connection->write_task = |
1580 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining | 1515 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining ( |
1581 | (connection->nth.transmit_timeout), | 1516 | connection->nth.transmit_timeout), |
1582 | connection->sock, | 1517 | connection->sock, |
1583 | &transmit_ready, connection); | 1518 | &transmit_ready, |
1519 | connection); | ||
1584 | return &connection->nth; | 1520 | return &connection->nth; |
1585 | } | 1521 | } |
1586 | /* not yet connected, wait for connection */ | 1522 | /* not yet connected, wait for connection */ |
@@ -1588,9 +1524,7 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1588 | "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", | 1524 | "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", |
1589 | connection); | 1525 | connection); |
1590 | connection->nth.timeout_task = | 1526 | connection->nth.timeout_task = |
1591 | GNUNET_SCHEDULER_add_delayed (timeout, | 1527 | GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection); |
1592 | &transmit_timeout, | ||
1593 | connection); | ||
1594 | return &connection->nth; | 1528 | return &connection->nth; |
1595 | } | 1529 | } |
1596 | 1530 | ||
@@ -1601,7 +1535,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1601 | * @param th notification to cancel | 1535 | * @param th notification to cancel |
1602 | */ | 1536 | */ |
1603 | void | 1537 | void |
1604 | GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_TransmitHandle *th) | 1538 | GNUNET_CONNECTION_notify_transmit_ready_cancel ( |
1539 | struct GNUNET_CONNECTION_TransmitHandle *th) | ||
1605 | { | 1540 | { |
1606 | GNUNET_assert (NULL != th->notify_ready); | 1541 | GNUNET_assert (NULL != th->notify_ready); |
1607 | th->notify_ready = NULL; | 1542 | th->notify_ready = NULL; |
@@ -1625,9 +1560,11 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_Transmi | |||
1625 | * @return connection to be proxied | 1560 | * @return connection to be proxied |
1626 | */ | 1561 | */ |
1627 | struct GNUNET_CONNECTION_Handle * | 1562 | struct GNUNET_CONNECTION_Handle * |
1628 | GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph) | 1563 | GNUNET_CONNECTION_create_proxied_from_handshake ( |
1564 | struct GNUNET_CONNECTION_Handle *cph) | ||
1629 | { | 1565 | { |
1630 | struct GNUNET_CONNECTION_Handle *proxied = GNUNET_CONNECTION_create_from_existing (NULL); | 1566 | struct GNUNET_CONNECTION_Handle *proxied = |
1567 | GNUNET_CONNECTION_create_from_existing (NULL); | ||
1631 | 1568 | ||
1632 | proxied->proxy_handshake = cph; | 1569 | proxied->proxy_handshake = cph; |
1633 | return proxied; | 1570 | return proxied; |