From c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Oct 2019 15:09:28 +0200 Subject: global reindent, now with uncrustify hook enabled --- src/transport/communicator.h | 6 +- src/transport/gnunet-communicator-tcp.c | 1798 ++--- src/transport/gnunet-communicator-udp.c | 2214 +++--- src/transport/gnunet-communicator-unix.c | 911 +-- src/transport/gnunet-helper-transport-bluetooth.c | 2585 +++---- src/transport/gnunet-helper-transport-wlan-dummy.c | 565 +- src/transport/gnunet-helper-transport-wlan.c | 1514 ++-- src/transport/gnunet-service-tng.c | 7587 ++++++++++---------- src/transport/gnunet-service-transport.c | 2336 +++--- src/transport/gnunet-service-transport.h | 64 +- src/transport/gnunet-service-transport_ats.c | 750 +- src/transport/gnunet-service-transport_ats.h | 52 +- src/transport/gnunet-service-transport_hello.c | 205 +- src/transport/gnunet-service-transport_hello.h | 20 +- .../gnunet-service-transport_manipulation.c | 478 +- .../gnunet-service-transport_manipulation.h | 34 +- .../gnunet-service-transport_neighbours.c | 4423 ++++++------ .../gnunet-service-transport_neighbours.h | 89 +- src/transport/gnunet-service-transport_plugins.c | 447 +- src/transport/gnunet-service-transport_plugins.h | 20 +- .../gnunet-service-transport_validation.c | 1721 ++--- .../gnunet-service-transport_validation.h | 28 +- src/transport/gnunet-transport-profiler.c | 529 +- src/transport/gnunet-transport-wlan-receiver.c | 120 +- src/transport/gnunet-transport-wlan-sender.c | 256 +- src/transport/gnunet-transport.c | 1202 ++-- src/transport/ieee80211_radiotap.h | 14 +- src/transport/plugin_transport_http.h | 96 +- src/transport/plugin_transport_http_client.c | 2473 +++---- src/transport/plugin_transport_http_common.c | 968 +-- src/transport/plugin_transport_http_common.h | 96 +- src/transport/plugin_transport_http_server.c | 3550 ++++----- src/transport/plugin_transport_smtp.c | 638 +- src/transport/plugin_transport_tcp.c | 3542 ++++----- src/transport/plugin_transport_template.c | 183 +- src/transport/plugin_transport_udp.c | 3821 +++++----- src/transport/plugin_transport_udp.h | 40 +- src/transport/plugin_transport_udp_broadcasting.c | 624 +- src/transport/plugin_transport_unix.c | 1566 ++-- src/transport/plugin_transport_wlan.c | 2059 +++--- src/transport/plugin_transport_wlan.h | 18 +- src/transport/tcp_connection_legacy.c | 1304 ++-- src/transport/tcp_server_legacy.c | 1256 ++-- src/transport/tcp_server_mst_legacy.c | 323 +- src/transport/tcp_service_legacy.c | 1639 ++--- src/transport/test_communicator_unix.c | 228 +- src/transport/test_http_common.c | 293 +- src/transport/test_plugin_transport.c | 826 +-- src/transport/test_quota_compliance.c | 316 +- src/transport/test_transport_address_switch.c | 354 +- src/transport/test_transport_api.c | 75 +- src/transport/test_transport_api_blacklisting.c | 165 +- src/transport/test_transport_api_disconnect.c | 91 +- src/transport/test_transport_api_limited_sockets.c | 70 +- .../test_transport_api_manipulation_cfg.c | 172 +- .../test_transport_api_manipulation_recv_tcp.c | 171 +- .../test_transport_api_manipulation_send_tcp.c | 169 +- src/transport/test_transport_api_monitor_peers.c | 191 +- src/transport/test_transport_api_reliability.c | 209 +- .../test_transport_api_restart_reconnect.c | 169 +- src/transport/test_transport_api_timeout.c | 122 +- src/transport/test_transport_blacklisting.c | 737 +- src/transport/test_transport_testing_restart.c | 138 +- src/transport/test_transport_testing_startstop.c | 106 +- src/transport/transport-testing-filenames.c | 98 +- src/transport/transport-testing-loggers.c | 45 +- src/transport/transport-testing-main.c | 445 +- src/transport/transport-testing-send.c | 191 +- src/transport/transport-testing.c | 1027 +-- src/transport/transport-testing.h | 78 +- src/transport/transport-testing2.c | 445 +- src/transport/transport-testing2.h | 62 +- src/transport/transport.h | 113 +- src/transport/transport_api2_application.c | 184 +- src/transport/transport_api2_communication.c | 455 +- src/transport/transport_api2_core.c | 484 +- src/transport/transport_api2_monitor.c | 127 +- src/transport/transport_api_address_to_string.c | 211 +- src/transport/transport_api_blacklist.c | 85 +- src/transport/transport_api_core.c | 600 +- src/transport/transport_api_hello_get.c | 137 +- src/transport/transport_api_manipulation.c | 131 +- src/transport/transport_api_monitor_peers.c | 362 +- src/transport/transport_api_monitor_plugins.c | 285 +- src/transport/transport_api_offer_hello.c | 72 +- 85 files changed, 32598 insertions(+), 31805 deletions(-) (limited to 'src/transport') diff --git a/src/transport/communicator.h b/src/transport/communicator.h index 04a9857e5..ab7a25de6 100644 --- a/src/transport/communicator.h +++ b/src/transport/communicator.h @@ -41,7 +41,8 @@ GNUNET_NETWORK_STRUCT_BEGIN * just the recommended "generic" style, communicators are always free * to implement original designs that better fit their requirements. */ -struct GNUNET_TRANSPORT_CommunicatorGenericKXConfirmation { +struct GNUNET_TRANSPORT_CommunicatorGenericKXConfirmation +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION */ @@ -88,7 +89,8 @@ struct GNUNET_TRANSPORT_CommunicatorGenericKXConfirmation { * free to implement original designs that better fit their * requirements. */ -struct GNUNET_TRANSPORT_CommunicatorGenericFCLimits { +struct GNUNET_TRANSPORT_CommunicatorGenericFCLimits +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS */ diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index a8d692940..f3ccbd262 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c @@ -47,7 +47,7 @@ * the other peer should revalidate). */ #define ADDRESS_VALIDITY_PERIOD \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) /** * How many messages do we keep at most in the queue to the @@ -86,8 +86,8 @@ * directions. */ #define INITIAL_KX_SIZE \ - (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) + \ - sizeof(struct TCPConfirmation)) + (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) \ + + sizeof(struct TCPConfirmation)) /** @@ -107,7 +107,8 @@ GNUNET_NETWORK_STRUCT_BEGIN * Signature we use to verify that the ephemeral key was really chosen by * the specified sender. */ -struct TcpHandshakeSignature { +struct TcpHandshakeSignature +{ /** * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE */ @@ -139,7 +140,8 @@ struct TcpHandshakeSignature { /** * Encrypted continuation of TCP initial handshake. */ -struct TCPConfirmation { +struct TCPConfirmation +{ /** * Sender's identity */ @@ -161,7 +163,8 @@ struct TCPConfirmation { /** * TCP message box. Always sent encrypted! */ -struct TCPBox { +struct TCPBox +{ /** * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX. Warning: the * header size EXCLUDES the size of the `struct TCPBox`. We usually @@ -189,7 +192,8 @@ struct TCPBox { * TCP rekey message box. Always sent encrypted! Data after * this message will use the new key. */ -struct TCPRekey { +struct TCPRekey +{ /** * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY. */ @@ -228,7 +232,8 @@ struct TCPRekey { * Needed/useful in case we drop RST/FIN packets on the GNUnet * port due to the possibility of malicious RST/FIN injection. */ -struct TCPFinish { +struct TCPFinish +{ /** * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH. */ @@ -252,7 +257,8 @@ GNUNET_NETWORK_STRUCT_END /** * Handle for a queue. */ -struct Queue { +struct Queue +{ /** * To whom are we talking to. */ @@ -430,7 +436,8 @@ struct Queue { * Handle for an incoming connection where we do not yet have enough * information to setup a full queue. */ -struct ProtoQueue { +struct ProtoQueue +{ /** * Kept in a DLL. */ @@ -553,7 +560,7 @@ static struct ProtoQueue *proto_tail; * @param cls NULL */ static void -listen_cb(void *cls); +listen_cb (void *cls); /** @@ -564,53 +571,53 @@ listen_cb(void *cls); * @param queue queue to close down */ static void -queue_destroy(struct Queue *queue) +queue_destroy (struct Queue *queue) { struct GNUNET_MQ_Handle *mq; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting queue for peer `%s'\n", - GNUNET_i2s(&queue->target)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Disconnecting queue for peer `%s'\n", + GNUNET_i2s (&queue->target)); if (NULL != (mq = queue->mq)) - { - queue->mq = NULL; - GNUNET_MQ_destroy(mq); - } + { + queue->mq = NULL; + GNUNET_MQ_destroy (mq); + } if (NULL != queue->qh) - { - GNUNET_TRANSPORT_communicator_mq_del(queue->qh); - queue->qh = NULL; - } - GNUNET_assert( + { + GNUNET_TRANSPORT_communicator_mq_del (queue->qh); + queue->qh = NULL; + } + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(queue_map, &queue->target, queue)); - GNUNET_STATISTICS_set(stats, - "# queues active", - GNUNET_CONTAINER_multipeermap_size(queue_map), - GNUNET_NO); + GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue)); + GNUNET_STATISTICS_set (stats, + "# queues active", + GNUNET_CONTAINER_multipeermap_size (queue_map), + GNUNET_NO); if (NULL != queue->read_task) - { - GNUNET_SCHEDULER_cancel(queue->read_task); - queue->read_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (queue->read_task); + queue->read_task = NULL; + } if (NULL != queue->write_task) - { - GNUNET_SCHEDULER_cancel(queue->write_task); - queue->write_task = NULL; - } - GNUNET_NETWORK_socket_close(queue->sock); - gcry_cipher_close(queue->in_cipher); - gcry_cipher_close(queue->out_cipher); - GNUNET_free(queue->address); + { + GNUNET_SCHEDULER_cancel (queue->write_task); + queue->write_task = NULL; + } + GNUNET_NETWORK_socket_close (queue->sock); + gcry_cipher_close (queue->in_cipher); + gcry_cipher_close (queue->out_cipher); + GNUNET_free (queue->address); if (0 != queue->backpressure) queue->destroyed = GNUNET_YES; else - GNUNET_free(queue); + GNUNET_free (queue); if (NULL == listen_task) - listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - listen_sock, - &listen_cb, - NULL); + listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + listen_sock, + &listen_cb, + NULL); } @@ -623,24 +630,24 @@ queue_destroy(struct Queue *queue) * @param smac[out] where to write the HMAC */ static void -calculate_hmac(struct GNUNET_HashCode *hmac_secret, - const void *buf, - size_t buf_size, - struct GNUNET_ShortHashCode *smac) +calculate_hmac (struct GNUNET_HashCode *hmac_secret, + const void *buf, + size_t buf_size, + struct GNUNET_ShortHashCode *smac) { struct GNUNET_HashCode mac; - GNUNET_CRYPTO_hmac_raw(hmac_secret, - sizeof(struct GNUNET_HashCode), - buf, - buf_size, - &mac); + GNUNET_CRYPTO_hmac_raw (hmac_secret, + sizeof(struct GNUNET_HashCode), + buf, + buf_size, + &mac); /* truncate to `struct GNUNET_ShortHashCode` */ - memcpy(smac, &mac, sizeof(struct GNUNET_ShortHashCode)); + memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode)); /* ratchet hmac key */ - GNUNET_CRYPTO_hash(hmac_secret, - sizeof(struct GNUNET_HashCode), - hmac_secret); + GNUNET_CRYPTO_hash (hmac_secret, + sizeof(struct GNUNET_HashCode), + hmac_secret); } @@ -651,18 +658,18 @@ calculate_hmac(struct GNUNET_HashCode *hmac_secret, * @param queue queue to shut down nicely */ static void -queue_finish(struct Queue *queue) +queue_finish (struct Queue *queue) { struct TCPFinish fin; - memset(&fin, 0, sizeof(fin)); - fin.header.size = htons(sizeof(fin)); - fin.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH); - calculate_hmac(&queue->out_hmac, &fin, sizeof(fin), &fin.hmac); + memset (&fin, 0, sizeof(fin)); + fin.header.size = htons (sizeof(fin)); + fin.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH); + calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac); /* if there is any message left in pwrite_buf, we overwrite it (possibly dropping the last message from CORE hard here) */ - memcpy(queue->pwrite_buf, &fin, sizeof(fin)); + memcpy (queue->pwrite_buf, &fin, sizeof(fin)); queue->pwrite_off = sizeof(fin); /* This flag will ensure that #queue_write() no longer notifies CORE about the possibility of sending @@ -680,10 +687,10 @@ queue_finish(struct Queue *queue) * @param queue queue for which the timeout should be rescheduled */ static void -reschedule_queue_timeout(struct Queue *queue) +reschedule_queue_timeout (struct Queue *queue) { queue->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); } @@ -693,7 +700,7 @@ reschedule_queue_timeout(struct Queue *queue) * @param cls the `struct Queue *` to disconnect */ static void -queue_read(void *cls); +queue_read (void *cls); /** @@ -704,31 +711,31 @@ queue_read(void *cls); * @param success #GNUNET_OK on success */ static void -core_read_finished_cb(void *cls, int success) +core_read_finished_cb (void *cls, int success) { struct Queue *queue = cls; if (GNUNET_OK != success) - GNUNET_STATISTICS_update(stats, - "# messages lost in communicator API towards CORE", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (stats, + "# messages lost in communicator API towards CORE", + 1, + GNUNET_NO); queue->backpressure--; /* handle deferred queue destruction */ if ((queue->destroyed) && (0 == queue->backpressure)) - { - GNUNET_free(queue); - return; - } - reschedule_queue_timeout(queue); + { + GNUNET_free (queue); + return; + } + reschedule_queue_timeout (queue); /* possibly unchoke reading, now that CORE made progress */ if (NULL == queue->read_task) queue->read_task = - GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_absolute_get_remaining( - queue->timeout), - queue->sock, - &queue_read, - queue); + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( + queue->timeout), + queue->sock, + &queue_read, + queue); } @@ -742,34 +749,34 @@ core_read_finished_cb(void *cls, int success) * @param plaintext_len number of bytes of plaintext received */ static void -pass_plaintext_to_core(struct Queue *queue, - const void *plaintext, - size_t plaintext_len) +pass_plaintext_to_core (struct Queue *queue, + const void *plaintext, + size_t plaintext_len) { const struct GNUNET_MessageHeader *hdr = plaintext; int ret; - if (ntohs(hdr->size) != plaintext_len) - { - /* NOTE: If we ever allow multiple CORE messages in one - BOX, this will have to change! */ - GNUNET_break(0); - return; - } - ret = GNUNET_TRANSPORT_communicator_receive(ch, - &queue->target, - hdr, - ADDRESS_VALIDITY_PERIOD, - &core_read_finished_cb, - queue); + if (ntohs (hdr->size) != plaintext_len) + { + /* NOTE: If we ever allow multiple CORE messages in one + BOX, this will have to change! */ + GNUNET_break (0); + return; + } + ret = GNUNET_TRANSPORT_communicator_receive (ch, + &queue->target, + hdr, + ADDRESS_VALIDITY_PERIOD, + &core_read_finished_cb, + queue); if (GNUNET_OK == ret) queue->backpressure++; - GNUNET_break(GNUNET_NO != ret); /* backpressure not working!? */ + GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */ if (GNUNET_SYSERR == ret) - GNUNET_STATISTICS_update(stats, - "# bytes lost due to CORE not running", - plaintext_len, - GNUNET_NO); + GNUNET_STATISTICS_update (stats, + "# bytes lost due to CORE not running", + plaintext_len, + GNUNET_NO); } @@ -783,51 +790,51 @@ pass_plaintext_to_core(struct Queue *queue, * @param hmac_key[out] HMAC key to initialize */ static void -setup_cipher(const struct GNUNET_HashCode *dh, - const struct GNUNET_PeerIdentity *pid, - gcry_cipher_hd_t *cipher, - struct GNUNET_HashCode *hmac_key) +setup_cipher (const struct GNUNET_HashCode *dh, + const struct GNUNET_PeerIdentity *pid, + gcry_cipher_hd_t *cipher, + struct GNUNET_HashCode *hmac_key) { char key[256 / 8]; char ctr[128 / 8]; - gcry_cipher_open(cipher, - GCRY_CIPHER_AES256 /* low level: go for speed */, - GCRY_CIPHER_MODE_CTR, - 0 /* flags */); - GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_kdf(key, - sizeof(key), - "TCP-key", - strlen("TCP-key"), - dh, - sizeof(*dh), - pid, - sizeof(*pid), - NULL, - 0)); - gcry_cipher_setkey(*cipher, key, sizeof(key)); - GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_kdf(ctr, - sizeof(ctr), - "TCP-ctr", - strlen("TCP-ctr"), - dh, - sizeof(*dh), - pid, - sizeof(*pid), - NULL, - 0)); - gcry_cipher_setctr(*cipher, ctr, sizeof(ctr)); - GNUNET_assert(GNUNET_YES == - GNUNET_CRYPTO_kdf(hmac_key, - sizeof(struct GNUNET_HashCode), - "TCP-hmac", - strlen("TCP-hmac"), - dh, - sizeof(*dh), - pid, - sizeof(*pid), - NULL, - 0)); + gcry_cipher_open (cipher, + GCRY_CIPHER_AES256 /* low level: go for speed */, + GCRY_CIPHER_MODE_CTR, + 0 /* flags */); + GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_kdf (key, + sizeof(key), + "TCP-key", + strlen ("TCP-key"), + dh, + sizeof(*dh), + pid, + sizeof(*pid), + NULL, + 0)); + gcry_cipher_setkey (*cipher, key, sizeof(key)); + GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_kdf (ctr, + sizeof(ctr), + "TCP-ctr", + strlen ("TCP-ctr"), + dh, + sizeof(*dh), + pid, + sizeof(*pid), + NULL, + 0)); + gcry_cipher_setctr (*cipher, ctr, sizeof(ctr)); + GNUNET_assert (GNUNET_YES == + GNUNET_CRYPTO_kdf (hmac_key, + sizeof(struct GNUNET_HashCode), + "TCP-hmac", + strlen ("TCP-hmac"), + dh, + sizeof(*dh), + pid, + sizeof(*pid), + NULL, + 0)); } @@ -838,13 +845,13 @@ setup_cipher(const struct GNUNET_HashCode *dh, * @param queue[in,out] queue to initialize decryption cipher for */ static void -setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, - struct Queue *queue) +setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, + struct Queue *queue) { struct GNUNET_HashCode dh; - GNUNET_CRYPTO_eddsa_ecdh(my_private_key, ephemeral, &dh); - setup_cipher(&dh, &my_identity, &queue->in_cipher, &queue->in_hmac); + GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh); + setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac); } @@ -857,30 +864,30 @@ setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, * @param rekey the rekey message */ static void -do_rekey(struct Queue *queue, const struct TCPRekey *rekey) +do_rekey (struct Queue *queue, const struct TCPRekey *rekey) { struct TcpHandshakeSignature thp; - thp.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); - thp.purpose.size = htonl(sizeof(thp)); + thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); + thp.purpose.size = htonl (sizeof(thp)); thp.sender = queue->target; thp.receiver = my_identity; thp.ephemeral = rekey->ephemeral; thp.monotonic_time = rekey->monotonic_time; /* FIXME: check monotonic time is monotonic... */ if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, - &thp.purpose, - &rekey->sender_sig, - &queue->target.public_key)) - { - GNUNET_break(0); - queue_finish(queue); - return; - } - gcry_cipher_close(queue->in_cipher); + GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, + &thp.purpose, + &rekey->sender_sig, + &queue->target.public_key)) + { + GNUNET_break (0); + queue_finish (queue); + return; + } + gcry_cipher_close (queue->in_cipher); queue->rekeyed = GNUNET_YES; - setup_in_cipher(&rekey->ephemeral, queue); + setup_in_cipher (&rekey->ephemeral, queue); } @@ -892,13 +899,13 @@ do_rekey(struct Queue *queue, const struct TCPRekey *rekey) * @return number of bytes of plaintext handled, 0 for none */ static size_t -try_handle_plaintext(struct Queue *queue) +try_handle_plaintext (struct Queue *queue) { const struct GNUNET_MessageHeader *hdr = - (const struct GNUNET_MessageHeader *)queue->pread_buf; - const struct TCPBox *box = (const struct TCPBox *)queue->pread_buf; - const struct TCPRekey *rekey = (const struct TCPRekey *)queue->pread_buf; - const struct TCPFinish *fin = (const struct TCPFinish *)queue->pread_buf; + (const struct GNUNET_MessageHeader *) queue->pread_buf; + const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf; + const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf; + const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf; struct TCPRekey rekeyz; struct TCPFinish finz; struct GNUNET_ShortHashCode tmac; @@ -907,74 +914,74 @@ try_handle_plaintext(struct Queue *queue) if (sizeof(*hdr) > queue->pread_off) return 0; /* not even a header */ - type = ntohs(hdr->type); + type = ntohs (hdr->type); switch (type) + { + case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX: + /* Special case: header size excludes box itself! */ + if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off) + return 0; + calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac); + if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac))) { - case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX: - /* Special case: header size excludes box itself! */ - if (ntohs(hdr->size) + sizeof(struct TCPBox) > queue->pread_off) - return 0; - calculate_hmac(&queue->in_hmac, &box[1], ntohs(hdr->size), &tmac); - if (0 != memcmp(&tmac, &box->hmac, sizeof(tmac))) - { - GNUNET_break_op(0); - queue_finish(queue); - return 0; - } - pass_plaintext_to_core(queue, (const void *)&box[1], ntohs(hdr->size)); - size = ntohs(hdr->size) + sizeof(*box); - break; - - case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY: - if (sizeof(*rekey) > queue->pread_off) - return 0; - if (ntohs(hdr->size) != sizeof(*rekey)) - { - GNUNET_break_op(0); - queue_finish(queue); - return 0; - } - rekeyz = *rekey; - memset(&rekeyz.hmac, 0, sizeof(rekeyz.hmac)); - calculate_hmac(&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac); - if (0 != memcmp(&tmac, &box->hmac, sizeof(tmac))) - { - GNUNET_break_op(0); - queue_finish(queue); - return 0; - } - do_rekey(queue, rekey); - size = ntohs(hdr->size); - break; + GNUNET_break_op (0); + queue_finish (queue); + return 0; + } + pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size)); + size = ntohs (hdr->size) + sizeof(*box); + break; - case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH: - if (sizeof(*fin) > queue->pread_off) - return 0; - if (ntohs(hdr->size) != sizeof(*fin)) - { - GNUNET_break_op(0); - queue_finish(queue); - return 0; - } - finz = *fin; - memset(&finz.hmac, 0, sizeof(finz.hmac)); - calculate_hmac(&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac); - if (0 != memcmp(&tmac, &fin->hmac, sizeof(tmac))) - { - GNUNET_break_op(0); - queue_finish(queue); - return 0; - } - /* handle FINISH by destroying queue */ - queue_destroy(queue); - break; + case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY: + if (sizeof(*rekey) > queue->pread_off) + return 0; + if (ntohs (hdr->size) != sizeof(*rekey)) + { + GNUNET_break_op (0); + queue_finish (queue); + return 0; + } + rekeyz = *rekey; + memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac)); + calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac); + if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac))) + { + GNUNET_break_op (0); + queue_finish (queue); + return 0; + } + do_rekey (queue, rekey); + size = ntohs (hdr->size); + break; - default: - GNUNET_break_op(0); - queue_finish(queue); + case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH: + if (sizeof(*fin) > queue->pread_off) + return 0; + if (ntohs (hdr->size) != sizeof(*fin)) + { + GNUNET_break_op (0); + queue_finish (queue); + return 0; + } + finz = *fin; + memset (&finz.hmac, 0, sizeof(finz.hmac)); + calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac); + if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac))) + { + GNUNET_break_op (0); + queue_finish (queue); return 0; } - GNUNET_assert(0 != size); + /* handle FINISH by destroying queue */ + queue_destroy (queue); + break; + + default: + GNUNET_break_op (0); + queue_finish (queue); + return 0; + } + GNUNET_assert (0 != size); return size; } @@ -985,96 +992,96 @@ try_handle_plaintext(struct Queue *queue) * @param cls the `struct Queue *` to disconnect */ static void -queue_read(void *cls) +queue_read (void *cls) { struct Queue *queue = cls; struct GNUNET_TIME_Relative left; ssize_t rcvd; queue->read_task = NULL; - rcvd = GNUNET_NETWORK_socket_recv(queue->sock, - &queue->cread_buf[queue->cread_off], - BUF_SIZE - queue->cread_off); + rcvd = GNUNET_NETWORK_socket_recv (queue->sock, + &queue->cread_buf[queue->cread_off], + BUF_SIZE - queue->cread_off); if (-1 == rcvd) + { + if ((EAGAIN != errno) && (EINTR != errno)) { - if ((EAGAIN != errno) && (EINTR != errno)) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv"); - queue_finish(queue); - return; - } - /* try again */ - queue->read_task = - GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read, queue); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); + queue_finish (queue); return; } + /* try again */ + queue->read_task = + GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue); + return; + } if (0 != rcvd) - reschedule_queue_timeout(queue); + reschedule_queue_timeout (queue); queue->cread_off += rcvd; while ((queue->pread_off < sizeof(queue->pread_buf)) && (queue->cread_off > 0)) - { - size_t max = GNUNET_MIN(sizeof(queue->pread_buf) - queue->pread_off, - queue->cread_off); - size_t done; - size_t total; + { + size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off, + queue->cread_off); + size_t done; + size_t total; - GNUNET_assert(0 == - gcry_cipher_decrypt(queue->in_cipher, + GNUNET_assert (0 == + gcry_cipher_decrypt (queue->in_cipher, &queue->pread_buf[queue->pread_off], max, queue->cread_buf, max)); - queue->pread_off += max; - total = 0; - while ((GNUNET_NO == queue->rekeyed) && - (0 != (done = try_handle_plaintext(queue)))) - { - /* 'done' bytes of plaintext were used, shift buffer */ - GNUNET_assert(done <= queue->pread_off); - /* NOTE: this memmove() could possibly sometimes be - avoided if we pass 'total' into try_handle_plaintext() - and use it at an offset into the buffer there! */ - memmove(queue->pread_buf, - &queue->pread_buf[done], - queue->pread_off - done); - queue->pread_off -= done; - total += done; - } - /* when we encounter a rekey message, the decryption above uses the - wrong key for everything after the rekey; in that case, we have - to re-do the decryption at 'total' instead of at 'max'. If there - is no rekey and the last message is incomplete (max > total), - it is safe to keep the decryption so we shift by 'max' */ - if (GNUNET_YES == queue->rekeyed) - { - max = total; - queue->rekeyed = GNUNET_NO; - } - memmove(queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max); - queue->cread_off -= max; + queue->pread_off += max; + total = 0; + while ((GNUNET_NO == queue->rekeyed) && + (0 != (done = try_handle_plaintext (queue)))) + { + /* 'done' bytes of plaintext were used, shift buffer */ + GNUNET_assert (done <= queue->pread_off); + /* NOTE: this memmove() could possibly sometimes be + avoided if we pass 'total' into try_handle_plaintext() + and use it at an offset into the buffer there! */ + memmove (queue->pread_buf, + &queue->pread_buf[done], + queue->pread_off - done); + queue->pread_off -= done; + total += done; + } + /* when we encounter a rekey message, the decryption above uses the + wrong key for everything after the rekey; in that case, we have + to re-do the decryption at 'total' instead of at 'max'. If there + is no rekey and the last message is incomplete (max > total), + it is safe to keep the decryption so we shift by 'max' */ + if (GNUNET_YES == queue->rekeyed) + { + max = total; + queue->rekeyed = GNUNET_NO; } + memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max); + queue->cread_off -= max; + } if (BUF_SIZE == queue->cread_off) return; /* buffer full, suspend reading */ - left = GNUNET_TIME_absolute_get_remaining(queue->timeout); + left = GNUNET_TIME_absolute_get_remaining (queue->timeout); if (0 != left.rel_value_us) + { + if (max_queue_length < queue->backpressure) { - if (max_queue_length < queue->backpressure) - { - /* continue reading */ - queue->read_task = - GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read, queue); - } - return; + /* continue reading */ + queue->read_task = + GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue); } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Queue %p was idle for %s, disconnecting\n", - queue, - GNUNET_STRINGS_relative_time_to_string( - GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - GNUNET_YES)); - queue_finish(queue); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Queue %p was idle for %s, disconnecting\n", + queue, + GNUNET_STRINGS_relative_time_to_string ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + GNUNET_YES)); + queue_finish (queue); } @@ -1086,7 +1093,7 @@ queue_read(void *cls) * @return converted bindto specification */ static struct sockaddr * -tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) +tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) { struct sockaddr *in; unsigned int port; @@ -1094,88 +1101,88 @@ tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) char *colon; char *cp; - if (1 == sscanf(bindto, "%u%1s", &port, dummy)) + if (1 == sscanf (bindto, "%u%1s", &port, dummy)) + { + /* interpreting value as just a PORT number */ + if (port > UINT16_MAX) { - /* interpreting value as just a PORT number */ - if (port > UINT16_MAX) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "BINDTO specification `%s' invalid: value too large for port\n", - bindto); - return NULL; - } - if ((GNUNET_NO == GNUNET_NETWORK_test_pf(PF_INET6)) || - (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno(cfg, - COMMUNICATOR_CONFIG_SECTION, - "DISABLE_V6"))) - { - struct sockaddr_in *i4; - - i4 = GNUNET_malloc(sizeof(struct sockaddr_in)); - i4->sin_family = AF_INET; - i4->sin_port = htons((uint16_t)port); - *sock_len = sizeof(struct sockaddr_in); - in = (struct sockaddr *)i4; - } - else - { - struct sockaddr_in6 *i6; - - i6 = GNUNET_malloc(sizeof(struct sockaddr_in6)); - i6->sin6_family = AF_INET6; - i6->sin6_port = htons((uint16_t)port); - *sock_len = sizeof(struct sockaddr_in6); - in = (struct sockaddr *)i6; - } - return in; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "BINDTO specification `%s' invalid: value too large for port\n", + bindto); + return NULL; + } + if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) || + (GNUNET_YES == + GNUNET_CONFIGURATION_get_value_yesno (cfg, + COMMUNICATOR_CONFIG_SECTION, + "DISABLE_V6"))) + { + struct sockaddr_in *i4; + + i4 = GNUNET_malloc (sizeof(struct sockaddr_in)); + i4->sin_family = AF_INET; + i4->sin_port = htons ((uint16_t) port); + *sock_len = sizeof(struct sockaddr_in); + in = (struct sockaddr *) i4; + } + else + { + struct sockaddr_in6 *i6; + + i6 = GNUNET_malloc (sizeof(struct sockaddr_in6)); + i6->sin6_family = AF_INET6; + i6->sin6_port = htons ((uint16_t) port); + *sock_len = sizeof(struct sockaddr_in6); + in = (struct sockaddr *) i6; } - cp = GNUNET_strdup(bindto); - colon = strrchr(cp, ':'); + return in; + } + cp = GNUNET_strdup (bindto); + colon = strrchr (cp, ':'); if (NULL != colon) + { + /* interpet value after colon as port */ + *colon = '\0'; + colon++; + if (1 == sscanf (colon, "%u%1s", &port, dummy)) { - /* interpet value after colon as port */ - *colon = '\0'; - colon++; - if (1 == sscanf(colon, "%u%1s", &port, dummy)) - { - /* interpreting value as just a PORT number */ - if (port > UINT16_MAX) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "BINDTO specification `%s' invalid: value too large for port\n", - bindto); - GNUNET_free(cp); - return NULL; - } - } - else - { - GNUNET_log( - GNUNET_ERROR_TYPE_ERROR, - "BINDTO specification `%s' invalid: last ':' not followed by number\n", - bindto); - GNUNET_free(cp); - return NULL; - } + /* interpreting value as just a PORT number */ + if (port > UINT16_MAX) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "BINDTO specification `%s' invalid: value too large for port\n", + bindto); + GNUNET_free (cp); + return NULL; + } } - else + else { - /* interpret missing port as 0, aka pick any free one */ - port = 0; + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + "BINDTO specification `%s' invalid: last ':' not followed by number\n", + bindto); + GNUNET_free (cp); + return NULL; } + } + else + { + /* interpret missing port as 0, aka pick any free one */ + port = 0; + } { /* try IPv4 */ struct sockaddr_in v4; - if (1 == inet_pton(AF_INET, cp, &v4)) - { - v4.sin_port = htons((uint16_t)port); - in = GNUNET_memdup(&v4, sizeof(v4)); - *sock_len = sizeof(v4); - GNUNET_free(cp); - return in; - } + if (1 == inet_pton (AF_INET, cp, &v4)) + { + v4.sin_port = htons ((uint16_t) port); + in = GNUNET_memdup (&v4, sizeof(v4)); + *sock_len = sizeof(v4); + GNUNET_free (cp); + return in; + } } { /* try IPv6 */ @@ -1183,22 +1190,22 @@ tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) const char *start; start = cp; - if (('[' == *cp) && (']' == cp[strlen(cp) - 1])) - { - start++; /* skip over '[' */ - cp[strlen(cp) - 1] = '\0'; /* eat ']' */ - } - if (1 == inet_pton(AF_INET6, start, &v6)) - { - v6.sin6_port = htons((uint16_t)port); - in = GNUNET_memdup(&v6, sizeof(v6)); - *sock_len = sizeof(v6); - GNUNET_free(cp); - return in; - } + if (('[' == *cp) && (']' == cp[strlen (cp) - 1])) + { + start++; /* skip over '[' */ + cp[strlen (cp) - 1] = '\0'; /* eat ']' */ + } + if (1 == inet_pton (AF_INET6, start, &v6)) + { + v6.sin6_port = htons ((uint16_t) port); + in = GNUNET_memdup (&v6, sizeof(v6)); + *sock_len = sizeof(v6); + GNUNET_free (cp); + return in; + } } /* #5528 FIXME (feature!): maybe also try getnameinfo()? */ - GNUNET_free(cp); + GNUNET_free (cp); return NULL; } @@ -1210,17 +1217,17 @@ tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) * @param queue queue to setup outgoing (encryption) cipher for */ static void -setup_out_cipher(struct Queue *queue) +setup_out_cipher (struct Queue *queue) { struct GNUNET_HashCode dh; - GNUNET_CRYPTO_ecdh_eddsa(&queue->ephemeral, &queue->target.public_key, &dh); + GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh); /* we don't need the private key anymore, drop it! */ - memset(&queue->ephemeral, 0, sizeof(queue->ephemeral)); - setup_cipher(&dh, &queue->target, &queue->out_cipher, &queue->out_hmac); - queue->rekey_time = GNUNET_TIME_relative_to_absolute(REKEY_TIME_INTERVAL); + memset (&queue->ephemeral, 0, sizeof(queue->ephemeral)); + setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac); + queue->rekey_time = GNUNET_TIME_relative_to_absolute (REKEY_TIME_INTERVAL); queue->rekey_left_bytes = - GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, REKEY_MAX_BYTES); + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, REKEY_MAX_BYTES); } @@ -1231,31 +1238,31 @@ setup_out_cipher(struct Queue *queue) * @param queue queue to perform rekeying on */ static void -inject_rekey(struct Queue *queue) +inject_rekey (struct Queue *queue) { struct TCPRekey rekey; struct TcpHandshakeSignature thp; - GNUNET_assert(0 == queue->pwrite_off); - memset(&rekey, 0, sizeof(rekey)); - GNUNET_assert(GNUNET_OK == - GNUNET_CRYPTO_ecdhe_key_create2(&queue->ephemeral)); - rekey.header.type = ntohs(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); - rekey.header.size = ntohs(sizeof(rekey)); - GNUNET_CRYPTO_ecdhe_key_get_public(&queue->ephemeral, &rekey.ephemeral); + GNUNET_assert (0 == queue->pwrite_off); + memset (&rekey, 0, sizeof(rekey)); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); + rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); + rekey.header.size = ntohs (sizeof(rekey)); + GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral); rekey.monotonic_time = - GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg)); - thp.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); - thp.purpose.size = htonl(sizeof(thp)); + GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); + thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); + thp.purpose.size = htonl (sizeof(thp)); thp.sender = my_identity; thp.receiver = queue->target; thp.ephemeral = rekey.ephemeral; thp.monotonic_time = rekey.monotonic_time; - GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, - &thp.purpose, - &rekey.sender_sig)); - calculate_hmac(&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac); - memcpy(queue->pwrite_buf, &rekey, sizeof(rekey)); + GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, + &thp.purpose, + &rekey.sender_sig)); + calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac); + memcpy (queue->pwrite_buf, &rekey, sizeof(rekey)); queue->pwrite_off = sizeof(rekey); } @@ -1267,79 +1274,79 @@ inject_rekey(struct Queue *queue) * @param cls a `struct Queue` */ static void -queue_write(void *cls) +queue_write (void *cls) { struct Queue *queue = cls; ssize_t sent; queue->write_task = NULL; if (0 != queue->cwrite_off) + { + sent = GNUNET_NETWORK_socket_send (queue->sock, + queue->cwrite_buf, + queue->cwrite_off); + if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); + queue_destroy (queue); + return; + } + if (sent > 0) { - sent = GNUNET_NETWORK_socket_send(queue->sock, - queue->cwrite_buf, - queue->cwrite_off); - if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno)) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send"); - queue_destroy(queue); - return; - } - if (sent > 0) - { - size_t usent = (size_t)sent; - - memmove(queue->cwrite_buf, - &queue->cwrite_buf[usent], - queue->cwrite_off - usent); - reschedule_queue_timeout(queue); - } + size_t usent = (size_t) sent; + + memmove (queue->cwrite_buf, + &queue->cwrite_buf[usent], + queue->cwrite_off - usent); + reschedule_queue_timeout (queue); } + } /* can we encrypt more? (always encrypt full messages, needed such that #mq_cancel() can work!) */ if ((0 < queue->rekey_left_bytes) && (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE)) - { - GNUNET_assert(0 == - gcry_cipher_encrypt(queue->out_cipher, + { + GNUNET_assert (0 == + gcry_cipher_encrypt (queue->out_cipher, &queue->cwrite_buf[queue->cwrite_off], queue->pwrite_off, queue->pwrite_buf, queue->pwrite_off)); - if (queue->rekey_left_bytes > queue->pwrite_off) - queue->rekey_left_bytes -= queue->pwrite_off; - else - queue->rekey_left_bytes = 0; - queue->cwrite_off += queue->pwrite_off; - queue->pwrite_off = 0; - } + if (queue->rekey_left_bytes > queue->pwrite_off) + queue->rekey_left_bytes -= queue->pwrite_off; + else + queue->rekey_left_bytes = 0; + queue->cwrite_off += queue->pwrite_off; + queue->pwrite_off = 0; + } if ((0 == queue->pwrite_off) && ((0 == queue->rekey_left_bytes) || (0 == - GNUNET_TIME_absolute_get_remaining(queue->rekey_time).rel_value_us))) - { - gcry_cipher_close(queue->out_cipher); - setup_out_cipher(queue); - inject_rekey(queue); - } - if ((0 == queue->pwrite_off) && (!queue->finishing) && + GNUNET_TIME_absolute_get_remaining (queue->rekey_time).rel_value_us))) + { + gcry_cipher_close (queue->out_cipher); + setup_out_cipher (queue); + inject_rekey (queue); + } + if ((0 == queue->pwrite_off) && (! queue->finishing) && (queue->mq_awaits_continue)) - { - queue->mq_awaits_continue = GNUNET_NO; - GNUNET_MQ_impl_send_continue(queue->mq); - } + { + queue->mq_awaits_continue = GNUNET_NO; + GNUNET_MQ_impl_send_continue (queue->mq); + } /* did we just finish writing 'finish'? */ if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing)) - { - queue_destroy(queue); - return; - } + { + queue_destroy (queue); + return; + } /* do we care to write more? */ if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off)) queue->write_task = - GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, - queue->sock, - &queue_write, - queue); + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + queue->sock, + &queue_write, + queue); } @@ -1352,32 +1359,32 @@ queue_write(void *cls) * @param impl_state our `struct Queue` */ static void -mq_send(struct GNUNET_MQ_Handle *mq, - const struct GNUNET_MessageHeader *msg, - void *impl_state) +mq_send (struct GNUNET_MQ_Handle *mq, + const struct GNUNET_MessageHeader *msg, + void *impl_state) { struct Queue *queue = impl_state; - uint16_t msize = ntohs(msg->size); + uint16_t msize = ntohs (msg->size); struct TCPBox box; - GNUNET_assert(mq == queue->mq); + GNUNET_assert (mq == queue->mq); if (GNUNET_YES == queue->finishing) return; /* this queue is dying, drop msg */ - GNUNET_assert(0 == queue->pread_off); - box.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX); - box.header.size = htons(msize); - calculate_hmac(&queue->out_hmac, msg, msize, &box.hmac); - memcpy(&queue->pread_buf[queue->pread_off], &box, sizeof(box)); + GNUNET_assert (0 == queue->pread_off); + box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX); + box.header.size = htons (msize); + calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac); + memcpy (&queue->pread_buf[queue->pread_off], &box, sizeof(box)); queue->pread_off += sizeof(box); - memcpy(&queue->pread_buf[queue->pread_off], msg, msize); + memcpy (&queue->pread_buf[queue->pread_off], msg, msize); queue->pread_off += msize; - GNUNET_assert(NULL != queue->sock); + GNUNET_assert (NULL != queue->sock); if (NULL == queue->write_task) queue->write_task = - GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, - queue->sock, - &queue_write, - queue); + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + queue->sock, + &queue_write, + queue); } @@ -1390,15 +1397,15 @@ mq_send(struct GNUNET_MQ_Handle *mq, * @param impl_state our `struct Queue` */ static void -mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) +mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct Queue *queue = impl_state; if (mq == queue->mq) - { - queue->mq = NULL; - queue_finish(queue); - } + { + queue->mq = NULL; + queue_finish (queue); + } } @@ -1409,11 +1416,11 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) * @param impl_state our `struct Queue` */ static void -mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) +mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct Queue *queue = impl_state; - GNUNET_assert(0 != queue->pwrite_off); + GNUNET_assert (0 != queue->pwrite_off); queue->pwrite_off = 0; } @@ -1428,15 +1435,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) * @param error error code */ static void -mq_error(void *cls, enum GNUNET_MQ_Error error) +mq_error (void *cls, enum GNUNET_MQ_Error error) { struct Queue *queue = cls; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "MQ error in queue to %s: %d\n", - GNUNET_i2s(&queue->target), - (int)error); - queue_finish(queue); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "MQ error in queue to %s: %d\n", + GNUNET_i2s (&queue->target), + (int) error); + queue_finish (queue); } @@ -1448,58 +1455,58 @@ mq_error(void *cls, enum GNUNET_MQ_Error error) * @param queue queue to boot */ static void -boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs) +boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs) { queue->nt = - GNUNET_NT_scanner_get_type(is, queue->address, queue->address_len); - (void)GNUNET_CONTAINER_multipeermap_put( + GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len); + (void) GNUNET_CONTAINER_multipeermap_put ( queue_map, &queue->target, queue, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GNUNET_STATISTICS_set(stats, - "# queues active", - GNUNET_CONTAINER_multipeermap_size(queue_map), - GNUNET_NO); + GNUNET_STATISTICS_set (stats, + "# queues active", + GNUNET_CONTAINER_multipeermap_size (queue_map), + GNUNET_NO); queue->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); - queue->mq = GNUNET_MQ_queue_for_callbacks(&mq_send, - &mq_destroy, - &mq_cancel, - queue, - NULL, - &mq_error, - queue); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + queue->mq = GNUNET_MQ_queue_for_callbacks (&mq_send, + &mq_destroy, + &mq_cancel, + queue, + NULL, + &mq_error, + queue); { char *foreign_addr; switch (queue->address->sa_family) - { - case AF_INET: - GNUNET_asprintf(&foreign_addr, - "%s-%s", - COMMUNICATOR_ADDRESS_PREFIX, - GNUNET_a2s(queue->address, queue->address_len)); - break; - - case AF_INET6: - GNUNET_asprintf(&foreign_addr, - "%s-%s", - COMMUNICATOR_ADDRESS_PREFIX, - GNUNET_a2s(queue->address, queue->address_len)); - break; - - default: - GNUNET_assert(0); - } - queue->qh = GNUNET_TRANSPORT_communicator_mq_add(ch, - &queue->target, - foreign_addr, - 0 /* no MTU */, - queue->nt, - cs, - queue->mq); - GNUNET_free(foreign_addr); + { + case AF_INET: + GNUNET_asprintf (&foreign_addr, + "%s-%s", + COMMUNICATOR_ADDRESS_PREFIX, + GNUNET_a2s (queue->address, queue->address_len)); + break; + + case AF_INET6: + GNUNET_asprintf (&foreign_addr, + "%s-%s", + COMMUNICATOR_ADDRESS_PREFIX, + GNUNET_a2s (queue->address, queue->address_len)); + break; + + default: + GNUNET_assert (0); + } + queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, + &queue->target, + foreign_addr, + 0 /* no MTU */, + queue->nt, + cs, + queue->mq); + GNUNET_free (foreign_addr); } } @@ -1515,33 +1522,33 @@ boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs) * @param epub our public key for the KX */ static void -transmit_kx(struct Queue *queue, - const struct GNUNET_CRYPTO_EcdhePublicKey *epub) +transmit_kx (struct Queue *queue, + const struct GNUNET_CRYPTO_EcdhePublicKey *epub) { struct TcpHandshakeSignature ths; struct TCPConfirmation tc; - memcpy(queue->cwrite_buf, epub, sizeof(*epub)); + memcpy (queue->cwrite_buf, epub, sizeof(*epub)); queue->cwrite_off = sizeof(epub); /* compute 'tc' and append in encrypted format to cwrite_buf */ tc.sender = my_identity; tc.monotonic_time = - GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg)); - ths.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); - ths.purpose.size = htonl(sizeof(ths)); + GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); + ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); + ths.purpose.size = htonl (sizeof(ths)); ths.sender = my_identity; ths.receiver = queue->target; ths.ephemeral = *epub; ths.monotonic_time = tc.monotonic_time; - GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, - &ths.purpose, - &tc.sender_sig)); - GNUNET_assert(0 == - gcry_cipher_encrypt(queue->out_cipher, - &queue->cwrite_buf[queue->cwrite_off], - sizeof(tc), - &tc, - sizeof(tc))); + GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, + &ths.purpose, + &tc.sender_sig)); + GNUNET_assert (0 == + gcry_cipher_encrypt (queue->out_cipher, + &queue->cwrite_buf[queue->cwrite_off], + sizeof(tc), + &tc, + sizeof(tc))); queue->cwrite_off += sizeof(tc); } @@ -1554,15 +1561,15 @@ transmit_kx(struct Queue *queue, * @param queue the queue to setup */ static void -start_initial_kx_out(struct Queue *queue) +start_initial_kx_out (struct Queue *queue) { struct GNUNET_CRYPTO_EcdhePublicKey epub; - GNUNET_assert(GNUNET_OK == - GNUNET_CRYPTO_ecdhe_key_create2(&queue->ephemeral)); - GNUNET_CRYPTO_ecdhe_key_get_public(&queue->ephemeral, &epub); - setup_out_cipher(queue); - transmit_kx(queue, &epub); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); + GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &epub); + setup_out_cipher (queue); + transmit_kx (queue, &epub); } @@ -1578,31 +1585,32 @@ start_initial_kx_out(struct Queue *queue) * @return #GNUNET_OK if the signature was OK, #GNUNET_SYSERR if not */ static int -decrypt_and_check_tc(struct Queue *queue, - struct TCPConfirmation *tc, - char *ibuf) +decrypt_and_check_tc (struct Queue *queue, + struct TCPConfirmation *tc, + char *ibuf) { struct TcpHandshakeSignature ths; - GNUNET_assert( + GNUNET_assert ( 0 == - gcry_cipher_decrypt(queue->in_cipher, - tc, - sizeof(*tc), - &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)], - sizeof(tc))); - ths.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); - ths.purpose.size = htonl(sizeof(ths)); + gcry_cipher_decrypt (queue->in_cipher, + tc, + sizeof(*tc), + &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)], + sizeof(tc))); + ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); + ths.purpose.size = htonl (sizeof(ths)); ths.sender = tc->sender; ths.receiver = my_identity; - memcpy(&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)); + memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)); ths.monotonic_time = tc->monotonic_time; /* FIXME: check monotonic time against previous mono times from this sender! */ - return GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, - &ths.purpose, - &tc->sender_sig, - &tc->sender.public_key); + return GNUNET_CRYPTO_eddsa_verify ( + GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, + &ths.purpose, + &tc->sender_sig, + &tc->sender.public_key); } @@ -1612,12 +1620,12 @@ decrypt_and_check_tc(struct Queue *queue, * @param pq proto queue to free */ static void -free_proto_queue(struct ProtoQueue *pq) +free_proto_queue (struct ProtoQueue *pq) { - GNUNET_NETWORK_socket_close(pq->sock); - GNUNET_free(pq->address); - GNUNET_CONTAINER_DLL_remove(proto_head, proto_tail, pq); - GNUNET_free(pq); + GNUNET_NETWORK_socket_close (pq->sock); + GNUNET_free (pq->address); + GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq); + GNUNET_free (pq); } @@ -1628,7 +1636,7 @@ free_proto_queue(struct ProtoQueue *pq) * @param cls a `struct ProtoQueue` */ static void -proto_read_kx(void *cls) +proto_read_kx (void *cls) { struct ProtoQueue *pq = cls; ssize_t rcvd; @@ -1637,67 +1645,67 @@ proto_read_kx(void *cls) struct TCPConfirmation tc; pq->read_task = NULL; - left = GNUNET_TIME_absolute_get_remaining(pq->timeout); + left = GNUNET_TIME_absolute_get_remaining (pq->timeout); if (0 == left.rel_value_us) - { - free_proto_queue(pq); - return; - } - rcvd = GNUNET_NETWORK_socket_recv(pq->sock, - &pq->ibuf[pq->ibuf_off], - sizeof(pq->ibuf) - pq->ibuf_off); + { + free_proto_queue (pq); + return; + } + rcvd = GNUNET_NETWORK_socket_recv (pq->sock, + &pq->ibuf[pq->ibuf_off], + sizeof(pq->ibuf) - pq->ibuf_off); if (-1 == rcvd) + { + if ((EAGAIN != errno) && (EINTR != errno)) { - if ((EAGAIN != errno) && (EINTR != errno)) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv"); - free_proto_queue(pq); - return; - } - /* try again */ - pq->read_task = - GNUNET_SCHEDULER_add_read_net(left, pq->sock, &proto_read_kx, pq); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); + free_proto_queue (pq); return; } + /* try again */ + pq->read_task = + GNUNET_SCHEDULER_add_read_net (left, pq->sock, &proto_read_kx, pq); + return; + } pq->ibuf_off += rcvd; if (pq->ibuf_off > sizeof(pq->ibuf)) - { - /* read more */ - pq->read_task = - GNUNET_SCHEDULER_add_read_net(left, pq->sock, &proto_read_kx, pq); - return; - } + { + /* read more */ + pq->read_task = + GNUNET_SCHEDULER_add_read_net (left, pq->sock, &proto_read_kx, pq); + return; + } /* we got all the data, let's find out who we are talking to! */ - queue = GNUNET_new(struct Queue); - setup_in_cipher((const struct GNUNET_CRYPTO_EcdhePublicKey *)pq->ibuf, - queue); - if (GNUNET_OK != decrypt_and_check_tc(queue, &tc, pq->ibuf)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Invalid TCP KX received from %s\n", - GNUNET_a2s(queue->address, queue->address_len)); - gcry_cipher_close(queue->in_cipher); - GNUNET_free(queue); - free_proto_queue(pq); - return; - } + queue = GNUNET_new (struct Queue); + setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf, + queue); + if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Invalid TCP KX received from %s\n", + GNUNET_a2s (queue->address, queue->address_len)); + gcry_cipher_close (queue->in_cipher); + GNUNET_free (queue); + free_proto_queue (pq); + return; + } queue->address = pq->address; /* steals reference */ queue->address_len = pq->address_len; queue->target = tc.sender; - start_initial_kx_out(queue); - boot_queue(queue, GNUNET_TRANSPORT_CS_INBOUND); + start_initial_kx_out (queue); + boot_queue (queue, GNUNET_TRANSPORT_CS_INBOUND); queue->read_task = - GNUNET_SCHEDULER_add_read_net(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - queue->sock, - &queue_read, - queue); - queue->write_task = - GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, queue->sock, - &queue_write, + &queue_read, queue); - GNUNET_CONTAINER_DLL_remove(proto_head, proto_tail, pq); - GNUNET_free(pq); + queue->write_task = + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + queue->sock, + &queue_write, + queue); + GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq); + GNUNET_free (pq); } @@ -1709,7 +1717,7 @@ proto_read_kx(void *cls) * @param cls NULL */ static void -listen_cb(void *cls) +listen_cb (void *cls) { struct sockaddr_storage in; socklen_t addrlen; @@ -1717,35 +1725,35 @@ listen_cb(void *cls) struct ProtoQueue *pq; listen_task = NULL; - GNUNET_assert(NULL != listen_sock); + GNUNET_assert (NULL != listen_sock); addrlen = sizeof(in); - memset(&in, 0, sizeof(in)); - sock = GNUNET_NETWORK_socket_accept(listen_sock, - (struct sockaddr *)&in, - &addrlen); + memset (&in, 0, sizeof(in)); + sock = GNUNET_NETWORK_socket_accept (listen_sock, + (struct sockaddr *) &in, + &addrlen); if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno))) return; /* system limit reached, wait until connection goes down */ - listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - listen_sock, - &listen_cb, - NULL); + listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + listen_sock, + &listen_cb, + NULL); if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno))) return; if (NULL == sock) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "accept"); - return; - } - pq = GNUNET_new(struct ProtoQueue); + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept"); + return; + } + pq = GNUNET_new (struct ProtoQueue); pq->address_len = addrlen; - pq->address = GNUNET_memdup(&in, addrlen); - pq->timeout = GNUNET_TIME_relative_to_absolute(PROTO_QUEUE_TIMEOUT); + pq->address = GNUNET_memdup (&in, addrlen); + pq->timeout = GNUNET_TIME_relative_to_absolute (PROTO_QUEUE_TIMEOUT); pq->sock = sock; - pq->read_task = GNUNET_SCHEDULER_add_read_net(PROTO_QUEUE_TIMEOUT, - pq->sock, - &proto_read_kx, - pq); - GNUNET_CONTAINER_DLL_insert(proto_head, proto_tail, pq); + pq->read_task = GNUNET_SCHEDULER_add_read_net (PROTO_QUEUE_TIMEOUT, + pq->sock, + &proto_read_kx, + pq); + GNUNET_CONTAINER_DLL_insert (proto_head, proto_tail, pq); } @@ -1757,7 +1765,7 @@ listen_cb(void *cls) * @param cls a `struct Queue` */ static void -queue_read_kx(void *cls) +queue_read_kx (void *cls) { struct Queue *queue = cls; ssize_t rcvd; @@ -1765,65 +1773,65 @@ queue_read_kx(void *cls) struct TCPConfirmation tc; queue->read_task = NULL; - left = GNUNET_TIME_absolute_get_remaining(queue->timeout); + left = GNUNET_TIME_absolute_get_remaining (queue->timeout); if (0 == left.rel_value_us) - { - queue_destroy(queue); - return; - } - rcvd = GNUNET_NETWORK_socket_recv(queue->sock, - &queue->cread_buf[queue->cread_off], - BUF_SIZE - queue->cread_off); + { + queue_destroy (queue); + return; + } + rcvd = GNUNET_NETWORK_socket_recv (queue->sock, + &queue->cread_buf[queue->cread_off], + BUF_SIZE - queue->cread_off); if (-1 == rcvd) + { + if ((EAGAIN != errno) && (EINTR != errno)) { - if ((EAGAIN != errno) && (EINTR != errno)) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv"); - queue_destroy(queue); - return; - } - queue->read_task = - GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read_kx, queue); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); + queue_destroy (queue); return; } + queue->read_task = + GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue); + return; + } queue->cread_off += rcvd; if (queue->cread_off < INITIAL_KX_SIZE) - { - /* read more */ - queue->read_task = - GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read_kx, queue); - return; - } + { + /* read more */ + queue->read_task = + GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue); + return; + } /* we got all the data, let's find out who we are talking to! */ - setup_in_cipher((const struct GNUNET_CRYPTO_EcdhePublicKey *) - queue->cread_buf, - queue); - if (GNUNET_OK != decrypt_and_check_tc(queue, &tc, queue->cread_buf)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Invalid TCP KX received from %s\n", - GNUNET_a2s(queue->address, queue->address_len)); - queue_destroy(queue); - return; - } + setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) + queue->cread_buf, + queue); + if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Invalid TCP KX received from %s\n", + GNUNET_a2s (queue->address, queue->address_len)); + queue_destroy (queue); + return; + } if (0 != - memcmp(&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity))) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Invalid sender in TCP KX received from %s\n", - GNUNET_a2s(queue->address, queue->address_len)); - queue_destroy(queue); - return; - } + memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity))) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Invalid sender in TCP KX received from %s\n", + GNUNET_a2s (queue->address, queue->address_len)); + queue_destroy (queue); + return; + } /* update queue timeout */ - reschedule_queue_timeout(queue); + reschedule_queue_timeout (queue); /* prepare to continue with regular read task immediately */ - memmove(queue->cread_buf, - &queue->cread_buf[INITIAL_KX_SIZE], - queue->cread_off - (INITIAL_KX_SIZE)); + memmove (queue->cread_buf, + &queue->cread_buf[INITIAL_KX_SIZE], + queue->cread_off - (INITIAL_KX_SIZE)); queue->cread_off -= INITIAL_KX_SIZE; - queue->read_task = GNUNET_SCHEDULER_add_now(&queue_read, queue); + queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue); } @@ -1846,7 +1854,7 @@ queue_read_kx(void *cls) * invalid */ static int -mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) +mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) { struct Queue *queue; const char *path; @@ -1854,54 +1862,54 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) socklen_t in_len; struct GNUNET_NETWORK_Handle *sock; - if (0 != strncmp(address, - COMMUNICATOR_ADDRESS_PREFIX "-", - strlen(COMMUNICATOR_ADDRESS_PREFIX "-"))) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")]; - in = tcp_address_to_sockaddr(path, &in_len); + if (0 != strncmp (address, + COMMUNICATOR_ADDRESS_PREFIX "-", + strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; + in = tcp_address_to_sockaddr (path, &in_len); - sock = GNUNET_NETWORK_socket_create(in->sa_family, SOCK_STREAM, IPPROTO_TCP); + sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP); if (NULL == sock) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "socket(%d) failed: %s", - in->sa_family, - strerror(errno)); - GNUNET_free(in); - return GNUNET_SYSERR; - } - if (GNUNET_OK != GNUNET_NETWORK_socket_connect(sock, in, in_len)) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "connect to `%s' failed: %s", - address, - strerror(errno)); - GNUNET_NETWORK_socket_close(sock); - GNUNET_free(in); - return GNUNET_SYSERR; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "socket(%d) failed: %s", + in->sa_family, + strerror (errno)); + GNUNET_free (in); + return GNUNET_SYSERR; + } + if (GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "connect to `%s' failed: %s", + address, + strerror (errno)); + GNUNET_NETWORK_socket_close (sock); + GNUNET_free (in); + return GNUNET_SYSERR; + } - queue = GNUNET_new(struct Queue); + queue = GNUNET_new (struct Queue); queue->target = *peer; queue->address = in; queue->address_len = in_len; queue->sock = sock; - boot_queue(queue, GNUNET_TRANSPORT_CS_OUTBOUND); + boot_queue (queue, GNUNET_TRANSPORT_CS_OUTBOUND); queue->read_task = - GNUNET_SCHEDULER_add_read_net(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - queue->sock, - &queue_read_kx, - queue); - start_initial_kx_out(queue); - queue->write_task = - GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, queue->sock, - &queue_write, + &queue_read_kx, queue); + start_initial_kx_out (queue); + queue->write_task = + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + queue->sock, + &queue_write, + queue); return GNUNET_OK; } @@ -1915,15 +1923,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) * @return #GNUNET_OK to continue to iterate */ static int -get_queue_delete_it(void *cls, - const struct GNUNET_PeerIdentity *target, - void *value) +get_queue_delete_it (void *cls, + const struct GNUNET_PeerIdentity *target, + void *value) { struct Queue *queue = value; - (void)cls; - (void)target; - queue_destroy(queue); + (void) cls; + (void) target; + queue_destroy (queue); return GNUNET_OK; } @@ -1934,47 +1942,47 @@ get_queue_delete_it(void *cls, * @param cls NULL (always) */ static void -do_shutdown(void *cls) +do_shutdown (void *cls) { while (NULL != proto_head) - free_proto_queue(proto_head); + free_proto_queue (proto_head); if (NULL != nat) - { - GNUNET_NAT_unregister(nat); - nat = NULL; - } + { + GNUNET_NAT_unregister (nat); + nat = NULL; + } if (NULL != listen_task) - { - GNUNET_SCHEDULER_cancel(listen_task); - listen_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (listen_task); + listen_task = NULL; + } if (NULL != listen_sock) - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(listen_sock)); - listen_sock = NULL; - } - GNUNET_CONTAINER_multipeermap_iterate(queue_map, &get_queue_delete_it, NULL); - GNUNET_CONTAINER_multipeermap_destroy(queue_map); + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (listen_sock)); + listen_sock = NULL; + } + GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); + GNUNET_CONTAINER_multipeermap_destroy (queue_map); if (NULL != ch) - { - GNUNET_TRANSPORT_communicator_disconnect(ch); - ch = NULL; - } + { + GNUNET_TRANSPORT_communicator_disconnect (ch); + ch = NULL; + } if (NULL != stats) - { - GNUNET_STATISTICS_destroy(stats, GNUNET_NO); - stats = NULL; - } + { + GNUNET_STATISTICS_destroy (stats, GNUNET_NO); + stats = NULL; + } if (NULL != my_private_key) - { - GNUNET_free(my_private_key); - my_private_key = NULL; - } + { + GNUNET_free (my_private_key); + my_private_key = NULL; + } if (NULL != is) - { - GNUNET_NT_scanner_done(is); - is = NULL; - } + { + GNUNET_NT_scanner_done (is); + is = NULL; + } } @@ -1990,14 +1998,14 @@ do_shutdown(void *cls) * @param msg payload */ static void -enc_notify_cb(void *cls, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *msg) +enc_notify_cb (void *cls, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *msg) { - (void)cls; - (void)sender; - (void)msg; - GNUNET_break_op(0); + (void) cls; + (void) sender; + (void) msg; + GNUNET_break_op (0); } @@ -2015,39 +2023,39 @@ enc_notify_cb(void *cls, * @param addrlen actual length of the @a addr */ static void -nat_address_cb(void *cls, - void **app_ctx, - int add_remove, - enum GNUNET_NAT_AddressClass ac, - const struct sockaddr *addr, - socklen_t addrlen) +nat_address_cb (void *cls, + void **app_ctx, + int add_remove, + enum GNUNET_NAT_AddressClass ac, + const struct sockaddr *addr, + socklen_t addrlen) { char *my_addr; struct GNUNET_TRANSPORT_AddressIdentifier *ai; if (GNUNET_YES == add_remove) - { - enum GNUNET_NetworkType nt; - - GNUNET_asprintf(&my_addr, - "%s-%s", - COMMUNICATOR_ADDRESS_PREFIX, - GNUNET_a2s(addr, addrlen)); - nt = GNUNET_NT_scanner_get_type(is, addr, addrlen); - ai = - GNUNET_TRANSPORT_communicator_address_add(ch, - my_addr, - nt, - GNUNET_TIME_UNIT_FOREVER_REL); - GNUNET_free(my_addr); - *app_ctx = ai; - } + { + enum GNUNET_NetworkType nt; + + GNUNET_asprintf (&my_addr, + "%s-%s", + COMMUNICATOR_ADDRESS_PREFIX, + GNUNET_a2s (addr, addrlen)); + nt = GNUNET_NT_scanner_get_type (is, addr, addrlen); + ai = + GNUNET_TRANSPORT_communicator_address_add (ch, + my_addr, + nt, + GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_free (my_addr); + *app_ctx = ai; + } else - { - ai = *app_ctx; - GNUNET_TRANSPORT_communicator_address_remove(ai); - *app_ctx = NULL; - } + { + ai = *app_ctx; + GNUNET_TRANSPORT_communicator_address_remove (ai); + *app_ctx = NULL; + } } @@ -2060,10 +2068,10 @@ nat_address_cb(void *cls, * @param c configuration */ static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { char *bindto; struct sockaddr *in; @@ -2071,113 +2079,113 @@ run(void *cls, struct sockaddr_storage in_sto; socklen_t sto_len; - (void)cls; + (void) cls; cfg = c; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename(cfg, - COMMUNICATOR_CONFIG_SECTION, - "BINDTO", - &bindto)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - COMMUNICATOR_CONFIG_SECTION, - "BINDTO"); - return; - } + GNUNET_CONFIGURATION_get_value_filename (cfg, + COMMUNICATOR_CONFIG_SECTION, + "BINDTO", + &bindto)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + COMMUNICATOR_CONFIG_SECTION, + "BINDTO"); + return; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number(cfg, - COMMUNICATOR_CONFIG_SECTION, - "MAX_QUEUE_LENGTH", - &max_queue_length)) + GNUNET_CONFIGURATION_get_value_number (cfg, + COMMUNICATOR_CONFIG_SECTION, + "MAX_QUEUE_LENGTH", + &max_queue_length)) max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; - in = tcp_address_to_sockaddr(bindto, &in_len); + in = tcp_address_to_sockaddr (bindto, &in_len); if (NULL == in) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to setup TCP socket address with path `%s'\n", - bindto); - GNUNET_free(bindto); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to setup TCP socket address with path `%s'\n", + bindto); + GNUNET_free (bindto); + return; + } listen_sock = - GNUNET_NETWORK_socket_create(in->sa_family, SOCK_STREAM, IPPROTO_TCP); + GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP); if (NULL == listen_sock) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); - GNUNET_free(in); - GNUNET_free(bindto); - return; - } - if (GNUNET_OK != GNUNET_NETWORK_socket_bind(listen_sock, in, in_len)) - { - GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", bindto); - GNUNET_NETWORK_socket_close(listen_sock); - listen_sock = NULL; - GNUNET_free(in); - GNUNET_free(bindto); - return; - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); + GNUNET_free (in); + GNUNET_free (bindto); + return; + } + if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, in, in_len)) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto); + GNUNET_NETWORK_socket_close (listen_sock); + listen_sock = NULL; + GNUNET_free (in); + GNUNET_free (bindto); + return; + } /* We might have bound to port 0, allowing the OS to figure it out; thus, get the real IN-address from the socket */ sto_len = sizeof(in_sto); - if (0 != getsockname(GNUNET_NETWORK_get_fd(listen_sock), - (struct sockaddr *)&in_sto, - &sto_len)) - { - memcpy(&in_sto, in, in_len); - sto_len = in_len; - } - GNUNET_free(in); - GNUNET_free(bindto); - in = (struct sockaddr *)&in_sto; + if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock), + (struct sockaddr *) &in_sto, + &sto_len)) + { + memcpy (&in_sto, in, in_len); + sto_len = in_len; + } + GNUNET_free (in); + GNUNET_free (bindto); + in = (struct sockaddr *) &in_sto; in_len = sto_len; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Bound to `%s'\n", - GNUNET_a2s((const struct sockaddr *)&in_sto, sto_len)); - stats = GNUNET_STATISTICS_create("C-TCP", cfg); - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); - is = GNUNET_NT_scanner_init(); - my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Bound to `%s'\n", + GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); + stats = GNUNET_STATISTICS_create ("C-TCP", cfg); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + is = GNUNET_NT_scanner_init (); + my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); if (NULL == my_private_key) - { - GNUNET_log( - GNUNET_ERROR_TYPE_ERROR, - _( - "Transport service is lacking key configuration settings. Exiting.\n")); - GNUNET_SCHEDULER_shutdown(); - return; - } - GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key); + { + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + _ ( + "Transport service is lacking key configuration settings. Exiting.\n")); + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); /* start listening */ - listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - listen_sock, - &listen_cb, + listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + listen_sock, + &listen_cb, + NULL); + queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); + ch = GNUNET_TRANSPORT_communicator_connect (cfg, + COMMUNICATOR_CONFIG_SECTION, + COMMUNICATOR_ADDRESS_PREFIX, + GNUNET_TRANSPORT_CC_RELIABLE, + &mq_init, + NULL, + &enc_notify_cb, NULL); - queue_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); - ch = GNUNET_TRANSPORT_communicator_connect(cfg, - COMMUNICATOR_CONFIG_SECTION, - COMMUNICATOR_ADDRESS_PREFIX, - GNUNET_TRANSPORT_CC_RELIABLE, - &mq_init, - NULL, - &enc_notify_cb, - NULL); if (NULL == ch) - { - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - return; - } - nat = GNUNET_NAT_register(cfg, - COMMUNICATOR_CONFIG_SECTION, - IPPROTO_TCP, - 1 /* one address */, - (const struct sockaddr **)&in, - &in_len, - &nat_address_cb, - NULL /* FIXME: support reversal: #5529 */, - NULL /* closure */); + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + nat = GNUNET_NAT_register (cfg, + COMMUNICATOR_CONFIG_SECTION, + IPPROTO_TCP, + 1 /* one address */, + (const struct sockaddr **) &in, + &in_len, + &nat_address_cb, + NULL /* FIXME: support reversal: #5529 */, + NULL /* closure */); } @@ -2189,26 +2197,26 @@ run(void *cls, * @return 0 ok, 1 on error */ int -main(int argc, char *const *argv) +main (int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; int ret; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; - ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc, - argv, - "gnunet-communicator-tcp", - _("GNUnet TCP communicator"), - options, - &run, - NULL)) + ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, + argv, + "gnunet-communicator-tcp", + _ ("GNUnet TCP communicator"), + options, + &run, + NULL)) ? 0 : 1; - GNUNET_free((void *)argv); + GNUNET_free ((void *) argv); return ret; } diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index 228540b81..2d9fabfec 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c @@ -67,7 +67,7 @@ * How often do we scan for changes to our network interfaces? */ #define INTERFACE_SCAN_FREQUENCY \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) /** * How long do we believe our addresses to remain up (before @@ -156,7 +156,8 @@ GNUNET_NETWORK_STRUCT_BEGIN * the specified sender. If possible, the receiver should respond with * a `struct UDPAck` (possibly via backchannel). */ -struct UdpHandshakeSignature { +struct UdpHandshakeSignature +{ /** * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE */ @@ -189,7 +190,8 @@ struct UdpHandshakeSignature { * "Plaintext" header at beginning of KX message. Followed * by encrypted `struct UDPConfirmation`. */ -struct InitialKX { +struct InitialKX +{ /** * Ephemeral key for KX. */ @@ -207,7 +209,8 @@ struct InitialKX { * Encrypted continuation of UDP initial handshake, followed * by message header with payload. */ -struct UDPConfirmation { +struct UDPConfirmation +{ /** * Sender's identity */ @@ -234,7 +237,8 @@ struct UDPConfirmation { * UDP key acknowledgement. May be sent via backchannel. Allows the * sender to use `struct UDPBox` with the acknowledge key henceforth. */ -struct UDPAck { +struct UDPAck +{ /** * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK. */ @@ -261,7 +265,8 @@ struct UDPAck { * be just any global peer -- an attacker must have at least * shared a LAN with the peer they're pretending to be here. */ -struct UdpBroadcastSignature { +struct UdpBroadcastSignature +{ /** * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST */ @@ -285,7 +290,8 @@ struct UdpBroadcastSignature { * recognized in LAN as GNUnet peers if this feature is enabled * anyway. Also, the entire message is in cleartext. */ -struct UDPBroadcast { +struct UDPBroadcast +{ /** * Sender's peer identity. */ @@ -303,7 +309,8 @@ struct UDPBroadcast { * UDP message box. Always sent encrypted, only allowed after * the receiver sent a `struct UDPAck` for the base key! */ -struct UDPBox { +struct UDPBox +{ /** * Key and IV identification code. KDF applied to an acknowledged * base key and a sequence number. Sequence numbers must be used @@ -336,7 +343,8 @@ struct SharedSecret; * Pre-generated "kid" code (key and IV identification code) to * quickly derive master key for a `struct UDPBox`. */ -struct KeyCacheEntry { +struct KeyCacheEntry +{ /** * Kept in a DLL. */ @@ -383,7 +391,8 @@ struct ReceiverAddress; /** * Shared secret we generated for a particular sender or receiver. */ -struct SharedSecret { +struct SharedSecret +{ /** * Kept in a DLL. */ @@ -448,7 +457,8 @@ struct SharedSecret { * Information we track per sender address we have recently been * in contact with (we decrypt messages from the sender). */ -struct SenderAddress { +struct SenderAddress +{ /** * To whom are we talking to. */ @@ -500,7 +510,8 @@ struct SenderAddress { * Information we track per receiving address we have recently been * in contact with (encryption to receiver). */ -struct ReceiverAddress { +struct ReceiverAddress +{ /** * To whom are we talking to. */ @@ -578,7 +589,8 @@ struct ReceiverAddress { /** * Interface we broadcast our presence on. */ -struct BroadcastInterface { +struct BroadcastInterface +{ /** * Kept in a DLL. */ @@ -739,25 +751,25 @@ static uint16_t my_port; * @param bi entity to close down */ static void -bi_destroy(struct BroadcastInterface *bi) +bi_destroy (struct BroadcastInterface *bi) { if (AF_INET6 == bi->sa->sa_family) + { + /* Leave the multicast group */ + if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, + IPPROTO_IPV6, + IPV6_LEAVE_GROUP, + &bi->mcreq, + sizeof(bi->mcreq))) { - /* Leave the multicast group */ - if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock, - IPPROTO_IPV6, - IPV6_LEAVE_GROUP, - &bi->mcreq, - sizeof(bi->mcreq))) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); - } + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); } - GNUNET_CONTAINER_DLL_remove(bi_head, bi_tail, bi); - GNUNET_SCHEDULER_cancel(bi->broadcast_task); - GNUNET_free(bi->sa); - GNUNET_free_non_null(bi->ba); - GNUNET_free(bi); + } + GNUNET_CONTAINER_DLL_remove (bi_head, bi_tail, bi); + GNUNET_SCHEDULER_cancel (bi->broadcast_task); + GNUNET_free (bi->sa); + GNUNET_free_non_null (bi->ba); + GNUNET_free (bi); } @@ -767,35 +779,35 @@ bi_destroy(struct BroadcastInterface *bi) * @param receiver entity to close down */ static void -receiver_destroy(struct ReceiverAddress *receiver) +receiver_destroy (struct ReceiverAddress *receiver) { struct GNUNET_MQ_Handle *mq; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting receiver for peer `%s'\n", - GNUNET_i2s(&receiver->target)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Disconnecting receiver for peer `%s'\n", + GNUNET_i2s (&receiver->target)); if (NULL != (mq = receiver->mq)) - { - receiver->mq = NULL; - GNUNET_MQ_destroy(mq); - } + { + receiver->mq = NULL; + GNUNET_MQ_destroy (mq); + } if (NULL != receiver->qh) - { - GNUNET_TRANSPORT_communicator_mq_del(receiver->qh); - receiver->qh = NULL; - } - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(receivers, - &receiver->target, - receiver)); - GNUNET_assert(receiver == GNUNET_CONTAINER_heap_remove_node(receiver->hn)); - GNUNET_STATISTICS_set(stats, - "# receivers active", - GNUNET_CONTAINER_multipeermap_size(receivers), - GNUNET_NO); - GNUNET_free(receiver->address); - GNUNET_free(receiver->foreign_addr); - GNUNET_free(receiver); + { + GNUNET_TRANSPORT_communicator_mq_del (receiver->qh); + receiver->qh = NULL; + } + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (receivers, + &receiver->target, + receiver)); + GNUNET_assert (receiver == GNUNET_CONTAINER_heap_remove_node (receiver->hn)); + GNUNET_STATISTICS_set (stats, + "# receivers active", + GNUNET_CONTAINER_multipeermap_size (receivers), + GNUNET_NO); + GNUNET_free (receiver->address); + GNUNET_free (receiver->foreign_addr); + GNUNET_free (receiver); } @@ -805,16 +817,16 @@ receiver_destroy(struct ReceiverAddress *receiver) * @param kce the key cache entry */ static void -kce_destroy(struct KeyCacheEntry *kce) +kce_destroy (struct KeyCacheEntry *kce) { struct SharedSecret *ss = kce->ss; ss->active_kce_count--; - GNUNET_CONTAINER_DLL_remove(ss->kce_head, ss->kce_tail, kce); - GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove(key_cache, - &kce->kid, - kce)); - GNUNET_free(kce); + GNUNET_CONTAINER_DLL_remove (ss->kce_head, ss->kce_tail, kce); + GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (key_cache, + &kce->kid, + kce)); + GNUNET_free (kce); } @@ -826,24 +838,24 @@ kce_destroy(struct KeyCacheEntry *kce) * @param kid[out] where to write the key ID */ static void -get_kid(const struct GNUNET_HashCode *msec, - uint32_t serial, - struct GNUNET_ShortHashCode *kid) +get_kid (const struct GNUNET_HashCode *msec, + uint32_t serial, + struct GNUNET_ShortHashCode *kid) { - uint32_t sid = htonl(serial); - - GNUNET_CRYPTO_hkdf(kid, - sizeof(*kid), - GCRY_MD_SHA512, - GCRY_MD_SHA256, - &sid, - sizeof(sid), - msec, - sizeof(*msec), - "UDP-KID", - strlen("UDP-KID"), - NULL, - 0); + uint32_t sid = htonl (serial); + + GNUNET_CRYPTO_hkdf (kid, + sizeof(*kid), + GCRY_MD_SHA512, + GCRY_MD_SHA256, + &sid, + sizeof(sid), + msec, + sizeof(*msec), + "UDP-KID", + strlen ("UDP-KID"), + NULL, + 0); } @@ -854,26 +866,26 @@ get_kid(const struct GNUNET_HashCode *msec, * @param seq sequence number for the key cache entry */ static void -kce_generate(struct SharedSecret *ss, uint32_t seq) +kce_generate (struct SharedSecret *ss, uint32_t seq) { struct KeyCacheEntry *kce; - GNUNET_assert(0 < seq); - kce = GNUNET_new(struct KeyCacheEntry); + GNUNET_assert (0 < seq); + kce = GNUNET_new (struct KeyCacheEntry); kce->ss = ss; kce->sequence_number = seq; - get_kid(&ss->master, seq, &kce->kid); - GNUNET_CONTAINER_DLL_insert(ss->kce_head, ss->kce_tail, kce); + get_kid (&ss->master, seq, &kce->kid); + GNUNET_CONTAINER_DLL_insert (ss->kce_head, ss->kce_tail, kce); ss->active_kce_count++; - (void)GNUNET_CONTAINER_multishortmap_put( + (void) GNUNET_CONTAINER_multishortmap_put ( key_cache, &kce->kid, kce, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GNUNET_STATISTICS_set(stats, - "# KIDs active", - GNUNET_CONTAINER_multishortmap_size(key_cache), - GNUNET_NO); + GNUNET_STATISTICS_set (stats, + "# KIDs active", + GNUNET_CONTAINER_multishortmap_size (key_cache), + GNUNET_NO); } @@ -883,31 +895,31 @@ kce_generate(struct SharedSecret *ss, uint32_t seq) * @param ss shared secret to destroy */ static void -secret_destroy(struct SharedSecret *ss) +secret_destroy (struct SharedSecret *ss) { struct SenderAddress *sender; struct ReceiverAddress *receiver; struct KeyCacheEntry *kce; if (NULL != (sender = ss->sender)) - { - GNUNET_CONTAINER_DLL_remove(sender->ss_head, sender->ss_tail, ss); - sender->num_secrets--; - } + { + GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss); + sender->num_secrets--; + } if (NULL != (receiver = ss->receiver)) - { - GNUNET_CONTAINER_DLL_remove(receiver->ss_head, receiver->ss_tail, ss); - receiver->num_secrets--; - receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used); - } + { + GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); + receiver->num_secrets--; + receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used); + } while (NULL != (kce = ss->kce_head)) - kce_destroy(kce); - GNUNET_STATISTICS_update(stats, "# Secrets active", -1, GNUNET_NO); - GNUNET_STATISTICS_set(stats, - "# KIDs active", - GNUNET_CONTAINER_multishortmap_size(key_cache), - GNUNET_NO); - GNUNET_free(ss); + kce_destroy (kce); + GNUNET_STATISTICS_update (stats, "# Secrets active", -1, GNUNET_NO); + GNUNET_STATISTICS_set (stats, + "# KIDs active", + GNUNET_CONTAINER_multishortmap_size (key_cache), + GNUNET_NO); + GNUNET_free (ss); } @@ -918,18 +930,18 @@ secret_destroy(struct SharedSecret *ss) * @param sender entity to close down */ static void -sender_destroy(struct SenderAddress *sender) +sender_destroy (struct SenderAddress *sender) { - GNUNET_assert( + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(senders, &sender->target, sender)); - GNUNET_assert(sender == GNUNET_CONTAINER_heap_remove_node(sender->hn)); - GNUNET_STATISTICS_set(stats, - "# senders active", - GNUNET_CONTAINER_multipeermap_size(senders), - GNUNET_NO); - GNUNET_free(sender->address); - GNUNET_free(sender); + GNUNET_CONTAINER_multipeermap_remove (senders, &sender->target, sender)); + GNUNET_assert (sender == GNUNET_CONTAINER_heap_remove_node (sender->hn)); + GNUNET_STATISTICS_set (stats, + "# senders active", + GNUNET_CONTAINER_multipeermap_size (senders), + GNUNET_NO); + GNUNET_free (sender->address); + GNUNET_free (sender); } @@ -942,28 +954,28 @@ sender_destroy(struct SenderAddress *sender) * @param iv[out] where to write the IV */ static void -get_iv_key(const struct GNUNET_HashCode *msec, - uint32_t serial, - char key[AES_KEY_SIZE], - char iv[AES_IV_SIZE]) +get_iv_key (const struct GNUNET_HashCode *msec, + uint32_t serial, + char key[AES_KEY_SIZE], + char iv[AES_IV_SIZE]) { - uint32_t sid = htonl(serial); + uint32_t sid = htonl (serial); char res[AES_KEY_SIZE + AES_IV_SIZE]; - GNUNET_CRYPTO_hkdf(res, - sizeof(res), - GCRY_MD_SHA512, - GCRY_MD_SHA256, - &sid, - sizeof(sid), - msec, - sizeof(*msec), - "UDP-IV-KEY", - strlen("UDP-IV-KEY"), - NULL, - 0); - memcpy(key, res, AES_KEY_SIZE); - memcpy(iv, &res[AES_KEY_SIZE], AES_IV_SIZE); + GNUNET_CRYPTO_hkdf (res, + sizeof(res), + GCRY_MD_SHA512, + GCRY_MD_SHA256, + &sid, + sizeof(sid), + msec, + sizeof(*msec), + "UDP-IV-KEY", + strlen ("UDP-IV-KEY"), + NULL, + 0); + memcpy (key, res, AES_KEY_SIZE); + memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE); } @@ -973,11 +985,11 @@ get_iv_key(const struct GNUNET_HashCode *msec, * @param sender address for which the timeout should be rescheduled */ static void -reschedule_sender_timeout(struct SenderAddress *sender) +reschedule_sender_timeout (struct SenderAddress *sender) { sender->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); - GNUNET_CONTAINER_heap_update_cost(sender->hn, sender->timeout.abs_value_us); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_CONTAINER_heap_update_cost (sender->hn, sender->timeout.abs_value_us); } @@ -987,12 +999,12 @@ reschedule_sender_timeout(struct SenderAddress *sender) * @param receiver address for which the timeout should be rescheduled */ static void -reschedule_receiver_timeout(struct ReceiverAddress *receiver) +reschedule_receiver_timeout (struct ReceiverAddress *receiver) { receiver->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); - GNUNET_CONTAINER_heap_update_cost(receiver->hn, - receiver->timeout.abs_value_us); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_CONTAINER_heap_update_cost (receiver->hn, + receiver->timeout.abs_value_us); } @@ -1002,7 +1014,7 @@ reschedule_receiver_timeout(struct ReceiverAddress *receiver) * @param cls unused, NULL */ static void -check_timeouts(void *cls) +check_timeouts (void *cls) { struct GNUNET_TIME_Relative st; struct GNUNET_TIME_Relative rt; @@ -1010,27 +1022,27 @@ check_timeouts(void *cls) struct ReceiverAddress *receiver; struct SenderAddress *sender; - (void)cls; + (void) cls; timeout_task = NULL; rt = GNUNET_TIME_UNIT_FOREVER_REL; - while (NULL != (receiver = GNUNET_CONTAINER_heap_peek(receivers_heap))) - { - rt = GNUNET_TIME_absolute_get_remaining(receiver->timeout); - if (0 != rt.rel_value_us) - break; - receiver_destroy(receiver); - } + while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap))) + { + rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout); + if (0 != rt.rel_value_us) + break; + receiver_destroy (receiver); + } st = GNUNET_TIME_UNIT_FOREVER_REL; - while (NULL != (sender = GNUNET_CONTAINER_heap_peek(senders_heap))) - { - st = GNUNET_TIME_absolute_get_remaining(sender->timeout); - if (0 != st.rel_value_us) - break; - sender_destroy(sender); - } - delay = GNUNET_TIME_relative_min(rt, st); + while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap))) + { + st = GNUNET_TIME_absolute_get_remaining (sender->timeout); + if (0 != st.rel_value_us) + break; + sender_destroy (sender); + } + delay = GNUNET_TIME_relative_min (rt, st); if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) - timeout_task = GNUNET_SCHEDULER_add_delayed(delay, &check_timeouts, NULL); + timeout_task = GNUNET_SCHEDULER_add_delayed (delay, &check_timeouts, NULL); } @@ -1040,20 +1052,20 @@ check_timeouts(void *cls) * @param ss[in,out] data structure to complete */ static void -calculate_cmac(struct SharedSecret *ss) +calculate_cmac (struct SharedSecret *ss) { - GNUNET_CRYPTO_hkdf(&ss->cmac, - sizeof(ss->cmac), - GCRY_MD_SHA512, - GCRY_MD_SHA256, - "CMAC", - strlen("CMAC"), - &ss->master, - sizeof(ss->master), - "UDP-CMAC", - strlen("UDP-CMAC"), - NULL, - 0); + GNUNET_CRYPTO_hkdf (&ss->cmac, + sizeof(ss->cmac), + GCRY_MD_SHA512, + GCRY_MD_SHA256, + "CMAC", + strlen ("CMAC"), + &ss->master, + sizeof(ss->master), + "UDP-CMAC", + strlen ("UDP-CMAC"), + NULL, + 0); } @@ -1066,36 +1078,36 @@ calculate_cmac(struct SharedSecret *ss) * @param plaintext_len number of bytes of plaintext received */ static void -pass_plaintext_to_core(struct SenderAddress *sender, - const void *plaintext, - size_t plaintext_len) +pass_plaintext_to_core (struct SenderAddress *sender, + const void *plaintext, + size_t plaintext_len) { const struct GNUNET_MessageHeader *hdr = plaintext; - while (ntohs(hdr->size) < plaintext_len) - { - GNUNET_STATISTICS_update(stats, - "# bytes given to core", - ntohs(hdr->size), - GNUNET_NO); - (void) - GNUNET_TRANSPORT_communicator_receive(ch, - &sender->target, - hdr, - ADDRESS_VALIDITY_PERIOD, - NULL /* no flow control possible */ - , - NULL); - /* move on to next message, if any */ - plaintext_len -= ntohs(hdr->size); - if (plaintext_len < sizeof(*hdr)) - break; - hdr = plaintext + ntohs(hdr->size); - } - GNUNET_STATISTICS_update(stats, - "# bytes padding discarded", - plaintext_len, - GNUNET_NO); + while (ntohs (hdr->size) < plaintext_len) + { + GNUNET_STATISTICS_update (stats, + "# bytes given to core", + ntohs (hdr->size), + GNUNET_NO); + (void) + GNUNET_TRANSPORT_communicator_receive (ch, + &sender->target, + hdr, + ADDRESS_VALIDITY_PERIOD, + NULL /* no flow control possible */ + , + NULL); + /* move on to next message, if any */ + plaintext_len -= ntohs (hdr->size); + if (plaintext_len < sizeof(*hdr)) + break; + hdr = plaintext + ntohs (hdr->size); + } + GNUNET_STATISTICS_update (stats, + "# bytes padding discarded", + plaintext_len, + GNUNET_NO); } @@ -1108,20 +1120,20 @@ pass_plaintext_to_core(struct SenderAddress *sender, * @param cipher[out] cipher to initialize */ static void -setup_cipher(const struct GNUNET_HashCode *msec, - uint32_t serial, - gcry_cipher_hd_t *cipher) +setup_cipher (const struct GNUNET_HashCode *msec, + uint32_t serial, + gcry_cipher_hd_t *cipher) { char key[AES_KEY_SIZE]; char iv[AES_IV_SIZE]; - gcry_cipher_open(cipher, - GCRY_CIPHER_AES256 /* low level: go for speed */, - GCRY_CIPHER_MODE_GCM, - 0 /* flags */); - get_iv_key(msec, serial, key, iv); - gcry_cipher_setkey(*cipher, key, sizeof(key)); - gcry_cipher_setiv(*cipher, iv, sizeof(iv)); + gcry_cipher_open (cipher, + GCRY_CIPHER_AES256 /* low level: go for speed */, + GCRY_CIPHER_MODE_GCM, + 0 /* flags */); + get_iv_key (msec, serial, key, iv); + gcry_cipher_setkey (*cipher, key, sizeof(key)); + gcry_cipher_setiv (*cipher, iv, sizeof(iv)); } @@ -1138,29 +1150,29 @@ setup_cipher(const struct GNUNET_HashCode *msec, * @return #GNUNET_OK on success */ static int -try_decrypt(const struct SharedSecret *ss, - const char tag[GCM_TAG_SIZE], - uint32_t serial, - const char *in_buf, - size_t in_buf_size, - char *out_buf) +try_decrypt (const struct SharedSecret *ss, + const char tag[GCM_TAG_SIZE], + uint32_t serial, + const char *in_buf, + size_t in_buf_size, + char *out_buf) { gcry_cipher_hd_t cipher; - setup_cipher(&ss->master, serial, &cipher); - GNUNET_assert( + setup_cipher (&ss->master, serial, &cipher); + GNUNET_assert ( 0 == - gcry_cipher_decrypt(cipher, out_buf, in_buf_size, in_buf, in_buf_size)); - if (0 != gcry_cipher_checktag(cipher, tag, GCM_TAG_SIZE)) - { - gcry_cipher_close(cipher); - GNUNET_STATISTICS_update(stats, - "# AEAD authentication failures", - 1, - GNUNET_NO); - return GNUNET_SYSERR; - } - gcry_cipher_close(cipher); + gcry_cipher_decrypt (cipher, out_buf, in_buf_size, in_buf, in_buf_size)); + if (0 != gcry_cipher_checktag (cipher, tag, GCM_TAG_SIZE)) + { + gcry_cipher_close (cipher); + GNUNET_STATISTICS_update (stats, + "# AEAD authentication failures", + 1, + GNUNET_NO); + return GNUNET_SYSERR; + } + gcry_cipher_close (cipher); return GNUNET_OK; } @@ -1172,12 +1184,12 @@ try_decrypt(const struct SharedSecret *ss, * @return new shared secret */ static struct SharedSecret * -setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral) +setup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral) { struct SharedSecret *ss; - ss = GNUNET_new(struct SharedSecret); - GNUNET_CRYPTO_eddsa_ecdh(my_private_key, ephemeral, &ss->master); + ss = GNUNET_new (struct SharedSecret); + GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &ss->master); return ss; } @@ -1190,20 +1202,20 @@ setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral) * @return new shared secret */ static struct SharedSecret * -setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, - struct ReceiverAddress *receiver) +setup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, + struct ReceiverAddress *receiver) { struct SharedSecret *ss; - ss = GNUNET_new(struct SharedSecret); - GNUNET_CRYPTO_ecdh_eddsa(ephemeral, - &receiver->target.public_key, - &ss->master); - calculate_cmac(ss); + ss = GNUNET_new (struct SharedSecret); + GNUNET_CRYPTO_ecdh_eddsa (ephemeral, + &receiver->target.public_key, + &ss->master); + calculate_cmac (ss); ss->receiver = receiver; - GNUNET_CONTAINER_DLL_insert(receiver->ss_head, receiver->ss_tail, ss); + GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss); receiver->num_secrets++; - GNUNET_STATISTICS_update(stats, "# Secrets active", 1, GNUNET_NO); + GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO); return ss; } @@ -1216,7 +1228,7 @@ setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, * @param receiver receiver to setup MQ for */ static void -setup_receiver_mq(struct ReceiverAddress *receiver); +setup_receiver_mq (struct ReceiverAddress *receiver); /** @@ -1230,36 +1242,36 @@ setup_receiver_mq(struct ReceiverAddress *receiver); * @return #GNUNET_YES to continue to iterate */ static int -handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) +handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) { const struct UDPAck *ack = cls; struct ReceiverAddress *receiver = value; - (void)pid; + (void) pid; for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next) + { + if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode))) { - if (0 == memcmp(&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode))) + uint32_t allowed; + + allowed = ntohl (ack->sequence_max); + + if (allowed > ss->sequence_allowed) + { + receiver->acks_available += (allowed - ss->sequence_allowed); + if ((allowed - ss->sequence_allowed) == receiver->acks_available) { - uint32_t allowed; - - allowed = ntohl(ack->sequence_max); - - if (allowed > ss->sequence_allowed) - { - receiver->acks_available += (allowed - ss->sequence_allowed); - if ((allowed - ss->sequence_allowed) == receiver->acks_available) - { - /* we just incremented from zero => MTU change! */ - setup_receiver_mq(receiver); - } - ss->sequence_allowed = allowed; - /* move ss to head to avoid discarding it anytime soon! */ - GNUNET_CONTAINER_DLL_remove(receiver->ss_head, receiver->ss_tail, ss); - GNUNET_CONTAINER_DLL_insert(receiver->ss_head, receiver->ss_tail, ss); - } - return GNUNET_NO; + /* we just incremented from zero => MTU change! */ + setup_receiver_mq (receiver); } + ss->sequence_allowed = allowed; + /* move ss to head to avoid discarding it anytime soon! */ + GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); + GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss); + } + return GNUNET_NO; } + } return GNUNET_YES; } @@ -1273,41 +1285,41 @@ handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) * @param buf_size number of bytes in @a buf */ static void -try_handle_plaintext(struct SenderAddress *sender, - const void *buf, - size_t buf_size) +try_handle_plaintext (struct SenderAddress *sender, + const void *buf, + size_t buf_size) { const struct GNUNET_MessageHeader *hdr = - (const struct GNUNET_MessageHeader *)buf; - const struct UDPAck *ack = (const struct UDPAck *)buf; + (const struct GNUNET_MessageHeader *) buf; + const struct UDPAck *ack = (const struct UDPAck *) buf; uint16_t type; if (sizeof(*hdr) > buf_size) return; /* not even a header */ - if (ntohs(hdr->size) > buf_size) + if (ntohs (hdr->size) > buf_size) return; /* not even a header */ - type = ntohs(hdr->type); + type = ntohs (hdr->type); switch (type) - { - case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK: - /* lookup master secret by 'cmac', then update sequence_max */ - GNUNET_CONTAINER_multipeermap_get_multiple(receivers, - &sender->target, - &handle_ack, - (void *)ack); - /* There could be more messages after the ACK, handle those as well */ - buf += ntohs(hdr->size); - buf_size -= ntohs(hdr->size); - pass_plaintext_to_core(sender, buf, buf_size); - break; - - case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD: - /* skip padding */ - break; - - default: - pass_plaintext_to_core(sender, buf, buf_size); - } + { + case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK: + /* lookup master secret by 'cmac', then update sequence_max */ + GNUNET_CONTAINER_multipeermap_get_multiple (receivers, + &sender->target, + &handle_ack, + (void *) ack); + /* There could be more messages after the ACK, handle those as well */ + buf += ntohs (hdr->size); + buf_size -= ntohs (hdr->size); + pass_plaintext_to_core (sender, buf, buf_size); + break; + + case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD: + /* skip padding */ + break; + + default: + pass_plaintext_to_core (sender, buf, buf_size); + } } @@ -1320,29 +1332,29 @@ try_handle_plaintext(struct SenderAddress *sender, * @param ss shared secret to generate ACKs for */ static void -consider_ss_ack(struct SharedSecret *ss) +consider_ss_ack (struct SharedSecret *ss) { - GNUNET_assert(NULL != ss->sender); + GNUNET_assert (NULL != ss->sender); /* drop ancient KeyCacheEntries */ while ((NULL != ss->kce_head) && (MAX_SQN_DELTA < ss->kce_head->sequence_number - ss->kce_tail->sequence_number)) - kce_destroy(ss->kce_tail); + kce_destroy (ss->kce_tail); if (ss->active_kce_count < KCN_THRESHOLD) - { - struct UDPAck ack; - - while (ss->active_kce_count < KCN_TARGET) - kce_generate(ss, ++ss->sequence_allowed); - ack.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); - ack.header.size = htons(sizeof(ack)); - ack.sequence_max = htonl(ss->sequence_allowed); - ack.cmac = ss->cmac; - GNUNET_TRANSPORT_communicator_notify(ch, - &ss->sender->target, - COMMUNICATOR_ADDRESS_PREFIX, - &ack.header); - } + { + struct UDPAck ack; + + while (ss->active_kce_count < KCN_TARGET) + kce_generate (ss, ++ss->sequence_allowed); + ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); + ack.header.size = htons (sizeof(ack)); + ack.sequence_max = htonl (ss->sequence_allowed); + ack.cmac = ss->cmac; + GNUNET_TRANSPORT_communicator_notify (ch, + &ss->sender->target, + COMMUNICATOR_ADDRESS_PREFIX, + &ack.header); + } } @@ -1354,42 +1366,43 @@ consider_ss_ack(struct SharedSecret *ss) * @param kce key index to decrypt @a box */ static void -decrypt_box(const struct UDPBox *box, - size_t box_len, - struct KeyCacheEntry *kce) +decrypt_box (const struct UDPBox *box, + size_t box_len, + struct KeyCacheEntry *kce) { struct SharedSecret *ss = kce->ss; char out_buf[box_len - sizeof(*box)]; - GNUNET_assert(NULL != ss->sender); - if (GNUNET_OK != try_decrypt(ss, - box->gcm_tag, - kce->sequence_number, - (const char *)&box[1], - sizeof(out_buf), - out_buf)) - { - GNUNET_STATISTICS_update(stats, - "# Decryption failures with valid KCE", - 1, - GNUNET_NO); - kce_destroy(kce); - return; - } - kce_destroy(kce); - GNUNET_STATISTICS_update(stats, - "# bytes decrypted with BOX", - sizeof(out_buf), - GNUNET_NO); - try_handle_plaintext(ss->sender, out_buf, sizeof(out_buf)); - consider_ss_ack(ss); + GNUNET_assert (NULL != ss->sender); + if (GNUNET_OK != try_decrypt (ss, + box->gcm_tag, + kce->sequence_number, + (const char *) &box[1], + sizeof(out_buf), + out_buf)) + { + GNUNET_STATISTICS_update (stats, + "# Decryption failures with valid KCE", + 1, + GNUNET_NO); + kce_destroy (kce); + return; + } + kce_destroy (kce); + GNUNET_STATISTICS_update (stats, + "# bytes decrypted with BOX", + sizeof(out_buf), + GNUNET_NO); + try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf)); + consider_ss_ack (ss); } /** * Closure for #find_sender_by_address() */ -struct SearchContext { +struct SearchContext +{ /** * Address we are looking for. */ @@ -1416,19 +1429,19 @@ struct SearchContext { * @return #GNUNET_YES if not found (continue to search), #GNUNET_NO if found */ static int -find_sender_by_address(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +find_sender_by_address (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct SearchContext *sc = cls; struct SenderAddress *sender = value; if ((sender->address_len == sc->address_len) && - (0 == memcmp(sender->address, sc->address, sender->address_len))) - { - sc->sender = sender; - return GNUNET_NO; /* stop iterating! */ - } + (0 == memcmp (sender->address, sc->address, sender->address_len))) + { + sc->sender = sender; + return GNUNET_NO; /* stop iterating! */ + } return GNUNET_YES; } @@ -1445,45 +1458,45 @@ find_sender_by_address(void *cls, * decrypting data from @a target */ static struct SenderAddress * -setup_sender(const struct GNUNET_PeerIdentity *target, - const struct sockaddr *address, - socklen_t address_len) +setup_sender (const struct GNUNET_PeerIdentity *target, + const struct sockaddr *address, + socklen_t address_len) { struct SenderAddress *sender; struct SearchContext sc = { .address = address, .address_len = address_len, .sender = NULL }; - GNUNET_CONTAINER_multipeermap_get_multiple(senders, - target, - &find_sender_by_address, - &sc); + GNUNET_CONTAINER_multipeermap_get_multiple (senders, + target, + &find_sender_by_address, + &sc); if (NULL != sc.sender) - { - reschedule_sender_timeout(sc.sender); - return sc.sender; - } - sender = GNUNET_new(struct SenderAddress); + { + reschedule_sender_timeout (sc.sender); + return sc.sender; + } + sender = GNUNET_new (struct SenderAddress); sender->target = *target; - sender->address = GNUNET_memdup(address, address_len); + sender->address = GNUNET_memdup (address, address_len); sender->address_len = address_len; - (void)GNUNET_CONTAINER_multipeermap_put( + (void) GNUNET_CONTAINER_multipeermap_put ( senders, &sender->target, sender, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GNUNET_STATISTICS_set(stats, - "# senders active", - GNUNET_CONTAINER_multipeermap_size(receivers), - GNUNET_NO); + GNUNET_STATISTICS_set (stats, + "# senders active", + GNUNET_CONTAINER_multipeermap_size (receivers), + GNUNET_NO); sender->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); - sender->hn = GNUNET_CONTAINER_heap_insert(senders_heap, - sender, - sender->timeout.abs_value_us); - sender->nt = GNUNET_NT_scanner_get_type(is, address, address_len); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap, + sender, + sender->timeout.abs_value_us); + sender->nt = GNUNET_NT_scanner_get_type (is, address, address_len); if (NULL == timeout_task) - timeout_task = GNUNET_SCHEDULER_add_now(&check_timeouts, NULL); + timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL); return sender; } @@ -1496,21 +1509,22 @@ setup_sender(const struct GNUNET_PeerIdentity *target, * @return #GNUNET_OK if signature is valid */ static int -verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, - const struct UDPConfirmation *uc) +verify_confirmation (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, + const struct UDPConfirmation *uc) { struct UdpHandshakeSignature uhs; - uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); - uhs.purpose.size = htonl(sizeof(uhs)); + uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); + uhs.purpose.size = htonl (sizeof(uhs)); uhs.sender = uc->sender; uhs.receiver = my_identity; uhs.ephemeral = *ephemeral; uhs.monotonic_time = uc->monotonic_time; - return GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, - &uhs.purpose, - &uc->sender_sig, - &uc->sender.public_key); + return GNUNET_CRYPTO_eddsa_verify ( + GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, + &uhs.purpose, + &uc->sender_sig, + &uc->sender.public_key); } @@ -1523,30 +1537,30 @@ verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, * @return string representation of @a address */ static char * -sockaddr_to_udpaddr_string(const struct sockaddr *address, - socklen_t address_len) +sockaddr_to_udpaddr_string (const struct sockaddr *address, + socklen_t address_len) { char *ret; switch (address->sa_family) - { - case AF_INET: - GNUNET_asprintf(&ret, - "%s-%s", - COMMUNICATOR_ADDRESS_PREFIX, - GNUNET_a2s(address, address_len)); - break; - - case AF_INET6: - GNUNET_asprintf(&ret, - "%s-%s", - COMMUNICATOR_ADDRESS_PREFIX, - GNUNET_a2s(address, address_len)); - break; - - default: - GNUNET_assert(0); - } + { + case AF_INET: + GNUNET_asprintf (&ret, + "%s-%s", + COMMUNICATOR_ADDRESS_PREFIX, + GNUNET_a2s (address, address_len)); + break; + + case AF_INET6: + GNUNET_asprintf (&ret, + "%s-%s", + COMMUNICATOR_ADDRESS_PREFIX, + GNUNET_a2s (address, address_len)); + break; + + default: + GNUNET_assert (0); + } return ret; } @@ -1557,87 +1571,87 @@ sockaddr_to_udpaddr_string(const struct sockaddr *address, * @param cls NULL */ static void -sock_read(void *cls) +sock_read (void *cls) { struct sockaddr_storage sa; socklen_t salen = sizeof(sa); char buf[UINT16_MAX]; ssize_t rcvd; - (void)cls; - read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - udp_sock, - &sock_read, - NULL); - rcvd = GNUNET_NETWORK_socket_recvfrom(udp_sock, - buf, - sizeof(buf), - (struct sockaddr *)&sa, - &salen); + (void) cls; + read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + udp_sock, + &sock_read, + NULL); + rcvd = GNUNET_NETWORK_socket_recvfrom (udp_sock, + buf, + sizeof(buf), + (struct sockaddr *) &sa, + &salen); if (-1 == rcvd) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv"); - return; - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); + return; + } /* first, see if it is a UDPBox */ if (rcvd > sizeof(struct UDPBox)) - { - const struct UDPBox *box; - struct KeyCacheEntry *kce; + { + const struct UDPBox *box; + struct KeyCacheEntry *kce; - box = (const struct UDPBox *)buf; - kce = GNUNET_CONTAINER_multishortmap_get(key_cache, &box->kid); - if (NULL != kce) - { - decrypt_box(box, (size_t)rcvd, kce); - return; - } + box = (const struct UDPBox *) buf; + kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &box->kid); + if (NULL != kce) + { + decrypt_box (box, (size_t) rcvd, kce); + return; } + } /* next, check if it is a broadcast */ if (sizeof(struct UDPBroadcast) == rcvd) + { + const struct UDPBroadcast *ub; + struct UdpBroadcastSignature uhs; + + ub = (const struct UDPBroadcast *) buf; + uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); + uhs.purpose.size = htonl (sizeof(uhs)); + uhs.sender = ub->sender; + GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address); + if (GNUNET_OK == + GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST, + &uhs.purpose, + &ub->sender_sig, + &ub->sender.public_key)) { - const struct UDPBroadcast *ub; - struct UdpBroadcastSignature uhs; - - ub = (const struct UDPBroadcast *)buf; - uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); - uhs.purpose.size = htonl(sizeof(uhs)); - uhs.sender = ub->sender; - GNUNET_CRYPTO_hash(&sa, salen, &uhs.h_address); - if (GNUNET_OK == - GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST, - &uhs.purpose, - &ub->sender_sig, - &ub->sender.public_key)) - { - char *addr_s; - enum GNUNET_NetworkType nt; - - addr_s = - sockaddr_to_udpaddr_string((const struct sockaddr *)&sa, salen); - GNUNET_STATISTICS_update(stats, "# broadcasts received", 1, GNUNET_NO); - /* use our own mechanism to determine network type */ - nt = - GNUNET_NT_scanner_get_type(is, (const struct sockaddr *)&sa, salen); - GNUNET_TRANSPORT_application_validate(ah, &ub->sender, nt, addr_s); - GNUNET_free(addr_s); - return; - } - /* continue with KX, mostly for statistics... */ + char *addr_s; + enum GNUNET_NetworkType nt; + + addr_s = + sockaddr_to_udpaddr_string ((const struct sockaddr *) &sa, salen); + GNUNET_STATISTICS_update (stats, "# broadcasts received", 1, GNUNET_NO); + /* use our own mechanism to determine network type */ + nt = + GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen); + GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s); + GNUNET_free (addr_s); + return; } + /* continue with KX, mostly for statistics... */ + } /* finally, test if it is a KX */ if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX)) - { - GNUNET_STATISTICS_update(stats, - "# messages dropped (no kid, too small for KX)", - 1, - GNUNET_NO); - return; - } + { + GNUNET_STATISTICS_update (stats, + "# messages dropped (no kid, too small for KX)", + 1, + GNUNET_NO); + return; + } { const struct InitialKX *kx; @@ -1646,48 +1660,48 @@ sock_read(void *cls) const struct UDPConfirmation *uc; struct SenderAddress *sender; - kx = (const struct InitialKX *)buf; - ss = setup_shared_secret_dec(&kx->ephemeral); - if (GNUNET_OK != try_decrypt(ss, - kx->gcm_tag, - 0, - &buf[sizeof(*kx)], - sizeof(pbuf), - pbuf)) - { - GNUNET_free(ss); - GNUNET_STATISTICS_update( - stats, - "# messages dropped (no kid, AEAD decryption failed)", - 1, - GNUNET_NO); - return; - } - uc = (const struct UDPConfirmation *)pbuf; - if (GNUNET_OK != verify_confirmation(&kx->ephemeral, uc)) - { - GNUNET_break_op(0); - GNUNET_free(ss); - GNUNET_STATISTICS_update(stats, - "# messages dropped (sender signature invalid)", - 1, - GNUNET_NO); - return; - } - calculate_cmac(ss); - sender = setup_sender(&uc->sender, (const struct sockaddr *)&sa, salen); + kx = (const struct InitialKX *) buf; + ss = setup_shared_secret_dec (&kx->ephemeral); + if (GNUNET_OK != try_decrypt (ss, + kx->gcm_tag, + 0, + &buf[sizeof(*kx)], + sizeof(pbuf), + pbuf)) + { + GNUNET_free (ss); + GNUNET_STATISTICS_update ( + stats, + "# messages dropped (no kid, AEAD decryption failed)", + 1, + GNUNET_NO); + return; + } + uc = (const struct UDPConfirmation *) pbuf; + if (GNUNET_OK != verify_confirmation (&kx->ephemeral, uc)) + { + GNUNET_break_op (0); + GNUNET_free (ss); + GNUNET_STATISTICS_update (stats, + "# messages dropped (sender signature invalid)", + 1, + GNUNET_NO); + return; + } + calculate_cmac (ss); + sender = setup_sender (&uc->sender, (const struct sockaddr *) &sa, salen); ss->sender = sender; - GNUNET_CONTAINER_DLL_insert(sender->ss_head, sender->ss_tail, ss); + GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss); sender->num_secrets++; - GNUNET_STATISTICS_update(stats, "# Secrets active", 1, GNUNET_NO); - GNUNET_STATISTICS_update(stats, - "# messages decrypted without BOX", - 1, - GNUNET_NO); - try_handle_plaintext(sender, &uc[1], sizeof(pbuf) - sizeof(*uc)); - consider_ss_ack(ss); + GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO); + GNUNET_STATISTICS_update (stats, + "# messages decrypted without BOX", + 1, + GNUNET_NO); + try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc)); + consider_ss_ack (ss); if (sender->num_secrets > MAX_SECRETS) - secret_destroy(sender->ss_tail); + secret_destroy (sender->ss_tail); } } @@ -1700,7 +1714,7 @@ sock_read(void *cls) * @return converted bindto specification */ static struct sockaddr * -udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) +udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) { struct sockaddr *in; unsigned int port; @@ -1708,88 +1722,88 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) char *colon; char *cp; - if (1 == sscanf(bindto, "%u%1s", &port, dummy)) + if (1 == sscanf (bindto, "%u%1s", &port, dummy)) + { + /* interpreting value as just a PORT number */ + if (port > UINT16_MAX) { - /* interpreting value as just a PORT number */ - if (port > UINT16_MAX) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "BINDTO specification `%s' invalid: value too large for port\n", - bindto); - return NULL; - } - if ((GNUNET_NO == GNUNET_NETWORK_test_pf(PF_INET6)) || - (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno(cfg, - COMMUNICATOR_CONFIG_SECTION, - "DISABLE_V6"))) - { - struct sockaddr_in *i4; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "BINDTO specification `%s' invalid: value too large for port\n", + bindto); + return NULL; + } + if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) || + (GNUNET_YES == + GNUNET_CONFIGURATION_get_value_yesno (cfg, + COMMUNICATOR_CONFIG_SECTION, + "DISABLE_V6"))) + { + struct sockaddr_in *i4; - i4 = GNUNET_malloc(sizeof(struct sockaddr_in)); - i4->sin_family = AF_INET; - i4->sin_port = htons((uint16_t)port); - *sock_len = sizeof(struct sockaddr_in); - in = (struct sockaddr *)i4; - } - else - { - struct sockaddr_in6 *i6; + i4 = GNUNET_malloc (sizeof(struct sockaddr_in)); + i4->sin_family = AF_INET; + i4->sin_port = htons ((uint16_t) port); + *sock_len = sizeof(struct sockaddr_in); + in = (struct sockaddr *) i4; + } + else + { + struct sockaddr_in6 *i6; - i6 = GNUNET_malloc(sizeof(struct sockaddr_in6)); - i6->sin6_family = AF_INET6; - i6->sin6_port = htons((uint16_t)port); - *sock_len = sizeof(struct sockaddr_in6); - in = (struct sockaddr *)i6; - } - return in; + i6 = GNUNET_malloc (sizeof(struct sockaddr_in6)); + i6->sin6_family = AF_INET6; + i6->sin6_port = htons ((uint16_t) port); + *sock_len = sizeof(struct sockaddr_in6); + in = (struct sockaddr *) i6; } - cp = GNUNET_strdup(bindto); - colon = strrchr(cp, ':'); + return in; + } + cp = GNUNET_strdup (bindto); + colon = strrchr (cp, ':'); if (NULL != colon) + { + /* interpet value after colon as port */ + *colon = '\0'; + colon++; + if (1 == sscanf (colon, "%u%1s", &port, dummy)) { - /* interpet value after colon as port */ - *colon = '\0'; - colon++; - if (1 == sscanf(colon, "%u%1s", &port, dummy)) - { - /* interpreting value as just a PORT number */ - if (port > UINT16_MAX) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "BINDTO specification `%s' invalid: value too large for port\n", - bindto); - GNUNET_free(cp); - return NULL; - } - } - else - { - GNUNET_log( - GNUNET_ERROR_TYPE_ERROR, - "BINDTO specification `%s' invalid: last ':' not followed by number\n", - bindto); - GNUNET_free(cp); - return NULL; - } + /* interpreting value as just a PORT number */ + if (port > UINT16_MAX) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "BINDTO specification `%s' invalid: value too large for port\n", + bindto); + GNUNET_free (cp); + return NULL; + } } - else + else { - /* interpret missing port as 0, aka pick any free one */ - port = 0; + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + "BINDTO specification `%s' invalid: last ':' not followed by number\n", + bindto); + GNUNET_free (cp); + return NULL; } + } + else + { + /* interpret missing port as 0, aka pick any free one */ + port = 0; + } { /* try IPv4 */ struct sockaddr_in v4; - if (1 == inet_pton(AF_INET, cp, &v4)) - { - v4.sin_port = htons((uint16_t)port); - in = GNUNET_memdup(&v4, sizeof(v4)); - *sock_len = sizeof(v4); - GNUNET_free(cp); - return in; - } + if (1 == inet_pton (AF_INET, cp, &v4)) + { + v4.sin_port = htons ((uint16_t) port); + in = GNUNET_memdup (&v4, sizeof(v4)); + *sock_len = sizeof(v4); + GNUNET_free (cp); + return in; + } } { /* try IPv6 */ @@ -1797,22 +1811,22 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) const char *start; start = cp; - if (('[' == *cp) && (']' == cp[strlen(cp) - 1])) - { - start++; /* skip over '[' */ - cp[strlen(cp) - 1] = '\0'; /* eat ']' */ - } - if (1 == inet_pton(AF_INET6, start, &v6)) - { - v6.sin6_port = htons((uint16_t)port); - in = GNUNET_memdup(&v6, sizeof(v6)); - *sock_len = sizeof(v6); - GNUNET_free(cp); - return in; - } + if (('[' == *cp) && (']' == cp[strlen (cp) - 1])) + { + start++; /* skip over '[' */ + cp[strlen (cp) - 1] = '\0'; /* eat ']' */ + } + if (1 == inet_pton (AF_INET6, start, &v6)) + { + v6.sin6_port = htons ((uint16_t) port); + in = GNUNET_memdup (&v6, sizeof(v6)); + *sock_len = sizeof(v6); + GNUNET_free (cp); + return in; + } } /* #5528 FIXME (feature!): maybe also try getnameinfo()? */ - GNUNET_free(cp); + GNUNET_free (cp); return NULL; } @@ -1825,22 +1839,22 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) * @param pad_size number of bytes of padding to append */ static void -do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size) +do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size) { char pad[pad_size]; - GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, pad, sizeof(pad)); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, pad, sizeof(pad)); if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader)) - { - struct GNUNET_MessageHeader hdr = - { .size = htons(sizeof(pad)), - .type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) }; + { + struct GNUNET_MessageHeader hdr = + { .size = htons (sizeof(pad)), + .type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) }; - memcpy(pad, &hdr, sizeof(hdr)); - } - GNUNET_assert( + memcpy (pad, &hdr, sizeof(hdr)); + } + GNUNET_assert ( 0 == - gcry_cipher_encrypt(out_cipher, dgram, sizeof(pad), pad, sizeof(pad))); + gcry_cipher_encrypt (out_cipher, dgram, sizeof(pad), pad, sizeof(pad))); } @@ -1853,123 +1867,123 @@ do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size) * @param impl_state our `struct ReceiverAddress` */ static void -mq_send(struct GNUNET_MQ_Handle *mq, - const struct GNUNET_MessageHeader *msg, - void *impl_state) +mq_send (struct GNUNET_MQ_Handle *mq, + const struct GNUNET_MessageHeader *msg, + void *impl_state) { struct ReceiverAddress *receiver = impl_state; - uint16_t msize = ntohs(msg->size); + uint16_t msize = ntohs (msg->size); - GNUNET_assert(mq == receiver->mq); + GNUNET_assert (mq == receiver->mq); if (msize > receiver->mtu) - { - GNUNET_break(0); - receiver_destroy(receiver); - return; - } - reschedule_receiver_timeout(receiver); + { + GNUNET_break (0); + receiver_destroy (receiver); + return; + } + reschedule_receiver_timeout (receiver); if (0 == receiver->acks_available) - { - /* use KX encryption method */ - struct UdpHandshakeSignature uhs; - struct UDPConfirmation uc; - struct InitialKX kx; - struct GNUNET_CRYPTO_EcdhePrivateKey epriv; - char dgram[receiver->mtu + sizeof(uc) + sizeof(kx)]; - size_t dpos; - gcry_cipher_hd_t out_cipher; - struct SharedSecret *ss; - - /* setup key material */ - GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_ecdhe_key_create2(&epriv)); - - ss = setup_shared_secret_enc(&epriv, receiver); - setup_cipher(&ss->master, 0, &out_cipher); - /* compute 'uc' */ - uc.sender = my_identity; - uc.monotonic_time = - GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg)); - uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); - uhs.purpose.size = htonl(sizeof(uhs)); - uhs.sender = my_identity; - uhs.receiver = receiver->target; - GNUNET_CRYPTO_ecdhe_key_get_public(&epriv, &uhs.ephemeral); - uhs.monotonic_time = uc.monotonic_time; - GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, + { + /* use KX encryption method */ + struct UdpHandshakeSignature uhs; + struct UDPConfirmation uc; + struct InitialKX kx; + struct GNUNET_CRYPTO_EcdhePrivateKey epriv; + char dgram[receiver->mtu + sizeof(uc) + sizeof(kx)]; + size_t dpos; + gcry_cipher_hd_t out_cipher; + struct SharedSecret *ss; + + /* setup key material */ + GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdhe_key_create2 (&epriv)); + + ss = setup_shared_secret_enc (&epriv, receiver); + setup_cipher (&ss->master, 0, &out_cipher); + /* compute 'uc' */ + uc.sender = my_identity; + uc.monotonic_time = + GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); + uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); + uhs.purpose.size = htonl (sizeof(uhs)); + uhs.sender = my_identity; + uhs.receiver = receiver->target; + GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral); + uhs.monotonic_time = uc.monotonic_time; + GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, &uhs.purpose, &uc.sender_sig)); - /* Leave space for kx */ - dpos = sizeof(struct GNUNET_CRYPTO_EcdhePublicKey); - /* Append encrypted uc to dgram */ - GNUNET_assert(0 == gcry_cipher_encrypt(out_cipher, + /* Leave space for kx */ + dpos = sizeof(struct GNUNET_CRYPTO_EcdhePublicKey); + /* Append encrypted uc to dgram */ + GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], sizeof(uc), &uc, sizeof(uc))); - dpos += sizeof(uc); - /* Append encrypted payload to dgram */ - GNUNET_assert( - 0 == gcry_cipher_encrypt(out_cipher, &dgram[dpos], msize, msg, msize)); - dpos += msize; - do_pad(out_cipher, &dgram[dpos], sizeof(dgram) - dpos); - /* Datagram starts with kx */ - kx.ephemeral = uhs.ephemeral; - GNUNET_assert( - 0 == gcry_cipher_gettag(out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag))); - gcry_cipher_close(out_cipher); - memcpy(dgram, &kx, sizeof(kx)); - if (-1 == GNUNET_NETWORK_socket_sendto(udp_sock, - dgram, - sizeof(dgram), - receiver->address, - receiver->address_len)) - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send"); - GNUNET_MQ_impl_send_continue(mq); - return; - } /* End of KX encryption method */ + dpos += sizeof(uc); + /* Append encrypted payload to dgram */ + GNUNET_assert ( + 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); + dpos += msize; + do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); + /* Datagram starts with kx */ + kx.ephemeral = uhs.ephemeral; + GNUNET_assert ( + 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag))); + gcry_cipher_close (out_cipher); + memcpy (dgram, &kx, sizeof(kx)); + if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, + dgram, + sizeof(dgram), + receiver->address, + receiver->address_len)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); + GNUNET_MQ_impl_send_continue (mq); + return; + } /* End of KX encryption method */ /* begin "BOX" encryption method, scan for ACKs from tail! */ for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev) + { + if (ss->sequence_used < ss->sequence_allowed) { - if (ss->sequence_used < ss->sequence_allowed) - { - char dgram[sizeof(struct UDPBox) + receiver->mtu]; - struct UDPBox *box; - gcry_cipher_hd_t out_cipher; - size_t dpos; - - box = (struct UDPBox *)dgram; - ss->sequence_used++; - get_kid(&ss->master, ss->sequence_used, &box->kid); - setup_cipher(&ss->master, ss->sequence_used, &out_cipher); - /* Append encrypted payload to dgram */ - dpos = sizeof(struct UDPBox); - GNUNET_assert( - 0 == gcry_cipher_encrypt(out_cipher, &dgram[dpos], msize, msg, msize)); - dpos += msize; - do_pad(out_cipher, &dgram[dpos], sizeof(dgram) - dpos); - GNUNET_assert(0 == gcry_cipher_gettag(out_cipher, - box->gcm_tag, - sizeof(box->gcm_tag))); - gcry_cipher_close(out_cipher); - if (-1 == GNUNET_NETWORK_socket_sendto(udp_sock, - dgram, - sizeof(dgram), - receiver->address, - receiver->address_len)) - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send"); - GNUNET_MQ_impl_send_continue(mq); - receiver->acks_available--; - if (0 == receiver->acks_available) - { - /* We have no more ACKs => MTU change! */ - setup_receiver_mq(receiver); - } - return; - } + char dgram[sizeof(struct UDPBox) + receiver->mtu]; + struct UDPBox *box; + gcry_cipher_hd_t out_cipher; + size_t dpos; + + box = (struct UDPBox *) dgram; + ss->sequence_used++; + get_kid (&ss->master, ss->sequence_used, &box->kid); + setup_cipher (&ss->master, ss->sequence_used, &out_cipher); + /* Append encrypted payload to dgram */ + dpos = sizeof(struct UDPBox); + GNUNET_assert ( + 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); + dpos += msize; + do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); + GNUNET_assert (0 == gcry_cipher_gettag (out_cipher, + box->gcm_tag, + sizeof(box->gcm_tag))); + gcry_cipher_close (out_cipher); + if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, + dgram, + sizeof(dgram), + receiver->address, + receiver->address_len)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); + GNUNET_MQ_impl_send_continue (mq); + receiver->acks_available--; + if (0 == receiver->acks_available) + { + /* We have no more ACKs => MTU change! */ + setup_receiver_mq (receiver); + } + return; } - GNUNET_assert(0); + } + GNUNET_assert (0); } @@ -1982,15 +1996,15 @@ mq_send(struct GNUNET_MQ_Handle *mq, * @param impl_state our `struct ReceiverAddress` */ static void -mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) +mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct ReceiverAddress *receiver = impl_state; if (mq == receiver->mq) - { - receiver->mq = NULL; - receiver_destroy(receiver); - } + { + receiver->mq = NULL; + receiver_destroy (receiver); + } } @@ -2001,10 +2015,10 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) * @param impl_state our `struct RecvierAddress` */ static void -mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) +mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) { /* Cancellation is impossible with UDP; bail */ - GNUNET_assert(0); + GNUNET_assert (0); } @@ -2018,15 +2032,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) * @param error error code */ static void -mq_error(void *cls, enum GNUNET_MQ_Error error) +mq_error (void *cls, enum GNUNET_MQ_Error error) { struct ReceiverAddress *receiver = cls; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "MQ error in queue to %s: %d\n", - GNUNET_i2s(&receiver->target), - (int)error); - receiver_destroy(receiver); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "MQ error in queue to %s: %d\n", + GNUNET_i2s (&receiver->target), + (int) error); + receiver_destroy (receiver); } @@ -2038,63 +2052,63 @@ mq_error(void *cls, enum GNUNET_MQ_Error error) * @param receiver receiver to setup MQ for */ static void -setup_receiver_mq(struct ReceiverAddress *receiver) +setup_receiver_mq (struct ReceiverAddress *receiver) { size_t base_mtu; if (NULL != receiver->qh) - { - GNUNET_TRANSPORT_communicator_mq_del(receiver->qh); - receiver->qh = NULL; - } - GNUNET_assert(NULL == receiver->mq); + { + GNUNET_TRANSPORT_communicator_mq_del (receiver->qh); + receiver->qh = NULL; + } + GNUNET_assert (NULL == receiver->mq); switch (receiver->address->sa_family) - { - case AF_INET: - base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */ - - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */ - - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; - break; - - case AF_INET6: - base_mtu = 1280 /* Minimum MTU required by IPv6 */ - - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */ - - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; - break; - - default: - GNUNET_assert(0); - break; - } + { + case AF_INET: + base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */ + - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */ + - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; + break; + + case AF_INET6: + base_mtu = 1280 /* Minimum MTU required by IPv6 */ + - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */ + - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; + break; + + default: + GNUNET_assert (0); + break; + } if (0 == receiver->acks_available) - { - /* MTU based on full KX messages */ - receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */ - - sizeof(struct UDPConfirmation); /* 104 */ - } + { + /* MTU based on full KX messages */ + receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */ + - sizeof(struct UDPConfirmation); /* 104 */ + } else - { - /* MTU based on BOXed messages */ - receiver->mtu = base_mtu - sizeof(struct UDPBox); - } + { + /* MTU based on BOXed messages */ + receiver->mtu = base_mtu - sizeof(struct UDPBox); + } /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to 1404 (IPv4 + Box) bytes, depending on circumstances... */ if (NULL == receiver->mq) - receiver->mq = GNUNET_MQ_queue_for_callbacks(&mq_send, - &mq_destroy, - &mq_cancel, - receiver, - NULL, - &mq_error, - receiver); + receiver->mq = GNUNET_MQ_queue_for_callbacks (&mq_send, + &mq_destroy, + &mq_cancel, + receiver, + NULL, + &mq_error, + receiver); receiver->qh = - GNUNET_TRANSPORT_communicator_mq_add(ch, - &receiver->target, - receiver->foreign_addr, - receiver->mtu, - receiver->nt, - GNUNET_TRANSPORT_CS_OUTBOUND, - receiver->mq); + GNUNET_TRANSPORT_communicator_mq_add (ch, + &receiver->target, + receiver->foreign_addr, + receiver->mtu, + receiver->nt, + GNUNET_TRANSPORT_CS_OUTBOUND, + receiver->mq); } @@ -2117,47 +2131,47 @@ setup_receiver_mq(struct ReceiverAddress *receiver) * invalid */ static int -mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) +mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) { struct ReceiverAddress *receiver; const char *path; struct sockaddr *in; socklen_t in_len; - if (0 != strncmp(address, - COMMUNICATOR_ADDRESS_PREFIX "-", - strlen(COMMUNICATOR_ADDRESS_PREFIX "-"))) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")]; - in = udp_address_to_sockaddr(path, &in_len); + if (0 != strncmp (address, + COMMUNICATOR_ADDRESS_PREFIX "-", + strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; + in = udp_address_to_sockaddr (path, &in_len); - receiver = GNUNET_new(struct ReceiverAddress); + receiver = GNUNET_new (struct ReceiverAddress); receiver->address = in; receiver->address_len = in_len; receiver->target = *peer; - receiver->nt = GNUNET_NT_scanner_get_type(is, in, in_len); - (void)GNUNET_CONTAINER_multipeermap_put( + receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len); + (void) GNUNET_CONTAINER_multipeermap_put ( receivers, &receiver->target, receiver, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); receiver->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); - receiver->hn = GNUNET_CONTAINER_heap_insert(receivers_heap, - receiver, - receiver->timeout.abs_value_us); - GNUNET_STATISTICS_set(stats, - "# receivers active", - GNUNET_CONTAINER_multipeermap_size(receivers), - GNUNET_NO); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap, + receiver, + receiver->timeout.abs_value_us); + GNUNET_STATISTICS_set (stats, + "# receivers active", + GNUNET_CONTAINER_multipeermap_size (receivers), + GNUNET_NO); receiver->foreign_addr = - sockaddr_to_udpaddr_string(receiver->address, receiver->address_len); - setup_receiver_mq(receiver); + sockaddr_to_udpaddr_string (receiver->address, receiver->address_len); + setup_receiver_mq (receiver); if (NULL == timeout_task) - timeout_task = GNUNET_SCHEDULER_add_now(&check_timeouts, NULL); + timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL); return GNUNET_OK; } @@ -2171,15 +2185,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) * @return #GNUNET_OK to continue to iterate */ static int -get_receiver_delete_it(void *cls, - const struct GNUNET_PeerIdentity *target, - void *value) +get_receiver_delete_it (void *cls, + const struct GNUNET_PeerIdentity *target, + void *value) { struct ReceiverAddress *receiver = value; - (void)cls; - (void)target; - receiver_destroy(receiver); + (void) cls; + (void) target; + receiver_destroy (receiver); return GNUNET_OK; } @@ -2193,15 +2207,15 @@ get_receiver_delete_it(void *cls, * @return #GNUNET_OK to continue to iterate */ static int -get_sender_delete_it(void *cls, - const struct GNUNET_PeerIdentity *target, - void *value) +get_sender_delete_it (void *cls, + const struct GNUNET_PeerIdentity *target, + void *value) { struct SenderAddress *sender = value; - (void)cls; - (void)target; - sender_destroy(sender); + (void) cls; + (void) target; + sender_destroy (sender); return GNUNET_OK; } @@ -2212,64 +2226,64 @@ get_sender_delete_it(void *cls, * @param cls NULL (always) */ static void -do_shutdown(void *cls) +do_shutdown (void *cls) { if (NULL != nat) - { - GNUNET_NAT_unregister(nat); - nat = NULL; - } + { + GNUNET_NAT_unregister (nat); + nat = NULL; + } while (NULL != bi_head) - bi_destroy(bi_head); + bi_destroy (bi_head); if (NULL != broadcast_task) - { - GNUNET_SCHEDULER_cancel(broadcast_task); - broadcast_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (broadcast_task); + broadcast_task = NULL; + } if (NULL != read_task) - { - GNUNET_SCHEDULER_cancel(read_task); - read_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (read_task); + read_task = NULL; + } if (NULL != udp_sock) - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(udp_sock)); - udp_sock = NULL; - } - GNUNET_CONTAINER_multipeermap_iterate(receivers, - &get_receiver_delete_it, - NULL); - GNUNET_CONTAINER_multipeermap_destroy(receivers); - GNUNET_CONTAINER_multipeermap_iterate(senders, &get_sender_delete_it, NULL); - GNUNET_CONTAINER_multipeermap_destroy(senders); - GNUNET_CONTAINER_multishortmap_destroy(key_cache); - GNUNET_CONTAINER_heap_destroy(senders_heap); - GNUNET_CONTAINER_heap_destroy(receivers_heap); + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (udp_sock)); + udp_sock = NULL; + } + GNUNET_CONTAINER_multipeermap_iterate (receivers, + &get_receiver_delete_it, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (receivers); + GNUNET_CONTAINER_multipeermap_iterate (senders, &get_sender_delete_it, NULL); + GNUNET_CONTAINER_multipeermap_destroy (senders); + GNUNET_CONTAINER_multishortmap_destroy (key_cache); + GNUNET_CONTAINER_heap_destroy (senders_heap); + GNUNET_CONTAINER_heap_destroy (receivers_heap); if (NULL != ch) - { - GNUNET_TRANSPORT_communicator_disconnect(ch); - ch = NULL; - } + { + GNUNET_TRANSPORT_communicator_disconnect (ch); + ch = NULL; + } if (NULL != ah) - { - GNUNET_TRANSPORT_application_done(ah); - ah = NULL; - } + { + GNUNET_TRANSPORT_application_done (ah); + ah = NULL; + } if (NULL != stats) - { - GNUNET_STATISTICS_destroy(stats, GNUNET_NO); - stats = NULL; - } + { + GNUNET_STATISTICS_destroy (stats, GNUNET_NO); + stats = NULL; + } if (NULL != my_private_key) - { - GNUNET_free(my_private_key); - my_private_key = NULL; - } + { + GNUNET_free (my_private_key); + my_private_key = NULL; + } if (NULL != is) - { - GNUNET_NT_scanner_done(is); - is = NULL; - } + { + GNUNET_NT_scanner_done (is); + is = NULL; + } } @@ -2283,24 +2297,24 @@ do_shutdown(void *cls) * @param msg payload */ static void -enc_notify_cb(void *cls, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *msg) +enc_notify_cb (void *cls, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *msg) { const struct UDPAck *ack; - (void)cls; - if ((ntohs(msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) || - (ntohs(msg->size) != sizeof(struct UDPAck))) - { - GNUNET_break_op(0); - return; - } - ack = (const struct UDPAck *)msg; - GNUNET_CONTAINER_multipeermap_get_multiple(receivers, - sender, - &handle_ack, - (void *)ack); + (void) cls; + if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) || + (ntohs (msg->size) != sizeof(struct UDPAck))) + { + GNUNET_break_op (0); + return; + } + ack = (const struct UDPAck *) msg; + GNUNET_CONTAINER_multipeermap_get_multiple (receivers, + sender, + &handle_ack, + (void *) ack); } @@ -2318,39 +2332,39 @@ enc_notify_cb(void *cls, * @param addrlen actual length of the @a addr */ static void -nat_address_cb(void *cls, - void **app_ctx, - int add_remove, - enum GNUNET_NAT_AddressClass ac, - const struct sockaddr *addr, - socklen_t addrlen) +nat_address_cb (void *cls, + void **app_ctx, + int add_remove, + enum GNUNET_NAT_AddressClass ac, + const struct sockaddr *addr, + socklen_t addrlen) { char *my_addr; struct GNUNET_TRANSPORT_AddressIdentifier *ai; if (GNUNET_YES == add_remove) - { - enum GNUNET_NetworkType nt; - - GNUNET_asprintf(&my_addr, - "%s-%s", - COMMUNICATOR_ADDRESS_PREFIX, - GNUNET_a2s(addr, addrlen)); - nt = GNUNET_NT_scanner_get_type(is, addr, addrlen); - ai = - GNUNET_TRANSPORT_communicator_address_add(ch, - my_addr, - nt, - GNUNET_TIME_UNIT_FOREVER_REL); - GNUNET_free(my_addr); - *app_ctx = ai; - } + { + enum GNUNET_NetworkType nt; + + GNUNET_asprintf (&my_addr, + "%s-%s", + COMMUNICATOR_ADDRESS_PREFIX, + GNUNET_a2s (addr, addrlen)); + nt = GNUNET_NT_scanner_get_type (is, addr, addrlen); + ai = + GNUNET_TRANSPORT_communicator_address_add (ch, + my_addr, + nt, + GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_free (my_addr); + *app_ctx = ai; + } else - { - ai = *app_ctx; - GNUNET_TRANSPORT_communicator_address_remove(ai); - *app_ctx = NULL; - } + { + ai = *app_ctx; + GNUNET_TRANSPORT_communicator_address_remove (ai); + *app_ctx = NULL; + } } @@ -2360,69 +2374,69 @@ nat_address_cb(void *cls, * @param cls a `struct BroadcastInterface` */ static void -ifc_broadcast(void *cls) +ifc_broadcast (void *cls) { struct BroadcastInterface *bi = cls; struct GNUNET_TIME_Relative delay; delay = BROADCAST_FREQUENCY; delay.rel_value_us = - GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us); + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us); bi->broadcast_task = - GNUNET_SCHEDULER_add_delayed(INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi); + GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi); switch (bi->sa->sa_family) - { - case AF_INET: { + { + case AF_INET: { static int yes = 1; static int no = 0; ssize_t sent; - if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock, - SOL_SOCKET, - SO_BROADCAST, - &yes, - sizeof(int))) - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); - sent = GNUNET_NETWORK_socket_sendto(udp_sock, - &bi->bcm, - sizeof(bi->bcm), - bi->ba, - bi->salen); + if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, + SOL_SOCKET, + SO_BROADCAST, + &yes, + sizeof(int))) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); + sent = GNUNET_NETWORK_socket_sendto (udp_sock, + &bi->bcm, + sizeof(bi->bcm), + bi->ba, + bi->salen); if (-1 == sent) - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "sendto"); - if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock, - SOL_SOCKET, - SO_BROADCAST, - &no, - sizeof(int))) - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); + if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, + SOL_SOCKET, + SO_BROADCAST, + &no, + sizeof(int))) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); break; } - case AF_INET6: { + case AF_INET6: { ssize_t sent; struct sockaddr_in6 dst; dst.sin6_family = AF_INET6; - dst.sin6_port = htons(my_port); + dst.sin6_port = htons (my_port); dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr; - dst.sin6_scope_id = ((struct sockaddr_in6 *)bi->ba)->sin6_scope_id; + dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id; - sent = GNUNET_NETWORK_socket_sendto(udp_sock, - &bi->bcm, - sizeof(bi->bcm), - (const struct sockaddr *)&dst, - sizeof(dst)); + sent = GNUNET_NETWORK_socket_sendto (udp_sock, + &bi->bcm, + sizeof(bi->bcm), + (const struct sockaddr *) &dst, + sizeof(dst)); if (-1 == sent) - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "sendto"); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); break; } - default: - GNUNET_break(0); - break; - } + default: + GNUNET_break (0); + break; + } } @@ -2441,90 +2455,90 @@ ifc_broadcast(void *cls) * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort */ static int -iface_proc(void *cls, - const char *name, - int isDefault, - const struct sockaddr *addr, - const struct sockaddr *broadcast_addr, - const struct sockaddr *netmask, - socklen_t addrlen) +iface_proc (void *cls, + const char *name, + int isDefault, + const struct sockaddr *addr, + const struct sockaddr *broadcast_addr, + const struct sockaddr *netmask, + socklen_t addrlen) { struct BroadcastInterface *bi; enum GNUNET_NetworkType network; struct UdpBroadcastSignature ubs; - (void)cls; - (void)netmask; + (void) cls; + (void) netmask; if (NULL == addr) return GNUNET_YES; /* need to know our address! */ - network = GNUNET_NT_scanner_get_type(is, addr, addrlen); + network = GNUNET_NT_scanner_get_type (is, addr, addrlen); if (GNUNET_NT_LOOPBACK == network) - { - /* Broadcasting on loopback does not make sense */ - return GNUNET_YES; - } + { + /* Broadcasting on loopback does not make sense */ + return GNUNET_YES; + } for (bi = bi_head; NULL != bi; bi = bi->next) + { + if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen))) { - if ((bi->salen == addrlen) && (0 == memcmp(addr, bi->sa, addrlen))) - { - bi->found = GNUNET_YES; - return GNUNET_OK; - } + bi->found = GNUNET_YES; + return GNUNET_OK; } + } if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr)) return GNUNET_OK; /* broadcast_addr is required for IPv6! */ if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket)) return GNUNET_OK; /* not using IPv6 */ - bi = GNUNET_new(struct BroadcastInterface); - bi->sa = GNUNET_memdup(addr, addrlen); + bi = GNUNET_new (struct BroadcastInterface); + bi->sa = GNUNET_memdup (addr, addrlen); if (NULL != broadcast_addr) - bi->ba = GNUNET_memdup(broadcast_addr, addrlen); + bi->ba = GNUNET_memdup (broadcast_addr, addrlen); bi->salen = addrlen; bi->found = GNUNET_YES; bi->bcm.sender = my_identity; - ubs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); - ubs.purpose.size = htonl(sizeof(ubs)); + ubs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); + ubs.purpose.size = htonl (sizeof(ubs)); ubs.sender = my_identity; - GNUNET_CRYPTO_hash(addr, addrlen, &ubs.h_address); - GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, - &ubs.purpose, - &bi->bcm.sender_sig)); - bi->broadcast_task = GNUNET_SCHEDULER_add_now(&ifc_broadcast, bi); - GNUNET_CONTAINER_DLL_insert(bi_head, bi_tail, bi); + GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address); + GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, + &ubs.purpose, + &bi->bcm.sender_sig)); + bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast, bi); + GNUNET_CONTAINER_DLL_insert (bi_head, bi_tail, bi); if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr)) + { + /* Create IPv6 multicast request */ + const struct sockaddr_in6 *s6 = + (const struct sockaddr_in6 *) broadcast_addr; + + GNUNET_assert ( + 1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr)); + + /* http://tools.ietf.org/html/rfc2553#section-5.2: + * + * IPV6_JOIN_GROUP + * + * Join a multicast group on a specified local interface. If the + * interface index is specified as 0, the kernel chooses the local + * interface. For example, some kernels look up the multicast + * group in the normal IPv6 routing table and using the resulting + * interface; we do this for each interface, so no need to use + * zero (anymore...). + */ + bi->mcreq.ipv6mr_interface = s6->sin6_scope_id; + + /* Join the multicast group */ + if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, + IPPROTO_IPV6, + IPV6_JOIN_GROUP, + &bi->mcreq, + sizeof(bi->mcreq))) { - /* Create IPv6 multicast request */ - const struct sockaddr_in6 *s6 = - (const struct sockaddr_in6 *)broadcast_addr; - - GNUNET_assert( - 1 == inet_pton(AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr)); - - /* http://tools.ietf.org/html/rfc2553#section-5.2: - * - * IPV6_JOIN_GROUP - * - * Join a multicast group on a specified local interface. If the - * interface index is specified as 0, the kernel chooses the local - * interface. For example, some kernels look up the multicast - * group in the normal IPv6 routing table and using the resulting - * interface; we do this for each interface, so no need to use - * zero (anymore...). - */ - bi->mcreq.ipv6mr_interface = s6->sin6_scope_id; - - /* Join the multicast group */ - if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock, - IPPROTO_IPV6, - IPV6_JOIN_GROUP, - &bi->mcreq, - sizeof(bi->mcreq))) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); - } + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); } + } return GNUNET_OK; } @@ -2535,23 +2549,23 @@ iface_proc(void *cls, * @param cls NULL, unused */ static void -do_broadcast(void *cls) +do_broadcast (void *cls) { struct BroadcastInterface *bin; - (void)cls; + (void) cls; for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next) bi->found = GNUNET_NO; - GNUNET_OS_network_interfaces_list(&iface_proc, NULL); + GNUNET_OS_network_interfaces_list (&iface_proc, NULL); for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin) - { - bin = bi->next; - if (GNUNET_NO == bi->found) - bi_destroy(bi); - } - broadcast_task = GNUNET_SCHEDULER_add_delayed(INTERFACE_SCAN_FREQUENCY, - &do_broadcast, - NULL); + { + bin = bi->next; + if (GNUNET_NO == bi->found) + bi_destroy (bi); + } + broadcast_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, + &do_broadcast, + NULL); } @@ -2564,10 +2578,10 @@ do_broadcast(void *cls) * @param c configuration */ static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { char *bindto; struct sockaddr *in; @@ -2575,143 +2589,143 @@ run(void *cls, struct sockaddr_storage in_sto; socklen_t sto_len; - (void)cls; + (void) cls; cfg = c; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename(cfg, - COMMUNICATOR_CONFIG_SECTION, - "BINDTO", - &bindto)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - COMMUNICATOR_CONFIG_SECTION, - "BINDTO"); - return; - } + GNUNET_CONFIGURATION_get_value_filename (cfg, + COMMUNICATOR_CONFIG_SECTION, + "BINDTO", + &bindto)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + COMMUNICATOR_CONFIG_SECTION, + "BINDTO"); + return; + } - in = udp_address_to_sockaddr(bindto, &in_len); + in = udp_address_to_sockaddr (bindto, &in_len); if (NULL == in) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to setup UDP socket address with path `%s'\n", - bindto); - GNUNET_free(bindto); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to setup UDP socket address with path `%s'\n", + bindto); + GNUNET_free (bindto); + return; + } udp_sock = - GNUNET_NETWORK_socket_create(in->sa_family, SOCK_DGRAM, IPPROTO_UDP); + GNUNET_NETWORK_socket_create (in->sa_family, SOCK_DGRAM, IPPROTO_UDP); if (NULL == udp_sock) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); - GNUNET_free(in); - GNUNET_free(bindto); - return; - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); + GNUNET_free (in); + GNUNET_free (bindto); + return; + } if (AF_INET6 == in->sa_family) have_v6_socket = GNUNET_YES; - if (GNUNET_OK != GNUNET_NETWORK_socket_bind(udp_sock, in, in_len)) - { - GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", bindto); - GNUNET_NETWORK_socket_close(udp_sock); - udp_sock = NULL; - GNUNET_free(in); - GNUNET_free(bindto); - return; - } + if (GNUNET_OK != GNUNET_NETWORK_socket_bind (udp_sock, in, in_len)) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto); + GNUNET_NETWORK_socket_close (udp_sock); + udp_sock = NULL; + GNUNET_free (in); + GNUNET_free (bindto); + return; + } /* We might have bound to port 0, allowing the OS to figure it out; thus, get the real IN-address from the socket */ sto_len = sizeof(in_sto); - if (0 != getsockname(GNUNET_NETWORK_get_fd(udp_sock), - (struct sockaddr *)&in_sto, - &sto_len)) - { - memcpy(&in_sto, in, in_len); - sto_len = in_len; - } - GNUNET_free(in); - GNUNET_free(bindto); - in = (struct sockaddr *)&in_sto; + if (0 != getsockname (GNUNET_NETWORK_get_fd (udp_sock), + (struct sockaddr *) &in_sto, + &sto_len)) + { + memcpy (&in_sto, in, in_len); + sto_len = in_len; + } + GNUNET_free (in); + GNUNET_free (bindto); + in = (struct sockaddr *) &in_sto; in_len = sto_len; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Bound to `%s'\n", - GNUNET_a2s((const struct sockaddr *)&in_sto, sto_len)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Bound to `%s'\n", + GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); switch (in->sa_family) - { - case AF_INET: - my_port = ntohs(((struct sockaddr_in *)in)->sin_port); - break; + { + case AF_INET: + my_port = ntohs (((struct sockaddr_in *) in)->sin_port); + break; - case AF_INET6: - my_port = ntohs(((struct sockaddr_in6 *)in)->sin6_port); - break; + case AF_INET6: + my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port); + break; - default: - GNUNET_break(0); - my_port = 0; - } - stats = GNUNET_STATISTICS_create("C-UDP", cfg); - senders = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES); - receivers = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES); - senders_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); + default: + GNUNET_break (0); + my_port = 0; + } + stats = GNUNET_STATISTICS_create ("C-UDP", cfg); + senders = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); + receivers = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); + senders_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); receivers_heap = - GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); - key_cache = GNUNET_CONTAINER_multishortmap_create(1024, GNUNET_YES); - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); - is = GNUNET_NT_scanner_init(); - my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); + GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); + key_cache = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_YES); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + is = GNUNET_NT_scanner_init (); + my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); if (NULL == my_private_key) - { - GNUNET_log( - GNUNET_ERROR_TYPE_ERROR, - _( - "Transport service is lacking key configuration settings. Exiting.\n")); - GNUNET_SCHEDULER_shutdown(); - return; - } - GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key); + { + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + _ ( + "Transport service is lacking key configuration settings. Exiting.\n")); + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); /* start reading */ - read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - udp_sock, - &sock_read, - NULL); - ch = GNUNET_TRANSPORT_communicator_connect(cfg, - COMMUNICATOR_CONFIG_SECTION, - COMMUNICATOR_ADDRESS_PREFIX, - GNUNET_TRANSPORT_CC_UNRELIABLE, - &mq_init, - NULL, - &enc_notify_cb, + read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + udp_sock, + &sock_read, NULL); + ch = GNUNET_TRANSPORT_communicator_connect (cfg, + COMMUNICATOR_CONFIG_SECTION, + COMMUNICATOR_ADDRESS_PREFIX, + GNUNET_TRANSPORT_CC_UNRELIABLE, + &mq_init, + NULL, + &enc_notify_cb, + NULL); if (NULL == ch) - { - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - return; - } - ah = GNUNET_TRANSPORT_application_init(cfg); + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + ah = GNUNET_TRANSPORT_application_init (cfg); if (NULL == ah) - { - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - return; - } + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } /* start broadcasting */ if (GNUNET_YES != - GNUNET_CONFIGURATION_get_value_yesno(cfg, - COMMUNICATOR_CONFIG_SECTION, - "DISABLE_BROADCAST")) - { - broadcast_task = GNUNET_SCHEDULER_add_now(&do_broadcast, NULL); - } - nat = GNUNET_NAT_register(cfg, - COMMUNICATOR_CONFIG_SECTION, - IPPROTO_UDP, - 1 /* one address */, - (const struct sockaddr **)&in, - &in_len, - &nat_address_cb, - NULL /* FIXME: support reversal: #5529 */, - NULL /* closure */); + GNUNET_CONFIGURATION_get_value_yesno (cfg, + COMMUNICATOR_CONFIG_SECTION, + "DISABLE_BROADCAST")) + { + broadcast_task = GNUNET_SCHEDULER_add_now (&do_broadcast, NULL); + } + nat = GNUNET_NAT_register (cfg, + COMMUNICATOR_CONFIG_SECTION, + IPPROTO_UDP, + 1 /* one address */, + (const struct sockaddr **) &in, + &in_len, + &nat_address_cb, + NULL /* FIXME: support reversal: #5529 */, + NULL /* closure */); } @@ -2723,26 +2737,26 @@ run(void *cls, * @return 0 ok, 1 on error */ int -main(int argc, char *const *argv) +main (int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; int ret; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; - ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc, - argv, - "gnunet-communicator-udp", - _("GNUnet UDP communicator"), - options, - &run, - NULL)) + ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, + argv, + "gnunet-communicator-udp", + _ ("GNUnet UDP communicator"), + options, + &run, + NULL)) ? 0 : 1; - GNUNET_free((void *)argv); + GNUNET_free ((void *) argv); return ret; } diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c index da610daa1..d8205addb 100644 --- a/src/transport/gnunet-communicator-unix.c +++ b/src/transport/gnunet-communicator-unix.c @@ -64,7 +64,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * UNIX Message-Packet header. */ -struct UNIXMessage { +struct UNIXMessage +{ /** * Message header. */ @@ -82,7 +83,8 @@ GNUNET_NETWORK_STRUCT_END /** * Handle for a queue. */ -struct Queue { +struct Queue +{ /** * Queues with pending messages (!) are kept in a DLL. */ @@ -205,37 +207,37 @@ static struct GNUNET_TRANSPORT_AddressIdentifier *ai; * @param queue queue to close down */ static void -queue_destroy(struct Queue *queue) +queue_destroy (struct Queue *queue) { struct GNUNET_MQ_Handle *mq; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting queue for peer `%s'\n", - GNUNET_i2s(&queue->target)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Disconnecting queue for peer `%s'\n", + GNUNET_i2s (&queue->target)); if (0 != queue->bytes_in_queue) - { - GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue); - queue->bytes_in_queue = 0; - } + { + GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); + queue->bytes_in_queue = 0; + } if (NULL != (mq = queue->mq)) - { - queue->mq = NULL; - GNUNET_MQ_destroy(mq); - } - GNUNET_assert( + { + queue->mq = NULL; + GNUNET_MQ_destroy (mq); + } + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(queue_map, &queue->target, queue)); - GNUNET_STATISTICS_set(stats, - "# queues active", - GNUNET_CONTAINER_multipeermap_size(queue_map), - GNUNET_NO); + GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue)); + GNUNET_STATISTICS_set (stats, + "# queues active", + GNUNET_CONTAINER_multipeermap_size (queue_map), + GNUNET_NO); if (NULL != queue->timeout_task) - { - GNUNET_SCHEDULER_cancel(queue->timeout_task); - queue->timeout_task = NULL; - } - GNUNET_free(queue->address); - GNUNET_free(queue); + { + GNUNET_SCHEDULER_cancel (queue->timeout_task); + queue->timeout_task = NULL; + } + GNUNET_free (queue->address); + GNUNET_free (queue); } @@ -245,28 +247,28 @@ queue_destroy(struct Queue *queue) * @param cls the `struct Queue *` to disconnect */ static void -queue_timeout(void *cls) +queue_timeout (void *cls) { struct Queue *queue = cls; struct GNUNET_TIME_Relative left; queue->timeout_task = NULL; - left = GNUNET_TIME_absolute_get_remaining(queue->timeout); + left = GNUNET_TIME_absolute_get_remaining (queue->timeout); if (0 != left.rel_value_us) - { - /* not actually our turn yet, but let's at least update - the monitor, it may think we're about to die ... */ - queue->timeout_task = - GNUNET_SCHEDULER_add_delayed(left, &queue_timeout, queue); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Queue %p was idle for %s, disconnecting\n", - queue, - GNUNET_STRINGS_relative_time_to_string( - GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - GNUNET_YES)); - queue_destroy(queue); + { + /* not actually our turn yet, but let's at least update + the monitor, it may think we're about to die ... */ + queue->timeout_task = + GNUNET_SCHEDULER_add_delayed (left, &queue_timeout, queue); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Queue %p was idle for %s, disconnecting\n", + queue, + GNUNET_STRINGS_relative_time_to_string ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + GNUNET_YES)); + queue_destroy (queue); } @@ -278,11 +280,11 @@ queue_timeout(void *cls) * @param queue queue for which the timeout should be rescheduled */ static void -reschedule_queue_timeout(struct Queue *queue) +reschedule_queue_timeout (struct Queue *queue) { - GNUNET_assert(NULL != queue->timeout_task); + GNUNET_assert (NULL != queue->timeout_task); queue->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); } @@ -295,22 +297,22 @@ reschedule_queue_timeout(struct Queue *queue) * @return converted unix path */ static struct sockaddr_un * -unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len) +unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) { struct sockaddr_un *un; size_t slen; - GNUNET_assert(0 < strlen(unixpath)); /* sanity check */ - un = GNUNET_new(struct sockaddr_un); + GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ + un = GNUNET_new (struct sockaddr_un); un->sun_family = AF_UNIX; - slen = strlen(unixpath); + slen = strlen (unixpath); if (slen >= sizeof(un->sun_path)) slen = sizeof(un->sun_path) - 1; - GNUNET_memcpy(un->sun_path, unixpath, slen); + GNUNET_memcpy (un->sun_path, unixpath, slen); un->sun_path[slen] = '\0'; slen = sizeof(struct sockaddr_un); #if HAVE_SOCKADDR_UN_SUN_LEN - un->sun_len = (u_char)slen; + un->sun_len = (u_char) slen; #endif (*sock_len) = slen; if ('@' == un->sun_path[0]) @@ -322,7 +324,8 @@ unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len) /** * Closure to #lookup_queue_it(). */ -struct LookupCtx { +struct LookupCtx +{ /** * Location to store the queue, if found. */ @@ -349,17 +352,17 @@ struct LookupCtx { * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success */ static int -lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) +lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { struct LookupCtx *lctx = cls; struct Queue *queue = value; if ((queue->address_len = lctx->un_len) && - (0 == memcmp(lctx->un, queue->address, queue->address_len))) - { - lctx->res = queue; - return GNUNET_NO; - } + (0 == memcmp (lctx->un, queue->address, queue->address_len))) + { + lctx->res = queue; + return GNUNET_NO; + } return GNUNET_YES; } @@ -372,18 +375,18 @@ lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) * @return NULL if queue was not found */ static struct Queue * -lookup_queue(const struct GNUNET_PeerIdentity *peer, - const struct sockaddr_un *un, - socklen_t un_len) +lookup_queue (const struct GNUNET_PeerIdentity *peer, + const struct sockaddr_un *un, + socklen_t un_len) { struct LookupCtx lctx; lctx.un = un; lctx.un_len = un_len; - GNUNET_CONTAINER_multipeermap_get_multiple(queue_map, - peer, - &lookup_queue_it, - &lctx); + GNUNET_CONTAINER_multipeermap_get_multiple (queue_map, + peer, + &lookup_queue_it, + &lctx); return lctx.res; } @@ -395,105 +398,105 @@ lookup_queue(const struct GNUNET_PeerIdentity *peer, * @param cls NULL */ static void -select_write_cb(void *cls) +select_write_cb (void *cls) { struct Queue *queue = queue_tail; const struct GNUNET_MessageHeader *msg = queue->msg; - size_t msg_size = ntohs(msg->size); + size_t msg_size = ntohs (msg->size); ssize_t sent; /* take queue of the ready list */ write_task = NULL; - GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue); + GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); if (NULL != queue_head) - write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, - unix_sock, - &select_write_cb, - NULL); + write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + unix_sock, + &select_write_cb, + NULL); /* send 'msg' */ queue->msg = NULL; - GNUNET_MQ_impl_send_continue(queue->mq); + GNUNET_MQ_impl_send_continue (queue->mq); resend: /* Send the data */ - sent = GNUNET_NETWORK_socket_sendto(unix_sock, - msg, - msg_size, - (const struct sockaddr *)queue->address, - queue->address_len); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "UNIX transmitted message to %s (%d/%u: %s)\n", - GNUNET_i2s(&queue->target), - (int)sent, - (unsigned int)msg_size, - (sent < 0) ? strerror(errno) : "ok"); + sent = GNUNET_NETWORK_socket_sendto (unix_sock, + msg, + msg_size, + (const struct sockaddr *) queue->address, + queue->address_len); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "UNIX transmitted message to %s (%d/%u: %s)\n", + GNUNET_i2s (&queue->target), + (int) sent, + (unsigned int) msg_size, + (sent < 0) ? strerror (errno) : "ok"); if (-1 != sent) - { - GNUNET_STATISTICS_update(stats, - "# bytes sent", - (long long)sent, - GNUNET_NO); - reschedule_queue_timeout(queue); - return; /* all good */ - } - GNUNET_STATISTICS_update(stats, - "# network transmission failures", - 1, - GNUNET_NO); + { + GNUNET_STATISTICS_update (stats, + "# bytes sent", + (long long) sent, + GNUNET_NO); + reschedule_queue_timeout (queue); + return; /* all good */ + } + GNUNET_STATISTICS_update (stats, + "# network transmission failures", + 1, + GNUNET_NO); switch (errno) - { - case EAGAIN: - case ENOBUFS: - /* We should retry later... */ - GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "send"); - return; + { + case EAGAIN: + case ENOBUFS: + /* We should retry later... */ + GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send"); + return; - case EMSGSIZE: { + case EMSGSIZE: { socklen_t size = 0; socklen_t len = sizeof(size); - GNUNET_NETWORK_socket_getsockopt(unix_sock, - SOL_SOCKET, - SO_SNDBUF, - &size, - &len); - if (size > ntohs(msg->size)) - { - /* Buffer is bigger than message: error, no retry - * This should never happen!*/ - GNUNET_break(0); - return; - } - GNUNET_log( + GNUNET_NETWORK_socket_getsockopt (unix_sock, + SOL_SOCKET, + SO_SNDBUF, + &size, + &len); + if (size > ntohs (msg->size)) + { + /* Buffer is bigger than message: error, no retry + * This should never happen!*/ + GNUNET_break (0); + return; + } + GNUNET_log ( GNUNET_ERROR_TYPE_DEBUG, "Trying to increase socket buffer size from %u to %u for message size %u\n", - (unsigned int)size, - (unsigned int)((msg_size / 1000) + 2) * 1000, - (unsigned int)msg_size); + (unsigned int) size, + (unsigned int) ((msg_size / 1000) + 2) * 1000, + (unsigned int) msg_size); size = ((msg_size / 1000) + 2) * 1000; - if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock, - SOL_SOCKET, - SO_SNDBUF, - &size, - sizeof(size))) + if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock, + SOL_SOCKET, + SO_SNDBUF, + &size, + sizeof(size))) goto resend; /* Increased buffer size, retry sending */ /* Ok, then just try very modest increase */ size = msg_size; - if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock, - SOL_SOCKET, - SO_SNDBUF, - &size, - sizeof(size))) + if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock, + SOL_SOCKET, + SO_SNDBUF, + &size, + sizeof(size))) goto resend; /* Increased buffer size, retry sending */ /* Could not increase buffer size: error, no retry */ - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt"); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt"); return; } - default: - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "send"); - return; - } + default: + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "send"); + return; + } } @@ -506,22 +509,22 @@ resend: * @param impl_state our `struct Queue` */ static void -mq_send(struct GNUNET_MQ_Handle *mq, - const struct GNUNET_MessageHeader *msg, - void *impl_state) +mq_send (struct GNUNET_MQ_Handle *mq, + const struct GNUNET_MessageHeader *msg, + void *impl_state) { struct Queue *queue = impl_state; - GNUNET_assert(mq == queue->mq); - GNUNET_assert(NULL == queue->msg); + GNUNET_assert (mq == queue->mq); + GNUNET_assert (NULL == queue->msg); queue->msg = msg; - GNUNET_CONTAINER_DLL_insert(queue_head, queue_tail, queue); - GNUNET_assert(NULL != unix_sock); + GNUNET_CONTAINER_DLL_insert (queue_head, queue_tail, queue); + GNUNET_assert (NULL != unix_sock); if (NULL == write_task) - write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, - unix_sock, - &select_write_cb, - NULL); + write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + unix_sock, + &select_write_cb, + NULL); } @@ -534,15 +537,15 @@ mq_send(struct GNUNET_MQ_Handle *mq, * @param impl_state our `struct Queue` */ static void -mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) +mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct Queue *queue = impl_state; if (mq == queue->mq) - { - queue->mq = NULL; - queue_destroy(queue); - } + { + queue->mq = NULL; + queue_destroy (queue); + } } @@ -553,19 +556,19 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) * @param impl_state our `struct Queue` */ static void -mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) +mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct Queue *queue = impl_state; - GNUNET_assert(NULL != queue->msg); + GNUNET_assert (NULL != queue->msg); queue->msg = NULL; - GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue); - GNUNET_assert(NULL != write_task); + GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); + GNUNET_assert (NULL != write_task); if (NULL == queue_head) - { - GNUNET_SCHEDULER_cancel(write_task); - write_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (write_task); + write_task = NULL; + } } @@ -579,15 +582,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) * @param error error code */ static void -mq_error(void *cls, enum GNUNET_MQ_Error error) +mq_error (void *cls, enum GNUNET_MQ_Error error) { struct Queue *queue = cls; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "UNIX MQ error in queue to %s: %d\n", - GNUNET_i2s(&queue->target), - (int)error); - queue_destroy(queue); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "UNIX MQ error in queue to %s: %d\n", + GNUNET_i2s (&queue->target), + (int) error); + queue_destroy (queue); } @@ -602,60 +605,60 @@ mq_error(void *cls, enum GNUNET_MQ_Error error) * @return the queue or NULL of max connections exceeded */ static struct Queue * -setup_queue(const struct GNUNET_PeerIdentity *target, - enum GNUNET_TRANSPORT_ConnectionStatus cs, - const struct sockaddr_un *un, - socklen_t un_len) +setup_queue (const struct GNUNET_PeerIdentity *target, + enum GNUNET_TRANSPORT_ConnectionStatus cs, + const struct sockaddr_un *un, + socklen_t un_len) { struct Queue *queue; - queue = GNUNET_new(struct Queue); + queue = GNUNET_new (struct Queue); queue->target = *target; - queue->address = GNUNET_memdup(un, un_len); + queue->address = GNUNET_memdup (un, un_len); queue->address_len = un_len; - (void)GNUNET_CONTAINER_multipeermap_put( + (void) GNUNET_CONTAINER_multipeermap_put ( queue_map, &queue->target, queue, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GNUNET_STATISTICS_set(stats, - "# queues active", - GNUNET_CONTAINER_multipeermap_size(queue_map), - GNUNET_NO); + GNUNET_STATISTICS_set (stats, + "# queues active", + GNUNET_CONTAINER_multipeermap_size (queue_map), + GNUNET_NO); queue->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); queue->timeout_task = - GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - &queue_timeout, - queue); - queue->mq = GNUNET_MQ_queue_for_callbacks(&mq_send, - &mq_destroy, - &mq_cancel, - queue, - NULL, - &mq_error, - queue); + GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + &queue_timeout, + queue); + queue->mq = GNUNET_MQ_queue_for_callbacks (&mq_send, + &mq_destroy, + &mq_cancel, + queue, + NULL, + &mq_error, + queue); { char *foreign_addr; if ('\0' == un->sun_path[0]) - GNUNET_asprintf(&foreign_addr, - "%s-@%s", - COMMUNICATOR_ADDRESS_PREFIX, - &un->sun_path[1]); + GNUNET_asprintf (&foreign_addr, + "%s-@%s", + COMMUNICATOR_ADDRESS_PREFIX, + &un->sun_path[1]); else - GNUNET_asprintf(&foreign_addr, - "%s-%s", - COMMUNICATOR_ADDRESS_PREFIX, - un->sun_path); - queue->qh = GNUNET_TRANSPORT_communicator_mq_add(ch, - &queue->target, - foreign_addr, - UNIX_MTU, - GNUNET_NT_LOOPBACK, - cs, - queue->mq); - GNUNET_free(foreign_addr); + GNUNET_asprintf (&foreign_addr, + "%s-%s", + COMMUNICATOR_ADDRESS_PREFIX, + un->sun_path); + queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, + &queue->target, + foreign_addr, + UNIX_MTU, + GNUNET_NT_LOOPBACK, + cs, + queue->mq); + GNUNET_free (foreign_addr); } return queue; } @@ -669,7 +672,7 @@ setup_queue(const struct GNUNET_PeerIdentity *target, * @param cls NULL */ static void -select_read_cb(void *cls); +select_read_cb (void *cls); /** @@ -680,21 +683,21 @@ select_read_cb(void *cls); * @param success #GNUNET_OK on success */ static void -receive_complete_cb(void *cls, int success) +receive_complete_cb (void *cls, int success) { - (void)cls; + (void) cls; delivering_messages--; if (GNUNET_OK != success) - GNUNET_STATISTICS_update(stats, - "# transport transmission failures", - 1, - GNUNET_NO); - GNUNET_assert(NULL != unix_sock); + GNUNET_STATISTICS_update (stats, + "# transport transmission failures", + 1, + GNUNET_NO); + GNUNET_assert (NULL != unix_sock); if ((NULL == read_task) && (delivering_messages < max_queue_length)) - read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - unix_sock, - &select_read_cb, - NULL); + read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + unix_sock, + &select_read_cb, + NULL); } @@ -706,7 +709,7 @@ receive_complete_cb(void *cls, int success) * @param cls NULL */ static void -select_read_cb(void *cls) +select_read_cb (void *cls) { char buf[65536] GNUNET_ALIGN; struct Queue *queue; @@ -716,93 +719,93 @@ select_read_cb(void *cls) ssize_t ret; uint16_t msize; - GNUNET_assert(NULL != unix_sock); - read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - unix_sock, - &select_read_cb, - NULL); + GNUNET_assert (NULL != unix_sock); + read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + unix_sock, + &select_read_cb, + NULL); addrlen = sizeof(un); - memset(&un, 0, sizeof(un)); - ret = GNUNET_NETWORK_socket_recvfrom(unix_sock, - buf, - sizeof(buf), - (struct sockaddr *)&un, - &addrlen); + memset (&un, 0, sizeof(un)); + ret = GNUNET_NETWORK_socket_recvfrom (unix_sock, + buf, + sizeof(buf), + (struct sockaddr *) &un, + &addrlen); if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno))) return; if (-1 == ret) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom"); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Read %d bytes from socket %s\n", - (int)ret, - un.sun_path); - GNUNET_assert(AF_UNIX == (un.sun_family)); - msg = (struct UNIXMessage *)buf; - msize = ntohs(msg->header.size); + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Read %d bytes from socket %s\n", + (int) ret, + un.sun_path); + GNUNET_assert (AF_UNIX == (un.sun_family)); + msg = (struct UNIXMessage *) buf; + msize = ntohs (msg->header.size); if ((msize < sizeof(struct UNIXMessage)) || (msize > ret)) - { - GNUNET_break_op(0); - return; - } - queue = lookup_queue(&msg->sender, &un, addrlen); + { + GNUNET_break_op (0); + return; + } + queue = lookup_queue (&msg->sender, &un, addrlen); if (NULL == queue) queue = - setup_queue(&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen); + setup_queue (&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen); else - reschedule_queue_timeout(queue); + reschedule_queue_timeout (queue); if (NULL == queue) - { - GNUNET_log( - GNUNET_ERROR_TYPE_ERROR, - _( - "Maximum number of UNIX connections exceeded, dropping incoming message\n")); - return; - } + { + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + _ ( + "Maximum number of UNIX connections exceeded, dropping incoming message\n")); + return; + } { uint16_t offset = 0; uint16_t tsize = msize - sizeof(struct UNIXMessage); - const char *msgbuf = (const char *)&msg[1]; + const char *msgbuf = (const char *) &msg[1]; while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize) + { + const struct GNUNET_MessageHeader *currhdr; + struct GNUNET_MessageHeader al_hdr; + uint16_t csize; + + currhdr = (const struct GNUNET_MessageHeader *) &msgbuf[offset]; + /* ensure aligned access */ + memcpy (&al_hdr, currhdr, sizeof(al_hdr)); + csize = ntohs (al_hdr.size); + if ((csize < sizeof(struct GNUNET_MessageHeader)) || + (csize > tsize - offset)) { - const struct GNUNET_MessageHeader *currhdr; - struct GNUNET_MessageHeader al_hdr; - uint16_t csize; - - currhdr = (const struct GNUNET_MessageHeader *)&msgbuf[offset]; - /* ensure aligned access */ - memcpy(&al_hdr, currhdr, sizeof(al_hdr)); - csize = ntohs(al_hdr.size); - if ((csize < sizeof(struct GNUNET_MessageHeader)) || - (csize > tsize - offset)) - { - GNUNET_break_op(0); - break; - } - ret = GNUNET_TRANSPORT_communicator_receive(ch, - &msg->sender, - currhdr, - GNUNET_TIME_UNIT_FOREVER_REL, - &receive_complete_cb, - NULL); - if (GNUNET_SYSERR == ret) - return; /* transport not up */ - if (GNUNET_NO == ret) - break; - delivering_messages++; - offset += csize; + GNUNET_break_op (0); + break; } + ret = GNUNET_TRANSPORT_communicator_receive (ch, + &msg->sender, + currhdr, + GNUNET_TIME_UNIT_FOREVER_REL, + &receive_complete_cb, + NULL); + if (GNUNET_SYSERR == ret) + return; /* transport not up */ + if (GNUNET_NO == ret) + break; + delivering_messages++; + offset += csize; + } } if (delivering_messages >= max_queue_length) - { - /* we should try to apply 'back pressure' */ - GNUNET_SCHEDULER_cancel(read_task); - read_task = NULL; - } + { + /* we should try to apply 'back pressure' */ + GNUNET_SCHEDULER_cancel (read_task); + read_task = NULL; + } } @@ -824,43 +827,43 @@ select_read_cb(void *cls) * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid */ static int -mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) +mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) { struct Queue *queue; const char *path; struct sockaddr_un *un; socklen_t un_len; - (void)cls; - if (0 != strncmp(address, - COMMUNICATOR_ADDRESS_PREFIX "-", - strlen(COMMUNICATOR_ADDRESS_PREFIX "-"))) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")]; - un = unix_address_to_sockaddr(path, &un_len); - queue = lookup_queue(peer, un, un_len); + (void) cls; + if (0 != strncmp (address, + COMMUNICATOR_ADDRESS_PREFIX "-", + strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; + un = unix_address_to_sockaddr (path, &un_len); + queue = lookup_queue (peer, un, un_len); if (NULL != queue) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Address `%s' for %s ignored, queue exists\n", - path, - GNUNET_i2s(peer)); - GNUNET_free(un); - return GNUNET_OK; - } - queue = setup_queue(peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len); - GNUNET_free(un); + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Address `%s' for %s ignored, queue exists\n", + path, + GNUNET_i2s (peer)); + GNUNET_free (un); + return GNUNET_OK; + } + queue = setup_queue (peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len); + GNUNET_free (un); if (NULL == queue) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Failed to setup queue to %s at `%s'\n", - GNUNET_i2s(peer), - path); - return GNUNET_NO; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to setup queue to %s at `%s'\n", + GNUNET_i2s (peer), + path); + return GNUNET_NO; + } return GNUNET_OK; } @@ -874,15 +877,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) * @return #GNUNET_OK to continue to iterate */ static int -get_queue_delete_it(void *cls, - const struct GNUNET_PeerIdentity *target, - void *value) +get_queue_delete_it (void *cls, + const struct GNUNET_PeerIdentity *target, + void *value) { struct Queue *queue = value; - (void)cls; - (void)target; - queue_destroy(queue); + (void) cls; + (void) target; + queue_destroy (queue); return GNUNET_OK; } @@ -893,40 +896,40 @@ get_queue_delete_it(void *cls, * @param cls NULL (always) */ static void -do_shutdown(void *cls) +do_shutdown (void *cls) { if (NULL != read_task) - { - GNUNET_SCHEDULER_cancel(read_task); - read_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (read_task); + read_task = NULL; + } if (NULL != write_task) - { - GNUNET_SCHEDULER_cancel(write_task); - write_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (write_task); + write_task = NULL; + } if (NULL != unix_sock) - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(unix_sock)); - unix_sock = NULL; - } - GNUNET_CONTAINER_multipeermap_iterate(queue_map, &get_queue_delete_it, NULL); - GNUNET_CONTAINER_multipeermap_destroy(queue_map); + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (unix_sock)); + unix_sock = NULL; + } + GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); + GNUNET_CONTAINER_multipeermap_destroy (queue_map); if (NULL != ai) - { - GNUNET_TRANSPORT_communicator_address_remove(ai); - ai = NULL; - } + { + GNUNET_TRANSPORT_communicator_address_remove (ai); + ai = NULL; + } if (NULL != ch) - { - GNUNET_TRANSPORT_communicator_disconnect(ch); - ch = NULL; - } + { + GNUNET_TRANSPORT_communicator_disconnect (ch); + ch = NULL; + } if (NULL != stats) - { - GNUNET_STATISTICS_destroy(stats, GNUNET_NO); - stats = NULL; - } + { + GNUNET_STATISTICS_destroy (stats, GNUNET_NO); + stats = NULL; + } } @@ -942,14 +945,14 @@ do_shutdown(void *cls) * @param msg payload */ static void -enc_notify_cb(void *cls, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *msg) +enc_notify_cb (void *cls, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *msg) { - (void)cls; - (void)sender; - (void)msg; - GNUNET_break_op(0); + (void) cls; + (void) sender; + (void) msg; + GNUNET_break_op (0); } @@ -962,110 +965,110 @@ enc_notify_cb(void *cls, * @param cfg configuration */ static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { char *unix_socket_path; struct sockaddr_un *un; socklen_t un_len; char *my_addr; - (void)cls; + (void) cls; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename(cfg, - COMMUNICATOR_CONFIG_SECTION, - "UNIXPATH", - &unix_socket_path)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - COMMUNICATOR_CONFIG_SECTION, - "UNIXPATH"); - return; - } + GNUNET_CONFIGURATION_get_value_filename (cfg, + COMMUNICATOR_CONFIG_SECTION, + "UNIXPATH", + &unix_socket_path)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + COMMUNICATOR_CONFIG_SECTION, + "UNIXPATH"); + return; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number(cfg, - COMMUNICATOR_CONFIG_SECTION, - "MAX_QUEUE_LENGTH", - &max_queue_length)) + GNUNET_CONFIGURATION_get_value_number (cfg, + COMMUNICATOR_CONFIG_SECTION, + "MAX_QUEUE_LENGTH", + &max_queue_length)) max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; - un = unix_address_to_sockaddr(unix_socket_path, &un_len); + un = unix_address_to_sockaddr (unix_socket_path, &un_len); if (NULL == un) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to setup UNIX domain socket address with path `%s'\n", - unix_socket_path); - GNUNET_free(unix_socket_path); - return; - } - unix_sock = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to setup UNIX domain socket address with path `%s'\n", + unix_socket_path); + GNUNET_free (unix_socket_path); + return; + } + unix_sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); if (NULL == unix_sock) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); - GNUNET_free(un); - GNUNET_free(unix_socket_path); - return; - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); + GNUNET_free (un); + GNUNET_free (unix_socket_path); + return; + } if (('\0' != un->sun_path[0]) && - (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Cannot create path to `%s'\n"), - un->sun_path); - GNUNET_NETWORK_socket_close(unix_sock); - unix_sock = NULL; - GNUNET_free(un); - GNUNET_free(unix_socket_path); - return; - } - if (GNUNET_OK != GNUNET_NETWORK_socket_bind(unix_sock, - (const struct sockaddr *)un, - un_len)) - { - GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path); - GNUNET_NETWORK_socket_close(unix_sock); - unix_sock = NULL; - GNUNET_free(un); - GNUNET_free(unix_socket_path); - return; - } - GNUNET_free(un); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path); - stats = GNUNET_STATISTICS_create("C-UNIX", cfg); - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); - read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - unix_sock, - &select_read_cb, - NULL); - queue_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); - ch = GNUNET_TRANSPORT_communicator_connect(cfg, - COMMUNICATOR_CONFIG_SECTION, - COMMUNICATOR_ADDRESS_PREFIX, - GNUNET_TRANSPORT_CC_RELIABLE, - &mq_init, - NULL, - &enc_notify_cb, + (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Cannot create path to `%s'\n"), + un->sun_path); + GNUNET_NETWORK_socket_close (unix_sock); + unix_sock = NULL; + GNUNET_free (un); + GNUNET_free (unix_socket_path); + return; + } + if (GNUNET_OK != GNUNET_NETWORK_socket_bind (unix_sock, + (const struct sockaddr *) un, + un_len)) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path); + GNUNET_NETWORK_socket_close (unix_sock); + unix_sock = NULL; + GNUNET_free (un); + GNUNET_free (unix_socket_path); + return; + } + GNUNET_free (un); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path); + stats = GNUNET_STATISTICS_create ("C-UNIX", cfg); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + unix_sock, + &select_read_cb, NULL); + queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); + ch = GNUNET_TRANSPORT_communicator_connect (cfg, + COMMUNICATOR_CONFIG_SECTION, + COMMUNICATOR_ADDRESS_PREFIX, + GNUNET_TRANSPORT_CC_RELIABLE, + &mq_init, + NULL, + &enc_notify_cb, + NULL); if (NULL == ch) - { - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - GNUNET_free(unix_socket_path); - return; - } - GNUNET_asprintf(&my_addr, - "%s-%s", - COMMUNICATOR_ADDRESS_PREFIX, - unix_socket_path); - GNUNET_free(unix_socket_path); - ai = GNUNET_TRANSPORT_communicator_address_add(ch, - my_addr, - GNUNET_NT_LOOPBACK, - GNUNET_TIME_UNIT_FOREVER_REL); - GNUNET_free(my_addr); + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + GNUNET_free (unix_socket_path); + return; + } + GNUNET_asprintf (&my_addr, + "%s-%s", + COMMUNICATOR_ADDRESS_PREFIX, + unix_socket_path); + GNUNET_free (unix_socket_path); + ai = GNUNET_TRANSPORT_communicator_address_add (ch, + my_addr, + GNUNET_NT_LOOPBACK, + GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_free (my_addr); } @@ -1077,27 +1080,27 @@ run(void *cls, * @return 0 ok, 1 on error */ int -main(int argc, char *const *argv) +main (int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; int ret; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run(argc, - argv, - "gnunet-communicator-unix", - _("GNUnet UNIX domain socket communicator"), - options, - &run, - NULL)) + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-communicator-unix", + _ ("GNUnet UNIX domain socket communicator"), + options, + &run, + NULL)) ? 0 : 1; - GNUNET_free((void *)argv); + GNUNET_free ((void *) argv); return ret; } @@ -1108,11 +1111,11 @@ main(int argc, char *const *argv) /** * MINIMIZE heap size (way below 128k) since this process doesn't need much. */ -void __attribute__ ((constructor)) GNUNET_ARM_memory_init() +void __attribute__ ((constructor)) GNUNET_ARM_memory_init () { - mallopt(M_TRIM_THRESHOLD, 4 * 1024); - mallopt(M_TOP_PAD, 1 * 1024); - malloc_trim(0); + mallopt (M_TRIM_THRESHOLD, 4 * 1024); + mallopt (M_TOP_PAD, 1 * 1024); + malloc_trim (0); } #endif diff --git a/src/transport/gnunet-helper-transport-bluetooth.c b/src/transport/gnunet-helper-transport-bluetooth.c index 4696f48f8..c0e0d9673 100644 --- a/src/transport/gnunet-helper-transport-bluetooth.c +++ b/src/transport/gnunet-helper-transport-bluetooth.c @@ -69,7 +69,8 @@ * struct for storing the information of the hardware. There is only * one of these. */ -struct HardwareInfos { +struct HardwareInfos +{ /** * Name of the interface, not necessarily 0-terminated (!). */ @@ -94,7 +95,8 @@ struct HardwareInfos { /** * IO buffer used for buffering data in transit (to wireless or to stdout). */ -struct SendBuffer { +struct SendBuffer +{ /** * How many bytes of data are stored in 'buf' for transmission right now? * Data always starts at offset 0 and extends to 'size'. @@ -119,7 +121,8 @@ struct SendBuffer { * Devices buffer used to keep a list with all the discoverable devices in * order to send them HELLO messages one by one when it receive a broadcast message. */ -struct BroadcastMessages { +struct BroadcastMessages +{ /* List with the discoverable devices' addresses */ bdaddr_t devices[MAX_PORTS]; @@ -140,7 +143,10 @@ struct BroadcastMessages { /** * Address used to identify the broadcast messages. */ -static struct GNUNET_TRANSPORT_WLAN_MacAddress broadcast_address = { { 255, 255, 255, 255, 255, 255 } }; +static struct GNUNET_TRANSPORT_WLAN_MacAddress broadcast_address = { { 255, 255, + 255, 255, + 255, + 255 } }; /** * Buffer with the discoverable devices. @@ -190,7 +196,8 @@ typedef void (*MessageTokenizerCallback) (void *cls, /** * Handle to a message stream tokenizer. */ -struct MessageStreamTokenizer { +struct MessageStreamTokenizer +{ /** * Function to call on completed messages. */ @@ -231,23 +238,23 @@ struct MessageStreamTokenizer { * @return handle to tokenizer */ static struct MessageStreamTokenizer * -mst_create(MessageTokenizerCallback cb, - void *cb_cls) +mst_create (MessageTokenizerCallback cb, + void *cb_cls) { struct MessageStreamTokenizer *ret; - ret = malloc(sizeof(struct MessageStreamTokenizer)); + ret = malloc (sizeof(struct MessageStreamTokenizer)); if (NULL == ret) - { - fprintf(stderr, "Failed to allocate buffer for tokenizer\n"); - exit(1); - } - ret->hdr = malloc(MIN_BUFFER_SIZE); + { + fprintf (stderr, "Failed to allocate buffer for tokenizer\n"); + exit (1); + } + ret->hdr = malloc (MIN_BUFFER_SIZE); if (NULL == ret->hdr) - { - fprintf(stderr, "Failed to allocate buffer for alignment\n"); - exit(1); - } + { + fprintf (stderr, "Failed to allocate buffer for alignment\n"); + exit (1); + } ret->curr_buf = MIN_BUFFER_SIZE; ret->cb = cb; ret->cb_cls = cb_cls; @@ -268,8 +275,8 @@ mst_create(MessageTokenizerCallback cb, * GNUNET_SYSERR if the data stream is corrupt */ static int -mst_receive(struct MessageStreamTokenizer *mst, - const char *buf, size_t size) +mst_receive (struct MessageStreamTokenizer *mst, + const char *buf, size_t size) { const struct GNUNET_MessageHeader *hdr; size_t delta; @@ -280,161 +287,162 @@ mst_receive(struct MessageStreamTokenizer *mst, int ret; ret = GNUNET_OK; - ibuf = (char *)mst->hdr; + ibuf = (char *) mst->hdr; while (mst->pos > 0) - { + { do_align: - if (mst->pos < mst->off) - { - //fprintf (stderr, "We processed too many bytes!\n"); - return GNUNET_SYSERR; - } - if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) || - (0 != (mst->off % ALIGN_FACTOR))) - { - /* need to align or need more space */ - mst->pos -= mst->off; - memmove(ibuf, &ibuf[mst->off], mst->pos); - mst->off = 0; - } - if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) - { - delta = - GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) - - (mst->pos - mst->off), size); - GNUNET_memcpy(&ibuf[mst->pos], buf, delta); - mst->pos += delta; - buf += delta; - size -= delta; - } - if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) - { - //FIXME should I reset ?? - // mst->off = 0; - // mst->pos = 0; - return GNUNET_OK; - } - hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off]; - want = ntohs(hdr->size); - if (want < sizeof(struct GNUNET_MessageHeader)) - { - fprintf(stderr, - "Received invalid message from stdin\n"); - return GNUNET_SYSERR; - } - if ((mst->curr_buf - mst->off < want) && - (mst->off > 0)) - { - /* need more space */ - mst->pos -= mst->off; - memmove(ibuf, &ibuf[mst->off], mst->pos); - mst->off = 0; - } - if (want > mst->curr_buf) - { - if (mst->off != 0) - { - fprintf(stderr, "Error! We should proceeded 0 bytes\n"); - return GNUNET_SYSERR; - } - mst->hdr = realloc(mst->hdr, want); - if (NULL == mst->hdr) - { - fprintf(stderr, "Failed to allocate buffer for alignment\n"); - exit(1); - } - ibuf = (char *)mst->hdr; - mst->curr_buf = want; - } - hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off]; - if (mst->pos - mst->off < want) - { - delta = GNUNET_MIN(want - (mst->pos - mst->off), size); - if (mst->pos + delta > mst->curr_buf) - { - fprintf(stderr, "The size of the buffer will be exceeded!\n"); - return GNUNET_SYSERR; - } - GNUNET_memcpy(&ibuf[mst->pos], buf, delta); - mst->pos += delta; - buf += delta; - size -= delta; - } - if (mst->pos - mst->off < want) - { - //FIXME should I use this? - // mst->off = 0; - // mst->pos = 0; - return GNUNET_OK; - } - mst->cb(mst->cb_cls, hdr); - mst->off += want; - if (mst->off == mst->pos) - { - /* reset to beginning of buffer, it's free right now! */ - mst->off = 0; - mst->pos = 0; - } + if (mst->pos < mst->off) + { + // fprintf (stderr, "We processed too many bytes!\n"); + return GNUNET_SYSERR; } - if (0 != mst->pos) + if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) || + (0 != (mst->off % ALIGN_FACTOR))) + { + /* need to align or need more space */ + mst->pos -= mst->off; + memmove (ibuf, &ibuf[mst->off], mst->pos); + mst->off = 0; + } + if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) + { + delta = + GNUNET_MIN (sizeof(struct GNUNET_MessageHeader) + - (mst->pos - mst->off), size); + GNUNET_memcpy (&ibuf[mst->pos], buf, delta); + mst->pos += delta; + buf += delta; + size -= delta; + } + if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) { - fprintf(stderr, "There should some valid bytes in the buffer on this stage\n"); + // FIXME should I reset ?? + // mst->off = 0; + // mst->pos = 0; + return GNUNET_OK; + } + hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; + want = ntohs (hdr->size); + if (want < sizeof(struct GNUNET_MessageHeader)) + { + fprintf (stderr, + "Received invalid message from stdin\n"); return GNUNET_SYSERR; } + if ((mst->curr_buf - mst->off < want) && + (mst->off > 0)) + { + /* need more space */ + mst->pos -= mst->off; + memmove (ibuf, &ibuf[mst->off], mst->pos); + mst->off = 0; + } + if (want > mst->curr_buf) + { + if (mst->off != 0) + { + fprintf (stderr, "Error! We should proceeded 0 bytes\n"); + return GNUNET_SYSERR; + } + mst->hdr = realloc (mst->hdr, want); + if (NULL == mst->hdr) + { + fprintf (stderr, "Failed to allocate buffer for alignment\n"); + exit (1); + } + ibuf = (char *) mst->hdr; + mst->curr_buf = want; + } + hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; + if (mst->pos - mst->off < want) + { + delta = GNUNET_MIN (want - (mst->pos - mst->off), size); + if (mst->pos + delta > mst->curr_buf) + { + fprintf (stderr, "The size of the buffer will be exceeded!\n"); + return GNUNET_SYSERR; + } + GNUNET_memcpy (&ibuf[mst->pos], buf, delta); + mst->pos += delta; + buf += delta; + size -= delta; + } + if (mst->pos - mst->off < want) + { + // FIXME should I use this? + // mst->off = 0; + // mst->pos = 0; + return GNUNET_OK; + } + mst->cb (mst->cb_cls, hdr); + mst->off += want; + if (mst->off == mst->pos) + { + /* reset to beginning of buffer, it's free right now! */ + mst->off = 0; + mst->pos = 0; + } + } + if (0 != mst->pos) + { + fprintf (stderr, + "There should some valid bytes in the buffer on this stage\n"); + return GNUNET_SYSERR; + } while (size > 0) + { + if (size < sizeof(struct GNUNET_MessageHeader)) + break; + offset = (unsigned long) buf; + need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; + if (GNUNET_NO == need_align) { - if (size < sizeof(struct GNUNET_MessageHeader)) - break; - offset = (unsigned long)buf; - need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; - if (GNUNET_NO == need_align) - { - /* can try to do zero-copy and process directly from original buffer */ - hdr = (const struct GNUNET_MessageHeader *)buf; - want = ntohs(hdr->size); - if (want < sizeof(struct GNUNET_MessageHeader)) - { - fprintf(stderr, - "Received invalid message from stdin\n"); - //exit (1); - mst->off = 0; - return GNUNET_SYSERR; - } - if (size < want) - break; /* or not, buffer incomplete, so copy to private buffer... */ - mst->cb(mst->cb_cls, hdr); - buf += want; - size -= want; - } - else - { - /* need to copy to private buffer to align; - * yes, we go a bit more spagetti than usual here */ - goto do_align; - } + /* can try to do zero-copy and process directly from original buffer */ + hdr = (const struct GNUNET_MessageHeader *) buf; + want = ntohs (hdr->size); + if (want < sizeof(struct GNUNET_MessageHeader)) + { + fprintf (stderr, + "Received invalid message from stdin\n"); + // exit (1); + mst->off = 0; + return GNUNET_SYSERR; + } + if (size < want) + break; /* or not, buffer incomplete, so copy to private buffer... */ + mst->cb (mst->cb_cls, hdr); + buf += want; + size -= want; + } + else + { + /* need to copy to private buffer to align; + * yes, we go a bit more spagetti than usual here */ + goto do_align; } + } if (size > 0) + { + if (size + mst->pos > mst->curr_buf) { - if (size + mst->pos > mst->curr_buf) - { - mst->hdr = realloc(mst->hdr, size + mst->pos); - if (NULL == mst->hdr) - { - fprintf(stderr, "Failed to allocate buffer for alignment\n"); - exit(1); - } - ibuf = (char *)mst->hdr; - mst->curr_buf = size + mst->pos; - } - if (mst->pos + size > mst->curr_buf) - { - fprintf(stderr, - "Assertion failed\n"); - exit(1); - } - GNUNET_memcpy(&ibuf[mst->pos], buf, size); - mst->pos += size; + mst->hdr = realloc (mst->hdr, size + mst->pos); + if (NULL == mst->hdr) + { + fprintf (stderr, "Failed to allocate buffer for alignment\n"); + exit (1); + } + ibuf = (char *) mst->hdr; + mst->curr_buf = size + mst->pos; + } + if (mst->pos + size > mst->curr_buf) + { + fprintf (stderr, + "Assertion failed\n"); + exit (1); } + GNUNET_memcpy (&ibuf[mst->pos], buf, size); + mst->pos += size; + } return ret; } @@ -444,10 +452,10 @@ do_align: * @param mst tokenizer to destroy */ static void -mst_destroy(struct MessageStreamTokenizer *mst) +mst_destroy (struct MessageStreamTokenizer *mst) { - free(mst->hdr); - free(mst); + free (mst->hdr); + free (mst); } /** @@ -458,7 +466,7 @@ mst_destroy(struct MessageStreamTokenizer *mst) * @return crc sum */ static unsigned long -calc_crc_osdep(const unsigned char *buf, size_t len) +calc_crc_osdep (const unsigned char *buf, size_t len) { static const unsigned long int crc_tbl_osdep[256] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, @@ -544,14 +552,14 @@ calc_crc_osdep(const unsigned char *buf, size_t len) * @return 0 on success (checksum matches), 1 on error */ static int -check_crc_buf_osdep(const unsigned char *buf, size_t len) +check_crc_buf_osdep (const unsigned char *buf, size_t len) { unsigned long crc; - crc = calc_crc_osdep(buf, len); + crc = calc_crc_osdep (buf, len); buf += len; - if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && - ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]) + if ((((crc) & 0xFF) == buf[0])&&(((crc >> 8) & 0xFF) == buf[1])&& + ( ((crc >> 16) & 0xFF) == buf[2]) &&( ((crc >> 24) & 0xFF) == buf[3]) ) return 0; return 1; } @@ -568,19 +576,20 @@ check_crc_buf_osdep(const unsigned char *buf, size_t len) * @return 0 on success */ static int -bind_socket(int socket, struct sockaddr_rc *addr) +bind_socket (int socket, struct sockaddr_rc *addr) { int port, status; /* Bind every possible port (from 0 to 30) and stop when binding doesn't fail */ - //FIXME : it should start from port 1, but on my computer it doesn't work :) + // FIXME : it should start from port 1, but on my computer it doesn't work :) for (port = 3; port <= 30; port++) - { - addr->rc_channel = port; - status = bind(socket, (struct sockaddr *)addr, sizeof(struct sockaddr_rc)); - if (status == 0) - return 0; - } + { + addr->rc_channel = port; + status = bind (socket, (struct sockaddr *) addr, sizeof(struct + sockaddr_rc)); + if (status == 0) + return 0; + } return -1; } @@ -594,7 +603,7 @@ bind_socket(int socket, struct sockaddr_rc *addr) * @return 0 on success */ static int -register_service(struct HardwareInfos *dev, int rc_channel) +register_service (struct HardwareInfos *dev, int rc_channel) { /** * 1. initializations @@ -606,8 +615,10 @@ register_service(struct HardwareInfos *dev, int rc_channel) * 7. cleanup */ uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - dev->pl_mac.mac[5], dev->pl_mac.mac[4], dev->pl_mac.mac[3], - dev->pl_mac.mac[2], dev->pl_mac.mac[1], dev->pl_mac.mac[0] }; + dev->pl_mac.mac[5], dev->pl_mac.mac[4], + dev->pl_mac.mac[3], + dev->pl_mac.mac[2], dev->pl_mac.mac[1], + dev->pl_mac.mac[0] }; const char *service_dsc = "Bluetooth plugin services"; const char *service_prov = "GNUnet provider"; uuid_t root_uuid, rfcomm_uuid, svc_uuid; @@ -616,61 +627,63 @@ register_service(struct HardwareInfos *dev, int rc_channel) sdp_record_t *record = 0; sdp_data_t *channel = 0; - record = sdp_record_alloc(); + record = sdp_record_alloc (); /* Set the general service ID */ - sdp_uuid128_create(&svc_uuid, &svc_uuid_int); - svc_list = sdp_list_append(0, &svc_uuid); - sdp_set_service_classes(record, svc_list); - sdp_set_service_id(record, svc_uuid); + sdp_uuid128_create (&svc_uuid, &svc_uuid_int); + svc_list = sdp_list_append (0, &svc_uuid); + sdp_set_service_classes (record, svc_list); + sdp_set_service_id (record, svc_uuid); /* Make the service record publicly browsable */ - sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); - root_list = sdp_list_append(0, &root_uuid); - sdp_set_browse_groups(record, root_list); + sdp_uuid16_create (&root_uuid, PUBLIC_BROWSE_GROUP); + root_list = sdp_list_append (0, &root_uuid); + sdp_set_browse_groups (record, root_list); /* Register the RFCOMM channel */ - sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); - channel = sdp_data_alloc(SDP_UINT8, &rc_channel); - rfcomm_list = sdp_list_append(0, &rfcomm_uuid); - sdp_list_append(rfcomm_list, channel); - proto_list = sdp_list_append(0, rfcomm_list); + sdp_uuid16_create (&rfcomm_uuid, RFCOMM_UUID); + channel = sdp_data_alloc (SDP_UINT8, &rc_channel); + rfcomm_list = sdp_list_append (0, &rfcomm_uuid); + sdp_list_append (rfcomm_list, channel); + proto_list = sdp_list_append (0, rfcomm_list); /* Set protocol information */ - access_proto_list = sdp_list_append(0, proto_list); - sdp_set_access_protos(record, access_proto_list); + access_proto_list = sdp_list_append (0, proto_list); + sdp_set_access_protos (record, access_proto_list); /* Set the name, provider, and description */ - sdp_set_info_attr(record, dev->iface, service_prov, service_dsc); + sdp_set_info_attr (record, dev->iface, service_prov, service_dsc); /* Connect to the local SDP server */ - dev->session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); + dev->session = sdp_connect (BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); - if (!dev->session) - { - fprintf(stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n", - IFNAMSIZ, dev->iface, strerror(errno)); - //FIXME exit? - return 1; - } + if (! dev->session) + { + fprintf (stderr, + "Failed to connect to the SDP server on interface `%.*s': %s\n", + IFNAMSIZ, dev->iface, strerror (errno)); + // FIXME exit? + return 1; + } /* Register the service record */ - if (sdp_record_register(dev->session, record, 0) < 0) - { - fprintf(stderr, "Failed to register a service record on interface `%.*s': %s\n", - IFNAMSIZ, dev->iface, strerror(errno)); - //FIXME exit? - return 1; - } + if (sdp_record_register (dev->session, record, 0) < 0) + { + fprintf (stderr, + "Failed to register a service record on interface `%.*s': %s\n", + IFNAMSIZ, dev->iface, strerror (errno)); + // FIXME exit? + return 1; + } /* Cleanup */ - sdp_data_free(channel); - sdp_list_free(root_list, 0); - sdp_list_free(rfcomm_list, 0); - sdp_list_free(proto_list, 0); - sdp_list_free(access_proto_list, 0); - sdp_list_free(svc_list, 0); - sdp_record_free(record); + sdp_data_free (channel); + sdp_list_free (root_list, 0); + sdp_list_free (rfcomm_list, 0); + sdp_list_free (proto_list, 0); + sdp_list_free (access_proto_list, 0); + sdp_list_free (svc_list, 0); + sdp_record_free (record); return 0; } @@ -684,7 +697,7 @@ register_service(struct HardwareInfos *dev, int rc_channel) * @return channel */ static int -get_channel(struct HardwareInfos *dev, bdaddr_t dest) +get_channel (struct HardwareInfos *dev, bdaddr_t dest) { /** * 1. detect all nearby devices @@ -704,46 +717,48 @@ get_channel(struct HardwareInfos *dev, bdaddr_t dest) int channel = -1; /* Connect to the local SDP server */ - session = sdp_connect(BDADDR_ANY, &dest, 0); - if (!session) - { - fprintf(stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n", - IFNAMSIZ, dev->iface, strerror(errno)); - return -1; - } + session = sdp_connect (BDADDR_ANY, &dest, 0); + if (! session) + { + fprintf (stderr, + "Failed to connect to the SDP server on interface `%.*s': %s\n", + IFNAMSIZ, dev->iface, strerror (errno)); + return -1; + } - sdp_uuid128_create(&svc_uuid, &svc_uuid_int); - search_list = sdp_list_append(0, &svc_uuid); - attrid_list = sdp_list_append(0, &range); + sdp_uuid128_create (&svc_uuid, &svc_uuid_int); + search_list = sdp_list_append (0, &svc_uuid); + attrid_list = sdp_list_append (0, &range); - if (sdp_service_search_attr_req(session, search_list, - SDP_ATTR_REQ_RANGE, attrid_list, &response_list) == 0) + if (sdp_service_search_attr_req (session, search_list, + SDP_ATTR_REQ_RANGE, attrid_list, + &response_list) == 0) + { + for (it = response_list; it; it = it->next) { - for (it = response_list; it; it = it->next) - { - sdp_record_t *record = (sdp_record_t*)it->data; - sdp_list_t *proto_list = 0; - if (sdp_get_access_protos(record, &proto_list) == 0) - { - channel = sdp_get_proto_port(proto_list, RFCOMM_UUID); - sdp_list_free(proto_list, 0); - } - sdp_record_free(record); - } + sdp_record_t *record = (sdp_record_t*) it->data; + sdp_list_t *proto_list = 0; + if (sdp_get_access_protos (record, &proto_list) == 0) + { + channel = sdp_get_proto_port (proto_list, RFCOMM_UUID); + sdp_list_free (proto_list, 0); + } + sdp_record_free (record); } + } - sdp_list_free(search_list, 0); - sdp_list_free(attrid_list, 0); - sdp_list_free(response_list, 0); + sdp_list_free (search_list, 0); + sdp_list_free (attrid_list, 0); + sdp_list_free (response_list, 0); - sdp_close(session); + sdp_close (session); if (-1 == channel) - fprintf(stderr, - "Failed to find the listening channel for interface `%.*s': %s\n", - IFNAMSIZ, - dev->iface, - strerror(errno)); + fprintf (stderr, + "Failed to find the listening channel for interface `%.*s': %s\n", + IFNAMSIZ, + dev->iface, + strerror (errno)); return channel; } @@ -759,48 +774,50 @@ get_channel(struct HardwareInfos *dev, bdaddr_t dest) * @return number of bytes written to 'buf' */ static ssize_t -read_from_the_socket(void *sock, - unsigned char *buf, size_t buf_size, - struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) +read_from_the_socket (void *sock, + unsigned char *buf, size_t buf_size, + struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) { unsigned char tmpbuf[buf_size]; ssize_t count; - count = read(*((int *)sock), tmpbuf, buf_size); + count = read (*((int *) sock), tmpbuf, buf_size); if (0 > count) - { - if (EAGAIN == errno) - return 0; + { + if (EAGAIN == errno) + return 0; - fprintf(stderr, "Failed to read from the HCI socket: %s\n", strerror(errno)); + fprintf (stderr, "Failed to read from the HCI socket: %s\n", strerror ( + errno)); - return -1; - } + return -1; + } #ifdef LINUX /* Get the channel used */ int len; struct sockaddr_rc rc_addr = { 0 }; - memset(&rc_addr, 0, sizeof(rc_addr)); + memset (&rc_addr, 0, sizeof(rc_addr)); len = sizeof(rc_addr); - if (0 > getsockname(*((int *)sock), (struct sockaddr *)&rc_addr, (socklen_t *)&len)) - { - fprintf(stderr, "getsockname() call failed : %s\n", strerror(errno)); - return -1; - } + if (0 > getsockname (*((int *) sock), (struct sockaddr *) &rc_addr, + (socklen_t *) &len)) + { + fprintf (stderr, "getsockname() call failed : %s\n", strerror (errno)); + return -1; + } - memset(ri, 0, sizeof(*ri)); + memset (ri, 0, sizeof(*ri)); ri->ri_channel = rc_addr.rc_channel; #endif /* Detect CRC32 at the end */ - if (0 == check_crc_buf_osdep(tmpbuf, count - sizeof(uint32_t))) - { - count -= sizeof(uint32_t); - } + if (0 == check_crc_buf_osdep (tmpbuf, count - sizeof(uint32_t))) + { + count -= sizeof(uint32_t); + } - GNUNET_memcpy(buf, tmpbuf, count); + GNUNET_memcpy (buf, tmpbuf, count); return count; } @@ -813,14 +830,15 @@ read_from_the_socket(void *sock, * @return 0 on success, non-zero on error */ static int -open_device(struct HardwareInfos *dev) +open_device (struct HardwareInfos *dev) { int i, dev_id = -1, fd_hci; - struct { + struct + { struct hci_dev_list_req list; struct hci_dev_req dev[HCI_MAX_DEV]; - } request; //used for detecting the local devices - struct sockaddr_rc rc_addr = { 0 }; //used for binding + } request; // used for detecting the local devices + struct sockaddr_rc rc_addr = { 0 }; // used for binding /* Initialize the neighbour structure */ neighbours.dev_id = -1; @@ -828,147 +846,148 @@ open_device(struct HardwareInfos *dev) neighbours.fds[i] = -1; /* Open a HCI socket */ - fd_hci = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + fd_hci = socket (AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); if (fd_hci < 0) - { - fprintf(stderr, - "Failed to create HCI socket: %s\n", - strerror(errno)); - return -1; - } + { + fprintf (stderr, + "Failed to create HCI socket: %s\n", + strerror (errno)); + return -1; + } - memset(&request, 0, sizeof(request)); + memset (&request, 0, sizeof(request)); request.list.dev_num = HCI_MAX_DEV; - if (ioctl(fd_hci, HCIGETDEVLIST, (void *)&request) < 0) - { - fprintf(stderr, - "ioctl(HCIGETDEVLIST) on interface `%.*s' failed: %s\n", - IFNAMSIZ, - dev->iface, - strerror(errno)); - (void)close(fd_hci); - return 1; - } + if (ioctl (fd_hci, HCIGETDEVLIST, (void *) &request) < 0) + { + fprintf (stderr, + "ioctl(HCIGETDEVLIST) on interface `%.*s' failed: %s\n", + IFNAMSIZ, + dev->iface, + strerror (errno)); + (void) close (fd_hci); + return 1; + } /* Search for a device with dev->iface name */ for (i = 0; i < request.list.dev_num; i++) - { - struct hci_dev_info dev_info; + { + struct hci_dev_info dev_info; + + memset (&dev_info, 0, sizeof(struct hci_dev_info)); + dev_info.dev_id = request.dev[i].dev_id; + strncpy (dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE); - memset(&dev_info, 0, sizeof(struct hci_dev_info)); - dev_info.dev_id = request.dev[i].dev_id; - strncpy(dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE); + if (ioctl (fd_hci, HCIGETDEVINFO, (void *) &dev_info)) + { + fprintf (stderr, + "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n", + IFNAMSIZ, + dev->iface, + strerror (errno)); + (void) close (fd_hci); + return 1; + } - if (ioctl(fd_hci, HCIGETDEVINFO, (void *)&dev_info)) + if (strncmp (dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE) == 0) + { + dev_id = dev_info.dev_id; // the device was found + /** + * Copy the MAC address to the device structure + */ + GNUNET_memcpy (&dev->pl_mac, &dev_info.bdaddr, sizeof(bdaddr_t)); + + /* Check if the interface is up */ + if (hci_test_bit (HCI_UP, (void *) &dev_info.flags) == 0) + { + /* Bring the interface up */ + if (ioctl (fd_hci, HCIDEVUP, dev_info.dev_id)) { - fprintf(stderr, - "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n", - IFNAMSIZ, - dev->iface, - strerror(errno)); - (void)close(fd_hci); + fprintf (stderr, + "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n", + IFNAMSIZ, + dev->iface, + strerror (errno)); + (void) close (fd_hci); return 1; } + } - if (strncmp(dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE) == 0) - { - dev_id = dev_info.dev_id; //the device was found - /** - * Copy the MAC address to the device structure - */ - GNUNET_memcpy(&dev->pl_mac, &dev_info.bdaddr, sizeof(bdaddr_t)); - - /* Check if the interface is up */ - if (hci_test_bit(HCI_UP, (void *)&dev_info.flags) == 0) - { - /* Bring the interface up */ - if (ioctl(fd_hci, HCIDEVUP, dev_info.dev_id)) - { - fprintf(stderr, - "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n", - IFNAMSIZ, - dev->iface, - strerror(errno)); - (void)close(fd_hci); - return 1; - } - } - - /* Check if the device is discoverable */ - if (hci_test_bit(HCI_PSCAN, (void *)&dev_info.flags) == 0 || - hci_test_bit(HCI_ISCAN, (void *)&dev_info.flags) == 0) - { - /* Set interface Page Scan and Inqury Scan ON */ - struct hci_dev_req dev_req; + /* Check if the device is discoverable */ + if ((hci_test_bit (HCI_PSCAN, (void *) &dev_info.flags) == 0) || + (hci_test_bit (HCI_ISCAN, (void *) &dev_info.flags) == 0) ) + { + /* Set interface Page Scan and Inqury Scan ON */ + struct hci_dev_req dev_req; - memset(&dev_req, 0, sizeof(dev_req)); - dev_req.dev_id = dev_info.dev_id; - dev_req.dev_opt = SCAN_PAGE | SCAN_INQUIRY; + memset (&dev_req, 0, sizeof(dev_req)); + dev_req.dev_id = dev_info.dev_id; + dev_req.dev_opt = SCAN_PAGE | SCAN_INQUIRY; - if (ioctl(fd_hci, HCISETSCAN, (unsigned long)&dev_req)) - { - fprintf(stderr, - "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n", - IFNAMSIZ, - dev->iface, - strerror(errno)); - (void)close(fd_hci); - return 1; - } - } - break; + if (ioctl (fd_hci, HCISETSCAN, (unsigned long) &dev_req)) + { + fprintf (stderr, + "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n", + IFNAMSIZ, + dev->iface, + strerror (errno)); + (void) close (fd_hci); + return 1; } + } + break; } + } /* Check if the interface was not found */ if (-1 == dev_id) - { - fprintf(stderr, - "The interface %s was not found\n", - dev->iface); - (void)close(fd_hci); - return 1; - } + { + fprintf (stderr, + "The interface %s was not found\n", + dev->iface); + (void) close (fd_hci); + return 1; + } /* Close the hci socket */ - (void)close(fd_hci); + (void) close (fd_hci); /* Bind the rfcomm socket to the interface */ - memset(&rc_addr, 0, sizeof(rc_addr)); + memset (&rc_addr, 0, sizeof(rc_addr)); rc_addr.rc_family = AF_BLUETOOTH; rc_addr.rc_bdaddr = *BDADDR_ANY; - if (bind_socket(dev->fd_rfcomm, &rc_addr) != 0) - { - fprintf(stderr, - "Failed to bind interface `%.*s': %s\n", - IFNAMSIZ, - dev->iface, - strerror(errno)); - return 1; - } + if (bind_socket (dev->fd_rfcomm, &rc_addr) != 0) + { + fprintf (stderr, + "Failed to bind interface `%.*s': %s\n", + IFNAMSIZ, + dev->iface, + strerror (errno)); + return 1; + } /* Register a SDP service */ - if (register_service(dev, rc_addr.rc_channel) != 0) - { - fprintf(stderr, - "Failed to register a service on interface `%.*s': %s\n", - IFNAMSIZ, - dev->iface, strerror(errno)); - return 1; - } + if (register_service (dev, rc_addr.rc_channel) != 0) + { + fprintf (stderr, + "Failed to register a service on interface `%.*s': %s\n", + IFNAMSIZ, + dev->iface, strerror (errno)); + return 1; + } /* Switch socket in listening mode */ - if (listen(dev->fd_rfcomm, 5) == -1) //FIXME: probably we need a bigger number - { - fprintf(stderr, "Failed to listen on socket for interface `%.*s': %s\n", IFNAMSIZ, - dev->iface, strerror(errno)); - return 1; - } + if (listen (dev->fd_rfcomm, 5) == -1) // FIXME: probably we need a bigger number + { + fprintf (stderr, "Failed to listen on socket for interface `%.*s': %s\n", + IFNAMSIZ, + dev->iface, strerror (errno)); + return 1; + } return 0; } @@ -983,10 +1002,10 @@ open_device(struct HardwareInfos *dev) **** copy from gnunet-helper-transport-wlan.c **** */ static void -mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, - const struct HardwareInfos *dev) +mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, + const struct HardwareInfos *dev) { - taIeeeHeader->frame_control = htons(IEEE80211_FC0_TYPE_DATA); + taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA); taIeeeHeader->addr3 = mac_bssid_gnunet; taIeeeHeader->addr2 = dev->pl_mac; } @@ -1001,22 +1020,22 @@ mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, **** similar with the one from gnunet-helper-transport-wlan.c **** */ static int -test_bluetooth_interface(const char *iface) +test_bluetooth_interface (const char *iface) { char strbuf[512]; struct stat sbuf; int ret; - ret = snprintf(strbuf, sizeof(strbuf), - "/sys/class/bluetooth/%s/subsystem", - iface); - if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat(strbuf, &sbuf))) - { - fprintf(stderr, - "Did not find 802.15.1 interface `%s'. Exiting.\n", - iface); - exit(1); - } + ret = snprintf (strbuf, sizeof(strbuf), + "/sys/class/bluetooth/%s/subsystem", + iface); + if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat (strbuf, &sbuf))) + { + fprintf (stderr, + "Did not find 802.15.1 interface `%s'. Exiting.\n", + iface); + exit (1); + } return 0; } #endif @@ -1031,19 +1050,19 @@ test_bluetooth_interface(const char *iface) **** same as the one from gnunet-helper-transport-wlan.c **** */ static int -mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, - const struct HardwareInfos *dev) +mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, + const struct HardwareInfos *dev) { static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros; - if ((0 == memcmp(&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) || - (0 == memcmp(&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE))) + if ((0 == memcmp (&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) || + (0 == memcmp (&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE))) return 0; /* some drivers set no Macs, then assume it is all for us! */ - if (0 != memcmp(&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE)) + if (0 != memcmp (&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE)) return 1; /* not a GNUnet ad-hoc package */ - if ((0 == memcmp(&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) || - (0 == memcmp(&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE))) + if ((0 == memcmp (&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) || + (0 == memcmp (&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE))) return 0; /* for us, or broadcast */ return 1; /* not for us */ } @@ -1059,37 +1078,37 @@ mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, **** same as the one from gnunet-helper-transport-wlan.c **** */ static void -stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr) +stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) { struct HardwareInfos *dev = cls; const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header; struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *blueheader; size_t sendsize; - sendsize = ntohs(hdr->size); + sendsize = ntohs (hdr->size); if ((sendsize < sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) || - (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type))) - { - fprintf(stderr, "Received malformed message\n"); - exit(1); - } - sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); + (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type))) + { + fprintf (stderr, "Received malformed message\n"); + exit (1); + } + sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); if (MAXLINE < sendsize) - { - fprintf(stderr, "Packet too big for buffer\n"); - exit(1); - } - header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr; - GNUNET_memcpy(&write_pout.buf, &header->frame, sendsize); - blueheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)&write_pout.buf; + { + fprintf (stderr, "Packet too big for buffer\n"); + exit (1); + } + header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; + GNUNET_memcpy (&write_pout.buf, &header->frame, sendsize); + blueheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &write_pout.buf; /* payload contains MAC address, but we don't trust it, so we'll * overwrite it with OUR MAC address to prevent mischief */ - mac_set(blueheader, dev); - GNUNET_memcpy(&blueheader->addr1, &header->frame.addr1, - sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)); + mac_set (blueheader, dev); + GNUNET_memcpy (&blueheader->addr1, &header->frame.addr1, + sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)); write_pout.size = sendsize; } @@ -1102,105 +1121,120 @@ stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr) * @return 0 on success */ static int -send_broadcast(struct HardwareInfos *dev, int *sendsocket) +send_broadcast (struct HardwareInfos *dev, int *sendsocket) { int new_device = 0; int loops = 0; search_for_devices: - if ((neighbours.size == neighbours.pos && new_device == 1) || neighbours.size == 0) + if (((neighbours.size == neighbours.pos)&&(new_device == 1)) || + (neighbours.size == 0) ) + { +inquiry_devices: // skip the conditions and force a inquiry for new devices { -inquiry_devices: //skip the conditions and force a inquiry for new devices + /** + * It means that I sent HELLO messages to all the devices from the list and I should search + * for new ones or that this is the first time when I do a search. + */ + inquiry_info *devices = NULL; + int i, responses, max_responses = MAX_PORTS; + + /* sanity checks */ + if (neighbours.size >= MAX_PORTS) { - /** - * It means that I sent HELLO messages to all the devices from the list and I should search - * for new ones or that this is the first time when I do a search. - */ - inquiry_info *devices = NULL; - int i, responses, max_responses = MAX_PORTS; - - /* sanity checks */ - if (neighbours.size >= MAX_PORTS) - { - fprintf(stderr, "%.*s reached the top limit for the discovarable devices\n", IFNAMSIZ, dev->iface); - return 2; - } - - /* Get the device id */ - if (neighbours.dev_id == -1) - { - char addr[19] = { 0 }; //the device MAC address - - ba2str((bdaddr_t *)&dev->pl_mac, addr); - neighbours.dev_id = hci_devid(addr); - if (neighbours.dev_id < 0) - { - fprintf(stderr, "Failed to get the device id for interface %.*s : %s\n", IFNAMSIZ, - dev->iface, strerror(errno)); - return 1; - } - } + fprintf (stderr, + "%.*s reached the top limit for the discovarable devices\n", + IFNAMSIZ, + dev->iface); + return 2; + } - devices = malloc(max_responses * sizeof(inquiry_info)); - if (devices == NULL) - { - fprintf(stderr, "Failed to allocate memory for inquiry info list on interface %.*s\n", IFNAMSIZ, - dev->iface); - return 1; - } + /* Get the device id */ + if (neighbours.dev_id == -1) + { + char addr[19] = { 0 }; // the device MAC address - responses = hci_inquiry(neighbours.dev_id, 8, max_responses, NULL, &devices, IREQ_CACHE_FLUSH); - if (responses < 0) - { - fprintf(stderr, "Failed to inquiry on interface %.*s\n", IFNAMSIZ, dev->iface); - return 1; - } + ba2str ((bdaddr_t *) &dev->pl_mac, addr); + neighbours.dev_id = hci_devid (addr); + if (neighbours.dev_id < 0) + { + fprintf (stderr, + "Failed to get the device id for interface %.*s : %s\n", + IFNAMSIZ, + dev->iface, strerror (errno)); + return 1; + } + } - fprintf(stderr, "LOG : Found %d devices\n", responses); //FIXME delete it after debugging stage + devices = malloc (max_responses * sizeof(inquiry_info)); + if (devices == NULL) + { + fprintf (stderr, + "Failed to allocate memory for inquiry info list on interface %.*s\n", + IFNAMSIZ, + dev->iface); + return 1; + } - if (responses == 0) - { - fprintf(stderr, "LOG : No devices discoverable\n"); - return 1; - } + responses = hci_inquiry (neighbours.dev_id, 8, max_responses, NULL, + &devices, IREQ_CACHE_FLUSH); + if (responses < 0) + { + fprintf (stderr, "Failed to inquiry on interface %.*s\n", IFNAMSIZ, + dev->iface); + return 1; + } - for (i = 0; i < responses; i++) - { - int j; - int found = 0; + fprintf (stderr, "LOG : Found %d devices\n", responses); // FIXME delete it after debugging stage - /* sanity check */ - if (i >= MAX_PORTS) - { - fprintf(stderr, "%.*s reached the top limit for the discoverable devices (after inquiry)\n", IFNAMSIZ, - dev->iface); - return 2; - } + if (responses == 0) + { + fprintf (stderr, "LOG : No devices discoverable\n"); + return 1; + } - /* Search if the address already exists on the list */ - for (j = 0; j < neighbours.size; j++) - { - if (memcmp(&(devices + i)->bdaddr, &(neighbours.devices[j]), sizeof(bdaddr_t)) == 0) - { - found = 1; - fprintf(stderr, "LOG : the device already exists on the list\n"); //FIXME debugging message - break; - } - } + for (i = 0; i < responses; i++) + { + int j; + int found = 0; - if (found == 0) - { - char addr[19] = { 0 }; + /* sanity check */ + if (i >= MAX_PORTS) + { + fprintf (stderr, + "%.*s reached the top limit for the discoverable devices (after inquiry)\n", + IFNAMSIZ, + dev->iface); + return 2; + } - ba2str(&(devices + i)->bdaddr, addr); - fprintf(stderr, "LOG : %s was added to the list\n", addr); //FIXME debugging message - GNUNET_memcpy(&(neighbours.devices[neighbours.size++]), &(devices + i)->bdaddr, sizeof(bdaddr_t)); - } + /* Search if the address already exists on the list */ + for (j = 0; j < neighbours.size; j++) + { + if (memcmp (&(devices + i)->bdaddr, &(neighbours.devices[j]), + sizeof(bdaddr_t)) == 0) + { + found = 1; + fprintf (stderr, "LOG : the device already exists on the list\n"); // FIXME debugging message + break; } + } + + if (found == 0) + { + char addr[19] = { 0 }; - free(devices); + ba2str (&(devices + i)->bdaddr, addr); + fprintf (stderr, "LOG : %s was added to the list\n", addr); // FIXME debugging message + GNUNET_memcpy (&(neighbours.devices[neighbours.size++]), &(devices + + i)-> + bdaddr, sizeof(bdaddr_t)); + } } + + free (devices); } + } int connection_successful = 0; struct sockaddr_rc addr_rc = { 0 }; @@ -1209,115 +1243,120 @@ inquiry_devices: //skip the conditions and force a inquiry for new devices /* Try to connect to a new device from the list */ while (neighbours.pos < neighbours.size) + { + /* Check if we are already connected to this device */ + if (neighbours.fds[neighbours.pos] == -1) { - /* Check if we are already connected to this device */ - if (neighbours.fds[neighbours.pos] == -1) - { - memset(&addr_rc.rc_bdaddr, 0, sizeof(addr_rc.rc_bdaddr)); - GNUNET_memcpy(&addr_rc.rc_bdaddr, &(neighbours.devices[neighbours.pos]), sizeof(addr_rc.rc_bdaddr)); + memset (&addr_rc.rc_bdaddr, 0, sizeof(addr_rc.rc_bdaddr)); + GNUNET_memcpy (&addr_rc.rc_bdaddr, &(neighbours.devices[neighbours.pos]), + sizeof(addr_rc.rc_bdaddr)); - addr_rc.rc_channel = get_channel(dev, addr_rc.rc_bdaddr); + addr_rc.rc_channel = get_channel (dev, addr_rc.rc_bdaddr); - *sendsocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); - if ((-1 < *sendsocket) && - (0 == connect(*sendsocket, - (struct sockaddr *)&addr_rc, - sizeof(addr_rc)))) - { - neighbours.fds[neighbours.pos++] = *sendsocket; - connection_successful = 1; - char addr[19] = { 0 }; - ba2str(&(neighbours.devices[neighbours.pos - 1]), addr); - fprintf(stderr, "LOG : Connected to %s\n", addr); - break; - } - else - { - char addr[19] = { 0 }; - errno_copy = errno; //Save a copy for later + *sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + if ((-1 < *sendsocket) && + (0 == connect (*sendsocket, + (struct sockaddr *) &addr_rc, + sizeof(addr_rc)))) + { + neighbours.fds[neighbours.pos++] = *sendsocket; + connection_successful = 1; + char addr[19] = { 0 }; + ba2str (&(neighbours.devices[neighbours.pos - 1]), addr); + fprintf (stderr, "LOG : Connected to %s\n", addr); + break; + } + else + { + char addr[19] = { 0 }; + errno_copy = errno; // Save a copy for later - if (-1 != *sendsocket) - { - (void)close(*sendsocket); - *sendsocket = -1; - } - ba2str(&(neighbours.devices[neighbours.pos]), addr); - fprintf(stderr, - "LOG : Couldn't connect on device %s, error : %s\n", - addr, - strerror(errno)); - if (errno != ECONNREFUSED) //FIXME be sure that this works - { - fprintf(stderr, "LOG : Removes %d device from the list\n", neighbours.pos); - /* Remove the device from the list */ - GNUNET_memcpy(&neighbours.devices[neighbours.pos], &neighbours.devices[neighbours.size - 1], sizeof(bdaddr_t)); - memset(&neighbours.devices[neighbours.size - 1], 0, sizeof(bdaddr_t)); - neighbours.fds[neighbours.pos] = neighbours.fds[neighbours.size - 1]; - neighbours.fds[neighbours.size - 1] = -1; - neighbours.size -= 1; - } + if (-1 != *sendsocket) + { + (void) close (*sendsocket); + *sendsocket = -1; + } + ba2str (&(neighbours.devices[neighbours.pos]), addr); + fprintf (stderr, + "LOG : Couldn't connect on device %s, error : %s\n", + addr, + strerror (errno)); + if (errno != ECONNREFUSED) // FIXME be sure that this works + { + fprintf (stderr, "LOG : Removes %d device from the list\n", + neighbours.pos); + /* Remove the device from the list */ + GNUNET_memcpy (&neighbours.devices[neighbours.pos], + &neighbours.devices[neighbours.size - 1], + sizeof(bdaddr_t)); + memset (&neighbours.devices[neighbours.size - 1], 0, + sizeof(bdaddr_t)); + neighbours.fds[neighbours.pos] = neighbours.fds[neighbours.size - 1]; + neighbours.fds[neighbours.size - 1] = -1; + neighbours.size -= 1; + } - neighbours.pos += 1; + neighbours.pos += 1; - if (neighbours.pos >= neighbours.size) - neighbours.pos = 0; + if (neighbours.pos >= neighbours.size) + neighbours.pos = 0; - loops += 1; + loops += 1; - if (loops == MAX_LOOPS) //don't get stuck trying to connect to one device - return 1; - } - } - else - { - fprintf(stderr, "LOG : Search for a new device\n"); //FIXME debugging message - neighbours.pos += 1; - } + if (loops == MAX_LOOPS) // don't get stuck trying to connect to one device + return 1; + } + } + else + { + fprintf (stderr, "LOG : Search for a new device\n"); // FIXME debugging message + neighbours.pos += 1; } + } /* Cycle on the list */ if (neighbours.pos == neighbours.size) - { - neighbours.pos = 0; - searching_devices_count += 1; + { + neighbours.pos = 0; + searching_devices_count += 1; - if (searching_devices_count == MAX_LOOPS) - { - fprintf(stderr, "LOG : Force to inquiry for new devices\n"); - searching_devices_count = 0; - goto inquiry_devices; - } + if (searching_devices_count == MAX_LOOPS) + { + fprintf (stderr, "LOG : Force to inquiry for new devices\n"); + searching_devices_count = 0; + goto inquiry_devices; } + } /* If a new device wasn't found, search an old one */ if (connection_successful == 0) + { + int loop_check = neighbours.pos; + while (neighbours.fds[neighbours.pos] == -1) { - int loop_check = neighbours.pos; - while (neighbours.fds[neighbours.pos] == -1) - { - if (neighbours.pos == neighbours.size) - neighbours.pos = 0; - - if (neighbours.pos == loop_check) - { - if (errno_copy == ECONNREFUSED) - { - fprintf(stderr, "LOG : No device found. Go back and search again\n"); //FIXME debugging message - new_device = 1; - loops += 1; - goto search_for_devices; - } - else - { - return 1; // Skip the broadcast message - } - } + if (neighbours.pos == neighbours.size) + neighbours.pos = 0; - neighbours.pos += 1; + if (neighbours.pos == loop_check) + { + if (errno_copy == ECONNREFUSED) + { + fprintf (stderr, "LOG : No device found. Go back and search again\n"); // FIXME debugging message + new_device = 1; + loops += 1; + goto search_for_devices; + } + else + { + return 1; // Skip the broadcast message } + } - *sendsocket = neighbours.fds[neighbours.pos++]; + neighbours.pos += 1; } + *sendsocket = neighbours.fds[neighbours.pos++]; + } + return 0; } #endif @@ -1334,7 +1373,7 @@ inquiry_devices: //skip the conditions and force a inquiry for new devices **** similar to gnunet-helper-transport-wlan.c **** */ int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { #ifdef LINUX struct HardwareInfos dev; @@ -1351,83 +1390,85 @@ main(int argc, char *argv[]) /* Assert privs so we can modify the firewall rules! */ { #ifdef HAVE_SETRESUID - uid_t uid = getuid(); + uid_t uid = getuid (); - if (0 != setresuid(uid, 0, 0)) - { - fprintf(stderr, - "Failed to setresuid to root: %s\n", - strerror(errno)); - return 254; - } + if (0 != setresuid (uid, 0, 0)) + { + fprintf (stderr, + "Failed to setresuid to root: %s\n", + strerror (errno)); + return 254; + } #else - if (0 != seteuid(0)) - { - fprintf(stderr, - "Failed to seteuid back to root: %s\n", strerror(errno)); - return 254; - } + if (0 != seteuid (0)) + { + fprintf (stderr, + "Failed to seteuid back to root: %s\n", strerror (errno)); + return 254; + } #endif } /* Make use of SGID capabilities on POSIX */ - memset(&dev, 0, sizeof(dev)); - dev.fd_rfcomm = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + memset (&dev, 0, sizeof(dev)); + dev.fd_rfcomm = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); raw_eno = errno; /* remember for later */ /* Now that we've dropped root rights, we can do error checking */ if (2 != argc) - { - fprintf(stderr, "You must specify the name of the interface as the first \ + { + fprintf (stderr, + "You must specify the name of the interface as the first \ and only argument to this program.\n"); - if (-1 != dev.fd_rfcomm) - (void)close(dev.fd_rfcomm); - return 1; - } + if (-1 != dev.fd_rfcomm) + (void) close (dev.fd_rfcomm); + return 1; + } if (-1 == dev.fd_rfcomm) - { - fprintf(stderr, "Failed to create a RFCOMM socket: %s\n", strerror(raw_eno)); - return 1; - } + { + fprintf (stderr, "Failed to create a RFCOMM socket: %s\n", strerror ( + raw_eno)); + return 1; + } if (dev.fd_rfcomm >= FD_SETSIZE) + { + fprintf (stderr, "File descriptor too large for select (%d > %d)\n", + dev.fd_rfcomm, FD_SETSIZE); + (void) close (dev.fd_rfcomm); + return 1; + } + if (0 != test_bluetooth_interface (argv[1])) + { + (void) close (dev.fd_rfcomm); + return 1; + } + strncpy (dev.iface, argv[1], IFNAMSIZ); + if (0 != open_device (&dev)) + { + (void) close (dev.fd_rfcomm); + return 1; + } + + /* Drop privs */ + { + uid_t uid = getuid (); + #ifdef HAVE_SETRESUID + if (0 != setresuid (uid, uid, uid)) { - fprintf(stderr, "File descriptor too large for select (%d > %d)\n", - dev.fd_rfcomm, FD_SETSIZE); - (void)close(dev.fd_rfcomm); - return 1; - } - if (0 != test_bluetooth_interface(argv[1])) - { - (void)close(dev.fd_rfcomm); + fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); + if (-1 != dev.fd_rfcomm) + (void) close (dev.fd_rfcomm); return 1; } - strncpy(dev.iface, argv[1], IFNAMSIZ); - if (0 != open_device(&dev)) + #else + if (0 != (setuid (uid) | seteuid (uid))) { - (void)close(dev.fd_rfcomm); + fprintf (stderr, "Failed to setuid: %s\n", strerror (errno)); + if (-1 != dev.fd_rfcomm) + (void) close (dev.fd_rfcomm); return 1; } - - /* Drop privs */ - { - uid_t uid = getuid(); - #ifdef HAVE_SETRESUID - if (0 != setresuid(uid, uid, uid)) - { - fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno)); - if (-1 != dev.fd_rfcomm) - (void)close(dev.fd_rfcomm); - return 1; - } - #else - if (0 != (setuid(uid) | seteuid(uid))) - { - fprintf(stderr, "Failed to setuid: %s\n", strerror(errno)); - if (-1 != dev.fd_rfcomm) - (void)close(dev.fd_rfcomm); - return 1; - } #endif } @@ -1435,15 +1476,16 @@ main(int argc, char *argv[]) { struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; - macmsg.hdr.size = htons(sizeof(macmsg)); - macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); - GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)); - GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg)); + macmsg.hdr.size = htons (sizeof(macmsg)); + macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); + GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof(struct + GNUNET_TRANSPORT_WLAN_MacAddress)); + GNUNET_memcpy (write_std.buf, &macmsg, sizeof(macmsg)); write_std.size = sizeof(macmsg); } - stdin_mst = mst_create(&stdin_send_hw, &dev); + stdin_mst = mst_create (&stdin_send_hw, &dev); stdin_open = 1; /** @@ -1451,348 +1493,381 @@ main(int argc, char *argv[]) * from get_wlan_header (plugin_transport_bluetooth.c) is correct. */ while (1) + { + maxfd = -1; + broadcast = 0; + sendsocket = -1; + + FD_ZERO (&rfds); + if ((0 == write_pout.size) && (1 == stdin_open)) + { + FD_SET (STDIN_FILENO, &rfds); + maxfd = MAX (maxfd, STDIN_FILENO); + } + if (0 == write_std.size) { - maxfd = -1; - broadcast = 0; - sendsocket = -1; + FD_SET (dev.fd_rfcomm, &rfds); + maxfd = MAX (maxfd, dev.fd_rfcomm); + } - FD_ZERO(&rfds); - if ((0 == write_pout.size) && (1 == stdin_open)) - { - FD_SET(STDIN_FILENO, &rfds); - maxfd = MAX(maxfd, STDIN_FILENO); - } - if (0 == write_std.size) + for (i = 0; i < crt_rfds; i++) // it can receive messages from multiple devices + { + FD_SET (rfds_list[i], &rfds); + maxfd = MAX (maxfd, rfds_list[i]); + } + FD_ZERO (&wfds); + if (0 < write_std.size) + { + FD_SET (STDOUT_FILENO, &wfds); + maxfd = MAX (maxfd, STDOUT_FILENO); + } + if (0 < write_pout.size) // it can send messages only to one device per loop + { + struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *frame; + /* Get the destination address */ + frame = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) write_pout.buf; + + if (memcmp (&frame->addr1, &dev.pl_mac, + sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0) + { + broadcast = 1; + memset (&write_pout, 0, sizeof(write_pout)); // clear the buffer + } + else if (memcmp (&frame->addr1, &broadcast_address, + sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0) + { + fprintf (stderr, "LOG : %s has a broadcast message (pos %d, size %d)\n", + dev.iface, neighbours.pos, neighbours.size); // FIXME: debugging message + + if (send_broadcast (&dev, &sendsocket) != 0) // if the searching wasn't successful don't get stuck on the select stage { - FD_SET(dev.fd_rfcomm, &rfds); - maxfd = MAX(maxfd, dev.fd_rfcomm); + broadcast = 1; + memset (&write_pout, 0, sizeof(write_pout)); // remove the message + fprintf (stderr, + "LOG : Skipping the broadcast message (pos %d, size %d)\n", + neighbours.pos, neighbours.size); } - - for (i = 0; i < crt_rfds; i++) // it can receive messages from multiple devices + else { - FD_SET(rfds_list[i], &rfds); - maxfd = MAX(maxfd, rfds_list[i]); + FD_SET (sendsocket, &wfds); + maxfd = MAX (maxfd, sendsocket); } - FD_ZERO(&wfds); - if (0 < write_std.size) + } + else + { + int found = 0; + int pos = 0; + /* Search if the address already exists on the list */ + for (i = 0; i < neighbours.size; i++) { - FD_SET(STDOUT_FILENO, &wfds); - maxfd = MAX(maxfd, STDOUT_FILENO); + if (memcmp (&frame->addr1, &(neighbours.devices[i]), + sizeof(bdaddr_t)) == 0) + { + pos = i; + if (neighbours.fds[i] != -1) + { + found = 1; // save the position where it was found + FD_SET (neighbours.fds[i], &wfds); + maxfd = MAX (maxfd, neighbours.fds[i]); + sendsocket = neighbours.fds[i]; + fprintf (stderr, "LOG: the address was found in the list\n"); + break; + } + } } - if (0 < write_pout.size) //it can send messages only to one device per loop + if (found == 0) { - struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *frame; - /* Get the destination address */ - frame = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)write_pout.buf; + int status; + struct sockaddr_rc addr = { 0 }; + + fprintf (stderr, + "LOG : %s has a new message for %.2X:%.2X:%.2X:%.2X:%.2X:%.2X which isn't on the broadcast list\n", + dev.iface, + frame->addr1.mac[5], frame->addr1.mac[4], + frame->addr1.mac[3], + frame->addr1.mac[2], frame->addr1.mac[1], + frame->addr1.mac[0]); // FIXME: debugging message + + sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + + if (sendsocket < 0) + { + fprintf (stderr, + "Failed to create a RFCOMM socket (sending stage): %s\n", + strerror (errno)); + return -1; + } + + GNUNET_memcpy (&addr.rc_bdaddr, &frame->addr1, sizeof(bdaddr_t)); + addr.rc_family = AF_BLUETOOTH; + addr.rc_channel = get_channel (&dev, addr.rc_bdaddr); - if (memcmp(&frame->addr1, &dev.pl_mac, - sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0) + int tries = 0; +connect_retry: + status = connect (sendsocket, (struct sockaddr *) &addr, + sizeof(addr)); + if ((0 != status) &&(errno != EAGAIN) ) + { + if ((errno == ECONNREFUSED) &&(tries < 2) ) + { + fprintf (stderr, "LOG : %.*s failed to connect. Trying again!\n", + IFNAMSIZ, dev.iface); + tries++; + goto connect_retry; + } + else if (errno == EBADF) { + fprintf (stderr, "LOG : %s failed to connect : %s. Skip it!\n", + dev.iface, strerror (errno)); + memset (&write_pout, 0, sizeof(write_pout)); broadcast = 1; - memset(&write_pout, 0, sizeof(write_pout)); //clear the buffer } - else if (memcmp(&frame->addr1, &broadcast_address, - sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0) + else { - fprintf(stderr, "LOG : %s has a broadcast message (pos %d, size %d)\n", dev.iface, neighbours.pos, neighbours.size); //FIXME: debugging message - - if (send_broadcast(&dev, &sendsocket) != 0) //if the searching wasn't successful don't get stuck on the select stage - { - broadcast = 1; - memset(&write_pout, 0, sizeof(write_pout)); //remove the message - fprintf(stderr, "LOG : Skipping the broadcast message (pos %d, size %d)\n", neighbours.pos, neighbours.size); - } - else - { - FD_SET(sendsocket, &wfds); - maxfd = MAX(maxfd, sendsocket); - } + fprintf (stderr, + "LOG : %s failed to connect : %s. Try again later!\n", + dev.iface, + strerror (errno)); + memset (&write_pout, 0, sizeof(write_pout)); + broadcast = 1; } + } else + { + FD_SET (sendsocket, &wfds); + maxfd = MAX (maxfd, sendsocket); + fprintf (stderr, "LOG : Connection successful\n"); + if (pos != 0) // save the socket { - int found = 0; - int pos = 0; - /* Search if the address already exists on the list */ - for (i = 0; i < neighbours.size; i++) - { - if (memcmp(&frame->addr1, &(neighbours.devices[i]), sizeof(bdaddr_t)) == 0) - { - pos = i; - if (neighbours.fds[i] != -1) - { - found = 1; //save the position where it was found - FD_SET(neighbours.fds[i], &wfds); - maxfd = MAX(maxfd, neighbours.fds[i]); - sendsocket = neighbours.fds[i]; - fprintf(stderr, "LOG: the address was found in the list\n"); - break; - } - } - } - if (found == 0) - { - int status; - struct sockaddr_rc addr = { 0 }; - - fprintf(stderr, "LOG : %s has a new message for %.2X:%.2X:%.2X:%.2X:%.2X:%.2X which isn't on the broadcast list\n", dev.iface, - frame->addr1.mac[5], frame->addr1.mac[4], frame->addr1.mac[3], - frame->addr1.mac[2], frame->addr1.mac[1], frame->addr1.mac[0]); //FIXME: debugging message - - sendsocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); - - if (sendsocket < 0) - { - fprintf(stderr, "Failed to create a RFCOMM socket (sending stage): %s\n", - strerror(errno)); - return -1; - } - - GNUNET_memcpy(&addr.rc_bdaddr, &frame->addr1, sizeof(bdaddr_t)); - addr.rc_family = AF_BLUETOOTH; - addr.rc_channel = get_channel(&dev, addr.rc_bdaddr); - - int tries = 0; -connect_retry: - status = connect(sendsocket, (struct sockaddr *)&addr, sizeof(addr)); - if (0 != status && errno != EAGAIN) - { - if (errno == ECONNREFUSED && tries < 2) - { - fprintf(stderr, "LOG : %.*s failed to connect. Trying again!\n", IFNAMSIZ, dev.iface); - tries++; - goto connect_retry; - } - else if (errno == EBADF) - { - fprintf(stderr, "LOG : %s failed to connect : %s. Skip it!\n", dev.iface, strerror(errno)); - memset(&write_pout, 0, sizeof(write_pout)); - broadcast = 1; - } - else - { - fprintf(stderr, "LOG : %s failed to connect : %s. Try again later!\n", dev.iface, strerror(errno)); - memset(&write_pout, 0, sizeof(write_pout)); - broadcast = 1; - } - } - else - { - FD_SET(sendsocket, &wfds); - maxfd = MAX(maxfd, sendsocket); - fprintf(stderr, "LOG : Connection successful\n"); - if (pos != 0) // save the socket - { - neighbours.fds[pos] = sendsocket; - } - else - { - /* Add the new device to the discovered devices list */ - if (neighbours.size < MAX_PORTS) - { - neighbours.fds[neighbours.size] = sendsocket; - GNUNET_memcpy(&(neighbours.devices[neighbours.size++]), &addr.rc_bdaddr, sizeof(bdaddr_t)); - } - else - { - fprintf(stderr, "The top limit for the discovarable devices' list was reached\n"); - } - } - } - } + neighbours.fds[pos] = sendsocket; + } + else + { + /* Add the new device to the discovered devices list */ + if (neighbours.size < MAX_PORTS) + { + neighbours.fds[neighbours.size] = sendsocket; + GNUNET_memcpy (&(neighbours.devices[neighbours.size++]), + &addr.rc_bdaddr, sizeof(bdaddr_t)); + } + else + { + fprintf (stderr, + "The top limit for the discovarable devices' list was reached\n"); + } } + } } + } + } - if (broadcast == 0) + if (broadcast == 0) + { + /* Select a fd which is ready for action :) */ + { + int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL); + if ((-1 == retval) && (EINTR == errno)) + continue; + if ((0 > retval) &&(errno != EBADF) ) // we handle BADF errors later { - /* Select a fd which is ready for action :) */ + fprintf (stderr, "select failed: %s\n", strerror (errno)); + break; + } + } + if (FD_ISSET (STDOUT_FILENO, &wfds)) + { + ssize_t ret = + write (STDOUT_FILENO, write_std.buf + write_std.pos, + write_std.size - write_std.pos); + if (0 > ret) + { + fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno)); + break; + } + write_std.pos += ret; + if (write_std.pos == write_std.size) + { + write_std.pos = 0; + write_std.size = 0; + } + fprintf (stderr, "LOG : %s sends a message to STDOUT\n", dev.iface); // FIXME: debugging message + } + if (-1 != sendsocket) + { + if (FD_ISSET (sendsocket, &wfds)) + { + ssize_t ret = write (sendsocket, + write_pout.buf + write_std.pos, + write_pout.size - write_pout.pos); + if (0 > ret) // FIXME should I first check the error type? { - int retval = select(maxfd + 1, &rfds, &wfds, NULL, NULL); - if ((-1 == retval) && (EINTR == errno)) - continue; - if (0 > retval && errno != EBADF) // we handle BADF errors later + fprintf (stderr, + "Failed to write to bluetooth device: %s. Closing the socket!\n", + strerror (errno)); + for (i = 0; i < neighbours.size; i++) + { + if (neighbours.fds[i] == sendsocket) { - fprintf(stderr, "select failed: %s\n", strerror(errno)); + (void) close (sendsocket); + neighbours.fds[i] = -1; break; } + } + /* Remove the message */ + memset (&write_pout.buf + write_std.pos, 0, (write_pout.size + - write_pout.pos)); + write_pout.pos = 0; + write_pout.size = 0; } - if (FD_ISSET(STDOUT_FILENO, &wfds)) + else + { + write_pout.pos += ret; + if ((write_pout.pos != write_pout.size) && (0 != ret)) { - ssize_t ret = - write(STDOUT_FILENO, write_std.buf + write_std.pos, - write_std.size - write_std.pos); - if (0 > ret) - { - fprintf(stderr, "Failed to write to STDOUT: %s\n", strerror(errno)); - break; - } - write_std.pos += ret; - if (write_std.pos == write_std.size) - { - write_std.pos = 0; - write_std.size = 0; - } - fprintf(stderr, "LOG : %s sends a message to STDOUT\n", dev.iface); //FIXME: debugging message + /* We should not get partial sends with packet-oriented devices... */ + fprintf (stderr, "Write error, partial send: %u/%u\n", + (unsigned int) write_pout.pos, + (unsigned int) write_pout.size); + break; } - if (-1 != sendsocket) + + if (write_pout.pos == write_pout.size) { - if (FD_ISSET(sendsocket, &wfds)) - { - ssize_t ret = write(sendsocket, - write_pout.buf + write_std.pos, - write_pout.size - write_pout.pos); - if (0 > ret) //FIXME should I first check the error type? - { - fprintf(stderr, "Failed to write to bluetooth device: %s. Closing the socket!\n", - strerror(errno)); - for (i = 0; i < neighbours.size; i++) - { - if (neighbours.fds[i] == sendsocket) - { - (void)close(sendsocket); - neighbours.fds[i] = -1; - break; - } - } - /* Remove the message */ - memset(&write_pout.buf + write_std.pos, 0, (write_pout.size - write_pout.pos)); - write_pout.pos = 0; - write_pout.size = 0; - } - else - { - write_pout.pos += ret; - if ((write_pout.pos != write_pout.size) && (0 != ret)) - { - /* We should not get partial sends with packet-oriented devices... */ - fprintf(stderr, "Write error, partial send: %u/%u\n", - (unsigned int)write_pout.pos, - (unsigned int)write_pout.size); - break; - } - - if (write_pout.pos == write_pout.size) - { - write_pout.pos = 0; - write_pout.size = 0; - } - fprintf(stderr, "LOG : %s sends a message to a DEVICE\n", dev.iface); //FIXME: debugging message - } - } + write_pout.pos = 0; + write_pout.size = 0; } - for (i = 0; i <= maxfd; i++) + fprintf (stderr, "LOG : %s sends a message to a DEVICE\n", + dev.iface); // FIXME: debugging message + } + } + } + for (i = 0; i <= maxfd; i++) + { + if (FD_ISSET (i, &rfds)) + { + if (i == STDIN_FILENO) + { + ssize_t ret = + read (i, readbuf, sizeof(readbuf)); + if (0 > ret) { - if (FD_ISSET(i, &rfds)) - { - if (i == STDIN_FILENO) - { - ssize_t ret = - read(i, readbuf, sizeof(readbuf)); - if (0 > ret) - { - fprintf(stderr, - "Read error from STDIN: %s\n", - strerror(errno)); - break; - } - if (0 == ret) - { - /* stop reading... */ - stdin_open = 0; - } - else - { - mst_receive(stdin_mst, readbuf, ret); - fprintf(stderr, "LOG : %s receives a message from STDIN\n", dev.iface); //FIXME: debugging message - } - } - else if (i == dev.fd_rfcomm) - { - int readsocket; - struct sockaddr_rc addr = { 0 }; - unsigned int opt = sizeof(addr); - - readsocket = accept(dev.fd_rfcomm, (struct sockaddr *)&addr, &opt); - fprintf(stderr, "LOG : %s accepts a message\n", dev.iface); //FIXME: debugging message - if (readsocket == -1) - { - fprintf(stderr, "Failed to accept a connection on interface: %.*s\n", IFNAMSIZ, - strerror(errno)); - break; - } - else - { - FD_SET(readsocket, &rfds); - maxfd = MAX(maxfd, readsocket); - - if (crt_rfds < MAX_PORTS) - rfds_list[crt_rfds++] = readsocket; - else - { - fprintf(stderr, "The limit for the read file descriptors list was \ + fprintf (stderr, + "Read error from STDIN: %s\n", + strerror (errno)); + break; + } + if (0 == ret) + { + /* stop reading... */ + stdin_open = 0; + } + else + { + mst_receive (stdin_mst, readbuf, ret); + fprintf (stderr, "LOG : %s receives a message from STDIN\n", + dev.iface); // FIXME: debugging message + } + } + else if (i == dev.fd_rfcomm) + { + int readsocket; + struct sockaddr_rc addr = { 0 }; + unsigned int opt = sizeof(addr); + + readsocket = accept (dev.fd_rfcomm, (struct sockaddr *) &addr, + &opt); + fprintf (stderr, "LOG : %s accepts a message\n", dev.iface); // FIXME: debugging message + if (readsocket == -1) + { + fprintf (stderr, + "Failed to accept a connection on interface: %.*s\n", + IFNAMSIZ, + strerror (errno)); + break; + } + else + { + FD_SET (readsocket, &rfds); + maxfd = MAX (maxfd, readsocket); + + if (crt_rfds < MAX_PORTS) + rfds_list[crt_rfds++] = readsocket; + else + { + fprintf (stderr, + "The limit for the read file descriptors list was \ reached\n"); - break; - } - } - } - else - { - struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm; - ssize_t ret; - fprintf(stderr, "LOG : %s reads something from the socket\n", dev.iface);//FIXME : debugging message - rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf; - ret = - read_from_the_socket((void *)&i, (unsigned char *)&rrm->frame, - sizeof(write_std.buf) - - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) - + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame), - rrm); - if (0 >= ret) - { - int j; - FD_CLR(i, &rfds); - close(i); - /* Remove the socket from the list */ - for (j = 0; j < crt_rfds; j++) - { - if (rfds_list[j] == i) - { - rfds_list[j] ^= rfds_list[crt_rfds - 1]; - rfds_list[crt_rfds - 1] ^= rfds_list[j]; - rfds_list[j] ^= rfds_list[crt_rfds - 1]; - crt_rfds -= 1; - break; - } - } - - fprintf(stderr, "Read error from raw socket: %s\n", strerror(errno)); - break; - } - if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev))) - { - write_std.size = ret - + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) - - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame); - rrm->header.size = htons(write_std.size); - rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); - } - } + break; + } + } + } + else + { + struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm; + ssize_t ret; + fprintf (stderr, "LOG : %s reads something from the socket\n", + dev.iface); // FIXME : debugging message + rrm = (struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf; + ret = + read_from_the_socket ((void *) &i, (unsigned char *) &rrm->frame, + sizeof(write_std.buf) + - sizeof(struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + + sizeof(struct + GNUNET_TRANSPORT_WLAN_Ieee80211Frame), + rrm); + if (0 >= ret) + { + int j; + FD_CLR (i, &rfds); + close (i); + /* Remove the socket from the list */ + for (j = 0; j < crt_rfds; j++) + { + if (rfds_list[j] == i) + { + rfds_list[j] ^= rfds_list[crt_rfds - 1]; + rfds_list[crt_rfds - 1] ^= rfds_list[j]; + rfds_list[j] ^= rfds_list[crt_rfds - 1]; + crt_rfds -= 1; + break; } + } + + fprintf (stderr, "Read error from raw socket: %s\n", strerror ( + errno)); + break; + } + if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev))) + { + write_std.size = ret + + sizeof(struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + - sizeof(struct + GNUNET_TRANSPORT_WLAN_Ieee80211Frame); + rrm->header.size = htons (write_std.size); + rrm->header.type = htons ( + GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); } + } } + } } + } /* Error handling, try to clean up a bit at least */ - mst_destroy(stdin_mst); + mst_destroy (stdin_mst); stdin_mst = NULL; - sdp_close(dev.session); - (void)close(dev.fd_rfcomm); + sdp_close (dev.session); + (void) close (dev.fd_rfcomm); if (-1 != sendsocket) - (void)close(sendsocket); + (void) close (sendsocket); for (i = 0; i < crt_rfds; i++) - (void)close(rfds_list[i]); + (void) close (rfds_list[i]); for (i = 0; i < neighbours.size; i++) - (void)close(neighbours.fds[i]); + (void) close (neighbours.fds[i]); #else struct HardwareInfos dev; struct GNUNET_NETWORK_Handle *sendsocket; @@ -1803,25 +1878,25 @@ connect_retry: SOCKADDR_BTH acc_addr = { 0 }; int addr_len = sizeof(SOCKADDR_BTH); int broadcast, i, stdin_open, crt_rfds = 0; - HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE); - HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); + HANDLE stdin_handle = GetStdHandle (STD_INPUT_HANDLE); + HANDLE stdout_handle = GetStdHandle (STD_OUTPUT_HANDLE); struct MessageStreamTokenizer *stdin_mst; /* check the handles */ if (stdin_handle == INVALID_HANDLE_VALUE) - { - fprintf(stderr, "Failed to get the stdin handle\n"); - ExitProcess(2); - } + { + fprintf (stderr, "Failed to get the stdin handle\n"); + ExitProcess (2); + } if (stdout_handle == INVALID_HANDLE_VALUE) - { - fprintf(stderr, "Failed to get the stdout handle\n"); - ExitProcess(2); - } + { + fprintf (stderr, "Failed to get the stdout handle\n"); + ExitProcess (2); + } /* initialize windows sockets */ - initialize_windows_sockets(); + initialize_windows_sockets (); // /* test bluetooth socket family support */ --> it return false because the GNUNET_NETWORK_test_pf should also receive the type of socket (BTHPROTO_RFCOMM) // if (GNUNET_NETWORK_test_pf (AF_BTH) != GNUNET_OK) @@ -1831,347 +1906,373 @@ connect_retry: // } /* create the socket */ - dev.handle = GNUNET_NETWORK_socket_create(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); + dev.handle = GNUNET_NETWORK_socket_create (AF_BTH, SOCK_STREAM, + BTHPROTO_RFCOMM); if (dev.handle == NULL) - { - fprintf(stderr, "Failed to create RFCOMM socket: "); - print_last_error(); - ExitProcess(2); - } + { + fprintf (stderr, "Failed to create RFCOMM socket: "); + print_last_error (); + ExitProcess (2); + } - if (open_device(&dev) == -1) + if (open_device (&dev) == -1) + { + fprintf (stderr, "Failed to open the device\n"); + print_last_error (); + if (GNUNET_NETWORK_socket_close (dev.handle) != GNUNET_OK) { - fprintf(stderr, "Failed to open the device\n"); - print_last_error(); - if (GNUNET_NETWORK_socket_close(dev.handle) != GNUNET_OK) - { - fprintf(stderr, "Failed to close the socket!\n"); - print_last_error(); - } - ExitProcess(2); + fprintf (stderr, "Failed to close the socket!\n"); + print_last_error (); } + ExitProcess (2); + } - if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(dev.handle, 1)) - { - fprintf(stderr, "Failed to change the socket mode\n"); - ExitProcess(2); - } + if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (dev.handle, 1)) + { + fprintf (stderr, "Failed to change the socket mode\n"); + ExitProcess (2); + } - memset(&write_std, 0, sizeof(write_std)); - memset(&write_pout, 0, sizeof(write_pout)); + memset (&write_std, 0, sizeof(write_std)); + memset (&write_pout, 0, sizeof(write_pout)); stdin_open = 1; - rfds = GNUNET_NETWORK_fdset_create(); - wfds = GNUNET_NETWORK_fdset_create(); + rfds = GNUNET_NETWORK_fdset_create (); + wfds = GNUNET_NETWORK_fdset_create (); /* Send MAC address of the bluetooth interface to STDOUT first */ { struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; - macmsg.hdr.size = htons(sizeof(macmsg)); - macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); - GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy)); - GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg)); + macmsg.hdr.size = htons (sizeof(macmsg)); + macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); + GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof(struct + GNUNET_TRANSPORT_WLAN_MacAddress_Copy)); + GNUNET_memcpy (write_std.buf, &macmsg, sizeof(macmsg)); write_std.size = sizeof(macmsg); } - stdin_mst = mst_create(&stdin_send_hw, &dev); + stdin_mst = mst_create (&stdin_send_hw, &dev); stdin_open = 1; int pos = 0; int stdin_pos = -1; int stdout_pos = -1; while (1) + { + broadcast = 0; + pos = 0; + stdin_pos = -1; + stdout_pos = -1; + sendsocket = NULL; // FIXME ???memleaks + + GNUNET_NETWORK_fdset_zero (rfds); + if ((0 == write_pout.size) && (1 == stdin_open)) + { + stdin_pos = pos; + pos += 1; + GNUNET_NETWORK_fdset_handle_set (rfds, (struct + GNUNET_DISK_FileHandle*) & + stdin_handle); + } + + if (0 == write_std.size) + { + pos += 1; + GNUNET_NETWORK_fdset_set (rfds, dev.handle); + } + + for (i = 0; i < crt_rfds; i++) + { + pos += 1; + GNUNET_NETWORK_fdset_set (rfds, rfds_list[i]); + } + + GNUNET_NETWORK_fdset_zero (wfds); + if (0 < write_std.size) { - broadcast = 0; - pos = 0; - stdin_pos = -1; - stdout_pos = -1; - sendsocket = NULL; //FIXME ???memleaks - - GNUNET_NETWORK_fdset_zero(rfds); - if ((0 == write_pout.size) && (1 == stdin_open)) + stdout_pos = pos; + GNUNET_NETWORK_fdset_handle_set (wfds, (struct + GNUNET_DISK_FileHandle*) & + stdout_handle); + // printf ("%s\n", write_std.buf); + // memset (write_std.buf, 0, write_std.size); + // write_std.size = 0; + } + + if (0 < write_pout.size) + { + if (strcmp (argv[1], "ff:ff:ff:ff:ff:ff") == 0) + { + fprintf (stderr, "LOG: BROADCAST! Skipping the message\n"); + // skip the message + broadcast = 1; + memset (write_pout.buf, 0, write_pout.size); + write_pout.size = 0; + } + else + { + SOCKADDR_BTH addr; + fprintf (stderr, "LOG : has a new message for %s\n", argv[1]); + sendsocket = GNUNET_NETWORK_socket_create (AF_BTH, SOCK_STREAM, + BTHPROTO_RFCOMM); + + if (sendsocket == NULL) { - stdin_pos = pos; - pos += 1; - GNUNET_NETWORK_fdset_handle_set(rfds, (struct GNUNET_DISK_FileHandle*)&stdin_handle); + fprintf (stderr, "Failed to create RFCOMM socket: \n"); + print_last_error (); + ExitProcess (2); } - if (0 == write_std.size) + memset (&addr, 0, sizeof(addr)); + // addr.addressFamily = AF_BTH; + if (SOCKET_ERROR == + WSAStringToAddress (argv[1], AF_BTH, NULL, (LPSOCKADDR) &addr, + &addr_len)) { - pos += 1; - GNUNET_NETWORK_fdset_set(rfds, dev.handle); + fprintf (stderr, "Failed to translate the address: "); + print_last_error (); + ExitProcess (2); } + addr.port = get_channel (argv[1]); + if (addr.port == -1) + { + fprintf (stderr, + "Couldn't find the sdp service for the address: %s\n", + argv[1]); + memset (write_pout.buf, 0, write_pout.size); + write_pout.size = 0; + broadcast = 1; // skipping the select part + } + else + { + if (GNUNET_OK != GNUNET_NETWORK_socket_connect (sendsocket, + (LPSOCKADDR) &addr, + addr_len)) + { + fprintf (stderr, "Failed to connect: "); + print_last_error (); + ExitProcess (2); + } - for (i = 0; i < crt_rfds; i++) + if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (sendsocket, 1)) + { + fprintf (stderr, "Failed to change the socket mode\n"); + ExitProcess (2); + } + + GNUNET_NETWORK_fdset_set (wfds, sendsocket); + } + } + } + + if (broadcast == 0) + { + int retval = GNUNET_NETWORK_socket_select (rfds, wfds, NULL, + GNUNET_TIME_relative_get_forever_ ()); + if (retval < 0) + { + fprintf (stderr, "Select error\n"); + ExitProcess (2); + } + // if (GNUNET_NETWORK_fdset_isset (wfds, (struct GNUNET_NETWORK_Handle*)&stdout_handle)) + if (retval == stdout_pos) + { + fprintf (stderr, "LOG : sends a message to STDOUT\n"); // FIXME: debugging message + // ssize_t ret; + // ret = GNUNET_NETWORK_socket_send ((struct GNUNET_NETWORK_Handle *)&stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos); + // ret = write (STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size - write_std.pos); + DWORD ret; + if (FALSE == WriteFile (stdout_handle, write_std.buf + write_std.pos, + write_std.size - write_std.pos, &ret, NULL)) { - pos += 1; - GNUNET_NETWORK_fdset_set(rfds, rfds_list[i]); + fprintf (stderr, "Failed to write to STDOUT: "); + print_last_error (); + break; } - GNUNET_NETWORK_fdset_zero(wfds); - if (0 < write_std.size) + if (ret <= 0) { - stdout_pos = pos; - GNUNET_NETWORK_fdset_handle_set(wfds, (struct GNUNET_DISK_FileHandle*)&stdout_handle); - // printf ("%s\n", write_std.buf); - // memset (write_std.buf, 0, write_std.size); - // write_std.size = 0; + fprintf (stderr, "Failed to write to STDOUT\n"); + ExitProcess (2); } - if (0 < write_pout.size) + write_std.pos += ret; + if (write_std.pos == write_std.size) { - if (strcmp(argv[1], "ff:ff:ff:ff:ff:ff") == 0) + write_std.pos = 0; + write_std.size = 0; + } + } + if (sendsocket != NULL) + { + if (GNUNET_NETWORK_fdset_isset (wfds, sendsocket)) + { + ssize_t ret; + ret = GNUNET_NETWORK_socket_send (sendsocket, write_pout.buf + + write_pout.pos, + write_pout.size - write_pout.pos); + + if (GNUNET_SYSERR == ret) + { + fprintf (stderr, + "Failed to send to the socket. Closing the socket. Error: \n"); + print_last_error (); + if (GNUNET_NETWORK_socket_close (sendsocket) != GNUNET_OK) { - fprintf(stderr, "LOG: BROADCAST! Skipping the message\n"); - // skip the message - broadcast = 1; - memset(write_pout.buf, 0, write_pout.size); - write_pout.size = 0; + fprintf (stderr, "Failed to close the sendsocket!\n"); + print_last_error (); } + ExitProcess (2); + } else + { + write_pout.pos += ret; + if ((write_pout.pos != write_pout.size) && (0 != ret)) { - SOCKADDR_BTH addr; - fprintf(stderr, "LOG : has a new message for %s\n", argv[1]); - sendsocket = GNUNET_NETWORK_socket_create(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); - - if (sendsocket == NULL) - { - fprintf(stderr, "Failed to create RFCOMM socket: \n"); - print_last_error(); - ExitProcess(2); - } - - memset(&addr, 0, sizeof(addr)); - //addr.addressFamily = AF_BTH; - if (SOCKET_ERROR == - WSAStringToAddress(argv[1], AF_BTH, NULL, (LPSOCKADDR)&addr, &addr_len)) - { - fprintf(stderr, "Failed to translate the address: "); - print_last_error(); - ExitProcess(2); - } - addr.port = get_channel(argv[1]); - if (addr.port == -1) - { - fprintf(stderr, "Couldn't find the sdp service for the address: %s\n", argv[1]); - memset(write_pout.buf, 0, write_pout.size); - write_pout.size = 0; - broadcast = 1; //skipping the select part - } - else - { - if (GNUNET_OK != GNUNET_NETWORK_socket_connect(sendsocket, (LPSOCKADDR)&addr, addr_len)) - { - fprintf(stderr, "Failed to connect: "); - print_last_error(); - ExitProcess(2); - } - - if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(sendsocket, 1)) - { - fprintf(stderr, "Failed to change the socket mode\n"); - ExitProcess(2); - } - - GNUNET_NETWORK_fdset_set(wfds, sendsocket); - } + /* we should not get partial sends with packet-oriented devices... */ + fprintf (stderr, "Write error, partial send: %u/%u\n", + (unsigned int) write_pout.pos, + (unsigned int) write_pout.size); + break; } - } - if (broadcast == 0) - { - int retval = GNUNET_NETWORK_socket_select(rfds, wfds, NULL, GNUNET_TIME_relative_get_forever_()); - if (retval < 0) + if (write_pout.pos == write_pout.size) { - fprintf(stderr, "Select error\n"); - ExitProcess(2); + write_pout.pos = 0; + write_pout.size = 0; } - //if (GNUNET_NETWORK_fdset_isset (wfds, (struct GNUNET_NETWORK_Handle*)&stdout_handle)) - if (retval == stdout_pos) - { - fprintf(stderr, "LOG : sends a message to STDOUT\n"); //FIXME: debugging message - //ssize_t ret; - //ret = GNUNET_NETWORK_socket_send ((struct GNUNET_NETWORK_Handle *)&stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos); - //ret = write (STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size - write_std.pos); - DWORD ret; - if (FALSE == WriteFile(stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos, &ret, NULL)) - { - fprintf(stderr, "Failed to write to STDOUT: "); - print_last_error(); - break; - } + fprintf (stderr, "LOG : sends a message to a DEVICE\n"); // FIXME: debugging message + } + } + } - if (ret <= 0) - { - fprintf(stderr, "Failed to write to STDOUT\n"); - ExitProcess(2); - } + // if (GNUNET_NETWORK_fdset_isset (rfds, (struct GNUNET_NETWORK_Handle*)&stdin_handle)) + if (retval == stdin_pos) + { + // ssize_t ret; + // ret = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)&stdin_handle, readbuf, sizeof (write_pout.buf)); + // ret = read (STDIN_FILENO, readbuf, sizeof (readbuf)); + DWORD ret; + if (FALSE == ReadFile (stdin_handle, readbuf, sizeof(readbuf), &ret, + NULL)) /* do nothing asynchronous */ + { + fprintf (stderr, "Read error from STDIN: "); + print_last_error (); + break; + } + if (0 == ret) + { + /* stop reading... */ + stdin_open = 0; + } + else + { + mst_receive (stdin_mst, readbuf, ret); + fprintf (stderr, "LOG : receives a message from STDIN\n"); // FIXME: debugging message + } + } + else if (GNUNET_NETWORK_fdset_isset (rfds, dev.handle)) + { + fprintf (stderr, "LOG: accepting connection\n"); + struct GNUNET_NETWORK_Handle *readsocket; + readsocket = GNUNET_NETWORK_socket_accept (dev.handle, + (LPSOCKADDR) &acc_addr, + &addr_len); + if (readsocket == NULL) + { + fprintf (stderr, "Accept error %d: ", GetLastError ()); + print_last_error (); + ExitProcess (2); + } + else + { + if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (readsocket, 1)) + { + fprintf (stderr, "Failed to change the socket mode\n"); + ExitProcess (2); + } + GNUNET_NETWORK_fdset_set (rfds, readsocket); - write_std.pos += ret; - if (write_std.pos == write_std.size) - { - write_std.pos = 0; - write_std.size = 0; - } - } - if (sendsocket != NULL) + if (crt_rfds < MAX_PORTS) + rfds_list[crt_rfds++] = readsocket; + else + { + fprintf (stderr, + "The limit for the read file descriptors list was reached\n"); + break; + } + } + } + else + for (i = 0; i < crt_rfds; i++) + { + if (GNUNET_NETWORK_fdset_isset (rfds, rfds_list[i])) + { + struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm; + ssize_t ret; + fprintf (stderr, "LOG: reading something from the socket\n"); // FIXME : debugging message + rrm = (struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf; + ret = read_from_the_socket (rfds_list[i], (unsigned + char *) &rrm->frame, + sizeof(write_std.buf) + - sizeof(struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + + sizeof(struct + GNUNET_TRANSPORT_WLAN_Ieee80211Frame), + rrm); + if (0 >= ret) { - if (GNUNET_NETWORK_fdset_isset(wfds, sendsocket)) - { - ssize_t ret; - ret = GNUNET_NETWORK_socket_send(sendsocket, write_pout.buf + write_pout.pos, - write_pout.size - write_pout.pos); - - if (GNUNET_SYSERR == ret) - { - fprintf(stderr, "Failed to send to the socket. Closing the socket. Error: \n"); - print_last_error(); - if (GNUNET_NETWORK_socket_close(sendsocket) != GNUNET_OK) - { - fprintf(stderr, "Failed to close the sendsocket!\n"); - print_last_error(); - } - ExitProcess(2); - } - else - { - write_pout.pos += ret; - if ((write_pout.pos != write_pout.size) && (0 != ret)) - { - /* we should not get partial sends with packet-oriented devices... */ - fprintf(stderr, "Write error, partial send: %u/%u\n", - (unsigned int)write_pout.pos, - (unsigned int)write_pout.size); - break; - } - - if (write_pout.pos == write_pout.size) - { - write_pout.pos = 0; - write_pout.size = 0; - } - fprintf(stderr, "LOG : sends a message to a DEVICE\n"); //FIXME: debugging message - } - } - } + // TODO remove the socket from the list + if (GNUNET_NETWORK_socket_close (rfds_list[i]) != GNUNET_OK) + { + fprintf (stderr, "Failed to close the sendsocket!\n"); + print_last_error (); + } - //if (GNUNET_NETWORK_fdset_isset (rfds, (struct GNUNET_NETWORK_Handle*)&stdin_handle)) - if (retval == stdin_pos) - { - //ssize_t ret; - //ret = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)&stdin_handle, readbuf, sizeof (write_pout.buf)); - //ret = read (STDIN_FILENO, readbuf, sizeof (readbuf)); - DWORD ret; - if (FALSE == ReadFile(stdin_handle, readbuf, sizeof(readbuf), &ret, NULL)) /* do nothing asynchronous */ - { - fprintf(stderr, "Read error from STDIN: "); - print_last_error(); - break; - } - if (0 == ret) - { - /* stop reading... */ - stdin_open = 0; - } - else - { - mst_receive(stdin_mst, readbuf, ret); - fprintf(stderr, "LOG : receives a message from STDIN\n"); //FIXME: debugging message - } + fprintf (stderr, "Read error from raw socket: "); + print_last_error (); + break; } - else - if (GNUNET_NETWORK_fdset_isset(rfds, dev.handle)) + if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev))) { - fprintf(stderr, "LOG: accepting connection\n"); - struct GNUNET_NETWORK_Handle *readsocket; - readsocket = GNUNET_NETWORK_socket_accept(dev.handle, (LPSOCKADDR)&acc_addr, &addr_len); - if (readsocket == NULL) - { - fprintf(stderr, "Accept error %d: ", GetLastError()); - print_last_error(); - ExitProcess(2); - } - else - { - if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(readsocket, 1)) - { - fprintf(stderr, "Failed to change the socket mode\n"); - ExitProcess(2); - } - GNUNET_NETWORK_fdset_set(rfds, readsocket); - - if (crt_rfds < MAX_PORTS) - rfds_list[crt_rfds++] = readsocket; - else - { - fprintf(stderr, "The limit for the read file descriptors list was reached\n"); - break; - } - } + write_std.size = ret + + sizeof(struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + - sizeof(struct + GNUNET_TRANSPORT_WLAN_Ieee80211Frame); + rrm->header.size = htons (write_std.size); + rrm->header.type = htons ( + GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); } - else - for (i = 0; i < crt_rfds; i++) - { - if (GNUNET_NETWORK_fdset_isset(rfds, rfds_list[i])) - { - struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm; - ssize_t ret; - fprintf(stderr, "LOG: reading something from the socket\n");//FIXME : debugging message - rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf; - ret = read_from_the_socket(rfds_list[i], (unsigned char *)&rrm->frame, - sizeof(write_std.buf) - - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) - + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame), - rrm); - if (0 >= ret) - { - //TODO remove the socket from the list - if (GNUNET_NETWORK_socket_close(rfds_list[i]) != GNUNET_OK) - { - fprintf(stderr, "Failed to close the sendsocket!\n"); - print_last_error(); - } - - fprintf(stderr, "Read error from raw socket: "); - print_last_error(); - break; - } - if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev))) - { - write_std.size = ret - + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) - - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame); - rrm->header.size = htons(write_std.size); - rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); - } - break; - } - } + break; + } } } + } - mst_destroy(stdin_mst); + mst_destroy (stdin_mst); stdin_mst = NULL; - if (GNUNET_NETWORK_socket_close(dev.handle) != GNUNET_OK) - { - fprintf(stderr, "Failed to close the socket!\n"); - print_last_error(); - } + if (GNUNET_NETWORK_socket_close (dev.handle) != GNUNET_OK) + { + fprintf (stderr, "Failed to close the socket!\n"); + print_last_error (); + } for (i = 0; i < crt_rfds; i++) + { + if (GNUNET_NETWORK_socket_close (rfds_list[i]) != GNUNET_OK) { - if (GNUNET_NETWORK_socket_close(rfds_list[i]) != GNUNET_OK) - { - fprintf(stderr, "Failed to close the socket!\n"); - print_last_error(); - } + fprintf (stderr, "Failed to close the socket!\n"); + print_last_error (); } + } - WSACleanup(); + WSACleanup (); #endif return 1; /* we never exit 'normally' */ } diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c index 44a54b7f6..ab77f5c68 100644 --- a/src/transport/gnunet-helper-transport-wlan-dummy.c +++ b/src/transport/gnunet-helper-transport-wlan-dummy.c @@ -47,7 +47,8 @@ /** * IO buffer used for buffering data in transit. */ -struct SendBuffer { +struct SendBuffer +{ /** * How many bytes that were stored in 'buf' did we already write to the * destination? Always smaller than 'size'. @@ -80,11 +81,11 @@ static int closeprog; * @param sig killing signal */ static void -sigfunc(int sig) +sigfunc (int sig) { closeprog = 1; - (void)unlink(FIFO_FILE1); - (void)unlink(FIFO_FILE2); + (void) unlink (FIFO_FILE1); + (void) unlink (FIFO_FILE2); } @@ -96,19 +97,19 @@ sigfunc(int sig) * @return number of bytes written */ static int -send_mac_to_plugin(char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) +send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) { struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; - GNUNET_memcpy(&macmsg.mac, - (char *)mac, - sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)); + GNUNET_memcpy (&macmsg.mac, + (char *) mac, + sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)); macmsg.hdr.size = - htons(sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); - macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); - GNUNET_memcpy(buffer, - &macmsg, - sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); + htons (sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); + macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); + GNUNET_memcpy (buffer, + &macmsg, + sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); return sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage); } @@ -124,7 +125,7 @@ send_mac_to_plugin(char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) * #GNUNET_SYSERR to stop further processing with error */ static int -stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr) +stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr) { struct SendBuffer *write_pout = cls; const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; @@ -132,32 +133,32 @@ stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr) struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader; uint16_t sendsize; - sendsize = ntohs(hdr->size); - in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr; - if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type)) || + sendsize = ntohs (hdr->size); + in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; + if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize)) - { - fprintf(stderr, "%s", "Received malformed message\n"); - exit(1); - } + { + fprintf (stderr, "%s", "Received malformed message\n"); + exit (1); + } payload_size = sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); - if ((payload_size + - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + - write_pout->size) > MAXLINE * 2) - { - fprintf(stderr, "%s", "Packet too big for buffer\n"); - exit(1); - } - memset(&newheader, 0, sizeof(newheader)); - newheader.header.size = htons(payload_size + sizeof(newheader)); - newheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); + if ((payload_size + + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + + write_pout->size) > MAXLINE * 2) + { + fprintf (stderr, "%s", "Packet too big for buffer\n"); + exit (1); + } + memset (&newheader, 0, sizeof(newheader)); + newheader.header.size = htons (payload_size + sizeof(newheader)); + newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); newheader.frame = in->frame; - GNUNET_memcpy(write_pout->buf + write_pout->size, - &newheader, - sizeof(newheader)); + GNUNET_memcpy (write_pout->buf + write_pout->size, + &newheader, + sizeof(newheader)); write_pout->size += sizeof(newheader); - GNUNET_memcpy(write_pout->buf + write_pout->size, &in[1], payload_size); + GNUNET_memcpy (write_pout->buf + write_pout->size, &in[1], payload_size); write_pout->size += payload_size; return GNUNET_OK; } @@ -173,18 +174,18 @@ stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr) * #GNUNET_SYSERR to stop further processing with error */ static int -file_in_send(void *cls, const struct GNUNET_MessageHeader *hdr) +file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr) { struct SendBuffer *write_std = cls; uint16_t sendsize; - sendsize = ntohs(hdr->size); + sendsize = ntohs (hdr->size); if ((sendsize + write_std->size) > MAXLINE * 2) - { - fprintf(stderr, "%s", "Packet too big for buffer\n"); - exit(1); - } - GNUNET_memcpy(write_std->buf + write_std->size, hdr, sendsize); + { + fprintf (stderr, "%s", "Packet too big for buffer\n"); + exit (1); + } + GNUNET_memcpy (write_std->buf + write_std->size, hdr, sendsize); write_std->size += sendsize; return GNUNET_OK; } @@ -198,7 +199,7 @@ file_in_send(void *cls, const struct GNUNET_MessageHeader *hdr) * @return 1 on error, 0 if terminated normally via signal */ int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { struct stat st; int erg; @@ -222,298 +223,298 @@ main(int argc, char *argv[]) int first; if ((2 != argc) || - ((0 != strcmp(argv[1], "1")) && (0 != strcmp(argv[1], "2")))) - { - fprintf( - stderr, - "%s", - "This program must be started with the operating mode (1 or 2) as the only argument.\n"); - return 1; - } + ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2")))) + { + fprintf ( + stderr, + "%s", + "This program must be started with the operating mode (1 or 2) as the only argument.\n"); + return 1; + } /* make the fifos if needed */ - umask(0); - if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file(FIFO_FILE1)) || - (GNUNET_OK != GNUNET_DISK_directory_create_for_file(FIFO_FILE2))) + umask (0); + if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) || + (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2))) + { + fprintf (stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1); + return 1; + } + if (0 == strcmp (argv[1], "1")) + { + if (0 != stat (FIFO_FILE1, &st)) { - fprintf(stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1); - return 1; - } - if (0 == strcmp(argv[1], "1")) - { - if (0 != stat(FIFO_FILE1, &st)) - { - erg = mkfifo(FIFO_FILE1, 0666); - if ((0 != erg) && (EEXIST != errno)) - fprintf(stderr, - "Error in mkfifo(%s): %s\n", - FIFO_FILE1, - strerror(errno)); - } + erg = mkfifo (FIFO_FILE1, 0666); + if ((0 != erg) && (EEXIST != errno)) + fprintf (stderr, + "Error in mkfifo(%s): %s\n", + FIFO_FILE1, + strerror (errno)); } + } else + { + if (0 != stat (FIFO_FILE2, &st)) { - if (0 != stat(FIFO_FILE2, &st)) - { - GNUNET_break(0 == (erg = mkfifo(FIFO_FILE2, 0666))); - if ((0 != erg) && (EEXIST != errno)) - fprintf(stderr, - "Error in mkfifo(%s): %s\n", - FIFO_FILE2, - strerror(errno)); - } + GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); + if ((0 != erg) && (EEXIST != errno)) + fprintf (stderr, + "Error in mkfifo(%s): %s\n", + FIFO_FILE2, + strerror (errno)); } + } - if (0 == strcmp(argv[1], "1")) + if (0 == strcmp (argv[1], "1")) + { + first = 1; + fpin = fopen (FIFO_FILE1, "r"); + if (NULL == fpin) { - first = 1; - fpin = fopen(FIFO_FILE1, "r"); - if (NULL == fpin) - { - fprintf(stderr, - "fopen of read FIFO_FILE1 failed: %s\n", - strerror(errno)); - goto end; - } - if (NULL == (fpout = fopen(FIFO_FILE2, "w"))) - { - GNUNET_break(0 == mkfifo(FIFO_FILE2, 0666)); - fpout = fopen(FIFO_FILE2, "w"); - } - if (NULL == fpout) - { - fprintf(stderr, - "fopen of write FIFO_FILE2 failed: %s\n", - strerror(errno)); - goto end; - } + fprintf (stderr, + "fopen of read FIFO_FILE1 failed: %s\n", + strerror (errno)); + goto end; + } + if (NULL == (fpout = fopen (FIFO_FILE2, "w"))) + { + GNUNET_break (0 == mkfifo (FIFO_FILE2, 0666)); + fpout = fopen (FIFO_FILE2, "w"); } + if (NULL == fpout) + { + fprintf (stderr, + "fopen of write FIFO_FILE2 failed: %s\n", + strerror (errno)); + goto end; + } + } else + { + first = 0; + if (NULL == (fpout = fopen (FIFO_FILE1, "w"))) { - first = 0; - if (NULL == (fpout = fopen(FIFO_FILE1, "w"))) - { - GNUNET_break(0 == mkfifo(FIFO_FILE1, 0666)); - fpout = fopen(FIFO_FILE1, "w"); - } - if (NULL == fpout) - { - fprintf(stderr, - "fopen of write FIFO_FILE1 failed: %s\n", - strerror(errno)); - goto end; - } - fpin = fopen(FIFO_FILE2, "r"); - if (NULL == fpin) - { - fprintf(stderr, - "fopen of read FIFO_FILE2 failed: %s\n", - strerror(errno)); - goto end; - } + GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666)); + fpout = fopen (FIFO_FILE1, "w"); } - - fdpin = fileno(fpin); - GNUNET_assert(fpin >= 0); - if (fdpin >= FD_SETSIZE) + if (NULL == fpout) { - fprintf(stderr, - "File fdpin number too large (%d > %u)\n", - fdpin, - (unsigned int)FD_SETSIZE); + fprintf (stderr, + "fopen of write FIFO_FILE1 failed: %s\n", + strerror (errno)); goto end; } - - fdpout = fileno(fpout); - GNUNET_assert(fdpout >= 0); - - if (fdpout >= FD_SETSIZE) + fpin = fopen (FIFO_FILE2, "r"); + if (NULL == fpin) { - fprintf(stderr, - "File fdpout number too large (%d > %u)\n", - fdpout, - (unsigned int)FD_SETSIZE); + fprintf (stderr, + "fopen of read FIFO_FILE2 failed: %s\n", + strerror (errno)); goto end; } + } + + fdpin = fileno (fpin); + GNUNET_assert (fpin >= 0); + if (fdpin >= FD_SETSIZE) + { + fprintf (stderr, + "File fdpin number too large (%d > %u)\n", + fdpin, + (unsigned int) FD_SETSIZE); + goto end; + } - signal(SIGINT, &sigfunc); - signal(SIGTERM, &sigfunc); - signal(GNUNET_TERM_SIG, &sigfunc); + fdpout = fileno (fpout); + GNUNET_assert (fdpout >= 0); + + if (fdpout >= FD_SETSIZE) + { + fprintf (stderr, + "File fdpout number too large (%d > %u)\n", + fdpout, + (unsigned int) FD_SETSIZE); + goto end; + } + + signal (SIGINT, &sigfunc); + signal (SIGTERM, &sigfunc); + signal (GNUNET_TERM_SIG, &sigfunc); write_std.size = 0; write_std.pos = 0; write_pout.size = 0; write_pout.pos = 0; - stdin_mst = GNUNET_MST_create(&stdin_send, &write_pout); - file_in_mst = GNUNET_MST_create(&file_in_send, &write_std); + stdin_mst = GNUNET_MST_create (&stdin_send, &write_pout); + file_in_mst = GNUNET_MST_create (&file_in_send, &write_std); /* Send 'random' mac address */ macaddr.mac[0] = 0x13; macaddr.mac[1] = 0x22; macaddr.mac[2] = 0x33; macaddr.mac[3] = 0x44; - macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256); - macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256); - write_std.size = send_mac_to_plugin(write_std.buf, &macaddr); + macaddr.mac[4] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 256); + macaddr.mac[5] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 256); + write_std.size = send_mac_to_plugin (write_std.buf, &macaddr); while (0 == closeprog) + { + maxfd = -1; + tv.tv_sec = 5; + tv.tv_usec = 0; + + FD_ZERO (&rfds); + FD_ZERO (&wfds); + /* if output queue is empty, read */ + if (0 == write_pout.size) { - maxfd = -1; - tv.tv_sec = 5; - tv.tv_usec = 0; - - FD_ZERO(&rfds); - FD_ZERO(&wfds); - /* if output queue is empty, read */ - if (0 == write_pout.size) - { - FD_SET(STDIN_FILENO, &rfds); - maxfd = MAX(STDIN_FILENO, maxfd); - } - if (0 == write_std.size) - { - FD_SET(fdpin, &rfds); - maxfd = MAX(fdpin, maxfd); - } + FD_SET (STDIN_FILENO, &rfds); + maxfd = MAX (STDIN_FILENO, maxfd); + } + if (0 == write_std.size) + { + FD_SET (fdpin, &rfds); + maxfd = MAX (fdpin, maxfd); + } - /* if there is something to write, try to write */ - if (0 < write_std.size) - { - FD_SET(STDOUT_FILENO, &wfds); - maxfd = MAX(maxfd, STDOUT_FILENO); - } - if (0 < write_pout.size) - { - FD_SET(fdpout, &wfds); - maxfd = MAX(maxfd, fdpout); - } + /* if there is something to write, try to write */ + if (0 < write_std.size) + { + FD_SET (STDOUT_FILENO, &wfds); + maxfd = MAX (maxfd, STDOUT_FILENO); + } + if (0 < write_pout.size) + { + FD_SET (fdpout, &wfds); + maxfd = MAX (maxfd, fdpout); + } - retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv); - if ((-1 == retval) && (EINTR == errno)) - continue; - if (0 > retval) - { - fprintf(stderr, "select failed: %s\n", strerror(errno)); - closeprog = 1; - break; - } + retval = select (maxfd + 1, &rfds, &wfds, NULL, &tv); + if ((-1 == retval) && (EINTR == errno)) + continue; + if (0 > retval) + { + fprintf (stderr, "select failed: %s\n", strerror (errno)); + closeprog = 1; + break; + } - if (FD_ISSET(STDOUT_FILENO, &wfds)) + if (FD_ISSET (STDOUT_FILENO, &wfds)) + { + ret = write (STDOUT_FILENO, + write_std.buf + write_std.pos, + write_std.size - write_std.pos); + if (0 > ret) + { + closeprog = 1; + fprintf (stderr, + "Write ERROR to STDOUT_FILENO: %s\n", + strerror (errno)); + break; + } + else + { + write_std.pos += ret; + /* check if finished writing */ + if (write_std.pos == write_std.size) { - ret = write(STDOUT_FILENO, - write_std.buf + write_std.pos, - write_std.size - write_std.pos); - if (0 > ret) - { - closeprog = 1; - fprintf(stderr, - "Write ERROR to STDOUT_FILENO: %s\n", - strerror(errno)); - break; - } - else - { - write_std.pos += ret; - /* check if finished writing */ - if (write_std.pos == write_std.size) - { - write_std.pos = 0; - write_std.size = 0; - } - } + write_std.pos = 0; + write_std.size = 0; } + } + } - if (FD_ISSET(fdpout, &wfds)) + if (FD_ISSET (fdpout, &wfds)) + { + ret = write (fdpout, + write_pout.buf + write_pout.pos, + write_pout.size - write_pout.pos); + + if (0 > ret) + { + closeprog = 1; + fprintf (stderr, + "Write ERROR to fdpout failed: %s\n", + strerror (errno)); + } + else + { + write_pout.pos += ret; + /* check if finished writing */ + if (write_pout.pos == write_pout.size) { - ret = write(fdpout, - write_pout.buf + write_pout.pos, - write_pout.size - write_pout.pos); - - if (0 > ret) - { - closeprog = 1; - fprintf(stderr, - "Write ERROR to fdpout failed: %s\n", - strerror(errno)); - } - else - { - write_pout.pos += ret; - /* check if finished writing */ - if (write_pout.pos == write_pout.size) - { - write_pout.pos = 0; - write_pout.size = 0; - } - } + write_pout.pos = 0; + write_pout.size = 0; } + } + } - if (FD_ISSET(STDIN_FILENO, &rfds)) - { - readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf)); - - if (0 > readsize) - { - closeprog = 1; - fprintf(stderr, - "Error reading from STDIN_FILENO: %s\n", - strerror(errno)); - } - else if (0 < readsize) - { - GNUNET_MST_from_buffer(stdin_mst, - readbuf, - readsize, - GNUNET_NO, - GNUNET_NO); - } - else - { - /* eof */ - closeprog = 1; - } - } + if (FD_ISSET (STDIN_FILENO, &rfds)) + { + readsize = read (STDIN_FILENO, readbuf, sizeof(readbuf)); + + if (0 > readsize) + { + closeprog = 1; + fprintf (stderr, + "Error reading from STDIN_FILENO: %s\n", + strerror (errno)); + } + else if (0 < readsize) + { + GNUNET_MST_from_buffer (stdin_mst, + readbuf, + readsize, + GNUNET_NO, + GNUNET_NO); + } + else + { + /* eof */ + closeprog = 1; + } + } - if (FD_ISSET(fdpin, &rfds)) - { - readsize = read(fdpin, readbuf, sizeof(readbuf)); - if (0 > readsize) - { - closeprog = 1; - fprintf(stderr, "Error reading from fdpin: %s\n", strerror(errno)); - break; - } - else if (0 < readsize) - { - GNUNET_MST_from_buffer(file_in_mst, - readbuf, - readsize, - GNUNET_NO, - GNUNET_NO); - } - else - { - /* eof */ - closeprog = 1; - } - } + if (FD_ISSET (fdpin, &rfds)) + { + readsize = read (fdpin, readbuf, sizeof(readbuf)); + if (0 > readsize) + { + closeprog = 1; + fprintf (stderr, "Error reading from fdpin: %s\n", strerror (errno)); + break; + } + else if (0 < readsize) + { + GNUNET_MST_from_buffer (file_in_mst, + readbuf, + readsize, + GNUNET_NO, + GNUNET_NO); + } + else + { + /* eof */ + closeprog = 1; + } } + } end: /* clean up */ if (NULL != stdin_mst) - GNUNET_MST_destroy(stdin_mst); + GNUNET_MST_destroy (stdin_mst); if (NULL != file_in_mst) - GNUNET_MST_destroy(file_in_mst); + GNUNET_MST_destroy (file_in_mst); if (NULL != fpout) - fclose(fpout); + fclose (fpout); if (NULL != fpin) - fclose(fpin); + fclose (fpin); if (1 == first) - { - (void)unlink(FIFO_FILE1); - (void)unlink(FIFO_FILE2); - } + { + (void) unlink (FIFO_FILE1); + (void) unlink (FIFO_FILE2); + } return 0; } diff --git a/src/transport/gnunet-helper-transport-wlan.c b/src/transport/gnunet-helper-transport-wlan.c index 885edb1b0..7ad6c5175 100644 --- a/src/transport/gnunet-helper-transport-wlan.c +++ b/src/transport/gnunet-helper-transport-wlan.c @@ -234,7 +234,8 @@ /** * Values in the 'struct PrismHeader'. All in host byte order (!). */ -struct PrismValue { +struct PrismValue +{ /** * This has a different ID for each parameter, see * PRISM_DID_* constants. @@ -263,7 +264,8 @@ struct PrismValue { /** * Prism header format ('struct p80211msg' in Linux). All in host byte order (!). */ -struct PrismHeader { +struct PrismHeader +{ /** * We expect this to be a PRISM_MSGCODE_*. */ @@ -301,7 +303,8 @@ struct PrismHeader { * reliable indicator of alignment requirement. See also * 'man 9 ieee80211_radiotap'. */ -enum RadiotapType { +enum RadiotapType +{ /** * IEEE80211_RADIOTAP_TSFT __le64 microseconds * @@ -576,7 +579,8 @@ enum RadiotapType { * The radio capture header precedes the 802.11 header. * All data in the header is little endian on all platforms. */ -struct Ieee80211RadiotapHeader { +struct Ieee80211RadiotapHeader +{ /** * Version 0. Only increases for drastic changes, introduction of * compatible new fields does not count. @@ -607,7 +611,8 @@ struct Ieee80211RadiotapHeader { * Format of the header we need to prepend to messages to be sent to the * Kernel. */ -struct RadiotapTransmissionHeader { +struct RadiotapTransmissionHeader +{ /** * First we begin with the 'generic' header we also get when receiving * messages. @@ -638,7 +643,12 @@ struct RadiotapTransmissionHeader { * following value for 'header.it_present' based on the presence of * the 'rate' and 'txflags' in the overall struct. */ -#define IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK ((1 << IEEE80211_RADIOTAP_RATE) | (1 << IEEE80211_RADIOTAP_TX_FLAGS)) +#define IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK ((1 \ + << \ + IEEE80211_RADIOTAP_RATE) \ + | (1 \ + << \ + IEEE80211_RADIOTAP_TX_FLAGS)) @@ -646,7 +656,8 @@ struct RadiotapTransmissionHeader { * struct Ieee80211RadiotapHeaderIterator - tracks walk through present radiotap arguments * in the radiotap header. Used when we parse radiotap packets received from the kernel. */ -struct Ieee80211RadiotapHeaderIterator { +struct Ieee80211RadiotapHeaderIterator +{ /** * pointer to the radiotap header we are walking through */ @@ -698,7 +709,8 @@ struct Ieee80211RadiotapHeaderIterator { * struct for storing the information of the hardware. There is only * one of these. */ -struct HardwareInfos { +struct HardwareInfos +{ /** * file descriptor for the raw socket */ @@ -725,7 +737,8 @@ struct HardwareInfos { /** * IO buffer used for buffering data in transit (to wireless or to stdout). */ -struct SendBuffer { +struct SendBuffer +{ /** * How many bytes of data are stored in 'buf' for transmission right now? * Data always starts at offset 0 and extends to 'size'. @@ -787,7 +800,8 @@ typedef void (*MessageTokenizerCallback) (void *cls, /** * Handle to a message stream tokenizer. */ -struct MessageStreamTokenizer { +struct MessageStreamTokenizer +{ /** * Function to call on completed messages. */ @@ -828,23 +842,23 @@ struct MessageStreamTokenizer { * @return handle to tokenizer */ static struct MessageStreamTokenizer * -mst_create(MessageTokenizerCallback cb, - void *cb_cls) +mst_create (MessageTokenizerCallback cb, + void *cb_cls) { struct MessageStreamTokenizer *ret; - ret = malloc(sizeof(struct MessageStreamTokenizer)); + ret = malloc (sizeof(struct MessageStreamTokenizer)); if (NULL == ret) - { - fprintf(stderr, "Failed to allocate buffer for tokenizer\n"); - exit(1); - } - ret->hdr = malloc(MIN_BUFFER_SIZE); + { + fprintf (stderr, "Failed to allocate buffer for tokenizer\n"); + exit (1); + } + ret->hdr = malloc (MIN_BUFFER_SIZE); if (NULL == ret->hdr) - { - fprintf(stderr, "Failed to allocate buffer for alignment\n"); - exit(1); - } + { + fprintf (stderr, "Failed to allocate buffer for alignment\n"); + exit (1); + } ret->curr_buf = MIN_BUFFER_SIZE; ret->cb = cb; ret->cb_cls = cb_cls; @@ -863,8 +877,8 @@ mst_create(MessageTokenizerCallback cb, * GNUNET_SYSERR if the data stream is corrupt */ static int -mst_receive(struct MessageStreamTokenizer *mst, - const char *buf, size_t size) +mst_receive (struct MessageStreamTokenizer *mst, + const char *buf, size_t size) { const struct GNUNET_MessageHeader *hdr; size_t delta; @@ -875,132 +889,132 @@ mst_receive(struct MessageStreamTokenizer *mst, int ret; ret = GNUNET_OK; - ibuf = (char *)mst->hdr; + ibuf = (char *) mst->hdr; while (mst->pos > 0) - { + { do_align: - if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) || - (0 != (mst->off % ALIGN_FACTOR))) - { - /* need to align or need more space */ - mst->pos -= mst->off; - memmove(ibuf, &ibuf[mst->off], mst->pos); - mst->off = 0; - } - if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) - { - delta = - GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) - - (mst->pos - mst->off), size); - GNUNET_memcpy(&ibuf[mst->pos], buf, delta); - mst->pos += delta; - buf += delta; - size -= delta; - } - if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) - { - return GNUNET_OK; - } - hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off]; - want = ntohs(hdr->size); - if (want < sizeof(struct GNUNET_MessageHeader)) - { - fprintf(stderr, - "Received invalid message from stdin\n"); - exit(1); - } - if (mst->curr_buf - mst->off < want) - { - /* need more space */ - mst->pos -= mst->off; - memmove(ibuf, &ibuf[mst->off], mst->pos); - mst->off = 0; - } - if (want > mst->curr_buf) - { - mst->hdr = realloc(mst->hdr, want); - if (NULL == mst->hdr) - { - fprintf(stderr, "Failed to allocate buffer for alignment\n"); - exit(1); - } - ibuf = (char *)mst->hdr; - mst->curr_buf = want; - } - hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off]; - if (mst->pos - mst->off < want) - { - delta = GNUNET_MIN(want - (mst->pos - mst->off), size); - GNUNET_memcpy(&ibuf[mst->pos], buf, delta); - mst->pos += delta; - buf += delta; - size -= delta; - } - if (mst->pos - mst->off < want) - { - return GNUNET_OK; - } - mst->cb(mst->cb_cls, hdr); - mst->off += want; - if (mst->off == mst->pos) - { - /* reset to beginning of buffer, it's free right now! */ - mst->off = 0; - mst->pos = 0; - } + if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) || + (0 != (mst->off % ALIGN_FACTOR))) + { + /* need to align or need more space */ + mst->pos -= mst->off; + memmove (ibuf, &ibuf[mst->off], mst->pos); + mst->off = 0; + } + if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) + { + delta = + GNUNET_MIN (sizeof(struct GNUNET_MessageHeader) + - (mst->pos - mst->off), size); + GNUNET_memcpy (&ibuf[mst->pos], buf, delta); + mst->pos += delta; + buf += delta; + size -= delta; + } + if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) + { + return GNUNET_OK; + } + hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; + want = ntohs (hdr->size); + if (want < sizeof(struct GNUNET_MessageHeader)) + { + fprintf (stderr, + "Received invalid message from stdin\n"); + exit (1); + } + if (mst->curr_buf - mst->off < want) + { + /* need more space */ + mst->pos -= mst->off; + memmove (ibuf, &ibuf[mst->off], mst->pos); + mst->off = 0; + } + if (want > mst->curr_buf) + { + mst->hdr = realloc (mst->hdr, want); + if (NULL == mst->hdr) + { + fprintf (stderr, "Failed to allocate buffer for alignment\n"); + exit (1); + } + ibuf = (char *) mst->hdr; + mst->curr_buf = want; + } + hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; + if (mst->pos - mst->off < want) + { + delta = GNUNET_MIN (want - (mst->pos - mst->off), size); + GNUNET_memcpy (&ibuf[mst->pos], buf, delta); + mst->pos += delta; + buf += delta; + size -= delta; + } + if (mst->pos - mst->off < want) + { + return GNUNET_OK; } + mst->cb (mst->cb_cls, hdr); + mst->off += want; + if (mst->off == mst->pos) + { + /* reset to beginning of buffer, it's free right now! */ + mst->off = 0; + mst->pos = 0; + } + } while (size > 0) + { + if (size < sizeof(struct GNUNET_MessageHeader)) + break; + offset = (unsigned long) buf; + need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; + if (GNUNET_NO == need_align) { - if (size < sizeof(struct GNUNET_MessageHeader)) - break; - offset = (unsigned long)buf; - need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; - if (GNUNET_NO == need_align) - { - /* can try to do zero-copy and process directly from original buffer */ - hdr = (const struct GNUNET_MessageHeader *)buf; - want = ntohs(hdr->size); - if (want < sizeof(struct GNUNET_MessageHeader)) - { - fprintf(stderr, - "Received invalid message from stdin\n"); - exit(1); - } - if (size < want) - break; /* or not, buffer incomplete, so copy to private buffer... */ - mst->cb(mst->cb_cls, hdr); - buf += want; - size -= want; - } - else - { - /* need to copy to private buffer to align; - * yes, we go a bit more spagetti than usual here */ - goto do_align; - } + /* can try to do zero-copy and process directly from original buffer */ + hdr = (const struct GNUNET_MessageHeader *) buf; + want = ntohs (hdr->size); + if (want < sizeof(struct GNUNET_MessageHeader)) + { + fprintf (stderr, + "Received invalid message from stdin\n"); + exit (1); + } + if (size < want) + break; /* or not, buffer incomplete, so copy to private buffer... */ + mst->cb (mst->cb_cls, hdr); + buf += want; + size -= want; + } + else + { + /* need to copy to private buffer to align; + * yes, we go a bit more spagetti than usual here */ + goto do_align; } + } if (size > 0) + { + if (size + mst->pos > mst->curr_buf) { - if (size + mst->pos > mst->curr_buf) - { - mst->hdr = realloc(mst->hdr, size + mst->pos); - if (NULL == mst->hdr) - { - fprintf(stderr, "Failed to allocate buffer for alignment\n"); - exit(1); - } - ibuf = (char *)mst->hdr; - mst->curr_buf = size + mst->pos; - } - if (mst->pos + size > mst->curr_buf) - { - fprintf(stderr, - "Assertion failed\n"); - exit(1); - } - GNUNET_memcpy(&ibuf[mst->pos], buf, size); - mst->pos += size; + mst->hdr = realloc (mst->hdr, size + mst->pos); + if (NULL == mst->hdr) + { + fprintf (stderr, "Failed to allocate buffer for alignment\n"); + exit (1); + } + ibuf = (char *) mst->hdr; + mst->curr_buf = size + mst->pos; + } + if (mst->pos + size > mst->curr_buf) + { + fprintf (stderr, + "Assertion failed\n"); + exit (1); } + GNUNET_memcpy (&ibuf[mst->pos], buf, size); + mst->pos += size; + } return ret; } @@ -1011,10 +1025,10 @@ do_align: * @param mst tokenizer to destroy */ static void -mst_destroy(struct MessageStreamTokenizer *mst) +mst_destroy (struct MessageStreamTokenizer *mst) { - free(mst->hdr); - free(mst); + free (mst->hdr); + free (mst); } /* ***************** end of server_mst.c clone ***************** **/ @@ -1040,9 +1054,11 @@ mst_destroy(struct MessageStreamTokenizer *mst) * @return 0 on success, -1 on error */ static int -ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterator, - const struct Ieee80211RadiotapHeader *radiotap_header, - size_t max_length) +ieee80211_radiotap_iterator_init (struct + Ieee80211RadiotapHeaderIterator *iterator, + const struct + Ieee80211RadiotapHeader *radiotap_header, + size_t max_length) { if ((iterator == NULL) || (radiotap_header == NULL)) @@ -1054,36 +1070,39 @@ ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterato /* sanity check for allowed length and radiotap length field */ if ((max_length < sizeof(struct Ieee80211RadiotapHeader)) || - (max_length < (GNUNET_le16toh(radiotap_header->it_len)))) + (max_length < (GNUNET_le16toh (radiotap_header->it_len)))) return -1; - memset(iterator, 0, sizeof(struct Ieee80211RadiotapHeaderIterator)); + memset (iterator, 0, sizeof(struct Ieee80211RadiotapHeaderIterator)); iterator->rtheader = radiotap_header; - iterator->max_length = GNUNET_le16toh(radiotap_header->it_len); - iterator->bitmap_shifter = GNUNET_le32toh(radiotap_header->it_present); - iterator->arg = ((uint8_t *)radiotap_header) + sizeof(struct Ieee80211RadiotapHeader); + iterator->max_length = GNUNET_le16toh (radiotap_header->it_len); + iterator->bitmap_shifter = GNUNET_le32toh (radiotap_header->it_present); + iterator->arg = ((uint8_t *) radiotap_header) + sizeof(struct + Ieee80211RadiotapHeader); /* find payload start allowing for extended bitmap(s) */ if (0 != (iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) + { + while (GNUNET_le32toh (*((uint32_t *) iterator->arg)) + & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) { - while (GNUNET_le32toh(*((uint32_t *)iterator->arg)) & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) - { - iterator->arg += sizeof(uint32_t); - /* - * check for insanity where the present bitmaps - * keep claiming to extend up to or even beyond the - * stated radiotap header length - */ - if (iterator->arg - ((uint8_t*)iterator->rtheader) > iterator->max_length) - return -1; - } iterator->arg += sizeof(uint32_t); /* - * no need to check again for blowing past stated radiotap - * header length, becuase ieee80211_radiotap_iterator_next - * checks it before it is dereferenced + * check for insanity where the present bitmaps + * keep claiming to extend up to or even beyond the + * stated radiotap header length */ + if (iterator->arg - ((uint8_t*) iterator->rtheader) > + iterator->max_length) + return -1; } + iterator->arg += sizeof(uint32_t); + /* + * no need to check again for blowing past stated radiotap + * header length, becuase ieee80211_radiotap_iterator_next + * checks it before it is dereferenced + */ + } /* we are all initialized happily */ return 0; } @@ -1102,7 +1121,8 @@ ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterato * @return next present arg index on success or -1 if no more or error */ static int -ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterator) +ieee80211_radiotap_iterator_next (struct + Ieee80211RadiotapHeaderIterator *iterator) { /* * small length lookup table for all radiotap types we heard of @@ -1149,94 +1169,96 @@ ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterato * least skip (by knowing the length)... */ while (iterator->arg_index < sizeof(rt_sizes)) + { + int hit = (0 != (iterator->bitmap_shifter & 1)); + + if (hit) { - int hit = (0 != (iterator->bitmap_shifter & 1)); + unsigned int wanted_alignment; + unsigned int unalignment; + /* + * arg is present, account for alignment padding + * 8-bit args can be at any alignment + * 16-bit args must start on 16-bit boundary + * 32-bit args must start on 32-bit boundary + * 64-bit args must start on 64-bit boundary + * + * note that total arg size can differ from alignment of + * elements inside arg, so we use upper nybble of length table + * to base alignment on. First, 'wanted_alignment' is set to be + * 1 for 8-bit, 2 for 16-bit, 4 for 32-bit and 8 for 64-bit + * arguments. Then, we calculate the 'unalignment' (how many + * bytes we are over by taking the difference of 'arg' and the + * overall starting point modulo the desired alignment. As + * desired alignments are powers of two, we can do modulo with + * binary "&" (and also avoid the possibility of a division by + * zero if the 'rt_sizes' table contains bogus entries). + * + * also note: these alignments are relative to the start of the + * radiotap header. There is no guarantee that the radiotap + * header itself is aligned on any kind of boundary, thus we + * need to really look at the delta here. + */ + wanted_alignment = rt_sizes[iterator->arg_index] >> 4; + unalignment = (((void *) iterator->arg) - ((void *) iterator->rtheader)) + & (wanted_alignment - 1); + if (0 != unalignment) + { + /* need padding (by 'wanted_alignment - unalignment') */ + iterator->arg_index += wanted_alignment - unalignment; + } - if (hit) - { - unsigned int wanted_alignment; - unsigned int unalignment; - /* - * arg is present, account for alignment padding - * 8-bit args can be at any alignment - * 16-bit args must start on 16-bit boundary - * 32-bit args must start on 32-bit boundary - * 64-bit args must start on 64-bit boundary - * - * note that total arg size can differ from alignment of - * elements inside arg, so we use upper nybble of length table - * to base alignment on. First, 'wanted_alignment' is set to be - * 1 for 8-bit, 2 for 16-bit, 4 for 32-bit and 8 for 64-bit - * arguments. Then, we calculate the 'unalignment' (how many - * bytes we are over by taking the difference of 'arg' and the - * overall starting point modulo the desired alignment. As - * desired alignments are powers of two, we can do modulo with - * binary "&" (and also avoid the possibility of a division by - * zero if the 'rt_sizes' table contains bogus entries). - * - * also note: these alignments are relative to the start of the - * radiotap header. There is no guarantee that the radiotap - * header itself is aligned on any kind of boundary, thus we - * need to really look at the delta here. - */ - wanted_alignment = rt_sizes[iterator->arg_index] >> 4; - unalignment = (((void *)iterator->arg) - ((void *)iterator->rtheader)) & (wanted_alignment - 1); - if (0 != unalignment) - { - /* need padding (by 'wanted_alignment - unalignment') */ - iterator->arg_index += wanted_alignment - unalignment; - } + /* + * this is what we will return to user, but we need to + * move on first so next call has something fresh to test + */ + iterator->this_arg_index = iterator->arg_index; + iterator->this_arg = iterator->arg; - /* - * this is what we will return to user, but we need to - * move on first so next call has something fresh to test - */ - iterator->this_arg_index = iterator->arg_index; - iterator->this_arg = iterator->arg; - - /* internally move on the size of this arg (using lower nybble from - the table) */ - iterator->arg += rt_sizes[iterator->arg_index] & 0x0f; - - /* - * check for insanity where we are given a bitmap that - * claims to have more arg content than the length of the - * radiotap section. We will normally end up equalling this - * max_length on the last arg, never exceeding it. - */ - if ((((void *)iterator->arg) - ((void *)iterator->rtheader)) > iterator->max_length) - return -1; - } + /* internally move on the size of this arg (using lower nybble from + the table) */ + iterator->arg += rt_sizes[iterator->arg_index] & 0x0f; - /* Now, move on to next bit / next entry */ - iterator->arg_index++; + /* + * check for insanity where we are given a bitmap that + * claims to have more arg content than the length of the + * radiotap section. We will normally end up equalling this + * max_length on the last arg, never exceeding it. + */ + if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) > + iterator->max_length) + return -1; + } - if (0 == (iterator->arg_index % 32)) - { - /* completed current uint32_t bitmap */ - if (0 != (iterator->bitmap_shifter & 1)) - { - /* bit 31 was set, there is more; move to next uint32_t bitmap */ - iterator->bitmap_shifter = GNUNET_le32toh(*iterator->next_bitmap); - iterator->next_bitmap++; - } - else - { - /* no more bitmaps: end (by setting arg_index to high, unsupported value) */ - iterator->arg_index = sizeof(rt_sizes); - } - } - else - { - /* just try the next bit (while loop will move on) */ - iterator->bitmap_shifter >>= 1; - } + /* Now, move on to next bit / next entry */ + iterator->arg_index++; - /* if we found a valid arg earlier, return it now */ - if (hit) - return iterator->this_arg_index; + if (0 == (iterator->arg_index % 32)) + { + /* completed current uint32_t bitmap */ + if (0 != (iterator->bitmap_shifter & 1)) + { + /* bit 31 was set, there is more; move to next uint32_t bitmap */ + iterator->bitmap_shifter = GNUNET_le32toh (*iterator->next_bitmap); + iterator->next_bitmap++; + } + else + { + /* no more bitmaps: end (by setting arg_index to high, unsupported value) */ + iterator->arg_index = sizeof(rt_sizes); + } + } + else + { + /* just try the next bit (while loop will move on) */ + iterator->bitmap_shifter >>= 1; } + /* if we found a valid arg earlier, return it now */ + if (hit) + return iterator->this_arg_index; + } + /* we don't know how to handle any more args (or there are no more), so we're done (this is not an error) */ return -1; @@ -1251,7 +1273,7 @@ ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterato * @return crc sum */ static unsigned long -calc_crc_osdep(const unsigned char *buf, size_t len) +calc_crc_osdep (const unsigned char *buf, size_t len) { static const unsigned long int crc_tbl_osdep[256] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, @@ -1337,14 +1359,14 @@ calc_crc_osdep(const unsigned char *buf, size_t len) * @return 0 on success (checksum matches), 1 on error */ static int -check_crc_buf_osdep(const unsigned char *buf, size_t len) +check_crc_buf_osdep (const unsigned char *buf, size_t len) { unsigned long crc; - crc = calc_crc_osdep(buf, len); + crc = calc_crc_osdep (buf, len); buf += len; - if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && - ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]) + if ((((crc) & 0xFF) == buf[0])&&(((crc >> 8) & 0xFF) == buf[1])&& + ( ((crc >> 16) & 0xFF) == buf[2]) &&( ((crc >> 24) & 0xFF) == buf[3]) ) return 0; return 1; } @@ -1362,13 +1384,13 @@ check_crc_buf_osdep(const unsigned char *buf, size_t len) * @return number of the channel */ static int -get_channel_from_frequency(int32_t frequency) +get_channel_from_frequency (int32_t frequency) { - if (frequency >= 2412 && frequency <= 2472) + if ((frequency >= 2412)&&(frequency <= 2472)) return (frequency - 2407) / 5; if (frequency == 2484) return 14; - if (frequency >= 5000 && frequency <= 6100) + if ((frequency >= 5000)&&(frequency <= 6100)) return (frequency - 5000) / 5; return -1; } @@ -1381,14 +1403,14 @@ get_channel_from_frequency(int32_t frequency) * @return channel number, -1 on error */ static int -linux_get_channel(const struct HardwareInfos *dev) +linux_get_channel (const struct HardwareInfos *dev) { struct iwreq wrq; int32_t frequency; - memset(&wrq, 0, sizeof(struct iwreq)); - strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ); - if (0 > ioctl(dev->fd_raw, SIOCGIWFREQ, &wrq)) + memset (&wrq, 0, sizeof(struct iwreq)); + strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ); + if (0 > ioctl (dev->fd_raw, SIOCGIWFREQ, &wrq)) return -1; frequency = wrq.u.freq.m; /* 'iw_freq' defines 'm' as '__s32', so we keep it signed */ if (100000000 < frequency) @@ -1396,7 +1418,7 @@ linux_get_channel(const struct HardwareInfos *dev) else if (1000000 < frequency) frequency /= 1000; if (1000 < frequency) - return get_channel_from_frequency(frequency); + return get_channel_from_frequency (frequency); return frequency; } @@ -1413,9 +1435,9 @@ linux_get_channel(const struct HardwareInfos *dev) * @return number of bytes written to 'buf' */ static ssize_t -linux_read(struct HardwareInfos *dev, - unsigned char *buf, size_t buf_size, - struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) +linux_read (struct HardwareInfos *dev, + unsigned char *buf, size_t buf_size, + struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) { unsigned char tmpbuf[buf_size]; ssize_t caplen; @@ -1425,207 +1447,210 @@ linux_read(struct HardwareInfos *dev, int got_channel = 0; int fcs_removed = 0; - caplen = read(dev->fd_raw, tmpbuf, buf_size); + caplen = read (dev->fd_raw, tmpbuf, buf_size); if (0 > caplen) - { - if (EAGAIN == errno) - return 0; - fprintf(stderr, "Failed to read from RAW socket: %s\n", strerror(errno)); - return -1; - } + { + if (EAGAIN == errno) + return 0; + fprintf (stderr, "Failed to read from RAW socket: %s\n", strerror (errno)); + return -1; + } - memset(ri, 0, sizeof(*ri)); + memset (ri, 0, sizeof(*ri)); switch (dev->arptype_in) - { - case ARPHRD_IEEE80211_PRISM: + { + case ARPHRD_IEEE80211_PRISM: { const struct PrismHeader *ph; - ph = (const struct PrismHeader*)tmpbuf; + ph = (const struct PrismHeader*) tmpbuf; n = ph->msglen; if ((n < 8) || (n >= caplen)) return 0; /* invalid format */ if ((PRISM_MSGCODE_MONITOR == ph->msgcode) && (n >= sizeof(struct PrismHeader))) + { + const char *pos; + size_t left; + struct PrismValue pv; + + left = n - sizeof(struct PrismHeader); + pos = (const char *) &ph[1]; + while (left > sizeof(struct PrismValue)) { - const char *pos; - size_t left; - struct PrismValue pv; + left -= sizeof(struct PrismValue); + GNUNET_memcpy (&pv, pos, sizeof(struct PrismValue)); + pos += sizeof(struct PrismValue); + + switch (pv.did) + { + case PRISM_DID_NOISE: + if (PRISM_STATUS_OK == pv.status) + { + ri->ri_noise = pv.data; + /* got_noise = 1; */ + } + break; + + case PRISM_DID_RATE: + if (PRISM_STATUS_OK == pv.status) + ri->ri_rate = pv.data * 500000; + break; + + case PRISM_DID_CHANNEL: + if (PRISM_STATUS_OK == pv.status) + { + ri->ri_channel = pv.data; + got_channel = 1; + } + break; + + case PRISM_DID_MACTIME: + if (PRISM_STATUS_OK == pv.status) + ri->ri_mactime = pv.data; + break; - left = n - sizeof(struct PrismHeader); - pos = (const char *)&ph[1]; - while (left > sizeof(struct PrismValue)) + case PRISM_DID_SIGNAL: + if (PRISM_STATUS_OK == pv.status) { - left -= sizeof(struct PrismValue); - GNUNET_memcpy(&pv, pos, sizeof(struct PrismValue)); - pos += sizeof(struct PrismValue); - - switch (pv.did) - { - case PRISM_DID_NOISE: - if (PRISM_STATUS_OK == pv.status) - { - ri->ri_noise = pv.data; - /* got_noise = 1; */ - } - break; - - case PRISM_DID_RATE: - if (PRISM_STATUS_OK == pv.status) - ri->ri_rate = pv.data * 500000; - break; - - case PRISM_DID_CHANNEL: - if (PRISM_STATUS_OK == pv.status) - { - ri->ri_channel = pv.data; - got_channel = 1; - } - break; - - case PRISM_DID_MACTIME: - if (PRISM_STATUS_OK == pv.status) - ri->ri_mactime = pv.data; - break; - - case PRISM_DID_SIGNAL: - if (PRISM_STATUS_OK == pv.status) - { - ri->ri_power = pv.data; - /* got_signal = 1; */ - } - break; - } + ri->ri_power = pv.data; + /* got_signal = 1; */ } + break; + } } + } if ((n < 8) || (n >= caplen)) return 0; /* invalid format */ } break; - case ARPHRD_IEEE80211_FULL: + case ARPHRD_IEEE80211_FULL: { struct Ieee80211RadiotapHeaderIterator iterator; struct Ieee80211RadiotapHeader *rthdr; - memset(&iterator, 0, sizeof(iterator)); - rthdr = (struct Ieee80211RadiotapHeader *)tmpbuf; - n = GNUNET_le16toh(rthdr->it_len); + memset (&iterator, 0, sizeof(iterator)); + rthdr = (struct Ieee80211RadiotapHeader *) tmpbuf; + n = GNUNET_le16toh (rthdr->it_len); if ((n < sizeof(struct Ieee80211RadiotapHeader)) || (n >= caplen)) return 0; /* invalid 'it_len' */ - if (0 != ieee80211_radiotap_iterator_init(&iterator, rthdr, caplen)) + if (0 != ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen)) return 0; /* go through the radiotap arguments we have been given by the driver */ - while (0 <= ieee80211_radiotap_iterator_next(&iterator)) + while (0 <= ieee80211_radiotap_iterator_next (&iterator)) + { + switch (iterator.this_arg_index) { - switch (iterator.this_arg_index) - { - case IEEE80211_RADIOTAP_TSFT: - ri->ri_mactime = GNUNET_le64toh(*((uint64_t *)iterator.this_arg)); - break; - - case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: - if (!got_signal) - { - ri->ri_power = *((int8_t*)iterator.this_arg); - got_signal = 1; - } - break; - - case IEEE80211_RADIOTAP_DB_ANTSIGNAL: - if (!got_signal) - { - ri->ri_power = *((int8_t*)iterator.this_arg); - got_signal = 1; - } - break; - - case IEEE80211_RADIOTAP_DBM_ANTNOISE: - if (!got_noise) - { - ri->ri_noise = *((int8_t*)iterator.this_arg); - got_noise = 1; - } - break; - - case IEEE80211_RADIOTAP_DB_ANTNOISE: - if (!got_noise) - { - ri->ri_noise = *((int8_t*)iterator.this_arg); - got_noise = 1; - } - break; - - case IEEE80211_RADIOTAP_ANTENNA: - ri->ri_antenna = *iterator.this_arg; - break; - - case IEEE80211_RADIOTAP_CHANNEL: - ri->ri_channel = *iterator.this_arg; - got_channel = 1; - break; + case IEEE80211_RADIOTAP_TSFT: + ri->ri_mactime = GNUNET_le64toh (*((uint64_t *) iterator.this_arg)); + break; - case IEEE80211_RADIOTAP_RATE: - ri->ri_rate = (*iterator.this_arg) * 500000; - break; + case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: + if (! got_signal) + { + ri->ri_power = *((int8_t*) iterator.this_arg); + got_signal = 1; + } + break; - case IEEE80211_RADIOTAP_FLAGS: - { - uint8_t flags = *iterator.this_arg; - /* is the CRC visible at the end? if so, remove */ - if (0 != (flags & IEEE80211_RADIOTAP_F_FCS)) - { - fcs_removed = 1; - caplen -= sizeof(uint32_t); - } - break; - } + case IEEE80211_RADIOTAP_DB_ANTSIGNAL: + if (! got_signal) + { + ri->ri_power = *((int8_t*) iterator.this_arg); + got_signal = 1; + } + break; + + case IEEE80211_RADIOTAP_DBM_ANTNOISE: + if (! got_noise) + { + ri->ri_noise = *((int8_t*) iterator.this_arg); + got_noise = 1; + } + break; + + case IEEE80211_RADIOTAP_DB_ANTNOISE: + if (! got_noise) + { + ri->ri_noise = *((int8_t*) iterator.this_arg); + got_noise = 1; + } + break; - case IEEE80211_RADIOTAP_RX_FLAGS: + case IEEE80211_RADIOTAP_ANTENNA: + ri->ri_antenna = *iterator.this_arg; + break; + + case IEEE80211_RADIOTAP_CHANNEL: + ri->ri_channel = *iterator.this_arg; + got_channel = 1; + break; + + case IEEE80211_RADIOTAP_RATE: + ri->ri_rate = (*iterator.this_arg) * 500000; + break; + + case IEEE80211_RADIOTAP_FLAGS: + { + uint8_t flags = *iterator.this_arg; + /* is the CRC visible at the end? if so, remove */ + if (0 != (flags & IEEE80211_RADIOTAP_F_FCS)) { - uint16_t flags = ntohs(*((uint16_t *)iterator.this_arg)); - if (0 != (flags & IEEE80211_RADIOTAP_F_RX_BADFCS)) - return 0; + fcs_removed = 1; + caplen -= sizeof(uint32_t); } break; - } /* end of 'switch' */ - } /* end of the 'while' loop */ + } + + case IEEE80211_RADIOTAP_RX_FLAGS: + { + uint16_t flags = ntohs (*((uint16_t *) iterator.this_arg)); + if (0 != (flags & IEEE80211_RADIOTAP_F_RX_BADFCS)) + return 0; + } + break; + } /* end of 'switch' */ + } /* end of the 'while' loop */ } break; - case ARPHRD_IEEE80211: - n = 0; /* no header */ - break; + case ARPHRD_IEEE80211: + n = 0; /* no header */ + break; - case ARPHRD_ETHER: + case ARPHRD_ETHER: { if (sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) > caplen) return 0; /* invalid */ - GNUNET_memcpy(&buf[sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)], - tmpbuf + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame), - caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4 /* 4 byte FCS */); + GNUNET_memcpy (&buf[sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)], + tmpbuf + sizeof(struct + GNUNET_TRANSPORT_WLAN_Ieee8023Frame), + caplen - sizeof(struct + GNUNET_TRANSPORT_WLAN_Ieee8023Frame) + - 4 /* 4 byte FCS */); return caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4; } - default: - errno = ENOTSUP; /* unsupported format */ - return -1; - } + default: + errno = ENOTSUP; /* unsupported format */ + return -1; + } caplen -= n; - if (!got_channel) - ri->ri_channel = linux_get_channel(dev); + if (! got_channel) + ri->ri_channel = linux_get_channel (dev); /* detect CRC32 at the end, even if the flag wasn't set and remove it */ if ((0 == fcs_removed) && - (0 == check_crc_buf_osdep(tmpbuf + n, caplen - sizeof(uint32_t)))) - { - /* NOTE: this heuristic can of course fail if there happens to - be a matching checksum at the end. Would be good to have - some data to see how often this heuristic actually works. */ - caplen -= sizeof(uint32_t); - } + (0 == check_crc_buf_osdep (tmpbuf + n, caplen - sizeof(uint32_t)))) + { + /* NOTE: this heuristic can of course fail if there happens to + be a matching checksum at the end. Would be good to have + some data to see how often this heuristic actually works. */ + caplen -= sizeof(uint32_t); + } /* copy payload to target buffer */ - GNUNET_memcpy(buf, tmpbuf + n, caplen); + GNUNET_memcpy (buf, tmpbuf + n, caplen); return caplen; } @@ -1642,7 +1667,7 @@ linux_read(struct HardwareInfos *dev, * @return 0 on success */ static int -open_device_raw(struct HardwareInfos *dev) +open_device_raw (struct HardwareInfos *dev) { struct ifreq ifr; struct iwreq wrq; @@ -1650,112 +1675,114 @@ open_device_raw(struct HardwareInfos *dev) struct sockaddr_ll sll; /* find the interface index */ - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, dev->iface, IFNAMSIZ); - if (-1 == ioctl(dev->fd_raw, SIOCGIFINDEX, &ifr)) - { - fprintf(stderr, "ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n", - IFNAMSIZ, dev->iface, strerror(errno)); - return 1; - } + memset (&ifr, 0, sizeof(ifr)); + strncpy (ifr.ifr_name, dev->iface, IFNAMSIZ); + if (-1 == ioctl (dev->fd_raw, SIOCGIFINDEX, &ifr)) + { + fprintf (stderr, "ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n", + IFNAMSIZ, dev->iface, strerror (errno)); + return 1; + } /* lookup the hardware type */ - memset(&sll, 0, sizeof(sll)); + memset (&sll, 0, sizeof(sll)); sll.sll_family = AF_PACKET; sll.sll_ifindex = ifr.ifr_ifindex; - sll.sll_protocol = htons(ETH_P_ALL); - if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr)) - { - fprintf(stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", - IFNAMSIZ, dev->iface, strerror(errno)); - return 1; - } + sll.sll_protocol = htons (ETH_P_ALL); + if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr)) + { + fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", + IFNAMSIZ, dev->iface, strerror (errno)); + return 1; + } if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) && (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL))) - { - fprintf(stderr, "Error: interface `%.*s' is not using a supported hardware address family (got %d)\n", - IFNAMSIZ, dev->iface, - ifr.ifr_hwaddr.sa_family); - return 1; - } + { + fprintf (stderr, + "Error: interface `%.*s' is not using a supported hardware address family (got %d)\n", + IFNAMSIZ, dev->iface, + ifr.ifr_hwaddr.sa_family); + return 1; + } /* lookup iw mode */ - memset(&wrq, 0, sizeof(struct iwreq)); - strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ); - if (-1 == ioctl(dev->fd_raw, SIOCGIWMODE, &wrq)) - { - /* most probably not supported (ie for rtap ipw interface) * - * so just assume its correctly set... */ - wrq.u.mode = IW_MODE_MONITOR; - } + memset (&wrq, 0, sizeof(struct iwreq)); + strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ); + if (-1 == ioctl (dev->fd_raw, SIOCGIWMODE, &wrq)) + { + /* most probably not supported (ie for rtap ipw interface) * + * so just assume its correctly set... */ + wrq.u.mode = IW_MODE_MONITOR; + } if ((wrq.u.mode != IW_MODE_MONITOR) && (wrq.u.mode != IW_MODE_ADHOC)) - { - fprintf(stderr, "Error: interface `%.*s' is not in monitor or ad-hoc mode (got %d)\n", - IFNAMSIZ, dev->iface, - wrq.u.mode); - return 1; - } + { + fprintf (stderr, + "Error: interface `%.*s' is not in monitor or ad-hoc mode (got %d)\n", + IFNAMSIZ, dev->iface, + wrq.u.mode); + return 1; + } /* Is interface st to up, broadcast & running ? */ if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags) - { - /* Bring interface up */ - ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING; - - if (-1 == ioctl(dev->fd_raw, SIOCSIFFLAGS, &ifr)) - { - fprintf(stderr, "ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n", - IFNAMSIZ, dev->iface, strerror(errno)); - return 1; - } - } + { + /* Bring interface up */ + ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING; - /* bind the raw socket to the interface */ - if (-1 == bind(dev->fd_raw, (struct sockaddr *)&sll, sizeof(sll))) + if (-1 == ioctl (dev->fd_raw, SIOCSIFFLAGS, &ifr)) { - fprintf(stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ, - dev->iface, strerror(errno)); + fprintf (stderr, "ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n", + IFNAMSIZ, dev->iface, strerror (errno)); return 1; } + } + + /* bind the raw socket to the interface */ + if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof(sll))) + { + fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ, + dev->iface, strerror (errno)); + return 1; + } /* lookup the hardware type */ - if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr)) - { - fprintf(stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", - IFNAMSIZ, dev->iface, strerror(errno)); - return 1; - } + if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr)) + { + fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", + IFNAMSIZ, dev->iface, strerror (errno)); + return 1; + } - GNUNET_memcpy(&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE); + GNUNET_memcpy (&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE); dev->arptype_in = ifr.ifr_hwaddr.sa_family; if ((ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) && (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) - { - fprintf(stderr, "Unsupported hardware link type %d on interface `%.*s'\n", - ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface); - return 1; - } + { + fprintf (stderr, "Unsupported hardware link type %d on interface `%.*s'\n", + ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface); + return 1; + } /* enable promiscuous mode */ - memset(&mr, 0, sizeof(mr)); + memset (&mr, 0, sizeof(mr)); mr.mr_ifindex = sll.sll_ifindex; mr.mr_type = PACKET_MR_PROMISC; if (0 != - setsockopt(dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, - sizeof(mr))) - { - fprintf(stderr, - "Failed to enable promiscuous mode on interface `%.*s'\n", - IFNAMSIZ, - dev->iface); - return 1; - } + setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, + sizeof(mr))) + { + fprintf (stderr, + "Failed to enable promiscuous mode on interface `%.*s'\n", + IFNAMSIZ, + dev->iface); + return 1; + } return 0; } @@ -1768,22 +1795,22 @@ open_device_raw(struct HardwareInfos *dev) * @return 0 on success, 1 on error */ static int -test_wlan_interface(const char *iface) +test_wlan_interface (const char *iface) { char strbuf[512]; struct stat sbuf; int ret; - ret = snprintf(strbuf, sizeof(strbuf), - "/sys/class/net/%s/phy80211/subsystem", - iface); - if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat(strbuf, &sbuf))) - { - fprintf(stderr, - "Did not find 802.11 interface `%s'. Exiting.\n", - iface); - exit(1); - } + ret = snprintf (strbuf, sizeof(strbuf), + "/sys/class/net/%s/phy80211/subsystem", + iface); + if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat (strbuf, &sbuf))) + { + fprintf (stderr, + "Did not find 802.11 interface `%s'. Exiting.\n", + iface); + exit (1); + } return 0; } @@ -1796,19 +1823,19 @@ test_wlan_interface(const char *iface) * @return 0 if mac belongs to us, 1 if mac is for another target */ static int -mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, - const struct HardwareInfos *dev) +mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, + const struct HardwareInfos *dev) { static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros; - if ((0 == memcmp(&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) || - (0 == memcmp(&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE))) + if ((0 == memcmp (&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) || + (0 == memcmp (&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE))) return 0; /* some drivers set no Macs, then assume it is all for us! */ - if (0 != memcmp(&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE)) + if (0 != memcmp (&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE)) return 1; /* not a GNUnet ad-hoc package */ - if ((0 == memcmp(&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) || - (0 == memcmp(&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE))) + if ((0 == memcmp (&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) || + (0 == memcmp (&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE))) return 0; /* for us, or broadcast */ return 1; /* not for us */ } @@ -1821,10 +1848,10 @@ mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, * @param dev pointer to the Hardware_Infos struct */ static void -mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, - const struct HardwareInfos *dev) +mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, + const struct HardwareInfos *dev) { - taIeeeHeader->frame_control = htons(IEEE80211_FC0_TYPE_DATA); + taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA); taIeeeHeader->addr2 = dev->pl_mac; taIeeeHeader->addr3 = mac_bssid_gnunet; } @@ -1839,7 +1866,7 @@ mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, * @param hdr pointer to the start of the packet */ static void -stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr) +stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) { struct HardwareInfos *dev = cls; const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header; @@ -1848,58 +1875,67 @@ stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr) struct RadiotapTransmissionHeader rtheader; struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame etheader; - sendsize = ntohs(hdr->size); + sendsize = ntohs (hdr->size); if ((sendsize < sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) || - (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type))) - { - fprintf(stderr, "Received malformed message\n"); - exit(1); - } - sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); + (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type))) + { + fprintf (stderr, "Received malformed message\n"); + exit (1); + } + sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); if (MAXLINE < sendsize) - { - fprintf(stderr, "Packet too big for buffer\n"); - exit(1); - } - header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr; + { + fprintf (stderr, "Packet too big for buffer\n"); + exit (1); + } + header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; switch (dev->arptype_in) - { - case ARPHRD_IEEE80211_PRISM: - case ARPHRD_IEEE80211_FULL: - case ARPHRD_IEEE80211: - rtheader.header.it_version = 0; - rtheader.header.it_pad = 0; - rtheader.header.it_len = GNUNET_htole16(sizeof(rtheader)); - rtheader.header.it_present = GNUNET_htole16(IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK); - rtheader.rate = header->rate; - rtheader.pad1 = 0; - rtheader.txflags = GNUNET_htole16(IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ); - GNUNET_memcpy(write_pout.buf, &rtheader, sizeof(rtheader)); - GNUNET_memcpy(&write_pout.buf[sizeof(rtheader)], &header->frame, sendsize); - wlanheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)&write_pout.buf[sizeof(rtheader)]; - - /* payload contains MAC address, but we don't trust it, so we'll - * overwrite it with OUR MAC address to prevent mischief */ - mac_set(wlanheader, dev); - write_pout.size = sendsize + sizeof(rtheader); - break; + { + case ARPHRD_IEEE80211_PRISM: + case ARPHRD_IEEE80211_FULL: + case ARPHRD_IEEE80211: + rtheader.header.it_version = 0; + rtheader.header.it_pad = 0; + rtheader.header.it_len = GNUNET_htole16 (sizeof(rtheader)); + rtheader.header.it_present = GNUNET_htole16 ( + IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK); + rtheader.rate = header->rate; + rtheader.pad1 = 0; + rtheader.txflags = GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK + | IEEE80211_RADIOTAP_F_TX_NOSEQ); + GNUNET_memcpy (write_pout.buf, &rtheader, sizeof(rtheader)); + GNUNET_memcpy (&write_pout.buf[sizeof(rtheader)], &header->frame, sendsize); + wlanheader = (struct + GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &write_pout.buf[sizeof( + rtheader) + ]; + + /* payload contains MAC address, but we don't trust it, so we'll + * overwrite it with OUR MAC address to prevent mischief */ + mac_set (wlanheader, dev); + write_pout.size = sendsize + sizeof(rtheader); + break; - case ARPHRD_ETHER: - etheader.dst = header->frame.addr1; - /* etheader.src = header->frame.addr2; --- untrusted input */ - etheader.src = dev->pl_mac; - etheader.type = htons(ETH_P_IP); - GNUNET_memcpy(write_pout.buf, ðeader, sizeof(etheader)); - GNUNET_memcpy(&write_pout.buf[sizeof(etheader)], &header[1], sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); - write_pout.size = sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame) + sizeof(etheader); - break; + case ARPHRD_ETHER: + etheader.dst = header->frame.addr1; + /* etheader.src = header->frame.addr2; --- untrusted input */ + etheader.src = dev->pl_mac; + etheader.type = htons (ETH_P_IP); + GNUNET_memcpy (write_pout.buf, ðeader, sizeof(etheader)); + GNUNET_memcpy (&write_pout.buf[sizeof(etheader)], &header[1], sendsize + - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); + write_pout.size = sendsize - sizeof(struct + GNUNET_TRANSPORT_WLAN_Ieee80211Frame) + + sizeof(etheader); + break; - default: - fprintf(stderr, - "Unsupported ARPTYPE!\n"); - break; - } + default: + fprintf (stderr, + "Unsupported ARPTYPE!\n"); + break; + } } @@ -1914,7 +1950,7 @@ stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr) * @return 0 on success (never happens, as we don't return unless aborted), 1 on error */ int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { struct HardwareInfos dev; char readbuf[MAXLINE]; @@ -1928,83 +1964,83 @@ main(int argc, char *argv[]) /* assert privs so we can modify the firewall rules! */ { #ifdef HAVE_SETRESUID - uid_t uid = getuid(); + uid_t uid = getuid (); - if (0 != setresuid(uid, 0, 0)) - { - fprintf(stderr, - "Failed to setresuid to root: %s\n", - strerror(errno)); - return 254; - } + if (0 != setresuid (uid, 0, 0)) + { + fprintf (stderr, + "Failed to setresuid to root: %s\n", + strerror (errno)); + return 254; + } #else - if (0 != seteuid(0)) - { - fprintf(stderr, - "Failed to seteuid back to root: %s\n", strerror(errno)); - return 254; - } + if (0 != seteuid (0)) + { + fprintf (stderr, + "Failed to seteuid back to root: %s\n", strerror (errno)); + return 254; + } #endif } /* make use of SGID capabilities on POSIX */ - memset(&dev, 0, sizeof(dev)); - dev.fd_raw = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); + memset (&dev, 0, sizeof(dev)); + dev.fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL)); raw_eno = errno; /* remember for later */ /* now that we've dropped root rights, we can do error checking */ if (2 != argc) - { - fprintf(stderr, - "You must specify the name of the interface as the first and only argument to this program.\n"); - if (-1 != dev.fd_raw) - (void)close(dev.fd_raw); - return 1; - } + { + fprintf (stderr, + "You must specify the name of the interface as the first and only argument to this program.\n"); + if (-1 != dev.fd_raw) + (void) close (dev.fd_raw); + return 1; + } if (-1 == dev.fd_raw) - { - fprintf(stderr, "Failed to create raw socket: %s\n", strerror(raw_eno)); - return 1; - } + { + fprintf (stderr, "Failed to create raw socket: %s\n", strerror (raw_eno)); + return 1; + } if (dev.fd_raw >= FD_SETSIZE) + { + fprintf (stderr, "File descriptor too large for select (%d > %d)\n", + dev.fd_raw, FD_SETSIZE); + (void) close (dev.fd_raw); + return 1; + } + if (0 != test_wlan_interface (argv[1])) + { + (void) close (dev.fd_raw); + return 1; + } + strncpy (dev.iface, argv[1], IFNAMSIZ); + if (0 != open_device_raw (&dev)) + { + (void) close (dev.fd_raw); + return 1; + } + + /* drop privs */ + { + uid_t uid = getuid (); +#ifdef HAVE_SETRESUID + if (0 != setresuid (uid, uid, uid)) { - fprintf(stderr, "File descriptor too large for select (%d > %d)\n", - dev.fd_raw, FD_SETSIZE); - (void)close(dev.fd_raw); - return 1; - } - if (0 != test_wlan_interface(argv[1])) - { - (void)close(dev.fd_raw); + fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); + if (-1 != dev.fd_raw) + (void) close (dev.fd_raw); return 1; } - strncpy(dev.iface, argv[1], IFNAMSIZ); - if (0 != open_device_raw(&dev)) +#else + if (0 != (setuid (uid) | seteuid (uid))) { - (void)close(dev.fd_raw); + fprintf (stderr, "Failed to setuid: %s\n", strerror (errno)); + if (-1 != dev.fd_raw) + (void) close (dev.fd_raw); return 1; } - - /* drop privs */ - { - uid_t uid = getuid(); -#ifdef HAVE_SETRESUID - if (0 != setresuid(uid, uid, uid)) - { - fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno)); - if (-1 != dev.fd_raw) - (void)close(dev.fd_raw); - return 1; - } -#else - if (0 != (setuid(uid) | seteuid(uid))) - { - fprintf(stderr, "Failed to setuid: %s\n", strerror(errno)); - if (-1 != dev.fd_raw) - (void)close(dev.fd_raw); - return 1; - } #endif } @@ -2013,141 +2049,145 @@ main(int argc, char *argv[]) { struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; - macmsg.hdr.size = htons(sizeof(macmsg)); - macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); - GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)); - GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg)); + macmsg.hdr.size = htons (sizeof(macmsg)); + macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); + GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof(struct + GNUNET_TRANSPORT_WLAN_MacAddress)); + GNUNET_memcpy (write_std.buf, &macmsg, sizeof(macmsg)); write_std.size = sizeof(macmsg); } - stdin_mst = mst_create(&stdin_send_hw, &dev); + stdin_mst = mst_create (&stdin_send_hw, &dev); stdin_open = 1; while (1) + { + maxfd = -1; + FD_ZERO (&rfds); + if ((0 == write_pout.size) && (1 == stdin_open)) { - maxfd = -1; - FD_ZERO(&rfds); - if ((0 == write_pout.size) && (1 == stdin_open)) - { - FD_SET(STDIN_FILENO, &rfds); - maxfd = MAX(maxfd, STDIN_FILENO); - } - if (0 == write_std.size) - { - FD_SET(dev.fd_raw, &rfds); - maxfd = MAX(maxfd, dev.fd_raw); - } - FD_ZERO(&wfds); - if (0 < write_std.size) - { - FD_SET(STDOUT_FILENO, &wfds); - maxfd = MAX(maxfd, STDOUT_FILENO); - } - if (0 < write_pout.size) - { - FD_SET(dev.fd_raw, &wfds); - maxfd = MAX(maxfd, dev.fd_raw); - } + FD_SET (STDIN_FILENO, &rfds); + maxfd = MAX (maxfd, STDIN_FILENO); + } + if (0 == write_std.size) + { + FD_SET (dev.fd_raw, &rfds); + maxfd = MAX (maxfd, dev.fd_raw); + } + FD_ZERO (&wfds); + if (0 < write_std.size) + { + FD_SET (STDOUT_FILENO, &wfds); + maxfd = MAX (maxfd, STDOUT_FILENO); + } + if (0 < write_pout.size) + { + FD_SET (dev.fd_raw, &wfds); + maxfd = MAX (maxfd, dev.fd_raw); + } + { + int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL); + if ((-1 == retval) && (EINTR == errno)) + continue; + if (0 > retval) { - int retval = select(maxfd + 1, &rfds, &wfds, NULL, NULL); - if ((-1 == retval) && (EINTR == errno)) - continue; - if (0 > retval) - { - fprintf(stderr, "select failed: %s\n", strerror(errno)); - break; - } + fprintf (stderr, "select failed: %s\n", strerror (errno)); + break; } - if (FD_ISSET(STDOUT_FILENO, &wfds)) - { - ssize_t ret = - write(STDOUT_FILENO, write_std.buf + write_std.pos, - write_std.size - write_std.pos); - if (0 > ret) - { - fprintf(stderr, "Failed to write to STDOUT: %s\n", strerror(errno)); - break; - } - write_std.pos += ret; - if (write_std.pos == write_std.size) - { - write_std.pos = 0; - write_std.size = 0; - } - } - if (FD_ISSET(dev.fd_raw, &wfds)) - { - ssize_t ret = - write(dev.fd_raw, write_pout.buf + write_pout.pos, - write_pout.size - write_pout.pos); - if (0 > ret) - { - fprintf(stderr, "Failed to write to WLAN device: %s\n", - strerror(errno)); - break; - } - write_pout.pos += ret; - if ((write_pout.pos != write_pout.size) && (0 != ret)) - { - /* we should not get partial sends with packet-oriented devices... */ - fprintf(stderr, "Write error, partial send: %u/%u\n", - (unsigned int)write_pout.pos, - (unsigned int)write_pout.size); - break; - } - if (write_pout.pos == write_pout.size) - { - write_pout.pos = 0; - write_pout.size = 0; - } - } + } + if (FD_ISSET (STDOUT_FILENO, &wfds)) + { + ssize_t ret = + write (STDOUT_FILENO, write_std.buf + write_std.pos, + write_std.size - write_std.pos); + if (0 > ret) + { + fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno)); + break; + } + write_std.pos += ret; + if (write_std.pos == write_std.size) + { + write_std.pos = 0; + write_std.size = 0; + } + } + if (FD_ISSET (dev.fd_raw, &wfds)) + { + ssize_t ret = + write (dev.fd_raw, write_pout.buf + write_pout.pos, + write_pout.size - write_pout.pos); + if (0 > ret) + { + fprintf (stderr, "Failed to write to WLAN device: %s\n", + strerror (errno)); + break; + } + write_pout.pos += ret; + if ((write_pout.pos != write_pout.size) && (0 != ret)) + { + /* we should not get partial sends with packet-oriented devices... */ + fprintf (stderr, "Write error, partial send: %u/%u\n", + (unsigned int) write_pout.pos, + (unsigned int) write_pout.size); + break; + } + if (write_pout.pos == write_pout.size) + { + write_pout.pos = 0; + write_pout.size = 0; + } + } - if (FD_ISSET(STDIN_FILENO, &rfds)) - { - ssize_t ret = - read(STDIN_FILENO, readbuf, sizeof(readbuf)); - if (0 > ret) - { - fprintf(stderr, "Read error from STDIN: %s\n", strerror(errno)); - break; - } - if (0 == ret) - { - /* stop reading... */ - stdin_open = 0; - } - mst_receive(stdin_mst, readbuf, ret); - } + if (FD_ISSET (STDIN_FILENO, &rfds)) + { + ssize_t ret = + read (STDIN_FILENO, readbuf, sizeof(readbuf)); + if (0 > ret) + { + fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno)); + break; + } + if (0 == ret) + { + /* stop reading... */ + stdin_open = 0; + } + mst_receive (stdin_mst, readbuf, ret); + } - if (FD_ISSET(dev.fd_raw, &rfds)) - { - struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm; - ssize_t ret; - - rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf; - ret = - linux_read(&dev, (unsigned char *)&rrm->frame, - sizeof(write_std.buf) - - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) - + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame), - rrm); - if (0 > ret) - { - fprintf(stderr, "Read error from raw socket: %s\n", strerror(errno)); - break; - } - if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev))) - { - write_std.size = ret - + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) - - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame); - rrm->header.size = htons(write_std.size); - rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); - } - } + if (FD_ISSET (dev.fd_raw, &rfds)) + { + struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm; + ssize_t ret; + + rrm = (struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf; + ret = + linux_read (&dev, (unsigned char *) &rrm->frame, + sizeof(write_std.buf) + - sizeof(struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame), + rrm); + if (0 > ret) + { + fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno)); + break; + } + if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev))) + { + write_std.size = ret + + sizeof(struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame); + rrm->header.size = htons (write_std.size); + rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); + } } + } /* Error handling, try to clean up a bit at least */ - mst_destroy(stdin_mst); - (void)close(dev.fd_raw); + mst_destroy (stdin_mst); + (void) close (dev.fd_raw); return 1; /* we never exit 'normally' */ } diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index 09e15655f..66a836b84 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c @@ -176,14 +176,14 @@ * the value chosen here might be too aggressively low! */ #define DELAY_WARN_THRESHOLD \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) /** * If a DVBox could not be forwarded after this number of * seconds we drop it. */ #define DV_FORWARD_TIMEOUT \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) /** * We only consider queues as "quality" connections when @@ -191,53 +191,53 @@ * the latency of the queue is below this threshold. */ #define DV_QUALITY_RTT_THRESHOLD \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) /** * How long do we consider a DV path valid if we see no * further updates on it? Note: the value chosen here might be too low! */ #define DV_PATH_VALIDITY_TIMEOUT \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) /** * How long do we cache backchannel (struct Backtalker) information * after a backchannel goes inactive? */ #define BACKCHANNEL_INACTIVITY_TIMEOUT \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) /** * How long before paths expire would we like to (re)discover DV paths? Should * be below #DV_PATH_VALIDITY_TIMEOUT. */ #define DV_PATH_DISCOVERY_FREQUENCY \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 4) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) /** * How long are ephemeral keys valid? */ #define EPHEMERAL_VALIDITY \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) /** * How long do we keep partially reassembled messages around before giving up? */ #define REASSEMBLY_EXPIRATION \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 4) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) /** * What is the fastest rate at which we send challenges *if* we keep learning * an address (gossip, DHT, etc.)? */ #define FAST_VALIDATION_CHALLENGE_FREQ \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) /** * What is the slowest rate at which we send challenges? */ #define MAX_VALIDATION_CHALLENGE_FREQ \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 1) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1) /** * How long until we forget about historic accumulators and thus @@ -245,7 +245,7 @@ * active connection experiences without an ACK. */ #define ACK_CUMMULATOR_TIMEOUT \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) /** * What is the non-randomized base frequency at which we @@ -263,13 +263,13 @@ * When do we forget an invalid address for sure? */ #define MAX_ADDRESS_VALID_UNTIL \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MONTHS, 1) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1) /** * How long do we consider an address valid if we just checked? */ #define ADDRESS_VALIDATION_LIFETIME \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) /** * What is the maximum frequency at which we do address validation? @@ -308,7 +308,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Unique identifier we attach to a message. */ -struct MessageUUIDP { +struct MessageUUIDP +{ /** * Unique value, generated by incrementing the * `message_uuid_ctr` of `struct Neighbour`. @@ -320,7 +321,8 @@ struct MessageUUIDP { /** * Unique identifier to map an acknowledgement to a transmission. */ -struct AcknowledgementUUIDP { +struct AcknowledgementUUIDP +{ /** * The UUID value. */ @@ -331,7 +333,8 @@ struct AcknowledgementUUIDP { /** * Type of a nonce used for challenges. */ -struct ChallengeNonceP { +struct ChallengeNonceP +{ /** * The value of the nonce. Note that this is NOT a hash. */ @@ -342,7 +345,8 @@ struct ChallengeNonceP { /** * Outer layer of an encapsulated backchannel message. */ -struct TransportBackchannelEncapsulationMessage { +struct TransportBackchannelEncapsulationMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION. */ @@ -358,7 +362,8 @@ struct TransportBackchannelEncapsulationMessage { /** * Body by which a peer confirms that it is using an ephemeral key. */ -struct EphemeralConfirmationPS { +struct EphemeralConfirmationPS +{ /** * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL */ @@ -397,7 +402,8 @@ struct EphemeralConfirmationPS { * Plaintext of the variable-size payload that is encrypted * within a `struct TransportBackchannelEncapsulationMessage` */ -struct TransportDVBoxPayloadP { +struct TransportDVBoxPayloadP +{ /** * Sender's peer identity. */ @@ -430,7 +436,8 @@ struct TransportDVBoxPayloadP { * Outer layer of an encapsulated unfragmented application message sent * over an unreliable channel. */ -struct TransportReliabilityBoxMessage { +struct TransportReliabilityBoxMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX */ @@ -456,7 +463,8 @@ struct TransportReliabilityBoxMessage { /** * Acknowledgement payload. */ -struct TransportCummulativeAckPayloadP { +struct TransportCummulativeAckPayloadP +{ /** * How long was the ACK delayed for generating cummulative ACKs? * Used to calculate the correct network RTT by taking the receipt @@ -479,7 +487,8 @@ struct TransportCummulativeAckPayloadP { * so ACKs are identified by a combination of PID of sender and * message UUID, without the queue playing any role! */ -struct TransportReliabilityAckMessage { +struct TransportReliabilityAckMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK */ @@ -499,7 +508,8 @@ struct TransportReliabilityAckMessage { /** * Outer layer of an encapsulated fragmented application message. */ -struct TransportFragmentBoxMessage { +struct TransportFragmentBoxMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT */ @@ -549,7 +559,8 @@ struct TransportFragmentBoxMessage { * potential amplificator will check the @e monotonic_time and only respond * (at most) once per message. */ -struct DvInitPS { +struct DvInitPS +{ /** * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR */ @@ -592,7 +603,8 @@ struct DvInitPS { * replay old messages. Thus, passively learned paths should always be * immediately marked as "potentially stale". */ -struct DvHopPS { +struct DvHopPS +{ /** * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP */ @@ -619,7 +631,8 @@ struct DvHopPS { * An entry describing a peer on a path in a * `struct TransportDVLearnMessage` message. */ -struct DVPathEntryP { +struct DVPathEntryP +{ /** * Identity of a peer on the path. */ @@ -646,7 +659,8 @@ struct DVPathEntryP { * zero, peers that can forward to the initator should always try to * forward to the initiator. */ -struct TransportDVLearnMessage { +struct TransportDVLearnMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN */ @@ -733,7 +747,8 @@ struct TransportDVLearnMessage { * the predecessor must be the origin (so this is not really useful * for anonymization). */ -struct TransportDVBoxMessage { +struct TransportDVBoxMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX */ @@ -791,7 +806,8 @@ struct TransportDVBoxMessage { * Message send to another peer to validate that it can indeed * receive messages at a particular address. */ -struct TransportValidationChallengeMessage { +struct TransportValidationChallengeMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE */ @@ -819,7 +835,8 @@ struct TransportValidationChallengeMessage { * Message signed by a peer to confirm that it can indeed * receive messages at a particular address. */ -struct TransportValidationPS { +struct TransportValidationPS +{ /** * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE */ @@ -842,7 +859,8 @@ struct TransportValidationPS { * Message send to a peer to respond to a * #GNUNET_MESSAGE_TYPE_ADDRESS_VALIDATION_CHALLENGE */ -struct TransportValidationResponseMessage { +struct TransportValidationResponseMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE */ @@ -886,7 +904,8 @@ struct TransportValidationResponseMessage { * send to us, and how much data we already received from the other * peer. */ -struct TransportFlowControlMessage { +struct TransportFlowControlMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL */ @@ -942,7 +961,8 @@ GNUNET_NETWORK_STRUCT_END /** * What type of client is the `struct TransportClient` about? */ -enum ClientType { +enum ClientType +{ /** * We do not know yet (client is fresh). */ @@ -974,7 +994,8 @@ enum ClientType { * Which transmission options are allowable for transmission? * Interpreted bit-wise! */ -enum RouteMessageOptions { +enum RouteMessageOptions +{ /** * Only confirmed, non-DV direct neighbours. */ @@ -1007,7 +1028,8 @@ enum RouteMessageOptions { /** * When did we launch this DV learning activity? */ -struct LearnLaunchEntry { +struct LearnLaunchEntry +{ /** * Kept (also) in a DLL sorted by launch time. */ @@ -1035,7 +1057,8 @@ struct LearnLaunchEntry { * Information we keep per #GOODPUT_AGING_SLOTS about historic * (or current) transmission performance. */ -struct TransmissionHistoryEntry { +struct TransmissionHistoryEntry +{ /** * Number of bytes actually sent in the interval. */ @@ -1052,7 +1075,8 @@ struct TransmissionHistoryEntry { /** * Performance data for a transmission possibility. */ -struct PerformanceData { +struct PerformanceData +{ /** * Weighted average for the RTT. */ @@ -1119,7 +1143,8 @@ struct VirtualLink; * Context from #handle_incoming_msg(). Closure for many * message handlers below. */ -struct CommunicatorMessageContext { +struct CommunicatorMessageContext +{ /** * Kept in a DLL of `struct VirtualLink` if waiting for CORE * flow control to unchoke. @@ -1153,7 +1178,8 @@ struct CommunicatorMessageContext { /** * Closure for #core_env_sent_cb. */ -struct CoreSentContext { +struct CoreSentContext +{ /** * Kept in a DLL to clear @e vl in case @e vl is lost. */ @@ -1192,7 +1218,8 @@ struct CoreSentContext { * data that is per neighbour that is not specific to how the * connectivity is established. */ -struct VirtualLink { +struct VirtualLink +{ /** * Identity of the peer at the other end of the link. */ @@ -1390,7 +1417,8 @@ struct VirtualLink { /** * Data structure kept when we are waiting for an acknowledgement. */ -struct PendingAcknowledgement { +struct PendingAcknowledgement +{ /** * If @e pm is non-NULL, this is the DLL in which this acknowledgement * is kept in relation to its pending message. @@ -1483,7 +1511,8 @@ struct PendingAcknowledgement { /** * One possible hop towards a DV target. */ -struct DistanceVectorHop { +struct DistanceVectorHop +{ /** * Kept in a MDLL, sorted by @e timeout. */ @@ -1564,7 +1593,8 @@ struct DistanceVectorHop { * Entry in our #dv_routes table, representing a (set of) distance * vector routes to a particular peer. */ -struct DistanceVector { +struct DistanceVector +{ /** * To which peer is this a route? */ @@ -1628,7 +1658,8 @@ struct DistanceVector { * what the communicator can actually provide towards a particular * peer/target). */ -struct QueueEntry { +struct QueueEntry +{ /** * Kept as a DLL. */ @@ -1660,7 +1691,8 @@ struct QueueEntry { * A queue is a message queue provided by a communicator * via which we can reach a particular neighbour. */ -struct Queue { +struct Queue +{ /** * Kept in a MDLL. */ @@ -1788,7 +1820,8 @@ struct Queue { /** * Information we keep for a message that we are reassembling. */ -struct ReassemblyContext { +struct ReassemblyContext +{ /** * Original message ID for of the message that all the fragments * belong to. @@ -1846,7 +1879,8 @@ struct ReassemblyContext { /** * A neighbour that at least one communicator is connected to. */ -struct Neighbour { +struct Neighbour +{ /** * Which peer is this about? */ @@ -1929,7 +1963,8 @@ struct Neighbour { * Another peer attempted to talk to us, we should try to establish * a connection in the other direction. */ -struct IncomingRequest { +struct IncomingRequest +{ /** * Kept in a DLL. */ @@ -1955,7 +1990,8 @@ struct IncomingRequest { /** * A peer that an application (client) would like us to talk to directly. */ -struct PeerRequest { +struct PeerRequest +{ /** * Which peer is this about? */ @@ -1988,7 +2024,8 @@ struct PeerRequest { /** * Types of different pending messages. */ -enum PendingMessageType { +enum PendingMessageType +{ /** * Ordinary message received from the CORE service. */ @@ -2037,7 +2074,8 @@ enum PendingMessageType { * is never again transmitted (even if it fits below the MTU), and * only (remaining) fragments are sent. */ -struct PendingMessage { +struct PendingMessage +{ /** * Kept in a MDLL of messages for this @a vl. */ @@ -2176,7 +2214,8 @@ struct PendingMessage { /** * Acknowledgement payload. */ -struct TransportCummulativeAckPayload { +struct TransportCummulativeAckPayload +{ /** * When did we receive the message we are ACKing? Used to calculate * the delay we introduced by cummulating ACKs. @@ -2194,7 +2233,8 @@ struct TransportCummulativeAckPayload { * Data structure in which we track acknowledgements still to * be sent to the */ -struct AcknowledgementCummulator { +struct AcknowledgementCummulator +{ /** * Target peer for which we are accumulating ACKs here. */ @@ -2234,7 +2274,8 @@ struct AcknowledgementCummulator { /** * One of the addresses of this peer. */ -struct AddressListEntry { +struct AddressListEntry +{ /** * Kept in a DLL. */ @@ -2286,7 +2327,8 @@ struct AddressListEntry { /** * Client connected to the transport service. */ -struct TransportClient { +struct TransportClient +{ /** * Kept in a DLL. */ @@ -2312,11 +2354,13 @@ struct TransportClient { */ enum ClientType type; - union { + union + { /** * Information for @e type #CT_CORE. */ - struct { + struct + { /** * Head of list of messages pending for this client, sorted by * transmission time ("next_attempt" + possibly internal prioritization). @@ -2332,7 +2376,8 @@ struct TransportClient { /** * Information for @e type #CT_MONITOR. */ - struct { + struct + { /** * Peer identity to monitor the addresses of. * Zero to monitor all neighbours. Valid if @@ -2350,7 +2395,8 @@ struct TransportClient { /** * Information for @e type #CT_COMMUNICATOR. */ - struct { + struct + { /** * If @e type is #CT_COMMUNICATOR, this communicator * supports communicating using these addresses. @@ -2395,7 +2441,8 @@ struct TransportClient { /** * Information for @e type #CT_APPLICATION */ - struct { + struct + { /** * Map of requests for peers the given client application would like to * see connections for. Maps from PIDs to `struct PeerRequest`. @@ -2410,7 +2457,8 @@ struct TransportClient { * State we keep for validation activities. Each of these * is both in the #validation_heap and the #validation_map. */ -struct ValidationState { +struct ValidationState +{ /** * For which peer is @a address to be validated (or possibly valid)? * Serves as key in the #validation_map. @@ -2520,7 +2568,8 @@ struct ValidationState { * material (to avoid repeatedly checking signatures), and to synchronize * monotonic time with the PEERSTORE. */ -struct Backtalker { +struct Backtalker +{ /** * Peer this is about. */ @@ -2743,11 +2792,11 @@ static struct GNUNET_TIME_Absolute hello_mono_time; * @return current age of the world */ static unsigned int -get_age() +get_age () { struct GNUNET_TIME_Absolute now; - now = GNUNET_TIME_absolute_get(); + now = GNUNET_TIME_absolute_get (); return now.abs_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us / 15; } @@ -2758,13 +2807,13 @@ get_age() * @param ir data structure to release */ static void -free_incoming_request(struct IncomingRequest *ir) +free_incoming_request (struct IncomingRequest *ir) { - GNUNET_CONTAINER_DLL_remove(ir_head, ir_tail, ir); - GNUNET_assert(ir_total > 0); + GNUNET_CONTAINER_DLL_remove (ir_head, ir_tail, ir); + GNUNET_assert (ir_total > 0); ir_total--; - GNUNET_PEERSTORE_watch_cancel(ir->wc); - GNUNET_free(ir); + GNUNET_PEERSTORE_watch_cancel (ir->wc); + GNUNET_free (ir); } @@ -2774,34 +2823,34 @@ free_incoming_request(struct IncomingRequest *ir) * @param pa data structure to release */ static void -free_pending_acknowledgement(struct PendingAcknowledgement *pa) +free_pending_acknowledgement (struct PendingAcknowledgement *pa) { struct Queue *q = pa->queue; struct PendingMessage *pm = pa->pm; struct DistanceVectorHop *dvh = pa->dvh; - GNUNET_CONTAINER_MDLL_remove(pa, pa_head, pa_tail, pa); + GNUNET_CONTAINER_MDLL_remove (pa, pa_head, pa_tail, pa); pa_count--; if (NULL != q) - { - GNUNET_CONTAINER_MDLL_remove(queue, q->pa_head, q->pa_tail, pa); - pa->queue = NULL; - } + { + GNUNET_CONTAINER_MDLL_remove (queue, q->pa_head, q->pa_tail, pa); + pa->queue = NULL; + } if (NULL != pm) - { - GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa); - pa->pm = NULL; - } + { + GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa); + pa->pm = NULL; + } if (NULL != dvh) - { - GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa); - pa->queue = NULL; - } - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multiuuidmap_remove(pending_acks, - &pa->ack_uuid.value, - pa)); - GNUNET_free(pa); + { + GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa); + pa->queue = NULL; + } + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multiuuidmap_remove (pending_acks, + &pa->ack_uuid.value, + pa)); + GNUNET_free (pa); } @@ -2814,23 +2863,23 @@ free_pending_acknowledgement(struct PendingAcknowledgement *pa) * @param root root of the tree to free */ static void -free_fragment_tree(struct PendingMessage *root) +free_fragment_tree (struct PendingMessage *root) { struct PendingMessage *frag; while (NULL != (frag = root->head_frag)) - { - struct PendingAcknowledgement *pa; + { + struct PendingAcknowledgement *pa; - free_fragment_tree(frag); - while (NULL != (pa = frag->pa_head)) - { - GNUNET_CONTAINER_MDLL_remove(pm, frag->pa_head, frag->pa_tail, pa); - pa->pm = NULL; - } - GNUNET_CONTAINER_MDLL_remove(frag, root->head_frag, root->tail_frag, frag); - GNUNET_free(frag); + free_fragment_tree (frag); + while (NULL != (pa = frag->pa_head)) + { + GNUNET_CONTAINER_MDLL_remove (pm, frag->pa_head, frag->pa_tail, pa); + pa->pm = NULL; } + GNUNET_CONTAINER_MDLL_remove (frag, root->head_frag, root->tail_frag, frag); + GNUNET_free (frag); + } } @@ -2842,44 +2891,44 @@ free_fragment_tree(struct PendingMessage *root) * @param pm the pending message to free */ static void -free_pending_message(struct PendingMessage *pm) +free_pending_message (struct PendingMessage *pm) { struct TransportClient *tc = pm->client; struct VirtualLink *vl = pm->vl; struct PendingAcknowledgement *pa; if (NULL != tc) - { - GNUNET_CONTAINER_MDLL_remove(client, - tc->details.core.pending_msg_head, - tc->details.core.pending_msg_tail, - pm); - } + { + GNUNET_CONTAINER_MDLL_remove (client, + tc->details.core.pending_msg_head, + tc->details.core.pending_msg_tail, + pm); + } if (NULL != vl) - { - GNUNET_CONTAINER_MDLL_remove(vl, - vl->pending_msg_head, - vl->pending_msg_tail, - pm); - } + { + GNUNET_CONTAINER_MDLL_remove (vl, + vl->pending_msg_head, + vl->pending_msg_tail, + pm); + } while (NULL != (pa = pm->pa_head)) - { - GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa); - pa->pm = NULL; - } + { + GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa); + pa->pm = NULL; + } - free_fragment_tree(pm); + free_fragment_tree (pm); if (NULL != pm->qe) - { - GNUNET_assert(pm == pm->qe->pm); - pm->qe->pm = NULL; - } + { + GNUNET_assert (pm == pm->qe->pm); + pm->qe->pm = NULL; + } if (NULL != pm->bpm) - { - free_fragment_tree(pm->bpm); - GNUNET_free(pm->bpm); - } - GNUNET_free(pm); + { + free_fragment_tree (pm->bpm); + GNUNET_free (pm->bpm); + } + GNUNET_free (pm); } @@ -2889,34 +2938,34 @@ free_pending_message(struct PendingMessage *pm) * @param vl link data to free */ static void -free_virtual_link(struct VirtualLink *vl) +free_virtual_link (struct VirtualLink *vl) { struct PendingMessage *pm; struct CoreSentContext *csc; while (NULL != (pm = vl->pending_msg_head)) - free_pending_message(pm); - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(links, &vl->target, vl)); + free_pending_message (pm); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (links, &vl->target, vl)); if (NULL != vl->visibility_task) - { - GNUNET_SCHEDULER_cancel(vl->visibility_task); - vl->visibility_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (vl->visibility_task); + vl->visibility_task = NULL; + } if (NULL != vl->fc_retransmit_task) - { - GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task); - vl->fc_retransmit_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); + vl->fc_retransmit_task = NULL; + } while (NULL != (csc = vl->csc_head)) - { - GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, csc); - GNUNET_assert(vl == csc->vl); - csc->vl = NULL; - } - GNUNET_break(NULL == vl->n); - GNUNET_break(NULL == vl->dv); - GNUNET_free(vl); + { + GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, csc); + GNUNET_assert (vl == csc->vl); + csc->vl = NULL; + } + GNUNET_break (NULL == vl->n); + GNUNET_break (NULL == vl->dv); + GNUNET_free (vl); } @@ -2926,20 +2975,20 @@ free_virtual_link(struct VirtualLink *vl) * @param vs validation state to free */ static void -free_validation_state(struct ValidationState *vs) +free_validation_state (struct ValidationState *vs) { - GNUNET_assert( + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(validation_map, &vs->pid, vs)); - GNUNET_CONTAINER_heap_remove_node(vs->hn); + GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs)); + GNUNET_CONTAINER_heap_remove_node (vs->hn); vs->hn = NULL; if (NULL != vs->sc) - { - GNUNET_PEERSTORE_store_cancel(vs->sc); - vs->sc = NULL; - } - GNUNET_free(vs->address); - GNUNET_free(vs); + { + GNUNET_PEERSTORE_store_cancel (vs->sc); + vs->sc = NULL; + } + GNUNET_free (vs->address); + GNUNET_free (vs); } @@ -2950,9 +2999,9 @@ free_validation_state(struct ValidationState *vs) * @return NULL if we do not have this peer as a neighbour */ static struct Neighbour * -lookup_neighbour(const struct GNUNET_PeerIdentity *pid) +lookup_neighbour (const struct GNUNET_PeerIdentity *pid) { - return GNUNET_CONTAINER_multipeermap_get(neighbours, pid); + return GNUNET_CONTAINER_multipeermap_get (neighbours, pid); } @@ -2963,16 +3012,17 @@ lookup_neighbour(const struct GNUNET_PeerIdentity *pid) * @return NULL if we do not have this peer as a virtual link */ static struct VirtualLink * -lookup_virtual_link(const struct GNUNET_PeerIdentity *pid) +lookup_virtual_link (const struct GNUNET_PeerIdentity *pid) { - return GNUNET_CONTAINER_multipeermap_get(links, pid); + return GNUNET_CONTAINER_multipeermap_get (links, pid); } /** * Details about what to notify monitors about. */ -struct MonitorEvent { +struct MonitorEvent +{ /** * @deprecated To be discussed if we keep these... */ @@ -3011,20 +3061,20 @@ struct MonitorEvent { * @param dvh hop to free */ static void -free_distance_vector_hop(struct DistanceVectorHop *dvh) +free_distance_vector_hop (struct DistanceVectorHop *dvh) { struct Neighbour *n = dvh->next_hop; struct DistanceVector *dv = dvh->dv; struct PendingAcknowledgement *pa; while (NULL != (pa = dvh->pa_head)) - { - GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa); - pa->dvh = NULL; - } - GNUNET_CONTAINER_MDLL_remove(neighbour, n->dv_head, n->dv_tail, dvh); - GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, dvh); - GNUNET_free(dvh); + { + GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa); + pa->dvh = NULL; + } + GNUNET_CONTAINER_MDLL_remove (neighbour, n->dv_head, n->dv_tail, dvh); + GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, dvh); + GNUNET_free (dvh); } @@ -3035,7 +3085,7 @@ free_distance_vector_hop(struct DistanceVectorHop *dvh) * @param cls a `struct VirtualLink` */ static void -check_link_down(void *cls); +check_link_down (void *cls); /** @@ -3044,22 +3094,22 @@ check_link_down(void *cls); * @param pid peer the connection was for */ static void -cores_send_disconnect_info(const struct GNUNET_PeerIdentity *pid) +cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Informing CORE clients about disconnect from %s\n", - GNUNET_i2s(pid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Informing CORE clients about disconnect from %s\n", + GNUNET_i2s (pid)); for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - struct GNUNET_MQ_Envelope *env; - struct DisconnectInfoMessage *dim; - - if (CT_CORE != tc->type) - continue; - env = GNUNET_MQ_msg(dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); - dim->peer = *pid; - GNUNET_MQ_send(tc->mq, env); - } + { + struct GNUNET_MQ_Envelope *env; + struct DisconnectInfoMessage *dim; + + if (CT_CORE != tc->type) + continue; + env = GNUNET_MQ_msg (dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); + dim->peer = *pid; + GNUNET_MQ_send (tc->mq, env); + } } @@ -3070,43 +3120,43 @@ cores_send_disconnect_info(const struct GNUNET_PeerIdentity *pid) * @param dv route to free */ static void -free_dv_route(struct DistanceVector *dv) +free_dv_route (struct DistanceVector *dv) { struct DistanceVectorHop *dvh; while (NULL != (dvh = dv->dv_head)) - free_distance_vector_hop(dvh); + free_distance_vector_hop (dvh); if (NULL == dv->dv_head) - { - struct VirtualLink *vl; + { + struct VirtualLink *vl; - GNUNET_assert( - GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(dv_routes, &dv->target, dv)); - if (NULL != (vl = dv->vl)) - { - GNUNET_assert(dv == vl->dv); - vl->dv = NULL; - if (NULL == vl->n) - { - cores_send_disconnect_info(&dv->target); - free_virtual_link(vl); - } - else - { - GNUNET_SCHEDULER_cancel(vl->visibility_task); - vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl); - } - dv->vl = NULL; - } + GNUNET_assert ( + GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv)); + if (NULL != (vl = dv->vl)) + { + GNUNET_assert (dv == vl->dv); + vl->dv = NULL; + if (NULL == vl->n) + { + cores_send_disconnect_info (&dv->target); + free_virtual_link (vl); + } + else + { + GNUNET_SCHEDULER_cancel (vl->visibility_task); + vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl); + } + dv->vl = NULL; + } - if (NULL != dv->timeout_task) - { - GNUNET_SCHEDULER_cancel(dv->timeout_task); - dv->timeout_task = NULL; - } - GNUNET_free(dv); + if (NULL != dv->timeout_task) + { + GNUNET_SCHEDULER_cancel (dv->timeout_task); + dv->timeout_task = NULL; } + GNUNET_free (dv); + } } @@ -3124,30 +3174,30 @@ free_dv_route(struct DistanceVector *dv) * @param me detailed information to transmit */ static void -notify_monitor(struct TransportClient *tc, - const struct GNUNET_PeerIdentity *peer, - const char *address, - enum GNUNET_NetworkType nt, - const struct MonitorEvent *me) +notify_monitor (struct TransportClient *tc, + const struct GNUNET_PeerIdentity *peer, + const char *address, + enum GNUNET_NetworkType nt, + const struct MonitorEvent *me) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_MonitorData *md; - size_t addr_len = strlen(address) + 1; + size_t addr_len = strlen (address) + 1; - env = GNUNET_MQ_msg_extra(md, - addr_len, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA); - md->nt = htonl((uint32_t)nt); + env = GNUNET_MQ_msg_extra (md, + addr_len, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA); + md->nt = htonl ((uint32_t) nt); md->peer = *peer; - md->last_validation = GNUNET_TIME_absolute_hton(me->last_validation); - md->valid_until = GNUNET_TIME_absolute_hton(me->valid_until); - md->next_validation = GNUNET_TIME_absolute_hton(me->next_validation); - md->rtt = GNUNET_TIME_relative_hton(me->rtt); - md->cs = htonl((uint32_t)me->cs); - md->num_msg_pending = htonl(me->num_msg_pending); - md->num_bytes_pending = htonl(me->num_bytes_pending); - memcpy(&md[1], address, addr_len); - GNUNET_MQ_send(tc->mq, env); + md->last_validation = GNUNET_TIME_absolute_hton (me->last_validation); + md->valid_until = GNUNET_TIME_absolute_hton (me->valid_until); + md->next_validation = GNUNET_TIME_absolute_hton (me->next_validation); + md->rtt = GNUNET_TIME_relative_hton (me->rtt); + md->cs = htonl ((uint32_t) me->cs); + md->num_msg_pending = htonl (me->num_msg_pending); + md->num_bytes_pending = htonl (me->num_bytes_pending); + memcpy (&md[1], address, addr_len); + GNUNET_MQ_send (tc->mq, env); } @@ -3161,22 +3211,22 @@ notify_monitor(struct TransportClient *tc, * @param me detailed information to transmit */ static void -notify_monitors(const struct GNUNET_PeerIdentity *peer, - const char *address, - enum GNUNET_NetworkType nt, - const struct MonitorEvent *me) +notify_monitors (const struct GNUNET_PeerIdentity *peer, + const char *address, + enum GNUNET_NetworkType nt, + const struct MonitorEvent *me) { for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - if (CT_MONITOR != tc->type) - continue; - if (tc->details.monitor.one_shot) - continue; - if ((0 != GNUNET_is_zero(&tc->details.monitor.peer)) && - (0 != GNUNET_memcmp(&tc->details.monitor.peer, peer))) - continue; - notify_monitor(tc, peer, address, nt, me); - } + { + if (CT_MONITOR != tc->type) + continue; + if (tc->details.monitor.one_shot) + continue; + if ((0 != GNUNET_is_zero (&tc->details.monitor.peer)) && + (0 != GNUNET_memcmp (&tc->details.monitor.peer, peer))) + continue; + notify_monitor (tc, peer, address, nt, me); + } } @@ -3190,18 +3240,18 @@ notify_monitors(const struct GNUNET_PeerIdentity *peer, * @return our `struct TransportClient` */ static void * -client_connect_cb(void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +client_connect_cb (void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct TransportClient *tc; - (void)cls; - tc = GNUNET_new(struct TransportClient); + (void) cls; + tc = GNUNET_new (struct TransportClient); tc->client = client; tc->mq = mq; - GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); + GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); return tc; } @@ -3212,16 +3262,16 @@ client_connect_cb(void *cls, * @param rc data structure to free */ static void -free_reassembly_context(struct ReassemblyContext *rc) +free_reassembly_context (struct ReassemblyContext *rc) { struct Neighbour *n = rc->neighbour; - GNUNET_assert(rc == GNUNET_CONTAINER_heap_remove_node(rc->hn)); - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_remove(n->reassembly_map, - rc->msg_uuid.uuid, - rc)); - GNUNET_free(rc); + GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn)); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multihashmap32_remove (n->reassembly_map, + rc->msg_uuid.uuid, + rc)); + GNUNET_free (rc); } @@ -3231,27 +3281,27 @@ free_reassembly_context(struct ReassemblyContext *rc) * @param cls a `struct Neighbour` */ static void -reassembly_cleanup_task(void *cls) +reassembly_cleanup_task (void *cls) { struct Neighbour *n = cls; struct ReassemblyContext *rc; n->reassembly_timeout_task = NULL; - while (NULL != (rc = GNUNET_CONTAINER_heap_peek(n->reassembly_heap))) + while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap))) + { + if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout) + .rel_value_us) { - if (0 == GNUNET_TIME_absolute_get_remaining(rc->reassembly_timeout) - .rel_value_us) - { - free_reassembly_context(rc); - continue; - } - GNUNET_assert(NULL == n->reassembly_timeout_task); - n->reassembly_timeout_task = - GNUNET_SCHEDULER_add_at(rc->reassembly_timeout, - &reassembly_cleanup_task, - n); - return; + free_reassembly_context (rc); + continue; } + GNUNET_assert (NULL == n->reassembly_timeout_task); + n->reassembly_timeout_task = + GNUNET_SCHEDULER_add_at (rc->reassembly_timeout, + &reassembly_cleanup_task, + n); + return; + } } @@ -3264,13 +3314,13 @@ reassembly_cleanup_task(void *cls) * @return #GNUNET_OK (continue iteration) */ static int -free_reassembly_cb(void *cls, uint32_t key, void *value) +free_reassembly_cb (void *cls, uint32_t key, void *value) { struct ReassemblyContext *rc = value; - (void)cls; - (void)key; - free_reassembly_context(rc); + (void) cls; + (void) key; + free_reassembly_context (rc); return GNUNET_OK; } @@ -3281,66 +3331,66 @@ free_reassembly_cb(void *cls, uint32_t key, void *value) * @param neighbour neighbour entry to free */ static void -free_neighbour(struct Neighbour *neighbour) +free_neighbour (struct Neighbour *neighbour) { struct DistanceVectorHop *dvh; struct VirtualLink *vl; - GNUNET_assert(NULL == neighbour->queue_head); - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(neighbours, - &neighbour->pid, - neighbour)); + GNUNET_assert (NULL == neighbour->queue_head); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (neighbours, + &neighbour->pid, + neighbour)); if (NULL != neighbour->reassembly_map) - { - GNUNET_CONTAINER_multihashmap32_iterate(neighbour->reassembly_map, - &free_reassembly_cb, - NULL); - GNUNET_CONTAINER_multihashmap32_destroy(neighbour->reassembly_map); - neighbour->reassembly_map = NULL; - GNUNET_CONTAINER_heap_destroy(neighbour->reassembly_heap); - neighbour->reassembly_heap = NULL; - } + { + GNUNET_CONTAINER_multihashmap32_iterate (neighbour->reassembly_map, + &free_reassembly_cb, + NULL); + GNUNET_CONTAINER_multihashmap32_destroy (neighbour->reassembly_map); + neighbour->reassembly_map = NULL; + GNUNET_CONTAINER_heap_destroy (neighbour->reassembly_heap); + neighbour->reassembly_heap = NULL; + } while (NULL != (dvh = neighbour->dv_head)) - { - struct DistanceVector *dv = dvh->dv; + { + struct DistanceVector *dv = dvh->dv; - free_distance_vector_hop(dvh); - if (NULL == dv->dv_head) - free_dv_route(dv); - } + free_distance_vector_hop (dvh); + if (NULL == dv->dv_head) + free_dv_route (dv); + } if (NULL != neighbour->reassembly_timeout_task) - { - GNUNET_SCHEDULER_cancel(neighbour->reassembly_timeout_task); - neighbour->reassembly_timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (neighbour->reassembly_timeout_task); + neighbour->reassembly_timeout_task = NULL; + } if (NULL != neighbour->get) - { - GNUNET_PEERSTORE_iterate_cancel(neighbour->get); - neighbour->get = NULL; - } + { + GNUNET_PEERSTORE_iterate_cancel (neighbour->get); + neighbour->get = NULL; + } if (NULL != neighbour->sc) + { + GNUNET_PEERSTORE_store_cancel (neighbour->sc); + neighbour->sc = NULL; + } + if (NULL != (vl = neighbour->vl)) + { + GNUNET_assert (neighbour == vl->n); + vl->n = NULL; + if (NULL == vl->dv) { - GNUNET_PEERSTORE_store_cancel(neighbour->sc); - neighbour->sc = NULL; + cores_send_disconnect_info (&vl->target); + free_virtual_link (vl); } - if (NULL != (vl = neighbour->vl)) + else { - GNUNET_assert(neighbour == vl->n); - vl->n = NULL; - if (NULL == vl->dv) - { - cores_send_disconnect_info(&vl->target); - free_virtual_link(vl); - } - else - { - GNUNET_SCHEDULER_cancel(vl->visibility_task); - vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl); - } - neighbour->vl = NULL; + GNUNET_SCHEDULER_cancel (vl->visibility_task); + vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl); } - GNUNET_free(neighbour); + neighbour->vl = NULL; + } + GNUNET_free (neighbour); } @@ -3351,16 +3401,16 @@ free_neighbour(struct Neighbour *neighbour) * @param pid peer the connection is for */ static void -core_send_connect_info(struct TransportClient *tc, - const struct GNUNET_PeerIdentity *pid) +core_send_connect_info (struct TransportClient *tc, + const struct GNUNET_PeerIdentity *pid) { struct GNUNET_MQ_Envelope *env; struct ConnectInfoMessage *cim; - GNUNET_assert(CT_CORE == tc->type); - env = GNUNET_MQ_msg(cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); + GNUNET_assert (CT_CORE == tc->type); + env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); cim->id = *pid; - GNUNET_MQ_send(tc->mq, env); + GNUNET_MQ_send (tc->mq, env); } @@ -3370,17 +3420,17 @@ core_send_connect_info(struct TransportClient *tc, * @param pid peer the queue was for */ static void -cores_send_connect_info(const struct GNUNET_PeerIdentity *pid) +cores_send_connect_info (const struct GNUNET_PeerIdentity *pid) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Informing CORE clients about connection to %s\n", - GNUNET_i2s(pid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Informing CORE clients about connection to %s\n", + GNUNET_i2s (pid)); for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - if (CT_CORE != tc->type) - continue; - core_send_connect_info(tc, pid); - } + { + if (CT_CORE != tc->type) + continue; + core_send_connect_info (tc, pid); + } } @@ -3392,7 +3442,7 @@ cores_send_connect_info(const struct GNUNET_PeerIdentity *pid) * @param cls the `struct Queue` to process transmissions for */ static void -transmit_on_queue(void *cls); +transmit_on_queue (void *cls); /** @@ -3403,38 +3453,38 @@ transmit_on_queue(void *cls); * @param p task priority to use, if @a queue is scheduled */ static void -schedule_transmit_on_queue(struct Queue *queue, - enum GNUNET_SCHEDULER_Priority p) +schedule_transmit_on_queue (struct Queue *queue, + enum GNUNET_SCHEDULER_Priority p) { if (queue->tc->details.communicator.total_queue_length >= COMMUNICATOR_TOTAL_QUEUE_LIMIT) - { - GNUNET_STATISTICS_update( - GST_stats, - "# Transmission throttled due to communicator queue limit", - 1, - GNUNET_NO); - queue->idle = GNUNET_NO; - return; - } + { + GNUNET_STATISTICS_update ( + GST_stats, + "# Transmission throttled due to communicator queue limit", + 1, + GNUNET_NO); + queue->idle = GNUNET_NO; + return; + } if (queue->queue_length >= QUEUE_LENGTH_LIMIT) - { - GNUNET_STATISTICS_update(GST_stats, - "# Transmission throttled due to queue queue limit", - 1, - GNUNET_NO); - queue->idle = GNUNET_NO; - return; - } + { + GNUNET_STATISTICS_update (GST_stats, + "# Transmission throttled due to queue queue limit", + 1, + GNUNET_NO); + queue->idle = GNUNET_NO; + return; + } /* queue might indeed be ready, schedule it */ if (NULL != queue->transmit_task) - GNUNET_SCHEDULER_cancel(queue->transmit_task); + GNUNET_SCHEDULER_cancel (queue->transmit_task); queue->transmit_task = - GNUNET_SCHEDULER_add_with_priority(p, &transmit_on_queue, queue); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Considering transmission on queue `%s' to %s\n", - queue->address, - GNUNET_i2s(&queue->neighbour->pid)); + GNUNET_SCHEDULER_add_with_priority (p, &transmit_on_queue, queue); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Considering transmission on queue `%s' to %s\n", + queue->address, + GNUNET_i2s (&queue->neighbour->pid)); } @@ -3445,7 +3495,7 @@ schedule_transmit_on_queue(struct Queue *queue, * @param cls a `struct VirtualLink` */ static void -check_link_down(void *cls) +check_link_down (void *cls) { struct VirtualLink *vl = cls; struct DistanceVector *dv = vl->dv; @@ -3457,30 +3507,30 @@ check_link_down(void *cls) dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS; for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; pos = pos->next_dv) - dvh_timeout = GNUNET_TIME_absolute_max(dvh_timeout, pos->path_valid_until); - if (0 == GNUNET_TIME_absolute_get_remaining(dvh_timeout).rel_value_us) - { - vl->dv->vl = NULL; - vl->dv = NULL; - } + dvh_timeout = GNUNET_TIME_absolute_max (dvh_timeout, pos->path_valid_until); + if (0 == GNUNET_TIME_absolute_get_remaining (dvh_timeout).rel_value_us) + { + vl->dv->vl = NULL; + vl->dv = NULL; + } q_timeout = GNUNET_TIME_UNIT_ZERO_ABS; for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) - q_timeout = GNUNET_TIME_absolute_max(q_timeout, q->validated_until); - if (0 == GNUNET_TIME_absolute_get_remaining(q_timeout).rel_value_us) - { - vl->n->vl = NULL; - vl->n = NULL; - } + q_timeout = GNUNET_TIME_absolute_max (q_timeout, q->validated_until); + if (0 == GNUNET_TIME_absolute_get_remaining (q_timeout).rel_value_us) + { + vl->n->vl = NULL; + vl->n = NULL; + } if ((NULL == vl->n) && (NULL == vl->dv)) - { - cores_send_disconnect_info(&vl->target); - free_virtual_link(vl); - return; - } + { + cores_send_disconnect_info (&vl->target); + free_virtual_link (vl); + return; + } vl->visibility_task = - GNUNET_SCHEDULER_add_at(GNUNET_TIME_absolute_max(q_timeout, dvh_timeout), - &check_link_down, - vl); + GNUNET_SCHEDULER_add_at (GNUNET_TIME_absolute_max (q_timeout, dvh_timeout), + &check_link_down, + vl); } @@ -3490,7 +3540,7 @@ check_link_down(void *cls) * @param queue the queue to free */ static void -free_queue(struct Queue *queue) +free_queue (struct Queue *queue) { struct Neighbour *neighbour = queue->neighbour; struct TransportClient *tc = queue->tc; @@ -3502,65 +3552,65 @@ free_queue(struct Queue *queue) struct VirtualLink *vl; if (NULL != queue->transmit_task) - { - GNUNET_SCHEDULER_cancel(queue->transmit_task); - queue->transmit_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (queue->transmit_task); + queue->transmit_task = NULL; + } while (NULL != (pa = queue->pa_head)) - { - GNUNET_CONTAINER_MDLL_remove(queue, queue->pa_head, queue->pa_tail, pa); - pa->queue = NULL; - } + { + GNUNET_CONTAINER_MDLL_remove (queue, queue->pa_head, queue->pa_tail, pa); + pa->queue = NULL; + } - GNUNET_CONTAINER_MDLL_remove(neighbour, - neighbour->queue_head, - neighbour->queue_tail, - queue); - GNUNET_CONTAINER_MDLL_remove(client, - tc->details.communicator.queue_head, - tc->details.communicator.queue_tail, - queue); + GNUNET_CONTAINER_MDLL_remove (neighbour, + neighbour->queue_head, + neighbour->queue_tail, + queue); + GNUNET_CONTAINER_MDLL_remove (client, + tc->details.communicator.queue_head, + tc->details.communicator.queue_tail, + queue); maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >= tc->details.communicator.total_queue_length); while (NULL != (qe = queue->queue_head)) + { + GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe); + queue->queue_length--; + tc->details.communicator.total_queue_length--; + if (NULL != qe->pm) { - GNUNET_CONTAINER_DLL_remove(queue->queue_head, queue->queue_tail, qe); - queue->queue_length--; - tc->details.communicator.total_queue_length--; - if (NULL != qe->pm) - { - GNUNET_assert(qe == qe->pm->qe); - qe->pm->qe = NULL; - } - GNUNET_free(qe); + GNUNET_assert (qe == qe->pm->qe); + qe->pm->qe = NULL; } - GNUNET_assert(0 == queue->queue_length); + GNUNET_free (qe); + } + GNUNET_assert (0 == queue->queue_length); if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT < tc->details.communicator.total_queue_length)) - { - /* Communicator dropped below threshold, resume all _other_ queues */ - GNUNET_STATISTICS_update( - GST_stats, - "# Transmission throttled due to communicator queue limit", - -1, - GNUNET_NO); - for (struct Queue *s = tc->details.communicator.queue_head; NULL != s; - s = s->next_client) - schedule_transmit_on_queue(s, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - } - notify_monitors(&neighbour->pid, queue->address, queue->nt, &me); - GNUNET_free(queue); + { + /* Communicator dropped below threshold, resume all _other_ queues */ + GNUNET_STATISTICS_update ( + GST_stats, + "# Transmission throttled due to communicator queue limit", + -1, + GNUNET_NO); + for (struct Queue *s = tc->details.communicator.queue_head; NULL != s; + s = s->next_client) + schedule_transmit_on_queue (s, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + } + notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); + GNUNET_free (queue); - vl = lookup_virtual_link(&neighbour->pid); + vl = lookup_virtual_link (&neighbour->pid); if ((NULL != vl) && (neighbour == vl->n)) - { - GNUNET_SCHEDULER_cancel(vl->visibility_task); - check_link_down(vl); - } + { + GNUNET_SCHEDULER_cancel (vl->visibility_task); + check_link_down (vl); + } if (NULL == neighbour->queue_head) - { - free_neighbour(neighbour); - } + { + free_neighbour (neighbour); + } } @@ -3570,24 +3620,24 @@ free_queue(struct Queue *queue) * @param ale address list entry to free */ static void -free_address_list_entry(struct AddressListEntry *ale) +free_address_list_entry (struct AddressListEntry *ale) { struct TransportClient *tc = ale->tc; - GNUNET_CONTAINER_DLL_remove(tc->details.communicator.addr_head, - tc->details.communicator.addr_tail, - ale); + GNUNET_CONTAINER_DLL_remove (tc->details.communicator.addr_head, + tc->details.communicator.addr_tail, + ale); if (NULL != ale->sc) - { - GNUNET_PEERSTORE_store_cancel(ale->sc); - ale->sc = NULL; - } + { + GNUNET_PEERSTORE_store_cancel (ale->sc); + ale->sc = NULL; + } if (NULL != ale->st) - { - GNUNET_SCHEDULER_cancel(ale->st); - ale->st = NULL; - } - GNUNET_free(ale); + { + GNUNET_SCHEDULER_cancel (ale->st); + ale->st = NULL; + } + GNUNET_free (ale); } @@ -3600,20 +3650,20 @@ free_address_list_entry(struct AddressListEntry *ale) * @return #GNUNET_YES (always) */ static int -stop_peer_request(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +stop_peer_request (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct TransportClient *tc = cls; struct PeerRequest *pr = value; - GNUNET_PEERSTORE_watch_cancel(pr->wc); - GNUNET_assert( + GNUNET_PEERSTORE_watch_cancel (pr->wc); + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(tc->details.application.requests, - pid, - pr)); - GNUNET_free(pr); + GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, + pid, + pr)); + GNUNET_free (pr); return GNUNET_OK; } @@ -3628,60 +3678,60 @@ stop_peer_request(void *cls, * @param app_ctx our `struct TransportClient` */ static void -client_disconnect_cb(void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_ctx) +client_disconnect_cb (void *cls, + struct GNUNET_SERVICE_Client *client, + void *app_ctx) { struct TransportClient *tc = app_ctx; - (void)cls; - (void)client; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Client %p disconnected, cleaning up.\n", - tc); - GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc); + (void) cls; + (void) client; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Client %p disconnected, cleaning up.\n", + tc); + GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); switch (tc->type) - { - case CT_NONE: - break; + { + case CT_NONE: + break; - case CT_CORE: { + case CT_CORE: { struct PendingMessage *pm; while (NULL != (pm = tc->details.core.pending_msg_head)) - { - GNUNET_CONTAINER_MDLL_remove(client, - tc->details.core.pending_msg_head, - tc->details.core.pending_msg_tail, - pm); - pm->client = NULL; - } + { + GNUNET_CONTAINER_MDLL_remove (client, + tc->details.core.pending_msg_head, + tc->details.core.pending_msg_tail, + pm); + pm->client = NULL; + } } break; - case CT_MONITOR: - break; + case CT_MONITOR: + break; - case CT_COMMUNICATOR: { + case CT_COMMUNICATOR: { struct Queue *q; struct AddressListEntry *ale; while (NULL != (q = tc->details.communicator.queue_head)) - free_queue(q); + free_queue (q); while (NULL != (ale = tc->details.communicator.addr_head)) - free_address_list_entry(ale); - GNUNET_free(tc->details.communicator.address_prefix); + free_address_list_entry (ale); + GNUNET_free (tc->details.communicator.address_prefix); } break; - case CT_APPLICATION: - GNUNET_CONTAINER_multipeermap_iterate(tc->details.application.requests, - &stop_peer_request, - tc); - GNUNET_CONTAINER_multipeermap_destroy(tc->details.application.requests); - break; - } - GNUNET_free(tc); + case CT_APPLICATION: + GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests, + &stop_peer_request, + tc); + GNUNET_CONTAINER_multipeermap_destroy (tc->details.application.requests); + break; + } + GNUNET_free (tc); } @@ -3695,17 +3745,17 @@ client_disconnect_cb(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -notify_client_connect_info(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +notify_client_connect_info (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct TransportClient *tc = cls; - (void)value; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Telling new CORE client about existing connection to %s\n", - GNUNET_i2s(pid)); - core_send_connect_info(tc, pid); + (void) value; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Telling new CORE client about existing connection to %s\n", + GNUNET_i2s (pid)); + core_send_connect_info (tc, pid); return GNUNET_OK; } @@ -3719,34 +3769,34 @@ notify_client_connect_info(void *cls, * @param start the start message that was sent */ static void -handle_client_start(void *cls, const struct StartMessage *start) +handle_client_start (void *cls, const struct StartMessage *start) { struct TransportClient *tc = cls; uint32_t options; - options = ntohl(start->options); + options = ntohl (start->options); if ((0 != (1 & options)) && - (0 != GNUNET_memcmp(&start->self, &GST_my_identity))) - { - /* client thinks this is a different peer, reject */ - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } + (0 != GNUNET_memcmp (&start->self, &GST_my_identity))) + { + /* client thinks this is a different peer, reject */ + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } if (CT_NONE != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } tc->type = CT_CORE; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "New CORE client with PID %s registered\n", - GNUNET_i2s(&start->self)); - GNUNET_CONTAINER_multipeermap_iterate(neighbours, - ¬ify_client_connect_info, - tc); - GNUNET_SERVICE_client_continue(tc->client); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "New CORE client with PID %s registered\n", + GNUNET_i2s (&start->self)); + GNUNET_CONTAINER_multipeermap_iterate (neighbours, + ¬ify_client_connect_info, + tc); + GNUNET_SERVICE_client_continue (tc->client); } @@ -3757,29 +3807,29 @@ handle_client_start(void *cls, const struct StartMessage *start) * @param obm the send message that was sent */ static int -check_client_send(void *cls, const struct OutboundMessage *obm) +check_client_send (void *cls, const struct OutboundMessage *obm) { struct TransportClient *tc = cls; uint16_t size; const struct GNUNET_MessageHeader *obmm; if (CT_CORE != tc->type) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - size = ntohs(obm->header.size) - sizeof(struct OutboundMessage); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + size = ntohs (obm->header.size) - sizeof(struct OutboundMessage); if (size < sizeof(struct GNUNET_MessageHeader)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - obmm = (const struct GNUNET_MessageHeader *)&obm[1]; - if (size != ntohs(obmm->size)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + obmm = (const struct GNUNET_MessageHeader *) &obm[1]; + if (size != ntohs (obmm->size)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -3792,25 +3842,25 @@ check_client_send(void *cls, const struct OutboundMessage *obm) * @param pm handle to the original pending message */ static void -client_send_response(struct PendingMessage *pm) +client_send_response (struct PendingMessage *pm) { struct TransportClient *tc = pm->client; struct VirtualLink *vl = pm->vl; if (NULL != tc) - { - struct GNUNET_MQ_Envelope *env; - struct SendOkMessage *som; - - env = GNUNET_MQ_msg(som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); - som->peer = vl->target; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Confirming transmission of <%llu> to %s\n", - pm->logging_uuid, - GNUNET_i2s(&vl->target)); - GNUNET_MQ_send(tc->mq, env); - } - free_pending_message(pm); + { + struct GNUNET_MQ_Envelope *env; + struct SendOkMessage *som; + + env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); + som->peer = vl->target; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Confirming transmission of <%llu> to %s\n", + pm->logging_uuid, + GNUNET_i2s (&vl->target)); + GNUNET_MQ_send (tc->mq, env); + } + free_pending_message (pm); } @@ -3824,10 +3874,10 @@ client_send_response(struct PendingMessage *pm) * @return number of entries set in @a hops_array */ static unsigned int -pick_random_dv_hops(const struct DistanceVector *dv, - enum RouteMessageOptions options, - struct DistanceVectorHop **hops_array, - unsigned int hops_array_length) +pick_random_dv_hops (const struct DistanceVector *dv, + enum RouteMessageOptions options, + struct DistanceVectorHop **hops_array, + unsigned int hops_array_length) { uint64_t choices[hops_array_length]; uint64_t num_dv; @@ -3839,56 +3889,56 @@ pick_random_dv_hops(const struct DistanceVector *dv, dv_count = 0; for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; pos = pos->next_dv) - { - if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && - (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until) - .rel_value_us == 0)) - continue; /* pos unconfirmed and confirmed required */ - num_dv += MAX_DV_HOPS_ALLOWED - pos->distance; - dv_count++; - } + { + if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && + (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until) + .rel_value_us == 0)) + continue; /* pos unconfirmed and confirmed required */ + num_dv += MAX_DV_HOPS_ALLOWED - pos->distance; + dv_count++; + } if (0 == dv_count) return 0; if (dv_count <= hops_array_length) - { - dv_count = 0; - for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; - pos = pos->next_dv) - hops_array[dv_count++] = pos; - return dv_count; - } + { + dv_count = 0; + for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; + pos = pos->next_dv) + hops_array[dv_count++] = pos; + return dv_count; + } for (unsigned int i = 0; i < hops_array_length; i++) - { - int ok = GNUNET_NO; - while (GNUNET_NO == ok) + { + int ok = GNUNET_NO; + while (GNUNET_NO == ok) + { + choices[i] = + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, num_dv); + ok = GNUNET_YES; + for (unsigned int j = 0; j < i; j++) + if (choices[i] == choices[j]) { - choices[i] = - GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, num_dv); - ok = GNUNET_YES; - for (unsigned int j = 0; j < i; j++) - if (choices[i] == choices[j]) - { - ok = GNUNET_NO; - break; - } + ok = GNUNET_NO; + break; } } + } dv_count = 0; num_dv = 0; for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; pos = pos->next_dv) - { - uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance; - - if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && - (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until) - .rel_value_us == 0)) - continue; /* pos unconfirmed and confirmed required */ - for (unsigned int i = 0; i < hops_array_length; i++) - if ((num_dv <= choices[i]) && (num_dv + delta > choices[i])) - hops_array[dv_count++] = pos; - num_dv += delta; - } + { + uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance; + + if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && + (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until) + .rel_value_us == 0)) + continue; /* pos unconfirmed and confirmed required */ + for (unsigned int i = 0; i < hops_array_length; i++) + if ((num_dv <= choices[i]) && (num_dv + delta > choices[i])) + hops_array[dv_count++] = pos; + num_dv += delta; + } return dv_count; } @@ -3900,7 +3950,7 @@ pick_random_dv_hops(const struct DistanceVector *dv, * @param cam the send message that was sent */ static int -check_communicator_available( +check_communicator_available ( void *cls, const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) { @@ -3908,15 +3958,15 @@ check_communicator_available( uint16_t size; if (CT_NONE != tc->type) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } tc->type = CT_COMMUNICATOR; - size = ntohs(cam->header.size) - sizeof(*cam); + size = ntohs (cam->header.size) - sizeof(*cam); if (0 == size) return GNUNET_OK; /* receive-only communicator */ - GNUNET_MQ_check_zero_termination(cam); + GNUNET_MQ_check_zero_termination (cam); return GNUNET_OK; } @@ -3927,22 +3977,22 @@ check_communicator_available( * @param cmc context for which we are done handling the message */ static void -finish_cmc_handling(struct CommunicatorMessageContext *cmc) +finish_cmc_handling (struct CommunicatorMessageContext *cmc) { - if (0 != ntohl(cmc->im.fc_on)) - { - /* send ACK when done to communicator for flow control! */ - struct GNUNET_MQ_Envelope *env; - struct GNUNET_TRANSPORT_IncomingMessageAck *ack; - - env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); - ack->reserved = htonl(0); - ack->fc_id = cmc->im.fc_id; - ack->sender = cmc->im.sender; - GNUNET_MQ_send(cmc->tc->mq, env); - } - GNUNET_SERVICE_client_continue(cmc->tc->client); - GNUNET_free(cmc); + if (0 != ntohl (cmc->im.fc_on)) + { + /* send ACK when done to communicator for flow control! */ + struct GNUNET_MQ_Envelope *env; + struct GNUNET_TRANSPORT_IncomingMessageAck *ack; + + env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); + ack->reserved = htonl (0); + ack->fc_id = cmc->im.fc_id; + ack->sender = cmc->im.sender; + GNUNET_MQ_send (cmc->tc->mq, env); + } + GNUNET_SERVICE_client_continue (cmc->tc->client); + GNUNET_free (cmc); } @@ -3956,7 +4006,7 @@ finish_cmc_handling(struct CommunicatorMessageContext *cmc) * @param rom the message that was sent */ static void -handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom) +handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom) { struct TransportClient *tc = cls; struct VirtualLink *vl; @@ -3964,31 +4014,31 @@ handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom) struct CommunicatorMessageContext *cmc; if (CT_CORE != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - vl = lookup_virtual_link(&rom->peer); + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + vl = lookup_virtual_link (&rom->peer); if (NULL == vl) - { - GNUNET_STATISTICS_update(GST_stats, - "# RECV_OK dropped: virtual link unknown", - 1, - GNUNET_NO); - GNUNET_SERVICE_client_continue(tc->client); - return; - } - delta = ntohl(rom->increase_window_delta); + { + GNUNET_STATISTICS_update (GST_stats, + "# RECV_OK dropped: virtual link unknown", + 1, + GNUNET_NO); + GNUNET_SERVICE_client_continue (tc->client); + return; + } + delta = ntohl (rom->increase_window_delta); vl->core_recv_window += delta; if (vl->core_recv_window <= 0) return; /* resume communicators */ while (NULL != (cmc = vl->cmc_tail)) - { - GNUNET_CONTAINER_DLL_remove(vl->cmc_head, vl->cmc_tail, cmc); - finish_cmc_handling(cmc); - } + { + GNUNET_CONTAINER_DLL_remove (vl->cmc_head, vl->cmc_tail, cmc); + finish_cmc_handling (cmc); + } } @@ -3999,28 +4049,28 @@ handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom) * @param cam the send message that was sent */ static void -handle_communicator_available( +handle_communicator_available ( void *cls, const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) { struct TransportClient *tc = cls; uint16_t size; - size = ntohs(cam->header.size) - sizeof(*cam); + size = ntohs (cam->header.size) - sizeof(*cam); if (0 == size) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Receive-only communicator connected\n"); - return; /* receive-only communicator */ - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Receive-only communicator connected\n"); + return; /* receive-only communicator */ + } tc->details.communicator.address_prefix = - GNUNET_strdup((const char *)&cam[1]); + GNUNET_strdup ((const char *) &cam[1]); tc->details.communicator.cc = - (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(cam->cc); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Communicator with prefix `%s' connected\n", - tc->details.communicator.address_prefix); - GNUNET_SERVICE_client_continue(tc->client); + (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Communicator with prefix `%s' connected\n", + tc->details.communicator.address_prefix); + GNUNET_SERVICE_client_continue (tc->client); } @@ -4032,7 +4082,7 @@ handle_communicator_available( * @return #GNUNET_OK if message is well-formed */ static int -check_communicator_backchannel( +check_communicator_backchannel ( void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) { @@ -4041,24 +4091,24 @@ check_communicator_backchannel( uint16_t msize; uint16_t isize; - (void)cls; - msize = ntohs(cb->header.size) - sizeof(*cb); - inbox = (const struct GNUNET_MessageHeader *)&cb[1]; - isize = ntohs(inbox->size); + (void) cls; + msize = ntohs (cb->header.size) - sizeof(*cb); + inbox = (const struct GNUNET_MessageHeader *) &cb[1]; + isize = ntohs (inbox->size); if (isize >= msize) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - is = (const char *)inbox; + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + is = (const char *) inbox; is += isize; msize -= isize; - GNUNET_assert(0 < msize); + GNUNET_assert (0 < msize); if ('\0' != is[msize - 1]) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -4070,26 +4120,26 @@ check_communicator_backchannel( * @param dv[in,out] virtual link to update ephemeral for */ static void -update_ephemeral(struct DistanceVector *dv) +update_ephemeral (struct DistanceVector *dv) { struct EphemeralConfirmationPS ec; if (0 != - GNUNET_TIME_absolute_get_remaining(dv->ephemeral_validity).rel_value_us) + GNUNET_TIME_absolute_get_remaining (dv->ephemeral_validity).rel_value_us) return; - dv->monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg); + dv->monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); dv->ephemeral_validity = - GNUNET_TIME_absolute_add(dv->monotime, EPHEMERAL_VALIDITY); - GNUNET_assert(GNUNET_OK == - GNUNET_CRYPTO_ecdhe_key_create2(&dv->private_key)); - GNUNET_CRYPTO_ecdhe_key_get_public(&dv->private_key, &dv->ephemeral_key); - ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); - ec.purpose.size = htonl(sizeof(ec)); + GNUNET_TIME_absolute_add (dv->monotime, EPHEMERAL_VALIDITY); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_ecdhe_key_create2 (&dv->private_key)); + GNUNET_CRYPTO_ecdhe_key_get_public (&dv->private_key, &dv->ephemeral_key); + ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); + ec.purpose.size = htonl (sizeof(ec)); ec.target = dv->target; ec.ephemeral_key = dv->ephemeral_key; - GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, - &ec.purpose, - &dv->sender_sig)); + GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, + &ec.purpose, + &dv->sender_sig)); } @@ -4103,45 +4153,45 @@ update_ephemeral(struct DistanceVector *dv) * @param payload_size number of bytes in @a payload */ static void -queue_send_msg(struct Queue *queue, - struct PendingMessage *pm, - const void *payload, - size_t payload_size) +queue_send_msg (struct Queue *queue, + struct PendingMessage *pm, + const void *payload, + size_t payload_size) { struct Neighbour *n = queue->neighbour; struct GNUNET_TRANSPORT_SendMessageTo *smt; struct GNUNET_MQ_Envelope *env; queue->idle = GNUNET_NO; - GNUNET_log( + GNUNET_log ( GNUNET_ERROR_TYPE_DEBUG, "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n", - (unsigned int)payload_size, + (unsigned int) payload_size, (NULL == pm) ? 0 : pm->logging_uuid, - (unsigned long long)queue->qid, - GNUNET_i2s(&queue->neighbour->pid)); - env = GNUNET_MQ_msg_extra(smt, - payload_size, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); + (unsigned long long) queue->qid, + GNUNET_i2s (&queue->neighbour->pid)); + env = GNUNET_MQ_msg_extra (smt, + payload_size, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); smt->qid = queue->qid; smt->mid = queue->mid_gen; smt->receiver = n->pid; - memcpy(&smt[1], payload, payload_size); + memcpy (&smt[1], payload, payload_size); { /* Pass the env to the communicator of queue for transmission. */ struct QueueEntry *qe; - qe = GNUNET_new(struct QueueEntry); + qe = GNUNET_new (struct QueueEntry); qe->mid = queue->mid_gen++; qe->queue = queue; if (NULL != pm) - { - qe->pm = pm; - GNUNET_assert(NULL == pm->qe); - pm->qe = qe; - } - GNUNET_CONTAINER_DLL_insert(queue->queue_head, queue->queue_tail, qe); - GNUNET_assert(CT_COMMUNICATOR == queue->tc->type); + { + qe->pm = pm; + GNUNET_assert (NULL == pm->qe); + pm->qe = qe; + } + GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe); + GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); queue->queue_length++; queue->tc->details.communicator.total_queue_length++; if (COMMUNICATOR_TOTAL_QUEUE_LIMIT == @@ -4149,7 +4199,7 @@ queue_send_msg(struct Queue *queue, queue->idle = GNUNET_NO; if (QUEUE_LENGTH_LIMIT == queue->queue_length) queue->idle = GNUNET_NO; - GNUNET_MQ_send(queue->tc->mq, env); + GNUNET_MQ_send (queue->tc->mq, env); } } @@ -4165,9 +4215,9 @@ queue_send_msg(struct Queue *queue, * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed */ static struct GNUNET_TIME_Relative -route_via_neighbour(const struct Neighbour *n, - const struct GNUNET_MessageHeader *hdr, - enum RouteMessageOptions options) +route_via_neighbour (const struct Neighbour *n, + const struct GNUNET_MessageHeader *hdr, + enum RouteMessageOptions options) { struct GNUNET_TIME_Absolute now; unsigned int candidates; @@ -4176,7 +4226,7 @@ route_via_neighbour(const struct Neighbour *n, struct GNUNET_TIME_Relative rtt; /* Pick one or two 'random' queues from n (under constraints of options) */ - now = GNUNET_TIME_absolute_get(); + now = GNUNET_TIME_absolute_get (); /* FIXME-OPTIMIZE: give queues 'weights' and pick proportional to weight in the future; weight could be assigned by observed bandwidth (note: not sure if we should do this for this type @@ -4184,53 +4234,53 @@ route_via_neighbour(const struct Neighbour *n, candidates = 0; for (struct Queue *pos = n->queue_head; NULL != pos; pos = pos->next_neighbour) - { - if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || - (pos->validated_until.abs_value_us > now.abs_value_us)) - candidates++; - } + { + if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || + (pos->validated_until.abs_value_us > now.abs_value_us)) + candidates++; + } if (0 == candidates) - { - /* This can happen rarely if the last confirmed queue timed - out just as we were beginning to process this message. */ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Could not route message of type %u to %s: no valid queue\n", - ntohs(hdr->type), - GNUNET_i2s(&n->pid)); - GNUNET_STATISTICS_update(GST_stats, - "# route selection failed (all no valid queue)", - 1, - GNUNET_NO); - return GNUNET_TIME_UNIT_FOREVER_REL; - } + { + /* This can happen rarely if the last confirmed queue timed + out just as we were beginning to process this message. */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Could not route message of type %u to %s: no valid queue\n", + ntohs (hdr->type), + GNUNET_i2s (&n->pid)); + GNUNET_STATISTICS_update (GST_stats, + "# route selection failed (all no valid queue)", + 1, + GNUNET_NO); + return GNUNET_TIME_UNIT_FOREVER_REL; + } rtt = GNUNET_TIME_UNIT_FOREVER_REL; - sel1 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates); + sel1 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates); if (0 == (options & RMO_REDUNDANT)) sel2 = candidates; /* picks none! */ else - sel2 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates); + sel2 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates); candidates = 0; for (struct Queue *pos = n->queue_head; NULL != pos; pos = pos->next_neighbour) + { + if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || + (pos->validated_until.abs_value_us > now.abs_value_us)) { - if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || - (pos->validated_until.abs_value_us > now.abs_value_us)) - { - if ((sel1 == candidates) || (sel2 == candidates)) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Routing message of type %u to %s using %s (#%u)\n", - ntohs(hdr->type), - GNUNET_i2s(&n->pid), - pos->address, - (sel1 == candidates) ? 1 : 2); - rtt = GNUNET_TIME_relative_min(rtt, pos->pd.aged_rtt); - queue_send_msg(pos, NULL, hdr, ntohs(hdr->size)); - } - candidates++; - } + if ((sel1 == candidates) || (sel2 == candidates)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Routing message of type %u to %s using %s (#%u)\n", + ntohs (hdr->type), + GNUNET_i2s (&n->pid), + pos->address, + (sel1 == candidates) ? 1 : 2); + rtt = GNUNET_TIME_relative_min (rtt, pos->pd.aged_rtt); + queue_send_msg (pos, NULL, hdr, ntohs (hdr->size)); + } + candidates++; } + } return rtt; } @@ -4238,7 +4288,8 @@ route_via_neighbour(const struct Neighbour *n, /** * Structure of the key material used to encrypt backchannel messages. */ -struct DVKeyState { +struct DVKeyState +{ /** * State of our block cipher. */ @@ -4247,7 +4298,8 @@ struct DVKeyState { /** * Actual key material. */ - struct { + struct + { /** * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()). */ @@ -4275,34 +4327,34 @@ struct DVKeyState { * @param key[out] symmetric cipher and HMAC state to generate */ static void -dv_setup_key_state_from_km(const struct GNUNET_HashCode *km, - const struct GNUNET_ShortHashCode *iv, - struct DVKeyState *key) +dv_setup_key_state_from_km (const struct GNUNET_HashCode *km, + const struct GNUNET_ShortHashCode *iv, + struct DVKeyState *key) { /* must match #dh_key_derive_eph_pub */ - GNUNET_assert(GNUNET_YES == - GNUNET_CRYPTO_kdf(&key->material, - sizeof(key->material), - "transport-backchannel-key", - strlen("transport-backchannel-key"), - &km, - sizeof(km), - iv, - sizeof(*iv))); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Deriving backchannel key based on KM %s and IV %s\n", - GNUNET_h2s(km), - GNUNET_sh2s(iv)); - gcry_cipher_open(&key->cipher, - GCRY_CIPHER_AES256 /* low level: go for speed */, - GCRY_CIPHER_MODE_CTR, - 0 /* flags */); - gcry_cipher_setkey(key->cipher, - &key->material.aes_key, - sizeof(key->material.aes_key)); - gcry_cipher_setctr(key->cipher, - &key->material.aes_ctr, - sizeof(key->material.aes_ctr)); + GNUNET_assert (GNUNET_YES == + GNUNET_CRYPTO_kdf (&key->material, + sizeof(key->material), + "transport-backchannel-key", + strlen ("transport-backchannel-key"), + &km, + sizeof(km), + iv, + sizeof(*iv))); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Deriving backchannel key based on KM %s and IV %s\n", + GNUNET_h2s (km), + GNUNET_sh2s (iv)); + gcry_cipher_open (&key->cipher, + GCRY_CIPHER_AES256 /* low level: go for speed */, + GCRY_CIPHER_MODE_CTR, + 0 /* flags */); + gcry_cipher_setkey (key->cipher, + &key->material.aes_key, + sizeof(key->material.aes_key)); + gcry_cipher_setctr (key->cipher, + &key->material.aes_ctr, + sizeof(key->material.aes_ctr)); } @@ -4316,7 +4368,7 @@ dv_setup_key_state_from_km(const struct GNUNET_HashCode *km, * @param key[out] set to the key material */ static void -dh_key_derive_eph_pid( +dh_key_derive_eph_pid ( const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, const struct GNUNET_PeerIdentity *target, const struct GNUNET_ShortHashCode *iv, @@ -4324,10 +4376,10 @@ dh_key_derive_eph_pid( { struct GNUNET_HashCode km; - GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa(priv_ephemeral, - &target->public_key, - &km)); - dv_setup_key_state_from_km(&km, iv, key); + GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral, + &target->public_key, + &km)); + dv_setup_key_state_from_km (&km, iv, key); } @@ -4341,16 +4393,16 @@ dh_key_derive_eph_pid( * @param key[out] set to the key material */ static void -dh_key_derive_eph_pub(const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, - const struct GNUNET_ShortHashCode *iv, - struct DVKeyState *key) +dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, + const struct GNUNET_ShortHashCode *iv, + struct DVKeyState *key) { struct GNUNET_HashCode km; - GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh(GST_my_private_key, - pub_ephemeral, - &km)); - dv_setup_key_state_from_km(&km, iv, key); + GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key, + pub_ephemeral, + &km)); + dv_setup_key_state_from_km (&km, iv, key); } @@ -4364,12 +4416,12 @@ dh_key_derive_eph_pub(const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, * @param data_size number of bytes in @a data */ static void -dv_hmac(const struct DVKeyState *key, - struct GNUNET_HashCode *hmac, - const void *data, - size_t data_size) +dv_hmac (const struct DVKeyState *key, + struct GNUNET_HashCode *hmac, + const void *data, + size_t data_size) { - GNUNET_CRYPTO_hmac(&key->material.hmac_key, data, data_size, hmac); + GNUNET_CRYPTO_hmac (&key->material.hmac_key, data, data_size, hmac); } @@ -4383,10 +4435,10 @@ dv_hmac(const struct DVKeyState *key, * @param in_size number of bytes of input in @a in and available at @a dst */ static void -dv_encrypt(struct DVKeyState *key, const void *in, void *dst, size_t in_size) +dv_encrypt (struct DVKeyState *key, const void *in, void *dst, size_t in_size) { - GNUNET_assert(0 == - gcry_cipher_encrypt(key->cipher, dst, in_size, in, in_size)); + GNUNET_assert (0 == + gcry_cipher_encrypt (key->cipher, dst, in_size, in, in_size)); } @@ -4400,13 +4452,13 @@ dv_encrypt(struct DVKeyState *key, const void *in, void *dst, size_t in_size) * @param out_size number of bytes of input in @a ciph and available in @a out */ static void -dv_decrypt(struct DVKeyState *key, - void *out, - const void *ciph, - size_t out_size) +dv_decrypt (struct DVKeyState *key, + void *out, + const void *ciph, + size_t out_size) { - GNUNET_assert( - 0 == gcry_cipher_decrypt(key->cipher, out, out_size, ciph, out_size)); + GNUNET_assert ( + 0 == gcry_cipher_decrypt (key->cipher, out, out_size, ciph, out_size)); } @@ -4416,10 +4468,10 @@ dv_decrypt(struct DVKeyState *key, * @param key key material to clean up (memory must not be free'd!) */ static void -dv_key_clean(struct DVKeyState *key) +dv_key_clean (struct DVKeyState *key) { - gcry_cipher_close(key->cipher); - GNUNET_CRYPTO_zero_keys(&key->material, sizeof(key->material)); + gcry_cipher_close (key->cipher); + GNUNET_CRYPTO_zero_keys (&key->material, sizeof(key->material)); } @@ -4452,92 +4504,92 @@ typedef void (*DVMessageHandler) (void *cls, * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed */ static struct GNUNET_TIME_Relative -encapsulate_for_dv(struct DistanceVector *dv, - unsigned int num_dvhs, - struct DistanceVectorHop **dvhs, - const struct GNUNET_MessageHeader *hdr, - DVMessageHandler use, - void *use_cls, - enum RouteMessageOptions options) +encapsulate_for_dv (struct DistanceVector *dv, + unsigned int num_dvhs, + struct DistanceVectorHop **dvhs, + const struct GNUNET_MessageHeader *hdr, + DVMessageHandler use, + void *use_cls, + enum RouteMessageOptions options) { struct TransportDVBoxMessage box_hdr; struct TransportDVBoxPayloadP payload_hdr; - uint16_t enc_body_size = ntohs(hdr->size); + uint16_t enc_body_size = ntohs (hdr->size); char enc[sizeof(struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN; struct TransportDVBoxPayloadP *enc_payload_hdr = - (struct TransportDVBoxPayloadP *)enc; + (struct TransportDVBoxPayloadP *) enc; struct DVKeyState key; struct GNUNET_TIME_Relative rtt; /* Encrypt payload */ - box_hdr.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX); - box_hdr.total_hops = htons(0); - update_ephemeral(dv); + box_hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX); + box_hdr.total_hops = htons (0); + update_ephemeral (dv); box_hdr.ephemeral_key = dv->ephemeral_key; payload_hdr.sender_sig = dv->sender_sig; - GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, - &box_hdr.iv, - sizeof(box_hdr.iv)); - dh_key_derive_eph_pid(&dv->private_key, &dv->target, &box_hdr.iv, &key); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + &box_hdr.iv, + sizeof(box_hdr.iv)); + dh_key_derive_eph_pid (&dv->private_key, &dv->target, &box_hdr.iv, &key); payload_hdr.sender = GST_my_identity; - payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton(dv->monotime); - dv_encrypt(&key, &payload_hdr, enc_payload_hdr, sizeof(payload_hdr)); - dv_encrypt(&key, - hdr, - &enc[sizeof(struct TransportDVBoxPayloadP)], - enc_body_size); - dv_hmac(&key, &box_hdr.hmac, enc, sizeof(enc)); - dv_key_clean(&key); + payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton (dv->monotime); + dv_encrypt (&key, &payload_hdr, enc_payload_hdr, sizeof(payload_hdr)); + dv_encrypt (&key, + hdr, + &enc[sizeof(struct TransportDVBoxPayloadP)], + enc_body_size); + dv_hmac (&key, &box_hdr.hmac, enc, sizeof(enc)); + dv_key_clean (&key); rtt = GNUNET_TIME_UNIT_FOREVER_REL; /* For each selected path, take the pre-computed header and body and add the path in the middle of the message; then send it. */ for (unsigned int i = 0; i < num_dvhs; i++) + { + struct DistanceVectorHop *dvh = dvhs[i]; + unsigned int num_hops = dvh->distance + 1; + char buf[sizeof(struct TransportDVBoxMessage) + + sizeof(struct GNUNET_PeerIdentity) * num_hops + + sizeof(struct TransportDVBoxPayloadP) + + enc_body_size] GNUNET_ALIGN; + struct GNUNET_PeerIdentity *dhops; + + box_hdr.header.size = htons (sizeof(buf)); + box_hdr.num_hops = htons (num_hops); + memcpy (buf, &box_hdr, sizeof(box_hdr)); + dhops = (struct GNUNET_PeerIdentity *) &buf[sizeof(box_hdr)]; + memcpy (dhops, + dvh->path, + dvh->distance * sizeof(struct GNUNET_PeerIdentity)); + dhops[dvh->distance] = dv->target; + if (GNUNET_EXTRA_LOGGING > 0) { - struct DistanceVectorHop *dvh = dvhs[i]; - unsigned int num_hops = dvh->distance + 1; - char buf[sizeof(struct TransportDVBoxMessage) + - sizeof(struct GNUNET_PeerIdentity) * num_hops + - sizeof(struct TransportDVBoxPayloadP) + - enc_body_size] GNUNET_ALIGN; - struct GNUNET_PeerIdentity *dhops; - - box_hdr.header.size = htons(sizeof(buf)); - box_hdr.num_hops = htons(num_hops); - memcpy(buf, &box_hdr, sizeof(box_hdr)); - dhops = (struct GNUNET_PeerIdentity *)&buf[sizeof(box_hdr)]; - memcpy(dhops, - dvh->path, - dvh->distance * sizeof(struct GNUNET_PeerIdentity)); - dhops[dvh->distance] = dv->target; - if (GNUNET_EXTRA_LOGGING > 0) - { - char *path; - - path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity)); - for (unsigned int j = 0; j <= num_hops; j++) - { - char *tmp; - - GNUNET_asprintf(&tmp, "%s-%s", path, GNUNET_i2s(&dhops[j])); - GNUNET_free(path); - path = tmp; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Routing message of type %u to %s using DV (#%u/%u) via %s\n", - ntohs(hdr->type), - GNUNET_i2s(&dv->target), - i + 1, - num_dvhs + 1, - path); - GNUNET_free(path); - } - rtt = GNUNET_TIME_relative_min(rtt, dvh->pd.aged_rtt); - memcpy(&dhops[num_hops], enc, sizeof(enc)); - use(use_cls, - dvh->next_hop, - (const struct GNUNET_MessageHeader *)buf, - options); - } + char *path; + + path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity)); + for (unsigned int j = 0; j <= num_hops; j++) + { + char *tmp; + + GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[j])); + GNUNET_free (path); + path = tmp; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Routing message of type %u to %s using DV (#%u/%u) via %s\n", + ntohs (hdr->type), + GNUNET_i2s (&dv->target), + i + 1, + num_dvhs + 1, + path); + GNUNET_free (path); + } + rtt = GNUNET_TIME_relative_min (rtt, dvh->pd.aged_rtt); + memcpy (&dhops[num_hops], enc, sizeof(enc)); + use (use_cls, + dvh->next_hop, + (const struct GNUNET_MessageHeader *) buf, + options); + } return rtt; } @@ -4552,13 +4604,13 @@ encapsulate_for_dv(struct DistanceVector *dv, * @param options message options for queue selection */ static void -send_dv_to_neighbour(void *cls, - struct Neighbour *next_hop, - const struct GNUNET_MessageHeader *hdr, - enum RouteMessageOptions options) +send_dv_to_neighbour (void *cls, + struct Neighbour *next_hop, + const struct GNUNET_MessageHeader *hdr, + enum RouteMessageOptions options) { - (void)cls; - (void)route_via_neighbour(next_hop, hdr, options); + (void) cls; + (void) route_via_neighbour (next_hop, hdr, options); } @@ -4574,9 +4626,9 @@ send_dv_to_neighbour(void *cls, * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed */ static struct GNUNET_TIME_Relative -route_control_message_without_fc(const struct GNUNET_PeerIdentity *target, - const struct GNUNET_MessageHeader *hdr, - enum RouteMessageOptions options) +route_control_message_without_fc (const struct GNUNET_PeerIdentity *target, + const struct GNUNET_MessageHeader *hdr, + enum RouteMessageOptions options) { struct VirtualLink *vl; struct Neighbour *n; @@ -4584,78 +4636,78 @@ route_control_message_without_fc(const struct GNUNET_PeerIdentity *target, struct GNUNET_TIME_Relative rtt1; struct GNUNET_TIME_Relative rtt2; - vl = lookup_virtual_link(target); - GNUNET_assert(NULL != vl); + vl = lookup_virtual_link (target); + GNUNET_assert (NULL != vl); n = vl->n; dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL; if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) - { - /* if confirmed is required, and we do not have anything - confirmed, drop respective options */ - if (NULL == n) - n = lookup_neighbour(target); - if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED))) - dv = GNUNET_CONTAINER_multipeermap_get(dv_routes, target); - } + { + /* if confirmed is required, and we do not have anything + confirmed, drop respective options */ + if (NULL == n) + n = lookup_neighbour (target); + if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED))) + dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, target); + } if ((NULL == n) && (NULL == dv)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Cannot route message of type %u to %s: no route\n", - ntohs(hdr->type), - GNUNET_i2s(target)); - GNUNET_STATISTICS_update(GST_stats, - "# Messages dropped in routing: no acceptable method", - 1, - GNUNET_NO); - return GNUNET_TIME_UNIT_FOREVER_REL; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Routing message of type %u to %s with options %X\n", - ntohs(hdr->type), - GNUNET_i2s(target), - (unsigned int)options); + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Cannot route message of type %u to %s: no route\n", + ntohs (hdr->type), + GNUNET_i2s (target)); + GNUNET_STATISTICS_update (GST_stats, + "# Messages dropped in routing: no acceptable method", + 1, + GNUNET_NO); + return GNUNET_TIME_UNIT_FOREVER_REL; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Routing message of type %u to %s with options %X\n", + ntohs (hdr->type), + GNUNET_i2s (target), + (unsigned int) options); /* If both dv and n are possible and we must choose: flip a coin for the choice between the two; for now 50/50 */ if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT))) - { - if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2)) - n = NULL; - else - dv = NULL; - } + { + if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2)) + n = NULL; + else + dv = NULL; + } if ((NULL != n) && (NULL != dv)) options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's enough for redunancy, so clear the flag. */ rtt1 = GNUNET_TIME_UNIT_FOREVER_REL; rtt2 = GNUNET_TIME_UNIT_FOREVER_REL; if (NULL != n) - { - rtt1 = route_via_neighbour(n, hdr, options); - } + { + rtt1 = route_via_neighbour (n, hdr, options); + } if (NULL != dv) - { - struct DistanceVectorHop *hops[2]; - unsigned int res; - - res = pick_random_dv_hops(dv, - options, - hops, - (0 == (options & RMO_REDUNDANT)) ? 1 : 2); - if (0 == res) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Failed to route message, could not determine DV path\n"); - return rtt1; - } - rtt2 = encapsulate_for_dv(dv, - res, - hops, - hdr, - &send_dv_to_neighbour, - NULL, - options & (~RMO_REDUNDANT)); - } - return GNUNET_TIME_relative_min(rtt1, rtt2); + { + struct DistanceVectorHop *hops[2]; + unsigned int res; + + res = pick_random_dv_hops (dv, + options, + hops, + (0 == (options & RMO_REDUNDANT)) ? 1 : 2); + if (0 == res) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to route message, could not determine DV path\n"); + return rtt1; + } + rtt2 = encapsulate_for_dv (dv, + res, + hops, + hdr, + &send_dv_to_neighbour, + NULL, + options & (~RMO_REDUNDANT)); + } + return GNUNET_TIME_relative_min (rtt1, rtt2); } @@ -4666,7 +4718,7 @@ route_control_message_without_fc(const struct GNUNET_PeerIdentity *target, * @param cls a `struct VirtualLink` to work with */ static void -consider_sending_fc(void *cls) +consider_sending_fc (void *cls) { struct VirtualLink *vl = cls; struct GNUNET_TIME_Absolute monotime; @@ -4674,7 +4726,7 @@ consider_sending_fc(void *cls) struct GNUNET_TIME_Relative duration; struct GNUNET_TIME_Relative rtt; - duration = GNUNET_TIME_absolute_get_duration(vl->last_fc_transmission); + duration = GNUNET_TIME_absolute_get_duration (vl->last_fc_transmission); /* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing it always! */ /* For example, we should probably ONLY do this if a bit more than @@ -4683,41 +4735,41 @@ consider_sending_fc(void *cls) need an estimate for the bandwidth-delay-product for the entire VL, as that determines "significantly". We have the delay, but the bandwidth statistics need to be added for the VL!*/ - (void)duration; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending FC seq %u to %s with new window %llu\n", - (unsigned int)vl->fc_seq_gen, - GNUNET_i2s(&vl->target), - (unsigned long long)vl->incoming_fc_window_size); - monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg); + (void) duration; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending FC seq %u to %s with new window %llu\n", + (unsigned int) vl->fc_seq_gen, + GNUNET_i2s (&vl->target), + (unsigned long long) vl->incoming_fc_window_size); + monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); vl->last_fc_transmission = monotime; - fc.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL); - fc.header.size = htons(sizeof(fc)); - fc.seq = htonl(vl->fc_seq_gen++); - fc.inbound_window_size = GNUNET_htonll(vl->incoming_fc_window_size); - fc.outbound_sent = GNUNET_htonll(vl->outbound_fc_window_size_used); - fc.outbound_window_size = GNUNET_htonll(vl->outbound_fc_window_size); - fc.sender_time = GNUNET_TIME_absolute_hton(monotime); - rtt = route_control_message_without_fc(&vl->target, &fc.header, RMO_NONE); + fc.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL); + fc.header.size = htons (sizeof(fc)); + fc.seq = htonl (vl->fc_seq_gen++); + fc.inbound_window_size = GNUNET_htonll (vl->incoming_fc_window_size); + fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used); + fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size); + fc.sender_time = GNUNET_TIME_absolute_hton (monotime); + rtt = route_control_message_without_fc (&vl->target, &fc.header, RMO_NONE); if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us) - { - rtt = GNUNET_TIME_UNIT_SECONDS; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "FC retransmission to %s failed, will retry in %s\n", - GNUNET_i2s(&vl->target), - GNUNET_STRINGS_relative_time_to_string(rtt, GNUNET_YES)); - vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO; - } + { + rtt = GNUNET_TIME_UNIT_SECONDS; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "FC retransmission to %s failed, will retry in %s\n", + GNUNET_i2s (&vl->target), + GNUNET_STRINGS_relative_time_to_string (rtt, GNUNET_YES)); + vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO; + } else - { - /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */ - vl->last_fc_rtt = rtt; - } + { + /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */ + vl->last_fc_rtt = rtt; + } if (NULL != vl->fc_retransmit_task) - GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task); + GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); vl->fc_retransmit_task = - GNUNET_SCHEDULER_add_delayed(rtt, &consider_sending_fc, vl); + GNUNET_SCHEDULER_add_delayed (rtt, &consider_sending_fc, vl); } @@ -4738,7 +4790,7 @@ consider_sending_fc(void *cls) * @param vl virtual link where we should check for transmission */ static void -check_vl_transmission(struct VirtualLink *vl) +check_vl_transmission (struct VirtualLink *vl) { struct Neighbour *n = vl->n; struct DistanceVector *dv = vl->dv; @@ -4750,57 +4802,57 @@ check_vl_transmission(struct VirtualLink *vl) elig = GNUNET_NO; for (struct PendingMessage *pm = vl->pending_msg_head; NULL != pm; pm = pm->next_vl) - { - if (NULL != pm->qe) - continue; /* not eligible, is in a queue! */ - if (pm->bytes_msg + vl->outbound_fc_window_size_used > - vl->outbound_fc_window_size) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Stalled transmision on VL %s due to flow control: %llu < %llu\n", - GNUNET_i2s(&vl->target), - (unsigned long long)vl->outbound_fc_window_size, - (unsigned long long)(pm->bytes_msg + - vl->outbound_fc_window_size_used)); - consider_sending_fc(vl); - return; /* We have a message, but flow control says "nope" */ - } - elig = GNUNET_YES; - break; - } + { + if (NULL != pm->qe) + continue; /* not eligible, is in a queue! */ + if (pm->bytes_msg + vl->outbound_fc_window_size_used > + vl->outbound_fc_window_size) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Stalled transmision on VL %s due to flow control: %llu < %llu\n", + GNUNET_i2s (&vl->target), + (unsigned long long) vl->outbound_fc_window_size, + (unsigned long long) (pm->bytes_msg + + vl->outbound_fc_window_size_used)); + consider_sending_fc (vl); + return; /* We have a message, but flow control says "nope" */ + } + elig = GNUNET_YES; + break; + } if (GNUNET_NO == elig) return; /* Notify queues at direct neighbours that we are interested */ - now = GNUNET_TIME_absolute_get(); + now = GNUNET_TIME_absolute_get (); if (NULL != n) + { + for (struct Queue *queue = n->queue_head; NULL != queue; + queue = queue->next_neighbour) + if ((GNUNET_YES == queue->idle) && + (queue->validated_until.abs_value_us > now.abs_value_us)) + schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + } + /* Notify queues via DV that we are interested */ + if (NULL != dv) + { + /* Do DV with lower scheduler priority, which effectively means that + IF a neighbour exists and is available, we prefer it. */ + for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; + pos = pos->next_dv) { - for (struct Queue *queue = n->queue_head; NULL != queue; + struct Neighbour *nh = pos->next_hop; + + if (pos->path_valid_until.abs_value_us <= now.abs_value_us) + continue; /* skip this one: path not validated */ + for (struct Queue *queue = nh->queue_head; NULL != queue; queue = queue->next_neighbour) if ((GNUNET_YES == queue->idle) && (queue->validated_until.abs_value_us > now.abs_value_us)) - schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - } - /* Notify queues via DV that we are interested */ - if (NULL != dv) - { - /* Do DV with lower scheduler priority, which effectively means that - IF a neighbour exists and is available, we prefer it. */ - for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; - pos = pos->next_dv) - { - struct Neighbour *nh = pos->next_hop; - - if (pos->path_valid_until.abs_value_us <= now.abs_value_us) - continue; /* skip this one: path not validated */ - for (struct Queue *queue = nh->queue_head; NULL != queue; - queue = queue->next_neighbour) - if ((GNUNET_YES == queue->idle) && - (queue->validated_until.abs_value_us > now.abs_value_us)) - schedule_transmit_on_queue(queue, - GNUNET_SCHEDULER_PRIORITY_BACKGROUND); - } + schedule_transmit_on_queue (queue, + GNUNET_SCHEDULER_PRIORITY_BACKGROUND); } + } } @@ -4811,7 +4863,7 @@ check_vl_transmission(struct VirtualLink *vl) * @param obm the send message that was sent */ static void -handle_client_send(void *cls, const struct OutboundMessage *obm) +handle_client_send (void *cls, const struct OutboundMessage *obm) { struct TransportClient *tc = cls; struct PendingMessage *pm; @@ -4820,46 +4872,46 @@ handle_client_send(void *cls, const struct OutboundMessage *obm) struct VirtualLink *vl; enum GNUNET_MQ_PriorityPreferences pp; - GNUNET_assert(CT_CORE == tc->type); - obmm = (const struct GNUNET_MessageHeader *)&obm[1]; - bytes_msg = ntohs(obmm->size); - pp = (enum GNUNET_MQ_PriorityPreferences)ntohl(obm->priority); - vl = lookup_virtual_link(&obm->peer); + GNUNET_assert (CT_CORE == tc->type); + obmm = (const struct GNUNET_MessageHeader *) &obm[1]; + bytes_msg = ntohs (obmm->size); + pp = (enum GNUNET_MQ_PriorityPreferences) ntohl (obm->priority); + vl = lookup_virtual_link (&obm->peer); if (NULL == vl) - { - /* Failure: don't have this peer as a neighbour (anymore). - Might have gone down asynchronously, so this is NOT - a protocol violation by CORE. Still count the event, - as this should be rare. */ - GNUNET_SERVICE_client_continue(tc->client); - GNUNET_STATISTICS_update(GST_stats, - "# messages dropped (neighbour unknown)", - 1, - GNUNET_NO); - return; - } + { + /* Failure: don't have this peer as a neighbour (anymore). + Might have gone down asynchronously, so this is NOT + a protocol violation by CORE. Still count the event, + as this should be rare. */ + GNUNET_SERVICE_client_continue (tc->client); + GNUNET_STATISTICS_update (GST_stats, + "# messages dropped (neighbour unknown)", + 1, + GNUNET_NO); + return; + } - pm = GNUNET_malloc(sizeof(struct PendingMessage) + bytes_msg); + pm = GNUNET_malloc (sizeof(struct PendingMessage) + bytes_msg); pm->logging_uuid = logging_uuid_gen++; pm->prefs = pp; pm->client = tc; pm->vl = vl; pm->bytes_msg = bytes_msg; - memcpy(&pm[1], obmm, bytes_msg); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending %u bytes as <%llu> to %s\n", - bytes_msg, - pm->logging_uuid, - GNUNET_i2s(&obm->peer)); - GNUNET_CONTAINER_MDLL_insert(client, - tc->details.core.pending_msg_head, - tc->details.core.pending_msg_tail, - pm); - GNUNET_CONTAINER_MDLL_insert(vl, - vl->pending_msg_head, - vl->pending_msg_tail, - pm); - check_vl_transmission(vl); + memcpy (&pm[1], obmm, bytes_msg); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending %u bytes as <%llu> to %s\n", + bytes_msg, + pm->logging_uuid, + GNUNET_i2s (&obm->peer)); + GNUNET_CONTAINER_MDLL_insert (client, + tc->details.core.pending_msg_head, + tc->details.core.pending_msg_tail, + pm); + GNUNET_CONTAINER_MDLL_insert (vl, + vl->pending_msg_head, + vl->pending_msg_tail, + pm); + check_vl_transmission (vl); } @@ -4873,39 +4925,40 @@ handle_client_send(void *cls, const struct OutboundMessage *obm) * @param cb the send message that was sent */ static void -handle_communicator_backchannel( +handle_communicator_backchannel ( void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) { struct TransportClient *tc = cls; const struct GNUNET_MessageHeader *inbox = - (const struct GNUNET_MessageHeader *)&cb[1]; - uint16_t isize = ntohs(inbox->size); - const char *is = ((const char *)&cb[1]) + isize; + (const struct GNUNET_MessageHeader *) &cb[1]; + uint16_t isize = ntohs (inbox->size); + const char *is = ((const char *) &cb[1]) + isize; char - mbuf[isize + - sizeof(struct TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN; + mbuf[isize + + sizeof(struct + TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN; struct TransportBackchannelEncapsulationMessage *be = - (struct TransportBackchannelEncapsulationMessage *)mbuf; + (struct TransportBackchannelEncapsulationMessage *) mbuf; /* 0-termination of 'is' was checked already in #check_communicator_backchannel() */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Preparing backchannel transmission to %s:%s of type %u\n", - GNUNET_i2s(&cb->pid), - is, - ntohs(inbox->size)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Preparing backchannel transmission to %s:%s of type %u\n", + GNUNET_i2s (&cb->pid), + is, + ntohs (inbox->size)); /* encapsulate and encrypt message */ be->header.type = - htons(GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); - be->header.size = htons(sizeof(mbuf)); - memcpy(&be[1], inbox, isize); - memcpy(&mbuf[sizeof(struct TransportBackchannelEncapsulationMessage) + - isize], - is, - strlen(is) + 1); - route_control_message_without_fc(&cb->pid, &be->header, RMO_DV_ALLOWED); - GNUNET_SERVICE_client_continue(tc->client); + htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); + be->header.size = htons (sizeof(mbuf)); + memcpy (&be[1], inbox, isize); + memcpy (&mbuf[sizeof(struct TransportBackchannelEncapsulationMessage) + + isize], + is, + strlen (is) + 1); + route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED); + GNUNET_SERVICE_client_continue (tc->client); } @@ -4917,17 +4970,17 @@ handle_communicator_backchannel( * @return #GNUNET_OK if message is well-formed */ static int -check_add_address(void *cls, - const struct GNUNET_TRANSPORT_AddAddressMessage *aam) +check_add_address (void *cls, + const struct GNUNET_TRANSPORT_AddAddressMessage *aam) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - GNUNET_MQ_check_zero_termination(aam); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + GNUNET_MQ_check_zero_termination (aam); return GNUNET_OK; } @@ -4938,7 +4991,7 @@ check_add_address(void *cls, * @param cls an `struct AddressListEntry *` */ static void -store_pi(void *cls); +store_pi (void *cls); /** @@ -4948,26 +5001,26 @@ store_pi(void *cls); * @param success #GNUNET_YES if peerstore was successful */ static void -peerstore_store_own_cb(void *cls, int success) +peerstore_store_own_cb (void *cls, int success) { struct AddressListEntry *ale = cls; ale->sc = NULL; if (GNUNET_YES != success) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to store our own address `%s' in peerstore!\n", - ale->address); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to store our own address `%s' in peerstore!\n", + ale->address); else - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Successfully stored our own address `%s' in peerstore!\n", - ale->address); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Successfully stored our own address `%s' in peerstore!\n", + ale->address); /* refresh period is 1/4 of expiration time, that should be plenty without being excessive. */ ale->st = - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(ale->expiration, - 4ULL), - &store_pi, - ale); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration, + 4ULL), + &store_pi, + ale); } @@ -4977,7 +5030,7 @@ peerstore_store_own_cb(void *cls, int success) * @param cls an `struct AddressListEntry *` */ static void -store_pi(void *cls) +store_pi (void *cls) { struct AddressListEntry *ale = cls; void *addr; @@ -4985,36 +5038,36 @@ store_pi(void *cls) struct GNUNET_TIME_Absolute expiration; ale->st = NULL; - expiration = GNUNET_TIME_relative_to_absolute(ale->expiration); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Storing our address `%s' in peerstore until %s!\n", - ale->address, - GNUNET_STRINGS_absolute_time_to_string(expiration)); - GNUNET_HELLO_sign_address(ale->address, - ale->nt, - hello_mono_time, - GST_my_private_key, - &addr, - &addr_len); - ale->sc = GNUNET_PEERSTORE_store(peerstore, - "transport", - &GST_my_identity, - GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, - addr, - addr_len, - expiration, - GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, - &peerstore_store_own_cb, - ale); - GNUNET_free(addr); + expiration = GNUNET_TIME_relative_to_absolute (ale->expiration); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Storing our address `%s' in peerstore until %s!\n", + ale->address, + GNUNET_STRINGS_absolute_time_to_string (expiration)); + GNUNET_HELLO_sign_address (ale->address, + ale->nt, + hello_mono_time, + GST_my_private_key, + &addr, + &addr_len); + ale->sc = GNUNET_PEERSTORE_store (peerstore, + "transport", + &GST_my_identity, + GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, + addr, + addr_len, + expiration, + GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, + &peerstore_store_own_cb, + ale); + GNUNET_free (addr); if (NULL == ale->sc) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Failed to store our address `%s' with peerstore\n", - ale->address); - ale->st = - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &store_pi, ale); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to store our address `%s' with peerstore\n", + ale->address); + ale->st = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &store_pi, ale); + } } @@ -5025,30 +5078,30 @@ store_pi(void *cls) * @param aam the send message that was sent */ static void -handle_add_address(void *cls, - const struct GNUNET_TRANSPORT_AddAddressMessage *aam) +handle_add_address (void *cls, + const struct GNUNET_TRANSPORT_AddAddressMessage *aam) { struct TransportClient *tc = cls; struct AddressListEntry *ale; size_t slen; /* 0-termination of &aam[1] was checked in #check_add_address */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Communicator added address `%s'!\n", - (const char *)&aam[1]); - slen = ntohs(aam->header.size) - sizeof(*aam); - ale = GNUNET_malloc(sizeof(struct AddressListEntry) + slen); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Communicator added address `%s'!\n", + (const char *) &aam[1]); + slen = ntohs (aam->header.size) - sizeof(*aam); + ale = GNUNET_malloc (sizeof(struct AddressListEntry) + slen); ale->tc = tc; - ale->address = (const char *)&ale[1]; - ale->expiration = GNUNET_TIME_relative_ntoh(aam->expiration); + ale->address = (const char *) &ale[1]; + ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration); ale->aid = aam->aid; - ale->nt = (enum GNUNET_NetworkType)ntohl(aam->nt); - memcpy(&ale[1], &aam[1], slen); - GNUNET_CONTAINER_DLL_insert(tc->details.communicator.addr_head, - tc->details.communicator.addr_tail, - ale); - ale->st = GNUNET_SCHEDULER_add_now(&store_pi, ale); - GNUNET_SERVICE_client_continue(tc->client); + ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt); + memcpy (&ale[1], &aam[1], slen); + GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head, + tc->details.communicator.addr_tail, + ale); + ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale); + GNUNET_SERVICE_client_continue (tc->client); } @@ -5059,34 +5112,34 @@ handle_add_address(void *cls, * @param dam the send message that was sent */ static void -handle_del_address(void *cls, - const struct GNUNET_TRANSPORT_DelAddressMessage *dam) +handle_del_address (void *cls, + const struct GNUNET_TRANSPORT_DelAddressMessage *dam) { struct TransportClient *tc = cls; struct AddressListEntry *alen; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } for (struct AddressListEntry *ale = tc->details.communicator.addr_head; NULL != ale; ale = alen) - { - alen = ale->next; - if (dam->aid != ale->aid) - continue; - GNUNET_assert(ale->tc == tc); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Communicator deleted address `%s'!\n", - ale->address); - free_address_list_entry(ale); - GNUNET_SERVICE_client_continue(tc->client); - } - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); + { + alen = ale->next; + if (dam->aid != ale->aid) + continue; + GNUNET_assert (ale->tc == tc); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Communicator deleted address `%s'!\n", + ale->address); + free_address_list_entry (ale); + GNUNET_SERVICE_client_continue (tc->client); + } + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); } @@ -5098,8 +5151,8 @@ handle_del_address(void *cls, * @param msg message to demultiplex */ static void -demultiplex_with_cmc(struct CommunicatorMessageContext *cmc, - const struct GNUNET_MessageHeader *msg); +demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, + const struct GNUNET_MessageHeader *msg); /** @@ -5110,23 +5163,23 @@ demultiplex_with_cmc(struct CommunicatorMessageContext *cmc, * @param cls a `struct CoreSentContext` */ static void -core_env_sent_cb(void *cls) +core_env_sent_cb (void *cls) { struct CoreSentContext *ctx = cls; struct VirtualLink *vl = ctx->vl; if (NULL == vl) - { - /* lost the link in the meantime, ignore */ - GNUNET_free(ctx); - return; - } - GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, ctx); - GNUNET_assert(vl->incoming_fc_window_size_ram >= ctx->size); + { + /* lost the link in the meantime, ignore */ + GNUNET_free (ctx); + return; + } + GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, ctx); + GNUNET_assert (vl->incoming_fc_window_size_ram >= ctx->size); vl->incoming_fc_window_size_ram -= ctx->size; vl->incoming_fc_window_size_used += ctx->isize; - consider_sending_fc(vl); - GNUNET_free(ctx); + consider_sending_fc (vl); + GNUNET_free (ctx); } @@ -5139,109 +5192,109 @@ core_env_sent_cb(void *cls) * @param mh the message that was received */ static void -handle_raw_message(void *cls, const struct GNUNET_MessageHeader *mh) +handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh) { struct CommunicatorMessageContext *cmc = cls; struct VirtualLink *vl; - uint16_t size = ntohs(mh->size); + uint16_t size = ntohs (mh->size); int have_core; if ((size > UINT16_MAX - sizeof(struct InboundMessage)) || (size < sizeof(struct GNUNET_MessageHeader))) - { - struct GNUNET_SERVICE_Client *client = cmc->tc->client; + { + struct GNUNET_SERVICE_Client *client = cmc->tc->client; - GNUNET_break(0); - finish_cmc_handling(cmc); - GNUNET_SERVICE_client_drop(client); - return; - } - vl = lookup_virtual_link(&cmc->im.sender); + GNUNET_break (0); + finish_cmc_handling (cmc); + GNUNET_SERVICE_client_drop (client); + return; + } + vl = lookup_virtual_link (&cmc->im.sender); if (NULL == vl) - { - /* FIXME: sender is giving us messages for CORE but we don't have - the link up yet! I *suspect* this can happen right now (i.e. - sender has verified us, but we didn't verify sender), but if - we pass this on, CORE would be confused (link down, messages - arrive). We should investigate more if this happens often, - or in a persistent manner, and possibly do "something" about - it. Thus logging as error for now. */ - GNUNET_break_op(0); - GNUNET_STATISTICS_update(GST_stats, - "# CORE messages droped (virtual link still down)", - 1, - GNUNET_NO); - - finish_cmc_handling(cmc); - return; - } + { + /* FIXME: sender is giving us messages for CORE but we don't have + the link up yet! I *suspect* this can happen right now (i.e. + sender has verified us, but we didn't verify sender), but if + we pass this on, CORE would be confused (link down, messages + arrive). We should investigate more if this happens often, + or in a persistent manner, and possibly do "something" about + it. Thus logging as error for now. */ + GNUNET_break_op (0); + GNUNET_STATISTICS_update (GST_stats, + "# CORE messages droped (virtual link still down)", + 1, + GNUNET_NO); + + finish_cmc_handling (cmc); + return; + } if (vl->incoming_fc_window_size_ram > UINT_MAX - size) - { - GNUNET_STATISTICS_update(GST_stats, - "# CORE messages droped (FC arithmetic overflow)", - 1, - GNUNET_NO); + { + GNUNET_STATISTICS_update (GST_stats, + "# CORE messages droped (FC arithmetic overflow)", + 1, + GNUNET_NO); - finish_cmc_handling(cmc); - return; - } + finish_cmc_handling (cmc); + return; + } if (vl->incoming_fc_window_size_ram + size > vl->available_fc_window_size) - { - GNUNET_STATISTICS_update(GST_stats, - "# CORE messages droped (FC window overflow)", - 1, - GNUNET_NO); - finish_cmc_handling(cmc); - return; - } + { + GNUNET_STATISTICS_update (GST_stats, + "# CORE messages droped (FC window overflow)", + 1, + GNUNET_NO); + finish_cmc_handling (cmc); + return; + } /* Forward to all CORE clients */ have_core = GNUNET_NO; for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - struct GNUNET_MQ_Envelope *env; - struct InboundMessage *im; - struct CoreSentContext *ctx; - - if (CT_CORE != tc->type) - continue; - vl->incoming_fc_window_size_ram += size; - env = GNUNET_MQ_msg_extra(im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); - ctx = GNUNET_new(struct CoreSentContext); - ctx->vl = vl; - ctx->size = size; - ctx->isize = (GNUNET_NO == have_core) ? size : 0; - have_core = GNUNET_YES; - GNUNET_CONTAINER_DLL_insert(vl->csc_head, vl->csc_tail, ctx); - GNUNET_MQ_notify_sent(env, &core_env_sent_cb, ctx); - im->peer = cmc->im.sender; - memcpy(&im[1], mh, size); - GNUNET_MQ_send(tc->mq, env); - vl->core_recv_window--; - } + { + struct GNUNET_MQ_Envelope *env; + struct InboundMessage *im; + struct CoreSentContext *ctx; + + if (CT_CORE != tc->type) + continue; + vl->incoming_fc_window_size_ram += size; + env = GNUNET_MQ_msg_extra (im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); + ctx = GNUNET_new (struct CoreSentContext); + ctx->vl = vl; + ctx->size = size; + ctx->isize = (GNUNET_NO == have_core) ? size : 0; + have_core = GNUNET_YES; + GNUNET_CONTAINER_DLL_insert (vl->csc_head, vl->csc_tail, ctx); + GNUNET_MQ_notify_sent (env, &core_env_sent_cb, ctx); + im->peer = cmc->im.sender; + memcpy (&im[1], mh, size); + GNUNET_MQ_send (tc->mq, env); + vl->core_recv_window--; + } if (GNUNET_NO == have_core) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Dropped message to CORE: no CORE client connected!\n"); - /* Nevertheless, count window as used, as it is from the - perspective of the other peer! */ - vl->incoming_fc_window_size_used += size; - /* TODO-M1 */ - finish_cmc_handling(cmc); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Delivered message from %s of type %u to CORE\n", - GNUNET_i2s(&cmc->im.sender), - ntohs(mh->type)); + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Dropped message to CORE: no CORE client connected!\n"); + /* Nevertheless, count window as used, as it is from the + perspective of the other peer! */ + vl->incoming_fc_window_size_used += size; + /* TODO-M1 */ + finish_cmc_handling (cmc); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Delivered message from %s of type %u to CORE\n", + GNUNET_i2s (&cmc->im.sender), + ntohs (mh->type)); if (vl->core_recv_window > 0) - { - finish_cmc_handling(cmc); - return; - } + { + finish_cmc_handling (cmc); + return; + } /* Wait with calling #finish_cmc_handling(cmc) until the message was processed by CORE MQs (for CORE flow control)! */ - GNUNET_CONTAINER_DLL_insert(vl->cmc_head, vl->cmc_tail, cmc); + GNUNET_CONTAINER_DLL_insert (vl->cmc_head, vl->cmc_tail, cmc); } @@ -5253,27 +5306,27 @@ handle_raw_message(void *cls, const struct GNUNET_MessageHeader *mh) * @return #GNUNET_YES if message is well-formed */ static int -check_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb) +check_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) { - uint16_t size = ntohs(fb->header.size); + uint16_t size = ntohs (fb->header.size); uint16_t bsize = size - sizeof(*fb); - (void)cls; + (void) cls; if (0 == bsize) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - if (bsize + ntohs(fb->frag_off) > ntohs(fb->msg_size)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - if (ntohs(fb->frag_off) >= ntohs(fb->msg_size)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + if (bsize + ntohs (fb->frag_off) > ntohs (fb->msg_size)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + if (ntohs (fb->frag_off) >= ntohs (fb->msg_size)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } return GNUNET_YES; } @@ -5284,16 +5337,16 @@ check_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb) * @param cls a `struct AcknowledgementCummulator *` */ static void -destroy_ack_cummulator(void *cls) +destroy_ack_cummulator (void *cls) { struct AcknowledgementCummulator *ac = cls; ac->task = NULL; - GNUNET_assert(0 == ac->num_acks); - GNUNET_assert( + GNUNET_assert (0 == ac->num_acks); + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(ack_cummulators, &ac->target, ac)); - GNUNET_free(ac); + GNUNET_CONTAINER_multipeermap_remove (ack_cummulators, &ac->target, ac)); + GNUNET_free (ac); } @@ -5303,39 +5356,39 @@ destroy_ack_cummulator(void *cls) * @param cls a `struct AcknowledgementCummulator *` */ static void -transmit_cummulative_ack_cb(void *cls) +transmit_cummulative_ack_cb (void *cls) { struct AcknowledgementCummulator *ac = cls; - char buf[sizeof(struct TransportReliabilityAckMessage) + - ac->ack_counter * - sizeof(struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN; + char buf[sizeof(struct TransportReliabilityAckMessage) + + ac->ack_counter + * sizeof(struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN; struct TransportReliabilityAckMessage *ack = - (struct TransportReliabilityAckMessage *)buf; + (struct TransportReliabilityAckMessage *) buf; struct TransportCummulativeAckPayloadP *ap; ac->task = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending ACK with %u components to %s\n", - ac->ack_counter, - GNUNET_i2s(&ac->target)); - GNUNET_assert(0 < ac->ack_counter); - ack->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending ACK with %u components to %s\n", + ac->ack_counter, + GNUNET_i2s (&ac->target)); + GNUNET_assert (0 < ac->ack_counter); + ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); ack->header.size = - htons(sizeof(*ack) + - ac->ack_counter * sizeof(struct TransportCummulativeAckPayloadP)); - ack->ack_counter = htonl(ac->ack_counter++); - ap = (struct TransportCummulativeAckPayloadP *)&ack[1]; + htons (sizeof(*ack) + + ac->ack_counter * sizeof(struct TransportCummulativeAckPayloadP)); + ack->ack_counter = htonl (ac->ack_counter++); + ap = (struct TransportCummulativeAckPayloadP *) &ack[1]; for (unsigned int i = 0; i < ac->ack_counter; i++) - { - ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid; - ap[i].ack_delay = GNUNET_TIME_relative_hton( - GNUNET_TIME_absolute_get_duration(ac->ack_uuids[i].receive_time)); - } - route_control_message_without_fc(&ac->target, &ack->header, RMO_DV_ALLOWED); + { + ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid; + ap[i].ack_delay = GNUNET_TIME_relative_hton ( + GNUNET_TIME_absolute_get_duration (ac->ack_uuids[i].receive_time)); + } + route_control_message_without_fc (&ac->target, &ack->header, RMO_DV_ALLOWED); ac->num_acks = 0; - ac->task = GNUNET_SCHEDULER_add_delayed(ACK_CUMMULATOR_TIMEOUT, - &destroy_ack_cummulator, - ac); + ac->task = GNUNET_SCHEDULER_add_delayed (ACK_CUMMULATOR_TIMEOUT, + &destroy_ack_cummulator, + ac); } @@ -5348,55 +5401,56 @@ transmit_cummulative_ack_cb(void *cls) * @param max_delay how long can the ACK wait */ static void -cummulative_ack(const struct GNUNET_PeerIdentity *pid, - const struct AcknowledgementUUIDP *ack_uuid, - struct GNUNET_TIME_Absolute max_delay) +cummulative_ack (const struct GNUNET_PeerIdentity *pid, + const struct AcknowledgementUUIDP *ack_uuid, + struct GNUNET_TIME_Absolute max_delay) { struct AcknowledgementCummulator *ac; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Scheduling ACK %s for transmission to %s\n", - GNUNET_uuid2s(&ack_uuid->value), - GNUNET_i2s(pid)); - ac = GNUNET_CONTAINER_multipeermap_get(ack_cummulators, pid); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling ACK %s for transmission to %s\n", + GNUNET_uuid2s (&ack_uuid->value), + GNUNET_i2s (pid)); + ac = GNUNET_CONTAINER_multipeermap_get (ack_cummulators, pid); if (NULL == ac) - { - ac = GNUNET_new(struct AcknowledgementCummulator); - ac->target = *pid; - ac->min_transmission_time = max_delay; - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put( - ack_cummulators, - &ac->target, - ac, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } + { + ac = GNUNET_new (struct AcknowledgementCummulator); + ac->target = *pid; + ac->min_transmission_time = max_delay; + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put ( + ack_cummulators, + &ac->target, + ac, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } else + { + if (MAX_CUMMULATIVE_ACKS == ac->num_acks) { - if (MAX_CUMMULATIVE_ACKS == ac->num_acks) - { - /* must run immediately, ack buffer full! */ - GNUNET_SCHEDULER_cancel(ac->task); - transmit_cummulative_ack_cb(ac); - } - GNUNET_SCHEDULER_cancel(ac->task); - ac->min_transmission_time = - GNUNET_TIME_absolute_min(ac->min_transmission_time, max_delay); + /* must run immediately, ack buffer full! */ + GNUNET_SCHEDULER_cancel (ac->task); + transmit_cummulative_ack_cb (ac); } - GNUNET_assert(ac->num_acks < MAX_CUMMULATIVE_ACKS); - ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get(); + GNUNET_SCHEDULER_cancel (ac->task); + ac->min_transmission_time = + GNUNET_TIME_absolute_min (ac->min_transmission_time, max_delay); + } + GNUNET_assert (ac->num_acks < MAX_CUMMULATIVE_ACKS); + ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get (); ac->ack_uuids[ac->num_acks].ack_uuid = *ack_uuid; ac->num_acks++; - ac->task = GNUNET_SCHEDULER_add_at(ac->min_transmission_time, - &transmit_cummulative_ack_cb, - ac); + ac->task = GNUNET_SCHEDULER_add_at (ac->min_transmission_time, + &transmit_cummulative_ack_cb, + ac); } /** * Closure for #find_by_message_uuid. */ -struct FindByMessageUuidContext { +struct FindByMessageUuidContext +{ /** * UUID to look for. */ @@ -5419,17 +5473,17 @@ struct FindByMessageUuidContext { * @return #GNUNET_YES if not found, #GNUNET_NO if found */ static int -find_by_message_uuid(void *cls, uint32_t key, void *value) +find_by_message_uuid (void *cls, uint32_t key, void *value) { struct FindByMessageUuidContext *fc = cls; struct ReassemblyContext *rc = value; - (void)key; - if (0 == GNUNET_memcmp(&fc->message_uuid, &rc->msg_uuid)) - { - fc->rc = rc; - return GNUNET_NO; - } + (void) key; + if (0 == GNUNET_memcmp (&fc->message_uuid, &rc->msg_uuid)) + { + fc->rc = rc; + return GNUNET_NO; + } return GNUNET_YES; } @@ -5442,7 +5496,7 @@ find_by_message_uuid(void *cls, uint32_t key, void *value) * @param fb the message that was received */ static void -handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb) +handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) { struct CommunicatorMessageContext *cmc = cls; struct Neighbour *n; @@ -5455,142 +5509,142 @@ handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb) struct GNUNET_TIME_Relative cdelay; struct FindByMessageUuidContext fc; - n = lookup_neighbour(&cmc->im.sender); + n = lookup_neighbour (&cmc->im.sender); if (NULL == n) - { - struct GNUNET_SERVICE_Client *client = cmc->tc->client; + { + struct GNUNET_SERVICE_Client *client = cmc->tc->client; - GNUNET_break(0); - finish_cmc_handling(cmc); - GNUNET_SERVICE_client_drop(client); - return; - } + GNUNET_break (0); + finish_cmc_handling (cmc); + GNUNET_SERVICE_client_drop (client); + return; + } if (NULL == n->reassembly_map) - { - n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create(8); - n->reassembly_heap = - GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); - n->reassembly_timeout_task = - GNUNET_SCHEDULER_add_delayed(REASSEMBLY_EXPIRATION, - &reassembly_cleanup_task, - n); - } - msize = ntohs(fb->msg_size); + { + n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create (8); + n->reassembly_heap = + GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); + n->reassembly_timeout_task = + GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION, + &reassembly_cleanup_task, + n); + } + msize = ntohs (fb->msg_size); fc.message_uuid = fb->msg_uuid; fc.rc = NULL; - (void)GNUNET_CONTAINER_multihashmap32_get_multiple(n->reassembly_map, - fb->msg_uuid.uuid, - &find_by_message_uuid, - &fc); + (void) GNUNET_CONTAINER_multihashmap32_get_multiple (n->reassembly_map, + fb->msg_uuid.uuid, + &find_by_message_uuid, + &fc); if (NULL == (rc = fc.rc)) - { - rc = GNUNET_malloc(sizeof(*rc) + msize + /* reassembly payload buffer */ - (msize + 7) / 8 * sizeof(uint8_t) /* bitfield */); - rc->msg_uuid = fb->msg_uuid; - rc->neighbour = n; - rc->msg_size = msize; - rc->reassembly_timeout = - GNUNET_TIME_relative_to_absolute(REASSEMBLY_EXPIRATION); - rc->last_frag = GNUNET_TIME_absolute_get(); - rc->hn = GNUNET_CONTAINER_heap_insert(n->reassembly_heap, - rc, - rc->reassembly_timeout.abs_value_us); - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_put( - n->reassembly_map, - rc->msg_uuid.uuid, - rc, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - target = (char *)&rc[1]; - rc->bitfield = (uint8_t *)(target + rc->msg_size); - rc->msg_missing = rc->msg_size; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received fragment at offset %u/%u from %s for NEW message %u\n", - ntohs(fb->frag_off), - msize, - GNUNET_i2s(&cmc->im.sender), - (unsigned int)fb->msg_uuid.uuid); - } + { + rc = GNUNET_malloc (sizeof(*rc) + msize /* reassembly payload buffer */ + + (msize + 7) / 8 * sizeof(uint8_t) /* bitfield */); + rc->msg_uuid = fb->msg_uuid; + rc->neighbour = n; + rc->msg_size = msize; + rc->reassembly_timeout = + GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION); + rc->last_frag = GNUNET_TIME_absolute_get (); + rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap, + rc, + rc->reassembly_timeout.abs_value_us); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multihashmap32_put ( + n->reassembly_map, + rc->msg_uuid.uuid, + rc, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + target = (char *) &rc[1]; + rc->bitfield = (uint8_t *) (target + rc->msg_size); + rc->msg_missing = rc->msg_size; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received fragment at offset %u/%u from %s for NEW message %u\n", + ntohs (fb->frag_off), + msize, + GNUNET_i2s (&cmc->im.sender), + (unsigned int) fb->msg_uuid.uuid); + } else - { - target = (char *)&rc[1]; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received fragment at offset %u/%u from %s for message %u\n", - ntohs(fb->frag_off), - msize, - GNUNET_i2s(&cmc->im.sender), - (unsigned int)fb->msg_uuid.uuid); - } + { + target = (char *) &rc[1]; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received fragment at offset %u/%u from %s for message %u\n", + ntohs (fb->frag_off), + msize, + GNUNET_i2s (&cmc->im.sender), + (unsigned int) fb->msg_uuid.uuid); + } if (msize != rc->msg_size) - { - GNUNET_break(0); - finish_cmc_handling(cmc); - return; - } + { + GNUNET_break (0); + finish_cmc_handling (cmc); + return; + } /* reassemble */ - fsize = ntohs(fb->header.size) - sizeof(*fb); + fsize = ntohs (fb->header.size) - sizeof(*fb); if (0 == fsize) - { - GNUNET_break(0); - finish_cmc_handling(cmc); - return; - } - frag_off = ntohs(fb->frag_off); + { + GNUNET_break (0); + finish_cmc_handling (cmc); + return; + } + frag_off = ntohs (fb->frag_off); if (frag_off + fsize > msize) - { - /* Fragment (plus fragment size) exceeds message size! */ - GNUNET_break_op(0); - finish_cmc_handling(cmc); - return; - } - memcpy(&target[frag_off], &fb[1], fsize); + { + /* Fragment (plus fragment size) exceeds message size! */ + GNUNET_break_op (0); + finish_cmc_handling (cmc); + return; + } + memcpy (&target[frag_off], &fb[1], fsize); /* update bitfield and msg_missing */ for (unsigned int i = frag_off; i < frag_off + fsize; i++) + { + if (0 == (rc->bitfield[i / 8] & (1 << (i % 8)))) { - if (0 == (rc->bitfield[i / 8] & (1 << (i % 8)))) - { - rc->bitfield[i / 8] |= (1 << (i % 8)); - rc->msg_missing--; - } + rc->bitfield[i / 8] |= (1 << (i % 8)); + rc->msg_missing--; } + } /* Compute cummulative ACK */ - cdelay = GNUNET_TIME_absolute_get_duration(rc->last_frag); - cdelay = GNUNET_TIME_relative_multiply(cdelay, rc->msg_missing / fsize); + cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag); + cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->msg_missing / fsize); if (0 == rc->msg_missing) cdelay = GNUNET_TIME_UNIT_ZERO; - cummulative_ack(&cmc->im.sender, - &fb->ack_uuid, - GNUNET_TIME_relative_to_absolute(cdelay)); - rc->last_frag = GNUNET_TIME_absolute_get(); + cummulative_ack (&cmc->im.sender, + &fb->ack_uuid, + GNUNET_TIME_relative_to_absolute (cdelay)); + rc->last_frag = GNUNET_TIME_absolute_get (); /* is reassembly complete? */ if (0 != rc->msg_missing) - { - finish_cmc_handling(cmc); - return; - } + { + finish_cmc_handling (cmc); + return; + } /* reassembly is complete, verify result */ - msg = (const struct GNUNET_MessageHeader *)&rc[1]; - if (ntohs(msg->size) != rc->msg_size) - { - GNUNET_break(0); - free_reassembly_context(rc); - finish_cmc_handling(cmc); - return; - } + msg = (const struct GNUNET_MessageHeader *) &rc[1]; + if (ntohs (msg->size) != rc->msg_size) + { + GNUNET_break (0); + free_reassembly_context (rc); + finish_cmc_handling (cmc); + return; + } /* successful reassembly */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Fragment reassembly complete for message %u\n", - (unsigned int)fb->msg_uuid.uuid); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Fragment reassembly complete for message %u\n", + (unsigned int) fb->msg_uuid.uuid); /* FIXME: check that the resulting msg is NOT a DV Box or Reliability Box, as that is NOT allowed! */ - demultiplex_with_cmc(cmc, msg); + demultiplex_with_cmc (cmc, msg); /* FIXME-OPTIMIZE: really free here? Might be bad if fragments are still en-route and we forget that we finished this reassembly immediately! -> keep around until timeout? -> shorten timeout based on ACK? */ - free_reassembly_context(rc); + free_reassembly_context (rc); } @@ -5602,11 +5656,11 @@ handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb) * @return #GNUNET_YES if message is well-formed */ static int -check_reliability_box(void *cls, - const struct TransportReliabilityBoxMessage *rb) +check_reliability_box (void *cls, + const struct TransportReliabilityBoxMessage *rb) { - (void)cls; - GNUNET_MQ_check_boxed_message(rb); + (void) cls; + GNUNET_MQ_check_boxed_message (rb); return GNUNET_YES; } @@ -5619,34 +5673,34 @@ check_reliability_box(void *cls, * @param rb the message that was received */ static void -handle_reliability_box(void *cls, - const struct TransportReliabilityBoxMessage *rb) +handle_reliability_box (void *cls, + const struct TransportReliabilityBoxMessage *rb) { struct CommunicatorMessageContext *cmc = cls; const struct GNUNET_MessageHeader *inbox = - (const struct GNUNET_MessageHeader *)&rb[1]; + (const struct GNUNET_MessageHeader *) &rb[1]; struct GNUNET_TIME_Relative rtt; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received reliability box from %s with UUID %s of type %u\n", - GNUNET_i2s(&cmc->im.sender), - GNUNET_uuid2s(&rb->ack_uuid.value), - (unsigned int)ntohs(inbox->type)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received reliability box from %s with UUID %s of type %u\n", + GNUNET_i2s (&cmc->im.sender), + GNUNET_uuid2s (&rb->ack_uuid.value), + (unsigned int) ntohs (inbox->type)); rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we do not really have an RTT for the * incoming* queue (should we have the sender add it to the rb message?) */ - cummulative_ack( + cummulative_ack ( &cmc->im.sender, &rb->ack_uuid, - (0 == ntohl(rb->ack_countdown)) + (0 == ntohl (rb->ack_countdown)) ? GNUNET_TIME_UNIT_ZERO_ABS - : GNUNET_TIME_relative_to_absolute( - GNUNET_TIME_relative_divide(rtt, 8 /* FIXME: magic constant */))); + : GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_relative_divide (rtt, 8 /* FIXME: magic constant */))); /* continue with inner message */ /* FIXME: check that inbox is NOT a DV Box, fragment or another reliability box (not allowed!) */ - demultiplex_with_cmc(cmc, inbox); + demultiplex_with_cmc (cmc, inbox); } @@ -5659,20 +5713,20 @@ handle_reliability_box(void *cls, * @param age current age */ static void -update_pd_age(struct PerformanceData *pd, unsigned int age) +update_pd_age (struct PerformanceData *pd, unsigned int age) { unsigned int sage; if (age == pd->last_age) return; /* nothing to do */ - sage = GNUNET_MAX(pd->last_age, age - 2 * GOODPUT_AGING_SLOTS); + sage = GNUNET_MAX (pd->last_age, age - 2 * GOODPUT_AGING_SLOTS); for (unsigned int i = sage; i <= age - GOODPUT_AGING_SLOTS; i++) - { - struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS]; + { + struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS]; - the->bytes_sent = 0; - the->bytes_received = 0; - } + the->bytes_sent = 0; + the->bytes_received = 0; + } pd->last_age = age; } @@ -5686,20 +5740,20 @@ update_pd_age(struct PerformanceData *pd, unsigned int age) * @param bytes_transmitted_ok number of bytes receiver confirmed as received */ static void -update_performance_data(struct PerformanceData *pd, - struct GNUNET_TIME_Relative rtt, - uint16_t bytes_transmitted_ok) +update_performance_data (struct PerformanceData *pd, + struct GNUNET_TIME_Relative rtt, + uint16_t bytes_transmitted_ok) { uint64_t nval = rtt.rel_value_us; uint64_t oval = pd->aged_rtt.rel_value_us; - unsigned int age = get_age(); + unsigned int age = get_age (); struct TransmissionHistoryEntry *the = &pd->the[age % GOODPUT_AGING_SLOTS]; if (oval == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) pd->aged_rtt = rtt; else pd->aged_rtt.rel_value_us = (nval + 7 * oval) / 8; - update_pd_age(pd, age); + update_pd_age (pd, age); the->bytes_received += bytes_transmitted_ok; } @@ -5712,11 +5766,11 @@ update_performance_data(struct PerformanceData *pd, * @param bytes_transmitted_ok number of bytes successfully transmitted */ static void -update_queue_performance(struct Queue *q, - struct GNUNET_TIME_Relative rtt, - uint16_t bytes_transmitted_ok) +update_queue_performance (struct Queue *q, + struct GNUNET_TIME_Relative rtt, + uint16_t bytes_transmitted_ok) { - update_performance_data(&q->pd, rtt, bytes_transmitted_ok); + update_performance_data (&q->pd, rtt, bytes_transmitted_ok); } @@ -5728,11 +5782,11 @@ update_queue_performance(struct Queue *q, * @param bytes_transmitted_ok number of bytes successfully transmitted */ static void -update_dvh_performance(struct DistanceVectorHop *dvh, - struct GNUNET_TIME_Relative rtt, - uint16_t bytes_transmitted_ok) +update_dvh_performance (struct DistanceVectorHop *dvh, + struct GNUNET_TIME_Relative rtt, + uint16_t bytes_transmitted_ok) { - update_performance_data(&dvh->pd, rtt, bytes_transmitted_ok); + update_performance_data (&dvh->pd, rtt, bytes_transmitted_ok); } @@ -5744,47 +5798,47 @@ update_dvh_performance(struct DistanceVectorHop *dvh, * @param pm pending message that was transmitted */ static void -completed_pending_message(struct PendingMessage *pm) +completed_pending_message (struct PendingMessage *pm) { struct PendingMessage *pos; switch (pm->pmt) - { - case PMT_CORE: - case PMT_RELIABILITY_BOX: - /* Full message sent, we are done */ - client_send_response(pm); - return; + { + case PMT_CORE: + case PMT_RELIABILITY_BOX: + /* Full message sent, we are done */ + client_send_response (pm); + return; - case PMT_FRAGMENT_BOX: - /* Fragment sent over reliabile channel */ - free_fragment_tree(pm); + case PMT_FRAGMENT_BOX: + /* Fragment sent over reliabile channel */ + free_fragment_tree (pm); + pos = pm->frag_parent; + GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm); + GNUNET_free (pm); + /* check if subtree is done */ + while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) && + (pos != pm)) + { + pm = pos; pos = pm->frag_parent; - GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm); - GNUNET_free(pm); - /* check if subtree is done */ - while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) && - (pos != pm)) - { - pm = pos; - pos = pm->frag_parent; - GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm); - GNUNET_free(pm); - } + GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm); + GNUNET_free (pm); + } - /* Was this the last applicable fragmment? */ - if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) && - (pos->frag_off == pos->bytes_msg)) - client_send_response(pos); - return; + /* Was this the last applicable fragmment? */ + if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) && + (pos->frag_off == pos->bytes_msg)) + client_send_response (pos); + return; - case PMT_DV_BOX: - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Completed transmission of message %llu (DV Box)\n", - pm->logging_uuid); - free_pending_message(pm); - return; - } + case PMT_DV_BOX: + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Completed transmission of message %llu (DV Box)\n", + pm->logging_uuid); + free_pending_message (pm); + return; + } } @@ -5796,23 +5850,23 @@ completed_pending_message(struct PendingMessage *pm) * other peer */ static void -handle_acknowledged(struct PendingAcknowledgement *pa, - struct GNUNET_TIME_Relative ack_delay) +handle_acknowledged (struct PendingAcknowledgement *pa, + struct GNUNET_TIME_Relative ack_delay) { struct GNUNET_TIME_Relative delay; - delay = GNUNET_TIME_absolute_get_duration(pa->transmission_time); + delay = GNUNET_TIME_absolute_get_duration (pa->transmission_time); if (delay.rel_value_us > ack_delay.rel_value_us) delay = GNUNET_TIME_UNIT_ZERO; else - delay = GNUNET_TIME_relative_subtract(delay, ack_delay); + delay = GNUNET_TIME_relative_subtract (delay, ack_delay); if (NULL != pa->queue) - update_queue_performance(pa->queue, delay, pa->message_size); + update_queue_performance (pa->queue, delay, pa->message_size); if (NULL != pa->dvh) - update_dvh_performance(pa->dvh, delay, pa->message_size); + update_dvh_performance (pa->dvh, delay, pa->message_size); if (NULL != pa->pm) - completed_pending_message(pa->pm); - free_pending_acknowledgement(pa); + completed_pending_message (pa->pm); + free_pending_acknowledgement (pa); } @@ -5824,25 +5878,25 @@ handle_acknowledged(struct PendingAcknowledgement *pa, * @return #GNUNET_Ok if @a ra is well-formed */ static int -check_reliability_ack(void *cls, - const struct TransportReliabilityAckMessage *ra) +check_reliability_ack (void *cls, + const struct TransportReliabilityAckMessage *ra) { unsigned int n_acks; - (void)cls; - n_acks = (ntohs(ra->header.size) - sizeof(*ra)) / - sizeof(struct TransportCummulativeAckPayloadP); + (void) cls; + n_acks = (ntohs (ra->header.size) - sizeof(*ra)) + / sizeof(struct TransportCummulativeAckPayloadP); if (0 == n_acks) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - if ((ntohs(ra->header.size) - sizeof(*ra)) != + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + if ((ntohs (ra->header.size) - sizeof(*ra)) != n_acks * sizeof(struct TransportCummulativeAckPayloadP)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -5855,46 +5909,46 @@ check_reliability_ack(void *cls, * @param ra the message that was received */ static void -handle_reliability_ack(void *cls, - const struct TransportReliabilityAckMessage *ra) +handle_reliability_ack (void *cls, + const struct TransportReliabilityAckMessage *ra) { struct CommunicatorMessageContext *cmc = cls; const struct TransportCummulativeAckPayloadP *ack; unsigned int n_acks; uint32_t ack_counter; - n_acks = (ntohs(ra->header.size) - sizeof(*ra)) / - sizeof(struct TransportCummulativeAckPayloadP); - ack = (const struct TransportCummulativeAckPayloadP *)&ra[1]; + n_acks = (ntohs (ra->header.size) - sizeof(*ra)) + / sizeof(struct TransportCummulativeAckPayloadP); + ack = (const struct TransportCummulativeAckPayloadP *) &ra[1]; for (unsigned int i = 0; i < n_acks; i++) - { - struct PendingAcknowledgement *pa = - GNUNET_CONTAINER_multiuuidmap_get(pending_acks, &ack[i].ack_uuid.value); - if (NULL == pa) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Received ACK from %s with UUID %s which is unknown to us!\n", - GNUNET_i2s(&cmc->im.sender), - GNUNET_uuid2s(&ack[i].ack_uuid.value)); - GNUNET_STATISTICS_update( - GST_stats, - "# FRAGMENT_ACKS dropped, no matching pending message", - 1, - GNUNET_NO); - continue; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received ACK from %s with UUID %s\n", - GNUNET_i2s(&cmc->im.sender), - GNUNET_uuid2s(&ack[i].ack_uuid.value)); - handle_acknowledged(pa, GNUNET_TIME_relative_ntoh(ack[i].ack_delay)); + { + struct PendingAcknowledgement *pa = + GNUNET_CONTAINER_multiuuidmap_get (pending_acks, &ack[i].ack_uuid.value); + if (NULL == pa) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Received ACK from %s with UUID %s which is unknown to us!\n", + GNUNET_i2s (&cmc->im.sender), + GNUNET_uuid2s (&ack[i].ack_uuid.value)); + GNUNET_STATISTICS_update ( + GST_stats, + "# FRAGMENT_ACKS dropped, no matching pending message", + 1, + GNUNET_NO); + continue; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received ACK from %s with UUID %s\n", + GNUNET_i2s (&cmc->im.sender), + GNUNET_uuid2s (&ack[i].ack_uuid.value)); + handle_acknowledged (pa, GNUNET_TIME_relative_ntoh (ack[i].ack_delay)); + } - ack_counter = htonl(ra->ack_counter); - (void)ack_counter; /* silence compiler warning for now */ + ack_counter = htonl (ra->ack_counter); + (void) ack_counter; /* silence compiler warning for now */ // FIXME-OPTIMIZE: track ACK losses based on ack_counter somewhere! // (DV and/or Neighbour?) - finish_cmc_handling(cmc); + finish_cmc_handling (cmc); } @@ -5906,30 +5960,30 @@ handle_reliability_ack(void *cls, * @return #GNUNET_YES if message is well-formed */ static int -check_backchannel_encapsulation( +check_backchannel_encapsulation ( void *cls, const struct TransportBackchannelEncapsulationMessage *be) { - uint16_t size = ntohs(be->header.size) - sizeof(*be); + uint16_t size = ntohs (be->header.size) - sizeof(*be); const struct GNUNET_MessageHeader *inbox = - (const struct GNUNET_MessageHeader *)&be[1]; + (const struct GNUNET_MessageHeader *) &be[1]; const char *is; uint16_t isize; - (void)cls; - if (ntohs(inbox->size) >= size) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - isize = ntohs(inbox->size); - is = ((const char *)inbox) + isize; + (void) cls; + if (ntohs (inbox->size) >= size) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + isize = ntohs (inbox->size); + is = ((const char *) inbox) + isize; size -= isize; if ('\0' != is[size - 1]) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } return GNUNET_YES; } @@ -5943,7 +5997,7 @@ check_backchannel_encapsulation( * @param be the message that was received */ static void -handle_backchannel_encapsulation( +handle_backchannel_encapsulation ( void *cls, const struct TransportBackchannelEncapsulationMessage *be) { @@ -5952,41 +6006,41 @@ handle_backchannel_encapsulation( struct GNUNET_MQ_Envelope *env; struct TransportClient *tc; const struct GNUNET_MessageHeader *inbox = - (const struct GNUNET_MessageHeader *)&be[1]; - uint16_t isize = ntohs(inbox->size); - const char *target_communicator = ((const char *)inbox) + isize; + (const struct GNUNET_MessageHeader *) &be[1]; + uint16_t isize = ntohs (inbox->size); + const char *target_communicator = ((const char *) inbox) + isize; /* Find client providing this communicator */ for (tc = clients_head; NULL != tc; tc = tc->next) if ((CT_COMMUNICATOR == tc->type) && (0 == - strcmp(tc->details.communicator.address_prefix, target_communicator))) + strcmp (tc->details.communicator.address_prefix, target_communicator))) break; if (NULL == tc) - { - char *stastr; - - GNUNET_asprintf( - &stastr, - "# Backchannel message dropped: target communicator `%s' unknown", - target_communicator); - GNUNET_STATISTICS_update(GST_stats, stastr, 1, GNUNET_NO); - GNUNET_free(stastr); - return; - } + { + char *stastr; + + GNUNET_asprintf ( + &stastr, + "# Backchannel message dropped: target communicator `%s' unknown", + target_communicator); + GNUNET_STATISTICS_update (GST_stats, stastr, 1, GNUNET_NO); + GNUNET_free (stastr); + return; + } /* Finally, deliver backchannel message to communicator */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Delivering backchannel message from %s of type %u to %s\n", - GNUNET_i2s(&cmc->im.sender), - ntohs(inbox->type), - target_communicator); - env = GNUNET_MQ_msg_extra( + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Delivering backchannel message from %s of type %u to %s\n", + GNUNET_i2s (&cmc->im.sender), + ntohs (inbox->type), + target_communicator); + env = GNUNET_MQ_msg_extra ( cbi, isize, GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING); cbi->pid = cmc->im.sender; - memcpy(&cbi[1], inbox, isize); - GNUNET_MQ_send(tc->mq, env); + memcpy (&cbi[1], inbox, isize); + GNUNET_MQ_send (tc->mq, env); } @@ -6000,26 +6054,26 @@ handle_backchannel_encapsulation( * @param cls a `struct DistanceVector` */ static void -path_cleanup_cb(void *cls) +path_cleanup_cb (void *cls) { struct DistanceVector *dv = cls; struct DistanceVectorHop *pos; dv->timeout_task = NULL; while (NULL != (pos = dv->dv_head)) - { - GNUNET_assert(dv == pos->dv); - if (GNUNET_TIME_absolute_get_remaining(pos->timeout).rel_value_us > 0) - break; - free_distance_vector_hop(pos); - } + { + GNUNET_assert (dv == pos->dv); + if (GNUNET_TIME_absolute_get_remaining (pos->timeout).rel_value_us > 0) + break; + free_distance_vector_hop (pos); + } if (NULL == pos) - { - free_dv_route(dv); - return; - } + { + free_dv_route (dv); + return; + } dv->timeout_task = - GNUNET_SCHEDULER_add_at(pos->timeout, &path_cleanup_cb, dv); + GNUNET_SCHEDULER_add_at (pos->timeout, &path_cleanup_cb, dv); } @@ -6031,44 +6085,44 @@ path_cleanup_cb(void *cls) * @param hop a path to some peer that is the reason for activation */ static void -activate_core_visible_dv_path(struct DistanceVectorHop *hop) +activate_core_visible_dv_path (struct DistanceVectorHop *hop) { struct DistanceVector *dv = hop->dv; struct VirtualLink *vl; - vl = lookup_virtual_link(&dv->target); + vl = lookup_virtual_link (&dv->target); if (NULL != vl) - { - /* Link was already up, remember dv is also now available and we are done */ - vl->dv = dv; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Virtual link to %s could now also use DV!\n", - GNUNET_i2s(&dv->target)); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Creating new virtual link to %s using DV!\n", - GNUNET_i2s(&dv->target)); - vl = GNUNET_new(struct VirtualLink); + { + /* Link was already up, remember dv is also now available and we are done */ + vl->dv = dv; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Virtual link to %s could now also use DV!\n", + GNUNET_i2s (&dv->target)); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Creating new virtual link to %s using DV!\n", + GNUNET_i2s (&dv->target)); + vl = GNUNET_new (struct VirtualLink); vl->message_uuid_ctr = - GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); vl->target = dv->target; vl->dv = dv; dv->vl = vl; vl->core_recv_window = RECV_WINDOW_SIZE; vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; vl->visibility_task = - GNUNET_SCHEDULER_add_at(hop->path_valid_until, &check_link_down, vl); - GNUNET_break(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put( - links, - &vl->target, - vl, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - consider_sending_fc(vl); + GNUNET_SCHEDULER_add_at (hop->path_valid_until, &check_link_down, vl); + GNUNET_break (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put ( + links, + &vl->target, + vl, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + consider_sending_fc (vl); /* We lacked a confirmed connection to the target before, so tell CORE about it (finally!) */ - cores_send_connect_info(&dv->target); + cores_send_connect_info (&dv->target); } @@ -6098,10 +6152,10 @@ activate_core_visible_dv_path(struct DistanceVectorHop *hop) * or path[i+1] is a direct neighbour for i>0) */ static int -learn_dv_path(const struct GNUNET_PeerIdentity *path, - unsigned int path_len, - struct GNUNET_TIME_Relative network_latency, - struct GNUNET_TIME_Absolute path_valid_until) +learn_dv_path (const struct GNUNET_PeerIdentity *path, + unsigned int path_len, + struct GNUNET_TIME_Relative network_latency, + struct GNUNET_TIME_Absolute path_valid_until) { struct DistanceVectorHop *hop; struct DistanceVector *dv; @@ -6109,143 +6163,143 @@ learn_dv_path(const struct GNUNET_PeerIdentity *path, unsigned int shorter_distance; if (path_len < 3) - { - /* what a boring path! not allowed! */ - GNUNET_break(0); - return GNUNET_SYSERR; - } - GNUNET_assert(0 == GNUNET_memcmp(&GST_my_identity, &path[0])); - next_hop = lookup_neighbour(&path[1]); + { + /* what a boring path! not allowed! */ + GNUNET_break (0); + return GNUNET_SYSERR; + } + GNUNET_assert (0 == GNUNET_memcmp (&GST_my_identity, &path[0])); + next_hop = lookup_neighbour (&path[1]); if (NULL == next_hop) - { - /* next hop must be a neighbour, otherwise this whole thing is useless! */ - GNUNET_break(0); + { + /* next hop must be a neighbour, otherwise this whole thing is useless! */ + GNUNET_break (0); + return GNUNET_SYSERR; + } + for (unsigned int i = 2; i < path_len; i++) + if (NULL != lookup_neighbour (&path[i])) + { + /* Useless path: we have a direct connection to some hop + in the middle of the path, so this one is not even + terribly useful for redundancy */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Path of %u hops useless: directly link to hop %u (%s)\n", + path_len, + i, + GNUNET_i2s (&path[i])); + GNUNET_STATISTICS_update (GST_stats, + "# Useless DV path ignored: hop is neighbour", + 1, + GNUNET_NO); return GNUNET_SYSERR; } - for (unsigned int i = 2; i < path_len; i++) - if (NULL != lookup_neighbour(&path[i])) - { - /* Useless path: we have a direct connection to some hop - in the middle of the path, so this one is not even - terribly useful for redundancy */ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Path of %u hops useless: directly link to hop %u (%s)\n", - path_len, - i, - GNUNET_i2s(&path[i])); - GNUNET_STATISTICS_update(GST_stats, - "# Useless DV path ignored: hop is neighbour", - 1, - GNUNET_NO); - return GNUNET_SYSERR; - } - dv = GNUNET_CONTAINER_multipeermap_get(dv_routes, &path[path_len - 1]); + dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &path[path_len - 1]); if (NULL == dv) - { - dv = GNUNET_new(struct DistanceVector); - dv->target = path[path_len - 1]; - dv->timeout_task = GNUNET_SCHEDULER_add_delayed(DV_PATH_VALIDITY_TIMEOUT, - &path_cleanup_cb, - dv); - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put( - dv_routes, - &dv->target, - dv, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } + { + dv = GNUNET_new (struct DistanceVector); + dv->target = path[path_len - 1]; + dv->timeout_task = GNUNET_SCHEDULER_add_delayed (DV_PATH_VALIDITY_TIMEOUT, + &path_cleanup_cb, + dv); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put ( + dv_routes, + &dv->target, + dv, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } /* Check if we have this path already! */ shorter_distance = 0; for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; pos = pos->next_dv) + { + if (pos->distance < path_len - 2) + shorter_distance++; + /* Note that the distances in 'pos' excludes us (path[0]) and + the next_hop (path[1]), so we need to subtract two + and check next_hop explicitly */ + if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop)) { - if (pos->distance < path_len - 2) - shorter_distance++; - /* Note that the distances in 'pos' excludes us (path[0]) and - the next_hop (path[1]), so we need to subtract two - and check next_hop explicitly */ - if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop)) + int match = GNUNET_YES; + + for (unsigned int i = 0; i < pos->distance; i++) + { + if (0 != GNUNET_memcmp (&pos->path[i], &path[i + 2])) + { + match = GNUNET_NO; + break; + } + } + if (GNUNET_YES == match) + { + struct GNUNET_TIME_Relative last_timeout; + + /* Re-discovered known path, update timeout */ + GNUNET_STATISTICS_update (GST_stats, + "# Known DV path refreshed", + 1, + GNUNET_NO); + last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout); + pos->timeout = + GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); + pos->path_valid_until = + GNUNET_TIME_absolute_max (pos->path_valid_until, path_valid_until); + GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, pos); + GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, pos); + if (0 < + GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us) + activate_core_visible_dv_path (pos); + if (last_timeout.rel_value_us < + GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT, + DV_PATH_DISCOVERY_FREQUENCY) + .rel_value_us) { - int match = GNUNET_YES; - - for (unsigned int i = 0; i < pos->distance; i++) - { - if (0 != GNUNET_memcmp(&pos->path[i], &path[i + 2])) - { - match = GNUNET_NO; - break; - } - } - if (GNUNET_YES == match) - { - struct GNUNET_TIME_Relative last_timeout; - - /* Re-discovered known path, update timeout */ - GNUNET_STATISTICS_update(GST_stats, - "# Known DV path refreshed", - 1, - GNUNET_NO); - last_timeout = GNUNET_TIME_absolute_get_remaining(pos->timeout); - pos->timeout = - GNUNET_TIME_relative_to_absolute(DV_PATH_VALIDITY_TIMEOUT); - pos->path_valid_until = - GNUNET_TIME_absolute_max(pos->path_valid_until, path_valid_until); - GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, pos); - GNUNET_CONTAINER_MDLL_insert(dv, dv->dv_head, dv->dv_tail, pos); - if (0 < - GNUNET_TIME_absolute_get_remaining(path_valid_until).rel_value_us) - activate_core_visible_dv_path(pos); - if (last_timeout.rel_value_us < - GNUNET_TIME_relative_subtract(DV_PATH_VALIDITY_TIMEOUT, - DV_PATH_DISCOVERY_FREQUENCY) - .rel_value_us) - { - /* Some peer send DV learn messages too often, we are learning - the same path faster than it would be useful; do not forward! */ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Rediscovered path too quickly, not forwarding further\n"); - return GNUNET_NO; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Refreshed known path to %s, forwarding further\n", - GNUNET_i2s(&dv->target)); - return GNUNET_YES; - } + /* Some peer send DV learn messages too often, we are learning + the same path faster than it would be useful; do not forward! */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Rediscovered path too quickly, not forwarding further\n"); + return GNUNET_NO; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Refreshed known path to %s, forwarding further\n", + GNUNET_i2s (&dv->target)); + return GNUNET_YES; + } } + } /* Count how many shorter paths we have (incl. direct neighbours) before simply giving up on this one! */ if (shorter_distance >= MAX_DV_PATHS_TO_TARGET) - { - /* We have a shorter path already! */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Have many shorter DV paths %s, not forwarding further\n", - GNUNET_i2s(&dv->target)); - return GNUNET_NO; - } + { + /* We have a shorter path already! */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Have many shorter DV paths %s, not forwarding further\n", + GNUNET_i2s (&dv->target)); + return GNUNET_NO; + } /* create new DV path entry */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Discovered new DV path to %s\n", - GNUNET_i2s(&dv->target)); - hop = GNUNET_malloc(sizeof(struct DistanceVectorHop) + - sizeof(struct GNUNET_PeerIdentity) * (path_len - 2)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Discovered new DV path to %s\n", + GNUNET_i2s (&dv->target)); + hop = GNUNET_malloc (sizeof(struct DistanceVectorHop) + + sizeof(struct GNUNET_PeerIdentity) * (path_len - 2)); hop->next_hop = next_hop; hop->dv = dv; - hop->path = (const struct GNUNET_PeerIdentity *)&hop[1]; - memcpy(&hop[1], - &path[2], - sizeof(struct GNUNET_PeerIdentity) * (path_len - 2)); - hop->timeout = GNUNET_TIME_relative_to_absolute(DV_PATH_VALIDITY_TIMEOUT); + hop->path = (const struct GNUNET_PeerIdentity *) &hop[1]; + memcpy (&hop[1], + &path[2], + sizeof(struct GNUNET_PeerIdentity) * (path_len - 2)); + hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); hop->path_valid_until = path_valid_until; hop->distance = path_len - 2; hop->pd.aged_rtt = network_latency; - GNUNET_CONTAINER_MDLL_insert(dv, dv->dv_head, dv->dv_tail, hop); - GNUNET_CONTAINER_MDLL_insert(neighbour, - next_hop->dv_head, - next_hop->dv_tail, - hop); - if (0 < GNUNET_TIME_absolute_get_remaining(path_valid_until).rel_value_us) - activate_core_visible_dv_path(hop); + GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, hop); + GNUNET_CONTAINER_MDLL_insert (neighbour, + next_hop->dv_head, + next_hop->dv_tail, + hop); + if (0 < GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us) + activate_core_visible_dv_path (hop); return GNUNET_YES; } @@ -6258,36 +6312,36 @@ learn_dv_path(const struct GNUNET_PeerIdentity *path, * @return #GNUNET_YES if message is well-formed */ static int -check_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl) +check_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) { - uint16_t size = ntohs(dvl->header.size); - uint16_t num_hops = ntohs(dvl->num_hops); - const struct DVPathEntryP *hops = (const struct DVPathEntryP *)&dvl[1]; + uint16_t size = ntohs (dvl->header.size); + uint16_t num_hops = ntohs (dvl->num_hops); + const struct DVPathEntryP *hops = (const struct DVPathEntryP *) &dvl[1]; - (void)cls; + (void) cls; if (size != sizeof(*dvl) + num_hops * sizeof(struct DVPathEntryP)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } if (num_hops > MAX_DV_HOPS_ALLOWED) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + for (unsigned int i = 0; i < num_hops; i++) + { + if (0 == GNUNET_memcmp (&dvl->initiator, &hops[i].hop)) { - GNUNET_break_op(0); + GNUNET_break_op (0); return GNUNET_SYSERR; } - for (unsigned int i = 0; i < num_hops; i++) + if (0 == GNUNET_memcmp (&GST_my_identity, &hops[i].hop)) { - if (0 == GNUNET_memcmp(&dvl->initiator, &hops[i].hop)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - if (0 == GNUNET_memcmp(&GST_my_identity, &hops[i].hop)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + GNUNET_break_op (0); + return GNUNET_SYSERR; } + } return GNUNET_YES; } @@ -6304,56 +6358,56 @@ check_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl) * delay */ static void -forward_dv_learn(const struct GNUNET_PeerIdentity *next_hop, - const struct TransportDVLearnMessage *msg, - uint16_t bi_history, - uint16_t nhops, - const struct DVPathEntryP *hops, - struct GNUNET_TIME_Absolute in_time) +forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, + const struct TransportDVLearnMessage *msg, + uint16_t bi_history, + uint16_t nhops, + const struct DVPathEntryP *hops, + struct GNUNET_TIME_Absolute in_time) { struct DVPathEntryP *dhops; - char buf[sizeof(struct TransportDVLearnMessage) + - (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN; - struct TransportDVLearnMessage *fwd = (struct TransportDVLearnMessage *)buf; + char buf[sizeof(struct TransportDVLearnMessage) + + (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN; + struct TransportDVLearnMessage *fwd = (struct TransportDVLearnMessage *) buf; struct GNUNET_TIME_Relative nnd; /* compute message for forwarding */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Forwarding DV learn message originating from %s to %s\n", - GNUNET_i2s(&msg->initiator), - GNUNET_i2s2(next_hop)); - GNUNET_assert(nhops < MAX_DV_HOPS_ALLOWED); - fwd->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); - fwd->header.size = htons(sizeof(struct TransportDVLearnMessage) + - (nhops + 1) * sizeof(struct DVPathEntryP)); - fwd->num_hops = htons(nhops + 1); - fwd->bidirectional = htons(bi_history); - nnd = GNUNET_TIME_relative_add(GNUNET_TIME_absolute_get_duration(in_time), - GNUNET_TIME_relative_ntoh( - msg->non_network_delay)); - fwd->non_network_delay = GNUNET_TIME_relative_hton(nnd); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Forwarding DV learn message originating from %s to %s\n", + GNUNET_i2s (&msg->initiator), + GNUNET_i2s2 (next_hop)); + GNUNET_assert (nhops < MAX_DV_HOPS_ALLOWED); + fwd->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); + fwd->header.size = htons (sizeof(struct TransportDVLearnMessage) + + (nhops + 1) * sizeof(struct DVPathEntryP)); + fwd->num_hops = htons (nhops + 1); + fwd->bidirectional = htons (bi_history); + nnd = GNUNET_TIME_relative_add (GNUNET_TIME_absolute_get_duration (in_time), + GNUNET_TIME_relative_ntoh ( + msg->non_network_delay)); + fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd); fwd->init_sig = msg->init_sig; fwd->initiator = msg->initiator; fwd->challenge = msg->challenge; - dhops = (struct DVPathEntryP *)&fwd[1]; - GNUNET_memcpy(dhops, hops, sizeof(struct DVPathEntryP) * nhops); + dhops = (struct DVPathEntryP *) &fwd[1]; + GNUNET_memcpy (dhops, hops, sizeof(struct DVPathEntryP) * nhops); dhops[nhops].hop = GST_my_identity; { struct DvHopPS dhp = { .purpose.purpose = - htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), - .purpose.size = htonl(sizeof(dhp)), + htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), + .purpose.size = htonl (sizeof(dhp)), .pred = dhops[nhops - 1].hop, .succ = *next_hop, .challenge = msg->challenge }; - GNUNET_assert(GNUNET_OK == - GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, - &dhp.purpose, - &dhops[nhops].hop_sig)); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, + &dhp.purpose, + &dhops[nhops].hop_sig)); } - route_control_message_without_fc(next_hop, - &fwd->header, - RMO_UNCONFIRMED_ALLOWED); + route_control_message_without_fc (next_hop, + &fwd->header, + RMO_UNCONFIRMED_ALLOWED); } @@ -6367,28 +6421,28 @@ forward_dv_learn(const struct GNUNET_PeerIdentity *next_hop, * @return #GNUNET_OK if the signature is valid */ static int -validate_dv_initiator_signature( +validate_dv_initiator_signature ( struct GNUNET_TIME_AbsoluteNBO sender_monotonic_time, const struct GNUNET_PeerIdentity *init, const struct ChallengeNonceP *challenge, const struct GNUNET_CRYPTO_EddsaSignature *init_sig) { - struct DvInitPS ip = { .purpose.purpose = htonl( + struct DvInitPS ip = { .purpose.purpose = htonl ( GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), - .purpose.size = htonl(sizeof(ip)), + .purpose.size = htonl (sizeof(ip)), .monotonic_time = sender_monotonic_time, .challenge = *challenge }; if ( GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, - &ip.purpose, - init_sig, - &init->public_key)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, + &ip.purpose, + init_sig, + &init->public_key)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -6396,7 +6450,8 @@ validate_dv_initiator_signature( /** * Closure for #dv_neighbour_selection and #dv_neighbour_transmission. */ -struct NeighbourSelectionContext { +struct NeighbourSelectionContext +{ /** * Original message we received. */ @@ -6448,17 +6503,17 @@ struct NeighbourSelectionContext { * @return #GNUNET_YES (always) */ static int -dv_neighbour_selection(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +dv_neighbour_selection (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct NeighbourSelectionContext *nsc = cls; - (void)value; - if (0 == GNUNET_memcmp(pid, &nsc->dvl->initiator)) + (void) value; + if (0 == GNUNET_memcmp (pid, &nsc->dvl->initiator)) return GNUNET_YES; /* skip initiator */ for (unsigned int i = 0; i < nsc->nhops; i++) - if (0 == GNUNET_memcmp(pid, &nsc->hops[i].hop)) + if (0 == GNUNET_memcmp (pid, &nsc->hops[i].hop)) return GNUNET_YES; /* skip peers on path */ nsc->num_eligible++; @@ -6477,32 +6532,32 @@ dv_neighbour_selection(void *cls, * @return #GNUNET_YES (always) */ static int -dv_neighbour_transmission(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +dv_neighbour_transmission (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct NeighbourSelectionContext *nsc = cls; - (void)value; - if (0 == GNUNET_memcmp(pid, &nsc->dvl->initiator)) + (void) value; + if (0 == GNUNET_memcmp (pid, &nsc->dvl->initiator)) return GNUNET_YES; /* skip initiator */ for (unsigned int i = 0; i < nsc->nhops; i++) - if (0 == GNUNET_memcmp(pid, &nsc->hops[i].hop)) + if (0 == GNUNET_memcmp (pid, &nsc->hops[i].hop)) return GNUNET_YES; /* skip peers on path */ for (unsigned int i = 0; i < nsc->num_selections; i++) - { - if (nsc->selections[i] == nsc->num_eligible) - { - forward_dv_learn(pid, - nsc->dvl, - nsc->bi_history, - nsc->nhops, - nsc->hops, - nsc->in_time); - break; - } + { + if (nsc->selections[i] == nsc->num_eligible) + { + forward_dv_learn (pid, + nsc->dvl, + nsc->bi_history, + nsc->nhops, + nsc->hops, + nsc->in_time); + break; } + } nsc->num_eligible++; return GNUNET_YES; } @@ -6552,42 +6607,42 @@ dv_neighbour_transmission(void *cls, * theory forward to */ static unsigned int -calculate_fork_degree(unsigned int hops_taken, - unsigned int neighbour_count, - unsigned int eligible_count) +calculate_fork_degree (unsigned int hops_taken, + unsigned int neighbour_count, + unsigned int eligible_count) { double target_total = 50.0; /* FIXME: use LOG(NSE)? */ double eligible_ratio = - ((double)eligible_count) / ((double)neighbour_count); + ((double) eligible_count) / ((double) neighbour_count); double boost_factor = eligible_ratio * eligible_ratio; unsigned int rnd; double left; if (hops_taken >= 64) - { - GNUNET_break(0); - return 0; /* precaution given bitshift below */ - } + { + GNUNET_break (0); + return 0; /* precaution given bitshift below */ + } for (unsigned int i = 1; i < hops_taken; i++) - { - /* For each hop, subtract the expected number of targets - reached at distance d (so what remains divided by 2^d) */ - target_total -= (target_total * boost_factor / (1LLU << i)); - } + { + /* For each hop, subtract the expected number of targets + reached at distance d (so what remains divided by 2^d) */ + target_total -= (target_total * boost_factor / (1LLU << i)); + } rnd = - (unsigned int)floor(target_total * boost_factor / (1LLU << hops_taken)); + (unsigned int) floor (target_total * boost_factor / (1LLU << hops_taken)); /* round up or down probabilistically depending on how close we were when floor()ing to rnd */ - left = target_total - (double)rnd; + left = target_total - (double) rnd; if (UINT32_MAX * left > - GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)) + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)) rnd++; /* round up */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Forwarding DV learn message of %u hops %u(/%u/%u) times\n", - hops_taken, - rnd, - eligible_count, - neighbour_count); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Forwarding DV learn message of %u hops %u(/%u/%u) times\n", + hops_taken, + rnd, + eligible_count, + neighbour_count); return rnd; } @@ -6599,14 +6654,14 @@ calculate_fork_degree(unsigned int hops_taken, * @param success #GNUNET_YES if peerstore was successful */ static void -neighbour_store_dvmono_cb(void *cls, int success) +neighbour_store_dvmono_cb (void *cls, int success) { struct Neighbour *n = cls; n->sc = NULL; if (GNUNET_YES != success) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to store other peer's monotonic time in peerstore!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to store other peer's monotonic time in peerstore!\n"); } @@ -6618,7 +6673,7 @@ neighbour_store_dvmono_cb(void *cls, int success) * @param dvl the message that was received */ static void -handle_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl) +handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) { struct CommunicatorMessageContext *cmc = cls; enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; @@ -6631,287 +6686,287 @@ handle_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl) struct GNUNET_TIME_Absolute in_time; struct Neighbour *n; - nhops = ntohs(dvl->bidirectional); /* 0 = sender is initiator */ - bi_history = ntohs(dvl->bidirectional); - hops = (const struct DVPathEntryP *)&dvl[1]; + nhops = ntohs (dvl->bidirectional); /* 0 = sender is initiator */ + bi_history = ntohs (dvl->bidirectional); + hops = (const struct DVPathEntryP *) &dvl[1]; if (0 == nhops) + { + /* sanity check */ + if (0 != GNUNET_memcmp (&dvl->initiator, &cmc->im.sender)) { - /* sanity check */ - if (0 != GNUNET_memcmp(&dvl->initiator, &cmc->im.sender)) - { - GNUNET_break(0); - finish_cmc_handling(cmc); - return; - } + GNUNET_break (0); + finish_cmc_handling (cmc); + return; } + } else + { + /* sanity check */ + if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, &cmc->im.sender)) { - /* sanity check */ - if (0 != GNUNET_memcmp(&hops[nhops - 1].hop, &cmc->im.sender)) - { - GNUNET_break(0); - finish_cmc_handling(cmc); - return; - } + GNUNET_break (0); + finish_cmc_handling (cmc); + return; } + } - GNUNET_assert(CT_COMMUNICATOR == cmc->tc->type); + GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type); cc = cmc->tc->details.communicator.cc; bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE == cc); // FIXME: add bi-directional flag to cc? - in_time = GNUNET_TIME_absolute_get(); + in_time = GNUNET_TIME_absolute_get (); /* continue communicator here, everything else can happen asynchronous! */ - finish_cmc_handling(cmc); + finish_cmc_handling (cmc); - n = lookup_neighbour(&dvl->initiator); + n = lookup_neighbour (&dvl->initiator); if (NULL != n) + { + if ((n->dv_monotime_available == GNUNET_YES) && + (GNUNET_TIME_absolute_ntoh (dvl->monotonic_time).abs_value_us < + n->last_dv_learn_monotime.abs_value_us)) + { + GNUNET_STATISTICS_update (GST_stats, + "# DV learn discarded due to time travel", + 1, + GNUNET_NO); + return; + } + if (GNUNET_OK != validate_dv_initiator_signature (dvl->monotonic_time, + &dvl->initiator, + &dvl->challenge, + &dvl->init_sig)) { - if ((n->dv_monotime_available == GNUNET_YES) && - (GNUNET_TIME_absolute_ntoh(dvl->monotonic_time).abs_value_us < - n->last_dv_learn_monotime.abs_value_us)) - { - GNUNET_STATISTICS_update(GST_stats, - "# DV learn discarded due to time travel", - 1, - GNUNET_NO); - return; - } - if (GNUNET_OK != validate_dv_initiator_signature(dvl->monotonic_time, - &dvl->initiator, - &dvl->challenge, - &dvl->init_sig)) - { - GNUNET_break_op(0); - return; - } - n->last_dv_learn_monotime = GNUNET_TIME_absolute_ntoh(dvl->monotonic_time); - if (GNUNET_YES == n->dv_monotime_available) - { - if (NULL != n->sc) - GNUNET_PEERSTORE_store_cancel(n->sc); - n->sc = - GNUNET_PEERSTORE_store(peerstore, - "transport", - &dvl->initiator, - GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, - &dvl->monotonic_time, - sizeof(dvl->monotonic_time), - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - &neighbour_store_dvmono_cb, - n); - } + GNUNET_break_op (0); + return; } + n->last_dv_learn_monotime = GNUNET_TIME_absolute_ntoh (dvl->monotonic_time); + if (GNUNET_YES == n->dv_monotime_available) + { + if (NULL != n->sc) + GNUNET_PEERSTORE_store_cancel (n->sc); + n->sc = + GNUNET_PEERSTORE_store (peerstore, + "transport", + &dvl->initiator, + GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, + &dvl->monotonic_time, + sizeof(dvl->monotonic_time), + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + &neighbour_store_dvmono_cb, + n); + } + } /* OPTIMIZE-FIXME: asynchronously (!) verify signatures!, If signature verification load too high, implement random drop strategy */ for (unsigned int i = 0; i < nhops; i++) - { - struct DvHopPS dhp = { .purpose.purpose = - htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), - .purpose.size = htonl(sizeof(dhp)), - .pred = (0 == i) ? dvl->initiator : hops[i - 1].hop, - .succ = (nhops == i + 1) ? GST_my_identity - : hops[i + 1].hop, - .challenge = dvl->challenge }; - - if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP, - &dhp.purpose, - &hops[i].hop_sig, - &hops[i].hop.public_key)) - { - GNUNET_break_op(0); - return; - } + { + struct DvHopPS dhp = { .purpose.purpose = + htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), + .purpose.size = htonl (sizeof(dhp)), + .pred = (0 == i) ? dvl->initiator : hops[i - 1].hop, + .succ = (nhops == i + 1) ? GST_my_identity + : hops[i + 1].hop, + .challenge = dvl->challenge }; + + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP, + &dhp.purpose, + &hops[i].hop_sig, + &hops[i].hop.public_key)) + { + GNUNET_break_op (0); + return; } + } if (GNUNET_EXTRA_LOGGING > 0) - { - char *path; - - path = GNUNET_strdup(GNUNET_i2s(&dvl->initiator)); - for (unsigned int i = 0; i < nhops; i++) - { - char *tmp; - - GNUNET_asprintf(&tmp, - "%s%s%s", - path, - (bi_history & (1 << (nhops - i))) ? "<->" : "-->", - GNUNET_i2s(&hops[i].hop)); - GNUNET_free(path); - path = tmp; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received DVInit via %s%s%s\n", - path, - bi_hop ? "<->" : "-->", - GNUNET_i2s(&GST_my_identity)); - GNUNET_free(path); - } + { + char *path; + + path = GNUNET_strdup (GNUNET_i2s (&dvl->initiator)); + for (unsigned int i = 0; i < nhops; i++) + { + char *tmp; + + GNUNET_asprintf (&tmp, + "%s%s%s", + path, + (bi_history & (1 << (nhops - i))) ? "<->" : "-->", + GNUNET_i2s (&hops[i].hop)); + GNUNET_free (path); + path = tmp; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received DVInit via %s%s%s\n", + path, + bi_hop ? "<->" : "-->", + GNUNET_i2s (&GST_my_identity)); + GNUNET_free (path); + } do_fwd = GNUNET_YES; - if (0 == GNUNET_memcmp(&GST_my_identity, &dvl->initiator)) - { - struct GNUNET_PeerIdentity path[nhops + 1]; - struct GNUNET_TIME_Relative host_latency_sum; - struct GNUNET_TIME_Relative latency; - struct GNUNET_TIME_Relative network_latency; - - /* We initiated this, learn the forward path! */ - path[0] = GST_my_identity; - path[1] = hops[0].hop; - host_latency_sum = GNUNET_TIME_relative_ntoh(dvl->non_network_delay); - - // Need also something to lookup initiation time - // to compute RTT! -> add RTT argument here? - latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly - // (based on dvl->challenge, we can identify time of origin!) - - network_latency = GNUNET_TIME_relative_subtract(latency, host_latency_sum); - /* assumption: latency on all links is the same */ - network_latency = GNUNET_TIME_relative_divide(network_latency, nhops); - - for (unsigned int i = 2; i <= nhops; i++) - { - struct GNUNET_TIME_Relative ilat; - - /* assumption: linear latency increase per hop */ - ilat = GNUNET_TIME_relative_multiply(network_latency, i); - path[i] = hops[i - 1].hop; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Learned path with %u hops to %s with latency %s\n", + if (0 == GNUNET_memcmp (&GST_my_identity, &dvl->initiator)) + { + struct GNUNET_PeerIdentity path[nhops + 1]; + struct GNUNET_TIME_Relative host_latency_sum; + struct GNUNET_TIME_Relative latency; + struct GNUNET_TIME_Relative network_latency; + + /* We initiated this, learn the forward path! */ + path[0] = GST_my_identity; + path[1] = hops[0].hop; + host_latency_sum = GNUNET_TIME_relative_ntoh (dvl->non_network_delay); + + // Need also something to lookup initiation time + // to compute RTT! -> add RTT argument here? + latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly + // (based on dvl->challenge, we can identify time of origin!) + + network_latency = GNUNET_TIME_relative_subtract (latency, host_latency_sum); + /* assumption: latency on all links is the same */ + network_latency = GNUNET_TIME_relative_divide (network_latency, nhops); + + for (unsigned int i = 2; i <= nhops; i++) + { + struct GNUNET_TIME_Relative ilat; + + /* assumption: linear latency increase per hop */ + ilat = GNUNET_TIME_relative_multiply (network_latency, i); + path[i] = hops[i - 1].hop; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Learned path with %u hops to %s with latency %s\n", + i, + GNUNET_i2s (&path[i]), + GNUNET_STRINGS_relative_time_to_string (ilat, GNUNET_YES)); + learn_dv_path (path, i, - GNUNET_i2s(&path[i]), - GNUNET_STRINGS_relative_time_to_string(ilat, GNUNET_YES)); - learn_dv_path(path, - i, - ilat, - GNUNET_TIME_relative_to_absolute( - ADDRESS_VALIDATION_LIFETIME)); - } - /* as we initiated, do not forward again (would be circular!) */ - do_fwd = GNUNET_NO; - return; + ilat, + GNUNET_TIME_relative_to_absolute ( + ADDRESS_VALIDATION_LIFETIME)); } + /* as we initiated, do not forward again (would be circular!) */ + do_fwd = GNUNET_NO; + return; + } if (bi_hop) + { + /* last hop was bi-directional, we could learn something here! */ + struct GNUNET_PeerIdentity path[nhops + 2]; + + path[0] = GST_my_identity; + path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */ + for (unsigned int i = 0; i < nhops; i++) { - /* last hop was bi-directional, we could learn something here! */ - struct GNUNET_PeerIdentity path[nhops + 2]; + int iret; - path[0] = GST_my_identity; - path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */ - for (unsigned int i = 0; i < nhops; i++) - { - int iret; - - if (0 == (bi_history & (1 << i))) - break; /* i-th hop not bi-directional, stop learning! */ - if (i == nhops - 1) - { - path[i + 2] = dvl->initiator; - } - else - { - path[i + 2] = hops[nhops - i - 2].hop; - } - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Learned inverse path with %u hops to %s\n", - i + 1, - GNUNET_i2s(&path[i + 2])); - iret = learn_dv_path(path, - i + 2, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_TIME_UNIT_ZERO_ABS); - if (GNUNET_SYSERR == iret) - { - /* path invalid or too long to be interesting for US, thus should also - not be interesting to our neighbours, cut path when forwarding to - 'i' hops, except of course for the one that goes back to the - initiator */ - GNUNET_STATISTICS_update(GST_stats, - "# DV learn not forwarded due invalidity of path", - 1, - GNUNET_NO); - do_fwd = GNUNET_NO; - break; - } - if ((GNUNET_NO == iret) && (nhops == i + 1)) - { - /* we have better paths, and this is the longest target, - so there cannot be anything interesting later */ - GNUNET_STATISTICS_update(GST_stats, - "# DV learn not forwarded, got better paths", - 1, - GNUNET_NO); - do_fwd = GNUNET_NO; - break; - } - } + if (0 == (bi_history & (1 << i))) + break; /* i-th hop not bi-directional, stop learning! */ + if (i == nhops - 1) + { + path[i + 2] = dvl->initiator; + } + else + { + path[i + 2] = hops[nhops - i - 2].hop; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Learned inverse path with %u hops to %s\n", + i + 1, + GNUNET_i2s (&path[i + 2])); + iret = learn_dv_path (path, + i + 2, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_TIME_UNIT_ZERO_ABS); + if (GNUNET_SYSERR == iret) + { + /* path invalid or too long to be interesting for US, thus should also + not be interesting to our neighbours, cut path when forwarding to + 'i' hops, except of course for the one that goes back to the + initiator */ + GNUNET_STATISTICS_update (GST_stats, + "# DV learn not forwarded due invalidity of path", + 1, + GNUNET_NO); + do_fwd = GNUNET_NO; + break; + } + if ((GNUNET_NO == iret) && (nhops == i + 1)) + { + /* we have better paths, and this is the longest target, + so there cannot be anything interesting later */ + GNUNET_STATISTICS_update (GST_stats, + "# DV learn not forwarded, got better paths", + 1, + GNUNET_NO); + do_fwd = GNUNET_NO; + break; + } } + } if (MAX_DV_HOPS_ALLOWED == nhops) - { - /* At limit, we're out of here! */ - finish_cmc_handling(cmc); - return; - } + { + /* At limit, we're out of here! */ + finish_cmc_handling (cmc); + return; + } /* Forward to initiator, if path non-trivial and possible */ bi_history = (bi_history << 1) | (bi_hop ? 1 : 0); did_initiator = GNUNET_NO; if ((1 < nhops) && (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_contains(neighbours, &dvl->initiator))) - { - /* send back to origin! */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending DVL back to initiator %s\n", - GNUNET_i2s(&dvl->initiator)); - forward_dv_learn(&dvl->initiator, dvl, bi_history, nhops, hops, in_time); - did_initiator = GNUNET_YES; - } + GNUNET_CONTAINER_multipeermap_contains (neighbours, &dvl->initiator))) + { + /* send back to origin! */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending DVL back to initiator %s\n", + GNUNET_i2s (&dvl->initiator)); + forward_dv_learn (&dvl->initiator, dvl, bi_history, nhops, hops, in_time); + did_initiator = GNUNET_YES; + } /* We forward under two conditions: either we still learned something ourselves (do_fwd), or the path was darn short and thus the initiator is likely to still be very interested in this (and we did NOT already send it back to the initiator) */ if ((do_fwd) || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) && (GNUNET_NO == did_initiator))) - { - /* Pick random neighbours that are not yet on the path */ - struct NeighbourSelectionContext nsc; - unsigned int n_cnt; - - n_cnt = GNUNET_CONTAINER_multipeermap_size(neighbours); - nsc.nhops = nhops; - nsc.dvl = dvl; - nsc.bi_history = bi_history; - nsc.hops = hops; - nsc.in_time = in_time; - nsc.num_eligible = 0; - GNUNET_CONTAINER_multipeermap_iterate(neighbours, - &dv_neighbour_selection, - &nsc); - if (0 == nsc.num_eligible) - return; /* done here, cannot forward to anyone else */ - nsc.num_selections = calculate_fork_degree(nhops, n_cnt, nsc.num_eligible); - nsc.num_selections = - GNUNET_MIN(MAX_DV_DISCOVERY_SELECTION, nsc.num_selections); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Forwarding DVL to %u other peers\n", - nsc.num_selections); - for (unsigned int i = 0; i < nsc.num_selections; i++) - nsc.selections[i] = - (nsc.num_selections == n_cnt) - ? i /* all were selected, avoid collisions by chance */ - : GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, n_cnt); - nsc.num_eligible = 0; - GNUNET_CONTAINER_multipeermap_iterate(neighbours, - &dv_neighbour_transmission, - &nsc); - } + { + /* Pick random neighbours that are not yet on the path */ + struct NeighbourSelectionContext nsc; + unsigned int n_cnt; + + n_cnt = GNUNET_CONTAINER_multipeermap_size (neighbours); + nsc.nhops = nhops; + nsc.dvl = dvl; + nsc.bi_history = bi_history; + nsc.hops = hops; + nsc.in_time = in_time; + nsc.num_eligible = 0; + GNUNET_CONTAINER_multipeermap_iterate (neighbours, + &dv_neighbour_selection, + &nsc); + if (0 == nsc.num_eligible) + return; /* done here, cannot forward to anyone else */ + nsc.num_selections = calculate_fork_degree (nhops, n_cnt, nsc.num_eligible); + nsc.num_selections = + GNUNET_MIN (MAX_DV_DISCOVERY_SELECTION, nsc.num_selections); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Forwarding DVL to %u other peers\n", + nsc.num_selections); + for (unsigned int i = 0; i < nsc.num_selections; i++) + nsc.selections[i] = + (nsc.num_selections == n_cnt) + ? i /* all were selected, avoid collisions by chance */ + : GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, n_cnt); + nsc.num_eligible = 0; + GNUNET_CONTAINER_multipeermap_iterate (neighbours, + &dv_neighbour_transmission, + &nsc); + } } @@ -6923,27 +6978,27 @@ handle_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl) * @return #GNUNET_YES if message is well-formed */ static int -check_dv_box(void *cls, const struct TransportDVBoxMessage *dvb) +check_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) { - uint16_t size = ntohs(dvb->header.size); - uint16_t num_hops = ntohs(dvb->num_hops); + uint16_t size = ntohs (dvb->header.size); + uint16_t num_hops = ntohs (dvb->num_hops); const struct GNUNET_PeerIdentity *hops = - (const struct GNUNET_PeerIdentity *)&dvb[1]; + (const struct GNUNET_PeerIdentity *) &dvb[1]; - (void)cls; - if (size < sizeof(*dvb) + num_hops * sizeof(struct GNUNET_PeerIdentity) + - sizeof(struct GNUNET_MessageHeader)) + (void) cls; + if (size < sizeof(*dvb) + num_hops * sizeof(struct GNUNET_PeerIdentity) + + sizeof(struct GNUNET_MessageHeader)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + /* This peer must not be on the path */ + for (unsigned int i = 0; i < num_hops; i++) + if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity)) { - GNUNET_break_op(0); + GNUNET_break_op (0); return GNUNET_SYSERR; } - /* This peer must not be on the path */ - for (unsigned int i = 0; i < num_hops; i++) - if (0 == GNUNET_memcmp(&hops[i], &GST_my_identity)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } return GNUNET_YES; } @@ -6961,13 +7016,13 @@ check_dv_box(void *cls, const struct TransportDVBoxMessage *dvb) * @param payload_size number of bytes in @a payload */ static void -forward_dv_box(struct Neighbour *next_hop, - const struct TransportDVBoxMessage *hdr, - uint16_t total_hops, - uint16_t num_hops, - const struct GNUNET_PeerIdentity *hops, - const void *enc_payload, - uint16_t enc_payload_size) +forward_dv_box (struct Neighbour *next_hop, + const struct TransportDVBoxMessage *hdr, + uint16_t total_hops, + uint16_t num_hops, + const struct GNUNET_PeerIdentity *hops, + const void *enc_payload, + uint16_t enc_payload_size) { struct VirtualLink *vl = next_hop->vl; struct PendingMessage *pm; @@ -6975,33 +7030,33 @@ forward_dv_box(struct Neighbour *next_hop, char *buf; struct GNUNET_PeerIdentity *dhops; - GNUNET_assert(NULL != vl); - msg_size = sizeof(struct TransportDVBoxMessage) + - num_hops * sizeof(struct GNUNET_PeerIdentity) + enc_payload_size; - pm = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size); + GNUNET_assert (NULL != vl); + msg_size = sizeof(struct TransportDVBoxMessage) + + num_hops * sizeof(struct GNUNET_PeerIdentity) + enc_payload_size; + pm = GNUNET_malloc (sizeof(struct PendingMessage) + msg_size); pm->pmt = PMT_DV_BOX; pm->vl = vl; - pm->timeout = GNUNET_TIME_relative_to_absolute(DV_FORWARD_TIMEOUT); + pm->timeout = GNUNET_TIME_relative_to_absolute (DV_FORWARD_TIMEOUT); pm->logging_uuid = logging_uuid_gen++; pm->prefs = GNUNET_MQ_PRIO_BACKGROUND; pm->bytes_msg = msg_size; - buf = (char *)&pm[1]; - memcpy(buf, hdr, sizeof(*hdr)); + buf = (char *) &pm[1]; + memcpy (buf, hdr, sizeof(*hdr)); dhops = - (struct GNUNET_PeerIdentity *)&buf[sizeof(struct TransportDVBoxMessage)]; - memcpy(dhops, hops, num_hops * sizeof(struct GNUNET_PeerIdentity)); - memcpy(&dhops[num_hops], enc_payload, enc_payload_size); - GNUNET_CONTAINER_MDLL_insert(vl, - vl->pending_msg_head, - vl->pending_msg_tail, - pm); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Created pending message %llu for DV Box with next hop %s (%u/%u)\n", - pm->logging_uuid, - GNUNET_i2s(&next_hop->pid), - (unsigned int)num_hops, - (unsigned int)total_hops); - check_vl_transmission(vl); + (struct GNUNET_PeerIdentity *) &buf[sizeof(struct TransportDVBoxMessage)]; + memcpy (dhops, hops, num_hops * sizeof(struct GNUNET_PeerIdentity)); + memcpy (&dhops[num_hops], enc_payload, enc_payload_size); + GNUNET_CONTAINER_MDLL_insert (vl, + vl->pending_msg_head, + vl->pending_msg_tail, + pm); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Created pending message %llu for DV Box with next hop %s (%u/%u)\n", + pm->logging_uuid, + GNUNET_i2s (&next_hop->pid), + (unsigned int) num_hops, + (unsigned int) total_hops); + check_vl_transmission (vl); } @@ -7011,30 +7066,30 @@ forward_dv_box(struct Neighbour *next_hop, * @param b data structure to release */ static void -free_backtalker(struct Backtalker *b) +free_backtalker (struct Backtalker *b) { if (NULL != b->get) - { - GNUNET_PEERSTORE_iterate_cancel(b->get); - b->get = NULL; - GNUNET_assert(NULL != b->cmc); - finish_cmc_handling(b->cmc); - b->cmc = NULL; - } + { + GNUNET_PEERSTORE_iterate_cancel (b->get); + b->get = NULL; + GNUNET_assert (NULL != b->cmc); + finish_cmc_handling (b->cmc); + b->cmc = NULL; + } if (NULL != b->task) - { - GNUNET_SCHEDULER_cancel(b->task); - b->task = NULL; - } + { + GNUNET_SCHEDULER_cancel (b->task); + b->task = NULL; + } if (NULL != b->sc) - { - GNUNET_PEERSTORE_store_cancel(b->sc); - b->sc = NULL; - } - GNUNET_assert( + { + GNUNET_PEERSTORE_store_cancel (b->sc); + b->sc = NULL; + } + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(backtalkers, &b->pid, b)); - GNUNET_free(b); + GNUNET_CONTAINER_multipeermap_remove (backtalkers, &b->pid, b)); + GNUNET_free (b); } @@ -7047,15 +7102,15 @@ free_backtalker(struct Backtalker *b) * @return #GNUNET_OK (always) */ static int -free_backtalker_cb(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +free_backtalker_cb (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct Backtalker *b = value; - (void)cls; - (void)pid; - free_backtalker(b); + (void) cls; + (void) pid; + free_backtalker (b); return GNUNET_OK; } @@ -7066,18 +7121,18 @@ free_backtalker_cb(void *cls, * @param cls a `struct Backtalker` */ static void -backtalker_timeout_cb(void *cls) +backtalker_timeout_cb (void *cls) { struct Backtalker *b = cls; b->task = NULL; - if (0 != GNUNET_TIME_absolute_get_remaining(b->timeout).rel_value_us) - { - b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b); - return; - } - GNUNET_assert(NULL == b->sc); - free_backtalker(b); + if (0 != GNUNET_TIME_absolute_get_remaining (b->timeout).rel_value_us) + { + b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); + return; + } + GNUNET_assert (NULL == b->sc); + free_backtalker (b); } @@ -7090,52 +7145,52 @@ backtalker_timeout_cb(void *cls) * @param emsg error message */ static void -backtalker_monotime_cb(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +backtalker_monotime_cb (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { struct Backtalker *b = cls; struct GNUNET_TIME_AbsoluteNBO *mtbe; struct GNUNET_TIME_Absolute mt; - (void)emsg; + (void) emsg; if (NULL == record) - { - /* we're done with #backtalker_monotime_cb() invocations, - continue normal processing */ - b->get = NULL; - GNUNET_assert(NULL != b->cmc); - if (0 != b->body_size) - demultiplex_with_cmc(b->cmc, - (const struct GNUNET_MessageHeader *)&b[1]); - else - finish_cmc_handling(b->cmc); - b->cmc = NULL; - return; - } + { + /* we're done with #backtalker_monotime_cb() invocations, + continue normal processing */ + b->get = NULL; + GNUNET_assert (NULL != b->cmc); + if (0 != b->body_size) + demultiplex_with_cmc (b->cmc, + (const struct GNUNET_MessageHeader *) &b[1]); + else + finish_cmc_handling (b->cmc); + b->cmc = NULL; + return; + } if (sizeof(*mtbe) != record->value_size) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } mtbe = record->value; - mt = GNUNET_TIME_absolute_ntoh(*mtbe); + mt = GNUNET_TIME_absolute_ntoh (*mtbe); if (mt.abs_value_us > b->monotonic_time.abs_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Backtalker message from %s dropped, monotime in the past\n", - GNUNET_i2s(&b->pid)); - GNUNET_STATISTICS_update( - GST_stats, - "# Backchannel messages dropped: monotonic time not increasing", - 1, - GNUNET_NO); - b->monotonic_time = mt; - /* Setting body_size to 0 prevents call to #forward_backchannel_payload() - */ - b->body_size = 0; - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Backtalker message from %s dropped, monotime in the past\n", + GNUNET_i2s (&b->pid)); + GNUNET_STATISTICS_update ( + GST_stats, + "# Backchannel messages dropped: monotonic time not increasing", + 1, + GNUNET_NO); + b->monotonic_time = mt; + /* Setting body_size to 0 prevents call to #forward_backchannel_payload() + */ + b->body_size = 0; + return; + } } @@ -7147,17 +7202,17 @@ backtalker_monotime_cb(void *cls, * @param success #GNUNET_OK on success */ static void -backtalker_monotime_store_cb(void *cls, int success) +backtalker_monotime_store_cb (void *cls, int success) { struct Backtalker *b = cls; if (GNUNET_OK != success) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to store backtalker's monotonic time in PEERSTORE!\n"); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to store backtalker's monotonic time in PEERSTORE!\n"); + } b->sc = NULL; - b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b); + b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); } @@ -7167,32 +7222,32 @@ backtalker_monotime_store_cb(void *cls, int success) * @param b a backtalker with updated monotonic time */ static void -update_backtalker_monotime(struct Backtalker *b) +update_backtalker_monotime (struct Backtalker *b) { struct GNUNET_TIME_AbsoluteNBO mtbe; if (NULL != b->sc) - { - GNUNET_PEERSTORE_store_cancel(b->sc); - b->sc = NULL; - } + { + GNUNET_PEERSTORE_store_cancel (b->sc); + b->sc = NULL; + } else - { - GNUNET_SCHEDULER_cancel(b->task); - b->task = NULL; - } - mtbe = GNUNET_TIME_absolute_hton(b->monotonic_time); + { + GNUNET_SCHEDULER_cancel (b->task); + b->task = NULL; + } + mtbe = GNUNET_TIME_absolute_hton (b->monotonic_time); b->sc = - GNUNET_PEERSTORE_store(peerstore, - "transport", - &b->pid, - GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, - &mtbe, - sizeof(mtbe), - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - &backtalker_monotime_store_cb, - b); + GNUNET_PEERSTORE_store (peerstore, + "transport", + &b->pid, + GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, + &mtbe, + sizeof(mtbe), + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + &backtalker_monotime_store_cb, + b); } @@ -7204,14 +7259,14 @@ update_backtalker_monotime(struct Backtalker *b) * @param dvb the message that was received */ static void -handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb) +handle_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) { struct CommunicatorMessageContext *cmc = cls; - uint16_t size = ntohs(dvb->header.size) - sizeof(*dvb); - uint16_t num_hops = ntohs(dvb->num_hops); + uint16_t size = ntohs (dvb->header.size) - sizeof(*dvb); + uint16_t num_hops = ntohs (dvb->num_hops); const struct GNUNET_PeerIdentity *hops = - (const struct GNUNET_PeerIdentity *)&dvb[1]; - const char *enc_payload = (const char *)&hops[num_hops]; + (const struct GNUNET_PeerIdentity *) &dvb[1]; + const char *enc_payload = (const char *) &hops[num_hops]; uint16_t enc_payload_size = size - (num_hops * sizeof(struct GNUNET_PeerIdentity)); struct DVKeyState key; @@ -7220,89 +7275,89 @@ handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb) size_t hdr_len; if (GNUNET_EXTRA_LOGGING > 0) - { - char *path; + { + char *path; - path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity)); - for (unsigned int i = 0; i < num_hops; i++) - { - char *tmp; + path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity)); + for (unsigned int i = 0; i < num_hops; i++) + { + char *tmp; - GNUNET_asprintf(&tmp, "%s->%s", path, GNUNET_i2s(&hops[i])); - GNUNET_free(path); - path = tmp; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received DVBox with remainig path %s\n", - path); - GNUNET_free(path); + GNUNET_asprintf (&tmp, "%s->%s", path, GNUNET_i2s (&hops[i])); + GNUNET_free (path); + path = tmp; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received DVBox with remainig path %s\n", + path); + GNUNET_free (path); + } if (num_hops > 0) + { + /* We're trying from the end of the hops array, as we may be + able to find a shortcut unknown to the origin that way */ + for (int i = num_hops - 1; i >= 0; i--) { - /* We're trying from the end of the hops array, as we may be - able to find a shortcut unknown to the origin that way */ - for (int i = num_hops - 1; i >= 0; i--) - { - struct Neighbour *n; - - if (0 == GNUNET_memcmp(&hops[i], &GST_my_identity)) - { - GNUNET_break_op(0); - finish_cmc_handling(cmc); - return; - } - n = lookup_neighbour(&hops[i]); - if (NULL == n) - continue; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Skipping %u/%u hops ahead while routing DV Box\n", - i, - num_hops); - forward_dv_box(n, - dvb, - ntohs(dvb->total_hops) + 1, - num_hops - i - 1, /* number of hops left */ - &hops[i + 1], /* remaining hops */ - enc_payload, - enc_payload_size); - GNUNET_STATISTICS_update(GST_stats, - "# DV hops skipped routing boxes", - i, - GNUNET_NO); - GNUNET_STATISTICS_update(GST_stats, - "# DV boxes routed (total)", - 1, - GNUNET_NO); - finish_cmc_handling(cmc); - return; - } - /* Woopsie, next hop not in neighbours, drop! */ - GNUNET_STATISTICS_update(GST_stats, - "# DV Boxes dropped: next hop unknown", - 1, - GNUNET_NO); - finish_cmc_handling(cmc); + struct Neighbour *n; + + if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity)) + { + GNUNET_break_op (0); + finish_cmc_handling (cmc); + return; + } + n = lookup_neighbour (&hops[i]); + if (NULL == n) + continue; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Skipping %u/%u hops ahead while routing DV Box\n", + i, + num_hops); + forward_dv_box (n, + dvb, + ntohs (dvb->total_hops) + 1, + num_hops - i - 1, /* number of hops left */ + &hops[i + 1], /* remaining hops */ + enc_payload, + enc_payload_size); + GNUNET_STATISTICS_update (GST_stats, + "# DV hops skipped routing boxes", + i, + GNUNET_NO); + GNUNET_STATISTICS_update (GST_stats, + "# DV boxes routed (total)", + 1, + GNUNET_NO); + finish_cmc_handling (cmc); return; } + /* Woopsie, next hop not in neighbours, drop! */ + GNUNET_STATISTICS_update (GST_stats, + "# DV Boxes dropped: next hop unknown", + 1, + GNUNET_NO); + finish_cmc_handling (cmc); + return; + } /* We are the target. Unbox and handle message. */ - GNUNET_STATISTICS_update(GST_stats, - "# DV boxes opened (ultimate target)", - 1, - GNUNET_NO); - cmc->total_hops = ntohs(dvb->total_hops); - - dh_key_derive_eph_pub(&dvb->ephemeral_key, &dvb->iv, &key); - hdr = (const char *)&dvb[1]; - hdr_len = ntohs(dvb->header.size) - sizeof(*dvb); - dv_hmac(&key, &hmac, hdr, hdr_len); - if (0 != GNUNET_memcmp(&hmac, &dvb->hmac)) - { - /* HMAC missmatch, disard! */ - GNUNET_break_op(0); - finish_cmc_handling(cmc); - return; - } + GNUNET_STATISTICS_update (GST_stats, + "# DV boxes opened (ultimate target)", + 1, + GNUNET_NO); + cmc->total_hops = ntohs (dvb->total_hops); + + dh_key_derive_eph_pub (&dvb->ephemeral_key, &dvb->iv, &key); + hdr = (const char *) &dvb[1]; + hdr_len = ntohs (dvb->header.size) - sizeof(*dvb); + dv_hmac (&key, &hmac, hdr, hdr_len); + if (0 != GNUNET_memcmp (&hmac, &dvb->hmac)) + { + /* HMAC missmatch, disard! */ + GNUNET_break_op (0); + finish_cmc_handling (cmc); + return; + } /* begin actual decryption */ { struct Backtalker *b; @@ -7310,117 +7365,118 @@ handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb) struct TransportDVBoxPayloadP ppay; char body[hdr_len - sizeof(ppay)] GNUNET_ALIGN; const struct GNUNET_MessageHeader *mh = - (const struct GNUNET_MessageHeader *)body; - - GNUNET_assert(hdr_len >= - sizeof(ppay) + sizeof(struct GNUNET_MessageHeader)); - dv_decrypt(&key, &ppay, hdr, sizeof(ppay)); - dv_decrypt(&key, &body, &hdr[sizeof(ppay)], hdr_len - sizeof(ppay)); - dv_key_clean(&key); - if (ntohs(mh->size) != sizeof(body)) - { - GNUNET_break_op(0); - finish_cmc_handling(cmc); - return; - } + (const struct GNUNET_MessageHeader *) body; + + GNUNET_assert (hdr_len >= + sizeof(ppay) + sizeof(struct GNUNET_MessageHeader)); + dv_decrypt (&key, &ppay, hdr, sizeof(ppay)); + dv_decrypt (&key, &body, &hdr[sizeof(ppay)], hdr_len - sizeof(ppay)); + dv_key_clean (&key); + if (ntohs (mh->size) != sizeof(body)) + { + GNUNET_break_op (0); + finish_cmc_handling (cmc); + return; + } /* need to prevent box-in-a-box (and DV_LEARN) so check inbox type! */ - switch (ntohs(mh->type)) - { - case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX: - GNUNET_break_op(0); - finish_cmc_handling(cmc); - return; + switch (ntohs (mh->type)) + { + case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX: + GNUNET_break_op (0); + finish_cmc_handling (cmc); + return; - case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN: - GNUNET_break_op(0); - finish_cmc_handling(cmc); - return; + case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN: + GNUNET_break_op (0); + finish_cmc_handling (cmc); + return; - default: - /* permitted, continue */ - break; - } - monotime = GNUNET_TIME_absolute_ntoh(ppay.monotonic_time); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Decrypted backtalk from %s\n", - GNUNET_i2s(&ppay.sender)); - b = GNUNET_CONTAINER_multipeermap_get(backtalkers, &ppay.sender); + default: + /* permitted, continue */ + break; + } + monotime = GNUNET_TIME_absolute_ntoh (ppay.monotonic_time); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Decrypted backtalk from %s\n", + GNUNET_i2s (&ppay.sender)); + b = GNUNET_CONTAINER_multipeermap_get (backtalkers, &ppay.sender); if ((NULL != b) && (monotime.abs_value_us < b->monotonic_time.abs_value_us)) - { - GNUNET_STATISTICS_update( - GST_stats, - "# Backchannel messages dropped: monotonic time not increasing", - 1, - GNUNET_NO); - finish_cmc_handling(cmc); - return; - } + { + GNUNET_STATISTICS_update ( + GST_stats, + "# Backchannel messages dropped: monotonic time not increasing", + 1, + GNUNET_NO); + finish_cmc_handling (cmc); + return; + } if ((NULL == b) || - (0 != GNUNET_memcmp(&b->last_ephemeral, &dvb->ephemeral_key))) + (0 != GNUNET_memcmp (&b->last_ephemeral, &dvb->ephemeral_key))) + { + /* Check signature */ + struct EphemeralConfirmationPS ec; + + ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); + ec.purpose.size = htonl (sizeof(ec)); + ec.target = GST_my_identity; + ec.ephemeral_key = dvb->ephemeral_key; + if ( + GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify ( + GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL, + &ec.purpose, + &ppay.sender_sig, + &ppay.sender.public_key)) { - /* Check signature */ - struct EphemeralConfirmationPS ec; - - ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); - ec.purpose.size = htonl(sizeof(ec)); - ec.target = GST_my_identity; - ec.ephemeral_key = dvb->ephemeral_key; - if ( - GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL, - &ec.purpose, - &ppay.sender_sig, - &ppay.sender.public_key)) - { - /* Signature invalid, disard! */ - GNUNET_break_op(0); - finish_cmc_handling(cmc); - return; - } + /* Signature invalid, disard! */ + GNUNET_break_op (0); + finish_cmc_handling (cmc); + return; } + } /* Update sender, we now know the real origin! */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "DVBox received for me from %s via %s\n", - GNUNET_i2s2(&ppay.sender), - GNUNET_i2s(&cmc->im.sender)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "DVBox received for me from %s via %s\n", + GNUNET_i2s2 (&ppay.sender), + GNUNET_i2s (&cmc->im.sender)); cmc->im.sender = ppay.sender; if (NULL != b) - { - /* update key cache and mono time */ - b->last_ephemeral = dvb->ephemeral_key; - b->monotonic_time = monotime; - update_backtalker_monotime(b); - b->timeout = - GNUNET_TIME_relative_to_absolute(BACKCHANNEL_INACTIVITY_TIMEOUT); - - demultiplex_with_cmc(cmc, mh); - return; - } + { + /* update key cache and mono time */ + b->last_ephemeral = dvb->ephemeral_key; + b->monotonic_time = monotime; + update_backtalker_monotime (b); + b->timeout = + GNUNET_TIME_relative_to_absolute (BACKCHANNEL_INACTIVITY_TIMEOUT); + + demultiplex_with_cmc (cmc, mh); + return; + } /* setup data structure to cache signature AND check monotonic time with PEERSTORE before forwarding backchannel payload */ - b = GNUNET_malloc(sizeof(struct Backtalker) + sizeof(body)); + b = GNUNET_malloc (sizeof(struct Backtalker) + sizeof(body)); b->pid = ppay.sender; b->body_size = sizeof(body); - memcpy(&b[1], body, sizeof(body)); - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put( - backtalkers, - &b->pid, - b, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + memcpy (&b[1], body, sizeof(body)); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put ( + backtalkers, + &b->pid, + b, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); b->monotonic_time = monotime; /* NOTE: to be checked still! */ b->cmc = cmc; b->timeout = - GNUNET_TIME_relative_to_absolute(BACKCHANNEL_INACTIVITY_TIMEOUT); - b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b); + GNUNET_TIME_relative_to_absolute (BACKCHANNEL_INACTIVITY_TIMEOUT); + b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); b->get = - GNUNET_PEERSTORE_iterate(peerstore, - "transport", - &b->pid, - GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, - &backtalker_monotime_cb, - b); + GNUNET_PEERSTORE_iterate (peerstore, + "transport", + &b->pid, + GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, + &backtalker_monotime_cb, + b); } /* end actual decryption */ } @@ -7433,17 +7489,17 @@ handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb) * @return #GNUNET_YES if message is well-formed */ static int -check_incoming_msg(void *cls, - const struct GNUNET_TRANSPORT_IncomingMessage *im) +check_incoming_msg (void *cls, + const struct GNUNET_TRANSPORT_IncomingMessage *im) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - GNUNET_MQ_check_boxed_message(im); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + GNUNET_MQ_check_boxed_message (im); return GNUNET_OK; } @@ -7451,7 +7507,8 @@ check_incoming_msg(void *cls, /** * Closure for #check_known_address. */ -struct CheckKnownAddressContext { +struct CheckKnownAddressContext +{ /** * Set to the address we are looking for. */ @@ -7474,15 +7531,15 @@ struct CheckKnownAddressContext { * @return #GNUNET_OK if not matching, #GNUNET_NO if match found */ static int -check_known_address(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +check_known_address (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct CheckKnownAddressContext *ckac = cls; struct ValidationState *vs = value; - (void)pid; - if (0 != strcmp(vs->address, ckac->address)) + (void) pid; + if (0 != strcmp (vs->address, ckac->address)) return GNUNET_OK; ckac->vs = vs; return GNUNET_NO; @@ -7495,7 +7552,7 @@ check_known_address(void *cls, * @param cls NULL */ static void -validation_start_cb(void *cls); +validation_start_cb (void *cls); /** @@ -7506,8 +7563,8 @@ validation_start_cb(void *cls); * @param new_time new time for revalidation */ static void -update_next_challenge_time(struct ValidationState *vs, - struct GNUNET_TIME_Absolute new_time) +update_next_challenge_time (struct ValidationState *vs, + struct GNUNET_TIME_Absolute new_time) { struct GNUNET_TIME_Relative delta; @@ -7516,21 +7573,21 @@ update_next_challenge_time(struct ValidationState *vs, vs->next_challenge = new_time; if (NULL == vs->hn) vs->hn = - GNUNET_CONTAINER_heap_insert(validation_heap, vs, new_time.abs_value_us); + GNUNET_CONTAINER_heap_insert (validation_heap, vs, new_time.abs_value_us); else - GNUNET_CONTAINER_heap_update_cost(vs->hn, new_time.abs_value_us); - if ((vs != GNUNET_CONTAINER_heap_peek(validation_heap)) && + GNUNET_CONTAINER_heap_update_cost (vs->hn, new_time.abs_value_us); + if ((vs != GNUNET_CONTAINER_heap_peek (validation_heap)) && (NULL != validation_task)) return; if (NULL != validation_task) - GNUNET_SCHEDULER_cancel(validation_task); + GNUNET_SCHEDULER_cancel (validation_task); /* randomize a bit */ delta.rel_value_us = - GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, - MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); - new_time = GNUNET_TIME_absolute_add(new_time, delta); + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, + MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); + new_time = GNUNET_TIME_absolute_add (new_time, delta); validation_task = - GNUNET_SCHEDULER_add_at(new_time, &validation_start_cb, NULL); + GNUNET_SCHEDULER_add_at (new_time, &validation_start_cb, NULL); } @@ -7541,57 +7598,58 @@ update_next_challenge_time(struct ValidationState *vs, * @param address an address to reach @a pid (presumably) */ static void -start_address_validation(const struct GNUNET_PeerIdentity *pid, - const char *address) +start_address_validation (const struct GNUNET_PeerIdentity *pid, + const char *address) { struct GNUNET_TIME_Absolute now; struct ValidationState *vs; struct CheckKnownAddressContext ckac = { .address = address, .vs = NULL }; - (void)GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, - pid, - &check_known_address, - &ckac); + (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, + pid, + &check_known_address, + &ckac); if (NULL != (vs = ckac.vs)) - { - /* if 'vs' is not currently valid, we need to speed up retrying the - * validation */ - if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) - { - /* reduce backoff as we got a fresh advertisement */ - vs->challenge_backoff = - GNUNET_TIME_relative_min(FAST_VALIDATION_CHALLENGE_FREQ, - GNUNET_TIME_relative_divide(vs->challenge_backoff, - 2)); - update_next_challenge_time(vs, - GNUNET_TIME_relative_to_absolute( - vs->challenge_backoff)); - } - return; + { + /* if 'vs' is not currently valid, we need to speed up retrying the + * validation */ + if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) + { + /* reduce backoff as we got a fresh advertisement */ + vs->challenge_backoff = + GNUNET_TIME_relative_min (FAST_VALIDATION_CHALLENGE_FREQ, + GNUNET_TIME_relative_divide ( + vs->challenge_backoff, + 2)); + update_next_challenge_time (vs, + GNUNET_TIME_relative_to_absolute ( + vs->challenge_backoff)); } - now = GNUNET_TIME_absolute_get(); - vs = GNUNET_new(struct ValidationState); + return; + } + now = GNUNET_TIME_absolute_get (); + vs = GNUNET_new (struct ValidationState); vs->pid = *pid; vs->valid_until = - GNUNET_TIME_relative_to_absolute(ADDRESS_VALIDATION_LIFETIME); + GNUNET_TIME_relative_to_absolute (ADDRESS_VALIDATION_LIFETIME); vs->first_challenge_use = now; vs->validation_rtt = GNUNET_TIME_UNIT_FOREVER_REL; - GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, - &vs->challenge, - sizeof(vs->challenge)); - vs->address = GNUNET_strdup(address); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Starting address validation `%s' of peer %s using challenge %s\n", - address, - GNUNET_i2s(pid), - GNUNET_sh2s(&vs->challenge.value)); - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put( - validation_map, - &vs->pid, - vs, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - update_next_challenge_time(vs, now); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + &vs->challenge, + sizeof(vs->challenge)); + vs->address = GNUNET_strdup (address); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting address validation `%s' of peer %s using challenge %s\n", + address, + GNUNET_i2s (pid), + GNUNET_sh2s (&vs->challenge.value)); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put ( + validation_map, + &vs->pid, + vs, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + update_next_challenge_time (vs, now); } @@ -7603,27 +7661,27 @@ start_address_validation(const struct GNUNET_PeerIdentity *pid, * @param emsg error message, or NULL if no errors */ static void -handle_hello_for_incoming(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +handle_hello_for_incoming (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { struct IncomingRequest *ir = cls; const char *val; if (NULL != emsg) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Got failure from PEERSTORE: %s\n", - emsg); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Got failure from PEERSTORE: %s\n", + emsg); + return; + } val = record->value; if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) - { - GNUNET_break(0); - return; - } - start_address_validation(&ir->pid, (const char *)record->value); + { + GNUNET_break (0); + return; + } + start_address_validation (&ir->pid, (const char *) record->value); } @@ -7636,7 +7694,7 @@ handle_hello_for_incoming(void *cls, * @param tvc the message that was received */ static void -handle_validation_challenge( +handle_validation_challenge ( void *cls, const struct TransportValidationChallengeMessage *tvc) { @@ -7650,44 +7708,44 @@ handle_validation_challenge( /* DV-routed messages are not allowed for validation challenges */ if (cmc->total_hops > 0) - { - GNUNET_break_op(0); - finish_cmc_handling(cmc); - return; - } + { + GNUNET_break_op (0); + finish_cmc_handling (cmc); + return; + } validity_duration = cmc->im.expected_address_validity; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received address validation challenge %s\n", - GNUNET_sh2s(&tvc->challenge.value)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received address validation challenge %s\n", + GNUNET_sh2s (&tvc->challenge.value)); /* If we have a virtual link, we use this mechanism to signal the size of the flow control window, and to allow the sender to ask for increases. If for us the virtual link is still down, we will always give a window size of zero. */ tvr.header.type = - htons(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); - tvr.header.size = htons(sizeof(tvr)); - tvr.reserved = htonl(0); + htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); + tvr.header.size = htons (sizeof(tvr)); + tvr.reserved = htonl (0); tvr.challenge = tvc->challenge; tvr.origin_time = tvc->sender_time; tvr.validity_duration = validity_duration; { /* create signature */ struct TransportValidationPS tvp = - { .purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), - .purpose.size = htonl(sizeof(tvp)), + { .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), + .purpose.size = htonl (sizeof(tvp)), .validity_duration = validity_duration, .challenge = tvc->challenge }; - GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, - &tvp.purpose, - &tvr.signature)); + GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, + &tvp.purpose, + &tvr.signature)); } - route_control_message_without_fc(&cmc->im.sender, - &tvr.header, - RMO_ANYTHING_GOES | RMO_REDUNDANT); + route_control_message_without_fc (&cmc->im.sender, + &tvr.header, + RMO_ANYTHING_GOES | RMO_REDUNDANT); sender = cmc->im.sender; - finish_cmc_handling(cmc); - vl = lookup_virtual_link(&sender); + finish_cmc_handling (cmc); + vl = lookup_virtual_link (&sender); if (NULL != vl) return; @@ -7696,36 +7754,37 @@ handle_validation_challenge( CORE), so we must try to bring the link up! */ /* (1) Check existing queues, if any, we may be lucky! */ - n = lookup_neighbour(&sender); + n = lookup_neighbour (&sender); if (NULL != n) for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) - start_address_validation(&sender, q->address); + start_address_validation (&sender, q->address); /* (2) Also try to see if we have addresses in PEERSTORE for this peer we could use */ for (ir = ir_head; NULL != ir; ir = ir->next) - if (0 == GNUNET_memcmp(&ir->pid, &sender)) + if (0 == GNUNET_memcmp (&ir->pid, &sender)) return; /* we are already trying */ - ir = GNUNET_new(struct IncomingRequest); + ir = GNUNET_new (struct IncomingRequest); ir->pid = sender; - GNUNET_CONTAINER_DLL_insert(ir_head, ir_tail, ir); - ir->wc = GNUNET_PEERSTORE_watch(peerstore, - "transport", - &ir->pid, - GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, - &handle_hello_for_incoming, - ir); + GNUNET_CONTAINER_DLL_insert (ir_head, ir_tail, ir); + ir->wc = GNUNET_PEERSTORE_watch (peerstore, + "transport", + &ir->pid, + GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, + &handle_hello_for_incoming, + ir); ir_total++; /* Bound attempts we do in parallel here, might otherwise get excessive */ while (ir_total > MAX_INCOMING_REQUEST) - free_incoming_request(ir_head); + free_incoming_request (ir_head); } /** * Closure for #check_known_challenge. */ -struct CheckKnownChallengeContext { +struct CheckKnownChallengeContext +{ /** * Set to the challenge we are looking for. */ @@ -7748,15 +7807,15 @@ struct CheckKnownChallengeContext { * @return #GNUNET_OK if not matching, #GNUNET_NO if match found */ static int -check_known_challenge(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +check_known_challenge (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct CheckKnownChallengeContext *ckac = cls; struct ValidationState *vs = value; - (void)pid; - if (0 != GNUNET_memcmp(&vs->challenge, ckac->challenge)) + (void) pid; + if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge)) return GNUNET_OK; ckac->vs = vs; return GNUNET_NO; @@ -7771,17 +7830,17 @@ check_known_challenge(void *cls, * @param success #GNUNET_YES on success */ static void -peerstore_store_validation_cb(void *cls, int success) +peerstore_store_validation_cb (void *cls, int success) { struct ValidationState *vs = cls; vs->sc = NULL; if (GNUNET_YES == success) return; - GNUNET_STATISTICS_update(GST_stats, - "# Peerstore failed to store foreign address", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GST_stats, + "# Peerstore failed to store foreign address", + 1, + GNUNET_NO); } @@ -7793,19 +7852,19 @@ peerstore_store_validation_cb(void *cls, int success) * @return NULL if no such queue exists */ static struct Queue * -find_queue(const struct GNUNET_PeerIdentity *pid, const char *address) +find_queue (const struct GNUNET_PeerIdentity *pid, const char *address) { struct Neighbour *n; - n = lookup_neighbour(pid); + n = lookup_neighbour (pid); if (NULL == n) return NULL; for (struct Queue *pos = n->queue_head; NULL != pos; pos = pos->next_neighbour) - { - if (0 == strcmp(pos->address, address)) - return pos; - } + { + if (0 == strcmp (pos->address, address)) + return pos; + } return NULL; } @@ -7819,7 +7878,7 @@ find_queue(const struct GNUNET_PeerIdentity *pid, const char *address) * @param tvr the message that was received */ static void -handle_validation_response( +handle_validation_response ( void *cls, const struct TransportValidationResponseMessage *tvr) { @@ -7833,147 +7892,147 @@ handle_validation_response( struct VirtualLink *vl; /* check this is one of our challenges */ - (void)GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, - &cmc->im.sender, - &check_known_challenge, - &ckac); + (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, + &cmc->im.sender, + &check_known_challenge, + &ckac); if (NULL == (vs = ckac.vs)) - { - /* This can happen simply if we 'forgot' the challenge by now, - i.e. because we received the validation response twice */ - GNUNET_STATISTICS_update(GST_stats, - "# Validations dropped, challenge unknown", - 1, - GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Validation response %s dropped, challenge unknown\n", - GNUNET_sh2s(&tvr->challenge.value)); - finish_cmc_handling(cmc); - return; - } + { + /* This can happen simply if we 'forgot' the challenge by now, + i.e. because we received the validation response twice */ + GNUNET_STATISTICS_update (GST_stats, + "# Validations dropped, challenge unknown", + 1, + GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Validation response %s dropped, challenge unknown\n", + GNUNET_sh2s (&tvr->challenge.value)); + finish_cmc_handling (cmc); + return; + } /* sanity check on origin time */ - origin_time = GNUNET_TIME_absolute_ntoh(tvr->origin_time); + origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time); if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) || (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us)) - { - GNUNET_break_op(0); - finish_cmc_handling(cmc); - return; - } + { + GNUNET_break_op (0); + finish_cmc_handling (cmc); + return; + } { /* check signature */ struct TransportValidationPS tvp = - { .purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), - .purpose.size = htonl(sizeof(tvp)), + { .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), + .purpose.size = htonl (sizeof(tvp)), .validity_duration = tvr->validity_duration, .challenge = tvr->challenge }; if ( GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, - &tvp.purpose, - &tvr->signature, - &cmc->im.sender.public_key)) - { - GNUNET_break_op(0); - finish_cmc_handling(cmc); - return; - } + GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, + &tvp.purpose, + &tvr->signature, + &cmc->im.sender.public_key)) + { + GNUNET_break_op (0); + finish_cmc_handling (cmc); + return; + } } /* validity is capped by our willingness to keep track of the validation entry and the maximum the other peer allows */ - vs->valid_until = GNUNET_TIME_relative_to_absolute( - GNUNET_TIME_relative_min(GNUNET_TIME_relative_ntoh( - tvr->validity_duration), - MAX_ADDRESS_VALID_UNTIL)); + vs->valid_until = GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_relative_min (GNUNET_TIME_relative_ntoh ( + tvr->validity_duration), + MAX_ADDRESS_VALID_UNTIL)); vs->validated_until = - GNUNET_TIME_absolute_min(vs->valid_until, - GNUNET_TIME_relative_to_absolute( - ADDRESS_VALIDATION_LIFETIME)); - vs->validation_rtt = GNUNET_TIME_absolute_get_duration(origin_time); + GNUNET_TIME_absolute_min (vs->valid_until, + GNUNET_TIME_relative_to_absolute ( + ADDRESS_VALIDATION_LIFETIME)); + vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time); vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO; - GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, - &vs->challenge, - sizeof(vs->challenge)); - vs->first_challenge_use = GNUNET_TIME_absolute_subtract( + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + &vs->challenge, + sizeof(vs->challenge)); + vs->first_challenge_use = GNUNET_TIME_absolute_subtract ( vs->validated_until, - GNUNET_TIME_relative_multiply(vs->validation_rtt, - VALIDATION_RTT_BUFFER_FACTOR)); + GNUNET_TIME_relative_multiply (vs->validation_rtt, + VALIDATION_RTT_BUFFER_FACTOR)); vs->last_challenge_use = GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */ - update_next_challenge_time(vs, vs->first_challenge_use); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Validation response %s accepted, address valid until %s\n", - GNUNET_sh2s(&tvr->challenge.value), - GNUNET_STRINGS_absolute_time_to_string(vs->valid_until)); - vs->sc = GNUNET_PEERSTORE_store(peerstore, - "transport", - &cmc->im.sender, - GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, - vs->address, - strlen(vs->address) + 1, - vs->valid_until, - GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, - &peerstore_store_validation_cb, - vs); - finish_cmc_handling(cmc); + update_next_challenge_time (vs, vs->first_challenge_use); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Validation response %s accepted, address valid until %s\n", + GNUNET_sh2s (&tvr->challenge.value), + GNUNET_STRINGS_absolute_time_to_string (vs->valid_until)); + vs->sc = GNUNET_PEERSTORE_store (peerstore, + "transport", + &cmc->im.sender, + GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, + vs->address, + strlen (vs->address) + 1, + vs->valid_until, + GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, + &peerstore_store_validation_cb, + vs); + finish_cmc_handling (cmc); /* Finally, we now possibly have a confirmed (!) working queue, update queue status (if queue still is around) */ - q = find_queue(&vs->pid, vs->address); + q = find_queue (&vs->pid, vs->address); if (NULL == q) - { - GNUNET_STATISTICS_update(GST_stats, - "# Queues lost at time of successful validation", - 1, - GNUNET_NO); - return; - } + { + GNUNET_STATISTICS_update (GST_stats, + "# Queues lost at time of successful validation", + 1, + GNUNET_NO); + return; + } q->validated_until = vs->validated_until; q->pd.aged_rtt = vs->validation_rtt; n = q->neighbour; - vl = lookup_virtual_link(&vs->pid); + vl = lookup_virtual_link (&vs->pid); if (NULL != vl) + { + /* Link was already up, remember n is also now available and we are done */ + if (NULL == vl->n) { - /* Link was already up, remember n is also now available and we are done */ - if (NULL == vl->n) - { - vl->n = n; - n->vl = vl; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Virtual link to %s could now also direct neighbour!\n", - GNUNET_i2s(&vs->pid)); - } - else - { - GNUNET_assert(n == vl->n); - } - return; + vl->n = n; + n->vl = vl; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Virtual link to %s could now also direct neighbour!\n", + GNUNET_i2s (&vs->pid)); + } + else + { + GNUNET_assert (n == vl->n); } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Creating new virtual link to %s using direct neighbour!\n", - GNUNET_i2s(&vs->pid)); - vl = GNUNET_new(struct VirtualLink); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Creating new virtual link to %s using direct neighbour!\n", + GNUNET_i2s (&vs->pid)); + vl = GNUNET_new (struct VirtualLink); vl->target = n->pid; vl->n = n; n->vl = vl; vl->core_recv_window = RECV_WINDOW_SIZE; vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; vl->visibility_task = - GNUNET_SCHEDULER_add_at(q->validated_until, &check_link_down, vl); - GNUNET_break(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put( - links, - &vl->target, - vl, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - consider_sending_fc(vl); + GNUNET_SCHEDULER_add_at (q->validated_until, &check_link_down, vl); + GNUNET_break (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put ( + links, + &vl->target, + vl, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + consider_sending_fc (vl); /* We lacked a confirmed connection to the target before, so tell CORE about it (finally!) */ - cores_send_connect_info(&n->pid); + cores_send_connect_info (&n->pid); } @@ -7983,19 +8042,19 @@ handle_validation_response( * @param im the send message that was received */ static void -handle_incoming_msg(void *cls, - const struct GNUNET_TRANSPORT_IncomingMessage *im) +handle_incoming_msg (void *cls, + const struct GNUNET_TRANSPORT_IncomingMessage *im) { struct TransportClient *tc = cls; struct CommunicatorMessageContext *cmc = - GNUNET_new(struct CommunicatorMessageContext); + GNUNET_new (struct CommunicatorMessageContext); cmc->tc = tc; cmc->im = *im; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received message via communicator from peer %s\n", - GNUNET_i2s(&im->sender)); - demultiplex_with_cmc(cmc, (const struct GNUNET_MessageHeader *)&im[1]); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received message via communicator from peer %s\n", + GNUNET_i2s (&im->sender)); + demultiplex_with_cmc (cmc, (const struct GNUNET_MessageHeader *) &im[1]); } @@ -8008,7 +8067,7 @@ handle_incoming_msg(void *cls, * @param fc the message that was received */ static void -handle_flow_control(void *cls, const struct TransportFlowControlMessage *fc) +handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc) { struct CommunicatorMessageContext *cmc = cls; struct VirtualLink *vl; @@ -8017,70 +8076,70 @@ handle_flow_control(void *cls, const struct TransportFlowControlMessage *fc) uint64_t os; uint64_t wnd; - vl = lookup_virtual_link(&cmc->im.sender); + vl = lookup_virtual_link (&cmc->im.sender); if (NULL == vl) - { - GNUNET_STATISTICS_update(GST_stats, - "# FC dropped: virtual link unknown", - 1, - GNUNET_NO); - finish_cmc_handling(cmc); - return; - } - st = GNUNET_TIME_absolute_ntoh(fc->sender_time); + { + GNUNET_STATISTICS_update (GST_stats, + "# FC dropped: virtual link unknown", + 1, + GNUNET_NO); + finish_cmc_handling (cmc); + return; + } + st = GNUNET_TIME_absolute_ntoh (fc->sender_time); if (st.abs_value_us < vl->last_fc_timestamp.abs_value_us) - { - /* out of order, drop */ - GNUNET_STATISTICS_update(GST_stats, - "# FC dropped: message out of order", - 1, - GNUNET_NO); - finish_cmc_handling(cmc); - return; - } - seq = ntohl(fc->seq); + { + /* out of order, drop */ + GNUNET_STATISTICS_update (GST_stats, + "# FC dropped: message out of order", + 1, + GNUNET_NO); + finish_cmc_handling (cmc); + return; + } + seq = ntohl (fc->seq); if (seq < vl->last_fc_seq) - { - /* Wrap-around/reset of other peer; start all counters from zero */ - vl->outbound_fc_window_size_used = 0; - } + { + /* Wrap-around/reset of other peer; start all counters from zero */ + vl->outbound_fc_window_size_used = 0; + } vl->last_fc_seq = seq; vl->last_fc_timestamp = st; - vl->outbound_fc_window_size = GNUNET_ntohll(fc->inbound_window_size); - os = GNUNET_ntohll(fc->outbound_sent); + vl->outbound_fc_window_size = GNUNET_ntohll (fc->inbound_window_size); + os = GNUNET_ntohll (fc->outbound_sent); vl->incoming_fc_window_size_loss = - (int64_t)(os - vl->incoming_fc_window_size_used); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received FC from %s, seq %u, new window %llu (loss at %lld)\n", - GNUNET_i2s(&vl->target), - (unsigned int)seq, - (unsigned long long)vl->outbound_fc_window_size, - (long long)vl->incoming_fc_window_size_loss); - wnd = GNUNET_ntohll(fc->outbound_window_size); + (int64_t) (os - vl->incoming_fc_window_size_used); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received FC from %s, seq %u, new window %llu (loss at %lld)\n", + GNUNET_i2s (&vl->target), + (unsigned int) seq, + (unsigned long long) vl->outbound_fc_window_size, + (long long) vl->incoming_fc_window_size_loss); + wnd = GNUNET_ntohll (fc->outbound_window_size); if ((wnd < vl->incoming_fc_window_size) || (vl->last_outbound_window_size_received != wnd) || - (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) % - FC_NO_CHANGE_REPLY_PROBABILITY)) - { - /* Consider re-sending our FC message, as clearly the - other peer's idea of the window is not up-to-date */ - consider_sending_fc(vl); - } + (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) + % FC_NO_CHANGE_REPLY_PROBABILITY)) + { + /* Consider re-sending our FC message, as clearly the + other peer's idea of the window is not up-to-date */ + consider_sending_fc (vl); + } if ((wnd == vl->incoming_fc_window_size) && (vl->last_outbound_window_size_received == wnd) && (NULL != vl->fc_retransmit_task)) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Stopping FC retransmission to %s: peer is current at window %llu\n", - GNUNET_i2s(&vl->target), - (unsigned long long)wnd); - GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task); - vl->fc_retransmit_task = NULL; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Stopping FC retransmission to %s: peer is current at window %llu\n", + GNUNET_i2s (&vl->target), + (unsigned long long) wnd); + GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); + vl->fc_retransmit_task = NULL; + } vl->last_outbound_window_size_received = wnd; /* FC window likely increased, check transmission possibilities! */ - check_vl_transmission(vl); - finish_cmc_handling(cmc); + check_vl_transmission (vl); + finish_cmc_handling (cmc); } @@ -8092,68 +8151,68 @@ handle_flow_control(void *cls, const struct TransportFlowControlMessage *fc) * @param msg message to demultiplex */ static void -demultiplex_with_cmc(struct CommunicatorMessageContext *cmc, - const struct GNUNET_MessageHeader *msg) +demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_var_size(fragment_box, - GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, - struct TransportFragmentBoxMessage, - &cmc), - GNUNET_MQ_hd_var_size(reliability_box, - GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, - struct TransportReliabilityBoxMessage, - &cmc), - GNUNET_MQ_hd_var_size(reliability_ack, - GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, - struct TransportReliabilityAckMessage, - &cmc), - GNUNET_MQ_hd_var_size(backchannel_encapsulation, - GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, - struct TransportBackchannelEncapsulationMessage, - &cmc), - GNUNET_MQ_hd_var_size(dv_learn, - GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, - struct TransportDVLearnMessage, - &cmc), - GNUNET_MQ_hd_var_size(dv_box, - GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, - struct TransportDVBoxMessage, - &cmc), - GNUNET_MQ_hd_fixed_size( + { GNUNET_MQ_hd_var_size (fragment_box, + GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, + struct TransportFragmentBoxMessage, + &cmc), + GNUNET_MQ_hd_var_size (reliability_box, + GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, + struct TransportReliabilityBoxMessage, + &cmc), + GNUNET_MQ_hd_var_size (reliability_ack, + GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, + struct TransportReliabilityAckMessage, + &cmc), + GNUNET_MQ_hd_var_size (backchannel_encapsulation, + GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, + struct TransportBackchannelEncapsulationMessage, + &cmc), + GNUNET_MQ_hd_var_size (dv_learn, + GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, + struct TransportDVLearnMessage, + &cmc), + GNUNET_MQ_hd_var_size (dv_box, + GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, + struct TransportDVBoxMessage, + &cmc), + GNUNET_MQ_hd_fixed_size ( validation_challenge, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE, struct TransportValidationChallengeMessage, &cmc), - GNUNET_MQ_hd_fixed_size(flow_control, - GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL, - struct TransportFlowControlMessage, - &cmc), - GNUNET_MQ_hd_fixed_size( + GNUNET_MQ_hd_fixed_size (flow_control, + GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL, + struct TransportFlowControlMessage, + &cmc), + GNUNET_MQ_hd_fixed_size ( validation_response, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE, struct TransportValidationResponseMessage, &cmc), - GNUNET_MQ_handler_end() }; + GNUNET_MQ_handler_end () }; int ret; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Handling message of type %u with %u bytes\n", - (unsigned int)ntohs(msg->type), - (unsigned int)ntohs(msg->size)); - ret = GNUNET_MQ_handle_message(handlers, msg); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Handling message of type %u with %u bytes\n", + (unsigned int) ntohs (msg->type), + (unsigned int) ntohs (msg->size)); + ret = GNUNET_MQ_handle_message (handlers, msg); if (GNUNET_SYSERR == ret) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(cmc->tc->client); - GNUNET_free(cmc); - return; - } + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (cmc->tc->client); + GNUNET_free (cmc); + return; + } if (GNUNET_NO == ret) - { - /* unencapsulated 'raw' message */ - handle_raw_message(&cmc, msg); - } + { + /* unencapsulated 'raw' message */ + handle_raw_message (&cmc, msg); + } } @@ -8164,17 +8223,17 @@ demultiplex_with_cmc(struct CommunicatorMessageContext *cmc, * @param aqm the send message that was sent */ static int -check_add_queue_message(void *cls, - const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) +check_add_queue_message (void *cls, + const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - GNUNET_MQ_check_zero_termination(aqm); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + GNUNET_MQ_check_zero_termination (aqm); return GNUNET_OK; } @@ -8185,7 +8244,7 @@ check_add_queue_message(void *cls, * @param pm pending message to generate UUID for. */ static void -set_pending_message_uuid(struct PendingMessage *pm) +set_pending_message_uuid (struct PendingMessage *pm) { if (pm->msg_uuid_set) return; @@ -8203,37 +8262,37 @@ set_pending_message_uuid(struct PendingMessage *pm) * @return corresponding fresh pending acknowledgement */ static struct PendingAcknowledgement * -prepare_pending_acknowledgement(struct Queue *queue, - struct DistanceVectorHop *dvh, - struct PendingMessage *pm) +prepare_pending_acknowledgement (struct Queue *queue, + struct DistanceVectorHop *dvh, + struct PendingMessage *pm) { struct PendingAcknowledgement *pa; - pa = GNUNET_new(struct PendingAcknowledgement); + pa = GNUNET_new (struct PendingAcknowledgement); pa->queue = queue; pa->dvh = dvh; pa->pm = pm; do - { - GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, - &pa->ack_uuid, - sizeof(pa->ack_uuid)); - } - while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put( + { + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + &pa->ack_uuid, + sizeof(pa->ack_uuid)); + } + while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put ( pending_acks, &pa->ack_uuid.value, pa, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - GNUNET_CONTAINER_MDLL_insert(queue, queue->pa_head, queue->pa_tail, pa); - GNUNET_CONTAINER_MDLL_insert(pm, pm->pa_head, pm->pa_tail, pa); + GNUNET_CONTAINER_MDLL_insert (queue, queue->pa_head, queue->pa_tail, pa); + GNUNET_CONTAINER_MDLL_insert (pm, pm->pa_head, pm->pa_tail, pa); if (NULL != dvh) - GNUNET_CONTAINER_MDLL_insert(dvh, dvh->pa_head, dvh->pa_tail, pa); - pa->transmission_time = GNUNET_TIME_absolute_get(); + GNUNET_CONTAINER_MDLL_insert (dvh, dvh->pa_head, dvh->pa_tail, pa); + pa->transmission_time = GNUNET_TIME_absolute_get (); pa->message_size = pm->bytes_msg; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Waiting for ACKnowledgment `%s' for <%llu>\n", - GNUNET_uuid2s(&pa->ack_uuid.value), - pm->logging_uuid); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Waiting for ACKnowledgment `%s' for <%llu>\n", + GNUNET_uuid2s (&pa->ack_uuid.value), + pm->logging_uuid); return pa; } @@ -8250,9 +8309,9 @@ prepare_pending_acknowledgement(struct Queue *queue, * @return new message to transmit */ static struct PendingMessage * -fragment_message(struct Queue *queue, - struct DistanceVectorHop *dvh, - struct PendingMessage *pm) +fragment_message (struct Queue *queue, + struct DistanceVectorHop *dvh, + struct PendingMessage *pm) { struct PendingAcknowledgement *pa; struct PendingMessage *ff; @@ -8261,17 +8320,17 @@ fragment_message(struct Queue *queue, mtu = (0 == queue->mtu) ? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo) : queue->mtu; - set_pending_message_uuid(pm); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Fragmenting message %llu <%llu> to %s for MTU %u\n", - (unsigned long long)pm->msg_uuid.uuid, - pm->logging_uuid, - GNUNET_i2s(&pm->vl->target), - (unsigned int)mtu); - pa = prepare_pending_acknowledgement(queue, dvh, pm); + set_pending_message_uuid (pm); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Fragmenting message %llu <%llu> to %s for MTU %u\n", + (unsigned long long) pm->msg_uuid.uuid, + pm->logging_uuid, + GNUNET_i2s (&pm->vl->target), + (unsigned int) mtu); + pa = prepare_pending_acknowledgement (queue, dvh, pm); /* This invariant is established in #handle_add_queue_message() */ - GNUNET_assert(mtu > sizeof(struct TransportFragmentBoxMessage)); + GNUNET_assert (mtu > sizeof(struct TransportFragmentBoxMessage)); /* select fragment for transmission, descending the tree if it has been expanded until we are at a leaf or at a fragment that is small @@ -8280,68 +8339,68 @@ fragment_message(struct Queue *queue, ff = pm; while (((ff->bytes_msg > mtu) || (pm == ff)) && (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag)) - { - ff = ff->head_frag; /* descent into fragmented fragments */ - } + { + ff = ff->head_frag; /* descent into fragmented fragments */ + } if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg)) - { - /* Did not yet calculate all fragments, calculate next fragment */ - struct PendingMessage *frag; - struct TransportFragmentBoxMessage tfb; - const char *orig; - char *msg; - uint16_t fragmax; - uint16_t fragsize; - uint16_t msize; - uint16_t xoff = 0; - - orig = (const char *)&ff[1]; - msize = ff->bytes_msg; - if (pm != ff) - { - const struct TransportFragmentBoxMessage *tfbo; - - tfbo = (const struct TransportFragmentBoxMessage *)orig; - orig += sizeof(struct TransportFragmentBoxMessage); - msize -= sizeof(struct TransportFragmentBoxMessage); - xoff = ntohs(tfbo->frag_off); - } - fragmax = mtu - sizeof(struct TransportFragmentBoxMessage); - fragsize = GNUNET_MIN(msize - ff->frag_off, fragmax); - frag = - GNUNET_malloc(sizeof(struct PendingMessage) + - sizeof(struct TransportFragmentBoxMessage) + fragsize); - frag->logging_uuid = logging_uuid_gen++; - frag->vl = pm->vl; - frag->frag_parent = ff; - frag->timeout = pm->timeout; - frag->bytes_msg = sizeof(struct TransportFragmentBoxMessage) + fragsize; - frag->pmt = PMT_FRAGMENT_BOX; - msg = (char *)&frag[1]; - tfb.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); - tfb.header.size = - htons(sizeof(struct TransportFragmentBoxMessage) + fragsize); - tfb.ack_uuid = pa->ack_uuid; - tfb.msg_uuid = pm->msg_uuid; - tfb.frag_off = htons(ff->frag_off + xoff); - tfb.msg_size = htons(pm->bytes_msg); - memcpy(msg, &tfb, sizeof(tfb)); - memcpy(&msg[sizeof(tfb)], &orig[ff->frag_off], fragsize); - GNUNET_CONTAINER_MDLL_insert(frag, ff->head_frag, ff->tail_frag, frag); - ff->frag_off += fragsize; - ff = frag; - } + { + /* Did not yet calculate all fragments, calculate next fragment */ + struct PendingMessage *frag; + struct TransportFragmentBoxMessage tfb; + const char *orig; + char *msg; + uint16_t fragmax; + uint16_t fragsize; + uint16_t msize; + uint16_t xoff = 0; + + orig = (const char *) &ff[1]; + msize = ff->bytes_msg; + if (pm != ff) + { + const struct TransportFragmentBoxMessage *tfbo; + + tfbo = (const struct TransportFragmentBoxMessage *) orig; + orig += sizeof(struct TransportFragmentBoxMessage); + msize -= sizeof(struct TransportFragmentBoxMessage); + xoff = ntohs (tfbo->frag_off); + } + fragmax = mtu - sizeof(struct TransportFragmentBoxMessage); + fragsize = GNUNET_MIN (msize - ff->frag_off, fragmax); + frag = + GNUNET_malloc (sizeof(struct PendingMessage) + + sizeof(struct TransportFragmentBoxMessage) + fragsize); + frag->logging_uuid = logging_uuid_gen++; + frag->vl = pm->vl; + frag->frag_parent = ff; + frag->timeout = pm->timeout; + frag->bytes_msg = sizeof(struct TransportFragmentBoxMessage) + fragsize; + frag->pmt = PMT_FRAGMENT_BOX; + msg = (char *) &frag[1]; + tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); + tfb.header.size = + htons (sizeof(struct TransportFragmentBoxMessage) + fragsize); + tfb.ack_uuid = pa->ack_uuid; + tfb.msg_uuid = pm->msg_uuid; + tfb.frag_off = htons (ff->frag_off + xoff); + tfb.msg_size = htons (pm->bytes_msg); + memcpy (msg, &tfb, sizeof(tfb)); + memcpy (&msg[sizeof(tfb)], &orig[ff->frag_off], fragsize); + GNUNET_CONTAINER_MDLL_insert (frag, ff->head_frag, ff->tail_frag, frag); + ff->frag_off += fragsize; + ff = frag; + } /* Move head to the tail and return it */ - GNUNET_CONTAINER_MDLL_remove(frag, - ff->frag_parent->head_frag, - ff->frag_parent->tail_frag, - ff); - GNUNET_CONTAINER_MDLL_insert_tail(frag, - ff->frag_parent->head_frag, - ff->frag_parent->tail_frag, - ff); + GNUNET_CONTAINER_MDLL_remove (frag, + ff->frag_parent->head_frag, + ff->frag_parent->tail_frag, + ff); + GNUNET_CONTAINER_MDLL_insert_tail (frag, + ff->frag_parent->head_frag, + ff->frag_parent->tail_frag, + ff); return ff; } @@ -8359,9 +8418,9 @@ fragment_message(struct Queue *queue, * @return new message to transmit */ static struct PendingMessage * -reliability_box_message(struct Queue *queue, - struct DistanceVectorHop *dvh, - struct PendingMessage *pm) +reliability_box_message (struct Queue *queue, + struct DistanceVectorHop *dvh, + struct PendingMessage *pm) { struct TransportReliabilityBoxMessage rbox; struct PendingAcknowledgement *pa; @@ -8373,39 +8432,39 @@ reliability_box_message(struct Queue *queue, do nothing */ if (NULL != pm->bpm) return pm->bpm; /* already computed earlier: do nothing */ - GNUNET_assert(NULL == pm->head_frag); + GNUNET_assert (NULL == pm->head_frag); if (pm->bytes_msg + sizeof(rbox) > UINT16_MAX) - { - /* failed hard */ - GNUNET_break(0); - client_send_response(pm); - return NULL; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Preparing reliability box for message <%llu> to %s on queue %s\n", - pm->logging_uuid, - GNUNET_i2s(&pm->vl->target), - queue->address); - pa = prepare_pending_acknowledgement(queue, dvh, pm); - - bpm = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(rbox) + - pm->bytes_msg); + { + /* failed hard */ + GNUNET_break (0); + client_send_response (pm); + return NULL; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Preparing reliability box for message <%llu> to %s on queue %s\n", + pm->logging_uuid, + GNUNET_i2s (&pm->vl->target), + queue->address); + pa = prepare_pending_acknowledgement (queue, dvh, pm); + + bpm = GNUNET_malloc (sizeof(struct PendingMessage) + sizeof(rbox) + + pm->bytes_msg); bpm->logging_uuid = logging_uuid_gen++; bpm->vl = pm->vl; bpm->frag_parent = pm; - GNUNET_CONTAINER_MDLL_insert(frag, pm->head_frag, pm->tail_frag, bpm); + GNUNET_CONTAINER_MDLL_insert (frag, pm->head_frag, pm->tail_frag, bpm); bpm->timeout = pm->timeout; bpm->pmt = PMT_RELIABILITY_BOX; bpm->bytes_msg = pm->bytes_msg + sizeof(rbox); - set_pending_message_uuid(bpm); - rbox.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX); - rbox.header.size = htons(sizeof(rbox) + pm->bytes_msg); - rbox.ack_countdown = htonl(0); // FIXME: implement ACK countdown support + set_pending_message_uuid (bpm); + rbox.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX); + rbox.header.size = htons (sizeof(rbox) + pm->bytes_msg); + rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support rbox.ack_uuid = pa->ack_uuid; - msg = (char *)&bpm[1]; - memcpy(msg, &rbox, sizeof(rbox)); - memcpy(&msg[sizeof(rbox)], &pm[1], pm->bytes_msg); + msg = (char *) &bpm[1]; + memcpy (msg, &rbox, sizeof(rbox)); + memcpy (&msg[sizeof(rbox)], &pm[1], pm->bytes_msg); pm->bpm = bpm; return bpm; } @@ -8420,60 +8479,61 @@ reliability_box_message(struct Queue *queue, * @param next_attempt timestamp to use */ static void -update_pm_next_attempt(struct PendingMessage *pm, - struct GNUNET_TIME_Absolute next_attempt) +update_pm_next_attempt (struct PendingMessage *pm, + struct GNUNET_TIME_Absolute next_attempt) { struct VirtualLink *vl = pm->vl; pm->next_attempt = next_attempt; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Next attempt for message <%llu> set to %s\n", - pm->logging_uuid, - GNUNET_STRINGS_absolute_time_to_string(next_attempt)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Next attempt for message <%llu> set to %s\n", + pm->logging_uuid, + GNUNET_STRINGS_absolute_time_to_string (next_attempt)); if (NULL == pm->frag_parent) - { - struct PendingMessage *pos; - - /* re-insert sort in neighbour list */ - GNUNET_CONTAINER_MDLL_remove(vl, - vl->pending_msg_head, - vl->pending_msg_tail, - pm); - pos = vl->pending_msg_tail; - while ((NULL != pos) && - (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) - pos = pos->prev_vl; - GNUNET_CONTAINER_MDLL_insert_after(vl, - vl->pending_msg_head, - vl->pending_msg_tail, - pos, - pm); - } + { + struct PendingMessage *pos; + + /* re-insert sort in neighbour list */ + GNUNET_CONTAINER_MDLL_remove (vl, + vl->pending_msg_head, + vl->pending_msg_tail, + pm); + pos = vl->pending_msg_tail; + while ((NULL != pos) && + (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) + pos = pos->prev_vl; + GNUNET_CONTAINER_MDLL_insert_after (vl, + vl->pending_msg_head, + vl->pending_msg_tail, + pos, + pm); + } else - { - /* re-insert sort in fragment list */ - struct PendingMessage *fp = pm->frag_parent; - struct PendingMessage *pos; - - GNUNET_CONTAINER_MDLL_remove(frag, fp->head_frag, fp->tail_frag, pm); - pos = fp->tail_frag; - while ((NULL != pos) && - (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) - pos = pos->prev_frag; - GNUNET_CONTAINER_MDLL_insert_after(frag, - fp->head_frag, - fp->tail_frag, - pos, - pm); - } + { + /* re-insert sort in fragment list */ + struct PendingMessage *fp = pm->frag_parent; + struct PendingMessage *pos; + + GNUNET_CONTAINER_MDLL_remove (frag, fp->head_frag, fp->tail_frag, pm); + pos = fp->tail_frag; + while ((NULL != pos) && + (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) + pos = pos->prev_frag; + GNUNET_CONTAINER_MDLL_insert_after (frag, + fp->head_frag, + fp->tail_frag, + pos, + pm); + } } /** * Context for #select_best_pending_from_link(). */ -struct PendingMessageScoreContext { +struct PendingMessageScoreContext +{ /** * Set to the best message that was found, NULL for none. */ @@ -8518,107 +8578,109 @@ struct PendingMessageScoreContext { * from DV encapsulation (0 for without DV) */ static void -select_best_pending_from_link(struct PendingMessageScoreContext *sc, - struct Queue *queue, - struct VirtualLink *vl, - struct DistanceVectorHop *dvh, - size_t overhead) +select_best_pending_from_link (struct PendingMessageScoreContext *sc, + struct Queue *queue, + struct VirtualLink *vl, + struct DistanceVectorHop *dvh, + size_t overhead) { struct GNUNET_TIME_Absolute now; - now = GNUNET_TIME_absolute_get(); + now = GNUNET_TIME_absolute_get (); for (struct PendingMessage *pos = vl->pending_msg_head; NULL != pos; pos = pos->next_vl) - { - size_t real_overhead = overhead; - int frag; - int relb; - - if ((NULL != dvh) && (PMT_DV_BOX == pos->pmt)) - continue; /* DV messages must not be DV-routed to next hop! */ - if (pos->next_attempt.abs_value_us > now.abs_value_us) - break; /* too early for all messages, they are sorted by next_attempt */ - if (NULL != pos->qe) - continue; /* not eligible */ - sc->consideration_counter++; - /* determine if we have to fragment, if so add fragmentation - overhead! */ - frag = GNUNET_NO; - if (((0 != queue->mtu) && - (pos->bytes_msg + real_overhead > queue->mtu)) || - (pos->bytes_msg > UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)) || - (NULL != pos->head_frag /* fragments already exist, should + { + size_t real_overhead = overhead; + int frag; + int relb; + + if ((NULL != dvh) && (PMT_DV_BOX == pos->pmt)) + continue; /* DV messages must not be DV-routed to next hop! */ + if (pos->next_attempt.abs_value_us > now.abs_value_us) + break; /* too early for all messages, they are sorted by next_attempt */ + if (NULL != pos->qe) + continue; /* not eligible */ + sc->consideration_counter++; + /* determine if we have to fragment, if so add fragmentation + overhead! */ + frag = GNUNET_NO; + if (((0 != queue->mtu) && + (pos->bytes_msg + real_overhead > queue->mtu)) || + (pos->bytes_msg > UINT16_MAX - sizeof(struct + GNUNET_TRANSPORT_SendMessageTo)) + || + (NULL != pos->head_frag /* fragments already exist, should respect that even if MTU is 0 for this queue */)) - { - frag = GNUNET_YES; - if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) - { - /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation - header without the ACK UUID when using a *reliable* channel! */ - } - real_overhead = overhead + sizeof(struct TransportFragmentBoxMessage); - } - /* determine if we have to reliability-box, if so add reliability box - overhead */ - relb = GNUNET_NO; - if ((GNUNET_NO == frag) && - (0 == (pos->prefs & GNUNET_MQ_PREF_UNRELIABLE)) && - (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc)) - { - relb = GNUNET_YES; - real_overhead += sizeof(struct TransportReliabilityBoxMessage); - } - - /* Finally, compare to existing 'best' in sc to see if this 'pos' pending - message would beat it! */ - if (NULL != sc->best) - { - /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue; - OPTIMIZE-ME: This is a heuristic, which so far has NOT been - experimentally validated. There may be some huge potential for - improvement here. Also, we right now only compare how well the - given message fits _this_ queue, and do not consider how well other - queues might suit the message. Taking other queues into consideration - may further improve the result, but could also be expensive - in terms of CPU time. */ - long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead; - long long pm_score = frag * 40 + relb * 20 + real_overhead; - long long time_delta = - (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us) / - 1000LL; - - /* "time_delta" considers which message has been 'ready' for transmission - for longer, if a message has a preference for low latency, increase - the weight of the time_delta by 10x if it is favorable for that message */ - if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && - (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY))) - time_delta *= 10; /* increase weight (always, both are low latency) */ - else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && - (time_delta > 0)) - time_delta *= - 10; /* increase weight, favors 'pos', which is low latency */ - else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && - (time_delta < 0)) - time_delta *= - 10; /* increase weight, favors 'sc->best', which is low latency */ - if (0 != queue->mtu) - { - /* Grant bonus if we are bellow MTU, larger bonus the closer we will - be to the MTU */ - if (queue->mtu > sc->real_overhead + sc->best->bytes_msg) - sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg); - if (queue->mtu > real_overhead + pos->bytes_msg) - pm_score -= queue->mtu - (real_overhead + pos->bytes_msg); - } - if (sc_score + time_delta > pm_score) - continue; /* sc_score larger, keep sc->best */ - } - sc->best = pos; - sc->dvh = dvh; - sc->frag = frag; - sc->relb = relb; + { + frag = GNUNET_YES; + if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) + { + /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation + header without the ACK UUID when using a *reliable* channel! */ + } + real_overhead = overhead + sizeof(struct TransportFragmentBoxMessage); + } + /* determine if we have to reliability-box, if so add reliability box + overhead */ + relb = GNUNET_NO; + if ((GNUNET_NO == frag) && + (0 == (pos->prefs & GNUNET_MQ_PREF_UNRELIABLE)) && + (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc)) + { + relb = GNUNET_YES; + real_overhead += sizeof(struct TransportReliabilityBoxMessage); + } + + /* Finally, compare to existing 'best' in sc to see if this 'pos' pending + message would beat it! */ + if (NULL != sc->best) + { + /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue; + OPTIMIZE-ME: This is a heuristic, which so far has NOT been + experimentally validated. There may be some huge potential for + improvement here. Also, we right now only compare how well the + given message fits _this_ queue, and do not consider how well other + queues might suit the message. Taking other queues into consideration + may further improve the result, but could also be expensive + in terms of CPU time. */ + long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead; + long long pm_score = frag * 40 + relb * 20 + real_overhead; + long long time_delta = + (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us) + / 1000LL; + + /* "time_delta" considers which message has been 'ready' for transmission + for longer, if a message has a preference for low latency, increase + the weight of the time_delta by 10x if it is favorable for that message */ + if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && + (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY))) + time_delta *= 10; /* increase weight (always, both are low latency) */ + else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && + (time_delta > 0)) + time_delta *= + 10; /* increase weight, favors 'pos', which is low latency */ + else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && + (time_delta < 0)) + time_delta *= + 10; /* increase weight, favors 'sc->best', which is low latency */ + if (0 != queue->mtu) + { + /* Grant bonus if we are bellow MTU, larger bonus the closer we will + be to the MTU */ + if (queue->mtu > sc->real_overhead + sc->best->bytes_msg) + sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg); + if (queue->mtu > real_overhead + pos->bytes_msg) + pm_score -= queue->mtu - (real_overhead + pos->bytes_msg); + } + if (sc_score + time_delta > pm_score) + continue; /* sc_score larger, keep sc->best */ } + sc->best = pos; + sc->dvh = dvh; + sc->frag = frag; + sc->relb = relb; + } } @@ -8633,26 +8695,26 @@ select_best_pending_from_link(struct PendingMessageScoreContext *sc, * @param options options of the original message */ static void -extract_box_cb(void *cls, - struct Neighbour *next_hop, - const struct GNUNET_MessageHeader *hdr, - enum RouteMessageOptions options) +extract_box_cb (void *cls, + struct Neighbour *next_hop, + const struct GNUNET_MessageHeader *hdr, + enum RouteMessageOptions options) { struct PendingMessageScoreContext *sc = cls; struct PendingMessage *pm = sc->best; struct PendingMessage *bpm; - uint16_t bsize = ntohs(hdr->size); + uint16_t bsize = ntohs (hdr->size); - GNUNET_assert(NULL == pm->bpm); - bpm = GNUNET_malloc(sizeof(struct PendingMessage) + bsize); + GNUNET_assert (NULL == pm->bpm); + bpm = GNUNET_malloc (sizeof(struct PendingMessage) + bsize); bpm->logging_uuid = logging_uuid_gen++; bpm->pmt = PMT_DV_BOX; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Creating DV Box %llu for original message %llu (next hop is %s)\n", - bpm->logging_uuid, - pm->logging_uuid, - GNUNET_i2s(&next_hop->pid)); - memcpy(&bpm[1], hdr, bsize); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Creating DV Box %llu for original message %llu (next hop is %s)\n", + bpm->logging_uuid, + pm->logging_uuid, + GNUNET_i2s (&next_hop->pid)); + memcpy (&bpm[1], hdr, bsize); pm->bpm = bpm; } @@ -8673,7 +8735,7 @@ extract_box_cb(void *cls, * @param cls the `struct Queue` to process transmissions for */ static void -transmit_on_queue(void *cls) +transmit_on_queue (void *cls) { struct Queue *queue = cls; struct Neighbour *n = queue->neighbour; @@ -8682,104 +8744,104 @@ transmit_on_queue(void *cls) queue->transmit_task = NULL; if (NULL == n->vl) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Virtual link `%s' is down, cannot have PM for queue `%s'\n", - GNUNET_i2s(&n->pid), - queue->address); - queue->idle = GNUNET_YES; - return; - } - memset(&sc, 0, sizeof(sc)); - select_best_pending_from_link(&sc, queue, n->vl, NULL, 0); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Virtual link `%s' is down, cannot have PM for queue `%s'\n", + GNUNET_i2s (&n->pid), + queue->address); + queue->idle = GNUNET_YES; + return; + } + memset (&sc, 0, sizeof(sc)); + select_best_pending_from_link (&sc, queue, n->vl, NULL, 0); if (NULL == sc.best) - { - /* Also look at DVH that have the n as first hop! */ - for (struct DistanceVectorHop *dvh = n->dv_head; NULL != dvh; - dvh = dvh->next_neighbour) - { - select_best_pending_from_link(&sc, - queue, - dvh->dv->vl, - dvh, - sizeof(struct GNUNET_PeerIdentity) * - (1 + dvh->distance) + - sizeof(struct TransportDVBoxMessage) + - sizeof(struct TransportDVBoxPayloadP)); - } + { + /* Also look at DVH that have the n as first hop! */ + for (struct DistanceVectorHop *dvh = n->dv_head; NULL != dvh; + dvh = dvh->next_neighbour) + { + select_best_pending_from_link (&sc, + queue, + dvh->dv->vl, + dvh, + sizeof(struct GNUNET_PeerIdentity) + * (1 + dvh->distance) + + sizeof(struct TransportDVBoxMessage) + + sizeof(struct TransportDVBoxPayloadP)); } + } if (NULL == sc.best) - { - /* no message pending, nothing to do here! */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "No pending messages, queue `%s' to %s now idle\n", - queue->address, - GNUNET_i2s(&n->pid)); - queue->idle = GNUNET_YES; - return; - } + { + /* no message pending, nothing to do here! */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "No pending messages, queue `%s' to %s now idle\n", + queue->address, + GNUNET_i2s (&n->pid)); + queue->idle = GNUNET_YES; + return; + } /* Given selection in `sc`, do transmission */ pm = sc.best; if (NULL != sc.dvh) - { - GNUNET_assert(PMT_DV_BOX != pm->pmt); - if (NULL != sc.best->bpm) - { - /* We did this boxing before, but possibly for a different path! - Discard old DV box! OPTIMIZE-ME: we might want to check if - it is the same and then not re-build the message... */ - free_pending_message(sc.best->bpm); - sc.best->bpm = NULL; - } - encapsulate_for_dv(sc.dvh->dv, - 1, - &sc.dvh, - (const struct GNUNET_MessageHeader *)&sc.best[1], - &extract_box_cb, - &sc, - RMO_NONE); - GNUNET_assert(NULL != sc.best->bpm); - pm = sc.best->bpm; - } + { + GNUNET_assert (PMT_DV_BOX != pm->pmt); + if (NULL != sc.best->bpm) + { + /* We did this boxing before, but possibly for a different path! + Discard old DV box! OPTIMIZE-ME: we might want to check if + it is the same and then not re-build the message... */ + free_pending_message (sc.best->bpm); + sc.best->bpm = NULL; + } + encapsulate_for_dv (sc.dvh->dv, + 1, + &sc.dvh, + (const struct GNUNET_MessageHeader *) &sc.best[1], + &extract_box_cb, + &sc, + RMO_NONE); + GNUNET_assert (NULL != sc.best->bpm); + pm = sc.best->bpm; + } if (GNUNET_YES == sc.frag) - { - pm = fragment_message(queue, sc.dvh, pm); - if (NULL == pm) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Fragmentation failed queue %s to %s for <%llu>, trying again\n", - queue->address, - GNUNET_i2s(&n->pid), - sc.best->logging_uuid); - schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - return; - } + { + pm = fragment_message (queue, sc.dvh, pm); + if (NULL == pm) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Fragmentation failed queue %s to %s for <%llu>, trying again\n", + queue->address, + GNUNET_i2s (&n->pid), + sc.best->logging_uuid); + schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + return; } + } else if (GNUNET_YES == sc.relb) - { - pm = reliability_box_message(queue, sc.dvh, pm); - if (NULL == pm) - { - /* Reliability boxing failed, try next message... */ - GNUNET_log( - GNUNET_ERROR_TYPE_DEBUG, - "Reliability boxing failed queue %s to %s for <%llu>, trying again\n", - queue->address, - GNUNET_i2s(&n->pid), - sc.best->logging_uuid); - schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - return; - } + { + pm = reliability_box_message (queue, sc.dvh, pm); + if (NULL == pm) + { + /* Reliability boxing failed, try next message... */ + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Reliability boxing failed queue %s to %s for <%llu>, trying again\n", + queue->address, + GNUNET_i2s (&n->pid), + sc.best->logging_uuid); + schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + return; } + } /* Pass 'pm' for transission to the communicator */ - GNUNET_log( + GNUNET_log ( GNUNET_ERROR_TYPE_DEBUG, "Passing message <%llu> to queue %s for peer %s (considered %u others)\n", pm->logging_uuid, queue->address, - GNUNET_i2s(&n->pid), + GNUNET_i2s (&n->pid), sc.consideration_counter); /* Flow control: increment amount of traffic sent; if we are routing @@ -8790,50 +8852,50 @@ transmit_on_queue(void *cls) pm->vl->outbound_fc_window_size_used += pm->bytes_msg; if (pm->vl != queue->neighbour->vl) - { - /* If the virtual link of the queue differs, this better be distance - vector routing! */ - GNUNET_assert(NULL != sc.dvh); - /* If we do distance vector routing, we better not do this for a - message that was itself DV-routed */ - GNUNET_assert(PMT_DV_BOX != sc.best->pmt); - /* We use the size of the unboxed message here, to avoid counting - the DV-Box header which is eaten up on the way by intermediaries */ - queue->neighbour->vl->outbound_fc_window_size_used += sc.best->bytes_msg; - } + { + /* If the virtual link of the queue differs, this better be distance + vector routing! */ + GNUNET_assert (NULL != sc.dvh); + /* If we do distance vector routing, we better not do this for a + message that was itself DV-routed */ + GNUNET_assert (PMT_DV_BOX != sc.best->pmt); + /* We use the size of the unboxed message here, to avoid counting + the DV-Box header which is eaten up on the way by intermediaries */ + queue->neighbour->vl->outbound_fc_window_size_used += sc.best->bytes_msg; + } else - { - GNUNET_assert(NULL == sc.dvh); - } + { + GNUNET_assert (NULL == sc.dvh); + } - queue_send_msg(queue, pm, &pm[1], pm->bytes_msg); + queue_send_msg (queue, pm, &pm[1], pm->bytes_msg); /* Check if this transmission somehow conclusively finished handing 'pm' even without any explicit ACKs */ if ((PMT_CORE == pm->pmt) || (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)) - { - completed_pending_message(pm); - } + { + completed_pending_message (pm); + } else - { - /* Message not finished, waiting for acknowledgement. - Update time by which we might retransmit 's' based on queue - characteristics (i.e. RTT); it takes one RTT for the message to - arrive and the ACK to come back in the best case; but the other - side is allowed to delay ACKs by 2 RTTs, so we use 4 RTT before - retransmitting. - - OPTIMIZE: Note that in the future this heuristic should likely - be improved further (measure RTT stability, consider message - urgency and size when delaying ACKs, etc.) */ - update_pm_next_attempt(pm, - GNUNET_TIME_relative_to_absolute( - GNUNET_TIME_relative_multiply(queue->pd.aged_rtt, + { + /* Message not finished, waiting for acknowledgement. + Update time by which we might retransmit 's' based on queue + characteristics (i.e. RTT); it takes one RTT for the message to + arrive and the ACK to come back in the best case; but the other + side is allowed to delay ACKs by 2 RTTs, so we use 4 RTT before + retransmitting. + + OPTIMIZE: Note that in the future this heuristic should likely + be improved further (measure RTT stability, consider message + urgency and size when delaying ACKs, etc.) */ + update_pm_next_attempt (pm, + GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_relative_multiply (queue->pd.aged_rtt, 4))); - } + } /* finally, re-schedule queue transmission task itself */ - schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); } @@ -8844,35 +8906,35 @@ transmit_on_queue(void *cls) * @param dqm the send message that was sent */ static void -handle_del_queue_message(void *cls, - const struct GNUNET_TRANSPORT_DelQueueMessage *dqm) +handle_del_queue_message (void *cls, + const struct GNUNET_TRANSPORT_DelQueueMessage *dqm) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; queue = queue->next_client) - { - struct Neighbour *neighbour = queue->neighbour; - - if ((dqm->qid != queue->qid) || - (0 != GNUNET_memcmp(&dqm->receiver, &neighbour->pid))) - continue; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Dropped queue %s to peer %s\n", - queue->address, - GNUNET_i2s(&neighbour->pid)); - free_queue(queue); - GNUNET_SERVICE_client_continue(tc->client); - return; - } - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); + { + struct Neighbour *neighbour = queue->neighbour; + + if ((dqm->qid != queue->qid) || + (0 != GNUNET_memcmp (&dqm->receiver, &neighbour->pid))) + continue; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Dropped queue %s to peer %s\n", + queue->address, + GNUNET_i2s (&neighbour->pid)); + free_queue (queue); + GNUNET_SERVICE_client_continue (tc->client); + return; + } + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); } @@ -8883,97 +8945,97 @@ handle_del_queue_message(void *cls, * @param sma the send message that was sent */ static void -handle_send_message_ack(void *cls, - const struct GNUNET_TRANSPORT_SendMessageToAck *sma) +handle_send_message_ack (void *cls, + const struct GNUNET_TRANSPORT_SendMessageToAck *sma) { struct TransportClient *tc = cls; struct QueueEntry *qe; struct PendingMessage *pm; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } /* find our queue entry matching the ACK */ qe = NULL; for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; queue = queue->next_client) + { + if (0 != GNUNET_memcmp (&queue->neighbour->pid, &sma->receiver)) + continue; + for (struct QueueEntry *qep = queue->queue_head; NULL != qep; + qep = qep->next) { - if (0 != GNUNET_memcmp(&queue->neighbour->pid, &sma->receiver)) + if (qep->mid != sma->mid) continue; - for (struct QueueEntry *qep = queue->queue_head; NULL != qep; - qep = qep->next) - { - if (qep->mid != sma->mid) - continue; - qe = qep; - break; - } + qe = qep; break; } + break; + } if (NULL == qe) - { - /* this should never happen */ - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - GNUNET_CONTAINER_DLL_remove(qe->queue->queue_head, - qe->queue->queue_tail, - qe); + { + /* this should never happen */ + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + GNUNET_CONTAINER_DLL_remove (qe->queue->queue_head, + qe->queue->queue_tail, + qe); qe->queue->queue_length--; tc->details.communicator.total_queue_length--; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received ACK on queue %s to peer %s (new length: %u/%u)\n", - qe->queue->address, - GNUNET_i2s(&qe->queue->neighbour->pid), - qe->queue->queue_length, - tc->details.communicator.total_queue_length); - GNUNET_SERVICE_client_continue(tc->client); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received ACK on queue %s to peer %s (new length: %u/%u)\n", + qe->queue->address, + GNUNET_i2s (&qe->queue->neighbour->pid), + qe->queue->queue_length, + tc->details.communicator.total_queue_length); + GNUNET_SERVICE_client_continue (tc->client); /* if applicable, resume transmissions that waited on ACK */ if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 == tc->details.communicator.total_queue_length) - { - /* Communicator dropped below threshold, resume all queues - incident with this client! */ - GNUNET_STATISTICS_update( - GST_stats, - "# Transmission throttled due to communicator queue limit", - -1, - GNUNET_NO); - for (struct Queue *queue = tc->details.communicator.queue_head; - NULL != queue; - queue = queue->next_client) - schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - } + { + /* Communicator dropped below threshold, resume all queues + incident with this client! */ + GNUNET_STATISTICS_update ( + GST_stats, + "# Transmission throttled due to communicator queue limit", + -1, + GNUNET_NO); + for (struct Queue *queue = tc->details.communicator.queue_head; + NULL != queue; + queue = queue->next_client) + schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + } else if (QUEUE_LENGTH_LIMIT - 1 == qe->queue->queue_length) - { - /* queue dropped below threshold; only resume this one queue */ - GNUNET_STATISTICS_update(GST_stats, - "# Transmission throttled due to queue queue limit", - -1, - GNUNET_NO); - schedule_transmit_on_queue(qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - } + { + /* queue dropped below threshold; only resume this one queue */ + GNUNET_STATISTICS_update (GST_stats, + "# Transmission throttled due to queue queue limit", + -1, + GNUNET_NO); + schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + } if (NULL != (pm = qe->pm)) - { - struct VirtualLink *vl; - - GNUNET_assert(qe == pm->qe); - pm->qe = NULL; - /* If waiting for this communicator may have blocked transmission - of pm on other queues for this neighbour, force schedule - transmit on queue for queues of the neighbour */ - vl = pm->vl; - if (vl->pending_msg_head == pm) - check_vl_transmission(vl); - } - GNUNET_free(qe); + { + struct VirtualLink *vl; + + GNUNET_assert (qe == pm->qe); + pm->qe = NULL; + /* If waiting for this communicator may have blocked transmission + of pm on other queues for this neighbour, force schedule + transmit on queue for queues of the neighbour */ + vl = pm->vl; + if (vl->pending_msg_head == pm) + check_vl_transmission (vl); + } + GNUNET_free (qe); } @@ -8987,24 +9049,24 @@ handle_send_message_ack(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -notify_client_queues(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +notify_client_queues (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct TransportClient *tc = cls; struct Neighbour *neighbour = value; - GNUNET_assert(CT_MONITOR == tc->type); + GNUNET_assert (CT_MONITOR == tc->type); for (struct Queue *q = neighbour->queue_head; NULL != q; q = q->next_neighbour) - { - struct MonitorEvent me = { .rtt = q->pd.aged_rtt, - .cs = q->cs, - .num_msg_pending = q->num_msg_pending, - .num_bytes_pending = q->num_bytes_pending }; + { + struct MonitorEvent me = { .rtt = q->pd.aged_rtt, + .cs = q->cs, + .num_msg_pending = q->num_msg_pending, + .num_bytes_pending = q->num_bytes_pending }; - notify_monitor(tc, pid, q->address, q->nt, &me); - } + notify_monitor (tc, pid, q->address, q->nt, &me); + } return GNUNET_OK; } @@ -9016,23 +9078,23 @@ notify_client_queues(void *cls, * @param start the start message that was sent */ static void -handle_monitor_start(void *cls, - const struct GNUNET_TRANSPORT_MonitorStart *start) +handle_monitor_start (void *cls, + const struct GNUNET_TRANSPORT_MonitorStart *start) { struct TransportClient *tc = cls; if (CT_NONE != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } tc->type = CT_MONITOR; tc->details.monitor.peer = start->peer; - tc->details.monitor.one_shot = ntohl(start->one_shot); - GNUNET_CONTAINER_multipeermap_iterate(neighbours, ¬ify_client_queues, tc); - GNUNET_SERVICE_client_mark_monitor(tc->client); - GNUNET_SERVICE_client_continue(tc->client); + tc->details.monitor.one_shot = ntohl (start->one_shot); + GNUNET_CONTAINER_multipeermap_iterate (neighbours, ¬ify_client_queues, tc); + GNUNET_SERVICE_client_mark_monitor (tc->client); + GNUNET_SERVICE_client_continue (tc->client); } @@ -9044,16 +9106,16 @@ handle_monitor_start(void *cls, * @return NULL if no such transport client is available */ static struct TransportClient * -lookup_communicator(const char *prefix) +lookup_communicator (const char *prefix) { for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - if (CT_COMMUNICATOR != tc->type) - continue; - if (0 == strcmp(prefix, tc->details.communicator.address_prefix)) - return tc; - } - GNUNET_log( + { + if (CT_COMMUNICATOR != tc->type) + continue; + if (0 == strcmp (prefix, tc->details.communicator.address_prefix)) + return tc; + } + GNUNET_log ( GNUNET_ERROR_TYPE_WARNING, "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n", prefix); @@ -9069,7 +9131,7 @@ lookup_communicator(const char *prefix) * @param address the address to try */ static void -suggest_to_connect(const struct GNUNET_PeerIdentity *pid, const char *address) +suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address) { static uint32_t idgen; struct TransportClient *tc; @@ -9078,40 +9140,40 @@ suggest_to_connect(const struct GNUNET_PeerIdentity *pid, const char *address) struct GNUNET_MQ_Envelope *env; size_t alen; - prefix = GNUNET_HELLO_address_to_prefix(address); + prefix = GNUNET_HELLO_address_to_prefix (address); if (NULL == prefix) - { - GNUNET_break(0); /* We got an invalid address!? */ - return; - } - tc = lookup_communicator(prefix); + { + GNUNET_break (0); /* We got an invalid address!? */ + return; + } + tc = lookup_communicator (prefix); if (NULL == tc) - { - GNUNET_STATISTICS_update(GST_stats, - "# Suggestions ignored due to missing communicator", - 1, - GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Cannot connect to %s at `%s', no matching communicator present\n", - GNUNET_i2s(pid), - address); - GNUNET_free(prefix); - return; - } + { + GNUNET_STATISTICS_update (GST_stats, + "# Suggestions ignored due to missing communicator", + 1, + GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Cannot connect to %s at `%s', no matching communicator present\n", + GNUNET_i2s (pid), + address); + GNUNET_free (prefix); + return; + } /* forward suggestion for queue creation to communicator */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Request #%u for `%s' communicator to create queue to `%s'\n", - (unsigned int)idgen, - prefix, - address); - GNUNET_free(prefix); - alen = strlen(address) + 1; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Request #%u for `%s' communicator to create queue to `%s'\n", + (unsigned int) idgen, + prefix, + address); + GNUNET_free (prefix); + alen = strlen (address) + 1; env = - GNUNET_MQ_msg_extra(cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); - cqm->request_id = htonl(idgen++); + GNUNET_MQ_msg_extra (cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); + cqm->request_id = htonl (idgen++); cqm->receiver = *pid; - memcpy(&cqm[1], address, alen); - GNUNET_MQ_send(tc->mq, env); + memcpy (&cqm[1], address, alen); + GNUNET_MQ_send (tc->mq, env); } @@ -9123,22 +9185,22 @@ suggest_to_connect(const struct GNUNET_PeerIdentity *pid, const char *address) * @param vs state to derive validation challenge from */ static void -validation_transmit_on_queue(struct Queue *q, struct ValidationState *vs) +validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs) { struct TransportValidationChallengeMessage tvc; - vs->last_challenge_use = GNUNET_TIME_absolute_get_monotonic(GST_cfg); + vs->last_challenge_use = GNUNET_TIME_absolute_get_monotonic (GST_cfg); tvc.header.type = - htons(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); - tvc.header.size = htons(sizeof(tvc)); - tvc.reserved = htonl(0); + htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); + tvc.header.size = htons (sizeof(tvc)); + tvc.reserved = htonl (0); tvc.challenge = vs->challenge; - tvc.sender_time = GNUNET_TIME_absolute_hton(vs->last_challenge_use); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Sending address validation challenge %s to %s\n", - GNUNET_sh2s(&tvc.challenge.value), - GNUNET_i2s(&q->neighbour->pid)); - queue_send_msg(q, NULL, &tvc, sizeof(tvc)); + tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Sending address validation challenge %s to %s\n", + GNUNET_sh2s (&tvc.challenge.value), + GNUNET_i2s (&q->neighbour->pid)); + queue_send_msg (q, NULL, &tvc, sizeof(tvc)); } @@ -9148,55 +9210,56 @@ validation_transmit_on_queue(struct Queue *q, struct ValidationState *vs) * @param cls NULL */ static void -validation_start_cb(void *cls) +validation_start_cb (void *cls) { struct ValidationState *vs; struct Queue *q; - (void)cls; + (void) cls; validation_task = NULL; - vs = GNUNET_CONTAINER_heap_peek(validation_heap); + vs = GNUNET_CONTAINER_heap_peek (validation_heap); /* drop validations past their expiration */ while ( (NULL != vs) && - (0 == GNUNET_TIME_absolute_get_remaining(vs->valid_until).rel_value_us)) - { - free_validation_state(vs); - vs = GNUNET_CONTAINER_heap_peek(validation_heap); - } + (0 == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us)) + { + free_validation_state (vs); + vs = GNUNET_CONTAINER_heap_peek (validation_heap); + } if (NULL == vs) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Address validation task not scheduled anymore, nothing to do\n"); - return; /* woopsie, no more addresses known, should only + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Address validation task not scheduled anymore, nothing to do\n"); + return; /* woopsie, no more addresses known, should only happen if we're really a lonely peer */ - } - q = find_queue(&vs->pid, vs->address); + } + q = find_queue (&vs->pid, vs->address); if (NULL == q) - { - vs->awaiting_queue = GNUNET_YES; - suggest_to_connect(&vs->pid, vs->address); - } + { + vs->awaiting_queue = GNUNET_YES; + suggest_to_connect (&vs->pid, vs->address); + } else - validation_transmit_on_queue(q, vs); + validation_transmit_on_queue (q, vs); /* Finally, reschedule next attempt */ vs->challenge_backoff = - GNUNET_TIME_randomized_backoff(vs->challenge_backoff, - MAX_VALIDATION_CHALLENGE_FREQ); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Address validation task will run again in %s\n", - GNUNET_STRINGS_relative_time_to_string(vs->challenge_backoff, - GNUNET_YES)); - update_next_challenge_time(vs, - GNUNET_TIME_relative_to_absolute( - vs->challenge_backoff)); + GNUNET_TIME_randomized_backoff (vs->challenge_backoff, + MAX_VALIDATION_CHALLENGE_FREQ); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Address validation task will run again in %s\n", + GNUNET_STRINGS_relative_time_to_string (vs->challenge_backoff, + GNUNET_YES)); + update_next_challenge_time (vs, + GNUNET_TIME_relative_to_absolute ( + vs->challenge_backoff)); } /** * Closure for #check_connection_quality. */ -struct QueueQualityContext { +struct QueueQualityContext +{ /** * Set to the @e k'th queue encountered. */ @@ -9232,26 +9295,26 @@ struct QueueQualityContext { * @return #GNUNET_OK (continue to iterate) */ static int -check_connection_quality(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +check_connection_quality (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct QueueQualityContext *ctx = cls; struct Neighbour *n = value; int do_inc; - (void)pid; + (void) pid; do_inc = GNUNET_NO; for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) - { - ctx->num_queues++; - if (0 == ctx->k--) - ctx->q = q; - /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput - statistics and consider those as well here? */ - if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us) - do_inc = GNUNET_YES; - } + { + ctx->num_queues++; + if (0 == ctx->k--) + ctx->q = q; + /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput + statistics and consider those as well here? */ + if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us) + do_inc = GNUNET_YES; + } if (GNUNET_YES == do_inc) ctx->quality_count++; return GNUNET_OK; @@ -9270,103 +9333,103 @@ check_connection_quality(void *cls, * @param cls NULL */ static void -start_dv_learn(void *cls) +start_dv_learn (void *cls) { struct LearnLaunchEntry *lle; struct QueueQualityContext qqc; struct TransportDVLearnMessage dvl; - (void)cls; + (void) cls; dvlearn_task = NULL; - if (0 == GNUNET_CONTAINER_multipeermap_size(neighbours)) + if (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)) return; /* lost all connectivity, cannot do learning */ qqc.quality_count = 0; qqc.num_queues = 0; - GNUNET_CONTAINER_multipeermap_iterate(neighbours, - &check_connection_quality, - &qqc); + GNUNET_CONTAINER_multipeermap_iterate (neighbours, + &check_connection_quality, + &qqc); if (qqc.quality_count > DV_LEARN_QUALITY_THRESHOLD) - { - struct GNUNET_TIME_Relative delay; - unsigned int factor; - - /* scale our retries by how far we are above the threshold */ - factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; - delay = GNUNET_TIME_relative_multiply(DV_LEARN_BASE_FREQUENCY, factor); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "At connection quality %u, will launch DV learn in %s\n", - qqc.quality_count, - GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); - dvlearn_task = GNUNET_SCHEDULER_add_delayed(delay, &start_dv_learn, NULL); - return; - } + { + struct GNUNET_TIME_Relative delay; + unsigned int factor; + + /* scale our retries by how far we are above the threshold */ + factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; + delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, factor); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "At connection quality %u, will launch DV learn in %s\n", + qqc.quality_count, + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); + dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay, &start_dv_learn, NULL); + return; + } /* remove old entries in #dvlearn_map if it has grown too big */ while (MAX_DV_LEARN_PENDING >= - GNUNET_CONTAINER_multishortmap_size(dvlearn_map)) - { - lle = lle_tail; - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multishortmap_remove(dvlearn_map, + GNUNET_CONTAINER_multishortmap_size (dvlearn_map)) + { + lle = lle_tail; + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multishortmap_remove (dvlearn_map, &lle->challenge.value, lle)); - GNUNET_CONTAINER_DLL_remove(lle_head, lle_tail, lle); - GNUNET_free(lle); - } + GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); + GNUNET_free (lle); + } /* setup data structure for learning */ - lle = GNUNET_new(struct LearnLaunchEntry); - GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, - &lle->challenge, - sizeof(lle->challenge)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Starting launch DV learn with challenge %s\n", - GNUNET_sh2s(&lle->challenge.value)); - GNUNET_CONTAINER_DLL_insert(lle_head, lle_tail, lle); - GNUNET_break(GNUNET_YES == - GNUNET_CONTAINER_multishortmap_put( - dvlearn_map, - &lle->challenge.value, - lle, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - dvl.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); - dvl.header.size = htons(sizeof(dvl)); - dvl.num_hops = htons(0); - dvl.bidirectional = htons(0); - dvl.non_network_delay = GNUNET_TIME_relative_hton(GNUNET_TIME_UNIT_ZERO); + lle = GNUNET_new (struct LearnLaunchEntry); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + &lle->challenge, + sizeof(lle->challenge)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting launch DV learn with challenge %s\n", + GNUNET_sh2s (&lle->challenge.value)); + GNUNET_CONTAINER_DLL_insert (lle_head, lle_tail, lle); + GNUNET_break (GNUNET_YES == + GNUNET_CONTAINER_multishortmap_put ( + dvlearn_map, + &lle->challenge.value, + lle, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); + dvl.header.size = htons (sizeof(dvl)); + dvl.num_hops = htons (0); + dvl.bidirectional = htons (0); + dvl.non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); dvl.monotonic_time = - GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(GST_cfg)); + GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg)); { - struct DvInitPS dvip = { .purpose.purpose = htonl( + struct DvInitPS dvip = { .purpose.purpose = htonl ( GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), - .purpose.size = htonl(sizeof(dvip)), + .purpose.size = htonl (sizeof(dvip)), .monotonic_time = dvl.monotonic_time, .challenge = lle->challenge }; - GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, - &dvip.purpose, - &dvl.init_sig)); + GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, + &dvip.purpose, + &dvl.init_sig)); } dvl.initiator = GST_my_identity; dvl.challenge = lle->challenge; qqc.quality_count = 0; - qqc.k = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues); + qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues); qqc.num_queues = 0; qqc.q = NULL; - GNUNET_CONTAINER_multipeermap_iterate(neighbours, - &check_connection_quality, - &qqc); - GNUNET_assert(NULL != qqc.q); + GNUNET_CONTAINER_multipeermap_iterate (neighbours, + &check_connection_quality, + &qqc); + GNUNET_assert (NULL != qqc.q); /* Do this as close to transmission time as possible! */ - lle->launch_time = GNUNET_TIME_absolute_get(); + lle->launch_time = GNUNET_TIME_absolute_get (); - queue_send_msg(qqc.q, NULL, &dvl, sizeof(dvl)); + queue_send_msg (qqc.q, NULL, &dvl, sizeof(dvl)); /* reschedule this job, randomizing the time it runs (but no actual backoff!) */ - dvlearn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_randomize( - DV_LEARN_BASE_FREQUENCY), - &start_dv_learn, - NULL); + dvlearn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_randomize ( + DV_LEARN_BASE_FREQUENCY), + &start_dv_learn, + NULL); } @@ -9380,21 +9443,21 @@ start_dv_learn(void *cls) * @return #GNUNET_NO if a match was found and we can stop looking */ static int -check_validation_request_pending(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +check_validation_request_pending (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct Queue *q = cls; struct ValidationState *vs = value; - (void)pid; + (void) pid; if ((GNUNET_YES == vs->awaiting_queue) && - (0 == strcmp(vs->address, q->address))) - { - vs->awaiting_queue = GNUNET_NO; - validation_transmit_on_queue(q, vs); - return GNUNET_NO; - } + (0 == strcmp (vs->address, q->address))) + { + vs->awaiting_queue = GNUNET_NO; + validation_transmit_on_queue (q, vs); + return GNUNET_NO; + } return GNUNET_OK; } @@ -9408,31 +9471,31 @@ check_validation_request_pending(void *cls, * @param emsg error message */ static void -neighbour_dv_monotime_cb(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +neighbour_dv_monotime_cb (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { struct Neighbour *n = cls; struct GNUNET_TIME_AbsoluteNBO *mtbe; - (void)emsg; + (void) emsg; if (NULL == record) - { - /* we're done with #neighbour_dv_monotime_cb() invocations, - continue normal processing */ - n->get = NULL; - n->dv_monotime_available = GNUNET_YES; - return; - } + { + /* we're done with #neighbour_dv_monotime_cb() invocations, + continue normal processing */ + n->get = NULL; + n->dv_monotime_available = GNUNET_YES; + return; + } if (sizeof(*mtbe) != record->value_size) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } mtbe = record->value; n->last_dv_learn_monotime = - GNUNET_TIME_absolute_max(n->last_dv_learn_monotime, - GNUNET_TIME_absolute_ntoh(*mtbe)); + GNUNET_TIME_absolute_max (n->last_dv_learn_monotime, + GNUNET_TIME_absolute_ntoh (*mtbe)); } @@ -9443,8 +9506,8 @@ neighbour_dv_monotime_cb(void *cls, * @param aqm the send message that was sent */ static void -handle_add_queue_message(void *cls, - const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) +handle_add_queue_message (void *cls, + const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) { struct TransportClient *tc = cls; struct Queue *queue; @@ -9452,77 +9515,77 @@ handle_add_queue_message(void *cls, const char *addr; uint16_t addr_len; - if (ntohl(aqm->mtu) <= sizeof(struct TransportFragmentBoxMessage)) - { - /* MTU so small as to be useless for transmissions, - required for #fragment_message()! */ - GNUNET_break_op(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - neighbour = lookup_neighbour(&aqm->receiver); + if (ntohl (aqm->mtu) <= sizeof(struct TransportFragmentBoxMessage)) + { + /* MTU so small as to be useless for transmissions, + required for #fragment_message()! */ + GNUNET_break_op (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + neighbour = lookup_neighbour (&aqm->receiver); if (NULL == neighbour) - { - neighbour = GNUNET_new(struct Neighbour); - neighbour->pid = aqm->receiver; - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put( - neighbours, - &neighbour->pid, - neighbour, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - neighbour->get = - GNUNET_PEERSTORE_iterate(peerstore, - "transport", - &neighbour->pid, - GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, - &neighbour_dv_monotime_cb, - neighbour); - } - addr_len = ntohs(aqm->header.size) - sizeof(*aqm); - addr = (const char *)&aqm[1]; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "New queue %s to %s available with QID %llu\n", - addr, - GNUNET_i2s(&aqm->receiver), - (unsigned long long)aqm->qid); - queue = GNUNET_malloc(sizeof(struct Queue) + addr_len); + { + neighbour = GNUNET_new (struct Neighbour); + neighbour->pid = aqm->receiver; + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put ( + neighbours, + &neighbour->pid, + neighbour, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + neighbour->get = + GNUNET_PEERSTORE_iterate (peerstore, + "transport", + &neighbour->pid, + GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, + &neighbour_dv_monotime_cb, + neighbour); + } + addr_len = ntohs (aqm->header.size) - sizeof(*aqm); + addr = (const char *) &aqm[1]; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "New queue %s to %s available with QID %llu\n", + addr, + GNUNET_i2s (&aqm->receiver), + (unsigned long long) aqm->qid); + queue = GNUNET_malloc (sizeof(struct Queue) + addr_len); queue->tc = tc; - queue->address = (const char *)&queue[1]; + queue->address = (const char *) &queue[1]; queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL; queue->qid = aqm->qid; - queue->mtu = ntohl(aqm->mtu); - queue->nt = (enum GNUNET_NetworkType)ntohl(aqm->nt); - queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl(aqm->cs); + queue->mtu = ntohl (aqm->mtu); + queue->nt = (enum GNUNET_NetworkType) ntohl (aqm->nt); + queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs); queue->neighbour = neighbour; queue->idle = GNUNET_YES; - memcpy(&queue[1], addr, addr_len); + memcpy (&queue[1], addr, addr_len); /* notify monitors about new queue */ { struct MonitorEvent me = { .rtt = queue->pd.aged_rtt, .cs = queue->cs }; - notify_monitors(&neighbour->pid, queue->address, queue->nt, &me); + notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); } - GNUNET_CONTAINER_MDLL_insert(neighbour, - neighbour->queue_head, - neighbour->queue_tail, - queue); - GNUNET_CONTAINER_MDLL_insert(client, - tc->details.communicator.queue_head, - tc->details.communicator.queue_tail, - queue); + GNUNET_CONTAINER_MDLL_insert (neighbour, + neighbour->queue_head, + neighbour->queue_tail, + queue); + GNUNET_CONTAINER_MDLL_insert (client, + tc->details.communicator.queue_head, + tc->details.communicator.queue_tail, + queue); /* check if valdiations are waiting for the queue */ (void) - GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, - &aqm->receiver, - &check_validation_request_pending, - queue); + GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, + &aqm->receiver, + &check_validation_request_pending, + queue); /* look for traffic for this queue */ - schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); /* might be our first queue, try launching DV learning */ if (NULL == dvlearn_task) - dvlearn_task = GNUNET_SCHEDULER_add_now(&start_dv_learn, NULL); - GNUNET_SERVICE_client_continue(tc->client); + dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, NULL); + GNUNET_SERVICE_client_continue (tc->client); } @@ -9534,25 +9597,25 @@ handle_add_queue_message(void *cls, * @param cqr confirmation message */ static void -handle_queue_create_ok(void *cls, - const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) +handle_queue_create_ok (void *cls, + const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - GNUNET_STATISTICS_update(GST_stats, - "# Suggestions succeeded at communicator", - 1, - GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Request #%u for communicator to create queue succeeded\n", - (unsigned int)ntohs(cqr->request_id)); - GNUNET_SERVICE_client_continue(tc->client); + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + GNUNET_STATISTICS_update (GST_stats, + "# Suggestions succeeded at communicator", + 1, + GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Request #%u for communicator to create queue succeeded\n", + (unsigned int) ntohs (cqr->request_id)); + GNUNET_SERVICE_client_continue (tc->client); } @@ -9565,26 +9628,26 @@ handle_queue_create_ok(void *cls, * @param cqr failure message */ static void -handle_queue_create_fail( +handle_queue_create_fail ( void *cls, const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Request #%u for communicator to create queue failed\n", - (unsigned int)ntohs(cqr->request_id)); - GNUNET_STATISTICS_update(GST_stats, - "# Suggestions failed in queue creation at communicator", - 1, - GNUNET_NO); - GNUNET_SERVICE_client_continue(tc->client); + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Request #%u for communicator to create queue failed\n", + (unsigned int) ntohs (cqr->request_id)); + GNUNET_STATISTICS_update (GST_stats, + "# Suggestions failed in queue creation at communicator", + 1, + GNUNET_NO); + GNUNET_SERVICE_client_continue (tc->client); } @@ -9596,27 +9659,27 @@ handle_queue_create_fail( * @param msg the start message */ static void -handle_suggest_cancel(void *cls, const struct ExpressPreferenceMessage *msg) +handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg) { struct TransportClient *tc = cls; struct PeerRequest *pr; if (CT_APPLICATION != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - pr = GNUNET_CONTAINER_multipeermap_get(tc->details.application.requests, - &msg->peer); + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + pr = GNUNET_CONTAINER_multipeermap_get (tc->details.application.requests, + &msg->peer); if (NULL == pr) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - (void)stop_peer_request(tc, &pr->pid, pr); - GNUNET_SERVICE_client_continue(tc->client); + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + (void) stop_peer_request (tc, &pr->pid, pr); + GNUNET_SERVICE_client_continue (tc->client); } @@ -9628,27 +9691,27 @@ handle_suggest_cancel(void *cls, const struct ExpressPreferenceMessage *msg) * @param emsg error message, or NULL if no errors */ static void -handle_hello_for_client(void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +handle_hello_for_client (void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { struct PeerRequest *pr = cls; const char *val; if (NULL != emsg) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Got failure from PEERSTORE: %s\n", - emsg); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Got failure from PEERSTORE: %s\n", + emsg); + return; + } val = record->value; if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) - { - GNUNET_break(0); - return; - } - start_address_validation(&pr->pid, (const char *)record->value); + { + GNUNET_break (0); + return; + } + start_address_validation (&pr->pid, (const char *) record->value); } @@ -9660,51 +9723,51 @@ handle_hello_for_client(void *cls, * @param msg the start message */ static void -handle_suggest(void *cls, const struct ExpressPreferenceMessage *msg) +handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg) { struct TransportClient *tc = cls; struct PeerRequest *pr; if (CT_NONE == tc->type) - { - tc->type = CT_APPLICATION; - tc->details.application.requests = - GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); - } + { + tc->type = CT_APPLICATION; + tc->details.application.requests = + GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); + } if (CT_APPLICATION != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Client suggested we talk to %s with preference %d at rate %u\n", - GNUNET_i2s(&msg->peer), - (int)ntohl(msg->pk), - (int)ntohl(msg->bw.value__)); - pr = GNUNET_new(struct PeerRequest); + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Client suggested we talk to %s with preference %d at rate %u\n", + GNUNET_i2s (&msg->peer), + (int) ntohl (msg->pk), + (int) ntohl (msg->bw.value__)); + pr = GNUNET_new (struct PeerRequest); pr->tc = tc; pr->pid = msg->peer; pr->bw = msg->bw; - pr->pk = (enum GNUNET_MQ_PriorityPreferences)ntohl(msg->pk); - if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put( + pr->pk = (enum GNUNET_MQ_PriorityPreferences) ntohl (msg->pk); + if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put ( tc->details.application.requests, &pr->pid, pr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) - { - GNUNET_break(0); - GNUNET_free(pr); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - pr->wc = GNUNET_PEERSTORE_watch(peerstore, - "transport", - &pr->pid, - GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, - &handle_hello_for_client, - pr); - GNUNET_SERVICE_client_continue(tc->client); + { + GNUNET_break (0); + GNUNET_free (pr); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + pr->wc = GNUNET_PEERSTORE_watch (peerstore, + "transport", + &pr->pid, + GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, + &handle_hello_for_client, + pr); + GNUNET_SERVICE_client_continue (tc->client); } @@ -9717,11 +9780,11 @@ handle_suggest(void *cls, const struct ExpressPreferenceMessage *msg) * @return #GNUNET_OK on success */ static int -check_request_hello_validation(void *cls, - const struct RequestHelloValidationMessage *m) +check_request_hello_validation (void *cls, + const struct RequestHelloValidationMessage *m) { - (void)cls; - GNUNET_MQ_check_zero_termination(m); + (void) cls; + GNUNET_MQ_check_zero_termination (m); return GNUNET_OK; } @@ -9734,13 +9797,13 @@ check_request_hello_validation(void *cls, * @param m message to verify */ static void -handle_request_hello_validation(void *cls, - const struct RequestHelloValidationMessage *m) +handle_request_hello_validation (void *cls, + const struct RequestHelloValidationMessage *m) { struct TransportClient *tc = cls; - start_address_validation(&m->peer, (const char *)&m[1]); - GNUNET_SERVICE_client_continue(tc->client); + start_address_validation (&m->peer, (const char *) &m[1]); + GNUNET_SERVICE_client_continue (tc->client); } @@ -9753,16 +9816,16 @@ handle_request_hello_validation(void *cls, * @return #GNUNET_OK (always) */ static int -free_neighbour_cb(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +free_neighbour_cb (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct Neighbour *neighbour = value; - (void)cls; - (void)pid; - GNUNET_break(0); // should this ever happen? - free_neighbour(neighbour); + (void) cls; + (void) pid; + GNUNET_break (0); // should this ever happen? + free_neighbour (neighbour); return GNUNET_OK; } @@ -9777,15 +9840,15 @@ free_neighbour_cb(void *cls, * @return #GNUNET_OK (always) */ static int -free_dv_routes_cb(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +free_dv_routes_cb (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct DistanceVector *dv = value; - (void)cls; - (void)pid; - free_dv_route(dv); + (void) cls; + (void) pid; + free_dv_route (dv); return GNUNET_OK; } @@ -9800,15 +9863,15 @@ free_dv_routes_cb(void *cls, * @return #GNUNET_OK (always) */ static int -free_validation_state_cb(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +free_validation_state_cb (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct ValidationState *vs = value; - (void)cls; - (void)pid; - free_validation_state(vs); + (void) cls; + (void) pid; + free_validation_state (vs); return GNUNET_OK; } @@ -9822,13 +9885,13 @@ free_validation_state_cb(void *cls, * @return #GNUNET_OK (always) */ static int -free_pending_ack_cb(void *cls, const struct GNUNET_Uuid *key, void *value) +free_pending_ack_cb (void *cls, const struct GNUNET_Uuid *key, void *value) { struct PendingAcknowledgement *pa = value; - (void)cls; - (void)key; - free_pending_acknowledgement(pa); + (void) cls; + (void) key; + free_pending_acknowledgement (pa); return GNUNET_OK; } @@ -9842,15 +9905,15 @@ free_pending_ack_cb(void *cls, const struct GNUNET_Uuid *key, void *value) * @return #GNUNET_OK (always) */ static int -free_ack_cummulator_cb(void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +free_ack_cummulator_cb (void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct AcknowledgementCummulator *ac = value; - (void)cls; - (void)pid; - GNUNET_free(ac); + (void) cls; + (void) pid; + GNUNET_free (ac); return GNUNET_OK; } @@ -9862,68 +9925,68 @@ free_ack_cummulator_cb(void *cls, * @param cls closure, unused */ static void -do_shutdown(void *cls) +do_shutdown (void *cls) { struct LearnLaunchEntry *lle; - (void)cls; + (void) cls; - GNUNET_CONTAINER_multipeermap_iterate(neighbours, &free_neighbour_cb, NULL); + GNUNET_CONTAINER_multipeermap_iterate (neighbours, &free_neighbour_cb, NULL); if (NULL != peerstore) - { - GNUNET_PEERSTORE_disconnect(peerstore, GNUNET_NO); - peerstore = NULL; - } + { + GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO); + peerstore = NULL; + } if (NULL != GST_stats) - { - GNUNET_STATISTICS_destroy(GST_stats, GNUNET_NO); - GST_stats = NULL; - } + { + GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); + GST_stats = NULL; + } if (NULL != GST_my_private_key) - { - GNUNET_free(GST_my_private_key); - GST_my_private_key = NULL; - } - GNUNET_CONTAINER_multipeermap_iterate(ack_cummulators, - &free_ack_cummulator_cb, - NULL); - GNUNET_CONTAINER_multipeermap_destroy(ack_cummulators); + { + GNUNET_free (GST_my_private_key); + GST_my_private_key = NULL; + } + GNUNET_CONTAINER_multipeermap_iterate (ack_cummulators, + &free_ack_cummulator_cb, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (ack_cummulators); ack_cummulators = NULL; - GNUNET_CONTAINER_multiuuidmap_iterate(pending_acks, - &free_pending_ack_cb, - NULL); - GNUNET_CONTAINER_multiuuidmap_destroy(pending_acks); + GNUNET_CONTAINER_multiuuidmap_iterate (pending_acks, + &free_pending_ack_cb, + NULL); + GNUNET_CONTAINER_multiuuidmap_destroy (pending_acks); pending_acks = NULL; - GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(neighbours)); - GNUNET_CONTAINER_multipeermap_destroy(neighbours); + GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)); + GNUNET_CONTAINER_multipeermap_destroy (neighbours); neighbours = NULL; - GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(links)); - GNUNET_CONTAINER_multipeermap_destroy(links); + GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (links)); + GNUNET_CONTAINER_multipeermap_destroy (links); links = NULL; - GNUNET_CONTAINER_multipeermap_iterate(backtalkers, - &free_backtalker_cb, - NULL); - GNUNET_CONTAINER_multipeermap_destroy(backtalkers); + GNUNET_CONTAINER_multipeermap_iterate (backtalkers, + &free_backtalker_cb, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (backtalkers); backtalkers = NULL; - GNUNET_CONTAINER_multipeermap_iterate(validation_map, - &free_validation_state_cb, - NULL); - GNUNET_CONTAINER_multipeermap_destroy(validation_map); + GNUNET_CONTAINER_multipeermap_iterate (validation_map, + &free_validation_state_cb, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (validation_map); validation_map = NULL; while (NULL != ir_head) - free_incoming_request(ir_head); - GNUNET_assert(0 == ir_total); + free_incoming_request (ir_head); + GNUNET_assert (0 == ir_total); while (NULL != (lle = lle_head)) - { - GNUNET_CONTAINER_DLL_remove(lle_head, lle_tail, lle); - GNUNET_free(lle); - } - GNUNET_CONTAINER_multishortmap_destroy(dvlearn_map); + { + GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); + GNUNET_free (lle); + } + GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map); dvlearn_map = NULL; - GNUNET_CONTAINER_heap_destroy(validation_heap); + GNUNET_CONTAINER_heap_destroy (validation_heap); validation_heap = NULL; - GNUNET_CONTAINER_multipeermap_iterate(dv_routes, &free_dv_routes_cb, NULL); - GNUNET_CONTAINER_multipeermap_destroy(dv_routes); + GNUNET_CONTAINER_multipeermap_iterate (dv_routes, &free_dv_routes_cb, NULL); + GNUNET_CONTAINER_multipeermap_destroy (dv_routes); dv_routes = NULL; } @@ -9936,58 +9999,58 @@ do_shutdown(void *cls) * @param service the initialized service */ static void -run(void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_SERVICE_Handle *service) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_SERVICE_Handle *service) { - (void)cls; - (void)service; + (void) cls; + (void) service; /* setup globals */ - hello_mono_time = GNUNET_TIME_absolute_get_monotonic(c); + hello_mono_time = GNUNET_TIME_absolute_get_monotonic (c); GST_cfg = c; - backtalkers = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); - pending_acks = GNUNET_CONTAINER_multiuuidmap_create(32768, GNUNET_YES); - ack_cummulators = GNUNET_CONTAINER_multipeermap_create(256, GNUNET_YES); - neighbours = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); - links = GNUNET_CONTAINER_multipeermap_create(512, GNUNET_YES); - dv_routes = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); - dvlearn_map = GNUNET_CONTAINER_multishortmap_create(2 * MAX_DV_LEARN_PENDING, - GNUNET_YES); - validation_map = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); + backtalkers = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); + pending_acks = GNUNET_CONTAINER_multiuuidmap_create (32768, GNUNET_YES); + ack_cummulators = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_YES); + neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); + links = GNUNET_CONTAINER_multipeermap_create (512, GNUNET_YES); + dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); + dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING, + GNUNET_YES); + validation_map = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); validation_heap = - GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); + GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); GST_my_private_key = - GNUNET_CRYPTO_eddsa_key_create_from_configuration(GST_cfg); + GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); if (NULL == GST_my_private_key) - { - GNUNET_log( - GNUNET_ERROR_TYPE_ERROR, - _( - "Transport service is lacking key configuration settings. Exiting.\n")); - GNUNET_SCHEDULER_shutdown(); - return; - } - GNUNET_CRYPTO_eddsa_key_get_public(GST_my_private_key, - &GST_my_identity.public_key); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "My identity is `%s'\n", - GNUNET_i2s_full(&GST_my_identity)); - GST_stats = GNUNET_STATISTICS_create("transport", GST_cfg); - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); - peerstore = GNUNET_PEERSTORE_connect(GST_cfg); + { + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + _ ( + "Transport service is lacking key configuration settings. Exiting.\n")); + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, + &GST_my_identity.public_key); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "My identity is `%s'\n", + GNUNET_i2s_full (&GST_my_identity)); + GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + peerstore = GNUNET_PEERSTORE_connect (GST_cfg); if (NULL == peerstore) - { - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - return; - } + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } } /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN( +GNUNET_SERVICE_MAIN ( "transport", GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, @@ -9995,78 +10058,78 @@ GNUNET_SERVICE_MAIN( &client_disconnect_cb, NULL, /* communication with applications */ - GNUNET_MQ_hd_fixed_size(suggest, - GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, - struct ExpressPreferenceMessage, - NULL), - GNUNET_MQ_hd_fixed_size(suggest_cancel, - GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, - struct ExpressPreferenceMessage, - NULL), - GNUNET_MQ_hd_var_size(request_hello_validation, - GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, - struct RequestHelloValidationMessage, - NULL), + GNUNET_MQ_hd_fixed_size (suggest, + GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, + struct ExpressPreferenceMessage, + NULL), + GNUNET_MQ_hd_fixed_size (suggest_cancel, + GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, + struct ExpressPreferenceMessage, + NULL), + GNUNET_MQ_hd_var_size (request_hello_validation, + GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, + struct RequestHelloValidationMessage, + NULL), /* communication with core */ - GNUNET_MQ_hd_fixed_size(client_start, - GNUNET_MESSAGE_TYPE_TRANSPORT_START, - struct StartMessage, - NULL), - GNUNET_MQ_hd_var_size(client_send, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, - struct OutboundMessage, - NULL), - GNUNET_MQ_hd_fixed_size(client_recv_ok, - GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK, - struct RecvOkMessage, - NULL), + GNUNET_MQ_hd_fixed_size (client_start, + GNUNET_MESSAGE_TYPE_TRANSPORT_START, + struct StartMessage, + NULL), + GNUNET_MQ_hd_var_size (client_send, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, + struct OutboundMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_recv_ok, + GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK, + struct RecvOkMessage, + NULL), /* communication with communicators */ - GNUNET_MQ_hd_var_size(communicator_available, - GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, - struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, - NULL), - GNUNET_MQ_hd_var_size(communicator_backchannel, - GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, - struct GNUNET_TRANSPORT_CommunicatorBackchannel, - NULL), - GNUNET_MQ_hd_var_size(add_address, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, - struct GNUNET_TRANSPORT_AddAddressMessage, - NULL), - GNUNET_MQ_hd_fixed_size(del_address, - GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, - struct GNUNET_TRANSPORT_DelAddressMessage, - NULL), - GNUNET_MQ_hd_var_size(incoming_msg, - GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, - struct GNUNET_TRANSPORT_IncomingMessage, - NULL), - GNUNET_MQ_hd_fixed_size(queue_create_ok, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, - struct GNUNET_TRANSPORT_CreateQueueResponse, - NULL), - GNUNET_MQ_hd_fixed_size(queue_create_fail, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, - struct GNUNET_TRANSPORT_CreateQueueResponse, - NULL), - GNUNET_MQ_hd_var_size(add_queue_message, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, - struct GNUNET_TRANSPORT_AddQueueMessage, - NULL), - GNUNET_MQ_hd_fixed_size(del_queue_message, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, - struct GNUNET_TRANSPORT_DelQueueMessage, - NULL), - GNUNET_MQ_hd_fixed_size(send_message_ack, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, - struct GNUNET_TRANSPORT_SendMessageToAck, - NULL), + GNUNET_MQ_hd_var_size (communicator_available, + GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, + struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, + NULL), + GNUNET_MQ_hd_var_size (communicator_backchannel, + GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, + struct GNUNET_TRANSPORT_CommunicatorBackchannel, + NULL), + GNUNET_MQ_hd_var_size (add_address, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, + struct GNUNET_TRANSPORT_AddAddressMessage, + NULL), + GNUNET_MQ_hd_fixed_size (del_address, + GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, + struct GNUNET_TRANSPORT_DelAddressMessage, + NULL), + GNUNET_MQ_hd_var_size (incoming_msg, + GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, + struct GNUNET_TRANSPORT_IncomingMessage, + NULL), + GNUNET_MQ_hd_fixed_size (queue_create_ok, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, + struct GNUNET_TRANSPORT_CreateQueueResponse, + NULL), + GNUNET_MQ_hd_fixed_size (queue_create_fail, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, + struct GNUNET_TRANSPORT_CreateQueueResponse, + NULL), + GNUNET_MQ_hd_var_size (add_queue_message, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, + struct GNUNET_TRANSPORT_AddQueueMessage, + NULL), + GNUNET_MQ_hd_fixed_size (del_queue_message, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, + struct GNUNET_TRANSPORT_DelQueueMessage, + NULL), + GNUNET_MQ_hd_fixed_size (send_message_ack, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, + struct GNUNET_TRANSPORT_SendMessageToAck, + NULL), /* communication with monitors */ - GNUNET_MQ_hd_fixed_size(monitor_start, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, - struct GNUNET_TRANSPORT_MonitorStart, - NULL), - GNUNET_MQ_handler_end()); + GNUNET_MQ_hd_fixed_size (monitor_start, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, + struct GNUNET_TRANSPORT_MonitorStart, + NULL), + GNUNET_MQ_handler_end ()); /* end of file gnunet-service-transport.c */ diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 5080e650e..853a61127 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -61,7 +61,8 @@ /** * Information we need for an asynchronous session kill. */ -struct GNUNET_ATS_SessionKiller { +struct GNUNET_ATS_SessionKiller +{ /** * Kept in a DLL. */ @@ -92,7 +93,8 @@ struct GNUNET_ATS_SessionKiller { /** * What type of client is the `struct TransportClient` about? */ -enum ClientType { +enum ClientType +{ /** * We do not know yet (client is fresh). */ @@ -128,7 +130,8 @@ struct GST_BlacklistCheck; /** * Client connected to the transport service. */ -struct TransportClient { +struct TransportClient +{ /** * This is a doubly-linked list. */ @@ -154,7 +157,8 @@ struct TransportClient { */ enum ClientType type; - union { + union + { /** * Peer identity to monitor the addresses of. * Zero to monitor all neighbours. Valid if @@ -165,7 +169,8 @@ struct TransportClient { /** * Additional details if @e type is CT_BLACKLIST. */ - struct { + struct + { /** * Blacklist check that we're currently performing (or NULL * if we're performing one that has been cancelled). @@ -189,7 +194,8 @@ struct TransportClient { /** * Context we use when performing a blacklist check. */ -struct GST_BlacklistCheck { +struct GST_BlacklistCheck +{ /** * This is a linked list. */ @@ -240,7 +246,8 @@ struct GST_BlacklistCheck { /** * Context for address to string operations */ -struct AddressToStringContext { +struct AddressToStringContext +{ /** * This is a doubly-linked list. */ @@ -261,7 +268,8 @@ struct AddressToStringContext { /** * Closure for #handle_send_transmit_continuation() */ -struct SendTransmitContinuationContext { +struct SendTransmitContinuationContext +{ /** * Client that made the request. */ @@ -416,31 +424,31 @@ struct GNUNET_NT_InterfaceScanner *GST_is; * @param may_drop #GNUNET_YES if the message can be dropped */ static void -unicast(struct TransportClient *tc, - const struct GNUNET_MessageHeader *msg, - int may_drop) +unicast (struct TransportClient *tc, + const struct GNUNET_MessageHeader *msg, + int may_drop) { struct GNUNET_MQ_Envelope *env; - if ((GNUNET_MQ_get_length(tc->mq) >= MAX_PENDING) && + if ((GNUNET_MQ_get_length (tc->mq) >= MAX_PENDING) && (GNUNET_YES == may_drop)) - { - GNUNET_log( - GNUNET_ERROR_TYPE_DEBUG, - "Dropping message of type %u and size %u, have %u/%u messages pending\n", - ntohs(msg->type), - ntohs(msg->size), - GNUNET_MQ_get_length(tc->mq), - MAX_PENDING); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop( - "# messages dropped due to slow client"), - 1, - GNUNET_NO); - return; - } - env = GNUNET_MQ_msg_copy(msg); - GNUNET_MQ_send(tc->mq, env); + { + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Dropping message of type %u and size %u, have %u/%u messages pending\n", + ntohs (msg->type), + ntohs (msg->size), + GNUNET_MQ_get_length (tc->mq), + MAX_PENDING); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# messages dropped due to slow client"), + 1, + GNUNET_NO); + return; + } + env = GNUNET_MQ_msg_copy (msg); + GNUNET_MQ_send (tc->mq, env); } @@ -454,17 +462,17 @@ unicast(struct TransportClient *tc, * @return our `struct TransportClient` */ static void * -client_connect_cb(void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +client_connect_cb (void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct TransportClient *tc; - tc = GNUNET_new(struct TransportClient); + tc = GNUNET_new (struct TransportClient); tc->client = client; tc->mq = mq; - GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); + GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); return tc; } @@ -475,7 +483,7 @@ client_connect_cb(void *cls, * @param cls the `struct BlacklistCheck*` */ static void -do_blacklist_check(void *cls); +do_blacklist_check (void *cls); /** @@ -488,16 +496,16 @@ do_blacklist_check(void *cls); * @return #GNUNET_OK (continue to iterate) */ static int -mark_match_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value) +mark_match_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) { struct TransportClient *tc = cls; struct SendTransmitContinuationContext *stcc = value; if (tc == stcc->tc) - { - stcc->down = GNUNET_YES; - stcc->tc = NULL; - } + { + stcc->down = GNUNET_YES; + stcc->tc = NULL; + } return GNUNET_OK; } @@ -511,50 +519,50 @@ mark_match_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value) * @param app_ctx our `struct TransportClient` */ static void -client_disconnect_cb(void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_ctx) +client_disconnect_cb (void *cls, + struct GNUNET_SERVICE_Client *client, + void *app_ctx) { struct TransportClient *tc = app_ctx; struct GST_BlacklistCheck *bc; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Client %p disconnected, cleaning up.\n", - tc); - GNUNET_CONTAINER_multipeermap_iterate(active_stccs, &mark_match_down, tc); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Client %p disconnected, cleaning up.\n", + tc); + GNUNET_CONTAINER_multipeermap_iterate (active_stccs, &mark_match_down, tc); for (struct AddressToStringContext *cur = a2s_head; NULL != cur; cur = cur->next) - { - if (cur->tc == tc) - cur->tc = NULL; - } - GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc); + { + if (cur->tc == tc) + cur->tc = NULL; + } + GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); switch (tc->type) - { - case CT_NONE: - break; - - case CT_CORE: - break; + { + case CT_NONE: + break; - case CT_MONITOR: - break; + case CT_CORE: + break; - case CT_BLACKLIST: - for (bc = bc_head; NULL != bc; bc = bc->next) - { - if (bc->bl_pos != tc) - continue; - bc->bl_pos = tc->next; - if (NULL == bc->task) - bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); - } - break; + case CT_MONITOR: + break; - case CT_CORE_NO_HANDLERS: - break; + case CT_BLACKLIST: + for (bc = bc_head; NULL != bc; bc = bc->next) + { + if (bc->bl_pos != tc) + continue; + bc->bl_pos = tc->next; + if (NULL == bc->task) + bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); } - GNUNET_free(tc); + break; + + case CT_CORE_NO_HANDLERS: + break; + } + GNUNET_free (tc); } @@ -571,24 +579,24 @@ client_disconnect_cb(void *cls, * @param bandwidth_out outbound bandwidth in NBO */ static void -notify_client_about_neighbour(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) +notify_client_about_neighbour (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { struct TransportClient *tc = cls; struct ConnectInfoMessage cim; - if (GNUNET_NO == GST_neighbours_test_connected(peer)) + if (GNUNET_NO == GST_neighbours_test_connected (peer)) return; - cim.header.size = htons(sizeof(struct ConnectInfoMessage)); - cim.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); + cim.header.size = htons (sizeof(struct ConnectInfoMessage)); + cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); cim.id = *peer; cim.quota_out = bandwidth_out; - unicast(tc, &cim.header, GNUNET_NO); + unicast (tc, &cim.header, GNUNET_NO); } @@ -601,39 +609,39 @@ notify_client_about_neighbour(void *cls, * @param start the start message that was sent */ static void -handle_client_start(void *cls, const struct StartMessage *start) +handle_client_start (void *cls, const struct StartMessage *start) { struct TransportClient *tc = cls; const struct GNUNET_MessageHeader *hello; uint32_t options; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc); - options = ntohl(start->options); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc); + options = ntohl (start->options); if ((0 != (1 & options)) && - (0 != memcmp(&start->self, - &GST_my_identity, - sizeof(struct GNUNET_PeerIdentity)))) - { - /* client thinks this is a different peer, reject */ - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } + (0 != memcmp (&start->self, + &GST_my_identity, + sizeof(struct GNUNET_PeerIdentity)))) + { + /* client thinks this is a different peer, reject */ + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } if (CT_NONE != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } if (0 != (2 & options)) tc->type = CT_CORE; else tc->type = CT_CORE_NO_HANDLERS; - hello = GST_hello_get(); + hello = GST_hello_get (); if (NULL != hello) - unicast(tc, hello, GNUNET_NO); - GST_neighbours_iterate(¬ify_client_about_neighbour, tc); - GNUNET_SERVICE_client_continue(tc->client); + unicast (tc, hello, GNUNET_NO); + GST_neighbours_iterate (¬ify_client_about_neighbour, tc); + GNUNET_SERVICE_client_continue (tc->client); } @@ -644,7 +652,7 @@ handle_client_start(void *cls, const struct StartMessage *start) * @param message the HELLO message */ static int -check_client_hello(void *cls, const struct GNUNET_MessageHeader *message) +check_client_hello (void *cls, const struct GNUNET_MessageHeader *message) { return GNUNET_OK; /* FIXME: check here? */ } @@ -657,13 +665,13 @@ check_client_hello(void *cls, const struct GNUNET_MessageHeader *message) * @param message the HELLO message */ static void -handle_client_hello(void *cls, const struct GNUNET_MessageHeader *message) +handle_client_hello (void *cls, const struct GNUNET_MessageHeader *message) { struct TransportClient *tc = cls; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n"); - GST_validation_handle_hello(message); - GNUNET_SERVICE_client_continue(tc->client); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n"); + GST_validation_handle_hello (message); + GNUNET_SERVICE_client_continue (tc->client); } @@ -677,55 +685,55 @@ handle_client_hello(void *cls, const struct GNUNET_MessageHeader *message) * @param bytes_on_wire bytes sent on wire */ static void -handle_send_transmit_continuation(void *cls, - int success, - size_t bytes_payload, - size_t bytes_on_wire) +handle_send_transmit_continuation (void *cls, + int success, + size_t bytes_payload, + size_t bytes_on_wire) { struct SendTransmitContinuationContext *stcc = cls; struct SendOkMessage send_ok_msg; struct GNUNET_TIME_Relative delay; const struct GNUNET_HELLO_Address *addr; - delay = GNUNET_TIME_absolute_get_duration(stcc->send_time); - addr = GST_neighbour_get_current_address(&stcc->target); + delay = GNUNET_TIME_absolute_get_duration (stcc->send_time); + addr = GST_neighbour_get_current_address (&stcc->target); if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "It took us %s to send %u/%u bytes to %s (%d, %s)\n", - GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), - (unsigned int)bytes_payload, - (unsigned int)bytes_on_wire, - GNUNET_i2s(&stcc->target), - success, - (NULL != addr) ? addr->transport_name : "%"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "It took us %s to send %u/%u bytes to %s (%d, %s)\n", + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), + (unsigned int) bytes_payload, + (unsigned int) bytes_on_wire, + GNUNET_i2s (&stcc->target), + success, + (NULL != addr) ? addr->transport_name : "%"); else - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "It took us %s to send %u/%u bytes to %s (%d, %s)\n", - GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), - (unsigned int)bytes_payload, - (unsigned int)bytes_on_wire, - GNUNET_i2s(&stcc->target), - success, - (NULL != addr) ? addr->transport_name : "%"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "It took us %s to send %u/%u bytes to %s (%d, %s)\n", + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), + (unsigned int) bytes_payload, + (unsigned int) bytes_on_wire, + GNUNET_i2s (&stcc->target), + success, + (NULL != addr) ? addr->transport_name : "%"); if (GNUNET_NO == stcc->down) - { - /* Only send confirmation if we are still connected */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending SEND_OK for transmission request %llu\n", - stcc->uuid); - send_ok_msg.header.size = htons(sizeof(send_ok_msg)); - send_ok_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); - send_ok_msg.bytes_msg = htonl(bytes_payload); - send_ok_msg.bytes_physical = htonl(bytes_on_wire); - send_ok_msg.success = htonl(success); - send_ok_msg.peer = stcc->target; - unicast(stcc->tc, &send_ok_msg.header, GNUNET_NO); - } - GNUNET_assert( + { + /* Only send confirmation if we are still connected */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending SEND_OK for transmission request %llu\n", + stcc->uuid); + send_ok_msg.header.size = htons (sizeof(send_ok_msg)); + send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); + send_ok_msg.bytes_msg = htonl (bytes_payload); + send_ok_msg.bytes_physical = htonl (bytes_on_wire); + send_ok_msg.success = htonl (success); + send_ok_msg.peer = stcc->target; + unicast (stcc->tc, &send_ok_msg.header, GNUNET_NO); + } + GNUNET_assert ( GNUNET_OK == - GNUNET_CONTAINER_multipeermap_remove(active_stccs, &stcc->target, stcc)); - GNUNET_free(stcc); + GNUNET_CONTAINER_multipeermap_remove (active_stccs, &stcc->target, stcc)); + GNUNET_free (stcc); } @@ -736,23 +744,23 @@ handle_send_transmit_continuation(void *cls, * @param obm the send message that was sent */ static int -check_client_send(void *cls, const struct OutboundMessage *obm) +check_client_send (void *cls, const struct OutboundMessage *obm) { uint16_t size; const struct GNUNET_MessageHeader *obmm; - size = ntohs(obm->header.size) - sizeof(struct OutboundMessage); + size = ntohs (obm->header.size) - sizeof(struct OutboundMessage); if (size < sizeof(struct GNUNET_MessageHeader)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - obmm = (const struct GNUNET_MessageHeader *)&obm[1]; - if (size != ntohs(obmm->size)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + obmm = (const struct GNUNET_MessageHeader *) &obm[1]; + if (size != ntohs (obmm->size)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -764,53 +772,53 @@ check_client_send(void *cls, const struct OutboundMessage *obm) * @param obm the send message that was sent */ static void -handle_client_send(void *cls, const struct OutboundMessage *obm) +handle_client_send (void *cls, const struct OutboundMessage *obm) { static unsigned long long uuid_gen; struct TransportClient *tc = cls; const struct GNUNET_MessageHeader *obmm; struct SendTransmitContinuationContext *stcc; - obmm = (const struct GNUNET_MessageHeader *)&obm[1]; - if (GNUNET_NO == GST_neighbours_test_connected(&obm->peer)) - { - /* not connected, not allowed to send; can happen due to asynchronous operations */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Could not send message to peer `%s': not connected\n", - GNUNET_i2s(&obm->peer)); - GNUNET_STATISTICS_update( - GST_stats, - gettext_noop("# bytes payload dropped (other peer was not connected)"), - ntohs(obmm->size), - GNUNET_NO); - GNUNET_SERVICE_client_continue(tc->client); - return; - } - GNUNET_log( + obmm = (const struct GNUNET_MessageHeader *) &obm[1]; + if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer)) + { + /* not connected, not allowed to send; can happen due to asynchronous operations */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Could not send message to peer `%s': not connected\n", + GNUNET_i2s (&obm->peer)); + GNUNET_STATISTICS_update ( + GST_stats, + gettext_noop ("# bytes payload dropped (other peer was not connected)"), + ntohs (obmm->size), + GNUNET_NO); + GNUNET_SERVICE_client_continue (tc->client); + return; + } + GNUNET_log ( GNUNET_ERROR_TYPE_DEBUG, "Received SEND request %llu for `%s' and first message of type %u and total size %u\n", uuid_gen, - GNUNET_i2s(&obm->peer), - ntohs(obmm->type), - ntohs(obmm->size)); - GNUNET_SERVICE_client_continue(tc->client); + GNUNET_i2s (&obm->peer), + ntohs (obmm->type), + ntohs (obmm->size)); + GNUNET_SERVICE_client_continue (tc->client); - stcc = GNUNET_new(struct SendTransmitContinuationContext); + stcc = GNUNET_new (struct SendTransmitContinuationContext); stcc->target = obm->peer; stcc->tc = tc; - stcc->send_time = GNUNET_TIME_absolute_get(); + stcc->send_time = GNUNET_TIME_absolute_get (); stcc->uuid = uuid_gen++; - (void)GNUNET_CONTAINER_multipeermap_put( + (void) GNUNET_CONTAINER_multipeermap_put ( active_stccs, &stcc->target, stcc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GST_manipulation_send(&obm->peer, - obmm, - ntohs(obmm->size), - GNUNET_TIME_relative_ntoh(obm->timeout), - &handle_send_transmit_continuation, - stcc); + GST_manipulation_send (&obm->peer, + obmm, + ntohs (obmm->size), + GNUNET_TIME_relative_ntoh (obm->timeout), + &handle_send_transmit_continuation, + stcc); } @@ -829,50 +837,50 @@ handle_client_send(void *cls, const struct OutboundMessage *obm) * never #GNUNET_NO */ static void -transmit_address_to_client(void *cls, const char *buf, int res) +transmit_address_to_client (void *cls, const char *buf, int res) { struct AddressToStringContext *actx = cls; struct GNUNET_MQ_Envelope *env; struct AddressToStringResultMessage *atsm; size_t slen; - GNUNET_assert((GNUNET_OK == res) || (GNUNET_SYSERR == res)); + GNUNET_assert ((GNUNET_OK == res) || (GNUNET_SYSERR == res)); if (NULL == actx->tc) return; if (NULL == buf) + { + env = GNUNET_MQ_msg (atsm, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); + if (GNUNET_OK == res) + { + /* this was the last call, transmit */ + atsm->res = htonl (GNUNET_OK); + atsm->addr_len = htonl (0); + GNUNET_MQ_send (actx->tc->mq, env); + GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx); + GNUNET_free (actx); + return; + } + if (GNUNET_SYSERR == res) { - env = GNUNET_MQ_msg(atsm, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); - if (GNUNET_OK == res) - { - /* this was the last call, transmit */ - atsm->res = htonl(GNUNET_OK); - atsm->addr_len = htonl(0); - GNUNET_MQ_send(actx->tc->mq, env); - GNUNET_CONTAINER_DLL_remove(a2s_head, a2s_tail, actx); - GNUNET_free(actx); - return; - } - if (GNUNET_SYSERR == res) - { - /* address conversion failed, but there will be more callbacks */ - atsm->res = htonl(GNUNET_SYSERR); - atsm->addr_len = htonl(0); - GNUNET_MQ_send(actx->tc->mq, env); - return; - } + /* address conversion failed, but there will be more callbacks */ + atsm->res = htonl (GNUNET_SYSERR); + atsm->addr_len = htonl (0); + GNUNET_MQ_send (actx->tc->mq, env); + return; } - GNUNET_assert(GNUNET_OK == res); + } + GNUNET_assert (GNUNET_OK == res); /* succesful conversion, append*/ - slen = strlen(buf) + 1; + slen = strlen (buf) + 1; env = - GNUNET_MQ_msg_extra(atsm, - slen, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); - atsm->res = htonl(GNUNET_YES); - atsm->addr_len = htonl(slen); - GNUNET_memcpy(&atsm[1], buf, slen); - GNUNET_MQ_send(actx->tc->mq, env); + GNUNET_MQ_msg_extra (atsm, + slen, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); + atsm->res = htonl (GNUNET_YES); + atsm->addr_len = htonl (slen); + GNUNET_memcpy (&atsm[1], buf, slen); + GNUNET_MQ_send (actx->tc->mq, env); } @@ -884,29 +892,29 @@ transmit_address_to_client(void *cls, const char *buf, int res) * @return #GNUNET_OK if @a alum is well-formed */ static int -check_client_address_to_string(void *cls, - const struct AddressLookupMessage *alum) +check_client_address_to_string (void *cls, + const struct AddressLookupMessage *alum) { const char *plugin_name; const char *address; uint32_t address_len; uint16_t size; - size = ntohs(alum->header.size); - address_len = ntohs(alum->addrlen); + size = ntohs (alum->header.size); + address_len = ntohs (alum->addrlen); if (size <= sizeof(struct AddressLookupMessage) + address_len) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - address = (const char *)&alum[1]; - plugin_name = (const char *)&address[address_len]; - if ('\0' != plugin_name[size - sizeof(struct AddressLookupMessage) - - address_len - 1]) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + address = (const char *) &alum[1]; + plugin_name = (const char *) &address[address_len]; + if ('\0' != plugin_name[size - sizeof(struct AddressLookupMessage) + - address_len - 1]) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -918,8 +926,8 @@ check_client_address_to_string(void *cls, * @param alum the resolution request */ static void -handle_client_address_to_string(void *cls, - const struct AddressLookupMessage *alum) +handle_client_address_to_string (void *cls, + const struct AddressLookupMessage *alum) { struct TransportClient *tc = cls; struct GNUNET_TRANSPORT_PluginFunctions *papi; @@ -932,45 +940,45 @@ handle_client_address_to_string(void *cls, struct GNUNET_TIME_Relative rtimeout; int32_t numeric; - address_len = ntohs(alum->addrlen); - address = (const char *)&alum[1]; - plugin_name = (const char *)&address[address_len]; - rtimeout = GNUNET_TIME_relative_ntoh(alum->timeout); - numeric = ntohs(alum->numeric_only); - papi = GST_plugins_printer_find(plugin_name); + address_len = ntohs (alum->addrlen); + address = (const char *) &alum[1]; + plugin_name = (const char *) &address[address_len]; + rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); + numeric = ntohs (alum->numeric_only); + papi = GST_plugins_printer_find (plugin_name); if (NULL == papi) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Failed to find plugin `%s'\n", - plugin_name); - env = GNUNET_MQ_msg(atsm, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); - atsm->res = htonl(GNUNET_SYSERR); - atsm->addr_len = htonl(0); - GNUNET_MQ_send(tc->mq, env); - env = GNUNET_MQ_msg(atsm, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); - atsm->res = htonl(GNUNET_OK); - atsm->addr_len = htonl(0); - GNUNET_MQ_send(tc->mq, env); - return; - } - actx = GNUNET_new(struct AddressToStringContext); + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to find plugin `%s'\n", + plugin_name); + env = GNUNET_MQ_msg (atsm, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); + atsm->res = htonl (GNUNET_SYSERR); + atsm->addr_len = htonl (0); + GNUNET_MQ_send (tc->mq, env); + env = GNUNET_MQ_msg (atsm, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); + atsm->res = htonl (GNUNET_OK); + atsm->addr_len = htonl (0); + GNUNET_MQ_send (tc->mq, env); + return; + } + actx = GNUNET_new (struct AddressToStringContext); actx->tc = tc; - GNUNET_CONTAINER_DLL_insert(a2s_head, a2s_tail, actx); - GNUNET_SERVICE_client_disable_continue_warning(tc->client); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Pretty-printing address of %u bytes using plugin `%s'\n", - address_len, - plugin_name); - papi->address_pretty_printer(papi->cls, - plugin_name, - address, - address_len, - numeric, - rtimeout, - &transmit_address_to_client, - actx); + GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx); + GNUNET_SERVICE_client_disable_continue_warning (tc->client); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Pretty-printing address of %u bytes using plugin `%s'\n", + address_len, + plugin_name); + papi->address_pretty_printer (papi->cls, + plugin_name, + address, + address_len, + numeric, + rtimeout, + &transmit_address_to_client, + actx); } @@ -982,7 +990,7 @@ handle_client_address_to_string(void *cls, * @return composed message */ static struct PeerIterateResponseMessage * -compose_address_iterate_response_message( +compose_address_iterate_response_message ( const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address) { @@ -992,34 +1000,34 @@ compose_address_iterate_response_message( size_t alen; char *addr; - GNUNET_assert(NULL != peer); + GNUNET_assert (NULL != peer); if (NULL != address) - { - tlen = strlen(address->transport_name) + 1; - alen = address->address_length; - } + { + tlen = strlen (address->transport_name) + 1; + alen = address->address_length; + } else - { - tlen = 0; - alen = 0; - } + { + tlen = 0; + alen = 0; + } size = (sizeof(struct PeerIterateResponseMessage) + alen + tlen); - msg = GNUNET_malloc(size); - msg->header.size = htons(size); + msg = GNUNET_malloc (size); + msg->header.size = htons (size); msg->header.type = - htons(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); - msg->reserved = htonl(0); + htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); + msg->reserved = htonl (0); msg->peer = *peer; - msg->addrlen = htonl(alen); - msg->pluginlen = htonl(tlen); + msg->addrlen = htonl (alen); + msg->pluginlen = htonl (tlen); if (NULL != address) - { - msg->local_address_info = htonl((uint32_t)address->local_info); - addr = (char *)&msg[1]; - GNUNET_memcpy(addr, address->address, alen); - GNUNET_memcpy(&addr[alen], address->transport_name, tlen); - } + { + msg->local_address_info = htonl ((uint32_t) address->local_info); + addr = (char *) &msg[1]; + GNUNET_memcpy (addr, address->address, alen); + GNUNET_memcpy (&addr[alen], address->transport_name, tlen); + } return msg; } @@ -1028,7 +1036,8 @@ compose_address_iterate_response_message( * Context for #send_validation_information() and * #send_peer_information(). */ -struct IterationContext { +struct IterationContext +{ /** * Context to use for the transmission. */ @@ -1058,31 +1067,31 @@ struct IterationContext { * @param bandwidth_out outbound quota in NBO */ static void -send_peer_information(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) +send_peer_information (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { struct IterationContext *pc = cls; struct GNUNET_MQ_Envelope *env; struct PeerIterateResponseMessage *msg; - if ((GNUNET_YES != pc->all) && (0 != memcmp(peer, &pc->id, sizeof(pc->id)))) + if ((GNUNET_YES != pc->all) && (0 != memcmp (peer, &pc->id, sizeof(pc->id)))) return; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending information about `%s' using address `%s' in state `%s'\n", - GNUNET_i2s(peer), - (NULL != address) ? GST_plugins_a2s(address) : "", - GNUNET_TRANSPORT_ps2s(state)); - msg = compose_address_iterate_response_message(peer, address); - msg->state = htonl(state); - msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); - env = GNUNET_MQ_msg_copy(&msg->header); - GNUNET_free(msg); - GNUNET_MQ_send(pc->tc->mq, env); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending information about `%s' using address `%s' in state `%s'\n", + GNUNET_i2s (peer), + (NULL != address) ? GST_plugins_a2s (address) : "", + GNUNET_TRANSPORT_ps2s (state)); + msg = compose_address_iterate_response_message (peer, address); + msg->state = htonl (state); + msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout); + env = GNUNET_MQ_msg_copy (&msg->header); + GNUNET_free (msg); + GNUNET_MQ_send (pc->tc->mq, env); } @@ -1094,61 +1103,61 @@ send_peer_information(void *cls, * @param msg the peer address information request */ static void -handle_client_monitor_peers(void *cls, const struct PeerMonitorMessage *msg) +handle_client_monitor_peers (void *cls, const struct PeerMonitorMessage *msg) { struct TransportClient *tc = cls; struct IterationContext pc; if (CT_NONE != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - GNUNET_SERVICE_client_disable_continue_warning(tc->client); - GNUNET_SERVICE_client_mark_monitor(tc->client); + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + GNUNET_SERVICE_client_disable_continue_warning (tc->client); + GNUNET_SERVICE_client_mark_monitor (tc->client); /* Send initial list */ pc.tc = tc; - if (0 == memcmp(&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity))) - { - /* iterate over all neighbours */ - pc.all = GNUNET_YES; - pc.id = msg->peer; - } + if (0 == memcmp (&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity))) + { + /* iterate over all neighbours */ + pc.all = GNUNET_YES; + pc.id = msg->peer; + } else - { - /* just return one neighbour */ - pc.all = GNUNET_NO; - pc.id = msg->peer; - } - GST_neighbours_iterate(&send_peer_information, &pc); + { + /* just return one neighbour */ + pc.all = GNUNET_NO; + pc.id = msg->peer; + } + GST_neighbours_iterate (&send_peer_information, &pc); - if (GNUNET_YES != ntohl(msg->one_shot)) - { - tc->details.monitor_peer = msg->peer; - tc->type = CT_MONITOR; - if (0 != - memcmp(&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity))) - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Client %p started monitoring of the peer `%s'\n", - tc, - GNUNET_i2s(&msg->peer)); - else - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Client %p started monitoring all peers\n", - tc); - } + if (GNUNET_YES != ntohl (msg->one_shot)) + { + tc->details.monitor_peer = msg->peer; + tc->type = CT_MONITOR; + if (0 != + memcmp (&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity))) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Client %p started monitoring of the peer `%s'\n", + tc, + GNUNET_i2s (&msg->peer)); + else + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Client %p started monitoring all peers\n", + tc); + } else - { - struct GNUNET_MessageHeader *msg; - struct GNUNET_MQ_Envelope *env; + { + struct GNUNET_MessageHeader *msg; + struct GNUNET_MQ_Envelope *env; - env = - GNUNET_MQ_msg(msg, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END); - GNUNET_MQ_send(tc->mq, env); - } + env = + GNUNET_MQ_msg (msg, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END); + GNUNET_MQ_send (tc->mq, env); + } } @@ -1165,9 +1174,9 @@ handle_client_monitor_peers(void *cls, const struct PeerMonitorMessage *msg) * merely signalling that the initial iteration is over */ static void -plugin_session_info_cb(void *cls, - struct GNUNET_ATS_Session *session, - const struct GNUNET_TRANSPORT_SessionInfo *info) +plugin_session_info_cb (void *cls, + struct GNUNET_ATS_Session *session, + const struct GNUNET_TRANSPORT_SessionInfo *info) { struct GNUNET_MQ_Envelope *env; struct TransportPluginMonitorMessage *msg; @@ -1178,65 +1187,65 @@ plugin_session_info_cb(void *cls, char *name; char *addr; - if (0 == GNUNET_notification_context_get_size(plugin_nc)) - { - GST_plugins_monitor_subscribe(NULL, NULL); - return; - } + if (0 == GNUNET_notification_context_get_size (plugin_nc)) + { + GST_plugins_monitor_subscribe (NULL, NULL); + return; + } if ((NULL == info) && (NULL == session)) + { + /* end of initial iteration */ + if (NULL != sync_client) { - /* end of initial iteration */ - if (NULL != sync_client) - { - env = - GNUNET_MQ_msg(sync, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC); - GNUNET_MQ_send(sync_client->mq, env); - sync_client = NULL; - } - return; + env = + GNUNET_MQ_msg (sync, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC); + GNUNET_MQ_send (sync_client->mq, env); + sync_client = NULL; } - GNUNET_assert(NULL != info); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Plugin event for peer %s on transport %s\n", - GNUNET_i2s(&info->address->peer), - info->address->transport_name); - slen = strlen(info->address->transport_name) + 1; + return; + } + GNUNET_assert (NULL != info); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Plugin event for peer %s on transport %s\n", + GNUNET_i2s (&info->address->peer), + info->address->transport_name); + slen = strlen (info->address->transport_name) + 1; alen = info->address->address_length; size = sizeof(struct TransportPluginMonitorMessage) + slen + alen; if (size > UINT16_MAX) - { - GNUNET_break(0); - return; - } - msg = GNUNET_malloc(size); - msg->header.size = htons(size); - msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT); - msg->session_state = htons((uint16_t)info->state); - msg->is_inbound = htons((int16_t)info->is_inbound); - msg->msgs_pending = htonl(info->num_msg_pending); - msg->bytes_pending = htonl(info->num_bytes_pending); - msg->timeout = GNUNET_TIME_absolute_hton(info->session_timeout); - msg->delay = GNUNET_TIME_absolute_hton(info->receive_delay); + { + GNUNET_break (0); + return; + } + msg = GNUNET_malloc (size); + msg->header.size = htons (size); + msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT); + msg->session_state = htons ((uint16_t) info->state); + msg->is_inbound = htons ((int16_t) info->is_inbound); + msg->msgs_pending = htonl (info->num_msg_pending); + msg->bytes_pending = htonl (info->num_bytes_pending); + msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout); + msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay); msg->peer = info->address->peer; - msg->session_id = (uint64_t)(intptr_t)session; - msg->plugin_name_len = htons(slen); - msg->plugin_address_len = htons(alen); - name = (char *)&msg[1]; - GNUNET_memcpy(name, info->address->transport_name, slen); + msg->session_id = (uint64_t) (intptr_t) session; + msg->plugin_name_len = htons (slen); + msg->plugin_address_len = htons (alen); + name = (char *) &msg[1]; + GNUNET_memcpy (name, info->address->transport_name, slen); addr = &name[slen]; - GNUNET_memcpy(addr, info->address->address, alen); + GNUNET_memcpy (addr, info->address->address, alen); if (NULL != sync_client) - { - struct GNUNET_MQ_Envelope *env; + { + struct GNUNET_MQ_Envelope *env; - env = GNUNET_MQ_msg_copy(&msg->header); - GNUNET_MQ_send(sync_client->mq, env); - } + env = GNUNET_MQ_msg_copy (&msg->header); + GNUNET_MQ_send (sync_client->mq, env); + } else - { - GNUNET_notification_context_broadcast(plugin_nc, &msg->header, GNUNET_NO); - } - GNUNET_free(msg); + { + GNUNET_notification_context_broadcast (plugin_nc, &msg->header, GNUNET_NO); + } + GNUNET_free (msg); } @@ -1247,17 +1256,17 @@ plugin_session_info_cb(void *cls, * @param message the peer address information request */ static void -handle_client_monitor_plugins(void *cls, - const struct GNUNET_MessageHeader *message) +handle_client_monitor_plugins (void *cls, + const struct GNUNET_MessageHeader *message) { struct TransportClient *tc = cls; - GNUNET_SERVICE_client_mark_monitor(tc->client); - GNUNET_SERVICE_client_disable_continue_warning(tc->client); - GNUNET_notification_context_add(plugin_nc, tc->mq); - GNUNET_assert(NULL == sync_client); + GNUNET_SERVICE_client_mark_monitor (tc->client); + GNUNET_SERVICE_client_disable_continue_warning (tc->client); + GNUNET_notification_context_add (plugin_nc, tc->mq); + GNUNET_assert (NULL == sync_client); sync_client = tc; - GST_plugins_monitor_subscribe(&plugin_session_info_cb, NULL); + GST_plugins_monitor_subscribe (&plugin_session_info_cb, NULL); } @@ -1268,28 +1277,28 @@ handle_client_monitor_plugins(void *cls, * @param may_drop #GNUNET_YES if the message can be dropped / is payload */ void -GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, int may_drop) +GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop) { int done; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Asked to broadcast message of type %u with %u bytes\n", - (unsigned int)ntohs(msg->type), - (unsigned int)ntohs(msg->size)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Asked to broadcast message of type %u with %u bytes\n", + (unsigned int) ntohs (msg->type), + (unsigned int) ntohs (msg->size)); done = GNUNET_NO; for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - if (CT_NONE == tc->type) - continue; /* client not yet ready */ - if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type)) - continue; /* skip, this client does not care about payload */ - unicast(tc, msg, may_drop); - done = GNUNET_YES; - } + { + if (CT_NONE == tc->type) + continue; /* client not yet ready */ + if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type)) + continue; /* skip, this client does not care about payload */ + unicast (tc, msg, may_drop); + done = GNUNET_YES; + } if (GNUNET_NO == done) - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Message of type %u not delivered, is CORE service up?\n", - ntohs(msg->type)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Message of type %u not delivered, is CORE service up?\n", + ntohs (msg->type)); } @@ -1302,7 +1311,7 @@ GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, int may_drop) * @param state_timeout the time out for the state */ void -GST_clients_broadcast_peer_notification( +GST_clients_broadcast_peer_notification ( const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, enum GNUNET_TRANSPORT_PeerState state, @@ -1311,25 +1320,25 @@ GST_clients_broadcast_peer_notification( struct GNUNET_MQ_Envelope *env; struct PeerIterateResponseMessage *msg; - msg = compose_address_iterate_response_message(peer, address); - msg->state = htonl(state); - msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); + msg = compose_address_iterate_response_message (peer, address); + msg->state = htonl (state); + msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout); for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - if (CT_MONITOR != tc->type) - continue; - if ((0 == memcmp(&tc->details.monitor_peer, - &all_zeros, - sizeof(struct GNUNET_PeerIdentity))) || - (0 == memcmp(&tc->details.monitor_peer, - peer, - sizeof(struct GNUNET_PeerIdentity)))) - { - env = GNUNET_MQ_msg_copy(&msg->header); - GNUNET_MQ_send(tc->mq, env); - } + { + if (CT_MONITOR != tc->type) + continue; + if ((0 == memcmp (&tc->details.monitor_peer, + &all_zeros, + sizeof(struct GNUNET_PeerIdentity))) || + (0 == memcmp (&tc->details.monitor_peer, + peer, + sizeof(struct GNUNET_PeerIdentity)))) + { + env = GNUNET_MQ_msg_copy (&msg->header); + GNUNET_MQ_send (tc->mq, env); } - GNUNET_free(msg); + } + GNUNET_free (msg); } @@ -1343,7 +1352,7 @@ GST_clients_broadcast_peer_notification( * @return #GNUNET_OK (continue to iterate) */ static int -mark_peer_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value) +mark_peer_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) { struct SendTransmitContinuationContext *stcc = value; @@ -1359,19 +1368,19 @@ mark_peer_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value) * @param peer peer that disconnected */ void -GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer) +GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer) { struct DisconnectInfoMessage disconnect_msg; - GNUNET_CONTAINER_multipeermap_get_multiple(active_stccs, - peer, - &mark_peer_down, - NULL); - disconnect_msg.header.size = htons(sizeof(struct DisconnectInfoMessage)); - disconnect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); - disconnect_msg.reserved = htonl(0); + GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs, + peer, + &mark_peer_down, + NULL); + disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage)); + disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); + disconnect_msg.reserved = htonl (0); disconnect_msg.peer = *peer; - GST_clients_broadcast(&disconnect_msg.header, GNUNET_NO); + GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO); } @@ -1387,27 +1396,27 @@ GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer) * @param bandwidth_out outbound quota in NBO */ static void -transmit_our_hello(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) +transmit_our_hello (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { const struct GNUNET_MessageHeader *hello = cls; - if (0 == memcmp(peer, &GST_my_identity, sizeof(struct GNUNET_PeerIdentity))) + if (0 == memcmp (peer, &GST_my_identity, sizeof(struct GNUNET_PeerIdentity))) return; /* not to ourselves */ - if (GNUNET_NO == GST_neighbours_test_connected(peer)) + if (GNUNET_NO == GST_neighbours_test_connected (peer)) return; - GST_neighbours_send(peer, - hello, - ntohs(hello->size), - hello_expiration, - NULL, - NULL); + GST_neighbours_send (peer, + hello, + ntohs (hello->size), + hello_expiration, + NULL, + NULL); } @@ -1418,12 +1427,12 @@ transmit_our_hello(void *cls, * @param hello new HELLO */ static void -process_hello_update(void *cls, const struct GNUNET_MessageHeader *hello) +process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n"); - GST_clients_broadcast(hello, GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n"); - GST_neighbours_iterate(&transmit_our_hello, (void *)hello); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n"); + GST_clients_broadcast (hello, GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n"); + GST_neighbours_iterate (&transmit_our_hello, (void *) hello); } @@ -1438,44 +1447,44 @@ process_hello_update(void *cls, const struct GNUNET_MessageHeader *hello) * @return how long the plugin should wait until receiving more data */ static struct GNUNET_TIME_Relative -process_payload(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - const struct GNUNET_MessageHeader *message) +process_payload (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + const struct GNUNET_MessageHeader *message) { struct GNUNET_TIME_Relative ret; int do_forward; struct InboundMessage *im; - size_t msg_size = ntohs(message->size); + size_t msg_size = ntohs (message->size); size_t size = sizeof(struct InboundMessage) + msg_size; char buf[size] GNUNET_ALIGN; do_forward = GNUNET_SYSERR; - ret = GST_neighbours_calculate_receive_delay(&address->peer, - msg_size, - &do_forward); - if (!GST_neighbours_test_connected(&address->peer)) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Discarded %u bytes type %u payload from peer `%s'\n", - (unsigned int)msg_size, - ntohs(message->type), - GNUNET_i2s(&address->peer)); - GNUNET_STATISTICS_update( - GST_stats, - gettext_noop("# bytes payload discarded due to not connected peer"), - msg_size, - GNUNET_NO); - return ret; - } + ret = GST_neighbours_calculate_receive_delay (&address->peer, + msg_size, + &do_forward); + if (! GST_neighbours_test_connected (&address->peer)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Discarded %u bytes type %u payload from peer `%s'\n", + (unsigned int) msg_size, + ntohs (message->type), + GNUNET_i2s (&address->peer)); + GNUNET_STATISTICS_update ( + GST_stats, + gettext_noop ("# bytes payload discarded due to not connected peer"), + msg_size, + GNUNET_NO); + return ret; + } if (GNUNET_YES != do_forward) return ret; - im = (struct InboundMessage *)buf; - im->header.size = htons(size); - im->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); + im = (struct InboundMessage *) buf; + im->header.size = htons (size); + im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); im->peer = address->peer; - GNUNET_memcpy(&im[1], message, ntohs(message->size)); - GST_clients_broadcast(&im->header, GNUNET_YES); + GNUNET_memcpy (&im[1], message, ntohs (message->size)); + GST_clients_broadcast (&im->header, GNUNET_YES); return ret; } @@ -1486,14 +1495,14 @@ process_payload(const struct GNUNET_HELLO_Address *address, * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill */ static void -kill_session_task(void *cls) +kill_session_task (void *cls) { struct GNUNET_ATS_SessionKiller *sk = cls; sk->task = NULL; - GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); - sk->plugin->disconnect_session(sk->plugin->cls, sk->session); - GNUNET_free(sk); + GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); + sk->plugin->disconnect_session (sk->plugin->cls, sk->session); + GNUNET_free (sk); } @@ -1505,7 +1514,7 @@ kill_session_task(void *cls) * @param session session to termiante */ static void -kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session) +kill_session (const char *plugin_name, struct GNUNET_ATS_Session *session) { struct GNUNET_TRANSPORT_PluginFunctions *plugin; struct GNUNET_ATS_SessionKiller *sk; @@ -1513,18 +1522,18 @@ kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session) for (sk = sk_head; NULL != sk; sk = sk->next) if (sk->session == session) return; - plugin = GST_plugins_find(plugin_name); + plugin = GST_plugins_find (plugin_name); if (NULL == plugin) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } /* need to issue disconnect asynchronously */ - sk = GNUNET_new(struct GNUNET_ATS_SessionKiller); + sk = GNUNET_new (struct GNUNET_ATS_SessionKiller); sk->session = session; sk->plugin = plugin; - sk->task = GNUNET_SCHEDULER_add_now(&kill_session_task, sk); - GNUNET_CONTAINER_DLL_insert(sk_head, sk_tail, sk); + sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk); + GNUNET_CONTAINER_DLL_insert (sk_head, sk_tail, sk); } @@ -1539,37 +1548,37 @@ kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session) * @param result the result */ static void -connect_bl_check_cont(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - int result) +connect_bl_check_cont (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + int result) { struct GNUNET_MessageHeader *msg = cls; if (GNUNET_OK == result) + { + /* Blacklist allows to speak to this peer, forward SYN to neighbours */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Received SYN message from peer `%s' at `%s'\n", + GNUNET_i2s (peer), + GST_plugins_a2s (address)); + if (GNUNET_OK != GST_neighbours_handle_session_syn (msg, peer)) { - /* Blacklist allows to speak to this peer, forward SYN to neighbours */ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Received SYN message from peer `%s' at `%s'\n", - GNUNET_i2s(peer), - GST_plugins_a2s(address)); - if (GNUNET_OK != GST_neighbours_handle_session_syn(msg, peer)) - { - GST_blacklist_abort_matching(address, session); - kill_session(address->transport_name, session); - } - GNUNET_free(msg); - return; + GST_blacklist_abort_matching (address, session); + kill_session (address->transport_name, session); } - GNUNET_free(msg); + GNUNET_free (msg); + return; + } + GNUNET_free (msg); if (GNUNET_SYSERR == result) return; /* check was aborted, session destroyed */ /* Blacklist denies to speak to this peer */ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Discarding SYN message from `%s' due to denied blacklist check\n", - GNUNET_i2s(peer)); - kill_session(address->transport_name, session); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Discarding SYN message from `%s' due to denied blacklist check\n", + GNUNET_i2s (peer)); + kill_session (address->transport_name, session); } @@ -1587,10 +1596,10 @@ connect_bl_check_cont(void *cls, * (plugins that do not support this, can ignore the return value) */ struct GNUNET_TIME_Relative -GST_receive_callback(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - const struct GNUNET_MessageHeader *message) +GST_receive_callback (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + const struct GNUNET_MessageHeader *message) { const char *plugin_name = cls; struct GNUNET_TIME_Relative ret; @@ -1599,115 +1608,115 @@ GST_receive_callback(void *cls, ret = GNUNET_TIME_UNIT_ZERO; if (NULL == message) goto end; - type = ntohs(message->type); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received message with type %u from peer `%s' at %s\n", - type, - GNUNET_i2s(&address->peer), - GST_plugins_a2s(address)); - - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# bytes total received"), - ntohs(message->size), - GNUNET_NO); - GST_neighbours_notify_data_recv(address, message); + type = ntohs (message->type); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received message with type %u from peer `%s' at %s\n", + type, + GNUNET_i2s (&address->peer), + GST_plugins_a2s (address)); + + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# bytes total received"), + ntohs (message->size), + GNUNET_NO); + GST_neighbours_notify_data_recv (address, message); switch (type) + { + case GNUNET_MESSAGE_TYPE_HELLO_LEGACY: + /* Legacy HELLO message, discard */ + return ret; + + case GNUNET_MESSAGE_TYPE_HELLO: + if (GNUNET_OK != GST_validation_handle_hello (message)) { - case GNUNET_MESSAGE_TYPE_HELLO_LEGACY: - /* Legacy HELLO message, discard */ - return ret; - - case GNUNET_MESSAGE_TYPE_HELLO: - if (GNUNET_OK != GST_validation_handle_hello(message)) - { - GNUNET_break_op(0); - GST_blacklist_abort_matching(address, session); - } - return ret; - - case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Processing PING from `%s'\n", - GST_plugins_a2s(address)); - if (GNUNET_OK != - GST_validation_handle_ping(&address->peer, message, address, session)) - { - GST_blacklist_abort_matching(address, session); - kill_session(plugin_name, session); - } - break; + GNUNET_break_op (0); + GST_blacklist_abort_matching (address, session); + } + return ret; - case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Processing PONG from `%s'\n", - GST_plugins_a2s(address)); - if (GNUNET_OK != GST_validation_handle_pong(&address->peer, message)) - { - GNUNET_break_op(0); - GST_blacklist_abort_matching(address, session); - kill_session(plugin_name, session); - } - break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Processing PING from `%s'\n", + GST_plugins_a2s (address)); + if (GNUNET_OK != + GST_validation_handle_ping (&address->peer, message, address, session)) + { + GST_blacklist_abort_matching (address, session); + kill_session (plugin_name, session); + } + break; + + case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Processing PONG from `%s'\n", + GST_plugins_a2s (address)); + if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message)) + { + GNUNET_break_op (0); + GST_blacklist_abort_matching (address, session); + kill_session (plugin_name, session); + } + break; - case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN: - /* Do blacklist check if communication with this peer is allowed */ - (void)GST_blacklist_test_allowed(&address->peer, + case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN: + /* Do blacklist check if communication with this peer is allowed */ + (void) GST_blacklist_test_allowed (&address->peer, NULL, &connect_bl_check_cont, - GNUNET_copy_message(message), + GNUNET_copy_message (message), address, session); - break; + break; - case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK: - if (GNUNET_OK != - GST_neighbours_handle_session_syn_ack(message, address, session)) - { - GST_blacklist_abort_matching(address, session); - kill_session(plugin_name, session); - } - break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK: + if (GNUNET_OK != + GST_neighbours_handle_session_syn_ack (message, address, session)) + { + GST_blacklist_abort_matching (address, session); + kill_session (plugin_name, session); + } + break; - case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: - if (GNUNET_OK != - GST_neighbours_handle_session_ack(message, address, session)) - { - GNUNET_break_op(0); - GST_blacklist_abort_matching(address, session); - kill_session(plugin_name, session); - } - break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: + if (GNUNET_OK != + GST_neighbours_handle_session_ack (message, address, session)) + { + GNUNET_break_op (0); + GST_blacklist_abort_matching (address, session); + kill_session (plugin_name, session); + } + break; - case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: - GST_neighbours_handle_disconnect_message(&address->peer, message); - break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: + GST_neighbours_handle_disconnect_message (&address->peer, message); + break; - case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA: - GST_neighbours_handle_quota_message(&address->peer, message); - break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA: + GST_neighbours_handle_quota_message (&address->peer, message); + break; - case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: - GST_neighbours_keepalive(&address->peer, message); - break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: + GST_neighbours_keepalive (&address->peer, message); + break; - case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: - GST_neighbours_keepalive_response(&address->peer, message); - break; + case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: + GST_neighbours_keepalive_response (&address->peer, message); + break; - default: - /* should be payload */ - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# bytes payload received"), - ntohs(message->size), - GNUNET_NO); - ret = process_payload(address, session, message); - break; - } + default: + /* should be payload */ + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# bytes payload received"), + ntohs (message->size), + GNUNET_NO); + ret = process_payload (address, session, message); + break; + } end: - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Allowing receive from peer %s to continue in %s\n", - GNUNET_i2s(&address->peer), - GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Allowing receive from peer %s to continue in %s\n", + GNUNET_i2s (&address->peer), + GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); return ret; } @@ -1722,7 +1731,7 @@ end: * @param address the address to add or remove */ static void -plugin_env_address_change_notification( +plugin_env_address_change_notification ( void *cls, int add_remove, const struct GNUNET_HELLO_Address *address) @@ -1730,29 +1739,29 @@ plugin_env_address_change_notification( static int addresses = 0; if (GNUNET_YES == add_remove) + { + addresses++; + GNUNET_STATISTICS_update (GST_stats, "# transport addresses", 1, GNUNET_NO); + } + else if (GNUNET_NO == add_remove) + { + if (0 == addresses) { - addresses++; - GNUNET_STATISTICS_update(GST_stats, "# transport addresses", 1, GNUNET_NO); + GNUNET_break (0); } - else if (GNUNET_NO == add_remove) + else { - if (0 == addresses) - { - GNUNET_break(0); - } - else - { - addresses--; - GNUNET_STATISTICS_update(GST_stats, - "# transport addresses", - -1, - GNUNET_NO); - } + addresses--; + GNUNET_STATISTICS_update (GST_stats, + "# transport addresses", + -1, + GNUNET_NO); } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Transport now has %u addresses to communicate\n", - addresses); - GST_hello_modify_addresses(add_remove, address); + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Transport now has %u addresses to communicate\n", + addresses); + GST_hello_modify_addresses (add_remove, address); } @@ -1770,45 +1779,45 @@ plugin_env_address_change_notification( * @param session which session is being destoyed */ static void -plugin_env_session_end(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +plugin_env_session_end (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { struct GNUNET_ATS_SessionKiller *sk; if (NULL == address) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } if (NULL == session) - { - GNUNET_break(0); - return; - } - GNUNET_assert(strlen(address->transport_name) > 0); + { + GNUNET_break (0); + return; + } + GNUNET_assert (strlen (address->transport_name) > 0); - GNUNET_log( + GNUNET_log ( GNUNET_ERROR_TYPE_DEBUG, "Notification from plugin about terminated session %p from peer `%s' address `%s'\n", session, - GNUNET_i2s(&address->peer), - GST_plugins_a2s(address)); + GNUNET_i2s (&address->peer), + GST_plugins_a2s (address)); - GST_neighbours_session_terminated(&address->peer, session); - GST_ats_del_session(address, session); - GST_blacklist_abort_matching(address, session); + GST_neighbours_session_terminated (&address->peer, session); + GST_ats_del_session (address, session); + GST_blacklist_abort_matching (address, session); for (sk = sk_head; NULL != sk; sk = sk->next) + { + if (sk->session == session) { - if (sk->session == session) - { - GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); - GNUNET_SCHEDULER_cancel(sk->task); - GNUNET_free(sk); - break; - } + GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); + GNUNET_SCHEDULER_cancel (sk->task); + GNUNET_free (sk); + break; } + } } @@ -1824,7 +1833,7 @@ plugin_env_session_end(void *cls, * @param result the result */ static void -plugin_env_session_start_bl_check_cont( +plugin_env_session_start_bl_check_cont ( void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, @@ -1832,19 +1841,19 @@ plugin_env_session_start_bl_check_cont( int result) { if (GNUNET_OK != result) - { - kill_session(address->transport_name, session); - return; - } + { + kill_session (address->transport_name, session); + return; + } if (GNUNET_YES != - GNUNET_HELLO_address_check_option(address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Informing verifier about inbound session's address `%s'\n", - GST_plugins_a2s(address)); - GST_validation_handle_address(address); - } + GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Informing verifier about inbound session's address `%s'\n", + GST_plugins_a2s (address)); + GST_validation_handle_address (address); + } } @@ -1857,49 +1866,49 @@ plugin_env_session_start_bl_check_cont( * @param scope network scope information */ static void -plugin_env_session_start(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - enum GNUNET_NetworkType scope) +plugin_env_session_start (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + enum GNUNET_NetworkType scope) { struct GNUNET_ATS_Properties prop; if (NULL == address) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } if (NULL == session) - { - GNUNET_break(0); - return; - } - GNUNET_log( + { + GNUNET_break (0); + return; + } + GNUNET_log ( GNUNET_ERROR_TYPE_INFO, "Notification from plugin `%s' about new session from peer `%s' address `%s'\n", address->transport_name, - GNUNET_i2s(&address->peer), - GST_plugins_a2s(address)); + GNUNET_i2s (&address->peer), + GST_plugins_a2s (address)); if (GNUNET_YES == - GNUNET_HELLO_address_check_option(address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)) - { - /* inbound is always new, but outbound MAY already be known, but - for example for UNIX, we have symmetric connections and thus we - may not know the address yet; add if necessary! */ - /* FIXME: maybe change API here so we just pass scope? */ - memset(&prop, 0, sizeof(prop)); - GNUNET_break(GNUNET_NT_UNSPECIFIED != scope); - prop.scope = scope; - GST_ats_add_inbound_address(address, session, &prop); - } + GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)) + { + /* inbound is always new, but outbound MAY already be known, but + for example for UNIX, we have symmetric connections and thus we + may not know the address yet; add if necessary! */ + /* FIXME: maybe change API here so we just pass scope? */ + memset (&prop, 0, sizeof(prop)); + GNUNET_break (GNUNET_NT_UNSPECIFIED != scope); + prop.scope = scope; + GST_ats_add_inbound_address (address, session, &prop); + } /* Do blacklist check if communication with this peer is allowed */ - (void)GST_blacklist_test_allowed(&address->peer, - address->transport_name, - &plugin_env_session_start_bl_check_cont, - NULL, - address, - session); + (void) GST_blacklist_test_allowed (&address->peer, + address->transport_name, + &plugin_env_session_start_bl_check_cont, + NULL, + address, + session); } @@ -1922,51 +1931,52 @@ plugin_env_session_start(void *cls, * @param ats_count number of @a ats elements */ static void -ats_request_address_change(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) +ats_request_address_change (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) { - uint32_t bw_in = ntohl(bandwidth_in.value__); - uint32_t bw_out = ntohl(bandwidth_out.value__); + uint32_t bw_in = ntohl (bandwidth_in.value__); + uint32_t bw_out = ntohl (bandwidth_out.value__); if (NULL == peer) - { - /* ATS service died, all suggestions become invalid! - (but we'll keep using the allocations for a little - while, to keep going while ATS restarts) */ - /* FIXME: We should drop all - connections now, as ATS won't explicitly tell - us and be unaware of ongoing resource allocations! */ - return; - } + { + /* ATS service died, all suggestions become invalid! + (but we'll keep using the allocations for a little + while, to keep going while ATS restarts) */ + /* FIXME: We should drop all + connections now, as ATS won't explicitly tell + us and be unaware of ongoing resource allocations! */ + return; + } /* ATS tells me to disconnect from peer */ if ((0 == bw_in) && (0 == bw_out)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "ATS tells me to disconnect from peer `%s'\n", - GNUNET_i2s(peer)); - GST_neighbours_force_disconnect(peer); - return; - } - GNUNET_assert(NULL != address); - GNUNET_STATISTICS_update(GST_stats, - "# ATS suggestions received", - 1, - GNUNET_NO); - GST_neighbours_switch_to_address(address, - session, - bandwidth_in, - bandwidth_out); + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "ATS tells me to disconnect from peer `%s'\n", + GNUNET_i2s (peer)); + GST_neighbours_force_disconnect (peer); + return; + } + GNUNET_assert (NULL != address); + GNUNET_STATISTICS_update (GST_stats, + "# ATS suggestions received", + 1, + GNUNET_NO); + GST_neighbours_switch_to_address (address, + session, + bandwidth_in, + bandwidth_out); } /** * Closure for #test_connection_ok(). */ -struct TestConnectionContext { +struct TestConnectionContext +{ /** * Is this the first neighbour we're checking? */ @@ -1991,19 +2001,19 @@ struct TestConnectionContext { * #GNUNET_NO if we must shutdown the connection */ static void -confirm_or_drop_neighbour(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - int allowed) +confirm_or_drop_neighbour (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + int allowed) { if (GNUNET_OK == allowed) return; /* we're done */ - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# disconnects due to blacklist"), - 1, - GNUNET_NO); - GST_neighbours_force_disconnect(peer); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# disconnects due to blacklist"), + 1, + GNUNET_NO); + GST_neighbours_force_disconnect (peer); } @@ -2020,31 +2030,31 @@ confirm_or_drop_neighbour(void *cls, * @param bandwidth_out bandwidth assigned outbound */ static void -test_connection_ok(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) +test_connection_ok (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { struct TestConnectionContext *tcc = cls; struct GST_BlacklistCheck *bc; - bc = GNUNET_new(struct GST_BlacklistCheck); - GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc); + bc = GNUNET_new (struct GST_BlacklistCheck); + GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); bc->peer = *peer; - bc->address = GNUNET_HELLO_address_copy(address); + bc->address = GNUNET_HELLO_address_copy (address); bc->cont = &confirm_or_drop_neighbour; bc->cont_cls = NULL; bc->bl_pos = tcc->tc; if (GNUNET_YES == tcc->first) - { - /* all would wait for the same client, no need to - * create more than just the first task right now */ - bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); - tcc->first = GNUNET_NO; - } + { + /* all would wait for the same client, no need to + * create more than just the first task right now */ + bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); + tcc->first = GNUNET_NO; + } } @@ -2057,26 +2067,26 @@ test_connection_ok(void *cls, * @param message the blacklist-init message that was sent */ static void -handle_client_blacklist_init(void *cls, - const struct GNUNET_MessageHeader *message) +handle_client_blacklist_init (void *cls, + const struct GNUNET_MessageHeader *message) { struct TransportClient *tc = cls; struct TestConnectionContext tcc; if (CT_NONE != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - GNUNET_SERVICE_client_mark_monitor(tc->client); + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + GNUNET_SERVICE_client_mark_monitor (tc->client); tc->type = CT_BLACKLIST; tc->details.blacklist.call_receive_done = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc); /* confirm that all existing connections are OK! */ tcc.tc = tc; tcc.first = GNUNET_YES; - GST_neighbours_iterate(&test_connection_ok, &tcc); + GST_neighbours_iterate (&test_connection_ok, &tcc); } @@ -2089,13 +2099,13 @@ handle_client_blacklist_init(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -free_blacklist_entry(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +free_blacklist_entry (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { char *be = value; - GNUNET_free_non_null(be); + GNUNET_free_non_null (be); return GNUNET_OK; } @@ -2107,12 +2117,12 @@ free_blacklist_entry(void *cls, * @param message containing information */ static void -handle_client_set_metric(void *cls, const struct TrafficMetricMessage *tm) +handle_client_set_metric (void *cls, const struct TrafficMetricMessage *tm) { struct TransportClient *tc = cls; - GST_manipulation_set_metric(tm); - GNUNET_SERVICE_client_continue(tc->client); + GST_manipulation_set_metric (tm); + GNUNET_SERVICE_client_continue (tc->client); } @@ -2123,58 +2133,58 @@ handle_client_set_metric(void *cls, const struct TrafficMetricMessage *tm) * @param cls closure, unused */ static void -shutdown_task(void *cls) +shutdown_task (void *cls) { struct AddressToStringContext *cur; - GST_neighbours_stop(); - GST_plugins_unload(); - GST_validation_stop(); - GST_ats_done(); - GNUNET_ATS_scheduling_done(GST_ats); + GST_neighbours_stop (); + GST_plugins_unload (); + GST_validation_stop (); + GST_ats_done (); + GNUNET_ATS_scheduling_done (GST_ats); GST_ats = NULL; - GNUNET_ATS_connectivity_done(GST_ats_connect); + GNUNET_ATS_connectivity_done (GST_ats_connect); GST_ats_connect = NULL; - GNUNET_NT_scanner_done(GST_is); + GNUNET_NT_scanner_done (GST_is); GST_is = NULL; while (NULL != (cur = a2s_head)) - { - GNUNET_CONTAINER_DLL_remove(a2s_head, a2s_tail, cur); - GNUNET_free(cur); - } + { + GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur); + GNUNET_free (cur); + } if (NULL != plugin_nc) - { - GNUNET_notification_context_destroy(plugin_nc); - plugin_nc = NULL; - } - GNUNET_CONTAINER_multipeermap_destroy(active_stccs); + { + GNUNET_notification_context_destroy (plugin_nc); + plugin_nc = NULL; + } + GNUNET_CONTAINER_multipeermap_destroy (active_stccs); active_stccs = NULL; if (NULL != blacklist) - { - GNUNET_CONTAINER_multipeermap_iterate(blacklist, - &free_blacklist_entry, - NULL); - GNUNET_CONTAINER_multipeermap_destroy(blacklist); - blacklist = NULL; - } - GST_hello_stop(); - GST_manipulation_stop(); + { + GNUNET_CONTAINER_multipeermap_iterate (blacklist, + &free_blacklist_entry, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (blacklist); + blacklist = NULL; + } + GST_hello_stop (); + GST_manipulation_stop (); if (NULL != GST_peerinfo) - { - GNUNET_PEERINFO_disconnect(GST_peerinfo); - GST_peerinfo = NULL; - } + { + GNUNET_PEERINFO_disconnect (GST_peerinfo); + GST_peerinfo = NULL; + } if (NULL != GST_stats) - { - GNUNET_STATISTICS_destroy(GST_stats, GNUNET_NO); - GST_stats = NULL; - } + { + GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); + GST_stats = NULL; + } if (NULL != GST_my_private_key) - { - GNUNET_free(GST_my_private_key); - GST_my_private_key = NULL; - } + { + GNUNET_free (GST_my_private_key); + GST_my_private_key = NULL; + } } @@ -2184,7 +2194,7 @@ shutdown_task(void *cls) * @param cls the `struct GST_BlacklistCheck *` */ static void -do_blacklist_check(void *cls) +do_blacklist_check (void *cls) { struct GST_BlacklistCheck *bc = cls; struct TransportClient *tc; @@ -2193,34 +2203,34 @@ do_blacklist_check(void *cls) bc->task = NULL; while (NULL != (tc = bc->bl_pos)) - { - if (CT_BLACKLIST == tc->type) - break; - bc->bl_pos = tc->next; - } + { + if (CT_BLACKLIST == tc->type) + break; + bc->bl_pos = tc->next; + } if (NULL == tc) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "No other blacklist clients active, will allow neighbour `%s'\n", - GNUNET_i2s(&bc->peer)); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "No other blacklist clients active, will allow neighbour `%s'\n", + GNUNET_i2s (&bc->peer)); - bc->cont(bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK); - GST_blacklist_test_cancel(bc); - return; - } + bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK); + GST_blacklist_test_cancel (bc); + return; + } if ((NULL != tc->details.blacklist.bc) || (GNUNET_NO != tc->details.blacklist.waiting_for_reply)) return; /* someone else busy with this client */ tc->details.blacklist.bc = bc; - env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY); - bm->is_allowed = htonl(0); + env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY); + bm->is_allowed = htonl (0); bm->peer = bc->peer; - GNUNET_MQ_send(tc->mq, env); + GNUNET_MQ_send (tc->mq, env); if (GNUNET_YES == tc->details.blacklist.call_receive_done) - { - tc->details.blacklist.call_receive_done = GNUNET_NO; - GNUNET_SERVICE_client_continue(tc->client); - } + { + tc->details.blacklist.call_receive_done = GNUNET_NO; + GNUNET_SERVICE_client_continue (tc->client); + } tc->details.blacklist.waiting_for_reply = GNUNET_YES; } @@ -2232,62 +2242,62 @@ do_blacklist_check(void *cls) * @param msg the blacklist-reply message that was sent */ static void -handle_client_blacklist_reply(void *cls, const struct BlacklistMessage *msg) +handle_client_blacklist_reply (void *cls, const struct BlacklistMessage *msg) { struct TransportClient *tc = cls; struct GST_BlacklistCheck *bc; if (CT_BLACKLIST != tc->type) - { - GNUNET_break(0); - GNUNET_SERVICE_client_drop(tc->client); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Blacklist client %p sent reply for `%s'\n", - tc, - GNUNET_i2s(&msg->peer)); + { + GNUNET_break (0); + GNUNET_SERVICE_client_drop (tc->client); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Blacklist client %p sent reply for `%s'\n", + tc, + GNUNET_i2s (&msg->peer)); bc = tc->details.blacklist.bc; tc->details.blacklist.bc = NULL; tc->details.blacklist.waiting_for_reply = GNUNET_NO; tc->details.blacklist.call_receive_done = GNUNET_YES; if (NULL != bc) + { + /* only run this if the blacklist check has not been + * cancelled in the meantime... */ + GNUNET_assert (bc->bl_pos == tc); + if (ntohl (msg->is_allowed) == GNUNET_SYSERR) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Blacklist check failed, peer not allowed\n"); + /* For the duration of the continuation, make the ongoing + check invisible (to avoid double-cancellation); then + add it back again so we can re-use GST_blacklist_test_cancel() */ + GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); + bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_NO); + GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); + GST_blacklist_test_cancel (bc); + tc->details.blacklist.call_receive_done = GNUNET_NO; + GNUNET_SERVICE_client_continue (tc->client); + return; + } + else { - /* only run this if the blacklist check has not been - * cancelled in the meantime... */ - GNUNET_assert(bc->bl_pos == tc); - if (ntohl(msg->is_allowed) == GNUNET_SYSERR) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Blacklist check failed, peer not allowed\n"); - /* For the duration of the continuation, make the ongoing - check invisible (to avoid double-cancellation); then - add it back again so we can re-use GST_blacklist_test_cancel() */ - GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc); - bc->cont(bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_NO); - GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc); - GST_blacklist_test_cancel(bc); - tc->details.blacklist.call_receive_done = GNUNET_NO; - GNUNET_SERVICE_client_continue(tc->client); - return; - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Blacklist check succeeded, continuing with checks\n"); - tc->details.blacklist.call_receive_done = GNUNET_NO; - GNUNET_SERVICE_client_continue(tc->client); - bc->bl_pos = tc->next; - bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); - } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Blacklist check succeeded, continuing with checks\n"); + tc->details.blacklist.call_receive_done = GNUNET_NO; + GNUNET_SERVICE_client_continue (tc->client); + bc->bl_pos = tc->next; + bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); } + } /* check if any other blacklist checks are waiting for this blacklister */ for (bc = bc_head; bc != NULL; bc = bc->next) if ((bc->bl_pos == tc) && (NULL == bc->task)) - { - bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); - break; - } + { + bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); + break; + } } @@ -2298,32 +2308,32 @@ handle_client_blacklist_reply(void *cls, const struct BlacklistMessage *msg) * @param transport_name transport to blacklist for this peer, NULL for all */ void -GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer, - const char *transport_name) +GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, + const char *transport_name) { char *transport = NULL; if (NULL != transport_name) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Adding peer `%s' with plugin `%s' to blacklist\n", - GNUNET_i2s(peer), - transport_name); - transport = GNUNET_strdup(transport_name); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Adding peer `%s' with plugin `%s' to blacklist\n", + GNUNET_i2s (peer), + transport_name); + transport = GNUNET_strdup (transport_name); + } else - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Adding peer `%s' with all plugins to blacklist\n", - GNUNET_i2s(peer)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Adding peer `%s' with all plugins to blacklist\n", + GNUNET_i2s (peer)); if (NULL == blacklist) blacklist = - GNUNET_CONTAINER_multipeermap_create(TRANSPORT_BLACKLIST_HT_SIZE, - GNUNET_NO); + GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE, + GNUNET_NO); - GNUNET_CONTAINER_multipeermap_put(blacklist, - peer, - transport, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_CONTAINER_multipeermap_put (blacklist, + peer, + transport, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); } @@ -2334,27 +2344,27 @@ GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer, * @param session session used to abort matching checks */ void -GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { struct GST_BlacklistCheck *bc; struct GST_BlacklistCheck *n; n = bc_head; while (NULL != (bc = n)) + { + n = bc->next; + if ((bc->session == session) && + (0 == GNUNET_HELLO_address_cmp (bc->address, address))) { - n = bc->next; - if ((bc->session == session) && - (0 == GNUNET_HELLO_address_cmp(bc->address, address))) - { - bc->cont(bc->cont_cls, - &bc->peer, - bc->address, - bc->session, - GNUNET_SYSERR); - GST_blacklist_test_cancel(bc); - } + bc->cont (bc->cont_cls, + &bc->peer, + bc->address, + bc->session, + GNUNET_SYSERR); + GST_blacklist_test_cancel (bc); } + } } @@ -2368,7 +2378,7 @@ GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address, * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches */ static int -test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value) +test_blacklisted (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { const char *transport_name = cls; char *be = value; @@ -2382,21 +2392,21 @@ test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value) * */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n", - GNUNET_i2s(key), - (NULL == transport_name) ? "unspecified" : transport_name, - (NULL == be) ? "all plugins" : be); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n", + GNUNET_i2s (key), + (NULL == transport_name) ? "unspecified" : transport_name, + (NULL == be) ? "all plugins" : be); /* all plugins for this peer were blacklisted: disallow */ if (NULL == value) return GNUNET_NO; /* blacklist check for specific transport */ if ((NULL != transport_name) && (NULL != value)) - { - if (0 == strcmp(transport_name, be)) - return GNUNET_NO; /* plugin is blacklisted! */ - } + { + if (0 == strcmp (transport_name, be)) + return GNUNET_NO; /* plugin is blacklisted! */ + } return GNUNET_OK; } @@ -2414,70 +2424,70 @@ test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value) * was made instantly and @a cont was already called */ struct GST_BlacklistCheck * -GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer, - const char *transport_name, - GST_BlacklistTestContinuation cont, - void *cont_cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, + const char *transport_name, + GST_BlacklistTestContinuation cont, + void *cont_cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { struct GST_BlacklistCheck *bc; struct TransportClient *tc; - GNUNET_assert(NULL != peer); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Blacklist check for peer `%s':%s\n", - GNUNET_i2s(peer), - (NULL != transport_name) ? transport_name : "unspecified"); + GNUNET_assert (NULL != peer); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Blacklist check for peer `%s':%s\n", + GNUNET_i2s (peer), + (NULL != transport_name) ? transport_name : "unspecified"); /* Check local blacklist by iterating over hashmap * If iteration is aborted, we found a matching blacklist entry */ if ((NULL != blacklist) && (GNUNET_SYSERR == - GNUNET_CONTAINER_multipeermap_get_multiple(blacklist, - peer, - &test_blacklisted, - (void *)transport_name))) - { - /* Disallowed by config, disapprove instantly */ - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# disconnects due to blacklist"), - 1, - GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Disallowing connection to peer `%s' on transport %s\n"), - GNUNET_i2s(peer), - (NULL != transport_name) ? transport_name : "unspecified"); - if (NULL != cont) - cont(cont_cls, peer, address, session, GNUNET_NO); - return NULL; - } + GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, + peer, + &test_blacklisted, + (void *) transport_name))) + { + /* Disallowed by config, disapprove instantly */ + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# disconnects due to blacklist"), + 1, + GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Disallowing connection to peer `%s' on transport %s\n"), + GNUNET_i2s (peer), + (NULL != transport_name) ? transport_name : "unspecified"); + if (NULL != cont) + cont (cont_cls, peer, address, session, GNUNET_NO); + return NULL; + } for (tc = clients_head; NULL != tc; tc = tc->next) if (CT_BLACKLIST == tc->type) break; if (NULL == tc) - { - /* no blacklist clients, approve instantly */ - if (NULL != cont) - cont(cont_cls, peer, address, session, GNUNET_OK); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Allowing connection to peer `%s' %s\n", - GNUNET_i2s(peer), - (NULL != transport_name) ? transport_name : ""); - return NULL; - } + { + /* no blacklist clients, approve instantly */ + if (NULL != cont) + cont (cont_cls, peer, address, session, GNUNET_OK); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Allowing connection to peer `%s' %s\n", + GNUNET_i2s (peer), + (NULL != transport_name) ? transport_name : ""); + return NULL; + } /* need to query blacklist clients */ - bc = GNUNET_new(struct GST_BlacklistCheck); - GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc); + bc = GNUNET_new (struct GST_BlacklistCheck); + GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); bc->peer = *peer; - bc->address = GNUNET_HELLO_address_copy(address); + bc->address = GNUNET_HELLO_address_copy (address); bc->session = session; bc->cont = cont; bc->cont_cls = cont_cls; bc->bl_pos = tc; - bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); + bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); return bc; } @@ -2488,25 +2498,25 @@ GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer, * @param bc check to cancel */ void -GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc) +GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc) { - GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc); + GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); if (NULL != bc->bl_pos) + { + if ((CT_BLACKLIST == bc->bl_pos->type) && + (bc->bl_pos->details.blacklist.bc == bc)) { - if ((CT_BLACKLIST == bc->bl_pos->type) && - (bc->bl_pos->details.blacklist.bc == bc)) - { - /* we're at the head of the queue, remove us! */ - bc->bl_pos->details.blacklist.bc = NULL; - } + /* we're at the head of the queue, remove us! */ + bc->bl_pos->details.blacklist.bc = NULL; } + } if (NULL != bc->task) - { - GNUNET_SCHEDULER_cancel(bc->task); - bc->task = NULL; - } - GNUNET_free_non_null(bc->address); - GNUNET_free(bc); + { + GNUNET_SCHEDULER_cancel (bc->task); + bc->task = NULL; + } + GNUNET_free_non_null (bc->address); + GNUNET_free (bc); } @@ -2519,10 +2529,10 @@ GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc) * @param value value of the option */ static void -blacklist_cfg_iter(void *cls, - const char *section, - const char *option, - const char *value) +blacklist_cfg_iter (void *cls, + const char *section, + const char *option, + const char *value) { unsigned int *res = cls; struct GNUNET_PeerIdentity peer; @@ -2530,32 +2540,32 @@ blacklist_cfg_iter(void *cls, char *pos; if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_public_key_from_string(option, - strlen(option), - &peer.public_key)) + GNUNET_CRYPTO_eddsa_public_key_from_string (option, + strlen (option), + &peer.public_key)) return; - if ((NULL == value) || (0 == strcmp(value, ""))) - { - /* Blacklist whole peer */ - GST_blacklist_add_peer(&peer, NULL); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Adding blacklisting entry for peer `%s'\n"), - GNUNET_i2s(&peer)); - } + if ((NULL == value) || (0 == strcmp (value, ""))) + { + /* Blacklist whole peer */ + GST_blacklist_add_peer (&peer, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Adding blacklisting entry for peer `%s'\n"), + GNUNET_i2s (&peer)); + } else + { + plugs = GNUNET_strdup (value); + for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " ")) { - plugs = GNUNET_strdup(value); - for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " ")) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Adding blacklisting entry for peer `%s':`%s'\n"), - GNUNET_i2s(&peer), - pos); - GST_blacklist_add_peer(&peer, pos); - } - GNUNET_free(plugs); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Adding blacklisting entry for peer `%s':`%s'\n"), + GNUNET_i2s (&peer), + pos); + GST_blacklist_add_peer (&peer, pos); } + GNUNET_free (plugs); + } (*res)++; } @@ -2567,23 +2577,23 @@ blacklist_cfg_iter(void *cls, * @param my_id my peer identity */ static void -read_blacklist_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_PeerIdentity *my_id) +read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *my_id) { char cfg_sect[512]; unsigned int res = 0; - GNUNET_snprintf(cfg_sect, - sizeof(cfg_sect), - "transport-blacklist-%s", - GNUNET_i2s_full(my_id)); - GNUNET_CONFIGURATION_iterate_section_values(cfg, - cfg_sect, - &blacklist_cfg_iter, - &res); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Loaded %u blacklisting entries from configuration\n", - res); + GNUNET_snprintf (cfg_sect, + sizeof(cfg_sect), + "transport-blacklist-%s", + GNUNET_i2s_full (my_id)); + GNUNET_CONFIGURATION_iterate_section_values (cfg, + cfg_sect, + &blacklist_cfg_iter, + &res); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Loaded %u blacklisting entries from configuration\n", + res); } @@ -2595,9 +2605,9 @@ read_blacklist_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg, * @param service the initialized service */ static void -run(void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_SERVICE_Handle *service) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_SERVICE_Handle *service) { char *keyfile; struct GNUNET_CRYPTO_EddsaPrivateKey *pk; @@ -2608,70 +2618,70 @@ run(void *cls, /* setup globals */ GST_cfg = c; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c, - "PEER", - "PRIVATE_KEY", - &keyfile)) - { - GNUNET_log( - GNUNET_ERROR_TYPE_ERROR, - _( - "Transport service is lacking key configuration settings. Exiting.\n")); - GNUNET_SCHEDULER_shutdown(); - return; - } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(c, - "transport", - "HELLO_EXPIRATION", - &hello_expiration)) - { - hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; - } - pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); - GNUNET_free(keyfile); - GNUNET_assert(NULL != pk); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, + "PEER", + "PRIVATE_KEY", + &keyfile)) + { + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + _ ( + "Transport service is lacking key configuration settings. Exiting.\n")); + GNUNET_SCHEDULER_shutdown (); + return; + } + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (c, + "transport", + "HELLO_EXPIRATION", + &hello_expiration)) + { + hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; + } + pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); + GNUNET_free (keyfile); + GNUNET_assert (NULL != pk); GST_my_private_key = pk; - GST_stats = GNUNET_STATISTICS_create("transport", GST_cfg); - GST_peerinfo = GNUNET_PEERINFO_connect(GST_cfg); - GNUNET_CRYPTO_eddsa_key_get_public(GST_my_private_key, - &GST_my_identity.public_key); - GNUNET_assert(NULL != GST_my_private_key); + GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); + GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg); + GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, + &GST_my_identity.public_key); + GNUNET_assert (NULL != GST_my_private_key); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "My identity is `%s'\n", - GNUNET_i2s_full(&GST_my_identity)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "My identity is `%s'\n", + GNUNET_i2s_full (&GST_my_identity)); - GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); if (NULL == GST_peerinfo) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Could not access PEERINFO service. Exiting.\n")); - GNUNET_SCHEDULER_shutdown(); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Could not access PEERINFO service. Exiting.\n")); + GNUNET_SCHEDULER_shutdown (); + return; + } max_fd_rlimit = 0; #if HAVE_GETRLIMIT { struct rlimit r_file; - if (0 == getrlimit(RLIMIT_NOFILE, &r_file)) - { - max_fd_rlimit = r_file.rlim_cur; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Maximum number of open files was: %u/%u\n", - (unsigned int)r_file.rlim_cur, - (unsigned int)r_file.rlim_max); - } + if (0 == getrlimit (RLIMIT_NOFILE, &r_file)) + { + max_fd_rlimit = r_file.rlim_cur; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Maximum number of open files was: %u/%u\n", + (unsigned int) r_file.rlim_cur, + (unsigned int) r_file.rlim_max); + } max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ } #endif - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(GST_cfg, - "transport", - "MAX_FD", - &max_fd_cfg)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (GST_cfg, + "transport", + "MAX_FD", + &max_fd_cfg)) max_fd_cfg = max_fd_rlimit; if (max_fd_cfg > max_fd_rlimit) @@ -2681,14 +2691,14 @@ run(void *cls, if (max_fd < DEFAULT_MAX_FDS) max_fd = DEFAULT_MAX_FDS; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Limiting number of sockets to %u: validation %u, neighbors: %u\n", - max_fd, - (max_fd / 3), - (max_fd / 3) * 2); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Limiting number of sockets to %u: validation %u, neighbors: %u\n", + max_fd, + (max_fd / 3), + (max_fd / 3) * 2); friend_only = - GNUNET_CONFIGURATION_get_value_yesno(GST_cfg, "topology", "FRIENDS-ONLY"); + GNUNET_CONFIGURATION_get_value_yesno (GST_cfg, "topology", "FRIENDS-ONLY"); if (GNUNET_SYSERR == friend_only) friend_only = GNUNET_NO; /* According to topology defaults */ /* start subsystems */ @@ -2697,79 +2707,79 @@ run(void *cls, struct GNUNET_PeerIdentity dstj; const char *ds = "DSTJBRRKZ8TBW3FGK6B0M5QXWT9WYNZ45H5MCV4HY7ST64Q8T9F0"; - GNUNET_assert( + GNUNET_assert ( GNUNET_OK == - GNUNET_CRYPTO_eddsa_public_key_from_string(ds, - strlen(ds), - &dstj.public_key)); - GST_blacklist_add_peer(&dstj, NULL); - } - read_blacklist_configuration(GST_cfg, &GST_my_identity); - GST_is = GNUNET_NT_scanner_init(); - GST_ats_connect = GNUNET_ATS_connectivity_init(GST_cfg); + GNUNET_CRYPTO_eddsa_public_key_from_string (ds, + strlen (ds), + &dstj.public_key)); + GST_blacklist_add_peer (&dstj, NULL); + } + read_blacklist_configuration (GST_cfg, &GST_my_identity); + GST_is = GNUNET_NT_scanner_init (); + GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg); GST_ats = - GNUNET_ATS_scheduling_init(GST_cfg, &ats_request_address_change, NULL); - GST_ats_init(); - GST_manipulation_init(); - GST_plugins_load(&GST_manipulation_recv, - &plugin_env_address_change_notification, - &plugin_env_session_start, - &plugin_env_session_end); - GST_hello_start(friend_only, &process_hello_update, NULL); - GST_neighbours_start((max_fd / 3) * 2); - active_stccs = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); - plugin_nc = GNUNET_notification_context_create(0); - GST_validation_start((max_fd / 3)); + GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); + GST_ats_init (); + GST_manipulation_init (); + GST_plugins_load (&GST_manipulation_recv, + &plugin_env_address_change_notification, + &plugin_env_session_start, + &plugin_env_session_end); + GST_hello_start (friend_only, &process_hello_update, NULL); + GST_neighbours_start ((max_fd / 3) * 2); + active_stccs = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); + plugin_nc = GNUNET_notification_context_create (0); + GST_validation_start ((max_fd / 3)); } /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN( +GNUNET_SERVICE_MAIN ( "transport", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, - GNUNET_MQ_hd_fixed_size(client_start, - GNUNET_MESSAGE_TYPE_TRANSPORT_START, - struct StartMessage, - NULL), - GNUNET_MQ_hd_var_size(client_hello, - GNUNET_MESSAGE_TYPE_HELLO, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_var_size(client_send, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, - struct OutboundMessage, - NULL), - GNUNET_MQ_hd_var_size(client_address_to_string, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, - struct AddressLookupMessage, - NULL), - GNUNET_MQ_hd_fixed_size(client_monitor_peers, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, - struct PeerMonitorMessage, - NULL), - GNUNET_MQ_hd_fixed_size(client_blacklist_init, - GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size(client_blacklist_reply, - GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, - struct BlacklistMessage, - NULL), - GNUNET_MQ_hd_fixed_size(client_set_metric, - GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, - struct TrafficMetricMessage, - NULL), - GNUNET_MQ_hd_fixed_size(client_monitor_plugins, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_handler_end()); + GNUNET_MQ_hd_fixed_size (client_start, + GNUNET_MESSAGE_TYPE_TRANSPORT_START, + struct StartMessage, + NULL), + GNUNET_MQ_hd_var_size (client_hello, + GNUNET_MESSAGE_TYPE_HELLO, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_var_size (client_send, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, + struct OutboundMessage, + NULL), + GNUNET_MQ_hd_var_size (client_address_to_string, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, + struct AddressLookupMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_monitor_peers, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, + struct PeerMonitorMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_blacklist_init, + GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size (client_blacklist_reply, + GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, + struct BlacklistMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_set_metric, + GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, + struct TrafficMetricMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_monitor_plugins, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_handler_end ()); /* end of file gnunet-service-transport.c */ diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h index fb42f1fae..3c2ca5a08 100644 --- a/src/transport/gnunet-service-transport.h +++ b/src/transport/gnunet-service-transport.h @@ -83,12 +83,18 @@ extern struct GNUNET_NT_InterfaceScanner *GST_is; */ typedef void (*GNUNET_TRANSPORT_NeighbourChangeCallback) (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); + const struct + GNUNET_PeerIdentity *peer, + const struct + GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState + state, + struct GNUNET_TIME_Absolute + state_timeout, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_out); /** @@ -117,8 +123,8 @@ typedef void * @param transport_name transport to blacklist for this peer, NULL for all */ void -GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer, - const char *transport_name); +GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, + const char *transport_name); /** @@ -141,12 +147,12 @@ struct GST_BlacklistCheck; * was made instantly and @a cont was already called */ struct GST_BlacklistCheck * -GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer, - const char *transport_name, - GST_BlacklistTestContinuation cont, - void *cont_cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session); +GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, + const char *transport_name, + GST_BlacklistTestContinuation cont, + void *cont_cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session); /** @@ -156,8 +162,8 @@ GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer, * @param session session used to abort matching checks */ void -GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session); +GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session); /** * Cancel a blacklist check. @@ -165,7 +171,7 @@ GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address, * @param bc check to cancel */ void -GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc); +GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc); /** @@ -182,10 +188,10 @@ GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc); * (plugins that do not support this, can ignore the return value) */ struct GNUNET_TIME_Relative -GST_receive_callback(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - const struct GNUNET_MessageHeader *message); +GST_receive_callback (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + const struct GNUNET_MessageHeader *message); /** * Broadcast the given message to all of our clients. @@ -194,8 +200,8 @@ GST_receive_callback(void *cls, * @param may_drop #GNUNET_YES if the message can be dropped / is payload */ void -GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, - int may_drop); +GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, + int may_drop); /** @@ -207,10 +213,12 @@ GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, * @param state_timeout the time out for the state */ void -GST_clients_broadcast_peer_notification(const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout); +GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer, + const struct + GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute + state_timeout); /** @@ -220,7 +228,7 @@ GST_clients_broadcast_peer_notification(const struct GNUNET_PeerIdentity *peer, * @param peer peer that disconnected */ void -GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer); +GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer); diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c index 555302813..9c262dbdf 100644 --- a/src/transport/gnunet-service-transport_ats.c +++ b/src/transport/gnunet-service-transport_ats.c @@ -32,13 +32,14 @@ /** * Log convenience function. */ -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-ats", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-ats", __VA_ARGS__) /** * Information we track for each address known to ATS. */ -struct AddressInfo { +struct AddressInfo +{ /** * The address (with peer identity). Must never change * while this struct is in the #p2a map. @@ -105,7 +106,8 @@ static unsigned int num_blocked; /** * Closure for #find_ai_cb() and #find_ai_no_session_cb(). */ -struct FindClosure { +struct FindClosure +{ /** * Session to look for (only used if the address is inbound). */ @@ -129,16 +131,16 @@ struct FindClosure { * is changed. */ static void -publish_p2a_stat_update() +publish_p2a_stat_update () { - GNUNET_STATISTICS_set(GST_stats, - gettext_noop("# Addresses given to ATS"), - GNUNET_CONTAINER_multipeermap_size(p2a) - num_blocked, - GNUNET_NO); - GNUNET_STATISTICS_set(GST_stats, - "# blocked addresses", - num_blocked, - GNUNET_NO); + GNUNET_STATISTICS_set (GST_stats, + gettext_noop ("# Addresses given to ATS"), + GNUNET_CONTAINER_multipeermap_size (p2a) - num_blocked, + GNUNET_NO); + GNUNET_STATISTICS_set (GST_stats, + "# blocked addresses", + num_blocked, + GNUNET_NO); } @@ -153,21 +155,21 @@ publish_p2a_stat_update() * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value */ static int -find_ai_cb(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +find_ai_cb (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct FindClosure *fc = cls; struct AddressInfo *ai = value; if ((0 == - GNUNET_HELLO_address_cmp(fc->address, - ai->address)) && + GNUNET_HELLO_address_cmp (fc->address, + ai->address)) && (fc->session == ai->session)) - { - fc->ret = ai; - return GNUNET_NO; - } + { + fc->ret = ai; + return GNUNET_NO; + } return GNUNET_YES; } @@ -181,18 +183,18 @@ find_ai_cb(void *cls, * @return NULL if this combination is unknown */ static struct AddressInfo * -find_ai(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +find_ai (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { struct FindClosure fc; fc.address = address; fc.session = session; fc.ret = NULL; - GNUNET_CONTAINER_multipeermap_get_multiple(p2a, - &address->peer, - &find_ai_cb, - &fc); + GNUNET_CONTAINER_multipeermap_get_multiple (p2a, + &address->peer, + &find_ai_cb, + &fc); return fc.ret; } @@ -207,9 +209,9 @@ find_ai(const struct GNUNET_HELLO_Address *address, * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value */ static int -find_ai_no_session_cb(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +find_ai_no_session_cb (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct FindClosure *fc = cls; struct AddressInfo *ai = value; @@ -217,12 +219,12 @@ find_ai_no_session_cb(void *cls, if (ai->expired) return GNUNET_YES; /* expired do not count here */ if (0 == - GNUNET_HELLO_address_cmp(fc->address, - ai->address)) - { - fc->ret = ai; - return GNUNET_NO; - } + GNUNET_HELLO_address_cmp (fc->address, + ai->address)) + { + fc->ret = ai; + return GNUNET_NO; + } return GNUNET_YES; } @@ -235,17 +237,17 @@ find_ai_no_session_cb(void *cls, * @return NULL if this combination is unknown */ static struct AddressInfo * -find_ai_no_session(const struct GNUNET_HELLO_Address *address) +find_ai_no_session (const struct GNUNET_HELLO_Address *address) { struct FindClosure fc; fc.address = address; fc.session = NULL; fc.ret = NULL; - GNUNET_CONTAINER_multipeermap_get_multiple(p2a, - &address->peer, - &find_ai_no_session_cb, - &fc); + GNUNET_CONTAINER_multipeermap_get_multiple (p2a, + &address->peer, + &find_ai_no_session_cb, + &fc); return fc.ret; } @@ -260,10 +262,10 @@ find_ai_no_session(const struct GNUNET_HELLO_Address *address) * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not. */ int -GST_ats_is_known(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +GST_ats_is_known (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { - return (NULL != find_ai(address, session)) ? GNUNET_YES : GNUNET_NO; + return (NULL != find_ai (address, session)) ? GNUNET_YES : GNUNET_NO; } @@ -275,9 +277,9 @@ GST_ats_is_known(const struct GNUNET_HELLO_Address *address, * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not. */ int -GST_ats_is_known_no_session(const struct GNUNET_HELLO_Address *address) +GST_ats_is_known_no_session (const struct GNUNET_HELLO_Address *address) { - return (NULL != find_ai_no_session(address)) + return (NULL != find_ai_no_session (address)) ? GNUNET_YES : GNUNET_NO; } @@ -290,22 +292,22 @@ GST_ats_is_known_no_session(const struct GNUNET_HELLO_Address *address) * @param cls the `struct AddressInfo` of the address to unblock */ static void -unblock_address(void *cls) +unblock_address (void *cls) { struct AddressInfo *ai = cls; ai->unblock_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Unblocking address %s of peer %s\n", - GST_plugins_a2s(ai->address), - GNUNET_i2s(&ai->address->peer)); - ai->ar = GNUNET_ATS_address_add(GST_ats, - ai->address, - ai->session, - &ai->properties); - GNUNET_break(NULL != ai->ar); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Unblocking address %s of peer %s\n", + GST_plugins_a2s (ai->address), + GNUNET_i2s (&ai->address->peer)); + ai->ar = GNUNET_ATS_address_add (GST_ats, + ai->address, + ai->session, + &ai->properties); + GNUNET_break (NULL != ai->ar); num_blocked--; - publish_p2a_stat_update(); + publish_p2a_stat_update (); } @@ -319,47 +321,47 @@ unblock_address(void *cls) * @param session the session (can be NULL) */ void -GST_ats_block_address(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +GST_ats_block_address (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { struct AddressInfo *ai; if (0 == - memcmp(&GST_my_identity, - &address->peer, - sizeof(struct GNUNET_PeerIdentity))) + memcmp (&GST_my_identity, + &address->peer, + sizeof(struct GNUNET_PeerIdentity))) return; /* our own, ignore! */ - ai = find_ai(address, - session); - if (NULL == ai || NULL == ai->ar) - { - /* The address is already gone/blocked, this can happen during a blacklist - * callback. */ - return; - } - ai->back_off = GNUNET_TIME_STD_BACKOFF(ai->back_off); + ai = find_ai (address, + session); + if ((NULL == ai)||(NULL == ai->ar)) + { + /* The address is already gone/blocked, this can happen during a blacklist + * callback. */ + return; + } + ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off); if (GNUNET_YES == - GNUNET_HELLO_address_check_option(address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)) - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Removing address %s of peer %s from use (inbound died)\n", - GST_plugins_a2s(address), - GNUNET_i2s(&address->peer)); + GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)) + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Removing address %s of peer %s from use (inbound died)\n", + GST_plugins_a2s (address), + GNUNET_i2s (&address->peer)); else - LOG(GNUNET_ERROR_TYPE_INFO, - "Blocking address %s of peer %s from use for %s\n", - GST_plugins_a2s(address), - GNUNET_i2s(&address->peer), - GNUNET_STRINGS_relative_time_to_string(ai->back_off, - GNUNET_YES)); + LOG (GNUNET_ERROR_TYPE_INFO, + "Blocking address %s of peer %s from use for %s\n", + GST_plugins_a2s (address), + GNUNET_i2s (&address->peer), + GNUNET_STRINGS_relative_time_to_string (ai->back_off, + GNUNET_YES)); /* destroy session and address */ if ((NULL == session) || (GNUNET_NO == - GNUNET_ATS_address_del_session(ai->ar, - session))) - { - GNUNET_ATS_address_destroy(ai->ar); - } + GNUNET_ATS_address_del_session (ai->ar, + session))) + { + GNUNET_ATS_address_destroy (ai->ar); + } /* "ar" has been freed, regardless how the branch above played out: it was either freed in #GNUNET_ATS_address_del_session() because it was @@ -368,12 +370,12 @@ GST_ats_block_address(const struct GNUNET_HELLO_Address *address, ai->ar = NULL; /* determine when the address should come back to life */ - ai->blocked = GNUNET_TIME_relative_to_absolute(ai->back_off); - ai->unblock_task = GNUNET_SCHEDULER_add_delayed(ai->back_off, - &unblock_address, - ai); + ai->blocked = GNUNET_TIME_relative_to_absolute (ai->back_off); + ai->unblock_task = GNUNET_SCHEDULER_add_delayed (ai->back_off, + &unblock_address, + ai); num_blocked++; - publish_p2a_stat_update(); + publish_p2a_stat_update (); } @@ -386,24 +388,24 @@ GST_ats_block_address(const struct GNUNET_HELLO_Address *address, * @param session the session (can be NULL) */ void -GST_ats_block_reset(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +GST_ats_block_reset (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { struct AddressInfo *ai; if (0 == - memcmp(&GST_my_identity, - &address->peer, - sizeof(struct GNUNET_PeerIdentity))) + memcmp (&GST_my_identity, + &address->peer, + sizeof(struct GNUNET_PeerIdentity))) return; /* our own, ignore! */ - ai = find_ai(address, session); + ai = find_ai (address, session); if (NULL == ai) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } /* address is in successful use, so it should not be blocked right now */ - GNUNET_break(NULL == ai->unblock_task); + GNUNET_break (NULL == ai->unblock_task); ai->back_off = GNUNET_TIME_UNIT_ZERO; } @@ -419,60 +421,60 @@ GST_ats_block_reset(const struct GNUNET_HELLO_Address *address, * @param prop performance information */ void -GST_ats_add_inbound_address(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - const struct GNUNET_ATS_Properties *prop) +GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + const struct GNUNET_ATS_Properties *prop) { struct GNUNET_ATS_AddressRecord *ar; struct AddressInfo *ai; if (0 == - memcmp(&GST_my_identity, - &address->peer, - sizeof(struct GNUNET_PeerIdentity))) + memcmp (&GST_my_identity, + &address->peer, + sizeof(struct GNUNET_PeerIdentity))) return; /* our own, ignore! */ /* Sanity checks for a valid inbound address */ if (NULL == address->transport_name) - { - GNUNET_break(0); - return; - } - GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); - GNUNET_assert(GNUNET_YES == - GNUNET_HELLO_address_check_option(address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)); - GNUNET_assert(NULL != session); - ai = find_ai(address, session); + { + GNUNET_break (0); + return; + } + GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); + GNUNET_assert (GNUNET_YES == + GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)); + GNUNET_assert (NULL != session); + ai = find_ai (address, session); if (NULL != ai) - { - /* This should only be called for new sessions, and thus - we should not already have the address */ - GNUNET_break(0); - return; - } + { + /* This should only be called for new sessions, and thus + we should not already have the address */ + GNUNET_break (0); + return; + } /* Is indeed new, let's tell ATS */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Notifying ATS about peer `%s''s new inbound address `%s' session %p in network %s\n", - GNUNET_i2s(&address->peer), - GST_plugins_a2s(address), - session, - GNUNET_NT_to_string(prop->scope)); - ar = GNUNET_ATS_address_add(GST_ats, - address, - session, - prop); - GNUNET_assert(NULL != ar); - ai = GNUNET_new(struct AddressInfo); - ai->address = GNUNET_HELLO_address_copy(address); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Notifying ATS about peer `%s''s new inbound address `%s' session %p in network %s\n", + GNUNET_i2s (&address->peer), + GST_plugins_a2s (address), + session, + GNUNET_NT_to_string (prop->scope)); + ar = GNUNET_ATS_address_add (GST_ats, + address, + session, + prop); + GNUNET_assert (NULL != ar); + ai = GNUNET_new (struct AddressInfo); + ai->address = GNUNET_HELLO_address_copy (address); ai->session = session; ai->properties = *prop; ai->ar = ar; - (void)GNUNET_CONTAINER_multipeermap_put(p2a, - &ai->address->peer, - ai, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - publish_p2a_stat_update(); + (void) GNUNET_CONTAINER_multipeermap_put (p2a, + &ai->address->peer, + ai, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + publish_p2a_stat_update (); } @@ -484,49 +486,49 @@ GST_ats_add_inbound_address(const struct GNUNET_HELLO_Address *address, * @param prop performance information */ void -GST_ats_add_address(const struct GNUNET_HELLO_Address *address, - const struct GNUNET_ATS_Properties *prop) +GST_ats_add_address (const struct GNUNET_HELLO_Address *address, + const struct GNUNET_ATS_Properties *prop) { struct GNUNET_ATS_AddressRecord *ar; struct AddressInfo *ai; if (0 == - memcmp(&GST_my_identity, - &address->peer, - sizeof(struct GNUNET_PeerIdentity))) + memcmp (&GST_my_identity, + &address->peer, + sizeof(struct GNUNET_PeerIdentity))) return; /* our own, ignore! */ /* validadte address */ if (NULL == address->transport_name) - { - GNUNET_break(0); - return; - } - GNUNET_assert(GNUNET_YES != - GNUNET_HELLO_address_check_option(address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)); - ai = find_ai_no_session(address); - GNUNET_assert(NULL == ai); - GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); + { + GNUNET_break (0); + return; + } + GNUNET_assert (GNUNET_YES != + GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)); + ai = find_ai_no_session (address); + GNUNET_assert (NULL == ai); + GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); /* address seems sane, let's tell ATS */ - LOG(GNUNET_ERROR_TYPE_INFO, - "Notifying ATS about peer %s's new address `%s'\n", - GNUNET_i2s(&address->peer), - GST_plugins_a2s(address)); - ar = GNUNET_ATS_address_add(GST_ats, - address, - NULL, - prop); - GNUNET_assert(NULL != ar); - ai = GNUNET_new(struct AddressInfo); - ai->address = GNUNET_HELLO_address_copy(address); + LOG (GNUNET_ERROR_TYPE_INFO, + "Notifying ATS about peer %s's new address `%s'\n", + GNUNET_i2s (&address->peer), + GST_plugins_a2s (address)); + ar = GNUNET_ATS_address_add (GST_ats, + address, + NULL, + prop); + GNUNET_assert (NULL != ar); + ai = GNUNET_new (struct AddressInfo); + ai->address = GNUNET_HELLO_address_copy (address); ai->ar = ar; ai->properties = *prop; - (void)GNUNET_CONTAINER_multipeermap_put(p2a, - &ai->address->peer, - ai, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - publish_p2a_stat_update(); + (void) GNUNET_CONTAINER_multipeermap_put (p2a, + &ai->address->peer, + ai, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + publish_p2a_stat_update (); } @@ -540,41 +542,41 @@ GST_ats_add_address(const struct GNUNET_HELLO_Address *address, * @param session the session */ void -GST_ats_new_session(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +GST_ats_new_session (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { struct AddressInfo *ai; if (0 == - memcmp(&GST_my_identity, - &address->peer, - sizeof(struct GNUNET_PeerIdentity))) + memcmp (&GST_my_identity, + &address->peer, + sizeof(struct GNUNET_PeerIdentity))) return; /* our own, ignore! */ - ai = find_ai(address, NULL); + ai = find_ai (address, NULL); if (NULL == ai) - { - /* We may simply already be aware of the session, even if some - other part of the code could not tell if it just created a new - session or just got one recycled from the plugin; hence, we may - be called with "new" session even for an "old" session; in that - case, check that this is the case, but just ignore it. */ - GNUNET_assert(NULL != (find_ai(address, session))); - return; - } - GNUNET_assert(NULL == ai->session); + { + /* We may simply already be aware of the session, even if some + other part of the code could not tell if it just created a new + session or just got one recycled from the plugin; hence, we may + be called with "new" session even for an "old" session; in that + case, check that this is the case, but just ignore it. */ + GNUNET_assert (NULL != (find_ai (address, session))); + return; + } + GNUNET_assert (NULL == ai->session); ai->session = session; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Telling ATS about new session for peer %s\n", - GNUNET_i2s(&address->peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Telling ATS about new session for peer %s\n", + GNUNET_i2s (&address->peer)); /* Note that the address might currently be blocked; we only tell ATS about the session if the address is currently not blocked; otherwise, ATS will be told about the session on unblock. */ if (NULL != ai->ar) - GNUNET_ATS_address_add_session(ai->ar, - session); + GNUNET_ATS_address_add_session (ai->ar, + session); else - GNUNET_assert(NULL != ai->unblock_task); + GNUNET_assert (NULL != ai->unblock_task); } @@ -584,30 +586,30 @@ GST_ats_new_session(const struct GNUNET_HELLO_Address *address, * @param ai the `struct AddressInfo` */ static void -destroy_ai(struct AddressInfo *ai) +destroy_ai (struct AddressInfo *ai) { - GNUNET_assert(NULL == ai->session); + GNUNET_assert (NULL == ai->session); if (NULL != ai->unblock_task) - { - GNUNET_SCHEDULER_cancel(ai->unblock_task); - ai->unblock_task = NULL; - num_blocked--; - } - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(p2a, - &ai->address->peer, - ai)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Telling ATS to destroy address from peer %s\n", - GNUNET_i2s(&ai->address->peer)); + { + GNUNET_SCHEDULER_cancel (ai->unblock_task); + ai->unblock_task = NULL; + num_blocked--; + } + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (p2a, + &ai->address->peer, + ai)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Telling ATS to destroy address from peer %s\n", + GNUNET_i2s (&ai->address->peer)); if (NULL != ai->ar) - { - GNUNET_ATS_address_destroy(ai->ar); - ai->ar = NULL; - } - publish_p2a_stat_update(); - GNUNET_HELLO_address_free(ai->address); - GNUNET_free(ai); + { + GNUNET_ATS_address_destroy (ai->ar); + ai->ar = NULL; + } + publish_p2a_stat_update (); + GNUNET_HELLO_address_free (ai->address); + GNUNET_free (ai); } @@ -623,100 +625,100 @@ destroy_ai(struct AddressInfo *ai) * @param session the session */ void -GST_ats_del_session(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +GST_ats_del_session (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { struct AddressInfo *ai; if (0 == - memcmp(&GST_my_identity, - &address->peer, - sizeof(struct GNUNET_PeerIdentity))) + memcmp (&GST_my_identity, + &address->peer, + sizeof(struct GNUNET_PeerIdentity))) return; /* our own, ignore! */ if (NULL == session) - { - GNUNET_break(0); - return; - } - ai = find_ai(address, - session); + { + GNUNET_break (0); + return; + } + ai = find_ai (address, + session); if (NULL == ai) - { - /* We sometimes create sessions just for sending a PING, - and if those are destroyed they were never known to - ATS which means we end up here (however, in this - case, the address must be an outbound address). */ - GNUNET_break(GNUNET_YES != - GNUNET_HELLO_address_check_option(address, + { + /* We sometimes create sessions just for sending a PING, + and if those are destroyed they were never known to + ATS which means we end up here (however, in this + case, the address must be an outbound address). */ + GNUNET_break (GNUNET_YES != + GNUNET_HELLO_address_check_option (address, GNUNET_HELLO_ADDRESS_INFO_INBOUND)); - return; - } - GNUNET_assert(session == ai->session); + return; + } + GNUNET_assert (session == ai->session); ai->session = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Telling ATS to destroy session %p from peer %s\n", - session, - GNUNET_i2s(&address->peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Telling ATS to destroy session %p from peer %s\n", + session, + GNUNET_i2s (&address->peer)); if (GNUNET_YES == ai->expired) + { + /* last reason to keep this 'ai' around is now gone, the + session is dead as well, clean up */ + if (NULL != ai->ar) { - /* last reason to keep this 'ai' around is now gone, the - session is dead as well, clean up */ - if (NULL != ai->ar) - { - /* Address expired but not blocked, and thus 'ar' was still - live because of the session; deleting just the session - will do for an inbound session, but for an outbound we - then also need to destroy the address with ATS. */ - if (GNUNET_NO == - GNUNET_ATS_address_del_session(ai->ar, - session)) - { - GNUNET_ATS_address_destroy(ai->ar); - } - /* "ar" has been freed, regardless how the branch - above played out: it was either freed in - #GNUNET_ATS_address_del_session() because it was - incoming, or explicitly in - #GNUNET_ATS_address_del_session(). */ - ai->ar = NULL; - } - destroy_ai(ai); - return; + /* Address expired but not blocked, and thus 'ar' was still + live because of the session; deleting just the session + will do for an inbound session, but for an outbound we + then also need to destroy the address with ATS. */ + if (GNUNET_NO == + GNUNET_ATS_address_del_session (ai->ar, + session)) + { + GNUNET_ATS_address_destroy (ai->ar); + } + /* "ar" has been freed, regardless how the branch + above played out: it was either freed in + #GNUNET_ATS_address_del_session() because it was + incoming, or explicitly in + #GNUNET_ATS_address_del_session(). */ + ai->ar = NULL; } + destroy_ai (ai); + return; + } if (NULL == ai->ar) + { + /* If ATS doesn't know about the address/session, this means + this address was blocked. */ + if (GNUNET_YES == + GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)) { - /* If ATS doesn't know about the address/session, this means - this address was blocked. */ - if (GNUNET_YES == - GNUNET_HELLO_address_check_option(address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)) - { - /* This was a blocked inbound session, which now lost the - session. But inbound addresses are by themselves useless, - so we must forget about the address as well. */ - destroy_ai(ai); - return; - } - /* Otherwise, we are done as we have set `ai->session` to NULL - already and ATS will simply not be told about the session when - the connection is unblocked and the outbound address becomes - available again. . */ + /* This was a blocked inbound session, which now lost the + session. But inbound addresses are by themselves useless, + so we must forget about the address as well. */ + destroy_ai (ai); return; } + /* Otherwise, we are done as we have set `ai->session` to NULL + already and ATS will simply not be told about the session when + the connection is unblocked and the outbound address becomes + available again. . */ + return; + } /* This is the "simple" case where ATS knows about the session and the address is neither blocked nor expired. Delete the session, and if it was inbound, free the address as well. */ if (GNUNET_YES == - GNUNET_ATS_address_del_session(ai->ar, - session)) - { - /* This was an inbound address, the session is now gone, so we - need to also forget about the address itself. */ - ai->ar = NULL; - destroy_ai(ai); - } + GNUNET_ATS_address_del_session (ai->ar, + session)) + { + /* This was an inbound address, the session is now gone, so we + need to also forget about the address itself. */ + ai->ar = NULL; + destroy_ai (ai); + } } @@ -728,31 +730,31 @@ GST_ats_del_session(const struct GNUNET_HELLO_Address *address, * @param distance new distance value */ void -GST_ats_update_distance(const struct GNUNET_HELLO_Address *address, - uint32_t distance) +GST_ats_update_distance (const struct GNUNET_HELLO_Address *address, + uint32_t distance) { struct AddressInfo *ai; - ai = find_ai_no_session(address); + ai = find_ai_no_session (address); if (NULL == ai) - { - /* We do not know about this address, do nothing. */ - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Updated distance for peer `%s' to %u\n", - GNUNET_i2s(&address->peer), - distance); + { + /* We do not know about this address, do nothing. */ + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Updated distance for peer `%s' to %u\n", + GNUNET_i2s (&address->peer), + distance); ai->properties.distance = distance; /* Give manipulation its chance to change metrics */ - GST_manipulation_manipulate_metrics(address, - ai->session, - &ai->properties); + GST_manipulation_manipulate_metrics (address, + ai->session, + &ai->properties); /* Address may be blocked, only give ATS if address is currently active. */ if (NULL != ai->ar) - GNUNET_ATS_address_update(ai->ar, - &ai->properties); + GNUNET_ATS_address_update (ai->ar, + &ai->properties); } @@ -764,32 +766,32 @@ GST_ats_update_distance(const struct GNUNET_HELLO_Address *address, * @param delay new delay value */ void -GST_ats_update_delay(const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Relative delay) +GST_ats_update_delay (const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Relative delay) { struct AddressInfo *ai; - ai = find_ai_no_session(address); + ai = find_ai_no_session (address); if (NULL == ai) - { - /* We do not know about this address, do nothing. */ - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Updated latency for peer `%s' to %s\n", - GNUNET_i2s(&address->peer), - GNUNET_STRINGS_relative_time_to_string(delay, - GNUNET_YES)); + { + /* We do not know about this address, do nothing. */ + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Updated latency for peer `%s' to %s\n", + GNUNET_i2s (&address->peer), + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); ai->properties.delay = delay; /* Give manipulation its chance to change metrics */ - GST_manipulation_manipulate_metrics(address, - ai->session, - &ai->properties); + GST_manipulation_manipulate_metrics (address, + ai->session, + &ai->properties); /* Address may be blocked, only give ATS if address is currently active. */ if (NULL != ai->ar) - GNUNET_ATS_address_update(ai->ar, - &ai->properties); + GNUNET_ATS_address_update (ai->ar, + &ai->properties); } @@ -802,35 +804,35 @@ GST_ats_update_delay(const struct GNUNET_HELLO_Address *address, * @param bps_out new utilization outbound */ void -GST_ats_update_utilization(const struct GNUNET_HELLO_Address *address, - uint32_t bps_in, - uint32_t bps_out) +GST_ats_update_utilization (const struct GNUNET_HELLO_Address *address, + uint32_t bps_in, + uint32_t bps_out) { struct AddressInfo *ai; - ai = find_ai_no_session(address); + ai = find_ai_no_session (address); if (NULL == ai) - { - /* We do not know about this address, do nothing. */ - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Updating utilization for peer `%s' address %s: %u/%u\n", - GNUNET_i2s(&address->peer), - GST_plugins_a2s(address), - (unsigned int)bps_in, - (unsigned int)bps_out); + { + /* We do not know about this address, do nothing. */ + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Updating utilization for peer `%s' address %s: %u/%u\n", + GNUNET_i2s (&address->peer), + GST_plugins_a2s (address), + (unsigned int) bps_in, + (unsigned int) bps_out); ai->properties.utilization_in = bps_in; ai->properties.utilization_out = bps_out; /* Give manipulation its chance to change metrics */ - GST_manipulation_manipulate_metrics(address, - ai->session, - &ai->properties); + GST_manipulation_manipulate_metrics (address, + ai->session, + &ai->properties); /* Address may be blocked, only give ATS if address is currently active. */ if (NULL != ai->ar) - GNUNET_ATS_address_update(ai->ar, - &ai->properties); + GNUNET_ATS_address_update (ai->ar, + &ai->properties); } @@ -842,34 +844,34 @@ GST_ats_update_utilization(const struct GNUNET_HELLO_Address *address, * @param address the address */ void -GST_ats_expire_address(const struct GNUNET_HELLO_Address *address) +GST_ats_expire_address (const struct GNUNET_HELLO_Address *address) { struct AddressInfo *ai; if (0 == - memcmp(&GST_my_identity, - &address->peer, - sizeof(struct GNUNET_PeerIdentity))) + memcmp (&GST_my_identity, + &address->peer, + sizeof(struct GNUNET_PeerIdentity))) return; /* our own, ignore! */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Address %s of peer %s expired\n", - GST_plugins_a2s(address), - GNUNET_i2s(&address->peer)); - ai = find_ai_no_session(address); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Address %s of peer %s expired\n", + GST_plugins_a2s (address), + GNUNET_i2s (&address->peer)); + ai = find_ai_no_session (address); if (NULL == ai) - { - GNUNET_assert(0); - return; - } + { + GNUNET_assert (0); + return; + } if (NULL != ai->session) - { - /* Got an active session, just remember the expiration - and act upon it when the session goes down. */ - ai->expired = GNUNET_YES; - return; - } + { + /* Got an active session, just remember the expiration + and act upon it when the session goes down. */ + ai->expired = GNUNET_YES; + return; + } /* Address expired, no session, free resources */ - destroy_ai(ai); + destroy_ai (ai); } @@ -877,9 +879,9 @@ GST_ats_expire_address(const struct GNUNET_HELLO_Address *address) * Initialize ATS subsystem. */ void -GST_ats_init() +GST_ats_init () { - p2a = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_YES); + p2a = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_YES); } @@ -892,13 +894,13 @@ GST_ats_init() * @return #GNUNET_OK (continue to iterate) */ static int -destroy_ai_cb(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +destroy_ai_cb (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct AddressInfo *ai = value; - destroy_ai(ai); + destroy_ai (ai); return GNUNET_OK; } @@ -907,13 +909,13 @@ destroy_ai_cb(void *cls, * Shutdown ATS subsystem. */ void -GST_ats_done() +GST_ats_done () { - GNUNET_CONTAINER_multipeermap_iterate(p2a, - &destroy_ai_cb, - NULL); - publish_p2a_stat_update(); - GNUNET_CONTAINER_multipeermap_destroy(p2a); + GNUNET_CONTAINER_multipeermap_iterate (p2a, + &destroy_ai_cb, + NULL); + publish_p2a_stat_update (); + GNUNET_CONTAINER_multipeermap_destroy (p2a); p2a = NULL; } diff --git a/src/transport/gnunet-service-transport_ats.h b/src/transport/gnunet-service-transport_ats.h index 9c906a9a2..d536714ec 100644 --- a/src/transport/gnunet-service-transport_ats.h +++ b/src/transport/gnunet-service-transport_ats.h @@ -31,14 +31,14 @@ * Initialize ATS subsystem. */ void -GST_ats_init(void); +GST_ats_init (void); /** * Shutdown ATS subsystem. */ void -GST_ats_done(void); +GST_ats_done (void); /** @@ -51,8 +51,8 @@ GST_ats_done(void); * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not. */ int -GST_ats_is_known(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session); +GST_ats_is_known (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session); /** @@ -63,7 +63,7 @@ GST_ats_is_known(const struct GNUNET_HELLO_Address *address, * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not. */ int -GST_ats_is_known_no_session(const struct GNUNET_HELLO_Address *address); +GST_ats_is_known_no_session (const struct GNUNET_HELLO_Address *address); /** @@ -76,8 +76,8 @@ GST_ats_is_known_no_session(const struct GNUNET_HELLO_Address *address); * @param session the session (can be NULL) */ void -GST_ats_block_address(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session); +GST_ats_block_address (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session); /** @@ -89,8 +89,8 @@ GST_ats_block_address(const struct GNUNET_HELLO_Address *address, * @param session the session (can be NULL) */ void -GST_ats_block_reset(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session); +GST_ats_block_reset (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session); /** @@ -104,9 +104,9 @@ GST_ats_block_reset(const struct GNUNET_HELLO_Address *address, * @param prop performance information */ void -GST_ats_add_inbound_address(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - const struct GNUNET_ATS_Properties *prop); +GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + const struct GNUNET_ATS_Properties *prop); /** @@ -117,8 +117,8 @@ GST_ats_add_inbound_address(const struct GNUNET_HELLO_Address *address, * @param prop performance information */ void -GST_ats_add_address(const struct GNUNET_HELLO_Address *address, - const struct GNUNET_ATS_Properties *prop); +GST_ats_add_address (const struct GNUNET_HELLO_Address *address, + const struct GNUNET_ATS_Properties *prop); /** @@ -131,8 +131,8 @@ GST_ats_add_address(const struct GNUNET_HELLO_Address *address, * @param session the session */ void -GST_ats_new_session(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session); +GST_ats_new_session (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session); /** @@ -144,9 +144,9 @@ GST_ats_new_session(const struct GNUNET_HELLO_Address *address, * @param bps_out new utilization outbound */ void -GST_ats_update_utilization(const struct GNUNET_HELLO_Address *address, - uint32_t bps_in, - uint32_t bps_out); +GST_ats_update_utilization (const struct GNUNET_HELLO_Address *address, + uint32_t bps_in, + uint32_t bps_out); /** @@ -158,8 +158,8 @@ GST_ats_update_utilization(const struct GNUNET_HELLO_Address *address, * @param delay new delay value */ void -GST_ats_update_delay(const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Relative delay); +GST_ats_update_delay (const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Relative delay); /** @@ -170,8 +170,8 @@ GST_ats_update_delay(const struct GNUNET_HELLO_Address *address, * @param distance new distance value */ void -GST_ats_update_distance(const struct GNUNET_HELLO_Address *address, - uint32_t distance); +GST_ats_update_distance (const struct GNUNET_HELLO_Address *address, + uint32_t distance); /** @@ -186,8 +186,8 @@ GST_ats_update_distance(const struct GNUNET_HELLO_Address *address, * @param session the session */ void -GST_ats_del_session(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session); +GST_ats_del_session (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session); /** @@ -198,7 +198,7 @@ GST_ats_del_session(const struct GNUNET_HELLO_Address *address, * @param address the address */ void -GST_ats_expire_address(const struct GNUNET_HELLO_Address *address); +GST_ats_expire_address (const struct GNUNET_HELLO_Address *address); #endif diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c index 24a8321a2..ed6565d23 100644 --- a/src/transport/gnunet-service-transport_hello.c +++ b/src/transport/gnunet-service-transport_hello.c @@ -36,7 +36,8 @@ /** * How often do we refresh our HELLO (due to expiration concerns)? */ -#define HELLO_REFRESH_PERIOD GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 6) +#define HELLO_REFRESH_PERIOD GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_HOURS, 6) /** * Hello address expiration @@ -48,7 +49,8 @@ extern struct GNUNET_TIME_Relative hello_expiration; * Entry in linked list of network addresses for ourselves. Also * includes a cached signature for 'struct TransportPongMessage's. */ -struct OwnAddressList { +struct OwnAddressList +{ /** * This is a doubly-linked list. */ @@ -123,7 +125,8 @@ static struct GNUNET_SCHEDULER_Task *hello_task; /** * Closure for #address_generator(). */ -struct GeneratorContext { +struct GeneratorContext +{ /** * Where are we in the DLL? */ @@ -146,19 +149,19 @@ struct GeneratorContext { * end of the iteration. */ static ssize_t -address_generator(void *cls, - size_t max, - void *buf) +address_generator (void *cls, + size_t max, + void *buf) { struct GeneratorContext *gc = cls; ssize_t ret; if (NULL == gc->addr_pos) return GNUNET_SYSERR; /* Done */ - ret = GNUNET_HELLO_add_address(gc->addr_pos->address, - gc->expiration, - buf, - max); + ret = GNUNET_HELLO_add_address (gc->addr_pos->address, + gc->expiration, + buf, + max); gc->addr_pos = gc->addr_pos->next; return ret; } @@ -171,38 +174,38 @@ address_generator(void *cls, * @param cls unused */ static void -refresh_hello_task(void *cls) +refresh_hello_task (void *cls) { struct GeneratorContext gc; hello_task = NULL; gc.addr_pos = oal_head; - gc.expiration = GNUNET_TIME_relative_to_absolute(hello_expiration); - - GNUNET_free_non_null(our_hello); - our_hello = GNUNET_HELLO_create(&GST_my_identity.public_key, - &address_generator, - &gc, - friend_option); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Refreshed my %s HELLO, new size is %d\n", - (GNUNET_YES == friend_option) ? "friend-only" : "public", - GNUNET_HELLO_size(our_hello)); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# refreshed my HELLO"), - 1, - GNUNET_NO); + gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration); + + GNUNET_free_non_null (our_hello); + our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key, + &address_generator, + &gc, + friend_option); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Refreshed my %s HELLO, new size is %d\n", + (GNUNET_YES == friend_option) ? "friend-only" : "public", + GNUNET_HELLO_size (our_hello)); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# refreshed my HELLO"), + 1, + GNUNET_NO); if (NULL != hello_cb) - hello_cb(hello_cb_cls, - GST_hello_get()); - GNUNET_PEERINFO_add_peer(GST_peerinfo, - our_hello, - NULL, - NULL); + hello_cb (hello_cb_cls, + GST_hello_get ()); + GNUNET_PEERINFO_add_peer (GST_peerinfo, + our_hello, + NULL, + NULL); hello_task = - GNUNET_SCHEDULER_add_delayed(HELLO_REFRESH_PERIOD, - &refresh_hello_task, - NULL); + GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, + &refresh_hello_task, + NULL); } @@ -212,14 +215,14 @@ refresh_hello_task(void *cls) * have been shutdown). */ static void -refresh_hello() +refresh_hello () { if (NULL != hello_task) - { - GNUNET_SCHEDULER_cancel(hello_task); - hello_task = GNUNET_SCHEDULER_add_now(&refresh_hello_task, - NULL); - } + { + GNUNET_SCHEDULER_cancel (hello_task); + hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task, + NULL); + } } @@ -231,14 +234,14 @@ refresh_hello() * @param cb_cls closure for @a cb */ void -GST_hello_start(int friend_only, - GST_HelloCallback cb, - void *cb_cls) +GST_hello_start (int friend_only, + GST_HelloCallback cb, + void *cb_cls) { hello_cb = cb; hello_cb_cls = cb_cls; friend_option = friend_only; - refresh_hello_task(NULL); + refresh_hello_task (NULL); } @@ -246,20 +249,20 @@ GST_hello_start(int friend_only, * Shutdown the HELLO module. */ void -GST_hello_stop() +GST_hello_stop () { hello_cb = NULL; hello_cb_cls = NULL; if (NULL != hello_task) - { - GNUNET_SCHEDULER_cancel(hello_task); - hello_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (hello_task); + hello_task = NULL; + } if (NULL != our_hello) - { - GNUNET_free(our_hello); - our_hello = NULL; - } + { + GNUNET_free (our_hello); + our_hello = NULL; + } } @@ -269,9 +272,9 @@ GST_hello_stop() * @return our HELLO message */ const struct GNUNET_MessageHeader * -GST_hello_get() +GST_hello_get () { - return (const struct GNUNET_MessageHeader *)our_hello; + return (const struct GNUNET_MessageHeader *) our_hello; } @@ -282,52 +285,52 @@ GST_hello_get() * @param address address to add or remove */ void -GST_hello_modify_addresses(int addremove, - const struct GNUNET_HELLO_Address *address) +GST_hello_modify_addresses (int addremove, + const struct GNUNET_HELLO_Address *address) { struct OwnAddressList *al; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - (GNUNET_YES == addremove) - ? "Adding `%s' to the set of our addresses\n" - : "Removing `%s' from the set of our addresses\n", - GST_plugins_a2s(address)); - GNUNET_assert(NULL != address); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + (GNUNET_YES == addremove) + ? "Adding `%s' to the set of our addresses\n" + : "Removing `%s' from the set of our addresses\n", + GST_plugins_a2s (address)); + GNUNET_assert (NULL != address); for (al = oal_head; al != NULL; al = al->next) - if (0 == GNUNET_HELLO_address_cmp(address, al->address)) + if (0 == GNUNET_HELLO_address_cmp (address, al->address)) break; if (GNUNET_NO == addremove) + { + if (NULL == al) { - if (NULL == al) - { - /* address to be removed not found!? */ - GNUNET_break(0); - return; - } - al->rc--; - if (0 != al->rc) - return; /* RC not yet zero */ - GNUNET_CONTAINER_DLL_remove(oal_head, - oal_tail, - al); - GNUNET_HELLO_address_free(al->address); - GNUNET_free(al); - refresh_hello(); + /* address to be removed not found!? */ + GNUNET_break (0); return; } + al->rc--; + if (0 != al->rc) + return; /* RC not yet zero */ + GNUNET_CONTAINER_DLL_remove (oal_head, + oal_tail, + al); + GNUNET_HELLO_address_free (al->address); + GNUNET_free (al); + refresh_hello (); + return; + } if (NULL != al) - { - /* address added twice or more */ - al->rc++; - return; - } - al = GNUNET_new(struct OwnAddressList); + { + /* address added twice or more */ + al->rc++; + return; + } + al = GNUNET_new (struct OwnAddressList); al->rc = 1; - GNUNET_CONTAINER_DLL_insert(oal_head, - oal_tail, - al); - al->address = GNUNET_HELLO_address_copy(address); - refresh_hello(); + GNUNET_CONTAINER_DLL_insert (oal_head, + oal_tail, + al); + al->address = GNUNET_HELLO_address_copy (address); + refresh_hello (); } @@ -342,20 +345,20 @@ GST_hello_modify_addresses(int addremove, * #GNUNET_NO if not */ int -GST_hello_test_address(const struct GNUNET_HELLO_Address *address, - struct GNUNET_CRYPTO_EddsaSignature **sig, - struct GNUNET_TIME_Absolute **sig_expiration) +GST_hello_test_address (const struct GNUNET_HELLO_Address *address, + struct GNUNET_CRYPTO_EddsaSignature **sig, + struct GNUNET_TIME_Absolute **sig_expiration) { struct OwnAddressList *al; for (al = oal_head; al != NULL; al = al->next) - if (0 == GNUNET_HELLO_address_cmp(address, - al->address)) - { - *sig = &al->pong_signature; - *sig_expiration = &al->pong_sig_expires; - return GNUNET_YES; - } + if (0 == GNUNET_HELLO_address_cmp (address, + al->address)) + { + *sig = &al->pong_signature; + *sig_expiration = &al->pong_sig_expires; + return GNUNET_YES; + } *sig = NULL; *sig_expiration = NULL; return GNUNET_NO; diff --git a/src/transport/gnunet-service-transport_hello.h b/src/transport/gnunet-service-transport_hello.h index 6dee4eb07..be089dd35 100644 --- a/src/transport/gnunet-service-transport_hello.h +++ b/src/transport/gnunet-service-transport_hello.h @@ -50,16 +50,16 @@ typedef void * @param cb_cls closure for @a cb */ void -GST_hello_start(int friend_only, - GST_HelloCallback cb, - void *cb_cls); +GST_hello_start (int friend_only, + GST_HelloCallback cb, + void *cb_cls); /** * Shutdown the HELLO module. */ void -GST_hello_stop(void); +GST_hello_stop (void); /** @@ -68,7 +68,7 @@ GST_hello_stop(void); * @return our HELLO message */ const struct GNUNET_MessageHeader * -GST_hello_get(void); +GST_hello_get (void); /** @@ -78,8 +78,8 @@ GST_hello_get(void); * @param address address to add or remove */ void -GST_hello_modify_addresses(int addremove, - const struct GNUNET_HELLO_Address *address); +GST_hello_modify_addresses (int addremove, + const struct GNUNET_HELLO_Address *address); /** @@ -93,9 +93,9 @@ GST_hello_modify_addresses(int addremove, * #GNUNET_NO if not */ int -GST_hello_test_address(const struct GNUNET_HELLO_Address *address, - struct GNUNET_CRYPTO_EddsaSignature **sig, - struct GNUNET_TIME_Absolute **sig_expiration); +GST_hello_test_address (const struct GNUNET_HELLO_Address *address, + struct GNUNET_CRYPTO_EddsaSignature **sig, + struct GNUNET_TIME_Absolute **sig_expiration); #endif diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c index 07f7eb618..47ae5b981 100644 --- a/src/transport/gnunet-service-transport_manipulation.c +++ b/src/transport/gnunet-service-transport_manipulation.c @@ -36,7 +36,8 @@ /** * Struct containing information about manipulations to a specific peer */ -struct TM_Peer { +struct TM_Peer +{ /** * Peer ID */ @@ -77,7 +78,8 @@ struct TM_Peer { /** * Entry in the delay queue for an outbound delayed message */ -struct DelayQueueEntry { +struct DelayQueueEntry +{ /** * Next in DLL */ @@ -169,39 +171,39 @@ static struct GNUNET_SCHEDULER_Task *generic_send_delay_task; * @param message containing information */ void -GST_manipulation_set_metric(const struct TrafficMetricMessage *tm) +GST_manipulation_set_metric (const struct TrafficMetricMessage *tm) { static struct GNUNET_PeerIdentity zero; struct TM_Peer *tmp; - if (0 == memcmp(&tm->peer, - &zero, - sizeof(struct GNUNET_PeerIdentity))) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received traffic metrics for all peers\n"); - delay_in = GNUNET_TIME_relative_ntoh(tm->delay_in); - delay_out = GNUNET_TIME_relative_ntoh(tm->delay_out); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received traffic metrics for peer `%s'\n", - GNUNET_i2s(&tm->peer)); + if (0 == memcmp (&tm->peer, + &zero, + sizeof(struct GNUNET_PeerIdentity))) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received traffic metrics for all peers\n"); + delay_in = GNUNET_TIME_relative_ntoh (tm->delay_in); + delay_out = GNUNET_TIME_relative_ntoh (tm->delay_out); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received traffic metrics for peer `%s'\n", + GNUNET_i2s (&tm->peer)); if (NULL == - (tmp = GNUNET_CONTAINER_multipeermap_get(peers, - &tm->peer))) - { - tmp = GNUNET_new(struct TM_Peer); - tmp->peer = tm->peer; - GNUNET_CONTAINER_multipeermap_put(peers, - &tm->peer, - tmp, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - } - GNUNET_ATS_properties_ntoh(&tmp->properties, - &tm->properties); - tmp->delay_in = GNUNET_TIME_relative_ntoh(tm->delay_in); - tmp->delay_out = GNUNET_TIME_relative_ntoh(tm->delay_out); + (tmp = GNUNET_CONTAINER_multipeermap_get (peers, + &tm->peer))) + { + tmp = GNUNET_new (struct TM_Peer); + tmp->peer = tm->peer; + GNUNET_CONTAINER_multipeermap_put (peers, + &tm->peer, + tmp, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + } + GNUNET_ATS_properties_ntoh (&tmp->properties, + &tm->properties); + tmp->delay_in = GNUNET_TIME_relative_ntoh (tm->delay_in); + tmp->delay_out = GNUNET_TIME_relative_ntoh (tm->delay_out); } @@ -212,52 +214,52 @@ GST_manipulation_set_metric(const struct TrafficMetricMessage *tm) * @param cls the `struct DelayQueueEntry` to transmit */ static void -send_delayed(void *cls) +send_delayed (void *cls) { struct DelayQueueEntry *dqe = cls; struct DelayQueueEntry *next; struct TM_Peer *tmp = dqe->tmp; - GNUNET_break(GNUNET_YES == - GST_neighbours_test_connected(&dqe->id)); + GNUNET_break (GNUNET_YES == + GST_neighbours_test_connected (&dqe->id)); if (NULL != tmp) + { + tmp->send_delay_task = NULL; + GNUNET_CONTAINER_DLL_remove (tmp->send_head, + tmp->send_tail, + dqe); + next = tmp->send_head; + if (NULL != next) { - tmp->send_delay_task = NULL; - GNUNET_CONTAINER_DLL_remove(tmp->send_head, - tmp->send_tail, - dqe); - next = tmp->send_head; - if (NULL != next) - { - /* More delayed messages */ - tmp->send_delay_task = GNUNET_SCHEDULER_add_at(next->sent_at, - &send_delayed, - next); - } + /* More delayed messages */ + tmp->send_delay_task = GNUNET_SCHEDULER_add_at (next->sent_at, + &send_delayed, + next); } + } else + { + /* Remove from generic queue */ + generic_send_delay_task = NULL; + GNUNET_CONTAINER_DLL_remove (generic_dqe_head, + generic_dqe_tail, + dqe); + next = generic_dqe_head; + if (NULL != next) { - /* Remove from generic queue */ - generic_send_delay_task = NULL; - GNUNET_CONTAINER_DLL_remove(generic_dqe_head, - generic_dqe_tail, - dqe); - next = generic_dqe_head; - if (NULL != next) - { - /* More delayed messages */ - generic_send_delay_task = GNUNET_SCHEDULER_add_at(next->sent_at, - &send_delayed, - next); - } + /* More delayed messages */ + generic_send_delay_task = GNUNET_SCHEDULER_add_at (next->sent_at, + &send_delayed, + next); } - GST_neighbours_send(&dqe->id, - dqe->msg, - dqe->msg_size, - dqe->timeout, - dqe->cont, - dqe->cont_cls); - GNUNET_free(dqe); + } + GST_neighbours_send (&dqe->id, + dqe->msg, + dqe->msg_size, + dqe->timeout, + dqe->cont, + dqe->cont_cls); + GNUNET_free (dqe); } @@ -273,71 +275,71 @@ send_delayed(void *cls) * @param cont_cls cls for @a cont */ void -GST_manipulation_send(const struct GNUNET_PeerIdentity *target, - const void *msg, - size_t msg_size, - struct GNUNET_TIME_Relative timeout, - GST_NeighbourSendContinuation cont, - void *cont_cls) +GST_manipulation_send (const struct GNUNET_PeerIdentity *target, + const void *msg, + size_t msg_size, + struct GNUNET_TIME_Relative timeout, + GST_NeighbourSendContinuation cont, + void *cont_cls) { struct TM_Peer *tmp; struct DelayQueueEntry *dqe; struct GNUNET_TIME_Relative delay; if (NULL != (tmp = - GNUNET_CONTAINER_multipeermap_get(peers, - target))) + GNUNET_CONTAINER_multipeermap_get (peers, + target))) delay = tmp->delay_out; else delay = delay_out; if (0 == delay.rel_value_us) - { - /* Normal sending */ - GST_neighbours_send(target, - msg, - msg_size, - timeout, - cont, cont_cls); - return; - } - dqe = GNUNET_malloc(sizeof(struct DelayQueueEntry) + msg_size); + { + /* Normal sending */ + GST_neighbours_send (target, + msg, + msg_size, + timeout, + cont, cont_cls); + return; + } + dqe = GNUNET_malloc (sizeof(struct DelayQueueEntry) + msg_size); dqe->id = *target; dqe->tmp = tmp; - dqe->sent_at = GNUNET_TIME_relative_to_absolute(delay); + dqe->sent_at = GNUNET_TIME_relative_to_absolute (delay); dqe->cont = cont; dqe->cont_cls = cont_cls; dqe->msg = &dqe[1]; dqe->msg_size = msg_size; dqe->timeout = timeout; - GNUNET_memcpy(dqe->msg, - msg, - msg_size); + GNUNET_memcpy (dqe->msg, + msg, + msg_size); if (NULL == tmp) - { - GNUNET_CONTAINER_DLL_insert_tail(generic_dqe_head, - generic_dqe_tail, - dqe); - if (NULL == generic_send_delay_task) - generic_send_delay_task = GNUNET_SCHEDULER_add_delayed(delay, - &send_delayed, - dqe); - } + { + GNUNET_CONTAINER_DLL_insert_tail (generic_dqe_head, + generic_dqe_tail, + dqe); + if (NULL == generic_send_delay_task) + generic_send_delay_task = GNUNET_SCHEDULER_add_delayed (delay, + &send_delayed, + dqe); + } else - { - GNUNET_CONTAINER_DLL_insert_tail(tmp->send_head, - tmp->send_tail, - dqe); - if (NULL == tmp->send_delay_task) - tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed(delay, - &send_delayed, - dqe); - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Delaying %u byte message to peer `%s' with peer specific delay for %s\n", - (unsigned int)msg_size, - GNUNET_i2s(target), - GNUNET_STRINGS_relative_time_to_string(delay, - GNUNET_YES)); + { + GNUNET_CONTAINER_DLL_insert_tail (tmp->send_head, + tmp->send_tail, + dqe); + if (NULL == tmp->send_delay_task) + tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed (delay, + &send_delayed, + dqe); + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Delaying %u byte message to peer `%s' with peer specific delay for %s\n", + (unsigned int) msg_size, + GNUNET_i2s (target), + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); } @@ -350,15 +352,15 @@ GST_manipulation_send(const struct GNUNET_PeerIdentity *target, * @param prop[IN|OUT] metrics to modify */ void -GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - struct GNUNET_ATS_Properties *prop) +GST_manipulation_manipulate_metrics (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + struct GNUNET_ATS_Properties *prop) { const struct GNUNET_PeerIdentity *peer = &address->peer; struct TM_Peer *tmp; - tmp = GNUNET_CONTAINER_multipeermap_get(peers, - peer); + tmp = GNUNET_CONTAINER_multipeermap_get (peers, + peer); if (NULL != tmp) *prop = tmp->properties; } @@ -375,33 +377,33 @@ GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address, * @return manipulated delay for next receive */ struct GNUNET_TIME_Relative -GST_manipulation_recv(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - const struct GNUNET_MessageHeader *message) +GST_manipulation_recv (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + const struct GNUNET_MessageHeader *message) { struct TM_Peer *tmp; struct GNUNET_TIME_Relative quota_delay; struct GNUNET_TIME_Relative m_delay; if (NULL != - (tmp = GNUNET_CONTAINER_multipeermap_get(peers, - &address->peer))) + (tmp = GNUNET_CONTAINER_multipeermap_get (peers, + &address->peer))) m_delay = tmp->delay_in; else m_delay = delay_in; - quota_delay = GST_receive_callback(cls, - address, - session, - message); - m_delay = GNUNET_TIME_relative_max(m_delay, - quota_delay); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Delaying next receive for peer `%s' for %s\n", - GNUNET_i2s(&address->peer), - GNUNET_STRINGS_relative_time_to_string(m_delay, - GNUNET_YES)); + quota_delay = GST_receive_callback (cls, + address, + session, + message); + m_delay = GNUNET_TIME_relative_max (m_delay, + quota_delay); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Delaying next receive for peer `%s' for %s\n", + GNUNET_i2s (&address->peer), + GNUNET_STRINGS_relative_time_to_string (m_delay, + GNUNET_YES)); return m_delay; } @@ -410,38 +412,38 @@ GST_manipulation_recv(void *cls, * Initialize traffic manipulation */ void -GST_manipulation_init() +GST_manipulation_init () { struct GNUNET_TIME_Relative delay; if ((GNUNET_OK == - GNUNET_CONFIGURATION_get_value_time(GST_cfg, - "transport", - "MANIPULATE_DELAY_IN", - &delay)) && + GNUNET_CONFIGURATION_get_value_time (GST_cfg, + "transport", + "MANIPULATE_DELAY_IN", + &delay)) && (delay.rel_value_us > 0)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Delaying inbound traffic for %s\n", - GNUNET_STRINGS_relative_time_to_string(delay, + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Delaying inbound traffic for %s\n", + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); - delay_in = delay; - } + delay_in = delay; + } if ((GNUNET_OK == - GNUNET_CONFIGURATION_get_value_time(GST_cfg, - "transport", - "MANIPULATE_DELAY_OUT", - &delay)) && + GNUNET_CONFIGURATION_get_value_time (GST_cfg, + "transport", + "MANIPULATE_DELAY_OUT", + &delay)) && (delay.rel_value_us > 0)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Delaying outbound traffic for %s\n", - GNUNET_STRINGS_relative_time_to_string(delay, + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Delaying outbound traffic for %s\n", + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); - delay_out = delay; - } - peers = GNUNET_CONTAINER_multipeermap_create(4, - GNUNET_NO); + delay_out = delay; + } + peers = GNUNET_CONTAINER_multipeermap_create (4, + GNUNET_NO); } @@ -451,58 +453,58 @@ GST_manipulation_init() * @param peer the disconnecting peer */ void -GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer) +GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer) { struct TM_Peer *tmp; struct DelayQueueEntry *dqe; struct DelayQueueEntry *next; - tmp = GNUNET_CONTAINER_multipeermap_get(peers, - peer); + tmp = GNUNET_CONTAINER_multipeermap_get (peers, + peer); if (NULL != tmp) + { + while (NULL != (dqe = tmp->send_head)) { - while (NULL != (dqe = tmp->send_head)) - { - GNUNET_CONTAINER_DLL_remove(tmp->send_head, - tmp->send_tail, - dqe); - if (NULL != dqe->cont) - dqe->cont(dqe->cont_cls, - GNUNET_SYSERR, - dqe->msg_size, - 0); - GNUNET_free(dqe); - } + GNUNET_CONTAINER_DLL_remove (tmp->send_head, + tmp->send_tail, + dqe); + if (NULL != dqe->cont) + dqe->cont (dqe->cont_cls, + GNUNET_SYSERR, + dqe->msg_size, + 0); + GNUNET_free (dqe); } + } next = generic_dqe_head; while (NULL != (dqe = next)) + { + next = dqe->next; + if (0 == memcmp (peer, + &dqe->id, + sizeof(dqe->id))) { - next = dqe->next; - if (0 == memcmp(peer, - &dqe->id, - sizeof(dqe->id))) - { - GNUNET_CONTAINER_DLL_remove(generic_dqe_head, - generic_dqe_tail, - dqe); - if (NULL != dqe->cont) - dqe->cont(dqe->cont_cls, - GNUNET_SYSERR, - dqe->msg_size, - 0); - GNUNET_free(dqe); - } + GNUNET_CONTAINER_DLL_remove (generic_dqe_head, + generic_dqe_tail, + dqe); + if (NULL != dqe->cont) + dqe->cont (dqe->cont_cls, + GNUNET_SYSERR, + dqe->msg_size, + 0); + GNUNET_free (dqe); } + } if (NULL != generic_send_delay_task) - { - GNUNET_SCHEDULER_cancel(generic_send_delay_task); - generic_send_delay_task = NULL; - if (NULL != generic_dqe_head) - generic_send_delay_task - = GNUNET_SCHEDULER_add_at(generic_dqe_head->sent_at, - &send_delayed, - generic_dqe_head); - } + { + GNUNET_SCHEDULER_cancel (generic_send_delay_task); + generic_send_delay_task = NULL; + if (NULL != generic_dqe_head) + generic_send_delay_task + = GNUNET_SCHEDULER_add_at (generic_dqe_head->sent_at, + &send_delayed, + generic_dqe_head); + } } @@ -515,35 +517,35 @@ GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer) * @return #GNUNET_OK (continue to iterate) */ static int -free_tmps(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +free_tmps (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct TM_Peer *tmp = value; struct DelayQueueEntry *dqe; - GNUNET_break(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(peers, - key, - value)); + GNUNET_break (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (peers, + key, + value)); while (NULL != (dqe = tmp->send_head)) - { - GNUNET_CONTAINER_DLL_remove(tmp->send_head, - tmp->send_tail, - dqe); - if (NULL != dqe->cont) - dqe->cont(dqe->cont_cls, - GNUNET_SYSERR, - dqe->msg_size, - 0); - GNUNET_free(dqe); - } + { + GNUNET_CONTAINER_DLL_remove (tmp->send_head, + tmp->send_tail, + dqe); + if (NULL != dqe->cont) + dqe->cont (dqe->cont_cls, + GNUNET_SYSERR, + dqe->msg_size, + 0); + GNUNET_free (dqe); + } if (NULL != tmp->send_delay_task) - { - GNUNET_SCHEDULER_cancel(tmp->send_delay_task); - tmp->send_delay_task = NULL; - } - GNUNET_free(tmp); + { + GNUNET_SCHEDULER_cancel (tmp->send_delay_task); + tmp->send_delay_task = NULL; + } + GNUNET_free (tmp); return GNUNET_OK; } @@ -552,32 +554,32 @@ free_tmps(void *cls, * Stop traffic manipulation */ void -GST_manipulation_stop() +GST_manipulation_stop () { struct DelayQueueEntry *cur; - GNUNET_CONTAINER_multipeermap_iterate(peers, - &free_tmps, - NULL); - GNUNET_CONTAINER_multipeermap_destroy(peers); + GNUNET_CONTAINER_multipeermap_iterate (peers, + &free_tmps, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (peers); peers = NULL; while (NULL != (cur = generic_dqe_head)) - { - GNUNET_CONTAINER_DLL_remove(generic_dqe_head, - generic_dqe_tail, - cur); - if (NULL != cur->cont) - cur->cont(cur->cont_cls, - GNUNET_SYSERR, - cur->msg_size, - 0); - GNUNET_free(cur); - } + { + GNUNET_CONTAINER_DLL_remove (generic_dqe_head, + generic_dqe_tail, + cur); + if (NULL != cur->cont) + cur->cont (cur->cont_cls, + GNUNET_SYSERR, + cur->msg_size, + 0); + GNUNET_free (cur); + } if (NULL != generic_send_delay_task) - { - GNUNET_SCHEDULER_cancel(generic_send_delay_task); - generic_send_delay_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (generic_send_delay_task); + generic_send_delay_task = NULL; + } } /* end of file gnunet-service-transport_manipulation.c */ diff --git a/src/transport/gnunet-service-transport_manipulation.h b/src/transport/gnunet-service-transport_manipulation.h index e2ab69d94..b84f3fc32 100644 --- a/src/transport/gnunet-service-transport_manipulation.h +++ b/src/transport/gnunet-service-transport_manipulation.h @@ -42,7 +42,7 @@ * @param message containing information */ void -GST_manipulation_set_metric(const struct TrafficMetricMessage *tm); +GST_manipulation_set_metric (const struct TrafficMetricMessage *tm); /** @@ -56,12 +56,12 @@ GST_manipulation_set_metric(const struct TrafficMetricMessage *tm); * @param cont_cls cls for continuation */ void -GST_manipulation_send(const struct GNUNET_PeerIdentity *target, - const void *msg, - size_t msg_size, - struct GNUNET_TIME_Relative timeout, - GST_NeighbourSendContinuation cont, - void *cont_cls); +GST_manipulation_send (const struct GNUNET_PeerIdentity *target, + const void *msg, + size_t msg_size, + struct GNUNET_TIME_Relative timeout, + GST_NeighbourSendContinuation cont, + void *cont_cls); /** @@ -75,10 +75,10 @@ GST_manipulation_send(const struct GNUNET_PeerIdentity *target, * @return manipulated delay for next receive */ struct GNUNET_TIME_Relative -GST_manipulation_recv(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - const struct GNUNET_MessageHeader *message); +GST_manipulation_recv (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + const struct GNUNET_MessageHeader *message); /** @@ -90,9 +90,9 @@ GST_manipulation_recv(void *cls, * @param prop[IN|OUT] metrics to modify */ void -GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - struct GNUNET_ATS_Properties *prop); +GST_manipulation_manipulate_metrics (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + struct GNUNET_ATS_Properties *prop); /** @@ -101,21 +101,21 @@ GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address, * @param peer the disconnecting peer */ void -GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer); +GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer); /** * Initialize traffic manipulation */ void -GST_manipulation_init(void); +GST_manipulation_init (void); /** * Stop traffic manipulation */ void -GST_manipulation_stop(void); +GST_manipulation_stop (void); #endif /* end of file gnunet-service-transport_neighbours.h */ diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 73d9a27f1..3de10d108 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -50,7 +50,8 @@ * Time we give plugin to transmit DISCONNECT message before the * neighbour entry self-destructs. */ -#define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) +#define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MILLISECONDS, 500) /** * How often must a peer violate bandwidth quotas before we start @@ -61,13 +62,15 @@ /** * How long are we willing to wait for a response from ATS before timing out? */ -#define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) +#define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 5) /** * How long are we willing to wait for an ACK from the other peer before * giving up on our connect operation? */ -#define SETUP_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) +#define SETUP_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 15) /** * How long are we willing to wait for a successful reconnect if @@ -85,7 +88,8 @@ /** * State describing which kind a reply this neighbour should send */ -enum GST_ACK_State { +enum GST_ACK_State +{ /** * We did not receive a SYN message for this neighbour */ @@ -115,7 +119,8 @@ GNUNET_NETWORK_STRUCT_BEGIN * a 'ACK'. Once the 'ACK' is received, both peers * should be connected. */ -struct TransportSynMessage { +struct TransportSynMessage +{ /** * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN * or #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK @@ -143,7 +148,8 @@ struct TransportSynMessage { * When the keep alive response with type is received, transport service * will call the respective plugin to update the session timeout */ -struct GNUNET_ATS_SessionKeepAliveMessage { +struct GNUNET_ATS_SessionKeepAliveMessage +{ /** * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE or * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE. @@ -162,7 +168,8 @@ struct GNUNET_ATS_SessionKeepAliveMessage { * the other peer should limit transmissions to the indicated * quota. */ -struct GNUNET_ATS_SessionQuotaMessage { +struct GNUNET_ATS_SessionQuotaMessage +{ /** * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA. */ @@ -181,7 +188,8 @@ struct GNUNET_ATS_SessionQuotaMessage { * notification, peers must not rely on always receiving disconnect * messages. */ -struct GNUNET_ATS_SessionDisconnectMessage { +struct GNUNET_ATS_SessionDisconnectMessage +{ /** * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT */ @@ -224,7 +232,8 @@ GNUNET_NETWORK_STRUCT_END * For each neighbour we keep a list of messages * that we still want to transmit to the neighbour. */ -struct MessageQueue { +struct MessageQueue +{ /** * This is a doubly linked list. */ @@ -266,7 +275,8 @@ struct MessageQueue { /** * A possible address we could use to communicate with a neighbour. */ -struct NeighbourAddress { +struct NeighbourAddress +{ /** * Active session for this address. */ @@ -309,7 +319,8 @@ struct NeighbourAddress { /** * Entry in neighbours. */ -struct NeighbourMapEntry { +struct NeighbourMapEntry +{ /** * Head of list of messages we would like to send to this peer; * must contain at most one message per client. @@ -483,23 +494,23 @@ static struct GNUNET_SCHEDULER_Task *util_transmission_tk; * @return corresponding human-readable string */ static char * -print_ack_state(enum GST_ACK_State s) +print_ack_state (enum GST_ACK_State s) { switch (s) - { - case ACK_UNDEFINED: - return "UNDEFINED"; + { + case ACK_UNDEFINED: + return "UNDEFINED"; - case ACK_SEND_SYN_ACK: - return "SEND_SYN_ACK"; + case ACK_SEND_SYN_ACK: + return "SEND_SYN_ACK"; - case ACK_SEND_ACK: - return "SEND_ACK"; + case ACK_SEND_ACK: + return "SEND_ACK"; - default: - GNUNET_break(0); - return "N/A"; - } + default: + GNUNET_break (0); + return "N/A"; + } } @@ -511,30 +522,30 @@ print_ack_state(enum GST_ACK_State s) * @param n affected peer */ static void -send_outbound_quota_to_clients(struct NeighbourMapEntry *n) +send_outbound_quota_to_clients (struct NeighbourMapEntry *n) { struct QuotaSetMessage q_msg; struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min; - if (!GNUNET_TRANSPORT_is_connected(n->state)) + if (! GNUNET_TRANSPORT_is_connected (n->state)) return; #if IGNORE_INBOUND_QUOTA bandwidth_min = n->primary_address.bandwidth_out; #else - bandwidth_min = GNUNET_BANDWIDTH_value_min(n->primary_address.bandwidth_out, - n->neighbour_receive_quota); + bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out, + n->neighbour_receive_quota); #endif - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending outbound quota of %u Bps for peer `%s' to all clients\n", - ntohl(bandwidth_min.value__), - GNUNET_i2s(&n->id)); - q_msg.header.size = htons(sizeof(struct QuotaSetMessage)); - q_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending outbound quota of %u Bps for peer `%s' to all clients\n", + ntohl (bandwidth_min.value__), + GNUNET_i2s (&n->id)); + q_msg.header.size = htons (sizeof(struct QuotaSetMessage)); + q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); q_msg.quota = bandwidth_min; q_msg.peer = n->id; - GST_clients_broadcast(&q_msg.header, - GNUNET_NO); + GST_clients_broadcast (&q_msg.header, + GNUNET_NO); } @@ -544,28 +555,28 @@ send_outbound_quota_to_clients(struct NeighbourMapEntry *n) * @param n the peer that connected */ static void -neighbours_connect_notification(struct NeighbourMapEntry *n) +neighbours_connect_notification (struct NeighbourMapEntry *n) { size_t len = sizeof(struct ConnectInfoMessage); char buf[len] GNUNET_ALIGN; - struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *)buf; + struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min; #if IGNORE_INBOUND_QUOTA bandwidth_min = n->primary_address.bandwidth_out; #else - bandwidth_min = GNUNET_BANDWIDTH_value_min(n->primary_address.bandwidth_out, - n->neighbour_receive_quota); + bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out, + n->neighbour_receive_quota); #endif - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "We are now connected to peer `%s'\n", - GNUNET_i2s(&n->id)); - connect_msg->header.size = htons(sizeof(buf)); - connect_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "We are now connected to peer `%s'\n", + GNUNET_i2s (&n->id)); + connect_msg->header.size = htons (sizeof(buf)); + connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); connect_msg->id = n->id; connect_msg->quota_out = bandwidth_min; - GST_clients_broadcast(&connect_msg->header, - GNUNET_NO); + GST_clients_broadcast (&connect_msg->header, + GNUNET_NO); } @@ -576,13 +587,13 @@ neighbours_connect_notification(struct NeighbourMapEntry *n) * @param n the peer that disconnected */ static void -neighbours_disconnect_notification(struct NeighbourMapEntry *n) +neighbours_disconnect_notification (struct NeighbourMapEntry *n) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peer `%s' disconnected\n", - GNUNET_i2s(&n->id)); - GST_manipulation_peer_disconnect(&n->id); - GST_clients_broadcast_disconnect(&n->id); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer `%s' disconnected\n", + GNUNET_i2s (&n->id)); + GST_manipulation_peer_disconnect (&n->id); + GST_clients_broadcast_disconnect (&n->id); } @@ -598,26 +609,28 @@ neighbours_disconnect_notification(struct NeighbourMapEntry *n) * @param bandwidth_out bandwidth assigned outbound, 0 on disconnect */ static void -neighbours_changed_notification(const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) -{ - (void)bandwidth_in; - (void)bandwidth_out; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n", - GNUNET_i2s(peer), - GST_plugins_a2s(address), - GNUNET_TRANSPORT_ps2s(state), - GNUNET_STRINGS_absolute_time_to_string(state_timeout)); +neighbours_changed_notification (const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_out) +{ + (void) bandwidth_in; + (void) bandwidth_out; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n", + GNUNET_i2s (peer), + GST_plugins_a2s (address), + GNUNET_TRANSPORT_ps2s (state), + GNUNET_STRINGS_absolute_time_to_string (state_timeout)); /* FIXME: include bandwidth in notification! */ - GST_clients_broadcast_peer_notification(peer, - address, - state, - state_timeout); + GST_clients_broadcast_peer_notification (peer, + address, + state, + state_timeout); } @@ -628,11 +641,11 @@ neighbours_changed_notification(const struct GNUNET_PeerIdentity *peer, * @return the entry, NULL if there is no existing record */ static struct NeighbourMapEntry * -lookup_neighbour(const struct GNUNET_PeerIdentity *pid) +lookup_neighbour (const struct GNUNET_PeerIdentity *pid) { if (NULL == neighbours) return NULL; - return GNUNET_CONTAINER_multipeermap_get(neighbours, pid); + return GNUNET_CONTAINER_multipeermap_get (neighbours, pid); } @@ -643,11 +656,11 @@ lookup_neighbour(const struct GNUNET_PeerIdentity *pid) * @return #GNUNET_YES if we are connected, #GNUNET_NO if not */ static int -test_connected(struct NeighbourMapEntry *n) +test_connected (struct NeighbourMapEntry *n) { if (NULL == n) return GNUNET_NO; - return GNUNET_TRANSPORT_is_connected(n->state); + return GNUNET_TRANSPORT_is_connected (n->state); } @@ -659,20 +672,20 @@ test_connected(struct NeighbourMapEntry *n) * @param na address we are done with; @a na itself must NOT be 'free'd, only the contents! */ static void -free_address(struct NeighbourAddress *na) +free_address (struct NeighbourAddress *na) { if (GNUNET_YES == na->ats_active) - GST_validation_set_address_use(na->address, - GNUNET_NO); + GST_validation_set_address_use (na->address, + GNUNET_NO); if (NULL != na->address) - { - GST_ats_block_address(na->address, - na->session); - GNUNET_HELLO_address_free(na->address); - na->address = NULL; - } - na->bandwidth_in = GNUNET_BANDWIDTH_value_init(0); - na->bandwidth_out = GNUNET_BANDWIDTH_value_init(0); + { + GST_ats_block_address (na->address, + na->session); + GNUNET_HELLO_address_free (na->address); + na->address = NULL; + } + na->bandwidth_in = GNUNET_BANDWIDTH_value_init (0); + na->bandwidth_out = GNUNET_BANDWIDTH_value_init (0); na->ats_active = GNUNET_NO; na->keep_alive_nonce = 0; na->session = NULL; @@ -687,7 +700,7 @@ free_address(struct NeighbourAddress *na) * @param cls the `struct NeighbourMapEntry` for which we are running */ static void -master_task(void *cls); +master_task (void *cls); /** @@ -698,50 +711,50 @@ master_task(void *cls); * @param timeout the new timeout */ static void -set_state_and_timeout(struct NeighbourMapEntry *n, - enum GNUNET_TRANSPORT_PeerState s, - struct GNUNET_TIME_Absolute timeout) +set_state_and_timeout (struct NeighbourMapEntry *n, + enum GNUNET_TRANSPORT_PeerState s, + struct GNUNET_TIME_Absolute timeout) { - if (GNUNET_TRANSPORT_is_connected(s) && - (!GNUNET_TRANSPORT_is_connected(n->state))) - { - neighbours_connect_notification(n); - GNUNET_STATISTICS_set(GST_stats, - gettext_noop("# peers connected"), - ++neighbours_connected, - GNUNET_NO); - } - if ((!GNUNET_TRANSPORT_is_connected(s)) && - GNUNET_TRANSPORT_is_connected(n->state)) - { - GNUNET_STATISTICS_set(GST_stats, - gettext_noop("# peers connected"), - --neighbours_connected, - GNUNET_NO); - neighbours_disconnect_notification(n); - } + if (GNUNET_TRANSPORT_is_connected (s) && + (! GNUNET_TRANSPORT_is_connected (n->state))) + { + neighbours_connect_notification (n); + GNUNET_STATISTICS_set (GST_stats, + gettext_noop ("# peers connected"), + ++neighbours_connected, + GNUNET_NO); + } + if ((! GNUNET_TRANSPORT_is_connected (s)) && + GNUNET_TRANSPORT_is_connected (n->state)) + { + GNUNET_STATISTICS_set (GST_stats, + gettext_noop ("# peers connected"), + --neighbours_connected, + GNUNET_NO); + neighbours_disconnect_notification (n); + } n->state = s; if ((timeout.abs_value_us < n->timeout.abs_value_us) && (NULL != n->task)) - { - /* new timeout is earlier, reschedule master task */ - GNUNET_SCHEDULER_cancel(n->task); - n->task = GNUNET_SCHEDULER_add_at(timeout, - &master_task, - n); - } + { + /* new timeout is earlier, reschedule master task */ + GNUNET_SCHEDULER_cancel (n->task); + n->task = GNUNET_SCHEDULER_add_at (timeout, + &master_task, + n); + } n->timeout = timeout; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Neighbour `%s' changed state to %s with timeout %s\n", - GNUNET_i2s(&n->id), - GNUNET_TRANSPORT_ps2s(s), - GNUNET_STRINGS_absolute_time_to_string(timeout)); - neighbours_changed_notification(&n->id, - n->primary_address.address, - n->state, - n->timeout, - n->primary_address.bandwidth_in, - n->primary_address.bandwidth_out); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Neighbour `%s' changed state to %s with timeout %s\n", + GNUNET_i2s (&n->id), + GNUNET_TRANSPORT_ps2s (s), + GNUNET_STRINGS_absolute_time_to_string (timeout)); + neighbours_changed_notification (&n->id, + n->primary_address.address, + n->state, + n->timeout, + n->primary_address.bandwidth_in, + n->primary_address.bandwidth_out); } @@ -757,62 +770,62 @@ set_state_and_timeout(struct NeighbourMapEntry *n, * @param bandwidth_out outbound quota to be used when connection is up */ static void -set_alternative_address(struct NeighbourMapEntry *n, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) +set_alternative_address (struct NeighbourMapEntry *n, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { struct GNUNET_TRANSPORT_PluginFunctions *papi; - if (NULL == (papi = GST_plugins_find(address->transport_name))) - { - GNUNET_break(0); - return; - } + if (NULL == (papi = GST_plugins_find (address->transport_name))) + { + GNUNET_break (0); + return; + } if (session == n->alternative_address.session) - { - n->alternative_address.bandwidth_in = bandwidth_in; - n->alternative_address.bandwidth_out = bandwidth_out; - return; - } + { + n->alternative_address.bandwidth_in = bandwidth_in; + n->alternative_address.bandwidth_out = bandwidth_out; + return; + } if (NULL != n->alternative_address.address) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Replacing existing alternative address with another one\n"); - free_address(&n->alternative_address); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Replacing existing alternative address with another one\n"); + free_address (&n->alternative_address); + } if (NULL == session) - session = papi->get_session(papi->cls, - address); + session = papi->get_session (papi->cls, + address); if (NULL == session) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Failed to obtain new session for peer `%s' and address '%s'\n", - GNUNET_i2s(&address->peer), - GST_plugins_a2s(address)); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# session creation failed"), - 1, - GNUNET_NO); - return; - } - GST_ats_new_session(address, - session); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Neighbour `%s' configured alternative address %s\n", - GNUNET_i2s(&n->id), - GST_plugins_a2s(address)); - - n->alternative_address.address = GNUNET_HELLO_address_copy(address); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Failed to obtain new session for peer `%s' and address '%s'\n", + GNUNET_i2s (&address->peer), + GST_plugins_a2s (address)); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# session creation failed"), + 1, + GNUNET_NO); + return; + } + GST_ats_new_session (address, + session); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Neighbour `%s' configured alternative address %s\n", + GNUNET_i2s (&n->id), + GST_plugins_a2s (address)); + + n->alternative_address.address = GNUNET_HELLO_address_copy (address); n->alternative_address.bandwidth_in = bandwidth_in; n->alternative_address.bandwidth_out = bandwidth_out; n->alternative_address.session = session; n->alternative_address.ats_active = GNUNET_NO; n->alternative_address.keep_alive_nonce = 0; - GNUNET_assert(GNUNET_YES == - GST_ats_is_known(n->alternative_address.address, - n->alternative_address.session)); + GNUNET_assert (GNUNET_YES == + GST_ats_is_known (n->alternative_address.address, + n->alternative_address.session)); } @@ -833,40 +846,44 @@ set_alternative_address(struct NeighbourMapEntry *n, * @a use_keepalive_timeout is #GNUNET_YES. */ static struct GNUNET_TIME_Relative -send_with_session(struct NeighbourMapEntry *n, - const void *msgbuf, - size_t msgbuf_size, - uint32_t priority, - struct GNUNET_TIME_Relative timeout, - unsigned int use_keepalive_timeout, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls) +send_with_session (struct NeighbourMapEntry *n, + const void *msgbuf, + size_t msgbuf_size, + uint32_t priority, + struct GNUNET_TIME_Relative timeout, + unsigned int use_keepalive_timeout, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { struct GNUNET_TRANSPORT_PluginFunctions *papi; struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL; - GNUNET_assert(NULL != n->primary_address.session); - if (((NULL == (papi = GST_plugins_find(n->primary_address.address->transport_name)) || - (-1 == papi->send(papi->cls, - n->primary_address.session, - msgbuf, - msgbuf_size, - priority, - (result = (GNUNET_NO == use_keepalive_timeout) ? timeout : - GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - papi->query_keepalive_factor(papi->cls))), - cont, - cont_cls)))) && + GNUNET_assert (NULL != n->primary_address.session); + if ((((NULL == (papi = GST_plugins_find ( + n->primary_address.address->transport_name))) || + (-1 == papi->send (papi->cls, + n->primary_address.session, + msgbuf, + msgbuf_size, + priority, + (result = (GNUNET_NO == use_keepalive_timeout) ? + timeout : + GNUNET_TIME_relative_divide ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + papi-> + query_keepalive_factor (papi->cls))), + cont, + cont_cls)))) && (NULL != cont)) - cont(cont_cls, - &n->id, - GNUNET_SYSERR, - msgbuf_size, - 0); - GST_neighbours_notify_data_sent(n->primary_address.address, - n->primary_address.session, - msgbuf_size); - GNUNET_break(NULL != papi); + cont (cont_cls, + &n->id, + GNUNET_SYSERR, + msgbuf_size, + 0); + GST_neighbours_notify_data_sent (n->primary_address.address, + n->primary_address.session, + msgbuf_size); + GNUNET_break (NULL != papi); return result; } @@ -878,20 +895,20 @@ send_with_session(struct NeighbourMapEntry *n, * @param n the neighbour */ static void -unset_primary_address(struct NeighbourMapEntry *n) +unset_primary_address (struct NeighbourMapEntry *n) { /* Notify monitoring about change */ if (NULL == n->primary_address.address) return; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Disabling primary address\n"); - neighbours_changed_notification(&n->id, - n->primary_address.address, - n->state, - n->timeout, - GNUNET_BANDWIDTH_value_init(0), - GNUNET_BANDWIDTH_value_init(0)); - free_address(&n->primary_address); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Disabling primary address\n"); + neighbours_changed_notification (&n->id, + n->primary_address.address, + n->state, + n->timeout, + GNUNET_BANDWIDTH_value_init (0), + GNUNET_BANDWIDTH_value_init (0)); + free_address (&n->primary_address); } @@ -901,68 +918,68 @@ unset_primary_address(struct NeighbourMapEntry *n) * @param n entry to free */ static void -free_neighbour(struct NeighbourMapEntry *n) +free_neighbour (struct NeighbourMapEntry *n) { struct MessageQueue *mq; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Freeing neighbour state of peer `%s'\n", - GNUNET_i2s(&n->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Freeing neighbour state of peer `%s'\n", + GNUNET_i2s (&n->id)); n->is_active = NULL; /* always free'd by its own continuation! */ /* fail messages currently in the queue */ while (NULL != (mq = n->messages_head)) - { - GNUNET_CONTAINER_DLL_remove(n->messages_head, - n->messages_tail, - mq); - if (NULL != mq->cont) - mq->cont(mq->cont_cls, - GNUNET_SYSERR, - mq->message_buf_size, - 0); - GNUNET_free(mq); - } + { + GNUNET_CONTAINER_DLL_remove (n->messages_head, + n->messages_tail, + mq); + if (NULL != mq->cont) + mq->cont (mq->cont_cls, + GNUNET_SYSERR, + mq->message_buf_size, + 0); + GNUNET_free (mq); + } /* Mark peer as disconnected */ - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED, - GNUNET_TIME_UNIT_FOREVER_ABS); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED, + GNUNET_TIME_UNIT_FOREVER_ABS); /* free addresses and mark as unused */ - unset_primary_address(n); + unset_primary_address (n); if (NULL != n->alternative_address.address) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cleaning up alternative address\n"); - free_address(&n->alternative_address); - } - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(neighbours, - &n->id, - n)); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cleaning up alternative address\n"); + free_address (&n->alternative_address); + } + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (neighbours, + &n->id, + n)); /* Cancel address requests for this peer */ if (NULL != n->suggest_handle) - { - GNUNET_ATS_connectivity_suggest_cancel(n->suggest_handle); - n->suggest_handle = NULL; - } + { + GNUNET_ATS_connectivity_suggest_cancel (n->suggest_handle); + n->suggest_handle = NULL; + } /* Cancel the disconnect task */ if (NULL != n->delayed_disconnect_task) - { - GNUNET_SCHEDULER_cancel(n->delayed_disconnect_task); - n->delayed_disconnect_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (n->delayed_disconnect_task); + n->delayed_disconnect_task = NULL; + } /* Cancel the master task */ if (NULL != n->task) - { - GNUNET_SCHEDULER_cancel(n->task); - n->task = NULL; - } + { + GNUNET_SCHEDULER_cancel (n->task); + n->task = NULL; + } /* free rest of memory */ - GNUNET_free(n); + GNUNET_free (n); } @@ -977,26 +994,26 @@ free_neighbour(struct NeighbourMapEntry *n) * @param physical bytes on wire */ static void -send_disconnect_cont(void *cls, - const struct GNUNET_PeerIdentity *target, - int result, - size_t payload, - size_t physical) +send_disconnect_cont (void *cls, + const struct GNUNET_PeerIdentity *target, + int result, + size_t payload, + size_t physical) { struct NeighbourMapEntry *n; - (void)cls; - (void)result; - (void)payload; - (void)physical; - n = lookup_neighbour(target); + (void) cls; + (void) result; + (void) payload; + (void) physical; + n = lookup_neighbour (target); if (NULL == n) return; /* already gone */ if (GNUNET_TRANSPORT_PS_DISCONNECT != n->state) return; /* have created a fresh entry since */ if (NULL != n->task) - GNUNET_SCHEDULER_cancel(n->task); - n->task = GNUNET_SCHEDULER_add_now(&master_task, n); + GNUNET_SCHEDULER_cancel (n->task); + n->task = GNUNET_SCHEDULER_add_now (&master_task, n); } @@ -1006,43 +1023,44 @@ send_disconnect_cont(void *cls, * @param n neighbour to send DISCONNECT message. */ static void -send_disconnect(struct NeighbourMapEntry *n) +send_disconnect (struct NeighbourMapEntry *n) { struct GNUNET_ATS_SessionDisconnectMessage disconnect_msg; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Sending DISCONNECT message to peer `%4s'\n", - GNUNET_i2s(&n->id)); - disconnect_msg.header.size = htons(sizeof(struct GNUNET_ATS_SessionDisconnectMessage)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Sending DISCONNECT message to peer `%4s'\n", + GNUNET_i2s (&n->id)); + disconnect_msg.header.size = htons (sizeof(struct + GNUNET_ATS_SessionDisconnectMessage)); disconnect_msg.header.type = - htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); - disconnect_msg.reserved = htonl(0); + htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); + disconnect_msg.reserved = htonl (0); disconnect_msg.purpose.size = - htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + - sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + - sizeof(struct GNUNET_TIME_AbsoluteNBO)); + htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + + sizeof(struct GNUNET_TIME_AbsoluteNBO)); disconnect_msg.purpose.purpose = - htonl(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); + htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); disconnect_msg.timestamp = - GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get()); + GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); disconnect_msg.public_key = GST_my_identity.public_key; - GNUNET_assert(GNUNET_OK == - GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, - &disconnect_msg.purpose, - &disconnect_msg.signature)); - - (void)send_with_session(n, - &disconnect_msg, - sizeof(disconnect_msg), - UINT32_MAX, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_NO, - &send_disconnect_cont, - NULL); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# DISCONNECT messages sent"), - 1, - GNUNET_NO); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, + &disconnect_msg.purpose, + &disconnect_msg.signature)); + + (void) send_with_session (n, + &disconnect_msg, + sizeof(disconnect_msg), + UINT32_MAX, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_NO, + &send_disconnect_cont, + NULL); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# DISCONNECT messages sent"), + 1, + GNUNET_NO); } @@ -1052,81 +1070,81 @@ send_disconnect(struct NeighbourMapEntry *n) * @param n neighbour to disconnect from */ static void -disconnect_neighbour(struct NeighbourMapEntry *n) +disconnect_neighbour (struct NeighbourMapEntry *n) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Disconnecting from peer %s in state %s\n", - GNUNET_i2s(&n->id), - GNUNET_TRANSPORT_ps2s(n->state)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Disconnecting from peer %s in state %s\n", + GNUNET_i2s (&n->id), + GNUNET_TRANSPORT_ps2s (n->state)); /* depending on state, notify neighbour and/or upper layers of this peer about disconnect */ switch (n->state) - { - case GNUNET_TRANSPORT_PS_NOT_CONNECTED: - case GNUNET_TRANSPORT_PS_INIT_ATS: - /* other peer is completely unaware of us, no need to send DISCONNECT */ - free_neighbour(n); - return; - - case GNUNET_TRANSPORT_PS_SYN_SENT: - send_disconnect(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_DISCONNECT, - GNUNET_TIME_UNIT_FOREVER_ABS); - break; - - case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: - /* we never ACK'ed the other peer's request, no need to send DISCONNECT */ - free_neighbour(n); - return; - - case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: - /* we DID ACK the other peer's request, must send DISCONNECT */ - send_disconnect(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_DISCONNECT, - GNUNET_TIME_UNIT_FOREVER_ABS); - break; - - case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: - case GNUNET_TRANSPORT_PS_CONNECTED: - case GNUNET_TRANSPORT_PS_RECONNECT_SENT: - /* we are currently connected, need to send disconnect and do - internal notifications and update statistics */ - send_disconnect(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_DISCONNECT, - GNUNET_TIME_UNIT_FOREVER_ABS); - break; + { + case GNUNET_TRANSPORT_PS_NOT_CONNECTED: + case GNUNET_TRANSPORT_PS_INIT_ATS: + /* other peer is completely unaware of us, no need to send DISCONNECT */ + free_neighbour (n); + return; - case GNUNET_TRANSPORT_PS_RECONNECT_ATS: - /* Disconnecting while waiting for an ATS address to reconnect, - * cannot send DISCONNECT */ - free_neighbour(n); - return; + case GNUNET_TRANSPORT_PS_SYN_SENT: + send_disconnect (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_DISCONNECT, + GNUNET_TIME_UNIT_FOREVER_ABS); + break; - case GNUNET_TRANSPORT_PS_DISCONNECT: - /* already disconnected, ignore */ - break; + case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: + /* we never ACK'ed the other peer's request, no need to send DISCONNECT */ + free_neighbour (n); + return; - case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: - /* already cleaned up, how did we get here!? */ - GNUNET_assert(0); - break; + case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: + /* we DID ACK the other peer's request, must send DISCONNECT */ + send_disconnect (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_DISCONNECT, + GNUNET_TIME_UNIT_FOREVER_ABS); + break; + + case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: + case GNUNET_TRANSPORT_PS_CONNECTED: + case GNUNET_TRANSPORT_PS_RECONNECT_SENT: + /* we are currently connected, need to send disconnect and do + internal notifications and update statistics */ + send_disconnect (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_DISCONNECT, + GNUNET_TIME_UNIT_FOREVER_ABS); + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_ATS: + /* Disconnecting while waiting for an ATS address to reconnect, + * cannot send DISCONNECT */ + free_neighbour (n); + return; - default: - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Unhandled state `%s'\n", - GNUNET_TRANSPORT_ps2s(n->state)); - GNUNET_break(0); - break; - } + case GNUNET_TRANSPORT_PS_DISCONNECT: + /* already disconnected, ignore */ + break; + + case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: + /* already cleaned up, how did we get here!? */ + GNUNET_assert (0); + break; + + default: + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unhandled state `%s'\n", + GNUNET_TRANSPORT_ps2s (n->state)); + GNUNET_break (0); + break; + } /* schedule timeout to clean up */ if (NULL != n->task) - GNUNET_SCHEDULER_cancel(n->task); - n->task = GNUNET_SCHEDULER_add_delayed(DISCONNECT_SENT_TIMEOUT, - &master_task, - n); + GNUNET_SCHEDULER_cancel (n->task); + n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT, + &master_task, + n); } @@ -1141,39 +1159,39 @@ disconnect_neighbour(struct NeighbourMapEntry *n) * @a n was freed */ static int -set_incoming_quota(struct NeighbourMapEntry *n, - struct GNUNET_BANDWIDTH_Value32NBO quota) -{ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Setting inbound quota of %u Bps for peer `%s' to all clients\n", - ntohl(quota.value__), GNUNET_i2s(&n->id)); - GNUNET_BANDWIDTH_tracker_update_quota(&n->in_tracker, - quota); - if (0 != ntohl(quota.value__)) - { - struct GNUNET_ATS_SessionQuotaMessage sqm; - - sqm.header.size = htons(sizeof(struct GNUNET_ATS_SessionQuotaMessage)); - sqm.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA); - sqm.quota = quota.value__; - if (NULL != n->primary_address.session) - (void)send_with_session(n, +set_incoming_quota (struct NeighbourMapEntry *n, + struct GNUNET_BANDWIDTH_Value32NBO quota) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Setting inbound quota of %u Bps for peer `%s' to all clients\n", + ntohl (quota.value__), GNUNET_i2s (&n->id)); + GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, + quota); + if (0 != ntohl (quota.value__)) + { + struct GNUNET_ATS_SessionQuotaMessage sqm; + + sqm.header.size = htons (sizeof(struct GNUNET_ATS_SessionQuotaMessage)); + sqm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA); + sqm.quota = quota.value__; + if (NULL != n->primary_address.session) + (void) send_with_session (n, &sqm, sizeof(sqm), UINT32_MAX - 1, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_NO, NULL, NULL); - return GNUNET_YES; - } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Disconnecting peer `%s' due to SET_QUOTA\n", - GNUNET_i2s(&n->id)); - if (GNUNET_YES == test_connected(n)) - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# disconnects due to quota of 0"), - 1, GNUNET_NO); - disconnect_neighbour(n); + return GNUNET_YES; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Disconnecting peer `%s' due to SET_QUOTA\n", + GNUNET_i2s (&n->id)); + if (GNUNET_YES == test_connected (n)) + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# disconnects due to quota of 0"), + 1, GNUNET_NO); + disconnect_neighbour (n); return GNUNET_NO; } @@ -1190,78 +1208,78 @@ set_incoming_quota(struct NeighbourMapEntry *n, * @param bandwidth_out outbound quota to be used when connection is up */ static void -set_primary_address(struct NeighbourMapEntry *n, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) +set_primary_address (struct NeighbourMapEntry *n, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { if (session == n->primary_address.session) + { + GST_validation_set_address_use (n->primary_address.address, + GNUNET_YES); + if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) { - GST_validation_set_address_use(n->primary_address.address, - GNUNET_YES); - if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) - { - n->primary_address.bandwidth_in = bandwidth_in; - if (GNUNET_YES != - set_incoming_quota(n, - bandwidth_in)) - return; - } - if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) - { - n->primary_address.bandwidth_out = bandwidth_out; - send_outbound_quota_to_clients(n); - } - return; + n->primary_address.bandwidth_in = bandwidth_in; + if (GNUNET_YES != + set_incoming_quota (n, + bandwidth_in)) + return; } - if ((NULL != n->primary_address.address) && - (0 == GNUNET_HELLO_address_cmp(address, - n->primary_address.address))) + if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) { - GNUNET_break(0); - return; + n->primary_address.bandwidth_out = bandwidth_out; + send_outbound_quota_to_clients (n); } + return; + } + if ((NULL != n->primary_address.address) && + (0 == GNUNET_HELLO_address_cmp (address, + n->primary_address.address))) + { + GNUNET_break (0); + return; + } if (NULL == session) - { - GNUNET_break(0); - GST_ats_block_address(address, - session); - return; - } + { + GNUNET_break (0); + GST_ats_block_address (address, + session); + return; + } if (NULL != n->primary_address.address) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Replacing existing primary address with another one\n"); - free_address(&n->primary_address); - } - n->primary_address.address = GNUNET_HELLO_address_copy(address); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Replacing existing primary address with another one\n"); + free_address (&n->primary_address); + } + n->primary_address.address = GNUNET_HELLO_address_copy (address); n->primary_address.bandwidth_in = bandwidth_in; n->primary_address.bandwidth_out = bandwidth_out; n->primary_address.session = session; n->primary_address.keep_alive_nonce = 0; - GNUNET_assert(GNUNET_YES == - GST_ats_is_known(n->primary_address.address, - n->primary_address.session)); + GNUNET_assert (GNUNET_YES == + GST_ats_is_known (n->primary_address.address, + n->primary_address.session)); /* subsystems about address use */ - GST_validation_set_address_use(n->primary_address.address, - GNUNET_YES); + GST_validation_set_address_use (n->primary_address.address, + GNUNET_YES); if (GNUNET_YES != - set_incoming_quota(n, - bandwidth_in)) + set_incoming_quota (n, + bandwidth_in)) return; - send_outbound_quota_to_clients(n); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Neighbour `%s' switched to address `%s'\n", - GNUNET_i2s(&n->id), - GST_plugins_a2s(address)); - - neighbours_changed_notification(&n->id, - n->primary_address.address, - n->state, - n->timeout, - n->primary_address.bandwidth_in, - n->primary_address.bandwidth_out); + send_outbound_quota_to_clients (n); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Neighbour `%s' switched to address `%s'\n", + GNUNET_i2s (&n->id), + GST_plugins_a2s (address)); + + neighbours_changed_notification (&n->id, + n->primary_address.address, + n->state, + n->timeout, + n->primary_address.bandwidth_in, + n->primary_address.bandwidth_out); } @@ -1275,75 +1293,78 @@ set_primary_address(struct NeighbourMapEntry *n, * @param physical bytes sent on wire */ static void -transmit_send_continuation(void *cls, - const struct GNUNET_PeerIdentity *receiver, - int success, - size_t size_payload, - size_t physical) +transmit_send_continuation (void *cls, + const struct GNUNET_PeerIdentity *receiver, + int success, + size_t size_payload, + size_t physical) { struct MessageQueue *mq = cls; struct NeighbourMapEntry *n; - if (NULL == (n = lookup_neighbour(receiver))) - { - if (NULL != mq->cont) - mq->cont(mq->cont_cls, - GNUNET_SYSERR /* not connected */, - size_payload, - 0); - GNUNET_free(mq); - return; /* disconnect or other error while transmitting, can happen */ - } + if (NULL == (n = lookup_neighbour (receiver))) + { + if (NULL != mq->cont) + mq->cont (mq->cont_cls, + GNUNET_SYSERR /* not connected */, + size_payload, + 0); + GNUNET_free (mq); + return; /* disconnect or other error while transmitting, can happen */ + } if (n->is_active == mq) - { - /* this is still "our" neighbour, remove us from its queue - and allow it to send the next message now */ - n->is_active = NULL; - if (NULL != n->task) - GNUNET_SCHEDULER_cancel(n->task); - n->task = GNUNET_SCHEDULER_add_now(&master_task, - n); - } + { + /* this is still "our" neighbour, remove us from its queue + and allow it to send the next message now */ + n->is_active = NULL; + if (NULL != n->task) + GNUNET_SCHEDULER_cancel (n->task); + n->task = GNUNET_SCHEDULER_add_now (&master_task, + n); + } if (bytes_in_send_queue < mq->message_buf_size) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Bytes_in_send_queue `%llu', Message_size %u, result: %s, payload %u, on wire %u\n", - bytes_in_send_queue, - (unsigned int)mq->message_buf_size, - (GNUNET_OK == success) ? "OK" : "FAIL", - (unsigned int)size_payload, - (unsigned int)physical); - GNUNET_break(0); - } - - GNUNET_break(size_payload == mq->message_buf_size); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Bytes_in_send_queue `%llu', Message_size %u, result: %s, payload %u, on wire %u\n", + bytes_in_send_queue, + (unsigned int) mq->message_buf_size, + (GNUNET_OK == success) ? "OK" : "FAIL", + (unsigned int) size_payload, + (unsigned int) physical); + GNUNET_break (0); + } + + GNUNET_break (size_payload == mq->message_buf_size); bytes_in_send_queue -= mq->message_buf_size; - GNUNET_STATISTICS_set(GST_stats, - gettext_noop("# bytes in message queue for other peers"), - bytes_in_send_queue, - GNUNET_NO); + GNUNET_STATISTICS_set (GST_stats, + gettext_noop ( + "# bytes in message queue for other peers"), + bytes_in_send_queue, + GNUNET_NO); if (GNUNET_OK == success) - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# messages transmitted to other peers"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# messages transmitted to other peers"), + 1, + GNUNET_NO); else - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# transmission failures for messages to other peers"), - 1, GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending message to `%s' of type %u with %u bytes was a %s\n", - GNUNET_i2s(receiver), - ntohs(((struct GNUNET_MessageHeader *)mq->message_buf)->type), - (unsigned int)mq->message_buf_size, - (success == GNUNET_OK) ? "success" : "FAILURE"); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ( + "# transmission failures for messages to other peers"), + 1, GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending message to `%s' of type %u with %u bytes was a %s\n", + GNUNET_i2s (receiver), + ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type), + (unsigned int) mq->message_buf_size, + (success == GNUNET_OK) ? "success" : "FAILURE"); if (NULL != mq->cont) - mq->cont(mq->cont_cls, - success, - size_payload, - physical); - GNUNET_free(mq); + mq->cont (mq->cont_cls, + success, + size_payload, + physical); + GNUNET_free (mq); } @@ -1359,77 +1380,78 @@ transmit_send_continuation(void *cls, * @param n target peer for which to transmit */ static void -try_transmission_to_peer(struct NeighbourMapEntry *n) +try_transmission_to_peer (struct NeighbourMapEntry *n) { struct MessageQueue *mq; struct GNUNET_TIME_Relative timeout; if (NULL == n->primary_address.address) - { - /* no address, why are we here? */ - GNUNET_break(0); - return; - } + { + /* no address, why are we here? */ + GNUNET_break (0); + return; + } if ((0 == n->primary_address.address->address_length) && (NULL == n->primary_address.session)) - { - /* no address, why are we here? */ - GNUNET_break(0); - return; - } + { + /* no address, why are we here? */ + GNUNET_break (0); + return; + } if (NULL != n->is_active) - { - /* transmission already pending */ - return; - } + { + /* transmission already pending */ + return; + } /* timeout messages from the queue that are past their due date */ while (NULL != (mq = n->messages_head)) - { - timeout = GNUNET_TIME_absolute_get_remaining(mq->timeout); - if (timeout.rel_value_us > 0) - break; - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# messages timed out while in transport queue"), - 1, - GNUNET_NO); - GNUNET_CONTAINER_DLL_remove(n->messages_head, - n->messages_tail, - mq); - n->is_active = mq; - transmit_send_continuation(mq, - &n->id, - GNUNET_SYSERR, - mq->message_buf_size, - 0); /* timeout */ - } + { + timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout); + if (timeout.rel_value_us > 0) + break; + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# messages timed out while in transport queue"), + 1, + GNUNET_NO); + GNUNET_CONTAINER_DLL_remove (n->messages_head, + n->messages_tail, + mq); + n->is_active = mq; + transmit_send_continuation (mq, + &n->id, + GNUNET_SYSERR, + mq->message_buf_size, + 0); /* timeout */ + } if (NULL == mq) return; /* no more messages */ if (NULL == n->primary_address.address) - { - /* transmit_send_continuation() caused us to drop session, - can't try transmission anymore. */ - return; - } + { + /* transmit_send_continuation() caused us to drop session, + can't try transmission anymore. */ + return; + } - GNUNET_CONTAINER_DLL_remove(n->messages_head, - n->messages_tail, - mq); + GNUNET_CONTAINER_DLL_remove (n->messages_head, + n->messages_tail, + mq); n->is_active = mq; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Giving message with %u bytes to plugin session %p\n", - (unsigned int)mq->message_buf_size, - n->primary_address.session); - (void)send_with_session(n, - mq->message_buf, - mq->message_buf_size, - 0 /* priority */, - timeout, - GNUNET_NO, - &transmit_send_continuation, - mq); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Giving message with %u bytes to plugin session %p\n", + (unsigned int) mq->message_buf_size, + n->primary_address.session); + (void) send_with_session (n, + mq->message_buf, + mq->message_buf_size, + 0 /* priority */, + timeout, + GNUNET_NO, + &transmit_send_continuation, + mq); } @@ -1442,45 +1464,45 @@ try_transmission_to_peer(struct NeighbourMapEntry *n) * @param n neighbour that went idle and needs a keepalive */ static void -send_keepalive(struct NeighbourMapEntry *n) +send_keepalive (struct NeighbourMapEntry *n) { struct GNUNET_ATS_SessionKeepAliveMessage m; struct GNUNET_TIME_Relative timeout; uint32_t nonce; - GNUNET_assert((GNUNET_TRANSPORT_PS_CONNECTED == n->state) || - (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)); - if (GNUNET_TIME_absolute_get_remaining(n->keep_alive_time).rel_value_us > 0) + GNUNET_assert ((GNUNET_TRANSPORT_PS_CONNECTED == n->state) || + (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)); + if (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time).rel_value_us > 0) return; /* no keepalive needed at this time */ nonce = 0; /* 0 indicates 'not set' */ while (0 == nonce) - nonce = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, - UINT32_MAX); - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Sending KEEPALIVE to peer `%s' with nonce %u\n", - GNUNET_i2s(&n->id), - nonce); - m.header.size = htons(sizeof(struct GNUNET_ATS_SessionKeepAliveMessage)); - m.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); - m.nonce = htonl(nonce); - - timeout = send_with_session(n, - &m, - sizeof(m), - UINT32_MAX /* priority */, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, - NULL, NULL); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# KEEPALIVES sent"), - 1, - GNUNET_NO); + nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, + UINT32_MAX); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending KEEPALIVE to peer `%s' with nonce %u\n", + GNUNET_i2s (&n->id), + nonce); + m.header.size = htons (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage)); + m.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); + m.nonce = htonl (nonce); + + timeout = send_with_session (n, + &m, + sizeof(m), + UINT32_MAX /* priority */, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, + NULL, NULL); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# KEEPALIVES sent"), + 1, + GNUNET_NO); n->primary_address.keep_alive_nonce = nonce; n->expect_latency_response = GNUNET_YES; - n->last_keep_alive_time = GNUNET_TIME_absolute_get(); - n->keep_alive_time = GNUNET_TIME_relative_to_absolute(timeout); + n->last_keep_alive_time = GNUNET_TIME_absolute_get (); + n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout); } @@ -1492,57 +1514,59 @@ send_keepalive(struct NeighbourMapEntry *n) * @param m the keep alive message containing the nonce to respond to */ void -GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour, - const struct GNUNET_MessageHeader *m) +GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour, + const struct GNUNET_MessageHeader *m) { struct NeighbourMapEntry *n; const struct GNUNET_ATS_SessionKeepAliveMessage *msg_in; struct GNUNET_ATS_SessionKeepAliveMessage msg; - if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs(m->size)) - { - GNUNET_break_op(0); - return; - } - - msg_in = (const struct GNUNET_ATS_SessionKeepAliveMessage *)m; - if (NULL == (n = lookup_neighbour(neighbour))) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# KEEPALIVE messages discarded (peer unknown)"), - 1, GNUNET_NO); - return; - } + if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs (m->size)) + { + GNUNET_break_op (0); + return; + } + + msg_in = (const struct GNUNET_ATS_SessionKeepAliveMessage *) m; + if (NULL == (n = lookup_neighbour (neighbour))) + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# KEEPALIVE messages discarded (peer unknown)"), + 1, GNUNET_NO); + return; + } if (NULL == n->primary_address.session) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# KEEPALIVE messages discarded (no session)"), - 1, GNUNET_NO); - return; - } - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received KEEPALIVE request from peer `%s' with nonce %u\n", - GNUNET_i2s(&n->id), - ntohl(msg_in->nonce)); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# KEEPALIVES received in good order"), - 1, - GNUNET_NO); + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# KEEPALIVE messages discarded (no session)"), + 1, GNUNET_NO); + return; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received KEEPALIVE request from peer `%s' with nonce %u\n", + GNUNET_i2s (&n->id), + ntohl (msg_in->nonce)); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# KEEPALIVES received in good order"), + 1, + GNUNET_NO); /* send reply to allow neighbour to measure latency */ - msg.header.size = htons(sizeof(struct GNUNET_ATS_SessionKeepAliveMessage)); - msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); + msg.header.size = htons (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage)); + msg.header.type = htons ( + GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); msg.nonce = msg_in->nonce; - (void)send_with_session(n, - &msg, - sizeof(struct GNUNET_ATS_SessionKeepAliveMessage), - UINT32_MAX /* priority */, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_YES, - NULL, NULL); + (void) send_with_session (n, + &msg, + sizeof(struct GNUNET_ATS_SessionKeepAliveMessage), + UINT32_MAX /* priority */, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, + NULL, NULL); } @@ -1555,97 +1579,105 @@ GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour, * @param m the message containing the keep alive response */ void -GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour, - const struct GNUNET_MessageHeader *m) +GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour, + const struct GNUNET_MessageHeader *m) { struct NeighbourMapEntry *n; const struct GNUNET_ATS_SessionKeepAliveMessage *msg; struct GNUNET_TRANSPORT_PluginFunctions *papi; struct GNUNET_TIME_Relative latency; - if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs(m->size)) - { - GNUNET_break_op(0); - return; - } - - msg = (const struct GNUNET_ATS_SessionKeepAliveMessage *)m; - if (NULL == (n = lookup_neighbour(neighbour))) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# KEEPALIVE_RESPONSEs discarded (not connected)"), - 1, - GNUNET_NO); - return; - } + if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs (m->size)) + { + GNUNET_break_op (0); + return; + } + + msg = (const struct GNUNET_ATS_SessionKeepAliveMessage *) m; + if (NULL == (n = lookup_neighbour (neighbour))) + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# KEEPALIVE_RESPONSEs discarded (not connected)"), + 1, + GNUNET_NO); + return; + } if ((GNUNET_TRANSPORT_PS_CONNECTED != n->state) || (GNUNET_YES != n->expect_latency_response)) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# KEEPALIVE_RESPONSEs discarded (not expected)"), - 1, - GNUNET_NO); - return; - } + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# KEEPALIVE_RESPONSEs discarded (not expected)"), + 1, + GNUNET_NO); + return; + } if (NULL == n->primary_address.address) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# KEEPALIVE_RESPONSEs discarded (address changed)"), - 1, - GNUNET_NO); - return; - } - if (n->primary_address.keep_alive_nonce != ntohl(msg->nonce)) - { - if (0 == n->primary_address.keep_alive_nonce) - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# KEEPALIVE_RESPONSEs discarded (no nonce)"), - 1, - GNUNET_NO); - else - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# KEEPALIVE_RESPONSEs discarded (bad nonce)"), - 1, - GNUNET_NO); - return; - } - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# KEEPALIVE_RESPONSEs received (OK)"), - 1, - GNUNET_NO); + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# KEEPALIVE_RESPONSEs discarded (address changed)"), + 1, + GNUNET_NO); + return; + } + if (n->primary_address.keep_alive_nonce != ntohl (msg->nonce)) + { + if (0 == n->primary_address.keep_alive_nonce) + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# KEEPALIVE_RESPONSEs discarded (no nonce)"), + 1, + GNUNET_NO); + else + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# KEEPALIVE_RESPONSEs discarded (bad nonce)"), + 1, + GNUNET_NO); + return; + } + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# KEEPALIVE_RESPONSEs received (OK)"), + 1, + GNUNET_NO); /* Update session timeout here */ - if (NULL != (papi = GST_plugins_find(n->primary_address.address->transport_name))) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Updating session for peer `%s' for session %p\n", - GNUNET_i2s(&n->id), - n->primary_address.session); - papi->update_session_timeout(papi->cls, - &n->id, - n->primary_address.session); - } + if (NULL != (papi = GST_plugins_find ( + n->primary_address.address->transport_name))) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Updating session for peer `%s' for session %p\n", + GNUNET_i2s (&n->id), + n->primary_address.session); + papi->update_session_timeout (papi->cls, + &n->id, + n->primary_address.session); + } else - { - GNUNET_break(0); - } + { + GNUNET_break (0); + } n->primary_address.keep_alive_nonce = 0; n->expect_latency_response = GNUNET_NO; - set_state_and_timeout(n, - n->state, - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); - - latency = GNUNET_TIME_absolute_get_duration(n->last_keep_alive_time); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received KEEPALIVE_RESPONSE from peer `%s', latency is %s\n", - GNUNET_i2s(&n->id), - GNUNET_STRINGS_relative_time_to_string(latency, - GNUNET_YES)); - GST_ats_update_delay(n->primary_address.address, - GNUNET_TIME_relative_divide(latency, - 2)); + set_state_and_timeout (n, + n->state, + GNUNET_TIME_relative_to_absolute ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); + + latency = GNUNET_TIME_absolute_get_duration (n->last_keep_alive_time); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received KEEPALIVE_RESPONSE from peer `%s', latency is %s\n", + GNUNET_i2s (&n->id), + GNUNET_STRINGS_relative_time_to_string (latency, + GNUNET_YES)); + GST_ats_update_delay (n->primary_address.address, + GNUNET_TIME_relative_divide (latency, + 2)); } @@ -1662,74 +1694,76 @@ GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour, * @return how long to wait before reading more from this sender */ struct GNUNET_TIME_Relative -GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender, - ssize_t size, - int *do_forward) +GST_neighbours_calculate_receive_delay (const struct + GNUNET_PeerIdentity *sender, + ssize_t size, + int *do_forward) { struct NeighbourMapEntry *n; struct GNUNET_TIME_Relative ret; if (NULL == neighbours) - { - *do_forward = GNUNET_NO; - return GNUNET_TIME_UNIT_FOREVER_REL; /* This can happen during shutdown */ - } - if (NULL == (n = lookup_neighbour(sender))) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# messages discarded due to lack of neighbour record"), - 1, - GNUNET_NO); - *do_forward = GNUNET_NO; - return GNUNET_TIME_UNIT_ZERO; - } - if (!test_connected(n)) - { - *do_forward = GNUNET_SYSERR; - return GNUNET_TIME_UNIT_ZERO; - } - if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, size)) - { - n->quota_violation_count++; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Bandwidth quota (%u b/s) violation detected (total of %u).\n", - n->in_tracker.available_bytes_per_s__, - n->quota_violation_count); - /* Discount 32k per violation */ - GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, -32 * 1024); - } + { + *do_forward = GNUNET_NO; + return GNUNET_TIME_UNIT_FOREVER_REL; /* This can happen during shutdown */ + } + if (NULL == (n = lookup_neighbour (sender))) + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# messages discarded due to lack of neighbour record"), + 1, + GNUNET_NO); + *do_forward = GNUNET_NO; + return GNUNET_TIME_UNIT_ZERO; + } + if (! test_connected (n)) + { + *do_forward = GNUNET_SYSERR; + return GNUNET_TIME_UNIT_ZERO; + } + if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, size)) + { + n->quota_violation_count++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Bandwidth quota (%u b/s) violation detected (total of %u).\n", + n->in_tracker.available_bytes_per_s__, + n->quota_violation_count); + /* Discount 32k per violation */ + GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, -32 * 1024); + } else + { + if (n->quota_violation_count > 0) { - if (n->quota_violation_count > 0) - { - /* try to add 32k back */ - GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, 32 * 1024); - n->quota_violation_count--; - } + /* try to add 32k back */ + GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 32 * 1024); + n->quota_violation_count--; } + } if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# bandwidth quota violations by other peers"), - 1, GNUNET_NO); - *do_forward = GNUNET_NO; - return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT; - } + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# bandwidth quota violations by other peers"), + 1, GNUNET_NO); + *do_forward = GNUNET_NO; + return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT; + } *do_forward = GNUNET_YES; - ret = GNUNET_BANDWIDTH_tracker_get_delay(&n->in_tracker, 32 * 1024); + ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 32 * 1024); if (ret.rel_value_us > 0) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n", - (long long)n->in_tracker.consumption_since_last_update__, - (unsigned int)n->in_tracker.available_bytes_per_s__, - GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# ms throttling suggested"), - (int64_t)ret.rel_value_us / 1000LL, - GNUNET_NO); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n", + (long long) n->in_tracker.consumption_since_last_update__, + (unsigned int) n->in_tracker.available_bytes_per_s__, + GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# ms throttling suggested"), + (int64_t) ret.rel_value_us / 1000LL, + GNUNET_NO); + } return ret; } @@ -1745,61 +1779,61 @@ GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender, * @param cont_cls closure for @a cont */ void -GST_neighbours_send(const struct GNUNET_PeerIdentity *target, - const void *msg, - size_t msg_size, - struct GNUNET_TIME_Relative timeout, - GST_NeighbourSendContinuation cont, - void *cont_cls) +GST_neighbours_send (const struct GNUNET_PeerIdentity *target, + const void *msg, + size_t msg_size, + struct GNUNET_TIME_Relative timeout, + GST_NeighbourSendContinuation cont, + void *cont_cls) { struct NeighbourMapEntry *n; struct MessageQueue *mq; /* All ove these cases should never happen; they are all API violations. But we check anyway, just to be sure. */ - if (NULL == (n = lookup_neighbour(target))) - { - GNUNET_break(0); - if (NULL != cont) - cont(cont_cls, - GNUNET_SYSERR, - msg_size, - 0); - return; - } - if (GNUNET_YES != test_connected(n)) - { - GNUNET_break(0); - if (NULL != cont) - cont(cont_cls, - GNUNET_SYSERR, - msg_size, - 0); - return; - } + if (NULL == (n = lookup_neighbour (target))) + { + GNUNET_break (0); + if (NULL != cont) + cont (cont_cls, + GNUNET_SYSERR, + msg_size, + 0); + return; + } + if (GNUNET_YES != test_connected (n)) + { + GNUNET_break (0); + if (NULL != cont) + cont (cont_cls, + GNUNET_SYSERR, + msg_size, + 0); + return; + } bytes_in_send_queue += msg_size; - GNUNET_STATISTICS_set(GST_stats, - gettext_noop - ("# bytes in message queue for other peers"), - bytes_in_send_queue, GNUNET_NO); - mq = GNUNET_malloc(sizeof(struct MessageQueue) + msg_size); + GNUNET_STATISTICS_set (GST_stats, + gettext_noop + ("# bytes in message queue for other peers"), + bytes_in_send_queue, GNUNET_NO); + mq = GNUNET_malloc (sizeof(struct MessageQueue) + msg_size); mq->cont = cont; mq->cont_cls = cont_cls; - GNUNET_memcpy(&mq[1], msg, msg_size); - mq->message_buf = (const char *)&mq[1]; + GNUNET_memcpy (&mq[1], msg, msg_size); + mq->message_buf = (const char *) &mq[1]; mq->message_buf_size = msg_size; - mq->timeout = GNUNET_TIME_relative_to_absolute(timeout); - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Enqueueing %u bytes to send to peer %s\n", - (unsigned int)msg_size, - GNUNET_i2s(target)); - GNUNET_CONTAINER_DLL_insert_tail(n->messages_head, - n->messages_tail, - mq); + mq->timeout = GNUNET_TIME_relative_to_absolute (timeout); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Enqueueing %u bytes to send to peer %s\n", + (unsigned int) msg_size, + GNUNET_i2s (target)); + GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, + n->messages_tail, + mq); if (NULL != n->task) - GNUNET_SCHEDULER_cancel(n->task); - n->task = GNUNET_SCHEDULER_add_now(&master_task, n); + GNUNET_SCHEDULER_cancel (n->task); + n->task = GNUNET_SCHEDULER_add_now (&master_task, n); } @@ -1816,77 +1850,81 @@ GST_neighbours_send(const struct GNUNET_PeerIdentity *target, * @param size_on_wire how much bandwidth was consumed on the wire (ignored) */ static void -send_session_syn_cont(void *cls, - const struct GNUNET_PeerIdentity *target, - int result, - size_t size_payload, - size_t size_on_wire) +send_session_syn_cont (void *cls, + const struct GNUNET_PeerIdentity *target, + int result, + size_t size_payload, + size_t size_on_wire) { struct NeighbourMapEntry *n; - (void)cls; - (void)size_payload; - (void)size_on_wire; - n = lookup_neighbour(target); + (void) cls; + (void) size_payload; + (void) size_on_wire; + n = lookup_neighbour (target); if (NULL == n) - { - /* SYN continuation was called after neighbor was freed, - * for example due to a time out for the state or the session - * used was already terminated: nothing to do here... */ - return; - } + { + /* SYN continuation was called after neighbor was freed, + * for example due to a time out for the state or the session + * used was already terminated: nothing to do here... */ + return; + } if ((GNUNET_TRANSPORT_PS_SYN_SENT != n->state) && (GNUNET_TRANSPORT_PS_RECONNECT_SENT != n->state) && (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT != n->state)) - { - /* SYN continuation was called after neighbor changed state, - * for example due to a time out for the state or the session - * used was already terminated: nothing to do here... */ - return; - } + { + /* SYN continuation was called after neighbor changed state, + * for example due to a time out for the state or the session + * used was already terminated: nothing to do here... */ + return; + } if (GNUNET_OK == result) return; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Failed to send SYN message to peer `%s'\n"), - GNUNET_i2s(target)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Failed to send SYN message to peer `%s'\n"), + GNUNET_i2s (target)); switch (n->state) - { - case GNUNET_TRANSPORT_PS_SYN_SENT: - /* Remove address and request an additional one */ - unset_primary_address(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_INIT_ATS, - GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_RECONNECT_SENT: - /* Remove address and request an additional one */ - unset_primary_address(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_RECONNECT_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: - /* Remove address and request and go back to primary address */ - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# Failed attempts to switch addresses (failed to send SYN CONT)"), - 1, - GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Switch failed, cleaning up alternative address\n"); - free_address(&n->alternative_address); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_CONNECTED, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - break; - - default: - disconnect_neighbour(n); - break; - } + { + case GNUNET_TRANSPORT_PS_SYN_SENT: + /* Remove address and request an additional one */ + unset_primary_address (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_INIT_ATS, + GNUNET_TIME_relative_to_absolute ( + FAST_RECONNECT_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_SENT: + /* Remove address and request an additional one */ + unset_primary_address (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_RECONNECT_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: + /* Remove address and request and go back to primary address */ + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# Failed attempts to switch addresses (failed to send SYN CONT)"), + 1, + GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Switch failed, cleaning up alternative address\n"); + free_address (&n->alternative_address); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_CONNECTED, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + break; + + default: + disconnect_neighbour (n); + break; + } } @@ -1896,94 +1934,98 @@ send_session_syn_cont(void *cls, * @param na address to use */ static void -send_syn(struct NeighbourAddress *na) +send_syn (struct NeighbourAddress *na) { struct GNUNET_TRANSPORT_PluginFunctions *papi; struct TransportSynMessage connect_msg; struct NeighbourMapEntry *n; - GNUNET_assert(NULL != na->session); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Sending SYN message to peer `%s' at %s\n", - GNUNET_i2s(&na->address->peer), - GST_plugins_a2s(na->address)); - - papi = GST_plugins_find(na->address->transport_name); - GNUNET_assert(NULL != papi); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# SYN messages sent"), - 1, GNUNET_NO); - na->connect_timestamp = GNUNET_TIME_absolute_get(); - connect_msg.header.size = htons(sizeof(struct TransportSynMessage)); - connect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN); - connect_msg.reserved = htonl(0); - connect_msg.timestamp = GNUNET_TIME_absolute_hton(na->connect_timestamp); + GNUNET_assert (NULL != na->session); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Sending SYN message to peer `%s' at %s\n", + GNUNET_i2s (&na->address->peer), + GST_plugins_a2s (na->address)); + + papi = GST_plugins_find (na->address->transport_name); + GNUNET_assert (NULL != papi); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# SYN messages sent"), + 1, GNUNET_NO); + na->connect_timestamp = GNUNET_TIME_absolute_get (); + connect_msg.header.size = htons (sizeof(struct TransportSynMessage)); + connect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN); + connect_msg.reserved = htonl (0); + connect_msg.timestamp = GNUNET_TIME_absolute_hton (na->connect_timestamp); if (-1 == - papi->send(papi->cls, - na->session, - (const char *)&connect_msg, - sizeof(struct TransportSynMessage), - UINT_MAX, - SETUP_CONNECTION_TIMEOUT, - &send_session_syn_cont, NULL)) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - _("Failed to transmit SYN message to %s\n"), - GST_plugins_a2s(na->address)); - n = lookup_neighbour(&na->address->peer); - if (NULL == n) - { - GNUNET_break(0); - return; - } - switch (n->state) - { - case GNUNET_TRANSPORT_PS_SYN_SENT: - /* Remove address and request and additional one */ - GNUNET_assert(na == &n->primary_address); - unset_primary_address(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_INIT_ATS, - GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT)); - /* Hard failure to send the SYN message with this address: - Destroy address and session */ - break; - - case GNUNET_TRANSPORT_PS_RECONNECT_SENT: - /* Remove address and request an additional one */ - GNUNET_assert(na == &n->primary_address); - unset_primary_address(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_RECONNECT_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: - GNUNET_assert(na == &n->alternative_address); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# Failed attempts to switch addresses (failed to send SYN)"), - 1, - GNUNET_NO); - /* Remove address and request an additional one */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Switch failed, cleaning up alternative address\n"); - free_address(&n->alternative_address); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_CONNECTED, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - break; - - default: - GNUNET_break(0); - disconnect_neighbour(n); - break; - } + papi->send (papi->cls, + na->session, + (const char *) &connect_msg, + sizeof(struct TransportSynMessage), + UINT_MAX, + SETUP_CONNECTION_TIMEOUT, + &send_session_syn_cont, NULL)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _ ("Failed to transmit SYN message to %s\n"), + GST_plugins_a2s (na->address)); + n = lookup_neighbour (&na->address->peer); + if (NULL == n) + { + GNUNET_break (0); return; } - GST_neighbours_notify_data_sent(na->address, - na->session, - sizeof(struct TransportSynMessage)); + switch (n->state) + { + case GNUNET_TRANSPORT_PS_SYN_SENT: + /* Remove address and request and additional one */ + GNUNET_assert (na == &n->primary_address); + unset_primary_address (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_INIT_ATS, + GNUNET_TIME_relative_to_absolute ( + FAST_RECONNECT_TIMEOUT)); + /* Hard failure to send the SYN message with this address: + Destroy address and session */ + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_SENT: + /* Remove address and request an additional one */ + GNUNET_assert (na == &n->primary_address); + unset_primary_address (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_RECONNECT_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: + GNUNET_assert (na == &n->alternative_address); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# Failed attempts to switch addresses (failed to send SYN)"), + 1, + GNUNET_NO); + /* Remove address and request an additional one */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Switch failed, cleaning up alternative address\n"); + free_address (&n->alternative_address); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_CONNECTED, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + break; + + default: + GNUNET_break (0); + disconnect_neighbour (n); + break; + } + return; + } + GST_neighbours_notify_data_sent (na->address, + na->session, + sizeof(struct TransportSynMessage)); } @@ -2000,50 +2042,52 @@ send_syn(struct NeighbourAddress *na) * @param size_on_wire how much bandwidth was consumed on the wire (ignored) */ static void -send_session_syn_ack_cont(void *cls, - const struct GNUNET_PeerIdentity *target, - int result, - size_t size_payload, - size_t size_on_wire) +send_session_syn_ack_cont (void *cls, + const struct GNUNET_PeerIdentity *target, + int result, + size_t size_payload, + size_t size_on_wire) { struct NeighbourMapEntry *n; - (void)cls; - (void)size_payload; - (void)size_on_wire; - n = lookup_neighbour(target); + (void) cls; + (void) size_payload; + (void) size_on_wire; + n = lookup_neighbour (target); if (NULL == n) - { - /* SYN_ACK continuation was called after neighbor was freed, - * for example due to a time out for the state or the session - * used was already terminated: nothing to do here... */ - return; - } + { + /* SYN_ACK continuation was called after neighbor was freed, + * for example due to a time out for the state or the session + * used was already terminated: nothing to do here... */ + return; + } if (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) - { - /* SYN_ACK continuation was called after neighbor changed state, - * for example due to a time out for the state or the session - * used was already terminated: nothing to do here... */ - return; - } + { + /* SYN_ACK continuation was called after neighbor changed state, + * for example due to a time out for the state or the session + * used was already terminated: nothing to do here... */ + return; + } if (GNUNET_OK == result) return; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Failed to send SYN_ACK message to peer `%s' using address `%s'\n"), - GNUNET_i2s(target), - GST_plugins_a2s(n->primary_address.address)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ( + "Failed to send SYN_ACK message to peer `%s' using address `%s'\n"), + GNUNET_i2s (target), + GST_plugins_a2s (n->primary_address.address)); /* Remove address and request and additional one */ /* FIXME: what if the neighbour's primary address changed in the meantime? Might want to instead pass "something" around in closure to be sure. */ - unset_primary_address(n); + unset_primary_address (n); n->ack_state = ACK_SEND_SYN_ACK; - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SYN_RECV_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SYN_RECV_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); } @@ -2055,8 +2099,8 @@ send_session_syn_ack_cont(void *cls, * @return #GNUNET_SYSERR if sending immediately failed, #GNUNET_OK otherwise */ static void -send_syn_ack_message(struct NeighbourAddress *na, - struct GNUNET_TIME_Absolute timestamp) +send_syn_ack_message (struct NeighbourAddress *na, + struct GNUNET_TIME_Absolute timestamp) { const struct GNUNET_HELLO_Address *address = na->address; struct GNUNET_ATS_Session *session = na->session; @@ -2064,61 +2108,63 @@ send_syn_ack_message(struct NeighbourAddress *na, struct TransportSynMessage connect_msg; struct NeighbourMapEntry *n; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Sending SYN_ACK to peer `%s'\n", - GNUNET_i2s(&address->peer)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Sending SYN_ACK to peer `%s'\n", + GNUNET_i2s (&address->peer)); - if (NULL == (papi = GST_plugins_find(address->transport_name))) - { - GNUNET_break(0); - return; - } + if (NULL == (papi = GST_plugins_find (address->transport_name))) + { + GNUNET_break (0); + return; + } if (NULL == session) - session = papi->get_session(papi->cls, - address); + session = papi->get_session (papi->cls, + address); if (NULL == session) - { - GNUNET_break(0); - return; - } - GST_ats_new_session(address, - session); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# SYN_ACK messages sent"), - 1, GNUNET_NO); - connect_msg.header.size = htons(sizeof(struct TransportSynMessage)); - connect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK); - connect_msg.reserved = htonl(0); - connect_msg.timestamp = GNUNET_TIME_absolute_hton(timestamp); + { + GNUNET_break (0); + return; + } + GST_ats_new_session (address, + session); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# SYN_ACK messages sent"), + 1, GNUNET_NO); + connect_msg.header.size = htons (sizeof(struct TransportSynMessage)); + connect_msg.header.type = htons ( + GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK); + connect_msg.reserved = htonl (0); + connect_msg.timestamp = GNUNET_TIME_absolute_hton (timestamp); if (GNUNET_SYSERR == - papi->send(papi->cls, - session, - (const char *)&connect_msg, - sizeof(struct TransportSynMessage), - UINT_MAX, - GNUNET_TIME_UNIT_FOREVER_REL, - &send_session_syn_ack_cont, NULL)) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - _("Failed to transmit SYN_ACK message to %s\n"), - GST_plugins_a2s(address)); - - n = lookup_neighbour(&address->peer); - if (NULL == n) - { - GNUNET_break(0); - return; - } - /* Remove address and request and additional one */ - unset_primary_address(n); - n->ack_state = ACK_SEND_SYN_ACK; - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SYN_RECV_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); + papi->send (papi->cls, + session, + (const char *) &connect_msg, + sizeof(struct TransportSynMessage), + UINT_MAX, + GNUNET_TIME_UNIT_FOREVER_REL, + &send_session_syn_ack_cont, NULL)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _ ("Failed to transmit SYN_ACK message to %s\n"), + GST_plugins_a2s (address)); + + n = lookup_neighbour (&address->peer); + if (NULL == n) + { + GNUNET_break (0); return; } + /* Remove address and request and additional one */ + unset_primary_address (n); + n->ack_state = ACK_SEND_SYN_ACK; + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SYN_RECV_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + return; + } } @@ -2131,7 +2177,7 @@ send_syn_ack_message(struct NeighbourAddress *na, * @param cls the `struct NeighbourMapEntry` to update calculations for */ static void -inbound_bw_tracker_update(void *cls) +inbound_bw_tracker_update (void *cls) { struct NeighbourMapEntry *n = cls; struct GNUNET_TRANSPORT_PluginFunctions *papi; @@ -2140,23 +2186,23 @@ inbound_bw_tracker_update(void *cls) if (NULL == n->primary_address.address) return; /* not active, ignore */ - papi = GST_plugins_find(n->primary_address.address->transport_name); - GNUNET_assert(NULL != papi); + papi = GST_plugins_find (n->primary_address.address->transport_name); + GNUNET_assert (NULL != papi); if (NULL == papi->update_inbound_delay) return; - delay = GST_neighbours_calculate_receive_delay(&n->id, - 0, - &do_forward); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "New inbound delay for peer `%s' is %llu ms\n", - GNUNET_i2s(&n->id), - (unsigned long long)delay.rel_value_us / 1000LL); + delay = GST_neighbours_calculate_receive_delay (&n->id, + 0, + &do_forward); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "New inbound delay for peer `%s' is %llu ms\n", + GNUNET_i2s (&n->id), + (unsigned long long) delay.rel_value_us / 1000LL); if (NULL == n->primary_address.session) return; - papi->update_inbound_delay(papi->cls, - &n->id, - n->primary_address.session, - delay); + papi->update_inbound_delay (papi->cls, + &n->id, + n->primary_address.session, + delay); } @@ -2167,44 +2213,44 @@ inbound_bw_tracker_update(void *cls) * @return new neighbour map entry */ static struct NeighbourMapEntry * -setup_neighbour(const struct GNUNET_PeerIdentity *peer) +setup_neighbour (const struct GNUNET_PeerIdentity *peer) { struct NeighbourMapEntry *n; if (0 == - memcmp(&GST_my_identity, - peer, - sizeof(struct GNUNET_PeerIdentity))) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cowardly refusing to consider myself my neighbour!\n"); - return NULL; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Creating new neighbour entry for `%s'\n", - GNUNET_i2s(peer)); - n = GNUNET_new(struct NeighbourMapEntry); + memcmp (&GST_my_identity, + peer, + sizeof(struct GNUNET_PeerIdentity))) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cowardly refusing to consider myself my neighbour!\n"); + return NULL; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Creating new neighbour entry for `%s'\n", + GNUNET_i2s (peer)); + n = GNUNET_new (struct NeighbourMapEntry); n->id = *peer; n->ack_state = ACK_UNDEFINED; - n->last_util_transmission = GNUNET_TIME_absolute_get(); + n->last_util_transmission = GNUNET_TIME_absolute_get (); n->neighbour_receive_quota = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; - GNUNET_BANDWIDTH_tracker_init(&n->in_tracker, - &inbound_bw_tracker_update, - n, - GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, - MAX_BANDWIDTH_CARRY_S); - n->task = GNUNET_SCHEDULER_add_now(&master_task, n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_NOT_CONNECTED, - GNUNET_TIME_UNIT_FOREVER_ABS); - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put(neighbours, - &n->id, - n, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - n->suggest_handle = GNUNET_ATS_connectivity_suggest(GST_ats_connect, - peer, - 0); + GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, + &inbound_bw_tracker_update, + n, + GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, + MAX_BANDWIDTH_CARRY_S); + n->task = GNUNET_SCHEDULER_add_now (&master_task, n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_NOT_CONNECTED, + GNUNET_TIME_UNIT_FOREVER_ABS); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put (neighbours, + &n->id, + n, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, + peer, + 0); return n; } @@ -2213,7 +2259,8 @@ setup_neighbour(const struct GNUNET_PeerIdentity *peer) /** * Entry in a DLL we use to keep track of pending blacklist checks. */ -struct BlacklistCheckSwitchContext { +struct BlacklistCheckSwitchContext +{ /** * DLL prev pointer. */ @@ -2250,145 +2297,149 @@ struct BlacklistCheckSwitchContext { * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message, - const struct GNUNET_PeerIdentity *peer) +GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, + const struct GNUNET_PeerIdentity *peer) { const struct TransportSynMessage *scm; struct NeighbourMapEntry *n; struct GNUNET_TIME_Absolute ts; - if (ntohs(message->size) != sizeof(struct TransportSynMessage)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# SYN messages received"), - 1, GNUNET_NO); + if (ntohs (message->size) != sizeof(struct TransportSynMessage)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# SYN messages received"), + 1, GNUNET_NO); if (NULL == neighbours) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("SYN request from peer `%s' ignored due impending shutdown\n"), - GNUNET_i2s(peer)); - return GNUNET_OK; /* we're shutting down */ - } - scm = (const struct TransportSynMessage *)message; - GNUNET_break_op(0 == ntohl(scm->reserved)); - ts = GNUNET_TIME_absolute_ntoh(scm->timestamp); + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ( + "SYN request from peer `%s' ignored due impending shutdown\n"), + GNUNET_i2s (peer)); + return GNUNET_OK; /* we're shutting down */ + } + scm = (const struct TransportSynMessage *) message; + GNUNET_break_op (0 == ntohl (scm->reserved)); + ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); if (0 == - memcmp(&GST_my_identity, - peer, - sizeof(struct GNUNET_PeerIdentity))) - { - /* loopback connection-to-self, ignore */ - return GNUNET_SYSERR; - } - n = lookup_neighbour(peer); + memcmp (&GST_my_identity, + peer, + sizeof(struct GNUNET_PeerIdentity))) + { + /* loopback connection-to-self, ignore */ + return GNUNET_SYSERR; + } + n = lookup_neighbour (peer); if (NULL == n) - { - /* This is a new neighbour and set to not connected */ - n = setup_neighbour(peer); - GNUNET_assert(NULL != n); - } + { + /* This is a new neighbour and set to not connected */ + n = setup_neighbour (peer); + GNUNET_assert (NULL != n); + } /* Remember this SYN message in neighbour */ n->ack_state = ACK_SEND_SYN_ACK; n->connect_ack_timestamp = ts; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Received SYN for peer `%s' in state %s/%s\n", - GNUNET_i2s(peer), - GNUNET_TRANSPORT_ps2s(n->state), - print_ack_state(n->ack_state)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Received SYN for peer `%s' in state %s/%s\n", + GNUNET_i2s (peer), + GNUNET_TRANSPORT_ps2s (n->state), + print_ack_state (n->ack_state)); switch (n->state) - { - case GNUNET_TRANSPORT_PS_NOT_CONNECTED: - /* Request an address from ATS to send SYN_ACK to this peer */ - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SYN_RECV_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_INIT_ATS: - /* SYN message takes priority over us asking ATS for address: - * Wait for ATS to suggest an address and send SYN_ACK */ - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SYN_RECV_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: - /* We already wait for an address to send an SYN_ACK */ - break; - - case GNUNET_TRANSPORT_PS_SYN_SENT: - case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: - /* Send ACK immediately */ - n->ack_state = ACK_SEND_ACK; - send_syn_ack_message(&n->primary_address, - ts); - break; - - case GNUNET_TRANSPORT_PS_CONNECTED: - /* we are already connected and can thus send the ACK immediately */ - GNUNET_assert(NULL != n->primary_address.address); - GNUNET_assert(NULL != n->primary_address.session); - n->ack_state = ACK_SEND_ACK; - send_syn_ack_message(&n->primary_address, - ts); - break; - - case GNUNET_TRANSPORT_PS_RECONNECT_ATS: - /* We wait for ATS address suggestion */ - break; - - case GNUNET_TRANSPORT_PS_RECONNECT_SENT: - /* We received a SYN message while waiting for a SYN_ACK in fast - * reconnect. Send SYN_ACK immediately */ - n->ack_state = ACK_SEND_ACK; - send_syn_ack_message(&n->primary_address, - n->connect_ack_timestamp); - break; - - case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: - /* We are already connected and can thus send the ACK immediately; - still, it can never hurt to have an alternative address, so also - tell ATS about it */ - GNUNET_assert(NULL != n->primary_address.address); - GNUNET_assert(NULL != n->primary_address.session); - n->ack_state = ACK_SEND_ACK; - send_syn_ack_message(&n->primary_address, - ts); - break; - - case GNUNET_TRANSPORT_PS_DISCONNECT: - /* Get rid of remains and re-try */ - free_neighbour(n); - n = setup_neighbour(peer); - GNUNET_assert(NULL != n); - /* Remember the SYN time stamp for ACK message */ - n->ack_state = ACK_SEND_SYN_ACK; - n->connect_ack_timestamp = ts; - /* Request an address for the peer */ - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SYN_RECV_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: - /* should not be possible */ - GNUNET_assert(0); - break; - - default: - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Unhandled state `%s'\n", - GNUNET_TRANSPORT_ps2s(n->state)); - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + case GNUNET_TRANSPORT_PS_NOT_CONNECTED: + /* Request an address from ATS to send SYN_ACK to this peer */ + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SYN_RECV_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_INIT_ATS: + /* SYN message takes priority over us asking ATS for address: + * Wait for ATS to suggest an address and send SYN_ACK */ + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SYN_RECV_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: + /* We already wait for an address to send an SYN_ACK */ + break; + + case GNUNET_TRANSPORT_PS_SYN_SENT: + case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: + /* Send ACK immediately */ + n->ack_state = ACK_SEND_ACK; + send_syn_ack_message (&n->primary_address, + ts); + break; + + case GNUNET_TRANSPORT_PS_CONNECTED: + /* we are already connected and can thus send the ACK immediately */ + GNUNET_assert (NULL != n->primary_address.address); + GNUNET_assert (NULL != n->primary_address.session); + n->ack_state = ACK_SEND_ACK; + send_syn_ack_message (&n->primary_address, + ts); + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_ATS: + /* We wait for ATS address suggestion */ + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_SENT: + /* We received a SYN message while waiting for a SYN_ACK in fast + * reconnect. Send SYN_ACK immediately */ + n->ack_state = ACK_SEND_ACK; + send_syn_ack_message (&n->primary_address, + n->connect_ack_timestamp); + break; + + case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: + /* We are already connected and can thus send the ACK immediately; + still, it can never hurt to have an alternative address, so also + tell ATS about it */ + GNUNET_assert (NULL != n->primary_address.address); + GNUNET_assert (NULL != n->primary_address.session); + n->ack_state = ACK_SEND_ACK; + send_syn_ack_message (&n->primary_address, + ts); + break; + + case GNUNET_TRANSPORT_PS_DISCONNECT: + /* Get rid of remains and re-try */ + free_neighbour (n); + n = setup_neighbour (peer); + GNUNET_assert (NULL != n); + /* Remember the SYN time stamp for ACK message */ + n->ack_state = ACK_SEND_SYN_ACK; + n->connect_ack_timestamp = ts; + /* Request an address for the peer */ + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SYN_RECV_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: + /* should not be possible */ + GNUNET_assert (0); + break; + + default: + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unhandled state `%s'\n", + GNUNET_TRANSPORT_ps2s (n->state)); + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -2410,43 +2461,43 @@ GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message, * #GNUNET_NO if more extensive changes are required (address changed) */ static int -try_run_fast_ats_update(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) +try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { struct NeighbourMapEntry *n; - n = lookup_neighbour(&address->peer); + n = lookup_neighbour (&address->peer); if ((NULL == n) || (NULL == n->primary_address.address) || - (0 != GNUNET_HELLO_address_cmp(address, - n->primary_address.address))) + (0 != GNUNET_HELLO_address_cmp (address, + n->primary_address.address))) return GNUNET_NO; /* We are not really switching addresses, but merely adjusting session and/or bandwidth, can do fast ATS update! */ if (session != n->primary_address.session) - { - /* switch to a different session, but keeping same address; could - happen if there is a 2nd inbound connection */ - n->primary_address.session = session; - GNUNET_assert(GNUNET_YES == - GST_ats_is_known(n->primary_address.address, + { + /* switch to a different session, but keeping same address; could + happen if there is a 2nd inbound connection */ + n->primary_address.session = session; + GNUNET_assert (GNUNET_YES == + GST_ats_is_known (n->primary_address.address, n->primary_address.session)); - } + } if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) - { - n->primary_address.bandwidth_in = bandwidth_in; - if (GNUNET_YES != - set_incoming_quota(n, - bandwidth_in)) - return GNUNET_NO; - } + { + n->primary_address.bandwidth_in = bandwidth_in; + if (GNUNET_YES != + set_incoming_quota (n, + bandwidth_in)) + return GNUNET_NO; + } if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) - { - n->primary_address.bandwidth_out = bandwidth_out; - send_outbound_quota_to_clients(n); - } + { + n->primary_address.bandwidth_out = bandwidth_out; + send_outbound_quota_to_clients (n); + } return GNUNET_OK; } @@ -2465,11 +2516,11 @@ try_run_fast_ats_update(const struct GNUNET_HELLO_Address *address, * #GNUNET_SYSERR if operation was aborted */ static void -switch_address_bl_check_cont(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - int result) +switch_address_bl_check_cont (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + int result) { struct BlacklistCheckSwitchContext *blc_ctx = cls; struct GNUNET_TRANSPORT_PluginFunctions *papi; @@ -2478,289 +2529,297 @@ switch_address_bl_check_cont(void *cls, if (GNUNET_SYSERR == result) goto cleanup; - papi = GST_plugins_find(address->transport_name); + papi = GST_plugins_find (address->transport_name); if (NULL == papi) - { - /* This can happen during shutdown. */ - goto cleanup; - } + { + /* This can happen during shutdown. */ + goto cleanup; + } if (GNUNET_NO == result) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n", - GST_plugins_a2s(address), - session, - GNUNET_i2s(peer)); - GNUNET_STATISTICS_update(GST_stats, - "# ATS suggestions ignored (blacklist denied)", - 1, - GNUNET_NO); - if (NULL != session) - papi->disconnect_session(papi->cls, - session); - if (GNUNET_YES != - GNUNET_HELLO_address_check_option(address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)) - GST_ats_block_address(address, - NULL); - goto cleanup; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n", + GST_plugins_a2s (address), + session, + GNUNET_i2s (peer)); + GNUNET_STATISTICS_update (GST_stats, + "# ATS suggestions ignored (blacklist denied)", + 1, + GNUNET_NO); + if (NULL != session) + papi->disconnect_session (papi->cls, + session); + if (GNUNET_YES != + GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)) + GST_ats_block_address (address, + NULL); + goto cleanup; + } if (NULL == session) - { - /* need to create a session, ATS only gave us an address */ - session = papi->get_session(papi->cls, - address); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Obtained new session for peer `%s' and address '%s': %p\n", - GNUNET_i2s(&address->peer), - GST_plugins_a2s(address), - session); - if (NULL != session) - GST_ats_new_session(address, - session); - } + { + /* need to create a session, ATS only gave us an address */ + session = papi->get_session (papi->cls, + address); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Obtained new session for peer `%s' and address '%s': %p\n", + GNUNET_i2s (&address->peer), + GST_plugins_a2s (address), + session); + if (NULL != session) + GST_ats_new_session (address, + session); + } if (NULL == session) - { - /* session creation failed, bad!, fail! */ - GNUNET_STATISTICS_update(GST_stats, - "# ATS suggestions ignored (failed to create session)", - 1, - GNUNET_NO); - /* No session could be obtained, remove blacklist check and clean up */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Failed to obtain new session for peer `%s' and address '%s'\n", - GNUNET_i2s(&address->peer), - GST_plugins_a2s(address)); - GST_ats_block_address(address, - session); - goto cleanup; - } + { + /* session creation failed, bad!, fail! */ + GNUNET_STATISTICS_update (GST_stats, + "# ATS suggestions ignored (failed to create session)", + 1, + GNUNET_NO); + /* No session could be obtained, remove blacklist check and clean up */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Failed to obtain new session for peer `%s' and address '%s'\n", + GNUNET_i2s (&address->peer), + GST_plugins_a2s (address)); + GST_ats_block_address (address, + session); + goto cleanup; + } /* We did this check already before going into blacklist, but it is theoretically possible that the situation changed in the meantime, hence we check again here */ if (GNUNET_OK == - try_run_fast_ats_update(address, - session, - blc_ctx->bandwidth_in, - blc_ctx->bandwidth_out)) + try_run_fast_ats_update (address, + session, + blc_ctx->bandwidth_in, + blc_ctx->bandwidth_out)) goto cleanup; /* was just a minor update, we're done */ /* check if we also need to setup the neighbour entry */ - if (NULL == (n = lookup_neighbour(peer))) + if (NULL == (n = lookup_neighbour (peer))) + { + n = setup_neighbour (peer); + if (NULL == n) { - n = setup_neighbour(peer); - if (NULL == n) - { - /* not sure how this can happen... */ - GNUNET_break(0); - goto cleanup; - } - n->state = GNUNET_TRANSPORT_PS_INIT_ATS; + /* not sure how this can happen... */ + GNUNET_break (0); + goto cleanup; } + n->state = GNUNET_TRANSPORT_PS_INIT_ATS; + } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peer `%s' switches to address `%s'\n", - GNUNET_i2s(&address->peer), - GST_plugins_a2s(address)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer `%s' switches to address `%s'\n", + GNUNET_i2s (&address->peer), + GST_plugins_a2s (address)); switch (n->state) - { - case GNUNET_TRANSPORT_PS_NOT_CONNECTED: - GNUNET_break(0); - GST_ats_block_address(address, - session); - free_neighbour(n); - return; - - case GNUNET_TRANSPORT_PS_INIT_ATS: - /* We requested an address and ATS suggests one: - * set primary address and send SYN message*/ - set_primary_address(n, - address, - session, - blc_ctx->bandwidth_in, - blc_ctx->bandwidth_out); - if (ACK_SEND_SYN_ACK == n->ack_state) - { - /* Send pending SYN_ACK message */ - n->ack_state = ACK_SEND_ACK; - send_syn_ack_message(&n->primary_address, - n->connect_ack_timestamp); - } - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SYN_SENT, - GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT)); - send_syn(&n->primary_address); - break; - - case GNUNET_TRANSPORT_PS_SYN_SENT: - /* ATS suggested a new address while waiting for an SYN_ACK: - * Switch and send new SYN */ - /* ATS suggests a different address, switch again */ - set_primary_address(n, - address, - session, - blc_ctx->bandwidth_in, - blc_ctx->bandwidth_out); - if (ACK_SEND_SYN_ACK == n->ack_state) - { - /* Send pending SYN_ACK message */ - n->ack_state = ACK_SEND_ACK; - send_syn_ack_message(&n->primary_address, - n->connect_ack_timestamp); - } - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SYN_SENT, - GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT)); - send_syn(&n->primary_address); - break; - - case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: - /* We requested an address and ATS suggests one: - * set primary address and send SYN_ACK message*/ - set_primary_address(n, - address, - session, - blc_ctx->bandwidth_in, - blc_ctx->bandwidth_out); - /* Send an ACK message as a response to the SYN msg */ - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SYN_RECV_ACK, - GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT)); - send_syn_ack_message(&n->primary_address, - n->connect_ack_timestamp); - if ((ACK_SEND_SYN_ACK == n->ack_state) || - (ACK_UNDEFINED == n->ack_state)) - n->ack_state = ACK_SEND_ACK; - break; - - case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: - /* ATS asks us to switch while we were trying to connect; switch to new - address and check blacklist again */ - if ((ACK_SEND_SYN_ACK == n->ack_state)) - { - n->ack_state = ACK_SEND_ACK; - send_syn_ack_message(&n->primary_address, - n->connect_ack_timestamp); - } - set_primary_address(n, - address, - session, - blc_ctx->bandwidth_in, - blc_ctx->bandwidth_out); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SYN_RECV_ACK, - GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_CONNECTED: - GNUNET_assert(NULL != n->primary_address.address); - GNUNET_assert(NULL != n->primary_address.session); - GNUNET_break(n->primary_address.session != session); - /* ATS asks us to switch a life connection; see if we can get - a SYN_ACK on it before we actually do this! */ - set_alternative_address(n, - address, - session, - blc_ctx->bandwidth_in, - blc_ctx->bandwidth_out); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, - GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT)); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# Attempts to switch addresses"), - 1, - GNUNET_NO); - send_syn(&n->alternative_address); - break; - - case GNUNET_TRANSPORT_PS_RECONNECT_ATS: - set_primary_address(n, - address, - session, - blc_ctx->bandwidth_in, - blc_ctx->bandwidth_out); - if (ACK_SEND_SYN_ACK == n->ack_state) - { - /* Send pending SYN_ACK message */ - n->ack_state = ACK_SEND_ACK; - send_syn_ack_message(&n->primary_address, - n->connect_ack_timestamp); - } - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_RECONNECT_SENT, - GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT)); - send_syn(&n->primary_address); - break; - - case GNUNET_TRANSPORT_PS_RECONNECT_SENT: - /* ATS asks us to switch while we were trying to reconnect; switch to new - address and send SYN again */ - set_primary_address(n, - address, - session, - blc_ctx->bandwidth_in, - blc_ctx->bandwidth_out); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_RECONNECT_SENT, - GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT)); - send_syn(&n->primary_address); - break; - - case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: - if ((0 == GNUNET_HELLO_address_cmp(n->primary_address.address, - address)) && - (n->primary_address.session == session)) - { - /* ATS switches back to still-active session */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "ATS double-switched, cleaning up alternative address\n"); - free_address(&n->alternative_address); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_CONNECTED, - n->timeout); - break; - } - /* ATS asks us to switch a life connection, send */ - set_alternative_address(n, - address, - session, - blc_ctx->bandwidth_in, - blc_ctx->bandwidth_out); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, - GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT)); - send_syn(&n->alternative_address); - break; - - case GNUNET_TRANSPORT_PS_DISCONNECT: - /* not going to switch addresses while disconnecting */ - GNUNET_STATISTICS_update(GST_stats, - "# ATS suggestion ignored (disconnecting)", - 1, - GNUNET_NO); - return; + { + case GNUNET_TRANSPORT_PS_NOT_CONNECTED: + GNUNET_break (0); + GST_ats_block_address (address, + session); + free_neighbour (n); + return; - case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: - GNUNET_assert(0); - break; + case GNUNET_TRANSPORT_PS_INIT_ATS: + /* We requested an address and ATS suggests one: + * set primary address and send SYN message*/ + set_primary_address (n, + address, + session, + blc_ctx->bandwidth_in, + blc_ctx->bandwidth_out); + if (ACK_SEND_SYN_ACK == n->ack_state) + { + /* Send pending SYN_ACK message */ + n->ack_state = ACK_SEND_ACK; + send_syn_ack_message (&n->primary_address, + n->connect_ack_timestamp); + } + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SYN_SENT, + GNUNET_TIME_relative_to_absolute ( + SETUP_CONNECTION_TIMEOUT)); + send_syn (&n->primary_address); + break; + + case GNUNET_TRANSPORT_PS_SYN_SENT: + /* ATS suggested a new address while waiting for an SYN_ACK: + * Switch and send new SYN */ + /* ATS suggests a different address, switch again */ + set_primary_address (n, + address, + session, + blc_ctx->bandwidth_in, + blc_ctx->bandwidth_out); + if (ACK_SEND_SYN_ACK == n->ack_state) + { + /* Send pending SYN_ACK message */ + n->ack_state = ACK_SEND_ACK; + send_syn_ack_message (&n->primary_address, + n->connect_ack_timestamp); + } + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SYN_SENT, + GNUNET_TIME_relative_to_absolute ( + SETUP_CONNECTION_TIMEOUT)); + send_syn (&n->primary_address); + break; + + case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: + /* We requested an address and ATS suggests one: + * set primary address and send SYN_ACK message*/ + set_primary_address (n, + address, + session, + blc_ctx->bandwidth_in, + blc_ctx->bandwidth_out); + /* Send an ACK message as a response to the SYN msg */ + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SYN_RECV_ACK, + GNUNET_TIME_relative_to_absolute ( + SETUP_CONNECTION_TIMEOUT)); + send_syn_ack_message (&n->primary_address, + n->connect_ack_timestamp); + if ((ACK_SEND_SYN_ACK == n->ack_state) || + (ACK_UNDEFINED == n->ack_state)) + n->ack_state = ACK_SEND_ACK; + break; - default: - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Unhandled state `%s'\n", - GNUNET_TRANSPORT_ps2s(n->state)); - GNUNET_break(0); + case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: + /* ATS asks us to switch while we were trying to connect; switch to new + address and check blacklist again */ + if ((ACK_SEND_SYN_ACK == n->ack_state)) + { + n->ack_state = ACK_SEND_ACK; + send_syn_ack_message (&n->primary_address, + n->connect_ack_timestamp); + } + set_primary_address (n, + address, + session, + blc_ctx->bandwidth_in, + blc_ctx->bandwidth_out); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SYN_RECV_ACK, + GNUNET_TIME_relative_to_absolute ( + SETUP_CONNECTION_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_CONNECTED: + GNUNET_assert (NULL != n->primary_address.address); + GNUNET_assert (NULL != n->primary_address.session); + GNUNET_break (n->primary_address.session != session); + /* ATS asks us to switch a life connection; see if we can get + a SYN_ACK on it before we actually do this! */ + set_alternative_address (n, + address, + session, + blc_ctx->bandwidth_in, + blc_ctx->bandwidth_out); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, + GNUNET_TIME_relative_to_absolute ( + SETUP_CONNECTION_TIMEOUT)); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# Attempts to switch addresses"), + 1, + GNUNET_NO); + send_syn (&n->alternative_address); + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_ATS: + set_primary_address (n, + address, + session, + blc_ctx->bandwidth_in, + blc_ctx->bandwidth_out); + if (ACK_SEND_SYN_ACK == n->ack_state) + { + /* Send pending SYN_ACK message */ + n->ack_state = ACK_SEND_ACK; + send_syn_ack_message (&n->primary_address, + n->connect_ack_timestamp); + } + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_RECONNECT_SENT, + GNUNET_TIME_relative_to_absolute ( + FAST_RECONNECT_TIMEOUT)); + send_syn (&n->primary_address); + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_SENT: + /* ATS asks us to switch while we were trying to reconnect; switch to new + address and send SYN again */ + set_primary_address (n, + address, + session, + blc_ctx->bandwidth_in, + blc_ctx->bandwidth_out); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_RECONNECT_SENT, + GNUNET_TIME_relative_to_absolute ( + FAST_RECONNECT_TIMEOUT)); + send_syn (&n->primary_address); + break; + + case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: + if ((0 == GNUNET_HELLO_address_cmp (n->primary_address.address, + address)) && + (n->primary_address.session == session)) + { + /* ATS switches back to still-active session */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "ATS double-switched, cleaning up alternative address\n"); + free_address (&n->alternative_address); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_CONNECTED, + n->timeout); break; } + /* ATS asks us to switch a life connection, send */ + set_alternative_address (n, + address, + session, + blc_ctx->bandwidth_in, + blc_ctx->bandwidth_out); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, + GNUNET_TIME_relative_to_absolute ( + SETUP_CONNECTION_TIMEOUT)); + send_syn (&n->alternative_address); + break; + + case GNUNET_TRANSPORT_PS_DISCONNECT: + /* not going to switch addresses while disconnecting */ + GNUNET_STATISTICS_update (GST_stats, + "# ATS suggestion ignored (disconnecting)", + 1, + GNUNET_NO); + return; + + case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: + GNUNET_assert (0); + break; + + default: + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unhandled state `%s'\n", + GNUNET_TRANSPORT_ps2s (n->state)); + GNUNET_break (0); + break; + } cleanup: - GNUNET_CONTAINER_DLL_remove(pending_bc_head, - pending_bc_tail, - blc_ctx); - GNUNET_free(blc_ctx); + GNUNET_CONTAINER_DLL_remove (pending_bc_head, + pending_bc_tail, + blc_ctx); + GNUNET_free (blc_ctx); } @@ -2782,65 +2841,67 @@ cleanup: * 0 to disconnect from peer */ void -GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) +GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_out) { struct GST_BlacklistCheck *blc; struct BlacklistCheckSwitchContext *blc_ctx; - GNUNET_assert(NULL != address->transport_name); + GNUNET_assert (NULL != address->transport_name); if (GNUNET_OK == - try_run_fast_ats_update(address, - session, - bandwidth_in, - bandwidth_out)) + try_run_fast_ats_update (address, + session, + bandwidth_in, + bandwidth_out)) return; /* Check if plugin is available */ - if (NULL == (GST_plugins_find(address->transport_name))) - { - /* we don't have the plugin for this address */ - GNUNET_break(0); - GST_ats_block_address(address, - session); - return; - } + if (NULL == (GST_plugins_find (address->transport_name))) + { + /* we don't have the plugin for this address */ + GNUNET_break (0); + GST_ats_block_address (address, + session); + return; + } if ((NULL == session) && - (GNUNET_HELLO_address_check_option(address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND))) - { - /* This is a inbound address and we do not have a session to use! */ - GNUNET_break(0); - GST_ats_block_address(address, - session); - return; - } + (GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND))) + { + /* This is a inbound address and we do not have a session to use! */ + GNUNET_break (0); + GST_ats_block_address (address, + session); + return; + } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "ATS suggests address '%s' for peer `%s' at %u/%u speed\n", - GST_plugins_a2s(address), - GNUNET_i2s(&address->peer), - (unsigned int)ntohl(bandwidth_in.value__), - (unsigned int)ntohl(bandwidth_out.value__)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "ATS suggests address '%s' for peer `%s' at %u/%u speed\n", + GST_plugins_a2s (address), + GNUNET_i2s (&address->peer), + (unsigned int) ntohl (bandwidth_in.value__), + (unsigned int) ntohl (bandwidth_out.value__)); /* Perform blacklist check */ - blc_ctx = GNUNET_new(struct BlacklistCheckSwitchContext); + blc_ctx = GNUNET_new (struct BlacklistCheckSwitchContext); blc_ctx->bandwidth_in = bandwidth_in; blc_ctx->bandwidth_out = bandwidth_out; - GNUNET_CONTAINER_DLL_insert(pending_bc_head, - pending_bc_tail, - blc_ctx); - if (NULL != (blc = GST_blacklist_test_allowed(&address->peer, - address->transport_name, - &switch_address_bl_check_cont, - blc_ctx, - address, - session))) - { - blc_ctx->blc = blc; - } + GNUNET_CONTAINER_DLL_insert (pending_bc_head, + pending_bc_tail, + blc_ctx); + if (NULL != (blc = GST_blacklist_test_allowed (&address->peer, + address->transport_name, + &switch_address_bl_check_cont, + blc_ctx, + address, + session))) + { + blc_ctx->blc = blc; + } } @@ -2854,39 +2915,40 @@ GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address, * @return #GNUNET_OK (continue to iterate) */ static int -send_utilization_data(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +send_utilization_data (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct NeighbourMapEntry *n = value; uint32_t bps_in; uint32_t bps_out; struct GNUNET_TIME_Relative delta; - (void)cls; - if ((GNUNET_YES != test_connected(n)) || + (void) cls; + if ((GNUNET_YES != test_connected (n)) || (NULL == n->primary_address.address)) return GNUNET_OK; - delta = GNUNET_TIME_absolute_get_difference(n->last_util_transmission, - GNUNET_TIME_absolute_get()); + delta = GNUNET_TIME_absolute_get_difference (n->last_util_transmission, + GNUNET_TIME_absolute_get ()); bps_in = 0; if ((0 != n->util_total_bytes_recv) && (0 != delta.rel_value_us)) - bps_in = (1000LL * 1000LL * n->util_total_bytes_recv) / (delta.rel_value_us); + bps_in = (1000LL * 1000LL * n->util_total_bytes_recv) + / (delta.rel_value_us); bps_out = 0; if ((0 != n->util_total_bytes_sent) && (0 != delta.rel_value_us)) bps_out = (1000LL * 1000LL * n->util_total_bytes_sent) / delta.rel_value_us; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "`%s' total: received %u Bytes/s, sent %u Bytes/s\n", - GNUNET_i2s(key), - bps_in, - bps_out); - GST_ats_update_utilization(n->primary_address.address, - bps_in, - bps_out); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "`%s' total: received %u Bytes/s, sent %u Bytes/s\n", + GNUNET_i2s (key), + bps_in, + bps_out); + GST_ats_update_utilization (n->primary_address.address, + bps_in, + bps_out); n->util_total_bytes_recv = 0; n->util_total_bytes_sent = 0; - n->last_util_transmission = GNUNET_TIME_absolute_get(); + n->last_util_transmission = GNUNET_TIME_absolute_get (); return GNUNET_OK; } @@ -2897,17 +2959,17 @@ send_utilization_data(void *cls, * @param cls the `struct NeighbourMapEntry` for which we are running */ static void -utilization_transmission(void *cls) +utilization_transmission (void *cls) { - (void)cls; + (void) cls; util_transmission_tk = NULL; - GNUNET_CONTAINER_multipeermap_iterate(neighbours, - &send_utilization_data, - NULL); + GNUNET_CONTAINER_multipeermap_iterate (neighbours, + &send_utilization_data, + NULL); util_transmission_tk - = GNUNET_SCHEDULER_add_delayed(UTIL_TRANSMISSION_INTERVAL, - &utilization_transmission, - NULL); + = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, + &utilization_transmission, + NULL); } @@ -2920,15 +2982,15 @@ utilization_transmission(void *cls) * @param message the message we received (really only the size is used) */ void -GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address, - const struct GNUNET_MessageHeader *message) +GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address, + const struct GNUNET_MessageHeader *message) { struct NeighbourMapEntry *n; - n = lookup_neighbour(&address->peer); + n = lookup_neighbour (&address->peer); if (NULL == n) return; - n->util_total_bytes_recv += ntohs(message->size); + n->util_total_bytes_recv += ntohs (message->size); } @@ -2942,13 +3004,13 @@ GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address, * @param message the message we sent (really only the size is used) */ void -GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - size_t size) +GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + size_t size) { struct NeighbourMapEntry *n; - n = lookup_neighbour(&address->peer); + n = lookup_neighbour (&address->peer); if (NULL == n) return; if (n->primary_address.session != session) @@ -2965,157 +3027,160 @@ GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address, * @param cls the 'struct NeighbourMapEntry' for which we are running */ static void -master_task(void *cls) +master_task (void *cls) { struct NeighbourMapEntry *n = cls; struct GNUNET_TIME_Relative delay; n->task = NULL; - delay = GNUNET_TIME_absolute_get_remaining(n->timeout); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Master task runs for neighbour `%s' in state %s with timeout in %s\n", - GNUNET_i2s(&n->id), - GNUNET_TRANSPORT_ps2s(n->state), - GNUNET_STRINGS_relative_time_to_string(delay, - GNUNET_YES)); + delay = GNUNET_TIME_absolute_get_remaining (n->timeout); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Master task runs for neighbour `%s' in state %s with timeout in %s\n", + GNUNET_i2s (&n->id), + GNUNET_TRANSPORT_ps2s (n->state), + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); switch (n->state) + { + case GNUNET_TRANSPORT_PS_NOT_CONNECTED: + /* invalid state for master task, clean up */ + GNUNET_break (0); + free_neighbour (n); + return; + + case GNUNET_TRANSPORT_PS_INIT_ATS: + if (0 == delay.rel_value_us) { - case GNUNET_TRANSPORT_PS_NOT_CONNECTED: - /* invalid state for master task, clean up */ - GNUNET_break(0); - free_neighbour(n); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connection to `%s' timed out waiting for ATS to provide address\n", + GNUNET_i2s (&n->id)); + free_neighbour (n); return; + } + break; - case GNUNET_TRANSPORT_PS_INIT_ATS: - if (0 == delay.rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connection to `%s' timed out waiting for ATS to provide address\n", - GNUNET_i2s(&n->id)); - free_neighbour(n); - return; - } - break; - - case GNUNET_TRANSPORT_PS_SYN_SENT: - if (0 == delay.rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connection to `%s' timed out waiting for other peer to send SYN_ACK\n", - GNUNET_i2s(&n->id)); - /* Remove address and request and additional one */ - unset_primary_address(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_INIT_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - return; - } - break; - - case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: - if (0 == delay.rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connection to `%s' timed out waiting ATS to provide address to use for SYN_ACK\n", - GNUNET_i2s(&n->id)); - free_neighbour(n); - return; - } - break; - - case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: - if (0 == delay.rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connection to `%s' timed out waiting for other peer to send ACK\n", - GNUNET_i2s(&n->id)); - disconnect_neighbour(n); - return; - } - break; - - case GNUNET_TRANSPORT_PS_CONNECTED: - if (0 == delay.rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs\n", - GNUNET_i2s(&n->id)); - disconnect_neighbour(n); - return; - } - try_transmission_to_peer(n); - send_keepalive(n); - break; + case GNUNET_TRANSPORT_PS_SYN_SENT: + if (0 == delay.rel_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connection to `%s' timed out waiting for other peer to send SYN_ACK\n", + GNUNET_i2s (&n->id)); + /* Remove address and request and additional one */ + unset_primary_address (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_INIT_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + return; + } + break; - case GNUNET_TRANSPORT_PS_RECONNECT_ATS: - if (0 == delay.rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connection to `%s' timed out, waiting for ATS replacement address\n", - GNUNET_i2s(&n->id)); - disconnect_neighbour(n); - return; - } - break; + case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: + if (0 == delay.rel_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connection to `%s' timed out waiting ATS to provide address to use for SYN_ACK\n", + GNUNET_i2s (&n->id)); + free_neighbour (n); + return; + } + break; - case GNUNET_TRANSPORT_PS_RECONNECT_SENT: - if (0 == delay.rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connection to `%s' timed out, waiting for other peer to SYN_ACK replacement address\n", - GNUNET_i2s(&n->id)); - disconnect_neighbour(n); - return; - } - break; + case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: + if (0 == delay.rel_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connection to `%s' timed out waiting for other peer to send ACK\n", + GNUNET_i2s (&n->id)); + disconnect_neighbour (n); + return; + } + break; - case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: - if (0 == delay.rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Switch failed, cleaning up alternative address\n"); - free_address(&n->alternative_address); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_CONNECTED, - GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT)); - } - try_transmission_to_peer(n); - send_keepalive(n); - break; + case GNUNET_TRANSPORT_PS_CONNECTED: + if (0 == delay.rel_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs\n", + GNUNET_i2s (&n->id)); + disconnect_neighbour (n); + return; + } + try_transmission_to_peer (n); + send_keepalive (n); + break; - case GNUNET_TRANSPORT_PS_DISCONNECT: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Cleaning up connection to `%s' after sending DISCONNECT\n", - GNUNET_i2s(&n->id)); - free_neighbour(n); + case GNUNET_TRANSPORT_PS_RECONNECT_ATS: + if (0 == delay.rel_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connection to `%s' timed out, waiting for ATS replacement address\n", + GNUNET_i2s (&n->id)); + disconnect_neighbour (n); return; + } + break; - case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: - /* how did we get here!? */ - GNUNET_assert(0); - break; + case GNUNET_TRANSPORT_PS_RECONNECT_SENT: + if (0 == delay.rel_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connection to `%s' timed out, waiting for other peer to SYN_ACK replacement address\n", + GNUNET_i2s (&n->id)); + disconnect_neighbour (n); + return; + } + break; - default: - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Unhandled state `%s'\n", - GNUNET_TRANSPORT_ps2s(n->state)); - GNUNET_break(0); - break; + case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: + if (0 == delay.rel_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Switch failed, cleaning up alternative address\n"); + free_address (&n->alternative_address); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_CONNECTED, + GNUNET_TIME_relative_to_absolute ( + SETUP_CONNECTION_TIMEOUT)); } - delay = GNUNET_TIME_absolute_get_remaining(n->timeout); + try_transmission_to_peer (n); + send_keepalive (n); + break; + + case GNUNET_TRANSPORT_PS_DISCONNECT: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Cleaning up connection to `%s' after sending DISCONNECT\n", + GNUNET_i2s (&n->id)); + free_neighbour (n); + return; + + case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: + /* how did we get here!? */ + GNUNET_assert (0); + break; + + default: + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unhandled state `%s'\n", + GNUNET_TRANSPORT_ps2s (n->state)); + GNUNET_break (0); + break; + } + delay = GNUNET_TIME_absolute_get_remaining (n->timeout); if ((GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) || (GNUNET_TRANSPORT_PS_CONNECTED == n->state)) - { - /* if we are *now* in one of the two states, we're sending - keep alive messages, so we need to consider the keepalive - delay, not just the connection timeout */ - delay = GNUNET_TIME_relative_min(GNUNET_TIME_absolute_get_remaining(n->keep_alive_time), - delay); - } + { + /* if we are *now* in one of the two states, we're sending + keep alive messages, so we need to consider the keepalive + delay, not just the connection timeout */ + delay = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining ( + n->keep_alive_time), + delay); + } if (NULL == n->task) - n->task = GNUNET_SCHEDULER_add_delayed(delay, - &master_task, - n); + n->task = GNUNET_SCHEDULER_add_delayed (delay, + &master_task, + n); } @@ -3126,23 +3191,23 @@ master_task(void *cls) * @param n neighbour to send the ACK to */ static void -send_session_ack_message(struct NeighbourMapEntry *n) +send_session_ack_message (struct NeighbourMapEntry *n) { struct GNUNET_MessageHeader msg; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Sending ACK message to peer `%s'\n", - GNUNET_i2s(&n->id)); - - msg.size = htons(sizeof(struct GNUNET_MessageHeader)); - msg.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); - (void)send_with_session(n, - &msg, - sizeof(struct GNUNET_MessageHeader), - UINT32_MAX, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_NO, - NULL, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Sending ACK message to peer `%s'\n", + GNUNET_i2s (&n->id)); + + msg.size = htons (sizeof(struct GNUNET_MessageHeader)); + msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); + (void) send_with_session (n, + &msg, + sizeof(struct GNUNET_MessageHeader), + UINT32_MAX, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_NO, + NULL, NULL); } @@ -3158,145 +3223,154 @@ send_session_ack_message(struct NeighbourMapEntry *n) * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +GST_neighbours_handle_session_syn_ack (const struct + GNUNET_MessageHeader *message, + const struct + GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { const struct TransportSynMessage *scm; struct GNUNET_TIME_Absolute ts; struct NeighbourMapEntry *n; - (void)session; - if (ntohs(message->size) != sizeof(struct TransportSynMessage)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# SYN_ACK messages received"), - 1, GNUNET_NO); - scm = (const struct TransportSynMessage *)message; - GNUNET_break_op(ntohl(scm->reserved) == 0); - if (NULL == (n = lookup_neighbour(&address->peer))) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# unexpected SYN_ACK messages (no peer)"), - 1, GNUNET_NO); - return GNUNET_SYSERR; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received SYN_ACK message from peer `%s' in state %s/%s\n", - GNUNET_i2s(&address->peer), - GNUNET_TRANSPORT_ps2s(n->state), - print_ack_state(n->ack_state)); - ts = GNUNET_TIME_absolute_ntoh(scm->timestamp); + (void) session; + if (ntohs (message->size) != sizeof(struct TransportSynMessage)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# SYN_ACK messages received"), + 1, GNUNET_NO); + scm = (const struct TransportSynMessage *) message; + GNUNET_break_op (ntohl (scm->reserved) == 0); + if (NULL == (n = lookup_neighbour (&address->peer))) + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# unexpected SYN_ACK messages (no peer)"), + 1, GNUNET_NO); + return GNUNET_SYSERR; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received SYN_ACK message from peer `%s' in state %s/%s\n", + GNUNET_i2s (&address->peer), + GNUNET_TRANSPORT_ps2s (n->state), + print_ack_state (n->ack_state)); + ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); switch (n->state) - { - case GNUNET_TRANSPORT_PS_NOT_CONNECTED: - GNUNET_break(0); - free_neighbour(n); - return GNUNET_SYSERR; - - case GNUNET_TRANSPORT_PS_INIT_ATS: - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# unexpected SYN_ACK messages (not ready)"), - 1, - GNUNET_NO); - break; - - case GNUNET_TRANSPORT_PS_SYN_SENT: - if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "SYN_ACK ignored as the timestamp does not match our SYN request\n"); - return GNUNET_OK; - } - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_CONNECTED, - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); - set_primary_address(n, - n->primary_address.address, - n->primary_address.session, - n->primary_address.bandwidth_in, - n->primary_address.bandwidth_out); - send_session_ack_message(n); - break; - - case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: - case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# unexpected SYN_ACK messages (not ready)"), - 1, - GNUNET_NO); - break; - - case GNUNET_TRANSPORT_PS_CONNECTED: - /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */ - send_session_ack_message(n); - break; - - case GNUNET_TRANSPORT_PS_RECONNECT_ATS: - /* we didn't expect any SYN_ACK, as we are waiting for ATS - to give us a new address... */ - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# unexpected SYN_ACK messages (waiting on ATS)"), - 1, - GNUNET_NO); - break; - - case GNUNET_TRANSPORT_PS_RECONNECT_SENT: - /* Reconnecting with new address address worked; go back to connected! */ - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_CONNECTED, - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); - send_session_ack_message(n); - break; - - case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: - /* new address worked; adopt it and go back to connected! */ - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_CONNECTED, - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); - GNUNET_break(GNUNET_NO == n->alternative_address.ats_active); - - /* Set primary addresses */ - set_primary_address(n, - n->alternative_address.address, - n->alternative_address.session, - n->alternative_address.bandwidth_in, - n->alternative_address.bandwidth_out); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# Successful attempts to switch addresses"), - 1, - GNUNET_NO); - - GNUNET_HELLO_address_free(n->alternative_address.address); - memset(&n->alternative_address, - 0, - sizeof(n->alternative_address)); - send_session_ack_message(n); - break; - - case GNUNET_TRANSPORT_PS_DISCONNECT: - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# unexpected SYN_ACK messages (disconnecting)"), - 1, GNUNET_NO); - return GNUNET_SYSERR; - - case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: - GNUNET_assert(0); - break; - - default: - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Unhandled state `%s'\n", - GNUNET_TRANSPORT_ps2s(n->state)); - GNUNET_break(0); - return GNUNET_SYSERR; + { + case GNUNET_TRANSPORT_PS_NOT_CONNECTED: + GNUNET_break (0); + free_neighbour (n); + return GNUNET_SYSERR; + + case GNUNET_TRANSPORT_PS_INIT_ATS: + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# unexpected SYN_ACK messages (not ready)"), + 1, + GNUNET_NO); + break; + + case GNUNET_TRANSPORT_PS_SYN_SENT: + if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "SYN_ACK ignored as the timestamp does not match our SYN request\n"); + return GNUNET_OK; } + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_CONNECTED, + GNUNET_TIME_relative_to_absolute ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); + set_primary_address (n, + n->primary_address.address, + n->primary_address.session, + n->primary_address.bandwidth_in, + n->primary_address.bandwidth_out); + send_session_ack_message (n); + break; + + case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: + case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# unexpected SYN_ACK messages (not ready)"), + 1, + GNUNET_NO); + break; + + case GNUNET_TRANSPORT_PS_CONNECTED: + /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */ + send_session_ack_message (n); + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_ATS: + /* we didn't expect any SYN_ACK, as we are waiting for ATS + to give us a new address... */ + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# unexpected SYN_ACK messages (waiting on ATS)"), + 1, + GNUNET_NO); + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_SENT: + /* Reconnecting with new address address worked; go back to connected! */ + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_CONNECTED, + GNUNET_TIME_relative_to_absolute ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); + send_session_ack_message (n); + break; + + case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: + /* new address worked; adopt it and go back to connected! */ + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_CONNECTED, + GNUNET_TIME_relative_to_absolute ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); + GNUNET_break (GNUNET_NO == n->alternative_address.ats_active); + + /* Set primary addresses */ + set_primary_address (n, + n->alternative_address.address, + n->alternative_address.session, + n->alternative_address.bandwidth_in, + n->alternative_address.bandwidth_out); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# Successful attempts to switch addresses"), + 1, + GNUNET_NO); + + GNUNET_HELLO_address_free (n->alternative_address.address); + memset (&n->alternative_address, + 0, + sizeof(n->alternative_address)); + send_session_ack_message (n); + break; + + case GNUNET_TRANSPORT_PS_DISCONNECT: + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# unexpected SYN_ACK messages (disconnecting)"), + 1, GNUNET_NO); + return GNUNET_SYSERR; + + case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: + GNUNET_assert (0); + break; + + default: + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unhandled state `%s'\n", + GNUNET_TRANSPORT_ps2s (n->state)); + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -3311,134 +3385,138 @@ GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message * this session was not in use */ int -GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session) +GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session) { struct NeighbourMapEntry *n; - if (NULL == (n = lookup_neighbour(peer))) + if (NULL == (n = lookup_neighbour (peer))) return GNUNET_NO; /* can't affect us */ if (session != n->primary_address.session) + { + /* Free alternative address */ + if (session == n->alternative_address.session) { - /* Free alternative address */ - if (session == n->alternative_address.session) - { - if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_CONNECTED, - n->timeout); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Session died, cleaning up alternative address\n"); - free_address(&n->alternative_address); - } - return GNUNET_NO; /* doesn't affect us further */ + if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_CONNECTED, + n->timeout); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Session died, cleaning up alternative address\n"); + free_address (&n->alternative_address); } + return GNUNET_NO; /* doesn't affect us further */ + } n->expect_latency_response = GNUNET_NO; /* The session for neighbour's primary address died */ switch (n->state) - { - case GNUNET_TRANSPORT_PS_NOT_CONNECTED: - GNUNET_break(0); - free_neighbour(n); - return GNUNET_YES; - - case GNUNET_TRANSPORT_PS_INIT_ATS: - GNUNET_break(0); - free_neighbour(n); - return GNUNET_YES; - - case GNUNET_TRANSPORT_PS_SYN_SENT: - /* The session used to send the SYN terminated: - * this implies a connect error*/ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Failed to send SYN in CONNECT_SENT with `%s' %p: session terminated\n", - GST_plugins_a2s(n->primary_address.address), - n->primary_address.session); - - /* Destroy the address since it cannot be used */ - unset_primary_address(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_INIT_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: - case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: - /* error on inbound session; free neighbour entirely */ - free_neighbour(n); - return GNUNET_YES; - - case GNUNET_TRANSPORT_PS_CONNECTED: - /* Our primary connection died, try a fast reconnect */ - unset_primary_address(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_RECONNECT_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_RECONNECT_ATS: - /* we don't have an address, how can it go down? */ - GNUNET_break(0); - break; - - case GNUNET_TRANSPORT_PS_RECONNECT_SENT: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Failed to send SYN in RECONNECT_SENT with `%s' %p: session terminated\n", - GST_plugins_a2s(n->primary_address.address), - n->primary_address.session); - /* Destroy the address since it cannot be used */ - unset_primary_address(n); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_RECONNECT_ATS, - GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: - /* primary went down while we were waiting for SYN_ACK on secondary; - secondary as primary */ - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Connection `%s' %p to peer `%s' was terminated while switching, " - "switching to alternative address `%s' %p\n", - GST_plugins_a2s(n->primary_address.address), - n->primary_address.session, - GNUNET_i2s(peer), - GST_plugins_a2s(n->alternative_address.address), - n->alternative_address.session); - - /* Destroy the inbound address since it cannot be used */ - free_address(&n->primary_address); - n->primary_address = n->alternative_address; - GNUNET_assert(GNUNET_YES == - GST_ats_is_known(n->primary_address.address, + { + case GNUNET_TRANSPORT_PS_NOT_CONNECTED: + GNUNET_break (0); + free_neighbour (n); + return GNUNET_YES; + + case GNUNET_TRANSPORT_PS_INIT_ATS: + GNUNET_break (0); + free_neighbour (n); + return GNUNET_YES; + + case GNUNET_TRANSPORT_PS_SYN_SENT: + /* The session used to send the SYN terminated: + * this implies a connect error*/ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to send SYN in CONNECT_SENT with `%s' %p: session terminated\n", + GST_plugins_a2s (n->primary_address.address), + n->primary_address.session); + + /* Destroy the address since it cannot be used */ + unset_primary_address (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_INIT_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: + case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: + /* error on inbound session; free neighbour entirely */ + free_neighbour (n); + return GNUNET_YES; + + case GNUNET_TRANSPORT_PS_CONNECTED: + /* Our primary connection died, try a fast reconnect */ + unset_primary_address (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_RECONNECT_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_ATS: + /* we don't have an address, how can it go down? */ + GNUNET_break (0); + break; + + case GNUNET_TRANSPORT_PS_RECONNECT_SENT: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to send SYN in RECONNECT_SENT with `%s' %p: session terminated\n", + GST_plugins_a2s (n->primary_address.address), + n->primary_address.session); + /* Destroy the address since it cannot be used */ + unset_primary_address (n); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_RECONNECT_ATS, + GNUNET_TIME_relative_to_absolute ( + ATS_RESPONSE_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: + /* primary went down while we were waiting for SYN_ACK on secondary; + secondary as primary */ + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Connection `%s' %p to peer `%s' was terminated while switching, " + "switching to alternative address `%s' %p\n", + GST_plugins_a2s (n->primary_address.address), + n->primary_address.session, + GNUNET_i2s (peer), + GST_plugins_a2s (n->alternative_address.address), + n->alternative_address.session); + + /* Destroy the inbound address since it cannot be used */ + free_address (&n->primary_address); + n->primary_address = n->alternative_address; + GNUNET_assert (GNUNET_YES == + GST_ats_is_known (n->primary_address.address, n->primary_address.session)); - memset(&n->alternative_address, - 0, - sizeof(struct NeighbourAddress)); - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_RECONNECT_SENT, - GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT)); - break; - - case GNUNET_TRANSPORT_PS_DISCONNECT: - unset_primary_address(n); - break; - - case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: - /* neighbour was freed and plugins told to terminate session */ - return GNUNET_NO; + memset (&n->alternative_address, + 0, + sizeof(struct NeighbourAddress)); + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_RECONNECT_SENT, + GNUNET_TIME_relative_to_absolute ( + FAST_RECONNECT_TIMEOUT)); + break; + + case GNUNET_TRANSPORT_PS_DISCONNECT: + unset_primary_address (n); + break; + + case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: + /* neighbour was freed and plugins told to terminate session */ + return GNUNET_NO; - default: - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Unhandled state `%s'\n", - GNUNET_TRANSPORT_ps2s(n->state)); - GNUNET_break(0); - break; - } + default: + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unhandled state `%s'\n", + GNUNET_TRANSPORT_ps2s (n->state)); + GNUNET_break (0); + break; + } if (NULL != n->task) - GNUNET_SCHEDULER_cancel(n->task); - n->task = GNUNET_SCHEDULER_add_now(&master_task, n); + GNUNET_SCHEDULER_cancel (n->task); + n->task = GNUNET_SCHEDULER_add_now (&master_task, n); return GNUNET_YES; } @@ -3454,32 +3532,32 @@ GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer, * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { struct NeighbourMapEntry *n; - (void)session; - if (ntohs(message->size) != sizeof(struct GNUNET_MessageHeader)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# ACK messages received"), - 1, - GNUNET_NO); - if (NULL == (n = lookup_neighbour(&address->peer))) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received ACK for peer `%s' in state %s/%s\n", - GNUNET_i2s(&address->peer), - GNUNET_TRANSPORT_ps2s(n->state), - print_ack_state(n->ack_state)); + (void) session; + if (ntohs (message->size) != sizeof(struct GNUNET_MessageHeader)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# ACK messages received"), + 1, + GNUNET_NO); + if (NULL == (n = lookup_neighbour (&address->peer))) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received ACK for peer `%s' in state %s/%s\n", + GNUNET_i2s (&address->peer), + GNUNET_TRANSPORT_ps2s (n->state), + print_ack_state (n->ack_state)); /* Check if we are in a plausible state for having sent a SYN_ACK. If not, return, otherwise break. @@ -3495,46 +3573,47 @@ GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message, if (((GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) && (ACK_SEND_ACK != n->ack_state)) || (NULL == n->primary_address.address)) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Received unexpected ACK message from peer `%s' in state %s/%s\n", - GNUNET_i2s(&address->peer), - GNUNET_TRANSPORT_ps2s(n->state), - print_ack_state(n->ack_state)); - - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# unexpected ACK messages"), - 1, - GNUNET_NO); - return GNUNET_OK; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received unexpected ACK message from peer `%s' in state %s/%s\n", + GNUNET_i2s (&address->peer), + GNUNET_TRANSPORT_ps2s (n->state), + print_ack_state (n->ack_state)); + + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# unexpected ACK messages"), + 1, + GNUNET_NO); + return GNUNET_OK; + } if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) - { - /* We tried to switch addresses while being connect. We explicitly wait - * for a SYN_ACK before going to GNUNET_TRANSPORT_PS_CONNECTED, - * so we do not want to set the address as in use! */ - return GNUNET_OK; - } - set_state_and_timeout(n, - GNUNET_TRANSPORT_PS_CONNECTED, - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); + { + /* We tried to switch addresses while being connect. We explicitly wait + * for a SYN_ACK before going to GNUNET_TRANSPORT_PS_CONNECTED, + * so we do not want to set the address as in use! */ + return GNUNET_OK; + } + set_state_and_timeout (n, + GNUNET_TRANSPORT_PS_CONNECTED, + GNUNET_TIME_relative_to_absolute ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); if (NULL == n->primary_address.address) - { - /* See issue #3693. - * We are in state = PSY_SYN_RECV_ACK or ack_state = ACK_SEND_ACK, which - * really means we did try (and succeed) to send a SYN and are waiting for - * an ACK. - * That suggests that the primary_address used to be non-NULL, but maybe it - * got reset to NULL without the state being changed appropriately? - */ - GNUNET_break(0); - return GNUNET_OK; - } + { + /* See issue #3693. + * We are in state = PSY_SYN_RECV_ACK or ack_state = ACK_SEND_ACK, which + * really means we did try (and succeed) to send a SYN and are waiting for + * an ACK. + * That suggests that the primary_address used to be non-NULL, but maybe it + * got reset to NULL without the state being changed appropriately? + */ + GNUNET_break (0); + return GNUNET_OK; + } /* Reset backoff for primary address */ - GST_ats_block_reset(n->primary_address.address, - n->primary_address.session); + GST_ats_block_reset (n->primary_address.address, + n->primary_address.session); return GNUNET_OK; } @@ -3546,9 +3625,9 @@ GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message, * @return #GNUNET_YES if we are connected, #GNUNET_NO if not */ int -GST_neighbours_test_connected(const struct GNUNET_PeerIdentity *target) +GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target) { - return test_connected(lookup_neighbour(target)); + return test_connected (lookup_neighbour (target)); } @@ -3558,15 +3637,15 @@ GST_neighbours_test_connected(const struct GNUNET_PeerIdentity *target) * @param cls the `struct NeighbourMapEntry` to free */ static void -delayed_disconnect(void *cls) +delayed_disconnect (void *cls) { struct NeighbourMapEntry *n = cls; n->delayed_disconnect_task = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Disconnecting by request from peer %s\n", - GNUNET_i2s(&n->id)); - free_neighbour(n); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Disconnecting by request from peer %s\n", + GNUNET_i2s (&n->id)); + free_neighbour (n); } @@ -3578,42 +3657,44 @@ delayed_disconnect(void *cls) * @param msg the quota message */ void -GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *msg) +GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *msg) { struct NeighbourMapEntry *n; const struct GNUNET_ATS_SessionQuotaMessage *sqm; struct GNUNET_BANDWIDTH_Value32NBO last; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received QUOTA message from peer `%s'\n", - GNUNET_i2s(peer)); - if (ntohs(msg->size) != sizeof(struct GNUNET_ATS_SessionQuotaMessage)) - { - GNUNET_break_op(0); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# quota messages ignored (malformed)"), - 1, - GNUNET_NO); - return; - } - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# QUOTA messages received"), - 1, GNUNET_NO); - sqm = (const struct GNUNET_ATS_SessionQuotaMessage *)msg; - if (NULL == (n = lookup_neighbour(peer))) - { - /* gone already */ - return; - } - last = GNUNET_BANDWIDTH_value_max(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, - GNUNET_BANDWIDTH_value_init(ntohl(sqm->quota))); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received QUOTA message from peer `%s'\n", + GNUNET_i2s (peer)); + if (ntohs (msg->size) != sizeof(struct GNUNET_ATS_SessionQuotaMessage)) + { + GNUNET_break_op (0); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# quota messages ignored (malformed)"), + 1, + GNUNET_NO); + return; + } + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# QUOTA messages received"), + 1, GNUNET_NO); + sqm = (const struct GNUNET_ATS_SessionQuotaMessage *) msg; + if (NULL == (n = lookup_neighbour (peer))) + { + /* gone already */ + return; + } + last = GNUNET_BANDWIDTH_value_max (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, + GNUNET_BANDWIDTH_value_init (ntohl ( + sqm->quota))); if (last.value__ != n->neighbour_receive_quota.value__) - { - n->neighbour_receive_quota = last; - send_outbound_quota_to_clients(n); - } + { + n->neighbour_receive_quota = last; + send_outbound_quota_to_clients (n); + } } @@ -3625,85 +3706,91 @@ GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer, * @param msg the disconnect message */ void -GST_neighbours_handle_disconnect_message(const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *msg) +GST_neighbours_handle_disconnect_message (const struct + GNUNET_PeerIdentity *peer, + const struct + GNUNET_MessageHeader *msg) { struct NeighbourMapEntry *n; const struct GNUNET_ATS_SessionDisconnectMessage *sdm; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received DISCONNECT message from peer `%s'\n", - GNUNET_i2s(peer)); - if (ntohs(msg->size) != sizeof(struct GNUNET_ATS_SessionDisconnectMessage)) - { - GNUNET_break_op(0); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# disconnect messages ignored (malformed)"), - 1, - GNUNET_NO); - return; - } - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# DISCONNECT messages received"), - 1, GNUNET_NO); - sdm = (const struct GNUNET_ATS_SessionDisconnectMessage *)msg; - if (NULL == (n = lookup_neighbour(peer))) - { - /* gone already */ - return; - } - if (GNUNET_TIME_absolute_ntoh(sdm->timestamp).abs_value_us <= n->connect_ack_timestamp.abs_value_us) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# disconnect messages ignored (timestamp)"), - 1, - GNUNET_NO); - return; - } - if (0 != memcmp(peer, - &sdm->public_key, - sizeof(struct GNUNET_PeerIdentity))) - { - GNUNET_break_op(0); - return; - } - if (ntohl(sdm->purpose.size) != - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + - sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + - sizeof(struct GNUNET_TIME_AbsoluteNBO)) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "DISCONNECT message from peer `%s' has invalid size\n", - GNUNET_i2s(peer)); - GNUNET_break_op(0); - return; - } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received DISCONNECT message from peer `%s'\n", + GNUNET_i2s (peer)); + if (ntohs (msg->size) != sizeof(struct GNUNET_ATS_SessionDisconnectMessage)) + { + GNUNET_break_op (0); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# disconnect messages ignored (malformed)"), + 1, + GNUNET_NO); + return; + } + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# DISCONNECT messages received"), + 1, GNUNET_NO); + sdm = (const struct GNUNET_ATS_SessionDisconnectMessage *) msg; + if (NULL == (n = lookup_neighbour (peer))) + { + /* gone already */ + return; + } + if (GNUNET_TIME_absolute_ntoh (sdm->timestamp).abs_value_us <= + n->connect_ack_timestamp.abs_value_us) + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# disconnect messages ignored (timestamp)"), + 1, + GNUNET_NO); + return; + } + if (0 != memcmp (peer, + &sdm->public_key, + sizeof(struct GNUNET_PeerIdentity))) + { + GNUNET_break_op (0); + return; + } + if (ntohl (sdm->purpose.size) != + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + + sizeof(struct GNUNET_TIME_AbsoluteNBO)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "DISCONNECT message from peer `%s' has invalid size\n", + GNUNET_i2s (peer)); + GNUNET_break_op (0); + return; + } if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, - &sdm->purpose, - &sdm->signature, - &sdm->public_key)) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "DISCONNECT message from peer `%s' cannot be verified \n", - GNUNET_i2s(peer)); - GNUNET_break_op(0); - return; - } + GNUNET_CRYPTO_eddsa_verify ( + GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, + &sdm->purpose, + &sdm->signature, + &sdm->public_key)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "DISCONNECT message from peer `%s' cannot be verified \n", + GNUNET_i2s (peer)); + GNUNET_break_op (0); + return; + } if (NULL == n->delayed_disconnect_task) - { - n->delayed_disconnect_task = GNUNET_SCHEDULER_add_now(&delayed_disconnect, - n); - } + { + n->delayed_disconnect_task = GNUNET_SCHEDULER_add_now (&delayed_disconnect, + n); + } } /** * Closure for the #neighbours_iterate() function. */ -struct IteratorContext { +struct IteratorContext +{ /** * Function to call on each connected neighbour. */ @@ -3725,32 +3812,32 @@ struct IteratorContext { * @return #GNUNET_OK (continue to iterate) */ static int -neighbours_iterate(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +neighbours_iterate (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct IteratorContext *ic = cls; struct NeighbourMapEntry *n = value; struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; - (void)key; + (void) key; if (NULL != n->primary_address.address) - { - bandwidth_in = n->primary_address.bandwidth_in; - bandwidth_out = n->primary_address.bandwidth_out; - } + { + bandwidth_in = n->primary_address.bandwidth_in; + bandwidth_out = n->primary_address.bandwidth_out; + } else - { - bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; - bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; - } - ic->cb(ic->cb_cls, - &n->id, - n->primary_address.address, - n->state, - n->timeout, - bandwidth_in, bandwidth_out); + { + bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; + bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; + } + ic->cb (ic->cb_cls, + &n->id, + n->primary_address.address, + n->state, + n->timeout, + bandwidth_in, bandwidth_out); return GNUNET_OK; } @@ -3762,8 +3849,8 @@ neighbours_iterate(void *cls, * @param cb_cls closure for @a cb */ void -GST_neighbours_iterate(GST_NeighbourIterator cb, - void *cb_cls) +GST_neighbours_iterate (GST_NeighbourIterator cb, + void *cb_cls) { struct IteratorContext ic; @@ -3771,9 +3858,9 @@ GST_neighbours_iterate(GST_NeighbourIterator cb, return; /* can happen during shutdown */ ic.cb = cb; ic.cb_cls = cb_cls; - GNUNET_CONTAINER_multipeermap_iterate(neighbours, - &neighbours_iterate, - &ic); + GNUNET_CONTAINER_multipeermap_iterate (neighbours, + &neighbours_iterate, + &ic); } @@ -3783,21 +3870,22 @@ GST_neighbours_iterate(GST_NeighbourIterator cb, * @param target peer to disconnect from */ void -GST_neighbours_force_disconnect(const struct GNUNET_PeerIdentity *target) +GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target) { struct NeighbourMapEntry *n; - if (NULL == (n = lookup_neighbour(target))) + if (NULL == (n = lookup_neighbour (target))) return; /* not active */ - if (GNUNET_YES == test_connected(n)) - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# disconnected from peer upon explicit request"), - 1, - GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Forced disconnect from peer %s\n", - GNUNET_i2s(target)); - disconnect_neighbour(n); + if (GNUNET_YES == test_connected (n)) + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# disconnected from peer upon explicit request"), + 1, + GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Forced disconnect from peer %s\n", + GNUNET_i2s (target)); + disconnect_neighbour (n); } @@ -3808,11 +3896,11 @@ GST_neighbours_force_disconnect(const struct GNUNET_PeerIdentity *target) * @return address currently used */ const struct GNUNET_HELLO_Address * -GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer) +GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer) { struct NeighbourMapEntry *n; - n = lookup_neighbour(peer); + n = lookup_neighbour (peer); if (NULL == n) return NULL; return n->primary_address.address; @@ -3825,14 +3913,15 @@ GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer) * @param max_fds maximum number of fds to use */ void -GST_neighbours_start(unsigned int max_fds) -{ - (void)max_fds; - neighbours = GNUNET_CONTAINER_multipeermap_create(NEIGHBOUR_TABLE_SIZE, - GNUNET_NO); - util_transmission_tk = GNUNET_SCHEDULER_add_delayed(UTIL_TRANSMISSION_INTERVAL, - &utilization_transmission, - NULL); +GST_neighbours_start (unsigned int max_fds) +{ + (void) max_fds; + neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, + GNUNET_NO); + util_transmission_tk = GNUNET_SCHEDULER_add_delayed ( + UTIL_TRANSMISSION_INTERVAL, + &utilization_transmission, + NULL); } @@ -3845,18 +3934,18 @@ GST_neighbours_start(unsigned int max_fds) * @return #GNUNET_OK (continue to iterate) */ static int -disconnect_all_neighbours(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +disconnect_all_neighbours (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct NeighbourMapEntry *n = value; - (void)cls; - (void)key; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting peer `%4s' during shutdown\n", - GNUNET_i2s(&n->id)); - free_neighbour(n); + (void) cls; + (void) key; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Disconnecting peer `%4s' during shutdown\n", + GNUNET_i2s (&n->id)); + free_neighbour (n); return GNUNET_OK; } @@ -3865,19 +3954,19 @@ disconnect_all_neighbours(void *cls, * Cleanup the neighbours subsystem. */ void -GST_neighbours_stop() +GST_neighbours_stop () { if (NULL == neighbours) return; if (NULL != util_transmission_tk) - { - GNUNET_SCHEDULER_cancel(util_transmission_tk); - util_transmission_tk = NULL; - } - GNUNET_CONTAINER_multipeermap_iterate(neighbours, - &disconnect_all_neighbours, - NULL); - GNUNET_CONTAINER_multipeermap_destroy(neighbours); + { + GNUNET_SCHEDULER_cancel (util_transmission_tk); + util_transmission_tk = NULL; + } + GNUNET_CONTAINER_multipeermap_iterate (neighbours, + &disconnect_all_neighbours, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (neighbours); neighbours = NULL; } diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index 2ce149cf3..13aeab4e6 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h @@ -40,14 +40,14 @@ * @param max_fds maximum number of fds to use */ void -GST_neighbours_start(unsigned int max_fds); +GST_neighbours_start (unsigned int max_fds); /** * Cleanup the neighbours subsystem. */ void -GST_neighbours_stop(void); +GST_neighbours_stop (void); /** @@ -57,7 +57,7 @@ GST_neighbours_stop(void); * @return #GNUNET_YES if we are connected, #GNUNET_NO if not */ int -GST_neighbours_test_connected(const struct GNUNET_PeerIdentity *target); +GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target); /** @@ -86,11 +86,11 @@ typedef void * @param cont_cls closure for @a cont */ void -GST_neighbours_send(const struct GNUNET_PeerIdentity *target, - const void *msg, - size_t msg_size, - struct GNUNET_TIME_Relative timeout, - GST_NeighbourSendContinuation cont, void *cont_cls); +GST_neighbours_send (const struct GNUNET_PeerIdentity *target, + const void *msg, + size_t msg_size, + struct GNUNET_TIME_Relative timeout, + GST_NeighbourSendContinuation cont, void *cont_cls); /** @@ -105,9 +105,10 @@ GST_neighbours_send(const struct GNUNET_PeerIdentity *target, * @return how long to wait before reading more from this sender */ struct GNUNET_TIME_Relative -GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender, - ssize_t size, - int *do_forward); +GST_neighbours_calculate_receive_delay (const struct + GNUNET_PeerIdentity *sender, + ssize_t size, + int *do_forward); /** @@ -118,8 +119,8 @@ GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender, * @param m the keep alive message containing the nonce to respond to */ void -GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour, - const struct GNUNET_MessageHeader *m); +GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour, + const struct GNUNET_MessageHeader *m); /** @@ -131,8 +132,8 @@ GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour, * @param m the message containing the keep alive response */ void -GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour, - const struct GNUNET_MessageHeader *m); +GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour, + const struct GNUNET_MessageHeader *m); /** @@ -141,7 +142,7 @@ GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour, * @param target peer to disconnect from */ void -GST_neighbours_force_disconnect(const struct GNUNET_PeerIdentity *target); +GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target); /** @@ -172,7 +173,7 @@ typedef void * @param cb_cls closure for @a cb */ void -GST_neighbours_iterate(GST_NeighbourIterator cb, void *cb_cls); +GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls); /** @@ -184,8 +185,8 @@ GST_neighbours_iterate(GST_NeighbourIterator cb, void *cb_cls); * this session was not in use */ int -GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session); +GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session); /** @@ -197,8 +198,8 @@ GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer, * @param message the message we received (really only the size is used) */ void -GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address, - const struct GNUNET_MessageHeader *message); +GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address, + const struct GNUNET_MessageHeader *message); /** @@ -211,9 +212,9 @@ GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address, * @param message the message we sent (really only the size is used) */ void -GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - size_t size); +GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + size_t size); /** @@ -226,10 +227,12 @@ GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address, * @param bandwidth_out outbound quota to be used when connection is up */ void -GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); +GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO + bandwidth_out); /** @@ -241,8 +244,8 @@ GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address, * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message, - const struct GNUNET_PeerIdentity *peer); +GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, + const struct GNUNET_PeerIdentity *peer); /** @@ -255,9 +258,11 @@ GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message, * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session); +GST_neighbours_handle_session_syn_ack (const struct + GNUNET_MessageHeader *message, + const struct + GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session); /** @@ -271,9 +276,9 @@ GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session); +GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session); /** @@ -283,7 +288,7 @@ GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message, * @return address currently used */ const struct GNUNET_HELLO_Address * -GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer); +GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer); /** @@ -294,8 +299,8 @@ GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer); * @param msg the quota message */ void -GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *msg); +GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *msg); /** @@ -306,8 +311,10 @@ GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer, * @param msg the disconnect message */ void -GST_neighbours_handle_disconnect_message(const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *msg); +GST_neighbours_handle_disconnect_message (const struct + GNUNET_PeerIdentity *peer, + const struct + GNUNET_MessageHeader *msg); #endif diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c index b9203f9f4..d0a10cbc7 100644 --- a/src/transport/gnunet-service-transport_plugins.c +++ b/src/transport/gnunet-service-transport_plugins.c @@ -32,7 +32,8 @@ /** * Entry in doubly-linked list of all of our plugins. */ -struct TransportPlugin { +struct TransportPlugin +{ /** * This is a doubly-linked list. */ @@ -86,12 +87,12 @@ static struct TransportPlugin *plugins_tail; * @param distance new distance */ static void -plugin_env_update_distance(void *cls, - const struct GNUNET_HELLO_Address *address, - uint32_t distance) +plugin_env_update_distance (void *cls, + const struct GNUNET_HELLO_Address *address, + uint32_t distance) { - GST_ats_update_distance(address, - distance); + GST_ats_update_distance (address, + distance); } @@ -105,18 +106,18 @@ plugin_env_update_distance(void *cls, * @return type of the network @a addr belongs to */ static enum GNUNET_NetworkType -plugin_env_address_to_type(void *cls, - const struct sockaddr *addr, - size_t addrlen) +plugin_env_address_to_type (void *cls, + const struct sockaddr *addr, + size_t addrlen) { if (NULL == GST_is) - { - GNUNET_break(0); - return GNUNET_NT_UNSPECIFIED; - } - return GNUNET_NT_scanner_get_type(GST_is, - addr, - addrlen); + { + GNUNET_break (0); + return GNUNET_NT_UNSPECIFIED; + } + return GNUNET_NT_scanner_get_type (GST_is, + addr, + addrlen); } @@ -133,10 +134,10 @@ plugin_env_address_to_type(void *cls, * @param address_type_cb function to call when a address type is requested */ void -GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, - GNUNET_TRANSPORT_AddressNotification address_cb, - GNUNET_TRANSPORT_SessionStart session_start_cb, - GNUNET_TRANSPORT_SessionEnd session_end_cb) +GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, + GNUNET_TRANSPORT_AddressNotification address_cb, + GNUNET_TRANSPORT_SessionStart session_start_cb, + GNUNET_TRANSPORT_SessionEnd session_end_cb) { struct TransportPlugin *plug; struct TransportPlugin *next; @@ -147,175 +148,175 @@ GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, int fail; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number(GST_cfg, - "TRANSPORT", - "NEIGHBOUR_LIMIT", - &tneigh)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Transport service is lacking NEIGHBOUR_LIMIT option.\n")); - return; - } + GNUNET_CONFIGURATION_get_value_number (GST_cfg, + "TRANSPORT", + "NEIGHBOUR_LIMIT", + &tneigh)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Transport service is lacking NEIGHBOUR_LIMIT option.\n")); + return; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string(GST_cfg, - "TRANSPORT", - "PLUGINS", - &plugs)) + GNUNET_CONFIGURATION_get_value_string (GST_cfg, + "TRANSPORT", + "PLUGINS", + &plugs)) return; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Starting transport plugins `%s'\n"), - plugs); - for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " ")) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Loading `%s' transport plugin\n"), - pos); - GNUNET_asprintf(&libname, - "libgnunet_plugin_transport_%s", - pos); - plug = GNUNET_new(struct TransportPlugin); - plug->short_name = GNUNET_strdup(pos); - plug->lib_name = libname; - plug->env.cfg = GST_cfg; - plug->env.my_identity = &GST_my_identity; - plug->env.get_our_hello = &GST_hello_get; - plug->env.cls = plug->short_name; - plug->env.receive = recv_cb; - plug->env.notify_address = address_cb; - plug->env.session_start = session_start_cb; - plug->env.session_end = session_end_cb; - plug->env.get_address_type = &plugin_env_address_to_type; - plug->env.update_address_distance = &plugin_env_update_distance; - plug->env.max_connections = tneigh; - plug->env.stats = GST_stats; - GNUNET_CONTAINER_DLL_insert(plugins_head, - plugins_tail, - plug); - } - GNUNET_free(plugs); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Starting transport plugins `%s'\n"), + plugs); + for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " ")) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Loading `%s' transport plugin\n"), + pos); + GNUNET_asprintf (&libname, + "libgnunet_plugin_transport_%s", + pos); + plug = GNUNET_new (struct TransportPlugin); + plug->short_name = GNUNET_strdup (pos); + plug->lib_name = libname; + plug->env.cfg = GST_cfg; + plug->env.my_identity = &GST_my_identity; + plug->env.get_our_hello = &GST_hello_get; + plug->env.cls = plug->short_name; + plug->env.receive = recv_cb; + plug->env.notify_address = address_cb; + plug->env.session_start = session_start_cb; + plug->env.session_end = session_end_cb; + plug->env.get_address_type = &plugin_env_address_to_type; + plug->env.update_address_distance = &plugin_env_update_distance; + plug->env.max_connections = tneigh; + plug->env.stats = GST_stats; + GNUNET_CONTAINER_DLL_insert (plugins_head, + plugins_tail, + plug); + } + GNUNET_free (plugs); next = plugins_head; while (NULL != next) + { + plug = next; + next = plug->next; + plug->api = GNUNET_PLUGIN_load (plug->lib_name, + &plug->env); + if (NULL == plug->api) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to load transport plugin for `%s'\n"), + plug->lib_name); + GNUNET_CONTAINER_DLL_remove (plugins_head, + plugins_tail, + plug); + GNUNET_free (plug->short_name); + GNUNET_free (plug->lib_name); + GNUNET_free (plug); + continue; + } + fail = GNUNET_NO; + if (NULL == plug->api->address_pretty_printer) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "address_pretty_printer", + plug->lib_name); + } + if (NULL == plug->api->address_to_string) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "address_to_string", + plug->lib_name); + } + if (NULL == plug->api->string_to_address) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "string_to_address", + plug->lib_name); + } + if (NULL == plug->api->check_address) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "check_address", + plug->lib_name); + } + if (NULL == plug->api->get_session) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "get_session", + plug->lib_name); + } + if (NULL == plug->api->get_network) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "get_network", + plug->lib_name); + } + if (NULL == plug->api->send) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "send", + plug->lib_name); + } + if (NULL == plug->api->disconnect_peer) { - plug = next; - next = plug->next; - plug->api = GNUNET_PLUGIN_load(plug->lib_name, - &plug->env); - if (NULL == plug->api) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Failed to load transport plugin for `%s'\n"), - plug->lib_name); - GNUNET_CONTAINER_DLL_remove(plugins_head, - plugins_tail, - plug); - GNUNET_free(plug->short_name); - GNUNET_free(plug->lib_name); - GNUNET_free(plug); - continue; - } - fail = GNUNET_NO; - if (NULL == plug->api->address_pretty_printer) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "address_pretty_printer", - plug->lib_name); - } - if (NULL == plug->api->address_to_string) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "address_to_string", - plug->lib_name); - } - if (NULL == plug->api->string_to_address) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "string_to_address", - plug->lib_name); - } - if (NULL == plug->api->check_address) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "check_address", - plug->lib_name); - } - if (NULL == plug->api->get_session) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "get_session", - plug->lib_name); - } - if (NULL == plug->api->get_network) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "get_network", - plug->lib_name); - } - if (NULL == plug->api->send) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "send", - plug->lib_name); - } - if (NULL == plug->api->disconnect_peer) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "disconnect_peer", - plug->lib_name); - } - if (NULL == plug->api->disconnect_session) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "disconnect_session", - plug->lib_name); - } - if (NULL == plug->api->query_keepalive_factor) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "query_keepalive_factor", - plug->lib_name); - } - if (NULL == plug->api->update_session_timeout) - { - fail = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Missing function `%s' in transport plugin for `%s'\n"), - "update_session_timeout", - plug->lib_name); - } - if (GNUNET_YES == fail) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Did not load plugin `%s' due to missing functions\n"), - plug->lib_name); - GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api)); - GNUNET_CONTAINER_DLL_remove(plugins_head, - plugins_tail, - plug); - GNUNET_free(plug->short_name); - GNUNET_free(plug->lib_name); - GNUNET_free(plug); - } + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "disconnect_peer", + plug->lib_name); } + if (NULL == plug->api->disconnect_session) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "disconnect_session", + plug->lib_name); + } + if (NULL == plug->api->query_keepalive_factor) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "query_keepalive_factor", + plug->lib_name); + } + if (NULL == plug->api->update_session_timeout) + { + fail = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Missing function `%s' in transport plugin for `%s'\n"), + "update_session_timeout", + plug->lib_name); + } + if (GNUNET_YES == fail) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Did not load plugin `%s' due to missing functions\n"), + plug->lib_name); + GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); + GNUNET_CONTAINER_DLL_remove (plugins_head, + plugins_tail, + plug); + GNUNET_free (plug->short_name); + GNUNET_free (plug->lib_name); + GNUNET_free (plug); + } + } } @@ -323,18 +324,18 @@ GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, * Unload all plugins */ void -GST_plugins_unload() +GST_plugins_unload () { struct TransportPlugin *plug; while (NULL != (plug = plugins_head)) - { - GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api)); - GNUNET_free(plug->lib_name); - GNUNET_free(plug->short_name); - GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug); - GNUNET_free(plug); - } + { + GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); + GNUNET_free (plug->lib_name); + GNUNET_free (plug->short_name); + GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug); + GNUNET_free (plug); + } } @@ -345,12 +346,12 @@ GST_plugins_unload() * @return the plugin's API, NULL if the plugin is not loaded */ struct GNUNET_TRANSPORT_PluginFunctions * -GST_plugins_find(const char *name) +GST_plugins_find (const char *name) { struct TransportPlugin *pos; for (pos = plugins_head; NULL != pos; pos = pos->next) - if (0 == strcmp(name, pos->short_name)) + if (0 == strcmp (name, pos->short_name)) break; if (NULL == pos) return NULL; @@ -369,18 +370,18 @@ GST_plugins_find(const char *name) * @return the plugin's API, NULL if the plugin is not loaded */ struct GNUNET_TRANSPORT_PluginFunctions * -GST_plugins_printer_find(const char *name) +GST_plugins_printer_find (const char *name) { struct TransportPlugin *pos; - char *stripped = GNUNET_strdup(name); - char *sep = strchr(stripped, '_'); + char *stripped = GNUNET_strdup (name); + char *sep = strchr (stripped, '_'); if (NULL != sep) sep[0] = '\0'; for (pos = plugins_head; NULL != pos; pos = pos->next) - if (pos->short_name == strstr(pos->short_name, stripped)) + if (pos->short_name == strstr (pos->short_name, stripped)) break; - GNUNET_free(stripped); + GNUNET_free (stripped); if (NULL == pos) return NULL; return pos->api; @@ -395,7 +396,7 @@ GST_plugins_printer_find(const char *name) * @return statically allocated (!) human-readable address */ const char * -GST_plugins_a2s(const struct GNUNET_HELLO_Address *address) +GST_plugins_a2s (const struct GNUNET_HELLO_Address *address) { struct GNUNET_TRANSPORT_PluginFunctions *api; static char unable_to_show[1024]; @@ -405,26 +406,26 @@ GST_plugins_a2s(const struct GNUNET_HELLO_Address *address) return ""; if (0 == address->address_length) return TRANSPORT_SESSION_INBOUND_STRING; /* Addresse with length 0 are inbound, address->address itself may be NULL */ - api = GST_plugins_printer_find(address->transport_name); + api = GST_plugins_printer_find (address->transport_name); if (NULL == api) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Failed to find transport plugin `%s'\n", - address->transport_name); - return ""; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Failed to find transport plugin `%s'\n", + address->transport_name); + return ""; + } if (0 == address->address_length) - { - GNUNET_snprintf(unable_to_show, - sizeof(unable_to_show), - "", - (unsigned int)address->address_length, - address->transport_name); - return unable_to_show; - } - return(NULL != (s = api->address_to_string(NULL, - address->address, - address->address_length)) + { + GNUNET_snprintf (unable_to_show, + sizeof(unable_to_show), + "", + (unsigned int) address->address_length, + address->transport_name); + return unable_to_show; + } + return(NULL != (s = api->address_to_string (NULL, + address->address, + address->address_length)) ? s : ""); } @@ -437,18 +438,18 @@ GST_plugins_a2s(const struct GNUNET_HELLO_Address *address) * @param cb_cls closure for @a cb */ void -GST_plugins_monitor_subscribe(GNUNET_TRANSPORT_SessionInfoCallback cb, - void *cb_cls) +GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb, + void *cb_cls) { struct TransportPlugin *pos; for (pos = plugins_head; NULL != pos; pos = pos->next) if (NULL == pos->api->setup_monitor) - GNUNET_break(0); + GNUNET_break (0); else - pos->api->setup_monitor(pos->api->cls, - cb, - cb_cls); + pos->api->setup_monitor (pos->api->cls, + cb, + cb_cls); } diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h index 2b6f6f070..0e69da074 100644 --- a/src/transport/gnunet-service-transport_plugins.h +++ b/src/transport/gnunet-service-transport_plugins.h @@ -49,16 +49,16 @@ * @param metric_update_cb function to call when address metrics change */ void -GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, - GNUNET_TRANSPORT_AddressNotification address_cb, - GNUNET_TRANSPORT_SessionStart session_start_cb, - GNUNET_TRANSPORT_SessionEnd session_end_cb); +GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, + GNUNET_TRANSPORT_AddressNotification address_cb, + GNUNET_TRANSPORT_SessionStart session_start_cb, + GNUNET_TRANSPORT_SessionEnd session_end_cb); /** * Unload all plugins */ void -GST_plugins_unload(void); +GST_plugins_unload (void); /** @@ -68,7 +68,7 @@ GST_plugins_unload(void); * @return the plugin's API, NULL if the plugin is not loaded */ struct GNUNET_TRANSPORT_PluginFunctions * -GST_plugins_find(const char *name); +GST_plugins_find (const char *name); /** @@ -82,7 +82,7 @@ GST_plugins_find(const char *name); * @return the plugin's API, NULL if the plugin is not loaded */ struct GNUNET_TRANSPORT_PluginFunctions * -GST_plugins_printer_find(const char *name); +GST_plugins_printer_find (const char *name); /** @@ -93,7 +93,7 @@ GST_plugins_printer_find(const char *name); * @return statically allocated (!) human-readable address */ const char * -GST_plugins_a2s(const struct GNUNET_HELLO_Address *address); +GST_plugins_a2s (const struct GNUNET_HELLO_Address *address); /** @@ -103,8 +103,8 @@ GST_plugins_a2s(const struct GNUNET_HELLO_Address *address); * @param cb_cls closure for @a cb */ void -GST_plugins_monitor_subscribe(GNUNET_TRANSPORT_SessionInfoCallback cb, - void *cb_cls); +GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb, + void *cb_cls); #endif diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 71f43fada..ec8600b7f 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c @@ -42,7 +42,8 @@ * was successful? If that is clarified/determined, "UGH" in * ~gnunetpeerinfogtk.c:1103 should be resolved. */ -enum GNUNET_TRANSPORT_ValidationState { +enum GNUNET_TRANSPORT_ValidationState +{ /** * Undefined state * @@ -89,14 +90,16 @@ enum GNUNET_TRANSPORT_ValidationState { * OTOH, we don't want to spend too much time generating PONG signatures, * so they must have some lifetime to reduce our CPU usage. */ -#define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 1) +#define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_HOURS, 1) /** * After how long do we expire an address in a HELLO that we just * validated? This value is also used for our own addresses when we * create a HELLO. */ -#define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 12) +#define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_HOURS, 12) /** * How often do we allow PINGing an address that we have not yet @@ -104,24 +107,28 @@ enum GNUNET_TRANSPORT_ValidationState { * we cannot validate (because after this time we can destroy the * validation record). */ -#define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) +#define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MINUTES, 5) /** * How often do we PING an address that we have successfully validated * in the past but are not actively using? Should be (significantly) * smaller than HELLO_ADDRESS_EXPIRATION. */ -#define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) +#define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MINUTES, 15) /** * How often do we PING an address that we are currently using? */ -#define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) +#define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MINUTES, 2) /** * How much delay is acceptable for sending the PING or PONG? */ -#define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) +#define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 1) /** * Size of the validation map hashmap. @@ -147,7 +154,8 @@ GNUNET_NETWORK_STRUCT_BEGIN * or an empty address if we are just sending a PING to confirm that a * connection which the receiver (of the PING) initiated is still valid. */ -struct TransportPingMessage { +struct TransportPingMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PING */ @@ -175,7 +183,8 @@ struct TransportPingMessage { * if the PING had not address either (and we received the request via * a connection that we initiated). */ -struct TransportPongMessage { +struct TransportPongMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PONG */ @@ -214,7 +223,8 @@ GNUNET_NETWORK_STRUCT_END /** * Information about an address under validation */ -struct ValidationEntry { +struct ValidationEntry +{ /** * The address. */ @@ -352,7 +362,8 @@ static struct GNUNET_TIME_Absolute validation_next; /** * Context for the validation entry match function. */ -struct ValidationEntryMatchContext { +struct ValidationEntryMatchContext +{ /** * Where to store the result? */ @@ -371,12 +382,12 @@ struct ValidationEntryMatchContext { * is changed. */ static void -publish_ve_stat_update() +publish_ve_stat_update () { - GNUNET_STATISTICS_set(GST_stats, - gettext_noop("# Addresses in validation map"), - GNUNET_CONTAINER_multipeermap_size(validation_map), - GNUNET_NO); + GNUNET_STATISTICS_set (GST_stats, + gettext_noop ("# Addresses in validation map"), + GNUNET_CONTAINER_multipeermap_size (validation_map), + GNUNET_NO); } @@ -390,19 +401,19 @@ publish_ve_stat_update() * #GNUNET_NO if the entry does match */ static int -validation_entry_match(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +validation_entry_match (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct ValidationEntryMatchContext *vemc = cls; struct ValidationEntry *ve = value; - if (0 == GNUNET_HELLO_address_cmp(ve->address, - vemc->address)) - { - vemc->ve = ve; - return GNUNET_NO; - } + if (0 == GNUNET_HELLO_address_cmp (ve->address, + vemc->address)) + { + vemc->ve = ve; + return GNUNET_NO; + } return GNUNET_YES; } @@ -415,8 +426,8 @@ validation_entry_match(void *cls, * @param state new state */ static void -validation_entry_changed(struct ValidationEntry *ve, - enum GNUNET_TRANSPORT_ValidationState state) +validation_entry_changed (struct ValidationEntry *ve, + enum GNUNET_TRANSPORT_ValidationState state) { ve->state = state; } @@ -431,9 +442,9 @@ validation_entry_changed(struct ValidationEntry *ve, * @return #GNUNET_YES (continue to iterate) */ static int -cleanup_validation_entry(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +cleanup_validation_entry (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct ValidationEntry *ve = value; @@ -441,47 +452,47 @@ cleanup_validation_entry(void *cls, ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS; /* Notify about deleted entry */ - validation_entry_changed(ve, - GNUNET_TRANSPORT_VS_REMOVE); + validation_entry_changed (ve, + GNUNET_TRANSPORT_VS_REMOVE); if (NULL != ve->bc) - { - GST_blacklist_test_cancel(ve->bc); - ve->bc = NULL; - } - GNUNET_break(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_remove(validation_map, - &ve->address->peer, - ve)); - publish_ve_stat_update(); + { + GST_blacklist_test_cancel (ve->bc); + ve->bc = NULL; + } + GNUNET_break (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_remove (validation_map, + &ve->address->peer, + ve)); + publish_ve_stat_update (); if (GNUNET_YES == ve->known_to_ats) - { - GST_ats_expire_address(ve->address); - GNUNET_assert(GNUNET_NO == - GST_ats_is_known_no_session(ve->address)); - ve->known_to_ats = GNUNET_NO; - } - GNUNET_HELLO_address_free(ve->address); + { + GST_ats_expire_address (ve->address); + GNUNET_assert (GNUNET_NO == + GST_ats_is_known_no_session (ve->address)); + ve->known_to_ats = GNUNET_NO; + } + GNUNET_HELLO_address_free (ve->address); if (NULL != ve->timeout_task) - { - GNUNET_SCHEDULER_cancel(ve->timeout_task); - ve->timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (ve->timeout_task); + ve->timeout_task = NULL; + } if (NULL != ve->revalidation_task) - { - GNUNET_SCHEDULER_cancel(ve->revalidation_task); - ve->revalidation_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (ve->revalidation_task); + ve->revalidation_task = NULL; + } if ((GNUNET_YES == ve->expecting_pong) && (validations_running > 0)) - { - validations_running--; - GNUNET_STATISTICS_set(GST_stats, - gettext_noop("# validations running"), - validations_running, - GNUNET_NO); - } - GNUNET_free(ve); + { + validations_running--; + GNUNET_STATISTICS_set (GST_stats, + gettext_noop ("# validations running"), + validations_running, + GNUNET_NO); + } + GNUNET_free (ve); return GNUNET_OK; } @@ -493,7 +504,7 @@ cleanup_validation_entry(void *cls, * @param cls the `struct ValidationEntry` */ static void -timeout_hello_validation(void *cls) +timeout_hello_validation (void *cls) { struct ValidationEntry *ve = cls; struct GNUNET_TIME_Absolute max; @@ -503,27 +514,28 @@ timeout_hello_validation(void *cls) /* For valid addresses, we want to wait until the expire; for addresses under PING validation, we want to wait until we give up on the PING */ - max = GNUNET_TIME_absolute_max(ve->valid_until, - ve->revalidation_block); - left = GNUNET_TIME_absolute_get_remaining(max); + max = GNUNET_TIME_absolute_max (ve->valid_until, + ve->revalidation_block); + left = GNUNET_TIME_absolute_get_remaining (max); if (left.rel_value_us > 0) - { - /* We should wait a bit longer. This happens when - address lifetimes are extended due to successful - validations. */ - ve->timeout_task = - GNUNET_SCHEDULER_add_delayed(left, - &timeout_hello_validation, - ve); - return; - } - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# address records discarded (timeout)"), - 1, - GNUNET_NO); - cleanup_validation_entry(NULL, - &ve->address->peer, - ve); + { + /* We should wait a bit longer. This happens when + address lifetimes are extended due to successful + validations. */ + ve->timeout_task = + GNUNET_SCHEDULER_add_delayed (left, + &timeout_hello_validation, + ve); + return; + } + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# address records discarded (timeout)"), + 1, + GNUNET_NO); + cleanup_validation_entry (NULL, + &ve->address->peer, + ve); } @@ -540,11 +552,11 @@ timeout_hello_validation(void *cls) * #GNUNET_SYSERR if operation was aborted */ static void -transmit_ping_if_allowed(void *cls, - const struct GNUNET_PeerIdentity *pid, - const struct GNUNET_HELLO_Address *address_null, - struct GNUNET_ATS_Session *session_null, - int result) +transmit_ping_if_allowed (void *cls, + const struct GNUNET_PeerIdentity *pid, + const struct GNUNET_HELLO_Address *address_null, + struct GNUNET_ATS_Session *session_null, + int result) { struct ValidationEntry *ve = cls; struct TransportPingMessage ping; @@ -559,116 +571,119 @@ transmit_ping_if_allowed(void *cls, ve->bc = NULL; if (GNUNET_OK != result) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Blacklist denies sending PING to `%s' `%s' `%s'\n", - GNUNET_i2s(pid), - GST_plugins_a2s(ve->address), - ve->address->transport_name); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# address records discarded (blacklist)"), - 1, - GNUNET_NO); - cleanup_validation_entry(NULL, - pid, - ve); - return; - } - hello = GST_hello_get(); - GNUNET_assert(NULL != hello); - slen = strlen(ve->address->transport_name) + 1; - hsize = ntohs(hello->size); - tsize = sizeof(struct TransportPingMessage) + - ve->address->address_length + slen + hsize; + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Blacklist denies sending PING to `%s' `%s' `%s'\n", + GNUNET_i2s (pid), + GST_plugins_a2s (ve->address), + ve->address->transport_name); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# address records discarded (blacklist)"), + 1, + GNUNET_NO); + cleanup_validation_entry (NULL, + pid, + ve); + return; + } + hello = GST_hello_get (); + GNUNET_assert (NULL != hello); + slen = strlen (ve->address->transport_name) + 1; + hsize = ntohs (hello->size); + tsize = sizeof(struct TransportPingMessage) + + ve->address->address_length + slen + hsize; ping.header.size = - htons(sizeof(struct TransportPingMessage) + - ve->address->address_length + slen); - ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); - ping.challenge = htonl(ve->challenge); + htons (sizeof(struct TransportPingMessage) + + ve->address->address_length + slen); + ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING); + ping.challenge = htonl (ve->challenge); ping.target = *pid; if (tsize >= GNUNET_MAX_MESSAGE_SIZE) - { - GNUNET_break(0); - hsize = 0; - tsize = - sizeof(struct TransportPingMessage) + ve->address->address_length + - slen + hsize; - } + { + GNUNET_break (0); + hsize = 0; + tsize = + sizeof(struct TransportPingMessage) + ve->address->address_length + + slen + hsize; + } { char message_buf[tsize] GNUNET_ALIGN; - GNUNET_memcpy(message_buf, - hello, - hsize); - GNUNET_memcpy(&message_buf[hsize], - &ping, - sizeof(struct TransportPingMessage)); - GNUNET_memcpy(&message_buf[sizeof(struct TransportPingMessage) + hsize], - ve->address->transport_name, - slen); - GNUNET_memcpy(&message_buf[sizeof(struct TransportPingMessage) + slen + hsize], - ve->address->address, - ve->address->address_length); - papi = GST_plugins_find(ve->address->transport_name); - GNUNET_assert(NULL != papi); - session = papi->get_session(papi->cls, - ve->address); + GNUNET_memcpy (message_buf, + hello, + hsize); + GNUNET_memcpy (&message_buf[hsize], + &ping, + sizeof(struct TransportPingMessage)); + GNUNET_memcpy (&message_buf[sizeof(struct TransportPingMessage) + hsize], + ve->address->transport_name, + slen); + GNUNET_memcpy (&message_buf[sizeof(struct TransportPingMessage) + slen + + hsize], + ve->address->address, + ve->address->address_length); + papi = GST_plugins_find (ve->address->transport_name); + GNUNET_assert (NULL != papi); + session = papi->get_session (papi->cls, + ve->address); if (NULL == session) - { - /* Could not get a valid session */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Failed to get session to send PING to `%s' at `%s'\n", - GNUNET_i2s(pid), - GST_plugins_a2s(ve->address)); - return; - } - - ret = papi->send(papi->cls, session, - message_buf, tsize, - PING_PRIORITY, - ACCEPTABLE_PING_DELAY, - NULL, NULL); + { + /* Could not get a valid session */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Failed to get session to send PING to `%s' at `%s'\n", + GNUNET_i2s (pid), + GST_plugins_a2s (ve->address)); + return; + } + + ret = papi->send (papi->cls, session, + message_buf, tsize, + PING_PRIORITY, + ACCEPTABLE_PING_DELAY, + NULL, NULL); if (-1 == ret) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Failed to send PING to `%s' at `%s'\n", - GNUNET_i2s(pid), - GST_plugins_a2s(ve->address)); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Transmitted plain PING to `%s' `%s' `%s'\n", - GNUNET_i2s(pid), - GST_plugins_a2s(ve->address), - ve->address->transport_name); - ve->network = papi->get_network(papi->cls, - session); - GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network); - GST_neighbours_notify_data_sent(ve->address, - session, - tsize); - next = GNUNET_TIME_relative_to_absolute(validation_delay); - validation_next = GNUNET_TIME_absolute_max(next, - validation_next); - ve->send_time = GNUNET_TIME_absolute_get(); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# PINGs for address validation sent"), - 1, - GNUNET_NO); + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to send PING to `%s' at `%s'\n", + GNUNET_i2s (pid), + GST_plugins_a2s (ve->address)); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitted plain PING to `%s' `%s' `%s'\n", + GNUNET_i2s (pid), + GST_plugins_a2s (ve->address), + ve->address->transport_name); + ve->network = papi->get_network (papi->cls, + session); + GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network); + GST_neighbours_notify_data_sent (ve->address, + session, + tsize); + next = GNUNET_TIME_relative_to_absolute (validation_delay); + validation_next = GNUNET_TIME_absolute_max (next, + validation_next); + ve->send_time = GNUNET_TIME_absolute_get (); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# PINGs for address validation sent"), + 1, + GNUNET_NO); ve->expecting_pong = GNUNET_YES; validations_running++; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Validation started, %u validation processes running\n", - validations_running); - GNUNET_STATISTICS_set(GST_stats, - gettext_noop("# validations running"), - validations_running, - GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Validation started, %u validation processes running\n", + validations_running); + GNUNET_STATISTICS_set (GST_stats, + gettext_noop ("# validations running"), + validations_running, + GNUNET_NO); /* Notify about PING sent */ - validation_entry_changed(ve, - GNUNET_TRANSPORT_VS_UPDATE); + validation_entry_changed (ve, + GNUNET_TRANSPORT_VS_UPDATE); } } @@ -679,7 +694,7 @@ transmit_ping_if_allowed(void *cls, * @param cls the `struct ValidationEntry` */ static void -revalidate_address(void *cls) +revalidate_address (void *cls) { struct ValidationEntry *ve = cls; struct GNUNET_TIME_Relative canonical_delay; @@ -689,12 +704,13 @@ revalidate_address(void *cls) uint32_t rdelay; ve->revalidation_task = NULL; - delay = GNUNET_TIME_absolute_get_remaining(ve->revalidation_block); + delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block); /* Considering current connectivity situation, what is the maximum block period permitted? */ if (GNUNET_YES == ve->in_use) canonical_delay = CONNECTED_PING_FREQUENCY; - else if (GNUNET_TIME_absolute_get_remaining(ve->valid_until).rel_value_us > 0) + else if (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us > + 0) canonical_delay = VALIDATED_PING_FREQUENCY; else canonical_delay = UNVALIDATED_PING_KEEPALIVE; @@ -702,94 +718,96 @@ revalidate_address(void *cls) new maximum delay (which may be lower); the real delay is originally randomized between "canonical_delay" and "2 * canonical_delay", so continue to permit that window for the operation. */ - delay = GNUNET_TIME_relative_min(delay, - GNUNET_TIME_relative_multiply(canonical_delay, - 2)); - ve->revalidation_block = GNUNET_TIME_relative_to_absolute(delay); + delay = GNUNET_TIME_relative_min (delay, + GNUNET_TIME_relative_multiply ( + canonical_delay, + 2)); + ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay); if (delay.rel_value_us > 0) - { - /* should wait a bit longer */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Waiting for %s longer before (re)validating address `%s'\n", - GNUNET_STRINGS_relative_time_to_string(delay, + { + /* should wait a bit longer */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Waiting for %s longer before (re)validating address `%s'\n", + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), - GST_plugins_a2s(ve->address)); - ve->revalidation_task = - GNUNET_SCHEDULER_add_delayed(delay, - &revalidate_address, ve); - ve->next_validation = GNUNET_TIME_relative_to_absolute(delay); - return; - } + GST_plugins_a2s (ve->address)); + ve->revalidation_task = + GNUNET_SCHEDULER_add_delayed (delay, + &revalidate_address, ve); + ve->next_validation = GNUNET_TIME_relative_to_absolute (delay); + return; + } /* check if globally we have too many active validations at a too high rate, if so, delay ours */ - blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next); + blocked_for = GNUNET_TIME_absolute_get_remaining (validation_next); if ((validations_running > validations_fast_start_threshold) && (blocked_for.rel_value_us > 0)) - { - /* Validations are blocked, have to wait for blocked_for time */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Validations blocked for another %s, delaying validating address `%s'\n", - GNUNET_STRINGS_relative_time_to_string(blocked_for, + { + /* Validations are blocked, have to wait for blocked_for time */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Validations blocked for another %s, delaying validating address `%s'\n", + GNUNET_STRINGS_relative_time_to_string (blocked_for, GNUNET_YES), - GST_plugins_a2s(ve->address)); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# validations delayed by global throttle"), - 1, - GNUNET_NO); - ve->revalidation_task = - GNUNET_SCHEDULER_add_delayed(blocked_for, - &revalidate_address, - ve); - ve->next_validation = GNUNET_TIME_relative_to_absolute(blocked_for); - return; - } + GST_plugins_a2s (ve->address)); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ( + "# validations delayed by global throttle"), + 1, + GNUNET_NO); + ve->revalidation_task = + GNUNET_SCHEDULER_add_delayed (blocked_for, + &revalidate_address, + ve); + ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for); + return; + } /* We are good to go; remember to not go again for `canonical_delay` time; add up to `canonical_delay` to randomize start time */ - ve->revalidation_block = GNUNET_TIME_relative_to_absolute(canonical_delay); + ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay); /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */ rdelay = - GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, - canonical_delay.rel_value_us); - - delay = GNUNET_TIME_relative_add(canonical_delay, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MICROSECONDS, - rdelay)); - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Validating now, next scheduled for %s, now validating address `%s'\n", - GNUNET_STRINGS_relative_time_to_string(blocked_for, - GNUNET_YES), - GST_plugins_a2s(ve->address)); + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + canonical_delay.rel_value_us); + + delay = GNUNET_TIME_relative_add (canonical_delay, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_MICROSECONDS, + rdelay)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Validating now, next scheduled for %s, now validating address `%s'\n", + GNUNET_STRINGS_relative_time_to_string (blocked_for, + GNUNET_YES), + GST_plugins_a2s (ve->address)); ve->revalidation_task = - GNUNET_SCHEDULER_add_delayed(delay, - &revalidate_address, - ve); - ve->next_validation = GNUNET_TIME_relative_to_absolute(delay); + GNUNET_SCHEDULER_add_delayed (delay, + &revalidate_address, + ve); + ve->next_validation = GNUNET_TIME_relative_to_absolute (delay); /* start PINGing by checking blacklist */ - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# address revalidations started"), 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# address revalidations started"), 1, + GNUNET_NO); if (NULL != ve->bc) - { - GST_blacklist_test_cancel(ve->bc); - ve->bc = NULL; - } - bc = GST_blacklist_test_allowed(&ve->address->peer, - ve->address->transport_name, - &transmit_ping_if_allowed, - ve, - NULL, - NULL); + { + GST_blacklist_test_cancel (ve->bc); + ve->bc = NULL; + } + bc = GST_blacklist_test_allowed (&ve->address->peer, + ve->address->transport_name, + &transmit_ping_if_allowed, + ve, + NULL, + NULL); if (NULL != bc) - { - /* If transmit_ping_if_allowed was already called it may have freed ve, - * so only set ve->bc if it has not been called. - */ - ve->bc = bc; - } + { + /* If transmit_ping_if_allowed was already called it may have freed ve, + * so only set ve->bc if it has not been called. + */ + ve->bc = bc; + } } @@ -803,41 +821,41 @@ revalidate_address(void *cls) * if we don't have an existing entry and no public key was given */ static struct ValidationEntry * -find_validation_entry(const struct GNUNET_HELLO_Address *address) +find_validation_entry (const struct GNUNET_HELLO_Address *address) { struct ValidationEntryMatchContext vemc; struct ValidationEntry *ve; vemc.ve = NULL; vemc.address = address; - GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, - &address->peer, - &validation_entry_match, &vemc); + GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, + &address->peer, + &validation_entry_match, &vemc); if (NULL != (ve = vemc.ve)) return ve; - GNUNET_assert(GNUNET_NO == - GST_ats_is_known_no_session(address)); - ve = GNUNET_new(struct ValidationEntry); + GNUNET_assert (GNUNET_NO == + GST_ats_is_known_no_session (address)); + ve = GNUNET_new (struct ValidationEntry); ve->in_use = GNUNET_SYSERR; /* not defined */ - ve->address = GNUNET_HELLO_address_copy(address); + ve->address = GNUNET_HELLO_address_copy (address); ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS; - memset(&ve->pong_sig_cache, - '\0', - sizeof(struct GNUNET_CRYPTO_EddsaSignature)); + memset (&ve->pong_sig_cache, + '\0', + sizeof(struct GNUNET_CRYPTO_EddsaSignature)); ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; ve->challenge = - GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); ve->timeout_task = - GNUNET_SCHEDULER_add_delayed(UNVALIDATED_PING_KEEPALIVE, - &timeout_hello_validation, - ve); - GNUNET_CONTAINER_multipeermap_put(validation_map, - &address->peer, - ve, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - publish_ve_stat_update(); - validation_entry_changed(ve, - GNUNET_TRANSPORT_VS_NEW); + GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE, + &timeout_hello_validation, + ve); + GNUNET_CONTAINER_multipeermap_put (validation_map, + &address->peer, + ve, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + publish_ve_stat_update (); + validation_entry_changed (ve, + GNUNET_TRANSPORT_VS_NEW); return ve; } @@ -854,9 +872,9 @@ find_validation_entry(const struct GNUNET_HELLO_Address *address) * #GNUNET_SYSERR would abort iteration (but we always iterate all) */ static int -add_valid_address(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute expiration) +add_valid_address (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { const struct GNUNET_HELLO_Message *hello = cls; struct ValidationEntry *ve; @@ -864,60 +882,60 @@ add_valid_address(void *cls, struct GNUNET_ATS_Properties prop; struct GNUNET_TRANSPORT_PluginFunctions *papi; - if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) + if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) return GNUNET_OK; /* expired */ - if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid)) - { - GNUNET_break(0); - return GNUNET_OK; /* invalid HELLO !? */ - } - if (NULL == (papi = GST_plugins_find(address->transport_name))) - { - /* might have been valid in the past, but we don't have that - plugin loaded right now */ - return GNUNET_OK; - } + if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) + { + GNUNET_break (0); + return GNUNET_OK; /* invalid HELLO !? */ + } + if (NULL == (papi = GST_plugins_find (address->transport_name))) + { + /* might have been valid in the past, but we don't have that + plugin loaded right now */ + return GNUNET_OK; + } if (NULL == - papi->address_to_string(papi->cls, - address->address, - address->address_length)) - { - /* Why do we try to add an ill-formed address? */ - GNUNET_break(0); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Address with %u bytes for plugin %s and peer %s is malformed\n", - (unsigned int)address->address_length, - address->transport_name, - GNUNET_i2s(&pid)); - return GNUNET_OK; - } + papi->address_to_string (papi->cls, + address->address, + address->address_length)) + { + /* Why do we try to add an ill-formed address? */ + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Address with %u bytes for plugin %s and peer %s is malformed\n", + (unsigned int) address->address_length, + address->transport_name, + GNUNET_i2s (&pid)); + return GNUNET_OK; + } - ve = find_validation_entry(address); - ve->network = papi->get_network_for_address(papi->cls, - address); - GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network); - ve->valid_until = GNUNET_TIME_absolute_max(ve->valid_until, - expiration); + ve = find_validation_entry (address); + ve->network = papi->get_network_for_address (papi->cls, + address); + GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network); + ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, + expiration); if (NULL == ve->revalidation_task) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Starting revalidations for valid address `%s'\n", - GST_plugins_a2s(ve->address)); - ve->next_validation = GNUNET_TIME_absolute_get(); - ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, ve); - } - validation_entry_changed(ve, - GNUNET_TRANSPORT_VS_UPDATE); - memset(&prop, 0, sizeof(prop)); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting revalidations for valid address `%s'\n", + GST_plugins_a2s (ve->address)); + ve->next_validation = GNUNET_TIME_absolute_get (); + ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); + } + validation_entry_changed (ve, + GNUNET_TRANSPORT_VS_UPDATE); + memset (&prop, 0, sizeof(prop)); prop.scope = ve->network; - prop.delay = GNUNET_TIME_relative_divide(ve->latency, 2); + prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); if (GNUNET_YES != ve->known_to_ats) - { - ve->known_to_ats = GNUNET_YES; - GST_ats_add_address(address, &prop); - GNUNET_assert(GNUNET_YES == - GST_ats_is_known_no_session(ve->address)); - } + { + ve->known_to_ats = GNUNET_YES; + GST_ats_add_address (address, &prop); + GNUNET_assert (GNUNET_YES == + GST_ats_is_known_no_session (ve->address)); + } return GNUNET_OK; } @@ -932,28 +950,28 @@ add_valid_address(void *cls, * @param err_msg error message */ static void -process_peerinfo_hello(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello, - const char *err_msg) +process_peerinfo_hello (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { - GNUNET_assert(NULL != peer); + GNUNET_assert (NULL != peer); if (NULL == hello) return; - if (0 == memcmp(&GST_my_identity, - peer, - sizeof(struct GNUNET_PeerIdentity))) - { - /* Peerinfo returned own identity, skip validation */ - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Handling HELLO for peer `%s'\n", - GNUNET_i2s(peer)); - GNUNET_assert(NULL == - GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, - &add_valid_address, - (void *)hello)); + if (0 == memcmp (&GST_my_identity, + peer, + sizeof(struct GNUNET_PeerIdentity))) + { + /* Peerinfo returned own identity, skip validation */ + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Handling HELLO for peer `%s'\n", + GNUNET_i2s (peer)); + GNUNET_assert (NULL == + GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, + &add_valid_address, + (void *) hello)); } @@ -963,7 +981,7 @@ process_peerinfo_hello(void *cls, * @param max_fds maximum number of fds to use */ void -GST_validation_start(unsigned int max_fds) +GST_validation_start (unsigned int max_fds) { /** * Initialization for validation throttling @@ -977,23 +995,24 @@ GST_validation_start(unsigned int max_fds) * (300 sec / ~150 == ~2 sec.) between two validations */ - validation_next = GNUNET_TIME_absolute_get(); - validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); + validation_next = GNUNET_TIME_absolute_get (); + validation_delay.rel_value_us = + (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); validations_fast_start_threshold = (max_fds / 2); validations_running = 0; - GNUNET_STATISTICS_set(GST_stats, - gettext_noop("# validations running"), - validations_running, - GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Validation uses a fast start threshold of %u connections and a delay of %s\n", - validations_fast_start_threshold, - GNUNET_STRINGS_relative_time_to_string(validation_delay, - GNUNET_YES)); - validation_map = GNUNET_CONTAINER_multipeermap_create(VALIDATION_MAP_SIZE, - GNUNET_NO); - pnc = GNUNET_PEERINFO_notify(GST_cfg, GNUNET_YES, - &process_peerinfo_hello, NULL); + GNUNET_STATISTICS_set (GST_stats, + gettext_noop ("# validations running"), + validations_running, + GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Validation uses a fast start threshold of %u connections and a delay of %s\n", + validations_fast_start_threshold, + GNUNET_STRINGS_relative_time_to_string (validation_delay, + GNUNET_YES)); + validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE, + GNUNET_NO); + pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES, + &process_peerinfo_hello, NULL); } @@ -1001,14 +1020,14 @@ GST_validation_start(unsigned int max_fds) * Stop the validation subsystem. */ void -GST_validation_stop() +GST_validation_stop () { - GNUNET_CONTAINER_multipeermap_iterate(validation_map, - &cleanup_validation_entry, - NULL); - GNUNET_CONTAINER_multipeermap_destroy(validation_map); + GNUNET_CONTAINER_multipeermap_iterate (validation_map, + &cleanup_validation_entry, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (validation_map); validation_map = NULL; - GNUNET_PEERINFO_notify_cancel(pnc); + GNUNET_PEERINFO_notify_cancel (pnc); } @@ -1024,41 +1043,41 @@ GST_validation_stop() * @param address target address */ static void -multicast_pong(void *cls, - struct GNUNET_TIME_Absolute valid_until, - struct GNUNET_TIME_Absolute validation_block, - const struct GNUNET_HELLO_Address *address) +multicast_pong (void *cls, + struct GNUNET_TIME_Absolute valid_until, + struct GNUNET_TIME_Absolute validation_block, + const struct GNUNET_HELLO_Address *address) { struct TransportPongMessage *pong = cls; struct GNUNET_TRANSPORT_PluginFunctions *papi; struct GNUNET_ATS_Session *session; - papi = GST_plugins_find(address->transport_name); + papi = GST_plugins_find (address->transport_name); if (NULL == papi) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Plugin %s not supported, cannot send PONG\n", - address->transport_name); - return; - } - GNUNET_assert(NULL != papi->send); - GNUNET_assert(NULL != papi->get_session); - session = papi->get_session(papi->cls, address); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Plugin %s not supported, cannot send PONG\n", + address->transport_name); + return; + } + GNUNET_assert (NULL != papi->send); + GNUNET_assert (NULL != papi->get_session); + session = papi->get_session (papi->cls, address); if (NULL == session) - { - GNUNET_break(0); - return; - } - GST_ats_new_session(address, session); - papi->send(papi->cls, session, - (const char *)pong, - ntohs(pong->header.size), - PONG_PRIORITY, - ACCEPTABLE_PING_DELAY, - NULL, NULL); - GST_neighbours_notify_data_sent(address, - session, - pong->header.size); + { + GNUNET_break (0); + return; + } + GST_ats_new_session (address, session); + papi->send (papi->cls, session, + (const char *) pong, + ntohs (pong->header.size), + PONG_PRIORITY, + ACCEPTABLE_PING_DELAY, + NULL, NULL); + GST_neighbours_notify_data_sent (address, + session, + pong->header.size); } @@ -1072,10 +1091,10 @@ multicast_pong(void *cls, * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *hdr, - const struct GNUNET_HELLO_Address *sender_address, - struct GNUNET_ATS_Session *session) +GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *hdr, + const struct GNUNET_HELLO_Address *sender_address, + struct GNUNET_ATS_Session *session) { const struct TransportPingMessage *ping; struct TransportPongMessage *pong; @@ -1092,32 +1111,33 @@ GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender, struct GNUNET_HELLO_Address address; if (0 == - memcmp(&GST_my_identity, - sender, - sizeof(struct GNUNET_PeerIdentity))) + memcmp (&GST_my_identity, + sender, + sizeof(struct GNUNET_PeerIdentity))) return GNUNET_OK; /* our own, ignore! */ - if (ntohs(hdr->size) < sizeof(struct TransportPingMessage)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - ping = (const struct TransportPingMessage *)hdr; + if (ntohs (hdr->size) < sizeof(struct TransportPingMessage)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + ping = (const struct TransportPingMessage *) hdr; if (0 != - memcmp(&ping->target, - &GST_my_identity, - sizeof(struct GNUNET_PeerIdentity))) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# PING message for different peer received"), 1, - GNUNET_NO); - return GNUNET_SYSERR; - } - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# PING messages received"), 1, - GNUNET_NO); - addr = (const char *)&ping[1]; - len_address = ntohs(hdr->size) - sizeof(struct TransportPingMessage); + memcmp (&ping->target, + &GST_my_identity, + sizeof(struct GNUNET_PeerIdentity))) + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# PING message for different peer received"), + 1, + GNUNET_NO); + return GNUNET_SYSERR; + } + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# PING messages received"), 1, + GNUNET_NO); + addr = (const char *) &ping[1]; + len_address = ntohs (hdr->size) - sizeof(struct TransportPingMessage); /* peer wants to confirm that this is one of our addresses, this is what is * used for address validation */ @@ -1125,198 +1145,207 @@ GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender, sig_cache_exp = NULL; papi = NULL; if (len_address > 0) + { + addrend = memchr (addr, '\0', len_address); + if (NULL == addrend) { - addrend = memchr(addr, '\0', len_address); - if (NULL == addrend) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - addrend++; - len_plugin = strlen(addr) + 1; - len_address -= len_plugin; - address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; - address.address = addrend; - address.address_length = len_address; - address.transport_name = addr; - address.peer = GST_my_identity; - - if (NULL == address.transport_name) - { - GNUNET_break(0); - } - - if (0 != strstr(address.transport_name, "_client")) - { - plugin_name = GNUNET_strdup(address.transport_name); - pos = strstr(plugin_name, "_client"); - GNUNET_assert(NULL != pos); - GNUNET_snprintf(pos, strlen("_server") + 1, "%s", "_server"); - } - else - plugin_name = GNUNET_strdup(address.transport_name); - - if (NULL == (papi = GST_plugins_find(plugin_name))) - { - /* we don't have the plugin for this address */ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Plugin `%s' not available, cannot confirm having this address\n"), - plugin_name); - GNUNET_free(plugin_name); - return GNUNET_SYSERR; - } - GNUNET_free(plugin_name); - if (GNUNET_OK != - papi->check_address(papi->cls, - addrend, - len_address)) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# failed address checks during validation"), 1, - GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Address `%s' is not one of my addresses, not confirming PING\n"), - GST_plugins_a2s(&address)); - return GNUNET_SYSERR; - } - else - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# successful address checks during validation"), 1, - GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Address `%s' is one of my addresses, confirming PING\n", - GST_plugins_a2s(&address)); - } - - if (GNUNET_YES != - GST_hello_test_address(&address, - &sig_cache, - &sig_cache_exp)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"), - GNUNET_i2s(sender), - GST_plugins_a2s(&address)); - return GNUNET_SYSERR; - } + GNUNET_break_op (0); + return GNUNET_SYSERR; } - else + addrend++; + len_plugin = strlen (addr) + 1; + len_address -= len_plugin; + address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; + address.address = addrend; + address.address_length = len_address; + address.transport_name = addr; + address.peer = GST_my_identity; + + if (NULL == address.transport_name) { - addrend = NULL; /* make gcc happy */ - len_plugin = 0; - static struct GNUNET_CRYPTO_EddsaSignature no_address_signature; - static struct GNUNET_TIME_Absolute no_address_signature_expiration; + GNUNET_break (0); + } - sig_cache = &no_address_signature; - sig_cache_exp = &no_address_signature_expiration; + if (0 != strstr (address.transport_name, "_client")) + { + plugin_name = GNUNET_strdup (address.transport_name); + pos = strstr (plugin_name, "_client"); + GNUNET_assert (NULL != pos); + GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server"); } + else + plugin_name = GNUNET_strdup (address.transport_name); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "I am `%s', sending PONG to peer `%s'\n", - GNUNET_i2s_full(&GST_my_identity), - GNUNET_i2s(sender)); + if (NULL == (papi = GST_plugins_find (plugin_name))) + { + /* we don't have the plugin for this address */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ( + "Plugin `%s' not available, cannot confirm having this address\n"), + plugin_name); + GNUNET_free (plugin_name); + return GNUNET_SYSERR; + } + GNUNET_free (plugin_name); + if (GNUNET_OK != + papi->check_address (papi->cls, + addrend, + len_address)) + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# failed address checks during validation"), + 1, + GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ( + "Address `%s' is not one of my addresses, not confirming PING\n"), + GST_plugins_a2s (&address)); + return GNUNET_SYSERR; + } + else + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ( + "# successful address checks during validation"), + 1, + GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Address `%s' is one of my addresses, confirming PING\n", + GST_plugins_a2s (&address)); + } + + if (GNUNET_YES != + GST_hello_test_address (&address, + &sig_cache, + &sig_cache_exp)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ( + "Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"), + GNUNET_i2s (sender), + GST_plugins_a2s (&address)); + return GNUNET_SYSERR; + } + } + else + { + addrend = NULL; /* make gcc happy */ + len_plugin = 0; + static struct GNUNET_CRYPTO_EddsaSignature no_address_signature; + static struct GNUNET_TIME_Absolute no_address_signature_expiration; + + sig_cache = &no_address_signature; + sig_cache_exp = &no_address_signature_expiration; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "I am `%s', sending PONG to peer `%s'\n", + GNUNET_i2s_full (&GST_my_identity), + GNUNET_i2s (sender)); /* message with structure: * [TransportPongMessage][Transport name][Address] */ - pong = GNUNET_malloc(sizeof(struct TransportPongMessage) + len_address + len_plugin); + pong = GNUNET_malloc (sizeof(struct TransportPongMessage) + len_address + + len_plugin); pong->header.size = - htons(sizeof(struct TransportPongMessage) + len_address + len_plugin); - pong->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); + htons (sizeof(struct TransportPongMessage) + len_address + len_plugin); + pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); pong->purpose.size = - htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + - sizeof(uint32_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO) + - len_address + len_plugin); - pong->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); - GNUNET_memcpy(&pong->challenge, &ping->challenge, sizeof(ping->challenge)); - pong->addrlen = htonl(len_address + len_plugin); - GNUNET_memcpy(&pong[1], addr, len_plugin); /* Copy transport plugin */ + htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + + sizeof(uint32_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO) + + len_address + len_plugin); + pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); + GNUNET_memcpy (&pong->challenge, &ping->challenge, sizeof(ping->challenge)); + pong->addrlen = htonl (len_address + len_plugin); + GNUNET_memcpy (&pong[1], addr, len_plugin); /* Copy transport plugin */ if (len_address > 0) - { - GNUNET_assert(NULL != addrend); - GNUNET_memcpy(&((char *)&pong[1])[len_plugin], addrend, len_address); - } - if (GNUNET_TIME_absolute_get_remaining(*sig_cache_exp).rel_value_us < + { + GNUNET_assert (NULL != addrend); + GNUNET_memcpy (&((char *) &pong[1])[len_plugin], addrend, len_address); + } + if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value_us < PONG_SIGNATURE_LIFETIME.rel_value_us / 4) + { + /* create / update cached sig */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Creating PONG signature to indicate ownership.\n"); + *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME); + pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, &pong->purpose, + sig_cache)) { - /* create / update cached sig */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Creating PONG signature to indicate ownership.\n"); - *sig_cache_exp = GNUNET_TIME_relative_to_absolute(PONG_SIGNATURE_LIFETIME); - pong->expiration = GNUNET_TIME_absolute_hton(*sig_cache_exp); - if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, &pong->purpose, - sig_cache)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Failed to create PONG signature for peer `%s'\n"), GNUNET_i2s(sender)); - } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to create PONG signature for peer `%s'\n"), + GNUNET_i2s (sender)); } + } else - { - pong->expiration = GNUNET_TIME_absolute_hton(*sig_cache_exp); - } + { + pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); + } pong->signature = *sig_cache; - GNUNET_assert(NULL != sender_address); + GNUNET_assert (NULL != sender_address); /* first see if the session we got this PING from can be used to transmit * a response reliably */ if (NULL == papi) + { + ret = -1; + } + else + { + GNUNET_assert (NULL != papi->send); + GNUNET_assert (NULL != papi->get_session); + if (NULL == session) { - ret = -1; + session = papi->get_session (papi->cls, sender_address); } - else + if (NULL == session) { - GNUNET_assert(NULL != papi->send); - GNUNET_assert(NULL != papi->get_session); - if (NULL == session) - { - session = papi->get_session(papi->cls, sender_address); - } - if (NULL == session) - { - GNUNET_break(0); - ret = -1; - } - else - { - ret = papi->send(papi->cls, session, - (const char *)pong, - ntohs(pong->header.size), - PONG_PRIORITY, ACCEPTABLE_PING_DELAY, - NULL, NULL); - if (-1 != ret) - GST_neighbours_notify_data_sent(sender_address, - session, - pong->header.size); - } + GNUNET_break (0); + ret = -1; } - if (-1 != ret) + else { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Transmitted PONG to `%s' via reliable mechanism\n", - GNUNET_i2s(sender)); - /* done! */ - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# PONGs unicast via reliable transport"), 1, - GNUNET_NO); - GNUNET_free(pong); - return GNUNET_OK; + ret = papi->send (papi->cls, session, + (const char *) pong, + ntohs (pong->header.size), + PONG_PRIORITY, ACCEPTABLE_PING_DELAY, + NULL, NULL); + if (-1 != ret) + GST_neighbours_notify_data_sent (sender_address, + session, + pong->header.size); } + } + if (-1 != ret) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitted PONG to `%s' via reliable mechanism\n", + GNUNET_i2s (sender)); + /* done! */ + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# PONGs unicast via reliable transport"), 1, + GNUNET_NO); + GNUNET_free (pong); + return GNUNET_OK; + } /* no reliable method found, try transmission via all known addresses */ - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# PONGs multicast to all available addresses"), 1, - GNUNET_NO); - GST_validation_get_addresses(sender, - &multicast_pong, pong); - GNUNET_free(pong); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# PONGs multicast to all available addresses"), + 1, + GNUNET_NO); + GST_validation_get_addresses (sender, + &multicast_pong, pong); + GNUNET_free (pong); return GNUNET_OK; } @@ -1327,36 +1356,36 @@ GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender, * @param address address we should try to validate */ void -GST_validation_handle_address(const struct GNUNET_HELLO_Address *address) +GST_validation_handle_address (const struct GNUNET_HELLO_Address *address) { struct GNUNET_TRANSPORT_PluginFunctions *papi; struct ValidationEntry *ve; - papi = GST_plugins_find(address->transport_name); + papi = GST_plugins_find (address->transport_name); if (NULL == papi) - { - /* This plugin is currently unvailable ... ignore */ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "No plugin available for %s\n", - address->transport_name); - return; - } - ve = find_validation_entry(address); + { + /* This plugin is currently unvailable ... ignore */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "No plugin available for %s\n", + address->transport_name); + return; + } + ve = find_validation_entry (address); if (NULL == ve->revalidation_task) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Validation process started for fresh address `%s' of %s\n", - GST_plugins_a2s(ve->address), - GNUNET_i2s(&ve->address->peer)); - ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, ve); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Validation process started for fresh address `%s' of %s\n", + GST_plugins_a2s (ve->address), + GNUNET_i2s (&ve->address->peer)); + ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Validation already running for address `%s' of %s\n", - GST_plugins_a2s(ve->address), - GNUNET_i2s(&ve->address->peer)); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Validation already running for address `%s' of %s\n", + GST_plugins_a2s (ve->address), + GNUNET_i2s (&ve->address->peer)); + } } @@ -1370,17 +1399,17 @@ GST_validation_handle_address(const struct GNUNET_HELLO_Address *address) * @return #GNUNET_OK (keep the address) */ static int -validate_address_iterator(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_TIME_Absolute expiration) +validate_address_iterator (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { - if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Skipping expired address from HELLO\n"); - return GNUNET_OK; /* expired */ - } - GST_validation_handle_address(address); + if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Skipping expired address from HELLO\n"); + return GNUNET_OK; /* expired */ + } + GST_validation_handle_address (address); return GNUNET_OK; } @@ -1395,19 +1424,19 @@ validate_address_iterator(void *cls, * end of the iteration. */ static ssize_t -add_valid_peer_address(void *cls, - size_t max, - void *buf) +add_valid_peer_address (void *cls, + size_t max, + void *buf) { struct ValidationEntry *ve = cls; if (GNUNET_YES == ve->copied) return GNUNET_SYSERR; /* Done */ ve->copied = GNUNET_YES; - return GNUNET_HELLO_add_address(ve->address, - ve->valid_until, - buf, - max); + return GNUNET_HELLO_add_address (ve->address, + ve->valid_until, + buf, + max); } @@ -1420,8 +1449,8 @@ add_valid_peer_address(void *cls, * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *hdr) +GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *hdr) { const struct TransportPongMessage *pong; struct ValidationEntry *ve; @@ -1436,197 +1465,200 @@ GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender, int do_verify; if (0 == - memcmp(&GST_my_identity, - sender, - sizeof(struct GNUNET_PeerIdentity))) + memcmp (&GST_my_identity, + sender, + sizeof(struct GNUNET_PeerIdentity))) return GNUNET_OK; /* our own, ignore! */ - if (ntohs(hdr->size) < sizeof(struct TransportPongMessage)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# PONG messages received"), 1, - GNUNET_NO); + if (ntohs (hdr->size) < sizeof(struct TransportPongMessage)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# PONG messages received"), 1, + GNUNET_NO); /* message with structure: * [TransportPongMessage][Transport name][Address] */ - pong = (const struct TransportPongMessage *)hdr; - tname = (const char *)&pong[1]; - size = ntohs(hdr->size) - sizeof(struct TransportPongMessage); - addr = memchr(tname, '\0', size); + pong = (const struct TransportPongMessage *) hdr; + tname = (const char *) &pong[1]; + size = ntohs (hdr->size) - sizeof(struct TransportPongMessage); + addr = memchr (tname, '\0', size); if (NULL == addr) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } addr++; - slen = strlen(tname) + 1; + slen = strlen (tname) + 1; addrlen = size - slen; - if (NULL == GST_plugins_find(tname)) - { - /* we got the PONG, but the transport plugin specified in it - is not supported by this peer, so this cannot be a good - PONG for us. */ - GNUNET_break_op(0); - return GNUNET_OK; - } + if (NULL == GST_plugins_find (tname)) + { + /* we got the PONG, but the transport plugin specified in it + is not supported by this peer, so this cannot be a good + PONG for us. */ + GNUNET_break_op (0); + return GNUNET_OK; + } address.peer = *sender; address.address = addr; address.address_length = addrlen; address.transport_name = tname; address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; - ve = find_validation_entry(&address); + ve = find_validation_entry (&address); if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong)) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# PONGs dropped, no matching pending validation"), - 1, GNUNET_NO); - return GNUNET_OK; - } + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ( + "# PONGs dropped, no matching pending validation"), + 1, GNUNET_NO); + return GNUNET_OK; + } /* now check that PONG is well-formed */ - if (0 != memcmp(&ve->address->peer, - sender, - sizeof(struct GNUNET_PeerIdentity))) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + if (0 != memcmp (&ve->address->peer, + sender, + sizeof(struct GNUNET_PeerIdentity))) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } if (0 == GNUNET_TIME_absolute_get_remaining - (GNUNET_TIME_absolute_ntoh(pong->expiration)).rel_value_us) - { - GNUNET_STATISTICS_update(GST_stats, - gettext_noop - ("# PONGs dropped, signature expired"), 1, - GNUNET_NO); - return GNUNET_SYSERR; - } + (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us) + { + GNUNET_STATISTICS_update (GST_stats, + gettext_noop + ("# PONGs dropped, signature expired"), 1, + GNUNET_NO); + return GNUNET_SYSERR; + } sig_res = GNUNET_SYSERR; do_verify = GNUNET_YES; - if (0 != GNUNET_TIME_absolute_get_remaining(ve->pong_sig_valid_until).rel_value_us) + if (0 != GNUNET_TIME_absolute_get_remaining ( + ve->pong_sig_valid_until).rel_value_us) + { + /* We have a cached and valid signature for this peer, + * try to compare instead of verify */ + if (0 == memcmp (&ve->pong_sig_cache, + &pong->signature, + sizeof(struct GNUNET_CRYPTO_EddsaSignature))) + { + /* signatures are identical, we can skip verification */ + sig_res = GNUNET_OK; + do_verify = GNUNET_NO; + } + else { - /* We have a cached and valid signature for this peer, - * try to compare instead of verify */ - if (0 == memcmp(&ve->pong_sig_cache, - &pong->signature, - sizeof(struct GNUNET_CRYPTO_EddsaSignature))) - { - /* signatures are identical, we can skip verification */ - sig_res = GNUNET_OK; - do_verify = GNUNET_NO; - } - else - { - sig_res = GNUNET_SYSERR; - /* signatures do not match, we have to verify */ - } + sig_res = GNUNET_SYSERR; + /* signatures do not match, we have to verify */ } + } if (GNUNET_YES == do_verify) + { + /* Do expensive verification */ + sig_res = GNUNET_CRYPTO_eddsa_verify ( + GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, + &pong->purpose, + &pong->signature, + &ve->address->peer.public_key); + if (sig_res == GNUNET_SYSERR) { - /* Do expensive verification */ - sig_res = GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, - &pong->purpose, - &pong->signature, - &ve->address->peer.public_key); - if (sig_res == GNUNET_SYSERR) - { - GNUNET_break_op(0); - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n", - tname, - GST_plugins_a2s(ve->address), - GNUNET_i2s(sender)); - } + GNUNET_break_op (0); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n", + tname, + GST_plugins_a2s (ve->address), + GNUNET_i2s (sender)); } + } if (sig_res == GNUNET_SYSERR) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Validation process successful for peer `%s' with plugin `%s' address `%s'\n", - GNUNET_i2s(sender), - tname, - GST_plugins_a2s(ve->address)); - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# validations succeeded"), - 1, - GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Validation process successful for peer `%s' with plugin `%s' address `%s'\n", + GNUNET_i2s (sender), + tname, + GST_plugins_a2s (ve->address)); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# validations succeeded"), + 1, + GNUNET_NO); /* validity achieved, remember it! */ ve->expecting_pong = GNUNET_NO; - ve->valid_until = GNUNET_TIME_relative_to_absolute(HELLO_ADDRESS_EXPIRATION); + ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); ve->pong_sig_cache = pong->signature; - ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh(pong->expiration); - ve->latency = GNUNET_TIME_absolute_get_duration(ve->send_time); + ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh (pong->expiration); + ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time); { if (GNUNET_YES == ve->known_to_ats) - { - GNUNET_assert(GNUNET_YES == - GST_ats_is_known_no_session(ve->address)); - GST_ats_update_delay(ve->address, - GNUNET_TIME_relative_divide(ve->latency, 2)); - } - else - { - struct GNUNET_ATS_Properties prop; - - memset(&prop, 0, sizeof(prop)); - GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network); - prop.scope = ve->network; - prop.delay = GNUNET_TIME_relative_divide(ve->latency, 2); - GNUNET_assert(GNUNET_NO == - GST_ats_is_known_no_session(ve->address)); - ve->known_to_ats = GNUNET_YES; - GST_ats_add_address(ve->address, &prop); - GNUNET_assert(GNUNET_YES == - GST_ats_is_known_no_session(ve->address)); - } - } - if (validations_running > 0) { - validations_running--; - GNUNET_STATISTICS_set(GST_stats, - gettext_noop("# validations running"), - validations_running, - GNUNET_NO); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Validation finished, %u validation processes running\n", - validations_running); + GNUNET_assert (GNUNET_YES == + GST_ats_is_known_no_session (ve->address)); + GST_ats_update_delay (ve->address, + GNUNET_TIME_relative_divide (ve->latency, 2)); } - else + else { - GNUNET_break(0); + struct GNUNET_ATS_Properties prop; + + memset (&prop, 0, sizeof(prop)); + GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network); + prop.scope = ve->network; + prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); + GNUNET_assert (GNUNET_NO == + GST_ats_is_known_no_session (ve->address)); + ve->known_to_ats = GNUNET_YES; + GST_ats_add_address (ve->address, &prop); + GNUNET_assert (GNUNET_YES == + GST_ats_is_known_no_session (ve->address)); } + } + if (validations_running > 0) + { + validations_running--; + GNUNET_STATISTICS_set (GST_stats, + gettext_noop ("# validations running"), + validations_running, + GNUNET_NO); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Validation finished, %u validation processes running\n", + validations_running); + } + else + { + GNUNET_break (0); + } /* Notify about new validity */ - validation_entry_changed(ve, - GNUNET_TRANSPORT_VS_UPDATE); + validation_entry_changed (ve, + GNUNET_TRANSPORT_VS_UPDATE); /* build HELLO to store in PEERINFO */ - GNUNET_STATISTICS_update(GST_stats, - gettext_noop("# HELLOs given to peerinfo"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (GST_stats, + gettext_noop ("# HELLOs given to peerinfo"), + 1, + GNUNET_NO); ve->copied = GNUNET_NO; - hello = GNUNET_HELLO_create(&ve->address->peer.public_key, - &add_valid_peer_address, - ve, - GNUNET_NO); - GNUNET_break(NULL != - GNUNET_PEERINFO_add_peer(GST_peerinfo, - hello, - NULL, - NULL)); - GNUNET_free(hello); + hello = GNUNET_HELLO_create (&ve->address->peer.public_key, + &add_valid_peer_address, + ve, + GNUNET_NO); + GNUNET_break (NULL != + GNUNET_PEERINFO_add_peer (GST_peerinfo, + hello, + NULL, + NULL)); + GNUNET_free (hello); return GNUNET_OK; } @@ -1639,42 +1671,42 @@ GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender, * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_validation_handle_hello(const struct GNUNET_MessageHeader *hello) +GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello) { const struct GNUNET_HELLO_Message *hm = - (const struct GNUNET_HELLO_Message *)hello; + (const struct GNUNET_HELLO_Message *) hello; struct GNUNET_PeerIdentity pid; int friend; - friend = GNUNET_HELLO_is_friend_only(hm); + friend = GNUNET_HELLO_is_friend_only (hm); if (((GNUNET_YES != friend) && (GNUNET_NO != friend)) || - (GNUNET_OK != GNUNET_HELLO_get_id(hm, &pid))) - { - /* malformed HELLO */ - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + (GNUNET_OK != GNUNET_HELLO_get_id (hm, &pid))) + { + /* malformed HELLO */ + GNUNET_break_op (0); + return GNUNET_SYSERR; + } if (0 == - memcmp(&GST_my_identity, - &pid, - sizeof(struct GNUNET_PeerIdentity))) - { - /* got our own HELLO, how boring */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Validation received our own HELLO (%s), ignoring\n", - GNUNET_i2s(&pid)); - return GNUNET_OK; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Validation received HELLO message for peer `%s' with size %u, checking for new addresses\n", - GNUNET_i2s(&pid), - ntohs(hello->size)); - GNUNET_assert(NULL == - GNUNET_HELLO_iterate_addresses(hm, - GNUNET_NO, - &validate_address_iterator, - NULL)); + memcmp (&GST_my_identity, + &pid, + sizeof(struct GNUNET_PeerIdentity))) + { + /* got our own HELLO, how boring */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Validation received our own HELLO (%s), ignoring\n", + GNUNET_i2s (&pid)); + return GNUNET_OK; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Validation received HELLO message for peer `%s' with size %u, checking for new addresses\n", + GNUNET_i2s (&pid), + ntohs (hello->size)); + GNUNET_assert (NULL == + GNUNET_HELLO_iterate_addresses (hm, + GNUNET_NO, + &validate_address_iterator, + NULL)); return GNUNET_OK; } @@ -1682,7 +1714,8 @@ GST_validation_handle_hello(const struct GNUNET_MessageHeader *hello) /** * Closure for #iterate_addresses(). */ -struct IteratorContext { +struct IteratorContext +{ /** * Function to call on each address. */ @@ -1704,17 +1737,17 @@ struct IteratorContext { * @return #GNUNET_OK (continue to iterate) */ static int -iterate_addresses(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +iterate_addresses (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct IteratorContext *ic = cls; struct ValidationEntry *ve = value; - ic->cb(ic->cb_cls, - ve->valid_until, - ve->revalidation_block, - ve->address); + ic->cb (ic->cb_cls, + ve->valid_until, + ve->revalidation_block, + ve->address); return GNUNET_OK; } @@ -1728,17 +1761,17 @@ iterate_addresses(void *cls, * @param cb_cls closure for @a cb */ void -GST_validation_get_addresses(const struct GNUNET_PeerIdentity *target, - GST_ValidationAddressCallback cb, - void *cb_cls) +GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, + GST_ValidationAddressCallback cb, + void *cb_cls) { struct IteratorContext ic; ic.cb = cb; ic.cb_cls = cb_cls; - GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, - target, - &iterate_addresses, &ic); + GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, + target, + &iterate_addresses, &ic); } @@ -1752,37 +1785,37 @@ GST_validation_get_addresses(const struct GNUNET_PeerIdentity *target, * #GNUNET_NO if we are no longer using the address for a connection */ void -GST_validation_set_address_use(const struct GNUNET_HELLO_Address *address, - int in_use) +GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address, + int in_use) { struct ValidationEntry *ve; - if (GNUNET_HELLO_address_check_option(address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)) + if (GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)) return; /* ignore inbound for validation */ - if (NULL == GST_plugins_find(address->transport_name)) - { - /* How can we use an address for which we don't have the plugin? */ - GNUNET_break(0); - return; - } - ve = find_validation_entry(address); + if (NULL == GST_plugins_find (address->transport_name)) + { + /* How can we use an address for which we don't have the plugin? */ + GNUNET_break (0); + return; + } + ve = find_validation_entry (address); if (NULL == ve) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } if (in_use == ve->in_use) return; ve->in_use = in_use; if (GNUNET_YES == in_use) - { - /* from now on, higher frequeny, so reschedule now */ - if (NULL != ve->revalidation_task) - GNUNET_SCHEDULER_cancel(ve->revalidation_task); - ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, - ve); - } + { + /* from now on, higher frequeny, so reschedule now */ + if (NULL != ve->revalidation_task) + GNUNET_SCHEDULER_cancel (ve->revalidation_task); + ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, + ve); + } } diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h index a5b9b7603..2a0428869 100644 --- a/src/transport/gnunet-service-transport_validation.h +++ b/src/transport/gnunet-service-transport_validation.h @@ -37,14 +37,14 @@ * @param max_fds maximum number of fds to use */ void -GST_validation_start(unsigned int max_fds); +GST_validation_start (unsigned int max_fds); /** * Stop the validation subsystem. */ void -GST_validation_stop(void); +GST_validation_stop (void); /** @@ -57,8 +57,8 @@ GST_validation_stop(void); * #GNUNET_NO if we are no longer using the address for a connection */ void -GST_validation_set_address_use(const struct GNUNET_HELLO_Address *address, - int in_use); +GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address, + int in_use); /** @@ -71,10 +71,10 @@ GST_validation_set_address_use(const struct GNUNET_HELLO_Address *address, * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *hdr, - const struct GNUNET_HELLO_Address *sender_address, - struct GNUNET_ATS_Session *session); +GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *hdr, + const struct GNUNET_HELLO_Address *sender_address, + struct GNUNET_ATS_Session *session); /** @@ -86,8 +86,8 @@ GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender, * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *hdr); +GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *hdr); /** @@ -98,7 +98,7 @@ GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender, * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error */ int -GST_validation_handle_hello(const struct GNUNET_MessageHeader *hello); +GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello); /** @@ -107,7 +107,7 @@ GST_validation_handle_hello(const struct GNUNET_MessageHeader *hello); * @param address address we should try to validate */ void -GST_validation_handle_address(const struct GNUNET_HELLO_Address *address); +GST_validation_handle_address (const struct GNUNET_HELLO_Address *address); /** @@ -138,8 +138,8 @@ typedef void * @param cb_cls closure for @a cb */ void -GST_validation_get_addresses(const struct GNUNET_PeerIdentity *target, - GST_ValidationAddressCallback cb, void *cb_cls); +GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, + GST_ValidationAddressCallback cb, void *cb_cls); #endif diff --git a/src/transport/gnunet-transport-profiler.c b/src/transport/gnunet-transport-profiler.c index 9451f95da..b09361d14 100644 --- a/src/transport/gnunet-transport-profiler.c +++ b/src/transport/gnunet-transport-profiler.c @@ -34,7 +34,8 @@ #include "gnunet_transport_service.h" -struct Iteration { +struct Iteration +{ struct Iteration *next; struct Iteration *prev; struct GNUNET_TIME_Absolute start; @@ -53,7 +54,7 @@ struct Iteration { * Timeout for a connections */ #define CONNECT_TIMEOUT \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) /** * Benchmarking block size in bye @@ -160,7 +161,7 @@ static unsigned int verbosity; * @param cls NULL */ static void -shutdown_task(void *cls) +shutdown_task (void *cls) { struct Iteration *icur; struct Iteration *inext; @@ -173,28 +174,28 @@ shutdown_task(void *cls) float stddev_duration; if (NULL != ats_sh) - { - GNUNET_ATS_connectivity_suggest_cancel(ats_sh); - ats_sh = NULL; - } + { + GNUNET_ATS_connectivity_suggest_cancel (ats_sh); + ats_sh = NULL; + } if (NULL != bl_handle) - { - GNUNET_TRANSPORT_blacklist_cancel(bl_handle); - bl_handle = NULL; - } + { + GNUNET_TRANSPORT_blacklist_cancel (bl_handle); + bl_handle = NULL; + } if (NULL != ats) - { - GNUNET_ATS_connectivity_done(ats); - ats = NULL; - } + { + GNUNET_ATS_connectivity_done (ats); + ats = NULL; + } if (NULL != handle) - { - GNUNET_TRANSPORT_core_disconnect(handle); - handle = NULL; - } + { + GNUNET_TRANSPORT_core_disconnect (handle); + handle = NULL; + } if (verbosity > 0) - fprintf(stdout, "\n"); + fprintf (stdout, "\n"); /* Output format: * All time values in ms @@ -202,95 +203,95 @@ shutdown_task(void *cls) * #messages;#messagesize;#avg_dur;#avg_rate;#duration_i0;#duration_i0;... */ if (benchmark_send) + { + /* First iteration to calculcate avg and stddev */ + iterations = 0; + avg_duration = 0; + avg_rate = 0.0; + + inext = ihead; + while (NULL != (icur = inext)) { - /* First iteration to calculcate avg and stddev */ - iterations = 0; - avg_duration = 0; - avg_rate = 0.0; - - inext = ihead; - while (NULL != (icur = inext)) - { - inext = icur->next; - icur->rate = ((benchmark_count * benchmark_size) / 1024) / - ((float)icur->dur.rel_value_us / (1000 * 1000)); - if (verbosity > 0) - fprintf(stdout, - _("%llu B in %llu ms == %.2f KB/s!\n"), - ((long long unsigned int)benchmark_count * benchmark_size), - ((long long unsigned int)icur->dur.rel_value_us / 1000), - (float)icur->rate); - - avg_duration += icur->dur.rel_value_us / (1000); - avg_rate += icur->rate; - iterations++; - } - if (0 == iterations) - iterations = 1; /* avoid division by zero */ - /* Calculate average rate */ - avg_rate /= iterations; - /* Calculate average duration */ - avg_duration /= iterations; - - stddev_rate = 0; - stddev_duration = 0; - inext = ihead; - while (NULL != (icur = inext)) - { - inext = icur->next; - stddev_rate += ((icur->rate - avg_rate) * (icur->rate - avg_rate)); - stddev_duration += (((icur->dur.rel_value_us / 1000) - avg_duration) * - ((icur->dur.rel_value_us / 1000) - avg_duration)); - } - /* Calculate standard deviation rate */ - stddev_rate = stddev_rate / iterations; - stddev_rate = sqrtf(stddev_rate); - - /* Calculate standard deviation duration */ - stddev_duration = stddev_duration / iterations; - stddev_duration = sqrtf(stddev_duration); - - /* Output */ - fprintf(stdout, - "%u;%u;%llu;%llu;%.2f;%.2f", - benchmark_count, - benchmark_size, - avg_duration, - (unsigned long long)stddev_duration, - avg_rate, - stddev_rate); - - inext = ihead; - while (NULL != (icur = inext)) - { - inext = icur->next; - GNUNET_CONTAINER_DLL_remove(ihead, itail, icur); - - fprintf(stdout, - ";%llu;%.2f", - (long long unsigned int)(icur->dur.rel_value_us / 1000), - icur->rate); - - GNUNET_free(icur); - } + inext = icur->next; + icur->rate = ((benchmark_count * benchmark_size) / 1024) + / ((float) icur->dur.rel_value_us / (1000 * 1000)); + if (verbosity > 0) + fprintf (stdout, + _ ("%llu B in %llu ms == %.2f KB/s!\n"), + ((long long unsigned int) benchmark_count * benchmark_size), + ((long long unsigned int) icur->dur.rel_value_us / 1000), + (float) icur->rate); + + avg_duration += icur->dur.rel_value_us / (1000); + avg_rate += icur->rate; + iterations++; } -#if 0 - if (benchmark_receive) + if (0 == iterations) + iterations = 1; /* avoid division by zero */ + /* Calculate average rate */ + avg_rate /= iterations; + /* Calculate average duration */ + avg_duration /= iterations; + + stddev_rate = 0; + stddev_duration = 0; + inext = ihead; + while (NULL != (icur = inext)) { - duration = GNUNET_TIME_absolute_get_duration(start_time); - fprintf(stdout, - "Received %llu bytes/s (%llu bytes in %s)\n", - 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), - traffic_received, - GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES)); + inext = icur->next; + stddev_rate += ((icur->rate - avg_rate) * (icur->rate - avg_rate)); + stddev_duration += (((icur->dur.rel_value_us / 1000) - avg_duration) + * ((icur->dur.rel_value_us / 1000) - avg_duration)); } + /* Calculate standard deviation rate */ + stddev_rate = stddev_rate / iterations; + stddev_rate = sqrtf (stddev_rate); + + /* Calculate standard deviation duration */ + stddev_duration = stddev_duration / iterations; + stddev_duration = sqrtf (stddev_duration); + + /* Output */ + fprintf (stdout, + "%u;%u;%llu;%llu;%.2f;%.2f", + benchmark_count, + benchmark_size, + avg_duration, + (unsigned long long) stddev_duration, + avg_rate, + stddev_rate); + + inext = ihead; + while (NULL != (icur = inext)) + { + inext = icur->next; + GNUNET_CONTAINER_DLL_remove (ihead, itail, icur); + + fprintf (stdout, + ";%llu;%.2f", + (long long unsigned int) (icur->dur.rel_value_us / 1000), + icur->rate); + + GNUNET_free (icur); + } + } +#if 0 + if (benchmark_receive) + { + duration = GNUNET_TIME_absolute_get_duration (start_time); + fprintf (stdout, + "Received %llu bytes/s (%llu bytes in %s)\n", + 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), + traffic_received, + GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); + } #endif - fprintf(stdout, "\n"); + fprintf (stdout, "\n"); } static void -iteration_done(); +iteration_done (); /** @@ -305,66 +306,66 @@ iteration_done(); * @return number of bytes written to @a buf */ static void -send_msg(void *cls) +send_msg (void *cls) { struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *m; if (NULL == mq) return; - env = GNUNET_MQ_msg_extra(m, benchmark_size, GNUNET_MESSAGE_TYPE_DUMMY); - memset(&m[1], 52, benchmark_size - sizeof(struct GNUNET_MessageHeader)); + env = GNUNET_MQ_msg_extra (m, benchmark_size, GNUNET_MESSAGE_TYPE_DUMMY); + memset (&m[1], 52, benchmark_size - sizeof(struct GNUNET_MessageHeader)); if (itail->msgs_sent < benchmark_count) - { - GNUNET_MQ_notify_sent(env, &send_msg, NULL); - } + { + GNUNET_MQ_notify_sent (env, &send_msg, NULL); + } else - { - iteration_done(); - } - GNUNET_MQ_send(mq, env); + { + iteration_done (); + } + GNUNET_MQ_send (mq, env); if ((verbosity > 0) && (0 == itail->msgs_sent % 10)) - fprintf(stdout, "."); + fprintf (stdout, "."); } static void -iteration_start() +iteration_start () { struct Iteration *icur; ret = 0; - if (!benchmark_send) + if (! benchmark_send) return; benchmark_running = GNUNET_YES; - icur = GNUNET_new(struct Iteration); - GNUNET_CONTAINER_DLL_insert_tail(ihead, itail, icur); - icur->start = GNUNET_TIME_absolute_get(); + icur = GNUNET_new (struct Iteration); + GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur); + icur->start = GNUNET_TIME_absolute_get (); if (verbosity > 0) - fprintf( + fprintf ( stdout, "\nStarting benchmark, starting to send %u messages in %u byte blocks\n", benchmark_count, benchmark_size); - send_msg(NULL); + send_msg (NULL); } static void -iteration_done() +iteration_done () { static int it_count = 0; it_count++; - itail->dur = GNUNET_TIME_absolute_get_duration(itail->start); + itail->dur = GNUNET_TIME_absolute_get_duration (itail->start); if (it_count == benchmark_iterations) - { - benchmark_running = GNUNET_NO; - GNUNET_SCHEDULER_shutdown(); - return; - } - iteration_start(); + { + benchmark_running = GNUNET_NO; + GNUNET_SCHEDULER_shutdown (); + return; + } + iteration_start (); } @@ -378,20 +379,20 @@ iteration_done() * @return NULL */ static void * -notify_connect(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *m) +notify_connect (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *m) { - if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) - { - fprintf(stdout, "Connected to different peer `%s'\n", GNUNET_i2s(&pid)); - return NULL; - } + if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity))) + { + fprintf (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid)); + return NULL; + } if (verbosity > 0) - fprintf(stdout, "Successfully connected to `%s'\n", GNUNET_i2s(&pid)); + fprintf (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid)); mq = m; - iteration_start(); + iteration_start (); return NULL; } @@ -405,20 +406,20 @@ notify_connect(void *cls, * @param internal_cls NULL */ static void -notify_disconnect(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *internal_cls) +notify_disconnect (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *internal_cls) { - if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) + if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity))) return; mq = NULL; if (GNUNET_YES == benchmark_running) - { - fprintf(stdout, - "Disconnected from peer `%s' while benchmarking\n", - GNUNET_i2s(&pid)); - return; - } + { + fprintf (stdout, + "Disconnected from peer `%s' while benchmarking\n", + GNUNET_i2s (&pid)); + return; + } } @@ -430,7 +431,7 @@ notify_disconnect(void *cls, * @return #GNUNET_OK */ static int -check_dummy(void *cls, const struct GNUNET_MessageHeader *message) +check_dummy (void *cls, const struct GNUNET_MessageHeader *message) { return GNUNET_OK; /* all messages are fine */ } @@ -443,26 +444,26 @@ check_dummy(void *cls, const struct GNUNET_MessageHeader *message) * @param message the message */ static void -handle_dummy(void *cls, const struct GNUNET_MessageHeader *message) +handle_dummy (void *cls, const struct GNUNET_MessageHeader *message) { - if (!benchmark_receive) + if (! benchmark_receive) return; if (verbosity > 0) - fprintf(stdout, - "Received %u bytes\n", - (unsigned int)ntohs(message->size)); + fprintf (stdout, + "Received %u bytes\n", + (unsigned int) ntohs (message->size)); } static int -blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *peer) +blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *peer) { - if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) - { - if (verbosity > 0) - fprintf(stdout, "Denying connection to `%s'\n", GNUNET_i2s(peer)); - return GNUNET_SYSERR; - } + if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity))) + { + if (verbosity > 0) + fprintf (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer)); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -476,92 +477,92 @@ blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *peer) * @param mycfg configuration */ static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *mycfg) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *mycfg) { struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_var_size(dummy, - GNUNET_MESSAGE_TYPE_DUMMY, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_handler_end() }; + { GNUNET_MQ_hd_var_size (dummy, + GNUNET_MESSAGE_TYPE_DUMMY, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_handler_end () }; - cfg = (struct GNUNET_CONFIGURATION_Handle *)mycfg; + cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; ret = 1; if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size) - { - fprintf(stderr, "Message size too big!\n"); - return; - } + { + fprintf (stderr, "Message size too big!\n"); + return; + } if (NULL == cpid) - { - fprintf(stderr, "No peer identity given\n"); - return; - } - if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string(cpid, - strlen(cpid), - &pid.public_key)) - { - fprintf(stderr, "Failed to parse peer identity `%s'\n", cpid); - return; - } + { + fprintf (stderr, "No peer identity given\n"); + return; + } + if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, + strlen (cpid), + &pid.public_key)) + { + fprintf (stderr, "Failed to parse peer identity `%s'\n", cpid); + return; + } if (1 == benchmark_send) - { - if (verbosity > 0) - fprintf(stderr, - "Trying to send %u messages with size %u to peer `%s'\n", - benchmark_count, - benchmark_size, - GNUNET_i2s(&pid)); - } + { + if (verbosity > 0) + fprintf (stderr, + "Trying to send %u messages with size %u to peer `%s'\n", + benchmark_count, + benchmark_size, + GNUNET_i2s (&pid)); + } else if (1 == benchmark_receive) - { - fprintf(stderr, - "Trying to receive messages from peer `%s'\n", - GNUNET_i2s(&pid)); - } + { + fprintf (stderr, + "Trying to receive messages from peer `%s'\n", + GNUNET_i2s (&pid)); + } else - { - fprintf(stderr, "No operation given\n"); - return; - } + { + fprintf (stderr, "No operation given\n"); + return; + } - ats = GNUNET_ATS_connectivity_init(cfg); + ats = GNUNET_ATS_connectivity_init (cfg); if (NULL == ats) - { - fprintf(stderr, "Failed to connect to ATS service\n"); - ret = 1; - return; - } - - handle = GNUNET_TRANSPORT_core_connect(cfg, - NULL, - handlers, - NULL, - ¬ify_connect, - ¬ify_disconnect, - NULL); + { + fprintf (stderr, "Failed to connect to ATS service\n"); + ret = 1; + return; + } + + handle = GNUNET_TRANSPORT_core_connect (cfg, + NULL, + handlers, + NULL, + ¬ify_connect, + ¬ify_disconnect, + NULL); if (NULL == handle) - { - fprintf(stderr, "Failed to connect to transport service\n"); - GNUNET_ATS_connectivity_done(ats); - ats = NULL; - ret = 1; - return; - } + { + fprintf (stderr, "Failed to connect to transport service\n"); + GNUNET_ATS_connectivity_done (ats); + ats = NULL; + ret = 1; + return; + } - bl_handle = GNUNET_TRANSPORT_blacklist(cfg, &blacklist_cb, NULL); - ats_sh = GNUNET_ATS_connectivity_suggest(ats, &pid, 1); - GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); + bl_handle = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL); + ats_sh = GNUNET_ATS_connectivity_suggest (ats, &pid, 1); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } int -main(int argc, char *const *argv) +main (int argc, char *const *argv) { int res; @@ -571,50 +572,50 @@ main(int argc, char *const *argv) benchmark_running = GNUNET_NO; struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_flag('s', - "send", - gettext_noop("send data to peer"), - &benchmark_send), - GNUNET_GETOPT_option_flag('r', - "receive", - gettext_noop("receive data from peer"), - &benchmark_receive), - GNUNET_GETOPT_option_uint('i', - "iterations", - NULL, - gettext_noop("iterations"), - &benchmark_iterations), - GNUNET_GETOPT_option_uint('n', - "number", - NULL, - gettext_noop("number of messages to send"), - &benchmark_count), - GNUNET_GETOPT_option_uint('m', - "messagesize", - NULL, - gettext_noop("message size to use"), - &benchmark_size), - GNUNET_GETOPT_option_string('p', - "peer", - "PEER", - gettext_noop("peer identity"), - &cpid), - GNUNET_GETOPT_option_verbose(&verbosity), + GNUNET_GETOPT_option_flag ('s', + "send", + gettext_noop ("send data to peer"), + &benchmark_send), + GNUNET_GETOPT_option_flag ('r', + "receive", + gettext_noop ("receive data from peer"), + &benchmark_receive), + GNUNET_GETOPT_option_uint ('i', + "iterations", + NULL, + gettext_noop ("iterations"), + &benchmark_iterations), + GNUNET_GETOPT_option_uint ('n', + "number", + NULL, + gettext_noop ("number of messages to send"), + &benchmark_count), + GNUNET_GETOPT_option_uint ('m', + "messagesize", + NULL, + gettext_noop ("message size to use"), + &benchmark_size), + GNUNET_GETOPT_option_string ('p', + "peer", + "PEER", + gettext_noop ("peer identity"), + &cpid), + GNUNET_GETOPT_option_verbose (&verbosity), GNUNET_GETOPT_OPTION_END }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; res = - GNUNET_PROGRAM_run(argc, - argv, - "gnunet-transport", - gettext_noop("Direct access to transport service."), - options, - &run, - NULL); - GNUNET_free((void *)argv); + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-transport", + gettext_noop ("Direct access to transport service."), + options, + &run, + NULL); + GNUNET_free ((void *) argv); if (GNUNET_OK == res) return ret; return 1; diff --git a/src/transport/gnunet-transport-wlan-receiver.c b/src/transport/gnunet-transport-wlan-receiver.c index c6adeec0a..7f34a957f 100644 --- a/src/transport/gnunet-transport-wlan-receiver.c +++ b/src/transport/gnunet-transport-wlan-receiver.c @@ -28,7 +28,7 @@ #include "plugin_transport_wlan.h" int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { char msg_buf[65536]; unsigned long long count; @@ -40,75 +40,75 @@ main(int argc, char *argv[]) int commpipe[2]; /* This holds the fd for the input & output of the pipe */ if (2 != argc) - { - fprintf(stderr, - "This program must be started with the interface name as argument.\n"); - fprintf(stderr, - "Usage: %s interface-name\n" - "e.g. %s mon0\n", - argv[0], - argv[0]); - return 1; - } + { + fprintf (stderr, + "This program must be started with the interface name as argument.\n"); + fprintf (stderr, + "Usage: %s interface-name\n" + "e.g. %s mon0\n", + argv[0], + argv[0]); + return 1; + } /* Setup communication pipeline first */ - if (pipe(commpipe)) - { - fprintf(stderr, "Failed to create pipe: %s\n", strerror(errno)); - exit(1); - } + if (pipe (commpipe)) + { + fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno)); + exit (1); + } /* Attempt to fork and check for errors */ - if ((pid = fork()) == -1) - { - fprintf(stderr, "Failed to fork: %s\n", strerror(errno)); - exit(1); - } + if ((pid = fork ()) == -1) + { + fprintf (stderr, "Failed to fork: %s\n", strerror (errno)); + exit (1); + } if (pid) + { + /* A positive (non-negative) PID indicates the parent process */ + if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */ + fprintf (stderr, "Failed to close fd: %s\n", strerror (errno)); + start = time (NULL); + count = 0; + while (1) { - /* A positive (non-negative) PID indicates the parent process */ - if (0 != close(commpipe[1])) /* Close unused side of pipe (in side) */ - fprintf(stderr, "Failed to close fd: %s\n", strerror(errno)); - start = time(NULL); - count = 0; - while (1) - { - ret = read(commpipe[0], msg_buf, sizeof(msg_buf)); - if (0 > ret) - { - fprintf(stderr, "read failed: %s\n", strerror(errno)); - break; - } - count += ret; - akt = time(NULL); - if (akt - start > 30) - { - bytes_per_s = count / (akt - start); - bytes_per_s /= 1024; - printf("recv %f kb/s\n", bytes_per_s); - start = akt; - count = 0; - } - } + ret = read (commpipe[0], msg_buf, sizeof(msg_buf)); + if (0 > ret) + { + fprintf (stderr, "read failed: %s\n", strerror (errno)); + break; + } + count += ret; + akt = time (NULL); + if (akt - start > 30) + { + bytes_per_s = count / (akt - start); + bytes_per_s /= 1024; + printf ("recv %f kb/s\n", bytes_per_s); + start = akt; + count = 0; + } } + } else + { + /* A zero PID indicates that this is the child process */ + (void) close (1); + if (-1 == + dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */ + fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); + (void) close (commpipe[0]); /* Close unused side of pipe (in side) */ + /* Replace the child fork with a new process */ + if (execlp ("gnunet-helper-transport-wlan", + "gnunet-helper-transport-wlan", + argv[1], + NULL) == -1) { - /* A zero PID indicates that this is the child process */ - (void)close(1); - if (-1 == - dup2(commpipe[1], 1)) /* Replace stdin with the in side of the pipe */ - fprintf(stderr, "dup2 failed: %s\n", strerror(errno)); - (void)close(commpipe[0]); /* Close unused side of pipe (in side) */ - /* Replace the child fork with a new process */ - if (execlp("gnunet-helper-transport-wlan", - "gnunet-helper-transport-wlan", - argv[1], - NULL) == -1) - { - fprintf(stderr, "Could not start gnunet-helper-transport-wlan!"); - _exit(1); - } + fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); + _exit (1); } + } return 0; } diff --git a/src/transport/gnunet-transport-wlan-sender.c b/src/transport/gnunet-transport-wlan-sender.c index be8bcdda0..191ea8619 100644 --- a/src/transport/gnunet-transport-wlan-sender.c +++ b/src/transport/gnunet-transport-wlan-sender.c @@ -54,11 +54,11 @@ * @return GNUNET_YES at success */ static int -getRadiotapHeader(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, - uint16_t size) +getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, + uint16_t size) { - header->header.size = htons(size); - header->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); + header->header.size = htons (size); + header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); header->rate = 255; header->tx_power = 0; header->antenna = 0; @@ -74,18 +74,18 @@ getRadiotapHeader(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, * @return GNUNET_YES if there was no error */ static int -getWlanHeader(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header, - const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, - const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, - unsigned int size) +getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header, + const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, + const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, + unsigned int size) { const int rate = 11000000; - Header->frame_control = htons(IEEE80211_FC0_TYPE_DATA); + Header->frame_control = htons (IEEE80211_FC0_TYPE_DATA); Header->addr3 = mac_bssid_gnunet; Header->addr2 = *mac; Header->addr1 = *to_mac_addr; - Header->duration = GNUNET_htole16((size * 1000000) / rate + 290); + Header->duration = GNUNET_htole16 ((size * 1000000) / rate + 290); Header->llc[0] = WLAN_LLC_DSAP_FIELD; Header->llc[1] = WLAN_LLC_SSAP_FIELD; Header->llc[2] = 0; // FIXME @@ -95,7 +95,7 @@ getWlanHeader(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header, int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { char msg_buf[WLAN_MTU]; struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radiotap; @@ -114,137 +114,137 @@ main(int argc, char *argv[]) int macpipe[2]; /* This holds the fd for the input & output of the pipe */ if (4 != argc) - { - fprintf( - stderr, - "This program must be started with the interface and the targets and source mac as argument.\n"); - fprintf(stderr, - "Usage: interface-name mac-DST mac-SRC\n" - "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); - return 1; - } - if (6 != sscanf(argv[2], - "%x-%x-%x-%x-%x-%x", - &temp[0], - &temp[1], - &temp[2], - &temp[3], - &temp[4], - &temp[5])) - { - fprintf(stderr, - "Usage: interface-name mac-DST mac-SRC\n" - "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); - return 1; - } + { + fprintf ( + stderr, + "This program must be started with the interface and the targets and source mac as argument.\n"); + fprintf (stderr, + "Usage: interface-name mac-DST mac-SRC\n" + "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); + return 1; + } + if (6 != sscanf (argv[2], + "%x-%x-%x-%x-%x-%x", + &temp[0], + &temp[1], + &temp[2], + &temp[3], + &temp[4], + &temp[5])) + { + fprintf (stderr, + "Usage: interface-name mac-DST mac-SRC\n" + "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); + return 1; + } for (i = 0; i < 6; i++) outmac.mac[i] = temp[i]; - if (6 != sscanf(argv[3], - "%x-%x-%x-%x-%x-%x", - &temp[0], - &temp[1], - &temp[2], - &temp[3], - &temp[4], - &temp[5])) - { - fprintf(stderr, - "Usage: interface-name mac-DST mac-SRC\n" - "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); - return 1; - } + if (6 != sscanf (argv[3], + "%x-%x-%x-%x-%x-%x", + &temp[0], + &temp[1], + &temp[2], + &temp[3], + &temp[4], + &temp[5])) + { + fprintf (stderr, + "Usage: interface-name mac-DST mac-SRC\n" + "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); + return 1; + } for (i = 0; i < 6; i++) inmac.mac[i] = temp[i]; /* Setup communication pipeline first */ - if (pipe(commpipe)) - { - fprintf(stderr, "Failed to create pipe: %s\n", strerror(errno)); - exit(1); - } - if (pipe(macpipe)) - { - fprintf(stderr, "Failed to create pipe: %s\n", strerror(errno)); - exit(1); - } + if (pipe (commpipe)) + { + fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno)); + exit (1); + } + if (pipe (macpipe)) + { + fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno)); + exit (1); + } /* Attempt to fork and check for errors */ - if ((pid = fork()) == -1) - { - fprintf(stderr, "Failed to fork: %s\n", strerror(errno)); - exit(1); - } - memset(msg_buf, 0x42, sizeof(msg_buf)); + if ((pid = fork ()) == -1) + { + fprintf (stderr, "Failed to fork: %s\n", strerror (errno)); + exit (1); + } + memset (msg_buf, 0x42, sizeof(msg_buf)); if (pid) + { + /* A positive (non-negative) PID indicates the parent process */ + if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */ + fprintf (stderr, "Failed to close fd: %s\n", strerror (errno)); + setvbuf (stdout, + (char *) NULL, + _IONBF, + 0); /* Set non-buffered output on stdout */ + + if (0 != close (macpipe[1])) + fprintf (stderr, "Failed to close fd: %s\n", strerror (errno)); + if (sizeof(hcm) != read (macpipe[0], &hcm, sizeof(hcm))) + fprintf (stderr, "Failed to read hcm...\n"); + fprintf (stderr, + "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", + hcm.mac.mac[0], + hcm.mac.mac[1], + hcm.mac.mac[2], + hcm.mac.mac[3], + hcm.mac.mac[4], + hcm.mac.mac[5]); + radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf; + getRadiotapHeader (radiotap, WLAN_MTU); + getWlanHeader (&radiotap->frame, &outmac, &inmac, WLAN_MTU); + start = time (NULL); + count = 0; + while (1) { - /* A positive (non-negative) PID indicates the parent process */ - if (0 != close(commpipe[0])) /* Close unused side of pipe (in side) */ - fprintf(stderr, "Failed to close fd: %s\n", strerror(errno)); - setvbuf(stdout, - (char *)NULL, - _IONBF, - 0); /* Set non-buffered output on stdout */ - - if (0 != close(macpipe[1])) - fprintf(stderr, "Failed to close fd: %s\n", strerror(errno)); - if (sizeof(hcm) != read(macpipe[0], &hcm, sizeof(hcm))) - fprintf(stderr, "Failed to read hcm...\n"); - fprintf(stderr, - "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", - hcm.mac.mac[0], - hcm.mac.mac[1], - hcm.mac.mac[2], - hcm.mac.mac[3], - hcm.mac.mac[4], - hcm.mac.mac[5]); - radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)msg_buf; - getRadiotapHeader(radiotap, WLAN_MTU); - getWlanHeader(&radiotap->frame, &outmac, &inmac, WLAN_MTU); - start = time(NULL); - count = 0; - while (1) - { - ret = write(commpipe[1], msg_buf, WLAN_MTU); - if (0 > ret) - { - fprintf(stderr, "write failed: %s\n", strerror(errno)); - break; - } - count += ret; - akt = time(NULL); - if (akt - start > 30) - { - bytes_per_s = count / (akt - start); - bytes_per_s /= 1024; - printf("send %f kbytes/s\n", bytes_per_s); - start = akt; - count = 0; - } - } + ret = write (commpipe[1], msg_buf, WLAN_MTU); + if (0 > ret) + { + fprintf (stderr, "write failed: %s\n", strerror (errno)); + break; + } + count += ret; + akt = time (NULL); + if (akt - start > 30) + { + bytes_per_s = count / (akt - start); + bytes_per_s /= 1024; + printf ("send %f kbytes/s\n", bytes_per_s); + start = akt; + count = 0; + } } + } else + { + /* A zero PID indicates that this is the child process */ + (void) close (0); + (void) close (1); + if (-1 == + dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */ + fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); + if (-1 == + dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */ + fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); + (void) close (commpipe[1]); /* Close unused side of pipe (out side) */ + (void) close (macpipe[0]); /* Close unused side of pipe (in side) */ + /* Replace the child fork with a new process */ + if (execlp ("gnunet-helper-transport-wlan", + "gnunet-helper-transport-wlan", + argv[1], + NULL) == -1) { - /* A zero PID indicates that this is the child process */ - (void)close(0); - (void)close(1); - if (-1 == - dup2(commpipe[0], 0)) /* Replace stdin with the in side of the pipe */ - fprintf(stderr, "dup2 failed: %s\n", strerror(errno)); - if (-1 == - dup2(macpipe[1], 1)) /* Replace stdout with the out side of the pipe */ - fprintf(stderr, "dup2 failed: %s\n", strerror(errno)); - (void)close(commpipe[1]); /* Close unused side of pipe (out side) */ - (void)close(macpipe[0]); /* Close unused side of pipe (in side) */ - /* Replace the child fork with a new process */ - if (execlp("gnunet-helper-transport-wlan", - "gnunet-helper-transport-wlan", - argv[1], - NULL) == -1) - { - fprintf(stderr, "Could not start gnunet-helper-transport-wlan!"); - _exit(1); - } + fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); + _exit (1); } + } return 0; } diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 6cc342d06..f0d9d30c3 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -34,18 +34,19 @@ * Timeout for a name resolution */ #define RESOLUTION_TIMEOUT \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) /** * Timeout for an operation */ -#define OP_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) /** * Context to store name resolutions for valiation */ -struct ValidationResolutionContext { +struct ValidationResolutionContext +{ /** * Next in DLL */ @@ -95,7 +96,8 @@ struct ValidationResolutionContext { /** * Struct to store information about peers in monitor mode */ -struct MonitoredPeer { +struct MonitoredPeer +{ /** * State of the peer */ @@ -115,7 +117,8 @@ struct MonitoredPeer { /** * Context to store name resolutions for valiation */ -struct PeerResolutionContext { +struct PeerResolutionContext +{ /** * Next in DLL */ @@ -329,15 +332,15 @@ static struct PeerResolutionContext *rc_tail; * @return #GNUNET_OK (continue to iterate) */ static int -destroy_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) +destroy_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { struct MonitoredPeer *m = value; - GNUNET_assert( + GNUNET_assert ( GNUNET_OK == - GNUNET_CONTAINER_multipeermap_remove(monitored_peers, key, value)); - GNUNET_free_non_null(m->address); - GNUNET_free(value); + GNUNET_CONTAINER_multipeermap_remove (monitored_peers, key, value)); + GNUNET_free_non_null (m->address); + GNUNET_free (value); return GNUNET_OK; } @@ -349,7 +352,7 @@ destroy_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) * @param cls NULL */ static void -shutdown_task(void *cls) +shutdown_task (void *cls) { struct GNUNET_TIME_Relative duration; struct ValidationResolutionContext *cur; @@ -357,82 +360,82 @@ shutdown_task(void *cls) struct PeerResolutionContext *rc; if (NULL != op_timeout) - { - GNUNET_SCHEDULER_cancel(op_timeout); - op_timeout = NULL; - } + { + GNUNET_SCHEDULER_cancel (op_timeout); + op_timeout = NULL; + } if (NULL != pic) - { - GNUNET_TRANSPORT_monitor_peers_cancel(pic); - pic = NULL; - } + { + GNUNET_TRANSPORT_monitor_peers_cancel (pic); + pic = NULL; + } if (NULL != pm) - { - GNUNET_TRANSPORT_monitor_plugins_cancel(pm); - pm = NULL; - } + { + GNUNET_TRANSPORT_monitor_plugins_cancel (pm); + pm = NULL; + } next = vc_head; for (cur = next; NULL != cur; cur = next) - { - next = cur->next; - - GNUNET_TRANSPORT_address_to_string_cancel(cur->asc); - GNUNET_CONTAINER_DLL_remove(vc_head, vc_tail, cur); - GNUNET_free(cur->transport); - GNUNET_HELLO_address_free(cur->addrcp); - GNUNET_free(cur); - } + { + next = cur->next; + + GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); + GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, cur); + GNUNET_free (cur->transport); + GNUNET_HELLO_address_free (cur->addrcp); + GNUNET_free (cur); + } while (NULL != (rc = rc_head)) - { - GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc); - GNUNET_TRANSPORT_address_to_string_cancel(rc->asc); - GNUNET_free(rc->transport); - GNUNET_free(rc->addrcp); - GNUNET_free(rc); - } + { + GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); + GNUNET_TRANSPORT_address_to_string_cancel (rc->asc); + GNUNET_free (rc->transport); + GNUNET_free (rc->addrcp); + GNUNET_free (rc); + } if (NULL != handle) - { - GNUNET_TRANSPORT_core_disconnect(handle); - handle = NULL; - } + { + GNUNET_TRANSPORT_core_disconnect (handle); + handle = NULL; + } if (benchmark_send) - { - duration = GNUNET_TIME_absolute_get_duration(start_time); - fprintf(stdout, - _("Transmitted %llu bytes/s (%llu bytes in %s)\n"), - 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), - traffic_sent, - GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES)); - } + { + duration = GNUNET_TIME_absolute_get_duration (start_time); + fprintf (stdout, + _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"), + 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), + traffic_sent, + GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); + } if (benchmark_receive) - { - duration = GNUNET_TIME_absolute_get_duration(start_time); - fprintf(stdout, - _("Received %llu bytes/s (%llu bytes in %s)\n"), - 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), - traffic_received, - GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES)); - } + { + duration = GNUNET_TIME_absolute_get_duration (start_time); + fprintf (stdout, + _ ("Received %llu bytes/s (%llu bytes in %s)\n"), + 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), + traffic_received, + GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); + } if (NULL != monitored_peers) - { - GNUNET_CONTAINER_multipeermap_iterate(monitored_peers, &destroy_it, NULL); - GNUNET_CONTAINER_multipeermap_destroy(monitored_peers); - monitored_peers = NULL; - } + { + GNUNET_CONTAINER_multipeermap_iterate (monitored_peers, &destroy_it, NULL); + GNUNET_CONTAINER_multipeermap_destroy (monitored_peers); + monitored_peers = NULL; + } if (NULL != monitored_plugins) - { - GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(monitored_plugins)); - GNUNET_CONTAINER_multipeermap_destroy(monitored_plugins); - monitored_plugins = NULL; - } + { + GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (monitored_plugins)); + GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins); + monitored_plugins = NULL; + } if (NULL != blacklist) - { - GNUNET_TRANSPORT_blacklist_cancel(blacklist); - blacklist = NULL; - ret = 0; - } + { + GNUNET_TRANSPORT_blacklist_cancel (blacklist); + blacklist = NULL; + ret = 0; + } } @@ -440,42 +443,42 @@ shutdown_task(void *cls) * We are done, shut down. */ static void -operation_timeout(void *cls) +operation_timeout (void *cls) { struct PeerResolutionContext *cur; struct PeerResolutionContext *next; op_timeout = NULL; if ((benchmark_send) || (benchmark_receive)) - { - fprintf(stdout, _("Failed to connect to `%s'\n"), GNUNET_i2s_full(&pid)); - GNUNET_SCHEDULER_shutdown(); - ret = 1; - return; - } + { + fprintf (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid)); + GNUNET_SCHEDULER_shutdown (); + ret = 1; + return; + } if (iterate_connections) + { + next = rc_head; + while (NULL != (cur = next)) { - next = rc_head; - while (NULL != (cur = next)) - { - next = cur->next; - fprintf(stdout, - _("Failed to resolve address for peer `%s'\n"), - GNUNET_i2s(&cur->addrcp->peer)); - - GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, cur); - GNUNET_TRANSPORT_address_to_string_cancel(cur->asc); - GNUNET_free(cur->transport); - GNUNET_free(cur->addrcp); - GNUNET_free(cur); - } - fprintf(stdout, - "%s", - _("Failed to list connections, timeout occurred\n")); - GNUNET_SCHEDULER_shutdown(); - ret = 1; - return; + next = cur->next; + fprintf (stdout, + _ ("Failed to resolve address for peer `%s'\n"), + GNUNET_i2s (&cur->addrcp->peer)); + + GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, cur); + GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); + GNUNET_free (cur->transport); + GNUNET_free (cur->addrcp); + GNUNET_free (cur); } + fprintf (stdout, + "%s", + _ ("Failed to list connections, timeout occurred\n")); + GNUNET_SCHEDULER_shutdown (); + ret = 1; + return; + } } @@ -486,21 +489,21 @@ operation_timeout(void *cls) * @param cls closure with the message queue */ static void -do_send(void *cls) +do_send (void *cls) { struct GNUNET_MQ_Handle *mq = cls; struct GNUNET_MessageHeader *m; struct GNUNET_MQ_Envelope *env; - env = GNUNET_MQ_msg_extra(m, BLOCKSIZE * 1024, GNUNET_MESSAGE_TYPE_DUMMY); - memset(&m[1], 52, BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader)); + env = GNUNET_MQ_msg_extra (m, BLOCKSIZE * 1024, GNUNET_MESSAGE_TYPE_DUMMY); + memset (&m[1], 52, BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader)); traffic_sent += BLOCKSIZE * 1024; - GNUNET_MQ_notify_sent(env, &do_send, mq); + GNUNET_MQ_notify_sent (env, &do_send, mq); if (verbosity > 0) - fprintf(stdout, - _("Transmitting %u bytes\n"), - (unsigned int)BLOCKSIZE * 1024); - GNUNET_MQ_send(mq, env); + fprintf (stdout, + _ ("Transmitting %u bytes\n"), + (unsigned int) BLOCKSIZE * 1024); + GNUNET_MQ_send (mq, env); } @@ -513,29 +516,29 @@ do_send(void *cls) * @param mq message queue for sending to @a peer */ static void * -notify_connect(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +notify_connect (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { - if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) + if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity))) return NULL; ret = 0; - if (!benchmark_send) + if (! benchmark_send) return NULL; if (NULL != op_timeout) - { - GNUNET_SCHEDULER_cancel(op_timeout); - op_timeout = NULL; - } + { + GNUNET_SCHEDULER_cancel (op_timeout); + op_timeout = NULL; + } if (verbosity > 0) - fprintf( + fprintf ( stdout, - _( + _ ( "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), - GNUNET_i2s(peer), + GNUNET_i2s (peer), BLOCKSIZE); - start_time = GNUNET_TIME_absolute_get(); - do_send(mq); + start_time = GNUNET_TIME_absolute_get (); + do_send (mq); return mq; } @@ -549,19 +552,19 @@ notify_connect(void *cls, * @param internal_cls what we returned from #notify_connect() */ static void -notify_disconnect(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *internal_cls) +notify_disconnect (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *internal_cls) { - if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) + if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity))) return; if (NULL == internal_cls) return; /* not about target peer */ - if (!benchmark_send) + if (! benchmark_send) return; /* not transmitting */ - fprintf(stdout, - _("Disconnected from peer `%s' while benchmarking\n"), - GNUNET_i2s(&pid)); + fprintf (stdout, + _ ("Disconnected from peer `%s' while benchmarking\n"), + GNUNET_i2s (&pid)); } @@ -575,20 +578,20 @@ notify_disconnect(void *cls, * @return NULL */ static void * -monitor_notify_connect(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +monitor_notify_connect (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); - const char *now_str = GNUNET_STRINGS_absolute_time_to_string(now); + struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); monitor_connect_counter++; - fprintf(stdout, - _("%24s: %-17s %4s (%u connections in total)\n"), - now_str, - _("Connected to"), - GNUNET_i2s(peer), - monitor_connect_counter); + fprintf (stdout, + _ ("%24s: %-17s %4s (%u connections in total)\n"), + now_str, + _ ("Connected to"), + GNUNET_i2s (peer), + monitor_connect_counter); return NULL; } @@ -602,22 +605,22 @@ monitor_notify_connect(void *cls, * @param internal_cls what we returned from #monitor_notify_connect() */ static void -monitor_notify_disconnect(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *internal_cls) +monitor_notify_disconnect (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *internal_cls) { - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); - const char *now_str = GNUNET_STRINGS_absolute_time_to_string(now); + struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); - GNUNET_assert(monitor_connect_counter > 0); + GNUNET_assert (monitor_connect_counter > 0); monitor_connect_counter--; - fprintf(stdout, - _("%24s: %-17s %4s (%u connections in total)\n"), - now_str, - _("Disconnected from"), - GNUNET_i2s(peer), - monitor_connect_counter); + fprintf (stdout, + _ ("%24s: %-17s %4s (%u connections in total)\n"), + now_str, + _ ("Disconnected from"), + GNUNET_i2s (peer), + monitor_connect_counter); } @@ -629,7 +632,7 @@ monitor_notify_disconnect(void *cls, * @return #GNUNET_OK */ static int -check_dummy(void *cls, const struct GNUNET_MessageHeader *message) +check_dummy (void *cls, const struct GNUNET_MessageHeader *message) { return GNUNET_OK; /* all messages are fine */ } @@ -642,17 +645,17 @@ check_dummy(void *cls, const struct GNUNET_MessageHeader *message) * @param message the message */ static void -handle_dummy(void *cls, const struct GNUNET_MessageHeader *message) +handle_dummy (void *cls, const struct GNUNET_MessageHeader *message) { - if (!benchmark_receive) + if (! benchmark_receive) return; if (verbosity > 0) - fprintf(stdout, - _("Received %u bytes\n"), - (unsigned int)ntohs(message->size)); + fprintf (stdout, + _ ("Received %u bytes\n"), + (unsigned int) ntohs (message->size)); if (0 == traffic_received) - start_time = GNUNET_TIME_absolute_get(); - traffic_received += ntohs(message->size); + start_time = GNUNET_TIME_absolute_get (); + traffic_received += ntohs (message->size); } @@ -666,40 +669,40 @@ handle_dummy(void *cls, const struct GNUNET_MessageHeader *message) * @param state_timeout when will the peer's state expire */ static void -resolve_peer_address(const struct GNUNET_HELLO_Address *address, - int numeric, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout); +resolve_peer_address (const struct GNUNET_HELLO_Address *address, + int numeric, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout); static void -print_info(const struct GNUNET_PeerIdentity *id, - const char *transport, - const char *addr, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout) +print_info (const struct GNUNET_PeerIdentity *id, + const char *transport, + const char *addr, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout) { if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || (GNUNET_YES == monitor_connections)) - { - fprintf(stdout, - _("Peer `%s': %s %s in state `%s' until %s\n"), - GNUNET_i2s(id), - (NULL == transport) ? "" : transport, - (NULL == transport) ? "" : addr, - GNUNET_TRANSPORT_ps2s(state), - GNUNET_STRINGS_absolute_time_to_string(state_timeout)); - } + { + fprintf (stdout, + _ ("Peer `%s': %s %s in state `%s' until %s\n"), + GNUNET_i2s (id), + (NULL == transport) ? "" : transport, + (NULL == transport) ? "" : addr, + GNUNET_TRANSPORT_ps2s (state), + GNUNET_STRINGS_absolute_time_to_string (state_timeout)); + } else if ((GNUNET_YES == iterate_connections) && - (GNUNET_TRANSPORT_is_connected(state))) - { - /* Only connected peers, skip state */ - fprintf(stdout, - _("Peer `%s': %s %s\n"), - GNUNET_i2s(id), - transport, - addr); - } + (GNUNET_TRANSPORT_is_connected (state))) + { + /* Only connected peers, skip state */ + fprintf (stdout, + _ ("Peer `%s': %s %s\n"), + GNUNET_i2s (id), + transport, + addr); + } } @@ -720,82 +723,82 @@ print_info(const struct GNUNET_PeerIdentity *id, * if #GNUNET_SYSERR: communication error (IPC error) */ static void -process_peer_string(void *cls, const char *address, int res) +process_peer_string (void *cls, const char *address, int res) { struct PeerResolutionContext *rc = cls; if (NULL != address) + { + if (GNUNET_SYSERR == res) { - if (GNUNET_SYSERR == res) - { - fprintf( - stderr, - "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", - GNUNET_i2s(&rc->addrcp->peer), - rc->addrcp->transport_name, - (unsigned int)rc->addrcp->address_length); - print_info(&rc->addrcp->peer, - rc->transport, - NULL, - rc->state, - rc->state_timeout); - rc->printed = GNUNET_YES; - return; - } - if (GNUNET_OK == res) - { - print_info(&rc->addrcp->peer, - rc->transport, - address, - rc->state, - rc->state_timeout); - rc->printed = GNUNET_YES; - return; /* Wait for done call */ - } - /* GNUNET_NO == res: ignore, was simply not supported */ + fprintf ( + stderr, + "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", + GNUNET_i2s (&rc->addrcp->peer), + rc->addrcp->transport_name, + (unsigned int) rc->addrcp->address_length); + print_info (&rc->addrcp->peer, + rc->transport, + NULL, + rc->state, + rc->state_timeout); + rc->printed = GNUNET_YES; return; } + if (GNUNET_OK == res) + { + print_info (&rc->addrcp->peer, + rc->transport, + address, + rc->state, + rc->state_timeout); + rc->printed = GNUNET_YES; + return; /* Wait for done call */ + } + /* GNUNET_NO == res: ignore, was simply not supported */ + return; + } /* NULL == address, last call, we are done */ rc->asc = NULL; - GNUNET_assert(address_resolutions > 0); + GNUNET_assert (address_resolutions > 0); address_resolutions--; if (GNUNET_NO == rc->printed) + { + if (numeric == GNUNET_NO) { - if (numeric == GNUNET_NO) - { - /* Failed to resolve address, try numeric lookup - (note: this should not be needed, as transport - should fallback to numeric conversion if DNS takes - too long) */ - resolve_peer_address(rc->addrcp, - GNUNET_YES, - rc->state, - rc->state_timeout); - } - else - { - print_info(&rc->addrcp->peer, - rc->transport, - NULL, - rc->state, - rc->state_timeout); - } + /* Failed to resolve address, try numeric lookup + (note: this should not be needed, as transport + should fallback to numeric conversion if DNS takes + too long) */ + resolve_peer_address (rc->addrcp, + GNUNET_YES, + rc->state, + rc->state_timeout); } - GNUNET_free(rc->transport); - GNUNET_free(rc->addrcp); - GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc); - GNUNET_free(rc); + else + { + print_info (&rc->addrcp->peer, + rc->transport, + NULL, + rc->state, + rc->state_timeout); + } + } + GNUNET_free (rc->transport); + GNUNET_free (rc->addrcp); + GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); + GNUNET_free (rc); if ((0 == address_resolutions) && (iterate_connections)) + { + if (NULL != op_timeout) { - if (NULL != op_timeout) - { - GNUNET_SCHEDULER_cancel(op_timeout); - op_timeout = NULL; - } - ret = 0; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_cancel (op_timeout); + op_timeout = NULL; } + ret = 0; + GNUNET_SCHEDULER_shutdown (); + } } @@ -810,28 +813,28 @@ process_peer_string(void *cls, const char *address, int res) * @param state_timeout when will the peer's state expire */ static void -resolve_peer_address(const struct GNUNET_HELLO_Address *address, - int numeric, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout) +resolve_peer_address (const struct GNUNET_HELLO_Address *address, + int numeric, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout) { struct PeerResolutionContext *rc; - rc = GNUNET_new(struct PeerResolutionContext); - GNUNET_CONTAINER_DLL_insert(rc_head, rc_tail, rc); + rc = GNUNET_new (struct PeerResolutionContext); + GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc); address_resolutions++; - rc->transport = GNUNET_strdup(address->transport_name); - rc->addrcp = GNUNET_HELLO_address_copy(address); + rc->transport = GNUNET_strdup (address->transport_name); + rc->addrcp = GNUNET_HELLO_address_copy (address); rc->printed = GNUNET_NO; rc->state = state; rc->state_timeout = state_timeout; /* Resolve address to string */ - rc->asc = GNUNET_TRANSPORT_address_to_string(cfg, - address, - numeric, - RESOLUTION_TIMEOUT, - &process_peer_string, - rc); + rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, + address, + numeric, + RESOLUTION_TIMEOUT, + &process_peer_string, + rc); } @@ -846,44 +849,45 @@ resolve_peer_address(const struct GNUNET_HELLO_Address *address, * @param state_timeout time out for the current state */ static void -process_peer_iteration_cb(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout) +process_peer_iteration_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout) { if (NULL == peer) - { - /* done */ - pic = NULL; - return; - } + { + /* done */ + pic = NULL; + return; + } if ((GNUNET_NO == iterate_all) && - (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state))) + (GNUNET_NO == GNUNET_TRANSPORT_is_connected (state))) return; /* Display only connected peers */ if (NULL != op_timeout) - GNUNET_SCHEDULER_cancel(op_timeout); + GNUNET_SCHEDULER_cancel (op_timeout); op_timeout = - GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL); + GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received address for peer `%s': %s\n", - GNUNET_i2s(peer), - address ? address->transport_name : ""); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received address for peer `%s': %s\n", + GNUNET_i2s (peer), + address ? address->transport_name : ""); if (NULL != address) - resolve_peer_address(address, numeric, state, state_timeout); + resolve_peer_address (address, numeric, state, state_timeout); else - print_info(peer, NULL, NULL, state, state_timeout); + print_info (peer, NULL, NULL, state, state_timeout); } /** * Context for address resolution by #plugin_monitoring_cb(). */ -struct PluginMonitorAddress { +struct PluginMonitorAddress +{ /** * Ongoing resolution request. */ @@ -909,57 +913,57 @@ struct PluginMonitorAddress { * @param info the monitoring information */ static void -print_plugin_event_info(struct PluginMonitorAddress *addr, - const struct GNUNET_TRANSPORT_SessionInfo *info) +print_plugin_event_info (struct PluginMonitorAddress *addr, + const struct GNUNET_TRANSPORT_SessionInfo *info) { const char *state; switch (info->state) - { - case GNUNET_TRANSPORT_SS_INIT: - state = "INIT"; - break; - - case GNUNET_TRANSPORT_SS_HANDSHAKE: - state = "HANDSHAKE"; - break; - - case GNUNET_TRANSPORT_SS_UP: - state = "UP"; - break; - - case GNUNET_TRANSPORT_SS_UPDATE: - state = "UPDATE"; - break; - - case GNUNET_TRANSPORT_SS_DONE: - state = "DONE"; - break; - - default: - state = "UNKNOWN"; - break; - } - fprintf(stdout, - "%s: state %s timeout in %s @ %s%s\n", - GNUNET_i2s(&info->address->peer), - state, - GNUNET_STRINGS_relative_time_to_string( - GNUNET_TIME_absolute_get_remaining(info->session_timeout), - GNUNET_YES), - addr->str, - (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : ""); - fprintf(stdout, - "%s: queue has %3u messages and %6u bytes\n", - GNUNET_i2s(&info->address->peer), - info->num_msg_pending, - info->num_bytes_pending); + { + case GNUNET_TRANSPORT_SS_INIT: + state = "INIT"; + break; + + case GNUNET_TRANSPORT_SS_HANDSHAKE: + state = "HANDSHAKE"; + break; + + case GNUNET_TRANSPORT_SS_UP: + state = "UP"; + break; + + case GNUNET_TRANSPORT_SS_UPDATE: + state = "UPDATE"; + break; + + case GNUNET_TRANSPORT_SS_DONE: + state = "DONE"; + break; + + default: + state = "UNKNOWN"; + break; + } + fprintf (stdout, + "%s: state %s timeout in %s @ %s%s\n", + GNUNET_i2s (&info->address->peer), + state, + GNUNET_STRINGS_relative_time_to_string ( + GNUNET_TIME_absolute_get_remaining (info->session_timeout), + GNUNET_YES), + addr->str, + (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : ""); + fprintf (stdout, + "%s: queue has %3u messages and %6u bytes\n", + GNUNET_i2s (&info->address->peer), + info->num_msg_pending, + info->num_bytes_pending); if (0 != - GNUNET_TIME_absolute_get_remaining(info->receive_delay).rel_value_us) - fprintf(stdout, - "%s: receiving blocked until %s\n", - GNUNET_i2s(&info->address->peer), - GNUNET_STRINGS_absolute_time_to_string(info->receive_delay)); + GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us) + fprintf (stdout, + "%s: receiving blocked until %s\n", + GNUNET_i2s (&info->address->peer), + GNUNET_STRINGS_absolute_time_to_string (info->receive_delay)); } @@ -980,19 +984,19 @@ print_plugin_event_info(struct PluginMonitorAddress *addr, * if #GNUNET_SYSERR: communication error (IPC error) */ static void -address_cb(void *cls, const char *address, int res) +address_cb (void *cls, const char *address, int res) { struct PluginMonitorAddress *addr = cls; if (NULL == address) - { - addr->asc = NULL; - return; - } + { + addr->asc = NULL; + return; + } if (NULL != addr->str) return; - addr->str = GNUNET_strdup(address); - print_plugin_event_info(addr, &addr->si); + addr->str = GNUNET_strdup (address); + print_plugin_event_info (addr, &addr->si); } @@ -1014,10 +1018,10 @@ address_cb(void *cls, const char *address, int res) * was being cancelled while sessions were active */ static void -plugin_monitoring_cb(void *cls, - struct GNUNET_TRANSPORT_PluginSession *session, - void **session_ctx, - const struct GNUNET_TRANSPORT_SessionInfo *info) +plugin_monitoring_cb (void *cls, + struct GNUNET_TRANSPORT_PluginSession *session, + void **session_ctx, + const struct GNUNET_TRANSPORT_SessionInfo *info) { struct PluginMonitorAddress *addr; @@ -1025,50 +1029,50 @@ plugin_monitoring_cb(void *cls, return; /* in sync with transport service */ addr = *session_ctx; if (NULL == info) + { + if (NULL != addr) { - if (NULL != addr) - { - if (NULL != addr->asc) - { - GNUNET_TRANSPORT_address_to_string_cancel(addr->asc); - addr->asc = NULL; - } - GNUNET_free_non_null(addr->str); - GNUNET_free(addr); - *session_ctx = NULL; - } - return; /* shutdown */ + if (NULL != addr->asc) + { + GNUNET_TRANSPORT_address_to_string_cancel (addr->asc); + addr->asc = NULL; + } + GNUNET_free_non_null (addr->str); + GNUNET_free (addr); + *session_ctx = NULL; } + return; /* shutdown */ + } if (0 != - memcmp(&info->address->peer, &pid, sizeof(struct GNUNET_PeerIdentity))) + memcmp (&info->address->peer, &pid, sizeof(struct GNUNET_PeerIdentity))) return; /* filtered */ if (NULL == addr) - { - addr = GNUNET_new(struct PluginMonitorAddress); - addr->asc = - GNUNET_TRANSPORT_address_to_string(cfg, - info->address, - numeric, - GNUNET_TIME_UNIT_FOREVER_REL, - &address_cb, - addr); - *session_ctx = addr; - } + { + addr = GNUNET_new (struct PluginMonitorAddress); + addr->asc = + GNUNET_TRANSPORT_address_to_string (cfg, + info->address, + numeric, + GNUNET_TIME_UNIT_FOREVER_REL, + &address_cb, + addr); + *session_ctx = addr; + } if (NULL == addr->str) addr->si = *info; else - print_plugin_event_info(addr, info); + print_plugin_event_info (addr, info); if (GNUNET_TRANSPORT_SS_DONE == info->state) + { + if (NULL != addr->asc) { - if (NULL != addr->asc) - { - GNUNET_TRANSPORT_address_to_string_cancel(addr->asc); - addr->asc = NULL; - } - GNUNET_free_non_null(addr->str); - GNUNET_free(addr); - *session_ctx = NULL; + GNUNET_TRANSPORT_address_to_string_cancel (addr->asc); + addr->asc = NULL; } + GNUNET_free_non_null (addr->str); + GNUNET_free (addr); + *session_ctx = NULL; + } } @@ -1083,64 +1087,64 @@ plugin_monitoring_cb(void *cls, * @param state_timeout time out for the current state */ static void -process_peer_monitoring_cb(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout) +process_peer_monitoring_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout) { struct MonitoredPeer *m; if (NULL == peer) - { - fprintf(stdout, - "%s", - _( - "Monitor disconnected from transport service. Reconnecting.\n")); - return; - } + { + fprintf (stdout, + "%s", + _ ( + "Monitor disconnected from transport service. Reconnecting.\n")); + return; + } if (NULL != op_timeout) - GNUNET_SCHEDULER_cancel(op_timeout); + GNUNET_SCHEDULER_cancel (op_timeout); op_timeout = - GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL); - - if (NULL == (m = GNUNET_CONTAINER_multipeermap_get(monitored_peers, peer))) - { - m = GNUNET_new(struct MonitoredPeer); - GNUNET_CONTAINER_multipeermap_put( - monitored_peers, - peer, - m, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - } + GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); + + if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer))) + { + m = GNUNET_new (struct MonitoredPeer); + GNUNET_CONTAINER_multipeermap_put ( + monitored_peers, + peer, + m, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + } else + { + if ((m->state == state) && + (m->state_timeout.abs_value_us == state_timeout.abs_value_us) && + (NULL == address) && (NULL == m->address)) { - if ((m->state == state) && - (m->state_timeout.abs_value_us == state_timeout.abs_value_us) && - (NULL == address) && (NULL == m->address)) - { - return; /* No real change */ - } - if ((m->state == state) && (NULL != address) && (NULL != m->address) && - (0 == GNUNET_HELLO_address_cmp(m->address, address))) - return; /* No real change */ + return; /* No real change */ } + if ((m->state == state) && (NULL != address) && (NULL != m->address) && + (0 == GNUNET_HELLO_address_cmp (m->address, address))) + return; /* No real change */ + } if (NULL != m->address) - { - GNUNET_free(m->address); - m->address = NULL; - } + { + GNUNET_free (m->address); + m->address = NULL; + } if (NULL != address) - m->address = GNUNET_HELLO_address_copy(address); + m->address = GNUNET_HELLO_address_copy (address); m->state = state; m->state_timeout = state_timeout; if (NULL != address) - resolve_peer_address(m->address, numeric, m->state, m->state_timeout); + resolve_peer_address (m->address, numeric, m->state, m->state_timeout); else - print_info(peer, NULL, NULL, m->state, m->state_timeout); + print_info (peer, NULL, NULL, m->state, m->state_timeout); } @@ -1154,9 +1158,9 @@ process_peer_monitoring_cb(void *cls, * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not */ static int -blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *cpid) +blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *cpid) { - if (0 == memcmp(cpid, &pid, sizeof(struct GNUNET_PeerIdentity))) + if (0 == memcmp (cpid, &pid, sizeof(struct GNUNET_PeerIdentity))) return GNUNET_SYSERR; return GNUNET_OK; } @@ -1171,259 +1175,259 @@ blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *cpid) * @param mycfg configuration */ static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *mycfg) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *mycfg) { static struct GNUNET_PeerIdentity zero_pid; int counter = 0; ret = 1; - cfg = (struct GNUNET_CONFIGURATION_Handle *)mycfg; + cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; - counter = benchmark_send + benchmark_receive + iterate_connections + - monitor_connections + monitor_connects + do_disconnect + - monitor_plugins; + counter = benchmark_send + benchmark_receive + iterate_connections + + monitor_connections + monitor_connects + do_disconnect + + monitor_plugins; if (1 < counter) + { + fprintf ( + stderr, + _ ( + "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"), + "disconnect", + "benchmark send", + "benchmark receive", + "information", + "monitor", + "events", + "plugins"); + return; + } + if (0 == counter) + { + fprintf ( + stderr, + _ ( + "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"), + "disconnect", + "benchmark send", + "benchmark receive", + "information", + "monitor", + "events", + "plugins"); + return; + } + + if (do_disconnect) /* -D: Disconnect from peer */ + { + if (0 == memcmp (&zero_pid, &pid, sizeof(pid))) { - fprintf( - stderr, - _( - "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"), - "disconnect", - "benchmark send", - "benchmark receive", - "information", - "monitor", - "events", - "plugins"); + fprintf (stderr, + _ ("Option `%s' makes no sense without option `%s'.\n"), + "-D", + "-p"); + ret = 1; return; } - if (0 == counter) + blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL); + if (NULL == blacklist) { - fprintf( - stderr, - _( - "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"), - "disconnect", - "benchmark send", - "benchmark receive", - "information", - "monitor", - "events", - "plugins"); + fprintf (stderr, + "%s", + _ ( + "Failed to connect to transport service for disconnection\n")); + ret = 1; return; } - - if (do_disconnect) /* -D: Disconnect from peer */ + fprintf (stdout, + "%s", + _ ("Blacklisting request in place, stop with CTRL-C\n")); + } + else if (benchmark_send) /* -s: Benchmark sending */ + { + if (0 == memcmp (&zero_pid, &pid, sizeof(pid))) { - if (0 == memcmp(&zero_pid, &pid, sizeof(pid))) - { - fprintf(stderr, - _("Option `%s' makes no sense without option `%s'.\n"), - "-D", - "-p"); - ret = 1; - return; - } - blacklist = GNUNET_TRANSPORT_blacklist(cfg, &blacklist_cb, NULL); - if (NULL == blacklist) - { - fprintf(stderr, - "%s", - _( - "Failed to connect to transport service for disconnection\n")); - ret = 1; - return; - } - fprintf(stdout, - "%s", - _("Blacklisting request in place, stop with CTRL-C\n")); + fprintf (stderr, + _ ("Option `%s' makes no sense without option `%s'.\n"), + "-s", + "-p"); + ret = 1; + return; } - else if (benchmark_send) /* -s: Benchmark sending */ + handle = GNUNET_TRANSPORT_core_connect (cfg, + NULL, + NULL, + NULL, + ¬ify_connect, + ¬ify_disconnect, + NULL); + if (NULL == handle) { - if (0 == memcmp(&zero_pid, &pid, sizeof(pid))) - { - fprintf(stderr, - _("Option `%s' makes no sense without option `%s'.\n"), - "-s", - "-p"); - ret = 1; - return; - } - handle = GNUNET_TRANSPORT_core_connect(cfg, - NULL, - NULL, - NULL, - ¬ify_connect, - ¬ify_disconnect, - NULL); - if (NULL == handle) - { - fprintf(stderr, "%s", _("Failed to connect to transport service\n")); - ret = 1; - return; - } - start_time = GNUNET_TIME_absolute_get(); - op_timeout = - GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL); + fprintf (stderr, "%s", _ ("Failed to connect to transport service\n")); + ret = 1; + return; } + start_time = GNUNET_TIME_absolute_get (); + op_timeout = + GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); + } else if (benchmark_receive) /* -b: Benchmark receiving */ + { + struct GNUNET_MQ_MessageHandler handlers[] = + { GNUNET_MQ_hd_var_size (dummy, + GNUNET_MESSAGE_TYPE_DUMMY, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_handler_end () }; + + handle = GNUNET_TRANSPORT_core_connect (cfg, + NULL, + handlers, + NULL, + NULL, + NULL, + NULL); + if (NULL == handle) { - struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_var_size(dummy, - GNUNET_MESSAGE_TYPE_DUMMY, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_handler_end() }; - - handle = GNUNET_TRANSPORT_core_connect(cfg, - NULL, - handlers, - NULL, - NULL, - NULL, - NULL); - if (NULL == handle) - { - fprintf(stderr, "%s", _("Failed to connect to transport service\n")); - ret = 1; - return; - } - if (verbosity > 0) - fprintf(stdout, "%s", _("Starting to receive benchmark data\n")); - start_time = GNUNET_TIME_absolute_get(); + fprintf (stderr, "%s", _ ("Failed to connect to transport service\n")); + ret = 1; + return; } + if (verbosity > 0) + fprintf (stdout, "%s", _ ("Starting to receive benchmark data\n")); + start_time = GNUNET_TIME_absolute_get (); + } else if (iterate_connections) /* -i: List information about peers once */ - { - pic = GNUNET_TRANSPORT_monitor_peers(cfg, - &pid, - GNUNET_YES, - &process_peer_iteration_cb, - (void *)cfg); - op_timeout = - GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL); - } + { + pic = GNUNET_TRANSPORT_monitor_peers (cfg, + &pid, + GNUNET_YES, + &process_peer_iteration_cb, + (void *) cfg); + op_timeout = + GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); + } else if (monitor_connections) /* -m: List information about peers continuously */ - { - monitored_peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); - pic = GNUNET_TRANSPORT_monitor_peers(cfg, - &pid, - GNUNET_NO, - &process_peer_monitoring_cb, - NULL); - } + { + monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); + pic = GNUNET_TRANSPORT_monitor_peers (cfg, + &pid, + GNUNET_NO, + &process_peer_monitoring_cb, + NULL); + } else if (monitor_plugins) /* -P: List information about plugins continuously */ - { - monitored_plugins = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); - pm = GNUNET_TRANSPORT_monitor_plugins(cfg, &plugin_monitoring_cb, NULL); - } + { + monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); + pm = GNUNET_TRANSPORT_monitor_plugins (cfg, &plugin_monitoring_cb, NULL); + } else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ + { + monitor_connect_counter = 0; + handle = GNUNET_TRANSPORT_core_connect (cfg, + NULL, + NULL, + NULL, + &monitor_notify_connect, + &monitor_notify_disconnect, + NULL); + if (NULL == handle) { - monitor_connect_counter = 0; - handle = GNUNET_TRANSPORT_core_connect(cfg, - NULL, - NULL, - NULL, - &monitor_notify_connect, - &monitor_notify_disconnect, - NULL); - if (NULL == handle) - { - fprintf(stderr, "%s", _("Failed to connect to transport service\n")); - ret = 1; - return; - } - ret = 0; - } - else - { - GNUNET_break(0); + fprintf (stderr, "%s", _ ("Failed to connect to transport service\n")); + ret = 1; return; } + ret = 0; + } + else + { + GNUNET_break (0); + return; + } - GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } int -main(int argc, char *const *argv) +main (int argc, char *const *argv) { int res; struct GNUNET_GETOPT_CommandLineOption options[] = - { GNUNET_GETOPT_option_flag( + { GNUNET_GETOPT_option_flag ( 'a', "all", - gettext_noop( + gettext_noop ( "print information for all peers (instead of only connected peers)"), &iterate_all), - GNUNET_GETOPT_option_flag( + GNUNET_GETOPT_option_flag ( 'b', "benchmark", - gettext_noop( + gettext_noop ( "measure how fast we are receiving data from all peers (until CTRL-C)"), &benchmark_receive), - GNUNET_GETOPT_option_flag('D', - "disconnect", - gettext_noop("disconnect from a peer"), - &do_disconnect), - GNUNET_GETOPT_option_flag( + GNUNET_GETOPT_option_flag ('D', + "disconnect", + gettext_noop ("disconnect from a peer"), + &do_disconnect), + GNUNET_GETOPT_option_flag ( 'i', "information", - gettext_noop( + gettext_noop ( "provide information about all current connections (once)"), &iterate_connections), - GNUNET_GETOPT_option_flag( + GNUNET_GETOPT_option_flag ( 'm', "monitor", - gettext_noop( + gettext_noop ( "provide information about all current connections (continuously)"), &monitor_connections), - GNUNET_GETOPT_option_flag( + GNUNET_GETOPT_option_flag ( 'e', "events", - gettext_noop( + gettext_noop ( "provide information about all connects and disconnect events (continuously)"), &monitor_connects), - GNUNET_GETOPT_option_flag('n', - "numeric", - gettext_noop("do not resolve hostnames"), - &numeric), - GNUNET_GETOPT_option_base32_auto('p', - "peer", - "PEER", - gettext_noop("peer identity"), - &pid), - GNUNET_GETOPT_option_flag('P', - "plugins", - gettext_noop("monitor plugin sessions"), - &monitor_plugins), - GNUNET_GETOPT_option_flag( + GNUNET_GETOPT_option_flag ('n', + "numeric", + gettext_noop ("do not resolve hostnames"), + &numeric), + GNUNET_GETOPT_option_base32_auto ('p', + "peer", + "PEER", + gettext_noop ("peer identity"), + &pid), + GNUNET_GETOPT_option_flag ('P', + "plugins", + gettext_noop ("monitor plugin sessions"), + &monitor_plugins), + GNUNET_GETOPT_option_flag ( 's', "send", - gettext_noop( + gettext_noop ( "send data for benchmarking to the other peer (until CTRL-C)"), &benchmark_send), - GNUNET_GETOPT_option_verbose(&verbosity), + GNUNET_GETOPT_option_verbose (&verbosity), GNUNET_GETOPT_OPTION_END }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; res = - GNUNET_PROGRAM_run(argc, - argv, - "gnunet-transport", - gettext_noop("Direct access to transport service."), - options, - &run, - NULL); - GNUNET_free((void *)argv); + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-transport", + gettext_noop ("Direct access to transport service."), + options, + &run, + NULL); + GNUNET_free ((void *) argv); if (GNUNET_OK == res) return ret; return 1; diff --git a/src/transport/ieee80211_radiotap.h b/src/transport/ieee80211_radiotap.h index f05449f18..9bdfa02f5 100644 --- a/src/transport/ieee80211_radiotap.h +++ b/src/transport/ieee80211_radiotap.h @@ -61,7 +61,8 @@ * The radio capture header precedes the 802.11 header. * All data in the header is little endian on all platforms. */ -struct ieee80211_radiotap_header { +struct ieee80211_radiotap_header +{ u8 it_version; /* Version 0. Only increases * for drastic changes, * introduction of compatible @@ -179,7 +180,8 @@ struct ieee80211_radiotap_header { * Number of unicast retries a transmitted frame used. * */ -enum ieee80211_radiotap_type { +enum ieee80211_radiotap_type +{ IEEE80211_RADIOTAP_TSFT = 0, IEEE80211_RADIOTAP_FLAGS = 1, IEEE80211_RADIOTAP_RATE = 2, @@ -255,19 +257,19 @@ enum ieee80211_radiotap_type { /* helpers */ static inline u16 -get_unaligned_le16(const u8 *p) +get_unaligned_le16 (const u8 *p) { return p[0] | p[1] << 8; } static inline int -ieee80211_get_radiotap_len(unsigned char *data) +ieee80211_get_radiotap_len (unsigned char *data) { struct ieee80211_radiotap_header *hdr = - (struct ieee80211_radiotap_header *)data; + (struct ieee80211_radiotap_header *) data; - return get_unaligned_le16((const u8 *)&hdr->it_len); + return get_unaligned_le16 ((const u8 *) &hdr->it_len); } #endif /* IEEE80211_RADIOTAP_H */ diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h index 4ad8f6e58..a3b59513e 100644 --- a/src/transport/plugin_transport_http.h +++ b/src/transport/plugin_transport_http.h @@ -62,12 +62,14 @@ #define OUTBOUND GNUNET_NO -#define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) +#define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 15) /** * Encapsulation of all of the state of the plugin. */ -struct Plugin { +struct Plugin +{ /** * Our environment. */ @@ -118,7 +120,7 @@ struct Plugin { /** * Task calling transport service about external address */ - struct GNUNET_SCHEDULER_Task * notify_ext_task; + struct GNUNET_SCHEDULER_Task *notify_ext_task; /** * Plugin name. @@ -206,7 +208,7 @@ struct Plugin { /** * MHD IPv4 task */ - struct GNUNET_SCHEDULER_Task * server_v4_task; + struct GNUNET_SCHEDULER_Task *server_v4_task; /** * The IPv4 server is scheduled to run asap @@ -221,7 +223,7 @@ struct Plugin { /** * MHD IPv4 task */ - struct GNUNET_SCHEDULER_Task * server_v6_task; + struct GNUNET_SCHEDULER_Task *server_v6_task; /** * The IPv6 server is scheduled to run asap @@ -260,7 +262,7 @@ struct Plugin { /** * curl perform task */ - struct GNUNET_SCHEDULER_Task * client_perform_task; + struct GNUNET_SCHEDULER_Task *client_perform_task; }; GNUNET_NETWORK_STRUCT_BEGIN @@ -268,7 +270,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * HTTP addresses including a full URI */ -struct HttpAddress { +struct HttpAddress +{ /** * Length of the address following in NBO */ @@ -283,7 +286,8 @@ struct HttpAddress { /** * IPv4 addresses */ -struct IPv4HttpAddress { +struct IPv4HttpAddress +{ /** * IPv4 address, in network byte order. */ @@ -298,7 +302,8 @@ struct IPv4HttpAddress { /** * IPv4 addresses */ -struct IPv6HttpAddress { +struct IPv6HttpAddress +{ /** * IPv6 address. */ @@ -312,7 +317,8 @@ struct IPv6HttpAddress { GNUNET_NETWORK_STRUCT_END -struct ServerRequest { +struct ServerRequest +{ /** * _RECV or _SEND */ @@ -338,7 +344,8 @@ struct ServerRequest { /** * Session handle for connections. */ -struct GNUNET_ATS_Session { +struct GNUNET_ATS_Session +{ /** * To whom are we talking to */ @@ -420,12 +427,12 @@ struct GNUNET_ATS_Session { /** * Task to wake up client receive handle when receiving is allowed again */ - struct GNUNET_SCHEDULER_Task * recv_wakeup_task; + struct GNUNET_SCHEDULER_Task *recv_wakeup_task; /** * Session timeout task */ - struct GNUNET_SCHEDULER_Task * timeout_task; + struct GNUNET_SCHEDULER_Task *timeout_task; /** * Is client send handle paused since there are no data to send? @@ -448,7 +455,8 @@ struct GNUNET_ATS_Session { /** * Message to send using http */ -struct HTTP_Message { +struct HTTP_Message +{ /** * next pointer for double linked list */ @@ -489,81 +497,81 @@ struct HTTP_Message { struct GNUNET_ATS_Session * -create_session(struct Plugin *plugin, - const struct GNUNET_PeerIdentity *target, - const void *addr, - size_t addrlen); +create_session (struct Plugin *plugin, + const struct GNUNET_PeerIdentity *target, + const void *addr, + size_t addrlen); int -exist_session(struct Plugin *plugin, - struct GNUNET_ATS_Session *s); +exist_session (struct Plugin *plugin, + struct GNUNET_ATS_Session *s); void -delete_session(struct GNUNET_ATS_Session *s); +delete_session (struct GNUNET_ATS_Session *s); int -exist_session(struct Plugin *plugin, - struct GNUNET_ATS_Session *s); +exist_session (struct Plugin *plugin, + struct GNUNET_ATS_Session *s); struct GNUNET_TIME_Relative -http_plugin_receive(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - struct GNUNET_ATS_Session *session, - const char *sender_address, - uint16_t sender_address_len); +http_plugin_receive (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + struct GNUNET_ATS_Session *session, + const char *sender_address, + uint16_t sender_address_len); const char * -http_plugin_address_to_string(void *cls, - const void *addr, - size_t addrlen); +http_plugin_address_to_string (void *cls, + const void *addr, + size_t addrlen); int -client_disconnect(struct GNUNET_ATS_Session *s); +client_disconnect (struct GNUNET_ATS_Session *s); int -client_connect(struct GNUNET_ATS_Session *s); +client_connect (struct GNUNET_ATS_Session *s); int -client_send(struct GNUNET_ATS_Session *s, struct HTTP_Message *msg); +client_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg); int -client_start(struct Plugin *plugin); +client_start (struct Plugin *plugin); void -client_stop(struct Plugin *plugin); +client_stop (struct Plugin *plugin); int -server_disconnect(struct GNUNET_ATS_Session *s); +server_disconnect (struct GNUNET_ATS_Session *s); int -server_send(struct GNUNET_ATS_Session *s, struct HTTP_Message *msg); +server_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg); int -server_start(struct Plugin *plugin); +server_start (struct Plugin *plugin); void -server_stop(struct Plugin *plugin); +server_stop (struct Plugin *plugin); void -notify_session_end(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *s); +notify_session_end (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *s); /*#ifndef PLUGIN_TRANSPORT_HTTP_H*/ diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 6148e9a44..98ab6544f 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -28,18 +28,23 @@ #if BUILD_HTTPS #define PLUGIN_NAME "https_client" #define HTTP_STAT_STR_CONNECTIONS "# HTTPS client connections" -#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_client_init -#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_client_done +#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \ + libgnunet_plugin_transport_https_client_init +#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \ + libgnunet_plugin_transport_https_client_done #else #define PLUGIN_NAME "http_client" #define HTTP_STAT_STR_CONNECTIONS "# HTTP client connections" -#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_client_init -#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_client_done +#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \ + libgnunet_plugin_transport_http_client_init +#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \ + libgnunet_plugin_transport_http_client_done #endif #define VERBOSE_CURL GNUNET_NO -#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) +#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 1) #define ENABLE_PUT GNUNET_YES #define ENABLE_GET GNUNET_YES @@ -53,7 +58,7 @@ #include "gnunet_curl_lib.h" -#define LOG(kind, ...) GNUNET_log_from(kind, PLUGIN_NAME, __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, PLUGIN_NAME, __VA_ARGS__) /** * Encapsulation of all of the state of the plugin. @@ -63,7 +68,8 @@ struct HTTP_Client_Plugin; /** * State of a HTTP PUT request */ -enum HTTP_PUT_REQUEST_STATE { +enum HTTP_PUT_REQUEST_STATE +{ /** * Just created, not yet connected */ @@ -103,7 +109,8 @@ enum HTTP_PUT_REQUEST_STATE { /** * Message to send using http */ -struct HTTP_Message { +struct HTTP_Message +{ /** * next pointer for double linked list */ @@ -153,7 +160,8 @@ struct GNUNET_ATS_Session; * A request handle * */ -struct RequestHandle { +struct RequestHandle +{ /** * Current state of this request */ @@ -174,7 +182,8 @@ struct RequestHandle { /** * Session handle for connections. */ -struct GNUNET_ATS_Session { +struct GNUNET_ATS_Session +{ /** * The URL to connect to */ @@ -267,7 +276,8 @@ struct GNUNET_ATS_Session { /** * Encapsulation of all of the state of the plugin. */ -struct HTTP_Client_Plugin { +struct HTTP_Client_Plugin +{ /** * Our environment. */ @@ -321,7 +331,7 @@ struct HTTP_Client_Plugin { /** * curl perform task */ - struct GNUNET_SCHEDULER_Task * client_perform_task; + struct GNUNET_SCHEDULER_Task *client_perform_task; /** * Type of proxy server: @@ -388,7 +398,7 @@ struct HTTP_Client_Plugin { * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s); +http_client_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *s); /** @@ -400,15 +410,15 @@ http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s); * @param state new state of the session */ static void -notify_session_monitor(struct HTTP_Client_Plugin *plugin, - struct GNUNET_ATS_Session *session, - enum GNUNET_TRANSPORT_SessionState state) +notify_session_monitor (struct HTTP_Client_Plugin *plugin, + struct GNUNET_ATS_Session *session, + enum GNUNET_TRANSPORT_SessionState state) { struct GNUNET_TRANSPORT_SessionInfo info; if (NULL == plugin->sic) return; - memset(&info, 0, sizeof(info)); + memset (&info, 0, sizeof(info)); info.state = state; info.is_inbound = GNUNET_NO; info.num_msg_pending = session->msgs_in_queue; @@ -416,9 +426,9 @@ notify_session_monitor(struct HTTP_Client_Plugin *plugin, info.receive_delay = session->next_receive; info.session_timeout = session->timeout; info.address = session->address; - plugin->sic(plugin->sic_cls, - session, - &info); + plugin->sic (plugin->sic_cls, + session, + &info); } @@ -428,7 +438,7 @@ notify_session_monitor(struct HTTP_Client_Plugin *plugin, * @param s the session to delete */ static void -client_delete_session(struct GNUNET_ATS_Session *s) +client_delete_session (struct GNUNET_ATS_Session *s) { struct HTTP_Client_Plugin *plugin = s->plugin; struct HTTP_Message *pos; @@ -436,95 +446,95 @@ client_delete_session(struct GNUNET_ATS_Session *s) CURLMcode mret; if (NULL != s->timeout_task) - { - GNUNET_SCHEDULER_cancel(s->timeout_task); - s->timeout_task = NULL; - s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; - } + { + GNUNET_SCHEDULER_cancel (s->timeout_task); + s->timeout_task = NULL; + s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; + } if (NULL != s->put_disconnect_task) - { - GNUNET_SCHEDULER_cancel(s->put_disconnect_task); - s->put_disconnect_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (s->put_disconnect_task); + s->put_disconnect_task = NULL; + } if (NULL != s->recv_wakeup_task) - { - GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); - s->recv_wakeup_task = NULL; - } - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_remove(plugin->sessions, - &s->address->peer, - s)); + { + GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); + s->recv_wakeup_task = NULL; + } + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, + &s->address->peer, + s)); if (NULL != s->put.easyhandle) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: disconnecting PUT request to peer `%s'\n", - s, - s->put.easyhandle, - GNUNET_i2s(&s->address->peer)); - - /* remove curl handle from multi handle */ - mret = curl_multi_remove_handle(plugin->curl_multi_handle, - s->put.easyhandle); - GNUNET_break(CURLM_OK == mret); - curl_easy_cleanup(s->put.easyhandle); - GNUNET_assert(plugin->cur_requests > 0); - plugin->cur_requests--; - s->put.easyhandle = NULL; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: disconnecting PUT request to peer `%s'\n", + s, + s->put.easyhandle, + GNUNET_i2s (&s->address->peer)); + + /* remove curl handle from multi handle */ + mret = curl_multi_remove_handle (plugin->curl_multi_handle, + s->put.easyhandle); + GNUNET_break (CURLM_OK == mret); + curl_easy_cleanup (s->put.easyhandle); + GNUNET_assert (plugin->cur_requests > 0); + plugin->cur_requests--; + s->put.easyhandle = NULL; + } if (NULL != s->get.easyhandle) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: disconnecting GET request to peer `%s'\n", - s, s->get.easyhandle, - GNUNET_i2s(&s->address->peer)); - /* remove curl handle from multi handle */ - mret = curl_multi_remove_handle(plugin->curl_multi_handle, - s->get.easyhandle); - GNUNET_break(CURLM_OK == mret); - curl_easy_cleanup(s->get.easyhandle); - GNUNET_assert(plugin->cur_requests > 0); - plugin->cur_requests--; - s->get.easyhandle = NULL; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: disconnecting GET request to peer `%s'\n", + s, s->get.easyhandle, + GNUNET_i2s (&s->address->peer)); + /* remove curl handle from multi handle */ + mret = curl_multi_remove_handle (plugin->curl_multi_handle, + s->get.easyhandle); + GNUNET_break (CURLM_OK == mret); + curl_easy_cleanup (s->get.easyhandle); + GNUNET_assert (plugin->cur_requests > 0); + plugin->cur_requests--; + s->get.easyhandle = NULL; + } - GNUNET_STATISTICS_set(plugin->env->stats, - HTTP_STAT_STR_CONNECTIONS, - plugin->cur_requests, - GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, + HTTP_STAT_STR_CONNECTIONS, + plugin->cur_requests, + GNUNET_NO); next = s->msg_head; while (NULL != (pos = next)) - { - next = pos->next; - GNUNET_CONTAINER_DLL_remove(s->msg_head, - s->msg_tail, - pos); - GNUNET_assert(0 < s->msgs_in_queue); - s->msgs_in_queue--; - GNUNET_assert(pos->size <= s->bytes_in_queue); - s->bytes_in_queue -= pos->size; - if (NULL != pos->transmit_cont) - pos->transmit_cont(pos->transmit_cont_cls, - &s->address->peer, - GNUNET_SYSERR, - pos->size, - pos->pos + s->overhead); - s->overhead = 0; - GNUNET_free(pos); - } - GNUNET_assert(0 == s->msgs_in_queue); - GNUNET_assert(0 == s->bytes_in_queue); - notify_session_monitor(plugin, - s, - GNUNET_TRANSPORT_SS_DONE); + { + next = pos->next; + GNUNET_CONTAINER_DLL_remove (s->msg_head, + s->msg_tail, + pos); + GNUNET_assert (0 < s->msgs_in_queue); + s->msgs_in_queue--; + GNUNET_assert (pos->size <= s->bytes_in_queue); + s->bytes_in_queue -= pos->size; + if (NULL != pos->transmit_cont) + pos->transmit_cont (pos->transmit_cont_cls, + &s->address->peer, + GNUNET_SYSERR, + pos->size, + pos->pos + s->overhead); + s->overhead = 0; + GNUNET_free (pos); + } + GNUNET_assert (0 == s->msgs_in_queue); + GNUNET_assert (0 == s->bytes_in_queue); + notify_session_monitor (plugin, + s, + GNUNET_TRANSPORT_SS_DONE); if (NULL != s->msg_tk) - { - GNUNET_MST_destroy(s->msg_tk); - s->msg_tk = NULL; - } - GNUNET_HELLO_address_free(s->address); - GNUNET_free(s->url); - GNUNET_free(s); + { + GNUNET_MST_destroy (s->msg_tk); + s->msg_tk = NULL; + } + GNUNET_HELLO_address_free (s->address); + GNUNET_free (s->url); + GNUNET_free (s); } @@ -534,10 +544,11 @@ client_delete_session(struct GNUNET_ATS_Session *s) * @param s the session */ static void -client_reschedule_session_timeout(struct GNUNET_ATS_Session *s) +client_reschedule_session_timeout (struct GNUNET_ATS_Session *s) { - GNUNET_assert(NULL != s->timeout_task); - s->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_assert (NULL != s->timeout_task); + s->timeout = GNUNET_TIME_relative_to_absolute ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); } @@ -548,7 +559,7 @@ client_reschedule_session_timeout(struct GNUNET_ATS_Session *s) * @param tc gnunet scheduler task context */ static void -client_run(void *cls); +client_run (void *cls); /** @@ -559,8 +570,8 @@ client_run(void *cls); * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok */ static int -client_schedule(struct HTTP_Client_Plugin *plugin, - int now) +client_schedule (struct HTTP_Client_Plugin *plugin, + int now) { fd_set rs; fd_set ws; @@ -574,54 +585,54 @@ client_schedule(struct HTTP_Client_Plugin *plugin, /* Cancel previous scheduled task */ if (plugin->client_perform_task != NULL) - { - GNUNET_SCHEDULER_cancel(plugin->client_perform_task); - plugin->client_perform_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->client_perform_task); + plugin->client_perform_task = NULL; + } max = -1; - FD_ZERO(&rs); - FD_ZERO(&ws); - FD_ZERO(&es); - mret = curl_multi_fdset(plugin->curl_multi_handle, &rs, &ws, &es, &max); + FD_ZERO (&rs); + FD_ZERO (&ws); + FD_ZERO (&es); + mret = curl_multi_fdset (plugin->curl_multi_handle, &rs, &ws, &es, &max); if (mret != CURLM_OK) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("%s failed at %s:%d: `%s'\n"), - "curl_multi_fdset", - __FILE__, - __LINE__, - curl_multi_strerror(mret)); - return GNUNET_SYSERR; - } - mret = curl_multi_timeout(plugin->curl_multi_handle, &to); + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("%s failed at %s:%d: `%s'\n"), + "curl_multi_fdset", + __FILE__, + __LINE__, + curl_multi_strerror (mret)); + return GNUNET_SYSERR; + } + mret = curl_multi_timeout (plugin->curl_multi_handle, &to); if (-1 == to) - timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1); + timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1); else - timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, to); + timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to); if (now == GNUNET_YES) timeout = GNUNET_TIME_UNIT_MILLISECONDS; if (CURLM_OK != mret) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("%s failed at %s:%d: `%s'\n"), - "curl_multi_timeout", __FILE__, __LINE__, - curl_multi_strerror(mret)); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("%s failed at %s:%d: `%s'\n"), + "curl_multi_timeout", __FILE__, __LINE__, + curl_multi_strerror (mret)); + return GNUNET_SYSERR; + } - grs = GNUNET_NETWORK_fdset_create(); - gws = GNUNET_NETWORK_fdset_create(); - GNUNET_NETWORK_fdset_copy_native(grs, &rs, max + 1); - GNUNET_NETWORK_fdset_copy_native(gws, &ws, max + 1); + grs = GNUNET_NETWORK_fdset_create (); + gws = GNUNET_NETWORK_fdset_create (); + GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); + GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); /* Schedule task to run when select is ready to read or write */ plugin->client_perform_task = - GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, - timeout, grs, gws, - &client_run, plugin); - GNUNET_NETWORK_fdset_destroy(gws); - GNUNET_NETWORK_fdset_destroy(grs); + GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, + timeout, grs, gws, + &client_run, plugin); + GNUNET_NETWORK_fdset_destroy (gws); + GNUNET_NETWORK_fdset_destroy (grs); return GNUNET_OK; } @@ -638,58 +649,58 @@ client_schedule(struct HTTP_Client_Plugin *plugin, * @return always 0 */ static int -client_log(CURL *curl, - curl_infotype type, - const char *data, - size_t size, - void *cls) +client_log (CURL *curl, + curl_infotype type, + const char *data, + size_t size, + void *cls) { struct RequestHandle *ch = cls; const char *ttype = "UNSPECIFIED"; char text[size + 2]; - if (!((CURLINFO_TEXT == type) || - (CURLINFO_HEADER_IN == type) || - (CURLINFO_HEADER_OUT == type))) + if (! ((CURLINFO_TEXT == type) || + (CURLINFO_HEADER_IN == type) || + (CURLINFO_HEADER_OUT == type))) return 0; switch (type) - { - case CURLINFO_TEXT: - ttype = "TEXT"; - break; - - case CURLINFO_HEADER_IN: - ttype = "HEADER_IN"; - break; - - case CURLINFO_HEADER_OUT: - ttype = "HEADER_OUT"; - /* Overhead*/ - GNUNET_assert(NULL != ch); - GNUNET_assert(NULL != ch->easyhandle); - GNUNET_assert(NULL != ch->s); - ch->s->overhead += size; - break; - - default: - ttype = "UNSPECIFIED"; - break; - } - GNUNET_memcpy(text, data, size); + { + case CURLINFO_TEXT: + ttype = "TEXT"; + break; + + case CURLINFO_HEADER_IN: + ttype = "HEADER_IN"; + break; + + case CURLINFO_HEADER_OUT: + ttype = "HEADER_OUT"; + /* Overhead*/ + GNUNET_assert (NULL != ch); + GNUNET_assert (NULL != ch->easyhandle); + GNUNET_assert (NULL != ch->s); + ch->s->overhead += size; + break; + + default: + ttype = "UNSPECIFIED"; + break; + } + GNUNET_memcpy (text, data, size); if (text[size - 1] == '\n') - { - text[size] = '\0'; - } + { + text[size] = '\0'; + } else - { - text[size] = '\n'; - text[size + 1] = '\0'; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Request %p %s: %s", - ch->easyhandle, - ttype, - text); + { + text[size] = '\n'; + text[size + 1] = '\0'; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Request %p %s: %s", + ch->easyhandle, + ttype, + text); return 0; } #endif @@ -701,7 +712,7 @@ client_log(CURL *curl, * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ static int -client_connect_get(struct GNUNET_ATS_Session *s); +client_connect_get (struct GNUNET_ATS_Session *s); /** @@ -711,7 +722,7 @@ client_connect_get(struct GNUNET_ATS_Session *s); * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success */ static int -client_connect_put(struct GNUNET_ATS_Session *s); +client_connect_put (struct GNUNET_ATS_Session *s); /** @@ -742,86 +753,86 @@ client_connect_put(struct GNUNET_ATS_Session *s); * and does NOT mean that the message was not transmitted (DV) */ static ssize_t -http_client_plugin_send(void *cls, - struct GNUNET_ATS_Session *s, - const char *msgbuf, - size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls) +http_client_plugin_send (void *cls, + struct GNUNET_ATS_Session *s, + const char *msgbuf, + size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { struct HTTP_Client_Plugin *plugin = cls; struct HTTP_Message *msg; char *stat_txt; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: Sending message with %u to peer `%s' \n", - s, - s->put.easyhandle, - msgbuf_size, - GNUNET_i2s(&s->address->peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: Sending message with %u to peer `%s' \n", + s, + s->put.easyhandle, + msgbuf_size, + GNUNET_i2s (&s->address->peer)); /* create new message and schedule */ - msg = GNUNET_malloc(sizeof(struct HTTP_Message) + msgbuf_size); + msg = GNUNET_malloc (sizeof(struct HTTP_Message) + msgbuf_size); msg->size = msgbuf_size; - msg->buf = (char *)&msg[1]; + msg->buf = (char *) &msg[1]; msg->transmit_cont = cont; msg->transmit_cont_cls = cont_cls; - GNUNET_memcpy(msg->buf, - msgbuf, - msgbuf_size); - GNUNET_CONTAINER_DLL_insert_tail(s->msg_head, - s->msg_tail, - msg); + GNUNET_memcpy (msg->buf, + msgbuf, + msgbuf_size); + GNUNET_CONTAINER_DLL_insert_tail (s->msg_head, + s->msg_tail, + msg); s->msgs_in_queue++; s->bytes_in_queue += msg->size; - GNUNET_asprintf(&stat_txt, - "# bytes currently in %s_client buffers", - plugin->protocol); - GNUNET_STATISTICS_update(plugin->env->stats, - stat_txt, msgbuf_size, GNUNET_NO); - GNUNET_free(stat_txt); - notify_session_monitor(plugin, - s, - GNUNET_TRANSPORT_SS_UPDATE); + GNUNET_asprintf (&stat_txt, + "# bytes currently in %s_client buffers", + plugin->protocol); + GNUNET_STATISTICS_update (plugin->env->stats, + stat_txt, msgbuf_size, GNUNET_NO); + GNUNET_free (stat_txt); + notify_session_monitor (plugin, + s, + GNUNET_TRANSPORT_SS_UPDATE); if (H_TMP_DISCONNECTING == s->put.state) - { - /* PUT request is currently getting disconnected */ - s->put.state = H_TMP_RECONNECT_REQUIRED; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: currently disconnecting, reconnecting immediately\n", - s, - s->put.easyhandle); - return msgbuf_size; - } + { + /* PUT request is currently getting disconnected */ + s->put.state = H_TMP_RECONNECT_REQUIRED; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: currently disconnecting, reconnecting immediately\n", + s, + s->put.easyhandle); + return msgbuf_size; + } if (H_PAUSED == s->put.state) - { - /* PUT request was paused, unpause */ - GNUNET_assert(s->put_disconnect_task != NULL); - GNUNET_SCHEDULER_cancel(s->put_disconnect_task); - s->put_disconnect_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: unpausing request\n", - s, s->put.easyhandle); - s->put.state = H_CONNECTED; - if (NULL != s->put.easyhandle) - curl_easy_pause(s->put.easyhandle, CURLPAUSE_CONT); - } + { + /* PUT request was paused, unpause */ + GNUNET_assert (s->put_disconnect_task != NULL); + GNUNET_SCHEDULER_cancel (s->put_disconnect_task); + s->put_disconnect_task = NULL; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: unpausing request\n", + s, s->put.easyhandle); + s->put.state = H_CONNECTED; + if (NULL != s->put.easyhandle) + curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT); + } else if (H_TMP_DISCONNECTED == s->put.state) + { + /* PUT request was disconnected, reconnect */ + LOG (GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s); + GNUNET_break (NULL == s->put.easyhandle); + if (GNUNET_SYSERR == client_connect_put (s)) { - /* PUT request was disconnected, reconnect */ - LOG(GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s); - GNUNET_break(NULL == s->put.easyhandle); - if (GNUNET_SYSERR == client_connect_put(s)) - { - /* Could not reconnect */ - http_client_plugin_session_disconnect(plugin, s); - return GNUNET_SYSERR; - } + /* Could not reconnect */ + http_client_plugin_session_disconnect (plugin, s); + return GNUNET_SYSERR; } - client_schedule(s->plugin, GNUNET_YES); + } + client_schedule (s->plugin, GNUNET_YES); return msgbuf_size; } @@ -834,26 +845,26 @@ http_client_plugin_send(void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -http_client_plugin_session_disconnect(void *cls, - struct GNUNET_ATS_Session *s) +http_client_plugin_session_disconnect (void *cls, + struct GNUNET_ATS_Session *s) { struct HTTP_Client_Plugin *plugin = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p: notifying transport about ending session\n", - s); - plugin->env->session_end(plugin->env->cls, - s->address, - s); - client_delete_session(s); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p: notifying transport about ending session\n", + s); + plugin->env->session_end (plugin->env->cls, + s->address, + s); + client_delete_session (s); /* Re-schedule since handles have changed */ if (NULL != plugin->client_perform_task) - { - GNUNET_SCHEDULER_cancel(plugin->client_perform_task); - plugin->client_perform_task = NULL; - } - client_schedule(plugin, GNUNET_YES); + { + GNUNET_SCHEDULER_cancel (plugin->client_perform_task); + plugin->client_perform_task = NULL; + } + client_schedule (plugin, GNUNET_YES); return GNUNET_OK; } @@ -868,7 +879,7 @@ http_client_plugin_session_disconnect(void *cls, * @return keepalive factor */ static unsigned int -http_client_query_keepalive_factor(void *cls) +http_client_query_keepalive_factor (void *cls) { return 3; } @@ -883,14 +894,14 @@ http_client_query_keepalive_factor(void *cls) * @return #GNUNET_OK (continue iterating) */ static int -destroy_session_cb(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +destroy_session_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct HTTP_Client_Plugin *plugin = cls; struct GNUNET_ATS_Session *session = value; - http_client_plugin_session_disconnect(plugin, session); + http_client_plugin_session_disconnect (plugin, session); return GNUNET_OK; } @@ -904,25 +915,26 @@ destroy_session_cb(void *cls, * @param target peer from which to disconnect */ static void -http_client_plugin_peer_disconnect(void *cls, - const struct GNUNET_PeerIdentity *target) +http_client_plugin_peer_disconnect (void *cls, + const struct GNUNET_PeerIdentity *target) { struct HTTP_Client_Plugin *plugin = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Transport tells me to disconnect `%s'\n", - GNUNET_i2s(target)); - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, - target, - &destroy_session_cb, - plugin); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transport tells me to disconnect `%s'\n", + GNUNET_i2s (target)); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, + target, + &destroy_session_cb, + plugin); } /** * Closure for #session_lookup_client_by_address(). */ -struct GNUNET_ATS_SessionClientCtx { +struct GNUNET_ATS_SessionClientCtx +{ /** * Address we are looking for. */ @@ -944,19 +956,19 @@ struct GNUNET_ATS_SessionClientCtx { * @return #GNUNET_NO if found, #GNUNET_OK if not */ static int -session_lookup_client_by_address(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +session_lookup_client_by_address (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct GNUNET_ATS_SessionClientCtx *sc_ctx = cls; struct GNUNET_ATS_Session *s = value; - if (0 == GNUNET_HELLO_address_cmp(sc_ctx->address, - s->address)) - { - sc_ctx->ret = s; - return GNUNET_NO; - } + if (0 == GNUNET_HELLO_address_cmp (sc_ctx->address, + s->address)) + { + sc_ctx->ret = s; + return GNUNET_NO; + } return GNUNET_YES; } @@ -969,16 +981,16 @@ session_lookup_client_by_address(void *cls, * @return the session or NULL */ static struct GNUNET_ATS_Session * -client_lookup_session(struct HTTP_Client_Plugin *plugin, - const struct GNUNET_HELLO_Address *address) +client_lookup_session (struct HTTP_Client_Plugin *plugin, + const struct GNUNET_HELLO_Address *address) { struct GNUNET_ATS_SessionClientCtx sc_ctx; sc_ctx.address = address; sc_ctx.ret = NULL; - GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, - &session_lookup_client_by_address, - &sc_ctx); + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, + &session_lookup_client_by_address, + &sc_ctx); return sc_ctx.ret; } @@ -991,19 +1003,19 @@ client_lookup_session(struct HTTP_Client_Plugin *plugin, * @param cls the `struct GNUNET_ATS_Session *` with the put */ static void -client_put_disconnect(void *cls) +client_put_disconnect (void *cls) { struct GNUNET_ATS_Session *s = cls; s->put_disconnect_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: will be disconnected due to no activity\n", - s, s->put.easyhandle); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: will be disconnected due to no activity\n", + s, s->put.easyhandle); s->put.state = H_TMP_DISCONNECTING; if (NULL != s->put.easyhandle) - curl_easy_pause(s->put.easyhandle, - CURLPAUSE_CONT); - client_schedule(s->plugin, GNUNET_YES); + curl_easy_pause (s->put.easyhandle, + CURLPAUSE_CONT); + client_schedule (s->plugin, GNUNET_YES); } @@ -1018,10 +1030,10 @@ client_put_disconnect(void *cls) * @return bytes written to stream, returning 0 will terminate request! */ static size_t -client_send_cb(void *stream, - size_t size, - size_t nmemb, - void *cls) +client_send_cb (void *stream, + size_t size, + size_t nmemb, + void *cls) { struct GNUNET_ATS_Session *s = cls; struct HTTP_Client_Plugin *plugin = s->plugin; @@ -1030,90 +1042,90 @@ client_send_cb(void *stream, char *stat_txt; if (H_TMP_DISCONNECTING == s->put.state) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: disconnect due to inactivity\n", - s, s->put.easyhandle); - return 0; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: disconnect due to inactivity\n", + s, s->put.easyhandle); + return 0; + } if (NULL == msg) + { + if (GNUNET_YES == plugin->emulate_xhr) { - if (GNUNET_YES == plugin->emulate_xhr) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: PUT request finished\n", - s, - s->put.easyhandle); - s->put.state = H_TMP_DISCONNECTING; - return 0; - } - - /* We have nothing to send, so pause PUT request */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: nothing to send, suspending\n", - s, - s->put.easyhandle); - s->put_disconnect_task - = GNUNET_SCHEDULER_add_delayed(PUT_DISCONNECT_TIMEOUT, - &client_put_disconnect, - s); - s->put.state = H_PAUSED; - return CURL_READFUNC_PAUSE; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: PUT request finished\n", + s, + s->put.easyhandle); + s->put.state = H_TMP_DISCONNECTING; + return 0; } + + /* We have nothing to send, so pause PUT request */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: nothing to send, suspending\n", + s, + s->put.easyhandle); + s->put_disconnect_task + = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT, + &client_put_disconnect, + s); + s->put.state = H_PAUSED; + return CURL_READFUNC_PAUSE; + } /* data to send */ - GNUNET_assert(msg->pos < msg->size); + GNUNET_assert (msg->pos < msg->size); /* calculate how much fits in buffer */ - len = GNUNET_MIN(msg->size - msg->pos, - size * nmemb); - GNUNET_memcpy(stream, - &msg->buf[msg->pos], - len); + len = GNUNET_MIN (msg->size - msg->pos, + size * nmemb); + GNUNET_memcpy (stream, + &msg->buf[msg->pos], + len); msg->pos += len; if (msg->pos == msg->size) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n", - s, - s->put.easyhandle, - msg->size, - msg->pos); - /* Calling transmit continuation */ - GNUNET_CONTAINER_DLL_remove(s->msg_head, - s->msg_tail, - msg); - GNUNET_assert(0 < s->msgs_in_queue); - s->msgs_in_queue--; - GNUNET_assert(msg->size <= s->bytes_in_queue); - s->bytes_in_queue -= msg->size; - if (NULL != msg->transmit_cont) - msg->transmit_cont(msg->transmit_cont_cls, - &s->address->peer, - GNUNET_OK, - msg->size, - msg->size + s->overhead); - s->overhead = 0; - GNUNET_free(msg); - } - notify_session_monitor(plugin, - s, - GNUNET_TRANSPORT_SS_UPDATE); - GNUNET_asprintf(&stat_txt, - "# bytes currently in %s_client buffers", - plugin->protocol); - GNUNET_STATISTICS_update(plugin->env->stats, - stat_txt, - -len, - GNUNET_NO); - GNUNET_free(stat_txt); - GNUNET_asprintf(&stat_txt, - "# bytes transmitted via %s_client", - plugin->protocol); - GNUNET_STATISTICS_update(plugin->env->stats, - stat_txt, - len, - GNUNET_NO); - GNUNET_free(stat_txt); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n", + s, + s->put.easyhandle, + msg->size, + msg->pos); + /* Calling transmit continuation */ + GNUNET_CONTAINER_DLL_remove (s->msg_head, + s->msg_tail, + msg); + GNUNET_assert (0 < s->msgs_in_queue); + s->msgs_in_queue--; + GNUNET_assert (msg->size <= s->bytes_in_queue); + s->bytes_in_queue -= msg->size; + if (NULL != msg->transmit_cont) + msg->transmit_cont (msg->transmit_cont_cls, + &s->address->peer, + GNUNET_OK, + msg->size, + msg->size + s->overhead); + s->overhead = 0; + GNUNET_free (msg); + } + notify_session_monitor (plugin, + s, + GNUNET_TRANSPORT_SS_UPDATE); + GNUNET_asprintf (&stat_txt, + "# bytes currently in %s_client buffers", + plugin->protocol); + GNUNET_STATISTICS_update (plugin->env->stats, + stat_txt, + -len, + GNUNET_NO); + GNUNET_free (stat_txt); + GNUNET_asprintf (&stat_txt, + "# bytes transmitted via %s_client", + plugin->protocol); + GNUNET_STATISTICS_update (plugin->env->stats, + stat_txt, + len, + GNUNET_NO); + GNUNET_free (stat_txt); return len; } @@ -1124,26 +1136,26 @@ client_send_cb(void *stream, * @param cls the session */ static void -client_wake_up(void *cls) +client_wake_up (void *cls) { struct GNUNET_ATS_Session *s = cls; s->recv_wakeup_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: Waking up GET handle\n", - s, s->get.easyhandle); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: Waking up GET handle\n", + s, s->get.easyhandle); if (H_PAUSED == s->put.state) - { - /* PUT request was paused, unpause */ - GNUNET_assert(s->put_disconnect_task != NULL); - GNUNET_SCHEDULER_cancel(s->put_disconnect_task); - s->put_disconnect_task = NULL; - s->put.state = H_CONNECTED; - if (NULL != s->put.easyhandle) - curl_easy_pause(s->put.easyhandle, CURLPAUSE_CONT); - } + { + /* PUT request was paused, unpause */ + GNUNET_assert (s->put_disconnect_task != NULL); + GNUNET_SCHEDULER_cancel (s->put_disconnect_task); + s->put_disconnect_task = NULL; + s->put.state = H_CONNECTED; + if (NULL != s->put.easyhandle) + curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT); + } if (NULL != s->get.easyhandle) - curl_easy_pause(s->get.easyhandle, CURLPAUSE_CONT); + curl_easy_pause (s->get.easyhandle, CURLPAUSE_CONT); } @@ -1155,8 +1167,8 @@ client_wake_up(void *cls) * @return always #GNUNET_OK */ static int -client_receive_mst_cb(void *cls, - const struct GNUNET_MessageHeader *message) +client_receive_mst_cb (void *cls, + const struct GNUNET_MessageHeader *message) { struct GNUNET_ATS_Session *s = cls; struct HTTP_Client_Plugin *plugin; @@ -1164,32 +1176,32 @@ client_receive_mst_cb(void *cls, char *stat_txt; plugin = s->plugin; - delay = s->plugin->env->receive(plugin->env->cls, - s->address, - s, - message); - GNUNET_asprintf(&stat_txt, - "# bytes received via %s_client", - plugin->protocol); - GNUNET_STATISTICS_update(plugin->env->stats, - stat_txt, - ntohs(message->size), - GNUNET_NO); - GNUNET_free(stat_txt); - - s->next_receive = GNUNET_TIME_relative_to_absolute(delay); - if (GNUNET_TIME_absolute_get().abs_value_us < s->next_receive.abs_value_us) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client: peer `%s' address `%s' next read delayed for %s\n", - GNUNET_i2s(&s->address->peer), - http_common_plugin_address_to_string(s->plugin->protocol, + delay = s->plugin->env->receive (plugin->env->cls, + s->address, + s, + message); + GNUNET_asprintf (&stat_txt, + "# bytes received via %s_client", + plugin->protocol); + GNUNET_STATISTICS_update (plugin->env->stats, + stat_txt, + ntohs (message->size), + GNUNET_NO); + GNUNET_free (stat_txt); + + s->next_receive = GNUNET_TIME_relative_to_absolute (delay); + if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client: peer `%s' address `%s' next read delayed for %s\n", + GNUNET_i2s (&s->address->peer), + http_common_plugin_address_to_string (s->plugin->protocol, s->address->address, s->address->address_length), - GNUNET_STRINGS_relative_time_to_string(delay, + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); - } - client_reschedule_session_timeout(s); + } + client_reschedule_session_timeout (s); return GNUNET_OK; } @@ -1205,10 +1217,10 @@ client_receive_mst_cb(void *cls, * @return bytes read from stream */ static size_t -client_receive_put(void *stream, - size_t size, - size_t nmemb, - void *cls) +client_receive_put (void *stream, + size_t size, + size_t nmemb, + void *cls) { return size * nmemb; } @@ -1225,53 +1237,53 @@ client_receive_put(void *stream, * @return bytes read from stream */ static size_t -client_receive(void *stream, - size_t size, - size_t nmemb, - void *cls) +client_receive (void *stream, + size_t size, + size_t nmemb, + void *cls) { struct GNUNET_ATS_Session *s = cls; struct GNUNET_TIME_Absolute now; size_t len = size * nmemb; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p / request %p: Received %u bytes from peer `%s'\n", - s, - s->get.easyhandle, - len, - GNUNET_i2s(&s->address->peer)); - now = GNUNET_TIME_absolute_get(); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p / request %p: Received %u bytes from peer `%s'\n", + s, + s->get.easyhandle, + len, + GNUNET_i2s (&s->address->peer)); + now = GNUNET_TIME_absolute_get (); if (now.abs_value_us < s->next_receive.abs_value_us) - { - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); - struct GNUNET_TIME_Relative delta - = GNUNET_TIME_absolute_get_difference(now, s->next_receive); - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n", - s, - s->get.easyhandle, - GNUNET_STRINGS_relative_time_to_string(delta, + { + struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + struct GNUNET_TIME_Relative delta + = GNUNET_TIME_absolute_get_difference (now, s->next_receive); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n", + s, + s->get.easyhandle, + GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES)); - if (s->recv_wakeup_task != NULL) - { - GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); - s->recv_wakeup_task = NULL; - } - s->recv_wakeup_task - = GNUNET_SCHEDULER_add_delayed(delta, - &client_wake_up, - s); - return CURL_WRITEFUNC_PAUSE; + if (s->recv_wakeup_task != NULL) + { + GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); + s->recv_wakeup_task = NULL; } + s->recv_wakeup_task + = GNUNET_SCHEDULER_add_delayed (delta, + &client_wake_up, + s); + return CURL_WRITEFUNC_PAUSE; + } if (NULL == s->msg_tk) - s->msg_tk = GNUNET_MST_create(&client_receive_mst_cb, - s); - GNUNET_MST_from_buffer(s->msg_tk, - stream, - len, - GNUNET_NO, - GNUNET_NO); + s->msg_tk = GNUNET_MST_create (&client_receive_mst_cb, + s); + GNUNET_MST_from_buffer (s->msg_tk, + stream, + len, + GNUNET_NO, + GNUNET_NO); return len; } @@ -1282,7 +1294,7 @@ client_receive(void *stream, * @param cls plugin as closure */ static void -client_run(void *cls) +client_run (void *cls) { struct HTTP_Client_Plugin *plugin = cls; int running; @@ -1295,141 +1307,144 @@ client_run(void *cls) plugin->client_perform_task = NULL; /* While data are available or timeouts occured */ do + { + running = 0; + /* Perform operations for all handles */ + mret = curl_multi_perform (plugin->curl_multi_handle, &running); + + /* Get additional information for all handles */ + while (NULL != (msg = curl_multi_info_read (plugin->curl_multi_handle, + &msgs_left))) { - running = 0; - /* Perform operations for all handles */ - mret = curl_multi_perform(plugin->curl_multi_handle, &running); + CURL *easy_h = msg->easy_handle; + struct GNUNET_ATS_Session *s = NULL; + char *d = NULL; /* curl requires 'd' to be a 'char *' */ + + GNUNET_assert (NULL != easy_h); + + /* Obtain session from easy handle */ + GNUNET_assert (CURLE_OK == curl_easy_getinfo (easy_h, CURLINFO_PRIVATE, + &d)); + s = (struct GNUNET_ATS_Session *) d; + GNUNET_assert (NULL != s); + + if (msg->msg != CURLMSG_DONE) + continue; /* This should not happen */ + + /* Get HTTP response code */ + GNUNET_break (CURLE_OK == curl_easy_getinfo (easy_h, + CURLINFO_RESPONSE_CODE, + &http_statuscode)); + + if (easy_h == s->put.easyhandle) + put_request = GNUNET_YES; + else + put_request = GNUNET_NO; + + /* Log status of terminated request */ + if ((0 != msg->data.result) || (http_statuscode != 200)) + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n", + s, msg->easy_handle, + (GNUNET_YES == put_request) ? "PUT" : "GET", + GNUNET_i2s (&s->address->peer), + http_statuscode, + msg->data.result, + curl_easy_strerror (msg->data.result)); + else + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: %s request to `%s' ended normal\n", + s, msg->easy_handle, + (GNUNET_YES == put_request) ? "PUT" : "GET", + GNUNET_i2s (&s->address->peer)); + + /* Remove easy handle from multi handle */ + curl_multi_remove_handle (plugin->curl_multi_handle, easy_h); + + /* Clean up easy handle */ + curl_easy_cleanup (easy_h); + + /* Remove information */ + GNUNET_assert (plugin->cur_requests > 0); + plugin->cur_requests--; + LOG (GNUNET_ERROR_TYPE_INFO, + "%s request to %s done, number of requests decreased to %u\n", + (GNUNET_YES == put_request) ? "PUT" : "GET", + s->url, + plugin->cur_requests); - /* Get additional information for all handles */ - while (NULL != (msg = curl_multi_info_read(plugin->curl_multi_handle, &msgs_left))) + if (GNUNET_YES == put_request) + { + /* Clean up a PUT request */ + s->put.easyhandle = NULL; + s->put.s = NULL; + + switch (s->put.state) + { + case H_NOT_CONNECTED: + case H_DISCONNECTED: + case H_TMP_DISCONNECTED: + /* This must not happen */ + GNUNET_break (0); + break; + + case H_TMP_RECONNECT_REQUIRED: + /* Transport called send while disconnect in progess, reconnect */ + if (GNUNET_SYSERR == client_connect_put (s)) + { + /* Reconnect failed, disconnect session */ + http_client_plugin_session_disconnect (plugin, s); + } + break; + + case H_TMP_DISCONNECTING: + /* PUT gets temporarily disconnected */ + s->put.state = H_TMP_DISCONNECTED; + break; + + case H_PAUSED: + case H_CONNECTED: + /* PUT gets permanently disconnected */ + s->put.state = H_DISCONNECTED; + http_client_plugin_session_disconnect (plugin, s); + break; + + default: + GNUNET_break (0); + break; + } + } + else if (GNUNET_NO == put_request) + { + /* Clean up a GET request */ + s->get.easyhandle = NULL; + s->get.s = NULL; + + /* If we are emulating an XHR client we need to make another GET + * request. + */ + if (GNUNET_YES == plugin->emulate_xhr) + { + if (GNUNET_SYSERR == client_connect_get (s)) + http_client_plugin_session_disconnect (plugin, s); + } + else { - CURL *easy_h = msg->easy_handle; - struct GNUNET_ATS_Session *s = NULL; - char *d = NULL; /* curl requires 'd' to be a 'char *' */ - - GNUNET_assert(NULL != easy_h); - - /* Obtain session from easy handle */ - GNUNET_assert(CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &d)); - s = (struct GNUNET_ATS_Session *)d; - GNUNET_assert(NULL != s); - - if (msg->msg != CURLMSG_DONE) - continue; /* This should not happen */ - - /* Get HTTP response code */ - GNUNET_break(CURLE_OK == curl_easy_getinfo(easy_h, - CURLINFO_RESPONSE_CODE, &http_statuscode)); - - if (easy_h == s->put.easyhandle) - put_request = GNUNET_YES; - else - put_request = GNUNET_NO; - - /* Log status of terminated request */ - if ((0 != msg->data.result) || (http_statuscode != 200)) - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n", - s, msg->easy_handle, - (GNUNET_YES == put_request) ? "PUT" : "GET", - GNUNET_i2s(&s->address->peer), - http_statuscode, - msg->data.result, - curl_easy_strerror(msg->data.result)); - else - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: %s request to `%s' ended normal\n", - s, msg->easy_handle, - (GNUNET_YES == put_request) ? "PUT" : "GET", - GNUNET_i2s(&s->address->peer)); - - /* Remove easy handle from multi handle */ - curl_multi_remove_handle(plugin->curl_multi_handle, easy_h); - - /* Clean up easy handle */ - curl_easy_cleanup(easy_h); - - /* Remove information */ - GNUNET_assert(plugin->cur_requests > 0); - plugin->cur_requests--; - LOG(GNUNET_ERROR_TYPE_INFO, - "%s request to %s done, number of requests decreased to %u\n", - (GNUNET_YES == put_request) ? "PUT" : "GET", - s->url, - plugin->cur_requests); - - if (GNUNET_YES == put_request) - { - /* Clean up a PUT request */ - s->put.easyhandle = NULL; - s->put.s = NULL; - - switch (s->put.state) - { - case H_NOT_CONNECTED: - case H_DISCONNECTED: - case H_TMP_DISCONNECTED: - /* This must not happen */ - GNUNET_break(0); - break; - - case H_TMP_RECONNECT_REQUIRED: - /* Transport called send while disconnect in progess, reconnect */ - if (GNUNET_SYSERR == client_connect_put(s)) - { - /* Reconnect failed, disconnect session */ - http_client_plugin_session_disconnect(plugin, s); - } - break; - - case H_TMP_DISCONNECTING: - /* PUT gets temporarily disconnected */ - s->put.state = H_TMP_DISCONNECTED; - break; - - case H_PAUSED: - case H_CONNECTED: - /* PUT gets permanently disconnected */ - s->put.state = H_DISCONNECTED; - http_client_plugin_session_disconnect(plugin, s); - break; - - default: - GNUNET_break(0); - break; - } - } - else if (GNUNET_NO == put_request) - { - /* Clean up a GET request */ - s->get.easyhandle = NULL; - s->get.s = NULL; - - /* If we are emulating an XHR client we need to make another GET - * request. - */ - if (GNUNET_YES == plugin->emulate_xhr) - { - if (GNUNET_SYSERR == client_connect_get(s)) - http_client_plugin_session_disconnect(plugin, s); - } - else - { - /* GET request was terminated, so disconnect session */ - http_client_plugin_session_disconnect(plugin, s); - } - } - else - GNUNET_break(0); /* Must not happen */ - - GNUNET_STATISTICS_set(plugin->env->stats, - HTTP_STAT_STR_CONNECTIONS, - plugin->cur_requests, - GNUNET_NO); + /* GET request was terminated, so disconnect session */ + http_client_plugin_session_disconnect (plugin, s); } + } + else + GNUNET_break (0); /* Must not happen */ + + GNUNET_STATISTICS_set (plugin->env->stats, + HTTP_STAT_STR_CONNECTIONS, + plugin->cur_requests, + GNUNET_NO); } + } while (mret == CURLM_CALL_MULTI_PERFORM); - client_schedule(plugin, GNUNET_NO); + client_schedule (plugin, GNUNET_NO); } @@ -1443,51 +1458,51 @@ client_run(void *cls) * @return opened socket */ static curl_socket_t -open_tcp_stealth_socket_cb(void *clientp, - curlsocktype purpose, - struct curl_sockaddr *address) +open_tcp_stealth_socket_cb (void *clientp, + curlsocktype purpose, + struct curl_sockaddr *address) { struct GNUNET_ATS_Session *s = clientp; int ret; switch (purpose) + { + case CURLSOCKTYPE_IPCXN: + ret = socket (address->family, + address->socktype, + address->protocol); + if (-1 == ret) + return CURL_SOCKET_BAD; + if (((SOCK_STREAM != address->socktype) || + ((0 != address->protocol) && + (IPPROTO_TCP != address->protocol)))) + return (curl_socket_t) ret; + if ((0 != setsockopt (ret, + IPPROTO_TCP, + TCP_STEALTH, + &s->address->peer, + sizeof(struct GNUNET_PeerIdentity)))) { - case CURLSOCKTYPE_IPCXN: - ret = socket(address->family, - address->socktype, - address->protocol); - if (-1 == ret) - return CURL_SOCKET_BAD; - if (((SOCK_STREAM != address->socktype) || - ((0 != address->protocol) && - (IPPROTO_TCP != address->protocol)))) - return (curl_socket_t)ret; - if ((0 != setsockopt(ret, - IPPROTO_TCP, - TCP_STEALTH, - &s->address->peer, - sizeof(struct GNUNET_PeerIdentity)))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("TCP_STEALTH not supported on this platform.\n")); - (void)close(ret); - return CURL_SOCKET_BAD; - } - return (curl_socket_t)ret; - - case CURLSOCKTYPE_ACCEPT: - GNUNET_break(0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("TCP_STEALTH not supported on this platform.\n")); + (void) close (ret); return CURL_SOCKET_BAD; - break; + } + return (curl_socket_t) ret; - case CURLSOCKTYPE_LAST: - GNUNET_break(0); - return CURL_SOCKET_BAD; + case CURLSOCKTYPE_ACCEPT: + GNUNET_break (0); + return CURL_SOCKET_BAD; + break; - default: - GNUNET_break(0); - return CURL_SOCKET_BAD; - } + case CURLSOCKTYPE_LAST: + GNUNET_break (0); + return CURL_SOCKET_BAD; + + default: + GNUNET_break (0); + return CURL_SOCKET_BAD; + } } #endif @@ -1499,175 +1514,177 @@ open_tcp_stealth_socket_cb(void *clientp, * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ static int -client_connect_get(struct GNUNET_ATS_Session *s) +client_connect_get (struct GNUNET_ATS_Session *s) { CURLMcode mret; struct HttpAddress *ha; uint32_t options; - ha = (struct HttpAddress *)s->address->address; - options = ntohl(ha->options); + ha = (struct HttpAddress *) s->address->address; + options = ntohl (ha->options); /* create get request */ - s->get.easyhandle = curl_easy_init(); + s->get.easyhandle = curl_easy_init (); s->get.s = s; if (0 != (options & HTTP_OPTIONS_TCP_STEALTH)) - { + { #ifdef TCP_STEALTH - curl_easy_setopt(s->get.easyhandle, - CURLOPT_OPENSOCKETFUNCTION, - &open_tcp_stealth_socket_cb); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_OPENSOCKETDATA, - s); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_OPENSOCKETFUNCTION, + &open_tcp_stealth_socket_cb); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_OPENSOCKETDATA, + s); #else - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cannot connect, TCP STEALTH needed and not supported by kernel.\n"); - curl_easy_cleanup(s->get.easyhandle); - s->get.easyhandle = NULL; - s->get.s = NULL; - return GNUNET_SYSERR; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cannot connect, TCP STEALTH needed and not supported by kernel.\n"); + curl_easy_cleanup (s->get.easyhandle); + s->get.easyhandle = NULL; + s->get.s = NULL; + return GNUNET_SYSERR; #endif - } + } #if VERBOSE_CURL - curl_easy_setopt(s->get.easyhandle, - CURLOPT_VERBOSE, - 1L); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_DEBUGFUNCTION, - &client_log); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_DEBUGDATA, - &s->get); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_VERBOSE, + 1L); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_DEBUGFUNCTION, + &client_log); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_DEBUGDATA, + &s->get); #endif #if BUILD_HTTPS - curl_easy_setopt(s->get.easyhandle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); + curl_easy_setopt (s->get.easyhandle, CURLOPT_SSLVERSION, + CURL_SSLVERSION_TLSv1); { if (HTTP_OPTIONS_VERIFY_CERTIFICATE == (options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) - { - curl_easy_setopt(s->get.easyhandle, - CURLOPT_SSL_VERIFYPEER, 1L); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_SSL_VERIFYHOST, - 2L); - } + { + curl_easy_setopt (s->get.easyhandle, + CURLOPT_SSL_VERIFYPEER, 1L); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_SSL_VERIFYHOST, + 2L); + } else - { - curl_easy_setopt(s->get.easyhandle, - CURLOPT_SSL_VERIFYPEER, - 0L); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_SSL_VERIFYHOST, - 0L); - } + { + curl_easy_setopt (s->get.easyhandle, + CURLOPT_SSL_VERIFYPEER, + 0L); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_SSL_VERIFYHOST, + 0L); + } } - curl_easy_setopt(s->get.easyhandle, - CURLOPT_PROTOCOLS, - CURLPROTO_HTTPS); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_REDIR_PROTOCOLS, - CURLPROTO_HTTPS); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_PROTOCOLS, + CURLPROTO_HTTPS); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_REDIR_PROTOCOLS, + CURLPROTO_HTTPS); #else - curl_easy_setopt(s->get.easyhandle, - CURLOPT_PROTOCOLS, - CURLPROTO_HTTP); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_REDIR_PROTOCOLS, - CURLPROTO_HTTP); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_PROTOCOLS, + CURLPROTO_HTTP); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_REDIR_PROTOCOLS, + CURLPROTO_HTTP); #endif if (NULL != s->plugin->proxy_hostname) - { - curl_easy_setopt(s->get.easyhandle, - CURLOPT_PROXY, - s->plugin->proxy_hostname); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_PROXYTYPE, - s->plugin->proxytype); - if (NULL != s->plugin->proxy_username) - curl_easy_setopt(s->get.easyhandle, - CURLOPT_PROXYUSERNAME, - s->plugin->proxy_username); - if (NULL != s->plugin->proxy_password) - curl_easy_setopt(s->get.easyhandle, - CURLOPT_PROXYPASSWORD, - s->plugin->proxy_password); - if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) - curl_easy_setopt(s->get.easyhandle, - CURLOPT_HTTPPROXYTUNNEL, - s->plugin->proxy_use_httpproxytunnel); - } + { + curl_easy_setopt (s->get.easyhandle, + CURLOPT_PROXY, + s->plugin->proxy_hostname); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_PROXYTYPE, + s->plugin->proxytype); + if (NULL != s->plugin->proxy_username) + curl_easy_setopt (s->get.easyhandle, + CURLOPT_PROXYUSERNAME, + s->plugin->proxy_username); + if (NULL != s->plugin->proxy_password) + curl_easy_setopt (s->get.easyhandle, + CURLOPT_PROXYPASSWORD, + s->plugin->proxy_password); + if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) + curl_easy_setopt (s->get.easyhandle, + CURLOPT_HTTPPROXYTUNNEL, + s->plugin->proxy_use_httpproxytunnel); + } if (GNUNET_YES == s->plugin->emulate_xhr) - { - char *url; - - GNUNET_asprintf(&url, - "%s,1", - s->url); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_URL, - url); - GNUNET_free(url); - } + { + char *url; + + GNUNET_asprintf (&url, + "%s,1", + s->url); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_URL, + url); + GNUNET_free (url); + } else - { - curl_easy_setopt(s->get.easyhandle, - CURLOPT_URL, - s->url); - } - curl_easy_setopt(s->get.easyhandle, - CURLOPT_READFUNCTION, - &client_send_cb); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_READDATA, - s); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_WRITEFUNCTION, - &client_receive); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_WRITEDATA, - s); + { + curl_easy_setopt (s->get.easyhandle, + CURLOPT_URL, + s->url); + } + curl_easy_setopt (s->get.easyhandle, + CURLOPT_READFUNCTION, + &client_send_cb); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_READDATA, + s); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_WRITEFUNCTION, + &client_receive); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_WRITEDATA, + s); /* No timeout by default, timeout done with session timeout */ - curl_easy_setopt(s->get.easyhandle, - CURLOPT_TIMEOUT, - 0L); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_PRIVATE, s); - curl_easy_setopt(s->get.easyhandle, - CURLOPT_CONNECTTIMEOUT_MS, - (long)(HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL)); - curl_easy_setopt(s->get.easyhandle, CURLOPT_BUFFERSIZE, - 2 * GNUNET_MAX_MESSAGE_SIZE); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_TIMEOUT, + 0L); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_PRIVATE, s); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_CONNECTTIMEOUT_MS, + (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us + / 1000LL)); + curl_easy_setopt (s->get.easyhandle, CURLOPT_BUFFERSIZE, + 2 * GNUNET_MAX_MESSAGE_SIZE); #if CURL_TCP_NODELAY - curl_easy_setopt(ps->recv_endpoint, - CURLOPT_TCP_NODELAY, - 1L); + curl_easy_setopt (ps->recv_endpoint, + CURLOPT_TCP_NODELAY, + 1L); #endif - curl_easy_setopt(s->get.easyhandle, - CURLOPT_FOLLOWLOCATION, - 0L); + curl_easy_setopt (s->get.easyhandle, + CURLOPT_FOLLOWLOCATION, + 0L); - mret = curl_multi_add_handle(s->plugin->curl_multi_handle, - s->get.easyhandle); + mret = curl_multi_add_handle (s->plugin->curl_multi_handle, + s->get.easyhandle); if (CURLM_OK != mret) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Session %p : Failed to add GET handle to multihandle: `%s'\n", - s, - curl_multi_strerror(mret)); - curl_easy_cleanup(s->get.easyhandle); - s->get.easyhandle = NULL; - s->get.s = NULL; - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Session %p : Failed to add GET handle to multihandle: `%s'\n", + s, + curl_multi_strerror (mret)); + curl_easy_cleanup (s->get.easyhandle); + s->get.easyhandle = NULL; + s->get.s = NULL; + GNUNET_break (0); + return GNUNET_SYSERR; + } s->plugin->cur_requests++; - LOG(GNUNET_ERROR_TYPE_INFO, - "GET request `%s' established, number of requests increased to %u\n", - s->url, - s->plugin->cur_requests); + LOG (GNUNET_ERROR_TYPE_INFO, + "GET request `%s' established, number of requests increased to %u\n", + s->url, + s->plugin->cur_requests); return GNUNET_OK; } @@ -1679,166 +1696,167 @@ client_connect_get(struct GNUNET_ATS_Session *s) * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok */ static int -client_connect_put(struct GNUNET_ATS_Session *s) +client_connect_put (struct GNUNET_ATS_Session *s) { CURLMcode mret; struct HttpAddress *ha; uint32_t options; - ha = (struct HttpAddress *)s->address->address; - options = ntohl(ha->options); + ha = (struct HttpAddress *) s->address->address; + options = ntohl (ha->options); /* create put request */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p: Init PUT handle\n", - s); - s->put.easyhandle = curl_easy_init(); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p: Init PUT handle\n", + s); + s->put.easyhandle = curl_easy_init (); s->put.s = s; #if VERBOSE_CURL - curl_easy_setopt(s->put.easyhandle, - CURLOPT_VERBOSE, - 1L); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_DEBUGFUNCTION, - &client_log); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_DEBUGDATA, - &s->put); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_VERBOSE, + 1L); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_DEBUGFUNCTION, + &client_log); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_DEBUGDATA, + &s->put); #endif if (0 != (options & HTTP_OPTIONS_TCP_STEALTH)) - { + { #ifdef TCP_STEALTH - curl_easy_setopt(s->put.easyhandle, - CURLOPT_OPENSOCKETFUNCTION, - &open_tcp_stealth_socket_cb); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_OPENSOCKETDATA, - s); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_OPENSOCKETFUNCTION, + &open_tcp_stealth_socket_cb); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_OPENSOCKETDATA, + s); #else - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Cannot connect, TCP STEALTH needed and not supported by kernel.\n"); - curl_easy_cleanup(s->put.easyhandle); - s->put.easyhandle = NULL; - s->put.s = NULL; - s->put.state = H_DISCONNECTED; - return GNUNET_SYSERR; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cannot connect, TCP STEALTH needed and not supported by kernel.\n"); + curl_easy_cleanup (s->put.easyhandle); + s->put.easyhandle = NULL; + s->put.s = NULL; + s->put.state = H_DISCONNECTED; + return GNUNET_SYSERR; #endif - } + } #if BUILD_HTTPS - curl_easy_setopt(s->put.easyhandle, - CURLOPT_SSLVERSION, - CURL_SSLVERSION_TLSv1); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_SSLVERSION, + CURL_SSLVERSION_TLSv1); { struct HttpAddress *ha; - ha = (struct HttpAddress *)s->address->address; + ha = (struct HttpAddress *) s->address->address; if (HTTP_OPTIONS_VERIFY_CERTIFICATE == - (ntohl(ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) - { - curl_easy_setopt(s->put.easyhandle, - CURLOPT_SSL_VERIFYPEER, - 1L); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_SSL_VERIFYHOST, - 2L); - } + (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) + { + curl_easy_setopt (s->put.easyhandle, + CURLOPT_SSL_VERIFYPEER, + 1L); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_SSL_VERIFYHOST, + 2L); + } else - { - curl_easy_setopt(s->put.easyhandle, - CURLOPT_SSL_VERIFYPEER, - 0L); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_SSL_VERIFYHOST, - 0L); - } + { + curl_easy_setopt (s->put.easyhandle, + CURLOPT_SSL_VERIFYPEER, + 0L); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_SSL_VERIFYHOST, + 0L); + } } - curl_easy_setopt(s->put.easyhandle, - CURLOPT_PROTOCOLS, - CURLPROTO_HTTPS); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_REDIR_PROTOCOLS, - CURLPROTO_HTTPS); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_PROTOCOLS, + CURLPROTO_HTTPS); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_REDIR_PROTOCOLS, + CURLPROTO_HTTPS); #else - curl_easy_setopt(s->put.easyhandle, - CURLOPT_PROTOCOLS, - CURLPROTO_HTTP); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_REDIR_PROTOCOLS, - CURLPROTO_HTTP); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_PROTOCOLS, + CURLPROTO_HTTP); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_REDIR_PROTOCOLS, + CURLPROTO_HTTP); #endif if (NULL != s->plugin->proxy_hostname) - { - curl_easy_setopt(s->put.easyhandle, - CURLOPT_PROXY, - s->plugin->proxy_hostname); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_PROXYTYPE, - s->plugin->proxytype); - if (NULL != s->plugin->proxy_username) - curl_easy_setopt(s->put.easyhandle, - CURLOPT_PROXYUSERNAME, - s->plugin->proxy_username); - if (NULL != s->plugin->proxy_password) - curl_easy_setopt(s->put.easyhandle, - CURLOPT_PROXYPASSWORD, - s->plugin->proxy_password); - if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) - curl_easy_setopt(s->put.easyhandle, - CURLOPT_HTTPPROXYTUNNEL, - s->plugin->proxy_use_httpproxytunnel); - } + { + curl_easy_setopt (s->put.easyhandle, + CURLOPT_PROXY, + s->plugin->proxy_hostname); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_PROXYTYPE, + s->plugin->proxytype); + if (NULL != s->plugin->proxy_username) + curl_easy_setopt (s->put.easyhandle, + CURLOPT_PROXYUSERNAME, + s->plugin->proxy_username); + if (NULL != s->plugin->proxy_password) + curl_easy_setopt (s->put.easyhandle, + CURLOPT_PROXYPASSWORD, + s->plugin->proxy_password); + if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) + curl_easy_setopt (s->put.easyhandle, + CURLOPT_HTTPPROXYTUNNEL, + s->plugin->proxy_use_httpproxytunnel); + } - curl_easy_setopt(s->put.easyhandle, - CURLOPT_URL, - s->url); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_UPLOAD, - 1L); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_READFUNCTION, - &client_send_cb); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_READDATA, - s); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_WRITEFUNCTION, - &client_receive_put); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_WRITEDATA, - s); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_URL, + s->url); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_UPLOAD, + 1L); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_READFUNCTION, + &client_send_cb); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_READDATA, + s); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_WRITEFUNCTION, + &client_receive_put); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_WRITEDATA, + s); /* No timeout by default, timeout done with session timeout */ - curl_easy_setopt(s->put.easyhandle, - CURLOPT_TIMEOUT, - 0L); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_PRIVATE, - s); - curl_easy_setopt(s->put.easyhandle, - CURLOPT_CONNECTTIMEOUT_MS, - (long)(HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL)); - curl_easy_setopt(s->put.easyhandle, CURLOPT_BUFFERSIZE, - 2 * GNUNET_MAX_MESSAGE_SIZE); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_TIMEOUT, + 0L); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_PRIVATE, + s); + curl_easy_setopt (s->put.easyhandle, + CURLOPT_CONNECTTIMEOUT_MS, + (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us + / 1000LL)); + curl_easy_setopt (s->put.easyhandle, CURLOPT_BUFFERSIZE, + 2 * GNUNET_MAX_MESSAGE_SIZE); #if CURL_TCP_NODELAY - curl_easy_setopt(s->put.easyhandle, CURLOPT_TCP_NODELAY, 1); + curl_easy_setopt (s->put.easyhandle, CURLOPT_TCP_NODELAY, 1); #endif - mret = curl_multi_add_handle(s->plugin->curl_multi_handle, - s->put.easyhandle); + mret = curl_multi_add_handle (s->plugin->curl_multi_handle, + s->put.easyhandle); if (CURLM_OK != mret) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Session %p : Failed to add PUT handle to multihandle: `%s'\n", - s, curl_multi_strerror(mret)); - curl_easy_cleanup(s->put.easyhandle); - s->put.easyhandle = NULL; - s->put.s = NULL; - s->put.state = H_DISCONNECTED; - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Session %p : Failed to add PUT handle to multihandle: `%s'\n", + s, curl_multi_strerror (mret)); + curl_easy_cleanup (s->put.easyhandle); + s->put.easyhandle = NULL; + s->put.s = NULL; + s->put.state = H_DISCONNECTED; + return GNUNET_SYSERR; + } s->put.state = H_CONNECTED; s->plugin->cur_requests++; - LOG(GNUNET_ERROR_TYPE_INFO, - "PUT request `%s' established, number of requests increased to %u\n", - s->url, s->plugin->cur_requests); + LOG (GNUNET_ERROR_TYPE_INFO, + "PUT request `%s' established, number of requests increased to %u\n", + s->url, s->plugin->cur_requests); return GNUNET_OK; } @@ -1851,67 +1869,67 @@ client_connect_put(struct GNUNET_ATS_Session *s) * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ static int -client_connect(struct GNUNET_ATS_Session *s) +client_connect (struct GNUNET_ATS_Session *s) { struct HTTP_Client_Plugin *plugin = s->plugin; int res = GNUNET_OK; /* create url */ if (NULL == - http_common_plugin_address_to_string(plugin->protocol, - s->address->address, - s->address->address_length)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Invalid address peer `%s'\n", - GNUNET_i2s(&s->address->peer)); - return GNUNET_SYSERR; - } + http_common_plugin_address_to_string (plugin->protocol, + s->address->address, + s->address->address_length)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Invalid address peer `%s'\n", + GNUNET_i2s (&s->address->peer)); + return GNUNET_SYSERR; + } - GNUNET_asprintf(&s->url, - "%s/%s;%u", - http_common_plugin_address_to_url(NULL, - s->address->address, - s->address->address_length), - GNUNET_i2s_full(plugin->env->my_identity), - plugin->last_tag); + GNUNET_asprintf (&s->url, + "%s/%s;%u", + http_common_plugin_address_to_url (NULL, + s->address->address, + s->address->address_length), + GNUNET_i2s_full (plugin->env->my_identity), + plugin->last_tag); plugin->last_tag++; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Initiating outbound session peer `%s' using address `%s'\n", - GNUNET_i2s(&s->address->peer), s->url); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Initiating outbound session peer `%s' using address `%s'\n", + GNUNET_i2s (&s->address->peer), s->url); - if (GNUNET_SYSERR == client_connect_get(s)) + if (GNUNET_SYSERR == client_connect_get (s)) return GNUNET_SYSERR; /* If we are emulating an XHR client then delay sending a PUT request until * there is something to send. */ if (GNUNET_YES == plugin->emulate_xhr) - { - s->put.state = H_TMP_DISCONNECTED; - } - else if (GNUNET_SYSERR == client_connect_put(s)) + { + s->put.state = H_TMP_DISCONNECTED; + } + else if (GNUNET_SYSERR == client_connect_put (s)) return GNUNET_SYSERR; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p: connected with GET %p and PUT %p\n", - s, s->get.easyhandle, - s->put.easyhandle); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p: connected with GET %p and PUT %p\n", + s, s->get.easyhandle, + s->put.easyhandle); /* Perform connect */ - GNUNET_STATISTICS_set(plugin->env->stats, - HTTP_STAT_STR_CONNECTIONS, - plugin->cur_requests, - GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, + HTTP_STAT_STR_CONNECTIONS, + plugin->cur_requests, + GNUNET_NO); /* Re-schedule since handles have changed */ if (NULL != plugin->client_perform_task) - { - GNUNET_SCHEDULER_cancel(plugin->client_perform_task); - plugin->client_perform_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->client_perform_task); + plugin->client_perform_task = NULL; + } /* Schedule task to run immediately */ - plugin->client_perform_task = GNUNET_SCHEDULER_add_now(client_run, - plugin); + plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run, + plugin); return res; } @@ -1924,8 +1942,8 @@ client_connect(struct GNUNET_ATS_Session *s) * @return the network type */ static enum GNUNET_NetworkType -http_client_plugin_get_network(void *cls, - struct GNUNET_ATS_Session *session) +http_client_plugin_get_network (void *cls, + struct GNUNET_ATS_Session *session) { return session->scope; } @@ -1939,13 +1957,14 @@ http_client_plugin_get_network(void *cls, * @return the network type */ static enum GNUNET_NetworkType -http_client_plugin_get_network_for_address(void *cls, - const struct GNUNET_HELLO_Address *address) +http_client_plugin_get_network_for_address (void *cls, + const struct + GNUNET_HELLO_Address *address) { struct HTTP_Client_Plugin *plugin = cls; - return http_common_get_network_for_address(plugin->env, - address); + return http_common_get_network_for_address (plugin->env, + address); } @@ -1955,33 +1974,33 @@ http_client_plugin_get_network_for_address(void *cls, * @param cls the `struct GNUNET_ATS_Session` of the idle session */ static void -client_session_timeout(void *cls) +client_session_timeout (void *cls) { struct GNUNET_ATS_Session *s = cls; struct GNUNET_TIME_Relative left; s->timeout_task = NULL; - left = GNUNET_TIME_absolute_get_remaining(s->timeout); + left = GNUNET_TIME_absolute_get_remaining (s->timeout); if (0 != left.rel_value_us) - { - /* not actually our turn yet, but let's at least update - the monitor, it may think we're about to die ... */ - notify_session_monitor(s->plugin, - s, - GNUNET_TRANSPORT_SS_UPDATE); - s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, - &client_session_timeout, - s); - return; - } - LOG(TIMEOUT_LOG, - "Session %p was idle for %s, disconnecting\n", - s, - GNUNET_STRINGS_relative_time_to_string(HTTP_CLIENT_SESSION_TIMEOUT, - GNUNET_YES)); - GNUNET_assert(GNUNET_OK == - http_client_plugin_session_disconnect(s->plugin, - s)); + { + /* not actually our turn yet, but let's at least update + the monitor, it may think we're about to die ... */ + notify_session_monitor (s->plugin, + s, + GNUNET_TRANSPORT_SS_UPDATE); + s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, + &client_session_timeout, + s); + return; + } + LOG (TIMEOUT_LOG, + "Session %p was idle for %s, disconnecting\n", + s, + GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT, + GNUNET_YES)); + GNUNET_assert (GNUNET_OK == + http_client_plugin_session_disconnect (s->plugin, + s)); } @@ -1994,8 +2013,8 @@ client_session_timeout(void *cls) * @return the session or NULL of max connections exceeded */ static struct GNUNET_ATS_Session * -http_client_plugin_get_session(void *cls, - const struct GNUNET_HELLO_Address *address) +http_client_plugin_get_session (void *cls, + const struct GNUNET_HELLO_Address *address) { struct HTTP_Client_Plugin *plugin = cls; struct GNUNET_ATS_Session *s; @@ -2004,96 +2023,97 @@ http_client_plugin_get_session(void *cls, size_t salen = 0; int res; - GNUNET_assert(NULL != address->address); + GNUNET_assert (NULL != address->address); /* find existing session */ - s = client_lookup_session(plugin, address); + s = client_lookup_session (plugin, address); if (NULL != s) return s; /* create a new session */ if (plugin->max_requests <= plugin->cur_requests) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Maximum number of requests (%u) reached: " - "cannot connect to peer `%s'\n", - plugin->max_requests, - GNUNET_i2s(&address->peer)); - return NULL; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Maximum number of requests (%u) reached: " + "cannot connect to peer `%s'\n", + plugin->max_requests, + GNUNET_i2s (&address->peer)); + return NULL; + } /* Determine network location */ net_type = GNUNET_NT_UNSPECIFIED; - sa = http_common_socket_from_address(address->address, - address->address_length, - &res); + sa = http_common_socket_from_address (address->address, + address->address_length, + &res); if (GNUNET_SYSERR == res) return NULL; if (GNUNET_YES == res) + { + GNUNET_assert (NULL != sa); + if (AF_INET == sa->sa_family) { - GNUNET_assert(NULL != sa); - if (AF_INET == sa->sa_family) - { - salen = sizeof(struct sockaddr_in); - } - else if (AF_INET6 == sa->sa_family) - { - salen = sizeof(struct sockaddr_in6); - } - net_type = plugin->env->get_address_type(plugin->env->cls, sa, salen); - GNUNET_free(sa); + salen = sizeof(struct sockaddr_in); } - else if (GNUNET_NO == res) + else if (AF_INET6 == sa->sa_family) { - /* Cannot convert to sockaddr -> is external hostname */ - net_type = GNUNET_NT_WAN; + salen = sizeof(struct sockaddr_in6); } + net_type = plugin->env->get_address_type (plugin->env->cls, sa, salen); + GNUNET_free (sa); + } + else if (GNUNET_NO == res) + { + /* Cannot convert to sockaddr -> is external hostname */ + net_type = GNUNET_NT_WAN; + } if (GNUNET_NT_UNSPECIFIED == net_type) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } - s = GNUNET_new(struct GNUNET_ATS_Session); + s = GNUNET_new (struct GNUNET_ATS_Session); s->plugin = plugin; - s->address = GNUNET_HELLO_address_copy(address); + s->address = GNUNET_HELLO_address_copy (address); s->scope = net_type; s->put.state = H_NOT_CONNECTED; - s->timeout = GNUNET_TIME_relative_to_absolute(HTTP_CLIENT_SESSION_TIMEOUT); - s->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_CLIENT_SESSION_TIMEOUT, - &client_session_timeout, - s); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Created new session %p for `%s' address `%s''\n", - s, - http_common_plugin_address_to_string(plugin->protocol, - s->address->address, - s->address->address_length), - GNUNET_i2s(&s->address->peer)); + s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_CLIENT_SESSION_TIMEOUT); + s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_CLIENT_SESSION_TIMEOUT, + &client_session_timeout, + s); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Created new session %p for `%s' address `%s''\n", + s, + http_common_plugin_address_to_string (plugin->protocol, + s->address->address, + s->address->address_length), + GNUNET_i2s (&s->address->peer)); /* add new session */ - (void)GNUNET_CONTAINER_multipeermap_put(plugin->sessions, - &s->address->peer, - s, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessions, + &s->address->peer, + s, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); /* initiate new connection */ - if (GNUNET_SYSERR == client_connect(s)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Cannot connect to peer `%s' address `%s''\n", - http_common_plugin_address_to_string(plugin->protocol, - s->address->address, s->address->address_length), - GNUNET_i2s(&s->address->peer)); - client_delete_session(s); - return NULL; - } - notify_session_monitor(plugin, - s, - GNUNET_TRANSPORT_SS_INIT); - notify_session_monitor(plugin, - s, - GNUNET_TRANSPORT_SS_UP); /* or handshake? */ + if (GNUNET_SYSERR == client_connect (s)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Cannot connect to peer `%s' address `%s''\n", + http_common_plugin_address_to_string (plugin->protocol, + s->address->address, + s->address->address_length), + GNUNET_i2s (&s->address->peer)); + client_delete_session (s); + return NULL; + } + notify_session_monitor (plugin, + s, + GNUNET_TRANSPORT_SS_INIT); + notify_session_monitor (plugin, + s, + GNUNET_TRANSPORT_SS_UP); /* or handshake? */ return s; } @@ -2105,18 +2125,19 @@ http_client_plugin_get_session(void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -client_start(struct HTTP_Client_Plugin *plugin) +client_start (struct HTTP_Client_Plugin *plugin) { - curl_global_init(CURL_GLOBAL_ALL); - plugin->curl_multi_handle = curl_multi_init(); + curl_global_init (CURL_GLOBAL_ALL); + plugin->curl_multi_handle = curl_multi_init (); if (NULL == plugin->curl_multi_handle) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Could not initialize curl multi handle, failed to start %s plugin!\n"), - plugin->name); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ( + "Could not initialize curl multi handle, failed to start %s plugin!\n"), + plugin->name); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -2134,9 +2155,9 @@ client_start(struct HTTP_Client_Plugin *plugin) * and transport; always returns #GNUNET_NO (this is the client!) */ static int -http_client_plugin_address_suggested(void *cls, - const void *addr, - size_t addrlen) +http_client_plugin_address_suggested (void *cls, + const void *addr, + size_t addrlen) { /* A HTTP/S client does not have any valid address so:*/ return GNUNET_NO; @@ -2150,43 +2171,43 @@ http_client_plugin_address_suggested(void *cls, * @return NULL */ void * -LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) +LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) { struct GNUNET_TRANSPORT_PluginFunctions *api = cls; struct HTTP_Client_Plugin *plugin = api->cls; if (NULL == api->cls) - { - /* Stub shutdown */ - GNUNET_free(api); - return NULL; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("Shutting down plugin `%s'\n"), - plugin->name); - GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, - &destroy_session_cb, - plugin); + { + /* Stub shutdown */ + GNUNET_free (api); + return NULL; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ("Shutting down plugin `%s'\n"), + plugin->name); + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, + &destroy_session_cb, + plugin); if (NULL != plugin->client_perform_task) - { - GNUNET_SCHEDULER_cancel(plugin->client_perform_task); - plugin->client_perform_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->client_perform_task); + plugin->client_perform_task = NULL; + } if (NULL != plugin->curl_multi_handle) - { - curl_multi_cleanup(plugin->curl_multi_handle); - plugin->curl_multi_handle = NULL; - } - curl_global_cleanup(); - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("Shutdown for plugin `%s' complete\n"), - plugin->name); - GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions); - GNUNET_free_non_null(plugin->proxy_hostname); - GNUNET_free_non_null(plugin->proxy_username); - GNUNET_free_non_null(plugin->proxy_password); - GNUNET_free(plugin); - GNUNET_free(api); + { + curl_multi_cleanup (plugin->curl_multi_handle); + plugin->curl_multi_handle = NULL; + } + curl_global_cleanup (); + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ("Shutdown for plugin `%s' complete\n"), + plugin->name); + GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); + GNUNET_free_non_null (plugin->proxy_hostname); + GNUNET_free_non_null (plugin->proxy_username); + GNUNET_free_non_null (plugin->proxy_password); + GNUNET_free (plugin); + GNUNET_free (api); return NULL; } @@ -2198,115 +2219,116 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -client_configure_plugin(struct HTTP_Client_Plugin *plugin) +client_configure_plugin (struct HTTP_Client_Plugin *plugin) { unsigned long long max_requests; char *proxy_type; /* Optional parameters */ if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg, - plugin->name, - "MAX_CONNECTIONS", - &max_requests)) + GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, + plugin->name, + "MAX_CONNECTIONS", + &max_requests)) max_requests = 128; plugin->max_requests = max_requests; - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("Maximum number of requests is %u\n"), - plugin->max_requests); + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ("Maximum number of requests is %u\n"), + plugin->max_requests); /* Read proxy configuration */ if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, - plugin->name, - "PROXY", - &plugin->proxy_hostname)) + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, + plugin->name, + "PROXY", + &plugin->proxy_hostname)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found proxy host: `%s'\n", + plugin->proxy_hostname); + /* proxy username */ + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, + plugin->name, + "PROXY_USERNAME", + &plugin->proxy_username)) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found proxy host: `%s'\n", - plugin->proxy_hostname); - /* proxy username */ - if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, - plugin->name, - "PROXY_USERNAME", - &plugin->proxy_username)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found proxy username name: `%s'\n", - plugin->proxy_username); - } - - /* proxy password */ - if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, - plugin->name, - "PROXY_PASSWORD", - &plugin->proxy_password)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found proxy password name: `%s'\n", - plugin->proxy_password); - } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found proxy username name: `%s'\n", + plugin->proxy_username); + } - /* proxy type */ - if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, - plugin->name, - "PROXY_TYPE", - &proxy_type)) - { - GNUNET_STRINGS_utf8_toupper(proxy_type, proxy_type); - - if (0 == strcmp(proxy_type, "HTTP")) - plugin->proxytype = CURLPROXY_HTTP; - else if (0 == strcmp(proxy_type, "SOCKS4")) - plugin->proxytype = CURLPROXY_SOCKS4; - else if (0 == strcmp(proxy_type, "SOCKS5")) - plugin->proxytype = CURLPROXY_SOCKS5; - else if (0 == strcmp(proxy_type, "SOCKS4A")) - plugin->proxytype = CURLPROXY_SOCKS4A; - else if (0 == strcmp(proxy_type, "SOCKS5_HOSTNAME ")) - plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME; - else - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), - proxy_type); - - GNUNET_free(proxy_type); - GNUNET_free(plugin->proxy_hostname); - plugin->proxy_hostname = NULL; - GNUNET_free_non_null(plugin->proxy_username); - plugin->proxy_username = NULL; - GNUNET_free_non_null(plugin->proxy_password); - plugin->proxy_password = NULL; - - return GNUNET_SYSERR; - } - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found proxy type: `%s'\n", - proxy_type); - } + /* proxy password */ + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, + plugin->name, + "PROXY_PASSWORD", + &plugin->proxy_password)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found proxy password name: `%s'\n", + plugin->proxy_password); + } - /* proxy http tunneling */ - plugin->proxy_use_httpproxytunnel - = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, + /* proxy type */ + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, - "PROXY_HTTP_TUNNELING"); - if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel) - plugin->proxy_use_httpproxytunnel = GNUNET_NO; + "PROXY_TYPE", + &proxy_type)) + { + GNUNET_STRINGS_utf8_toupper (proxy_type, proxy_type); + + if (0 == strcmp (proxy_type, "HTTP")) + plugin->proxytype = CURLPROXY_HTTP; + else if (0 == strcmp (proxy_type, "SOCKS4")) + plugin->proxytype = CURLPROXY_SOCKS4; + else if (0 == strcmp (proxy_type, "SOCKS5")) + plugin->proxytype = CURLPROXY_SOCKS5; + else if (0 == strcmp (proxy_type, "SOCKS4A")) + plugin->proxytype = CURLPROXY_SOCKS4A; + else if (0 == strcmp (proxy_type, "SOCKS5_HOSTNAME ")) + plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME; + else + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ( + "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), + proxy_type); + + GNUNET_free (proxy_type); + GNUNET_free (plugin->proxy_hostname); + plugin->proxy_hostname = NULL; + GNUNET_free_non_null (plugin->proxy_username); + plugin->proxy_username = NULL; + GNUNET_free_non_null (plugin->proxy_password); + plugin->proxy_password = NULL; + + return GNUNET_SYSERR; + } - GNUNET_free_non_null(proxy_type); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found proxy type: `%s'\n", + proxy_type); } + /* proxy http tunneling */ + plugin->proxy_use_httpproxytunnel + = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, + plugin->name, + "PROXY_HTTP_TUNNELING"); + if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel) + plugin->proxy_use_httpproxytunnel = GNUNET_NO; + + GNUNET_free_non_null (proxy_type); + } + /* Should we emulate an XHR client for testing? */ plugin->emulate_xhr - = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, - plugin->name, - "EMULATE_XHR"); + = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, + plugin->name, + "EMULATE_XHR"); return GNUNET_OK; } @@ -2320,13 +2342,13 @@ client_configure_plugin(struct HTTP_Client_Plugin *plugin) * @return res string if conversion was successful, NULL otherwise */ static const char * -http_client_plugin_address_to_string(void *cls, - const void *addr, - size_t addrlen) +http_client_plugin_address_to_string (void *cls, + const void *addr, + size_t addrlen) { - return http_common_plugin_address_to_string(PLUGIN_NAME, - addr, - addrlen); + return http_common_plugin_address_to_string (PLUGIN_NAME, + addr, + addrlen); } @@ -2340,11 +2362,12 @@ http_client_plugin_address_to_string(void *cls, * @param session which session is being updated */ static void -http_client_plugin_update_session_timeout(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session) +http_client_plugin_update_session_timeout (void *cls, + const struct + GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session) { - client_reschedule_session_timeout(session); + client_reschedule_session_timeout (session); } @@ -2359,24 +2382,24 @@ http_client_plugin_update_session_timeout(void *cls, * @param delay new delay to use for receiving */ static void -http_client_plugin_update_inbound_delay(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *s, - struct GNUNET_TIME_Relative delay) +http_client_plugin_update_inbound_delay (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *s, + struct GNUNET_TIME_Relative delay) { - s->next_receive = GNUNET_TIME_relative_to_absolute(delay); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "New inbound delay %s\n", - GNUNET_STRINGS_relative_time_to_string(delay, - GNUNET_NO)); + s->next_receive = GNUNET_TIME_relative_to_absolute (delay); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New inbound delay %s\n", + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_NO)); if (s->recv_wakeup_task != NULL) - { - GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); - s->recv_wakeup_task - = GNUNET_SCHEDULER_add_delayed(delay, - &client_wake_up, - s); - } + { + GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); + s->recv_wakeup_task + = GNUNET_SCHEDULER_add_delayed (delay, + &client_wake_up, + s); + } } @@ -2390,19 +2413,19 @@ http_client_plugin_update_inbound_delay(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -send_session_info_iter(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +send_session_info_iter (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct HTTP_Client_Plugin *plugin = cls; struct GNUNET_ATS_Session *session = value; - notify_session_monitor(plugin, - session, - GNUNET_TRANSPORT_SS_INIT); - notify_session_monitor(plugin, - session, - GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */ + notify_session_monitor (plugin, + session, + GNUNET_TRANSPORT_SS_INIT); + notify_session_monitor (plugin, + session, + GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */ return GNUNET_OK; } @@ -2420,22 +2443,22 @@ send_session_info_iter(void *cls, * @param sic_cls closure for @a sic */ static void -http_client_plugin_setup_monitor(void *cls, - GNUNET_TRANSPORT_SessionInfoCallback sic, - void *sic_cls) +http_client_plugin_setup_monitor (void *cls, + GNUNET_TRANSPORT_SessionInfoCallback sic, + void *sic_cls) { struct HTTP_Client_Plugin *plugin = cls; plugin->sic = sic; plugin->sic_cls = sic_cls; if (NULL != sic) - { - GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, - &send_session_info_iter, - plugin); - /* signal end of first iteration */ - sic(sic_cls, NULL, NULL); - } + { + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, + &send_session_info_iter, + plugin); + /* signal end of first iteration */ + sic (sic_cls, NULL, NULL); + } } @@ -2443,29 +2466,29 @@ http_client_plugin_setup_monitor(void *cls, * Entry point for the plugin. */ void * -LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) +LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) { struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; struct HTTP_Client_Plugin *plugin; if (NULL == env->receive) - { - /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully - initialze the plugin or the API */ - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); - api->cls = NULL; - api->address_to_string = &http_client_plugin_address_to_string; - api->string_to_address = &http_common_plugin_string_to_address; - api->address_pretty_printer = &http_common_plugin_address_pretty_printer; - return api; - } + { + /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully + initialze the plugin or the API */ + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); + api->cls = NULL; + api->address_to_string = &http_client_plugin_address_to_string; + api->string_to_address = &http_common_plugin_string_to_address; + api->address_pretty_printer = &http_common_plugin_address_pretty_printer; + return api; + } - plugin = GNUNET_new(struct HTTP_Client_Plugin); + plugin = GNUNET_new (struct HTTP_Client_Plugin); plugin->env = env; - plugin->sessions = GNUNET_CONTAINER_multipeermap_create(128, - GNUNET_YES); - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); + plugin->sessions = GNUNET_CONTAINER_multipeermap_create (128, + GNUNET_YES); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->send = &http_client_plugin_send; api->disconnect_session = &http_client_plugin_session_disconnect; @@ -2490,18 +2513,18 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) #endif plugin->last_tag = 1; - if (GNUNET_SYSERR == client_configure_plugin(plugin)) - { - LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); - return NULL; - } + if (GNUNET_SYSERR == client_configure_plugin (plugin)) + { + LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); + return NULL; + } /* Start client */ - if (GNUNET_SYSERR == client_start(plugin)) - { - LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); - return NULL; - } + if (GNUNET_SYSERR == client_start (plugin)) + { + LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); + return NULL; + } return api; } diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index 902fc5c36..6d3ee3429 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c @@ -30,23 +30,23 @@ #include "gnunet_resolver_service.h" static void -http_clean_splitted(struct SplittedHTTPAddress *spa) +http_clean_splitted (struct SplittedHTTPAddress *spa) { if (NULL != spa) - { - GNUNET_free_non_null(spa->protocol); - GNUNET_free_non_null(spa->host); - GNUNET_free_non_null(spa->path); - GNUNET_free_non_null(spa); - } + { + GNUNET_free_non_null (spa->protocol); + GNUNET_free_non_null (spa->host); + GNUNET_free_non_null (spa->path); + GNUNET_free_non_null (spa); + } } struct SplittedHTTPAddress * -http_split_address(const char * addr) +http_split_address (const char *addr) { struct SplittedHTTPAddress *sp; - char *src = GNUNET_strdup(addr); + char *src = GNUNET_strdup (addr); char *protocol_start = NULL; char *host_start = NULL; char *v6_end = NULL; @@ -55,128 +55,129 @@ http_split_address(const char * addr) protocol_start = src; - sp = GNUNET_new(struct SplittedHTTPAddress); + sp = GNUNET_new (struct SplittedHTTPAddress); /* Address string consists of protocol://host[:port]path*/ - host_start = strstr(src, "://"); + host_start = strstr (src, "://"); if (NULL == host_start) - { - GNUNET_free(src); - GNUNET_free(sp); - return NULL; - } + { + GNUNET_free (src); + GNUNET_free (sp); + return NULL; + } host_start[0] = '\0'; - sp->protocol = GNUNET_strdup(protocol_start); - - host_start += strlen("://"); - if (strlen(host_start) == 0) - { - GNUNET_free(src); - GNUNET_free(sp->protocol); - GNUNET_free(sp); - return NULL; - } + sp->protocol = GNUNET_strdup (protocol_start); + + host_start += strlen ("://"); + if (strlen (host_start) == 0) + { + GNUNET_free (src); + GNUNET_free (sp->protocol); + GNUNET_free (sp); + return NULL; + } /* Find path start */ - path_start = strchr(host_start, '/'); + path_start = strchr (host_start, '/'); if (NULL != path_start) - { - sp->path = GNUNET_strdup(path_start); - path_start[0] = '\0'; - } + { + sp->path = GNUNET_strdup (path_start); + path_start[0] = '\0'; + } else - sp->path = GNUNET_strdup(""); - - if (strlen(host_start) < 1) - { - GNUNET_free(src); - GNUNET_free(sp->protocol); - GNUNET_free(sp->path); - GNUNET_free(sp); - return NULL; - } - - if (NULL != (port_start = strrchr(host_start, ':'))) - { - /* *We COULD have a port, but also an IPv6 address! */ - if (NULL != (v6_end = strchr(host_start, ']'))) - { - if (v6_end < port_start) - { - /* IPv6 address + port */ - port_start[0] = '\0'; - port_start++; - sp->port = atoi(port_start); - if ((0 == sp->port) || (65535 < sp->port)) - { - GNUNET_free(src); - GNUNET_free(sp->protocol); - GNUNET_free(sp->path); - GNUNET_free(sp); - return NULL; - } - } - else - { - /* IPv6 address + no port */ - if (0 == strcmp(sp->protocol, "https")) - sp->port = HTTPS_DEFAULT_PORT; - else if (0 == strcmp(sp->protocol, "http")) - sp->port = HTTP_DEFAULT_PORT; - } - } - else - { - /* No IPv6 address */ - port_start[0] = '\0'; - port_start++; - sp->port = atoi(port_start); - if ((0 == sp->port) || (65535 < sp->port)) - { - GNUNET_free(src); - GNUNET_free(sp->protocol); - GNUNET_free(sp->path); - GNUNET_free(sp); - return NULL; - } - } - } - else - { - /* No ':' as port separator, default port for protocol */ - if (0 == strcmp(sp->protocol, "https")) - sp->port = HTTPS_DEFAULT_PORT; - else if (0 == strcmp(sp->protocol, "http")) - sp->port = HTTP_DEFAULT_PORT; - else + sp->path = GNUNET_strdup (""); + + if (strlen (host_start) < 1) + { + GNUNET_free (src); + GNUNET_free (sp->protocol); + GNUNET_free (sp->path); + GNUNET_free (sp); + return NULL; + } + + if (NULL != (port_start = strrchr (host_start, ':'))) + { + /* *We COULD have a port, but also an IPv6 address! */ + if (NULL != (v6_end = strchr (host_start, ']'))) + { + if (v6_end < port_start) + { + /* IPv6 address + port */ + port_start[0] = '\0'; + port_start++; + sp->port = atoi (port_start); + if ((0 == sp->port) || (65535 < sp->port)) { - GNUNET_break(0); - GNUNET_free(src); - GNUNET_free(sp->protocol); - GNUNET_free(sp->path); - GNUNET_free(sp); + GNUNET_free (src); + GNUNET_free (sp->protocol); + GNUNET_free (sp->path); + GNUNET_free (sp); return NULL; } - } - if (strlen(host_start) > 0) - sp->host = GNUNET_strdup(host_start); + } + else + { + /* IPv6 address + no port */ + if (0 == strcmp (sp->protocol, "https")) + sp->port = HTTPS_DEFAULT_PORT; + else if (0 == strcmp (sp->protocol, "http")) + sp->port = HTTP_DEFAULT_PORT; + } + } + else + { + /* No IPv6 address */ + port_start[0] = '\0'; + port_start++; + sp->port = atoi (port_start); + if ((0 == sp->port) || (65535 < sp->port)) + { + GNUNET_free (src); + GNUNET_free (sp->protocol); + GNUNET_free (sp->path); + GNUNET_free (sp); + return NULL; + } + } + } else - { - GNUNET_break(0); - GNUNET_free(src); - GNUNET_free(sp->protocol); - GNUNET_free(sp->path); - GNUNET_free(sp); + { + /* No ':' as port separator, default port for protocol */ + if (0 == strcmp (sp->protocol, "https")) + sp->port = HTTPS_DEFAULT_PORT; + else if (0 == strcmp (sp->protocol, "http")) + sp->port = HTTP_DEFAULT_PORT; + else + { + GNUNET_break (0); + GNUNET_free (src); + GNUNET_free (sp->protocol); + GNUNET_free (sp->path); + GNUNET_free (sp); return NULL; } - GNUNET_free(src); + } + if (strlen (host_start) > 0) + sp->host = GNUNET_strdup (host_start); + else + { + GNUNET_break (0); + GNUNET_free (src); + GNUNET_free (sp->protocol); + GNUNET_free (sp->path); + GNUNET_free (sp); + return NULL; + } + GNUNET_free (src); return sp; } /** * Closure for #append_port(). */ -struct PrettyPrinterContext { +struct PrettyPrinterContext +{ /** * DLL */ @@ -205,7 +206,7 @@ struct PrettyPrinterContext { /** * Timeout task */ - struct GNUNET_SCHEDULER_Task * timeout_task; + struct GNUNET_SCHEDULER_Task *timeout_task; /** * Splitted Address @@ -251,149 +252,156 @@ static struct PrettyPrinterContext *dll_ppc_tail; * @return string representing the same address or NULL on error */ static const char * -http_common_plugin_dnsresult_to_address(const char *plugin, - const struct SplittedHTTPAddress *saddr, - uint32_t options, - const char *dnsresult) +http_common_plugin_dnsresult_to_address (const char *plugin, + const struct + SplittedHTTPAddress *saddr, + uint32_t options, + const char *dnsresult) { static char rbuf[1024]; char *res; - GNUNET_asprintf(&res, "%s.%u.%s://%s:%u%s", plugin, options, saddr->protocol, - dnsresult, saddr->port, saddr->path); - if (strlen(res) + 1 < 500) - { - GNUNET_memcpy(rbuf, res, strlen(res) + 1); - GNUNET_free(res); - return rbuf; - } - GNUNET_break(0); - GNUNET_free(res); + GNUNET_asprintf (&res, "%s.%u.%s://%s:%u%s", plugin, options, saddr->protocol, + dnsresult, saddr->port, saddr->path); + if (strlen (res) + 1 < 500) + { + GNUNET_memcpy (rbuf, res, strlen (res) + 1); + GNUNET_free (res); + return rbuf; + } + GNUNET_break (0); + GNUNET_free (res); return NULL; } static void -http_common_dns_reverse_lookup_cb(void *cls, const char *hostname) +http_common_dns_reverse_lookup_cb (void *cls, const char *hostname) { struct PrettyPrinterContext *ppc = cls; if (NULL != hostname) - { - ppc->asc(ppc->asc_cls, - http_common_plugin_dnsresult_to_address(ppc->plugin, ppc->saddr, ppc->options, + { + ppc->asc (ppc->asc_cls, + http_common_plugin_dnsresult_to_address (ppc->plugin, ppc->saddr, + ppc->options, hostname), GNUNET_OK); - ppc->sucess = GNUNET_YES; - } + ppc->sucess = GNUNET_YES; + } else - { - ppc->asc(ppc->asc_cls, NULL, - (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK); - - GNUNET_CONTAINER_DLL_remove(dll_ppc_head, dll_ppc_tail, ppc); - http_clean_splitted(ppc->saddr); - GNUNET_free(ppc->plugin); - GNUNET_free(ppc); - } + { + ppc->asc (ppc->asc_cls, NULL, + (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK); + + GNUNET_CONTAINER_DLL_remove (dll_ppc_head, dll_ppc_tail, ppc); + http_clean_splitted (ppc->saddr); + GNUNET_free (ppc->plugin); + GNUNET_free (ppc); + } } static int -http_common_dns_reverse_lookup(const struct sockaddr *sockaddr, - socklen_t sockaddr_len, - const char *type, - struct SplittedHTTPAddress *saddr, - uint32_t options, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback asc, - void *asc_cls) +http_common_dns_reverse_lookup (const struct sockaddr *sockaddr, + socklen_t sockaddr_len, + const char *type, + struct SplittedHTTPAddress *saddr, + uint32_t options, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback asc, + void *asc_cls) { struct PrettyPrinterContext *ppc; - ppc = GNUNET_new(struct PrettyPrinterContext); + ppc = GNUNET_new (struct PrettyPrinterContext); ppc->saddr = saddr; ppc->asc = asc; ppc->asc_cls = asc_cls; - ppc->plugin = GNUNET_strdup(type); + ppc->plugin = GNUNET_strdup (type); ppc->options = options; - ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sockaddr, - sockaddr_len, - GNUNET_YES, - timeout, - &http_common_dns_reverse_lookup_cb, - ppc); + ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sockaddr, + sockaddr_len, + GNUNET_YES, + timeout, + & + http_common_dns_reverse_lookup_cb, + ppc); if (NULL == ppc->resolver_handle) - { - GNUNET_free(ppc->plugin); - GNUNET_free(ppc); - return GNUNET_SYSERR; - } - GNUNET_CONTAINER_DLL_insert(dll_ppc_head, - dll_ppc_tail, - ppc); + { + GNUNET_free (ppc->plugin); + GNUNET_free (ppc); + return GNUNET_SYSERR; + } + GNUNET_CONTAINER_DLL_insert (dll_ppc_head, + dll_ppc_tail, + ppc); return GNUNET_OK; } static void -http_common_dns_ip_lookup_cb(void *cls, - const struct sockaddr *addr, - socklen_t addrlen) +http_common_dns_ip_lookup_cb (void *cls, + const struct sockaddr *addr, + socklen_t addrlen) { struct PrettyPrinterContext *ppc = cls; if (NULL != addr) - { - ppc->asc(ppc->asc_cls, - http_common_plugin_dnsresult_to_address(ppc->plugin, ppc->saddr, ppc->options, - GNUNET_a2s(addr, addrlen)), GNUNET_OK); - ppc->sucess = GNUNET_YES; - ppc->asc(ppc->asc_cls, GNUNET_a2s(addr, addrlen), GNUNET_OK); - } + { + ppc->asc (ppc->asc_cls, + http_common_plugin_dnsresult_to_address (ppc->plugin, ppc->saddr, + ppc->options, + GNUNET_a2s (addr, + addrlen)), + GNUNET_OK); + ppc->sucess = GNUNET_YES; + ppc->asc (ppc->asc_cls, GNUNET_a2s (addr, addrlen), GNUNET_OK); + } else - { - ppc->asc(ppc->asc_cls, NULL, - (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK); - - GNUNET_CONTAINER_DLL_remove(dll_ppc_head, dll_ppc_tail, ppc); - GNUNET_free(ppc->plugin); - http_clean_splitted(ppc->saddr); - GNUNET_free(ppc); - } + { + ppc->asc (ppc->asc_cls, NULL, + (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK); + + GNUNET_CONTAINER_DLL_remove (dll_ppc_head, dll_ppc_tail, ppc); + GNUNET_free (ppc->plugin); + http_clean_splitted (ppc->saddr); + GNUNET_free (ppc); + } } static int -http_common_dns_ip_lookup(const char *name, - const char *type, - struct SplittedHTTPAddress *saddr, - uint32_t options, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) +http_common_dns_ip_lookup (const char *name, + const char *type, + struct SplittedHTTPAddress *saddr, + uint32_t options, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback asc, + void *asc_cls) { struct PrettyPrinterContext *ppc; - ppc = GNUNET_new(struct PrettyPrinterContext); + ppc = GNUNET_new (struct PrettyPrinterContext); ppc->sucess = GNUNET_NO; ppc->saddr = saddr; ppc->asc = asc; ppc->asc_cls = asc_cls; - ppc->plugin = GNUNET_strdup(type); + ppc->plugin = GNUNET_strdup (type); ppc->options = options; - ppc->resolver_handle = GNUNET_RESOLVER_ip_get(name, - AF_UNSPEC, - timeout, - &http_common_dns_ip_lookup_cb, - ppc); + ppc->resolver_handle = GNUNET_RESOLVER_ip_get (name, + AF_UNSPEC, + timeout, + &http_common_dns_ip_lookup_cb, + ppc); if (NULL == ppc->resolver_handle) - { - GNUNET_free(ppc->plugin); - GNUNET_free(ppc); - return GNUNET_SYSERR; - } - GNUNET_CONTAINER_DLL_insert(dll_ppc_head, - dll_ppc_tail, - ppc); + { + GNUNET_free (ppc->plugin); + GNUNET_free (ppc); + return GNUNET_SYSERR; + } + GNUNET_CONTAINER_DLL_insert (dll_ppc_head, + dll_ppc_tail, + ppc); return GNUNET_OK; } @@ -413,13 +421,14 @@ http_common_dns_ip_lookup(const char *name, * @param asc_cls closure for @a asc */ void -http_common_plugin_address_pretty_printer(void *cls, const char *type, - const void *addr, - size_t addrlen, - int numeric, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback asc, - void *asc_cls) +http_common_plugin_address_pretty_printer (void *cls, const char *type, + const void *addr, + size_t addrlen, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback + asc, + void *asc_cls) { const struct HttpAddress *address = addr; struct SplittedHTTPAddress *saddr; @@ -432,120 +441,120 @@ http_common_plugin_address_pretty_printer(void *cls, const char *type, saddr = NULL; sock_addr = NULL; if ((addrlen < sizeof(struct HttpAddress)) || - (addrlen != http_common_address_get_size(address))) - { - GNUNET_break(0); - goto handle_error; - } - - addr_str = (char *)&address[1]; - if (addr_str[ntohl(address->urlen) - 1] != '\0') - { - GNUNET_break(0); - goto handle_error; - } - - saddr = http_split_address(addr_str); + (addrlen != http_common_address_get_size (address))) + { + GNUNET_break (0); + goto handle_error; + } + + addr_str = (char *) &address[1]; + if (addr_str[ntohl (address->urlen) - 1] != '\0') + { + GNUNET_break (0); + goto handle_error; + } + + saddr = http_split_address (addr_str); if (NULL == saddr) - { - GNUNET_break(0); - goto handle_error; - } + { + GNUNET_break (0); + goto handle_error; + } - sock_addr = http_common_socket_from_address(addr, addrlen, &res); + sock_addr = http_common_socket_from_address (addr, addrlen, &res); if (GNUNET_SYSERR == res) - { - /* Malformed address */ - GNUNET_break(0); - goto handle_error; - } + { + /* Malformed address */ + GNUNET_break (0); + goto handle_error; + } else if (GNUNET_NO == res) - { - /* Could not convert to IP */ - have_ip = GNUNET_NO; - } + { + /* Could not convert to IP */ + have_ip = GNUNET_NO; + } else if (GNUNET_YES == res) - { - /* Converted to IP */ - have_ip = GNUNET_YES; - } + { + /* Converted to IP */ + have_ip = GNUNET_YES; + } else - { - /* Must not happen */ - GNUNET_break(0); - goto handle_error; - } + { + /* Must not happen */ + GNUNET_break (0); + goto handle_error; + } if ((GNUNET_YES == numeric) && (GNUNET_YES == have_ip)) - { - /* No lookup required */ - ret = http_common_plugin_address_to_string(type, address, addrlen); - asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); - asc(asc_cls, NULL, GNUNET_OK); - http_clean_splitted(saddr); - GNUNET_free_non_null(sock_addr); - return; - } + { + /* No lookup required */ + ret = http_common_plugin_address_to_string (type, address, addrlen); + asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); + asc (asc_cls, NULL, GNUNET_OK); + http_clean_splitted (saddr); + GNUNET_free_non_null (sock_addr); + return; + } if ((GNUNET_YES == numeric) && (GNUNET_NO == have_ip)) - { - /* Forward lookup */ - if (GNUNET_SYSERR == - http_common_dns_ip_lookup(saddr->host, type, saddr, - address->options, timeout, - asc, asc_cls)) - { - GNUNET_break(0); - goto handle_error; - } - /* Wait for resolver callback */ - GNUNET_free_non_null(sock_addr); - return; + { + /* Forward lookup */ + if (GNUNET_SYSERR == + http_common_dns_ip_lookup (saddr->host, type, saddr, + address->options, timeout, + asc, asc_cls)) + { + GNUNET_break (0); + goto handle_error; } + /* Wait for resolver callback */ + GNUNET_free_non_null (sock_addr); + return; + } if ((GNUNET_NO == numeric) && (GNUNET_YES == have_ip)) - { - /* Reverse lookup */ - if (GNUNET_SYSERR == - http_common_dns_reverse_lookup(sock_addr, - (AF_INET == sock_addr->sa_family) - ? sizeof(struct sockaddr_in) - : sizeof(struct sockaddr_in6), - type, - saddr, - address->options, timeout, - asc, asc_cls)) - { - GNUNET_break(0); - goto handle_error; - } - /* Wait for resolver callback */ - GNUNET_free_non_null(sock_addr); - return; + { + /* Reverse lookup */ + if (GNUNET_SYSERR == + http_common_dns_reverse_lookup (sock_addr, + (AF_INET == sock_addr->sa_family) + ? sizeof(struct sockaddr_in) + : sizeof(struct sockaddr_in6), + type, + saddr, + address->options, timeout, + asc, asc_cls)) + { + GNUNET_break (0); + goto handle_error; } + /* Wait for resolver callback */ + GNUNET_free_non_null (sock_addr); + return; + } if ((GNUNET_NO == numeric) && (GNUNET_NO == have_ip)) - { - /* No lookup required */ - ret = http_common_plugin_address_to_string(type, address, addrlen); - asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); - asc(asc_cls, NULL, GNUNET_OK); - GNUNET_free_non_null(sock_addr); - http_clean_splitted(saddr); - return; - } + { + /* No lookup required */ + ret = http_common_plugin_address_to_string (type, address, addrlen); + asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); + asc (asc_cls, NULL, GNUNET_OK); + GNUNET_free_non_null (sock_addr); + http_clean_splitted (saddr); + return; + } /* Error (argument supplied not GNUNET_YES or GNUNET_NO) */ - GNUNET_break(0); + GNUNET_break (0); goto handle_error; handle_error: /* Report error */ - asc(asc_cls, NULL, GNUNET_SYSERR); - asc(asc_cls, NULL, GNUNET_OK); - GNUNET_free_non_null(sock_addr); + asc (asc_cls, NULL, GNUNET_SYSERR); + asc (asc_cls, NULL, GNUNET_OK); + GNUNET_free_non_null (sock_addr); if (NULL != saddr) - http_clean_splitted(saddr); + http_clean_splitted (saddr); } @@ -553,36 +562,36 @@ handle_error: * FIXME. */ const char * -http_common_plugin_address_to_url(void *cls, - const void *addr, - size_t addrlen) +http_common_plugin_address_to_url (void *cls, + const void *addr, + size_t addrlen) { static char rbuf[1024]; const struct HttpAddress *address = addr; - const char * addr_str; + const char *addr_str; if (NULL == addr) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } if (0 == addrlen) - { - GNUNET_break(0); - return NULL; - } - if (addrlen != http_common_address_get_size(address)) - { - GNUNET_break(0); - return NULL; - } - addr_str = (char *)&address[1]; - if (addr_str[ntohl(address->urlen) - 1] != '\0') + { + GNUNET_break (0); + return NULL; + } + if (addrlen != http_common_address_get_size (address)) + { + GNUNET_break (0); + return NULL; + } + addr_str = (char *) &address[1]; + if (addr_str[ntohl (address->urlen) - 1] != '\0') return NULL; - GNUNET_memcpy(rbuf, - &address[1], - ntohl(address->urlen)); + GNUNET_memcpy (rbuf, + &address[1], + ntohl (address->urlen)); return rbuf; } @@ -599,35 +608,35 @@ http_common_plugin_address_to_url(void *cls, * @return string representing the same address */ const char * -http_common_plugin_address_to_string(const char *plugin, - const void *addr, - size_t addrlen) +http_common_plugin_address_to_string (const char *plugin, + const void *addr, + size_t addrlen) { static char rbuf[1024]; const struct HttpAddress *address = addr; - const char * addr_str; + const char *addr_str; char *res; - GNUNET_assert(NULL != plugin); + GNUNET_assert (NULL != plugin); if (NULL == addr) return NULL; if (0 == addrlen) return NULL; - if (addrlen != http_common_address_get_size(address)) + if (addrlen != http_common_address_get_size (address)) return NULL; - addr_str = (char *)&address[1]; - if (addr_str[ntohl(address->urlen) - 1] != '\0') + addr_str = (char *) &address[1]; + if (addr_str[ntohl (address->urlen) - 1] != '\0') return NULL; - GNUNET_asprintf(&res, "%s.%u.%s", plugin, ntohl(address->options), - &address[1]); - if (strlen(res) + 1 < 500) - { - GNUNET_memcpy(rbuf, res, strlen(res) + 1); - GNUNET_free(res); - return rbuf; - } - GNUNET_break(0); - GNUNET_free(res); + GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl (address->options), + &address[1]); + if (strlen (res) + 1 < 500) + { + GNUNET_memcpy (rbuf, res, strlen (res) + 1); + GNUNET_free (res); + return rbuf; + } + GNUNET_break (0); + GNUNET_free (res); return NULL; } @@ -644,11 +653,11 @@ http_common_plugin_address_to_string(const char *plugin, * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ int -http_common_plugin_string_to_address(void *cls, - const char *addr, - uint16_t addrlen, - void **buf, - size_t *added) +http_common_plugin_string_to_address (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, + size_t *added) { struct HttpAddress *a; char *address; @@ -662,50 +671,50 @@ http_common_plugin_string_to_address(void *cls, plugin = NULL; optionstr = NULL; if ((NULL == addr) || (addrlen == 0)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if ('\0' != addr[addrlen - 1]) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - if (strlen(addr) != addrlen - 1) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - plugin = GNUNET_strdup(addr); - optionstr = strchr(plugin, '.'); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (strlen (addr) != addrlen - 1) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + plugin = GNUNET_strdup (addr); + optionstr = strchr (plugin, '.'); if (NULL == optionstr) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } optionstr[0] = '\0'; optionstr++; - options = atol(optionstr); /* 0 on conversion error, that's ok */ - address = strchr(optionstr, '.'); + options = atol (optionstr); /* 0 on conversion error, that's ok */ + address = strchr (optionstr, '.'); if (NULL == address) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } address[0] = '\0'; address++; - urlen = strlen(address) + 1; + urlen = strlen (address) + 1; - a = GNUNET_malloc(sizeof(struct HttpAddress) + urlen); - a->options = htonl(options); - a->urlen = htonl(urlen); - GNUNET_memcpy(&a[1], address, urlen); + a = GNUNET_malloc (sizeof(struct HttpAddress) + urlen); + a->options = htonl (options); + a->urlen = htonl (urlen); + GNUNET_memcpy (&a[1], address, urlen); (*buf) = a; (*added) = sizeof(struct HttpAddress) + urlen; - GNUNET_free(plugin); + GNUNET_free (plugin); return GNUNET_OK; } @@ -719,25 +728,25 @@ http_common_plugin_string_to_address(void *cls, * @return the HttpAddress */ struct HttpAddress * -http_common_address_from_socket(const char *protocol, - const struct sockaddr *addr, - socklen_t addrlen) +http_common_address_from_socket (const char *protocol, + const struct sockaddr *addr, + socklen_t addrlen) { struct HttpAddress *address = NULL; char *res; size_t len; - GNUNET_asprintf(&res, - "%s://%s", - protocol, - GNUNET_a2s(addr, - addrlen)); - len = strlen(res) + 1; - address = GNUNET_malloc(sizeof(struct HttpAddress) + len); - address->options = htonl(HTTP_OPTIONS_NONE); - address->urlen = htonl(len); - GNUNET_memcpy(&address[1], res, len); - GNUNET_free(res); + GNUNET_asprintf (&res, + "%s://%s", + protocol, + GNUNET_a2s (addr, + addrlen)); + len = strlen (res) + 1; + address = GNUNET_malloc (sizeof(struct HttpAddress) + len); + address->options = htonl (HTTP_OPTIONS_NONE); + address->urlen = htonl (len); + GNUNET_memcpy (&address[1], res, len); + GNUNET_free (res); return address; } @@ -754,79 +763,79 @@ http_common_address_from_socket(const char *protocol, * @return the string */ struct sockaddr * -http_common_socket_from_address(const void *addr, - size_t addrlen, - int *res) +http_common_socket_from_address (const void *addr, + size_t addrlen, + int *res) { const struct HttpAddress *ha; - struct SplittedHTTPAddress * spa; + struct SplittedHTTPAddress *spa; struct sockaddr_storage *s; - char * to_conv; + char *to_conv; size_t urlen; (*res) = GNUNET_SYSERR; - ha = (const struct HttpAddress *)addr; + ha = (const struct HttpAddress *) addr; if (NULL == addr) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } if (0 == addrlen) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } if (addrlen < sizeof(struct HttpAddress)) - { - GNUNET_break(0); - return NULL; - } - urlen = ntohl(ha->urlen); + { + GNUNET_break (0); + return NULL; + } + urlen = ntohl (ha->urlen); if (sizeof(struct HttpAddress) + urlen != addrlen) - { - /* This is a legacy addresses */ - return NULL; - } + { + /* This is a legacy addresses */ + return NULL; + } if (addrlen < sizeof(struct HttpAddress) + urlen) - { - /* This is a legacy addresses */ - return NULL; - } - if (((char *)addr)[addrlen - 1] != '\0') - { - GNUNET_break(0); - return NULL; - } - spa = http_split_address((const char *)&ha[1]); + { + /* This is a legacy addresses */ + return NULL; + } + if (((char *) addr)[addrlen - 1] != '\0') + { + GNUNET_break (0); + return NULL; + } + spa = http_split_address ((const char *) &ha[1]); if (NULL == spa) - { - (*res) = GNUNET_SYSERR; - return NULL; - } + { + (*res) = GNUNET_SYSERR; + return NULL; + } - s = GNUNET_new(struct sockaddr_storage); - GNUNET_asprintf(&to_conv, "%s:%u", spa->host, spa->port); + s = GNUNET_new (struct sockaddr_storage); + GNUNET_asprintf (&to_conv, "%s:%u", spa->host, spa->port); if (GNUNET_SYSERR - == GNUNET_STRINGS_to_address_ip(to_conv, strlen(to_conv), s)) - { - /* could be a hostname */ - GNUNET_free(s); - (*res) = GNUNET_NO; - s = NULL; - } + == GNUNET_STRINGS_to_address_ip (to_conv, strlen (to_conv), s)) + { + /* could be a hostname */ + GNUNET_free (s); + (*res) = GNUNET_NO; + s = NULL; + } else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family)) - { - GNUNET_free(s); - (*res) = GNUNET_SYSERR; - s = NULL; - } + { + GNUNET_free (s); + (*res) = GNUNET_SYSERR; + s = NULL; + } else - { - (*res) = GNUNET_YES; - } - http_clean_splitted(spa); - GNUNET_free(to_conv); - return (struct sockaddr *)s; + { + (*res) = GNUNET_YES; + } + http_clean_splitted (spa); + GNUNET_free (to_conv); + return (struct sockaddr *) s; } @@ -837,9 +846,9 @@ http_common_socket_from_address(const void *addr, * @return the size */ size_t -http_common_address_get_size(const struct HttpAddress * addr) +http_common_address_get_size (const struct HttpAddress *addr) { - return sizeof(struct HttpAddress) + ntohl(addr->urlen); + return sizeof(struct HttpAddress) + ntohl (addr->urlen); } @@ -853,18 +862,18 @@ http_common_address_get_size(const struct HttpAddress * addr) * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error */ size_t -http_common_cmp_addresses(const void *addr1, - size_t addrlen1, - const void *addr2, - size_t addrlen2) +http_common_cmp_addresses (const void *addr1, + size_t addrlen1, + const void *addr2, + size_t addrlen2) { const char *a1 = addr1; const char *a2 = addr2; const struct HttpAddress *ha1; const struct HttpAddress *ha2; - ha1 = (const struct HttpAddress *)a1; - ha2 = (const struct HttpAddress *)a2; + ha1 = (const struct HttpAddress *) a1; + ha2 = (const struct HttpAddress *) a2; if (NULL == a1) return GNUNET_SYSERR; @@ -885,7 +894,7 @@ http_common_cmp_addresses(const void *addr1, if (ha1->urlen != ha2->urlen) return GNUNET_NO; - if (0 == strcmp((const char *)&ha1[1], (const char *)&ha2[1])) + if (0 == strcmp ((const char *) &ha1[1], (const char *) &ha2[1])) return GNUNET_YES; return GNUNET_NO; } @@ -899,8 +908,9 @@ http_common_cmp_addresses(const void *addr1, * @return the network type */ enum GNUNET_NetworkType -http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *env, - const struct GNUNET_HELLO_Address *address) +http_common_get_network_for_address (struct + GNUNET_TRANSPORT_PluginEnvironment *env, + const struct GNUNET_HELLO_Address *address) { struct sockaddr *sa; enum GNUNET_NetworkType net_type; @@ -908,27 +918,27 @@ http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *e int res; net_type = GNUNET_NT_UNSPECIFIED; - sa = http_common_socket_from_address(address->address, - address->address_length, - &res); + sa = http_common_socket_from_address (address->address, + address->address_length, + &res); if (GNUNET_SYSERR == res) return net_type; if (GNUNET_YES == res) + { + GNUNET_assert (NULL != sa); + if (AF_INET == sa->sa_family) { - GNUNET_assert(NULL != sa); - if (AF_INET == sa->sa_family) - { - salen = sizeof(struct sockaddr_in); - } - else if (AF_INET6 == sa->sa_family) - { - salen = sizeof(struct sockaddr_in6); - } - net_type = env->get_address_type(env->cls, - sa, - salen); - GNUNET_free(sa); + salen = sizeof(struct sockaddr_in); + } + else if (AF_INET6 == sa->sa_family) + { + salen = sizeof(struct sockaddr_in6); } + net_type = env->get_address_type (env->cls, + sa, + salen); + GNUNET_free (sa); + } return net_type; } diff --git a/src/transport/plugin_transport_http_common.h b/src/transport/plugin_transport_http_common.h index 6aaf663a1..299dc0e68 100644 --- a/src/transport/plugin_transport_http_common.h +++ b/src/transport/plugin_transport_http_common.h @@ -33,10 +33,14 @@ #define TESTING GNUNET_NO #if TESTING -#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) -#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) -#define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 7) -#define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 7) +#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 3) +#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 3) +#define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 7) +#define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 7) #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG #else @@ -47,8 +51,10 @@ #define PROTOCOL "http" #endif -#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) -#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) +#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 15) +#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 15) #define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT #define HTTP_SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG @@ -61,7 +67,8 @@ /** * Bits in the `options` field of HTTP addresses. */ -enum HttpAddressOptions { +enum HttpAddressOptions +{ /** * No bits set. */ @@ -86,7 +93,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * HttpAddress */ -struct HttpAddress { +struct HttpAddress +{ /** * Address options * see `enum HttpAddressOptions` @@ -104,7 +112,8 @@ GNUNET_NETWORK_STRUCT_END /** * Representation of HTTP URL split into its components. */ -struct SplittedHTTPAddress { +struct SplittedHTTPAddress +{ char *protocol; char *host; char *path; @@ -117,7 +126,7 @@ struct SplittedHTTPAddress { * and path components. */ struct SplittedHTTPAddress * -http_split_address(const char *addr); +http_split_address (const char *addr); /** @@ -135,14 +144,15 @@ http_split_address(const char *addr); * @param asc_cls closure for @a asc */ void -http_common_plugin_address_pretty_printer(void *cls, - const char *type, - const void *addr, - size_t addrlen, - int numeric, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback asc, - void *asc_cls); +http_common_plugin_address_pretty_printer (void *cls, + const char *type, + const void *addr, + size_t addrlen, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback + asc, + void *asc_cls); /** @@ -157,9 +167,9 @@ http_common_plugin_address_pretty_printer(void *cls, * @return string representing the same address */ const char * -http_common_plugin_address_to_string(const char *plugin, - const void *addr, - size_t addrlen); +http_common_plugin_address_to_string (const char *plugin, + const void *addr, + size_t addrlen); /** @@ -175,11 +185,11 @@ http_common_plugin_address_to_string(const char *plugin, * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ int -http_common_plugin_string_to_address(void *cls, - const char *addr, - uint16_t addrlen, - void **buf, - size_t *added); +http_common_plugin_string_to_address (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, + size_t *added); /** @@ -191,9 +201,9 @@ http_common_plugin_string_to_address(void *cls, * @return the string */ struct HttpAddress * -http_common_address_from_socket(const char *protocol, - const struct sockaddr *addr, - socklen_t addrlen); +http_common_address_from_socket (const char *protocol, + const struct sockaddr *addr, + socklen_t addrlen); /** @@ -208,15 +218,15 @@ http_common_address_from_socket(const char *protocol, * @return the string */ struct sockaddr * -http_common_socket_from_address(const void *addr, - size_t addrlen, - int *res); +http_common_socket_from_address (const void *addr, + size_t addrlen, + int *res); const char * -http_common_plugin_address_to_url(void *cls, - const void *addr, - size_t addrlen); +http_common_plugin_address_to_url (void *cls, + const void *addr, + size_t addrlen); /** @@ -226,7 +236,7 @@ http_common_plugin_address_to_url(void *cls, * @return the size */ size_t -http_common_address_get_size(const struct HttpAddress * addr); +http_common_address_get_size (const struct HttpAddress *addr); /** @@ -239,10 +249,10 @@ http_common_address_get_size(const struct HttpAddress * addr); * @return #GNUNET_YES if equal, #GNUNET_NO else */ size_t -http_common_cmp_addresses(const void *addr1, - size_t addrlen1, - const void *addr2, - size_t addrlen2); +http_common_cmp_addresses (const void *addr1, + size_t addrlen1, + const void *addr2, + size_t addrlen2); /** @@ -253,8 +263,10 @@ http_common_cmp_addresses(const void *addr1, * @return the network type */ enum GNUNET_NetworkType -http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *env, - const struct GNUNET_HELLO_Address *address); +http_common_get_network_for_address (struct + GNUNET_TRANSPORT_PluginEnvironment *env, + const struct + GNUNET_HELLO_Address *address); /* end of plugin_transport_http_common.h */ diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 1b454c09f..51555a56f 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -38,26 +38,33 @@ #if BUILD_HTTPS #define PLUGIN_NAME "https_server" -#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_server_init -#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_server_done +#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \ + libgnunet_plugin_transport_https_server_init +#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \ + libgnunet_plugin_transport_https_server_done #else #define PLUGIN_NAME "http_server" -#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_server_init -#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_server_done +#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \ + libgnunet_plugin_transport_http_server_init +#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \ + libgnunet_plugin_transport_http_server_done #endif -#define HTTP_ERROR_RESPONSE "404 Not Found

Not Found

The requested URL was not found on this server.


" +#define HTTP_ERROR_RESPONSE \ + "404 Not Found

Not Found

The requested URL was not found on this server.


" #define _RECEIVE 0 #define _SEND 1 -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-" PLUGIN_NAME, __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-" PLUGIN_NAME, \ + __VA_ARGS__) /** * Information we keep with MHD for an HTTP request. */ -struct ServerRequest { +struct ServerRequest +{ /** * The session this server request belongs to * Can be NULL, when session was disconnected and freed @@ -101,7 +108,8 @@ struct ServerRequest { /** * Wrapper to manage addresses */ -struct HttpAddressWrapper { +struct HttpAddressWrapper +{ /** * Linked list next */ @@ -127,7 +135,8 @@ struct HttpAddressWrapper { /** * Message to send using http */ -struct HTTP_Message { +struct HTTP_Message +{ /** * next pointer for double linked list */ @@ -175,7 +184,8 @@ struct HTTP_Message { /** * Session handle for connections. */ -struct GNUNET_ATS_Session { +struct GNUNET_ATS_Session +{ /** * To whom are we talking to (set to our identity * if we are still waiting for the welcome message) @@ -231,12 +241,12 @@ struct GNUNET_ATS_Session { /** * Session timeout task */ - struct GNUNET_SCHEDULER_Task * timeout_task; + struct GNUNET_SCHEDULER_Task *timeout_task; /** * Task to resume MHD handling when receiving is allowed again */ - struct GNUNET_SCHEDULER_Task * recv_wakeup_task; + struct GNUNET_SCHEDULER_Task *recv_wakeup_task; /** * Number of bytes waiting for transmission to this peer. @@ -268,7 +278,8 @@ struct GNUNET_ATS_Session { /** * Encapsulation of all of the state of the plugin. */ -struct HTTP_Server_Plugin { +struct HTTP_Server_Plugin +{ /** * Our environment. */ @@ -461,15 +472,15 @@ struct HTTP_Server_Plugin { * @param state new state of the session */ static void -notify_session_monitor(struct HTTP_Server_Plugin *plugin, - struct GNUNET_ATS_Session *session, - enum GNUNET_TRANSPORT_SessionState state) +notify_session_monitor (struct HTTP_Server_Plugin *plugin, + struct GNUNET_ATS_Session *session, + enum GNUNET_TRANSPORT_SessionState state) { struct GNUNET_TRANSPORT_SessionInfo info; if (NULL == plugin->sic) return; - memset(&info, 0, sizeof(info)); + memset (&info, 0, sizeof(info)); info.state = state; info.is_inbound = GNUNET_YES; info.num_msg_pending = session->msgs_in_queue; @@ -477,9 +488,9 @@ notify_session_monitor(struct HTTP_Server_Plugin *plugin, info.receive_delay = session->next_receive; info.session_timeout = session->timeout; info.address = session->address; - plugin->sic(plugin->sic_cls, - session, - &info); + plugin->sic (plugin->sic_cls, + session, + &info); } @@ -489,16 +500,16 @@ notify_session_monitor(struct HTTP_Server_Plugin *plugin, * @param cls the session */ static void -server_wake_up(void *cls) +server_wake_up (void *cls) { struct GNUNET_ATS_Session *s = cls; s->recv_wakeup_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p: Waking up PUT handle\n", - s); - GNUNET_assert(s->server_recv->suspended); - MHD_resume_connection(s->server_recv->mhd_conn); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p: Waking up PUT handle\n", + s); + GNUNET_assert (s->server_recv->suspended); + MHD_resume_connection (s->server_recv->mhd_conn); s->server_recv->suspended = false; } @@ -512,9 +523,9 @@ server_wake_up(void *cls) * until timeout */ static void -server_reschedule(struct HTTP_Server_Plugin *plugin, - struct MHD_Daemon *server, - int now); +server_reschedule (struct HTTP_Server_Plugin *plugin, + struct MHD_Daemon *server, + int now); /** @@ -523,106 +534,106 @@ server_reschedule(struct HTTP_Server_Plugin *plugin, * @param s the session to delete */ static void -server_delete_session(struct GNUNET_ATS_Session *s) +server_delete_session (struct GNUNET_ATS_Session *s) { struct HTTP_Server_Plugin *plugin = s->plugin; struct HTTP_Message *msg; if (NULL != s->timeout_task) - { - GNUNET_SCHEDULER_cancel(s->timeout_task); - s->timeout_task = NULL; - s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; - } + { + GNUNET_SCHEDULER_cancel (s->timeout_task); + s->timeout_task = NULL; + s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; + } if (NULL != s->recv_wakeup_task) - { - GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); - s->recv_wakeup_task = NULL; - if (NULL != s->server_recv) - { - GNUNET_assert(s->server_recv->suspended); - s->server_recv->suspended = false; - MHD_resume_connection(s->server_recv->mhd_conn); - } - } - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_remove(plugin->sessions, - &s->target, - s)); + { + GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); + s->recv_wakeup_task = NULL; + if (NULL != s->server_recv) + { + GNUNET_assert (s->server_recv->suspended); + s->server_recv->suspended = false; + MHD_resume_connection (s->server_recv->mhd_conn); + } + } + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, + &s->target, + s)); while (NULL != (msg = s->msg_head)) - { - GNUNET_CONTAINER_DLL_remove(s->msg_head, - s->msg_tail, - msg); - if (NULL != msg->transmit_cont) - msg->transmit_cont(msg->transmit_cont_cls, - &s->target, - GNUNET_SYSERR, - msg->size, - msg->pos + msg->overhead); - GNUNET_assert(s->msgs_in_queue > 0); - s->msgs_in_queue--; - GNUNET_assert(s->bytes_in_queue >= msg->size); - s->bytes_in_queue -= msg->size; - GNUNET_free(msg); - } - - GNUNET_assert(0 == s->msgs_in_queue); - GNUNET_assert(0 == s->bytes_in_queue); + { + GNUNET_CONTAINER_DLL_remove (s->msg_head, + s->msg_tail, + msg); + if (NULL != msg->transmit_cont) + msg->transmit_cont (msg->transmit_cont_cls, + &s->target, + GNUNET_SYSERR, + msg->size, + msg->pos + msg->overhead); + GNUNET_assert (s->msgs_in_queue > 0); + s->msgs_in_queue--; + GNUNET_assert (s->bytes_in_queue >= msg->size); + s->bytes_in_queue -= msg->size; + GNUNET_free (msg); + } + + GNUNET_assert (0 == s->msgs_in_queue); + GNUNET_assert (0 == s->bytes_in_queue); if (NULL != s->server_send) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server: %p / %p Terminating inbound PUT session to peer `%s'\n", - s, s->server_send, - GNUNET_i2s(&s->target)); - s->server_send->session = NULL; - MHD_set_connection_option(s->server_send->mhd_conn, - MHD_CONNECTION_OPTION_TIMEOUT, - 1 /* 0 = no timeout, so this is MIN */); - if (s->server_send->suspended) - { - s->server_send->suspended = false; - MHD_resume_connection(s->server_send->mhd_conn); - } - server_reschedule(plugin, - s->server_send->mhd_daemon, - GNUNET_YES); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server: %p / %p Terminating inbound PUT session to peer `%s'\n", + s, s->server_send, + GNUNET_i2s (&s->target)); + s->server_send->session = NULL; + MHD_set_connection_option (s->server_send->mhd_conn, + MHD_CONNECTION_OPTION_TIMEOUT, + 1 /* 0 = no timeout, so this is MIN */); + if (s->server_send->suspended) + { + s->server_send->suspended = false; + MHD_resume_connection (s->server_send->mhd_conn); + } + server_reschedule (plugin, + s->server_send->mhd_daemon, + GNUNET_YES); + } if (NULL != s->server_recv) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server: %p / %p Terminating inbound GET session to peer `%s'\n", - s, s->server_recv, GNUNET_i2s(&s->target)); - s->server_recv->session = NULL; - MHD_set_connection_option(s->server_recv->mhd_conn, - MHD_CONNECTION_OPTION_TIMEOUT, - 1 /* 0 = no timeout, so this is MIN */); - server_reschedule(plugin, - s->server_recv->mhd_daemon, - GNUNET_YES); - } - notify_session_monitor(plugin, - s, - GNUNET_TRANSPORT_SS_DONE); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server: %p / %p Terminating inbound GET session to peer `%s'\n", + s, s->server_recv, GNUNET_i2s (&s->target)); + s->server_recv->session = NULL; + MHD_set_connection_option (s->server_recv->mhd_conn, + MHD_CONNECTION_OPTION_TIMEOUT, + 1 /* 0 = no timeout, so this is MIN */); + server_reschedule (plugin, + s->server_recv->mhd_daemon, + GNUNET_YES); + } + notify_session_monitor (plugin, + s, + GNUNET_TRANSPORT_SS_DONE); if (GNUNET_YES == s->known_to_service) - { - plugin->env->session_end(plugin->env->cls, - s->address, - s); - s->known_to_service = GNUNET_NO; - } + { + plugin->env->session_end (plugin->env->cls, + s->address, + s); + s->known_to_service = GNUNET_NO; + } if (NULL != s->msg_tk) - { - GNUNET_MST_destroy(s->msg_tk); - s->msg_tk = NULL; - } - GNUNET_HELLO_address_free(s->address); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p destroyed\n", - s); - GNUNET_free(s); + { + GNUNET_MST_destroy (s->msg_tk); + s->msg_tk = NULL; + } + GNUNET_HELLO_address_free (s->address); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p destroyed\n", + s); + GNUNET_free (s); } @@ -635,10 +646,10 @@ server_delete_session(struct GNUNET_ATS_Session *s) * @return #GNUNET_OK on success */ static int -http_server_plugin_disconnect_session(void *cls, - struct GNUNET_ATS_Session *s) +http_server_plugin_disconnect_session (void *cls, + struct GNUNET_ATS_Session *s) { - server_delete_session(s); + server_delete_session (s); return GNUNET_OK; } @@ -649,31 +660,32 @@ http_server_plugin_disconnect_session(void *cls, * @param cls the session */ static void -server_session_timeout(void *cls) +server_session_timeout (void *cls) { struct GNUNET_ATS_Session *s = cls; struct GNUNET_TIME_Relative left; s->timeout_task = NULL; - left = GNUNET_TIME_absolute_get_remaining(s->timeout); + left = GNUNET_TIME_absolute_get_remaining (s->timeout); if (0 != left.rel_value_us) - { - /* not actually our turn yet, but let's at least update - the monitor, it may think we're about to die ... */ - notify_session_monitor(s->plugin, - s, - GNUNET_TRANSPORT_SS_UP); - s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, - &server_session_timeout, - s); - return; - } - GNUNET_log(TIMEOUT_LOG, - "Session %p was idle for %s, disconnecting\n", - s, - GNUNET_STRINGS_relative_time_to_string(HTTP_SERVER_SESSION_TIMEOUT, - GNUNET_YES)); - server_delete_session(s); + { + /* not actually our turn yet, but let's at least update + the monitor, it may think we're about to die ... */ + notify_session_monitor (s->plugin, + s, + GNUNET_TRANSPORT_SS_UP); + s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, + &server_session_timeout, + s); + return; + } + GNUNET_log (TIMEOUT_LOG, + "Session %p was idle for %s, disconnecting\n", + s, + GNUNET_STRINGS_relative_time_to_string ( + HTTP_SERVER_SESSION_TIMEOUT, + GNUNET_YES)); + server_delete_session (s); } @@ -683,10 +695,11 @@ server_session_timeout(void *cls) * @param s the session */ static void -server_reschedule_session_timeout(struct GNUNET_ATS_Session *s) +server_reschedule_session_timeout (struct GNUNET_ATS_Session *s) { - GNUNET_assert(NULL != s->timeout_task); - s->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_assert (NULL != s->timeout_task); + s->timeout = GNUNET_TIME_relative_to_absolute ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); } @@ -718,65 +731,65 @@ server_reschedule_session_timeout(struct GNUNET_ATS_Session *s) * and does NOT mean that the message was not transmitted (DV) */ static ssize_t -http_server_plugin_send(void *cls, - struct GNUNET_ATS_Session *session, - const char *msgbuf, - size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls) +http_server_plugin_send (void *cls, + struct GNUNET_ATS_Session *session, + const char *msgbuf, + size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { struct HTTP_Server_Plugin *plugin = cls; struct HTTP_Message *msg; ssize_t bytes_sent = 0; char *stat_txt; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p/request %p: Sending message with %u to peer `%s'\n", - session, - session->server_send, - msgbuf_size, - GNUNET_i2s(&session->target)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p/request %p: Sending message with %u to peer `%s'\n", + session, + session->server_send, + msgbuf_size, + GNUNET_i2s (&session->target)); /* create new message and schedule */ bytes_sent = sizeof(struct HTTP_Message) + msgbuf_size; - msg = GNUNET_malloc(bytes_sent); + msg = GNUNET_malloc (bytes_sent); msg->next = NULL; msg->size = msgbuf_size; msg->pos = 0; - msg->buf = (char *)&msg[1]; + msg->buf = (char *) &msg[1]; msg->transmit_cont = cont; msg->transmit_cont_cls = cont_cls; - GNUNET_memcpy(msg->buf, - msgbuf, - msgbuf_size); - GNUNET_CONTAINER_DLL_insert_tail(session->msg_head, - session->msg_tail, - msg); + GNUNET_memcpy (msg->buf, + msgbuf, + msgbuf_size); + GNUNET_CONTAINER_DLL_insert_tail (session->msg_head, + session->msg_tail, + msg); session->msgs_in_queue++; session->bytes_in_queue += msg->size; - notify_session_monitor(plugin, - session, - GNUNET_TRANSPORT_SS_UP); - GNUNET_asprintf(&stat_txt, - "# bytes currently in %s_server buffers", - plugin->protocol); - GNUNET_STATISTICS_update(plugin->env->stats, - stat_txt, msgbuf_size, GNUNET_NO); - GNUNET_free(stat_txt); + notify_session_monitor (plugin, + session, + GNUNET_TRANSPORT_SS_UP); + GNUNET_asprintf (&stat_txt, + "# bytes currently in %s_server buffers", + plugin->protocol); + GNUNET_STATISTICS_update (plugin->env->stats, + stat_txt, msgbuf_size, GNUNET_NO); + GNUNET_free (stat_txt); if (NULL != session->server_send) + { + if (session->server_send->suspended) { - if (session->server_send->suspended) - { - MHD_resume_connection(session->server_send->mhd_conn); - session->server_send->suspended = false; - } - server_reschedule(session->plugin, - session->server_send->mhd_daemon, - GNUNET_YES); + MHD_resume_connection (session->server_send->mhd_conn); + session->server_send->suspended = false; } + server_reschedule (session->plugin, + session->server_send->mhd_daemon, + GNUNET_YES); + } return bytes_sent; } @@ -790,9 +803,9 @@ http_server_plugin_send(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -destroy_session_shutdown_cb(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +destroy_session_shutdown_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct GNUNET_ATS_Session *s = value; struct ServerRequest *sc_send; @@ -800,7 +813,7 @@ destroy_session_shutdown_cb(void *cls, sc_send = s->server_send; sc_recv = s->server_recv; - server_delete_session(s); + server_delete_session (s); if (NULL != sc_send) sc_send->session = NULL; if (NULL != sc_recv) @@ -819,13 +832,13 @@ destroy_session_shutdown_cb(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -destroy_session_cb(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +destroy_session_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct GNUNET_ATS_Session *s = value; - server_delete_session(s); + server_delete_session (s); return GNUNET_OK; } @@ -839,18 +852,18 @@ destroy_session_cb(void *cls, * @param target peer from which to disconnect */ static void -http_server_plugin_disconnect_peer(void *cls, - const struct GNUNET_PeerIdentity *target) +http_server_plugin_disconnect_peer (void *cls, + const struct GNUNET_PeerIdentity *target) { struct HTTP_Server_Plugin *plugin = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Transport tells me to disconnect `%s'\n", - GNUNET_i2s(target)); - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, - target, - &destroy_session_cb, - plugin); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transport tells me to disconnect `%s'\n", + GNUNET_i2s (target)); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, + target, + &destroy_session_cb, + plugin); } @@ -867,9 +880,9 @@ http_server_plugin_disconnect_peer(void *cls, * and transport */ static int -http_server_plugin_address_suggested(void *cls, - const void *addr, - size_t addrlen) +http_server_plugin_address_suggested (void *cls, + const void *addr, + size_t addrlen) { struct HTTP_Server_Plugin *plugin = cls; struct HttpAddressWrapper *next; @@ -877,26 +890,27 @@ http_server_plugin_address_suggested(void *cls, const struct HttpAddress *haddr = addr; if ((NULL != plugin->ext_addr) && - GNUNET_YES == (http_common_cmp_addresses(addr, addrlen, - plugin->ext_addr->address, - plugin->ext_addr->address_length))) - { - /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ - if ((ntohl(haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != - (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) - return GNUNET_NO; /* VERIFY option not set as required! */ - return GNUNET_OK; - } + (GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, + plugin->ext_addr->address, + plugin->ext_addr-> + address_length))) ) + { + /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ + if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != + (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) + return GNUNET_NO; /* VERIFY option not set as required! */ + return GNUNET_OK; + } next = plugin->addr_head; while (NULL != (pos = next)) - { - next = pos->next; - if (GNUNET_YES == (http_common_cmp_addresses(addr, - addrlen, - pos->address, - pos->addrlen))) - return GNUNET_OK; - } + { + next = pos->next; + if (GNUNET_YES == (http_common_cmp_addresses (addr, + addrlen, + pos->address, + pos->addrlen))) + return GNUNET_OK; + } return GNUNET_NO; } @@ -912,8 +926,8 @@ http_server_plugin_address_suggested(void *cls, * @return always NULL */ static struct GNUNET_ATS_Session * -http_server_plugin_get_session(void *cls, - const struct GNUNET_HELLO_Address *address) +http_server_plugin_get_session (void *cls, + const struct GNUNET_HELLO_Address *address) { return NULL; } @@ -926,14 +940,14 @@ http_server_plugin_get_session(void *cls, * @param cls plugin as closure */ static void -server_v4_run(void *cls) +server_v4_run (void *cls) { struct HTTP_Server_Plugin *plugin = cls; plugin->server_v4_task = NULL; plugin->server_v4_immediately = GNUNET_NO; - GNUNET_assert(MHD_YES == MHD_run(plugin->server_v4)); - server_reschedule(plugin, plugin->server_v4, GNUNET_NO); + GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4)); + server_reschedule (plugin, plugin->server_v4, GNUNET_NO); } @@ -944,14 +958,14 @@ server_v4_run(void *cls) * @param cls plugin as closure */ static void -server_v6_run(void *cls) +server_v6_run (void *cls) { struct HTTP_Server_Plugin *plugin = cls; plugin->server_v6_task = NULL; plugin->server_v6_immediately = GNUNET_NO; - GNUNET_assert(MHD_YES == MHD_run(plugin->server_v6)); - server_reschedule(plugin, plugin->server_v6, GNUNET_NO); + GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6)); + server_reschedule (plugin, plugin->server_v6, GNUNET_NO); } @@ -965,11 +979,11 @@ server_v6_run(void *cls) * @return gnunet task identifier */ static struct GNUNET_SCHEDULER_Task * -server_schedule(struct HTTP_Server_Plugin *plugin, - struct MHD_Daemon *daemon_handle, - int now) +server_schedule (struct HTTP_Server_Plugin *plugin, + struct MHD_Daemon *daemon_handle, + int now) { - struct GNUNET_SCHEDULER_Task * ret; + struct GNUNET_SCHEDULER_Task *ret; fd_set rs; fd_set ws; fd_set es; @@ -985,76 +999,76 @@ server_schedule(struct HTTP_Server_Plugin *plugin, return NULL; ret = NULL; - FD_ZERO(&rs); - FD_ZERO(&ws); - FD_ZERO(&es); - wrs = GNUNET_NETWORK_fdset_create(); - wws = GNUNET_NETWORK_fdset_create(); + FD_ZERO (&rs); + FD_ZERO (&ws); + FD_ZERO (&es); + wrs = GNUNET_NETWORK_fdset_create (); + wws = GNUNET_NETWORK_fdset_create (); max = -1; - GNUNET_assert(MHD_YES == - MHD_get_fdset(daemon_handle, - &rs, - &ws, - &es, - &max)); - haveto = MHD_get_timeout(daemon_handle, &timeout); + GNUNET_assert (MHD_YES == + MHD_get_fdset (daemon_handle, + &rs, + &ws, + &es, + &max)); + haveto = MHD_get_timeout (daemon_handle, &timeout); if (haveto == MHD_YES) - { - if (timeout != last_timeout) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "SELECT Timeout changed from %llu to %llu (ms)\n", - last_timeout, timeout); - last_timeout = timeout; - } - if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value_us / 1000LL) - tv.rel_value_us = (uint64_t)timeout * 1000LL; - else - tv = GNUNET_TIME_UNIT_SECONDS; - } + { + if (timeout != last_timeout) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "SELECT Timeout changed from %llu to %llu (ms)\n", + last_timeout, timeout); + last_timeout = timeout; + } + if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value_us / 1000LL) + tv.rel_value_us = (uint64_t) timeout * 1000LL; + else + tv = GNUNET_TIME_UNIT_SECONDS; + } else tv = GNUNET_TIME_UNIT_SECONDS; /* Force immediate run, since we have outbound data to send */ if (now == GNUNET_YES) tv = GNUNET_TIME_UNIT_MILLISECONDS; - GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); - GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); + GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); + GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); if (daemon_handle == plugin->server_v4) + { + if (plugin->server_v4_task != NULL) { - if (plugin->server_v4_task != NULL) - { - GNUNET_SCHEDULER_cancel(plugin->server_v4_task); - plugin->server_v4_task = NULL; - } + GNUNET_SCHEDULER_cancel (plugin->server_v4_task); + plugin->server_v4_task = NULL; + } #if 0 - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Scheduling IPv4 server task in %llu ms\n", - tv); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling IPv4 server task in %llu ms\n", + tv); #endif - ret = - GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, - tv, wrs, wws, - &server_v4_run, plugin); - } + ret = + GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, + tv, wrs, wws, + &server_v4_run, plugin); + } if (daemon_handle == plugin->server_v6) + { + if (plugin->server_v6_task != NULL) { - if (plugin->server_v6_task != NULL) - { - GNUNET_SCHEDULER_cancel(plugin->server_v6_task); - plugin->server_v6_task = NULL; - } + GNUNET_SCHEDULER_cancel (plugin->server_v6_task); + plugin->server_v6_task = NULL; + } #if 0 - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Scheduling IPv6 server task in %llu ms\n", tv); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling IPv6 server task in %llu ms\n", tv); #endif - ret = - GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, - tv, wrs, wws, - &server_v6_run, plugin); - } - GNUNET_NETWORK_fdset_destroy(wrs); - GNUNET_NETWORK_fdset_destroy(wws); + ret = + GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, + tv, wrs, wws, + &server_v6_run, plugin); + } + GNUNET_NETWORK_fdset_destroy (wrs); + GNUNET_NETWORK_fdset_destroy (wws); return ret; } @@ -1068,41 +1082,41 @@ server_schedule(struct HTTP_Server_Plugin *plugin, * until timeout */ static void -server_reschedule(struct HTTP_Server_Plugin *plugin, - struct MHD_Daemon *server, - int now) +server_reschedule (struct HTTP_Server_Plugin *plugin, + struct MHD_Daemon *server, + int now) { if ((server == plugin->server_v4) && (plugin->server_v4 != NULL)) - { - if (GNUNET_YES == plugin->server_v4_immediately) - return; /* No rescheduling, server will run asap */ + { + if (GNUNET_YES == plugin->server_v4_immediately) + return; /* No rescheduling, server will run asap */ - if (GNUNET_YES == now) - plugin->server_v4_immediately = GNUNET_YES; + if (GNUNET_YES == now) + plugin->server_v4_immediately = GNUNET_YES; - if (plugin->server_v4_task != NULL) - { - GNUNET_SCHEDULER_cancel(plugin->server_v4_task); - plugin->server_v4_task = NULL; - } - plugin->server_v4_task = server_schedule(plugin, plugin->server_v4, now); + if (plugin->server_v4_task != NULL) + { + GNUNET_SCHEDULER_cancel (plugin->server_v4_task); + plugin->server_v4_task = NULL; } + plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now); + } if ((server == plugin->server_v6) && (plugin->server_v6 != NULL)) - { - if (GNUNET_YES == plugin->server_v6_immediately) - return; /* No rescheduling, server will run asap */ + { + if (GNUNET_YES == plugin->server_v6_immediately) + return; /* No rescheduling, server will run asap */ - if (GNUNET_YES == now) - plugin->server_v6_immediately = GNUNET_YES; + if (GNUNET_YES == now) + plugin->server_v6_immediately = GNUNET_YES; - if (plugin->server_v6_task != NULL) - { - GNUNET_SCHEDULER_cancel(plugin->server_v6_task); - plugin->server_v6_task = NULL; - } - plugin->server_v6_task = server_schedule(plugin, plugin->server_v6, now); + if (plugin->server_v6_task != NULL) + { + GNUNET_SCHEDULER_cancel (plugin->server_v6_task); + plugin->server_v6_task = NULL; } + plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now); + } } @@ -1115,7 +1129,7 @@ server_reschedule(struct HTTP_Server_Plugin *plugin, * @return keepalive factor */ static unsigned int -http_server_query_keepalive_factor(void *cls) +http_server_query_keepalive_factor (void *cls) { return 3; } @@ -1131,11 +1145,12 @@ http_server_query_keepalive_factor(void *cls) * @param session which session is being updated */ static void -http_server_plugin_update_session_timeout(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session) +http_server_plugin_update_session_timeout (void *cls, + const struct + GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session) { - server_reschedule_session_timeout(session); + server_reschedule_session_timeout (session); } @@ -1147,31 +1162,31 @@ http_server_plugin_update_session_timeout(void *cls, * @param to timeout in seconds */ static void -server_mhd_connection_timeout(struct HTTP_Server_Plugin *plugin, - struct GNUNET_ATS_Session *s, - unsigned int to) +server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, + struct GNUNET_ATS_Session *s, + unsigned int to) { /* Setting timeouts for other connections */ if (NULL != s->server_recv) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Setting timeout for %p to %u sec.\n", - s->server_recv, to); - MHD_set_connection_option(s->server_recv->mhd_conn, - MHD_CONNECTION_OPTION_TIMEOUT, - to); - server_reschedule(plugin, s->server_recv->mhd_daemon, GNUNET_NO); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Setting timeout for %p to %u sec.\n", + s->server_recv, to); + MHD_set_connection_option (s->server_recv->mhd_conn, + MHD_CONNECTION_OPTION_TIMEOUT, + to); + server_reschedule (plugin, s->server_recv->mhd_daemon, GNUNET_NO); + } if (NULL != s->server_send) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Setting timeout for %p to %u sec.\n", - s->server_send, to); - MHD_set_connection_option(s->server_send->mhd_conn, - MHD_CONNECTION_OPTION_TIMEOUT, - to); - server_reschedule(plugin, s->server_send->mhd_daemon, GNUNET_NO); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Setting timeout for %p to %u sec.\n", + s->server_send, to); + MHD_set_connection_option (s->server_send->mhd_conn, + MHD_CONNECTION_OPTION_TIMEOUT, + to); + server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO); + } } @@ -1186,11 +1201,11 @@ server_mhd_connection_timeout(struct HTTP_Server_Plugin *plugin, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -server_parse_url(struct HTTP_Server_Plugin *plugin, - const char *url, - struct GNUNET_PeerIdentity *target, - uint32_t *tag, - uint32_t *options) +server_parse_url (struct HTTP_Server_Plugin *plugin, + const char *url, + struct GNUNET_PeerIdentity *target, + uint32_t *tag, + uint32_t *options) { regmatch_t matches[4]; const char *tag_start; @@ -1205,105 +1220,105 @@ server_parse_url(struct HTTP_Server_Plugin *plugin, ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$") if (NULL == url) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - - if (regexec(&plugin->url_regex, url, 4, matches, 0)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "URL `%s' did not match regex\n", url); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + + if (regexec (&plugin->url_regex, url, 4, matches, 0)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "URL `%s' did not match regex\n", url); + return GNUNET_SYSERR; + } target_start = &url[matches[1].rm_so]; tag_start = &url[matches[2].rm_so]; /* convert tag */ - rc = strtoul(tag_start, &tag_end, 10); + rc = strtoul (tag_start, &tag_end, 10); if (&url[matches[2].rm_eo] != tag_end) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "URL tag did not line up with submatch\n"); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "URL tag did not line up with submatch\n"); + return GNUNET_SYSERR; + } if (rc == 0) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "URL tag is zero\n"); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "URL tag is zero\n"); + return GNUNET_SYSERR; + } if ((rc == ULONG_MAX) && (ERANGE == errno)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "URL tag > ULONG_MAX\n"); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "URL tag > ULONG_MAX\n"); + return GNUNET_SYSERR; + } if (rc > UINT32_MAX) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "URL tag > UINT32_MAX\n"); - return GNUNET_SYSERR; - } - (*tag) = (uint32_t)rc; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found tag `%u' in url\n", - *tag); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "URL tag > UINT32_MAX\n"); + return GNUNET_SYSERR; + } + (*tag) = (uint32_t) rc; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found tag `%u' in url\n", + *tag); /* convert peer id */ hash_length = matches[1].rm_eo - matches[1].rm_so; if (hash_length != plugin->peer_id_length) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "URL target is %u bytes, expecting %u\n", - hash_length, plugin->peer_id_length); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "URL target is %u bytes, expecting %u\n", + hash_length, plugin->peer_id_length); + return GNUNET_SYSERR; + } if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_public_key_from_string(target_start, - hash_length, - &target->public_key)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "URL target conversion failed\n"); - return GNUNET_SYSERR; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found target `%s' in URL\n", - GNUNET_i2s_full(target)); + GNUNET_CRYPTO_eddsa_public_key_from_string (target_start, + hash_length, + &target->public_key)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "URL target conversion failed\n"); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found target `%s' in URL\n", + GNUNET_i2s_full (target)); /* convert options */ if (-1 == matches[3].rm_so) + { + *options = 0; + } + else + { + rc = strtoul (&url[matches[3].rm_so + 1], &options_end, 10); + if (&url[matches[3].rm_eo] != options_end) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "URL options did not line up with submatch\n"); + return GNUNET_SYSERR; + } + if ((rc == ULONG_MAX) && (ERANGE == errno)) { - *options = 0; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "URL options > ULONG_MAX\n"); + return GNUNET_SYSERR; } - else + if (rc > UINT32_MAX) { - rc = strtoul(&url[matches[3].rm_so + 1], &options_end, 10); - if (&url[matches[3].rm_eo] != options_end) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "URL options did not line up with submatch\n"); - return GNUNET_SYSERR; - } - if ((rc == ULONG_MAX) && (ERANGE == errno)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "URL options > ULONG_MAX\n"); - return GNUNET_SYSERR; - } - if (rc > UINT32_MAX) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "URL options > UINT32_MAX\n"); - return GNUNET_SYSERR; - } - (*options) = (uint32_t)rc; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found options `%u' in url\n", - *options); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "URL options > UINT32_MAX\n"); + return GNUNET_SYSERR; } + (*options) = (uint32_t) rc; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found options `%u' in url\n", + *options); + } return GNUNET_OK; } @@ -1311,7 +1326,8 @@ server_parse_url(struct HTTP_Server_Plugin *plugin, /** * Closure for #session_tag_it(). */ -struct GNUNET_ATS_SessionTagContext { +struct GNUNET_ATS_SessionTagContext +{ /** * Set to session matching the tag. */ @@ -1333,18 +1349,18 @@ struct GNUNET_ATS_SessionTagContext { * @return #GNUNET_NO if we found the session, #GNUNET_OK if not */ static int -session_tag_it(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +session_tag_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct GNUNET_ATS_SessionTagContext *stc = cls; struct GNUNET_ATS_Session *s = value; if (s->tag == stc->tag) - { - stc->res = s; - return GNUNET_NO; - } + { + stc->res = s; + return GNUNET_NO; + } return GNUNET_YES; } @@ -1359,10 +1375,10 @@ session_tag_it(void *cls, * @return the server connecetion */ static struct ServerRequest * -server_lookup_connection(struct HTTP_Server_Plugin *plugin, - struct MHD_Connection *mhd_connection, - const char *url, - const char *method) +server_lookup_connection (struct HTTP_Server_Plugin *plugin, + struct MHD_Connection *mhd_connection, + const char *url, + const char *method) { struct GNUNET_ATS_Session *s = NULL; struct ServerRequest *sc = NULL; @@ -1376,131 +1392,131 @@ server_lookup_connection(struct HTTP_Server_Plugin *plugin, unsigned int to; enum GNUNET_NetworkType scope; - conn_info = MHD_get_connection_info(mhd_connection, - MHD_CONNECTION_INFO_CLIENT_ADDRESS); + conn_info = MHD_get_connection_info (mhd_connection, + MHD_CONNECTION_INFO_CLIENT_ADDRESS); if ((conn_info->client_addr->sa_family != AF_INET) && (conn_info->client_addr->sa_family != AF_INET6)) return NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "New %s request from %s\n", - method, - url); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New %s request from %s\n", + method, + url); stc.tag = 0; options = 0; /* make gcc happy */ if (GNUNET_SYSERR == - server_parse_url(plugin, url, &target, &stc.tag, &options)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Invalid url %s\n", url); - return NULL; - } - if (0 == strcmp(MHD_HTTP_METHOD_PUT, method)) + server_parse_url (plugin, url, &target, &stc.tag, &options)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Invalid url %s\n", url); + return NULL; + } + if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) direction = _RECEIVE; - else if (0 == strcmp(MHD_HTTP_METHOD_GET, method)) + else if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) direction = _SEND; else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Invalid method %s for request from %s\n", - method, url); - return NULL; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Invalid method %s for request from %s\n", + method, url); + return NULL; + } plugin->cur_request++; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "New %s request from %s with tag %u (%u of %u)\n", - method, - GNUNET_i2s(&target), - stc.tag, - plugin->cur_request, plugin->max_request); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New %s request from %s with tag %u (%u of %u)\n", + method, + GNUNET_i2s (&target), + stc.tag, + plugin->cur_request, plugin->max_request); /* find existing session */ stc.res = NULL; - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, - &target, - &session_tag_it, - &stc); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, + &target, + &session_tag_it, + &stc); if (NULL == (s = stc.res)) - { - /* create new session */ - addr = NULL; - switch (conn_info->client_addr->sa_family) - { - case (AF_INET): - addr = http_common_address_from_socket(plugin->protocol, - conn_info->client_addr, - sizeof(struct sockaddr_in)); - addr_len = http_common_address_get_size(addr); - scope = plugin->env->get_address_type(plugin->env->cls, - conn_info->client_addr, - sizeof(struct sockaddr_in)); - break; - - case (AF_INET6): - addr = http_common_address_from_socket(plugin->protocol, - conn_info->client_addr, - sizeof(struct sockaddr_in6)); - addr_len = http_common_address_get_size(addr); - scope = plugin->env->get_address_type(plugin->env->cls, - conn_info->client_addr, - sizeof(struct sockaddr_in6)); - break; - - default: - /* external host name */ - return NULL; - } - s = GNUNET_new(struct GNUNET_ATS_Session); - s->target = target; - s->plugin = plugin; - s->scope = scope; - s->address = GNUNET_HELLO_address_allocate(&s->target, - PLUGIN_NAME, - addr, - addr_len, - GNUNET_HELLO_ADDRESS_INFO_INBOUND); - s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; - s->tag = stc.tag; - s->timeout = GNUNET_TIME_relative_to_absolute(HTTP_SERVER_SESSION_TIMEOUT); - s->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_SERVER_SESSION_TIMEOUT, - &server_session_timeout, - s); - (void)GNUNET_CONTAINER_multipeermap_put(plugin->sessions, + { + /* create new session */ + addr = NULL; + switch (conn_info->client_addr->sa_family) + { + case (AF_INET): + addr = http_common_address_from_socket (plugin->protocol, + conn_info->client_addr, + sizeof(struct sockaddr_in)); + addr_len = http_common_address_get_size (addr); + scope = plugin->env->get_address_type (plugin->env->cls, + conn_info->client_addr, + sizeof(struct sockaddr_in)); + break; + + case (AF_INET6): + addr = http_common_address_from_socket (plugin->protocol, + conn_info->client_addr, + sizeof(struct sockaddr_in6)); + addr_len = http_common_address_get_size (addr); + scope = plugin->env->get_address_type (plugin->env->cls, + conn_info->client_addr, + sizeof(struct sockaddr_in6)); + break; + + default: + /* external host name */ + return NULL; + } + s = GNUNET_new (struct GNUNET_ATS_Session); + s->target = target; + s->plugin = plugin; + s->scope = scope; + s->address = GNUNET_HELLO_address_allocate (&s->target, + PLUGIN_NAME, + addr, + addr_len, + GNUNET_HELLO_ADDRESS_INFO_INBOUND); + s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; + s->tag = stc.tag; + s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_SERVER_SESSION_TIMEOUT); + s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_SERVER_SESSION_TIMEOUT, + &server_session_timeout, + s); + (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessions, &s->target, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - notify_session_monitor(plugin, - s, - GNUNET_TRANSPORT_SS_INIT); - notify_session_monitor(plugin, - s, - GNUNET_TRANSPORT_SS_HANDSHAKE); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Creating new session %p for peer `%s' connecting from `%s'\n", - s, GNUNET_i2s(&target), - http_common_plugin_address_to_string(plugin->protocol, + notify_session_monitor (plugin, + s, + GNUNET_TRANSPORT_SS_INIT); + notify_session_monitor (plugin, + s, + GNUNET_TRANSPORT_SS_HANDSHAKE); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Creating new session %p for peer `%s' connecting from `%s'\n", + s, GNUNET_i2s (&target), + http_common_plugin_address_to_string (plugin->protocol, addr, addr_len)); - GNUNET_free_non_null(addr); - } + GNUNET_free_non_null (addr); + } if ((_RECEIVE == direction) && (NULL != s->server_recv)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Duplicate PUT request from `%s' tag %u, dismissing new request\n", - GNUNET_i2s(&target), - stc.tag); - return NULL; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Duplicate PUT request from `%s' tag %u, dismissing new request\n", + GNUNET_i2s (&target), + stc.tag); + return NULL; + } if ((_SEND == direction) && (NULL != s->server_send)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Duplicate GET request from `%s' tag %u, dismissing new request\n", - GNUNET_i2s(&target), - stc.tag); - return NULL; - } - sc = GNUNET_new(struct ServerRequest); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Duplicate GET request from `%s' tag %u, dismissing new request\n", + GNUNET_i2s (&target), + stc.tag); + return NULL; + } + sc = GNUNET_new (struct ServerRequest); if (conn_info->client_addr->sa_family == AF_INET) sc->mhd_daemon = plugin->server_v4; if (conn_info->client_addr->sa_family == AF_INET6) @@ -1511,30 +1527,30 @@ server_lookup_connection(struct HTTP_Server_Plugin *plugin, sc->session = s; sc->options = options; if (direction == _SEND) - { - s->server_send = sc; - } + { + s->server_send = sc; + } if (direction == _RECEIVE) - { - s->server_recv = sc; - } + { + s->server_recv = sc; + } if ((GNUNET_NO == s->known_to_service) && (NULL != s->server_send) && (NULL != s->server_recv)) - { - s->known_to_service = GNUNET_YES; - notify_session_monitor(plugin, - s, - GNUNET_TRANSPORT_SS_UP); - plugin->env->session_start(plugin->env->cls, - s->address, - s, - s->scope); - } + { + s->known_to_service = GNUNET_YES; + notify_session_monitor (plugin, + s, + GNUNET_TRANSPORT_SS_UP); + plugin->env->session_start (plugin->env->cls, + s->address, + s, + s->scope); + } to = (HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL); - server_mhd_connection_timeout(plugin, s, to); + server_mhd_connection_timeout (plugin, s, to); return sc; } @@ -1549,10 +1565,10 @@ server_lookup_connection(struct HTTP_Server_Plugin *plugin, * @return bytes written to @a buf */ static ssize_t -server_send_callback(void *cls, - uint64_t pos, - char *buf, - size_t max) +server_send_callback (void *cls, + uint64_t pos, + char *buf, + size_t max) { struct ServerRequest *sc = cls; struct GNUNET_ATS_Session *s = sc->session; @@ -1561,79 +1577,79 @@ server_send_callback(void *cls, char *stat_txt; if (NULL == s) - { - /* session is disconnecting */ - return 0; - } + { + /* session is disconnecting */ + return 0; + } sc = s->server_send; if (NULL == sc) return 0; msg = s->msg_head; if (NULL != msg) - { - /* sending */ - bytes_read = GNUNET_MIN(msg->size - msg->pos, - max); - GNUNET_memcpy(buf, &msg->buf[msg->pos], bytes_read); - msg->pos += bytes_read; - - /* removing message */ - if (msg->pos == msg->size) - { - GNUNET_CONTAINER_DLL_remove(s->msg_head, - s->msg_tail, - msg); - if (NULL != msg->transmit_cont) - msg->transmit_cont(msg->transmit_cont_cls, &s->target, GNUNET_OK, - msg->size, msg->size + msg->overhead); - GNUNET_assert(s->msgs_in_queue > 0); - s->msgs_in_queue--; - GNUNET_assert(s->bytes_in_queue >= msg->size); - s->bytes_in_queue -= msg->size; - GNUNET_free(msg); - notify_session_monitor(s->plugin, - s, - GNUNET_TRANSPORT_SS_UPDATE); - } + { + /* sending */ + bytes_read = GNUNET_MIN (msg->size - msg->pos, + max); + GNUNET_memcpy (buf, &msg->buf[msg->pos], bytes_read); + msg->pos += bytes_read; + + /* removing message */ + if (msg->pos == msg->size) + { + GNUNET_CONTAINER_DLL_remove (s->msg_head, + s->msg_tail, + msg); + if (NULL != msg->transmit_cont) + msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK, + msg->size, msg->size + msg->overhead); + GNUNET_assert (s->msgs_in_queue > 0); + s->msgs_in_queue--; + GNUNET_assert (s->bytes_in_queue >= msg->size); + s->bytes_in_queue -= msg->size; + GNUNET_free (msg); + notify_session_monitor (s->plugin, + s, + GNUNET_TRANSPORT_SS_UPDATE); } + } if (0 < bytes_read) - { - sc->connected = GNUNET_YES; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sent %u bytes to peer `%s' with session %p \n", - bytes_read, - GNUNET_i2s(&s->target), - s); - GNUNET_asprintf(&stat_txt, - "# bytes currently in %s_server buffers", - s->plugin->protocol); - GNUNET_STATISTICS_update(s->plugin->env->stats, - stat_txt, - -bytes_read, - GNUNET_NO); - GNUNET_free(stat_txt); - GNUNET_asprintf(&stat_txt, - "# bytes transmitted via %s_server", - s->plugin->protocol); - GNUNET_STATISTICS_update(s->plugin->env->stats, - stat_txt, bytes_read, GNUNET_NO); - GNUNET_free(stat_txt); - } + { + sc->connected = GNUNET_YES; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sent %u bytes to peer `%s' with session %p \n", + bytes_read, + GNUNET_i2s (&s->target), + s); + GNUNET_asprintf (&stat_txt, + "# bytes currently in %s_server buffers", + s->plugin->protocol); + GNUNET_STATISTICS_update (s->plugin->env->stats, + stat_txt, + -bytes_read, + GNUNET_NO); + GNUNET_free (stat_txt); + GNUNET_asprintf (&stat_txt, + "# bytes transmitted via %s_server", + s->plugin->protocol); + GNUNET_STATISTICS_update (s->plugin->env->stats, + stat_txt, bytes_read, GNUNET_NO); + GNUNET_free (stat_txt); + } else if ((sc->options & OPTION_LONG_POLL) && sc->connected) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Completing GET response to peer `%s' with session %p\n", - GNUNET_i2s(&s->target), - s); - return MHD_CONTENT_READER_END_OF_STREAM; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Completing GET response to peer `%s' with session %p\n", + GNUNET_i2s (&s->target), + s); + return MHD_CONTENT_READER_END_OF_STREAM; + } else - { - MHD_suspend_connection(s->server_send->mhd_conn); - s->server_send->suspended = true; - return 0; - } + { + MHD_suspend_connection (s->server_send->mhd_conn); + s->server_send->suspended = true; + return 0; + } return bytes_read; } @@ -1646,8 +1662,8 @@ server_send_callback(void *cls, * @return #GNUNET_OK (all OK) */ static int -server_receive_mst_cb(void *cls, - const struct GNUNET_MessageHeader *message) +server_receive_mst_cb (void *cls, + const struct GNUNET_MessageHeader *message) { struct GNUNET_ATS_Session *s = cls; struct HTTP_Server_Plugin *plugin = s->plugin; @@ -1655,41 +1671,41 @@ server_receive_mst_cb(void *cls, char *stat_txt; if (GNUNET_NO == s->known_to_service) - { - s->known_to_service = GNUNET_YES; - plugin->env->session_start(plugin->env->cls, - s->address, - s, - s->scope); - notify_session_monitor(plugin, - s, - GNUNET_TRANSPORT_SS_UP); - } - delay = plugin->env->receive(plugin->env->cls, - s->address, - s, - message); - GNUNET_asprintf(&stat_txt, - "# bytes received via %s_server", - plugin->protocol); - GNUNET_STATISTICS_update(plugin->env->stats, - stat_txt, - ntohs(message->size), - GNUNET_NO); - GNUNET_free(stat_txt); - s->next_receive = GNUNET_TIME_relative_to_absolute(delay); + { + s->known_to_service = GNUNET_YES; + plugin->env->session_start (plugin->env->cls, + s->address, + s, + s->scope); + notify_session_monitor (plugin, + s, + GNUNET_TRANSPORT_SS_UP); + } + delay = plugin->env->receive (plugin->env->cls, + s->address, + s, + message); + GNUNET_asprintf (&stat_txt, + "# bytes received via %s_server", + plugin->protocol); + GNUNET_STATISTICS_update (plugin->env->stats, + stat_txt, + ntohs (message->size), + GNUNET_NO); + GNUNET_free (stat_txt); + s->next_receive = GNUNET_TIME_relative_to_absolute (delay); if (delay.rel_value_us > 0) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Peer `%s' address `%s' next read delayed for %s\n", - GNUNET_i2s(&s->target), - http_common_plugin_address_to_string(plugin->protocol, + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Peer `%s' address `%s' next read delayed for %s\n", + GNUNET_i2s (&s->target), + http_common_plugin_address_to_string (plugin->protocol, s->address->address, s->address->address_length), - GNUNET_STRINGS_relative_time_to_string(delay, + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); - } - server_reschedule_session_timeout(s); + } + server_reschedule_session_timeout (s); return GNUNET_OK; } @@ -1701,17 +1717,17 @@ server_receive_mst_cb(void *cls, * @param response response object to modify */ static void -add_cors_headers(struct MHD_Response *response) +add_cors_headers (struct MHD_Response *response) { - MHD_add_response_header(response, - "Access-Control-Allow-Origin", - "*"); - MHD_add_response_header(response, - "Access-Control-Allow-Methods", - "GET, PUT, OPTIONS"); - MHD_add_response_header(response, - "Access-Control-Max-Age", - "86400"); + MHD_add_response_header (response, + "Access-Control-Allow-Origin", + "*"); + MHD_add_response_header (response, + "Access-Control-Allow-Methods", + "GET, PUT, OPTIONS"); + MHD_add_response_header (response, + "Access-Control-Max-Age", + "86400"); } @@ -1729,14 +1745,14 @@ add_cors_headers(struct MHD_Response *response) * @return MHD_YES if connection is accepted, MHD_NO on reject */ static int -server_access_cb(void *cls, - struct MHD_Connection *mhd_connection, - const char *url, - const char *method, - const char *version, - const char *upload_data, - size_t *upload_data_size, - void **httpSessionCache) +server_access_cb (void *cls, + struct MHD_Connection *mhd_connection, + const char *url, + const char *method, + const char *version, + const char *upload_data, + size_t *upload_data_size, + void **httpSessionCache) { struct HTTP_Server_Plugin *plugin = cls; struct ServerRequest *sc = *httpSessionCache; @@ -1744,166 +1760,169 @@ server_access_cb(void *cls, struct MHD_Response *response; int res = MHD_YES; - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"), - sc, - plugin->cur_request, - plugin->max_request, - method, - version, - url, - (*upload_data_size)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ( + "Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"), + sc, + plugin->cur_request, + plugin->max_request, + method, + version, + url, + (*upload_data_size)); if (NULL == sc) - { - /* CORS pre-flight request */ - if (0 == strcmp(MHD_HTTP_METHOD_OPTIONS, method)) - { - response = MHD_create_response_from_buffer(0, NULL, - MHD_RESPMEM_PERSISTENT); - add_cors_headers(response); - res = MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); - MHD_destroy_response(response); - return res; - } - /* new connection */ - sc = server_lookup_connection(plugin, mhd_connection, url, method); - if (NULL != sc) - { - /* attach to new / existing session */ - (*httpSessionCache) = sc; - } - else - { - /* existing session already has matching connection, refuse */ - response = MHD_create_response_from_buffer(strlen(HTTP_ERROR_RESPONSE), - HTTP_ERROR_RESPONSE, - MHD_RESPMEM_PERSISTENT); - MHD_add_response_header(response, - MHD_HTTP_HEADER_CONTENT_TYPE, - "text/html"); - add_cors_headers(response); - res = MHD_queue_response(mhd_connection, MHD_HTTP_NOT_FOUND, response); - MHD_destroy_response(response); - return res; - } - } + { + /* CORS pre-flight request */ + if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method)) + { + response = MHD_create_response_from_buffer (0, NULL, + MHD_RESPMEM_PERSISTENT); + add_cors_headers (response); + res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); + MHD_destroy_response (response); + return res; + } + /* new connection */ + sc = server_lookup_connection (plugin, mhd_connection, url, method); + if (NULL != sc) + { + /* attach to new / existing session */ + (*httpSessionCache) = sc; + } + else + { + /* existing session already has matching connection, refuse */ + response = MHD_create_response_from_buffer (strlen (HTTP_ERROR_RESPONSE), + HTTP_ERROR_RESPONSE, + MHD_RESPMEM_PERSISTENT); + MHD_add_response_header (response, + MHD_HTTP_HEADER_CONTENT_TYPE, + "text/html"); + add_cors_headers (response); + res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); + MHD_destroy_response (response); + return res; + } + } /* 'old' connection */ if (NULL == (s = sc->session)) - { - /* Session was already disconnected; - sent HTTP/1.1: 200 OK as response */ - response = MHD_create_response_from_buffer(strlen("Thank you!"), - "Thank you!", - MHD_RESPMEM_PERSISTENT); - add_cors_headers(response); - MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); - MHD_destroy_response(response); - return MHD_YES; - } + { + /* Session was already disconnected; + sent HTTP/1.1: 200 OK as response */ + response = MHD_create_response_from_buffer (strlen ("Thank you!"), + "Thank you!", + MHD_RESPMEM_PERSISTENT); + add_cors_headers (response); + MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); + MHD_destroy_response (response); + return MHD_YES; + } if (sc->direction == _SEND) - { - response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 32 * 1024, - &server_send_callback, sc, NULL); - add_cors_headers(response); - MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); - MHD_destroy_response(response); + { + response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 32 * 1024, + &server_send_callback, sc, + NULL); + add_cors_headers (response); + MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); + MHD_destroy_response (response); + return MHD_YES; + } + if (sc->direction == _RECEIVE) + { + if ((*upload_data_size == 0) && (sc->connected == GNUNET_NO)) + { + /* (*upload_data_size == 0) first callback when header are passed */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n", + s, sc, + GNUNET_i2s (&s->target), + http_common_plugin_address_to_string (plugin->protocol, + s->address->address, + s->address->address_length)); + sc->connected = GNUNET_YES; return MHD_YES; } - if (sc->direction == _RECEIVE) - { - if ((*upload_data_size == 0) && (sc->connected == GNUNET_NO)) - { - /* (*upload_data_size == 0) first callback when header are passed */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n", - s, sc, - GNUNET_i2s(&s->target), - http_common_plugin_address_to_string(plugin->protocol, - s->address->address, - s->address->address_length)); - sc->connected = GNUNET_YES; - return MHD_YES; - } - else if ((*upload_data_size == 0) && (sc->connected == GNUNET_YES)) - { - /* (*upload_data_size == 0) when upload is complete */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n", - s, sc, - GNUNET_i2s(&s->target), - http_common_plugin_address_to_string(plugin->protocol, - s->address->address, - s->address->address_length)); - sc->connected = GNUNET_NO; - /* Sent HTTP/1.1: 200 OK as PUT Response\ */ - response = MHD_create_response_from_buffer(strlen("Thank you!"), - "Thank you!", - MHD_RESPMEM_PERSISTENT); - add_cors_headers(response); - MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); - MHD_destroy_response(response); - return MHD_YES; - } - else if ((*upload_data_size > 0) && (sc->connected == GNUNET_YES)) + else if ((*upload_data_size == 0) && (sc->connected == GNUNET_YES)) + { + /* (*upload_data_size == 0) when upload is complete */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n", + s, sc, + GNUNET_i2s (&s->target), + http_common_plugin_address_to_string (plugin->protocol, + s->address->address, + s->address->address_length)); + sc->connected = GNUNET_NO; + /* Sent HTTP/1.1: 200 OK as PUT Response\ */ + response = MHD_create_response_from_buffer (strlen ("Thank you!"), + "Thank you!", + MHD_RESPMEM_PERSISTENT); + add_cors_headers (response); + MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); + MHD_destroy_response (response); + return MHD_YES; + } + else if ((*upload_data_size > 0) && (sc->connected == GNUNET_YES)) + { + struct GNUNET_TIME_Relative delay; + + /* (*upload_data_size > 0) for every segment received */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n", + s, sc, + GNUNET_i2s (&s->target), + http_common_plugin_address_to_string (plugin->protocol, + s->address->address, + s->address->address_length), + *upload_data_size); + delay = GNUNET_TIME_absolute_get_remaining (s->next_receive); + if (0 == delay.rel_value_us) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "PUT with %u bytes forwarded to MST\n", + *upload_data_size); + if (s->msg_tk == NULL) { - struct GNUNET_TIME_Relative delay; - - /* (*upload_data_size > 0) for every segment received */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n", - s, sc, - GNUNET_i2s(&s->target), - http_common_plugin_address_to_string(plugin->protocol, - s->address->address, - s->address->address_length), - *upload_data_size); - delay = GNUNET_TIME_absolute_get_remaining(s->next_receive); - if (0 == delay.rel_value_us) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "PUT with %u bytes forwarded to MST\n", - *upload_data_size); - if (s->msg_tk == NULL) - { - s->msg_tk = GNUNET_MST_create(&server_receive_mst_cb, - s); - } - GNUNET_MST_from_buffer(s->msg_tk, - upload_data, - *upload_data_size, - GNUNET_NO, GNUNET_NO); - server_mhd_connection_timeout(plugin, s, - GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us / 1000LL - / 1000LL); - (*upload_data_size) = 0; - } - else - { - /* delay processing */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %s\n", - s, - sc, - GNUNET_STRINGS_relative_time_to_string(delay, - GNUNET_YES)); - GNUNET_assert(s->server_recv->mhd_conn == mhd_connection); - MHD_suspend_connection(s->server_recv->mhd_conn); - s->server_recv->suspended = true; - if (NULL == s->recv_wakeup_task) - s->recv_wakeup_task - = GNUNET_SCHEDULER_add_delayed(delay, - &server_wake_up, - s); - } - return MHD_YES; + s->msg_tk = GNUNET_MST_create (&server_receive_mst_cb, + s); } + GNUNET_MST_from_buffer (s->msg_tk, + upload_data, + *upload_data_size, + GNUNET_NO, GNUNET_NO); + server_mhd_connection_timeout (plugin, s, + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT. + rel_value_us / 1000LL + / 1000LL); + (*upload_data_size) = 0; + } else - { - GNUNET_break(0); - return MHD_NO; - } + { + /* delay processing */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %s\n", + s, + sc, + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); + GNUNET_assert (s->server_recv->mhd_conn == mhd_connection); + MHD_suspend_connection (s->server_recv->mhd_conn); + s->server_recv->suspended = true; + if (NULL == s->recv_wakeup_task) + s->recv_wakeup_task + = GNUNET_SCHEDULER_add_delayed (delay, + &server_wake_up, + s); + } + return MHD_YES; } + else + { + GNUNET_break (0); + return MHD_NO; + } + } return res; } @@ -1916,54 +1935,56 @@ server_access_cb(void *cls, * @param httpSessionCache the pointer to distinguish */ static void -server_disconnect_cb(void *cls, - struct MHD_Connection *connection, - void **httpSessionCache) +server_disconnect_cb (void *cls, + struct MHD_Connection *connection, + void **httpSessionCache) { struct HTTP_Server_Plugin *plugin = cls; struct ServerRequest *sc = *httpSessionCache; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Disconnect for connection %p\n", - sc); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Disconnect for connection %p\n", + sc); if (NULL == sc) - { - /* CORS pre-flight request finished */ - return; - } + { + /* CORS pre-flight request finished */ + return; + } if (NULL != sc->session) - { - if (sc->direction == _SEND) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Peer `%s' connection %p, GET on address `%s' disconnected\n", - GNUNET_i2s(&sc->session->target), - sc->session->server_send, - http_common_plugin_address_to_string(plugin->protocol, - sc->session->address->address, - sc->session->address->address_length)); - - sc->session->server_send = NULL; - } - else if (sc->direction == _RECEIVE) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Peer `%s' connection %p PUT on address `%s' disconnected\n", - GNUNET_i2s(&sc->session->target), - sc->session->server_recv, - http_common_plugin_address_to_string(plugin->protocol, - sc->session->address->address, - sc->session->address->address_length)); - sc->session->server_recv = NULL; - if (NULL != sc->session->msg_tk) - { - GNUNET_MST_destroy(sc->session->msg_tk); - sc->session->msg_tk = NULL; - } - } - } - GNUNET_free(sc); + { + if (sc->direction == _SEND) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Peer `%s' connection %p, GET on address `%s' disconnected\n", + GNUNET_i2s (&sc->session->target), + sc->session->server_send, + http_common_plugin_address_to_string (plugin->protocol, + sc->session->address->address, + sc->session->address-> + address_length)); + + sc->session->server_send = NULL; + } + else if (sc->direction == _RECEIVE) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Peer `%s' connection %p PUT on address `%s' disconnected\n", + GNUNET_i2s (&sc->session->target), + sc->session->server_recv, + http_common_plugin_address_to_string (plugin->protocol, + sc->session->address->address, + sc->session->address-> + address_length)); + sc->session->server_recv = NULL; + if (NULL != sc->session->msg_tk) + { + GNUNET_MST_destroy (sc->session->msg_tk); + sc->session->msg_tk = NULL; + } + } + } + GNUNET_free (sc); plugin->cur_request--; } @@ -1978,10 +1999,10 @@ server_disconnect_cb(void *cls, * @see #MHD_OPTION_NOTIFY_CONNECTION */ static void -server_connection_cb(void *cls, - struct MHD_Connection *connection, - void **socket_context, - enum MHD_ConnectionNotificationCode toe) +server_connection_cb (void *cls, + struct MHD_Connection *connection, + void **socket_context, + enum MHD_ConnectionNotificationCode toe) { struct HTTP_Server_Plugin *plugin = cls; const union MHD_ConnectionInfo *info; @@ -1990,12 +2011,12 @@ server_connection_cb(void *cls, return; /* Reschedule to remove closed socket from our select set */ - info = MHD_get_connection_info(connection, - MHD_CONNECTION_INFO_DAEMON); - GNUNET_assert(NULL != info); - server_reschedule(plugin, - info->daemon, - GNUNET_YES); + info = MHD_get_connection_info (connection, + MHD_CONNECTION_INFO_DAEMON); + GNUNET_assert (NULL != info); + server_reschedule (plugin, + info->daemon, + GNUNET_YES); } @@ -2008,27 +2029,28 @@ server_connection_cb(void *cls, * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected */ static int -server_accept_cb(void *cls, - const struct sockaddr *addr, - socklen_t addr_len) +server_accept_cb (void *cls, + const struct sockaddr *addr, + socklen_t addr_len) { struct HTTP_Server_Plugin *plugin = cls; if (plugin->cur_request <= plugin->max_request) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("Accepting connection (%u of %u) from `%s'\n"), - plugin->cur_request, plugin->max_request, - GNUNET_a2s(addr, addr_len)); - return MHD_YES; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ("Accepting connection (%u of %u) from `%s'\n"), + plugin->cur_request, plugin->max_request, + GNUNET_a2s (addr, addr_len)); + return MHD_YES; + } else - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Server reached maximum number connections (%u), rejecting new connection\n"), - plugin->max_request); - return MHD_NO; - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ( + "Server reached maximum number connections (%u), rejecting new connection\n"), + plugin->max_request); + return MHD_NO; + } } @@ -2041,19 +2063,19 @@ server_accept_cb(void *cls, * will be called by MHD) */ static void -server_log(void *arg, - const char *fmt, - va_list ap) +server_log (void *arg, + const char *fmt, + va_list ap) { char text[1024]; - vsnprintf(text, - sizeof(text), - fmt, - ap); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Server: %s\n", - text); + vsnprintf (text, + sizeof(text), + fmt, + ap); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Server: %s\n", + text); } @@ -2065,32 +2087,32 @@ server_log(void *arg, * @return content of the file */ static char * -server_load_file(const char *file) +server_load_file (const char *file) { struct GNUNET_DISK_FileHandle *gn_file; uint64_t fsize; char *text = NULL; - if (GNUNET_OK != GNUNET_DISK_file_size(file, - &fsize, GNUNET_NO, GNUNET_YES)) + if (GNUNET_OK != GNUNET_DISK_file_size (file, + &fsize, GNUNET_NO, GNUNET_YES)) return NULL; - text = GNUNET_malloc(fsize + 1); + text = GNUNET_malloc (fsize + 1); gn_file = - GNUNET_DISK_file_open(file, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_USER_READ); + GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_USER_READ); if (NULL == gn_file) - { - GNUNET_free(text); - return NULL; - } - if (GNUNET_SYSERR == GNUNET_DISK_file_read(gn_file, text, fsize)) - { - GNUNET_free(text); - GNUNET_DISK_file_close(gn_file); - return NULL; - } + { + GNUNET_free (text); + return NULL; + } + if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fsize)) + { + GNUNET_free (text); + GNUNET_DISK_file_close (gn_file); + return NULL; + } text[fsize] = '\0'; - GNUNET_DISK_file_close(gn_file); + GNUNET_DISK_file_close (gn_file); return text; } #endif @@ -2104,7 +2126,7 @@ server_load_file(const char *file) * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -server_load_certificate(struct HTTP_Server_Plugin *plugin) +server_load_certificate (struct HTTP_Server_Plugin *plugin) { int res = GNUNET_OK; char *key_file; @@ -2112,110 +2134,112 @@ server_load_certificate(struct HTTP_Server_Plugin *plugin) if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename(plugin->env->cfg, - plugin->name, - "KEY_FILE", &key_file)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - plugin->name, "CERT_FILE"); - return GNUNET_SYSERR; - } + GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, + plugin->name, + "KEY_FILE", &key_file)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + plugin->name, "CERT_FILE"); + return GNUNET_SYSERR; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename(plugin->env->cfg, - plugin->name, - "CERT_FILE", &cert_file)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - plugin->name, "CERT_FILE"); - GNUNET_free(key_file); - return GNUNET_SYSERR; - } + GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, + plugin->name, + "CERT_FILE", &cert_file)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + plugin->name, "CERT_FILE"); + GNUNET_free (key_file); + return GNUNET_SYSERR; + } /* Get crypto init string from config. If not present, use * default values */ if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, - plugin->name, - "CRYPTO_INIT", - &plugin->crypto_init)) - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Using crypto init string `%s'\n", - plugin->crypto_init); + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, + plugin->name, + "CRYPTO_INIT", + &plugin->crypto_init)) + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Using crypto init string `%s'\n", + plugin->crypto_init); else - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Using default crypto init string \n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Using default crypto init string \n"); /* read key & certificates from file */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Trying to loading TLS certificate from key-file `%s' cert-file`%s'\n", - key_file, cert_file); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Trying to loading TLS certificate from key-file `%s' cert-file`%s'\n", + key_file, cert_file); - plugin->key = server_load_file(key_file); - plugin->cert = server_load_file(cert_file); - - if ((plugin->key == NULL) || (plugin->cert == NULL)) - { - struct GNUNET_OS_Process *cert_creation; - - GNUNET_free_non_null(plugin->key); - plugin->key = NULL; - GNUNET_free_non_null(plugin->cert); - plugin->cert = NULL; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "No usable TLS certificate found, creating certificate\n"); - errno = 0; - cert_creation = - GNUNET_OS_start_process(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, - NULL, NULL, NULL, - "gnunet-transport-certificate-creation", - "gnunet-transport-certificate-creation", - key_file, - cert_file, - NULL); - if (NULL == cert_creation) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n")); - GNUNET_free(key_file); - GNUNET_free(cert_file); - - GNUNET_free_non_null(plugin->key); - plugin->key = NULL; - GNUNET_free_non_null(plugin->cert); - plugin->cert = NULL; - GNUNET_free_non_null(plugin->crypto_init); - plugin->crypto_init = NULL; - - return GNUNET_SYSERR; - } - GNUNET_assert(GNUNET_OK == GNUNET_OS_process_wait(cert_creation)); - GNUNET_OS_process_destroy(cert_creation); - - plugin->key = server_load_file(key_file); - plugin->cert = server_load_file(cert_file); - } + plugin->key = server_load_file (key_file); + plugin->cert = server_load_file (cert_file); if ((plugin->key == NULL) || (plugin->cert == NULL)) + { + struct GNUNET_OS_Process *cert_creation; + + GNUNET_free_non_null (plugin->key); + plugin->key = NULL; + GNUNET_free_non_null (plugin->cert); + plugin->cert = NULL; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "No usable TLS certificate found, creating certificate\n"); + errno = 0; + cert_creation = + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + NULL, NULL, NULL, + "gnunet-transport-certificate-creation", + "gnunet-transport-certificate-creation", + key_file, + cert_file, + NULL); + if (NULL == cert_creation) { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("No usable TLS certificate found and creating one at `%s/%s' failed!\n"), - key_file, cert_file); - GNUNET_free(key_file); - GNUNET_free(cert_file); + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ( + "Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n")); + GNUNET_free (key_file); + GNUNET_free (cert_file); - GNUNET_free_non_null(plugin->key); + GNUNET_free_non_null (plugin->key); plugin->key = NULL; - GNUNET_free_non_null(plugin->cert); + GNUNET_free_non_null (plugin->cert); plugin->cert = NULL; - GNUNET_free_non_null(plugin->crypto_init); + GNUNET_free_non_null (plugin->crypto_init); plugin->crypto_init = NULL; return GNUNET_SYSERR; } - GNUNET_free(key_file); - GNUNET_free(cert_file); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "TLS certificate loaded\n"); + GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (cert_creation)); + GNUNET_OS_process_destroy (cert_creation); + + plugin->key = server_load_file (key_file); + plugin->cert = server_load_file (cert_file); + } + + if ((plugin->key == NULL) || (plugin->cert == NULL)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ( + "No usable TLS certificate found and creating one at `%s/%s' failed!\n"), + key_file, cert_file); + GNUNET_free (key_file); + GNUNET_free (cert_file); + + GNUNET_free_non_null (plugin->key); + plugin->key = NULL; + GNUNET_free_non_null (plugin->cert); + plugin->cert = NULL; + GNUNET_free_non_null (plugin->crypto_init); + plugin->crypto_init = NULL; + + return GNUNET_SYSERR; + } + GNUNET_free (key_file); + GNUNET_free (cert_file); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "TLS certificate loaded\n"); return res; } #endif @@ -2231,40 +2255,40 @@ server_load_certificate(struct HTTP_Server_Plugin *plugin) * @return NULL on error */ static struct MHD_Daemon * -run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin, - const struct sockaddr_in *addr, - int v6) +run_mhd_start_daemon (struct HTTP_Server_Plugin *plugin, + const struct sockaddr_in *addr, + int v6) { struct MHD_Daemon *server; unsigned int timeout; #if MHD_VERSION >= 0x00090E00 timeout = HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL / 1000LL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "MHD can set timeout per connection! Default time out %u sec.\n", - timeout); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "MHD can set timeout per connection! Default time out %u sec.\n", + timeout); #else timeout = HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL; - LOG(GNUNET_ERROR_TYPE_WARNING, - "MHD cannot set timeout per connection! Default time out %u sec.\n", - timeout); + LOG (GNUNET_ERROR_TYPE_WARNING, + "MHD cannot set timeout per connection! Default time out %u sec.\n", + timeout); #endif - server = MHD_start_daemon( + server = MHD_start_daemon ( #if VERBOSE_SERVER MHD_USE_DEBUG | #endif #if BUILD_HTTPS MHD_USE_SSL | #endif - MHD_USE_SUSPEND_RESUME | - v6, + MHD_USE_SUSPEND_RESUME + | v6, plugin->port, &server_accept_cb, plugin, &server_access_cb, plugin, MHD_OPTION_SOCK_ADDR, addr, MHD_OPTION_CONNECTION_LIMIT, - (unsigned int)plugin->max_request, + (unsigned int) plugin->max_request, #if BUILD_HTTPS MHD_OPTION_HTTPS_PRIORITIES, plugin->crypto_init, @@ -2276,8 +2300,8 @@ run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin, MHD_OPTION_CONNECTION_TIMEOUT, timeout, MHD_OPTION_CONNECTION_MEMORY_LIMIT, - (size_t)(2 * - GNUNET_MAX_MESSAGE_SIZE), + (size_t) (2 + * GNUNET_MAX_MESSAGE_SIZE), MHD_OPTION_NOTIFY_COMPLETED, &server_disconnect_cb, plugin, MHD_OPTION_NOTIFY_CONNECTION, @@ -2288,24 +2312,24 @@ run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin, #ifdef TCP_STEALTH if ((NULL != server) && (0 != (plugin->options & HTTP_OPTIONS_TCP_STEALTH))) - { - const union MHD_DaemonInfo *di; + { + const union MHD_DaemonInfo *di; - di = MHD_get_daemon_info(server, - MHD_DAEMON_INFO_LISTEN_FD, - NULL); - if ((0 != setsockopt((int)di->listen_fd, - IPPROTO_TCP, - TCP_STEALTH, - plugin->env->my_identity, - sizeof(struct GNUNET_PeerIdentity)))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("TCP_STEALTH not supported on this platform.\n")); - MHD_stop_daemon(server); - server = NULL; - } + di = MHD_get_daemon_info (server, + MHD_DAEMON_INFO_LISTEN_FD, + NULL); + if ((0 != setsockopt ((int) di->listen_fd, + IPPROTO_TCP, + TCP_STEALTH, + plugin->env->my_identity, + sizeof(struct GNUNET_PeerIdentity)))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("TCP_STEALTH not supported on this platform.\n")); + MHD_stop_daemon (server); + server = NULL; } + } #endif return server; } @@ -2318,76 +2342,79 @@ run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin, * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -server_start(struct HTTP_Server_Plugin *plugin) +server_start (struct HTTP_Server_Plugin *plugin) { const char *msg; - GNUNET_assert(NULL != plugin); + GNUNET_assert (NULL != plugin); #if BUILD_HTTPS - if (GNUNET_SYSERR == server_load_certificate(plugin)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Could not load or create server certificate! Loading plugin failed!\n")); - return GNUNET_SYSERR; - } + if (GNUNET_SYSERR == server_load_certificate (plugin)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ( + "Could not load or create server certificate! Loading plugin failed!\n")); + return GNUNET_SYSERR; + } #endif plugin->server_v4 = NULL; if (GNUNET_YES == plugin->use_ipv4) - { - plugin->server_v4 - = run_mhd_start_daemon(plugin, - (const struct sockaddr_in *)plugin->server_addr_v4, - MHD_NO_FLAG); + { + plugin->server_v4 + = run_mhd_start_daemon (plugin, + (const struct + sockaddr_in *) plugin->server_addr_v4, + MHD_NO_FLAG); - if (NULL == plugin->server_v4) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Failed to start %s IPv4 server component on port %u\n", - plugin->name, - plugin->port); - } - else - server_reschedule(plugin, - plugin->server_v4, - GNUNET_NO); + if (NULL == plugin->server_v4) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Failed to start %s IPv4 server component on port %u\n", + plugin->name, + plugin->port); } + else + server_reschedule (plugin, + plugin->server_v4, + GNUNET_NO); + } plugin->server_v6 = NULL; if (GNUNET_YES == plugin->use_ipv6) - { - plugin->server_v6 - = run_mhd_start_daemon(plugin, - (const struct sockaddr_in *)plugin->server_addr_v6, - MHD_USE_IPv6); - if (NULL == plugin->server_v6) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Failed to start %s IPv6 server component on port %u\n", - plugin->name, - plugin->port); - } - else - { - server_reschedule(plugin, - plugin->server_v6, - GNUNET_NO); - } - } + { + plugin->server_v6 + = run_mhd_start_daemon (plugin, + (const struct + sockaddr_in *) plugin->server_addr_v6, + MHD_USE_IPv6); + if (NULL == plugin->server_v6) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Failed to start %s IPv6 server component on port %u\n", + plugin->name, + plugin->port); + } + else + { + server_reschedule (plugin, + plugin->server_v6, + GNUNET_NO); + } + } msg = "No"; if ((NULL == plugin->server_v6) && (NULL == plugin->server_v4)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "%s %s server component started on port %u\n", - msg, - plugin->name, - plugin->port); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "%s %s server component started on port %u\n", + msg, + plugin->name, + plugin->port); + return GNUNET_SYSERR; + } if ((NULL != plugin->server_v6) && (NULL != plugin->server_v4)) msg = "IPv4 and IPv6"; @@ -2395,11 +2422,11 @@ server_start(struct HTTP_Server_Plugin *plugin) msg = "IPv6"; else if (NULL != plugin->server_v4) msg = "IPv4"; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "%s %s server component started on port %u\n", - msg, - plugin->name, - plugin->port); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "%s %s server component started on port %u\n", + msg, + plugin->name, + plugin->port); return GNUNET_OK; } @@ -2413,47 +2440,51 @@ server_start(struct HTTP_Server_Plugin *plugin) * @param addrlen address length */ static void -server_add_address(void *cls, - int add_remove, - const struct sockaddr *addr, - socklen_t addrlen) +server_add_address (void *cls, + int add_remove, + const struct sockaddr *addr, + socklen_t addrlen) { struct HTTP_Server_Plugin *plugin = cls; struct GNUNET_HELLO_Address *address; struct HttpAddressWrapper *w = NULL; - w = GNUNET_new(struct HttpAddressWrapper); - w->address = http_common_address_from_socket(plugin->protocol, - addr, - addrlen); + w = GNUNET_new (struct HttpAddressWrapper); + w->address = http_common_address_from_socket (plugin->protocol, + addr, + addrlen); if (NULL == w->address) - { - GNUNET_free(w); - return; - } - w->addrlen = http_common_address_get_size(w->address); - - GNUNET_CONTAINER_DLL_insert(plugin->addr_head, - plugin->addr_tail, - w); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Notifying transport to add address `%s'\n", - http_common_plugin_address_to_string(plugin->protocol, - w->address, - w->addrlen)); + { + GNUNET_free (w); + return; + } + w->addrlen = http_common_address_get_size (w->address); + + GNUNET_CONTAINER_DLL_insert (plugin->addr_head, + plugin->addr_tail, + w); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Notifying transport to add address `%s'\n", + http_common_plugin_address_to_string (plugin->protocol, + w->address, + w->addrlen)); /* modify our published address list */ #if BUILD_HTTPS - address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "https_client", w->address, + w->addrlen, + GNUNET_HELLO_ADDRESS_INFO_NONE); #else - address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "http_client", w->address, + w->addrlen, + GNUNET_HELLO_ADDRESS_INFO_NONE); #endif - plugin->env->notify_address(plugin->env->cls, - add_remove, - address); - GNUNET_HELLO_address_free(address); + plugin->env->notify_address (plugin->env->cls, + add_remove, + address); + GNUNET_HELLO_address_free (address); } @@ -2466,59 +2497,63 @@ server_add_address(void *cls, * @param addrlen address length */ static void -server_remove_address(void *cls, - int add_remove, - const struct sockaddr *addr, - socklen_t addrlen) +server_remove_address (void *cls, + int add_remove, + const struct sockaddr *addr, + socklen_t addrlen) { struct HTTP_Server_Plugin *plugin = cls; struct GNUNET_HELLO_Address *address; struct HttpAddressWrapper *w = plugin->addr_head; size_t saddr_len; - void * saddr; + void *saddr; - saddr = http_common_address_from_socket(plugin->protocol, - addr, - addrlen); + saddr = http_common_address_from_socket (plugin->protocol, + addr, + addrlen); if (NULL == saddr) return; - saddr_len = http_common_address_get_size(saddr); + saddr_len = http_common_address_get_size (saddr); while (NULL != w) - { - if (GNUNET_YES == - http_common_cmp_addresses(w->address, - w->addrlen, - saddr, - saddr_len)) - break; - w = w->next; - } - GNUNET_free(saddr); + { + if (GNUNET_YES == + http_common_cmp_addresses (w->address, + w->addrlen, + saddr, + saddr_len)) + break; + w = w->next; + } + GNUNET_free (saddr); if (NULL == w) return; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Notifying transport to remove address `%s'\n", - http_common_plugin_address_to_string(plugin->protocol, - w->address, - w->addrlen)); - GNUNET_CONTAINER_DLL_remove(plugin->addr_head, - plugin->addr_tail, - w); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Notifying transport to remove address `%s'\n", + http_common_plugin_address_to_string (plugin->protocol, + w->address, + w->addrlen)); + GNUNET_CONTAINER_DLL_remove (plugin->addr_head, + plugin->addr_tail, + w); /* modify our published address list */ #if BUILD_HTTPS - address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "https_client", w->address, + w->addrlen, + GNUNET_HELLO_ADDRESS_INFO_NONE); #else - address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "http_client", w->address, + w->addrlen, + GNUNET_HELLO_ADDRESS_INFO_NONE); #endif - plugin->env->notify_address(plugin->env->cls, add_remove, address); - GNUNET_HELLO_address_free(address); - GNUNET_free(w->address); - GNUNET_free(w); + plugin->env->notify_address (plugin->env->cls, add_remove, address); + GNUNET_HELLO_address_free (address); + GNUNET_free (w->address); + GNUNET_free (w); } @@ -2536,67 +2571,67 @@ server_remove_address(void *cls, * @param addrlen actual lenght of the address */ static void -server_nat_port_map_callback(void *cls, - void **app_ctx, - int add_remove, - enum GNUNET_NAT_AddressClass ac, - const struct sockaddr *addr, - socklen_t addrlen) +server_nat_port_map_callback (void *cls, + void **app_ctx, + int add_remove, + enum GNUNET_NAT_AddressClass ac, + const struct sockaddr *addr, + socklen_t addrlen) { struct HTTP_Server_Plugin *plugin = cls; - (void)app_ctx; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "NAT called to %s address `%s'\n", - (add_remove == GNUNET_NO) ? "remove" : "add", - GNUNET_a2s(addr, addrlen)); + (void) app_ctx; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "NAT called to %s address `%s'\n", + (add_remove == GNUNET_NO) ? "remove" : "add", + GNUNET_a2s (addr, addrlen)); if (AF_INET == addr->sa_family) - { - struct sockaddr_in *s4 = (struct sockaddr_in *)addr; + { + struct sockaddr_in *s4 = (struct sockaddr_in *) addr; - if (GNUNET_NO == plugin->use_ipv4) - return; + if (GNUNET_NO == plugin->use_ipv4) + return; - if ((NULL != plugin->server_addr_v4) && - (0 != memcmp(&plugin->server_addr_v4->sin_addr, - &s4->sin_addr, - sizeof(struct in_addr)))) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Skipping address `%s' (not bindto address)\n", - GNUNET_a2s(addr, addrlen)); - return; - } + if ((NULL != plugin->server_addr_v4) && + (0 != memcmp (&plugin->server_addr_v4->sin_addr, + &s4->sin_addr, + sizeof(struct in_addr)))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Skipping address `%s' (not bindto address)\n", + GNUNET_a2s (addr, addrlen)); + return; } + } if (AF_INET6 == addr->sa_family) - { - struct sockaddr_in6 *s6 = (struct sockaddr_in6 *)addr; - if (GNUNET_NO == plugin->use_ipv6) - return; + { + struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) addr; + if (GNUNET_NO == plugin->use_ipv6) + return; - if ((NULL != plugin->server_addr_v6) && - (0 != memcmp(&plugin->server_addr_v6->sin6_addr, - &s6->sin6_addr, sizeof(struct in6_addr)))) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Skipping address `%s' (not bindto address)\n", - GNUNET_a2s(addr, addrlen)); - return; - } + if ((NULL != plugin->server_addr_v6) && + (0 != memcmp (&plugin->server_addr_v6->sin6_addr, + &s6->sin6_addr, sizeof(struct in6_addr)))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Skipping address `%s' (not bindto address)\n", + GNUNET_a2s (addr, addrlen)); + return; } + } switch (add_remove) - { - case GNUNET_YES: - server_add_address(cls, add_remove, addr, addrlen); - break; - - case GNUNET_NO: - server_remove_address(cls, add_remove, addr, addrlen); - break; - } + { + case GNUNET_YES: + server_add_address (cls, add_remove, addr, addrlen); + break; + + case GNUNET_NO: + server_remove_address (cls, add_remove, addr, addrlen); + break; + } } @@ -2611,11 +2646,11 @@ server_nat_port_map_callback(void *cls, * @return number of addresses */ static int -server_get_addresses(struct HTTP_Server_Plugin *plugin, - const char *service_name, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct sockaddr ***addrs, - socklen_t ** addr_lens) +server_get_addresses (struct HTTP_Server_Plugin *plugin, + const char *service_name, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct sockaddr ***addrs, + socklen_t **addr_lens) { int disablev6; unsigned long long port; @@ -2633,159 +2668,160 @@ server_get_addresses(struct HTTP_Server_Plugin *plugin, *addrs = NULL; *addr_lens = NULL; - disablev6 = !plugin->use_ipv6; + disablev6 = ! plugin->use_ipv6; port = 0; - if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT")) - { - GNUNET_break(GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number(cfg, service_name, + if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) + { + GNUNET_break (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port)); - if (port > 65535) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Require valid port number for service in configuration!\n")); - return GNUNET_SYSERR; - } - } - if (0 == port) + if (port > 65535) { - LOG(GNUNET_ERROR_TYPE_INFO, - "Starting in listen only mode\n"); - return -1; /* listen only */ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ( + "Require valid port number for service in configuration!\n")); + return GNUNET_SYSERR; } - - - if (GNUNET_CONFIGURATION_have_value(cfg, service_name, - "BINDTO")) - { - GNUNET_break(GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(cfg, service_name, + } + if (0 == port) + { + LOG (GNUNET_ERROR_TYPE_INFO, + "Starting in listen only mode\n"); + return -1; /* listen only */ + } + + + if (GNUNET_CONFIGURATION_have_value (cfg, service_name, + "BINDTO")) + { + GNUNET_break (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "BINDTO", &hostname)); - } + } else hostname = NULL; if (NULL != hostname) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Resolving `%s' since that is where `%s' will bind to.\n", + hostname, service_name); + memset (&hints, 0, sizeof(struct addrinfo)); + if (disablev6) + hints.ai_family = AF_INET; + if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || + (NULL == res)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to resolve `%s': %s\n"), + hostname, + gai_strerror (ret)); + GNUNET_free (hostname); + return GNUNET_SYSERR; + } + next = res; + i = 0; + while (NULL != (pos = next)) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Resolving `%s' since that is where `%s' will bind to.\n", - hostname, service_name); - memset(&hints, 0, sizeof(struct addrinfo)); - if (disablev6) - hints.ai_family = AF_INET; - if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || - (NULL == res)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Failed to resolve `%s': %s\n"), - hostname, - gai_strerror(ret)); - GNUNET_free(hostname); - return GNUNET_SYSERR; - } - next = res; - i = 0; - while (NULL != (pos = next)) - { - next = pos->ai_next; - if ((disablev6) && (pos->ai_family == AF_INET6)) - continue; - i++; - } - if (0 == i) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Failed to find %saddress for `%s'.\n"), - disablev6 ? "IPv4 " : "", hostname); - freeaddrinfo(res); - GNUNET_free(hostname); - return GNUNET_SYSERR; - } - resi = i; - saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); - i = 0; - next = res; - while (NULL != (pos = next)) - { - next = pos->ai_next; - if ((disablev6) && (pos->ai_family == AF_INET6)) - continue; - if ((pos->ai_protocol != IPPROTO_TCP) && (0 != pos->ai_protocol)) - continue; /* not TCP */ - if ((pos->ai_socktype != SOCK_STREAM) && (0 != pos->ai_socktype)) - continue; /* huh? */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Service will bind to `%s'\n", - GNUNET_a2s(pos->ai_addr, - pos->ai_addrlen)); - if (pos->ai_family == AF_INET) - { - GNUNET_assert(pos->ai_addrlen == sizeof(struct sockaddr_in)); - saddrlens[i] = pos->ai_addrlen; - saddrs[i] = GNUNET_malloc(saddrlens[i]); - GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); - ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); - } - else - { - GNUNET_assert(pos->ai_family == AF_INET6); - GNUNET_assert(pos->ai_addrlen == sizeof(struct sockaddr_in6)); - saddrlens[i] = pos->ai_addrlen; - saddrs[i] = GNUNET_malloc(saddrlens[i]); - GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); - ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); - } - i++; - } - GNUNET_free(hostname); - freeaddrinfo(res); - resi = i; + next = pos->ai_next; + if ((disablev6) && (pos->ai_family == AF_INET6)) + continue; + i++; + } + if (0 == i) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to find %saddress for `%s'.\n"), + disablev6 ? "IPv4 " : "", hostname); + freeaddrinfo (res); + GNUNET_free (hostname); + return GNUNET_SYSERR; } + resi = i; + saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); + i = 0; + next = res; + while (NULL != (pos = next)) + { + next = pos->ai_next; + if ((disablev6) && (pos->ai_family == AF_INET6)) + continue; + if ((pos->ai_protocol != IPPROTO_TCP) && (0 != pos->ai_protocol)) + continue; /* not TCP */ + if ((pos->ai_socktype != SOCK_STREAM) && (0 != pos->ai_socktype)) + continue; /* huh? */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Service will bind to `%s'\n", + GNUNET_a2s (pos->ai_addr, + pos->ai_addrlen)); + if (pos->ai_family == AF_INET) + { + GNUNET_assert (pos->ai_addrlen == sizeof(struct sockaddr_in)); + saddrlens[i] = pos->ai_addrlen; + saddrs[i] = GNUNET_malloc (saddrlens[i]); + GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); + } + else + { + GNUNET_assert (pos->ai_family == AF_INET6); + GNUNET_assert (pos->ai_addrlen == sizeof(struct sockaddr_in6)); + saddrlens[i] = pos->ai_addrlen; + saddrs[i] = GNUNET_malloc (saddrlens[i]); + GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); + ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); + } + i++; + } + GNUNET_free (hostname); + freeaddrinfo (res); + resi = i; + } else + { + /* will bind against everything, just set port */ + if (disablev6) { - /* will bind against everything, just set port */ - if (disablev6) - { - /* V4-only */ - resi = 1; - i = 0; - saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); - - saddrlens[i] = sizeof(struct sockaddr_in); - saddrs[i] = GNUNET_malloc(saddrlens[i]); + /* V4-only */ + resi = 1; + i = 0; + saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); + + saddrlens[i] = sizeof(struct sockaddr_in); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; + ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; #endif - ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; - ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); - } - else - { - /* dual stack */ - resi = 2; - saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); - i = 0; - saddrlens[i] = sizeof(struct sockaddr_in6); - saddrs[i] = GNUNET_malloc(saddrlens[i]); + ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); + } + else + { + /* dual stack */ + resi = 2; + saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); + i = 0; + saddrlens[i] = sizeof(struct sockaddr_in6); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; + ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; #endif - ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; - ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); - i++; - saddrlens[i] = sizeof(struct sockaddr_in); - saddrs[i] = GNUNET_malloc(saddrlens[i]); + ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; + ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); + i++; + saddrlens[i] = sizeof(struct sockaddr_in); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1]; + ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; #endif - ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; - ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); - } + ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); } + } *addrs = saddrs; *addr_lens = saddrlens; return resi; @@ -2798,44 +2834,44 @@ server_get_addresses(struct HTTP_Server_Plugin *plugin, * @param plugin the plugin handle */ static void -server_start_report_addresses(struct HTTP_Server_Plugin *plugin) +server_start_report_addresses (struct HTTP_Server_Plugin *plugin) { int res = GNUNET_OK; struct sockaddr **addrs; socklen_t *addrlens; - res = server_get_addresses(plugin, - plugin->name, - plugin->env->cfg, - &addrs, &addrlens); - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("Found %u addresses to report to NAT service\n"), - res); + res = server_get_addresses (plugin, + plugin->name, + plugin->env->cfg, + &addrs, &addrlens); + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ("Found %u addresses to report to NAT service\n"), + res); if (GNUNET_SYSERR == res) - { - plugin->nat = NULL; - return; - } + { + plugin->nat = NULL; + return; + } plugin->nat - = GNUNET_NAT_register(plugin->env->cfg, - "transport-http_server", - IPPROTO_TCP, - (unsigned int)res, - (const struct sockaddr **)addrs, - addrlens, - &server_nat_port_map_callback, - NULL, - plugin); + = GNUNET_NAT_register (plugin->env->cfg, + "transport-http_server", + IPPROTO_TCP, + (unsigned int) res, + (const struct sockaddr **) addrs, + addrlens, + &server_nat_port_map_callback, + NULL, + plugin); while (res > 0) - { - res--; - GNUNET_assert(NULL != addrs[res]); - GNUNET_free(addrs[res]); - } - GNUNET_free_non_null(addrs); - GNUNET_free_non_null(addrlens); + { + res--; + GNUNET_assert (NULL != addrs[res]); + GNUNET_free (addrs[res]); + } + GNUNET_free_non_null (addrs); + GNUNET_free_non_null (addrlens); } @@ -2845,26 +2881,26 @@ server_start_report_addresses(struct HTTP_Server_Plugin *plugin) * @param plugin the plugin handle */ static void -server_stop_report_addresses(struct HTTP_Server_Plugin *plugin) +server_stop_report_addresses (struct HTTP_Server_Plugin *plugin) { struct HttpAddressWrapper *w; /* Stop NAT handle */ if (NULL != plugin->nat) - { - GNUNET_NAT_unregister(plugin->nat); - plugin->nat = NULL; - } + { + GNUNET_NAT_unregister (plugin->nat); + plugin->nat = NULL; + } /* Clean up addresses */ while (NULL != plugin->addr_head) - { - w = plugin->addr_head; - GNUNET_CONTAINER_DLL_remove(plugin->addr_head, - plugin->addr_tail, - w); - GNUNET_free(w->address); - GNUNET_free(w); - } + { + w = plugin->addr_head; + GNUNET_CONTAINER_DLL_remove (plugin->addr_head, + plugin->addr_tail, + w); + GNUNET_free (w->address); + GNUNET_free (w); + } } @@ -2875,39 +2911,39 @@ server_stop_report_addresses(struct HTTP_Server_Plugin *plugin) * @return #GNUNET_YES on success, else #GNUNET_NO */ static int -server_check_ipv6_support(struct HTTP_Server_Plugin *plugin) +server_check_ipv6_support (struct HTTP_Server_Plugin *plugin) { struct GNUNET_NETWORK_Handle *desc = NULL; int res = GNUNET_NO; /* Probe IPv6 support */ - desc = GNUNET_NETWORK_socket_create(PF_INET6, - SOCK_STREAM, - 0); + desc = GNUNET_NETWORK_socket_create (PF_INET6, + SOCK_STREAM, + 0); if (NULL == desc) - { - if ((errno == ENOBUFS) || - (errno == ENOMEM) || - (errno == ENFILE) || - (errno == EACCES)) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, - "socket"); - } - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Disabling IPv6 since it is not supported on this system!\n")); - res = GNUNET_NO; - } + { + if ((errno == ENOBUFS) || + (errno == ENOMEM) || + (errno == ENFILE) || + (errno == EACCES)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, + "socket"); + } + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("Disabling IPv6 since it is not supported on this system!\n")); + res = GNUNET_NO; + } else - { - GNUNET_break(GNUNET_OK == - GNUNET_NETWORK_socket_close(desc)); - desc = NULL; - res = GNUNET_YES; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Testing IPv6 on this system: %s\n", - (res == GNUNET_YES) ? "successful" : "failed"); + { + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (desc)); + desc = NULL; + res = GNUNET_YES; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Testing IPv6 on this system: %s\n", + (res == GNUNET_YES) ? "successful" : "failed"); return res; } @@ -2918,7 +2954,7 @@ server_check_ipv6_support(struct HTTP_Server_Plugin *plugin) * @param cls plugin */ static void -server_notify_external_hostname(void *cls) +server_notify_external_hostname (void *cls) { struct HTTP_Server_Plugin *plugin = cls; struct HttpAddress *ext_addr; @@ -2927,48 +2963,48 @@ server_notify_external_hostname(void *cls) char *url; plugin->notify_ext_task = NULL; - GNUNET_asprintf(&url, - "%s://%s", - plugin->protocol, - plugin->external_hostname); - urlen = strlen(url) + 1; - ext_addr = GNUNET_malloc(sizeof(struct HttpAddress) + urlen); - ext_addr->options = htonl(plugin->options); - ext_addr->urlen = htonl(urlen); + GNUNET_asprintf (&url, + "%s://%s", + plugin->protocol, + plugin->external_hostname); + urlen = strlen (url) + 1; + ext_addr = GNUNET_malloc (sizeof(struct HttpAddress) + urlen); + ext_addr->options = htonl (plugin->options); + ext_addr->urlen = htonl (urlen); ext_addr_len = sizeof(struct HttpAddress) + urlen; - GNUNET_memcpy(&ext_addr[1], url, urlen); - GNUNET_free(url); + GNUNET_memcpy (&ext_addr[1], url, urlen); + GNUNET_free (url); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Notifying transport about external hostname address `%s'\n", - plugin->external_hostname); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Notifying transport about external hostname address `%s'\n", + plugin->external_hostname); #if BUILD_HTTPS if (GNUNET_YES == plugin->verify_external_hostname) - LOG(GNUNET_ERROR_TYPE_INFO, - "Enabling SSL verification for external hostname address `%s'\n", - plugin->external_hostname); + LOG (GNUNET_ERROR_TYPE_INFO, + "Enabling SSL verification for external hostname address `%s'\n", + plugin->external_hostname); plugin->ext_addr - = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - "https_client", - ext_addr, - ext_addr_len, - GNUNET_HELLO_ADDRESS_INFO_NONE); - plugin->env->notify_address(plugin->env->cls, - GNUNET_YES, - plugin->ext_addr); - GNUNET_free(ext_addr); + = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "https_client", + ext_addr, + ext_addr_len, + GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, + GNUNET_YES, + plugin->ext_addr); + GNUNET_free (ext_addr); #else plugin->ext_addr - = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - "http_client", - ext_addr, - ext_addr_len, - GNUNET_HELLO_ADDRESS_INFO_NONE); - plugin->env->notify_address(plugin->env->cls, - GNUNET_YES, - plugin->ext_addr); - GNUNET_free(ext_addr); + = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "http_client", + ext_addr, + ext_addr_len, + GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, + GNUNET_YES, + plugin->ext_addr); + GNUNET_free (ext_addr); #endif } @@ -2980,7 +3016,7 @@ server_notify_external_hostname(void *cls) * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -server_configure_plugin(struct HTTP_Server_Plugin *plugin) +server_configure_plugin (struct HTTP_Server_Plugin *plugin) { unsigned long long port; unsigned long long max_connections; @@ -2992,224 +3028,225 @@ server_configure_plugin(struct HTTP_Server_Plugin *plugin) /* Use IPv4? */ if (GNUNET_CONFIGURATION_have_value (plugin->env->cfg, plugin->name, "USE_IPv4")) - { - plugin->use_ipv4 = - GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, - plugin->name, - "USE_IPv4"); - } + { + plugin->use_ipv4 = + GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, + plugin->name, + "USE_IPv4"); + } else plugin->use_ipv4 = GNUNET_YES; - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("IPv4 support is %s\n"), - (plugin->use_ipv4 == GNUNET_YES) ? "enabled" : "disabled"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ("IPv4 support is %s\n"), + (plugin->use_ipv4 == GNUNET_YES) ? "enabled" : "disabled"); /* Use IPv6? */ if (GNUNET_CONFIGURATION_have_value (plugin->env->cfg, plugin->name, "USE_IPv6")) - { - plugin->use_ipv6 = - GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, - plugin->name, - "USE_IPv6"); - } + { + plugin->use_ipv6 = + GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, + plugin->name, + "USE_IPv6"); + } else plugin->use_ipv6 = GNUNET_YES; - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("IPv6 support is %s\n"), - (plugin->use_ipv6 == GNUNET_YES) ? "enabled" : "disabled"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ("IPv6 support is %s\n"), + (plugin->use_ipv6 == GNUNET_YES) ? "enabled" : "disabled"); if ((plugin->use_ipv4 == GNUNET_NO) && (plugin->use_ipv6 == GNUNET_NO)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n")); - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n")); + return GNUNET_SYSERR; + } /* Reading port number from config file */ if ((GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg, - plugin->name, - "PORT", &port)) || (port > 65535)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Port is required! Fix in configuration\n")); - return GNUNET_SYSERR; - } + GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, + plugin->name, + "PORT", &port)) || (port > 65535)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Port is required! Fix in configuration\n")); + return GNUNET_SYSERR; + } plugin->port = port; - LOG(GNUNET_ERROR_TYPE_INFO, - _("Using port %u\n"), plugin->port); + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Using port %u\n"), plugin->port); if ((plugin->use_ipv4 == GNUNET_YES) && (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, - plugin->name, - "BINDTO", - &bind4_address))) + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, + plugin->name, + "BINDTO", + &bind4_address))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Binding %s plugin to specific IPv4 address: `%s'\n", + plugin->protocol, + bind4_address); + plugin->server_addr_v4 = GNUNET_new (struct sockaddr_in); + if (1 != inet_pton (AF_INET, + bind4_address, + &plugin->server_addr_v4->sin_addr)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Specific IPv4 address `%s' in configuration file is invalid!\n"), + bind4_address); + GNUNET_free (bind4_address); + GNUNET_free (plugin->server_addr_v4); + plugin->server_addr_v4 = NULL; + return GNUNET_SYSERR; + } + else { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Binding %s plugin to specific IPv4 address: `%s'\n", - plugin->protocol, - bind4_address); - plugin->server_addr_v4 = GNUNET_new(struct sockaddr_in); - if (1 != inet_pton(AF_INET, - bind4_address, - &plugin->server_addr_v4->sin_addr)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Specific IPv4 address `%s' in configuration file is invalid!\n"), - bind4_address); - GNUNET_free(bind4_address); - GNUNET_free(plugin->server_addr_v4); - plugin->server_addr_v4 = NULL; - return GNUNET_SYSERR; - } - else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Binding to IPv4 address %s\n", - bind4_address); - plugin->server_addr_v4->sin_family = AF_INET; - plugin->server_addr_v4->sin_port = htons(plugin->port); - } - GNUNET_free(bind4_address); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Binding to IPv4 address %s\n", + bind4_address); + plugin->server_addr_v4->sin_family = AF_INET; + plugin->server_addr_v4->sin_port = htons (plugin->port); } + GNUNET_free (bind4_address); + } if ((plugin->use_ipv6 == GNUNET_YES) && (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, - plugin->name, - "BINDTO6", - &bind6_address))) + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, + plugin->name, + "BINDTO6", + &bind6_address))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Binding %s plugin to specific IPv6 address: `%s'\n", + plugin->protocol, bind6_address); + plugin->server_addr_v6 = GNUNET_new (struct sockaddr_in6); + if (1 != + inet_pton (AF_INET6, + bind6_address, + &plugin->server_addr_v6->sin6_addr)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Specific IPv6 address `%s' in configuration file is invalid!\n"), + bind6_address); + GNUNET_free (bind6_address); + GNUNET_free (plugin->server_addr_v6); + plugin->server_addr_v6 = NULL; + return GNUNET_SYSERR; + } + else { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Binding %s plugin to specific IPv6 address: `%s'\n", - plugin->protocol, bind6_address); - plugin->server_addr_v6 = GNUNET_new(struct sockaddr_in6); - if (1 != - inet_pton(AF_INET6, - bind6_address, - &plugin->server_addr_v6->sin6_addr)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Specific IPv6 address `%s' in configuration file is invalid!\n"), - bind6_address); - GNUNET_free(bind6_address); - GNUNET_free(plugin->server_addr_v6); - plugin->server_addr_v6 = NULL; - return GNUNET_SYSERR; - } - else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Binding to IPv6 address %s\n", - bind6_address); - plugin->server_addr_v6->sin6_family = AF_INET6; - plugin->server_addr_v6->sin6_port = htons(plugin->port); - } - GNUNET_free(bind6_address); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Binding to IPv6 address %s\n", + bind6_address); + plugin->server_addr_v6->sin6_family = AF_INET6; + plugin->server_addr_v6->sin6_port = htons (plugin->port); } + GNUNET_free (bind6_address); + } plugin->verify_external_hostname = GNUNET_NO; #if BUILD_HTTPS plugin->verify_external_hostname - = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, - plugin->name, - "VERIFY_EXTERNAL_HOSTNAME"); + = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, + plugin->name, + "VERIFY_EXTERNAL_HOSTNAME"); if (GNUNET_SYSERR == plugin->verify_external_hostname) plugin->verify_external_hostname = GNUNET_NO; if (GNUNET_YES == plugin->verify_external_hostname) plugin->options |= HTTP_OPTIONS_VERIFY_CERTIFICATE; #endif external_hostname_use_port - = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, - plugin->name, - "EXTERNAL_HOSTNAME_USE_PORT"); + = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, + plugin->name, + "EXTERNAL_HOSTNAME_USE_PORT"); if (GNUNET_SYSERR == external_hostname_use_port) external_hostname_use_port = GNUNET_NO; if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, - plugin->name, - "EXTERNAL_HOSTNAME", - &eh_tmp)) - { - char *tmp; - char *pos = NULL; - char *pos_url = NULL; - - if (NULL != strstr(eh_tmp, "://")) - tmp = &strstr(eh_tmp, "://")[3]; - else - tmp = eh_tmp; - - if (GNUNET_YES == external_hostname_use_port) - { - if ((strlen(tmp) > 1) && (NULL != (pos = strchr(tmp, '/')))) - { - pos_url = pos + 1; - pos[0] = '\0'; - GNUNET_asprintf(&plugin->external_hostname, - "%s:%u/%s", - tmp, - (uint16_t)port, - pos_url); - } - else - GNUNET_asprintf(&plugin->external_hostname, - "%s:%u", - tmp, - (uint16_t)port); - } - else - plugin->external_hostname = GNUNET_strdup(tmp); - GNUNET_free(eh_tmp); - - LOG(GNUNET_ERROR_TYPE_INFO, - _("Using external hostname `%s'\n"), - plugin->external_hostname); - plugin->notify_ext_task = GNUNET_SCHEDULER_add_now(&server_notify_external_hostname, - plugin); - - /* Use only configured external hostname */ - if (GNUNET_CONFIGURATION_have_value - (plugin->env->cfg, - plugin->name, - "EXTERNAL_HOSTNAME_ONLY")) - { - plugin->external_only = - GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, - plugin->name, - "EXTERNAL_HOSTNAME_ONLY"); - } + GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, + plugin->name, + "EXTERNAL_HOSTNAME", + &eh_tmp)) + { + char *tmp; + char *pos = NULL; + char *pos_url = NULL; + + if (NULL != strstr (eh_tmp, "://")) + tmp = &strstr (eh_tmp, "://")[3]; + else + tmp = eh_tmp; + + if (GNUNET_YES == external_hostname_use_port) + { + if ((strlen (tmp) > 1) && (NULL != (pos = strchr (tmp, '/')))) + { + pos_url = pos + 1; + pos[0] = '\0'; + GNUNET_asprintf (&plugin->external_hostname, + "%s:%u/%s", + tmp, + (uint16_t) port, + pos_url); + } else - plugin->external_only = GNUNET_NO; - - if (GNUNET_YES == plugin->external_only) - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("Notifying transport only about hostname `%s'\n"), - plugin->external_hostname); + GNUNET_asprintf (&plugin->external_hostname, + "%s:%u", + tmp, + (uint16_t) port); + } + else + plugin->external_hostname = GNUNET_strdup (tmp); + GNUNET_free (eh_tmp); + + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Using external hostname `%s'\n"), + plugin->external_hostname); + plugin->notify_ext_task = GNUNET_SCHEDULER_add_now ( + &server_notify_external_hostname, + plugin); + + /* Use only configured external hostname */ + if (GNUNET_CONFIGURATION_have_value + (plugin->env->cfg, + plugin->name, + "EXTERNAL_HOSTNAME_ONLY")) + { + plugin->external_only = + GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, + plugin->name, + "EXTERNAL_HOSTNAME_ONLY"); } + else + plugin->external_only = GNUNET_NO; + + if (GNUNET_YES == plugin->external_only) + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ("Notifying transport only about hostname `%s'\n"), + plugin->external_hostname); + } else - LOG(GNUNET_ERROR_TYPE_DEBUG, - "No external hostname configured\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "No external hostname configured\n"); /* Optional parameters */ if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg, - plugin->name, - "MAX_CONNECTIONS", - &max_connections)) + GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, + plugin->name, + "MAX_CONNECTIONS", + &max_connections)) max_connections = 128; plugin->max_request = max_connections; - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("Maximum number of connections is %u\n"), - plugin->max_request); + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ("Maximum number of connections is %u\n"), + plugin->max_request); - plugin->peer_id_length = strlen(GNUNET_i2s_full(plugin->env->my_identity)); + plugin->peer_id_length = strlen (GNUNET_i2s_full (plugin->env->my_identity)); return GNUNET_OK; } @@ -3222,94 +3259,94 @@ server_configure_plugin(struct HTTP_Server_Plugin *plugin) * @return NULL */ void * -LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) +LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) { struct GNUNET_TRANSPORT_PluginFunctions *api = cls; struct HTTP_Server_Plugin *plugin = api->cls; if (NULL == api->cls) - { - /* Free for stub mode */ - GNUNET_free(api); - return NULL; - } + { + /* Free for stub mode */ + GNUNET_free (api); + return NULL; + } plugin->in_shutdown = GNUNET_YES; - LOG(GNUNET_ERROR_TYPE_INFO, - _("Shutting down plugin `%s'\n"), - plugin->name); + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Shutting down plugin `%s'\n"), + plugin->name); if (NULL != plugin->notify_ext_task) - { - GNUNET_SCHEDULER_cancel(plugin->notify_ext_task); - plugin->notify_ext_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->notify_ext_task); + plugin->notify_ext_task = NULL; + } if (NULL != plugin->ext_addr) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Notifying transport to remove address `%s'\n", - http_common_plugin_address_to_string(plugin->protocol, + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Notifying transport to remove address `%s'\n", + http_common_plugin_address_to_string (plugin->protocol, plugin->ext_addr->address, plugin->ext_addr->address_length)); #if BUILD_HTTPS - plugin->env->notify_address(plugin->env->cls, - GNUNET_NO, - plugin->ext_addr); + plugin->env->notify_address (plugin->env->cls, + GNUNET_NO, + plugin->ext_addr); #else - plugin->env->notify_address(plugin->env->cls, - GNUNET_NO, - plugin->ext_addr); + plugin->env->notify_address (plugin->env->cls, + GNUNET_NO, + plugin->ext_addr); #endif - GNUNET_HELLO_address_free(plugin->ext_addr); - plugin->ext_addr = NULL; - } + GNUNET_HELLO_address_free (plugin->ext_addr); + plugin->ext_addr = NULL; + } /* Stop to report addresses to transport service */ - server_stop_report_addresses(plugin); + server_stop_report_addresses (plugin); if (NULL != plugin->server_v4_task) - { - GNUNET_SCHEDULER_cancel(plugin->server_v4_task); - plugin->server_v4_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->server_v4_task); + plugin->server_v4_task = NULL; + } if (NULL != plugin->server_v6_task) - { - GNUNET_SCHEDULER_cancel(plugin->server_v6_task); - plugin->server_v6_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->server_v6_task); + plugin->server_v6_task = NULL; + } #if BUILD_HTTPS - GNUNET_free_non_null(plugin->crypto_init); - GNUNET_free_non_null(plugin->cert); - GNUNET_free_non_null(plugin->key); + GNUNET_free_non_null (plugin->crypto_init); + GNUNET_free_non_null (plugin->cert); + GNUNET_free_non_null (plugin->key); #endif - GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, - &destroy_session_shutdown_cb, - plugin); - GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions); + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, + &destroy_session_shutdown_cb, + plugin); + GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); plugin->sessions = NULL; if (NULL != plugin->server_v4) - { - MHD_stop_daemon(plugin->server_v4); - plugin->server_v4 = NULL; - } + { + MHD_stop_daemon (plugin->server_v4); + plugin->server_v4 = NULL; + } if (NULL != plugin->server_v6) - { - MHD_stop_daemon(plugin->server_v6); - plugin->server_v6 = NULL; - } + { + MHD_stop_daemon (plugin->server_v6); + plugin->server_v6 = NULL; + } /* Clean up */ - GNUNET_free_non_null(plugin->external_hostname); - GNUNET_free_non_null(plugin->ext_addr); - GNUNET_free_non_null(plugin->server_addr_v4); - GNUNET_free_non_null(plugin->server_addr_v6); - regfree(&plugin->url_regex); - - LOG(GNUNET_ERROR_TYPE_DEBUG, - _("Shutdown for plugin `%s' complete\n"), - plugin->name); - - GNUNET_free(plugin); - GNUNET_free(api); + GNUNET_free_non_null (plugin->external_hostname); + GNUNET_free_non_null (plugin->ext_addr); + GNUNET_free_non_null (plugin->server_addr_v4); + GNUNET_free_non_null (plugin->server_addr_v6); + regfree (&plugin->url_regex); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + _ ("Shutdown for plugin `%s' complete\n"), + plugin->name); + + GNUNET_free (plugin); + GNUNET_free (api); return NULL; } @@ -3326,13 +3363,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) * @return string representing the same address */ static const char * -http_server_plugin_address_to_string(void *cls, - const void *addr, - size_t addrlen) +http_server_plugin_address_to_string (void *cls, + const void *addr, + size_t addrlen) { - return http_common_plugin_address_to_string(PLUGIN_NAME, - addr, - addrlen); + return http_common_plugin_address_to_string (PLUGIN_NAME, + addr, + addrlen); } @@ -3344,8 +3381,8 @@ http_server_plugin_address_to_string(void *cls, * @return the network type in HBO or #GNUNET_SYSERR */ static enum GNUNET_NetworkType -http_server_plugin_get_network(void *cls, - struct GNUNET_ATS_Session *session) +http_server_plugin_get_network (void *cls, + struct GNUNET_ATS_Session *session) { return session->scope; } @@ -3359,13 +3396,14 @@ http_server_plugin_get_network(void *cls, * @return the network type */ static enum GNUNET_NetworkType -http_server_plugin_get_network_for_address(void *cls, - const struct GNUNET_HELLO_Address *address) +http_server_plugin_get_network_for_address (void *cls, + const struct + GNUNET_HELLO_Address *address) { struct HTTP_Server_Plugin *plugin = cls; - return http_common_get_network_for_address(plugin->env, - address); + return http_common_get_network_for_address (plugin->env, + address); } @@ -3380,24 +3418,24 @@ http_server_plugin_get_network_for_address(void *cls, * @param delay new delay to use for receiving */ static void -http_server_plugin_update_inbound_delay(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session, - struct GNUNET_TIME_Relative delay) +http_server_plugin_update_inbound_delay (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session, + struct GNUNET_TIME_Relative delay) { - session->next_receive = GNUNET_TIME_relative_to_absolute(delay); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "New inbound delay %s\n", - GNUNET_STRINGS_relative_time_to_string(delay, - GNUNET_NO)); + session->next_receive = GNUNET_TIME_relative_to_absolute (delay); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New inbound delay %s\n", + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_NO)); if (NULL != session->recv_wakeup_task) - { - GNUNET_SCHEDULER_cancel(session->recv_wakeup_task); - session->recv_wakeup_task - = GNUNET_SCHEDULER_add_delayed(delay, - &server_wake_up, - session); - } + { + GNUNET_SCHEDULER_cancel (session->recv_wakeup_task); + session->recv_wakeup_task + = GNUNET_SCHEDULER_add_delayed (delay, + &server_wake_up, + session); + } } @@ -3411,16 +3449,16 @@ http_server_plugin_update_inbound_delay(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -send_session_info_iter(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +send_session_info_iter (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct HTTP_Server_Plugin *plugin = cls; struct GNUNET_ATS_Session *session = value; - notify_session_monitor(plugin, - session, - GNUNET_TRANSPORT_SS_INIT); + notify_session_monitor (plugin, + session, + GNUNET_TRANSPORT_SS_INIT); return GNUNET_OK; } @@ -3438,22 +3476,22 @@ send_session_info_iter(void *cls, * @param sic_cls closure for @a sic */ static void -http_server_plugin_setup_monitor(void *cls, - GNUNET_TRANSPORT_SessionInfoCallback sic, - void *sic_cls) +http_server_plugin_setup_monitor (void *cls, + GNUNET_TRANSPORT_SessionInfoCallback sic, + void *sic_cls) { struct HTTP_Server_Plugin *plugin = cls; plugin->sic = sic; plugin->sic_cls = sic_cls; if (NULL != sic) - { - GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, - &send_session_info_iter, - plugin); - /* signal end of first iteration */ - sic(sic_cls, NULL, NULL); - } + { + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, + &send_session_info_iter, + plugin); + /* signal end of first iteration */ + sic (sic_cls, NULL, NULL); + } } @@ -3464,29 +3502,29 @@ http_server_plugin_setup_monitor(void *cls, * @return api */ void * -LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) +LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) { struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; struct HTTP_Server_Plugin *plugin; if (NULL == env->receive) - { - /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully - initialze the plugin or the API */ - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); - api->cls = NULL; - api->address_to_string = &http_server_plugin_address_to_string; - api->string_to_address = &http_common_plugin_string_to_address; - api->address_pretty_printer = &http_common_plugin_address_pretty_printer; - return api; - } - plugin = GNUNET_new(struct HTTP_Server_Plugin); + { + /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully + initialze the plugin or the API */ + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); + api->cls = NULL; + api->address_to_string = &http_server_plugin_address_to_string; + api->string_to_address = &http_common_plugin_string_to_address; + api->address_pretty_printer = &http_common_plugin_address_pretty_printer; + return api; + } + plugin = GNUNET_new (struct HTTP_Server_Plugin); plugin->env = env; - plugin->sessions = GNUNET_CONTAINER_multipeermap_create(128, - GNUNET_YES); + plugin->sessions = GNUNET_CONTAINER_multipeermap_create (128, + GNUNET_YES); - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->send = &http_server_plugin_send; api->disconnect_peer = &http_server_plugin_disconnect_peer; @@ -3512,51 +3550,51 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) #endif if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno(env->cfg, - plugin->name, - "TCP_STEALTH")) - { + GNUNET_CONFIGURATION_get_value_yesno (env->cfg, + plugin->name, + "TCP_STEALTH")) + { #ifdef TCP_STEALTH - plugin->options |= HTTP_OPTIONS_TCP_STEALTH; + plugin->options |= HTTP_OPTIONS_TCP_STEALTH; #else - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("TCP_STEALTH not supported on this platform.\n")); - LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); - return NULL; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("TCP_STEALTH not supported on this platform.\n")); + LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); + return NULL; #endif - } + } /* Compile URL regex */ - if (regcomp(&plugin->url_regex, - URL_REGEX, - REG_EXTENDED)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Unable to compile URL regex\n")); - LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); - return NULL; - } + if (regcomp (&plugin->url_regex, + URL_REGEX, + REG_EXTENDED)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Unable to compile URL regex\n")); + LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); + return NULL; + } /* Configure plugin */ - if (GNUNET_SYSERR == server_configure_plugin(plugin)) - { - LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); - return NULL; - } + if (GNUNET_SYSERR == server_configure_plugin (plugin)) + { + LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); + return NULL; + } /* Check IPv6 support */ if (GNUNET_YES == plugin->use_ipv6) - plugin->use_ipv6 = server_check_ipv6_support(plugin); + plugin->use_ipv6 = server_check_ipv6_support (plugin); /* Report addresses to transport service */ if (GNUNET_NO == plugin->external_only) - server_start_report_addresses(plugin); + server_start_report_addresses (plugin); - if (GNUNET_SYSERR == server_start(plugin)) - { - LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); - return NULL; - } + if (GNUNET_SYSERR == server_start (plugin)) + { + LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); + return NULL; + } return api; } diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c index d7b87e7b1..7fbbc9126 100644 --- a/src/transport/plugin_transport_smtp.c +++ b/src/transport/plugin_transport_smtp.c @@ -53,7 +53,8 @@ /** * Host-Address in a SMTP network. */ -typedef struct { +typedef struct +{ /** * Filter line that every sender must include in the E-mails such * that the receiver can effectively filter out the GNUnet traffic @@ -75,7 +76,8 @@ GNUNET_NETWORK_STRUCT_BEGIN * Encapsulation of a GNUnet message in the SMTP mail body (before * base64 encoding). */ -typedef struct { +typedef struct +{ GNUNET_MessageHeader header; /** @@ -143,13 +145,13 @@ static GNUNET_CronTime last_transmission; /* ********************* the real stuff ******************* */ -#define strAUTOncmp(a, b) strncmp(a, b, strlen(b)) +#define strAUTOncmp(a, b) strncmp (a, b, strlen (b)) /** * Listen to the pipe, decode messages and send to core. */ static void * -listenAndDistribute(void *unused) +listenAndDistribute (void *unused) { char *line; unsigned int linesize; @@ -162,93 +164,96 @@ listenAndDistribute(void *unused) int fd; unsigned int pos; - linesize = ((GNUNET_MAX_BUFFER_SIZE * 4 / 3) + 8) * (MAX_CHAR_PER_LINE + 2) / MAX_CHAR_PER_LINE; /* maximum size of a line supported */ - line = GNUNET_malloc(linesize + 2); /* 2 bytes for off-by-one errors, just to be safe... */ + linesize = ((GNUNET_MAX_BUFFER_SIZE * 4 / 3) + 8) * (MAX_CHAR_PER_LINE + 2) + / MAX_CHAR_PER_LINE; /* maximum size of a line supported */ + line = GNUNET_malloc (linesize + 2); /* 2 bytes for off-by-one errors, just to be safe... */ #define READLINE(l, limit) \ - do { retl = fgets(l, (limit), fdes); \ + do { retl = fgets (l, (limit), fdes); \ if ((retl == NULL) || (smtp_shutdown == GNUNET_YES)) { \ - goto END; \ - } \ + goto END; \ + } \ if (core_api->load_monitor != NULL) \ - GNUNET_network_monitor_notify_transmission (core_api->load_monitor, GNUNET_ND_DOWNLOAD, strlen(retl)); \ - } while (0) + GNUNET_network_monitor_notify_transmission (core_api->load_monitor, \ + GNUNET_ND_DOWNLOAD, \ + strlen (retl)); \ + } while (0) while (smtp_shutdown == GNUNET_NO) + { + fd = OPEN (pipename, O_RDONLY | O_ASYNC); + if (fd == -1) + { + if (smtp_shutdown == GNUNET_NO) + GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); + continue; + } + fdes = fdopen (fd, "r"); + while (smtp_shutdown == GNUNET_NO) { - fd = OPEN(pipename, O_RDONLY | O_ASYNC); - if (fd == -1) - { - if (smtp_shutdown == GNUNET_NO) - GNUNET_thread_sleep(5 * GNUNET_CRON_SECONDS); - continue; - } - fdes = fdopen(fd, "r"); - while (smtp_shutdown == GNUNET_NO) - { - /* skip until end of header */ - do - { - READLINE(line, linesize); - } - while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */ - READLINE(line, linesize); /* read base64 encoded message; decode, process */ - pos = 0; - while (1) - { - pos = strlen(line) - 1; /* ignore new line */ - READLINE(&line[pos], linesize - pos); /* read base64 encoded message; decode, process */ - if ((line[pos] == '\r') || (line[pos] == '\n')) - break; /* empty line => end of message! */ - } - size = GNUNET_STRINGS_base64_decode(line, pos, &out); - if (size < sizeof(SMTPMessage)) - { - GNUNET_GE_BREAK(ectx, 0); - GNUNET_free(out); - goto END; - } - - mp = (SMTPMessage *)&out[size - sizeof(SMTPMessage)]; - if (ntohs(mp->header.size) != size) - { - GNUNET_GE_LOG(ectx, - GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, - _("Received malformed message via %s. Ignored.\n"), - "SMTP"); + /* skip until end of header */ + do + { + READLINE (line, linesize); + } + while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */ + READLINE (line, linesize); /* read base64 encoded message; decode, process */ + pos = 0; + while (1) + { + pos = strlen (line) - 1; /* ignore new line */ + READLINE (&line[pos], linesize - pos); /* read base64 encoded message; decode, process */ + if ((line[pos] == '\r') || (line[pos] == '\n')) + break; /* empty line => end of message! */ + } + size = GNUNET_STRINGS_base64_decode (line, pos, &out); + if (size < sizeof(SMTPMessage)) + { + GNUNET_GE_BREAK (ectx, 0); + GNUNET_free (out); + goto END; + } + + mp = (SMTPMessage *) &out[size - sizeof(SMTPMessage)]; + if (ntohs (mp->header.size) != size) + { + GNUNET_GE_LOG (ectx, + GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, + _ ("Received malformed message via %s. Ignored.\n"), + "SMTP"); #if DEBUG_SMTP - GNUNET_GE_LOG(ectx, - GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, - "Size returned by base64=%d, in the msg=%d.\n", size, - ntohl(mp->size)); + GNUNET_GE_LOG (ectx, + GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, + "Size returned by base64=%d, in the msg=%d.\n", size, + ntohl (mp->size)); #endif - GNUNET_free(out); - goto END; - } - if (stats != NULL) - stats->change(stat_bytesReceived, size); - coreMP = GNUNET_new(GNUNET_TransportPacket); - coreMP->msg = out; - coreMP->size = size - sizeof(SMTPMessage); - coreMP->tsession = NULL; - coreMP->sender = mp->sender; + GNUNET_free (out); + goto END; + } + if (stats != NULL) + stats->change (stat_bytesReceived, size); + coreMP = GNUNET_new (GNUNET_TransportPacket); + coreMP->msg = out; + coreMP->size = size - sizeof(SMTPMessage); + coreMP->tsession = NULL; + coreMP->sender = mp->sender; #if DEBUG_SMTP - GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, - "SMTP message passed to the core.\n"); + GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, + "SMTP message passed to the core.\n"); #endif - core_api->receive(coreMP); - } + core_api->receive (coreMP); + } END: #if DEBUG_SMTP - GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, - "SMTP message processed.\n"); + GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, + "SMTP message processed.\n"); #endif - if (fdes != NULL) - fclose(fdes); - } - GNUNET_free(line); + if (fdes != NULL) + fclose (fdes); + } + GNUNET_free (line); return NULL; } @@ -264,20 +269,20 @@ END: * @return GNUNET_OK on success, GNUNET_SYSERR on error */ static int -api_verify_hello(const GNUNET_MessageHello * hello) +api_verify_hello (const GNUNET_MessageHello *hello) { const EmailAddress *maddr; - maddr = (const EmailAddress *)&hello[1]; - if ((ntohs(hello->header.size) != - sizeof(GNUNET_MessageHello) + ntohs(hello->senderAddressSize)) || + maddr = (const EmailAddress *) &hello[1]; + if ((ntohs (hello->header.size) != + sizeof(GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) || (maddr->senderAddress - [ntohs(hello->senderAddressSize) - 1 - FILTER_STRING_SIZE] != '\0')) - { - GNUNET_GE_BREAK(ectx, 0); - return GNUNET_SYSERR; /* obviously invalid */ - } - if (NULL == strstr(maddr->filter, ": ")) + [ntohs (hello->senderAddressSize) - 1 - FILTER_STRING_SIZE] != '\0')) + { + GNUNET_GE_BREAK (ectx, 0); + return GNUNET_SYSERR; /* obviously invalid */ + } + if (NULL == strstr (maddr->filter, ": ")) return GNUNET_SYSERR; return GNUNET_OK; } @@ -290,64 +295,65 @@ api_verify_hello(const GNUNET_MessageHello * hello) * @return hello on success, NULL on error */ static GNUNET_MessageHello * -api_create_hello() +api_create_hello () { GNUNET_MessageHello *msg; char *filter; EmailAddress *haddr; int i; - GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "FILTER", - "X-mailer: GNUnet", &filter); - if (NULL == strstr(filter, ": ")) - { - GNUNET_GE_LOG(ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, - _("SMTP filter string to invalid, lacks ': '\n")); - GNUNET_free(filter); - return NULL; - } - - if (strlen(filter) > FILTER_STRING_SIZE) - { - filter[FILTER_STRING_SIZE] = '\0'; - GNUNET_GE_LOG(ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, - _("SMTP filter string to long, capped to `%s'\n"), filter); - } - i = (strlen(email) + 8) & (~7); /* make multiple of 8 */ + GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "FILTER", + "X-mailer: GNUnet", &filter); + if (NULL == strstr (filter, ": ")) + { + GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, + _ ("SMTP filter string to invalid, lacks ': '\n")); + GNUNET_free (filter); + return NULL; + } + + if (strlen (filter) > FILTER_STRING_SIZE) + { + filter[FILTER_STRING_SIZE] = '\0'; + GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, + _ ("SMTP filter string to long, capped to `%s'\n"), filter); + } + i = (strlen (email) + 8) & (~7); /* make multiple of 8 */ msg = - GNUNET_malloc(sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i); - memset(msg, 0, sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i); - haddr = (EmailAddress *)&msg[1]; - memset(&haddr->filter[0], 0, FILTER_STRING_SIZE); - strcpy(&haddr->filter[0], filter); - GNUNET_memcpy(&haddr->senderAddress[0], email, strlen(email) + 1); - msg->senderAddressSize = htons(strlen(email) + 1 + sizeof(EmailAddress)); - msg->protocol = htons(GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP); - msg->MTU = htonl(smtpAPI.mtu); - msg->header.size = htons(GNUNET_sizeof_hello(msg)); - if (api_verify_hello(msg) == GNUNET_SYSERR) - GNUNET_GE_ASSERT(ectx, 0); - GNUNET_free(filter); + GNUNET_malloc (sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i); + memset (msg, 0, sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i); + haddr = (EmailAddress *) &msg[1]; + memset (&haddr->filter[0], 0, FILTER_STRING_SIZE); + strcpy (&haddr->filter[0], filter); + GNUNET_memcpy (&haddr->senderAddress[0], email, strlen (email) + 1); + msg->senderAddressSize = htons (strlen (email) + 1 + sizeof(EmailAddress)); + msg->protocol = htons (GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP); + msg->MTU = htonl (smtpAPI.mtu); + msg->header.size = htons (GNUNET_sizeof_hello (msg)); + if (api_verify_hello (msg) == GNUNET_SYSERR) + GNUNET_GE_ASSERT (ectx, 0); + GNUNET_free (filter); return msg; } -struct GetMessageClosure { +struct GetMessageClosure +{ unsigned int esize; unsigned int pos; char *ebody; }; static const char * -get_message(void **buf, int *len, void *cls) +get_message (void **buf, int *len, void *cls) { struct GetMessageClosure *gmc = cls; *buf = NULL; if (len == NULL) - { - gmc->pos = 0; - return NULL; - } + { + gmc->pos = 0; + return NULL; + } if (gmc->pos == gmc->esize) return NULL; /* done */ *len = gmc->esize; @@ -365,8 +371,8 @@ get_message(void **buf, int *len, void *cls) * @return GNUNET_SYSERR on error, GNUNET_OK on success */ static int -api_send(GNUNET_TSession * tsession, const void *msg, const unsigned int size, - int important) +api_send (GNUNET_TSession *tsession, const void *msg, const unsigned int size, + int important) { const GNUNET_MessageHello *hello; const EmailAddress *haddr; @@ -386,139 +392,140 @@ api_send(GNUNET_TSession * tsession, const void *msg, const unsigned int size, if (smtp_shutdown == GNUNET_YES) return GNUNET_SYSERR; if ((size == 0) || (size > smtpAPI.mtu)) - { - GNUNET_GE_BREAK(ectx, 0); - return GNUNET_SYSERR; - } - now = GNUNET_get_time(); + { + GNUNET_GE_BREAK (ectx, 0); + return GNUNET_SYSERR; + } + now = GNUNET_get_time (); if ((important != GNUNET_YES) && - ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS) + ( ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS) ) return GNUNET_NO; /* rate too high */ last_transmission = now; - hello = (const GNUNET_MessageHello *)tsession->internal; + hello = (const GNUNET_MessageHello *) tsession->internal; if (hello == NULL) return GNUNET_SYSERR; - GNUNET_mutex_lock(lock); - session = smtp_create_session(); + GNUNET_mutex_lock (lock); + session = smtp_create_session (); if (session == NULL) - { - GNUNET_GE_LOG(ectx, - GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | - GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"), - "smtp_create_session", smtp_strerror(smtp_errno(), ebuf, + { + GNUNET_GE_LOG (ectx, + GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER + | GNUNET_GE_IMMEDIATE, _ ("SMTP: `%s' failed: %s.\n"), + "smtp_create_session", smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); - GNUNET_mutex_unlock(lock); - return GNUNET_SYSERR; - } - if (0 == smtp_set_server(session, smtp_server_name)) - { - GNUNET_GE_LOG(ectx, - GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | - GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"), - "smtp_set_server", smtp_strerror(smtp_errno(), ebuf, + GNUNET_mutex_unlock (lock); + return GNUNET_SYSERR; + } + if (0 == smtp_set_server (session, smtp_server_name)) + { + GNUNET_GE_LOG (ectx, + GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER + | GNUNET_GE_IMMEDIATE, _ ("SMTP: `%s' failed: %s.\n"), + "smtp_set_server", smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); - smtp_destroy_session(session); - GNUNET_mutex_unlock(lock); - return GNUNET_SYSERR; - } - haddr = (const EmailAddress *)&hello[1]; - message = smtp_add_message(session); + smtp_destroy_session (session); + GNUNET_mutex_unlock (lock); + return GNUNET_SYSERR; + } + haddr = (const EmailAddress *) &hello[1]; + message = smtp_add_message (session); if (message == NULL) - { - GNUNET_GE_LOG(ectx, - GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | - GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), - "smtp_add_message", smtp_strerror(smtp_errno(), ebuf, + { + GNUNET_GE_LOG (ectx, + GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER + | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"), + "smtp_add_message", smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); - smtp_destroy_session(session); - GNUNET_mutex_unlock(lock); - return GNUNET_SYSERR; - } - smtp_set_header(message, "To", NULL, haddr->senderAddress); - smtp_set_header(message, "From", NULL, email); + smtp_destroy_session (session); + GNUNET_mutex_unlock (lock); + return GNUNET_SYSERR; + } + smtp_set_header (message, "To", NULL, haddr->senderAddress); + smtp_set_header (message, "From", NULL, email); - filter = GNUNET_strdup(haddr->filter); - fvalue = strstr(filter, ": "); - GNUNET_GE_ASSERT(NULL, NULL != fvalue); + filter = GNUNET_strdup (haddr->filter); + fvalue = strstr (filter, ": "); + GNUNET_GE_ASSERT (NULL, NULL != fvalue); fvalue[0] = '\0'; fvalue += 2; - if (0 == smtp_set_header(message, filter, fvalue)) - { - GNUNET_GE_LOG(ectx, - GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | - GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), - "smtp_set_header", smtp_strerror(smtp_errno(), ebuf, + if (0 == smtp_set_header (message, filter, fvalue)) + { + GNUNET_GE_LOG (ectx, + GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER + | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"), + "smtp_set_header", smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); - smtp_destroy_session(session); - GNUNET_mutex_unlock(lock); - GNUNET_free(filter); - return GNUNET_SYSERR; - } - GNUNET_free(filter); - m = GNUNET_malloc(size + sizeof(SMTPMessage)); - GNUNET_memcpy(m, msg, size); - mp = (SMTPMessage *)&m[size]; - mp->header.size = htons(size + sizeof(SMTPMessage)); - mp->header.type = htons(0); + smtp_destroy_session (session); + GNUNET_mutex_unlock (lock); + GNUNET_free (filter); + return GNUNET_SYSERR; + } + GNUNET_free (filter); + m = GNUNET_malloc (size + sizeof(SMTPMessage)); + GNUNET_memcpy (m, msg, size); + mp = (SMTPMessage *) &m[size]; + mp->header.size = htons (size + sizeof(SMTPMessage)); + mp->header.type = htons (0); mp->sender = *core_api->my_identity; gm_cls.ebody = NULL; gm_cls.pos = 0; - gm_cls.esize = GNUNET_STRINGS_base64_encode(m, size + sizeof(SMTPMessage), &gm_cls.ebody); - GNUNET_free(m); - if (0 == smtp_size_set_estimate(message, gm_cls.esize)) - { - GNUNET_GE_LOG(ectx, - GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | - GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), - "smtp_size_set_estimate", smtp_strerror(smtp_errno(), ebuf, + gm_cls.esize = GNUNET_STRINGS_base64_encode (m, size + sizeof(SMTPMessage), + &gm_cls.ebody); + GNUNET_free (m); + if (0 == smtp_size_set_estimate (message, gm_cls.esize)) + { + GNUNET_GE_LOG (ectx, + GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER + | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"), + "smtp_size_set_estimate", smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); - } - if (0 == smtp_set_messagecb(message, &get_message, &gm_cls)) - { - GNUNET_GE_LOG(ectx, - GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | - GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), - "smtp_set_messagecb", smtp_strerror(smtp_errno(), ebuf, + } + if (0 == smtp_set_messagecb (message, &get_message, &gm_cls)) + { + GNUNET_GE_LOG (ectx, + GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER + | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"), + "smtp_set_messagecb", smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); - smtp_destroy_session(session); - GNUNET_mutex_unlock(lock); - GNUNET_free(gm_cls.ebody); - return GNUNET_SYSERR; - } - recipient = smtp_add_recipient(message, haddr->senderAddress); + smtp_destroy_session (session); + GNUNET_mutex_unlock (lock); + GNUNET_free (gm_cls.ebody); + return GNUNET_SYSERR; + } + recipient = smtp_add_recipient (message, haddr->senderAddress); if (recipient == NULL) - { - GNUNET_GE_LOG(ectx, - GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | - GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), - "smtp_add_recipient", smtp_strerror(smtp_errno(), ebuf, + { + GNUNET_GE_LOG (ectx, + GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER + | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"), + "smtp_add_recipient", smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); - smtp_destroy_session(session); - GNUNET_mutex_unlock(lock); - return GNUNET_SYSERR; - } - if (0 == smtp_start_session(session)) - { - GNUNET_GE_LOG(ectx, - GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | - GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), - "smtp_start_session", smtp_strerror(smtp_errno(), ebuf, + smtp_destroy_session (session); + GNUNET_mutex_unlock (lock); + return GNUNET_SYSERR; + } + if (0 == smtp_start_session (session)) + { + GNUNET_GE_LOG (ectx, + GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER + | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"), + "smtp_start_session", smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); - smtp_destroy_session(session); - GNUNET_mutex_unlock(lock); - GNUNET_free(gm_cls.ebody); - return GNUNET_SYSERR; - } + smtp_destroy_session (session); + GNUNET_mutex_unlock (lock); + GNUNET_free (gm_cls.ebody); + return GNUNET_SYSERR; + } if (stats != NULL) - stats->change(stat_bytesSent, size); + stats->change (stat_bytesSent, size); if (core_api->load_monitor != NULL) - GNUNET_network_monitor_notify_transmission(core_api->load_monitor, - GNUNET_ND_UPLOAD, gm_cls.esize); - smtp_message_reset_status(message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */ - smtp_destroy_session(session); - GNUNET_mutex_unlock(lock); - GNUNET_free(gm_cls.ebody); + GNUNET_network_monitor_notify_transmission (core_api->load_monitor, + GNUNET_ND_UPLOAD, gm_cls.esize); + smtp_message_reset_status (message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */ + smtp_destroy_session (session); + GNUNET_mutex_unlock (lock); + GNUNET_free (gm_cls.ebody); return GNUNET_OK; } @@ -530,15 +537,15 @@ api_send(GNUNET_TSession * tsession, const void *msg, const unsigned int size, * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed */ static int -api_connect(const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr, - int may_reuse) +api_connect (const GNUNET_MessageHello *hello, GNUNET_TSession **tsessionPtr, + int may_reuse) { GNUNET_TSession *tsession; - tsession = GNUNET_new(GNUNET_TSession); - tsession->internal = GNUNET_malloc(GNUNET_sizeof_hello(hello)); + tsession = GNUNET_new (GNUNET_TSession); + tsession->internal = GNUNET_malloc (GNUNET_sizeof_hello (hello)); tsession->peer = hello->senderIdentity; - GNUNET_memcpy(tsession->internal, hello, GNUNET_sizeof_hello(hello)); + GNUNET_memcpy (tsession->internal, hello, GNUNET_sizeof_hello (hello)); tsession->ttype = smtpAPI.protocol_number; (*tsessionPtr) = tsession; return GNUNET_OK; @@ -551,14 +558,14 @@ api_connect(const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr, * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed */ static int -api_disconnect(GNUNET_TSession * tsession) +api_disconnect (GNUNET_TSession *tsession) { if (tsession != NULL) - { - if (tsession->internal != NULL) - GNUNET_free(tsession->internal); - GNUNET_free(tsession); - } + { + if (tsession->internal != NULL) + GNUNET_free (tsession->internal); + GNUNET_free (tsession); + } return GNUNET_OK; } @@ -567,18 +574,18 @@ api_disconnect(GNUNET_TSession * tsession) * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed */ static int -api_start_transport_server() +api_start_transport_server () { smtp_shutdown = GNUNET_NO; /* initialize SMTP network */ - dispatchThread = GNUNET_thread_create(&listenAndDistribute, NULL, 1024 * 4); + dispatchThread = GNUNET_thread_create (&listenAndDistribute, NULL, 1024 * 4); if (dispatchThread == NULL) - { - GNUNET_GE_DIE_STRERROR(ectx, - GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL, - "pthread_create"); - return GNUNET_SYSERR; - } + { + GNUNET_GE_DIE_STRERROR (ectx, + GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL, + "pthread_create"); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -587,13 +594,13 @@ api_start_transport_server() * restarted later! */ static int -api_stop_transport_server() +api_stop_transport_server () { void *unused; smtp_shutdown = GNUNET_YES; - GNUNET_thread_stop_sleep(dispatchThread); - GNUNET_thread_join(dispatchThread, &unused); + GNUNET_thread_stop_sleep (dispatchThread); + GNUNET_thread_join (dispatchThread, &unused); return GNUNET_OK; } @@ -601,8 +608,8 @@ api_stop_transport_server() * Convert SMTP hello to an IP address (always fails). */ static int -api_hello_to_address(const GNUNET_MessageHello * hello, void **sa, - unsigned int *sa_len) +api_hello_to_address (const GNUNET_MessageHello *hello, void **sa, + unsigned int *sa_len) { return GNUNET_SYSERR; } @@ -611,7 +618,7 @@ api_hello_to_address(const GNUNET_MessageHello * hello, void **sa, * Always fails. */ static int -api_associate(GNUNET_TSession * tsession) +api_associate (GNUNET_TSession *tsession) { return GNUNET_SYSERR; /* SMTP connections can never be associated */ } @@ -621,8 +628,8 @@ api_associate(GNUNET_TSession * tsession) * frequency limits to SMTP in the future!). */ static int -api_test_would_try(GNUNET_TSession * tsession, unsigned int size, - int important) +api_test_would_try (GNUNET_TSession *tsession, unsigned int size, + int important) { return GNUNET_OK; /* we always try... */ } @@ -632,61 +639,64 @@ api_test_would_try(GNUNET_TSession * tsession, unsigned int size, * returns the smtp transport API. */ GNUNET_TransportAPI * -inittransport_smtp(struct GNUNET_CoreAPIForTransport * core) +inittransport_smtp (struct GNUNET_CoreAPIForTransport *core) { unsigned long long mtu; struct sigaction sa; core_api = core; ectx = core->ectx; - if (!GNUNET_GC_have_configuration_value(core_api->cfg, "SMTP", "EMAIL")) - { - GNUNET_GE_LOG(ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, - _ - ("No email-address specified, can not start SMTP transport.\n")); - return NULL; - } - GNUNET_GC_get_configuration_value_number(core_api->cfg, "SMTP", "MTU", 1200, - SMTP_MESSAGE_SIZE, - SMTP_MESSAGE_SIZE, &mtu); - GNUNET_GC_get_configuration_value_number(core_api->cfg, "SMTP", "RATELIMIT", - 0, 0, 1024 * 1024, &rate_limit); - stats = core_api->service_request("stats"); + if (! GNUNET_GC_have_configuration_value (core_api->cfg, "SMTP", "EMAIL")) + { + GNUNET_GE_LOG (ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, + _ + ( + "No email-address specified, can not start SMTP transport.\n")); + return NULL; + } + GNUNET_GC_get_configuration_value_number (core_api->cfg, "SMTP", "MTU", 1200, + SMTP_MESSAGE_SIZE, + SMTP_MESSAGE_SIZE, &mtu); + GNUNET_GC_get_configuration_value_number (core_api->cfg, "SMTP", "RATELIMIT", + 0, 0, 1024 * 1024, &rate_limit); + stats = core_api->service_request ("stats"); if (stats != NULL) - { - stat_bytesReceived = - stats->create(gettext_noop("# bytes received via SMTP")); - stat_bytesSent = stats->create(gettext_noop("# bytes sent via SMTP")); - stat_bytesDropped = - stats->create(gettext_noop("# bytes dropped by SMTP (outgoing)")); - } - GNUNET_GC_get_configuration_value_filename(core_api->cfg, "SMTP", "PIPE", &pipename); - unlink(pipename); - if (0 != mkfifo(pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) - { - GNUNET_GE_LOG_STRERROR(ectx, - GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL, - "mkfifo"); - GNUNET_free(pipename); - core_api->service_release(stats); - stats = NULL; - return NULL; - } + { + stat_bytesReceived = + stats->create (gettext_noop ("# bytes received via SMTP")); + stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP")); + stat_bytesDropped = + stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)")); + } + GNUNET_GC_get_configuration_value_filename (core_api->cfg, "SMTP", "PIPE", + &pipename); + unlink (pipename); + if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) + { + GNUNET_GE_LOG_STRERROR (ectx, + GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL, + "mkfifo"); + GNUNET_free (pipename); + core_api->service_release (stats); + stats = NULL; + return NULL; + } /* we need to allow the mailer program to send us messages; * easiest done by giving it write permissions (see Mantis #1142) */ - if (0 != chmod(pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) - GNUNET_GE_LOG_STRERROR(ectx, - GNUNET_GE_ADMIN | GNUNET_GE_BULK | - GNUNET_GE_WARNING, "chmod"); - GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "EMAIL", NULL, - &email); - lock = GNUNET_mutex_create(GNUNET_NO); - GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "SERVER", - "localhost:25", &smtp_server_name); + if (0 != chmod (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) + GNUNET_GE_LOG_STRERROR (ectx, + GNUNET_GE_ADMIN | GNUNET_GE_BULK + | GNUNET_GE_WARNING, "chmod"); + GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "EMAIL", + NULL, + &email); + lock = GNUNET_mutex_create (GNUNET_NO); + GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "SERVER", + "localhost:25", &smtp_server_name); sa.sa_handler = SIG_IGN; - sigemptyset(&sa.sa_mask); + sigemptyset (&sa.sa_mask); sa.sa_flags = 0; - sigaction(SIGPIPE, &sa, &old_handler); + sigaction (SIGPIPE, &sa, &old_handler); smtpAPI.protocol_number = GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP; smtpAPI.mtu = mtu - sizeof(SMTPMessage); @@ -705,21 +715,21 @@ inittransport_smtp(struct GNUNET_CoreAPIForTransport * core) } void -donetransport_smtp() +donetransport_smtp () { - sigaction(SIGPIPE, &old_handler, NULL); - GNUNET_free(smtp_server_name); + sigaction (SIGPIPE, &old_handler, NULL); + GNUNET_free (smtp_server_name); if (stats != NULL) - { - core_api->service_release(stats); - stats = NULL; - } - GNUNET_mutex_destroy(lock); + { + core_api->service_release (stats); + stats = NULL; + } + GNUNET_mutex_destroy (lock); lock = NULL; - unlink(pipename); - GNUNET_free(pipename); + unlink (pipename); + GNUNET_free (pipename); pipename = NULL; - GNUNET_free(email); + GNUNET_free (email); email = NULL; } diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 80b21d86a..36ff00dd8 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -35,7 +35,7 @@ #include "gnunet_transport_plugin.h" #include "transport.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-tcp", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-tcp", __VA_ARGS__) #define PLUGIN_NAME "tcp" @@ -43,7 +43,7 @@ * How long until we give up on establishing an NAT connection? * Must be > 4 RTT */ -#define NAT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) +#define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) /** * Opaque handle that can be used to cancel @@ -83,7 +83,7 @@ struct LEGACY_SERVICE_Context; * @param srv service to stop */ void -LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *srv); +LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv); /** @@ -103,7 +103,8 @@ typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, /** * Credentials for UNIX domain sockets. */ -struct GNUNET_CONNECTION_Credentials { +struct GNUNET_CONNECTION_Credentials +{ /** * UID of the other end of the connection. */ @@ -185,7 +186,7 @@ typedef void (*GNUNET_CONNECTION_Receiver) (void *cls, * @param connection connection to destroy */ void -GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection); +GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection); /** @@ -249,7 +250,8 @@ typedef void (*GNUNET_SERVER_MessageCallback) ( * Message handler. Each struct specifies how to handle on particular * type of message received. */ -struct GNUNET_SERVER_MessageHandler { +struct GNUNET_SERVER_MessageHandler +{ /** * Function to call for messages of "type". */ @@ -278,7 +280,8 @@ struct GNUNET_SERVER_MessageHandler { /** * Options for the service (bitmask). */ -enum LEGACY_SERVICE_Options { +enum LEGACY_SERVICE_Options +{ /** * Use defaults. Terminates all client connections and the listen * sockets immediately upon receiving the shutdown signal. @@ -309,7 +312,7 @@ enum LEGACY_SERVICE_Options { * @param client the client to disconnect from */ void -GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client); +GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client); /** * Return user context associated with the given client. @@ -320,8 +323,8 @@ GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client); * @return pointer to user context */ void * -GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client, - size_t size); +GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client, + size_t size); /** @@ -350,8 +353,8 @@ typedef int (*GNUNET_SERVER_MessageTokenizerCallback) ( * @return handle to tokenizer */ struct GNUNET_SERVER_MessageStreamTokenizer * -GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, - void *cb_cls); +GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, + void *cb_cls); /** * Add incoming data to the receive buffer and call the @@ -370,12 +373,12 @@ GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, * #GNUNET_SYSERR if the data stream is corrupt */ int -GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst, - void *client_identity, - const char *buf, - size_t size, - int purge, - int one_shot); +GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, + void *client_identity, + const char *buf, + size_t size, + int purge, + int one_shot); /** @@ -384,7 +387,7 @@ GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst, * @param mst tokenizer to destroy */ void -GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst); +GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst); /** @@ -396,9 +399,9 @@ GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst); * @param size number of bytes in user context struct (for verification only) */ void -GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, - void *ptr, - size_t size); +GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, + void *ptr, + size_t size); /** * Return user context associated with the given client. * @@ -407,7 +410,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, * @return pointer to user context of type 'type *'. */ #define GNUNET_SERVER_client_get_user_context(client, type) \ - (type *)GNUNET_SERVER_client_get_user_context_(client, sizeof(type)) + (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof(type)) /** * Set user context to be associated with the given client. @@ -416,7 +419,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, * @param value pointer to user context */ #define GNUNET_SERVER_client_set_user_context(client, value) \ - GNUNET_SERVER_client_set_user_context_(client, value, sizeof(*value)) + GNUNET_SERVER_client_set_user_context_ (client, value, sizeof(*value)) /** @@ -435,7 +438,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, * NULL if we are already going to notify someone else (busy) */ struct GNUNET_SERVER_TransmitHandle * -GNUNET_SERVER_notify_transmit_ready( +GNUNET_SERVER_notify_transmit_ready ( struct GNUNET_SERVER_Client *client, size_t size, struct GNUNET_TIME_Relative timeout, @@ -448,7 +451,7 @@ GNUNET_SERVER_notify_transmit_ready( * @param th request to abort */ void -GNUNET_SERVER_notify_transmit_ready_cancel( +GNUNET_SERVER_notify_transmit_ready_cancel ( struct GNUNET_SERVER_TransmitHandle *th); @@ -460,7 +463,7 @@ GNUNET_SERVER_notify_transmit_ready_cancel( * @param client the client to keep */ void -GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client); +GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client); /** @@ -472,7 +475,7 @@ GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client); * @param client the client to drop */ void -GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client); +GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client); /** @@ -496,7 +499,7 @@ typedef void (*LEGACY_SERVICE_Main) ( * @param server server to stop accepting connections. */ void -GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server); +GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server); /** * Notify us when the server has enough space to transmit @@ -514,7 +517,7 @@ GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server); * NULL if we are already going to notify someone else (busy) */ struct GNUNET_SERVER_TransmitHandle * -GNUNET_SERVER_notify_transmit_ready( +GNUNET_SERVER_notify_transmit_ready ( struct GNUNET_SERVER_Client *client, size_t size, struct GNUNET_TIME_Relative timeout, @@ -534,8 +537,8 @@ GNUNET_SERVER_notify_transmit_ready( * @return the client handle */ struct GNUNET_SERVER_Client * -GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, - struct GNUNET_CONNECTION_Handle *connection); +GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, + struct GNUNET_CONNECTION_Handle *connection); /** @@ -544,7 +547,7 @@ GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, * @param server server to resume accepting connections. */ void -GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server); +GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server); /** * Free resources held by this server. @@ -552,7 +555,7 @@ GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server); * @param server server to destroy */ void -GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server); +GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server); #include "tcp_connection_legacy.c" @@ -565,7 +568,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Initial handshake message for a session. */ -struct WelcomeMessage { +struct WelcomeMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME. */ @@ -581,7 +585,8 @@ struct WelcomeMessage { * Basically a WELCOME message, but with the purpose * of giving the waiting peer a client handle to use */ -struct TCP_NAT_ProbeMessage { +struct TCP_NAT_ProbeMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE. */ @@ -597,7 +602,8 @@ GNUNET_NETWORK_STRUCT_END /** * Context for sending a NAT probe via TCP. */ -struct TCPProbeContext { +struct TCPProbeContext +{ /** * Active probes are kept in a DLL. */ @@ -632,7 +638,8 @@ struct TCPProbeContext { /** * Bits in the `options` field of TCP addresses. */ -enum TcpAddressOptions { +enum TcpAddressOptions +{ /** * No bits set. */ @@ -654,7 +661,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Network format for IPv4 addresses. */ -struct IPv4TcpAddress { +struct IPv4TcpAddress +{ /** * Optional options and flags for this address, * see `enum TcpAddressOptions` @@ -675,7 +683,8 @@ struct IPv4TcpAddress { /** * Network format for IPv6 addresses. */ -struct IPv6TcpAddress { +struct IPv6TcpAddress +{ /** * Optional flags for this address * see `enum TcpAddressOptions` @@ -703,7 +712,8 @@ struct Plugin; * Information kept for each message that is yet to * be transmitted. */ -struct PendingMessage { +struct PendingMessage +{ /** * This is a doubly-linked list. */ @@ -747,7 +757,8 @@ struct PendingMessage { /** * Session handle for TCP connections. */ -struct GNUNET_ATS_Session { +struct GNUNET_ATS_Session +{ /** * To whom are we talking to (set to our identity * if we are still waiting for the welcome message) @@ -849,7 +860,8 @@ struct GNUNET_ATS_Session { * Context for address to string conversion, closure * for #append_port(). */ -struct PrettyPrinterContext { +struct PrettyPrinterContext +{ /** * DLL */ @@ -905,7 +917,8 @@ struct PrettyPrinterContext { /** * Encapsulation of all of the state of the plugin. */ -struct Plugin { +struct Plugin +{ /** * Our environment. */ @@ -1036,10 +1049,10 @@ struct Plugin { * set to NULL). */ static int -get_server_addresses(const char *service_name, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct sockaddr ***addrs, - socklen_t **addr_lens) +get_server_addresses (const char *service_name, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct sockaddr ***addrs, + socklen_t **addr_lens) { int disablev6; struct GNUNET_NETWORK_Handle *desc; @@ -1060,72 +1073,72 @@ get_server_addresses(const char *service_name, *addrs = NULL; *addr_lens = NULL; desc = NULL; - if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "DISABLEV6")) - { - if (GNUNET_SYSERR == - (disablev6 = GNUNET_CONFIGURATION_get_value_yesno(cfg, - service_name, - "DISABLEV6"))) - return GNUNET_SYSERR; - } + if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) + { + if (GNUNET_SYSERR == + (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, + service_name, + "DISABLEV6"))) + return GNUNET_SYSERR; + } else disablev6 = GNUNET_NO; - if (!disablev6) + if (! disablev6) + { + /* probe IPv6 support */ + desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); + if (NULL == desc) + { + if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || + (EACCES == errno)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_INFO, + _ ( + "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), + service_name, + strerror (errno)); + disablev6 = GNUNET_YES; + } + else { - /* probe IPv6 support */ - desc = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0); - if (NULL == desc) - { - if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || - (EACCES == errno)) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); - return GNUNET_SYSERR; - } - LOG(GNUNET_ERROR_TYPE_INFO, - _( - "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), - service_name, - strerror(errno)); - disablev6 = GNUNET_YES; - } - else - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc)); - desc = NULL; - } + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); + desc = NULL; } + } port = 0; - if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT")) + if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) + { + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, + service_name, + "PORT", + &port)) { - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, - service_name, - "PORT", - &port)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Require valid port number for service `%s' in configuration!\n"), - service_name); - } - if (port > 65535) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Require valid port number for service `%s' in configuration!\n"), - service_name); - return GNUNET_SYSERR; - } + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Require valid port number for service `%s' in configuration!\n"), + service_name); } - - if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "BINDTO")) + if (port > 65535) { - GNUNET_break(GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(cfg, + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Require valid port number for service `%s' in configuration!\n"), + service_name); + return GNUNET_SYSERR; + } + } + + if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) + { + GNUNET_break (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "BINDTO", &hostname)); - } + } else hostname = NULL; @@ -1133,232 +1146,232 @@ get_server_addresses(const char *service_name, abstract = GNUNET_NO; #ifdef AF_UNIX if ((GNUNET_YES == - GNUNET_CONFIGURATION_have_value(cfg, service_name, "UNIXPATH")) && - (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, - service_name, - "UNIXPATH", - &unixpath)) && - (0 < strlen(unixpath))) - { - /* probe UNIX support */ - struct sockaddr_un s_un; + GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && + (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, + service_name, + "UNIXPATH", + &unixpath)) && + (0 < strlen (unixpath))) + { + /* probe UNIX support */ + struct sockaddr_un s_un; - if (strlen(unixpath) >= sizeof(s_un.sun_path)) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("UNIXPATH `%s' too long, maximum length is %llu\n"), - unixpath, - (unsigned long long)sizeof(s_un.sun_path)); - unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath); - LOG(GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath); - } + if (strlen (unixpath) >= sizeof(s_un.sun_path)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), + unixpath, + (unsigned long long) sizeof(s_un.sun_path)); + unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); + LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath); + } #ifdef LINUX - abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, - "TESTING", - "USE_ABSTRACT_SOCKETS"); - if (GNUNET_SYSERR == abstract) - abstract = GNUNET_NO; + abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, + "TESTING", + "USE_ABSTRACT_SOCKETS"); + if (GNUNET_SYSERR == abstract) + abstract = GNUNET_NO; #endif - if ((GNUNET_YES != abstract) && - (GNUNET_OK != GNUNET_DISK_directory_create_for_file(unixpath))) - GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); - } + if ((GNUNET_YES != abstract) && + (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath))) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); + } if (NULL != unixpath) + { + desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); + if (NULL == desc) + { + if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || + (EACCES == errno)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); + GNUNET_free_non_null (hostname); + GNUNET_free (unixpath); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_INFO, + _ ( + "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), + service_name, + strerror (errno)); + GNUNET_free (unixpath); + unixpath = NULL; + } + else { - desc = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0); - if (NULL == desc) - { - if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || - (EACCES == errno)) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); - GNUNET_free_non_null(hostname); - GNUNET_free(unixpath); - return GNUNET_SYSERR; - } - LOG(GNUNET_ERROR_TYPE_INFO, - _( - "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), - service_name, - strerror(errno)); - GNUNET_free(unixpath); - unixpath = NULL; - } - else - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc)); - desc = NULL; - } + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); + desc = NULL; } + } #endif if ((0 == port) && (NULL == unixpath)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _( - "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), - service_name); - GNUNET_free_non_null(hostname); + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ( + "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), + service_name); + GNUNET_free_non_null (hostname); + return GNUNET_SYSERR; + } + if (0 == port) + { + saddrs = GNUNET_malloc (2 * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc (2 * sizeof(socklen_t)); + add_unixpath (saddrs, saddrlens, unixpath, abstract); + GNUNET_free_non_null (unixpath); + GNUNET_free_non_null (hostname); + *addrs = saddrs; + *addr_lens = saddrlens; + return 1; + } + + if (NULL != hostname) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Resolving `%s' since that is where `%s' will bind to.\n", + hostname, + service_name); + memset (&hints, 0, sizeof(struct addrinfo)); + if (disablev6) + hints.ai_family = AF_INET; + hints.ai_protocol = IPPROTO_TCP; + if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || + (NULL == res)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to resolve `%s': %s\n"), + hostname, + gai_strerror (ret)); + GNUNET_free (hostname); + GNUNET_free_non_null (unixpath); return GNUNET_SYSERR; } - if (0 == port) + next = res; + i = 0; + while (NULL != (pos = next)) { - saddrs = GNUNET_malloc(2 * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc(2 * sizeof(socklen_t)); - add_unixpath(saddrs, saddrlens, unixpath, abstract); - GNUNET_free_non_null(unixpath); - GNUNET_free_non_null(hostname); - *addrs = saddrs; - *addr_lens = saddrlens; - return 1; + next = pos->ai_next; + if ((disablev6) && (pos->ai_family == AF_INET6)) + continue; + i++; } - - if (NULL != hostname) + if (0 == i) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Resolving `%s' since that is where `%s' will bind to.\n", - hostname, - service_name); - memset(&hints, 0, sizeof(struct addrinfo)); - if (disablev6) - hints.ai_family = AF_INET; - hints.ai_protocol = IPPROTO_TCP; - if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || - (NULL == res)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Failed to resolve `%s': %s\n"), - hostname, - gai_strerror(ret)); - GNUNET_free(hostname); - GNUNET_free_non_null(unixpath); - return GNUNET_SYSERR; - } - next = res; - i = 0; - while (NULL != (pos = next)) - { - next = pos->ai_next; - if ((disablev6) && (pos->ai_family == AF_INET6)) - continue; - i++; - } - if (0 == i) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Failed to find %saddress for `%s'.\n"), - disablev6 ? "IPv4 " : "", - hostname); - freeaddrinfo(res); - GNUNET_free(hostname); - GNUNET_free_non_null(unixpath); - return GNUNET_SYSERR; - } - resi = i; + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to find %saddress for `%s'.\n"), + disablev6 ? "IPv4 " : "", + hostname); + freeaddrinfo (res); + GNUNET_free (hostname); + GNUNET_free_non_null (unixpath); + return GNUNET_SYSERR; + } + resi = i; + if (NULL != unixpath) + resi++; + saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); + i = 0; + if (NULL != unixpath) + { + add_unixpath (saddrs, saddrlens, unixpath, abstract); + i++; + } + next = res; + while (NULL != (pos = next)) + { + next = pos->ai_next; + if ((disablev6) && (AF_INET6 == pos->ai_family)) + continue; + if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) + continue; /* not TCP */ + if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) + continue; /* huh? */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Service `%s' will bind to `%s'\n", + service_name, + GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); + if (AF_INET == pos->ai_family) + { + GNUNET_assert (sizeof(struct sockaddr_in) == pos->ai_addrlen); + saddrlens[i] = pos->ai_addrlen; + saddrs[i] = GNUNET_malloc (saddrlens[i]); + GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); + } + else + { + GNUNET_assert (AF_INET6 == pos->ai_family); + GNUNET_assert (sizeof(struct sockaddr_in6) == pos->ai_addrlen); + saddrlens[i] = pos->ai_addrlen; + saddrs[i] = GNUNET_malloc (saddrlens[i]); + GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); + ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); + } + i++; + } + GNUNET_free (hostname); + freeaddrinfo (res); + resi = i; + } + else + { + /* will bind against everything, just set port */ + if (disablev6) + { + /* V4-only */ + resi = 1; if (NULL != unixpath) resi++; - saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); i = 0; + saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); if (NULL != unixpath) - { - add_unixpath(saddrs, saddrlens, unixpath, abstract); - i++; - } - next = res; - while (NULL != (pos = next)) - { - next = pos->ai_next; - if ((disablev6) && (AF_INET6 == pos->ai_family)) - continue; - if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) - continue; /* not TCP */ - if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) - continue; /* huh? */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Service `%s' will bind to `%s'\n", - service_name, - GNUNET_a2s(pos->ai_addr, pos->ai_addrlen)); - if (AF_INET == pos->ai_family) - { - GNUNET_assert(sizeof(struct sockaddr_in) == pos->ai_addrlen); - saddrlens[i] = pos->ai_addrlen; - saddrs[i] = GNUNET_malloc(saddrlens[i]); - GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); - ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); - } - else - { - GNUNET_assert(AF_INET6 == pos->ai_family); - GNUNET_assert(sizeof(struct sockaddr_in6) == pos->ai_addrlen); - saddrlens[i] = pos->ai_addrlen; - saddrs[i] = GNUNET_malloc(saddrlens[i]); - GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); - ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); - } - i++; - } - GNUNET_free(hostname); - freeaddrinfo(res); - resi = i; - } - else - { - /* will bind against everything, just set port */ - if (disablev6) - { - /* V4-only */ - resi = 1; - if (NULL != unixpath) - resi++; - i = 0; - saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); - if (NULL != unixpath) - { - add_unixpath(saddrs, saddrlens, unixpath, abstract); - i++; - } - saddrlens[i] = sizeof(struct sockaddr_in); - saddrs[i] = GNUNET_malloc(saddrlens[i]); + { + add_unixpath (saddrs, saddrlens, unixpath, abstract); + i++; + } + saddrlens[i] = sizeof(struct sockaddr_in); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; + ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; #endif - ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; - ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); - } - else - { - /* dual stack */ - resi = 2; - if (NULL != unixpath) - resi++; - saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); - i = 0; - if (NULL != unixpath) - { - add_unixpath(saddrs, saddrlens, unixpath, abstract); - i++; - } - saddrlens[i] = sizeof(struct sockaddr_in6); - saddrs[i] = GNUNET_malloc(saddrlens[i]); + ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); + } + else + { + /* dual stack */ + resi = 2; + if (NULL != unixpath) + resi++; + saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); + i = 0; + if (NULL != unixpath) + { + add_unixpath (saddrs, saddrlens, unixpath, abstract); + i++; + } + saddrlens[i] = sizeof(struct sockaddr_in6); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; + ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; #endif - ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; - ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); - i++; - saddrlens[i] = sizeof(struct sockaddr_in); - saddrs[i] = GNUNET_malloc(saddrlens[i]); + ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; + ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); + i++; + saddrlens[i] = sizeof(struct sockaddr_in); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1]; + ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; #endif - ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; - ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); - } + ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); } - GNUNET_free_non_null(unixpath); + } + GNUNET_free_non_null (unixpath); *addrs = saddrs; *addr_lens = saddrlens; return resi; @@ -1375,26 +1388,26 @@ get_server_addresses(const char *service_name, * @param state new state of the session */ static void -notify_session_monitor(struct Plugin *plugin, - struct GNUNET_ATS_Session *session, - enum GNUNET_TRANSPORT_SessionState state) +notify_session_monitor (struct Plugin *plugin, + struct GNUNET_ATS_Session *session, + enum GNUNET_TRANSPORT_SessionState state) { struct GNUNET_TRANSPORT_SessionInfo info; if (NULL == plugin->sic) return; - memset(&info, 0, sizeof(info)); + memset (&info, 0, sizeof(info)); info.state = state; info.is_inbound = - GNUNET_HELLO_address_check_option(session->address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND); + GNUNET_HELLO_address_check_option (session->address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND); info.num_msg_pending = session->msgs_in_queue; info.num_bytes_pending = session->bytes_in_queue; if (NULL != session->receive_delay_task) info.receive_delay = session->receive_delay; info.session_timeout = session->timeout; info.address = session->address; - plugin->sic(plugin->sic_cls, session, &info); + plugin->sic (plugin->sic_cls, session, &info); } @@ -1411,12 +1424,12 @@ notify_session_monitor(struct Plugin *plugin, * @param addrlen actual length of @a addr */ static void -tcp_nat_port_map_callback(void *cls, - void **app_ctx, - int add_remove, - enum GNUNET_NAT_AddressClass ac, - const struct sockaddr *addr, - socklen_t addrlen) +tcp_nat_port_map_callback (void *cls, + void **app_ctx, + int add_remove, + enum GNUNET_NAT_AddressClass ac, + const struct sockaddr *addr, + socklen_t addrlen) { struct Plugin *plugin = cls; struct GNUNET_HELLO_Address *address; @@ -1425,57 +1438,57 @@ tcp_nat_port_map_callback(void *cls, void *arg; size_t args; - (void)app_ctx; - LOG(GNUNET_ERROR_TYPE_INFO, - "NAT notification to %s address `%s'\n", - (GNUNET_YES == add_remove) ? "add" : "remove", - GNUNET_a2s(addr, addrlen)); + (void) app_ctx; + LOG (GNUNET_ERROR_TYPE_INFO, + "NAT notification to %s address `%s'\n", + (GNUNET_YES == add_remove) ? "add" : "remove", + GNUNET_a2s (addr, addrlen)); /* convert 'addr' to our internal format */ switch (addr->sa_family) - { - case AF_INET: - GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); - memset(&t4, 0, sizeof(t4)); - t4.options = htonl(plugin->myoptions); - t4.ipv4_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; - t4.t4_port = ((struct sockaddr_in *)addr)->sin_port; - arg = &t4; - args = sizeof(t4); - break; - - case AF_INET6: - if (IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)addr)->sin6_addr)) - { - /* skip link local, we don't allow them in - #tcp_plugin_check_address() */ - return; - } - GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); - memset(&t6, 0, sizeof(t6)); - GNUNET_memcpy(&t6.ipv6_addr, - &((struct sockaddr_in6 *)addr)->sin6_addr, - sizeof(struct in6_addr)); - t6.options = htonl(plugin->myoptions); - t6.t6_port = ((struct sockaddr_in6 *)addr)->sin6_port; - arg = &t6; - args = sizeof(t6); - break; - - default: - GNUNET_break(0); + { + case AF_INET: + GNUNET_assert (addrlen == sizeof(struct sockaddr_in)); + memset (&t4, 0, sizeof(t4)); + t4.options = htonl (plugin->myoptions); + t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; + t4.t4_port = ((struct sockaddr_in *) addr)->sin_port; + arg = &t4; + args = sizeof(t4); + break; + + case AF_INET6: + if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) + { + /* skip link local, we don't allow them in + #tcp_plugin_check_address() */ return; } + GNUNET_assert (addrlen == sizeof(struct sockaddr_in6)); + memset (&t6, 0, sizeof(t6)); + GNUNET_memcpy (&t6.ipv6_addr, + &((struct sockaddr_in6 *) addr)->sin6_addr, + sizeof(struct in6_addr)); + t6.options = htonl (plugin->myoptions); + t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; + arg = &t6; + args = sizeof(t6); + break; + + default: + GNUNET_break (0); + return; + } /* modify our published address list */ - GNUNET_assert((args == sizeof(struct IPv4TcpAddress)) || - (args == sizeof(struct IPv6TcpAddress))); + GNUNET_assert ((args == sizeof(struct IPv4TcpAddress)) || + (args == sizeof(struct IPv6TcpAddress))); /* TODO: use 'ac' here in the future... */ - address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - PLUGIN_NAME, - arg, - args, - GNUNET_HELLO_ADDRESS_INFO_NONE); - plugin->env->notify_address(plugin->env->cls, add_remove, address); - GNUNET_HELLO_address_free(address); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, + arg, + args, + GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, add_remove, address); + GNUNET_HELLO_address_free (address); } @@ -1491,7 +1504,7 @@ tcp_nat_port_map_callback(void *cls, * @return string representing the same address */ static const char * -tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) +tcp_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) { static char rbuf[INET6_ADDRSTRLEN + 12]; char buf[INET6_ADDRSTRLEN]; @@ -1505,43 +1518,43 @@ tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) uint32_t options; switch (addrlen) - { - case sizeof(struct IPv6TcpAddress): - t6 = addr; - af = AF_INET6; - port = ntohs(t6->t6_port); - options = ntohl(t6->options); - GNUNET_memcpy(&a6, &t6->ipv6_addr, sizeof(a6)); - sb = &a6; - break; - - case sizeof(struct IPv4TcpAddress): - t4 = addr; - af = AF_INET; - port = ntohs(t4->t4_port); - options = ntohl(t4->options); - GNUNET_memcpy(&a4, &t4->ipv4_addr, sizeof(a4)); - sb = &a4; - break; - - default: - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Unexpected address length: %u bytes\n"), - (unsigned int)addrlen); - return NULL; - } - if (NULL == inet_ntop(af, sb, buf, INET6_ADDRSTRLEN)) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); - return NULL; - } - GNUNET_snprintf(rbuf, - sizeof(rbuf), - (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", - PLUGIN_NAME, - options, - buf, - port); + { + case sizeof(struct IPv6TcpAddress): + t6 = addr; + af = AF_INET6; + port = ntohs (t6->t6_port); + options = ntohl (t6->options); + GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof(a6)); + sb = &a6; + break; + + case sizeof(struct IPv4TcpAddress): + t4 = addr; + af = AF_INET; + port = ntohs (t4->t4_port); + options = ntohl (t4->options); + GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof(a4)); + sb = &a4; + break; + + default: + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("Unexpected address length: %u bytes\n"), + (unsigned int) addrlen); + return NULL; + } + if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); + return NULL; + } + GNUNET_snprintf (rbuf, + sizeof(rbuf), + (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", + PLUGIN_NAME, + options, + buf, + port); return rbuf; } @@ -1559,11 +1572,11 @@ tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -tcp_plugin_string_to_address(void *cls, - const char *addr, - uint16_t addrlen, - void **buf, - size_t *added) +tcp_plugin_string_to_address (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, + size_t *added) { struct sockaddr_storage socket_address; char *address; @@ -1576,57 +1589,57 @@ tcp_plugin_string_to_address(void *cls, plugin = NULL; optionstr = NULL; if ((NULL == addr) || (0 == addrlen)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if ('\0' != addr[addrlen - 1]) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - if (strlen(addr) != addrlen - 1) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - plugin = GNUNET_strdup(addr); - optionstr = strchr(plugin, '.'); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (strlen (addr) != addrlen - 1) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + plugin = GNUNET_strdup (addr); + optionstr = strchr (plugin, '.'); if (NULL == optionstr) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } optionstr[0] = '\0'; optionstr++; - options = atol(optionstr); - address = strchr(optionstr, '.'); + options = atol (optionstr); + address = strchr (optionstr, '.'); if (NULL == address) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } address[0] = '\0'; address++; if (GNUNET_OK != - GNUNET_STRINGS_to_address_ip(address, strlen(address), &socket_address)) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } + GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address)) + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } - GNUNET_free(plugin); + GNUNET_free (plugin); switch (socket_address.ss_family) - { - case AF_INET: { + { + case AF_INET: { struct IPv4TcpAddress *t4; - struct sockaddr_in *in4 = (struct sockaddr_in *)&socket_address; - t4 = GNUNET_new(struct IPv4TcpAddress); - t4->options = htonl(options); + struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; + t4 = GNUNET_new (struct IPv4TcpAddress); + t4->options = htonl (options); t4->ipv4_addr = in4->sin_addr.s_addr; t4->t4_port = in4->sin_port; *buf = t4; @@ -1634,11 +1647,11 @@ tcp_plugin_string_to_address(void *cls, return GNUNET_OK; } - case AF_INET6: { + case AF_INET6: { struct IPv6TcpAddress *t6; - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&socket_address; - t6 = GNUNET_new(struct IPv6TcpAddress); - t6->options = htonl(options); + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; + t6 = GNUNET_new (struct IPv6TcpAddress); + t6->options = htonl (options); t6->ipv6_addr = in6->sin6_addr; t6->t6_port = in6->sin6_port; *buf = t6; @@ -1646,9 +1659,9 @@ tcp_plugin_string_to_address(void *cls, return GNUNET_OK; } - default: - return GNUNET_SYSERR; - } + default: + return GNUNET_SYSERR; + } } @@ -1663,11 +1676,11 @@ tcp_plugin_string_to_address(void *cls, * @return NULL if no matching session exists */ static struct GNUNET_ATS_Session * -lookup_session_by_client(struct Plugin *plugin, - struct GNUNET_SERVER_Client *client) +lookup_session_by_client (struct Plugin *plugin, + struct GNUNET_SERVER_Client *client) { - return GNUNET_SERVER_client_get_user_context(client, - struct GNUNET_ATS_Session); + return GNUNET_SERVER_client_get_user_context (client, + struct GNUNET_ATS_Session); } @@ -1681,111 +1694,111 @@ lookup_session_by_client(struct Plugin *plugin, * @return #GNUNET_OK on success */ static int -tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session) +tcp_plugin_disconnect_session (void *cls, struct GNUNET_ATS_Session *session) { struct Plugin *plugin = cls; struct PendingMessage *pm; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting session of peer `%s' address `%s'\n", - GNUNET_i2s(&session->target), - tcp_plugin_address_to_string(session->plugin, - session->address->address, - session->address->address_length)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Disconnecting session of peer `%s' address `%s'\n", + GNUNET_i2s (&session->target), + tcp_plugin_address_to_string (session->plugin, + session->address->address, + session->address->address_length)); if (NULL != session->timeout_task) - { - GNUNET_SCHEDULER_cancel(session->timeout_task); - session->timeout_task = NULL; - session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; - } + { + GNUNET_SCHEDULER_cancel (session->timeout_task); + session->timeout_task = NULL; + session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; + } - if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(plugin->sessionmap, - &session->target, - session)) - { - GNUNET_STATISTICS_update(session->plugin->env->stats, - gettext_noop("# TCP sessions active"), - -1, - GNUNET_NO); - } + if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, + &session->target, + session)) + { + GNUNET_STATISTICS_update (session->plugin->env->stats, + gettext_noop ("# TCP sessions active"), + -1, + GNUNET_NO); + } else - { - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(plugin->nat_wait_conns, + { + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, &session->target, session)); - } + } if (NULL != session->client) - GNUNET_SERVER_client_set_user_context(session->client, NULL); + GNUNET_SERVER_client_set_user_context (session->client, NULL); /* clean up state */ if (NULL != session->transmit_handle) - { - GNUNET_SERVER_notify_transmit_ready_cancel(session->transmit_handle); - session->transmit_handle = NULL; - } - session->plugin->env->session_end(session->plugin->env->cls, - session->address, - session); + { + GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle); + session->transmit_handle = NULL; + } + session->plugin->env->session_end (session->plugin->env->cls, + session->address, + session); if (NULL != session->nat_connection_timeout) - { - GNUNET_SCHEDULER_cancel(session->nat_connection_timeout); - session->nat_connection_timeout = NULL; - } + { + GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); + session->nat_connection_timeout = NULL; + } while (NULL != (pm = session->pending_messages_head)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - (NULL != pm->transmit_cont) - ? "Could not deliver message to `%s' at %s.\n" - : "Could not deliver message to `%s' at %s, notifying.\n", - GNUNET_i2s(&session->target), - tcp_plugin_address_to_string(session->plugin, + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + (NULL != pm->transmit_cont) + ? "Could not deliver message to `%s' at %s.\n" + : "Could not deliver message to `%s' at %s, notifying.\n", + GNUNET_i2s (&session->target), + tcp_plugin_address_to_string (session->plugin, session->address->address, session->address->address_length)); - GNUNET_STATISTICS_update(session->plugin->env->stats, - gettext_noop("# bytes currently in TCP buffers"), - -(int64_t)pm->message_size, - GNUNET_NO); - GNUNET_STATISTICS_update(session->plugin->env->stats, - gettext_noop( - "# bytes discarded by TCP (disconnect)"), - pm->message_size, - GNUNET_NO); - GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, - session->pending_messages_tail, - pm); - GNUNET_assert(0 < session->msgs_in_queue); - session->msgs_in_queue--; - GNUNET_assert(pm->message_size <= session->bytes_in_queue); - session->bytes_in_queue -= pm->message_size; - if (NULL != pm->transmit_cont) - pm->transmit_cont(pm->transmit_cont_cls, - &session->target, - GNUNET_SYSERR, - pm->message_size, - 0); - GNUNET_free(pm); - } - GNUNET_assert(0 == session->msgs_in_queue); - GNUNET_assert(0 == session->bytes_in_queue); - notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_DONE); + GNUNET_STATISTICS_update (session->plugin->env->stats, + gettext_noop ("# bytes currently in TCP buffers"), + -(int64_t) pm->message_size, + GNUNET_NO); + GNUNET_STATISTICS_update (session->plugin->env->stats, + gettext_noop ( + "# bytes discarded by TCP (disconnect)"), + pm->message_size, + GNUNET_NO); + GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, + session->pending_messages_tail, + pm); + GNUNET_assert (0 < session->msgs_in_queue); + session->msgs_in_queue--; + GNUNET_assert (pm->message_size <= session->bytes_in_queue); + session->bytes_in_queue -= pm->message_size; + if (NULL != pm->transmit_cont) + pm->transmit_cont (pm->transmit_cont_cls, + &session->target, + GNUNET_SYSERR, + pm->message_size, + 0); + GNUNET_free (pm); + } + GNUNET_assert (0 == session->msgs_in_queue); + GNUNET_assert (0 == session->bytes_in_queue); + notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_DONE); if (NULL != session->receive_delay_task) - { - GNUNET_SCHEDULER_cancel(session->receive_delay_task); - session->receive_delay_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (session->receive_delay_task); + session->receive_delay_task = NULL; + } if (NULL != session->client) - { - GNUNET_SERVER_client_disconnect(session->client); - session->client = NULL; - } - GNUNET_HELLO_address_free(session->address); - GNUNET_assert(NULL == session->transmit_handle); - GNUNET_free(session); + { + GNUNET_SERVER_client_disconnect (session->client); + session->client = NULL; + } + GNUNET_HELLO_address_free (session->address); + GNUNET_assert (NULL == session->transmit_handle); + GNUNET_free (session); return GNUNET_OK; } @@ -1799,7 +1812,7 @@ tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session) * @return keepalive factor */ static unsigned int -tcp_plugin_query_keepalive_factor(void *cls) +tcp_plugin_query_keepalive_factor (void *cls) { return 3; } @@ -1811,29 +1824,29 @@ tcp_plugin_query_keepalive_factor(void *cls) * @param cls the `struct GNUNET_ATS_Session` of the idle session */ static void -session_timeout(void *cls) +session_timeout (void *cls) { struct GNUNET_ATS_Session *s = cls; struct GNUNET_TIME_Relative left; s->timeout_task = NULL; - left = GNUNET_TIME_absolute_get_remaining(s->timeout); + left = GNUNET_TIME_absolute_get_remaining (s->timeout); if (0 != left.rel_value_us) - { - /* not actually our turn yet, but let's at least update - the monitor, it may think we're about to die ... */ - notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); - s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, &session_timeout, s); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p was idle for %s, disconnecting\n", - s, - GNUNET_STRINGS_relative_time_to_string( - GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - GNUNET_YES)); + { + /* not actually our turn yet, but let's at least update + the monitor, it may think we're about to die ... */ + notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); + s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p was idle for %s, disconnecting\n", + s, + GNUNET_STRINGS_relative_time_to_string ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + GNUNET_YES)); /* call session destroy function */ - tcp_plugin_disconnect_session(s->plugin, s); + tcp_plugin_disconnect_session (s->plugin, s); } @@ -1843,11 +1856,11 @@ session_timeout(void *cls) * @param s session to increment timeout for */ static void -reschedule_session_timeout(struct GNUNET_ATS_Session *s) +reschedule_session_timeout (struct GNUNET_ATS_Session *s) { - GNUNET_assert(NULL != s->timeout_task); + GNUNET_assert (NULL != s->timeout_task); s->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); } @@ -1864,75 +1877,75 @@ reschedule_session_timeout(struct GNUNET_ATS_Session *s) * @return new session object */ static struct GNUNET_ATS_Session * -create_session(struct Plugin *plugin, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_NetworkType scope, - struct GNUNET_SERVER_Client *client, - int is_nat) +create_session (struct Plugin *plugin, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_NetworkType scope, + struct GNUNET_SERVER_Client *client, + int is_nat) { struct GNUNET_ATS_Session *session; struct PendingMessage *pm; if (GNUNET_YES != is_nat) - GNUNET_assert(NULL != client); + GNUNET_assert (NULL != client); else - GNUNET_assert(NULL == client); - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Creating new session for peer `%s' at address %s\n", - GNUNET_i2s(&address->peer), - tcp_plugin_address_to_string(plugin, - address->address, - address->address_length)); - session = GNUNET_new(struct GNUNET_ATS_Session); - session->last_activity = GNUNET_TIME_absolute_get(); + GNUNET_assert (NULL == client); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Creating new session for peer `%s' at address %s\n", + GNUNET_i2s (&address->peer), + tcp_plugin_address_to_string (plugin, + address->address, + address->address_length)); + session = GNUNET_new (struct GNUNET_ATS_Session); + session->last_activity = GNUNET_TIME_absolute_get (); session->plugin = plugin; session->is_nat = is_nat; if (NULL != client) - { - session->client = client; - GNUNET_SERVER_client_set_user_context(client, session); - } - session->address = GNUNET_HELLO_address_copy(address); + { + session->client = client; + GNUNET_SERVER_client_set_user_context (client, session); + } + session->address = GNUNET_HELLO_address_copy (address); session->target = address->peer; session->expecting_welcome = GNUNET_YES; session->scope = scope; - pm = GNUNET_malloc(sizeof(struct PendingMessage) + - sizeof(struct WelcomeMessage)); - pm->msg = (const char *)&pm[1]; + pm = GNUNET_malloc (sizeof(struct PendingMessage) + + sizeof(struct WelcomeMessage)); + pm->msg = (const char *) &pm[1]; pm->message_size = sizeof(struct WelcomeMessage); - GNUNET_memcpy(&pm[1], &plugin->my_welcome, sizeof(struct WelcomeMessage)); + GNUNET_memcpy (&pm[1], &plugin->my_welcome, sizeof(struct WelcomeMessage)); pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# bytes currently in TCP buffers"), - pm->message_size, - GNUNET_NO); - GNUNET_CONTAINER_DLL_insert(session->pending_messages_head, - session->pending_messages_tail, - pm); + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# bytes currently in TCP buffers"), + pm->message_size, + GNUNET_NO); + GNUNET_CONTAINER_DLL_insert (session->pending_messages_head, + session->pending_messages_tail, + pm); session->msgs_in_queue++; session->bytes_in_queue += pm->message_size; session->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); session->timeout_task = - GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - &session_timeout, - session); - notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_INIT); + GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + &session_timeout, + session); + notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_INIT); if (GNUNET_YES != is_nat) - { - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# TCP sessions active"), - 1, - GNUNET_NO); - notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_UP); - } + { + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# TCP sessions active"), + 1, + GNUNET_NO); + notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UP); + } else - { - notify_session_monitor(session->plugin, - session, - GNUNET_TRANSPORT_SS_HANDSHAKE); - } + { + notify_session_monitor (session->plugin, + session, + GNUNET_TRANSPORT_SS_HANDSHAKE); + } return session; } @@ -1944,7 +1957,7 @@ create_session(struct Plugin *plugin, * @param session for which session should we do this */ static void -process_pending_messages(struct GNUNET_ATS_Session *session); +process_pending_messages (struct GNUNET_ATS_Session *session); /** @@ -1959,7 +1972,7 @@ process_pending_messages(struct GNUNET_ATS_Session *session); * @return number of bytes written to @a buf */ static size_t -do_transmit(void *cls, size_t size, void *buf) +do_transmit (void *cls, size_t size, void *buf) { struct GNUNET_ATS_Session *session = cls; struct GNUNET_PeerIdentity pid; @@ -1974,127 +1987,127 @@ do_transmit(void *cls, size_t size, void *buf) session->transmit_handle = NULL; plugin = session->plugin; if (NULL == buf) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Timeout trying to transmit to peer `%s', discarding message queue.\n", - GNUNET_i2s(&session->target)); - /* timeout; cancel all messages that have already expired */ - hd = NULL; - tl = NULL; - ret = 0; - now = GNUNET_TIME_absolute_get(); - while ((NULL != (pos = session->pending_messages_head)) && - (pos->timeout.abs_value_us <= now.abs_value_us)) - { - GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, - session->pending_messages_tail, - pos); - GNUNET_assert(0 < session->msgs_in_queue); - session->msgs_in_queue--; - GNUNET_assert(pos->message_size <= session->bytes_in_queue); - session->bytes_in_queue -= pos->message_size; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Failed to transmit %u byte message to `%s'.\n", - pos->message_size, - GNUNET_i2s(&session->target)); - ret += pos->message_size; - GNUNET_CONTAINER_DLL_insert_after(hd, tl, tl, pos); - } - /* do this call before callbacks (so that if callbacks destroy - * session, they have a chance to cancel actions done by this - * call) */ - process_pending_messages(session); - pid = session->target; - /* no do callbacks and do not use session again since - * the callbacks may abort the session */ - while (NULL != (pos = hd)) - { - GNUNET_CONTAINER_DLL_remove(hd, tl, pos); - if (NULL != pos->transmit_cont) - pos->transmit_cont(pos->transmit_cont_cls, - &pid, - GNUNET_SYSERR, - pos->message_size, - 0); - GNUNET_free(pos); - } - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# bytes currently in TCP buffers"), - -(int64_t)ret, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop( - "# bytes discarded by TCP (timeout)"), - ret, - GNUNET_NO); - if (0 < ret) - notify_session_monitor(session->plugin, - session, - GNUNET_TRANSPORT_SS_UPDATE); - return 0; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Timeout trying to transmit to peer `%s', discarding message queue.\n", + GNUNET_i2s (&session->target)); + /* timeout; cancel all messages that have already expired */ + hd = NULL; + tl = NULL; + ret = 0; + now = GNUNET_TIME_absolute_get (); + while ((NULL != (pos = session->pending_messages_head)) && + (pos->timeout.abs_value_us <= now.abs_value_us)) + { + GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, + session->pending_messages_tail, + pos); + GNUNET_assert (0 < session->msgs_in_queue); + session->msgs_in_queue--; + GNUNET_assert (pos->message_size <= session->bytes_in_queue); + session->bytes_in_queue -= pos->message_size; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Failed to transmit %u byte message to `%s'.\n", + pos->message_size, + GNUNET_i2s (&session->target)); + ret += pos->message_size; + GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); + } + /* do this call before callbacks (so that if callbacks destroy + * session, they have a chance to cancel actions done by this + * call) */ + process_pending_messages (session); + pid = session->target; + /* no do callbacks and do not use session again since + * the callbacks may abort the session */ + while (NULL != (pos = hd)) + { + GNUNET_CONTAINER_DLL_remove (hd, tl, pos); + if (NULL != pos->transmit_cont) + pos->transmit_cont (pos->transmit_cont_cls, + &pid, + GNUNET_SYSERR, + pos->message_size, + 0); + GNUNET_free (pos); + } + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# bytes currently in TCP buffers"), + -(int64_t) ret, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ( + "# bytes discarded by TCP (timeout)"), + ret, + GNUNET_NO); + if (0 < ret) + notify_session_monitor (session->plugin, + session, + GNUNET_TRANSPORT_SS_UPDATE); + return 0; + } /* copy all pending messages that would fit */ ret = 0; cbuf = buf; hd = NULL; tl = NULL; while (NULL != (pos = session->pending_messages_head)) - { - if (ret + pos->message_size > size) - break; - GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, - session->pending_messages_tail, - pos); - GNUNET_assert(0 < session->msgs_in_queue); - session->msgs_in_queue--; - GNUNET_assert(pos->message_size <= session->bytes_in_queue); - session->bytes_in_queue -= pos->message_size; - GNUNET_assert(size >= pos->message_size); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Transmitting message of type %u size %u to peer %s at %s\n", - ntohs(((struct GNUNET_MessageHeader *)pos->msg)->type), - pos->message_size, - GNUNET_i2s(&session->target), - tcp_plugin_address_to_string(session->plugin, + { + if (ret + pos->message_size > size) + break; + GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, + session->pending_messages_tail, + pos); + GNUNET_assert (0 < session->msgs_in_queue); + session->msgs_in_queue--; + GNUNET_assert (pos->message_size <= session->bytes_in_queue); + session->bytes_in_queue -= pos->message_size; + GNUNET_assert (size >= pos->message_size); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting message of type %u size %u to peer %s at %s\n", + ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), + pos->message_size, + GNUNET_i2s (&session->target), + tcp_plugin_address_to_string (session->plugin, session->address->address, session->address->address_length)); - /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */ - GNUNET_memcpy(cbuf, pos->msg, pos->message_size); - cbuf += pos->message_size; - ret += pos->message_size; - size -= pos->message_size; - GNUNET_CONTAINER_DLL_insert_tail(hd, tl, pos); - } - notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE); + /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */ + GNUNET_memcpy (cbuf, pos->msg, pos->message_size); + cbuf += pos->message_size; + ret += pos->message_size; + size -= pos->message_size; + GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos); + } + notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE); /* schedule 'continuation' before callbacks so that callbacks that * cancel everything don't cause us to use a session that no longer * exists... */ - process_pending_messages(session); - session->last_activity = GNUNET_TIME_absolute_get(); + process_pending_messages (session); + session->last_activity = GNUNET_TIME_absolute_get (); pid = session->target; /* we'll now call callbacks that may cancel the session; hence * we should not use 'session' after this point */ while (NULL != (pos = hd)) - { - GNUNET_CONTAINER_DLL_remove(hd, tl, pos); - if (NULL != pos->transmit_cont) - pos->transmit_cont(pos->transmit_cont_cls, - &pid, - GNUNET_OK, - pos->message_size, - pos->message_size); /* FIXME: include TCP overhead */ - GNUNET_free(pos); - } - GNUNET_assert(NULL == hd); - GNUNET_assert(NULL == tl); - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# bytes currently in TCP buffers"), - -(int64_t)ret, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# bytes transmitted via TCP"), - ret, - GNUNET_NO); + { + GNUNET_CONTAINER_DLL_remove (hd, tl, pos); + if (NULL != pos->transmit_cont) + pos->transmit_cont (pos->transmit_cont_cls, + &pid, + GNUNET_OK, + pos->message_size, + pos->message_size); /* FIXME: include TCP overhead */ + GNUNET_free (pos); + } + GNUNET_assert (NULL == hd); + GNUNET_assert (NULL == tl); + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# bytes currently in TCP buffers"), + -(int64_t) ret, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# bytes transmitted via TCP"), + ret, + GNUNET_NO); return ret; } @@ -2106,23 +2119,23 @@ do_transmit(void *cls, size_t size, void *buf) * @param session for which session should we do this */ static void -process_pending_messages(struct GNUNET_ATS_Session *session) +process_pending_messages (struct GNUNET_ATS_Session *session) { struct PendingMessage *pm; - GNUNET_assert(NULL != session->client); + GNUNET_assert (NULL != session->client); if (NULL != session->transmit_handle) return; if (NULL == (pm = session->pending_messages_head)) return; session->transmit_handle = - GNUNET_SERVER_notify_transmit_ready(session->client, - pm->message_size, - GNUNET_TIME_absolute_get_remaining( - pm->timeout), - &do_transmit, - session); + GNUNET_SERVER_notify_transmit_ready (session->client, + pm->message_size, + GNUNET_TIME_absolute_get_remaining ( + pm->timeout), + &do_transmit, + session); } @@ -2154,85 +2167,85 @@ process_pending_messages(struct GNUNET_ATS_Session *session) * and does NOT mean that the message was not transmitted (DV) */ static ssize_t -tcp_plugin_send(void *cls, - struct GNUNET_ATS_Session *session, - const char *msgbuf, - size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls) +tcp_plugin_send (void *cls, + struct GNUNET_ATS_Session *session, + const char *msgbuf, + size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { struct Plugin *plugin = cls; struct PendingMessage *pm; /* create new message entry */ - pm = GNUNET_malloc(sizeof(struct PendingMessage) + msgbuf_size); - pm->msg = (const char *)&pm[1]; - GNUNET_memcpy(&pm[1], msgbuf, msgbuf_size); + pm = GNUNET_malloc (sizeof(struct PendingMessage) + msgbuf_size); + pm->msg = (const char *) &pm[1]; + GNUNET_memcpy (&pm[1], msgbuf, msgbuf_size); pm->message_size = msgbuf_size; - pm->timeout = GNUNET_TIME_relative_to_absolute(to); + pm->timeout = GNUNET_TIME_relative_to_absolute (to); pm->transmit_cont = cont; pm->transmit_cont_cls = cont_cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Asked to transmit %u bytes to `%s', added message to list.\n", - msgbuf_size, - GNUNET_i2s(&session->target)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Asked to transmit %u bytes to `%s', added message to list.\n", + msgbuf_size, + GNUNET_i2s (&session->target)); if (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessionmap, - &session->target, - session)) - { - GNUNET_assert(NULL != session->client); - GNUNET_SERVER_client_set_timeout(session->client, - GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# bytes currently in TCP buffers"), - msgbuf_size, - GNUNET_NO); - - /* append pm to pending_messages list */ - GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head, - session->pending_messages_tail, - pm); - notify_session_monitor(session->plugin, - session, - GNUNET_TRANSPORT_SS_UPDATE); - session->msgs_in_queue++; - session->bytes_in_queue += pm->message_size; - process_pending_messages(session); - return msgbuf_size; - } + GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, + &session->target, + session)) + { + GNUNET_assert (NULL != session->client); + GNUNET_SERVER_client_set_timeout (session->client, + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# bytes currently in TCP buffers"), + msgbuf_size, + GNUNET_NO); + + /* append pm to pending_messages list */ + GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, + session->pending_messages_tail, + pm); + notify_session_monitor (session->plugin, + session, + GNUNET_TRANSPORT_SS_UPDATE); + session->msgs_in_queue++; + session->bytes_in_queue += pm->message_size; + process_pending_messages (session); + return msgbuf_size; + } if (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_contains_value(plugin->nat_wait_conns, - &session->target, - session)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "This NAT WAIT session for peer `%s' is not yet ready!\n", - GNUNET_i2s(&session->target)); - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# bytes currently in TCP buffers"), - msgbuf_size, - GNUNET_NO); - /* append pm to pending_messages list */ - GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head, - session->pending_messages_tail, - pm); - session->msgs_in_queue++; - session->bytes_in_queue += pm->message_size; - notify_session_monitor(session->plugin, - session, - GNUNET_TRANSPORT_SS_HANDSHAKE); - return msgbuf_size; - } - LOG(GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session); - if (NULL != cont) - cont(cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); - GNUNET_break(0); - GNUNET_free(pm); + GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns, + &session->target, + session)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "This NAT WAIT session for peer `%s' is not yet ready!\n", + GNUNET_i2s (&session->target)); + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# bytes currently in TCP buffers"), + msgbuf_size, + GNUNET_NO); + /* append pm to pending_messages list */ + GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, + session->pending_messages_tail, + pm); + session->msgs_in_queue++; + session->bytes_in_queue += pm->message_size; + notify_session_monitor (session->plugin, + session, + GNUNET_TRANSPORT_SS_HANDSHAKE); + return msgbuf_size; + } + LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session); + if (NULL != cont) + cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); + GNUNET_break (0); + GNUNET_free (pm); return GNUNET_SYSERR; /* session does not exist here */ } @@ -2240,7 +2253,8 @@ tcp_plugin_send(void *cls, /** * Closure for #session_lookup_it(). */ -struct GNUNET_ATS_SessionItCtx { +struct GNUNET_ATS_SessionItCtx +{ /** * Address we are looking for. */ @@ -2262,14 +2276,14 @@ struct GNUNET_ATS_SessionItCtx { * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session */ static int -session_lookup_it(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +session_lookup_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct GNUNET_ATS_SessionItCtx *si_ctx = cls; struct GNUNET_ATS_Session *session = value; - if (0 != GNUNET_HELLO_address_cmp(si_ctx->address, session->address)) + if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address)) return GNUNET_YES; si_ctx->result = session; return GNUNET_NO; @@ -2282,18 +2296,18 @@ session_lookup_it(void *cls, * @param cls the `struct GNUNET_ATS_Session` */ static void -nat_connect_timeout(void *cls) +nat_connect_timeout (void *cls) { struct GNUNET_ATS_Session *session = cls; session->nat_connection_timeout = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", - GNUNET_i2s(&session->target), - tcp_plugin_address_to_string(session->plugin, - session->address->address, - session->address->address_length)); - tcp_plugin_disconnect_session(session->plugin, session); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", + GNUNET_i2s (&session->target), + tcp_plugin_address_to_string (session->plugin, + session->address->address, + session->address->address_length)); + tcp_plugin_disconnect_session (session->plugin, session); } @@ -2307,11 +2321,11 @@ nat_connect_timeout(void *cls) * @param session which session is being updated */ static void -tcp_plugin_update_session_timeout(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session) +tcp_plugin_update_session_timeout (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session) { - reschedule_session_timeout(session); + reschedule_session_timeout (session); } @@ -2322,13 +2336,13 @@ tcp_plugin_update_session_timeout(void *cls, * @param cls the `struct GNUNET_ATS_Session *` */ static void -delayed_done(void *cls) +delayed_done (void *cls) { struct GNUNET_ATS_Session *session = cls; session->receive_delay_task = NULL; - reschedule_session_timeout(session); - GNUNET_SERVER_receive_done(session->client, GNUNET_OK); + reschedule_session_timeout (session); + GNUNET_SERVER_receive_done (session->client, GNUNET_OK); } @@ -2343,20 +2357,20 @@ delayed_done(void *cls) * @param delay new delay to use for receiving */ static void -tcp_plugin_update_inbound_delay(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session, - struct GNUNET_TIME_Relative delay) +tcp_plugin_update_inbound_delay (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session, + struct GNUNET_TIME_Relative delay) { if (NULL == session->receive_delay_task) return; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "New inbound delay %s\n", - GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_NO)); - session->receive_delay = GNUNET_TIME_relative_to_absolute(delay); - GNUNET_SCHEDULER_cancel(session->receive_delay_task); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New inbound delay %s\n", + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_NO)); + session->receive_delay = GNUNET_TIME_relative_to_absolute (delay); + GNUNET_SCHEDULER_cancel (session->receive_delay_task); session->receive_delay_task = - GNUNET_SCHEDULER_add_delayed(delay, &delayed_done, session); + GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); } @@ -2370,7 +2384,7 @@ tcp_plugin_update_inbound_delay(void *cls, * @return the session if the address is valid, NULL otherwise */ static struct GNUNET_ATS_Session * -tcp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) +tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session = NULL; @@ -2392,230 +2406,230 @@ tcp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) #endif addrlen = address->address_length; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Trying to get session for `%s' address of peer `%s'\n", - tcp_plugin_address_to_string(plugin, - address->address, - address->address_length), - GNUNET_i2s(&address->peer)); - - if (GNUNET_HELLO_address_check_option(address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)) - { - GNUNET_break(0); - return NULL; - } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Trying to get session for `%s' address of peer `%s'\n", + tcp_plugin_address_to_string (plugin, + address->address, + address->address_length), + GNUNET_i2s (&address->peer)); + + if (GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)) + { + GNUNET_break (0); + return NULL; + } /* look for existing session */ - if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(plugin->sessionmap, - &address->peer)) - { - struct GNUNET_ATS_SessionItCtx si_ctx; - - si_ctx.address = address; - si_ctx.result = NULL; - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessionmap, - &address->peer, - &session_lookup_it, - &si_ctx); - if (NULL != si_ctx.result) - { - session = si_ctx.result; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found existing session for `%s' address `%s'\n", - GNUNET_i2s(&address->peer), - tcp_plugin_address_to_string(plugin, - address->address, - address->address_length)); - return session; - } - /* This is a bit of a hack, limiting TCP to never allow more than - one TCP connection to any given peer at the same time. - Without this, peers sometimes disagree about which of the TCP - connections they should use, causing one side to believe that - they transmit successfully, while the other receives nothing. */ - return NULL; /* Refuse to have more than one TCP connection per + if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, + &address->peer)) + { + struct GNUNET_ATS_SessionItCtx si_ctx; + + si_ctx.address = address; + si_ctx.result = NULL; + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, + &address->peer, + &session_lookup_it, + &si_ctx); + if (NULL != si_ctx.result) + { + session = si_ctx.result; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found existing session for `%s' address `%s'\n", + GNUNET_i2s (&address->peer), + tcp_plugin_address_to_string (plugin, + address->address, + address->address_length)); + return session; + } + /* This is a bit of a hack, limiting TCP to never allow more than + one TCP connection to any given peer at the same time. + Without this, peers sometimes disagree about which of the TCP + connections they should use, causing one side to believe that + they transmit successfully, while the other receives nothing. */ + return NULL; /* Refuse to have more than one TCP connection per peer pair at the same time. */ - } + } if (addrlen == sizeof(struct IPv6TcpAddress)) - { - GNUNET_assert(NULL != address->address); /* make static analysis happy */ - t6 = address->address; - options = t6->options; - af = AF_INET6; - memset(&a6, 0, sizeof(a6)); + { + GNUNET_assert (NULL != address->address); /* make static analysis happy */ + t6 = address->address; + options = t6->options; + af = AF_INET6; + memset (&a6, 0, sizeof(a6)); #if HAVE_SOCKADDR_IN_SIN_LEN - a6.sin6_len = sizeof(a6); + a6.sin6_len = sizeof(a6); #endif - a6.sin6_family = AF_INET6; - a6.sin6_port = t6->t6_port; - if (t6->t6_port == 0) - is_natd = GNUNET_YES; - GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); - sb = &a6; - sbs = sizeof(a6); - } + a6.sin6_family = AF_INET6; + a6.sin6_port = t6->t6_port; + if (t6->t6_port == 0) + is_natd = GNUNET_YES; + GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); + sb = &a6; + sbs = sizeof(a6); + } else if (addrlen == sizeof(struct IPv4TcpAddress)) - { - GNUNET_assert(NULL != address->address); /* make static analysis happy */ - t4 = address->address; - options = t4->options; - af = AF_INET; - memset(&a4, 0, sizeof(a4)); + { + GNUNET_assert (NULL != address->address); /* make static analysis happy */ + t4 = address->address; + options = t4->options; + af = AF_INET; + memset (&a4, 0, sizeof(a4)); #if HAVE_SOCKADDR_IN_SIN_LEN - a4.sin_len = sizeof(a4); + a4.sin_len = sizeof(a4); #endif - a4.sin_family = AF_INET; - a4.sin_port = t4->t4_port; - if (t4->t4_port == 0) - is_natd = GNUNET_YES; - a4.sin_addr.s_addr = t4->ipv4_addr; - sb = &a4; - sbs = sizeof(a4); - } + a4.sin_family = AF_INET; + a4.sin_port = t4->t4_port; + if (t4->t4_port == 0) + is_natd = GNUNET_YES; + a4.sin_addr.s_addr = t4->ipv4_addr; + sb = &a4; + sbs = sizeof(a4); + } else - { - GNUNET_STATISTICS_update( - plugin->env->stats, - gettext_noop("# requests to create session with invalid address"), - 1, - GNUNET_NO); - return NULL; - } + { + GNUNET_STATISTICS_update ( + plugin->env->stats, + gettext_noop ("# requests to create session with invalid address"), + 1, + GNUNET_NO); + return NULL; + } - net_type = plugin->env->get_address_type(plugin->env->cls, sb, sbs); - GNUNET_break(net_type != GNUNET_NT_UNSPECIFIED); + net_type = plugin->env->get_address_type (plugin->env->cls, sb, sbs); + GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED); if ((is_natd == GNUNET_YES) && (addrlen == sizeof(struct IPv6TcpAddress))) - { - /* NAT client only works with IPv4 addresses */ - return NULL; - } + { + /* NAT client only works with IPv4 addresses */ + return NULL; + } if (plugin->cur_connections >= plugin->max_connections) - { - /* saturated */ - return NULL; - } + { + /* saturated */ + return NULL; + } if ((is_natd == GNUNET_YES) && (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_contains(plugin->nat_wait_conns, - &address->peer))) - { - /* Only do one NAT punch attempt per peer identity */ - return NULL; - } + GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, + &address->peer))) + { + /* Only do one NAT punch attempt per peer identity */ + return NULL; + } if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && (GNUNET_NO == - GNUNET_CONTAINER_multipeermap_contains(plugin->nat_wait_conns, - &address->peer))) - { - struct sockaddr_in local_sa; - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found valid IPv4 NAT address (creating session)!\n"); - session = create_session(plugin, address, net_type, NULL, GNUNET_YES); - session->nat_connection_timeout = - GNUNET_SCHEDULER_add_delayed(NAT_TIMEOUT, &nat_connect_timeout, session); - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put( - plugin->nat_wait_conns, - &session->target, - session, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Created NAT WAIT connection to `%s' at `%s'\n", - GNUNET_i2s(&session->target), - GNUNET_a2s(sb, sbs)); - memset(&local_sa, 0, sizeof(local_sa)); - local_sa.sin_family = AF_INET; - local_sa.sin_port = htons(plugin->open_port); - /* We leave sin_address at 0, let the kernel figure it out, - even if our bind() is more specific. (May want to reconsider - later.) */ - if (GNUNET_OK == GNUNET_NAT_request_reversal(plugin->nat, &local_sa, &a4)) - return session; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Running NAT client for `%s' at `%s' failed\n", - GNUNET_i2s(&session->target), - GNUNET_a2s(sb, sbs)); - tcp_plugin_disconnect_session(plugin, session); - return NULL; - } + GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, + &address->peer))) + { + struct sockaddr_in local_sa; + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found valid IPv4 NAT address (creating session)!\n"); + session = create_session (plugin, address, net_type, NULL, GNUNET_YES); + session->nat_connection_timeout = + GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, &nat_connect_timeout, session); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put ( + plugin->nat_wait_conns, + &session->target, + session, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Created NAT WAIT connection to `%s' at `%s'\n", + GNUNET_i2s (&session->target), + GNUNET_a2s (sb, sbs)); + memset (&local_sa, 0, sizeof(local_sa)); + local_sa.sin_family = AF_INET; + local_sa.sin_port = htons (plugin->open_port); + /* We leave sin_address at 0, let the kernel figure it out, + even if our bind() is more specific. (May want to reconsider + later.) */ + if (GNUNET_OK == GNUNET_NAT_request_reversal (plugin->nat, &local_sa, &a4)) + return session; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Running NAT client for `%s' at `%s' failed\n", + GNUNET_i2s (&session->target), + GNUNET_a2s (sb, sbs)); + tcp_plugin_disconnect_session (plugin, session); + return NULL; + } /* create new outbound session */ if (0 != (options & TCP_OPTIONS_TCP_STEALTH)) - { + { #ifdef TCP_STEALTH - s = GNUNET_NETWORK_socket_create(af, SOCK_STREAM, 0); - if (NULL == s) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - "socket"); - sa = NULL; - } + s = GNUNET_NETWORK_socket_create (af, SOCK_STREAM, 0); + if (NULL == s) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, + "socket"); + sa = NULL; + } + else + { + if ((GNUNET_OK != + GNUNET_NETWORK_socket_setsockopt (s, + IPPROTO_TCP, + TCP_STEALTH, + &session->target, + sizeof( + struct GNUNET_PeerIdentity))) || + (GNUNET_OK != + GNUNET_NETWORK_socket_setsockopt (s, + IPPROTO_TCP, + TCP_STEALTH_INTEGRITY, + &plugin->my_welcome, + sizeof(struct WelcomeMessage)))) + { + /* TCP STEALTH not supported by kernel */ + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); + sa = NULL; + } else - { - if ((GNUNET_OK != - GNUNET_NETWORK_socket_setsockopt(s, - IPPROTO_TCP, - TCP_STEALTH, - &session->target, - sizeof( - struct GNUNET_PeerIdentity))) || - (GNUNET_OK != - GNUNET_NETWORK_socket_setsockopt(s, - IPPROTO_TCP, - TCP_STEALTH_INTEGRITY, - &plugin->my_welcome, - sizeof(struct WelcomeMessage)))) - { - /* TCP STEALTH not supported by kernel */ - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(s)); - sa = NULL; - } - else - { - sa = GNUNET_CONNECTION_connect_socket(s, sb, sbs); - } - } + { + sa = GNUNET_CONNECTION_connect_socket (s, sb, sbs); + } + } #else - sa = NULL; + sa = NULL; #endif - } + } else - { - sa = GNUNET_CONNECTION_create_from_sockaddr(af, sb, sbs); - } + { + sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs); + } if (NULL == sa) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Failed to create connection to `%s' at `%s'\n", - GNUNET_i2s(&address->peer), - GNUNET_a2s(sb, sbs)); - return NULL; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Asked to transmit to `%s', creating fresh session using address `%s'.\n", - GNUNET_i2s(&address->peer), - GNUNET_a2s(sb, sbs)); - - session = create_session(plugin, - address, - net_type, - GNUNET_SERVER_connect_socket(plugin->server, sa), - GNUNET_NO); - (void)GNUNET_CONTAINER_multipeermap_put( + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Failed to create connection to `%s' at `%s'\n", + GNUNET_i2s (&address->peer), + GNUNET_a2s (sb, sbs)); + return NULL; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Asked to transmit to `%s', creating fresh session using address `%s'.\n", + GNUNET_i2s (&address->peer), + GNUNET_a2s (sb, sbs)); + + session = create_session (plugin, + address, + net_type, + GNUNET_SERVER_connect_socket (plugin->server, sa), + GNUNET_NO); + (void) GNUNET_CONTAINER_multipeermap_put ( plugin->sessionmap, &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); /* Send TCP Welcome */ - process_pending_messages(session); + process_pending_messages (session); return session; } @@ -2632,19 +2646,19 @@ tcp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) * @return #GNUNET_YES (continue to iterate) */ static int -session_disconnect_it(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +session_disconnect_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session = value; - GNUNET_STATISTICS_update(session->plugin->env->stats, - gettext_noop( - "# transport-service disconnect requests for TCP"), - 1, - GNUNET_NO); - tcp_plugin_disconnect_session(plugin, session); + GNUNET_STATISTICS_update (session->plugin->env->stats, + gettext_noop ( + "# transport-service disconnect requests for TCP"), + 1, + GNUNET_NO); + tcp_plugin_disconnect_session (plugin, session); return GNUNET_YES; } @@ -2666,21 +2680,21 @@ session_disconnect_it(void *cls, * to be cancelled */ static void -tcp_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) +tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting peer `%s'\n", - GNUNET_i2s(target)); - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessionmap, - target, - &session_disconnect_it, - plugin); - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->nat_wait_conns, - target, - &session_disconnect_it, - plugin); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Disconnecting peer `%s'\n", + GNUNET_i2s (target)); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, + target, + &session_disconnect_it, + plugin); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->nat_wait_conns, + target, + &session_disconnect_it, + plugin); } @@ -2695,42 +2709,42 @@ tcp_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) * @param hostname hostname part of the address */ static void -append_port(void *cls, const char *hostname) +append_port (void *cls, const char *hostname) { struct PrettyPrinterContext *ppc = cls; struct Plugin *plugin = ppc->plugin; char *ret; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "append_port called with hostname `%s'\n", - hostname); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "append_port called with hostname `%s'\n", + hostname); if (NULL == hostname) - { - /* Final call, done */ - ppc->resolver_handle = NULL; - GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head, - plugin->ppc_dll_tail, - ppc); - ppc->asc(ppc->asc_cls, NULL, GNUNET_OK); - GNUNET_free(ppc); - return; - } + { + /* Final call, done */ + ppc->resolver_handle = NULL; + GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, + plugin->ppc_dll_tail, + ppc); + ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); + GNUNET_free (ppc); + return; + } if (GNUNET_YES == ppc->ipv6) - GNUNET_asprintf(&ret, - "%s.%u.[%s]:%d", - PLUGIN_NAME, - ppc->options, - hostname, - ppc->port); + GNUNET_asprintf (&ret, + "%s.%u.[%s]:%d", + PLUGIN_NAME, + ppc->options, + hostname, + ppc->port); else - GNUNET_asprintf(&ret, - "%s.%u.%s:%d", - PLUGIN_NAME, - ppc->options, - hostname, - ppc->port); - ppc->asc(ppc->asc_cls, ret, GNUNET_OK); - GNUNET_free(ret); + GNUNET_asprintf (&ret, + "%s.%u.%s:%d", + PLUGIN_NAME, + ppc->options, + hostname, + ppc->port); + ppc->asc (ppc->asc_cls, ret, GNUNET_OK); + GNUNET_free (ret); } @@ -2748,14 +2762,14 @@ append_port(void *cls, const char *hostname) * @param asc_cls closure for @a asc */ static void -tcp_plugin_address_pretty_printer(void *cls, - const char *type, - const void *addr, - size_t addrlen, - int numeric, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback asc, - void *asc_cls) +tcp_plugin_address_pretty_printer (void *cls, + const char *type, + const void *addr, + size_t addrlen, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback asc, + void *asc_cls) { struct Plugin *plugin = cls; struct PrettyPrinterContext *ppc; @@ -2769,40 +2783,40 @@ tcp_plugin_address_pretty_printer(void *cls, uint32_t options; if (sizeof(struct IPv6TcpAddress) == addrlen) - { - t6 = addr; - memset(&a6, 0, sizeof(a6)); - a6.sin6_family = AF_INET6; - a6.sin6_port = t6->t6_port; - GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); - port = ntohs(t6->t6_port); - options = ntohl(t6->options); - sb = &a6; - sbs = sizeof(a6); - } + { + t6 = addr; + memset (&a6, 0, sizeof(a6)); + a6.sin6_family = AF_INET6; + a6.sin6_port = t6->t6_port; + GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); + port = ntohs (t6->t6_port); + options = ntohl (t6->options); + sb = &a6; + sbs = sizeof(a6); + } else if (sizeof(struct IPv4TcpAddress) == addrlen) - { - t4 = addr; - memset(&a4, 0, sizeof(a4)); - a4.sin_family = AF_INET; - a4.sin_port = t4->t4_port; - a4.sin_addr.s_addr = t4->ipv4_addr; - port = ntohs(t4->t4_port); - options = ntohl(t4->options); - sb = &a4; - sbs = sizeof(a4); - } + { + t4 = addr; + memset (&a4, 0, sizeof(a4)); + a4.sin_family = AF_INET; + a4.sin_port = t4->t4_port; + a4.sin_addr.s_addr = t4->ipv4_addr; + port = ntohs (t4->t4_port); + options = ntohl (t4->options); + sb = &a4; + sbs = sizeof(a4); + } else - { - /* invalid address */ - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Unexpected address length: %u bytes\n"), - (unsigned int)addrlen); - asc(asc_cls, NULL, GNUNET_SYSERR); - asc(asc_cls, NULL, GNUNET_OK); - return; - } - ppc = GNUNET_new(struct PrettyPrinterContext); + { + /* invalid address */ + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("Unexpected address length: %u bytes\n"), + (unsigned int) addrlen); + asc (asc_cls, NULL, GNUNET_SYSERR); + asc (asc_cls, NULL, GNUNET_OK); + return; + } + ppc = GNUNET_new (struct PrettyPrinterContext); ppc->plugin = plugin; if (addrlen == sizeof(struct IPv6TcpAddress)) ppc->ipv6 = GNUNET_YES; @@ -2812,20 +2826,20 @@ tcp_plugin_address_pretty_printer(void *cls, ppc->asc_cls = asc_cls; ppc->port = port; ppc->options = options; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n"); - ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sb, - sbs, - !numeric, - timeout, - &append_port, - ppc); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n"); + ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, + sbs, + ! numeric, + timeout, + &append_port, + ppc); if (NULL == ppc->resolver_handle) - { - GNUNET_break(0); - GNUNET_free(ppc); - return; - } - GNUNET_CONTAINER_DLL_insert(plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); + { + GNUNET_break (0); + GNUNET_free (ppc); + return; + } + GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); } @@ -2845,7 +2859,7 @@ tcp_plugin_address_pretty_printer(void *cls, * and transport, #GNUNET_SYSERR if not */ static int -tcp_plugin_check_address(void *cls, const void *addr, size_t addrlen) +tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) { struct Plugin *plugin = cls; const struct IPv4TcpAddress *v4; @@ -2853,61 +2867,61 @@ tcp_plugin_check_address(void *cls, const void *addr, size_t addrlen) if ((addrlen != sizeof(struct IPv4TcpAddress)) && (addrlen != sizeof(struct IPv6TcpAddress))) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } if (addrlen == sizeof(struct IPv4TcpAddress)) - { - struct sockaddr_in s4; + { + struct sockaddr_in s4; - v4 = (const struct IPv4TcpAddress *)addr; - if (0 != memcmp(&v4->options, &plugin->myoptions, sizeof(uint32_t))) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - memset(&s4, 0, sizeof(s4)); - s4.sin_family = AF_INET; + v4 = (const struct IPv4TcpAddress *) addr; + if (0 != memcmp (&v4->options, &plugin->myoptions, sizeof(uint32_t))) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + memset (&s4, 0, sizeof(s4)); + s4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - s4.sin_len = sizeof(s4); + s4.sin_len = sizeof(s4); #endif - s4.sin_port = v4->t4_port; - s4.sin_addr.s_addr = v4->ipv4_addr; + s4.sin_port = v4->t4_port; + s4.sin_addr.s_addr = v4->ipv4_addr; - if (GNUNET_OK != - GNUNET_NAT_test_address(plugin->nat, &s4, sizeof(struct sockaddr_in))) - return GNUNET_SYSERR; - } + if (GNUNET_OK != + GNUNET_NAT_test_address (plugin->nat, &s4, sizeof(struct sockaddr_in))) + return GNUNET_SYSERR; + } else - { - struct sockaddr_in6 s6; + { + struct sockaddr_in6 s6; - v6 = (const struct IPv6TcpAddress *)addr; - if (IN6_IS_ADDR_LINKLOCAL(&v6->ipv6_addr)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - if (0 != memcmp(&v6->options, &plugin->myoptions, sizeof(uint32_t))) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - memset(&s6, 0, sizeof(s6)); - s6.sin6_family = AF_INET6; + v6 = (const struct IPv6TcpAddress *) addr; + if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + if (0 != memcmp (&v6->options, &plugin->myoptions, sizeof(uint32_t))) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + memset (&s6, 0, sizeof(s6)); + s6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN - s6.sin6_len = sizeof(s6); + s6.sin6_len = sizeof(s6); #endif - s6.sin6_port = v6->t6_port; - s6.sin6_addr = v6->ipv6_addr; + s6.sin6_port = v6->t6_port; + s6.sin6_addr = v6->ipv6_addr; - if (GNUNET_OK != GNUNET_NAT_test_address(plugin->nat, - &s6, - sizeof(struct sockaddr_in6))) - return GNUNET_SYSERR; - } + if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat, + &s6, + sizeof(struct sockaddr_in6))) + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -2922,9 +2936,9 @@ tcp_plugin_check_address(void *cls, const void *addr, size_t addrlen) * @param message the actual message */ static void -handle_tcp_nat_probe(void *cls, - struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) +handle_tcp_nat_probe (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session; @@ -2936,115 +2950,115 @@ handle_tcp_nat_probe(void *cls, const struct sockaddr_in *s4; const struct sockaddr_in6 *s6; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n"); /* We have received a TCP NAT probe, meaning we (hopefully) initiated * a connection to this peer by running gnunet-nat-client. This peer * received the punch message and now wants us to use the new connection * as the default for that peer. Do so and then send a WELCOME message * so we can really be connected! */ - if (ntohs(message->size) != sizeof(struct TCP_NAT_ProbeMessage)) - { - GNUNET_break_op(0); - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - return; - } + if (ntohs (message->size) != sizeof(struct TCP_NAT_ProbeMessage)) + { + GNUNET_break_op (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } - tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *)message; - if (0 == memcmp(&tcp_nat_probe->clientIdentity, - plugin->env->my_identity, - sizeof(struct GNUNET_PeerIdentity))) - { - /* refuse connections from ourselves */ - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - return; - } + tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; + if (0 == memcmp (&tcp_nat_probe->clientIdentity, + plugin->env->my_identity, + sizeof(struct GNUNET_PeerIdentity))) + { + /* refuse connections from ourselves */ + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } - session = GNUNET_CONTAINER_multipeermap_get(plugin->nat_wait_conns, - &tcp_nat_probe->clientIdentity); + session = GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns, + &tcp_nat_probe->clientIdentity); if (NULL == session) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); - GNUNET_SERVER_receive_done(client, GNUNET_OK); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); + GNUNET_SERVER_receive_done (client, GNUNET_OK); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); if (NULL != session->nat_connection_timeout) - { - GNUNET_SCHEDULER_cancel(session->nat_connection_timeout); - session->nat_connection_timeout = NULL; - } + { + GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); + session->nat_connection_timeout = NULL; + } - if (GNUNET_OK != GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) - { - GNUNET_break(0); - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - tcp_plugin_disconnect_session(plugin, session); - return; - } - GNUNET_assert( + if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + tcp_plugin_disconnect_session (plugin, session); + return; + } + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(plugin->nat_wait_conns, - &tcp_nat_probe->clientIdentity, - session)); - GNUNET_SERVER_client_set_user_context(client, session); - (void)GNUNET_CONTAINER_multipeermap_put( + GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, + &tcp_nat_probe->clientIdentity, + session)); + GNUNET_SERVER_client_set_user_context (client, session); + (void) GNUNET_CONTAINER_multipeermap_put ( plugin->sessionmap, &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - session->last_activity = GNUNET_TIME_absolute_get(); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found address `%s' for incoming connection\n", - GNUNET_a2s(vaddr, alen)); - switch (((const struct sockaddr *)vaddr)->sa_family) - { - case AF_INET: - s4 = vaddr; - t4 = GNUNET_new(struct IPv4TcpAddress); - t4->options = htonl(TCP_OPTIONS_NONE); - t4->t4_port = s4->sin_port; - t4->ipv4_addr = s4->sin_addr.s_addr; - session->address = - GNUNET_HELLO_address_allocate(&tcp_nat_probe->clientIdentity, - PLUGIN_NAME, - &t4, - sizeof(struct IPv4TcpAddress), - GNUNET_HELLO_ADDRESS_INFO_NONE); - break; - - case AF_INET6: - s6 = vaddr; - t6 = GNUNET_new(struct IPv6TcpAddress); - t6->options = htonl(TCP_OPTIONS_NONE); - t6->t6_port = s6->sin6_port; - GNUNET_memcpy(&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); - session->address = - GNUNET_HELLO_address_allocate(&tcp_nat_probe->clientIdentity, - PLUGIN_NAME, - &t6, - sizeof(struct IPv6TcpAddress), - GNUNET_HELLO_ADDRESS_INFO_NONE); - break; - - default: - GNUNET_break_op(0); - LOG(GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n"); - GNUNET_free(vaddr); - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - tcp_plugin_disconnect_session(plugin, session); - return; - } - GNUNET_free(vaddr); - GNUNET_break(NULL == session->client); + session->last_activity = GNUNET_TIME_absolute_get (); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found address `%s' for incoming connection\n", + GNUNET_a2s (vaddr, alen)); + switch (((const struct sockaddr *) vaddr)->sa_family) + { + case AF_INET: + s4 = vaddr; + t4 = GNUNET_new (struct IPv4TcpAddress); + t4->options = htonl (TCP_OPTIONS_NONE); + t4->t4_port = s4->sin_port; + t4->ipv4_addr = s4->sin_addr.s_addr; + session->address = + GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, + PLUGIN_NAME, + &t4, + sizeof(struct IPv4TcpAddress), + GNUNET_HELLO_ADDRESS_INFO_NONE); + break; + + case AF_INET6: + s6 = vaddr; + t6 = GNUNET_new (struct IPv6TcpAddress); + t6->options = htonl (TCP_OPTIONS_NONE); + t6->t6_port = s6->sin6_port; + GNUNET_memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); + session->address = + GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, + PLUGIN_NAME, + &t6, + sizeof(struct IPv6TcpAddress), + GNUNET_HELLO_ADDRESS_INFO_NONE); + break; + + default: + GNUNET_break_op (0); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n"); + GNUNET_free (vaddr); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + tcp_plugin_disconnect_session (plugin, session); + return; + } + GNUNET_free (vaddr); + GNUNET_break (NULL == session->client); session->client = client; - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# TCP sessions active"), - 1, - GNUNET_NO); - process_pending_messages(session); - GNUNET_SERVER_receive_done(client, GNUNET_OK); + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# TCP sessions active"), + 1, + GNUNET_NO); + process_pending_messages (session); + GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -3057,12 +3071,12 @@ handle_tcp_nat_probe(void *cls, * @param message the actual message */ static void -handle_tcp_welcome(void *cls, - struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) +handle_tcp_welcome (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) { struct Plugin *plugin = cls; - const struct WelcomeMessage *wm = (const struct WelcomeMessage *)message; + const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message; struct GNUNET_HELLO_Address *address; struct GNUNET_ATS_Session *session; size_t alen; @@ -3072,141 +3086,141 @@ handle_tcp_welcome(void *cls, const struct sockaddr_in *s4; const struct sockaddr_in6 *s6; - if (0 == memcmp(&wm->clientIdentity, - plugin->env->my_identity, - sizeof(struct GNUNET_PeerIdentity))) + if (0 == memcmp (&wm->clientIdentity, + plugin->env->my_identity, + sizeof(struct GNUNET_PeerIdentity))) + { + /* refuse connections from ourselves */ + if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) { - /* refuse connections from ourselves */ - if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) - { - LOG(GNUNET_ERROR_TYPE_INFO, - "Received WELCOME message from my own identity `%s' on address `%s'\n", - GNUNET_i2s(&wm->clientIdentity), - GNUNET_a2s(vaddr, alen)); - GNUNET_free(vaddr); - } - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - return; + LOG (GNUNET_ERROR_TYPE_INFO, + "Received WELCOME message from my own identity `%s' on address `%s'\n", + GNUNET_i2s (&wm->clientIdentity), + GNUNET_a2s (vaddr, alen)); + GNUNET_free (vaddr); } + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } - if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received WELCOME message from `%s' on address `%s'\n", - GNUNET_i2s(&wm->clientIdentity), - GNUNET_a2s(vaddr, alen)); - GNUNET_free(vaddr); - } - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# TCP WELCOME messages received"), - 1, - GNUNET_NO); - session = lookup_session_by_client(plugin, client); + if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received WELCOME message from `%s' on address `%s'\n", + GNUNET_i2s (&wm->clientIdentity), + GNUNET_a2s (vaddr, alen)); + GNUNET_free (vaddr); + } + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# TCP WELCOME messages received"), + 1, + GNUNET_NO); + session = lookup_session_by_client (plugin, client); if (NULL != session) + { + if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) { - if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found existing session %p for peer `%s'\n", - session, - GNUNET_a2s(vaddr, alen)); - GNUNET_free(vaddr); - } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found existing session %p for peer `%s'\n", + session, + GNUNET_a2s (vaddr, alen)); + GNUNET_free (vaddr); } + } else - { - if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) - { - if (alen == sizeof(struct sockaddr_in)) - { - s4 = vaddr; - memset(&t4, '\0', sizeof(t4)); - t4.options = htonl(TCP_OPTIONS_NONE); - t4.t4_port = s4->sin_port; - t4.ipv4_addr = s4->sin_addr.s_addr; - address = - GNUNET_HELLO_address_allocate(&wm->clientIdentity, - PLUGIN_NAME, - &t4, - sizeof(t4), - GNUNET_HELLO_ADDRESS_INFO_INBOUND); - } - else if (alen == sizeof(struct sockaddr_in6)) - { - s6 = vaddr; - memset(&t6, '\0', sizeof(t6)); - t6.options = htonl(TCP_OPTIONS_NONE); - t6.t6_port = s6->sin6_port; - GNUNET_memcpy(&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); - address = - GNUNET_HELLO_address_allocate(&wm->clientIdentity, - PLUGIN_NAME, - &t6, - sizeof(t6), - GNUNET_HELLO_ADDRESS_INFO_INBOUND); - } - else - { - GNUNET_break(0); - GNUNET_free_non_null(vaddr); - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - return; - } - session = create_session(plugin, - address, - plugin->env->get_address_type(plugin->env->cls, - vaddr, - alen), - client, - GNUNET_NO); - GNUNET_break(GNUNET_NT_UNSPECIFIED != session->scope); - GNUNET_HELLO_address_free(address); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Creating new%s session %p for peer `%s' client %p\n", - GNUNET_HELLO_address_check_option(session->address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND) - ? " inbound" - : "", - session, - tcp_plugin_address_to_string(plugin, - session->address->address, - session->address->address_length), - client); - GNUNET_free(vaddr); - (void)GNUNET_CONTAINER_multipeermap_put( - plugin->sessionmap, - &session->target, - session, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - /* Notify transport and ATS about new session */ - plugin->env->session_start(plugin->env->cls, - session->address, - session, - session->scope); - } + { + if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) + { + if (alen == sizeof(struct sockaddr_in)) + { + s4 = vaddr; + memset (&t4, '\0', sizeof(t4)); + t4.options = htonl (TCP_OPTIONS_NONE); + t4.t4_port = s4->sin_port; + t4.ipv4_addr = s4->sin_addr.s_addr; + address = + GNUNET_HELLO_address_allocate (&wm->clientIdentity, + PLUGIN_NAME, + &t4, + sizeof(t4), + GNUNET_HELLO_ADDRESS_INFO_INBOUND); + } + else if (alen == sizeof(struct sockaddr_in6)) + { + s6 = vaddr; + memset (&t6, '\0', sizeof(t6)); + t6.options = htonl (TCP_OPTIONS_NONE); + t6.t6_port = s6->sin6_port; + GNUNET_memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); + address = + GNUNET_HELLO_address_allocate (&wm->clientIdentity, + PLUGIN_NAME, + &t6, + sizeof(t6), + GNUNET_HELLO_ADDRESS_INFO_INBOUND); + } else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Did not obtain TCP socket address for incoming connection\n"); - GNUNET_break(0); - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - return; - } + { + GNUNET_break (0); + GNUNET_free_non_null (vaddr); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + session = create_session (plugin, + address, + plugin->env->get_address_type (plugin->env->cls, + vaddr, + alen), + client, + GNUNET_NO); + GNUNET_break (GNUNET_NT_UNSPECIFIED != session->scope); + GNUNET_HELLO_address_free (address); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Creating new%s session %p for peer `%s' client %p\n", + GNUNET_HELLO_address_check_option (session->address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND) + ? " inbound" + : "", + session, + tcp_plugin_address_to_string (plugin, + session->address->address, + session->address->address_length), + client); + GNUNET_free (vaddr); + (void) GNUNET_CONTAINER_multipeermap_put ( + plugin->sessionmap, + &session->target, + session, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + /* Notify transport and ATS about new session */ + plugin->env->session_start (plugin->env->cls, + session->address, + session, + session->scope); + } + else + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Did not obtain TCP socket address for incoming connection\n"); + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; } + } if (GNUNET_YES != session->expecting_welcome) - { - GNUNET_break_op(0); - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - return; - } - session->last_activity = GNUNET_TIME_absolute_get(); + { + GNUNET_break_op (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + session->last_activity = GNUNET_TIME_absolute_get (); session->expecting_welcome = GNUNET_NO; - process_pending_messages(session); - GNUNET_SERVER_client_set_timeout(client, - GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); - GNUNET_SERVER_receive_done(client, GNUNET_OK); + process_pending_messages (session); + GNUNET_SERVER_client_set_timeout (client, + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -3219,102 +3233,102 @@ handle_tcp_welcome(void *cls, * @param message the actual message */ static void -handle_tcp_data(void *cls, - struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) +handle_tcp_data (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session; struct GNUNET_TIME_Relative delay; uint16_t type; - type = ntohs(message->type); + type = ntohs (message->type); if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) - { - /* We don't want to propagate WELCOME and NAT Probe messages up! */ - GNUNET_SERVER_receive_done(client, GNUNET_OK); - return; - } - session = lookup_session_by_client(plugin, client); + { + /* We don't want to propagate WELCOME and NAT Probe messages up! */ + GNUNET_SERVER_receive_done (client, GNUNET_OK); + return; + } + session = lookup_session_by_client (plugin, client); if (NULL == session) - { - /* No inbound session found */ - void *vaddr = NULL; - size_t alen; - - GNUNET_assert(GNUNET_OK == - GNUNET_SERVER_client_get_address(client, &vaddr, &alen)); - LOG(GNUNET_ERROR_TYPE_ERROR, - "Received unexpected %u bytes of type %u from `%s'\n", - (unsigned int)ntohs(message->size), - (unsigned int)ntohs(message->type), - GNUNET_a2s(vaddr, alen)); - GNUNET_break_op(0); - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - GNUNET_free_non_null(vaddr); - return; - } + { + /* No inbound session found */ + void *vaddr = NULL; + size_t alen; + + GNUNET_assert (GNUNET_OK == + GNUNET_SERVER_client_get_address (client, &vaddr, &alen)); + LOG (GNUNET_ERROR_TYPE_ERROR, + "Received unexpected %u bytes of type %u from `%s'\n", + (unsigned int) ntohs (message->size), + (unsigned int) ntohs (message->type), + GNUNET_a2s (vaddr, alen)); + GNUNET_break_op (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + GNUNET_free_non_null (vaddr); + return; + } if (GNUNET_YES == session->expecting_welcome) - { - /* Session is expecting WELCOME message */ - void *vaddr = NULL; - size_t alen; - - GNUNET_SERVER_client_get_address(client, &vaddr, &alen); - LOG(GNUNET_ERROR_TYPE_ERROR, - "Received unexpected %u bytes of type %u from `%s'\n", - (unsigned int)ntohs(message->size), - (unsigned int)ntohs(message->type), - GNUNET_a2s(vaddr, alen)); - GNUNET_break_op(0); - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - GNUNET_free_non_null(vaddr); - return; - } + { + /* Session is expecting WELCOME message */ + void *vaddr = NULL; + size_t alen; - session->last_activity = GNUNET_TIME_absolute_get(); + GNUNET_SERVER_client_get_address (client, &vaddr, &alen); + LOG (GNUNET_ERROR_TYPE_ERROR, + "Received unexpected %u bytes of type %u from `%s'\n", + (unsigned int) ntohs (message->size), + (unsigned int) ntohs (message->type), + GNUNET_a2s (vaddr, alen)); + GNUNET_break_op (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + GNUNET_free_non_null (vaddr); + return; + } + + session->last_activity = GNUNET_TIME_absolute_get (); { void *vaddr = NULL; size_t alen; - GNUNET_SERVER_client_get_address(client, &vaddr, &alen); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Passing %u bytes of type %u from `%s' at %s to transport service.\n", - (unsigned int)ntohs(message->size), - (unsigned int)ntohs(message->type), - GNUNET_i2s(&session->target), - GNUNET_a2s(vaddr, alen)); - GNUNET_free_non_null(vaddr); - } - - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# bytes received via TCP"), - ntohs(message->size), - GNUNET_NO); - - GNUNET_assert( - GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessionmap, - &session->target, - session)); + GNUNET_SERVER_client_get_address (client, &vaddr, &alen); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Passing %u bytes of type %u from `%s' at %s to transport service.\n", + (unsigned int) ntohs (message->size), + (unsigned int) ntohs (message->type), + GNUNET_i2s (&session->target), + GNUNET_a2s (vaddr, alen)); + GNUNET_free_non_null (vaddr); + } + + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# bytes received via TCP"), + ntohs (message->size), + GNUNET_NO); + + GNUNET_assert ( + GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, + &session->target, + session)); delay = - plugin->env->receive(plugin->env->cls, session->address, session, message); - reschedule_session_timeout(session); + plugin->env->receive (plugin->env->cls, session->address, session, message); + reschedule_session_timeout (session); if (0 == delay.rel_value_us) - { - GNUNET_SERVER_receive_done(client, GNUNET_OK); - } + { + GNUNET_SERVER_receive_done (client, GNUNET_OK); + } else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Throttling receiving from `%s' for %s\n", - GNUNET_i2s(&session->target), - GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); - GNUNET_SERVER_disable_receive_done_warning(client); - GNUNET_assert(NULL == session->receive_delay_task); - session->receive_delay_task = - GNUNET_SCHEDULER_add_delayed(delay, &delayed_done, session); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Throttling receiving from `%s' for %s\n", + GNUNET_i2s (&session->target), + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); + GNUNET_SERVER_disable_receive_done_warning (client); + GNUNET_assert (NULL == session->receive_delay_task); + session->receive_delay_task = + GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); + } } @@ -3327,30 +3341,30 @@ handle_tcp_data(void *cls, * @param client identification of the client */ static void -connect_notify(void *cls, struct GNUNET_SERVER_Client *client) +connect_notify (void *cls, struct GNUNET_SERVER_Client *client) { struct Plugin *plugin = cls; if (NULL == client) return; plugin->cur_connections++; - GNUNET_STATISTICS_set(plugin->env->stats, - gettext_noop("# TCP server connections active"), - plugin->cur_connections, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# TCP server connect events"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, + gettext_noop ("# TCP server connections active"), + plugin->cur_connections, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# TCP server connect events"), + 1, + GNUNET_NO); if (plugin->cur_connections != plugin->max_connections) return; - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - _("TCP connection limit reached, suspending server\n")); - GNUNET_STATISTICS_update(plugin->env->stats, - gettext_noop("# TCP service suspended"), - 1, - GNUNET_NO); - GNUNET_SERVER_suspend( + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _ ("TCP connection limit reached, suspending server\n")); + GNUNET_STATISTICS_update (plugin->env->stats, + gettext_noop ("# TCP service suspended"), + 1, + GNUNET_NO); + GNUNET_SERVER_suspend ( plugin->server); /* Maximum number of connections rechead */ } @@ -3364,43 +3378,43 @@ connect_notify(void *cls, struct GNUNET_SERVER_Client *client) * @param client identification of the client */ static void -disconnect_notify(void *cls, struct GNUNET_SERVER_Client *client) +disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session; if (NULL == client) return; - GNUNET_assert(plugin->cur_connections >= 1); + GNUNET_assert (plugin->cur_connections >= 1); plugin->cur_connections--; - session = lookup_session_by_client(plugin, client); + session = lookup_session_by_client (plugin, client); if (NULL == session) return; /* unknown, nothing to do */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Destroying session of `%s' with %s due to network-level disconnect.\n", - GNUNET_i2s(&session->target), - tcp_plugin_address_to_string(session->plugin, - session->address->address, - session->address->address_length)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Destroying session of `%s' with %s due to network-level disconnect.\n", + GNUNET_i2s (&session->target), + tcp_plugin_address_to_string (session->plugin, + session->address->address, + session->address->address_length)); if (plugin->cur_connections == plugin->max_connections) - { - GNUNET_STATISTICS_update(session->plugin->env->stats, - gettext_noop("# TCP service resumed"), - 1, - GNUNET_NO); - GNUNET_SERVER_resume(plugin->server); /* Resume server */ - } - GNUNET_STATISTICS_set(plugin->env->stats, - gettext_noop("# TCP server connections active"), - plugin->cur_connections, - GNUNET_NO); - GNUNET_STATISTICS_update(session->plugin->env->stats, - gettext_noop( - "# network-level TCP disconnect events"), - 1, - GNUNET_NO); - tcp_plugin_disconnect_session(plugin, session); + { + GNUNET_STATISTICS_update (session->plugin->env->stats, + gettext_noop ("# TCP service resumed"), + 1, + GNUNET_NO); + GNUNET_SERVER_resume (plugin->server); /* Resume server */ + } + GNUNET_STATISTICS_set (plugin->env->stats, + gettext_noop ("# TCP server connections active"), + plugin->cur_connections, + GNUNET_NO); + GNUNET_STATISTICS_update (session->plugin->env->stats, + gettext_noop ( + "# network-level TCP disconnect events"), + 1, + GNUNET_NO); + tcp_plugin_disconnect_session (plugin, session); } @@ -3413,28 +3427,28 @@ disconnect_notify(void *cls, struct GNUNET_SERVER_Client *client) * @return number of bytes copied into @a buf */ static size_t -notify_send_probe(void *cls, size_t size, void *buf) +notify_send_probe (void *cls, size_t size, void *buf) { struct TCPProbeContext *tcp_probe_ctx = cls; struct Plugin *plugin = tcp_probe_ctx->plugin; size_t ret; tcp_probe_ctx->transmit_handle = NULL; - GNUNET_CONTAINER_DLL_remove(plugin->probe_head, - plugin->probe_tail, - tcp_probe_ctx); + GNUNET_CONTAINER_DLL_remove (plugin->probe_head, + plugin->probe_tail, + tcp_probe_ctx); if (NULL == buf) - { - GNUNET_CONNECTION_destroy(tcp_probe_ctx->sock); - GNUNET_free(tcp_probe_ctx); - return 0; - } - GNUNET_assert(size >= sizeof(tcp_probe_ctx->message)); - GNUNET_memcpy(buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message)); - GNUNET_SERVER_connect_socket(tcp_probe_ctx->plugin->server, - tcp_probe_ctx->sock); + { + GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock); + GNUNET_free (tcp_probe_ctx); + return 0; + } + GNUNET_assert (size >= sizeof(tcp_probe_ctx->message)); + GNUNET_memcpy (buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message)); + GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server, + tcp_probe_ctx->sock); ret = sizeof(tcp_probe_ctx->message); - GNUNET_free(tcp_probe_ctx); + GNUNET_free (tcp_probe_ctx); return ret; } @@ -3449,9 +3463,9 @@ notify_send_probe(void *cls, size_t size, void *buf) * @param addrlen number of bytes in @a addr */ static void -try_connection_reversal(void *cls, - const struct sockaddr *addr, - socklen_t addrlen) +try_connection_reversal (void *cls, + const struct sockaddr *addr, + socklen_t addrlen) { struct Plugin *plugin = cls; struct GNUNET_CONNECTION_Handle *sock; @@ -3461,31 +3475,31 @@ try_connection_reversal(void *cls, * We have received an ICMP response, ostensibly from a peer * that wants to connect to us! Send a message to establish a connection. */ - sock = GNUNET_CONNECTION_create_from_sockaddr(AF_INET, addr, addrlen); + sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen); if (NULL == sock) - { - /* failed for some odd reason (out of sockets?); ignore attempt */ - return; - } + { + /* failed for some odd reason (out of sockets?); ignore attempt */ + return; + } - tcp_probe_ctx = GNUNET_new(struct TCPProbeContext); + tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); tcp_probe_ctx->message.header.size = - htons(sizeof(struct TCP_NAT_ProbeMessage)); + htons (sizeof(struct TCP_NAT_ProbeMessage)); tcp_probe_ctx->message.header.type = - htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); + htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); tcp_probe_ctx->message.clientIdentity = *plugin->env->my_identity; tcp_probe_ctx->plugin = plugin; tcp_probe_ctx->sock = sock; - GNUNET_CONTAINER_DLL_insert(plugin->probe_head, - plugin->probe_tail, - tcp_probe_ctx); + GNUNET_CONTAINER_DLL_insert (plugin->probe_head, + plugin->probe_tail, + tcp_probe_ctx); tcp_probe_ctx->transmit_handle = - GNUNET_CONNECTION_notify_transmit_ready(sock, - ntohs(tcp_probe_ctx->message - .header.size), - GNUNET_TIME_UNIT_FOREVER_REL, - ¬ify_send_probe, - tcp_probe_ctx); + GNUNET_CONNECTION_notify_transmit_ready (sock, + ntohs (tcp_probe_ctx->message + .header.size), + GNUNET_TIME_UNIT_FOREVER_REL, + ¬ify_send_probe, + tcp_probe_ctx); } @@ -3497,7 +3511,7 @@ try_connection_reversal(void *cls, * @return the network type in HBO or #GNUNET_SYSERR */ static enum GNUNET_NetworkType -tcp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) +tcp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) { return session->scope; } @@ -3511,8 +3525,8 @@ tcp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) * @return the network type */ static enum GNUNET_NetworkType -tcp_plugin_get_network_for_address(void *cls, - const struct GNUNET_HELLO_Address *address) +tcp_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) { struct Plugin *plugin = cls; size_t addrlen; @@ -3525,39 +3539,39 @@ tcp_plugin_get_network_for_address(void *cls, addrlen = address->address_length; if (addrlen == sizeof(struct IPv6TcpAddress)) - { - GNUNET_assert(NULL != address->address); /* make static analysis happy */ - t6 = address->address; - memset(&a6, 0, sizeof(a6)); + { + GNUNET_assert (NULL != address->address); /* make static analysis happy */ + t6 = address->address; + memset (&a6, 0, sizeof(a6)); #if HAVE_SOCKADDR_IN_SIN_LEN - a6.sin6_len = sizeof(a6); + a6.sin6_len = sizeof(a6); #endif - a6.sin6_family = AF_INET6; - a6.sin6_port = t6->t6_port; - GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); - sb = &a6; - sbs = sizeof(a6); - } + a6.sin6_family = AF_INET6; + a6.sin6_port = t6->t6_port; + GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); + sb = &a6; + sbs = sizeof(a6); + } else if (addrlen == sizeof(struct IPv4TcpAddress)) - { - GNUNET_assert(NULL != address->address); /* make static analysis happy */ - t4 = address->address; - memset(&a4, 0, sizeof(a4)); + { + GNUNET_assert (NULL != address->address); /* make static analysis happy */ + t4 = address->address; + memset (&a4, 0, sizeof(a4)); #if HAVE_SOCKADDR_IN_SIN_LEN - a4.sin_len = sizeof(a4); + a4.sin_len = sizeof(a4); #endif - a4.sin_family = AF_INET; - a4.sin_port = t4->t4_port; - a4.sin_addr.s_addr = t4->ipv4_addr; - sb = &a4; - sbs = sizeof(a4); - } + a4.sin_family = AF_INET; + a4.sin_port = t4->t4_port; + a4.sin_addr.s_addr = t4->ipv4_addr; + sb = &a4; + sbs = sizeof(a4); + } else - { - GNUNET_break(0); - return GNUNET_NT_UNSPECIFIED; - } - return plugin->env->get_address_type(plugin->env->cls, sb, sbs); + { + GNUNET_break (0); + return GNUNET_NT_UNSPECIFIED; + } + return plugin->env->get_address_type (plugin->env->cls, sb, sbs); } @@ -3571,17 +3585,17 @@ tcp_plugin_get_network_for_address(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -send_session_info_iter(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +send_session_info_iter (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session = value; - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); /* FIXME: cannot tell if this is up or not from current session state... */ - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); return GNUNET_OK; } @@ -3599,22 +3613,22 @@ send_session_info_iter(void *cls, * @param sic_cls closure for @a sic */ static void -tcp_plugin_setup_monitor(void *cls, - GNUNET_TRANSPORT_SessionInfoCallback sic, - void *sic_cls) +tcp_plugin_setup_monitor (void *cls, + GNUNET_TRANSPORT_SessionInfoCallback sic, + void *sic_cls) { struct Plugin *plugin = cls; plugin->sic = sic; plugin->sic_cls = sic_cls; if (NULL != sic) - { - GNUNET_CONTAINER_multipeermap_iterate(plugin->sessionmap, - &send_session_info_iter, - plugin); - /* signal end of first iteration */ - sic(sic_cls, NULL, NULL); - } + { + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, + &send_session_info_iter, + plugin); + /* signal end of first iteration */ + sic (sic_cls, NULL, NULL); + } } @@ -3625,7 +3639,7 @@ tcp_plugin_setup_monitor(void *cls, * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error */ void * -libgnunet_plugin_transport_tcp_init(void *cls) +libgnunet_plugin_transport_tcp_init (void *cls) { static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { { &handle_tcp_welcome, @@ -3633,9 +3647,9 @@ libgnunet_plugin_transport_tcp_init(void *cls) GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, sizeof(struct WelcomeMessage) }, { &handle_tcp_nat_probe, - NULL, - GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, - sizeof(struct TCP_NAT_ProbeMessage) }, + NULL, + GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, + sizeof(struct TCP_NAT_ProbeMessage) }, { &handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0 }, { NULL, NULL, 0, 0 } }; struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; @@ -3657,152 +3671,152 @@ libgnunet_plugin_transport_tcp_init(void *cls) socklen_t *addrlens; if (NULL == env->receive) - { - /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully - initialze the plugin or the API */ - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); - api->cls = NULL; - api->address_pretty_printer = &tcp_plugin_address_pretty_printer; - api->address_to_string = &tcp_plugin_address_to_string; - api->string_to_address = &tcp_plugin_string_to_address; - return api; - } + { + /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully + initialze the plugin or the API */ + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); + api->cls = NULL; + api->address_pretty_printer = &tcp_plugin_address_pretty_printer; + api->address_to_string = &tcp_plugin_address_to_string; + api->string_to_address = &tcp_plugin_string_to_address; + return api; + } - GNUNET_assert(NULL != env->cfg); - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, - "transport-tcp", - "MAX_CONNECTIONS", - &max_connections)) + GNUNET_assert (NULL != env->cfg); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, + "transport-tcp", + "MAX_CONNECTIONS", + &max_connections)) max_connections = 128; aport = 0; - if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, - "transport-tcp", - "PORT", - &bport)) || - (bport > 65535) || - ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(env->cfg, + if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", - "ADVERTISED-PORT", - &aport)) && + "PORT", + &bport)) || + (bport > 65535) || + ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (env->cfg, + "transport-tcp", + "ADVERTISED-PORT", + &aport)) && (aport > 65535))) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Require valid port number for service `%s' in configuration!\n"), - "transport-tcp"); - return NULL; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Require valid port number for service `%s' in configuration!\n"), + "transport-tcp"); + return NULL; + } if (0 == aport) aport = bport; if (0 == bport) aport = 0; if (0 != bport) + { + service = LEGACY_SERVICE_start ("transport-tcp", + env->cfg, + LEGACY_SERVICE_OPTION_NONE); + if (NULL == service) { - service = LEGACY_SERVICE_start("transport-tcp", - env->cfg, - LEGACY_SERVICE_OPTION_NONE); - if (NULL == service) - { - LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to start service.\n")); - return NULL; - } + LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to start service.\n")); + return NULL; } + } else service = NULL; api = NULL; - plugin = GNUNET_new(struct Plugin); + plugin = GNUNET_new (struct Plugin); plugin->sessionmap = - GNUNET_CONTAINER_multipeermap_create(max_connections, GNUNET_YES); + GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); plugin->max_connections = max_connections; plugin->open_port = bport; plugin->adv_port = aport; plugin->env = env; - plugin->my_welcome.header.size = htons(sizeof(struct WelcomeMessage)); + plugin->my_welcome.header.size = htons (sizeof(struct WelcomeMessage)); plugin->my_welcome.header.type = - htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); + htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); plugin->my_welcome.clientIdentity = *plugin->env->my_identity; if ((NULL != service) && - (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, - "transport-tcp", - "TCP_STEALTH"))) - { + (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg, + "transport-tcp", + "TCP_STEALTH"))) + { #ifdef TCP_STEALTH - plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH; - lsocks = LEGACY_SERVICE_get_listen_sockets(service); - if (NULL != lsocks) + plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH; + lsocks = LEGACY_SERVICE_get_listen_sockets (service); + if (NULL != lsocks) + { + uint32_t len = sizeof(struct WelcomeMessage); + + for (i = 0; NULL != lsocks[i]; i++) + { + if ( + (GNUNET_OK != + GNUNET_NETWORK_socket_setsockopt (lsocks[i], + IPPROTO_TCP, + TCP_STEALTH, + env->my_identity, + sizeof( + struct GNUNET_PeerIdentity))) || + (GNUNET_OK != + GNUNET_NETWORK_socket_setsockopt (lsocks[i], + IPPROTO_TCP, + TCP_STEALTH_INTEGRITY_LEN, + &len, + sizeof(len)))) { - uint32_t len = sizeof(struct WelcomeMessage); - - for (i = 0; NULL != lsocks[i]; i++) - { - if ( - (GNUNET_OK != - GNUNET_NETWORK_socket_setsockopt(lsocks[i], - IPPROTO_TCP, - TCP_STEALTH, - env->my_identity, - sizeof( - struct GNUNET_PeerIdentity))) || - (GNUNET_OK != - GNUNET_NETWORK_socket_setsockopt(lsocks[i], - IPPROTO_TCP, - TCP_STEALTH_INTEGRITY_LEN, - &len, - sizeof(len)))) - { - /* TCP STEALTH not supported by kernel */ - GNUNET_assert(0 == i); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("TCP_STEALTH not supported on this platform.\n")); - goto die; - } - } + /* TCP STEALTH not supported by kernel */ + GNUNET_assert (0 == i); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("TCP_STEALTH not supported on this platform.\n")); + goto die; } + } + } #else - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("TCP_STEALTH not supported on this platform.\n")); - goto die; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("TCP_STEALTH not supported on this platform.\n")); + goto die; #endif - } + } if ((NULL != service) && (GNUNET_SYSERR != (ret_s = - get_server_addresses("transport-tcp", env->cfg, &addrs, &addrlens)))) - { - for (ret = ret_s - 1; ret >= 0; ret--) - LOG(GNUNET_ERROR_TYPE_INFO, - "Binding to address `%s'\n", - GNUNET_a2s(addrs[ret], addrlens[ret])); - plugin->nat = GNUNET_NAT_register(env->cfg, - "transport-tcp", - IPPROTO_TCP, - (unsigned int)ret_s, - (const struct sockaddr **)addrs, - addrlens, - &tcp_nat_port_map_callback, - &try_connection_reversal, - plugin); - for (ret = ret_s - 1; ret >= 0; ret--) - GNUNET_free(addrs[ret]); - GNUNET_free_non_null(addrs); - GNUNET_free_non_null(addrlens); - } + get_server_addresses ("transport-tcp", env->cfg, &addrs, &addrlens)))) + { + for (ret = ret_s - 1; ret >= 0; ret--) + LOG (GNUNET_ERROR_TYPE_INFO, + "Binding to address `%s'\n", + GNUNET_a2s (addrs[ret], addrlens[ret])); + plugin->nat = GNUNET_NAT_register (env->cfg, + "transport-tcp", + IPPROTO_TCP, + (unsigned int) ret_s, + (const struct sockaddr **) addrs, + addrlens, + &tcp_nat_port_map_callback, + &try_connection_reversal, + plugin); + for (ret = ret_s - 1; ret >= 0; ret--) + GNUNET_free (addrs[ret]); + GNUNET_free_non_null (addrs); + GNUNET_free_non_null (addrlens); + } else - { - plugin->nat = GNUNET_NAT_register(plugin->env->cfg, - "transport-tcp", - IPPROTO_TCP, - 0, - NULL, - NULL, - NULL, - &try_connection_reversal, - plugin); - } - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); + { + plugin->nat = GNUNET_NAT_register (plugin->env->cfg, + "transport-tcp", + IPPROTO_TCP, + 0, + NULL, + NULL, + NULL, + &try_connection_reversal, + plugin); + } + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->send = &tcp_plugin_send; api->get_session = &tcp_plugin_get_session; @@ -3820,65 +3834,65 @@ libgnunet_plugin_transport_tcp_init(void *cls) api->setup_monitor = &tcp_plugin_setup_monitor; plugin->service = service; if (NULL != service) - { - plugin->server = LEGACY_SERVICE_get_server(service); - } + { + plugin->server = LEGACY_SERVICE_get_server (service); + } else + { + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (env->cfg, + "transport-tcp", + "TIMEOUT", + &idle_timeout)) { - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg, - "transport-tcp", - "TIMEOUT", - &idle_timeout)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - "transport-tcp", - "TIMEOUT"); - goto die; - } - plugin->server = GNUNET_SERVER_create_with_sockets(NULL, - plugin, - NULL, - idle_timeout, - GNUNET_YES); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "transport-tcp", + "TIMEOUT"); + goto die; } - plugin->handlers = GNUNET_malloc(sizeof(my_handlers)); - GNUNET_memcpy(plugin->handlers, my_handlers, sizeof(my_handlers)); + plugin->server = GNUNET_SERVER_create_with_sockets (NULL, + plugin, + NULL, + idle_timeout, + GNUNET_YES); + } + plugin->handlers = GNUNET_malloc (sizeof(my_handlers)); + GNUNET_memcpy (plugin->handlers, my_handlers, sizeof(my_handlers)); for (i = 0; i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler); i++) plugin->handlers[i].callback_cls = plugin; - GNUNET_SERVER_add_handlers(plugin->server, plugin->handlers); - GNUNET_SERVER_connect_notify(plugin->server, &connect_notify, plugin); - GNUNET_SERVER_disconnect_notify(plugin->server, &disconnect_notify, plugin); + GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); + GNUNET_SERVER_connect_notify (plugin->server, &connect_notify, plugin); + GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); plugin->nat_wait_conns = - GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); + GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); if (0 != bport) - LOG(GNUNET_ERROR_TYPE_INFO, - _("TCP transport listening on port %llu\n"), - bport); + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("TCP transport listening on port %llu\n"), + bport); else - LOG(GNUNET_ERROR_TYPE_INFO, - _("TCP transport not listening on any port (client only)\n")); + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("TCP transport not listening on any port (client only)\n")); if ((aport != bport) && (0 != bport)) - LOG(GNUNET_ERROR_TYPE_INFO, - _("TCP transport advertises itself as being on port %llu\n"), - aport); + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("TCP transport advertises itself as being on port %llu\n"), + aport); /* Initially set connections to 0 */ - GNUNET_STATISTICS_set(plugin->env->stats, - gettext_noop("# TCP sessions active"), - 0, - GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, + gettext_noop ("# TCP sessions active"), + 0, + GNUNET_NO); return api; die: if (NULL != plugin->nat) - GNUNET_NAT_unregister(plugin->nat); - GNUNET_CONTAINER_multipeermap_destroy(plugin->sessionmap); + GNUNET_NAT_unregister (plugin->nat); + GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); if (NULL != service) - LEGACY_SERVICE_stop(service); - GNUNET_free(plugin); - GNUNET_free_non_null(api); + LEGACY_SERVICE_stop (service); + GNUNET_free (plugin); + GNUNET_free_non_null (api); return NULL; } @@ -3890,7 +3904,7 @@ die: * @return NULL */ void * -libgnunet_plugin_transport_tcp_done(void *cls) +libgnunet_plugin_transport_tcp_done (void *cls) { struct GNUNET_TRANSPORT_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; @@ -3899,52 +3913,52 @@ libgnunet_plugin_transport_tcp_done(void *cls) struct PrettyPrinterContext *next; if (NULL == plugin) - { - GNUNET_free(api); - return NULL; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); + { + GNUNET_free (api); + return NULL; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); /* Removing leftover sessions */ - GNUNET_CONTAINER_multipeermap_iterate(plugin->sessionmap, - &session_disconnect_it, - plugin); + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, + &session_disconnect_it, + plugin); /* Removing leftover NAT sessions */ - GNUNET_CONTAINER_multipeermap_iterate(plugin->nat_wait_conns, - &session_disconnect_it, - plugin); + GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, + &session_disconnect_it, + plugin); for (cur = plugin->ppc_dll_head; NULL != cur; cur = next) - { - next = cur->next; - GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head, - plugin->ppc_dll_tail, - cur); - GNUNET_RESOLVER_request_cancel(cur->resolver_handle); - cur->asc(cur->asc_cls, NULL, GNUNET_OK); - GNUNET_free(cur); - } + { + next = cur->next; + GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, + plugin->ppc_dll_tail, + cur); + GNUNET_RESOLVER_request_cancel (cur->resolver_handle); + cur->asc (cur->asc_cls, NULL, GNUNET_OK); + GNUNET_free (cur); + } if (NULL != plugin->service) - LEGACY_SERVICE_stop(plugin->service); + LEGACY_SERVICE_stop (plugin->service); else - GNUNET_SERVER_destroy(plugin->server); - GNUNET_free(plugin->handlers); + GNUNET_SERVER_destroy (plugin->server); + GNUNET_free (plugin->handlers); if (NULL != plugin->nat) - GNUNET_NAT_unregister(plugin->nat); + GNUNET_NAT_unregister (plugin->nat); while (NULL != (tcp_probe = plugin->probe_head)) - { - GNUNET_CONTAINER_DLL_remove(plugin->probe_head, - plugin->probe_tail, - tcp_probe); - GNUNET_CONNECTION_destroy(tcp_probe->sock); - GNUNET_free(tcp_probe); - } - GNUNET_CONTAINER_multipeermap_destroy(plugin->nat_wait_conns); - GNUNET_CONTAINER_multipeermap_destroy(plugin->sessionmap); - GNUNET_break(0 == plugin->cur_connections); - GNUNET_free(plugin); - GNUNET_free(api); + { + GNUNET_CONTAINER_DLL_remove (plugin->probe_head, + plugin->probe_tail, + tcp_probe); + GNUNET_CONNECTION_destroy (tcp_probe->sock); + GNUNET_free (tcp_probe); + } + GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns); + GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); + GNUNET_break (0 == plugin->cur_connections); + GNUNET_free (plugin); + GNUNET_free (api); return NULL; } diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c index 7977590b0..54b3a277a 100644 --- a/src/transport/plugin_transport_template.c +++ b/src/transport/plugin_transport_template.c @@ -31,14 +31,15 @@ #include "gnunet_transport_service.h" #include "gnunet_transport_plugin.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-template", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-template", __VA_ARGS__) /** * After how long do we expire an address that we * learned from another peer if it is not reconfirmed * by anyone? */ -#define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 6) +#define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_HOURS, 6) #define PLUGIN_NAME "template" @@ -51,7 +52,8 @@ struct Plugin; /** * Session handle for connections. */ -struct GNUNET_ATS_Session { +struct GNUNET_ATS_Session +{ /** * To whom are we talking to (set to our identity * if we are still waiting for the welcome message) @@ -105,7 +107,8 @@ struct GNUNET_ATS_Session { GNUNET_NETWORK_STRUCT_BEGIN -struct TemplateAddress { +struct TemplateAddress +{ /** * Address options in NBO */ @@ -119,7 +122,8 @@ GNUNET_NETWORK_STRUCT_END /** * Encapsulation of all of the state of the plugin. */ -struct Plugin { +struct Plugin +{ /** * Our environment. */ @@ -156,15 +160,15 @@ struct Plugin { * @param state new state of the session */ static void -notify_session_monitor(struct Plugin *plugin, - struct GNUNET_ATS_Session *session, - enum GNUNET_TRANSPORT_SessionState state) +notify_session_monitor (struct Plugin *plugin, + struct GNUNET_ATS_Session *session, + enum GNUNET_TRANSPORT_SessionState state) { struct GNUNET_TRANSPORT_SessionInfo info; if (NULL == plugin->sic) return; - memset(&info, 0, sizeof(info)); + memset (&info, 0, sizeof(info)); info.state = state; info.is_inbound = GNUNET_SYSERR; /* FIXME */ // info.num_msg_pending = @@ -172,9 +176,9 @@ notify_session_monitor(struct Plugin *plugin, // info.receive_delay = // info.session_timeout = session->timeout; // info.address = session->address; - plugin->sic(plugin->sic_cls, - session, - &info); + plugin->sic (plugin->sic_cls, + session, + &info); } #endif @@ -207,14 +211,14 @@ notify_session_monitor(struct Plugin *plugin, * and does NOT mean that the message was not transmitted (DV) */ static ssize_t -template_plugin_send(void *cls, - struct GNUNET_ATS_Session *session, - const char *msgbuf, - size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls) +template_plugin_send (void *cls, + struct GNUNET_ATS_Session *session, + const char *msgbuf, + size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { /* struct Plugin *plugin = cls; */ ssize_t bytes_sent = 0; @@ -232,8 +236,8 @@ template_plugin_send(void *cls, * @param target peer from which to disconnect */ static void -template_plugin_disconnect_peer(void *cls, - const struct GNUNET_PeerIdentity *target) +template_plugin_disconnect_peer (void *cls, + const struct GNUNET_PeerIdentity *target) { // struct Plugin *plugin = cls; // FIXME @@ -250,8 +254,8 @@ template_plugin_disconnect_peer(void *cls, * @return #GNUNET_OK on success */ static int -template_plugin_disconnect_session(void *cls, - struct GNUNET_ATS_Session *session) +template_plugin_disconnect_session (void *cls, + struct GNUNET_ATS_Session *session) { // struct Plugin *plugin = cls; // FIXME @@ -268,7 +272,7 @@ template_plugin_disconnect_session(void *cls, * @return keepalive factor */ static unsigned int -template_plugin_query_keepalive_factor(void *cls) +template_plugin_query_keepalive_factor (void *cls) { return 3; } @@ -282,10 +286,10 @@ template_plugin_query_keepalive_factor(void *cls) * @return the network type in HBO or #GNUNET_SYSERR */ static enum GNUNET_NetworkType -template_plugin_get_network(void *cls, - struct GNUNET_ATS_Session *session) +template_plugin_get_network (void *cls, + struct GNUNET_ATS_Session *session) { - GNUNET_assert(NULL != session); + GNUNET_assert (NULL != session); return GNUNET_NT_UNSPECIFIED; /* Change to correct network type */ } @@ -298,8 +302,9 @@ template_plugin_get_network(void *cls, * @return the network type */ static enum GNUNET_NetworkType -template_plugin_get_network_for_address(void *cls, - const struct GNUNET_HELLO_Address *address) +template_plugin_get_network_for_address (void *cls, + const struct + GNUNET_HELLO_Address *address) { return GNUNET_NT_WAN; /* FOR NOW */ } @@ -320,15 +325,15 @@ template_plugin_get_network_for_address(void *cls, * @param asc_cls closure for @a asc */ static void -template_plugin_address_pretty_printer(void *cls, const char *type, - const void *addr, size_t addrlen, - int numeric, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback - asc, void *asc_cls) +template_plugin_address_pretty_printer (void *cls, const char *type, + const void *addr, size_t addrlen, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback + asc, void *asc_cls) { - asc(asc_cls, "converted address", GNUNET_OK); /* return address */ - asc(asc_cls, NULL, GNUNET_OK); /* done */ + asc (asc_cls, "converted address", GNUNET_OK); /* return address */ + asc (asc_cls, NULL, GNUNET_OK); /* done */ } @@ -346,7 +351,7 @@ template_plugin_address_pretty_printer(void *cls, const char *type, * and transport */ static int -template_plugin_address_suggested(void *cls, const void *addr, size_t addrlen) +template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) { /* struct Plugin *plugin = cls; */ @@ -367,18 +372,18 @@ template_plugin_address_suggested(void *cls, const void *addr, size_t addrlen) * @return string representing the same address */ static const char * -template_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) +template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) { /* * Print address in format template.options.address */ if (0 == addrlen) - { - return TRANSPORT_SESSION_INBOUND_STRING; - } + { + return TRANSPORT_SESSION_INBOUND_STRING; + } - GNUNET_break(0); + GNUNET_break (0); return NULL; } @@ -396,15 +401,15 @@ template_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -template_plugin_string_to_address(void *cls, - const char *addr, - uint16_t addrlen, - void **buf, size_t *added) +template_plugin_string_to_address (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, size_t *added) { /* * Parse string in format template.options.address */ - GNUNET_break(0); + GNUNET_break (0); return GNUNET_SYSERR; } @@ -419,18 +424,18 @@ template_plugin_string_to_address(void *cls, * @return the session if the address is valid, NULL otherwise */ static struct GNUNET_ATS_Session * -template_plugin_get_session(void *cls, - const struct GNUNET_HELLO_Address *address) +template_plugin_get_session (void *cls, + const struct GNUNET_HELLO_Address *address) { - GNUNET_break(0); + GNUNET_break (0); return NULL; } static void -template_plugin_update_session_timeout(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session) +template_plugin_update_session_timeout (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session) { } @@ -446,16 +451,16 @@ template_plugin_update_session_timeout(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -send_session_info_iter(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +send_session_info_iter (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session = value; - notify_session_monitor(plugin, - session, - GNUNET_TRANSPORT_SS_UP); + notify_session_monitor (plugin, + session, + GNUNET_TRANSPORT_SS_UP); return GNUNET_OK; } #endif @@ -474,24 +479,24 @@ send_session_info_iter(void *cls, * @param sic_cls closure for @a sic */ static void -template_plugin_setup_monitor(void *cls, - GNUNET_TRANSPORT_SessionInfoCallback sic, - void *sic_cls) +template_plugin_setup_monitor (void *cls, + GNUNET_TRANSPORT_SessionInfoCallback sic, + void *sic_cls) { struct Plugin *plugin = cls; plugin->sic = sic; plugin->sic_cls = sic_cls; if (NULL != sic) - { + { #if 0 - GNUNET_CONTAINER_multipeermap_iterate(NULL /* FIXME */, - &send_session_info_iter, - plugin); + GNUNET_CONTAINER_multipeermap_iterate (NULL /* FIXME */, + &send_session_info_iter, + plugin); #endif - /* signal end of first iteration */ - sic(sic_cls, NULL, NULL); - } + /* signal end of first iteration */ + sic (sic_cls, NULL, NULL); + } } @@ -499,27 +504,27 @@ template_plugin_setup_monitor(void *cls, * Entry point for the plugin. */ void * -libgnunet_plugin_transport_template_init(void *cls) +libgnunet_plugin_transport_template_init (void *cls) { struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; struct Plugin *plugin; if (NULL == env->receive) - { - /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully - initialze the plugin or the API */ - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); - api->cls = NULL; - api->address_to_string = &template_plugin_address_to_string; - api->string_to_address = &template_plugin_string_to_address; - api->address_pretty_printer = &template_plugin_address_pretty_printer; - return api; - } - - plugin = GNUNET_new(struct Plugin); + { + /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully + initialze the plugin or the API */ + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); + api->cls = NULL; + api->address_to_string = &template_plugin_address_to_string; + api->string_to_address = &template_plugin_string_to_address; + api->address_pretty_printer = &template_plugin_address_pretty_printer; + return api; + } + + plugin = GNUNET_new (struct Plugin); plugin->env = env; - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->send = &template_plugin_send; api->disconnect_peer = &template_plugin_disconnect_peer; @@ -534,7 +539,7 @@ libgnunet_plugin_transport_template_init(void *cls) api->get_network_for_address = &template_plugin_get_network_for_address; api->update_session_timeout = &template_plugin_update_session_timeout; api->setup_monitor = &template_plugin_setup_monitor; - LOG(GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n"); + LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n"); return api; } @@ -543,13 +548,13 @@ libgnunet_plugin_transport_template_init(void *cls) * Exit point from the plugin. */ void * -libgnunet_plugin_transport_template_done(void *cls) +libgnunet_plugin_transport_template_done (void *cls) { struct GNUNET_TRANSPORT_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; - GNUNET_free(plugin); - GNUNET_free(api); + GNUNET_free (plugin); + GNUNET_free (api); return NULL; } diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index c056bb79c..8d0bbea47 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -40,13 +40,13 @@ #include "gnunet_transport_plugin.h" #include "transport.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-udp", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__) /** * After how much inactivity should a UDP session time out? */ #define UDP_SESSION_TIME_OUT \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) /** * Number of messages we can defragment in parallel. We only really @@ -71,7 +71,8 @@ /** * UDP Message-Packet header (after defragmentation). */ -struct UDPMessage { +struct UDPMessage +{ /** * Message header. */ @@ -92,7 +93,8 @@ struct UDPMessage { /** * Closure for #append_port(). */ -struct PrettyPrinterContext { +struct PrettyPrinterContext +{ /** * DLL */ @@ -148,7 +150,8 @@ struct PrettyPrinterContext { /** * Session with another peer. */ -struct GNUNET_ATS_Session { +struct GNUNET_ATS_Session +{ /** * Which peer is this session for? */ @@ -248,7 +251,8 @@ struct GNUNET_ATS_Session { * Data structure to track defragmentation contexts based * on the source of the UDP traffic. */ -struct DefragContext { +struct DefragContext +{ /** * Defragmentation context. */ @@ -297,7 +301,8 @@ struct DefragContext { /** * Context to send fragmented messages */ -struct UDP_FragmentationContext { +struct UDP_FragmentationContext +{ /** * Next in linked list */ @@ -387,7 +392,8 @@ typedef void (*QueueContinuation) (void *cls, /** * Information we track for each message in the queue. */ -struct UDP_MessageWrapper { +struct UDP_MessageWrapper +{ /** * Session this message belongs to */ @@ -471,7 +477,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * UDP ACK Message-Packet header. */ -struct UDP_ACK_Message { +struct UDP_ACK_Message +{ /** * Message header. */ @@ -505,9 +512,9 @@ GNUNET_NETWORK_STRUCT_END * @param state new state of the session */ static void -notify_session_monitor(struct Plugin *plugin, - struct GNUNET_ATS_Session *session, - enum GNUNET_TRANSPORT_SessionState state) +notify_session_monitor (struct Plugin *plugin, + struct GNUNET_ATS_Session *session, + enum GNUNET_TRANSPORT_SessionState state) { struct GNUNET_TRANSPORT_SessionInfo info; @@ -515,7 +522,7 @@ notify_session_monitor(struct Plugin *plugin, return; if (GNUNET_YES == session->in_destroy) return; /* already destroyed, just RC>0 left-over actions */ - memset(&info, 0, sizeof(info)); + memset (&info, 0, sizeof(info)); info.state = state; info.is_inbound = GNUNET_SYSERR; /* hard to say */ info.num_msg_pending = session->msgs_in_queue; @@ -525,7 +532,7 @@ notify_session_monitor(struct Plugin *plugin, to receive from others) */ info.session_timeout = session->timeout; info.address = session->address; - plugin->sic(plugin->sic_cls, session, &info); + plugin->sic (plugin->sic_cls, session, &info); } @@ -538,15 +545,15 @@ notify_session_monitor(struct Plugin *plugin, * @return #GNUNET_OK (continue to iterate) */ static int -send_session_info_iter(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +send_session_info_iter (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session = value; - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); return GNUNET_OK; } @@ -564,22 +571,22 @@ send_session_info_iter(void *cls, * @param sic_cls closure for @a sic */ static void -udp_plugin_setup_monitor(void *cls, - GNUNET_TRANSPORT_SessionInfoCallback sic, - void *sic_cls) +udp_plugin_setup_monitor (void *cls, + GNUNET_TRANSPORT_SessionInfoCallback sic, + void *sic_cls) { struct Plugin *plugin = cls; plugin->sic = sic; plugin->sic_cls = sic_cls; if (NULL != sic) - { - GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, - &send_session_info_iter, - plugin); - /* signal end of first iteration */ - sic(sic_cls, NULL, NULL); - } + { + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, + &send_session_info_iter, + plugin); + /* signal end of first iteration */ + sic (sic_cls, NULL, NULL); + } } @@ -592,25 +599,25 @@ udp_plugin_setup_monitor(void *cls, * @param s session to free */ static void -free_session(struct GNUNET_ATS_Session *s) +free_session (struct GNUNET_ATS_Session *s) { if (NULL != s->address) - { - GNUNET_HELLO_address_free(s->address); - s->address = NULL; - } + { + GNUNET_HELLO_address_free (s->address); + s->address = NULL; + } if (NULL != s->frag_ctx) - { - GNUNET_FRAGMENT_context_destroy(s->frag_ctx->frag, NULL, NULL); - GNUNET_free(s->frag_ctx); - s->frag_ctx = NULL; - } + { + GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL); + GNUNET_free (s->frag_ctx); + s->frag_ctx = NULL; + } if (NULL != s->mst) - { - GNUNET_MST_destroy(s->mst); - s->mst = NULL; - } - GNUNET_free(s); + { + GNUNET_MST_destroy (s->mst); + s->mst = NULL; + } + GNUNET_free (s); } @@ -623,7 +630,7 @@ free_session(struct GNUNET_ATS_Session *s) * @return keepalive factor */ static unsigned int -udp_query_keepalive_factor(void *cls) +udp_query_keepalive_factor (void *cls) { return 15; } @@ -637,7 +644,7 @@ udp_query_keepalive_factor(void *cls) * @return the network type */ static enum GNUNET_NetworkType -udp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) +udp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) { return session->scope; } @@ -651,8 +658,8 @@ udp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) * @return the network type */ static enum GNUNET_NetworkType -udp_plugin_get_network_for_address(void *cls, - const struct GNUNET_HELLO_Address *address) +udp_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) { struct Plugin *plugin = cls; size_t addrlen; @@ -665,39 +672,39 @@ udp_plugin_get_network_for_address(void *cls, addrlen = address->address_length; if (addrlen == sizeof(struct IPv6UdpAddress)) - { - GNUNET_assert(NULL != address->address); /* make static analysis happy */ - u6 = address->address; - memset(&a6, 0, sizeof(a6)); + { + GNUNET_assert (NULL != address->address); /* make static analysis happy */ + u6 = address->address; + memset (&a6, 0, sizeof(a6)); #if HAVE_SOCKADDR_IN_SIN_LEN - a6.sin6_len = sizeof(a6); + a6.sin6_len = sizeof(a6); #endif - a6.sin6_family = AF_INET6; - a6.sin6_port = u6->u6_port; - GNUNET_memcpy(&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); - sb = &a6; - sbs = sizeof(a6); - } + a6.sin6_family = AF_INET6; + a6.sin6_port = u6->u6_port; + GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); + sb = &a6; + sbs = sizeof(a6); + } else if (addrlen == sizeof(struct IPv4UdpAddress)) - { - GNUNET_assert(NULL != address->address); /* make static analysis happy */ - u4 = address->address; - memset(&a4, 0, sizeof(a4)); + { + GNUNET_assert (NULL != address->address); /* make static analysis happy */ + u4 = address->address; + memset (&a4, 0, sizeof(a4)); #if HAVE_SOCKADDR_IN_SIN_LEN - a4.sin_len = sizeof(a4); + a4.sin_len = sizeof(a4); #endif - a4.sin_family = AF_INET; - a4.sin_port = u4->u4_port; - a4.sin_addr.s_addr = u4->ipv4_addr; - sb = &a4; - sbs = sizeof(a4); - } + a4.sin_family = AF_INET; + a4.sin_port = u4->u4_port; + a4.sin_addr.s_addr = u4->ipv4_addr; + sb = &a4; + sbs = sizeof(a4); + } else - { - GNUNET_break(0); - return GNUNET_NT_UNSPECIFIED; - } - return plugin->env->get_address_type(plugin->env->cls, sb, sbs); + { + GNUNET_break (0); + return GNUNET_NT_UNSPECIFIED; + } + return plugin->env->get_address_type (plugin->env->cls, sb, sbs); } @@ -711,7 +718,7 @@ udp_plugin_get_network_for_address(void *cls, * @param cls the plugin handle */ static void -udp_plugin_select_v4(void *cls); +udp_plugin_select_v4 (void *cls); /** @@ -722,7 +729,7 @@ udp_plugin_select_v4(void *cls); * @param cls the plugin handle */ static void -udp_plugin_select_v6(void *cls); +udp_plugin_select_v6 (void *cls); /** @@ -731,7 +738,7 @@ udp_plugin_select_v6(void *cls); * @param plugin plugin to reschedule */ static void -schedule_select_v4(struct Plugin *plugin) +schedule_select_v4 (struct Plugin *plugin) { struct GNUNET_TIME_Relative min_delay; struct GNUNET_TIME_Relative delay; @@ -739,47 +746,47 @@ schedule_select_v4(struct Plugin *plugin) struct UDP_MessageWrapper *min_udpw; if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4)) - { - /* Find a message ready to send: - * Flow delay from other peer is expired or not set (0) */ - min_delay = GNUNET_TIME_UNIT_FOREVER_REL; - min_udpw = NULL; - for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next) - { - delay = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time); - if (delay.rel_value_us < min_delay.rel_value_us) - { - min_delay = delay; - min_udpw = udpw; - } - } - if (NULL != plugin->select_task_v4) - GNUNET_SCHEDULER_cancel(plugin->select_task_v4); - if (NULL != min_udpw) - { - if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Calculated flow delay for UDPv4 at %s for %s\n", - GNUNET_STRINGS_relative_time_to_string(min_delay, - GNUNET_YES), - GNUNET_i2s(&min_udpw->session->target)); - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Calculated flow delay for UDPv4 at %s for %s\n", - GNUNET_STRINGS_relative_time_to_string(min_delay, - GNUNET_YES), - GNUNET_i2s(&min_udpw->session->target)); - } - } - plugin->select_task_v4 = - GNUNET_SCHEDULER_add_read_net(min_delay, - plugin->sockv4, - &udp_plugin_select_v4, - plugin); - } + { + /* Find a message ready to send: + * Flow delay from other peer is expired or not set (0) */ + min_delay = GNUNET_TIME_UNIT_FOREVER_REL; + min_udpw = NULL; + for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next) + { + delay = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time); + if (delay.rel_value_us < min_delay.rel_value_us) + { + min_delay = delay; + min_udpw = udpw; + } + } + if (NULL != plugin->select_task_v4) + GNUNET_SCHEDULER_cancel (plugin->select_task_v4); + if (NULL != min_udpw) + { + if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Calculated flow delay for UDPv4 at %s for %s\n", + GNUNET_STRINGS_relative_time_to_string (min_delay, + GNUNET_YES), + GNUNET_i2s (&min_udpw->session->target)); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Calculated flow delay for UDPv4 at %s for %s\n", + GNUNET_STRINGS_relative_time_to_string (min_delay, + GNUNET_YES), + GNUNET_i2s (&min_udpw->session->target)); + } + } + plugin->select_task_v4 = + GNUNET_SCHEDULER_add_read_net (min_delay, + plugin->sockv4, + &udp_plugin_select_v4, + plugin); + } } @@ -789,7 +796,7 @@ schedule_select_v4(struct Plugin *plugin) * @param plugin plugin to reschedule */ static void -schedule_select_v6(struct Plugin *plugin) +schedule_select_v6 (struct Plugin *plugin) { struct GNUNET_TIME_Relative min_delay; struct GNUNET_TIME_Relative delay; @@ -797,45 +804,45 @@ schedule_select_v6(struct Plugin *plugin) struct UDP_MessageWrapper *min_udpw; if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6)) - { - min_delay = GNUNET_TIME_UNIT_FOREVER_REL; - min_udpw = NULL; - for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next) - { - delay = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time); - if (delay.rel_value_us < min_delay.rel_value_us) - { - min_delay = delay; - min_udpw = udpw; - } - } - if (NULL != plugin->select_task_v6) - GNUNET_SCHEDULER_cancel(plugin->select_task_v6); - if (NULL != min_udpw) - { - if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Calculated flow delay for UDPv6 at %s for %s\n", - GNUNET_STRINGS_relative_time_to_string(min_delay, - GNUNET_YES), - GNUNET_i2s(&min_udpw->session->target)); - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Calculated flow delay for UDPv6 at %s for %s\n", - GNUNET_STRINGS_relative_time_to_string(min_delay, - GNUNET_YES), - GNUNET_i2s(&min_udpw->session->target)); - } - } - plugin->select_task_v6 = - GNUNET_SCHEDULER_add_read_net(min_delay, - plugin->sockv6, - &udp_plugin_select_v6, - plugin); - } + { + min_delay = GNUNET_TIME_UNIT_FOREVER_REL; + min_udpw = NULL; + for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next) + { + delay = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time); + if (delay.rel_value_us < min_delay.rel_value_us) + { + min_delay = delay; + min_udpw = udpw; + } + } + if (NULL != plugin->select_task_v6) + GNUNET_SCHEDULER_cancel (plugin->select_task_v6); + if (NULL != min_udpw) + { + if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Calculated flow delay for UDPv6 at %s for %s\n", + GNUNET_STRINGS_relative_time_to_string (min_delay, + GNUNET_YES), + GNUNET_i2s (&min_udpw->session->target)); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Calculated flow delay for UDPv6 at %s for %s\n", + GNUNET_STRINGS_relative_time_to_string (min_delay, + GNUNET_YES), + GNUNET_i2s (&min_udpw->session->target)); + } + } + plugin->select_task_v6 = + GNUNET_SCHEDULER_add_read_net (min_delay, + plugin->sockv6, + &udp_plugin_select_v6, + plugin); + } } @@ -854,7 +861,7 @@ schedule_select_v6(struct Plugin *plugin) * @return string representing the same address */ const char * -udp_address_to_string(void *cls, const void *addr, size_t addrlen) +udp_address_to_string (void *cls, const void *addr, size_t addrlen) { static char rbuf[INET6_ADDRSTRLEN + 10]; char buf[INET6_ADDRSTRLEN]; @@ -868,42 +875,42 @@ udp_address_to_string(void *cls, const void *addr, size_t addrlen) uint32_t options; if (NULL == addr) - { - GNUNET_break_op(0); - return NULL; - } + { + GNUNET_break_op (0); + return NULL; + } if (addrlen == sizeof(struct IPv6UdpAddress)) - { - t6 = addr; - af = AF_INET6; - options = ntohl(t6->options); - port = ntohs(t6->u6_port); - a6 = t6->ipv6_addr; - sb = &a6; - } + { + t6 = addr; + af = AF_INET6; + options = ntohl (t6->options); + port = ntohs (t6->u6_port); + a6 = t6->ipv6_addr; + sb = &a6; + } else if (addrlen == sizeof(struct IPv4UdpAddress)) - { - t4 = addr; - af = AF_INET; - options = ntohl(t4->options); - port = ntohs(t4->u4_port); - a4.s_addr = t4->ipv4_addr; - sb = &a4; - } + { + t4 = addr; + af = AF_INET; + options = ntohl (t4->options); + port = ntohs (t4->u4_port); + a4.s_addr = t4->ipv4_addr; + sb = &a4; + } else - { - GNUNET_break_op(0); - return NULL; - } - inet_ntop(af, sb, buf, INET6_ADDRSTRLEN); - GNUNET_snprintf(rbuf, - sizeof(rbuf), - (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", - PLUGIN_NAME, - options, - buf, - port); + { + GNUNET_break_op (0); + return NULL; + } + inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); + GNUNET_snprintf (rbuf, + sizeof(rbuf), + (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", + PLUGIN_NAME, + options, + buf, + port); return rbuf; } @@ -920,11 +927,11 @@ udp_address_to_string(void *cls, const void *addr, size_t addrlen) * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -udp_string_to_address(void *cls, - const char *addr, - uint16_t addrlen, - void **buf, - size_t *added) +udp_string_to_address (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, + size_t *added) { struct sockaddr_storage socket_address; char *address; @@ -938,59 +945,59 @@ udp_string_to_address(void *cls, optionstr = NULL; if ((NULL == addr) || (0 == addrlen)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if ('\0' != addr[addrlen - 1]) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - if (strlen(addr) != addrlen - 1) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - plugin = GNUNET_strdup(addr); - optionstr = strchr(plugin, '.'); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (strlen (addr) != addrlen - 1) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + plugin = GNUNET_strdup (addr); + optionstr = strchr (plugin, '.'); if (NULL == optionstr) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } optionstr[0] = '\0'; optionstr++; - options = atol(optionstr); - address = strchr(optionstr, '.'); + options = atol (optionstr); + address = strchr (optionstr, '.'); if (NULL == address) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } address[0] = '\0'; address++; if (GNUNET_OK != - GNUNET_STRINGS_to_address_ip(address, strlen(address), &socket_address)) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } - GNUNET_free(plugin); + GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address)) + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } + GNUNET_free (plugin); switch (socket_address.ss_family) - { - case AF_INET: { + { + case AF_INET: { struct IPv4UdpAddress *u4; const struct sockaddr_in *in4 = - (const struct sockaddr_in *)&socket_address; + (const struct sockaddr_in *) &socket_address; - u4 = GNUNET_new(struct IPv4UdpAddress); - u4->options = htonl(options); + u4 = GNUNET_new (struct IPv4UdpAddress); + u4->options = htonl (options); u4->ipv4_addr = in4->sin_addr.s_addr; u4->u4_port = in4->sin_port; *buf = u4; @@ -998,13 +1005,13 @@ udp_string_to_address(void *cls, return GNUNET_OK; } - case AF_INET6: { + case AF_INET6: { struct IPv6UdpAddress *u6; const struct sockaddr_in6 *in6 = - (const struct sockaddr_in6 *)&socket_address; + (const struct sockaddr_in6 *) &socket_address; - u6 = GNUNET_new(struct IPv6UdpAddress); - u6->options = htonl(options); + u6 = GNUNET_new (struct IPv6UdpAddress); + u6->options = htonl (options); u6->ipv6_addr = in6->sin6_addr; u6->u6_port = in6->sin6_port; *buf = u6; @@ -1012,10 +1019,10 @@ udp_string_to_address(void *cls, return GNUNET_OK; } - default: - GNUNET_break(0); - return GNUNET_SYSERR; - } + default: + GNUNET_break (0); + return GNUNET_SYSERR; + } } @@ -1026,39 +1033,39 @@ udp_string_to_address(void *cls, * @param hostname result from DNS resolver */ static void -append_port(void *cls, const char *hostname) +append_port (void *cls, const char *hostname) { struct PrettyPrinterContext *ppc = cls; struct Plugin *plugin = ppc->plugin; char *ret; if (NULL == hostname) - { - /* Final call, done */ - GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head, - plugin->ppc_dll_tail, - ppc); - ppc->resolver_handle = NULL; - ppc->asc(ppc->asc_cls, NULL, GNUNET_OK); - GNUNET_free(ppc); - return; - } + { + /* Final call, done */ + GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, + plugin->ppc_dll_tail, + ppc); + ppc->resolver_handle = NULL; + ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); + GNUNET_free (ppc); + return; + } if (GNUNET_YES == ppc->ipv6) - GNUNET_asprintf(&ret, - "%s.%u.[%s]:%d", - PLUGIN_NAME, - ppc->options, - hostname, - ppc->port); + GNUNET_asprintf (&ret, + "%s.%u.[%s]:%d", + PLUGIN_NAME, + ppc->options, + hostname, + ppc->port); else - GNUNET_asprintf(&ret, - "%s.%u.%s:%d", - PLUGIN_NAME, - ppc->options, - hostname, - ppc->port); - ppc->asc(ppc->asc_cls, ret, GNUNET_OK); - GNUNET_free(ret); + GNUNET_asprintf (&ret, + "%s.%u.%s:%d", + PLUGIN_NAME, + ppc->options, + hostname, + ppc->port); + ppc->asc (ppc->asc_cls, ret, GNUNET_OK); + GNUNET_free (ret); } @@ -1077,14 +1084,14 @@ append_port(void *cls, const char *hostname) * @param asc_cls closure for @a asc */ static void -udp_plugin_address_pretty_printer(void *cls, - const char *type, - const void *addr, - size_t addrlen, - int numeric, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback asc, - void *asc_cls) +udp_plugin_address_pretty_printer (void *cls, + const char *type, + const void *addr, + size_t addrlen, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback asc, + void *asc_cls) { struct Plugin *plugin = cls; struct PrettyPrinterContext *ppc; @@ -1098,44 +1105,44 @@ udp_plugin_address_pretty_printer(void *cls, uint32_t options; if (addrlen == sizeof(struct IPv6UdpAddress)) - { - u6 = addr; - memset(&a6, 0, sizeof(a6)); - a6.sin6_family = AF_INET6; + { + u6 = addr; + memset (&a6, 0, sizeof(a6)); + a6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN - a6.sin6_len = sizeof(a6); + a6.sin6_len = sizeof(a6); #endif - a6.sin6_port = u6->u6_port; - a6.sin6_addr = u6->ipv6_addr; - port = ntohs(u6->u6_port); - options = ntohl(u6->options); - sb = (const struct sockaddr *)&a6; - sbs = sizeof(a6); - } + a6.sin6_port = u6->u6_port; + a6.sin6_addr = u6->ipv6_addr; + port = ntohs (u6->u6_port); + options = ntohl (u6->options); + sb = (const struct sockaddr *) &a6; + sbs = sizeof(a6); + } else if (addrlen == sizeof(struct IPv4UdpAddress)) - { - u4 = addr; - memset(&a4, 0, sizeof(a4)); - a4.sin_family = AF_INET; + { + u4 = addr; + memset (&a4, 0, sizeof(a4)); + a4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - a4.sin_len = sizeof(a4); + a4.sin_len = sizeof(a4); #endif - a4.sin_port = u4->u4_port; - a4.sin_addr.s_addr = u4->ipv4_addr; - port = ntohs(u4->u4_port); - options = ntohl(u4->options); - sb = (const struct sockaddr *)&a4; - sbs = sizeof(a4); - } + a4.sin_port = u4->u4_port; + a4.sin_addr.s_addr = u4->ipv4_addr; + port = ntohs (u4->u4_port); + options = ntohl (u4->options); + sb = (const struct sockaddr *) &a4; + sbs = sizeof(a4); + } else - { - /* invalid address */ - GNUNET_break_op(0); - asc(asc_cls, NULL, GNUNET_SYSERR); - asc(asc_cls, NULL, GNUNET_OK); - return; - } - ppc = GNUNET_new(struct PrettyPrinterContext); + { + /* invalid address */ + GNUNET_break_op (0); + asc (asc_cls, NULL, GNUNET_SYSERR); + asc (asc_cls, NULL, GNUNET_OK); + return; + } + ppc = GNUNET_new (struct PrettyPrinterContext); ppc->plugin = plugin; ppc->asc = asc; ppc->asc_cls = asc_cls; @@ -1145,13 +1152,13 @@ udp_plugin_address_pretty_printer(void *cls, ppc->ipv6 = GNUNET_YES; else ppc->ipv6 = GNUNET_NO; - GNUNET_CONTAINER_DLL_insert(plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); - ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sb, - sbs, - !numeric, - timeout, - &append_port, - ppc); + GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); + ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, + sbs, + ! numeric, + timeout, + &append_port, + ppc); } @@ -1165,7 +1172,7 @@ udp_plugin_address_pretty_printer(void *cls, * @return #GNUNET_OK if port is either our open or advertised port */ static int -check_port(const struct Plugin *plugin, uint16_t in_port) +check_port (const struct Plugin *plugin, uint16_t in_port) { if ((plugin->port == in_port) || (plugin->aport == in_port)) return GNUNET_OK; @@ -1189,56 +1196,56 @@ check_port(const struct Plugin *plugin, uint16_t in_port) * and transport, #GNUNET_SYSERR if not */ static int -udp_plugin_check_address(void *cls, const void *addr, size_t addrlen) +udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) { struct Plugin *plugin = cls; const struct IPv4UdpAddress *v4; const struct IPv6UdpAddress *v6; if (sizeof(struct IPv4UdpAddress) == addrlen) - { - struct sockaddr_in s4; + { + struct sockaddr_in s4; - v4 = (const struct IPv4UdpAddress *)addr; - if (GNUNET_OK != check_port(plugin, ntohs(v4->u4_port))) - return GNUNET_SYSERR; - memset(&s4, 0, sizeof(s4)); - s4.sin_family = AF_INET; + v4 = (const struct IPv4UdpAddress *) addr; + if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) + return GNUNET_SYSERR; + memset (&s4, 0, sizeof(s4)); + s4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - s4.sin_len = sizeof(s4); + s4.sin_len = sizeof(s4); #endif - s4.sin_port = v4->u4_port; - s4.sin_addr.s_addr = v4->ipv4_addr; + s4.sin_port = v4->u4_port; + s4.sin_addr.s_addr = v4->ipv4_addr; - if (GNUNET_OK != - GNUNET_NAT_test_address(plugin->nat, &s4, sizeof(struct sockaddr_in))) - return GNUNET_SYSERR; - } + if (GNUNET_OK != + GNUNET_NAT_test_address (plugin->nat, &s4, sizeof(struct sockaddr_in))) + return GNUNET_SYSERR; + } else if (sizeof(struct IPv6UdpAddress) == addrlen) - { - struct sockaddr_in6 s6; - - v6 = (const struct IPv6UdpAddress *)addr; - if (IN6_IS_ADDR_LINKLOCAL(&v6->ipv6_addr)) - return GNUNET_OK; /* plausible, if unlikely... */ - memset(&s6, 0, sizeof(s6)); - s6.sin6_family = AF_INET6; + { + struct sockaddr_in6 s6; + + v6 = (const struct IPv6UdpAddress *) addr; + if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) + return GNUNET_OK; /* plausible, if unlikely... */ + memset (&s6, 0, sizeof(s6)); + s6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN - s6.sin6_len = sizeof(s6); + s6.sin6_len = sizeof(s6); #endif - s6.sin6_port = v6->u6_port; - s6.sin6_addr = v6->ipv6_addr; + s6.sin6_port = v6->u6_port; + s6.sin6_addr = v6->ipv6_addr; - if (GNUNET_OK != GNUNET_NAT_test_address(plugin->nat, - &s6, - sizeof(struct sockaddr_in6))) - return GNUNET_SYSERR; - } - else - { - GNUNET_break_op(0); + if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat, + &s6, + sizeof(struct sockaddr_in6))) return GNUNET_SYSERR; - } + } + else + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1256,12 +1263,12 @@ udp_plugin_check_address(void *cls, const void *addr, size_t addrlen) * @param addrlen actual length of the @a addr */ static void -udp_nat_port_map_callback(void *cls, - void **app_ctx, - int add_remove, - enum GNUNET_NAT_AddressClass ac, - const struct sockaddr *addr, - socklen_t addrlen) +udp_nat_port_map_callback (void *cls, + void **app_ctx, + int add_remove, + enum GNUNET_NAT_AddressClass ac, + const struct sockaddr *addr, + socklen_t addrlen) { struct Plugin *plugin = cls; struct GNUNET_HELLO_Address *address; @@ -1270,23 +1277,23 @@ udp_nat_port_map_callback(void *cls, void *arg; size_t args; - (void)app_ctx; - LOG(GNUNET_ERROR_TYPE_DEBUG, - (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n" - : "NAT notification to remove address `%s'\n", - GNUNET_a2s(addr, addrlen)); + (void) app_ctx; + LOG (GNUNET_ERROR_TYPE_DEBUG, + (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n" + : "NAT notification to remove address `%s'\n", + GNUNET_a2s (addr, addrlen)); /* convert 'address' to our internal format */ switch (addr->sa_family) - { - case AF_INET: { + { + case AF_INET: { const struct sockaddr_in *i4; - GNUNET_assert(sizeof(struct sockaddr_in) == addrlen); - i4 = (const struct sockaddr_in *)addr; - if (0 == ntohs(i4->sin_port)) + GNUNET_assert (sizeof(struct sockaddr_in) == addrlen); + i4 = (const struct sockaddr_in *) addr; + if (0 == ntohs (i4->sin_port)) return; /* Port = 0 means unmapped, ignore these for UDP. */ - memset(&u4, 0, sizeof(u4)); - u4.options = htonl(plugin->myoptions); + memset (&u4, 0, sizeof(u4)); + u4.options = htonl (plugin->myoptions); u4.ipv4_addr = i4->sin_addr.s_addr; u4.u4_port = i4->sin_port; arg = &u4; @@ -1294,15 +1301,15 @@ udp_nat_port_map_callback(void *cls, break; } - case AF_INET6: { + case AF_INET6: { const struct sockaddr_in6 *i6; - GNUNET_assert(sizeof(struct sockaddr_in6) == addrlen); - i6 = (const struct sockaddr_in6 *)addr; - if (0 == ntohs(i6->sin6_port)) + GNUNET_assert (sizeof(struct sockaddr_in6) == addrlen); + i6 = (const struct sockaddr_in6 *) addr; + if (0 == ntohs (i6->sin6_port)) return; /* Port = 0 means unmapped, ignore these for UDP. */ - memset(&u6, 0, sizeof(u6)); - u6.options = htonl(plugin->myoptions); + memset (&u6, 0, sizeof(u6)); + u6.options = htonl (plugin->myoptions); u6.ipv6_addr = i6->sin6_addr; u6.u6_port = i6->sin6_port; arg = &u6; @@ -1310,19 +1317,19 @@ udp_nat_port_map_callback(void *cls, break; } - default: - GNUNET_break(0); - return; - } + default: + GNUNET_break (0); + return; + } /* modify our published address list */ /* TODO: use 'ac' here in the future... */ - address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - PLUGIN_NAME, - arg, - args, - GNUNET_HELLO_ADDRESS_INFO_NONE); - plugin->env->notify_address(plugin->env->cls, add_remove, address); - GNUNET_HELLO_address_free(address); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, + arg, + args, + GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, add_remove, address); + GNUNET_HELLO_address_free (address); } @@ -1332,7 +1339,8 @@ udp_nat_port_map_callback(void *cls, /** * Closure for #session_cmp_it(). */ -struct GNUNET_ATS_SessionCompareContext { +struct GNUNET_ATS_SessionCompareContext +{ /** * Set to session matching the address. */ @@ -1354,17 +1362,17 @@ struct GNUNET_ATS_SessionCompareContext { * @return #GNUNET_NO if we found the session, #GNUNET_OK if not */ static int -session_cmp_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) +session_cmp_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { struct GNUNET_ATS_SessionCompareContext *cctx = cls; struct GNUNET_ATS_Session *s = value; - if (0 == GNUNET_HELLO_address_cmp(s->address, cctx->address)) - { - GNUNET_assert(GNUNET_NO == s->in_destroy); - cctx->res = s; - return GNUNET_NO; - } + if (0 == GNUNET_HELLO_address_cmp (s->address, cctx->address)) + { + GNUNET_assert (GNUNET_NO == s->in_destroy); + cctx->res = s; + return GNUNET_NO; + } return GNUNET_OK; } @@ -1379,8 +1387,8 @@ session_cmp_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) * @return the session if it exists, or NULL if it is not found */ static struct GNUNET_ATS_Session * -udp_plugin_lookup_session(void *cls, - const struct GNUNET_HELLO_Address *address) +udp_plugin_lookup_session (void *cls, + const struct GNUNET_HELLO_Address *address) { struct Plugin *plugin = cls; const struct IPv6UdpAddress *udp_a6; @@ -1388,54 +1396,54 @@ udp_plugin_lookup_session(void *cls, struct GNUNET_ATS_SessionCompareContext cctx; if (NULL == address->address) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } if (sizeof(struct IPv4UdpAddress) == address->address_length) + { + if (NULL == plugin->sockv4) + return NULL; + udp_a4 = (const struct IPv4UdpAddress *) address->address; + if (0 == udp_a4->u4_port) { - if (NULL == plugin->sockv4) - return NULL; - udp_a4 = (const struct IPv4UdpAddress *)address->address; - if (0 == udp_a4->u4_port) - { - GNUNET_break(0); - return NULL; - } + GNUNET_break (0); + return NULL; } + } else if (sizeof(struct IPv6UdpAddress) == address->address_length) + { + if (NULL == plugin->sockv6) + return NULL; + udp_a6 = (const struct IPv6UdpAddress *) address->address; + if (0 == udp_a6->u6_port) { - if (NULL == plugin->sockv6) - return NULL; - udp_a6 = (const struct IPv6UdpAddress *)address->address; - if (0 == udp_a6->u6_port) - { - GNUNET_break(0); - return NULL; - } - } - else - { - GNUNET_break(0); + GNUNET_break (0); return NULL; } + } + else + { + GNUNET_break (0); + return NULL; + } /* check if session already exists */ cctx.address = address; cctx.res = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Looking for existing session for peer `%s' with address `%s'\n", - GNUNET_i2s(&address->peer), - udp_address_to_string(plugin, - address->address, - address->address_length)); - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, - &address->peer, - &session_cmp_it, - &cctx); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Looking for existing session for peer `%s' with address `%s'\n", + GNUNET_i2s (&address->peer), + udp_address_to_string (plugin, + address->address, + address->address_length)); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, + &address->peer, + &session_cmp_it, + &cctx); if (NULL == cctx.res) return NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); return cctx.res; } @@ -1449,12 +1457,12 @@ udp_plugin_lookup_session(void *cls, * @param s session to reschedule timeout activity for */ static void -reschedule_session_timeout(struct GNUNET_ATS_Session *s) +reschedule_session_timeout (struct GNUNET_ATS_Session *s) { if (GNUNET_YES == s->in_destroy) return; - GNUNET_assert(NULL != s->timeout_task); - s->timeout = GNUNET_TIME_relative_to_absolute(UDP_SESSION_TIME_OUT); + GNUNET_assert (NULL != s->timeout_task); + s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT); } @@ -1468,22 +1476,22 @@ reschedule_session_timeout(struct GNUNET_ATS_Session *s) * @param session which session is being updated */ static void -udp_plugin_update_session_timeout(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session) +udp_plugin_update_session_timeout (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session) { struct Plugin *plugin = cls; if (GNUNET_YES != - GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions, - peer, - session)) - { - GNUNET_break(0); - return; - } + GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, + peer, + session)) + { + GNUNET_break (0); + return; + } /* Reschedule session timeout */ - reschedule_session_timeout(session); + reschedule_session_timeout (session); } @@ -1498,47 +1506,47 @@ udp_plugin_update_session_timeout(void *cls, * @param udpw message wrapper to dequeue */ static void -dequeue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw) +dequeue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw) { struct GNUNET_ATS_Session *session = udpw->session; if (plugin->bytes_in_buffer < udpw->msg_size) - { - GNUNET_break(0); - } + { + GNUNET_break (0); + } else - { - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total bytes in send buffers", - -(long long)udpw->msg_size, - GNUNET_NO); - plugin->bytes_in_buffer -= udpw->msg_size; - } - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total messages in send buffers", - -1, - GNUNET_NO); + { + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total bytes in send buffers", + -(long long) udpw->msg_size, + GNUNET_NO); + plugin->bytes_in_buffer -= udpw->msg_size; + } + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total messages in send buffers", + -1, + GNUNET_NO); if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length) - { - GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, - plugin->ipv4_queue_tail, - udpw); - } + { + GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head, + plugin->ipv4_queue_tail, + udpw); + } else if (sizeof(struct IPv6UdpAddress) == udpw->session->address->address_length) - { - GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, - plugin->ipv6_queue_tail, - udpw); - } + { + GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head, + plugin->ipv6_queue_tail, + udpw); + } else - { - GNUNET_break(0); - return; - } - GNUNET_assert(session->msgs_in_queue > 0); + { + GNUNET_break (0); + return; + } + GNUNET_assert (session->msgs_in_queue > 0); session->msgs_in_queue--; - GNUNET_assert(session->bytes_in_queue >= udpw->msg_size); + GNUNET_assert (session->bytes_in_queue >= udpw->msg_size); session->bytes_in_queue -= udpw->msg_size; } @@ -1550,56 +1558,56 @@ dequeue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw) * @param udpw message wrapper to queue */ static void -enqueue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw) +enqueue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw) { struct GNUNET_ATS_Session *session = udpw->session; if (GNUNET_YES == session->in_destroy) - { - GNUNET_break(0); - GNUNET_free(udpw); - return; - } + { + GNUNET_break (0); + GNUNET_free (udpw); + return; + } if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size) - { - GNUNET_break(0); - } + { + GNUNET_break (0); + } else - { - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total bytes in send buffers", - udpw->msg_size, - GNUNET_NO); - plugin->bytes_in_buffer += udpw->msg_size; - } - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total messages in send buffers", - 1, - GNUNET_NO); + { + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total bytes in send buffers", + udpw->msg_size, + GNUNET_NO); + plugin->bytes_in_buffer += udpw->msg_size; + } + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total messages in send buffers", + 1, + GNUNET_NO); if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length) - { - GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, - plugin->ipv4_queue_tail, - udpw); - } + { + GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head, + plugin->ipv4_queue_tail, + udpw); + } else if (sizeof(struct IPv6UdpAddress) == udpw->session->address->address_length) - { - GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head, - plugin->ipv6_queue_tail, - udpw); - } + { + GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head, + plugin->ipv6_queue_tail, + udpw); + } else - { - GNUNET_break(0); - udpw->cont(udpw->cont_cls, - &session->target, - GNUNET_SYSERR, - udpw->msg_size, - 0); - GNUNET_free(udpw); - return; - } + { + GNUNET_break (0); + udpw->cont (udpw->cont_cls, + &session->target, + GNUNET_SYSERR, + udpw->msg_size, + 0); + GNUNET_free (udpw); + return; + } session->msgs_in_queue++; session->bytes_in_queue += udpw->msg_size; } @@ -1616,7 +1624,7 @@ enqueue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw) * #GNUNET_SYSERR if the transmission failed */ static void -fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result) +fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result) { struct Plugin *plugin = frag_ctx->plugin; struct GNUNET_ATS_Session *s = frag_ctx->session; @@ -1625,122 +1633,122 @@ fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result) size_t overhead; struct GNUNET_TIME_Relative delay; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "%p: Fragmented message removed with result %s\n", - frag_ctx, - (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "%p: Fragmented message removed with result %s\n", + frag_ctx, + (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); /* Call continuation for fragmented message */ if (frag_ctx->on_wire_size >= frag_ctx->payload_size) overhead = frag_ctx->on_wire_size - frag_ctx->payload_size; else overhead = frag_ctx->on_wire_size; - delay = GNUNET_TIME_absolute_get_duration(frag_ctx->start_time); + delay = GNUNET_TIME_absolute_get_duration (frag_ctx->start_time); if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Fragmented message acknowledged after %s (expected at %s)\n", - GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), - GNUNET_STRINGS_absolute_time_to_string(frag_ctx->next_frag_time)); - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Fragmented message acknowledged after %s (expected at %s)\n", + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), + GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); + } else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Fragmented message acknowledged after %s (expected at %s)\n", - GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), - GNUNET_STRINGS_absolute_time_to_string(frag_ctx->next_frag_time)); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Fragmented message acknowledged after %s (expected at %s)\n", + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), + GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); + } if (NULL != frag_ctx->cont) - frag_ctx->cont(frag_ctx->cont_cls, - &s->target, - result, - s->frag_ctx->payload_size, - frag_ctx->on_wire_size); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented messages active", - -1, - GNUNET_NO); + frag_ctx->cont (frag_ctx->cont_cls, + &s->target, + result, + s->frag_ctx->payload_size, + frag_ctx->on_wire_size); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented messages active", + -1, + GNUNET_NO); if (GNUNET_OK == result) - { - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented msgs, messages, sent, success", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented msgs, bytes payload, sent, success", - s->frag_ctx->payload_size, - GNUNET_NO); - GNUNET_STATISTICS_update( - plugin->env->stats, - "# UDP, fragmented msgs, bytes overhead, sent, success", - overhead, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total, bytes overhead, sent", - overhead, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total, bytes payload, sent", - s->frag_ctx->payload_size, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, messages, sent, success", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, bytes payload, sent, success", + s->frag_ctx->payload_size, + GNUNET_NO); + GNUNET_STATISTICS_update ( + plugin->env->stats, + "# UDP, fragmented msgs, bytes overhead, sent, success", + overhead, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes overhead, sent", + overhead, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes payload, sent", + s->frag_ctx->payload_size, + GNUNET_NO); + } else - { - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented msgs, messages, sent, failure", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented msgs, bytes payload, sent, failure", - s->frag_ctx->payload_size, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented msgs, bytes payload, sent, failure", - overhead, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented msgs, bytes payload, sent, failure", - overhead, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, messages, sent, failure", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, bytes payload, sent, failure", + s->frag_ctx->payload_size, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, bytes payload, sent, failure", + overhead, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, bytes payload, sent, failure", + overhead, + GNUNET_NO); + } /* Remove remaining fragments from queue, no need to transmit those any longer. */ if (s->address->address_length == sizeof(struct IPv6UdpAddress)) - { - udpw = plugin->ipv6_queue_head; - while (NULL != udpw) - { - tmp = udpw->next; - if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx)) - { - dequeue(plugin, udpw); - GNUNET_free(udpw); - } - udpw = tmp; - } - } + { + udpw = plugin->ipv6_queue_head; + while (NULL != udpw) + { + tmp = udpw->next; + if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx)) + { + dequeue (plugin, udpw); + GNUNET_free (udpw); + } + udpw = tmp; + } + } if (s->address->address_length == sizeof(struct IPv4UdpAddress)) - { - udpw = plugin->ipv4_queue_head; - while (NULL != udpw) - { - tmp = udpw->next; - if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx)) - { - dequeue(plugin, udpw); - GNUNET_free(udpw); - } - udpw = tmp; - } - } - notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); - GNUNET_FRAGMENT_context_destroy(frag_ctx->frag, - &s->last_expected_msg_delay, - &s->last_expected_ack_delay); + { + udpw = plugin->ipv4_queue_head; + while (NULL != udpw) + { + tmp = udpw->next; + if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx)) + { + dequeue (plugin, udpw); + GNUNET_free (udpw); + } + udpw = tmp; + } + } + notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); + GNUNET_FRAGMENT_context_destroy (frag_ctx->frag, + &s->last_expected_msg_delay, + &s->last_expected_ack_delay); s->frag_ctx = NULL; - GNUNET_free(frag_ctx); + GNUNET_free (frag_ctx); } @@ -1753,45 +1761,45 @@ fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result) * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static void -qc_fragment_sent(void *cls, struct UDP_MessageWrapper *udpw, int result) +qc_fragment_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) { struct Plugin *plugin = cls; - GNUNET_assert(NULL != udpw->frag_ctx); + GNUNET_assert (NULL != udpw->frag_ctx); if (GNUNET_OK == result) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Fragment of message with %u bytes transmitted to %s\n", - (unsigned int)udpw->payload_size, - GNUNET_i2s(&udpw->session->target)); - GNUNET_FRAGMENT_context_transmission_done(udpw->frag_ctx->frag); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented msgs, fragments, sent, success", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update( - plugin->env->stats, - "# UDP, fragmented msgs, fragments bytes, sent, success", - udpw->msg_size, - GNUNET_NO); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Fragment of message with %u bytes transmitted to %s\n", + (unsigned int) udpw->payload_size, + GNUNET_i2s (&udpw->session->target)); + GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, fragments, sent, success", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update ( + plugin->env->stats, + "# UDP, fragmented msgs, fragments bytes, sent, success", + udpw->msg_size, + GNUNET_NO); + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Failed to transmit fragment of message with %u bytes to %s\n", - (unsigned int)udpw->payload_size, - GNUNET_i2s(&udpw->session->target)); - fragmented_message_done(udpw->frag_ctx, GNUNET_SYSERR); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented msgs, fragments, sent, failure", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update( - plugin->env->stats, - "# UDP, fragmented msgs, fragments bytes, sent, failure", - udpw->msg_size, - GNUNET_NO); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Failed to transmit fragment of message with %u bytes to %s\n", + (unsigned int) udpw->payload_size, + GNUNET_i2s (&udpw->session->target)); + fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, fragments, sent, failure", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update ( + plugin->env->stats, + "# UDP, fragmented msgs, fragments bytes, sent, failure", + udpw->msg_size, + GNUNET_NO); + } } @@ -1805,35 +1813,35 @@ qc_fragment_sent(void *cls, struct UDP_MessageWrapper *udpw, int result) * @param msg the message that was created */ static void -enqueue_fragment(void *cls, const struct GNUNET_MessageHeader *msg) +enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) { struct UDP_FragmentationContext *frag_ctx = cls; struct Plugin *plugin = frag_ctx->plugin; struct UDP_MessageWrapper *udpw; struct GNUNET_ATS_Session *session = frag_ctx->session; - size_t msg_len = ntohs(msg->size); + size_t msg_len = ntohs (msg->size); - LOG(GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len); - udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + msg_len); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len); + udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + msg_len); udpw->session = session; - udpw->msg_buf = (char *)&udpw[1]; + udpw->msg_buf = (char *) &udpw[1]; udpw->msg_size = msg_len; udpw->payload_size = msg_len; /* FIXME: minus fragment overhead */ udpw->timeout = frag_ctx->timeout; udpw->start_time = frag_ctx->start_time; udpw->transmission_time = frag_ctx->next_frag_time; frag_ctx->next_frag_time = - GNUNET_TIME_absolute_add(frag_ctx->next_frag_time, - frag_ctx->flow_delay_from_other_peer); + GNUNET_TIME_absolute_add (frag_ctx->next_frag_time, + frag_ctx->flow_delay_from_other_peer); udpw->frag_ctx = frag_ctx; udpw->qc = &qc_fragment_sent; udpw->qc_cls = plugin; - GNUNET_memcpy(udpw->msg_buf, msg, msg_len); - enqueue(plugin, udpw); + GNUNET_memcpy (udpw->msg_buf, msg, msg_len); + enqueue (plugin, udpw); if (session->address->address_length == sizeof(struct IPv4UdpAddress)) - schedule_select_v4(plugin); + schedule_select_v4 (plugin); else - schedule_select_v6(plugin); + schedule_select_v6 (plugin); } @@ -1846,7 +1854,7 @@ enqueue_fragment(void *cls, const struct GNUNET_MessageHeader *msg) * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static void -qc_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result) +qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) { struct Plugin *plugin = cls; size_t overhead; @@ -1858,68 +1866,68 @@ qc_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result) overhead = udpw->msg_size; if (NULL != udpw->cont) - { - delay = GNUNET_TIME_absolute_get_duration(udpw->start_time); - if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Message sent via UDP with delay of %s\n", - GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); - } - else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Message sent via UDP with delay of %s\n", - GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); - } - udpw->cont(udpw->cont_cls, - &udpw->session->target, - result, - udpw->payload_size, - overhead); - } + { + delay = GNUNET_TIME_absolute_get_duration (udpw->start_time); + if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Message sent via UDP with delay of %s\n", + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); + } + else + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Message sent via UDP with delay of %s\n", + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); + } + udpw->cont (udpw->cont_cls, + &udpw->session->target, + result, + udpw->payload_size, + overhead); + } if (GNUNET_OK == result) - { - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, unfragmented msgs, messages, sent, success", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update( - plugin->env->stats, - "# UDP, unfragmented msgs, bytes payload, sent, success", - udpw->payload_size, - GNUNET_NO); - GNUNET_STATISTICS_update( - plugin->env->stats, - "# UDP, unfragmented msgs, bytes overhead, sent, success", - overhead, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total, bytes overhead, sent", - overhead, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total, bytes payload, sent", - udpw->payload_size, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented msgs, messages, sent, success", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update ( + plugin->env->stats, + "# UDP, unfragmented msgs, bytes payload, sent, success", + udpw->payload_size, + GNUNET_NO); + GNUNET_STATISTICS_update ( + plugin->env->stats, + "# UDP, unfragmented msgs, bytes overhead, sent, success", + overhead, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes overhead, sent", + overhead, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes payload, sent", + udpw->payload_size, + GNUNET_NO); + } else - { - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, unfragmented msgs, messages, sent, failure", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update( - plugin->env->stats, - "# UDP, unfragmented msgs, bytes payload, sent, failure", - udpw->payload_size, - GNUNET_NO); - GNUNET_STATISTICS_update( - plugin->env->stats, - "# UDP, unfragmented msgs, bytes overhead, sent, failure", - overhead, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented msgs, messages, sent, failure", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update ( + plugin->env->stats, + "# UDP, unfragmented msgs, bytes payload, sent, failure", + udpw->payload_size, + GNUNET_NO); + GNUNET_STATISTICS_update ( + plugin->env->stats, + "# UDP, unfragmented msgs, bytes overhead, sent, failure", + overhead, + GNUNET_NO); + } } @@ -1951,14 +1959,14 @@ qc_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result) * and does NOT mean that the message was not transmitted (DV) */ static ssize_t -udp_plugin_send(void *cls, - struct GNUNET_ATS_Session *s, - const char *msgbuf, - size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls) +udp_plugin_send (void *cls, + struct GNUNET_ATS_Session *s, + const char *msgbuf, + size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { struct Plugin *plugin = cls; size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage); @@ -1975,30 +1983,30 @@ udp_plugin_send(void *cls, (NULL == plugin->sockv4)) return GNUNET_SYSERR; if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if (GNUNET_YES != - GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions, - &s->target, - s)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "UDP transmits %u-byte message to `%s' using address `%s'\n", - udpmlen, - GNUNET_i2s(&s->target), - udp_address_to_string(plugin, - s->address->address, - s->address->address_length)); - - udp = (struct UDPMessage *)mbuf; - udp->header.size = htons(udpmlen); - udp->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE); - udp->reserved = htonl(0); + GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, + &s->target, + s)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "UDP transmits %u-byte message to `%s' using address `%s'\n", + udpmlen, + GNUNET_i2s (&s->target), + udp_address_to_string (plugin, + s->address->address, + s->address->address_length)); + + udp = (struct UDPMessage *) mbuf; + udp->header.size = htons (udpmlen); + udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE); + udp->reserved = htonl (0); udp->sender = *plugin->env->my_identity; /* We do not update the session time out here! Otherwise this @@ -2010,100 +2018,100 @@ udp_plugin_send(void *cls, * responses! */ if (udpmlen <= UDP_MTU) - { - /* unfragmented message */ - udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + udpmlen); - udpw->session = s; - udpw->msg_buf = (char *)&udpw[1]; - udpw->msg_size = udpmlen; /* message size with UDP overhead */ - udpw->payload_size = msgbuf_size; /* message size without UDP overhead */ - udpw->start_time = GNUNET_TIME_absolute_get(); - udpw->timeout = GNUNET_TIME_relative_to_absolute(to); - udpw->transmission_time = s->last_transmit_time; - s->last_transmit_time = - GNUNET_TIME_absolute_add(s->last_transmit_time, - s->flow_delay_from_other_peer); - udpw->cont = cont; - udpw->cont_cls = cont_cls; - udpw->frag_ctx = NULL; - udpw->qc = &qc_message_sent; - udpw->qc_cls = plugin; - GNUNET_memcpy(udpw->msg_buf, udp, sizeof(struct UDPMessage)); - GNUNET_memcpy(&udpw->msg_buf[sizeof(struct UDPMessage)], - msgbuf, - msgbuf_size); - enqueue(plugin, udpw); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, unfragmented messages queued total", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, unfragmented bytes payload queued total", - msgbuf_size, - GNUNET_NO); - if (s->address->address_length == sizeof(struct IPv4UdpAddress)) - schedule_select_v4(plugin); - else - schedule_select_v6(plugin); - } + { + /* unfragmented message */ + udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + udpmlen); + udpw->session = s; + udpw->msg_buf = (char *) &udpw[1]; + udpw->msg_size = udpmlen; /* message size with UDP overhead */ + udpw->payload_size = msgbuf_size; /* message size without UDP overhead */ + udpw->start_time = GNUNET_TIME_absolute_get (); + udpw->timeout = GNUNET_TIME_relative_to_absolute (to); + udpw->transmission_time = s->last_transmit_time; + s->last_transmit_time = + GNUNET_TIME_absolute_add (s->last_transmit_time, + s->flow_delay_from_other_peer); + udpw->cont = cont; + udpw->cont_cls = cont_cls; + udpw->frag_ctx = NULL; + udpw->qc = &qc_message_sent; + udpw->qc_cls = plugin; + GNUNET_memcpy (udpw->msg_buf, udp, sizeof(struct UDPMessage)); + GNUNET_memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)], + msgbuf, + msgbuf_size); + enqueue (plugin, udpw); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented messages queued total", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented bytes payload queued total", + msgbuf_size, + GNUNET_NO); + if (s->address->address_length == sizeof(struct IPv4UdpAddress)) + schedule_select_v4 (plugin); + else + schedule_select_v6 (plugin); + } else - { - /* fragmented message */ - if (NULL != s->frag_ctx) - return GNUNET_SYSERR; - GNUNET_memcpy(&udp[1], msgbuf, msgbuf_size); - frag_ctx = GNUNET_new(struct UDP_FragmentationContext); - frag_ctx->plugin = plugin; - frag_ctx->session = s; - frag_ctx->cont = cont; - frag_ctx->cont_cls = cont_cls; - frag_ctx->start_time = GNUNET_TIME_absolute_get(); - frag_ctx->next_frag_time = s->last_transmit_time; - frag_ctx->flow_delay_from_other_peer = - GNUNET_TIME_relative_divide(s->flow_delay_from_other_peer, - 1 + (msgbuf_size / UDP_MTU)); - frag_ctx->timeout = GNUNET_TIME_relative_to_absolute(to); - frag_ctx->payload_size = - msgbuf_size; /* unfragmented message size without UDP overhead */ - frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ - frag_ctx->frag = GNUNET_FRAGMENT_context_create(plugin->env->stats, - UDP_MTU, - &plugin->tracker, - s->last_expected_msg_delay, - s->last_expected_ack_delay, - &udp->header, - &enqueue_fragment, - frag_ctx); - s->frag_ctx = frag_ctx; - s->last_transmit_time = frag_ctx->next_frag_time; - latency = GNUNET_TIME_absolute_get_remaining(s->last_transmit_time); - if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) - LOG(GNUNET_ERROR_TYPE_WARNING, - "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", - GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_YES), - GNUNET_i2s(&s->target), - (unsigned int)s->msgs_in_queue); - else - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", - GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_YES), - GNUNET_i2s(&s->target), - (unsigned int)s->msgs_in_queue); - - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented messages active", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented messages, total", - 1, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragmented bytes (payload)", - frag_ctx->payload_size, - GNUNET_NO); - } - notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); + { + /* fragmented message */ + if (NULL != s->frag_ctx) + return GNUNET_SYSERR; + GNUNET_memcpy (&udp[1], msgbuf, msgbuf_size); + frag_ctx = GNUNET_new (struct UDP_FragmentationContext); + frag_ctx->plugin = plugin; + frag_ctx->session = s; + frag_ctx->cont = cont; + frag_ctx->cont_cls = cont_cls; + frag_ctx->start_time = GNUNET_TIME_absolute_get (); + frag_ctx->next_frag_time = s->last_transmit_time; + frag_ctx->flow_delay_from_other_peer = + GNUNET_TIME_relative_divide (s->flow_delay_from_other_peer, + 1 + (msgbuf_size / UDP_MTU)); + frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to); + frag_ctx->payload_size = + msgbuf_size; /* unfragmented message size without UDP overhead */ + frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ + frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, + UDP_MTU, + &plugin->tracker, + s->last_expected_msg_delay, + s->last_expected_ack_delay, + &udp->header, + &enqueue_fragment, + frag_ctx); + s->frag_ctx = frag_ctx; + s->last_transmit_time = frag_ctx->next_frag_time; + latency = GNUNET_TIME_absolute_get_remaining (s->last_transmit_time); + if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) + LOG (GNUNET_ERROR_TYPE_WARNING, + "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", + GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES), + GNUNET_i2s (&s->target), + (unsigned int) s->msgs_in_queue); + else + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", + GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES), + GNUNET_i2s (&s->target), + (unsigned int) s->msgs_in_queue); + + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented messages active", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented messages, total", + 1, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented bytes (payload)", + frag_ctx->payload_size, + GNUNET_NO); + } + notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); return udpmlen; } @@ -2114,7 +2122,8 @@ udp_plugin_send(void *cls, /** * Closure for #find_receive_context(). */ -struct FindReceiveContext { +struct FindReceiveContext +{ /** * Where to store the result. */ @@ -2148,20 +2157,20 @@ struct FindReceiveContext { * #GNUNET_NO if not. */ static int -find_receive_context(void *cls, - struct GNUNET_CONTAINER_HeapNode *node, - void *element, - GNUNET_CONTAINER_HeapCostType cost) +find_receive_context (void *cls, + struct GNUNET_CONTAINER_HeapNode *node, + void *element, + GNUNET_CONTAINER_HeapCostType cost) { struct FindReceiveContext *frc = cls; struct DefragContext *e = element; if ((frc->udp_addr_len == e->udp_addr_len) && - (0 == memcmp(frc->udp_addr, e->udp_addr, frc->udp_addr_len))) - { - frc->rc = e; - return GNUNET_NO; - } + (0 == memcmp (frc->udp_addr, e->udp_addr, frc->udp_addr_len))) + { + frc->rc = e; + return GNUNET_NO; + } return GNUNET_YES; } @@ -2175,96 +2184,96 @@ find_receive_context(void *cls, * @return #GNUNET_OK on success */ static int -udp_disconnect_session(void *cls, struct GNUNET_ATS_Session *s) +udp_disconnect_session (void *cls, struct GNUNET_ATS_Session *s) { struct Plugin *plugin = cls; struct UDP_MessageWrapper *udpw; struct UDP_MessageWrapper *next; struct FindReceiveContext frc; - GNUNET_assert(GNUNET_YES != s->in_destroy); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p to peer `%s' at address %s ended\n", - s, - GNUNET_i2s(&s->target), - udp_address_to_string(plugin, - s->address->address, - s->address->address_length)); + GNUNET_assert (GNUNET_YES != s->in_destroy); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p to peer `%s' at address %s ended\n", + s, + GNUNET_i2s (&s->target), + udp_address_to_string (plugin, + s->address->address, + s->address->address_length)); if (NULL != s->timeout_task) - { - GNUNET_SCHEDULER_cancel(s->timeout_task); - s->timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (s->timeout_task); + s->timeout_task = NULL; + } if (NULL != s->frag_ctx) - { - /* Remove fragmented message due to disconnect */ - fragmented_message_done(s->frag_ctx, GNUNET_SYSERR); - } - GNUNET_assert( + { + /* Remove fragmented message due to disconnect */ + fragmented_message_done (s->frag_ctx, GNUNET_SYSERR); + } + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(plugin->sessions, &s->target, s)); + GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s)); frc.rc = NULL; frc.udp_addr = s->address->address; frc.udp_addr_len = s->address->address_length; /* Lookup existing receive context for this address */ if (NULL != plugin->defrag_ctxs) + { + GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, + &find_receive_context, + &frc); + if (NULL != frc.rc) { - GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs, - &find_receive_context, - &frc); - if (NULL != frc.rc) - { - struct DefragContext *d_ctx = frc.rc; + struct DefragContext *d_ctx = frc.rc; - GNUNET_CONTAINER_heap_remove_node(d_ctx->hnode); - GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag); - GNUNET_free(d_ctx); - } + GNUNET_CONTAINER_heap_remove_node (d_ctx->hnode); + GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); + GNUNET_free (d_ctx); } + } s->in_destroy = GNUNET_YES; next = plugin->ipv4_queue_head; while (NULL != (udpw = next)) + { + next = udpw->next; + if (udpw->session == s) { - next = udpw->next; - if (udpw->session == s) - { - dequeue(plugin, udpw); - udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); - GNUNET_free(udpw); - } + dequeue (plugin, udpw); + udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); + GNUNET_free (udpw); } + } next = plugin->ipv6_queue_head; while (NULL != (udpw = next)) + { + next = udpw->next; + if (udpw->session == s) { - next = udpw->next; - if (udpw->session == s) - { - dequeue(plugin, udpw); - udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); - GNUNET_free(udpw); - } + dequeue (plugin, udpw); + udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); + GNUNET_free (udpw); } + } if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont)) - { - /* The 'frag_ctx' itself will be freed in #free_session() a bit - later, as it might be in use right now */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Calling continuation for fragemented message to `%s' with result SYSERR\n", - GNUNET_i2s(&s->target)); - s->frag_ctx->cont(s->frag_ctx->cont_cls, - &s->target, - GNUNET_SYSERR, - s->frag_ctx->payload_size, - s->frag_ctx->on_wire_size); - } - notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_DONE); - plugin->env->session_end(plugin->env->cls, s->address, s); - GNUNET_STATISTICS_set(plugin->env->stats, - "# UDP sessions active", - GNUNET_CONTAINER_multipeermap_size(plugin->sessions), - GNUNET_NO); + { + /* The 'frag_ctx' itself will be freed in #free_session() a bit + later, as it might be in use right now */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Calling continuation for fragemented message to `%s' with result SYSERR\n", + GNUNET_i2s (&s->target)); + s->frag_ctx->cont (s->frag_ctx->cont_cls, + &s->target, + GNUNET_SYSERR, + s->frag_ctx->payload_size, + s->frag_ctx->on_wire_size); + } + notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_DONE); + plugin->env->session_end (plugin->env->cls, s->address, s); + GNUNET_STATISTICS_set (plugin->env->stats, + "# UDP sessions active", + GNUNET_CONTAINER_multipeermap_size (plugin->sessions), + GNUNET_NO); if (0 == s->rc) - free_session(s); + free_session (s); return GNUNET_OK; } @@ -2278,10 +2287,10 @@ udp_disconnect_session(void *cls, struct GNUNET_ATS_Session *s) * @param udp_addr_len number of bytes in @a udp_addr */ static void -read_process_ack(struct Plugin *plugin, - const struct GNUNET_MessageHeader *msg, - const union UdpAddress *udp_addr, - socklen_t udp_addr_len) +read_process_ack (struct Plugin *plugin, + const struct GNUNET_MessageHeader *msg, + const union UdpAddress *udp_addr, + socklen_t udp_addr_len) { const struct GNUNET_MessageHeader *ack; const struct UDP_ACK_Message *udp_ack; @@ -2290,93 +2299,93 @@ read_process_ack(struct Plugin *plugin, struct GNUNET_TIME_Relative flow_delay; /* check message format */ - if (ntohs(msg->size) < + if (ntohs (msg->size) < sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader)) - { - GNUNET_break_op(0); - return; - } - udp_ack = (const struct UDP_ACK_Message *)msg; - ack = (const struct GNUNET_MessageHeader *)&udp_ack[1]; - if (ntohs(ack->size) != ntohs(msg->size) - sizeof(struct UDP_ACK_Message)) - { - GNUNET_break_op(0); - return; - } + { + GNUNET_break_op (0); + return; + } + udp_ack = (const struct UDP_ACK_Message *) msg; + ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; + if (ntohs (ack->size) != ntohs (msg->size) - sizeof(struct UDP_ACK_Message)) + { + GNUNET_break_op (0); + return; + } /* Locate session */ - address = GNUNET_HELLO_address_allocate(&udp_ack->sender, - PLUGIN_NAME, - udp_addr, - udp_addr_len, - GNUNET_HELLO_ADDRESS_INFO_NONE); - s = udp_plugin_lookup_session(plugin, address); + address = GNUNET_HELLO_address_allocate (&udp_ack->sender, + PLUGIN_NAME, + udp_addr, + udp_addr_len, + GNUNET_HELLO_ADDRESS_INFO_NONE); + s = udp_plugin_lookup_session (plugin, address); if (NULL == s) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "UDP session of address %s for ACK not found\n", - udp_address_to_string(plugin, + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "UDP session of address %s for ACK not found\n", + udp_address_to_string (plugin, address->address, address->address_length)); - GNUNET_HELLO_address_free(address); - return; - } + GNUNET_HELLO_address_free (address); + return; + } if (NULL == s->frag_ctx) - { - LOG(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Fragmentation context of address %s for ACK (%s) not found\n", - udp_address_to_string(plugin, + { + LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Fragmentation context of address %s for ACK (%s) not found\n", + udp_address_to_string (plugin, address->address, address->address_length), - GNUNET_FRAGMENT_print_ack(ack)); - GNUNET_HELLO_address_free(address); - return; - } - GNUNET_HELLO_address_free(address); + GNUNET_FRAGMENT_print_ack (ack)); + GNUNET_HELLO_address_free (address); + return; + } + GNUNET_HELLO_address_free (address); /* evaluate flow delay: how long should we wait between messages? */ - if (UINT32_MAX == ntohl(udp_ack->delay)) - { - /* Other peer asked for us to terminate the session */ - LOG(GNUNET_ERROR_TYPE_INFO, - "Asked to disconnect UDP session of %s\n", - GNUNET_i2s(&udp_ack->sender)); - udp_disconnect_session(plugin, s); - return; - } - flow_delay.rel_value_us = (uint64_t)ntohl(udp_ack->delay); + if (UINT32_MAX == ntohl (udp_ack->delay)) + { + /* Other peer asked for us to terminate the session */ + LOG (GNUNET_ERROR_TYPE_INFO, + "Asked to disconnect UDP session of %s\n", + GNUNET_i2s (&udp_ack->sender)); + udp_disconnect_session (plugin, s); + return; + } + flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) - LOG(GNUNET_ERROR_TYPE_WARNING, - "We received a sending delay of %s for %s\n", - GNUNET_STRINGS_relative_time_to_string(flow_delay, GNUNET_YES), - GNUNET_i2s(&udp_ack->sender)); + LOG (GNUNET_ERROR_TYPE_WARNING, + "We received a sending delay of %s for %s\n", + GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES), + GNUNET_i2s (&udp_ack->sender)); else - LOG(GNUNET_ERROR_TYPE_DEBUG, - "We received a sending delay of %s for %s\n", - GNUNET_STRINGS_relative_time_to_string(flow_delay, GNUNET_YES), - GNUNET_i2s(&udp_ack->sender)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "We received a sending delay of %s for %s\n", + GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES), + GNUNET_i2s (&udp_ack->sender)); /* Flow delay is for the reassembled packet, however, our delay is per packet, so we need to adjust: */ s->flow_delay_from_other_peer = flow_delay; /* Handle ACK */ - if (GNUNET_OK != GNUNET_FRAGMENT_process_ack(s->frag_ctx->frag, ack)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", - (unsigned int)ntohs(msg->size), - GNUNET_i2s(&udp_ack->sender), - udp_address_to_string(plugin, udp_addr, udp_addr_len)); - /* Expect more ACKs to arrive */ - return; - } + if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", + (unsigned int) ntohs (msg->size), + GNUNET_i2s (&udp_ack->sender), + udp_address_to_string (plugin, udp_addr, udp_addr_len)); + /* Expect more ACKs to arrive */ + return; + } /* Remove fragmented message after successful sending */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Message from %s at %s full ACK'ed\n", - GNUNET_i2s(&udp_ack->sender), - udp_address_to_string(plugin, udp_addr, udp_addr_len)); - fragmented_message_done(s->frag_ctx, GNUNET_OK); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Message from %s at %s full ACK'ed\n", + GNUNET_i2s (&udp_ack->sender), + udp_address_to_string (plugin, udp_addr, udp_addr_len)); + fragmented_message_done (s->frag_ctx, GNUNET_OK); } @@ -2389,17 +2398,17 @@ read_process_ack(struct Plugin *plugin, * @return #GNUNET_OK (always) */ static int -process_inbound_tokenized_messages(void *cls, - const struct GNUNET_MessageHeader *hdr) +process_inbound_tokenized_messages (void *cls, + const struct GNUNET_MessageHeader *hdr) { struct GNUNET_ATS_Session *session = cls; struct Plugin *plugin = session->plugin; if (GNUNET_YES == session->in_destroy) return GNUNET_OK; - reschedule_session_timeout(session); + reschedule_session_timeout (session); session->flow_delay_for_other_peer = - plugin->env->receive(plugin->env->cls, session->address, session, hdr); + plugin->env->receive (plugin->env->cls, session->address, session, hdr); return GNUNET_OK; } @@ -2413,13 +2422,13 @@ process_inbound_tokenized_messages(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -disconnect_and_free_it(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +disconnect_and_free_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct Plugin *plugin = cls; - udp_disconnect_session(plugin, value); + udp_disconnect_session (plugin, value); return GNUNET_OK; } @@ -2433,17 +2442,17 @@ disconnect_and_free_it(void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed */ static void -udp_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) +udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting from peer `%s'\n", - GNUNET_i2s(target)); - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, - target, - &disconnect_and_free_it, - plugin); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Disconnecting from peer `%s'\n", + GNUNET_i2s (target)); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, + target, + &disconnect_and_free_it, + plugin); } @@ -2453,29 +2462,29 @@ udp_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) * @param cls the `struct GNUNET_ATS_Session` to time out */ static void -session_timeout(void *cls) +session_timeout (void *cls) { struct GNUNET_ATS_Session *s = cls; struct Plugin *plugin = s->plugin; struct GNUNET_TIME_Relative left; s->timeout_task = NULL; - left = GNUNET_TIME_absolute_get_remaining(s->timeout); + left = GNUNET_TIME_absolute_get_remaining (s->timeout); if (left.rel_value_us > 0) - { - /* not actually our turn yet, but let's at least update - the monitor, it may think we're about to die ... */ - notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); - s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, &session_timeout, s); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p was idle for %s, disconnecting\n", - s, - GNUNET_STRINGS_relative_time_to_string(UDP_SESSION_TIME_OUT, - GNUNET_YES)); + { + /* not actually our turn yet, but let's at least update + the monitor, it may think we're about to die ... */ + notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); + s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p was idle for %s, disconnecting\n", + s, + GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, + GNUNET_YES)); /* call session destroy function */ - udp_disconnect_session(plugin, s); + udp_disconnect_session (plugin, s); } @@ -2491,46 +2500,46 @@ session_timeout(void *cls) * @return NULL on error, otherwise session handle */ static struct GNUNET_ATS_Session * -udp_plugin_create_session(void *cls, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_NetworkType network_type) +udp_plugin_create_session (void *cls, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_NetworkType network_type) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *s; - s = GNUNET_new(struct GNUNET_ATS_Session); - s->mst = GNUNET_MST_create(&process_inbound_tokenized_messages, s); + s = GNUNET_new (struct GNUNET_ATS_Session); + s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages, s); s->plugin = plugin; - s->address = GNUNET_HELLO_address_copy(address); + s->address = GNUNET_HELLO_address_copy (address); s->target = address->peer; - s->last_transmit_time = GNUNET_TIME_absolute_get(); + s->last_transmit_time = GNUNET_TIME_absolute_get (); s->last_expected_ack_delay = - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250); + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250); s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO; s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; - s->timeout = GNUNET_TIME_relative_to_absolute(UDP_SESSION_TIME_OUT); + s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT); s->timeout_task = - GNUNET_SCHEDULER_add_delayed(UDP_SESSION_TIME_OUT, &session_timeout, s); + GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, &session_timeout, s); s->scope = network_type; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Creating new session %p for peer `%s' address `%s'\n", - s, - GNUNET_i2s(&address->peer), - udp_address_to_string(plugin, - address->address, - address->address_length)); - GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multipeermap_put( - plugin->sessions, - &s->target, - s, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - GNUNET_STATISTICS_set(plugin->env->stats, - "# UDP sessions active", - GNUNET_CONTAINER_multipeermap_size(plugin->sessions), - GNUNET_NO); - notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_INIT); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Creating new session %p for peer `%s' address `%s'\n", + s, + GNUNET_i2s (&address->peer), + udp_address_to_string (plugin, + address->address, + address->address_length)); + GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put ( + plugin->sessions, + &s->target, + s, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_STATISTICS_set (plugin->env->stats, + "# UDP sessions active", + GNUNET_CONTAINER_multipeermap_size (plugin->sessions), + GNUNET_NO); + notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_INIT); return s; } @@ -2544,7 +2553,7 @@ udp_plugin_create_session(void *cls, * @return the session or NULL of max connections exceeded */ static struct GNUNET_ATS_Session * -udp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) +udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *s; @@ -2553,54 +2562,54 @@ udp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) const struct IPv6UdpAddress *udp_v6; if (NULL == address) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } if ((address->address_length != sizeof(struct IPv4UdpAddress)) && (address->address_length != sizeof(struct IPv6UdpAddress))) - { - GNUNET_break_op(0); - return NULL; - } - if (NULL != (s = udp_plugin_lookup_session(cls, address))) + { + GNUNET_break_op (0); + return NULL; + } + if (NULL != (s = udp_plugin_lookup_session (cls, address))) return s; /* need to create new session */ if (sizeof(struct IPv4UdpAddress) == address->address_length) - { - struct sockaddr_in v4; + { + struct sockaddr_in v4; - udp_v4 = (const struct IPv4UdpAddress *)address->address; - memset(&v4, '\0', sizeof(v4)); - v4.sin_family = AF_INET; + udp_v4 = (const struct IPv4UdpAddress *) address->address; + memset (&v4, '\0', sizeof(v4)); + v4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - v4.sin_len = sizeof(struct sockaddr_in); + v4.sin_len = sizeof(struct sockaddr_in); #endif - v4.sin_port = udp_v4->u4_port; - v4.sin_addr.s_addr = udp_v4->ipv4_addr; - network_type = plugin->env->get_address_type(plugin->env->cls, - (const struct sockaddr *)&v4, - sizeof(v4)); - } + v4.sin_port = udp_v4->u4_port; + v4.sin_addr.s_addr = udp_v4->ipv4_addr; + network_type = plugin->env->get_address_type (plugin->env->cls, + (const struct sockaddr *) &v4, + sizeof(v4)); + } if (sizeof(struct IPv6UdpAddress) == address->address_length) - { - struct sockaddr_in6 v6; + { + struct sockaddr_in6 v6; - udp_v6 = (const struct IPv6UdpAddress *)address->address; - memset(&v6, '\0', sizeof(v6)); - v6.sin6_family = AF_INET6; + udp_v6 = (const struct IPv6UdpAddress *) address->address; + memset (&v6, '\0', sizeof(v6)); + v6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN - v6.sin6_len = sizeof(struct sockaddr_in6); + v6.sin6_len = sizeof(struct sockaddr_in6); #endif - v6.sin6_port = udp_v6->u6_port; - v6.sin6_addr = udp_v6->ipv6_addr; - network_type = plugin->env->get_address_type(plugin->env->cls, - (const struct sockaddr *)&v6, - sizeof(v6)); - } - GNUNET_break(GNUNET_NT_UNSPECIFIED != network_type); - return udp_plugin_create_session(cls, address, network_type); + v6.sin6_port = udp_v6->u6_port; + v6.sin6_addr = udp_v6->ipv6_addr; + network_type = plugin->env->get_address_type (plugin->env->cls, + (const struct sockaddr *) &v6, + sizeof(v6)); + } + GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); + return udp_plugin_create_session (cls, address, network_type); } @@ -2614,50 +2623,50 @@ udp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) * @param network_type network type the address belongs to */ static void -process_udp_message(struct Plugin *plugin, - const struct UDPMessage *msg, - const union UdpAddress *udp_addr, - size_t udp_addr_len, - enum GNUNET_NetworkType network_type) +process_udp_message (struct Plugin *plugin, + const struct UDPMessage *msg, + const union UdpAddress *udp_addr, + size_t udp_addr_len, + enum GNUNET_NetworkType network_type) { struct GNUNET_ATS_Session *s; struct GNUNET_HELLO_Address *address; - GNUNET_break(GNUNET_NT_UNSPECIFIED != network_type); - if (0 != ntohl(msg->reserved)) - { - GNUNET_break_op(0); - return; - } - if (ntohs(msg->header.size) < + GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); + if (0 != ntohl (msg->reserved)) + { + GNUNET_break_op (0); + return; + } + if (ntohs (msg->header.size) < sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage)) - { - GNUNET_break_op(0); - return; - } - - address = GNUNET_HELLO_address_allocate(&msg->sender, - PLUGIN_NAME, - udp_addr, - udp_addr_len, - GNUNET_HELLO_ADDRESS_INFO_NONE); - if (NULL == (s = udp_plugin_lookup_session(plugin, address))) - { - s = udp_plugin_create_session(plugin, address, network_type); - plugin->env->session_start(plugin->env->cls, address, s, s->scope); - notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_UP); - } - GNUNET_free(address); + { + GNUNET_break_op (0); + return; + } + + address = GNUNET_HELLO_address_allocate (&msg->sender, + PLUGIN_NAME, + udp_addr, + udp_addr_len, + GNUNET_HELLO_ADDRESS_INFO_NONE); + if (NULL == (s = udp_plugin_lookup_session (plugin, address))) + { + s = udp_plugin_create_session (plugin, address, network_type); + plugin->env->session_start (plugin->env->cls, address, s, s->scope); + notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UP); + } + GNUNET_free (address); s->rc++; - GNUNET_MST_from_buffer(s->mst, - (const char *)&msg[1], - ntohs(msg->header.size) - sizeof(struct UDPMessage), - GNUNET_YES, - GNUNET_NO); + GNUNET_MST_from_buffer (s->mst, + (const char *) &msg[1], + ntohs (msg->header.size) - sizeof(struct UDPMessage), + GNUNET_YES, + GNUNET_NO); s->rc--; if ((0 == s->rc) && (GNUNET_YES == s->in_destroy)) - free_session(s); + free_session (s); } @@ -2668,29 +2677,29 @@ process_udp_message(struct Plugin *plugin, * @param msg the message */ static void -fragment_msg_proc(void *cls, const struct GNUNET_MessageHeader *msg) +fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg) { struct DefragContext *dc = cls; const struct UDPMessage *um; - if (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) - { - GNUNET_break_op(0); - return; - } - if (ntohs(msg->size) < sizeof(struct UDPMessage)) - { - GNUNET_break_op(0); - return; - } - um = (const struct UDPMessage *)msg; + if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) + { + GNUNET_break_op (0); + return; + } + if (ntohs (msg->size) < sizeof(struct UDPMessage)) + { + GNUNET_break_op (0); + return; + } + um = (const struct UDPMessage *) msg; dc->sender = um->sender; dc->have_sender = GNUNET_YES; - process_udp_message(dc->plugin, - um, - dc->udp_addr, - dc->udp_addr_len, - dc->network_type); + process_udp_message (dc->plugin, + um, + dc->udp_addr, + dc->udp_addr_len, + dc->network_type); } @@ -2704,24 +2713,24 @@ fragment_msg_proc(void *cls, const struct GNUNET_MessageHeader *msg) * #GNUNET_SYSERR if we failed to send the ACK */ static void -ack_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result) +ack_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) { struct Plugin *plugin = cls; if (GNUNET_OK == result) - { - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, ACK messages sent", - 1, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, ACK messages sent", + 1, + GNUNET_NO); + } else - { - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, ACK transmissions failed", - 1, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, ACK transmissions failed", + 1, + GNUNET_NO); + } } @@ -2733,11 +2742,11 @@ ack_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result) * @param msg ack to transmit */ static void -ack_proc(void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) +ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) { struct DefragContext *rc = cls; struct Plugin *plugin = rc->plugin; - size_t msize = sizeof(struct UDP_ACK_Message) + ntohs(msg->size); + size_t msize = sizeof(struct UDP_ACK_Message) + ntohs (msg->size); struct UDP_ACK_Message *udp_ack; uint32_t delay; struct UDP_MessageWrapper *udpw; @@ -2745,36 +2754,36 @@ ack_proc(void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) struct GNUNET_HELLO_Address *address; if (GNUNET_NO == rc->have_sender) - { - /* tried to defragment but never succeeded, hence will not ACK */ - /* This can happen if we just lost msgs */ - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, fragments discarded without ACK", - 1, - GNUNET_NO); - return; - } - address = GNUNET_HELLO_address_allocate(&rc->sender, - PLUGIN_NAME, - rc->udp_addr, - rc->udp_addr_len, - GNUNET_HELLO_ADDRESS_INFO_NONE); - s = udp_plugin_lookup_session(plugin, address); - GNUNET_HELLO_address_free(address); + { + /* tried to defragment but never succeeded, hence will not ACK */ + /* This can happen if we just lost msgs */ + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragments discarded without ACK", + 1, + GNUNET_NO); + return; + } + address = GNUNET_HELLO_address_allocate (&rc->sender, + PLUGIN_NAME, + rc->udp_addr, + rc->udp_addr_len, + GNUNET_HELLO_ADDRESS_INFO_NONE); + s = udp_plugin_lookup_session (plugin, address); + GNUNET_HELLO_address_free (address); if (NULL == s) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Trying to transmit ACK to peer `%s' but no session found!\n", - udp_address_to_string(plugin, rc->udp_addr, rc->udp_addr_len)); - GNUNET_CONTAINER_heap_remove_node(rc->hnode); - GNUNET_DEFRAGMENT_context_destroy(rc->defrag); - GNUNET_free(rc); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, ACK transmissions failed", - 1, - GNUNET_NO); - return; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Trying to transmit ACK to peer `%s' but no session found!\n", + udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len)); + GNUNET_CONTAINER_heap_remove_node (rc->hnode); + GNUNET_DEFRAGMENT_context_destroy (rc->defrag); + GNUNET_free (rc); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, ACK transmissions failed", + 1, + GNUNET_NO); + return; + } if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == s->flow_delay_for_other_peer.rel_value_us) delay = UINT32_MAX; @@ -2782,32 +2791,32 @@ ack_proc(void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) delay = s->flow_delay_for_other_peer.rel_value_us; else delay = UINT32_MAX - 1; /* largest value we can communicate */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sending ACK to `%s' including delay of %s\n", - udp_address_to_string(plugin, rc->udp_addr, rc->udp_addr_len), - GNUNET_STRINGS_relative_time_to_string(s->flow_delay_for_other_peer, - GNUNET_YES)); - udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + msize); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending ACK to `%s' including delay of %s\n", + udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len), + GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, + GNUNET_YES)); + udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + msize); udpw->msg_size = msize; udpw->payload_size = 0; udpw->session = s; - udpw->start_time = GNUNET_TIME_absolute_get(); + udpw->start_time = GNUNET_TIME_absolute_get (); udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; - udpw->msg_buf = (char *)&udpw[1]; + udpw->msg_buf = (char *) &udpw[1]; udpw->qc = &ack_message_sent; udpw->qc_cls = plugin; - udp_ack = (struct UDP_ACK_Message *)udpw->msg_buf; - udp_ack->header.size = htons((uint16_t)msize); - udp_ack->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); - udp_ack->delay = htonl(delay); + udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf; + udp_ack->header.size = htons ((uint16_t) msize); + udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); + udp_ack->delay = htonl (delay); udp_ack->sender = *plugin->env->my_identity; - GNUNET_memcpy(&udp_ack[1], msg, ntohs(msg->size)); - enqueue(plugin, udpw); - notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_UPDATE); + GNUNET_memcpy (&udp_ack[1], msg, ntohs (msg->size)); + enqueue (plugin, udpw); + notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UPDATE); if (s->address->address_length == sizeof(struct IPv4UdpAddress)) - schedule_select_v4(plugin); + schedule_select_v4 (plugin); else - schedule_select_v6(plugin); + schedule_select_v6 (plugin); } @@ -2821,11 +2830,11 @@ ack_proc(void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) * @param network_type network type the address belongs to */ static void -read_process_fragment(struct Plugin *plugin, - const struct GNUNET_MessageHeader *msg, - const union UdpAddress *udp_addr, - size_t udp_addr_len, - enum GNUNET_NetworkType network_type) +read_process_fragment (struct Plugin *plugin, + const struct GNUNET_MessageHeader *msg, + const union UdpAddress *udp_addr, + size_t udp_addr_len, + enum GNUNET_NetworkType network_type) { struct DefragContext *d_ctx; struct GNUNET_TIME_Absolute now; @@ -2836,65 +2845,65 @@ read_process_fragment(struct Plugin *plugin, frc.udp_addr_len = udp_addr_len; /* Lookup existing receive context for this address */ - GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs, - &find_receive_context, - &frc); - now = GNUNET_TIME_absolute_get(); + GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, + &find_receive_context, + &frc); + now = GNUNET_TIME_absolute_get (); d_ctx = frc.rc; if (NULL == d_ctx) - { - /* Create a new defragmentation context */ - d_ctx = GNUNET_malloc(sizeof(struct DefragContext) + udp_addr_len); - GNUNET_memcpy(&d_ctx[1], udp_addr, udp_addr_len); - d_ctx->udp_addr = (const union UdpAddress *)&d_ctx[1]; - d_ctx->udp_addr_len = udp_addr_len; - d_ctx->network_type = network_type; - d_ctx->plugin = plugin; - d_ctx->defrag = - GNUNET_DEFRAGMENT_context_create(plugin->env->stats, - UDP_MTU, - UDP_MAX_MESSAGES_IN_DEFRAG, - d_ctx, - &fragment_msg_proc, - &ack_proc); - d_ctx->hnode = GNUNET_CONTAINER_heap_insert(plugin->defrag_ctxs, - d_ctx, - (GNUNET_CONTAINER_HeapCostType) - now.abs_value_us); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Created new defragmentation context for %u-byte fragment from `%s'\n", - (unsigned int)ntohs(msg->size), - udp_address_to_string(plugin, udp_addr, udp_addr_len)); - } + { + /* Create a new defragmentation context */ + d_ctx = GNUNET_malloc (sizeof(struct DefragContext) + udp_addr_len); + GNUNET_memcpy (&d_ctx[1], udp_addr, udp_addr_len); + d_ctx->udp_addr = (const union UdpAddress *) &d_ctx[1]; + d_ctx->udp_addr_len = udp_addr_len; + d_ctx->network_type = network_type; + d_ctx->plugin = plugin; + d_ctx->defrag = + GNUNET_DEFRAGMENT_context_create (plugin->env->stats, + UDP_MTU, + UDP_MAX_MESSAGES_IN_DEFRAG, + d_ctx, + &fragment_msg_proc, + &ack_proc); + d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, + d_ctx, + (GNUNET_CONTAINER_HeapCostType) + now.abs_value_us); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Created new defragmentation context for %u-byte fragment from `%s'\n", + (unsigned int) ntohs (msg->size), + udp_address_to_string (plugin, udp_addr, udp_addr_len)); + } else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found existing defragmentation context for %u-byte fragment from `%s'\n", - (unsigned int)ntohs(msg->size), - udp_address_to_string(plugin, udp_addr, udp_addr_len)); - } - - if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment(d_ctx->defrag, msg)) - { - /* keep this 'rc' from expiring */ - GNUNET_CONTAINER_heap_update_cost(d_ctx->hnode, - (GNUNET_CONTAINER_HeapCostType) - now.abs_value_us); - } - if (GNUNET_CONTAINER_heap_get_size(plugin->defrag_ctxs) > + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found existing defragmentation context for %u-byte fragment from `%s'\n", + (unsigned int) ntohs (msg->size), + udp_address_to_string (plugin, udp_addr, udp_addr_len)); + } + + if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg)) + { + /* keep this 'rc' from expiring */ + GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode, + (GNUNET_CONTAINER_HeapCostType) + now.abs_value_us); + } + if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) - { - /* remove 'rc' that was inactive the longest */ - d_ctx = GNUNET_CONTAINER_heap_remove_root(plugin->defrag_ctxs); - GNUNET_assert(NULL != d_ctx); - GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag); - GNUNET_free(d_ctx); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, Defragmentations aborted", - 1, - GNUNET_NO); - } + { + /* remove 'rc' that was inactive the longest */ + d_ctx = GNUNET_CONTAINER_heap_remove_root (plugin->defrag_ctxs); + GNUNET_assert (NULL != d_ctx); + GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); + GNUNET_free (d_ctx); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, Defragmentations aborted", + 1, + GNUNET_NO); + } } @@ -2905,7 +2914,7 @@ read_process_fragment(struct Plugin *plugin, * @param rsock socket to read from */ static void -udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) +udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) { socklen_t fromlen; struct sockaddr_storage addr; @@ -2922,126 +2931,126 @@ udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) enum GNUNET_NetworkType network_type; fromlen = sizeof(addr); - memset(&addr, 0, sizeof(addr)); - size = GNUNET_NETWORK_socket_recvfrom(rsock, - buf, - sizeof(buf), - (struct sockaddr *)&addr, - &fromlen); - sa = (const struct sockaddr *)&addr; + memset (&addr, 0, sizeof(addr)); + size = GNUNET_NETWORK_socket_recvfrom (rsock, + buf, + sizeof(buf), + (struct sockaddr *) &addr, + &fromlen); + sa = (const struct sockaddr *) &addr; if (-1 == size) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "UDP failed to receive data: %s\n", - strerror(errno)); - /* Connection failure or something. Not a protocol violation. */ - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "UDP failed to receive data: %s\n", + strerror (errno)); + /* Connection failure or something. Not a protocol violation. */ + return; + } /* Check if this is a STUN packet */ if (GNUNET_NO != - GNUNET_NAT_stun_handle_packet(plugin->nat, - (const struct sockaddr *)&addr, - fromlen, - buf, - size)) + GNUNET_NAT_stun_handle_packet (plugin->nat, + (const struct sockaddr *) &addr, + fromlen, + buf, + size)) return; /* was STUN, do not process further */ if (size < sizeof(struct GNUNET_MessageHeader)) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n", - (unsigned int)size, - GNUNET_a2s(sa, fromlen)); - /* _MAY_ be a connection failure (got partial message) */ - /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ - GNUNET_break_op(0); - return; - } - - msg = (const struct GNUNET_MessageHeader *)buf; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "UDP received %u-byte message from `%s' type %u\n", - (unsigned int)size, - GNUNET_a2s(sa, fromlen), - ntohs(msg->type)); - if (size != ntohs(msg->size)) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "UDP malformed message (size %u) header from %s\n", - (unsigned int)size, - GNUNET_a2s(sa, fromlen)); - GNUNET_break_op(0); - return; - } - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total bytes received", - size, - GNUNET_NO); - network_type = plugin->env->get_address_type(plugin->env->cls, sa, fromlen); + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n", + (unsigned int) size, + GNUNET_a2s (sa, fromlen)); + /* _MAY_ be a connection failure (got partial message) */ + /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ + GNUNET_break_op (0); + return; + } + + msg = (const struct GNUNET_MessageHeader *) buf; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "UDP received %u-byte message from `%s' type %u\n", + (unsigned int) size, + GNUNET_a2s (sa, fromlen), + ntohs (msg->type)); + if (size != ntohs (msg->size)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "UDP malformed message (size %u) header from %s\n", + (unsigned int) size, + GNUNET_a2s (sa, fromlen)); + GNUNET_break_op (0); + return; + } + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total bytes received", + size, + GNUNET_NO); + network_type = plugin->env->get_address_type (plugin->env->cls, sa, fromlen); switch (sa->sa_family) - { - case AF_INET: - sa4 = (const struct sockaddr_in *)&addr; - v4.options = 0; - v4.ipv4_addr = sa4->sin_addr.s_addr; - v4.u4_port = sa4->sin_port; - int_addr = (union UdpAddress *)&v4; - int_addr_len = sizeof(v4); - break; - - case AF_INET6: - sa6 = (const struct sockaddr_in6 *)&addr; - v6.options = 0; - v6.ipv6_addr = sa6->sin6_addr; - v6.u6_port = sa6->sin6_port; - int_addr = (union UdpAddress *)&v6; - int_addr_len = sizeof(v6); - break; - - default: - GNUNET_break(0); - return; - } + { + case AF_INET: + sa4 = (const struct sockaddr_in *) &addr; + v4.options = 0; + v4.ipv4_addr = sa4->sin_addr.s_addr; + v4.u4_port = sa4->sin_port; + int_addr = (union UdpAddress *) &v4; + int_addr_len = sizeof(v4); + break; + + case AF_INET6: + sa6 = (const struct sockaddr_in6 *) &addr; + v6.options = 0; + v6.ipv6_addr = sa6->sin6_addr; + v6.u6_port = sa6->sin6_port; + int_addr = (union UdpAddress *) &v6; + int_addr_len = sizeof(v6); + break; + + default: + GNUNET_break (0); + return; + } + + switch (ntohs (msg->type)) + { + case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON: + if (GNUNET_YES == plugin->enable_broadcasting_receiving) + udp_broadcast_receive (plugin, + buf, + size, + int_addr, + int_addr_len, + network_type); + return; - switch (ntohs(msg->type)) + case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: + if (ntohs (msg->size) < sizeof(struct UDPMessage)) { - case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON: - if (GNUNET_YES == plugin->enable_broadcasting_receiving) - udp_broadcast_receive(plugin, - buf, - size, - int_addr, - int_addr_len, - network_type); - return; - - case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: - if (ntohs(msg->size) < sizeof(struct UDPMessage)) - { - GNUNET_break_op(0); - return; - } - process_udp_message(plugin, - (const struct UDPMessage *)msg, - int_addr, - int_addr_len, - network_type); + GNUNET_break_op (0); return; + } + process_udp_message (plugin, + (const struct UDPMessage *) msg, + int_addr, + int_addr_len, + network_type); + return; - case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: - read_process_ack(plugin, msg, int_addr, int_addr_len); - return; + case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: + read_process_ack (plugin, msg, int_addr, int_addr_len); + return; - case GNUNET_MESSAGE_TYPE_FRAGMENT: - read_process_fragment(plugin, msg, int_addr, int_addr_len, network_type); - return; + case GNUNET_MESSAGE_TYPE_FRAGMENT: + read_process_fragment (plugin, msg, int_addr, int_addr_len, network_type); + return; - default: - GNUNET_break_op(0); - return; - } + default: + GNUNET_break_op (0); + return; + } } @@ -3055,8 +3064,8 @@ udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) * @return message selected for transmission, or NULL for none */ static struct UDP_MessageWrapper * -remove_timeout_messages_and_select(struct Plugin *plugin, - struct GNUNET_NETWORK_Handle *sock) +remove_timeout_messages_and_select (struct Plugin *plugin, + struct GNUNET_NETWORK_Handle *sock) { struct UDP_MessageWrapper *udpw; struct GNUNET_TIME_Relative remaining; @@ -3067,65 +3076,65 @@ remove_timeout_messages_and_select(struct Plugin *plugin, udpw = (sock == plugin->sockv4) ? plugin->ipv4_queue_head : plugin->ipv6_queue_head; while (NULL != udpw) - { - session = udpw->session; - /* Find messages with timeout */ - remaining = GNUNET_TIME_absolute_get_remaining(udpw->timeout); - if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) - { - /* Message timed out */ - removed = GNUNET_YES; - dequeue(plugin, udpw); - udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); - GNUNET_free(udpw); - - if (sock == plugin->sockv4) - { - udpw = plugin->ipv4_queue_head; - } - else if (sock == plugin->sockv6) - { - udpw = plugin->ipv6_queue_head; - } - else - { - GNUNET_break(0); /* should never happen */ - udpw = NULL; - } - GNUNET_STATISTICS_update(plugin->env->stats, - "# messages discarded due to timeout", - 1, - GNUNET_NO); - } + { + session = udpw->session; + /* Find messages with timeout */ + remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout); + if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) + { + /* Message timed out */ + removed = GNUNET_YES; + dequeue (plugin, udpw); + udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); + GNUNET_free (udpw); + + if (sock == plugin->sockv4) + { + udpw = plugin->ipv4_queue_head; + } + else if (sock == plugin->sockv6) + { + udpw = plugin->ipv6_queue_head; + } else - { - /* Message did not time out, check transmission time */ - remaining = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time); - if (0 == remaining.rel_value_us) - { - /* this message is not delayed */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Message for peer `%s' (%u bytes) is not delayed \n", - GNUNET_i2s(&udpw->session->target), - udpw->payload_size); - break; /* Found message to send, break */ - } - else - { - /* Message is delayed, try next */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Message for peer `%s' (%u bytes) is delayed for %s\n", - GNUNET_i2s(&udpw->session->target), - udpw->payload_size, - GNUNET_STRINGS_relative_time_to_string(remaining, GNUNET_YES)); - udpw = udpw->next; - } - } - } + { + GNUNET_break (0); /* should never happen */ + udpw = NULL; + } + GNUNET_STATISTICS_update (plugin->env->stats, + "# messages discarded due to timeout", + 1, + GNUNET_NO); + } + else + { + /* Message did not time out, check transmission time */ + remaining = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time); + if (0 == remaining.rel_value_us) + { + /* this message is not delayed */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Message for peer `%s' (%u bytes) is not delayed \n", + GNUNET_i2s (&udpw->session->target), + udpw->payload_size); + break; /* Found message to send, break */ + } + else + { + /* Message is delayed, try next */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Message for peer `%s' (%u bytes) is delayed for %s\n", + GNUNET_i2s (&udpw->session->target), + udpw->payload_size, + GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES)); + udpw = udpw->next; + } + } + } if (GNUNET_YES == removed) - notify_session_monitor(session->plugin, - session, - GNUNET_TRANSPORT_SS_UPDATE); + notify_session_monitor (session->plugin, + session, + GNUNET_TRANSPORT_SS_UPDATE); return udpw; } @@ -3140,50 +3149,50 @@ remove_timeout_messages_and_select(struct Plugin *plugin, * @param error the errno value returned from the sendto() call */ static void -analyze_send_error(struct Plugin *plugin, - const struct sockaddr *sa, - socklen_t slen, - int error) +analyze_send_error (struct Plugin *plugin, + const struct sockaddr *sa, + socklen_t slen, + int error) { enum GNUNET_NetworkType type; - type = plugin->env->get_address_type(plugin->env->cls, sa, slen); + type = plugin->env->get_address_type (plugin->env->cls, sa, slen); if (((GNUNET_NT_LAN == type) || (GNUNET_NT_WAN == type)) && ((ENETUNREACH == errno) || (ENETDOWN == errno))) - { - if (slen == sizeof(struct sockaddr_in)) - { - /* IPv4: "Network unreachable" or "Network down" - * - * This indicates we do not have connectivity - */ - LOG(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - _("UDP could not transmit message to `%s': " - "Network seems down, please check your network configuration\n"), - GNUNET_a2s(sa, slen)); - } - if (slen == sizeof(struct sockaddr_in6)) - { - /* IPv6: "Network unreachable" or "Network down" - * - * This indicates that this system is IPv6 enabled, but does not - * have a valid global IPv6 address assigned or we do not have - * connectivity - */ - LOG(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - _( - "UDP could not transmit IPv6 message! " - "Please check your network configuration and disable IPv6 if your " - "connection does not have a global IPv6 address\n")); - } - } + { + if (slen == sizeof(struct sockaddr_in)) + { + /* IPv4: "Network unreachable" or "Network down" + * + * This indicates we do not have connectivity + */ + LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, + _ ("UDP could not transmit message to `%s': " + "Network seems down, please check your network configuration\n"), + GNUNET_a2s (sa, slen)); + } + if (slen == sizeof(struct sockaddr_in6)) + { + /* IPv6: "Network unreachable" or "Network down" + * + * This indicates that this system is IPv6 enabled, but does not + * have a valid global IPv6 address assigned or we do not have + * connectivity + */ + LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, + _ ( + "UDP could not transmit IPv6 message! " + "Please check your network configuration and disable IPv6 if your " + "connection does not have a global IPv6 address\n")); + } + } else - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "UDP could not transmit message to `%s': `%s'\n", - GNUNET_a2s(sa, slen), - strerror(error)); - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "UDP could not transmit message to `%s': `%s'\n", + GNUNET_a2s (sa, slen), + strerror (error)); + } } @@ -3195,7 +3204,7 @@ analyze_send_error(struct Plugin *plugin, * @param sock which socket (v4/v6) to send on */ static void -udp_select_send(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) +udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) { ssize_t sent; socklen_t slen; @@ -3207,95 +3216,95 @@ udp_select_send(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) struct UDP_MessageWrapper *udpw; /* Find message(s) to send */ - while (NULL != (udpw = remove_timeout_messages_and_select(plugin, sock))) + while (NULL != (udpw = remove_timeout_messages_and_select (plugin, sock))) + { + if (sizeof(struct IPv4UdpAddress) == + udpw->session->address->address_length) { - if (sizeof(struct IPv4UdpAddress) == - udpw->session->address->address_length) - { - u4 = udpw->session->address->address; - memset(&a4, 0, sizeof(a4)); - a4.sin_family = AF_INET; + u4 = udpw->session->address->address; + memset (&a4, 0, sizeof(a4)); + a4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - a4.sin_len = sizeof(a4); + a4.sin_len = sizeof(a4); #endif - a4.sin_port = u4->u4_port; - a4.sin_addr.s_addr = u4->ipv4_addr; - a = (const struct sockaddr *)&a4; - slen = sizeof(a4); - } - else if (sizeof(struct IPv6UdpAddress) == - udpw->session->address->address_length) - { - u6 = udpw->session->address->address; - memset(&a6, 0, sizeof(a6)); - a6.sin6_family = AF_INET6; + a4.sin_port = u4->u4_port; + a4.sin_addr.s_addr = u4->ipv4_addr; + a = (const struct sockaddr *) &a4; + slen = sizeof(a4); + } + else if (sizeof(struct IPv6UdpAddress) == + udpw->session->address->address_length) + { + u6 = udpw->session->address->address; + memset (&a6, 0, sizeof(a6)); + a6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN - a6.sin6_len = sizeof(a6); + a6.sin6_len = sizeof(a6); #endif - a6.sin6_port = u6->u6_port; - a6.sin6_addr = u6->ipv6_addr; - a = (const struct sockaddr *)&a6; - slen = sizeof(a6); - } - else - { - GNUNET_break(0); - dequeue(plugin, udpw); - udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); - notify_session_monitor(plugin, - udpw->session, - GNUNET_TRANSPORT_SS_UPDATE); - GNUNET_free(udpw); - continue; - } - sent = GNUNET_NETWORK_socket_sendto(sock, - udpw->msg_buf, - udpw->msg_size, - a, - slen); - udpw->session->last_transmit_time = - GNUNET_TIME_absolute_max(GNUNET_TIME_absolute_get(), - udpw->session->last_transmit_time); - dequeue(plugin, udpw); - if (GNUNET_SYSERR == sent) - { - /* Failure */ - analyze_send_error(plugin, a, slen, errno); - udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total, bytes, sent, failure", - sent, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total, messages, sent, failure", - 1, - GNUNET_NO); - } - else - { - /* Success */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", - (unsigned int)(udpw->msg_size), - GNUNET_i2s(&udpw->session->target), - GNUNET_a2s(a, slen), - (int)sent, - (sent < 0) ? strerror(errno) : "ok"); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total, bytes, sent, success", - sent, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UDP, total, messages, sent, success", - 1, - GNUNET_NO); - if (NULL != udpw->frag_ctx) - udpw->frag_ctx->on_wire_size += udpw->msg_size; - udpw->qc(udpw->qc_cls, udpw, GNUNET_OK); - } - notify_session_monitor(plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE); - GNUNET_free(udpw); - } + a6.sin6_port = u6->u6_port; + a6.sin6_addr = u6->ipv6_addr; + a = (const struct sockaddr *) &a6; + slen = sizeof(a6); + } + else + { + GNUNET_break (0); + dequeue (plugin, udpw); + udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); + notify_session_monitor (plugin, + udpw->session, + GNUNET_TRANSPORT_SS_UPDATE); + GNUNET_free (udpw); + continue; + } + sent = GNUNET_NETWORK_socket_sendto (sock, + udpw->msg_buf, + udpw->msg_size, + a, + slen); + udpw->session->last_transmit_time = + GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (), + udpw->session->last_transmit_time); + dequeue (plugin, udpw); + if (GNUNET_SYSERR == sent) + { + /* Failure */ + analyze_send_error (plugin, a, slen, errno); + udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes, sent, failure", + sent, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, messages, sent, failure", + 1, + GNUNET_NO); + } + else + { + /* Success */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", + (unsigned int) (udpw->msg_size), + GNUNET_i2s (&udpw->session->target), + GNUNET_a2s (a, slen), + (int) sent, + (sent < 0) ? strerror (errno) : "ok"); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes, sent, success", + sent, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, messages, sent, success", + 1, + GNUNET_NO); + if (NULL != udpw->frag_ctx) + udpw->frag_ctx->on_wire_size += udpw->msg_size; + udpw->qc (udpw->qc_cls, udpw, GNUNET_OK); + } + notify_session_monitor (plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE); + GNUNET_free (udpw); + } } @@ -3310,7 +3319,7 @@ udp_select_send(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) * @param cls the plugin handle */ static void -udp_plugin_select_v4(void *cls) +udp_plugin_select_v4 (void *cls) { struct Plugin *plugin = cls; const struct GNUNET_SCHEDULER_TaskContext *tc; @@ -3318,12 +3327,12 @@ udp_plugin_select_v4(void *cls) plugin->select_task_v4 = NULL; if (NULL == plugin->sockv4) return; - tc = GNUNET_SCHEDULER_get_task_context(); + tc = GNUNET_SCHEDULER_get_task_context (); if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && - (GNUNET_NETWORK_fdset_isset(tc->read_ready, plugin->sockv4))) - udp_select_read(plugin, plugin->sockv4); - udp_select_send(plugin, plugin->sockv4); - schedule_select_v4(plugin); + (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4))) + udp_select_read (plugin, plugin->sockv4); + udp_select_send (plugin, plugin->sockv4); + schedule_select_v4 (plugin); } @@ -3335,7 +3344,7 @@ udp_plugin_select_v4(void *cls) * @param cls the plugin handle */ static void -udp_plugin_select_v6(void *cls) +udp_plugin_select_v6 (void *cls) { struct Plugin *plugin = cls; const struct GNUNET_SCHEDULER_TaskContext *tc; @@ -3343,13 +3352,13 @@ udp_plugin_select_v6(void *cls) plugin->select_task_v6 = NULL; if (NULL == plugin->sockv6) return; - tc = GNUNET_SCHEDULER_get_task_context(); + tc = GNUNET_SCHEDULER_get_task_context (); if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && - (GNUNET_NETWORK_fdset_isset(tc->read_ready, plugin->sockv6))) - udp_select_read(plugin, plugin->sockv6); + (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6))) + udp_select_read (plugin, plugin->sockv6); - udp_select_send(plugin, plugin->sockv6); - schedule_select_v6(plugin); + udp_select_send (plugin, plugin->sockv6); + schedule_select_v6 (plugin); } @@ -3365,9 +3374,9 @@ udp_plugin_select_v6(void *cls) * @return number of sockets that were successfully bound */ static unsigned int -setup_sockets(struct Plugin *plugin, - const struct sockaddr_in6 *bind_v6, - const struct sockaddr_in *bind_v4) +setup_sockets (struct Plugin *plugin, + const struct sockaddr_in6 *bind_v6, + const struct sockaddr_in *bind_v4) { int tries; unsigned int sockets_created = 0; @@ -3382,186 +3391,186 @@ setup_sockets(struct Plugin *plugin, /* Create IPv6 socket */ eno = EINVAL; if (GNUNET_YES == plugin->enable_ipv6) + { + plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); + if (NULL == plugin->sockv6) { - plugin->sockv6 = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_DGRAM, 0); - if (NULL == plugin->sockv6) - { - LOG(GNUNET_ERROR_TYPE_INFO, - _("Disabling IPv6 since it is not supported on this system!\n")); - plugin->enable_ipv6 = GNUNET_NO; - } - else - { - memset(&server_addrv6, 0, sizeof(struct sockaddr_in6)); -#if HAVE_SOCKADDR_IN_SIN_LEN - server_addrv6.sin6_len = sizeof(struct sockaddr_in6); -#endif - server_addrv6.sin6_family = AF_INET6; - if (NULL != bind_v6) - server_addrv6.sin6_addr = bind_v6->sin6_addr; - else - server_addrv6.sin6_addr = in6addr_any; - - if (0 == plugin->port) /* autodetect */ - server_addrv6.sin6_port = htons( - GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + - 32000); - else - server_addrv6.sin6_port = htons(plugin->port); - addrlen = sizeof(struct sockaddr_in6); - server_addr = (const struct sockaddr *)&server_addrv6; - - tries = 0; - while (tries < 10) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Binding to IPv6 `%s'\n", - GNUNET_a2s(server_addr, addrlen)); - /* binding */ - if (GNUNET_OK == - GNUNET_NETWORK_socket_bind(plugin->sockv6, server_addr, addrlen)) - break; - eno = errno; - if (0 != plugin->port) - { - tries = 10; /* fail immediately */ - break; /* bind failed on specific port */ - } - /* autodetect */ - server_addrv6.sin6_port = htons( - GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + - 32000); - tries++; - } - if (tries >= 10) - { - GNUNET_NETWORK_socket_close(plugin->sockv6); - plugin->enable_ipv6 = GNUNET_NO; - plugin->sockv6 = NULL; - } - else - { - plugin->port = ntohs(server_addrv6.sin6_port); - } - if (NULL != plugin->sockv6) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "IPv6 UDP socket created listinging at %s\n", - GNUNET_a2s(server_addr, addrlen)); - addrs[sockets_created] = server_addr; - addrlens[sockets_created] = addrlen; - sockets_created++; - } - else - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Failed to bind UDP socket to %s: %s\n"), - GNUNET_a2s(server_addr, addrlen), - strerror(eno)); - } - } - } - - /* Create IPv4 socket */ - eno = EINVAL; - plugin->sockv4 = GNUNET_NETWORK_socket_create(PF_INET, SOCK_DGRAM, 0); - if (NULL == plugin->sockv4) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "socket"); - LOG(GNUNET_ERROR_TYPE_INFO, - _("Disabling IPv4 since it is not supported on this system!\n")); - plugin->enable_ipv4 = GNUNET_NO; + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Disabling IPv6 since it is not supported on this system!\n")); + plugin->enable_ipv6 = GNUNET_NO; } - else + else { - memset(&server_addrv4, 0, sizeof(struct sockaddr_in)); + memset (&server_addrv6, 0, sizeof(struct sockaddr_in6)); #if HAVE_SOCKADDR_IN_SIN_LEN - server_addrv4.sin_len = sizeof(struct sockaddr_in); + server_addrv6.sin6_len = sizeof(struct sockaddr_in6); #endif - server_addrv4.sin_family = AF_INET; - if (NULL != bind_v4) - server_addrv4.sin_addr = bind_v4->sin_addr; + server_addrv6.sin6_family = AF_INET6; + if (NULL != bind_v6) + server_addrv6.sin6_addr = bind_v6->sin6_addr; else - server_addrv4.sin_addr.s_addr = INADDR_ANY; + server_addrv6.sin6_addr = in6addr_any; - if (0 == plugin->port) - /* autodetect */ - server_addrv4.sin_port = htons( - GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); + if (0 == plugin->port) /* autodetect */ + server_addrv6.sin6_port = htons ( + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + + 32000); else - server_addrv4.sin_port = htons(plugin->port); - - addrlen = sizeof(struct sockaddr_in); - server_addr = (const struct sockaddr *)&server_addrv4; + server_addrv6.sin6_port = htons (plugin->port); + addrlen = sizeof(struct sockaddr_in6); + server_addr = (const struct sockaddr *) &server_addrv6; tries = 0; while (tries < 10) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Binding to IPv6 `%s'\n", + GNUNET_a2s (server_addr, addrlen)); + /* binding */ + if (GNUNET_OK == + GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, addrlen)) + break; + eno = errno; + if (0 != plugin->port) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Binding to IPv4 `%s'\n", - GNUNET_a2s(server_addr, addrlen)); - - /* binding */ - if (GNUNET_OK == - GNUNET_NETWORK_socket_bind(plugin->sockv4, server_addr, addrlen)) - break; - eno = errno; - if (0 != plugin->port) - { - tries = 10; /* fail */ - break; /* bind failed on specific port */ - } - - /* autodetect */ - server_addrv4.sin_port = htons( - GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); - tries++; + tries = 10; /* fail immediately */ + break; /* bind failed on specific port */ } + /* autodetect */ + server_addrv6.sin6_port = htons ( + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + + 32000); + tries++; + } if (tries >= 10) - { - GNUNET_NETWORK_socket_close(plugin->sockv4); - plugin->enable_ipv4 = GNUNET_NO; - plugin->sockv4 = NULL; - } + { + GNUNET_NETWORK_socket_close (plugin->sockv6); + plugin->enable_ipv6 = GNUNET_NO; + plugin->sockv6 = NULL; + } else - { - plugin->port = ntohs(server_addrv4.sin_port); - } - - if (NULL != plugin->sockv4) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "IPv4 socket created on port %s\n", - GNUNET_a2s(server_addr, addrlen)); - addrs[sockets_created] = server_addr; - addrlens[sockets_created] = addrlen; - sockets_created++; - } + { + plugin->port = ntohs (server_addrv6.sin6_port); + } + if (NULL != plugin->sockv6) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "IPv6 UDP socket created listinging at %s\n", + GNUNET_a2s (server_addr, addrlen)); + addrs[sockets_created] = server_addr; + addrlens[sockets_created] = addrlen; + sockets_created++; + } else - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Failed to bind UDP socket to %s: %s\n"), - GNUNET_a2s(server_addr, addrlen), - strerror(eno)); - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("Failed to bind UDP socket to %s: %s\n"), + GNUNET_a2s (server_addr, addrlen), + strerror (eno)); + } } + } - if (0 == sockets_created) + /* Create IPv4 socket */ + eno = EINVAL; + plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); + if (NULL == plugin->sockv4) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Disabling IPv4 since it is not supported on this system!\n")); + plugin->enable_ipv4 = GNUNET_NO; + } + else + { + memset (&server_addrv4, 0, sizeof(struct sockaddr_in)); +#if HAVE_SOCKADDR_IN_SIN_LEN + server_addrv4.sin_len = sizeof(struct sockaddr_in); +#endif + server_addrv4.sin_family = AF_INET; + if (NULL != bind_v4) + server_addrv4.sin_addr = bind_v4->sin_addr; + else + server_addrv4.sin_addr.s_addr = INADDR_ANY; + + if (0 == plugin->port) + /* autodetect */ + server_addrv4.sin_port = htons ( + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); + else + server_addrv4.sin_port = htons (plugin->port); + + addrlen = sizeof(struct sockaddr_in); + server_addr = (const struct sockaddr *) &server_addrv4; + + tries = 0; + while (tries < 10) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Binding to IPv4 `%s'\n", + GNUNET_a2s (server_addr, addrlen)); + + /* binding */ + if (GNUNET_OK == + GNUNET_NETWORK_socket_bind (plugin->sockv4, server_addr, addrlen)) + break; + eno = errno; + if (0 != plugin->port) + { + tries = 10; /* fail */ + break; /* bind failed on specific port */ + } + + /* autodetect */ + server_addrv4.sin_port = htons ( + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); + tries++; + } + if (tries >= 10) + { + GNUNET_NETWORK_socket_close (plugin->sockv4); + plugin->enable_ipv4 = GNUNET_NO; + plugin->sockv4 = NULL; + } + else { - LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); - return 0; /* No sockets created, return */ + plugin->port = ntohs (server_addrv4.sin_port); } - schedule_select_v4(plugin); - schedule_select_v6(plugin); - plugin->nat = GNUNET_NAT_register(plugin->env->cfg, - "transport-udp", - IPPROTO_UDP, - sockets_created, - addrs, - addrlens, - &udp_nat_port_map_callback, - NULL, - plugin); + + if (NULL != plugin->sockv4) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "IPv4 socket created on port %s\n", + GNUNET_a2s (server_addr, addrlen)); + addrs[sockets_created] = server_addr; + addrlens[sockets_created] = addrlen; + sockets_created++; + } + else + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to bind UDP socket to %s: %s\n"), + GNUNET_a2s (server_addr, addrlen), + strerror (eno)); + } + } + + if (0 == sockets_created) + { + LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UDP sockets\n")); + return 0; /* No sockets created, return */ + } + schedule_select_v4 (plugin); + schedule_select_v6 (plugin); + plugin->nat = GNUNET_NAT_register (plugin->env->cfg, + "transport-udp", + IPPROTO_UDP, + sockets_created, + addrs, + addrlens, + &udp_nat_port_map_callback, + NULL, + plugin); return sockets_created; } @@ -3574,7 +3583,7 @@ setup_sockets(struct Plugin *plugin, * @return our `struct GNUNET_TRANSPORT_PluginFunctions` */ void * -libgnunet_plugin_transport_udp_init(void *cls) +libgnunet_plugin_transport_udp_init (void *cls) { struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; @@ -3595,128 +3604,128 @@ libgnunet_plugin_transport_udp_init(void *cls) int have_bind6; if (NULL == env->receive) - { - /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully - initialze the plugin or the API */ - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); - api->cls = NULL; - api->address_pretty_printer = &udp_plugin_address_pretty_printer; - api->address_to_string = &udp_address_to_string; - api->string_to_address = &udp_string_to_address; - return api; - } + { + /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully + initialze the plugin or the API */ + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); + api->cls = NULL; + api->address_pretty_printer = &udp_plugin_address_pretty_printer; + api->address_to_string = &udp_address_to_string; + api->string_to_address = &udp_string_to_address; + return api; + } /* Get port number: port == 0 : autodetect a port, * > 0 : use this port, not given : 2086 default */ - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, - "transport-udp", - "PORT", - &port)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, + "transport-udp", + "PORT", + &port)) port = 2086; if (port > 65535) - { - GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, - "transport-udp", - "PORT", - _("must be in [0,65535]")); - return NULL; - } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, - "transport-udp", - "ADVERTISED_PORT", - &aport)) + { + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + "transport-udp", + "PORT", + _ ("must be in [0,65535]")); + return NULL; + } + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, + "transport-udp", + "ADVERTISED_PORT", + &aport)) aport = port; if (aport > 65535) - { - GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, - "transport-udp", - "ADVERTISED_PORT", - _("must be in [0,65535]")); - return NULL; - } + { + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + "transport-udp", + "ADVERTISED_PORT", + _ ("must be in [0,65535]")); + return NULL; + } if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "nat", "DISABLEV6")) + GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6")) enable_v6 = GNUNET_NO; else enable_v6 = GNUNET_YES; have_bind4 = GNUNET_NO; - memset(&server_addrv4, 0, sizeof(server_addrv4)); - if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg, - "transport-udp", - "BINDTO", - &bind4_address)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Binding UDP plugin to specific address: `%s'\n", - bind4_address); - if (1 != inet_pton(AF_INET, bind4_address, &server_addrv4.sin_addr)) - { - GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, - "transport-udp", - "BINDTO", - _("must be valid IPv4 address")); - GNUNET_free(bind4_address); - return NULL; - } - have_bind4 = GNUNET_YES; + memset (&server_addrv4, 0, sizeof(server_addrv4)); + if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, + "transport-udp", + "BINDTO", + &bind4_address)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Binding UDP plugin to specific address: `%s'\n", + bind4_address); + if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) + { + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + "transport-udp", + "BINDTO", + _ ("must be valid IPv4 address")); + GNUNET_free (bind4_address); + return NULL; } - GNUNET_free_non_null(bind4_address); + have_bind4 = GNUNET_YES; + } + GNUNET_free_non_null (bind4_address); have_bind6 = GNUNET_NO; - memset(&server_addrv6, 0, sizeof(server_addrv6)); - if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg, - "transport-udp", - "BINDTO6", - &bind6_address)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Binding udp plugin to specific address: `%s'\n", - bind6_address); - if (1 != inet_pton(AF_INET6, bind6_address, &server_addrv6.sin6_addr)) - { - GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, - "transport-udp", - "BINDTO6", - _("must be valid IPv6 address")); - GNUNET_free(bind6_address); - return NULL; - } - have_bind6 = GNUNET_YES; + memset (&server_addrv6, 0, sizeof(server_addrv6)); + if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, + "transport-udp", + "BINDTO6", + &bind6_address)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Binding udp plugin to specific address: `%s'\n", + bind6_address); + if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) + { + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + "transport-udp", + "BINDTO6", + _ ("must be valid IPv6 address")); + GNUNET_free (bind6_address); + return NULL; } - GNUNET_free_non_null(bind6_address); + have_bind6 = GNUNET_YES; + } + GNUNET_free_non_null (bind6_address); - enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, - "transport-udp", - "BROADCAST"); + enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, + "transport-udp", + "BROADCAST"); if (enable_broadcasting == GNUNET_SYSERR) enable_broadcasting = GNUNET_NO; enable_broadcasting_recv = - GNUNET_CONFIGURATION_get_value_yesno(env->cfg, - "transport-udp", - "BROADCAST_RECEIVE"); + GNUNET_CONFIGURATION_get_value_yesno (env->cfg, + "transport-udp", + "BROADCAST_RECEIVE"); if (enable_broadcasting_recv == GNUNET_SYSERR) enable_broadcasting_recv = GNUNET_YES; if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_time(env->cfg, - "transport-udp", - "BROADCAST_INTERVAL", - &interval)) - { - interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10); - } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, - "transport-udp", - "MAX_BPS", - &udp_max_bps)) - { - /* 50 MB/s == infinity for practical purposes */ - udp_max_bps = 1024 * 1024 * 50; - } - - p = GNUNET_new(struct Plugin); + GNUNET_CONFIGURATION_get_value_time (env->cfg, + "transport-udp", + "BROADCAST_INTERVAL", + &interval)) + { + interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); + } + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, + "transport-udp", + "MAX_BPS", + &udp_max_bps)) + { + /* 50 MB/s == infinity for practical purposes */ + udp_max_bps = 1024 * 1024 * 50; + } + + p = GNUNET_new (struct Plugin); p->port = port; p->aport = aport; p->broadcast_interval = interval; @@ -3725,33 +3734,33 @@ libgnunet_plugin_transport_udp_init(void *cls) p->enable_broadcasting = enable_broadcasting; p->enable_broadcasting_receiving = enable_broadcasting_recv; p->env = env; - p->sessions = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_NO); + p->sessions = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO); p->defrag_ctxs = - GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); - GNUNET_BANDWIDTH_tracker_init(&p->tracker, - NULL, - NULL, - GNUNET_BANDWIDTH_value_init( - (uint32_t)udp_max_bps), - 30); - res = setup_sockets(p, - (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL, - (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL); + GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); + GNUNET_BANDWIDTH_tracker_init (&p->tracker, + NULL, + NULL, + GNUNET_BANDWIDTH_value_init ( + (uint32_t) udp_max_bps), + 30); + res = setup_sockets (p, + (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL, + (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL); if ((0 == res) || ((NULL == p->sockv4) && (NULL == p->sockv6))) - { - LOG(GNUNET_ERROR_TYPE_ERROR, _("Failed to create UDP network sockets\n")); - GNUNET_CONTAINER_multipeermap_destroy(p->sessions); - GNUNET_CONTAINER_heap_destroy(p->defrag_ctxs); - if (NULL != p->nat) - GNUNET_NAT_unregister(p->nat); - GNUNET_free(p); - return NULL; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Failed to create UDP network sockets\n")); + GNUNET_CONTAINER_multipeermap_destroy (p->sessions); + GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); + if (NULL != p->nat) + GNUNET_NAT_unregister (p->nat); + GNUNET_free (p); + return NULL; + } /* Setup broadcasting and receiving beacons */ - setup_broadcast(p, &server_addrv6, &server_addrv4); + setup_broadcast (p, &server_addrv6, &server_addrv4); - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = p; api->disconnect_session = &udp_disconnect_session; api->query_keepalive_factor = &udp_query_keepalive_factor; @@ -3781,16 +3790,16 @@ libgnunet_plugin_transport_udp_init(void *cls) * @return #GNUNET_YES */ static int -heap_cleanup_iterator(void *cls, - struct GNUNET_CONTAINER_HeapNode *node, - void *element, - GNUNET_CONTAINER_HeapCostType cost) +heap_cleanup_iterator (void *cls, + struct GNUNET_CONTAINER_HeapNode *node, + void *element, + GNUNET_CONTAINER_HeapCostType cost) { struct DefragContext *d_ctx = element; - GNUNET_CONTAINER_heap_remove_node(node); - GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag); - GNUNET_free(d_ctx); + GNUNET_CONTAINER_heap_remove_node (node); + GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); + GNUNET_free (d_ctx); return GNUNET_YES; } @@ -3803,7 +3812,7 @@ heap_cleanup_iterator(void *cls, * @return NULL */ void * -libgnunet_plugin_transport_udp_done(void *cls) +libgnunet_plugin_transport_udp_done (void *cls) { struct GNUNET_TRANSPORT_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; @@ -3811,77 +3820,77 @@ libgnunet_plugin_transport_udp_done(void *cls) struct UDP_MessageWrapper *udpw; if (NULL == plugin) - { - GNUNET_free(api); - return NULL; - } - stop_broadcast(plugin); + { + GNUNET_free (api); + return NULL; + } + stop_broadcast (plugin); if (NULL != plugin->select_task_v4) - { - GNUNET_SCHEDULER_cancel(plugin->select_task_v4); - plugin->select_task_v4 = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->select_task_v4); + plugin->select_task_v4 = NULL; + } if (NULL != plugin->select_task_v6) - { - GNUNET_SCHEDULER_cancel(plugin->select_task_v6); - plugin->select_task_v6 = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->select_task_v6); + plugin->select_task_v6 = NULL; + } if (NULL != plugin->sockv4) - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(plugin->sockv4)); - plugin->sockv4 = NULL; - } + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); + plugin->sockv4 = NULL; + } if (NULL != plugin->sockv6) - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(plugin->sockv6)); - plugin->sockv6 = NULL; - } + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); + plugin->sockv6 = NULL; + } if (NULL != plugin->nat) - { - GNUNET_NAT_unregister(plugin->nat); - plugin->nat = NULL; - } + { + GNUNET_NAT_unregister (plugin->nat); + plugin->nat = NULL; + } if (NULL != plugin->defrag_ctxs) - { - GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs, - &heap_cleanup_iterator, - NULL); - GNUNET_CONTAINER_heap_destroy(plugin->defrag_ctxs); - plugin->defrag_ctxs = NULL; - } + { + GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, + &heap_cleanup_iterator, + NULL); + GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); + plugin->defrag_ctxs = NULL; + } while (NULL != (udpw = plugin->ipv4_queue_head)) - { - dequeue(plugin, udpw); - udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); - GNUNET_free(udpw); - } + { + dequeue (plugin, udpw); + udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); + GNUNET_free (udpw); + } while (NULL != (udpw = plugin->ipv6_queue_head)) - { - dequeue(plugin, udpw); - udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); - GNUNET_free(udpw); - } - GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, - &disconnect_and_free_it, - plugin); - GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions); + { + dequeue (plugin, udpw); + udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); + GNUNET_free (udpw); + } + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, + &disconnect_and_free_it, + plugin); + GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); while (NULL != (cur = plugin->ppc_dll_head)) - { - GNUNET_break(0); - GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head, - plugin->ppc_dll_tail, - cur); - GNUNET_RESOLVER_request_cancel(cur->resolver_handle); - if (NULL != cur->timeout_task) - { - GNUNET_SCHEDULER_cancel(cur->timeout_task); - cur->timeout_task = NULL; - } - GNUNET_free(cur); - } - GNUNET_free(plugin); - GNUNET_free(api); + { + GNUNET_break (0); + GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, + plugin->ppc_dll_tail, + cur); + GNUNET_RESOLVER_request_cancel (cur->resolver_handle); + if (NULL != cur->timeout_task) + { + GNUNET_SCHEDULER_cancel (cur->timeout_task); + cur->timeout_task = NULL; + } + GNUNET_free (cur); + } + GNUNET_free (plugin); + GNUNET_free (api); return NULL; } diff --git a/src/transport/plugin_transport_udp.h b/src/transport/plugin_transport_udp.h index 6bdc020ff..7192da885 100644 --- a/src/transport/plugin_transport_udp.h +++ b/src/transport/plugin_transport_udp.h @@ -41,7 +41,7 @@ #include "gnunet_transport_plugin.h" #include "transport.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-udp", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__) #define PLUGIN_NAME "udp" @@ -60,7 +60,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Network format for IPv4 addresses. */ -struct IPv4UdpAddress { +struct IPv4UdpAddress +{ /** * Optional options and flags for this address */ @@ -81,7 +82,8 @@ struct IPv4UdpAddress { /** * Network format for IPv6 addresses. */ -struct IPv6UdpAddress { +struct IPv6UdpAddress +{ /** * Optional options and flags for this address */ @@ -103,7 +105,8 @@ GNUNET_NETWORK_STRUCT_END * Either an IPv4 or IPv6 UDP address. Note that without a "length", * one cannot tell which one of the two types this address represents. */ -union UdpAddress { +union UdpAddress +{ /** * IPv4 case. */ @@ -131,7 +134,8 @@ struct PrettyPrinterContext; /** * Encapsulation of all of the state of the plugin. */ -struct Plugin { +struct Plugin +{ /** * Our environment. */ @@ -312,9 +316,9 @@ struct Plugin { * @return string representing the same address */ const char * -udp_address_to_string(void *cls, - const void *addr, - size_t addrlen); +udp_address_to_string (void *cls, + const void *addr, + size_t addrlen); /** @@ -329,22 +333,22 @@ udp_address_to_string(void *cls, * @param network_type network type of the sender's address */ void -udp_broadcast_receive(struct Plugin *plugin, - const char *buf, - ssize_t size, - const union UdpAddress *udp_addr, - size_t udp_addr_len, - enum GNUNET_NetworkType network_type); +udp_broadcast_receive (struct Plugin *plugin, + const char *buf, + ssize_t size, + const union UdpAddress *udp_addr, + size_t udp_addr_len, + enum GNUNET_NetworkType network_type); void -setup_broadcast(struct Plugin *plugin, - struct sockaddr_in6 *server_addrv6, - struct sockaddr_in *server_addrv4); +setup_broadcast (struct Plugin *plugin, + struct sockaddr_in6 *server_addrv6, + struct sockaddr_in *server_addrv4); void -stop_broadcast(struct Plugin *plugin); +stop_broadcast (struct Plugin *plugin); /*#ifndef PLUGIN_TRANSPORT_UDP_H*/ #endif diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c index 470c03af8..d8fdfe886 100644 --- a/src/transport/plugin_transport_udp_broadcasting.c +++ b/src/transport/plugin_transport_udp_broadcasting.c @@ -38,7 +38,7 @@ #include "gnunet_transport_plugin.h" #include "transport.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-udp", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__) /* *********** Cryogenic ********** */ #if LINUX @@ -50,9 +50,10 @@ #include #define PM_MAGIC 'k' -#define PM_SET_DELAY_AND_TIMEOUT _IOW(PM_MAGIC, 1, struct pm_times) +#define PM_SET_DELAY_AND_TIMEOUT _IOW (PM_MAGIC, 1, struct pm_times) -struct pm_times { +struct pm_times +{ unsigned long delay_msecs; unsigned long timeout_msecs; }; @@ -60,7 +61,8 @@ struct pm_times { /************************************/ -struct UDP_Beacon_Message { +struct UDP_Beacon_Message +{ /** * Message header. */ @@ -73,7 +75,8 @@ struct UDP_Beacon_Message { }; -struct BroadcastAddress { +struct BroadcastAddress +{ struct BroadcastAddress *next; struct BroadcastAddress *prev; @@ -81,7 +84,7 @@ struct BroadcastAddress { /** * ID of select broadcast task */ - struct GNUNET_SCHEDULER_Task * broadcast_task; + struct GNUNET_SCHEDULER_Task *broadcast_task; struct Plugin *plugin; @@ -106,7 +109,8 @@ struct BroadcastAddress { /** * Client-specific context for #broadcast_mst_cb(). */ -struct MstContext { +struct MstContext +{ struct Plugin *plugin; const union UdpAddress *udp_addr; @@ -129,8 +133,8 @@ struct MstContext { * @return #GNUNET_OK (always) */ static int -broadcast_mst_cb(void *cls, - const struct GNUNET_MessageHeader *message) +broadcast_mst_cb (void *cls, + const struct GNUNET_MessageHeader *message) { struct MstContext *mc = cls; struct Plugin *plugin = mc->plugin; @@ -138,32 +142,32 @@ broadcast_mst_cb(void *cls, const struct GNUNET_MessageHeader *hello; const struct UDP_Beacon_Message *msg; - msg = (const struct UDP_Beacon_Message *)message; + msg = (const struct UDP_Beacon_Message *) message; if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON != - ntohs(msg->header.type)) + ntohs (msg->header.type)) return GNUNET_OK; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received beacon with %u bytes from peer `%s' via address `%s'\n", - ntohs(msg->header.size), - GNUNET_i2s(&msg->sender), - udp_address_to_string(NULL, - mc->udp_addr, - mc->udp_addr_len)); - hello = (struct GNUNET_MessageHeader *)&msg[1]; - address = GNUNET_HELLO_address_allocate(&msg->sender, - PLUGIN_NAME, - mc->udp_addr, - mc->udp_addr_len, - GNUNET_HELLO_ADDRESS_INFO_NONE); - plugin->env->receive(plugin->env->cls, - address, - NULL, - hello); - GNUNET_HELLO_address_free(address); - GNUNET_STATISTICS_update(plugin->env->stats, - _("# Multicast HELLO beacons received via UDP"), - 1, GNUNET_NO); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received beacon with %u bytes from peer `%s' via address `%s'\n", + ntohs (msg->header.size), + GNUNET_i2s (&msg->sender), + udp_address_to_string (NULL, + mc->udp_addr, + mc->udp_addr_len)); + hello = (struct GNUNET_MessageHeader *) &msg[1]; + address = GNUNET_HELLO_address_allocate (&msg->sender, + PLUGIN_NAME, + mc->udp_addr, + mc->udp_addr_len, + GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->receive (plugin->env->cls, + address, + NULL, + hello); + GNUNET_HELLO_address_free (address); + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# Multicast HELLO beacons received via UDP"), + 1, GNUNET_NO); return GNUNET_OK; } @@ -180,59 +184,59 @@ broadcast_mst_cb(void *cls, * @param network_type network type of the sender's address */ void -udp_broadcast_receive(struct Plugin *plugin, - const char *buf, - ssize_t size, - const union UdpAddress *udp_addr, - size_t udp_addr_len, - enum GNUNET_NetworkType network_type) +udp_broadcast_receive (struct Plugin *plugin, + const char *buf, + ssize_t size, + const union UdpAddress *udp_addr, + size_t udp_addr_len, + enum GNUNET_NetworkType network_type) { struct GNUNET_MessageStreamTokenizer *broadcast_mst; struct MstContext mc; - broadcast_mst = GNUNET_MST_create(&broadcast_mst_cb, - &mc); + broadcast_mst = GNUNET_MST_create (&broadcast_mst_cb, + &mc); mc.plugin = plugin; mc.udp_addr = udp_addr; mc.udp_addr_len = udp_addr_len; mc.ats_address_network_type = network_type; - GNUNET_MST_from_buffer(broadcast_mst, - buf, size, - GNUNET_NO, - GNUNET_NO); - GNUNET_MST_destroy(broadcast_mst); + GNUNET_MST_from_buffer (broadcast_mst, + buf, size, + GNUNET_NO, + GNUNET_NO); + GNUNET_MST_destroy (broadcast_mst); } static unsigned int -prepare_beacon(struct Plugin *plugin, - struct UDP_Beacon_Message *msg) +prepare_beacon (struct Plugin *plugin, + struct UDP_Beacon_Message *msg) { uint16_t hello_size; uint16_t msg_size; const struct GNUNET_MessageHeader *hello; - hello = plugin->env->get_our_hello(); + hello = plugin->env->get_our_hello (); if (NULL == hello) return 0; - hello_size = GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)hello); + hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); msg_size = hello_size + sizeof(struct UDP_Beacon_Message); - if (hello_size < (sizeof(struct GNUNET_MessageHeader)) || + if ((hello_size < (sizeof(struct GNUNET_MessageHeader)))|| (msg_size > (UDP_MTU))) return 0; msg->sender = *(plugin->env->my_identity); - msg->header.size = htons(msg_size); - msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON); - GNUNET_memcpy(&msg[1], hello, hello_size); + msg->header.size = htons (msg_size); + msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON); + GNUNET_memcpy (&msg[1], hello, hello_size); return msg_size; } static void -udp_ipv4_broadcast_send(void *cls) +udp_ipv4_broadcast_send (void *cls) { struct BroadcastAddress *baddr = cls; struct Plugin *plugin = baddr->plugin; @@ -242,82 +246,84 @@ udp_ipv4_broadcast_send(void *cls) baddr->broadcast_task = NULL; - msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *)&buf); + msg_size = prepare_beacon (plugin, (struct UDP_Beacon_Message *) &buf); if (0 != msg_size) + { + struct sockaddr_in *addr = (struct sockaddr_in *) baddr->addr; + + addr->sin_port = htons (plugin->port); + sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4, &buf, msg_size, + (const struct sockaddr *) addr, + baddr->addrlen); + if (sent == GNUNET_SYSERR) { - struct sockaddr_in *addr = (struct sockaddr_in *)baddr->addr; - - addr->sin_port = htons(plugin->port); - sent = GNUNET_NETWORK_socket_sendto(plugin->sockv4, &buf, msg_size, - (const struct sockaddr *)addr, - baddr->addrlen); - if (sent == GNUNET_SYSERR) - { - if ((ENETUNREACH == errno) || (ENETDOWN == errno)) - { - /* "Network unreachable" or "Network down" - * - * This indicates that we just do not have network connectivity - */ - GNUNET_log(GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING, - "Network connectivity is down, cannot send beacon!\n"); - } - else - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "sendto"); - } + if ((ENETUNREACH == errno) || (ENETDOWN == errno)) + { + /* "Network unreachable" or "Network down" + * + * This indicates that we just do not have network connectivity + */ + GNUNET_log (GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING, + "Network connectivity is down, cannot send beacon!\n"); + } else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent, - GNUNET_a2s(baddr->addr, baddr->addrlen)); - } + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); + } + else + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent, + GNUNET_a2s (baddr->addr, baddr->addrlen)); } + } #if LINUX /* * Cryogenic */ if (NULL != baddr->cryogenic_fd) + { + baddr->cryogenic_times.delay_msecs = + (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5; + baddr->cryogenic_times.timeout_msecs = + (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5; + + if (ioctl (baddr->cryogenic_fd->fd, + PM_SET_DELAY_AND_TIMEOUT, + &baddr->cryogenic_times) < 0) { - baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5; - baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5; - - if (ioctl(baddr->cryogenic_fd->fd, - PM_SET_DELAY_AND_TIMEOUT, - &baddr->cryogenic_times) < 0) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "ioctl"); - baddr->broadcast_task = - GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, - &udp_ipv4_broadcast_send, baddr); - } - else - GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, - baddr->cryogenic_fd, - &udp_ipv4_broadcast_send, - baddr); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl"); + baddr->broadcast_task = + GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, + &udp_ipv4_broadcast_send, baddr); } + else + GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, + baddr->cryogenic_fd, + &udp_ipv4_broadcast_send, + baddr); + } else #endif baddr->broadcast_task = - GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, - &udp_ipv4_broadcast_send, baddr); + GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, + &udp_ipv4_broadcast_send, baddr); } static void -udp_ipv6_broadcast_send(void *cls) +udp_ipv6_broadcast_send (void *cls) { struct BroadcastAddress *baddr = cls; struct Plugin *plugin = baddr->plugin; ssize_t sent; uint16_t msg_size; char buf[65536] GNUNET_ALIGN; - const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *)baddr->addr; + const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) baddr->addr; baddr->broadcast_task = NULL; - msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *)&buf); + msg_size = prepare_beacon (plugin, (struct UDP_Beacon_Message *) &buf); /* Note: unclear if this actually works to limit the multicast to the specified interface as we're not (necessarily) using a link-local multicast group and the kernel suggests that the @@ -327,63 +333,65 @@ udp_ipv6_broadcast_send(void *cls) in that case, we might want to revert to only doing this once, and not per interface (hard to test...) */ plugin->ipv6_multicast_address.sin6_scope_id = s6->sin6_scope_id; - sent = GNUNET_NETWORK_socket_sendto(plugin->sockv6, &buf, msg_size, - (const struct sockaddr *) - &plugin->ipv6_multicast_address, - sizeof(struct sockaddr_in6)); + sent = GNUNET_NETWORK_socket_sendto (plugin->sockv6, &buf, msg_size, + (const struct sockaddr *) + &plugin->ipv6_multicast_address, + sizeof(struct sockaddr_in6)); plugin->ipv6_multicast_address.sin6_scope_id = 0; if (sent == GNUNET_SYSERR) + { + if ((ENETUNREACH == errno) || (ENETDOWN == errno)) { - if ((ENETUNREACH == errno) || (ENETDOWN == errno)) - { - /* "Network unreachable" or "Network down" - * - * This indicates that this system is IPv6 enabled, but does not - * have a valid global IPv6 address assigned - */ - GNUNET_log(GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING, - "Network connectivity is down, cannot send beacon!\n"); - } - else - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "sendto"); + /* "Network unreachable" or "Network down" + * + * This indicates that this system is IPv6 enabled, but does not + * have a valid global IPv6 address assigned + */ + GNUNET_log (GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING, + "Network connectivity is down, cannot send beacon!\n"); } + else + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); + } else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sending IPv6 HELLO beacon broadcast with %d bytes to address %s\n", - (int)sent, - GNUNET_a2s((const struct sockaddr *)&plugin->ipv6_multicast_address, + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending IPv6 HELLO beacon broadcast with %d bytes to address %s\n", + (int) sent, + GNUNET_a2s ((const struct sockaddr *) &plugin->ipv6_multicast_address, sizeof(struct sockaddr_in6))); - } + } #if LINUX /* * Cryogenic */ if (NULL != baddr->cryogenic_fd) + { + baddr->cryogenic_times.delay_msecs = + (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5; + baddr->cryogenic_times.timeout_msecs = + (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5; + + if (ioctl (baddr->cryogenic_fd->fd, + PM_SET_DELAY_AND_TIMEOUT, + &baddr->cryogenic_times) < 0) { - baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5; - baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5; - - if (ioctl(baddr->cryogenic_fd->fd, - PM_SET_DELAY_AND_TIMEOUT, - &baddr->cryogenic_times) < 0) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "ioctl"); - baddr->broadcast_task = - GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, - &udp_ipv6_broadcast_send, baddr); - } - else - GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, - baddr->cryogenic_fd, - &udp_ipv6_broadcast_send, - baddr); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl"); + baddr->broadcast_task = + GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, + &udp_ipv6_broadcast_send, baddr); } + else + GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, + baddr->cryogenic_fd, + &udp_ipv6_broadcast_send, + baddr); + } else #endif baddr->broadcast_task = - GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, - &udp_ipv6_broadcast_send, baddr); + GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, + &udp_ipv6_broadcast_send, baddr); } @@ -400,12 +408,12 @@ udp_ipv6_broadcast_send(void *cls) * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort */ static int -iface_proc(void *cls, - const char *name, - int isDefault, - const struct sockaddr *addr, - const struct sockaddr *broadcast_addr, - const struct sockaddr *netmask, socklen_t addrlen) +iface_proc (void *cls, + const char *name, + int isDefault, + const struct sockaddr *addr, + const struct sockaddr *broadcast_addr, + const struct sockaddr *netmask, socklen_t addrlen) { struct Plugin *plugin = cls; struct BroadcastAddress *ba; @@ -413,113 +421,115 @@ iface_proc(void *cls, if (NULL == addr) return GNUNET_OK; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "address %s for interface %s %p\n ", - GNUNET_a2s(addr, addrlen), name, addr); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "address %s for interface %s %p\n ", + GNUNET_a2s (addr, addrlen), name, addr); if (NULL == broadcast_addr) return GNUNET_OK; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "broadcast address %s for interface %s %p\n ", - GNUNET_a2s(broadcast_addr, addrlen), name, broadcast_addr); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "netmask %s for interface %s %p\n ", - GNUNET_a2s(netmask, addrlen), name, netmask); - - network = plugin->env->get_address_type(plugin->env->cls, broadcast_addr, addrlen); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "broadcast address %s for interface %s %p\n ", + GNUNET_a2s (broadcast_addr, addrlen), name, broadcast_addr); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "netmask %s for interface %s %p\n ", + GNUNET_a2s (netmask, addrlen), name, netmask); + + network = plugin->env->get_address_type (plugin->env->cls, broadcast_addr, + addrlen); if (GNUNET_NT_LOOPBACK == network) - { - /* Broadcasting on loopback does not make sense */ - return GNUNET_YES; - } + { + /* Broadcasting on loopback does not make sense */ + return GNUNET_YES; + } - ba = GNUNET_new(struct BroadcastAddress); + ba = GNUNET_new (struct BroadcastAddress); ba->plugin = plugin; - ba->addr = GNUNET_malloc(addrlen); - GNUNET_memcpy(ba->addr, broadcast_addr, addrlen); + ba->addr = GNUNET_malloc (addrlen); + GNUNET_memcpy (ba->addr, broadcast_addr, addrlen); ba->addrlen = addrlen; if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4) && (addrlen == sizeof(struct sockaddr_in))) - { + { #if LINUX - /* - * setup Cryogenic FD for ipv4 broadcasting - */ - char *filename; - - GNUNET_asprintf(&filename, - "/dev/cryogenic/%s", - name); - if (0 == access(name, R_OK)) - { - ba->cryogenic_fd = - GNUNET_DISK_file_open(filename, - GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_NONE); - } - GNUNET_free(filename); -#endif - ba->broadcast_task = - GNUNET_SCHEDULER_add_now(&udp_ipv4_broadcast_send, ba); + /* + * setup Cryogenic FD for ipv4 broadcasting + */ + char *filename; + + GNUNET_asprintf (&filename, + "/dev/cryogenic/%s", + name); + if (0 == access (name, R_OK)) + { + ba->cryogenic_fd = + GNUNET_DISK_file_open (filename, + GNUNET_DISK_OPEN_WRITE, + GNUNET_DISK_PERM_NONE); } + GNUNET_free (filename); +#endif + ba->broadcast_task = + GNUNET_SCHEDULER_add_now (&udp_ipv4_broadcast_send, ba); + } if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6) && (addrlen == sizeof(struct sockaddr_in6))) + { + /* Create IPv6 multicast request */ + struct ipv6_mreq multicastRequest; + const struct sockaddr_in6 *s6 = (const struct + sockaddr_in6 *) broadcast_addr; + + multicastRequest.ipv6mr_multiaddr = + plugin->ipv6_multicast_address.sin6_addr; + /* http://tools.ietf.org/html/rfc2553#section-5.2: + * + * IPV6_JOIN_GROUP + * + * Join a multicast group on a specified local interface. If the + * interface index is specified as 0, the kernel chooses the local + * interface. For example, some kernels look up the multicast + * group in the normal IPv6 routing table and using the resulting + * interface; we do this for each interface, so no need to use + * zero (anymore...). + */ + multicastRequest.ipv6mr_interface = s6->sin6_scope_id; + + /* Join the multicast group */ + if (GNUNET_OK != + GNUNET_NETWORK_socket_setsockopt + (plugin->sockv6, IPPROTO_IPV6, IPV6_JOIN_GROUP, + &multicastRequest, sizeof(multicastRequest))) { - /* Create IPv6 multicast request */ - struct ipv6_mreq multicastRequest; - const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *)broadcast_addr; - - multicastRequest.ipv6mr_multiaddr = - plugin->ipv6_multicast_address.sin6_addr; - /* http://tools.ietf.org/html/rfc2553#section-5.2: - * - * IPV6_JOIN_GROUP - * - * Join a multicast group on a specified local interface. If the - * interface index is specified as 0, the kernel chooses the local - * interface. For example, some kernels look up the multicast - * group in the normal IPv6 routing table and using the resulting - * interface; we do this for each interface, so no need to use - * zero (anymore...). + LOG (GNUNET_ERROR_TYPE_WARNING, + "Failed to join IPv6 multicast group: IPv6 broadcasting not running\n"); + } + else + { +#if LINUX + /* + * setup Cryogenic FD for ipv6 broadcasting */ - multicastRequest.ipv6mr_interface = s6->sin6_scope_id; + char *filename; - /* Join the multicast group */ - if (GNUNET_OK != - GNUNET_NETWORK_socket_setsockopt - (plugin->sockv6, IPPROTO_IPV6, IPV6_JOIN_GROUP, - &multicastRequest, sizeof(multicastRequest))) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Failed to join IPv6 multicast group: IPv6 broadcasting not running\n"); - } - else - { -#if LINUX - /* - * setup Cryogenic FD for ipv6 broadcasting - */ - char *filename; - - GNUNET_asprintf(&filename, - "/dev/cryogenic/%s", - name); - if (0 == access(name, R_OK)) - { - ba->cryogenic_fd = - GNUNET_DISK_file_open(filename, - GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_NONE); - } - GNUNET_free(filename); + GNUNET_asprintf (&filename, + "/dev/cryogenic/%s", + name); + if (0 == access (name, R_OK)) + { + ba->cryogenic_fd = + GNUNET_DISK_file_open (filename, + GNUNET_DISK_OPEN_WRITE, + GNUNET_DISK_PERM_NONE); + } + GNUNET_free (filename); #endif - ba->broadcast_task = - GNUNET_SCHEDULER_add_now(&udp_ipv6_broadcast_send, ba); - } + ba->broadcast_task = + GNUNET_SCHEDULER_add_now (&udp_ipv6_broadcast_send, ba); } - GNUNET_CONTAINER_DLL_insert(plugin->broadcast_head, - plugin->broadcast_tail, ba); + } + GNUNET_CONTAINER_DLL_insert (plugin->broadcast_head, + plugin->broadcast_tail, ba); return GNUNET_OK; } @@ -532,48 +542,50 @@ iface_proc(void *cls, * @param server_addrv4 */ void -setup_broadcast(struct Plugin *plugin, - struct sockaddr_in6 *server_addrv6, - struct sockaddr_in *server_addrv4) +setup_broadcast (struct Plugin *plugin, + struct sockaddr_in6 *server_addrv6, + struct sockaddr_in *server_addrv4) { if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, - "topology", - "FRIENDS-ONLY")) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Disabling HELLO broadcasting due to friend-to-friend only configuration!\n")); - return; - } + GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, + "topology", + "FRIENDS-ONLY")) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ( + "Disabling HELLO broadcasting due to friend-to-friend only configuration!\n")); + return; + } if (GNUNET_YES != plugin->enable_broadcasting) return; /* We do not send, just receive */ /* create IPv4 broadcast socket */ if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4)) - { - static int yes = 1; + { + static int yes = 1; - if (GNUNET_NETWORK_socket_setsockopt - (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes, - sizeof(int)) != GNUNET_OK) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"), - ntohs(server_addrv4->sin_port)); - } + if (GNUNET_NETWORK_socket_setsockopt + (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes, + sizeof(int)) != GNUNET_OK) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ( + "Failed to set IPv4 broadcast option for broadcast socket on port %d\n"), + ntohs (server_addrv4->sin_port)); } + } /* create IPv6 multicast socket */ if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL)) - { - memset(&plugin->ipv6_multicast_address, 0, sizeof(struct sockaddr_in6)); - GNUNET_assert(1 == - inet_pton(AF_INET6, "FF05::13B", + { + memset (&plugin->ipv6_multicast_address, 0, sizeof(struct sockaddr_in6)); + GNUNET_assert (1 == + inet_pton (AF_INET6, "FF05::13B", &plugin->ipv6_multicast_address.sin6_addr)); - plugin->ipv6_multicast_address.sin6_family = AF_INET6; - plugin->ipv6_multicast_address.sin6_port = htons(plugin->port); - } - GNUNET_OS_network_interfaces_list(&iface_proc, plugin); + plugin->ipv6_multicast_address.sin6_family = AF_INET6; + plugin->ipv6_multicast_address.sin6_port = htons (plugin->port); + } + GNUNET_OS_network_interfaces_list (&iface_proc, plugin); } @@ -583,55 +595,55 @@ setup_broadcast(struct Plugin *plugin, * @param plugin */ void -stop_broadcast(struct Plugin *plugin) +stop_broadcast (struct Plugin *plugin) { if (GNUNET_YES == plugin->enable_broadcasting) + { + /* Disable broadcasting */ + while (plugin->broadcast_head != NULL) { - /* Disable broadcasting */ - while (plugin->broadcast_head != NULL) + struct BroadcastAddress *p = plugin->broadcast_head; + + if (p->broadcast_task != NULL) + { + GNUNET_SCHEDULER_cancel (p->broadcast_task); + p->broadcast_task = NULL; + } + if ((GNUNET_YES == plugin->enable_ipv6) && + (NULL != plugin->sockv6) && + (p->addrlen == sizeof(struct sockaddr_in6))) + { + /* Create IPv6 multicast request */ + struct ipv6_mreq multicastRequest; + const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) p->addr; + + multicastRequest.ipv6mr_multiaddr = + plugin->ipv6_multicast_address.sin6_addr; + multicastRequest.ipv6mr_interface = s6->sin6_scope_id; + + /* Leave the multicast group */ + if (GNUNET_OK == + GNUNET_NETWORK_socket_setsockopt + (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP, + &multicastRequest, sizeof(multicastRequest))) { - struct BroadcastAddress *p = plugin->broadcast_head; - - if (p->broadcast_task != NULL) - { - GNUNET_SCHEDULER_cancel(p->broadcast_task); - p->broadcast_task = NULL; - } - if ((GNUNET_YES == plugin->enable_ipv6) && - (NULL != plugin->sockv6) && - (p->addrlen == sizeof(struct sockaddr_in6))) - { - /* Create IPv6 multicast request */ - struct ipv6_mreq multicastRequest; - const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *)p->addr; - - multicastRequest.ipv6mr_multiaddr = - plugin->ipv6_multicast_address.sin6_addr; - multicastRequest.ipv6mr_interface = s6->sin6_scope_id; - - /* Leave the multicast group */ - if (GNUNET_OK == - GNUNET_NETWORK_socket_setsockopt - (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP, - &multicastRequest, sizeof(multicastRequest))) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt"); - } - else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n"); - } - } + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt"); + } + else + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n"); + } + } #if LINUX - GNUNET_DISK_file_close(p->cryogenic_fd); + GNUNET_DISK_file_close (p->cryogenic_fd); #endif - GNUNET_CONTAINER_DLL_remove(plugin->broadcast_head, - plugin->broadcast_tail, p); - GNUNET_free(p->addr); - GNUNET_free(p); - } + GNUNET_CONTAINER_DLL_remove (plugin->broadcast_head, + plugin->broadcast_tail, p); + GNUNET_free (p->addr); + GNUNET_free (p); } + } } /* end of plugin_transport_udp_broadcasting.c */ diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 5f7b38479..42d16f131 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -51,7 +51,8 @@ /** * Options for UNIX Domain addresses. */ -enum UNIX_ADDRESS_OPTIONS { +enum UNIX_ADDRESS_OPTIONS +{ /** * No special options. */ @@ -68,9 +69,9 @@ enum UNIX_ADDRESS_OPTIONS { * How long until we give up on transmitting the welcome message? */ #define HOSTNAME_RESOLVE_TIMEOUT \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-unix", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-unix", __VA_ARGS__) GNUNET_NETWORK_STRUCT_BEGIN @@ -78,7 +79,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Binary format for an UNIX Domain Socket address in GNUnet. */ -struct UnixAddress { +struct UnixAddress +{ /** * Options to use for the address, in NBO */ @@ -96,7 +98,8 @@ struct UnixAddress { /** * UNIX Message-Packet header. */ -struct UNIXMessage { +struct UNIXMessage +{ /** * Message header. */ @@ -114,7 +117,8 @@ GNUNET_NETWORK_STRUCT_END /** * Information we track for a message awaiting transmission. */ -struct UNIXMessageWrapper { +struct UNIXMessageWrapper +{ /** * We keep messages in a doubly linked list. */ @@ -170,7 +174,8 @@ struct UNIXMessageWrapper { /** * Handle for a session. */ -struct GNUNET_ATS_Session { +struct GNUNET_ATS_Session +{ /** * Sessions with pending messages (!) are kept in a DLL. */ @@ -230,7 +235,8 @@ struct Plugin; /** * Information we keep for each of our listen sockets. */ -struct UNIX_Sock_Info { +struct UNIX_Sock_Info +{ /** * The network handle */ @@ -241,7 +247,8 @@ struct UNIX_Sock_Info { /** * Encapsulation of all of the state of the plugin. */ -struct Plugin { +struct Plugin +{ /** * ID of task used to update our addresses when one expires. */ @@ -323,15 +330,15 @@ struct Plugin { * @param state new state of the session */ static void -notify_session_monitor(struct Plugin *plugin, - struct GNUNET_ATS_Session *session, - enum GNUNET_TRANSPORT_SessionState state) +notify_session_monitor (struct Plugin *plugin, + struct GNUNET_ATS_Session *session, + enum GNUNET_TRANSPORT_SessionState state) { struct GNUNET_TRANSPORT_SessionInfo info; if (NULL == plugin->sic) return; - memset(&info, 0, sizeof(info)); + memset (&info, 0, sizeof(info)); info.state = state; info.is_inbound = GNUNET_SYSERR; /* hard to say */ info.num_msg_pending = session->msgs_in_queue; @@ -341,7 +348,7 @@ notify_session_monitor(struct Plugin *plugin, to receive from others) */ info.session_timeout = session->timeout; info.address = session->address; - plugin->sic(plugin->sic_cls, session, &info); + plugin->sic (plugin->sic_cls, session, &info); } @@ -357,50 +364,50 @@ notify_session_monitor(struct Plugin *plugin, * @return string representing the same address */ static const char * -unix_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) +unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) { static char rbuf[1024]; - struct UnixAddress *ua = (struct UnixAddress *)addr; + struct UnixAddress *ua = (struct UnixAddress *) addr; char *addrstr; size_t addr_str_len; unsigned int off; if ((NULL == addr) || (sizeof(struct UnixAddress) > addrlen)) - { - GNUNET_break(0); - return NULL; - } - addrstr = (char *)&ua[1]; - addr_str_len = ntohl(ua->addrlen); + { + GNUNET_break (0); + return NULL; + } + addrstr = (char *) &ua[1]; + addr_str_len = ntohl (ua->addrlen); if (addr_str_len != addrlen - sizeof(struct UnixAddress)) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } if ('\0' != addrstr[addr_str_len - 1]) - { - GNUNET_break(0); - return NULL; - } - if (strlen(addrstr) + 1 != addr_str_len) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } + if (strlen (addrstr) + 1 != addr_str_len) + { + GNUNET_break (0); + return NULL; + } off = 0; if ('\0' == addrstr[0]) off++; - memset(rbuf, 0, sizeof(rbuf)); - GNUNET_snprintf(rbuf, - sizeof(rbuf) - 1, - "%s.%u.%s%.*s", - PLUGIN_NAME, - ntohl(ua->options), - (off == 1) ? "@" : "", - (int)(addr_str_len - off), - &addrstr[off]); + memset (rbuf, 0, sizeof(rbuf)); + GNUNET_snprintf (rbuf, + sizeof(rbuf) - 1, + "%s.%u.%s%.*s", + PLUGIN_NAME, + ntohl (ua->options), + (off == 1) ? "@" : "", + (int) (addr_str_len - off), + &addrstr[off]); return rbuf; } @@ -415,61 +422,61 @@ unix_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) * @return #GNUNET_OK on success */ static int -unix_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *session) +unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session) { struct Plugin *plugin = cls; struct UNIXMessageWrapper *msgw; struct UNIXMessageWrapper *next; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting session for peer `%s' `%s'\n", - GNUNET_i2s(&session->target), - unix_plugin_address_to_string(NULL, - session->address->address, - session->address->address_length)); - plugin->env->session_end(plugin->env->cls, session->address, session); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Disconnecting session for peer `%s' `%s'\n", + GNUNET_i2s (&session->target), + unix_plugin_address_to_string (NULL, + session->address->address, + session->address->address_length)); + plugin->env->session_end (plugin->env->cls, session->address, session); next = plugin->msg_head; while (NULL != next) - { - msgw = next; - next = msgw->next; - if (msgw->session != session) - continue; - GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); - session->msgs_in_queue--; - GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); - session->bytes_in_queue -= msgw->msgsize; - GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); - plugin->bytes_in_queue -= msgw->msgsize; - if (NULL != msgw->cont) - msgw->cont(msgw->cont_cls, - &msgw->session->target, - GNUNET_SYSERR, - msgw->payload, - 0); - GNUNET_free(msgw->msg); - GNUNET_free(msgw); - } - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(plugin->session_map, - &session->target, - session)); - GNUNET_STATISTICS_set(plugin->env->stats, - "# UNIX sessions active", - GNUNET_CONTAINER_multipeermap_size( - plugin->session_map), - GNUNET_NO); + { + msgw = next; + next = msgw->next; + if (msgw->session != session) + continue; + GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); + session->msgs_in_queue--; + GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); + session->bytes_in_queue -= msgw->msgsize; + GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); + plugin->bytes_in_queue -= msgw->msgsize; + if (NULL != msgw->cont) + msgw->cont (msgw->cont_cls, + &msgw->session->target, + GNUNET_SYSERR, + msgw->payload, + 0); + GNUNET_free (msgw->msg); + GNUNET_free (msgw); + } + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (plugin->session_map, + &session->target, + session)); + GNUNET_STATISTICS_set (plugin->env->stats, + "# UNIX sessions active", + GNUNET_CONTAINER_multipeermap_size ( + plugin->session_map), + GNUNET_NO); if (NULL != session->timeout_task) - { - GNUNET_SCHEDULER_cancel(session->timeout_task); - session->timeout_task = NULL; - session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; - } - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_DONE); - GNUNET_HELLO_address_free(session->address); - GNUNET_break(0 == session->bytes_in_queue); - GNUNET_break(0 == session->msgs_in_queue); - GNUNET_free(session); + { + GNUNET_SCHEDULER_cancel (session->timeout_task); + session->timeout_task = NULL; + session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; + } + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_DONE); + GNUNET_HELLO_address_free (session->address); + GNUNET_break (0 == session->bytes_in_queue); + GNUNET_break (0 == session->msgs_in_queue); + GNUNET_free (session); return GNUNET_OK; } @@ -480,31 +487,31 @@ unix_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *session) * @param cls the `struct GNUNET_ATS_Session *` to disconnect */ static void -session_timeout(void *cls) +session_timeout (void *cls) { struct GNUNET_ATS_Session *session = cls; struct GNUNET_TIME_Relative left; session->timeout_task = NULL; - left = GNUNET_TIME_absolute_get_remaining(session->timeout); + left = GNUNET_TIME_absolute_get_remaining (session->timeout); if (0 != left.rel_value_us) - { - /* not actually our turn yet, but let's at least update - the monitor, it may think we're about to die ... */ - notify_session_monitor(session->plugin, - session, - GNUNET_TRANSPORT_SS_UPDATE); - session->timeout_task = - GNUNET_SCHEDULER_add_delayed(left, &session_timeout, session); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Session %p was idle for %s, disconnecting\n", - session, - GNUNET_STRINGS_relative_time_to_string( - GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - GNUNET_YES)); - unix_plugin_session_disconnect(session->plugin, session); + { + /* not actually our turn yet, but let's at least update + the monitor, it may think we're about to die ... */ + notify_session_monitor (session->plugin, + session, + GNUNET_TRANSPORT_SS_UPDATE); + session->timeout_task = + GNUNET_SCHEDULER_add_delayed (left, &session_timeout, session); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Session %p was idle for %s, disconnecting\n", + session, + GNUNET_STRINGS_relative_time_to_string ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + GNUNET_YES)); + unix_plugin_session_disconnect (session->plugin, session); } @@ -516,11 +523,11 @@ session_timeout(void *cls) * @param session session for which the timeout should be rescheduled */ static void -reschedule_session_timeout(struct GNUNET_ATS_Session *session) +reschedule_session_timeout (struct GNUNET_ATS_Session *session) { - GNUNET_assert(NULL != session->timeout_task); + GNUNET_assert (NULL != session->timeout_task); session->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); } @@ -532,22 +539,22 @@ reschedule_session_timeout(struct GNUNET_ATS_Session *session) * @return converted unix path */ static struct sockaddr_un * -unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len) +unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) { struct sockaddr_un *un; size_t slen; - GNUNET_assert(0 < strlen(unixpath)); /* sanity check */ - un = GNUNET_new(struct sockaddr_un); + GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ + un = GNUNET_new (struct sockaddr_un); un->sun_family = AF_UNIX; - slen = strlen(unixpath); + slen = strlen (unixpath); if (slen >= sizeof(un->sun_path)) slen = sizeof(un->sun_path) - 1; - GNUNET_memcpy(un->sun_path, unixpath, slen); + GNUNET_memcpy (un->sun_path, unixpath, slen); un->sun_path[slen] = '\0'; slen = sizeof(struct sockaddr_un); #if HAVE_SOCKADDR_UN_SUN_LEN - un->sun_len = (u_char)slen; + un->sun_len = (u_char) slen; #endif (*sock_len) = slen; return un; @@ -557,7 +564,8 @@ unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len) /** * Closure to #lookup_session_it(). */ -struct LookupCtx { +struct LookupCtx +{ /** * Location to store the session, if found. */ @@ -579,18 +587,18 @@ struct LookupCtx { * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success */ static int -lookup_session_it(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +lookup_session_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct LookupCtx *lctx = cls; struct GNUNET_ATS_Session *session = value; - if (0 == GNUNET_HELLO_address_cmp(lctx->address, session->address)) - { - lctx->res = session; - return GNUNET_NO; - } + if (0 == GNUNET_HELLO_address_cmp (lctx->address, session->address)) + { + lctx->res = session; + return GNUNET_NO; + } return GNUNET_YES; } @@ -603,17 +611,17 @@ lookup_session_it(void *cls, * @return NULL if session was not found */ static struct GNUNET_ATS_Session * -lookup_session(struct Plugin *plugin, - const struct GNUNET_HELLO_Address *address) +lookup_session (struct Plugin *plugin, + const struct GNUNET_HELLO_Address *address) { struct LookupCtx lctx; lctx.address = address; lctx.res = NULL; - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->session_map, - &address->peer, - &lookup_session_it, - &lctx); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, + &address->peer, + &lookup_session_it, + &lctx); return lctx.res; } @@ -627,7 +635,7 @@ lookup_session(struct Plugin *plugin, * @return keepalive factor */ static unsigned int -unix_plugin_query_keepalive_factor(void *cls) +unix_plugin_query_keepalive_factor (void *cls) { return 3; } @@ -655,18 +663,18 @@ unix_plugin_query_keepalive_factor(void *cls) * @return on success the number of bytes written, RETRY for retry, -1 on errors */ static ssize_t -unix_real_send(void *cls, - struct GNUNET_NETWORK_Handle *send_handle, - const struct GNUNET_PeerIdentity *target, - const char *msgbuf, - size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Absolute timeout, - const struct UnixAddress *addr, - size_t addrlen, - size_t payload, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls) +unix_real_send (void *cls, + struct GNUNET_NETWORK_Handle *send_handle, + const struct GNUNET_PeerIdentity *target, + const char *msgbuf, + size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Absolute timeout, + const struct UnixAddress *addr, + size_t addrlen, + size_t payload, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { struct Plugin *plugin = cls; ssize_t sent; @@ -675,96 +683,96 @@ unix_real_send(void *cls, const char *unixpath; if (NULL == send_handle) - { - GNUNET_break(0); /* We do not have a send handle */ - return GNUNET_SYSERR; - } + { + GNUNET_break (0); /* We do not have a send handle */ + return GNUNET_SYSERR; + } if ((NULL == addr) || (0 == addrlen)) - { - GNUNET_break(0); /* Can never send if we don't have an address */ - return GNUNET_SYSERR; - } + { + GNUNET_break (0); /* Can never send if we don't have an address */ + return GNUNET_SYSERR; + } /* Prepare address */ - unixpath = (const char *)&addr[1]; - if (NULL == (un = unix_address_to_sockaddr(unixpath, &un_len))) - { - GNUNET_break(0); - return -1; - } + unixpath = (const char *) &addr[1]; + if (NULL == (un = unix_address_to_sockaddr (unixpath, &un_len))) + { + GNUNET_break (0); + return -1; + } if ((GNUNET_YES == plugin->is_abstract) && - (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options)))) - { - un->sun_path[0] = '\0'; - } + (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl (addr->options)))) + { + un->sun_path[0] = '\0'; + } resend: /* Send the data */ - sent = GNUNET_NETWORK_socket_sendto(send_handle, - msgbuf, - msgbuf_size, - (const struct sockaddr *)un, - un_len); + sent = GNUNET_NETWORK_socket_sendto (send_handle, + msgbuf, + msgbuf_size, + (const struct sockaddr *) un, + un_len); if (GNUNET_SYSERR == sent) + { + if ((EAGAIN == errno) || (ENOBUFS == errno)) { - if ((EAGAIN == errno) || (ENOBUFS == errno)) - { - GNUNET_free(un); - return RETRY; /* We have to retry later */ - } - if (EMSGSIZE == errno) + GNUNET_free (un); + return RETRY; /* We have to retry later */ + } + if (EMSGSIZE == errno) + { + socklen_t size = 0; + socklen_t len = sizeof(size); + + GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *) + send_handle, + SOL_SOCKET, + SO_SNDBUF, + &size, + &len); + if (size < msgbuf_size) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Trying to increase socket buffer size from %u to %u for message size %u\n", + (unsigned int) size, + (unsigned int) ((msgbuf_size / 1000) + 2) * 1000, + (unsigned int) msgbuf_size); + size = ((msgbuf_size / 1000) + 2) * 1000; + if (GNUNET_OK == + GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) + send_handle, + SOL_SOCKET, + SO_SNDBUF, + &size, + sizeof(size))) + goto resend; /* Increased buffer size, retry sending */ + else { - socklen_t size = 0; - socklen_t len = sizeof(size); - - GNUNET_NETWORK_socket_getsockopt((struct GNUNET_NETWORK_Handle *) - send_handle, - SOL_SOCKET, - SO_SNDBUF, - &size, - &len); - if (size < msgbuf_size) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Trying to increase socket buffer size from %u to %u for message size %u\n", - (unsigned int)size, - (unsigned int)((msgbuf_size / 1000) + 2) * 1000, - (unsigned int)msgbuf_size); - size = ((msgbuf_size / 1000) + 2) * 1000; - if (GNUNET_OK == - GNUNET_NETWORK_socket_setsockopt((struct GNUNET_NETWORK_Handle *) - send_handle, - SOL_SOCKET, - SO_SNDBUF, - &size, - sizeof(size))) - goto resend; /* Increased buffer size, retry sending */ - else - { - /* Could not increase buffer size: error, no retry */ - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt"); - GNUNET_free(un); - return GNUNET_SYSERR; - } - } - else - { - /* Buffer is bigger than message: error, no retry - * This should never happen!*/ - GNUNET_break(0); - GNUNET_free(un); - return GNUNET_SYSERR; - } + /* Could not increase buffer size: error, no retry */ + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt"); + GNUNET_free (un); + return GNUNET_SYSERR; } + } + else + { + /* Buffer is bigger than message: error, no retry + * This should never happen!*/ + GNUNET_break (0); + GNUNET_free (un); + return GNUNET_SYSERR; + } } - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "UNIX transmitted %u-byte message to %s (%d: %s)\n", - (unsigned int)msgbuf_size, - GNUNET_a2s((const struct sockaddr *)un, un_len), - (int)sent, - (sent < 0) ? strerror(errno) : "ok"); - GNUNET_free(un); + } + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "UNIX transmitted %u-byte message to %s (%d: %s)\n", + (unsigned int) msgbuf_size, + GNUNET_a2s ((const struct sockaddr *) un, un_len), + (int) sent, + (sent < 0) ? strerror (errno) : "ok"); + GNUNET_free (un); return sent; } @@ -777,9 +785,9 @@ resend: * @return the network type in HBO or #GNUNET_SYSERR */ static enum GNUNET_NetworkType -unix_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) +unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) { - GNUNET_assert(NULL != session); + GNUNET_assert (NULL != session); return GNUNET_NT_LOOPBACK; } @@ -792,8 +800,8 @@ unix_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) * @return the network type */ static enum GNUNET_NetworkType -unix_plugin_get_network_for_address(void *cls, - const struct GNUNET_HELLO_Address *address) +unix_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) { return GNUNET_NT_LOOPBACK; } @@ -808,7 +816,7 @@ unix_plugin_get_network_for_address(void *cls, * @return the session or NULL of max connections exceeded */ static struct GNUNET_ATS_Session * -unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) +unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session; @@ -817,80 +825,80 @@ unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) uint32_t addr_str_len; uint32_t addr_option; - ua = (struct UnixAddress *)address->address; + ua = (struct UnixAddress *) address->address; if ((NULL == address->address) || (0 == address->address_length) || (sizeof(struct UnixAddress) > address->address_length)) - { - GNUNET_break(0); - return NULL; - } - addrstr = (char *)&ua[1]; - addr_str_len = ntohl(ua->addrlen); - addr_option = ntohl(ua->options); + { + GNUNET_break (0); + return NULL; + } + addrstr = (char *) &ua[1]; + addr_str_len = ntohl (ua->addrlen); + addr_option = ntohl (ua->options); if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && (GNUNET_NO == plugin->is_abstract)) - { - return NULL; - } + { + return NULL; + } if (addr_str_len != address->address_length - sizeof(struct UnixAddress)) - { - return NULL; /* This can be a legacy address */ - } + { + return NULL; /* This can be a legacy address */ + } if ('\0' != addrstr[addr_str_len - 1]) - { - GNUNET_break(0); - return NULL; - } - if (strlen(addrstr) + 1 != addr_str_len) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } + if (strlen (addrstr) + 1 != addr_str_len) + { + GNUNET_break (0); + return NULL; + } /* Check if a session for this address already exists */ - if (NULL != (session = lookup_session(plugin, address))) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Found existing session %p for address `%s'\n", - session, - unix_plugin_address_to_string(NULL, + if (NULL != (session = lookup_session (plugin, address))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found existing session %p for address `%s'\n", + session, + unix_plugin_address_to_string (NULL, address->address, address->address_length)); - return session; - } + return session; + } /* create a new session */ - session = GNUNET_new(struct GNUNET_ATS_Session); + session = GNUNET_new (struct GNUNET_ATS_Session); session->target = address->peer; - session->address = GNUNET_HELLO_address_copy(address); + session->address = GNUNET_HELLO_address_copy (address); session->plugin = plugin; session->timeout = - GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); session->timeout_task = - GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - &session_timeout, - session); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Creating a new session %p for address `%s'\n", - session, - unix_plugin_address_to_string(NULL, - address->address, - address->address_length)); - (void)GNUNET_CONTAINER_multipeermap_put( + GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + &session_timeout, + session); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Creating a new session %p for address `%s'\n", + session, + unix_plugin_address_to_string (NULL, + address->address, + address->address_length)); + (void) GNUNET_CONTAINER_multipeermap_put ( plugin->session_map, &address->peer, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GNUNET_STATISTICS_set(plugin->env->stats, - "# UNIX sessions active", - GNUNET_CONTAINER_multipeermap_size( - plugin->session_map), - GNUNET_NO); - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); + GNUNET_STATISTICS_set (plugin->env->stats, + "# UNIX sessions active", + GNUNET_CONTAINER_multipeermap_size ( + plugin->session_map), + GNUNET_NO); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); return session; } @@ -905,21 +913,21 @@ unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) * @param session which session is being updated */ static void -unix_plugin_update_session_timeout(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session) +unix_plugin_update_session_timeout (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session) { struct Plugin *plugin = cls; if (GNUNET_OK != - GNUNET_CONTAINER_multipeermap_contains_value(plugin->session_map, - &session->target, - session)) - { - GNUNET_break(0); - return; - } - reschedule_session_timeout(session); + GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, + &session->target, + session)) + { + GNUNET_break (0); + return; + } + reschedule_session_timeout (session); } @@ -933,47 +941,47 @@ unix_plugin_update_session_timeout(void *cls, * @param ua_len length of the address @a ua */ static void -unix_demultiplexer(struct Plugin *plugin, - struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *currhdr, - const struct UnixAddress *ua, - size_t ua_len) +unix_demultiplexer (struct Plugin *plugin, + struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *currhdr, + const struct UnixAddress *ua, + size_t ua_len) { struct GNUNET_ATS_Session *session; struct GNUNET_HELLO_Address *address; - GNUNET_assert(ua_len >= sizeof(struct UnixAddress)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received message from %s\n", - unix_plugin_address_to_string(NULL, ua, ua_len)); - GNUNET_STATISTICS_update(plugin->env->stats, - "# bytes received via UNIX", - ntohs(currhdr->size), - GNUNET_NO); + GNUNET_assert (ua_len >= sizeof(struct UnixAddress)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received message from %s\n", + unix_plugin_address_to_string (NULL, ua, ua_len)); + GNUNET_STATISTICS_update (plugin->env->stats, + "# bytes received via UNIX", + ntohs (currhdr->size), + GNUNET_NO); /* Look for existing session */ - address = GNUNET_HELLO_address_allocate( + address = GNUNET_HELLO_address_allocate ( sender, PLUGIN_NAME, ua, ua_len, GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ - session = lookup_session(plugin, address); + session = lookup_session (plugin, address); if (NULL == session) - { - session = unix_plugin_get_session(plugin, address); - /* Notify transport and ATS about new inbound session */ - plugin->env->session_start(NULL, - session->address, - session, - GNUNET_NT_LOOPBACK); - } + { + session = unix_plugin_get_session (plugin, address); + /* Notify transport and ATS about new inbound session */ + plugin->env->session_start (NULL, + session->address, + session, + GNUNET_NT_LOOPBACK); + } else - { - reschedule_session_timeout(session); - } - GNUNET_HELLO_address_free(address); - plugin->env->receive(plugin->env->cls, session->address, session, currhdr); + { + reschedule_session_timeout (session); + } + GNUNET_HELLO_address_free (address); + plugin->env->receive (plugin->env->cls, session->address, session, currhdr); } @@ -983,7 +991,7 @@ unix_demultiplexer(struct Plugin *plugin, * @param plugin the plugin */ static void -unix_plugin_do_read(struct Plugin *plugin) +unix_plugin_do_read (struct Plugin *plugin) { char buf[65536] GNUNET_ALIGN; struct UnixAddress *ua; @@ -1001,70 +1009,70 @@ unix_plugin_do_read(struct Plugin *plugin) size_t ua_len; addrlen = sizeof(un); - memset(&un, 0, sizeof(un)); - ret = GNUNET_NETWORK_socket_recvfrom(plugin->unix_sock.desc, - buf, - sizeof(buf), - (struct sockaddr *)&un, - &addrlen); + memset (&un, 0, sizeof(un)); + ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, + buf, + sizeof(buf), + (struct sockaddr *) &un, + &addrlen); if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) return; if (GNUNET_SYSERR == ret) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom"); - return; - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); + return; + } else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Read %d bytes from socket %s\n", - (int)ret, - un.sun_path); - } - - GNUNET_assert(AF_UNIX == (un.sun_family)); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Read %d bytes from socket %s\n", + (int) ret, + un.sun_path); + } + + GNUNET_assert (AF_UNIX == (un.sun_family)); is_abstract = GNUNET_NO; if ('\0' == un.sun_path[0]) - { - un.sun_path[0] = '@'; - is_abstract = GNUNET_YES; - } - - ua_len = sizeof(struct UnixAddress) + strlen(un.sun_path) + 1; - ua = GNUNET_malloc(ua_len); - ua->addrlen = htonl(strlen(&un.sun_path[0]) + 1); - GNUNET_memcpy(&ua[1], &un.sun_path[0], strlen(un.sun_path) + 1); + { + un.sun_path[0] = '@'; + is_abstract = GNUNET_YES; + } + + ua_len = sizeof(struct UnixAddress) + strlen (un.sun_path) + 1; + ua = GNUNET_malloc (ua_len); + ua->addrlen = htonl (strlen (&un.sun_path[0]) + 1); + GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); if (is_abstract) - ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); + ua->options = htonl (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); else - ua->options = htonl(UNIX_OPTIONS_NONE); + ua->options = htonl (UNIX_OPTIONS_NONE); - msg = (struct UNIXMessage *)buf; - csize = ntohs(msg->header.size); + msg = (struct UNIXMessage *) buf; + csize = ntohs (msg->header.size); if ((csize < sizeof(struct UNIXMessage)) || (csize > ret)) - { - GNUNET_break_op(0); - GNUNET_free(ua); - return; - } - msgbuf = (char *)&msg[1]; - GNUNET_memcpy(&sender, &msg->sender, sizeof(struct GNUNET_PeerIdentity)); + { + GNUNET_break_op (0); + GNUNET_free (ua); + return; + } + msgbuf = (char *) &msg[1]; + GNUNET_memcpy (&sender, &msg->sender, sizeof(struct GNUNET_PeerIdentity)); offset = 0; tsize = csize - sizeof(struct UNIXMessage); while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize) + { + currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset]; + csize = ntohs (currhdr->size); + if ((csize < sizeof(struct GNUNET_MessageHeader)) || + (csize > tsize - offset)) { - currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset]; - csize = ntohs(currhdr->size); - if ((csize < sizeof(struct GNUNET_MessageHeader)) || - (csize > tsize - offset)) - { - GNUNET_break_op(0); - break; - } - unix_demultiplexer(plugin, &sender, currhdr, ua, ua_len); - offset += csize; + GNUNET_break_op (0); + break; } - GNUNET_free(ua); + unix_demultiplexer (plugin, &sender, currhdr, ua, ua_len); + offset += csize; + } + GNUNET_free (ua); } @@ -1074,7 +1082,7 @@ unix_plugin_do_read(struct Plugin *plugin) * @param plugin handle to the plugin */ static void -unix_plugin_do_write(struct Plugin *plugin) +unix_plugin_do_write (struct Plugin *plugin) { ssize_t sent = 0; struct UNIXMessageWrapper *msgw; @@ -1084,108 +1092,108 @@ unix_plugin_do_write(struct Plugin *plugin) session = NULL; did_delete = GNUNET_NO; while (NULL != (msgw = plugin->msg_head)) - { - if (GNUNET_TIME_absolute_get_remaining(msgw->timeout).rel_value_us > 0) - break; /* Message is ready for sending */ - /* Message has a timeout */ - did_delete = GNUNET_YES; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Timeout for message with %u bytes \n", - (unsigned int)msgw->msgsize); - GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); - session = msgw->session; - session->msgs_in_queue--; - GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); - session->bytes_in_queue -= msgw->msgsize; - GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); - plugin->bytes_in_queue -= msgw->msgsize; - GNUNET_STATISTICS_set(plugin->env->stats, - "# bytes currently in UNIX buffers", - plugin->bytes_in_queue, - GNUNET_NO); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UNIX bytes discarded", - msgw->msgsize, - GNUNET_NO); - if (NULL != msgw->cont) - msgw->cont(msgw->cont_cls, - &msgw->session->target, - GNUNET_SYSERR, - msgw->payload, - 0); - GNUNET_free(msgw->msg); - GNUNET_free(msgw); - } + { + if (GNUNET_TIME_absolute_get_remaining (msgw->timeout).rel_value_us > 0) + break; /* Message is ready for sending */ + /* Message has a timeout */ + did_delete = GNUNET_YES; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Timeout for message with %u bytes \n", + (unsigned int) msgw->msgsize); + GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); + session = msgw->session; + session->msgs_in_queue--; + GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); + session->bytes_in_queue -= msgw->msgsize; + GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); + plugin->bytes_in_queue -= msgw->msgsize; + GNUNET_STATISTICS_set (plugin->env->stats, + "# bytes currently in UNIX buffers", + plugin->bytes_in_queue, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UNIX bytes discarded", + msgw->msgsize, + GNUNET_NO); + if (NULL != msgw->cont) + msgw->cont (msgw->cont_cls, + &msgw->session->target, + GNUNET_SYSERR, + msgw->payload, + 0); + GNUNET_free (msgw->msg); + GNUNET_free (msgw); + } if (NULL == msgw) - { - if (GNUNET_YES == did_delete) - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); - return; /* Nothing to send at the moment */ - } + { + if (GNUNET_YES == did_delete) + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); + return; /* Nothing to send at the moment */ + } session = msgw->session; - sent = unix_real_send(plugin, - plugin->unix_sock.desc, - &session->target, - (const char *)msgw->msg, - msgw->msgsize, - msgw->priority, - msgw->timeout, - msgw->session->address->address, - msgw->session->address->address_length, - msgw->payload, - msgw->cont, - msgw->cont_cls); + sent = unix_real_send (plugin, + plugin->unix_sock.desc, + &session->target, + (const char *) msgw->msg, + msgw->msgsize, + msgw->priority, + msgw->timeout, + msgw->session->address->address, + msgw->session->address->address_length, + msgw->payload, + msgw->cont, + msgw->cont_cls); if (RETRY == sent) - { - GNUNET_STATISTICS_update(plugin->env->stats, - "# UNIX retry attempts", - 1, - GNUNET_NO); - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); - return; - } - GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); + { + GNUNET_STATISTICS_update (plugin->env->stats, + "# UNIX retry attempts", + 1, + GNUNET_NO); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); + return; + } + GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); session->msgs_in_queue--; - GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); + GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); session->bytes_in_queue -= msgw->msgsize; - GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); + GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); plugin->bytes_in_queue -= msgw->msgsize; - GNUNET_STATISTICS_set(plugin->env->stats, - "# bytes currently in UNIX buffers", - plugin->bytes_in_queue, - GNUNET_NO); - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); + GNUNET_STATISTICS_set (plugin->env->stats, + "# bytes currently in UNIX buffers", + plugin->bytes_in_queue, + GNUNET_NO); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); if (GNUNET_SYSERR == sent) - { - /* failed and no retry */ - if (NULL != msgw->cont) - msgw->cont(msgw->cont_cls, - &msgw->session->target, - GNUNET_SYSERR, - msgw->payload, - 0); - GNUNET_STATISTICS_update(plugin->env->stats, - "# UNIX bytes discarded", - msgw->msgsize, - GNUNET_NO); - GNUNET_free(msgw->msg); - GNUNET_free(msgw); - return; - } + { + /* failed and no retry */ + if (NULL != msgw->cont) + msgw->cont (msgw->cont_cls, + &msgw->session->target, + GNUNET_SYSERR, + msgw->payload, + 0); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UNIX bytes discarded", + msgw->msgsize, + GNUNET_NO); + GNUNET_free (msgw->msg); + GNUNET_free (msgw); + return; + } /* successfully sent bytes */ - GNUNET_break(sent > 0); - GNUNET_STATISTICS_update(plugin->env->stats, - "# bytes transmitted via UNIX", - msgw->msgsize, - GNUNET_NO); + GNUNET_break (sent > 0); + GNUNET_STATISTICS_update (plugin->env->stats, + "# bytes transmitted via UNIX", + msgw->msgsize, + GNUNET_NO); if (NULL != msgw->cont) - msgw->cont(msgw->cont_cls, - &msgw->session->target, - GNUNET_OK, - msgw->payload, - msgw->msgsize); - GNUNET_free(msgw->msg); - GNUNET_free(msgw); + msgw->cont (msgw->cont_cls, + &msgw->session->target, + GNUNET_OK, + msgw->payload, + msgw->msgsize); + GNUNET_free (msgw->msg); + GNUNET_free (msgw); } @@ -1196,20 +1204,20 @@ unix_plugin_do_write(struct Plugin *plugin) * @param cls the plugin handle */ static void -unix_plugin_select_read(void *cls) +unix_plugin_select_read (void *cls) { struct Plugin *plugin = cls; const struct GNUNET_SCHEDULER_TaskContext *tc; plugin->read_task = NULL; - tc = GNUNET_SCHEDULER_get_task_context(); + tc = GNUNET_SCHEDULER_get_task_context (); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) - unix_plugin_do_read(plugin); + unix_plugin_do_read (plugin); plugin->read_task = - GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - plugin->unix_sock.desc, - &unix_plugin_select_read, - plugin); + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + plugin->unix_sock.desc, + &unix_plugin_select_read, + plugin); } @@ -1220,22 +1228,22 @@ unix_plugin_select_read(void *cls) * @param cls the plugin handle */ static void -unix_plugin_select_write(void *cls) +unix_plugin_select_write (void *cls) { struct Plugin *plugin = cls; const struct GNUNET_SCHEDULER_TaskContext *tc; plugin->write_task = NULL; - tc = GNUNET_SCHEDULER_get_task_context(); + tc = GNUNET_SCHEDULER_get_task_context (); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) - unix_plugin_do_write(plugin); + unix_plugin_do_write (plugin); if (NULL == plugin->msg_head) return; /* write queue empty */ plugin->write_task = - GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, - plugin->unix_sock.desc, - &unix_plugin_select_write, - plugin); + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + plugin->unix_sock.desc, + &unix_plugin_select_write, + plugin); } @@ -1267,14 +1275,14 @@ unix_plugin_select_write(void *cls) * and does NOT mean that the message was not transmitted (DV) */ static ssize_t -unix_plugin_send(void *cls, - struct GNUNET_ATS_Session *session, - const char *msgbuf, - size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls) +unix_plugin_send (void *cls, + struct GNUNET_ATS_Session *session, + const char *msgbuf, + size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { struct Plugin *plugin = cls; struct UNIXMessageWrapper *wrapper; @@ -1282,60 +1290,60 @@ unix_plugin_send(void *cls, int ssize; if (GNUNET_OK != - GNUNET_CONTAINER_multipeermap_contains_value(plugin->session_map, - &session->target, - session)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Invalid session for peer `%s' `%s'\n", - GNUNET_i2s(&session->target), - unix_plugin_address_to_string(NULL, + GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, + &session->target, + session)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Invalid session for peer `%s' `%s'\n", + GNUNET_i2s (&session->target), + unix_plugin_address_to_string (NULL, session->address->address, session->address->address_length)); - GNUNET_break(0); - return GNUNET_SYSERR; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sending %u bytes with session for peer `%s' `%s'\n", - msgbuf_size, - GNUNET_i2s(&session->target), - unix_plugin_address_to_string(NULL, - session->address->address, - session->address->address_length)); + GNUNET_break (0); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending %u bytes with session for peer `%s' `%s'\n", + msgbuf_size, + GNUNET_i2s (&session->target), + unix_plugin_address_to_string (NULL, + session->address->address, + session->address->address_length)); ssize = sizeof(struct UNIXMessage) + msgbuf_size; - message = GNUNET_malloc(sizeof(struct UNIXMessage) + msgbuf_size); - message->header.size = htons(ssize); - message->header.type = htons(0); - GNUNET_memcpy(&message->sender, - plugin->env->my_identity, - sizeof(struct GNUNET_PeerIdentity)); - GNUNET_memcpy(&message[1], msgbuf, msgbuf_size); - wrapper = GNUNET_new(struct UNIXMessageWrapper); + message = GNUNET_malloc (sizeof(struct UNIXMessage) + msgbuf_size); + message->header.size = htons (ssize); + message->header.type = htons (0); + GNUNET_memcpy (&message->sender, + plugin->env->my_identity, + sizeof(struct GNUNET_PeerIdentity)); + GNUNET_memcpy (&message[1], msgbuf, msgbuf_size); + wrapper = GNUNET_new (struct UNIXMessageWrapper); wrapper->msg = message; wrapper->msgsize = ssize; wrapper->payload = msgbuf_size; wrapper->priority = priority; - wrapper->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); + wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to); wrapper->cont = cont; wrapper->cont_cls = cont_cls; wrapper->session = session; - GNUNET_CONTAINER_DLL_insert_tail(plugin->msg_head, - plugin->msg_tail, - wrapper); + GNUNET_CONTAINER_DLL_insert_tail (plugin->msg_head, + plugin->msg_tail, + wrapper); plugin->bytes_in_queue += ssize; session->bytes_in_queue += ssize; session->msgs_in_queue++; - GNUNET_STATISTICS_set(plugin->env->stats, - "# bytes currently in UNIX buffers", - plugin->bytes_in_queue, - GNUNET_NO); - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); + GNUNET_STATISTICS_set (plugin->env->stats, + "# bytes currently in UNIX buffers", + plugin->bytes_in_queue, + GNUNET_NO); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); if (NULL == plugin->write_task) plugin->write_task = - GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, - plugin->unix_sock.desc, - &unix_plugin_select_write, - plugin); + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, + plugin->unix_sock.desc, + &unix_plugin_select_write, + plugin); return ssize; } @@ -1347,57 +1355,57 @@ unix_plugin_send(void *cls, * @return number of sockets created or #GNUNET_SYSERR on error */ static int -unix_transport_server_start(void *cls) +unix_transport_server_start (void *cls) { struct Plugin *plugin = cls; struct sockaddr_un *un; socklen_t un_len; - un = unix_address_to_sockaddr(plugin->unix_socket_path, &un_len); + un = unix_address_to_sockaddr (plugin->unix_socket_path, &un_len); if (GNUNET_YES == plugin->is_abstract) - { - plugin->unix_socket_path[0] = '@'; - un->sun_path[0] = '\0'; - } + { + plugin->unix_socket_path[0] = '@'; + un->sun_path[0] = '\0'; + } plugin->unix_sock.desc = - GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0); + GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); if (NULL == plugin->unix_sock.desc) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); - GNUNET_free(un); - return GNUNET_SYSERR; - } + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); + GNUNET_free (un); + return GNUNET_SYSERR; + } if ('\0' != un->sun_path[0]) + { + if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path)) { - if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Cannot create path to `%s'\n"), - un->sun_path); - GNUNET_NETWORK_socket_close(plugin->unix_sock.desc); - plugin->unix_sock.desc = NULL; - GNUNET_free(un); - return GNUNET_SYSERR; - } - } - if (GNUNET_OK != GNUNET_NETWORK_socket_bind(plugin->unix_sock.desc, - (const struct sockaddr *)un, - un_len)) - { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "bind"); - LOG(GNUNET_ERROR_TYPE_ERROR, _("Cannot bind to `%s'\n"), un->sun_path); - GNUNET_NETWORK_socket_close(plugin->unix_sock.desc); + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Cannot create path to `%s'\n"), + un->sun_path); + GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); plugin->unix_sock.desc = NULL; - GNUNET_free(un); + GNUNET_free (un); return GNUNET_SYSERR; } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path); + } + if (GNUNET_OK != GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, + (const struct sockaddr *) un, + un_len)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); + LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot bind to `%s'\n"), un->sun_path); + GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); + plugin->unix_sock.desc = NULL; + GNUNET_free (un); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path); plugin->read_task = - GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, - plugin->unix_sock.desc, - &unix_plugin_select_read, - plugin); - GNUNET_free(un); + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + plugin->unix_sock.desc, + &unix_plugin_select_read, + plugin); + GNUNET_free (un); return 1; } @@ -1419,7 +1427,7 @@ unix_transport_server_start(void *cls) * */ static int -unix_plugin_check_address(void *cls, const void *addr, size_t addrlen) +unix_plugin_check_address (void *cls, const void *addr, size_t addrlen) { struct Plugin *plugin = cls; const struct UnixAddress *ua = addr; @@ -1428,24 +1436,24 @@ unix_plugin_check_address(void *cls, const void *addr, size_t addrlen) if ((NULL == addr) || (0 == addrlen) || (sizeof(struct UnixAddress) > addrlen)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - addrstr = (char *)&ua[1]; - addr_str_len = ntohl(ua->addrlen); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + addrstr = (char *) &ua[1]; + addr_str_len = ntohl (ua->addrlen); if ('\0' != addrstr[addr_str_len - 1]) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - if (strlen(addrstr) + 1 != addr_str_len) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - - if (0 == strcmp(plugin->unix_socket_path, addrstr)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (strlen (addrstr) + 1 != addr_str_len) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + + if (0 == strcmp (plugin->unix_socket_path, addrstr)) return GNUNET_OK; return GNUNET_SYSERR; } @@ -1466,23 +1474,23 @@ unix_plugin_check_address(void *cls, const void *addr, size_t addrlen) * @param asc_cls closure for @a asc */ static void -unix_plugin_address_pretty_printer(void *cls, - const char *type, - const void *addr, - size_t addrlen, - int numeric, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback asc, - void *asc_cls) +unix_plugin_address_pretty_printer (void *cls, + const char *type, + const void *addr, + size_t addrlen, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback asc, + void *asc_cls) { const char *ret; if ((NULL != addr) && (addrlen > 0)) - ret = unix_plugin_address_to_string(NULL, addr, addrlen); + ret = unix_plugin_address_to_string (NULL, addr, addrlen); else ret = NULL; - asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); - asc(asc_cls, NULL, GNUNET_OK); + asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); + asc (asc_cls, NULL, GNUNET_OK); } @@ -1499,11 +1507,11 @@ unix_plugin_address_pretty_printer(void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -unix_plugin_string_to_address(void *cls, - const char *addr, - uint16_t addrlen, - void **buf, - size_t *added) +unix_plugin_string_to_address (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, + size_t *added) { struct UnixAddress *ua; char *address; @@ -1518,53 +1526,53 @@ unix_plugin_string_to_address(void *cls, optionstr = NULL; if ((NULL == addr) || (addrlen == 0)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if ('\0' != addr[addrlen - 1]) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - if (strlen(addr) != addrlen - 1) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - plugin = GNUNET_strdup(addr); - optionstr = strchr(plugin, '.'); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (strlen (addr) != addrlen - 1) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + plugin = GNUNET_strdup (addr); + optionstr = strchr (plugin, '.'); if (NULL == optionstr) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } optionstr[0] = '\0'; optionstr++; - options = atol(optionstr); - address = strchr(optionstr, '.'); + options = atol (optionstr); + address = strchr (optionstr, '.'); if (NULL == address) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } address[0] = '\0'; address++; - if (0 != strcmp(plugin, PLUGIN_NAME)) - { - GNUNET_break(0); - GNUNET_free(plugin); - return GNUNET_SYSERR; - } - - ua_size = sizeof(struct UnixAddress) + strlen(address) + 1; - ua = GNUNET_malloc(ua_size); - ua->options = htonl(options); - ua->addrlen = htonl(strlen(address) + 1); - GNUNET_memcpy(&ua[1], address, strlen(address) + 1); - GNUNET_free(plugin); + if (0 != strcmp (plugin, PLUGIN_NAME)) + { + GNUNET_break (0); + GNUNET_free (plugin); + return GNUNET_SYSERR; + } + + ua_size = sizeof(struct UnixAddress) + strlen (address) + 1; + ua = GNUNET_malloc (ua_size); + ua->options = htonl (options); + ua->addrlen = htonl (strlen (address) + 1); + GNUNET_memcpy (&ua[1], address, strlen (address) + 1); + GNUNET_free (plugin); (*buf) = ua; (*added) = ua_size; @@ -1578,7 +1586,7 @@ unix_plugin_string_to_address(void *cls, * @param cls the plugin */ static void -address_notification(void *cls) +address_notification (void *cls) { struct Plugin *plugin = cls; struct GNUNET_HELLO_Address *address; @@ -1586,24 +1594,24 @@ address_notification(void *cls) struct UnixAddress *ua; char *unix_path; - len = sizeof(struct UnixAddress) + strlen(plugin->unix_socket_path) + 1; - ua = GNUNET_malloc(len); - ua->options = htonl(plugin->myoptions); - ua->addrlen = htonl(strlen(plugin->unix_socket_path) + 1); - unix_path = (char *)&ua[1]; - GNUNET_memcpy(unix_path, - plugin->unix_socket_path, - strlen(plugin->unix_socket_path) + 1); + len = sizeof(struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; + ua = GNUNET_malloc (len); + ua->options = htonl (plugin->myoptions); + ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1); + unix_path = (char *) &ua[1]; + GNUNET_memcpy (unix_path, + plugin->unix_socket_path, + strlen (plugin->unix_socket_path) + 1); plugin->address_update_task = NULL; - address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - PLUGIN_NAME, - ua, - len, - GNUNET_HELLO_ADDRESS_INFO_NONE); - plugin->env->notify_address(plugin->env->cls, GNUNET_YES, address); - GNUNET_free(ua); - GNUNET_free(address); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, + ua, + len, + GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); + GNUNET_free (ua); + GNUNET_free (address); } @@ -1616,14 +1624,14 @@ address_notification(void *cls) * @return #GNUNET_YES (always, continue to iterate) */ static int -get_session_delete_it(void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +get_session_delete_it (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session = value; - unix_plugin_session_disconnect(plugin, session); + unix_plugin_session_disconnect (plugin, session); return GNUNET_YES; } @@ -1636,15 +1644,15 @@ get_session_delete_it(void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed */ static void -unix_plugin_peer_disconnect(void *cls, - const struct GNUNET_PeerIdentity *target) +unix_plugin_peer_disconnect (void *cls, + const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->session_map, - target, - &get_session_delete_it, - plugin); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, + target, + &get_session_delete_it, + plugin); } @@ -1658,15 +1666,15 @@ unix_plugin_peer_disconnect(void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -send_session_info_iter(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +send_session_info_iter (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session = value; - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); - notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); + notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); return GNUNET_OK; } @@ -1684,22 +1692,22 @@ send_session_info_iter(void *cls, * @param sic_cls closure for @a sic */ static void -unix_plugin_setup_monitor(void *cls, - GNUNET_TRANSPORT_SessionInfoCallback sic, - void *sic_cls) +unix_plugin_setup_monitor (void *cls, + GNUNET_TRANSPORT_SessionInfoCallback sic, + void *sic_cls) { struct Plugin *plugin = cls; plugin->sic = sic; plugin->sic_cls = sic_cls; if (NULL != sic) - { - GNUNET_CONTAINER_multipeermap_iterate(plugin->session_map, - &send_session_info_iter, - plugin); - /* signal end of first iteration */ - sic(sic_cls, NULL, NULL); - } + { + GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, + &send_session_info_iter, + plugin); + /* signal end of first iteration */ + sic (sic_cls, NULL, NULL); + } } @@ -1711,7 +1719,7 @@ unix_plugin_setup_monitor(void *cls, * @return NULL on error, plugin functions otherwise */ void * -libgnunet_plugin_transport_unix_init(void *cls) +libgnunet_plugin_transport_unix_init (void *cls) { struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; @@ -1719,45 +1727,45 @@ libgnunet_plugin_transport_unix_init(void *cls) int sockets_created; if (NULL == env->receive) - { - /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully - initialze the plugin or the API */ - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); - api->cls = NULL; - api->address_pretty_printer = &unix_plugin_address_pretty_printer; - api->address_to_string = &unix_plugin_address_to_string; - api->string_to_address = &unix_plugin_string_to_address; - return api; - } - - plugin = GNUNET_new(struct Plugin); + { + /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully + initialze the plugin or the API */ + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); + api->cls = NULL; + api->address_pretty_printer = &unix_plugin_address_pretty_printer; + api->address_to_string = &unix_plugin_address_to_string; + api->string_to_address = &unix_plugin_string_to_address; + return api; + } + + plugin = GNUNET_new (struct Plugin); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename(env->cfg, - "transport-unix", - "UNIXPATH", - &plugin->unix_socket_path)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - "transport-unix", - "UNIXPATH"); - GNUNET_free(plugin); - return NULL; - } + GNUNET_CONFIGURATION_get_value_filename (env->cfg, + "transport-unix", + "UNIXPATH", + &plugin->unix_socket_path)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "transport-unix", + "UNIXPATH"); + GNUNET_free (plugin); + return NULL; + } plugin->env = env; /* Initialize my flags */ #ifdef LINUX plugin->is_abstract = - GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, - "testing", - "USE_ABSTRACT_SOCKETS"); + GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, + "testing", + "USE_ABSTRACT_SOCKETS"); #endif plugin->myoptions = UNIX_OPTIONS_NONE; if (GNUNET_YES == plugin->is_abstract) plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS; - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->get_session = &unix_plugin_get_session; api->send = &unix_plugin_send; @@ -1772,18 +1780,18 @@ libgnunet_plugin_transport_unix_init(void *cls) api->get_network_for_address = &unix_plugin_get_network_for_address; api->update_session_timeout = &unix_plugin_update_session_timeout; api->setup_monitor = &unix_plugin_setup_monitor; - sockets_created = unix_transport_server_start(plugin); + sockets_created = unix_transport_server_start (plugin); if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) - { - LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX listen socket\n")); - GNUNET_free(api); - GNUNET_free(plugin->unix_socket_path); - GNUNET_free(plugin); - return NULL; - } - plugin->session_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); + { + LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UNIX listen socket\n")); + GNUNET_free (api); + GNUNET_free (plugin->unix_socket_path); + GNUNET_free (plugin); + return NULL; + } + plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); plugin->address_update_task = - GNUNET_SCHEDULER_add_now(&address_notification, plugin); + GNUNET_SCHEDULER_add_now (&address_notification, plugin); return api; } @@ -1795,7 +1803,7 @@ libgnunet_plugin_transport_unix_init(void *cls) * @return NULL (always) */ void * -libgnunet_plugin_transport_unix_done(void *cls) +libgnunet_plugin_transport_unix_done (void *cls) { struct GNUNET_TRANSPORT_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; @@ -1806,75 +1814,75 @@ libgnunet_plugin_transport_unix_done(void *cls) struct GNUNET_ATS_Session *session; if (NULL == plugin) - { - GNUNET_free(api); - return NULL; - } - len = sizeof(struct UnixAddress) + strlen(plugin->unix_socket_path) + 1; - ua = GNUNET_malloc(len); - ua->options = htonl(plugin->myoptions); - ua->addrlen = htonl(strlen(plugin->unix_socket_path) + 1); - GNUNET_memcpy(&ua[1], - plugin->unix_socket_path, - strlen(plugin->unix_socket_path) + 1); - address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - PLUGIN_NAME, - ua, - len, - GNUNET_HELLO_ADDRESS_INFO_NONE); - plugin->env->notify_address(plugin->env->cls, GNUNET_NO, address); - - GNUNET_free(address); - GNUNET_free(ua); + { + GNUNET_free (api); + return NULL; + } + len = sizeof(struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; + ua = GNUNET_malloc (len); + ua->options = htonl (plugin->myoptions); + ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1); + GNUNET_memcpy (&ua[1], + plugin->unix_socket_path, + strlen (plugin->unix_socket_path) + 1); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, + ua, + len, + GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); + + GNUNET_free (address); + GNUNET_free (ua); while (NULL != (msgw = plugin->msg_head)) - { - GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); - session = msgw->session; - session->msgs_in_queue--; - GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); - session->bytes_in_queue -= msgw->msgsize; - GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); - plugin->bytes_in_queue -= msgw->msgsize; - if (NULL != msgw->cont) - msgw->cont(msgw->cont_cls, - &msgw->session->target, - GNUNET_SYSERR, - msgw->payload, - 0); - GNUNET_free(msgw->msg); - GNUNET_free(msgw); - } + { + GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); + session = msgw->session; + session->msgs_in_queue--; + GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); + session->bytes_in_queue -= msgw->msgsize; + GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); + plugin->bytes_in_queue -= msgw->msgsize; + if (NULL != msgw->cont) + msgw->cont (msgw->cont_cls, + &msgw->session->target, + GNUNET_SYSERR, + msgw->payload, + 0); + GNUNET_free (msgw->msg); + GNUNET_free (msgw); + } if (NULL != plugin->read_task) - { - GNUNET_SCHEDULER_cancel(plugin->read_task); - plugin->read_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->read_task); + plugin->read_task = NULL; + } if (NULL != plugin->write_task) - { - GNUNET_SCHEDULER_cancel(plugin->write_task); - plugin->write_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->write_task); + plugin->write_task = NULL; + } if (NULL != plugin->address_update_task) - { - GNUNET_SCHEDULER_cancel(plugin->address_update_task); - plugin->address_update_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->address_update_task); + plugin->address_update_task = NULL; + } if (NULL != plugin->unix_sock.desc) - { - GNUNET_break(GNUNET_OK == - GNUNET_NETWORK_socket_close(plugin->unix_sock.desc)); - plugin->unix_sock.desc = NULL; - } - GNUNET_CONTAINER_multipeermap_iterate(plugin->session_map, - &get_session_delete_it, - plugin); - GNUNET_CONTAINER_multipeermap_destroy(plugin->session_map); - GNUNET_break(0 == plugin->bytes_in_queue); - GNUNET_free(plugin->unix_socket_path); - GNUNET_free(plugin); - GNUNET_free(api); + { + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (plugin->unix_sock.desc)); + plugin->unix_sock.desc = NULL; + } + GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, + &get_session_delete_it, + plugin); + GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map); + GNUNET_break (0 == plugin->bytes_in_queue); + GNUNET_free (plugin->unix_socket_path); + GNUNET_free (plugin); + GNUNET_free (api); return NULL; } diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 6cdf240c3..570a39ed7 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -47,20 +47,22 @@ #define DUMMY_HELPER_NAME "gnunet-helper-transport-wlan-dummy" #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_wlan_init #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_wlan_done -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-wlan", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-wlan", __VA_ARGS__) /** * time out of a mac endpoint */ -#define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2) +#define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2) /** * We reduce the frequence of HELLO beacons in relation to * the number of MAC addresses currently visible to us. * This is the multiplication factor. */ -#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2) +#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 2) /* end case wlan */ @@ -72,14 +74,18 @@ #define HELPER_NAME "gnunet-helper-transport-bluetooth" /* yes, this is correct, we use the same dummy driver as 'wlan' */ #define DUMMY_HELPER_NAME "gnunet-helper-transport-wlan-dummy" -#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_bluetooth_init -#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_bluetooth_done -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-bluetooth", __VA_ARGS__) +#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \ + libgnunet_plugin_transport_bluetooth_init +#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \ + libgnunet_plugin_transport_bluetooth_done +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-bluetooth", \ + __VA_ARGS__) /** * time out of a mac endpoint */ -#define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 60) +#define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 60) /** @@ -87,7 +93,8 @@ * the number of MAC addresses currently visible to us. * This is the multiplication factor. */ -#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) +#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 60) /* end case bluetooth */ #else @@ -111,7 +118,8 @@ typedef int (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, void *client, - const struct GNUNET_MessageHeader *message); + const struct + GNUNET_MessageHeader *message); /* Include legacy message stream tokenizer that was removed from util (for now) */ @@ -154,7 +162,8 @@ GNUNET_NETWORK_STRUCT_BEGIN * the CRC and then tokenize the payload and pass it to the * 'receive' callback. */ -struct WlanHeader { +struct WlanHeader +{ /** * Message type is #GNUNET_MESSAGE_TYPE_WLAN_DATA. */ @@ -183,7 +192,8 @@ struct WlanHeader { /** * Address format for WLAN. */ -struct WlanAddress { +struct WlanAddress +{ /** * Options set for the WLAN, in NBO. */ @@ -203,7 +213,8 @@ GNUNET_NETWORK_STRUCT_END * Information kept for each message that is yet to be fragmented and * transmitted. */ -struct PendingMessage { +struct PendingMessage +{ /** * next entry in the DLL */ @@ -234,14 +245,15 @@ struct PendingMessage { /** * Timeout task (for this message). */ - struct GNUNET_SCHEDULER_Task * timeout_task; + struct GNUNET_SCHEDULER_Task *timeout_task; }; /** * Session handle for connections with other peers. */ -struct GNUNET_ATS_Session { +struct GNUNET_ATS_Session +{ /** * To whom are we talking to (set to our identity * if we are still waiting for the welcome message) @@ -278,14 +290,15 @@ struct GNUNET_ATS_Session { /** * Timeout task (for the session). */ - struct GNUNET_SCHEDULER_Task * timeout_task; + struct GNUNET_SCHEDULER_Task *timeout_task; }; /** * Struct for messages that are being fragmented in a MAC's transmission queue. */ -struct FragmentMessage { +struct FragmentMessage +{ /** * This is a doubly-linked list. */ @@ -325,7 +338,7 @@ struct FragmentMessage { /** * Timeout task. */ - struct GNUNET_SCHEDULER_Task * timeout_task; + struct GNUNET_SCHEDULER_Task *timeout_task; /** * Continuation to call when we're done with this message. @@ -358,7 +371,8 @@ struct FragmentMessage { /** * Struct to represent one network card connection */ -struct MacEndpoint { +struct MacEndpoint +{ /** * We keep all MACs in a DLL in the plugin. */ @@ -407,7 +421,7 @@ struct MacEndpoint { /** * Timeout task. */ - struct GNUNET_SCHEDULER_Task * timeout_task; + struct GNUNET_SCHEDULER_Task *timeout_task; /** * count of messages in the fragment out queue for this mac endpoint @@ -449,7 +463,8 @@ struct MacEndpoint { /** * Encapsulation of all of the state of the plugin. */ -struct Plugin { +struct Plugin +{ /** * Our environment. */ @@ -544,7 +559,8 @@ struct Plugin { * the session or the MAC endpoint associated with the * message (or both). */ -struct MacAndSession { +struct MacAndSession +{ /** * NULL if the identity of the other peer is not known. */ @@ -566,16 +582,16 @@ struct MacAndSession { * this function */ static const char * -mac_to_string(const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac) +mac_to_string (const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) { static char macstr[20]; - GNUNET_snprintf(macstr, - sizeof(macstr), - "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", - mac->mac[0], mac->mac[1], - mac->mac[2], mac->mac[3], - mac->mac[4], mac->mac[5]); + GNUNET_snprintf (macstr, + sizeof(macstr), + "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", + mac->mac[0], mac->mac[1], + mac->mac[2], mac->mac[3], + mac->mac[4], mac->mac[5]); return macstr; } @@ -592,25 +608,25 @@ mac_to_string(const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac) * @return string representing the same address */ static const char * -wlan_plugin_address_to_string(void *cls, - const void *addr, - size_t addrlen) +wlan_plugin_address_to_string (void *cls, + const void *addr, + size_t addrlen) { const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac; static char macstr[36]; if (sizeof(struct WlanAddress) != addrlen) - { - GNUNET_break(0); - return NULL; - } - mac = &((struct WlanAddress *)addr)->mac; - GNUNET_snprintf(macstr, - sizeof(macstr), - "%s.%u.%s", - PLUGIN_NAME, - ntohl(((struct WlanAddress *)addr)->options), - mac_to_string(mac)); + { + GNUNET_break (0); + return NULL; + } + mac = &((struct WlanAddress *) addr)->mac; + GNUNET_snprintf (macstr, + sizeof(macstr), + "%s.%u.%s", + PLUGIN_NAME, + ntohl (((struct WlanAddress *) addr)->options), + mac_to_string (mac)); return macstr; } @@ -624,15 +640,15 @@ wlan_plugin_address_to_string(void *cls, * @param state new state of the session */ static void -notify_session_monitor(struct Plugin *plugin, - struct GNUNET_ATS_Session *session, - enum GNUNET_TRANSPORT_SessionState state) +notify_session_monitor (struct Plugin *plugin, + struct GNUNET_ATS_Session *session, + enum GNUNET_TRANSPORT_SessionState state) { struct GNUNET_TRANSPORT_SessionInfo info; if (NULL == plugin->sic) return; - memset(&info, 0, sizeof(info)); + memset (&info, 0, sizeof(info)); info.state = state; info.is_inbound = GNUNET_SYSERR; /* hard to say */ info.num_msg_pending = 0; /* we queue per MAC, not per peer */ @@ -640,9 +656,9 @@ notify_session_monitor(struct Plugin *plugin, info.receive_delay = GNUNET_TIME_UNIT_ZERO_ABS; /* not supported by WLAN */ info.session_timeout = session->timeout; info.address = session->address; - plugin->sic(plugin->sic_cls, - session, - &info); + plugin->sic (plugin->sic_cls, + session, + &info); } @@ -654,24 +670,24 @@ notify_session_monitor(struct Plugin *plugin, * @param size total message size */ static void -get_radiotap_header(struct MacEndpoint *endpoint, - struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, - uint16_t size) +get_radiotap_header (struct MacEndpoint *endpoint, + struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, + uint16_t size) { - header->header.type = ntohs(GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); - header->header.size = ntohs(size); + header->header.type = ntohs (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); + header->header.size = ntohs (size); if (NULL != endpoint) - { - header->rate = endpoint->rate; - header->tx_power = endpoint->tx_power; - header->antenna = endpoint->antenna; - } + { + header->rate = endpoint->rate; + header->tx_power = endpoint->tx_power; + header->antenna = endpoint->antenna; + } else - { - header->rate = 255; - header->tx_power = 0; - header->antenna = 0; - } + { + header->rate = 255; + header->tx_power = 0; + header->antenna = 0; + } } @@ -684,18 +700,18 @@ get_radiotap_header(struct MacEndpoint *endpoint, * @param size size of the whole packet, needed to calculate the time to send the packet */ static void -get_wlan_header(struct Plugin *plugin, - struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *header, - const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, - unsigned int size) +get_wlan_header (struct Plugin *plugin, + struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *header, + const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, + unsigned int size) { const int rate = 11000000; - header->frame_control = htons(IEEE80211_FC0_TYPE_DATA); + header->frame_control = htons (IEEE80211_FC0_TYPE_DATA); header->addr1 = *to_mac_addr; header->addr2 = plugin->mac_address; header->addr3 = mac_bssid_gnunet; - header->duration = GNUNET_htole16((size * 1000000) / rate + 290); + header->duration = GNUNET_htole16 ((size * 1000000) / rate + 290); header->sequence_control = 0; // FIXME? header->llc[0] = WLAN_LLC_DSAP_FIELD; header->llc[1] = WLAN_LLC_SSAP_FIELD; @@ -712,44 +728,45 @@ get_wlan_header(struct Plugin *plugin, * @param hdr pointer to the hdr where the ack is stored */ static void -send_ack(void *cls, - uint32_t msg_id, - const struct GNUNET_MessageHeader *hdr) +send_ack (void *cls, + uint32_t msg_id, + const struct GNUNET_MessageHeader *hdr) { struct MacEndpoint *endpoint = cls; - struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage* radio_header; - uint16_t msize = ntohs(hdr->size); - size_t size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize; + struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*radio_header; + uint16_t msize = ntohs (hdr->size); + size_t size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + + msize; char buf[size]; if (NULL == endpoint) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } if (size >= GNUNET_MAX_MESSAGE_SIZE) - { - GNUNET_break(0); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sending ACK to %s\n", - mac_to_string(&endpoint->wlan_addr.mac)); - radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)buf; - get_radiotap_header(endpoint, radio_header, size); - get_wlan_header(endpoint->plugin, - &radio_header->frame, - &endpoint->wlan_addr.mac, - sizeof(endpoint->wlan_addr.mac)); - GNUNET_memcpy(&radio_header[1], hdr, msize); + { + GNUNET_break (0); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending ACK to %s\n", + mac_to_string (&endpoint->wlan_addr.mac)); + radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf; + get_radiotap_header (endpoint, radio_header, size); + get_wlan_header (endpoint->plugin, + &radio_header->frame, + &endpoint->wlan_addr.mac, + sizeof(endpoint->wlan_addr.mac)); + GNUNET_memcpy (&radio_header[1], hdr, msize); if (NULL != - GNUNET_HELPER_send(endpoint->plugin->suid_helper, - &radio_header->header, - GNUNET_NO /* dropping ACKs is bad */, - NULL, NULL)) - GNUNET_STATISTICS_update(endpoint->plugin->env->stats, - _("# ACKs sent"), - 1, GNUNET_NO); + GNUNET_HELPER_send (endpoint->plugin->suid_helper, + &radio_header->header, + GNUNET_NO /* dropping ACKs is bad */, + NULL, NULL)) + GNUNET_STATISTICS_update (endpoint->plugin->env->stats, + _ ("# ACKs sent"), + 1, GNUNET_NO); } @@ -760,24 +777,24 @@ send_ack(void *cls, * @param hdr pointer to the data */ static void -wlan_data_message_handler(void *cls, - const struct GNUNET_MessageHeader *hdr) +wlan_data_message_handler (void *cls, + const struct GNUNET_MessageHeader *hdr) { struct MacEndpoint *endpoint = cls; struct Plugin *plugin = endpoint->plugin; struct MacAndSession mas; - GNUNET_STATISTICS_update(plugin->env->stats, - _("# Messages defragmented"), - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# Messages defragmented"), + 1, + GNUNET_NO); mas.session = NULL; mas.endpoint = endpoint; - (void)GNUNET_SERVER_mst_receive(plugin->fragment_data_tokenizer, - &mas, - (const char *)hdr, - ntohs(hdr->size), - GNUNET_YES, GNUNET_NO); + (void) GNUNET_SERVER_mst_receive (plugin->fragment_data_tokenizer, + &mas, + (const char *) hdr, + ntohs (hdr->size), + GNUNET_YES, GNUNET_NO); } @@ -788,32 +805,32 @@ wlan_data_message_handler(void *cls, * @param session the session free */ static int -wlan_plugin_disconnect_session(void *cls, - struct GNUNET_ATS_Session *session) +wlan_plugin_disconnect_session (void *cls, + struct GNUNET_ATS_Session *session) { struct MacEndpoint *endpoint = session->mac; struct Plugin *plugin = endpoint->plugin; - plugin->env->session_end(plugin->env->cls, - session->address, - session); - notify_session_monitor(plugin, - session, - GNUNET_TRANSPORT_SS_DONE); - GNUNET_CONTAINER_DLL_remove(endpoint->sessions_head, - endpoint->sessions_tail, - session); + plugin->env->session_end (plugin->env->cls, + session->address, + session); + notify_session_monitor (plugin, + session, + GNUNET_TRANSPORT_SS_DONE); + GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, + endpoint->sessions_tail, + session); if (session->timeout_task != NULL) - { - GNUNET_SCHEDULER_cancel(session->timeout_task); - session->timeout_task = NULL; - } - GNUNET_STATISTICS_update(plugin->env->stats, - _("# Sessions allocated"), - -1, - GNUNET_NO); - GNUNET_HELLO_address_free(session->address); - GNUNET_free(session); + { + GNUNET_SCHEDULER_cancel (session->timeout_task); + session->timeout_task = NULL; + } + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# Sessions allocated"), + -1, + GNUNET_NO); + GNUNET_HELLO_address_free (session->address); + GNUNET_free (session); return GNUNET_OK; } @@ -827,7 +844,7 @@ wlan_plugin_disconnect_session(void *cls, * @return keepalive factor */ static unsigned int -wlan_plugin_query_keepalive_factor(void *cls) +wlan_plugin_query_keepalive_factor (void *cls) { return 3; } @@ -839,23 +856,23 @@ wlan_plugin_query_keepalive_factor(void *cls) * @param cls pointer to the Session */ static void -session_timeout(void *cls) +session_timeout (void *cls) { struct GNUNET_ATS_Session *session = cls; struct GNUNET_TIME_Relative left; session->timeout_task = NULL; - left = GNUNET_TIME_absolute_get_remaining(session->timeout); + left = GNUNET_TIME_absolute_get_remaining (session->timeout); if (0 != left.rel_value_us) - { - session->timeout_task = - GNUNET_SCHEDULER_add_delayed(left, - &session_timeout, - session); - return; - } - wlan_plugin_disconnect_session(session->mac->plugin, - session); + { + session->timeout_task = + GNUNET_SCHEDULER_add_delayed (left, + &session_timeout, + session); + return; + } + wlan_plugin_disconnect_session (session->mac->plugin, + session); } @@ -868,13 +885,15 @@ session_timeout(void *cls) * @return returns the session or NULL */ static struct GNUNET_ATS_Session * -lookup_session(struct MacEndpoint *endpoint, - const struct GNUNET_PeerIdentity *peer) +lookup_session (struct MacEndpoint *endpoint, + const struct GNUNET_PeerIdentity *peer) { struct GNUNET_ATS_Session *session; - for (session = endpoint->sessions_head; NULL != session; session = session->next) - if (0 == memcmp(peer, &session->target, sizeof(struct GNUNET_PeerIdentity))) + for (session = endpoint->sessions_head; NULL != session; session = + session->next) + if (0 == memcmp (peer, &session->target, sizeof(struct + GNUNET_PeerIdentity))) return session; return NULL; } @@ -888,41 +907,43 @@ lookup_session(struct MacEndpoint *endpoint, * @return returns the session or NULL */ static struct GNUNET_ATS_Session * -create_session(struct MacEndpoint *endpoint, - const struct GNUNET_PeerIdentity *peer) +create_session (struct MacEndpoint *endpoint, + const struct GNUNET_PeerIdentity *peer) { struct GNUNET_ATS_Session *session; - GNUNET_STATISTICS_update(endpoint->plugin->env->stats, - _("# Sessions allocated"), - 1, - GNUNET_NO); - session = GNUNET_new(struct GNUNET_ATS_Session); - GNUNET_CONTAINER_DLL_insert_tail(endpoint->sessions_head, - endpoint->sessions_tail, - session); - session->address = GNUNET_HELLO_address_allocate(peer, - PLUGIN_NAME, - &endpoint->wlan_addr, - sizeof(endpoint->wlan_addr), - GNUNET_HELLO_ADDRESS_INFO_NONE); + GNUNET_STATISTICS_update (endpoint->plugin->env->stats, + _ ("# Sessions allocated"), + 1, + GNUNET_NO); + session = GNUNET_new (struct GNUNET_ATS_Session); + GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head, + endpoint->sessions_tail, + session); + session->address = GNUNET_HELLO_address_allocate (peer, + PLUGIN_NAME, + &endpoint->wlan_addr, + sizeof(endpoint->wlan_addr), + GNUNET_HELLO_ADDRESS_INFO_NONE); session->mac = endpoint; session->target = *peer; - session->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + session->timeout = GNUNET_TIME_relative_to_absolute ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); session->timeout_task = - GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, - session); - notify_session_monitor(endpoint->plugin, - session, - GNUNET_TRANSPORT_SS_INIT); - notify_session_monitor(endpoint->plugin, - session, - GNUNET_TRANSPORT_SS_UP); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Created new session %p for peer `%s' with endpoint %s\n", - session, - GNUNET_i2s(peer), - mac_to_string(&endpoint->wlan_addr.mac)); + GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + &session_timeout, + session); + notify_session_monitor (endpoint->plugin, + session, + GNUNET_TRANSPORT_SS_INIT); + notify_session_monitor (endpoint->plugin, + session, + GNUNET_TRANSPORT_SS_UP); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Created new session %p for peer `%s' with endpoint %s\n", + session, + GNUNET_i2s (peer), + mac_to_string (&endpoint->wlan_addr.mac)); return session; } @@ -936,14 +957,14 @@ create_session(struct MacEndpoint *endpoint, * @return returns the session */ static struct GNUNET_ATS_Session * -get_session(struct MacEndpoint *endpoint, - const struct GNUNET_PeerIdentity *peer) +get_session (struct MacEndpoint *endpoint, + const struct GNUNET_PeerIdentity *peer) { struct GNUNET_ATS_Session *session; - if (NULL != (session = lookup_session(endpoint, peer))) + if (NULL != (session = lookup_session (endpoint, peer))) return session; - return create_session(endpoint, peer); + return create_session (endpoint, peer); } @@ -958,13 +979,13 @@ get_session(struct MacEndpoint *endpoint, * if the helper was stopped) */ static void -fragment_transmission_done(void *cls, - int result) +fragment_transmission_done (void *cls, + int result) { struct FragmentMessage *fm = cls; fm->sh = NULL; - GNUNET_FRAGMENT_context_transmission_done(fm->fragcontext); + GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext); } @@ -975,8 +996,8 @@ fragment_transmission_done(void *cls, * @param hdr pointer to the start of the fragment message */ static void -transmit_fragment(void *cls, - const struct GNUNET_MessageHeader *hdr) +transmit_fragment (void *cls, + const struct GNUNET_MessageHeader *hdr) { struct FragmentMessage *fm = cls; struct MacEndpoint *endpoint = fm->macendpoint; @@ -984,51 +1005,51 @@ transmit_fragment(void *cls, uint16_t msize; if (NULL == endpoint) - { - GNUNET_break(0); - return; - } - msize = ntohs(hdr->size); + { + GNUNET_break (0); + return; + } + msize = ntohs (hdr->size); size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize; { char buf[size]; struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radio_header; - radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)buf; - get_radiotap_header(endpoint, radio_header, size); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sending %u bytes of data to MAC `%s'\n", - (unsigned int)msize, - mac_to_string(&endpoint->wlan_addr.mac)); - - get_wlan_header(endpoint->plugin, - &radio_header->frame, - &endpoint->wlan_addr.mac, - sizeof(endpoint->wlan_addr.mac)); - GNUNET_memcpy(&radio_header[1], hdr, msize); - GNUNET_assert(NULL == fm->sh); - fm->sh = GNUNET_HELPER_send(endpoint->plugin->suid_helper, - &radio_header->header, - GNUNET_NO, - &fragment_transmission_done, fm); + radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf; + get_radiotap_header (endpoint, radio_header, size); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending %u bytes of data to MAC `%s'\n", + (unsigned int) msize, + mac_to_string (&endpoint->wlan_addr.mac)); + + get_wlan_header (endpoint->plugin, + &radio_header->frame, + &endpoint->wlan_addr.mac, + sizeof(endpoint->wlan_addr.mac)); + GNUNET_memcpy (&radio_header[1], hdr, msize); + GNUNET_assert (NULL == fm->sh); + fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, + &radio_header->header, + GNUNET_NO, + &fragment_transmission_done, fm); fm->size_on_wire += size; if (NULL != fm->sh) - { - GNUNET_STATISTICS_update(endpoint->plugin->env->stats, - _("# message fragments sent"), - 1, - GNUNET_NO); - } + { + GNUNET_STATISTICS_update (endpoint->plugin->env->stats, + _ ("# message fragments sent"), + 1, + GNUNET_NO); + } else - { - GNUNET_FRAGMENT_context_transmission_done(fm->fragcontext); - } - GNUNET_STATISTICS_update(endpoint->plugin->env->stats, - "# bytes currently in buffers", - -msize, GNUNET_NO); - GNUNET_STATISTICS_update(endpoint->plugin->env->stats, - "# bytes transmitted", - msize, GNUNET_NO); + { + GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext); + } + GNUNET_STATISTICS_update (endpoint->plugin->env->stats, + "# bytes currently in buffers", + -msize, GNUNET_NO); + GNUNET_STATISTICS_update (endpoint->plugin->env->stats, + "# bytes transmitted", + msize, GNUNET_NO); } } @@ -1039,39 +1060,39 @@ transmit_fragment(void *cls, * @param fm message to free */ static void -free_fragment_message(struct FragmentMessage *fm) +free_fragment_message (struct FragmentMessage *fm) { struct MacEndpoint *endpoint = fm->macendpoint; - GNUNET_STATISTICS_update(endpoint->plugin->env->stats, - _("# messages pending (with fragmentation)"), - -1, GNUNET_NO); - GNUNET_CONTAINER_DLL_remove(endpoint->sending_messages_head, - endpoint->sending_messages_tail, - fm); + GNUNET_STATISTICS_update (endpoint->plugin->env->stats, + _ ("# messages pending (with fragmentation)"), + -1, GNUNET_NO); + GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head, + endpoint->sending_messages_tail, + fm); if (NULL != fm->sh) - { - GNUNET_HELPER_send_cancel(fm->sh); - fm->sh = NULL; - } + { + GNUNET_HELPER_send_cancel (fm->sh); + fm->sh = NULL; + } if (NULL != fm->msg) - { - GNUNET_free(fm->msg); - fm->msg = NULL; - } + { + GNUNET_free (fm->msg); + fm->msg = NULL; + } if (NULL != fm->fragcontext) - { - GNUNET_FRAGMENT_context_destroy(fm->fragcontext, - &endpoint->msg_delay, - &endpoint->ack_delay); - fm->fragcontext = NULL; - } + { + GNUNET_FRAGMENT_context_destroy (fm->fragcontext, + &endpoint->msg_delay, + &endpoint->ack_delay); + fm->fragcontext = NULL; + } if (NULL != fm->timeout_task) - { - GNUNET_SCHEDULER_cancel(fm->timeout_task); - fm->timeout_task = NULL; - } - GNUNET_free(fm); + { + GNUNET_SCHEDULER_cancel (fm->timeout_task); + fm->timeout_task = NULL; + } + GNUNET_free (fm); } @@ -1081,21 +1102,21 @@ free_fragment_message(struct FragmentMessage *fm) * @param cls pointer to the 'struct FragmentMessage' */ static void -fragmentmessage_timeout(void *cls) +fragmentmessage_timeout (void *cls) { struct FragmentMessage *fm = cls; fm->timeout_task = NULL; if (NULL != fm->cont) - { - fm->cont(fm->cont_cls, - &fm->target, - GNUNET_SYSERR, - fm->size_payload, - fm->size_on_wire); - fm->cont = NULL; - } - free_fragment_message(fm); + { + fm->cont (fm->cont_cls, + &fm->target, + GNUNET_SYSERR, + fm->size_payload, + fm->size_on_wire); + fm->cont = NULL; + } + free_fragment_message (fm); } @@ -1114,49 +1135,49 @@ fragmentmessage_timeout(void *cls) * @param cont_cls closure for @a cont */ static void -send_with_fragmentation(struct MacEndpoint *endpoint, - struct GNUNET_TIME_Relative timeout, - const struct GNUNET_PeerIdentity *target, - const struct GNUNET_MessageHeader *msg, - size_t payload_size, - GNUNET_TRANSPORT_TransmitContinuation cont, - void *cont_cls) +send_with_fragmentation (struct MacEndpoint *endpoint, + struct GNUNET_TIME_Relative timeout, + const struct GNUNET_PeerIdentity *target, + const struct GNUNET_MessageHeader *msg, + size_t payload_size, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { struct FragmentMessage *fm; struct Plugin *plugin; plugin = endpoint->plugin; - fm = GNUNET_new(struct FragmentMessage); + fm = GNUNET_new (struct FragmentMessage); fm->macendpoint = endpoint; fm->target = *target; fm->size_payload = payload_size; - fm->timeout = GNUNET_TIME_relative_to_absolute(timeout); + fm->timeout = GNUNET_TIME_relative_to_absolute (timeout); fm->cont = cont; fm->cont_cls = cont_cls; /* 1 MBit/s typical data rate, 1430 byte fragments => ~100 ms per message */ fm->timeout_task = - GNUNET_SCHEDULER_add_delayed(timeout, - &fragmentmessage_timeout, - fm); + GNUNET_SCHEDULER_add_delayed (timeout, + &fragmentmessage_timeout, + fm); if (GNUNET_YES == plugin->have_mac) - { - fm->fragcontext = - GNUNET_FRAGMENT_context_create(plugin->env->stats, - WLAN_MTU, - &plugin->tracker, - fm->macendpoint->msg_delay, - fm->macendpoint->ack_delay, - msg, - &transmit_fragment, fm); - } + { + fm->fragcontext = + GNUNET_FRAGMENT_context_create (plugin->env->stats, + WLAN_MTU, + &plugin->tracker, + fm->macendpoint->msg_delay, + fm->macendpoint->ack_delay, + msg, + &transmit_fragment, fm); + } else - { - fm->msg = GNUNET_copy_message(msg); - } - GNUNET_CONTAINER_DLL_insert_tail(endpoint->sending_messages_head, - endpoint->sending_messages_tail, - fm); + { + fm->msg = GNUNET_copy_message (msg); + } + GNUNET_CONTAINER_DLL_insert_tail (endpoint->sending_messages_head, + endpoint->sending_messages_tail, + fm); } @@ -1166,38 +1187,38 @@ send_with_fragmentation(struct MacEndpoint *endpoint, * @param endpoint pointer to the MacEndpoint to free */ static void -free_macendpoint(struct MacEndpoint *endpoint) +free_macendpoint (struct MacEndpoint *endpoint) { struct Plugin *plugin = endpoint->plugin; struct FragmentMessage *fm; struct GNUNET_ATS_Session *session; - GNUNET_STATISTICS_update(plugin->env->stats, - _("# MAC endpoints allocated"), - -1, - GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# MAC endpoints allocated"), + -1, + GNUNET_NO); while (NULL != (session = endpoint->sessions_head)) - wlan_plugin_disconnect_session(plugin, - session); + wlan_plugin_disconnect_session (plugin, + session); while (NULL != (fm = endpoint->sending_messages_head)) - free_fragment_message(fm); - GNUNET_CONTAINER_DLL_remove(plugin->mac_head, - plugin->mac_tail, - endpoint); + free_fragment_message (fm); + GNUNET_CONTAINER_DLL_remove (plugin->mac_head, + plugin->mac_tail, + endpoint); if (NULL != endpoint->defrag) - { - GNUNET_DEFRAGMENT_context_destroy(endpoint->defrag); - endpoint->defrag = NULL; - } + { + GNUNET_DEFRAGMENT_context_destroy (endpoint->defrag); + endpoint->defrag = NULL; + } plugin->mac_count--; if (NULL != endpoint->timeout_task) - { - GNUNET_SCHEDULER_cancel(endpoint->timeout_task); - endpoint->timeout_task = NULL; - } - GNUNET_free(endpoint); + { + GNUNET_SCHEDULER_cancel (endpoint->timeout_task); + endpoint->timeout_task = NULL; + } + GNUNET_free (endpoint); } @@ -1207,22 +1228,22 @@ free_macendpoint(struct MacEndpoint *endpoint) * @param cls pointer to the `struct MacEndpoint *` */ static void -macendpoint_timeout(void *cls) +macendpoint_timeout (void *cls) { struct MacEndpoint *endpoint = cls; struct GNUNET_TIME_Relative timeout; endpoint->timeout_task = NULL; - timeout = GNUNET_TIME_absolute_get_remaining(endpoint->timeout); + timeout = GNUNET_TIME_absolute_get_remaining (endpoint->timeout); if (0 == timeout.rel_value_us) - { - free_macendpoint(endpoint); - return; - } + { + free_macendpoint (endpoint); + return; + } endpoint->timeout_task = - GNUNET_SCHEDULER_add_delayed(timeout, - &macendpoint_timeout, - endpoint); + GNUNET_SCHEDULER_add_delayed (timeout, + &macendpoint_timeout, + endpoint); } @@ -1234,43 +1255,44 @@ macendpoint_timeout(void *cls) * @return handle to our data structure for this MAC */ static struct MacEndpoint * -create_macendpoint(struct Plugin *plugin, - struct WlanAddress *mac) +create_macendpoint (struct Plugin *plugin, + struct WlanAddress *mac) { struct MacEndpoint *pos; for (pos = plugin->mac_head; NULL != pos; pos = pos->next) - if (0 == memcmp(mac, &pos->wlan_addr, sizeof(pos->wlan_addr))) + if (0 == memcmp (mac, &pos->wlan_addr, sizeof(pos->wlan_addr))) return pos; - pos = GNUNET_new(struct MacEndpoint); + pos = GNUNET_new (struct MacEndpoint); pos->wlan_addr = (*mac); pos->plugin = plugin; pos->defrag = - GNUNET_DEFRAGMENT_context_create(plugin->env->stats, - WLAN_MTU, - MESSAGES_IN_DEFRAG_QUEUE_PER_MAC, - pos, - &wlan_data_message_handler, - &send_ack); + GNUNET_DEFRAGMENT_context_create (plugin->env->stats, + WLAN_MTU, + MESSAGES_IN_DEFRAG_QUEUE_PER_MAC, + pos, + &wlan_data_message_handler, + &send_ack); pos->msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; - pos->ack_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100); - pos->timeout = GNUNET_TIME_relative_to_absolute(MACENDPOINT_TIMEOUT); + pos->ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, + 100); + pos->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); pos->timeout_task = - GNUNET_SCHEDULER_add_delayed(MACENDPOINT_TIMEOUT, &macendpoint_timeout, - pos); - GNUNET_CONTAINER_DLL_insert(plugin->mac_head, - plugin->mac_tail, - pos); + GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout, + pos); + GNUNET_CONTAINER_DLL_insert (plugin->mac_head, + plugin->mac_tail, + pos); plugin->mac_count++; - GNUNET_STATISTICS_update(plugin->env->stats, - _("# MAC endpoints allocated"), - 1, GNUNET_NO); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "New MAC endpoint `%s'\n", - wlan_plugin_address_to_string(NULL, - &pos->wlan_addr, - sizeof(struct WlanAddress))); + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# MAC endpoints allocated"), + 1, GNUNET_NO); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New MAC endpoint `%s'\n", + wlan_plugin_address_to_string (NULL, + &pos->wlan_addr, + sizeof(struct WlanAddress))); return pos; } @@ -1283,8 +1305,8 @@ create_macendpoint(struct Plugin *plugin, * @return the network type in HBO or #GNUNET_SYSERR */ static enum GNUNET_NetworkType -wlan_plugin_get_network(void *cls, - struct GNUNET_ATS_Session *session) +wlan_plugin_get_network (void *cls, + struct GNUNET_ATS_Session *session) { #if BUILD_WLAN return GNUNET_NT_WLAN; @@ -1302,8 +1324,8 @@ wlan_plugin_get_network(void *cls, * @return the network type */ static enum GNUNET_NetworkType -wlan_plugin_get_network_for_address(void *cls, - const struct GNUNET_HELLO_Address *address) +wlan_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) { #if BUILD_WLAN return GNUNET_NT_WLAN; @@ -1322,8 +1344,8 @@ wlan_plugin_get_network_for_address(void *cls, * @return the session or NULL of max connections exceeded */ static struct GNUNET_ATS_Session * -wlan_plugin_get_session(void *cls, - const struct GNUNET_HELLO_Address *address) +wlan_plugin_get_session (void *cls, + const struct GNUNET_HELLO_Address *address) { struct Plugin *plugin = cls; struct MacEndpoint *endpoint; @@ -1331,19 +1353,19 @@ wlan_plugin_get_session(void *cls, if (NULL == address) return NULL; if (sizeof(struct WlanAddress) != address->address_length) - { - GNUNET_break(0); - return NULL; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Service asked to create session for peer `%s' with MAC `%s'\n", - GNUNET_i2s(&address->peer), - wlan_plugin_address_to_string(NULL, - address->address, - address->address_length)); - endpoint = create_macendpoint(plugin, - (struct WlanAddress *)address->address); - return get_session(endpoint, &address->peer); + { + GNUNET_break (0); + return NULL; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Service asked to create session for peer `%s' with MAC `%s'\n", + GNUNET_i2s (&address->peer), + wlan_plugin_address_to_string (NULL, + address->address, + address->address_length)); + endpoint = create_macendpoint (plugin, + (struct WlanAddress *) address->address); + return get_session (endpoint, &address->peer); } @@ -1356,21 +1378,22 @@ wlan_plugin_get_session(void *cls, * @param target peer from which to disconnect */ static void -wlan_plugin_disconnect_peer(void *cls, - const struct GNUNET_PeerIdentity *target) +wlan_plugin_disconnect_peer (void *cls, + const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; struct GNUNET_ATS_Session *session; struct MacEndpoint *endpoint; for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next) - for (session = endpoint->sessions_head; NULL != session; session = session->next) - if (0 == memcmp(target, &session->target, - sizeof(struct GNUNET_PeerIdentity))) - { - wlan_plugin_disconnect_session(plugin, session); - break; /* inner-loop only (in case peer has another MAC as well!) */ - } + for (session = endpoint->sessions_head; NULL != session; session = + session->next) + if (0 == memcmp (target, &session->target, + sizeof(struct GNUNET_PeerIdentity))) + { + wlan_plugin_disconnect_session (plugin, session); + break; /* inner-loop only (in case peer has another MAC as well!) */ + } } @@ -1402,43 +1425,43 @@ wlan_plugin_disconnect_peer(void *cls, * and does NOT mean that the message was not transmitted (DV) */ static ssize_t -wlan_plugin_send(void *cls, - struct GNUNET_ATS_Session *session, - const char *msgbuf, size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) +wlan_plugin_send (void *cls, + struct GNUNET_ATS_Session *session, + const char *msgbuf, size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { struct Plugin *plugin = cls; struct WlanHeader *wlanheader; size_t size = msgbuf_size + sizeof(struct WlanHeader); char buf[size] GNUNET_ALIGN; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Transmitting %u bytes of payload to peer `%s' (starting with %u byte message of type %u)\n", - msgbuf_size, - GNUNET_i2s(&session->target), - (unsigned int)ntohs(((struct GNUNET_MessageHeader*)msgbuf)->size), - (unsigned int)ntohs(((struct GNUNET_MessageHeader*)msgbuf)->type)); - wlanheader = (struct WlanHeader *)buf; - wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader)); - wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting %u bytes of payload to peer `%s' (starting with %u byte message of type %u)\n", + msgbuf_size, + GNUNET_i2s (&session->target), + (unsigned int) ntohs (((struct GNUNET_MessageHeader*) msgbuf)->size), + (unsigned int) ntohs (((struct GNUNET_MessageHeader*) msgbuf)->type)); + wlanheader = (struct WlanHeader *) buf; + wlanheader->header.size = htons (msgbuf_size + sizeof(struct WlanHeader)); + wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA); wlanheader->sender = *plugin->env->my_identity; wlanheader->target = session->target; - wlanheader->crc = htonl(GNUNET_CRYPTO_crc32_n(msgbuf, msgbuf_size)); - GNUNET_memcpy(&wlanheader[1], - msgbuf, - msgbuf_size); - GNUNET_STATISTICS_update(plugin->env->stats, - "# bytes currently in buffers", + wlanheader->crc = htonl (GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size)); + GNUNET_memcpy (&wlanheader[1], + msgbuf, + msgbuf_size); + GNUNET_STATISTICS_update (plugin->env->stats, + "# bytes currently in buffers", + msgbuf_size, + GNUNET_NO); + send_with_fragmentation (session->mac, + to, + &session->target, + &wlanheader->header, msgbuf_size, - GNUNET_NO); - send_with_fragmentation(session->mac, - to, - &session->target, - &wlanheader->header, - msgbuf_size, - cont, cont_cls); + cont, cont_cls); return size; } @@ -1452,9 +1475,9 @@ wlan_plugin_send(void *cls, * @param hdr start of the message */ static int -process_data(void *cls, - void *client, - const struct GNUNET_MessageHeader *hdr) +process_data (void *cls, + void *client, + const struct GNUNET_MessageHeader *hdr) { struct Plugin *plugin = cls; struct GNUNET_HELLO_Address *address; @@ -1465,221 +1488,224 @@ process_data(void *cls, int ret; uint16_t msize; - msize = ntohs(hdr->size); + msize = ntohs (hdr->size); - GNUNET_STATISTICS_update(plugin->env->stats, - "# bytes received", - msize, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# bytes received", + msize, GNUNET_NO); - switch (ntohs(hdr->type)) - { - case GNUNET_MESSAGE_TYPE_HELLO: + switch (ntohs (hdr->type)) + { + case GNUNET_MESSAGE_TYPE_HELLO: - if (GNUNET_OK != - GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)hdr, - &tmpsource)) - { - GNUNET_break_op(0); - break; - } - if (NULL == mas->endpoint) - { - GNUNET_break(0); - break; - } + if (GNUNET_OK != + GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hdr, + &tmpsource)) + { + GNUNET_break_op (0); + break; + } + if (NULL == mas->endpoint) + { + GNUNET_break (0); + break; + } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", - (unsigned int)msize, - GNUNET_i2s(&tmpsource), - wlan_plugin_address_to_string(NULL, + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", + (unsigned int) msize, + GNUNET_i2s (&tmpsource), + wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, sizeof(mas->endpoint->wlan_addr))); - GNUNET_STATISTICS_update(plugin->env->stats, - _("# HELLO messages received"), 1, - GNUNET_NO); - address = GNUNET_HELLO_address_allocate(&tmpsource, - PLUGIN_NAME, - &mas->endpoint->wlan_addr, - sizeof(mas->endpoint->wlan_addr), - GNUNET_HELLO_ADDRESS_INFO_NONE); - mas->session = lookup_session(mas->endpoint, - &tmpsource); - if (NULL == mas->session) - { - mas->session = create_session(mas->endpoint, - &tmpsource); - plugin->env->session_start(plugin->env->cls, - address, - mas->session, - scope); - } - plugin->env->receive(plugin->env->cls, - address, - mas->session, - hdr); - GNUNET_HELLO_address_free(address); + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# HELLO messages received"), 1, + GNUNET_NO); + address = GNUNET_HELLO_address_allocate (&tmpsource, + PLUGIN_NAME, + &mas->endpoint->wlan_addr, + sizeof(mas->endpoint->wlan_addr), + GNUNET_HELLO_ADDRESS_INFO_NONE); + mas->session = lookup_session (mas->endpoint, + &tmpsource); + if (NULL == mas->session) + { + mas->session = create_session (mas->endpoint, + &tmpsource); + plugin->env->session_start (plugin->env->cls, + address, + mas->session, + scope); + } + plugin->env->receive (plugin->env->cls, + address, + mas->session, + hdr); + GNUNET_HELLO_address_free (address); + break; + + case GNUNET_MESSAGE_TYPE_FRAGMENT: + if (NULL == mas->endpoint) + { + GNUNET_break (0); break; - - case GNUNET_MESSAGE_TYPE_FRAGMENT: - if (NULL == mas->endpoint) - { - GNUNET_break(0); - break; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Processing %u bytes of FRAGMENT from MAC %s\n", - (unsigned int)msize, - wlan_plugin_address_to_string(NULL, + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Processing %u bytes of FRAGMENT from MAC %s\n", + (unsigned int) msize, + wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, sizeof(mas->endpoint->wlan_addr))); - GNUNET_STATISTICS_update(plugin->env->stats, - _("# fragments received"), - 1, - GNUNET_NO); - (void)GNUNET_DEFRAGMENT_process_fragment(mas->endpoint->defrag, + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# fragments received"), + 1, + GNUNET_NO); + (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, hdr); - break; + break; - case GNUNET_MESSAGE_TYPE_FRAGMENT_ACK: - if (NULL == mas->endpoint) - { - GNUNET_break(0); - break; - } - GNUNET_STATISTICS_update(plugin->env->stats, - _("# ACKs received"), - 1, GNUNET_NO); - for (fm = mas->endpoint->sending_messages_head; NULL != fm; fm = fm->next) + case GNUNET_MESSAGE_TYPE_FRAGMENT_ACK: + if (NULL == mas->endpoint) + { + GNUNET_break (0); + break; + } + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# ACKs received"), + 1, GNUNET_NO); + for (fm = mas->endpoint->sending_messages_head; NULL != fm; fm = fm->next) + { + ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr); + if (GNUNET_OK == ret) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got last ACK, finished message transmission to `%s' (%p)\n", + wlan_plugin_address_to_string (NULL, + &mas->endpoint->wlan_addr, + sizeof(mas->endpoint->wlan_addr)), + fm); + mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute ( + MACENDPOINT_TIMEOUT); + if (NULL != fm->cont) { - ret = GNUNET_FRAGMENT_process_ack(fm->fragcontext, hdr); - if (GNUNET_OK == ret) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got last ACK, finished message transmission to `%s' (%p)\n", - wlan_plugin_address_to_string(NULL, - &mas->endpoint->wlan_addr, - sizeof(mas->endpoint->wlan_addr)), - fm); - mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute(MACENDPOINT_TIMEOUT); - if (NULL != fm->cont) - { - fm->cont(fm->cont_cls, - &fm->target, - GNUNET_OK, - fm->size_payload, - fm->size_on_wire); - fm->cont = NULL; - } - free_fragment_message(fm); - break; - } - if (GNUNET_NO == ret) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got an ACK, message transmission to `%s' not yet finished\n", - wlan_plugin_address_to_string(NULL, - &mas->endpoint->wlan_addr, - sizeof(mas->endpoint->wlan_addr))); - break; - } + fm->cont (fm->cont_cls, + &fm->target, + GNUNET_OK, + fm->size_payload, + fm->size_on_wire); + fm->cont = NULL; } - if (NULL == fm) - LOG(GNUNET_ERROR_TYPE_DEBUG, - "ACK not matched against any active fragmentation with MAC `%s'\n", - wlan_plugin_address_to_string(NULL, + free_fragment_message (fm); + break; + } + if (GNUNET_NO == ret) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got an ACK, message transmission to `%s' not yet finished\n", + wlan_plugin_address_to_string (NULL, + &mas->endpoint->wlan_addr, + sizeof(mas->endpoint->wlan_addr))); + break; + } + } + if (NULL == fm) + LOG (GNUNET_ERROR_TYPE_DEBUG, + "ACK not matched against any active fragmentation with MAC `%s'\n", + wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, sizeof(mas->endpoint->wlan_addr))); - break; + break; - case GNUNET_MESSAGE_TYPE_WLAN_DATA: - if (NULL == mas->endpoint) - { - GNUNET_break(0); - break; - } - if (msize < sizeof(struct WlanHeader)) - { - GNUNET_break(0); - break; - } - wlanheader = (const struct WlanHeader *)hdr; - if (0 != memcmp(&wlanheader->target, - plugin->env->my_identity, - sizeof(struct GNUNET_PeerIdentity))) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Data for `%s', not for me, ignoring\n", - GNUNET_i2s(&wlanheader->target)); - break; - } - if (ntohl(wlanheader->crc) != - GNUNET_CRYPTO_crc32_n(&wlanheader[1], - msize - sizeof(struct WlanHeader))) - { - GNUNET_STATISTICS_update(plugin->env->stats, - _("# DATA messages discarded due to CRC32 error"), - 1, - GNUNET_NO); - break; - } - mas->session = lookup_session(mas->endpoint, - &wlanheader->sender); - if (NULL == mas->session) - { - mas->session = create_session(mas->endpoint, - &wlanheader->sender); - address = GNUNET_HELLO_address_allocate(&wlanheader->sender, - PLUGIN_NAME, - &mas->endpoint->wlan_addr, - sizeof(struct WlanAddress), - GNUNET_HELLO_ADDRESS_INFO_NONE); - plugin->env->session_start(plugin->env->cls, - address, - mas->session, - scope); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Notifying transport about peer `%s''s new session %p \n", - GNUNET_i2s(&wlanheader->sender), - mas->session); - GNUNET_HELLO_address_free(address); - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Processing %u bytes of DATA from peer `%s'\n", - (unsigned int)msize, - GNUNET_i2s(&wlanheader->sender)); - mas->session->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); - (void)GNUNET_SERVER_mst_receive(plugin->wlan_header_payload_tokenizer, + case GNUNET_MESSAGE_TYPE_WLAN_DATA: + if (NULL == mas->endpoint) + { + GNUNET_break (0); + break; + } + if (msize < sizeof(struct WlanHeader)) + { + GNUNET_break (0); + break; + } + wlanheader = (const struct WlanHeader *) hdr; + if (0 != memcmp (&wlanheader->target, + plugin->env->my_identity, + sizeof(struct GNUNET_PeerIdentity))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Data for `%s', not for me, ignoring\n", + GNUNET_i2s (&wlanheader->target)); + break; + } + if (ntohl (wlanheader->crc) != + GNUNET_CRYPTO_crc32_n (&wlanheader[1], + msize - sizeof(struct WlanHeader))) + { + GNUNET_STATISTICS_update (plugin->env->stats, + _ ( + "# DATA messages discarded due to CRC32 error"), + 1, + GNUNET_NO); + break; + } + mas->session = lookup_session (mas->endpoint, + &wlanheader->sender); + if (NULL == mas->session) + { + mas->session = create_session (mas->endpoint, + &wlanheader->sender); + address = GNUNET_HELLO_address_allocate (&wlanheader->sender, + PLUGIN_NAME, + &mas->endpoint->wlan_addr, + sizeof(struct WlanAddress), + GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->session_start (plugin->env->cls, + address, + mas->session, + scope); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Notifying transport about peer `%s''s new session %p \n", + GNUNET_i2s (&wlanheader->sender), + mas->session); + GNUNET_HELLO_address_free (address); + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Processing %u bytes of DATA from peer `%s'\n", + (unsigned int) msize, + GNUNET_i2s (&wlanheader->sender)); + mas->session->timeout = GNUNET_TIME_relative_to_absolute ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer, mas, - (const char *)&wlanheader[1], + (const char *) &wlanheader[1], msize - sizeof(struct WlanHeader), GNUNET_YES, GNUNET_NO); - break; + break; - default: - if (NULL == mas->endpoint) - { - GNUNET_break(0); - break; - } - if (NULL == mas->session) - { - GNUNET_break(0); - break; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received packet with %u bytes of type %u from peer %s\n", - (unsigned int)msize, - (unsigned int)ntohs(hdr->type), - GNUNET_i2s(&mas->session->target)); - plugin->env->receive(plugin->env->cls, - mas->session->address, - mas->session, - hdr); + default: + if (NULL == mas->endpoint) + { + GNUNET_break (0); + break; + } + if (NULL == mas->session) + { + GNUNET_break (0); break; } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received packet with %u bytes of type %u from peer %s\n", + (unsigned int) msize, + (unsigned int) ntohs (hdr->type), + GNUNET_i2s (&mas->session->target)); + plugin->env->receive (plugin->env->cls, + mas->session->address, + mas->session, + hdr); + break; + } return GNUNET_OK; } @@ -1690,7 +1716,7 @@ process_data(void *cls, * @param cls pointer to the plugin struct */ static void -send_hello_beacon(void *cls) +send_hello_beacon (void *cls) { struct Plugin *plugin = cls; uint16_t size; @@ -1698,42 +1724,43 @@ send_hello_beacon(void *cls) struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader; const struct GNUNET_MessageHeader *hello; - hello = plugin->env->get_our_hello(); + hello = plugin->env->get_our_hello (); if (NULL != hello) + { + hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); + GNUNET_assert (sizeof(struct WlanHeader) + hello_size <= WLAN_MTU); + size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + + hello_size; { - hello_size = GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)hello); - GNUNET_assert(sizeof(struct WlanHeader) + hello_size <= WLAN_MTU); - size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size; - { - char buf[size] GNUNET_ALIGN; - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Sending %u byte HELLO beacon\n", - (unsigned int)size); - radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*)buf; - get_radiotap_header(NULL, radioHeader, size); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Broadcasting %u bytes of data to MAC `%s'\n", - (unsigned int)size, - mac_to_string(&bc_all_mac)); - get_wlan_header(plugin, &radioHeader->frame, &bc_all_mac, size); - GNUNET_memcpy(&radioHeader[1], hello, hello_size); - if (NULL != - GNUNET_HELPER_send(plugin->suid_helper, - &radioHeader->header, - GNUNET_YES /* can drop */, - NULL, NULL)) - GNUNET_STATISTICS_update(plugin->env->stats, - _("# HELLO beacons sent"), - 1, GNUNET_NO); - } + char buf[size] GNUNET_ALIGN; + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending %u byte HELLO beacon\n", + (unsigned int) size); + radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*) buf; + get_radiotap_header (NULL, radioHeader, size); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Broadcasting %u bytes of data to MAC `%s'\n", + (unsigned int) size, + mac_to_string (&bc_all_mac)); + get_wlan_header (plugin, &radioHeader->frame, &bc_all_mac, size); + GNUNET_memcpy (&radioHeader[1], hello, hello_size); + if (NULL != + GNUNET_HELPER_send (plugin->suid_helper, + &radioHeader->header, + GNUNET_YES /* can drop */, + NULL, NULL)) + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# HELLO beacons sent"), + 1, GNUNET_NO); } + } plugin->beacon_task = - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply - (HELLO_BEACON_SCALING_FACTOR, - plugin->mac_count + 1), - &send_hello_beacon, - plugin); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (HELLO_BEACON_SCALING_FACTOR, + plugin->mac_count + 1), + &send_hello_beacon, + plugin); } @@ -1744,8 +1771,8 @@ send_hello_beacon(void *cls) * @param hdr header of the GNUNET_MessageHeader */ static int -handle_helper_message(void *cls, - const struct GNUNET_MessageHeader *hdr) +handle_helper_message (void *cls, + const struct GNUNET_MessageHeader *hdr) { struct Plugin *plugin = cls; struct GNUNET_HELLO_Address *my_address; @@ -1757,156 +1784,161 @@ handle_helper_message(void *cls, struct FragmentMessage *fm; struct MacEndpoint *endpoint; - msize = ntohs(hdr->size); - switch (ntohs(hdr->type)) + msize = ntohs (hdr->size); + switch (ntohs (hdr->type)) + { + case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL: + if (msize != sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)) { - case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL: - if (msize != sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)) - { - GNUNET_break(0); - break; - } - cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *)hdr; - if (GNUNET_YES == plugin->have_mac) - { - if (0 == memcmp(&plugin->mac_address, - &cm->mac, - sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) - break; /* no change */ - /* remove old address */ - memset(&wa, 0, sizeof(struct WlanAddress)); - wa.mac = plugin->mac_address; - wa.options = htonl(plugin->options); - my_address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - PLUGIN_NAME, - &wa, sizeof(wa), - GNUNET_HELLO_ADDRESS_INFO_NONE); - plugin->env->notify_address(plugin->env->cls, - GNUNET_NO, - my_address); - GNUNET_HELLO_address_free(my_address); - plugin->mac_address = cm->mac; - } - else - { - plugin->mac_address = cm->mac; - plugin->have_mac = GNUNET_YES; - for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next) - { - for (fm = endpoint->sending_messages_head; NULL != fm; fm = fm->next) - { - if (NULL != fm->fragcontext) - { - GNUNET_break(0); /* should not happen */ - continue; - } - fm->fragcontext = - GNUNET_FRAGMENT_context_create(plugin->env->stats, - WLAN_MTU, - &plugin->tracker, - fm->macendpoint->msg_delay, - fm->macendpoint->ack_delay, - fm->msg, - &transmit_fragment, fm); - GNUNET_free(fm->msg); - fm->msg = NULL; - } - } - GNUNET_break(NULL == plugin->beacon_task); - plugin->beacon_task = GNUNET_SCHEDULER_add_now(&send_hello_beacon, - plugin); - } - - memset(&wa, 0, sizeof(struct WlanAddress)); - wa.mac = plugin->mac_address; - wa.options = htonl(plugin->options); - my_address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - PLUGIN_NAME, - &wa, sizeof(wa), - GNUNET_HELLO_ADDRESS_INFO_NONE); - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n", - mac_to_string(&cm->mac), - GNUNET_i2s(plugin->env->my_identity)); - plugin->env->notify_address(plugin->env->cls, - GNUNET_YES, - my_address); - GNUNET_HELLO_address_free(my_address); + GNUNET_break (0); break; - - case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got data message from helper with %u bytes\n", - msize); - GNUNET_STATISTICS_update(plugin->env->stats, - _("# DATA messages received"), 1, - GNUNET_NO); - if (msize < sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Size of packet is too small (%u bytes < %u)\n", - msize, sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)); - break; - } - rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)hdr; - - /* check if message is actually for us */ - if (0 != memcmp(&rxinfo->frame.addr3, &mac_bssid_gnunet, - sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) - { - /* Not the GNUnet BSSID */ - break; - } - if ((0 != memcmp(&rxinfo->frame.addr1, &bc_all_mac, - sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) && - (0 != memcmp(&rxinfo->frame.addr1, &plugin->mac_address, - sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))) - { - /* Neither broadcast nor specifically for us */ - break; - } - if (0 == memcmp(&rxinfo->frame.addr2, &plugin->mac_address, - sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) + } + cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *) hdr; + if (GNUNET_YES == plugin->have_mac) + { + if (0 == memcmp (&plugin->mac_address, + &cm->mac, + sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) + break; /* no change */ + /* remove old address */ + memset (&wa, 0, sizeof(struct WlanAddress)); + wa.mac = plugin->mac_address; + wa.options = htonl (plugin->options); + my_address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, + &wa, sizeof(wa), + GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, + GNUNET_NO, + my_address); + GNUNET_HELLO_address_free (my_address); + plugin->mac_address = cm->mac; + } + else + { + plugin->mac_address = cm->mac; + plugin->have_mac = GNUNET_YES; + for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = + endpoint->next) + { + for (fm = endpoint->sending_messages_head; NULL != fm; fm = fm->next) { - /* packet is FROM us, thus not FOR us */ - break; + if (NULL != fm->fragcontext) + { + GNUNET_break (0); /* should not happen */ + continue; + } + fm->fragcontext = + GNUNET_FRAGMENT_context_create (plugin->env->stats, + WLAN_MTU, + &plugin->tracker, + fm->macendpoint->msg_delay, + fm->macendpoint->ack_delay, + fm->msg, + &transmit_fragment, fm); + GNUNET_free (fm->msg); + fm->msg = NULL; } + } + GNUNET_break (NULL == plugin->beacon_task); + plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon, + plugin); + } - GNUNET_STATISTICS_update(plugin->env->stats, - _("# DATA messages processed"), - 1, GNUNET_NO); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receiving %u bytes of data from MAC `%s'\n", - (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)), - mac_to_string(&rxinfo->frame.addr2)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receiving %u bytes of data to MAC `%s'\n", - (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)), - mac_to_string(&rxinfo->frame.addr1)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receiving %u bytes of data with BSSID MAC `%s'\n", - (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)), - mac_to_string(&rxinfo->frame.addr3)); - wa.mac = rxinfo->frame.addr2; - wa.options = htonl(0); - mas.endpoint = create_macendpoint(plugin, &wa); - mas.session = NULL; - (void)GNUNET_SERVER_mst_receive(plugin->helper_payload_tokenizer, - &mas, - (const char*)&rxinfo[1], - msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage), - GNUNET_YES, GNUNET_NO); + memset (&wa, 0, sizeof(struct WlanAddress)); + wa.mac = plugin->mac_address; + wa.options = htonl (plugin->options); + my_address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, + &wa, sizeof(wa), + GNUNET_HELLO_ADDRESS_INFO_NONE); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n", + mac_to_string (&cm->mac), + GNUNET_i2s (plugin->env->my_identity)); + plugin->env->notify_address (plugin->env->cls, + GNUNET_YES, + my_address); + GNUNET_HELLO_address_free (my_address); + break; + + case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got data message from helper with %u bytes\n", + msize); + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# DATA messages received"), 1, + GNUNET_NO); + if (msize < sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Size of packet is too small (%u bytes < %u)\n", + msize, sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)); break; + } + rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) hdr; - default: - GNUNET_break(0); - LOG(GNUNET_ERROR_TYPE_ERROR, - "Unexpected message of type %u (%u bytes)", - ntohs(hdr->type), - ntohs(hdr->size)); + /* check if message is actually for us */ + if (0 != memcmp (&rxinfo->frame.addr3, &mac_bssid_gnunet, + sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) + { + /* Not the GNUnet BSSID */ break; } + if ((0 != memcmp (&rxinfo->frame.addr1, &bc_all_mac, + sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) && + (0 != memcmp (&rxinfo->frame.addr1, &plugin->mac_address, + sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))) + { + /* Neither broadcast nor specifically for us */ + break; + } + if (0 == memcmp (&rxinfo->frame.addr2, &plugin->mac_address, + sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) + { + /* packet is FROM us, thus not FOR us */ + break; + } + + GNUNET_STATISTICS_update (plugin->env->stats, + _ ("# DATA messages processed"), + 1, GNUNET_NO); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receiving %u bytes of data from MAC `%s'\n", + (unsigned int) (msize - sizeof(struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)), + mac_to_string (&rxinfo->frame.addr2)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receiving %u bytes of data to MAC `%s'\n", + (unsigned int) (msize - sizeof(struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)), + mac_to_string (&rxinfo->frame.addr1)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receiving %u bytes of data with BSSID MAC `%s'\n", + (unsigned int) (msize - sizeof(struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)), + mac_to_string (&rxinfo->frame.addr3)); + wa.mac = rxinfo->frame.addr2; + wa.options = htonl (0); + mas.endpoint = create_macendpoint (plugin, &wa); + mas.session = NULL; + (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer, + &mas, + (const char*) &rxinfo[1], + msize - sizeof(struct + GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage), + GNUNET_YES, GNUNET_NO); + break; + + default: + GNUNET_break (0); + LOG (GNUNET_ERROR_TYPE_ERROR, + "Unexpected message of type %u (%u bytes)", + ntohs (hdr->type), + ntohs (hdr->size)); + break; + } return GNUNET_OK; } @@ -1924,34 +1956,34 @@ handle_helper_message(void *cls, * and transport */ static int -wlan_plugin_address_suggested(void *cls, - const void *addr, - size_t addrlen) +wlan_plugin_address_suggested (void *cls, + const void *addr, + size_t addrlen) { struct Plugin *plugin = cls; - struct WlanAddress *wa = (struct WlanAddress *)addr; + struct WlanAddress *wa = (struct WlanAddress *) addr; if (addrlen != sizeof(struct WlanAddress)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } if (GNUNET_YES != plugin->have_mac) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Rejecting MAC `%s': I don't know my MAC!\n", - mac_to_string(addr)); - return GNUNET_NO; /* don't know my MAC */ - } - if (0 != memcmp(&wa->mac, - &plugin->mac_address, - sizeof(wa->mac))) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Rejecting MAC `%s': not my MAC!\n", - mac_to_string(addr)); - return GNUNET_NO; /* not my MAC */ - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Rejecting MAC `%s': I don't know my MAC!\n", + mac_to_string (addr)); + return GNUNET_NO; /* don't know my MAC */ + } + if (0 != memcmp (&wa->mac, + &plugin->mac_address, + sizeof(wa->mac))) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Rejecting MAC `%s': not my MAC!\n", + mac_to_string (addr)); + return GNUNET_NO; /* not my MAC */ + } return GNUNET_OK; } @@ -1970,27 +2002,27 @@ wlan_plugin_address_suggested(void *cls, * @param asc_cls closure for @a asc */ static void -wlan_plugin_address_pretty_printer(void *cls, - const char *type, - const void *addr, - size_t addrlen, - int numeric, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback asc, - void *asc_cls) +wlan_plugin_address_pretty_printer (void *cls, + const char *type, + const void *addr, + size_t addrlen, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback asc, + void *asc_cls) { const char *ret; if (sizeof(struct WlanAddress) == addrlen) - ret = wlan_plugin_address_to_string(NULL, - addr, - addrlen); + ret = wlan_plugin_address_to_string (NULL, + addr, + addrlen); else ret = NULL; - asc(asc_cls, - ret, - (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); - asc(asc_cls, NULL, GNUNET_OK); + asc (asc_cls, + ret, + (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); + asc (asc_cls, NULL, GNUNET_OK); } @@ -2000,7 +2032,7 @@ wlan_plugin_address_pretty_printer(void *cls, * @param cls pointer to the api struct */ void * -LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) +LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) { struct WlanAddress wa; struct GNUNET_HELLO_Address *address; @@ -2010,62 +2042,62 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) struct MacEndpoint *endpoint_next; if (NULL == plugin) - { - GNUNET_free(api); - return NULL; - } + { + GNUNET_free (api); + return NULL; + } if (GNUNET_YES == plugin->have_mac) - { - memset(&wa, 0, sizeof(wa)); - wa.options = htonl(plugin->options); - wa.mac = plugin->mac_address; - address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, - PLUGIN_NAME, - &wa, sizeof(struct WlanAddress), - GNUNET_HELLO_ADDRESS_INFO_NONE); - - plugin->env->notify_address(plugin->env->cls, - GNUNET_NO, - address); - plugin->have_mac = GNUNET_NO; - GNUNET_HELLO_address_free(address); - } + { + memset (&wa, 0, sizeof(wa)); + wa.options = htonl (plugin->options); + wa.mac = plugin->mac_address; + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, + &wa, sizeof(struct WlanAddress), + GNUNET_HELLO_ADDRESS_INFO_NONE); + + plugin->env->notify_address (plugin->env->cls, + GNUNET_NO, + address); + plugin->have_mac = GNUNET_NO; + GNUNET_HELLO_address_free (address); + } if (NULL != plugin->beacon_task) - { - GNUNET_SCHEDULER_cancel(plugin->beacon_task); - plugin->beacon_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (plugin->beacon_task); + plugin->beacon_task = NULL; + } if (NULL != plugin->suid_helper) - { - GNUNET_HELPER_stop(plugin->suid_helper, - GNUNET_NO); - plugin->suid_helper = NULL; - } + { + GNUNET_HELPER_stop (plugin->suid_helper, + GNUNET_NO); + plugin->suid_helper = NULL; + } endpoint_next = plugin->mac_head; while (NULL != (endpoint = endpoint_next)) - { - endpoint_next = endpoint->next; - free_macendpoint(endpoint); - } + { + endpoint_next = endpoint->next; + free_macendpoint (endpoint); + } if (NULL != plugin->fragment_data_tokenizer) - { - GNUNET_SERVER_mst_destroy(plugin->fragment_data_tokenizer); - plugin->fragment_data_tokenizer = NULL; - } + { + GNUNET_SERVER_mst_destroy (plugin->fragment_data_tokenizer); + plugin->fragment_data_tokenizer = NULL; + } if (NULL != plugin->wlan_header_payload_tokenizer) - { - GNUNET_SERVER_mst_destroy(plugin->wlan_header_payload_tokenizer); - plugin->wlan_header_payload_tokenizer = NULL; - } + { + GNUNET_SERVER_mst_destroy (plugin->wlan_header_payload_tokenizer); + plugin->wlan_header_payload_tokenizer = NULL; + } if (NULL != plugin->helper_payload_tokenizer) - { - GNUNET_SERVER_mst_destroy(plugin->helper_payload_tokenizer); - plugin->helper_payload_tokenizer = NULL; - } - GNUNET_free_non_null(plugin->wlan_interface); - GNUNET_free(plugin); - GNUNET_free(api); + { + GNUNET_SERVER_mst_destroy (plugin->helper_payload_tokenizer); + plugin->helper_payload_tokenizer = NULL; + } + GNUNET_free_non_null (plugin->wlan_interface); + GNUNET_free (plugin); + GNUNET_free (api); return NULL; } @@ -2083,11 +2115,11 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -wlan_plugin_string_to_address(void *cls, - const char *addr, - uint16_t addrlen, - void **buf, - size_t *added) +wlan_plugin_string_to_address (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, + size_t *added) { struct WlanAddress *wa; unsigned int a[6]; @@ -2096,34 +2128,34 @@ wlan_plugin_string_to_address(void *cls, uint32_t options; if ((NULL == addr) || (0 == addrlen)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if ('\0' != addr[addrlen - 1]) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - if (strlen(addr) != addrlen - 1) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (strlen (addr) != addrlen - 1) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } - if (8 != sscanf(addr, - "%4s.%u.%X:%X:%X:%X:%X:%X", - plugin, &options, - &a[0], &a[1], &a[2], - &a[3], &a[4], &a[5])) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - wa = GNUNET_new(struct WlanAddress); + if (8 != sscanf (addr, + "%4s.%u.%X:%X:%X:%X:%X:%X", + plugin, &options, + &a[0], &a[1], &a[2], + &a[3], &a[4], &a[5])) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + wa = GNUNET_new (struct WlanAddress); for (i = 0; i < 6; i++) wa->mac.mac[i] = a[i]; - wa->options = htonl(0); + wa->options = htonl (0); *buf = wa; *added = sizeof(struct WlanAddress); return GNUNET_OK; @@ -2143,9 +2175,9 @@ wlan_plugin_string_to_address(void *cls, * @param sic_cls closure for @a sic */ static void -wlan_plugin_setup_monitor(void *cls, - GNUNET_TRANSPORT_SessionInfoCallback sic, - void *sic_cls) +wlan_plugin_setup_monitor (void *cls, + GNUNET_TRANSPORT_SessionInfoCallback sic, + void *sic_cls) { struct Plugin *plugin = cls; struct MacEndpoint *mac; @@ -2154,19 +2186,20 @@ wlan_plugin_setup_monitor(void *cls, plugin->sic = sic; plugin->sic_cls = sic_cls; if (NULL != sic) - { - for (mac = plugin->mac_head; NULL != mac; mac = mac->next) - for (session = mac->sessions_head; NULL != session; session = session->next) - { - notify_session_monitor(plugin, - session, - GNUNET_TRANSPORT_SS_INIT); - notify_session_monitor(plugin, - session, - GNUNET_TRANSPORT_SS_UP); - } - sic(sic_cls, NULL, NULL); - } + { + for (mac = plugin->mac_head; NULL != mac; mac = mac->next) + for (session = mac->sessions_head; NULL != session; session = + session->next) + { + notify_session_monitor (plugin, + session, + GNUNET_TRANSPORT_SS_INIT); + notify_session_monitor (plugin, + session, + GNUNET_TRANSPORT_SS_UP); + } + sic (sic_cls, NULL, NULL); + } } @@ -2181,12 +2214,13 @@ wlan_plugin_setup_monitor(void *cls, * @param session which session is being updated */ static void -wlan_plugin_update_session_timeout(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session) +wlan_plugin_update_session_timeout (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session) { - GNUNET_assert(NULL != session->timeout_task); - session->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_assert (NULL != session->timeout_task); + session->timeout = GNUNET_TIME_relative_to_absolute ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); } @@ -2201,10 +2235,10 @@ wlan_plugin_update_session_timeout(void *cls, * @param delay new delay to use for receiving */ static void -wlan_plugin_update_inbound_delay(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_ATS_Session *session, - struct GNUNET_TIME_Relative delay) +wlan_plugin_update_inbound_delay (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_ATS_Session *session, + struct GNUNET_TIME_Relative delay) { /* does nothing, as inbound delay is not supported by WLAN */ } @@ -2217,7 +2251,7 @@ wlan_plugin_update_inbound_delay(void *cls, * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error */ void * -LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) +LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) { struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; @@ -2228,127 +2262,128 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) /* check for 'special' mode */ if (NULL == env->receive) - { - /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully - initialze the plugin or the API */ - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); - api->cls = NULL; - api->address_pretty_printer = &wlan_plugin_address_pretty_printer; - api->address_to_string = &wlan_plugin_address_to_string; - api->string_to_address = &wlan_plugin_string_to_address; - return api; - } + { + /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully + initialze the plugin or the API */ + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); + api->cls = NULL; + api->address_pretty_printer = &wlan_plugin_address_pretty_printer; + api->address_to_string = &wlan_plugin_address_to_string; + api->string_to_address = &wlan_plugin_string_to_address; + return api; + } testmode = 0; /* check configuration */ if ((GNUNET_YES == - GNUNET_CONFIGURATION_have_value(env->cfg, - CONFIG_NAME, - "TESTMODE")) && + GNUNET_CONFIGURATION_have_value (env->cfg, + CONFIG_NAME, + "TESTMODE")) && ((GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_number(env->cfg, - CONFIG_NAME, - "TESTMODE", - &testmode)) || + GNUNET_CONFIGURATION_get_value_number (env->cfg, + CONFIG_NAME, + "TESTMODE", + &testmode)) || (testmode > 2))) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - CONFIG_NAME, - "TESTMODE"); - return NULL; - } - binary = GNUNET_OS_get_libexec_binary_path(HELPER_NAME); + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + CONFIG_NAME, + "TESTMODE"); + return NULL; + } + binary = GNUNET_OS_get_libexec_binary_path (HELPER_NAME); if ((0 == testmode) && (GNUNET_YES != - GNUNET_OS_check_helper_binary(binary, - GNUNET_YES, - NULL))) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Helper binary `%s' not SUID, cannot run WLAN transport\n"), - HELPER_NAME); - GNUNET_free(binary); - return NULL; - } - GNUNET_free(binary); + GNUNET_OS_check_helper_binary (binary, + GNUNET_YES, + NULL))) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Helper binary `%s' not SUID, cannot run WLAN transport\n"), + HELPER_NAME); + GNUNET_free (binary); + return NULL; + } + GNUNET_free (binary); if (GNUNET_YES != - GNUNET_CONFIGURATION_get_value_string(env->cfg, - CONFIG_NAME, - "INTERFACE", - &wlan_interface)) - { - GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, - CONFIG_NAME, - "INTERFACE"); - return NULL; - } + GNUNET_CONFIGURATION_get_value_string (env->cfg, + CONFIG_NAME, + "INTERFACE", + &wlan_interface)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + CONFIG_NAME, + "INTERFACE"); + return NULL; + } - plugin = GNUNET_new(struct Plugin); + plugin = GNUNET_new (struct Plugin); plugin->wlan_interface = wlan_interface; plugin->env = env; - GNUNET_STATISTICS_set(plugin->env->stats, - _("# sessions allocated"), - 0, GNUNET_NO); - GNUNET_STATISTICS_set(plugin->env->stats, - _("# MAC endpoints allocated"), - 0, 0); - GNUNET_BANDWIDTH_tracker_init(&plugin->tracker, NULL, NULL, - GNUNET_BANDWIDTH_value_init(100 * 1024 * - 1024 / 8), - 100); - plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create(&process_data, - plugin); - plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create(&process_data, - plugin); - plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create(&process_data, + GNUNET_STATISTICS_set (plugin->env->stats, + _ ("# sessions allocated"), + 0, GNUNET_NO); + GNUNET_STATISTICS_set (plugin->env->stats, + _ ("# MAC endpoints allocated"), + 0, 0); + GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, NULL, NULL, + GNUNET_BANDWIDTH_value_init (100 * 1024 + * 1024 / 8), + 100); + plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin); + plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create ( + &process_data, + plugin); + plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, + plugin); plugin->options = 0; /* some compilers do not like switch on 'long long'... */ - switch ((unsigned int)testmode) - { - case 0: /* normal */ - plugin->helper_argv[0] = (char *)HELPER_NAME; - plugin->helper_argv[1] = wlan_interface; - plugin->helper_argv[2] = NULL; - plugin->suid_helper = GNUNET_HELPER_start(GNUNET_NO, - HELPER_NAME, - plugin->helper_argv, - &handle_helper_message, - NULL, - plugin); - break; - - case 1: /* testmode, peer 1 */ - plugin->helper_argv[0] = (char *)DUMMY_HELPER_NAME; - plugin->helper_argv[1] = (char *)"1"; - plugin->helper_argv[2] = NULL; - plugin->suid_helper = GNUNET_HELPER_start(GNUNET_NO, - DUMMY_HELPER_NAME, - plugin->helper_argv, - &handle_helper_message, - NULL, - plugin); - break; - - case 2: /* testmode, peer 2 */ - plugin->helper_argv[0] = (char *)DUMMY_HELPER_NAME; - plugin->helper_argv[1] = (char *)"2"; - plugin->helper_argv[2] = NULL; - plugin->suid_helper = GNUNET_HELPER_start(GNUNET_NO, - DUMMY_HELPER_NAME, - plugin->helper_argv, - &handle_helper_message, - NULL, - plugin); - break; - - default: - GNUNET_assert(0); - } + switch ((unsigned int) testmode) + { + case 0: /* normal */ + plugin->helper_argv[0] = (char *) HELPER_NAME; + plugin->helper_argv[1] = wlan_interface; + plugin->helper_argv[2] = NULL; + plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO, + HELPER_NAME, + plugin->helper_argv, + &handle_helper_message, + NULL, + plugin); + break; + + case 1: /* testmode, peer 1 */ + plugin->helper_argv[0] = (char *) DUMMY_HELPER_NAME; + plugin->helper_argv[1] = (char *) "1"; + plugin->helper_argv[2] = NULL; + plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO, + DUMMY_HELPER_NAME, + plugin->helper_argv, + &handle_helper_message, + NULL, + plugin); + break; + + case 2: /* testmode, peer 2 */ + plugin->helper_argv[0] = (char *) DUMMY_HELPER_NAME; + plugin->helper_argv[1] = (char *) "2"; + plugin->helper_argv[2] = NULL; + plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO, + DUMMY_HELPER_NAME, + plugin->helper_argv, + &handle_helper_message, + NULL, + plugin); + break; + + default: + GNUNET_assert (0); + } - api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); + api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->send = &wlan_plugin_send; api->get_session = &wlan_plugin_get_session; diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h index bf1a90dba..5fe9f166f 100644 --- a/src/transport/plugin_transport_wlan.h +++ b/src/transport/plugin_transport_wlan.h @@ -58,14 +58,16 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * A MAC Address. */ -struct GNUNET_TRANSPORT_WLAN_MacAddress { +struct GNUNET_TRANSPORT_WLAN_MacAddress +{ uint8_t mac[MAC_ADDR_SIZE]; }; /** * Format of a WLAN Control Message. */ -struct GNUNET_TRANSPORT_WLAN_HelperControlMessage { +struct GNUNET_TRANSPORT_WLAN_HelperControlMessage +{ /** * Message header. Type is * GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL @@ -81,7 +83,8 @@ struct GNUNET_TRANSPORT_WLAN_HelperControlMessage { /** * generic definitions for IEEE 802.3 frames */ -struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame { +struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame +{ /** * Address 1: destination address in ad-hoc mode or AP, BSSID if station, */ @@ -102,7 +105,8 @@ struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame { /** * generic definitions for IEEE 802.11 frames */ -struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame { +struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame +{ /** * 802.11 Frame Control field. A bitmask. The overall field is a * 16-bit mask of the respecitve fields. The lowest two bits should @@ -154,7 +158,8 @@ struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame { * Message from the plugin to the WLAN helper: send the given message with the * given connection parameters. */ -struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage { +struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage +{ /** * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER'. */ @@ -193,7 +198,8 @@ struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage { /** * struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos */ -struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage { +struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage +{ /** * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER'. */ diff --git a/src/transport/tcp_connection_legacy.c b/src/transport/tcp_connection_legacy.c index 42fe6a8a6..8eea664c4 100644 --- a/src/transport/tcp_connection_legacy.c +++ b/src/transport/tcp_connection_legacy.c @@ -42,17 +42,18 @@ * Default is 5s. */ #define CONNECT_RETRY_TIMEOUT \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) #define LOG_STRERROR(kind, syscall) \ - GNUNET_log_from_strerror(kind, "util-connection", syscall) + GNUNET_log_from_strerror (kind, "util-connection", syscall) /** * Transmission handle. There can only be one for each connection. */ -struct GNUNET_CONNECTION_TransmitHandle { +struct GNUNET_CONNECTION_TransmitHandle +{ /** * Function to call if the send buffer has notify_size * bytes available. @@ -91,7 +92,8 @@ struct GNUNET_CONNECTION_TransmitHandle { * During connect, we try multiple possible IP addresses * to find out which one might work. */ -struct AddressProbe { +struct AddressProbe +{ /** * This is a linked list. */ @@ -132,7 +134,8 @@ struct AddressProbe { /** * @brief handle for a network connection */ -struct GNUNET_CONNECTION_Handle { +struct GNUNET_CONNECTION_Handle +{ /** * Configuration to use. */ @@ -268,7 +271,7 @@ struct GNUNET_CONNECTION_Handle { * @param connection the connection to set persistent */ void -GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *connection) +GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection) { connection->persist = GNUNET_YES; } @@ -286,9 +289,9 @@ GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *connection) * @return #GNUNET_OK on success */ int -GNUNET_CONNECTION_disable_corking(struct GNUNET_CONNECTION_Handle *connection) +GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection) { - return GNUNET_NETWORK_socket_disable_corking(connection->sock); + return GNUNET_NETWORK_socket_disable_corking (connection->sock); } @@ -301,13 +304,13 @@ GNUNET_CONNECTION_disable_corking(struct GNUNET_CONNECTION_Handle *connection) * @return the boxed connection handle */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_from_existing(struct GNUNET_NETWORK_Handle *osSocket) +GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket) { struct GNUNET_CONNECTION_Handle *connection; - connection = GNUNET_new(struct GNUNET_CONNECTION_Handle); + connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; - connection->write_buffer = GNUNET_malloc(connection->write_buffer_size); + connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); connection->sock = osSocket; return connection; } @@ -323,9 +326,9 @@ GNUNET_CONNECTION_create_from_existing(struct GNUNET_NETWORK_Handle *osSocket) * @return the connection handle, NULL on error */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_from_accept(GNUNET_CONNECTION_AccessCheck access_cb, - void *access_cb_cls, - struct GNUNET_NETWORK_Handle *lsock) +GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, + void *access_cb_cls, + struct GNUNET_NETWORK_Handle *lsock) { struct GNUNET_CONNECTION_Handle *connection; char addr[128]; @@ -351,107 +354,107 @@ GNUNET_CONNECTION_create_from_accept(GNUNET_CONNECTION_AccessCheck access_cb, addrlen = sizeof(addr); sock = - GNUNET_NETWORK_socket_accept(lsock, (struct sockaddr *)&addr, &addrlen); + GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); if (NULL == sock) - { - if (EAGAIN != errno) - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "accept"); - return NULL; - } + { + if (EAGAIN != errno) + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept"); + return NULL; + } if ((addrlen > sizeof(addr)) || (addrlen < sizeof(sa_family_t))) - { - GNUNET_break(0); - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock)); - return NULL; - } + { + GNUNET_break (0); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + return NULL; + } - sa = (struct sockaddr *)addr; - v6 = (struct sockaddr_in6 *)addr; - if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED(&v6->sin6_addr))) - { - /* convert to V4 address */ - v4 = GNUNET_new(struct sockaddr_in); - memset(v4, 0, sizeof(struct sockaddr_in)); - v4->sin_family = AF_INET; + sa = (struct sockaddr *) addr; + v6 = (struct sockaddr_in6 *) addr; + if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) + { + /* convert to V4 address */ + v4 = GNUNET_new (struct sockaddr_in); + memset (v4, 0, sizeof(struct sockaddr_in)); + v4->sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN - v4->sin_len = (u_char)sizeof(struct sockaddr_in); + v4->sin_len = (u_char) sizeof(struct sockaddr_in); #endif - GNUNET_memcpy(&v4->sin_addr, - &((char *)&v6->sin6_addr)[sizeof(struct in6_addr) - - sizeof(struct in_addr)], - sizeof(struct in_addr)); - v4->sin_port = v6->sin6_port; - uaddr = v4; - addrlen = sizeof(struct sockaddr_in); - } + GNUNET_memcpy (&v4->sin_addr, + &((char *) &v6->sin6_addr)[sizeof(struct in6_addr) + - sizeof(struct in_addr)], + sizeof(struct in_addr)); + v4->sin_port = v6->sin6_port; + uaddr = v4; + addrlen = sizeof(struct sockaddr_in); + } else - { - uaddr = GNUNET_malloc(addrlen); - GNUNET_memcpy(uaddr, addr, addrlen); - } + { + uaddr = GNUNET_malloc (addrlen); + GNUNET_memcpy (uaddr, addr, addrlen); + } gcp = NULL; if (AF_UNIX == sa->sa_family) - { + { #if HAVE_GETPEEREID - /* most BSDs */ - if (0 == getpeereid(GNUNET_NETWORK_get_fd(sock), &gc.uid, &gc.gid)) - gcp = &gc; + /* most BSDs */ + if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) + gcp = &gc; #else #ifdef SO_PEERCRED - /* largely traditional GNU/Linux */ - olen = sizeof(uc); - if ((0 == getsockopt(GNUNET_NETWORK_get_fd(sock), - SOL_SOCKET, - SO_PEERCRED, - &uc, - &olen)) && - (olen == sizeof(uc))) - { - gc.uid = uc.uid; - gc.gid = uc.gid; - gcp = &gc; - } + /* largely traditional GNU/Linux */ + olen = sizeof(uc); + if ((0 == getsockopt (GNUNET_NETWORK_get_fd (sock), + SOL_SOCKET, + SO_PEERCRED, + &uc, + &olen)) && + (olen == sizeof(uc))) + { + gc.uid = uc.uid; + gc.gid = uc.gid; + gcp = &gc; + } #else #if HAVE_GETPEERUCRED - /* this is for Solaris 10 */ - ucred_t *uc; - - uc = NULL; - if (0 == getpeerucred(GNUNET_NETWORK_get_fd(sock), &uc)) - { - gc.uid = ucred_geteuid(uc); - gc.gid = ucred_getegid(uc); - gcp = &gc; - } - ucred_free(uc); + /* this is for Solaris 10 */ + ucred_t *uc; + + uc = NULL; + if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc)) + { + gc.uid = ucred_geteuid (uc); + gc.gid = ucred_getegid (uc); + gcp = &gc; + } + ucred_free (uc); #endif #endif #endif - } + } if ((NULL != access_cb) && - (GNUNET_YES != (aret = access_cb(access_cb_cls, gcp, uaddr, addrlen)))) - { - if (GNUNET_NO == aret) - 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; - } - connection = GNUNET_new(struct GNUNET_CONNECTION_Handle); + (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen)))) + { + if (GNUNET_NO == aret) + 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; + } + connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; - connection->write_buffer = GNUNET_malloc(connection->write_buffer_size); + connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); connection->addr = uaddr; connection->addrlen = addrlen; connection->sock = sock; - LOG(GNUNET_ERROR_TYPE_INFO, - _("Accepting connection from `%s': %p\n"), - GNUNET_a2s(uaddr, addrlen), - connection); + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Accepting connection from `%s': %p\n"), + GNUNET_a2s (uaddr, addrlen), + connection); return connection; } @@ -465,14 +468,14 @@ GNUNET_CONNECTION_create_from_accept(GNUNET_CONNECTION_AccessCheck access_cb, * @return #GNUNET_OK on success */ int -GNUNET_CONNECTION_get_address(struct GNUNET_CONNECTION_Handle *connection, - void **addr, - size_t *addrlen) +GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, + void **addr, + size_t *addrlen) { if ((NULL == connection->addr) || (0 == connection->addrlen)) return GNUNET_NO; - *addr = GNUNET_malloc(connection->addrlen); - GNUNET_memcpy(*addr, connection->addr, connection->addrlen); + *addr = GNUNET_malloc (connection->addrlen); + GNUNET_memcpy (*addr, connection->addr, connection->addrlen); *addrlen = connection->addrlen; return GNUNET_OK; } @@ -485,22 +488,22 @@ GNUNET_CONNECTION_get_address(struct GNUNET_CONNECTION_Handle *connection, * @param errcode error code to send */ static void -signal_receive_error(struct GNUNET_CONNECTION_Handle *connection, int errcode) +signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode) { GNUNET_CONNECTION_Receiver receiver; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error (%s), connection closed (%p)\n", - strerror(errcode), - connection); - GNUNET_assert(NULL != (receiver = connection->receiver)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive encounters error (%s), connection closed (%p)\n", + strerror (errcode), + connection); + GNUNET_assert (NULL != (receiver = connection->receiver)); connection->receiver = NULL; - receiver(connection->receiver_cls, - NULL, - 0, - connection->addr, - connection->addrlen, - errcode); + receiver (connection->receiver_cls, + NULL, + 0, + connection->addr, + connection->addrlen, + errcode); } @@ -510,16 +513,16 @@ signal_receive_error(struct GNUNET_CONNECTION_Handle *connection, int errcode) * @param connection connection to signal for */ static void -signal_receive_timeout(struct GNUNET_CONNECTION_Handle *connection) +signal_receive_timeout (struct GNUNET_CONNECTION_Handle *connection) { GNUNET_CONNECTION_Receiver receiver; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Connection signals timeout to receiver (%p)!\n", - connection); - GNUNET_assert(NULL != (receiver = connection->receiver)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connection signals timeout to receiver (%p)!\n", + connection); + GNUNET_assert (NULL != (receiver = connection->receiver)); connection->receiver = NULL; - receiver(connection->receiver_cls, NULL, 0, NULL, 0, 0); + receiver (connection->receiver_cls, NULL, 0, NULL, 0, 0); } @@ -530,34 +533,34 @@ signal_receive_timeout(struct GNUNET_CONNECTION_Handle *connection) * @param ecode error code (errno) */ static void -signal_transmit_error(struct GNUNET_CONNECTION_Handle *connection, int ecode) +signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, int ecode) { GNUNET_CONNECTION_TransmitReadyNotify notify; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Transmission encounterd error (%s), connection closed (%p)\n", - strerror(ecode), - connection); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmission encounterd error (%s), connection closed (%p)\n", + strerror (ecode), + connection); if (NULL != connection->sock) - { - (void)GNUNET_NETWORK_socket_shutdown(connection->sock, SHUT_RDWR); - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(connection->sock)); - connection->sock = NULL; - GNUNET_assert(NULL == connection->write_task); - } + { + (void) GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); + connection->sock = NULL; + GNUNET_assert (NULL == connection->write_task); + } if (NULL != connection->read_task) - { - /* send errors trigger read errors... */ - GNUNET_SCHEDULER_cancel(connection->read_task); - connection->read_task = NULL; - signal_receive_timeout(connection); - return; - } + { + /* send errors trigger read errors... */ + GNUNET_SCHEDULER_cancel (connection->read_task); + connection->read_task = NULL; + signal_receive_timeout (connection); + return; + } if (NULL == connection->nth.notify_ready) return; /* nobody to tell about it */ notify = connection->nth.notify_ready; connection->nth.notify_ready = NULL; - notify(connection->nth.notify_ready_cls, 0, NULL); + notify (connection->nth.notify_ready_cls, 0, NULL); } @@ -568,37 +571,37 @@ signal_transmit_error(struct GNUNET_CONNECTION_Handle *connection, int ecode) * @param connection the connection we tried to establish */ static void -connect_fail_continuation(struct GNUNET_CONNECTION_Handle *connection) +connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection) { - LOG(GNUNET_ERROR_TYPE_INFO, - "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n", - connection->hostname, - connection->port); - GNUNET_break(NULL == connection->ap_head); - GNUNET_break(NULL == connection->ap_tail); - GNUNET_break(GNUNET_NO == connection->dns_active); - GNUNET_break(NULL == connection->sock); - GNUNET_assert(NULL == connection->write_task); - GNUNET_assert(NULL == connection->proxy_handshake); + LOG (GNUNET_ERROR_TYPE_INFO, + "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n", + connection->hostname, + connection->port); + GNUNET_break (NULL == connection->ap_head); + GNUNET_break (NULL == connection->ap_tail); + GNUNET_break (GNUNET_NO == connection->dns_active); + GNUNET_break (NULL == connection->sock); + GNUNET_assert (NULL == connection->write_task); + GNUNET_assert (NULL == connection->proxy_handshake); /* signal errors for jobs that used to wait on the connection */ connection->destroy_later = 1; if (NULL != connection->receiver) - signal_receive_error(connection, ECONNREFUSED); + signal_receive_error (connection, ECONNREFUSED); if (NULL != connection->nth.notify_ready) - { - GNUNET_assert(NULL != connection->nth.timeout_task); - GNUNET_SCHEDULER_cancel(connection->nth.timeout_task); - connection->nth.timeout_task = NULL; - signal_transmit_error(connection, ECONNREFUSED); - } + { + GNUNET_assert (NULL != connection->nth.timeout_task); + GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); + connection->nth.timeout_task = NULL; + signal_transmit_error (connection, ECONNREFUSED); + } if (-1 == connection->destroy_later) - { - /* do it now */ - connection->destroy_later = 0; - GNUNET_CONNECTION_destroy(connection); - return; - } + { + /* do it now */ + connection->destroy_later = 0; + GNUNET_CONNECTION_destroy (connection); + return; + } connection->destroy_later = 0; } @@ -609,7 +612,7 @@ connect_fail_continuation(struct GNUNET_CONNECTION_Handle *connection) * @param cls our connection handle */ static void -transmit_ready(void *cls); +transmit_ready (void *cls); /** @@ -619,7 +622,7 @@ transmit_ready(void *cls); * @param cls connection to read from */ static void -receive_ready(void *cls); +receive_ready (void *cls); /** @@ -628,42 +631,42 @@ receive_ready(void *cls); * @param connection the connection we tried to establish */ static void -connect_success_continuation(struct GNUNET_CONNECTION_Handle *connection) +connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Connection to `%s' succeeded! (%p)\n", - GNUNET_a2s(connection->addr, connection->addrlen), - connection); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connection to `%s' succeeded! (%p)\n", + GNUNET_a2s (connection->addr, connection->addrlen), + connection); /* trigger jobs that waited for the connection */ if (NULL != connection->receiver) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Connection succeeded, starting with receiving data (%p)\n", - connection); - GNUNET_assert(NULL == connection->read_task); - connection->read_task = - GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_absolute_get_remaining( - connection->receive_timeout), + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connection succeeded, starting with receiving data (%p)\n", + connection); + GNUNET_assert (NULL == connection->read_task); + connection->read_task = + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( + connection->receive_timeout), + connection->sock, + &receive_ready, + connection); + } + if (NULL != connection->nth.notify_ready) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connection succeeded, starting with sending data (%p)\n", + connection); + GNUNET_assert (connection->nth.timeout_task != NULL); + GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); + connection->nth.timeout_task = NULL; + GNUNET_assert (connection->write_task == NULL); + connection->write_task = + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining ( + connection->nth.transmit_timeout), connection->sock, - &receive_ready, + &transmit_ready, connection); - } - if (NULL != connection->nth.notify_ready) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Connection succeeded, starting with sending data (%p)\n", - connection); - GNUNET_assert(connection->nth.timeout_task != NULL); - GNUNET_SCHEDULER_cancel(connection->nth.timeout_task); - connection->nth.timeout_task = NULL; - GNUNET_assert(connection->write_task == NULL); - connection->write_task = - GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_absolute_get_remaining( - connection->nth.transmit_timeout), - connection->sock, - &transmit_ready, - connection); - } + } } @@ -674,7 +677,7 @@ connect_success_continuation(struct GNUNET_CONNECTION_Handle *connection) * @param cls the `struct AddressProbe *` with the address that we are probing */ static void -connect_probe_continuation(void *cls) +connect_probe_continuation (void *cls) { struct AddressProbe *ap = cls; struct GNUNET_CONNECTION_Handle *connection = ap->connection; @@ -683,44 +686,44 @@ connect_probe_continuation(void *cls) int error; socklen_t len; - GNUNET_assert(NULL != ap->sock); - GNUNET_CONTAINER_DLL_remove(connection->ap_head, connection->ap_tail, ap); + GNUNET_assert (NULL != ap->sock); + GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap); len = sizeof(error); errno = 0; error = 0; - tc = GNUNET_SCHEDULER_get_task_context(); + tc = GNUNET_SCHEDULER_get_task_context (); if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || - (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt(ap->sock, - SOL_SOCKET, - SO_ERROR, - &error, - &len)) || + (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt (ap->sock, + SOL_SOCKET, + SO_ERROR, + &error, + &len)) || (0 != error)) - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(ap->sock)); - GNUNET_free(ap); - if ((NULL == connection->ap_head) && - (GNUNET_NO == connection->dns_active) && - (NULL == connection->proxy_handshake)) - connect_fail_continuation(connection); - return; - } - GNUNET_assert(NULL == connection->sock); + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); + GNUNET_free (ap); + if ((NULL == connection->ap_head) && + (GNUNET_NO == connection->dns_active) && + (NULL == connection->proxy_handshake)) + connect_fail_continuation (connection); + return; + } + GNUNET_assert (NULL == connection->sock); connection->sock = ap->sock; - GNUNET_assert(NULL == connection->addr); - connection->addr = GNUNET_malloc(ap->addrlen); - GNUNET_memcpy(connection->addr, ap->addr, ap->addrlen); + GNUNET_assert (NULL == connection->addr); + connection->addr = GNUNET_malloc (ap->addrlen); + GNUNET_memcpy (connection->addr, ap->addr, ap->addrlen); connection->addrlen = ap->addrlen; - GNUNET_free(ap); + GNUNET_free (ap); /* cancel all other attempts */ while (NULL != (pos = connection->ap_head)) - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(pos->sock)); - GNUNET_SCHEDULER_cancel(pos->task); - GNUNET_CONTAINER_DLL_remove(connection->ap_head, connection->ap_tail, pos); - GNUNET_free(pos); - } - connect_success_continuation(connection); + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); + GNUNET_SCHEDULER_cancel (pos->task); + GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); + GNUNET_free (pos); + } + connect_success_continuation (connection); } @@ -733,87 +736,87 @@ connect_probe_continuation(void *cls) * @param addrlen length of @a addr */ static void -try_connect_using_address(void *cls, - const struct sockaddr *addr, - socklen_t addrlen) +try_connect_using_address (void *cls, + const struct sockaddr *addr, + socklen_t addrlen) { struct GNUNET_CONNECTION_Handle *connection = cls; struct AddressProbe *ap; struct GNUNET_TIME_Relative delay; if (NULL == addr) - { - connection->dns_active = NULL; - if ((NULL == connection->ap_head) && (NULL == connection->sock) && - (NULL == connection->proxy_handshake)) - connect_fail_continuation(connection); - return; - } + { + connection->dns_active = NULL; + if ((NULL == connection->ap_head) && (NULL == connection->sock) && + (NULL == connection->proxy_handshake)) + connect_fail_continuation (connection); + return; + } if (NULL != connection->sock) return; /* already connected */ - GNUNET_assert(NULL == connection->addr); + GNUNET_assert (NULL == connection->addr); /* try to connect */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Trying to connect using address `%s:%u/%s:%u'\n", - connection->hostname, - connection->port, - GNUNET_a2s(addr, addrlen), - connection->port); - ap = GNUNET_malloc(sizeof(struct AddressProbe) + addrlen); - ap->addr = (const struct sockaddr *)&ap[1]; - GNUNET_memcpy(&ap[1], addr, addrlen); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Trying to connect using address `%s:%u/%s:%u'\n", + connection->hostname, + connection->port, + GNUNET_a2s (addr, addrlen), + connection->port); + ap = GNUNET_malloc (sizeof(struct AddressProbe) + addrlen); + ap->addr = (const struct sockaddr *) &ap[1]; + GNUNET_memcpy (&ap[1], addr, addrlen); ap->addrlen = addrlen; ap->connection = connection; switch (ap->addr->sa_family) - { - case AF_INET: - ((struct sockaddr_in *)ap->addr)->sin_port = htons(connection->port); - break; - - case AF_INET6: - ((struct sockaddr_in6 *)ap->addr)->sin6_port = htons(connection->port); - break; - - default: - GNUNET_break(0); - GNUNET_free(ap); - return; /* not supported by us */ - } - ap->sock = GNUNET_NETWORK_socket_create(ap->addr->sa_family, SOCK_STREAM, 0); + { + case AF_INET: + ((struct sockaddr_in *) ap->addr)->sin_port = htons (connection->port); + break; + + case AF_INET6: + ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (connection->port); + break; + + default: + GNUNET_break (0); + GNUNET_free (ap); + return; /* not supported by us */ + } + ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); if (NULL == ap->sock) - { - GNUNET_free(ap); - return; /* not supported by OS */ - } - LOG(GNUNET_ERROR_TYPE_INFO, - "Trying to connect to `%s' (%p)\n", - GNUNET_a2s(ap->addr, ap->addrlen), - connection); + { + GNUNET_free (ap); + return; /* not supported by OS */ + } + LOG (GNUNET_ERROR_TYPE_INFO, + "Trying to connect to `%s' (%p)\n", + GNUNET_a2s (ap->addr, ap->addrlen), + connection); if ((GNUNET_OK != - GNUNET_NETWORK_socket_connect(ap->sock, ap->addr, ap->addrlen)) && + GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && (EINPROGRESS != errno)) - { - /* maybe refused / unsupported address, try next */ - LOG_STRERROR(GNUNET_ERROR_TYPE_INFO, "connect"); - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(ap->sock)); - GNUNET_free(ap); - return; - } - GNUNET_CONTAINER_DLL_insert(connection->ap_head, connection->ap_tail, ap); + { + /* maybe refused / unsupported address, try next */ + LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); + GNUNET_free (ap); + return; + } + GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap); delay = CONNECT_RETRY_TIMEOUT; if (NULL != connection->nth.notify_ready) - delay = GNUNET_TIME_relative_min(delay, - GNUNET_TIME_absolute_get_remaining( - connection->nth.transmit_timeout)); + delay = GNUNET_TIME_relative_min (delay, + GNUNET_TIME_absolute_get_remaining ( + connection->nth.transmit_timeout)); if (NULL != connection->receiver) - delay = GNUNET_TIME_relative_min(delay, - GNUNET_TIME_absolute_get_remaining( - connection->receive_timeout)); - ap->task = GNUNET_SCHEDULER_add_write_net(delay, - ap->sock, - &connect_probe_continuation, - ap); + delay = GNUNET_TIME_relative_min (delay, + GNUNET_TIME_absolute_get_remaining ( + connection->receive_timeout)); + ap->task = GNUNET_SCHEDULER_add_write_net (delay, + ap->sock, + &connect_probe_continuation, + ap); } @@ -828,25 +831,25 @@ try_connect_using_address(void *cls, * @return the connection handle */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_from_connect( +GNUNET_CONNECTION_create_from_connect ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *hostname, uint16_t port) { struct GNUNET_CONNECTION_Handle *connection; - GNUNET_assert(0 < strlen(hostname)); /* sanity check */ - connection = GNUNET_new(struct GNUNET_CONNECTION_Handle); + GNUNET_assert (0 < strlen (hostname)); /* sanity check */ + connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); connection->cfg = cfg; connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; - connection->write_buffer = GNUNET_malloc(connection->write_buffer_size); + connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); connection->port = port; - connection->hostname = GNUNET_strdup(hostname); - connection->dns_active = GNUNET_RESOLVER_ip_get(connection->hostname, - AF_UNSPEC, - CONNECT_RETRY_TIMEOUT, - &try_connect_using_address, - connection); + connection->hostname = GNUNET_strdup (hostname); + connection->dns_active = GNUNET_RESOLVER_ip_get (connection->hostname, + AF_UNSPEC, + CONNECT_RETRY_TIMEOUT, + &try_connect_using_address, + connection); return connection; } @@ -861,7 +864,7 @@ GNUNET_CONNECTION_create_from_connect( * @return the connection handle, NULL on systems without UNIX support */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_from_connect_to_unixpath( +GNUNET_CONNECTION_create_from_connect_to_unixpath ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *unixpath) { @@ -869,51 +872,51 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath( struct GNUNET_CONNECTION_Handle *connection; struct sockaddr_un *un; - GNUNET_assert(0 < strlen(unixpath)); /* sanity check */ - un = GNUNET_new(struct sockaddr_un); + GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ + un = GNUNET_new (struct sockaddr_un); un->sun_family = AF_UNIX; - GNUNET_strlcpy(un->sun_path, unixpath, sizeof(un->sun_path)); + GNUNET_strlcpy (un->sun_path, unixpath, sizeof(un->sun_path)); #ifdef LINUX { int abstract; - abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, - "TESTING", - "USE_ABSTRACT_SOCKETS"); + abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, + "TESTING", + "USE_ABSTRACT_SOCKETS"); if (GNUNET_YES == abstract) un->sun_path[0] = '\0'; } #endif #if HAVE_SOCKADDR_UN_SUN_LEN - un->sun_len = (u_char)sizeof(struct sockaddr_un); + un->sun_len = (u_char) sizeof(struct sockaddr_un); #endif - connection = GNUNET_new(struct GNUNET_CONNECTION_Handle); + connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); connection->cfg = cfg; connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; - connection->write_buffer = GNUNET_malloc(connection->write_buffer_size); + connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); connection->port = 0; connection->hostname = NULL; - connection->addr = (struct sockaddr *)un; + connection->addr = (struct sockaddr *) un; connection->addrlen = sizeof(struct sockaddr_un); - connection->sock = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0); + connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); if (NULL == connection->sock) - { - GNUNET_free(connection->addr); - GNUNET_free(connection->write_buffer); - GNUNET_free(connection); - return NULL; - } - if ((GNUNET_OK != GNUNET_NETWORK_socket_connect(connection->sock, - connection->addr, - connection->addrlen)) && + { + GNUNET_free (connection->addr); + GNUNET_free (connection->write_buffer); + GNUNET_free (connection); + return NULL; + } + if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (connection->sock, + connection->addr, + connection->addrlen)) && (EINPROGRESS != errno)) - { - /* Just return; we expect everything to work eventually so don't fail HARD */ - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(connection->sock)); - connection->sock = NULL; - return connection; - } - connect_success_continuation(connection); + { + /* Just return; we expect everything to work eventually so don't fail HARD */ + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); + connection->sock = NULL; + return connection; + } + connect_success_continuation (connection); return connection; #else return NULL; @@ -932,31 +935,31 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath( * @return the connection handle */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_connect_socket(struct GNUNET_NETWORK_Handle *s, - const struct sockaddr *serv_addr, - socklen_t addrlen) +GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s, + const struct sockaddr *serv_addr, + socklen_t addrlen) { struct GNUNET_CONNECTION_Handle *connection; - if ((GNUNET_OK != GNUNET_NETWORK_socket_connect(s, serv_addr, addrlen)) && + if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && (EINPROGRESS != errno)) - { - /* maybe refused / unsupported address, try next */ - LOG_STRERROR(GNUNET_ERROR_TYPE_DEBUG, "connect"); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Attempt to connect to `%s' failed\n", - GNUNET_a2s(serv_addr, addrlen)); - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(s)); - return NULL; - } - connection = GNUNET_CONNECTION_create_from_existing(s); - connection->addr = GNUNET_malloc(addrlen); - GNUNET_memcpy(connection->addr, serv_addr, addrlen); + { + /* maybe refused / unsupported address, try next */ + LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "connect"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Attempt to connect to `%s' failed\n", + GNUNET_a2s (serv_addr, addrlen)); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); + return NULL; + } + connection = GNUNET_CONNECTION_create_from_existing (s); + connection->addr = GNUNET_malloc (addrlen); + GNUNET_memcpy (connection->addr, serv_addr, addrlen); connection->addrlen = addrlen; - LOG(GNUNET_ERROR_TYPE_INFO, - "Trying to connect to `%s' (%p)\n", - GNUNET_a2s(serv_addr, addrlen), - connection); + LOG (GNUNET_ERROR_TYPE_INFO, + "Trying to connect to `%s' (%p)\n", + GNUNET_a2s (serv_addr, addrlen), + connection); return connection; } @@ -973,19 +976,19 @@ GNUNET_CONNECTION_connect_socket(struct GNUNET_NETWORK_Handle *s, * @return the connection handle */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_from_sockaddr(int af_family, - const struct sockaddr *serv_addr, - socklen_t addrlen) +GNUNET_CONNECTION_create_from_sockaddr (int af_family, + const struct sockaddr *serv_addr, + socklen_t addrlen) { struct GNUNET_NETWORK_Handle *s; - s = GNUNET_NETWORK_socket_create(af_family, SOCK_STREAM, 0); + s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); if (NULL == s) - { - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket"); - return NULL; - } - return GNUNET_CONNECTION_connect_socket(s, serv_addr, addrlen); + { + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket"); + return NULL; + } + return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen); } @@ -998,7 +1001,7 @@ GNUNET_CONNECTION_create_from_sockaddr(int af_family, * @return #GNUNET_YES if valid, #GNUNET_NO otherwise */ int -GNUNET_CONNECTION_check(struct GNUNET_CONNECTION_Handle *connection) +GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) { if ((NULL != connection->ap_head) || (NULL != connection->dns_active) || (NULL != connection->proxy_handshake)) @@ -1017,78 +1020,78 @@ GNUNET_CONNECTION_check(struct GNUNET_CONNECTION_Handle *connection) * @param connection connection to destroy */ void -GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection) +GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) { struct AddressProbe *pos; if (0 != connection->destroy_later) - { - connection->destroy_later = -1; - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection); - GNUNET_assert(NULL == connection->nth.notify_ready); - GNUNET_assert(NULL == connection->receiver); + { + connection->destroy_later = -1; + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection); + GNUNET_assert (NULL == connection->nth.notify_ready); + GNUNET_assert (NULL == connection->receiver); if (NULL != connection->write_task) - { - GNUNET_SCHEDULER_cancel(connection->write_task); - connection->write_task = NULL; - connection->write_buffer_off = 0; - } + { + GNUNET_SCHEDULER_cancel (connection->write_task); + connection->write_task = NULL; + connection->write_buffer_off = 0; + } if (NULL != connection->read_task) - { - GNUNET_SCHEDULER_cancel(connection->read_task); - connection->read_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (connection->read_task); + connection->read_task = NULL; + } if (NULL != connection->nth.timeout_task) - { - GNUNET_SCHEDULER_cancel(connection->nth.timeout_task); - connection->nth.timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); + connection->nth.timeout_task = NULL; + } connection->nth.notify_ready = NULL; if (NULL != connection->dns_active) - { - GNUNET_RESOLVER_request_cancel(connection->dns_active); - connection->dns_active = NULL; - } + { + GNUNET_RESOLVER_request_cancel (connection->dns_active); + connection->dns_active = NULL; + } if (NULL != connection->proxy_handshake) - { - /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */ - connection->proxy_handshake->destroy_later = -1; - connection->proxy_handshake = NULL; /* Not leaked ??? */ - } + { + /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */ + connection->proxy_handshake->destroy_later = -1; + connection->proxy_handshake = NULL; /* Not leaked ??? */ + } while (NULL != (pos = connection->ap_head)) - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(pos->sock)); - GNUNET_SCHEDULER_cancel(pos->task); - GNUNET_CONTAINER_DLL_remove(connection->ap_head, connection->ap_tail, pos); - GNUNET_free(pos); - } + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); + GNUNET_SCHEDULER_cancel (pos->task); + GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); + GNUNET_free (pos); + } if ((NULL != connection->sock) && (GNUNET_YES != connection->persist)) + { + if ((GNUNET_OK != + GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) && + (ENOTCONN != errno) && (ECONNRESET != errno)) + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown"); + } + if (NULL != connection->sock) + { + if (GNUNET_YES != connection->persist) { - if ((GNUNET_OK != - GNUNET_NETWORK_socket_shutdown(connection->sock, SHUT_RDWR)) && - (ENOTCONN != errno) && (ECONNRESET != errno)) - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "shutdown"); + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (connection->sock)); } - if (NULL != connection->sock) + else { - if (GNUNET_YES != connection->persist) - { - GNUNET_break(GNUNET_OK == - GNUNET_NETWORK_socket_close(connection->sock)); - } - else - { - GNUNET_NETWORK_socket_free_memory_only_( - connection->sock); /* at least no memory leak (we deliberately + GNUNET_NETWORK_socket_free_memory_only_ ( + connection->sock); /* at least no memory leak (we deliberately * leak the socket in this special case) ... */ - } } - GNUNET_free_non_null(connection->addr); - GNUNET_free_non_null(connection->hostname); - GNUNET_free(connection->write_buffer); - GNUNET_free(connection); + } + GNUNET_free_non_null (connection->addr); + GNUNET_free_non_null (connection->hostname); + GNUNET_free (connection->write_buffer); + GNUNET_free (connection); } @@ -1099,7 +1102,7 @@ GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection) * @param cls connection to read from */ static void -receive_ready(void *cls) +receive_ready (void *cls) { struct GNUNET_CONNECTION_Handle *connection = cls; const struct GNUNET_SCHEDULER_TaskContext *tc; @@ -1108,49 +1111,50 @@ receive_ready(void *cls) GNUNET_CONNECTION_Receiver receiver; connection->read_task = NULL; - tc = GNUNET_SCHEDULER_get_task_context(); + tc = GNUNET_SCHEDULER_get_task_context (); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receive from `%s' encounters error: timeout (%s, %p)\n", - GNUNET_a2s(connection->addr, connection->addrlen), - GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration( - connection->receive_timeout), - GNUNET_YES), - connection); - signal_receive_timeout(connection); - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive from `%s' encounters error: timeout (%s, %p)\n", + GNUNET_a2s (connection->addr, connection->addrlen), + GNUNET_STRINGS_relative_time_to_string ( + GNUNET_TIME_absolute_get_duration ( + connection->receive_timeout), + GNUNET_YES), + connection); + signal_receive_timeout (connection); + return; + } if (NULL == connection->sock) - { - /* connect failed for good */ - signal_receive_error(connection, ECONNREFUSED); - return; - } - GNUNET_assert(GNUNET_NETWORK_fdset_isset(tc->read_ready, connection->sock)); + { + /* connect failed for good */ + signal_receive_error (connection, ECONNREFUSED); + return; + } + GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock)); RETRY: - ret = GNUNET_NETWORK_socket_recv(connection->sock, buffer, connection->max); + ret = GNUNET_NETWORK_socket_recv (connection->sock, buffer, connection->max); if (-1 == ret) - { - if (EINTR == errno) - goto RETRY; - signal_receive_error(connection, errno); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "receive_ready read %u/%u bytes from `%s' (%p)!\n", - (unsigned int)ret, - connection->max, - GNUNET_a2s(connection->addr, connection->addrlen), - connection); - GNUNET_assert(NULL != (receiver = connection->receiver)); + { + if (EINTR == errno) + goto RETRY; + signal_receive_error (connection, errno); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "receive_ready read %u/%u bytes from `%s' (%p)!\n", + (unsigned int) ret, + connection->max, + GNUNET_a2s (connection->addr, connection->addrlen), + connection); + GNUNET_assert (NULL != (receiver = connection->receiver)); connection->receiver = NULL; - receiver(connection->receiver_cls, - buffer, - ret, - connection->addr, - connection->addrlen, - 0); + receiver (connection->receiver_cls, + buffer, + ret, + connection->addr, + connection->addrlen, + 0); } @@ -1170,36 +1174,36 @@ RETRY: * called with error) */ int -GNUNET_CONNECTION_receive(struct GNUNET_CONNECTION_Handle *connection, - size_t max, - struct GNUNET_TIME_Relative timeout, - GNUNET_CONNECTION_Receiver receiver, - void *receiver_cls) +GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, + size_t max, + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_Receiver receiver, + void *receiver_cls) { - GNUNET_assert((NULL == connection->read_task) && - (NULL == connection->receiver)); - GNUNET_assert(NULL != receiver); + GNUNET_assert ((NULL == connection->read_task) && + (NULL == connection->receiver)); + GNUNET_assert (NULL != receiver); connection->receiver = receiver; connection->receiver_cls = receiver_cls; - connection->receive_timeout = GNUNET_TIME_relative_to_absolute(timeout); + connection->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); connection->max = max; if (NULL != connection->sock) - { - connection->read_task = - GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_absolute_get_remaining( - connection->receive_timeout), - connection->sock, - &receive_ready, - connection); - return GNUNET_OK; - } + { + connection->read_task = + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( + connection->receive_timeout), + connection->sock, + &receive_ready, + connection); + return GNUNET_OK; + } if ((NULL == connection->dns_active) && (NULL == connection->ap_head) && (NULL == connection->proxy_handshake)) - { - connection->receiver = NULL; - receiver(receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); - return GNUNET_SYSERR; - } + { + connection->receiver = NULL; + receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1213,14 +1217,14 @@ GNUNET_CONNECTION_receive(struct GNUNET_CONNECTION_Handle *connection, * @return closure of the original receiver callback closure */ void * -GNUNET_CONNECTION_receive_cancel(struct GNUNET_CONNECTION_Handle *connection) +GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection) { if (NULL != connection->read_task) - { - GNUNET_assert(connection == - GNUNET_SCHEDULER_cancel(connection->read_task)); - connection->read_task = NULL; - } + { + GNUNET_assert (connection == + GNUNET_SCHEDULER_cancel (connection->read_task)); + connection->read_task = NULL; + } connection->receiver = NULL; return connection->receiver_cls; } @@ -1234,44 +1238,44 @@ GNUNET_CONNECTION_receive_cancel(struct GNUNET_CONNECTION_Handle *connection) * @return #GNUNET_YES if we were able to call notify */ static int -process_notify(struct GNUNET_CONNECTION_Handle *connection) +process_notify (struct GNUNET_CONNECTION_Handle *connection) { size_t used; size_t avail; size_t size; GNUNET_CONNECTION_TransmitReadyNotify notify; - LOG(GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n"); - GNUNET_assert(NULL == connection->write_task); + LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n"); + GNUNET_assert (NULL == connection->write_task); if (NULL == (notify = connection->nth.notify_ready)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n"); - return GNUNET_NO; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n"); + return GNUNET_NO; + } used = connection->write_buffer_off - connection->write_buffer_pos; avail = connection->write_buffer_size - used; size = connection->nth.notify_size; if (size > avail) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n"); - return GNUNET_NO; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n"); + return GNUNET_NO; + } connection->nth.notify_ready = NULL; if (connection->write_buffer_size - connection->write_buffer_off < size) - { - /* need to compact */ - memmove(connection->write_buffer, - &connection->write_buffer[connection->write_buffer_pos], - used); - connection->write_buffer_off -= connection->write_buffer_pos; - connection->write_buffer_pos = 0; - } + { + /* need to compact */ + memmove (connection->write_buffer, + &connection->write_buffer[connection->write_buffer_pos], + used); + connection->write_buffer_off -= connection->write_buffer_pos; + connection->write_buffer_pos = 0; + } avail = connection->write_buffer_size - connection->write_buffer_off; - GNUNET_assert(avail >= size); - size = notify(connection->nth.notify_ready_cls, - avail, - &connection->write_buffer[connection->write_buffer_off]); - GNUNET_assert(size <= avail); + GNUNET_assert (avail >= size); + size = notify (connection->nth.notify_ready_cls, + avail, + &connection->write_buffer[connection->write_buffer_off]); + GNUNET_assert (size <= avail); if (0 != size) connection->write_buffer_off += size; return GNUNET_YES; @@ -1289,22 +1293,22 @@ process_notify(struct GNUNET_CONNECTION_Handle *connection) * @param cls the `struct GNUNET_CONNECTION_Handle` */ static void -transmit_timeout(void *cls) +transmit_timeout (void *cls) { struct GNUNET_CONNECTION_Handle *connection = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; connection->nth.timeout_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", - connection->hostname, - connection->port, - GNUNET_a2s(connection->addr, connection->addrlen), - connection); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", + connection->hostname, + connection->port, + GNUNET_a2s (connection->addr, connection->addrlen), + connection); notify = connection->nth.notify_ready; - GNUNET_assert(NULL != notify); + GNUNET_assert (NULL != notify); connection->nth.notify_ready = NULL; - notify(connection->nth.notify_ready_cls, 0, NULL); + notify (connection->nth.notify_ready_cls, 0, NULL); } @@ -1317,21 +1321,21 @@ transmit_timeout(void *cls) * @param cls the `struct GNUNET_CONNECTION_Handle` */ static void -connect_error(void *cls) +connect_error (void *cls) { struct GNUNET_CONNECTION_Handle *connection = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Transmission request of size %u fails (%s/%u), connection failed (%p).\n", - connection->nth.notify_size, - connection->hostname, - connection->port, - connection); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmission request of size %u fails (%s/%u), connection failed (%p).\n", + connection->nth.notify_size, + connection->hostname, + connection->port, + connection); connection->write_task = NULL; notify = connection->nth.notify_ready; connection->nth.notify_ready = NULL; - notify(connection->nth.notify_ready_cls, 0, NULL); + notify (connection->nth.notify_ready_cls, 0, NULL); } @@ -1341,7 +1345,7 @@ connect_error(void *cls) * @param cls our connection handle */ static void -transmit_ready(void *cls) +transmit_ready (void *cls) { struct GNUNET_CONNECTION_Handle *connection = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; @@ -1349,107 +1353,107 @@ transmit_ready(void *cls) ssize_t ret; size_t have; - LOG(GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection); - GNUNET_assert(NULL != connection->write_task); + LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection); + GNUNET_assert (NULL != connection->write_task); connection->write_task = NULL; - GNUNET_assert(NULL == connection->nth.timeout_task); - tc = GNUNET_SCHEDULER_get_task_context(); + GNUNET_assert (NULL == connection->nth.timeout_task); + tc = GNUNET_SCHEDULER_get_task_context (); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Transmit to `%s' fails, time out reached (%p).\n", - GNUNET_a2s(connection->addr, connection->addrlen), - connection); - notify = connection->nth.notify_ready; - GNUNET_assert(NULL != notify); - connection->nth.notify_ready = NULL; - notify(connection->nth.notify_ready_cls, 0, NULL); - return; - } - GNUNET_assert(NULL != connection->sock); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmit to `%s' fails, time out reached (%p).\n", + GNUNET_a2s (connection->addr, connection->addrlen), + connection); + notify = connection->nth.notify_ready; + GNUNET_assert (NULL != notify); + connection->nth.notify_ready = NULL; + notify (connection->nth.notify_ready_cls, 0, NULL); + return; + } + GNUNET_assert (NULL != connection->sock); if (NULL == tc->write_ready) - { - /* special circumstances (in particular, PREREQ_DONE after - * connect): not yet ready to write, but no "fatal" error either. - * Hence retry. */ - goto SCHEDULE_WRITE; - } - if (!GNUNET_NETWORK_fdset_isset(tc->write_ready, connection->sock)) - { - GNUNET_assert(NULL == connection->write_task); - /* special circumstances (in particular, shutdown): not yet ready - * to write, but no "fatal" error either. Hence retry. */ - goto SCHEDULE_WRITE; - } - GNUNET_assert(connection->write_buffer_off >= connection->write_buffer_pos); + { + /* special circumstances (in particular, PREREQ_DONE after + * connect): not yet ready to write, but no "fatal" error either. + * Hence retry. */ + goto SCHEDULE_WRITE; + } + if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock)) + { + GNUNET_assert (NULL == connection->write_task); + /* special circumstances (in particular, shutdown): not yet ready + * to write, but no "fatal" error either. Hence retry. */ + goto SCHEDULE_WRITE; + } + GNUNET_assert (connection->write_buffer_off >= connection->write_buffer_pos); if ((NULL != connection->nth.notify_ready) && (connection->write_buffer_size < connection->nth.notify_size)) - { - connection->write_buffer = - GNUNET_realloc(connection->write_buffer, connection->nth.notify_size); - connection->write_buffer_size = connection->nth.notify_size; - } - process_notify(connection); + { + connection->write_buffer = + GNUNET_realloc (connection->write_buffer, connection->nth.notify_size); + connection->write_buffer_size = connection->nth.notify_size; + } + process_notify (connection); have = connection->write_buffer_off - connection->write_buffer_pos; if (0 == have) - { - /* no data ready for writing, terminate write loop */ - return; - } - GNUNET_assert(have <= connection->write_buffer_size); - GNUNET_assert(have + connection->write_buffer_pos <= - connection->write_buffer_size); - GNUNET_assert(connection->write_buffer_pos <= connection->write_buffer_size); + { + /* no data ready for writing, terminate write loop */ + return; + } + GNUNET_assert (have <= connection->write_buffer_size); + GNUNET_assert (have + connection->write_buffer_pos <= + connection->write_buffer_size); + GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); RETRY: ret = - GNUNET_NETWORK_socket_send(connection->sock, - &connection - ->write_buffer[connection->write_buffer_pos], - have); + GNUNET_NETWORK_socket_send (connection->sock, + &connection + ->write_buffer[connection->write_buffer_pos], + have); if (-1 == ret) + { + if (EINTR == errno) + goto RETRY; + if (NULL != connection->write_task) { - if (EINTR == errno) - goto RETRY; - if (NULL != connection->write_task) - { - GNUNET_SCHEDULER_cancel(connection->write_task); - connection->write_task = NULL; - } - signal_transmit_error(connection, errno); - return; + GNUNET_SCHEDULER_cancel (connection->write_task); + connection->write_task = NULL; } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Connection transmitted %u/%u bytes to `%s' (%p)\n", - (unsigned int)ret, - have, - GNUNET_a2s(connection->addr, connection->addrlen), - connection); + signal_transmit_error (connection, errno); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connection transmitted %u/%u bytes to `%s' (%p)\n", + (unsigned int) ret, + have, + GNUNET_a2s (connection->addr, connection->addrlen), + connection); connection->write_buffer_pos += ret; if (connection->write_buffer_pos == connection->write_buffer_off) - { - /* transmitted all pending data */ - connection->write_buffer_pos = 0; - connection->write_buffer_off = 0; - } + { + /* transmitted all pending data */ + connection->write_buffer_pos = 0; + connection->write_buffer_off = 0; + } if ((0 == connection->write_buffer_off) && (NULL == connection->nth.notify_ready)) return; /* all data sent! */ /* not done writing, schedule more */ SCHEDULE_WRITE: - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Re-scheduling transmit_ready (more to do) (%p).\n", - connection); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Re-scheduling transmit_ready (more to do) (%p).\n", + connection); have = connection->write_buffer_off - connection->write_buffer_pos; - GNUNET_assert((NULL != connection->nth.notify_ready) || (have > 0)); + GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0)); if (NULL == connection->write_task) connection->write_task = - GNUNET_SCHEDULER_add_write_net((connection->nth.notify_ready == NULL) - ? GNUNET_TIME_UNIT_FOREVER_REL - : GNUNET_TIME_absolute_get_remaining( - connection->nth.transmit_timeout), - connection->sock, - &transmit_ready, - connection); + GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == NULL) + ? GNUNET_TIME_UNIT_FOREVER_REL + : GNUNET_TIME_absolute_get_remaining ( + connection->nth.transmit_timeout), + connection->sock, + &transmit_ready, + connection); } @@ -1468,7 +1472,7 @@ SCHEDULE_WRITE: * NULL if we are already going to notify someone else (busy) */ struct GNUNET_CONNECTION_TransmitHandle * -GNUNET_CONNECTION_notify_transmit_ready( +GNUNET_CONNECTION_notify_transmit_ready ( struct GNUNET_CONNECTION_Handle *connection, size_t size, struct GNUNET_TIME_Relative timeout, @@ -1476,52 +1480,52 @@ GNUNET_CONNECTION_notify_transmit_ready( void *notify_cls) { if (NULL != connection->nth.notify_ready) - { - GNUNET_assert(0); - return NULL; - } - GNUNET_assert(NULL != notify); - GNUNET_assert(size < GNUNET_MAX_MESSAGE_SIZE); - GNUNET_assert(connection->write_buffer_off <= connection->write_buffer_size); - GNUNET_assert(connection->write_buffer_pos <= connection->write_buffer_size); - GNUNET_assert(connection->write_buffer_pos <= connection->write_buffer_off); + { + GNUNET_assert (0); + return NULL; + } + GNUNET_assert (NULL != notify); + GNUNET_assert (size < GNUNET_MAX_MESSAGE_SIZE); + GNUNET_assert (connection->write_buffer_off <= connection->write_buffer_size); + GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); + GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_off); connection->nth.notify_ready = notify; connection->nth.notify_ready_cls = notify_cls; connection->nth.connection = connection; connection->nth.notify_size = size; - connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute(timeout); - GNUNET_assert(NULL == connection->nth.timeout_task); + connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); + GNUNET_assert (NULL == connection->nth.timeout_task); if ((NULL == connection->sock) && (NULL == connection->ap_head) && (NULL == connection->dns_active) && (NULL == connection->proxy_handshake)) - { - if (NULL != connection->write_task) - GNUNET_SCHEDULER_cancel(connection->write_task); - connection->write_task = - GNUNET_SCHEDULER_add_now(&connect_error, connection); - return &connection->nth; - } + { + if (NULL != connection->write_task) + GNUNET_SCHEDULER_cancel (connection->write_task); + connection->write_task = + GNUNET_SCHEDULER_add_now (&connect_error, connection); + return &connection->nth; + } if (NULL != connection->write_task) return &connection->nth; /* previous transmission still in progress */ if (NULL != connection->sock) - { - /* connected, try to transmit now */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Scheduling transmission (%p).\n", - connection); - connection->write_task = - GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_absolute_get_remaining( - connection->nth.transmit_timeout), - connection->sock, - &transmit_ready, - connection); - return &connection->nth; - } + { + /* connected, try to transmit now */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling transmission (%p).\n", + connection); + connection->write_task = + GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining ( + connection->nth.transmit_timeout), + connection->sock, + &transmit_ready, + connection); + return &connection->nth; + } /* not yet connected, wait for connection */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", - connection); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", + connection); connection->nth.timeout_task = - GNUNET_SCHEDULER_add_delayed(timeout, &transmit_timeout, connection); + GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection); return &connection->nth; } @@ -1532,21 +1536,21 @@ GNUNET_CONNECTION_notify_transmit_ready( * @param th notification to cancel */ void -GNUNET_CONNECTION_notify_transmit_ready_cancel( +GNUNET_CONNECTION_notify_transmit_ready_cancel ( struct GNUNET_CONNECTION_TransmitHandle *th) { - GNUNET_assert(NULL != th->notify_ready); + GNUNET_assert (NULL != th->notify_ready); th->notify_ready = NULL; if (NULL != th->timeout_task) - { - GNUNET_SCHEDULER_cancel(th->timeout_task); - th->timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (th->timeout_task); + th->timeout_task = NULL; + } if (NULL != th->connection->write_task) - { - GNUNET_SCHEDULER_cancel(th->connection->write_task); - th->connection->write_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (th->connection->write_task); + th->connection->write_task = NULL; + } } @@ -1557,11 +1561,11 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel( * @return connection to be proxied */ struct GNUNET_CONNECTION_Handle * -GNUNET_CONNECTION_create_proxied_from_handshake( +GNUNET_CONNECTION_create_proxied_from_handshake ( struct GNUNET_CONNECTION_Handle *cph) { struct GNUNET_CONNECTION_Handle *proxied = - GNUNET_CONNECTION_create_from_existing(NULL); + GNUNET_CONNECTION_create_from_existing (NULL); proxied->proxy_handshake = cph; return proxied; @@ -1576,17 +1580,17 @@ GNUNET_CONNECTION_create_proxied_from_handshake( * @param proxied connection connection to proxy server */ void -GNUNET_CONNECTION_acivate_proxied(struct GNUNET_CONNECTION_Handle *proxied) +GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied) { struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake; - GNUNET_assert(NULL != cph); - GNUNET_assert(NULL == proxied->sock); - GNUNET_assert(NULL != cph->sock); + GNUNET_assert (NULL != cph); + GNUNET_assert (NULL == proxied->sock); + GNUNET_assert (NULL != cph->sock); proxied->sock = cph->sock; cph->sock = NULL; - GNUNET_CONNECTION_destroy(cph); - connect_success_continuation(proxied); + GNUNET_CONNECTION_destroy (cph); + connect_success_continuation (proxied); } diff --git a/src/transport/tcp_server_legacy.c b/src/transport/tcp_server_legacy.c index f2d5386ff..1a1d493cd 100644 --- a/src/transport/tcp_server_legacy.c +++ b/src/transport/tcp_server_legacy.c @@ -28,13 +28,18 @@ #include "gnunet_util_lib.h" #include "gnunet_protocols.h" -#define LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file(kind, "util-server", syscall, filename) +#define LOG_STRERROR_FILE(kind, syscall, \ + filename) GNUNET_log_from_strerror_file (kind, \ + "util-server", \ + syscall, \ + filename) /** * List of arrays of message handlers. */ -struct HandlerList { +struct HandlerList +{ /** * This is a linked list. */ @@ -50,7 +55,8 @@ struct HandlerList { /** * List of arrays of message handlers. */ -struct NotifyList { +struct NotifyList +{ /** * This is a doubly linked list. */ @@ -76,7 +82,8 @@ struct NotifyList { /** * @brief handle for a server */ -struct GNUNET_SERVER_Handle { +struct GNUNET_SERVER_Handle +{ /** * List of handlers for incoming messages. */ @@ -137,7 +144,7 @@ struct GNUNET_SERVER_Handle { /** * Task scheduled to do the listening. */ - struct GNUNET_SCHEDULER_Task * listen_task; + struct GNUNET_SCHEDULER_Task *listen_task; /** * Alternative function to create a MST instance. @@ -179,7 +186,8 @@ struct GNUNET_SERVER_Handle { /** * Handle server returns for aborting transmission to a client. */ -struct GNUNET_SERVER_TransmitHandle { +struct GNUNET_SERVER_TransmitHandle +{ /** * Function to call to get the message. */ @@ -200,7 +208,8 @@ struct GNUNET_SERVER_TransmitHandle { /** * @brief handle for a client of the server */ -struct GNUNET_SERVER_Client { +struct GNUNET_SERVER_Client +{ /** * This is a doubly linked list. */ @@ -235,12 +244,12 @@ struct GNUNET_SERVER_Client { /** * ID of task used to restart processing. */ - struct GNUNET_SCHEDULER_Task * restart_task; + struct GNUNET_SCHEDULER_Task *restart_task; /** * Task that warns about missing calls to #GNUNET_SERVER_receive_done. */ - struct GNUNET_SCHEDULER_Task * warn_task; + struct GNUNET_SCHEDULER_Task *warn_task; /** * Time when the warn task was started. @@ -338,13 +347,13 @@ struct GNUNET_SERVER_Client { * @return pointer to user context */ void * -GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client, - size_t size) +GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client, + size_t size) { if ((0 == client->user_context_size) && (NULL == client->user_context)) return NULL; /* never set */ - GNUNET_assert(size == client->user_context_size); + GNUNET_assert (size == client->user_context_size); return client->user_context; } @@ -358,16 +367,16 @@ GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client, * @param size number of bytes in user context struct (for verification only) */ void -GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, - void *ptr, - size_t size) +GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, + void *ptr, + size_t size) { if (NULL == ptr) - { - client->user_context_size = 0; - client->user_context = ptr; - return; - } + { + client->user_context_size = 0; + client->user_context = ptr; + return; + } client->user_context_size = size; client->user_context = ptr; } @@ -380,7 +389,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, * socket */ static void -process_listen_socket(void *cls) +process_listen_socket (void *cls) { struct GNUNET_SERVER_Handle *server = cls; const struct GNUNET_SCHEDULER_TaskContext *tc; @@ -388,27 +397,27 @@ process_listen_socket(void *cls) unsigned int i; server->listen_task = NULL; - tc = GNUNET_SCHEDULER_get_task_context(); + tc = GNUNET_SCHEDULER_get_task_context (); for (i = 0; NULL != server->listen_sockets[i]; i++) + { + if (GNUNET_NETWORK_fdset_isset (tc->read_ready, + server->listen_sockets[i])) { - if (GNUNET_NETWORK_fdset_isset(tc->read_ready, - server->listen_sockets[i])) - { - sock = - GNUNET_CONNECTION_create_from_accept(server->access_cb, - server->access_cb_cls, - server->listen_sockets[i]); - if (NULL != sock) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server accepted incoming connection.\n"); - (void)GNUNET_SERVER_connect_socket(server, - sock); - } - } + sock = + GNUNET_CONNECTION_create_from_accept (server->access_cb, + server->access_cb_cls, + server->listen_sockets[i]); + if (NULL != sock) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server accepted incoming connection.\n"); + (void) GNUNET_SERVER_connect_socket (server, + sock); + } } + } /* listen for more! */ - GNUNET_SERVER_resume(server); + GNUNET_SERVER_resume (server); } @@ -420,90 +429,90 @@ process_listen_socket(void *cls) * @return NULL on error, otherwise the listen socket */ static struct GNUNET_NETWORK_Handle * -open_listen_socket(const struct sockaddr *server_addr, - socklen_t socklen) +open_listen_socket (const struct sockaddr *server_addr, + socklen_t socklen) { struct GNUNET_NETWORK_Handle *sock; uint16_t port; int eno; switch (server_addr->sa_family) - { - case AF_INET: - port = ntohs(((const struct sockaddr_in *)server_addr)->sin_port); - break; - - case AF_INET6: - port = ntohs(((const struct sockaddr_in6 *)server_addr)->sin6_port); - break; - - case AF_UNIX: - port = 0; - break; - - default: - GNUNET_break(0); - port = 0; - break; - } - sock = GNUNET_NETWORK_socket_create(server_addr->sa_family, SOCK_STREAM, 0); + { + case AF_INET: + port = ntohs (((const struct sockaddr_in *) server_addr)->sin_port); + break; + + case AF_INET6: + port = ntohs (((const struct sockaddr_in6 *) server_addr)->sin6_port); + break; + + case AF_UNIX: + port = 0; + break; + + default: + GNUNET_break (0); + port = 0; + break; + } + sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, SOCK_STREAM, 0); if (NULL == sock) - { - LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); - errno = 0; - return NULL; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); + errno = 0; + return NULL; + } /* bind the socket */ - if (GNUNET_OK != GNUNET_NETWORK_socket_bind(sock, server_addr, socklen)) + if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, server_addr, socklen)) + { + eno = errno; + if (EADDRINUSE != errno) { - eno = errno; - if (EADDRINUSE != errno) - { - /* we don't log 'EADDRINUSE' here since an IPv4 bind may - * fail if we already took the port on IPv6; if both IPv4 and - * IPv6 binds fail, then our caller will log using the - * errno preserved in 'eno' */ - LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, - "bind"); - if (0 != port) - LOG(GNUNET_ERROR_TYPE_ERROR, - _("`%s' failed for port %d (%s).\n"), - "bind", - port, - (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); - eno = 0; - } - else - { - if (0 != port) - LOG(GNUNET_ERROR_TYPE_WARNING, - _("`%s' failed for port %d (%s): address already in use\n"), - "bind", port, - (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); - else if (AF_UNIX == server_addr->sa_family) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("`%s' failed for `%s': address already in use\n"), - "bind", - GNUNET_a2s(server_addr, socklen)); - } - } - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock)); - errno = eno; - return NULL; + /* we don't log 'EADDRINUSE' here since an IPv4 bind may + * fail if we already took the port on IPv6; if both IPv4 and + * IPv6 binds fail, then our caller will log using the + * errno preserved in 'eno' */ + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, + "bind"); + if (0 != port) + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("`%s' failed for port %d (%s).\n"), + "bind", + port, + (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); + eno = 0; } - if (GNUNET_OK != GNUNET_NETWORK_socket_listen(sock, 5)) + else { - LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, - "listen"); - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock)); - errno = 0; - return NULL; + if (0 != port) + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("`%s' failed for port %d (%s): address already in use\n"), + "bind", port, + (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); + else if (AF_UNIX == server_addr->sa_family) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("`%s' failed for `%s': address already in use\n"), + "bind", + GNUNET_a2s (server_addr, socklen)); + } } + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + errno = eno; + return NULL; + } + if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5)) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, + "listen"); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + errno = 0; + return NULL; + } if (0 != port) - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server starts to listen on port %u.\n", - port); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server starts to listen on port %u.\n", + port); return sock; } @@ -521,22 +530,22 @@ open_listen_socket(const struct sockaddr *server_addr, * (typically, "port" already in use) */ struct GNUNET_SERVER_Handle * -GNUNET_SERVER_create_with_sockets(GNUNET_CONNECTION_AccessCheck access_cb, - void *access_cb_cls, - struct GNUNET_NETWORK_Handle **lsocks, - struct GNUNET_TIME_Relative idle_timeout, - int require_found) +GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access_cb, + void *access_cb_cls, + struct GNUNET_NETWORK_Handle **lsocks, + struct GNUNET_TIME_Relative idle_timeout, + int require_found) { struct GNUNET_SERVER_Handle *server; - server = GNUNET_new(struct GNUNET_SERVER_Handle); + server = GNUNET_new (struct GNUNET_SERVER_Handle); server->idle_timeout = idle_timeout; server->listen_sockets = lsocks; server->access_cb = access_cb; server->access_cb_cls = access_cb_cls; server->require_found = require_found; if (NULL != lsocks) - GNUNET_SERVER_resume(server); + GNUNET_SERVER_resume (server); return server; } @@ -555,12 +564,12 @@ GNUNET_SERVER_create_with_sockets(GNUNET_CONNECTION_AccessCheck access_cb, * (typically, "port" already in use) */ struct GNUNET_SERVER_Handle * -GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb, - void *access_cb_cls, - struct sockaddr *const *server_addr, - const socklen_t * socklen, - struct GNUNET_TIME_Relative idle_timeout, - int require_found) +GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access_cb, + void *access_cb_cls, + struct sockaddr *const *server_addr, + const socklen_t *socklen, + struct GNUNET_TIME_Relative idle_timeout, + int require_found) { struct GNUNET_NETWORK_Handle **lsocks; unsigned int i; @@ -572,48 +581,48 @@ GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb, while (NULL != server_addr[i]) i++; if (i > 0) + { + lsocks = GNUNET_malloc (sizeof(struct GNUNET_NETWORK_Handle *) * (i + 1)); + i = 0; + j = 0; + while (NULL != server_addr[i]) { - lsocks = GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (i + 1)); - i = 0; - j = 0; - while (NULL != server_addr[i]) + seen = 0; + for (k = 0; k < i; k++) + if ((socklen[k] == socklen[i]) && + (0 == memcmp (server_addr[k], server_addr[i], socklen[i]))) { - seen = 0; - for (k = 0; k < i; k++) - if ((socklen[k] == socklen[i]) && - (0 == memcmp(server_addr[k], server_addr[i], socklen[i]))) - { - seen = 1; - break; - } - if (0 != seen) - { - /* duplicate address, skip */ - i++; - continue; - } - lsocks[j] = open_listen_socket(server_addr[i], socklen[i]); - if (NULL != lsocks[j]) - j++; - i++; - } - if (0 == j) - { - if (0 != errno) - LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "bind"); - GNUNET_free(lsocks); - lsocks = NULL; + seen = 1; + break; } + if (0 != seen) + { + /* duplicate address, skip */ + i++; + continue; + } + lsocks[j] = open_listen_socket (server_addr[i], socklen[i]); + if (NULL != lsocks[j]) + j++; + i++; } - else + if (0 == j) { + if (0 != errno) + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind"); + GNUNET_free (lsocks); lsocks = NULL; } - return GNUNET_SERVER_create_with_sockets(access_cb, - access_cb_cls, - lsocks, - idle_timeout, - require_found); + } + else + { + lsocks = NULL; + } + return GNUNET_SERVER_create_with_sockets (access_cb, + access_cb_cls, + lsocks, + idle_timeout, + require_found); } @@ -630,10 +639,10 @@ GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb, * @param client the client to set the 'monitor' flag on */ void -GNUNET_SERVER_client_mark_monitor(struct GNUNET_SERVER_Client *client) +GNUNET_SERVER_client_mark_monitor (struct GNUNET_SERVER_Client *client) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Marking client as monitor!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Marking client as monitor!\n"); client->is_monitor = GNUNET_YES; } @@ -645,11 +654,11 @@ GNUNET_SERVER_client_mark_monitor(struct GNUNET_SERVER_Client *client) * @param cls the `struct GNUNET_SERVER_Handle *` to destroy */ static void -do_destroy(void *cls) +do_destroy (void *cls) { struct GNUNET_SERVER_Handle *server = cls; - GNUNET_SERVER_destroy(server); + GNUNET_SERVER_destroy (server); } @@ -660,7 +669,7 @@ do_destroy(void *cls) * @param server server to test for full shutdown */ static void -test_monitor_clients(struct GNUNET_SERVER_Handle *server) +test_monitor_clients (struct GNUNET_SERVER_Handle *server) { struct GNUNET_SERVER_Client *client; @@ -671,7 +680,7 @@ test_monitor_clients(struct GNUNET_SERVER_Handle *server) return; /* not done yet */ server->in_soft_shutdown = GNUNET_SYSERR; - (void)GNUNET_SCHEDULER_add_now(&do_destroy, server); + (void) GNUNET_SCHEDULER_add_now (&do_destroy, server); } @@ -681,13 +690,13 @@ test_monitor_clients(struct GNUNET_SERVER_Handle *server) * @param server server to stop accepting connections. */ void -GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server) +GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server) { if (NULL != server->listen_task) - { - GNUNET_SCHEDULER_cancel(server->listen_task); - server->listen_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (server->listen_task); + server->listen_task = NULL; + } } @@ -697,7 +706,7 @@ GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server) * @param server server to stop accepting connections. */ void -GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server) +GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server) { struct GNUNET_NETWORK_FDSet *r; unsigned int i; @@ -707,25 +716,26 @@ GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server) if (NULL == server->listen_sockets[0]) return; /* nothing to do, no listen sockets! */ if (NULL == server->listen_sockets[1]) - { - /* simplified method: no fd set needed; this is then much simpler - and much more efficient */ - server->listen_task = - GNUNET_SCHEDULER_add_read_net_with_priority(GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_SCHEDULER_PRIORITY_HIGH, - server->listen_sockets[0], - &process_listen_socket, server); - return; - } - r = GNUNET_NETWORK_fdset_create(); + { + /* simplified method: no fd set needed; this is then much simpler + and much more efficient */ + server->listen_task = + GNUNET_SCHEDULER_add_read_net_with_priority (GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_SCHEDULER_PRIORITY_HIGH, + server->listen_sockets[0], + &process_listen_socket, + server); + return; + } + r = GNUNET_NETWORK_fdset_create (); i = 0; while (NULL != server->listen_sockets[i]) - GNUNET_NETWORK_fdset_set(r, server->listen_sockets[i++]); + GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]); server->listen_task = - GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, - &process_listen_socket, server); - GNUNET_NETWORK_fdset_destroy(r); + GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, + GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, + &process_listen_socket, server); + GNUNET_NETWORK_fdset_destroy (r); } @@ -736,29 +746,29 @@ GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server) * @param server server to stop listening on */ void -GNUNET_SERVER_stop_listening(struct GNUNET_SERVER_Handle *server) +GNUNET_SERVER_stop_listening (struct GNUNET_SERVER_Handle *server) { unsigned int i; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server in soft shutdown\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server in soft shutdown\n"); if (NULL != server->listen_task) - { - GNUNET_SCHEDULER_cancel(server->listen_task); - server->listen_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (server->listen_task); + server->listen_task = NULL; + } if (NULL != server->listen_sockets) - { - i = 0; - while (NULL != server->listen_sockets[i]) - GNUNET_break(GNUNET_OK == - GNUNET_NETWORK_socket_close(server->listen_sockets[i++])); - GNUNET_free(server->listen_sockets); - server->listen_sockets = NULL; - } + { + i = 0; + while (NULL != server->listen_sockets[i]) + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (server->listen_sockets[i++])); + GNUNET_free (server->listen_sockets); + server->listen_sockets = NULL; + } if (GNUNET_NO == server->in_soft_shutdown) server->in_soft_shutdown = GNUNET_YES; - test_monitor_clients(server); + test_monitor_clients (server); } @@ -768,54 +778,54 @@ GNUNET_SERVER_stop_listening(struct GNUNET_SERVER_Handle *server) * @param server server to destroy */ void -GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server) +GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server) { struct HandlerList *hpos; struct NotifyList *npos; unsigned int i; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server shutting down.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server shutting down.\n"); if (NULL != server->listen_task) - { - GNUNET_SCHEDULER_cancel(server->listen_task); - server->listen_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (server->listen_task); + server->listen_task = NULL; + } if (NULL != server->listen_sockets) - { - i = 0; - while (NULL != server->listen_sockets[i]) - GNUNET_break(GNUNET_OK == - GNUNET_NETWORK_socket_close(server->listen_sockets[i++])); - GNUNET_free(server->listen_sockets); - server->listen_sockets = NULL; - } + { + i = 0; + while (NULL != server->listen_sockets[i]) + GNUNET_break (GNUNET_OK == + GNUNET_NETWORK_socket_close (server->listen_sockets[i++])); + GNUNET_free (server->listen_sockets); + server->listen_sockets = NULL; + } while (NULL != server->clients_head) - GNUNET_SERVER_client_disconnect(server->clients_head); + GNUNET_SERVER_client_disconnect (server->clients_head); while (NULL != (hpos = server->handlers)) - { - server->handlers = hpos->next; - GNUNET_free(hpos); - } + { + server->handlers = hpos->next; + GNUNET_free (hpos); + } while (NULL != (npos = server->disconnect_notify_list_head)) - { - npos->callback(npos->callback_cls, - NULL); - GNUNET_CONTAINER_DLL_remove(server->disconnect_notify_list_head, - server->disconnect_notify_list_tail, - npos); - GNUNET_free(npos); - } + { + npos->callback (npos->callback_cls, + NULL); + GNUNET_CONTAINER_DLL_remove (server->disconnect_notify_list_head, + server->disconnect_notify_list_tail, + npos); + GNUNET_free (npos); + } while (NULL != (npos = server->connect_notify_list_head)) - { - npos->callback(npos->callback_cls, - NULL); - GNUNET_CONTAINER_DLL_remove(server->connect_notify_list_head, - server->connect_notify_list_tail, - npos); - GNUNET_free(npos); - } - GNUNET_free(server); + { + npos->callback (npos->callback_cls, + NULL); + GNUNET_CONTAINER_DLL_remove (server->connect_notify_list_head, + server->connect_notify_list_tail, + npos); + GNUNET_free (npos); + } + GNUNET_free (server); } @@ -833,12 +843,12 @@ GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server) * (or server is destroyed). */ void -GNUNET_SERVER_add_handlers(struct GNUNET_SERVER_Handle *server, - const struct GNUNET_SERVER_MessageHandler *handlers) +GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, + const struct GNUNET_SERVER_MessageHandler *handlers) { struct HandlerList *p; - p = GNUNET_new(struct HandlerList); + p = GNUNET_new (struct HandlerList); p->handlers = handlers; p->next = server->handlers; server->handlers = p; @@ -856,11 +866,11 @@ GNUNET_SERVER_add_handlers(struct GNUNET_SERVER_Handle *server, * @param cls closure for @a create, @a receive, @a destroy */ void -GNUNET_SERVER_set_callbacks(struct GNUNET_SERVER_Handle *server, - GNUNET_SERVER_MstCreateCallback create, - GNUNET_SERVER_MstDestroyCallback destroy, - GNUNET_SERVER_MstReceiveCallback receive, - void *cls) +GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server, + GNUNET_SERVER_MstCreateCallback create, + GNUNET_SERVER_MstDestroyCallback destroy, + GNUNET_SERVER_MstReceiveCallback receive, + void *cls) { server->mst_create = create; server->mst_destroy = destroy; @@ -875,19 +885,21 @@ GNUNET_SERVER_set_callbacks(struct GNUNET_SERVER_Handle *server, * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from */ static void -warn_no_receive_done(void *cls) +warn_no_receive_done (void *cls) { struct GNUNET_SERVER_Client *client = cls; - GNUNET_break(0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */ + GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */ client->warn_task = - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, - &warn_no_receive_done, client); - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"), - (unsigned int)client->warn_type, - GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(client->warn_start), - GNUNET_YES)); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, + &warn_no_receive_done, client); + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ( + "Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"), + (unsigned int) client->warn_type, + GNUNET_STRINGS_relative_time_to_string ( + GNUNET_TIME_absolute_get_duration (client->warn_start), + GNUNET_YES)); } @@ -899,13 +911,13 @@ warn_no_receive_done(void *cls) * @param client client for which to disable the warning */ void -GNUNET_SERVER_disable_receive_done_warning(struct GNUNET_SERVER_Client *client) +GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client) { if (NULL != client->warn_task) - { - GNUNET_SCHEDULER_cancel(client->warn_task); - client->warn_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (client->warn_task); + client->warn_task = NULL; + } } @@ -925,9 +937,9 @@ GNUNET_SERVER_disable_receive_done_warning(struct GNUNET_SERVER_Client *client) * client should be shut down */ int -GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server, - struct GNUNET_SERVER_Client *sender, - const struct GNUNET_MessageHeader *message) +GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, + struct GNUNET_SERVER_Client *sender, + const struct GNUNET_MessageHeader *message) { struct HandlerList *pos; const struct GNUNET_SERVER_MessageHandler *mh; @@ -936,62 +948,62 @@ GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server, uint16_t size; int found; - type = ntohs(message->type); - size = ntohs(message->size); - LOG(GNUNET_ERROR_TYPE_INFO, - "Received message of type %u and size %u from client\n", - type, size); + type = ntohs (message->type); + size = ntohs (message->size); + LOG (GNUNET_ERROR_TYPE_INFO, + "Received message of type %u and size %u from client\n", + type, size); found = GNUNET_NO; for (pos = server->handlers; NULL != pos; pos = pos->next) + { + i = 0; + while (pos->handlers[i].callback != NULL) { - i = 0; - while (pos->handlers[i].callback != NULL) + mh = &pos->handlers[i]; + if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL)) + { + if ((0 != mh->expected_size) && (mh->expected_size != size)) { - mh = &pos->handlers[i]; - if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL)) - { - if ((0 != mh->expected_size) && (mh->expected_size != size)) - { #if GNUNET8_NETWORK_IS_DEAD - LOG(GNUNET_ERROR_TYPE_WARNING, - "Expected %u bytes for message of type %u, got %u\n", - mh->expected_size, mh->type, size); - GNUNET_break_op(0); + LOG (GNUNET_ERROR_TYPE_WARNING, + "Expected %u bytes for message of type %u, got %u\n", + mh->expected_size, mh->type, size); + GNUNET_break_op (0); #else - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Expected %u bytes for message of type %u, got %u\n", - mh->expected_size, mh->type, size); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Expected %u bytes for message of type %u, got %u\n", + mh->expected_size, mh->type, size); #endif - return GNUNET_SYSERR; - } - if (NULL != sender) - { - if ((0 == sender->suspended) && - (NULL == sender->warn_task)) - { - GNUNET_break(0 != type); /* type should never be 0 here, as we don't use 0 */ - sender->warn_start = GNUNET_TIME_absolute_get(); - sender->warn_task = - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, - &warn_no_receive_done, - sender); - sender->warn_type = type; - } - sender->suspended++; - } - mh->callback(mh->callback_cls, sender, message); - found = GNUNET_YES; - } - i++; + return GNUNET_SYSERR; } + if (NULL != sender) + { + if ((0 == sender->suspended) && + (NULL == sender->warn_task)) + { + GNUNET_break (0 != type); /* type should never be 0 here, as we don't use 0 */ + sender->warn_start = GNUNET_TIME_absolute_get (); + sender->warn_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, + &warn_no_receive_done, + sender); + sender->warn_type = type; + } + sender->suspended++; + } + mh->callback (mh->callback_cls, sender, message); + found = GNUNET_YES; + } + i++; } + } if (GNUNET_NO == found) - { - LOG(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Received message of unknown type %d\n", type); - if (GNUNET_YES == server->require_found) - return GNUNET_SYSERR; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Received message of unknown type %d\n", type); + if (GNUNET_YES == server->require_found) + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1007,12 +1019,12 @@ GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server, * @param errCode code indicating errors receiving, 0 for success */ static void -process_incoming(void *cls, - const void *buf, - size_t available, - const struct sockaddr *addr, - socklen_t addrlen, - int errCode); +process_incoming (void *cls, + const void *buf, + size_t available, + const struct sockaddr *addr, + socklen_t addrlen, + int errCode); /** @@ -1029,52 +1041,53 @@ process_incoming(void *cls, * #GNUNET_SYSERR if we should instantly abort due to error in a previous step */ static void -process_mst(struct GNUNET_SERVER_Client *client, - int ret) +process_mst (struct GNUNET_SERVER_Client *client, + int ret) { while ((GNUNET_SYSERR != ret) && (NULL != client->server) && (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) + { + if (GNUNET_OK == ret) { - if (GNUNET_OK == ret) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server re-enters receive loop, timeout: %s.\n", - GNUNET_STRINGS_relative_time_to_string(client->idle_timeout, GNUNET_YES)); - client->receive_pending = GNUNET_YES; - if (GNUNET_OK != - GNUNET_CONNECTION_receive(client->connection, - GNUNET_MAX_MESSAGE_SIZE - 1, - client->idle_timeout, - &process_incoming, - client)) - return; - break; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server processes additional messages instantly.\n"); - if (NULL != client->server->mst_receive) - ret = - client->server->mst_receive(client->server->mst_cls, client->mst, - client, NULL, 0, GNUNET_NO, GNUNET_YES); - else - ret = - GNUNET_SERVER_mst_receive(client->mst, client, NULL, 0, GNUNET_NO, - GNUNET_YES); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server re-enters receive loop, timeout: %s.\n", + GNUNET_STRINGS_relative_time_to_string (client->idle_timeout, + GNUNET_YES)); + client->receive_pending = GNUNET_YES; + if (GNUNET_OK != + GNUNET_CONNECTION_receive (client->connection, + GNUNET_MAX_MESSAGE_SIZE - 1, + client->idle_timeout, + &process_incoming, + client)) + return; + break; } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n", - ret, client->server, - client->shutdown_now, - client->suspended); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server processes additional messages instantly.\n"); + if (NULL != client->server->mst_receive) + ret = + client->server->mst_receive (client->server->mst_cls, client->mst, + client, NULL, 0, GNUNET_NO, GNUNET_YES); + else + ret = + GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO, + GNUNET_YES); + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n", + ret, client->server, + client->shutdown_now, + client->suspended); if (GNUNET_NO == ret) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server has more data pending but is suspended.\n"); - client->receive_pending = GNUNET_SYSERR; /* data pending */ - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server has more data pending but is suspended.\n"); + client->receive_pending = GNUNET_SYSERR; /* data pending */ + } if ((GNUNET_SYSERR == ret) || (GNUNET_YES == client->shutdown_now)) - GNUNET_SERVER_client_disconnect(client); + GNUNET_SERVER_client_disconnect (client); } @@ -1089,12 +1102,12 @@ process_mst(struct GNUNET_SERVER_Client *client, * @param errCode code indicating errors receiving, 0 for success */ static void -process_incoming(void *cls, - const void *buf, - size_t available, - const struct sockaddr *addr, - socklen_t addrlen, - int errCode) +process_incoming (void *cls, + const void *buf, + size_t available, + const struct sockaddr *addr, + socklen_t addrlen, + int errCode) { struct GNUNET_SERVER_Client *client = cls; struct GNUNET_SERVER_Handle *server = client->server; @@ -1102,11 +1115,11 @@ process_incoming(void *cls, struct GNUNET_TIME_Absolute now; int ret; - GNUNET_assert(GNUNET_YES == client->receive_pending); + GNUNET_assert (GNUNET_YES == client->receive_pending); client->receive_pending = GNUNET_NO; - now = GNUNET_TIME_absolute_get(); - end = GNUNET_TIME_absolute_add(client->last_activity, - client->idle_timeout); + now = GNUNET_TIME_absolute_get (); + end = GNUNET_TIME_absolute_add (client->last_activity, + client->idle_timeout); if ((NULL == buf) && (0 == available) && @@ -1114,70 +1127,70 @@ process_incoming(void *cls, (0 == errCode) && (GNUNET_YES != client->shutdown_now) && (NULL != server) && - (GNUNET_YES == GNUNET_CONNECTION_check(client->connection)) && + (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && (end.abs_value_us > now.abs_value_us)) - { - /* wait longer, timeout changed (i.e. due to us sending) */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receive time out, but no disconnect due to sending (%p)\n", - client); - client->receive_pending = GNUNET_YES; - GNUNET_CONNECTION_receive(client->connection, - GNUNET_MAX_MESSAGE_SIZE - 1, - GNUNET_TIME_absolute_get_remaining(end), - &process_incoming, - client); - return; - } + { + /* wait longer, timeout changed (i.e. due to us sending) */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receive time out, but no disconnect due to sending (%p)\n", + client); + client->receive_pending = GNUNET_YES; + GNUNET_CONNECTION_receive (client->connection, + GNUNET_MAX_MESSAGE_SIZE - 1, + GNUNET_TIME_absolute_get_remaining (end), + &process_incoming, + client); + return; + } if ((NULL == buf) || (0 == available) || (0 != errCode) || (NULL == server) || (GNUNET_YES == client->shutdown_now) || - (GNUNET_YES != GNUNET_CONNECTION_check(client->connection))) - { - /* other side closed connection, error connecting, etc. */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Failed to connect or other side closed connection (%p)\n", - client); - GNUNET_SERVER_client_disconnect(client); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server receives %u bytes from `%s'.\n", - (unsigned int)available, - GNUNET_a2s(addr, addrlen)); - GNUNET_SERVER_client_keep(client); + (GNUNET_YES != GNUNET_CONNECTION_check (client->connection))) + { + /* other side closed connection, error connecting, etc. */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Failed to connect or other side closed connection (%p)\n", + client); + GNUNET_SERVER_client_disconnect (client); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server receives %u bytes from `%s'.\n", + (unsigned int) available, + GNUNET_a2s (addr, addrlen)); + GNUNET_SERVER_client_keep (client); client->last_activity = now; if (NULL != server->mst_receive) - { - ret = client->server->mst_receive(client->server->mst_cls, - client->mst, - client, - buf, - available, - GNUNET_NO, - GNUNET_YES); - } + { + ret = client->server->mst_receive (client->server->mst_cls, + client->mst, + client, + buf, + available, + GNUNET_NO, + GNUNET_YES); + } else if (NULL != client->mst) - { - ret = - GNUNET_SERVER_mst_receive(client->mst, - client, - buf, - available, - GNUNET_NO, - GNUNET_YES); - } + { + ret = + GNUNET_SERVER_mst_receive (client->mst, + client, + buf, + available, + GNUNET_NO, + GNUNET_YES); + } else - { - GNUNET_break(0); - return; - } - process_mst(client, - ret); - GNUNET_SERVER_client_drop(client); + { + GNUNET_break (0); + return; + } + process_mst (client, + ret); + GNUNET_SERVER_client_drop (client); } @@ -1188,30 +1201,30 @@ process_incoming(void *cls, * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from */ static void -restart_processing(void *cls) +restart_processing (void *cls) { struct GNUNET_SERVER_Client *client = cls; - GNUNET_assert(GNUNET_YES != client->shutdown_now); + GNUNET_assert (GNUNET_YES != client->shutdown_now); client->restart_task = NULL; if (GNUNET_NO == client->receive_pending) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n"); - client->receive_pending = GNUNET_YES; - GNUNET_CONNECTION_receive(client->connection, - GNUNET_MAX_MESSAGE_SIZE - 1, - client->idle_timeout, - &process_incoming, - client); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server continues processing messages still in the buffer.\n"); - GNUNET_SERVER_client_keep(client); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n"); + client->receive_pending = GNUNET_YES; + GNUNET_CONNECTION_receive (client->connection, + GNUNET_MAX_MESSAGE_SIZE - 1, + client->idle_timeout, + &process_incoming, + client); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server continues processing messages still in the buffer.\n"); + GNUNET_SERVER_client_keep (client); client->receive_pending = GNUNET_NO; - process_mst(client, - GNUNET_NO); - GNUNET_SERVER_client_drop(client); + process_mst (client, + GNUNET_NO); + GNUNET_SERVER_client_drop (client); } @@ -1226,25 +1239,25 @@ restart_processing(void *cls) * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing */ static int -client_message_tokenizer_callback(void *cls, - void *client, - const struct GNUNET_MessageHeader *message) +client_message_tokenizer_callback (void *cls, + void *client, + const struct GNUNET_MessageHeader *message) { struct GNUNET_SERVER_Handle *server = cls; struct GNUNET_SERVER_Client *sender = client; int ret; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Tokenizer gives server message of type %u and size %u from client\n", - ntohs(message->type), ntohs(message->size)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Tokenizer gives server message of type %u and size %u from client\n", + ntohs (message->type), ntohs (message->size)); sender->in_process_client_buffer = GNUNET_YES; - ret = GNUNET_SERVER_inject(server, sender, message); + ret = GNUNET_SERVER_inject (server, sender, message); sender->in_process_client_buffer = GNUNET_NO; if ((GNUNET_OK != ret) || (GNUNET_YES == sender->shutdown_now)) - { - GNUNET_SERVER_client_disconnect(sender); - return GNUNET_SYSERR; - } + { + GNUNET_SERVER_client_disconnect (sender); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1261,37 +1274,37 @@ client_message_tokenizer_callback(void *cls, * @return the client handle */ struct GNUNET_SERVER_Client * -GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, - struct GNUNET_CONNECTION_Handle *connection) +GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, + struct GNUNET_CONNECTION_Handle *connection) { struct GNUNET_SERVER_Client *client; struct NotifyList *n; - client = GNUNET_new(struct GNUNET_SERVER_Client); + client = GNUNET_new (struct GNUNET_SERVER_Client); client->connection = connection; client->server = server; - client->last_activity = GNUNET_TIME_absolute_get(); + client->last_activity = GNUNET_TIME_absolute_get (); client->idle_timeout = server->idle_timeout; - GNUNET_CONTAINER_DLL_insert(server->clients_head, - server->clients_tail, - client); + GNUNET_CONTAINER_DLL_insert (server->clients_head, + server->clients_tail, + client); if (NULL != server->mst_create) client->mst = - server->mst_create(server->mst_cls, client); + server->mst_create (server->mst_cls, client); else client->mst = - GNUNET_SERVER_mst_create(&client_message_tokenizer_callback, - server); - GNUNET_assert(NULL != client->mst); + GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, + server); + GNUNET_assert (NULL != client->mst); for (n = server->connect_notify_list_head; NULL != n; n = n->next) - n->callback(n->callback_cls, client); + n->callback (n->callback_cls, client); client->receive_pending = GNUNET_YES; if (GNUNET_SYSERR == - GNUNET_CONNECTION_receive(client->connection, - GNUNET_MAX_MESSAGE_SIZE - 1, - client->idle_timeout, - &process_incoming, - client)) + GNUNET_CONNECTION_receive (client->connection, + GNUNET_MAX_MESSAGE_SIZE - 1, + client->idle_timeout, + &process_incoming, + client)) return NULL; return client; } @@ -1306,8 +1319,8 @@ GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, * @param timeout new timeout for activities on the socket */ void -GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client, - struct GNUNET_TIME_Relative timeout) +GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, + struct GNUNET_TIME_Relative timeout) { client->idle_timeout = timeout; } @@ -1321,7 +1334,7 @@ GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client, * @param client the client to keep */ void -GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client) +GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client) { client->reference_count++; } @@ -1336,12 +1349,12 @@ GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client) * @param client the client to drop */ void -GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client) +GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client) { - GNUNET_assert(client->reference_count > 0); + GNUNET_assert (client->reference_count > 0); client->reference_count--; if ((GNUNET_YES == client->shutdown_now) && (0 == client->reference_count)) - GNUNET_SERVER_client_disconnect(client); + GNUNET_SERVER_client_disconnect (client); } @@ -1354,10 +1367,10 @@ GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client) * @return #GNUNET_OK on success */ int -GNUNET_SERVER_client_get_address(struct GNUNET_SERVER_Client *client, - void **addr, size_t * addrlen) +GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, + void **addr, size_t *addrlen) { - return GNUNET_CONNECTION_get_address(client->connection, addr, addrlen); + return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen); } @@ -1372,18 +1385,18 @@ GNUNET_SERVER_client_get_address(struct GNUNET_SERVER_Client *client, * @param callback_cls closure for @a callback */ void -GNUNET_SERVER_disconnect_notify(struct GNUNET_SERVER_Handle *server, - GNUNET_SERVER_DisconnectCallback callback, - void *callback_cls) +GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server, + GNUNET_SERVER_DisconnectCallback callback, + void *callback_cls) { struct NotifyList *n; - n = GNUNET_new(struct NotifyList); + n = GNUNET_new (struct NotifyList); n->callback = callback; n->callback_cls = callback_cls; - GNUNET_CONTAINER_DLL_insert(server->disconnect_notify_list_head, - server->disconnect_notify_list_tail, - n); + GNUNET_CONTAINER_DLL_insert (server->disconnect_notify_list_head, + server->disconnect_notify_list_tail, + n); } @@ -1401,21 +1414,21 @@ GNUNET_SERVER_disconnect_notify(struct GNUNET_SERVER_Handle *server, * @param callback_cls closure for @a callback */ void -GNUNET_SERVER_connect_notify(struct GNUNET_SERVER_Handle *server, - GNUNET_SERVER_ConnectCallback callback, - void *callback_cls) +GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server, + GNUNET_SERVER_ConnectCallback callback, + void *callback_cls) { struct NotifyList *n; struct GNUNET_SERVER_Client *client; - n = GNUNET_new(struct NotifyList); + n = GNUNET_new (struct NotifyList); n->callback = callback; n->callback_cls = callback_cls; - GNUNET_CONTAINER_DLL_insert(server->connect_notify_list_head, - server->connect_notify_list_tail, - n); + GNUNET_CONTAINER_DLL_insert (server->connect_notify_list_head, + server->connect_notify_list_tail, + n); for (client = server->clients_head; NULL != client; client = client->next) - callback(callback_cls, client); + callback (callback_cls, client); } @@ -1427,9 +1440,10 @@ GNUNET_SERVER_connect_notify(struct GNUNET_SERVER_Handle *server, * @param callback_cls closure for @a callback */ void -GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server, - GNUNET_SERVER_DisconnectCallback callback, - void *callback_cls) +GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, + GNUNET_SERVER_DisconnectCallback + callback, + void *callback_cls) { struct NotifyList *pos; @@ -1437,14 +1451,14 @@ GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server, if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) break; if (NULL == pos) - { - GNUNET_break(0); - return; - } - GNUNET_CONTAINER_DLL_remove(server->disconnect_notify_list_head, - server->disconnect_notify_list_tail, - pos); - GNUNET_free(pos); + { + GNUNET_break (0); + return; + } + GNUNET_CONTAINER_DLL_remove (server->disconnect_notify_list_head, + server->disconnect_notify_list_tail, + pos); + GNUNET_free (pos); } @@ -1456,9 +1470,9 @@ GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server, * @param callback_cls closure for @a callback */ void -GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server, - GNUNET_SERVER_ConnectCallback callback, - void *callback_cls) +GNUNET_SERVER_connect_notify_cancel (struct GNUNET_SERVER_Handle *server, + GNUNET_SERVER_ConnectCallback callback, + void *callback_cls) { struct NotifyList *pos; @@ -1466,14 +1480,14 @@ GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server, if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) break; if (NULL == pos) - { - GNUNET_break(0); - return; - } - GNUNET_CONTAINER_DLL_remove(server->connect_notify_list_head, - server->connect_notify_list_tail, - pos); - GNUNET_free(pos); + { + GNUNET_break (0); + return; + } + GNUNET_CONTAINER_DLL_remove (server->connect_notify_list_head, + server->connect_notify_list_tail, + pos); + GNUNET_free (pos); } @@ -1486,86 +1500,86 @@ GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server, * @param client the client to disconnect from */ void -GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client) +GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client) { struct GNUNET_SERVER_Handle *server = client->server; struct NotifyList *n; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Client is being disconnected from the server.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client is being disconnected from the server.\n"); if (NULL != client->restart_task) - { - GNUNET_SCHEDULER_cancel(client->restart_task); - client->restart_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (client->restart_task); + client->restart_task = NULL; + } if (NULL != client->warn_task) - { - GNUNET_SCHEDULER_cancel(client->warn_task); - client->warn_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (client->warn_task); + client->warn_task = NULL; + } if (GNUNET_YES == client->receive_pending) - { - GNUNET_CONNECTION_receive_cancel(client->connection); - client->receive_pending = GNUNET_NO; - } + { + GNUNET_CONNECTION_receive_cancel (client->connection); + client->receive_pending = GNUNET_NO; + } client->shutdown_now = GNUNET_YES; client->reference_count++; /* make sure nobody else clean up client... */ if ((NULL != client->mst) && (NULL != server)) - { - GNUNET_CONTAINER_DLL_remove(server->clients_head, - server->clients_tail, - client); - if (NULL != server->mst_destroy) - server->mst_destroy(server->mst_cls, - client->mst); - else - GNUNET_SERVER_mst_destroy(client->mst); - client->mst = NULL; - for (n = server->disconnect_notify_list_head; NULL != n; n = n->next) - n->callback(n->callback_cls, - client); - } + { + GNUNET_CONTAINER_DLL_remove (server->clients_head, + server->clients_tail, + client); + if (NULL != server->mst_destroy) + server->mst_destroy (server->mst_cls, + client->mst); + else + GNUNET_SERVER_mst_destroy (client->mst); + client->mst = NULL; + for (n = server->disconnect_notify_list_head; NULL != n; n = n->next) + n->callback (n->callback_cls, + client); + } client->reference_count--; if (client->reference_count > 0) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "RC of %p still positive, not destroying everything.\n", - client); - client->server = NULL; - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "RC of %p still positive, not destroying everything.\n", + client); + client->server = NULL; + return; + } if (GNUNET_YES == client->in_process_client_buffer) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Still processing inputs of %p, not destroying everything.\n", - client); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "RC of %p now zero, destroying everything.\n", - client); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Still processing inputs of %p, not destroying everything.\n", + client); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "RC of %p now zero, destroying everything.\n", + client); if (GNUNET_YES == client->persist) - GNUNET_CONNECTION_persist_(client->connection); + GNUNET_CONNECTION_persist_ (client->connection); if (NULL != client->th.cth) - GNUNET_SERVER_notify_transmit_ready_cancel(&client->th); - GNUNET_CONNECTION_destroy(client->connection); + GNUNET_SERVER_notify_transmit_ready_cancel (&client->th); + GNUNET_CONNECTION_destroy (client->connection); /* need to cancel again, as it might have been re-added in the meantime (i.e. during callbacks) */ if (NULL != client->warn_task) - { - GNUNET_SCHEDULER_cancel(client->warn_task); - client->warn_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (client->warn_task); + client->warn_task = NULL; + } if (GNUNET_YES == client->receive_pending) - { - GNUNET_CONNECTION_receive_cancel(client->connection); - client->receive_pending = GNUNET_NO; - } - GNUNET_free(client); + { + GNUNET_CONNECTION_receive_cancel (client->connection); + client->receive_pending = GNUNET_NO; + } + GNUNET_free (client); /* we might be in soft-shutdown, test if we're done */ if (NULL != server) - test_monitor_clients(server); + test_monitor_clients (server); } @@ -1578,9 +1592,9 @@ GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client) * @return #GNUNET_OK on success */ int -GNUNET_SERVER_client_disable_corking(struct GNUNET_SERVER_Client *client) +GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client) { - return GNUNET_CONNECTION_disable_corking(client->connection); + return GNUNET_CONNECTION_disable_corking (client->connection); } @@ -1594,7 +1608,7 @@ GNUNET_SERVER_client_disable_corking(struct GNUNET_SERVER_Client *client) * @return number of bytes actually transmitted */ static size_t -transmit_ready_callback_wrapper(void *cls, size_t size, void *buf) +transmit_ready_callback_wrapper (void *cls, size_t size, void *buf) { struct GNUNET_SERVER_Client *client = cls; GNUNET_CONNECTION_TransmitReadyNotify callback; @@ -1602,8 +1616,8 @@ transmit_ready_callback_wrapper(void *cls, size_t size, void *buf) client->th.cth = NULL; callback = client->th.callback; client->th.callback = NULL; - client->last_activity = GNUNET_TIME_absolute_get(); - return callback(client->th.callback_cls, size, buf); + client->last_activity = GNUNET_TIME_absolute_get (); + return callback (client->th.callback_cls, size, buf); } @@ -1623,20 +1637,23 @@ transmit_ready_callback_wrapper(void *cls, size_t size, void *buf) * NULL if we are already going to notify someone else (busy) */ struct GNUNET_SERVER_TransmitHandle * -GNUNET_SERVER_notify_transmit_ready(struct GNUNET_SERVER_Client *client, - size_t size, - struct GNUNET_TIME_Relative timeout, - GNUNET_CONNECTION_TransmitReadyNotify callback, - void *callback_cls) +GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, + size_t size, + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_TransmitReadyNotify + callback, + void *callback_cls) { if (NULL != client->th.callback) return NULL; client->th.callback_cls = callback_cls; client->th.callback = callback; - client->th.cth = GNUNET_CONNECTION_notify_transmit_ready(client->connection, size, - timeout, - &transmit_ready_callback_wrapper, - client); + client->th.cth = GNUNET_CONNECTION_notify_transmit_ready (client->connection, + size, + timeout, + & + transmit_ready_callback_wrapper, + client); return &client->th; } @@ -1647,9 +1664,10 @@ GNUNET_SERVER_notify_transmit_ready(struct GNUNET_SERVER_Client *client, * @param th request to abort */ void -GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle *th) +GNUNET_SERVER_notify_transmit_ready_cancel (struct + GNUNET_SERVER_TransmitHandle *th) { - GNUNET_CONNECTION_notify_transmit_ready_cancel(th->cth); + GNUNET_CONNECTION_notify_transmit_ready_cancel (th->cth); th->cth = NULL; th->callback = NULL; } @@ -1662,7 +1680,7 @@ GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle * * @param client the client to set the persistent flag on */ void -GNUNET_SERVER_client_persist_(struct GNUNET_SERVER_Client *client) +GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client) { client->persist = GNUNET_YES; } @@ -1681,50 +1699,50 @@ GNUNET_SERVER_client_persist_(struct GNUNET_SERVER_Client *client) * serious error) */ void -GNUNET_SERVER_receive_done(struct GNUNET_SERVER_Client *client, - int success) +GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, + int success) { if (NULL == client) return; - GNUNET_assert(client->suspended > 0); + GNUNET_assert (client->suspended > 0); client->suspended--; if (GNUNET_OK != success) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "GNUNET_SERVER_receive_done called with failure indication\n"); - if ((client->reference_count > 0) || (client->suspended > 0)) - client->shutdown_now = GNUNET_YES; - else - GNUNET_SERVER_client_disconnect(client); - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "GNUNET_SERVER_receive_done called with failure indication\n"); + if ((client->reference_count > 0) || (client->suspended > 0)) + client->shutdown_now = GNUNET_YES; + else + GNUNET_SERVER_client_disconnect (client); + return; + } if (client->suspended > 0) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "GNUNET_SERVER_receive_done called, but more clients pending\n"); - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "GNUNET_SERVER_receive_done called, but more clients pending\n"); + return; + } if (NULL != client->warn_task) - { - GNUNET_SCHEDULER_cancel(client->warn_task); - client->warn_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (client->warn_task); + client->warn_task = NULL; + } if (GNUNET_YES == client->in_process_client_buffer) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "GNUNET_SERVER_receive_done called while still in processing loop\n"); - return; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "GNUNET_SERVER_receive_done called while still in processing loop\n"); + return; + } if ((NULL == client->server) || (GNUNET_YES == client->shutdown_now)) - { - GNUNET_SERVER_client_disconnect(client); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "GNUNET_SERVER_receive_done causes restart in reading from the socket\n"); - GNUNET_assert(NULL == client->restart_task); - client->restart_task = GNUNET_SCHEDULER_add_now(&restart_processing, - client); + { + GNUNET_SERVER_client_disconnect (client); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "GNUNET_SERVER_receive_done causes restart in reading from the socket\n"); + GNUNET_assert (NULL == client->restart_task); + client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing, + client); } diff --git a/src/transport/tcp_server_mst_legacy.c b/src/transport/tcp_server_mst_legacy.c index 03c02ff75..b27590a6f 100644 --- a/src/transport/tcp_server_mst_legacy.c +++ b/src/transport/tcp_server_mst_legacy.c @@ -38,7 +38,8 @@ /** * Handle to a message stream tokenizer. */ -struct GNUNET_SERVER_MessageStreamTokenizer { +struct GNUNET_SERVER_MessageStreamTokenizer +{ /** * Function to call on completed messages. */ @@ -80,13 +81,13 @@ struct GNUNET_SERVER_MessageStreamTokenizer { * @return handle to tokenizer */ struct GNUNET_SERVER_MessageStreamTokenizer * -GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, - void *cb_cls) +GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, + void *cb_cls) { struct GNUNET_SERVER_MessageStreamTokenizer *ret; - ret = GNUNET_new(struct GNUNET_SERVER_MessageStreamTokenizer); - ret->hdr = GNUNET_malloc(GNUNET_MIN_MESSAGE_SIZE); + ret = GNUNET_new (struct GNUNET_SERVER_MessageStreamTokenizer); + ret->hdr = GNUNET_malloc (GNUNET_MIN_MESSAGE_SIZE); ret->curr_buf = GNUNET_MIN_MESSAGE_SIZE; ret->cb = cb; ret->cb_cls = cb_cls; @@ -110,10 +111,10 @@ GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, * #GNUNET_SYSERR if the data stream is corrupt */ int -GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst, - void *client_identity, - const char *buf, size_t size, - int purge, int one_shot) +GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, + void *client_identity, + const char *buf, size_t size, + int purge, int one_shot) { const struct GNUNET_MessageHeader *hdr; size_t delta; @@ -123,170 +124,170 @@ GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst, unsigned long offset; int ret; - GNUNET_assert(mst->off <= mst->pos); - GNUNET_assert(mst->pos <= mst->curr_buf); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server-mst receives %u bytes with %u bytes already in private buffer\n", - (unsigned int)size, (unsigned int)(mst->pos - mst->off)); + GNUNET_assert (mst->off <= mst->pos); + GNUNET_assert (mst->pos <= mst->curr_buf); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server-mst receives %u bytes with %u bytes already in private buffer\n", + (unsigned int) size, (unsigned int) (mst->pos - mst->off)); ret = GNUNET_OK; - ibuf = (char *)mst->hdr; + ibuf = (char *) mst->hdr; while (mst->pos > 0) - { + { do_align: - GNUNET_assert(mst->pos >= mst->off); - if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) || - (0 != (mst->off % ALIGN_FACTOR))) - { - /* need to align or need more space */ - mst->pos -= mst->off; - memmove(ibuf, &ibuf[mst->off], mst->pos); - mst->off = 0; - } - if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) - { - delta = - GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) - - (mst->pos - mst->off), size); - GNUNET_memcpy(&ibuf[mst->pos], buf, delta); - mst->pos += delta; - buf += delta; - size -= delta; - } - if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) - { - if (purge) - { - mst->off = 0; - mst->pos = 0; - } - return GNUNET_OK; - } - hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off]; - want = ntohs(hdr->size); + GNUNET_assert (mst->pos >= mst->off); + if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) || + (0 != (mst->off % ALIGN_FACTOR))) + { + /* need to align or need more space */ + mst->pos -= mst->off; + memmove (ibuf, &ibuf[mst->off], mst->pos); + mst->off = 0; + } + if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) + { + delta = + GNUNET_MIN (sizeof(struct GNUNET_MessageHeader) + - (mst->pos - mst->off), size); + GNUNET_memcpy (&ibuf[mst->pos], buf, delta); + mst->pos += delta; + buf += delta; + size -= delta; + } + if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) + { + if (purge) + { + mst->off = 0; + mst->pos = 0; + } + return GNUNET_OK; + } + hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; + want = ntohs (hdr->size); + if (want < sizeof(struct GNUNET_MessageHeader)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + if ((mst->curr_buf - mst->off < want) && + (mst->off > 0)) + { + /* can get more space by moving */ + mst->pos -= mst->off; + memmove (ibuf, &ibuf[mst->off], mst->pos); + mst->off = 0; + } + if (mst->curr_buf < want) + { + /* need to get more space by growing buffer */ + GNUNET_assert (0 == mst->off); + mst->hdr = GNUNET_realloc (mst->hdr, want); + ibuf = (char *) mst->hdr; + mst->curr_buf = want; + } + hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; + if (mst->pos - mst->off < want) + { + delta = GNUNET_MIN (want - (mst->pos - mst->off), size); + GNUNET_assert (mst->pos + delta <= mst->curr_buf); + GNUNET_memcpy (&ibuf[mst->pos], buf, delta); + mst->pos += delta; + buf += delta; + size -= delta; + } + if (mst->pos - mst->off < want) + { + if (purge) + { + mst->off = 0; + mst->pos = 0; + } + return GNUNET_OK; + } + if (one_shot == GNUNET_SYSERR) + { + /* cannot call callback again, but return value saying that + * we have another full message in the buffer */ + ret = GNUNET_NO; + goto copy; + } + if (one_shot == GNUNET_YES) + one_shot = GNUNET_SYSERR; + mst->off += want; + if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr)) + return GNUNET_SYSERR; + if (mst->off == mst->pos) + { + /* reset to beginning of buffer, it's free right now! */ + mst->off = 0; + mst->pos = 0; + } + } + GNUNET_assert (0 == mst->pos); + while (size > 0) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server-mst has %u bytes left in inbound buffer\n", + (unsigned int) size); + if (size < sizeof(struct GNUNET_MessageHeader)) + break; + offset = (unsigned long) buf; + need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO; + if (GNUNET_NO == need_align) + { + /* can try to do zero-copy and process directly from original buffer */ + hdr = (const struct GNUNET_MessageHeader *) buf; + want = ntohs (hdr->size); if (want < sizeof(struct GNUNET_MessageHeader)) - { - GNUNET_break_op(0); - return GNUNET_SYSERR; - } - if ((mst->curr_buf - mst->off < want) && - (mst->off > 0)) - { - /* can get more space by moving */ - mst->pos -= mst->off; - memmove(ibuf, &ibuf[mst->off], mst->pos); - mst->off = 0; - } - if (mst->curr_buf < want) - { - /* need to get more space by growing buffer */ - GNUNET_assert(0 == mst->off); - mst->hdr = GNUNET_realloc(mst->hdr, want); - ibuf = (char *)mst->hdr; - mst->curr_buf = want; - } - hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off]; - if (mst->pos - mst->off < want) - { - delta = GNUNET_MIN(want - (mst->pos - mst->off), size); - GNUNET_assert(mst->pos + delta <= mst->curr_buf); - GNUNET_memcpy(&ibuf[mst->pos], buf, delta); - mst->pos += delta; - buf += delta; - size -= delta; - } - if (mst->pos - mst->off < want) - { - if (purge) - { - mst->off = 0; - mst->pos = 0; - } - return GNUNET_OK; - } + { + GNUNET_break_op (0); + mst->off = 0; + return GNUNET_SYSERR; + } + if (size < want) + break; /* or not: buffer incomplete, so copy to private buffer... */ if (one_shot == GNUNET_SYSERR) - { - /* cannot call callback again, but return value saying that - * we have another full message in the buffer */ - ret = GNUNET_NO; - goto copy; - } + { + /* cannot call callback again, but return value saying that + * we have another full message in the buffer */ + ret = GNUNET_NO; + goto copy; + } if (one_shot == GNUNET_YES) one_shot = GNUNET_SYSERR; - mst->off += want; - if (GNUNET_SYSERR == mst->cb(mst->cb_cls, client_identity, hdr)) + if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr)) return GNUNET_SYSERR; - if (mst->off == mst->pos) - { - /* reset to beginning of buffer, it's free right now! */ - mst->off = 0; - mst->pos = 0; - } + buf += want; + size -= want; } - GNUNET_assert(0 == mst->pos); - while (size > 0) + else { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server-mst has %u bytes left in inbound buffer\n", - (unsigned int)size); - if (size < sizeof(struct GNUNET_MessageHeader)) - break; - offset = (unsigned long)buf; - need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO; - if (GNUNET_NO == need_align) - { - /* can try to do zero-copy and process directly from original buffer */ - hdr = (const struct GNUNET_MessageHeader *)buf; - want = ntohs(hdr->size); - if (want < sizeof(struct GNUNET_MessageHeader)) - { - GNUNET_break_op(0); - mst->off = 0; - return GNUNET_SYSERR; - } - if (size < want) - break; /* or not: buffer incomplete, so copy to private buffer... */ - if (one_shot == GNUNET_SYSERR) - { - /* cannot call callback again, but return value saying that - * we have another full message in the buffer */ - ret = GNUNET_NO; - goto copy; - } - if (one_shot == GNUNET_YES) - one_shot = GNUNET_SYSERR; - if (GNUNET_SYSERR == mst->cb(mst->cb_cls, client_identity, hdr)) - return GNUNET_SYSERR; - buf += want; - size -= want; - } - else - { - /* need to copy to private buffer to align; - * yes, we go a bit more spagetti than usual here */ - goto do_align; - } + /* need to copy to private buffer to align; + * yes, we go a bit more spagetti than usual here */ + goto do_align; } + } copy: - if ((size > 0) && (!purge)) + if ((size > 0) && (! purge)) + { + if (size + mst->pos > mst->curr_buf) { - if (size + mst->pos > mst->curr_buf) - { - mst->hdr = GNUNET_realloc(mst->hdr, size + mst->pos); - ibuf = (char *)mst->hdr; - mst->curr_buf = size + mst->pos; - } - GNUNET_assert(size + mst->pos <= mst->curr_buf); - GNUNET_memcpy(&ibuf[mst->pos], buf, size); - mst->pos += size; + mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos); + ibuf = (char *) mst->hdr; + mst->curr_buf = size + mst->pos; } + GNUNET_assert (size + mst->pos <= mst->curr_buf); + GNUNET_memcpy (&ibuf[mst->pos], buf, size); + mst->pos += size; + } if (purge) - { - mst->off = 0; - mst->pos = 0; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Server-mst leaves %u bytes in private buffer\n", - (unsigned int)(mst->pos - mst->off)); + { + mst->off = 0; + mst->pos = 0; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Server-mst leaves %u bytes in private buffer\n", + (unsigned int) (mst->pos - mst->off)); return ret; } @@ -297,10 +298,10 @@ copy: * @param mst tokenizer to destroy */ void -GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst) +GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst) { - GNUNET_free(mst->hdr); - GNUNET_free(mst); + GNUNET_free (mst->hdr); + GNUNET_free (mst); } diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c index 129511fec..54020b642 100644 --- a/src/transport/tcp_service_legacy.c +++ b/src/transport/tcp_service_legacy.c @@ -45,8 +45,8 @@ * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is */ static int -check_ipv4_listed(const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, - const struct in_addr *add) +check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, + const struct in_addr *add) { unsigned int i; @@ -54,12 +54,12 @@ check_ipv4_listed(const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, return GNUNET_NO; i = 0; while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0)) - { - if ((add->s_addr & list[i].netmask.s_addr) == - (list[i].network.s_addr & list[i].netmask.s_addr)) - return GNUNET_YES; - i++; - } + { + if ((add->s_addr & list[i].netmask.s_addr) == + (list[i].network.s_addr & list[i].netmask.s_addr)) + return GNUNET_YES; + i++; + } return GNUNET_NO; } @@ -72,8 +72,8 @@ check_ipv4_listed(const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is */ static int -check_ipv6_listed(const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, - const struct in6_addr *ip) +check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, + const struct in6_addr *ip) { unsigned int i; unsigned int j; @@ -81,20 +81,20 @@ check_ipv6_listed(const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, if (NULL == list) return GNUNET_NO; - memset(&zero, 0, sizeof(struct in6_addr)); + memset (&zero, 0, sizeof(struct in6_addr)); i = 0; NEXT: - while (0 != memcmp(&zero, &list[i].network, sizeof(struct in6_addr))) - { - for (j = 0; j < sizeof(struct in6_addr) / sizeof(int); j++) - if (((((int *)ip)[j] & ((int *)&list[i].netmask)[j])) != - (((int *)&list[i].network)[j] & ((int *)&list[i].netmask)[j])) - { - i++; - goto NEXT; - } - return GNUNET_YES; - } + while (0 != memcmp (&zero, &list[i].network, sizeof(struct in6_addr))) + { + for (j = 0; j < sizeof(struct in6_addr) / sizeof(int); j++) + if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) != + (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j])) + { + i++; + goto NEXT; + } + return GNUNET_YES; + } return GNUNET_NO; } @@ -105,7 +105,8 @@ NEXT: /** * Context for "service_task". */ -struct LEGACY_SERVICE_Context { +struct LEGACY_SERVICE_Context +{ /** * Our configuration. */ @@ -237,20 +238,20 @@ struct LEGACY_SERVICE_Context { * @return number of bytes written to 'buf' */ static size_t -write_test(void *cls, size_t size, void *buf) +write_test (void *cls, size_t size, void *buf) { struct GNUNET_SERVER_Client *client = cls; struct GNUNET_MessageHeader *msg; if (size < sizeof(struct GNUNET_MessageHeader)) - { - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); - return 0; /* client disconnected */ - } - msg = (struct GNUNET_MessageHeader *)buf; - msg->type = htons(GNUNET_MESSAGE_TYPE_TEST); - msg->size = htons(sizeof(struct GNUNET_MessageHeader)); - GNUNET_SERVER_receive_done(client, GNUNET_OK); + { + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return 0; /* client disconnected */ + } + msg = (struct GNUNET_MessageHeader *) buf; + msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); + msg->size = htons (sizeof(struct GNUNET_MessageHeader)); + GNUNET_SERVER_receive_done (client, GNUNET_OK); return sizeof(struct GNUNET_MessageHeader); } @@ -263,18 +264,18 @@ write_test(void *cls, size_t size, void *buf) * @param message the actual message */ static void -handle_test(void *cls, - struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) +handle_test (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) { /* simply bounce message back to acknowledge */ if (NULL == - GNUNET_SERVER_notify_transmit_ready(client, - sizeof(struct GNUNET_MessageHeader), - GNUNET_TIME_UNIT_FOREVER_REL, - &write_test, - client)) - GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); + GNUNET_SERVER_notify_transmit_ready (client, + sizeof(struct GNUNET_MessageHeader), + GNUNET_TIME_UNIT_FOREVER_REL, + &write_test, + client)) + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); } @@ -305,10 +306,10 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] = * for unknown address family (will be denied). */ static int -check_access(void *cls, - const struct GNUNET_CONNECTION_Credentials *uc, - const struct sockaddr *addr, - socklen_t addrlen) +check_access (void *cls, + const struct GNUNET_CONNECTION_Credentials *uc, + const struct sockaddr *addr, + socklen_t addrlen) { struct LEGACY_SERVICE_Context *sctx = cls; const struct sockaddr_in *i4; @@ -316,42 +317,42 @@ check_access(void *cls, int ret; switch (addr->sa_family) - { - case AF_INET: - GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); - i4 = (const struct sockaddr_in *)addr; - ret = ((NULL == sctx->v4_allowed) || - (check_ipv4_listed(sctx->v4_allowed, &i4->sin_addr))) && - ((NULL == sctx->v4_denied) || - (!check_ipv4_listed(sctx->v4_denied, &i4->sin_addr))); - break; - - case AF_INET6: - GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); - i6 = (const struct sockaddr_in6 *)addr; - ret = ((NULL == sctx->v6_allowed) || - (check_ipv6_listed(sctx->v6_allowed, &i6->sin6_addr))) && - ((NULL == sctx->v6_denied) || - (!check_ipv6_listed(sctx->v6_denied, &i6->sin6_addr))); - break; - - case AF_UNIX: - ret = GNUNET_OK; /* controlled using file-system ACL now */ - break; - - default: - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Unknown address family %d\n"), - addr->sa_family); - return GNUNET_SYSERR; - } + { + case AF_INET: + GNUNET_assert (addrlen == sizeof(struct sockaddr_in)); + i4 = (const struct sockaddr_in *) addr; + ret = ((NULL == sctx->v4_allowed) || + (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) && + ((NULL == sctx->v4_denied) || + (! check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); + break; + + case AF_INET6: + GNUNET_assert (addrlen == sizeof(struct sockaddr_in6)); + i6 = (const struct sockaddr_in6 *) addr; + ret = ((NULL == sctx->v6_allowed) || + (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) && + ((NULL == sctx->v6_denied) || + (! check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); + break; + + case AF_UNIX: + ret = GNUNET_OK; /* controlled using file-system ACL now */ + break; + + default: + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("Unknown address family %d\n"), + addr->sa_family); + return GNUNET_SYSERR; + } if (GNUNET_OK != ret) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Access from `%s' denied to service `%s'\n"), - GNUNET_a2s(addr, addrlen), - sctx->service_name); - } + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("Access from `%s' denied to service `%s'\n"), + GNUNET_a2s (addr, addrlen), + sctx->service_name); + } return ret; } @@ -364,14 +365,14 @@ check_access(void *cls, * @return name of the file for the process ID */ static char * -get_pid_file_name(struct LEGACY_SERVICE_Context *sctx) +get_pid_file_name (struct LEGACY_SERVICE_Context *sctx) { char *pif; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(sctx->cfg, - sctx->service_name, - "PIDFILE", - &pif)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, + sctx->service_name, + "PIDFILE", + &pif)) return NULL; return pif; } @@ -387,33 +388,33 @@ get_pid_file_name(struct LEGACY_SERVICE_Context *sctx) * no ACL configured) */ static int -process_acl4(struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, - struct LEGACY_SERVICE_Context *sctx, - const char *option) +process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, + struct LEGACY_SERVICE_Context *sctx, + const char *option) { char *opt; - if (!GNUNET_CONFIGURATION_have_value(sctx->cfg, sctx->service_name, option)) - { - *ret = NULL; - return GNUNET_OK; - } - GNUNET_break(GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(sctx->cfg, - sctx->service_name, - option, - &opt)); - if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy(opt))) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), - opt, - sctx->service_name, - option); - GNUNET_free(opt); - return GNUNET_SYSERR; - } - GNUNET_free(opt); + if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option)) + { + *ret = NULL; + return GNUNET_OK; + } + GNUNET_break (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (sctx->cfg, + sctx->service_name, + option, + &opt)); + if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt))) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), + opt, + sctx->service_name, + option); + GNUNET_free (opt); + return GNUNET_SYSERR; + } + GNUNET_free (opt); return GNUNET_OK; } @@ -428,33 +429,33 @@ process_acl4(struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, * no ACL configured) */ static int -process_acl6(struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, - struct LEGACY_SERVICE_Context *sctx, - const char *option) +process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, + struct LEGACY_SERVICE_Context *sctx, + const char *option) { char *opt; - if (!GNUNET_CONFIGURATION_have_value(sctx->cfg, sctx->service_name, option)) - { - *ret = NULL; - return GNUNET_OK; - } - GNUNET_break(GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(sctx->cfg, - sctx->service_name, - option, - &opt)); - if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy(opt))) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), - opt, - sctx->service_name, - option); - GNUNET_free(opt); - return GNUNET_SYSERR; - } - GNUNET_free(opt); + if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option)) + { + *ret = NULL; + return GNUNET_OK; + } + GNUNET_break (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (sctx->cfg, + sctx->service_name, + option, + &opt)); + if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt))) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), + opt, + sctx->service_name, + option); + GNUNET_free (opt); + return GNUNET_SYSERR; + } + GNUNET_free (opt); return GNUNET_OK; } @@ -470,30 +471,30 @@ process_acl6(struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, * parameter is ignore on systems other than LINUX */ static void -add_unixpath(struct sockaddr **saddrs, - socklen_t *saddrlens, - const char *unixpath, - int abstract) +add_unixpath (struct sockaddr **saddrs, + socklen_t *saddrlens, + const char *unixpath, + int abstract) { #ifdef AF_UNIX struct sockaddr_un *un; - un = GNUNET_new(struct sockaddr_un); + un = GNUNET_new (struct sockaddr_un); un->sun_family = AF_UNIX; - GNUNET_strlcpy(un->sun_path, unixpath, sizeof(un->sun_path)); + GNUNET_strlcpy (un->sun_path, unixpath, sizeof(un->sun_path)); #ifdef LINUX if (GNUNET_YES == abstract) un->sun_path[0] = '\0'; #endif #if HAVE_SOCKADDR_UN_SUN_LEN - un->sun_len = (u_char)sizeof(struct sockaddr_un); + un->sun_len = (u_char) sizeof(struct sockaddr_un); #endif - *saddrs = (struct sockaddr *)un; + *saddrs = (struct sockaddr *) un; *saddrlens = sizeof(struct sockaddr_un); #else /* this function should never be called * unless AF_UNIX is defined! */ - GNUNET_assert(0); + GNUNET_assert (0); #endif } @@ -519,7 +520,7 @@ add_unixpath(struct sockaddr **saddrs, * set to NULL). */ int -LEGACY_SERVICE_get_server_addresses( +LEGACY_SERVICE_get_server_addresses ( const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, struct sockaddr ***addrs, @@ -544,72 +545,72 @@ LEGACY_SERVICE_get_server_addresses( *addrs = NULL; *addr_lens = NULL; desc = NULL; - if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "DISABLEV6")) - { - if (GNUNET_SYSERR == - (disablev6 = GNUNET_CONFIGURATION_get_value_yesno(cfg, - service_name, - "DISABLEV6"))) - return GNUNET_SYSERR; - } + if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) + { + if (GNUNET_SYSERR == + (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, + service_name, + "DISABLEV6"))) + return GNUNET_SYSERR; + } else disablev6 = GNUNET_NO; - if (!disablev6) + if (! disablev6) + { + /* probe IPv6 support */ + desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); + if (NULL == desc) { - /* probe IPv6 support */ - desc = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0); - if (NULL == desc) - { - if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || - (EACCES == errno)) - { - LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); - return GNUNET_SYSERR; - } - LOG(GNUNET_ERROR_TYPE_INFO, - _( - "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), - service_name, - strerror(errno)); - disablev6 = GNUNET_YES; - } - else - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc)); - desc = NULL; - } + if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || + (EACCES == errno)) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_INFO, + _ ( + "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), + service_name, + strerror (errno)); + disablev6 = GNUNET_YES; } + else + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); + desc = NULL; + } + } port = 0; - if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT")) + if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) + { + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, + service_name, + "PORT", + &port)) { - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, - service_name, - "PORT", - &port)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Require valid port number for service `%s' in configuration!\n"), - service_name); - } - if (port > 65535) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Require valid port number for service `%s' in configuration!\n"), - service_name); - return GNUNET_SYSERR; - } + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Require valid port number for service `%s' in configuration!\n"), + service_name); } - - if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "BINDTO")) + if (port > 65535) { - GNUNET_break(GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string(cfg, + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Require valid port number for service `%s' in configuration!\n"), + service_name); + return GNUNET_SYSERR; + } + } + + if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) + { + GNUNET_break (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "BINDTO", &hostname)); - } + } else hostname = NULL; @@ -617,232 +618,232 @@ LEGACY_SERVICE_get_server_addresses( abstract = GNUNET_NO; #ifdef AF_UNIX if ((GNUNET_YES == - GNUNET_CONFIGURATION_have_value(cfg, service_name, "UNIXPATH")) && - (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, - service_name, - "UNIXPATH", - &unixpath)) && - (0 < strlen(unixpath))) + GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && + (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, + service_name, + "UNIXPATH", + &unixpath)) && + (0 < strlen (unixpath))) + { + /* probe UNIX support */ + struct sockaddr_un s_un; + + if (strlen (unixpath) >= sizeof(s_un.sun_path)) { - /* probe UNIX support */ - struct sockaddr_un s_un; - - if (strlen(unixpath) >= sizeof(s_un.sun_path)) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - _("UNIXPATH `%s' too long, maximum length is %llu\n"), - unixpath, - (unsigned long long)sizeof(s_un.sun_path)); - unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath); - LOG(GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath); - } + LOG (GNUNET_ERROR_TYPE_WARNING, + _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), + unixpath, + (unsigned long long) sizeof(s_un.sun_path)); + unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); + LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath); + } #ifdef LINUX - abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, - "TESTING", - "USE_ABSTRACT_SOCKETS"); - if (GNUNET_SYSERR == abstract) - abstract = GNUNET_NO; + abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, + "TESTING", + "USE_ABSTRACT_SOCKETS"); + if (GNUNET_SYSERR == abstract) + abstract = GNUNET_NO; #endif - if ((GNUNET_YES != abstract) && - (GNUNET_OK != GNUNET_DISK_directory_create_for_file(unixpath))) - GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); - } + if ((GNUNET_YES != abstract) && + (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath))) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); + } if (NULL != unixpath) + { + desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); + if (NULL == desc) { - desc = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0); - if (NULL == desc) - { - if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || - (EACCES == errno)) - { - LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); - GNUNET_free_non_null(hostname); - GNUNET_free(unixpath); - return GNUNET_SYSERR; - } - LOG(GNUNET_ERROR_TYPE_INFO, - _( - "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), - service_name, - strerror(errno)); - GNUNET_free(unixpath); - unixpath = NULL; - } - else - { - GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc)); - desc = NULL; - } + if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || + (EACCES == errno)) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); + GNUNET_free_non_null (hostname); + GNUNET_free (unixpath); + return GNUNET_SYSERR; + } + LOG (GNUNET_ERROR_TYPE_INFO, + _ ( + "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), + service_name, + strerror (errno)); + GNUNET_free (unixpath); + unixpath = NULL; } + else + { + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); + desc = NULL; + } + } #endif if ((0 == port) && (NULL == unixpath)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ( + "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), + service_name); + GNUNET_free_non_null (hostname); + return GNUNET_SYSERR; + } + if (0 == port) + { + saddrs = GNUNET_malloc (2 * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc (2 * sizeof(socklen_t)); + add_unixpath (saddrs, saddrlens, unixpath, abstract); + GNUNET_free_non_null (unixpath); + GNUNET_free_non_null (hostname); + *addrs = saddrs; + *addr_lens = saddrlens; + return 1; + } + + if (NULL != hostname) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Resolving `%s' since that is where `%s' will bind to.\n", + hostname, + service_name); + memset (&hints, 0, sizeof(struct addrinfo)); + if (disablev6) + hints.ai_family = AF_INET; + hints.ai_protocol = IPPROTO_TCP; + if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || + (NULL == res)) { - LOG(GNUNET_ERROR_TYPE_ERROR, - _( - "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), - service_name); - GNUNET_free_non_null(hostname); + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to resolve `%s': %s\n"), + hostname, + gai_strerror (ret)); + GNUNET_free (hostname); + GNUNET_free_non_null (unixpath); return GNUNET_SYSERR; } - if (0 == port) + next = res; + i = 0; + while (NULL != (pos = next)) { - saddrs = GNUNET_malloc(2 * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc(2 * sizeof(socklen_t)); - add_unixpath(saddrs, saddrlens, unixpath, abstract); - GNUNET_free_non_null(unixpath); - GNUNET_free_non_null(hostname); - *addrs = saddrs; - *addr_lens = saddrlens; - return 1; + next = pos->ai_next; + if ((disablev6) && (pos->ai_family == AF_INET6)) + continue; + i++; } - - if (NULL != hostname) + if (0 == i) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Resolving `%s' since that is where `%s' will bind to.\n", - hostname, - service_name); - memset(&hints, 0, sizeof(struct addrinfo)); - if (disablev6) - hints.ai_family = AF_INET; - hints.ai_protocol = IPPROTO_TCP; - if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || - (NULL == res)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Failed to resolve `%s': %s\n"), - hostname, - gai_strerror(ret)); - GNUNET_free(hostname); - GNUNET_free_non_null(unixpath); - return GNUNET_SYSERR; - } - next = res; - i = 0; - while (NULL != (pos = next)) - { - next = pos->ai_next; - if ((disablev6) && (pos->ai_family == AF_INET6)) - continue; - i++; - } - if (0 == i) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Failed to find %saddress for `%s'.\n"), - disablev6 ? "IPv4 " : "", - hostname); - freeaddrinfo(res); - GNUNET_free(hostname); - GNUNET_free_non_null(unixpath); - return GNUNET_SYSERR; - } - resi = i; + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to find %saddress for `%s'.\n"), + disablev6 ? "IPv4 " : "", + hostname); + freeaddrinfo (res); + GNUNET_free (hostname); + GNUNET_free_non_null (unixpath); + return GNUNET_SYSERR; + } + resi = i; + if (NULL != unixpath) + resi++; + saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); + i = 0; + if (NULL != unixpath) + { + add_unixpath (saddrs, saddrlens, unixpath, abstract); + i++; + } + next = res; + while (NULL != (pos = next)) + { + next = pos->ai_next; + if ((disablev6) && (AF_INET6 == pos->ai_family)) + continue; + if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) + continue; /* not TCP */ + if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) + continue; /* huh? */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Service `%s' will bind to `%s'\n", + service_name, + GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); + if (AF_INET == pos->ai_family) + { + GNUNET_assert (sizeof(struct sockaddr_in) == pos->ai_addrlen); + saddrlens[i] = pos->ai_addrlen; + saddrs[i] = GNUNET_malloc (saddrlens[i]); + GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); + } + else + { + GNUNET_assert (AF_INET6 == pos->ai_family); + GNUNET_assert (sizeof(struct sockaddr_in6) == pos->ai_addrlen); + saddrlens[i] = pos->ai_addrlen; + saddrs[i] = GNUNET_malloc (saddrlens[i]); + GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); + ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); + } + i++; + } + GNUNET_free (hostname); + freeaddrinfo (res); + resi = i; + } + else + { + /* will bind against everything, just set port */ + if (disablev6) + { + /* V4-only */ + resi = 1; if (NULL != unixpath) resi++; - saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); i = 0; + saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); if (NULL != unixpath) - { - add_unixpath(saddrs, saddrlens, unixpath, abstract); - i++; - } - next = res; - while (NULL != (pos = next)) - { - next = pos->ai_next; - if ((disablev6) && (AF_INET6 == pos->ai_family)) - continue; - if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) - continue; /* not TCP */ - if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) - continue; /* huh? */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Service `%s' will bind to `%s'\n", - service_name, - GNUNET_a2s(pos->ai_addr, pos->ai_addrlen)); - if (AF_INET == pos->ai_family) - { - GNUNET_assert(sizeof(struct sockaddr_in) == pos->ai_addrlen); - saddrlens[i] = pos->ai_addrlen; - saddrs[i] = GNUNET_malloc(saddrlens[i]); - GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); - ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); - } - else - { - GNUNET_assert(AF_INET6 == pos->ai_family); - GNUNET_assert(sizeof(struct sockaddr_in6) == pos->ai_addrlen); - saddrlens[i] = pos->ai_addrlen; - saddrs[i] = GNUNET_malloc(saddrlens[i]); - GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); - ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); - } - i++; - } - GNUNET_free(hostname); - freeaddrinfo(res); - resi = i; - } - else - { - /* will bind against everything, just set port */ - if (disablev6) - { - /* V4-only */ - resi = 1; - if (NULL != unixpath) - resi++; - i = 0; - saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); - if (NULL != unixpath) - { - add_unixpath(saddrs, saddrlens, unixpath, abstract); - i++; - } - saddrlens[i] = sizeof(struct sockaddr_in); - saddrs[i] = GNUNET_malloc(saddrlens[i]); + { + add_unixpath (saddrs, saddrlens, unixpath, abstract); + i++; + } + saddrlens[i] = sizeof(struct sockaddr_in); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; + ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; #endif - ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; - ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); - } - else - { - /* dual stack */ - resi = 2; - if (NULL != unixpath) - resi++; - saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); - saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); - i = 0; - if (NULL != unixpath) - { - add_unixpath(saddrs, saddrlens, unixpath, abstract); - i++; - } - saddrlens[i] = sizeof(struct sockaddr_in6); - saddrs[i] = GNUNET_malloc(saddrlens[i]); + ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); + } + else + { + /* dual stack */ + resi = 2; + if (NULL != unixpath) + resi++; + saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); + saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); + i = 0; + if (NULL != unixpath) + { + add_unixpath (saddrs, saddrlens, unixpath, abstract); + i++; + } + saddrlens[i] = sizeof(struct sockaddr_in6); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; + ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; #endif - ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; - ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); - i++; - saddrlens[i] = sizeof(struct sockaddr_in); - saddrs[i] = GNUNET_malloc(saddrlens[i]); + ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; + ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); + i++; + saddrlens[i] = sizeof(struct sockaddr_in); + saddrs[i] = GNUNET_malloc (saddrlens[i]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1]; + ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; #endif - ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; - ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); - } + ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; + ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); } - GNUNET_free_non_null(unixpath); + } + GNUNET_free_non_null (unixpath); *addrs = saddrs; *addr_lens = saddrlens; return resi; @@ -868,7 +869,7 @@ LEGACY_SERVICE_get_server_addresses( * @return #GNUNET_OK if configuration succeeded */ static int -setup_service(struct LEGACY_SERVICE_Context *sctx) +setup_service (struct LEGACY_SERVICE_Context *sctx) { struct GNUNET_TIME_Relative idleout; int tolerant; @@ -876,91 +877,91 @@ setup_service(struct LEGACY_SERVICE_Context *sctx) unsigned int cnt; int flags; - if (GNUNET_CONFIGURATION_have_value(sctx->cfg, - sctx->service_name, - "TIMEOUT")) + if (GNUNET_CONFIGURATION_have_value (sctx->cfg, + sctx->service_name, + "TIMEOUT")) + { + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (sctx->cfg, + sctx->service_name, + "TIMEOUT", + &idleout)) { - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(sctx->cfg, - sctx->service_name, - "TIMEOUT", - &idleout)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Specified value for `%s' of service `%s' is invalid\n"), - "TIMEOUT", - sctx->service_name); - return GNUNET_SYSERR; - } - sctx->timeout = idleout; + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Specified value for `%s' of service `%s' is invalid\n"), + "TIMEOUT", + sctx->service_name); + return GNUNET_SYSERR; } + sctx->timeout = idleout; + } else sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; - if (GNUNET_CONFIGURATION_have_value(sctx->cfg, - sctx->service_name, - "TOLERANT")) + if (GNUNET_CONFIGURATION_have_value (sctx->cfg, + sctx->service_name, + "TOLERANT")) + { + if (GNUNET_SYSERR == + (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, + sctx->service_name, + "TOLERANT"))) { - if (GNUNET_SYSERR == - (tolerant = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, - sctx->service_name, - "TOLERANT"))) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Specified value for `%s' of service `%s' is invalid\n"), - "TOLERANT", - sctx->service_name); - return GNUNET_SYSERR; - } + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Specified value for `%s' of service `%s' is invalid\n"), + "TOLERANT", + sctx->service_name); + return GNUNET_SYSERR; } + } else tolerant = GNUNET_NO; errno = 0; - if ((NULL != (nfds = getenv("LISTEN_FDS"))) && - (1 == sscanf(nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && + if ((NULL != (nfds = getenv ("LISTEN_FDS"))) && + (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE)) + { + sctx->lsocks = + GNUNET_malloc (sizeof(struct GNUNET_NETWORK_Handle *) * (cnt + 1)); + while (0 < cnt--) { - sctx->lsocks = - GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (cnt + 1)); - while (0 < cnt--) - { - flags = fcntl(3 + cnt, F_GETFD); - if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || - (NULL == - (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native(3 + cnt)))) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _( - "Could not access pre-bound socket %u, will try to bind myself\n"), - (unsigned int)3 + cnt); - cnt++; - while (sctx->lsocks[cnt] != NULL) - GNUNET_break(0 == GNUNET_NETWORK_socket_close(sctx->lsocks[cnt++])); - GNUNET_free(sctx->lsocks); - sctx->lsocks = NULL; - break; - } - } - unsetenv("LISTEN_FDS"); + flags = fcntl (3 + cnt, F_GETFD); + if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || + (NULL == + (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ( + "Could not access pre-bound socket %u, will try to bind myself\n"), + (unsigned int) 3 + cnt); + cnt++; + while (sctx->lsocks[cnt] != NULL) + GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++])); + GNUNET_free (sctx->lsocks); + sctx->lsocks = NULL; + break; + } } + unsetenv ("LISTEN_FDS"); + } if ((NULL == sctx->lsocks) && - (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses(sctx->service_name, - sctx->cfg, - &sctx->addrs, - &sctx->addrlens))) + (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses (sctx->service_name, + sctx->cfg, + &sctx->addrs, + &sctx->addrlens))) return GNUNET_SYSERR; sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; - sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, - sctx->service_name, - "UNIX_MATCH_UID"); - sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, - sctx->service_name, - "UNIX_MATCH_GID"); - process_acl4(&sctx->v4_denied, sctx, "REJECT_FROM"); - process_acl4(&sctx->v4_allowed, sctx, "ACCEPT_FROM"); - process_acl6(&sctx->v6_denied, sctx, "REJECT_FROM6"); - process_acl6(&sctx->v6_allowed, sctx, "ACCEPT_FROM6"); + sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, + sctx->service_name, + "UNIX_MATCH_UID"); + sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, + sctx->service_name, + "UNIX_MATCH_GID"); + process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); + process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); + process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); + process_acl6 (&sctx->v6_allowed, sctx, "ACCEPT_FROM6"); return GNUNET_OK; } @@ -974,14 +975,14 @@ setup_service(struct LEGACY_SERVICE_Context *sctx) * @return value of the 'USERNAME' option */ static char * -get_user_name(struct LEGACY_SERVICE_Context *sctx) +get_user_name (struct LEGACY_SERVICE_Context *sctx) { char *un; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(sctx->cfg, - sctx->service_name, - "USERNAME", - &un)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, + sctx->service_name, + "USERNAME", + &un)) return NULL; return un; } @@ -995,7 +996,7 @@ get_user_name(struct LEGACY_SERVICE_Context *sctx) * @return #GNUNET_OK on success (including no work to be done) */ static int -write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid) +write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid) { FILE *pidfd; char *pif; @@ -1003,46 +1004,46 @@ write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid) char *rdir; int len; - if (NULL == (pif = get_pid_file_name(sctx))) + if (NULL == (pif = get_pid_file_name (sctx))) return GNUNET_OK; /* no file desired */ - user = get_user_name(sctx); - rdir = GNUNET_strdup(pif); - len = strlen(rdir); + user = get_user_name (sctx); + rdir = GNUNET_strdup (pif); + len = strlen (rdir); while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) len--; rdir[len] = '\0'; - if (0 != access(rdir, F_OK)) - { - /* we get to create a directory -- and claim it - * as ours! */ - (void)GNUNET_DISK_directory_create(rdir); - if ((NULL != user) && (0 < strlen(user))) - GNUNET_DISK_file_change_owner(rdir, user); - } - if (0 != access(rdir, W_OK | X_OK)) - { - LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "access", rdir); - GNUNET_free(rdir); - GNUNET_free_non_null(user); - GNUNET_free(pif); - return GNUNET_SYSERR; - } - GNUNET_free(rdir); - pidfd = fopen(pif, "w"); + if (0 != access (rdir, F_OK)) + { + /* we get to create a directory -- and claim it + * as ours! */ + (void) GNUNET_DISK_directory_create (rdir); + if ((NULL != user) && (0 < strlen (user))) + GNUNET_DISK_file_change_owner (rdir, user); + } + if (0 != access (rdir, W_OK | X_OK)) + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir); + GNUNET_free (rdir); + GNUNET_free_non_null (user); + GNUNET_free (pif); + return GNUNET_SYSERR; + } + GNUNET_free (rdir); + pidfd = fopen (pif, "w"); if (NULL == pidfd) - { - LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "fopen", pif); - GNUNET_free(pif); - GNUNET_free_non_null(user); - return GNUNET_SYSERR; - } - if (0 > fprintf(pidfd, "%u", pid)) - LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); - GNUNET_break(0 == fclose(pidfd)); - if ((NULL != user) && (0 < strlen(user))) - GNUNET_DISK_file_change_owner(pif, user); - GNUNET_free_non_null(user); - GNUNET_free(pif); + { + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); + GNUNET_free (pif); + GNUNET_free_non_null (user); + return GNUNET_SYSERR; + } + if (0 > fprintf (pidfd, "%u", pid)) + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); + GNUNET_break (0 == fclose (pidfd)); + if ((NULL != user) && (0 < strlen (user))) + GNUNET_DISK_file_change_owner (pif, user); + GNUNET_free_non_null (user); + GNUNET_free (pif); return GNUNET_OK; } @@ -1053,16 +1054,16 @@ write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid) * @param cls the `struct LEGACY_SERVICE_Context` */ static void -shutdown_task(void *cls) +shutdown_task (void *cls) { struct LEGACY_SERVICE_Context *service = cls; struct GNUNET_SERVER_Handle *server = service->server; service->shutdown_task = NULL; if (0 != (service->options & LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN)) - GNUNET_SERVER_stop_listening(server); + GNUNET_SERVER_stop_listening (server); else - GNUNET_SERVER_destroy(server); + GNUNET_SERVER_destroy (server); } @@ -1072,79 +1073,79 @@ shutdown_task(void *cls) * @param cls service context */ static void -service_task(void *cls) +service_task (void *cls) { struct LEGACY_SERVICE_Context *sctx = cls; unsigned int i; - GNUNET_RESOLVER_connect(sctx->cfg); + GNUNET_RESOLVER_connect (sctx->cfg); if (NULL != sctx->lsocks) - sctx->server = GNUNET_SERVER_create_with_sockets(&check_access, - sctx, - sctx->lsocks, - sctx->timeout, - sctx->require_found); + sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, + sctx, + sctx->lsocks, + sctx->timeout, + sctx->require_found); else - sctx->server = GNUNET_SERVER_create(&check_access, - sctx, - sctx->addrs, - sctx->addrlens, - sctx->timeout, - sctx->require_found); + sctx->server = GNUNET_SERVER_create (&check_access, + sctx, + sctx->addrs, + sctx->addrlens, + sctx->timeout, + sctx->require_found); if (NULL == sctx->server) - { - if (NULL != sctx->addrs) - for (i = 0; NULL != sctx->addrs[i]; i++) - LOG(GNUNET_ERROR_TYPE_INFO, - _("Failed to start `%s' at `%s'\n"), - sctx->service_name, - GNUNET_a2s(sctx->addrs[i], sctx->addrlens[i])); - sctx->ret = GNUNET_SYSERR; - return; - } + { + if (NULL != sctx->addrs) + for (i = 0; NULL != sctx->addrs[i]; i++) + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Failed to start `%s' at `%s'\n"), + sctx->service_name, + GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); + sctx->ret = GNUNET_SYSERR; + return; + } if (NULL != sctx->addrs) for (i = 0; NULL != sctx->addrs[i]; i++) if ((AF_UNIX == sctx->addrs[i]->sa_family) && - ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) - GNUNET_DISK_fix_permissions(((const struct sockaddr_un *) - sctx->addrs[i]) - ->sun_path, - sctx->match_uid, - sctx->match_gid); + ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0])) + GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) + sctx->addrs[i]) + ->sun_path, + sctx->match_uid, + sctx->match_gid); if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN)) - { - /* install a task that will kill the server - * process if the scheduler ever gets a shutdown signal */ - sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown(&shutdown_task, sctx); - } - sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers)); - GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers)); + { + /* install a task that will kill the server + * process if the scheduler ever gets a shutdown signal */ + sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, sctx); + } + sctx->my_handlers = GNUNET_malloc (sizeof(defhandlers)); + GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof(defhandlers)); i = 0; while (NULL != sctx->my_handlers[i].callback) sctx->my_handlers[i++].callback_cls = sctx; - GNUNET_SERVER_add_handlers(sctx->server, sctx->my_handlers); + GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); if (-1 != sctx->ready_confirm_fd) - { - GNUNET_break(1 == write(sctx->ready_confirm_fd, ".", 1)); - GNUNET_break(0 == close(sctx->ready_confirm_fd)); - sctx->ready_confirm_fd = -1; - write_pid_file(sctx, getpid()); - } + { + GNUNET_break (1 == write (sctx->ready_confirm_fd, ".", 1)); + GNUNET_break (0 == close (sctx->ready_confirm_fd)); + sctx->ready_confirm_fd = -1; + write_pid_file (sctx, getpid ()); + } if (NULL != sctx->addrs) + { + i = 0; + while (NULL != sctx->addrs[i]) { - i = 0; - while (NULL != sctx->addrs[i]) - { - LOG(GNUNET_ERROR_TYPE_INFO, - _("Service `%s' runs at %s\n"), - sctx->service_name, - GNUNET_a2s(sctx->addrs[i], sctx->addrlens[i])); - i++; - } + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Service `%s' runs at %s\n"), + sctx->service_name, + GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); + i++; } - sctx->task(sctx->task_cls, sctx->server, sctx->cfg); + } + sctx->task (sctx->task_cls, sctx->server, sctx->cfg); } @@ -1155,73 +1156,73 @@ service_task(void *cls) * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -detach_terminal(struct LEGACY_SERVICE_Context *sctx) +detach_terminal (struct LEGACY_SERVICE_Context *sctx) { pid_t pid; int nullfd; int filedes[2]; - if (0 != pipe(filedes)) - { - LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "pipe"); - return GNUNET_SYSERR; - } - pid = fork(); + if (0 != pipe (filedes)) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); + return GNUNET_SYSERR; + } + pid = fork (); if (pid < 0) - { - LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "fork"); - return GNUNET_SYSERR; - } + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); + return GNUNET_SYSERR; + } if (0 != pid) + { + /* Parent */ + char c; + + GNUNET_break (0 == close (filedes[1])); + c = 'X'; + if (1 != read (filedes[0], &c, sizeof(char))) + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read"); + fflush (stdout); + switch (c) { - /* Parent */ - char c; - - GNUNET_break(0 == close(filedes[1])); - c = 'X'; - if (1 != read(filedes[0], &c, sizeof(char))) - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "read"); - fflush(stdout); - switch (c) - { - case '.': - exit(0); - - case 'I': - LOG(GNUNET_ERROR_TYPE_INFO, - _("Service process failed to initialize\n")); - break; - - case 'S': - LOG(GNUNET_ERROR_TYPE_INFO, - _("Service process could not initialize server function\n")); - break; - - case 'X': - LOG(GNUNET_ERROR_TYPE_INFO, - _("Service process failed to report status\n")); - break; - } - exit(1); /* child reported error */ + case '.': + exit (0); + + case 'I': + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Service process failed to initialize\n")); + break; + + case 'S': + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Service process could not initialize server function\n")); + break; + + case 'X': + LOG (GNUNET_ERROR_TYPE_INFO, + _ ("Service process failed to report status\n")); + break; } - GNUNET_break(0 == close(0)); - GNUNET_break(0 == close(1)); - GNUNET_break(0 == close(filedes[0])); - nullfd = open("/dev/null", O_RDWR | O_APPEND); + exit (1); /* child reported error */ + } + GNUNET_break (0 == close (0)); + GNUNET_break (0 == close (1)); + GNUNET_break (0 == close (filedes[0])); + nullfd = open ("/dev/null", O_RDWR | O_APPEND); if (nullfd < 0) return GNUNET_SYSERR; /* set stdin/stdout to /dev/null */ - if ((dup2(nullfd, 0) < 0) || (dup2(nullfd, 1) < 0)) - { - LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "dup2"); - (void)close(nullfd); - return GNUNET_SYSERR; - } - (void)close(nullfd); + if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0)) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); + (void) close (nullfd); + return GNUNET_SYSERR; + } + (void) close (nullfd); /* Detach from controlling terminal */ - pid = setsid(); + pid = setsid (); if (-1 == pid) - LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "setsid"); + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid"); sctx->ready_confirm_fd = filedes[1]; return GNUNET_OK; @@ -1235,45 +1236,45 @@ detach_terminal(struct LEGACY_SERVICE_Context *sctx) * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -set_user_id(struct LEGACY_SERVICE_Context *sctx) +set_user_id (struct LEGACY_SERVICE_Context *sctx) { char *user; - if (NULL == (user = get_user_name(sctx))) + if (NULL == (user = get_user_name (sctx))) return GNUNET_OK; /* keep */ struct passwd *pws; errno = 0; - pws = getpwnam(user); + pws = getpwnam (user); if (NULL == pws) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Cannot obtain information about user `%s': %s\n"), - user, - errno == 0 ? _("No such user") : strerror(errno)); - GNUNET_free(user); - return GNUNET_SYSERR; - } - if ((0 != setgid(pws->pw_gid)) || (0 != setegid(pws->pw_gid)) || + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Cannot obtain information about user `%s': %s\n"), + user, + errno == 0 ? _ ("No such user") : strerror (errno)); + GNUNET_free (user); + return GNUNET_SYSERR; + } + if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) || #if HAVE_INITGROUPS - (0 != initgroups(user, pws->pw_gid)) || + (0 != initgroups (user, pws->pw_gid)) || #endif - (0 != setuid(pws->pw_uid)) || (0 != seteuid(pws->pw_uid))) + (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid))) + { + if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || + (0 != setreuid (pws->pw_uid, pws->pw_uid))) { - if ((0 != setregid(pws->pw_gid, pws->pw_gid)) || - (0 != setreuid(pws->pw_uid, pws->pw_uid))) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - _("Cannot change user/group to `%s': %s\n"), - user, - strerror(errno)); - GNUNET_free(user); - return GNUNET_SYSERR; - } + LOG (GNUNET_ERROR_TYPE_ERROR, + _ ("Cannot change user/group to `%s': %s\n"), + user, + strerror (errno)); + GNUNET_free (user); + return GNUNET_SYSERR; } + } - GNUNET_free(user); + GNUNET_free (user); return GNUNET_OK; } @@ -1284,15 +1285,15 @@ set_user_id(struct LEGACY_SERVICE_Context *sctx) * @param sctx service context */ static void -pid_file_delete(struct LEGACY_SERVICE_Context *sctx) +pid_file_delete (struct LEGACY_SERVICE_Context *sctx) { - char *pif = get_pid_file_name(sctx); + char *pif = get_pid_file_name (sctx); if (NULL == pif) return; /* no PID file */ - if (0 != unlink(pif)) - LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "unlink", pif); - GNUNET_free(pif); + if (0 != unlink (pif)) + LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif); + GNUNET_free (pif); } @@ -1310,19 +1311,19 @@ pid_file_delete(struct LEGACY_SERVICE_Context *sctx) * if we shutdown nicely */ int -LEGACY_SERVICE_run(int argc, - char *const *argv, - const char *service_name, - enum LEGACY_SERVICE_Options options, - LEGACY_SERVICE_Main task, - void *task_cls) +LEGACY_SERVICE_run (int argc, + char *const *argv, + const char *service_name, + enum LEGACY_SERVICE_Options options, + LEGACY_SERVICE_Main task, + void *task_cls) { #define HANDLE_ERROR \ do \ - { \ - GNUNET_break(0); \ - goto shutdown; \ - } while (0) + { \ + GNUNET_break (0); \ + goto shutdown; \ + } while (0) int err; int ret; @@ -1340,32 +1341,32 @@ LEGACY_SERVICE_run(int argc, const char *xdg; struct GNUNET_GETOPT_CommandLineOption service_options[] = - { GNUNET_GETOPT_option_cfgfile(&opt_cfg_fn), - GNUNET_GETOPT_option_flag('d', - "daemonize", - gettext_noop( - "do daemonize (detach from terminal)"), - &do_daemonize), - GNUNET_GETOPT_option_help(NULL), - GNUNET_GETOPT_option_loglevel(&loglev), - GNUNET_GETOPT_option_logfile(&logfile), - GNUNET_GETOPT_option_version(PACKAGE_VERSION " " VCS_VERSION), + { GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn), + GNUNET_GETOPT_option_flag ('d', + "daemonize", + gettext_noop ( + "do daemonize (detach from terminal)"), + &do_daemonize), + GNUNET_GETOPT_option_help (NULL), + GNUNET_GETOPT_option_loglevel (&loglev), + GNUNET_GETOPT_option_logfile (&logfile), + GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION), GNUNET_GETOPT_OPTION_END }; err = 1; do_daemonize = 0; logfile = NULL; loglev = NULL; opt_cfg_fn = NULL; - xdg = getenv("XDG_CONFIG_HOME"); + xdg = getenv ("XDG_CONFIG_HOME"); if (NULL != xdg) - GNUNET_asprintf(&cfg_fn, - "%s%s%s", - xdg, - DIR_SEPARATOR_STR, - GNUNET_OS_project_data_get()->config_file); + GNUNET_asprintf (&cfg_fn, + "%s%s%s", + xdg, + DIR_SEPARATOR_STR, + GNUNET_OS_project_data_get ()->config_file); else - cfg_fn = GNUNET_strdup(GNUNET_OS_project_data_get()->user_config_file); - memset(&sctx, 0, sizeof(sctx)); + cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); + memset (&sctx, 0, sizeof(sctx)); sctx.options = options; sctx.ready_confirm_fd = -1; sctx.ret = GNUNET_OK; @@ -1373,117 +1374,117 @@ LEGACY_SERVICE_run(int argc, sctx.task = task; sctx.task_cls = task_cls; sctx.service_name = service_name; - sctx.cfg = cfg = GNUNET_CONFIGURATION_create(); + sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); /* setup subsystems */ - ret = GNUNET_GETOPT_run(service_name, service_options, argc, argv); + ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv); if (GNUNET_SYSERR == ret) goto shutdown; if (GNUNET_NO == ret) - { - err = 0; - goto shutdown; - } - if (GNUNET_OK != GNUNET_log_setup(service_name, loglev, logfile)) + { + err = 0; + goto shutdown; + } + if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile)) HANDLE_ERROR; if (NULL == opt_cfg_fn) - opt_cfg_fn = GNUNET_strdup(cfg_fn); - if (GNUNET_YES == GNUNET_DISK_file_test(opt_cfg_fn)) + opt_cfg_fn = GNUNET_strdup (cfg_fn); + if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_fn)) + { + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn)) { - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, opt_cfg_fn)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Malformed configuration file `%s', exit ...\n"), - opt_cfg_fn); - goto shutdown; - } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Malformed configuration file `%s', exit ...\n"), + opt_cfg_fn); + goto shutdown; } + } else + { + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL)) { - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, NULL)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Malformed configuration, exit ...\n")); - goto shutdown; - } - if (0 != strcmp(opt_cfg_fn, cfg_fn)) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Could not access configuration file `%s'\n"), - opt_cfg_fn); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Malformed configuration, exit ...\n")); + goto shutdown; } - if (GNUNET_OK != setup_service(&sctx)) + if (0 != strcmp (opt_cfg_fn, cfg_fn)) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Could not access configuration file `%s'\n"), + opt_cfg_fn); + } + if (GNUNET_OK != setup_service (&sctx)) goto shutdown; - if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal(&sctx))) + if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sctx))) HANDLE_ERROR; - if (GNUNET_OK != set_user_id(&sctx)) + if (GNUNET_OK != set_user_id (&sctx)) goto shutdown; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Service `%s' runs with configuration from `%s'\n", - service_name, - opt_cfg_fn); - if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, - "TESTING", - "SKEW_OFFSET", - &skew_offset)) && - (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, - "TESTING", - "SKEW_VARIANCE", - &skew_variance))) - { - clock_offset = skew_offset - skew_variance; - GNUNET_TIME_set_offset(clock_offset); - LOG(GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); - } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Service `%s' runs with configuration from `%s'\n", + service_name, + opt_cfg_fn); + if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, + "TESTING", + "SKEW_OFFSET", + &skew_offset)) && + (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, + "TESTING", + "SKEW_VARIANCE", + &skew_variance))) + { + clock_offset = skew_offset - skew_variance; + GNUNET_TIME_set_offset (clock_offset); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); + } /* actually run service */ err = 0; - GNUNET_SCHEDULER_run(&service_task, &sctx); + GNUNET_SCHEDULER_run (&service_task, &sctx); /* shutdown */ if ((1 == do_daemonize) && (NULL != sctx.server)) - pid_file_delete(&sctx); - GNUNET_free_non_null(sctx.my_handlers); + pid_file_delete (&sctx); + GNUNET_free_non_null (sctx.my_handlers); shutdown: if (-1 != sctx.ready_confirm_fd) - { - if (1 != write(sctx.ready_confirm_fd, err ? "I" : "S", 1)) - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "write"); - GNUNET_break(0 == close(sctx.ready_confirm_fd)); - } + { + if (1 != write (sctx.ready_confirm_fd, err ? "I" : "S", 1)) + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); + GNUNET_break (0 == close (sctx.ready_confirm_fd)); + } #if HAVE_MALLINFO { char *counter; - if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value(sctx.cfg, - service_name, - "GAUGER_HEAP")) && - (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(sctx.cfg, - service_name, - "GAUGER_HEAP", - &counter))) - { - struct mallinfo mi; + if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg, + service_name, + "GAUGER_HEAP")) && + (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg, + service_name, + "GAUGER_HEAP", + &counter))) + { + struct mallinfo mi; - mi = mallinfo(); - GAUGER(service_name, counter, mi.usmblks, "blocks"); - GNUNET_free(counter); - } + mi = mallinfo (); + GAUGER (service_name, counter, mi.usmblks, "blocks"); + GNUNET_free (counter); + } } #endif - GNUNET_CONFIGURATION_destroy(cfg); + GNUNET_CONFIGURATION_destroy (cfg); i = 0; if (NULL != sctx.addrs) while (NULL != sctx.addrs[i]) - GNUNET_free(sctx.addrs[i++]); - GNUNET_free_non_null(sctx.addrs); - GNUNET_free_non_null(sctx.addrlens); - GNUNET_free_non_null(logfile); - GNUNET_free_non_null(loglev); - GNUNET_free(cfg_fn); - GNUNET_free_non_null(opt_cfg_fn); - GNUNET_free_non_null(sctx.v4_denied); - GNUNET_free_non_null(sctx.v6_denied); - GNUNET_free_non_null(sctx.v4_allowed); - GNUNET_free_non_null(sctx.v6_allowed); + GNUNET_free (sctx.addrs[i++]); + GNUNET_free_non_null (sctx.addrs); + GNUNET_free_non_null (sctx.addrlens); + GNUNET_free_non_null (logfile); + GNUNET_free_non_null (loglev); + GNUNET_free (cfg_fn); + GNUNET_free_non_null (opt_cfg_fn); + GNUNET_free_non_null (sctx.v4_denied); + GNUNET_free_non_null (sctx.v6_denied); + GNUNET_free_non_null (sctx.v4_allowed); + GNUNET_free_non_null (sctx.v6_allowed); return err ? GNUNET_SYSERR : sctx.ret; } @@ -1499,14 +1500,14 @@ shutdown: * @return NULL on error, service handle */ struct LEGACY_SERVICE_Context * -LEGACY_SERVICE_start(const char *service_name, - const struct GNUNET_CONFIGURATION_Handle *cfg, - enum LEGACY_SERVICE_Options options) +LEGACY_SERVICE_start (const char *service_name, + const struct GNUNET_CONFIGURATION_Handle *cfg, + enum LEGACY_SERVICE_Options options) { int i; struct LEGACY_SERVICE_Context *sctx; - sctx = GNUNET_new(struct LEGACY_SERVICE_Context); + sctx = GNUNET_new (struct LEGACY_SERVICE_Context); sctx->ready_confirm_fd = -1; /* no daemonizing */ sctx->ret = GNUNET_OK; sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; @@ -1515,47 +1516,47 @@ LEGACY_SERVICE_start(const char *service_name, sctx->options = options; /* setup subsystems */ - if (GNUNET_OK != setup_service(sctx)) - { - LEGACY_SERVICE_stop(sctx); - return NULL; - } + if (GNUNET_OK != setup_service (sctx)) + { + LEGACY_SERVICE_stop (sctx); + return NULL; + } if (NULL != sctx->lsocks) - sctx->server = GNUNET_SERVER_create_with_sockets(&check_access, - sctx, - sctx->lsocks, - sctx->timeout, - sctx->require_found); + sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, + sctx, + sctx->lsocks, + sctx->timeout, + sctx->require_found); else - sctx->server = GNUNET_SERVER_create(&check_access, - sctx, - sctx->addrs, - sctx->addrlens, - sctx->timeout, - sctx->require_found); + sctx->server = GNUNET_SERVER_create (&check_access, + sctx, + sctx->addrs, + sctx->addrlens, + sctx->timeout, + sctx->require_found); if (NULL == sctx->server) - { - LEGACY_SERVICE_stop(sctx); - return NULL; - } + { + LEGACY_SERVICE_stop (sctx); + return NULL; + } if (NULL != sctx->addrs) for (i = 0; NULL != sctx->addrs[i]; i++) if ((AF_UNIX == sctx->addrs[i]->sa_family) && - ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) - GNUNET_DISK_fix_permissions(((const struct sockaddr_un *) - sctx->addrs[i]) - ->sun_path, - sctx->match_uid, - sctx->match_gid); - - sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers)); - GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers)); + ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0])) + GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) + sctx->addrs[i]) + ->sun_path, + sctx->match_uid, + sctx->match_gid); + + sctx->my_handlers = GNUNET_malloc (sizeof(defhandlers)); + GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof(defhandlers)); i = 0; while ((sctx->my_handlers[i].callback != NULL)) sctx->my_handlers[i++].callback_cls = sctx; - GNUNET_SERVER_add_handlers(sctx->server, sctx->my_handlers); + GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); return sctx; } @@ -1568,7 +1569,7 @@ LEGACY_SERVICE_start(const char *service_name, * @return handle to the server for this service, NULL if there is none */ struct GNUNET_SERVER_Handle * -LEGACY_SERVICE_get_server(struct LEGACY_SERVICE_Context *ctx) +LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx) { return ctx->server; } @@ -1582,7 +1583,7 @@ LEGACY_SERVICE_get_server(struct LEGACY_SERVICE_Context *ctx) * array of listen sockets. */ struct GNUNET_NETWORK_Handle *const * -LEGACY_SERVICE_get_listen_sockets(struct LEGACY_SERVICE_Context *ctx) +LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx) { return ctx->lsocks; } @@ -1594,7 +1595,7 @@ LEGACY_SERVICE_get_listen_sockets(struct LEGACY_SERVICE_Context *ctx) * @param sctx the service context returned from the start function */ void -LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *sctx) +LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx) { unsigned int i; @@ -1602,43 +1603,43 @@ LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *sctx) { char *counter; - if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value(sctx->cfg, - sctx->service_name, - "GAUGER_HEAP")) && - (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(sctx->cfg, - sctx->service_name, - "GAUGER_HEAP", - &counter))) - { - struct mallinfo mi; + if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx->cfg, + sctx->service_name, + "GAUGER_HEAP")) && + (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx->cfg, + sctx->service_name, + "GAUGER_HEAP", + &counter))) + { + struct mallinfo mi; - mi = mallinfo(); - GAUGER(sctx->service_name, counter, mi.usmblks, "blocks"); - GNUNET_free(counter); - } + mi = mallinfo (); + GAUGER (sctx->service_name, counter, mi.usmblks, "blocks"); + GNUNET_free (counter); + } } #endif if (NULL != sctx->shutdown_task) - { - GNUNET_SCHEDULER_cancel(sctx->shutdown_task); - sctx->shutdown_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (sctx->shutdown_task); + sctx->shutdown_task = NULL; + } if (NULL != sctx->server) - GNUNET_SERVER_destroy(sctx->server); - GNUNET_free_non_null(sctx->my_handlers); + GNUNET_SERVER_destroy (sctx->server); + GNUNET_free_non_null (sctx->my_handlers); if (NULL != sctx->addrs) - { - i = 0; - while (NULL != sctx->addrs[i]) - GNUNET_free(sctx->addrs[i++]); - GNUNET_free(sctx->addrs); - } - GNUNET_free_non_null(sctx->addrlens); - GNUNET_free_non_null(sctx->v4_denied); - GNUNET_free_non_null(sctx->v6_denied); - GNUNET_free_non_null(sctx->v4_allowed); - GNUNET_free_non_null(sctx->v6_allowed); - GNUNET_free(sctx); + { + i = 0; + while (NULL != sctx->addrs[i]) + GNUNET_free (sctx->addrs[i++]); + GNUNET_free (sctx->addrs); + } + GNUNET_free_non_null (sctx->addrlens); + GNUNET_free_non_null (sctx->v4_denied); + GNUNET_free_non_null (sctx->v6_denied); + GNUNET_free_non_null (sctx->v4_allowed); + GNUNET_free_non_null (sctx->v6_allowed); + GNUNET_free (sctx); } diff --git a/src/transport/test_communicator_unix.c b/src/transport/test_communicator_unix.c index 77bd4bb38..d1ab99910 100644 --- a/src/transport/test_communicator_unix.c +++ b/src/transport/test_communicator_unix.c @@ -33,55 +33,61 @@ #include -#define LOG(kind, ...) GNUNET_log_from(kind, "test_transport_communicator_unix", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, \ + "test_transport_communicator_unix", \ + __VA_ARGS__) #define NUM_PEERS 2 static struct GNUNET_PeerIdentity peer_id[NUM_PEERS]; -static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS]; +static struct +GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS]; -//static char *addresses[NUM_PEERS]; +// static char *addresses[NUM_PEERS]; #define PAYLOAD_SIZE 256 -//static char payload[PAYLOAD_SIZE] = "TEST PAYLOAD"; -//static char payload[] = "TEST PAYLOAD"; +// static char payload[PAYLOAD_SIZE] = "TEST PAYLOAD"; +// static char payload[] = "TEST PAYLOAD"; static uint32_t payload = 42; static void -communicator_available_cb(void *cls, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, - enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, - char *address_prefix) +communicator_available_cb (void *cls, + struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle + *tc_h, + enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, + char *address_prefix) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Communicator available. (cc: %u, prefix: %s)\n", - cc, - address_prefix); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Communicator available. (cc: %u, prefix: %s)\n", + cc, + address_prefix); } static void -add_address_cb(void *cls, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, - const char *address, - struct GNUNET_TIME_Relative expiration, - uint32_t aid, - enum GNUNET_NetworkType nt) +add_address_cb (void *cls, + struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * + tc_h, + const char *address, + struct GNUNET_TIME_Relative expiration, + uint32_t aid, + enum GNUNET_NetworkType nt) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n", - address, - expiration.rel_value_us, - aid, - nt); - //addresses[1] = GNUNET_strdup (address); - GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(tc_hs[0], - &peer_id[1], - address); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n", + address, + expiration.rel_value_us, + aid, + nt); + // addresses[1] = GNUNET_strdup (address); + GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0], + &peer_id[1], + address); } @@ -97,16 +103,18 @@ add_address_cb(void *cls, * #GNUNET_NO if queue will not be established (bogous address) */ static void -queue_create_reply_cb(void *cls, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, - int will_try) +queue_create_reply_cb (void *cls, + struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * + tc_h, + int will_try) { if (GNUNET_YES == will_try) - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Queue will be established!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Queue will be established!\n"); else - LOG(GNUNET_ERROR_TYPE_WARNING, - "Queue won't be established (bougus address?)!\n"); + LOG (GNUNET_ERROR_TYPE_WARNING, + "Queue won't be established (bougus address?)!\n"); } @@ -122,15 +130,16 @@ queue_create_reply_cb(void *cls, * @param tc_queue Handle to newly opened queue */ static void -add_queue_cb(void *cls, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue) +add_queue_cb (void *cls, + struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, + struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * + tc_queue) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Got Queue!\n"); - GNUNET_TRANSPORT_TESTING_transport_communicator_send(tc_queue, - &payload, - sizeof(payload)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Got Queue!\n"); + GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_queue, + &payload, + sizeof(payload)); } @@ -144,9 +153,10 @@ add_queue_cb(void *cls, * @param msg Received message */ void -incoming_message_cb(void *cls, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, - const struct GNUNET_MessageHeader *msg) +incoming_message_cb (void *cls, + struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle + *tc_h, + const struct GNUNET_MessageHeader *msg) { } @@ -157,11 +167,11 @@ incoming_message_cb(void *cls, * @param cls Closure - Handle to configuration */ static void -run(void *cls) +run (void *cls) { struct GNUNET_CONFIGURATION_Handle *cfg = cls; - tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( + tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( "transport", "gnunet-communicator-unix", "test_communicator_1.conf", @@ -171,7 +181,7 @@ run(void *cls) &add_queue_cb, NULL, NULL); /* cls */ - tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( + tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( "transport", "gnunet-communicator-unix", "test_communicator_2.conf", @@ -184,8 +194,8 @@ run(void *cls) } int -main(int argc, - char *const *argv) +main (int argc, + char *const *argv) { char *cfg_filename; char *opt_cfg_filename; @@ -195,73 +205,73 @@ main(int argc, struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_GETOPT_CommandLineOption service_options[] = { - GNUNET_GETOPT_option_cfgfile(&opt_cfg_filename), - GNUNET_GETOPT_option_help(NULL), - GNUNET_GETOPT_option_loglevel(&loglev), - GNUNET_GETOPT_option_logfile(&logfile), + GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), + GNUNET_GETOPT_option_help (NULL), + GNUNET_GETOPT_option_loglevel (&loglev), + GNUNET_GETOPT_option_logfile (&logfile), GNUNET_GETOPT_OPTION_END }; - if (GNUNET_OK != GNUNET_log_setup("test_communicator_unix", - loglev, - logfile)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + if (GNUNET_OK != GNUNET_log_setup ("test_communicator_unix", + loglev, + logfile)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } - xdg = getenv("XDG_CONFIG_HOME"); + xdg = getenv ("XDG_CONFIG_HOME"); if (NULL != xdg) - GNUNET_asprintf(&cfg_filename, - "%s%s%s", - xdg, - DIR_SEPARATOR_STR, - GNUNET_OS_project_data_get()->config_file); + GNUNET_asprintf (&cfg_filename, + "%s%s%s", + xdg, + DIR_SEPARATOR_STR, + GNUNET_OS_project_data_get ()->config_file); else - cfg_filename = GNUNET_strdup(GNUNET_OS_project_data_get()->user_config_file); - cfg = GNUNET_CONFIGURATION_create(); + cfg_filename = GNUNET_strdup ( + GNUNET_OS_project_data_get ()->user_config_file); + cfg = GNUNET_CONFIGURATION_create (); if (NULL != opt_cfg_filename) + { + if ((GNUNET_YES != + GNUNET_DISK_file_test (opt_cfg_filename)) || + (GNUNET_SYSERR == + GNUNET_CONFIGURATION_load (cfg, + opt_cfg_filename))) { - if ((GNUNET_YES != - GNUNET_DISK_file_test(opt_cfg_filename)) || - (GNUNET_SYSERR == - GNUNET_CONFIGURATION_load(cfg, - opt_cfg_filename))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Malformed configuration file `%s', exit ...\n"), - opt_cfg_filename); - return GNUNET_SYSERR; - } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Malformed configuration file `%s', exit ...\n"), + opt_cfg_filename); + return GNUNET_SYSERR; } + } else + { + if (GNUNET_YES == + GNUNET_DISK_file_test (cfg_filename)) { - if (GNUNET_YES == - GNUNET_DISK_file_test(cfg_filename)) - { - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_load(cfg, - cfg_filename)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Malformed configuration file `%s', exit ...\n"), - cfg_filename); - return GNUNET_SYSERR; - } - } - else - { - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_load(cfg, - NULL)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Malformed configuration, exit ...\n")); - return GNUNET_SYSERR; - } - } + if (GNUNET_SYSERR == + GNUNET_CONFIGURATION_load (cfg, + cfg_filename)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Malformed configuration file `%s', exit ...\n"), + cfg_filename); + return GNUNET_SYSERR; + } } - GNUNET_SCHEDULER_run(&run, - cfg); + else + { + if (GNUNET_SYSERR == + GNUNET_CONFIGURATION_load (cfg, + NULL)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Malformed configuration, exit ...\n")); + return GNUNET_SYSERR; + } + } + } + GNUNET_SCHEDULER_run (&run, + cfg); } - diff --git a/src/transport/test_http_common.c b/src/transport/test_http_common.c index 251b1543a..d925f1318 100644 --- a/src/transport/test_http_common.c +++ b/src/transport/test_http_common.c @@ -28,227 +28,236 @@ static void -clean(struct SplittedHTTPAddress *addr) +clean (struct SplittedHTTPAddress *addr) { if (NULL == addr) return; - GNUNET_free_non_null(addr->host); - GNUNET_free_non_null(addr->path); - GNUNET_free_non_null(addr->protocol); - GNUNET_free(addr); + GNUNET_free_non_null (addr->host); + GNUNET_free_non_null (addr->path); + GNUNET_free_non_null (addr->protocol); + GNUNET_free (addr); } static int -check(struct SplittedHTTPAddress *addr, - const char *protocol, - const char *host, - int port, - const char *path) +check (struct SplittedHTTPAddress *addr, + const char *protocol, + const char *host, + int port, + const char *path) { if (NULL == addr) return GNUNET_NO; if (((NULL == addr->protocol) && (NULL != protocol)) || ((NULL != addr->protocol) && (NULL == protocol))) - { - GNUNET_break(0); - return GNUNET_NO; - } + { + GNUNET_break (0); + return GNUNET_NO; + } else if ((NULL != addr->protocol) && (NULL != protocol)) + { + if (0 != strcmp (addr->protocol, protocol)) { - if (0 != strcmp(addr->protocol, protocol)) - { - GNUNET_break(0); - return GNUNET_NO; - } + GNUNET_break (0); + return GNUNET_NO; } + } if (((NULL == addr->host) && (NULL != host)) || ((NULL != addr->host) && (NULL == host))) - { - GNUNET_break(0); - return GNUNET_NO; - } + { + GNUNET_break (0); + return GNUNET_NO; + } else if ((NULL != addr->host) && (NULL != host)) + { + if (0 != strcmp (addr->host, host)) { - if (0 != strcmp(addr->host, host)) - { - GNUNET_break(0); - return GNUNET_NO; - } + GNUNET_break (0); + return GNUNET_NO; } + } if (((NULL == addr->path) && (NULL != path)) || ((NULL != addr->path) && (NULL == path))) - { - GNUNET_break(0); - return GNUNET_NO; - } + { + GNUNET_break (0); + return GNUNET_NO; + } else if ((NULL != addr->path) && (NULL != path)) + { + if (0 != strcmp (addr->path, path)) { - if (0 != strcmp(addr->path, path)) - { - GNUNET_break(0); - return GNUNET_NO; - } + GNUNET_break (0); + return GNUNET_NO; } + } if ((addr->port != port)) - { - GNUNET_break(0); - return GNUNET_NO; - } + { + GNUNET_break (0); + return GNUNET_NO; + } return GNUNET_OK; } static int -check_pass(const char *src, - const char *protocol, - const char *host, - int port, - const char *path) +check_pass (const char *src, + const char *protocol, + const char *host, + int port, + const char *path) { struct SplittedHTTPAddress *spa; - spa = http_split_address(src); + spa = http_split_address (src); if (NULL == spa) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - if (GNUNET_OK != check(spa, protocol, host, port, path)) - { - clean(spa); - GNUNET_break(0); - return GNUNET_SYSERR; - } - clean(spa); + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (GNUNET_OK != check (spa, protocol, host, port, path)) + { + clean (spa); + GNUNET_break (0); + return GNUNET_SYSERR; + } + clean (spa); return GNUNET_OK; } static int -check_fail(const char *src) +check_fail (const char *src) { - struct SplittedHTTPAddress * spa; + struct SplittedHTTPAddress *spa; - spa = http_split_address(src); + spa = http_split_address (src); if (NULL != spa) - { - GNUNET_break(0); - clean(spa); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + clean (spa); + return GNUNET_SYSERR; + } return GNUNET_OK; } static void -test_pass_hostname() +test_pass_hostname () { - check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, ""); - check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/"); - check_pass("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, "/path"); - check_pass("http://test.local/path/", "http", "test.local", HTTP_DEFAULT_PORT, "/path/"); - check_pass("http://test.local/path/more", "http", "test.local", HTTP_DEFAULT_PORT, "/path/more"); - check_pass("http://test.local:81", "http", "test.local", 81, ""); - check_pass("http://test.local:81/", "http", "test.local", 81, "/"); - check_pass("http://test.local:81/path", "http", "test.local", 81, "/path"); - check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/"); - check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more"); + check_pass ("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, ""); + check_pass ("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, + "/"); + check_pass ("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, + "/path"); + check_pass ("http://test.local/path/", "http", "test.local", + HTTP_DEFAULT_PORT, "/path/"); + check_pass ("http://test.local/path/more", "http", "test.local", + HTTP_DEFAULT_PORT, "/path/more"); + check_pass ("http://test.local:81", "http", "test.local", 81, ""); + check_pass ("http://test.local:81/", "http", "test.local", 81, "/"); + check_pass ("http://test.local:81/path", "http", "test.local", 81, "/path"); + check_pass ("http://test.local:81/path/", "http", "test.local", 81, "/path/"); + check_pass ("http://test.local:81/path/more", "http", "test.local", 81, + "/path/more"); } static void -test_pass_ipv4() +test_pass_ipv4 () { - check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""); - check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/"); - check_pass("http://127.0.0.1/path", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path"); - check_pass("http://127.0.0.1/path/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path/"); - check_pass("http://127.0.0.1:81", "http", "127.0.0.1", 81, ""); - check_pass("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/"); - check_pass("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path"); - check_pass("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/"); - check_pass("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, "/path/more"); + check_pass ("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""); + check_pass ("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/"); + check_pass ("http://127.0.0.1/path", "http", "127.0.0.1", HTTP_DEFAULT_PORT, + "/path"); + check_pass ("http://127.0.0.1/path/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, + "/path/"); + check_pass ("http://127.0.0.1:81", "http", "127.0.0.1", 81, ""); + check_pass ("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/"); + check_pass ("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path"); + check_pass ("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/"); + check_pass ("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, + "/path/more"); } static void -test_fail_ipv6() +test_fail_ipv6 () { - check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); - check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/"); - check_pass("http://[::1]/path", "http", "[::1]", HTTP_DEFAULT_PORT, "/path"); - check_pass("http://[::1]/path/", "http", "[::1]", HTTP_DEFAULT_PORT, "/path/"); - check_pass("http://[::1]:81", "http", "[::1]", 81, ""); - check_pass("http://[::1]:81/", "http", "[::1]", 81, "/"); - check_pass("http://[::1]:81/path", "http", "[::1]", 81, "/path"); - check_pass("http://[::1]:81/path/", "http", "[::1]", 81, "/path/"); - check_pass("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more"); + check_pass ("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); + check_pass ("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/"); + check_pass ("http://[::1]/path", "http", "[::1]", HTTP_DEFAULT_PORT, "/path"); + check_pass ("http://[::1]/path/", "http", "[::1]", HTTP_DEFAULT_PORT, + "/path/"); + check_pass ("http://[::1]:81", "http", "[::1]", 81, ""); + check_pass ("http://[::1]:81/", "http", "[::1]", 81, "/"); + check_pass ("http://[::1]:81/path", "http", "[::1]", 81, "/path"); + check_pass ("http://[::1]:81/path/", "http", "[::1]", 81, "/path/"); + check_pass ("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more"); } static void -test_fail() +test_fail () { - if (GNUNET_SYSERR == check_fail("")) - GNUNET_break(0); - if (GNUNET_SYSERR == check_fail("http")) - GNUNET_break(0); - if (GNUNET_SYSERR == check_fail("://")) - GNUNET_break(0); - if (GNUNET_SYSERR == check_fail("http://")) - GNUNET_break(0); - if (GNUNET_SYSERR == check_fail("//localhost")) - GNUNET_break(0); - if (GNUNET_SYSERR == check_fail("//:80")) - GNUNET_break(0); - if (GNUNET_SYSERR == check_fail("//:80/")) - GNUNET_break(0); - if (GNUNET_SYSERR == check_fail("//:80:")) - GNUNET_break(0); - if (GNUNET_SYSERR == check_fail("http://localhost:a/")) - GNUNET_break(0); - if (GNUNET_SYSERR == check_fail("http://127.0.0.1:a/")) - GNUNET_break(0); + if (GNUNET_SYSERR == check_fail ("")) + GNUNET_break (0); + if (GNUNET_SYSERR == check_fail ("http")) + GNUNET_break (0); + if (GNUNET_SYSERR == check_fail ("://")) + GNUNET_break (0); + if (GNUNET_SYSERR == check_fail ("http://")) + GNUNET_break (0); + if (GNUNET_SYSERR == check_fail ("//localhost")) + GNUNET_break (0); + if (GNUNET_SYSERR == check_fail ("//:80")) + GNUNET_break (0); + if (GNUNET_SYSERR == check_fail ("//:80/")) + GNUNET_break (0); + if (GNUNET_SYSERR == check_fail ("//:80:")) + GNUNET_break (0); + if (GNUNET_SYSERR == check_fail ("http://localhost:a/")) + GNUNET_break (0); + if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/")) + GNUNET_break (0); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { int ret = 0; - struct SplittedHTTPAddress * spa; + struct SplittedHTTPAddress *spa; - GNUNET_log_setup("test", "DEBUG", NULL); - spa = http_split_address(""); + GNUNET_log_setup ("test", "DEBUG", NULL); + spa = http_split_address (""); if (NULL != spa) - { - clean(spa); - spa = NULL; - GNUNET_break(0); - } + { + clean (spa); + spa = NULL; + GNUNET_break (0); + } - spa = http_split_address("http://"); + spa = http_split_address ("http://"); if (NULL != spa) - { - clean(spa); - GNUNET_break(0); - } + { + clean (spa); + GNUNET_break (0); + } - spa = http_split_address("://"); + spa = http_split_address ("://"); if (NULL != spa) - { - clean(spa); - GNUNET_break(0); - } - - test_pass_hostname(); - test_pass_ipv4(); - test_fail_ipv6(); - test_fail(); + { + clean (spa); + GNUNET_break (0); + } + + test_pass_hostname (); + test_pass_ipv4 (); + test_fail_ipv6 (); + test_fail (); return ret; } diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index 686938afc..ceb4333ac 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c @@ -36,8 +36,8 @@ /** * How long until we give up on transmitting the message? */ -#define WAIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) #define HOSTKEY_FILE "test_plugin_hostkey.ecc" @@ -89,12 +89,12 @@ struct GNUNET_HELPER_Handle *suid_helper; /** * Timeout task */ -static struct GNUNET_SCHEDULER_Task * timeout_endbadly; +static struct GNUNET_SCHEDULER_Task *timeout_endbadly; /** * Timeout task */ -static struct GNUNET_SCHEDULER_Task * timeout_wait; +static struct GNUNET_SCHEDULER_Task *timeout_wait; /** * Library name @@ -120,7 +120,8 @@ unsigned int pretty_printers_running; */ static int ok; -struct AddressWrapper { +struct AddressWrapper +{ struct AddressWrapper *next; struct AddressWrapper *prev; @@ -134,7 +135,7 @@ struct AddressWrapper { static void -end() +end () { struct AddressWrapper *w; int c = 0; @@ -142,153 +143,154 @@ end() ok = 0; if (NULL != timeout_endbadly) - { - GNUNET_SCHEDULER_cancel(timeout_endbadly); - timeout_endbadly = NULL; - } + { + GNUNET_SCHEDULER_cancel (timeout_endbadly); + timeout_endbadly = NULL; + } if (NULL != api) - GNUNET_PLUGIN_unload(libname, api); + GNUNET_PLUGIN_unload (libname, api); while (NULL != head) - { - w = head; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Plugin did not remove address `%s'\n", - w->addrstring); - GNUNET_CONTAINER_DLL_remove(head, tail, w); - c++; - GNUNET_HELLO_address_free(w->address); - GNUNET_free(w->addrstring); - GNUNET_free(w); - } + { + w = head; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Plugin did not remove address `%s'\n", + w->addrstring); + GNUNET_CONTAINER_DLL_remove (head, tail, w); + c++; + GNUNET_HELLO_address_free (w->address); + GNUNET_free (w->addrstring); + GNUNET_free (w); + } if (c > 0) - { - GNUNET_break(0); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses \n", - c); - ok = 1; - } - - GNUNET_free(libname); + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Plugin did not remove %u addresses \n", + c); + ok = 1; + } + + GNUNET_free (libname); libname = NULL; - GNUNET_STATISTICS_destroy(stats, GNUNET_NO); + GNUNET_STATISTICS_destroy (stats, GNUNET_NO); stats = NULL; if (NULL != suid_helper) - { - GNUNET_HELPER_stop(suid_helper, GNUNET_NO); - suid_helper = NULL; - } + { + GNUNET_HELPER_stop (suid_helper, GNUNET_NO); + suid_helper = NULL; + } } static void -end_badly(void *cls) +end_badly (void *cls) { struct AddressWrapper *w; int c = 0; timeout_endbadly = NULL; if (NULL != timeout_wait) - { - GNUNET_SCHEDULER_cancel(timeout_wait); - timeout_wait = NULL; - } + { + GNUNET_SCHEDULER_cancel (timeout_wait); + timeout_wait = NULL; + } if (pretty_printers_running > 0) - { - timeout_endbadly = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &end_badly, &ok); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Have pending calls to pretty_printer ... deferring shutdown\n"); - return; - } + { + timeout_endbadly = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &end_badly, &ok); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Have pending calls to pretty_printer ... deferring shutdown\n"); + return; + } if (NULL != cls) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Test took too long to execute, timeout .... \n"); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Test took too long to execute, timeout .... \n"); + } if (NULL != libname) - { - if (NULL != api) - GNUNET_PLUGIN_unload(libname, api); - GNUNET_free(libname); - libname = NULL; - } + { + if (NULL != api) + GNUNET_PLUGIN_unload (libname, api); + GNUNET_free (libname); + libname = NULL; + } while (NULL != head) - { - w = head; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", - w->addrstring); - GNUNET_CONTAINER_DLL_remove(head, tail, w); - c++; - GNUNET_HELLO_address_free(w->address); - if (NULL != w->test_task) - GNUNET_SCHEDULER_cancel(w->test_task); - GNUNET_free(w->addrstring); - GNUNET_free(w); - } + { + w = head; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", + w->addrstring); + GNUNET_CONTAINER_DLL_remove (head, tail, w); + c++; + GNUNET_HELLO_address_free (w->address); + if (NULL != w->test_task) + GNUNET_SCHEDULER_cancel (w->test_task); + GNUNET_free (w->addrstring); + GNUNET_free (w); + } if (c > 0) - { - GNUNET_break(0); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n", - c); - } + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n", + c); + } if (NULL != stats) - { - GNUNET_STATISTICS_destroy(stats, GNUNET_NO); - stats = NULL; - } + { + GNUNET_STATISTICS_destroy (stats, GNUNET_NO); + stats = NULL; + } if (NULL != suid_helper) - { - GNUNET_HELPER_stop(suid_helper, GNUNET_NO); - suid_helper = NULL; - } + { + GNUNET_HELPER_stop (suid_helper, GNUNET_NO); + suid_helper = NULL; + } ok = 1; } static void -wait_end(void *cls) +wait_end (void *cls) { timeout_wait = NULL; if (0 == addresses_reported) - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Plugin did not report any addresses, could not check address conversion functions\n"); - end(); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Plugin did not report any addresses, could not check address conversion functions\n"); + end (); } static void -end_badly_now() +end_badly_now () { if (NULL != timeout_wait) - { - GNUNET_SCHEDULER_cancel(timeout_wait); - timeout_wait = NULL; - } + { + GNUNET_SCHEDULER_cancel (timeout_wait); + timeout_wait = NULL; + } if (NULL != timeout_endbadly) - { - GNUNET_SCHEDULER_cancel(timeout_endbadly); - timeout_endbadly = NULL; - } - timeout_endbadly = GNUNET_SCHEDULER_add_now(&end_badly, NULL); + { + GNUNET_SCHEDULER_cancel (timeout_endbadly); + timeout_endbadly = NULL; + } + timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL); } static struct GNUNET_TIME_Relative -env_receive(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session, - const struct GNUNET_MessageHeader *message) +env_receive (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session, + const struct GNUNET_MessageHeader *message) { /* do nothing */ - return GNUNET_TIME_relative_get_zero_(); + return GNUNET_TIME_relative_get_zero_ (); } static int got_reply; @@ -303,28 +305,28 @@ static int got_reply; * @param res result code */ static void -address_pretty_printer_cb(void *cls, const char *address, int res) +address_pretty_printer_cb (void *cls, const char *address, int res) { if (NULL != address) - { - got_reply = GNUNET_YES; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", address); - pretty_printers_running--; - } + { + got_reply = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", address); + pretty_printers_running--; + } else + { + if (GNUNET_NO == got_reply) { - if (GNUNET_NO == got_reply) - { - pretty_printers_running--; - GNUNET_break(0); - end_badly_now(); - } + pretty_printers_running--; + GNUNET_break (0); + end_badly_now (); } + } } static void -test_addr_string(void *cls) +test_addr_string (void *cls) { struct AddressWrapper *w = cls; void *s2a; @@ -332,40 +334,41 @@ test_addr_string(void *cls) w->test_task = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Testing: address_to_string \n"); - w->addrstring = GNUNET_strdup(api->address_to_string(api, - w->address->address, - w->address->address_length)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Testing: address_to_string \n"); + w->addrstring = GNUNET_strdup (api->address_to_string (api, + w->address->address, + w->address-> + address_length)); if (NULL == w->addrstring) - { - GNUNET_break(0); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Plugin cannot convert address to string!\n"); - end_badly_now(); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Plugin added address `%s'\n", - w->addrstring); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Testing address_to_string: OK\n"); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Testing: string_to_address \n"); + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Plugin cannot convert address to string!\n"); + end_badly_now (); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Plugin added address `%s'\n", + w->addrstring); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Testing address_to_string: OK\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Testing: string_to_address \n"); s2a = NULL; s2a_len = 0; if ((GNUNET_OK != - api->string_to_address(api, w->addrstring, - strlen(w->addrstring) + 1, - &s2a, &s2a_len)) || + api->string_to_address (api, w->addrstring, + strlen (w->addrstring) + 1, + &s2a, &s2a_len)) || (NULL == s2a)) - { - GNUNET_break(0); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Plugin cannot convert string to address!\n"); - end_badly_now(); - return; - } + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Plugin cannot convert string to address!\n"); + end_badly_now (); + return; + } /* GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -376,164 +379,166 @@ test_addr_string(void *cls) fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]); */ if (s2a_len != w->address->address_length) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Plugin creates different address length when converting address->string->address: %u != %u\n", - (unsigned int)w->address->address_length, - (unsigned int)s2a_len); - } - else if (0 != memcmp(s2a, w->address->address, s2a_len)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Plugin creates different address length when converting back and forth %i!\n", - memcmp(s2a, + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Plugin creates different address length when converting address->string->address: %u != %u\n", + (unsigned int) w->address->address_length, + (unsigned int) s2a_len); + } + else if (0 != memcmp (s2a, w->address->address, s2a_len)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Plugin creates different address length when converting back and forth %i!\n", + memcmp (s2a, w->address->address, s2a_len)); - } + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Testing string_to_address: OK\n"); - } - GNUNET_free(s2a); + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Testing string_to_address: OK\n"); + } + GNUNET_free (s2a); pretty_printers_running++; - api->address_pretty_printer(api->cls, - w->address->transport_name, - w->address->address, - w->address->address_length, - GNUNET_YES, - GNUNET_TIME_UNIT_MINUTES, - &address_pretty_printer_cb, w); + api->address_pretty_printer (api->cls, + w->address->transport_name, + w->address->address, + w->address->address_length, + GNUNET_YES, + GNUNET_TIME_UNIT_MINUTES, + &address_pretty_printer_cb, w); if (GNUNET_OK != - api->check_address(api->cls, - w->address->address, - w->address->address_length)) - { - GNUNET_break(0); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Plugin refuses added address!\n"); - end_badly_now(); - return; - } + api->check_address (api->cls, + w->address->address, + w->address->address_length)) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Plugin refuses added address!\n"); + end_badly_now (); + return; + } if (NULL != timeout_wait) - { - GNUNET_SCHEDULER_cancel(timeout_wait); - timeout_wait = NULL; - } - timeout_wait = GNUNET_SCHEDULER_add_delayed(WAIT, &wait_end, NULL); + { + GNUNET_SCHEDULER_cancel (timeout_wait); + timeout_wait = NULL; + } + timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); } static void -env_notify_address(void *cls, - int add_remove, - const struct GNUNET_HELLO_Address *address) +env_notify_address (void *cls, + int add_remove, + const struct GNUNET_HELLO_Address *address) { struct AddressWrapper *w; struct AddressWrapper *wtmp; if (GNUNET_YES == add_remove) - { - addresses_reported++; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Adding address of length %u\n", - (unsigned int)address->address_length); - - for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) - { - if ((address->address_length == wtmp->address->address_length) && - (0 == memcmp(address->address, wtmp->address->address, address->address_length))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Duplicate address notification .... \n"); - return; - } - } - - w = GNUNET_new(struct AddressWrapper); - w->address = GNUNET_HELLO_address_copy(address); - GNUNET_CONTAINER_DLL_insert(head, tail, w); - got_reply = GNUNET_NO; - w->test_task = GNUNET_SCHEDULER_add_now(&test_addr_string, - w); - return; - } + { + addresses_reported++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Adding address of length %u\n", + (unsigned int) address->address_length); + + for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) + { + if ((address->address_length == wtmp->address->address_length) && + (0 == memcmp (address->address, wtmp->address->address, + address->address_length))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Duplicate address notification .... \n"); + return; + } + } + + w = GNUNET_new (struct AddressWrapper); + w->address = GNUNET_HELLO_address_copy (address); + GNUNET_CONTAINER_DLL_insert (head, tail, w); + got_reply = GNUNET_NO; + w->test_task = GNUNET_SCHEDULER_add_now (&test_addr_string, + w); + return; + } if (GNUNET_NO == add_remove) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Removing address of length %u\n", - (unsigned int)address->address_length); - w = head; - while (NULL != w) - { - if ((address->address_length == w->address->address_length) && - (0 == memcmp(w->address->address, address->address, address->address_length))) - { - break; - } - w = w->next; - } - - if (w == NULL) - { - GNUNET_break(0); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Plugin removes address never added!\n"); - end_badly_now(); - return; - } - - GNUNET_CONTAINER_DLL_remove(head, tail, w); - GNUNET_HELLO_address_free(w->address); - GNUNET_free(w->addrstring); - GNUNET_free(w); + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Removing address of length %u\n", + (unsigned int) address->address_length); + w = head; + while (NULL != w) + { + if ((address->address_length == w->address->address_length) && + (0 == memcmp (w->address->address, address->address, + address->address_length))) + { + break; + } + w = w->next; + } + + if (w == NULL) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Plugin removes address never added!\n"); + end_badly_now (); return; } - GNUNET_break(0); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Invalid operation: %u\n", - add_remove); - end_badly_now(); + + GNUNET_CONTAINER_DLL_remove (head, tail, w); + GNUNET_HELLO_address_free (w->address); + GNUNET_free (w->addrstring); + GNUNET_free (w); + return; + } + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Invalid operation: %u\n", + add_remove); + end_badly_now (); } static enum GNUNET_NetworkType -env_get_address_type(void *cls, - const struct sockaddr *addr, - size_t addrlen) +env_get_address_type (void *cls, + const struct sockaddr *addr, + size_t addrlen) { return GNUNET_NT_LOOPBACK; } static const struct GNUNET_MessageHeader * -env_get_our_hello() +env_get_our_hello () { - return (const struct GNUNET_MessageHeader *)hello; + return (const struct GNUNET_MessageHeader *) hello; } static void -env_session_end(void *cls, - const struct GNUNET_HELLO_Address *address, - struct GNUNET_ATS_Session *session) +env_session_end (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_ATS_Session *session) { } static void -env_update_distance(void *cls, - const struct GNUNET_HELLO_Address *address, - uint32_t distance) +env_update_distance (void *cls, + const struct GNUNET_HELLO_Address *address, + uint32_t distance) { } static void -setup_plugin_environment() +setup_plugin_environment () { env.cfg = cfg; env.cls = &env; @@ -550,8 +555,8 @@ setup_plugin_environment() static int -handle_helper_message(void *cls, - const struct GNUNET_MessageHeader *hdr) +handle_helper_message (void *cls, + const struct GNUNET_MessageHeader *hdr) { return GNUNET_OK; } @@ -564,184 +569,185 @@ handle_helper_message(void *cls, * @param c configuration to use */ static void -run(void *cls, - char * const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { - char * const *argv = cls; + char *const *argv = cls; unsigned long long tneigh; char *keyfile; char *plugin; char *sep; - timeout_endbadly = GNUNET_SCHEDULER_add_delayed(TIMEOUT, - &end_badly, - &ok); + timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &end_badly, + &ok); cfg = c; /* parse configuration */ if ((GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number(c, - "TRANSPORT", - "NEIGHBOUR_LIMIT", - &tneigh)) || + GNUNET_CONFIGURATION_get_value_number (c, + "TRANSPORT", + "NEIGHBOUR_LIMIT", + &tneigh)) || (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename(c, - "PEER", - "PRIVATE_KEY", - &keyfile))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Transport service is lacking key configuration settings. Exiting.\n"); - return; - } - - if (NULL == (stats = GNUNET_STATISTICS_create("transport", - cfg))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Could not create statistics. Exiting.\n"); - GNUNET_free(keyfile); - end_badly_now(); - return; - } - - if (GNUNET_OK != GNUNET_DISK_file_test(HOSTKEY_FILE)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Hostkey `%s' missing. Exiting.\n", - HOSTKEY_FILE); - GNUNET_free(keyfile); - end_badly_now(); - return; - } + GNUNET_CONFIGURATION_get_value_filename (c, + "PEER", + "PRIVATE_KEY", + &keyfile))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Transport service is lacking key configuration settings. Exiting.\n"); + return; + } + + if (NULL == (stats = GNUNET_STATISTICS_create ("transport", + cfg))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not create statistics. Exiting.\n"); + GNUNET_free (keyfile); + end_badly_now (); + return; + } + + if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Hostkey `%s' missing. Exiting.\n", + HOSTKEY_FILE); + GNUNET_free (keyfile); + end_badly_now (); + return; + } if (GNUNET_OK != - GNUNET_DISK_directory_create_for_file(keyfile)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Could not create a directory for hostkey `%s'. Exiting.\n", - keyfile); - GNUNET_free(keyfile); - end_badly_now(); - return; - } + GNUNET_DISK_directory_create_for_file (keyfile)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not create a directory for hostkey `%s'. Exiting.\n", + keyfile); + GNUNET_free (keyfile); + end_badly_now (); + return; + } if (GNUNET_OK != - GNUNET_DISK_file_copy(HOSTKEY_FILE, - keyfile)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", - HOSTKEY_FILE, - keyfile); - GNUNET_free(keyfile); - end_badly_now(); - return; - } - - max_connect_per_transport = (uint32_t)tneigh; - my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); - GNUNET_free(keyfile); + GNUNET_DISK_file_copy (HOSTKEY_FILE, + keyfile)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", + HOSTKEY_FILE, + keyfile); + GNUNET_free (keyfile); + end_badly_now (); + return; + } + + max_connect_per_transport = (uint32_t) tneigh; + my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); + GNUNET_free (keyfile); if (NULL == my_private_key) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Could not access hostkey. Exiting.\n"); - end_badly_now(); - return; - } - GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not access hostkey. Exiting.\n"); + end_badly_now (); + return; + } + GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); - hello = GNUNET_HELLO_create(&my_identity.public_key, NULL, NULL, GNUNET_NO); + hello = GNUNET_HELLO_create (&my_identity.public_key, NULL, NULL, GNUNET_NO); /* load plugins... */ - setup_plugin_environment(); + setup_plugin_environment (); - GNUNET_assert(strlen(argv[0]) > strlen("test_plugin_")); - plugin = strstr(argv[0], "test_plugin_"); - sep = strrchr(argv[0], '.'); + GNUNET_assert (strlen (argv[0]) > strlen ("test_plugin_")); + plugin = strstr (argv[0], "test_plugin_"); + sep = strrchr (argv[0], '.'); if (NULL == plugin) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); - end_badly_now(); - return; - } - plugin += strlen("test_plugin_"); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); + end_badly_now (); + return; + } + plugin += strlen ("test_plugin_"); if (NULL != sep) sep[0] = '\0'; /* Hack for WLAN: start a second helper */ - if (0 == strcmp(plugin, "wlan")) - { - char * helper_argv[3]; - helper_argv[0] = (char *)"gnunet-helper-transport-wlan-dummy"; - helper_argv[1] = (char *)"2"; - helper_argv[2] = NULL; - suid_helper = GNUNET_HELPER_start(GNUNET_NO, - "gnunet-helper-transport-wlan-dummy", helper_argv, - &handle_helper_message, NULL, NULL); - } + if (0 == strcmp (plugin, "wlan")) + { + char *helper_argv[3]; + helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy"; + helper_argv[1] = (char *) "2"; + helper_argv[2] = NULL; + suid_helper = GNUNET_HELPER_start (GNUNET_NO, + "gnunet-helper-transport-wlan-dummy", + helper_argv, + &handle_helper_message, NULL, NULL); + } /* Loading plugin */ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); - GNUNET_asprintf(&libname, "libgnunet_plugin_transport_%s", plugin); - api = GNUNET_PLUGIN_load(libname, &env); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); + GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin); + api = GNUNET_PLUGIN_load (libname, &env); if (NULL == api) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to load transport plugin for %s\n", plugin); - end_badly_now(); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to load transport plugin for %s\n", plugin); + end_badly_now (); + return; + } - timeout_wait = GNUNET_SCHEDULER_add_delayed(WAIT, &wait_end, NULL); + timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); /* Check if all functions are implemented */ if (NULL == api->address_pretty_printer) - { - GNUNET_break(0); - end_badly_now(); - return; - } + { + GNUNET_break (0); + end_badly_now (); + return; + } if (NULL == api->address_to_string) - { - GNUNET_break(0); - end_badly_now(); - return; - } - GNUNET_assert(NULL != api->check_address); + { + GNUNET_break (0); + end_badly_now (); + return; + } + GNUNET_assert (NULL != api->check_address); if (NULL == api->check_address) - { - GNUNET_break(0); - end_badly_now(); - return; - } - GNUNET_assert(NULL != api->disconnect_peer); + { + GNUNET_break (0); + end_badly_now (); + return; + } + GNUNET_assert (NULL != api->disconnect_peer); if (NULL == api->disconnect_peer) - { - GNUNET_break(0); - end_badly_now(); - return; - } - GNUNET_assert(NULL != api->get_session); + { + GNUNET_break (0); + end_badly_now (); + return; + } + GNUNET_assert (NULL != api->get_session); if (NULL == api->get_session) - { - GNUNET_break(0); - end_badly_now(); - return; - } + { + GNUNET_break (0); + end_badly_now (); + return; + } if (NULL == api->address_pretty_printer) - { - GNUNET_break(0); - end_badly_now(); - return; - } + { + GNUNET_break (0); + end_badly_now (); + return; + } if (NULL == api->string_to_address) - { - GNUNET_break(0); - end_badly_now(); - return; - } + { + GNUNET_break (0); + end_badly_now (); + return; + } } @@ -753,32 +759,32 @@ run(void *cls, * @return 0 ok, 1 on error */ int -main(int argc, - char * const *argv) +main (int argc, + char *const *argv) { static struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; int ret; - char * const argv_prog[] = { + char *const argv_prog[] = { "test_plugin_transport", "-c", "test_plugin_transport_data.conf", NULL }; - GNUNET_log_setup("test-plugin-transport", - "WARNING", - NULL); - GNUNET_DISK_purge_cfg_dir("test_plugin_transport_data.conf", - "GNUNET_TEST_HOME"); + GNUNET_log_setup ("test-plugin-transport", + "WARNING", + NULL); + GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf", + "GNUNET_TEST_HOME"); ok = 1; /* set to fail */ ret = (GNUNET_OK - == GNUNET_PROGRAM_run(3, argv_prog, "test-plugin-transport", - "testcase", options, &run, (void *)argv)) ? ok : 1; - GNUNET_DISK_purge_cfg_dir("test_plugin_transport_data.conf", - "GNUNET_TEST_HOME"); + == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport", + "testcase", options, &run, (void *) argv)) ? ok : 1; + GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf", + "GNUNET_TEST_HOME"); return ret; } diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 092935944..c3c46db37 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c @@ -32,9 +32,9 @@ /** * Testcase timeout */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 480) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 480) -#define DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 80) +#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 80) static struct GNUNET_SCHEDULER_Task *measure_task; @@ -61,61 +61,61 @@ static struct GNUNET_TIME_Absolute start_time; static void -report() +report () { unsigned long long delta; unsigned long long datarate; - delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us; + delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; if (0 == delta) delta = 1; datarate = (total_bytes_recv * 1000 * 1000) / delta; - fprintf(stderr, - "Throughput was %llu b/s\n", - datarate); + fprintf (stderr, + "Throughput was %llu b/s\n", + datarate); ccc->global_ret = GNUNET_OK; if (datarate > 1.5 * quota_in[1]) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Datarate of %llu b/s significantly higher than allowed inbound quota of %llu b/s\n", - datarate, - quota_in[1]); - ccc->global_ret = GNUNET_SYSERR; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Datarate of %llu b/s significantly higher than allowed inbound quota of %llu b/s\n", + datarate, + quota_in[1]); + ccc->global_ret = GNUNET_SYSERR; + } if (datarate > 1.5 * quota_out[0]) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Datarate of %llu b/s significantly higher than allowed outbound quota of %llu b/s\n", - datarate, - quota_out[0]); - ccc->global_ret = GNUNET_SYSERR; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Datarate of %llu b/s significantly higher than allowed outbound quota of %llu b/s\n", + datarate, + quota_out[0]); + ccc->global_ret = GNUNET_SYSERR; + } if (GNUNET_OK == ccc->global_ret) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", - datarate, - quota_out[0], - quota_in[1]); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", + datarate, + quota_out[0], + quota_in[1]); + } } static void -custom_shutdown(void *cls) +custom_shutdown (void *cls) { if (NULL != measure_task) - { - GNUNET_SCHEDULER_cancel(measure_task); - measure_task = NULL; - } - report(); + { + GNUNET_SCHEDULER_cancel (measure_task); + measure_task = NULL; + } + report (); } static size_t -get_size(unsigned int iter) +get_size (unsigned int iter) { size_t ret; @@ -126,52 +126,52 @@ get_size(unsigned int iter) static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) { - if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type)) + if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type)) return; - total_bytes_recv += ntohs(hdr->header.size); + total_bytes_recv += ntohs (hdr->header.size); { - char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", - receiver->no, - ps, - ntohl(hdr->num), - ntohs(hdr->header.size), - GNUNET_i2s(sender)); - GNUNET_free(ps); + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", + receiver->no, + ps, + ntohl (hdr->num), + ntohs (hdr->header.size), + GNUNET_i2s (sender)); + GNUNET_free (ps); } } static void -measure(void *cls) +measure (void *cls) { static int counter; measure_task = NULL; counter++; if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) - { - fprintf(stderr, "%s", ".\n"); - GNUNET_SCHEDULER_shutdown(); - return; - } - fprintf(stderr, "%s", "."); - measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &measure, - NULL); + { + fprintf (stderr, "%s", ".\n"); + GNUNET_SCHEDULER_shutdown (); + return; + } + fprintf (stderr, "%s", "."); + measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &measure, + NULL); } static void -start_task(void *cls) +start_task (void *cls) { static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { .num_messages = TOTAL_MSGS, @@ -179,71 +179,71 @@ start_task(void *cls) }; sc.ccc = ccc; - measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &measure, - NULL); - start_time = GNUNET_TIME_absolute_get(); - GNUNET_SCHEDULER_add_now(&GNUNET_TRANSPORT_TESTING_simple_send, - &sc); + measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &measure, + NULL); + start_time = GNUNET_TIME_absolute_get (); + GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send, + &sc); } static char * -generate_config(const char *cfg_file, - unsigned long long quota_in, - unsigned long long quota_out) +generate_config (const char *cfg_file, + unsigned long long quota_in, + unsigned long long quota_out) { char *in_name; char *out_name; char *fname = NULL; - struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create(); - - GNUNET_assert(GNUNET_OK == - GNUNET_CONFIGURATION_load(cfg, - cfg_file)); - GNUNET_asprintf(&fname, - "q_in_%llu_q_out_%llu_%s", - quota_in, - quota_out, - cfg_file); - GNUNET_CONFIGURATION_set_value_string(cfg, - "PATHS", - "DEFAULTCONFIG", - fname); + struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); + + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_load (cfg, + cfg_file)); + GNUNET_asprintf (&fname, + "q_in_%llu_q_out_%llu_%s", + quota_in, + quota_out, + cfg_file); + GNUNET_CONFIGURATION_set_value_string (cfg, + "PATHS", + "DEFAULTCONFIG", + fname); for (int c = 0; c < GNUNET_NT_COUNT; c++) - { - GNUNET_asprintf(&in_name, - "%s_QUOTA_IN", - GNUNET_NT_to_string(c)); - GNUNET_asprintf(&out_name, - "%s_QUOTA_OUT", - GNUNET_NT_to_string(c)); - GNUNET_CONFIGURATION_set_value_number(cfg, - "ats", - in_name, - quota_in); - GNUNET_CONFIGURATION_set_value_number(cfg, - "ats", - out_name, - quota_out); - GNUNET_free(in_name); - GNUNET_free(out_name); - } - GNUNET_assert(GNUNET_OK == - GNUNET_CONFIGURATION_write(cfg, - fname)); - GNUNET_CONFIGURATION_destroy(cfg); + { + GNUNET_asprintf (&in_name, + "%s_QUOTA_IN", + GNUNET_NT_to_string (c)); + GNUNET_asprintf (&out_name, + "%s_QUOTA_OUT", + GNUNET_NT_to_string (c)); + GNUNET_CONFIGURATION_set_value_number (cfg, + "ats", + in_name, + quota_in); + GNUNET_CONFIGURATION_set_value_number (cfg, + "ats", + out_name, + quota_out); + GNUNET_free (in_name); + GNUNET_free (out_name); + } + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_write (cfg, + fname)); + GNUNET_CONFIGURATION_destroy (cfg); return fname; } static int -check(void *cls, - struct GNUNET_TRANSPORT_TESTING_Handle *tth_, - const char *test_plugin_, - const char *test_name_, - unsigned int num_peers, - char *cfg_files[]) +check (void *cls, + struct GNUNET_TRANSPORT_TESTING_Handle *tth_, + const char *test_plugin_, + const char *test_name_, + unsigned int num_peers, + char *cfg_files[]) { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { .connect_continuation = &start_task, @@ -257,63 +257,63 @@ check(void *cls, ccc = &my_ccc; - if (NULL != strstr(test_name_, - "asymmetric")) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", - quota_in[1], - quota_out[1]); - quota_out[0] = 1024 * 1024 * 1024; - quota_in[0] = 1024 * 1024 * 1024; - } + if (NULL != strstr (test_name_, + "asymmetric")) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", + quota_in[1], + quota_out[1]); + quota_out[0] = 1024 * 1024 * 1024; + quota_in[0] = 1024 * 1024 * 1024; + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Running symmetric test with (in/out) %llu/%llu b/s \n", - quota_in[1], - quota_out[1]); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Running symmetric test with (in/out) %llu/%llu b/s \n", + quota_in[1], + quota_out[1]); + } for (unsigned int i = 0; i < 2; i++) - { - gen_cfgs[i] = generate_config(cfg_files[i], - quota_in[i], - quota_out[i]); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Generated config file `%s'\n", - gen_cfgs[i]); - } + { + gen_cfgs[i] = generate_config (cfg_files[i], + quota_in[i], + quota_out[i]); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Generated config file `%s'\n", + gen_cfgs[i]); + } - return GNUNET_TRANSPORT_TESTING_connect_check(&my_ccc, - tth_, - test_plugin_, - test_name_, - num_peers, - gen_cfgs); + return GNUNET_TRANSPORT_TESTING_connect_check (&my_ccc, + tth_, + test_plugin_, + test_name_, + num_peers, + gen_cfgs); } int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &check, - NULL)) - { - GNUNET_break(0); - return 1; - } + GNUNET_TRANSPORT_TESTING_main (2, + &check, + NULL)) + { + GNUNET_break (0); + return 1; + } for (unsigned int i = 0; i < 2; i++) + { + if ((NULL != gen_cfgs[i]) && + (GNUNET_YES == GNUNET_DISK_file_test (gen_cfgs[i]))) { - if ((NULL != gen_cfgs[i]) && - (GNUNET_YES == GNUNET_DISK_file_test(gen_cfgs[i]))) - { - GNUNET_DISK_directory_remove(gen_cfgs[i]); - GNUNET_free(gen_cfgs[i]); - } + GNUNET_DISK_directory_remove (gen_cfgs[i]); + GNUNET_free (gen_cfgs[i]); } + } return 0; } diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index ffb6baefe..b030aa1b8 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c @@ -51,7 +51,7 @@ /** * Testcase timeout (set aggressively as we know this test doesn't work right now) */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; @@ -62,7 +62,8 @@ static struct GNUNET_SCHEDULER_Task *measure_task; /** * Statistics we track per peer. */ -struct PeerStats { +struct PeerStats +{ struct GNUNET_STATISTICS_Handle *stat; unsigned int addresses_avail; @@ -83,16 +84,16 @@ static unsigned long long bytes_recv_after_switch; static int -stat_start_attempt_cb(void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) +stat_start_attempt_cb (void *cls, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) { struct PeerStats *stat = cls; stat->switch_attempts++; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Switch attempted (%p)", stat); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch attempted (%p)", stat); bytes_recv_after_switch = 0; bytes_sent_after_switch = 0; @@ -101,26 +102,26 @@ stat_start_attempt_cb(void *cls, static int -stat_success_attempt_cb(void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) +stat_success_attempt_cb (void *cls, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) { struct PeerStats *stat = cls; stat->switch_success++; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Switch succeeded (%p)", stat); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch succeeded (%p)", stat); return GNUNET_OK; } static int -stat_fail_attempt_cb(void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) +stat_fail_attempt_cb (void *cls, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) { struct PeerStats *stat = cls; @@ -128,17 +129,17 @@ stat_fail_attempt_cb(void *cls, return GNUNET_OK; stat->switch_fail++; - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Switch failed (%p)", stat); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Switch failed (%p)", stat); return GNUNET_OK; } static int -stat_addresses_available(void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) +stat_addresses_available (void *cls, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) { struct PeerStats *stat = cls; @@ -150,7 +151,8 @@ stat_addresses_available(void *cls, /** * List of statistics entries we care about. */ -static struct WatchEntry { +static struct WatchEntry +{ /** * Name of the statistic we watch. */ @@ -164,112 +166,112 @@ static struct WatchEntry { { { "# Attempts to switch addresses", &stat_start_attempt_cb }, { "# Successful attempts to switch addresses", &stat_success_attempt_cb }, { "# Failed attempts to switch addresses (failed to send CONNECT CONT)", - &stat_fail_attempt_cb }, + &stat_fail_attempt_cb }, { "# Failed attempts to switch addresses (failed to send CONNECT)", - &stat_fail_attempt_cb }, + &stat_fail_attempt_cb }, { "# Failed attempts to switch addresses (no response)", - &stat_fail_attempt_cb }, + &stat_fail_attempt_cb }, { "# transport addresses", &stat_addresses_available }, { NULL, NULL } }; static void -custom_shutdown(void *cls) +custom_shutdown (void *cls) { int result; if (NULL != measure_task) - { - GNUNET_SCHEDULER_cancel(measure_task); - measure_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (measure_task); + measure_task = NULL; + } if (0 == stats[0].switch_attempts + stats[1].switch_attempts) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Test did not work, as peers didn't switch (flawed testcase)!\n"); - ccc->global_ret = 77; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Test did not work, as peers didn't switch (flawed testcase)!\n"); + ccc->global_ret = 77; + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Fail (timeout)! No transmission after switch! Stopping peers\n"); - ccc->global_ret = 77; /* GNUNET_SYSERR; */ - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Fail (timeout)! No transmission after switch! Stopping peers\n"); + ccc->global_ret = 77; /* GNUNET_SYSERR; */ + } /* stop statistics */ for (unsigned int i = 0; i < 2; i++) + { + if (NULL != stats[i].stat) { - if (NULL != stats[i].stat) - { - for (unsigned int j = 0; NULL != watches[j].stat_name; j++) - GNUNET_assert(GNUNET_OK == - GNUNET_STATISTICS_watch_cancel(stats[i].stat, - "transport", - watches[j].stat_name, - watches[j].stat_handler, - &stats[i])); - GNUNET_STATISTICS_destroy(stats[i].stat, GNUNET_NO); - stats[i].stat = NULL; - } + for (unsigned int j = 0; NULL != watches[j].stat_name; j++) + GNUNET_assert (GNUNET_OK == + GNUNET_STATISTICS_watch_cancel (stats[i].stat, + "transport", + watches[j].stat_name, + watches[j].stat_handler, + &stats[i])); + GNUNET_STATISTICS_destroy (stats[i].stat, GNUNET_NO); + stats[i].stat = NULL; } + } result = 0; - fprintf(stderr, "\n"); + fprintf (stderr, "\n"); if (stats[0].switch_attempts > 0) + { + fprintf ( + stderr, + "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", + stats[0].switch_attempts, + stats[0].switch_success, + stats[0].switch_fail); + if (stats[0].switch_success != stats[0].switch_attempts) { - fprintf( - stderr, - "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", - stats[0].switch_attempts, - stats[0].switch_success, - stats[0].switch_fail); - if (stats[0].switch_success != stats[0].switch_attempts) - { - GNUNET_break(0); - result++; - } + GNUNET_break (0); + result++; } + } else if (stats[0].addresses_avail > 1) - { - fprintf(stderr, - "Peer 1 had %u addresses available, but did not try to switch\n", - stats[0].addresses_avail); - } + { + fprintf (stderr, + "Peer 1 had %u addresses available, but did not try to switch\n", + stats[0].addresses_avail); + } if (stats[1].switch_attempts > 0) + { + fprintf ( + stderr, + "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", + stats[1].switch_attempts, + stats[1].switch_success, + stats[1].switch_fail); + if (stats[1].switch_success != stats[1].switch_attempts) { - fprintf( - stderr, - "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", - stats[1].switch_attempts, - stats[1].switch_success, - stats[1].switch_fail); - if (stats[1].switch_success != stats[1].switch_attempts) - { - GNUNET_break(0); - result++; - } + GNUNET_break (0); + result++; } + } else if (stats[1].addresses_avail > 1) - { - fprintf(stderr, - "Peer 2 had %u addresses available, but did not try to switch\n", - stats[1].addresses_avail); - } + { + fprintf (stderr, + "Peer 2 had %u addresses available, but did not try to switch\n", + stats[1].addresses_avail); + } if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && (bytes_sent_after_switch == 0)) - { - fprintf(stderr, "No data sent after switching!\n"); - GNUNET_break(0); - result++; - } + { + fprintf (stderr, "No data sent after switching!\n"); + GNUNET_break (0); + result++; + } if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && (bytes_recv_after_switch == 0)) - { - fprintf(stderr, "No data received after switching!\n"); - GNUNET_break(0); - result++; - } + { + fprintf (stderr, "No data received after switching!\n"); + GNUNET_break (0); + result++; + } #if 0 /* This test is not really expected to pass right now... */ if (0 != result) @@ -279,132 +281,132 @@ custom_shutdown(void *cls) static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) { - if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type)) + if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type)) return; { - char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", - receiver->no, - ps, - (uint32_t)ntohl(hdr->num), - ntohs(hdr->header.size), - GNUNET_i2s(sender)); - GNUNET_free(ps); + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", + receiver->no, + ps, + (uint32_t) ntohl (hdr->num), + ntohs (hdr->header.size), + GNUNET_i2s (sender)); + GNUNET_free (ps); } if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && (stats[0].switch_attempts == stats[0].switch_fail + stats[0].switch_success) && (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success)) + { + bytes_recv_after_switch += ntohs (hdr->header.size); + if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0)) { - bytes_recv_after_switch += ntohs(hdr->header.size); - if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0)) - { - /* A peer switched addresses and sent and received data after the - * switch operations */ - GNUNET_SCHEDULER_shutdown(); - } + /* A peer switched addresses and sent and received data after the + * switch operations */ + GNUNET_SCHEDULER_shutdown (); } + } } static void -notify_send(void *cls) +notify_send (void *cls) { static uint32_t cnt; - GNUNET_assert( + GNUNET_assert ( GNUNET_OK == - GNUNET_TRANSPORT_TESTING_send(ccc->p[1], - ccc->p[0], - GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, - GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, - ++cnt, - ¬ify_send, - NULL)); + GNUNET_TRANSPORT_TESTING_send (ccc->p[1], + ccc->p[0], + GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, + GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, + ++cnt, + ¬ify_send, + NULL)); if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && (stats[0].switch_attempts == stats[0].switch_fail + stats[0].switch_success) && (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success)) - { - bytes_sent_after_switch += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE; - } + { + bytes_sent_after_switch += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE; + } } static void -progress_indicator(void *cls) +progress_indicator (void *cls) { static int counter; measure_task = NULL; counter++; if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter) - { - fprintf(stderr, "%s", ".\n"); - } + { + fprintf (stderr, "%s", ".\n"); + } else - { - fprintf(stderr, "%s", "."); - measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &progress_indicator, - NULL); - } + { + fprintf (stderr, "%s", "."); + measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &progress_indicator, + NULL); + } } static void -connected_cb(void *cls) +connected_cb (void *cls) { for (unsigned int i = 0; i < 2; i++) + { + stats[i].stat = GNUNET_STATISTICS_create ("transport", ccc->p[i]->cfg); + if (NULL == stats[i].stat) { - stats[i].stat = GNUNET_STATISTICS_create("transport", ccc->p[i]->cfg); - if (NULL == stats[i].stat) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Fail! Could not create statistics for peers!\n"); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown(); - return; - } - for (unsigned int j = 0; NULL != watches[j].stat_name; j++) - { - GNUNET_STATISTICS_watch(stats[i].stat, - "transport", - watches[j].stat_name, - watches[j].stat_handler, - &stats[i]); - } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Fail! Could not create statistics for peers!\n"); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; + } + for (unsigned int j = 0; NULL != watches[j].stat_name; j++) + { + GNUNET_STATISTICS_watch (stats[i].stat, + "transport", + watches[j].stat_name, + watches[j].stat_handler, + &stats[i]); } + } /* Show progress */ ccc->global_ret = GNUNET_OK; - measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &progress_indicator, - NULL); + measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &progress_indicator, + NULL); /* Peers are connected, start transmit test messages */ - GNUNET_assert( + GNUNET_assert ( GNUNET_OK == - GNUNET_TRANSPORT_TESTING_send(ccc->p[1], - ccc->p[0], - GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, - GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, - 0, - ¬ify_send, - NULL)); + GNUNET_TRANSPORT_TESTING_send (ccc->p[1], + ccc->p[0], + GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, + GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, + 0, + ¬ify_send, + NULL)); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { .connect_continuation = &connected_cb, @@ -417,9 +419,9 @@ main(int argc, char *argv[]) ccc = &my_ccc; int ret; - ret = GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc); + ret = GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc); if (77 == ret) return 77; if (GNUNET_OK != ret) diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index e7d2e5a7e..950eb2b04 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c @@ -34,42 +34,43 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { { - char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", - receiver->no, - ps, - ntohs(message->header.type), - ntohs(message->header.size), - GNUNET_i2s(sender)); - GNUNET_free(ps); + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", + receiver->no, + ps, + ntohs (message->header.type), + ntohs (message->header.size), + GNUNET_i2s (sender)); + GNUNET_free (ps); } - if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs(message->header.type)) && - (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs(message->header.size))) - { - ccc->global_ret = GNUNET_OK; - GNUNET_SCHEDULER_shutdown(); - } + if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) && + (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs ( + message->header.size))) + { + ccc->global_ret = GNUNET_OK; + GNUNET_SCHEDULER_shutdown (); + } else - { - GNUNET_break(0); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown(); - } + { + GNUNET_break (0); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + } } @@ -81,8 +82,8 @@ notify_receive(void *cls, * in both directions simultaneously? */ static int -test(char *argv[], - int bi_directional) +test (char *argv[], + int bi_directional) { struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { .num_messages = 1 @@ -101,22 +102,22 @@ test(char *argv[], ccc = &my_ccc; sc.ccc = ccc; if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { - if ((0 != test(argv, - GNUNET_NO)) || - (0 != test(argv, - GNUNET_YES))) + if ((0 != test (argv, + GNUNET_NO)) || + (0 != test (argv, + GNUNET_YES))) return 1; return 0; } diff --git a/src/transport/test_transport_api_blacklisting.c b/src/transport/test_transport_api_blacklisting.c index 6cf5b251b..2ba88a863 100644 --- a/src/transport/test_transport_api_blacklisting.c +++ b/src/transport/test_transport_api_blacklisting.c @@ -28,7 +28,7 @@ #include "gnunet_transport_service.h" #include "transport-testing.h" -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; @@ -46,135 +46,136 @@ static struct GNUNET_SCHEDULER_Task *shutdown_task; static void -end(void *cls) +end (void *cls) { shutdown_task = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Stopping\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Stopping\n"); if ((GNUNET_YES == blacklist_request_p1) && (GNUNET_YES == blacklist_request_p2) && (GNUNET_NO == connected)) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peers were never connected, success\n"); - ccc->global_ret = GNUNET_OK; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peers were never connected, success\n"); + ccc->global_ret = GNUNET_OK; + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Peers were not connected, fail\n"); - ccc->global_ret = GNUNET_SYSERR; - } - GNUNET_SCHEDULER_shutdown(); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Peers were not connected, fail\n"); + ccc->global_ret = GNUNET_SYSERR; + } + GNUNET_SCHEDULER_shutdown (); } static void -custom_shutdown(void *cls) +custom_shutdown (void *cls) { if (NULL != shutdown_task) - { - GNUNET_SCHEDULER_cancel(shutdown_task); - shutdown_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (shutdown_task); + shutdown_task = NULL; + } if (NULL != blacklist_p1) - { - GNUNET_TRANSPORT_blacklist_cancel(blacklist_p1); - blacklist_p1 = NULL; - } + { + GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1); + blacklist_p1 = NULL; + } if (NULL != blacklist_p2) - { - GNUNET_TRANSPORT_blacklist_cancel(blacklist_p2); - blacklist_p2 = NULL; - } + { + GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2); + blacklist_p2 = NULL; + } } static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Unexpectedly even received the message despite blacklist\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpectedly even received the message despite blacklist\n"); connected = GNUNET_YES; - GNUNET_SCHEDULER_cancel(shutdown_task); - end(NULL); + GNUNET_SCHEDULER_cancel (shutdown_task); + end (NULL); } static void -notify_connect(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) +notify_connect (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { - GNUNET_TRANSPORT_TESTING_log_connect(cls, - me, - other); - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Peers connected despite blacklist!\n"); + GNUNET_TRANSPORT_TESTING_log_connect (cls, + me, + other); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Peers connected despite blacklist!\n"); connected = GNUNET_YES; /* this test now failed */ - GNUNET_SCHEDULER_cancel(shutdown_task); - end(NULL); + GNUNET_SCHEDULER_cancel (shutdown_task); + end (NULL); } static int -blacklist_cb(void *cls, - const struct GNUNET_PeerIdentity *pid) +blacklist_cb (void *cls, + const struct GNUNET_PeerIdentity *pid) { struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; int res = GNUNET_SYSERR; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u: Blacklist request for peer `%s'\n", - p->no, - GNUNET_i2s(pid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u: Blacklist request for peer `%s'\n", + p->no, + GNUNET_i2s (pid)); if (p == ccc->p[0]) - { - blacklist_request_p1 = GNUNET_YES; - res = GNUNET_OK; - } + { + blacklist_request_p1 = GNUNET_YES; + res = GNUNET_OK; + } if (p == ccc->p[1]) - { - blacklist_request_p2 = GNUNET_YES; - res = GNUNET_SYSERR; - } + { + blacklist_request_p2 = GNUNET_YES; + res = GNUNET_SYSERR; + } if ((GNUNET_YES == blacklist_request_p2) && (GNUNET_YES == blacklist_request_p1) && (NULL == shutdown_task)) - { - shutdown_task - = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3), - &end, - NULL); - } + { + shutdown_task + = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( + GNUNET_TIME_UNIT_SECONDS, 3), + &end, + NULL); + } return res; } static void -start_blacklist(void *cls) +start_blacklist (void *cls) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Starting blacklists\n"); - blacklist_p1 = GNUNET_TRANSPORT_blacklist(ccc->p[0]->cfg, - &blacklist_cb, - ccc->p[0]); - GNUNET_assert(NULL != blacklist_p1); - blacklist_p2 = GNUNET_TRANSPORT_blacklist(ccc->p[1]->cfg, - &blacklist_cb, - ccc->p[1]); - GNUNET_assert(NULL != blacklist_p2); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting blacklists\n"); + blacklist_p1 = GNUNET_TRANSPORT_blacklist (ccc->p[0]->cfg, + &blacklist_cb, + ccc->p[0]); + GNUNET_assert (NULL != blacklist_p1); + blacklist_p2 = GNUNET_TRANSPORT_blacklist (ccc->p[1]->cfg, + &blacklist_cb, + ccc->p[1]); + GNUNET_assert (NULL != blacklist_p2); } int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { .num_messages = 1 @@ -194,9 +195,9 @@ main(int argc, ccc = &my_ccc; if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c index 47e52b67e..76e0325af 100644 --- a/src/transport/test_transport_api_disconnect.c +++ b/src/transport/test_transport_api_disconnect.c @@ -32,7 +32,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; @@ -41,69 +41,70 @@ static int shutdown_; static void -notify_disconnect(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) +notify_disconnect (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { if (me != ccc->p[0]) return; - GNUNET_TRANSPORT_TESTING_log_disconnect(cls, - me, - other); + GNUNET_TRANSPORT_TESTING_log_disconnect (cls, + me, + other); if (GNUNET_YES == shutdown_) - { - ccc->global_ret = GNUNET_OK; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Test good, shutting down...\n"); - GNUNET_SCHEDULER_shutdown(); - } + { + ccc->global_ret = GNUNET_OK; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Test good, shutting down...\n"); + GNUNET_SCHEDULER_shutdown (); + } } static void -stop_peer(void *cls) +stop_peer (void *cls) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Shutting down peer %u (`%s')\n", - ccc->p[1]->no, - GNUNET_i2s(&ccc->p[1]->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shutting down peer %u (`%s')\n", + ccc->p[1]->no, + GNUNET_i2s (&ccc->p[1]->id)); shutdown_ = GNUNET_YES; - GNUNET_TRANSPORT_TESTING_stop_peer(ccc->p[1]); + GNUNET_TRANSPORT_TESTING_stop_peer (ccc->p[1]); ccc->p[1] = NULL; } static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { { - char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", - receiver->no, - ps, - ntohs(message->header.type), - ntohs(message->header.size), - GNUNET_i2s(sender)); - GNUNET_free(ps); + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", + receiver->no, + ps, + ntohs (message->header.type), + ntohs (message->header.size), + GNUNET_i2s (sender)); + GNUNET_free (ps); + } + if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) && + (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs ( + message->header.size))) + { + GNUNET_SCHEDULER_add_now (&stop_peer, + NULL); + return; } - if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs(message->header.type)) && - (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs(message->header.size))) - { - GNUNET_SCHEDULER_add_now(&stop_peer, - NULL); - return; - } } int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { .num_messages = 1 @@ -122,9 +123,9 @@ main(int argc, ccc = &my_ccc; sc.ccc = ccc; if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c index a5d40479f..089ad7a32 100644 --- a/src/transport/test_transport_api_limited_sockets.c +++ b/src/transport/test_transport_api_limited_sockets.c @@ -33,7 +33,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) #define MAX_FILES 50 @@ -44,32 +44,32 @@ static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received message of type %d from peer %s!\n", - ntohs(message->header.type), - GNUNET_i2s(sender)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received message of type %d from peer %s!\n", + ntohs (message->header.type), + GNUNET_i2s (sender)); if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == - ntohs(message->header.type)) && + ntohs (message->header.type)) && (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == - ntohs(message->header.size))) - { - ccc->global_ret = GNUNET_OK; - } + ntohs (message->header.size))) + { + ccc->global_ret = GNUNET_OK; + } else - { - GNUNET_break(0); - } - GNUNET_SCHEDULER_shutdown(); + { + GNUNET_break (0); + } + GNUNET_SCHEDULER_shutdown (); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { .num_messages = 1 @@ -89,26 +89,26 @@ main(int argc, char *argv[]) int res; sc.ccc = &my_ccc; - res = getrlimit(RLIMIT_NOFILE, - &r_file_old); + res = getrlimit (RLIMIT_NOFILE, + &r_file_old); r_file_new.rlim_cur = MAX_FILES; r_file_new.rlim_max = r_file_old.rlim_max; - res = setrlimit(RLIMIT_NOFILE, - &r_file_new); + res = setrlimit (RLIMIT_NOFILE, + &r_file_new); if (0 != res) - { - fprintf(stderr, - "Setting limit failed: %s\n", - strerror(errno)); - return 77; - } + { + fprintf (stderr, + "Setting limit failed: %s\n", + strerror (errno)); + return 77; + } ccc = &my_ccc; ccc->global_ret = GNUNET_SYSERR; if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } @@ -118,10 +118,10 @@ main(int argc, char *argv[]) int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { - fprintf(stderr, - "Cannot run test on this system\n"); + fprintf (stderr, + "Cannot run test on this system\n"); return 77; } diff --git a/src/transport/test_transport_api_manipulation_cfg.c b/src/transport/test_transport_api_manipulation_cfg.c index 4661a85a2..73c81114e 100644 --- a/src/transport/test_transport_api_manipulation_cfg.c +++ b/src/transport/test_transport_api_manipulation_cfg.c @@ -35,7 +35,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) #define TEST_MESSAGE_SIZE 2600 @@ -56,107 +56,107 @@ static struct GNUNET_TIME_Absolute start_response; static void -sendtask_response_task(void *cls) +sendtask_response_task (void *cls) { int ret; - start_response = GNUNET_TIME_absolute_get(); - ret = GNUNET_TRANSPORT_TESTING_send(ccc->p[1], - ccc->p[0], - GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, - TEST_MESSAGE_SIZE, - 1, - NULL, - NULL); + start_response = GNUNET_TIME_absolute_get (); + ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[1], + ccc->p[0], + GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, + TEST_MESSAGE_SIZE, + 1, + NULL, + NULL); if (GNUNET_NO == ret) - { - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - return; - } - GNUNET_assert(GNUNET_SYSERR != ret); + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_assert (GNUNET_SYSERR != ret); } static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { struct GNUNET_TIME_Relative duration; { - char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", - receiver->no, - ps, - ntohs(message->header.type), - ntohs(message->header.size), - GNUNET_i2s(sender)); - GNUNET_free(ps); + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", + receiver->no, + ps, + ntohs (message->header.type), + ntohs (message->header.size), + GNUNET_i2s (sender)); + GNUNET_free (ps); } - switch (ntohs(message->header.type)) + switch (ntohs (message->header.type)) + { + case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE: + duration = GNUNET_TIME_absolute_get_difference (start_request, + GNUNET_TIME_absolute_get ()); + if (duration.rel_value_us >= TEST_DELAY) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Request message was delayed for %s\n", + GNUNET_STRINGS_relative_time_to_string (duration, + GNUNET_YES)); + } + else { - case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE: - duration = GNUNET_TIME_absolute_get_difference(start_request, - GNUNET_TIME_absolute_get()); - if (duration.rel_value_us >= TEST_DELAY) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Request message was delayed for %s\n", - GNUNET_STRINGS_relative_time_to_string(duration, - GNUNET_YES)); - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Request message was delayed for unexpected duration %s\n", - GNUNET_STRINGS_relative_time_to_string(duration, - GNUNET_YES)); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown(); - } - /* Send response */ - GNUNET_SCHEDULER_add_now(&sendtask_response_task, - NULL); - return; - - case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2: - duration = GNUNET_TIME_absolute_get_difference(start_response, - GNUNET_TIME_absolute_get()); - if (duration.rel_value_us >= TEST_DELAY) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Response message was delayed for %s\n", - GNUNET_STRINGS_relative_time_to_string(duration, - GNUNET_YES)); - ccc->global_ret = GNUNET_OK; - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Response message was delayed for unexpected duration %s\n", - GNUNET_STRINGS_relative_time_to_string(duration, - GNUNET_YES)); - ccc->global_ret = GNUNET_SYSERR; - } - GNUNET_SCHEDULER_shutdown(); - break; - - default: - GNUNET_break(0); - break; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Request message was delayed for unexpected duration %s\n", + GNUNET_STRINGS_relative_time_to_string (duration, + GNUNET_YES)); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); } + /* Send response */ + GNUNET_SCHEDULER_add_now (&sendtask_response_task, + NULL); + return; + + case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2: + duration = GNUNET_TIME_absolute_get_difference (start_response, + GNUNET_TIME_absolute_get ()); + if (duration.rel_value_us >= TEST_DELAY) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Response message was delayed for %s\n", + GNUNET_STRINGS_relative_time_to_string (duration, + GNUNET_YES)); + ccc->global_ret = GNUNET_OK; + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Response message was delayed for unexpected duration %s\n", + GNUNET_STRINGS_relative_time_to_string (duration, + GNUNET_YES)); + ccc->global_ret = GNUNET_SYSERR; + } + GNUNET_SCHEDULER_shutdown (); + break; + + default: + GNUNET_break (0); + break; + } } int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { .num_messages = 1 @@ -173,11 +173,11 @@ main(int argc, ccc = &my_ccc; sc.ccc = ccc; - start_request = GNUNET_TIME_absolute_get(); + start_request = GNUNET_TIME_absolute_get (); if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } diff --git a/src/transport/test_transport_api_manipulation_recv_tcp.c b/src/transport/test_transport_api_manipulation_recv_tcp.c index 080d245ca..5f651e3ed 100644 --- a/src/transport/test_transport_api_manipulation_recv_tcp.c +++ b/src/transport/test_transport_api_manipulation_recv_tcp.c @@ -34,7 +34,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; @@ -51,133 +51,134 @@ static struct GNUNET_TIME_Relative dur_delayed; static void -do_free(void *cls) +do_free (void *cls) { struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; - GNUNET_free(sc); + GNUNET_free (sc); } static void -delayed_transmit(void *cls) +delayed_transmit (void *cls) { struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; - start_delayed = GNUNET_TIME_absolute_get(); - GNUNET_TRANSPORT_TESTING_large_send(sc); + start_delayed = GNUNET_TIME_absolute_get (); + GNUNET_TRANSPORT_TESTING_large_send (sc); } static void -sendtask(void *cls) +sendtask (void *cls) { struct GNUNET_TRANSPORT_TESTING_SendClosure *sc; struct GNUNET_ATS_Properties prop; struct GNUNET_TIME_Relative delay; - sc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_SendClosure); + sc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_SendClosure); sc->num_messages = 1; sc->ccc = ccc; sc->cont = &do_free; sc->cont_cls = sc; if (0 == messages_recv) - { - start_normal = GNUNET_TIME_absolute_get(); - } + { + start_normal = GNUNET_TIME_absolute_get (); + } if (0 < messages_recv) + { + memset (&prop, + 0, + sizeof(prop)); + delay = GNUNET_TIME_UNIT_SECONDS; + GNUNET_TRANSPORT_manipulation_set (ccc->p[1]->tmh, + &ccc->p[0]->id, + &prop, + delay, + GNUNET_TIME_UNIT_ZERO); + /* wait 1s to allow manipulation to go into effect */ + if (1 == messages_recv) { - memset(&prop, - 0, - sizeof(prop)); - delay = GNUNET_TIME_UNIT_SECONDS; - GNUNET_TRANSPORT_manipulation_set(ccc->p[1]->tmh, - &ccc->p[0]->id, - &prop, - delay, - GNUNET_TIME_UNIT_ZERO); - /* wait 1s to allow manipulation to go into effect */ - if (1 == messages_recv) - { - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &delayed_transmit, - sc); - return; - } + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &delayed_transmit, + sc); + return; } - GNUNET_TRANSPORT_TESTING_large_send(sc); + } + GNUNET_TRANSPORT_TESTING_large_send (sc); } static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { { - char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", - receiver->no, - ps, - ntohs(message->header.type), - ntohs(message->header.size), - GNUNET_i2s(sender)); - GNUNET_free(ps); + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", + receiver->no, + ps, + ntohs (message->header.type), + ntohs (message->header.size), + GNUNET_i2s (sender)); + GNUNET_free (ps); + } + if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) || + (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs ( + message->header.size))) + { + GNUNET_break (0); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; } - if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(message->header.type)) || - (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs(message->header.size))) - { - GNUNET_break(0); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown(); - return; - } if (messages_recv <= 2) - { - /* Received non-delayed message */ - dur_normal = GNUNET_TIME_absolute_get_duration(start_normal); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received non-delayed message %u after %s\n", - messages_recv, - GNUNET_STRINGS_relative_time_to_string(dur_normal, + { + /* Received non-delayed message */ + dur_normal = GNUNET_TIME_absolute_get_duration (start_normal); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received non-delayed message %u after %s\n", + messages_recv, + GNUNET_STRINGS_relative_time_to_string (dur_normal, GNUNET_YES)); - GNUNET_SCHEDULER_add_now(&sendtask, - NULL); - messages_recv++; - return; - } + GNUNET_SCHEDULER_add_now (&sendtask, + NULL); + messages_recv++; + return; + } /* Received manipulated message */ - dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received delayed message %u after %s\n", - messages_recv, - GNUNET_STRINGS_relative_time_to_string(dur_delayed, - GNUNET_YES)); + dur_delayed = GNUNET_TIME_absolute_get_duration (start_delayed); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received delayed message %u after %s\n", + messages_recv, + GNUNET_STRINGS_relative_time_to_string (dur_delayed, + GNUNET_YES)); if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) - { - GNUNET_break(0); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Delayed message was not delayed correctly: took only %s\n", - GNUNET_STRINGS_relative_time_to_string(dur_delayed, + { + GNUNET_break (0); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Delayed message was not delayed correctly: took only %s\n", + GNUNET_STRINGS_relative_time_to_string (dur_delayed, GNUNET_YES)); - } + } else - { - ccc->global_ret = GNUNET_OK; - } + { + ccc->global_ret = GNUNET_OK; + } /* shutdown */ - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); } int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { .connect_continuation = &sendtask, @@ -191,9 +192,9 @@ main(int argc, ccc = &my_ccc; if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } diff --git a/src/transport/test_transport_api_manipulation_send_tcp.c b/src/transport/test_transport_api_manipulation_send_tcp.c index ea4c7621b..28516bcae 100644 --- a/src/transport/test_transport_api_manipulation_send_tcp.c +++ b/src/transport/test_transport_api_manipulation_send_tcp.c @@ -34,7 +34,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; @@ -50,130 +50,131 @@ static struct GNUNET_TIME_Relative dur_delayed; static void -do_free(void *cls) +do_free (void *cls) { struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; - GNUNET_free(sc); + GNUNET_free (sc); } static void -delayed_transmit(void *cls) +delayed_transmit (void *cls) { struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; - start_delayed = GNUNET_TIME_absolute_get(); - GNUNET_TRANSPORT_TESTING_large_send(sc); + start_delayed = GNUNET_TIME_absolute_get (); + GNUNET_TRANSPORT_TESTING_large_send (sc); } static void -sendtask(void *cls) +sendtask (void *cls) { struct GNUNET_TRANSPORT_TESTING_SendClosure *sc; struct GNUNET_TIME_Relative delay; struct GNUNET_ATS_Properties prop; - sc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_SendClosure); + sc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_SendClosure); sc->num_messages = 1; sc->ccc = ccc; sc->cont = &do_free; sc->cont_cls = sc; if (0 == messages_recv) - { - start_normal = GNUNET_TIME_absolute_get(); - } + { + start_normal = GNUNET_TIME_absolute_get (); + } if (1 == messages_recv) - { - memset(&prop, - 0, - sizeof(prop)); - delay = GNUNET_TIME_UNIT_SECONDS; - GNUNET_TRANSPORT_manipulation_set(ccc->p[0]->tmh, - &ccc->p[1]->id, - &prop, - GNUNET_TIME_UNIT_ZERO, - delay); - /* wait 1s to allow manipulation to go into effect */ - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &delayed_transmit, - sc); - return; - } - GNUNET_TRANSPORT_TESTING_large_send(sc); + { + memset (&prop, + 0, + sizeof(prop)); + delay = GNUNET_TIME_UNIT_SECONDS; + GNUNET_TRANSPORT_manipulation_set (ccc->p[0]->tmh, + &ccc->p[1]->id, + &prop, + GNUNET_TIME_UNIT_ZERO, + delay); + /* wait 1s to allow manipulation to go into effect */ + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &delayed_transmit, + sc); + return; + } + GNUNET_TRANSPORT_TESTING_large_send (sc); } static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { { - char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", - receiver->no, - ps, - ntohs(message->header.type), - ntohs(message->header.size), - GNUNET_i2s(sender)); - GNUNET_free(ps); + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", + receiver->no, + ps, + ntohs (message->header.type), + ntohs (message->header.size), + GNUNET_i2s (sender)); + GNUNET_free (ps); } - if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(message->header.type)) || - (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs(message->header.size))) - { - GNUNET_break(0); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown(); - return; - } + if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) || + (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs ( + message->header.size))) + { + GNUNET_break (0); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; + } if (0 == messages_recv) - { - /* Received non-delayed message */ - dur_normal = GNUNET_TIME_absolute_get_duration(start_normal); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received non-delayed message %u after %s\n", - messages_recv, - GNUNET_STRINGS_relative_time_to_string(dur_normal, + { + /* Received non-delayed message */ + dur_normal = GNUNET_TIME_absolute_get_duration (start_normal); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received non-delayed message %u after %s\n", + messages_recv, + GNUNET_STRINGS_relative_time_to_string (dur_normal, GNUNET_YES)); - GNUNET_SCHEDULER_add_now(&sendtask, - NULL); - messages_recv++; - return; - } + GNUNET_SCHEDULER_add_now (&sendtask, + NULL); + messages_recv++; + return; + } /* Received manipulated message */ - dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received delayed message %u after %s\n", - messages_recv, - GNUNET_STRINGS_relative_time_to_string(dur_delayed, - GNUNET_YES)); + dur_delayed = GNUNET_TIME_absolute_get_duration (start_delayed); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received delayed message %u after %s\n", + messages_recv, + GNUNET_STRINGS_relative_time_to_string (dur_delayed, + GNUNET_YES)); if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) - { - GNUNET_break(0); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Delayed message was not delayed correctly: took only %s\n", - GNUNET_STRINGS_relative_time_to_string(dur_delayed, + { + GNUNET_break (0); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Delayed message was not delayed correctly: took only %s\n", + GNUNET_STRINGS_relative_time_to_string (dur_delayed, GNUNET_YES)); - } + } else - { - ccc->global_ret = GNUNET_OK; - } - GNUNET_SCHEDULER_shutdown(); + { + ccc->global_ret = GNUNET_OK; + } + GNUNET_SCHEDULER_shutdown (); } int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { .connect_continuation = &sendtask, @@ -187,9 +188,9 @@ main(int argc, ccc = &my_ccc; if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } diff --git a/src/transport/test_transport_api_monitor_peers.c b/src/transport/test_transport_api_monitor_peers.c index a76ebe5ee..4e12d0bad 100644 --- a/src/transport/test_transport_api_monitor_peers.c +++ b/src/transport/test_transport_api_monitor_peers.c @@ -28,12 +28,13 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) /** * How long until we give up on transmitting the message? */ -#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 30) #define TEST_MESSAGE_SIZE 2600 @@ -55,151 +56,151 @@ static int p2_c_notify; static void -custom_shutdown(void *cls) +custom_shutdown (void *cls) { if (NULL != pmc_p1) - { - GNUNET_TRANSPORT_monitor_peers_cancel(pmc_p1); - pmc_p1 = NULL; - } + { + GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p1); + pmc_p1 = NULL; + } if (NULL != pmc_p2) - { - GNUNET_TRANSPORT_monitor_peers_cancel(pmc_p2); - pmc_p2 = NULL; - } + { + GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p2); + pmc_p2 = NULL; + } } static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { - char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", - receiver->no, - ps, - ntohs(message->header.type), - ntohs(message->header.size), - GNUNET_i2s(sender)); - GNUNET_free(ps); + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", + receiver->no, + ps, + ntohs (message->header.type), + ntohs (message->header.size), + GNUNET_i2s (sender)); + GNUNET_free (ps); } static void -sendtask(void *cls) +sendtask (void *cls) { /* intentionally empty */ } static void -check_done() +check_done () { if ((GNUNET_YES == p1_c) && (GNUNET_YES == p2_c) && p1_c_notify && p2_c_notify) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Both peers state to be connected\n"); - ccc->global_ret = GNUNET_OK; - GNUNET_SCHEDULER_shutdown(); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Both peers state to be connected\n"); + ccc->global_ret = GNUNET_OK; + GNUNET_SCHEDULER_shutdown (); + } } static void -notify_connect(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) +notify_connect (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { - GNUNET_TRANSPORT_TESTING_log_connect(cls, - me, - other); - if (0 == memcmp(other, &ccc->p[0]->id, sizeof(struct GNUNET_PeerIdentity))) - { - p1_c_notify = GNUNET_YES; - } - if (0 == memcmp(other, &ccc->p[1]->id, sizeof(struct GNUNET_PeerIdentity))) - { - p2_c_notify = GNUNET_YES; - } - check_done(); + GNUNET_TRANSPORT_TESTING_log_connect (cls, + me, + other); + if (0 == memcmp (other, &ccc->p[0]->id, sizeof(struct GNUNET_PeerIdentity))) + { + p1_c_notify = GNUNET_YES; + } + if (0 == memcmp (other, &ccc->p[1]->id, sizeof(struct GNUNET_PeerIdentity))) + { + p2_c_notify = GNUNET_YES; + } + check_done (); } static void -monitor1_cb(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout) +monitor1_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout) { if ((NULL == address) || (NULL == ccc->p[0])) return; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Monitor 1: %s %s %s\n", - GNUNET_i2s(&address->peer), - GNUNET_TRANSPORT_ps2s(state), - GNUNET_STRINGS_absolute_time_to_string(state_timeout)); - if ((0 == memcmp(&address->peer, &ccc->p[1]->id, sizeof(ccc->p[1]->id))) && - (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Monitor 1: %s %s %s\n", + GNUNET_i2s (&address->peer), + GNUNET_TRANSPORT_ps2s (state), + GNUNET_STRINGS_absolute_time_to_string (state_timeout)); + if ((0 == memcmp (&address->peer, &ccc->p[1]->id, sizeof(ccc->p[1]->id))) && + (GNUNET_YES == GNUNET_TRANSPORT_is_connected (state)) && (GNUNET_NO == p1_c)) - { - p1_c = GNUNET_YES; - check_done(); - } + { + p1_c = GNUNET_YES; + check_done (); + } } static void -monitor2_cb(void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout) +monitor2_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout) { if ((NULL == address) || (NULL == ccc->p[1])) return; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Monitor 2: %s %s %s\n", - GNUNET_i2s(&address->peer), - GNUNET_TRANSPORT_ps2s(state), - GNUNET_STRINGS_absolute_time_to_string(state_timeout)); - if ((0 == memcmp(&address->peer, &ccc->p[0]->id, sizeof(ccc->p[0]->id))) && - (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Monitor 2: %s %s %s\n", + GNUNET_i2s (&address->peer), + GNUNET_TRANSPORT_ps2s (state), + GNUNET_STRINGS_absolute_time_to_string (state_timeout)); + if ((0 == memcmp (&address->peer, &ccc->p[0]->id, sizeof(ccc->p[0]->id))) && + (GNUNET_YES == GNUNET_TRANSPORT_is_connected (state)) && (GNUNET_NO == p2_c)) - { - p2_c = GNUNET_YES; - check_done(); - } + { + p2_c = GNUNET_YES; + check_done (); + } } static void -start_monitors(void *cls) +start_monitors (void *cls) { - pmc_p1 = GNUNET_TRANSPORT_monitor_peers(ccc->p[0]->cfg, - NULL, - GNUNET_NO, - &monitor1_cb, - NULL); - pmc_p2 = GNUNET_TRANSPORT_monitor_peers(ccc->p[1]->cfg, - NULL, - GNUNET_NO, - &monitor2_cb, - NULL); + pmc_p1 = GNUNET_TRANSPORT_monitor_peers (ccc->p[0]->cfg, + NULL, + GNUNET_NO, + &monitor1_cb, + NULL); + pmc_p2 = GNUNET_TRANSPORT_monitor_peers (ccc->p[1]->cfg, + NULL, + GNUNET_NO, + &monitor2_cb, + NULL); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { .pre_connect_task = &start_monitors, @@ -214,9 +215,9 @@ main(int argc, char *argv[]) ccc = &my_ccc; if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 76910a6c8..d8fd2046d 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c @@ -48,7 +48,8 @@ /** * Testcase timeout */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 450 * FACTOR) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 450 \ + * FACTOR) /** * If we are in an "xhdr" test, the factor by which we divide @@ -83,7 +84,7 @@ static char bitmap[TOTAL_MSGS / 8]; * Get the desired message size for message number @a iter. */ static size_t -get_size(unsigned int iter) +get_size (unsigned int iter) { size_t ret; @@ -91,7 +92,7 @@ get_size(unsigned int iter) #ifndef LINUX /* FreeBSD/OSX etc. Unix DGRAMs do not work * with large messages */ - if (0 == strcmp("unix", ccc->test_plugin)) + if (0 == strcmp ("unix", ccc->test_plugin)) ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 1024); #endif ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 60000); @@ -108,9 +109,9 @@ get_size(unsigned int iter) * @return message size of the message */ static size_t -get_size_cnt(unsigned int cnt_down) +get_size_cnt (unsigned int cnt_down) { - size_t ret = get_size(TOTAL_MSGS / xhdr - 1 - cnt_down); + size_t ret = get_size (TOTAL_MSGS / xhdr - 1 - cnt_down); total_bytes += ret; return ret; @@ -124,19 +125,19 @@ get_size_cnt(unsigned int cnt_down) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ static int -set_bit(unsigned int bitIdx) +set_bit (unsigned int bitIdx) { size_t arraySlot; unsigned int targetBit; if (bitIdx >= sizeof(bitmap) * 8) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "tried to set bit %u of %u(!?!?)\n", - bitIdx, - (unsigned int)sizeof(bitmap) * 8); - return GNUNET_SYSERR; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "tried to set bit %u of %u(!?!?)\n", + bitIdx, + (unsigned int) sizeof(bitmap) * 8); + return GNUNET_SYSERR; + } arraySlot = bitIdx / 8; targetBit = (1L << (bitIdx % 8)); bitmap[arraySlot] |= targetBit; @@ -152,143 +153,143 @@ set_bit(unsigned int bitIdx) * @return Bit @a bit from @a map */ static int -get_bit(const char *map, - unsigned int bit) +get_bit (const char *map, + unsigned int bit) { if (bit > TOTAL_MSGS) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "get bit %u of %u(!?!?)\n", - bit, - (unsigned int)sizeof(bitmap) * 8); - return 0; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "get bit %u of %u(!?!?)\n", + bit, + (unsigned int) sizeof(bitmap) * 8); + return 0; + } return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; } static void -custom_shutdown(void *cls) +custom_shutdown (void *cls) { unsigned long long delta; unsigned long long rate; int ok; /* Calculcate statistics */ - delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us; + delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; if (0 == delta) delta = 1; rate = (1000LL * 1000ll * total_bytes) / (1024 * delta); - fprintf(stderr, - "\nThroughput was %llu KiBytes/s\n", - rate); + fprintf (stderr, + "\nThroughput was %llu KiBytes/s\n", + rate); { char *value_name; - GNUNET_asprintf(&value_name, - "unreliable_%s", - ccc->test_plugin); - GAUGER("TRANSPORT", - value_name, - (int)rate, - "kb/s"); - GNUNET_free(value_name); + GNUNET_asprintf (&value_name, + "unreliable_%s", + ccc->test_plugin); + GAUGER ("TRANSPORT", + value_name, + (int) rate, + "kb/s"); + GNUNET_free (value_name); } ok = 0; for (unsigned int i = 0; i < TOTAL_MSGS / xhdr; i++) + { + if (get_bit (bitmap, i) == 0) { - if (get_bit(bitmap, i) == 0) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Did not receive message %d\n", - i); - ok = -1; - } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Did not receive message %d\n", + i); + ok = -1; } + } if (0 != ok) ccc->global_ret = GNUNET_SYSERR; /* fail: messages missing! */ } static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) { static int n; unsigned int s; char cbuf[GNUNET_MAX_MESSAGE_SIZE - 1]; - if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type)) + if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type)) return; - msg_recv = ntohl(hdr->num); - s = get_size(ntohl(hdr->num)); + msg_recv = ntohl (hdr->num); + s = get_size (ntohl (hdr->num)); - if (ntohs(hdr->header.size) != s) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Expected message %u of size %u, got %u bytes of message %u\n", - (uint32_t)ntohl(hdr->num), - s, - ntohs(hdr->header.size), - (uint32_t)ntohl(hdr->num)); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown(); - return; - } + if (ntohs (hdr->header.size) != s) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Expected message %u of size %u, got %u bytes of message %u\n", + (uint32_t) ntohl (hdr->num), + s, + ntohs (hdr->header.size), + (uint32_t) ntohl (hdr->num)); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; + } - memset(cbuf, - ntohl(hdr->num), - s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage)); + memset (cbuf, + ntohl (hdr->num), + s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage)); if (0 != - memcmp(cbuf, - &hdr[1], - s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Expected message %u with bits %u, but body did not match\n", - (uint32_t)ntohl(hdr->num), - (unsigned char)ntohl(hdr->num)); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown(); - return; - } + memcmp (cbuf, + &hdr[1], + s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Expected message %u with bits %u, but body did not match\n", + (uint32_t) ntohl (hdr->num), + (unsigned char) ntohl (hdr->num)); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; + } #if VERBOSE - if (0 == ntohl(hdr->num) % 5) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Got message %u of size %u\n", - (uint32_t)ntohl(hdr->num), - ntohs(hdr->header.size)); - } + if (0 == ntohl (hdr->num) % 5) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got message %u of size %u\n", + (uint32_t) ntohl (hdr->num), + ntohs (hdr->header.size)); + } #endif n++; - if (GNUNET_SYSERR == set_bit(ntohl(hdr->num))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Message id %u is bigger than maxmimum number of messages %u expected\n", - (uint32_t)ntohl(hdr->num), - TOTAL_MSGS / xhdr); - } + if (GNUNET_SYSERR == set_bit (ntohl (hdr->num))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Message id %u is bigger than maxmimum number of messages %u expected\n", + (uint32_t) ntohl (hdr->num), + TOTAL_MSGS / xhdr); + } if (0 == (n % (TOTAL_MSGS / xhdr / 100))) - { - fprintf(stderr, "%s", "."); - } + { + fprintf (stderr, "%s", "."); + } if (n == TOTAL_MSGS / xhdr) - { - /* end testcase with success */ - ccc->global_ret = GNUNET_OK; - GNUNET_SCHEDULER_shutdown(); - } + { + /* end testcase with success */ + ccc->global_ret = GNUNET_OK; + GNUNET_SCHEDULER_shutdown (); + } } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { - if (0 == strstr(argv[0], "xhdr")) + if (0 == strstr (argv[0], "xhdr")) xhdr = 30; struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { .num_messages = TOTAL_MSGS / xhdr, @@ -308,11 +309,11 @@ main(int argc, char *argv[]) ccc = &my_ccc; sc.ccc = ccc; - start_time = GNUNET_TIME_absolute_get(); + start_time = GNUNET_TIME_absolute_get (); if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } diff --git a/src/transport/test_transport_api_restart_reconnect.c b/src/transport/test_transport_api_restart_reconnect.c index bf9a7f9a1..dff57a3a8 100644 --- a/src/transport/test_transport_api_restart_reconnect.c +++ b/src/transport/test_transport_api_restart_reconnect.c @@ -32,7 +32,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; @@ -47,112 +47,113 @@ static int restarted; static void -custom_shutdown(void *cls) +custom_shutdown (void *cls) { if (NULL != ats_sh) - { - GNUNET_ATS_connectivity_suggest_cancel(ats_sh); - ats_sh = NULL; - } + { + GNUNET_ATS_connectivity_suggest_cancel (ats_sh); + ats_sh = NULL; + } } static void -restart_cb(void *cls) +restart_cb (void *cls) { static unsigned int c; struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; c++; if ((2 != c) && - (NULL != strstr(ccc->test_name, - "2peers"))) + (NULL != strstr (ccc->test_name, + "2peers"))) return; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Restarted peer %u (`%s'), issuing reconnect\n", - p->no, - GNUNET_i2s(&p->id)); - ats_sh = GNUNET_ATS_connectivity_suggest(p->ats, - &ccc->p[1]->id, - 1); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Restarted peer %u (`%s'), issuing reconnect\n", + p->no, + GNUNET_i2s (&p->id)); + ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, + &ccc->p[1]->id, + 1); } static void -restart(struct GNUNET_TRANSPORT_TESTING_PeerContext *p) +restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Restarting peer %u (`%s')\n", - p->no, - GNUNET_i2s(&p->id)); - GNUNET_assert(GNUNET_OK == - GNUNET_TRANSPORT_TESTING_restart_peer(p, - &restart_cb, - p)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Restarting peer %u (`%s')\n", + p->no, + GNUNET_i2s (&p->id)); + GNUNET_assert (GNUNET_OK == + GNUNET_TRANSPORT_TESTING_restart_peer (p, + &restart_cb, + p)); } static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { { - char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", - receiver->no, - ps, - ntohs(message->header.type), - ntohs(message->header.size), - GNUNET_i2s(sender)); - GNUNET_free(ps); + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", + receiver->no, + ps, + ntohs (message->header.type), + ntohs (message->header.size), + GNUNET_i2s (sender)); + GNUNET_free (ps); } - if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs(message->header.type)) && - (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs(message->header.size))) + if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) && + (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs ( + message->header.size))) + { + if (GNUNET_NO == restarted) { - if (GNUNET_NO == restarted) - { - restarted = GNUNET_YES; - fprintf(stderr, "TN: %s\n", ccc->test_name); - restart(ccc->p[0]); - if (NULL != strstr(ccc->test_name, - "2peers")) - restart(ccc->p[1]); - return; - } - else - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Restarted peers connected and message was sent, stopping test...\n"); - ccc->global_ret = GNUNET_OK; - GNUNET_SCHEDULER_shutdown(); - } + restarted = GNUNET_YES; + fprintf (stderr, "TN: %s\n", ccc->test_name); + restart (ccc->p[0]); + if (NULL != strstr (ccc->test_name, + "2peers")) + restart (ccc->p[1]); + return; } - else + else { - GNUNET_break(0); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown(); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Restarted peers connected and message was sent, stopping test...\n"); + ccc->global_ret = GNUNET_OK; + GNUNET_SCHEDULER_shutdown (); } + } + else + { + GNUNET_break (0); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + } } static void -notify_connect(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) +notify_connect (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { .num_messages = 1 }; sc.ccc = ccc; - GNUNET_TRANSPORT_TESTING_log_connect(cls, - me, - other); + GNUNET_TRANSPORT_TESTING_log_connect (cls, + me, + other); if (me == ccc->p[0]) p1_connected = GNUNET_YES; if (me == ccc->p[1]) @@ -161,22 +162,22 @@ notify_connect(void *cls, if ((GNUNET_YES == restarted) && (GNUNET_YES == p1_connected) && (GNUNET_YES == p2_connected)) - { - /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ - GNUNET_SCHEDULER_add_now(&GNUNET_TRANSPORT_TESTING_simple_send, - &sc); - } + { + /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ + GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send, + &sc); + } } static void -notify_disconnect(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) +notify_disconnect (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { - GNUNET_TRANSPORT_TESTING_log_disconnect(cls, - me, - other); + GNUNET_TRANSPORT_TESTING_log_disconnect (cls, + me, + other); if (me == ccc->p[0]) p1_connected = GNUNET_NO; if (me == ccc->p[1]) @@ -185,8 +186,8 @@ notify_disconnect(void *cls, int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { .num_messages = 1 @@ -205,9 +206,9 @@ main(int argc, ccc = &my_ccc; sc.ccc = ccc; if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c index dd2639136..80a457d15 100644 --- a/src/transport/test_transport_api_timeout.c +++ b/src/transport/test_transport_api_timeout.c @@ -34,9 +34,9 @@ /** * How long until we give up on transmitting the message? */ -#define WAIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) #define MTYPE 12345 @@ -52,94 +52,94 @@ static unsigned int disconnects; static void -custom_shutdown(void *cls) +custom_shutdown (void *cls) { if (NULL != timer_task) - { - GNUNET_SCHEDULER_cancel(timer_task); - timer_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (timer_task); + timer_task = NULL; + } if (0 == disconnects) - { - ccc->global_ret = GNUNET_OK; - } + { + ccc->global_ret = GNUNET_OK; + } else - { - ccc->global_ret = -GNUNET_SYSERR; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Fail! Had %u disconnects while waiting %s\n", - disconnects, - GNUNET_STRINGS_relative_time_to_string(WAIT, + { + ccc->global_ret = -GNUNET_SYSERR; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Fail! Had %u disconnects while waiting %s\n", + disconnects, + GNUNET_STRINGS_relative_time_to_string (WAIT, GNUNET_YES)); - } + } } static void -notify_receive(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received message of type %d from peer %s!\n", - ntohs(message->header.type), - GNUNET_i2s(sender)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received message of type %d from peer %s!\n", + ntohs (message->header.type), + GNUNET_i2s (sender)); } static void -notify_disconnect(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) +notify_disconnect (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { - GNUNET_TRANSPORT_TESTING_log_disconnect(cls, - me, - other); + GNUNET_TRANSPORT_TESTING_log_disconnect (cls, + me, + other); if (shutdown_flag != GNUNET_YES) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "FAIL! Peer `%s' disconnected during waiting period!\n", - GNUNET_i2s(other)); - disconnects++; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "FAIL! Peer `%s' disconnected during waiting period!\n", + GNUNET_i2s (other)); + disconnects++; + } } static void -timer(void *cls) +timer (void *cls) { static unsigned int percentage; timer_task = NULL; percentage += 10; - time_running = GNUNET_TIME_relative_add(time_running, - GNUNET_TIME_relative_divide(WAIT, - 10)); + time_running = GNUNET_TIME_relative_add (time_running, + GNUNET_TIME_relative_divide (WAIT, + 10)); if (time_running.rel_value_us == - GNUNET_TIME_relative_max(time_running, WAIT).rel_value_us) - { - fprintf(stderr, "%s", "100%%\n"); - shutdown_flag = GNUNET_YES; - GNUNET_SCHEDULER_shutdown(); - } + GNUNET_TIME_relative_max (time_running, WAIT).rel_value_us) + { + fprintf (stderr, "%s", "100%%\n"); + shutdown_flag = GNUNET_YES; + GNUNET_SCHEDULER_shutdown (); + } else - { - fprintf(stderr, - "%u%%..", - percentage); - timer_task = - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(WAIT, 10), - &timer, - NULL); - } + { + fprintf (stderr, + "%u%%..", + percentage); + timer_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (WAIT, 10), + &timer, + NULL); + } } int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { .connect_continuation = &timer, @@ -153,9 +153,9 @@ main(int argc, ccc = &my_ccc; if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main(2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) return 1; return 0; } diff --git a/src/transport/test_transport_blacklisting.c b/src/transport/test_transport_blacklisting.c index 1d8ef3fde..ef7f96d99 100644 --- a/src/transport/test_transport_blacklisting.c +++ b/src/transport/test_transport_blacklisting.c @@ -58,132 +58,134 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; -static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; +static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; struct GNUNET_TRANSPORT_TESTING_Handle *tth; /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) -#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) +#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ + 10) static int stage; static int ok; static int connected; -static struct GNUNET_SCHEDULER_Task * die_task; +static struct GNUNET_SCHEDULER_Task *die_task; -static struct GNUNET_SCHEDULER_Task * timeout_task; +static struct GNUNET_SCHEDULER_Task *timeout_task; -static struct GNUNET_SCHEDULER_Task * stage_task; +static struct GNUNET_SCHEDULER_Task *stage_task; #if VERBOSE -#define OKPP do { ok++; fprintf(stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) +#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, \ + __FILE__, __LINE__); } while (0) #else #define OKPP do { ok++; } while (0) #endif static void -run_stage(void *cls); +run_stage (void *cls); static void -end(void *cls) +end (void *cls) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); if (die_task != NULL) - { - GNUNET_SCHEDULER_cancel(die_task); - die_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = NULL; + } if (timeout_task != NULL) - { - GNUNET_SCHEDULER_cancel(timeout_task); - timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (timeout_task); + timeout_task = NULL; + } if (stage_task != NULL) - { - GNUNET_SCHEDULER_cancel(stage_task); - stage_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (stage_task); + stage_task = NULL; + } if (cc != NULL) - { - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); - cc = NULL; - } + { + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); + cc = NULL; + } if (p1 != NULL) - { - GNUNET_TRANSPORT_TESTING_stop_peer(p1); - p1 = NULL; - } + { + GNUNET_TRANSPORT_TESTING_stop_peer (p1); + p1 = NULL; + } if (p2 != NULL) - { - GNUNET_TRANSPORT_TESTING_stop_peer(p2); - p2 = NULL; - } + { + GNUNET_TRANSPORT_TESTING_stop_peer (p2); + p2 = NULL; + } } static void -end_badly(void *cls) +end_badly (void *cls) { die_task = NULL; if (timeout_task != NULL) - { - GNUNET_SCHEDULER_cancel(timeout_task); - timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (timeout_task); + timeout_task = NULL; + } if (stage_task != NULL) - { - GNUNET_SCHEDULER_cancel(stage_task); - stage_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (stage_task); + stage_task = NULL; + } if (cc != NULL) - { - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); - cc = NULL; - } + { + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); + cc = NULL; + } if (p1 != NULL) - GNUNET_TRANSPORT_TESTING_stop_peer(p1); + GNUNET_TRANSPORT_TESTING_stop_peer (p1); if (p2 != NULL) - GNUNET_TRANSPORT_TESTING_stop_peer(p2); + GNUNET_TRANSPORT_TESTING_stop_peer (p2); ok = GNUNET_SYSERR; } static void -testing_connect_cb(void *cls) +testing_connect_cb (void *cls) { cc = NULL; - char *p1_c = GNUNET_strdup(GNUNET_i2s(&p1->id)); + char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n", - p1->no, p1_c, p2->no, GNUNET_i2s(&p2->id)); - GNUNET_free(p1_c); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n", + p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); + GNUNET_free (p1_c); connected = GNUNET_YES; - stage_task = GNUNET_SCHEDULER_add_now(&run_stage, NULL); + stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL); } static void -connect_timeout(void *cls) +connect_timeout (void *cls) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peers not connected, next stage\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peers not connected, next stage\n"); timeout_task = NULL; - stage_task = GNUNET_SCHEDULER_add_now(&run_stage, - NULL); + stage_task = GNUNET_SCHEDULER_add_now (&run_stage, + NULL); } @@ -191,371 +193,384 @@ static int started; static void -start_cb(void *cls) +start_cb (void *cls) { struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; started++; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s_full(&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer %u (`%s') started\n", + p->no, + GNUNET_i2s_full (&p->id)); if (started != 2) return; - char *sender_c = GNUNET_strdup(GNUNET_i2s(&p1->id)); + char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", - p1->no, - sender_c, - p2->no, - GNUNET_i2s(&p2->id)); - GNUNET_free(sender_c); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", + p1->no, + sender_c, + p2->no, + GNUNET_i2s (&p2->id)); + GNUNET_free (sender_c); - cc = GNUNET_TRANSPORT_TESTING_connect_peers(p1, - p2, - &testing_connect_cb, - NULL); + cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, + p2, + &testing_connect_cb, + NULL); } static int -check_blacklist_config(const char *cfg_file, - struct GNUNET_PeerIdentity *peer, - struct GNUNET_PeerIdentity *bl_peer) +check_blacklist_config (const char *cfg_file, + struct GNUNET_PeerIdentity *peer, + struct GNUNET_PeerIdentity *bl_peer) { struct GNUNET_CONFIGURATION_Handle *cfg; char *section; char *peer_str; - cfg = GNUNET_CONFIGURATION_create(); - if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfg_file)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n", cfg_file); - GNUNET_CONFIGURATION_destroy(cfg); - return GNUNET_SYSERR; - } - - peer_str = GNUNET_strdup(GNUNET_i2s_full(peer)); - GNUNET_asprintf(§ion, "transport-blacklist-%s", peer_str); - - if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(cfg, section, GNUNET_i2s_full(bl_peer))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n", - cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); - GNUNET_CONFIGURATION_destroy(cfg); - GNUNET_free(section); - GNUNET_free(peer_str); - return GNUNET_SYSERR; - } - - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n", - cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); - - GNUNET_CONFIGURATION_destroy(cfg); - GNUNET_free(section); - GNUNET_free(peer_str); + cfg = GNUNET_CONFIGURATION_create (); + if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_file)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n", + cfg_file); + GNUNET_CONFIGURATION_destroy (cfg); + return GNUNET_SYSERR; + } + + peer_str = GNUNET_strdup (GNUNET_i2s_full (peer)); + GNUNET_asprintf (§ion, "transport-blacklist-%s", peer_str); + + if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, section, + GNUNET_i2s_full (bl_peer))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n", + cfg_file, peer_str, GNUNET_i2s_full (bl_peer)); + GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_free (section); + GNUNET_free (peer_str); + return GNUNET_SYSERR; + } + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n", + cfg_file, peer_str, GNUNET_i2s_full (bl_peer)); + + GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_free (section); + GNUNET_free (peer_str); return GNUNET_OK; } static void -run_stage(void *cls) +run_stage (void *cls) { stage_task = NULL; if (NULL != die_task) - GNUNET_SCHEDULER_cancel(die_task); - die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage); + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage); if (0 == stage) + { + started = GNUNET_NO; + connected = GNUNET_NO; + if (0 == strcmp (test_name, "test_transport_blacklisting_no_bl")) { - started = GNUNET_NO; - connected = GNUNET_NO; - if (0 == strcmp(test_name, "test_transport_blacklisting_no_bl")) - { - /* Try to connect peers successfully */ - p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - "test_transport_blacklisting_cfg_peer1.conf", - 1, - NULL, - NULL, - NULL, - NULL, - &start_cb, - NULL); - - p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - "test_transport_blacklisting_cfg_peer2.conf", - 2, - NULL, - NULL, - NULL, - NULL, - &start_cb, - NULL); - } - else if (0 == strcmp(test_name, - "test_transport_blacklisting_outbound_bl_full")) - { - const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_full.conf"; - const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf"; - - p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfg_p1, - 1, NULL, NULL, NULL, - NULL, - &start_cb, NULL); - p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfg_p2, 2, - NULL, NULL, NULL, - NULL, - &start_cb, NULL); - - /* check if configuration contain correct blacklist entries */ - if ((GNUNET_SYSERR == - check_blacklist_config(cfg_p1, &p1->id, &p2->id)) || - (GNUNET_SYSERR == - check_blacklist_config(cfg_p2, &p2->id, &p1->id))) - { - GNUNET_TRANSPORT_TESTING_stop_peer(p1); - p1 = NULL; - GNUNET_TRANSPORT_TESTING_stop_peer(p2); - p2 = NULL; - ok = 1; - GNUNET_SCHEDULER_add_now(&end, NULL); - } - } - else if (0 - == strcmp(test_name, "test_transport_blacklisting_outbound_bl_plugin")) - { - const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_plugin.conf"; - const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf"; - - p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfg_p1, - 1, - NULL, - NULL, - NULL, - NULL, - &start_cb, - NULL); - - p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfg_p2, 2, - NULL, - NULL, - NULL, - NULL, - &start_cb, - NULL); - - /* check if configuration contain correct blacklist entries */ - if ((GNUNET_SYSERR == - check_blacklist_config(cfg_p1, &p1->id, &p2->id)) || - (GNUNET_SYSERR == - check_blacklist_config(cfg_p2, &p2->id, &p1->id))) - { - GNUNET_TRANSPORT_TESTING_stop_peer(p1); - p1 = NULL; - GNUNET_TRANSPORT_TESTING_stop_peer(p2); - p2 = NULL; - ok = 1; - GNUNET_SCHEDULER_add_now(&end, NULL); - } - } - else if (0 == strcmp(test_name, - "test_transport_blacklisting_inbound_bl_full")) - { - const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf"; - const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf"; - - p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfg_p1, 1, - NULL, - NULL, NULL, NULL, - &start_cb, NULL); - - p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfg_p2, 2, - NULL, - NULL, NULL, NULL, - &start_cb, NULL); - - /* check if configuration contain correct blacklist entries */ - if ((GNUNET_SYSERR == - check_blacklist_config(cfg_p2, &p2->id, &p1->id))) - { - GNUNET_TRANSPORT_TESTING_stop_peer(p1); - p1 = NULL; - GNUNET_TRANSPORT_TESTING_stop_peer(p2); - p2 = NULL; - ok = 1; - GNUNET_SCHEDULER_add_now(&end, NULL); - } - } - else if (0 == strcmp(test_name, - "test_transport_blacklisting_inbound_bl_plugin")) - { - const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf"; - const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf"; - - p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfg_p1, 1, - NULL, - NULL, NULL, NULL, - &start_cb, NULL); - - p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfg_p2, 2, - NULL, - NULL, NULL, - NULL, - &start_cb, NULL); - - /* check if configuration contain correct blacklist entries */ - if ((GNUNET_SYSERR == - check_blacklist_config(cfg_p2, &p2->id, &p1->id))) - { - GNUNET_TRANSPORT_TESTING_stop_peer(p1); - p1 = NULL; - GNUNET_TRANSPORT_TESTING_stop_peer(p2); - p2 = NULL; - ok = 1; - GNUNET_SCHEDULER_add_now(&end, NULL); - } - } - else if (0 == strcmp(test_name, - "test_transport_blacklisting_multiple_plugins")) - { - const char * cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf"; - const char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf"; - - p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfg_p1, 1, - NULL, - NULL, NULL, NULL, - &start_cb, NULL); - - p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfg_p2, 2, - NULL, - NULL, NULL, NULL, - &start_cb, NULL); - - /* check if configuration contain correct blacklist entries */ - if ((GNUNET_SYSERR == - check_blacklist_config(cfg_p1, &p1->id, &p2->id)) || - (GNUNET_SYSERR == - check_blacklist_config(cfg_p2, &p2->id, &p1->id))) - { - GNUNET_TRANSPORT_TESTING_stop_peer(p1); - p1 = NULL; - GNUNET_TRANSPORT_TESTING_stop_peer(p2); - p2 = NULL; - ok = 1; - GNUNET_SCHEDULER_add_now(&end, NULL); - } - } - else - { - GNUNET_break(0); - GNUNET_SCHEDULER_add_now(&end, NULL); - } - - if ((NULL == p1) || (NULL == p2)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start peers\n"); - ok = 1; - GNUNET_SCHEDULER_add_now(&end, NULL); - } - - timeout_task = GNUNET_SCHEDULER_add_delayed(CONNECT_TIMEOUT, - &connect_timeout, - NULL); - stage++; - return; + /* Try to connect peers successfully */ + p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + "test_transport_blacklisting_cfg_peer1.conf", + 1, + NULL, + NULL, + NULL, + NULL, + &start_cb, + NULL); + + p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + "test_transport_blacklisting_cfg_peer2.conf", + 2, + NULL, + NULL, + NULL, + NULL, + &start_cb, + NULL); } - - if (cc != NULL) + else if (0 == strcmp (test_name, + "test_transport_blacklisting_outbound_bl_full")) { - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); - cc = NULL; + const char *cfg_p1 = + "test_transport_blacklisting_cfg_blp_peer1_full.conf"; + const char *cfg_p2 = + "test_transport_blacklisting_cfg_blp_peer2_full.conf"; + + p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfg_p1, + 1, NULL, NULL, NULL, + NULL, + &start_cb, NULL); + p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfg_p2, 2, + NULL, NULL, NULL, + NULL, + &start_cb, NULL); + + /* check if configuration contain correct blacklist entries */ + if ((GNUNET_SYSERR == + check_blacklist_config (cfg_p1, &p1->id, &p2->id)) || + (GNUNET_SYSERR == + check_blacklist_config (cfg_p2, &p2->id, &p1->id))) + { + GNUNET_TRANSPORT_TESTING_stop_peer (p1); + p1 = NULL; + GNUNET_TRANSPORT_TESTING_stop_peer (p2); + p2 = NULL; + ok = 1; + GNUNET_SCHEDULER_add_now (&end, NULL); + } } - - if (p1 != NULL) + else if (0 + == strcmp (test_name, + "test_transport_blacklisting_outbound_bl_plugin")) { - GNUNET_TRANSPORT_TESTING_stop_peer(p1); - p1 = NULL; + const char *cfg_p1 = + "test_transport_blacklisting_cfg_blp_peer1_plugin.conf"; + const char *cfg_p2 = + "test_transport_blacklisting_cfg_blp_peer2_plugin.conf"; + + p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfg_p1, + 1, + NULL, + NULL, + NULL, + NULL, + &start_cb, + NULL); + + p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfg_p2, 2, + NULL, + NULL, + NULL, + NULL, + &start_cb, + NULL); + + /* check if configuration contain correct blacklist entries */ + if ((GNUNET_SYSERR == + check_blacklist_config (cfg_p1, &p1->id, &p2->id)) || + (GNUNET_SYSERR == + check_blacklist_config (cfg_p2, &p2->id, &p1->id))) + { + GNUNET_TRANSPORT_TESTING_stop_peer (p1); + p1 = NULL; + GNUNET_TRANSPORT_TESTING_stop_peer (p2); + p2 = NULL; + ok = 1; + GNUNET_SCHEDULER_add_now (&end, NULL); + } } - if (p2 != NULL) + else if (0 == strcmp (test_name, + "test_transport_blacklisting_inbound_bl_full")) + { + const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf"; + const char *cfg_p2 = + "test_transport_blacklisting_cfg_blp_peer2_full.conf"; + + p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfg_p1, 1, + NULL, + NULL, NULL, NULL, + &start_cb, NULL); + + p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfg_p2, 2, + NULL, + NULL, NULL, NULL, + &start_cb, NULL); + + /* check if configuration contain correct blacklist entries */ + if ((GNUNET_SYSERR == + check_blacklist_config (cfg_p2, &p2->id, &p1->id))) + { + GNUNET_TRANSPORT_TESTING_stop_peer (p1); + p1 = NULL; + GNUNET_TRANSPORT_TESTING_stop_peer (p2); + p2 = NULL; + ok = 1; + GNUNET_SCHEDULER_add_now (&end, NULL); + } + } + else if (0 == strcmp (test_name, + "test_transport_blacklisting_inbound_bl_plugin")) + { + const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf"; + const char *cfg_p2 = + "test_transport_blacklisting_cfg_blp_peer2_plugin.conf"; + + p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfg_p1, 1, + NULL, + NULL, NULL, NULL, + &start_cb, NULL); + + p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfg_p2, 2, + NULL, + NULL, NULL, + NULL, + &start_cb, NULL); + + /* check if configuration contain correct blacklist entries */ + if ((GNUNET_SYSERR == + check_blacklist_config (cfg_p2, &p2->id, &p1->id))) + { + GNUNET_TRANSPORT_TESTING_stop_peer (p1); + p1 = NULL; + GNUNET_TRANSPORT_TESTING_stop_peer (p2); + p2 = NULL; + ok = 1; + GNUNET_SCHEDULER_add_now (&end, NULL); + } + } + else if (0 == strcmp (test_name, + "test_transport_blacklisting_multiple_plugins")) + { + const char *cfg_p1 = + "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf"; + const char *cfg_p2 = + "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf"; + + p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfg_p1, 1, + NULL, + NULL, NULL, NULL, + &start_cb, NULL); + + p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfg_p2, 2, + NULL, + NULL, NULL, NULL, + &start_cb, NULL); + + /* check if configuration contain correct blacklist entries */ + if ((GNUNET_SYSERR == + check_blacklist_config (cfg_p1, &p1->id, &p2->id)) || + (GNUNET_SYSERR == + check_blacklist_config (cfg_p2, &p2->id, &p1->id))) + { + GNUNET_TRANSPORT_TESTING_stop_peer (p1); + p1 = NULL; + GNUNET_TRANSPORT_TESTING_stop_peer (p2); + p2 = NULL; + ok = 1; + GNUNET_SCHEDULER_add_now (&end, NULL); + } + } + else { - GNUNET_TRANSPORT_TESTING_stop_peer(p2); - p2 = NULL; + GNUNET_break (0); + GNUNET_SCHEDULER_add_now (&end, NULL); } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n", - stage, (GNUNET_NO == started) ? "NOT STARTED" : "STARTED", - (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED"); + if ((NULL == p1) || (NULL == p2)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start peers\n"); + ok = 1; + GNUNET_SCHEDULER_add_now (&end, NULL); + } - if ((0 == strcmp(test_name, "test_transport_blacklisting_no_bl")) - || (0 == strcmp(test_name, "test_transport_blacklisting_multiple_plugins"))) + timeout_task = GNUNET_SCHEDULER_add_delayed (CONNECT_TIMEOUT, + &connect_timeout, + NULL); + stage++; + return; + } + + if (cc != NULL) + { + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); + cc = NULL; + } + + if (p1 != NULL) + { + GNUNET_TRANSPORT_TESTING_stop_peer (p1); + p1 = NULL; + } + if (p2 != NULL) + { + GNUNET_TRANSPORT_TESTING_stop_peer (p2); + p2 = NULL; + } + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n", + stage, (GNUNET_NO == started) ? "NOT STARTED" : "STARTED", + (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED"); + + if ((0 == strcmp (test_name, "test_transport_blacklisting_no_bl")) + || (0 == strcmp (test_name, + "test_transport_blacklisting_multiple_plugins"))) + { + if ((GNUNET_NO != started) && (GNUNET_YES == connected)) + ok = 0; + else { - if ((GNUNET_NO != started) && (GNUNET_YES == connected)) - ok = 0; - else - { - GNUNET_break(0); - ok = 1; - } + GNUNET_break (0); + ok = 1; } + } else + { + if ((GNUNET_NO != started) && (GNUNET_YES != connected)) + ok = 0; + else { - if ((GNUNET_NO != started) && (GNUNET_YES != connected)) - ok = 0; - else - { - ok = 1; - } + ok = 1; } - GNUNET_SCHEDULER_add_now(&end, NULL); + } + GNUNET_SCHEDULER_add_now (&end, NULL); } static void -run(void *cls, char * const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { connected = GNUNET_NO; stage = 0; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running test `%s'!\n", test_name); - stage_task = GNUNET_SCHEDULER_add_now(&run_stage, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running test `%s'!\n", test_name); + stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL); } int -main(int argc, char *argv0[]) +main (int argc, char *argv0[]) { ok = 1; - test_name = GNUNET_TRANSPORT_TESTING_get_test_name(argv0[0]); + test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0[0]); - GNUNET_log_setup("test-transport-api-blacklisting", "WARNING", NULL); + GNUNET_log_setup ("test-transport-api-blacklisting", "WARNING", NULL); - static char * const argv[] = + static char *const argv[] = { "date", "-c", "test_transport_api_data.conf", NULL }; static struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; - tth = GNUNET_TRANSPORT_TESTING_init(); + tth = GNUNET_TRANSPORT_TESTING_init (); - GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, argv, - "test-transport-api-blacklisting", "nohelp", options, &run, NULL); + GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, argv, + "test-transport-api-blacklisting", "nohelp", options, + &run, NULL); - GNUNET_TRANSPORT_TESTING_done(tth); + GNUNET_TRANSPORT_TESTING_done (tth); return ok; } diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c index d47696018..108c8929e 100644 --- a/src/transport/test_transport_testing_restart.c +++ b/src/transport/test_transport_testing_restart.c @@ -26,7 +26,7 @@ #include "gnunet_transport_service.h" #include "transport-testing.h" -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) static struct GNUNET_SCHEDULER_Task *timeout_task; @@ -39,104 +39,104 @@ static int ret; static void -end() +end () { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Stopping peers\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Stopping peers\n"); if (NULL != timeout_task) - GNUNET_SCHEDULER_cancel(timeout_task); + GNUNET_SCHEDULER_cancel (timeout_task); if (NULL != p) - GNUNET_TRANSPORT_TESTING_stop_peer(p); + GNUNET_TRANSPORT_TESTING_stop_peer (p); if (NULL != tth) - GNUNET_TRANSPORT_TESTING_done(tth); + GNUNET_TRANSPORT_TESTING_done (tth); } static void -end_badly() +end_badly () { timeout_task = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Timeout!\n"); - end(); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Timeout!\n"); + end (); ret = GNUNET_SYSERR; } static void -restart_cb(void *cls) +restart_cb (void *cls) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') successfully restarted\n", - p->no, - GNUNET_i2s(&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') successfully restarted\n", + p->no, + GNUNET_i2s (&p->id)); ret = 0; - GNUNET_SCHEDULER_add_now(&end, - NULL); + GNUNET_SCHEDULER_add_now (&end, + NULL); } static void -restart_task() +restart_task () { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') restarting\n", - p->no, - GNUNET_i2s(&p->id)); - GNUNET_TRANSPORT_TESTING_restart_peer(p, - &restart_cb, - p); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') restarting\n", + p->no, + GNUNET_i2s (&p->id)); + GNUNET_TRANSPORT_TESTING_restart_peer (p, + &restart_cb, + p); } static void -start_cb(void *cls) +start_cb (void *cls) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') successfully started\n", - p->no, - GNUNET_i2s(&p->id)); - GNUNET_SCHEDULER_add_now(&restart_task, - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') successfully started\n", + p->no, + GNUNET_i2s (&p->id)); + GNUNET_SCHEDULER_add_now (&restart_task, + NULL); } static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { ret = 1; - tth = GNUNET_TRANSPORT_TESTING_init(); - GNUNET_assert(NULL != tth); + tth = GNUNET_TRANSPORT_TESTING_init (); + GNUNET_assert (NULL != tth); timeout_task - = GNUNET_SCHEDULER_add_delayed(TIMEOUT, - &end_badly, - NULL); - p = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfgfile, - 1, - NULL, /* receive cb */ - NULL, /* connect cb */ - NULL, /* disconnect cb */ - NULL, /* nc/nd closure */ - start_cb, /* startup cb */ - NULL); /* closure */ + = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &end_badly, + NULL); + p = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfgfile, + 1, + NULL, /* receive cb */ + NULL, /* connect cb */ + NULL, /* disconnect cb */ + NULL, /* nc/nd closure */ + start_cb, /* startup cb */ + NULL); /* closure */ if (NULL == p) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to start peer\n"); - end(); - ret = 1; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to start peer\n"); + end (); + ret = 1; + } } int -main(int argc, - char *argv[]) +main (int argc, + char *argv[]) { char *const argv_1[] = { "test_transport_testing_restart", "-c", @@ -146,16 +146,16 @@ main(int argc, GNUNET_GETOPT_OPTION_END }; - GNUNET_log_setup("test_transport_testing_restart", - "WARNING", - NULL); - GNUNET_PROGRAM_run((sizeof(argv_1) / sizeof(char *)) - 1, - argv_1, - "test_transport_testing_restart", - "nohelp", - options, - &run, - NULL); + GNUNET_log_setup ("test_transport_testing_restart", + "WARNING", + NULL); + GNUNET_PROGRAM_run ((sizeof(argv_1) / sizeof(char *)) - 1, + argv_1, + "test_transport_testing_restart", + "nohelp", + options, + &run, + NULL); return ret; } diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c index c57b24054..5b75a80e1 100644 --- a/src/transport/test_transport_testing_startstop.c +++ b/src/transport/test_transport_testing_startstop.c @@ -26,7 +26,7 @@ #include "gnunet_transport_service.h" #include "transport-testing.h" -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) static struct GNUNET_SCHEDULER_Task *timeout_task; @@ -39,79 +39,79 @@ static int ret; static void -end() +end () { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Stopping peers\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Stopping peers\n"); if (NULL != timeout_task) - GNUNET_SCHEDULER_cancel(timeout_task); + GNUNET_SCHEDULER_cancel (timeout_task); if (NULL != p) - GNUNET_TRANSPORT_TESTING_stop_peer(p); + GNUNET_TRANSPORT_TESTING_stop_peer (p); if (NULL != tth) - GNUNET_TRANSPORT_TESTING_done(tth); + GNUNET_TRANSPORT_TESTING_done (tth); } static void -end_badly() +end_badly () { timeout_task = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Timeout!\n"); - end(); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Timeout!\n"); + end (); ret = GNUNET_SYSERR; } static void -start_cb(void *cls) +start_cb (void *cls) { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') successfully started\n", - p->no, - GNUNET_i2s(&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') successfully started\n", + p->no, + GNUNET_i2s (&p->id)); ret = 0; - GNUNET_SCHEDULER_add_now(&end, - NULL); + GNUNET_SCHEDULER_add_now (&end, + NULL); } static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { ret = 1; - tth = GNUNET_TRANSPORT_TESTING_init(); - GNUNET_assert(NULL != tth); + tth = GNUNET_TRANSPORT_TESTING_init (); + GNUNET_assert (NULL != tth); timeout_task = - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, - &end_badly, - NULL); - - p = GNUNET_TRANSPORT_TESTING_start_peer(tth, - cfgfile, - 1, - NULL, /* receive cb */ - NULL, /* connect cb */ - NULL, /* disconnect cb */ - NULL, /* nc/nd closure */ - &start_cb, /* startup cb */ - NULL); /* closure */ + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, + &end_badly, + NULL); + + p = GNUNET_TRANSPORT_TESTING_start_peer (tth, + cfgfile, + 1, + NULL, /* receive cb */ + NULL, /* connect cb */ + NULL, /* disconnect cb */ + NULL, /* nc/nd closure */ + &start_cb, /* startup cb */ + NULL); /* closure */ if (NULL == p) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); - if (timeout_task != NULL) - GNUNET_SCHEDULER_cancel(timeout_task); - timeout_task = GNUNET_SCHEDULER_add_now(&end_badly, NULL); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); + if (timeout_task != NULL) + GNUNET_SCHEDULER_cancel (timeout_task); + timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); + } } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { char *const argv_1[] = { "test_transport_testing", "-c", @@ -121,15 +121,15 @@ main(int argc, char *argv[]) GNUNET_GETOPT_OPTION_END }; - GNUNET_log_setup("test_transport_testing_startstop", - "WARNING", - NULL); - GNUNET_PROGRAM_run((sizeof(argv_1) / sizeof(char *)) - 1, - argv_1, - "test_transport_testing_startstop", "nohelp", - options, - &run, - &ret); + GNUNET_log_setup ("test_transport_testing_startstop", + "WARNING", + NULL); + GNUNET_PROGRAM_run ((sizeof(argv_1) / sizeof(char *)) - 1, + argv_1, + "test_transport_testing_startstop", "nohelp", + options, + &run, + &ret); return ret; } diff --git a/src/transport/transport-testing-filenames.c b/src/transport/transport-testing-filenames.c index 8d493864e..7c136b690 100644 --- a/src/transport/transport-testing-filenames.c +++ b/src/transport/transport-testing-filenames.c @@ -33,30 +33,30 @@ * @return extracted file name, has to be freed by caller */ static char * -extract_filename(const char *file) +extract_filename (const char *file) { - char *pch = GNUNET_strdup(file); + char *pch = GNUNET_strdup (file); char *backup = pch; char *filename = NULL; char *res; - if (NULL != strstr(pch, "/")) + if (NULL != strstr (pch, "/")) + { + pch = strtok (pch, "/"); + while (pch != NULL) { - pch = strtok(pch, "/"); - while (pch != NULL) - { - pch = strtok(NULL, "/"); - if (pch != NULL) - { - filename = pch; - } - } + pch = strtok (NULL, "/"); + if (pch != NULL) + { + filename = pch; + } } + } else filename = pch; - res = GNUNET_strdup(filename); - GNUNET_free(backup); + res = GNUNET_strdup (filename); + GNUNET_free (backup); return res; } @@ -69,9 +69,9 @@ extract_filename(const char *file) * @return the result */ char * -GNUNET_TRANSPORT_TESTING_get_test_name(const char *file) +GNUNET_TRANSPORT_TESTING_get_test_name (const char *file) { - char *backup = extract_filename(file); + char *backup = extract_filename (file); char *filename = backup; char *dotexe; char *ret; @@ -80,18 +80,18 @@ GNUNET_TRANSPORT_TESTING_get_test_name(const char *file) return NULL; /* remove "lt-" */ - filename = strstr(filename, "test"); + filename = strstr (filename, "test"); if (NULL == filename) - { - GNUNET_free(backup); - return NULL; - } + { + GNUNET_free (backup); + return NULL; + } /* remove ".exe" */ - if (NULL != (dotexe = strstr(filename, ".exe"))) + if (NULL != (dotexe = strstr (filename, ".exe"))) dotexe[0] = '\0'; - ret = GNUNET_strdup(filename); - GNUNET_free(backup); + ret = GNUNET_strdup (filename); + GNUNET_free (backup); return ret; } @@ -103,12 +103,12 @@ GNUNET_TRANSPORT_TESTING_get_test_name(const char *file) * @return the result */ char * -GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file) +GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file) { - char *src = extract_filename(file); + char *src = extract_filename (file); char *split; - split = strstr(src, "."); + split = strstr (src, "."); if (NULL != split) split[0] = '\0'; return src; @@ -123,40 +123,40 @@ GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file) * @return the result */ char * -GNUNET_TRANSPORT_TESTING_get_test_plugin_name(const char *file, - const char *test) +GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, + const char *test) { char *filename; char *dotexe; - char *e = extract_filename(file); - char *t = extract_filename(test); + char *e = extract_filename (file); + char *t = extract_filename (test); char *ret; if (NULL == e) goto fail; /* remove "lt-" */ - filename = strstr(e, "tes"); + filename = strstr (e, "tes"); if (NULL == filename) goto fail; /* remove ".exe" */ - if (NULL != (dotexe = strstr(filename, ".exe"))) + if (NULL != (dotexe = strstr (filename, ".exe"))) dotexe[0] = '\0'; /* find last _ */ - filename = strstr(filename, t); + filename = strstr (filename, t); if (NULL == filename) goto fail; /* copy plugin */ - filename += strlen(t); + filename += strlen (t); if ('\0' != *filename) filename++; - ret = GNUNET_strdup(filename); + ret = GNUNET_strdup (filename); goto suc; fail: ret = NULL; suc: - GNUNET_free(t); - GNUNET_free(e); + GNUNET_free (t); + GNUNET_free (e); return ret; } @@ -170,10 +170,10 @@ suc: * @return the result */ char * -GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, - int count) +GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, + int count) { - char *filename = extract_filename(file); + char *filename = extract_filename (file); char *backup = filename; char *dotexe; char *ret; @@ -181,20 +181,20 @@ GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, if (NULL == filename) return NULL; /* remove "lt-" */ - filename = strstr(filename, "test"); + filename = strstr (filename, "test"); if (NULL == filename) goto fail; /* remove ".exe" */ - if (NULL != (dotexe = strstr(filename, ".exe"))) + if (NULL != (dotexe = strstr (filename, ".exe"))) dotexe[0] = '\0'; - GNUNET_asprintf(&ret, - "%s_peer%u.conf", - filename, - count); - GNUNET_free(backup); + GNUNET_asprintf (&ret, + "%s_peer%u.conf", + filename, + count); + GNUNET_free (backup); return ret; fail: - GNUNET_free(backup); + GNUNET_free (backup); return NULL; } diff --git a/src/transport/transport-testing-loggers.c b/src/transport/transport-testing-loggers.c index 5fb7f2233..0e539eac0 100644 --- a/src/transport/transport-testing-loggers.c +++ b/src/transport/transport-testing-loggers.c @@ -1,4 +1,3 @@ - /* This file is part of GNUnet. Copyright (C) 2016 GNUnet e.V. @@ -34,19 +33,20 @@ * @param other peer that connected. */ void -GNUNET_TRANSPORT_TESTING_log_connect(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) +GNUNET_TRANSPORT_TESTING_log_connect (void *cls, + struct + GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) { char *ps; - ps = GNUNET_strdup(GNUNET_i2s(&me->id)); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peer %s connected to %u (%s)!\n", - GNUNET_i2s(other), - me->no, - ps); - GNUNET_free(ps); + ps = GNUNET_strdup (GNUNET_i2s (&me->id)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer %s connected to %u (%s)!\n", + GNUNET_i2s (other), + me->no, + ps); + GNUNET_free (ps); } @@ -59,19 +59,22 @@ GNUNET_TRANSPORT_TESTING_log_connect(void *cls, * @param other peer that disconnected. */ void -GNUNET_TRANSPORT_TESTING_log_disconnect(void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) +GNUNET_TRANSPORT_TESTING_log_disconnect (void *cls, + struct + GNUNET_TRANSPORT_TESTING_PeerContext * + me, + const struct + GNUNET_PeerIdentity *other) { char *ps; - ps = GNUNET_strdup(GNUNET_i2s(&me->id)); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peer `%s' disconnected from %u (%s)!\n", - GNUNET_i2s(other), - me->no, - ps); - GNUNET_free(ps); + ps = GNUNET_strdup (GNUNET_i2s (&me->id)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer `%s' disconnected from %u (%s)!\n", + GNUNET_i2s (other), + me->no, + ps); + GNUNET_free (ps); } /* end of transport-testing-loggers.c */ diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c index 7e7b0df4b..7581120c8 100644 --- a/src/transport/transport-testing-main.c +++ b/src/transport/transport-testing-main.c @@ -28,7 +28,8 @@ /** * Closure for #connect_cb. */ -struct GNUNET_TRANSPORT_TESTING_ConnectRequestList { +struct GNUNET_TRANSPORT_TESTING_ConnectRequestList +{ /** * Stored in a DLL. */ @@ -67,41 +68,41 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequestList { * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` */ static void -do_shutdown(void *cls) +do_shutdown (void *cls) { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Testcase shutting down\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Testcase shutting down\n"); if (NULL != ccc->shutdown_task) - ccc->shutdown_task(ccc->shutdown_task_cls); + ccc->shutdown_task (ccc->shutdown_task_cls); if (NULL != ccc->timeout_task) - { - GNUNET_SCHEDULER_cancel(ccc->timeout_task); - ccc->timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (ccc->timeout_task); + ccc->timeout_task = NULL; + } if (NULL != ccc->connect_task) - { - GNUNET_SCHEDULER_cancel(ccc->connect_task); - ccc->connect_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (ccc->connect_task); + ccc->connect_task = NULL; + } while (NULL != (crl = ccc->crl_head)) - { - GNUNET_CONTAINER_DLL_remove(ccc->crl_head, - ccc->crl_tail, - crl); - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(crl->cr); - GNUNET_free(crl); - } + { + GNUNET_CONTAINER_DLL_remove (ccc->crl_head, + ccc->crl_tail, + crl); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (crl->cr); + GNUNET_free (crl); + } for (unsigned int i = 0; i < ccc->num_peers; i++) + { + if (NULL != ccc->p[i]) { - if (NULL != ccc->p[i]) - { - GNUNET_TRANSPORT_TESTING_stop_peer(ccc->p[i]); - ccc->p[i] = NULL; - } + GNUNET_TRANSPORT_TESTING_stop_peer (ccc->p[i]); + ccc->p[i] = NULL; } + } } @@ -111,15 +112,15 @@ do_shutdown(void *cls) * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` */ static void -do_timeout(void *cls) +do_timeout (void *cls) { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; ccc->timeout_task = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Testcase timed out\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Testcase timed out\n"); ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); } @@ -128,7 +129,8 @@ do_timeout(void *cls) * #connect_cb, #disconnect_cb, #my_nc and #start_cb. * Allows us to identify which peer this is about. */ -struct GNUNET_TRANSPORT_TESTING_InternalPeerContext { +struct GNUNET_TRANSPORT_TESTING_InternalPeerContext +{ /** * Overall context of the callback. */ @@ -144,7 +146,8 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext { /** * Information tracked per connected peer. */ -struct ConnectPairInfo { +struct ConnectPairInfo +{ /** * Peer this is about. */ @@ -164,33 +167,33 @@ struct ConnectPairInfo { * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *` */ static void -connect_cb(void *cls) +connect_cb (void *cls) { struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl = cls; struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = crl->ccc; - GNUNET_CONTAINER_DLL_remove(ccc->crl_head, - ccc->crl_tail, - crl); + GNUNET_CONTAINER_DLL_remove (ccc->crl_head, + ccc->crl_tail, + crl); { - char *p1_c = GNUNET_strdup(GNUNET_i2s(&crl->p1->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peers connected: %u (%s) <-> %u (%s)\n", - crl->p1->no, - p1_c, - crl->p2->no, - GNUNET_i2s(&crl->p2->id)); - GNUNET_free(p1_c); - GNUNET_free(crl); + char *p1_c = GNUNET_strdup (GNUNET_i2s (&crl->p1->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peers connected: %u (%s) <-> %u (%s)\n", + crl->p1->no, + p1_c, + crl->p2->no, + GNUNET_i2s (&crl->p2->id)); + GNUNET_free (p1_c); + GNUNET_free (crl); } if (NULL == ccc->crl_head) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "All connections UP, launching custom test logic.\n"); - GNUNET_SCHEDULER_add_now(ccc->connect_continuation, - ccc->connect_continuation_cls); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All connections UP, launching custom test logic.\n"); + GNUNET_SCHEDULER_add_now (ccc->connect_continuation, + ccc->connect_continuation_cls); + } } @@ -202,14 +205,16 @@ connect_cb(void *cls) * @return NULL if @a peer was not found */ struct GNUNET_TRANSPORT_TESTING_PeerContext * -GNUNET_TRANSPORT_TESTING_find_peer(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, - const struct GNUNET_PeerIdentity *peer) +GNUNET_TRANSPORT_TESTING_find_peer (struct + GNUNET_TRANSPORT_TESTING_ConnectCheckContext + *ccc, + const struct GNUNET_PeerIdentity *peer) { for (unsigned int i = 0; i < ccc->num_peers; i++) if ((NULL != ccc->p[i]) && - (0 == memcmp(peer, - &ccc->p[i]->id, - sizeof(*peer)))) + (0 == memcmp (peer, + &ccc->p[i]->id, + sizeof(*peer)))) return ccc->p[i]; return NULL; } @@ -224,19 +229,19 @@ GNUNET_TRANSPORT_TESTING_find_peer(struct GNUNET_TRANSPORT_TESTING_ConnectCheckC * @return closure for message handlers */ static void * -my_nc(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +my_nc (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; struct ConnectPairInfo *cpi; if (NULL != ccc->nc) - ccc->nc(ccc->cls, - ccc->p[ipi->off], - peer); - cpi = GNUNET_new(struct ConnectPairInfo); + ccc->nc (ccc->cls, + ccc->p[ipi->off], + peer); + cpi = GNUNET_new (struct ConnectPairInfo); cpi->ipi = ipi; cpi->sender = peer; /* valid until disconnect */ return cpi; @@ -251,19 +256,19 @@ my_nc(void *cls, * @param custom_cls return value from @my_nc */ static void -my_nd(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *custom_cls) +my_nd (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *custom_cls) { struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; struct ConnectPairInfo *cpi = custom_cls; if (NULL != ccc->nd) - ccc->nd(ccc->cls, - ccc->p[ipi->off], - peer); - GNUNET_free(cpi); + ccc->nd (ccc->cls, + ccc->p[ipi->off], + peer); + GNUNET_free (cpi); } @@ -275,8 +280,8 @@ my_nd(void *cls, * @return #GNUNET_OK (all messages are fine) */ static int -check_test(void *cls, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +check_test (void *cls, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { return GNUNET_OK; } @@ -289,18 +294,18 @@ check_test(void *cls, * @param message message we received */ static void -handle_test(void *cls, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +handle_test (void *cls, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { struct ConnectPairInfo *cpi = cls; struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; if (NULL != ccc->rec) - ccc->rec(ccc->cls, - ccc->p[ipi->off], - cpi->sender, - message); + ccc->rec (ccc->cls, + ccc->p[ipi->off], + cpi->sender, + message); } @@ -312,8 +317,8 @@ handle_test(void *cls, * @return #GNUNET_OK (all messages are fine) */ static int -check_test2(void *cls, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +check_test2 (void *cls, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { return GNUNET_OK; } @@ -326,18 +331,18 @@ check_test2(void *cls, * @param message message we received */ static void -handle_test2(void *cls, - const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) +handle_test2 (void *cls, + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) { struct ConnectPairInfo *cpi = cls; struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; if (NULL != ccc->rec) - ccc->rec(ccc->cls, - ccc->p[ipi->off], - cpi->sender, - message); + ccc->rec (ccc->cls, + ccc->p[ipi->off], + cpi->sender, + message); } @@ -347,41 +352,42 @@ handle_test2(void *cls, * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` */ static void -do_connect(void *cls) +do_connect (void *cls) { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; ccc->connect_task = NULL; for (unsigned int i = 0; i < ccc->num_peers; i++) - for (unsigned int j = (ccc->bi_directional ? 0 : i + 1); j < ccc->num_peers; j++) + for (unsigned int j = (ccc->bi_directional ? 0 : i + 1); j < ccc->num_peers; + j++) + { + struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; + + if (i == j) + continue; + crl = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequestList); + GNUNET_CONTAINER_DLL_insert (ccc->crl_head, + ccc->crl_tail, + crl); + crl->ccc = ccc; + crl->p1 = ccc->p[i]; + crl->p2 = ccc->p[j]; { - struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; - - if (i == j) - continue; - crl = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequestList); - GNUNET_CONTAINER_DLL_insert(ccc->crl_head, - ccc->crl_tail, - crl); - crl->ccc = ccc; - crl->p1 = ccc->p[i]; - crl->p2 = ccc->p[j]; - { - char *sender_c = GNUNET_strdup(GNUNET_i2s(&ccc->p[0]->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", - ccc->p[0]->no, - sender_c, - ccc->p[1]->no, - GNUNET_i2s(&ccc->p[1]->id)); - GNUNET_free(sender_c); - } - crl->cr = GNUNET_TRANSPORT_TESTING_connect_peers(ccc->p[i], - ccc->p[j], - &connect_cb, - crl); + char *sender_c = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", + ccc->p[0]->no, + sender_c, + ccc->p[1]->no, + GNUNET_i2s (&ccc->p[1]->id)); + GNUNET_free (sender_c); } + crl->cr = GNUNET_TRANSPORT_TESTING_connect_peers (ccc->p[i], + ccc->p[j], + &connect_cb, + crl); + } } @@ -393,32 +399,32 @@ do_connect(void *cls) * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` */ static void -start_cb(void *cls) +start_cb (void *cls) { struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off]; ccc->started++; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Peer %u (`%s') started\n", - p->no, - GNUNET_i2s(&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer %u (`%s') started\n", + p->no, + GNUNET_i2s (&p->id)); if (ccc->started != ccc->num_peers) return; if (NULL != ccc->pre_connect_task) - { - /* Run the custom per-connect job, then give it a second to - go into effect before we continue connecting peers. */ - ccc->pre_connect_task(ccc->pre_connect_task_cls); - ccc->connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &do_connect, - ccc); - } + { + /* Run the custom per-connect job, then give it a second to + go into effect before we continue connecting peers. */ + ccc->pre_connect_task (ccc->pre_connect_task_cls); + ccc->connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &do_connect, + ccc); + } else - { - do_connect(ccc); - } + { + do_connect (ccc); + } } @@ -433,52 +439,52 @@ start_cb(void *cls) * @param cfg configuration */ static void -connect_check_run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +connect_check_run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; int ok; ccc->cfg = cfg; - ccc->timeout_task = GNUNET_SCHEDULER_add_delayed(ccc->timeout, - &do_timeout, - ccc); - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, - ccc); + ccc->timeout_task = GNUNET_SCHEDULER_add_delayed (ccc->timeout, + &do_timeout, + ccc); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, + ccc); ok = GNUNET_OK; for (unsigned int i = 0; i < ccc->num_peers; i++) - { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size(test, - GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, - struct GNUNET_TRANSPORT_TESTING_TestMessage, - NULL), - GNUNET_MQ_hd_var_size(test2, - GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, - struct GNUNET_TRANSPORT_TESTING_TestMessage, - NULL), - GNUNET_MQ_handler_end() - }; - ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer(ccc->tth, - ccc->cfg_files[i], - i + 1, - handlers, - &my_nc, - &my_nd, - &ccc->ip[i], - &start_cb, - &ccc->ip[i]); - if (NULL == ccc->p[i]) - ok = GNUNET_SYSERR; - } + { + struct GNUNET_MQ_MessageHandler handlers[] = { + GNUNET_MQ_hd_var_size (test, + GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, + struct GNUNET_TRANSPORT_TESTING_TestMessage, + NULL), + GNUNET_MQ_hd_var_size (test2, + GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, + struct GNUNET_TRANSPORT_TESTING_TestMessage, + NULL), + GNUNET_MQ_handler_end () + }; + ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer (ccc->tth, + ccc->cfg_files[i], + i + 1, + handlers, + &my_nc, + &my_nd, + &ccc->ip[i], + &start_cb, + &ccc->ip[i]); + if (NULL == ccc->p[i]) + ok = GNUNET_SYSERR; + } if (GNUNET_OK != ok) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Fail! Could not start peers!\n"); - GNUNET_SCHEDULER_shutdown(); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Fail! Could not start peers!\n"); + GNUNET_SCHEDULER_shutdown (); + } } @@ -498,12 +504,13 @@ connect_check_run(void *cls, * @return #GNUNET_SYSERR on error */ int -GNUNET_TRANSPORT_TESTING_connect_check(void *cls, - struct GNUNET_TRANSPORT_TESTING_Handle *tth_, - const char *test_plugin_, - const char *test_name_, - unsigned int num_peers, - char *cfg_files[]) +GNUNET_TRANSPORT_TESTING_connect_check (void *cls, + struct GNUNET_TRANSPORT_TESTING_Handle * + tth_, + const char *test_plugin_, + const char *test_name_, + unsigned int num_peers, + char *cfg_files[]) { static struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END @@ -511,10 +518,10 @@ GNUNET_TRANSPORT_TESTING_connect_check(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; struct GNUNET_TRANSPORT_TESTING_PeerContext *p[num_peers]; struct GNUNET_TRANSPORT_TESTING_InternalPeerContext ip[num_peers]; - char * argv[] = { - (char *)test_name_, + char *argv[] = { + (char *) test_name_, "-c", - (char *)ccc->config_file, + (char *) ccc->config_file, NULL }; @@ -527,18 +534,18 @@ GNUNET_TRANSPORT_TESTING_connect_check(void *cls, ccc->p = p; ccc->ip = ip; for (unsigned int i = 0; i < num_peers; i++) - { - ip[i].off = i; - ip[i].ccc = ccc; - } + { + ip[i].off = i; + ip[i].ccc = ccc; + } if (GNUNET_OK != - GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, - argv, - test_name_, - "nohelp", - options, - &connect_check_run, - ccc)) + GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, + argv, + test_name_, + "nohelp", + options, + &connect_check_run, + ccc)) return GNUNET_SYSERR; return ccc->global_ret; } @@ -555,11 +562,11 @@ GNUNET_TRANSPORT_TESTING_connect_check(void *cls, * @return #GNUNET_OK on success */ int -GNUNET_TRANSPORT_TESTING_main_(const char *argv0, - const char *filename, - unsigned int num_peers, - GNUNET_TRANSPORT_TESTING_CheckCallback check, - void *check_cls) +GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, + const char *filename, + unsigned int num_peers, + GNUNET_TRANSPORT_TESTING_CheckCallback check, + void *check_cls) { struct GNUNET_TRANSPORT_TESTING_Handle *tth; char *test_name; @@ -569,36 +576,36 @@ GNUNET_TRANSPORT_TESTING_main_(const char *argv0, int ret; ret = GNUNET_OK; - test_name = GNUNET_TRANSPORT_TESTING_get_test_name(argv0); - GNUNET_log_setup(test_name, - "WARNING", - NULL); - test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name(filename); - test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name(argv0, - test_source); + test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0); + GNUNET_log_setup (test_name, + "WARNING", + NULL); + test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (filename); + test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv0, + test_source); for (unsigned int i = 0; i < num_peers; i++) - cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name(argv0, - i + 1); - tth = GNUNET_TRANSPORT_TESTING_init(); + cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name (argv0, + i + 1); + tth = GNUNET_TRANSPORT_TESTING_init (); if (NULL == tth) - { - ret = GNUNET_SYSERR; - } + { + ret = GNUNET_SYSERR; + } else - { - ret = check(check_cls, - tth, - test_plugin, - test_name, - num_peers, - cfg_names); - GNUNET_TRANSPORT_TESTING_done(tth); - } + { + ret = check (check_cls, + tth, + test_plugin, + test_name, + num_peers, + cfg_names); + GNUNET_TRANSPORT_TESTING_done (tth); + } for (unsigned int i = 0; i < num_peers; i++) - GNUNET_free(cfg_names[i]); - GNUNET_free(test_source); - GNUNET_free_non_null(test_plugin); - GNUNET_free(test_name); + GNUNET_free (cfg_names[i]); + GNUNET_free (test_source); + GNUNET_free_non_null (test_plugin); + GNUNET_free (test_name); return ret; } diff --git a/src/transport/transport-testing-send.c b/src/transport/transport-testing-send.c index 42735e4c1..5885ffb03 100644 --- a/src/transport/transport-testing-send.c +++ b/src/transport/transport-testing-send.c @@ -27,15 +27,16 @@ /** * Acceptable transmission delay. */ -#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 30) /** * Return @a cx in @a cls. */ static void -find_cr(void *cls, - struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) +find_cr (void *cls, + struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) { struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls; @@ -62,66 +63,68 @@ find_cr(void *cls, * #GNUNET_SYSERR if @a msize is illegal */ int -GNUNET_TRANSPORT_TESTING_send(struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - uint16_t mtype, - uint16_t msize, - uint32_t num, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) +GNUNET_TRANSPORT_TESTING_send (struct + GNUNET_TRANSPORT_TESTING_PeerContext *sender, + struct GNUNET_TRANSPORT_TESTING_PeerContext * + receiver, + uint16_t mtype, + uint16_t msize, + uint32_t num, + GNUNET_SCHEDULER_TaskCallback cont, + void *cont_cls) { struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr; struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_TESTING_TestMessage *test; if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } cr = NULL; - GNUNET_TRANSPORT_TESTING_find_connecting_context(sender, - receiver, - &find_cr, - &cr); + GNUNET_TRANSPORT_TESTING_find_connecting_context (sender, + receiver, + &find_cr, + &cr); if (NULL == cr) - GNUNET_TRANSPORT_TESTING_find_connecting_context(receiver, - sender, - &find_cr, - &cr); + GNUNET_TRANSPORT_TESTING_find_connecting_context (receiver, + sender, + &find_cr, + &cr); if (NULL == cr) - { - GNUNET_break(0); - return GNUNET_NO; - } + { + GNUNET_break (0); + return GNUNET_NO; + } if (NULL == cr->mq) - { - GNUNET_break(0); - return GNUNET_NO; - } { - char *receiver_s = GNUNET_strdup(GNUNET_i2s(&receiver->id)); - - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Sending message from peer %u (`%s') -> peer %u (`%s') !\n", - sender->no, - GNUNET_i2s(&sender->id), - receiver->no, - receiver_s); - GNUNET_free(receiver_s); + GNUNET_break (0); + return GNUNET_NO; } - env = GNUNET_MQ_msg_extra(test, - msize - sizeof(*test), - mtype); - test->num = htonl(num); - memset(&test[1], - num, - msize - sizeof(*test)); - GNUNET_MQ_notify_sent(env, - cont, - cont_cls); - GNUNET_MQ_send(cr->mq, - env); + { + char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Sending message from peer %u (`%s') -> peer %u (`%s') !\n", + sender->no, + GNUNET_i2s (&sender->id), + receiver->no, + receiver_s); + GNUNET_free (receiver_s); + } + env = GNUNET_MQ_msg_extra (test, + msize - sizeof(*test), + mtype); + test->num = htonl (num); + memset (&test[1], + num, + msize - sizeof(*test)); + GNUNET_MQ_notify_sent (env, + cont, + cont_cls); + GNUNET_MQ_send (cr->mq, + env); return GNUNET_OK; } @@ -137,28 +140,28 @@ GNUNET_TRANSPORT_TESTING_send(struct GNUNET_TRANSPORT_TESTING_PeerContext *sende * @param cont_cls closure for @a cont */ static void -do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, - uint16_t size, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) +do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, + uint16_t size, + GNUNET_SCHEDULER_TaskCallback cont, + void *cont_cls) { int ret; ccc->global_ret = GNUNET_SYSERR; - ret = GNUNET_TRANSPORT_TESTING_send(ccc->p[0], - ccc->p[1], - GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, - size, - ccc->send_num_gen++, - cont, - cont_cls); - GNUNET_assert(GNUNET_SYSERR != ret); + ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[0], + ccc->p[1], + GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, + size, + ccc->send_num_gen++, + cont, + cont_cls); + GNUNET_assert (GNUNET_SYSERR != ret); if (GNUNET_NO == ret) - { - GNUNET_break(0); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown(); - } + { + GNUNET_break (0); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + } } @@ -171,30 +174,30 @@ do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, * of which should be currently connected */ void -GNUNET_TRANSPORT_TESTING_simple_send(void *cls) +GNUNET_TRANSPORT_TESTING_simple_send (void *cls) { struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; int done; size_t msize; if (0 < sc->num_messages) - { - sc->num_messages--; - done = (0 == sc->num_messages); - } + { + sc->num_messages--; + done = (0 == sc->num_messages); + } else - { - done = 0; /* infinite loop */ - } + { + done = 0; /* infinite loop */ + } msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage); if (NULL != sc->get_size_cb) - msize = sc->get_size_cb(sc->num_messages); + msize = sc->get_size_cb (sc->num_messages); /* if this was the last message, call the continuation, otherwise call this function again */ - do_send(sc->ccc, - msize, - done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send, - done ? sc->cont_cls : sc); + do_send (sc->ccc, + msize, + done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send, + done ? sc->cont_cls : sc); } @@ -207,30 +210,30 @@ GNUNET_TRANSPORT_TESTING_simple_send(void *cls) * of which should be currently connected */ void -GNUNET_TRANSPORT_TESTING_large_send(void *cls) +GNUNET_TRANSPORT_TESTING_large_send (void *cls) { struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; int done; size_t msize; if (0 < sc->num_messages) - { - sc->num_messages--; - done = (0 == sc->num_messages); - } + { + sc->num_messages--; + done = (0 == sc->num_messages); + } else - { - done = 0; /* infinite loop */ - } + { + done = 0; /* infinite loop */ + } msize = 2600; if (NULL != sc->get_size_cb) - msize = sc->get_size_cb(sc->num_messages); + msize = sc->get_size_cb (sc->num_messages); /* if this was the last message, call the continuation, otherwise call this function again */ - do_send(sc->ccc, - msize, - done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send, - done ? sc->cont_cls : sc); + do_send (sc->ccc, + msize, + done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send, + done ? sc->cont_cls : sc); } /* end of transport-testing-send.c */ diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index acf1645a9..225f7044f 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c @@ -26,19 +26,19 @@ #include "transport-testing.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-testing", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing", __VA_ARGS__) static struct GNUNET_TRANSPORT_TESTING_PeerContext * -find_peer_context(struct GNUNET_TRANSPORT_TESTING_Handle *tth, - const struct GNUNET_PeerIdentity *peer) +find_peer_context (struct GNUNET_TRANSPORT_TESTING_Handle *tth, + const struct GNUNET_PeerIdentity *peer) { struct GNUNET_TRANSPORT_TESTING_PeerContext *t; for (t = tth->p_head; NULL != t; t = t->next) - if (0 == memcmp(&t->id, - peer, - sizeof(struct GNUNET_PeerIdentity))) + if (0 == memcmp (&t->id, + peer, + sizeof(struct GNUNET_PeerIdentity))) return t; return NULL; } @@ -53,29 +53,34 @@ find_peer_context(struct GNUNET_TRANSPORT_TESTING_Handle *tth, * @param cb_cls closure for @a cb */ void -GNUNET_TRANSPORT_TESTING_find_connecting_context(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, - struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, - GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, - void *cb_cls) +GNUNET_TRANSPORT_TESTING_find_connecting_context (struct + GNUNET_TRANSPORT_TESTING_PeerContext + *p1, + struct + GNUNET_TRANSPORT_TESTING_PeerContext + *p2, + GNUNET_TRANSPORT_TESTING_ConnectContextCallback + cb, + void *cb_cls) { struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; for (cc = tth->cc_head; NULL != cc; cc = ccn) - { - ccn = cc->next; - if ((cc->p1 == p1) && - (cc->p2 == p2)) - cb(cb_cls, - cc); - } + { + ccn = cc->next; + if ((cc->p1 == p1) && + (cc->p2 == p2)) + cb (cb_cls, + cc); + } } static void -set_p1c(void *cls, - struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) +set_p1c (void *cls, + struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) { int *found = cls; @@ -86,8 +91,8 @@ set_p1c(void *cls, static void -set_mq(void *cls, - struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) +set_mq (void *cls, + struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) { struct GNUNET_MQ_Handle *mq = cls; @@ -96,8 +101,8 @@ set_mq(void *cls, static void -set_p2c(void *cls, - struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) +set_p2c (void *cls, + struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) { int *found = cls; @@ -108,8 +113,8 @@ set_p2c(void *cls, static void -clear_p1c(void *cls, - struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) +clear_p1c (void *cls, + struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) { int *found = cls; @@ -120,8 +125,8 @@ clear_p1c(void *cls, static void -clear_p2c(void *cls, - struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) +clear_p2c (void *cls, + struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) { int *found = cls; @@ -132,9 +137,9 @@ clear_p2c(void *cls, static void * -notify_connect(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +notify_connect (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; @@ -145,103 +150,103 @@ notify_connect(void *cls, int found; void *ret; - p2 = find_peer_context(p->tth, - peer); + p2 = find_peer_context (p->tth, + peer); if (NULL != p->nc) - ret = p->nc(p->cb_cls, - peer, - mq); + ret = p->nc (p->cb_cls, + peer, + mq); else ret = NULL; if (NULL != p2) - GNUNET_asprintf(&p2_s, - "%u (`%s')", - p2->no, - GNUNET_i2s(&p2->id)); + GNUNET_asprintf (&p2_s, + "%u (`%s')", + p2->no, + GNUNET_i2s (&p2->id)); else - GNUNET_asprintf(&p2_s, - "`%s'", - GNUNET_i2s(peer)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Peers %s connected to peer %u (`%s')\n", - p2_s, - p->no, - GNUNET_i2s(&p->id)); - GNUNET_free(p2_s); + GNUNET_asprintf (&p2_s, + "`%s'", + GNUNET_i2s (peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Peers %s connected to peer %u (`%s')\n", + p2_s, + p->no, + GNUNET_i2s (&p->id)); + GNUNET_free (p2_s); /* update flags in connecting contexts */ found = GNUNET_NO; - GNUNET_TRANSPORT_TESTING_find_connecting_context(p, - p2, - &set_p1c, - &found); + GNUNET_TRANSPORT_TESTING_find_connecting_context (p, + p2, + &set_p1c, + &found); if (GNUNET_NO == found) - { - cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest); - cc->p1 = p; - cc->p2 = p2; - cc->p1_c = GNUNET_YES; - GNUNET_CONTAINER_DLL_insert(tth->cc_head, - tth->cc_tail, - cc); - } + { + cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); + cc->p1 = p; + cc->p2 = p2; + cc->p1_c = GNUNET_YES; + GNUNET_CONTAINER_DLL_insert (tth->cc_head, + tth->cc_tail, + cc); + } found = GNUNET_NO; - GNUNET_TRANSPORT_TESTING_find_connecting_context(p2, - p, - &set_p2c, - &found); + GNUNET_TRANSPORT_TESTING_find_connecting_context (p2, + p, + &set_p2c, + &found); if (GNUNET_NO == found) - { - cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest); - cc->p1 = p2; - cc->p2 = p; - cc->p1_c = GNUNET_YES; - GNUNET_CONTAINER_DLL_insert(tth->cc_head, - tth->cc_tail, - cc); - } - GNUNET_TRANSPORT_TESTING_find_connecting_context(p, - p2, - &set_mq, - mq); + { + cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); + cc->p1 = p2; + cc->p2 = p; + cc->p1_c = GNUNET_YES; + GNUNET_CONTAINER_DLL_insert (tth->cc_head, + tth->cc_tail, + cc); + } + GNUNET_TRANSPORT_TESTING_find_connecting_context (p, + p2, + &set_mq, + mq); /* update set connected flag for all requests */ for (cc = tth->cc_head; NULL != cc; cc = cc->next) - { - if (GNUNET_YES == cc->connected) - continue; - if ((GNUNET_YES == cc->p1_c) && - (GNUNET_YES == cc->p2_c)) - { - cc->connected = GNUNET_YES; - /* stop trying to connect */ - if (NULL != cc->tct) - { - GNUNET_SCHEDULER_cancel(cc->tct); - cc->tct = NULL; - } - if (NULL != cc->oh) - { - GNUNET_TRANSPORT_offer_hello_cancel(cc->oh); - cc->oh = NULL; - } - if (NULL != cc->ats_sh) - { - GNUNET_ATS_connectivity_suggest_cancel(cc->ats_sh); - cc->ats_sh = NULL; - } - } + { + if (GNUNET_YES == cc->connected) + continue; + if ((GNUNET_YES == cc->p1_c) && + (GNUNET_YES == cc->p2_c)) + { + cc->connected = GNUNET_YES; + /* stop trying to connect */ + if (NULL != cc->tct) + { + GNUNET_SCHEDULER_cancel (cc->tct); + cc->tct = NULL; + } + if (NULL != cc->oh) + { + GNUNET_TRANSPORT_offer_hello_cancel (cc->oh); + cc->oh = NULL; + } + if (NULL != cc->ats_sh) + { + GNUNET_ATS_connectivity_suggest_cancel (cc->ats_sh); + cc->ats_sh = NULL; + } } + } /* then notify application */ for (cc = tth->cc_head; NULL != cc; cc = ccn) + { + ccn = cc->next; + if ((GNUNET_YES == cc->connected) && + (NULL != cc->cb)) { - ccn = cc->next; - if ((GNUNET_YES == cc->connected) && - (NULL != cc->cb)) - { - cc->cb(cc->cb_cls); - cc->cb = NULL; /* only notify once! */ - } + cc->cb (cc->cb_cls); + cc->cb = NULL; /* only notify once! */ } + } return ret; } @@ -252,13 +257,13 @@ notify_connect(void *cls, * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest` */ static void -offer_hello(void *cls); +offer_hello (void *cls); static void -notify_disconnect(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *handler_cls) +notify_disconnect (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *handler_cls) { struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; @@ -268,93 +273,94 @@ notify_disconnect(void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; - p2 = find_peer_context(p->tth, - peer); + p2 = find_peer_context (p->tth, + peer); no = p->no; if (NULL != p2) - GNUNET_asprintf(&p2_s, - "%u (`%s')", - p2->no, - GNUNET_i2s(&p2->id)); + GNUNET_asprintf (&p2_s, + "%u (`%s')", + p2->no, + GNUNET_i2s (&p2->id)); else - GNUNET_asprintf(&p2_s, - "`%s'", - GNUNET_i2s(peer)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Peers %s disconnected from peer %u (`%s')\n", - p2_s, - no, - GNUNET_i2s(&p->id)); - GNUNET_free(p2_s); + GNUNET_asprintf (&p2_s, + "`%s'", + GNUNET_i2s (peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Peers %s disconnected from peer %u (`%s')\n", + p2_s, + no, + GNUNET_i2s (&p->id)); + GNUNET_free (p2_s); /* notify about disconnect */ if (NULL != p->nd) - p->nd(p->cb_cls, - peer, - handler_cls); + p->nd (p->cb_cls, + peer, + handler_cls); if (NULL == p2) return; /* clear MQ, it is now invalid */ - GNUNET_TRANSPORT_TESTING_find_connecting_context(p, - p2, - &set_mq, - NULL); + GNUNET_TRANSPORT_TESTING_find_connecting_context (p, + p2, + &set_mq, + NULL); /* update set connected flags for all requests */ - GNUNET_TRANSPORT_TESTING_find_connecting_context(p, - p2, - &clear_p1c, - NULL); - GNUNET_TRANSPORT_TESTING_find_connecting_context(p2, - p, - &clear_p2c, - NULL); + GNUNET_TRANSPORT_TESTING_find_connecting_context (p, + p2, + &clear_p1c, + NULL); + GNUNET_TRANSPORT_TESTING_find_connecting_context (p2, + p, + &clear_p2c, + NULL); /* resume connectivity requests as necessary */ for (cc = tth->cc_head; NULL != cc; cc = cc->next) - { - if (GNUNET_NO == cc->connected) - continue; - if ((GNUNET_YES != cc->p1_c) || - (GNUNET_YES != cc->p2_c)) - { - cc->connected = GNUNET_NO; - /* start trying to connect */ - if ((NULL == cc->tct) && - (NULL == cc->oh)) - cc->tct = GNUNET_SCHEDULER_add_now(&offer_hello, - cc); - if (NULL == cc->ats_sh) - cc->ats_sh = GNUNET_ATS_connectivity_suggest(cc->p1->ats, - &p2->id, - 1); - } + { + if (GNUNET_NO == cc->connected) + continue; + if ((GNUNET_YES != cc->p1_c) || + (GNUNET_YES != cc->p2_c)) + { + cc->connected = GNUNET_NO; + /* start trying to connect */ + if ((NULL == cc->tct) && + (NULL == cc->oh)) + cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello, + cc); + if (NULL == cc->ats_sh) + cc->ats_sh = GNUNET_ATS_connectivity_suggest (cc->p1->ats, + &p2->id, + 1); } + } } static void -get_hello(void *cb_cls, - const struct GNUNET_MessageHeader *message) +get_hello (void *cb_cls, + const struct GNUNET_MessageHeader *message) { struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cb_cls; struct GNUNET_PeerIdentity hello_id; - GNUNET_assert(GNUNET_OK == - GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)message, - &hello_id)); - GNUNET_assert(0 == memcmp(&hello_id, - &p->id, - sizeof(hello_id))); - GNUNET_free_non_null(p->hello); - p->hello = (struct GNUNET_HELLO_Message *)GNUNET_copy_message(message); + GNUNET_assert (GNUNET_OK == + GNUNET_HELLO_get_id ((const struct + GNUNET_HELLO_Message *) message, + &hello_id)); + GNUNET_assert (0 == memcmp (&hello_id, + &p->id, + sizeof(hello_id))); + GNUNET_free_non_null (p->hello); + p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message); if (NULL != p->start_cb) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') successfully started\n", - p->no, - GNUNET_i2s(&p->id)); - p->start_cb(p->start_cb_cls); - p->start_cb = NULL; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') successfully started\n", + p->no, + GNUNET_i2s (&p->id)); + p->start_cb (p->start_cb_cls); + p->start_cb = NULL; + } } @@ -372,43 +378,45 @@ get_hello(void *cb_cls, * @return the peer context */ struct GNUNET_TRANSPORT_TESTING_PeerContext * -GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth, - const char *cfgname, - int peer_id, - const struct GNUNET_MQ_MessageHandler *handlers, - GNUNET_TRANSPORT_NotifyConnect nc, - GNUNET_TRANSPORT_NotifyDisconnect nd, - void *cb_cls, - GNUNET_SCHEDULER_TaskCallback start_cb, - void *start_cb_cls) +GNUNET_TRANSPORT_TESTING_start_peer (struct + GNUNET_TRANSPORT_TESTING_Handle *tth, + const char *cfgname, + int peer_id, + const struct + GNUNET_MQ_MessageHandler *handlers, + GNUNET_TRANSPORT_NotifyConnect nc, + GNUNET_TRANSPORT_NotifyDisconnect nd, + void *cb_cls, + GNUNET_SCHEDULER_TaskCallback start_cb, + void *start_cb_cls) { char *emsg = NULL; struct GNUNET_TRANSPORT_TESTING_PeerContext *p; struct GNUNET_PeerIdentity dummy; unsigned int i; - if (GNUNET_NO == GNUNET_DISK_file_test(cfgname)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "File not found: `%s'\n", - cfgname); - return NULL; - } + if (GNUNET_NO == GNUNET_DISK_file_test (cfgname)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "File not found: `%s'\n", + cfgname); + return NULL; + } - p = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_PeerContext); + p = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_PeerContext); p->tth = tth; p->nc = nc; p->nd = nd; if (NULL != handlers) - { - for (i = 0; NULL != handlers[i].cb; i++) - ; - p->handlers = GNUNET_new_array(i + 1, - struct GNUNET_MQ_MessageHandler); - GNUNET_memcpy(p->handlers, - handlers, - i * sizeof(struct GNUNET_MQ_MessageHandler)); - } + { + for (i = 0; NULL != handlers[i].cb; i++) + ; + p->handlers = GNUNET_new_array (i + 1, + struct GNUNET_MQ_MessageHandler); + GNUNET_memcpy (p->handlers, + handlers, + i * sizeof(struct GNUNET_MQ_MessageHandler)); + } if (NULL != cb_cls) p->cb_cls = cb_cls; else @@ -418,105 +426,105 @@ GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth, p->start_cb_cls = start_cb_cls; else p->start_cb_cls = p; - GNUNET_CONTAINER_DLL_insert(tth->p_head, - tth->p_tail, - p); + GNUNET_CONTAINER_DLL_insert (tth->p_head, + tth->p_tail, + p); /* Create configuration and call testing lib to modify it */ - p->cfg = GNUNET_CONFIGURATION_create(); - GNUNET_assert(GNUNET_OK == - GNUNET_CONFIGURATION_load(p->cfg, cfgname)); + p->cfg = GNUNET_CONFIGURATION_create (); + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_load (p->cfg, cfgname)); if (GNUNET_SYSERR == - GNUNET_TESTING_configuration_create(tth->tl_system, - p->cfg)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to create unique configuration based on `%s'\n", - cfgname); - GNUNET_CONFIGURATION_destroy(p->cfg); - GNUNET_free(p); - return NULL; - } + GNUNET_TESTING_configuration_create (tth->tl_system, + p->cfg)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Testing library failed to create unique configuration based on `%s'\n", + cfgname); + GNUNET_CONFIGURATION_destroy (p->cfg); + GNUNET_free (p); + return NULL; + } p->no = peer_id; /* Configure peer with configuration */ - p->peer = GNUNET_TESTING_peer_configure(tth->tl_system, - p->cfg, - p->no, - NULL, - &emsg); + p->peer = GNUNET_TESTING_peer_configure (tth->tl_system, + p->cfg, + p->no, + NULL, + &emsg); if (NULL == p->peer) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to create unique configuration based on `%s': `%s'\n", - cfgname, - emsg); - GNUNET_TRANSPORT_TESTING_stop_peer(p); - GNUNET_free_non_null(emsg); - return NULL; - } - GNUNET_free_non_null(emsg); - if (GNUNET_OK != GNUNET_TESTING_peer_start(p->peer)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to create unique configuration based on `%s'\n", - cfgname); - GNUNET_TRANSPORT_TESTING_stop_peer(p); - return NULL; - } + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Testing library failed to create unique configuration based on `%s': `%s'\n", + cfgname, + emsg); + GNUNET_TRANSPORT_TESTING_stop_peer (p); + GNUNET_free_non_null (emsg); + return NULL; + } + GNUNET_free_non_null (emsg); + if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Testing library failed to create unique configuration based on `%s'\n", + cfgname); + GNUNET_TRANSPORT_TESTING_stop_peer (p); + return NULL; + } - memset(&dummy, - '\0', - sizeof(dummy)); - GNUNET_TESTING_peer_get_identity(p->peer, - &p->id); - if (0 == memcmp(&dummy, - &p->id, - sizeof(struct GNUNET_PeerIdentity))) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to obtain peer identity for peer %u\n", - p->no); - GNUNET_TRANSPORT_TESTING_stop_peer(p); - return NULL; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u configured with identity `%s'\n", - p->no, - GNUNET_i2s_full(&p->id)); - p->tmh = GNUNET_TRANSPORT_manipulation_connect(p->cfg); - p->th = GNUNET_TRANSPORT_core_connect(p->cfg, - NULL, - handlers, - p, - ¬ify_connect, - ¬ify_disconnect, - NULL); + memset (&dummy, + '\0', + sizeof(dummy)); + GNUNET_TESTING_peer_get_identity (p->peer, + &p->id); + if (0 == memcmp (&dummy, + &p->id, + sizeof(struct GNUNET_PeerIdentity))) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Testing library failed to obtain peer identity for peer %u\n", + p->no); + GNUNET_TRANSPORT_TESTING_stop_peer (p); + return NULL; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u configured with identity `%s'\n", + p->no, + GNUNET_i2s_full (&p->id)); + p->tmh = GNUNET_TRANSPORT_manipulation_connect (p->cfg); + p->th = GNUNET_TRANSPORT_core_connect (p->cfg, + NULL, + handlers, + p, + ¬ify_connect, + ¬ify_disconnect, + NULL); if ((NULL == p->th) || (NULL == p->tmh)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to transport service for peer `%s': `%s'\n", - cfgname, - emsg); - GNUNET_TRANSPORT_TESTING_stop_peer(p); - return NULL; - } - p->ats = GNUNET_ATS_connectivity_init(p->cfg); + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to transport service for peer `%s': `%s'\n", + cfgname, + emsg); + GNUNET_TRANSPORT_TESTING_stop_peer (p); + return NULL; + } + p->ats = GNUNET_ATS_connectivity_init (p->cfg); if (NULL == p->ats) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to ATS service for peer `%s': `%s'\n", - cfgname, - emsg); - GNUNET_TRANSPORT_TESTING_stop_peer(p); - return NULL; - } - p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, - GNUNET_TRANSPORT_AC_ANY, - &get_hello, - p); - GNUNET_assert(NULL != p->ghh); + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to ATS service for peer `%s': `%s'\n", + cfgname, + emsg); + GNUNET_TRANSPORT_TESTING_stop_peer (p); + return NULL; + } + p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, + GNUNET_TRANSPORT_AC_ANY, + &get_hello, + p); + GNUNET_assert (NULL != p->ghh); return p; } @@ -530,89 +538,90 @@ GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth, * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR */ int -GNUNET_TRANSPORT_TESTING_restart_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p, - GNUNET_SCHEDULER_TaskCallback restart_cb, - void *restart_cb_cls) +GNUNET_TRANSPORT_TESTING_restart_peer (struct + GNUNET_TRANSPORT_TESTING_PeerContext *p, + GNUNET_SCHEDULER_TaskCallback restart_cb, + void *restart_cb_cls) { struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; /* shutdown */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Stopping peer %u (`%s')\n", - p->no, - GNUNET_i2s(&p->id)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Stopping peer %u (`%s')\n", + p->no, + GNUNET_i2s (&p->id)); if (NULL != p->ghh) - { - GNUNET_TRANSPORT_hello_get_cancel(p->ghh); - p->ghh = NULL; - } + { + GNUNET_TRANSPORT_hello_get_cancel (p->ghh); + p->ghh = NULL; + } if (NULL != p->th) - { - GNUNET_TRANSPORT_core_disconnect(p->th); - p->th = NULL; - } + { + GNUNET_TRANSPORT_core_disconnect (p->th); + p->th = NULL; + } if (NULL != p->tmh) - { - GNUNET_TRANSPORT_manipulation_disconnect(p->tmh); - p->tmh = NULL; - } + { + GNUNET_TRANSPORT_manipulation_disconnect (p->tmh); + p->tmh = NULL; + } for (cc = p->tth->cc_head; NULL != cc; cc = ccn) - { - ccn = cc->next; - if ((cc->p1 == p) || - (cc->p2 == p)) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); - } + { + ccn = cc->next; + if ((cc->p1 == p) || + (cc->p2 == p)) + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); + } if (NULL != p->ats) - { - GNUNET_ATS_connectivity_done(p->ats); - p->ats = NULL; - } + { + GNUNET_ATS_connectivity_done (p->ats); + p->ats = NULL; + } if (GNUNET_SYSERR == - GNUNET_TESTING_peer_stop(p->peer)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Failed to stop peer %u (`%s')\n", - p->no, - GNUNET_i2s(&p->id)); - return GNUNET_SYSERR; - } + GNUNET_TESTING_peer_stop (p->peer)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Failed to stop peer %u (`%s')\n", + p->no, + GNUNET_i2s (&p->id)); + return GNUNET_SYSERR; + } - sleep(5); // YUCK! + sleep (5); // YUCK! - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Restarting peer %u (`%s')\n", - p->no, - GNUNET_i2s(&p->id)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Restarting peer %u (`%s')\n", + p->no, + GNUNET_i2s (&p->id)); /* restart */ - if (GNUNET_SYSERR == GNUNET_TESTING_peer_start(p->peer)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Failed to restart peer %u (`%s')\n", - p->no, - GNUNET_i2s(&p->id)); - return GNUNET_SYSERR; - } + if (GNUNET_SYSERR == GNUNET_TESTING_peer_start (p->peer)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Failed to restart peer %u (`%s')\n", + p->no, + GNUNET_i2s (&p->id)); + return GNUNET_SYSERR; + } - GNUNET_assert(NULL == p->start_cb); + GNUNET_assert (NULL == p->start_cb); p->start_cb = restart_cb; p->start_cb_cls = restart_cb_cls; - p->th = GNUNET_TRANSPORT_core_connect(p->cfg, - NULL, - p->handlers, - p, - ¬ify_connect, - ¬ify_disconnect, - NULL); - GNUNET_assert(NULL != p->th); - p->ats = GNUNET_ATS_connectivity_init(p->cfg); - p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, - GNUNET_TRANSPORT_AC_ANY, - &get_hello, - p); - GNUNET_assert(NULL != p->ghh); + p->th = GNUNET_TRANSPORT_core_connect (p->cfg, + NULL, + p->handlers, + p, + ¬ify_connect, + ¬ify_disconnect, + NULL); + GNUNET_assert (NULL != p->th); + p->ats = GNUNET_ATS_connectivity_init (p->cfg); + p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, + GNUNET_TRANSPORT_AC_ANY, + &get_hello, + p); + GNUNET_assert (NULL != p->ghh); return GNUNET_OK; } @@ -623,75 +632,76 @@ GNUNET_TRANSPORT_TESTING_restart_peer(struct GNUNET_TRANSPORT_TESTING_PeerContex * @param p the peer */ void -GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p) +GNUNET_TRANSPORT_TESTING_stop_peer (struct + GNUNET_TRANSPORT_TESTING_PeerContext *p) { struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; for (cc = tth->cc_head; NULL != cc; cc = ccn) - { - ccn = cc->next; - if ((cc->p1 == p) || - (cc->p2 == p)) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); - } + { + ccn = cc->next; + if ((cc->p1 == p) || + (cc->p2 == p)) + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); + } if (NULL != p->ghh) - { - GNUNET_TRANSPORT_hello_get_cancel(p->ghh); - p->ghh = NULL; - } + { + GNUNET_TRANSPORT_hello_get_cancel (p->ghh); + p->ghh = NULL; + } if (NULL != p->tmh) - { - GNUNET_TRANSPORT_manipulation_disconnect(p->tmh); - p->tmh = NULL; - } + { + GNUNET_TRANSPORT_manipulation_disconnect (p->tmh); + p->tmh = NULL; + } if (NULL != p->th) - { - GNUNET_TRANSPORT_core_disconnect(p->th); - p->th = NULL; - } + { + GNUNET_TRANSPORT_core_disconnect (p->th); + p->th = NULL; + } if (NULL != p->peer) + { + if (GNUNET_OK != + GNUNET_TESTING_peer_stop (p->peer)) { - if (GNUNET_OK != - GNUNET_TESTING_peer_stop(p->peer)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Testing lib failed to stop peer %u (`%s')\n", - p->no, - GNUNET_i2s(&p->id)); - } - GNUNET_TESTING_peer_destroy(p->peer); - p->peer = NULL; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Testing lib failed to stop peer %u (`%s')\n", + p->no, + GNUNET_i2s (&p->id)); } + GNUNET_TESTING_peer_destroy (p->peer); + p->peer = NULL; + } if (NULL != p->ats) - { - GNUNET_ATS_connectivity_done(p->ats); - p->ats = NULL; - } + { + GNUNET_ATS_connectivity_done (p->ats); + p->ats = NULL; + } if (NULL != p->hello) - { - GNUNET_free(p->hello); - p->hello = NULL; - } + { + GNUNET_free (p->hello); + p->hello = NULL; + } if (NULL != p->cfg) - { - GNUNET_CONFIGURATION_destroy(p->cfg); - p->cfg = NULL; - } + { + GNUNET_CONFIGURATION_destroy (p->cfg); + p->cfg = NULL; + } if (NULL != p->handlers) - { - GNUNET_free(p->handlers); - p->handlers = NULL; - } - GNUNET_CONTAINER_DLL_remove(tth->p_head, - tth->p_tail, - p); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') stopped\n", - p->no, - GNUNET_i2s(&p->id)); - GNUNET_free(p); + { + GNUNET_free (p->handlers); + p->handlers = NULL; + } + GNUNET_CONTAINER_DLL_remove (tth->p_head, + tth->p_tail, + p); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Peer %u (`%s') stopped\n", + p->no, + GNUNET_i2s (&p->id)); + GNUNET_free (p); } @@ -700,14 +710,14 @@ GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext * * transport service. */ static void -hello_offered(void *cls) +hello_offered (void *cls) { struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; cc->oh = NULL; - cc->tct = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &offer_hello, - cc); + cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &offer_hello, + cc); } @@ -717,7 +727,7 @@ hello_offered(void *cls) * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest` */ static void -offer_hello(void *cls) +offer_hello (void *cls) { struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1; @@ -725,25 +735,26 @@ offer_hello(void *cls) cc->tct = NULL; { - char *p2_s = GNUNET_strdup(GNUNET_i2s(&p2->id)); - - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n", - p1->no, - GNUNET_i2s(&p1->id), - p2->no, - p2_s, - GNUNET_HELLO_size(cc->p2->hello)); - GNUNET_free(p2_s); + char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id)); + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n", + p1->no, + GNUNET_i2s (&p1->id), + p2->no, + p2_s, + GNUNET_HELLO_size (cc->p2->hello)); + GNUNET_free (p2_s); } if (NULL != cc->oh) - GNUNET_TRANSPORT_offer_hello_cancel(cc->oh); + GNUNET_TRANSPORT_offer_hello_cancel (cc->oh); cc->oh = - GNUNET_TRANSPORT_offer_hello(cc->p1->cfg, - (const struct GNUNET_MessageHeader *)cc->p2->hello, - &hello_offered, - cc); + GNUNET_TRANSPORT_offer_hello (cc->p1->cfg, + (const struct + GNUNET_MessageHeader *) cc->p2->hello, + &hello_offered, + cc); } @@ -760,10 +771,12 @@ offer_hello(void *cls) * @return a connect request handle */ struct GNUNET_TRANSPORT_TESTING_ConnectRequest * -GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, - struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, - GNUNET_SCHEDULER_TaskCallback cb, - void *cls) +GNUNET_TRANSPORT_TESTING_connect_peers (struct + GNUNET_TRANSPORT_TESTING_PeerContext *p1, + struct + GNUNET_TRANSPORT_TESTING_PeerContext *p2, + GNUNET_SCHEDULER_TaskCallback cb, + void *cls) { struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; @@ -771,16 +784,16 @@ GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerConte ccn = NULL; for (cc = tth->cc_head; NULL != cc; cc = cc->next) + { + if ((cc->p1 == p1) && + (cc->p2 == p2)) { - if ((cc->p1 == p1) && - (cc->p2 == p2)) - { - ccn = cc; - break; - } + ccn = cc; + break; } + } - cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest); + cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); cc->p1 = p1; cc->p2 = p2; cc->cb = cb; @@ -789,22 +802,22 @@ GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerConte else cc->cb_cls = cc; if (NULL != ccn) - { - cc->p1_c = ccn->p1_c; - cc->p2_c = ccn->p2_c; - cc->connected = ccn->connected; - } - GNUNET_CONTAINER_DLL_insert(tth->cc_head, - tth->cc_tail, - cc); - cc->tct = GNUNET_SCHEDULER_add_now(&offer_hello, - cc); - cc->ats_sh = GNUNET_ATS_connectivity_suggest(cc->p1->ats, - &p2->id, - 1); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "New connect request %p\n", - cc); + { + cc->p1_c = ccn->p1_c; + cc->p2_c = ccn->p2_c; + cc->connected = ccn->connected; + } + GNUNET_CONTAINER_DLL_insert (tth->cc_head, + tth->cc_tail, + cc); + cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello, + cc); + cc->ats_sh = GNUNET_ATS_connectivity_suggest (cc->p1->ats, + &p2->id, + 1); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New connect request %p\n", + cc); return cc; } @@ -817,31 +830,33 @@ GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerConte * @param cc a connect request handle */ void -GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc) +GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct + GNUNET_TRANSPORT_TESTING_ConnectRequest + *cc) { struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Canceling connect request!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Canceling connect request!\n"); if (NULL != cc->tct) - { - GNUNET_SCHEDULER_cancel(cc->tct); - cc->tct = NULL; - } + { + GNUNET_SCHEDULER_cancel (cc->tct); + cc->tct = NULL; + } if (NULL != cc->oh) - { - GNUNET_TRANSPORT_offer_hello_cancel(cc->oh); - cc->oh = NULL; - } + { + GNUNET_TRANSPORT_offer_hello_cancel (cc->oh); + cc->oh = NULL; + } if (NULL != cc->ats_sh) - { - GNUNET_ATS_connectivity_suggest_cancel(cc->ats_sh); - cc->ats_sh = NULL; - } - GNUNET_CONTAINER_DLL_remove(tth->cc_head, - tth->cc_tail, - cc); - GNUNET_free(cc); + { + GNUNET_ATS_connectivity_suggest_cancel (cc->ats_sh); + cc->ats_sh = NULL; + } + GNUNET_CONTAINER_DLL_remove (tth->cc_head, + tth->cc_tail, + cc); + GNUNET_free (cc); } @@ -851,7 +866,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_Co * @param tth transport testing handle */ void -GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth) +GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth) { struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ct; @@ -862,26 +877,26 @@ GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth) return; cc = tth->cc_head; while (NULL != cc) - { - ct = cc->next; - LOG(GNUNET_ERROR_TYPE_ERROR, - "Developer forgot to cancel connect request!\n"); - GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); - cc = ct; - } + { + ct = cc->next; + LOG (GNUNET_ERROR_TYPE_ERROR, + "Developer forgot to cancel connect request!\n"); + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); + cc = ct; + } p = tth->p_head; while (NULL != p) - { - t = p->next; - LOG(GNUNET_ERROR_TYPE_ERROR, - "Developer forgot to stop peer!\n"); - GNUNET_TRANSPORT_TESTING_stop_peer(p); - p = t; - } - GNUNET_TESTING_system_destroy(tth->tl_system, - GNUNET_YES); + { + t = p->next; + LOG (GNUNET_ERROR_TYPE_ERROR, + "Developer forgot to stop peer!\n"); + GNUNET_TRANSPORT_TESTING_stop_peer (p); + p = t; + } + GNUNET_TESTING_system_destroy (tth->tl_system, + GNUNET_YES); - GNUNET_free(tth); + GNUNET_free (tth); } @@ -891,22 +906,22 @@ GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth) * @return transport testing handle */ struct GNUNET_TRANSPORT_TESTING_Handle * -GNUNET_TRANSPORT_TESTING_init() +GNUNET_TRANSPORT_TESTING_init () { struct GNUNET_TRANSPORT_TESTING_Handle *tth; - tth = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_Handle); - tth->tl_system = GNUNET_TESTING_system_create("transport-testing", - NULL, - NULL, - NULL); + tth = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_Handle); + tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", + NULL, + NULL, + NULL); if (NULL == tth->tl_system) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to initialize testing library!\n"); - GNUNET_free(tth); - return NULL; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to initialize testing library!\n"); + GNUNET_free (tth); + return NULL; + } return tth; } diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index fc39646b2..0f7c51ce5 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h @@ -51,7 +51,8 @@ struct GNUNET_TRANSPORT_TESTING_Handle; /** * Context for a single peer */ -struct GNUNET_TRANSPORT_TESTING_PeerContext { +struct GNUNET_TRANSPORT_TESTING_PeerContext +{ /** * Next element in the DLL */ @@ -152,7 +153,8 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext { /** * Handle for a request to connect two peers. */ -struct GNUNET_TRANSPORT_TESTING_ConnectRequest { +struct GNUNET_TRANSPORT_TESTING_ConnectRequest +{ /** * Kept in a DLL. */ @@ -224,7 +226,8 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest { /** * Handle for a test run. */ -struct GNUNET_TRANSPORT_TESTING_Handle { +struct GNUNET_TRANSPORT_TESTING_Handle +{ /** * Testing library system handle */ @@ -258,7 +261,7 @@ struct GNUNET_TRANSPORT_TESTING_Handle { * @return transport testing handle */ struct GNUNET_TRANSPORT_TESTING_Handle * -GNUNET_TRANSPORT_TESTING_init(void); +GNUNET_TRANSPORT_TESTING_init (void); /** @@ -267,7 +270,7 @@ GNUNET_TRANSPORT_TESTING_init(void); * @param tth transport testing handle */ void -GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth); +GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth); /** @@ -285,7 +288,7 @@ GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth); * @return the peer context */ struct GNUNET_TRANSPORT_TESTING_PeerContext * -GNUNET_TRANSPORT_TESTING_start_peer( +GNUNET_TRANSPORT_TESTING_start_peer ( struct GNUNET_TRANSPORT_TESTING_Handle *tth, const char *cfgname, int peer_id, @@ -303,7 +306,7 @@ GNUNET_TRANSPORT_TESTING_start_peer( * @param p the peer */ void -GNUNET_TRANSPORT_TESTING_stop_peer( +GNUNET_TRANSPORT_TESTING_stop_peer ( struct GNUNET_TRANSPORT_TESTING_PeerContext *pc); @@ -316,7 +319,7 @@ GNUNET_TRANSPORT_TESTING_stop_peer( * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR */ int -GNUNET_TRANSPORT_TESTING_restart_peer( +GNUNET_TRANSPORT_TESTING_restart_peer ( struct GNUNET_TRANSPORT_TESTING_PeerContext *p, GNUNET_SCHEDULER_TaskCallback restart_cb, void *restart_cb_cls); @@ -335,7 +338,7 @@ GNUNET_TRANSPORT_TESTING_restart_peer( * @return a connect request handle */ struct GNUNET_TRANSPORT_TESTING_ConnectRequest * -GNUNET_TRANSPORT_TESTING_connect_peers( +GNUNET_TRANSPORT_TESTING_connect_peers ( struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, GNUNET_SCHEDULER_TaskCallback cb, @@ -350,7 +353,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers( * @param cc a connect request handle */ void -GNUNET_TRANSPORT_TESTING_connect_peers_cancel( +GNUNET_TRANSPORT_TESTING_connect_peers_cancel ( struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); @@ -374,7 +377,7 @@ typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContextCallback) ( * @param cb_cls closure for @a cb */ void -GNUNET_TRANSPORT_TESTING_find_connecting_context( +GNUNET_TRANSPORT_TESTING_find_connecting_context ( struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, @@ -410,7 +413,8 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext; GNUNET_NETWORK_STRUCT_BEGIN -struct GNUNET_TRANSPORT_TESTING_TestMessage { +struct GNUNET_TRANSPORT_TESTING_TestMessage +{ /** * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE. */ @@ -471,7 +475,8 @@ typedef void (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) ( * Closure that must be passed to * #GNUNET_TRANSPORT_TESTING_connect_check. */ -struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext { +struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext +{ /** * How should we continue after the connect? */ @@ -634,7 +639,7 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext { * @return NULL if @a peer was not found */ struct GNUNET_TRANSPORT_TESTING_PeerContext * -GNUNET_TRANSPORT_TESTING_find_peer( +GNUNET_TRANSPORT_TESTING_find_peer ( struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, const struct GNUNET_PeerIdentity *peer); @@ -656,7 +661,7 @@ GNUNET_TRANSPORT_TESTING_find_peer( * @return #GNUNET_SYSERR on error */ int -GNUNET_TRANSPORT_TESTING_connect_check( +GNUNET_TRANSPORT_TESTING_connect_check ( void *cls, struct GNUNET_TRANSPORT_TESTING_Handle *tth_, const char *test_plugin_, @@ -697,11 +702,11 @@ typedef int (*GNUNET_TRANSPORT_TESTING_CheckCallback) ( * @return #GNUNET_OK on success */ int -GNUNET_TRANSPORT_TESTING_main_(const char *argv0, - const char *filename, - unsigned int num_peers, - GNUNET_TRANSPORT_TESTING_CheckCallback check, - void *check_cls); +GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, + const char *filename, + unsigned int num_peers, + GNUNET_TRANSPORT_TESTING_CheckCallback check, + void *check_cls); /** @@ -713,11 +718,11 @@ GNUNET_TRANSPORT_TESTING_main_(const char *argv0, * @return #GNUNET_OK on success */ #define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \ - GNUNET_TRANSPORT_TESTING_main_(argv[0], \ - __FILE__, \ - num_peers, \ - check, \ - check_cls) + GNUNET_TRANSPORT_TESTING_main_ (argv[0], \ + __FILE__, \ + num_peers, \ + check, \ + check_cls) /* ***************** Convenience functions for sending ********* */ @@ -739,7 +744,7 @@ GNUNET_TRANSPORT_TESTING_main_(const char *argv0, * #GNUNET_SYSERR if @a msize is illegal */ int -GNUNET_TRANSPORT_TESTING_send( +GNUNET_TRANSPORT_TESTING_send ( struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, uint16_t mtype, @@ -765,7 +770,8 @@ GNUNET_TRANSPORT_TESTING_send( * #GNUNET_TRANSPORT_TESTING_simple_send() and * #GNUNET_TRANSPORT_TESTING_large_send(). */ -struct GNUNET_TRANSPORT_TESTING_SendClosure { +struct GNUNET_TRANSPORT_TESTING_SendClosure +{ /** * Context for the transmission. */ @@ -805,7 +811,7 @@ struct GNUNET_TRANSPORT_TESTING_SendClosure { * of which should be currently connected */ void -GNUNET_TRANSPORT_TESTING_simple_send(void *cls); +GNUNET_TRANSPORT_TESTING_simple_send (void *cls); /** * Size of a message sent with @@ -823,7 +829,7 @@ GNUNET_TRANSPORT_TESTING_simple_send(void *cls); * of which should be currently connected */ void -GNUNET_TRANSPORT_TESTING_large_send(void *cls); +GNUNET_TRANSPORT_TESTING_large_send (void *cls); /* ********************** log-only convenience functions ************* */ @@ -837,7 +843,7 @@ GNUNET_TRANSPORT_TESTING_large_send(void *cls); * @param other peer that connected. */ void -GNUNET_TRANSPORT_TESTING_log_connect( +GNUNET_TRANSPORT_TESTING_log_connect ( void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other); @@ -851,7 +857,7 @@ GNUNET_TRANSPORT_TESTING_log_connect( * @param other peer that disconnected. */ void -GNUNET_TRANSPORT_TESTING_log_disconnect( +GNUNET_TRANSPORT_TESTING_log_disconnect ( void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other); @@ -868,7 +874,7 @@ GNUNET_TRANSPORT_TESTING_log_disconnect( * @return resulting test name */ char * -GNUNET_TRANSPORT_TESTING_get_test_name(const char *file); +GNUNET_TRANSPORT_TESTING_get_test_name (const char *file); /** @@ -880,7 +886,7 @@ GNUNET_TRANSPORT_TESTING_get_test_name(const char *file); * @return configuration name to use */ char * -GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count); +GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count); /** @@ -890,8 +896,8 @@ GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count); * @return the plugin name */ char * -GNUNET_TRANSPORT_TESTING_get_test_plugin_name(const char *executable, - const char *testname); +GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable, + const char *testname); /** @@ -902,7 +908,7 @@ GNUNET_TRANSPORT_TESTING_get_test_plugin_name(const char *executable, * @return the source name */ char * -GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file); +GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file); #endif /* end of transport_testing.h */ diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c index 6a86f9b84..7204d26da 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c @@ -35,13 +35,14 @@ #include "transport.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-testing2", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__) /** * @brief Handle to a transport communicator */ -struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle { +struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle +{ /** * @brief Handle to the configuration */ @@ -145,7 +146,8 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle { /** * @brief Queue of a communicator and some context */ -struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue { +struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue +{ /** * @brief Handle to the TransportCommunicator */ @@ -205,7 +207,8 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue { /** * @brief Handle/Context to a single transmission */ -struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission { +struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission +{ }; @@ -219,16 +222,16 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission { * @return GNUNET_YES in case message is correct */ static int -check_communicator_available( +check_communicator_available ( void *cls, const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) { uint16_t size; - size = ntohs(msg->header.size) - sizeof(*msg); + size = ntohs (msg->header.size) - sizeof(*msg); if (0 == size) return GNUNET_OK; /* receive-only communicator */ - GNUNET_MQ_check_zero_termination(msg); + GNUNET_MQ_check_zero_termination (msg); return GNUNET_OK; } @@ -242,27 +245,27 @@ check_communicator_available( * @param msg Message struct */ static void -handle_communicator_available( +handle_communicator_available ( void *cls, const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; uint16_t size; - size = ntohs(msg->header.size) - sizeof(*msg); + size = ntohs (msg->header.size) - sizeof(*msg); if (0 == size) return; /* receive-only communicator */ - tc_h->c_characteristics = ntohl(msg->cc); - tc_h->c_addr_prefix = GNUNET_strdup((const char *)&msg[1]); + tc_h->c_characteristics = ntohl (msg->cc); + tc_h->c_addr_prefix = GNUNET_strdup ((const char *) &msg[1]); if (NULL != tc_h->communicator_available_cb) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n"); - tc_h->communicator_available_cb(tc_h->cb_cls, - tc_h, - tc_h->c_characteristics, - tc_h->c_addr_prefix); - } - GNUNET_SERVICE_client_continue(tc_h->client); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n"); + tc_h->communicator_available_cb (tc_h->cb_cls, + tc_h, + tc_h->c_characteristics, + tc_h->c_addr_prefix); + } + GNUNET_SERVICE_client_continue (tc_h->client); } @@ -274,17 +277,17 @@ handle_communicator_available( * @return #GNUNET_OK if message is well-formed */ static int -check_add_address(void *cls, - const struct GNUNET_TRANSPORT_AddAddressMessage *msg) +check_add_address (void *cls, + const struct GNUNET_TRANSPORT_AddAddressMessage *msg) { struct TransportClient *tc = cls; - //if (CT_COMMUNICATOR != tc->type) - //{ + // if (CT_COMMUNICATOR != tc->type) + // { // GNUNET_break (0); // return GNUNET_SYSERR; - //} - GNUNET_MQ_check_zero_termination(msg); + // } + GNUNET_MQ_check_zero_termination (msg); return GNUNET_OK; } @@ -298,27 +301,27 @@ check_add_address(void *cls, * @param msg Message */ static void -handle_add_address(void *cls, - const struct GNUNET_TRANSPORT_AddAddressMessage *msg) +handle_add_address (void *cls, + const struct GNUNET_TRANSPORT_AddAddressMessage *msg) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; uint16_t size; - size = ntohs(msg->header.size) - sizeof(*msg); + size = ntohs (msg->header.size) - sizeof(*msg); if (0 == size) return; /* receive-only communicator */ - tc_h->c_address = GNUNET_strdup((const char *)&msg[1]); + tc_h->c_address = GNUNET_strdup ((const char *) &msg[1]); if (NULL != tc_h->add_address_cb) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available()\n"); - tc_h->add_address_cb(tc_h->cb_cls, - tc_h, - tc_h->c_address, - GNUNET_TIME_relative_ntoh(msg->expiration), - msg->aid, - ntohl(msg->nt)); - } - GNUNET_SERVICE_client_continue(tc_h->client); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available()\n"); + tc_h->add_address_cb (tc_h->cb_cls, + tc_h, + tc_h->c_address, + GNUNET_TIME_relative_ntoh (msg->expiration), + msg->aid, + ntohl (msg->nt)); + } + GNUNET_SERVICE_client_continue (tc_h->client); } @@ -330,17 +333,17 @@ handle_add_address(void *cls, * @return #GNUNET_OK if message is well-formed */ static int -check_incoming_msg(void *cls, - const struct GNUNET_TRANSPORT_IncomingMessage *msg) +check_incoming_msg (void *cls, + const struct GNUNET_TRANSPORT_IncomingMessage *msg) { - //struct TransportClient *tc = cls; + // struct TransportClient *tc = cls; - //if (CT_COMMUNICATOR != tc->type) - //{ + // if (CT_COMMUNICATOR != tc->type) + // { // GNUNET_break (0); // return GNUNET_SYSERR; - //} - GNUNET_MQ_check_boxed_message(msg); + // } + GNUNET_MQ_check_boxed_message (msg); return GNUNET_OK; } @@ -354,23 +357,23 @@ check_incoming_msg(void *cls, * @param msg Message */ static void -handle_incoming_msg(void *cls, - const struct GNUNET_TRANSPORT_IncomingMessage *msg) +handle_incoming_msg (void *cls, + const struct GNUNET_TRANSPORT_IncomingMessage *msg) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; if (NULL != tc_h->incoming_msg_cb) - { - tc_h->incoming_msg_cb(tc_h->cb_cls, - tc_h, - (const struct GNUNET_MessageHeader *)msg); - } + { + tc_h->incoming_msg_cb (tc_h->cb_cls, + tc_h, + (const struct GNUNET_MessageHeader *) msg); + } else - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Incoming message from communicator but no handler!\n"); - } - GNUNET_SERVICE_client_continue(tc_h->client); + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Incoming message from communicator but no handler!\n"); + } + GNUNET_SERVICE_client_continue (tc_h->client); } @@ -381,16 +384,16 @@ handle_incoming_msg(void *cls, * @param msg Message */ static void -handle_queue_create_ok(void *cls, - const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) +handle_queue_create_ok (void *cls, + const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; if (NULL != tc_h->queue_create_reply_cb) - { - tc_h->queue_create_reply_cb(tc_h->cb_cls, tc_h, GNUNET_YES); - } - GNUNET_SERVICE_client_continue(tc_h->client); + { + tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_YES); + } + GNUNET_SERVICE_client_continue (tc_h->client); } @@ -404,17 +407,17 @@ handle_queue_create_ok(void *cls, * @param msg Message */ static void -handle_queue_create_fail( +handle_queue_create_fail ( void *cls, const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; if (NULL != tc_h->queue_create_reply_cb) - { - tc_h->queue_create_reply_cb(tc_h->cb_cls, tc_h, GNUNET_NO); - } - GNUNET_SERVICE_client_continue(tc_h->client); + { + tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_NO); + } + GNUNET_SERVICE_client_continue (tc_h->client); } @@ -425,10 +428,10 @@ handle_queue_create_fail( * @param aqm the send message that was sent */ static int -check_add_queue_message(void *cls, - const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) +check_add_queue_message (void *cls, + const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) { - GNUNET_MQ_check_zero_termination(aqm); + GNUNET_MQ_check_zero_termination (aqm); return GNUNET_OK; } @@ -442,27 +445,27 @@ check_add_queue_message(void *cls, * @param msg Message struct */ static void -handle_add_queue_message(void *cls, - const struct GNUNET_TRANSPORT_AddQueueMessage *msg) +handle_add_queue_message (void *cls, + const struct GNUNET_TRANSPORT_AddQueueMessage *msg) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue; tc_queue = tc_h->queue_head; while (tc_queue->qid != msg->qid) - { - tc_queue = tc_queue->next; - } - GNUNET_assert(tc_queue->qid == msg->qid); - GNUNET_assert(0 == GNUNET_memcmp(&tc_queue->peer_id, &msg->receiver)); + { + tc_queue = tc_queue->next; + } + GNUNET_assert (tc_queue->qid == msg->qid); + GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver)); tc_queue->nt = msg->nt; tc_queue->mtu = msg->mtu; tc_queue->cs = msg->cs; if (NULL != tc_h->add_queue_cb) - { - tc_h->add_queue_cb(tc_h->cb_cls, tc_h, tc_queue); - } - GNUNET_SERVICE_client_continue(tc_h->client); + { + tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue); + } + GNUNET_SERVICE_client_continue (tc_h->client); } @@ -472,11 +475,11 @@ handle_add_queue_message(void *cls, * @param cls Closure - Handle to the service */ static void -shutdown_service(void *cls) +shutdown_service (void *cls) { struct GNUNET_SERVICE_Handle *h = cls; - GNUNET_SERVICE_stop(h); + GNUNET_SERVICE_stop (h); } @@ -490,14 +493,14 @@ shutdown_service(void *cls) * @return TransportCommunicator Handle */ static void * -connect_cb(void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +connect_cb (void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n"); tc_h->client = client; tc_h->c_mq = mq; @@ -505,14 +508,14 @@ connect_cb(void *cls, return tc_h; /* Iterate over queues. They are yet to be opened. Request opening. */ while (NULL != (tc_queue_iter = tc_h->queue_head)) - { - if (NULL == tc_queue_iter->open_queue_env) - continue; - /* Send the previously created mq envelope to request the creation of the - * queue. */ - GNUNET_MQ_send(tc_h->c_mq, tc_queue_iter->open_queue_env); - tc_queue_iter->open_queue_env = NULL; - } + { + if (NULL == tc_queue_iter->open_queue_env) + continue; + /* Send the previously created mq envelope to request the creation of the + * queue. */ + GNUNET_MQ_send (tc_h->c_mq, tc_queue_iter->open_queue_env); + tc_queue_iter->open_queue_env = NULL; + } return tc_h; } @@ -525,13 +528,13 @@ connect_cb(void *cls, * @param internal_cls TransporCommmunicator Handle */ static void -disconnect_cb(void *cls, - struct GNUNET_SERVICE_Client *client, - void *internal_cls) +disconnect_cb (void *cls, + struct GNUNET_SERVICE_Client *client, + void *internal_cls) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n"); tc_h->client = NULL; } @@ -544,66 +547,66 @@ disconnect_cb(void *cls, * @param cfg Configuration */ static void -transport_communicator_start( +transport_communicator_start ( struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) { struct GNUNET_MQ_MessageHandler mh[] = { - GNUNET_MQ_hd_var_size(communicator_available, - GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, - struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, - &tc_h), - //GNUNET_MQ_hd_var_size (communicator_backchannel, + GNUNET_MQ_hd_var_size (communicator_available, + GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, + struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, + &tc_h), + // GNUNET_MQ_hd_var_size (communicator_backchannel, // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, // struct GNUNET_TRANSPORT_CommunicatorBackchannel, // NULL), - GNUNET_MQ_hd_var_size(add_address, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, - struct GNUNET_TRANSPORT_AddAddressMessage, - &tc_h), - //GNUNET_MQ_hd_fixed_size (del_address, + GNUNET_MQ_hd_var_size (add_address, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, + struct GNUNET_TRANSPORT_AddAddressMessage, + &tc_h), + // GNUNET_MQ_hd_fixed_size (del_address, // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, // struct GNUNET_TRANSPORT_DelAddressMessage, // NULL), - GNUNET_MQ_hd_var_size(incoming_msg, - GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, - struct GNUNET_TRANSPORT_IncomingMessage, - NULL), - GNUNET_MQ_hd_fixed_size(queue_create_ok, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, - struct GNUNET_TRANSPORT_CreateQueueResponse, - tc_h), - GNUNET_MQ_hd_fixed_size(queue_create_fail, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, - struct GNUNET_TRANSPORT_CreateQueueResponse, - tc_h), - GNUNET_MQ_hd_var_size(add_queue_message, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, - struct GNUNET_TRANSPORT_AddQueueMessage, - NULL), - //GNUNET_MQ_hd_fixed_size (del_queue_message, + GNUNET_MQ_hd_var_size (incoming_msg, + GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, + struct GNUNET_TRANSPORT_IncomingMessage, + NULL), + GNUNET_MQ_hd_fixed_size (queue_create_ok, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, + struct GNUNET_TRANSPORT_CreateQueueResponse, + tc_h), + GNUNET_MQ_hd_fixed_size (queue_create_fail, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, + struct GNUNET_TRANSPORT_CreateQueueResponse, + tc_h), + GNUNET_MQ_hd_var_size (add_queue_message, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, + struct GNUNET_TRANSPORT_AddQueueMessage, + NULL), + // GNUNET_MQ_hd_fixed_size (del_queue_message, // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, // struct GNUNET_TRANSPORT_DelQueueMessage, // NULL), - //GNUNET_MQ_hd_fixed_size (send_message_ack, + // GNUNET_MQ_hd_fixed_size (send_message_ack, // GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, // struct GNUNET_TRANSPORT_SendMessageToAck, // NULL), }; struct GNUNET_SERVICE_Handle *h; - h = GNUNET_SERVICE_start("transport", - tc_h->cfg, - &connect_cb, - &disconnect_cb, - tc_h, - mh); + h = GNUNET_SERVICE_start ("transport", + tc_h->cfg, + &connect_cb, + &disconnect_cb, + tc_h, + mh); if (NULL == h) - LOG(GNUNET_ERROR_TYPE_ERROR, "Failed starting service!\n"); + LOG (GNUNET_ERROR_TYPE_ERROR, "Failed starting service!\n"); else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Started service\n"); - /* TODO */ GNUNET_SCHEDULER_add_shutdown(&shutdown_service, h); - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Started service\n"); + /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h); + } } @@ -613,21 +616,21 @@ transport_communicator_start( * @param cls Closure - Process of communicator */ static void -shutdown_communicator(void *cls) +shutdown_communicator (void *cls) { struct GNUNET_OS_Process *proc = cls; - if (GNUNET_OK != GNUNET_OS_process_kill(proc, SIGTERM)) + if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGTERM)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Error shutting down communicator with SIGERM, trying SIGKILL\n"); + if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGKILL)) { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Error shutting down communicator with SIGERM, trying SIGKILL\n"); - if (GNUNET_OK != GNUNET_OS_process_kill(proc, SIGKILL)) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Error shutting down communicator with SIGERM and SIGKILL\n"); - } + LOG (GNUNET_ERROR_TYPE_ERROR, + "Error shutting down communicator with SIGERM and SIGKILL\n"); } - GNUNET_OS_process_destroy(proc); + } + GNUNET_OS_process_destroy (proc); } @@ -637,33 +640,33 @@ shutdown_communicator(void *cls) * @param cfgname Name of the communicator */ static void -communicator_start( +communicator_start ( struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, const char *binary_name) { char *binary; - LOG(GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n"); - binary = GNUNET_OS_get_libexec_binary_path(binary_name); - tc_h->c_proc = GNUNET_OS_start_process(GNUNET_YES, - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, - NULL, - NULL, - NULL, - binary, - binary_name, - "-c", - tc_h->cfg_filename, - NULL); + LOG (GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n"); + binary = GNUNET_OS_get_libexec_binary_path (binary_name); + tc_h->c_proc = GNUNET_OS_start_process (GNUNET_YES, + GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + NULL, + NULL, + NULL, + binary, + binary_name, + "-c", + tc_h->cfg_filename, + NULL); if (NULL == tc_h->c_proc) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!"); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "started communicator\n"); - GNUNET_free(binary); - /* TODO */ GNUNET_SCHEDULER_add_shutdown(&shutdown_communicator, - tc_h->c_proc); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!"); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, "started communicator\n"); + GNUNET_free (binary); + /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_communicator, + tc_h->c_proc); } @@ -680,7 +683,7 @@ communicator_start( * @return Handle to the communicator duo */ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * -GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( +GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( const char *service_name, const char *binary_name, const char *cfg_filename, @@ -695,19 +698,19 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; tc_h = - GNUNET_new(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle); - tc_h->cfg_filename = GNUNET_strdup(cfg_filename); - tc_h->cfg = GNUNET_CONFIGURATION_create(); - if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load(tc_h->cfg, cfg_filename))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Malformed configuration file `%s', exit ...\n"), - cfg_filename); - GNUNET_free(tc_h->cfg_filename); - GNUNET_CONFIGURATION_destroy(tc_h->cfg); - GNUNET_free(tc_h); - return NULL; - } + GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle); + tc_h->cfg_filename = GNUNET_strdup (cfg_filename); + tc_h->cfg = GNUNET_CONFIGURATION_create (); + if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load (tc_h->cfg, cfg_filename))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Malformed configuration file `%s', exit ...\n"), + cfg_filename); + GNUNET_free (tc_h->cfg_filename); + GNUNET_CONFIGURATION_destroy (tc_h->cfg); + GNUNET_free (tc_h); + return NULL; + } tc_h->communicator_available_cb = communicator_available_cb; tc_h->add_address_cb = add_address_cb; tc_h->queue_create_reply_cb = queue_create_reply_cb; @@ -716,11 +719,11 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( tc_h->cb_cls = cb_cls; /* Start communicator part of service */ - transport_communicator_start(tc_h); + transport_communicator_start (tc_h); /* Schedule start communicator */ - communicator_start(tc_h, - binary_name); + communicator_start (tc_h, + binary_name); return tc_h; } @@ -733,7 +736,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( * @param address For which address */ void -GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue( +GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue ( struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, const struct GNUNET_PeerIdentity *peer_id, const char *address) @@ -746,33 +749,33 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue( size_t alen; tc_queue = - GNUNET_new(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); + GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); tc_queue->tc_h = tc_h; - prefix = GNUNET_HELLO_address_to_prefix(address); + prefix = GNUNET_HELLO_address_to_prefix (address); if (NULL == prefix) - { - GNUNET_break(0); /* We got an invalid address!? */ - GNUNET_free(tc_queue); - return; - } - GNUNET_free(prefix); - alen = strlen(address) + 1; + { + GNUNET_break (0); /* We got an invalid address!? */ + GNUNET_free (tc_queue); + return; + } + GNUNET_free (prefix); + alen = strlen (address) + 1; env = - GNUNET_MQ_msg_extra(msg, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); - msg->request_id = htonl(idgen++); + GNUNET_MQ_msg_extra (msg, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); + msg->request_id = htonl (idgen++); tc_queue->qid = msg->request_id; msg->receiver = *peer_id; tc_queue->peer_id = *peer_id; - memcpy(&msg[1], address, alen); + memcpy (&msg[1], address, alen); if (NULL != tc_h->c_mq) - { - GNUNET_MQ_send(tc_h->c_mq, env); - } + { + GNUNET_MQ_send (tc_h->c_mq, env); + } else - { - tc_queue->open_queue_env = env; - } - GNUNET_CONTAINER_DLL_insert(tc_h->queue_head, tc_h->queue_tail, tc_queue); + { + tc_queue->open_queue_env = env; + } + GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue); } @@ -800,20 +803,20 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send size_t inbox_size; inbox_size = sizeof(struct GNUNET_MessageHeader) + payload_size; - mh = GNUNET_malloc(inbox_size); - mh->size = htons(inbox_size); + mh = GNUNET_malloc (inbox_size); + mh->size = htons (inbox_size); mh->type = GNUNET_MESSAGE_TYPE_DUMMY; - memcpy(&mh[1], - payload, - payload_size); - env = GNUNET_MQ_msg_extra(msg, - inbox_size, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); - msg->qid = htonl(tc_queue->qid); + memcpy (&mh[1], + payload, + payload_size); + env = GNUNET_MQ_msg_extra (msg, + inbox_size, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); + msg->qid = htonl (tc_queue->qid); msg->mid = tc_queue->mid++; msg->receiver = tc_queue->peer_id; - memcpy(&msg[1], mh, inbox_size); - GNUNET_free(mh); - GNUNET_MQ_send(tc_queue->tc_h->c_mq, env); + memcpy (&msg[1], mh, inbox_size); + GNUNET_free (mh); + GNUNET_MQ_send (tc_queue->tc_h->c_mq, env); return tc_t; } diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h index 8954e20d1..b136be125 100644 --- a/src/transport/transport-testing2.h +++ b/src/transport/transport-testing2.h @@ -59,8 +59,12 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission; */ typedef void (*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, - enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, + struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle + *tc_h, + enum + GNUNET_TRANSPORT_CommunicatorCharacteristics + cc, char *address_prefix); @@ -76,9 +80,12 @@ typedef void */ typedef void (*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, + struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle + *tc_h, const char *address, - struct GNUNET_TIME_Relative expiration, + struct GNUNET_TIME_Relative + expiration, uint32_t aid, enum GNUNET_NetworkType nt); @@ -92,7 +99,9 @@ typedef void */ typedef void (*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, + struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle + *tc_h, int will_try); @@ -105,8 +114,12 @@ typedef void */ typedef void (*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue); + struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle + *tc_h, + struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue + *tc_queue); /** @@ -118,8 +131,11 @@ typedef void */ typedef void (*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls, - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, - const struct GNUNET_MessageHeader *msg); + struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle + *tc_h, + const struct + GNUNET_MessageHeader *msg); /** @@ -138,11 +154,12 @@ typedef void * @return Handle to the communicator duo */ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * -GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( +GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( const char *service_name, const char *binary_name, const char *cfg_filename, - GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb, + GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback + communicator_available_cb, GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, @@ -158,10 +175,13 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( * @param address For which address */ void -GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue - (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, - const struct GNUNET_PeerIdentity *peer_id, - const char *address); +GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle + *tc_h, + const struct + GNUNET_PeerIdentity + *peer_id, + const char *address); /** @@ -174,10 +194,10 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue * @return Handle to the transmission */ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * -GNUNET_TRANSPORT_TESTING_transport_communicator_send - (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue, - const void *payload, - size_t payload_size /*, +GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct + GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue + *tc_queue, + const void *payload, + size_t payload_size /*, GNUNET_TRANSPORT_TESTING_SuccessStatus cb, - void *cb_cls*/); - + void *cb_cls*/ ); diff --git a/src/transport/transport.h b/src/transport/transport.h index 7e2fd4739..36182d8d7 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -55,13 +55,13 @@ * Maximum frequency for re-evaluating latencies for all transport addresses. */ #define LATENCY_EVALUATION_MAX_DELAY \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 1) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1) /** * Maximum frequency for re-evaluating latencies for connected addresses. */ #define CONNECTED_LATENCY_EVALUATION_MAX_DELAY \ - GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) /** * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are @@ -88,7 +88,8 @@ GNUNET_NETWORK_STRUCT_BEGIN * asking to check if both processes agree about this * peers identity. */ -struct StartMessage { +struct StartMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_START */ @@ -113,7 +114,8 @@ struct StartMessage { * Message from the transport service to the library * informing about neighbors. */ -struct ConnectInfoMessage { +struct ConnectInfoMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT */ @@ -144,7 +146,8 @@ struct ConnectInfoMessage { * Message from the transport service to the library * informing about disconnects. */ -struct DisconnectInfoMessage { +struct DisconnectInfoMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT */ @@ -169,7 +172,8 @@ struct DisconnectInfoMessage { * * NOTE: no longer used in TNG! */ -struct QuotaSetMessage { +struct QuotaSetMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA */ @@ -191,7 +195,8 @@ struct QuotaSetMessage { * Message used to notify the transport API about a message * received from the network. The actual message follows. */ -struct InboundMessage { +struct InboundMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV */ @@ -208,7 +213,8 @@ struct InboundMessage { * Message used to notify the transport API that it can * send another message to the transport service. */ -struct SendOkMessage { +struct SendOkMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK */ @@ -251,7 +257,8 @@ struct SendOkMessage { * send another message to the transport service. * (Used to implement flow control.) */ -struct RecvOkMessage { +struct RecvOkMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK */ @@ -274,7 +281,8 @@ struct RecvOkMessage { * Message used to notify the transport service about a message * to be transmitted to another peer. The actual message follows. */ -struct OutboundMessage { +struct OutboundMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND */ @@ -285,7 +293,7 @@ struct OutboundMessage { */ uint32_t priority GNUNET_PACKED; -#if !(defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ +#if ! (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ defined(GNUNET_TRANSPORT_CORE_VERSION)) /** @@ -301,7 +309,7 @@ struct OutboundMessage { }; -#if !(defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ +#if ! (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ defined(GNUNET_TRANSPORT_CORE_VERSION)) @@ -312,7 +320,8 @@ struct OutboundMessage { * last message must have a @e res of #GNUNET_OK and an @e addr_len * of zero. */ -struct AddressToStringResultMessage { +struct AddressToStringResultMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY */ @@ -336,7 +345,8 @@ struct AddressToStringResultMessage { * asking for converting a transport address to a * human-readable UTF-8 string. */ -struct AddressLookupMessage { +struct AddressLookupMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING */ @@ -373,7 +383,8 @@ struct AddressLookupMessage { * Memory layout: * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]] */ -struct ValidationIterateResponseMessage { +struct ValidationIterateResponseMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE */ @@ -433,7 +444,8 @@ struct ValidationIterateResponseMessage { * Message from the library to the transport service * asking for binary addresses known for a peer. */ -struct ValidationMonitorMessage { +struct ValidationMonitorMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST */ @@ -455,7 +467,8 @@ struct ValidationMonitorMessage { * Message from the library to the transport service * asking for binary addresses known for a peer. */ -struct PeerMonitorMessage { +struct PeerMonitorMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST */ @@ -477,7 +490,8 @@ struct PeerMonitorMessage { * Message from the library to the transport service * asking for binary addresses known for a peer. */ -struct TrafficMetricMessage { +struct TrafficMetricMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC */ @@ -520,7 +534,8 @@ struct TrafficMetricMessage { * Memory layout: * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]] */ -struct PeerIterateResponseMessage { +struct PeerIterateResponseMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE */ @@ -567,7 +582,8 @@ struct PeerIterateResponseMessage { * Change in blacklisting (either request or notification, * depending on which direction it is going). */ -struct BlacklistMessage { +struct BlacklistMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY. @@ -590,7 +606,8 @@ struct BlacklistMessage { /** * Transport-level connection status update. */ -struct TransportPluginMonitorMessage { +struct TransportPluginMonitorMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT. */ @@ -663,7 +680,8 @@ struct TransportPluginMonitorMessage { * Communicator goes online. Note which addresses it can * work with. */ -struct GNUNET_TRANSPORT_CommunicatorAvailableMessage { +struct GNUNET_TRANSPORT_CommunicatorAvailableMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR. */ @@ -681,7 +699,8 @@ struct GNUNET_TRANSPORT_CommunicatorAvailableMessage { /** * Add address to the list. */ -struct GNUNET_TRANSPORT_AddAddressMessage { +struct GNUNET_TRANSPORT_AddAddressMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS. */ @@ -709,7 +728,8 @@ struct GNUNET_TRANSPORT_AddAddressMessage { /** * Remove address from the list. */ -struct GNUNET_TRANSPORT_DelAddressMessage { +struct GNUNET_TRANSPORT_DelAddressMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS. */ @@ -725,7 +745,8 @@ struct GNUNET_TRANSPORT_DelAddressMessage { /** * Inform transport about an incoming message. */ -struct GNUNET_TRANSPORT_IncomingMessage { +struct GNUNET_TRANSPORT_IncomingMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG. */ @@ -760,7 +781,8 @@ struct GNUNET_TRANSPORT_IncomingMessage { * Transport informs us about being done with an incoming message. * (only sent if fc_on was set). */ -struct GNUNET_TRANSPORT_IncomingMessageAck { +struct GNUNET_TRANSPORT_IncomingMessageAck +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK. */ @@ -786,7 +808,8 @@ struct GNUNET_TRANSPORT_IncomingMessageAck { /** * Add queue to the transport */ -struct GNUNET_TRANSPORT_AddQueueMessage { +struct GNUNET_TRANSPORT_AddQueueMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP. */ @@ -824,7 +847,8 @@ struct GNUNET_TRANSPORT_AddQueueMessage { /** * Remove queue, it is no longer available. */ -struct GNUNET_TRANSPORT_DelQueueMessage { +struct GNUNET_TRANSPORT_DelQueueMessage +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN. */ @@ -845,7 +869,8 @@ struct GNUNET_TRANSPORT_DelQueueMessage { /** * Transport tells communicator that it wants a new queue. */ -struct GNUNET_TRANSPORT_CreateQueue { +struct GNUNET_TRANSPORT_CreateQueue +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE. */ @@ -868,7 +893,8 @@ struct GNUNET_TRANSPORT_CreateQueue { /** * Communicator tells transport how queue creation went down. */ -struct GNUNET_TRANSPORT_CreateQueueResponse { +struct GNUNET_TRANSPORT_CreateQueueResponse +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK or * #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL. @@ -885,7 +911,8 @@ struct GNUNET_TRANSPORT_CreateQueueResponse { /** * Inform communicator about transport's desire to send a message. */ -struct GNUNET_TRANSPORT_SendMessageTo { +struct GNUNET_TRANSPORT_SendMessageTo +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG. */ @@ -913,7 +940,8 @@ struct GNUNET_TRANSPORT_SendMessageTo { /** * Inform transport that message was sent. */ -struct GNUNET_TRANSPORT_SendMessageToAck { +struct GNUNET_TRANSPORT_SendMessageToAck +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK. */ @@ -941,7 +969,8 @@ struct GNUNET_TRANSPORT_SendMessageToAck { * transmission of a backchannel message with the given peer @e pid * and communicator. */ -struct GNUNET_TRANSPORT_CommunicatorBackchannel { +struct GNUNET_TRANSPORT_CommunicatorBackchannel +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL */ @@ -969,7 +998,8 @@ struct GNUNET_TRANSPORT_CommunicatorBackchannel { * Message from transport to communicator passing along a backchannel * message from the given peer @e pid. */ -struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming { +struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming +{ /** * Type will be * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING @@ -994,7 +1024,8 @@ struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming { /** * Request to start monitoring. */ -struct GNUNET_TRANSPORT_MonitorStart { +struct GNUNET_TRANSPORT_MonitorStart +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START. */ @@ -1015,7 +1046,8 @@ struct GNUNET_TRANSPORT_MonitorStart { /** * Monitoring data. */ -struct GNUNET_TRANSPORT_MonitorData { +struct GNUNET_TRANSPORT_MonitorData +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA. */ @@ -1065,7 +1097,8 @@ struct GNUNET_TRANSPORT_MonitorData { /** * Request to verify address. */ -struct GNUNET_TRANSPORT_AddressToVerify { +struct GNUNET_TRANSPORT_AddressToVerify +{ /** * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY. */ @@ -1089,7 +1122,8 @@ struct GNUNET_TRANSPORT_AddressToVerify { * Application client to TRANSPORT service: we would like to have * address suggestions for this peer. */ -struct ExpressPreferenceMessage { +struct ExpressPreferenceMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST or * #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL to stop @@ -1119,7 +1153,8 @@ struct ExpressPreferenceMessage { * We got an address of another peer, TRANSPORT service * should validate it. There is no response. */ -struct RequestHelloValidationMessage { +struct RequestHelloValidationMessage +{ /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION. */ diff --git a/src/transport/transport_api2_application.c b/src/transport/transport_api2_application.c index 8ddf48a86..4862863dd 100644 --- a/src/transport/transport_api2_application.c +++ b/src/transport/transport_api2_application.c @@ -30,13 +30,14 @@ #define LOG(kind, ...) \ - GNUNET_log_from(kind, "transport-application-api", __VA_ARGS__) + GNUNET_log_from (kind, "transport-application-api", __VA_ARGS__) /** * Handle for TRANSPORT address suggestion requests. */ -struct GNUNET_TRANSPORT_ApplicationSuggestHandle { +struct GNUNET_TRANSPORT_ApplicationSuggestHandle +{ /** * ID of the peer for which address suggestion was requested. */ @@ -62,7 +63,8 @@ struct GNUNET_TRANSPORT_ApplicationSuggestHandle { /** * Handle to the TRANSPORT subsystem for application management. */ -struct GNUNET_TRANSPORT_ApplicationHandle { +struct GNUNET_TRANSPORT_ApplicationHandle +{ /** * Our configuration. */ @@ -98,7 +100,7 @@ struct GNUNET_TRANSPORT_ApplicationHandle { * @param ch handle to use to re-connect. */ static void -reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch); +reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch); /** @@ -107,12 +109,12 @@ reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch); * @param cls handle to use to re-connect. */ static void -reconnect_task(void *cls) +reconnect_task (void *cls) { struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; ch->task = NULL; - reconnect(ch); + reconnect (ch); } @@ -122,15 +124,15 @@ reconnect_task(void *cls) * @param ch our handle */ static void -force_reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch) +force_reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch) { if (NULL != ch->mq) - { - GNUNET_MQ_destroy(ch->mq); - ch->mq = NULL; - } - ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff); - ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff, &reconnect_task, ch); + { + GNUNET_MQ_destroy (ch->mq); + ch->mq = NULL; + } + ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff); + ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, &reconnect_task, ch); } @@ -142,14 +144,14 @@ force_reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch) * @param error details about the error */ static void -error_handler(void *cls, enum GNUNET_MQ_Error error) +error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "TRANSPORT connection died (code %d), reconnecting\n", - (int)error); - force_reconnect(ch); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "TRANSPORT connection died (code %d), reconnecting\n", + (int) error); + force_reconnect (ch); } @@ -163,9 +165,9 @@ error_handler(void *cls, enum GNUNET_MQ_Error error) * failure (message queue no longer exists) */ static int -transmit_suggestion(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +transmit_suggestion (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh = value; @@ -174,11 +176,11 @@ transmit_suggestion(void *cls, if (NULL == ch->mq) return GNUNET_SYSERR; - ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST); - m->pk = htonl((uint32_t)sh->pk); + ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST); + m->pk = htonl ((uint32_t) sh->pk); m->bw = sh->bw; m->peer = *peer; - GNUNET_MQ_send(ch->mq, ev); + GNUNET_MQ_send (ch->mq, ev); return GNUNET_OK; } @@ -189,21 +191,21 @@ transmit_suggestion(void *cls, * @param ch handle to use to re-connect. */ static void -reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch) +reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch) { static const struct GNUNET_MQ_MessageHandler handlers[] = { { NULL, 0, 0 } }; - GNUNET_assert(NULL == ch->mq); + GNUNET_assert (NULL == ch->mq); ch->mq = - GNUNET_CLIENT_connect(ch->cfg, "transport", handlers, &error_handler, ch); + GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch); if (NULL == ch->mq) - { - force_reconnect(ch); - return; - } - GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, - &transmit_suggestion, - ch); + { + force_reconnect (ch); + return; + } + GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, + &transmit_suggestion, + ch); } @@ -214,15 +216,15 @@ reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch) * @return transport application handle, NULL on error */ struct GNUNET_TRANSPORT_ApplicationHandle * -GNUNET_TRANSPORT_application_init( +GNUNET_TRANSPORT_application_init ( const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_TRANSPORT_ApplicationHandle *ch; - ch = GNUNET_new(struct GNUNET_TRANSPORT_ApplicationHandle); + ch = GNUNET_new (struct GNUNET_TRANSPORT_ApplicationHandle); ch->cfg = cfg; - ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES); - reconnect(ch); + ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); + reconnect (ch); return ch; } @@ -237,11 +239,11 @@ GNUNET_TRANSPORT_application_init( * @return #GNUNET_OK (continue to iterate) */ static int -free_sug_handle(void *cls, const struct GNUNET_PeerIdentity *key, void *value) +free_sug_handle (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { struct GNUNET_TRANSPORT_ApplicationSuggestHandle *cur = value; - GNUNET_free(cur); + GNUNET_free (cur); return GNUNET_OK; } @@ -252,24 +254,24 @@ free_sug_handle(void *cls, const struct GNUNET_PeerIdentity *key, void *value) * @param ch handle to release */ void -GNUNET_TRANSPORT_application_done( +GNUNET_TRANSPORT_application_done ( struct GNUNET_TRANSPORT_ApplicationHandle *ch) { if (NULL != ch->mq) - { - GNUNET_MQ_destroy(ch->mq); - ch->mq = NULL; - } + { + GNUNET_MQ_destroy (ch->mq); + ch->mq = NULL; + } if (NULL != ch->task) - { - GNUNET_SCHEDULER_cancel(ch->task); - ch->task = NULL; - } - GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, - &free_sug_handle, - NULL); - GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests); - GNUNET_free(ch); + { + GNUNET_SCHEDULER_cancel (ch->task); + ch->task = NULL; + } + GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, + &free_sug_handle, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests); + GNUNET_free (ch); } @@ -284,7 +286,7 @@ GNUNET_TRANSPORT_application_done( * @return suggest handle, NULL if a request is already pending */ struct GNUNET_TRANSPORT_ApplicationSuggestHandle * -GNUNET_TRANSPORT_application_suggest( +GNUNET_TRANSPORT_application_suggest ( struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_MQ_PriorityPreferences pk, @@ -292,22 +294,22 @@ GNUNET_TRANSPORT_application_suggest( { struct GNUNET_TRANSPORT_ApplicationSuggestHandle *s; - s = GNUNET_new(struct GNUNET_TRANSPORT_ApplicationSuggestHandle); + s = GNUNET_new (struct GNUNET_TRANSPORT_ApplicationSuggestHandle); s->ch = ch; s->id = *peer; s->pk = pk; s->bw = bw; - (void)GNUNET_CONTAINER_multipeermap_put( + (void) GNUNET_CONTAINER_multipeermap_put ( ch->sug_requests, &s->id, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Requesting TRANSPORT to suggest address for `%s'\n", - GNUNET_i2s(peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Requesting TRANSPORT to suggest address for `%s'\n", + GNUNET_i2s (peer)); if (NULL == ch->mq) return s; - GNUNET_assert(GNUNET_OK == transmit_suggestion(ch, &s->id, s)); + GNUNET_assert (GNUNET_OK == transmit_suggestion (ch, &s->id, s)); return s; } @@ -318,30 +320,30 @@ GNUNET_TRANSPORT_application_suggest( * @param sh handle to stop */ void -GNUNET_TRANSPORT_application_suggest_cancel( +GNUNET_TRANSPORT_application_suggest_cancel ( struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh) { struct GNUNET_TRANSPORT_ApplicationHandle *ch = sh->ch; struct GNUNET_MQ_Envelope *ev; struct ExpressPreferenceMessage *m; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Telling TRANSPORT we no longer care for an address for `%s'\n", - GNUNET_i2s(&sh->id)); - GNUNET_assert( + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Telling TRANSPORT we no longer care for an address for `%s'\n", + GNUNET_i2s (&sh->id)); + GNUNET_assert ( GNUNET_OK == - GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests, &sh->id, sh)); + GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, &sh->id, sh)); if (NULL == ch->mq) - { - GNUNET_free(sh); - return; - } - ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL); - m->pk = htonl((uint32_t)sh->pk); + { + GNUNET_free (sh); + return; + } + ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL); + m->pk = htonl ((uint32_t) sh->pk); m->bw = sh->bw; m->peer = sh->id; - GNUNET_MQ_send(ch->mq, ev); - GNUNET_free(sh); + GNUNET_MQ_send (ch->mq, ev); + GNUNET_free (sh); } @@ -361,7 +363,7 @@ GNUNET_TRANSPORT_application_suggest_cancel( * @param addr address to validate */ void -GNUNET_TRANSPORT_application_validate( +GNUNET_TRANSPORT_application_validate ( struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_NetworkType nt, @@ -372,23 +374,23 @@ GNUNET_TRANSPORT_application_validate( size_t alen; if (NULL == ch->mq) - { - GNUNET_log( - GNUNET_ERROR_TYPE_WARNING, - "Address validation for %s:%s skipped as transport is not connected\n", - GNUNET_i2s(peer), - addr); - return; - } - alen = strlen(addr) + 1; + { + GNUNET_log ( + GNUNET_ERROR_TYPE_WARNING, + "Address validation for %s:%s skipped as transport is not connected\n", + GNUNET_i2s (peer), + addr); + return; + } + alen = strlen (addr) + 1; ev = - GNUNET_MQ_msg_extra(m, - alen, - GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION); + GNUNET_MQ_msg_extra (m, + alen, + GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION); m->peer = *peer; - m->nt = htonl((uint32_t)nt); - memcpy(&m[1], addr, alen); - GNUNET_MQ_send(ch->mq, ev); + m->nt = htonl ((uint32_t) nt); + memcpy (&m[1], addr, alen); + GNUNET_MQ_send (ch->mq, ev); } diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c index f9c387a87..de5b42c3f 100644 --- a/src/transport/transport_api2_communication.c +++ b/src/transport/transport_api2_communication.c @@ -42,7 +42,8 @@ /** * Information we track per packet to enable flow control. */ -struct FlowControl { +struct FlowControl +{ /** * Kept in a DLL. */ @@ -79,7 +80,8 @@ struct FlowControl { * Information we track per message to tell the transport about * success or failures. */ -struct AckPending { +struct AckPending +{ /** * Kept in a DLL. */ @@ -110,7 +112,8 @@ struct AckPending { /** * Opaque handle to the transport service for communicators. */ -struct GNUNET_TRANSPORT_CommunicatorHandle { +struct GNUNET_TRANSPORT_CommunicatorHandle +{ /** * Head of DLL of addresses this communicator offers to the transport service. */ @@ -226,7 +229,8 @@ struct GNUNET_TRANSPORT_CommunicatorHandle { * Handle returned to identify the internal data structure the transport * API has created to manage a message queue to a particular peer. */ -struct GNUNET_TRANSPORT_QueueHandle { +struct GNUNET_TRANSPORT_QueueHandle +{ /** * Kept in a DLL. */ @@ -283,7 +287,8 @@ struct GNUNET_TRANSPORT_QueueHandle { * Internal representation of an address a communicator is * currently providing for the transport service. */ -struct GNUNET_TRANSPORT_AddressIdentifier { +struct GNUNET_TRANSPORT_AddressIdentifier +{ /** * Kept in a DLL. */ @@ -329,7 +334,7 @@ struct GNUNET_TRANSPORT_AddressIdentifier { * @param ch handle to reconnect */ static void -reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch); +reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch); /** @@ -339,20 +344,20 @@ reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch); * @param ai address to add */ static void -send_add_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai) +send_add_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_AddAddressMessage *aam; if (NULL == ai->ch->mq) return; - env = GNUNET_MQ_msg_extra(aam, - strlen(ai->address) + 1, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS); - aam->expiration = GNUNET_TIME_relative_hton(ai->expiration); - aam->nt = htonl((uint32_t)ai->nt); - memcpy(&aam[1], ai->address, strlen(ai->address) + 1); - GNUNET_MQ_send(ai->ch->mq, env); + env = GNUNET_MQ_msg_extra (aam, + strlen (ai->address) + 1, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS); + aam->expiration = GNUNET_TIME_relative_hton (ai->expiration); + aam->nt = htonl ((uint32_t) ai->nt); + memcpy (&aam[1], ai->address, strlen (ai->address) + 1); + GNUNET_MQ_send (ai->ch->mq, env); } @@ -363,16 +368,16 @@ send_add_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai) * @param ai address to delete */ static void -send_del_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai) +send_del_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_DelAddressMessage *dam; if (NULL == ai->ch->mq) return; - env = GNUNET_MQ_msg(dam, GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS); - dam->aid = htonl(ai->aid); - GNUNET_MQ_send(ai->ch->mq, env); + env = GNUNET_MQ_msg (dam, GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS); + dam->aid = htonl (ai->aid); + GNUNET_MQ_send (ai->ch->mq, env); } @@ -383,23 +388,23 @@ send_del_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai) * @param qh queue to add */ static void -send_add_queue(struct GNUNET_TRANSPORT_QueueHandle *qh) +send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_AddQueueMessage *aqm; if (NULL == qh->ch->mq) return; - env = GNUNET_MQ_msg_extra(aqm, - strlen(qh->address) + 1, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP); - aqm->qid = htonl(qh->queue_id); + env = GNUNET_MQ_msg_extra (aqm, + strlen (qh->address) + 1, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP); + aqm->qid = htonl (qh->queue_id); aqm->receiver = qh->peer; - aqm->nt = htonl((uint32_t)qh->nt); - aqm->mtu = htonl(qh->mtu); - aqm->cs = htonl((uint32_t)qh->cs); - memcpy(&aqm[1], qh->address, strlen(qh->address) + 1); - GNUNET_MQ_send(qh->ch->mq, env); + aqm->nt = htonl ((uint32_t) qh->nt); + aqm->mtu = htonl (qh->mtu); + aqm->cs = htonl ((uint32_t) qh->cs); + memcpy (&aqm[1], qh->address, strlen (qh->address) + 1); + GNUNET_MQ_send (qh->ch->mq, env); } @@ -410,17 +415,17 @@ send_add_queue(struct GNUNET_TRANSPORT_QueueHandle *qh) * @param qh queue to delete */ static void -send_del_queue(struct GNUNET_TRANSPORT_QueueHandle *qh) +send_del_queue (struct GNUNET_TRANSPORT_QueueHandle *qh) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_DelQueueMessage *dqm; if (NULL == qh->ch->mq) return; - env = GNUNET_MQ_msg(dqm, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN); - dqm->qid = htonl(qh->queue_id); + env = GNUNET_MQ_msg (dqm, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN); + dqm->qid = htonl (qh->queue_id); dqm->receiver = qh->peer; - GNUNET_MQ_send(qh->ch->mq, env); + GNUNET_MQ_send (qh->ch->mq, env); } @@ -433,27 +438,27 @@ send_del_queue(struct GNUNET_TRANSPORT_QueueHandle *qh) * @param ch service to disconnect from */ static void -disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch) +disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) { struct FlowControl *fcn; struct AckPending *apn; for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fcn) - { - fcn = fc->next; - GNUNET_CONTAINER_DLL_remove(ch->fc_head, ch->fc_tail, fc); - fc->cb(fc->cb_cls, GNUNET_SYSERR); - GNUNET_free(fc); - } + { + fcn = fc->next; + GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc); + fc->cb (fc->cb_cls, GNUNET_SYSERR); + GNUNET_free (fc); + } for (struct AckPending *ap = ch->ap_head; NULL != ap; ap = apn) - { - apn = ap->next; - GNUNET_CONTAINER_DLL_remove(ch->ap_head, ch->ap_tail, ap); - GNUNET_free(ap); - } + { + apn = ap->next; + GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap); + GNUNET_free (ap); + } if (NULL == ch->mq) return; - GNUNET_MQ_destroy(ch->mq); + GNUNET_MQ_destroy (ch->mq); ch->mq = NULL; } @@ -462,16 +467,16 @@ disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch) * Function called on MQ errors. */ static void -error_handler(void *cls, enum GNUNET_MQ_Error error) +error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "MQ failure %d, reconnecting to transport service.\n", - error); - disconnect(ch); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "MQ failure %d, reconnecting to transport service.\n", + error); + disconnect (ch); /* TODO: maybe do this with exponential backoff/delay */ - reconnect(ch); + reconnect (ch); } @@ -483,29 +488,29 @@ error_handler(void *cls, enum GNUNET_MQ_Error error) * @param incoming_ack the ack */ static void -handle_incoming_ack( +handle_incoming_ack ( void *cls, const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fc->next) + { + if ((fc->id == incoming_ack->fc_id) && + (0 == memcmp (&fc->sender, + &incoming_ack->sender, + sizeof(struct GNUNET_PeerIdentity)))) { - if ((fc->id == incoming_ack->fc_id) && - (0 == memcmp(&fc->sender, - &incoming_ack->sender, - sizeof(struct GNUNET_PeerIdentity)))) - { - GNUNET_CONTAINER_DLL_remove(ch->fc_head, ch->fc_tail, fc); - fc->cb(fc->cb_cls, GNUNET_OK); - GNUNET_free(fc); - return; - } + GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc); + fc->cb (fc->cb_cls, GNUNET_OK); + GNUNET_free (fc); + return; } - GNUNET_break(0); - disconnect(ch); + } + GNUNET_break (0); + disconnect (ch); /* TODO: maybe do this with exponential backoff/delay */ - reconnect(ch); + reconnect (ch); } @@ -518,10 +523,10 @@ handle_incoming_ack( * @return #GNUNET_OK if @a smt is well-formed */ static int -check_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) +check_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) { - (void)cls; - GNUNET_MQ_check_zero_termination(cq); + (void) cls; + GNUNET_MQ_check_zero_termination (cq); return GNUNET_OK; } @@ -533,26 +538,26 @@ check_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) * @param cq the queue creation request */ static void -handle_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) +handle_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; - const char *addr = (const char *)&cq[1]; + const char *addr = (const char *) &cq[1]; struct GNUNET_TRANSPORT_CreateQueueResponse *cqr; struct GNUNET_MQ_Envelope *env; - if (GNUNET_OK != ch->mq_init(ch->mq_init_cls, &cq->receiver, addr)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Address `%s' invalid for this communicator\n", - addr); - env = GNUNET_MQ_msg(cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL); - } + if (GNUNET_OK != ch->mq_init (ch->mq_init_cls, &cq->receiver, addr)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Address `%s' invalid for this communicator\n", + addr); + env = GNUNET_MQ_msg (cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL); + } else - { - env = GNUNET_MQ_msg(cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK); - } + { + env = GNUNET_MQ_msg (cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK); + } cqr->request_id = cq->request_id; - GNUNET_MQ_send(ch->mq, env); + GNUNET_MQ_send (ch->mq, env); } @@ -565,10 +570,10 @@ handle_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) * @return #GNUNET_OK if @a smt is well-formed */ static int -check_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) +check_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) { - (void)cls; - GNUNET_MQ_check_boxed_message(smt); + (void) cls; + GNUNET_MQ_check_boxed_message (smt); return GNUNET_OK; } @@ -583,19 +588,19 @@ check_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) * @param mid message that the ack is about */ static void -send_ack(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, - int status, - const struct GNUNET_PeerIdentity *receiver, - uint64_t mid) +send_ack (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, + int status, + const struct GNUNET_PeerIdentity *receiver, + uint64_t mid) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_SendMessageToAck *ack; - env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK); - ack->status = htonl(status); + env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK); + ack->status = htonl (status); ack->mid = mid; ack->receiver = *receiver; - GNUNET_MQ_send(ch->mq, env); + GNUNET_MQ_send (ch->mq, env); } @@ -606,14 +611,14 @@ send_ack(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, * @param cls an `struct AckPending *` */ static void -send_ack_cb(void *cls) +send_ack_cb (void *cls) { struct AckPending *ap = cls; struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ap->ch; - GNUNET_CONTAINER_DLL_remove(ch->ap_head, ch->ap_tail, ap); - send_ack(ch, GNUNET_OK, &ap->receiver, ap->mid); - GNUNET_free(ap); + GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap); + send_ack (ch, GNUNET_OK, &ap->receiver, ap->mid); + GNUNET_free (ap); } @@ -624,7 +629,7 @@ send_ack_cb(void *cls) * @param smt the transmission request */ static void -handle_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) +handle_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; const struct GNUNET_MessageHeader *mh; @@ -634,27 +639,27 @@ handle_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) for (qh = ch->queue_head; NULL != qh; qh = qh->next) if ((qh->queue_id == smt->qid) && - (0 == memcmp(&qh->peer, - &smt->receiver, - sizeof(struct GNUNET_PeerIdentity)))) + (0 == memcmp (&qh->peer, + &smt->receiver, + sizeof(struct GNUNET_PeerIdentity)))) break; if (NULL == qh) - { - /* queue is already gone, tell transport this one failed */ - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Transmission failed, queue no longer exists.\n"); - send_ack(ch, GNUNET_NO, &smt->receiver, smt->mid); - return; - } - ap = GNUNET_new(struct AckPending); + { + /* queue is already gone, tell transport this one failed */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Transmission failed, queue no longer exists.\n"); + send_ack (ch, GNUNET_NO, &smt->receiver, smt->mid); + return; + } + ap = GNUNET_new (struct AckPending); ap->ch = ch; ap->receiver = smt->receiver; ap->mid = smt->mid; - GNUNET_CONTAINER_DLL_insert(ch->ap_head, ch->ap_tail, ap); - mh = (const struct GNUNET_MessageHeader *)&smt[1]; - env = GNUNET_MQ_msg_copy(mh); - GNUNET_MQ_notify_sent(env, &send_ack_cb, ap); - GNUNET_MQ_send(qh->mq, env); + GNUNET_CONTAINER_DLL_insert (ch->ap_head, ch->ap_tail, ap); + mh = (const struct GNUNET_MessageHeader *) &smt[1]; + env = GNUNET_MQ_msg_copy (mh); + GNUNET_MQ_notify_sent (env, &send_ack_cb, ap); + GNUNET_MQ_send (qh->mq, env); } @@ -667,12 +672,12 @@ handle_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) * @return #GNUNET_OK if @a smt is well-formed */ static int -check_backchannel_incoming( +check_backchannel_incoming ( void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi) { - (void)cls; - GNUNET_MQ_check_boxed_message(bi); + (void) cls; + GNUNET_MQ_check_boxed_message (bi); return GNUNET_OK; } @@ -684,20 +689,20 @@ check_backchannel_incoming( * @param bi the backchannel message */ static void -handle_backchannel_incoming( +handle_backchannel_incoming ( void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; if (NULL != ch->notify_cb) - ch->notify_cb(ch->notify_cb_cls, - &bi->pid, - (const struct GNUNET_MessageHeader *)&bi[1]); + ch->notify_cb (ch->notify_cb_cls, + &bi->pid, + (const struct GNUNET_MessageHeader *) &bi[1]); else - GNUNET_log( + GNUNET_log ( GNUNET_ERROR_TYPE_INFO, - _("Dropped backchanel message: handler not provided by communicator\n")); + _ ("Dropped backchanel message: handler not provided by communicator\n")); } @@ -707,46 +712,46 @@ handle_backchannel_incoming( * @param ch handle to reconnect */ static void -reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch) +reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) { struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_fixed_size(incoming_ack, - GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK, - struct GNUNET_TRANSPORT_IncomingMessageAck, - ch), - GNUNET_MQ_hd_var_size(create_queue, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE, - struct GNUNET_TRANSPORT_CreateQueue, - ch), - GNUNET_MQ_hd_var_size(send_msg, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG, - struct GNUNET_TRANSPORT_SendMessageTo, - ch), - GNUNET_MQ_hd_var_size( + { GNUNET_MQ_hd_fixed_size (incoming_ack, + GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK, + struct GNUNET_TRANSPORT_IncomingMessageAck, + ch), + GNUNET_MQ_hd_var_size (create_queue, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE, + struct GNUNET_TRANSPORT_CreateQueue, + ch), + GNUNET_MQ_hd_var_size (send_msg, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG, + struct GNUNET_TRANSPORT_SendMessageTo, + ch), + GNUNET_MQ_hd_var_size ( backchannel_incoming, GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING, struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming, ch), - GNUNET_MQ_handler_end() }; + GNUNET_MQ_handler_end () }; struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam; struct GNUNET_MQ_Envelope *env; ch->mq = - GNUNET_CLIENT_connect(ch->cfg, "transport", handlers, &error_handler, ch); + GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch); if (NULL == ch->mq) return; - env = GNUNET_MQ_msg_extra(cam, - strlen(ch->addr_prefix) + 1, - GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR); - cam->cc = htonl((uint32_t)ch->cc); - memcpy(&cam[1], ch->addr_prefix, strlen(ch->addr_prefix) + 1); - GNUNET_MQ_send(ch->mq, env); + env = GNUNET_MQ_msg_extra (cam, + strlen (ch->addr_prefix) + 1, + GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR); + cam->cc = htonl ((uint32_t) ch->cc); + memcpy (&cam[1], ch->addr_prefix, strlen (ch->addr_prefix) + 1); + GNUNET_MQ_send (ch->mq, env); for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai; ai = ai->next) - send_add_address(ai); + send_add_address (ai); for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; NULL != qh; qh = qh->next) - send_add_queue(qh); + send_add_queue (qh); } @@ -769,7 +774,7 @@ reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch) * @return NULL on error */ struct GNUNET_TRANSPORT_CommunicatorHandle * -GNUNET_TRANSPORT_communicator_connect( +GNUNET_TRANSPORT_communicator_connect ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, const char *addr_prefix, @@ -781,7 +786,7 @@ GNUNET_TRANSPORT_communicator_connect( { struct GNUNET_TRANSPORT_CommunicatorHandle *ch; - ch = GNUNET_new(struct GNUNET_TRANSPORT_CommunicatorHandle); + ch = GNUNET_new (struct GNUNET_TRANSPORT_CommunicatorHandle); ch->cfg = cfg; ch->config_section = config_section; ch->addr_prefix = addr_prefix; @@ -790,18 +795,18 @@ GNUNET_TRANSPORT_communicator_connect( ch->notify_cb = notify_cb; ch->notify_cb_cls = notify_cb_cls; ch->cc = cc; - reconnect(ch); + reconnect (ch); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number(cfg, - config_section, - "MAX_QUEUE_LENGTH", - &ch->max_queue_length)) + GNUNET_CONFIGURATION_get_value_number (cfg, + config_section, + "MAX_QUEUE_LENGTH", + &ch->max_queue_length)) ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; if (NULL == ch->mq) - { - GNUNET_free(ch); - return NULL; - } + { + GNUNET_free (ch); + return NULL; + } return ch; } @@ -812,16 +817,16 @@ GNUNET_TRANSPORT_communicator_connect( * @param ch handle returned from connect */ void -GNUNET_TRANSPORT_communicator_disconnect( +GNUNET_TRANSPORT_communicator_disconnect ( struct GNUNET_TRANSPORT_CommunicatorHandle *ch) { - disconnect(ch); + disconnect (ch); while (NULL != ch->ai_head) - { - GNUNET_break(0); /* communicator forgot to remove address, warn! */ - GNUNET_TRANSPORT_communicator_address_remove(ch->ai_head); - } - GNUNET_free(ch); + { + GNUNET_break (0); /* communicator forgot to remove address, warn! */ + GNUNET_TRANSPORT_communicator_address_remove (ch->ai_head); + } + GNUNET_free (ch); } @@ -849,7 +854,7 @@ GNUNET_TRANSPORT_communicator_disconnect( * the tranport service is not yet up */ int -GNUNET_TRANSPORT_communicator_receive( +GNUNET_TRANSPORT_communicator_receive ( struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, @@ -863,41 +868,41 @@ GNUNET_TRANSPORT_communicator_receive( if (NULL == ch->mq) return GNUNET_SYSERR; - if ((NULL == cb) && (GNUNET_MQ_get_length(ch->mq) >= ch->max_queue_length)) - { - GNUNET_log( - GNUNET_ERROR_TYPE_WARNING, - "Dropping message: transprot is too slow, queue length %llu exceeded\n", - ch->max_queue_length); - return GNUNET_NO; - } - - msize = ntohs(msg->size); + if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length)) + { + GNUNET_log ( + GNUNET_ERROR_TYPE_WARNING, + "Dropping message: transprot is too slow, queue length %llu exceeded\n", + ch->max_queue_length); + return GNUNET_NO; + } + + msize = ntohs (msg->size); env = - GNUNET_MQ_msg_extra(im, msize, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG); + GNUNET_MQ_msg_extra (im, msize, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG); if (NULL == env) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } im->expected_address_validity = - GNUNET_TIME_relative_hton(expected_addr_validity); + GNUNET_TIME_relative_hton (expected_addr_validity); im->sender = *sender; - memcpy(&im[1], msg, msize); + memcpy (&im[1], msg, msize); if (NULL != cb) - { - struct FlowControl *fc; - - im->fc_on = htonl(GNUNET_YES); - im->fc_id = ch->fc_gen++; - fc = GNUNET_new(struct FlowControl); - fc->sender = *sender; - fc->id = im->fc_id; - fc->cb = cb; - fc->cb_cls = cb_cls; - GNUNET_CONTAINER_DLL_insert(ch->fc_head, ch->fc_tail, fc); - } - GNUNET_MQ_send(ch->mq, env); + { + struct FlowControl *fc; + + im->fc_on = htonl (GNUNET_YES); + im->fc_id = ch->fc_gen++; + fc = GNUNET_new (struct FlowControl); + fc->sender = *sender; + fc->id = im->fc_id; + fc->cb = cb; + fc->cb_cls = cb_cls; + GNUNET_CONTAINER_DLL_insert (ch->fc_head, ch->fc_tail, fc); + } + GNUNET_MQ_send (ch->mq, env); return GNUNET_OK; } @@ -922,7 +927,7 @@ GNUNET_TRANSPORT_communicator_receive( * @return API handle identifying the new MQ */ struct GNUNET_TRANSPORT_QueueHandle * -GNUNET_TRANSPORT_communicator_mq_add( +GNUNET_TRANSPORT_communicator_mq_add ( struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, @@ -933,17 +938,17 @@ GNUNET_TRANSPORT_communicator_mq_add( { struct GNUNET_TRANSPORT_QueueHandle *qh; - qh = GNUNET_new(struct GNUNET_TRANSPORT_QueueHandle); + qh = GNUNET_new (struct GNUNET_TRANSPORT_QueueHandle); qh->ch = ch; qh->peer = *peer; - qh->address = GNUNET_strdup(address); + qh->address = GNUNET_strdup (address); qh->nt = nt; qh->mtu = mtu; qh->cs = cs; qh->mq = mq; qh->queue_id = ch->queue_gen++; - GNUNET_CONTAINER_DLL_insert(ch->queue_head, ch->queue_tail, qh); - send_add_queue(qh); + GNUNET_CONTAINER_DLL_insert (ch->queue_head, ch->queue_tail, qh); + send_add_queue (qh); return qh; } @@ -955,15 +960,15 @@ GNUNET_TRANSPORT_communicator_mq_add( * @param qh handle for the queue that must be invalidated */ void -GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh) +GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = qh->ch; - send_del_queue(qh); - GNUNET_CONTAINER_DLL_remove(ch->queue_head, ch->queue_tail, qh); - GNUNET_MQ_destroy(qh->mq); - GNUNET_free(qh->address); - GNUNET_free(qh); + send_del_queue (qh); + GNUNET_CONTAINER_DLL_remove (ch->queue_head, ch->queue_tail, qh); + GNUNET_MQ_destroy (qh->mq); + GNUNET_free (qh->address); + GNUNET_free (qh); } @@ -977,7 +982,7 @@ GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh) * @param expiration when does the communicator forsee this address expiring? */ struct GNUNET_TRANSPORT_AddressIdentifier * -GNUNET_TRANSPORT_communicator_address_add( +GNUNET_TRANSPORT_communicator_address_add ( struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, @@ -985,14 +990,14 @@ GNUNET_TRANSPORT_communicator_address_add( { struct GNUNET_TRANSPORT_AddressIdentifier *ai; - ai = GNUNET_new(struct GNUNET_TRANSPORT_AddressIdentifier); + ai = GNUNET_new (struct GNUNET_TRANSPORT_AddressIdentifier); ai->ch = ch; - ai->address = GNUNET_strdup(address); + ai->address = GNUNET_strdup (address); ai->nt = nt; ai->expiration = expiration; ai->aid = ch->aid_gen++; - GNUNET_CONTAINER_DLL_insert(ch->ai_head, ch->ai_tail, ai); - send_add_address(ai); + GNUNET_CONTAINER_DLL_insert (ch->ai_head, ch->ai_tail, ai); + send_add_address (ai); return ai; } @@ -1004,15 +1009,15 @@ GNUNET_TRANSPORT_communicator_address_add( * @param ai address that is no longer provided */ void -GNUNET_TRANSPORT_communicator_address_remove( +GNUNET_TRANSPORT_communicator_address_remove ( struct GNUNET_TRANSPORT_AddressIdentifier *ai) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ai->ch; - send_del_address(ai); - GNUNET_CONTAINER_DLL_remove(ch->ai_head, ch->ai_tail, ai); - GNUNET_free(ai->address); - GNUNET_free(ai); + send_del_address (ai); + GNUNET_CONTAINER_DLL_remove (ch->ai_head, ch->ai_tail, ai); + GNUNET_free (ai->address); + GNUNET_free (ai); } @@ -1034,7 +1039,7 @@ GNUNET_TRANSPORT_communicator_address_remove( * notify-API to @a pid's communicator @a comm */ void -GNUNET_TRANSPORT_communicator_notify( +GNUNET_TRANSPORT_communicator_notify ( struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *pid, const char *comm, @@ -1042,18 +1047,18 @@ GNUNET_TRANSPORT_communicator_notify( { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb; - size_t slen = strlen(comm) + 1; - uint16_t mlen = ntohs(header->size); + size_t slen = strlen (comm) + 1; + uint16_t mlen = ntohs (header->size); - GNUNET_assert(mlen + slen + sizeof(*cb) < UINT16_MAX); + GNUNET_assert (mlen + slen + sizeof(*cb) < UINT16_MAX); env = - GNUNET_MQ_msg_extra(cb, - slen + mlen, - GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL); + GNUNET_MQ_msg_extra (cb, + slen + mlen, + GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL); cb->pid = *pid; - memcpy(&cb[1], header, mlen); - memcpy(((char *)&cb[1]) + mlen, comm, slen); - GNUNET_MQ_send(ch->mq, env); + memcpy (&cb[1], header, mlen); + memcpy (((char *) &cb[1]) + mlen, comm, slen); + GNUNET_MQ_send (ch->mq, env); } diff --git a/src/transport/transport_api2_core.c b/src/transport/transport_api2_core.c index 1d2d84bdf..cd8bacf3d 100644 --- a/src/transport/transport_api2_core.c +++ b/src/transport/transport_api2_core.c @@ -32,7 +32,7 @@ #include "gnunet_transport_core_service.h" #include "transport.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-api-core", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__) /** * How large to start with for the hashmap of neighbours. @@ -53,7 +53,8 @@ /** * Entry in hash table of all of our current (connected) neighbours. */ -struct Neighbour { +struct Neighbour +{ /** * Identity of this neighbour. */ @@ -105,7 +106,8 @@ struct Neighbour { * Handle for the transport service (includes all of the * state for the transport service). */ -struct GNUNET_TRANSPORT_CoreHandle { +struct GNUNET_TRANSPORT_CoreHandle +{ /** * Closure for the callbacks. */ @@ -173,7 +175,7 @@ struct GNUNET_TRANSPORT_CoreHandle { * @param h transport service to reconnect */ static void -disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h); +disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h); /** @@ -184,10 +186,10 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h); * @return NULL if no such peer entry exists */ static struct Neighbour * -neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, - const struct GNUNET_PeerIdentity *peer) +neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, + const struct GNUNET_PeerIdentity *peer) { - return GNUNET_CONTAINER_multipeermap_get(h->neighbours, peer); + return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer); } @@ -202,27 +204,27 @@ neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, * #GNUNET_NO if not. */ static int -neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value) +neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { struct GNUNET_TRANSPORT_CoreHandle *handle = cls; struct Neighbour *n = value; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Dropping entry for neighbour `%s'.\n", - GNUNET_i2s(key)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Dropping entry for neighbour `%s'.\n", + GNUNET_i2s (key)); if (NULL != handle->nd_cb) - handle->nd_cb(handle->cls, &n->id, n->handlers_cls); + handle->nd_cb (handle->cls, &n->id, n->handlers_cls); if (NULL != n->env) - { - GNUNET_MQ_send_cancel(n->env); - n->env = NULL; - } - GNUNET_MQ_destroy(n->mq); - GNUNET_assert(NULL == n->mq); - GNUNET_assert( + { + GNUNET_MQ_send_cancel (n->env); + n->env = NULL; + } + GNUNET_MQ_destroy (n->mq); + GNUNET_assert (NULL == n->mq); + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(handle->neighbours, key, n)); - GNUNET_free(n); + GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n)); + GNUNET_free (n); return GNUNET_YES; } @@ -237,13 +239,13 @@ neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value) * @param error error code */ static void -mq_error_handler(void *cls, enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Error receiving from transport service, disconnecting temporarily.\n"); - disconnect_and_schedule_reconnect(h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Error receiving from transport service, disconnecting temporarily.\n"); + disconnect_and_schedule_reconnect (h); } @@ -258,13 +260,13 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) * @param cls the `struct Neighbour` where the message was sent */ static void -notify_send_done(void *cls) +notify_send_done (void *cls) { struct Neighbour *n = cls; n->awaiting_done = GNUNET_NO; n->env = NULL; - GNUNET_MQ_impl_send_continue(n->mq); + GNUNET_MQ_impl_send_continue (n->mq); } @@ -275,18 +277,18 @@ notify_send_done(void *cls) * @param n neighbour to perform transmission for */ static void -do_send(struct Neighbour *n) +do_send (struct Neighbour *n) { - GNUNET_assert(0 < n->ready_window); - GNUNET_assert(NULL != n->env); + GNUNET_assert (0 < n->ready_window); + GNUNET_assert (NULL != n->env); n->ready_window--; n->awaiting_done = GNUNET_YES; - GNUNET_MQ_notify_sent(n->env, ¬ify_send_done, n); - GNUNET_MQ_send(n->h->mq, n->env); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Passed message of type %u for neighbour `%s' to TRANSPORT.\n", - ntohs(GNUNET_MQ_env_get_msg(n->env)->type), - GNUNET_i2s(&n->id)); + GNUNET_MQ_notify_sent (n->env, ¬ify_send_done, n); + GNUNET_MQ_send (n->h->mq, n->env); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Passed message of type %u for neighbour `%s' to TRANSPORT.\n", + ntohs (GNUNET_MQ_env_get_msg (n->env)->type), + GNUNET_i2s (&n->id)); } @@ -301,44 +303,44 @@ do_send(struct Neighbour *n) * @param impl_state state of the implementation */ static void -mq_send_impl(struct GNUNET_MQ_Handle *mq, - const struct GNUNET_MessageHeader *msg, - void *impl_state) +mq_send_impl (struct GNUNET_MQ_Handle *mq, + const struct GNUNET_MessageHeader *msg, + void *impl_state) { struct Neighbour *n = impl_state; struct OutboundMessage *obm; uint16_t msize; - msize = ntohs(msg->size); + msize = ntohs (msg->size); if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm)) - { - GNUNET_break(0); - GNUNET_MQ_impl_send_continue(mq); - return; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "CORE requested transmission of message of type %u to neighbour `%s'.\n", - ntohs(msg->type), - GNUNET_i2s(&n->id)); - - GNUNET_assert(NULL == n->env); + { + GNUNET_break (0); + GNUNET_MQ_impl_send_continue (mq); + return; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "CORE requested transmission of message of type %u to neighbour `%s'.\n", + ntohs (msg->type), + GNUNET_i2s (&n->id)); + + GNUNET_assert (NULL == n->env); n->env = - GNUNET_MQ_msg_nested_mh(obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); - n->env_size = ntohs(msg->size); + GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); + n->env_size = ntohs (msg->size); { struct GNUNET_MQ_Envelope *env; - env = GNUNET_MQ_get_current_envelope(mq); - obm->priority = htonl((uint32_t)GNUNET_MQ_env_get_options(env)); + env = GNUNET_MQ_get_current_envelope (mq); + obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env)); } obm->peer = n->id; if (0 == n->ready_window) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Flow control delays transmission to CORE until we see SEND_OK.\n"); - return; /* can't send yet, need to wait for SEND_OK */ - } - do_send(n); + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Flow control delays transmission to CORE until we see SEND_OK.\n"); + return; /* can't send yet, need to wait for SEND_OK */ + } + do_send (n); } @@ -350,11 +352,11 @@ mq_send_impl(struct GNUNET_MQ_Handle *mq, * @param impl_state state of the implementation */ static void -mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) +mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct Neighbour *n = impl_state; - GNUNET_assert(mq == n->mq); + GNUNET_assert (mq == n->mq); n->mq = NULL; } @@ -367,22 +369,22 @@ mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) * @param impl_state state specific to the implementation */ static void -mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) +mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct Neighbour *n = impl_state; n->ready_window++; if (GNUNET_YES == n->awaiting_done) - { - GNUNET_MQ_send_cancel(n->env); - n->env = NULL; - n->awaiting_done = GNUNET_NO; - } + { + GNUNET_MQ_send_cancel (n->env); + n->env = NULL; + n->awaiting_done = GNUNET_NO; + } else - { - GNUNET_assert(0 == n->ready_window); - n->env = NULL; - } + { + GNUNET_assert (0 == n->ready_window); + n->env = NULL; + } } @@ -395,11 +397,11 @@ mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) * @param error error code */ static void -peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) +peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { /* struct Neighbour *n = cls; */ - GNUNET_break_op(0); + GNUNET_break_op (0); } @@ -410,44 +412,44 @@ peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) * @param cim message received */ static void -handle_connect(void *cls, const struct ConnectInfoMessage *cim) +handle_connect (void *cls, const struct ConnectInfoMessage *cim) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; struct Neighbour *n; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receiving CONNECT message for `%s'\n", - GNUNET_i2s(&cim->id)); - n = neighbour_find(h, &cim->id); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receiving CONNECT message for `%s'\n", + GNUNET_i2s (&cim->id)); + n = neighbour_find (h, &cim->id); if (NULL != n) - { - GNUNET_break(0); - disconnect_and_schedule_reconnect(h); - return; - } - n = GNUNET_new(struct Neighbour); + { + GNUNET_break (0); + disconnect_and_schedule_reconnect (h); + return; + } + n = GNUNET_new (struct Neighbour); n->id = cim->id; n->h = h; n->ready_window = SEND_WINDOW_SIZE; - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put( - h->neighbours, - &n->id, - n, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - - n->mq = GNUNET_MQ_queue_for_callbacks(&mq_send_impl, - &mq_destroy_impl, - &mq_cancel_impl, - n, - h->handlers, - &peer_mq_error_handler, - n); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put ( + h->neighbours, + &n->id, + n, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + + n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, + &mq_destroy_impl, + &mq_cancel_impl, + n, + h->handlers, + &peer_mq_error_handler, + n); if (NULL != h->nc_cb) - { - n->handlers_cls = h->nc_cb(h->cls, &n->id, n->mq); - GNUNET_MQ_set_handlers_closure(n->mq, n->handlers_cls); - } + { + n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq); + GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls); + } } @@ -458,23 +460,23 @@ handle_connect(void *cls, const struct ConnectInfoMessage *cim) * @param dim message received */ static void -handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim) +handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; struct Neighbour *n; - GNUNET_break(ntohl(dim->reserved) == 0); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receiving DISCONNECT message for `%s'.\n", - GNUNET_i2s(&dim->peer)); - n = neighbour_find(h, &dim->peer); + GNUNET_break (ntohl (dim->reserved) == 0); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receiving DISCONNECT message for `%s'.\n", + GNUNET_i2s (&dim->peer)); + n = neighbour_find (h, &dim->peer); if (NULL == n) - { - GNUNET_break(0); - disconnect_and_schedule_reconnect(h); - return; - } - GNUNET_assert(GNUNET_YES == neighbour_delete(h, &dim->peer, n)); + { + GNUNET_break (0); + disconnect_and_schedule_reconnect (h); + return; + } + GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n)); } @@ -485,26 +487,26 @@ handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim) * @param okm message received */ static void -handle_send_ok(void *cls, const struct SendOkMessage *okm) +handle_send_ok (void *cls, const struct SendOkMessage *okm) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; struct Neighbour *n; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receiving SEND_OK message for transmission to %s\n", - GNUNET_i2s(&okm->peer)); - n = neighbour_find(h, &okm->peer); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receiving SEND_OK message for transmission to %s\n", + GNUNET_i2s (&okm->peer)); + n = neighbour_find (h, &okm->peer); if (NULL == n) - { - /* We should never get a 'SEND_OK' for a peer that we are not - connected to */ - GNUNET_break(0); - disconnect_and_schedule_reconnect(h); - return; - } + { + /* We should never get a 'SEND_OK' for a peer that we are not + connected to */ + GNUNET_break (0); + disconnect_and_schedule_reconnect (h); + return; + } n->ready_window++; if ((NULL != n->env) && (1 == n->ready_window)) - do_send(n); + do_send (n); } @@ -515,23 +517,23 @@ handle_send_ok(void *cls, const struct SendOkMessage *okm) * @param im message received */ static int -check_recv(void *cls, const struct InboundMessage *im) +check_recv (void *cls, const struct InboundMessage *im) { const struct GNUNET_MessageHeader *imm; uint16_t size; - size = ntohs(im->header.size) - sizeof(*im); + size = ntohs (im->header.size) - sizeof(*im); if (size < sizeof(struct GNUNET_MessageHeader)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - imm = (const struct GNUNET_MessageHeader *)&im[1]; - if (ntohs(imm->size) != size) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + imm = (const struct GNUNET_MessageHeader *) &im[1]; + if (ntohs (imm->size) != size) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -543,26 +545,26 @@ check_recv(void *cls, const struct InboundMessage *im) * @param im message received */ static void -handle_recv(void *cls, const struct InboundMessage *im) +handle_recv (void *cls, const struct InboundMessage *im) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; const struct GNUNET_MessageHeader *imm = - (const struct GNUNET_MessageHeader *)&im[1]; + (const struct GNUNET_MessageHeader *) &im[1]; struct Neighbour *n; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received message of type %u with %u bytes from `%s'.\n", - (unsigned int)ntohs(imm->type), - (unsigned int)ntohs(imm->size), - GNUNET_i2s(&im->peer)); - n = neighbour_find(h, &im->peer); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received message of type %u with %u bytes from `%s'.\n", + (unsigned int) ntohs (imm->type), + (unsigned int) ntohs (imm->size), + GNUNET_i2s (&im->peer)); + n = neighbour_find (h, &im->peer); if (NULL == n) - { - GNUNET_break(0); - disconnect_and_schedule_reconnect(h); - return; - } - GNUNET_MQ_inject_message(n->mq, imm); + { + GNUNET_break (0); + disconnect_and_schedule_reconnect (h); + return; + } + GNUNET_MQ_inject_message (n->mq, imm); } @@ -572,47 +574,47 @@ handle_recv(void *cls, const struct InboundMessage *im) * @param cls the handle to the transport service */ static void -reconnect(void *cls) +reconnect (void *cls) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_fixed_size(connect, - GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, - struct ConnectInfoMessage, - h), - GNUNET_MQ_hd_fixed_size(disconnect, - GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, - struct DisconnectInfoMessage, - h), - GNUNET_MQ_hd_fixed_size(send_ok, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, - struct SendOkMessage, - h), - GNUNET_MQ_hd_var_size(recv, - GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, - struct InboundMessage, - h), - GNUNET_MQ_handler_end() }; + { GNUNET_MQ_hd_fixed_size (connect, + GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, + struct ConnectInfoMessage, + h), + GNUNET_MQ_hd_fixed_size (disconnect, + GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, + struct DisconnectInfoMessage, + h), + GNUNET_MQ_hd_fixed_size (send_ok, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, + struct SendOkMessage, + h), + GNUNET_MQ_hd_var_size (recv, + GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, + struct InboundMessage, + h), + GNUNET_MQ_handler_end () }; struct GNUNET_MQ_Envelope *env; struct StartMessage *s; uint32_t options; h->reconnect_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); - GNUNET_assert(NULL == h->mq); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); + GNUNET_assert (NULL == h->mq); h->mq = - GNUNET_CLIENT_connect(h->cfg, "transport", handlers, &mq_error_handler, h); + GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); if (NULL == h->mq) return; - env = GNUNET_MQ_msg(s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); + env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); options = 0; if (h->check_self) options |= 1; if (NULL != h->handlers) options |= 2; - s->options = htonl(options); + s->options = htonl (options); s->self = h->self; - GNUNET_MQ_send(h->mq, env); + GNUNET_MQ_send (h->mq, env); } @@ -622,14 +624,14 @@ reconnect(void *cls) * @param h transport service to reconnect */ static void -disconnect(struct GNUNET_TRANSPORT_CoreHandle *h) +disconnect (struct GNUNET_TRANSPORT_CoreHandle *h) { - GNUNET_CONTAINER_multipeermap_iterate(h->neighbours, &neighbour_delete, h); + GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h); if (NULL != h->mq) - { - GNUNET_MQ_destroy(h->mq); - h->mq = NULL; - } + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } } @@ -640,16 +642,16 @@ disconnect(struct GNUNET_TRANSPORT_CoreHandle *h) * @param h transport service to reconnect */ static void -disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h) +disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) { - GNUNET_assert(NULL == h->reconnect_task); - disconnect(h); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Scheduling task to reconnect to transport service in %s.\n", - GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); + GNUNET_assert (NULL == h->reconnect_task); + disconnect (h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling task to reconnect to transport service in %s.\n", + GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); h->reconnect_task = - GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); - h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); + GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); + h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); } @@ -661,12 +663,12 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h) * @return NULL if disconnected, otherwise message queue for @a peer */ struct GNUNET_MQ_Handle * -GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, - const struct GNUNET_PeerIdentity *peer) +GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, + const struct GNUNET_PeerIdentity *peer) { struct Neighbour *n; - n = neighbour_find(handle, peer); + n = neighbour_find (handle, peer); if (NULL == n) return NULL; return n->mq; @@ -694,21 +696,21 @@ GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, * @param pid which peer was the message from that was fully processed by CORE */ void -GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch, - const struct GNUNET_PeerIdentity *pid) +GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch, + const struct GNUNET_PeerIdentity *pid) { struct GNUNET_MQ_Envelope *env; struct RecvOkMessage *rok; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Message for %s finished CORE processing, sending RECV_OK.\n", - GNUNET_i2s(pid)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Message for %s finished CORE processing, sending RECV_OK.\n", + GNUNET_i2s (pid)); if (NULL == ch->mq) return; - env = GNUNET_MQ_msg(rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); - rok->increase_window_delta = htonl(1); + env = GNUNET_MQ_msg (rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); + rok->increase_window_delta = htonl (1); rok->peer = *pid; - GNUNET_MQ_send(ch->mq, env); + GNUNET_MQ_send (ch->mq, env); } @@ -726,46 +728,46 @@ GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch, * @return NULL on error */ struct GNUNET_TRANSPORT_CoreHandle * -GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_PeerIdentity *self, - const struct GNUNET_MQ_MessageHandler *handlers, - void *cls, - GNUNET_TRANSPORT_NotifyConnect nc, - GNUNET_TRANSPORT_NotifyDisconnect nd) +GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *self, + const struct GNUNET_MQ_MessageHandler *handlers, + void *cls, + GNUNET_TRANSPORT_NotifyConnect nc, + GNUNET_TRANSPORT_NotifyDisconnect nd) { struct GNUNET_TRANSPORT_CoreHandle *h; unsigned int i; - h = GNUNET_new(struct GNUNET_TRANSPORT_CoreHandle); + h = GNUNET_new (struct GNUNET_TRANSPORT_CoreHandle); if (NULL != self) - { - h->self = *self; - h->check_self = GNUNET_YES; - } + { + h->self = *self; + h->check_self = GNUNET_YES; + } h->cfg = cfg; h->cls = cls; h->nc_cb = nc; h->nd_cb = nd; h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; if (NULL != handlers) - { - for (i = 0; NULL != handlers[i].cb; i++) - ; - h->handlers = GNUNET_new_array(i + 1, struct GNUNET_MQ_MessageHandler); - GNUNET_memcpy(h->handlers, - handlers, - i * sizeof(struct GNUNET_MQ_MessageHandler)); - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); - reconnect(h); + { + for (i = 0; NULL != handlers[i].cb; i++) + ; + h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler); + GNUNET_memcpy (h->handlers, + handlers, + i * sizeof(struct GNUNET_MQ_MessageHandler)); + } + LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); + reconnect (h); if (NULL == h->mq) - { - GNUNET_free_non_null(h->handlers); - GNUNET_free(h); - return NULL; - } + { + GNUNET_free_non_null (h->handlers); + GNUNET_free (h); + return NULL; + } h->neighbours = - GNUNET_CONTAINER_multipeermap_create(STARTING_NEIGHBOURS_SIZE, GNUNET_YES); + GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); return h; } @@ -777,22 +779,22 @@ GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, * #GNUNET_TRANSPORT_core_connect() */ void -GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle) +GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); /* this disconnects all neighbours... */ - disconnect(handle); + disconnect (handle); /* and now we stop trying to connect again... */ if (NULL != handle->reconnect_task) - { - GNUNET_SCHEDULER_cancel(handle->reconnect_task); - handle->reconnect_task = NULL; - } - GNUNET_CONTAINER_multipeermap_destroy(handle->neighbours); + { + GNUNET_SCHEDULER_cancel (handle->reconnect_task); + handle->reconnect_task = NULL; + } + GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); handle->neighbours = NULL; - GNUNET_free_non_null(handle->handlers); + GNUNET_free_non_null (handle->handlers); handle->handlers = NULL; - GNUNET_free(handle); + GNUNET_free (handle); } diff --git a/src/transport/transport_api2_monitor.c b/src/transport/transport_api2_monitor.c index 74624326c..f358051b6 100644 --- a/src/transport/transport_api2_monitor.c +++ b/src/transport/transport_api2_monitor.c @@ -33,7 +33,8 @@ /** * Opaque handle to the transport service for monitors. */ -struct GNUNET_TRANSPORT_MonitorContext { +struct GNUNET_TRANSPORT_MonitorContext +{ /** * Our configuration. */ @@ -72,7 +73,7 @@ struct GNUNET_TRANSPORT_MonitorContext { * @param mc handle to reconnect */ static void -reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc); +reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc); /** @@ -82,17 +83,17 @@ reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc); * @param ai address to delete */ static void -send_start_monitor(struct GNUNET_TRANSPORT_MonitorContext *mc) +send_start_monitor (struct GNUNET_TRANSPORT_MonitorContext *mc) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_MonitorStart *smm; if (NULL == mc->mq) return; - env = GNUNET_MQ_msg(smm, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START); - smm->one_shot = htonl((uint32_t)mc->one_shot); + env = GNUNET_MQ_msg (smm, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START); + smm->one_shot = htonl ((uint32_t) mc->one_shot); smm->peer = mc->peer; - GNUNET_MQ_send(mc->mq, env); + GNUNET_MQ_send (mc->mq, env); } @@ -102,11 +103,11 @@ send_start_monitor(struct GNUNET_TRANSPORT_MonitorContext *mc) * @param mc service to disconnect from */ static void -disconnect(struct GNUNET_TRANSPORT_MonitorContext *mc) +disconnect (struct GNUNET_TRANSPORT_MonitorContext *mc) { if (NULL == mc->mq) return; - GNUNET_MQ_destroy(mc->mq); + GNUNET_MQ_destroy (mc->mq); mc->mq = NULL; } @@ -118,16 +119,16 @@ disconnect(struct GNUNET_TRANSPORT_MonitorContext *mc) * @param error what error happened? */ static void -error_handler(void *cls, enum GNUNET_MQ_Error error) +error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_MonitorContext *mc = cls; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "MQ failure %d, reconnecting to transport service.\n", - error); - disconnect(mc); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "MQ failure %d, reconnecting to transport service.\n", + error); + disconnect (mc); /* TODO: maybe do this with exponential backoff/delay */ - reconnect(mc); + reconnect (mc); } @@ -140,10 +141,10 @@ error_handler(void *cls, enum GNUNET_MQ_Error error) * @return #GNUNET_OK if @a smt is well-formed */ static int -check_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) +check_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) { - (void)cls; - GNUNET_MQ_check_zero_termination(md); + (void) cls; + GNUNET_MQ_check_zero_termination (md); return GNUNET_OK; } @@ -155,21 +156,21 @@ check_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) * @param md monitor data */ static void -handle_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) +handle_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) { struct GNUNET_TRANSPORT_MonitorContext *mc = cls; struct GNUNET_TRANSPORT_MonitorInformation mi; - mi.address = (const char *)&md[1]; - mi.nt = (enum GNUNET_NetworkType)ntohl(md->nt); - mi.cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl(md->cs); - mi.num_msg_pending = ntohl(md->num_msg_pending); - mi.num_bytes_pending = ntohl(md->num_bytes_pending); - mi.last_validation = GNUNET_TIME_absolute_ntoh(md->last_validation); - mi.valid_until = GNUNET_TIME_absolute_ntoh(md->valid_until); - mi.next_validation = GNUNET_TIME_absolute_ntoh(md->next_validation); - mi.rtt = GNUNET_TIME_relative_ntoh(md->rtt); - mc->cb(mc->cb_cls, &md->peer, &mi); + mi.address = (const char *) &md[1]; + mi.nt = (enum GNUNET_NetworkType) ntohl (md->nt); + mi.cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (md->cs); + mi.num_msg_pending = ntohl (md->num_msg_pending); + mi.num_bytes_pending = ntohl (md->num_bytes_pending); + mi.last_validation = GNUNET_TIME_absolute_ntoh (md->last_validation); + mi.valid_until = GNUNET_TIME_absolute_ntoh (md->valid_until); + mi.next_validation = GNUNET_TIME_absolute_ntoh (md->next_validation); + mi.rtt = GNUNET_TIME_relative_ntoh (md->rtt); + mc->cb (mc->cb_cls, &md->peer, &mi); } @@ -180,19 +181,19 @@ handle_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) * @param me end message */ static void -handle_monitor_end(void *cls, const struct GNUNET_MessageHeader *me) +handle_monitor_end (void *cls, const struct GNUNET_MessageHeader *me) { struct GNUNET_TRANSPORT_MonitorContext *mc = cls; if (GNUNET_YES != mc->one_shot) - { - GNUNET_break(0); - disconnect(mc); - reconnect(mc); - return; - } - mc->cb(mc->cb_cls, NULL, NULL); - GNUNET_TRANSPORT_monitor_cancel(mc); + { + GNUNET_break (0); + disconnect (mc); + reconnect (mc); + return; + } + mc->cb (mc->cb_cls, NULL, NULL); + GNUNET_TRANSPORT_monitor_cancel (mc); } @@ -202,24 +203,24 @@ handle_monitor_end(void *cls, const struct GNUNET_MessageHeader *me) * @param mc handle to reconnect */ static void -reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc) +reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc) { struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_var_size(monitor_data, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA, - struct GNUNET_TRANSPORT_MonitorData, - mc), - GNUNET_MQ_hd_fixed_size(monitor_end, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END, - struct GNUNET_MessageHeader, - mc), - GNUNET_MQ_handler_end() }; + { GNUNET_MQ_hd_var_size (monitor_data, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA, + struct GNUNET_TRANSPORT_MonitorData, + mc), + GNUNET_MQ_hd_fixed_size (monitor_end, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END, + struct GNUNET_MessageHeader, + mc), + GNUNET_MQ_handler_end () }; mc->mq = - GNUNET_CLIENT_connect(mc->cfg, "transport", handlers, &error_handler, mc); + GNUNET_CLIENT_connect (mc->cfg, "transport", handlers, &error_handler, mc); if (NULL == mc->mq) return; - send_start_monitor(mc); + send_start_monitor (mc); } @@ -250,27 +251,27 @@ reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc) * @param cb_cls closure for @a mc */ struct GNUNET_TRANSPORT_MonitorContext * -GNUNET_TRANSPORT_monitor(const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_PeerIdentity *peer, - int one_shot, - GNUNET_TRANSPORT_MonitorCallback cb, - void *cb_cls) +GNUNET_TRANSPORT_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *peer, + int one_shot, + GNUNET_TRANSPORT_MonitorCallback cb, + void *cb_cls) { struct GNUNET_TRANSPORT_MonitorContext *mc; - mc = GNUNET_new(struct GNUNET_TRANSPORT_MonitorContext); + mc = GNUNET_new (struct GNUNET_TRANSPORT_MonitorContext); mc->cfg = cfg; if (NULL != peer) mc->peer = *peer; mc->one_shot = one_shot; mc->cb = cb; mc->cb_cls = cb_cls; - reconnect(mc); + reconnect (mc); if (NULL == mc->mq) - { - GNUNET_free(mc); - return NULL; - } + { + GNUNET_free (mc); + return NULL; + } return mc; } @@ -281,10 +282,10 @@ GNUNET_TRANSPORT_monitor(const struct GNUNET_CONFIGURATION_Handle *cfg, * @param pmc handle for the request to cancel */ void -GNUNET_TRANSPORT_monitor_cancel(struct GNUNET_TRANSPORT_MonitorContext *mc) +GNUNET_TRANSPORT_monitor_cancel (struct GNUNET_TRANSPORT_MonitorContext *mc) { - disconnect(mc); - GNUNET_free(mc); + disconnect (mc); + GNUNET_free (mc); } /* end of transport_api2_monitor.c */ diff --git a/src/transport/transport_api_address_to_string.c b/src/transport/transport_api_address_to_string.c index d5e383914..c7de39ea8 100644 --- a/src/transport/transport_api_address_to_string.c +++ b/src/transport/transport_api_address_to_string.c @@ -33,7 +33,8 @@ /** * Context for the address lookup. */ -struct GNUNET_TRANSPORT_AddressToStringContext { +struct GNUNET_TRANSPORT_AddressToStringContext +{ /** * Function to call with the human-readable address. */ @@ -59,35 +60,35 @@ struct GNUNET_TRANSPORT_AddressToStringContext { * @return #GNUNET_OK if message is well-formed */ static int -check_reply(void *cls, - const struct AddressToStringResultMessage *atsm) +check_reply (void *cls, + const struct AddressToStringResultMessage *atsm) { - uint16_t size = ntohs(atsm->header.size) - sizeof(*atsm); + uint16_t size = ntohs (atsm->header.size) - sizeof(*atsm); const char *address; int result; uint32_t addr_len; - result = (int)ntohl(atsm->res); - addr_len = ntohl(atsm->addr_len); + result = (int) ntohl (atsm->res); + addr_len = ntohl (atsm->addr_len); if (GNUNET_SYSERR == result) return GNUNET_OK; if (0 == size) + { + if (GNUNET_OK != result) { - if (GNUNET_OK != result) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - return GNUNET_OK; + GNUNET_break (0); + return GNUNET_SYSERR; } - address = (const char *)&atsm[1]; + return GNUNET_OK; + } + address = (const char *) &atsm[1]; if ((addr_len > size) || (address[addr_len - 1] != '\0')) - { - /* invalid reply */ - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + /* invalid reply */ + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -99,40 +100,40 @@ check_reply(void *cls, * @param msg message with the human-readable address */ static void -handle_reply(void *cls, - const struct AddressToStringResultMessage *atsm) +handle_reply (void *cls, + const struct AddressToStringResultMessage *atsm) { struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; - uint16_t size = ntohs(atsm->header.size) - sizeof(*atsm); + uint16_t size = ntohs (atsm->header.size) - sizeof(*atsm); const char *address; int result; - result = (int)ntohl(atsm->res); + result = (int) ntohl (atsm->res); if (GNUNET_SYSERR == result) - { - /* expect more replies; as this is not the last - call, we must pass the empty string for the address */ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Address resolution failed\n"); - alucb->cb(alucb->cb_cls, - "", - GNUNET_NO); - return; - } + { + /* expect more replies; as this is not the last + call, we must pass the empty string for the address */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Address resolution failed\n"); + alucb->cb (alucb->cb_cls, + "", + GNUNET_NO); + return; + } if (0 == size) - { - /* we are done (successfully, without communication errors) */ - alucb->cb(alucb->cb_cls, - NULL, - GNUNET_OK); - GNUNET_TRANSPORT_address_to_string_cancel(alucb); - return; - } - address = (const char *)&atsm[1]; + { + /* we are done (successfully, without communication errors) */ + alucb->cb (alucb->cb_cls, + NULL, + GNUNET_OK); + GNUNET_TRANSPORT_address_to_string_cancel (alucb); + return; + } + address = (const char *) &atsm[1]; /* return normal reply to caller, also expect more replies */ - alucb->cb(alucb->cb_cls, - address, - GNUNET_OK); + alucb->cb (alucb->cb_cls, + address, + GNUNET_OK); } @@ -146,17 +147,17 @@ handle_reply(void *cls, * @param error error code */ static void -mq_error_handler(void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Disconnected from transport, address resolution failed\n"); - alucb->cb(alucb->cb_cls, - NULL, - GNUNET_SYSERR); - GNUNET_TRANSPORT_address_to_string_cancel(alucb); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Disconnected from transport, address resolution failed\n"); + alucb->cb (alucb->cb_cls, + NULL, + GNUNET_SYSERR); + GNUNET_TRANSPORT_address_to_string_cancel (alucb); } @@ -173,21 +174,23 @@ mq_error_handler(void *cls, * @return handle to cancel the operation, NULL on error */ struct GNUNET_TRANSPORT_AddressToStringContext * -GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_HELLO_Address *address, - int numeric, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressToStringCallback aluc, - void *aluc_cls) +GNUNET_TRANSPORT_address_to_string (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_HELLO_Address *address, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressToStringCallback + aluc, + void *aluc_cls) { struct GNUNET_TRANSPORT_AddressToStringContext *alc - = GNUNET_new(struct GNUNET_TRANSPORT_AddressToStringContext); + = GNUNET_new (struct GNUNET_TRANSPORT_AddressToStringContext); struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size(reply, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY, - struct AddressToStringResultMessage, - alc), - GNUNET_MQ_handler_end() + GNUNET_MQ_hd_var_size (reply, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY, + struct AddressToStringResultMessage, + alc), + GNUNET_MQ_handler_end () }; size_t alen; size_t slen; @@ -196,49 +199,49 @@ GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg char *addrbuf; alen = address->address_length; - slen = strlen(address->transport_name) + 1; + slen = strlen (address->transport_name) + 1; if ((alen + slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct AddressLookupMessage)) || (alen >= GNUNET_MAX_MESSAGE_SIZE) || (slen >= GNUNET_MAX_MESSAGE_SIZE)) - { - GNUNET_break(0); - GNUNET_free(alc); - return NULL; - } + { + GNUNET_break (0); + GNUNET_free (alc); + return NULL; + } alc->cb = aluc; alc->cb_cls = aluc_cls; - alc->mq = GNUNET_CLIENT_connect(cfg, - "transport", - handlers, - &mq_error_handler, - alc); + alc->mq = GNUNET_CLIENT_connect (cfg, + "transport", + handlers, + &mq_error_handler, + alc); if (NULL == alc->mq) - { - GNUNET_break(0); - GNUNET_free(alc); - return NULL; - } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Client tries to resolve for peer `%s' address plugin %s len %u\n", - GNUNET_i2s(&address->peer), - address->transport_name, - (unsigned int)address->address_length); - env = GNUNET_MQ_msg_extra(msg, - alen + slen, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING); - msg->numeric_only = htons((int16_t)numeric); - msg->addrlen = htons((uint16_t)alen); - msg->timeout = GNUNET_TIME_relative_hton(timeout); - addrbuf = (char *)&msg[1]; - GNUNET_memcpy(addrbuf, - address->address, - alen); - GNUNET_memcpy(&addrbuf[alen], - address->transport_name, - slen); - GNUNET_MQ_send(alc->mq, - env); + { + GNUNET_break (0); + GNUNET_free (alc); + return NULL; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Client tries to resolve for peer `%s' address plugin %s len %u\n", + GNUNET_i2s (&address->peer), + address->transport_name, + (unsigned int) address->address_length); + env = GNUNET_MQ_msg_extra (msg, + alen + slen, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING); + msg->numeric_only = htons ((int16_t) numeric); + msg->addrlen = htons ((uint16_t) alen); + msg->timeout = GNUNET_TIME_relative_hton (timeout); + addrbuf = (char *) &msg[1]; + GNUNET_memcpy (addrbuf, + address->address, + alen); + GNUNET_memcpy (&addrbuf[alen], + address->transport_name, + slen); + GNUNET_MQ_send (alc->mq, + env); return alc; } @@ -249,10 +252,12 @@ GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg * @param alc the context handle */ void -GNUNET_TRANSPORT_address_to_string_cancel(struct GNUNET_TRANSPORT_AddressToStringContext *alc) +GNUNET_TRANSPORT_address_to_string_cancel (struct + GNUNET_TRANSPORT_AddressToStringContext + *alc) { - GNUNET_MQ_destroy(alc->mq); - GNUNET_free(alc); + GNUNET_MQ_destroy (alc->mq); + GNUNET_free (alc); } diff --git a/src/transport/transport_api_blacklist.c b/src/transport/transport_api_blacklist.c index f04def49d..45d9bcf29 100644 --- a/src/transport/transport_api_blacklist.c +++ b/src/transport/transport_api_blacklist.c @@ -34,7 +34,8 @@ /** * Handle for blacklisting requests. */ -struct GNUNET_TRANSPORT_Blacklist { +struct GNUNET_TRANSPORT_Blacklist +{ /** * Connection to transport service. */ @@ -64,7 +65,7 @@ struct GNUNET_TRANSPORT_Blacklist { * @param br overall handle */ static void -reconnect(struct GNUNET_TRANSPORT_Blacklist *br); +reconnect (struct GNUNET_TRANSPORT_Blacklist *br); /** @@ -74,21 +75,21 @@ reconnect(struct GNUNET_TRANSPORT_Blacklist *br); * @param bm query */ static void -handle_query(void *cls, - const struct BlacklistMessage *bm) +handle_query (void *cls, + const struct BlacklistMessage *bm) { struct GNUNET_TRANSPORT_Blacklist *br = cls; struct GNUNET_MQ_Envelope *env; struct BlacklistMessage *res; - GNUNET_break(0 == ntohl(bm->is_allowed)); - env = GNUNET_MQ_msg(res, - GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY); - res->is_allowed = htonl(br->cb(br->cb_cls, - &bm->peer)); + GNUNET_break (0 == ntohl (bm->is_allowed)); + env = GNUNET_MQ_msg (res, + GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY); + res->is_allowed = htonl (br->cb (br->cb_cls, + &bm->peer)); res->peer = bm->peer; - GNUNET_MQ_send(br->mq, - env); + GNUNET_MQ_send (br->mq, + env); } /** @@ -100,12 +101,12 @@ handle_query(void *cls, * @param error error code */ static void -mq_error_handler(void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_Blacklist *br = cls; - reconnect(br); + reconnect (br); } @@ -115,31 +116,31 @@ mq_error_handler(void *cls, * @param br overall handle */ static void -reconnect(struct GNUNET_TRANSPORT_Blacklist *br) +reconnect (struct GNUNET_TRANSPORT_Blacklist *br) { struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size(query, - GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY, - struct BlacklistMessage, - br), - GNUNET_MQ_handler_end() + GNUNET_MQ_hd_fixed_size (query, + GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY, + struct BlacklistMessage, + br), + GNUNET_MQ_handler_end () }; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *req; if (NULL != br->mq) - GNUNET_MQ_destroy(br->mq); - br->mq = GNUNET_CLIENT_connect(br->cfg, - "transport", - handlers, - &mq_error_handler, - br); + GNUNET_MQ_destroy (br->mq); + br->mq = GNUNET_CLIENT_connect (br->cfg, + "transport", + handlers, + &mq_error_handler, + br); if (NULL == br->mq) return; - env = GNUNET_MQ_msg(req, - GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT); - GNUNET_MQ_send(br->mq, - env); + env = GNUNET_MQ_msg (req, + GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT); + GNUNET_MQ_send (br->mq, + env); } @@ -158,22 +159,22 @@ reconnect(struct GNUNET_TRANSPORT_Blacklist *br) * @return NULL on error, otherwise handle for cancellation */ struct GNUNET_TRANSPORT_Blacklist * -GNUNET_TRANSPORT_blacklist(const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_TRANSPORT_BlacklistCallback cb, - void *cb_cls) +GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_TRANSPORT_BlacklistCallback cb, + void *cb_cls) { struct GNUNET_TRANSPORT_Blacklist *br; - br = GNUNET_new(struct GNUNET_TRANSPORT_Blacklist); + br = GNUNET_new (struct GNUNET_TRANSPORT_Blacklist); br->cfg = cfg; br->cb = cb; br->cb_cls = cb_cls; - reconnect(br); + reconnect (br); if (NULL == br->mq) - { - GNUNET_free(br); - return NULL; - } + { + GNUNET_free (br); + return NULL; + } return br; } @@ -185,10 +186,10 @@ GNUNET_TRANSPORT_blacklist(const struct GNUNET_CONFIGURATION_Handle *cfg, * @param br handle of the request that is to be cancelled */ void -GNUNET_TRANSPORT_blacklist_cancel(struct GNUNET_TRANSPORT_Blacklist *br) +GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br) { - GNUNET_MQ_destroy(br->mq); - GNUNET_free(br); + GNUNET_MQ_destroy (br->mq); + GNUNET_free (br); } diff --git a/src/transport/transport_api_core.c b/src/transport/transport_api_core.c index d88461d5a..5d841fa10 100644 --- a/src/transport/transport_api_core.c +++ b/src/transport/transport_api_core.c @@ -32,7 +32,7 @@ #include "gnunet_transport_service.h" #include "transport.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-api-core", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__) /** * If we could not send any payload to a peer for this amount of @@ -49,7 +49,8 @@ /** * Entry in hash table of all of our current (connected) neighbours. */ -struct Neighbour { +struct Neighbour +{ /** * Overall transport handle. */ @@ -118,7 +119,8 @@ struct Neighbour { * Handle for the transport service (includes all of the * state for the transport service). */ -struct GNUNET_TRANSPORT_CoreHandle { +struct GNUNET_TRANSPORT_CoreHandle +{ /** * Closure for the callbacks. */ @@ -200,7 +202,7 @@ struct GNUNET_TRANSPORT_CoreHandle { * @param h transport service to reconnect */ static void -disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h); +disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h); /** @@ -211,10 +213,10 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h); * @return NULL if no such peer entry exists */ static struct Neighbour * -neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, - const struct GNUNET_PeerIdentity *peer) +neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, + const struct GNUNET_PeerIdentity *peer) { - return GNUNET_CONTAINER_multipeermap_get(h->neighbours, peer); + return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer); } @@ -225,17 +227,17 @@ neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, * @param cls the `struct Neighbour` that has excess bandwidth */ static void -notify_excess_cb(void *cls) +notify_excess_cb (void *cls) { struct Neighbour *n = cls; struct GNUNET_TRANSPORT_CoreHandle *h = n->h; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Notifying CORE that more bandwidth is available for %s\n", - GNUNET_i2s(&n->id)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Notifying CORE that more bandwidth is available for %s\n", + GNUNET_i2s (&n->id)); if (NULL != h->neb_cb) - h->neb_cb(h->cls, &n->id, n->handlers_cls); + h->neb_cb (h->cls, &n->id, n->handlers_cls); } @@ -250,33 +252,33 @@ notify_excess_cb(void *cls) * #GNUNET_NO if not. */ static int -neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value) +neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { struct GNUNET_TRANSPORT_CoreHandle *handle = cls; struct Neighbour *n = value; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Dropping entry for neighbour `%s'.\n", - GNUNET_i2s(key)); - GNUNET_BANDWIDTH_tracker_notification_stop(&n->out_tracker); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Dropping entry for neighbour `%s'.\n", + GNUNET_i2s (key)); + GNUNET_BANDWIDTH_tracker_notification_stop (&n->out_tracker); if (NULL != handle->nd_cb) - handle->nd_cb(handle->cls, &n->id, n->handlers_cls); + handle->nd_cb (handle->cls, &n->id, n->handlers_cls); if (NULL != n->timeout_task) - { - GNUNET_SCHEDULER_cancel(n->timeout_task); - n->timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (n->timeout_task); + n->timeout_task = NULL; + } if (NULL != n->env) - { - GNUNET_MQ_send_cancel(n->env); - n->env = NULL; - } - GNUNET_MQ_destroy(n->mq); - GNUNET_assert(NULL == n->mq); - GNUNET_assert( + { + GNUNET_MQ_send_cancel (n->env); + n->env = NULL; + } + GNUNET_MQ_destroy (n->mq); + GNUNET_assert (NULL == n->mq); + GNUNET_assert ( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove(handle->neighbours, key, n)); - GNUNET_free(n); + GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n)); + GNUNET_free (n); return GNUNET_YES; } @@ -291,14 +293,14 @@ neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value) * @param error error code */ static void -mq_error_handler(void *cls, enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; - LOG(GNUNET_ERROR_TYPE_ERROR, - "Error receiving from transport service (%d), disconnecting temporarily.\n", - error); - disconnect_and_schedule_reconnect(h); + LOG (GNUNET_ERROR_TYPE_ERROR, + "Error receiving from transport service (%d), disconnecting temporarily.\n", + error); + disconnect_and_schedule_reconnect (h); } @@ -310,16 +312,16 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) * @return #GNUNET_OK if message is well-formed */ static int -check_hello(void *cls, const struct GNUNET_MessageHeader *msg) +check_hello (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_PeerIdentity me; if (GNUNET_OK != - GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)msg, &me)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -331,7 +333,7 @@ check_hello(void *cls, const struct GNUNET_MessageHeader *msg) * @param msg message received */ static void -handle_hello(void *cls, const struct GNUNET_MessageHeader *msg) +handle_hello (void *cls, const struct GNUNET_MessageHeader *msg) { /* we do not care => FIXME: signal in options to NEVER send HELLOs! */ } @@ -346,13 +348,13 @@ handle_hello(void *cls, const struct GNUNET_MessageHeader *msg) * @param cls the `struct Neighbour` where the message was sent */ static void -notify_send_done_fin(void *cls) +notify_send_done_fin (void *cls) { struct Neighbour *n = cls; n->timeout_task = NULL; n->is_ready = GNUNET_YES; - GNUNET_MQ_impl_send_continue(n->mq); + GNUNET_MQ_impl_send_continue (n->mq); } @@ -365,31 +367,31 @@ notify_send_done_fin(void *cls) * @param cls the `struct Neighbour` where the message was sent */ static void -notify_send_done(void *cls) +notify_send_done (void *cls) { struct Neighbour *n = cls; struct GNUNET_TIME_Relative delay; n->timeout_task = NULL; if (NULL != n->env) - { - GNUNET_BANDWIDTH_tracker_consume(&n->out_tracker, - n->env_size + n->traffic_overhead); - n->env = NULL; - n->traffic_overhead = 0; - } - delay = GNUNET_BANDWIDTH_tracker_get_delay(&n->out_tracker, 128); + { + GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, + n->env_size + n->traffic_overhead); + n->env = NULL; + n->traffic_overhead = 0; + } + delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 128); if (0 == delay.rel_value_us) - { - n->is_ready = GNUNET_YES; - GNUNET_MQ_impl_send_continue(n->mq); - return; - } - GNUNET_MQ_impl_send_in_flight(n->mq); + { + n->is_ready = GNUNET_YES; + GNUNET_MQ_impl_send_continue (n->mq); + return; + } + GNUNET_MQ_impl_send_in_flight (n->mq); /* cannot send even a small message without violating quota, wait a before allowing MQ to send next message */ n->timeout_task = - GNUNET_SCHEDULER_add_delayed(delay, ¬ify_send_done_fin, n); + GNUNET_SCHEDULER_add_delayed (delay, ¬ify_send_done_fin, n); } @@ -404,44 +406,44 @@ notify_send_done(void *cls) * @param impl_state state of the implementation */ static void -mq_send_impl(struct GNUNET_MQ_Handle *mq, - const struct GNUNET_MessageHeader *msg, - void *impl_state) +mq_send_impl (struct GNUNET_MQ_Handle *mq, + const struct GNUNET_MessageHeader *msg, + void *impl_state) { struct Neighbour *n = impl_state; struct GNUNET_TRANSPORT_CoreHandle *h = n->h; struct OutboundMessage *obm; uint16_t msize; - GNUNET_assert(GNUNET_YES == n->is_ready); - msize = ntohs(msg->size); + GNUNET_assert (GNUNET_YES == n->is_ready); + msize = ntohs (msg->size); if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm)) - { - GNUNET_break(0); - GNUNET_MQ_impl_send_continue(mq); - return; - } - GNUNET_assert(NULL == n->env); + { + GNUNET_break (0); + GNUNET_MQ_impl_send_continue (mq); + return; + } + GNUNET_assert (NULL == n->env); n->env = - GNUNET_MQ_msg_nested_mh(obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); + GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); { struct GNUNET_MQ_Envelope *env; - env = GNUNET_MQ_get_current_envelope(mq); - obm->priority = htonl((uint32_t)GNUNET_MQ_env_get_options(env)); + env = GNUNET_MQ_get_current_envelope (mq); + obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env)); } - obm->timeout = GNUNET_TIME_relative_hton( + obm->timeout = GNUNET_TIME_relative_hton ( GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */ obm->peer = n->id; - GNUNET_assert(NULL == n->timeout_task); + GNUNET_assert (NULL == n->timeout_task); n->is_ready = GNUNET_NO; - n->env_size = ntohs(msg->size); - GNUNET_MQ_notify_sent(n->env, ¬ify_send_done, n); - GNUNET_MQ_send(h->mq, n->env); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Queued message of type %u for neighbour `%s'.\n", - ntohs(msg->type), - GNUNET_i2s(&n->id)); + n->env_size = ntohs (msg->size); + GNUNET_MQ_notify_sent (n->env, ¬ify_send_done, n); + GNUNET_MQ_send (h->mq, n->env); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Queued message of type %u for neighbour `%s'.\n", + ntohs (msg->type), + GNUNET_i2s (&n->id)); } @@ -453,11 +455,11 @@ mq_send_impl(struct GNUNET_MQ_Handle *mq, * @param impl_state state of the implementation */ static void -mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) +mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct Neighbour *n = impl_state; - GNUNET_assert(mq == n->mq); + GNUNET_assert (mq == n->mq); n->mq = NULL; } @@ -470,16 +472,16 @@ mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) * @param impl_state state specific to the implementation */ static void -mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) +mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct Neighbour *n = impl_state; - GNUNET_assert(GNUNET_NO == n->is_ready); + GNUNET_assert (GNUNET_NO == n->is_ready); if (NULL != n->env) - { - GNUNET_MQ_send_cancel(n->env); - n->env = NULL; - } + { + GNUNET_MQ_send_cancel (n->env); + n->env = NULL; + } n->is_ready = GNUNET_YES; } @@ -494,11 +496,11 @@ mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) * @param error error code */ static void -peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) +peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { /* struct Neighbour *n = cls; */ - GNUNET_break_op(0); + GNUNET_break_op (0); } @@ -509,16 +511,16 @@ peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) * @param cls the `struct Neighbour` for which the timeout changed */ static void -outbound_bw_tracker_update(void *cls) +outbound_bw_tracker_update (void *cls) { struct Neighbour *n = cls; struct GNUNET_TIME_Relative delay; if (NULL == n->timeout_task) return; - delay = GNUNET_BANDWIDTH_tracker_get_delay(&n->out_tracker, 128); - GNUNET_SCHEDULER_cancel(n->timeout_task); - n->timeout_task = GNUNET_SCHEDULER_add_delayed(delay, ¬ify_send_done, n); + delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 128); + GNUNET_SCHEDULER_cancel (n->timeout_task); + n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, ¬ify_send_done, n); } @@ -529,54 +531,54 @@ outbound_bw_tracker_update(void *cls) * @param cim message received */ static void -handle_connect(void *cls, const struct ConnectInfoMessage *cim) +handle_connect (void *cls, const struct ConnectInfoMessage *cim) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; struct Neighbour *n; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receiving CONNECT message for `%s' with quota %u\n", - GNUNET_i2s(&cim->id), - ntohl(cim->quota_out.value__)); - n = neighbour_find(h, &cim->id); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receiving CONNECT message for `%s' with quota %u\n", + GNUNET_i2s (&cim->id), + ntohl (cim->quota_out.value__)); + n = neighbour_find (h, &cim->id); if (NULL != n) - { - GNUNET_break(0); /* FIXME: this assertion seems to fail sometimes!? */ - disconnect_and_schedule_reconnect(h); - return; - } - n = GNUNET_new(struct Neighbour); + { + GNUNET_break (0); /* FIXME: this assertion seems to fail sometimes!? */ + disconnect_and_schedule_reconnect (h); + return; + } + n = GNUNET_new (struct Neighbour); n->id = cim->id; n->h = h; n->is_ready = GNUNET_YES; n->traffic_overhead = 0; - GNUNET_BANDWIDTH_tracker_init2(&n->out_tracker, - &outbound_bw_tracker_update, - n, - GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, - MAX_BANDWIDTH_CARRY_S, - ¬ify_excess_cb, - n); - GNUNET_assert(GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put( - h->neighbours, - &n->id, - n, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - - GNUNET_BANDWIDTH_tracker_update_quota(&n->out_tracker, cim->quota_out); - n->mq = GNUNET_MQ_queue_for_callbacks(&mq_send_impl, - &mq_destroy_impl, - &mq_cancel_impl, - n, - h->handlers, - &peer_mq_error_handler, - n); + GNUNET_BANDWIDTH_tracker_init2 (&n->out_tracker, + &outbound_bw_tracker_update, + n, + GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, + MAX_BANDWIDTH_CARRY_S, + ¬ify_excess_cb, + n); + GNUNET_assert (GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put ( + h->neighbours, + &n->id, + n, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + + GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out); + n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, + &mq_destroy_impl, + &mq_cancel_impl, + n, + h->handlers, + &peer_mq_error_handler, + n); if (NULL != h->nc_cb) - { - n->handlers_cls = h->nc_cb(h->cls, &n->id, n->mq); - GNUNET_MQ_set_handlers_closure(n->mq, n->handlers_cls); - } + { + n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq); + GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls); + } } @@ -587,23 +589,23 @@ handle_connect(void *cls, const struct ConnectInfoMessage *cim) * @param dim message received */ static void -handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim) +handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; struct Neighbour *n; - GNUNET_break(ntohl(dim->reserved) == 0); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receiving DISCONNECT message for `%s'.\n", - GNUNET_i2s(&dim->peer)); - n = neighbour_find(h, &dim->peer); + GNUNET_break (ntohl (dim->reserved) == 0); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receiving DISCONNECT message for `%s'.\n", + GNUNET_i2s (&dim->peer)); + n = neighbour_find (h, &dim->peer); if (NULL == n) - { - GNUNET_break(0); - disconnect_and_schedule_reconnect(h); - return; - } - GNUNET_assert(GNUNET_YES == neighbour_delete(h, &dim->peer, n)); + { + GNUNET_break (0); + disconnect_and_schedule_reconnect (h); + return; + } + GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n)); } @@ -614,36 +616,36 @@ handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim) * @param okm message received */ static void -handle_send_ok(void *cls, const struct SendOkMessage *okm) +handle_send_ok (void *cls, const struct SendOkMessage *okm) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; struct Neighbour *n; uint32_t bytes_msg; uint32_t bytes_physical; - bytes_msg = ntohl(okm->bytes_msg); - bytes_physical = ntohl(okm->bytes_physical); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receiving SEND_OK message, transmission to %s %s.\n", - GNUNET_i2s(&okm->peer), - ntohl(okm->success) == GNUNET_OK ? "succeeded" : "failed"); - n = neighbour_find(h, &okm->peer); + bytes_msg = ntohl (okm->bytes_msg); + bytes_physical = ntohl (okm->bytes_physical); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receiving SEND_OK message, transmission to %s %s.\n", + GNUNET_i2s (&okm->peer), + ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed"); + n = neighbour_find (h, &okm->peer); if (NULL == n) - { - /* We should never get a 'SEND_OK' for a peer that we are not - connected to */ - GNUNET_break(0); - disconnect_and_schedule_reconnect(h); - return; - } + { + /* We should never get a 'SEND_OK' for a peer that we are not + connected to */ + GNUNET_break (0); + disconnect_and_schedule_reconnect (h); + return; + } if (bytes_physical > bytes_msg) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Overhead for %u byte message was %u\n", - bytes_msg, - bytes_physical - bytes_msg); - n->traffic_overhead += bytes_physical - bytes_msg; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Overhead for %u byte message was %u\n", + bytes_msg, + bytes_physical - bytes_msg); + n->traffic_overhead += bytes_physical - bytes_msg; + } } @@ -654,23 +656,23 @@ handle_send_ok(void *cls, const struct SendOkMessage *okm) * @param im message received */ static int -check_recv(void *cls, const struct InboundMessage *im) +check_recv (void *cls, const struct InboundMessage *im) { const struct GNUNET_MessageHeader *imm; uint16_t size; - size = ntohs(im->header.size) - sizeof(*im); + size = ntohs (im->header.size) - sizeof(*im); if (size < sizeof(struct GNUNET_MessageHeader)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - imm = (const struct GNUNET_MessageHeader *)&im[1]; - if (ntohs(imm->size) != size) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + imm = (const struct GNUNET_MessageHeader *) &im[1]; + if (ntohs (imm->size) != size) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -682,27 +684,27 @@ check_recv(void *cls, const struct InboundMessage *im) * @param im message received */ static void -handle_recv(void *cls, const struct InboundMessage *im) +handle_recv (void *cls, const struct InboundMessage *im) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; const struct GNUNET_MessageHeader *imm = - (const struct GNUNET_MessageHeader *)&im[1]; + (const struct GNUNET_MessageHeader *) &im[1]; struct Neighbour *n; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received message of type %u with %u bytes from `%s'.\n", - (unsigned int)ntohs(imm->type), - (unsigned int)ntohs(imm->size), - GNUNET_i2s(&im->peer)); - n = neighbour_find(h, &im->peer); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received message of type %u with %u bytes from `%s'.\n", + (unsigned int) ntohs (imm->type), + (unsigned int) ntohs (imm->size), + GNUNET_i2s (&im->peer)); + n = neighbour_find (h, &im->peer); if (NULL == n) - { - GNUNET_break(0); - disconnect_and_schedule_reconnect(h); - return; - } + { + GNUNET_break (0); + disconnect_and_schedule_reconnect (h); + return; + } h->rom_pending++; - GNUNET_MQ_inject_message(n->mq, imm); + GNUNET_MQ_inject_message (n->mq, imm); } @@ -713,24 +715,24 @@ handle_recv(void *cls, const struct InboundMessage *im) * @param msg message received */ static void -handle_set_quota(void *cls, const struct QuotaSetMessage *qm) +handle_set_quota (void *cls, const struct QuotaSetMessage *qm) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; struct Neighbour *n; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Receiving SET_QUOTA message for `%s' with quota %u\n", - GNUNET_i2s(&qm->peer), - ntohl(qm->quota.value__)); - n = neighbour_find(h, &qm->peer); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Receiving SET_QUOTA message for `%s' with quota %u\n", + GNUNET_i2s (&qm->peer), + ntohl (qm->quota.value__)); + n = neighbour_find (h, &qm->peer); if (NULL == n) - { - GNUNET_break( - 0); /* FIXME: julius reports this assertion fails sometimes? */ - disconnect_and_schedule_reconnect(h); - return; - } - GNUNET_BANDWIDTH_tracker_update_quota(&n->out_tracker, qm->quota); + { + GNUNET_break ( + 0); /* FIXME: julius reports this assertion fails sometimes? */ + disconnect_and_schedule_reconnect (h); + return; + } + GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, qm->quota); } @@ -740,55 +742,55 @@ handle_set_quota(void *cls, const struct QuotaSetMessage *qm) * @param cls the handle to the transport service */ static void -reconnect(void *cls) +reconnect (void *cls) { struct GNUNET_TRANSPORT_CoreHandle *h = cls; struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_var_size(hello, - GNUNET_MESSAGE_TYPE_HELLO, - struct GNUNET_MessageHeader, - h), - GNUNET_MQ_hd_fixed_size(connect, - GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, - struct ConnectInfoMessage, - h), - GNUNET_MQ_hd_fixed_size(disconnect, - GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, - struct DisconnectInfoMessage, - h), - GNUNET_MQ_hd_fixed_size(send_ok, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, - struct SendOkMessage, - h), - GNUNET_MQ_hd_var_size(recv, - GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, - struct InboundMessage, - h), - GNUNET_MQ_hd_fixed_size(set_quota, - GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, - struct QuotaSetMessage, - h), - GNUNET_MQ_handler_end() }; + { GNUNET_MQ_hd_var_size (hello, + GNUNET_MESSAGE_TYPE_HELLO, + struct GNUNET_MessageHeader, + h), + GNUNET_MQ_hd_fixed_size (connect, + GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, + struct ConnectInfoMessage, + h), + GNUNET_MQ_hd_fixed_size (disconnect, + GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, + struct DisconnectInfoMessage, + h), + GNUNET_MQ_hd_fixed_size (send_ok, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, + struct SendOkMessage, + h), + GNUNET_MQ_hd_var_size (recv, + GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, + struct InboundMessage, + h), + GNUNET_MQ_hd_fixed_size (set_quota, + GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, + struct QuotaSetMessage, + h), + GNUNET_MQ_handler_end () }; struct GNUNET_MQ_Envelope *env; struct StartMessage *s; uint32_t options; h->reconnect_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); - GNUNET_assert(NULL == h->mq); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); + GNUNET_assert (NULL == h->mq); h->mq = - GNUNET_CLIENT_connect(h->cfg, "transport", handlers, &mq_error_handler, h); + GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); if (NULL == h->mq) return; - env = GNUNET_MQ_msg(s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); + env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); options = 0; if (h->check_self) options |= 1; if (NULL != h->handlers) options |= 2; - s->options = htonl(options); + s->options = htonl (options); s->self = h->self; - GNUNET_MQ_send(h->mq, env); + GNUNET_MQ_send (h->mq, env); } @@ -799,22 +801,22 @@ reconnect(void *cls) * @param h transport service to reconnect */ static void -disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h) +disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) { - GNUNET_assert(NULL == h->reconnect_task); + GNUNET_assert (NULL == h->reconnect_task); /* Forget about all neighbours that we used to be connected to */ - GNUNET_CONTAINER_multipeermap_iterate(h->neighbours, &neighbour_delete, h); + GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h); if (NULL != h->mq) - { - GNUNET_MQ_destroy(h->mq); - h->mq = NULL; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Scheduling task to reconnect to transport service in %s.\n", - GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Scheduling task to reconnect to transport service in %s.\n", + GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); h->reconnect_task = - GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); - h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); + GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); + h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); } @@ -826,12 +828,12 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h) * @return NULL if disconnected, otherwise message queue for @a peer */ struct GNUNET_MQ_Handle * -GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, - const struct GNUNET_PeerIdentity *peer) +GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, + const struct GNUNET_PeerIdentity *peer) { struct Neighbour *n; - n = neighbour_find(handle, peer); + n = neighbour_find (handle, peer); if (NULL == n) return NULL; return n->mq; @@ -853,23 +855,23 @@ GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, * @return NULL on error */ struct GNUNET_TRANSPORT_CoreHandle * -GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_PeerIdentity *self, - const struct GNUNET_MQ_MessageHandler *handlers, - void *cls, - GNUNET_TRANSPORT_NotifyConnect nc, - GNUNET_TRANSPORT_NotifyDisconnect nd, - GNUNET_TRANSPORT_NotifyExcessBandwidth neb) +GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *self, + const struct GNUNET_MQ_MessageHandler *handlers, + void *cls, + GNUNET_TRANSPORT_NotifyConnect nc, + GNUNET_TRANSPORT_NotifyDisconnect nd, + GNUNET_TRANSPORT_NotifyExcessBandwidth neb) { struct GNUNET_TRANSPORT_CoreHandle *h; unsigned int i; - h = GNUNET_new(struct GNUNET_TRANSPORT_CoreHandle); + h = GNUNET_new (struct GNUNET_TRANSPORT_CoreHandle); if (NULL != self) - { - h->self = *self; - h->check_self = GNUNET_YES; - } + { + h->self = *self; + h->check_self = GNUNET_YES; + } h->cfg = cfg; h->cls = cls; h->nc_cb = nc; @@ -877,24 +879,24 @@ GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, h->neb_cb = neb; h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; if (NULL != handlers) - { - for (i = 0; NULL != handlers[i].cb; i++) - ; - h->handlers = GNUNET_new_array(i + 1, struct GNUNET_MQ_MessageHandler); - GNUNET_memcpy(h->handlers, - handlers, - i * sizeof(struct GNUNET_MQ_MessageHandler)); - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); - reconnect(h); + { + for (i = 0; NULL != handlers[i].cb; i++) + ; + h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler); + GNUNET_memcpy (h->handlers, + handlers, + i * sizeof(struct GNUNET_MQ_MessageHandler)); + } + LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); + reconnect (h); if (NULL == h->mq) - { - GNUNET_free_non_null(h->handlers); - GNUNET_free(h); - return NULL; - } + { + GNUNET_free_non_null (h->handlers); + GNUNET_free (h); + return NULL; + } h->neighbours = - GNUNET_CONTAINER_multipeermap_create(STARTING_NEIGHBOURS_SIZE, GNUNET_YES); + GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); return h; } @@ -906,23 +908,23 @@ GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, * #GNUNET_TRANSPORT_core_connect() */ void -GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle) +GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); /* this disconnects all neighbours... */ if (NULL == handle->reconnect_task) - disconnect_and_schedule_reconnect(handle); + disconnect_and_schedule_reconnect (handle); /* and now we stop trying to connect again... */ if (NULL != handle->reconnect_task) - { - GNUNET_SCHEDULER_cancel(handle->reconnect_task); - handle->reconnect_task = NULL; - } - GNUNET_CONTAINER_multipeermap_destroy(handle->neighbours); + { + GNUNET_SCHEDULER_cancel (handle->reconnect_task); + handle->reconnect_task = NULL; + } + GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); handle->neighbours = NULL; - GNUNET_free_non_null(handle->handlers); + GNUNET_free_non_null (handle->handlers); handle->handlers = NULL; - GNUNET_free(handle); + GNUNET_free (handle); } @@ -947,18 +949,18 @@ GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle) * @param pid which peer was the message from that was fully processed by CORE */ void -GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch, - const struct GNUNET_PeerIdentity *pid) +GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch, + const struct GNUNET_PeerIdentity *pid) { struct RecvOkMessage *rom; struct GNUNET_MQ_Envelope *env; - GNUNET_assert(ch->rom_pending > 0); + GNUNET_assert (ch->rom_pending > 0); ch->rom_pending--; - env = GNUNET_MQ_msg(rom, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); - rom->increase_window_delta = htonl(1); + env = GNUNET_MQ_msg (rom, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); + rom->increase_window_delta = htonl (1); rom->peer = *pid; - GNUNET_MQ_send(ch->mq, env); + GNUNET_MQ_send (ch->mq, env); } diff --git a/src/transport/transport_api_hello_get.c b/src/transport/transport_api_hello_get.c index 0f53148af..f8bcc5f07 100644 --- a/src/transport/transport_api_hello_get.c +++ b/src/transport/transport_api_hello_get.c @@ -36,7 +36,8 @@ /** * Functions to call with this peer's HELLO. */ -struct GNUNET_TRANSPORT_HelloGetHandle { +struct GNUNET_TRANSPORT_HelloGetHandle +{ /** * Our configuration. */ @@ -87,22 +88,22 @@ struct GNUNET_TRANSPORT_HelloGetHandle { * @return #GNUNET_OK if message is well-formed */ static int -check_hello(void *cls, - const struct GNUNET_MessageHeader *msg) +check_hello (void *cls, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_PeerIdentity me; if (GNUNET_OK != - GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)msg, - &me)) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Receiving (my own) HELLO message (%u bytes), I am `%s'.\n", - (unsigned int)ntohs(msg->size), - GNUNET_i2s(&me)); + GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, + &me)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Receiving (my own) HELLO message (%u bytes), I am `%s'.\n", + (unsigned int) ntohs (msg->size), + GNUNET_i2s (&me)); return GNUNET_OK; } @@ -114,13 +115,13 @@ check_hello(void *cls, * @param msg message received */ static void -handle_hello(void *cls, - const struct GNUNET_MessageHeader *msg) +handle_hello (void *cls, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; - ghh->rec(ghh->rec_cls, - msg); + ghh->rec (ghh->rec_cls, + msg); } @@ -131,7 +132,7 @@ handle_hello(void *cls, * @param ghh transport service to reconnect */ static void -schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh); +schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh); /** @@ -144,16 +145,16 @@ schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh); * @param error error code */ static void -mq_error_handler(void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Error receiving from transport service, disconnecting temporarily.\n"); - GNUNET_MQ_destroy(ghh->mq); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Error receiving from transport service, disconnecting temporarily.\n"); + GNUNET_MQ_destroy (ghh->mq); ghh->mq = NULL; - schedule_reconnect(ghh); + schedule_reconnect (ghh); } @@ -163,35 +164,35 @@ mq_error_handler(void *cls, * @param cls the handle to the transport service */ static void -reconnect(void *cls) +reconnect (void *cls) { struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size(hello, - GNUNET_MESSAGE_TYPE_HELLO, - struct GNUNET_MessageHeader, - ghh), - GNUNET_MQ_handler_end() + GNUNET_MQ_hd_var_size (hello, + GNUNET_MESSAGE_TYPE_HELLO, + struct GNUNET_MessageHeader, + ghh), + GNUNET_MQ_handler_end () }; struct GNUNET_MQ_Envelope *env; struct StartMessage *s; ghh->reconnect_task = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Connecting to transport service.\n"); - GNUNET_assert(NULL == ghh->mq); - ghh->mq = GNUNET_CLIENT_connect(ghh->cfg, - "transport", - handlers, - &mq_error_handler, - ghh); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Connecting to transport service.\n"); + GNUNET_assert (NULL == ghh->mq); + ghh->mq = GNUNET_CLIENT_connect (ghh->cfg, + "transport", + handlers, + &mq_error_handler, + ghh); if (NULL == ghh->mq) return; - env = GNUNET_MQ_msg(s, - GNUNET_MESSAGE_TYPE_TRANSPORT_START); - s->options = htonl(0); - GNUNET_MQ_send(ghh->mq, - env); + env = GNUNET_MQ_msg (s, + GNUNET_MESSAGE_TYPE_TRANSPORT_START); + s->options = htonl (0); + GNUNET_MQ_send (ghh->mq, + env); } @@ -202,13 +203,13 @@ reconnect(void *cls) * @param ghh transport service to reconnect */ static void -schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh) +schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh) { ghh->reconnect_task = - GNUNET_SCHEDULER_add_delayed(ghh->reconnect_delay, - &reconnect, - ghh); - ghh->reconnect_delay = GNUNET_TIME_STD_BACKOFF(ghh->reconnect_delay); + GNUNET_SCHEDULER_add_delayed (ghh->reconnect_delay, + &reconnect, + ghh); + ghh->reconnect_delay = GNUNET_TIME_STD_BACKOFF (ghh->reconnect_delay); } @@ -226,24 +227,24 @@ schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh) * @return handle to cancel the operation */ struct GNUNET_TRANSPORT_HelloGetHandle * -GNUNET_TRANSPORT_hello_get(const struct GNUNET_CONFIGURATION_Handle *cfg, - enum GNUNET_TRANSPORT_AddressClass ac, - GNUNET_TRANSPORT_HelloUpdateCallback rec, - void *rec_cls) +GNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg, + enum GNUNET_TRANSPORT_AddressClass ac, + GNUNET_TRANSPORT_HelloUpdateCallback rec, + void *rec_cls) { struct GNUNET_TRANSPORT_HelloGetHandle *ghh; - ghh = GNUNET_new(struct GNUNET_TRANSPORT_HelloGetHandle); + ghh = GNUNET_new (struct GNUNET_TRANSPORT_HelloGetHandle); ghh->rec = rec; ghh->rec_cls = rec_cls; ghh->cfg = cfg; ghh->ac = ac; - reconnect(ghh); + reconnect (ghh); if (NULL == ghh->mq) - { - GNUNET_free(ghh); - return NULL; - } + { + GNUNET_free (ghh); + return NULL; + } return ghh; } @@ -254,19 +255,19 @@ GNUNET_TRANSPORT_hello_get(const struct GNUNET_CONFIGURATION_Handle *cfg, * @param ghh handle to cancel */ void -GNUNET_TRANSPORT_hello_get_cancel(struct GNUNET_TRANSPORT_HelloGetHandle *ghh) +GNUNET_TRANSPORT_hello_get_cancel (struct GNUNET_TRANSPORT_HelloGetHandle *ghh) { if (NULL != ghh->reconnect_task) - { - GNUNET_SCHEDULER_cancel(ghh->reconnect_task); - ghh->reconnect_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (ghh->reconnect_task); + ghh->reconnect_task = NULL; + } if (NULL != ghh->mq) - { - GNUNET_MQ_destroy(ghh->mq); - ghh->mq = NULL; - } - GNUNET_free(ghh); + { + GNUNET_MQ_destroy (ghh->mq); + ghh->mq = NULL; + } + GNUNET_free (ghh); } diff --git a/src/transport/transport_api_manipulation.c b/src/transport/transport_api_manipulation.c index c4bc96aef..4f4ccc4a0 100644 --- a/src/transport/transport_api_manipulation.c +++ b/src/transport/transport_api_manipulation.c @@ -32,14 +32,15 @@ #include "gnunet_transport_service.h" #include "transport.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "transport-api", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-api", __VA_ARGS__) /** * Handle for the transport service (includes all of the * state for the transport service). */ -struct GNUNET_TRANSPORT_ManipulationHandle { +struct GNUNET_TRANSPORT_ManipulationHandle +{ /** * My client connection to the transport service. */ @@ -74,7 +75,8 @@ struct GNUNET_TRANSPORT_ManipulationHandle { * @param h transport service to reconnect */ static void -disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h); +disconnect_and_schedule_reconnect (struct + GNUNET_TRANSPORT_ManipulationHandle *h); /** @@ -87,15 +89,15 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h) * @param error error code */ static void -mq_error_handler(void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Error receiving from transport service, disconnecting temporarily.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Error receiving from transport service, disconnecting temporarily.\n"); h->reconnecting = GNUNET_YES; - disconnect_and_schedule_reconnect(h); + disconnect_and_schedule_reconnect (h); } @@ -105,31 +107,31 @@ mq_error_handler(void *cls, * @param cls the handle to the transport service */ static void -reconnect(void *cls) +reconnect (void *cls) { struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_handler_end() + GNUNET_MQ_handler_end () }; struct GNUNET_MQ_Envelope *env; struct StartMessage *s; h->reconnect_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Connecting to transport service.\n"); - GNUNET_assert(NULL == h->mq); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connecting to transport service.\n"); + GNUNET_assert (NULL == h->mq); h->reconnecting = GNUNET_NO; - h->mq = GNUNET_CLIENT_connect(h->cfg, - "transport", - handlers, - &mq_error_handler, - h); + h->mq = GNUNET_CLIENT_connect (h->cfg, + "transport", + handlers, + &mq_error_handler, + h); if (NULL == h->mq) return; - env = GNUNET_MQ_msg(s, - GNUNET_MESSAGE_TYPE_TRANSPORT_START); - GNUNET_MQ_send(h->mq, - env); + env = GNUNET_MQ_msg (s, + GNUNET_MESSAGE_TYPE_TRANSPORT_START); + GNUNET_MQ_send (h->mq, + env); } @@ -140,19 +142,20 @@ reconnect(void *cls) * @param h transport service to reconnect */ static void -disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h) +disconnect_and_schedule_reconnect (struct + GNUNET_TRANSPORT_ManipulationHandle *h) { - GNUNET_assert(NULL == h->reconnect_task); + GNUNET_assert (NULL == h->reconnect_task); if (NULL != h->mq) - { - GNUNET_MQ_destroy(h->mq); - h->mq = NULL; - } + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } h->reconnect_task = - GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, - &reconnect, - h); - h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); + GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, + &reconnect, + h); + h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); } @@ -169,27 +172,28 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h) * with one message delay. */ void -GNUNET_TRANSPORT_manipulation_set(struct GNUNET_TRANSPORT_ManipulationHandle *handle, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Properties *prop, - struct GNUNET_TIME_Relative delay_in, - struct GNUNET_TIME_Relative delay_out) +GNUNET_TRANSPORT_manipulation_set (struct + GNUNET_TRANSPORT_ManipulationHandle *handle, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_ATS_Properties *prop, + struct GNUNET_TIME_Relative delay_in, + struct GNUNET_TIME_Relative delay_out) { struct GNUNET_MQ_Envelope *env; struct TrafficMetricMessage *msg; if (NULL == handle->mq) return; - env = GNUNET_MQ_msg(msg, - GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); - msg->reserved = htonl(0); + env = GNUNET_MQ_msg (msg, + GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); + msg->reserved = htonl (0); msg->peer = *peer; - GNUNET_ATS_properties_hton(&msg->properties, - prop); - msg->delay_in = GNUNET_TIME_relative_hton(delay_in); - msg->delay_out = GNUNET_TIME_relative_hton(delay_out); - GNUNET_MQ_send(handle->mq, - env); + GNUNET_ATS_properties_hton (&msg->properties, + prop); + msg->delay_in = GNUNET_TIME_relative_hton (delay_in); + msg->delay_out = GNUNET_TIME_relative_hton (delay_out); + GNUNET_MQ_send (handle->mq, + env); } @@ -201,20 +205,21 @@ GNUNET_TRANSPORT_manipulation_set(struct GNUNET_TRANSPORT_ManipulationHandle *ha * @return NULL on error */ struct GNUNET_TRANSPORT_ManipulationHandle * -GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) +GNUNET_TRANSPORT_manipulation_connect (const struct + GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_TRANSPORT_ManipulationHandle *h; - h = GNUNET_new(struct GNUNET_TRANSPORT_ManipulationHandle); + h = GNUNET_new (struct GNUNET_TRANSPORT_ManipulationHandle); h->cfg = cfg; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Connecting to transport service.\n"); - reconnect(h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connecting to transport service.\n"); + reconnect (h); if (NULL == h->mq) - { - GNUNET_free(h); - return NULL; - } + { + GNUNET_free (h); + return NULL; + } return h; } @@ -225,17 +230,19 @@ GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle * * @param handle handle to the service as returned from #GNUNET_TRANSPORT_manipulation_connect() */ void -GNUNET_TRANSPORT_manipulation_disconnect(struct GNUNET_TRANSPORT_ManipulationHandle *handle) +GNUNET_TRANSPORT_manipulation_disconnect (struct + GNUNET_TRANSPORT_ManipulationHandle * + handle) { if (NULL == handle->reconnect_task) - disconnect_and_schedule_reconnect(handle); + disconnect_and_schedule_reconnect (handle); /* and now we stop trying to connect again... */ if (NULL != handle->reconnect_task) - { - GNUNET_SCHEDULER_cancel(handle->reconnect_task); - handle->reconnect_task = NULL; - } - GNUNET_free(handle); + { + GNUNET_SCHEDULER_cancel (handle->reconnect_task); + handle->reconnect_task = NULL; + } + GNUNET_free (handle); } diff --git a/src/transport/transport_api_monitor_peers.c b/src/transport/transport_api_monitor_peers.c index 44127eb7e..956bf9e15 100644 --- a/src/transport/transport_api_monitor_peers.c +++ b/src/transport/transport_api_monitor_peers.c @@ -39,7 +39,8 @@ /** * Context for iterating validation entries. */ -struct GNUNET_TRANSPORT_PeerMonitoringContext { +struct GNUNET_TRANSPORT_PeerMonitoringContext +{ /** * Function to call with the binary address. */ @@ -89,34 +90,34 @@ struct GNUNET_TRANSPORT_PeerMonitoringContext { * @return #GNUNET_YES or #GNUNET_NO */ int -GNUNET_TRANSPORT_is_connected(enum GNUNET_TRANSPORT_PeerState state) +GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state) { switch (state) - { - case GNUNET_TRANSPORT_PS_NOT_CONNECTED: - case GNUNET_TRANSPORT_PS_INIT_ATS: - case GNUNET_TRANSPORT_PS_SYN_SENT: - case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: - case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: - return GNUNET_NO; - - case GNUNET_TRANSPORT_PS_CONNECTED: - case GNUNET_TRANSPORT_PS_RECONNECT_ATS: - case GNUNET_TRANSPORT_PS_RECONNECT_SENT: - case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: - return GNUNET_YES; - - case GNUNET_TRANSPORT_PS_DISCONNECT: - case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: - return GNUNET_NO; - - default: - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Unhandled state `%s'\n", - GNUNET_TRANSPORT_ps2s(state)); - GNUNET_break(0); - break; - } + { + case GNUNET_TRANSPORT_PS_NOT_CONNECTED: + case GNUNET_TRANSPORT_PS_INIT_ATS: + case GNUNET_TRANSPORT_PS_SYN_SENT: + case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: + case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: + return GNUNET_NO; + + case GNUNET_TRANSPORT_PS_CONNECTED: + case GNUNET_TRANSPORT_PS_RECONNECT_ATS: + case GNUNET_TRANSPORT_PS_RECONNECT_SENT: + case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: + return GNUNET_YES; + + case GNUNET_TRANSPORT_PS_DISCONNECT: + case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: + return GNUNET_NO; + + default: + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unhandled state `%s'\n", + GNUNET_TRANSPORT_ps2s (state)); + GNUNET_break (0); + break; + } return GNUNET_SYSERR; } @@ -128,47 +129,47 @@ GNUNET_TRANSPORT_is_connected(enum GNUNET_TRANSPORT_PeerState state) * @return corresponding string */ const char * -GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state) +GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state) { switch (state) - { - case GNUNET_TRANSPORT_PS_NOT_CONNECTED: - return "S_NOT_CONNECTED"; + { + case GNUNET_TRANSPORT_PS_NOT_CONNECTED: + return "S_NOT_CONNECTED"; - case GNUNET_TRANSPORT_PS_INIT_ATS: - return "S_INIT_ATS"; + case GNUNET_TRANSPORT_PS_INIT_ATS: + return "S_INIT_ATS"; - case GNUNET_TRANSPORT_PS_SYN_SENT: - return "S_SYN_SENT"; + case GNUNET_TRANSPORT_PS_SYN_SENT: + return "S_SYN_SENT"; - case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: - return "S_SYN_RECV_ATS"; + case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: + return "S_SYN_RECV_ATS"; - case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: - return "S_SYN_RECV_ACK"; + case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: + return "S_SYN_RECV_ACK"; - case GNUNET_TRANSPORT_PS_CONNECTED: - return "S_CONNECTED"; + case GNUNET_TRANSPORT_PS_CONNECTED: + return "S_CONNECTED"; - case GNUNET_TRANSPORT_PS_RECONNECT_ATS: - return "S_RECONNECT_ATS"; + case GNUNET_TRANSPORT_PS_RECONNECT_ATS: + return "S_RECONNECT_ATS"; - case GNUNET_TRANSPORT_PS_RECONNECT_SENT: - return "S_RECONNECT_SENT"; + case GNUNET_TRANSPORT_PS_RECONNECT_SENT: + return "S_RECONNECT_SENT"; - case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: - return "S_SWITCH_SYN_SENT"; + case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: + return "S_SWITCH_SYN_SENT"; - case GNUNET_TRANSPORT_PS_DISCONNECT: - return "S_DISCONNECT"; + case GNUNET_TRANSPORT_PS_DISCONNECT: + return "S_DISCONNECT"; - case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: - return "S_DISCONNECT_FINISHED"; + case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: + return "S_DISCONNECT_FINISHED"; - default: - GNUNET_break(0); - return "UNDEFINED"; - } + default: + GNUNET_break (0); + return "UNDEFINED"; + } } @@ -178,7 +179,7 @@ GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state) * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *` */ static void -do_peer_connect(void *cls); +do_peer_connect (void *cls); /** @@ -187,20 +188,20 @@ do_peer_connect(void *cls); * @param pal_ctx our context */ static void -reconnect_peer_ctx(struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx) +reconnect_peer_ctx (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx) { - GNUNET_assert(GNUNET_NO == pal_ctx->one_shot); - GNUNET_MQ_destroy(pal_ctx->mq); + GNUNET_assert (GNUNET_NO == pal_ctx->one_shot); + GNUNET_MQ_destroy (pal_ctx->mq); pal_ctx->mq = NULL; - pal_ctx->cb(pal_ctx->cb_cls, - NULL, - NULL, - GNUNET_TRANSPORT_PS_NOT_CONNECTED, - GNUNET_TIME_UNIT_ZERO_ABS); - pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF(pal_ctx->backoff); - pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed(pal_ctx->backoff, - &do_peer_connect, - pal_ctx); + pal_ctx->cb (pal_ctx->cb_cls, + NULL, + NULL, + GNUNET_TRANSPORT_PS_NOT_CONNECTED, + GNUNET_TIME_UNIT_ZERO_ABS); + pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff); + pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff, + &do_peer_connect, + pal_ctx); } @@ -211,25 +212,25 @@ reconnect_peer_ctx(struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx) * @param msg message from service */ static void -handle_response_end(void *cls, - const struct GNUNET_MessageHeader *msg) +handle_response_end (void *cls, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; if (pal_ctx->one_shot) - { - /* iteration finished */ - pal_ctx->cb(pal_ctx->cb_cls, - NULL, - NULL, - GNUNET_TRANSPORT_PS_NOT_CONNECTED, - GNUNET_TIME_UNIT_ZERO_ABS); - GNUNET_TRANSPORT_monitor_peers_cancel(pal_ctx); - return; - } + { + /* iteration finished */ + pal_ctx->cb (pal_ctx->cb_cls, + NULL, + NULL, + GNUNET_TRANSPORT_PS_NOT_CONNECTED, + GNUNET_TIME_UNIT_ZERO_ABS); + GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx); + return; + } /* not quite what we expected, reconnect */ - GNUNET_break(0); - reconnect_peer_ctx(pal_ctx); + GNUNET_break (0); + reconnect_peer_ctx (pal_ctx); } @@ -241,34 +242,34 @@ handle_response_end(void *cls, * @return #GNUNET_OK if @a pir_msg is well-formed */ static int -check_response(void *cls, - const struct PeerIterateResponseMessage *pir_msg) +check_response (void *cls, + const struct PeerIterateResponseMessage *pir_msg) { - uint16_t size = ntohs(pir_msg->header.size) - sizeof(*pir_msg); - size_t alen = ntohl(pir_msg->addrlen); - size_t tlen = ntohl(pir_msg->pluginlen); + uint16_t size = ntohs (pir_msg->header.size) - sizeof(*pir_msg); + size_t alen = ntohl (pir_msg->addrlen); + size_t tlen = ntohl (pir_msg->pluginlen); const char *addr; const char *transport_name; if (size != tlen + alen) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if ((0 == tlen) && (0 == alen)) return GNUNET_OK; if (0 == tlen) - { - GNUNET_break(0); /* This must not happen: address without plugin */ - return GNUNET_SYSERR; - } - addr = (const char *)&pir_msg[1]; + { + GNUNET_break (0); /* This must not happen: address without plugin */ + return GNUNET_SYSERR; + } + addr = (const char *) &pir_msg[1]; transport_name = &addr[alen]; if (transport_name[tlen - 1] != '\0') - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -280,42 +281,42 @@ check_response(void *cls, * @param msg message with the human-readable address */ static void -handle_response(void *cls, - const struct PeerIterateResponseMessage *pir_msg) +handle_response (void *cls, + const struct PeerIterateResponseMessage *pir_msg) { struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; struct GNUNET_HELLO_Address *address; - size_t alen = ntohl(pir_msg->addrlen); - size_t tlen = ntohl(pir_msg->pluginlen); + size_t alen = ntohl (pir_msg->addrlen); + size_t tlen = ntohl (pir_msg->pluginlen); const char *addr; const char *transport_name; if ((0 == tlen) && (0 == alen)) - { - /* No address available */ - pal_ctx->cb(pal_ctx->cb_cls, - &pir_msg->peer, - NULL, - ntohl(pir_msg->state), - GNUNET_TIME_absolute_ntoh(pir_msg->state_timeout)); - return; - } - addr = (const char *)&pir_msg[1]; + { + /* No address available */ + pal_ctx->cb (pal_ctx->cb_cls, + &pir_msg->peer, + NULL, + ntohl (pir_msg->state), + GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout)); + return; + } + addr = (const char *) &pir_msg[1]; transport_name = &addr[alen]; /* notify client */ - address = GNUNET_HELLO_address_allocate(&pir_msg->peer, - transport_name, - addr, - alen, - ntohl(pir_msg->local_address_info)); - pal_ctx->cb(pal_ctx->cb_cls, - &pir_msg->peer, - address, - ntohl(pir_msg->state), - GNUNET_TIME_absolute_ntoh(pir_msg->state_timeout)); - GNUNET_HELLO_address_free(address); + address = GNUNET_HELLO_address_allocate (&pir_msg->peer, + transport_name, + addr, + alen, + ntohl (pir_msg->local_address_info)); + pal_ctx->cb (pal_ctx->cb_cls, + &pir_msg->peer, + address, + ntohl (pir_msg->state), + GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout)); + GNUNET_HELLO_address_free (address); } @@ -329,23 +330,23 @@ handle_response(void *cls, * @param error error code */ static void -mq_error_handler(void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; if (pal_ctx->one_shot) - { - /* Disconnect */ - pal_ctx->cb(pal_ctx->cb_cls, - NULL, - NULL, - GNUNET_TRANSPORT_PS_NOT_CONNECTED, - GNUNET_TIME_UNIT_ZERO_ABS); - GNUNET_TRANSPORT_monitor_peers_cancel(pal_ctx); - return; - } - reconnect_peer_ctx(pal_ctx); + { + /* Disconnect */ + pal_ctx->cb (pal_ctx->cb_cls, + NULL, + NULL, + GNUNET_TRANSPORT_PS_NOT_CONNECTED, + GNUNET_TIME_UNIT_ZERO_ABS); + GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx); + return; + } + reconnect_peer_ctx (pal_ctx); } @@ -355,37 +356,37 @@ mq_error_handler(void *cls, * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *` */ static void -do_peer_connect(void *cls) +do_peer_connect (void *cls) { struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size(response, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE, - struct PeerIterateResponseMessage, - pal_ctx), - GNUNET_MQ_hd_fixed_size(response_end, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END, - struct GNUNET_MessageHeader, - pal_ctx), - GNUNET_MQ_handler_end() + GNUNET_MQ_hd_var_size (response, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE, + struct PeerIterateResponseMessage, + pal_ctx), + GNUNET_MQ_hd_fixed_size (response_end, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END, + struct GNUNET_MessageHeader, + pal_ctx), + GNUNET_MQ_handler_end () }; struct PeerMonitorMessage *msg; struct GNUNET_MQ_Envelope *env; pal_ctx->reconnect_task = NULL; - pal_ctx->mq = GNUNET_CLIENT_connect(pal_ctx->cfg, - "transport", - handlers, - &mq_error_handler, - pal_ctx); + pal_ctx->mq = GNUNET_CLIENT_connect (pal_ctx->cfg, + "transport", + handlers, + &mq_error_handler, + pal_ctx); if (NULL == pal_ctx->mq) return; - env = GNUNET_MQ_msg(msg, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST); - msg->one_shot = htonl(pal_ctx->one_shot); + env = GNUNET_MQ_msg (msg, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST); + msg->one_shot = htonl (pal_ctx->one_shot); msg->peer = pal_ctx->peer; - GNUNET_MQ_send(pal_ctx->mq, - env); + GNUNET_MQ_send (pal_ctx->mq, + env); } @@ -416,14 +417,15 @@ do_peer_connect(void *cls) * @param peer_callback_cls closure for @a peer_address_callback */ struct GNUNET_TRANSPORT_PeerMonitoringContext * -GNUNET_TRANSPORT_monitor_peers(const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_PeerIdentity *peer, - int one_shot, - GNUNET_TRANSPORT_PeerIterateCallback peer_callback, - void *peer_callback_cls) +GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *peer, + int one_shot, + GNUNET_TRANSPORT_PeerIterateCallback + peer_callback, + void *peer_callback_cls) { struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx - = GNUNET_new(struct GNUNET_TRANSPORT_PeerMonitoringContext); + = GNUNET_new (struct GNUNET_TRANSPORT_PeerMonitoringContext); pal_ctx->cb = peer_callback; pal_ctx->cb_cls = peer_callback_cls; @@ -431,12 +433,12 @@ GNUNET_TRANSPORT_monitor_peers(const struct GNUNET_CONFIGURATION_Handle *cfg, if (NULL != peer) pal_ctx->peer = *peer; pal_ctx->one_shot = one_shot; - do_peer_connect(pal_ctx); + do_peer_connect (pal_ctx); if (NULL == pal_ctx->mq) - { - GNUNET_free(pal_ctx); - return NULL; - } + { + GNUNET_free (pal_ctx); + return NULL; + } return pal_ctx; } @@ -447,19 +449,21 @@ GNUNET_TRANSPORT_monitor_peers(const struct GNUNET_CONFIGURATION_Handle *cfg, * @param pic handle for the request to cancel */ void -GNUNET_TRANSPORT_monitor_peers_cancel(struct GNUNET_TRANSPORT_PeerMonitoringContext *pic) +GNUNET_TRANSPORT_monitor_peers_cancel (struct + GNUNET_TRANSPORT_PeerMonitoringContext * + pic) { if (NULL != pic->mq) - { - GNUNET_MQ_destroy(pic->mq); - pic->mq = NULL; - } + { + GNUNET_MQ_destroy (pic->mq); + pic->mq = NULL; + } if (NULL != pic->reconnect_task) - { - GNUNET_SCHEDULER_cancel(pic->reconnect_task); - pic->reconnect_task = NULL; - } - GNUNET_free(pic); + { + GNUNET_SCHEDULER_cancel (pic->reconnect_task); + pic->reconnect_task = NULL; + } + GNUNET_free (pic); } diff --git a/src/transport/transport_api_monitor_plugins.c b/src/transport/transport_api_monitor_plugins.c index 12d052008..7910a57c2 100644 --- a/src/transport/transport_api_monitor_plugins.c +++ b/src/transport/transport_api_monitor_plugins.c @@ -35,7 +35,8 @@ /** * Handle for a plugin session state monitor. */ -struct GNUNET_TRANSPORT_PluginMonitor { +struct GNUNET_TRANSPORT_PluginMonitor +{ /** * Connection to the service. */ @@ -78,7 +79,8 @@ struct GNUNET_TRANSPORT_PluginMonitor { * Abstract representation of a plugin's session. * Corresponds to the `struct GNUNET_ATS_Session` within the TRANSPORT service. */ -struct GNUNET_TRANSPORT_PluginSession { +struct GNUNET_TRANSPORT_PluginSession +{ /** * Unique session identifier. */ @@ -98,7 +100,7 @@ struct GNUNET_TRANSPORT_PluginSession { * @param cls our `struct GNUNET_TRANSPORT_PluginMonitor *` */ static void -do_plugin_connect(void *cls); +do_plugin_connect (void *cls); /** @@ -110,23 +112,23 @@ do_plugin_connect(void *cls); * @return #GNUNET_OK (continue to iterate) */ static int -free_entry(void *cls, - uint32_t key, - void *value) +free_entry (void *cls, + uint32_t key, + void *value) { struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; struct GNUNET_TRANSPORT_PluginSession *ps = value; - pm->cb(pm->cb_cls, - ps, - &ps->client_ctx, - NULL); - GNUNET_break(GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove(pm->sessions, - key, - ps)); - GNUNET_break(NULL == ps->client_ctx); - GNUNET_free(ps); + pm->cb (pm->cb_cls, + ps, + &ps->client_ctx, + NULL); + GNUNET_break (GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_remove (pm->sessions, + key, + ps)); + GNUNET_break (NULL == ps->client_ctx); + GNUNET_free (ps); return GNUNET_OK; } @@ -137,17 +139,17 @@ free_entry(void *cls, * @param pm our context */ static void -reconnect_plugin_ctx(struct GNUNET_TRANSPORT_PluginMonitor *pm) +reconnect_plugin_ctx (struct GNUNET_TRANSPORT_PluginMonitor *pm) { - GNUNET_MQ_destroy(pm->mq); + GNUNET_MQ_destroy (pm->mq); pm->mq = NULL; - GNUNET_CONTAINER_multihashmap32_iterate(pm->sessions, - &free_entry, - pm); - pm->backoff = GNUNET_TIME_STD_BACKOFF(pm->backoff); - pm->reconnect_task = GNUNET_SCHEDULER_add_delayed(pm->backoff, - &do_plugin_connect, - pm); + GNUNET_CONTAINER_multihashmap32_iterate (pm->sessions, + &free_entry, + pm); + pm->backoff = GNUNET_TIME_STD_BACKOFF (pm->backoff); + pm->reconnect_task = GNUNET_SCHEDULER_add_delayed (pm->backoff, + &do_plugin_connect, + pm); } @@ -158,16 +160,17 @@ reconnect_plugin_ctx(struct GNUNET_TRANSPORT_PluginMonitor *pm) * @return 32-bit hash map index */ static uint32_t -wrap_id(uint64_t id) +wrap_id (uint64_t id) { - return ((uint32_t)id) ^ ((uint32_t)(id >> 32)); + return ((uint32_t) id) ^ ((uint32_t) (id >> 32)); } /** * Context for #locate_by_id(). */ -struct SearchContext { +struct SearchContext +{ /** * Result. */ @@ -189,18 +192,18 @@ struct SearchContext { * @return #GNUNET_OK (continue to iterate), or #GNUNET_SYSERR (match found) */ static int -locate_by_id(void *cls, - uint32_t key, - void *value) +locate_by_id (void *cls, + uint32_t key, + void *value) { struct SearchContext *sc = cls; struct GNUNET_TRANSPORT_PluginSession *ps = value; if (sc->session_id == ps->session_id) - { - sc->ps = ps; - return GNUNET_SYSERR; - } + { + sc->ps = ps; + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -213,25 +216,26 @@ locate_by_id(void *cls, * @return #GNUNET_Ok if message is well-formed */ static int -check_event(void *cls, - const struct TransportPluginMonitorMessage *tpmm) +check_event (void *cls, + const struct TransportPluginMonitorMessage *tpmm) { const char *pname; size_t pname_len; size_t paddr_len; - pname = (const char *)&tpmm[1]; - pname_len = ntohs(tpmm->plugin_name_len); - paddr_len = ntohs(tpmm->plugin_address_len); - if ((pname_len + - paddr_len + - sizeof(struct TransportPluginMonitorMessage) != ntohs(tpmm->header.size)) || + pname = (const char *) &tpmm[1]; + pname_len = ntohs (tpmm->plugin_name_len); + paddr_len = ntohs (tpmm->plugin_address_len); + if ((pname_len + + paddr_len + + sizeof(struct TransportPluginMonitorMessage) != ntohs ( + tpmm->header.size)) || ((0 != pname_len) && ('\0' != pname[pname_len - 1]))) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -243,8 +247,8 @@ check_event(void *cls, * @paramm tpmm message with event data */ static void -handle_event(void *cls, - const struct TransportPluginMonitorMessage *tpmm) +handle_event (void *cls, + const struct TransportPluginMonitorMessage *tpmm) { struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; struct GNUNET_TRANSPORT_PluginSession *ps; @@ -257,63 +261,65 @@ handle_event(void *cls, struct GNUNET_HELLO_Address addr; struct SearchContext rv; - pname = (const char *)&tpmm[1]; - pname_len = ntohs(tpmm->plugin_name_len); - paddr_len = ntohs(tpmm->plugin_address_len); + pname = (const char *) &tpmm[1]; + pname_len = ntohs (tpmm->plugin_name_len); + paddr_len = ntohs (tpmm->plugin_address_len); paddr = &pname[pname_len]; ps = NULL; - ss = (enum GNUNET_TRANSPORT_SessionState)ntohs(tpmm->session_state); + ss = (enum GNUNET_TRANSPORT_SessionState) ntohs (tpmm->session_state); if (GNUNET_TRANSPORT_SS_INIT == ss) - { - ps = GNUNET_new(struct GNUNET_TRANSPORT_PluginSession); - ps->session_id = tpmm->session_id; - (void)GNUNET_CONTAINER_multihashmap32_put(pm->sessions, - wrap_id(tpmm->session_id), + { + ps = GNUNET_new (struct GNUNET_TRANSPORT_PluginSession); + ps->session_id = tpmm->session_id; + (void) GNUNET_CONTAINER_multihashmap32_put (pm->sessions, + wrap_id (tpmm->session_id), ps, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - } + } else - { - rv.session_id = tpmm->session_id; - rv.ps = NULL; - (void)GNUNET_CONTAINER_multihashmap32_get_multiple(pm->sessions, - wrap_id(tpmm->session_id), + { + rv.session_id = tpmm->session_id; + rv.ps = NULL; + (void) GNUNET_CONTAINER_multihashmap32_get_multiple (pm->sessions, + wrap_id ( + tpmm->session_id), &locate_by_id, &rv); - ps = rv.ps; - if (NULL == ps) - { - GNUNET_break(0); - reconnect_plugin_ctx(pm); - return; - } + ps = rv.ps; + if (NULL == ps) + { + GNUNET_break (0); + reconnect_plugin_ctx (pm); + return; } + } info.state = ss; - info.is_inbound = (int16_t)ntohs(tpmm->is_inbound); - info.num_msg_pending = ntohl(tpmm->msgs_pending); - info.num_bytes_pending = ntohl(tpmm->bytes_pending); - info.receive_delay = GNUNET_TIME_absolute_ntoh(tpmm->delay); - info.session_timeout = GNUNET_TIME_absolute_ntoh(tpmm->timeout); + info.is_inbound = (int16_t) ntohs (tpmm->is_inbound); + info.num_msg_pending = ntohl (tpmm->msgs_pending); + info.num_bytes_pending = ntohl (tpmm->bytes_pending); + info.receive_delay = GNUNET_TIME_absolute_ntoh (tpmm->delay); + info.session_timeout = GNUNET_TIME_absolute_ntoh (tpmm->timeout); info.address = &addr; addr.peer = tpmm->peer; addr.address = (0 == paddr_len) ? NULL : paddr; addr.address_length = paddr_len; addr.transport_name = (0 == pname_len) ? NULL : pname; addr.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; - pm->cb(pm->cb_cls, - ps, - &ps->client_ctx, - &info); + pm->cb (pm->cb_cls, + ps, + &ps->client_ctx, + &info); if (GNUNET_TRANSPORT_SS_DONE == ss) - { - GNUNET_break(NULL == ps->client_ctx); - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove(pm->sessions, - wrap_id(tpmm->session_id), + { + GNUNET_break (NULL == ps->client_ctx); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_remove (pm->sessions, + wrap_id ( + tpmm->session_id), ps)); - GNUNET_free(ps); - } + GNUNET_free (ps); + } } @@ -324,16 +330,16 @@ handle_event(void *cls, * @param msg message from the service */ static void -handle_sync(void *cls, - const struct GNUNET_MessageHeader *msg) +handle_sync (void *cls, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; /* we are in sync, notify callback */ - pm->cb(pm->cb_cls, - NULL, - NULL, - NULL); + pm->cb (pm->cb_cls, + NULL, + NULL, + NULL); } @@ -347,12 +353,12 @@ handle_sync(void *cls, * @param error error code */ static void -mq_error_handler(void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; - reconnect_plugin_ctx(pm); + reconnect_plugin_ctx (pm); } @@ -362,35 +368,35 @@ mq_error_handler(void *cls, * @param cls our `struct GNUNET_TRANSPORT_PluginMonitor *` */ static void -do_plugin_connect(void *cls) +do_plugin_connect (void *cls) { struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size(event, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT, - struct TransportPluginMonitorMessage, - pm), - GNUNET_MQ_hd_fixed_size(sync, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC, - struct GNUNET_MessageHeader, - pm), - GNUNET_MQ_handler_end() + GNUNET_MQ_hd_var_size (event, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT, + struct TransportPluginMonitorMessage, + pm), + GNUNET_MQ_hd_fixed_size (sync, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC, + struct GNUNET_MessageHeader, + pm), + GNUNET_MQ_handler_end () }; struct GNUNET_MessageHeader *msg; struct GNUNET_MQ_Envelope *env; pm->reconnect_task = NULL; - pm->mq = GNUNET_CLIENT_connect(pm->cfg, - "transport", - handlers, - &mq_error_handler, - pm); + pm->mq = GNUNET_CLIENT_connect (pm->cfg, + "transport", + handlers, + &mq_error_handler, + pm); if (NULL == pm->mq) return; - env = GNUNET_MQ_msg(msg, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START); - GNUNET_MQ_send(pm->mq, - env); + env = GNUNET_MQ_msg (msg, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START); + GNUNET_MQ_send (pm->mq, + env); } @@ -404,23 +410,23 @@ do_plugin_connect(void *cls) * @return NULL on error, otherwise handle for cancellation */ struct GNUNET_TRANSPORT_PluginMonitor * -GNUNET_TRANSPORT_monitor_plugins(const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_TRANSPORT_SessionMonitorCallback cb, - void *cb_cls) +GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_TRANSPORT_SessionMonitorCallback cb, + void *cb_cls) { struct GNUNET_TRANSPORT_PluginMonitor *pm; - pm = GNUNET_new(struct GNUNET_TRANSPORT_PluginMonitor); + pm = GNUNET_new (struct GNUNET_TRANSPORT_PluginMonitor); pm->cb = cb; pm->cb_cls = cb_cls; pm->cfg = cfg; - do_plugin_connect(pm); + do_plugin_connect (pm); if (NULL == pm->mq) - { - GNUNET_free(pm); - return NULL; - } - pm->sessions = GNUNET_CONTAINER_multihashmap32_create(128); + { + GNUNET_free (pm); + return NULL; + } + pm->sessions = GNUNET_CONTAINER_multihashmap32_create (128); return pm; } @@ -434,23 +440,24 @@ GNUNET_TRANSPORT_monitor_plugins(const struct GNUNET_CONFIGURATION_Handle *cfg, * @param pm handle of the request that is to be cancelled */ void -GNUNET_TRANSPORT_monitor_plugins_cancel(struct GNUNET_TRANSPORT_PluginMonitor *pm) +GNUNET_TRANSPORT_monitor_plugins_cancel (struct + GNUNET_TRANSPORT_PluginMonitor *pm) { if (NULL != pm->mq) - { - GNUNET_MQ_destroy(pm->mq); - pm->mq = NULL; - } + { + GNUNET_MQ_destroy (pm->mq); + pm->mq = NULL; + } if (NULL != pm->reconnect_task) - { - GNUNET_SCHEDULER_cancel(pm->reconnect_task); - pm->reconnect_task = NULL; - } - GNUNET_CONTAINER_multihashmap32_iterate(pm->sessions, - &free_entry, - pm); - GNUNET_CONTAINER_multihashmap32_destroy(pm->sessions); - GNUNET_free(pm); + { + GNUNET_SCHEDULER_cancel (pm->reconnect_task); + pm->reconnect_task = NULL; + } + GNUNET_CONTAINER_multihashmap32_iterate (pm->sessions, + &free_entry, + pm); + GNUNET_CONTAINER_multihashmap32_destroy (pm->sessions); + GNUNET_free (pm); } diff --git a/src/transport/transport_api_offer_hello.c b/src/transport/transport_api_offer_hello.c index 89f8d463d..eb342f57c 100644 --- a/src/transport/transport_api_offer_hello.c +++ b/src/transport/transport_api_offer_hello.c @@ -33,7 +33,8 @@ /** * Entry in linked list for all offer-HELLO requests. */ -struct GNUNET_TRANSPORT_OfferHelloHandle { +struct GNUNET_TRANSPORT_OfferHelloHandle +{ /** * Transport service handle we use for transmission. */ @@ -57,13 +58,13 @@ struct GNUNET_TRANSPORT_OfferHelloHandle { * @param cls the handle for the operation */ static void -finished_hello(void *cls) +finished_hello (void *cls) { struct GNUNET_TRANSPORT_OfferHelloHandle *ohh = cls; if (NULL != ohh->cont) - ohh->cont(ohh->cls); - GNUNET_TRANSPORT_offer_hello_cancel(ohh); + ohh->cont (ohh->cls); + GNUNET_TRANSPORT_offer_hello_cancel (ohh); } @@ -83,43 +84,43 @@ finished_hello(void *cls) * */ struct GNUNET_TRANSPORT_OfferHelloHandle * -GNUNET_TRANSPORT_offer_hello(const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_MessageHeader *hello, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) +GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_MessageHeader *hello, + GNUNET_SCHEDULER_TaskCallback cont, + void *cont_cls) { struct GNUNET_TRANSPORT_OfferHelloHandle *ohh - = GNUNET_new(struct GNUNET_TRANSPORT_OfferHelloHandle); + = GNUNET_new (struct GNUNET_TRANSPORT_OfferHelloHandle); struct GNUNET_MQ_Envelope *env; struct GNUNET_PeerIdentity peer; if (GNUNET_OK != - GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)hello, - &peer)) - { - GNUNET_break(0); - GNUNET_free(ohh); - return NULL; - } - ohh->mq = GNUNET_CLIENT_connect(cfg, - "transport", - NULL, - NULL, - ohh); + GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, + &peer)) + { + GNUNET_break (0); + GNUNET_free (ohh); + return NULL; + } + ohh->mq = GNUNET_CLIENT_connect (cfg, + "transport", + NULL, + NULL, + ohh); if (NULL == ohh->mq) - { - GNUNET_free(ohh); - return NULL; - } + { + GNUNET_free (ohh); + return NULL; + } ohh->cont = cont; ohh->cls = cont_cls; - GNUNET_break(ntohs(hello->type) == GNUNET_MESSAGE_TYPE_HELLO); - env = GNUNET_MQ_msg_copy(hello); - GNUNET_MQ_notify_sent(env, - &finished_hello, - ohh); - GNUNET_MQ_send(ohh->mq, - env); + GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO); + env = GNUNET_MQ_msg_copy (hello); + GNUNET_MQ_notify_sent (env, + &finished_hello, + ohh); + GNUNET_MQ_send (ohh->mq, + env); return ohh; } @@ -130,10 +131,11 @@ GNUNET_TRANSPORT_offer_hello(const struct GNUNET_CONFIGURATION_Handle *cfg, * @param ohh the handle for the operation to cancel */ void -GNUNET_TRANSPORT_offer_hello_cancel(struct GNUNET_TRANSPORT_OfferHelloHandle *ohh) +GNUNET_TRANSPORT_offer_hello_cancel (struct + GNUNET_TRANSPORT_OfferHelloHandle *ohh) { - GNUNET_MQ_destroy(ohh->mq); - GNUNET_free(ohh); + GNUNET_MQ_destroy (ohh->mq); + GNUNET_free (ohh); } -- cgit v1.2.3