diff options
author | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2011-11-04 14:00:32 +0000 |
---|---|---|
committer | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2011-11-04 14:00:32 +0000 |
commit | 35ae75e2d0f26ad0e25861f3c4a5c4c005fd1378 (patch) | |
tree | d0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/util/connection.c | |
parent | 99545d48451fe00589106195cb13c63c5f56b893 (diff) |
curly wars / auto-indentation
git-svn-id: https://gnunet.org/svn/gnunet@18000 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/util/connection.c')
-rw-r--r-- | src/util/connection.c | 1015 |
1 files changed, 500 insertions, 515 deletions
diff --git a/src/util/connection.c b/src/util/connection.c index cd0035a8f3..61c26673be 100644 --- a/src/util/connection.c +++ b/src/util/connection.c @@ -333,8 +333,7 @@ GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock) * @return the boxed socket handle */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle - *osSocket) +GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket) { struct GNUNET_CONNECTION_Handle *ret; @@ -357,8 +356,8 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, - void *access_cls, - struct GNUNET_NETWORK_Handle *lsock) + void *access_cls, + struct GNUNET_NETWORK_Handle *lsock) { struct GNUNET_CONNECTION_Handle *ret; char addr[128]; @@ -379,94 +378,94 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, addrlen = sizeof (addr); sock = - GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); + GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); if (NULL == sock) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept"); - return NULL; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept"); + return NULL; + } if ((addrlen > sizeof (addr)) || (addrlen < sizeof (sa_family_t))) - { - GNUNET_break (0); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); - return NULL; - } + { + GNUNET_break (0); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + return NULL; + } sa = (struct sockaddr *) addr; v6 = (struct sockaddr_in6 *) addr; if ((sa->sa_family == AF_INET6) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) - { - /* convert to V4 address */ - v4 = GNUNET_malloc (sizeof (struct sockaddr_in)); - memset (v4, 0, sizeof (struct sockaddr_in)); - v4->sin_family = AF_INET; + { + /* convert to V4 address */ + v4 = GNUNET_malloc (sizeof (struct sockaddr_in)); + memset (v4, 0, sizeof (struct sockaddr_in)); + v4->sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - v4->sin_len = (u_char) sizeof (struct sockaddr_in); + v4->sin_len = (u_char) sizeof (struct sockaddr_in); #endif - memcpy (&v4->sin_addr, - &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - - sizeof (struct in_addr)], - sizeof (struct in_addr)); - v4->sin_port = v6->sin6_port; - uaddr = v4; - addrlen = sizeof (struct sockaddr_in); - } + memcpy (&v4->sin_addr, + &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - + sizeof (struct in_addr)], + sizeof (struct in_addr)); + v4->sin_port = v6->sin6_port; + uaddr = v4; + addrlen = sizeof (struct sockaddr_in); + } else - { - uaddr = GNUNET_malloc (addrlen); - memcpy (uaddr, addr, addrlen); - } + { + uaddr = GNUNET_malloc (addrlen); + memcpy (uaddr, addr, addrlen); + } gcp = NULL; gc.uid = 0; gc.gid = 0; if (sa->sa_family == AF_UNIX) - { + { #if HAVE_GETPEEREID - /* most BSDs */ - if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) - gcp = &gc; + /* most BSDs */ + if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) + gcp = &gc; #else #ifdef SO_PEERCRED - /* largely traditional GNU/Linux */ - olen = sizeof (uc); - if ((0 == - getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, - &uc, &olen)) && (olen == sizeof (uc))) - { - gc.uid = uc.uid; - gc.gid = uc.gid; - gcp = &gc; - } + /* largely traditional GNU/Linux */ + olen = sizeof (uc); + if ((0 == + getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, &uc, + &olen)) && (olen == sizeof (uc))) + { + gc.uid = uc.uid; + gc.gid = uc.gid; + gcp = &gc; + } #else #if HAVE_GETPEERUCRED - /* this is for Solaris 10 */ - ucred_t *uc; - - uc = NULL; - if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc)) - { - gc.uid = ucred_geteuid (uc); - gc.gid = ucred_getegid (uc); - gcp = &gc; - } - ucred_free (uc); + /* this is for Solaris 10 */ + ucred_t *uc; + + uc = NULL; + if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc)) + { + gc.uid = ucred_geteuid (uc); + gc.gid = ucred_getegid (uc); + gcp = &gc; + } + ucred_free (uc); #endif #endif #endif - } + } if ((access != NULL) && (GNUNET_YES != (aret = access (access_cls, gcp, uaddr, addrlen)))) - { - if (aret == GNUNET_NO) - LOG (GNUNET_ERROR_TYPE_INFO, _("Access denied to `%s'\n"), - GNUNET_a2s (uaddr, addrlen)); - GNUNET_break (GNUNET_OK == - GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); - GNUNET_free (uaddr); - return NULL; - } + { + if (aret == GNUNET_NO) + LOG (GNUNET_ERROR_TYPE_INFO, _("Access denied to `%s'\n"), + GNUNET_a2s (uaddr, addrlen)); + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + GNUNET_free (uaddr); + return NULL; + } ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); @@ -490,7 +489,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, */ int GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock, - void **addr, size_t * addrlen) + void **addr, size_t * addrlen) { if ((sock->addr == NULL) || (sock->addrlen == 0)) return GNUNET_NO; @@ -523,8 +522,7 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); * @param tc unused */ static void -destroy_continuation (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +destroy_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CONNECTION_Handle *sock = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; @@ -533,78 +531,77 @@ destroy_continuation (void *cls, sock->destroy_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_assert (sock->dns_active == NULL); if (0 != (sock->ccs & COCO_TRANSMIT_READY)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroy waits for CCS-TR to be done (%p)\n", sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy waits for CCS-TR to be done (%p)\n", + sock); #endif - sock->ccs |= COCO_DESTROY_CONTINUATION; - return; - } + sock->ccs |= COCO_DESTROY_CONTINUATION; + return; + } if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroy waits for write_task to be done (%p)\n", sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Destroy waits for write_task to be done (%p)\n", sock); #endif - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); - sock->destroy_task = - GNUNET_SCHEDULER_add_after (sock->write_task, &destroy_continuation, - sock); - return; - } + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); + sock->destroy_task = + GNUNET_SCHEDULER_add_after (sock->write_task, &destroy_continuation, + sock); + return; + } if (0 != (sock->ccs & COCO_RECEIVE_AGAIN)) - { - sock->ccs |= COCO_DESTROY_CONTINUATION; - return; - } + { + sock->ccs |= COCO_DESTROY_CONTINUATION; + return; + } if (sock->sock != NULL) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down socket (%p)\n", sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down socket (%p)\n", sock); #endif - if (sock->persist != GNUNET_YES) - { - if ((GNUNET_YES != - GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR)) - && (errno != ENOTCONN) && (errno != ECONNRESET)) - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown"); - } - } - if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) + if (sock->persist != GNUNET_YES) { - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); - sock->destroy_task = - GNUNET_SCHEDULER_add_after (sock->read_task, &destroy_continuation, - sock); - return; + if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR)) + && (errno != ENOTCONN) && (errno != ECONNRESET)) + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown"); } + } + if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); + sock->destroy_task = + GNUNET_SCHEDULER_add_after (sock->read_task, &destroy_continuation, + sock); + return; + } #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock); #endif while (NULL != (pos = sock->ap_head)) - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); - GNUNET_SCHEDULER_cancel (pos->task); - GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos); - GNUNET_free (pos); - } + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); + GNUNET_SCHEDULER_cancel (pos->task); + GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos); + GNUNET_free (pos); + } GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); GNUNET_assert (sock->ccs == COCO_NONE); if (NULL != (notify = sock->nth.notify_ready)) - { - sock->nth.notify_ready = NULL; - notify (sock->nth.notify_ready_cls, 0, NULL); - } + { + sock->nth.notify_ready = NULL; + notify (sock->nth.notify_ready_cls, 0, NULL); + } if (sock->sock != NULL) - { - if (sock->persist != GNUNET_YES) - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); - else - GNUNET_free (sock->sock); /* at least no memory leak (we deliberately - * leak the socket in this special case) ... */ - } + { + if (sock->persist != GNUNET_YES) + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); + else + GNUNET_free (sock->sock); /* at least no memory leak (we deliberately + * leak the socket in this special case) ... */ + } GNUNET_free_non_null (sock->addr); GNUNET_free_non_null (sock->hostname); GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); @@ -639,9 +636,8 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) { #if DEBUG_CONNECTION LOG ((0 != - strncmp (h->hostname, "localhost:", - 10)) ? GNUNET_ERROR_TYPE_INFO : - GNUNET_ERROR_TYPE_WARNING, + strncmp (h->hostname, "localhost:", + 10)) ? GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING, _ ("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"), h->hostname, h->port); @@ -654,39 +650,39 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) /* trigger jobs that used to wait on "connect_task" */ if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_fail_continuation triggers receive_again (%p)\n", h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_fail_continuation triggers receive_again (%p)\n", h); #endif - h->ccs -= COCO_RECEIVE_AGAIN; - h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); - } + h->ccs -= COCO_RECEIVE_AGAIN; + h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); + } if (0 != (h->ccs & COCO_TRANSMIT_READY)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_fail_continuation cancels timeout_task, triggers transmit_ready (%p)\n", - h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_fail_continuation cancels timeout_task, triggers transmit_ready (%p)\n", + h); #endif - GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); - GNUNET_SCHEDULER_cancel (h->nth.timeout_task); - h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; - h->ccs -= COCO_TRANSMIT_READY; - GNUNET_assert (h->nth.notify_ready != NULL); - GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); - h->write_task = GNUNET_SCHEDULER_add_now (&transmit_ready, h); - } + GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); + GNUNET_SCHEDULER_cancel (h->nth.timeout_task); + h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; + h->ccs -= COCO_TRANSMIT_READY; + GNUNET_assert (h->nth.notify_ready != NULL); + GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); + h->write_task = GNUNET_SCHEDULER_add_now (&transmit_ready, h); + } if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_fail_continuation runs destroy_continuation (%p)\n", h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_fail_continuation runs destroy_continuation (%p)\n", h); #endif - h->ccs -= COCO_DESTROY_CONTINUATION; - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); - h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); - } + h->ccs -= COCO_DESTROY_CONTINUATION; + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); + h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); + } } @@ -704,43 +700,42 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) #endif /* trigger jobs that waited for the connection */ if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs receive_again (%p)\n", h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_success_continuation runs receive_again (%p)\n", h); #endif - h->ccs -= COCO_RECEIVE_AGAIN; - h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); - } + h->ccs -= COCO_RECEIVE_AGAIN; + h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); + } if (0 != (h->ccs & COCO_TRANSMIT_READY)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n", - h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n", + h); #endif - GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); - GNUNET_SCHEDULER_cancel (h->nth.timeout_task); - h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; - h->ccs -= COCO_TRANSMIT_READY; - GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); - GNUNET_assert (h->nth.notify_ready != NULL); - h->write_task = - GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining - (h->nth.transmit_timeout), h->sock, - &transmit_ready, h); - } + GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); + GNUNET_SCHEDULER_cancel (h->nth.timeout_task); + h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; + h->ccs -= COCO_TRANSMIT_READY; + GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); + GNUNET_assert (h->nth.notify_ready != NULL); + h->write_task = + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining + (h->nth.transmit_timeout), h->sock, + &transmit_ready, h); + } if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs destroy_continuation (%p)\n", - h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "connect_success_continuation runs destroy_continuation (%p)\n", h); #endif - h->ccs -= COCO_DESTROY_CONTINUATION; - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); - h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); - } + h->ccs -= COCO_DESTROY_CONTINUATION; + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); + h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); + } } @@ -753,7 +748,7 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) */ static void connect_probe_continuation (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct AddressProbe *ap = cls; struct GNUNET_CONNECTION_Handle *h = ap->h; @@ -768,15 +763,15 @@ connect_probe_continuation (void *cls, error = 0; if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || (GNUNET_OK != - GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, - &error, &len)) || (error != 0)) - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); - GNUNET_free (ap); - if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO)) - connect_fail_continuation (h); - return; - } + GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error, + &len)) || (error != 0)) + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); + GNUNET_free (ap); + if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO)) + connect_fail_continuation (h); + return; + } GNUNET_assert (h->sock == NULL); h->sock = ap->sock; GNUNET_assert (h->addr == NULL); @@ -786,12 +781,12 @@ connect_probe_continuation (void *cls, GNUNET_free (ap); /* cancel all other attempts */ while (NULL != (pos = h->ap_head)) - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); - GNUNET_SCHEDULER_cancel (pos->task); - GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos); - GNUNET_free (pos); - } + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); + GNUNET_SCHEDULER_cancel (pos->task); + GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos); + GNUNET_free (pos); + } connect_success_continuation (h); } @@ -806,27 +801,27 @@ connect_probe_continuation (void *cls, */ static void try_connect_using_address (void *cls, const struct sockaddr *addr, - socklen_t addrlen) + socklen_t addrlen) { struct GNUNET_CONNECTION_Handle *h = cls; struct AddressProbe *ap; struct GNUNET_TIME_Relative delay; if (addr == NULL) - { - h->dns_active = NULL; - if ((NULL == h->ap_head) && (NULL == h->sock)) - connect_fail_continuation (h); - return; - } + { + h->dns_active = NULL; + if ((NULL == h->ap_head) && (NULL == h->sock)) + connect_fail_continuation (h); + return; + } if (h->sock != NULL) - return; /* already connected */ + return; /* already connected */ GNUNET_assert (h->addr == NULL); /* try to connect */ #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_DEBUG, - "Trying to connect using address `%s:%u/%s:%u'\n", h->hostname, - h->port, GNUNET_a2s (addr, addrlen), h->port); + "Trying to connect using address `%s:%u/%s:%u'\n", h->hostname, h->port, + GNUNET_a2s (addr, addrlen), h->port); #endif ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen); ap->addr = (const struct sockaddr *) &ap[1]; @@ -835,25 +830,24 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, ap->h = h; switch (ap->addr->sa_family) - { - case AF_INET: - ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port); - break; - case AF_INET6: - ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port); - break; - default: - GNUNET_break (0); - GNUNET_free (ap); - return; /* not supported by us */ - } - ap->sock = - GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); + { + case AF_INET: + ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port); + break; + case AF_INET6: + ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port); + break; + default: + GNUNET_break (0); + GNUNET_free (ap); + return; /* not supported by us */ + } + ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); if (ap->sock == NULL) - { - GNUNET_free (ap); - return; /* not supported by OS */ - } + { + GNUNET_free (ap); + return; /* not supported by OS */ + } #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"), GNUNET_a2s (ap->addr, ap->addrlen), h); @@ -861,33 +855,32 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && (errno != EINPROGRESS)) - { - /* maybe refused / unsupported address, try next */ - LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); + { + /* maybe refused / unsupported address, try next */ + LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); #if 0 - LOG (GNUNET_ERROR_TYPE_INFO, - _("Failed to connect to `%s' (%p)\n"), - GNUNET_a2s (ap->addr, ap->addrlen), h); + LOG (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to `%s' (%p)\n"), + GNUNET_a2s (ap->addr, ap->addrlen), h); #endif - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); - GNUNET_free (ap); - return; - } + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); + GNUNET_free (ap); + return; + } GNUNET_CONTAINER_DLL_insert (h->ap_head, h->ap_tail, ap); delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; if (h->nth.notify_ready != NULL) delay = - GNUNET_TIME_relative_min (delay, - GNUNET_TIME_absolute_get_remaining (h-> - nth.transmit_timeout)); + GNUNET_TIME_relative_min (delay, + GNUNET_TIME_absolute_get_remaining (h-> + nth.transmit_timeout)); if (h->receiver != NULL) delay = - GNUNET_TIME_relative_min (delay, - GNUNET_TIME_absolute_get_remaining - (h->receive_timeout)); + GNUNET_TIME_relative_min (delay, + GNUNET_TIME_absolute_get_remaining + (h->receive_timeout)); ap->task = - GNUNET_SCHEDULER_add_write_net (delay, ap->sock, - &connect_probe_continuation, ap); + GNUNET_SCHEDULER_add_write_net (delay, ap->sock, + &connect_probe_continuation, ap); } @@ -902,13 +895,13 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, * @return the socket handle */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_from_connect (const struct - GNUNET_CONFIGURATION_Handle *cfg, - const char *hostname, uint16_t port) +GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *hostname, + uint16_t port) { struct GNUNET_CONNECTION_Handle *ret; - GNUNET_assert (0 < strlen (hostname)); /* sanity check */ + GNUNET_assert (0 < strlen (hostname)); /* sanity check */ ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); ret->cfg = cfg; ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; @@ -916,9 +909,9 @@ GNUNET_CONNECTION_create_from_connect (const struct ret->port = port; ret->hostname = GNUNET_strdup (hostname); ret->dns_active = - GNUNET_RESOLVER_ip_get (ret->hostname, AF_UNSPEC, - GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, - &try_connect_using_address, ret); + GNUNET_RESOLVER_ip_get (ret->hostname, AF_UNSPEC, + GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, + &try_connect_using_address, ret); return ret; } @@ -934,15 +927,15 @@ GNUNET_CONNECTION_create_from_connect (const struct */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct - GNUNET_CONFIGURATION_Handle - *cfg, const char *unixpath) + GNUNET_CONFIGURATION_Handle + *cfg, const char *unixpath) { #ifdef AF_UNIX struct GNUNET_CONNECTION_Handle *ret; struct sockaddr_un *un; size_t slen; - GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ + GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ un = GNUNET_malloc (sizeof (struct sockaddr_un)); un->sun_family = AF_UNIX; slen = strlen (unixpath); @@ -967,20 +960,20 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct ret->addrlen = slen; ret->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); if (NULL == ret->sock) - { - GNUNET_free (ret->addr); - GNUNET_free (ret->write_buffer); - GNUNET_free (ret); - return NULL; - } + { + GNUNET_free (ret->addr); + GNUNET_free (ret->write_buffer); + GNUNET_free (ret); + return NULL; + } if (GNUNET_OK != GNUNET_NETWORK_socket_connect (ret->sock, ret->addr, ret->addrlen)) - { - /* Just return; we expect everything to work eventually so don't fail HARD */ - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock)); - ret->sock = NULL; - return ret; - } + { + /* Just return; we expect everything to work eventually so don't fail HARD */ + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock)); + ret->sock = NULL; + return ret; + } connect_success_continuation (ret); return ret; #else @@ -1001,8 +994,8 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_sockaddr (int af_family, - const struct sockaddr *serv_addr, - socklen_t addrlen) + const struct sockaddr *serv_addr, + socklen_t addrlen) { struct GNUNET_NETWORK_Handle *s; struct GNUNET_CONNECTION_Handle *ret; @@ -1010,22 +1003,20 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); if (s == NULL) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - "socket"); - return NULL; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket"); + return NULL; + } if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && (errno != EINPROGRESS)) - { - /* maybe refused / unsupported address, try next */ - LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); - LOG (GNUNET_ERROR_TYPE_INFO, - _("Attempt to connect to `%s' failed\n"), GNUNET_a2s (serv_addr, - addrlen)); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); - return NULL; - } + { + /* maybe refused / unsupported address, try next */ + LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); + LOG (GNUNET_ERROR_TYPE_INFO, _("Attempt to connect to `%s' failed\n"), + GNUNET_a2s (serv_addr, addrlen)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); + return NULL; + } ret = GNUNET_CONNECTION_create_from_existing (s); ret->addr = GNUNET_malloc (addrlen); memcpy (ret->addr, serv_addr, addrlen); @@ -1050,7 +1041,7 @@ int GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) { if ((sock->ap_head != NULL) || (sock->dns_active != NULL)) - return GNUNET_YES; /* still trying to connect */ + return GNUNET_YES; /* still trying to connect */ return (sock->sock == NULL) ? GNUNET_NO : GNUNET_YES; } @@ -1070,23 +1061,23 @@ GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) */ void GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock, - int finish_pending_write) + int finish_pending_write) { if (GNUNET_NO == finish_pending_write) + { + if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) { - if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (sock->write_task); - sock->write_task = GNUNET_SCHEDULER_NO_TASK; - sock->write_buffer_off = 0; - } - sock->nth.notify_ready = NULL; + GNUNET_SCHEDULER_cancel (sock->write_task); + sock->write_task = GNUNET_SCHEDULER_NO_TASK; + sock->write_buffer_off = 0; } + sock->nth.notify_ready = NULL; + } if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL)) - { - GNUNET_RESOLVER_request_cancel (sock->dns_active); - sock->dns_active = NULL; - } + { + GNUNET_RESOLVER_request_cancel (sock->dns_active); + sock->dns_active = NULL; + } GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); sock->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, sock); @@ -1102,8 +1093,8 @@ signal_timeout (struct GNUNET_CONNECTION_Handle *sh) GNUNET_CONNECTION_Receiver receiver; #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Network signals time out to receiver (%p)!\n", sh); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Network signals time out to receiver (%p)!\n", + sh); #endif GNUNET_assert (NULL != (receiver = sh->receiver)); sh->receiver = NULL; @@ -1141,62 +1132,61 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sh->read_task = GNUNET_SCHEDULER_NO_TASK; if ((GNUNET_YES == sh->ignore_shutdown) && (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) - { - /* ignore shutdown request, go again immediately */ + { + /* ignore shutdown request, go again immediately */ #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Ignoring shutdown signal per configuration\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Ignoring shutdown signal per configuration\n"); #endif - sh->read_task = - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining - (sh->receive_timeout), sh->sock, - &receive_ready, sh); - return; - } + sh->read_task = + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining + (sh->receive_timeout), sh->sock, + &receive_ready, sh); + return; + } now = GNUNET_TIME_absolute_get (); if ((now.abs_value > sh->receive_timeout.abs_value) || (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) || (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) - { + { #if DEBUG_CONNECTION - if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive from `%s' encounters error: time out by %llums... (%p)\n", - GNUNET_a2s (sh->addr, sh->addrlen), - GNUNET_TIME_absolute_get_duration (sh->receive_timeout). - rel_value, sh); + if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive from `%s' encounters error: time out by %llums... (%p)\n", + GNUNET_a2s (sh->addr, sh->addrlen), + GNUNET_TIME_absolute_get_duration (sh->receive_timeout).rel_value, + sh); #endif - signal_timeout (sh); - return; - } + signal_timeout (sh); + return; + } if (sh->sock == NULL) - { - /* connect failed for good */ + { + /* connect failed for good */ #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error, socket closed... (%p)\n", sh); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive encounters error, socket closed... (%p)\n", sh); #endif - signal_error (sh, ECONNREFUSED); - return; - } + signal_error (sh, ECONNREFUSED); + return; + } GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, sh->sock)); RETRY: ret = GNUNET_NETWORK_socket_recv (sh->sock, buffer, sh->max); if (ret == -1) - { - if (errno == EINTR) - goto RETRY; + { + if (errno == EINTR) + goto RETRY; #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, "Error receiving: %s\n", - STRERROR (errno)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Error receiving: %s\n", STRERROR (errno)); #endif - signal_error (sh, errno); - return; - } + signal_error (sh, errno); + return; + } #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_DEBUG, - "receive_ready read %u/%u bytes from `%s' (%p)!\n", - (unsigned int) ret, sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh); + "receive_ready read %u/%u bytes from `%s' (%p)!\n", (unsigned int) ret, + sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh); #endif GNUNET_assert (NULL != (receiver = sh->receiver)); sh->receiver = NULL; @@ -1222,32 +1212,32 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sh->read_task = GNUNET_SCHEDULER_NO_TASK; if (sh->sock == NULL) - { - /* not connected and no longer trying */ + { + /* not connected and no longer trying */ #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error, socket closed (%p)...\n", sh); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive encounters error, socket closed (%p)...\n", sh); #endif - signal_error (sh, ECONNREFUSED); - return; - } + signal_error (sh, ECONNREFUSED); + return; + } now = GNUNET_TIME_absolute_get (); if ((now.abs_value > sh->receive_timeout.abs_value) || (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error: time out (%p)...\n", sh); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive encounters error: time out (%p)...\n", sh); #endif - signal_timeout (sh); - return; - } + signal_timeout (sh); + return; + } GNUNET_assert (sh->sock != NULL); /* connect succeeded, wait for data! */ sh->read_task = - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining - (sh->receive_timeout), sh->sock, - &receive_ready, sh); + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining + (sh->receive_timeout), sh->sock, + &receive_ready, sh); } @@ -1266,31 +1256,31 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ void GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max, - struct GNUNET_TIME_Relative timeout, - GNUNET_CONNECTION_Receiver receiver, - void *receiver_cls) + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_Receiver receiver, + void *receiver_cls) { struct GNUNET_SCHEDULER_TaskContext tc; GNUNET_assert ((sock->read_task == GNUNET_SCHEDULER_NO_TASK) && - (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) && - (sock->receiver == NULL)); + (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) && + (sock->receiver == NULL)); sock->receiver = receiver; sock->receiver_cls = receiver_cls; sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); sock->max = max; if (sock->sock != NULL) - { - memset (&tc, 0, sizeof (tc)); - tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE; - receive_again (sock, &tc); - return; - } + { + memset (&tc, 0, sizeof (tc)); + tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE; + receive_again (sock, &tc); + return; + } if ((sock->dns_active == NULL) && (sock->ap_head == NULL)) - { - receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); - return; - } + { + receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); + return; + } sock->ccs += COCO_RECEIVE_AGAIN; } @@ -1303,7 +1293,7 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max, */ void GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock, - int do_ignore) + int do_ignore) { sock->ignore_shutdown = do_ignore; } @@ -1321,15 +1311,15 @@ void * GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock) { if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task)); - sock->read_task = GNUNET_SCHEDULER_NO_TASK; - } + { + GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task)); + sock->read_task = GNUNET_SCHEDULER_NO_TASK; + } else - { - GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN)); - sock->ccs -= COCO_RECEIVE_AGAIN; - } + { + GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN)); + sock->ccs -= COCO_RECEIVE_AGAIN; + } sock->receiver = NULL; return sock->receiver_cls; } @@ -1360,18 +1350,18 @@ process_notify (struct GNUNET_CONNECTION_Handle *sock) return GNUNET_NO; sock->nth.notify_ready = NULL; if (sock->write_buffer_size - sock->write_buffer_off < size) - { - /* need to compact */ - memmove (sock->write_buffer, - &sock->write_buffer[sock->write_buffer_pos], used); - sock->write_buffer_off -= sock->write_buffer_pos; - sock->write_buffer_pos = 0; - } + { + /* need to compact */ + memmove (sock->write_buffer, &sock->write_buffer[sock->write_buffer_pos], + used); + sock->write_buffer_off -= sock->write_buffer_pos; + sock->write_buffer_pos = 0; + } avail = sock->write_buffer_size - sock->write_buffer_off; GNUNET_assert (avail >= size); size = - notify (sock->nth.notify_ready_cls, avail, - &sock->write_buffer[sock->write_buffer_off]); + notify (sock->nth.notify_ready_cls, avail, + &sock->write_buffer[sock->write_buffer_off]); GNUNET_assert (size <= avail); sock->write_buffer_off += size; return GNUNET_YES; @@ -1401,12 +1391,11 @@ transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", - sock->hostname, sock->port, GNUNET_a2s (sock->addr, - sock->addrlen), sock); + "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", sock->hostname, + sock->port, GNUNET_a2s (sock->addr, sock->addrlen), sock); #endif GNUNET_assert (0 != (sock->ccs & COCO_TRANSMIT_READY)); - sock->ccs -= COCO_TRANSMIT_READY; /* remove request */ + sock->ccs -= COCO_TRANSMIT_READY; /* remove request */ notify = sock->nth.notify_ready; sock->nth.notify_ready = NULL; notify (sock->nth.notify_ready_cls, 0, NULL); @@ -1451,20 +1440,20 @@ transmit_error (struct GNUNET_CONNECTION_Handle *sock) GNUNET_CONNECTION_TransmitReadyNotify notify; if (NULL != sock->sock) - { - GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); - sock->sock = NULL; - } + { + GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); + sock->sock = NULL; + } if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (sock->read_task); - sock->read_task = GNUNET_SCHEDULER_NO_TASK; - signal_timeout (sock); - return; - } + { + GNUNET_SCHEDULER_cancel (sock->read_task); + sock->read_task = GNUNET_SCHEDULER_NO_TASK; + signal_timeout (sock); + return; + } if (sock->nth.notify_ready == NULL) - return; /* nobody to tell about it */ + return; /* nobody to tell about it */ notify = sock->nth.notify_ready; sock->nth.notify_ready = NULL; notify (sock->nth.notify_ready_cls, 0, NULL); @@ -1494,109 +1483,107 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sock->write_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - { - if ( (sock->ignore_shutdown == GNUNET_YES) && - (NULL != sock->sock) ) - goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */ + { + if ((sock->ignore_shutdown == GNUNET_YES) && (NULL != sock->sock)) + goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */ #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmit to `%s' fails, shutdown happened (%p).\n", - GNUNET_a2s (sock->addr, sock->addrlen), sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmit to `%s' fails, shutdown happened (%p).\n", + GNUNET_a2s (sock->addr, sock->addrlen), sock); #endif - notify = sock->nth.notify_ready; - if (NULL != notify) - { - sock->nth.notify_ready = NULL; - notify (sock->nth.notify_ready_cls, 0, NULL); - } - return; - } - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) + notify = sock->nth.notify_ready; + if (NULL != notify) { -#if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmit to `%s' fails, time out reached (%p).\n", - GNUNET_a2s (sock->addr, sock->addrlen), sock); -#endif - notify = sock->nth.notify_ready; - GNUNET_assert (NULL != notify); sock->nth.notify_ready = NULL; notify (sock->nth.notify_ready_cls, 0, NULL); - return; } + return; + } + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) + { +#if DEBUG_CONNECTION + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmit to `%s' fails, time out reached (%p).\n", + GNUNET_a2s (sock->addr, sock->addrlen), sock); +#endif + notify = sock->nth.notify_ready; + GNUNET_assert (NULL != notify); + sock->nth.notify_ready = NULL; + notify (sock->nth.notify_ready_cls, 0, NULL); + return; + } GNUNET_assert (NULL != sock->sock); if (tc->write_ready == NULL) - { - /* special circumstances (in particular, - * PREREQ_DONE after connect): not yet ready to write, - * but no "fatal" error either. Hence retry. */ - goto SCHEDULE_WRITE; - } + { + /* special circumstances (in particular, + * PREREQ_DONE after connect): not yet ready to write, + * but no "fatal" error either. Hence retry. */ + goto SCHEDULE_WRITE; + } if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, sock->sock)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_INFO, - _ - ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), - sock); + LOG (GNUNET_ERROR_TYPE_INFO, + _ + ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), + sock); #endif - transmit_error (sock); - return; /* connect failed for good, we're finished */ - } + transmit_error (sock); + return; /* connect failed for good, we're finished */ + } GNUNET_assert (sock->write_buffer_off >= sock->write_buffer_pos); if ((sock->nth.notify_ready != NULL) && (sock->write_buffer_size < sock->nth.notify_size)) - { - sock->write_buffer = - GNUNET_realloc (sock->write_buffer, sock->nth.notify_size); - sock->write_buffer_size = sock->nth.notify_size; - } + { + sock->write_buffer = + GNUNET_realloc (sock->write_buffer, sock->nth.notify_size); + sock->write_buffer_size = sock->nth.notify_size; + } process_notify (sock); have = sock->write_buffer_off - sock->write_buffer_pos; if (have == 0) - { - /* no data ready for writing, terminate write loop */ - return; - } + { + /* no data ready for writing, terminate write loop */ + return; + } GNUNET_assert (have <= sock->write_buffer_size); GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size); GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size); RETRY: ret = - GNUNET_NETWORK_socket_send (sock->sock, - &sock->write_buffer[sock->write_buffer_pos], - have); + GNUNET_NETWORK_socket_send (sock->sock, + &sock->write_buffer[sock->write_buffer_pos], + have); if (ret == -1) - { - if (errno == EINTR) - goto RETRY; + { + if (errno == EINTR) + goto RETRY; #if 0 - int en = errno; + int en = errno; - LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to send to `%s': %s\n"), - GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en)); + LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to send to `%s': %s\n"), + GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en)); #endif #if DEBUG_CONNECTION - LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "send"); + LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "send"); #endif - transmit_error (sock); - return; - } + transmit_error (sock); + return; + } #if DEBUG_CONNECTION LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n", - (unsigned int) ret, have, GNUNET_a2s (sock->addr, sock->addrlen), - sock); + (unsigned int) ret, have, GNUNET_a2s (sock->addr, sock->addrlen), sock); #endif sock->write_buffer_pos += ret; if (sock->write_buffer_pos == sock->write_buffer_off) - { - /* transmitted all pending data */ - sock->write_buffer_pos = 0; - sock->write_buffer_off = 0; - } + { + /* transmitted all pending data */ + sock->write_buffer_pos = 0; + sock->write_buffer_off = 0; + } if ((sock->write_buffer_off == 0) && (NULL == sock->nth.notify_ready)) - return; /* all data sent! */ + return; /* all data sent! */ /* not done writing, schedule more */ SCHEDULE_WRITE: #if DEBUG_CONNECTION @@ -1607,11 +1594,11 @@ SCHEDULE_WRITE: GNUNET_assert ((sock->nth.notify_ready != NULL) || (have > 0)); if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) sock->write_task = - GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == - NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : - GNUNET_TIME_absolute_get_remaining - (sock->nth.transmit_timeout), - sock->sock, &transmit_ready, sock); + GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == + NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : + GNUNET_TIME_absolute_get_remaining + (sock->nth.transmit_timeout), + sock->sock, &transmit_ready, sock); } @@ -1630,17 +1617,17 @@ SCHEDULE_WRITE: * NULL if we are already going to notify someone else (busy) */ struct GNUNET_CONNECTION_TransmitHandle * -GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle - *sock, size_t size, - struct GNUNET_TIME_Relative timeout, - GNUNET_CONNECTION_TransmitReadyNotify - notify, void *notify_cls) +GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *sock, + size_t size, + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_TransmitReadyNotify + notify, void *notify_cls) { if (sock->nth.notify_ready != NULL) - { - GNUNET_assert (0); - return NULL; - } + { + GNUNET_assert (0); + return NULL; + } GNUNET_assert (notify != NULL); GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size); @@ -1654,36 +1641,34 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task); if ((sock->sock == NULL) && (sock->ap_head == NULL) && (sock->dns_active == NULL)) - { - if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel (sock->write_task); - sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock); - return &sock->nth; - } + { + if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (sock->write_task); + sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock); + return &sock->nth; + } if (GNUNET_SCHEDULER_NO_TASK != sock->write_task) return &sock->nth; if (sock->sock != NULL) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n", - sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n", sock); #endif - sock->write_task = - GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining - (sock->nth.transmit_timeout), - sock->sock, &transmit_ready, sock); - } + sock->write_task = + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining + (sock->nth.transmit_timeout), + sock->sock, &transmit_ready, sock); + } else - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", - sock); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", sock); #endif - sock->ccs |= COCO_TRANSMIT_READY; - sock->nth.timeout_task = - GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, sock); - } + sock->ccs |= COCO_TRANSMIT_READY; + sock->nth.timeout_task = + GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, sock); + } return &sock->nth; } @@ -1695,28 +1680,28 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle */ void GNUNET_CONNECTION_notify_transmit_ready_cancel (struct - GNUNET_CONNECTION_TransmitHandle - *th) + GNUNET_CONNECTION_TransmitHandle + *th) { GNUNET_assert (th->notify_ready != NULL); if (0 != (th->sh->ccs & COCO_TRANSMIT_READY)) - { + { #if DEBUG_CONNECTION - LOG (GNUNET_ERROR_TYPE_DEBUG, - "notify_transmit_ready_cancel cancels timeout_task (%p)\n", th); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "notify_transmit_ready_cancel cancels timeout_task (%p)\n", th); #endif - GNUNET_SCHEDULER_cancel (th->timeout_task); - th->timeout_task = GNUNET_SCHEDULER_NO_TASK; - th->sh->ccs -= COCO_TRANSMIT_READY; - } + GNUNET_SCHEDULER_cancel (th->timeout_task); + th->timeout_task = GNUNET_SCHEDULER_NO_TASK; + th->sh->ccs -= COCO_TRANSMIT_READY; + } else + { + if (th->sh->write_task != GNUNET_SCHEDULER_NO_TASK) { - if (th->sh->write_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (th->sh->write_task); - th->sh->write_task = GNUNET_SCHEDULER_NO_TASK; - } + GNUNET_SCHEDULER_cancel (th->sh->write_task); + th->sh->write_task = GNUNET_SCHEDULER_NO_TASK; } + } th->notify_ready = NULL; } |