From 652e89b59ed2207c2c12172fdabcd6e659995c81 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 1 Nov 2009 20:47:52 +0000 Subject: fixing bio testcase and a bug in bio.c, also indenting --- src/util/bio.c | 197 ++- src/util/client.c | 209 ++-- src/util/common_allocation.c | 3 +- src/util/common_logging.c | 35 +- src/util/configuration.c | 73 +- src/util/connection.c | 576 +++++---- src/util/container_bloomfilter.c | 68 +- src/util/container_heap.c | 11 +- src/util/container_meta_data.c | 11 +- src/util/container_multihashmap.c | 18 +- src/util/container_slist.c | 24 +- src/util/crypto_aes.c | 14 +- src/util/crypto_hash.c | 66 +- src/util/crypto_ksk.c | 58 +- src/util/crypto_random.c | 15 +- src/util/crypto_rsa.c | 64 +- src/util/disk.c | 246 ++-- src/util/disk.h | 52 +- src/util/gnunet-service-resolver.c | 14 +- src/util/network.c | 1600 +++++++++++++------------ src/util/os_installation.c | 5 +- src/util/os_priority.c | 204 ++-- src/util/peer.c | 39 +- src/util/perf_crypto_hash.c | 3 +- src/util/program.c | 8 +- src/util/pseudonym.c | 29 +- src/util/resolver_api.c | 236 ++-- src/util/scheduler.c | 158 ++- src/util/server.c | 136 +-- src/util/service.c | 48 +- src/util/strings.c | 8 +- src/util/test_bio.c | 189 +-- src/util/test_client.c | 25 +- src/util/test_configuration.c | 2 +- src/util/test_connection.c | 47 +- src/util/test_connection_addressing.c | 57 +- src/util/test_connection_receive_cancel.c | 31 +- src/util/test_connection_timeout.c | 23 +- src/util/test_connection_timeout_no_connect.c | 9 +- src/util/test_connection_transmit_cancel.c | 8 +- src/util/test_container_bloomfilter.c | 3 +- src/util/test_container_slist.c | 15 +- src/util/test_crypto_aes.c | 4 +- src/util/test_crypto_ksk.c | 4 +- src/util/test_crypto_rsa.c | 11 +- src/util/test_disk.c | 28 +- src/util/test_getopt.c | 6 +- src/util/test_os_load.c | 16 +- src/util/test_resolver_api.c | 9 +- src/util/test_scheduler.c | 33 +- src/util/test_server.c | 3 +- src/util/test_server_disconnect.c | 3 +- src/util/test_server_with_client.c | 3 +- src/util/test_service.c | 19 +- src/util/time.c | 34 +- src/util/winproc.c | 4 +- 56 files changed, 2387 insertions(+), 2427 deletions(-) (limited to 'src') diff --git a/src/util/bio.c b/src/util/bio.c index ea9415d63..860e9e63e 100644 --- a/src/util/bio.c +++ b/src/util/bio.c @@ -57,9 +57,9 @@ GNUNET_BIO_read_open (const char *fn) struct GNUNET_BIO_ReadHandle *h; fd = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); - h = GNUNET_malloc (sizeof(struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); - h->buffer = (char*) &h[1]; + GNUNET_DISK_PERM_NONE); + h = GNUNET_malloc (sizeof (struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); + h->buffer = (char *) &h[1]; h->size = BIO_BUFFER_SIZE; h->fd = fd; return h; @@ -74,8 +74,8 @@ GNUNET_BIO_read_open (const char *fn) * @param emsg set to the error message * @return GNUNET_OK on success, GNUNET_SYSERR otherwise */ -int GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, - char **emsg) +int +GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg) { *emsg = h->emsg; GNUNET_DISK_file_close (h->fd); @@ -93,10 +93,9 @@ int GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, * @param len the number of bytes to read * @return GNUNET_OK on success, GNUNET_SYSERR on failure */ -int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, - const char *what, - void *result, - size_t len) +int +GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, + const char *what, void *result, size_t len) { char *dst = result; size_t min; @@ -119,32 +118,28 @@ int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, pos += min; } if (pos == len) - return GNUNET_OK; /* done! */ + return GNUNET_OK; /* done! */ GNUNET_assert (h->have == h->pos); /* fill buffer */ - ret = GNUNET_DISK_file_read (h->fd, - h->buffer, - h->size); + ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); if (ret == -1) { - GNUNET_asprintf (&h->emsg, - _("Error reading `%s': %s"), - what, - STRERROR (errno)); - return GNUNET_SYSERR; + GNUNET_asprintf (&h->emsg, + _("Error reading `%s': %s"), + what, STRERROR (errno)); + return GNUNET_SYSERR; } if (ret == 0) - { - GNUNET_asprintf (&h->emsg, - _("Error reading `%s': %s"), - what, - _("End of file")); - return GNUNET_SYSERR; - } + { + GNUNET_asprintf (&h->emsg, + _("Error reading `%s': %s"), + what, _("End of file")); + return GNUNET_SYSERR; + } h->pos = 0; h->have = ret; } - while (pos < len); /* should always be true */ + while (pos < len); /* should always be true */ return GNUNET_OK; } @@ -159,10 +154,9 @@ int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, * @param maxLen maximum allowed length for the string * @return GNUNET_OK on success, GNUNET_SYSERR on failure */ -int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, - const char *what, - char **result, - size_t maxLen) +int +GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, + const char *what, char **result, size_t maxLen) { char *buf; uint32_t big; @@ -177,14 +171,14 @@ int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, if (big > maxLen) { GNUNET_asprintf (&h->emsg, - _("String `%s' longer than allowed (%u > %u)"), - what, - big, - maxLen); + _("String `%s' longer than allowed (%u > %u)"), + what, big, maxLen); return GNUNET_SYSERR; } buf = GNUNET_malloc (big); buf[--big] = '\0'; + if (big == 0) + return GNUNET_OK; if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big)) { GNUNET_free (buf); @@ -203,30 +197,27 @@ int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, * @param result the buffer to store a pointer to the (allocated) metadata * @return GNUNET_OK on success, GNUNET_SYSERR on failure */ -int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, - const char *what, - struct GNUNET_CONTAINER_MetaData **result) +int +GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, + const char *what, + struct GNUNET_CONTAINER_MetaData **result) { uint32_t size; char *buf; struct GNUNET_CONTAINER_MetaData *meta; - if (GNUNET_BIO_read_int32__ (h, - what, - (int32_t*) &size) != GNUNET_OK) + if (GNUNET_BIO_read_int32__ (h, what, (int32_t *) & size) != GNUNET_OK) return GNUNET_SYSERR; if (size > MAX_META_DATA) { GNUNET_asprintf (&h->emsg, - _("Serialized metadata `%s' larger than allowed (%u > %u)"), - what, - size, - MAX_META_DATA); + _ + ("Serialized metadata `%s' larger than allowed (%u > %u)"), + what, size, MAX_META_DATA); return GNUNET_SYSERR; } buf = GNUNET_malloc (size); - if (GNUNET_OK != - GNUNET_BIO_read (h, what, buf, size)) + if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size)) { GNUNET_free (buf); return GNUNET_SYSERR; @@ -236,8 +227,7 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, { GNUNET_free (buf); GNUNET_asprintf (&h->emsg, - _("Metadata `%s' failed to deserialize"), - what); + _("Metadata `%s' failed to deserialize"), what); return GNUNET_SYSERR; } GNUNET_free (buf); @@ -253,18 +243,14 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, * @param what describes what is being read (for error message creation) * @param i address of 32-bit integer to read * @return GNUNET_OK on success, GNUNET_SYSERR on error - */ -int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, - const char *what, - int32_t *i) + */ +int +GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, + const char *what, int32_t * i) { int32_t big; - if (GNUNET_OK != - GNUNET_BIO_read (h, - what, - &big, - sizeof (int32_t))) + if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof (int32_t))) return GNUNET_SYSERR; *i = ntohl (big); return GNUNET_OK; @@ -278,18 +264,14 @@ int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, * @param what describes what is being read (for error message creation) * @param i address of 64-bit integer to read * @return GNUNET_OK on success, GNUNET_SYSERR on error - */ -int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, - const char *what, - int64_t *i) + */ +int +GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, + const char *what, int64_t * i) { int64_t big; - if (GNUNET_OK != - GNUNET_BIO_read (h, - what, - &big, - sizeof (int64_t))) + if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof (int64_t))) return GNUNET_SYSERR; *i = GNUNET_ntohll (big); return GNUNET_OK; @@ -314,16 +296,21 @@ struct GNUNET_BIO_WriteHandle * @param fn file name to be opened * @return IO handle on success, NULL on error */ -struct GNUNET_BIO_WriteHandle *GNUNET_BIO_write_open (const char *fn) +struct GNUNET_BIO_WriteHandle * +GNUNET_BIO_write_open (const char *fn) { struct GNUNET_DISK_FileHandle *fd; struct GNUNET_BIO_WriteHandle *h; - fd = GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); - h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); - h->buffer = (char*) &h[1]; + fd = GNUNET_DISK_file_open (fn, + GNUNET_DISK_OPEN_WRITE | + GNUNET_DISK_OPEN_TRUNCATE | + GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); + h = + GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); + h->buffer = (char *) &h[1]; h->size = BIO_BUFFER_SIZE; h->fd = fd; @@ -337,7 +324,8 @@ struct GNUNET_BIO_WriteHandle *GNUNET_BIO_write_open (const char *fn) * @param h file handle * @return GNUNET_OK on success, GNUNET_SYSERR otherwise */ -int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) +int +GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) { ssize_t wrt; int ret; @@ -350,9 +338,9 @@ int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) { wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); if (wrt == h->have) - ret = GNUNET_OK; + ret = GNUNET_OK; else - ret = GNUNET_SYSERR; + ret = GNUNET_SYSERR; GNUNET_DISK_file_close (h->fd); } GNUNET_free (h); @@ -368,9 +356,9 @@ int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) * @param n number of bytes to write * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, - const void *buffer, - size_t n) +int +GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, + const void *buffer, size_t n) { const char *src = buffer; size_t min; @@ -390,18 +378,18 @@ int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, pos += min; h->have += min; if (pos == n) - return GNUNET_OK; /* done */ + return GNUNET_OK; /* done */ GNUNET_assert (h->have == h->size); ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size); if (ret != h->size) { GNUNET_DISK_file_close (h->fd); h->fd = NULL; - return GNUNET_SYSERR; /* error */ + return GNUNET_SYSERR; /* error */ } h->have = 0; } - while (pos < n); /* should always be true */ + while (pos < n); /* should always be true */ return GNUNET_OK; } @@ -413,14 +401,13 @@ int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, * @param s string to write (can be NULL) * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, - const char *s) +int +GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s) { uint32_t slen; - slen = (uint32_t) ((s == NULL) ? 0 : strlen(s) + 1); - if (GNUNET_OK != - GNUNET_BIO_write_int32 (h, slen)) + slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1); + if (GNUNET_OK != GNUNET_BIO_write_int32 (h, slen)) return GNUNET_SYSERR; if (0 != slen) return GNUNET_BIO_write (h, s, slen - 1); @@ -435,28 +422,28 @@ int GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, * @param m metadata to write * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, - const struct GNUNET_CONTAINER_MetaData *m) +int +GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, + const struct GNUNET_CONTAINER_MetaData *m) { unsigned int size; char *buf; size = GNUNET_CONTAINER_meta_data_get_serialized_size (m, - GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL - | - GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS); + GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL + | + GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS); if (size > MAX_META_DATA) size = MAX_META_DATA; buf = GNUNET_malloc (size); GNUNET_CONTAINER_meta_data_serialize (m, - buf, - size, - GNUNET_CONTAINER_META_DATA_SERIALIZE_PART | - GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS); - if ( (GNUNET_OK != - GNUNET_BIO_write_int32 (h, size)) || - (GNUNET_OK != - GNUNET_BIO_write (h, buf, size)) ) + buf, + size, + GNUNET_CONTAINER_META_DATA_SERIALIZE_PART + | + GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS); + if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, size)) + || (GNUNET_OK != GNUNET_BIO_write (h, buf, size))) { GNUNET_free (buf); return GNUNET_SYSERR; @@ -472,9 +459,9 @@ int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, * @param h hande to open file * @param i address of 32-bit integer to write * @return GNUNET_OK on success, GNUNET_SYSERR on error - */ -int GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, - int32_t i) + */ +int +GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i) { int32_t big; big = htonl (i); @@ -488,9 +475,9 @@ int GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, * @param h hande to open file * @param i address of 64-bit integer to write * @return GNUNET_OK on success, GNUNET_SYSERR on error - */ -int GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, - int64_t i) + */ +int +GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i) { int64_t big; big = GNUNET_htonll (i); diff --git a/src/util/client.c b/src/util/client.c index 8915c2f65..60aa6f101 100644 --- a/src/util/client.c +++ b/src/util/client.c @@ -48,7 +48,7 @@ /** * Handle for a transmission request. */ -struct GNUNET_CLIENT_TransmitHandle +struct GNUNET_CLIENT_TransmitHandle { /** * Connection state. @@ -128,7 +128,7 @@ struct GNUNET_CLIENT_Connection * Our configuration. */ struct GNUNET_CONFIGURATION_Handle *cfg; - + /** * Name of the service we interact with. */ @@ -198,8 +198,8 @@ struct GNUNET_CLIENT_Connection static struct GNUNET_CONNECTION_Handle * do_connect (struct GNUNET_SCHEDULER_Handle *sched, - const char *service_name, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const char *service_name, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_CONNECTION_Handle *sock; char *hostname; @@ -217,7 +217,8 @@ do_connect (struct GNUNET_SCHEDULER_Handle *sched, "HOSTNAME", &hostname))) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Could not determine valid hostname and port for service `%s' from configuration.\n"), + _ + ("Could not determine valid hostname and port for service `%s' from configuration.\n"), service_name); return NULL; } @@ -226,14 +227,14 @@ do_connect (struct GNUNET_SCHEDULER_Handle *sched, GNUNET_free (hostname); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Need a non-empty hostname for service `%s'.\n"), - service_name); + service_name); return NULL; } sock = GNUNET_CONNECTION_create_from_connect (sched, - cfg, - hostname, - port, - GNUNET_SERVER_MAX_MESSAGE_SIZE); + cfg, + hostname, + port, + GNUNET_SERVER_MAX_MESSAGE_SIZE); GNUNET_free (hostname); return sock; } @@ -277,7 +278,7 @@ finish_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_CLIENT_Connection *sock = cls; if (sock->th != NULL) - GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th); + GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th); GNUNET_array_grow (sock->received_buf, sock->received_size, 0); GNUNET_free (sock->service_name); GNUNET_CONFIGURATION_destroy (sock->cfg); @@ -307,10 +308,10 @@ GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock) sock->in_receive = GNUNET_SYSERR; else GNUNET_SCHEDULER_add_after (sock->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - &finish_cleanup, sock); + GNUNET_YES, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + &finish_cleanup, sock); } @@ -322,8 +323,8 @@ check_complete (struct GNUNET_CLIENT_Connection *conn) { if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) && (conn->received_pos >= - ntohs (((const struct GNUNET_MessageHeader *) conn-> - received_buf)->size))) + ntohs (((const struct GNUNET_MessageHeader *) conn->received_buf)-> + size))) conn->msg_complete = GNUNET_YES; } @@ -352,11 +353,10 @@ receive_helper (void *cls, GNUNET_assert (conn->msg_complete == GNUNET_NO); if (GNUNET_SYSERR == conn->in_receive) GNUNET_SCHEDULER_add_after (conn->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - &finish_cleanup, - conn); + GNUNET_YES, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + &finish_cleanup, conn); conn->in_receive = GNUNET_NO; if ((available == 0) || (conn->sock == NULL) || (errCode != 0)) { @@ -403,28 +403,28 @@ receive_task (void *scls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CLIENT_Connection *sock = scls; GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler; - const struct GNUNET_MessageHeader *cmsg = (const struct GNUNET_MessageHeader *) sock->received_buf; + const struct GNUNET_MessageHeader *cmsg = + (const struct GNUNET_MessageHeader *) sock->received_buf; void *cls = sock->receiver_handler_cls; uint16_t msize = ntohs (cmsg->size); char mbuf[msize]; - struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader*) mbuf; + struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf; if (GNUNET_SYSERR == sock->in_receive) GNUNET_SCHEDULER_add_after (sock->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - &finish_cleanup, - sock); + GNUNET_YES, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + &finish_cleanup, sock); sock->in_receive = GNUNET_NO; GNUNET_assert (GNUNET_YES == sock->msg_complete); GNUNET_assert (sock->received_pos >= msize); memcpy (msg, cmsg, msize); memmove (sock->received_buf, - &sock->received_buf[msize], sock->received_pos - msize); + &sock->received_buf[msize], sock->received_pos - msize); sock->received_pos -= msize; sock->msg_complete = GNUNET_NO; - sock->receiver_handler = NULL; + sock->receiver_handler = NULL; check_complete (sock); if (handler != NULL) handler (cls, msg); @@ -457,15 +457,14 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, sock->in_receive = GNUNET_YES; if (GNUNET_YES == sock->msg_complete) GNUNET_SCHEDULER_add_after (sock->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - &receive_task, sock); + GNUNET_YES, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + &receive_task, sock); else GNUNET_CONNECTION_receive (sock->sock, - GNUNET_SERVER_MAX_MESSAGE_SIZE, - timeout, - &receive_helper, sock); + GNUNET_SERVER_MAX_MESSAGE_SIZE, + timeout, &receive_helper, sock); } @@ -488,8 +487,8 @@ write_shutdown (void *cls, size_t size, void *buf) if (size < sizeof (struct GNUNET_MessageHeader)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Failed to transmit shutdown request to client.\n")); - return 0; /* client disconnected */ + _("Failed to transmit shutdown request to client.\n")); + return 0; /* client disconnected */ } msg = (struct GNUNET_MessageHeader *) buf; msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN); @@ -508,9 +507,10 @@ void GNUNET_CLIENT_service_shutdown (struct GNUNET_CLIENT_Connection *sock) { GNUNET_CONNECTION_notify_transmit_ready (sock->sock, - sizeof (struct GNUNET_MessageHeader), - GNUNET_TIME_UNIT_FOREVER_REL, - &write_shutdown, sock); + sizeof (struct + GNUNET_MessageHeader), + GNUNET_TIME_UNIT_FOREVER_REL, + &write_shutdown, sock); } @@ -624,9 +624,9 @@ GNUNET_CLIENT_service_test (struct GNUNET_SCHEDULER_Handle *sched, conn->test_cb_cls = task_cls; if (NULL == GNUNET_CONNECTION_notify_transmit_ready (conn->sock, - sizeof (struct - GNUNET_MessageHeader), - timeout, &write_test, NULL)) + sizeof (struct + GNUNET_MessageHeader), + timeout, &write_test, NULL)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failure to transmit request to service `%s'\n"), @@ -649,10 +649,7 @@ GNUNET_CLIENT_service_test (struct GNUNET_SCHEDULER_Handle *sched, * @param buf where to write them * @return number of bytes written to buf */ -static size_t -client_notify (void *cls, - size_t size, - void *buf); +static size_t client_notify (void *cls, size_t size, void *buf); @@ -665,22 +662,22 @@ client_notify (void *cls, */ static void client_delayed_retry (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CLIENT_TransmitHandle *th = cls; th->task = GNUNET_SCHEDULER_NO_TASK; th->th = GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, - th->size, - GNUNET_TIME_absolute_get_remaining (th->timeout), - &client_notify, - th); + th->size, + GNUNET_TIME_absolute_get_remaining + (th->timeout), + &client_notify, th); if (th->th == NULL) { GNUNET_break (0); th->notify (th->notify_cls, 0, NULL); GNUNET_free (th); - return; + return; } } @@ -696,51 +693,42 @@ client_delayed_retry (void *cls, * @return number of bytes written to buf */ static size_t -client_notify (void *cls, - size_t size, - void *buf) +client_notify (void *cls, size_t size, void *buf) { struct GNUNET_CLIENT_TransmitHandle *th = cls; size_t ret; struct GNUNET_TIME_Relative delay; - + th->th = NULL; th->sock->th = NULL; if (buf == NULL) { delay = GNUNET_TIME_absolute_get_remaining (th->timeout); delay.value /= 2; - if ( (GNUNET_YES != th->auto_retry) || - (0 == --th->attempts_left) || - (delay.value < 1) ) - { - GNUNET_break (0 == th->notify (th->notify_cls, - 0, - NULL)); - GNUNET_free (th); - return 0; - } + if ((GNUNET_YES != th->auto_retry) || + (0 == --th->attempts_left) || (delay.value < 1)) + { + GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL)); + GNUNET_free (th); + return 0; + } /* auto-retry */ GNUNET_CONNECTION_destroy (th->sock->sock); - th->sock->sock = do_connect (th->sock->sched, - th->sock->service_name, - th->sock->cfg); + th->sock->sock = do_connect (th->sock->sched, + th->sock->service_name, th->sock->cfg); GNUNET_assert (NULL != th->sock->sock); delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS); th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - delay, - &client_delayed_retry, - th); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + delay, + &client_delayed_retry, th); th->sock->th = th; return 0; } GNUNET_assert (size >= th->size); - ret = th->notify (th->notify_cls, - size, - buf); + ret = th->notify (th->notify_cls, size, buf); GNUNET_free (th); return ret; } @@ -769,7 +757,7 @@ struct GNUNET_CLIENT_TransmitHandle * GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, size_t size, struct GNUNET_TIME_Relative timeout, - int auto_retry, + int auto_retry, GNUNET_CONNECTION_TransmitReadyNotify notify, void *notify_cls) { @@ -786,10 +774,9 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, th->notify_cls = notify_cls; th->attempts_left = MAX_ATTEMPTS; th->th = GNUNET_CONNECTION_notify_transmit_ready (sock->sock, - size, - timeout, - &client_notify, - th); + size, + timeout, + &client_notify, th); if (NULL == th->th) { GNUNET_break (0); @@ -807,13 +794,13 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, * @param th handle from the original request. */ void -GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle *th) +GNUNET_CLIENT_notify_transmit_ready_cancel (struct + GNUNET_CLIENT_TransmitHandle *th) { if (th->task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_break (NULL == th->th); - GNUNET_SCHEDULER_cancel (th->sock->sched, - th->task); + GNUNET_SCHEDULER_cancel (th->sock->sched, th->task); } else { @@ -871,14 +858,12 @@ struct TARCtx * @return number of bytes written to buf */ static size_t -transmit_for_response (void *cls, - size_t size, - void *buf) +transmit_for_response (void *cls, size_t size, void *buf) { struct TARCtx *tc = cls; uint16_t msize; - msize = ntohs(tc->hdr->size); + msize = ntohs (tc->hdr->size); if (NULL == buf) { tc->rn (tc->rn_cls, NULL); @@ -888,9 +873,9 @@ transmit_for_response (void *cls, GNUNET_assert (size >= msize); memcpy (buf, tc->hdr, msize); GNUNET_CLIENT_receive (tc->sock, - tc->rn, - tc->rn_cls, - GNUNET_TIME_absolute_get_remaining (tc->timeout)); + tc->rn, + tc->rn_cls, + GNUNET_TIME_absolute_get_remaining (tc->timeout)); GNUNET_free (tc); return msize; } @@ -918,32 +903,34 @@ transmit_for_response (void *cls, * is already pending */ int -GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *sock, - const struct GNUNET_MessageHeader *hdr, - struct GNUNET_TIME_Relative timeout, - int auto_retry, - GNUNET_CLIENT_MessageHandler rn, - void *rn_cls) +GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection + *sock, + const struct GNUNET_MessageHeader + *hdr, + struct GNUNET_TIME_Relative timeout, + int auto_retry, + GNUNET_CLIENT_MessageHandler rn, + void *rn_cls) { struct TARCtx *tc; uint16_t msize; if (NULL != sock->th) return GNUNET_SYSERR; - msize = ntohs(hdr->size); - tc = GNUNET_malloc(sizeof (struct TARCtx) + msize); + msize = ntohs (hdr->size); + tc = GNUNET_malloc (sizeof (struct TARCtx) + msize); tc->sock = sock; - tc->hdr = (const struct GNUNET_MessageHeader*) &tc[1]; + tc->hdr = (const struct GNUNET_MessageHeader *) &tc[1]; memcpy (&tc[1], hdr, msize); tc->timeout = GNUNET_TIME_relative_to_absolute (timeout); tc->rn = rn; tc->rn_cls = rn_cls; if (NULL == GNUNET_CLIENT_notify_transmit_ready (sock, - msize, - timeout, - auto_retry, - &transmit_for_response, - tc)) + msize, + timeout, + auto_retry, + &transmit_for_response, + tc)) { GNUNET_break (0); GNUNET_free (tc); diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 2f78c98f6..748ca620d 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c @@ -48,8 +48,7 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) { /* As a security precaution, we generally do not allow very large allocations using the default 'GNUNET_malloc' macro */ - GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, - linenumber); + GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); return GNUNET_xmalloc_unchecked_ (size, filename, linenumber); } diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 96cfcd85c..5af499341 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -442,7 +442,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind) * @return string form; will be overwritten by next call to GNUNET_h2s. */ const char * -GNUNET_h2s (const GNUNET_HashCode *hc) +GNUNET_h2s (const GNUNET_HashCode * hc) { static struct GNUNET_CRYPTO_HashAsciiEncoded ret; GNUNET_CRYPTO_hash_to_enc (hc, &ret); @@ -481,12 +481,12 @@ GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) * @return nicely formatted string for the address * will be overwritten by next call to GNUNET_a2s. */ -const char *GNUNET_a2s (const struct sockaddr *addr, - socklen_t addrlen) +const char * +GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen) { - static char buf[INET6_ADDRSTRLEN+8]; + static char buf[INET6_ADDRSTRLEN + 8]; static char b2[6]; - const struct sockaddr_in * v4; + const struct sockaddr_in *v4; const struct sockaddr_in6 *v6; if (addr == NULL) @@ -494,24 +494,24 @@ const char *GNUNET_a2s (const struct sockaddr *addr, switch (addr->sa_family) { case AF_INET: - v4 = (const struct sockaddr_in*)addr; - inet_ntop(AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); - if (0 == ntohs(v4->sin_port)) - return buf; + v4 = (const struct sockaddr_in *) addr; + inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); + if (0 == ntohs (v4->sin_port)) + return buf; strcat (buf, ":"); - sprintf (b2, "%u", ntohs(v4->sin_port)); + sprintf (b2, "%u", ntohs (v4->sin_port)); strcat (buf, b2); return buf; case AF_INET6: - v6 = (const struct sockaddr_in6*)addr; + v6 = (const struct sockaddr_in6 *) addr; buf[0] = '['; - inet_ntop(AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN); - if (0 == ntohs(v6->sin6_port)) - return &buf[1]; + inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN); + if (0 == ntohs (v6->sin6_port)) + return &buf[1]; strcat (buf, "]:"); - sprintf (b2, "%u", ntohs(v6->sin6_port)); + sprintf (b2, "%u", ntohs (v6->sin6_port)); strcat (buf, b2); - return buf; + return buf; default: return _("invalid address"); } @@ -521,8 +521,7 @@ const char *GNUNET_a2s (const struct sockaddr *addr, /** * Initializer */ -void __attribute__ ((constructor)) -GNUNET_util_cl_init() +void __attribute__ ((constructor)) GNUNET_util_cl_init () { GNUNET_stderr = stderr; } diff --git a/src/util/configuration.c b/src/util/configuration.c index 2541a79f4..c14645067 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -344,10 +344,10 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_assert (0 == fclose (fp)); if (error != 0) { - cfg->dirty = GNUNET_SYSERR; /* last write failed */ + cfg->dirty = GNUNET_SYSERR; /* last write failed */ return GNUNET_SYSERR; } - cfg->dirty = GNUNET_NO; /* last write succeeded */ + cfg->dirty = GNUNET_NO; /* last write succeeded */ return GNUNET_OK; } @@ -359,9 +359,10 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, * @param iter function to call on each option * @param iter_cls closure for iter */ -void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_CONFIGURATION_Iterator iter, - void *iter_cls) +void +GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_CONFIGURATION_Iterator iter, + void *iter_cls) { struct ConfigSection *spos; struct ConfigEntry *epos; @@ -371,10 +372,10 @@ void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg { epos = spos->entries; while (epos != NULL) - { - iter (iter_cls, spos->name, epos->key, epos->val); - epos = epos->next; - } + { + iter (iter_cls, spos->name, epos->key, epos->val); + epos = epos->next; + } spos = spos->next; } } @@ -391,9 +392,7 @@ void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg */ static void copy_entry (void *cls, - const char *section, - const char *option, - const char *value) + const char *section, const char *option, const char *value) { struct GNUNET_CONFIGURATION_Handle *dst = cls; GNUNET_CONFIGURATION_set_value_string (dst, section, option, value); @@ -425,7 +424,8 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) * @return matching entry, NULL if not found */ static struct ConfigSection * -findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section) +findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section) { struct ConfigSection *pos; @@ -531,8 +531,9 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, +GNUNET_CONFIGURATION_get_value_number (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, unsigned long long *number) { @@ -558,17 +559,14 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle */ int GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, - struct GNUNET_TIME_Relative *time) + *cfg, const char *section, + const char *option, + struct GNUNET_TIME_Relative *time) { unsigned long long num; int ret; - ret = GNUNET_CONFIGURATION_get_value_number (cfg, - section, - option, - &num); + ret = GNUNET_CONFIGURATION_get_value_number (cfg, section, option, &num); if (ret == GNUNET_OK) time->value = (uint64_t) num; return ret; @@ -586,8 +584,9 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, +GNUNET_CONFIGURATION_get_value_string (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, char **value) { struct ConfigEntry *e; @@ -616,8 +615,9 @@ GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, +GNUNET_CONFIGURATION_get_value_choice (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, const char **choices, const char **value) @@ -656,8 +656,9 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle * @return GNUNET_YES if so, GNUNET_NO if not. */ int -GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *section, const char *option) +GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option) { struct ConfigEntry *e; if ((NULL == (e = findEntry (cfg, section, option))) || (e->val == NULL)) @@ -676,8 +677,8 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, * @return $-expanded string */ char * -GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, - char *orig) +GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle + *cfg, char *orig) { int i; char *prefix; @@ -733,8 +734,9 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cf * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, +GNUNET_CONFIGURATION_get_value_filename (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, char **value) { int ret; @@ -770,8 +772,9 @@ GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handl * @return GNUNET_YES, GNUNET_NO or GNUNET_SYSERR */ int -GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *section, const char *option) +GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option) { static const char *yesno[] = { "YES", "NO", NULL }; const char *val; @@ -801,7 +804,7 @@ int GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, - const char *option, + const char *option, GNUNET_FileNameCallback cb, void *cb_cls) { diff --git a/src/util/connection.c b/src/util/connection.c index 6c2aafb0e..daf0cbf03 100644 --- a/src/util/connection.c +++ b/src/util/connection.c @@ -45,32 +45,32 @@ * Possible functions to call after connect failed or succeeded. */ enum ConnectContinuations - { +{ /** * Call nothing. */ - COCO_NONE = 0, + COCO_NONE = 0, /** * Call "receive_again". */ - COCO_RECEIVE_AGAIN = 1, + COCO_RECEIVE_AGAIN = 1, /** * Call "transmit_ready". */ - COCO_TRANSMIT_READY = 2, + COCO_TRANSMIT_READY = 2, /** * Call "destroy_continuation". */ - COCO_DESTROY_CONTINUATION = 4 - }; + COCO_DESTROY_CONTINUATION = 4 +}; /** * Transmission handle. There can only be one for each connection. - */ + */ struct GNUNET_CONNECTION_TransmitHandle { @@ -166,7 +166,7 @@ struct GNUNET_CONNECTION_Handle /** * Configuration to use. - */ + */ const struct GNUNET_CONFIGURATION_Handle *cfg; /** @@ -253,12 +253,12 @@ struct GNUNET_CONNECTION_Handle * Timeout for receiving (in absolute time). */ struct GNUNET_TIME_Absolute receive_timeout; - + /** * Functions to call after connect failed or succeeded. */ enum ConnectContinuations ccs; - + /** * Maximum number of bytes to read (for receiving). */ @@ -293,8 +293,9 @@ struct GNUNET_CONNECTION_Handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_existing (struct GNUNET_SCHEDULER_Handle - *sched, struct GNUNET_NETWORK_Handle *osSocket, - size_t maxbuf) + *sched, + struct GNUNET_NETWORK_Handle + *osSocket, size_t maxbuf) { struct GNUNET_CONNECTION_Handle *ret; ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); @@ -320,10 +321,11 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_SCHEDULER_Handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle - *sched, - GNUNET_CONNECTION_AccessCheck access, - void *access_cls, struct GNUNET_NETWORK_Handle *lsock, - size_t maxbuf) + *sched, + GNUNET_CONNECTION_AccessCheck access, + void *access_cls, + struct GNUNET_NETWORK_Handle *lsock, + size_t maxbuf) { struct GNUNET_CONNECTION_Handle *ret; char addr[32]; @@ -336,7 +338,8 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle void *uaddr; addrlen = sizeof (addr); - sock = GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); + sock = + GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); if (NULL == sock) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept"); @@ -375,10 +378,11 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle (GNUNET_YES != (aret = access (access_cls, uaddr, addrlen)))) { if (aret == GNUNET_NO) - GNUNET_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_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; @@ -392,9 +396,8 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle ret->sched = sched; #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Accepting connection from `%s': %p\n"), - GNUNET_a2s(uaddr, addrlen), - ret); + _("Accepting connection from `%s': %p\n"), + GNUNET_a2s (uaddr, addrlen), ret); #endif return ret; } @@ -409,7 +412,7 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle */ 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; @@ -428,7 +431,7 @@ GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock, */ static void retry_connect_continuation (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc); + const struct GNUNET_SCHEDULER_TaskContext *tc); /** @@ -467,9 +470,8 @@ destroy_continuation (void *cls, if (0 != (sock->ccs & COCO_TRANSMIT_READY)) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Destroy waits for CCS-TR to be done (%p)\n", - sock); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Destroy waits for CCS-TR to be done (%p)\n", sock); #endif sock->ccs |= COCO_DESTROY_CONTINUATION; return; @@ -477,9 +479,8 @@ destroy_continuation (void *cls, if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Destroy waits for write_task to be done (%p)\n", - sock); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Destroy waits for write_task to be done (%p)\n", sock); #endif GNUNET_SCHEDULER_add_after (sock->sched, GNUNET_YES, @@ -496,9 +497,8 @@ destroy_continuation (void *cls, if (sock->sock != NULL) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shutting down socket (%p)\n", - sock); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shutting down socket (%p)\n", sock); #endif GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); } @@ -512,9 +512,7 @@ destroy_continuation (void *cls, return; } #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Destroy actually runs (%p)!\n", - sock); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock); #endif GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); GNUNET_assert (sock->ccs == COCO_NONE); @@ -529,8 +527,7 @@ destroy_continuation (void *cls, GNUNET_free_non_null (sock->hostname); #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Freeing memory of connection %p.\n", - sock); + "Freeing memory of connection %p.\n", sock); #endif GNUNET_free (sock); } @@ -559,10 +556,8 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) { #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to establish TCP connection to `%s:%u', no further addresses to try (%p).\n", - h->hostname, - h->port, - h); + "Failed to establish TCP connection to `%s:%u', no further addresses to try (%p).\n", + h->hostname, h->port, h); #endif /* connect failed / timed out */ GNUNET_break (h->ap_head == NULL); @@ -575,49 +570,46 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "connect_timeout_continuation triggers receive_again (%p)\n", - h); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "connect_timeout_continuation triggers receive_again (%p)\n", + h); #endif h->ccs -= COCO_RECEIVE_AGAIN; h->read_task = GNUNET_SCHEDULER_add_after (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - &receive_again, - h); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + &receive_again, h); } if (0 != (h->ccs & COCO_TRANSMIT_READY)) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "connect_timeout_continuation cancels timeout_task, triggers transmit_ready (%p)\n", - h); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "connect_timeout_continuation cancels timeout_task, triggers transmit_ready (%p)\n", + h); #endif - GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); + GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); GNUNET_SCHEDULER_cancel (h->sched, h->nth.timeout_task); h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; h->ccs -= COCO_TRANSMIT_READY; h->write_task = GNUNET_SCHEDULER_add_after (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - &transmit_ready, - h); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + &transmit_ready, h); } if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "connect_timeout_continuation runs destroy_continuation (%p)\n", - h); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "connect_timeout_continuation runs destroy_continuation (%p)\n", + h); #endif h->ccs -= COCO_DESTROY_CONTINUATION; GNUNET_SCHEDULER_add_continuation (h->sched, - GNUNET_NO, - &destroy_continuation, - h, - GNUNET_SCHEDULER_REASON_TIMEOUT); + GNUNET_NO, + &destroy_continuation, + h, GNUNET_SCHEDULER_REASON_TIMEOUT); } } @@ -632,58 +624,57 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) { #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connection to `%s' succeeded! (%p)\n", - GNUNET_a2s(h->addr, h->addrlen), - h); + "Connection to `%s' succeeded! (%p)\n", + GNUNET_a2s (h->addr, h->addrlen), h); #endif /* trigger jobs that waited for the connection */ if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs receive_again (%p)\n", - h); + GNUNET_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_after (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - &receive_again, - h); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + &receive_again, h); } if (0 != (h->ccs & COCO_TRANSMIT_READY)) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n", - h); + GNUNET_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_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); GNUNET_SCHEDULER_cancel (h->sched, h->nth.timeout_task); h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; h->ccs -= COCO_TRANSMIT_READY; h->write_task = - GNUNET_SCHEDULER_add_write_net (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_absolute_get_remaining (h->nth.transmit_timeout), - h->sock, &transmit_ready, h); + GNUNET_SCHEDULER_add_write_net (h->sched, + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_absolute_get_remaining + (h->nth.transmit_timeout), h->sock, + &transmit_ready, h); } if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs destroy_continuation (%p)\n", - h); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "connect_success_continuation runs destroy_continuation (%p)\n", + h); #endif h->ccs -= COCO_DESTROY_CONTINUATION; GNUNET_SCHEDULER_add_continuation (h->sched, - GNUNET_NO, - &destroy_continuation, - h, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); + GNUNET_NO, + &destroy_continuation, + h, + GNUNET_SCHEDULER_REASON_PREREQ_DONE); } } @@ -697,7 +688,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; @@ -709,15 +700,16 @@ connect_probe_continuation (void *cls, len = sizeof (error); errno = 0; 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) || (errno != 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) + || (errno != 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); + if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO)) + connect_fail_continuation (h); return; } h->sock = ap->sock; @@ -748,55 +740,48 @@ connect_probe_continuation (void *cls, */ static void try_connect_using_address (void *cls, - const struct sockaddr * addr, - socklen_t addrlen) + const struct sockaddr *addr, socklen_t addrlen) { struct GNUNET_CONNECTION_Handle *h = cls; struct AddressProbe *ap; struct GNUNET_TIME_Relative delay; - + if (addr == NULL) { if (h->dns_active == GNUNET_SYSERR) - { - h->dns_active = GNUNET_NO; - GNUNET_SCHEDULER_add_after (h->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - h->read_task, - &destroy_continuation, - h); - return; - } + { + h->dns_active = GNUNET_NO; + GNUNET_SCHEDULER_add_after (h->sched, + GNUNET_YES, + GNUNET_SCHEDULER_PRIORITY_KEEP, + h->read_task, &destroy_continuation, h); + return; + } h->dns_active = GNUNET_NO; if (NULL == h->ap_head) - connect_fail_continuation (h); + connect_fail_continuation (h); return; } if (h->sock != NULL) - return; /* already connected */ + return; /* already connected */ if (h->dns_active == GNUNET_SYSERR) { #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connection %p has already been destroyed.\n", - h); + "Connection %p has already been destroyed.\n", h); #endif - return; /* already destroyed */ + return; /* already destroyed */ } /* try to connect */ #if DEBUG_CONNECTION GNUNET_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]; + ap->addr = (const struct sockaddr *) &ap[1]; memcpy (&ap[1], addr, addrlen); - ap->addrlen = addrlen; + ap->addrlen = addrlen; ap->h = h; switch (ap->addr->sa_family) @@ -810,25 +795,24 @@ try_connect_using_address (void *cls, default: GNUNET_break (0); GNUNET_free (ap); - return; /* not supported by us */ + return; /* not supported by us */ } - ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); + 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 */ + return; /* not supported by OS */ } #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Trying to connect to `%s' (%p)\n"), - GNUNET_a2s(ap->addr, - ap->addrlen), - h); + _("Trying to connect to `%s' (%p)\n"), + GNUNET_a2s (ap->addr, ap->addrlen), h); #endif - if ( (GNUNET_OK != GNUNET_NETWORK_socket_connect (ap->sock, - ap->addr, - ap->addrlen)) && - (errno != EINPROGRESS)) + if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (ap->sock, + ap->addr, + ap->addrlen)) && + (errno != EINPROGRESS)) { /* maybe refused / unsupported address, try next */ GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); @@ -840,18 +824,18 @@ try_connect_using_address (void *cls, 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_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)); - ap->task = GNUNET_SCHEDULER_add_write_net (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - delay, - ap->sock, - &connect_probe_continuation, - ap); + GNUNET_TIME_absolute_get_remaining (h-> + receive_timeout)); + ap->task = + GNUNET_SCHEDULER_add_write_net (h->sched, GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, delay, ap->sock, + &connect_probe_continuation, ap); } @@ -863,18 +847,17 @@ try_connect_using_address (void *cls, */ static void retry_connect_continuation (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CONNECTION_Handle *sock = cls; sock->dns_active = GNUNET_YES; GNUNET_RESOLVER_ip_get (sock->sched, - sock->cfg, - sock->hostname, - AF_UNSPEC, - GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, - &try_connect_using_address, - sock); + sock->cfg, + sock->hostname, + AF_UNSPEC, + GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, + &try_connect_using_address, sock); } @@ -892,14 +875,15 @@ retry_connect_continuation (void *cls, * @return the socket handle */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched, - const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *hostname, - uint16_t port, size_t maxbuf) +GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched, + const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *hostname, uint16_t port, + size_t maxbuf) { 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) + maxbuf); ret->cfg = cfg; ret->sched = sched; @@ -927,9 +911,9 @@ GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched, */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle - *sched, int af_family, - const struct sockaddr *serv_addr, - socklen_t addrlen, size_t maxbuf) + *sched, int af_family, + const struct sockaddr *serv_addr, + socklen_t addrlen, size_t maxbuf) { struct GNUNET_NETWORK_Handle *s; struct GNUNET_CONNECTION_Handle *ret; @@ -941,7 +925,8 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle GNUNET_ERROR_TYPE_BULK, "socket"); return NULL; } - if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && (errno != EINPROGRESS)) + if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) + && (errno != EINPROGRESS)) { /* maybe refused / unsupported address, try next */ GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); @@ -954,9 +939,8 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle ret->addrlen = addrlen; #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Trying to connect to `%s' (%p)\n"), - GNUNET_a2s(serv_addr, addrlen), - ret); + _("Trying to connect to `%s' (%p)\n"), + GNUNET_a2s (serv_addr, addrlen), ret); #endif return ret; } @@ -973,8 +957,7 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle int GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) { - if ( (sock->ap_head != NULL) || - (sock->dns_active == GNUNET_YES) ) + if ((sock->ap_head != NULL) || (sock->dns_active == GNUNET_YES)) return GNUNET_YES; /* still trying to connect */ return (sock->sock == NULL) ? GNUNET_NO : GNUNET_YES; } @@ -990,11 +973,10 @@ GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) void GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock) { - if ( (sock->write_buffer_off == 0) && - (sock->dns_active == GNUNET_YES) ) + if ((sock->write_buffer_off == 0) && (sock->dns_active == GNUNET_YES)) { - sock->dns_active = GNUNET_SYSERR; /* if we're still trying to connect and have - no message pending, stop trying! */ + sock->dns_active = GNUNET_SYSERR; /* if we're still trying to connect and have + no message pending, stop trying! */ return; } GNUNET_assert (sock->sched != NULL); @@ -1016,8 +998,7 @@ signal_timeout (struct GNUNET_CONNECTION_Handle *sh) #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Network signals time out to receiver (%p)!\n", - sh); + "Network signals time out to receiver (%p)!\n", sh); #endif GNUNET_assert (NULL != (receiver = sh->receiver)); sh->receiver = NULL; @@ -1053,17 +1034,17 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sh->read_task = GNUNET_SCHEDULER_NO_TASK; now = GNUNET_TIME_absolute_get (); - if ( (now.value > sh->receive_timeout.value) || - (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) || - (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) ) + if ((now.value > sh->receive_timeout.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)) - GNUNET_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).value, - sh); + GNUNET_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). + value, sh); #endif signal_timeout (sh); return; @@ -1073,8 +1054,7 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /* connect failed for good */ #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error, socket closed... (%p)\n", - sh); + "Receive encounters error, socket closed... (%p)\n", sh); #endif signal_error (sh, ECONNREFUSED); return; @@ -1088,8 +1068,7 @@ RETRY: goto RETRY; #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Error receiving: %s\n", - STRERROR (errno)); + "Error receiving: %s\n", STRERROR (errno)); #endif signal_error (sh, errno); return; @@ -1097,10 +1076,8 @@ RETRY: #if DEBUG_CONNECTION GNUNET_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); + (unsigned int) ret, + sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh); #endif GNUNET_assert (NULL != (receiver = sh->receiver)); sh->receiver = NULL; @@ -1125,13 +1102,12 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct GNUNET_TIME_Absolute now; sh->read_task = GNUNET_SCHEDULER_NO_TASK; - if (sh->sock == NULL) + if (sh->sock == NULL) { /* not connected and no longer trying */ #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error, socket closed (%p)...\n", - sh); + "Receive encounters error, socket closed (%p)...\n", sh); #endif signal_error (sh, ECONNREFUSED); return; @@ -1142,8 +1118,7 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error: time out (%p)...\n", - sh); + "Receive encounters error: time out (%p)...\n", sh); #endif signal_timeout (sh); return; @@ -1151,14 +1126,13 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (sh->sock != NULL); /* connect succeeded, wait for data! */ sh->read_task = GNUNET_SCHEDULER_add_read_net (tc->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_absolute_get_remaining - (sh->receive_timeout), - sh->sock, - &receive_ready, - sh); + GNUNET_YES, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_absolute_get_remaining + (sh->receive_timeout), + sh->sock, + &receive_ready, sh); } @@ -1177,14 +1151,15 @@ 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) + size_t max, + 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)) && + (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) && (sock->receiver == NULL)); sock->receiver = receiver; sock->receiver_cls = receiver_cls; @@ -1198,8 +1173,7 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, receive_again (sock, &tc); return; } - if ( (sock->dns_active != GNUNET_YES) && - (sock->ap_head == NULL) ) + if ((sock->dns_active != GNUNET_YES) && (sock->ap_head == NULL)) { receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); return; @@ -1221,12 +1195,12 @@ GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock) { if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->sched, - sock->read_task)); + GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->sched, + sock->read_task)); sock->read_task = GNUNET_SCHEDULER_NO_TASK; } else - { + { GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN)); sock->ccs -= COCO_RECEIVE_AGAIN; } @@ -1285,28 +1259,24 @@ process_notify (struct GNUNET_CONNECTION_Handle *sock) * This task notifies the client about the timeout. */ static void -transmit_timeout (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CONNECTION_Handle *sock = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "transmit_timeout running (%p)\n", - sock); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "transmit_timeout running (%p)\n", sock); #endif sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; #if DEBUG_CONNECTION - GNUNET_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); + GNUNET_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); #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); @@ -1320,17 +1290,15 @@ transmit_timeout (void *cls, * This task notifies the client about the error. */ static void -connect_error (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +connect_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CONNECTION_Handle *sock = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transmission request of size %u fails, connection failed (%p).\n", - sock->nth.notify_size, - sock); + "Transmission request of size %u fails, connection failed (%p).\n", + sock->nth.notify_size, sock); #endif sock->write_task = GNUNET_SCHEDULER_NO_TASK; notify = sock->nth.notify_ready; @@ -1369,9 +1337,8 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) size_t have; #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "transmit_ready running (%p).\n", - sock); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "transmit_ready running (%p).\n", sock); #endif GNUNET_assert (sock->write_task != GNUNET_SCHEDULER_NO_TASK); sock->write_task = GNUNET_SCHEDULER_NO_TASK; @@ -1379,10 +1346,9 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transmit to `%s' fails, time out reached (%p).\n", - GNUNET_a2s (sock->addr, sock->addrlen), - sock); + GNUNET_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; sock->nth.notify_ready = NULL; @@ -1393,24 +1359,25 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 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. */ + 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 (!GNUNET_NETWORK_fdset_isset (tc->write_ready, sock->sock)) { #if DEBUG_CONNECTION GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), - sock); + _ + ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), + sock); #endif 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; + } transmit_error (sock); return; /* connect failed for good, we're finished */ } @@ -1419,13 +1386,14 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) have = sock->write_buffer_off - sock->write_buffer_pos; if (have == 0) { - /* no data ready for writing, terminate write loop */ + /* no data ready for writing, terminate write loop */ return; } RETRY: ret = GNUNET_NETWORK_socket_send (sock->sock, - &sock->write_buffer[sock->write_buffer_pos], - have); + &sock->write_buffer[sock-> + write_buffer_pos], + have); if (ret == -1) { if (errno == EINTR) @@ -1442,10 +1410,8 @@ RETRY: #if DEBUG_CONNECTION GNUNET_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) @@ -1454,25 +1420,23 @@ RETRY: 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! */ + if ((sock->write_buffer_off == 0) && (NULL == sock->nth.notify_ready)) + return; /* all data sent! */ /* not done writing, schedule more */ SCHEDULE_WRITE: #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Re-scheduling transmit_ready (more to do) (%p).\n", - sock); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Re-scheduling transmit_ready (more to do) (%p).\n", sock); #endif if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) sock->write_task = GNUNET_SCHEDULER_add_write_net (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_absolute_get_remaining (sock->nth.transmit_timeout), - sock->sock, - &transmit_ready, sock); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_absolute_get_remaining + (sock->nth.transmit_timeout), + sock->sock, &transmit_ready, sock); } @@ -1492,10 +1456,10 @@ SCHEDULE_WRITE: */ 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) + *sock, size_t size, + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_TransmitReadyNotify + notify, void *notify_cls) { if (sock->nth.notify_ready != NULL) return NULL; @@ -1510,17 +1474,15 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle sock->nth.notify_size = size; sock->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task); - if ( (sock->sock == NULL) && - (sock->ap_head == NULL) && - (sock->dns_active != GNUNET_YES) ) - { + if ((sock->sock == NULL) && + (sock->ap_head == NULL) && (sock->dns_active != GNUNET_YES)) + { sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, - &connect_error, - sock); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_ZERO, + &connect_error, sock); return &sock->nth; } if (GNUNET_SCHEDULER_NO_TASK != sock->write_task) @@ -1528,33 +1490,35 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle if (sock->sock != NULL) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Scheduling transmit_ready (%p).\n", - sock); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling transmit_ready (%p).\n", sock); #endif sock->write_task = GNUNET_SCHEDULER_add_write_net (sock->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_absolute_get_remaining (sock->nth.transmit_timeout), - sock->sock, - &transmit_ready, sock); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_absolute_get_remaining + (sock->nth. + transmit_timeout), + sock->sock, + &transmit_ready, + sock); } else { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", - sock); + GNUNET_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 (sock->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - timeout, - &transmit_timeout, - sock); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + timeout, + &transmit_timeout, + sock); } return &sock->nth; } @@ -1566,15 +1530,16 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle */ void GNUNET_CONNECTION_notify_transmit_ready_cancel (struct - GNUNET_CONNECTION_TransmitHandle *h) + GNUNET_CONNECTION_TransmitHandle + *h) { GNUNET_assert (h->notify_ready != NULL); if (0 != (h->sh->ccs & COCO_TRANSMIT_READY)) { #if DEBUG_CONNECTION - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "notify_transmit_ready_cancel cancels timeout_task (%p)\n", - h); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "notify_transmit_ready_cancel cancels timeout_task (%p)\n", + h); #endif GNUNET_SCHEDULER_cancel (h->sh->sched, h->timeout_task); h->timeout_task = GNUNET_SCHEDULER_NO_TASK; @@ -1582,8 +1547,7 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct } else { - GNUNET_SCHEDULER_cancel (h->sh->sched, - h->sh->write_task); + GNUNET_SCHEDULER_cancel (h->sh->sched, h->sh->write_task); h->sh->write_task = GNUNET_SCHEDULER_NO_TASK; } h->notify_ready = NULL; diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index 1ed09296d..8e44f4fc6 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c @@ -142,7 +142,8 @@ testBit (char *bitArray, unsigned int bitIdx) * @param fh A file to keep the 4 bit address usage counters in */ static void -incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) +incrementBit (char *bitArray, unsigned int bitIdx, + const struct GNUNET_DISK_FileHandle *fh) { off_t fileSlot; unsigned char value; @@ -157,8 +158,8 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File fileSlot = bitIdx / 2; targetLoc = bitIdx % 2; - GNUNET_assert (fileSlot == - GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); + GNUNET_assert (fileSlot == + GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); if (1 != GNUNET_DISK_file_read (fh, &value, 1)) value = 0; low = value & 0xF; @@ -175,9 +176,9 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File high++; } value = ((high << 4) | low); - GNUNET_assert (fileSlot == GNUNET_DISK_file_seek (fh, - fileSlot, - GNUNET_DISK_SEEK_SET)); + GNUNET_assert (fileSlot == GNUNET_DISK_file_seek (fh, + fileSlot, + GNUNET_DISK_SEEK_SET)); GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); } @@ -190,7 +191,8 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File * @param fh A file to keep the 4bit address usage counters in */ static void -decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) +decrementBit (char *bitArray, unsigned int bitIdx, + const struct GNUNET_DISK_FileHandle *fh) { off_t fileSlot; unsigned char value; @@ -243,8 +245,7 @@ decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File * @return GNUNET_OK if created ok, GNUNET_SYSERR otherwise */ static int -makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, - size_t size) +makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size) { char *buffer; size_t bytesleft = size; @@ -286,7 +287,7 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, * @param bit the current bit */ typedef void (*BitIterator) (void *cls, - struct GNUNET_CONTAINER_BloomFilter * bf, + struct GNUNET_CONTAINER_BloomFilter * bf, unsigned int bit); /** @@ -314,9 +315,9 @@ iterateBits (struct GNUNET_CONTAINER_BloomFilter *bf, { while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) { - callback (arg, - bf, - (((uint32_t *) &tmp[round & 1])[slot]) & + callback (arg, + bf, + (((uint32_t *) & tmp[round & 1])[slot]) & ((bf->bitArraySize * 8) - 1)); slot++; bitCount--; @@ -342,7 +343,7 @@ iterateBits (struct GNUNET_CONTAINER_BloomFilter *bf, */ static void incrementBitCallback (void *cls, - struct GNUNET_CONTAINER_BloomFilter *bf, + struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) { incrementBit (bf->bitArray, bit, bf->fh); @@ -357,7 +358,7 @@ incrementBitCallback (void *cls, */ static void decrementBitCallback (void *cls, - struct GNUNET_CONTAINER_BloomFilter *bf, + struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) { decrementBit (bf->bitArray, bit, bf->fh); @@ -372,7 +373,7 @@ decrementBitCallback (void *cls, */ static void testBitCallback (void *cls, - struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) + struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) { int *arg = cls; if (GNUNET_NO == testBit (bf->bitArray, bit)) @@ -392,9 +393,8 @@ testBitCallback (void *cls, * @return the bloomfilter */ struct GNUNET_CONTAINER_BloomFilter * -GNUNET_CONTAINER_bloomfilter_load (const char *filename, - size_t size, - unsigned int k) +GNUNET_CONTAINER_bloomfilter_load (const char *filename, + size_t size, unsigned int k) { struct GNUNET_CONTAINER_BloomFilter *bf; char *rbuff; @@ -416,8 +416,9 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, if (filename != NULL) { bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE - | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (NULL == bf->fh) { GNUNET_free (bf); @@ -446,12 +447,11 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, int res; res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); - if (res == -1) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "read", - bf->filename); - } + if (res == -1) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "read", bf->filename); + } if (res == 0) break; /* is ok! we just did not use that many bits yet */ for (i = 0; i < res; i++) @@ -486,8 +486,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, */ struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init (const char *data, - size_t size, - unsigned int k) + size_t size, unsigned int k) { struct GNUNET_CONTAINER_BloomFilter *bf; size_t ui; @@ -527,8 +526,7 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, */ int GNUNET_CONTAINER_bloomfilter_get_raw_data (struct GNUNET_CONTAINER_BloomFilter - *bf, char *data, - size_t size) + *bf, char *data, size_t size) { if (NULL == bf) return GNUNET_SYSERR; @@ -624,8 +622,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, */ int GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, - const char *data, - size_t size) + const char *data, size_t size) { unsigned int i; @@ -671,9 +668,8 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, void GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, GNUNET_HashCodeIterator iterator, - void *iterator_cls, - size_t size, - unsigned int k) + void *iterator_cls, + size_t size, unsigned int k) { GNUNET_HashCode hc; unsigned int i; diff --git a/src/util/container_heap.c b/src/util/container_heap.c index 4709d97a6..9d252159f 100644 --- a/src/util/container_heap.c +++ b/src/util/container_heap.c @@ -67,7 +67,8 @@ struct GNUNET_CONTAINER_Heap * @param heap the heap * @return NULL if the heap is empty */ -void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap) +void * +GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap) { if ((heap == NULL) || (heap->root == NULL)) return NULL; @@ -76,7 +77,7 @@ void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap) } static int -next_power_of_2(int v) +next_power_of_2 (int v) { v |= v >> 1; v |= v >> 2; @@ -129,7 +130,7 @@ void GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap) { while (heap->size > 0) - GNUNET_CONTAINER_heap_remove_root (heap); + GNUNET_CONTAINER_heap_remove_root (heap); GNUNET_free (heap); return; } @@ -175,7 +176,7 @@ getNextPos (struct GNUNET_CONTAINER_Heap *root) else { parent = root->root; - for (i = next_power_of_2(pos) >> 2; i > 1; i >>= 1) + for (i = next_power_of_2 (pos) >> 2; i > 1; i >>= 1) { if (((pos / i) % 2) == 0) parent = parent->left_child; @@ -209,7 +210,7 @@ getPos (struct GNUNET_CONTAINER_Heap *root, unsigned int pos) else { ret = root->root; - for (i = next_power_of_2(pos) >> 2; i > 0; i >>= 1) + for (i = next_power_of_2 (pos) >> 2; i > 0; i >>= 1) { if (((pos / i) % 2) == 0) ret = ret->left_child; diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c index 5c70f95ff..ebf6ce778 100644 --- a/src/util/container_meta_data.c +++ b/src/util/container_meta_data.c @@ -196,8 +196,7 @@ GNUNET_CONTAINER_meta_data_get_contents (const struct { if ((iter != NULL) && (GNUNET_OK != iter (iter_cls, - md->items[i].type, - md->items[i].data))) + md->items[i].type, md->items[i].data))) return GNUNET_SYSERR; } else @@ -487,8 +486,7 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData hdr->version = htonl (md == NULL ? 1 : 0); hdr->entries = htonl (ic); for (i = 0; i < ic; i++) - ((uint32_t *) &hdr[1])[i] = - htonl ((uint32_t) md->items[i].type); + ((uint32_t *) & hdr[1])[i] = htonl ((uint32_t) md->items[i].type); pos = sizeof (struct MetaDataHeader); pos += sizeof (unsigned int) * ic; for (i = 0; i < ic; i++) @@ -556,7 +554,8 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData */ ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size (const struct - GNUNET_CONTAINER_MetaData *md, + GNUNET_CONTAINER_MetaData * + md, enum GNUNET_CONTAINER_MetaDataSerializationOptions opt) @@ -579,7 +578,7 @@ GNUNET_CONTAINER_meta_data_get_serialized_size (const struct hdr->version = htonl (md == NULL ? 1 : 0); hdr->entries = htonl (ic); for (i = 0; i < ic; i++) - ((uint32_t *) &hdr[1])[i] = htonl ((uint32_t) md->items[i].type); + ((uint32_t *) & hdr[1])[i] = htonl ((uint32_t) md->items[i].type); pos = sizeof (struct MetaDataHeader); pos += sizeof (uint32_t) * ic; for (i = 0; i < ic; i++) diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c index 2c88b1a52..e291b8b50 100644 --- a/src/util/container_multihashmap.c +++ b/src/util/container_multihashmap.c @@ -199,8 +199,7 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct e = map->map[i]; while (e != NULL) { - if ( (NULL != it) && - (GNUNET_OK != it (it_cls, &e->key, e->value)) ) + if ((NULL != it) && (GNUNET_OK != it (it_cls, &e->key, e->value))) return GNUNET_SYSERR; count++; e = e->next; @@ -235,8 +234,8 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap e = map->map[i]; while (e != NULL) { - if ( (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && - (value == e->value)) + if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && + (value == e->value)) { if (p == NULL) map->map[i] = e->next; @@ -354,7 +353,7 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map) while (NULL != (e = old_map[i])) { old_map[i] = e->next; - idx = idx_of (map, &e->key); + idx = idx_of (map, &e->key); e->next = new_map[idx]; new_map[idx] = e; } @@ -386,8 +385,8 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, unsigned int i; i = idx_of (map, key); - if ( (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && - (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST) ) + if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && + (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) { e = map->map[i]; while (e != NULL) @@ -405,7 +404,7 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, if (map->size / 3 >= map->map_length / 4) { grow (map); - i = idx_of (map, key); + i = idx_of (map, key); } e = GNUNET_malloc (sizeof (struct MapEntry)); e->key = *key; @@ -443,8 +442,7 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct { if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) { - if ( (it != NULL) && - (GNUNET_OK != it (it_cls, &e->key, e->value)) ) + if ((it != NULL) && (GNUNET_OK != it (it_cls, &e->key, e->value))) return GNUNET_SYSERR; count++; } diff --git a/src/util/container_slist.c b/src/util/container_slist.c index 3d96e26e2..4f5607a28 100644 --- a/src/util/container_slist.c +++ b/src/util/container_slist.c @@ -34,7 +34,7 @@ struct GNUNET_CONTAINER_SList_Elem { /** * This is a linked list. - */ + */ struct GNUNET_CONTAINER_SList_Elem *next; /** @@ -102,9 +102,8 @@ struct GNUNET_CONTAINER_SList_Iterator * @return a new element */ static struct GNUNET_CONTAINER_SList_Elem * -create_elem (enum GNUNET_CONTAINER_SListDisposition disp, - const void *buf, - size_t len) +create_elem (enum GNUNET_CONTAINER_SListDisposition disp, + const void *buf, size_t len) { struct GNUNET_CONTAINER_SList_Elem *e; @@ -112,12 +111,12 @@ create_elem (enum GNUNET_CONTAINER_SListDisposition disp, { e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len); memcpy (&e[1], buf, len); - e->elem = (void*) &e[1]; + e->elem = (void *) &e[1]; } else { e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem)); - e->elem = (void*) buf; + e->elem = (void *) buf; } e->disp = disp; e->len = len; @@ -133,8 +132,8 @@ create_elem (enum GNUNET_CONTAINER_SListDisposition disp, * @param len length of the buffer */ void -GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, - enum GNUNET_CONTAINER_SListDisposition disp, +GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, + enum GNUNET_CONTAINER_SListDisposition disp, const void *buf, size_t len) { struct GNUNET_CONTAINER_SList_Elem *e; @@ -201,7 +200,7 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l) { n = e->next; if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC) - GNUNET_free (e->elem); + GNUNET_free (e->elem); GNUNET_free (e); e = n; } @@ -224,8 +223,7 @@ GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, struct GNUNET_CONTAINER_SList_Elem *e; for (e = l->head; e != NULL; e = e->next) - if ( (e->len == len) && - (memcmp (buf, e->elem, len) == 0) ) + if ((e->len == len) && (memcmp (buf, e->elem, len) == 0)) return GNUNET_YES; return GNUNET_NO; } @@ -275,8 +273,8 @@ GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i) */ void GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before, - enum GNUNET_CONTAINER_SListDisposition disp, - const void *buf, size_t len) + enum GNUNET_CONTAINER_SListDisposition disp, + const void *buf, size_t len) { struct GNUNET_CONTAINER_SList_Elem *e; diff --git a/src/util/crypto_aes.c b/src/util/crypto_aes.c index 6db932b5b..a44c2d133 100644 --- a/src/util/crypto_aes.c +++ b/src/util/crypto_aes.c @@ -76,9 +76,9 @@ ssize_t GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len, const struct GNUNET_CRYPTO_AesSessionKey - *sessionkey, + * sessionkey, const struct GNUNET_CRYPTO_AesInitializationVector - *iv, void *result) + * iv, void *result) { gcry_cipher_hd_t handle; int rc; @@ -116,12 +116,12 @@ GNUNET_CRYPTO_aes_encrypt (const void *block, * @return -1 on failure, size of decrypted block on success */ ssize_t -GNUNET_CRYPTO_aes_decrypt (const void *block, - size_t size, +GNUNET_CRYPTO_aes_decrypt (const void *block, + size_t size, const struct GNUNET_CRYPTO_AesSessionKey - *sessionkey, - const struct GNUNET_CRYPTO_AesInitializationVector - *iv, void *result) + * sessionkey, + const struct GNUNET_CRYPTO_AesInitializationVector + * iv, void *result) { gcry_cipher_hd_t handle; int rc; diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index 60e0ec5a2..3f5869489 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c @@ -359,12 +359,10 @@ sha512_final (struct sha512_ctx *sctx, unsigned char *hash) * @param ret pointer to where to write the hashcode */ void -GNUNET_CRYPTO_hash (const void *block, - size_t size, - GNUNET_HashCode * ret) +GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret) { struct sha512_ctx ctx; - + sha512_init (&ctx); sha512_update (&ctx, block, size); sha512_final (&ctx, (unsigned char *) ret); @@ -416,7 +414,7 @@ struct FileHashContext * Current offset. */ uint64_t offset; - + /** * Run on shutdown? */ @@ -480,8 +478,7 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_SCHEDULER_add_after (tc->sched, fhc->run_on_shutdown, GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - &file_hash_task, fhc); + GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc); } @@ -523,8 +520,8 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched, } fhc->run_on_shutdown = run_on_shutdown; fhc->fh = GNUNET_DISK_file_open (filename, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); if (!fhc->fh) { file_hash_finish (fhc, NULL); @@ -533,8 +530,7 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched, GNUNET_SCHEDULER_add_after (sched, run_on_shutdown, priority, - GNUNET_SCHEDULER_NO_TASK, - &file_hash_task, fhc); + GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc); } @@ -662,18 +658,18 @@ GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, } void -GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, GNUNET_HashCode * result) +GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, + GNUNET_HashCode * result) { int i; - for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; - i--) - result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, (uint32_t)-1); + for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; i--) + result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, (uint32_t) - 1); } void GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, - const GNUNET_HashCode * b, - GNUNET_HashCode * result) + const GNUNET_HashCode * b, + GNUNET_HashCode * result) { int i; for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; @@ -683,8 +679,8 @@ GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, void GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, - const GNUNET_HashCode * delta, - GNUNET_HashCode * result) + const GNUNET_HashCode * delta, + GNUNET_HashCode * result) { int i; for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; @@ -694,7 +690,7 @@ GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, void GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, - const GNUNET_HashCode * b, GNUNET_HashCode * result) + const GNUNET_HashCode * b, GNUNET_HashCode * result) { int i; for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; @@ -707,18 +703,18 @@ GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, */ void GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, - struct GNUNET_CRYPTO_AesSessionKey *skey, - struct GNUNET_CRYPTO_AesInitializationVector - *iv) + struct GNUNET_CRYPTO_AesSessionKey *skey, + struct GNUNET_CRYPTO_AesInitializationVector + *iv) { GNUNET_assert (sizeof (GNUNET_HashCode) >= - GNUNET_CRYPTO_AES_KEY_LENGTH + - sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); + GNUNET_CRYPTO_AES_KEY_LENGTH + + sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); skey->crc32 = htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH], - sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); + sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); } /** @@ -741,21 +737,21 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit) */ int GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, - const GNUNET_HashCode * h2) + const GNUNET_HashCode * h2) { unsigned int *i1; unsigned int *i2; int i; - + i1 = (unsigned int *) h1; i2 = (unsigned int *) h2; for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) { if (i1[i] > i2[i]) - return 1; + return 1; if (i1[i] < i2[i]) - return -1; + return -1; } return 0; } @@ -767,21 +763,21 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, */ int GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, - const GNUNET_HashCode * h2, - const GNUNET_HashCode * target) + const GNUNET_HashCode * h2, + const GNUNET_HashCode * target) { int i; unsigned int d1; unsigned int d2; - + for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) { d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; if (d1 > d2) - return 1; + return 1; else if (d1 < d2) - return -1; + return -1; } return 0; } diff --git a/src/util/crypto_ksk.c b/src/util/crypto_ksk.c index 170974b2f..96f8140ad 100644 --- a/src/util/crypto_ksk.c +++ b/src/util/crypto_ksk.c @@ -774,11 +774,8 @@ static pid_t genproc; * blocked gathering entropy. */ static void -entropy_generator (void *cls, - const char *what, - int printchar, - int current, - int total) +entropy_generator (void *cls, + const char *what, int printchar, int current, int total) { unsigned long code; enum GNUNET_OS_ProcessStatusType type; @@ -789,50 +786,45 @@ entropy_generator (void *cls, if (current == total) { if (genproc != 0) - { - if (0 != PLIBC_KILL(genproc, SIGTERM)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, - "kill"); - GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); - genproc = 0; - } + { + if (0 != PLIBC_KILL (genproc, SIGTERM)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill"); + GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); + genproc = 0; + } return; } if (genproc != 0) { - ret = GNUNET_OS_process_status (genproc, - &type, - &code); + ret = GNUNET_OS_process_status (genproc, &type, &code); if (ret == GNUNET_NO) - return; /* still running */ + return; /* still running */ if (ret == GNUNET_SYSERR) - { - GNUNET_break (0); - return; - } - if (0 != PLIBC_KILL(genproc, SIGTERM)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, - "kill"); + { + GNUNET_break (0); + return; + } + if (0 != PLIBC_KILL (genproc, SIGTERM)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill"); GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); - genproc = 0; + genproc = 0; } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Starting `%s' process to generate entropy\n"), - "find"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Starting `%s' process to generate entropy\n"), "find"); genproc = GNUNET_OS_start_process ("sh", - "sh", - "-c", - "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null", - NULL); + "sh", + "-c", + "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null", + NULL); } -static void +static void killfind () { if (genproc != 0) { - PLIBC_KILL(genproc, SIGKILL); + PLIBC_KILL (genproc, SIGKILL); genproc = 0; } } diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index 50af9f251..5d85d1daa 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c @@ -37,8 +37,7 @@ * @return a random value in the interval [0,i[. */ uint32_t -GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, - uint32_t i) +GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i) { #ifdef gcry_fast_random_poll static unsigned int invokeCount; @@ -55,8 +54,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, gcry_fast_random_poll (); #endif gcry_randomize ((unsigned char *) &ret, - sizeof (uint32_t), - GCRY_STRONG_RANDOM); + sizeof (uint32_t), GCRY_STRONG_RANDOM); return ret % i; } else @@ -108,8 +106,7 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n) * @return random 64-bit number */ uint64_t -GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, - uint64_t max) +GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max) { uint64_t ret; @@ -117,8 +114,7 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, if (mode == GNUNET_CRYPTO_QUALITY_STRONG) { gcry_randomize ((unsigned char *) &ret, - sizeof (uint64_t), - GCRY_STRONG_RANDOM); + sizeof (uint64_t), GCRY_STRONG_RANDOM); return ret % max; } else @@ -144,8 +140,7 @@ GNUNET_CRYPTO_random_disable_entropy_gathering () /** * Initializer */ -void __attribute__ ((constructor)) -GNUNET_util_random_init() +void __attribute__ ((constructor)) GNUNET_util_random_init () { SRANDOM (time (NULL)); } diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index cbd9f8f37..c3e0a7833 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -571,9 +571,13 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) return NULL; while (GNUNET_YES != GNUNET_DISK_file_test (filename)) { - fd = GNUNET_DISK_file_open (filename, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_FAILIFEXISTS, - GNUNET_DISK_PERM_USER_READ| GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_READ); + fd = GNUNET_DISK_file_open (filename, + GNUNET_DISK_OPEN_WRITE | + GNUNET_DISK_OPEN_CREATE | + GNUNET_DISK_OPEN_FAILIFEXISTS, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ); if (NULL == fd) { if (errno == EEXIST) @@ -584,7 +588,11 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) } cnt = 0; - while (GNUNET_YES != GNUNET_DISK_file_lock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded), GNUNET_YES)) + while (GNUNET_YES != + GNUNET_DISK_file_lock (fd, 0, + sizeof (struct + RsaPrivateKeyBinaryEncoded), + GNUNET_YES)) { sleep (1); if (0 == ++cnt % 10) @@ -602,13 +610,17 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) GNUNET_assert (ret != NULL); enc = rsa_encode_key (ret); GNUNET_assert (enc != NULL); - GNUNET_assert (ntohs (enc->len) == GNUNET_DISK_file_write (fd, enc, ntohs (enc->len))); + GNUNET_assert (ntohs (enc->len) == + GNUNET_DISK_file_write (fd, enc, ntohs (enc->len))); GNUNET_free (enc); GNUNET_DISK_file_sync (fd); - if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "fcntl", filename); + if (GNUNET_YES != + GNUNET_DISK_file_unlock (fd, 0, + sizeof (struct + RsaPrivateKeyBinaryEncoded))) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", + filename); GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Stored new private key in `%s'.\n"), filename); @@ -616,7 +628,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) } /* hostkey file exists already, read it! */ fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + GNUNET_DISK_PERM_NONE); if (NULL == fd) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); @@ -625,7 +637,10 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) cnt = 0; while (1) { - if (GNUNET_YES != GNUNET_DISK_file_lock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded), GNUNET_NO)) + if (GNUNET_YES != + GNUNET_DISK_file_lock (fd, 0, + sizeof (struct RsaPrivateKeyBinaryEncoded), + GNUNET_NO)) { if (0 == ++cnt % 10) { @@ -645,9 +660,12 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) /* eh, what!? File we opened is now gone!? */ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); - if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "fcntl", filename); + if (GNUNET_YES != + GNUNET_DISK_file_unlock (fd, 0, + sizeof (struct + RsaPrivateKeyBinaryEncoded))) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", + filename); GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); return NULL; @@ -658,9 +676,12 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) { /* maybe we got the read lock before the hostkey generating process had a chance to get the write lock; give it up! */ - if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "fcntl", filename); + if (GNUNET_YES != + GNUNET_DISK_file_unlock (fd, 0, + sizeof (struct + RsaPrivateKeyBinaryEncoded))) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", + filename); if (0 == ++cnt % 10) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -690,7 +711,9 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) filename); } GNUNET_free (enc); - if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded))) + if (GNUNET_YES != + GNUNET_DISK_file_unlock (fd, 0, + sizeof (struct RsaPrivateKeyBinaryEncoded))) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); return ret; @@ -758,10 +781,9 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, * @return the size of the decrypted block, -1 on error */ ssize_t -GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key, - const struct GNUNET_CRYPTO_RsaEncryptedData *block, - void *result, - size_t max) +GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, + const struct GNUNET_CRYPTO_RsaEncryptedData * + block, void *result, size_t max) { gcry_sexp_t resultsexp; gcry_sexp_t data; diff --git a/src/util/disk.c b/src/util/disk.c index b1b631a7f..9f93a1ee2 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -79,7 +79,7 @@ struct GNUNET_DISK_PipeHandle /** * File descriptors for the pipe. */ - struct GNUNET_DISK_FileHandle * fd[2]; + struct GNUNET_DISK_FileHandle *fd[2]; }; @@ -171,8 +171,8 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h) * @return the new position on success, GNUNET_SYSERR otherwise */ off_t -GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset, - enum GNUNET_DISK_Seek whence) +GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset, + enum GNUNET_DISK_Seek whence) { if (h == NULL) { @@ -182,8 +182,9 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset, #ifdef MINGW DWORD ret; - static DWORD t[] = { [GNUNET_DISK_SEEK_SET] = FILE_BEGIN, - [GNUNET_DISK_SEEK_CUR] = FILE_CURRENT, [GNUNET_DISK_SEEK_END] = FILE_END }; + static DWORD t[] = {[GNUNET_DISK_SEEK_SET] = FILE_BEGIN, + [GNUNET_DISK_SEEK_CUR] = FILE_CURRENT,[GNUNET_DISK_SEEK_END] = FILE_END + }; ret = SetFilePointer (h->h, offset, NULL, t[whence]); if (ret == INVALID_SET_FILE_POINTER) @@ -193,8 +194,9 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset, } return ret; #else - static int t[] = { [GNUNET_DISK_SEEK_SET] = SEEK_SET, - [GNUNET_DISK_SEEK_CUR] = SEEK_CUR, [GNUNET_DISK_SEEK_END] = SEEK_END }; + static int t[] = {[GNUNET_DISK_SEEK_SET] = SEEK_SET, + [GNUNET_DISK_SEEK_CUR] = SEEK_CUR,[GNUNET_DISK_SEEK_END] = SEEK_END + }; return lseek (h->fd, offset, t[whence]); #endif @@ -215,8 +217,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset, */ int GNUNET_DISK_file_size (const char *filename, - uint64_t *size, - int includeSymLinks) + uint64_t * size, int includeSymLinks) { struct GetFileSizeData gfsd; int ret; @@ -245,27 +246,24 @@ GNUNET_DISK_file_size (const char *filename, * @param ino set to the inode ID * @return GNUNET_OK on success */ -int GNUNET_DISK_file_get_identifiers (const char *filename, - uint32_t *dev, - uint64_t *ino) +int +GNUNET_DISK_file_get_identifiers (const char *filename, + uint32_t * dev, uint64_t * ino) { #if LINUX struct stat sbuf; struct statvfs fbuf; - if ( (0 == stat(filename, - &sbuf)) && - (0 == statvfs (filename, - &fbuf) ) ) + if ((0 == stat (filename, &sbuf)) && (0 == statvfs (filename, &fbuf))) { *dev = (uint32_t) fbuf.f_fsid; *ino = (uint64_t) sbuf.st_ino; return GNUNET_OK; } -#endif +#endif return GNUNET_SYSERR; } - + /** * Create an (empty) temporary file on disk. @@ -286,12 +284,7 @@ GNUNET_DISK_mktemp (const char *t) tmpdir = getenv ("TMPDIR"); tmpdir = tmpdir ? tmpdir : "/tmp"; - GNUNET_asprintf (&tmpl, - "%s%s%s%s", - tmpdir, - DIR_SEPARATOR_STR, - t, - "XXXXXX"); + GNUNET_asprintf (&tmpl, "%s%s%s%s", tmpdir, DIR_SEPARATOR_STR, t, "XXXXXX"); #ifdef MINGW fn = (char *) GNUNET_malloc (MAX_PATH + 1); plibc_conv_to_win_path (tmpl, fn); @@ -302,16 +295,12 @@ GNUNET_DISK_mktemp (const char *t) fd = mkstemp (fn); if (fd == -1) { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "mkstemp", - fn); + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn); GNUNET_free (fn); return NULL; } if (0 != CLOSE (fd)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "close", - fn); + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); return fn; } @@ -348,8 +337,8 @@ GNUNET_DISK_get_blocks_available (const char *part) if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("`%s' failed for drive `%s': %u\n"), - "GetDiskFreeSpace", szDrive, GetLastError ()); + _("`%s' failed for drive `%s': %u\n"), + "GetDiskFreeSpace", szDrive, GetLastError ()); return -1; } @@ -564,8 +553,8 @@ GNUNET_DISK_directory_create_for_file (const char *filename) * @return the number of bytes read on success, GNUNET_SYSERR on failure */ ssize_t -GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result, - size_t len) +GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result, + size_t len) { if (h == NULL) { @@ -597,19 +586,17 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result, * @return number of bytes read, GNUNET_SYSERR on failure */ ssize_t -GNUNET_DISK_fn_read (const char * fn, - void *result, - size_t len) +GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) { struct GNUNET_DISK_FileHandle *fh; ssize_t ret; fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + GNUNET_DISK_PERM_NONE); if (!fh) return GNUNET_SYSERR; ret = GNUNET_DISK_file_read (fh, result, len); - GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); return ret; } @@ -623,8 +610,8 @@ GNUNET_DISK_fn_read (const char * fn, * @return number of bytes written on success, GNUNET_SYSERR on error */ ssize_t -GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, const void *buffer, - size_t n) +GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, + const void *buffer, size_t n) { if (h == NULL) { @@ -657,21 +644,20 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, const void *buff * @return number of bytes written on success, GNUNET_SYSERR on error */ ssize_t -GNUNET_DISK_fn_write (const char * fn, const void *buffer, - size_t n, - enum GNUNET_DISK_AccessPermissions mode) +GNUNET_DISK_fn_write (const char *fn, const void *buffer, + size_t n, enum GNUNET_DISK_AccessPermissions mode) { struct GNUNET_DISK_FileHandle *fh; ssize_t ret; - fh = GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_WRITE - | GNUNET_DISK_OPEN_TRUNCATE - | GNUNET_DISK_OPEN_CREATE, mode); + fh = GNUNET_DISK_file_open (fn, + GNUNET_DISK_OPEN_WRITE + | GNUNET_DISK_OPEN_TRUNCATE + | GNUNET_DISK_OPEN_CREATE, mode); if (!fh) return GNUNET_SYSERR; ret = GNUNET_DISK_file_write (fh, buffer, n); - GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); return ret; } @@ -688,7 +674,7 @@ GNUNET_DISK_fn_write (const char * fn, const void *buffer, int GNUNET_DISK_directory_scan (const char *dirName, GNUNET_FileNameCallback callback, - void *callback_cls) + void *callback_cls) { DIR *dinfo; struct dirent *finfo; @@ -954,9 +940,7 @@ GNUNET_DISK_directory_remove (const char *fileName) return GNUNET_SYSERR; } if (GNUNET_SYSERR == - GNUNET_DISK_directory_scan (fileName, - &remove_helper, - NULL)) + GNUNET_DISK_directory_scan (fileName, &remove_helper, NULL)) return GNUNET_SYSERR; if (0 != RMDIR (fileName)) { @@ -988,13 +972,16 @@ GNUNET_DISK_file_copy (const char *src, const char *dst) return GNUNET_SYSERR; pos = 0; in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + GNUNET_DISK_PERM_NONE); if (!in) return GNUNET_SYSERR; out = GNUNET_DISK_file_open (dst, GNUNET_DISK_OPEN_WRITE - | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_FAILIFEXISTS, - GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE - | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_GROUP_WRITE); + | GNUNET_DISK_OPEN_CREATE | + GNUNET_DISK_OPEN_FAILIFEXISTS, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_GROUP_WRITE); if (!out) { GNUNET_DISK_file_close (in); @@ -1089,7 +1076,7 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user) */ int GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, - off_t lockEnd, int excl) + off_t lockEnd, int excl) { if (fh == NULL) { @@ -1100,7 +1087,7 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, #ifndef MINGW struct flock fl; - memset (&fl, 0, sizeof(struct flock)); + memset (&fl, 0, sizeof (struct flock)); fl.l_type = excl ? F_WRLCK : F_RDLCK; fl.l_whence = SEEK_SET; fl.l_start = lockStart; @@ -1110,11 +1097,12 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, #else OVERLAPPED o; - memset (&o, 0, sizeof(OVERLAPPED)); + memset (&o, 0, sizeof (OVERLAPPED)); o.Offset = lockStart; if (!LockFileEx (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) - | LOCKFILE_FAIL_IMMEDIATELY, 0, lockEnd - lockStart, 0, &o)) + | LOCKFILE_FAIL_IMMEDIATELY, 0, lockEnd - lockStart, 0, + &o)) { SetErrnoFromWinError (GetLastError ()); return GNUNET_SYSERR; @@ -1134,7 +1122,7 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, */ int GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, - off_t unlockEnd) + off_t unlockEnd) { if (fh == NULL) { @@ -1145,7 +1133,7 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, #ifndef MINGW struct flock fl; - memset (&fl, 0, sizeof(struct flock)); + memset (&fl, 0, sizeof (struct flock)); fl.l_type = F_UNLCK; fl.l_whence = SEEK_SET; fl.l_start = unlockStart; @@ -1155,7 +1143,7 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, #else OVERLAPPED o; - memset (&o, 0, sizeof(OVERLAPPED)); + memset (&o, 0, sizeof (OVERLAPPED)); o.Offset = unlockStart; if (!UnlockFileEx (fh->h, 0, unlockEnd - unlockStart, 0, &o)) @@ -1183,8 +1171,8 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, */ struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open (const char *fn, - enum GNUNET_DISK_OpenFlags flags, - enum GNUNET_DISK_AccessPermissions perm) + enum GNUNET_DISK_OpenFlags flags, + enum GNUNET_DISK_AccessPermissions perm) { char *expfn; struct GNUNET_DISK_FileHandle *ret; @@ -1203,7 +1191,7 @@ GNUNET_DISK_file_open (const char *fn, #ifndef MINGW mode = 0; if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE)) - oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */ + oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */ else if (flags & GNUNET_DISK_OPEN_READ) oflags = O_RDONLY; else if (flags & GNUNET_DISK_OPEN_WRITE) @@ -1245,11 +1233,11 @@ GNUNET_DISK_file_open (const char *fn, fd = open (expfn, oflags | O_LARGEFILE, mode); if (fd == -1) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn); - GNUNET_free (expfn); - return NULL; - } + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn); + GNUNET_free (expfn); + return NULL; + } #else access = 0; disp = OPEN_ALWAYS; @@ -1277,33 +1265,35 @@ GNUNET_DISK_file_open (const char *fn, disp = TRUNCATE_EXISTING; } else - { - disp = OPEN_ALWAYS; - } + { + disp = OPEN_ALWAYS; + } /* TODO: access priviledges? */ h = CreateFile (expfn, access, FILE_SHARE_DELETE | FILE_SHARE_READ - | FILE_SHARE_WRITE, NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL); + | FILE_SHARE_WRITE, NULL, disp, FILE_ATTRIBUTE_NORMAL, + NULL); if (h == INVALID_HANDLE_VALUE) - { - SetErrnoFromWinError (GetLastError ()); - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn); - GNUNET_free (expfn); - return NULL; - } - - if (flags & GNUNET_DISK_OPEN_APPEND) - if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER) { SetErrnoFromWinError (GetLastError ()); - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer", expfn); - CloseHandle (h); + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn); GNUNET_free (expfn); return NULL; } + + if (flags & GNUNET_DISK_OPEN_APPEND) + if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER) + { + SetErrnoFromWinError (GetLastError ()); + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer", + expfn); + CloseHandle (h); + GNUNET_free (expfn); + return NULL; + } #endif - ret = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle)); + ret = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); #ifdef MINGW ret->h = h; #else @@ -1330,19 +1320,19 @@ GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) #if MINGW if (!CloseHandle (h->h)) - { - SetErrnoFromWinError (GetLastError ()); - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close"); - GNUNET_free (h); - return GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close"); + GNUNET_free (h); + return GNUNET_SYSERR; + } #else if (close (h->fd) != 0) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close"); - GNUNET_free (h); - return GNUNET_SYSERR; - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close"); + GNUNET_free (h); + return GNUNET_SYSERR; + } #endif GNUNET_free (h); return GNUNET_OK; @@ -1454,8 +1444,9 @@ struct GNUNET_DISK_MapHandle * @return pointer to the mapped memory region, NULL on failure */ void * -GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, - enum GNUNET_DISK_MapType access, size_t len) +GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, + struct GNUNET_DISK_MapHandle **m, + enum GNUNET_DISK_MapType access, size_t len) { if (h == NULL) { @@ -1467,7 +1458,7 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK DWORD mapAccess, protect; void *ret; - if ((access & GNUNET_DISK_MAP_TYPE_READ) && + if ((access & GNUNET_DISK_MAP_TYPE_READ) && (access & GNUNET_DISK_MAP_TYPE_WRITE)) { protect = PAGE_READWRITE; @@ -1594,7 +1585,9 @@ GNUNET_DISK_pipe (int blocking) struct GNUNET_DISK_PipeHandle *p; struct GNUNET_DISK_FileHandle *fds; - p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) + 2 * sizeof (struct GNUNET_DISK_FileHandle)); + p = + GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) + + 2 * sizeof (struct GNUNET_DISK_FileHandle)); fds = (struct GNUNET_DISK_FileHandle *) &p[1]; p->fd[0] = &fds[0]; p->fd[1] = &fds[1]; @@ -1620,27 +1613,27 @@ GNUNET_DISK_pipe (int blocking) flags |= O_NONBLOCK; ret = fcntl (fd[0], F_SETFL, flags); if (ret != -1) - { - flags = fcntl (fd[1], F_GETFL); - flags |= O_NONBLOCK; - ret = fcntl (fd[1], F_SETFL, flags); - } + { + flags = fcntl (fd[1], F_GETFL); + flags |= O_NONBLOCK; + ret = fcntl (fd[1], F_SETFL, flags); + } if (ret == -1) - { - eno = errno; - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "fcntl"); - GNUNET_break (0 == close (p->fd[0]->fd)); - GNUNET_break (0 == close (p->fd[1]->fd)); - GNUNET_free (p); - errno = eno; - return NULL; - } + { + eno = errno; + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fcntl"); + GNUNET_break (0 == close (p->fd[0]->fd)); + GNUNET_break (0 == close (p->fd[1]->fd)); + GNUNET_free (p); + errno = eno; + return NULL; + } } #else BOOL ret; ret = CreatePipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0); - if (! ret) + if (!ret) { GNUNET_free (p); SetErrnoFromWinError (GetLastError ()); @@ -1649,10 +1642,10 @@ GNUNET_DISK_pipe (int blocking) if (!blocking) { DWORD mode; - + mode = PIPE_NOWAIT; - p->fd[0] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle)); - p->fd[1] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle)); + p->fd[0] = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); + p->fd[1] = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL); SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL); /* this always fails on Windows 95, so we don't care about error handling */ @@ -1673,7 +1666,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) { int ret = GNUNET_OK; int save; - + #ifdef MINGW if (!CloseHandle (p->fd[0]->h)) { @@ -1711,8 +1704,8 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) * @param n end to access */ const struct GNUNET_DISK_FileHandle * -GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, - enum GNUNET_DISK_PipeEnd n) +GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, + enum GNUNET_DISK_PipeEnd n) { switch (n) { @@ -1736,15 +1729,14 @@ GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, */ int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, - void *dst, - size_t dst_len) + void *dst, size_t dst_len) { #ifdef MINGW if (dst_len < sizeof (HANDLE)) return GNUNET_SYSERR; *((HANDLE *) dst) = fh->h; #else - if (dst_len < sizeof(int)) + if (dst_len < sizeof (int)) return GNUNET_SYSERR; *((int *) dst) = fh->fd; #endif diff --git a/src/util/disk.h b/src/util/disk.h index 96324e120..21c1ab9a1 100644 --- a/src/util/disk.h +++ b/src/util/disk.h @@ -16,41 +16,40 @@ along with GNUnet; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - +*/ + /** * @file util/disk.h * @brief Internal DISK related helper functions * @author Nils Durner - */ - - + */ + #ifndef GNUNET_DISK_H_ #define GNUNET_DISK_H_ - + #include "gnunet_disk_lib.h" - - + /** * Handle used to access files (and pipes). - */ -struct GNUNET_DISK_FileHandle -{ + */ +struct GNUNET_DISK_FileHandle +{ + #ifdef MINGW /** * File handle under W32. - */ - HANDLE h; -#else + */ + HANDLE h; + +#else /* */ /** * File handle on other OSes. - */ - int fd; -#endif -}; - - - + */ + int fd; + +#endif /* */ +}; + /** * Retrieve OS file handle * @@ -59,9 +58,8 @@ struct GNUNET_DISK_FileHandle * @param dst destination buffer * @param dst_len length of dst * @return GNUNET_OK on success, GNUNET_SYSERR otherwise - */ -int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, - void *dst, - size_t dst_len); - -#endif /* GNUNET_DISK_H_ */ + */ +int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle + *fh, void *dst, size_t dst_len); + +#endif /* GNUNET_DISK_H_ */ diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index 1dce5cedc..f8dd2e166 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c @@ -44,7 +44,7 @@ struct IPCache * This is a linked list. */ struct IPCache *next; - + /** * Hostname in human-readable form. */ @@ -54,7 +54,7 @@ struct IPCache * Hostname in binary format. */ struct sockaddr *sa; - + /** * Last time this entry was updated. */ @@ -89,11 +89,9 @@ getnameinfo_resolve (struct IPCache *cache) { char hostname[256]; - if (0 == getnameinfo (cache->sa, - cache->salen, - hostname, - sizeof(hostname), - NULL, 0, 0)) + if (0 == getnameinfo (cache->sa, + cache->salen, + hostname, sizeof (hostname), NULL, 0, 0)) cache->addr = GNUNET_strdup (hostname); } #endif @@ -273,7 +271,7 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, // FIXME NILS 1 #endif - ) + ) return GNUNET_NO; /* other function may still succeed */ return GNUNET_SYSERR; } diff --git a/src/util/network.c b/src/util/network.c index 071b18cc6..df3c90c81 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -16,90 +16,94 @@ along with GNUnet; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - +*/ + /** * @file util/network.c * @brief basic, low-level networking interface * @author Nils Durner - */ - + */ + #include "platform.h" #include "gnunet_disk_lib.h" #include "disk.h" #include "gnunet_container_lib.h" - + #define DEBUG_NETWORK GNUNET_NO - + #ifndef INVALID_SOCKET #define INVALID_SOCKET -1 -#endif - -struct GNUNET_NETWORK_Handle -{ - int fd; -}; - -struct GNUNET_NETWORK_FDSet -{ - /* socket descriptors */ - int nsds; - fd_set sds; +#endif /* */ + struct GNUNET_NETWORK_Handle +{ + int fd; + }; + struct GNUNET_NETWORK_FDSet +{ + + /* socket descriptors */ + int nsds; + fd_set sds; + #ifdef WINDOWS - /* handles */ - struct GNUNET_CONTAINER_SList *handles; -#endif -}; - + /* handles */ + struct GNUNET_CONTAINER_SList *handles; + +#endif /* */ +}; + #ifndef FD_COPY #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) -#endif - - - +#endif /* */ + /** * Set if a socket should use blocking or non-blocking IO. * @param fd socket * @param doBlock blocking mode * @return GNUNET_OK on success, GNUNET_SYSERR on error - */ -static int -socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, - int doBlock) -{ + */ +static int +socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock) +{ + #if MINGW - u_long mode; - mode = !doBlock; - if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR) - { - SetErrnoFromWinsockError (WSAGetLastError ()); - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); - return GNUNET_SYSERR; - } - return GNUNET_OK; - -#else - /* not MINGW */ - int flags = fcntl (fd->fd, F_GETFL); - if (flags == -1) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); - return GNUNET_SYSERR; - } - if (doBlock) - flags &= ~O_NONBLOCK; - else - flags |= O_NONBLOCK; - if (0 != fcntl (fd->fd, F_SETFL, flags)) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); - return GNUNET_SYSERR; - } - return GNUNET_OK; -#endif -} - - + u_long mode; + mode = !doBlock; + if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR) + + { + SetErrnoFromWinsockError (WSAGetLastError ()); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); + return GNUNET_SYSERR; + } + return GNUNET_OK; + +#else /* */ + /* not MINGW */ + int flags = fcntl (fd->fd, F_GETFL); + if (flags == -1) + + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); + return GNUNET_SYSERR; + } + if (doBlock) + flags &= ~O_NONBLOCK; + + else + flags |= O_NONBLOCK; + if (0 != fcntl (fd->fd, F_SETFL, flags)) + + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); + return GNUNET_SYSERR; + } + return GNUNET_OK; + +#endif /* */ +} + + #ifndef MINGW /** * Make a socket non-inheritable to child processes @@ -107,62 +111,56 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, * @param h the socket to make non-inheritable * @return GNUNET_OK on success, GNUNET_SYSERR otherwise * @warning Not implemented on Windows - */ -static int -socket_set_inheritable (const struct GNUNET_NETWORK_Handle - *h) -{ - int i; - - i = fcntl (h->fd, F_GETFD); - if (i == (i | FD_CLOEXEC)) - return GNUNET_OK; - return (fcntl (h->fd, F_SETFD, i | FD_CLOEXEC) == 0) - ? GNUNET_OK : GNUNET_SYSERR; -} -#endif - - - + */ +static int +socket_set_inheritable (const struct GNUNET_NETWORK_Handle *h) +{ + int i; + i = fcntl (h->fd, F_GETFD); + if (i == (i | FD_CLOEXEC)) + return GNUNET_OK; + return (fcntl (h->fd, F_SETFD, i | FD_CLOEXEC) == 0) + ? GNUNET_OK : GNUNET_SYSERR; + } + + +#endif /* */ + #ifdef DARWIN /** * The MSG_NOSIGNAL equivalent on Mac OS X * * @param h the socket to make non-delaying - */ -static void -socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle - *h) -{ - int value = 1; - if (0 != setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value))) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, - "setsockopt"); -} -#endif - - - + */ +static void +socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h) +{ + int value = 1; + if (0 != + setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof (value))) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); + } + + +#endif /* */ + /** * Disable delays when sending data via the socket. * (GNUnet makes sure that messages are as big as * possible already). * * @param h the socket to make non-delaying - */ -static void -socket_set_nodelay (const struct GNUNET_NETWORK_Handle - *h) -{ - int value = 1; - if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value))) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, - "setsockopt"); - -} - - - + */ +static void +socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h) +{ + int value = 1; + if (0 != + setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value))) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); + } + + /** * accept a new connection on a socket * @@ -170,124 +168,142 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle * @param address address of the connecting peer, may be NULL * @param address_len length of address * @return client socket - */ + */ struct GNUNET_NETWORK_Handle * -GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, - struct sockaddr *address, - socklen_t * address_len) -{ - struct GNUNET_NETWORK_Handle *ret; - - ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); - ret->fd = accept (desc->fd, address, address_len); - if (ret->fd == INVALID_SOCKET) - { +GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, + struct sockaddr *address, + socklen_t * address_len) +{ + struct GNUNET_NETWORK_Handle *ret; + ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); + ret->fd = accept (desc->fd, address, address_len); + if (ret->fd == INVALID_SOCKET) + + { + #ifdef MINGW - SetErrnoFromWinsockError (WSAGetLastError ()); -#endif - GNUNET_free (ret); - return NULL; - } + SetErrnoFromWinsockError (WSAGetLastError ()); + +#endif /* */ + GNUNET_free (ret); + return NULL; + } + #ifndef MINGW - if (ret->fd >= FD_SETSIZE) - { - GNUNET_break (0 == close (ret->fd)); - GNUNET_free (ret); - errno = EMFILE; - return NULL; - } -#endif - if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) - { - /* we might want to treat this one as fatal... */ - GNUNET_break (0); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); - return NULL; - } + if (ret->fd >= FD_SETSIZE) + + { + GNUNET_break (0 == close (ret->fd)); + GNUNET_free (ret); + errno = EMFILE; + return NULL; + } + +#endif /* */ + if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) + + { + + /* we might want to treat this one as fatal... */ + GNUNET_break (0); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); + return NULL; + } + #ifndef MINGW - if (GNUNET_OK != socket_set_inheritable (ret)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "socket_set_inheritable"); -#endif + if (GNUNET_OK != socket_set_inheritable (ret)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "socket_set_inheritable"); + +#endif /* */ #ifdef DARWIN - socket_set_nosigpipe (ret); -#endif - socket_set_nodelay (ret); - return ret; -} - + socket_set_nosigpipe (ret); + +#endif /* */ + socket_set_nodelay (ret); + return ret; + } + + /** * Bind to a connected socket * @param desc socket * @param address address to be bound * @param address_len length of address * @return GNUNET_OK on success, GNUNET_SYSERR otherwise - */ -int -GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, - const struct sockaddr *address, - socklen_t address_len) -{ - int ret; - - ret = bind (desc->fd, address, address_len); + */ +int +GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, + const struct sockaddr *address, + socklen_t address_len) +{ + int ret; + ret = bind (desc->fd, address, address_len); + #ifdef MINGW - if (SOCKET_ERROR == ret) - SetErrnoFromWinsockError (WSAGetLastError ()); -#endif - return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; -} - - + if (SOCKET_ERROR == ret) + SetErrnoFromWinsockError (WSAGetLastError ()); + +#endif /* */ + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; + } + + /** * Close a socket * @param desc socket * @return GNUNET_OK on success, GNUNET_SYSERR otherwise - */ -int -GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) -{ - int ret; - int eno; - + */ +int +GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) +{ + int ret; + int eno; + #ifdef MINGW - ret = closesocket (desc->fd); - SetErrnoFromWinsockError (WSAGetLastError ()); -#else - ret = close (desc->fd); -#endif - eno = errno; - GNUNET_free (desc); - errno = eno; - return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; -} - + ret = closesocket (desc->fd); + SetErrnoFromWinsockError (WSAGetLastError ()); + +#else /* */ + ret = close (desc->fd); + +#endif /* */ + eno = errno; + GNUNET_free (desc); + errno = eno; + return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; + } + + /** * Connect a socket * @param desc socket * @param address peer address * @param address_len length of address * @return GNUNET_OK on success, GNUNET_SYSERR otherwise - */ -int -GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, - const struct sockaddr *address, - socklen_t address_len) -{ - int ret; - - ret = connect (desc->fd, address, address_len); + */ +int +GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, + const struct sockaddr *address, + socklen_t address_len) +{ + int ret; + ret = connect (desc->fd, address, address_len); + #ifdef MINGW - if (SOCKET_ERROR == ret) - { - SetErrnoFromWinsockError (WSAGetLastError ()); - if (errno == EWOULDBLOCK) - errno = EINPROGRESS; - } -#endif - return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; -} - + if (SOCKET_ERROR == ret) + + { + SetErrnoFromWinsockError (WSAGetLastError ()); + if (errno == EWOULDBLOCK) + errno = EINPROGRESS; + } + +#endif /* */ + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; + } + + /** * Get socket options * @@ -297,71 +313,78 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, * @param optval options * @param optlen length of optval * @return GNUNET_OK on success, GNUNET_SYSERR otherwise - */ -int -GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, - int level, int optname, void *optval, - socklen_t * optlen) -{ - int ret; - - ret = getsockopt (desc->fd, level, optname, optval, optlen); + */ +int +GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, + int level, int optname, void *optval, + socklen_t * optlen) +{ + int ret; + ret = getsockopt (desc->fd, level, optname, optval, optlen); + #ifdef MINGW - if (ret == 0 && level == SOL_SOCKET && optname == SO_ERROR) - *((int *) optval) = GetErrnoFromWinsockError (*((int *) optval)); - else if (SOCKET_ERROR == ret) - SetErrnoFromWinsockError (WSAGetLastError ()); -#endif - return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; -} - + if (ret == 0 && level == SOL_SOCKET && optname == SO_ERROR) + *((int *) optval) = GetErrnoFromWinsockError (*((int *) optval)); + + else if (SOCKET_ERROR == ret) + SetErrnoFromWinsockError (WSAGetLastError ()); + +#endif /* */ + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; + } + + /** * Listen on a socket * @param desc socket * @param backlog length of the listen queue * @return GNUNET_OK on success, GNUNET_SYSERR otherwise - */ -int -GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, - int backlog) -{ - int ret; - - ret = listen (desc->fd, backlog); + */ +int +GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, + int backlog) +{ + int ret; + ret = listen (desc->fd, backlog); + #ifdef MINGW - if (SOCKET_ERROR == ret) - SetErrnoFromWinsockError (WSAGetLastError ()); -#endif - - return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; -} - + if (SOCKET_ERROR == ret) + SetErrnoFromWinsockError (WSAGetLastError ()); + +#endif /* */ + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; + } + + /** * Read data from a connected socket (always non-blocking). * @param desc socket * @param buffer buffer * @param length length of buffer - */ -ssize_t -GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, - void *buffer, size_t length) -{ - int ret; - int flags; - - flags = 0; + */ + ssize_t +GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, + void *buffer, size_t length) +{ + int ret; + int flags; + flags = 0; + #ifdef MSG_DONTWAIT - flags |= MSG_DONTWAIT; -#endif - ret = recv (desc->fd, buffer, length, flags); + flags |= MSG_DONTWAIT; + +#endif /* */ + ret = recv (desc->fd, buffer, length, flags); + #ifdef MINGW - if (SOCKET_ERROR == ret) - SetErrnoFromWinsockError (WSAGetLastError ()); -#endif - - return ret; -} - + if (SOCKET_ERROR == ret) + SetErrnoFromWinsockError (WSAGetLastError ()); + +#endif /* */ + return ret; + } + + /** * Send data (always non-blocking). * @@ -369,31 +392,34 @@ GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, * @param buffer data to send * @param length size of the buffer * @return number of bytes sent, GNUNET_SYSERR on error - */ -ssize_t -GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, - const void *buffer, size_t length) -{ - int ret; - int flags; - - flags = 0; + */ + ssize_t +GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, + const void *buffer, size_t length) +{ + int ret; + int flags; + flags = 0; + #ifdef MSG_DONTWAIT - flags |= MSG_DONTWAIT; -#endif + flags |= MSG_DONTWAIT; + +#endif /* */ #ifdef MSG_NOSIGNAL - flags |= MSG_NOSIGNAL; -#endif - ret = send (desc->fd, buffer, length, flags); + flags |= MSG_NOSIGNAL; + +#endif /* */ + ret = send (desc->fd, buffer, length, flags); + #ifdef MINGW - if (SOCKET_ERROR == ret) - SetErrnoFromWinsockError (WSAGetLastError ()); -#endif - - return ret; -} - - + if (SOCKET_ERROR == ret) + SetErrnoFromWinsockError (WSAGetLastError ()); + +#endif /* */ + return ret; + } + + /** * Send data to a particular destination (always non-blocking). * This function only works for UDP sockets. @@ -404,32 +430,36 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, * @param dest_addr destination address * @param dest_len length of address * @return number of bytes sent, GNUNET_SYSERR on error - */ -ssize_t -GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, - const void *message, size_t length, - const struct sockaddr * dest_addr, - socklen_t dest_len) -{ - int ret; - int flags; - - flags = 0; + */ + ssize_t +GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, + const void *message, size_t length, + const struct sockaddr * dest_addr, + socklen_t dest_len) +{ + int ret; + int flags; + flags = 0; + #ifdef MSG_DONTWAIT - flags |= MSG_DONTWAIT; -#endif + flags |= MSG_DONTWAIT; + +#endif /* */ #ifdef MSG_NOSIGNAL - flags |= MSG_NOSIGNAL; -#endif - ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len); + flags |= MSG_NOSIGNAL; + +#endif /* */ + ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len); + #ifdef MINGW - if (SOCKET_ERROR == ret) - SetErrnoFromWinsockError (WSAGetLastError ()); -#endif - - return ret; -} - + if (SOCKET_ERROR == ret) + SetErrnoFromWinsockError (WSAGetLastError ()); + +#endif /* */ + return ret; + } + + /** * Set socket option * @param fd socket @@ -438,26 +468,25 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, * @param option_value value to set * @param option_len size of option_value * @return GNUNET_OK on success, GNUNET_SYSERR otherwise - */ -int -GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, - int level, int option_name, - const void *option_value, - socklen_t option_len) -{ - int ret; - - ret = setsockopt (fd->fd, level, option_name, option_value, option_len); + */ +int +GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, + int level, int option_name, + const void *option_value, + socklen_t option_len) +{ + int ret; + ret = setsockopt (fd->fd, level, option_name, option_value, option_len); + #ifdef MINGW - if (SOCKET_ERROR == ret) - SetErrnoFromWinsockError (WSAGetLastError ()); -#endif - - return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; -} - - - + if (SOCKET_ERROR == ret) + SetErrnoFromWinsockError (WSAGetLastError ()); + +#endif /* */ + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; + } + + /** * Create a new socket. Configure it for non-blocking IO and * mark it as non-inheritable to child processes (set the @@ -467,282 +496,297 @@ GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, * @param type socket type * @param protocol network protocol * @return new socket, NULL on error - */ + */ struct GNUNET_NETWORK_Handle * -GNUNET_NETWORK_socket_create (int domain, int type, int protocol) -{ - struct GNUNET_NETWORK_Handle *ret; - - ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); - ret->fd = socket (domain, type, protocol); - if (INVALID_SOCKET == ret->fd) - { +GNUNET_NETWORK_socket_create (int domain, int type, int protocol) +{ + struct GNUNET_NETWORK_Handle *ret; + ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); + ret->fd = socket (domain, type, protocol); + if (INVALID_SOCKET == ret->fd) + + { + #ifdef MINGW - SetErrnoFromWinsockError (WSAGetLastError ()); -#endif - GNUNET_free (ret); - return NULL; - } + SetErrnoFromWinsockError (WSAGetLastError ()); + +#endif /* */ + GNUNET_free (ret); + return NULL; + } + #ifndef MINGW - if (ret->fd >= FD_SETSIZE) - { - GNUNET_break (0 == close (ret->fd)); - GNUNET_free (ret); - errno = EMFILE; - return NULL; - } -#endif - - if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) - { - /* we might want to treat this one as fatal... */ - GNUNET_break (0); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); - return NULL; - } + if (ret->fd >= FD_SETSIZE) + + { + GNUNET_break (0 == close (ret->fd)); + GNUNET_free (ret); + errno = EMFILE; + return NULL; + } + +#endif /* */ + if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) + + { + + /* we might want to treat this one as fatal... */ + GNUNET_break (0); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); + return NULL; + } + #ifndef MINGW - if (GNUNET_OK != socket_set_inheritable (ret)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "socket_set_inheritable"); -#endif + if (GNUNET_OK != socket_set_inheritable (ret)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "socket_set_inheritable"); + +#endif /* */ #ifdef DARWIN - socket_set_nosigpipe (ret); -#endif - if (type == SOCK_STREAM) - socket_set_nodelay (ret); - - return ret; -} - + socket_set_nosigpipe (ret); + +#endif /* */ + if (type == SOCK_STREAM) + socket_set_nodelay (ret); + return ret; + } + + /** * Shut down socket operations * @param desc socket * @param how type of shutdown * @return GNUNET_OK on success, GNUNET_SYSERR otherwise - */ -int -GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, - int how) -{ - int ret; - - ret = shutdown (desc->fd, how); + */ +int +GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, + int how) +{ + int ret; + ret = shutdown (desc->fd, how); + #ifdef MINGW - if (ret != 0) - SetErrnoFromWinsockError (WSAGetLastError ()); -#endif - - return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; -} - - + if (ret != 0) + SetErrnoFromWinsockError (WSAGetLastError ()); + +#endif /* */ + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; + } + + /** * Reset FD set * @param fds fd set - */ -void -GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds) -{ - FD_ZERO (&fds->sds); - fds->nsds = 0; + */ +void +GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds) +{ + FD_ZERO (&fds->sds); + fds->nsds = 0; + #ifdef MINGW - GNUNET_CONTAINER_slist_clear (fds->handles); -#endif -} - - + GNUNET_CONTAINER_slist_clear (fds->handles); + +#endif /* */ +} + /** * Add a socket to the FD set * @param fds fd set * @param desc socket to add - */ -void -GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, - const struct GNUNET_NETWORK_Handle *desc) -{ - FD_SET (desc->fd, &fds->sds); - - if (desc->fd + 1 > fds->nsds) - fds->nsds = desc->fd + 1; -} - - + */ +void +GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, + const struct GNUNET_NETWORK_Handle *desc) +{ + FD_SET (desc->fd, &fds->sds); + if (desc->fd + 1 > fds->nsds) + fds->nsds = desc->fd + 1; + } + + /** * Check whether a socket is part of the fd set * @param fds fd set * @param desc socket * @return 0 if the FD is not set - */ -int -GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, - const struct GNUNET_NETWORK_Handle *desc) -{ - return FD_ISSET (desc->fd, &fds->sds); -} - - + */ +int +GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, + const struct GNUNET_NETWORK_Handle *desc) +{ + return FD_ISSET (desc->fd, &fds->sds); + } + + /** * Add one fd set to another * @param dst the fd set to add to * @param src the fd set to add from - */ -void -GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, - const struct GNUNET_NETWORK_FDSet *src) -{ - int nfds; - - for (nfds = src->nsds; nfds > 0; nfds--) - if (FD_ISSET (nfds, &src->sds)) - { - FD_SET (nfds, &dst->sds); - if (nfds + 1 > dst->nsds) - dst->nsds = nfds + 1; - } -} - - + */ +void +GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, + const struct GNUNET_NETWORK_FDSet *src) +{ + int nfds; + for (nfds = src->nsds; nfds > 0; nfds--) + if (FD_ISSET (nfds, &src->sds)) + + { + FD_SET (nfds, &dst->sds); + if (nfds + 1 > dst->nsds) + dst->nsds = nfds + 1; + } + } + + /** * Copy one fd set to another * @param to destination * @param from source - */ -void -GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, - const struct GNUNET_NETWORK_FDSet *from) -{ - FD_COPY (&from->sds, &to->sds); - to->nsds = from->nsds; + */ +void +GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, + const struct GNUNET_NETWORK_FDSet *from) +{ + FD_COPY (&from->sds, &to->sds); + to->nsds = from->nsds; + #ifdef MINGW - struct GNUNET_CONTAINER_SList_Iterator *iter; - - - GNUNET_CONTAINER_slist_clear (to->handles); - - for (iter = GNUNET_CONTAINER_slist_begin (from->handles); - GNUNET_CONTAINER_slist_end (iter) != GNUNET_YES; GNUNET_CONTAINER_slist_next (iter)) - { - void *handle; - size_t len; - - handle = GNUNET_CONTAINER_slist_get (iter, &len); - GNUNET_CONTAINER_slist_add (to->handles, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, handle, len); - } -#endif -} - - + struct GNUNET_CONTAINER_SList_Iterator *iter; + GNUNET_CONTAINER_slist_clear (to->handles); + for (iter = GNUNET_CONTAINER_slist_begin (from->handles); + GNUNET_CONTAINER_slist_end (iter) != GNUNET_YES; + GNUNET_CONTAINER_slist_next (iter)) + + { + void *handle; + size_t len; + handle = GNUNET_CONTAINER_slist_get (iter, &len); + GNUNET_CONTAINER_slist_add (to->handles, + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + handle, len); + } +#endif /* */ +} + /** * Copy a native fd set * @param to destination * @param from native source set * @param nfds the biggest socket number in from + 1 - */ -void -GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, - const fd_set * from, int nfds) -{ - FD_COPY (from, &to->sds); - to->nsds = nfds; -} - - + */ +void +GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, + const fd_set * from, int nfds) +{ + FD_COPY (from, &to->sds); + to->nsds = nfds; + } + /** * Add a file handle to the fd set * @param fds fd set * @param h the file handle to add - */ -void -GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, - const struct GNUNET_DISK_FileHandle *h) -{ + */ +void +GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, + const struct GNUNET_DISK_FileHandle *h) +{ + #ifdef MINGW - HANDLE hw; - - GNUNET_DISK_internal_file_handle_ (h, &hw, sizeof (HANDLE)); - GNUNET_CONTAINER_slist_add (fds->handles, GNUNET_NO, &hw, sizeof (HANDLE)); -#else - int fd; - - GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int)); - FD_SET (fd, &fds->sds); - if (fd + 1 > fds->nsds) - fds->nsds = fd + 1; -#endif -} - + HANDLE hw; + GNUNET_DISK_internal_file_handle_ (h, &hw, sizeof (HANDLE)); + GNUNET_CONTAINER_slist_add (fds->handles, GNUNET_NO, &hw, sizeof (HANDLE)); + +#else /* */ + int fd; + GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int)); + FD_SET (fd, &fds->sds); + if (fd + 1 > fds->nsds) + fds->nsds = fd + 1; + +#endif /* */ +} + + /** * Check if a file handle is part of an fd set * @param fds fd set * @param h file handle * @return GNUNET_YES if the file handle is part of the set - */ -int -GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, - const struct GNUNET_DISK_FileHandle *h) -{ + */ +int +GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, + const struct GNUNET_DISK_FileHandle *h) +{ + #ifdef MINGW - return GNUNET_CONTAINER_slist_contains (fds->handles, h->h, sizeof (HANDLE)); -#else - return FD_ISSET (h->fd, &fds->sds); -#endif -} - + return GNUNET_CONTAINER_slist_contains (fds->handles, h->h, + sizeof (HANDLE)); + +#else /* */ + return FD_ISSET (h->fd, &fds->sds); + +#endif /* */ +} + + /** * Checks if two fd sets overlap * @param fds1 first fd set * @param fds2 second fd set * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise - */ -int -GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, - const struct GNUNET_NETWORK_FDSet *fds2) -{ - int nfds; - - nfds = fds1->nsds; - if (nfds < fds2->nsds) - nfds = fds2->nsds; - - for (; nfds >= 0; nfds--) - if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) - return GNUNET_YES; - - return GNUNET_NO; -} - + */ +int +GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, + const struct GNUNET_NETWORK_FDSet *fds2) +{ + int nfds; + nfds = fds1->nsds; + if (nfds < fds2->nsds) + nfds = fds2->nsds; + for (; nfds >= 0; nfds--) + if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) + return GNUNET_YES; + return GNUNET_NO; + } + + /** * Creates an fd set * @return a new fd set - */ + */ struct GNUNET_NETWORK_FDSet * -GNUNET_NETWORK_fdset_create () -{ - struct GNUNET_NETWORK_FDSet *fds; - - fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet)); +GNUNET_NETWORK_fdset_create () +{ + struct GNUNET_NETWORK_FDSet *fds; + fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet)); + #ifdef MINGW - fds->handles = GNUNET_CONTAINER_slist_create (); -#endif - GNUNET_NETWORK_fdset_zero (fds); - return fds; -} - - + fds->handles = GNUNET_CONTAINER_slist_create (); + +#endif /* */ + GNUNET_NETWORK_fdset_zero (fds); + return fds; + } + + /** * Releases the associated memory of an fd set * @param fds fd set - */ -void -GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) -{ + */ +void +GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) +{ + #ifdef MINGW - GNUNET_CONTAINER_slist_destroy (fds->handles); -#endif - GNUNET_free (fds); -} - - + GNUNET_CONTAINER_slist_destroy (fds->handles); + +#endif /* */ + GNUNET_free (fds); + } + /** * Check if sockets meet certain conditions * @param rfds set of sockets to be checked for readability @@ -750,249 +794,259 @@ GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) * @param efds set of sockets to be checked for exceptions * @param timeout relative value when to return * @return number of selected sockets, GNUNET_SYSERR on error - */ -int -GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, - struct GNUNET_NETWORK_FDSet *wfds, - struct GNUNET_NETWORK_FDSet *efds, - const struct GNUNET_TIME_Relative timeout) -{ - int nfds; - - nfds = 0; - if (NULL != rfds) - nfds = rfds->nsds; - if (NULL != wfds) - nfds = GNUNET_MAX (nfds, wfds->nsds); - if (NULL != efds) - nfds = GNUNET_MAX (nfds, efds->nsds); - + */ +int +GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, + struct GNUNET_NETWORK_FDSet *wfds, + struct GNUNET_NETWORK_FDSet *efds, + const struct GNUNET_TIME_Relative timeout) +{ + int nfds; + nfds = 0; + if (NULL != rfds) + nfds = rfds->nsds; + if (NULL != wfds) + nfds = GNUNET_MAX (nfds, wfds->nsds); + if (NULL != efds) + nfds = GNUNET_MAX (nfds, efds->nsds); + #ifndef MINGW - struct timeval tv; - - tv.tv_sec = timeout.value / GNUNET_TIME_UNIT_SECONDS.value; - tv.tv_usec = 1000 * (timeout.value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.value)); - if ( (nfds == 0) && - (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), - "select"); - GNUNET_break (0); - } - return select (nfds + 1, - (rfds != NULL) ? &rfds->sds : NULL, - (wfds != NULL) ? &wfds->sds : NULL, - (efds != NULL) ? &efds->sds : NULL, - (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value) - ? NULL - : &tv); -#else - DWORD limit; - fd_set sock_read, sock_write, sock_except; - fd_set aread, awrite, aexcept; - int i; - struct timeval tvslice; - int retcode; - DWORD ms_total; - + struct timeval tv; + tv.tv_sec = timeout.value / GNUNET_TIME_UNIT_SECONDS.value; + tv.tv_usec = + 1000 * (timeout.value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.value)); + if ((nfds == 0) && (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)) + + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ + ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), + "select"); + GNUNET_break (0); + } + return select (nfds + 1, + (rfds != NULL) ? &rfds->sds : NULL, + (wfds != NULL) ? &wfds->sds : NULL, + (efds != NULL) ? &efds->sds : NULL, + (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value) + ? NULL : &tv); + +#else /* */ + DWORD limit; + fd_set sock_read, sock_write, sock_except; + fd_set aread, awrite, aexcept; + int i; + struct timeval tvslice; + int retcode; + DWORD ms_total; + #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) - - /* calculate how long we need to wait in milliseconds */ - if (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value) - ms_total = INFINITE; - else - ms_total = timeout.value / GNUNET_TIME_UNIT_MILLISECONDS.value; - - /* select() may be used as a portable way to sleep */ - if (!(rfds || wfds || efds)) - { - Sleep (ms_total); - return 0; - } - - if (rfds) - sock_read = rfds->sds; - else - FD_ZERO(&sock_read); - - if (wfds) - sock_write = wfds->sds; - else - FD_ZERO(&sock_write); - - if (efds) - sock_except = efds->sds; - else - FD_ZERO(&sock_except); - - /* multiplex between winsock select() and waiting on the handles */ - - FD_ZERO (&aread); - FD_ZERO (&awrite); - FD_ZERO (&aexcept); - - limit = GetTickCount () + ms_total; - do - { - retcode = 0; - - if (nfds > 0) - { - /* overwrite the zero'd sets here; the select call - * will clear those that are not active */ - - FD_COPY (&sock_read, &aread); - FD_COPY (&sock_write, &awrite); - FD_COPY (&sock_except, &aexcept); - - tvslice.tv_sec = 0; - tvslice.tv_usec = 100000; - - if ((retcode = - select (nfds + 1, &aread, &awrite, &aexcept, - &tvslice)) == SOCKET_ERROR) - { - SetErrnoFromWinsockError (WSAGetLastError ()); - if (errno == ENOTSOCK) - errno = EBADF; - + + /* calculate how long we need to wait in milliseconds */ + if (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value) + ms_total = INFINITE; + + else + ms_total = timeout.value / GNUNET_TIME_UNIT_MILLISECONDS.value; + + /* select() may be used as a portable way to sleep */ + if (!(rfds || wfds || efds)) + + { + Sleep (ms_total); + return 0; + } + if (rfds) + sock_read = rfds->sds; + + else + FD_ZERO (&sock_read); + if (wfds) + sock_write = wfds->sds; + + else + FD_ZERO (&sock_write); + if (efds) + sock_except = efds->sds; + + else + FD_ZERO (&sock_except); + + /* multiplex between winsock select() and waiting on the handles */ + FD_ZERO (&aread); + FD_ZERO (&awrite); + FD_ZERO (&aexcept); + limit = GetTickCount () + ms_total; + + do + + { + retcode = 0; + if (nfds > 0) + + { + + /* overwrite the zero'd sets here; the select call + * will clear those that are not active */ + FD_COPY (&sock_read, &aread); + FD_COPY (&sock_write, &awrite); + FD_COPY (&sock_except, &aexcept); + tvslice.tv_sec = 0; + tvslice.tv_usec = 100000; + if ((retcode = + select (nfds + 1, &aread, &awrite, &aexcept, + &tvslice)) == SOCKET_ERROR) + + { + SetErrnoFromWinsockError (WSAGetLastError ()); + if (errno == ENOTSOCK) + errno = EBADF; + #if DEBUG_NETWORK - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select"); -#endif - - goto select_loop_end; - } - } - - /* Poll read pipes */ - if (rfds) - { - struct GNUNET_CONTAINER_SList_Iterator *i; - int on_next; - - on_next = GNUNET_NO; - for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); - GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; - on_next || GNUNET_CONTAINER_slist_next (i)) - { - HANDLE h; - DWORD dwBytes; - - h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL); - on_next = GNUNET_NO; - - if (!PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL)) - { - GNUNET_CONTAINER_slist_erase (i); - on_next = GNUNET_YES; - - retcode = -1; - SetErrnoFromWinError (GetLastError ()); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select"); + +#endif /* */ + goto select_loop_end; + } + } + + /* Poll read pipes */ + if (rfds) + + { + struct GNUNET_CONTAINER_SList_Iterator *i; + int on_next; + on_next = GNUNET_NO; + for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); + GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; + on_next || GNUNET_CONTAINER_slist_next (i)) + + { + HANDLE h; + DWORD dwBytes; + h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL); + on_next = GNUNET_NO; + if (!PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL)) + + { + GNUNET_CONTAINER_slist_erase (i); + on_next = GNUNET_YES; + retcode = -1; + SetErrnoFromWinError (GetLastError ()); + #if DEBUG_NETWORK - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "PeekNamedPipe"); -#endif - goto select_loop_end; - } - else if (dwBytes) - { - retcode++; - } - else - { - GNUNET_CONTAINER_slist_erase (i); - on_next = GNUNET_YES; - } - } - } - - /* Poll for faulty pipes */ - if (efds) - { - struct GNUNET_CONTAINER_SList_Iterator *i; - int on_next; - - on_next = GNUNET_NO; - for (i = GNUNET_CONTAINER_slist_begin (efds->handles); - GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; - on_next || GNUNET_CONTAINER_slist_next (i)) - { - HANDLE h; - DWORD dwBytes; - - h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL); - - if (PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL)) - { - GNUNET_CONTAINER_slist_erase (i); - on_next = GNUNET_YES; - - retcode++; - } - else - on_next = GNUNET_NO; - } - } - - /* FIXME */ - if (wfds) - GNUNET_assert (GNUNET_CONTAINER_slist_count (wfds->handles) == 0); - - /* Check for closed sockets */ - for (i = 0; i < nfds; i++) - { - if (SAFE_FD_ISSET (i, &sock_read)) - { - struct sockaddr addr; - int len; - - if (getpeername (i, &addr, &len) == SOCKET_ERROR) - { - int err, len; - - len = sizeof (err); - if (getsockopt - (i, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == 0 - && err == WSAENOTCONN) - { - if (!SAFE_FD_ISSET (i, &aread)) - { - FD_SET (i, &aread); - retcode++; - } - } - } - } - } - - select_loop_end:; - } - while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit)); - - if (retcode != -1) - { - if (rfds) - { - GNUNET_NETWORK_fdset_zero (rfds); - GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); - } - - if (wfds) - { - GNUNET_NETWORK_fdset_zero (wfds); - GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); - } - - if (efds) - { - GNUNET_NETWORK_fdset_zero (efds); - GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); - } - } - - return retcode; -#endif -} - - -/* end of network.c */ + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, + "PeekNamedPipe"); + +#endif /* */ + goto select_loop_end; + } + + else if (dwBytes) + + { + retcode++; + } + + else + + { + GNUNET_CONTAINER_slist_erase (i); + on_next = GNUNET_YES; + } + } + } + + /* Poll for faulty pipes */ + if (efds) + + { + struct GNUNET_CONTAINER_SList_Iterator *i; + int on_next; + on_next = GNUNET_NO; + for (i = GNUNET_CONTAINER_slist_begin (efds->handles); + GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; + on_next || GNUNET_CONTAINER_slist_next (i)) + + { + HANDLE h; + DWORD dwBytes; + h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL); + if (PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL)) + + { + GNUNET_CONTAINER_slist_erase (i); + on_next = GNUNET_YES; + retcode++; + } + + else + on_next = GNUNET_NO; + } + } + + /* FIXME */ + if (wfds) + GNUNET_assert (GNUNET_CONTAINER_slist_count (wfds->handles) == 0); + + /* Check for closed sockets */ + for (i = 0; i < nfds; i++) + + { + if (SAFE_FD_ISSET (i, &sock_read)) + + { + struct sockaddr addr; + int len; + if (getpeername (i, &addr, &len) == SOCKET_ERROR) + + { + int err, len; + len = sizeof (err); + if (getsockopt + (i, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == 0 + &&err == WSAENOTCONN) + + { + if (!SAFE_FD_ISSET (i, &aread)) + + { + FD_SET (i, &aread); + retcode++; + } + } + } + } + } + select_loop_end:; + } + while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit)); + if (retcode != -1) + + { + if (rfds) + + { + GNUNET_NETWORK_fdset_zero (rfds); + GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); + } + if (wfds) + + { + GNUNET_NETWORK_fdset_zero (wfds); + GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); + } + if (efds) + + { + GNUNET_NETWORK_fdset_zero (efds); + GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); + } + } + return retcode; + +#endif /* */ +} + + +/* end of network.c */ diff --git a/src/util/os_installation.c b/src/util/os_installation.c index afb8c2474..7079e2fef 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c @@ -298,8 +298,9 @@ os_get_gnunet_path () return ret; /* other attempts here */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Could not determine installation path for GNUnet. Set `%s' environment variable.\n"), - "GNUNET_PREFIX"); + _ + ("Could not determine installation path for GNUnet. Set `%s' environment variable.\n"), + "GNUNET_PREFIX"); return NULL; } diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 4c77704bf..cb04428d3 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c @@ -141,23 +141,23 @@ GNUNET_OS_start_process (const char *filename, ...) if (ret != 0) { if (ret == -1) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); + } else - { + { #if HAVE_WORKING_VFORK - /* let's hope vfork actually works; for some extreme cases (including - a testcase) we need 'execvp' to have run before we return, since - we may send a signal to the process next and we don't want it - to be caught by OUR signal handler (but either by the default - handler or the actual handler as installed by the process itself). */ + /* let's hope vfork actually works; for some extreme cases (including + a testcase) we need 'execvp' to have run before we return, since + we may send a signal to the process next and we don't want it + to be caught by OUR signal handler (but either by the default + handler or the actual handler as installed by the process itself). */ #else - /* let's give the child process a chance to run execvp, 1s should - be plenty in practice */ - sleep (1); + /* let's give the child process a chance to run execvp, 1s should + be plenty in practice */ + sleep (1); #endif - } + } return ret; } argc = 0; @@ -184,29 +184,30 @@ GNUNET_OS_start_process (const char *filename, ...) cmdlen = 0; va_start (ap, filename); while (NULL != (arg = va_arg (ap, char *))) - cmdlen = cmdlen + strlen (arg) + 3; + cmdlen = cmdlen + strlen (arg) + 3; va_end (ap); - cmd = idx = GNUNET_malloc (sizeof(char) * cmdlen); + cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen); va_start (ap, filename); while (NULL != (arg = va_arg (ap, char *))) - idx += sprintf (idx, "\"%s\" ", arg); + idx += sprintf (idx, "\"%s\" ", arg); va_end (ap); - memset (&start, 0, sizeof(start)); - start.cb = sizeof(start); + memset (&start, 0, sizeof (start)); + start.cb = sizeof (start); - if (!CreateProcess (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, - NULL, &start, &proc)) - { - SetErrnoFromWinError (GetLastError ()); - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); - return -1; - } + if (!CreateProcess + (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start, + &proc)) + { + SetErrnoFromWinError (GetLastError ()); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); + return -1; + } CloseHandle (proc.hProcess); CloseHandle (proc.hThread); - GNUNET_free(cmd); + GNUNET_free (cmd); return proc.dwProcessId; #endif @@ -236,23 +237,23 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[]) if (ret != 0) { if (ret == -1) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); + } else - { + { #if HAVE_WORKING_VFORK - /* let's hope vfork actually works; for some extreme cases (including - a testcase) we need 'execvp' to have run before we return, since - we may send a signal to the process next and we don't want it - to be caught by OUR signal handler (but either by the default - handler or the actual handler as installed by the process itself). */ + /* let's hope vfork actually works; for some extreme cases (including + a testcase) we need 'execvp' to have run before we return, since + we may send a signal to the process next and we don't want it + to be caught by OUR signal handler (but either by the default + handler or the actual handler as installed by the process itself). */ #else - /* let's give the child process a chance to run execvp, 1s should - be plenty in practice */ - sleep (1); + /* let's give the child process a chance to run execvp, 1s should + be plenty in practice */ + sleep (1); #endif - } + } return ret; } execvp (filename, argv); @@ -268,33 +269,34 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[]) cmdlen = 0; arg = argv; while (*arg) - { - cmdlen = cmdlen + strlen (*arg) + 3; - arg++; - } + { + cmdlen = cmdlen + strlen (*arg) + 3; + arg++; + } - cmd = idx = GNUNET_malloc (sizeof(char) * cmdlen); + cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen); arg = argv; while (*arg) - { - idx += sprintf (idx, "\"%s\" ", *arg); - arg++; - } - - memset (&start, 0, sizeof(start)); - start.cb = sizeof(start); - - if (!CreateProcess (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, - NULL, &start, &proc)) - { - SetErrnoFromWinError (GetLastError ()); - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); - return -1; - } + { + idx += sprintf (idx, "\"%s\" ", *arg); + arg++; + } + + memset (&start, 0, sizeof (start)); + start.cb = sizeof (start); + + if (!CreateProcess + (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start, + &proc)) + { + SetErrnoFromWinError (GetLastError ()); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); + return -1; + } CloseHandle (proc.hProcess); CloseHandle (proc.hThread); - GNUNET_free(cmd); + GNUNET_free (cmd); return proc.dwProcessId; #endif @@ -309,7 +311,7 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[]) */ int GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, - unsigned long *code) + unsigned long *code) { #ifndef MINGW int status; @@ -317,7 +319,7 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, GNUNET_assert (0 != proc); ret = waitpid (proc, &status, WNOHANG); - if (0 == ret) + if (0 == ret) { *type = GNUNET_OS_PROCESS_RUNNING; *code = 0; @@ -329,50 +331,50 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, return GNUNET_SYSERR; } if (WIFEXITED (status)) - { - *type = GNUNET_OS_PROCESS_EXITED; - *code = WEXITSTATUS (status); - } + { + *type = GNUNET_OS_PROCESS_EXITED; + *code = WEXITSTATUS (status); + } else if (WIFSIGNALED (status)) - { - *type = GNUNET_OS_PROCESS_SIGNALED; - *code = WTERMSIG (status); - } + { + *type = GNUNET_OS_PROCESS_SIGNALED; + *code = WTERMSIG (status); + } else if (WIFSTOPPED (status)) - { - *type = GNUNET_OS_PROCESS_SIGNALED; - *code = WSTOPSIG (status); - } + { + *type = GNUNET_OS_PROCESS_SIGNALED; + *code = WSTOPSIG (status); + } else if (WIFCONTINUED (status)) - { - *type = GNUNET_OS_PROCESS_RUNNING; - *code = 0; - } + { + *type = GNUNET_OS_PROCESS_RUNNING; + *code = 0; + } else - { - *type = GNUNET_OS_PROCESS_UNKNOWN; - *code = 0; - } + { + *type = GNUNET_OS_PROCESS_UNKNOWN; + *code = 0; + } #else HANDLE h; DWORD c; h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc); if (INVALID_HANDLE_VALUE == h) - { - SetErrnoFromWinError (GetLastError ()); - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "OpenProcess"); - return GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "OpenProcess"); + return GNUNET_SYSERR; + } c = GetExitCodeProcess (proc, &c); if (STILL_ACTIVE == c) - { - *type = GNUNET_OS_PROCESS_RUNNING; - *code = 0; - CloseHandle (h); - return GNUNET_NO; - } + { + *type = GNUNET_OS_PROCESS_RUNNING; + *code = 0; + CloseHandle (h); + return GNUNET_NO; + } *type = GNUNET_OS_PROCESS_EXITED; *code = c; CloseHandle (h); @@ -401,16 +403,16 @@ GNUNET_OS_process_wait (pid_t proc) h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc); if (INVALID_HANDLE_VALUE == h) - { - SetErrnoFromWinError (GetLastError ()); - return GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + return GNUNET_SYSERR; + } if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE)) - { - SetErrnoFromWinError (GetLastError ()); - ret = GNUNET_SYSERR; - } + { + SetErrnoFromWinError (GetLastError ()); + ret = GNUNET_SYSERR; + } else ret = GNUNET_OK; diff --git a/src/util/peer.c b/src/util/peer.c index acb1b3922..2ad4b3d67 100644 --- a/src/util/peer.c +++ b/src/util/peer.c @@ -83,7 +83,7 @@ static unsigned int free_list_start; * @return the interned identity. */ GNUNET_PEER_Id -GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) +GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) { GNUNET_PEER_Id ret; struct PeerEntry *e; @@ -93,8 +93,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) return 0; if (NULL == map) map = GNUNET_CONTAINER_multihashmap_create (32); - e = GNUNET_CONTAINER_multihashmap_get (map, - &pid->hashPubKey); + e = GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); if (e != NULL) { GNUNET_assert (e->rc > 0); @@ -105,8 +104,8 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) if (ret == size) { GNUNET_array_grow (table, size, size + 16); - for (i=ret;ihashPubKey, - &table[ret], - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + &pid->hashPubKey, + &table[ret], + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); return ret; } @@ -135,8 +134,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) * @param count size of the ids array */ void -GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, - unsigned int count) +GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count) { int i; GNUNET_PEER_Id id; @@ -150,13 +148,13 @@ GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, GNUNET_assert (table[id].rc > 0); table[id].rc--; if (table[id].rc == 0) - { - GNUNET_CONTAINER_multihashmap_remove (map, - &table[id].id.hashPubKey, - &table[id]); - table[id].pid = free_list_start; - free_list_start = id; - } + { + GNUNET_CONTAINER_multihashmap_remove (map, + &table[id].id.hashPubKey, + &table[id]); + table[id].pid = free_list_start; + free_list_start = id; + } } } @@ -179,8 +177,8 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta) if (table[id].rc == 0) { GNUNET_CONTAINER_multihashmap_remove (map, - &table[id].id.hashPubKey, - &table[id]); + &table[id].id.hashPubKey, + &table[id]); table[id].pid = free_list_start; free_list_start = id; } @@ -194,8 +192,7 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta) * @param pid where to write the normal peer identity */ void -GNUNET_PEER_resolve (GNUNET_PEER_Id id, - struct GNUNET_PeerIdentity * pid) +GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid) { if (id == 0) { diff --git a/src/util/perf_crypto_hash.c b/src/util/perf_crypto_hash.c index 76ba24be0..6e505b807 100644 --- a/src/util/perf_crypto_hash.c +++ b/src/util/perf_crypto_hash.c @@ -57,7 +57,8 @@ main (int argc, char *argv[]) start = GNUNET_TIME_absolute_get (); perfHash (); printf ("Hash perf took %llu ms\n", - (unsigned long long) GNUNET_TIME_absolute_get_duration (start).value); + (unsigned long long) GNUNET_TIME_absolute_get_duration (start). + value); return 0; } diff --git a/src/util/program.c b/src/util/program.c index aa272ea96..695a6f9bc 100644 --- a/src/util/program.c +++ b/src/util/program.c @@ -89,10 +89,10 @@ program_main (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * @param a2 second command line option */ static int -cmd_sorter (const void *a1, const void *a2) +cmd_sorter (__const void *a1, __const void *a2) { - const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; - const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; + __const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; + __const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; if (toupper (c1->shortName) > toupper (c2->shortName)) return 1; if (toupper (c1->shortName) < toupper (c2->shortName)) @@ -174,7 +174,7 @@ GNUNET_PROGRAM_run (int argc, qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), &cmd_sorter); loglev = GNUNET_strdup ("WARNING"); - if ((-1 == (ret = GNUNET_GETOPT_run (binaryName, + if ((-1 == (ret = GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) || ((GNUNET_OK != diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c index bf746c66b..0465b1b2c 100644 --- a/src/util/pseudonym.c +++ b/src/util/pseudonym.c @@ -193,7 +193,7 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg, tag += off; } buf = GNUNET_malloc (tag); - ((int32_t *) buf)[0] = htonl (ranking); /* ranking */ + ((int32_t *) buf)[0] = htonl (ranking); /* ranking */ if (ns_name != NULL) { memcpy (&buf[sizeof (int32_t)], ns_name, off + 1); @@ -211,7 +211,8 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)); GNUNET_break (tag == GNUNET_DISK_fn_write (fn, buf, tag, GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_READ)); + | GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ)); GNUNET_free (fn); GNUNET_free (buf); /* create entry for pseudonym name in names */ @@ -365,8 +366,9 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg, if (0 == STAT (fn, &sbuf)) GNUNET_DISK_file_size (fn, &len, GNUNET_YES); fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE - | GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE); + | GNUNET_DISK_OPEN_READWRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); i = 0; idx = -1; while ((len >= sizeof (GNUNET_HashCode)) && @@ -437,11 +439,14 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, return GNUNET_SYSERR; } fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE - | GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE); + | GNUNET_DISK_OPEN_READWRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); GNUNET_free (fn); - GNUNET_DISK_file_seek (fh, idx * sizeof (GNUNET_HashCode), GNUNET_DISK_SEEK_SET); - if (sizeof (GNUNET_HashCode) != GNUNET_DISK_file_read (fh, nsid, sizeof (GNUNET_HashCode))) + GNUNET_DISK_file_seek (fh, idx * sizeof (GNUNET_HashCode), + GNUNET_DISK_SEEK_SET); + if (sizeof (GNUNET_HashCode) != + GNUNET_DISK_file_read (fh, nsid, sizeof (GNUNET_HashCode))) { GNUNET_DISK_file_close (fh); return GNUNET_SYSERR; @@ -462,12 +467,12 @@ struct ListPseudonymClosure * FIXME */ GNUNET_PSEUDONYM_Iterator iterator; - + /** * FIXME */ void *closure; - + /** * FIXME */ @@ -575,9 +580,7 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param data value of entry to insert */ static int -merge_meta_helper (void *cls, - EXTRACTOR_KeywordType type, - const char *data) +merge_meta_helper (void *cls, EXTRACTOR_KeywordType type, const char *data) { struct GNUNET_CONTAINER_MetaData *meta = cls; GNUNET_CONTAINER_meta_data_insert (meta, type, data); diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index c32fc58fa..69d143bc1 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c @@ -100,7 +100,7 @@ struct GNUNET_RESOLVER_RequestHandle /** * Desired address family. - */ + */ int domain; /** @@ -123,35 +123,30 @@ check_config (const struct GNUNET_CONFIGURATION_Handle *cfg) struct sockaddr_in v4; struct sockaddr_in6 v6; - memset (&v4, 0, sizeof(v4)); - v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); + memset (&v4, 0, sizeof (v4)); + v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); v4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - v4.sin_len = sizeof(v4); + v4.sin_len = sizeof (v4); #endif - memset (&v6, 0, sizeof(v6)); + memset (&v6, 0, sizeof (v6)); v6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN - v6.sin6_len = sizeof(v6); + v6.sin6_len = sizeof (v6); #endif if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, - "resolver", - "HOSTNAME", - &hostname)) + "resolver", + "HOSTNAME", &hostname)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Must specify `%s' for `%s' in configuration!\n"), - "HOSTNAME", - "resolver"); + _("Must specify `%s' for `%s' in configuration!\n"), + "HOSTNAME", "resolver"); GNUNET_assert (0); } - if ( (1 != inet_pton (AF_INET, - hostname, - &v4)) || - (1 != inet_pton (AF_INET6, - hostname, - &v6)) ) + if ((1 != inet_pton (AF_INET, + hostname, + &v4)) || (1 != inet_pton (AF_INET6, hostname, &v6))) { GNUNET_free (hostname); return; @@ -160,16 +155,15 @@ check_config (const struct GNUNET_CONFIGURATION_Handle *cfg) while (loopback[i] != NULL) if (0 == strcasecmp (loopback[i++], hostname)) { - GNUNET_free (hostname); - return; + GNUNET_free (hostname); + return; } GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"), - "localhost", - "HOSTNAME", - "resolver"); - GNUNET_free (hostname); - GNUNET_assert (0); + _ + ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"), + "localhost", "HOSTNAME", "resolver"); + GNUNET_free (hostname); + GNUNET_assert (0); } @@ -274,9 +268,7 @@ handle_address_response (void *cls, const struct GNUNET_MessageHeader *msg) #if DEBUG_RESOLVER { char *ips = no_resolve (sa, salen); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Resolver returns `%s'.\n", - ips); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s'.\n", ips); GNUNET_free (ips); } #endif @@ -297,54 +289,42 @@ handle_address_response (void *cls, const struct GNUNET_MessageHeader *msg) * @param tc unused scheduler context */ static void -numeric_resolution (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_RESOLVER_RequestHandle *rh = cls; struct sockaddr_in v4; struct sockaddr_in6 v6; - memset (&v4, 0, sizeof(v4)); + memset (&v4, 0, sizeof (v4)); v4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - v4.sin_len = sizeof(v4); + v4.sin_len = sizeof (v4); #endif - memset (&v6, 0, sizeof(v6)); + memset (&v6, 0, sizeof (v6)); v6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN - v6.sin6_len = sizeof(v6); + v6.sin6_len = sizeof (v6); #endif - if ( ( (rh->domain == AF_UNSPEC) || (rh->domain == AF_INET) ) && - (1 == inet_pton (AF_INET, - rh->hostname, - &v4.sin_addr)) ) + if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) && + (1 == inet_pton (AF_INET, rh->hostname, &v4.sin_addr))) { - rh->addr_callback (rh->cls, - (const struct sockaddr*) &v4, - sizeof(v4)); - if ( (rh->domain == AF_UNSPEC) && - (1 == inet_pton (AF_INET6, - rh->hostname, - &v6.sin6_addr)) ) - { - /* this can happen on some systems IF "hostname" is "localhost" */ - rh->addr_callback (rh->cls, - (const struct sockaddr*) &v6, - sizeof(v6)); - } - rh->addr_callback (rh->cls, NULL, 0); + rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); + if ((rh->domain == AF_UNSPEC) && + (1 == inet_pton (AF_INET6, rh->hostname, &v6.sin6_addr))) + { + /* this can happen on some systems IF "hostname" is "localhost" */ + rh->addr_callback (rh->cls, + (const struct sockaddr *) &v6, sizeof (v6)); + } + rh->addr_callback (rh->cls, NULL, 0); GNUNET_free (rh); return; } - if ( ( (rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6) ) && - (1 == inet_pton (AF_INET6, - rh->hostname, - &v6.sin6_addr)) ) + if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) && + (1 == inet_pton (AF_INET6, rh->hostname, &v6.sin6_addr))) { - rh->addr_callback (rh->cls, - (const struct sockaddr*) &v6, - sizeof(v6)); + rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); rh->addr_callback (rh->cls, NULL, 0); GNUNET_free (rh); return; @@ -365,44 +345,35 @@ numeric_resolution (void *cls, * @param tc unused scheduler context */ static void -loopback_resolution (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_RESOLVER_RequestHandle *rh = cls; struct sockaddr_in v4; struct sockaddr_in6 v6; - memset (&v4, 0, sizeof(v4)); - v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); + memset (&v4, 0, sizeof (v4)); + v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); v4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - v4.sin_len = sizeof(v4); + v4.sin_len = sizeof (v4); #endif - memset (&v6, 0, sizeof(v6)); + memset (&v6, 0, sizeof (v6)); v6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN - v6.sin6_len = sizeof(v6); + v6.sin6_len = sizeof (v6); #endif v6.sin6_addr = in6addr_loopback; switch (rh->domain) { case AF_INET: - rh->addr_callback (rh->cls, - (const struct sockaddr*) &v4, - sizeof(v4)); + rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); break; case AF_INET6: - rh->addr_callback (rh->cls, - (const struct sockaddr*) &v6, - sizeof(v6)); + rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); break; case AF_UNSPEC: - rh->addr_callback (rh->cls, - (const struct sockaddr*) &v6, - sizeof(v6)); - rh->addr_callback (rh->cls, - (const struct sockaddr*) &v4, - sizeof(v4)); + rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); + rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); break; default: GNUNET_break (0); @@ -431,8 +402,8 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, const char *hostname, int domain, struct GNUNET_TIME_Relative timeout, - GNUNET_RESOLVER_AddressCallback callback, - void *callback_cls) + GNUNET_RESOLVER_AddressCallback callback, + void *callback_cls) { struct GNUNET_CLIENT_Connection *client; struct GNUNET_RESOLVER_GetMessage *msg; @@ -451,32 +422,31 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, GNUNET_break (0); return NULL; } - rh = GNUNET_malloc (sizeof(struct GNUNET_RESOLVER_RequestHandle) + slen); + rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); rh->sched = sched; rh->domain = domain; rh->addr_callback = callback; rh->cls = callback_cls; memcpy (&rh[1], hostname, slen); - rh->hostname = (const char*) &rh[1]; + rh->hostname = (const char *) &rh[1]; rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); /* first, check if this is a numeric address */ - if ( ( (1 == inet_pton (AF_INET, - hostname, - &v4)) && - ( (domain == AF_INET) || (domain == AF_UNSPEC)) ) || - ( (1 == inet_pton (AF_INET6, - hostname, - &v6)) && - ( (domain == AF_INET6) || (domain == AF_UNSPEC)) ) ) + if (((1 == inet_pton (AF_INET, + hostname, + &v4)) && + ((domain == AF_INET) || (domain == AF_UNSPEC))) || + ((1 == inet_pton (AF_INET6, + hostname, + &v6)) && + ((domain == AF_INET6) || (domain == AF_UNSPEC)))) { rh->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, - &numeric_resolution, - rh); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_ZERO, + &numeric_resolution, rh); return rh; } /* then, check if this is a loopback address */ @@ -484,25 +454,24 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, while (loopback[i] != NULL) if (0 == strcasecmp (loopback[i++], hostname)) { - rh->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, - &loopback_resolution, - rh); - return rh; + rh->task = GNUNET_SCHEDULER_add_delayed (sched, + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_ZERO, + &loopback_resolution, rh); + return rh; } client = GNUNET_CLIENT_connect (sched, "resolver", cfg); if (client == NULL) { GNUNET_free (rh); - return NULL; + return NULL; } rh->client = client; - msg = (struct GNUNET_RESOLVER_GetMessage*) buf; + msg = (struct GNUNET_RESOLVER_GetMessage *) buf; msg->header.size = htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + slen); msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); @@ -517,11 +486,10 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, #endif if (GNUNET_OK != GNUNET_CLIENT_transmit_and_get_response (client, - &msg->header, - timeout, - GNUNET_YES, - &handle_address_response, - rh)) + &msg->header, + timeout, + GNUNET_YES, + &handle_address_response, rh)) { GNUNET_free (rh); GNUNET_CLIENT_disconnect (client); @@ -538,8 +506,7 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, * @param msg message with the hostname, NULL on error */ static void -handle_hostname_response (void *cls, - const struct GNUNET_MessageHeader *msg) +handle_hostname_response (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_RESOLVER_RequestHandle *rh = cls; uint16_t size; @@ -596,17 +563,14 @@ handle_hostname_response (void *cls, * @param tc unused scheduler context */ static void -numeric_reverse (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_RESOLVER_RequestHandle *rh = cls; char *result; - result = no_resolve ((const struct sockaddr*) &rh[1], - rh->salen); + result = no_resolve ((const struct sockaddr *) &rh[1], rh->salen); #if DEBUG_RESOLVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Resolver returns `%s'.\n"), result); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result); #endif if (result != NULL) { @@ -659,12 +623,11 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, if (GNUNET_NO == do_resolve) { rh->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, - &numeric_reverse, - rh); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_ZERO, + &numeric_reverse, rh); return rh; } if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) > @@ -682,7 +645,7 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, } rh->client = client; - msg = (struct GNUNET_RESOLVER_GetMessage*) buf; + msg = (struct GNUNET_RESOLVER_GetMessage *) buf; msg->header.size = htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + salen); msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); @@ -695,11 +658,10 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, #endif if (GNUNET_OK != GNUNET_CLIENT_transmit_and_get_response (client, - &msg->header, - timeout, - GNUNET_YES, - &handle_hostname_response, - rh)) + &msg->header, + timeout, + GNUNET_YES, + &handle_hostname_response, rh)) { GNUNET_CLIENT_disconnect (client); GNUNET_free (rh); @@ -722,8 +684,8 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, */ struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched, - const struct GNUNET_CONFIGURATION_Handle *cfg, - int domain, + const struct GNUNET_CONFIGURATION_Handle + *cfg, int domain, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *cls) @@ -742,7 +704,8 @@ GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched, _("Resolving our hostname `%s'\n"), hostname); #endif return GNUNET_RESOLVER_ip_get (sched, - cfg, hostname, domain, timeout, callback, cls); + cfg, hostname, domain, timeout, callback, + cls); } @@ -760,8 +723,7 @@ GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *h) if (h->client != NULL) GNUNET_CLIENT_disconnect (h->client); if (h->task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel (h->sched, - h->task); + GNUNET_SCHEDULER_cancel (h->sched, h->task); GNUNET_free (h); } diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 24ea28d2c..2bb356eb6 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c @@ -232,9 +232,9 @@ is_pending (struct GNUNET_SCHEDULER_Handle *sched, */ static void update_sets (struct GNUNET_SCHEDULER_Handle *sched, - struct GNUNET_NETWORK_FDSet * rs, - struct GNUNET_NETWORK_FDSet * ws, - struct GNUNET_TIME_Relative *timeout) + struct GNUNET_NETWORK_FDSet *rs, + struct GNUNET_NETWORK_FDSet *ws, + struct GNUNET_TIME_Relative *timeout) { struct Task *pos; @@ -254,12 +254,12 @@ update_sets (struct GNUNET_SCHEDULER_Handle *sched, to = GNUNET_TIME_absolute_get_remaining (pos->timeout); if (timeout->value > to.value) - *timeout = to; + *timeout = to; } if (pos->read_set != NULL) - GNUNET_NETWORK_fdset_add (rs, pos->read_set); + GNUNET_NETWORK_fdset_add (rs, pos->read_set); if (pos->write_set != NULL) - GNUNET_NETWORK_fdset_add (ws, pos->write_set); + GNUNET_NETWORK_fdset_add (ws, pos->write_set); pos = pos->next; } } @@ -275,8 +275,8 @@ update_sets (struct GNUNET_SCHEDULER_Handle *sched, * @return GNUNET_YES if there was some overlap */ static int -set_overlaps (const struct GNUNET_NETWORK_FDSet * ready, - struct GNUNET_NETWORK_FDSet * want) +set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, + struct GNUNET_NETWORK_FDSet *want) { if (NULL == want) return GNUNET_NO; @@ -307,7 +307,7 @@ is_ready (struct GNUNET_SCHEDULER_Handle *sched, struct Task *task, struct GNUNET_TIME_Absolute now, const struct GNUNET_NETWORK_FDSet *rs, - const struct GNUNET_NETWORK_FDSet * ws) + const struct GNUNET_NETWORK_FDSet *ws) { if ((GNUNET_NO == task->run_on_shutdown) && (GNUNET_YES == sched->shutdown)) return GNUNET_NO; @@ -341,8 +341,7 @@ is_ready (struct GNUNET_SCHEDULER_Handle *sched, * @param task task ready for execution */ static void -queue_ready_task (struct GNUNET_SCHEDULER_Handle *handle, - struct Task *task) +queue_ready_task (struct GNUNET_SCHEDULER_Handle *handle, struct Task *task) { task->next = handle->ready[check_priority (task->priority)]; handle->ready[check_priority (task->priority)] = task; @@ -360,8 +359,8 @@ queue_ready_task (struct GNUNET_SCHEDULER_Handle *handle, */ static void check_ready (struct GNUNET_SCHEDULER_Handle *handle, - const struct GNUNET_NETWORK_FDSet * rs, - const struct GNUNET_NETWORK_FDSet * ws) + const struct GNUNET_NETWORK_FDSet *rs, + const struct GNUNET_NETWORK_FDSet *ws) { struct Task *pos; struct Task *prev; @@ -375,9 +374,8 @@ check_ready (struct GNUNET_SCHEDULER_Handle *handle, { #if DEBUG_TASKS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Checking readyness of task: %llu / %p\n", - pos->id, - pos->callback_cls); + "Checking readyness of task: %llu / %p\n", + pos->id, pos->callback_cls); #endif next = pos->next; if (GNUNET_YES == is_ready (handle, pos, now, rs, ws)) @@ -401,7 +399,8 @@ check_ready (struct GNUNET_SCHEDULER_Handle *handle, * * @param t task to destroy */ -static void destroy_task (struct Task *t) +static void +destroy_task (struct Task *t) { if (NULL != t->read_set) GNUNET_NETWORK_fdset_destroy (t->read_set); @@ -452,9 +451,7 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched) pos->callback (pos->callback_cls, &tc); #if DEBUG_TASKS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Running task: %llu / %p\n", - pos->id, - pos->callback_cls); + "Running task: %llu / %p\n", pos->id, pos->callback_cls); #endif destroy_task (pos); sched->tasks_run++; @@ -477,9 +474,9 @@ sighandler_shutdown () { static char c; - GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_WRITE), - &c, - sizeof(c)); + GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle + (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c, + sizeof (c)); } @@ -537,7 +534,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls) { GNUNET_NETWORK_fdset_zero (rs); GNUNET_NETWORK_fdset_zero (ws); - timeout = GNUNET_TIME_relative_get_forever(); + timeout = GNUNET_TIME_relative_get_forever (); update_sets (&sched, rs, ws, &timeout); #ifndef MINGW GNUNET_NETWORK_fdset_handle_set (rs, pr); @@ -545,30 +542,28 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls) if (sched.ready_count > 0) { /* no blocking, more work already ready! */ - timeout = GNUNET_TIME_relative_get_zero(); + timeout = GNUNET_TIME_relative_get_zero (); } ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); #ifndef MINGW if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) - break; + break; #endif if (last_tr == sched.tasks_run) - { - busy_wait_warning++; - } + { + busy_wait_warning++; + } else - { - last_tr = sched.tasks_run; - busy_wait_warning = 0; - } - if ( (ret == 0) && - (timeout.value == 0) && - (busy_wait_warning > 16) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Looks like we're busy waiting...\n")); - sleep (1); /* mitigate */ - } + { + last_tr = sched.tasks_run; + busy_wait_warning = 0; + } + if ((ret == 0) && (timeout.value == 0) && (busy_wait_warning > 16)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Looks like we're busy waiting...\n")); + sleep (1); /* mitigate */ + } if (ret == GNUNET_SYSERR) { if (errno == EINTR) @@ -707,9 +702,7 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Handle *sched, ret = t->callback_cls; #if DEBUG_TASKS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Canceling task: %llu / %p\n", - task, - t->callback_cls); + "Canceling task: %llu / %p\n", task, t->callback_cls); #endif destroy_task (t); return ret; @@ -745,9 +738,8 @@ GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched, task->run_on_shutdown = run_on_shutdown; #if DEBUG_TASKS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding continuation task: %llu / %p\n", - task->id, - task->callback_cls); + "Adding continuation task: %llu / %p\n", + task->id, task->callback_cls); #endif queue_ready_task (sched, task); } @@ -848,11 +840,13 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle * sched, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, - struct GNUNET_TIME_Relative delay, - struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_Task main, void *cls) + int run_on_shutdown, + enum GNUNET_SCHEDULER_Priority prio, + GNUNET_SCHEDULER_TaskIdentifier + prerequisite_task, + struct GNUNET_TIME_Relative delay, + struct GNUNET_NETWORK_Handle * rfd, + GNUNET_SCHEDULER_Task main, void *cls) { struct GNUNET_NETWORK_FDSet *rs; GNUNET_SCHEDULER_TaskIdentifier ret; @@ -861,8 +855,8 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched, rs = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_set (rs, rfd); ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, - prerequisite_task, delay, - rs, NULL, main, cls); + prerequisite_task, delay, + rs, NULL, main, cls); GNUNET_NETWORK_fdset_destroy (rs); return ret; } @@ -894,11 +888,13 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, - struct GNUNET_TIME_Relative delay, - struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_Task main, void *cls) + int run_on_shutdown, + enum GNUNET_SCHEDULER_Priority prio, + GNUNET_SCHEDULER_TaskIdentifier + prerequisite_task, + struct GNUNET_TIME_Relative delay, + struct GNUNET_NETWORK_Handle * wfd, + GNUNET_SCHEDULER_Task main, void *cls) { struct GNUNET_NETWORK_FDSet *ws; GNUNET_SCHEDULER_TaskIdentifier ret; @@ -907,8 +903,8 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched, ws = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_set (ws, wfd); ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, - prerequisite_task, delay, - NULL, ws, main, cls); + prerequisite_task, delay, + NULL, ws, main, cls); GNUNET_NETWORK_fdset_destroy (ws); return ret; } @@ -957,7 +953,7 @@ GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle * sched, prerequisite_task, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet * rs, - const struct GNUNET_NETWORK_FDSet * ws, + const struct GNUNET_NETWORK_FDSet * ws, GNUNET_SCHEDULER_Task main, void *cls) { struct Task *task; @@ -987,9 +983,7 @@ GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle * sched, sched->pending = task; #if DEBUG_TASKS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding task: %llu / %p\n", - task->id, - task->callback_cls); + "Adding task: %llu / %p\n", task->id, task->callback_cls); #endif return task->id; } @@ -1020,12 +1014,13 @@ GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle * sched, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle * sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, - struct GNUNET_TIME_Relative delay, - const struct GNUNET_DISK_FileHandle *rfd, - GNUNET_SCHEDULER_Task main, void *cls) + int run_on_shutdown, + enum GNUNET_SCHEDULER_Priority prio, + GNUNET_SCHEDULER_TaskIdentifier + prerequisite_task, + struct GNUNET_TIME_Relative delay, + const struct GNUNET_DISK_FileHandle * rfd, + GNUNET_SCHEDULER_Task main, void *cls) { struct GNUNET_NETWORK_FDSet *rs; GNUNET_SCHEDULER_TaskIdentifier ret; @@ -1034,8 +1029,8 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle * sched, rs = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_handle_set (rs, rfd); ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, - prerequisite_task, delay, - rs, NULL, main, cls); + prerequisite_task, delay, + rs, NULL, main, cls); GNUNET_NETWORK_fdset_destroy (rs); return ret; } @@ -1067,12 +1062,13 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle * sched, */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle * sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, - struct GNUNET_TIME_Relative delay, - const struct GNUNET_DISK_FileHandle *wfd, - GNUNET_SCHEDULER_Task main, void *cls) + int run_on_shutdown, + enum GNUNET_SCHEDULER_Priority prio, + GNUNET_SCHEDULER_TaskIdentifier + prerequisite_task, + struct GNUNET_TIME_Relative delay, + const struct GNUNET_DISK_FileHandle * wfd, + GNUNET_SCHEDULER_Task main, void *cls) { struct GNUNET_NETWORK_FDSet *ws; GNUNET_SCHEDULER_TaskIdentifier ret; @@ -1081,8 +1077,8 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle * sched, ws = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_handle_set (ws, wfd); ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, - prerequisite_task, delay, - NULL, ws, main, cls); + prerequisite_task, delay, + NULL, ws, main, cls); GNUNET_NETWORK_fdset_destroy (ws); return ret; } diff --git a/src/util/server.c b/src/util/server.c index 646299718..42fa8c46c 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -272,13 +272,11 @@ destroy_server (struct GNUNET_SERVER_Handle *server) struct NotifyList *npos; #if DEBUG_SERVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Server shutting down.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n"); #endif GNUNET_assert (server->listen_socket == NULL); if (GNUNET_OK != GNUNET_DISK_pipe_close (server->shutpipe)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, - "pipe-close"); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "pipe-close"); while (server->clients != NULL) { pos = server->clients; @@ -318,26 +316,29 @@ process_listen_socket (void *cls, { /* shutdown was initiated */ GNUNET_assert (server->listen_socket != NULL); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (server->listen_socket)); + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (server->listen_socket)); server->listen_socket = NULL; if (server->do_shutdown) destroy_server (server); return; } - shutpipe = GNUNET_DISK_pipe_handle (server->shutpipe, - GNUNET_DISK_PIPE_END_READ); - GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, server->listen_socket)); - GNUNET_assert (!GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, shutpipe)); - sock = GNUNET_CONNECTION_create_from_accept (tc->sched, - server->access, - server->access_cls, - server->listen_socket, - server->maxbuf); + shutpipe = GNUNET_DISK_pipe_handle (server->shutpipe, + GNUNET_DISK_PIPE_END_READ); + GNUNET_assert (GNUNET_NETWORK_fdset_isset + (tc->read_ready, server->listen_socket)); + GNUNET_assert (!GNUNET_NETWORK_fdset_handle_isset + (tc->read_ready, shutpipe)); + sock = + GNUNET_CONNECTION_create_from_accept (tc->sched, server->access, + server->access_cls, + server->listen_socket, + server->maxbuf); if (sock != NULL) { #if DEBUG_SERVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Server accepted incoming connection.\n"); + "Server accepted incoming connection.\n"); #endif client = GNUNET_SERVER_connect_socket (server, sock); /* decrement reference count, we don't keep "client" alive */ @@ -352,8 +353,7 @@ process_listen_socket (void *cls, GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, - r, NULL, - &process_listen_socket, server); + r, NULL, &process_listen_socket, server); GNUNET_NETWORK_fdset_destroy (r); } @@ -388,7 +388,8 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); return NULL; } - if (GNUNET_NETWORK_socket_setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) + if (GNUNET_NETWORK_socket_setsockopt + (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); /* bind the socket */ @@ -409,9 +410,8 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) return NULL; } #if DEBUG_SERVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Server starts to listen on port %u.\n", - port); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Server starts to listen on port %u.\n", port); #endif return sock; } @@ -472,15 +472,14 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, { r = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_set (r, ret->listen_socket); - GNUNET_NETWORK_fdset_handle_set (r, GNUNET_DISK_pipe_handle (ret->shutpipe, - GNUNET_DISK_PIPE_END_READ)); - GNUNET_SCHEDULER_add_select (sched, - GNUNET_YES, + GNUNET_NETWORK_fdset_handle_set (r, + GNUNET_DISK_pipe_handle (ret->shutpipe, + GNUNET_DISK_PIPE_END_READ)); + GNUNET_SCHEDULER_add_select (sched, GNUNET_YES, GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, - r, - NULL, &process_listen_socket, ret); + GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, + &process_listen_socket, ret); GNUNET_NETWORK_fdset_destroy (r); } return ret; @@ -500,10 +499,11 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s) if (s->listen_socket == NULL) destroy_server (s); else - GNUNET_break (1 == GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (s->shutpipe, - GNUNET_DISK_PIPE_END_WRITE), - &c, - sizeof(c))); + GNUNET_break (1 == + GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle + (s->shutpipe, + GNUNET_DISK_PIPE_END_WRITE), &c, + sizeof (c))); } @@ -565,9 +565,8 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, size = ntohs (message->size); #if DEBUG_SERVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Server schedules transmission of %u-byte message of type %u to client.\n", - size, - type); + "Server schedules transmission of %u-byte message of type %u to client.\n", + size, type); #endif pos = server->handlers; found = GNUNET_NO; @@ -668,10 +667,10 @@ process_client_buffer (struct GNUNET_SERVER_Client *client) server = client->server; #if DEBUG_SERVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Private buffer contains %u bytes; client is %s and we are %s\n", - client->receive_pos, - client->suspended ? "suspended" : "up", - client->shutdown_now ? "in shutdown" : "running"); + "Private buffer contains %u bytes; client is %s and we are %s\n", + client->receive_pos, + client->suspended ? "suspended" : "up", + client->shutdown_now ? "in shutdown" : "running"); #endif while ((client->receive_pos >= sizeof (struct GNUNET_MessageHeader)) && (0 == client->suspended) && (GNUNET_YES != client->shutdown_now)) @@ -679,19 +678,17 @@ process_client_buffer (struct GNUNET_SERVER_Client *client) hdr = (const struct GNUNET_MessageHeader *) &client->incoming_buffer; msize = ntohs (hdr->size); if (msize > client->receive_pos) - { + { #if DEBUG_SERVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Total message size is %u, we only have %u bytes; need more data\n", - msize, - client->receive_pos); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Total message size is %u, we only have %u bytes; need more data\n", + msize, client->receive_pos); #endif - break; - } + break; + } #if DEBUG_SERVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Passing %u bytes to callback for processing\n", - msize); + "Passing %u bytes to callback for processing\n", msize); #endif if ((msize < sizeof (struct GNUNET_MessageHeader)) || (GNUNET_OK != GNUNET_SERVER_inject (server, client, hdr))) @@ -727,9 +724,7 @@ static void process_incoming (void *cls, const void *buf, size_t available, - const struct sockaddr *addr, - socklen_t addrlen, - int errCode) + const struct sockaddr *addr, socklen_t addrlen, int errCode) { struct GNUNET_SERVER_Client *client = cls; struct GNUNET_SERVER_Handle *server = client->server; @@ -749,9 +744,8 @@ process_incoming (void *cls, } #if DEBUG_SERVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Server receives %u bytes from `%s'.\n", - available, - GNUNET_a2s(addr, addrlen)); + "Server receives %u bytes from `%s'.\n", + available, GNUNET_a2s (addr, addrlen)); #endif GNUNET_SERVER_client_keep (client); client->last_activity = GNUNET_TIME_absolute_get (); @@ -763,8 +757,7 @@ process_incoming (void *cls, maxcpy = sizeof (client->incoming_buffer) - client->receive_pos; #if DEBUG_SERVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Can copy %u bytes to private buffer\n", - maxcpy); + "Can copy %u bytes to private buffer\n", maxcpy); #endif memcpy (&client->incoming_buffer[client->receive_pos], cbuf, maxcpy); client->receive_pos += maxcpy; @@ -775,12 +768,12 @@ process_incoming (void *cls, if (available > 0) { #if DEBUG_SERVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client has suspended processing; copying %u bytes to side buffer to be used later.\n", - available); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Client has suspended processing; copying %u bytes to side buffer to be used later.\n", + available); #endif - GNUNET_assert (client->side_buf_size == 0); - GNUNET_assert (client->side_buf == NULL); + GNUNET_assert (client->side_buf_size == 0); + GNUNET_assert (client->side_buf == NULL); client->side_buf_size = available; client->side_buf = GNUNET_malloc (available); memcpy (client->side_buf, cbuf, available); @@ -790,7 +783,7 @@ process_incoming (void *cls, } #if DEBUG_SERVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Now processing messages in private buffer\n"); + "Now processing messages in private buffer\n"); #endif process_client_buffer (client); } @@ -800,9 +793,8 @@ process_incoming (void *cls, { /* Finally, keep receiving! */ client->receive (client->client_closure, - GNUNET_SERVER_MAX_MESSAGE_SIZE, - server->idle_timeout, - &process_incoming, client); + GNUNET_SERVER_MAX_MESSAGE_SIZE, + server->idle_timeout, &process_incoming, client); } if (GNUNET_YES == client->shutdown_now) shutdown_incoming_processing (client); @@ -821,9 +813,8 @@ restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) process_client_buffer (client); if (0 == client->suspended) client->receive (client->client_closure, - GNUNET_SERVER_MAX_MESSAGE_SIZE, - client->server->idle_timeout, - &process_incoming, client); + GNUNET_SERVER_MAX_MESSAGE_SIZE, + client->server->idle_timeout, &process_incoming, client); } @@ -840,9 +831,8 @@ add_client (struct GNUNET_SERVER_Handle *server, client->next = server->clients; server->clients = client; client->receive (client->client_closure, - GNUNET_SERVER_MAX_MESSAGE_SIZE, - server->idle_timeout, - &process_incoming, client); + GNUNET_SERVER_MAX_MESSAGE_SIZE, + server->idle_timeout, &process_incoming, client); } @@ -888,7 +878,7 @@ sock_notify_transmit_ready (void *cls, void *notify_cls) { return GNUNET_CONNECTION_notify_transmit_ready (cls, size, timeout, notify, - notify_cls); + notify_cls); } @@ -1058,7 +1048,7 @@ GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, if (client->receive != &sock_receive) return GNUNET_SYSERR; /* not a network client */ return GNUNET_CONNECTION_get_address (client->client_closure, - addr, addrlen); + addr, addrlen); } diff --git a/src/util/service.c b/src/util/service.c index 948730df9..0a33809be 100644 --- a/src/util/service.c +++ b/src/util/service.c @@ -650,7 +650,7 @@ check_access (void *cls, const struct sockaddr *addr, socklen_t addrlen) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Access from `%s' denied to service `%s'\n"), - GNUNET_a2s(addr, addrlen), sctx->serviceName); + GNUNET_a2s (addr, addrlen), sctx->serviceName); } return ret; } @@ -770,8 +770,8 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) { if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (sctx->cfg, - sctx->serviceName, - "TIMEOUT", &idleout)) + sctx->serviceName, + "TIMEOUT", &idleout)) return GNUNET_SYSERR; sctx->timeout = idleout; @@ -794,7 +794,8 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) { if (GNUNET_SYSERR == (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, - sctx->serviceName, + sctx-> + serviceName, "DISABLEV6"))) return GNUNET_SYSERR; } @@ -824,16 +825,16 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); return GNUNET_SYSERR; } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), - sctx->serviceName, - STRERROR (errno)); - disablev6 = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ + ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), + sctx->serviceName, STRERROR (errno)); + disablev6 = GNUNET_YES; } else - { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); - } + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); + } } @@ -900,7 +901,7 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to find %saddress for `%s'.\n"), - disablev6 ? "IPv4 " : "", hostname); + disablev6 ? "IPv4 " : "", hostname); freeaddrinfo (res); GNUNET_free (hostname); return GNUNET_SYSERR; @@ -1086,10 +1087,8 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (sctx->server == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Failed to start `%s' at `%s'\n"), - sctx->serviceName, - GNUNET_a2s (sctx->addr, - sctx->addrlen)); + _("Failed to start `%s' at `%s'\n"), + sctx->serviceName, GNUNET_a2s (sctx->addr, sctx->addrlen)); sctx->ret = GNUNET_SYSERR; return; } @@ -1107,10 +1106,8 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) write_pid_file (sctx, getpid ()); } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Service `%s' runs at %s\n"), - sctx->serviceName, - GNUNET_a2s (sctx->addr, - sctx->addrlen)); + _("Service `%s' runs at %s\n"), + sctx->serviceName, GNUNET_a2s (sctx->addr, sctx->addrlen)); sctx->task (sctx->task_cls, tc->sched, sctx->server, sctx->cfg); } @@ -1121,7 +1118,7 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static int detach_terminal (struct GNUNET_SERVICE_Context *sctx) { -#ifndef MINGW +#ifndef MINGW pid_t pid; int nullfd; int filedes[2]; @@ -1304,7 +1301,7 @@ GNUNET_SERVICE_run (int argc, sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); /* setup subsystems */ if ((GNUNET_SYSERR == - GNUNET_GETOPT_run (serviceName, + GNUNET_GETOPT_run (serviceName, service_options, argc, argv)) || @@ -1337,9 +1334,8 @@ GNUNET_SERVICE_run (int argc, } #if 0 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Service `%s' runs with configuration from `%s'\n", - serviceName, - cfg_fn); + "Service `%s' runs with configuration from `%s'\n", + serviceName, cfg_fn); #endif /* actually run service */ GNUNET_SCHEDULER_run (&service_task, &sctx); diff --git a/src/util/strings.c b/src/util/strings.c index 133fda857..d53bcd482 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -198,13 +198,13 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset) tmp = GNUNET_malloc (tmpSize); itmp = tmp; finSize = tmpSize; - if (iconv (cd, + if (iconv (cd, #if FREEBSD - (const char **) &input, + (const char **) &input, #else - (char **) &input, + (char **) &input, #endif - &len, &itmp, &finSize) == (size_t) - 1) + &len, &itmp, &finSize) == (size_t) - 1) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "iconv"); iconv_close (cd); diff --git a/src/util/test_bio.c b/src/util/test_bio.c index c673fc11f..7b5be6ccd 100644 --- a/src/util/test_bio.c +++ b/src/util/test_bio.c @@ -34,98 +34,121 @@ int main (int argc, char *argv[]) { - char *readResultString; - int64_t testNumber = (int64_t)TESTNUMBER64; - int64_t testNum; - char *msg; - char file[102400]; - char meta[1024*1024*10]; - int i,j; - for(i=0;i<102400;i++){ - file[i]='a'; + char *readResultString; + int64_t testNumber = (int64_t) TESTNUMBER64; + int64_t testNum; + char *msg; + static char file[102400]; + static char meta[1024 * 1024 * 10]; + int i, j; + for (i = 0; i < 102400; i++) + { + file[i] = 'a'; } - for(j=0;j<1024*1024*10;j++){ - meta[j]='b'; + for (j = 0; j < 1024 * 1024 * 10; j++) + { + meta[j] = 'b'; } - char* fileName = GNUNET_DISK_mktemp ("gnunet_bio"); - char* fileName2 = GNUNET_DISK_mktemp ("gnunet_zwei_bio"); - char* fileName3 = GNUNET_DISK_mktemp ("gnunet_drei_bio"); - char* fileName4 = GNUNET_DISK_mktemp ("gnunet_vier_bio"); + char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); + char *fileName2 = GNUNET_DISK_mktemp ("gnunet_zwei_bio"); + char *fileName3 = GNUNET_DISK_mktemp ("gnunet_drei_bio"); + char *fileName4 = GNUNET_DISK_mktemp ("gnunet_vier_bio"); - struct GNUNET_BIO_ReadHandle *fileR,*fileR2,*fileR3,*fileR4; - struct GNUNET_BIO_WriteHandle *fileW,*fileW2,*fileW3,*fileW4; - struct GNUNET_CONTAINER_MetaData *metaDataW; - struct GNUNET_CONTAINER_MetaData *metaDataR; - struct GNUNET_BIO_ReadHandle *fileRNO; - struct GNUNET_BIO_WriteHandle *fileWNO; - struct GNUNET_CONTAINER_MetaData *metaData; - struct GNUNET_CONTAINER_MetaData *metaDataNO; + struct GNUNET_BIO_ReadHandle *fileR, *fileR2, *fileR3, *fileR4; + struct GNUNET_BIO_WriteHandle *fileW, *fileW2, *fileW3, *fileW4; + struct GNUNET_CONTAINER_MetaData *metaDataW; + struct GNUNET_CONTAINER_MetaData *metaDataR; + struct GNUNET_BIO_ReadHandle *fileRNO; + struct GNUNET_BIO_WriteHandle *fileWNO; + struct GNUNET_CONTAINER_MetaData *metaData; + struct GNUNET_CONTAINER_MetaData *metaDataNO; - metaData = GNUNET_CONTAINER_meta_data_create(); - metaDataNO = GNUNET_CONTAINER_meta_data_create(); - metaDataR = GNUNET_CONTAINER_meta_data_create(); - metaDataW = GNUNET_CONTAINER_meta_data_create(); - GNUNET_CONTAINER_meta_data_add_publication_date(metaDataW); - GNUNET_CONTAINER_meta_data_add_publication_date(metaData); - GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_meta_data_insert(metaData,EXTRACTOR_COMMENT,meta)); + metaData = GNUNET_CONTAINER_meta_data_create (); + metaDataNO = GNUNET_CONTAINER_meta_data_create (); + metaDataR = GNUNET_CONTAINER_meta_data_create (); + metaDataW = GNUNET_CONTAINER_meta_data_create (); + GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW); + GNUNET_CONTAINER_meta_data_add_publication_date (metaData); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_meta_data_insert (metaData, + EXTRACTOR_COMMENT, meta)); ///////////write - fileW = GNUNET_BIO_write_open(fileName); - GNUNET_assert(NULL != fileW); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW, TESTSTRING)); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_meta_data(fileW,metaDataW)); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_int64(fileW,testNumber)); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_close(fileW)); - fileW2 = GNUNET_BIO_write_open(fileName2); - GNUNET_assert(NULL != fileW2); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW2,NULL)); - fileWNO = GNUNET_BIO_write_open(file); - fileW3 = GNUNET_BIO_write_open(fileName3); - GNUNET_assert(NULL != fileW3); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_meta_data(fileW3,metaData)); - fileW4 = GNUNET_BIO_write_open(fileName4); - GNUNET_assert(NULL != fileW4); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW4,"")); - GNUNET_assert(NULL != fileWNO); - GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_write_string(fileWNO, TESTSTRING)); - GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_write_meta_data(fileWNO,metaDataW)); - GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_write_close(fileWNO)); + fileW = GNUNET_BIO_write_open (fileName); + GNUNET_assert (NULL != fileW); + GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, TESTSTRING)); + GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_meta_data (fileW, metaDataW)); + GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int64 (fileW, testNumber)); + GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); + fileW2 = GNUNET_BIO_write_open (fileName2); + GNUNET_assert (NULL != fileW2); + GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW2, NULL)); + fileWNO = GNUNET_BIO_write_open (file); + GNUNET_assert (NULL != fileWNO); + GNUNET_assert (GNUNET_SYSERR == + GNUNET_BIO_write_string (fileWNO, TESTSTRING)); + GNUNET_assert (GNUNET_SYSERR == + GNUNET_BIO_write_meta_data (fileWNO, metaDataW)); + GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (fileWNO)); + fileW3 = GNUNET_BIO_write_open (fileName3); + GNUNET_assert (NULL != fileW3); + GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_meta_data (fileW3, metaData)); + fileW4 = GNUNET_BIO_write_open (fileName4); + GNUNET_assert (NULL != fileW4); + GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW4, "")); + GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW4)); ////////////read - fileRNO = GNUNET_BIO_read_open(file); - GNUNET_assert(NULL != fileRNO); - GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_read_string(fileRNO, "Read string error", &readResultString, 200)); - GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_read_int64(fileRNO, &testNum)); - GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_read_meta_data(fileRNO,"Read meta error", &metaDataNO)); - fileR = GNUNET_BIO_read_open(fileName); - GNUNET_assert(NULL != fileR); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_string(fileR, "Read string error", &readResultString, 200)); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_meta_data(fileR, "Read meta error", &metaDataR)); - GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_meta_data_test_equal(metaDataR,metaDataW)); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_int64(fileR, &testNum)); - fileR2 = GNUNET_BIO_read_open(fileName2); - GNUNET_assert(NULL != fileR2); - GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_read_string(fileR2, "Read string error", &readResultString, 200)); - fileR3 = GNUNET_BIO_read_open(fileName3); - GNUNET_assert(NULL != fileR3); - GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_read_meta_data(fileR3, "Read meta error", &metaDataR)); - fileR4 = GNUNET_BIO_read_open(fileName4); - GNUNET_assert(NULL != fileR4); - GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_string(fileR4, "Read string error", &readResultString, 200)); - GNUNET_BIO_read_close(fileR,&msg); - GNUNET_BIO_read_close(fileR2,&msg); - GNUNET_BIO_read_close(fileR3,&msg); - GNUNET_BIO_read_close(fileR4,&msg); - GNUNET_CONTAINER_meta_data_destroy(metaDataW); - GNUNET_CONTAINER_meta_data_destroy(metaDataNO); - GNUNET_CONTAINER_meta_data_destroy(metaDataR); - GNUNET_CONTAINER_meta_data_destroy(metaData); - GNUNET_free(fileName); - GNUNET_free(fileName2); - GNUNET_free(fileName3); - GNUNET_free(fileName4); + fileRNO = GNUNET_BIO_read_open (file); + GNUNET_assert (NULL != fileRNO); + GNUNET_assert (GNUNET_SYSERR == + GNUNET_BIO_read_string (fileRNO, "Read string error", + &readResultString, 200)); + GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_int64 (fileRNO, &testNum)); + GNUNET_assert (GNUNET_SYSERR == + GNUNET_BIO_read_meta_data (fileRNO, "Read meta error", + &metaDataNO)); + fileR = GNUNET_BIO_read_open (fileName); + GNUNET_assert (NULL != fileR); + GNUNET_assert (GNUNET_OK == + GNUNET_BIO_read_string (fileR, "Read string error", + &readResultString, 200)); + GNUNET_assert (GNUNET_OK == + GNUNET_BIO_read_meta_data (fileR, "Read meta error", + &metaDataR)); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_meta_data_test_equal (metaDataR, + metaDataW)); + GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum)); + fileR2 = GNUNET_BIO_read_open (fileName2); + GNUNET_assert (NULL != fileR2); + GNUNET_assert (GNUNET_SYSERR == + GNUNET_BIO_read_string (fileR2, "Read string error", + &readResultString, 200)); + fileR3 = GNUNET_BIO_read_open (fileName3); + GNUNET_assert (NULL != fileR3); + GNUNET_assert (GNUNET_SYSERR == + GNUNET_BIO_read_meta_data (fileR3, "Read meta error", + &metaDataR)); + fileR4 = GNUNET_BIO_read_open (fileName4); + GNUNET_assert (NULL != fileR4); + GNUNET_assert (GNUNET_OK == + GNUNET_BIO_read_string (fileR4, "Read string error", + &readResultString, 200)); + GNUNET_BIO_read_close (fileR, &msg); + GNUNET_BIO_read_close (fileR2, &msg); + GNUNET_BIO_read_close (fileR3, &msg); + GNUNET_BIO_read_close (fileR4, &msg); + GNUNET_CONTAINER_meta_data_destroy (metaDataW); + GNUNET_CONTAINER_meta_data_destroy (metaDataNO); + GNUNET_CONTAINER_meta_data_destroy (metaDataR); + GNUNET_CONTAINER_meta_data_destroy (metaData); + GNUNET_free (fileName); + GNUNET_free (fileName2); + GNUNET_free (fileName3); + GNUNET_free (fileName4); - return 0; + return 0; } /* end of main */ diff --git a/src/util/test_client.c b/src/util/test_client.c index 04efd951b..04f002c43 100644 --- a/src/util/test_client.c +++ b/src/util/test_client.c @@ -61,8 +61,7 @@ copy_msg (void *cls, size_t size, void *buf) GNUNET_SERVER_receive_done (ctx->client, GNUNET_OK); GNUNET_free (cpy); GNUNET_free (ctx); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Message bounced back to client\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bounced back to client\n"); return sizeof (struct GNUNET_MessageHeader); } @@ -79,7 +78,7 @@ echo_cb (void *cls, struct GNUNET_MessageHeader *cpy; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Receiving message from client, bouncing back\n"); + "Receiving message from client, bouncing back\n"); GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); cc = GNUNET_malloc (sizeof (struct CopyContext)); @@ -109,10 +108,11 @@ recv_bounce (void *cls, const struct GNUNET_MessageHeader *got) GNUNET_assert (got != NULL); /* timeout */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Receiving bounce, checking content\n"); + "Receiving bounce, checking content\n"); msg.type = htons (MY_TYPE); msg.size = htons (sizeof (struct GNUNET_MessageHeader)); - GNUNET_assert (0 == memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader))); + GNUNET_assert (0 == + memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader))); GNUNET_CLIENT_disconnect (client); client = NULL; GNUNET_SERVER_destroy (server); @@ -128,8 +128,7 @@ make_msg (void *cls, size_t size, void *buf) GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); msg->type = htons (MY_TYPE); msg->size = htons (sizeof (struct GNUNET_MessageHeader)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating message for transmission\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating message for transmission\n"); return sizeof (struct GNUNET_MessageHeader); } @@ -163,9 +162,9 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (NULL != GNUNET_CLIENT_notify_transmit_ready (client, sizeof (struct - GNUNET_MessageHeader), + GNUNET_MessageHeader), GNUNET_TIME_UNIT_SECONDS, - GNUNET_NO, + GNUNET_NO, &make_msg, NULL)); GNUNET_CLIENT_receive (client, &recv_bounce, cls, GNUNET_TIME_relative_multiply @@ -199,13 +198,13 @@ main (int argc, char *argv[]) { int ret = 0; - GNUNET_log_setup ("test_client", + GNUNET_log_setup ("test_client", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check (); return ret; diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c index 6a2fda699..4c7f69a14 100644 --- a/src/util/test_configuration.c +++ b/src/util/test_configuration.c @@ -70,7 +70,7 @@ testConfig () #ifndef MINGW if (0 != strcmp (c, "/hello/world")) #else - #define HI "\\hello\\world" +#define HI "\\hello\\world" if (strstr (c, HI) != c + strlen (c) - strlen (HI)) #endif { diff --git a/src/util/test_connection.c b/src/util/test_connection.c index e144f66c1..0f4c46b3b 100644 --- a/src/util/test_connection.c +++ b/src/util/test_connection.c @@ -64,12 +64,13 @@ open_listen_socket () sa.sin_family = AF_INET; desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); GNUNET_assert (desc != NULL); - if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) + if (GNUNET_NETWORK_socket_setsockopt + (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, - (const struct sockaddr*) &sa, - sizeof (sa)) == GNUNET_OK); + GNUNET_assert (GNUNET_NETWORK_socket_bind + (desc, (const struct sockaddr *) &sa, + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } @@ -94,10 +95,10 @@ receive_check (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n"); #endif GNUNET_CONNECTION_receive (asock, - 1024, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, - cls); + 1024, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), + &receive_check, cls); } else { @@ -118,7 +119,7 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test accepts connection\n"); #endif asock = GNUNET_CONNECTION_create_from_accept (tc->sched, - NULL, NULL, ls, 1024); + NULL, NULL, ls, 1024); GNUNET_assert (asock != NULL); GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); #if VERBOSE @@ -130,9 +131,10 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) "Test asks to receive on accepted socket\n"); #endif GNUNET_CONNECTION_receive (asock, - 1024, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, cls); + 1024, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, + cls); } static size_t @@ -158,27 +160,26 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) lsock = GNUNET_CONNECTION_create_from_existing (tc->sched, ls, 0); GNUNET_assert (lsock != NULL); csock = GNUNET_CONNECTION_create_from_connect (tc->sched, - cfg, - "localhost", PORT, 1024); + cfg, + "localhost", PORT, 1024); GNUNET_assert (csock != NULL); #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n"); #endif GNUNET_assert (NULL != GNUNET_CONNECTION_notify_transmit_ready (csock, - 12, - GNUNET_TIME_UNIT_SECONDS, - &make_hello, - NULL)); + 12, + GNUNET_TIME_UNIT_SECONDS, + &make_hello, NULL)); #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n"); #endif GNUNET_SCHEDULER_add_read_net (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, - ls, &run_accept, cls); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_HIGH, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_FOREVER_REL, + ls, &run_accept, cls); } diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c index f37352c67..1b85dfac6 100644 --- a/src/util/test_connection_addressing.c +++ b/src/util/test_connection_addressing.c @@ -63,12 +63,13 @@ open_listen_socket () sa.sin_port = htons (PORT); desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); GNUNET_assert (desc != 0); - if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) + if (GNUNET_NETWORK_socket_setsockopt + (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, - (const struct sockaddr*) &sa, - sizeof (sa)) == GNUNET_OK); + GNUNET_assert (GNUNET_NETWORK_socket_bind + (desc, (const struct sockaddr *) &sa, + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } @@ -88,10 +89,10 @@ receive_check (void *cls, if (sofar < 12) { GNUNET_CONNECTION_receive (asock, - 1024, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, - cls); + 1024, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), + &receive_check, cls); } else { @@ -110,7 +111,7 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct sockaddr_in expect; asock = GNUNET_CONNECTION_create_from_accept (tc->sched, - NULL, NULL, ls, 1024); + NULL, NULL, ls, 1024); GNUNET_assert (asock != NULL); GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); GNUNET_assert (GNUNET_OK == @@ -128,9 +129,10 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (addr); GNUNET_CONNECTION_destroy (lsock); GNUNET_CONNECTION_receive (asock, - 1024, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, cls); + 1024, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, + cls); } static size_t @@ -156,23 +158,22 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) v4.sin_port = htons (PORT); v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); csock = GNUNET_CONNECTION_create_from_sockaddr (tc->sched, - AF_INET, - (const struct sockaddr - *) &v4, sizeof (v4), - 1024); + AF_INET, + (const struct sockaddr + *) &v4, sizeof (v4), 1024); GNUNET_assert (csock != NULL); GNUNET_assert (NULL != GNUNET_CONNECTION_notify_transmit_ready (csock, - 12, - GNUNET_TIME_UNIT_SECONDS, - &make_hello, NULL)); + 12, + GNUNET_TIME_UNIT_SECONDS, + &make_hello, NULL)); GNUNET_CONNECTION_destroy (csock); GNUNET_SCHEDULER_add_read_net (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, - ls, &run_accept, cls); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_HIGH, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_FOREVER_REL, + ls, &run_accept, cls); } @@ -197,13 +198,13 @@ main (int argc, char *argv[]) { int ret = 0; - GNUNET_log_setup ("test_connection_addressing", + GNUNET_log_setup ("test_connection_addressing", #if VERBOSE - "DEBUG", + "DEBUG", #else - "WARNING", + "WARNING", #endif - NULL); + NULL); ret += check (); return ret; } diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c index e985bf935..5856e27ed 100644 --- a/src/util/test_connection_receive_cancel.c +++ b/src/util/test_connection_receive_cancel.c @@ -62,12 +62,13 @@ open_listen_socket () sa.sin_port = htons (PORT); desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); GNUNET_assert (desc != NULL); - if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) + if (GNUNET_NETWORK_socket_setsockopt + (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, - (const struct sockaddr*) &sa, - sizeof (sa)) == GNUNET_OK); + GNUNET_assert (GNUNET_NETWORK_socket_bind + (desc, (const struct sockaddr *) &sa, + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } @@ -89,15 +90,15 @@ run_accept_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { asock = GNUNET_CONNECTION_create_from_accept (tc->sched, - NULL, NULL, ls, 1024); + NULL, NULL, ls, 1024); GNUNET_assert (asock != NULL); GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); GNUNET_CONNECTION_destroy (lsock); GNUNET_CONNECTION_receive (asock, - 1024, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, - cls); + 1024, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, + cls); } @@ -120,14 +121,14 @@ task_receive_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) lsock = GNUNET_CONNECTION_create_from_existing (tc->sched, ls, 0); GNUNET_assert (lsock != NULL); csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg, - "localhost", PORT, 1024); + "localhost", PORT, 1024); GNUNET_assert (csock != NULL); GNUNET_SCHEDULER_add_read_net (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, - ls, &run_accept_cancel, cls); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_HIGH, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_FOREVER_REL, + ls, &run_accept_cancel, cls); GNUNET_SCHEDULER_add_delayed (tc->sched, GNUNET_NO, GNUNET_SCHEDULER_PRIORITY_KEEP, diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c index 5968f797f..0590d36d5 100644 --- a/src/util/test_connection_timeout.c +++ b/src/util/test_connection_timeout.c @@ -59,12 +59,13 @@ open_listen_socket () sa.sin_port = htons (PORT); desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); GNUNET_assert (desc != NULL); - if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) + if (GNUNET_NETWORK_socket_setsockopt + (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, - (const struct sockaddr*) &sa, - sizeof (sa)) == GNUNET_OK); + GNUNET_assert (GNUNET_NETWORK_socket_bind + (desc, (const struct sockaddr *) &sa, + sizeof (sa)) == GNUNET_OK); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } @@ -93,9 +94,9 @@ send_kilo (void *cls, size_t size, void *buf) GNUNET_assert (NULL != GNUNET_CONNECTION_notify_transmit_ready (csock, - 1024, - GNUNET_TIME_UNIT_SECONDS, - &send_kilo, cls)); + 1024, + GNUNET_TIME_UNIT_SECONDS, + &send_kilo, cls)); return 1024; } @@ -108,13 +109,13 @@ task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) lsock = GNUNET_CONNECTION_create_from_existing (tc->sched, ls, 0); GNUNET_assert (lsock != NULL); csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg, - "localhost", PORT, 1024); + "localhost", PORT, 1024); GNUNET_assert (csock != NULL); GNUNET_assert (NULL != GNUNET_CONNECTION_notify_transmit_ready (csock, - 1024, - GNUNET_TIME_UNIT_SECONDS, - &send_kilo, cls)); + 1024, + GNUNET_TIME_UNIT_SECONDS, + &send_kilo, cls)); } diff --git a/src/util/test_connection_timeout_no_connect.c b/src/util/test_connection_timeout_no_connect.c index 84d50b4fb..6d226999f 100644 --- a/src/util/test_connection_timeout_no_connect.c +++ b/src/util/test_connection_timeout_no_connect.c @@ -54,13 +54,14 @@ static void task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg, - "localhost", PORT, 1024); + "localhost", PORT, 1024); GNUNET_assert (csock != NULL); GNUNET_assert (NULL != GNUNET_CONNECTION_notify_transmit_ready (csock, - 1024, - GNUNET_TIME_UNIT_SECONDS, - &handle_timeout, cls)); + 1024, + GNUNET_TIME_UNIT_SECONDS, + &handle_timeout, + cls)); } diff --git a/src/util/test_connection_transmit_cancel.c b/src/util/test_connection_transmit_cancel.c index 5ec19bdb1..afdca68b5 100644 --- a/src/util/test_connection_transmit_cancel.c +++ b/src/util/test_connection_transmit_cancel.c @@ -51,12 +51,12 @@ task_transmit_cancel (void *cls, struct GNUNET_CONNECTION_Handle *csock; csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg, - "localhost", PORT, 1024); + "localhost", PORT, 1024); GNUNET_assert (csock != NULL); th = GNUNET_CONNECTION_notify_transmit_ready (csock, - 12, - GNUNET_TIME_UNIT_MINUTES, - ¬_run, cls); + 12, + GNUNET_TIME_UNIT_MINUTES, + ¬_run, cls); GNUNET_CONNECTION_notify_transmit_ready_cancel (th); GNUNET_CONNECTION_destroy (csock); *ok = 0; diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c index 2e7fb2e28..f54028f54 100644 --- a/src/util/test_container_bloomfilter.c +++ b/src/util/test_container_bloomfilter.c @@ -42,8 +42,7 @@ nextHC (GNUNET_HashCode * hc) } static int -add_iterator (void *cls, - GNUNET_HashCode * next) +add_iterator (void *cls, GNUNET_HashCode * next) { int *ret = cls; GNUNET_HashCode pos; diff --git a/src/util/test_container_slist.c b/src/util/test_container_slist.c index 7d31eff2e..bc134d26a 100644 --- a/src/util/test_container_slist.c +++ b/src/util/test_container_slist.c @@ -39,7 +39,7 @@ main (int argc, char *argv[]) unsigned int i; unsigned int j; size_t s; - const void *p; + const void *p; GNUNET_log_setup ("test-container-slist", "WARNING", NULL); @@ -48,7 +48,9 @@ main (int argc, char *argv[]) CHECK (GNUNET_CONTAINER_slist_count (l) == 0); for (i = 0; i < 100; i++) - GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &i, sizeof (i)); + GNUNET_CONTAINER_slist_add (l, + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + &i, sizeof (i)); CHECK (GNUNET_CONTAINER_slist_count (l) == 100); for (it = GNUNET_CONTAINER_slist_begin (l), i = 99; @@ -62,8 +64,9 @@ main (int argc, char *argv[]) CHECK (s == sizeof (i)); j *= 2; - GNUNET_CONTAINER_slist_insert (it, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &j, - sizeof (j)); + GNUNET_CONTAINER_slist_insert (it, + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + &j, sizeof (j)); } GNUNET_free (it); CHECK (GNUNET_CONTAINER_slist_count (l) == 200); @@ -101,7 +104,9 @@ main (int argc, char *argv[]) CHECK (GNUNET_CONTAINER_slist_count (l) == 0); for (i = 0; i < 100; i++) - GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &i, sizeof (i)); + GNUNET_CONTAINER_slist_add (l, + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, + &i, sizeof (i)); GNUNET_CONTAINER_slist_destroy (l); diff --git a/src/util/test_crypto_aes.c b/src/util/test_crypto_aes.c index f876e4175..fb0d05683 100644 --- a/src/util/test_crypto_aes.c +++ b/src/util/test_crypto_aes.c @@ -52,7 +52,7 @@ testSymcipher () } size = GNUNET_CRYPTO_aes_decrypt (result, size, &key, - (const struct + (const struct GNUNET_CRYPTO_AesInitializationVector *) INITVALUE, res); if (strlen (TESTSTRING) + 1 != size) @@ -134,7 +134,7 @@ verifyCrypto () GNUNET_CRYPTO_aes_decrypt (result, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, - (const struct + (const struct GNUNET_CRYPTO_AesInitializationVector *) "testtesttesttest", res)) { diff --git a/src/util/test_crypto_ksk.c b/src/util/test_crypto_ksk.c index 943e9792b..ad63cb6de 100644 --- a/src/util/test_crypto_ksk.c +++ b/src/util/test_crypto_ksk.c @@ -169,8 +169,8 @@ testSignVerify (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) continue; } if (GNUNET_SYSERR != - GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, - &purp, &sig, &pkey)) + GNUNET_CRYPTO_rsa_verify + (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, &purp, &sig, &pkey)) { printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); ok = GNUNET_SYSERR; diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c index 6b17b4f49..b3663662e 100644 --- a/src/util/test_crypto_rsa.c +++ b/src/util/test_crypto_rsa.c @@ -76,9 +76,7 @@ testEncryptDecrypt () if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) { printf ("%s != %.*s - testEncryptDecrypt failed!\n", - TESTSTRING, - (int) MAX_TESTVAL, - result); + TESTSTRING, (int) MAX_TESTVAL, result); ok++; continue; } @@ -229,8 +227,8 @@ testSignVerify () continue; } if (GNUNET_SYSERR != - GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, - &purp, &sig, &pkey)) + GNUNET_CRYPTO_rsa_verify + (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, &purp, &sig, &pkey)) { printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); ok = GNUNET_SYSERR; @@ -275,7 +273,8 @@ testSignPerformance () } } printf ("%d RSA sign operations %llu ms\n", ITER, - (unsigned long long) GNUNET_TIME_absolute_get_duration (start).value); + (unsigned long long) GNUNET_TIME_absolute_get_duration (start). + value); GNUNET_CRYPTO_rsa_key_free (hostkey); return ok; } diff --git a/src/util/test_disk.c b/src/util/test_disk.c index 8b485edc5..c84ec812a 100644 --- a/src/util/test_disk.c +++ b/src/util/test_disk.c @@ -36,10 +36,11 @@ testReadWrite () char tmp[100 + 1]; int ret; - if (strlen(TESTSTRING) != - GNUNET_DISK_fn_write (".testfile", TESTSTRING, - strlen (TESTSTRING), - GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)) + if (strlen (TESTSTRING) != + GNUNET_DISK_fn_write (".testfile", TESTSTRING, + strlen (TESTSTRING), + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)) return 1; if (GNUNET_OK != GNUNET_DISK_file_test (".testfile")) return 1; @@ -92,8 +93,9 @@ testOpenClose () long avail; fh = GNUNET_DISK_file_open (".testfile", GNUNET_DISK_OPEN_READWRITE - | GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE); + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5)); GNUNET_DISK_file_close (fh); @@ -108,8 +110,9 @@ testOpenClose () avail = GNUNET_DISK_get_blocks_available (".testfile"); GNUNET_log_skip (0, GNUNET_NO); fh = GNUNET_DISK_file_open (".testfile", GNUNET_DISK_OPEN_READWRITE - | GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_WRITE - | GNUNET_DISK_PERM_USER_READ); + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_USER_READ); GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) && (avail != -1)) @@ -138,11 +141,14 @@ scan_callback (void *want, const char *filename) static int testDirScan () { - if (GNUNET_OK != GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry")) + if (GNUNET_OK != + GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry")) return 1; - if (GNUNET_OK != GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more")) + if (GNUNET_OK != + GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more")) return 1; - GNUNET_DISK_directory_scan ("test", &scan_callback, "test" DIR_SEPARATOR_STR "entry"); + GNUNET_DISK_directory_scan ("test", &scan_callback, + "test" DIR_SEPARATOR_STR "entry"); if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) return 1; if (ok < 2) diff --git a/src/util/test_getopt.c b/src/util/test_getopt.c index e254ac31f..1472fbb91 100644 --- a/src/util/test_getopt.c +++ b/src/util/test_getopt.c @@ -87,8 +87,7 @@ testVersion () GNUNET_GETOPT_OPTION_END }; - if (-1 != GNUNET_GETOPT_run ("test_getopt", - versionoptionlist, 2, myargv)) + if (-1 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv)) { GNUNET_break (0); return 1; @@ -109,8 +108,7 @@ testAbout () GNUNET_GETOPT_OPTION_END }; - if (-1 != GNUNET_GETOPT_run ("test_getopt", - aboutoptionlist, 2, myargv)) + if (-1 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv)) { GNUNET_break (0); return 1; diff --git a/src/util/test_os_load.c b/src/util/test_os_load.c index 7cc35e56d..e45c4ac36 100644 --- a/src/util/test_os_load.c +++ b/src/util/test_os_load.c @@ -131,14 +131,18 @@ testdisk () } memset (buf, 42, sizeof (buf)); fh = GNUNET_DISK_file_open (".loadfile", GNUNET_DISK_OPEN_WRITE - | GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE); - GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid(fh)); + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); + GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); while (GNUNET_TIME_absolute_get_duration (start).value < 60 * 1000) { - GNUNET_DISK_file_seek (fh, GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, - 1024 * 1024 * 1024), GNUNET_DISK_SEEK_SET); - GNUNET_assert (sizeof (buf) == GNUNET_DISK_file_write (fh, buf, sizeof (buf))); + GNUNET_DISK_file_seek (fh, + GNUNET_CRYPTO_random_u64 + (GNUNET_CRYPTO_QUALITY_WEAK, 1024 * 1024 * 1024), + GNUNET_DISK_SEEK_SET); + GNUNET_assert (sizeof (buf) == + GNUNET_DISK_file_write (fh, buf, sizeof (buf))); GNUNET_DISK_file_sync (fh); if (ret < GNUNET_OS_load_disk_get (cfg)) break; diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index 295217c30..15a7f820b 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c @@ -44,8 +44,8 @@ check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen) return; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Got IP address `%s' for our host.\n"), - GNUNET_a2s (sa, salen)); + _("Got IP address `%s' for our host.\n"), + GNUNET_a2s (sa, salen)); } @@ -126,8 +126,7 @@ static void run (void *cls, struct GNUNET_SCHEDULER_Handle *sched, char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct sockaddr_in sa; struct GNUNET_TIME_Relative timeout = @@ -186,7 +185,7 @@ check () GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } - GNUNET_OS_process_wait(pid); + GNUNET_OS_process_wait (pid); if (ok != 0) fprintf (stderr, "Missed some resolutions: %u\n", ok); return ok; diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index b19ccff2d..98dce6f97 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.c @@ -119,17 +119,17 @@ task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); GNUNET_SCHEDULER_add_read_file (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, - fds[0], &taskRd, cls); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_DEFAULT, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_FOREVER_REL, + fds[0], &taskRd, cls); GNUNET_SCHEDULER_add_write_file (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_FOREVER_REL, - fds[1], &taskWrt, cls); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_DEFAULT, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_FOREVER_REL, + fds[1], &taskWrt, cls); } @@ -146,19 +146,18 @@ task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) t2 = GNUNET_SCHEDULER_add_after (tc->sched, GNUNET_NO, GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, - &task2, cls); + GNUNET_SCHEDULER_NO_TASK, &task2, cls); /* t3 will go before t4: higher priority */ t4 = GNUNET_SCHEDULER_add_after (tc->sched, GNUNET_NO, GNUNET_SCHEDULER_PRIORITY_IDLE, t2, &task4, cls); GNUNET_SCHEDULER_add_delayed (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - t2, - GNUNET_TIME_relative_get_zero (), - &task3, cls); + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_DEFAULT, + t2, + GNUNET_TIME_relative_get_zero (), + &task3, cls); /* t4 will go first: lower prio, but prereq! */ GNUNET_SCHEDULER_add_after (tc->sched, GNUNET_NO, diff --git a/src/util/test_server.c b/src/util/test_server.c index eadc03568..ae5609de0 100644 --- a/src/util/test_server.c +++ b/src/util/test_server.c @@ -87,7 +87,8 @@ my_receive (void *cls, *ok = 2; /* report success */ msg.type = htons (MY_TYPE2); msg.size = htons (sizeof (struct GNUNET_MessageHeader)); - receiver (receiver_cls, &msg, sizeof (struct GNUNET_MessageHeader), NULL, 0, 0); + receiver (receiver_cls, &msg, sizeof (struct GNUNET_MessageHeader), + NULL, 0, 0); break; case 3: /* called after first receive instantly diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c index 9aff7fc72..c5ce5e736 100644 --- a/src/util/test_server_disconnect.c +++ b/src/util/test_server_disconnect.c @@ -210,8 +210,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 256, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), - GNUNET_NO, - ¬ify_ready, NULL); + GNUNET_NO, ¬ify_ready, NULL); } diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c index 2558fd10c..508c505b1 100644 --- a/src/util/test_server_with_client.c +++ b/src/util/test_server_with_client.c @@ -184,8 +184,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 256, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), - GNUNET_NO, - ¬ify_ready, NULL); + GNUNET_NO, ¬ify_ready, NULL); } diff --git a/src/util/test_service.c b/src/util/test_service.c index 037f6edf7..93cafb4d2 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c @@ -86,8 +86,7 @@ ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CLIENT_notify_transmit_ready (client, sizeof (struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_SECONDS, - GNUNET_NO, - &build_msg, client); + GNUNET_NO, &build_msg, client); } static void @@ -114,12 +113,12 @@ runner (void *cls, GNUNET_SERVER_add_handlers (server, myhandlers); GNUNET_CLIENT_service_test (sched, "test_service", - cfg, GNUNET_TIME_UNIT_SECONDS, &ready, (void*) cfg); + cfg, GNUNET_TIME_UNIT_SECONDS, &ready, + (void *) cfg); } static void -term (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +term (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { int *ok = cls; *ok = 0; @@ -170,8 +169,7 @@ ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CLIENT_notify_transmit_ready (client, sizeof (struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_SECONDS, - GNUNET_NO, - &build_msg, client); + GNUNET_NO, &build_msg, client); } static void @@ -184,7 +182,8 @@ runner6 (void *cls, GNUNET_SERVER_add_handlers (server, myhandlers); GNUNET_CLIENT_service_test (sched, "test_service6", - cfg, GNUNET_TIME_UNIT_SECONDS, &ready6, (void*) cfg); + cfg, GNUNET_TIME_UNIT_SECONDS, &ready6, + (void *) cfg); } /** @@ -254,8 +253,8 @@ static void start_stop_main (void *cls, struct GNUNET_SCHEDULER_Handle *sched, char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { int *ret = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/util/time.c b/src/util/time.c index 90351138a..6411de662 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -40,7 +40,9 @@ GNUNET_TIME_absolute_get () struct timeval tv; GETTIMEOFDAY (&tv, NULL); - ret.value = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + ((uint64_t) tv.tv_usec / 1000LL)); + ret.value = + (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + + ((uint64_t) tv.tv_usec / 1000LL)); return ret; } @@ -106,7 +108,7 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) { struct GNUNET_TIME_Absolute ret; - if (rel.value == (uint64_t) -1LL) + if (rel.value == (uint64_t) - 1LL) return GNUNET_TIME_absolute_get_forever (); struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); if (rel.value + now.value < rel.value) @@ -126,11 +128,10 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) * @param t2 other timestamp * @return timestamp that is smaller */ -struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct - GNUNET_TIME_Relative - t1, - struct - GNUNET_TIME_Relative t2) +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_min (struct + GNUNET_TIME_Relative + t1, struct GNUNET_TIME_Relative t2) { return (t1.value < t2.value) ? t1 : t2; } @@ -144,11 +145,10 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct * @param t2 other timestamp * @return timestamp that is smaller */ -struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min (struct - GNUNET_TIME_Absolute - t1, - struct - GNUNET_TIME_Absolute t2) +struct GNUNET_TIME_Absolute +GNUNET_TIME_absolute_min (struct + GNUNET_TIME_Absolute + t1, struct GNUNET_TIME_Absolute t2) { return (t1.value < t2.value) ? t1 : t2; } @@ -254,7 +254,7 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, { GNUNET_break (0); return GNUNET_TIME_relative_get_forever (); - } + } return ret; } @@ -269,9 +269,9 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, * @return remaining duration for the operation, * assuming it continues at the same speed */ -struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, - uint64_t finished, - uint64_t total) +struct GNUNET_TIME_Relative +GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, + uint64_t finished, uint64_t total) { struct GNUNET_TIME_Relative dur; double exp; @@ -283,7 +283,7 @@ struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolu if (finished == 0) return GNUNET_TIME_UNIT_FOREVER_REL; dur = GNUNET_TIME_absolute_get_duration (start); - exp = ((double)dur.value) * ((double) total) / ((double)finished); + exp = ((double) dur.value) * ((double) total) / ((double) finished); ret.value = ((uint64_t) exp) - dur.value; return ret; } diff --git a/src/util/winproc.c b/src/util/winproc.c index 862222c05..bd2f2d091 100644 --- a/src/util/winproc.c +++ b/src/util/winproc.c @@ -73,8 +73,8 @@ void plibc_panic (int err, char *msg) { GNUNET_log (((err == - INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR), - "%s", msg); + INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR), + "%s", msg); } /** -- cgit v1.2.3