aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/transport
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/communicator.h6
-rw-r--r--src/transport/gnunet-communicator-tcp.c1798
-rw-r--r--src/transport/gnunet-communicator-udp.c2214
-rw-r--r--src/transport/gnunet-communicator-unix.c911
-rw-r--r--src/transport/gnunet-helper-transport-bluetooth.c2585
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c565
-rw-r--r--src/transport/gnunet-helper-transport-wlan.c1514
-rw-r--r--src/transport/gnunet-service-tng.c7587
-rw-r--r--src/transport/gnunet-service-transport.c2336
-rw-r--r--src/transport/gnunet-service-transport.h64
-rw-r--r--src/transport/gnunet-service-transport_ats.c750
-rw-r--r--src/transport/gnunet-service-transport_ats.h52
-rw-r--r--src/transport/gnunet-service-transport_hello.c205
-rw-r--r--src/transport/gnunet-service-transport_hello.h20
-rw-r--r--src/transport/gnunet-service-transport_manipulation.c478
-rw-r--r--src/transport/gnunet-service-transport_manipulation.h34
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c4423
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h89
-rw-r--r--src/transport/gnunet-service-transport_plugins.c447
-rw-r--r--src/transport/gnunet-service-transport_plugins.h20
-rw-r--r--src/transport/gnunet-service-transport_validation.c1721
-rw-r--r--src/transport/gnunet-service-transport_validation.h28
-rw-r--r--src/transport/gnunet-transport-profiler.c529
-rw-r--r--src/transport/gnunet-transport-wlan-receiver.c120
-rw-r--r--src/transport/gnunet-transport-wlan-sender.c256
-rw-r--r--src/transport/gnunet-transport.c1202
-rw-r--r--src/transport/ieee80211_radiotap.h14
-rw-r--r--src/transport/plugin_transport_http.h96
-rw-r--r--src/transport/plugin_transport_http_client.c2473
-rw-r--r--src/transport/plugin_transport_http_common.c968
-rw-r--r--src/transport/plugin_transport_http_common.h96
-rw-r--r--src/transport/plugin_transport_http_server.c3550
-rw-r--r--src/transport/plugin_transport_smtp.c638
-rw-r--r--src/transport/plugin_transport_tcp.c3540
-rw-r--r--src/transport/plugin_transport_template.c183
-rw-r--r--src/transport/plugin_transport_udp.c3821
-rw-r--r--src/transport/plugin_transport_udp.h40
-rw-r--r--src/transport/plugin_transport_udp_broadcasting.c624
-rw-r--r--src/transport/plugin_transport_unix.c1566
-rw-r--r--src/transport/plugin_transport_wlan.c2059
-rw-r--r--src/transport/plugin_transport_wlan.h18
-rw-r--r--src/transport/tcp_connection_legacy.c1304
-rw-r--r--src/transport/tcp_server_legacy.c1256
-rw-r--r--src/transport/tcp_server_mst_legacy.c323
-rw-r--r--src/transport/tcp_service_legacy.c1639
-rw-r--r--src/transport/test_communicator_unix.c228
-rw-r--r--src/transport/test_http_common.c293
-rw-r--r--src/transport/test_plugin_transport.c826
-rw-r--r--src/transport/test_quota_compliance.c316
-rw-r--r--src/transport/test_transport_address_switch.c354
-rw-r--r--src/transport/test_transport_api.c75
-rw-r--r--src/transport/test_transport_api_blacklisting.c165
-rw-r--r--src/transport/test_transport_api_disconnect.c91
-rw-r--r--src/transport/test_transport_api_limited_sockets.c70
-rw-r--r--src/transport/test_transport_api_manipulation_cfg.c172
-rw-r--r--src/transport/test_transport_api_manipulation_recv_tcp.c171
-rw-r--r--src/transport/test_transport_api_manipulation_send_tcp.c169
-rw-r--r--src/transport/test_transport_api_monitor_peers.c191
-rw-r--r--src/transport/test_transport_api_reliability.c209
-rw-r--r--src/transport/test_transport_api_restart_reconnect.c169
-rw-r--r--src/transport/test_transport_api_timeout.c122
-rw-r--r--src/transport/test_transport_blacklisting.c737
-rw-r--r--src/transport/test_transport_testing_restart.c138
-rw-r--r--src/transport/test_transport_testing_startstop.c106
-rw-r--r--src/transport/transport-testing-filenames.c98
-rw-r--r--src/transport/transport-testing-loggers.c45
-rw-r--r--src/transport/transport-testing-main.c445
-rw-r--r--src/transport/transport-testing-send.c191
-rw-r--r--src/transport/transport-testing.c1027
-rw-r--r--src/transport/transport-testing.h78
-rw-r--r--src/transport/transport-testing2.c445
-rw-r--r--src/transport/transport-testing2.h62
-rw-r--r--src/transport/transport.h113
-rw-r--r--src/transport/transport_api2_application.c184
-rw-r--r--src/transport/transport_api2_communication.c455
-rw-r--r--src/transport/transport_api2_core.c484
-rw-r--r--src/transport/transport_api2_monitor.c127
-rw-r--r--src/transport/transport_api_address_to_string.c211
-rw-r--r--src/transport/transport_api_blacklist.c85
-rw-r--r--src/transport/transport_api_core.c600
-rw-r--r--src/transport/transport_api_hello_get.c137
-rw-r--r--src/transport/transport_api_manipulation.c131
-rw-r--r--src/transport/transport_api_monitor_peers.c362
-rw-r--r--src/transport/transport_api_monitor_plugins.c285
-rw-r--r--src/transport/transport_api_offer_hello.c72
85 files changed, 32597 insertions, 31804 deletions
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
41 * just the recommended "generic" style, communicators are always free 41 * just the recommended "generic" style, communicators are always free
42 * to implement original designs that better fit their requirements. 42 * to implement original designs that better fit their requirements.
43 */ 43 */
44struct GNUNET_TRANSPORT_CommunicatorGenericKXConfirmation { 44struct GNUNET_TRANSPORT_CommunicatorGenericKXConfirmation
45{
45 /** 46 /**
46 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION 47 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION
47 */ 48 */
@@ -88,7 +89,8 @@ struct GNUNET_TRANSPORT_CommunicatorGenericKXConfirmation {
88 * free to implement original designs that better fit their 89 * free to implement original designs that better fit their
89 * requirements. 90 * requirements.
90 */ 91 */
91struct GNUNET_TRANSPORT_CommunicatorGenericFCLimits { 92struct GNUNET_TRANSPORT_CommunicatorGenericFCLimits
93{
92 /** 94 /**
93 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS 95 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS
94 */ 96 */
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 @@
47 * the other peer should revalidate). 47 * the other peer should revalidate).
48 */ 48 */
49#define ADDRESS_VALIDITY_PERIOD \ 49#define ADDRESS_VALIDITY_PERIOD \
50 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) 50 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
51 51
52/** 52/**
53 * How many messages do we keep at most in the queue to the 53 * How many messages do we keep at most in the queue to the
@@ -86,8 +86,8 @@
86 * directions. 86 * directions.
87 */ 87 */
88#define INITIAL_KX_SIZE \ 88#define INITIAL_KX_SIZE \
89 (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) + \ 89 (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) \
90 sizeof(struct TCPConfirmation)) 90 + sizeof(struct TCPConfirmation))
91 91
92 92
93/** 93/**
@@ -107,7 +107,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
107 * Signature we use to verify that the ephemeral key was really chosen by 107 * Signature we use to verify that the ephemeral key was really chosen by
108 * the specified sender. 108 * the specified sender.
109 */ 109 */
110struct TcpHandshakeSignature { 110struct TcpHandshakeSignature
111{
111 /** 112 /**
112 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE 113 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE
113 */ 114 */
@@ -139,7 +140,8 @@ struct TcpHandshakeSignature {
139/** 140/**
140 * Encrypted continuation of TCP initial handshake. 141 * Encrypted continuation of TCP initial handshake.
141 */ 142 */
142struct TCPConfirmation { 143struct TCPConfirmation
144{
143 /** 145 /**
144 * Sender's identity 146 * Sender's identity
145 */ 147 */
@@ -161,7 +163,8 @@ struct TCPConfirmation {
161/** 163/**
162 * TCP message box. Always sent encrypted! 164 * TCP message box. Always sent encrypted!
163 */ 165 */
164struct TCPBox { 166struct TCPBox
167{
165 /** 168 /**
166 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX. Warning: the 169 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX. Warning: the
167 * header size EXCLUDES the size of the `struct TCPBox`. We usually 170 * header size EXCLUDES the size of the `struct TCPBox`. We usually
@@ -189,7 +192,8 @@ struct TCPBox {
189 * TCP rekey message box. Always sent encrypted! Data after 192 * TCP rekey message box. Always sent encrypted! Data after
190 * this message will use the new key. 193 * this message will use the new key.
191 */ 194 */
192struct TCPRekey { 195struct TCPRekey
196{
193 /** 197 /**
194 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY. 198 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY.
195 */ 199 */
@@ -228,7 +232,8 @@ struct TCPRekey {
228 * Needed/useful in case we drop RST/FIN packets on the GNUnet 232 * Needed/useful in case we drop RST/FIN packets on the GNUnet
229 * port due to the possibility of malicious RST/FIN injection. 233 * port due to the possibility of malicious RST/FIN injection.
230 */ 234 */
231struct TCPFinish { 235struct TCPFinish
236{
232 /** 237 /**
233 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH. 238 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH.
234 */ 239 */
@@ -252,7 +257,8 @@ GNUNET_NETWORK_STRUCT_END
252/** 257/**
253 * Handle for a queue. 258 * Handle for a queue.
254 */ 259 */
255struct Queue { 260struct Queue
261{
256 /** 262 /**
257 * To whom are we talking to. 263 * To whom are we talking to.
258 */ 264 */
@@ -430,7 +436,8 @@ struct Queue {
430 * Handle for an incoming connection where we do not yet have enough 436 * Handle for an incoming connection where we do not yet have enough
431 * information to setup a full queue. 437 * information to setup a full queue.
432 */ 438 */
433struct ProtoQueue { 439struct ProtoQueue
440{
434 /** 441 /**
435 * Kept in a DLL. 442 * Kept in a DLL.
436 */ 443 */
@@ -553,7 +560,7 @@ static struct ProtoQueue *proto_tail;
553 * @param cls NULL 560 * @param cls NULL
554 */ 561 */
555static void 562static void
556listen_cb(void *cls); 563listen_cb (void *cls);
557 564
558 565
559/** 566/**
@@ -564,53 +571,53 @@ listen_cb(void *cls);
564 * @param queue queue to close down 571 * @param queue queue to close down
565 */ 572 */
566static void 573static void
567queue_destroy(struct Queue *queue) 574queue_destroy (struct Queue *queue)
568{ 575{
569 struct GNUNET_MQ_Handle *mq; 576 struct GNUNET_MQ_Handle *mq;
570 577
571 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
572 "Disconnecting queue for peer `%s'\n", 579 "Disconnecting queue for peer `%s'\n",
573 GNUNET_i2s(&queue->target)); 580 GNUNET_i2s (&queue->target));
574 if (NULL != (mq = queue->mq)) 581 if (NULL != (mq = queue->mq))
575 { 582 {
576 queue->mq = NULL; 583 queue->mq = NULL;
577 GNUNET_MQ_destroy(mq); 584 GNUNET_MQ_destroy (mq);
578 } 585 }
579 if (NULL != queue->qh) 586 if (NULL != queue->qh)
580 { 587 {
581 GNUNET_TRANSPORT_communicator_mq_del(queue->qh); 588 GNUNET_TRANSPORT_communicator_mq_del (queue->qh);
582 queue->qh = NULL; 589 queue->qh = NULL;
583 } 590 }
584 GNUNET_assert( 591 GNUNET_assert (
585 GNUNET_YES == 592 GNUNET_YES ==
586 GNUNET_CONTAINER_multipeermap_remove(queue_map, &queue->target, queue)); 593 GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue));
587 GNUNET_STATISTICS_set(stats, 594 GNUNET_STATISTICS_set (stats,
588 "# queues active", 595 "# queues active",
589 GNUNET_CONTAINER_multipeermap_size(queue_map), 596 GNUNET_CONTAINER_multipeermap_size (queue_map),
590 GNUNET_NO); 597 GNUNET_NO);
591 if (NULL != queue->read_task) 598 if (NULL != queue->read_task)
592 { 599 {
593 GNUNET_SCHEDULER_cancel(queue->read_task); 600 GNUNET_SCHEDULER_cancel (queue->read_task);
594 queue->read_task = NULL; 601 queue->read_task = NULL;
595 } 602 }
596 if (NULL != queue->write_task) 603 if (NULL != queue->write_task)
597 { 604 {
598 GNUNET_SCHEDULER_cancel(queue->write_task); 605 GNUNET_SCHEDULER_cancel (queue->write_task);
599 queue->write_task = NULL; 606 queue->write_task = NULL;
600 } 607 }
601 GNUNET_NETWORK_socket_close(queue->sock); 608 GNUNET_NETWORK_socket_close (queue->sock);
602 gcry_cipher_close(queue->in_cipher); 609 gcry_cipher_close (queue->in_cipher);
603 gcry_cipher_close(queue->out_cipher); 610 gcry_cipher_close (queue->out_cipher);
604 GNUNET_free(queue->address); 611 GNUNET_free (queue->address);
605 if (0 != queue->backpressure) 612 if (0 != queue->backpressure)
606 queue->destroyed = GNUNET_YES; 613 queue->destroyed = GNUNET_YES;
607 else 614 else
608 GNUNET_free(queue); 615 GNUNET_free (queue);
609 if (NULL == listen_task) 616 if (NULL == listen_task)
610 listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 617 listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
611 listen_sock, 618 listen_sock,
612 &listen_cb, 619 &listen_cb,
613 NULL); 620 NULL);
614} 621}
615 622
616 623
@@ -623,24 +630,24 @@ queue_destroy(struct Queue *queue)
623 * @param smac[out] where to write the HMAC 630 * @param smac[out] where to write the HMAC
624 */ 631 */
625static void 632static void
626calculate_hmac(struct GNUNET_HashCode *hmac_secret, 633calculate_hmac (struct GNUNET_HashCode *hmac_secret,
627 const void *buf, 634 const void *buf,
628 size_t buf_size, 635 size_t buf_size,
629 struct GNUNET_ShortHashCode *smac) 636 struct GNUNET_ShortHashCode *smac)
630{ 637{
631 struct GNUNET_HashCode mac; 638 struct GNUNET_HashCode mac;
632 639
633 GNUNET_CRYPTO_hmac_raw(hmac_secret, 640 GNUNET_CRYPTO_hmac_raw (hmac_secret,
634 sizeof(struct GNUNET_HashCode), 641 sizeof(struct GNUNET_HashCode),
635 buf, 642 buf,
636 buf_size, 643 buf_size,
637 &mac); 644 &mac);
638 /* truncate to `struct GNUNET_ShortHashCode` */ 645 /* truncate to `struct GNUNET_ShortHashCode` */
639 memcpy(smac, &mac, sizeof(struct GNUNET_ShortHashCode)); 646 memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
640 /* ratchet hmac key */ 647 /* ratchet hmac key */
641 GNUNET_CRYPTO_hash(hmac_secret, 648 GNUNET_CRYPTO_hash (hmac_secret,
642 sizeof(struct GNUNET_HashCode), 649 sizeof(struct GNUNET_HashCode),
643 hmac_secret); 650 hmac_secret);
644} 651}
645 652
646 653
@@ -651,18 +658,18 @@ calculate_hmac(struct GNUNET_HashCode *hmac_secret,
651 * @param queue queue to shut down nicely 658 * @param queue queue to shut down nicely
652 */ 659 */
653static void 660static void
654queue_finish(struct Queue *queue) 661queue_finish (struct Queue *queue)
655{ 662{
656 struct TCPFinish fin; 663 struct TCPFinish fin;
657 664
658 memset(&fin, 0, sizeof(fin)); 665 memset (&fin, 0, sizeof(fin));
659 fin.header.size = htons(sizeof(fin)); 666 fin.header.size = htons (sizeof(fin));
660 fin.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH); 667 fin.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH);
661 calculate_hmac(&queue->out_hmac, &fin, sizeof(fin), &fin.hmac); 668 calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
662 /* if there is any message left in pwrite_buf, we 669 /* if there is any message left in pwrite_buf, we
663 overwrite it (possibly dropping the last message 670 overwrite it (possibly dropping the last message
664 from CORE hard here) */ 671 from CORE hard here) */
665 memcpy(queue->pwrite_buf, &fin, sizeof(fin)); 672 memcpy (queue->pwrite_buf, &fin, sizeof(fin));
666 queue->pwrite_off = sizeof(fin); 673 queue->pwrite_off = sizeof(fin);
667 /* This flag will ensure that #queue_write() no longer 674 /* This flag will ensure that #queue_write() no longer
668 notifies CORE about the possibility of sending 675 notifies CORE about the possibility of sending
@@ -680,10 +687,10 @@ queue_finish(struct Queue *queue)
680 * @param queue queue for which the timeout should be rescheduled 687 * @param queue queue for which the timeout should be rescheduled
681 */ 688 */
682static void 689static void
683reschedule_queue_timeout(struct Queue *queue) 690reschedule_queue_timeout (struct Queue *queue)
684{ 691{
685 queue->timeout = 692 queue->timeout =
686 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 693 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
687} 694}
688 695
689 696
@@ -693,7 +700,7 @@ reschedule_queue_timeout(struct Queue *queue)
693 * @param cls the `struct Queue *` to disconnect 700 * @param cls the `struct Queue *` to disconnect
694 */ 701 */
695static void 702static void
696queue_read(void *cls); 703queue_read (void *cls);
697 704
698 705
699/** 706/**
@@ -704,31 +711,31 @@ queue_read(void *cls);
704 * @param success #GNUNET_OK on success 711 * @param success #GNUNET_OK on success
705 */ 712 */
706static void 713static void
707core_read_finished_cb(void *cls, int success) 714core_read_finished_cb (void *cls, int success)
708{ 715{
709 struct Queue *queue = cls; 716 struct Queue *queue = cls;
710 717
711 if (GNUNET_OK != success) 718 if (GNUNET_OK != success)
712 GNUNET_STATISTICS_update(stats, 719 GNUNET_STATISTICS_update (stats,
713 "# messages lost in communicator API towards CORE", 720 "# messages lost in communicator API towards CORE",
714 1, 721 1,
715 GNUNET_NO); 722 GNUNET_NO);
716 queue->backpressure--; 723 queue->backpressure--;
717 /* handle deferred queue destruction */ 724 /* handle deferred queue destruction */
718 if ((queue->destroyed) && (0 == queue->backpressure)) 725 if ((queue->destroyed) && (0 == queue->backpressure))
719 { 726 {
720 GNUNET_free(queue); 727 GNUNET_free (queue);
721 return; 728 return;
722 } 729 }
723 reschedule_queue_timeout(queue); 730 reschedule_queue_timeout (queue);
724 /* possibly unchoke reading, now that CORE made progress */ 731 /* possibly unchoke reading, now that CORE made progress */
725 if (NULL == queue->read_task) 732 if (NULL == queue->read_task)
726 queue->read_task = 733 queue->read_task =
727 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_absolute_get_remaining( 734 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (
728 queue->timeout), 735 queue->timeout),
729 queue->sock, 736 queue->sock,
730 &queue_read, 737 &queue_read,
731 queue); 738 queue);
732} 739}
733 740
734 741
@@ -742,34 +749,34 @@ core_read_finished_cb(void *cls, int success)
742 * @param plaintext_len number of bytes of plaintext received 749 * @param plaintext_len number of bytes of plaintext received
743 */ 750 */
744static void 751static void
745pass_plaintext_to_core(struct Queue *queue, 752pass_plaintext_to_core (struct Queue *queue,
746 const void *plaintext, 753 const void *plaintext,
747 size_t plaintext_len) 754 size_t plaintext_len)
748{ 755{
749 const struct GNUNET_MessageHeader *hdr = plaintext; 756 const struct GNUNET_MessageHeader *hdr = plaintext;
750 int ret; 757 int ret;
751 758
752 if (ntohs(hdr->size) != plaintext_len) 759 if (ntohs (hdr->size) != plaintext_len)
753 { 760 {
754 /* NOTE: If we ever allow multiple CORE messages in one 761 /* NOTE: If we ever allow multiple CORE messages in one
755 BOX, this will have to change! */ 762 BOX, this will have to change! */
756 GNUNET_break(0); 763 GNUNET_break (0);
757 return; 764 return;
758 } 765 }
759 ret = GNUNET_TRANSPORT_communicator_receive(ch, 766 ret = GNUNET_TRANSPORT_communicator_receive (ch,
760 &queue->target, 767 &queue->target,
761 hdr, 768 hdr,
762 ADDRESS_VALIDITY_PERIOD, 769 ADDRESS_VALIDITY_PERIOD,
763 &core_read_finished_cb, 770 &core_read_finished_cb,
764 queue); 771 queue);
765 if (GNUNET_OK == ret) 772 if (GNUNET_OK == ret)
766 queue->backpressure++; 773 queue->backpressure++;
767 GNUNET_break(GNUNET_NO != ret); /* backpressure not working!? */ 774 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
768 if (GNUNET_SYSERR == ret) 775 if (GNUNET_SYSERR == ret)
769 GNUNET_STATISTICS_update(stats, 776 GNUNET_STATISTICS_update (stats,
770 "# bytes lost due to CORE not running", 777 "# bytes lost due to CORE not running",
771 plaintext_len, 778 plaintext_len,
772 GNUNET_NO); 779 GNUNET_NO);
773} 780}
774 781
775 782
@@ -783,51 +790,51 @@ pass_plaintext_to_core(struct Queue *queue,
783 * @param hmac_key[out] HMAC key to initialize 790 * @param hmac_key[out] HMAC key to initialize
784 */ 791 */
785static void 792static void
786setup_cipher(const struct GNUNET_HashCode *dh, 793setup_cipher (const struct GNUNET_HashCode *dh,
787 const struct GNUNET_PeerIdentity *pid, 794 const struct GNUNET_PeerIdentity *pid,
788 gcry_cipher_hd_t *cipher, 795 gcry_cipher_hd_t *cipher,
789 struct GNUNET_HashCode *hmac_key) 796 struct GNUNET_HashCode *hmac_key)
790{ 797{
791 char key[256 / 8]; 798 char key[256 / 8];
792 char ctr[128 / 8]; 799 char ctr[128 / 8];
793 800
794 gcry_cipher_open(cipher, 801 gcry_cipher_open (cipher,
795 GCRY_CIPHER_AES256 /* low level: go for speed */, 802 GCRY_CIPHER_AES256 /* low level: go for speed */,
796 GCRY_CIPHER_MODE_CTR, 803 GCRY_CIPHER_MODE_CTR,
797 0 /* flags */); 804 0 /* flags */);
798 GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_kdf(key, 805 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_kdf (key,
799 sizeof(key), 806 sizeof(key),
800 "TCP-key", 807 "TCP-key",
801 strlen("TCP-key"), 808 strlen ("TCP-key"),
802 dh, 809 dh,
803 sizeof(*dh), 810 sizeof(*dh),
804 pid, 811 pid,
805 sizeof(*pid), 812 sizeof(*pid),
806 NULL, 813 NULL,
807 0)); 814 0));
808 gcry_cipher_setkey(*cipher, key, sizeof(key)); 815 gcry_cipher_setkey (*cipher, key, sizeof(key));
809 GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_kdf(ctr, 816 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_kdf (ctr,
810 sizeof(ctr), 817 sizeof(ctr),
811 "TCP-ctr", 818 "TCP-ctr",
812 strlen("TCP-ctr"), 819 strlen ("TCP-ctr"),
813 dh, 820 dh,
814 sizeof(*dh), 821 sizeof(*dh),
815 pid, 822 pid,
816 sizeof(*pid), 823 sizeof(*pid),
817 NULL, 824 NULL,
818 0)); 825 0));
819 gcry_cipher_setctr(*cipher, ctr, sizeof(ctr)); 826 gcry_cipher_setctr (*cipher, ctr, sizeof(ctr));
820 GNUNET_assert(GNUNET_YES == 827 GNUNET_assert (GNUNET_YES ==
821 GNUNET_CRYPTO_kdf(hmac_key, 828 GNUNET_CRYPTO_kdf (hmac_key,
822 sizeof(struct GNUNET_HashCode), 829 sizeof(struct GNUNET_HashCode),
823 "TCP-hmac", 830 "TCP-hmac",
824 strlen("TCP-hmac"), 831 strlen ("TCP-hmac"),
825 dh, 832 dh,
826 sizeof(*dh), 833 sizeof(*dh),
827 pid, 834 pid,
828 sizeof(*pid), 835 sizeof(*pid),
829 NULL, 836 NULL,
830 0)); 837 0));
831} 838}
832 839
833 840
@@ -838,13 +845,13 @@ setup_cipher(const struct GNUNET_HashCode *dh,
838 * @param queue[in,out] queue to initialize decryption cipher for 845 * @param queue[in,out] queue to initialize decryption cipher for
839 */ 846 */
840static void 847static void
841setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, 848setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
842 struct Queue *queue) 849 struct Queue *queue)
843{ 850{
844 struct GNUNET_HashCode dh; 851 struct GNUNET_HashCode dh;
845 852
846 GNUNET_CRYPTO_eddsa_ecdh(my_private_key, ephemeral, &dh); 853 GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh);
847 setup_cipher(&dh, &my_identity, &queue->in_cipher, &queue->in_hmac); 854 setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
848} 855}
849 856
850 857
@@ -857,30 +864,30 @@ setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
857 * @param rekey the rekey message 864 * @param rekey the rekey message
858 */ 865 */
859static void 866static void
860do_rekey(struct Queue *queue, const struct TCPRekey *rekey) 867do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
861{ 868{
862 struct TcpHandshakeSignature thp; 869 struct TcpHandshakeSignature thp;
863 870
864 thp.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); 871 thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
865 thp.purpose.size = htonl(sizeof(thp)); 872 thp.purpose.size = htonl (sizeof(thp));
866 thp.sender = queue->target; 873 thp.sender = queue->target;
867 thp.receiver = my_identity; 874 thp.receiver = my_identity;
868 thp.ephemeral = rekey->ephemeral; 875 thp.ephemeral = rekey->ephemeral;
869 thp.monotonic_time = rekey->monotonic_time; 876 thp.monotonic_time = rekey->monotonic_time;
870 /* FIXME: check monotonic time is monotonic... */ 877 /* FIXME: check monotonic time is monotonic... */
871 if (GNUNET_OK != 878 if (GNUNET_OK !=
872 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, 879 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY,
873 &thp.purpose, 880 &thp.purpose,
874 &rekey->sender_sig, 881 &rekey->sender_sig,
875 &queue->target.public_key)) 882 &queue->target.public_key))
876 { 883 {
877 GNUNET_break(0); 884 GNUNET_break (0);
878 queue_finish(queue); 885 queue_finish (queue);
879 return; 886 return;
880 } 887 }
881 gcry_cipher_close(queue->in_cipher); 888 gcry_cipher_close (queue->in_cipher);
882 queue->rekeyed = GNUNET_YES; 889 queue->rekeyed = GNUNET_YES;
883 setup_in_cipher(&rekey->ephemeral, queue); 890 setup_in_cipher (&rekey->ephemeral, queue);
884} 891}
885 892
886 893
@@ -892,13 +899,13 @@ do_rekey(struct Queue *queue, const struct TCPRekey *rekey)
892 * @return number of bytes of plaintext handled, 0 for none 899 * @return number of bytes of plaintext handled, 0 for none
893 */ 900 */
894static size_t 901static size_t
895try_handle_plaintext(struct Queue *queue) 902try_handle_plaintext (struct Queue *queue)
896{ 903{
897 const struct GNUNET_MessageHeader *hdr = 904 const struct GNUNET_MessageHeader *hdr =
898 (const struct GNUNET_MessageHeader *)queue->pread_buf; 905 (const struct GNUNET_MessageHeader *) queue->pread_buf;
899 const struct TCPBox *box = (const struct TCPBox *)queue->pread_buf; 906 const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf;
900 const struct TCPRekey *rekey = (const struct TCPRekey *)queue->pread_buf; 907 const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
901 const struct TCPFinish *fin = (const struct TCPFinish *)queue->pread_buf; 908 const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
902 struct TCPRekey rekeyz; 909 struct TCPRekey rekeyz;
903 struct TCPFinish finz; 910 struct TCPFinish finz;
904 struct GNUNET_ShortHashCode tmac; 911 struct GNUNET_ShortHashCode tmac;
@@ -907,74 +914,74 @@ try_handle_plaintext(struct Queue *queue)
907 914
908 if (sizeof(*hdr) > queue->pread_off) 915 if (sizeof(*hdr) > queue->pread_off)
909 return 0; /* not even a header */ 916 return 0; /* not even a header */
910 type = ntohs(hdr->type); 917 type = ntohs (hdr->type);
911 switch (type) 918 switch (type)
919 {
920 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX:
921 /* Special case: header size excludes box itself! */
922 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
923 return 0;
924 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
925 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
912 { 926 {
913 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX: 927 GNUNET_break_op (0);
914 /* Special case: header size excludes box itself! */ 928 queue_finish (queue);
915 if (ntohs(hdr->size) + sizeof(struct TCPBox) > queue->pread_off) 929 return 0;
916 return 0; 930 }
917 calculate_hmac(&queue->in_hmac, &box[1], ntohs(hdr->size), &tmac); 931 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
918 if (0 != memcmp(&tmac, &box->hmac, sizeof(tmac))) 932 size = ntohs (hdr->size) + sizeof(*box);
919 { 933 break;
920 GNUNET_break_op(0);
921 queue_finish(queue);
922 return 0;
923 }
924 pass_plaintext_to_core(queue, (const void *)&box[1], ntohs(hdr->size));
925 size = ntohs(hdr->size) + sizeof(*box);
926 break;
927
928 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY:
929 if (sizeof(*rekey) > queue->pread_off)
930 return 0;
931 if (ntohs(hdr->size) != sizeof(*rekey))
932 {
933 GNUNET_break_op(0);
934 queue_finish(queue);
935 return 0;
936 }
937 rekeyz = *rekey;
938 memset(&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
939 calculate_hmac(&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
940 if (0 != memcmp(&tmac, &box->hmac, sizeof(tmac)))
941 {
942 GNUNET_break_op(0);
943 queue_finish(queue);
944 return 0;
945 }
946 do_rekey(queue, rekey);
947 size = ntohs(hdr->size);
948 break;
949 934
950 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH: 935 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY:
951 if (sizeof(*fin) > queue->pread_off) 936 if (sizeof(*rekey) > queue->pread_off)
952 return 0; 937 return 0;
953 if (ntohs(hdr->size) != sizeof(*fin)) 938 if (ntohs (hdr->size) != sizeof(*rekey))
954 { 939 {
955 GNUNET_break_op(0); 940 GNUNET_break_op (0);
956 queue_finish(queue); 941 queue_finish (queue);
957 return 0; 942 return 0;
958 } 943 }
959 finz = *fin; 944 rekeyz = *rekey;
960 memset(&finz.hmac, 0, sizeof(finz.hmac)); 945 memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
961 calculate_hmac(&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac); 946 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
962 if (0 != memcmp(&tmac, &fin->hmac, sizeof(tmac))) 947 if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
963 { 948 {
964 GNUNET_break_op(0); 949 GNUNET_break_op (0);
965 queue_finish(queue); 950 queue_finish (queue);
966 return 0; 951 return 0;
967 } 952 }
968 /* handle FINISH by destroying queue */ 953 do_rekey (queue, rekey);
969 queue_destroy(queue); 954 size = ntohs (hdr->size);
970 break; 955 break;
971 956
972 default: 957 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH:
973 GNUNET_break_op(0); 958 if (sizeof(*fin) > queue->pread_off)
974 queue_finish(queue); 959 return 0;
960 if (ntohs (hdr->size) != sizeof(*fin))
961 {
962 GNUNET_break_op (0);
963 queue_finish (queue);
964 return 0;
965 }
966 finz = *fin;
967 memset (&finz.hmac, 0, sizeof(finz.hmac));
968 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
969 if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
970 {
971 GNUNET_break_op (0);
972 queue_finish (queue);
975 return 0; 973 return 0;
976 } 974 }
977 GNUNET_assert(0 != size); 975 /* handle FINISH by destroying queue */
976 queue_destroy (queue);
977 break;
978
979 default:
980 GNUNET_break_op (0);
981 queue_finish (queue);
982 return 0;
983 }
984 GNUNET_assert (0 != size);
978 return size; 985 return size;
979} 986}
980 987
@@ -985,96 +992,96 @@ try_handle_plaintext(struct Queue *queue)
985 * @param cls the `struct Queue *` to disconnect 992 * @param cls the `struct Queue *` to disconnect
986 */ 993 */
987static void 994static void
988queue_read(void *cls) 995queue_read (void *cls)
989{ 996{
990 struct Queue *queue = cls; 997 struct Queue *queue = cls;
991 struct GNUNET_TIME_Relative left; 998 struct GNUNET_TIME_Relative left;
992 ssize_t rcvd; 999 ssize_t rcvd;
993 1000
994 queue->read_task = NULL; 1001 queue->read_task = NULL;
995 rcvd = GNUNET_NETWORK_socket_recv(queue->sock, 1002 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
996 &queue->cread_buf[queue->cread_off], 1003 &queue->cread_buf[queue->cread_off],
997 BUF_SIZE - queue->cread_off); 1004 BUF_SIZE - queue->cread_off);
998 if (-1 == rcvd) 1005 if (-1 == rcvd)
1006 {
1007 if ((EAGAIN != errno) && (EINTR != errno))
999 { 1008 {
1000 if ((EAGAIN != errno) && (EINTR != errno)) 1009 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
1001 { 1010 queue_finish (queue);
1002 GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv");
1003 queue_finish(queue);
1004 return;
1005 }
1006 /* try again */
1007 queue->read_task =
1008 GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read, queue);
1009 return; 1011 return;
1010 } 1012 }
1013 /* try again */
1014 queue->read_task =
1015 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1016 return;
1017 }
1011 if (0 != rcvd) 1018 if (0 != rcvd)
1012 reschedule_queue_timeout(queue); 1019 reschedule_queue_timeout (queue);
1013 queue->cread_off += rcvd; 1020 queue->cread_off += rcvd;
1014 while ((queue->pread_off < sizeof(queue->pread_buf)) && 1021 while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1015 (queue->cread_off > 0)) 1022 (queue->cread_off > 0))
1016 { 1023 {
1017 size_t max = GNUNET_MIN(sizeof(queue->pread_buf) - queue->pread_off, 1024 size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
1018 queue->cread_off); 1025 queue->cread_off);
1019 size_t done; 1026 size_t done;
1020 size_t total; 1027 size_t total;
1021 1028
1022 GNUNET_assert(0 == 1029 GNUNET_assert (0 ==
1023 gcry_cipher_decrypt(queue->in_cipher, 1030 gcry_cipher_decrypt (queue->in_cipher,
1024 &queue->pread_buf[queue->pread_off], 1031 &queue->pread_buf[queue->pread_off],
1025 max, 1032 max,
1026 queue->cread_buf, 1033 queue->cread_buf,
1027 max)); 1034 max));
1028 queue->pread_off += max; 1035 queue->pread_off += max;
1029 total = 0; 1036 total = 0;
1030 while ((GNUNET_NO == queue->rekeyed) && 1037 while ((GNUNET_NO == queue->rekeyed) &&
1031 (0 != (done = try_handle_plaintext(queue)))) 1038 (0 != (done = try_handle_plaintext (queue))))
1032 { 1039 {
1033 /* 'done' bytes of plaintext were used, shift buffer */ 1040 /* 'done' bytes of plaintext were used, shift buffer */
1034 GNUNET_assert(done <= queue->pread_off); 1041 GNUNET_assert (done <= queue->pread_off);
1035 /* NOTE: this memmove() could possibly sometimes be 1042 /* NOTE: this memmove() could possibly sometimes be
1036 avoided if we pass 'total' into try_handle_plaintext() 1043 avoided if we pass 'total' into try_handle_plaintext()
1037 and use it at an offset into the buffer there! */ 1044 and use it at an offset into the buffer there! */
1038 memmove(queue->pread_buf, 1045 memmove (queue->pread_buf,
1039 &queue->pread_buf[done], 1046 &queue->pread_buf[done],
1040 queue->pread_off - done); 1047 queue->pread_off - done);
1041 queue->pread_off -= done; 1048 queue->pread_off -= done;
1042 total += done; 1049 total += done;
1043 } 1050 }
1044 /* when we encounter a rekey message, the decryption above uses the 1051 /* when we encounter a rekey message, the decryption above uses the
1045 wrong key for everything after the rekey; in that case, we have 1052 wrong key for everything after the rekey; in that case, we have
1046 to re-do the decryption at 'total' instead of at 'max'. If there 1053 to re-do the decryption at 'total' instead of at 'max'. If there
1047 is no rekey and the last message is incomplete (max > total), 1054 is no rekey and the last message is incomplete (max > total),
1048 it is safe to keep the decryption so we shift by 'max' */ 1055 it is safe to keep the decryption so we shift by 'max' */
1049 if (GNUNET_YES == queue->rekeyed) 1056 if (GNUNET_YES == queue->rekeyed)
1050 { 1057 {
1051 max = total; 1058 max = total;
1052 queue->rekeyed = GNUNET_NO; 1059 queue->rekeyed = GNUNET_NO;
1053 }
1054 memmove(queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1055 queue->cread_off -= max;
1056 } 1060 }
1061 memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1062 queue->cread_off -= max;
1063 }
1057 1064
1058 if (BUF_SIZE == queue->cread_off) 1065 if (BUF_SIZE == queue->cread_off)
1059 return; /* buffer full, suspend reading */ 1066 return; /* buffer full, suspend reading */
1060 left = GNUNET_TIME_absolute_get_remaining(queue->timeout); 1067 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
1061 if (0 != left.rel_value_us) 1068 if (0 != left.rel_value_us)
1069 {
1070 if (max_queue_length < queue->backpressure)
1062 { 1071 {
1063 if (max_queue_length < queue->backpressure) 1072 /* continue reading */
1064 { 1073 queue->read_task =
1065 /* continue reading */ 1074 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1066 queue->read_task =
1067 GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read, queue);
1068 }
1069 return;
1070 } 1075 }
1071 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1076 return;
1072 "Queue %p was idle for %s, disconnecting\n", 1077 }
1073 queue, 1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1074 GNUNET_STRINGS_relative_time_to_string( 1079 "Queue %p was idle for %s, disconnecting\n",
1075 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1080 queue,
1076 GNUNET_YES)); 1081 GNUNET_STRINGS_relative_time_to_string (
1077 queue_finish(queue); 1082 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1083 GNUNET_YES));
1084 queue_finish (queue);
1078} 1085}
1079 1086
1080 1087
@@ -1086,7 +1093,7 @@ queue_read(void *cls)
1086 * @return converted bindto specification 1093 * @return converted bindto specification
1087 */ 1094 */
1088static struct sockaddr * 1095static struct sockaddr *
1089tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) 1096tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1090{ 1097{
1091 struct sockaddr *in; 1098 struct sockaddr *in;
1092 unsigned int port; 1099 unsigned int port;
@@ -1094,88 +1101,88 @@ tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
1094 char *colon; 1101 char *colon;
1095 char *cp; 1102 char *cp;
1096 1103
1097 if (1 == sscanf(bindto, "%u%1s", &port, dummy)) 1104 if (1 == sscanf (bindto, "%u%1s", &port, dummy))
1105 {
1106 /* interpreting value as just a PORT number */
1107 if (port > UINT16_MAX)
1098 { 1108 {
1099 /* interpreting value as just a PORT number */ 1109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1100 if (port > UINT16_MAX) 1110 "BINDTO specification `%s' invalid: value too large for port\n",
1101 { 1111 bindto);
1102 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1112 return NULL;
1103 "BINDTO specification `%s' invalid: value too large for port\n", 1113 }
1104 bindto); 1114 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1105 return NULL; 1115 (GNUNET_YES ==
1106 } 1116 GNUNET_CONFIGURATION_get_value_yesno (cfg,
1107 if ((GNUNET_NO == GNUNET_NETWORK_test_pf(PF_INET6)) || 1117 COMMUNICATOR_CONFIG_SECTION,
1108 (GNUNET_YES == 1118 "DISABLE_V6")))
1109 GNUNET_CONFIGURATION_get_value_yesno(cfg, 1119 {
1110 COMMUNICATOR_CONFIG_SECTION, 1120 struct sockaddr_in *i4;
1111 "DISABLE_V6"))) 1121
1112 { 1122 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1113 struct sockaddr_in *i4; 1123 i4->sin_family = AF_INET;
1114 1124 i4->sin_port = htons ((uint16_t) port);
1115 i4 = GNUNET_malloc(sizeof(struct sockaddr_in)); 1125 *sock_len = sizeof(struct sockaddr_in);
1116 i4->sin_family = AF_INET; 1126 in = (struct sockaddr *) i4;
1117 i4->sin_port = htons((uint16_t)port); 1127 }
1118 *sock_len = sizeof(struct sockaddr_in); 1128 else
1119 in = (struct sockaddr *)i4; 1129 {
1120 } 1130 struct sockaddr_in6 *i6;
1121 else 1131
1122 { 1132 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
1123 struct sockaddr_in6 *i6; 1133 i6->sin6_family = AF_INET6;
1124 1134 i6->sin6_port = htons ((uint16_t) port);
1125 i6 = GNUNET_malloc(sizeof(struct sockaddr_in6)); 1135 *sock_len = sizeof(struct sockaddr_in6);
1126 i6->sin6_family = AF_INET6; 1136 in = (struct sockaddr *) i6;
1127 i6->sin6_port = htons((uint16_t)port);
1128 *sock_len = sizeof(struct sockaddr_in6);
1129 in = (struct sockaddr *)i6;
1130 }
1131 return in;
1132 } 1137 }
1133 cp = GNUNET_strdup(bindto); 1138 return in;
1134 colon = strrchr(cp, ':'); 1139 }
1140 cp = GNUNET_strdup (bindto);
1141 colon = strrchr (cp, ':');
1135 if (NULL != colon) 1142 if (NULL != colon)
1143 {
1144 /* interpet value after colon as port */
1145 *colon = '\0';
1146 colon++;
1147 if (1 == sscanf (colon, "%u%1s", &port, dummy))
1136 { 1148 {
1137 /* interpet value after colon as port */ 1149 /* interpreting value as just a PORT number */
1138 *colon = '\0'; 1150 if (port > UINT16_MAX)
1139 colon++; 1151 {
1140 if (1 == sscanf(colon, "%u%1s", &port, dummy)) 1152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1141 { 1153 "BINDTO specification `%s' invalid: value too large for port\n",
1142 /* interpreting value as just a PORT number */ 1154 bindto);
1143 if (port > UINT16_MAX) 1155 GNUNET_free (cp);
1144 { 1156 return NULL;
1145 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1157 }
1146 "BINDTO specification `%s' invalid: value too large for port\n",
1147 bindto);
1148 GNUNET_free(cp);
1149 return NULL;
1150 }
1151 }
1152 else
1153 {
1154 GNUNET_log(
1155 GNUNET_ERROR_TYPE_ERROR,
1156 "BINDTO specification `%s' invalid: last ':' not followed by number\n",
1157 bindto);
1158 GNUNET_free(cp);
1159 return NULL;
1160 }
1161 } 1158 }
1162 else 1159 else
1163 { 1160 {
1164 /* interpret missing port as 0, aka pick any free one */ 1161 GNUNET_log (
1165 port = 0; 1162 GNUNET_ERROR_TYPE_ERROR,
1163 "BINDTO specification `%s' invalid: last ':' not followed by number\n",
1164 bindto);
1165 GNUNET_free (cp);
1166 return NULL;
1166 } 1167 }
1168 }
1169 else
1170 {
1171 /* interpret missing port as 0, aka pick any free one */
1172 port = 0;
1173 }
1167 { 1174 {
1168 /* try IPv4 */ 1175 /* try IPv4 */
1169 struct sockaddr_in v4; 1176 struct sockaddr_in v4;
1170 1177
1171 if (1 == inet_pton(AF_INET, cp, &v4)) 1178 if (1 == inet_pton (AF_INET, cp, &v4))
1172 { 1179 {
1173 v4.sin_port = htons((uint16_t)port); 1180 v4.sin_port = htons ((uint16_t) port);
1174 in = GNUNET_memdup(&v4, sizeof(v4)); 1181 in = GNUNET_memdup (&v4, sizeof(v4));
1175 *sock_len = sizeof(v4); 1182 *sock_len = sizeof(v4);
1176 GNUNET_free(cp); 1183 GNUNET_free (cp);
1177 return in; 1184 return in;
1178 } 1185 }
1179 } 1186 }
1180 { 1187 {
1181 /* try IPv6 */ 1188 /* try IPv6 */
@@ -1183,22 +1190,22 @@ tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
1183 const char *start; 1190 const char *start;
1184 1191
1185 start = cp; 1192 start = cp;
1186 if (('[' == *cp) && (']' == cp[strlen(cp) - 1])) 1193 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
1187 { 1194 {
1188 start++; /* skip over '[' */ 1195 start++; /* skip over '[' */
1189 cp[strlen(cp) - 1] = '\0'; /* eat ']' */ 1196 cp[strlen (cp) - 1] = '\0'; /* eat ']' */
1190 } 1197 }
1191 if (1 == inet_pton(AF_INET6, start, &v6)) 1198 if (1 == inet_pton (AF_INET6, start, &v6))
1192 { 1199 {
1193 v6.sin6_port = htons((uint16_t)port); 1200 v6.sin6_port = htons ((uint16_t) port);
1194 in = GNUNET_memdup(&v6, sizeof(v6)); 1201 in = GNUNET_memdup (&v6, sizeof(v6));
1195 *sock_len = sizeof(v6); 1202 *sock_len = sizeof(v6);
1196 GNUNET_free(cp); 1203 GNUNET_free (cp);
1197 return in; 1204 return in;
1198 } 1205 }
1199 } 1206 }
1200 /* #5528 FIXME (feature!): maybe also try getnameinfo()? */ 1207 /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
1201 GNUNET_free(cp); 1208 GNUNET_free (cp);
1202 return NULL; 1209 return NULL;
1203} 1210}
1204 1211
@@ -1210,17 +1217,17 @@ tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
1210 * @param queue queue to setup outgoing (encryption) cipher for 1217 * @param queue queue to setup outgoing (encryption) cipher for
1211 */ 1218 */
1212static void 1219static void
1213setup_out_cipher(struct Queue *queue) 1220setup_out_cipher (struct Queue *queue)
1214{ 1221{
1215 struct GNUNET_HashCode dh; 1222 struct GNUNET_HashCode dh;
1216 1223
1217 GNUNET_CRYPTO_ecdh_eddsa(&queue->ephemeral, &queue->target.public_key, &dh); 1224 GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh);
1218 /* we don't need the private key anymore, drop it! */ 1225 /* we don't need the private key anymore, drop it! */
1219 memset(&queue->ephemeral, 0, sizeof(queue->ephemeral)); 1226 memset (&queue->ephemeral, 0, sizeof(queue->ephemeral));
1220 setup_cipher(&dh, &queue->target, &queue->out_cipher, &queue->out_hmac); 1227 setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1221 queue->rekey_time = GNUNET_TIME_relative_to_absolute(REKEY_TIME_INTERVAL); 1228 queue->rekey_time = GNUNET_TIME_relative_to_absolute (REKEY_TIME_INTERVAL);
1222 queue->rekey_left_bytes = 1229 queue->rekey_left_bytes =
1223 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, REKEY_MAX_BYTES); 1230 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, REKEY_MAX_BYTES);
1224} 1231}
1225 1232
1226 1233
@@ -1231,31 +1238,31 @@ setup_out_cipher(struct Queue *queue)
1231 * @param queue queue to perform rekeying on 1238 * @param queue queue to perform rekeying on
1232 */ 1239 */
1233static void 1240static void
1234inject_rekey(struct Queue *queue) 1241inject_rekey (struct Queue *queue)
1235{ 1242{
1236 struct TCPRekey rekey; 1243 struct TCPRekey rekey;
1237 struct TcpHandshakeSignature thp; 1244 struct TcpHandshakeSignature thp;
1238 1245
1239 GNUNET_assert(0 == queue->pwrite_off); 1246 GNUNET_assert (0 == queue->pwrite_off);
1240 memset(&rekey, 0, sizeof(rekey)); 1247 memset (&rekey, 0, sizeof(rekey));
1241 GNUNET_assert(GNUNET_OK == 1248 GNUNET_assert (GNUNET_OK ==
1242 GNUNET_CRYPTO_ecdhe_key_create2(&queue->ephemeral)); 1249 GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral));
1243 rekey.header.type = ntohs(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); 1250 rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
1244 rekey.header.size = ntohs(sizeof(rekey)); 1251 rekey.header.size = ntohs (sizeof(rekey));
1245 GNUNET_CRYPTO_ecdhe_key_get_public(&queue->ephemeral, &rekey.ephemeral); 1252 GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral);
1246 rekey.monotonic_time = 1253 rekey.monotonic_time =
1247 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg)); 1254 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
1248 thp.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); 1255 thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
1249 thp.purpose.size = htonl(sizeof(thp)); 1256 thp.purpose.size = htonl (sizeof(thp));
1250 thp.sender = my_identity; 1257 thp.sender = my_identity;
1251 thp.receiver = queue->target; 1258 thp.receiver = queue->target;
1252 thp.ephemeral = rekey.ephemeral; 1259 thp.ephemeral = rekey.ephemeral;
1253 thp.monotonic_time = rekey.monotonic_time; 1260 thp.monotonic_time = rekey.monotonic_time;
1254 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, 1261 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key,
1255 &thp.purpose, 1262 &thp.purpose,
1256 &rekey.sender_sig)); 1263 &rekey.sender_sig));
1257 calculate_hmac(&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac); 1264 calculate_hmac (&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1258 memcpy(queue->pwrite_buf, &rekey, sizeof(rekey)); 1265 memcpy (queue->pwrite_buf, &rekey, sizeof(rekey));
1259 queue->pwrite_off = sizeof(rekey); 1266 queue->pwrite_off = sizeof(rekey);
1260} 1267}
1261 1268
@@ -1267,79 +1274,79 @@ inject_rekey(struct Queue *queue)
1267 * @param cls a `struct Queue` 1274 * @param cls a `struct Queue`
1268 */ 1275 */
1269static void 1276static void
1270queue_write(void *cls) 1277queue_write (void *cls)
1271{ 1278{
1272 struct Queue *queue = cls; 1279 struct Queue *queue = cls;
1273 ssize_t sent; 1280 ssize_t sent;
1274 1281
1275 queue->write_task = NULL; 1282 queue->write_task = NULL;
1276 if (0 != queue->cwrite_off) 1283 if (0 != queue->cwrite_off)
1284 {
1285 sent = GNUNET_NETWORK_socket_send (queue->sock,
1286 queue->cwrite_buf,
1287 queue->cwrite_off);
1288 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1289 {
1290 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
1291 queue_destroy (queue);
1292 return;
1293 }
1294 if (sent > 0)
1277 { 1295 {
1278 sent = GNUNET_NETWORK_socket_send(queue->sock, 1296 size_t usent = (size_t) sent;
1279 queue->cwrite_buf, 1297
1280 queue->cwrite_off); 1298 memmove (queue->cwrite_buf,
1281 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno)) 1299 &queue->cwrite_buf[usent],
1282 { 1300 queue->cwrite_off - usent);
1283 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send"); 1301 reschedule_queue_timeout (queue);
1284 queue_destroy(queue);
1285 return;
1286 }
1287 if (sent > 0)
1288 {
1289 size_t usent = (size_t)sent;
1290
1291 memmove(queue->cwrite_buf,
1292 &queue->cwrite_buf[usent],
1293 queue->cwrite_off - usent);
1294 reschedule_queue_timeout(queue);
1295 }
1296 } 1302 }
1303 }
1297 /* can we encrypt more? (always encrypt full messages, needed 1304 /* can we encrypt more? (always encrypt full messages, needed
1298 such that #mq_cancel() can work!) */ 1305 such that #mq_cancel() can work!) */
1299 if ((0 < queue->rekey_left_bytes) && 1306 if ((0 < queue->rekey_left_bytes) &&
1300 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE)) 1307 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1301 { 1308 {
1302 GNUNET_assert(0 == 1309 GNUNET_assert (0 ==
1303 gcry_cipher_encrypt(queue->out_cipher, 1310 gcry_cipher_encrypt (queue->out_cipher,
1304 &queue->cwrite_buf[queue->cwrite_off], 1311 &queue->cwrite_buf[queue->cwrite_off],
1305 queue->pwrite_off, 1312 queue->pwrite_off,
1306 queue->pwrite_buf, 1313 queue->pwrite_buf,
1307 queue->pwrite_off)); 1314 queue->pwrite_off));
1308 if (queue->rekey_left_bytes > queue->pwrite_off) 1315 if (queue->rekey_left_bytes > queue->pwrite_off)
1309 queue->rekey_left_bytes -= queue->pwrite_off; 1316 queue->rekey_left_bytes -= queue->pwrite_off;
1310 else 1317 else
1311 queue->rekey_left_bytes = 0; 1318 queue->rekey_left_bytes = 0;
1312 queue->cwrite_off += queue->pwrite_off; 1319 queue->cwrite_off += queue->pwrite_off;
1313 queue->pwrite_off = 0; 1320 queue->pwrite_off = 0;
1314 } 1321 }
1315 if ((0 == queue->pwrite_off) && 1322 if ((0 == queue->pwrite_off) &&
1316 ((0 == queue->rekey_left_bytes) || 1323 ((0 == queue->rekey_left_bytes) ||
1317 (0 == 1324 (0 ==
1318 GNUNET_TIME_absolute_get_remaining(queue->rekey_time).rel_value_us))) 1325 GNUNET_TIME_absolute_get_remaining (queue->rekey_time).rel_value_us)))
1319 { 1326 {
1320 gcry_cipher_close(queue->out_cipher); 1327 gcry_cipher_close (queue->out_cipher);
1321 setup_out_cipher(queue); 1328 setup_out_cipher (queue);
1322 inject_rekey(queue); 1329 inject_rekey (queue);
1323 } 1330 }
1324 if ((0 == queue->pwrite_off) && (!queue->finishing) && 1331 if ((0 == queue->pwrite_off) && (! queue->finishing) &&
1325 (queue->mq_awaits_continue)) 1332 (queue->mq_awaits_continue))
1326 { 1333 {
1327 queue->mq_awaits_continue = GNUNET_NO; 1334 queue->mq_awaits_continue = GNUNET_NO;
1328 GNUNET_MQ_impl_send_continue(queue->mq); 1335 GNUNET_MQ_impl_send_continue (queue->mq);
1329 } 1336 }
1330 /* did we just finish writing 'finish'? */ 1337 /* did we just finish writing 'finish'? */
1331 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing)) 1338 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1332 { 1339 {
1333 queue_destroy(queue); 1340 queue_destroy (queue);
1334 return; 1341 return;
1335 } 1342 }
1336 /* do we care to write more? */ 1343 /* do we care to write more? */
1337 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off)) 1344 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1338 queue->write_task = 1345 queue->write_task =
1339 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 1346 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1340 queue->sock, 1347 queue->sock,
1341 &queue_write, 1348 &queue_write,
1342 queue); 1349 queue);
1343} 1350}
1344 1351
1345 1352
@@ -1352,32 +1359,32 @@ queue_write(void *cls)
1352 * @param impl_state our `struct Queue` 1359 * @param impl_state our `struct Queue`
1353 */ 1360 */
1354static void 1361static void
1355mq_send(struct GNUNET_MQ_Handle *mq, 1362mq_send (struct GNUNET_MQ_Handle *mq,
1356 const struct GNUNET_MessageHeader *msg, 1363 const struct GNUNET_MessageHeader *msg,
1357 void *impl_state) 1364 void *impl_state)
1358{ 1365{
1359 struct Queue *queue = impl_state; 1366 struct Queue *queue = impl_state;
1360 uint16_t msize = ntohs(msg->size); 1367 uint16_t msize = ntohs (msg->size);
1361 struct TCPBox box; 1368 struct TCPBox box;
1362 1369
1363 GNUNET_assert(mq == queue->mq); 1370 GNUNET_assert (mq == queue->mq);
1364 if (GNUNET_YES == queue->finishing) 1371 if (GNUNET_YES == queue->finishing)
1365 return; /* this queue is dying, drop msg */ 1372 return; /* this queue is dying, drop msg */
1366 GNUNET_assert(0 == queue->pread_off); 1373 GNUNET_assert (0 == queue->pread_off);
1367 box.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX); 1374 box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
1368 box.header.size = htons(msize); 1375 box.header.size = htons (msize);
1369 calculate_hmac(&queue->out_hmac, msg, msize, &box.hmac); 1376 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
1370 memcpy(&queue->pread_buf[queue->pread_off], &box, sizeof(box)); 1377 memcpy (&queue->pread_buf[queue->pread_off], &box, sizeof(box));
1371 queue->pread_off += sizeof(box); 1378 queue->pread_off += sizeof(box);
1372 memcpy(&queue->pread_buf[queue->pread_off], msg, msize); 1379 memcpy (&queue->pread_buf[queue->pread_off], msg, msize);
1373 queue->pread_off += msize; 1380 queue->pread_off += msize;
1374 GNUNET_assert(NULL != queue->sock); 1381 GNUNET_assert (NULL != queue->sock);
1375 if (NULL == queue->write_task) 1382 if (NULL == queue->write_task)
1376 queue->write_task = 1383 queue->write_task =
1377 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 1384 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1378 queue->sock, 1385 queue->sock,
1379 &queue_write, 1386 &queue_write,
1380 queue); 1387 queue);
1381} 1388}
1382 1389
1383 1390
@@ -1390,15 +1397,15 @@ mq_send(struct GNUNET_MQ_Handle *mq,
1390 * @param impl_state our `struct Queue` 1397 * @param impl_state our `struct Queue`
1391 */ 1398 */
1392static void 1399static void
1393mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) 1400mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
1394{ 1401{
1395 struct Queue *queue = impl_state; 1402 struct Queue *queue = impl_state;
1396 1403
1397 if (mq == queue->mq) 1404 if (mq == queue->mq)
1398 { 1405 {
1399 queue->mq = NULL; 1406 queue->mq = NULL;
1400 queue_finish(queue); 1407 queue_finish (queue);
1401 } 1408 }
1402} 1409}
1403 1410
1404 1411
@@ -1409,11 +1416,11 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
1409 * @param impl_state our `struct Queue` 1416 * @param impl_state our `struct Queue`
1410 */ 1417 */
1411static void 1418static void
1412mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) 1419mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
1413{ 1420{
1414 struct Queue *queue = impl_state; 1421 struct Queue *queue = impl_state;
1415 1422
1416 GNUNET_assert(0 != queue->pwrite_off); 1423 GNUNET_assert (0 != queue->pwrite_off);
1417 queue->pwrite_off = 0; 1424 queue->pwrite_off = 0;
1418} 1425}
1419 1426
@@ -1428,15 +1435,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
1428 * @param error error code 1435 * @param error error code
1429 */ 1436 */
1430static void 1437static void
1431mq_error(void *cls, enum GNUNET_MQ_Error error) 1438mq_error (void *cls, enum GNUNET_MQ_Error error)
1432{ 1439{
1433 struct Queue *queue = cls; 1440 struct Queue *queue = cls;
1434 1441
1435 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1442 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1436 "MQ error in queue to %s: %d\n", 1443 "MQ error in queue to %s: %d\n",
1437 GNUNET_i2s(&queue->target), 1444 GNUNET_i2s (&queue->target),
1438 (int)error); 1445 (int) error);
1439 queue_finish(queue); 1446 queue_finish (queue);
1440} 1447}
1441 1448
1442 1449
@@ -1448,58 +1455,58 @@ mq_error(void *cls, enum GNUNET_MQ_Error error)
1448 * @param queue queue to boot 1455 * @param queue queue to boot
1449 */ 1456 */
1450static void 1457static void
1451boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs) 1458boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
1452{ 1459{
1453 queue->nt = 1460 queue->nt =
1454 GNUNET_NT_scanner_get_type(is, queue->address, queue->address_len); 1461 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
1455 (void)GNUNET_CONTAINER_multipeermap_put( 1462 (void) GNUNET_CONTAINER_multipeermap_put (
1456 queue_map, 1463 queue_map,
1457 &queue->target, 1464 &queue->target,
1458 queue, 1465 queue,
1459 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1466 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1460 GNUNET_STATISTICS_set(stats, 1467 GNUNET_STATISTICS_set (stats,
1461 "# queues active", 1468 "# queues active",
1462 GNUNET_CONTAINER_multipeermap_size(queue_map), 1469 GNUNET_CONTAINER_multipeermap_size (queue_map),
1463 GNUNET_NO); 1470 GNUNET_NO);
1464 queue->timeout = 1471 queue->timeout =
1465 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1472 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1466 queue->mq = GNUNET_MQ_queue_for_callbacks(&mq_send, 1473 queue->mq = GNUNET_MQ_queue_for_callbacks (&mq_send,
1467 &mq_destroy, 1474 &mq_destroy,
1468 &mq_cancel, 1475 &mq_cancel,
1469 queue, 1476 queue,
1470 NULL, 1477 NULL,
1471 &mq_error, 1478 &mq_error,
1472 queue); 1479 queue);
1473 { 1480 {
1474 char *foreign_addr; 1481 char *foreign_addr;
1475 1482
1476 switch (queue->address->sa_family) 1483 switch (queue->address->sa_family)
1477 { 1484 {
1478 case AF_INET: 1485 case AF_INET:
1479 GNUNET_asprintf(&foreign_addr, 1486 GNUNET_asprintf (&foreign_addr,
1480 "%s-%s", 1487 "%s-%s",
1481 COMMUNICATOR_ADDRESS_PREFIX, 1488 COMMUNICATOR_ADDRESS_PREFIX,
1482 GNUNET_a2s(queue->address, queue->address_len)); 1489 GNUNET_a2s (queue->address, queue->address_len));
1483 break; 1490 break;
1484 1491
1485 case AF_INET6: 1492 case AF_INET6:
1486 GNUNET_asprintf(&foreign_addr, 1493 GNUNET_asprintf (&foreign_addr,
1487 "%s-%s", 1494 "%s-%s",
1488 COMMUNICATOR_ADDRESS_PREFIX, 1495 COMMUNICATOR_ADDRESS_PREFIX,
1489 GNUNET_a2s(queue->address, queue->address_len)); 1496 GNUNET_a2s (queue->address, queue->address_len));
1490 break; 1497 break;
1491 1498
1492 default: 1499 default:
1493 GNUNET_assert(0); 1500 GNUNET_assert (0);
1494 } 1501 }
1495 queue->qh = GNUNET_TRANSPORT_communicator_mq_add(ch, 1502 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch,
1496 &queue->target, 1503 &queue->target,
1497 foreign_addr, 1504 foreign_addr,
1498 0 /* no MTU */, 1505 0 /* no MTU */,
1499 queue->nt, 1506 queue->nt,
1500 cs, 1507 cs,
1501 queue->mq); 1508 queue->mq);
1502 GNUNET_free(foreign_addr); 1509 GNUNET_free (foreign_addr);
1503 } 1510 }
1504} 1511}
1505 1512
@@ -1515,33 +1522,33 @@ boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
1515 * @param epub our public key for the KX 1522 * @param epub our public key for the KX
1516 */ 1523 */
1517static void 1524static void
1518transmit_kx(struct Queue *queue, 1525transmit_kx (struct Queue *queue,
1519 const struct GNUNET_CRYPTO_EcdhePublicKey *epub) 1526 const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
1520{ 1527{
1521 struct TcpHandshakeSignature ths; 1528 struct TcpHandshakeSignature ths;
1522 struct TCPConfirmation tc; 1529 struct TCPConfirmation tc;
1523 1530
1524 memcpy(queue->cwrite_buf, epub, sizeof(*epub)); 1531 memcpy (queue->cwrite_buf, epub, sizeof(*epub));
1525 queue->cwrite_off = sizeof(epub); 1532 queue->cwrite_off = sizeof(epub);
1526 /* compute 'tc' and append in encrypted format to cwrite_buf */ 1533 /* compute 'tc' and append in encrypted format to cwrite_buf */
1527 tc.sender = my_identity; 1534 tc.sender = my_identity;
1528 tc.monotonic_time = 1535 tc.monotonic_time =
1529 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg)); 1536 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
1530 ths.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); 1537 ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
1531 ths.purpose.size = htonl(sizeof(ths)); 1538 ths.purpose.size = htonl (sizeof(ths));
1532 ths.sender = my_identity; 1539 ths.sender = my_identity;
1533 ths.receiver = queue->target; 1540 ths.receiver = queue->target;
1534 ths.ephemeral = *epub; 1541 ths.ephemeral = *epub;
1535 ths.monotonic_time = tc.monotonic_time; 1542 ths.monotonic_time = tc.monotonic_time;
1536 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, 1543 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key,
1537 &ths.purpose, 1544 &ths.purpose,
1538 &tc.sender_sig)); 1545 &tc.sender_sig));
1539 GNUNET_assert(0 == 1546 GNUNET_assert (0 ==
1540 gcry_cipher_encrypt(queue->out_cipher, 1547 gcry_cipher_encrypt (queue->out_cipher,
1541 &queue->cwrite_buf[queue->cwrite_off], 1548 &queue->cwrite_buf[queue->cwrite_off],
1542 sizeof(tc), 1549 sizeof(tc),
1543 &tc, 1550 &tc,
1544 sizeof(tc))); 1551 sizeof(tc)));
1545 queue->cwrite_off += sizeof(tc); 1552 queue->cwrite_off += sizeof(tc);
1546} 1553}
1547 1554
@@ -1554,15 +1561,15 @@ transmit_kx(struct Queue *queue,
1554 * @param queue the queue to setup 1561 * @param queue the queue to setup
1555 */ 1562 */
1556static void 1563static void
1557start_initial_kx_out(struct Queue *queue) 1564start_initial_kx_out (struct Queue *queue)
1558{ 1565{
1559 struct GNUNET_CRYPTO_EcdhePublicKey epub; 1566 struct GNUNET_CRYPTO_EcdhePublicKey epub;
1560 1567
1561 GNUNET_assert(GNUNET_OK == 1568 GNUNET_assert (GNUNET_OK ==
1562 GNUNET_CRYPTO_ecdhe_key_create2(&queue->ephemeral)); 1569 GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral));
1563 GNUNET_CRYPTO_ecdhe_key_get_public(&queue->ephemeral, &epub); 1570 GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &epub);
1564 setup_out_cipher(queue); 1571 setup_out_cipher (queue);
1565 transmit_kx(queue, &epub); 1572 transmit_kx (queue, &epub);
1566} 1573}
1567 1574
1568 1575
@@ -1578,31 +1585,32 @@ start_initial_kx_out(struct Queue *queue)
1578 * @return #GNUNET_OK if the signature was OK, #GNUNET_SYSERR if not 1585 * @return #GNUNET_OK if the signature was OK, #GNUNET_SYSERR if not
1579 */ 1586 */
1580static int 1587static int
1581decrypt_and_check_tc(struct Queue *queue, 1588decrypt_and_check_tc (struct Queue *queue,
1582 struct TCPConfirmation *tc, 1589 struct TCPConfirmation *tc,
1583 char *ibuf) 1590 char *ibuf)
1584{ 1591{
1585 struct TcpHandshakeSignature ths; 1592 struct TcpHandshakeSignature ths;
1586 1593
1587 GNUNET_assert( 1594 GNUNET_assert (
1588 0 == 1595 0 ==
1589 gcry_cipher_decrypt(queue->in_cipher, 1596 gcry_cipher_decrypt (queue->in_cipher,
1590 tc, 1597 tc,
1591 sizeof(*tc), 1598 sizeof(*tc),
1592 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)], 1599 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
1593 sizeof(tc))); 1600 sizeof(tc)));
1594 ths.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); 1601 ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
1595 ths.purpose.size = htonl(sizeof(ths)); 1602 ths.purpose.size = htonl (sizeof(ths));
1596 ths.sender = tc->sender; 1603 ths.sender = tc->sender;
1597 ths.receiver = my_identity; 1604 ths.receiver = my_identity;
1598 memcpy(&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)); 1605 memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
1599 ths.monotonic_time = tc->monotonic_time; 1606 ths.monotonic_time = tc->monotonic_time;
1600 /* FIXME: check monotonic time against previous mono times 1607 /* FIXME: check monotonic time against previous mono times
1601 from this sender! */ 1608 from this sender! */
1602 return GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, 1609 return GNUNET_CRYPTO_eddsa_verify (
1603 &ths.purpose, 1610 GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE,
1604 &tc->sender_sig, 1611 &ths.purpose,
1605 &tc->sender.public_key); 1612 &tc->sender_sig,
1613 &tc->sender.public_key);
1606} 1614}
1607 1615
1608 1616
@@ -1612,12 +1620,12 @@ decrypt_and_check_tc(struct Queue *queue,
1612 * @param pq proto queue to free 1620 * @param pq proto queue to free
1613 */ 1621 */
1614static void 1622static void
1615free_proto_queue(struct ProtoQueue *pq) 1623free_proto_queue (struct ProtoQueue *pq)
1616{ 1624{
1617 GNUNET_NETWORK_socket_close(pq->sock); 1625 GNUNET_NETWORK_socket_close (pq->sock);
1618 GNUNET_free(pq->address); 1626 GNUNET_free (pq->address);
1619 GNUNET_CONTAINER_DLL_remove(proto_head, proto_tail, pq); 1627 GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
1620 GNUNET_free(pq); 1628 GNUNET_free (pq);
1621} 1629}
1622 1630
1623 1631
@@ -1628,7 +1636,7 @@ free_proto_queue(struct ProtoQueue *pq)
1628 * @param cls a `struct ProtoQueue` 1636 * @param cls a `struct ProtoQueue`
1629 */ 1637 */
1630static void 1638static void
1631proto_read_kx(void *cls) 1639proto_read_kx (void *cls)
1632{ 1640{
1633 struct ProtoQueue *pq = cls; 1641 struct ProtoQueue *pq = cls;
1634 ssize_t rcvd; 1642 ssize_t rcvd;
@@ -1637,67 +1645,67 @@ proto_read_kx(void *cls)
1637 struct TCPConfirmation tc; 1645 struct TCPConfirmation tc;
1638 1646
1639 pq->read_task = NULL; 1647 pq->read_task = NULL;
1640 left = GNUNET_TIME_absolute_get_remaining(pq->timeout); 1648 left = GNUNET_TIME_absolute_get_remaining (pq->timeout);
1641 if (0 == left.rel_value_us) 1649 if (0 == left.rel_value_us)
1642 { 1650 {
1643 free_proto_queue(pq); 1651 free_proto_queue (pq);
1644 return; 1652 return;
1645 } 1653 }
1646 rcvd = GNUNET_NETWORK_socket_recv(pq->sock, 1654 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
1647 &pq->ibuf[pq->ibuf_off], 1655 &pq->ibuf[pq->ibuf_off],
1648 sizeof(pq->ibuf) - pq->ibuf_off); 1656 sizeof(pq->ibuf) - pq->ibuf_off);
1649 if (-1 == rcvd) 1657 if (-1 == rcvd)
1658 {
1659 if ((EAGAIN != errno) && (EINTR != errno))
1650 { 1660 {
1651 if ((EAGAIN != errno) && (EINTR != errno)) 1661 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
1652 { 1662 free_proto_queue (pq);
1653 GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv");
1654 free_proto_queue(pq);
1655 return;
1656 }
1657 /* try again */
1658 pq->read_task =
1659 GNUNET_SCHEDULER_add_read_net(left, pq->sock, &proto_read_kx, pq);
1660 return; 1663 return;
1661 } 1664 }
1665 /* try again */
1666 pq->read_task =
1667 GNUNET_SCHEDULER_add_read_net (left, pq->sock, &proto_read_kx, pq);
1668 return;
1669 }
1662 pq->ibuf_off += rcvd; 1670 pq->ibuf_off += rcvd;
1663 if (pq->ibuf_off > sizeof(pq->ibuf)) 1671 if (pq->ibuf_off > sizeof(pq->ibuf))
1664 { 1672 {
1665 /* read more */ 1673 /* read more */
1666 pq->read_task = 1674 pq->read_task =
1667 GNUNET_SCHEDULER_add_read_net(left, pq->sock, &proto_read_kx, pq); 1675 GNUNET_SCHEDULER_add_read_net (left, pq->sock, &proto_read_kx, pq);
1668 return; 1676 return;
1669 } 1677 }
1670 /* we got all the data, let's find out who we are talking to! */ 1678 /* we got all the data, let's find out who we are talking to! */
1671 queue = GNUNET_new(struct Queue); 1679 queue = GNUNET_new (struct Queue);
1672 setup_in_cipher((const struct GNUNET_CRYPTO_EcdhePublicKey *)pq->ibuf, 1680 setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
1673 queue); 1681 queue);
1674 if (GNUNET_OK != decrypt_and_check_tc(queue, &tc, pq->ibuf)) 1682 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
1675 { 1683 {
1676 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1684 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1677 "Invalid TCP KX received from %s\n", 1685 "Invalid TCP KX received from %s\n",
1678 GNUNET_a2s(queue->address, queue->address_len)); 1686 GNUNET_a2s (queue->address, queue->address_len));
1679 gcry_cipher_close(queue->in_cipher); 1687 gcry_cipher_close (queue->in_cipher);
1680 GNUNET_free(queue); 1688 GNUNET_free (queue);
1681 free_proto_queue(pq); 1689 free_proto_queue (pq);
1682 return; 1690 return;
1683 } 1691 }
1684 queue->address = pq->address; /* steals reference */ 1692 queue->address = pq->address; /* steals reference */
1685 queue->address_len = pq->address_len; 1693 queue->address_len = pq->address_len;
1686 queue->target = tc.sender; 1694 queue->target = tc.sender;
1687 start_initial_kx_out(queue); 1695 start_initial_kx_out (queue);
1688 boot_queue(queue, GNUNET_TRANSPORT_CS_INBOUND); 1696 boot_queue (queue, GNUNET_TRANSPORT_CS_INBOUND);
1689 queue->read_task = 1697 queue->read_task =
1690 GNUNET_SCHEDULER_add_read_net(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1698 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1691 queue->sock,
1692 &queue_read,
1693 queue);
1694 queue->write_task =
1695 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
1696 queue->sock, 1699 queue->sock,
1697 &queue_write, 1700 &queue_read,
1698 queue); 1701 queue);
1699 GNUNET_CONTAINER_DLL_remove(proto_head, proto_tail, pq); 1702 queue->write_task =
1700 GNUNET_free(pq); 1703 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1704 queue->sock,
1705 &queue_write,
1706 queue);
1707 GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
1708 GNUNET_free (pq);
1701} 1709}
1702 1710
1703 1711
@@ -1709,7 +1717,7 @@ proto_read_kx(void *cls)
1709 * @param cls NULL 1717 * @param cls NULL
1710 */ 1718 */
1711static void 1719static void
1712listen_cb(void *cls) 1720listen_cb (void *cls)
1713{ 1721{
1714 struct sockaddr_storage in; 1722 struct sockaddr_storage in;
1715 socklen_t addrlen; 1723 socklen_t addrlen;
@@ -1717,35 +1725,35 @@ listen_cb(void *cls)
1717 struct ProtoQueue *pq; 1725 struct ProtoQueue *pq;
1718 1726
1719 listen_task = NULL; 1727 listen_task = NULL;
1720 GNUNET_assert(NULL != listen_sock); 1728 GNUNET_assert (NULL != listen_sock);
1721 addrlen = sizeof(in); 1729 addrlen = sizeof(in);
1722 memset(&in, 0, sizeof(in)); 1730 memset (&in, 0, sizeof(in));
1723 sock = GNUNET_NETWORK_socket_accept(listen_sock, 1731 sock = GNUNET_NETWORK_socket_accept (listen_sock,
1724 (struct sockaddr *)&in, 1732 (struct sockaddr *) &in,
1725 &addrlen); 1733 &addrlen);
1726 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno))) 1734 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
1727 return; /* system limit reached, wait until connection goes down */ 1735 return; /* system limit reached, wait until connection goes down */
1728 listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 1736 listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1729 listen_sock, 1737 listen_sock,
1730 &listen_cb, 1738 &listen_cb,
1731 NULL); 1739 NULL);
1732 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno))) 1740 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
1733 return; 1741 return;
1734 if (NULL == sock) 1742 if (NULL == sock)
1735 { 1743 {
1736 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "accept"); 1744 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept");
1737 return; 1745 return;
1738 } 1746 }
1739 pq = GNUNET_new(struct ProtoQueue); 1747 pq = GNUNET_new (struct ProtoQueue);
1740 pq->address_len = addrlen; 1748 pq->address_len = addrlen;
1741 pq->address = GNUNET_memdup(&in, addrlen); 1749 pq->address = GNUNET_memdup (&in, addrlen);
1742 pq->timeout = GNUNET_TIME_relative_to_absolute(PROTO_QUEUE_TIMEOUT); 1750 pq->timeout = GNUNET_TIME_relative_to_absolute (PROTO_QUEUE_TIMEOUT);
1743 pq->sock = sock; 1751 pq->sock = sock;
1744 pq->read_task = GNUNET_SCHEDULER_add_read_net(PROTO_QUEUE_TIMEOUT, 1752 pq->read_task = GNUNET_SCHEDULER_add_read_net (PROTO_QUEUE_TIMEOUT,
1745 pq->sock, 1753 pq->sock,
1746 &proto_read_kx, 1754 &proto_read_kx,
1747 pq); 1755 pq);
1748 GNUNET_CONTAINER_DLL_insert(proto_head, proto_tail, pq); 1756 GNUNET_CONTAINER_DLL_insert (proto_head, proto_tail, pq);
1749} 1757}
1750 1758
1751 1759
@@ -1757,7 +1765,7 @@ listen_cb(void *cls)
1757 * @param cls a `struct Queue` 1765 * @param cls a `struct Queue`
1758 */ 1766 */
1759static void 1767static void
1760queue_read_kx(void *cls) 1768queue_read_kx (void *cls)
1761{ 1769{
1762 struct Queue *queue = cls; 1770 struct Queue *queue = cls;
1763 ssize_t rcvd; 1771 ssize_t rcvd;
@@ -1765,65 +1773,65 @@ queue_read_kx(void *cls)
1765 struct TCPConfirmation tc; 1773 struct TCPConfirmation tc;
1766 1774
1767 queue->read_task = NULL; 1775 queue->read_task = NULL;
1768 left = GNUNET_TIME_absolute_get_remaining(queue->timeout); 1776 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
1769 if (0 == left.rel_value_us) 1777 if (0 == left.rel_value_us)
1770 { 1778 {
1771 queue_destroy(queue); 1779 queue_destroy (queue);
1772 return; 1780 return;
1773 } 1781 }
1774 rcvd = GNUNET_NETWORK_socket_recv(queue->sock, 1782 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1775 &queue->cread_buf[queue->cread_off], 1783 &queue->cread_buf[queue->cread_off],
1776 BUF_SIZE - queue->cread_off); 1784 BUF_SIZE - queue->cread_off);
1777 if (-1 == rcvd) 1785 if (-1 == rcvd)
1786 {
1787 if ((EAGAIN != errno) && (EINTR != errno))
1778 { 1788 {
1779 if ((EAGAIN != errno) && (EINTR != errno)) 1789 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
1780 { 1790 queue_destroy (queue);
1781 GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv");
1782 queue_destroy(queue);
1783 return;
1784 }
1785 queue->read_task =
1786 GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read_kx, queue);
1787 return; 1791 return;
1788 } 1792 }
1793 queue->read_task =
1794 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
1795 return;
1796 }
1789 queue->cread_off += rcvd; 1797 queue->cread_off += rcvd;
1790 if (queue->cread_off < INITIAL_KX_SIZE) 1798 if (queue->cread_off < INITIAL_KX_SIZE)
1791 { 1799 {
1792 /* read more */ 1800 /* read more */
1793 queue->read_task = 1801 queue->read_task =
1794 GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read_kx, queue); 1802 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
1795 return; 1803 return;
1796 } 1804 }
1797 /* we got all the data, let's find out who we are talking to! */ 1805 /* we got all the data, let's find out who we are talking to! */
1798 setup_in_cipher((const struct GNUNET_CRYPTO_EcdhePublicKey *) 1806 setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *)
1799 queue->cread_buf, 1807 queue->cread_buf,
1800 queue); 1808 queue);
1801 if (GNUNET_OK != decrypt_and_check_tc(queue, &tc, queue->cread_buf)) 1809 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
1802 { 1810 {
1803 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1811 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1804 "Invalid TCP KX received from %s\n", 1812 "Invalid TCP KX received from %s\n",
1805 GNUNET_a2s(queue->address, queue->address_len)); 1813 GNUNET_a2s (queue->address, queue->address_len));
1806 queue_destroy(queue); 1814 queue_destroy (queue);
1807 return; 1815 return;
1808 } 1816 }
1809 if (0 != 1817 if (0 !=
1810 memcmp(&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity))) 1818 memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
1811 { 1819 {
1812 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1820 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1813 "Invalid sender in TCP KX received from %s\n", 1821 "Invalid sender in TCP KX received from %s\n",
1814 GNUNET_a2s(queue->address, queue->address_len)); 1822 GNUNET_a2s (queue->address, queue->address_len));
1815 queue_destroy(queue); 1823 queue_destroy (queue);
1816 return; 1824 return;
1817 } 1825 }
1818 1826
1819 /* update queue timeout */ 1827 /* update queue timeout */
1820 reschedule_queue_timeout(queue); 1828 reschedule_queue_timeout (queue);
1821 /* prepare to continue with regular read task immediately */ 1829 /* prepare to continue with regular read task immediately */
1822 memmove(queue->cread_buf, 1830 memmove (queue->cread_buf,
1823 &queue->cread_buf[INITIAL_KX_SIZE], 1831 &queue->cread_buf[INITIAL_KX_SIZE],
1824 queue->cread_off - (INITIAL_KX_SIZE)); 1832 queue->cread_off - (INITIAL_KX_SIZE));
1825 queue->cread_off -= INITIAL_KX_SIZE; 1833 queue->cread_off -= INITIAL_KX_SIZE;
1826 queue->read_task = GNUNET_SCHEDULER_add_now(&queue_read, queue); 1834 queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
1827} 1835}
1828 1836
1829 1837
@@ -1846,7 +1854,7 @@ queue_read_kx(void *cls)
1846 * invalid 1854 * invalid
1847 */ 1855 */
1848static int 1856static int
1849mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) 1857mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1850{ 1858{
1851 struct Queue *queue; 1859 struct Queue *queue;
1852 const char *path; 1860 const char *path;
@@ -1854,54 +1862,54 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1854 socklen_t in_len; 1862 socklen_t in_len;
1855 struct GNUNET_NETWORK_Handle *sock; 1863 struct GNUNET_NETWORK_Handle *sock;
1856 1864
1857 if (0 != strncmp(address, 1865 if (0 != strncmp (address,
1858 COMMUNICATOR_ADDRESS_PREFIX "-", 1866 COMMUNICATOR_ADDRESS_PREFIX "-",
1859 strlen(COMMUNICATOR_ADDRESS_PREFIX "-"))) 1867 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
1860 { 1868 {
1861 GNUNET_break_op(0); 1869 GNUNET_break_op (0);
1862 return GNUNET_SYSERR; 1870 return GNUNET_SYSERR;
1863 } 1871 }
1864 path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")]; 1872 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
1865 in = tcp_address_to_sockaddr(path, &in_len); 1873 in = tcp_address_to_sockaddr (path, &in_len);
1866 1874
1867 sock = GNUNET_NETWORK_socket_create(in->sa_family, SOCK_STREAM, IPPROTO_TCP); 1875 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
1868 if (NULL == sock) 1876 if (NULL == sock)
1869 { 1877 {
1870 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1878 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1871 "socket(%d) failed: %s", 1879 "socket(%d) failed: %s",
1872 in->sa_family, 1880 in->sa_family,
1873 strerror(errno)); 1881 strerror (errno));
1874 GNUNET_free(in); 1882 GNUNET_free (in);
1875 return GNUNET_SYSERR; 1883 return GNUNET_SYSERR;
1876 } 1884 }
1877 if (GNUNET_OK != GNUNET_NETWORK_socket_connect(sock, in, in_len)) 1885 if (GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len))
1878 { 1886 {
1879 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1887 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1880 "connect to `%s' failed: %s", 1888 "connect to `%s' failed: %s",
1881 address, 1889 address,
1882 strerror(errno)); 1890 strerror (errno));
1883 GNUNET_NETWORK_socket_close(sock); 1891 GNUNET_NETWORK_socket_close (sock);
1884 GNUNET_free(in); 1892 GNUNET_free (in);
1885 return GNUNET_SYSERR; 1893 return GNUNET_SYSERR;
1886 } 1894 }
1887 1895
1888 queue = GNUNET_new(struct Queue); 1896 queue = GNUNET_new (struct Queue);
1889 queue->target = *peer; 1897 queue->target = *peer;
1890 queue->address = in; 1898 queue->address = in;
1891 queue->address_len = in_len; 1899 queue->address_len = in_len;
1892 queue->sock = sock; 1900 queue->sock = sock;
1893 boot_queue(queue, GNUNET_TRANSPORT_CS_OUTBOUND); 1901 boot_queue (queue, GNUNET_TRANSPORT_CS_OUTBOUND);
1894 queue->read_task = 1902 queue->read_task =
1895 GNUNET_SCHEDULER_add_read_net(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1903 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1896 queue->sock,
1897 &queue_read_kx,
1898 queue);
1899 start_initial_kx_out(queue);
1900 queue->write_task =
1901 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
1902 queue->sock, 1904 queue->sock,
1903 &queue_write, 1905 &queue_read_kx,
1904 queue); 1906 queue);
1907 start_initial_kx_out (queue);
1908 queue->write_task =
1909 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1910 queue->sock,
1911 &queue_write,
1912 queue);
1905 return GNUNET_OK; 1913 return GNUNET_OK;
1906} 1914}
1907 1915
@@ -1915,15 +1923,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1915 * @return #GNUNET_OK to continue to iterate 1923 * @return #GNUNET_OK to continue to iterate
1916 */ 1924 */
1917static int 1925static int
1918get_queue_delete_it(void *cls, 1926get_queue_delete_it (void *cls,
1919 const struct GNUNET_PeerIdentity *target, 1927 const struct GNUNET_PeerIdentity *target,
1920 void *value) 1928 void *value)
1921{ 1929{
1922 struct Queue *queue = value; 1930 struct Queue *queue = value;
1923 1931
1924 (void)cls; 1932 (void) cls;
1925 (void)target; 1933 (void) target;
1926 queue_destroy(queue); 1934 queue_destroy (queue);
1927 return GNUNET_OK; 1935 return GNUNET_OK;
1928} 1936}
1929 1937
@@ -1934,47 +1942,47 @@ get_queue_delete_it(void *cls,
1934 * @param cls NULL (always) 1942 * @param cls NULL (always)
1935 */ 1943 */
1936static void 1944static void
1937do_shutdown(void *cls) 1945do_shutdown (void *cls)
1938{ 1946{
1939 while (NULL != proto_head) 1947 while (NULL != proto_head)
1940 free_proto_queue(proto_head); 1948 free_proto_queue (proto_head);
1941 if (NULL != nat) 1949 if (NULL != nat)
1942 { 1950 {
1943 GNUNET_NAT_unregister(nat); 1951 GNUNET_NAT_unregister (nat);
1944 nat = NULL; 1952 nat = NULL;
1945 } 1953 }
1946 if (NULL != listen_task) 1954 if (NULL != listen_task)
1947 { 1955 {
1948 GNUNET_SCHEDULER_cancel(listen_task); 1956 GNUNET_SCHEDULER_cancel (listen_task);
1949 listen_task = NULL; 1957 listen_task = NULL;
1950 } 1958 }
1951 if (NULL != listen_sock) 1959 if (NULL != listen_sock)
1952 { 1960 {
1953 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(listen_sock)); 1961 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (listen_sock));
1954 listen_sock = NULL; 1962 listen_sock = NULL;
1955 } 1963 }
1956 GNUNET_CONTAINER_multipeermap_iterate(queue_map, &get_queue_delete_it, NULL); 1964 GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL);
1957 GNUNET_CONTAINER_multipeermap_destroy(queue_map); 1965 GNUNET_CONTAINER_multipeermap_destroy (queue_map);
1958 if (NULL != ch) 1966 if (NULL != ch)
1959 { 1967 {
1960 GNUNET_TRANSPORT_communicator_disconnect(ch); 1968 GNUNET_TRANSPORT_communicator_disconnect (ch);
1961 ch = NULL; 1969 ch = NULL;
1962 } 1970 }
1963 if (NULL != stats) 1971 if (NULL != stats)
1964 { 1972 {
1965 GNUNET_STATISTICS_destroy(stats, GNUNET_NO); 1973 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
1966 stats = NULL; 1974 stats = NULL;
1967 } 1975 }
1968 if (NULL != my_private_key) 1976 if (NULL != my_private_key)
1969 { 1977 {
1970 GNUNET_free(my_private_key); 1978 GNUNET_free (my_private_key);
1971 my_private_key = NULL; 1979 my_private_key = NULL;
1972 } 1980 }
1973 if (NULL != is) 1981 if (NULL != is)
1974 { 1982 {
1975 GNUNET_NT_scanner_done(is); 1983 GNUNET_NT_scanner_done (is);
1976 is = NULL; 1984 is = NULL;
1977 } 1985 }
1978} 1986}
1979 1987
1980 1988
@@ -1990,14 +1998,14 @@ do_shutdown(void *cls)
1990 * @param msg payload 1998 * @param msg payload
1991 */ 1999 */
1992static void 2000static void
1993enc_notify_cb(void *cls, 2001enc_notify_cb (void *cls,
1994 const struct GNUNET_PeerIdentity *sender, 2002 const struct GNUNET_PeerIdentity *sender,
1995 const struct GNUNET_MessageHeader *msg) 2003 const struct GNUNET_MessageHeader *msg)
1996{ 2004{
1997 (void)cls; 2005 (void) cls;
1998 (void)sender; 2006 (void) sender;
1999 (void)msg; 2007 (void) msg;
2000 GNUNET_break_op(0); 2008 GNUNET_break_op (0);
2001} 2009}
2002 2010
2003 2011
@@ -2015,39 +2023,39 @@ enc_notify_cb(void *cls,
2015 * @param addrlen actual length of the @a addr 2023 * @param addrlen actual length of the @a addr
2016 */ 2024 */
2017static void 2025static void
2018nat_address_cb(void *cls, 2026nat_address_cb (void *cls,
2019 void **app_ctx, 2027 void **app_ctx,
2020 int add_remove, 2028 int add_remove,
2021 enum GNUNET_NAT_AddressClass ac, 2029 enum GNUNET_NAT_AddressClass ac,
2022 const struct sockaddr *addr, 2030 const struct sockaddr *addr,
2023 socklen_t addrlen) 2031 socklen_t addrlen)
2024{ 2032{
2025 char *my_addr; 2033 char *my_addr;
2026 struct GNUNET_TRANSPORT_AddressIdentifier *ai; 2034 struct GNUNET_TRANSPORT_AddressIdentifier *ai;
2027 2035
2028 if (GNUNET_YES == add_remove) 2036 if (GNUNET_YES == add_remove)
2029 { 2037 {
2030 enum GNUNET_NetworkType nt; 2038 enum GNUNET_NetworkType nt;
2031 2039
2032 GNUNET_asprintf(&my_addr, 2040 GNUNET_asprintf (&my_addr,
2033 "%s-%s", 2041 "%s-%s",
2034 COMMUNICATOR_ADDRESS_PREFIX, 2042 COMMUNICATOR_ADDRESS_PREFIX,
2035 GNUNET_a2s(addr, addrlen)); 2043 GNUNET_a2s (addr, addrlen));
2036 nt = GNUNET_NT_scanner_get_type(is, addr, addrlen); 2044 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
2037 ai = 2045 ai =
2038 GNUNET_TRANSPORT_communicator_address_add(ch, 2046 GNUNET_TRANSPORT_communicator_address_add (ch,
2039 my_addr, 2047 my_addr,
2040 nt, 2048 nt,
2041 GNUNET_TIME_UNIT_FOREVER_REL); 2049 GNUNET_TIME_UNIT_FOREVER_REL);
2042 GNUNET_free(my_addr); 2050 GNUNET_free (my_addr);
2043 *app_ctx = ai; 2051 *app_ctx = ai;
2044 } 2052 }
2045 else 2053 else
2046 { 2054 {
2047 ai = *app_ctx; 2055 ai = *app_ctx;
2048 GNUNET_TRANSPORT_communicator_address_remove(ai); 2056 GNUNET_TRANSPORT_communicator_address_remove (ai);
2049 *app_ctx = NULL; 2057 *app_ctx = NULL;
2050 } 2058 }
2051} 2059}
2052 2060
2053 2061
@@ -2060,10 +2068,10 @@ nat_address_cb(void *cls,
2060 * @param c configuration 2068 * @param c configuration
2061 */ 2069 */
2062static void 2070static void
2063run(void *cls, 2071run (void *cls,
2064 char *const *args, 2072 char *const *args,
2065 const char *cfgfile, 2073 const char *cfgfile,
2066 const struct GNUNET_CONFIGURATION_Handle *c) 2074 const struct GNUNET_CONFIGURATION_Handle *c)
2067{ 2075{
2068 char *bindto; 2076 char *bindto;
2069 struct sockaddr *in; 2077 struct sockaddr *in;
@@ -2071,113 +2079,113 @@ run(void *cls,
2071 struct sockaddr_storage in_sto; 2079 struct sockaddr_storage in_sto;
2072 socklen_t sto_len; 2080 socklen_t sto_len;
2073 2081
2074 (void)cls; 2082 (void) cls;
2075 cfg = c; 2083 cfg = c;
2076 if (GNUNET_OK != 2084 if (GNUNET_OK !=
2077 GNUNET_CONFIGURATION_get_value_filename(cfg, 2085 GNUNET_CONFIGURATION_get_value_filename (cfg,
2078 COMMUNICATOR_CONFIG_SECTION, 2086 COMMUNICATOR_CONFIG_SECTION,
2079 "BINDTO", 2087 "BINDTO",
2080 &bindto)) 2088 &bindto))
2081 { 2089 {
2082 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 2090 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2083 COMMUNICATOR_CONFIG_SECTION, 2091 COMMUNICATOR_CONFIG_SECTION,
2084 "BINDTO"); 2092 "BINDTO");
2085 return; 2093 return;
2086 } 2094 }
2087 if (GNUNET_OK != 2095 if (GNUNET_OK !=
2088 GNUNET_CONFIGURATION_get_value_number(cfg, 2096 GNUNET_CONFIGURATION_get_value_number (cfg,
2089 COMMUNICATOR_CONFIG_SECTION, 2097 COMMUNICATOR_CONFIG_SECTION,
2090 "MAX_QUEUE_LENGTH", 2098 "MAX_QUEUE_LENGTH",
2091 &max_queue_length)) 2099 &max_queue_length))
2092 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; 2100 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
2093 2101
2094 in = tcp_address_to_sockaddr(bindto, &in_len); 2102 in = tcp_address_to_sockaddr (bindto, &in_len);
2095 if (NULL == in) 2103 if (NULL == in)
2096 { 2104 {
2097 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2105 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2098 "Failed to setup TCP socket address with path `%s'\n", 2106 "Failed to setup TCP socket address with path `%s'\n",
2099 bindto); 2107 bindto);
2100 GNUNET_free(bindto); 2108 GNUNET_free (bindto);
2101 return; 2109 return;
2102 } 2110 }
2103 listen_sock = 2111 listen_sock =
2104 GNUNET_NETWORK_socket_create(in->sa_family, SOCK_STREAM, IPPROTO_TCP); 2112 GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2105 if (NULL == listen_sock) 2113 if (NULL == listen_sock)
2106 { 2114 {
2107 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); 2115 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
2108 GNUNET_free(in); 2116 GNUNET_free (in);
2109 GNUNET_free(bindto); 2117 GNUNET_free (bindto);
2110 return; 2118 return;
2111 } 2119 }
2112 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(listen_sock, in, in_len)) 2120 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, in, in_len))
2113 { 2121 {
2114 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", bindto); 2122 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto);
2115 GNUNET_NETWORK_socket_close(listen_sock); 2123 GNUNET_NETWORK_socket_close (listen_sock);
2116 listen_sock = NULL; 2124 listen_sock = NULL;
2117 GNUNET_free(in); 2125 GNUNET_free (in);
2118 GNUNET_free(bindto); 2126 GNUNET_free (bindto);
2119 return; 2127 return;
2120 } 2128 }
2121 /* We might have bound to port 0, allowing the OS to figure it out; 2129 /* We might have bound to port 0, allowing the OS to figure it out;
2122 thus, get the real IN-address from the socket */ 2130 thus, get the real IN-address from the socket */
2123 sto_len = sizeof(in_sto); 2131 sto_len = sizeof(in_sto);
2124 if (0 != getsockname(GNUNET_NETWORK_get_fd(listen_sock), 2132 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
2125 (struct sockaddr *)&in_sto, 2133 (struct sockaddr *) &in_sto,
2126 &sto_len)) 2134 &sto_len))
2127 { 2135 {
2128 memcpy(&in_sto, in, in_len); 2136 memcpy (&in_sto, in, in_len);
2129 sto_len = in_len; 2137 sto_len = in_len;
2130 } 2138 }
2131 GNUNET_free(in); 2139 GNUNET_free (in);
2132 GNUNET_free(bindto); 2140 GNUNET_free (bindto);
2133 in = (struct sockaddr *)&in_sto; 2141 in = (struct sockaddr *) &in_sto;
2134 in_len = sto_len; 2142 in_len = sto_len;
2135 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2136 "Bound to `%s'\n", 2144 "Bound to `%s'\n",
2137 GNUNET_a2s((const struct sockaddr *)&in_sto, sto_len)); 2145 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
2138 stats = GNUNET_STATISTICS_create("C-TCP", cfg); 2146 stats = GNUNET_STATISTICS_create ("C-TCP", cfg);
2139 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 2147 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
2140 is = GNUNET_NT_scanner_init(); 2148 is = GNUNET_NT_scanner_init ();
2141 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); 2149 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
2142 if (NULL == my_private_key) 2150 if (NULL == my_private_key)
2143 { 2151 {
2144 GNUNET_log( 2152 GNUNET_log (
2145 GNUNET_ERROR_TYPE_ERROR, 2153 GNUNET_ERROR_TYPE_ERROR,
2146 _( 2154 _ (
2147 "Transport service is lacking key configuration settings. Exiting.\n")); 2155 "Transport service is lacking key configuration settings. Exiting.\n"));
2148 GNUNET_SCHEDULER_shutdown(); 2156 GNUNET_SCHEDULER_shutdown ();
2149 return; 2157 return;
2150 } 2158 }
2151 GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key); 2159 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
2152 /* start listening */ 2160 /* start listening */
2153 listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 2161 listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
2154 listen_sock, 2162 listen_sock,
2155 &listen_cb, 2163 &listen_cb,
2164 NULL);
2165 queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
2166 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
2167 COMMUNICATOR_CONFIG_SECTION,
2168 COMMUNICATOR_ADDRESS_PREFIX,
2169 GNUNET_TRANSPORT_CC_RELIABLE,
2170 &mq_init,
2171 NULL,
2172 &enc_notify_cb,
2156 NULL); 2173 NULL);
2157 queue_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
2158 ch = GNUNET_TRANSPORT_communicator_connect(cfg,
2159 COMMUNICATOR_CONFIG_SECTION,
2160 COMMUNICATOR_ADDRESS_PREFIX,
2161 GNUNET_TRANSPORT_CC_RELIABLE,
2162 &mq_init,
2163 NULL,
2164 &enc_notify_cb,
2165 NULL);
2166 if (NULL == ch) 2174 if (NULL == ch)
2167 { 2175 {
2168 GNUNET_break(0); 2176 GNUNET_break (0);
2169 GNUNET_SCHEDULER_shutdown(); 2177 GNUNET_SCHEDULER_shutdown ();
2170 return; 2178 return;
2171 } 2179 }
2172 nat = GNUNET_NAT_register(cfg, 2180 nat = GNUNET_NAT_register (cfg,
2173 COMMUNICATOR_CONFIG_SECTION, 2181 COMMUNICATOR_CONFIG_SECTION,
2174 IPPROTO_TCP, 2182 IPPROTO_TCP,
2175 1 /* one address */, 2183 1 /* one address */,
2176 (const struct sockaddr **)&in, 2184 (const struct sockaddr **) &in,
2177 &in_len, 2185 &in_len,
2178 &nat_address_cb, 2186 &nat_address_cb,
2179 NULL /* FIXME: support reversal: #5529 */, 2187 NULL /* FIXME: support reversal: #5529 */,
2180 NULL /* closure */); 2188 NULL /* closure */);
2181} 2189}
2182 2190
2183 2191
@@ -2189,26 +2197,26 @@ run(void *cls,
2189 * @return 0 ok, 1 on error 2197 * @return 0 ok, 1 on error
2190 */ 2198 */
2191int 2199int
2192main(int argc, char *const *argv) 2200main (int argc, char *const *argv)
2193{ 2201{
2194 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 2202 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
2195 GNUNET_GETOPT_OPTION_END 2203 GNUNET_GETOPT_OPTION_END
2196 }; 2204 };
2197 int ret; 2205 int ret;
2198 2206
2199 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 2207 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
2200 return 2; 2208 return 2;
2201 2209
2202 ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc, 2210 ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
2203 argv, 2211 argv,
2204 "gnunet-communicator-tcp", 2212 "gnunet-communicator-tcp",
2205 _("GNUnet TCP communicator"), 2213 _ ("GNUnet TCP communicator"),
2206 options, 2214 options,
2207 &run, 2215 &run,
2208 NULL)) 2216 NULL))
2209 ? 0 2217 ? 0
2210 : 1; 2218 : 1;
2211 GNUNET_free((void *)argv); 2219 GNUNET_free ((void *) argv);
2212 return ret; 2220 return ret;
2213} 2221}
2214 2222
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 @@
67 * How often do we scan for changes to our network interfaces? 67 * How often do we scan for changes to our network interfaces?
68 */ 68 */
69#define INTERFACE_SCAN_FREQUENCY \ 69#define INTERFACE_SCAN_FREQUENCY \
70 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) 70 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
71 71
72/** 72/**
73 * How long do we believe our addresses to remain up (before 73 * How long do we believe our addresses to remain up (before
@@ -156,7 +156,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
156 * the specified sender. If possible, the receiver should respond with 156 * the specified sender. If possible, the receiver should respond with
157 * a `struct UDPAck` (possibly via backchannel). 157 * a `struct UDPAck` (possibly via backchannel).
158 */ 158 */
159struct UdpHandshakeSignature { 159struct UdpHandshakeSignature
160{
160 /** 161 /**
161 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE 162 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE
162 */ 163 */
@@ -189,7 +190,8 @@ struct UdpHandshakeSignature {
189 * "Plaintext" header at beginning of KX message. Followed 190 * "Plaintext" header at beginning of KX message. Followed
190 * by encrypted `struct UDPConfirmation`. 191 * by encrypted `struct UDPConfirmation`.
191 */ 192 */
192struct InitialKX { 193struct InitialKX
194{
193 /** 195 /**
194 * Ephemeral key for KX. 196 * Ephemeral key for KX.
195 */ 197 */
@@ -207,7 +209,8 @@ struct InitialKX {
207 * Encrypted continuation of UDP initial handshake, followed 209 * Encrypted continuation of UDP initial handshake, followed
208 * by message header with payload. 210 * by message header with payload.
209 */ 211 */
210struct UDPConfirmation { 212struct UDPConfirmation
213{
211 /** 214 /**
212 * Sender's identity 215 * Sender's identity
213 */ 216 */
@@ -234,7 +237,8 @@ struct UDPConfirmation {
234 * UDP key acknowledgement. May be sent via backchannel. Allows the 237 * UDP key acknowledgement. May be sent via backchannel. Allows the
235 * sender to use `struct UDPBox` with the acknowledge key henceforth. 238 * sender to use `struct UDPBox` with the acknowledge key henceforth.
236 */ 239 */
237struct UDPAck { 240struct UDPAck
241{
238 /** 242 /**
239 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK. 243 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK.
240 */ 244 */
@@ -261,7 +265,8 @@ struct UDPAck {
261 * be just any global peer -- an attacker must have at least 265 * be just any global peer -- an attacker must have at least
262 * shared a LAN with the peer they're pretending to be here. 266 * shared a LAN with the peer they're pretending to be here.
263 */ 267 */
264struct UdpBroadcastSignature { 268struct UdpBroadcastSignature
269{
265 /** 270 /**
266 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST 271 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST
267 */ 272 */
@@ -285,7 +290,8 @@ struct UdpBroadcastSignature {
285 * recognized in LAN as GNUnet peers if this feature is enabled 290 * recognized in LAN as GNUnet peers if this feature is enabled
286 * anyway. Also, the entire message is in cleartext. 291 * anyway. Also, the entire message is in cleartext.
287 */ 292 */
288struct UDPBroadcast { 293struct UDPBroadcast
294{
289 /** 295 /**
290 * Sender's peer identity. 296 * Sender's peer identity.
291 */ 297 */
@@ -303,7 +309,8 @@ struct UDPBroadcast {
303 * UDP message box. Always sent encrypted, only allowed after 309 * UDP message box. Always sent encrypted, only allowed after
304 * the receiver sent a `struct UDPAck` for the base key! 310 * the receiver sent a `struct UDPAck` for the base key!
305 */ 311 */
306struct UDPBox { 312struct UDPBox
313{
307 /** 314 /**
308 * Key and IV identification code. KDF applied to an acknowledged 315 * Key and IV identification code. KDF applied to an acknowledged
309 * base key and a sequence number. Sequence numbers must be used 316 * base key and a sequence number. Sequence numbers must be used
@@ -336,7 +343,8 @@ struct SharedSecret;
336 * Pre-generated "kid" code (key and IV identification code) to 343 * Pre-generated "kid" code (key and IV identification code) to
337 * quickly derive master key for a `struct UDPBox`. 344 * quickly derive master key for a `struct UDPBox`.
338 */ 345 */
339struct KeyCacheEntry { 346struct KeyCacheEntry
347{
340 /** 348 /**
341 * Kept in a DLL. 349 * Kept in a DLL.
342 */ 350 */
@@ -383,7 +391,8 @@ struct ReceiverAddress;
383/** 391/**
384 * Shared secret we generated for a particular sender or receiver. 392 * Shared secret we generated for a particular sender or receiver.
385 */ 393 */
386struct SharedSecret { 394struct SharedSecret
395{
387 /** 396 /**
388 * Kept in a DLL. 397 * Kept in a DLL.
389 */ 398 */
@@ -448,7 +457,8 @@ struct SharedSecret {
448 * Information we track per sender address we have recently been 457 * Information we track per sender address we have recently been
449 * in contact with (we decrypt messages from the sender). 458 * in contact with (we decrypt messages from the sender).
450 */ 459 */
451struct SenderAddress { 460struct SenderAddress
461{
452 /** 462 /**
453 * To whom are we talking to. 463 * To whom are we talking to.
454 */ 464 */
@@ -500,7 +510,8 @@ struct SenderAddress {
500 * Information we track per receiving address we have recently been 510 * Information we track per receiving address we have recently been
501 * in contact with (encryption to receiver). 511 * in contact with (encryption to receiver).
502 */ 512 */
503struct ReceiverAddress { 513struct ReceiverAddress
514{
504 /** 515 /**
505 * To whom are we talking to. 516 * To whom are we talking to.
506 */ 517 */
@@ -578,7 +589,8 @@ struct ReceiverAddress {
578/** 589/**
579 * Interface we broadcast our presence on. 590 * Interface we broadcast our presence on.
580 */ 591 */
581struct BroadcastInterface { 592struct BroadcastInterface
593{
582 /** 594 /**
583 * Kept in a DLL. 595 * Kept in a DLL.
584 */ 596 */
@@ -739,25 +751,25 @@ static uint16_t my_port;
739 * @param bi entity to close down 751 * @param bi entity to close down
740 */ 752 */
741static void 753static void
742bi_destroy(struct BroadcastInterface *bi) 754bi_destroy (struct BroadcastInterface *bi)
743{ 755{
744 if (AF_INET6 == bi->sa->sa_family) 756 if (AF_INET6 == bi->sa->sa_family)
757 {
758 /* Leave the multicast group */
759 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock,
760 IPPROTO_IPV6,
761 IPV6_LEAVE_GROUP,
762 &bi->mcreq,
763 sizeof(bi->mcreq)))
745 { 764 {
746 /* Leave the multicast group */ 765 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
747 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock,
748 IPPROTO_IPV6,
749 IPV6_LEAVE_GROUP,
750 &bi->mcreq,
751 sizeof(bi->mcreq)))
752 {
753 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt");
754 }
755 } 766 }
756 GNUNET_CONTAINER_DLL_remove(bi_head, bi_tail, bi); 767 }
757 GNUNET_SCHEDULER_cancel(bi->broadcast_task); 768 GNUNET_CONTAINER_DLL_remove (bi_head, bi_tail, bi);
758 GNUNET_free(bi->sa); 769 GNUNET_SCHEDULER_cancel (bi->broadcast_task);
759 GNUNET_free_non_null(bi->ba); 770 GNUNET_free (bi->sa);
760 GNUNET_free(bi); 771 GNUNET_free_non_null (bi->ba);
772 GNUNET_free (bi);
761} 773}
762 774
763 775
@@ -767,35 +779,35 @@ bi_destroy(struct BroadcastInterface *bi)
767 * @param receiver entity to close down 779 * @param receiver entity to close down
768 */ 780 */
769static void 781static void
770receiver_destroy(struct ReceiverAddress *receiver) 782receiver_destroy (struct ReceiverAddress *receiver)
771{ 783{
772 struct GNUNET_MQ_Handle *mq; 784 struct GNUNET_MQ_Handle *mq;
773 785
774 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
775 "Disconnecting receiver for peer `%s'\n", 787 "Disconnecting receiver for peer `%s'\n",
776 GNUNET_i2s(&receiver->target)); 788 GNUNET_i2s (&receiver->target));
777 if (NULL != (mq = receiver->mq)) 789 if (NULL != (mq = receiver->mq))
778 { 790 {
779 receiver->mq = NULL; 791 receiver->mq = NULL;
780 GNUNET_MQ_destroy(mq); 792 GNUNET_MQ_destroy (mq);
781 } 793 }
782 if (NULL != receiver->qh) 794 if (NULL != receiver->qh)
783 { 795 {
784 GNUNET_TRANSPORT_communicator_mq_del(receiver->qh); 796 GNUNET_TRANSPORT_communicator_mq_del (receiver->qh);
785 receiver->qh = NULL; 797 receiver->qh = NULL;
786 } 798 }
787 GNUNET_assert(GNUNET_YES == 799 GNUNET_assert (GNUNET_YES ==
788 GNUNET_CONTAINER_multipeermap_remove(receivers, 800 GNUNET_CONTAINER_multipeermap_remove (receivers,
789 &receiver->target, 801 &receiver->target,
790 receiver)); 802 receiver));
791 GNUNET_assert(receiver == GNUNET_CONTAINER_heap_remove_node(receiver->hn)); 803 GNUNET_assert (receiver == GNUNET_CONTAINER_heap_remove_node (receiver->hn));
792 GNUNET_STATISTICS_set(stats, 804 GNUNET_STATISTICS_set (stats,
793 "# receivers active", 805 "# receivers active",
794 GNUNET_CONTAINER_multipeermap_size(receivers), 806 GNUNET_CONTAINER_multipeermap_size (receivers),
795 GNUNET_NO); 807 GNUNET_NO);
796 GNUNET_free(receiver->address); 808 GNUNET_free (receiver->address);
797 GNUNET_free(receiver->foreign_addr); 809 GNUNET_free (receiver->foreign_addr);
798 GNUNET_free(receiver); 810 GNUNET_free (receiver);
799} 811}
800 812
801 813
@@ -805,16 +817,16 @@ receiver_destroy(struct ReceiverAddress *receiver)
805 * @param kce the key cache entry 817 * @param kce the key cache entry
806 */ 818 */
807static void 819static void
808kce_destroy(struct KeyCacheEntry *kce) 820kce_destroy (struct KeyCacheEntry *kce)
809{ 821{
810 struct SharedSecret *ss = kce->ss; 822 struct SharedSecret *ss = kce->ss;
811 823
812 ss->active_kce_count--; 824 ss->active_kce_count--;
813 GNUNET_CONTAINER_DLL_remove(ss->kce_head, ss->kce_tail, kce); 825 GNUNET_CONTAINER_DLL_remove (ss->kce_head, ss->kce_tail, kce);
814 GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove(key_cache, 826 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (key_cache,
815 &kce->kid, 827 &kce->kid,
816 kce)); 828 kce));
817 GNUNET_free(kce); 829 GNUNET_free (kce);
818} 830}
819 831
820 832
@@ -826,24 +838,24 @@ kce_destroy(struct KeyCacheEntry *kce)
826 * @param kid[out] where to write the key ID 838 * @param kid[out] where to write the key ID
827 */ 839 */
828static void 840static void
829get_kid(const struct GNUNET_HashCode *msec, 841get_kid (const struct GNUNET_HashCode *msec,
830 uint32_t serial, 842 uint32_t serial,
831 struct GNUNET_ShortHashCode *kid) 843 struct GNUNET_ShortHashCode *kid)
832{ 844{
833 uint32_t sid = htonl(serial); 845 uint32_t sid = htonl (serial);
834 846
835 GNUNET_CRYPTO_hkdf(kid, 847 GNUNET_CRYPTO_hkdf (kid,
836 sizeof(*kid), 848 sizeof(*kid),
837 GCRY_MD_SHA512, 849 GCRY_MD_SHA512,
838 GCRY_MD_SHA256, 850 GCRY_MD_SHA256,
839 &sid, 851 &sid,
840 sizeof(sid), 852 sizeof(sid),
841 msec, 853 msec,
842 sizeof(*msec), 854 sizeof(*msec),
843 "UDP-KID", 855 "UDP-KID",
844 strlen("UDP-KID"), 856 strlen ("UDP-KID"),
845 NULL, 857 NULL,
846 0); 858 0);
847} 859}
848 860
849 861
@@ -854,26 +866,26 @@ get_kid(const struct GNUNET_HashCode *msec,
854 * @param seq sequence number for the key cache entry 866 * @param seq sequence number for the key cache entry
855 */ 867 */
856static void 868static void
857kce_generate(struct SharedSecret *ss, uint32_t seq) 869kce_generate (struct SharedSecret *ss, uint32_t seq)
858{ 870{
859 struct KeyCacheEntry *kce; 871 struct KeyCacheEntry *kce;
860 872
861 GNUNET_assert(0 < seq); 873 GNUNET_assert (0 < seq);
862 kce = GNUNET_new(struct KeyCacheEntry); 874 kce = GNUNET_new (struct KeyCacheEntry);
863 kce->ss = ss; 875 kce->ss = ss;
864 kce->sequence_number = seq; 876 kce->sequence_number = seq;
865 get_kid(&ss->master, seq, &kce->kid); 877 get_kid (&ss->master, seq, &kce->kid);
866 GNUNET_CONTAINER_DLL_insert(ss->kce_head, ss->kce_tail, kce); 878 GNUNET_CONTAINER_DLL_insert (ss->kce_head, ss->kce_tail, kce);
867 ss->active_kce_count++; 879 ss->active_kce_count++;
868 (void)GNUNET_CONTAINER_multishortmap_put( 880 (void) GNUNET_CONTAINER_multishortmap_put (
869 key_cache, 881 key_cache,
870 &kce->kid, 882 &kce->kid,
871 kce, 883 kce,
872 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 884 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
873 GNUNET_STATISTICS_set(stats, 885 GNUNET_STATISTICS_set (stats,
874 "# KIDs active", 886 "# KIDs active",
875 GNUNET_CONTAINER_multishortmap_size(key_cache), 887 GNUNET_CONTAINER_multishortmap_size (key_cache),
876 GNUNET_NO); 888 GNUNET_NO);
877} 889}
878 890
879 891
@@ -883,31 +895,31 @@ kce_generate(struct SharedSecret *ss, uint32_t seq)
883 * @param ss shared secret to destroy 895 * @param ss shared secret to destroy
884 */ 896 */
885static void 897static void
886secret_destroy(struct SharedSecret *ss) 898secret_destroy (struct SharedSecret *ss)
887{ 899{
888 struct SenderAddress *sender; 900 struct SenderAddress *sender;
889 struct ReceiverAddress *receiver; 901 struct ReceiverAddress *receiver;
890 struct KeyCacheEntry *kce; 902 struct KeyCacheEntry *kce;
891 903
892 if (NULL != (sender = ss->sender)) 904 if (NULL != (sender = ss->sender))
893 { 905 {
894 GNUNET_CONTAINER_DLL_remove(sender->ss_head, sender->ss_tail, ss); 906 GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss);
895 sender->num_secrets--; 907 sender->num_secrets--;
896 } 908 }
897 if (NULL != (receiver = ss->receiver)) 909 if (NULL != (receiver = ss->receiver))
898 { 910 {
899 GNUNET_CONTAINER_DLL_remove(receiver->ss_head, receiver->ss_tail, ss); 911 GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
900 receiver->num_secrets--; 912 receiver->num_secrets--;
901 receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used); 913 receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used);
902 } 914 }
903 while (NULL != (kce = ss->kce_head)) 915 while (NULL != (kce = ss->kce_head))
904 kce_destroy(kce); 916 kce_destroy (kce);
905 GNUNET_STATISTICS_update(stats, "# Secrets active", -1, GNUNET_NO); 917 GNUNET_STATISTICS_update (stats, "# Secrets active", -1, GNUNET_NO);
906 GNUNET_STATISTICS_set(stats, 918 GNUNET_STATISTICS_set (stats,
907 "# KIDs active", 919 "# KIDs active",
908 GNUNET_CONTAINER_multishortmap_size(key_cache), 920 GNUNET_CONTAINER_multishortmap_size (key_cache),
909 GNUNET_NO); 921 GNUNET_NO);
910 GNUNET_free(ss); 922 GNUNET_free (ss);
911} 923}
912 924
913 925
@@ -918,18 +930,18 @@ secret_destroy(struct SharedSecret *ss)
918 * @param sender entity to close down 930 * @param sender entity to close down
919 */ 931 */
920static void 932static void
921sender_destroy(struct SenderAddress *sender) 933sender_destroy (struct SenderAddress *sender)
922{ 934{
923 GNUNET_assert( 935 GNUNET_assert (
924 GNUNET_YES == 936 GNUNET_YES ==
925 GNUNET_CONTAINER_multipeermap_remove(senders, &sender->target, sender)); 937 GNUNET_CONTAINER_multipeermap_remove (senders, &sender->target, sender));
926 GNUNET_assert(sender == GNUNET_CONTAINER_heap_remove_node(sender->hn)); 938 GNUNET_assert (sender == GNUNET_CONTAINER_heap_remove_node (sender->hn));
927 GNUNET_STATISTICS_set(stats, 939 GNUNET_STATISTICS_set (stats,
928 "# senders active", 940 "# senders active",
929 GNUNET_CONTAINER_multipeermap_size(senders), 941 GNUNET_CONTAINER_multipeermap_size (senders),
930 GNUNET_NO); 942 GNUNET_NO);
931 GNUNET_free(sender->address); 943 GNUNET_free (sender->address);
932 GNUNET_free(sender); 944 GNUNET_free (sender);
933} 945}
934 946
935 947
@@ -942,28 +954,28 @@ sender_destroy(struct SenderAddress *sender)
942 * @param iv[out] where to write the IV 954 * @param iv[out] where to write the IV
943 */ 955 */
944static void 956static void
945get_iv_key(const struct GNUNET_HashCode *msec, 957get_iv_key (const struct GNUNET_HashCode *msec,
946 uint32_t serial, 958 uint32_t serial,
947 char key[AES_KEY_SIZE], 959 char key[AES_KEY_SIZE],
948 char iv[AES_IV_SIZE]) 960 char iv[AES_IV_SIZE])
949{ 961{
950 uint32_t sid = htonl(serial); 962 uint32_t sid = htonl (serial);
951 char res[AES_KEY_SIZE + AES_IV_SIZE]; 963 char res[AES_KEY_SIZE + AES_IV_SIZE];
952 964
953 GNUNET_CRYPTO_hkdf(res, 965 GNUNET_CRYPTO_hkdf (res,
954 sizeof(res), 966 sizeof(res),
955 GCRY_MD_SHA512, 967 GCRY_MD_SHA512,
956 GCRY_MD_SHA256, 968 GCRY_MD_SHA256,
957 &sid, 969 &sid,
958 sizeof(sid), 970 sizeof(sid),
959 msec, 971 msec,
960 sizeof(*msec), 972 sizeof(*msec),
961 "UDP-IV-KEY", 973 "UDP-IV-KEY",
962 strlen("UDP-IV-KEY"), 974 strlen ("UDP-IV-KEY"),
963 NULL, 975 NULL,
964 0); 976 0);
965 memcpy(key, res, AES_KEY_SIZE); 977 memcpy (key, res, AES_KEY_SIZE);
966 memcpy(iv, &res[AES_KEY_SIZE], AES_IV_SIZE); 978 memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE);
967} 979}
968 980
969 981
@@ -973,11 +985,11 @@ get_iv_key(const struct GNUNET_HashCode *msec,
973 * @param sender address for which the timeout should be rescheduled 985 * @param sender address for which the timeout should be rescheduled
974 */ 986 */
975static void 987static void
976reschedule_sender_timeout(struct SenderAddress *sender) 988reschedule_sender_timeout (struct SenderAddress *sender)
977{ 989{
978 sender->timeout = 990 sender->timeout =
979 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 991 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
980 GNUNET_CONTAINER_heap_update_cost(sender->hn, sender->timeout.abs_value_us); 992 GNUNET_CONTAINER_heap_update_cost (sender->hn, sender->timeout.abs_value_us);
981} 993}
982 994
983 995
@@ -987,12 +999,12 @@ reschedule_sender_timeout(struct SenderAddress *sender)
987 * @param receiver address for which the timeout should be rescheduled 999 * @param receiver address for which the timeout should be rescheduled
988 */ 1000 */
989static void 1001static void
990reschedule_receiver_timeout(struct ReceiverAddress *receiver) 1002reschedule_receiver_timeout (struct ReceiverAddress *receiver)
991{ 1003{
992 receiver->timeout = 1004 receiver->timeout =
993 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1005 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
994 GNUNET_CONTAINER_heap_update_cost(receiver->hn, 1006 GNUNET_CONTAINER_heap_update_cost (receiver->hn,
995 receiver->timeout.abs_value_us); 1007 receiver->timeout.abs_value_us);
996} 1008}
997 1009
998 1010
@@ -1002,7 +1014,7 @@ reschedule_receiver_timeout(struct ReceiverAddress *receiver)
1002 * @param cls unused, NULL 1014 * @param cls unused, NULL
1003 */ 1015 */
1004static void 1016static void
1005check_timeouts(void *cls) 1017check_timeouts (void *cls)
1006{ 1018{
1007 struct GNUNET_TIME_Relative st; 1019 struct GNUNET_TIME_Relative st;
1008 struct GNUNET_TIME_Relative rt; 1020 struct GNUNET_TIME_Relative rt;
@@ -1010,27 +1022,27 @@ check_timeouts(void *cls)
1010 struct ReceiverAddress *receiver; 1022 struct ReceiverAddress *receiver;
1011 struct SenderAddress *sender; 1023 struct SenderAddress *sender;
1012 1024
1013 (void)cls; 1025 (void) cls;
1014 timeout_task = NULL; 1026 timeout_task = NULL;
1015 rt = GNUNET_TIME_UNIT_FOREVER_REL; 1027 rt = GNUNET_TIME_UNIT_FOREVER_REL;
1016 while (NULL != (receiver = GNUNET_CONTAINER_heap_peek(receivers_heap))) 1028 while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap)))
1017 { 1029 {
1018 rt = GNUNET_TIME_absolute_get_remaining(receiver->timeout); 1030 rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout);
1019 if (0 != rt.rel_value_us) 1031 if (0 != rt.rel_value_us)
1020 break; 1032 break;
1021 receiver_destroy(receiver); 1033 receiver_destroy (receiver);
1022 } 1034 }
1023 st = GNUNET_TIME_UNIT_FOREVER_REL; 1035 st = GNUNET_TIME_UNIT_FOREVER_REL;
1024 while (NULL != (sender = GNUNET_CONTAINER_heap_peek(senders_heap))) 1036 while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap)))
1025 { 1037 {
1026 st = GNUNET_TIME_absolute_get_remaining(sender->timeout); 1038 st = GNUNET_TIME_absolute_get_remaining (sender->timeout);
1027 if (0 != st.rel_value_us) 1039 if (0 != st.rel_value_us)
1028 break; 1040 break;
1029 sender_destroy(sender); 1041 sender_destroy (sender);
1030 } 1042 }
1031 delay = GNUNET_TIME_relative_min(rt, st); 1043 delay = GNUNET_TIME_relative_min (rt, st);
1032 if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) 1044 if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
1033 timeout_task = GNUNET_SCHEDULER_add_delayed(delay, &check_timeouts, NULL); 1045 timeout_task = GNUNET_SCHEDULER_add_delayed (delay, &check_timeouts, NULL);
1034} 1046}
1035 1047
1036 1048
@@ -1040,20 +1052,20 @@ check_timeouts(void *cls)
1040 * @param ss[in,out] data structure to complete 1052 * @param ss[in,out] data structure to complete
1041 */ 1053 */
1042static void 1054static void
1043calculate_cmac(struct SharedSecret *ss) 1055calculate_cmac (struct SharedSecret *ss)
1044{ 1056{
1045 GNUNET_CRYPTO_hkdf(&ss->cmac, 1057 GNUNET_CRYPTO_hkdf (&ss->cmac,
1046 sizeof(ss->cmac), 1058 sizeof(ss->cmac),
1047 GCRY_MD_SHA512, 1059 GCRY_MD_SHA512,
1048 GCRY_MD_SHA256, 1060 GCRY_MD_SHA256,
1049 "CMAC", 1061 "CMAC",
1050 strlen("CMAC"), 1062 strlen ("CMAC"),
1051 &ss->master, 1063 &ss->master,
1052 sizeof(ss->master), 1064 sizeof(ss->master),
1053 "UDP-CMAC", 1065 "UDP-CMAC",
1054 strlen("UDP-CMAC"), 1066 strlen ("UDP-CMAC"),
1055 NULL, 1067 NULL,
1056 0); 1068 0);
1057} 1069}
1058 1070
1059 1071
@@ -1066,36 +1078,36 @@ calculate_cmac(struct SharedSecret *ss)
1066 * @param plaintext_len number of bytes of plaintext received 1078 * @param plaintext_len number of bytes of plaintext received
1067 */ 1079 */
1068static void 1080static void
1069pass_plaintext_to_core(struct SenderAddress *sender, 1081pass_plaintext_to_core (struct SenderAddress *sender,
1070 const void *plaintext, 1082 const void *plaintext,
1071 size_t plaintext_len) 1083 size_t plaintext_len)
1072{ 1084{
1073 const struct GNUNET_MessageHeader *hdr = plaintext; 1085 const struct GNUNET_MessageHeader *hdr = plaintext;
1074 1086
1075 while (ntohs(hdr->size) < plaintext_len) 1087 while (ntohs (hdr->size) < plaintext_len)
1076 { 1088 {
1077 GNUNET_STATISTICS_update(stats, 1089 GNUNET_STATISTICS_update (stats,
1078 "# bytes given to core", 1090 "# bytes given to core",
1079 ntohs(hdr->size), 1091 ntohs (hdr->size),
1080 GNUNET_NO); 1092 GNUNET_NO);
1081 (void) 1093 (void)
1082 GNUNET_TRANSPORT_communicator_receive(ch, 1094 GNUNET_TRANSPORT_communicator_receive (ch,
1083 &sender->target, 1095 &sender->target,
1084 hdr, 1096 hdr,
1085 ADDRESS_VALIDITY_PERIOD, 1097 ADDRESS_VALIDITY_PERIOD,
1086 NULL /* no flow control possible */ 1098 NULL /* no flow control possible */
1087 , 1099 ,
1088 NULL); 1100 NULL);
1089 /* move on to next message, if any */ 1101 /* move on to next message, if any */
1090 plaintext_len -= ntohs(hdr->size); 1102 plaintext_len -= ntohs (hdr->size);
1091 if (plaintext_len < sizeof(*hdr)) 1103 if (plaintext_len < sizeof(*hdr))
1092 break; 1104 break;
1093 hdr = plaintext + ntohs(hdr->size); 1105 hdr = plaintext + ntohs (hdr->size);
1094 } 1106 }
1095 GNUNET_STATISTICS_update(stats, 1107 GNUNET_STATISTICS_update (stats,
1096 "# bytes padding discarded", 1108 "# bytes padding discarded",
1097 plaintext_len, 1109 plaintext_len,
1098 GNUNET_NO); 1110 GNUNET_NO);
1099} 1111}
1100 1112
1101 1113
@@ -1108,20 +1120,20 @@ pass_plaintext_to_core(struct SenderAddress *sender,
1108 * @param cipher[out] cipher to initialize 1120 * @param cipher[out] cipher to initialize
1109 */ 1121 */
1110static void 1122static void
1111setup_cipher(const struct GNUNET_HashCode *msec, 1123setup_cipher (const struct GNUNET_HashCode *msec,
1112 uint32_t serial, 1124 uint32_t serial,
1113 gcry_cipher_hd_t *cipher) 1125 gcry_cipher_hd_t *cipher)
1114{ 1126{
1115 char key[AES_KEY_SIZE]; 1127 char key[AES_KEY_SIZE];
1116 char iv[AES_IV_SIZE]; 1128 char iv[AES_IV_SIZE];
1117 1129
1118 gcry_cipher_open(cipher, 1130 gcry_cipher_open (cipher,
1119 GCRY_CIPHER_AES256 /* low level: go for speed */, 1131 GCRY_CIPHER_AES256 /* low level: go for speed */,
1120 GCRY_CIPHER_MODE_GCM, 1132 GCRY_CIPHER_MODE_GCM,
1121 0 /* flags */); 1133 0 /* flags */);
1122 get_iv_key(msec, serial, key, iv); 1134 get_iv_key (msec, serial, key, iv);
1123 gcry_cipher_setkey(*cipher, key, sizeof(key)); 1135 gcry_cipher_setkey (*cipher, key, sizeof(key));
1124 gcry_cipher_setiv(*cipher, iv, sizeof(iv)); 1136 gcry_cipher_setiv (*cipher, iv, sizeof(iv));
1125} 1137}
1126 1138
1127 1139
@@ -1138,29 +1150,29 @@ setup_cipher(const struct GNUNET_HashCode *msec,
1138 * @return #GNUNET_OK on success 1150 * @return #GNUNET_OK on success
1139 */ 1151 */
1140static int 1152static int
1141try_decrypt(const struct SharedSecret *ss, 1153try_decrypt (const struct SharedSecret *ss,
1142 const char tag[GCM_TAG_SIZE], 1154 const char tag[GCM_TAG_SIZE],
1143 uint32_t serial, 1155 uint32_t serial,
1144 const char *in_buf, 1156 const char *in_buf,
1145 size_t in_buf_size, 1157 size_t in_buf_size,
1146 char *out_buf) 1158 char *out_buf)
1147{ 1159{
1148 gcry_cipher_hd_t cipher; 1160 gcry_cipher_hd_t cipher;
1149 1161
1150 setup_cipher(&ss->master, serial, &cipher); 1162 setup_cipher (&ss->master, serial, &cipher);
1151 GNUNET_assert( 1163 GNUNET_assert (
1152 0 == 1164 0 ==
1153 gcry_cipher_decrypt(cipher, out_buf, in_buf_size, in_buf, in_buf_size)); 1165 gcry_cipher_decrypt (cipher, out_buf, in_buf_size, in_buf, in_buf_size));
1154 if (0 != gcry_cipher_checktag(cipher, tag, GCM_TAG_SIZE)) 1166 if (0 != gcry_cipher_checktag (cipher, tag, GCM_TAG_SIZE))
1155 { 1167 {
1156 gcry_cipher_close(cipher); 1168 gcry_cipher_close (cipher);
1157 GNUNET_STATISTICS_update(stats, 1169 GNUNET_STATISTICS_update (stats,
1158 "# AEAD authentication failures", 1170 "# AEAD authentication failures",
1159 1, 1171 1,
1160 GNUNET_NO); 1172 GNUNET_NO);
1161 return GNUNET_SYSERR; 1173 return GNUNET_SYSERR;
1162 } 1174 }
1163 gcry_cipher_close(cipher); 1175 gcry_cipher_close (cipher);
1164 return GNUNET_OK; 1176 return GNUNET_OK;
1165} 1177}
1166 1178
@@ -1172,12 +1184,12 @@ try_decrypt(const struct SharedSecret *ss,
1172 * @return new shared secret 1184 * @return new shared secret
1173 */ 1185 */
1174static struct SharedSecret * 1186static struct SharedSecret *
1175setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral) 1187setup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
1176{ 1188{
1177 struct SharedSecret *ss; 1189 struct SharedSecret *ss;
1178 1190
1179 ss = GNUNET_new(struct SharedSecret); 1191 ss = GNUNET_new (struct SharedSecret);
1180 GNUNET_CRYPTO_eddsa_ecdh(my_private_key, ephemeral, &ss->master); 1192 GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &ss->master);
1181 return ss; 1193 return ss;
1182} 1194}
1183 1195
@@ -1190,20 +1202,20 @@ setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
1190 * @return new shared secret 1202 * @return new shared secret
1191 */ 1203 */
1192static struct SharedSecret * 1204static struct SharedSecret *
1193setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, 1205setup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral,
1194 struct ReceiverAddress *receiver) 1206 struct ReceiverAddress *receiver)
1195{ 1207{
1196 struct SharedSecret *ss; 1208 struct SharedSecret *ss;
1197 1209
1198 ss = GNUNET_new(struct SharedSecret); 1210 ss = GNUNET_new (struct SharedSecret);
1199 GNUNET_CRYPTO_ecdh_eddsa(ephemeral, 1211 GNUNET_CRYPTO_ecdh_eddsa (ephemeral,
1200 &receiver->target.public_key, 1212 &receiver->target.public_key,
1201 &ss->master); 1213 &ss->master);
1202 calculate_cmac(ss); 1214 calculate_cmac (ss);
1203 ss->receiver = receiver; 1215 ss->receiver = receiver;
1204 GNUNET_CONTAINER_DLL_insert(receiver->ss_head, receiver->ss_tail, ss); 1216 GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1205 receiver->num_secrets++; 1217 receiver->num_secrets++;
1206 GNUNET_STATISTICS_update(stats, "# Secrets active", 1, GNUNET_NO); 1218 GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
1207 return ss; 1219 return ss;
1208} 1220}
1209 1221
@@ -1216,7 +1228,7 @@ setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral,
1216 * @param receiver receiver to setup MQ for 1228 * @param receiver receiver to setup MQ for
1217 */ 1229 */
1218static void 1230static void
1219setup_receiver_mq(struct ReceiverAddress *receiver); 1231setup_receiver_mq (struct ReceiverAddress *receiver);
1220 1232
1221 1233
1222/** 1234/**
@@ -1230,36 +1242,36 @@ setup_receiver_mq(struct ReceiverAddress *receiver);
1230 * @return #GNUNET_YES to continue to iterate 1242 * @return #GNUNET_YES to continue to iterate
1231 */ 1243 */
1232static int 1244static int
1233handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) 1245handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
1234{ 1246{
1235 const struct UDPAck *ack = cls; 1247 const struct UDPAck *ack = cls;
1236 struct ReceiverAddress *receiver = value; 1248 struct ReceiverAddress *receiver = value;
1237 1249
1238 (void)pid; 1250 (void) pid;
1239 for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next) 1251 for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next)
1252 {
1253 if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
1240 { 1254 {
1241 if (0 == memcmp(&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode))) 1255 uint32_t allowed;
1256
1257 allowed = ntohl (ack->sequence_max);
1258
1259 if (allowed > ss->sequence_allowed)
1260 {
1261 receiver->acks_available += (allowed - ss->sequence_allowed);
1262 if ((allowed - ss->sequence_allowed) == receiver->acks_available)
1242 { 1263 {
1243 uint32_t allowed; 1264 /* we just incremented from zero => MTU change! */
1244 1265 setup_receiver_mq (receiver);
1245 allowed = ntohl(ack->sequence_max);
1246
1247 if (allowed > ss->sequence_allowed)
1248 {
1249 receiver->acks_available += (allowed - ss->sequence_allowed);
1250 if ((allowed - ss->sequence_allowed) == receiver->acks_available)
1251 {
1252 /* we just incremented from zero => MTU change! */
1253 setup_receiver_mq(receiver);
1254 }
1255 ss->sequence_allowed = allowed;
1256 /* move ss to head to avoid discarding it anytime soon! */
1257 GNUNET_CONTAINER_DLL_remove(receiver->ss_head, receiver->ss_tail, ss);
1258 GNUNET_CONTAINER_DLL_insert(receiver->ss_head, receiver->ss_tail, ss);
1259 }
1260 return GNUNET_NO;
1261 } 1266 }
1267 ss->sequence_allowed = allowed;
1268 /* move ss to head to avoid discarding it anytime soon! */
1269 GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1270 GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1271 }
1272 return GNUNET_NO;
1262 } 1273 }
1274 }
1263 return GNUNET_YES; 1275 return GNUNET_YES;
1264} 1276}
1265 1277
@@ -1273,41 +1285,41 @@ handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
1273 * @param buf_size number of bytes in @a buf 1285 * @param buf_size number of bytes in @a buf
1274 */ 1286 */
1275static void 1287static void
1276try_handle_plaintext(struct SenderAddress *sender, 1288try_handle_plaintext (struct SenderAddress *sender,
1277 const void *buf, 1289 const void *buf,
1278 size_t buf_size) 1290 size_t buf_size)
1279{ 1291{
1280 const struct GNUNET_MessageHeader *hdr = 1292 const struct GNUNET_MessageHeader *hdr =
1281 (const struct GNUNET_MessageHeader *)buf; 1293 (const struct GNUNET_MessageHeader *) buf;
1282 const struct UDPAck *ack = (const struct UDPAck *)buf; 1294 const struct UDPAck *ack = (const struct UDPAck *) buf;
1283 uint16_t type; 1295 uint16_t type;
1284 1296
1285 if (sizeof(*hdr) > buf_size) 1297 if (sizeof(*hdr) > buf_size)
1286 return; /* not even a header */ 1298 return; /* not even a header */
1287 if (ntohs(hdr->size) > buf_size) 1299 if (ntohs (hdr->size) > buf_size)
1288 return; /* not even a header */ 1300 return; /* not even a header */
1289 type = ntohs(hdr->type); 1301 type = ntohs (hdr->type);
1290 switch (type) 1302 switch (type)
1291 { 1303 {
1292 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK: 1304 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK:
1293 /* lookup master secret by 'cmac', then update sequence_max */ 1305 /* lookup master secret by 'cmac', then update sequence_max */
1294 GNUNET_CONTAINER_multipeermap_get_multiple(receivers, 1306 GNUNET_CONTAINER_multipeermap_get_multiple (receivers,
1295 &sender->target, 1307 &sender->target,
1296 &handle_ack, 1308 &handle_ack,
1297 (void *)ack); 1309 (void *) ack);
1298 /* There could be more messages after the ACK, handle those as well */ 1310 /* There could be more messages after the ACK, handle those as well */
1299 buf += ntohs(hdr->size); 1311 buf += ntohs (hdr->size);
1300 buf_size -= ntohs(hdr->size); 1312 buf_size -= ntohs (hdr->size);
1301 pass_plaintext_to_core(sender, buf, buf_size); 1313 pass_plaintext_to_core (sender, buf, buf_size);
1302 break; 1314 break;
1303 1315
1304 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD: 1316 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD:
1305 /* skip padding */ 1317 /* skip padding */
1306 break; 1318 break;
1307 1319
1308 default: 1320 default:
1309 pass_plaintext_to_core(sender, buf, buf_size); 1321 pass_plaintext_to_core (sender, buf, buf_size);
1310 } 1322 }
1311} 1323}
1312 1324
1313 1325
@@ -1320,29 +1332,29 @@ try_handle_plaintext(struct SenderAddress *sender,
1320 * @param ss shared secret to generate ACKs for 1332 * @param ss shared secret to generate ACKs for
1321 */ 1333 */
1322static void 1334static void
1323consider_ss_ack(struct SharedSecret *ss) 1335consider_ss_ack (struct SharedSecret *ss)
1324{ 1336{
1325 GNUNET_assert(NULL != ss->sender); 1337 GNUNET_assert (NULL != ss->sender);
1326 /* drop ancient KeyCacheEntries */ 1338 /* drop ancient KeyCacheEntries */
1327 while ((NULL != ss->kce_head) && 1339 while ((NULL != ss->kce_head) &&
1328 (MAX_SQN_DELTA < 1340 (MAX_SQN_DELTA <
1329 ss->kce_head->sequence_number - ss->kce_tail->sequence_number)) 1341 ss->kce_head->sequence_number - ss->kce_tail->sequence_number))
1330 kce_destroy(ss->kce_tail); 1342 kce_destroy (ss->kce_tail);
1331 if (ss->active_kce_count < KCN_THRESHOLD) 1343 if (ss->active_kce_count < KCN_THRESHOLD)
1332 { 1344 {
1333 struct UDPAck ack; 1345 struct UDPAck ack;
1334 1346
1335 while (ss->active_kce_count < KCN_TARGET) 1347 while (ss->active_kce_count < KCN_TARGET)
1336 kce_generate(ss, ++ss->sequence_allowed); 1348 kce_generate (ss, ++ss->sequence_allowed);
1337 ack.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); 1349 ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK);
1338 ack.header.size = htons(sizeof(ack)); 1350 ack.header.size = htons (sizeof(ack));
1339 ack.sequence_max = htonl(ss->sequence_allowed); 1351 ack.sequence_max = htonl (ss->sequence_allowed);
1340 ack.cmac = ss->cmac; 1352 ack.cmac = ss->cmac;
1341 GNUNET_TRANSPORT_communicator_notify(ch, 1353 GNUNET_TRANSPORT_communicator_notify (ch,
1342 &ss->sender->target, 1354 &ss->sender->target,
1343 COMMUNICATOR_ADDRESS_PREFIX, 1355 COMMUNICATOR_ADDRESS_PREFIX,
1344 &ack.header); 1356 &ack.header);
1345 } 1357 }
1346} 1358}
1347 1359
1348 1360
@@ -1354,42 +1366,43 @@ consider_ss_ack(struct SharedSecret *ss)
1354 * @param kce key index to decrypt @a box 1366 * @param kce key index to decrypt @a box
1355 */ 1367 */
1356static void 1368static void
1357decrypt_box(const struct UDPBox *box, 1369decrypt_box (const struct UDPBox *box,
1358 size_t box_len, 1370 size_t box_len,
1359 struct KeyCacheEntry *kce) 1371 struct KeyCacheEntry *kce)
1360{ 1372{
1361 struct SharedSecret *ss = kce->ss; 1373 struct SharedSecret *ss = kce->ss;
1362 char out_buf[box_len - sizeof(*box)]; 1374 char out_buf[box_len - sizeof(*box)];
1363 1375
1364 GNUNET_assert(NULL != ss->sender); 1376 GNUNET_assert (NULL != ss->sender);
1365 if (GNUNET_OK != try_decrypt(ss, 1377 if (GNUNET_OK != try_decrypt (ss,
1366 box->gcm_tag, 1378 box->gcm_tag,
1367 kce->sequence_number, 1379 kce->sequence_number,
1368 (const char *)&box[1], 1380 (const char *) &box[1],
1369 sizeof(out_buf), 1381 sizeof(out_buf),
1370 out_buf)) 1382 out_buf))
1371 { 1383 {
1372 GNUNET_STATISTICS_update(stats, 1384 GNUNET_STATISTICS_update (stats,
1373 "# Decryption failures with valid KCE", 1385 "# Decryption failures with valid KCE",
1374 1, 1386 1,
1375 GNUNET_NO); 1387 GNUNET_NO);
1376 kce_destroy(kce); 1388 kce_destroy (kce);
1377 return; 1389 return;
1378 } 1390 }
1379 kce_destroy(kce); 1391 kce_destroy (kce);
1380 GNUNET_STATISTICS_update(stats, 1392 GNUNET_STATISTICS_update (stats,
1381 "# bytes decrypted with BOX", 1393 "# bytes decrypted with BOX",
1382 sizeof(out_buf), 1394 sizeof(out_buf),
1383 GNUNET_NO); 1395 GNUNET_NO);
1384 try_handle_plaintext(ss->sender, out_buf, sizeof(out_buf)); 1396 try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf));
1385 consider_ss_ack(ss); 1397 consider_ss_ack (ss);
1386} 1398}
1387 1399
1388 1400
1389/** 1401/**
1390 * Closure for #find_sender_by_address() 1402 * Closure for #find_sender_by_address()
1391 */ 1403 */
1392struct SearchContext { 1404struct SearchContext
1405{
1393 /** 1406 /**
1394 * Address we are looking for. 1407 * Address we are looking for.
1395 */ 1408 */
@@ -1416,19 +1429,19 @@ struct SearchContext {
1416 * @return #GNUNET_YES if not found (continue to search), #GNUNET_NO if found 1429 * @return #GNUNET_YES if not found (continue to search), #GNUNET_NO if found
1417 */ 1430 */
1418static int 1431static int
1419find_sender_by_address(void *cls, 1432find_sender_by_address (void *cls,
1420 const struct GNUNET_PeerIdentity *key, 1433 const struct GNUNET_PeerIdentity *key,
1421 void *value) 1434 void *value)
1422{ 1435{
1423 struct SearchContext *sc = cls; 1436 struct SearchContext *sc = cls;
1424 struct SenderAddress *sender = value; 1437 struct SenderAddress *sender = value;
1425 1438
1426 if ((sender->address_len == sc->address_len) && 1439 if ((sender->address_len == sc->address_len) &&
1427 (0 == memcmp(sender->address, sc->address, sender->address_len))) 1440 (0 == memcmp (sender->address, sc->address, sender->address_len)))
1428 { 1441 {
1429 sc->sender = sender; 1442 sc->sender = sender;
1430 return GNUNET_NO; /* stop iterating! */ 1443 return GNUNET_NO; /* stop iterating! */
1431 } 1444 }
1432 return GNUNET_YES; 1445 return GNUNET_YES;
1433} 1446}
1434 1447
@@ -1445,45 +1458,45 @@ find_sender_by_address(void *cls,
1445 * decrypting data from @a target 1458 * decrypting data from @a target
1446 */ 1459 */
1447static struct SenderAddress * 1460static struct SenderAddress *
1448setup_sender(const struct GNUNET_PeerIdentity *target, 1461setup_sender (const struct GNUNET_PeerIdentity *target,
1449 const struct sockaddr *address, 1462 const struct sockaddr *address,
1450 socklen_t address_len) 1463 socklen_t address_len)
1451{ 1464{
1452 struct SenderAddress *sender; 1465 struct SenderAddress *sender;
1453 struct SearchContext sc = { .address = address, 1466 struct SearchContext sc = { .address = address,
1454 .address_len = address_len, 1467 .address_len = address_len,
1455 .sender = NULL }; 1468 .sender = NULL };
1456 1469
1457 GNUNET_CONTAINER_multipeermap_get_multiple(senders, 1470 GNUNET_CONTAINER_multipeermap_get_multiple (senders,
1458 target, 1471 target,
1459 &find_sender_by_address, 1472 &find_sender_by_address,
1460 &sc); 1473 &sc);
1461 if (NULL != sc.sender) 1474 if (NULL != sc.sender)
1462 { 1475 {
1463 reschedule_sender_timeout(sc.sender); 1476 reschedule_sender_timeout (sc.sender);
1464 return sc.sender; 1477 return sc.sender;
1465 } 1478 }
1466 sender = GNUNET_new(struct SenderAddress); 1479 sender = GNUNET_new (struct SenderAddress);
1467 sender->target = *target; 1480 sender->target = *target;
1468 sender->address = GNUNET_memdup(address, address_len); 1481 sender->address = GNUNET_memdup (address, address_len);
1469 sender->address_len = address_len; 1482 sender->address_len = address_len;
1470 (void)GNUNET_CONTAINER_multipeermap_put( 1483 (void) GNUNET_CONTAINER_multipeermap_put (
1471 senders, 1484 senders,
1472 &sender->target, 1485 &sender->target,
1473 sender, 1486 sender,
1474 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1487 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1475 GNUNET_STATISTICS_set(stats, 1488 GNUNET_STATISTICS_set (stats,
1476 "# senders active", 1489 "# senders active",
1477 GNUNET_CONTAINER_multipeermap_size(receivers), 1490 GNUNET_CONTAINER_multipeermap_size (receivers),
1478 GNUNET_NO); 1491 GNUNET_NO);
1479 sender->timeout = 1492 sender->timeout =
1480 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1493 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1481 sender->hn = GNUNET_CONTAINER_heap_insert(senders_heap, 1494 sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap,
1482 sender, 1495 sender,
1483 sender->timeout.abs_value_us); 1496 sender->timeout.abs_value_us);
1484 sender->nt = GNUNET_NT_scanner_get_type(is, address, address_len); 1497 sender->nt = GNUNET_NT_scanner_get_type (is, address, address_len);
1485 if (NULL == timeout_task) 1498 if (NULL == timeout_task)
1486 timeout_task = GNUNET_SCHEDULER_add_now(&check_timeouts, NULL); 1499 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
1487 return sender; 1500 return sender;
1488} 1501}
1489 1502
@@ -1496,21 +1509,22 @@ setup_sender(const struct GNUNET_PeerIdentity *target,
1496 * @return #GNUNET_OK if signature is valid 1509 * @return #GNUNET_OK if signature is valid
1497 */ 1510 */
1498static int 1511static int
1499verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, 1512verify_confirmation (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
1500 const struct UDPConfirmation *uc) 1513 const struct UDPConfirmation *uc)
1501{ 1514{
1502 struct UdpHandshakeSignature uhs; 1515 struct UdpHandshakeSignature uhs;
1503 1516
1504 uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); 1517 uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
1505 uhs.purpose.size = htonl(sizeof(uhs)); 1518 uhs.purpose.size = htonl (sizeof(uhs));
1506 uhs.sender = uc->sender; 1519 uhs.sender = uc->sender;
1507 uhs.receiver = my_identity; 1520 uhs.receiver = my_identity;
1508 uhs.ephemeral = *ephemeral; 1521 uhs.ephemeral = *ephemeral;
1509 uhs.monotonic_time = uc->monotonic_time; 1522 uhs.monotonic_time = uc->monotonic_time;
1510 return GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, 1523 return GNUNET_CRYPTO_eddsa_verify (
1511 &uhs.purpose, 1524 GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE,
1512 &uc->sender_sig, 1525 &uhs.purpose,
1513 &uc->sender.public_key); 1526 &uc->sender_sig,
1527 &uc->sender.public_key);
1514} 1528}
1515 1529
1516 1530
@@ -1523,30 +1537,30 @@ verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
1523 * @return string representation of @a address 1537 * @return string representation of @a address
1524 */ 1538 */
1525static char * 1539static char *
1526sockaddr_to_udpaddr_string(const struct sockaddr *address, 1540sockaddr_to_udpaddr_string (const struct sockaddr *address,
1527 socklen_t address_len) 1541 socklen_t address_len)
1528{ 1542{
1529 char *ret; 1543 char *ret;
1530 1544
1531 switch (address->sa_family) 1545 switch (address->sa_family)
1532 { 1546 {
1533 case AF_INET: 1547 case AF_INET:
1534 GNUNET_asprintf(&ret, 1548 GNUNET_asprintf (&ret,
1535 "%s-%s", 1549 "%s-%s",
1536 COMMUNICATOR_ADDRESS_PREFIX, 1550 COMMUNICATOR_ADDRESS_PREFIX,
1537 GNUNET_a2s(address, address_len)); 1551 GNUNET_a2s (address, address_len));
1538 break; 1552 break;
1539 1553
1540 case AF_INET6: 1554 case AF_INET6:
1541 GNUNET_asprintf(&ret, 1555 GNUNET_asprintf (&ret,
1542 "%s-%s", 1556 "%s-%s",
1543 COMMUNICATOR_ADDRESS_PREFIX, 1557 COMMUNICATOR_ADDRESS_PREFIX,
1544 GNUNET_a2s(address, address_len)); 1558 GNUNET_a2s (address, address_len));
1545 break; 1559 break;
1546 1560
1547 default: 1561 default:
1548 GNUNET_assert(0); 1562 GNUNET_assert (0);
1549 } 1563 }
1550 return ret; 1564 return ret;
1551} 1565}
1552 1566
@@ -1557,87 +1571,87 @@ sockaddr_to_udpaddr_string(const struct sockaddr *address,
1557 * @param cls NULL 1571 * @param cls NULL
1558 */ 1572 */
1559static void 1573static void
1560sock_read(void *cls) 1574sock_read (void *cls)
1561{ 1575{
1562 struct sockaddr_storage sa; 1576 struct sockaddr_storage sa;
1563 socklen_t salen = sizeof(sa); 1577 socklen_t salen = sizeof(sa);
1564 char buf[UINT16_MAX]; 1578 char buf[UINT16_MAX];
1565 ssize_t rcvd; 1579 ssize_t rcvd;
1566 1580
1567 (void)cls; 1581 (void) cls;
1568 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 1582 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1569 udp_sock, 1583 udp_sock,
1570 &sock_read, 1584 &sock_read,
1571 NULL); 1585 NULL);
1572 rcvd = GNUNET_NETWORK_socket_recvfrom(udp_sock, 1586 rcvd = GNUNET_NETWORK_socket_recvfrom (udp_sock,
1573 buf, 1587 buf,
1574 sizeof(buf), 1588 sizeof(buf),
1575 (struct sockaddr *)&sa, 1589 (struct sockaddr *) &sa,
1576 &salen); 1590 &salen);
1577 if (-1 == rcvd) 1591 if (-1 == rcvd)
1578 { 1592 {
1579 GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv"); 1593 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
1580 return; 1594 return;
1581 } 1595 }
1582 1596
1583 /* first, see if it is a UDPBox */ 1597 /* first, see if it is a UDPBox */
1584 if (rcvd > sizeof(struct UDPBox)) 1598 if (rcvd > sizeof(struct UDPBox))
1585 { 1599 {
1586 const struct UDPBox *box; 1600 const struct UDPBox *box;
1587 struct KeyCacheEntry *kce; 1601 struct KeyCacheEntry *kce;
1588 1602
1589 box = (const struct UDPBox *)buf; 1603 box = (const struct UDPBox *) buf;
1590 kce = GNUNET_CONTAINER_multishortmap_get(key_cache, &box->kid); 1604 kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &box->kid);
1591 if (NULL != kce) 1605 if (NULL != kce)
1592 { 1606 {
1593 decrypt_box(box, (size_t)rcvd, kce); 1607 decrypt_box (box, (size_t) rcvd, kce);
1594 return; 1608 return;
1595 }
1596 } 1609 }
1610 }
1597 1611
1598 /* next, check if it is a broadcast */ 1612 /* next, check if it is a broadcast */
1599 if (sizeof(struct UDPBroadcast) == rcvd) 1613 if (sizeof(struct UDPBroadcast) == rcvd)
1614 {
1615 const struct UDPBroadcast *ub;
1616 struct UdpBroadcastSignature uhs;
1617
1618 ub = (const struct UDPBroadcast *) buf;
1619 uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
1620 uhs.purpose.size = htonl (sizeof(uhs));
1621 uhs.sender = ub->sender;
1622 GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address);
1623 if (GNUNET_OK ==
1624 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST,
1625 &uhs.purpose,
1626 &ub->sender_sig,
1627 &ub->sender.public_key))
1600 { 1628 {
1601 const struct UDPBroadcast *ub; 1629 char *addr_s;
1602 struct UdpBroadcastSignature uhs; 1630 enum GNUNET_NetworkType nt;
1603 1631
1604 ub = (const struct UDPBroadcast *)buf; 1632 addr_s =
1605 uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); 1633 sockaddr_to_udpaddr_string ((const struct sockaddr *) &sa, salen);
1606 uhs.purpose.size = htonl(sizeof(uhs)); 1634 GNUNET_STATISTICS_update (stats, "# broadcasts received", 1, GNUNET_NO);
1607 uhs.sender = ub->sender; 1635 /* use our own mechanism to determine network type */
1608 GNUNET_CRYPTO_hash(&sa, salen, &uhs.h_address); 1636 nt =
1609 if (GNUNET_OK == 1637 GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen);
1610 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST, 1638 GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s);
1611 &uhs.purpose, 1639 GNUNET_free (addr_s);
1612 &ub->sender_sig, 1640 return;
1613 &ub->sender.public_key))
1614 {
1615 char *addr_s;
1616 enum GNUNET_NetworkType nt;
1617
1618 addr_s =
1619 sockaddr_to_udpaddr_string((const struct sockaddr *)&sa, salen);
1620 GNUNET_STATISTICS_update(stats, "# broadcasts received", 1, GNUNET_NO);
1621 /* use our own mechanism to determine network type */
1622 nt =
1623 GNUNET_NT_scanner_get_type(is, (const struct sockaddr *)&sa, salen);
1624 GNUNET_TRANSPORT_application_validate(ah, &ub->sender, nt, addr_s);
1625 GNUNET_free(addr_s);
1626 return;
1627 }
1628 /* continue with KX, mostly for statistics... */
1629 } 1641 }
1642 /* continue with KX, mostly for statistics... */
1643 }
1630 1644
1631 1645
1632 /* finally, test if it is a KX */ 1646 /* finally, test if it is a KX */
1633 if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX)) 1647 if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX))
1634 { 1648 {
1635 GNUNET_STATISTICS_update(stats, 1649 GNUNET_STATISTICS_update (stats,
1636 "# messages dropped (no kid, too small for KX)", 1650 "# messages dropped (no kid, too small for KX)",
1637 1, 1651 1,
1638 GNUNET_NO); 1652 GNUNET_NO);
1639 return; 1653 return;
1640 } 1654 }
1641 1655
1642 { 1656 {
1643 const struct InitialKX *kx; 1657 const struct InitialKX *kx;
@@ -1646,48 +1660,48 @@ sock_read(void *cls)
1646 const struct UDPConfirmation *uc; 1660 const struct UDPConfirmation *uc;
1647 struct SenderAddress *sender; 1661 struct SenderAddress *sender;
1648 1662
1649 kx = (const struct InitialKX *)buf; 1663 kx = (const struct InitialKX *) buf;
1650 ss = setup_shared_secret_dec(&kx->ephemeral); 1664 ss = setup_shared_secret_dec (&kx->ephemeral);
1651 if (GNUNET_OK != try_decrypt(ss, 1665 if (GNUNET_OK != try_decrypt (ss,
1652 kx->gcm_tag, 1666 kx->gcm_tag,
1653 0, 1667 0,
1654 &buf[sizeof(*kx)], 1668 &buf[sizeof(*kx)],
1655 sizeof(pbuf), 1669 sizeof(pbuf),
1656 pbuf)) 1670 pbuf))
1657 { 1671 {
1658 GNUNET_free(ss); 1672 GNUNET_free (ss);
1659 GNUNET_STATISTICS_update( 1673 GNUNET_STATISTICS_update (
1660 stats, 1674 stats,
1661 "# messages dropped (no kid, AEAD decryption failed)", 1675 "# messages dropped (no kid, AEAD decryption failed)",
1662 1, 1676 1,
1663 GNUNET_NO); 1677 GNUNET_NO);
1664 return; 1678 return;
1665 } 1679 }
1666 uc = (const struct UDPConfirmation *)pbuf; 1680 uc = (const struct UDPConfirmation *) pbuf;
1667 if (GNUNET_OK != verify_confirmation(&kx->ephemeral, uc)) 1681 if (GNUNET_OK != verify_confirmation (&kx->ephemeral, uc))
1668 { 1682 {
1669 GNUNET_break_op(0); 1683 GNUNET_break_op (0);
1670 GNUNET_free(ss); 1684 GNUNET_free (ss);
1671 GNUNET_STATISTICS_update(stats, 1685 GNUNET_STATISTICS_update (stats,
1672 "# messages dropped (sender signature invalid)", 1686 "# messages dropped (sender signature invalid)",
1673 1, 1687 1,
1674 GNUNET_NO); 1688 GNUNET_NO);
1675 return; 1689 return;
1676 } 1690 }
1677 calculate_cmac(ss); 1691 calculate_cmac (ss);
1678 sender = setup_sender(&uc->sender, (const struct sockaddr *)&sa, salen); 1692 sender = setup_sender (&uc->sender, (const struct sockaddr *) &sa, salen);
1679 ss->sender = sender; 1693 ss->sender = sender;
1680 GNUNET_CONTAINER_DLL_insert(sender->ss_head, sender->ss_tail, ss); 1694 GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss);
1681 sender->num_secrets++; 1695 sender->num_secrets++;
1682 GNUNET_STATISTICS_update(stats, "# Secrets active", 1, GNUNET_NO); 1696 GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
1683 GNUNET_STATISTICS_update(stats, 1697 GNUNET_STATISTICS_update (stats,
1684 "# messages decrypted without BOX", 1698 "# messages decrypted without BOX",
1685 1, 1699 1,
1686 GNUNET_NO); 1700 GNUNET_NO);
1687 try_handle_plaintext(sender, &uc[1], sizeof(pbuf) - sizeof(*uc)); 1701 try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc));
1688 consider_ss_ack(ss); 1702 consider_ss_ack (ss);
1689 if (sender->num_secrets > MAX_SECRETS) 1703 if (sender->num_secrets > MAX_SECRETS)
1690 secret_destroy(sender->ss_tail); 1704 secret_destroy (sender->ss_tail);
1691 } 1705 }
1692} 1706}
1693 1707
@@ -1700,7 +1714,7 @@ sock_read(void *cls)
1700 * @return converted bindto specification 1714 * @return converted bindto specification
1701 */ 1715 */
1702static struct sockaddr * 1716static struct sockaddr *
1703udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) 1717udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1704{ 1718{
1705 struct sockaddr *in; 1719 struct sockaddr *in;
1706 unsigned int port; 1720 unsigned int port;
@@ -1708,88 +1722,88 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
1708 char *colon; 1722 char *colon;
1709 char *cp; 1723 char *cp;
1710 1724
1711 if (1 == sscanf(bindto, "%u%1s", &port, dummy)) 1725 if (1 == sscanf (bindto, "%u%1s", &port, dummy))
1726 {
1727 /* interpreting value as just a PORT number */
1728 if (port > UINT16_MAX)
1712 { 1729 {
1713 /* interpreting value as just a PORT number */ 1730 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1714 if (port > UINT16_MAX) 1731 "BINDTO specification `%s' invalid: value too large for port\n",
1715 { 1732 bindto);
1716 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1733 return NULL;
1717 "BINDTO specification `%s' invalid: value too large for port\n", 1734 }
1718 bindto); 1735 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1719 return NULL; 1736 (GNUNET_YES ==
1720 } 1737 GNUNET_CONFIGURATION_get_value_yesno (cfg,
1721 if ((GNUNET_NO == GNUNET_NETWORK_test_pf(PF_INET6)) || 1738 COMMUNICATOR_CONFIG_SECTION,
1722 (GNUNET_YES == 1739 "DISABLE_V6")))
1723 GNUNET_CONFIGURATION_get_value_yesno(cfg, 1740 {
1724 COMMUNICATOR_CONFIG_SECTION, 1741 struct sockaddr_in *i4;
1725 "DISABLE_V6")))
1726 {
1727 struct sockaddr_in *i4;
1728 1742
1729 i4 = GNUNET_malloc(sizeof(struct sockaddr_in)); 1743 i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
1730 i4->sin_family = AF_INET; 1744 i4->sin_family = AF_INET;
1731 i4->sin_port = htons((uint16_t)port); 1745 i4->sin_port = htons ((uint16_t) port);
1732 *sock_len = sizeof(struct sockaddr_in); 1746 *sock_len = sizeof(struct sockaddr_in);
1733 in = (struct sockaddr *)i4; 1747 in = (struct sockaddr *) i4;
1734 } 1748 }
1735 else 1749 else
1736 { 1750 {
1737 struct sockaddr_in6 *i6; 1751 struct sockaddr_in6 *i6;
1738 1752
1739 i6 = GNUNET_malloc(sizeof(struct sockaddr_in6)); 1753 i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
1740 i6->sin6_family = AF_INET6; 1754 i6->sin6_family = AF_INET6;
1741 i6->sin6_port = htons((uint16_t)port); 1755 i6->sin6_port = htons ((uint16_t) port);
1742 *sock_len = sizeof(struct sockaddr_in6); 1756 *sock_len = sizeof(struct sockaddr_in6);
1743 in = (struct sockaddr *)i6; 1757 in = (struct sockaddr *) i6;
1744 }
1745 return in;
1746 } 1758 }
1747 cp = GNUNET_strdup(bindto); 1759 return in;
1748 colon = strrchr(cp, ':'); 1760 }
1761 cp = GNUNET_strdup (bindto);
1762 colon = strrchr (cp, ':');
1749 if (NULL != colon) 1763 if (NULL != colon)
1764 {
1765 /* interpet value after colon as port */
1766 *colon = '\0';
1767 colon++;
1768 if (1 == sscanf (colon, "%u%1s", &port, dummy))
1750 { 1769 {
1751 /* interpet value after colon as port */ 1770 /* interpreting value as just a PORT number */
1752 *colon = '\0'; 1771 if (port > UINT16_MAX)
1753 colon++; 1772 {
1754 if (1 == sscanf(colon, "%u%1s", &port, dummy)) 1773 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1755 { 1774 "BINDTO specification `%s' invalid: value too large for port\n",
1756 /* interpreting value as just a PORT number */ 1775 bindto);
1757 if (port > UINT16_MAX) 1776 GNUNET_free (cp);
1758 { 1777 return NULL;
1759 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1778 }
1760 "BINDTO specification `%s' invalid: value too large for port\n",
1761 bindto);
1762 GNUNET_free(cp);
1763 return NULL;
1764 }
1765 }
1766 else
1767 {
1768 GNUNET_log(
1769 GNUNET_ERROR_TYPE_ERROR,
1770 "BINDTO specification `%s' invalid: last ':' not followed by number\n",
1771 bindto);
1772 GNUNET_free(cp);
1773 return NULL;
1774 }
1775 } 1779 }
1776 else 1780 else
1777 { 1781 {
1778 /* interpret missing port as 0, aka pick any free one */ 1782 GNUNET_log (
1779 port = 0; 1783 GNUNET_ERROR_TYPE_ERROR,
1784 "BINDTO specification `%s' invalid: last ':' not followed by number\n",
1785 bindto);
1786 GNUNET_free (cp);
1787 return NULL;
1780 } 1788 }
1789 }
1790 else
1791 {
1792 /* interpret missing port as 0, aka pick any free one */
1793 port = 0;
1794 }
1781 { 1795 {
1782 /* try IPv4 */ 1796 /* try IPv4 */
1783 struct sockaddr_in v4; 1797 struct sockaddr_in v4;
1784 1798
1785 if (1 == inet_pton(AF_INET, cp, &v4)) 1799 if (1 == inet_pton (AF_INET, cp, &v4))
1786 { 1800 {
1787 v4.sin_port = htons((uint16_t)port); 1801 v4.sin_port = htons ((uint16_t) port);
1788 in = GNUNET_memdup(&v4, sizeof(v4)); 1802 in = GNUNET_memdup (&v4, sizeof(v4));
1789 *sock_len = sizeof(v4); 1803 *sock_len = sizeof(v4);
1790 GNUNET_free(cp); 1804 GNUNET_free (cp);
1791 return in; 1805 return in;
1792 } 1806 }
1793 } 1807 }
1794 { 1808 {
1795 /* try IPv6 */ 1809 /* try IPv6 */
@@ -1797,22 +1811,22 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
1797 const char *start; 1811 const char *start;
1798 1812
1799 start = cp; 1813 start = cp;
1800 if (('[' == *cp) && (']' == cp[strlen(cp) - 1])) 1814 if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
1801 { 1815 {
1802 start++; /* skip over '[' */ 1816 start++; /* skip over '[' */
1803 cp[strlen(cp) - 1] = '\0'; /* eat ']' */ 1817 cp[strlen (cp) - 1] = '\0'; /* eat ']' */
1804 } 1818 }
1805 if (1 == inet_pton(AF_INET6, start, &v6)) 1819 if (1 == inet_pton (AF_INET6, start, &v6))
1806 { 1820 {
1807 v6.sin6_port = htons((uint16_t)port); 1821 v6.sin6_port = htons ((uint16_t) port);
1808 in = GNUNET_memdup(&v6, sizeof(v6)); 1822 in = GNUNET_memdup (&v6, sizeof(v6));
1809 *sock_len = sizeof(v6); 1823 *sock_len = sizeof(v6);
1810 GNUNET_free(cp); 1824 GNUNET_free (cp);
1811 return in; 1825 return in;
1812 } 1826 }
1813 } 1827 }
1814 /* #5528 FIXME (feature!): maybe also try getnameinfo()? */ 1828 /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
1815 GNUNET_free(cp); 1829 GNUNET_free (cp);
1816 return NULL; 1830 return NULL;
1817} 1831}
1818 1832
@@ -1825,22 +1839,22 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
1825 * @param pad_size number of bytes of padding to append 1839 * @param pad_size number of bytes of padding to append
1826 */ 1840 */
1827static void 1841static void
1828do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size) 1842do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
1829{ 1843{
1830 char pad[pad_size]; 1844 char pad[pad_size];
1831 1845
1832 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, pad, sizeof(pad)); 1846 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, pad, sizeof(pad));
1833 if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader)) 1847 if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader))
1834 { 1848 {
1835 struct GNUNET_MessageHeader hdr = 1849 struct GNUNET_MessageHeader hdr =
1836 { .size = htons(sizeof(pad)), 1850 { .size = htons (sizeof(pad)),
1837 .type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) }; 1851 .type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) };
1838 1852
1839 memcpy(pad, &hdr, sizeof(hdr)); 1853 memcpy (pad, &hdr, sizeof(hdr));
1840 } 1854 }
1841 GNUNET_assert( 1855 GNUNET_assert (
1842 0 == 1856 0 ==
1843 gcry_cipher_encrypt(out_cipher, dgram, sizeof(pad), pad, sizeof(pad))); 1857 gcry_cipher_encrypt (out_cipher, dgram, sizeof(pad), pad, sizeof(pad)));
1844} 1858}
1845 1859
1846 1860
@@ -1853,123 +1867,123 @@ do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
1853 * @param impl_state our `struct ReceiverAddress` 1867 * @param impl_state our `struct ReceiverAddress`
1854 */ 1868 */
1855static void 1869static void
1856mq_send(struct GNUNET_MQ_Handle *mq, 1870mq_send (struct GNUNET_MQ_Handle *mq,
1857 const struct GNUNET_MessageHeader *msg, 1871 const struct GNUNET_MessageHeader *msg,
1858 void *impl_state) 1872 void *impl_state)
1859{ 1873{
1860 struct ReceiverAddress *receiver = impl_state; 1874 struct ReceiverAddress *receiver = impl_state;
1861 uint16_t msize = ntohs(msg->size); 1875 uint16_t msize = ntohs (msg->size);
1862 1876
1863 GNUNET_assert(mq == receiver->mq); 1877 GNUNET_assert (mq == receiver->mq);
1864 if (msize > receiver->mtu) 1878 if (msize > receiver->mtu)
1865 { 1879 {
1866 GNUNET_break(0); 1880 GNUNET_break (0);
1867 receiver_destroy(receiver); 1881 receiver_destroy (receiver);
1868 return; 1882 return;
1869 } 1883 }
1870 reschedule_receiver_timeout(receiver); 1884 reschedule_receiver_timeout (receiver);
1871 1885
1872 if (0 == receiver->acks_available) 1886 if (0 == receiver->acks_available)
1873 { 1887 {
1874 /* use KX encryption method */ 1888 /* use KX encryption method */
1875 struct UdpHandshakeSignature uhs; 1889 struct UdpHandshakeSignature uhs;
1876 struct UDPConfirmation uc; 1890 struct UDPConfirmation uc;
1877 struct InitialKX kx; 1891 struct InitialKX kx;
1878 struct GNUNET_CRYPTO_EcdhePrivateKey epriv; 1892 struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
1879 char dgram[receiver->mtu + sizeof(uc) + sizeof(kx)]; 1893 char dgram[receiver->mtu + sizeof(uc) + sizeof(kx)];
1880 size_t dpos; 1894 size_t dpos;
1881 gcry_cipher_hd_t out_cipher; 1895 gcry_cipher_hd_t out_cipher;
1882 struct SharedSecret *ss; 1896 struct SharedSecret *ss;
1883 1897
1884 /* setup key material */ 1898 /* setup key material */
1885 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_ecdhe_key_create2(&epriv)); 1899 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdhe_key_create2 (&epriv));
1886 1900
1887 ss = setup_shared_secret_enc(&epriv, receiver); 1901 ss = setup_shared_secret_enc (&epriv, receiver);
1888 setup_cipher(&ss->master, 0, &out_cipher); 1902 setup_cipher (&ss->master, 0, &out_cipher);
1889 /* compute 'uc' */ 1903 /* compute 'uc' */
1890 uc.sender = my_identity; 1904 uc.sender = my_identity;
1891 uc.monotonic_time = 1905 uc.monotonic_time =
1892 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg)); 1906 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
1893 uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); 1907 uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
1894 uhs.purpose.size = htonl(sizeof(uhs)); 1908 uhs.purpose.size = htonl (sizeof(uhs));
1895 uhs.sender = my_identity; 1909 uhs.sender = my_identity;
1896 uhs.receiver = receiver->target; 1910 uhs.receiver = receiver->target;
1897 GNUNET_CRYPTO_ecdhe_key_get_public(&epriv, &uhs.ephemeral); 1911 GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral);
1898 uhs.monotonic_time = uc.monotonic_time; 1912 uhs.monotonic_time = uc.monotonic_time;
1899 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, 1913 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key,
1900 &uhs.purpose, 1914 &uhs.purpose,
1901 &uc.sender_sig)); 1915 &uc.sender_sig));
1902 /* Leave space for kx */ 1916 /* Leave space for kx */
1903 dpos = sizeof(struct GNUNET_CRYPTO_EcdhePublicKey); 1917 dpos = sizeof(struct GNUNET_CRYPTO_EcdhePublicKey);
1904 /* Append encrypted uc to dgram */ 1918 /* Append encrypted uc to dgram */
1905 GNUNET_assert(0 == gcry_cipher_encrypt(out_cipher, 1919 GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher,
1906 &dgram[dpos], 1920 &dgram[dpos],
1907 sizeof(uc), 1921 sizeof(uc),
1908 &uc, 1922 &uc,
1909 sizeof(uc))); 1923 sizeof(uc)));
1910 dpos += sizeof(uc); 1924 dpos += sizeof(uc);
1911 /* Append encrypted payload to dgram */ 1925 /* Append encrypted payload to dgram */
1912 GNUNET_assert( 1926 GNUNET_assert (
1913 0 == gcry_cipher_encrypt(out_cipher, &dgram[dpos], msize, msg, msize)); 1927 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
1914 dpos += msize; 1928 dpos += msize;
1915 do_pad(out_cipher, &dgram[dpos], sizeof(dgram) - dpos); 1929 do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
1916 /* Datagram starts with kx */ 1930 /* Datagram starts with kx */
1917 kx.ephemeral = uhs.ephemeral; 1931 kx.ephemeral = uhs.ephemeral;
1918 GNUNET_assert( 1932 GNUNET_assert (
1919 0 == gcry_cipher_gettag(out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag))); 1933 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag)));
1920 gcry_cipher_close(out_cipher); 1934 gcry_cipher_close (out_cipher);
1921 memcpy(dgram, &kx, sizeof(kx)); 1935 memcpy (dgram, &kx, sizeof(kx));
1922 if (-1 == GNUNET_NETWORK_socket_sendto(udp_sock, 1936 if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock,
1923 dgram, 1937 dgram,
1924 sizeof(dgram), 1938 sizeof(dgram),
1925 receiver->address, 1939 receiver->address,
1926 receiver->address_len)) 1940 receiver->address_len))
1927 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send"); 1941 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
1928 GNUNET_MQ_impl_send_continue(mq); 1942 GNUNET_MQ_impl_send_continue (mq);
1929 return; 1943 return;
1930 } /* End of KX encryption method */ 1944 } /* End of KX encryption method */
1931 1945
1932 /* begin "BOX" encryption method, scan for ACKs from tail! */ 1946 /* begin "BOX" encryption method, scan for ACKs from tail! */
1933 for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev) 1947 for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev)
1948 {
1949 if (ss->sequence_used < ss->sequence_allowed)
1934 { 1950 {
1935 if (ss->sequence_used < ss->sequence_allowed) 1951 char dgram[sizeof(struct UDPBox) + receiver->mtu];
1936 { 1952 struct UDPBox *box;
1937 char dgram[sizeof(struct UDPBox) + receiver->mtu]; 1953 gcry_cipher_hd_t out_cipher;
1938 struct UDPBox *box; 1954 size_t dpos;
1939 gcry_cipher_hd_t out_cipher; 1955
1940 size_t dpos; 1956 box = (struct UDPBox *) dgram;
1941 1957 ss->sequence_used++;
1942 box = (struct UDPBox *)dgram; 1958 get_kid (&ss->master, ss->sequence_used, &box->kid);
1943 ss->sequence_used++; 1959 setup_cipher (&ss->master, ss->sequence_used, &out_cipher);
1944 get_kid(&ss->master, ss->sequence_used, &box->kid); 1960 /* Append encrypted payload to dgram */
1945 setup_cipher(&ss->master, ss->sequence_used, &out_cipher); 1961 dpos = sizeof(struct UDPBox);
1946 /* Append encrypted payload to dgram */ 1962 GNUNET_assert (
1947 dpos = sizeof(struct UDPBox); 1963 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
1948 GNUNET_assert( 1964 dpos += msize;
1949 0 == gcry_cipher_encrypt(out_cipher, &dgram[dpos], msize, msg, msize)); 1965 do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
1950 dpos += msize; 1966 GNUNET_assert (0 == gcry_cipher_gettag (out_cipher,
1951 do_pad(out_cipher, &dgram[dpos], sizeof(dgram) - dpos); 1967 box->gcm_tag,
1952 GNUNET_assert(0 == gcry_cipher_gettag(out_cipher, 1968 sizeof(box->gcm_tag)));
1953 box->gcm_tag, 1969 gcry_cipher_close (out_cipher);
1954 sizeof(box->gcm_tag))); 1970 if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock,
1955 gcry_cipher_close(out_cipher); 1971 dgram,
1956 if (-1 == GNUNET_NETWORK_socket_sendto(udp_sock, 1972 sizeof(dgram),
1957 dgram, 1973 receiver->address,
1958 sizeof(dgram), 1974 receiver->address_len))
1959 receiver->address, 1975 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
1960 receiver->address_len)) 1976 GNUNET_MQ_impl_send_continue (mq);
1961 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send"); 1977 receiver->acks_available--;
1962 GNUNET_MQ_impl_send_continue(mq); 1978 if (0 == receiver->acks_available)
1963 receiver->acks_available--; 1979 {
1964 if (0 == receiver->acks_available) 1980 /* We have no more ACKs => MTU change! */
1965 { 1981 setup_receiver_mq (receiver);
1966 /* We have no more ACKs => MTU change! */ 1982 }
1967 setup_receiver_mq(receiver); 1983 return;
1968 }
1969 return;
1970 }
1971 } 1984 }
1972 GNUNET_assert(0); 1985 }
1986 GNUNET_assert (0);
1973} 1987}
1974 1988
1975 1989
@@ -1982,15 +1996,15 @@ mq_send(struct GNUNET_MQ_Handle *mq,
1982 * @param impl_state our `struct ReceiverAddress` 1996 * @param impl_state our `struct ReceiverAddress`
1983 */ 1997 */
1984static void 1998static void
1985mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) 1999mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
1986{ 2000{
1987 struct ReceiverAddress *receiver = impl_state; 2001 struct ReceiverAddress *receiver = impl_state;
1988 2002
1989 if (mq == receiver->mq) 2003 if (mq == receiver->mq)
1990 { 2004 {
1991 receiver->mq = NULL; 2005 receiver->mq = NULL;
1992 receiver_destroy(receiver); 2006 receiver_destroy (receiver);
1993 } 2007 }
1994} 2008}
1995 2009
1996 2010
@@ -2001,10 +2015,10 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
2001 * @param impl_state our `struct RecvierAddress` 2015 * @param impl_state our `struct RecvierAddress`
2002 */ 2016 */
2003static void 2017static void
2004mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) 2018mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2005{ 2019{
2006 /* Cancellation is impossible with UDP; bail */ 2020 /* Cancellation is impossible with UDP; bail */
2007 GNUNET_assert(0); 2021 GNUNET_assert (0);
2008} 2022}
2009 2023
2010 2024
@@ -2018,15 +2032,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
2018 * @param error error code 2032 * @param error error code
2019 */ 2033 */
2020static void 2034static void
2021mq_error(void *cls, enum GNUNET_MQ_Error error) 2035mq_error (void *cls, enum GNUNET_MQ_Error error)
2022{ 2036{
2023 struct ReceiverAddress *receiver = cls; 2037 struct ReceiverAddress *receiver = cls;
2024 2038
2025 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2039 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2026 "MQ error in queue to %s: %d\n", 2040 "MQ error in queue to %s: %d\n",
2027 GNUNET_i2s(&receiver->target), 2041 GNUNET_i2s (&receiver->target),
2028 (int)error); 2042 (int) error);
2029 receiver_destroy(receiver); 2043 receiver_destroy (receiver);
2030} 2044}
2031 2045
2032 2046
@@ -2038,63 +2052,63 @@ mq_error(void *cls, enum GNUNET_MQ_Error error)
2038 * @param receiver receiver to setup MQ for 2052 * @param receiver receiver to setup MQ for
2039 */ 2053 */
2040static void 2054static void
2041setup_receiver_mq(struct ReceiverAddress *receiver) 2055setup_receiver_mq (struct ReceiverAddress *receiver)
2042{ 2056{
2043 size_t base_mtu; 2057 size_t base_mtu;
2044 2058
2045 if (NULL != receiver->qh) 2059 if (NULL != receiver->qh)
2046 { 2060 {
2047 GNUNET_TRANSPORT_communicator_mq_del(receiver->qh); 2061 GNUNET_TRANSPORT_communicator_mq_del (receiver->qh);
2048 receiver->qh = NULL; 2062 receiver->qh = NULL;
2049 } 2063 }
2050 GNUNET_assert(NULL == receiver->mq); 2064 GNUNET_assert (NULL == receiver->mq);
2051 switch (receiver->address->sa_family) 2065 switch (receiver->address->sa_family)
2052 { 2066 {
2053 case AF_INET: 2067 case AF_INET:
2054 base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */ 2068 base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */
2055 - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */ 2069 - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */
2056 - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; 2070 - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
2057 break; 2071 break;
2058 2072
2059 case AF_INET6: 2073 case AF_INET6:
2060 base_mtu = 1280 /* Minimum MTU required by IPv6 */ 2074 base_mtu = 1280 /* Minimum MTU required by IPv6 */
2061 - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */ 2075 - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */
2062 - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; 2076 - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
2063 break; 2077 break;
2064 2078
2065 default: 2079 default:
2066 GNUNET_assert(0); 2080 GNUNET_assert (0);
2067 break; 2081 break;
2068 } 2082 }
2069 if (0 == receiver->acks_available) 2083 if (0 == receiver->acks_available)
2070 { 2084 {
2071 /* MTU based on full KX messages */ 2085 /* MTU based on full KX messages */
2072 receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */ 2086 receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
2073 - sizeof(struct UDPConfirmation); /* 104 */ 2087 - sizeof(struct UDPConfirmation); /* 104 */
2074 } 2088 }
2075 else 2089 else
2076 { 2090 {
2077 /* MTU based on BOXed messages */ 2091 /* MTU based on BOXed messages */
2078 receiver->mtu = base_mtu - sizeof(struct UDPBox); 2092 receiver->mtu = base_mtu - sizeof(struct UDPBox);
2079 } 2093 }
2080 /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to 2094 /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to
2081 1404 (IPv4 + Box) bytes, depending on circumstances... */ 2095 1404 (IPv4 + Box) bytes, depending on circumstances... */
2082 if (NULL == receiver->mq) 2096 if (NULL == receiver->mq)
2083 receiver->mq = GNUNET_MQ_queue_for_callbacks(&mq_send, 2097 receiver->mq = GNUNET_MQ_queue_for_callbacks (&mq_send,
2084 &mq_destroy, 2098 &mq_destroy,
2085 &mq_cancel, 2099 &mq_cancel,
2086 receiver, 2100 receiver,
2087 NULL, 2101 NULL,
2088 &mq_error, 2102 &mq_error,
2089 receiver); 2103 receiver);
2090 receiver->qh = 2104 receiver->qh =
2091 GNUNET_TRANSPORT_communicator_mq_add(ch, 2105 GNUNET_TRANSPORT_communicator_mq_add (ch,
2092 &receiver->target, 2106 &receiver->target,
2093 receiver->foreign_addr, 2107 receiver->foreign_addr,
2094 receiver->mtu, 2108 receiver->mtu,
2095 receiver->nt, 2109 receiver->nt,
2096 GNUNET_TRANSPORT_CS_OUTBOUND, 2110 GNUNET_TRANSPORT_CS_OUTBOUND,
2097 receiver->mq); 2111 receiver->mq);
2098} 2112}
2099 2113
2100 2114
@@ -2117,47 +2131,47 @@ setup_receiver_mq(struct ReceiverAddress *receiver)
2117 * invalid 2131 * invalid
2118 */ 2132 */
2119static int 2133static int
2120mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) 2134mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2121{ 2135{
2122 struct ReceiverAddress *receiver; 2136 struct ReceiverAddress *receiver;
2123 const char *path; 2137 const char *path;
2124 struct sockaddr *in; 2138 struct sockaddr *in;
2125 socklen_t in_len; 2139 socklen_t in_len;
2126 2140
2127 if (0 != strncmp(address, 2141 if (0 != strncmp (address,
2128 COMMUNICATOR_ADDRESS_PREFIX "-", 2142 COMMUNICATOR_ADDRESS_PREFIX "-",
2129 strlen(COMMUNICATOR_ADDRESS_PREFIX "-"))) 2143 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
2130 { 2144 {
2131 GNUNET_break_op(0); 2145 GNUNET_break_op (0);
2132 return GNUNET_SYSERR; 2146 return GNUNET_SYSERR;
2133 } 2147 }
2134 path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")]; 2148 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2135 in = udp_address_to_sockaddr(path, &in_len); 2149 in = udp_address_to_sockaddr (path, &in_len);
2136 2150
2137 receiver = GNUNET_new(struct ReceiverAddress); 2151 receiver = GNUNET_new (struct ReceiverAddress);
2138 receiver->address = in; 2152 receiver->address = in;
2139 receiver->address_len = in_len; 2153 receiver->address_len = in_len;
2140 receiver->target = *peer; 2154 receiver->target = *peer;
2141 receiver->nt = GNUNET_NT_scanner_get_type(is, in, in_len); 2155 receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
2142 (void)GNUNET_CONTAINER_multipeermap_put( 2156 (void) GNUNET_CONTAINER_multipeermap_put (
2143 receivers, 2157 receivers,
2144 &receiver->target, 2158 &receiver->target,
2145 receiver, 2159 receiver,
2146 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2160 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2147 receiver->timeout = 2161 receiver->timeout =
2148 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2162 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2149 receiver->hn = GNUNET_CONTAINER_heap_insert(receivers_heap, 2163 receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap,
2150 receiver, 2164 receiver,
2151 receiver->timeout.abs_value_us); 2165 receiver->timeout.abs_value_us);
2152 GNUNET_STATISTICS_set(stats, 2166 GNUNET_STATISTICS_set (stats,
2153 "# receivers active", 2167 "# receivers active",
2154 GNUNET_CONTAINER_multipeermap_size(receivers), 2168 GNUNET_CONTAINER_multipeermap_size (receivers),
2155 GNUNET_NO); 2169 GNUNET_NO);
2156 receiver->foreign_addr = 2170 receiver->foreign_addr =
2157 sockaddr_to_udpaddr_string(receiver->address, receiver->address_len); 2171 sockaddr_to_udpaddr_string (receiver->address, receiver->address_len);
2158 setup_receiver_mq(receiver); 2172 setup_receiver_mq (receiver);
2159 if (NULL == timeout_task) 2173 if (NULL == timeout_task)
2160 timeout_task = GNUNET_SCHEDULER_add_now(&check_timeouts, NULL); 2174 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
2161 return GNUNET_OK; 2175 return GNUNET_OK;
2162} 2176}
2163 2177
@@ -2171,15 +2185,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2171 * @return #GNUNET_OK to continue to iterate 2185 * @return #GNUNET_OK to continue to iterate
2172 */ 2186 */
2173static int 2187static int
2174get_receiver_delete_it(void *cls, 2188get_receiver_delete_it (void *cls,
2175 const struct GNUNET_PeerIdentity *target, 2189 const struct GNUNET_PeerIdentity *target,
2176 void *value) 2190 void *value)
2177{ 2191{
2178 struct ReceiverAddress *receiver = value; 2192 struct ReceiverAddress *receiver = value;
2179 2193
2180 (void)cls; 2194 (void) cls;
2181 (void)target; 2195 (void) target;
2182 receiver_destroy(receiver); 2196 receiver_destroy (receiver);
2183 return GNUNET_OK; 2197 return GNUNET_OK;
2184} 2198}
2185 2199
@@ -2193,15 +2207,15 @@ get_receiver_delete_it(void *cls,
2193 * @return #GNUNET_OK to continue to iterate 2207 * @return #GNUNET_OK to continue to iterate
2194 */ 2208 */
2195static int 2209static int
2196get_sender_delete_it(void *cls, 2210get_sender_delete_it (void *cls,
2197 const struct GNUNET_PeerIdentity *target, 2211 const struct GNUNET_PeerIdentity *target,
2198 void *value) 2212 void *value)
2199{ 2213{
2200 struct SenderAddress *sender = value; 2214 struct SenderAddress *sender = value;
2201 2215
2202 (void)cls; 2216 (void) cls;
2203 (void)target; 2217 (void) target;
2204 sender_destroy(sender); 2218 sender_destroy (sender);
2205 return GNUNET_OK; 2219 return GNUNET_OK;
2206} 2220}
2207 2221
@@ -2212,64 +2226,64 @@ get_sender_delete_it(void *cls,
2212 * @param cls NULL (always) 2226 * @param cls NULL (always)
2213 */ 2227 */
2214static void 2228static void
2215do_shutdown(void *cls) 2229do_shutdown (void *cls)
2216{ 2230{
2217 if (NULL != nat) 2231 if (NULL != nat)
2218 { 2232 {
2219 GNUNET_NAT_unregister(nat); 2233 GNUNET_NAT_unregister (nat);
2220 nat = NULL; 2234 nat = NULL;
2221 } 2235 }
2222 while (NULL != bi_head) 2236 while (NULL != bi_head)
2223 bi_destroy(bi_head); 2237 bi_destroy (bi_head);
2224 if (NULL != broadcast_task) 2238 if (NULL != broadcast_task)
2225 { 2239 {
2226 GNUNET_SCHEDULER_cancel(broadcast_task); 2240 GNUNET_SCHEDULER_cancel (broadcast_task);
2227 broadcast_task = NULL; 2241 broadcast_task = NULL;
2228 } 2242 }
2229 if (NULL != read_task) 2243 if (NULL != read_task)
2230 { 2244 {
2231 GNUNET_SCHEDULER_cancel(read_task); 2245 GNUNET_SCHEDULER_cancel (read_task);
2232 read_task = NULL; 2246 read_task = NULL;
2233 } 2247 }
2234 if (NULL != udp_sock) 2248 if (NULL != udp_sock)
2235 { 2249 {
2236 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(udp_sock)); 2250 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (udp_sock));
2237 udp_sock = NULL; 2251 udp_sock = NULL;
2238 } 2252 }
2239 GNUNET_CONTAINER_multipeermap_iterate(receivers, 2253 GNUNET_CONTAINER_multipeermap_iterate (receivers,
2240 &get_receiver_delete_it, 2254 &get_receiver_delete_it,
2241 NULL); 2255 NULL);
2242 GNUNET_CONTAINER_multipeermap_destroy(receivers); 2256 GNUNET_CONTAINER_multipeermap_destroy (receivers);
2243 GNUNET_CONTAINER_multipeermap_iterate(senders, &get_sender_delete_it, NULL); 2257 GNUNET_CONTAINER_multipeermap_iterate (senders, &get_sender_delete_it, NULL);
2244 GNUNET_CONTAINER_multipeermap_destroy(senders); 2258 GNUNET_CONTAINER_multipeermap_destroy (senders);
2245 GNUNET_CONTAINER_multishortmap_destroy(key_cache); 2259 GNUNET_CONTAINER_multishortmap_destroy (key_cache);
2246 GNUNET_CONTAINER_heap_destroy(senders_heap); 2260 GNUNET_CONTAINER_heap_destroy (senders_heap);
2247 GNUNET_CONTAINER_heap_destroy(receivers_heap); 2261 GNUNET_CONTAINER_heap_destroy (receivers_heap);
2248 if (NULL != ch) 2262 if (NULL != ch)
2249 { 2263 {
2250 GNUNET_TRANSPORT_communicator_disconnect(ch); 2264 GNUNET_TRANSPORT_communicator_disconnect (ch);
2251 ch = NULL; 2265 ch = NULL;
2252 } 2266 }
2253 if (NULL != ah) 2267 if (NULL != ah)
2254 { 2268 {
2255 GNUNET_TRANSPORT_application_done(ah); 2269 GNUNET_TRANSPORT_application_done (ah);
2256 ah = NULL; 2270 ah = NULL;
2257 } 2271 }
2258 if (NULL != stats) 2272 if (NULL != stats)
2259 { 2273 {
2260 GNUNET_STATISTICS_destroy(stats, GNUNET_NO); 2274 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
2261 stats = NULL; 2275 stats = NULL;
2262 } 2276 }
2263 if (NULL != my_private_key) 2277 if (NULL != my_private_key)
2264 { 2278 {
2265 GNUNET_free(my_private_key); 2279 GNUNET_free (my_private_key);
2266 my_private_key = NULL; 2280 my_private_key = NULL;
2267 } 2281 }
2268 if (NULL != is) 2282 if (NULL != is)
2269 { 2283 {
2270 GNUNET_NT_scanner_done(is); 2284 GNUNET_NT_scanner_done (is);
2271 is = NULL; 2285 is = NULL;
2272 } 2286 }
2273} 2287}
2274 2288
2275 2289
@@ -2283,24 +2297,24 @@ do_shutdown(void *cls)
2283 * @param msg payload 2297 * @param msg payload
2284 */ 2298 */
2285static void 2299static void
2286enc_notify_cb(void *cls, 2300enc_notify_cb (void *cls,
2287 const struct GNUNET_PeerIdentity *sender, 2301 const struct GNUNET_PeerIdentity *sender,
2288 const struct GNUNET_MessageHeader *msg) 2302 const struct GNUNET_MessageHeader *msg)
2289{ 2303{
2290 const struct UDPAck *ack; 2304 const struct UDPAck *ack;
2291 2305
2292 (void)cls; 2306 (void) cls;
2293 if ((ntohs(msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) || 2307 if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) ||
2294 (ntohs(msg->size) != sizeof(struct UDPAck))) 2308 (ntohs (msg->size) != sizeof(struct UDPAck)))
2295 { 2309 {
2296 GNUNET_break_op(0); 2310 GNUNET_break_op (0);
2297 return; 2311 return;
2298 } 2312 }
2299 ack = (const struct UDPAck *)msg; 2313 ack = (const struct UDPAck *) msg;
2300 GNUNET_CONTAINER_multipeermap_get_multiple(receivers, 2314 GNUNET_CONTAINER_multipeermap_get_multiple (receivers,
2301 sender, 2315 sender,
2302 &handle_ack, 2316 &handle_ack,
2303 (void *)ack); 2317 (void *) ack);
2304} 2318}
2305 2319
2306 2320
@@ -2318,39 +2332,39 @@ enc_notify_cb(void *cls,
2318 * @param addrlen actual length of the @a addr 2332 * @param addrlen actual length of the @a addr
2319 */ 2333 */
2320static void 2334static void
2321nat_address_cb(void *cls, 2335nat_address_cb (void *cls,
2322 void **app_ctx, 2336 void **app_ctx,
2323 int add_remove, 2337 int add_remove,
2324 enum GNUNET_NAT_AddressClass ac, 2338 enum GNUNET_NAT_AddressClass ac,
2325 const struct sockaddr *addr, 2339 const struct sockaddr *addr,
2326 socklen_t addrlen) 2340 socklen_t addrlen)
2327{ 2341{
2328 char *my_addr; 2342 char *my_addr;
2329 struct GNUNET_TRANSPORT_AddressIdentifier *ai; 2343 struct GNUNET_TRANSPORT_AddressIdentifier *ai;
2330 2344
2331 if (GNUNET_YES == add_remove) 2345 if (GNUNET_YES == add_remove)
2332 { 2346 {
2333 enum GNUNET_NetworkType nt; 2347 enum GNUNET_NetworkType nt;
2334 2348
2335 GNUNET_asprintf(&my_addr, 2349 GNUNET_asprintf (&my_addr,
2336 "%s-%s", 2350 "%s-%s",
2337 COMMUNICATOR_ADDRESS_PREFIX, 2351 COMMUNICATOR_ADDRESS_PREFIX,
2338 GNUNET_a2s(addr, addrlen)); 2352 GNUNET_a2s (addr, addrlen));
2339 nt = GNUNET_NT_scanner_get_type(is, addr, addrlen); 2353 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
2340 ai = 2354 ai =
2341 GNUNET_TRANSPORT_communicator_address_add(ch, 2355 GNUNET_TRANSPORT_communicator_address_add (ch,
2342 my_addr, 2356 my_addr,
2343 nt, 2357 nt,
2344 GNUNET_TIME_UNIT_FOREVER_REL); 2358 GNUNET_TIME_UNIT_FOREVER_REL);
2345 GNUNET_free(my_addr); 2359 GNUNET_free (my_addr);
2346 *app_ctx = ai; 2360 *app_ctx = ai;
2347 } 2361 }
2348 else 2362 else
2349 { 2363 {
2350 ai = *app_ctx; 2364 ai = *app_ctx;
2351 GNUNET_TRANSPORT_communicator_address_remove(ai); 2365 GNUNET_TRANSPORT_communicator_address_remove (ai);
2352 *app_ctx = NULL; 2366 *app_ctx = NULL;
2353 } 2367 }
2354} 2368}
2355 2369
2356 2370
@@ -2360,69 +2374,69 @@ nat_address_cb(void *cls,
2360 * @param cls a `struct BroadcastInterface` 2374 * @param cls a `struct BroadcastInterface`
2361 */ 2375 */
2362static void 2376static void
2363ifc_broadcast(void *cls) 2377ifc_broadcast (void *cls)
2364{ 2378{
2365 struct BroadcastInterface *bi = cls; 2379 struct BroadcastInterface *bi = cls;
2366 struct GNUNET_TIME_Relative delay; 2380 struct GNUNET_TIME_Relative delay;
2367 2381
2368 delay = BROADCAST_FREQUENCY; 2382 delay = BROADCAST_FREQUENCY;
2369 delay.rel_value_us = 2383 delay.rel_value_us =
2370 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us); 2384 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us);
2371 bi->broadcast_task = 2385 bi->broadcast_task =
2372 GNUNET_SCHEDULER_add_delayed(INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi); 2386 GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi);
2373 2387
2374 switch (bi->sa->sa_family) 2388 switch (bi->sa->sa_family)
2375 { 2389 {
2376 case AF_INET: { 2390 case AF_INET: {
2377 static int yes = 1; 2391 static int yes = 1;
2378 static int no = 0; 2392 static int no = 0;
2379 ssize_t sent; 2393 ssize_t sent;
2380 2394
2381 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock, 2395 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock,
2382 SOL_SOCKET, 2396 SOL_SOCKET,
2383 SO_BROADCAST, 2397 SO_BROADCAST,
2384 &yes, 2398 &yes,
2385 sizeof(int))) 2399 sizeof(int)))
2386 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 2400 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
2387 sent = GNUNET_NETWORK_socket_sendto(udp_sock, 2401 sent = GNUNET_NETWORK_socket_sendto (udp_sock,
2388 &bi->bcm, 2402 &bi->bcm,
2389 sizeof(bi->bcm), 2403 sizeof(bi->bcm),
2390 bi->ba, 2404 bi->ba,
2391 bi->salen); 2405 bi->salen);
2392 if (-1 == sent) 2406 if (-1 == sent)
2393 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "sendto"); 2407 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto");
2394 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock, 2408 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock,
2395 SOL_SOCKET, 2409 SOL_SOCKET,
2396 SO_BROADCAST, 2410 SO_BROADCAST,
2397 &no, 2411 &no,
2398 sizeof(int))) 2412 sizeof(int)))
2399 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 2413 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
2400 break; 2414 break;
2401 } 2415 }
2402 2416
2403 case AF_INET6: { 2417 case AF_INET6: {
2404 ssize_t sent; 2418 ssize_t sent;
2405 struct sockaddr_in6 dst; 2419 struct sockaddr_in6 dst;
2406 2420
2407 dst.sin6_family = AF_INET6; 2421 dst.sin6_family = AF_INET6;
2408 dst.sin6_port = htons(my_port); 2422 dst.sin6_port = htons (my_port);
2409 dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr; 2423 dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr;
2410 dst.sin6_scope_id = ((struct sockaddr_in6 *)bi->ba)->sin6_scope_id; 2424 dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id;
2411 2425
2412 sent = GNUNET_NETWORK_socket_sendto(udp_sock, 2426 sent = GNUNET_NETWORK_socket_sendto (udp_sock,
2413 &bi->bcm, 2427 &bi->bcm,
2414 sizeof(bi->bcm), 2428 sizeof(bi->bcm),
2415 (const struct sockaddr *)&dst, 2429 (const struct sockaddr *) &dst,
2416 sizeof(dst)); 2430 sizeof(dst));
2417 if (-1 == sent) 2431 if (-1 == sent)
2418 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "sendto"); 2432 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto");
2419 break; 2433 break;
2420 } 2434 }
2421 2435
2422 default: 2436 default:
2423 GNUNET_break(0); 2437 GNUNET_break (0);
2424 break; 2438 break;
2425 } 2439 }
2426} 2440}
2427 2441
2428 2442
@@ -2441,90 +2455,90 @@ ifc_broadcast(void *cls)
2441 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort 2455 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
2442 */ 2456 */
2443static int 2457static int
2444iface_proc(void *cls, 2458iface_proc (void *cls,
2445 const char *name, 2459 const char *name,
2446 int isDefault, 2460 int isDefault,
2447 const struct sockaddr *addr, 2461 const struct sockaddr *addr,
2448 const struct sockaddr *broadcast_addr, 2462 const struct sockaddr *broadcast_addr,
2449 const struct sockaddr *netmask, 2463 const struct sockaddr *netmask,
2450 socklen_t addrlen) 2464 socklen_t addrlen)
2451{ 2465{
2452 struct BroadcastInterface *bi; 2466 struct BroadcastInterface *bi;
2453 enum GNUNET_NetworkType network; 2467 enum GNUNET_NetworkType network;
2454 struct UdpBroadcastSignature ubs; 2468 struct UdpBroadcastSignature ubs;
2455 2469
2456 (void)cls; 2470 (void) cls;
2457 (void)netmask; 2471 (void) netmask;
2458 if (NULL == addr) 2472 if (NULL == addr)
2459 return GNUNET_YES; /* need to know our address! */ 2473 return GNUNET_YES; /* need to know our address! */
2460 network = GNUNET_NT_scanner_get_type(is, addr, addrlen); 2474 network = GNUNET_NT_scanner_get_type (is, addr, addrlen);
2461 if (GNUNET_NT_LOOPBACK == network) 2475 if (GNUNET_NT_LOOPBACK == network)
2462 { 2476 {
2463 /* Broadcasting on loopback does not make sense */ 2477 /* Broadcasting on loopback does not make sense */
2464 return GNUNET_YES; 2478 return GNUNET_YES;
2465 } 2479 }
2466 for (bi = bi_head; NULL != bi; bi = bi->next) 2480 for (bi = bi_head; NULL != bi; bi = bi->next)
2481 {
2482 if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen)))
2467 { 2483 {
2468 if ((bi->salen == addrlen) && (0 == memcmp(addr, bi->sa, addrlen))) 2484 bi->found = GNUNET_YES;
2469 { 2485 return GNUNET_OK;
2470 bi->found = GNUNET_YES;
2471 return GNUNET_OK;
2472 }
2473 } 2486 }
2487 }
2474 2488
2475 if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr)) 2489 if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr))
2476 return GNUNET_OK; /* broadcast_addr is required for IPv6! */ 2490 return GNUNET_OK; /* broadcast_addr is required for IPv6! */
2477 if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket)) 2491 if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket))
2478 return GNUNET_OK; /* not using IPv6 */ 2492 return GNUNET_OK; /* not using IPv6 */
2479 2493
2480 bi = GNUNET_new(struct BroadcastInterface); 2494 bi = GNUNET_new (struct BroadcastInterface);
2481 bi->sa = GNUNET_memdup(addr, addrlen); 2495 bi->sa = GNUNET_memdup (addr, addrlen);
2482 if (NULL != broadcast_addr) 2496 if (NULL != broadcast_addr)
2483 bi->ba = GNUNET_memdup(broadcast_addr, addrlen); 2497 bi->ba = GNUNET_memdup (broadcast_addr, addrlen);
2484 bi->salen = addrlen; 2498 bi->salen = addrlen;
2485 bi->found = GNUNET_YES; 2499 bi->found = GNUNET_YES;
2486 bi->bcm.sender = my_identity; 2500 bi->bcm.sender = my_identity;
2487 ubs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); 2501 ubs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
2488 ubs.purpose.size = htonl(sizeof(ubs)); 2502 ubs.purpose.size = htonl (sizeof(ubs));
2489 ubs.sender = my_identity; 2503 ubs.sender = my_identity;
2490 GNUNET_CRYPTO_hash(addr, addrlen, &ubs.h_address); 2504 GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address);
2491 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, 2505 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key,
2492 &ubs.purpose, 2506 &ubs.purpose,
2493 &bi->bcm.sender_sig)); 2507 &bi->bcm.sender_sig));
2494 bi->broadcast_task = GNUNET_SCHEDULER_add_now(&ifc_broadcast, bi); 2508 bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast, bi);
2495 GNUNET_CONTAINER_DLL_insert(bi_head, bi_tail, bi); 2509 GNUNET_CONTAINER_DLL_insert (bi_head, bi_tail, bi);
2496 if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr)) 2510 if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr))
2511 {
2512 /* Create IPv6 multicast request */
2513 const struct sockaddr_in6 *s6 =
2514 (const struct sockaddr_in6 *) broadcast_addr;
2515
2516 GNUNET_assert (
2517 1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr));
2518
2519 /* http://tools.ietf.org/html/rfc2553#section-5.2:
2520 *
2521 * IPV6_JOIN_GROUP
2522 *
2523 * Join a multicast group on a specified local interface. If the
2524 * interface index is specified as 0, the kernel chooses the local
2525 * interface. For example, some kernels look up the multicast
2526 * group in the normal IPv6 routing table and using the resulting
2527 * interface; we do this for each interface, so no need to use
2528 * zero (anymore...).
2529 */
2530 bi->mcreq.ipv6mr_interface = s6->sin6_scope_id;
2531
2532 /* Join the multicast group */
2533 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock,
2534 IPPROTO_IPV6,
2535 IPV6_JOIN_GROUP,
2536 &bi->mcreq,
2537 sizeof(bi->mcreq)))
2497 { 2538 {
2498 /* Create IPv6 multicast request */ 2539 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
2499 const struct sockaddr_in6 *s6 =
2500 (const struct sockaddr_in6 *)broadcast_addr;
2501
2502 GNUNET_assert(
2503 1 == inet_pton(AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr));
2504
2505 /* http://tools.ietf.org/html/rfc2553#section-5.2:
2506 *
2507 * IPV6_JOIN_GROUP
2508 *
2509 * Join a multicast group on a specified local interface. If the
2510 * interface index is specified as 0, the kernel chooses the local
2511 * interface. For example, some kernels look up the multicast
2512 * group in the normal IPv6 routing table and using the resulting
2513 * interface; we do this for each interface, so no need to use
2514 * zero (anymore...).
2515 */
2516 bi->mcreq.ipv6mr_interface = s6->sin6_scope_id;
2517
2518 /* Join the multicast group */
2519 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock,
2520 IPPROTO_IPV6,
2521 IPV6_JOIN_GROUP,
2522 &bi->mcreq,
2523 sizeof(bi->mcreq)))
2524 {
2525 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt");
2526 }
2527 } 2540 }
2541 }
2528 return GNUNET_OK; 2542 return GNUNET_OK;
2529} 2543}
2530 2544
@@ -2535,23 +2549,23 @@ iface_proc(void *cls,
2535 * @param cls NULL, unused 2549 * @param cls NULL, unused
2536 */ 2550 */
2537static void 2551static void
2538do_broadcast(void *cls) 2552do_broadcast (void *cls)
2539{ 2553{
2540 struct BroadcastInterface *bin; 2554 struct BroadcastInterface *bin;
2541 2555
2542 (void)cls; 2556 (void) cls;
2543 for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next) 2557 for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next)
2544 bi->found = GNUNET_NO; 2558 bi->found = GNUNET_NO;
2545 GNUNET_OS_network_interfaces_list(&iface_proc, NULL); 2559 GNUNET_OS_network_interfaces_list (&iface_proc, NULL);
2546 for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin) 2560 for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin)
2547 { 2561 {
2548 bin = bi->next; 2562 bin = bi->next;
2549 if (GNUNET_NO == bi->found) 2563 if (GNUNET_NO == bi->found)
2550 bi_destroy(bi); 2564 bi_destroy (bi);
2551 } 2565 }
2552 broadcast_task = GNUNET_SCHEDULER_add_delayed(INTERFACE_SCAN_FREQUENCY, 2566 broadcast_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY,
2553 &do_broadcast, 2567 &do_broadcast,
2554 NULL); 2568 NULL);
2555} 2569}
2556 2570
2557 2571
@@ -2564,10 +2578,10 @@ do_broadcast(void *cls)
2564 * @param c configuration 2578 * @param c configuration
2565 */ 2579 */
2566static void 2580static void
2567run(void *cls, 2581run (void *cls,
2568 char *const *args, 2582 char *const *args,
2569 const char *cfgfile, 2583 const char *cfgfile,
2570 const struct GNUNET_CONFIGURATION_Handle *c) 2584 const struct GNUNET_CONFIGURATION_Handle *c)
2571{ 2585{
2572 char *bindto; 2586 char *bindto;
2573 struct sockaddr *in; 2587 struct sockaddr *in;
@@ -2575,143 +2589,143 @@ run(void *cls,
2575 struct sockaddr_storage in_sto; 2589 struct sockaddr_storage in_sto;
2576 socklen_t sto_len; 2590 socklen_t sto_len;
2577 2591
2578 (void)cls; 2592 (void) cls;
2579 cfg = c; 2593 cfg = c;
2580 if (GNUNET_OK != 2594 if (GNUNET_OK !=
2581 GNUNET_CONFIGURATION_get_value_filename(cfg, 2595 GNUNET_CONFIGURATION_get_value_filename (cfg,
2582 COMMUNICATOR_CONFIG_SECTION, 2596 COMMUNICATOR_CONFIG_SECTION,
2583 "BINDTO", 2597 "BINDTO",
2584 &bindto)) 2598 &bindto))
2585 { 2599 {
2586 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 2600 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2587 COMMUNICATOR_CONFIG_SECTION, 2601 COMMUNICATOR_CONFIG_SECTION,
2588 "BINDTO"); 2602 "BINDTO");
2589 return; 2603 return;
2590 } 2604 }
2591 2605
2592 in = udp_address_to_sockaddr(bindto, &in_len); 2606 in = udp_address_to_sockaddr (bindto, &in_len);
2593 if (NULL == in) 2607 if (NULL == in)
2594 { 2608 {
2595 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2609 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2596 "Failed to setup UDP socket address with path `%s'\n", 2610 "Failed to setup UDP socket address with path `%s'\n",
2597 bindto); 2611 bindto);
2598 GNUNET_free(bindto); 2612 GNUNET_free (bindto);
2599 return; 2613 return;
2600 } 2614 }
2601 udp_sock = 2615 udp_sock =
2602 GNUNET_NETWORK_socket_create(in->sa_family, SOCK_DGRAM, IPPROTO_UDP); 2616 GNUNET_NETWORK_socket_create (in->sa_family, SOCK_DGRAM, IPPROTO_UDP);
2603 if (NULL == udp_sock) 2617 if (NULL == udp_sock)
2604 { 2618 {
2605 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); 2619 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
2606 GNUNET_free(in); 2620 GNUNET_free (in);
2607 GNUNET_free(bindto); 2621 GNUNET_free (bindto);
2608 return; 2622 return;
2609 } 2623 }
2610 if (AF_INET6 == in->sa_family) 2624 if (AF_INET6 == in->sa_family)
2611 have_v6_socket = GNUNET_YES; 2625 have_v6_socket = GNUNET_YES;
2612 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(udp_sock, in, in_len)) 2626 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (udp_sock, in, in_len))
2613 { 2627 {
2614 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", bindto); 2628 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto);
2615 GNUNET_NETWORK_socket_close(udp_sock); 2629 GNUNET_NETWORK_socket_close (udp_sock);
2616 udp_sock = NULL; 2630 udp_sock = NULL;
2617 GNUNET_free(in); 2631 GNUNET_free (in);
2618 GNUNET_free(bindto); 2632 GNUNET_free (bindto);
2619 return; 2633 return;
2620 } 2634 }
2621 /* We might have bound to port 0, allowing the OS to figure it out; 2635 /* We might have bound to port 0, allowing the OS to figure it out;
2622 thus, get the real IN-address from the socket */ 2636 thus, get the real IN-address from the socket */
2623 sto_len = sizeof(in_sto); 2637 sto_len = sizeof(in_sto);
2624 if (0 != getsockname(GNUNET_NETWORK_get_fd(udp_sock), 2638 if (0 != getsockname (GNUNET_NETWORK_get_fd (udp_sock),
2625 (struct sockaddr *)&in_sto, 2639 (struct sockaddr *) &in_sto,
2626 &sto_len)) 2640 &sto_len))
2627 { 2641 {
2628 memcpy(&in_sto, in, in_len); 2642 memcpy (&in_sto, in, in_len);
2629 sto_len = in_len; 2643 sto_len = in_len;
2630 } 2644 }
2631 GNUNET_free(in); 2645 GNUNET_free (in);
2632 GNUNET_free(bindto); 2646 GNUNET_free (bindto);
2633 in = (struct sockaddr *)&in_sto; 2647 in = (struct sockaddr *) &in_sto;
2634 in_len = sto_len; 2648 in_len = sto_len;
2635 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2636 "Bound to `%s'\n", 2650 "Bound to `%s'\n",
2637 GNUNET_a2s((const struct sockaddr *)&in_sto, sto_len)); 2651 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
2638 switch (in->sa_family) 2652 switch (in->sa_family)
2639 { 2653 {
2640 case AF_INET: 2654 case AF_INET:
2641 my_port = ntohs(((struct sockaddr_in *)in)->sin_port); 2655 my_port = ntohs (((struct sockaddr_in *) in)->sin_port);
2642 break; 2656 break;
2643 2657
2644 case AF_INET6: 2658 case AF_INET6:
2645 my_port = ntohs(((struct sockaddr_in6 *)in)->sin6_port); 2659 my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port);
2646 break; 2660 break;
2647 2661
2648 default: 2662 default:
2649 GNUNET_break(0); 2663 GNUNET_break (0);
2650 my_port = 0; 2664 my_port = 0;
2651 } 2665 }
2652 stats = GNUNET_STATISTICS_create("C-UDP", cfg); 2666 stats = GNUNET_STATISTICS_create ("C-UDP", cfg);
2653 senders = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES); 2667 senders = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES);
2654 receivers = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES); 2668 receivers = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES);
2655 senders_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 2669 senders_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2656 receivers_heap = 2670 receivers_heap =
2657 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 2671 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2658 key_cache = GNUNET_CONTAINER_multishortmap_create(1024, GNUNET_YES); 2672 key_cache = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_YES);
2659 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 2673 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
2660 is = GNUNET_NT_scanner_init(); 2674 is = GNUNET_NT_scanner_init ();
2661 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); 2675 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
2662 if (NULL == my_private_key) 2676 if (NULL == my_private_key)
2663 { 2677 {
2664 GNUNET_log( 2678 GNUNET_log (
2665 GNUNET_ERROR_TYPE_ERROR, 2679 GNUNET_ERROR_TYPE_ERROR,
2666 _( 2680 _ (
2667 "Transport service is lacking key configuration settings. Exiting.\n")); 2681 "Transport service is lacking key configuration settings. Exiting.\n"));
2668 GNUNET_SCHEDULER_shutdown(); 2682 GNUNET_SCHEDULER_shutdown ();
2669 return; 2683 return;
2670 } 2684 }
2671 GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key); 2685 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
2672 /* start reading */ 2686 /* start reading */
2673 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 2687 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
2674 udp_sock, 2688 udp_sock,
2675 &sock_read, 2689 &sock_read,
2676 NULL);
2677 ch = GNUNET_TRANSPORT_communicator_connect(cfg,
2678 COMMUNICATOR_CONFIG_SECTION,
2679 COMMUNICATOR_ADDRESS_PREFIX,
2680 GNUNET_TRANSPORT_CC_UNRELIABLE,
2681 &mq_init,
2682 NULL,
2683 &enc_notify_cb,
2684 NULL); 2690 NULL);
2691 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
2692 COMMUNICATOR_CONFIG_SECTION,
2693 COMMUNICATOR_ADDRESS_PREFIX,
2694 GNUNET_TRANSPORT_CC_UNRELIABLE,
2695 &mq_init,
2696 NULL,
2697 &enc_notify_cb,
2698 NULL);
2685 if (NULL == ch) 2699 if (NULL == ch)
2686 { 2700 {
2687 GNUNET_break(0); 2701 GNUNET_break (0);
2688 GNUNET_SCHEDULER_shutdown(); 2702 GNUNET_SCHEDULER_shutdown ();
2689 return; 2703 return;
2690 } 2704 }
2691 ah = GNUNET_TRANSPORT_application_init(cfg); 2705 ah = GNUNET_TRANSPORT_application_init (cfg);
2692 if (NULL == ah) 2706 if (NULL == ah)
2693 { 2707 {
2694 GNUNET_break(0); 2708 GNUNET_break (0);
2695 GNUNET_SCHEDULER_shutdown(); 2709 GNUNET_SCHEDULER_shutdown ();
2696 return; 2710 return;
2697 } 2711 }
2698 /* start broadcasting */ 2712 /* start broadcasting */
2699 if (GNUNET_YES != 2713 if (GNUNET_YES !=
2700 GNUNET_CONFIGURATION_get_value_yesno(cfg, 2714 GNUNET_CONFIGURATION_get_value_yesno (cfg,
2701 COMMUNICATOR_CONFIG_SECTION, 2715 COMMUNICATOR_CONFIG_SECTION,
2702 "DISABLE_BROADCAST")) 2716 "DISABLE_BROADCAST"))
2703 { 2717 {
2704 broadcast_task = GNUNET_SCHEDULER_add_now(&do_broadcast, NULL); 2718 broadcast_task = GNUNET_SCHEDULER_add_now (&do_broadcast, NULL);
2705 } 2719 }
2706 nat = GNUNET_NAT_register(cfg, 2720 nat = GNUNET_NAT_register (cfg,
2707 COMMUNICATOR_CONFIG_SECTION, 2721 COMMUNICATOR_CONFIG_SECTION,
2708 IPPROTO_UDP, 2722 IPPROTO_UDP,
2709 1 /* one address */, 2723 1 /* one address */,
2710 (const struct sockaddr **)&in, 2724 (const struct sockaddr **) &in,
2711 &in_len, 2725 &in_len,
2712 &nat_address_cb, 2726 &nat_address_cb,
2713 NULL /* FIXME: support reversal: #5529 */, 2727 NULL /* FIXME: support reversal: #5529 */,
2714 NULL /* closure */); 2728 NULL /* closure */);
2715} 2729}
2716 2730
2717 2731
@@ -2723,26 +2737,26 @@ run(void *cls,
2723 * @return 0 ok, 1 on error 2737 * @return 0 ok, 1 on error
2724 */ 2738 */
2725int 2739int
2726main(int argc, char *const *argv) 2740main (int argc, char *const *argv)
2727{ 2741{
2728 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 2742 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
2729 GNUNET_GETOPT_OPTION_END 2743 GNUNET_GETOPT_OPTION_END
2730 }; 2744 };
2731 int ret; 2745 int ret;
2732 2746
2733 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 2747 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
2734 return 2; 2748 return 2;
2735 2749
2736 ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc, 2750 ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
2737 argv, 2751 argv,
2738 "gnunet-communicator-udp", 2752 "gnunet-communicator-udp",
2739 _("GNUnet UDP communicator"), 2753 _ ("GNUnet UDP communicator"),
2740 options, 2754 options,
2741 &run, 2755 &run,
2742 NULL)) 2756 NULL))
2743 ? 0 2757 ? 0
2744 : 1; 2758 : 1;
2745 GNUNET_free((void *)argv); 2759 GNUNET_free ((void *) argv);
2746 return ret; 2760 return ret;
2747} 2761}
2748 2762
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
64/** 64/**
65 * UNIX Message-Packet header. 65 * UNIX Message-Packet header.
66 */ 66 */
67struct UNIXMessage { 67struct UNIXMessage
68{
68 /** 69 /**
69 * Message header. 70 * Message header.
70 */ 71 */
@@ -82,7 +83,8 @@ GNUNET_NETWORK_STRUCT_END
82/** 83/**
83 * Handle for a queue. 84 * Handle for a queue.
84 */ 85 */
85struct Queue { 86struct Queue
87{
86 /** 88 /**
87 * Queues with pending messages (!) are kept in a DLL. 89 * Queues with pending messages (!) are kept in a DLL.
88 */ 90 */
@@ -205,37 +207,37 @@ static struct GNUNET_TRANSPORT_AddressIdentifier *ai;
205 * @param queue queue to close down 207 * @param queue queue to close down
206 */ 208 */
207static void 209static void
208queue_destroy(struct Queue *queue) 210queue_destroy (struct Queue *queue)
209{ 211{
210 struct GNUNET_MQ_Handle *mq; 212 struct GNUNET_MQ_Handle *mq;
211 213
212 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
213 "Disconnecting queue for peer `%s'\n", 215 "Disconnecting queue for peer `%s'\n",
214 GNUNET_i2s(&queue->target)); 216 GNUNET_i2s (&queue->target));
215 if (0 != queue->bytes_in_queue) 217 if (0 != queue->bytes_in_queue)
216 { 218 {
217 GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue); 219 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue);
218 queue->bytes_in_queue = 0; 220 queue->bytes_in_queue = 0;
219 } 221 }
220 if (NULL != (mq = queue->mq)) 222 if (NULL != (mq = queue->mq))
221 { 223 {
222 queue->mq = NULL; 224 queue->mq = NULL;
223 GNUNET_MQ_destroy(mq); 225 GNUNET_MQ_destroy (mq);
224 } 226 }
225 GNUNET_assert( 227 GNUNET_assert (
226 GNUNET_YES == 228 GNUNET_YES ==
227 GNUNET_CONTAINER_multipeermap_remove(queue_map, &queue->target, queue)); 229 GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue));
228 GNUNET_STATISTICS_set(stats, 230 GNUNET_STATISTICS_set (stats,
229 "# queues active", 231 "# queues active",
230 GNUNET_CONTAINER_multipeermap_size(queue_map), 232 GNUNET_CONTAINER_multipeermap_size (queue_map),
231 GNUNET_NO); 233 GNUNET_NO);
232 if (NULL != queue->timeout_task) 234 if (NULL != queue->timeout_task)
233 { 235 {
234 GNUNET_SCHEDULER_cancel(queue->timeout_task); 236 GNUNET_SCHEDULER_cancel (queue->timeout_task);
235 queue->timeout_task = NULL; 237 queue->timeout_task = NULL;
236 } 238 }
237 GNUNET_free(queue->address); 239 GNUNET_free (queue->address);
238 GNUNET_free(queue); 240 GNUNET_free (queue);
239} 241}
240 242
241 243
@@ -245,28 +247,28 @@ queue_destroy(struct Queue *queue)
245 * @param cls the `struct Queue *` to disconnect 247 * @param cls the `struct Queue *` to disconnect
246 */ 248 */
247static void 249static void
248queue_timeout(void *cls) 250queue_timeout (void *cls)
249{ 251{
250 struct Queue *queue = cls; 252 struct Queue *queue = cls;
251 struct GNUNET_TIME_Relative left; 253 struct GNUNET_TIME_Relative left;
252 254
253 queue->timeout_task = NULL; 255 queue->timeout_task = NULL;
254 left = GNUNET_TIME_absolute_get_remaining(queue->timeout); 256 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
255 if (0 != left.rel_value_us) 257 if (0 != left.rel_value_us)
256 { 258 {
257 /* not actually our turn yet, but let's at least update 259 /* not actually our turn yet, but let's at least update
258 the monitor, it may think we're about to die ... */ 260 the monitor, it may think we're about to die ... */
259 queue->timeout_task = 261 queue->timeout_task =
260 GNUNET_SCHEDULER_add_delayed(left, &queue_timeout, queue); 262 GNUNET_SCHEDULER_add_delayed (left, &queue_timeout, queue);
261 return; 263 return;
262 } 264 }
263 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "Queue %p was idle for %s, disconnecting\n", 266 "Queue %p was idle for %s, disconnecting\n",
265 queue, 267 queue,
266 GNUNET_STRINGS_relative_time_to_string( 268 GNUNET_STRINGS_relative_time_to_string (
267 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 269 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
268 GNUNET_YES)); 270 GNUNET_YES));
269 queue_destroy(queue); 271 queue_destroy (queue);
270} 272}
271 273
272 274
@@ -278,11 +280,11 @@ queue_timeout(void *cls)
278 * @param queue queue for which the timeout should be rescheduled 280 * @param queue queue for which the timeout should be rescheduled
279 */ 281 */
280static void 282static void
281reschedule_queue_timeout(struct Queue *queue) 283reschedule_queue_timeout (struct Queue *queue)
282{ 284{
283 GNUNET_assert(NULL != queue->timeout_task); 285 GNUNET_assert (NULL != queue->timeout_task);
284 queue->timeout = 286 queue->timeout =
285 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 287 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
286} 288}
287 289
288 290
@@ -295,22 +297,22 @@ reschedule_queue_timeout(struct Queue *queue)
295 * @return converted unix path 297 * @return converted unix path
296 */ 298 */
297static struct sockaddr_un * 299static struct sockaddr_un *
298unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len) 300unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
299{ 301{
300 struct sockaddr_un *un; 302 struct sockaddr_un *un;
301 size_t slen; 303 size_t slen;
302 304
303 GNUNET_assert(0 < strlen(unixpath)); /* sanity check */ 305 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
304 un = GNUNET_new(struct sockaddr_un); 306 un = GNUNET_new (struct sockaddr_un);
305 un->sun_family = AF_UNIX; 307 un->sun_family = AF_UNIX;
306 slen = strlen(unixpath); 308 slen = strlen (unixpath);
307 if (slen >= sizeof(un->sun_path)) 309 if (slen >= sizeof(un->sun_path))
308 slen = sizeof(un->sun_path) - 1; 310 slen = sizeof(un->sun_path) - 1;
309 GNUNET_memcpy(un->sun_path, unixpath, slen); 311 GNUNET_memcpy (un->sun_path, unixpath, slen);
310 un->sun_path[slen] = '\0'; 312 un->sun_path[slen] = '\0';
311 slen = sizeof(struct sockaddr_un); 313 slen = sizeof(struct sockaddr_un);
312#if HAVE_SOCKADDR_UN_SUN_LEN 314#if HAVE_SOCKADDR_UN_SUN_LEN
313 un->sun_len = (u_char)slen; 315 un->sun_len = (u_char) slen;
314#endif 316#endif
315 (*sock_len) = slen; 317 (*sock_len) = slen;
316 if ('@' == un->sun_path[0]) 318 if ('@' == un->sun_path[0])
@@ -322,7 +324,8 @@ unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len)
322/** 324/**
323 * Closure to #lookup_queue_it(). 325 * Closure to #lookup_queue_it().
324 */ 326 */
325struct LookupCtx { 327struct LookupCtx
328{
326 /** 329 /**
327 * Location to store the queue, if found. 330 * Location to store the queue, if found.
328 */ 331 */
@@ -349,17 +352,17 @@ struct LookupCtx {
349 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success 352 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
350 */ 353 */
351static int 354static int
352lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 355lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
353{ 356{
354 struct LookupCtx *lctx = cls; 357 struct LookupCtx *lctx = cls;
355 struct Queue *queue = value; 358 struct Queue *queue = value;
356 359
357 if ((queue->address_len = lctx->un_len) && 360 if ((queue->address_len = lctx->un_len) &&
358 (0 == memcmp(lctx->un, queue->address, queue->address_len))) 361 (0 == memcmp (lctx->un, queue->address, queue->address_len)))
359 { 362 {
360 lctx->res = queue; 363 lctx->res = queue;
361 return GNUNET_NO; 364 return GNUNET_NO;
362 } 365 }
363 return GNUNET_YES; 366 return GNUNET_YES;
364} 367}
365 368
@@ -372,18 +375,18 @@ lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
372 * @return NULL if queue was not found 375 * @return NULL if queue was not found
373 */ 376 */
374static struct Queue * 377static struct Queue *
375lookup_queue(const struct GNUNET_PeerIdentity *peer, 378lookup_queue (const struct GNUNET_PeerIdentity *peer,
376 const struct sockaddr_un *un, 379 const struct sockaddr_un *un,
377 socklen_t un_len) 380 socklen_t un_len)
378{ 381{
379 struct LookupCtx lctx; 382 struct LookupCtx lctx;
380 383
381 lctx.un = un; 384 lctx.un = un;
382 lctx.un_len = un_len; 385 lctx.un_len = un_len;
383 GNUNET_CONTAINER_multipeermap_get_multiple(queue_map, 386 GNUNET_CONTAINER_multipeermap_get_multiple (queue_map,
384 peer, 387 peer,
385 &lookup_queue_it, 388 &lookup_queue_it,
386 &lctx); 389 &lctx);
387 return lctx.res; 390 return lctx.res;
388} 391}
389 392
@@ -395,105 +398,105 @@ lookup_queue(const struct GNUNET_PeerIdentity *peer,
395 * @param cls NULL 398 * @param cls NULL
396 */ 399 */
397static void 400static void
398select_write_cb(void *cls) 401select_write_cb (void *cls)
399{ 402{
400 struct Queue *queue = queue_tail; 403 struct Queue *queue = queue_tail;
401 const struct GNUNET_MessageHeader *msg = queue->msg; 404 const struct GNUNET_MessageHeader *msg = queue->msg;
402 size_t msg_size = ntohs(msg->size); 405 size_t msg_size = ntohs (msg->size);
403 ssize_t sent; 406 ssize_t sent;
404 407
405 /* take queue of the ready list */ 408 /* take queue of the ready list */
406 write_task = NULL; 409 write_task = NULL;
407 GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue); 410 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue);
408 if (NULL != queue_head) 411 if (NULL != queue_head)
409 write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 412 write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
410 unix_sock, 413 unix_sock,
411 &select_write_cb, 414 &select_write_cb,
412 NULL); 415 NULL);
413 416
414 /* send 'msg' */ 417 /* send 'msg' */
415 queue->msg = NULL; 418 queue->msg = NULL;
416 GNUNET_MQ_impl_send_continue(queue->mq); 419 GNUNET_MQ_impl_send_continue (queue->mq);
417resend: 420resend:
418 /* Send the data */ 421 /* Send the data */
419 sent = GNUNET_NETWORK_socket_sendto(unix_sock, 422 sent = GNUNET_NETWORK_socket_sendto (unix_sock,
420 msg, 423 msg,
421 msg_size, 424 msg_size,
422 (const struct sockaddr *)queue->address, 425 (const struct sockaddr *) queue->address,
423 queue->address_len); 426 queue->address_len);
424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "UNIX transmitted message to %s (%d/%u: %s)\n", 428 "UNIX transmitted message to %s (%d/%u: %s)\n",
426 GNUNET_i2s(&queue->target), 429 GNUNET_i2s (&queue->target),
427 (int)sent, 430 (int) sent,
428 (unsigned int)msg_size, 431 (unsigned int) msg_size,
429 (sent < 0) ? strerror(errno) : "ok"); 432 (sent < 0) ? strerror (errno) : "ok");
430 if (-1 != sent) 433 if (-1 != sent)
431 { 434 {
432 GNUNET_STATISTICS_update(stats, 435 GNUNET_STATISTICS_update (stats,
433 "# bytes sent", 436 "# bytes sent",
434 (long long)sent, 437 (long long) sent,
435 GNUNET_NO); 438 GNUNET_NO);
436 reschedule_queue_timeout(queue); 439 reschedule_queue_timeout (queue);
437 return; /* all good */ 440 return; /* all good */
438 } 441 }
439 GNUNET_STATISTICS_update(stats, 442 GNUNET_STATISTICS_update (stats,
440 "# network transmission failures", 443 "# network transmission failures",
441 1, 444 1,
442 GNUNET_NO); 445 GNUNET_NO);
443 switch (errno) 446 switch (errno)
444 { 447 {
445 case EAGAIN: 448 case EAGAIN:
446 case ENOBUFS: 449 case ENOBUFS:
447 /* We should retry later... */ 450 /* We should retry later... */
448 GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "send"); 451 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
449 return; 452 return;
450 453
451 case EMSGSIZE: { 454 case EMSGSIZE: {
452 socklen_t size = 0; 455 socklen_t size = 0;
453 socklen_t len = sizeof(size); 456 socklen_t len = sizeof(size);
454 457
455 GNUNET_NETWORK_socket_getsockopt(unix_sock, 458 GNUNET_NETWORK_socket_getsockopt (unix_sock,
456 SOL_SOCKET, 459 SOL_SOCKET,
457 SO_SNDBUF, 460 SO_SNDBUF,
458 &size, 461 &size,
459 &len); 462 &len);
460 if (size > ntohs(msg->size)) 463 if (size > ntohs (msg->size))
461 { 464 {
462 /* Buffer is bigger than message: error, no retry 465 /* Buffer is bigger than message: error, no retry
463 * This should never happen!*/ 466 * This should never happen!*/
464 GNUNET_break(0); 467 GNUNET_break (0);
465 return; 468 return;
466 } 469 }
467 GNUNET_log( 470 GNUNET_log (
468 GNUNET_ERROR_TYPE_DEBUG, 471 GNUNET_ERROR_TYPE_DEBUG,
469 "Trying to increase socket buffer size from %u to %u for message size %u\n", 472 "Trying to increase socket buffer size from %u to %u for message size %u\n",
470 (unsigned int)size, 473 (unsigned int) size,
471 (unsigned int)((msg_size / 1000) + 2) * 1000, 474 (unsigned int) ((msg_size / 1000) + 2) * 1000,
472 (unsigned int)msg_size); 475 (unsigned int) msg_size);
473 size = ((msg_size / 1000) + 2) * 1000; 476 size = ((msg_size / 1000) + 2) * 1000;
474 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock, 477 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock,
475 SOL_SOCKET, 478 SOL_SOCKET,
476 SO_SNDBUF, 479 SO_SNDBUF,
477 &size, 480 &size,
478 sizeof(size))) 481 sizeof(size)))
479 goto resend; /* Increased buffer size, retry sending */ 482 goto resend; /* Increased buffer size, retry sending */
480 /* Ok, then just try very modest increase */ 483 /* Ok, then just try very modest increase */
481 size = msg_size; 484 size = msg_size;
482 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock, 485 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock,
483 SOL_SOCKET, 486 SOL_SOCKET,
484 SO_SNDBUF, 487 SO_SNDBUF,
485 &size, 488 &size,
486 sizeof(size))) 489 sizeof(size)))
487 goto resend; /* Increased buffer size, retry sending */ 490 goto resend; /* Increased buffer size, retry sending */
488 /* Could not increase buffer size: error, no retry */ 491 /* Could not increase buffer size: error, no retry */
489 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt"); 492 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
490 return; 493 return;
491 } 494 }
492 495
493 default: 496 default:
494 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "send"); 497 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "send");
495 return; 498 return;
496 } 499 }
497} 500}
498 501
499 502
@@ -506,22 +509,22 @@ resend:
506 * @param impl_state our `struct Queue` 509 * @param impl_state our `struct Queue`
507 */ 510 */
508static void 511static void
509mq_send(struct GNUNET_MQ_Handle *mq, 512mq_send (struct GNUNET_MQ_Handle *mq,
510 const struct GNUNET_MessageHeader *msg, 513 const struct GNUNET_MessageHeader *msg,
511 void *impl_state) 514 void *impl_state)
512{ 515{
513 struct Queue *queue = impl_state; 516 struct Queue *queue = impl_state;
514 517
515 GNUNET_assert(mq == queue->mq); 518 GNUNET_assert (mq == queue->mq);
516 GNUNET_assert(NULL == queue->msg); 519 GNUNET_assert (NULL == queue->msg);
517 queue->msg = msg; 520 queue->msg = msg;
518 GNUNET_CONTAINER_DLL_insert(queue_head, queue_tail, queue); 521 GNUNET_CONTAINER_DLL_insert (queue_head, queue_tail, queue);
519 GNUNET_assert(NULL != unix_sock); 522 GNUNET_assert (NULL != unix_sock);
520 if (NULL == write_task) 523 if (NULL == write_task)
521 write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 524 write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
522 unix_sock, 525 unix_sock,
523 &select_write_cb, 526 &select_write_cb,
524 NULL); 527 NULL);
525} 528}
526 529
527 530
@@ -534,15 +537,15 @@ mq_send(struct GNUNET_MQ_Handle *mq,
534 * @param impl_state our `struct Queue` 537 * @param impl_state our `struct Queue`
535 */ 538 */
536static void 539static void
537mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) 540mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
538{ 541{
539 struct Queue *queue = impl_state; 542 struct Queue *queue = impl_state;
540 543
541 if (mq == queue->mq) 544 if (mq == queue->mq)
542 { 545 {
543 queue->mq = NULL; 546 queue->mq = NULL;
544 queue_destroy(queue); 547 queue_destroy (queue);
545 } 548 }
546} 549}
547 550
548 551
@@ -553,19 +556,19 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
553 * @param impl_state our `struct Queue` 556 * @param impl_state our `struct Queue`
554 */ 557 */
555static void 558static void
556mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) 559mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
557{ 560{
558 struct Queue *queue = impl_state; 561 struct Queue *queue = impl_state;
559 562
560 GNUNET_assert(NULL != queue->msg); 563 GNUNET_assert (NULL != queue->msg);
561 queue->msg = NULL; 564 queue->msg = NULL;
562 GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue); 565 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue);
563 GNUNET_assert(NULL != write_task); 566 GNUNET_assert (NULL != write_task);
564 if (NULL == queue_head) 567 if (NULL == queue_head)
565 { 568 {
566 GNUNET_SCHEDULER_cancel(write_task); 569 GNUNET_SCHEDULER_cancel (write_task);
567 write_task = NULL; 570 write_task = NULL;
568 } 571 }
569} 572}
570 573
571 574
@@ -579,15 +582,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
579 * @param error error code 582 * @param error error code
580 */ 583 */
581static void 584static void
582mq_error(void *cls, enum GNUNET_MQ_Error error) 585mq_error (void *cls, enum GNUNET_MQ_Error error)
583{ 586{
584 struct Queue *queue = cls; 587 struct Queue *queue = cls;
585 588
586 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 589 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
587 "UNIX MQ error in queue to %s: %d\n", 590 "UNIX MQ error in queue to %s: %d\n",
588 GNUNET_i2s(&queue->target), 591 GNUNET_i2s (&queue->target),
589 (int)error); 592 (int) error);
590 queue_destroy(queue); 593 queue_destroy (queue);
591} 594}
592 595
593 596
@@ -602,60 +605,60 @@ mq_error(void *cls, enum GNUNET_MQ_Error error)
602 * @return the queue or NULL of max connections exceeded 605 * @return the queue or NULL of max connections exceeded
603 */ 606 */
604static struct Queue * 607static struct Queue *
605setup_queue(const struct GNUNET_PeerIdentity *target, 608setup_queue (const struct GNUNET_PeerIdentity *target,
606 enum GNUNET_TRANSPORT_ConnectionStatus cs, 609 enum GNUNET_TRANSPORT_ConnectionStatus cs,
607 const struct sockaddr_un *un, 610 const struct sockaddr_un *un,
608 socklen_t un_len) 611 socklen_t un_len)
609{ 612{
610 struct Queue *queue; 613 struct Queue *queue;
611 614
612 queue = GNUNET_new(struct Queue); 615 queue = GNUNET_new (struct Queue);
613 queue->target = *target; 616 queue->target = *target;
614 queue->address = GNUNET_memdup(un, un_len); 617 queue->address = GNUNET_memdup (un, un_len);
615 queue->address_len = un_len; 618 queue->address_len = un_len;
616 (void)GNUNET_CONTAINER_multipeermap_put( 619 (void) GNUNET_CONTAINER_multipeermap_put (
617 queue_map, 620 queue_map,
618 &queue->target, 621 &queue->target,
619 queue, 622 queue,
620 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 623 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
621 GNUNET_STATISTICS_set(stats, 624 GNUNET_STATISTICS_set (stats,
622 "# queues active", 625 "# queues active",
623 GNUNET_CONTAINER_multipeermap_size(queue_map), 626 GNUNET_CONTAINER_multipeermap_size (queue_map),
624 GNUNET_NO); 627 GNUNET_NO);
625 queue->timeout = 628 queue->timeout =
626 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 629 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
627 queue->timeout_task = 630 queue->timeout_task =
628 GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 631 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
629 &queue_timeout, 632 &queue_timeout,
630 queue); 633 queue);
631 queue->mq = GNUNET_MQ_queue_for_callbacks(&mq_send, 634 queue->mq = GNUNET_MQ_queue_for_callbacks (&mq_send,
632 &mq_destroy, 635 &mq_destroy,
633 &mq_cancel, 636 &mq_cancel,
634 queue, 637 queue,
635 NULL, 638 NULL,
636 &mq_error, 639 &mq_error,
637 queue); 640 queue);
638 { 641 {
639 char *foreign_addr; 642 char *foreign_addr;
640 643
641 if ('\0' == un->sun_path[0]) 644 if ('\0' == un->sun_path[0])
642 GNUNET_asprintf(&foreign_addr, 645 GNUNET_asprintf (&foreign_addr,
643 "%s-@%s", 646 "%s-@%s",
644 COMMUNICATOR_ADDRESS_PREFIX, 647 COMMUNICATOR_ADDRESS_PREFIX,
645 &un->sun_path[1]); 648 &un->sun_path[1]);
646 else 649 else
647 GNUNET_asprintf(&foreign_addr, 650 GNUNET_asprintf (&foreign_addr,
648 "%s-%s", 651 "%s-%s",
649 COMMUNICATOR_ADDRESS_PREFIX, 652 COMMUNICATOR_ADDRESS_PREFIX,
650 un->sun_path); 653 un->sun_path);
651 queue->qh = GNUNET_TRANSPORT_communicator_mq_add(ch, 654 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch,
652 &queue->target, 655 &queue->target,
653 foreign_addr, 656 foreign_addr,
654 UNIX_MTU, 657 UNIX_MTU,
655 GNUNET_NT_LOOPBACK, 658 GNUNET_NT_LOOPBACK,
656 cs, 659 cs,
657 queue->mq); 660 queue->mq);
658 GNUNET_free(foreign_addr); 661 GNUNET_free (foreign_addr);
659 } 662 }
660 return queue; 663 return queue;
661} 664}
@@ -669,7 +672,7 @@ setup_queue(const struct GNUNET_PeerIdentity *target,
669 * @param cls NULL 672 * @param cls NULL
670 */ 673 */
671static void 674static void
672select_read_cb(void *cls); 675select_read_cb (void *cls);
673 676
674 677
675/** 678/**
@@ -680,21 +683,21 @@ select_read_cb(void *cls);
680 * @param success #GNUNET_OK on success 683 * @param success #GNUNET_OK on success
681 */ 684 */
682static void 685static void
683receive_complete_cb(void *cls, int success) 686receive_complete_cb (void *cls, int success)
684{ 687{
685 (void)cls; 688 (void) cls;
686 delivering_messages--; 689 delivering_messages--;
687 if (GNUNET_OK != success) 690 if (GNUNET_OK != success)
688 GNUNET_STATISTICS_update(stats, 691 GNUNET_STATISTICS_update (stats,
689 "# transport transmission failures", 692 "# transport transmission failures",
690 1, 693 1,
691 GNUNET_NO); 694 GNUNET_NO);
692 GNUNET_assert(NULL != unix_sock); 695 GNUNET_assert (NULL != unix_sock);
693 if ((NULL == read_task) && (delivering_messages < max_queue_length)) 696 if ((NULL == read_task) && (delivering_messages < max_queue_length))
694 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 697 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
695 unix_sock, 698 unix_sock,
696 &select_read_cb, 699 &select_read_cb,
697 NULL); 700 NULL);
698} 701}
699 702
700 703
@@ -706,7 +709,7 @@ receive_complete_cb(void *cls, int success)
706 * @param cls NULL 709 * @param cls NULL
707 */ 710 */
708static void 711static void
709select_read_cb(void *cls) 712select_read_cb (void *cls)
710{ 713{
711 char buf[65536] GNUNET_ALIGN; 714 char buf[65536] GNUNET_ALIGN;
712 struct Queue *queue; 715 struct Queue *queue;
@@ -716,93 +719,93 @@ select_read_cb(void *cls)
716 ssize_t ret; 719 ssize_t ret;
717 uint16_t msize; 720 uint16_t msize;
718 721
719 GNUNET_assert(NULL != unix_sock); 722 GNUNET_assert (NULL != unix_sock);
720 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 723 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
721 unix_sock, 724 unix_sock,
722 &select_read_cb, 725 &select_read_cb,
723 NULL); 726 NULL);
724 addrlen = sizeof(un); 727 addrlen = sizeof(un);
725 memset(&un, 0, sizeof(un)); 728 memset (&un, 0, sizeof(un));
726 ret = GNUNET_NETWORK_socket_recvfrom(unix_sock, 729 ret = GNUNET_NETWORK_socket_recvfrom (unix_sock,
727 buf, 730 buf,
728 sizeof(buf), 731 sizeof(buf),
729 (struct sockaddr *)&un, 732 (struct sockaddr *) &un,
730 &addrlen); 733 &addrlen);
731 if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno))) 734 if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno)))
732 return; 735 return;
733 if (-1 == ret) 736 if (-1 == ret)
734 { 737 {
735 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom"); 738 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
736 return; 739 return;
737 } 740 }
738 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
739 "Read %d bytes from socket %s\n", 742 "Read %d bytes from socket %s\n",
740 (int)ret, 743 (int) ret,
741 un.sun_path); 744 un.sun_path);
742 GNUNET_assert(AF_UNIX == (un.sun_family)); 745 GNUNET_assert (AF_UNIX == (un.sun_family));
743 msg = (struct UNIXMessage *)buf; 746 msg = (struct UNIXMessage *) buf;
744 msize = ntohs(msg->header.size); 747 msize = ntohs (msg->header.size);
745 if ((msize < sizeof(struct UNIXMessage)) || (msize > ret)) 748 if ((msize < sizeof(struct UNIXMessage)) || (msize > ret))
746 { 749 {
747 GNUNET_break_op(0); 750 GNUNET_break_op (0);
748 return; 751 return;
749 } 752 }
750 queue = lookup_queue(&msg->sender, &un, addrlen); 753 queue = lookup_queue (&msg->sender, &un, addrlen);
751 if (NULL == queue) 754 if (NULL == queue)
752 queue = 755 queue =
753 setup_queue(&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen); 756 setup_queue (&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen);
754 else 757 else
755 reschedule_queue_timeout(queue); 758 reschedule_queue_timeout (queue);
756 if (NULL == queue) 759 if (NULL == queue)
757 { 760 {
758 GNUNET_log( 761 GNUNET_log (
759 GNUNET_ERROR_TYPE_ERROR, 762 GNUNET_ERROR_TYPE_ERROR,
760 _( 763 _ (
761 "Maximum number of UNIX connections exceeded, dropping incoming message\n")); 764 "Maximum number of UNIX connections exceeded, dropping incoming message\n"));
762 return; 765 return;
763 } 766 }
764 767
765 { 768 {
766 uint16_t offset = 0; 769 uint16_t offset = 0;
767 uint16_t tsize = msize - sizeof(struct UNIXMessage); 770 uint16_t tsize = msize - sizeof(struct UNIXMessage);
768 const char *msgbuf = (const char *)&msg[1]; 771 const char *msgbuf = (const char *) &msg[1];
769 772
770 while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize) 773 while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize)
774 {
775 const struct GNUNET_MessageHeader *currhdr;
776 struct GNUNET_MessageHeader al_hdr;
777 uint16_t csize;
778
779 currhdr = (const struct GNUNET_MessageHeader *) &msgbuf[offset];
780 /* ensure aligned access */
781 memcpy (&al_hdr, currhdr, sizeof(al_hdr));
782 csize = ntohs (al_hdr.size);
783 if ((csize < sizeof(struct GNUNET_MessageHeader)) ||
784 (csize > tsize - offset))
771 { 785 {
772 const struct GNUNET_MessageHeader *currhdr; 786 GNUNET_break_op (0);
773 struct GNUNET_MessageHeader al_hdr; 787 break;
774 uint16_t csize;
775
776 currhdr = (const struct GNUNET_MessageHeader *)&msgbuf[offset];
777 /* ensure aligned access */
778 memcpy(&al_hdr, currhdr, sizeof(al_hdr));
779 csize = ntohs(al_hdr.size);
780 if ((csize < sizeof(struct GNUNET_MessageHeader)) ||
781 (csize > tsize - offset))
782 {
783 GNUNET_break_op(0);
784 break;
785 }
786 ret = GNUNET_TRANSPORT_communicator_receive(ch,
787 &msg->sender,
788 currhdr,
789 GNUNET_TIME_UNIT_FOREVER_REL,
790 &receive_complete_cb,
791 NULL);
792 if (GNUNET_SYSERR == ret)
793 return; /* transport not up */
794 if (GNUNET_NO == ret)
795 break;
796 delivering_messages++;
797 offset += csize;
798 } 788 }
789 ret = GNUNET_TRANSPORT_communicator_receive (ch,
790 &msg->sender,
791 currhdr,
792 GNUNET_TIME_UNIT_FOREVER_REL,
793 &receive_complete_cb,
794 NULL);
795 if (GNUNET_SYSERR == ret)
796 return; /* transport not up */
797 if (GNUNET_NO == ret)
798 break;
799 delivering_messages++;
800 offset += csize;
801 }
799 } 802 }
800 if (delivering_messages >= max_queue_length) 803 if (delivering_messages >= max_queue_length)
801 { 804 {
802 /* we should try to apply 'back pressure' */ 805 /* we should try to apply 'back pressure' */
803 GNUNET_SCHEDULER_cancel(read_task); 806 GNUNET_SCHEDULER_cancel (read_task);
804 read_task = NULL; 807 read_task = NULL;
805 } 808 }
806} 809}
807 810
808 811
@@ -824,43 +827,43 @@ select_read_cb(void *cls)
824 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid 827 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid
825 */ 828 */
826static int 829static int
827mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) 830mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
828{ 831{
829 struct Queue *queue; 832 struct Queue *queue;
830 const char *path; 833 const char *path;
831 struct sockaddr_un *un; 834 struct sockaddr_un *un;
832 socklen_t un_len; 835 socklen_t un_len;
833 836
834 (void)cls; 837 (void) cls;
835 if (0 != strncmp(address, 838 if (0 != strncmp (address,
836 COMMUNICATOR_ADDRESS_PREFIX "-", 839 COMMUNICATOR_ADDRESS_PREFIX "-",
837 strlen(COMMUNICATOR_ADDRESS_PREFIX "-"))) 840 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
838 { 841 {
839 GNUNET_break_op(0); 842 GNUNET_break_op (0);
840 return GNUNET_SYSERR; 843 return GNUNET_SYSERR;
841 } 844 }
842 path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")]; 845 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
843 un = unix_address_to_sockaddr(path, &un_len); 846 un = unix_address_to_sockaddr (path, &un_len);
844 queue = lookup_queue(peer, un, un_len); 847 queue = lookup_queue (peer, un, un_len);
845 if (NULL != queue) 848 if (NULL != queue)
846 { 849 {
847 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 850 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
848 "Address `%s' for %s ignored, queue exists\n", 851 "Address `%s' for %s ignored, queue exists\n",
849 path, 852 path,
850 GNUNET_i2s(peer)); 853 GNUNET_i2s (peer));
851 GNUNET_free(un); 854 GNUNET_free (un);
852 return GNUNET_OK; 855 return GNUNET_OK;
853 } 856 }
854 queue = setup_queue(peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len); 857 queue = setup_queue (peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len);
855 GNUNET_free(un); 858 GNUNET_free (un);
856 if (NULL == queue) 859 if (NULL == queue)
857 { 860 {
858 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 861 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
859 "Failed to setup queue to %s at `%s'\n", 862 "Failed to setup queue to %s at `%s'\n",
860 GNUNET_i2s(peer), 863 GNUNET_i2s (peer),
861 path); 864 path);
862 return GNUNET_NO; 865 return GNUNET_NO;
863 } 866 }
864 return GNUNET_OK; 867 return GNUNET_OK;
865} 868}
866 869
@@ -874,15 +877,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
874 * @return #GNUNET_OK to continue to iterate 877 * @return #GNUNET_OK to continue to iterate
875 */ 878 */
876static int 879static int
877get_queue_delete_it(void *cls, 880get_queue_delete_it (void *cls,
878 const struct GNUNET_PeerIdentity *target, 881 const struct GNUNET_PeerIdentity *target,
879 void *value) 882 void *value)
880{ 883{
881 struct Queue *queue = value; 884 struct Queue *queue = value;
882 885
883 (void)cls; 886 (void) cls;
884 (void)target; 887 (void) target;
885 queue_destroy(queue); 888 queue_destroy (queue);
886 return GNUNET_OK; 889 return GNUNET_OK;
887} 890}
888 891
@@ -893,40 +896,40 @@ get_queue_delete_it(void *cls,
893 * @param cls NULL (always) 896 * @param cls NULL (always)
894 */ 897 */
895static void 898static void
896do_shutdown(void *cls) 899do_shutdown (void *cls)
897{ 900{
898 if (NULL != read_task) 901 if (NULL != read_task)
899 { 902 {
900 GNUNET_SCHEDULER_cancel(read_task); 903 GNUNET_SCHEDULER_cancel (read_task);
901 read_task = NULL; 904 read_task = NULL;
902 } 905 }
903 if (NULL != write_task) 906 if (NULL != write_task)
904 { 907 {
905 GNUNET_SCHEDULER_cancel(write_task); 908 GNUNET_SCHEDULER_cancel (write_task);
906 write_task = NULL; 909 write_task = NULL;
907 } 910 }
908 if (NULL != unix_sock) 911 if (NULL != unix_sock)
909 { 912 {
910 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(unix_sock)); 913 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (unix_sock));
911 unix_sock = NULL; 914 unix_sock = NULL;
912 } 915 }
913 GNUNET_CONTAINER_multipeermap_iterate(queue_map, &get_queue_delete_it, NULL); 916 GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL);
914 GNUNET_CONTAINER_multipeermap_destroy(queue_map); 917 GNUNET_CONTAINER_multipeermap_destroy (queue_map);
915 if (NULL != ai) 918 if (NULL != ai)
916 { 919 {
917 GNUNET_TRANSPORT_communicator_address_remove(ai); 920 GNUNET_TRANSPORT_communicator_address_remove (ai);
918 ai = NULL; 921 ai = NULL;
919 } 922 }
920 if (NULL != ch) 923 if (NULL != ch)
921 { 924 {
922 GNUNET_TRANSPORT_communicator_disconnect(ch); 925 GNUNET_TRANSPORT_communicator_disconnect (ch);
923 ch = NULL; 926 ch = NULL;
924 } 927 }
925 if (NULL != stats) 928 if (NULL != stats)
926 { 929 {
927 GNUNET_STATISTICS_destroy(stats, GNUNET_NO); 930 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
928 stats = NULL; 931 stats = NULL;
929 } 932 }
930} 933}
931 934
932 935
@@ -942,14 +945,14 @@ do_shutdown(void *cls)
942 * @param msg payload 945 * @param msg payload
943 */ 946 */
944static void 947static void
945enc_notify_cb(void *cls, 948enc_notify_cb (void *cls,
946 const struct GNUNET_PeerIdentity *sender, 949 const struct GNUNET_PeerIdentity *sender,
947 const struct GNUNET_MessageHeader *msg) 950 const struct GNUNET_MessageHeader *msg)
948{ 951{
949 (void)cls; 952 (void) cls;
950 (void)sender; 953 (void) sender;
951 (void)msg; 954 (void) msg;
952 GNUNET_break_op(0); 955 GNUNET_break_op (0);
953} 956}
954 957
955 958
@@ -962,110 +965,110 @@ enc_notify_cb(void *cls,
962 * @param cfg configuration 965 * @param cfg configuration
963 */ 966 */
964static void 967static void
965run(void *cls, 968run (void *cls,
966 char *const *args, 969 char *const *args,
967 const char *cfgfile, 970 const char *cfgfile,
968 const struct GNUNET_CONFIGURATION_Handle *cfg) 971 const struct GNUNET_CONFIGURATION_Handle *cfg)
969{ 972{
970 char *unix_socket_path; 973 char *unix_socket_path;
971 struct sockaddr_un *un; 974 struct sockaddr_un *un;
972 socklen_t un_len; 975 socklen_t un_len;
973 char *my_addr; 976 char *my_addr;
974 977
975 (void)cls; 978 (void) cls;
976 979
977 if (GNUNET_OK != 980 if (GNUNET_OK !=
978 GNUNET_CONFIGURATION_get_value_filename(cfg, 981 GNUNET_CONFIGURATION_get_value_filename (cfg,
979 COMMUNICATOR_CONFIG_SECTION, 982 COMMUNICATOR_CONFIG_SECTION,
980 "UNIXPATH", 983 "UNIXPATH",
981 &unix_socket_path)) 984 &unix_socket_path))
982 { 985 {
983 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 986 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
984 COMMUNICATOR_CONFIG_SECTION, 987 COMMUNICATOR_CONFIG_SECTION,
985 "UNIXPATH"); 988 "UNIXPATH");
986 return; 989 return;
987 } 990 }
988 if (GNUNET_OK != 991 if (GNUNET_OK !=
989 GNUNET_CONFIGURATION_get_value_number(cfg, 992 GNUNET_CONFIGURATION_get_value_number (cfg,
990 COMMUNICATOR_CONFIG_SECTION, 993 COMMUNICATOR_CONFIG_SECTION,
991 "MAX_QUEUE_LENGTH", 994 "MAX_QUEUE_LENGTH",
992 &max_queue_length)) 995 &max_queue_length))
993 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; 996 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
994 997
995 un = unix_address_to_sockaddr(unix_socket_path, &un_len); 998 un = unix_address_to_sockaddr (unix_socket_path, &un_len);
996 if (NULL == un) 999 if (NULL == un)
997 { 1000 {
998 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1001 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
999 "Failed to setup UNIX domain socket address with path `%s'\n", 1002 "Failed to setup UNIX domain socket address with path `%s'\n",
1000 unix_socket_path); 1003 unix_socket_path);
1001 GNUNET_free(unix_socket_path); 1004 GNUNET_free (unix_socket_path);
1002 return; 1005 return;
1003 } 1006 }
1004 unix_sock = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0); 1007 unix_sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1005 if (NULL == unix_sock) 1008 if (NULL == unix_sock)
1006 { 1009 {
1007 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); 1010 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1008 GNUNET_free(un); 1011 GNUNET_free (un);
1009 GNUNET_free(unix_socket_path); 1012 GNUNET_free (unix_socket_path);
1010 return; 1013 return;
1011 } 1014 }
1012 if (('\0' != un->sun_path[0]) && 1015 if (('\0' != un->sun_path[0]) &&
1013 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path))) 1016 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path)))
1014 { 1017 {
1015 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1018 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1016 _("Cannot create path to `%s'\n"), 1019 _ ("Cannot create path to `%s'\n"),
1017 un->sun_path); 1020 un->sun_path);
1018 GNUNET_NETWORK_socket_close(unix_sock); 1021 GNUNET_NETWORK_socket_close (unix_sock);
1019 unix_sock = NULL; 1022 unix_sock = NULL;
1020 GNUNET_free(un); 1023 GNUNET_free (un);
1021 GNUNET_free(unix_socket_path); 1024 GNUNET_free (unix_socket_path);
1022 return; 1025 return;
1023 } 1026 }
1024 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(unix_sock, 1027 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (unix_sock,
1025 (const struct sockaddr *)un, 1028 (const struct sockaddr *) un,
1026 un_len)) 1029 un_len))
1027 { 1030 {
1028 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path); 1031 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path);
1029 GNUNET_NETWORK_socket_close(unix_sock); 1032 GNUNET_NETWORK_socket_close (unix_sock);
1030 unix_sock = NULL; 1033 unix_sock = NULL;
1031 GNUNET_free(un); 1034 GNUNET_free (un);
1032 GNUNET_free(unix_socket_path); 1035 GNUNET_free (unix_socket_path);
1033 return; 1036 return;
1034 } 1037 }
1035 GNUNET_free(un); 1038 GNUNET_free (un);
1036 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path); 1039 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path);
1037 stats = GNUNET_STATISTICS_create("C-UNIX", cfg); 1040 stats = GNUNET_STATISTICS_create ("C-UNIX", cfg);
1038 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 1041 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
1039 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 1042 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1040 unix_sock, 1043 unix_sock,
1041 &select_read_cb, 1044 &select_read_cb,
1042 NULL);
1043 queue_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
1044 ch = GNUNET_TRANSPORT_communicator_connect(cfg,
1045 COMMUNICATOR_CONFIG_SECTION,
1046 COMMUNICATOR_ADDRESS_PREFIX,
1047 GNUNET_TRANSPORT_CC_RELIABLE,
1048 &mq_init,
1049 NULL,
1050 &enc_notify_cb,
1051 NULL); 1045 NULL);
1046 queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1047 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
1048 COMMUNICATOR_CONFIG_SECTION,
1049 COMMUNICATOR_ADDRESS_PREFIX,
1050 GNUNET_TRANSPORT_CC_RELIABLE,
1051 &mq_init,
1052 NULL,
1053 &enc_notify_cb,
1054 NULL);
1052 if (NULL == ch) 1055 if (NULL == ch)
1053 { 1056 {
1054 GNUNET_break(0); 1057 GNUNET_break (0);
1055 GNUNET_SCHEDULER_shutdown(); 1058 GNUNET_SCHEDULER_shutdown ();
1056 GNUNET_free(unix_socket_path); 1059 GNUNET_free (unix_socket_path);
1057 return; 1060 return;
1058 } 1061 }
1059 GNUNET_asprintf(&my_addr, 1062 GNUNET_asprintf (&my_addr,
1060 "%s-%s", 1063 "%s-%s",
1061 COMMUNICATOR_ADDRESS_PREFIX, 1064 COMMUNICATOR_ADDRESS_PREFIX,
1062 unix_socket_path); 1065 unix_socket_path);
1063 GNUNET_free(unix_socket_path); 1066 GNUNET_free (unix_socket_path);
1064 ai = GNUNET_TRANSPORT_communicator_address_add(ch, 1067 ai = GNUNET_TRANSPORT_communicator_address_add (ch,
1065 my_addr, 1068 my_addr,
1066 GNUNET_NT_LOOPBACK, 1069 GNUNET_NT_LOOPBACK,
1067 GNUNET_TIME_UNIT_FOREVER_REL); 1070 GNUNET_TIME_UNIT_FOREVER_REL);
1068 GNUNET_free(my_addr); 1071 GNUNET_free (my_addr);
1069} 1072}
1070 1073
1071 1074
@@ -1077,27 +1080,27 @@ run(void *cls,
1077 * @return 0 ok, 1 on error 1080 * @return 0 ok, 1 on error
1078 */ 1081 */
1079int 1082int
1080main(int argc, char *const *argv) 1083main (int argc, char *const *argv)
1081{ 1084{
1082 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 1085 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1083 GNUNET_GETOPT_OPTION_END 1086 GNUNET_GETOPT_OPTION_END
1084 }; 1087 };
1085 int ret; 1088 int ret;
1086 1089
1087 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 1090 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1088 return 2; 1091 return 2;
1089 1092
1090 ret = (GNUNET_OK == 1093 ret = (GNUNET_OK ==
1091 GNUNET_PROGRAM_run(argc, 1094 GNUNET_PROGRAM_run (argc,
1092 argv, 1095 argv,
1093 "gnunet-communicator-unix", 1096 "gnunet-communicator-unix",
1094 _("GNUnet UNIX domain socket communicator"), 1097 _ ("GNUnet UNIX domain socket communicator"),
1095 options, 1098 options,
1096 &run, 1099 &run,
1097 NULL)) 1100 NULL))
1098 ? 0 1101 ? 0
1099 : 1; 1102 : 1;
1100 GNUNET_free((void *)argv); 1103 GNUNET_free ((void *) argv);
1101 return ret; 1104 return ret;
1102} 1105}
1103 1106
@@ -1108,11 +1111,11 @@ main(int argc, char *const *argv)
1108/** 1111/**
1109 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 1112 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1110 */ 1113 */
1111void __attribute__ ((constructor)) GNUNET_ARM_memory_init() 1114void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
1112{ 1115{
1113 mallopt(M_TRIM_THRESHOLD, 4 * 1024); 1116 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1114 mallopt(M_TOP_PAD, 1 * 1024); 1117 mallopt (M_TOP_PAD, 1 * 1024);
1115 malloc_trim(0); 1118 malloc_trim (0);
1116} 1119}
1117#endif 1120#endif
1118 1121
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 @@
69 * struct for storing the information of the hardware. There is only 69 * struct for storing the information of the hardware. There is only
70 * one of these. 70 * one of these.
71 */ 71 */
72struct HardwareInfos { 72struct HardwareInfos
73{
73 /** 74 /**
74 * Name of the interface, not necessarily 0-terminated (!). 75 * Name of the interface, not necessarily 0-terminated (!).
75 */ 76 */
@@ -94,7 +95,8 @@ struct HardwareInfos {
94/** 95/**
95 * IO buffer used for buffering data in transit (to wireless or to stdout). 96 * IO buffer used for buffering data in transit (to wireless or to stdout).
96 */ 97 */
97struct SendBuffer { 98struct SendBuffer
99{
98 /** 100 /**
99 * How many bytes of data are stored in 'buf' for transmission right now? 101 * How many bytes of data are stored in 'buf' for transmission right now?
100 * Data always starts at offset 0 and extends to 'size'. 102 * Data always starts at offset 0 and extends to 'size'.
@@ -119,7 +121,8 @@ struct SendBuffer {
119 * Devices buffer used to keep a list with all the discoverable devices in 121 * Devices buffer used to keep a list with all the discoverable devices in
120 * order to send them HELLO messages one by one when it receive a broadcast message. 122 * order to send them HELLO messages one by one when it receive a broadcast message.
121 */ 123 */
122struct BroadcastMessages { 124struct BroadcastMessages
125{
123 /* List with the discoverable devices' addresses */ 126 /* List with the discoverable devices' addresses */
124 bdaddr_t devices[MAX_PORTS]; 127 bdaddr_t devices[MAX_PORTS];
125 128
@@ -140,7 +143,10 @@ struct BroadcastMessages {
140/** 143/**
141 * Address used to identify the broadcast messages. 144 * Address used to identify the broadcast messages.
142 */ 145 */
143static struct GNUNET_TRANSPORT_WLAN_MacAddress broadcast_address = { { 255, 255, 255, 255, 255, 255 } }; 146static struct GNUNET_TRANSPORT_WLAN_MacAddress broadcast_address = { { 255, 255,
147 255, 255,
148 255,
149 255 } };
144 150
145/** 151/**
146 * Buffer with the discoverable devices. 152 * Buffer with the discoverable devices.
@@ -190,7 +196,8 @@ typedef void (*MessageTokenizerCallback) (void *cls,
190/** 196/**
191 * Handle to a message stream tokenizer. 197 * Handle to a message stream tokenizer.
192 */ 198 */
193struct MessageStreamTokenizer { 199struct MessageStreamTokenizer
200{
194 /** 201 /**
195 * Function to call on completed messages. 202 * Function to call on completed messages.
196 */ 203 */
@@ -231,23 +238,23 @@ struct MessageStreamTokenizer {
231 * @return handle to tokenizer 238 * @return handle to tokenizer
232 */ 239 */
233static struct MessageStreamTokenizer * 240static struct MessageStreamTokenizer *
234mst_create(MessageTokenizerCallback cb, 241mst_create (MessageTokenizerCallback cb,
235 void *cb_cls) 242 void *cb_cls)
236{ 243{
237 struct MessageStreamTokenizer *ret; 244 struct MessageStreamTokenizer *ret;
238 245
239 ret = malloc(sizeof(struct MessageStreamTokenizer)); 246 ret = malloc (sizeof(struct MessageStreamTokenizer));
240 if (NULL == ret) 247 if (NULL == ret)
241 { 248 {
242 fprintf(stderr, "Failed to allocate buffer for tokenizer\n"); 249 fprintf (stderr, "Failed to allocate buffer for tokenizer\n");
243 exit(1); 250 exit (1);
244 } 251 }
245 ret->hdr = malloc(MIN_BUFFER_SIZE); 252 ret->hdr = malloc (MIN_BUFFER_SIZE);
246 if (NULL == ret->hdr) 253 if (NULL == ret->hdr)
247 { 254 {
248 fprintf(stderr, "Failed to allocate buffer for alignment\n"); 255 fprintf (stderr, "Failed to allocate buffer for alignment\n");
249 exit(1); 256 exit (1);
250 } 257 }
251 ret->curr_buf = MIN_BUFFER_SIZE; 258 ret->curr_buf = MIN_BUFFER_SIZE;
252 ret->cb = cb; 259 ret->cb = cb;
253 ret->cb_cls = cb_cls; 260 ret->cb_cls = cb_cls;
@@ -268,8 +275,8 @@ mst_create(MessageTokenizerCallback cb,
268 * GNUNET_SYSERR if the data stream is corrupt 275 * GNUNET_SYSERR if the data stream is corrupt
269 */ 276 */
270static int 277static int
271mst_receive(struct MessageStreamTokenizer *mst, 278mst_receive (struct MessageStreamTokenizer *mst,
272 const char *buf, size_t size) 279 const char *buf, size_t size)
273{ 280{
274 const struct GNUNET_MessageHeader *hdr; 281 const struct GNUNET_MessageHeader *hdr;
275 size_t delta; 282 size_t delta;
@@ -280,161 +287,162 @@ mst_receive(struct MessageStreamTokenizer *mst,
280 int ret; 287 int ret;
281 288
282 ret = GNUNET_OK; 289 ret = GNUNET_OK;
283 ibuf = (char *)mst->hdr; 290 ibuf = (char *) mst->hdr;
284 while (mst->pos > 0) 291 while (mst->pos > 0)
285 { 292 {
286do_align: 293do_align:
287 if (mst->pos < mst->off) 294 if (mst->pos < mst->off)
288 { 295 {
289 //fprintf (stderr, "We processed too many bytes!\n"); 296 // fprintf (stderr, "We processed too many bytes!\n");
290 return GNUNET_SYSERR; 297 return GNUNET_SYSERR;
291 }
292 if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
293 (0 != (mst->off % ALIGN_FACTOR)))
294 {
295 /* need to align or need more space */
296 mst->pos -= mst->off;
297 memmove(ibuf, &ibuf[mst->off], mst->pos);
298 mst->off = 0;
299 }
300 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
301 {
302 delta =
303 GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) -
304 (mst->pos - mst->off), size);
305 GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
306 mst->pos += delta;
307 buf += delta;
308 size -= delta;
309 }
310 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
311 {
312 //FIXME should I reset ??
313 // mst->off = 0;
314 // mst->pos = 0;
315 return GNUNET_OK;
316 }
317 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
318 want = ntohs(hdr->size);
319 if (want < sizeof(struct GNUNET_MessageHeader))
320 {
321 fprintf(stderr,
322 "Received invalid message from stdin\n");
323 return GNUNET_SYSERR;
324 }
325 if ((mst->curr_buf - mst->off < want) &&
326 (mst->off > 0))
327 {
328 /* need more space */
329 mst->pos -= mst->off;
330 memmove(ibuf, &ibuf[mst->off], mst->pos);
331 mst->off = 0;
332 }
333 if (want > mst->curr_buf)
334 {
335 if (mst->off != 0)
336 {
337 fprintf(stderr, "Error! We should proceeded 0 bytes\n");
338 return GNUNET_SYSERR;
339 }
340 mst->hdr = realloc(mst->hdr, want);
341 if (NULL == mst->hdr)
342 {
343 fprintf(stderr, "Failed to allocate buffer for alignment\n");
344 exit(1);
345 }
346 ibuf = (char *)mst->hdr;
347 mst->curr_buf = want;
348 }
349 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
350 if (mst->pos - mst->off < want)
351 {
352 delta = GNUNET_MIN(want - (mst->pos - mst->off), size);
353 if (mst->pos + delta > mst->curr_buf)
354 {
355 fprintf(stderr, "The size of the buffer will be exceeded!\n");
356 return GNUNET_SYSERR;
357 }
358 GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
359 mst->pos += delta;
360 buf += delta;
361 size -= delta;
362 }
363 if (mst->pos - mst->off < want)
364 {
365 //FIXME should I use this?
366 // mst->off = 0;
367 // mst->pos = 0;
368 return GNUNET_OK;
369 }
370 mst->cb(mst->cb_cls, hdr);
371 mst->off += want;
372 if (mst->off == mst->pos)
373 {
374 /* reset to beginning of buffer, it's free right now! */
375 mst->off = 0;
376 mst->pos = 0;
377 }
378 } 298 }
379 if (0 != mst->pos) 299 if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
300 (0 != (mst->off % ALIGN_FACTOR)))
301 {
302 /* need to align or need more space */
303 mst->pos -= mst->off;
304 memmove (ibuf, &ibuf[mst->off], mst->pos);
305 mst->off = 0;
306 }
307 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
308 {
309 delta =
310 GNUNET_MIN (sizeof(struct GNUNET_MessageHeader)
311 - (mst->pos - mst->off), size);
312 GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
313 mst->pos += delta;
314 buf += delta;
315 size -= delta;
316 }
317 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
318 {
319 // FIXME should I reset ??
320 // mst->off = 0;
321 // mst->pos = 0;
322 return GNUNET_OK;
323 }
324 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
325 want = ntohs (hdr->size);
326 if (want < sizeof(struct GNUNET_MessageHeader))
380 { 327 {
381 fprintf(stderr, "There should some valid bytes in the buffer on this stage\n"); 328 fprintf (stderr,
329 "Received invalid message from stdin\n");
382 return GNUNET_SYSERR; 330 return GNUNET_SYSERR;
383 } 331 }
332 if ((mst->curr_buf - mst->off < want) &&
333 (mst->off > 0))
334 {
335 /* need more space */
336 mst->pos -= mst->off;
337 memmove (ibuf, &ibuf[mst->off], mst->pos);
338 mst->off = 0;
339 }
340 if (want > mst->curr_buf)
341 {
342 if (mst->off != 0)
343 {
344 fprintf (stderr, "Error! We should proceeded 0 bytes\n");
345 return GNUNET_SYSERR;
346 }
347 mst->hdr = realloc (mst->hdr, want);
348 if (NULL == mst->hdr)
349 {
350 fprintf (stderr, "Failed to allocate buffer for alignment\n");
351 exit (1);
352 }
353 ibuf = (char *) mst->hdr;
354 mst->curr_buf = want;
355 }
356 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
357 if (mst->pos - mst->off < want)
358 {
359 delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
360 if (mst->pos + delta > mst->curr_buf)
361 {
362 fprintf (stderr, "The size of the buffer will be exceeded!\n");
363 return GNUNET_SYSERR;
364 }
365 GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
366 mst->pos += delta;
367 buf += delta;
368 size -= delta;
369 }
370 if (mst->pos - mst->off < want)
371 {
372 // FIXME should I use this?
373 // mst->off = 0;
374 // mst->pos = 0;
375 return GNUNET_OK;
376 }
377 mst->cb (mst->cb_cls, hdr);
378 mst->off += want;
379 if (mst->off == mst->pos)
380 {
381 /* reset to beginning of buffer, it's free right now! */
382 mst->off = 0;
383 mst->pos = 0;
384 }
385 }
386 if (0 != mst->pos)
387 {
388 fprintf (stderr,
389 "There should some valid bytes in the buffer on this stage\n");
390 return GNUNET_SYSERR;
391 }
384 while (size > 0) 392 while (size > 0)
393 {
394 if (size < sizeof(struct GNUNET_MessageHeader))
395 break;
396 offset = (unsigned long) buf;
397 need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
398 if (GNUNET_NO == need_align)
385 { 399 {
386 if (size < sizeof(struct GNUNET_MessageHeader)) 400 /* can try to do zero-copy and process directly from original buffer */
387 break; 401 hdr = (const struct GNUNET_MessageHeader *) buf;
388 offset = (unsigned long)buf; 402 want = ntohs (hdr->size);
389 need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; 403 if (want < sizeof(struct GNUNET_MessageHeader))
390 if (GNUNET_NO == need_align) 404 {
391 { 405 fprintf (stderr,
392 /* can try to do zero-copy and process directly from original buffer */ 406 "Received invalid message from stdin\n");
393 hdr = (const struct GNUNET_MessageHeader *)buf; 407 // exit (1);
394 want = ntohs(hdr->size); 408 mst->off = 0;
395 if (want < sizeof(struct GNUNET_MessageHeader)) 409 return GNUNET_SYSERR;
396 { 410 }
397 fprintf(stderr, 411 if (size < want)
398 "Received invalid message from stdin\n"); 412 break; /* or not, buffer incomplete, so copy to private buffer... */
399 //exit (1); 413 mst->cb (mst->cb_cls, hdr);
400 mst->off = 0; 414 buf += want;
401 return GNUNET_SYSERR; 415 size -= want;
402 }
403 if (size < want)
404 break; /* or not, buffer incomplete, so copy to private buffer... */
405 mst->cb(mst->cb_cls, hdr);
406 buf += want;
407 size -= want;
408 }
409 else
410 {
411 /* need to copy to private buffer to align;
412 * yes, we go a bit more spagetti than usual here */
413 goto do_align;
414 }
415 } 416 }
417 else
418 {
419 /* need to copy to private buffer to align;
420 * yes, we go a bit more spagetti than usual here */
421 goto do_align;
422 }
423 }
416 if (size > 0) 424 if (size > 0)
425 {
426 if (size + mst->pos > mst->curr_buf)
417 { 427 {
418 if (size + mst->pos > mst->curr_buf) 428 mst->hdr = realloc (mst->hdr, size + mst->pos);
419 { 429 if (NULL == mst->hdr)
420 mst->hdr = realloc(mst->hdr, size + mst->pos); 430 {
421 if (NULL == mst->hdr) 431 fprintf (stderr, "Failed to allocate buffer for alignment\n");
422 { 432 exit (1);
423 fprintf(stderr, "Failed to allocate buffer for alignment\n"); 433 }
424 exit(1); 434 ibuf = (char *) mst->hdr;
425 } 435 mst->curr_buf = size + mst->pos;
426 ibuf = (char *)mst->hdr; 436 }
427 mst->curr_buf = size + mst->pos; 437 if (mst->pos + size > mst->curr_buf)
428 } 438 {
429 if (mst->pos + size > mst->curr_buf) 439 fprintf (stderr,
430 { 440 "Assertion failed\n");
431 fprintf(stderr, 441 exit (1);
432 "Assertion failed\n");
433 exit(1);
434 }
435 GNUNET_memcpy(&ibuf[mst->pos], buf, size);
436 mst->pos += size;
437 } 442 }
443 GNUNET_memcpy (&ibuf[mst->pos], buf, size);
444 mst->pos += size;
445 }
438 return ret; 446 return ret;
439} 447}
440 448
@@ -444,10 +452,10 @@ do_align:
444 * @param mst tokenizer to destroy 452 * @param mst tokenizer to destroy
445 */ 453 */
446static void 454static void
447mst_destroy(struct MessageStreamTokenizer *mst) 455mst_destroy (struct MessageStreamTokenizer *mst)
448{ 456{
449 free(mst->hdr); 457 free (mst->hdr);
450 free(mst); 458 free (mst);
451} 459}
452 460
453/** 461/**
@@ -458,7 +466,7 @@ mst_destroy(struct MessageStreamTokenizer *mst)
458 * @return crc sum 466 * @return crc sum
459 */ 467 */
460static unsigned long 468static unsigned long
461calc_crc_osdep(const unsigned char *buf, size_t len) 469calc_crc_osdep (const unsigned char *buf, size_t len)
462{ 470{
463 static const unsigned long int crc_tbl_osdep[256] = { 471 static const unsigned long int crc_tbl_osdep[256] = {
464 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 472 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
@@ -544,14 +552,14 @@ calc_crc_osdep(const unsigned char *buf, size_t len)
544 * @return 0 on success (checksum matches), 1 on error 552 * @return 0 on success (checksum matches), 1 on error
545 */ 553 */
546static int 554static int
547check_crc_buf_osdep(const unsigned char *buf, size_t len) 555check_crc_buf_osdep (const unsigned char *buf, size_t len)
548{ 556{
549 unsigned long crc; 557 unsigned long crc;
550 558
551 crc = calc_crc_osdep(buf, len); 559 crc = calc_crc_osdep (buf, len);
552 buf += len; 560 buf += len;
553 if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && 561 if ((((crc) & 0xFF) == buf[0])&&(((crc >> 8) & 0xFF) == buf[1])&&
554 ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]) 562 ( ((crc >> 16) & 0xFF) == buf[2]) &&( ((crc >> 24) & 0xFF) == buf[3]) )
555 return 0; 563 return 0;
556 return 1; 564 return 1;
557} 565}
@@ -568,19 +576,20 @@ check_crc_buf_osdep(const unsigned char *buf, size_t len)
568 * @return 0 on success 576 * @return 0 on success
569 */ 577 */
570static int 578static int
571bind_socket(int socket, struct sockaddr_rc *addr) 579bind_socket (int socket, struct sockaddr_rc *addr)
572{ 580{
573 int port, status; 581 int port, status;
574 582
575 /* Bind every possible port (from 0 to 30) and stop when binding doesn't fail */ 583 /* Bind every possible port (from 0 to 30) and stop when binding doesn't fail */
576 //FIXME : it should start from port 1, but on my computer it doesn't work :) 584 // FIXME : it should start from port 1, but on my computer it doesn't work :)
577 for (port = 3; port <= 30; port++) 585 for (port = 3; port <= 30; port++)
578 { 586 {
579 addr->rc_channel = port; 587 addr->rc_channel = port;
580 status = bind(socket, (struct sockaddr *)addr, sizeof(struct sockaddr_rc)); 588 status = bind (socket, (struct sockaddr *) addr, sizeof(struct
581 if (status == 0) 589 sockaddr_rc));
582 return 0; 590 if (status == 0)
583 } 591 return 0;
592 }
584 593
585 return -1; 594 return -1;
586} 595}
@@ -594,7 +603,7 @@ bind_socket(int socket, struct sockaddr_rc *addr)
594 * @return 0 on success 603 * @return 0 on success
595 */ 604 */
596static int 605static int
597register_service(struct HardwareInfos *dev, int rc_channel) 606register_service (struct HardwareInfos *dev, int rc_channel)
598{ 607{
599 /** 608 /**
600 * 1. initializations 609 * 1. initializations
@@ -606,8 +615,10 @@ register_service(struct HardwareInfos *dev, int rc_channel)
606 * 7. cleanup 615 * 7. cleanup
607 */ 616 */
608 uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 617 uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
609 dev->pl_mac.mac[5], dev->pl_mac.mac[4], dev->pl_mac.mac[3], 618 dev->pl_mac.mac[5], dev->pl_mac.mac[4],
610 dev->pl_mac.mac[2], dev->pl_mac.mac[1], dev->pl_mac.mac[0] }; 619 dev->pl_mac.mac[3],
620 dev->pl_mac.mac[2], dev->pl_mac.mac[1],
621 dev->pl_mac.mac[0] };
611 const char *service_dsc = "Bluetooth plugin services"; 622 const char *service_dsc = "Bluetooth plugin services";
612 const char *service_prov = "GNUnet provider"; 623 const char *service_prov = "GNUnet provider";
613 uuid_t root_uuid, rfcomm_uuid, svc_uuid; 624 uuid_t root_uuid, rfcomm_uuid, svc_uuid;
@@ -616,61 +627,63 @@ register_service(struct HardwareInfos *dev, int rc_channel)
616 sdp_record_t *record = 0; 627 sdp_record_t *record = 0;
617 sdp_data_t *channel = 0; 628 sdp_data_t *channel = 0;
618 629
619 record = sdp_record_alloc(); 630 record = sdp_record_alloc ();
620 631
621 /* Set the general service ID */ 632 /* Set the general service ID */
622 sdp_uuid128_create(&svc_uuid, &svc_uuid_int); 633 sdp_uuid128_create (&svc_uuid, &svc_uuid_int);
623 svc_list = sdp_list_append(0, &svc_uuid); 634 svc_list = sdp_list_append (0, &svc_uuid);
624 sdp_set_service_classes(record, svc_list); 635 sdp_set_service_classes (record, svc_list);
625 sdp_set_service_id(record, svc_uuid); 636 sdp_set_service_id (record, svc_uuid);
626 637
627 /* Make the service record publicly browsable */ 638 /* Make the service record publicly browsable */
628 sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); 639 sdp_uuid16_create (&root_uuid, PUBLIC_BROWSE_GROUP);
629 root_list = sdp_list_append(0, &root_uuid); 640 root_list = sdp_list_append (0, &root_uuid);
630 sdp_set_browse_groups(record, root_list); 641 sdp_set_browse_groups (record, root_list);
631 642
632 /* Register the RFCOMM channel */ 643 /* Register the RFCOMM channel */
633 sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); 644 sdp_uuid16_create (&rfcomm_uuid, RFCOMM_UUID);
634 channel = sdp_data_alloc(SDP_UINT8, &rc_channel); 645 channel = sdp_data_alloc (SDP_UINT8, &rc_channel);
635 rfcomm_list = sdp_list_append(0, &rfcomm_uuid); 646 rfcomm_list = sdp_list_append (0, &rfcomm_uuid);
636 sdp_list_append(rfcomm_list, channel); 647 sdp_list_append (rfcomm_list, channel);
637 proto_list = sdp_list_append(0, rfcomm_list); 648 proto_list = sdp_list_append (0, rfcomm_list);
638 649
639 /* Set protocol information */ 650 /* Set protocol information */
640 access_proto_list = sdp_list_append(0, proto_list); 651 access_proto_list = sdp_list_append (0, proto_list);
641 sdp_set_access_protos(record, access_proto_list); 652 sdp_set_access_protos (record, access_proto_list);
642 653
643 /* Set the name, provider, and description */ 654 /* Set the name, provider, and description */
644 sdp_set_info_attr(record, dev->iface, service_prov, service_dsc); 655 sdp_set_info_attr (record, dev->iface, service_prov, service_dsc);
645 656
646 /* Connect to the local SDP server */ 657 /* Connect to the local SDP server */
647 dev->session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); 658 dev->session = sdp_connect (BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
648 659
649 if (!dev->session) 660 if (! dev->session)
650 { 661 {
651 fprintf(stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n", 662 fprintf (stderr,
652 IFNAMSIZ, dev->iface, strerror(errno)); 663 "Failed to connect to the SDP server on interface `%.*s': %s\n",
653 //FIXME exit? 664 IFNAMSIZ, dev->iface, strerror (errno));
654 return 1; 665 // FIXME exit?
655 } 666 return 1;
667 }
656 668
657 /* Register the service record */ 669 /* Register the service record */
658 if (sdp_record_register(dev->session, record, 0) < 0) 670 if (sdp_record_register (dev->session, record, 0) < 0)
659 { 671 {
660 fprintf(stderr, "Failed to register a service record on interface `%.*s': %s\n", 672 fprintf (stderr,
661 IFNAMSIZ, dev->iface, strerror(errno)); 673 "Failed to register a service record on interface `%.*s': %s\n",
662 //FIXME exit? 674 IFNAMSIZ, dev->iface, strerror (errno));
663 return 1; 675 // FIXME exit?
664 } 676 return 1;
677 }
665 678
666 /* Cleanup */ 679 /* Cleanup */
667 sdp_data_free(channel); 680 sdp_data_free (channel);
668 sdp_list_free(root_list, 0); 681 sdp_list_free (root_list, 0);
669 sdp_list_free(rfcomm_list, 0); 682 sdp_list_free (rfcomm_list, 0);
670 sdp_list_free(proto_list, 0); 683 sdp_list_free (proto_list, 0);
671 sdp_list_free(access_proto_list, 0); 684 sdp_list_free (access_proto_list, 0);
672 sdp_list_free(svc_list, 0); 685 sdp_list_free (svc_list, 0);
673 sdp_record_free(record); 686 sdp_record_free (record);
674 687
675 return 0; 688 return 0;
676} 689}
@@ -684,7 +697,7 @@ register_service(struct HardwareInfos *dev, int rc_channel)
684 * @return channel 697 * @return channel
685 */ 698 */
686static int 699static int
687get_channel(struct HardwareInfos *dev, bdaddr_t dest) 700get_channel (struct HardwareInfos *dev, bdaddr_t dest)
688{ 701{
689 /** 702 /**
690 * 1. detect all nearby devices 703 * 1. detect all nearby devices
@@ -704,46 +717,48 @@ get_channel(struct HardwareInfos *dev, bdaddr_t dest)
704 int channel = -1; 717 int channel = -1;
705 718
706 /* Connect to the local SDP server */ 719 /* Connect to the local SDP server */
707 session = sdp_connect(BDADDR_ANY, &dest, 0); 720 session = sdp_connect (BDADDR_ANY, &dest, 0);
708 if (!session) 721 if (! session)
709 { 722 {
710 fprintf(stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n", 723 fprintf (stderr,
711 IFNAMSIZ, dev->iface, strerror(errno)); 724 "Failed to connect to the SDP server on interface `%.*s': %s\n",
712 return -1; 725 IFNAMSIZ, dev->iface, strerror (errno));
713 } 726 return -1;
727 }
714 728
715 sdp_uuid128_create(&svc_uuid, &svc_uuid_int); 729 sdp_uuid128_create (&svc_uuid, &svc_uuid_int);
716 search_list = sdp_list_append(0, &svc_uuid); 730 search_list = sdp_list_append (0, &svc_uuid);
717 attrid_list = sdp_list_append(0, &range); 731 attrid_list = sdp_list_append (0, &range);
718 732
719 if (sdp_service_search_attr_req(session, search_list, 733 if (sdp_service_search_attr_req (session, search_list,
720 SDP_ATTR_REQ_RANGE, attrid_list, &response_list) == 0) 734 SDP_ATTR_REQ_RANGE, attrid_list,
735 &response_list) == 0)
736 {
737 for (it = response_list; it; it = it->next)
721 { 738 {
722 for (it = response_list; it; it = it->next) 739 sdp_record_t *record = (sdp_record_t*) it->data;
723 { 740 sdp_list_t *proto_list = 0;
724 sdp_record_t *record = (sdp_record_t*)it->data; 741 if (sdp_get_access_protos (record, &proto_list) == 0)
725 sdp_list_t *proto_list = 0; 742 {
726 if (sdp_get_access_protos(record, &proto_list) == 0) 743 channel = sdp_get_proto_port (proto_list, RFCOMM_UUID);
727 { 744 sdp_list_free (proto_list, 0);
728 channel = sdp_get_proto_port(proto_list, RFCOMM_UUID); 745 }
729 sdp_list_free(proto_list, 0); 746 sdp_record_free (record);
730 }
731 sdp_record_free(record);
732 }
733 } 747 }
748 }
734 749
735 sdp_list_free(search_list, 0); 750 sdp_list_free (search_list, 0);
736 sdp_list_free(attrid_list, 0); 751 sdp_list_free (attrid_list, 0);
737 sdp_list_free(response_list, 0); 752 sdp_list_free (response_list, 0);
738 753
739 sdp_close(session); 754 sdp_close (session);
740 755
741 if (-1 == channel) 756 if (-1 == channel)
742 fprintf(stderr, 757 fprintf (stderr,
743 "Failed to find the listening channel for interface `%.*s': %s\n", 758 "Failed to find the listening channel for interface `%.*s': %s\n",
744 IFNAMSIZ, 759 IFNAMSIZ,
745 dev->iface, 760 dev->iface,
746 strerror(errno)); 761 strerror (errno));
747 762
748 return channel; 763 return channel;
749} 764}
@@ -759,48 +774,50 @@ get_channel(struct HardwareInfos *dev, bdaddr_t dest)
759 * @return number of bytes written to 'buf' 774 * @return number of bytes written to 'buf'
760 */ 775 */
761static ssize_t 776static ssize_t
762read_from_the_socket(void *sock, 777read_from_the_socket (void *sock,
763 unsigned char *buf, size_t buf_size, 778 unsigned char *buf, size_t buf_size,
764 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) 779 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
765{ 780{
766 unsigned char tmpbuf[buf_size]; 781 unsigned char tmpbuf[buf_size];
767 ssize_t count; 782 ssize_t count;
768 count = read(*((int *)sock), tmpbuf, buf_size); 783 count = read (*((int *) sock), tmpbuf, buf_size);
769 784
770 if (0 > count) 785 if (0 > count)
771 { 786 {
772 if (EAGAIN == errno) 787 if (EAGAIN == errno)
773 return 0; 788 return 0;
774 789
775 fprintf(stderr, "Failed to read from the HCI socket: %s\n", strerror(errno)); 790 fprintf (stderr, "Failed to read from the HCI socket: %s\n", strerror (
791 errno));
776 792
777 return -1; 793 return -1;
778 } 794 }
779 795
780 #ifdef LINUX 796 #ifdef LINUX
781 /* Get the channel used */ 797 /* Get the channel used */
782 int len; 798 int len;
783 struct sockaddr_rc rc_addr = { 0 }; 799 struct sockaddr_rc rc_addr = { 0 };
784 800
785 memset(&rc_addr, 0, sizeof(rc_addr)); 801 memset (&rc_addr, 0, sizeof(rc_addr));
786 len = sizeof(rc_addr); 802 len = sizeof(rc_addr);
787 if (0 > getsockname(*((int *)sock), (struct sockaddr *)&rc_addr, (socklen_t *)&len)) 803 if (0 > getsockname (*((int *) sock), (struct sockaddr *) &rc_addr,
788 { 804 (socklen_t *) &len))
789 fprintf(stderr, "getsockname() call failed : %s\n", strerror(errno)); 805 {
790 return -1; 806 fprintf (stderr, "getsockname() call failed : %s\n", strerror (errno));
791 } 807 return -1;
808 }
792 809
793 memset(ri, 0, sizeof(*ri)); 810 memset (ri, 0, sizeof(*ri));
794 ri->ri_channel = rc_addr.rc_channel; 811 ri->ri_channel = rc_addr.rc_channel;
795 #endif 812 #endif
796 813
797 /* Detect CRC32 at the end */ 814 /* Detect CRC32 at the end */
798 if (0 == check_crc_buf_osdep(tmpbuf, count - sizeof(uint32_t))) 815 if (0 == check_crc_buf_osdep (tmpbuf, count - sizeof(uint32_t)))
799 { 816 {
800 count -= sizeof(uint32_t); 817 count -= sizeof(uint32_t);
801 } 818 }
802 819
803 GNUNET_memcpy(buf, tmpbuf, count); 820 GNUNET_memcpy (buf, tmpbuf, count);
804 821
805 return count; 822 return count;
806} 823}
@@ -813,14 +830,15 @@ read_from_the_socket(void *sock,
813 * @return 0 on success, non-zero on error 830 * @return 0 on success, non-zero on error
814 */ 831 */
815static int 832static int
816open_device(struct HardwareInfos *dev) 833open_device (struct HardwareInfos *dev)
817{ 834{
818 int i, dev_id = -1, fd_hci; 835 int i, dev_id = -1, fd_hci;
819 struct { 836 struct
837 {
820 struct hci_dev_list_req list; 838 struct hci_dev_list_req list;
821 struct hci_dev_req dev[HCI_MAX_DEV]; 839 struct hci_dev_req dev[HCI_MAX_DEV];
822 } request; //used for detecting the local devices 840 } request; // used for detecting the local devices
823 struct sockaddr_rc rc_addr = { 0 }; //used for binding 841 struct sockaddr_rc rc_addr = { 0 }; // used for binding
824 842
825 /* Initialize the neighbour structure */ 843 /* Initialize the neighbour structure */
826 neighbours.dev_id = -1; 844 neighbours.dev_id = -1;
@@ -828,147 +846,148 @@ open_device(struct HardwareInfos *dev)
828 neighbours.fds[i] = -1; 846 neighbours.fds[i] = -1;
829 847
830 /* Open a HCI socket */ 848 /* Open a HCI socket */
831 fd_hci = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); 849 fd_hci = socket (AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
832 850
833 if (fd_hci < 0) 851 if (fd_hci < 0)
834 { 852 {
835 fprintf(stderr, 853 fprintf (stderr,
836 "Failed to create HCI socket: %s\n", 854 "Failed to create HCI socket: %s\n",
837 strerror(errno)); 855 strerror (errno));
838 return -1; 856 return -1;
839 } 857 }
840 858
841 memset(&request, 0, sizeof(request)); 859 memset (&request, 0, sizeof(request));
842 request.list.dev_num = HCI_MAX_DEV; 860 request.list.dev_num = HCI_MAX_DEV;
843 861
844 if (ioctl(fd_hci, HCIGETDEVLIST, (void *)&request) < 0) 862 if (ioctl (fd_hci, HCIGETDEVLIST, (void *) &request) < 0)
845 { 863 {
846 fprintf(stderr, 864 fprintf (stderr,
847 "ioctl(HCIGETDEVLIST) on interface `%.*s' failed: %s\n", 865 "ioctl(HCIGETDEVLIST) on interface `%.*s' failed: %s\n",
848 IFNAMSIZ, 866 IFNAMSIZ,
849 dev->iface, 867 dev->iface,
850 strerror(errno)); 868 strerror (errno));
851 (void)close(fd_hci); 869 (void) close (fd_hci);
852 return 1; 870 return 1;
853 } 871 }
854 872
855 /* Search for a device with dev->iface name */ 873 /* Search for a device with dev->iface name */
856 for (i = 0; i < request.list.dev_num; i++) 874 for (i = 0; i < request.list.dev_num; i++)
857 { 875 {
858 struct hci_dev_info dev_info; 876 struct hci_dev_info dev_info;
859 877
860 memset(&dev_info, 0, sizeof(struct hci_dev_info)); 878 memset (&dev_info, 0, sizeof(struct hci_dev_info));
861 dev_info.dev_id = request.dev[i].dev_id; 879 dev_info.dev_id = request.dev[i].dev_id;
862 strncpy(dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE); 880 strncpy (dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE);
863 881
864 if (ioctl(fd_hci, HCIGETDEVINFO, (void *)&dev_info)) 882 if (ioctl (fd_hci, HCIGETDEVINFO, (void *) &dev_info))
883 {
884 fprintf (stderr,
885 "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n",
886 IFNAMSIZ,
887 dev->iface,
888 strerror (errno));
889 (void) close (fd_hci);
890 return 1;
891 }
892
893 if (strncmp (dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE) == 0)
894 {
895 dev_id = dev_info.dev_id; // the device was found
896 /**
897 * Copy the MAC address to the device structure
898 */
899 GNUNET_memcpy (&dev->pl_mac, &dev_info.bdaddr, sizeof(bdaddr_t));
900
901 /* Check if the interface is up */
902 if (hci_test_bit (HCI_UP, (void *) &dev_info.flags) == 0)
903 {
904 /* Bring the interface up */
905 if (ioctl (fd_hci, HCIDEVUP, dev_info.dev_id))
865 { 906 {
866 fprintf(stderr, 907 fprintf (stderr,
867 "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n", 908 "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n",
868 IFNAMSIZ, 909 IFNAMSIZ,
869 dev->iface, 910 dev->iface,
870 strerror(errno)); 911 strerror (errno));
871 (void)close(fd_hci); 912 (void) close (fd_hci);
872 return 1; 913 return 1;
873 } 914 }
915 }
874 916
875 if (strncmp(dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE) == 0) 917 /* Check if the device is discoverable */
876 { 918 if ((hci_test_bit (HCI_PSCAN, (void *) &dev_info.flags) == 0) ||
877 dev_id = dev_info.dev_id; //the device was found 919 (hci_test_bit (HCI_ISCAN, (void *) &dev_info.flags) == 0) )
878 /** 920 {
879 * Copy the MAC address to the device structure 921 /* Set interface Page Scan and Inqury Scan ON */
880 */ 922 struct hci_dev_req dev_req;
881 GNUNET_memcpy(&dev->pl_mac, &dev_info.bdaddr, sizeof(bdaddr_t));
882
883 /* Check if the interface is up */
884 if (hci_test_bit(HCI_UP, (void *)&dev_info.flags) == 0)
885 {
886 /* Bring the interface up */
887 if (ioctl(fd_hci, HCIDEVUP, dev_info.dev_id))
888 {
889 fprintf(stderr,
890 "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n",
891 IFNAMSIZ,
892 dev->iface,
893 strerror(errno));
894 (void)close(fd_hci);
895 return 1;
896 }
897 }
898
899 /* Check if the device is discoverable */
900 if (hci_test_bit(HCI_PSCAN, (void *)&dev_info.flags) == 0 ||
901 hci_test_bit(HCI_ISCAN, (void *)&dev_info.flags) == 0)
902 {
903 /* Set interface Page Scan and Inqury Scan ON */
904 struct hci_dev_req dev_req;
905 923
906 memset(&dev_req, 0, sizeof(dev_req)); 924 memset (&dev_req, 0, sizeof(dev_req));
907 dev_req.dev_id = dev_info.dev_id; 925 dev_req.dev_id = dev_info.dev_id;
908 dev_req.dev_opt = SCAN_PAGE | SCAN_INQUIRY; 926 dev_req.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
909 927
910 if (ioctl(fd_hci, HCISETSCAN, (unsigned long)&dev_req)) 928 if (ioctl (fd_hci, HCISETSCAN, (unsigned long) &dev_req))
911 { 929 {
912 fprintf(stderr, 930 fprintf (stderr,
913 "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n", 931 "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n",
914 IFNAMSIZ, 932 IFNAMSIZ,
915 dev->iface, 933 dev->iface,
916 strerror(errno)); 934 strerror (errno));
917 (void)close(fd_hci); 935 (void) close (fd_hci);
918 return 1; 936 return 1;
919 }
920 }
921 break;
922 } 937 }
938 }
939 break;
923 } 940 }
941 }
924 942
925 /* Check if the interface was not found */ 943 /* Check if the interface was not found */
926 if (-1 == dev_id) 944 if (-1 == dev_id)
927 { 945 {
928 fprintf(stderr, 946 fprintf (stderr,
929 "The interface %s was not found\n", 947 "The interface %s was not found\n",
930 dev->iface); 948 dev->iface);
931 (void)close(fd_hci); 949 (void) close (fd_hci);
932 return 1; 950 return 1;
933 } 951 }
934 952
935 /* Close the hci socket */ 953 /* Close the hci socket */
936 (void)close(fd_hci); 954 (void) close (fd_hci);
937 955
938 956
939 957
940 /* Bind the rfcomm socket to the interface */ 958 /* Bind the rfcomm socket to the interface */
941 memset(&rc_addr, 0, sizeof(rc_addr)); 959 memset (&rc_addr, 0, sizeof(rc_addr));
942 rc_addr.rc_family = AF_BLUETOOTH; 960 rc_addr.rc_family = AF_BLUETOOTH;
943 rc_addr.rc_bdaddr = *BDADDR_ANY; 961 rc_addr.rc_bdaddr = *BDADDR_ANY;
944 962
945 if (bind_socket(dev->fd_rfcomm, &rc_addr) != 0) 963 if (bind_socket (dev->fd_rfcomm, &rc_addr) != 0)
946 { 964 {
947 fprintf(stderr, 965 fprintf (stderr,
948 "Failed to bind interface `%.*s': %s\n", 966 "Failed to bind interface `%.*s': %s\n",
949 IFNAMSIZ, 967 IFNAMSIZ,
950 dev->iface, 968 dev->iface,
951 strerror(errno)); 969 strerror (errno));
952 return 1; 970 return 1;
953 } 971 }
954 972
955 /* Register a SDP service */ 973 /* Register a SDP service */
956 if (register_service(dev, rc_addr.rc_channel) != 0) 974 if (register_service (dev, rc_addr.rc_channel) != 0)
957 { 975 {
958 fprintf(stderr, 976 fprintf (stderr,
959 "Failed to register a service on interface `%.*s': %s\n", 977 "Failed to register a service on interface `%.*s': %s\n",
960 IFNAMSIZ, 978 IFNAMSIZ,
961 dev->iface, strerror(errno)); 979 dev->iface, strerror (errno));
962 return 1; 980 return 1;
963 } 981 }
964 982
965 /* Switch socket in listening mode */ 983 /* Switch socket in listening mode */
966 if (listen(dev->fd_rfcomm, 5) == -1) //FIXME: probably we need a bigger number 984 if (listen (dev->fd_rfcomm, 5) == -1) // FIXME: probably we need a bigger number
967 { 985 {
968 fprintf(stderr, "Failed to listen on socket for interface `%.*s': %s\n", IFNAMSIZ, 986 fprintf (stderr, "Failed to listen on socket for interface `%.*s': %s\n",
969 dev->iface, strerror(errno)); 987 IFNAMSIZ,
970 return 1; 988 dev->iface, strerror (errno));
971 } 989 return 1;
990 }
972 991
973 return 0; 992 return 0;
974} 993}
@@ -983,10 +1002,10 @@ open_device(struct HardwareInfos *dev)
983 **** copy from gnunet-helper-transport-wlan.c **** 1002 **** copy from gnunet-helper-transport-wlan.c ****
984 */ 1003 */
985static void 1004static void
986mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, 1005mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
987 const struct HardwareInfos *dev) 1006 const struct HardwareInfos *dev)
988{ 1007{
989 taIeeeHeader->frame_control = htons(IEEE80211_FC0_TYPE_DATA); 1008 taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
990 taIeeeHeader->addr3 = mac_bssid_gnunet; 1009 taIeeeHeader->addr3 = mac_bssid_gnunet;
991 taIeeeHeader->addr2 = dev->pl_mac; 1010 taIeeeHeader->addr2 = dev->pl_mac;
992} 1011}
@@ -1001,22 +1020,22 @@ mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1001 **** similar with the one from gnunet-helper-transport-wlan.c **** 1020 **** similar with the one from gnunet-helper-transport-wlan.c ****
1002 */ 1021 */
1003static int 1022static int
1004test_bluetooth_interface(const char *iface) 1023test_bluetooth_interface (const char *iface)
1005{ 1024{
1006 char strbuf[512]; 1025 char strbuf[512];
1007 struct stat sbuf; 1026 struct stat sbuf;
1008 int ret; 1027 int ret;
1009 1028
1010 ret = snprintf(strbuf, sizeof(strbuf), 1029 ret = snprintf (strbuf, sizeof(strbuf),
1011 "/sys/class/bluetooth/%s/subsystem", 1030 "/sys/class/bluetooth/%s/subsystem",
1012 iface); 1031 iface);
1013 if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat(strbuf, &sbuf))) 1032 if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat (strbuf, &sbuf)))
1014 { 1033 {
1015 fprintf(stderr, 1034 fprintf (stderr,
1016 "Did not find 802.15.1 interface `%s'. Exiting.\n", 1035 "Did not find 802.15.1 interface `%s'. Exiting.\n",
1017 iface); 1036 iface);
1018 exit(1); 1037 exit (1);
1019 } 1038 }
1020 return 0; 1039 return 0;
1021} 1040}
1022#endif 1041#endif
@@ -1031,19 +1050,19 @@ test_bluetooth_interface(const char *iface)
1031 **** same as the one from gnunet-helper-transport-wlan.c **** 1050 **** same as the one from gnunet-helper-transport-wlan.c ****
1032 */ 1051 */
1033static int 1052static int
1034mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, 1053mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1035 const struct HardwareInfos *dev) 1054 const struct HardwareInfos *dev)
1036{ 1055{
1037 static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros; 1056 static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros;
1038 1057
1039 if ((0 == memcmp(&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) || 1058 if ((0 == memcmp (&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) ||
1040 (0 == memcmp(&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE))) 1059 (0 == memcmp (&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)))
1041 return 0; /* some drivers set no Macs, then assume it is all for us! */ 1060 return 0; /* some drivers set no Macs, then assume it is all for us! */
1042 1061
1043 if (0 != memcmp(&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE)) 1062 if (0 != memcmp (&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE))
1044 return 1; /* not a GNUnet ad-hoc package */ 1063 return 1; /* not a GNUnet ad-hoc package */
1045 if ((0 == memcmp(&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) || 1064 if ((0 == memcmp (&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) ||
1046 (0 == memcmp(&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE))) 1065 (0 == memcmp (&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)))
1047 return 0; /* for us, or broadcast */ 1066 return 0; /* for us, or broadcast */
1048 return 1; /* not for us */ 1067 return 1; /* not for us */
1049} 1068}
@@ -1059,37 +1078,37 @@ mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1059 **** same as the one from gnunet-helper-transport-wlan.c **** 1078 **** same as the one from gnunet-helper-transport-wlan.c ****
1060 */ 1079 */
1061static void 1080static void
1062stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr) 1081stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1063{ 1082{
1064 struct HardwareInfos *dev = cls; 1083 struct HardwareInfos *dev = cls;
1065 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header; 1084 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header;
1066 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *blueheader; 1085 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *blueheader;
1067 size_t sendsize; 1086 size_t sendsize;
1068 1087
1069 sendsize = ntohs(hdr->size); 1088 sendsize = ntohs (hdr->size);
1070 if ((sendsize < 1089 if ((sendsize <
1071 sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) || 1090 sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) ||
1072 (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type))) 1091 (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)))
1073 { 1092 {
1074 fprintf(stderr, "Received malformed message\n"); 1093 fprintf (stderr, "Received malformed message\n");
1075 exit(1); 1094 exit (1);
1076 } 1095 }
1077 sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - 1096 sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)
1078 sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); 1097 - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
1079 if (MAXLINE < sendsize) 1098 if (MAXLINE < sendsize)
1080 { 1099 {
1081 fprintf(stderr, "Packet too big for buffer\n"); 1100 fprintf (stderr, "Packet too big for buffer\n");
1082 exit(1); 1101 exit (1);
1083 } 1102 }
1084 header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr; 1103 header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
1085 GNUNET_memcpy(&write_pout.buf, &header->frame, sendsize); 1104 GNUNET_memcpy (&write_pout.buf, &header->frame, sendsize);
1086 blueheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)&write_pout.buf; 1105 blueheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &write_pout.buf;
1087 1106
1088 /* payload contains MAC address, but we don't trust it, so we'll 1107 /* payload contains MAC address, but we don't trust it, so we'll
1089 * overwrite it with OUR MAC address to prevent mischief */ 1108 * overwrite it with OUR MAC address to prevent mischief */
1090 mac_set(blueheader, dev); 1109 mac_set (blueheader, dev);
1091 GNUNET_memcpy(&blueheader->addr1, &header->frame.addr1, 1110 GNUNET_memcpy (&blueheader->addr1, &header->frame.addr1,
1092 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)); 1111 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
1093 write_pout.size = sendsize; 1112 write_pout.size = sendsize;
1094} 1113}
1095 1114
@@ -1102,105 +1121,120 @@ stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
1102 * @return 0 on success 1121 * @return 0 on success
1103 */ 1122 */
1104static int 1123static int
1105send_broadcast(struct HardwareInfos *dev, int *sendsocket) 1124send_broadcast (struct HardwareInfos *dev, int *sendsocket)
1106{ 1125{
1107 int new_device = 0; 1126 int new_device = 0;
1108 int loops = 0; 1127 int loops = 0;
1109 1128
1110search_for_devices: 1129search_for_devices:
1111 if ((neighbours.size == neighbours.pos && new_device == 1) || neighbours.size == 0) 1130 if (((neighbours.size == neighbours.pos)&&(new_device == 1)) ||
1131 (neighbours.size == 0) )
1132 {
1133inquiry_devices: // skip the conditions and force a inquiry for new devices
1112 { 1134 {
1113inquiry_devices: //skip the conditions and force a inquiry for new devices 1135 /**
1136 * It means that I sent HELLO messages to all the devices from the list and I should search
1137 * for new ones or that this is the first time when I do a search.
1138 */
1139 inquiry_info *devices = NULL;
1140 int i, responses, max_responses = MAX_PORTS;
1141
1142 /* sanity checks */
1143 if (neighbours.size >= MAX_PORTS)
1114 { 1144 {
1115 /** 1145 fprintf (stderr,
1116 * It means that I sent HELLO messages to all the devices from the list and I should search 1146 "%.*s reached the top limit for the discovarable devices\n",
1117 * for new ones or that this is the first time when I do a search. 1147 IFNAMSIZ,
1118 */ 1148 dev->iface);
1119 inquiry_info *devices = NULL; 1149 return 2;
1120 int i, responses, max_responses = MAX_PORTS; 1150 }
1121
1122 /* sanity checks */
1123 if (neighbours.size >= MAX_PORTS)
1124 {
1125 fprintf(stderr, "%.*s reached the top limit for the discovarable devices\n", IFNAMSIZ, dev->iface);
1126 return 2;
1127 }
1128
1129 /* Get the device id */
1130 if (neighbours.dev_id == -1)
1131 {
1132 char addr[19] = { 0 }; //the device MAC address
1133
1134 ba2str((bdaddr_t *)&dev->pl_mac, addr);
1135 neighbours.dev_id = hci_devid(addr);
1136 if (neighbours.dev_id < 0)
1137 {
1138 fprintf(stderr, "Failed to get the device id for interface %.*s : %s\n", IFNAMSIZ,
1139 dev->iface, strerror(errno));
1140 return 1;
1141 }
1142 }
1143 1151
1144 devices = malloc(max_responses * sizeof(inquiry_info)); 1152 /* Get the device id */
1145 if (devices == NULL) 1153 if (neighbours.dev_id == -1)
1146 { 1154 {
1147 fprintf(stderr, "Failed to allocate memory for inquiry info list on interface %.*s\n", IFNAMSIZ, 1155 char addr[19] = { 0 }; // the device MAC address
1148 dev->iface);
1149 return 1;
1150 }
1151 1156
1152 responses = hci_inquiry(neighbours.dev_id, 8, max_responses, NULL, &devices, IREQ_CACHE_FLUSH); 1157 ba2str ((bdaddr_t *) &dev->pl_mac, addr);
1153 if (responses < 0) 1158 neighbours.dev_id = hci_devid (addr);
1154 { 1159 if (neighbours.dev_id < 0)
1155 fprintf(stderr, "Failed to inquiry on interface %.*s\n", IFNAMSIZ, dev->iface); 1160 {
1156 return 1; 1161 fprintf (stderr,
1157 } 1162 "Failed to get the device id for interface %.*s : %s\n",
1163 IFNAMSIZ,
1164 dev->iface, strerror (errno));
1165 return 1;
1166 }
1167 }
1158 1168
1159 fprintf(stderr, "LOG : Found %d devices\n", responses); //FIXME delete it after debugging stage 1169 devices = malloc (max_responses * sizeof(inquiry_info));
1170 if (devices == NULL)
1171 {
1172 fprintf (stderr,
1173 "Failed to allocate memory for inquiry info list on interface %.*s\n",
1174 IFNAMSIZ,
1175 dev->iface);
1176 return 1;
1177 }
1160 1178
1161 if (responses == 0) 1179 responses = hci_inquiry (neighbours.dev_id, 8, max_responses, NULL,
1162 { 1180 &devices, IREQ_CACHE_FLUSH);
1163 fprintf(stderr, "LOG : No devices discoverable\n"); 1181 if (responses < 0)
1164 return 1; 1182 {
1165 } 1183 fprintf (stderr, "Failed to inquiry on interface %.*s\n", IFNAMSIZ,
1184 dev->iface);
1185 return 1;
1186 }
1166 1187
1167 for (i = 0; i < responses; i++) 1188 fprintf (stderr, "LOG : Found %d devices\n", responses); // FIXME delete it after debugging stage
1168 {
1169 int j;
1170 int found = 0;
1171 1189
1172 /* sanity check */ 1190 if (responses == 0)
1173 if (i >= MAX_PORTS) 1191 {
1174 { 1192 fprintf (stderr, "LOG : No devices discoverable\n");
1175 fprintf(stderr, "%.*s reached the top limit for the discoverable devices (after inquiry)\n", IFNAMSIZ, 1193 return 1;
1176 dev->iface); 1194 }
1177 return 2;
1178 }
1179 1195
1180 /* Search if the address already exists on the list */ 1196 for (i = 0; i < responses; i++)
1181 for (j = 0; j < neighbours.size; j++) 1197 {
1182 { 1198 int j;
1183 if (memcmp(&(devices + i)->bdaddr, &(neighbours.devices[j]), sizeof(bdaddr_t)) == 0) 1199 int found = 0;
1184 {
1185 found = 1;
1186 fprintf(stderr, "LOG : the device already exists on the list\n"); //FIXME debugging message
1187 break;
1188 }
1189 }
1190 1200
1191 if (found == 0) 1201 /* sanity check */
1192 { 1202 if (i >= MAX_PORTS)
1193 char addr[19] = { 0 }; 1203 {
1204 fprintf (stderr,
1205 "%.*s reached the top limit for the discoverable devices (after inquiry)\n",
1206 IFNAMSIZ,
1207 dev->iface);
1208 return 2;
1209 }
1194 1210
1195 ba2str(&(devices + i)->bdaddr, addr); 1211 /* Search if the address already exists on the list */
1196 fprintf(stderr, "LOG : %s was added to the list\n", addr); //FIXME debugging message 1212 for (j = 0; j < neighbours.size; j++)
1197 GNUNET_memcpy(&(neighbours.devices[neighbours.size++]), &(devices + i)->bdaddr, sizeof(bdaddr_t)); 1213 {
1198 } 1214 if (memcmp (&(devices + i)->bdaddr, &(neighbours.devices[j]),
1215 sizeof(bdaddr_t)) == 0)
1216 {
1217 found = 1;
1218 fprintf (stderr, "LOG : the device already exists on the list\n"); // FIXME debugging message
1219 break;
1199 } 1220 }
1221 }
1222
1223 if (found == 0)
1224 {
1225 char addr[19] = { 0 };
1200 1226
1201 free(devices); 1227 ba2str (&(devices + i)->bdaddr, addr);
1228 fprintf (stderr, "LOG : %s was added to the list\n", addr); // FIXME debugging message
1229 GNUNET_memcpy (&(neighbours.devices[neighbours.size++]), &(devices
1230 + i)->
1231 bdaddr, sizeof(bdaddr_t));
1232 }
1202 } 1233 }
1234
1235 free (devices);
1203 } 1236 }
1237 }
1204 1238
1205 int connection_successful = 0; 1239 int connection_successful = 0;
1206 struct sockaddr_rc addr_rc = { 0 }; 1240 struct sockaddr_rc addr_rc = { 0 };
@@ -1209,115 +1243,120 @@ inquiry_devices: //skip the conditions and force a inquiry for new devices
1209 1243
1210 /* Try to connect to a new device from the list */ 1244 /* Try to connect to a new device from the list */
1211 while (neighbours.pos < neighbours.size) 1245 while (neighbours.pos < neighbours.size)
1246 {
1247 /* Check if we are already connected to this device */
1248 if (neighbours.fds[neighbours.pos] == -1)
1212 { 1249 {
1213 /* Check if we are already connected to this device */ 1250 memset (&addr_rc.rc_bdaddr, 0, sizeof(addr_rc.rc_bdaddr));
1214 if (neighbours.fds[neighbours.pos] == -1) 1251 GNUNET_memcpy (&addr_rc.rc_bdaddr, &(neighbours.devices[neighbours.pos]),
1215 { 1252 sizeof(addr_rc.rc_bdaddr));
1216 memset(&addr_rc.rc_bdaddr, 0, sizeof(addr_rc.rc_bdaddr));
1217 GNUNET_memcpy(&addr_rc.rc_bdaddr, &(neighbours.devices[neighbours.pos]), sizeof(addr_rc.rc_bdaddr));
1218 1253
1219 addr_rc.rc_channel = get_channel(dev, addr_rc.rc_bdaddr); 1254 addr_rc.rc_channel = get_channel (dev, addr_rc.rc_bdaddr);
1220 1255
1221 *sendsocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 1256 *sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
1222 if ((-1 < *sendsocket) && 1257 if ((-1 < *sendsocket) &&
1223 (0 == connect(*sendsocket, 1258 (0 == connect (*sendsocket,
1224 (struct sockaddr *)&addr_rc, 1259 (struct sockaddr *) &addr_rc,
1225 sizeof(addr_rc)))) 1260 sizeof(addr_rc))))
1226 { 1261 {
1227 neighbours.fds[neighbours.pos++] = *sendsocket; 1262 neighbours.fds[neighbours.pos++] = *sendsocket;
1228 connection_successful = 1; 1263 connection_successful = 1;
1229 char addr[19] = { 0 }; 1264 char addr[19] = { 0 };
1230 ba2str(&(neighbours.devices[neighbours.pos - 1]), addr); 1265 ba2str (&(neighbours.devices[neighbours.pos - 1]), addr);
1231 fprintf(stderr, "LOG : Connected to %s\n", addr); 1266 fprintf (stderr, "LOG : Connected to %s\n", addr);
1232 break; 1267 break;
1233 } 1268 }
1234 else 1269 else
1235 { 1270 {
1236 char addr[19] = { 0 }; 1271 char addr[19] = { 0 };
1237 errno_copy = errno; //Save a copy for later 1272 errno_copy = errno; // Save a copy for later
1238 1273
1239 if (-1 != *sendsocket) 1274 if (-1 != *sendsocket)
1240 { 1275 {
1241 (void)close(*sendsocket); 1276 (void) close (*sendsocket);
1242 *sendsocket = -1; 1277 *sendsocket = -1;
1243 } 1278 }
1244 ba2str(&(neighbours.devices[neighbours.pos]), addr); 1279 ba2str (&(neighbours.devices[neighbours.pos]), addr);
1245 fprintf(stderr, 1280 fprintf (stderr,
1246 "LOG : Couldn't connect on device %s, error : %s\n", 1281 "LOG : Couldn't connect on device %s, error : %s\n",
1247 addr, 1282 addr,
1248 strerror(errno)); 1283 strerror (errno));
1249 if (errno != ECONNREFUSED) //FIXME be sure that this works 1284 if (errno != ECONNREFUSED) // FIXME be sure that this works
1250 { 1285 {
1251 fprintf(stderr, "LOG : Removes %d device from the list\n", neighbours.pos); 1286 fprintf (stderr, "LOG : Removes %d device from the list\n",
1252 /* Remove the device from the list */ 1287 neighbours.pos);
1253 GNUNET_memcpy(&neighbours.devices[neighbours.pos], &neighbours.devices[neighbours.size - 1], sizeof(bdaddr_t)); 1288 /* Remove the device from the list */
1254 memset(&neighbours.devices[neighbours.size - 1], 0, sizeof(bdaddr_t)); 1289 GNUNET_memcpy (&neighbours.devices[neighbours.pos],
1255 neighbours.fds[neighbours.pos] = neighbours.fds[neighbours.size - 1]; 1290 &neighbours.devices[neighbours.size - 1],
1256 neighbours.fds[neighbours.size - 1] = -1; 1291 sizeof(bdaddr_t));
1257 neighbours.size -= 1; 1292 memset (&neighbours.devices[neighbours.size - 1], 0,
1258 } 1293 sizeof(bdaddr_t));
1294 neighbours.fds[neighbours.pos] = neighbours.fds[neighbours.size - 1];
1295 neighbours.fds[neighbours.size - 1] = -1;
1296 neighbours.size -= 1;
1297 }
1259 1298
1260 neighbours.pos += 1; 1299 neighbours.pos += 1;
1261 1300
1262 if (neighbours.pos >= neighbours.size) 1301 if (neighbours.pos >= neighbours.size)
1263 neighbours.pos = 0; 1302 neighbours.pos = 0;
1264 1303
1265 loops += 1; 1304 loops += 1;
1266 1305
1267 if (loops == MAX_LOOPS) //don't get stuck trying to connect to one device 1306 if (loops == MAX_LOOPS) // don't get stuck trying to connect to one device
1268 return 1; 1307 return 1;
1269 } 1308 }
1270 } 1309 }
1271 else 1310 else
1272 { 1311 {
1273 fprintf(stderr, "LOG : Search for a new device\n"); //FIXME debugging message 1312 fprintf (stderr, "LOG : Search for a new device\n"); // FIXME debugging message
1274 neighbours.pos += 1; 1313 neighbours.pos += 1;
1275 }
1276 } 1314 }
1315 }
1277 1316
1278 /* Cycle on the list */ 1317 /* Cycle on the list */
1279 if (neighbours.pos == neighbours.size) 1318 if (neighbours.pos == neighbours.size)
1280 { 1319 {
1281 neighbours.pos = 0; 1320 neighbours.pos = 0;
1282 searching_devices_count += 1; 1321 searching_devices_count += 1;
1283 1322
1284 if (searching_devices_count == MAX_LOOPS) 1323 if (searching_devices_count == MAX_LOOPS)
1285 { 1324 {
1286 fprintf(stderr, "LOG : Force to inquiry for new devices\n"); 1325 fprintf (stderr, "LOG : Force to inquiry for new devices\n");
1287 searching_devices_count = 0; 1326 searching_devices_count = 0;
1288 goto inquiry_devices; 1327 goto inquiry_devices;
1289 }
1290 } 1328 }
1329 }
1291 /* If a new device wasn't found, search an old one */ 1330 /* If a new device wasn't found, search an old one */
1292 if (connection_successful == 0) 1331 if (connection_successful == 0)
1332 {
1333 int loop_check = neighbours.pos;
1334 while (neighbours.fds[neighbours.pos] == -1)
1293 { 1335 {
1294 int loop_check = neighbours.pos; 1336 if (neighbours.pos == neighbours.size)
1295 while (neighbours.fds[neighbours.pos] == -1) 1337 neighbours.pos = 0;
1296 {
1297 if (neighbours.pos == neighbours.size)
1298 neighbours.pos = 0;
1299
1300 if (neighbours.pos == loop_check)
1301 {
1302 if (errno_copy == ECONNREFUSED)
1303 {
1304 fprintf(stderr, "LOG : No device found. Go back and search again\n"); //FIXME debugging message
1305 new_device = 1;
1306 loops += 1;
1307 goto search_for_devices;
1308 }
1309 else
1310 {
1311 return 1; // Skip the broadcast message
1312 }
1313 }
1314 1338
1315 neighbours.pos += 1; 1339 if (neighbours.pos == loop_check)
1340 {
1341 if (errno_copy == ECONNREFUSED)
1342 {
1343 fprintf (stderr, "LOG : No device found. Go back and search again\n"); // FIXME debugging message
1344 new_device = 1;
1345 loops += 1;
1346 goto search_for_devices;
1316 } 1347 }
1348 else
1349 {
1350 return 1; // Skip the broadcast message
1351 }
1352 }
1317 1353
1318 *sendsocket = neighbours.fds[neighbours.pos++]; 1354 neighbours.pos += 1;
1319 } 1355 }
1320 1356
1357 *sendsocket = neighbours.fds[neighbours.pos++];
1358 }
1359
1321 return 0; 1360 return 0;
1322} 1361}
1323#endif 1362#endif
@@ -1334,7 +1373,7 @@ inquiry_devices: //skip the conditions and force a inquiry for new devices
1334 **** similar to gnunet-helper-transport-wlan.c **** 1373 **** similar to gnunet-helper-transport-wlan.c ****
1335 */ 1374 */
1336int 1375int
1337main(int argc, char *argv[]) 1376main (int argc, char *argv[])
1338{ 1377{
1339#ifdef LINUX 1378#ifdef LINUX
1340 struct HardwareInfos dev; 1379 struct HardwareInfos dev;
@@ -1351,83 +1390,85 @@ main(int argc, char *argv[])
1351 /* Assert privs so we can modify the firewall rules! */ 1390 /* Assert privs so we can modify the firewall rules! */
1352 { 1391 {
1353#ifdef HAVE_SETRESUID 1392#ifdef HAVE_SETRESUID
1354 uid_t uid = getuid(); 1393 uid_t uid = getuid ();
1355 1394
1356 if (0 != setresuid(uid, 0, 0)) 1395 if (0 != setresuid (uid, 0, 0))
1357 { 1396 {
1358 fprintf(stderr, 1397 fprintf (stderr,
1359 "Failed to setresuid to root: %s\n", 1398 "Failed to setresuid to root: %s\n",
1360 strerror(errno)); 1399 strerror (errno));
1361 return 254; 1400 return 254;
1362 } 1401 }
1363#else 1402#else
1364 if (0 != seteuid(0)) 1403 if (0 != seteuid (0))
1365 { 1404 {
1366 fprintf(stderr, 1405 fprintf (stderr,
1367 "Failed to seteuid back to root: %s\n", strerror(errno)); 1406 "Failed to seteuid back to root: %s\n", strerror (errno));
1368 return 254; 1407 return 254;
1369 } 1408 }
1370#endif 1409#endif
1371 } 1410 }
1372 1411
1373 /* Make use of SGID capabilities on POSIX */ 1412 /* Make use of SGID capabilities on POSIX */
1374 memset(&dev, 0, sizeof(dev)); 1413 memset (&dev, 0, sizeof(dev));
1375 dev.fd_rfcomm = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 1414 dev.fd_rfcomm = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
1376 raw_eno = errno; /* remember for later */ 1415 raw_eno = errno; /* remember for later */
1377 1416
1378 /* Now that we've dropped root rights, we can do error checking */ 1417 /* Now that we've dropped root rights, we can do error checking */
1379 if (2 != argc) 1418 if (2 != argc)
1380 { 1419 {
1381 fprintf(stderr, "You must specify the name of the interface as the first \ 1420 fprintf (stderr,
1421 "You must specify the name of the interface as the first \
1382 and only argument to this program.\n"); 1422 and only argument to this program.\n");
1383 if (-1 != dev.fd_rfcomm) 1423 if (-1 != dev.fd_rfcomm)
1384 (void)close(dev.fd_rfcomm); 1424 (void) close (dev.fd_rfcomm);
1385 return 1; 1425 return 1;
1386 } 1426 }
1387 1427
1388 if (-1 == dev.fd_rfcomm) 1428 if (-1 == dev.fd_rfcomm)
1389 { 1429 {
1390 fprintf(stderr, "Failed to create a RFCOMM socket: %s\n", strerror(raw_eno)); 1430 fprintf (stderr, "Failed to create a RFCOMM socket: %s\n", strerror (
1391 return 1; 1431 raw_eno));
1392 } 1432 return 1;
1433 }
1393 if (dev.fd_rfcomm >= FD_SETSIZE) 1434 if (dev.fd_rfcomm >= FD_SETSIZE)
1435 {
1436 fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
1437 dev.fd_rfcomm, FD_SETSIZE);
1438 (void) close (dev.fd_rfcomm);
1439 return 1;
1440 }
1441 if (0 != test_bluetooth_interface (argv[1]))
1442 {
1443 (void) close (dev.fd_rfcomm);
1444 return 1;
1445 }
1446 strncpy (dev.iface, argv[1], IFNAMSIZ);
1447 if (0 != open_device (&dev))
1448 {
1449 (void) close (dev.fd_rfcomm);
1450 return 1;
1451 }
1452
1453 /* Drop privs */
1454 {
1455 uid_t uid = getuid ();
1456 #ifdef HAVE_SETRESUID
1457 if (0 != setresuid (uid, uid, uid))
1394 { 1458 {
1395 fprintf(stderr, "File descriptor too large for select (%d > %d)\n", 1459 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
1396 dev.fd_rfcomm, FD_SETSIZE); 1460 if (-1 != dev.fd_rfcomm)
1397 (void)close(dev.fd_rfcomm); 1461 (void) close (dev.fd_rfcomm);
1398 return 1;
1399 }
1400 if (0 != test_bluetooth_interface(argv[1]))
1401 {
1402 (void)close(dev.fd_rfcomm);
1403 return 1; 1462 return 1;
1404 } 1463 }
1405 strncpy(dev.iface, argv[1], IFNAMSIZ); 1464 #else
1406 if (0 != open_device(&dev)) 1465 if (0 != (setuid (uid) | seteuid (uid)))
1407 { 1466 {
1408 (void)close(dev.fd_rfcomm); 1467 fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
1468 if (-1 != dev.fd_rfcomm)
1469 (void) close (dev.fd_rfcomm);
1409 return 1; 1470 return 1;
1410 } 1471 }
1411
1412 /* Drop privs */
1413 {
1414 uid_t uid = getuid();
1415 #ifdef HAVE_SETRESUID
1416 if (0 != setresuid(uid, uid, uid))
1417 {
1418 fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno));
1419 if (-1 != dev.fd_rfcomm)
1420 (void)close(dev.fd_rfcomm);
1421 return 1;
1422 }
1423 #else
1424 if (0 != (setuid(uid) | seteuid(uid)))
1425 {
1426 fprintf(stderr, "Failed to setuid: %s\n", strerror(errno));
1427 if (-1 != dev.fd_rfcomm)
1428 (void)close(dev.fd_rfcomm);
1429 return 1;
1430 }
1431 #endif 1472 #endif
1432 } 1473 }
1433 1474
@@ -1435,15 +1476,16 @@ main(int argc, char *argv[])
1435 { 1476 {
1436 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 1477 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
1437 1478
1438 macmsg.hdr.size = htons(sizeof(macmsg)); 1479 macmsg.hdr.size = htons (sizeof(macmsg));
1439 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 1480 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
1440 GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)); 1481 GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof(struct
1441 GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg)); 1482 GNUNET_TRANSPORT_WLAN_MacAddress));
1483 GNUNET_memcpy (write_std.buf, &macmsg, sizeof(macmsg));
1442 write_std.size = sizeof(macmsg); 1484 write_std.size = sizeof(macmsg);
1443 } 1485 }
1444 1486
1445 1487
1446 stdin_mst = mst_create(&stdin_send_hw, &dev); 1488 stdin_mst = mst_create (&stdin_send_hw, &dev);
1447 stdin_open = 1; 1489 stdin_open = 1;
1448 1490
1449 /** 1491 /**
@@ -1451,348 +1493,381 @@ main(int argc, char *argv[])
1451 * from get_wlan_header (plugin_transport_bluetooth.c) is correct. 1493 * from get_wlan_header (plugin_transport_bluetooth.c) is correct.
1452 */ 1494 */
1453 while (1) 1495 while (1)
1496 {
1497 maxfd = -1;
1498 broadcast = 0;
1499 sendsocket = -1;
1500
1501 FD_ZERO (&rfds);
1502 if ((0 == write_pout.size) && (1 == stdin_open))
1503 {
1504 FD_SET (STDIN_FILENO, &rfds);
1505 maxfd = MAX (maxfd, STDIN_FILENO);
1506 }
1507 if (0 == write_std.size)
1454 { 1508 {
1455 maxfd = -1; 1509 FD_SET (dev.fd_rfcomm, &rfds);
1456 broadcast = 0; 1510 maxfd = MAX (maxfd, dev.fd_rfcomm);
1457 sendsocket = -1; 1511 }
1458 1512
1459 FD_ZERO(&rfds); 1513 for (i = 0; i < crt_rfds; i++) // it can receive messages from multiple devices
1460 if ((0 == write_pout.size) && (1 == stdin_open)) 1514 {
1461 { 1515 FD_SET (rfds_list[i], &rfds);
1462 FD_SET(STDIN_FILENO, &rfds); 1516 maxfd = MAX (maxfd, rfds_list[i]);
1463 maxfd = MAX(maxfd, STDIN_FILENO); 1517 }
1464 } 1518 FD_ZERO (&wfds);
1465 if (0 == write_std.size) 1519 if (0 < write_std.size)
1520 {
1521 FD_SET (STDOUT_FILENO, &wfds);
1522 maxfd = MAX (maxfd, STDOUT_FILENO);
1523 }
1524 if (0 < write_pout.size) // it can send messages only to one device per loop
1525 {
1526 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *frame;
1527 /* Get the destination address */
1528 frame = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) write_pout.buf;
1529
1530 if (memcmp (&frame->addr1, &dev.pl_mac,
1531 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
1532 {
1533 broadcast = 1;
1534 memset (&write_pout, 0, sizeof(write_pout)); // clear the buffer
1535 }
1536 else if (memcmp (&frame->addr1, &broadcast_address,
1537 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
1538 {
1539 fprintf (stderr, "LOG : %s has a broadcast message (pos %d, size %d)\n",
1540 dev.iface, neighbours.pos, neighbours.size); // FIXME: debugging message
1541
1542 if (send_broadcast (&dev, &sendsocket) != 0) // if the searching wasn't successful don't get stuck on the select stage
1466 { 1543 {
1467 FD_SET(dev.fd_rfcomm, &rfds); 1544 broadcast = 1;
1468 maxfd = MAX(maxfd, dev.fd_rfcomm); 1545 memset (&write_pout, 0, sizeof(write_pout)); // remove the message
1546 fprintf (stderr,
1547 "LOG : Skipping the broadcast message (pos %d, size %d)\n",
1548 neighbours.pos, neighbours.size);
1469 } 1549 }
1470 1550 else
1471 for (i = 0; i < crt_rfds; i++) // it can receive messages from multiple devices
1472 { 1551 {
1473 FD_SET(rfds_list[i], &rfds); 1552 FD_SET (sendsocket, &wfds);
1474 maxfd = MAX(maxfd, rfds_list[i]); 1553 maxfd = MAX (maxfd, sendsocket);
1475 } 1554 }
1476 FD_ZERO(&wfds); 1555 }
1477 if (0 < write_std.size) 1556 else
1557 {
1558 int found = 0;
1559 int pos = 0;
1560 /* Search if the address already exists on the list */
1561 for (i = 0; i < neighbours.size; i++)
1478 { 1562 {
1479 FD_SET(STDOUT_FILENO, &wfds); 1563 if (memcmp (&frame->addr1, &(neighbours.devices[i]),
1480 maxfd = MAX(maxfd, STDOUT_FILENO); 1564 sizeof(bdaddr_t)) == 0)
1565 {
1566 pos = i;
1567 if (neighbours.fds[i] != -1)
1568 {
1569 found = 1; // save the position where it was found
1570 FD_SET (neighbours.fds[i], &wfds);
1571 maxfd = MAX (maxfd, neighbours.fds[i]);
1572 sendsocket = neighbours.fds[i];
1573 fprintf (stderr, "LOG: the address was found in the list\n");
1574 break;
1575 }
1576 }
1481 } 1577 }
1482 if (0 < write_pout.size) //it can send messages only to one device per loop 1578 if (found == 0)
1483 { 1579 {
1484 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *frame; 1580 int status;
1485 /* Get the destination address */ 1581 struct sockaddr_rc addr = { 0 };
1486 frame = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)write_pout.buf;
1487 1582
1488 if (memcmp(&frame->addr1, &dev.pl_mac, 1583 fprintf (stderr,
1489 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0) 1584 "LOG : %s has a new message for %.2X:%.2X:%.2X:%.2X:%.2X:%.2X which isn't on the broadcast list\n",
1585 dev.iface,
1586 frame->addr1.mac[5], frame->addr1.mac[4],
1587 frame->addr1.mac[3],
1588 frame->addr1.mac[2], frame->addr1.mac[1],
1589 frame->addr1.mac[0]); // FIXME: debugging message
1590
1591 sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
1592
1593 if (sendsocket < 0)
1594 {
1595 fprintf (stderr,
1596 "Failed to create a RFCOMM socket (sending stage): %s\n",
1597 strerror (errno));
1598 return -1;
1599 }
1600
1601 GNUNET_memcpy (&addr.rc_bdaddr, &frame->addr1, sizeof(bdaddr_t));
1602 addr.rc_family = AF_BLUETOOTH;
1603 addr.rc_channel = get_channel (&dev, addr.rc_bdaddr);
1604
1605 int tries = 0;
1606connect_retry:
1607 status = connect (sendsocket, (struct sockaddr *) &addr,
1608 sizeof(addr));
1609 if ((0 != status) &&(errno != EAGAIN) )
1610 {
1611 if ((errno == ECONNREFUSED) &&(tries < 2) )
1612 {
1613 fprintf (stderr, "LOG : %.*s failed to connect. Trying again!\n",
1614 IFNAMSIZ, dev.iface);
1615 tries++;
1616 goto connect_retry;
1617 }
1618 else if (errno == EBADF)
1490 { 1619 {
1620 fprintf (stderr, "LOG : %s failed to connect : %s. Skip it!\n",
1621 dev.iface, strerror (errno));
1622 memset (&write_pout, 0, sizeof(write_pout));
1491 broadcast = 1; 1623 broadcast = 1;
1492 memset(&write_pout, 0, sizeof(write_pout)); //clear the buffer
1493 } 1624 }
1494 else if (memcmp(&frame->addr1, &broadcast_address, 1625 else
1495 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
1496 { 1626 {
1497 fprintf(stderr, "LOG : %s has a broadcast message (pos %d, size %d)\n", dev.iface, neighbours.pos, neighbours.size); //FIXME: debugging message 1627 fprintf (stderr,
1498 1628 "LOG : %s failed to connect : %s. Try again later!\n",
1499 if (send_broadcast(&dev, &sendsocket) != 0) //if the searching wasn't successful don't get stuck on the select stage 1629 dev.iface,
1500 { 1630 strerror (errno));
1501 broadcast = 1; 1631 memset (&write_pout, 0, sizeof(write_pout));
1502 memset(&write_pout, 0, sizeof(write_pout)); //remove the message 1632 broadcast = 1;
1503 fprintf(stderr, "LOG : Skipping the broadcast message (pos %d, size %d)\n", neighbours.pos, neighbours.size);
1504 }
1505 else
1506 {
1507 FD_SET(sendsocket, &wfds);
1508 maxfd = MAX(maxfd, sendsocket);
1509 }
1510 } 1633 }
1634 }
1511 else 1635 else
1636 {
1637 FD_SET (sendsocket, &wfds);
1638 maxfd = MAX (maxfd, sendsocket);
1639 fprintf (stderr, "LOG : Connection successful\n");
1640 if (pos != 0) // save the socket
1512 { 1641 {
1513 int found = 0; 1642 neighbours.fds[pos] = sendsocket;
1514 int pos = 0;
1515 /* Search if the address already exists on the list */
1516 for (i = 0; i < neighbours.size; i++)
1517 {
1518 if (memcmp(&frame->addr1, &(neighbours.devices[i]), sizeof(bdaddr_t)) == 0)
1519 {
1520 pos = i;
1521 if (neighbours.fds[i] != -1)
1522 {
1523 found = 1; //save the position where it was found
1524 FD_SET(neighbours.fds[i], &wfds);
1525 maxfd = MAX(maxfd, neighbours.fds[i]);
1526 sendsocket = neighbours.fds[i];
1527 fprintf(stderr, "LOG: the address was found in the list\n");
1528 break;
1529 }
1530 }
1531 }
1532 if (found == 0)
1533 {
1534 int status;
1535 struct sockaddr_rc addr = { 0 };
1536
1537 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,
1538 frame->addr1.mac[5], frame->addr1.mac[4], frame->addr1.mac[3],
1539 frame->addr1.mac[2], frame->addr1.mac[1], frame->addr1.mac[0]); //FIXME: debugging message
1540
1541 sendsocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
1542
1543 if (sendsocket < 0)
1544 {
1545 fprintf(stderr, "Failed to create a RFCOMM socket (sending stage): %s\n",
1546 strerror(errno));
1547 return -1;
1548 }
1549
1550 GNUNET_memcpy(&addr.rc_bdaddr, &frame->addr1, sizeof(bdaddr_t));
1551 addr.rc_family = AF_BLUETOOTH;
1552 addr.rc_channel = get_channel(&dev, addr.rc_bdaddr);
1553
1554 int tries = 0;
1555connect_retry:
1556 status = connect(sendsocket, (struct sockaddr *)&addr, sizeof(addr));
1557 if (0 != status && errno != EAGAIN)
1558 {
1559 if (errno == ECONNREFUSED && tries < 2)
1560 {
1561 fprintf(stderr, "LOG : %.*s failed to connect. Trying again!\n", IFNAMSIZ, dev.iface);
1562 tries++;
1563 goto connect_retry;
1564 }
1565 else if (errno == EBADF)
1566 {
1567 fprintf(stderr, "LOG : %s failed to connect : %s. Skip it!\n", dev.iface, strerror(errno));
1568 memset(&write_pout, 0, sizeof(write_pout));
1569 broadcast = 1;
1570 }
1571 else
1572 {
1573 fprintf(stderr, "LOG : %s failed to connect : %s. Try again later!\n", dev.iface, strerror(errno));
1574 memset(&write_pout, 0, sizeof(write_pout));
1575 broadcast = 1;
1576 }
1577 }
1578 else
1579 {
1580 FD_SET(sendsocket, &wfds);
1581 maxfd = MAX(maxfd, sendsocket);
1582 fprintf(stderr, "LOG : Connection successful\n");
1583 if (pos != 0) // save the socket
1584 {
1585 neighbours.fds[pos] = sendsocket;
1586 }
1587 else
1588 {
1589 /* Add the new device to the discovered devices list */
1590 if (neighbours.size < MAX_PORTS)
1591 {
1592 neighbours.fds[neighbours.size] = sendsocket;
1593 GNUNET_memcpy(&(neighbours.devices[neighbours.size++]), &addr.rc_bdaddr, sizeof(bdaddr_t));
1594 }
1595 else
1596 {
1597 fprintf(stderr, "The top limit for the discovarable devices' list was reached\n");
1598 }
1599 }
1600 }
1601 }
1602 } 1643 }
1644 else
1645 {
1646 /* Add the new device to the discovered devices list */
1647 if (neighbours.size < MAX_PORTS)
1648 {
1649 neighbours.fds[neighbours.size] = sendsocket;
1650 GNUNET_memcpy (&(neighbours.devices[neighbours.size++]),
1651 &addr.rc_bdaddr, sizeof(bdaddr_t));
1652 }
1653 else
1654 {
1655 fprintf (stderr,
1656 "The top limit for the discovarable devices' list was reached\n");
1657 }
1658 }
1659 }
1603 } 1660 }
1661 }
1662 }
1604 1663
1605 if (broadcast == 0) 1664 if (broadcast == 0)
1665 {
1666 /* Select a fd which is ready for action :) */
1667 {
1668 int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
1669 if ((-1 == retval) && (EINTR == errno))
1670 continue;
1671 if ((0 > retval) &&(errno != EBADF) ) // we handle BADF errors later
1672 {
1673 fprintf (stderr, "select failed: %s\n", strerror (errno));
1674 break;
1675 }
1676 }
1677 if (FD_ISSET (STDOUT_FILENO, &wfds))
1678 {
1679 ssize_t ret =
1680 write (STDOUT_FILENO, write_std.buf + write_std.pos,
1681 write_std.size - write_std.pos);
1682 if (0 > ret)
1683 {
1684 fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
1685 break;
1686 }
1687 write_std.pos += ret;
1688 if (write_std.pos == write_std.size)
1606 { 1689 {
1607 /* Select a fd which is ready for action :) */ 1690 write_std.pos = 0;
1691 write_std.size = 0;
1692 }
1693 fprintf (stderr, "LOG : %s sends a message to STDOUT\n", dev.iface); // FIXME: debugging message
1694 }
1695 if (-1 != sendsocket)
1696 {
1697 if (FD_ISSET (sendsocket, &wfds))
1698 {
1699 ssize_t ret = write (sendsocket,
1700 write_pout.buf + write_std.pos,
1701 write_pout.size - write_pout.pos);
1702 if (0 > ret) // FIXME should I first check the error type?
1608 { 1703 {
1609 int retval = select(maxfd + 1, &rfds, &wfds, NULL, NULL); 1704 fprintf (stderr,
1610 if ((-1 == retval) && (EINTR == errno)) 1705 "Failed to write to bluetooth device: %s. Closing the socket!\n",
1611 continue; 1706 strerror (errno));
1612 if (0 > retval && errno != EBADF) // we handle BADF errors later 1707 for (i = 0; i < neighbours.size; i++)
1708 {
1709 if (neighbours.fds[i] == sendsocket)
1613 { 1710 {
1614 fprintf(stderr, "select failed: %s\n", strerror(errno)); 1711 (void) close (sendsocket);
1712 neighbours.fds[i] = -1;
1615 break; 1713 break;
1616 } 1714 }
1715 }
1716 /* Remove the message */
1717 memset (&write_pout.buf + write_std.pos, 0, (write_pout.size
1718 - write_pout.pos));
1719 write_pout.pos = 0;
1720 write_pout.size = 0;
1617 } 1721 }
1618 if (FD_ISSET(STDOUT_FILENO, &wfds)) 1722 else
1723 {
1724 write_pout.pos += ret;
1725 if ((write_pout.pos != write_pout.size) && (0 != ret))
1619 { 1726 {
1620 ssize_t ret = 1727 /* We should not get partial sends with packet-oriented devices... */
1621 write(STDOUT_FILENO, write_std.buf + write_std.pos, 1728 fprintf (stderr, "Write error, partial send: %u/%u\n",
1622 write_std.size - write_std.pos); 1729 (unsigned int) write_pout.pos,
1623 if (0 > ret) 1730 (unsigned int) write_pout.size);
1624 { 1731 break;
1625 fprintf(stderr, "Failed to write to STDOUT: %s\n", strerror(errno));
1626 break;
1627 }
1628 write_std.pos += ret;
1629 if (write_std.pos == write_std.size)
1630 {
1631 write_std.pos = 0;
1632 write_std.size = 0;
1633 }
1634 fprintf(stderr, "LOG : %s sends a message to STDOUT\n", dev.iface); //FIXME: debugging message
1635 } 1732 }
1636 if (-1 != sendsocket) 1733
1734 if (write_pout.pos == write_pout.size)
1637 { 1735 {
1638 if (FD_ISSET(sendsocket, &wfds)) 1736 write_pout.pos = 0;
1639 { 1737 write_pout.size = 0;
1640 ssize_t ret = write(sendsocket, 1738 }
1641 write_pout.buf + write_std.pos, 1739 fprintf (stderr, "LOG : %s sends a message to a DEVICE\n",
1642 write_pout.size - write_pout.pos); 1740 dev.iface); // FIXME: debugging message
1643 if (0 > ret) //FIXME should I first check the error type? 1741 }
1644 { 1742 }
1645 fprintf(stderr, "Failed to write to bluetooth device: %s. Closing the socket!\n", 1743 }
1646 strerror(errno)); 1744 for (i = 0; i <= maxfd; i++)
1647 for (i = 0; i < neighbours.size; i++) 1745 {
1648 { 1746 if (FD_ISSET (i, &rfds))
1649 if (neighbours.fds[i] == sendsocket) 1747 {
1650 { 1748 if (i == STDIN_FILENO)
1651 (void)close(sendsocket); 1749 {
1652 neighbours.fds[i] = -1; 1750 ssize_t ret =
1653 break; 1751 read (i, readbuf, sizeof(readbuf));
1654 } 1752 if (0 > ret)
1655 } 1753 {
1656 /* Remove the message */ 1754 fprintf (stderr,
1657 memset(&write_pout.buf + write_std.pos, 0, (write_pout.size - write_pout.pos)); 1755 "Read error from STDIN: %s\n",
1658 write_pout.pos = 0; 1756 strerror (errno));
1659 write_pout.size = 0; 1757 break;
1660 }
1661 else
1662 {
1663 write_pout.pos += ret;
1664 if ((write_pout.pos != write_pout.size) && (0 != ret))
1665 {
1666 /* We should not get partial sends with packet-oriented devices... */
1667 fprintf(stderr, "Write error, partial send: %u/%u\n",
1668 (unsigned int)write_pout.pos,
1669 (unsigned int)write_pout.size);
1670 break;
1671 }
1672
1673 if (write_pout.pos == write_pout.size)
1674 {
1675 write_pout.pos = 0;
1676 write_pout.size = 0;
1677 }
1678 fprintf(stderr, "LOG : %s sends a message to a DEVICE\n", dev.iface); //FIXME: debugging message
1679 }
1680 }
1681 } 1758 }
1682 for (i = 0; i <= maxfd; i++) 1759 if (0 == ret)
1683 { 1760 {
1684 if (FD_ISSET(i, &rfds)) 1761 /* stop reading... */
1685 { 1762 stdin_open = 0;
1686 if (i == STDIN_FILENO) 1763 }
1687 { 1764 else
1688 ssize_t ret = 1765 {
1689 read(i, readbuf, sizeof(readbuf)); 1766 mst_receive (stdin_mst, readbuf, ret);
1690 if (0 > ret) 1767 fprintf (stderr, "LOG : %s receives a message from STDIN\n",
1691 { 1768 dev.iface); // FIXME: debugging message
1692 fprintf(stderr, 1769 }
1693 "Read error from STDIN: %s\n", 1770 }
1694 strerror(errno)); 1771 else if (i == dev.fd_rfcomm)
1695 break; 1772 {
1696 } 1773 int readsocket;
1697 if (0 == ret) 1774 struct sockaddr_rc addr = { 0 };
1698 { 1775 unsigned int opt = sizeof(addr);
1699 /* stop reading... */ 1776
1700 stdin_open = 0; 1777 readsocket = accept (dev.fd_rfcomm, (struct sockaddr *) &addr,
1701 } 1778 &opt);
1702 else 1779 fprintf (stderr, "LOG : %s accepts a message\n", dev.iface); // FIXME: debugging message
1703 { 1780 if (readsocket == -1)
1704 mst_receive(stdin_mst, readbuf, ret); 1781 {
1705 fprintf(stderr, "LOG : %s receives a message from STDIN\n", dev.iface); //FIXME: debugging message 1782 fprintf (stderr,
1706 } 1783 "Failed to accept a connection on interface: %.*s\n",
1707 } 1784 IFNAMSIZ,
1708 else if (i == dev.fd_rfcomm) 1785 strerror (errno));
1709 { 1786 break;
1710 int readsocket; 1787 }
1711 struct sockaddr_rc addr = { 0 }; 1788 else
1712 unsigned int opt = sizeof(addr); 1789 {
1713 1790 FD_SET (readsocket, &rfds);
1714 readsocket = accept(dev.fd_rfcomm, (struct sockaddr *)&addr, &opt); 1791 maxfd = MAX (maxfd, readsocket);
1715 fprintf(stderr, "LOG : %s accepts a message\n", dev.iface); //FIXME: debugging message 1792
1716 if (readsocket == -1) 1793 if (crt_rfds < MAX_PORTS)
1717 { 1794 rfds_list[crt_rfds++] = readsocket;
1718 fprintf(stderr, "Failed to accept a connection on interface: %.*s\n", IFNAMSIZ, 1795 else
1719 strerror(errno)); 1796 {
1720 break; 1797 fprintf (stderr,
1721 } 1798 "The limit for the read file descriptors list was \
1722 else
1723 {
1724 FD_SET(readsocket, &rfds);
1725 maxfd = MAX(maxfd, readsocket);
1726
1727 if (crt_rfds < MAX_PORTS)
1728 rfds_list[crt_rfds++] = readsocket;
1729 else
1730 {
1731 fprintf(stderr, "The limit for the read file descriptors list was \
1732 reached\n"); 1799 reached\n");
1733 break; 1800 break;
1734 } 1801 }
1735 } 1802 }
1736 } 1803 }
1737 else 1804 else
1738 { 1805 {
1739 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm; 1806 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
1740 ssize_t ret; 1807 ssize_t ret;
1741 fprintf(stderr, "LOG : %s reads something from the socket\n", dev.iface);//FIXME : debugging message 1808 fprintf (stderr, "LOG : %s reads something from the socket\n",
1742 rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf; 1809 dev.iface); // FIXME : debugging message
1743 ret = 1810 rrm = (struct
1744 read_from_the_socket((void *)&i, (unsigned char *)&rrm->frame, 1811 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
1745 sizeof(write_std.buf) 1812 ret =
1746 - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) 1813 read_from_the_socket ((void *) &i, (unsigned char *) &rrm->frame,
1747 + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame), 1814 sizeof(write_std.buf)
1748 rrm); 1815 - sizeof(struct
1749 if (0 >= ret) 1816 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
1750 { 1817 + sizeof(struct
1751 int j; 1818 GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
1752 FD_CLR(i, &rfds); 1819 rrm);
1753 close(i); 1820 if (0 >= ret)
1754 /* Remove the socket from the list */ 1821 {
1755 for (j = 0; j < crt_rfds; j++) 1822 int j;
1756 { 1823 FD_CLR (i, &rfds);
1757 if (rfds_list[j] == i) 1824 close (i);
1758 { 1825 /* Remove the socket from the list */
1759 rfds_list[j] ^= rfds_list[crt_rfds - 1]; 1826 for (j = 0; j < crt_rfds; j++)
1760 rfds_list[crt_rfds - 1] ^= rfds_list[j]; 1827 {
1761 rfds_list[j] ^= rfds_list[crt_rfds - 1]; 1828 if (rfds_list[j] == i)
1762 crt_rfds -= 1; 1829 {
1763 break; 1830 rfds_list[j] ^= rfds_list[crt_rfds - 1];
1764 } 1831 rfds_list[crt_rfds - 1] ^= rfds_list[j];
1765 } 1832 rfds_list[j] ^= rfds_list[crt_rfds - 1];
1766 1833 crt_rfds -= 1;
1767 fprintf(stderr, "Read error from raw socket: %s\n", strerror(errno)); 1834 break;
1768 break;
1769 }
1770 if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev)))
1771 {
1772 write_std.size = ret
1773 + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
1774 - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
1775 rrm->header.size = htons(write_std.size);
1776 rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
1777 }
1778 }
1779 } 1835 }
1836 }
1837
1838 fprintf (stderr, "Read error from raw socket: %s\n", strerror (
1839 errno));
1840 break;
1841 }
1842 if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
1843 {
1844 write_std.size = ret
1845 + sizeof(struct
1846 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
1847 - sizeof(struct
1848 GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
1849 rrm->header.size = htons (write_std.size);
1850 rrm->header.type = htons (
1851 GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
1780 } 1852 }
1853 }
1781 } 1854 }
1855 }
1782 } 1856 }
1857 }
1783 /* Error handling, try to clean up a bit at least */ 1858 /* Error handling, try to clean up a bit at least */
1784 mst_destroy(stdin_mst); 1859 mst_destroy (stdin_mst);
1785 stdin_mst = NULL; 1860 stdin_mst = NULL;
1786 sdp_close(dev.session); 1861 sdp_close (dev.session);
1787 (void)close(dev.fd_rfcomm); 1862 (void) close (dev.fd_rfcomm);
1788 if (-1 != sendsocket) 1863 if (-1 != sendsocket)
1789 (void)close(sendsocket); 1864 (void) close (sendsocket);
1790 1865
1791 for (i = 0; i < crt_rfds; i++) 1866 for (i = 0; i < crt_rfds; i++)
1792 (void)close(rfds_list[i]); 1867 (void) close (rfds_list[i]);
1793 1868
1794 for (i = 0; i < neighbours.size; i++) 1869 for (i = 0; i < neighbours.size; i++)
1795 (void)close(neighbours.fds[i]); 1870 (void) close (neighbours.fds[i]);
1796 #else 1871 #else
1797 struct HardwareInfos dev; 1872 struct HardwareInfos dev;
1798 struct GNUNET_NETWORK_Handle *sendsocket; 1873 struct GNUNET_NETWORK_Handle *sendsocket;
@@ -1803,25 +1878,25 @@ connect_retry:
1803 SOCKADDR_BTH acc_addr = { 0 }; 1878 SOCKADDR_BTH acc_addr = { 0 };
1804 int addr_len = sizeof(SOCKADDR_BTH); 1879 int addr_len = sizeof(SOCKADDR_BTH);
1805 int broadcast, i, stdin_open, crt_rfds = 0; 1880 int broadcast, i, stdin_open, crt_rfds = 0;
1806 HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE); 1881 HANDLE stdin_handle = GetStdHandle (STD_INPUT_HANDLE);
1807 HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); 1882 HANDLE stdout_handle = GetStdHandle (STD_OUTPUT_HANDLE);
1808 struct MessageStreamTokenizer *stdin_mst; 1883 struct MessageStreamTokenizer *stdin_mst;
1809 1884
1810 /* check the handles */ 1885 /* check the handles */
1811 if (stdin_handle == INVALID_HANDLE_VALUE) 1886 if (stdin_handle == INVALID_HANDLE_VALUE)
1812 { 1887 {
1813 fprintf(stderr, "Failed to get the stdin handle\n"); 1888 fprintf (stderr, "Failed to get the stdin handle\n");
1814 ExitProcess(2); 1889 ExitProcess (2);
1815 } 1890 }
1816 1891
1817 if (stdout_handle == INVALID_HANDLE_VALUE) 1892 if (stdout_handle == INVALID_HANDLE_VALUE)
1818 { 1893 {
1819 fprintf(stderr, "Failed to get the stdout handle\n"); 1894 fprintf (stderr, "Failed to get the stdout handle\n");
1820 ExitProcess(2); 1895 ExitProcess (2);
1821 } 1896 }
1822 1897
1823 /* initialize windows sockets */ 1898 /* initialize windows sockets */
1824 initialize_windows_sockets(); 1899 initialize_windows_sockets ();
1825 1900
1826 // /* test bluetooth socket family support */ --> it return false because the GNUNET_NETWORK_test_pf should also receive the type of socket (BTHPROTO_RFCOMM) 1901 // /* test bluetooth socket family support */ --> it return false because the GNUNET_NETWORK_test_pf should also receive the type of socket (BTHPROTO_RFCOMM)
1827 // if (GNUNET_NETWORK_test_pf (AF_BTH) != GNUNET_OK) 1902 // if (GNUNET_NETWORK_test_pf (AF_BTH) != GNUNET_OK)
@@ -1831,347 +1906,373 @@ connect_retry:
1831 // } 1906 // }
1832 1907
1833 /* create the socket */ 1908 /* create the socket */
1834 dev.handle = GNUNET_NETWORK_socket_create(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); 1909 dev.handle = GNUNET_NETWORK_socket_create (AF_BTH, SOCK_STREAM,
1910 BTHPROTO_RFCOMM);
1835 if (dev.handle == NULL) 1911 if (dev.handle == NULL)
1836 { 1912 {
1837 fprintf(stderr, "Failed to create RFCOMM socket: "); 1913 fprintf (stderr, "Failed to create RFCOMM socket: ");
1838 print_last_error(); 1914 print_last_error ();
1839 ExitProcess(2); 1915 ExitProcess (2);
1840 } 1916 }
1841 1917
1842 1918
1843 if (open_device(&dev) == -1) 1919 if (open_device (&dev) == -1)
1920 {
1921 fprintf (stderr, "Failed to open the device\n");
1922 print_last_error ();
1923 if (GNUNET_NETWORK_socket_close (dev.handle) != GNUNET_OK)
1844 { 1924 {
1845 fprintf(stderr, "Failed to open the device\n"); 1925 fprintf (stderr, "Failed to close the socket!\n");
1846 print_last_error(); 1926 print_last_error ();
1847 if (GNUNET_NETWORK_socket_close(dev.handle) != GNUNET_OK)
1848 {
1849 fprintf(stderr, "Failed to close the socket!\n");
1850 print_last_error();
1851 }
1852 ExitProcess(2);
1853 } 1927 }
1928 ExitProcess (2);
1929 }
1854 1930
1855 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(dev.handle, 1)) 1931 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (dev.handle, 1))
1856 { 1932 {
1857 fprintf(stderr, "Failed to change the socket mode\n"); 1933 fprintf (stderr, "Failed to change the socket mode\n");
1858 ExitProcess(2); 1934 ExitProcess (2);
1859 } 1935 }
1860 1936
1861 memset(&write_std, 0, sizeof(write_std)); 1937 memset (&write_std, 0, sizeof(write_std));
1862 memset(&write_pout, 0, sizeof(write_pout)); 1938 memset (&write_pout, 0, sizeof(write_pout));
1863 stdin_open = 1; 1939 stdin_open = 1;
1864 1940
1865 rfds = GNUNET_NETWORK_fdset_create(); 1941 rfds = GNUNET_NETWORK_fdset_create ();
1866 wfds = GNUNET_NETWORK_fdset_create(); 1942 wfds = GNUNET_NETWORK_fdset_create ();
1867 1943
1868 /* Send MAC address of the bluetooth interface to STDOUT first */ 1944 /* Send MAC address of the bluetooth interface to STDOUT first */
1869 { 1945 {
1870 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 1946 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
1871 1947
1872 macmsg.hdr.size = htons(sizeof(macmsg)); 1948 macmsg.hdr.size = htons (sizeof(macmsg));
1873 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 1949 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
1874 GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy)); 1950 GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof(struct
1875 GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg)); 1951 GNUNET_TRANSPORT_WLAN_MacAddress_Copy));
1952 GNUNET_memcpy (write_std.buf, &macmsg, sizeof(macmsg));
1876 write_std.size = sizeof(macmsg); 1953 write_std.size = sizeof(macmsg);
1877 } 1954 }
1878 1955
1879 1956
1880 stdin_mst = mst_create(&stdin_send_hw, &dev); 1957 stdin_mst = mst_create (&stdin_send_hw, &dev);
1881 stdin_open = 1; 1958 stdin_open = 1;
1882 1959
1883 int pos = 0; 1960 int pos = 0;
1884 int stdin_pos = -1; 1961 int stdin_pos = -1;
1885 int stdout_pos = -1; 1962 int stdout_pos = -1;
1886 while (1) 1963 while (1)
1964 {
1965 broadcast = 0;
1966 pos = 0;
1967 stdin_pos = -1;
1968 stdout_pos = -1;
1969 sendsocket = NULL; // FIXME ???memleaks
1970
1971 GNUNET_NETWORK_fdset_zero (rfds);
1972 if ((0 == write_pout.size) && (1 == stdin_open))
1887 { 1973 {
1888 broadcast = 0; 1974 stdin_pos = pos;
1889 pos = 0; 1975 pos += 1;
1890 stdin_pos = -1; 1976 GNUNET_NETWORK_fdset_handle_set (rfds, (struct
1891 stdout_pos = -1; 1977 GNUNET_DISK_FileHandle*) &
1892 sendsocket = NULL; //FIXME ???memleaks 1978 stdin_handle);
1893 1979 }
1894 GNUNET_NETWORK_fdset_zero(rfds); 1980
1895 if ((0 == write_pout.size) && (1 == stdin_open)) 1981 if (0 == write_std.size)
1982 {
1983 pos += 1;
1984 GNUNET_NETWORK_fdset_set (rfds, dev.handle);
1985 }
1986
1987 for (i = 0; i < crt_rfds; i++)
1988 {
1989 pos += 1;
1990 GNUNET_NETWORK_fdset_set (rfds, rfds_list[i]);
1991 }
1992
1993 GNUNET_NETWORK_fdset_zero (wfds);
1994 if (0 < write_std.size)
1995 {
1996 stdout_pos = pos;
1997 GNUNET_NETWORK_fdset_handle_set (wfds, (struct
1998 GNUNET_DISK_FileHandle*) &
1999 stdout_handle);
2000 // printf ("%s\n", write_std.buf);
2001 // memset (write_std.buf, 0, write_std.size);
2002 // write_std.size = 0;
2003 }
2004
2005 if (0 < write_pout.size)
2006 {
2007 if (strcmp (argv[1], "ff:ff:ff:ff:ff:ff") == 0)
2008 {
2009 fprintf (stderr, "LOG: BROADCAST! Skipping the message\n");
2010 // skip the message
2011 broadcast = 1;
2012 memset (write_pout.buf, 0, write_pout.size);
2013 write_pout.size = 0;
2014 }
2015 else
2016 {
2017 SOCKADDR_BTH addr;
2018 fprintf (stderr, "LOG : has a new message for %s\n", argv[1]);
2019 sendsocket = GNUNET_NETWORK_socket_create (AF_BTH, SOCK_STREAM,
2020 BTHPROTO_RFCOMM);
2021
2022 if (sendsocket == NULL)
1896 { 2023 {
1897 stdin_pos = pos; 2024 fprintf (stderr, "Failed to create RFCOMM socket: \n");
1898 pos += 1; 2025 print_last_error ();
1899 GNUNET_NETWORK_fdset_handle_set(rfds, (struct GNUNET_DISK_FileHandle*)&stdin_handle); 2026 ExitProcess (2);
1900 } 2027 }
1901 2028
1902 if (0 == write_std.size) 2029 memset (&addr, 0, sizeof(addr));
2030 // addr.addressFamily = AF_BTH;
2031 if (SOCKET_ERROR ==
2032 WSAStringToAddress (argv[1], AF_BTH, NULL, (LPSOCKADDR) &addr,
2033 &addr_len))
2034 {
2035 fprintf (stderr, "Failed to translate the address: ");
2036 print_last_error ();
2037 ExitProcess (2);
2038 }
2039 addr.port = get_channel (argv[1]);
2040 if (addr.port == -1)
2041 {
2042 fprintf (stderr,
2043 "Couldn't find the sdp service for the address: %s\n",
2044 argv[1]);
2045 memset (write_pout.buf, 0, write_pout.size);
2046 write_pout.size = 0;
2047 broadcast = 1; // skipping the select part
2048 }
2049 else
1903 { 2050 {
1904 pos += 1; 2051 if (GNUNET_OK != GNUNET_NETWORK_socket_connect (sendsocket,
1905 GNUNET_NETWORK_fdset_set(rfds, dev.handle); 2052 (LPSOCKADDR) &addr,
2053 addr_len))
2054 {
2055 fprintf (stderr, "Failed to connect: ");
2056 print_last_error ();
2057 ExitProcess (2);
2058 }
2059
2060 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (sendsocket, 1))
2061 {
2062 fprintf (stderr, "Failed to change the socket mode\n");
2063 ExitProcess (2);
2064 }
2065
2066 GNUNET_NETWORK_fdset_set (wfds, sendsocket);
1906 } 2067 }
2068 }
2069 }
1907 2070
1908 for (i = 0; i < crt_rfds; i++) 2071 if (broadcast == 0)
2072 {
2073 int retval = GNUNET_NETWORK_socket_select (rfds, wfds, NULL,
2074 GNUNET_TIME_relative_get_forever_ ());
2075 if (retval < 0)
2076 {
2077 fprintf (stderr, "Select error\n");
2078 ExitProcess (2);
2079 }
2080 // if (GNUNET_NETWORK_fdset_isset (wfds, (struct GNUNET_NETWORK_Handle*)&stdout_handle))
2081 if (retval == stdout_pos)
2082 {
2083 fprintf (stderr, "LOG : sends a message to STDOUT\n"); // FIXME: debugging message
2084 // ssize_t ret;
2085 // ret = GNUNET_NETWORK_socket_send ((struct GNUNET_NETWORK_Handle *)&stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos);
2086 // ret = write (STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size - write_std.pos);
2087 DWORD ret;
2088 if (FALSE == WriteFile (stdout_handle, write_std.buf + write_std.pos,
2089 write_std.size - write_std.pos, &ret, NULL))
1909 { 2090 {
1910 pos += 1; 2091 fprintf (stderr, "Failed to write to STDOUT: ");
1911 GNUNET_NETWORK_fdset_set(rfds, rfds_list[i]); 2092 print_last_error ();
2093 break;
1912 } 2094 }
1913 2095
1914 GNUNET_NETWORK_fdset_zero(wfds); 2096 if (ret <= 0)
1915 if (0 < write_std.size)
1916 { 2097 {
1917 stdout_pos = pos; 2098 fprintf (stderr, "Failed to write to STDOUT\n");
1918 GNUNET_NETWORK_fdset_handle_set(wfds, (struct GNUNET_DISK_FileHandle*)&stdout_handle); 2099 ExitProcess (2);
1919 // printf ("%s\n", write_std.buf);
1920 // memset (write_std.buf, 0, write_std.size);
1921 // write_std.size = 0;
1922 } 2100 }
1923 2101
1924 if (0 < write_pout.size) 2102 write_std.pos += ret;
2103 if (write_std.pos == write_std.size)
2104 {
2105 write_std.pos = 0;
2106 write_std.size = 0;
2107 }
2108 }
2109 if (sendsocket != NULL)
2110 {
2111 if (GNUNET_NETWORK_fdset_isset (wfds, sendsocket))
1925 { 2112 {
1926 if (strcmp(argv[1], "ff:ff:ff:ff:ff:ff") == 0) 2113 ssize_t ret;
2114 ret = GNUNET_NETWORK_socket_send (sendsocket, write_pout.buf
2115 + write_pout.pos,
2116 write_pout.size - write_pout.pos);
2117
2118 if (GNUNET_SYSERR == ret)
2119 {
2120 fprintf (stderr,
2121 "Failed to send to the socket. Closing the socket. Error: \n");
2122 print_last_error ();
2123 if (GNUNET_NETWORK_socket_close (sendsocket) != GNUNET_OK)
1927 { 2124 {
1928 fprintf(stderr, "LOG: BROADCAST! Skipping the message\n"); 2125 fprintf (stderr, "Failed to close the sendsocket!\n");
1929 // skip the message 2126 print_last_error ();
1930 broadcast = 1;
1931 memset(write_pout.buf, 0, write_pout.size);
1932 write_pout.size = 0;
1933 } 2127 }
2128 ExitProcess (2);
2129 }
1934 else 2130 else
2131 {
2132 write_pout.pos += ret;
2133 if ((write_pout.pos != write_pout.size) && (0 != ret))
1935 { 2134 {
1936 SOCKADDR_BTH addr; 2135 /* we should not get partial sends with packet-oriented devices... */
1937 fprintf(stderr, "LOG : has a new message for %s\n", argv[1]); 2136 fprintf (stderr, "Write error, partial send: %u/%u\n",
1938 sendsocket = GNUNET_NETWORK_socket_create(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); 2137 (unsigned int) write_pout.pos,
1939 2138 (unsigned int) write_pout.size);
1940 if (sendsocket == NULL) 2139 break;
1941 {
1942 fprintf(stderr, "Failed to create RFCOMM socket: \n");
1943 print_last_error();
1944 ExitProcess(2);
1945 }
1946
1947 memset(&addr, 0, sizeof(addr));
1948 //addr.addressFamily = AF_BTH;
1949 if (SOCKET_ERROR ==
1950 WSAStringToAddress(argv[1], AF_BTH, NULL, (LPSOCKADDR)&addr, &addr_len))
1951 {
1952 fprintf(stderr, "Failed to translate the address: ");
1953 print_last_error();
1954 ExitProcess(2);
1955 }
1956 addr.port = get_channel(argv[1]);
1957 if (addr.port == -1)
1958 {
1959 fprintf(stderr, "Couldn't find the sdp service for the address: %s\n", argv[1]);
1960 memset(write_pout.buf, 0, write_pout.size);
1961 write_pout.size = 0;
1962 broadcast = 1; //skipping the select part
1963 }
1964 else
1965 {
1966 if (GNUNET_OK != GNUNET_NETWORK_socket_connect(sendsocket, (LPSOCKADDR)&addr, addr_len))
1967 {
1968 fprintf(stderr, "Failed to connect: ");
1969 print_last_error();
1970 ExitProcess(2);
1971 }
1972
1973 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(sendsocket, 1))
1974 {
1975 fprintf(stderr, "Failed to change the socket mode\n");
1976 ExitProcess(2);
1977 }
1978
1979 GNUNET_NETWORK_fdset_set(wfds, sendsocket);
1980 }
1981 } 2140 }
1982 }
1983 2141
1984 if (broadcast == 0) 2142 if (write_pout.pos == write_pout.size)
1985 {
1986 int retval = GNUNET_NETWORK_socket_select(rfds, wfds, NULL, GNUNET_TIME_relative_get_forever_());
1987 if (retval < 0)
1988 { 2143 {
1989 fprintf(stderr, "Select error\n"); 2144 write_pout.pos = 0;
1990 ExitProcess(2); 2145 write_pout.size = 0;
1991 } 2146 }
1992 //if (GNUNET_NETWORK_fdset_isset (wfds, (struct GNUNET_NETWORK_Handle*)&stdout_handle)) 2147 fprintf (stderr, "LOG : sends a message to a DEVICE\n"); // FIXME: debugging message
1993 if (retval == stdout_pos) 2148 }
1994 { 2149 }
1995 fprintf(stderr, "LOG : sends a message to STDOUT\n"); //FIXME: debugging message 2150 }
1996 //ssize_t ret;
1997 //ret = GNUNET_NETWORK_socket_send ((struct GNUNET_NETWORK_Handle *)&stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos);
1998 //ret = write (STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size - write_std.pos);
1999 DWORD ret;
2000 if (FALSE == WriteFile(stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos, &ret, NULL))
2001 {
2002 fprintf(stderr, "Failed to write to STDOUT: ");
2003 print_last_error();
2004 break;
2005 }
2006 2151
2007 if (ret <= 0) 2152 // if (GNUNET_NETWORK_fdset_isset (rfds, (struct GNUNET_NETWORK_Handle*)&stdin_handle))
2008 { 2153 if (retval == stdin_pos)
2009 fprintf(stderr, "Failed to write to STDOUT\n"); 2154 {
2010 ExitProcess(2); 2155 // ssize_t ret;
2011 } 2156 // ret = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)&stdin_handle, readbuf, sizeof (write_pout.buf));
2157 // ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
2158 DWORD ret;
2159 if (FALSE == ReadFile (stdin_handle, readbuf, sizeof(readbuf), &ret,
2160 NULL)) /* do nothing asynchronous */
2161 {
2162 fprintf (stderr, "Read error from STDIN: ");
2163 print_last_error ();
2164 break;
2165 }
2166 if (0 == ret)
2167 {
2168 /* stop reading... */
2169 stdin_open = 0;
2170 }
2171 else
2172 {
2173 mst_receive (stdin_mst, readbuf, ret);
2174 fprintf (stderr, "LOG : receives a message from STDIN\n"); // FIXME: debugging message
2175 }
2176 }
2177 else if (GNUNET_NETWORK_fdset_isset (rfds, dev.handle))
2178 {
2179 fprintf (stderr, "LOG: accepting connection\n");
2180 struct GNUNET_NETWORK_Handle *readsocket;
2181 readsocket = GNUNET_NETWORK_socket_accept (dev.handle,
2182 (LPSOCKADDR) &acc_addr,
2183 &addr_len);
2184 if (readsocket == NULL)
2185 {
2186 fprintf (stderr, "Accept error %d: ", GetLastError ());
2187 print_last_error ();
2188 ExitProcess (2);
2189 }
2190 else
2191 {
2192 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (readsocket, 1))
2193 {
2194 fprintf (stderr, "Failed to change the socket mode\n");
2195 ExitProcess (2);
2196 }
2197 GNUNET_NETWORK_fdset_set (rfds, readsocket);
2012 2198
2013 write_std.pos += ret; 2199 if (crt_rfds < MAX_PORTS)
2014 if (write_std.pos == write_std.size) 2200 rfds_list[crt_rfds++] = readsocket;
2015 { 2201 else
2016 write_std.pos = 0; 2202 {
2017 write_std.size = 0; 2203 fprintf (stderr,
2018 } 2204 "The limit for the read file descriptors list was reached\n");
2019 } 2205 break;
2020 if (sendsocket != NULL) 2206 }
2207 }
2208 }
2209 else
2210 for (i = 0; i < crt_rfds; i++)
2211 {
2212 if (GNUNET_NETWORK_fdset_isset (rfds, rfds_list[i]))
2213 {
2214 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
2215 ssize_t ret;
2216 fprintf (stderr, "LOG: reading something from the socket\n"); // FIXME : debugging message
2217 rrm = (struct
2218 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
2219 ret = read_from_the_socket (rfds_list[i], (unsigned
2220 char *) &rrm->frame,
2221 sizeof(write_std.buf)
2222 - sizeof(struct
2223 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2224 + sizeof(struct
2225 GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
2226 rrm);
2227 if (0 >= ret)
2021 { 2228 {
2022 if (GNUNET_NETWORK_fdset_isset(wfds, sendsocket)) 2229 // TODO remove the socket from the list
2023 { 2230 if (GNUNET_NETWORK_socket_close (rfds_list[i]) != GNUNET_OK)
2024 ssize_t ret; 2231 {
2025 ret = GNUNET_NETWORK_socket_send(sendsocket, write_pout.buf + write_pout.pos, 2232 fprintf (stderr, "Failed to close the sendsocket!\n");
2026 write_pout.size - write_pout.pos); 2233 print_last_error ();
2027 2234 }
2028 if (GNUNET_SYSERR == ret)
2029 {
2030 fprintf(stderr, "Failed to send to the socket. Closing the socket. Error: \n");
2031 print_last_error();
2032 if (GNUNET_NETWORK_socket_close(sendsocket) != GNUNET_OK)
2033 {
2034 fprintf(stderr, "Failed to close the sendsocket!\n");
2035 print_last_error();
2036 }
2037 ExitProcess(2);
2038 }
2039 else
2040 {
2041 write_pout.pos += ret;
2042 if ((write_pout.pos != write_pout.size) && (0 != ret))
2043 {
2044 /* we should not get partial sends with packet-oriented devices... */
2045 fprintf(stderr, "Write error, partial send: %u/%u\n",
2046 (unsigned int)write_pout.pos,
2047 (unsigned int)write_pout.size);
2048 break;
2049 }
2050
2051 if (write_pout.pos == write_pout.size)
2052 {
2053 write_pout.pos = 0;
2054 write_pout.size = 0;
2055 }
2056 fprintf(stderr, "LOG : sends a message to a DEVICE\n"); //FIXME: debugging message
2057 }
2058 }
2059 }
2060 2235
2061 //if (GNUNET_NETWORK_fdset_isset (rfds, (struct GNUNET_NETWORK_Handle*)&stdin_handle)) 2236 fprintf (stderr, "Read error from raw socket: ");
2062 if (retval == stdin_pos) 2237 print_last_error ();
2063 { 2238 break;
2064 //ssize_t ret;
2065 //ret = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)&stdin_handle, readbuf, sizeof (write_pout.buf));
2066 //ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
2067 DWORD ret;
2068 if (FALSE == ReadFile(stdin_handle, readbuf, sizeof(readbuf), &ret, NULL)) /* do nothing asynchronous */
2069 {
2070 fprintf(stderr, "Read error from STDIN: ");
2071 print_last_error();
2072 break;
2073 }
2074 if (0 == ret)
2075 {
2076 /* stop reading... */
2077 stdin_open = 0;
2078 }
2079 else
2080 {
2081 mst_receive(stdin_mst, readbuf, ret);
2082 fprintf(stderr, "LOG : receives a message from STDIN\n"); //FIXME: debugging message
2083 }
2084 } 2239 }
2085 else 2240 if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
2086 if (GNUNET_NETWORK_fdset_isset(rfds, dev.handle))
2087 { 2241 {
2088 fprintf(stderr, "LOG: accepting connection\n"); 2242 write_std.size = ret
2089 struct GNUNET_NETWORK_Handle *readsocket; 2243 + sizeof(struct
2090 readsocket = GNUNET_NETWORK_socket_accept(dev.handle, (LPSOCKADDR)&acc_addr, &addr_len); 2244 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2091 if (readsocket == NULL) 2245 - sizeof(struct
2092 { 2246 GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
2093 fprintf(stderr, "Accept error %d: ", GetLastError()); 2247 rrm->header.size = htons (write_std.size);
2094 print_last_error(); 2248 rrm->header.type = htons (
2095 ExitProcess(2); 2249 GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
2096 }
2097 else
2098 {
2099 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(readsocket, 1))
2100 {
2101 fprintf(stderr, "Failed to change the socket mode\n");
2102 ExitProcess(2);
2103 }
2104 GNUNET_NETWORK_fdset_set(rfds, readsocket);
2105
2106 if (crt_rfds < MAX_PORTS)
2107 rfds_list[crt_rfds++] = readsocket;
2108 else
2109 {
2110 fprintf(stderr, "The limit for the read file descriptors list was reached\n");
2111 break;
2112 }
2113 }
2114 } 2250 }
2115 else 2251 break;
2116 for (i = 0; i < crt_rfds; i++) 2252 }
2117 {
2118 if (GNUNET_NETWORK_fdset_isset(rfds, rfds_list[i]))
2119 {
2120 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
2121 ssize_t ret;
2122 fprintf(stderr, "LOG: reading something from the socket\n");//FIXME : debugging message
2123 rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf;
2124 ret = read_from_the_socket(rfds_list[i], (unsigned char *)&rrm->frame,
2125 sizeof(write_std.buf)
2126 - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2127 + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
2128 rrm);
2129 if (0 >= ret)
2130 {
2131 //TODO remove the socket from the list
2132 if (GNUNET_NETWORK_socket_close(rfds_list[i]) != GNUNET_OK)
2133 {
2134 fprintf(stderr, "Failed to close the sendsocket!\n");
2135 print_last_error();
2136 }
2137
2138 fprintf(stderr, "Read error from raw socket: ");
2139 print_last_error();
2140 break;
2141 }
2142 if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev)))
2143 {
2144 write_std.size = ret
2145 + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2146 - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
2147 rrm->header.size = htons(write_std.size);
2148 rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
2149 }
2150 break;
2151 }
2152 }
2153 } 2253 }
2154 } 2254 }
2255 }
2155 2256
2156 mst_destroy(stdin_mst); 2257 mst_destroy (stdin_mst);
2157 stdin_mst = NULL; 2258 stdin_mst = NULL;
2158 2259
2159 if (GNUNET_NETWORK_socket_close(dev.handle) != GNUNET_OK) 2260 if (GNUNET_NETWORK_socket_close (dev.handle) != GNUNET_OK)
2160 { 2261 {
2161 fprintf(stderr, "Failed to close the socket!\n"); 2262 fprintf (stderr, "Failed to close the socket!\n");
2162 print_last_error(); 2263 print_last_error ();
2163 } 2264 }
2164 2265
2165 for (i = 0; i < crt_rfds; i++) 2266 for (i = 0; i < crt_rfds; i++)
2267 {
2268 if (GNUNET_NETWORK_socket_close (rfds_list[i]) != GNUNET_OK)
2166 { 2269 {
2167 if (GNUNET_NETWORK_socket_close(rfds_list[i]) != GNUNET_OK) 2270 fprintf (stderr, "Failed to close the socket!\n");
2168 { 2271 print_last_error ();
2169 fprintf(stderr, "Failed to close the socket!\n");
2170 print_last_error();
2171 }
2172 } 2272 }
2273 }
2173 2274
2174 WSACleanup(); 2275 WSACleanup ();
2175 #endif 2276 #endif
2176 return 1; /* we never exit 'normally' */ 2277 return 1; /* we never exit 'normally' */
2177} 2278}
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 @@
47/** 47/**
48 * IO buffer used for buffering data in transit. 48 * IO buffer used for buffering data in transit.
49 */ 49 */
50struct SendBuffer { 50struct SendBuffer
51{
51 /** 52 /**
52 * How many bytes that were stored in 'buf' did we already write to the 53 * How many bytes that were stored in 'buf' did we already write to the
53 * destination? Always smaller than 'size'. 54 * destination? Always smaller than 'size'.
@@ -80,11 +81,11 @@ static int closeprog;
80 * @param sig killing signal 81 * @param sig killing signal
81 */ 82 */
82static void 83static void
83sigfunc(int sig) 84sigfunc (int sig)
84{ 85{
85 closeprog = 1; 86 closeprog = 1;
86 (void)unlink(FIFO_FILE1); 87 (void) unlink (FIFO_FILE1);
87 (void)unlink(FIFO_FILE2); 88 (void) unlink (FIFO_FILE2);
88} 89}
89 90
90 91
@@ -96,19 +97,19 @@ sigfunc(int sig)
96 * @return number of bytes written 97 * @return number of bytes written
97 */ 98 */
98static int 99static int
99send_mac_to_plugin(char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) 100send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
100{ 101{
101 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 102 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
102 103
103 GNUNET_memcpy(&macmsg.mac, 104 GNUNET_memcpy (&macmsg.mac,
104 (char *)mac, 105 (char *) mac,
105 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)); 106 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
106 macmsg.hdr.size = 107 macmsg.hdr.size =
107 htons(sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 108 htons (sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
108 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 109 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
109 GNUNET_memcpy(buffer, 110 GNUNET_memcpy (buffer,
110 &macmsg, 111 &macmsg,
111 sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 112 sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
112 return sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage); 113 return sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage);
113} 114}
114 115
@@ -124,7 +125,7 @@ send_mac_to_plugin(char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
124 * #GNUNET_SYSERR to stop further processing with error 125 * #GNUNET_SYSERR to stop further processing with error
125 */ 126 */
126static int 127static int
127stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr) 128stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr)
128{ 129{
129 struct SendBuffer *write_pout = cls; 130 struct SendBuffer *write_pout = cls;
130 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; 131 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in;
@@ -132,32 +133,32 @@ stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr)
132 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader; 133 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader;
133 uint16_t sendsize; 134 uint16_t sendsize;
134 135
135 sendsize = ntohs(hdr->size); 136 sendsize = ntohs (hdr->size);
136 in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr; 137 in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
137 if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type)) || 138 if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ||
138 (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize)) 139 (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize))
139 { 140 {
140 fprintf(stderr, "%s", "Received malformed message\n"); 141 fprintf (stderr, "%s", "Received malformed message\n");
141 exit(1); 142 exit (1);
142 } 143 }
143 payload_size = 144 payload_size =
144 sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); 145 sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
145 if ((payload_size + 146 if ((payload_size
146 sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + 147 + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
147 write_pout->size) > MAXLINE * 2) 148 + write_pout->size) > MAXLINE * 2)
148 { 149 {
149 fprintf(stderr, "%s", "Packet too big for buffer\n"); 150 fprintf (stderr, "%s", "Packet too big for buffer\n");
150 exit(1); 151 exit (1);
151 } 152 }
152 memset(&newheader, 0, sizeof(newheader)); 153 memset (&newheader, 0, sizeof(newheader));
153 newheader.header.size = htons(payload_size + sizeof(newheader)); 154 newheader.header.size = htons (payload_size + sizeof(newheader));
154 newheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); 155 newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
155 newheader.frame = in->frame; 156 newheader.frame = in->frame;
156 GNUNET_memcpy(write_pout->buf + write_pout->size, 157 GNUNET_memcpy (write_pout->buf + write_pout->size,
157 &newheader, 158 &newheader,
158 sizeof(newheader)); 159 sizeof(newheader));
159 write_pout->size += sizeof(newheader); 160 write_pout->size += sizeof(newheader);
160 GNUNET_memcpy(write_pout->buf + write_pout->size, &in[1], payload_size); 161 GNUNET_memcpy (write_pout->buf + write_pout->size, &in[1], payload_size);
161 write_pout->size += payload_size; 162 write_pout->size += payload_size;
162 return GNUNET_OK; 163 return GNUNET_OK;
163} 164}
@@ -173,18 +174,18 @@ stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr)
173 * #GNUNET_SYSERR to stop further processing with error 174 * #GNUNET_SYSERR to stop further processing with error
174 */ 175 */
175static int 176static int
176file_in_send(void *cls, const struct GNUNET_MessageHeader *hdr) 177file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr)
177{ 178{
178 struct SendBuffer *write_std = cls; 179 struct SendBuffer *write_std = cls;
179 uint16_t sendsize; 180 uint16_t sendsize;
180 181
181 sendsize = ntohs(hdr->size); 182 sendsize = ntohs (hdr->size);
182 if ((sendsize + write_std->size) > MAXLINE * 2) 183 if ((sendsize + write_std->size) > MAXLINE * 2)
183 { 184 {
184 fprintf(stderr, "%s", "Packet too big for buffer\n"); 185 fprintf (stderr, "%s", "Packet too big for buffer\n");
185 exit(1); 186 exit (1);
186 } 187 }
187 GNUNET_memcpy(write_std->buf + write_std->size, hdr, sendsize); 188 GNUNET_memcpy (write_std->buf + write_std->size, hdr, sendsize);
188 write_std->size += sendsize; 189 write_std->size += sendsize;
189 return GNUNET_OK; 190 return GNUNET_OK;
190} 191}
@@ -198,7 +199,7 @@ file_in_send(void *cls, const struct GNUNET_MessageHeader *hdr)
198 * @return 1 on error, 0 if terminated normally via signal 199 * @return 1 on error, 0 if terminated normally via signal
199 */ 200 */
200int 201int
201main(int argc, char *argv[]) 202main (int argc, char *argv[])
202{ 203{
203 struct stat st; 204 struct stat st;
204 int erg; 205 int erg;
@@ -222,298 +223,298 @@ main(int argc, char *argv[])
222 int first; 223 int first;
223 224
224 if ((2 != argc) || 225 if ((2 != argc) ||
225 ((0 != strcmp(argv[1], "1")) && (0 != strcmp(argv[1], "2")))) 226 ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))))
226 { 227 {
227 fprintf( 228 fprintf (
228 stderr, 229 stderr,
229 "%s", 230 "%s",
230 "This program must be started with the operating mode (1 or 2) as the only argument.\n"); 231 "This program must be started with the operating mode (1 or 2) as the only argument.\n");
231 return 1; 232 return 1;
232 } 233 }
233 234
234 /* make the fifos if needed */ 235 /* make the fifos if needed */
235 umask(0); 236 umask (0);
236 if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file(FIFO_FILE1)) || 237 if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) ||
237 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(FIFO_FILE2))) 238 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)))
239 {
240 fprintf (stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
241 return 1;
242 }
243 if (0 == strcmp (argv[1], "1"))
244 {
245 if (0 != stat (FIFO_FILE1, &st))
238 { 246 {
239 fprintf(stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1); 247 erg = mkfifo (FIFO_FILE1, 0666);
240 return 1; 248 if ((0 != erg) && (EEXIST != errno))
241 } 249 fprintf (stderr,
242 if (0 == strcmp(argv[1], "1")) 250 "Error in mkfifo(%s): %s\n",
243 { 251 FIFO_FILE1,
244 if (0 != stat(FIFO_FILE1, &st)) 252 strerror (errno));
245 {
246 erg = mkfifo(FIFO_FILE1, 0666);
247 if ((0 != erg) && (EEXIST != errno))
248 fprintf(stderr,
249 "Error in mkfifo(%s): %s\n",
250 FIFO_FILE1,
251 strerror(errno));
252 }
253 } 253 }
254 }
254 else 255 else
256 {
257 if (0 != stat (FIFO_FILE2, &st))
255 { 258 {
256 if (0 != stat(FIFO_FILE2, &st)) 259 GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666)));
257 { 260 if ((0 != erg) && (EEXIST != errno))
258 GNUNET_break(0 == (erg = mkfifo(FIFO_FILE2, 0666))); 261 fprintf (stderr,
259 if ((0 != erg) && (EEXIST != errno)) 262 "Error in mkfifo(%s): %s\n",
260 fprintf(stderr, 263 FIFO_FILE2,
261 "Error in mkfifo(%s): %s\n", 264 strerror (errno));
262 FIFO_FILE2,
263 strerror(errno));
264 }
265 } 265 }
266 }
266 267
267 if (0 == strcmp(argv[1], "1")) 268 if (0 == strcmp (argv[1], "1"))
269 {
270 first = 1;
271 fpin = fopen (FIFO_FILE1, "r");
272 if (NULL == fpin)
268 { 273 {
269 first = 1; 274 fprintf (stderr,
270 fpin = fopen(FIFO_FILE1, "r"); 275 "fopen of read FIFO_FILE1 failed: %s\n",
271 if (NULL == fpin) 276 strerror (errno));
272 { 277 goto end;
273 fprintf(stderr, 278 }
274 "fopen of read FIFO_FILE1 failed: %s\n", 279 if (NULL == (fpout = fopen (FIFO_FILE2, "w")))
275 strerror(errno)); 280 {
276 goto end; 281 GNUNET_break (0 == mkfifo (FIFO_FILE2, 0666));
277 } 282 fpout = fopen (FIFO_FILE2, "w");
278 if (NULL == (fpout = fopen(FIFO_FILE2, "w")))
279 {
280 GNUNET_break(0 == mkfifo(FIFO_FILE2, 0666));
281 fpout = fopen(FIFO_FILE2, "w");
282 }
283 if (NULL == fpout)
284 {
285 fprintf(stderr,
286 "fopen of write FIFO_FILE2 failed: %s\n",
287 strerror(errno));
288 goto end;
289 }
290 } 283 }
284 if (NULL == fpout)
285 {
286 fprintf (stderr,
287 "fopen of write FIFO_FILE2 failed: %s\n",
288 strerror (errno));
289 goto end;
290 }
291 }
291 else 292 else
293 {
294 first = 0;
295 if (NULL == (fpout = fopen (FIFO_FILE1, "w")))
292 { 296 {
293 first = 0; 297 GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666));
294 if (NULL == (fpout = fopen(FIFO_FILE1, "w"))) 298 fpout = fopen (FIFO_FILE1, "w");
295 {
296 GNUNET_break(0 == mkfifo(FIFO_FILE1, 0666));
297 fpout = fopen(FIFO_FILE1, "w");
298 }
299 if (NULL == fpout)
300 {
301 fprintf(stderr,
302 "fopen of write FIFO_FILE1 failed: %s\n",
303 strerror(errno));
304 goto end;
305 }
306 fpin = fopen(FIFO_FILE2, "r");
307 if (NULL == fpin)
308 {
309 fprintf(stderr,
310 "fopen of read FIFO_FILE2 failed: %s\n",
311 strerror(errno));
312 goto end;
313 }
314 } 299 }
315 300 if (NULL == fpout)
316 fdpin = fileno(fpin);
317 GNUNET_assert(fpin >= 0);
318 if (fdpin >= FD_SETSIZE)
319 { 301 {
320 fprintf(stderr, 302 fprintf (stderr,
321 "File fdpin number too large (%d > %u)\n", 303 "fopen of write FIFO_FILE1 failed: %s\n",
322 fdpin, 304 strerror (errno));
323 (unsigned int)FD_SETSIZE);
324 goto end; 305 goto end;
325 } 306 }
326 307 fpin = fopen (FIFO_FILE2, "r");
327 fdpout = fileno(fpout); 308 if (NULL == fpin)
328 GNUNET_assert(fdpout >= 0);
329
330 if (fdpout >= FD_SETSIZE)
331 { 309 {
332 fprintf(stderr, 310 fprintf (stderr,
333 "File fdpout number too large (%d > %u)\n", 311 "fopen of read FIFO_FILE2 failed: %s\n",
334 fdpout, 312 strerror (errno));
335 (unsigned int)FD_SETSIZE);
336 goto end; 313 goto end;
337 } 314 }
315 }
316
317 fdpin = fileno (fpin);
318 GNUNET_assert (fpin >= 0);
319 if (fdpin >= FD_SETSIZE)
320 {
321 fprintf (stderr,
322 "File fdpin number too large (%d > %u)\n",
323 fdpin,
324 (unsigned int) FD_SETSIZE);
325 goto end;
326 }
338 327
339 signal(SIGINT, &sigfunc); 328 fdpout = fileno (fpout);
340 signal(SIGTERM, &sigfunc); 329 GNUNET_assert (fdpout >= 0);
341 signal(GNUNET_TERM_SIG, &sigfunc); 330
331 if (fdpout >= FD_SETSIZE)
332 {
333 fprintf (stderr,
334 "File fdpout number too large (%d > %u)\n",
335 fdpout,
336 (unsigned int) FD_SETSIZE);
337 goto end;
338 }
339
340 signal (SIGINT, &sigfunc);
341 signal (SIGTERM, &sigfunc);
342 signal (GNUNET_TERM_SIG, &sigfunc);
342 343
343 write_std.size = 0; 344 write_std.size = 0;
344 write_std.pos = 0; 345 write_std.pos = 0;
345 write_pout.size = 0; 346 write_pout.size = 0;
346 write_pout.pos = 0; 347 write_pout.pos = 0;
347 stdin_mst = GNUNET_MST_create(&stdin_send, &write_pout); 348 stdin_mst = GNUNET_MST_create (&stdin_send, &write_pout);
348 file_in_mst = GNUNET_MST_create(&file_in_send, &write_std); 349 file_in_mst = GNUNET_MST_create (&file_in_send, &write_std);
349 350
350 /* Send 'random' mac address */ 351 /* Send 'random' mac address */
351 macaddr.mac[0] = 0x13; 352 macaddr.mac[0] = 0x13;
352 macaddr.mac[1] = 0x22; 353 macaddr.mac[1] = 0x22;
353 macaddr.mac[2] = 0x33; 354 macaddr.mac[2] = 0x33;
354 macaddr.mac[3] = 0x44; 355 macaddr.mac[3] = 0x44;
355 macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256); 356 macaddr.mac[4] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 256);
356 macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256); 357 macaddr.mac[5] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 256);
357 write_std.size = send_mac_to_plugin(write_std.buf, &macaddr); 358 write_std.size = send_mac_to_plugin (write_std.buf, &macaddr);
358 359
359 while (0 == closeprog) 360 while (0 == closeprog)
361 {
362 maxfd = -1;
363 tv.tv_sec = 5;
364 tv.tv_usec = 0;
365
366 FD_ZERO (&rfds);
367 FD_ZERO (&wfds);
368 /* if output queue is empty, read */
369 if (0 == write_pout.size)
360 { 370 {
361 maxfd = -1; 371 FD_SET (STDIN_FILENO, &rfds);
362 tv.tv_sec = 5; 372 maxfd = MAX (STDIN_FILENO, maxfd);
363 tv.tv_usec = 0; 373 }
364 374 if (0 == write_std.size)
365 FD_ZERO(&rfds); 375 {
366 FD_ZERO(&wfds); 376 FD_SET (fdpin, &rfds);
367 /* if output queue is empty, read */ 377 maxfd = MAX (fdpin, maxfd);
368 if (0 == write_pout.size) 378 }
369 {
370 FD_SET(STDIN_FILENO, &rfds);
371 maxfd = MAX(STDIN_FILENO, maxfd);
372 }
373 if (0 == write_std.size)
374 {
375 FD_SET(fdpin, &rfds);
376 maxfd = MAX(fdpin, maxfd);
377 }
378 379
379 /* if there is something to write, try to write */ 380 /* if there is something to write, try to write */
380 if (0 < write_std.size) 381 if (0 < write_std.size)
381 { 382 {
382 FD_SET(STDOUT_FILENO, &wfds); 383 FD_SET (STDOUT_FILENO, &wfds);
383 maxfd = MAX(maxfd, STDOUT_FILENO); 384 maxfd = MAX (maxfd, STDOUT_FILENO);
384 } 385 }
385 if (0 < write_pout.size) 386 if (0 < write_pout.size)
386 { 387 {
387 FD_SET(fdpout, &wfds); 388 FD_SET (fdpout, &wfds);
388 maxfd = MAX(maxfd, fdpout); 389 maxfd = MAX (maxfd, fdpout);
389 } 390 }
390 391
391 retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv); 392 retval = select (maxfd + 1, &rfds, &wfds, NULL, &tv);
392 if ((-1 == retval) && (EINTR == errno)) 393 if ((-1 == retval) && (EINTR == errno))
393 continue; 394 continue;
394 if (0 > retval) 395 if (0 > retval)
395 { 396 {
396 fprintf(stderr, "select failed: %s\n", strerror(errno)); 397 fprintf (stderr, "select failed: %s\n", strerror (errno));
397 closeprog = 1; 398 closeprog = 1;
398 break; 399 break;
399 } 400 }
400 401
401 if (FD_ISSET(STDOUT_FILENO, &wfds)) 402 if (FD_ISSET (STDOUT_FILENO, &wfds))
403 {
404 ret = write (STDOUT_FILENO,
405 write_std.buf + write_std.pos,
406 write_std.size - write_std.pos);
407 if (0 > ret)
408 {
409 closeprog = 1;
410 fprintf (stderr,
411 "Write ERROR to STDOUT_FILENO: %s\n",
412 strerror (errno));
413 break;
414 }
415 else
416 {
417 write_std.pos += ret;
418 /* check if finished writing */
419 if (write_std.pos == write_std.size)
402 { 420 {
403 ret = write(STDOUT_FILENO, 421 write_std.pos = 0;
404 write_std.buf + write_std.pos, 422 write_std.size = 0;
405 write_std.size - write_std.pos);
406 if (0 > ret)
407 {
408 closeprog = 1;
409 fprintf(stderr,
410 "Write ERROR to STDOUT_FILENO: %s\n",
411 strerror(errno));
412 break;
413 }
414 else
415 {
416 write_std.pos += ret;
417 /* check if finished writing */
418 if (write_std.pos == write_std.size)
419 {
420 write_std.pos = 0;
421 write_std.size = 0;
422 }
423 }
424 } 423 }
424 }
425 }
425 426
426 if (FD_ISSET(fdpout, &wfds)) 427 if (FD_ISSET (fdpout, &wfds))
428 {
429 ret = write (fdpout,
430 write_pout.buf + write_pout.pos,
431 write_pout.size - write_pout.pos);
432
433 if (0 > ret)
434 {
435 closeprog = 1;
436 fprintf (stderr,
437 "Write ERROR to fdpout failed: %s\n",
438 strerror (errno));
439 }
440 else
441 {
442 write_pout.pos += ret;
443 /* check if finished writing */
444 if (write_pout.pos == write_pout.size)
427 { 445 {
428 ret = write(fdpout, 446 write_pout.pos = 0;
429 write_pout.buf + write_pout.pos, 447 write_pout.size = 0;
430 write_pout.size - write_pout.pos);
431
432 if (0 > ret)
433 {
434 closeprog = 1;
435 fprintf(stderr,
436 "Write ERROR to fdpout failed: %s\n",
437 strerror(errno));
438 }
439 else
440 {
441 write_pout.pos += ret;
442 /* check if finished writing */
443 if (write_pout.pos == write_pout.size)
444 {
445 write_pout.pos = 0;
446 write_pout.size = 0;
447 }
448 }
449 } 448 }
449 }
450 }
450 451
451 if (FD_ISSET(STDIN_FILENO, &rfds)) 452 if (FD_ISSET (STDIN_FILENO, &rfds))
452 { 453 {
453 readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf)); 454 readsize = read (STDIN_FILENO, readbuf, sizeof(readbuf));
454 455
455 if (0 > readsize) 456 if (0 > readsize)
456 { 457 {
457 closeprog = 1; 458 closeprog = 1;
458 fprintf(stderr, 459 fprintf (stderr,
459 "Error reading from STDIN_FILENO: %s\n", 460 "Error reading from STDIN_FILENO: %s\n",
460 strerror(errno)); 461 strerror (errno));
461 } 462 }
462 else if (0 < readsize) 463 else if (0 < readsize)
463 { 464 {
464 GNUNET_MST_from_buffer(stdin_mst, 465 GNUNET_MST_from_buffer (stdin_mst,
465 readbuf, 466 readbuf,
466 readsize, 467 readsize,
467 GNUNET_NO, 468 GNUNET_NO,
468 GNUNET_NO); 469 GNUNET_NO);
469 } 470 }
470 else 471 else
471 { 472 {
472 /* eof */ 473 /* eof */
473 closeprog = 1; 474 closeprog = 1;
474 } 475 }
475 } 476 }
476 477
477 if (FD_ISSET(fdpin, &rfds)) 478 if (FD_ISSET (fdpin, &rfds))
478 { 479 {
479 readsize = read(fdpin, readbuf, sizeof(readbuf)); 480 readsize = read (fdpin, readbuf, sizeof(readbuf));
480 if (0 > readsize) 481 if (0 > readsize)
481 { 482 {
482 closeprog = 1; 483 closeprog = 1;
483 fprintf(stderr, "Error reading from fdpin: %s\n", strerror(errno)); 484 fprintf (stderr, "Error reading from fdpin: %s\n", strerror (errno));
484 break; 485 break;
485 } 486 }
486 else if (0 < readsize) 487 else if (0 < readsize)
487 { 488 {
488 GNUNET_MST_from_buffer(file_in_mst, 489 GNUNET_MST_from_buffer (file_in_mst,
489 readbuf, 490 readbuf,
490 readsize, 491 readsize,
491 GNUNET_NO, 492 GNUNET_NO,
492 GNUNET_NO); 493 GNUNET_NO);
493 } 494 }
494 else 495 else
495 { 496 {
496 /* eof */ 497 /* eof */
497 closeprog = 1; 498 closeprog = 1;
498 } 499 }
499 }
500 } 500 }
501 }
501 502
502end: 503end:
503 /* clean up */ 504 /* clean up */
504 if (NULL != stdin_mst) 505 if (NULL != stdin_mst)
505 GNUNET_MST_destroy(stdin_mst); 506 GNUNET_MST_destroy (stdin_mst);
506 if (NULL != file_in_mst) 507 if (NULL != file_in_mst)
507 GNUNET_MST_destroy(file_in_mst); 508 GNUNET_MST_destroy (file_in_mst);
508 509
509 if (NULL != fpout) 510 if (NULL != fpout)
510 fclose(fpout); 511 fclose (fpout);
511 if (NULL != fpin) 512 if (NULL != fpin)
512 fclose(fpin); 513 fclose (fpin);
513 if (1 == first) 514 if (1 == first)
514 { 515 {
515 (void)unlink(FIFO_FILE1); 516 (void) unlink (FIFO_FILE1);
516 (void)unlink(FIFO_FILE2); 517 (void) unlink (FIFO_FILE2);
517 } 518 }
518 return 0; 519 return 0;
519} 520}
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 @@
234/** 234/**
235 * Values in the 'struct PrismHeader'. All in host byte order (!). 235 * Values in the 'struct PrismHeader'. All in host byte order (!).
236 */ 236 */
237struct PrismValue { 237struct PrismValue
238{
238 /** 239 /**
239 * This has a different ID for each parameter, see 240 * This has a different ID for each parameter, see
240 * PRISM_DID_* constants. 241 * PRISM_DID_* constants.
@@ -263,7 +264,8 @@ struct PrismValue {
263/** 264/**
264 * Prism header format ('struct p80211msg' in Linux). All in host byte order (!). 265 * Prism header format ('struct p80211msg' in Linux). All in host byte order (!).
265 */ 266 */
266struct PrismHeader { 267struct PrismHeader
268{
267 /** 269 /**
268 * We expect this to be a PRISM_MSGCODE_*. 270 * We expect this to be a PRISM_MSGCODE_*.
269 */ 271 */
@@ -301,7 +303,8 @@ struct PrismHeader {
301 * reliable indicator of alignment requirement. See also 303 * reliable indicator of alignment requirement. See also
302 * 'man 9 ieee80211_radiotap'. 304 * 'man 9 ieee80211_radiotap'.
303 */ 305 */
304enum RadiotapType { 306enum RadiotapType
307{
305 /** 308 /**
306 * IEEE80211_RADIOTAP_TSFT __le64 microseconds 309 * IEEE80211_RADIOTAP_TSFT __le64 microseconds
307 * 310 *
@@ -576,7 +579,8 @@ enum RadiotapType {
576 * The radio capture header precedes the 802.11 header. 579 * The radio capture header precedes the 802.11 header.
577 * All data in the header is little endian on all platforms. 580 * All data in the header is little endian on all platforms.
578 */ 581 */
579struct Ieee80211RadiotapHeader { 582struct Ieee80211RadiotapHeader
583{
580 /** 584 /**
581 * Version 0. Only increases for drastic changes, introduction of 585 * Version 0. Only increases for drastic changes, introduction of
582 * compatible new fields does not count. 586 * compatible new fields does not count.
@@ -607,7 +611,8 @@ struct Ieee80211RadiotapHeader {
607 * Format of the header we need to prepend to messages to be sent to the 611 * Format of the header we need to prepend to messages to be sent to the
608 * Kernel. 612 * Kernel.
609 */ 613 */
610struct RadiotapTransmissionHeader { 614struct RadiotapTransmissionHeader
615{
611 /** 616 /**
612 * First we begin with the 'generic' header we also get when receiving 617 * First we begin with the 'generic' header we also get when receiving
613 * messages. 618 * messages.
@@ -638,7 +643,12 @@ struct RadiotapTransmissionHeader {
638 * following value for 'header.it_present' based on the presence of 643 * following value for 'header.it_present' based on the presence of
639 * the 'rate' and 'txflags' in the overall struct. 644 * the 'rate' and 'txflags' in the overall struct.
640 */ 645 */
641#define IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK ((1 << IEEE80211_RADIOTAP_RATE) | (1 << IEEE80211_RADIOTAP_TX_FLAGS)) 646#define IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK ((1 \
647 << \
648 IEEE80211_RADIOTAP_RATE) \
649 | (1 \
650 << \
651 IEEE80211_RADIOTAP_TX_FLAGS))
642 652
643 653
644 654
@@ -646,7 +656,8 @@ struct RadiotapTransmissionHeader {
646 * struct Ieee80211RadiotapHeaderIterator - tracks walk through present radiotap arguments 656 * struct Ieee80211RadiotapHeaderIterator - tracks walk through present radiotap arguments
647 * in the radiotap header. Used when we parse radiotap packets received from the kernel. 657 * in the radiotap header. Used when we parse radiotap packets received from the kernel.
648 */ 658 */
649struct Ieee80211RadiotapHeaderIterator { 659struct Ieee80211RadiotapHeaderIterator
660{
650 /** 661 /**
651 * pointer to the radiotap header we are walking through 662 * pointer to the radiotap header we are walking through
652 */ 663 */
@@ -698,7 +709,8 @@ struct Ieee80211RadiotapHeaderIterator {
698 * struct for storing the information of the hardware. There is only 709 * struct for storing the information of the hardware. There is only
699 * one of these. 710 * one of these.
700 */ 711 */
701struct HardwareInfos { 712struct HardwareInfos
713{
702 /** 714 /**
703 * file descriptor for the raw socket 715 * file descriptor for the raw socket
704 */ 716 */
@@ -725,7 +737,8 @@ struct HardwareInfos {
725/** 737/**
726 * IO buffer used for buffering data in transit (to wireless or to stdout). 738 * IO buffer used for buffering data in transit (to wireless or to stdout).
727 */ 739 */
728struct SendBuffer { 740struct SendBuffer
741{
729 /** 742 /**
730 * How many bytes of data are stored in 'buf' for transmission right now? 743 * How many bytes of data are stored in 'buf' for transmission right now?
731 * Data always starts at offset 0 and extends to 'size'. 744 * Data always starts at offset 0 and extends to 'size'.
@@ -787,7 +800,8 @@ typedef void (*MessageTokenizerCallback) (void *cls,
787/** 800/**
788 * Handle to a message stream tokenizer. 801 * Handle to a message stream tokenizer.
789 */ 802 */
790struct MessageStreamTokenizer { 803struct MessageStreamTokenizer
804{
791 /** 805 /**
792 * Function to call on completed messages. 806 * Function to call on completed messages.
793 */ 807 */
@@ -828,23 +842,23 @@ struct MessageStreamTokenizer {
828 * @return handle to tokenizer 842 * @return handle to tokenizer
829 */ 843 */
830static struct MessageStreamTokenizer * 844static struct MessageStreamTokenizer *
831mst_create(MessageTokenizerCallback cb, 845mst_create (MessageTokenizerCallback cb,
832 void *cb_cls) 846 void *cb_cls)
833{ 847{
834 struct MessageStreamTokenizer *ret; 848 struct MessageStreamTokenizer *ret;
835 849
836 ret = malloc(sizeof(struct MessageStreamTokenizer)); 850 ret = malloc (sizeof(struct MessageStreamTokenizer));
837 if (NULL == ret) 851 if (NULL == ret)
838 { 852 {
839 fprintf(stderr, "Failed to allocate buffer for tokenizer\n"); 853 fprintf (stderr, "Failed to allocate buffer for tokenizer\n");
840 exit(1); 854 exit (1);
841 } 855 }
842 ret->hdr = malloc(MIN_BUFFER_SIZE); 856 ret->hdr = malloc (MIN_BUFFER_SIZE);
843 if (NULL == ret->hdr) 857 if (NULL == ret->hdr)
844 { 858 {
845 fprintf(stderr, "Failed to allocate buffer for alignment\n"); 859 fprintf (stderr, "Failed to allocate buffer for alignment\n");
846 exit(1); 860 exit (1);
847 } 861 }
848 ret->curr_buf = MIN_BUFFER_SIZE; 862 ret->curr_buf = MIN_BUFFER_SIZE;
849 ret->cb = cb; 863 ret->cb = cb;
850 ret->cb_cls = cb_cls; 864 ret->cb_cls = cb_cls;
@@ -863,8 +877,8 @@ mst_create(MessageTokenizerCallback cb,
863 * GNUNET_SYSERR if the data stream is corrupt 877 * GNUNET_SYSERR if the data stream is corrupt
864 */ 878 */
865static int 879static int
866mst_receive(struct MessageStreamTokenizer *mst, 880mst_receive (struct MessageStreamTokenizer *mst,
867 const char *buf, size_t size) 881 const char *buf, size_t size)
868{ 882{
869 const struct GNUNET_MessageHeader *hdr; 883 const struct GNUNET_MessageHeader *hdr;
870 size_t delta; 884 size_t delta;
@@ -875,132 +889,132 @@ mst_receive(struct MessageStreamTokenizer *mst,
875 int ret; 889 int ret;
876 890
877 ret = GNUNET_OK; 891 ret = GNUNET_OK;
878 ibuf = (char *)mst->hdr; 892 ibuf = (char *) mst->hdr;
879 while (mst->pos > 0) 893 while (mst->pos > 0)
880 { 894 {
881do_align: 895do_align:
882 if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) || 896 if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
883 (0 != (mst->off % ALIGN_FACTOR))) 897 (0 != (mst->off % ALIGN_FACTOR)))
884 { 898 {
885 /* need to align or need more space */ 899 /* need to align or need more space */
886 mst->pos -= mst->off; 900 mst->pos -= mst->off;
887 memmove(ibuf, &ibuf[mst->off], mst->pos); 901 memmove (ibuf, &ibuf[mst->off], mst->pos);
888 mst->off = 0; 902 mst->off = 0;
889 } 903 }
890 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) 904 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
891 { 905 {
892 delta = 906 delta =
893 GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) - 907 GNUNET_MIN (sizeof(struct GNUNET_MessageHeader)
894 (mst->pos - mst->off), size); 908 - (mst->pos - mst->off), size);
895 GNUNET_memcpy(&ibuf[mst->pos], buf, delta); 909 GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
896 mst->pos += delta; 910 mst->pos += delta;
897 buf += delta; 911 buf += delta;
898 size -= delta; 912 size -= delta;
899 } 913 }
900 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) 914 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
901 { 915 {
902 return GNUNET_OK; 916 return GNUNET_OK;
903 } 917 }
904 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off]; 918 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
905 want = ntohs(hdr->size); 919 want = ntohs (hdr->size);
906 if (want < sizeof(struct GNUNET_MessageHeader)) 920 if (want < sizeof(struct GNUNET_MessageHeader))
907 { 921 {
908 fprintf(stderr, 922 fprintf (stderr,
909 "Received invalid message from stdin\n"); 923 "Received invalid message from stdin\n");
910 exit(1); 924 exit (1);
911 } 925 }
912 if (mst->curr_buf - mst->off < want) 926 if (mst->curr_buf - mst->off < want)
913 { 927 {
914 /* need more space */ 928 /* need more space */
915 mst->pos -= mst->off; 929 mst->pos -= mst->off;
916 memmove(ibuf, &ibuf[mst->off], mst->pos); 930 memmove (ibuf, &ibuf[mst->off], mst->pos);
917 mst->off = 0; 931 mst->off = 0;
918 } 932 }
919 if (want > mst->curr_buf) 933 if (want > mst->curr_buf)
920 { 934 {
921 mst->hdr = realloc(mst->hdr, want); 935 mst->hdr = realloc (mst->hdr, want);
922 if (NULL == mst->hdr) 936 if (NULL == mst->hdr)
923 { 937 {
924 fprintf(stderr, "Failed to allocate buffer for alignment\n"); 938 fprintf (stderr, "Failed to allocate buffer for alignment\n");
925 exit(1); 939 exit (1);
926 } 940 }
927 ibuf = (char *)mst->hdr; 941 ibuf = (char *) mst->hdr;
928 mst->curr_buf = want; 942 mst->curr_buf = want;
929 } 943 }
930 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off]; 944 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
931 if (mst->pos - mst->off < want) 945 if (mst->pos - mst->off < want)
932 { 946 {
933 delta = GNUNET_MIN(want - (mst->pos - mst->off), size); 947 delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
934 GNUNET_memcpy(&ibuf[mst->pos], buf, delta); 948 GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
935 mst->pos += delta; 949 mst->pos += delta;
936 buf += delta; 950 buf += delta;
937 size -= delta; 951 size -= delta;
938 } 952 }
939 if (mst->pos - mst->off < want) 953 if (mst->pos - mst->off < want)
940 { 954 {
941 return GNUNET_OK; 955 return GNUNET_OK;
942 }
943 mst->cb(mst->cb_cls, hdr);
944 mst->off += want;
945 if (mst->off == mst->pos)
946 {
947 /* reset to beginning of buffer, it's free right now! */
948 mst->off = 0;
949 mst->pos = 0;
950 }
951 } 956 }
957 mst->cb (mst->cb_cls, hdr);
958 mst->off += want;
959 if (mst->off == mst->pos)
960 {
961 /* reset to beginning of buffer, it's free right now! */
962 mst->off = 0;
963 mst->pos = 0;
964 }
965 }
952 while (size > 0) 966 while (size > 0)
967 {
968 if (size < sizeof(struct GNUNET_MessageHeader))
969 break;
970 offset = (unsigned long) buf;
971 need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
972 if (GNUNET_NO == need_align)
953 { 973 {
954 if (size < sizeof(struct GNUNET_MessageHeader)) 974 /* can try to do zero-copy and process directly from original buffer */
955 break; 975 hdr = (const struct GNUNET_MessageHeader *) buf;
956 offset = (unsigned long)buf; 976 want = ntohs (hdr->size);
957 need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; 977 if (want < sizeof(struct GNUNET_MessageHeader))
958 if (GNUNET_NO == need_align) 978 {
959 { 979 fprintf (stderr,
960 /* can try to do zero-copy and process directly from original buffer */ 980 "Received invalid message from stdin\n");
961 hdr = (const struct GNUNET_MessageHeader *)buf; 981 exit (1);
962 want = ntohs(hdr->size); 982 }
963 if (want < sizeof(struct GNUNET_MessageHeader)) 983 if (size < want)
964 { 984 break; /* or not, buffer incomplete, so copy to private buffer... */
965 fprintf(stderr, 985 mst->cb (mst->cb_cls, hdr);
966 "Received invalid message from stdin\n"); 986 buf += want;
967 exit(1); 987 size -= want;
968 } 988 }
969 if (size < want) 989 else
970 break; /* or not, buffer incomplete, so copy to private buffer... */ 990 {
971 mst->cb(mst->cb_cls, hdr); 991 /* need to copy to private buffer to align;
972 buf += want; 992 * yes, we go a bit more spagetti than usual here */
973 size -= want; 993 goto do_align;
974 }
975 else
976 {
977 /* need to copy to private buffer to align;
978 * yes, we go a bit more spagetti than usual here */
979 goto do_align;
980 }
981 } 994 }
995 }
982 if (size > 0) 996 if (size > 0)
997 {
998 if (size + mst->pos > mst->curr_buf)
983 { 999 {
984 if (size + mst->pos > mst->curr_buf) 1000 mst->hdr = realloc (mst->hdr, size + mst->pos);
985 { 1001 if (NULL == mst->hdr)
986 mst->hdr = realloc(mst->hdr, size + mst->pos); 1002 {
987 if (NULL == mst->hdr) 1003 fprintf (stderr, "Failed to allocate buffer for alignment\n");
988 { 1004 exit (1);
989 fprintf(stderr, "Failed to allocate buffer for alignment\n"); 1005 }
990 exit(1); 1006 ibuf = (char *) mst->hdr;
991 } 1007 mst->curr_buf = size + mst->pos;
992 ibuf = (char *)mst->hdr; 1008 }
993 mst->curr_buf = size + mst->pos; 1009 if (mst->pos + size > mst->curr_buf)
994 } 1010 {
995 if (mst->pos + size > mst->curr_buf) 1011 fprintf (stderr,
996 { 1012 "Assertion failed\n");
997 fprintf(stderr, 1013 exit (1);
998 "Assertion failed\n");
999 exit(1);
1000 }
1001 GNUNET_memcpy(&ibuf[mst->pos], buf, size);
1002 mst->pos += size;
1003 } 1014 }
1015 GNUNET_memcpy (&ibuf[mst->pos], buf, size);
1016 mst->pos += size;
1017 }
1004 return ret; 1018 return ret;
1005} 1019}
1006 1020
@@ -1011,10 +1025,10 @@ do_align:
1011 * @param mst tokenizer to destroy 1025 * @param mst tokenizer to destroy
1012 */ 1026 */
1013static void 1027static void
1014mst_destroy(struct MessageStreamTokenizer *mst) 1028mst_destroy (struct MessageStreamTokenizer *mst)
1015{ 1029{
1016 free(mst->hdr); 1030 free (mst->hdr);
1017 free(mst); 1031 free (mst);
1018} 1032}
1019 1033
1020/* ***************** end of server_mst.c clone ***************** **/ 1034/* ***************** end of server_mst.c clone ***************** **/
@@ -1040,9 +1054,11 @@ mst_destroy(struct MessageStreamTokenizer *mst)
1040 * @return 0 on success, -1 on error 1054 * @return 0 on success, -1 on error
1041 */ 1055 */
1042static int 1056static int
1043ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterator, 1057ieee80211_radiotap_iterator_init (struct
1044 const struct Ieee80211RadiotapHeader *radiotap_header, 1058 Ieee80211RadiotapHeaderIterator *iterator,
1045 size_t max_length) 1059 const struct
1060 Ieee80211RadiotapHeader *radiotap_header,
1061 size_t max_length)
1046{ 1062{
1047 if ((iterator == NULL) || 1063 if ((iterator == NULL) ||
1048 (radiotap_header == NULL)) 1064 (radiotap_header == NULL))
@@ -1054,36 +1070,39 @@ ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterato
1054 1070
1055 /* sanity check for allowed length and radiotap length field */ 1071 /* sanity check for allowed length and radiotap length field */
1056 if ((max_length < sizeof(struct Ieee80211RadiotapHeader)) || 1072 if ((max_length < sizeof(struct Ieee80211RadiotapHeader)) ||
1057 (max_length < (GNUNET_le16toh(radiotap_header->it_len)))) 1073 (max_length < (GNUNET_le16toh (radiotap_header->it_len))))
1058 return -1; 1074 return -1;
1059 1075
1060 memset(iterator, 0, sizeof(struct Ieee80211RadiotapHeaderIterator)); 1076 memset (iterator, 0, sizeof(struct Ieee80211RadiotapHeaderIterator));
1061 iterator->rtheader = radiotap_header; 1077 iterator->rtheader = radiotap_header;
1062 iterator->max_length = GNUNET_le16toh(radiotap_header->it_len); 1078 iterator->max_length = GNUNET_le16toh (radiotap_header->it_len);
1063 iterator->bitmap_shifter = GNUNET_le32toh(radiotap_header->it_present); 1079 iterator->bitmap_shifter = GNUNET_le32toh (radiotap_header->it_present);
1064 iterator->arg = ((uint8_t *)radiotap_header) + sizeof(struct Ieee80211RadiotapHeader); 1080 iterator->arg = ((uint8_t *) radiotap_header) + sizeof(struct
1081 Ieee80211RadiotapHeader);
1065 1082
1066 /* find payload start allowing for extended bitmap(s) */ 1083 /* find payload start allowing for extended bitmap(s) */
1067 if (0 != (iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) 1084 if (0 != (iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK))
1085 {
1086 while (GNUNET_le32toh (*((uint32_t *) iterator->arg))
1087 & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)
1068 { 1088 {
1069 while (GNUNET_le32toh(*((uint32_t *)iterator->arg)) & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)
1070 {
1071 iterator->arg += sizeof(uint32_t);
1072 /*
1073 * check for insanity where the present bitmaps
1074 * keep claiming to extend up to or even beyond the
1075 * stated radiotap header length
1076 */
1077 if (iterator->arg - ((uint8_t*)iterator->rtheader) > iterator->max_length)
1078 return -1;
1079 }
1080 iterator->arg += sizeof(uint32_t); 1089 iterator->arg += sizeof(uint32_t);
1081 /* 1090 /*
1082 * no need to check again for blowing past stated radiotap 1091 * check for insanity where the present bitmaps
1083 * header length, becuase ieee80211_radiotap_iterator_next 1092 * keep claiming to extend up to or even beyond the
1084 * checks it before it is dereferenced 1093 * stated radiotap header length
1085 */ 1094 */
1095 if (iterator->arg - ((uint8_t*) iterator->rtheader) >
1096 iterator->max_length)
1097 return -1;
1086 } 1098 }
1099 iterator->arg += sizeof(uint32_t);
1100 /*
1101 * no need to check again for blowing past stated radiotap
1102 * header length, becuase ieee80211_radiotap_iterator_next
1103 * checks it before it is dereferenced
1104 */
1105 }
1087 /* we are all initialized happily */ 1106 /* we are all initialized happily */
1088 return 0; 1107 return 0;
1089} 1108}
@@ -1102,7 +1121,8 @@ ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterato
1102 * @return next present arg index on success or -1 if no more or error 1121 * @return next present arg index on success or -1 if no more or error
1103 */ 1122 */
1104static int 1123static int
1105ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterator) 1124ieee80211_radiotap_iterator_next (struct
1125 Ieee80211RadiotapHeaderIterator *iterator)
1106{ 1126{
1107 /* 1127 /*
1108 * small length lookup table for all radiotap types we heard of 1128 * small length lookup table for all radiotap types we heard of
@@ -1149,94 +1169,96 @@ ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterato
1149 * least skip (by knowing the length)... 1169 * least skip (by knowing the length)...
1150 */ 1170 */
1151 while (iterator->arg_index < sizeof(rt_sizes)) 1171 while (iterator->arg_index < sizeof(rt_sizes))
1172 {
1173 int hit = (0 != (iterator->bitmap_shifter & 1));
1174
1175 if (hit)
1152 { 1176 {
1153 int hit = (0 != (iterator->bitmap_shifter & 1)); 1177 unsigned int wanted_alignment;
1178 unsigned int unalignment;
1179 /*
1180 * arg is present, account for alignment padding
1181 * 8-bit args can be at any alignment
1182 * 16-bit args must start on 16-bit boundary
1183 * 32-bit args must start on 32-bit boundary
1184 * 64-bit args must start on 64-bit boundary
1185 *
1186 * note that total arg size can differ from alignment of
1187 * elements inside arg, so we use upper nybble of length table
1188 * to base alignment on. First, 'wanted_alignment' is set to be
1189 * 1 for 8-bit, 2 for 16-bit, 4 for 32-bit and 8 for 64-bit
1190 * arguments. Then, we calculate the 'unalignment' (how many
1191 * bytes we are over by taking the difference of 'arg' and the
1192 * overall starting point modulo the desired alignment. As
1193 * desired alignments are powers of two, we can do modulo with
1194 * binary "&" (and also avoid the possibility of a division by
1195 * zero if the 'rt_sizes' table contains bogus entries).
1196 *
1197 * also note: these alignments are relative to the start of the
1198 * radiotap header. There is no guarantee that the radiotap
1199 * header itself is aligned on any kind of boundary, thus we
1200 * need to really look at the delta here.
1201 */
1202 wanted_alignment = rt_sizes[iterator->arg_index] >> 4;
1203 unalignment = (((void *) iterator->arg) - ((void *) iterator->rtheader))
1204 & (wanted_alignment - 1);
1205 if (0 != unalignment)
1206 {
1207 /* need padding (by 'wanted_alignment - unalignment') */
1208 iterator->arg_index += wanted_alignment - unalignment;
1209 }
1154 1210
1155 if (hit) 1211 /*
1156 { 1212 * this is what we will return to user, but we need to
1157 unsigned int wanted_alignment; 1213 * move on first so next call has something fresh to test
1158 unsigned int unalignment; 1214 */
1159 /* 1215 iterator->this_arg_index = iterator->arg_index;
1160 * arg is present, account for alignment padding 1216 iterator->this_arg = iterator->arg;
1161 * 8-bit args can be at any alignment
1162 * 16-bit args must start on 16-bit boundary
1163 * 32-bit args must start on 32-bit boundary
1164 * 64-bit args must start on 64-bit boundary
1165 *
1166 * note that total arg size can differ from alignment of
1167 * elements inside arg, so we use upper nybble of length table
1168 * to base alignment on. First, 'wanted_alignment' is set to be
1169 * 1 for 8-bit, 2 for 16-bit, 4 for 32-bit and 8 for 64-bit
1170 * arguments. Then, we calculate the 'unalignment' (how many
1171 * bytes we are over by taking the difference of 'arg' and the
1172 * overall starting point modulo the desired alignment. As
1173 * desired alignments are powers of two, we can do modulo with
1174 * binary "&" (and also avoid the possibility of a division by
1175 * zero if the 'rt_sizes' table contains bogus entries).
1176 *
1177 * also note: these alignments are relative to the start of the
1178 * radiotap header. There is no guarantee that the radiotap
1179 * header itself is aligned on any kind of boundary, thus we
1180 * need to really look at the delta here.
1181 */
1182 wanted_alignment = rt_sizes[iterator->arg_index] >> 4;
1183 unalignment = (((void *)iterator->arg) - ((void *)iterator->rtheader)) & (wanted_alignment - 1);
1184 if (0 != unalignment)
1185 {
1186 /* need padding (by 'wanted_alignment - unalignment') */
1187 iterator->arg_index += wanted_alignment - unalignment;
1188 }
1189 1217
1190 /* 1218 /* internally move on the size of this arg (using lower nybble from
1191 * this is what we will return to user, but we need to 1219 the table) */
1192 * move on first so next call has something fresh to test 1220 iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
1193 */
1194 iterator->this_arg_index = iterator->arg_index;
1195 iterator->this_arg = iterator->arg;
1196
1197 /* internally move on the size of this arg (using lower nybble from
1198 the table) */
1199 iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
1200
1201 /*
1202 * check for insanity where we are given a bitmap that
1203 * claims to have more arg content than the length of the
1204 * radiotap section. We will normally end up equalling this
1205 * max_length on the last arg, never exceeding it.
1206 */
1207 if ((((void *)iterator->arg) - ((void *)iterator->rtheader)) > iterator->max_length)
1208 return -1;
1209 }
1210 1221
1211 /* Now, move on to next bit / next entry */ 1222 /*
1212 iterator->arg_index++; 1223 * check for insanity where we are given a bitmap that
1224 * claims to have more arg content than the length of the
1225 * radiotap section. We will normally end up equalling this
1226 * max_length on the last arg, never exceeding it.
1227 */
1228 if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) >
1229 iterator->max_length)
1230 return -1;
1231 }
1213 1232
1214 if (0 == (iterator->arg_index % 32)) 1233 /* Now, move on to next bit / next entry */
1215 { 1234 iterator->arg_index++;
1216 /* completed current uint32_t bitmap */
1217 if (0 != (iterator->bitmap_shifter & 1))
1218 {
1219 /* bit 31 was set, there is more; move to next uint32_t bitmap */
1220 iterator->bitmap_shifter = GNUNET_le32toh(*iterator->next_bitmap);
1221 iterator->next_bitmap++;
1222 }
1223 else
1224 {
1225 /* no more bitmaps: end (by setting arg_index to high, unsupported value) */
1226 iterator->arg_index = sizeof(rt_sizes);
1227 }
1228 }
1229 else
1230 {
1231 /* just try the next bit (while loop will move on) */
1232 iterator->bitmap_shifter >>= 1;
1233 }
1234 1235
1235 /* if we found a valid arg earlier, return it now */ 1236 if (0 == (iterator->arg_index % 32))
1236 if (hit) 1237 {
1237 return iterator->this_arg_index; 1238 /* completed current uint32_t bitmap */
1239 if (0 != (iterator->bitmap_shifter & 1))
1240 {
1241 /* bit 31 was set, there is more; move to next uint32_t bitmap */
1242 iterator->bitmap_shifter = GNUNET_le32toh (*iterator->next_bitmap);
1243 iterator->next_bitmap++;
1244 }
1245 else
1246 {
1247 /* no more bitmaps: end (by setting arg_index to high, unsupported value) */
1248 iterator->arg_index = sizeof(rt_sizes);
1249 }
1250 }
1251 else
1252 {
1253 /* just try the next bit (while loop will move on) */
1254 iterator->bitmap_shifter >>= 1;
1238 } 1255 }
1239 1256
1257 /* if we found a valid arg earlier, return it now */
1258 if (hit)
1259 return iterator->this_arg_index;
1260 }
1261
1240 /* we don't know how to handle any more args (or there are no more), 1262 /* we don't know how to handle any more args (or there are no more),
1241 so we're done (this is not an error) */ 1263 so we're done (this is not an error) */
1242 return -1; 1264 return -1;
@@ -1251,7 +1273,7 @@ ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterato
1251 * @return crc sum 1273 * @return crc sum
1252 */ 1274 */
1253static unsigned long 1275static unsigned long
1254calc_crc_osdep(const unsigned char *buf, size_t len) 1276calc_crc_osdep (const unsigned char *buf, size_t len)
1255{ 1277{
1256 static const unsigned long int crc_tbl_osdep[256] = { 1278 static const unsigned long int crc_tbl_osdep[256] = {
1257 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 1279 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
@@ -1337,14 +1359,14 @@ calc_crc_osdep(const unsigned char *buf, size_t len)
1337 * @return 0 on success (checksum matches), 1 on error 1359 * @return 0 on success (checksum matches), 1 on error
1338 */ 1360 */
1339static int 1361static int
1340check_crc_buf_osdep(const unsigned char *buf, size_t len) 1362check_crc_buf_osdep (const unsigned char *buf, size_t len)
1341{ 1363{
1342 unsigned long crc; 1364 unsigned long crc;
1343 1365
1344 crc = calc_crc_osdep(buf, len); 1366 crc = calc_crc_osdep (buf, len);
1345 buf += len; 1367 buf += len;
1346 if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && 1368 if ((((crc) & 0xFF) == buf[0])&&(((crc >> 8) & 0xFF) == buf[1])&&
1347 ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]) 1369 ( ((crc >> 16) & 0xFF) == buf[2]) &&( ((crc >> 24) & 0xFF) == buf[3]) )
1348 return 0; 1370 return 0;
1349 return 1; 1371 return 1;
1350} 1372}
@@ -1362,13 +1384,13 @@ check_crc_buf_osdep(const unsigned char *buf, size_t len)
1362 * @return number of the channel 1384 * @return number of the channel
1363 */ 1385 */
1364static int 1386static int
1365get_channel_from_frequency(int32_t frequency) 1387get_channel_from_frequency (int32_t frequency)
1366{ 1388{
1367 if (frequency >= 2412 && frequency <= 2472) 1389 if ((frequency >= 2412)&&(frequency <= 2472))
1368 return (frequency - 2407) / 5; 1390 return (frequency - 2407) / 5;
1369 if (frequency == 2484) 1391 if (frequency == 2484)
1370 return 14; 1392 return 14;
1371 if (frequency >= 5000 && frequency <= 6100) 1393 if ((frequency >= 5000)&&(frequency <= 6100))
1372 return (frequency - 5000) / 5; 1394 return (frequency - 5000) / 5;
1373 return -1; 1395 return -1;
1374} 1396}
@@ -1381,14 +1403,14 @@ get_channel_from_frequency(int32_t frequency)
1381 * @return channel number, -1 on error 1403 * @return channel number, -1 on error
1382 */ 1404 */
1383static int 1405static int
1384linux_get_channel(const struct HardwareInfos *dev) 1406linux_get_channel (const struct HardwareInfos *dev)
1385{ 1407{
1386 struct iwreq wrq; 1408 struct iwreq wrq;
1387 int32_t frequency; 1409 int32_t frequency;
1388 1410
1389 memset(&wrq, 0, sizeof(struct iwreq)); 1411 memset (&wrq, 0, sizeof(struct iwreq));
1390 strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ); 1412 strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
1391 if (0 > ioctl(dev->fd_raw, SIOCGIWFREQ, &wrq)) 1413 if (0 > ioctl (dev->fd_raw, SIOCGIWFREQ, &wrq))
1392 return -1; 1414 return -1;
1393 frequency = wrq.u.freq.m; /* 'iw_freq' defines 'm' as '__s32', so we keep it signed */ 1415 frequency = wrq.u.freq.m; /* 'iw_freq' defines 'm' as '__s32', so we keep it signed */
1394 if (100000000 < frequency) 1416 if (100000000 < frequency)
@@ -1396,7 +1418,7 @@ linux_get_channel(const struct HardwareInfos *dev)
1396 else if (1000000 < frequency) 1418 else if (1000000 < frequency)
1397 frequency /= 1000; 1419 frequency /= 1000;
1398 if (1000 < frequency) 1420 if (1000 < frequency)
1399 return get_channel_from_frequency(frequency); 1421 return get_channel_from_frequency (frequency);
1400 return frequency; 1422 return frequency;
1401} 1423}
1402 1424
@@ -1413,9 +1435,9 @@ linux_get_channel(const struct HardwareInfos *dev)
1413 * @return number of bytes written to 'buf' 1435 * @return number of bytes written to 'buf'
1414 */ 1436 */
1415static ssize_t 1437static ssize_t
1416linux_read(struct HardwareInfos *dev, 1438linux_read (struct HardwareInfos *dev,
1417 unsigned char *buf, size_t buf_size, 1439 unsigned char *buf, size_t buf_size,
1418 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) 1440 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
1419{ 1441{
1420 unsigned char tmpbuf[buf_size]; 1442 unsigned char tmpbuf[buf_size];
1421 ssize_t caplen; 1443 ssize_t caplen;
@@ -1425,207 +1447,210 @@ linux_read(struct HardwareInfos *dev,
1425 int got_channel = 0; 1447 int got_channel = 0;
1426 int fcs_removed = 0; 1448 int fcs_removed = 0;
1427 1449
1428 caplen = read(dev->fd_raw, tmpbuf, buf_size); 1450 caplen = read (dev->fd_raw, tmpbuf, buf_size);
1429 if (0 > caplen) 1451 if (0 > caplen)
1430 { 1452 {
1431 if (EAGAIN == errno) 1453 if (EAGAIN == errno)
1432 return 0; 1454 return 0;
1433 fprintf(stderr, "Failed to read from RAW socket: %s\n", strerror(errno)); 1455 fprintf (stderr, "Failed to read from RAW socket: %s\n", strerror (errno));
1434 return -1; 1456 return -1;
1435 } 1457 }
1436 1458
1437 memset(ri, 0, sizeof(*ri)); 1459 memset (ri, 0, sizeof(*ri));
1438 switch (dev->arptype_in) 1460 switch (dev->arptype_in)
1439 { 1461 {
1440 case ARPHRD_IEEE80211_PRISM: 1462 case ARPHRD_IEEE80211_PRISM:
1441 { 1463 {
1442 const struct PrismHeader *ph; 1464 const struct PrismHeader *ph;
1443 1465
1444 ph = (const struct PrismHeader*)tmpbuf; 1466 ph = (const struct PrismHeader*) tmpbuf;
1445 n = ph->msglen; 1467 n = ph->msglen;
1446 if ((n < 8) || (n >= caplen)) 1468 if ((n < 8) || (n >= caplen))
1447 return 0; /* invalid format */ 1469 return 0; /* invalid format */
1448 if ((PRISM_MSGCODE_MONITOR == ph->msgcode) && 1470 if ((PRISM_MSGCODE_MONITOR == ph->msgcode) &&
1449 (n >= sizeof(struct PrismHeader))) 1471 (n >= sizeof(struct PrismHeader)))
1472 {
1473 const char *pos;
1474 size_t left;
1475 struct PrismValue pv;
1476
1477 left = n - sizeof(struct PrismHeader);
1478 pos = (const char *) &ph[1];
1479 while (left > sizeof(struct PrismValue))
1450 { 1480 {
1451 const char *pos; 1481 left -= sizeof(struct PrismValue);
1452 size_t left; 1482 GNUNET_memcpy (&pv, pos, sizeof(struct PrismValue));
1453 struct PrismValue pv; 1483 pos += sizeof(struct PrismValue);
1484
1485 switch (pv.did)
1486 {
1487 case PRISM_DID_NOISE:
1488 if (PRISM_STATUS_OK == pv.status)
1489 {
1490 ri->ri_noise = pv.data;
1491 /* got_noise = 1; */
1492 }
1493 break;
1494
1495 case PRISM_DID_RATE:
1496 if (PRISM_STATUS_OK == pv.status)
1497 ri->ri_rate = pv.data * 500000;
1498 break;
1499
1500 case PRISM_DID_CHANNEL:
1501 if (PRISM_STATUS_OK == pv.status)
1502 {
1503 ri->ri_channel = pv.data;
1504 got_channel = 1;
1505 }
1506 break;
1507
1508 case PRISM_DID_MACTIME:
1509 if (PRISM_STATUS_OK == pv.status)
1510 ri->ri_mactime = pv.data;
1511 break;
1454 1512
1455 left = n - sizeof(struct PrismHeader); 1513 case PRISM_DID_SIGNAL:
1456 pos = (const char *)&ph[1]; 1514 if (PRISM_STATUS_OK == pv.status)
1457 while (left > sizeof(struct PrismValue))
1458 { 1515 {
1459 left -= sizeof(struct PrismValue); 1516 ri->ri_power = pv.data;
1460 GNUNET_memcpy(&pv, pos, sizeof(struct PrismValue)); 1517 /* got_signal = 1; */
1461 pos += sizeof(struct PrismValue);
1462
1463 switch (pv.did)
1464 {
1465 case PRISM_DID_NOISE:
1466 if (PRISM_STATUS_OK == pv.status)
1467 {
1468 ri->ri_noise = pv.data;
1469 /* got_noise = 1; */
1470 }
1471 break;
1472
1473 case PRISM_DID_RATE:
1474 if (PRISM_STATUS_OK == pv.status)
1475 ri->ri_rate = pv.data * 500000;
1476 break;
1477
1478 case PRISM_DID_CHANNEL:
1479 if (PRISM_STATUS_OK == pv.status)
1480 {
1481 ri->ri_channel = pv.data;
1482 got_channel = 1;
1483 }
1484 break;
1485
1486 case PRISM_DID_MACTIME:
1487 if (PRISM_STATUS_OK == pv.status)
1488 ri->ri_mactime = pv.data;
1489 break;
1490
1491 case PRISM_DID_SIGNAL:
1492 if (PRISM_STATUS_OK == pv.status)
1493 {
1494 ri->ri_power = pv.data;
1495 /* got_signal = 1; */
1496 }
1497 break;
1498 }
1499 } 1518 }
1519 break;
1520 }
1500 } 1521 }
1522 }
1501 if ((n < 8) || (n >= caplen)) 1523 if ((n < 8) || (n >= caplen))
1502 return 0; /* invalid format */ 1524 return 0; /* invalid format */
1503 } 1525 }
1504 break; 1526 break;
1505 1527
1506 case ARPHRD_IEEE80211_FULL: 1528 case ARPHRD_IEEE80211_FULL:
1507 { 1529 {
1508 struct Ieee80211RadiotapHeaderIterator iterator; 1530 struct Ieee80211RadiotapHeaderIterator iterator;
1509 struct Ieee80211RadiotapHeader *rthdr; 1531 struct Ieee80211RadiotapHeader *rthdr;
1510 1532
1511 memset(&iterator, 0, sizeof(iterator)); 1533 memset (&iterator, 0, sizeof(iterator));
1512 rthdr = (struct Ieee80211RadiotapHeader *)tmpbuf; 1534 rthdr = (struct Ieee80211RadiotapHeader *) tmpbuf;
1513 n = GNUNET_le16toh(rthdr->it_len); 1535 n = GNUNET_le16toh (rthdr->it_len);
1514 if ((n < sizeof(struct Ieee80211RadiotapHeader)) || (n >= caplen)) 1536 if ((n < sizeof(struct Ieee80211RadiotapHeader)) || (n >= caplen))
1515 return 0; /* invalid 'it_len' */ 1537 return 0; /* invalid 'it_len' */
1516 if (0 != ieee80211_radiotap_iterator_init(&iterator, rthdr, caplen)) 1538 if (0 != ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen))
1517 return 0; 1539 return 0;
1518 /* go through the radiotap arguments we have been given by the driver */ 1540 /* go through the radiotap arguments we have been given by the driver */
1519 while (0 <= ieee80211_radiotap_iterator_next(&iterator)) 1541 while (0 <= ieee80211_radiotap_iterator_next (&iterator))
1542 {
1543 switch (iterator.this_arg_index)
1520 { 1544 {
1521 switch (iterator.this_arg_index) 1545 case IEEE80211_RADIOTAP_TSFT:
1522 { 1546 ri->ri_mactime = GNUNET_le64toh (*((uint64_t *) iterator.this_arg));
1523 case IEEE80211_RADIOTAP_TSFT: 1547 break;
1524 ri->ri_mactime = GNUNET_le64toh(*((uint64_t *)iterator.this_arg));
1525 break;
1526
1527 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
1528 if (!got_signal)
1529 {
1530 ri->ri_power = *((int8_t*)iterator.this_arg);
1531 got_signal = 1;
1532 }
1533 break;
1534
1535 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
1536 if (!got_signal)
1537 {
1538 ri->ri_power = *((int8_t*)iterator.this_arg);
1539 got_signal = 1;
1540 }
1541 break;
1542
1543 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
1544 if (!got_noise)
1545 {
1546 ri->ri_noise = *((int8_t*)iterator.this_arg);
1547 got_noise = 1;
1548 }
1549 break;
1550
1551 case IEEE80211_RADIOTAP_DB_ANTNOISE:
1552 if (!got_noise)
1553 {
1554 ri->ri_noise = *((int8_t*)iterator.this_arg);
1555 got_noise = 1;
1556 }
1557 break;
1558
1559 case IEEE80211_RADIOTAP_ANTENNA:
1560 ri->ri_antenna = *iterator.this_arg;
1561 break;
1562
1563 case IEEE80211_RADIOTAP_CHANNEL:
1564 ri->ri_channel = *iterator.this_arg;
1565 got_channel = 1;
1566 break;
1567 1548
1568 case IEEE80211_RADIOTAP_RATE: 1549 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
1569 ri->ri_rate = (*iterator.this_arg) * 500000; 1550 if (! got_signal)
1570 break; 1551 {
1552 ri->ri_power = *((int8_t*) iterator.this_arg);
1553 got_signal = 1;
1554 }
1555 break;
1571 1556
1572 case IEEE80211_RADIOTAP_FLAGS: 1557 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
1573 { 1558 if (! got_signal)
1574 uint8_t flags = *iterator.this_arg; 1559 {
1575 /* is the CRC visible at the end? if so, remove */ 1560 ri->ri_power = *((int8_t*) iterator.this_arg);
1576 if (0 != (flags & IEEE80211_RADIOTAP_F_FCS)) 1561 got_signal = 1;
1577 { 1562 }
1578 fcs_removed = 1; 1563 break;
1579 caplen -= sizeof(uint32_t); 1564
1580 } 1565 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
1581 break; 1566 if (! got_noise)
1582 } 1567 {
1568 ri->ri_noise = *((int8_t*) iterator.this_arg);
1569 got_noise = 1;
1570 }
1571 break;
1572
1573 case IEEE80211_RADIOTAP_DB_ANTNOISE:
1574 if (! got_noise)
1575 {
1576 ri->ri_noise = *((int8_t*) iterator.this_arg);
1577 got_noise = 1;
1578 }
1579 break;
1583 1580
1584 case IEEE80211_RADIOTAP_RX_FLAGS: 1581 case IEEE80211_RADIOTAP_ANTENNA:
1582 ri->ri_antenna = *iterator.this_arg;
1583 break;
1584
1585 case IEEE80211_RADIOTAP_CHANNEL:
1586 ri->ri_channel = *iterator.this_arg;
1587 got_channel = 1;
1588 break;
1589
1590 case IEEE80211_RADIOTAP_RATE:
1591 ri->ri_rate = (*iterator.this_arg) * 500000;
1592 break;
1593
1594 case IEEE80211_RADIOTAP_FLAGS:
1595 {
1596 uint8_t flags = *iterator.this_arg;
1597 /* is the CRC visible at the end? if so, remove */
1598 if (0 != (flags & IEEE80211_RADIOTAP_F_FCS))
1585 { 1599 {
1586 uint16_t flags = ntohs(*((uint16_t *)iterator.this_arg)); 1600 fcs_removed = 1;
1587 if (0 != (flags & IEEE80211_RADIOTAP_F_RX_BADFCS)) 1601 caplen -= sizeof(uint32_t);
1588 return 0;
1589 } 1602 }
1590 break; 1603 break;
1591 } /* end of 'switch' */ 1604 }
1592 } /* end of the 'while' loop */ 1605
1606 case IEEE80211_RADIOTAP_RX_FLAGS:
1607 {
1608 uint16_t flags = ntohs (*((uint16_t *) iterator.this_arg));
1609 if (0 != (flags & IEEE80211_RADIOTAP_F_RX_BADFCS))
1610 return 0;
1611 }
1612 break;
1613 } /* end of 'switch' */
1614 } /* end of the 'while' loop */
1593 } 1615 }
1594 break; 1616 break;
1595 1617
1596 case ARPHRD_IEEE80211: 1618 case ARPHRD_IEEE80211:
1597 n = 0; /* no header */ 1619 n = 0; /* no header */
1598 break; 1620 break;
1599 1621
1600 case ARPHRD_ETHER: 1622 case ARPHRD_ETHER:
1601 { 1623 {
1602 if (sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) > caplen) 1624 if (sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) > caplen)
1603 return 0; /* invalid */ 1625 return 0; /* invalid */
1604 GNUNET_memcpy(&buf[sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)], 1626 GNUNET_memcpy (&buf[sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)],
1605 tmpbuf + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame), 1627 tmpbuf + sizeof(struct
1606 caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4 /* 4 byte FCS */); 1628 GNUNET_TRANSPORT_WLAN_Ieee8023Frame),
1629 caplen - sizeof(struct
1630 GNUNET_TRANSPORT_WLAN_Ieee8023Frame)
1631 - 4 /* 4 byte FCS */);
1607 return caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4; 1632 return caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4;
1608 } 1633 }
1609 1634
1610 default: 1635 default:
1611 errno = ENOTSUP; /* unsupported format */ 1636 errno = ENOTSUP; /* unsupported format */
1612 return -1; 1637 return -1;
1613 } 1638 }
1614 caplen -= n; 1639 caplen -= n;
1615 if (!got_channel) 1640 if (! got_channel)
1616 ri->ri_channel = linux_get_channel(dev); 1641 ri->ri_channel = linux_get_channel (dev);
1617 1642
1618 /* detect CRC32 at the end, even if the flag wasn't set and remove it */ 1643 /* detect CRC32 at the end, even if the flag wasn't set and remove it */
1619 if ((0 == fcs_removed) && 1644 if ((0 == fcs_removed) &&
1620 (0 == check_crc_buf_osdep(tmpbuf + n, caplen - sizeof(uint32_t)))) 1645 (0 == check_crc_buf_osdep (tmpbuf + n, caplen - sizeof(uint32_t))))
1621 { 1646 {
1622 /* NOTE: this heuristic can of course fail if there happens to 1647 /* NOTE: this heuristic can of course fail if there happens to
1623 be a matching checksum at the end. Would be good to have 1648 be a matching checksum at the end. Would be good to have
1624 some data to see how often this heuristic actually works. */ 1649 some data to see how often this heuristic actually works. */
1625 caplen -= sizeof(uint32_t); 1650 caplen -= sizeof(uint32_t);
1626 } 1651 }
1627 /* copy payload to target buffer */ 1652 /* copy payload to target buffer */
1628 GNUNET_memcpy(buf, tmpbuf + n, caplen); 1653 GNUNET_memcpy (buf, tmpbuf + n, caplen);
1629 return caplen; 1654 return caplen;
1630} 1655}
1631 1656
@@ -1642,7 +1667,7 @@ linux_read(struct HardwareInfos *dev,
1642 * @return 0 on success 1667 * @return 0 on success
1643 */ 1668 */
1644static int 1669static int
1645open_device_raw(struct HardwareInfos *dev) 1670open_device_raw (struct HardwareInfos *dev)
1646{ 1671{
1647 struct ifreq ifr; 1672 struct ifreq ifr;
1648 struct iwreq wrq; 1673 struct iwreq wrq;
@@ -1650,112 +1675,114 @@ open_device_raw(struct HardwareInfos *dev)
1650 struct sockaddr_ll sll; 1675 struct sockaddr_ll sll;
1651 1676
1652 /* find the interface index */ 1677 /* find the interface index */
1653 memset(&ifr, 0, sizeof(ifr)); 1678 memset (&ifr, 0, sizeof(ifr));
1654 strncpy(ifr.ifr_name, dev->iface, IFNAMSIZ); 1679 strncpy (ifr.ifr_name, dev->iface, IFNAMSIZ);
1655 if (-1 == ioctl(dev->fd_raw, SIOCGIFINDEX, &ifr)) 1680 if (-1 == ioctl (dev->fd_raw, SIOCGIFINDEX, &ifr))
1656 { 1681 {
1657 fprintf(stderr, "ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n", 1682 fprintf (stderr, "ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n",
1658 IFNAMSIZ, dev->iface, strerror(errno)); 1683 IFNAMSIZ, dev->iface, strerror (errno));
1659 return 1; 1684 return 1;
1660 } 1685 }
1661 1686
1662 /* lookup the hardware type */ 1687 /* lookup the hardware type */
1663 memset(&sll, 0, sizeof(sll)); 1688 memset (&sll, 0, sizeof(sll));
1664 sll.sll_family = AF_PACKET; 1689 sll.sll_family = AF_PACKET;
1665 sll.sll_ifindex = ifr.ifr_ifindex; 1690 sll.sll_ifindex = ifr.ifr_ifindex;
1666 sll.sll_protocol = htons(ETH_P_ALL); 1691 sll.sll_protocol = htons (ETH_P_ALL);
1667 if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr)) 1692 if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
1668 { 1693 {
1669 fprintf(stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", 1694 fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
1670 IFNAMSIZ, dev->iface, strerror(errno)); 1695 IFNAMSIZ, dev->iface, strerror (errno));
1671 return 1; 1696 return 1;
1672 } 1697 }
1673 if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && 1698 if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
1674 (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) && 1699 (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) &&
1675 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && 1700 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
1676 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL))) 1701 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)))
1677 { 1702 {
1678 fprintf(stderr, "Error: interface `%.*s' is not using a supported hardware address family (got %d)\n", 1703 fprintf (stderr,
1679 IFNAMSIZ, dev->iface, 1704 "Error: interface `%.*s' is not using a supported hardware address family (got %d)\n",
1680 ifr.ifr_hwaddr.sa_family); 1705 IFNAMSIZ, dev->iface,
1681 return 1; 1706 ifr.ifr_hwaddr.sa_family);
1682 } 1707 return 1;
1708 }
1683 1709
1684 /* lookup iw mode */ 1710 /* lookup iw mode */
1685 memset(&wrq, 0, sizeof(struct iwreq)); 1711 memset (&wrq, 0, sizeof(struct iwreq));
1686 strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ); 1712 strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
1687 if (-1 == ioctl(dev->fd_raw, SIOCGIWMODE, &wrq)) 1713 if (-1 == ioctl (dev->fd_raw, SIOCGIWMODE, &wrq))
1688 { 1714 {
1689 /* most probably not supported (ie for rtap ipw interface) * 1715 /* most probably not supported (ie for rtap ipw interface) *
1690 * so just assume its correctly set... */ 1716 * so just assume its correctly set... */
1691 wrq.u.mode = IW_MODE_MONITOR; 1717 wrq.u.mode = IW_MODE_MONITOR;
1692 } 1718 }
1693 1719
1694 if ((wrq.u.mode != IW_MODE_MONITOR) && 1720 if ((wrq.u.mode != IW_MODE_MONITOR) &&
1695 (wrq.u.mode != IW_MODE_ADHOC)) 1721 (wrq.u.mode != IW_MODE_ADHOC))
1696 { 1722 {
1697 fprintf(stderr, "Error: interface `%.*s' is not in monitor or ad-hoc mode (got %d)\n", 1723 fprintf (stderr,
1698 IFNAMSIZ, dev->iface, 1724 "Error: interface `%.*s' is not in monitor or ad-hoc mode (got %d)\n",
1699 wrq.u.mode); 1725 IFNAMSIZ, dev->iface,
1700 return 1; 1726 wrq.u.mode);
1701 } 1727 return 1;
1728 }
1702 1729
1703 /* Is interface st to up, broadcast & running ? */ 1730 /* Is interface st to up, broadcast & running ? */
1704 if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags) 1731 if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags)
1705 { 1732 {
1706 /* Bring interface up */ 1733 /* Bring interface up */
1707 ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING; 1734 ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
1708
1709 if (-1 == ioctl(dev->fd_raw, SIOCSIFFLAGS, &ifr))
1710 {
1711 fprintf(stderr, "ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n",
1712 IFNAMSIZ, dev->iface, strerror(errno));
1713 return 1;
1714 }
1715 }
1716 1735
1717 /* bind the raw socket to the interface */ 1736 if (-1 == ioctl (dev->fd_raw, SIOCSIFFLAGS, &ifr))
1718 if (-1 == bind(dev->fd_raw, (struct sockaddr *)&sll, sizeof(sll)))
1719 { 1737 {
1720 fprintf(stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ, 1738 fprintf (stderr, "ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n",
1721 dev->iface, strerror(errno)); 1739 IFNAMSIZ, dev->iface, strerror (errno));
1722 return 1; 1740 return 1;
1723 } 1741 }
1742 }
1743
1744 /* bind the raw socket to the interface */
1745 if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof(sll)))
1746 {
1747 fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ,
1748 dev->iface, strerror (errno));
1749 return 1;
1750 }
1724 1751
1725 /* lookup the hardware type */ 1752 /* lookup the hardware type */
1726 if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr)) 1753 if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
1727 { 1754 {
1728 fprintf(stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", 1755 fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
1729 IFNAMSIZ, dev->iface, strerror(errno)); 1756 IFNAMSIZ, dev->iface, strerror (errno));
1730 return 1; 1757 return 1;
1731 } 1758 }
1732 1759
1733 GNUNET_memcpy(&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE); 1760 GNUNET_memcpy (&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE);
1734 dev->arptype_in = ifr.ifr_hwaddr.sa_family; 1761 dev->arptype_in = ifr.ifr_hwaddr.sa_family;
1735 if ((ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) && 1762 if ((ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) &&
1736 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && 1763 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
1737 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && 1764 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
1738 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) 1765 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL))
1739 { 1766 {
1740 fprintf(stderr, "Unsupported hardware link type %d on interface `%.*s'\n", 1767 fprintf (stderr, "Unsupported hardware link type %d on interface `%.*s'\n",
1741 ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface); 1768 ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface);
1742 return 1; 1769 return 1;
1743 } 1770 }
1744 1771
1745 /* enable promiscuous mode */ 1772 /* enable promiscuous mode */
1746 memset(&mr, 0, sizeof(mr)); 1773 memset (&mr, 0, sizeof(mr));
1747 mr.mr_ifindex = sll.sll_ifindex; 1774 mr.mr_ifindex = sll.sll_ifindex;
1748 mr.mr_type = PACKET_MR_PROMISC; 1775 mr.mr_type = PACKET_MR_PROMISC;
1749 if (0 != 1776 if (0 !=
1750 setsockopt(dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, 1777 setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
1751 sizeof(mr))) 1778 sizeof(mr)))
1752 { 1779 {
1753 fprintf(stderr, 1780 fprintf (stderr,
1754 "Failed to enable promiscuous mode on interface `%.*s'\n", 1781 "Failed to enable promiscuous mode on interface `%.*s'\n",
1755 IFNAMSIZ, 1782 IFNAMSIZ,
1756 dev->iface); 1783 dev->iface);
1757 return 1; 1784 return 1;
1758 } 1785 }
1759 return 0; 1786 return 0;
1760} 1787}
1761 1788
@@ -1768,22 +1795,22 @@ open_device_raw(struct HardwareInfos *dev)
1768 * @return 0 on success, 1 on error 1795 * @return 0 on success, 1 on error
1769 */ 1796 */
1770static int 1797static int
1771test_wlan_interface(const char *iface) 1798test_wlan_interface (const char *iface)
1772{ 1799{
1773 char strbuf[512]; 1800 char strbuf[512];
1774 struct stat sbuf; 1801 struct stat sbuf;
1775 int ret; 1802 int ret;
1776 1803
1777 ret = snprintf(strbuf, sizeof(strbuf), 1804 ret = snprintf (strbuf, sizeof(strbuf),
1778 "/sys/class/net/%s/phy80211/subsystem", 1805 "/sys/class/net/%s/phy80211/subsystem",
1779 iface); 1806 iface);
1780 if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat(strbuf, &sbuf))) 1807 if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat (strbuf, &sbuf)))
1781 { 1808 {
1782 fprintf(stderr, 1809 fprintf (stderr,
1783 "Did not find 802.11 interface `%s'. Exiting.\n", 1810 "Did not find 802.11 interface `%s'. Exiting.\n",
1784 iface); 1811 iface);
1785 exit(1); 1812 exit (1);
1786 } 1813 }
1787 return 0; 1814 return 0;
1788} 1815}
1789 1816
@@ -1796,19 +1823,19 @@ test_wlan_interface(const char *iface)
1796 * @return 0 if mac belongs to us, 1 if mac is for another target 1823 * @return 0 if mac belongs to us, 1 if mac is for another target
1797 */ 1824 */
1798static int 1825static int
1799mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, 1826mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1800 const struct HardwareInfos *dev) 1827 const struct HardwareInfos *dev)
1801{ 1828{
1802 static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros; 1829 static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros;
1803 1830
1804 if ((0 == memcmp(&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) || 1831 if ((0 == memcmp (&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) ||
1805 (0 == memcmp(&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE))) 1832 (0 == memcmp (&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)))
1806 return 0; /* some drivers set no Macs, then assume it is all for us! */ 1833 return 0; /* some drivers set no Macs, then assume it is all for us! */
1807 1834
1808 if (0 != memcmp(&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE)) 1835 if (0 != memcmp (&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE))
1809 return 1; /* not a GNUnet ad-hoc package */ 1836 return 1; /* not a GNUnet ad-hoc package */
1810 if ((0 == memcmp(&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) || 1837 if ((0 == memcmp (&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) ||
1811 (0 == memcmp(&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE))) 1838 (0 == memcmp (&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)))
1812 return 0; /* for us, or broadcast */ 1839 return 0; /* for us, or broadcast */
1813 return 1; /* not for us */ 1840 return 1; /* not for us */
1814} 1841}
@@ -1821,10 +1848,10 @@ mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1821 * @param dev pointer to the Hardware_Infos struct 1848 * @param dev pointer to the Hardware_Infos struct
1822 */ 1849 */
1823static void 1850static void
1824mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, 1851mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1825 const struct HardwareInfos *dev) 1852 const struct HardwareInfos *dev)
1826{ 1853{
1827 taIeeeHeader->frame_control = htons(IEEE80211_FC0_TYPE_DATA); 1854 taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
1828 taIeeeHeader->addr2 = dev->pl_mac; 1855 taIeeeHeader->addr2 = dev->pl_mac;
1829 taIeeeHeader->addr3 = mac_bssid_gnunet; 1856 taIeeeHeader->addr3 = mac_bssid_gnunet;
1830} 1857}
@@ -1839,7 +1866,7 @@ mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1839 * @param hdr pointer to the start of the packet 1866 * @param hdr pointer to the start of the packet
1840 */ 1867 */
1841static void 1868static void
1842stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr) 1869stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1843{ 1870{
1844 struct HardwareInfos *dev = cls; 1871 struct HardwareInfos *dev = cls;
1845 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header; 1872 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header;
@@ -1848,58 +1875,67 @@ stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
1848 struct RadiotapTransmissionHeader rtheader; 1875 struct RadiotapTransmissionHeader rtheader;
1849 struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame etheader; 1876 struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame etheader;
1850 1877
1851 sendsize = ntohs(hdr->size); 1878 sendsize = ntohs (hdr->size);
1852 if ((sendsize < 1879 if ((sendsize <
1853 sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) || 1880 sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) ||
1854 (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type))) 1881 (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)))
1855 { 1882 {
1856 fprintf(stderr, "Received malformed message\n"); 1883 fprintf (stderr, "Received malformed message\n");
1857 exit(1); 1884 exit (1);
1858 } 1885 }
1859 sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); 1886 sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)
1887 - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
1860 if (MAXLINE < sendsize) 1888 if (MAXLINE < sendsize)
1861 { 1889 {
1862 fprintf(stderr, "Packet too big for buffer\n"); 1890 fprintf (stderr, "Packet too big for buffer\n");
1863 exit(1); 1891 exit (1);
1864 } 1892 }
1865 header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr; 1893 header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
1866 switch (dev->arptype_in) 1894 switch (dev->arptype_in)
1867 { 1895 {
1868 case ARPHRD_IEEE80211_PRISM: 1896 case ARPHRD_IEEE80211_PRISM:
1869 case ARPHRD_IEEE80211_FULL: 1897 case ARPHRD_IEEE80211_FULL:
1870 case ARPHRD_IEEE80211: 1898 case ARPHRD_IEEE80211:
1871 rtheader.header.it_version = 0; 1899 rtheader.header.it_version = 0;
1872 rtheader.header.it_pad = 0; 1900 rtheader.header.it_pad = 0;
1873 rtheader.header.it_len = GNUNET_htole16(sizeof(rtheader)); 1901 rtheader.header.it_len = GNUNET_htole16 (sizeof(rtheader));
1874 rtheader.header.it_present = GNUNET_htole16(IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK); 1902 rtheader.header.it_present = GNUNET_htole16 (
1875 rtheader.rate = header->rate; 1903 IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK);
1876 rtheader.pad1 = 0; 1904 rtheader.rate = header->rate;
1877 rtheader.txflags = GNUNET_htole16(IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ); 1905 rtheader.pad1 = 0;
1878 GNUNET_memcpy(write_pout.buf, &rtheader, sizeof(rtheader)); 1906 rtheader.txflags = GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK
1879 GNUNET_memcpy(&write_pout.buf[sizeof(rtheader)], &header->frame, sendsize); 1907 | IEEE80211_RADIOTAP_F_TX_NOSEQ);
1880 wlanheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)&write_pout.buf[sizeof(rtheader)]; 1908 GNUNET_memcpy (write_pout.buf, &rtheader, sizeof(rtheader));
1881 1909 GNUNET_memcpy (&write_pout.buf[sizeof(rtheader)], &header->frame, sendsize);
1882 /* payload contains MAC address, but we don't trust it, so we'll 1910 wlanheader = (struct
1883 * overwrite it with OUR MAC address to prevent mischief */ 1911 GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &write_pout.buf[sizeof(
1884 mac_set(wlanheader, dev); 1912 rtheader)
1885 write_pout.size = sendsize + sizeof(rtheader); 1913 ];
1886 break; 1914
1915 /* payload contains MAC address, but we don't trust it, so we'll
1916 * overwrite it with OUR MAC address to prevent mischief */
1917 mac_set (wlanheader, dev);
1918 write_pout.size = sendsize + sizeof(rtheader);
1919 break;
1887 1920
1888 case ARPHRD_ETHER: 1921 case ARPHRD_ETHER:
1889 etheader.dst = header->frame.addr1; 1922 etheader.dst = header->frame.addr1;
1890 /* etheader.src = header->frame.addr2; --- untrusted input */ 1923 /* etheader.src = header->frame.addr2; --- untrusted input */
1891 etheader.src = dev->pl_mac; 1924 etheader.src = dev->pl_mac;
1892 etheader.type = htons(ETH_P_IP); 1925 etheader.type = htons (ETH_P_IP);
1893 GNUNET_memcpy(write_pout.buf, &etheader, sizeof(etheader)); 1926 GNUNET_memcpy (write_pout.buf, &etheader, sizeof(etheader));
1894 GNUNET_memcpy(&write_pout.buf[sizeof(etheader)], &header[1], sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); 1927 GNUNET_memcpy (&write_pout.buf[sizeof(etheader)], &header[1], sendsize
1895 write_pout.size = sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame) + sizeof(etheader); 1928 - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
1896 break; 1929 write_pout.size = sendsize - sizeof(struct
1930 GNUNET_TRANSPORT_WLAN_Ieee80211Frame)
1931 + sizeof(etheader);
1932 break;
1897 1933
1898 default: 1934 default:
1899 fprintf(stderr, 1935 fprintf (stderr,
1900 "Unsupported ARPTYPE!\n"); 1936 "Unsupported ARPTYPE!\n");
1901 break; 1937 break;
1902 } 1938 }
1903} 1939}
1904 1940
1905 1941
@@ -1914,7 +1950,7 @@ stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
1914 * @return 0 on success (never happens, as we don't return unless aborted), 1 on error 1950 * @return 0 on success (never happens, as we don't return unless aborted), 1 on error
1915 */ 1951 */
1916int 1952int
1917main(int argc, char *argv[]) 1953main (int argc, char *argv[])
1918{ 1954{
1919 struct HardwareInfos dev; 1955 struct HardwareInfos dev;
1920 char readbuf[MAXLINE]; 1956 char readbuf[MAXLINE];
@@ -1928,83 +1964,83 @@ main(int argc, char *argv[])
1928 /* assert privs so we can modify the firewall rules! */ 1964 /* assert privs so we can modify the firewall rules! */
1929 { 1965 {
1930#ifdef HAVE_SETRESUID 1966#ifdef HAVE_SETRESUID
1931 uid_t uid = getuid(); 1967 uid_t uid = getuid ();
1932 1968
1933 if (0 != setresuid(uid, 0, 0)) 1969 if (0 != setresuid (uid, 0, 0))
1934 { 1970 {
1935 fprintf(stderr, 1971 fprintf (stderr,
1936 "Failed to setresuid to root: %s\n", 1972 "Failed to setresuid to root: %s\n",
1937 strerror(errno)); 1973 strerror (errno));
1938 return 254; 1974 return 254;
1939 } 1975 }
1940#else 1976#else
1941 if (0 != seteuid(0)) 1977 if (0 != seteuid (0))
1942 { 1978 {
1943 fprintf(stderr, 1979 fprintf (stderr,
1944 "Failed to seteuid back to root: %s\n", strerror(errno)); 1980 "Failed to seteuid back to root: %s\n", strerror (errno));
1945 return 254; 1981 return 254;
1946 } 1982 }
1947#endif 1983#endif
1948 } 1984 }
1949 1985
1950 /* make use of SGID capabilities on POSIX */ 1986 /* make use of SGID capabilities on POSIX */
1951 memset(&dev, 0, sizeof(dev)); 1987 memset (&dev, 0, sizeof(dev));
1952 dev.fd_raw = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); 1988 dev.fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
1953 raw_eno = errno; /* remember for later */ 1989 raw_eno = errno; /* remember for later */
1954 1990
1955 /* now that we've dropped root rights, we can do error checking */ 1991 /* now that we've dropped root rights, we can do error checking */
1956 if (2 != argc) 1992 if (2 != argc)
1957 { 1993 {
1958 fprintf(stderr, 1994 fprintf (stderr,
1959 "You must specify the name of the interface as the first and only argument to this program.\n"); 1995 "You must specify the name of the interface as the first and only argument to this program.\n");
1960 if (-1 != dev.fd_raw) 1996 if (-1 != dev.fd_raw)
1961 (void)close(dev.fd_raw); 1997 (void) close (dev.fd_raw);
1962 return 1; 1998 return 1;
1963 } 1999 }
1964 2000
1965 if (-1 == dev.fd_raw) 2001 if (-1 == dev.fd_raw)
1966 { 2002 {
1967 fprintf(stderr, "Failed to create raw socket: %s\n", strerror(raw_eno)); 2003 fprintf (stderr, "Failed to create raw socket: %s\n", strerror (raw_eno));
1968 return 1; 2004 return 1;
1969 } 2005 }
1970 if (dev.fd_raw >= FD_SETSIZE) 2006 if (dev.fd_raw >= FD_SETSIZE)
2007 {
2008 fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
2009 dev.fd_raw, FD_SETSIZE);
2010 (void) close (dev.fd_raw);
2011 return 1;
2012 }
2013 if (0 != test_wlan_interface (argv[1]))
2014 {
2015 (void) close (dev.fd_raw);
2016 return 1;
2017 }
2018 strncpy (dev.iface, argv[1], IFNAMSIZ);
2019 if (0 != open_device_raw (&dev))
2020 {
2021 (void) close (dev.fd_raw);
2022 return 1;
2023 }
2024
2025 /* drop privs */
2026 {
2027 uid_t uid = getuid ();
2028#ifdef HAVE_SETRESUID
2029 if (0 != setresuid (uid, uid, uid))
1971 { 2030 {
1972 fprintf(stderr, "File descriptor too large for select (%d > %d)\n", 2031 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
1973 dev.fd_raw, FD_SETSIZE); 2032 if (-1 != dev.fd_raw)
1974 (void)close(dev.fd_raw); 2033 (void) close (dev.fd_raw);
1975 return 1;
1976 }
1977 if (0 != test_wlan_interface(argv[1]))
1978 {
1979 (void)close(dev.fd_raw);
1980 return 1; 2034 return 1;
1981 } 2035 }
1982 strncpy(dev.iface, argv[1], IFNAMSIZ); 2036#else
1983 if (0 != open_device_raw(&dev)) 2037 if (0 != (setuid (uid) | seteuid (uid)))
1984 { 2038 {
1985 (void)close(dev.fd_raw); 2039 fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
2040 if (-1 != dev.fd_raw)
2041 (void) close (dev.fd_raw);
1986 return 1; 2042 return 1;
1987 } 2043 }
1988
1989 /* drop privs */
1990 {
1991 uid_t uid = getuid();
1992#ifdef HAVE_SETRESUID
1993 if (0 != setresuid(uid, uid, uid))
1994 {
1995 fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno));
1996 if (-1 != dev.fd_raw)
1997 (void)close(dev.fd_raw);
1998 return 1;
1999 }
2000#else
2001 if (0 != (setuid(uid) | seteuid(uid)))
2002 {
2003 fprintf(stderr, "Failed to setuid: %s\n", strerror(errno));
2004 if (-1 != dev.fd_raw)
2005 (void)close(dev.fd_raw);
2006 return 1;
2007 }
2008#endif 2044#endif
2009 } 2045 }
2010 2046
@@ -2013,141 +2049,145 @@ main(int argc, char *argv[])
2013 { 2049 {
2014 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 2050 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
2015 2051
2016 macmsg.hdr.size = htons(sizeof(macmsg)); 2052 macmsg.hdr.size = htons (sizeof(macmsg));
2017 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 2053 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
2018 GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)); 2054 GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof(struct
2019 GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg)); 2055 GNUNET_TRANSPORT_WLAN_MacAddress));
2056 GNUNET_memcpy (write_std.buf, &macmsg, sizeof(macmsg));
2020 write_std.size = sizeof(macmsg); 2057 write_std.size = sizeof(macmsg);
2021 } 2058 }
2022 2059
2023 stdin_mst = mst_create(&stdin_send_hw, &dev); 2060 stdin_mst = mst_create (&stdin_send_hw, &dev);
2024 stdin_open = 1; 2061 stdin_open = 1;
2025 while (1) 2062 while (1)
2063 {
2064 maxfd = -1;
2065 FD_ZERO (&rfds);
2066 if ((0 == write_pout.size) && (1 == stdin_open))
2026 { 2067 {
2027 maxfd = -1; 2068 FD_SET (STDIN_FILENO, &rfds);
2028 FD_ZERO(&rfds); 2069 maxfd = MAX (maxfd, STDIN_FILENO);
2029 if ((0 == write_pout.size) && (1 == stdin_open)) 2070 }
2030 { 2071 if (0 == write_std.size)
2031 FD_SET(STDIN_FILENO, &rfds); 2072 {
2032 maxfd = MAX(maxfd, STDIN_FILENO); 2073 FD_SET (dev.fd_raw, &rfds);
2033 } 2074 maxfd = MAX (maxfd, dev.fd_raw);
2034 if (0 == write_std.size) 2075 }
2035 { 2076 FD_ZERO (&wfds);
2036 FD_SET(dev.fd_raw, &rfds); 2077 if (0 < write_std.size)
2037 maxfd = MAX(maxfd, dev.fd_raw); 2078 {
2038 } 2079 FD_SET (STDOUT_FILENO, &wfds);
2039 FD_ZERO(&wfds); 2080 maxfd = MAX (maxfd, STDOUT_FILENO);
2040 if (0 < write_std.size) 2081 }
2041 { 2082 if (0 < write_pout.size)
2042 FD_SET(STDOUT_FILENO, &wfds); 2083 {
2043 maxfd = MAX(maxfd, STDOUT_FILENO); 2084 FD_SET (dev.fd_raw, &wfds);
2044 } 2085 maxfd = MAX (maxfd, dev.fd_raw);
2045 if (0 < write_pout.size) 2086 }
2046 { 2087 {
2047 FD_SET(dev.fd_raw, &wfds); 2088 int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
2048 maxfd = MAX(maxfd, dev.fd_raw); 2089 if ((-1 == retval) && (EINTR == errno))
2049 } 2090 continue;
2091 if (0 > retval)
2050 { 2092 {
2051 int retval = select(maxfd + 1, &rfds, &wfds, NULL, NULL); 2093 fprintf (stderr, "select failed: %s\n", strerror (errno));
2052 if ((-1 == retval) && (EINTR == errno)) 2094 break;
2053 continue;
2054 if (0 > retval)
2055 {
2056 fprintf(stderr, "select failed: %s\n", strerror(errno));
2057 break;
2058 }
2059 } 2095 }
2060 if (FD_ISSET(STDOUT_FILENO, &wfds)) 2096 }
2061 { 2097 if (FD_ISSET (STDOUT_FILENO, &wfds))
2062 ssize_t ret = 2098 {
2063 write(STDOUT_FILENO, write_std.buf + write_std.pos, 2099 ssize_t ret =
2064 write_std.size - write_std.pos); 2100 write (STDOUT_FILENO, write_std.buf + write_std.pos,
2065 if (0 > ret) 2101 write_std.size - write_std.pos);
2066 { 2102 if (0 > ret)
2067 fprintf(stderr, "Failed to write to STDOUT: %s\n", strerror(errno)); 2103 {
2068 break; 2104 fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
2069 } 2105 break;
2070 write_std.pos += ret; 2106 }
2071 if (write_std.pos == write_std.size) 2107 write_std.pos += ret;
2072 { 2108 if (write_std.pos == write_std.size)
2073 write_std.pos = 0; 2109 {
2074 write_std.size = 0; 2110 write_std.pos = 0;
2075 } 2111 write_std.size = 0;
2076 } 2112 }
2077 if (FD_ISSET(dev.fd_raw, &wfds)) 2113 }
2078 { 2114 if (FD_ISSET (dev.fd_raw, &wfds))
2079 ssize_t ret = 2115 {
2080 write(dev.fd_raw, write_pout.buf + write_pout.pos, 2116 ssize_t ret =
2081 write_pout.size - write_pout.pos); 2117 write (dev.fd_raw, write_pout.buf + write_pout.pos,
2082 if (0 > ret) 2118 write_pout.size - write_pout.pos);
2083 { 2119 if (0 > ret)
2084 fprintf(stderr, "Failed to write to WLAN device: %s\n", 2120 {
2085 strerror(errno)); 2121 fprintf (stderr, "Failed to write to WLAN device: %s\n",
2086 break; 2122 strerror (errno));
2087 } 2123 break;
2088 write_pout.pos += ret; 2124 }
2089 if ((write_pout.pos != write_pout.size) && (0 != ret)) 2125 write_pout.pos += ret;
2090 { 2126 if ((write_pout.pos != write_pout.size) && (0 != ret))
2091 /* we should not get partial sends with packet-oriented devices... */ 2127 {
2092 fprintf(stderr, "Write error, partial send: %u/%u\n", 2128 /* we should not get partial sends with packet-oriented devices... */
2093 (unsigned int)write_pout.pos, 2129 fprintf (stderr, "Write error, partial send: %u/%u\n",
2094 (unsigned int)write_pout.size); 2130 (unsigned int) write_pout.pos,
2095 break; 2131 (unsigned int) write_pout.size);
2096 } 2132 break;
2097 if (write_pout.pos == write_pout.size) 2133 }
2098 { 2134 if (write_pout.pos == write_pout.size)
2099 write_pout.pos = 0; 2135 {
2100 write_pout.size = 0; 2136 write_pout.pos = 0;
2101 } 2137 write_pout.size = 0;
2102 } 2138 }
2139 }
2103 2140
2104 if (FD_ISSET(STDIN_FILENO, &rfds)) 2141 if (FD_ISSET (STDIN_FILENO, &rfds))
2105 { 2142 {
2106 ssize_t ret = 2143 ssize_t ret =
2107 read(STDIN_FILENO, readbuf, sizeof(readbuf)); 2144 read (STDIN_FILENO, readbuf, sizeof(readbuf));
2108 if (0 > ret) 2145 if (0 > ret)
2109 { 2146 {
2110 fprintf(stderr, "Read error from STDIN: %s\n", strerror(errno)); 2147 fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno));
2111 break; 2148 break;
2112 } 2149 }
2113 if (0 == ret) 2150 if (0 == ret)
2114 { 2151 {
2115 /* stop reading... */ 2152 /* stop reading... */
2116 stdin_open = 0; 2153 stdin_open = 0;
2117 } 2154 }
2118 mst_receive(stdin_mst, readbuf, ret); 2155 mst_receive (stdin_mst, readbuf, ret);
2119 } 2156 }
2120 2157
2121 if (FD_ISSET(dev.fd_raw, &rfds)) 2158 if (FD_ISSET (dev.fd_raw, &rfds))
2122 { 2159 {
2123 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm; 2160 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
2124 ssize_t ret; 2161 ssize_t ret;
2125 2162
2126 rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf; 2163 rrm = (struct
2127 ret = 2164 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
2128 linux_read(&dev, (unsigned char *)&rrm->frame, 2165 ret =
2129 sizeof(write_std.buf) 2166 linux_read (&dev, (unsigned char *) &rrm->frame,
2130 - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) 2167 sizeof(write_std.buf)
2131 + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame), 2168 - sizeof(struct
2132 rrm); 2169 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2133 if (0 > ret) 2170 + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
2134 { 2171 rrm);
2135 fprintf(stderr, "Read error from raw socket: %s\n", strerror(errno)); 2172 if (0 > ret)
2136 break; 2173 {
2137 } 2174 fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno));
2138 if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev))) 2175 break;
2139 { 2176 }
2140 write_std.size = ret 2177 if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
2141 + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) 2178 {
2142 - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame); 2179 write_std.size = ret
2143 rrm->header.size = htons(write_std.size); 2180 + sizeof(struct
2144 rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); 2181 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2145 } 2182 - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
2146 } 2183 rrm->header.size = htons (write_std.size);
2184 rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
2185 }
2147 } 2186 }
2187 }
2148 /* Error handling, try to clean up a bit at least */ 2188 /* Error handling, try to clean up a bit at least */
2149 mst_destroy(stdin_mst); 2189 mst_destroy (stdin_mst);
2150 (void)close(dev.fd_raw); 2190 (void) close (dev.fd_raw);
2151 return 1; /* we never exit 'normally' */ 2191 return 1; /* we never exit 'normally' */
2152} 2192}
2153 2193
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 @@
176 * the value chosen here might be too aggressively low! 176 * the value chosen here might be too aggressively low!
177 */ 177 */
178#define DELAY_WARN_THRESHOLD \ 178#define DELAY_WARN_THRESHOLD \
179 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 179 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
180 180
181/** 181/**
182 * If a DVBox could not be forwarded after this number of 182 * If a DVBox could not be forwarded after this number of
183 * seconds we drop it. 183 * seconds we drop it.
184 */ 184 */
185#define DV_FORWARD_TIMEOUT \ 185#define DV_FORWARD_TIMEOUT \
186 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) 186 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
187 187
188/** 188/**
189 * We only consider queues as "quality" connections when 189 * We only consider queues as "quality" connections when
@@ -191,53 +191,53 @@
191 * the latency of the queue is below this threshold. 191 * the latency of the queue is below this threshold.
192 */ 192 */
193#define DV_QUALITY_RTT_THRESHOLD \ 193#define DV_QUALITY_RTT_THRESHOLD \
194 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) 194 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
195 195
196/** 196/**
197 * How long do we consider a DV path valid if we see no 197 * How long do we consider a DV path valid if we see no
198 * further updates on it? Note: the value chosen here might be too low! 198 * further updates on it? Note: the value chosen here might be too low!
199 */ 199 */
200#define DV_PATH_VALIDITY_TIMEOUT \ 200#define DV_PATH_VALIDITY_TIMEOUT \
201 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) 201 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
202 202
203/** 203/**
204 * How long do we cache backchannel (struct Backtalker) information 204 * How long do we cache backchannel (struct Backtalker) information
205 * after a backchannel goes inactive? 205 * after a backchannel goes inactive?
206 */ 206 */
207#define BACKCHANNEL_INACTIVITY_TIMEOUT \ 207#define BACKCHANNEL_INACTIVITY_TIMEOUT \
208 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) 208 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
209 209
210/** 210/**
211 * How long before paths expire would we like to (re)discover DV paths? Should 211 * How long before paths expire would we like to (re)discover DV paths? Should
212 * be below #DV_PATH_VALIDITY_TIMEOUT. 212 * be below #DV_PATH_VALIDITY_TIMEOUT.
213 */ 213 */
214#define DV_PATH_DISCOVERY_FREQUENCY \ 214#define DV_PATH_DISCOVERY_FREQUENCY \
215 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 4) 215 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4)
216 216
217/** 217/**
218 * How long are ephemeral keys valid? 218 * How long are ephemeral keys valid?
219 */ 219 */
220#define EPHEMERAL_VALIDITY \ 220#define EPHEMERAL_VALIDITY \
221 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) 221 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
222 222
223/** 223/**
224 * How long do we keep partially reassembled messages around before giving up? 224 * How long do we keep partially reassembled messages around before giving up?
225 */ 225 */
226#define REASSEMBLY_EXPIRATION \ 226#define REASSEMBLY_EXPIRATION \
227 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 4) 227 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4)
228 228
229/** 229/**
230 * What is the fastest rate at which we send challenges *if* we keep learning 230 * What is the fastest rate at which we send challenges *if* we keep learning
231 * an address (gossip, DHT, etc.)? 231 * an address (gossip, DHT, etc.)?
232 */ 232 */
233#define FAST_VALIDATION_CHALLENGE_FREQ \ 233#define FAST_VALIDATION_CHALLENGE_FREQ \
234 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) 234 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
235 235
236/** 236/**
237 * What is the slowest rate at which we send challenges? 237 * What is the slowest rate at which we send challenges?
238 */ 238 */
239#define MAX_VALIDATION_CHALLENGE_FREQ \ 239#define MAX_VALIDATION_CHALLENGE_FREQ \
240 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 1) 240 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1)
241 241
242/** 242/**
243 * How long until we forget about historic accumulators and thus 243 * How long until we forget about historic accumulators and thus
@@ -245,7 +245,7 @@
245 * active connection experiences without an ACK. 245 * active connection experiences without an ACK.
246 */ 246 */
247#define ACK_CUMMULATOR_TIMEOUT \ 247#define ACK_CUMMULATOR_TIMEOUT \
248 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) 248 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
249 249
250/** 250/**
251 * What is the non-randomized base frequency at which we 251 * What is the non-randomized base frequency at which we
@@ -263,13 +263,13 @@
263 * When do we forget an invalid address for sure? 263 * When do we forget an invalid address for sure?
264 */ 264 */
265#define MAX_ADDRESS_VALID_UNTIL \ 265#define MAX_ADDRESS_VALID_UNTIL \
266 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MONTHS, 1) 266 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1)
267 267
268/** 268/**
269 * How long do we consider an address valid if we just checked? 269 * How long do we consider an address valid if we just checked?
270 */ 270 */
271#define ADDRESS_VALIDATION_LIFETIME \ 271#define ADDRESS_VALIDATION_LIFETIME \
272 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) 272 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
273 273
274/** 274/**
275 * What is the maximum frequency at which we do address validation? 275 * What is the maximum frequency at which we do address validation?
@@ -308,7 +308,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
308/** 308/**
309 * Unique identifier we attach to a message. 309 * Unique identifier we attach to a message.
310 */ 310 */
311struct MessageUUIDP { 311struct MessageUUIDP
312{
312 /** 313 /**
313 * Unique value, generated by incrementing the 314 * Unique value, generated by incrementing the
314 * `message_uuid_ctr` of `struct Neighbour`. 315 * `message_uuid_ctr` of `struct Neighbour`.
@@ -320,7 +321,8 @@ struct MessageUUIDP {
320/** 321/**
321 * Unique identifier to map an acknowledgement to a transmission. 322 * Unique identifier to map an acknowledgement to a transmission.
322 */ 323 */
323struct AcknowledgementUUIDP { 324struct AcknowledgementUUIDP
325{
324 /** 326 /**
325 * The UUID value. 327 * The UUID value.
326 */ 328 */
@@ -331,7 +333,8 @@ struct AcknowledgementUUIDP {
331/** 333/**
332 * Type of a nonce used for challenges. 334 * Type of a nonce used for challenges.
333 */ 335 */
334struct ChallengeNonceP { 336struct ChallengeNonceP
337{
335 /** 338 /**
336 * The value of the nonce. Note that this is NOT a hash. 339 * The value of the nonce. Note that this is NOT a hash.
337 */ 340 */
@@ -342,7 +345,8 @@ struct ChallengeNonceP {
342/** 345/**
343 * Outer layer of an encapsulated backchannel message. 346 * Outer layer of an encapsulated backchannel message.
344 */ 347 */
345struct TransportBackchannelEncapsulationMessage { 348struct TransportBackchannelEncapsulationMessage
349{
346 /** 350 /**
347 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION. 351 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION.
348 */ 352 */
@@ -358,7 +362,8 @@ struct TransportBackchannelEncapsulationMessage {
358/** 362/**
359 * Body by which a peer confirms that it is using an ephemeral key. 363 * Body by which a peer confirms that it is using an ephemeral key.
360 */ 364 */
361struct EphemeralConfirmationPS { 365struct EphemeralConfirmationPS
366{
362 /** 367 /**
363 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL 368 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL
364 */ 369 */
@@ -397,7 +402,8 @@ struct EphemeralConfirmationPS {
397 * Plaintext of the variable-size payload that is encrypted 402 * Plaintext of the variable-size payload that is encrypted
398 * within a `struct TransportBackchannelEncapsulationMessage` 403 * within a `struct TransportBackchannelEncapsulationMessage`
399 */ 404 */
400struct TransportDVBoxPayloadP { 405struct TransportDVBoxPayloadP
406{
401 /** 407 /**
402 * Sender's peer identity. 408 * Sender's peer identity.
403 */ 409 */
@@ -430,7 +436,8 @@ struct TransportDVBoxPayloadP {
430 * Outer layer of an encapsulated unfragmented application message sent 436 * Outer layer of an encapsulated unfragmented application message sent
431 * over an unreliable channel. 437 * over an unreliable channel.
432 */ 438 */
433struct TransportReliabilityBoxMessage { 439struct TransportReliabilityBoxMessage
440{
434 /** 441 /**
435 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX 442 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX
436 */ 443 */
@@ -456,7 +463,8 @@ struct TransportReliabilityBoxMessage {
456/** 463/**
457 * Acknowledgement payload. 464 * Acknowledgement payload.
458 */ 465 */
459struct TransportCummulativeAckPayloadP { 466struct TransportCummulativeAckPayloadP
467{
460 /** 468 /**
461 * How long was the ACK delayed for generating cummulative ACKs? 469 * How long was the ACK delayed for generating cummulative ACKs?
462 * Used to calculate the correct network RTT by taking the receipt 470 * Used to calculate the correct network RTT by taking the receipt
@@ -479,7 +487,8 @@ struct TransportCummulativeAckPayloadP {
479 * so ACKs are identified by a combination of PID of sender and 487 * so ACKs are identified by a combination of PID of sender and
480 * message UUID, without the queue playing any role! 488 * message UUID, without the queue playing any role!
481 */ 489 */
482struct TransportReliabilityAckMessage { 490struct TransportReliabilityAckMessage
491{
483 /** 492 /**
484 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK 493 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK
485 */ 494 */
@@ -499,7 +508,8 @@ struct TransportReliabilityAckMessage {
499/** 508/**
500 * Outer layer of an encapsulated fragmented application message. 509 * Outer layer of an encapsulated fragmented application message.
501 */ 510 */
502struct TransportFragmentBoxMessage { 511struct TransportFragmentBoxMessage
512{
503 /** 513 /**
504 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT 514 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT
505 */ 515 */
@@ -549,7 +559,8 @@ struct TransportFragmentBoxMessage {
549 * potential amplificator will check the @e monotonic_time and only respond 559 * potential amplificator will check the @e monotonic_time and only respond
550 * (at most) once per message. 560 * (at most) once per message.
551 */ 561 */
552struct DvInitPS { 562struct DvInitPS
563{
553 /** 564 /**
554 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 565 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR
555 */ 566 */
@@ -592,7 +603,8 @@ struct DvInitPS {
592 * replay old messages. Thus, passively learned paths should always be 603 * replay old messages. Thus, passively learned paths should always be
593 * immediately marked as "potentially stale". 604 * immediately marked as "potentially stale".
594 */ 605 */
595struct DvHopPS { 606struct DvHopPS
607{
596 /** 608 /**
597 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP 609 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP
598 */ 610 */
@@ -619,7 +631,8 @@ struct DvHopPS {
619 * An entry describing a peer on a path in a 631 * An entry describing a peer on a path in a
620 * `struct TransportDVLearnMessage` message. 632 * `struct TransportDVLearnMessage` message.
621 */ 633 */
622struct DVPathEntryP { 634struct DVPathEntryP
635{
623 /** 636 /**
624 * Identity of a peer on the path. 637 * Identity of a peer on the path.
625 */ 638 */
@@ -646,7 +659,8 @@ struct DVPathEntryP {
646 * zero, peers that can forward to the initator should always try to 659 * zero, peers that can forward to the initator should always try to
647 * forward to the initiator. 660 * forward to the initiator.
648 */ 661 */
649struct TransportDVLearnMessage { 662struct TransportDVLearnMessage
663{
650 /** 664 /**
651 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN 665 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN
652 */ 666 */
@@ -733,7 +747,8 @@ struct TransportDVLearnMessage {
733 * the predecessor must be the origin (so this is not really useful 747 * the predecessor must be the origin (so this is not really useful
734 * for anonymization). 748 * for anonymization).
735 */ 749 */
736struct TransportDVBoxMessage { 750struct TransportDVBoxMessage
751{
737 /** 752 /**
738 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX 753 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX
739 */ 754 */
@@ -791,7 +806,8 @@ struct TransportDVBoxMessage {
791 * Message send to another peer to validate that it can indeed 806 * Message send to another peer to validate that it can indeed
792 * receive messages at a particular address. 807 * receive messages at a particular address.
793 */ 808 */
794struct TransportValidationChallengeMessage { 809struct TransportValidationChallengeMessage
810{
795 /** 811 /**
796 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE 812 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE
797 */ 813 */
@@ -819,7 +835,8 @@ struct TransportValidationChallengeMessage {
819 * Message signed by a peer to confirm that it can indeed 835 * Message signed by a peer to confirm that it can indeed
820 * receive messages at a particular address. 836 * receive messages at a particular address.
821 */ 837 */
822struct TransportValidationPS { 838struct TransportValidationPS
839{
823 /** 840 /**
824 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE 841 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE
825 */ 842 */
@@ -842,7 +859,8 @@ struct TransportValidationPS {
842 * Message send to a peer to respond to a 859 * Message send to a peer to respond to a
843 * #GNUNET_MESSAGE_TYPE_ADDRESS_VALIDATION_CHALLENGE 860 * #GNUNET_MESSAGE_TYPE_ADDRESS_VALIDATION_CHALLENGE
844 */ 861 */
845struct TransportValidationResponseMessage { 862struct TransportValidationResponseMessage
863{
846 /** 864 /**
847 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE 865 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE
848 */ 866 */
@@ -886,7 +904,8 @@ struct TransportValidationResponseMessage {
886 * send to us, and how much data we already received from the other 904 * send to us, and how much data we already received from the other
887 * peer. 905 * peer.
888 */ 906 */
889struct TransportFlowControlMessage { 907struct TransportFlowControlMessage
908{
890 /** 909 /**
891 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL 910 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL
892 */ 911 */
@@ -942,7 +961,8 @@ GNUNET_NETWORK_STRUCT_END
942/** 961/**
943 * What type of client is the `struct TransportClient` about? 962 * What type of client is the `struct TransportClient` about?
944 */ 963 */
945enum ClientType { 964enum ClientType
965{
946 /** 966 /**
947 * We do not know yet (client is fresh). 967 * We do not know yet (client is fresh).
948 */ 968 */
@@ -974,7 +994,8 @@ enum ClientType {
974 * Which transmission options are allowable for transmission? 994 * Which transmission options are allowable for transmission?
975 * Interpreted bit-wise! 995 * Interpreted bit-wise!
976 */ 996 */
977enum RouteMessageOptions { 997enum RouteMessageOptions
998{
978 /** 999 /**
979 * Only confirmed, non-DV direct neighbours. 1000 * Only confirmed, non-DV direct neighbours.
980 */ 1001 */
@@ -1007,7 +1028,8 @@ enum RouteMessageOptions {
1007/** 1028/**
1008 * When did we launch this DV learning activity? 1029 * When did we launch this DV learning activity?
1009 */ 1030 */
1010struct LearnLaunchEntry { 1031struct LearnLaunchEntry
1032{
1011 /** 1033 /**
1012 * Kept (also) in a DLL sorted by launch time. 1034 * Kept (also) in a DLL sorted by launch time.
1013 */ 1035 */
@@ -1035,7 +1057,8 @@ struct LearnLaunchEntry {
1035 * Information we keep per #GOODPUT_AGING_SLOTS about historic 1057 * Information we keep per #GOODPUT_AGING_SLOTS about historic
1036 * (or current) transmission performance. 1058 * (or current) transmission performance.
1037 */ 1059 */
1038struct TransmissionHistoryEntry { 1060struct TransmissionHistoryEntry
1061{
1039 /** 1062 /**
1040 * Number of bytes actually sent in the interval. 1063 * Number of bytes actually sent in the interval.
1041 */ 1064 */
@@ -1052,7 +1075,8 @@ struct TransmissionHistoryEntry {
1052/** 1075/**
1053 * Performance data for a transmission possibility. 1076 * Performance data for a transmission possibility.
1054 */ 1077 */
1055struct PerformanceData { 1078struct PerformanceData
1079{
1056 /** 1080 /**
1057 * Weighted average for the RTT. 1081 * Weighted average for the RTT.
1058 */ 1082 */
@@ -1119,7 +1143,8 @@ struct VirtualLink;
1119 * Context from #handle_incoming_msg(). Closure for many 1143 * Context from #handle_incoming_msg(). Closure for many
1120 * message handlers below. 1144 * message handlers below.
1121 */ 1145 */
1122struct CommunicatorMessageContext { 1146struct CommunicatorMessageContext
1147{
1123 /** 1148 /**
1124 * Kept in a DLL of `struct VirtualLink` if waiting for CORE 1149 * Kept in a DLL of `struct VirtualLink` if waiting for CORE
1125 * flow control to unchoke. 1150 * flow control to unchoke.
@@ -1153,7 +1178,8 @@ struct CommunicatorMessageContext {
1153/** 1178/**
1154 * Closure for #core_env_sent_cb. 1179 * Closure for #core_env_sent_cb.
1155 */ 1180 */
1156struct CoreSentContext { 1181struct CoreSentContext
1182{
1157 /** 1183 /**
1158 * Kept in a DLL to clear @e vl in case @e vl is lost. 1184 * Kept in a DLL to clear @e vl in case @e vl is lost.
1159 */ 1185 */
@@ -1192,7 +1218,8 @@ struct CoreSentContext {
1192 * data that is per neighbour that is not specific to how the 1218 * data that is per neighbour that is not specific to how the
1193 * connectivity is established. 1219 * connectivity is established.
1194 */ 1220 */
1195struct VirtualLink { 1221struct VirtualLink
1222{
1196 /** 1223 /**
1197 * Identity of the peer at the other end of the link. 1224 * Identity of the peer at the other end of the link.
1198 */ 1225 */
@@ -1390,7 +1417,8 @@ struct VirtualLink {
1390/** 1417/**
1391 * Data structure kept when we are waiting for an acknowledgement. 1418 * Data structure kept when we are waiting for an acknowledgement.
1392 */ 1419 */
1393struct PendingAcknowledgement { 1420struct PendingAcknowledgement
1421{
1394 /** 1422 /**
1395 * If @e pm is non-NULL, this is the DLL in which this acknowledgement 1423 * If @e pm is non-NULL, this is the DLL in which this acknowledgement
1396 * is kept in relation to its pending message. 1424 * is kept in relation to its pending message.
@@ -1483,7 +1511,8 @@ struct PendingAcknowledgement {
1483/** 1511/**
1484 * One possible hop towards a DV target. 1512 * One possible hop towards a DV target.
1485 */ 1513 */
1486struct DistanceVectorHop { 1514struct DistanceVectorHop
1515{
1487 /** 1516 /**
1488 * Kept in a MDLL, sorted by @e timeout. 1517 * Kept in a MDLL, sorted by @e timeout.
1489 */ 1518 */
@@ -1564,7 +1593,8 @@ struct DistanceVectorHop {
1564 * Entry in our #dv_routes table, representing a (set of) distance 1593 * Entry in our #dv_routes table, representing a (set of) distance
1565 * vector routes to a particular peer. 1594 * vector routes to a particular peer.
1566 */ 1595 */
1567struct DistanceVector { 1596struct DistanceVector
1597{
1568 /** 1598 /**
1569 * To which peer is this a route? 1599 * To which peer is this a route?
1570 */ 1600 */
@@ -1628,7 +1658,8 @@ struct DistanceVector {
1628 * what the communicator can actually provide towards a particular 1658 * what the communicator can actually provide towards a particular
1629 * peer/target). 1659 * peer/target).
1630 */ 1660 */
1631struct QueueEntry { 1661struct QueueEntry
1662{
1632 /** 1663 /**
1633 * Kept as a DLL. 1664 * Kept as a DLL.
1634 */ 1665 */
@@ -1660,7 +1691,8 @@ struct QueueEntry {
1660 * A queue is a message queue provided by a communicator 1691 * A queue is a message queue provided by a communicator
1661 * via which we can reach a particular neighbour. 1692 * via which we can reach a particular neighbour.
1662 */ 1693 */
1663struct Queue { 1694struct Queue
1695{
1664 /** 1696 /**
1665 * Kept in a MDLL. 1697 * Kept in a MDLL.
1666 */ 1698 */
@@ -1788,7 +1820,8 @@ struct Queue {
1788/** 1820/**
1789 * Information we keep for a message that we are reassembling. 1821 * Information we keep for a message that we are reassembling.
1790 */ 1822 */
1791struct ReassemblyContext { 1823struct ReassemblyContext
1824{
1792 /** 1825 /**
1793 * Original message ID for of the message that all the fragments 1826 * Original message ID for of the message that all the fragments
1794 * belong to. 1827 * belong to.
@@ -1846,7 +1879,8 @@ struct ReassemblyContext {
1846/** 1879/**
1847 * A neighbour that at least one communicator is connected to. 1880 * A neighbour that at least one communicator is connected to.
1848 */ 1881 */
1849struct Neighbour { 1882struct Neighbour
1883{
1850 /** 1884 /**
1851 * Which peer is this about? 1885 * Which peer is this about?
1852 */ 1886 */
@@ -1929,7 +1963,8 @@ struct Neighbour {
1929 * Another peer attempted to talk to us, we should try to establish 1963 * Another peer attempted to talk to us, we should try to establish
1930 * a connection in the other direction. 1964 * a connection in the other direction.
1931 */ 1965 */
1932struct IncomingRequest { 1966struct IncomingRequest
1967{
1933 /** 1968 /**
1934 * Kept in a DLL. 1969 * Kept in a DLL.
1935 */ 1970 */
@@ -1955,7 +1990,8 @@ struct IncomingRequest {
1955/** 1990/**
1956 * A peer that an application (client) would like us to talk to directly. 1991 * A peer that an application (client) would like us to talk to directly.
1957 */ 1992 */
1958struct PeerRequest { 1993struct PeerRequest
1994{
1959 /** 1995 /**
1960 * Which peer is this about? 1996 * Which peer is this about?
1961 */ 1997 */
@@ -1988,7 +2024,8 @@ struct PeerRequest {
1988/** 2024/**
1989 * Types of different pending messages. 2025 * Types of different pending messages.
1990 */ 2026 */
1991enum PendingMessageType { 2027enum PendingMessageType
2028{
1992 /** 2029 /**
1993 * Ordinary message received from the CORE service. 2030 * Ordinary message received from the CORE service.
1994 */ 2031 */
@@ -2037,7 +2074,8 @@ enum PendingMessageType {
2037 * is never again transmitted (even if it fits below the MTU), and 2074 * is never again transmitted (even if it fits below the MTU), and
2038 * only (remaining) fragments are sent. 2075 * only (remaining) fragments are sent.
2039 */ 2076 */
2040struct PendingMessage { 2077struct PendingMessage
2078{
2041 /** 2079 /**
2042 * Kept in a MDLL of messages for this @a vl. 2080 * Kept in a MDLL of messages for this @a vl.
2043 */ 2081 */
@@ -2176,7 +2214,8 @@ struct PendingMessage {
2176/** 2214/**
2177 * Acknowledgement payload. 2215 * Acknowledgement payload.
2178 */ 2216 */
2179struct TransportCummulativeAckPayload { 2217struct TransportCummulativeAckPayload
2218{
2180 /** 2219 /**
2181 * When did we receive the message we are ACKing? Used to calculate 2220 * When did we receive the message we are ACKing? Used to calculate
2182 * the delay we introduced by cummulating ACKs. 2221 * the delay we introduced by cummulating ACKs.
@@ -2194,7 +2233,8 @@ struct TransportCummulativeAckPayload {
2194 * Data structure in which we track acknowledgements still to 2233 * Data structure in which we track acknowledgements still to
2195 * be sent to the 2234 * be sent to the
2196 */ 2235 */
2197struct AcknowledgementCummulator { 2236struct AcknowledgementCummulator
2237{
2198 /** 2238 /**
2199 * Target peer for which we are accumulating ACKs here. 2239 * Target peer for which we are accumulating ACKs here.
2200 */ 2240 */
@@ -2234,7 +2274,8 @@ struct AcknowledgementCummulator {
2234/** 2274/**
2235 * One of the addresses of this peer. 2275 * One of the addresses of this peer.
2236 */ 2276 */
2237struct AddressListEntry { 2277struct AddressListEntry
2278{
2238 /** 2279 /**
2239 * Kept in a DLL. 2280 * Kept in a DLL.
2240 */ 2281 */
@@ -2286,7 +2327,8 @@ struct AddressListEntry {
2286/** 2327/**
2287 * Client connected to the transport service. 2328 * Client connected to the transport service.
2288 */ 2329 */
2289struct TransportClient { 2330struct TransportClient
2331{
2290 /** 2332 /**
2291 * Kept in a DLL. 2333 * Kept in a DLL.
2292 */ 2334 */
@@ -2312,11 +2354,13 @@ struct TransportClient {
2312 */ 2354 */
2313 enum ClientType type; 2355 enum ClientType type;
2314 2356
2315 union { 2357 union
2358 {
2316 /** 2359 /**
2317 * Information for @e type #CT_CORE. 2360 * Information for @e type #CT_CORE.
2318 */ 2361 */
2319 struct { 2362 struct
2363 {
2320 /** 2364 /**
2321 * Head of list of messages pending for this client, sorted by 2365 * Head of list of messages pending for this client, sorted by
2322 * transmission time ("next_attempt" + possibly internal prioritization). 2366 * transmission time ("next_attempt" + possibly internal prioritization).
@@ -2332,7 +2376,8 @@ struct TransportClient {
2332 /** 2376 /**
2333 * Information for @e type #CT_MONITOR. 2377 * Information for @e type #CT_MONITOR.
2334 */ 2378 */
2335 struct { 2379 struct
2380 {
2336 /** 2381 /**
2337 * Peer identity to monitor the addresses of. 2382 * Peer identity to monitor the addresses of.
2338 * Zero to monitor all neighbours. Valid if 2383 * Zero to monitor all neighbours. Valid if
@@ -2350,7 +2395,8 @@ struct TransportClient {
2350 /** 2395 /**
2351 * Information for @e type #CT_COMMUNICATOR. 2396 * Information for @e type #CT_COMMUNICATOR.
2352 */ 2397 */
2353 struct { 2398 struct
2399 {
2354 /** 2400 /**
2355 * If @e type is #CT_COMMUNICATOR, this communicator 2401 * If @e type is #CT_COMMUNICATOR, this communicator
2356 * supports communicating using these addresses. 2402 * supports communicating using these addresses.
@@ -2395,7 +2441,8 @@ struct TransportClient {
2395 /** 2441 /**
2396 * Information for @e type #CT_APPLICATION 2442 * Information for @e type #CT_APPLICATION
2397 */ 2443 */
2398 struct { 2444 struct
2445 {
2399 /** 2446 /**
2400 * Map of requests for peers the given client application would like to 2447 * Map of requests for peers the given client application would like to
2401 * see connections for. Maps from PIDs to `struct PeerRequest`. 2448 * see connections for. Maps from PIDs to `struct PeerRequest`.
@@ -2410,7 +2457,8 @@ struct TransportClient {
2410 * State we keep for validation activities. Each of these 2457 * State we keep for validation activities. Each of these
2411 * is both in the #validation_heap and the #validation_map. 2458 * is both in the #validation_heap and the #validation_map.
2412 */ 2459 */
2413struct ValidationState { 2460struct ValidationState
2461{
2414 /** 2462 /**
2415 * For which peer is @a address to be validated (or possibly valid)? 2463 * For which peer is @a address to be validated (or possibly valid)?
2416 * Serves as key in the #validation_map. 2464 * Serves as key in the #validation_map.
@@ -2520,7 +2568,8 @@ struct ValidationState {
2520 * material (to avoid repeatedly checking signatures), and to synchronize 2568 * material (to avoid repeatedly checking signatures), and to synchronize
2521 * monotonic time with the PEERSTORE. 2569 * monotonic time with the PEERSTORE.
2522 */ 2570 */
2523struct Backtalker { 2571struct Backtalker
2572{
2524 /** 2573 /**
2525 * Peer this is about. 2574 * Peer this is about.
2526 */ 2575 */
@@ -2743,11 +2792,11 @@ static struct GNUNET_TIME_Absolute hello_mono_time;
2743 * @return current age of the world 2792 * @return current age of the world
2744 */ 2793 */
2745static unsigned int 2794static unsigned int
2746get_age() 2795get_age ()
2747{ 2796{
2748 struct GNUNET_TIME_Absolute now; 2797 struct GNUNET_TIME_Absolute now;
2749 2798
2750 now = GNUNET_TIME_absolute_get(); 2799 now = GNUNET_TIME_absolute_get ();
2751 return now.abs_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us / 15; 2800 return now.abs_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us / 15;
2752} 2801}
2753 2802
@@ -2758,13 +2807,13 @@ get_age()
2758 * @param ir data structure to release 2807 * @param ir data structure to release
2759 */ 2808 */
2760static void 2809static void
2761free_incoming_request(struct IncomingRequest *ir) 2810free_incoming_request (struct IncomingRequest *ir)
2762{ 2811{
2763 GNUNET_CONTAINER_DLL_remove(ir_head, ir_tail, ir); 2812 GNUNET_CONTAINER_DLL_remove (ir_head, ir_tail, ir);
2764 GNUNET_assert(ir_total > 0); 2813 GNUNET_assert (ir_total > 0);
2765 ir_total--; 2814 ir_total--;
2766 GNUNET_PEERSTORE_watch_cancel(ir->wc); 2815 GNUNET_PEERSTORE_watch_cancel (ir->wc);
2767 GNUNET_free(ir); 2816 GNUNET_free (ir);
2768} 2817}
2769 2818
2770 2819
@@ -2774,34 +2823,34 @@ free_incoming_request(struct IncomingRequest *ir)
2774 * @param pa data structure to release 2823 * @param pa data structure to release
2775 */ 2824 */
2776static void 2825static void
2777free_pending_acknowledgement(struct PendingAcknowledgement *pa) 2826free_pending_acknowledgement (struct PendingAcknowledgement *pa)
2778{ 2827{
2779 struct Queue *q = pa->queue; 2828 struct Queue *q = pa->queue;
2780 struct PendingMessage *pm = pa->pm; 2829 struct PendingMessage *pm = pa->pm;
2781 struct DistanceVectorHop *dvh = pa->dvh; 2830 struct DistanceVectorHop *dvh = pa->dvh;
2782 2831
2783 GNUNET_CONTAINER_MDLL_remove(pa, pa_head, pa_tail, pa); 2832 GNUNET_CONTAINER_MDLL_remove (pa, pa_head, pa_tail, pa);
2784 pa_count--; 2833 pa_count--;
2785 if (NULL != q) 2834 if (NULL != q)
2786 { 2835 {
2787 GNUNET_CONTAINER_MDLL_remove(queue, q->pa_head, q->pa_tail, pa); 2836 GNUNET_CONTAINER_MDLL_remove (queue, q->pa_head, q->pa_tail, pa);
2788 pa->queue = NULL; 2837 pa->queue = NULL;
2789 } 2838 }
2790 if (NULL != pm) 2839 if (NULL != pm)
2791 { 2840 {
2792 GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa); 2841 GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa);
2793 pa->pm = NULL; 2842 pa->pm = NULL;
2794 } 2843 }
2795 if (NULL != dvh) 2844 if (NULL != dvh)
2796 { 2845 {
2797 GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa); 2846 GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa);
2798 pa->queue = NULL; 2847 pa->queue = NULL;
2799 } 2848 }
2800 GNUNET_assert(GNUNET_YES == 2849 GNUNET_assert (GNUNET_YES ==
2801 GNUNET_CONTAINER_multiuuidmap_remove(pending_acks, 2850 GNUNET_CONTAINER_multiuuidmap_remove (pending_acks,
2802 &pa->ack_uuid.value, 2851 &pa->ack_uuid.value,
2803 pa)); 2852 pa));
2804 GNUNET_free(pa); 2853 GNUNET_free (pa);
2805} 2854}
2806 2855
2807 2856
@@ -2814,23 +2863,23 @@ free_pending_acknowledgement(struct PendingAcknowledgement *pa)
2814 * @param root root of the tree to free 2863 * @param root root of the tree to free
2815 */ 2864 */
2816static void 2865static void
2817free_fragment_tree(struct PendingMessage *root) 2866free_fragment_tree (struct PendingMessage *root)
2818{ 2867{
2819 struct PendingMessage *frag; 2868 struct PendingMessage *frag;
2820 2869
2821 while (NULL != (frag = root->head_frag)) 2870 while (NULL != (frag = root->head_frag))
2822 { 2871 {
2823 struct PendingAcknowledgement *pa; 2872 struct PendingAcknowledgement *pa;
2824 2873
2825 free_fragment_tree(frag); 2874 free_fragment_tree (frag);
2826 while (NULL != (pa = frag->pa_head)) 2875 while (NULL != (pa = frag->pa_head))
2827 { 2876 {
2828 GNUNET_CONTAINER_MDLL_remove(pm, frag->pa_head, frag->pa_tail, pa); 2877 GNUNET_CONTAINER_MDLL_remove (pm, frag->pa_head, frag->pa_tail, pa);
2829 pa->pm = NULL; 2878 pa->pm = NULL;
2830 }
2831 GNUNET_CONTAINER_MDLL_remove(frag, root->head_frag, root->tail_frag, frag);
2832 GNUNET_free(frag);
2833 } 2879 }
2880 GNUNET_CONTAINER_MDLL_remove (frag, root->head_frag, root->tail_frag, frag);
2881 GNUNET_free (frag);
2882 }
2834} 2883}
2835 2884
2836 2885
@@ -2842,44 +2891,44 @@ free_fragment_tree(struct PendingMessage *root)
2842 * @param pm the pending message to free 2891 * @param pm the pending message to free
2843 */ 2892 */
2844static void 2893static void
2845free_pending_message(struct PendingMessage *pm) 2894free_pending_message (struct PendingMessage *pm)
2846{ 2895{
2847 struct TransportClient *tc = pm->client; 2896 struct TransportClient *tc = pm->client;
2848 struct VirtualLink *vl = pm->vl; 2897 struct VirtualLink *vl = pm->vl;
2849 struct PendingAcknowledgement *pa; 2898 struct PendingAcknowledgement *pa;
2850 2899
2851 if (NULL != tc) 2900 if (NULL != tc)
2852 { 2901 {
2853 GNUNET_CONTAINER_MDLL_remove(client, 2902 GNUNET_CONTAINER_MDLL_remove (client,
2854 tc->details.core.pending_msg_head, 2903 tc->details.core.pending_msg_head,
2855 tc->details.core.pending_msg_tail, 2904 tc->details.core.pending_msg_tail,
2856 pm); 2905 pm);
2857 } 2906 }
2858 if (NULL != vl) 2907 if (NULL != vl)
2859 { 2908 {
2860 GNUNET_CONTAINER_MDLL_remove(vl, 2909 GNUNET_CONTAINER_MDLL_remove (vl,
2861 vl->pending_msg_head, 2910 vl->pending_msg_head,
2862 vl->pending_msg_tail, 2911 vl->pending_msg_tail,
2863 pm); 2912 pm);
2864 } 2913 }
2865 while (NULL != (pa = pm->pa_head)) 2914 while (NULL != (pa = pm->pa_head))
2866 { 2915 {
2867 GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa); 2916 GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa);
2868 pa->pm = NULL; 2917 pa->pm = NULL;
2869 } 2918 }
2870 2919
2871 free_fragment_tree(pm); 2920 free_fragment_tree (pm);
2872 if (NULL != pm->qe) 2921 if (NULL != pm->qe)
2873 { 2922 {
2874 GNUNET_assert(pm == pm->qe->pm); 2923 GNUNET_assert (pm == pm->qe->pm);
2875 pm->qe->pm = NULL; 2924 pm->qe->pm = NULL;
2876 } 2925 }
2877 if (NULL != pm->bpm) 2926 if (NULL != pm->bpm)
2878 { 2927 {
2879 free_fragment_tree(pm->bpm); 2928 free_fragment_tree (pm->bpm);
2880 GNUNET_free(pm->bpm); 2929 GNUNET_free (pm->bpm);
2881 } 2930 }
2882 GNUNET_free(pm); 2931 GNUNET_free (pm);
2883} 2932}
2884 2933
2885 2934
@@ -2889,34 +2938,34 @@ free_pending_message(struct PendingMessage *pm)
2889 * @param vl link data to free 2938 * @param vl link data to free
2890 */ 2939 */
2891static void 2940static void
2892free_virtual_link(struct VirtualLink *vl) 2941free_virtual_link (struct VirtualLink *vl)
2893{ 2942{
2894 struct PendingMessage *pm; 2943 struct PendingMessage *pm;
2895 struct CoreSentContext *csc; 2944 struct CoreSentContext *csc;
2896 2945
2897 while (NULL != (pm = vl->pending_msg_head)) 2946 while (NULL != (pm = vl->pending_msg_head))
2898 free_pending_message(pm); 2947 free_pending_message (pm);
2899 GNUNET_assert(GNUNET_YES == 2948 GNUNET_assert (GNUNET_YES ==
2900 GNUNET_CONTAINER_multipeermap_remove(links, &vl->target, vl)); 2949 GNUNET_CONTAINER_multipeermap_remove (links, &vl->target, vl));
2901 if (NULL != vl->visibility_task) 2950 if (NULL != vl->visibility_task)
2902 { 2951 {
2903 GNUNET_SCHEDULER_cancel(vl->visibility_task); 2952 GNUNET_SCHEDULER_cancel (vl->visibility_task);
2904 vl->visibility_task = NULL; 2953 vl->visibility_task = NULL;
2905 } 2954 }
2906 if (NULL != vl->fc_retransmit_task) 2955 if (NULL != vl->fc_retransmit_task)
2907 { 2956 {
2908 GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task); 2957 GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task);
2909 vl->fc_retransmit_task = NULL; 2958 vl->fc_retransmit_task = NULL;
2910 } 2959 }
2911 while (NULL != (csc = vl->csc_head)) 2960 while (NULL != (csc = vl->csc_head))
2912 { 2961 {
2913 GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, csc); 2962 GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, csc);
2914 GNUNET_assert(vl == csc->vl); 2963 GNUNET_assert (vl == csc->vl);
2915 csc->vl = NULL; 2964 csc->vl = NULL;
2916 } 2965 }
2917 GNUNET_break(NULL == vl->n); 2966 GNUNET_break (NULL == vl->n);
2918 GNUNET_break(NULL == vl->dv); 2967 GNUNET_break (NULL == vl->dv);
2919 GNUNET_free(vl); 2968 GNUNET_free (vl);
2920} 2969}
2921 2970
2922 2971
@@ -2926,20 +2975,20 @@ free_virtual_link(struct VirtualLink *vl)
2926 * @param vs validation state to free 2975 * @param vs validation state to free
2927 */ 2976 */
2928static void 2977static void
2929free_validation_state(struct ValidationState *vs) 2978free_validation_state (struct ValidationState *vs)
2930{ 2979{
2931 GNUNET_assert( 2980 GNUNET_assert (
2932 GNUNET_YES == 2981 GNUNET_YES ==
2933 GNUNET_CONTAINER_multipeermap_remove(validation_map, &vs->pid, vs)); 2982 GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs));
2934 GNUNET_CONTAINER_heap_remove_node(vs->hn); 2983 GNUNET_CONTAINER_heap_remove_node (vs->hn);
2935 vs->hn = NULL; 2984 vs->hn = NULL;
2936 if (NULL != vs->sc) 2985 if (NULL != vs->sc)
2937 { 2986 {
2938 GNUNET_PEERSTORE_store_cancel(vs->sc); 2987 GNUNET_PEERSTORE_store_cancel (vs->sc);
2939 vs->sc = NULL; 2988 vs->sc = NULL;
2940 } 2989 }
2941 GNUNET_free(vs->address); 2990 GNUNET_free (vs->address);
2942 GNUNET_free(vs); 2991 GNUNET_free (vs);
2943} 2992}
2944 2993
2945 2994
@@ -2950,9 +2999,9 @@ free_validation_state(struct ValidationState *vs)
2950 * @return NULL if we do not have this peer as a neighbour 2999 * @return NULL if we do not have this peer as a neighbour
2951 */ 3000 */
2952static struct Neighbour * 3001static struct Neighbour *
2953lookup_neighbour(const struct GNUNET_PeerIdentity *pid) 3002lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
2954{ 3003{
2955 return GNUNET_CONTAINER_multipeermap_get(neighbours, pid); 3004 return GNUNET_CONTAINER_multipeermap_get (neighbours, pid);
2956} 3005}
2957 3006
2958 3007
@@ -2963,16 +3012,17 @@ lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
2963 * @return NULL if we do not have this peer as a virtual link 3012 * @return NULL if we do not have this peer as a virtual link
2964 */ 3013 */
2965static struct VirtualLink * 3014static struct VirtualLink *
2966lookup_virtual_link(const struct GNUNET_PeerIdentity *pid) 3015lookup_virtual_link (const struct GNUNET_PeerIdentity *pid)
2967{ 3016{
2968 return GNUNET_CONTAINER_multipeermap_get(links, pid); 3017 return GNUNET_CONTAINER_multipeermap_get (links, pid);
2969} 3018}
2970 3019
2971 3020
2972/** 3021/**
2973 * Details about what to notify monitors about. 3022 * Details about what to notify monitors about.
2974 */ 3023 */
2975struct MonitorEvent { 3024struct MonitorEvent
3025{
2976 /** 3026 /**
2977 * @deprecated To be discussed if we keep these... 3027 * @deprecated To be discussed if we keep these...
2978 */ 3028 */
@@ -3011,20 +3061,20 @@ struct MonitorEvent {
3011 * @param dvh hop to free 3061 * @param dvh hop to free
3012 */ 3062 */
3013static void 3063static void
3014free_distance_vector_hop(struct DistanceVectorHop *dvh) 3064free_distance_vector_hop (struct DistanceVectorHop *dvh)
3015{ 3065{
3016 struct Neighbour *n = dvh->next_hop; 3066 struct Neighbour *n = dvh->next_hop;
3017 struct DistanceVector *dv = dvh->dv; 3067 struct DistanceVector *dv = dvh->dv;
3018 struct PendingAcknowledgement *pa; 3068 struct PendingAcknowledgement *pa;
3019 3069
3020 while (NULL != (pa = dvh->pa_head)) 3070 while (NULL != (pa = dvh->pa_head))
3021 { 3071 {
3022 GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa); 3072 GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa);
3023 pa->dvh = NULL; 3073 pa->dvh = NULL;
3024 } 3074 }
3025 GNUNET_CONTAINER_MDLL_remove(neighbour, n->dv_head, n->dv_tail, dvh); 3075 GNUNET_CONTAINER_MDLL_remove (neighbour, n->dv_head, n->dv_tail, dvh);
3026 GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, dvh); 3076 GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, dvh);
3027 GNUNET_free(dvh); 3077 GNUNET_free (dvh);
3028} 3078}
3029 3079
3030 3080
@@ -3035,7 +3085,7 @@ free_distance_vector_hop(struct DistanceVectorHop *dvh)
3035 * @param cls a `struct VirtualLink` 3085 * @param cls a `struct VirtualLink`
3036 */ 3086 */
3037static void 3087static void
3038check_link_down(void *cls); 3088check_link_down (void *cls);
3039 3089
3040 3090
3041/** 3091/**
@@ -3044,22 +3094,22 @@ check_link_down(void *cls);
3044 * @param pid peer the connection was for 3094 * @param pid peer the connection was for
3045 */ 3095 */
3046static void 3096static void
3047cores_send_disconnect_info(const struct GNUNET_PeerIdentity *pid) 3097cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid)
3048{ 3098{
3049 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3099 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3050 "Informing CORE clients about disconnect from %s\n", 3100 "Informing CORE clients about disconnect from %s\n",
3051 GNUNET_i2s(pid)); 3101 GNUNET_i2s (pid));
3052 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 3102 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3053 { 3103 {
3054 struct GNUNET_MQ_Envelope *env; 3104 struct GNUNET_MQ_Envelope *env;
3055 struct DisconnectInfoMessage *dim; 3105 struct DisconnectInfoMessage *dim;
3056 3106
3057 if (CT_CORE != tc->type) 3107 if (CT_CORE != tc->type)
3058 continue; 3108 continue;
3059 env = GNUNET_MQ_msg(dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 3109 env = GNUNET_MQ_msg (dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
3060 dim->peer = *pid; 3110 dim->peer = *pid;
3061 GNUNET_MQ_send(tc->mq, env); 3111 GNUNET_MQ_send (tc->mq, env);
3062 } 3112 }
3063} 3113}
3064 3114
3065 3115
@@ -3070,43 +3120,43 @@ cores_send_disconnect_info(const struct GNUNET_PeerIdentity *pid)
3070 * @param dv route to free 3120 * @param dv route to free
3071 */ 3121 */
3072static void 3122static void
3073free_dv_route(struct DistanceVector *dv) 3123free_dv_route (struct DistanceVector *dv)
3074{ 3124{
3075 struct DistanceVectorHop *dvh; 3125 struct DistanceVectorHop *dvh;
3076 3126
3077 while (NULL != (dvh = dv->dv_head)) 3127 while (NULL != (dvh = dv->dv_head))
3078 free_distance_vector_hop(dvh); 3128 free_distance_vector_hop (dvh);
3079 if (NULL == dv->dv_head) 3129 if (NULL == dv->dv_head)
3080 { 3130 {
3081 struct VirtualLink *vl; 3131 struct VirtualLink *vl;
3082 3132
3083 GNUNET_assert( 3133 GNUNET_assert (
3084 GNUNET_YES == 3134 GNUNET_YES ==
3085 GNUNET_CONTAINER_multipeermap_remove(dv_routes, &dv->target, dv)); 3135 GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv));
3086 if (NULL != (vl = dv->vl)) 3136 if (NULL != (vl = dv->vl))
3087 { 3137 {
3088 GNUNET_assert(dv == vl->dv); 3138 GNUNET_assert (dv == vl->dv);
3089 vl->dv = NULL; 3139 vl->dv = NULL;
3090 if (NULL == vl->n) 3140 if (NULL == vl->n)
3091 { 3141 {
3092 cores_send_disconnect_info(&dv->target); 3142 cores_send_disconnect_info (&dv->target);
3093 free_virtual_link(vl); 3143 free_virtual_link (vl);
3094 } 3144 }
3095 else 3145 else
3096 { 3146 {
3097 GNUNET_SCHEDULER_cancel(vl->visibility_task); 3147 GNUNET_SCHEDULER_cancel (vl->visibility_task);
3098 vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl); 3148 vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl);
3099 } 3149 }
3100 dv->vl = NULL; 3150 dv->vl = NULL;
3101 } 3151 }
3102 3152
3103 if (NULL != dv->timeout_task) 3153 if (NULL != dv->timeout_task)
3104 { 3154 {
3105 GNUNET_SCHEDULER_cancel(dv->timeout_task); 3155 GNUNET_SCHEDULER_cancel (dv->timeout_task);
3106 dv->timeout_task = NULL; 3156 dv->timeout_task = NULL;
3107 }
3108 GNUNET_free(dv);
3109 } 3157 }
3158 GNUNET_free (dv);
3159 }
3110} 3160}
3111 3161
3112 3162
@@ -3124,30 +3174,30 @@ free_dv_route(struct DistanceVector *dv)
3124 * @param me detailed information to transmit 3174 * @param me detailed information to transmit
3125 */ 3175 */
3126static void 3176static void
3127notify_monitor(struct TransportClient *tc, 3177notify_monitor (struct TransportClient *tc,
3128 const struct GNUNET_PeerIdentity *peer, 3178 const struct GNUNET_PeerIdentity *peer,
3129 const char *address, 3179 const char *address,
3130 enum GNUNET_NetworkType nt, 3180 enum GNUNET_NetworkType nt,
3131 const struct MonitorEvent *me) 3181 const struct MonitorEvent *me)
3132{ 3182{
3133 struct GNUNET_MQ_Envelope *env; 3183 struct GNUNET_MQ_Envelope *env;
3134 struct GNUNET_TRANSPORT_MonitorData *md; 3184 struct GNUNET_TRANSPORT_MonitorData *md;
3135 size_t addr_len = strlen(address) + 1; 3185 size_t addr_len = strlen (address) + 1;
3136 3186
3137 env = GNUNET_MQ_msg_extra(md, 3187 env = GNUNET_MQ_msg_extra (md,
3138 addr_len, 3188 addr_len,
3139 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA); 3189 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA);
3140 md->nt = htonl((uint32_t)nt); 3190 md->nt = htonl ((uint32_t) nt);
3141 md->peer = *peer; 3191 md->peer = *peer;
3142 md->last_validation = GNUNET_TIME_absolute_hton(me->last_validation); 3192 md->last_validation = GNUNET_TIME_absolute_hton (me->last_validation);
3143 md->valid_until = GNUNET_TIME_absolute_hton(me->valid_until); 3193 md->valid_until = GNUNET_TIME_absolute_hton (me->valid_until);
3144 md->next_validation = GNUNET_TIME_absolute_hton(me->next_validation); 3194 md->next_validation = GNUNET_TIME_absolute_hton (me->next_validation);
3145 md->rtt = GNUNET_TIME_relative_hton(me->rtt); 3195 md->rtt = GNUNET_TIME_relative_hton (me->rtt);
3146 md->cs = htonl((uint32_t)me->cs); 3196 md->cs = htonl ((uint32_t) me->cs);
3147 md->num_msg_pending = htonl(me->num_msg_pending); 3197 md->num_msg_pending = htonl (me->num_msg_pending);
3148 md->num_bytes_pending = htonl(me->num_bytes_pending); 3198 md->num_bytes_pending = htonl (me->num_bytes_pending);
3149 memcpy(&md[1], address, addr_len); 3199 memcpy (&md[1], address, addr_len);
3150 GNUNET_MQ_send(tc->mq, env); 3200 GNUNET_MQ_send (tc->mq, env);
3151} 3201}
3152 3202
3153 3203
@@ -3161,22 +3211,22 @@ notify_monitor(struct TransportClient *tc,
3161 * @param me detailed information to transmit 3211 * @param me detailed information to transmit
3162 */ 3212 */
3163static void 3213static void
3164notify_monitors(const struct GNUNET_PeerIdentity *peer, 3214notify_monitors (const struct GNUNET_PeerIdentity *peer,
3165 const char *address, 3215 const char *address,
3166 enum GNUNET_NetworkType nt, 3216 enum GNUNET_NetworkType nt,
3167 const struct MonitorEvent *me) 3217 const struct MonitorEvent *me)
3168{ 3218{
3169 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 3219 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3170 { 3220 {
3171 if (CT_MONITOR != tc->type) 3221 if (CT_MONITOR != tc->type)
3172 continue; 3222 continue;
3173 if (tc->details.monitor.one_shot) 3223 if (tc->details.monitor.one_shot)
3174 continue; 3224 continue;
3175 if ((0 != GNUNET_is_zero(&tc->details.monitor.peer)) && 3225 if ((0 != GNUNET_is_zero (&tc->details.monitor.peer)) &&
3176 (0 != GNUNET_memcmp(&tc->details.monitor.peer, peer))) 3226 (0 != GNUNET_memcmp (&tc->details.monitor.peer, peer)))
3177 continue; 3227 continue;
3178 notify_monitor(tc, peer, address, nt, me); 3228 notify_monitor (tc, peer, address, nt, me);
3179 } 3229 }
3180} 3230}
3181 3231
3182 3232
@@ -3190,18 +3240,18 @@ notify_monitors(const struct GNUNET_PeerIdentity *peer,
3190 * @return our `struct TransportClient` 3240 * @return our `struct TransportClient`
3191 */ 3241 */
3192static void * 3242static void *
3193client_connect_cb(void *cls, 3243client_connect_cb (void *cls,
3194 struct GNUNET_SERVICE_Client *client, 3244 struct GNUNET_SERVICE_Client *client,
3195 struct GNUNET_MQ_Handle *mq) 3245 struct GNUNET_MQ_Handle *mq)
3196{ 3246{
3197 struct TransportClient *tc; 3247 struct TransportClient *tc;
3198 3248
3199 (void)cls; 3249 (void) cls;
3200 tc = GNUNET_new(struct TransportClient); 3250 tc = GNUNET_new (struct TransportClient);
3201 tc->client = client; 3251 tc->client = client;
3202 tc->mq = mq; 3252 tc->mq = mq;
3203 GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc); 3253 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
3204 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); 3254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
3205 return tc; 3255 return tc;
3206} 3256}
3207 3257
@@ -3212,16 +3262,16 @@ client_connect_cb(void *cls,
3212 * @param rc data structure to free 3262 * @param rc data structure to free
3213 */ 3263 */
3214static void 3264static void
3215free_reassembly_context(struct ReassemblyContext *rc) 3265free_reassembly_context (struct ReassemblyContext *rc)
3216{ 3266{
3217 struct Neighbour *n = rc->neighbour; 3267 struct Neighbour *n = rc->neighbour;
3218 3268
3219 GNUNET_assert(rc == GNUNET_CONTAINER_heap_remove_node(rc->hn)); 3269 GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn));
3220 GNUNET_assert(GNUNET_OK == 3270 GNUNET_assert (GNUNET_OK ==
3221 GNUNET_CONTAINER_multihashmap32_remove(n->reassembly_map, 3271 GNUNET_CONTAINER_multihashmap32_remove (n->reassembly_map,
3222 rc->msg_uuid.uuid, 3272 rc->msg_uuid.uuid,
3223 rc)); 3273 rc));
3224 GNUNET_free(rc); 3274 GNUNET_free (rc);
3225} 3275}
3226 3276
3227 3277
@@ -3231,27 +3281,27 @@ free_reassembly_context(struct ReassemblyContext *rc)
3231 * @param cls a `struct Neighbour` 3281 * @param cls a `struct Neighbour`
3232 */ 3282 */
3233static void 3283static void
3234reassembly_cleanup_task(void *cls) 3284reassembly_cleanup_task (void *cls)
3235{ 3285{
3236 struct Neighbour *n = cls; 3286 struct Neighbour *n = cls;
3237 struct ReassemblyContext *rc; 3287 struct ReassemblyContext *rc;
3238 3288
3239 n->reassembly_timeout_task = NULL; 3289 n->reassembly_timeout_task = NULL;
3240 while (NULL != (rc = GNUNET_CONTAINER_heap_peek(n->reassembly_heap))) 3290 while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap)))
3291 {
3292 if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)
3293 .rel_value_us)
3241 { 3294 {
3242 if (0 == GNUNET_TIME_absolute_get_remaining(rc->reassembly_timeout) 3295 free_reassembly_context (rc);
3243 .rel_value_us) 3296 continue;
3244 {
3245 free_reassembly_context(rc);
3246 continue;
3247 }
3248 GNUNET_assert(NULL == n->reassembly_timeout_task);
3249 n->reassembly_timeout_task =
3250 GNUNET_SCHEDULER_add_at(rc->reassembly_timeout,
3251 &reassembly_cleanup_task,
3252 n);
3253 return;
3254 } 3297 }
3298 GNUNET_assert (NULL == n->reassembly_timeout_task);
3299 n->reassembly_timeout_task =
3300 GNUNET_SCHEDULER_add_at (rc->reassembly_timeout,
3301 &reassembly_cleanup_task,
3302 n);
3303 return;
3304 }
3255} 3305}
3256 3306
3257 3307
@@ -3264,13 +3314,13 @@ reassembly_cleanup_task(void *cls)
3264 * @return #GNUNET_OK (continue iteration) 3314 * @return #GNUNET_OK (continue iteration)
3265 */ 3315 */
3266static int 3316static int
3267free_reassembly_cb(void *cls, uint32_t key, void *value) 3317free_reassembly_cb (void *cls, uint32_t key, void *value)
3268{ 3318{
3269 struct ReassemblyContext *rc = value; 3319 struct ReassemblyContext *rc = value;
3270 3320
3271 (void)cls; 3321 (void) cls;
3272 (void)key; 3322 (void) key;
3273 free_reassembly_context(rc); 3323 free_reassembly_context (rc);
3274 return GNUNET_OK; 3324 return GNUNET_OK;
3275} 3325}
3276 3326
@@ -3281,66 +3331,66 @@ free_reassembly_cb(void *cls, uint32_t key, void *value)
3281 * @param neighbour neighbour entry to free 3331 * @param neighbour neighbour entry to free
3282 */ 3332 */
3283static void 3333static void
3284free_neighbour(struct Neighbour *neighbour) 3334free_neighbour (struct Neighbour *neighbour)
3285{ 3335{
3286 struct DistanceVectorHop *dvh; 3336 struct DistanceVectorHop *dvh;
3287 struct VirtualLink *vl; 3337 struct VirtualLink *vl;
3288 3338
3289 GNUNET_assert(NULL == neighbour->queue_head); 3339 GNUNET_assert (NULL == neighbour->queue_head);
3290 GNUNET_assert(GNUNET_YES == 3340 GNUNET_assert (GNUNET_YES ==
3291 GNUNET_CONTAINER_multipeermap_remove(neighbours, 3341 GNUNET_CONTAINER_multipeermap_remove (neighbours,
3292 &neighbour->pid, 3342 &neighbour->pid,
3293 neighbour)); 3343 neighbour));
3294 if (NULL != neighbour->reassembly_map) 3344 if (NULL != neighbour->reassembly_map)
3295 { 3345 {
3296 GNUNET_CONTAINER_multihashmap32_iterate(neighbour->reassembly_map, 3346 GNUNET_CONTAINER_multihashmap32_iterate (neighbour->reassembly_map,
3297 &free_reassembly_cb, 3347 &free_reassembly_cb,
3298 NULL); 3348 NULL);
3299 GNUNET_CONTAINER_multihashmap32_destroy(neighbour->reassembly_map); 3349 GNUNET_CONTAINER_multihashmap32_destroy (neighbour->reassembly_map);
3300 neighbour->reassembly_map = NULL; 3350 neighbour->reassembly_map = NULL;
3301 GNUNET_CONTAINER_heap_destroy(neighbour->reassembly_heap); 3351 GNUNET_CONTAINER_heap_destroy (neighbour->reassembly_heap);
3302 neighbour->reassembly_heap = NULL; 3352 neighbour->reassembly_heap = NULL;
3303 } 3353 }
3304 while (NULL != (dvh = neighbour->dv_head)) 3354 while (NULL != (dvh = neighbour->dv_head))
3305 { 3355 {
3306 struct DistanceVector *dv = dvh->dv; 3356 struct DistanceVector *dv = dvh->dv;
3307 3357
3308 free_distance_vector_hop(dvh); 3358 free_distance_vector_hop (dvh);
3309 if (NULL == dv->dv_head) 3359 if (NULL == dv->dv_head)
3310 free_dv_route(dv); 3360 free_dv_route (dv);
3311 } 3361 }
3312 if (NULL != neighbour->reassembly_timeout_task) 3362 if (NULL != neighbour->reassembly_timeout_task)
3313 { 3363 {
3314 GNUNET_SCHEDULER_cancel(neighbour->reassembly_timeout_task); 3364 GNUNET_SCHEDULER_cancel (neighbour->reassembly_timeout_task);
3315 neighbour->reassembly_timeout_task = NULL; 3365 neighbour->reassembly_timeout_task = NULL;
3316 } 3366 }
3317 if (NULL != neighbour->get) 3367 if (NULL != neighbour->get)
3318 { 3368 {
3319 GNUNET_PEERSTORE_iterate_cancel(neighbour->get); 3369 GNUNET_PEERSTORE_iterate_cancel (neighbour->get);
3320 neighbour->get = NULL; 3370 neighbour->get = NULL;
3321 } 3371 }
3322 if (NULL != neighbour->sc) 3372 if (NULL != neighbour->sc)
3373 {
3374 GNUNET_PEERSTORE_store_cancel (neighbour->sc);
3375 neighbour->sc = NULL;
3376 }
3377 if (NULL != (vl = neighbour->vl))
3378 {
3379 GNUNET_assert (neighbour == vl->n);
3380 vl->n = NULL;
3381 if (NULL == vl->dv)
3323 { 3382 {
3324 GNUNET_PEERSTORE_store_cancel(neighbour->sc); 3383 cores_send_disconnect_info (&vl->target);
3325 neighbour->sc = NULL; 3384 free_virtual_link (vl);
3326 } 3385 }
3327 if (NULL != (vl = neighbour->vl)) 3386 else
3328 { 3387 {
3329 GNUNET_assert(neighbour == vl->n); 3388 GNUNET_SCHEDULER_cancel (vl->visibility_task);
3330 vl->n = NULL; 3389 vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl);
3331 if (NULL == vl->dv)
3332 {
3333 cores_send_disconnect_info(&vl->target);
3334 free_virtual_link(vl);
3335 }
3336 else
3337 {
3338 GNUNET_SCHEDULER_cancel(vl->visibility_task);
3339 vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl);
3340 }
3341 neighbour->vl = NULL;
3342 } 3390 }
3343 GNUNET_free(neighbour); 3391 neighbour->vl = NULL;
3392 }
3393 GNUNET_free (neighbour);
3344} 3394}
3345 3395
3346 3396
@@ -3351,16 +3401,16 @@ free_neighbour(struct Neighbour *neighbour)
3351 * @param pid peer the connection is for 3401 * @param pid peer the connection is for
3352 */ 3402 */
3353static void 3403static void
3354core_send_connect_info(struct TransportClient *tc, 3404core_send_connect_info (struct TransportClient *tc,
3355 const struct GNUNET_PeerIdentity *pid) 3405 const struct GNUNET_PeerIdentity *pid)
3356{ 3406{
3357 struct GNUNET_MQ_Envelope *env; 3407 struct GNUNET_MQ_Envelope *env;
3358 struct ConnectInfoMessage *cim; 3408 struct ConnectInfoMessage *cim;
3359 3409
3360 GNUNET_assert(CT_CORE == tc->type); 3410 GNUNET_assert (CT_CORE == tc->type);
3361 env = GNUNET_MQ_msg(cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 3411 env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
3362 cim->id = *pid; 3412 cim->id = *pid;
3363 GNUNET_MQ_send(tc->mq, env); 3413 GNUNET_MQ_send (tc->mq, env);
3364} 3414}
3365 3415
3366 3416
@@ -3370,17 +3420,17 @@ core_send_connect_info(struct TransportClient *tc,
3370 * @param pid peer the queue was for 3420 * @param pid peer the queue was for
3371 */ 3421 */
3372static void 3422static void
3373cores_send_connect_info(const struct GNUNET_PeerIdentity *pid) 3423cores_send_connect_info (const struct GNUNET_PeerIdentity *pid)
3374{ 3424{
3375 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3376 "Informing CORE clients about connection to %s\n", 3426 "Informing CORE clients about connection to %s\n",
3377 GNUNET_i2s(pid)); 3427 GNUNET_i2s (pid));
3378 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 3428 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3379 { 3429 {
3380 if (CT_CORE != tc->type) 3430 if (CT_CORE != tc->type)
3381 continue; 3431 continue;
3382 core_send_connect_info(tc, pid); 3432 core_send_connect_info (tc, pid);
3383 } 3433 }
3384} 3434}
3385 3435
3386 3436
@@ -3392,7 +3442,7 @@ cores_send_connect_info(const struct GNUNET_PeerIdentity *pid)
3392 * @param cls the `struct Queue` to process transmissions for 3442 * @param cls the `struct Queue` to process transmissions for
3393 */ 3443 */
3394static void 3444static void
3395transmit_on_queue(void *cls); 3445transmit_on_queue (void *cls);
3396 3446
3397 3447
3398/** 3448/**
@@ -3403,38 +3453,38 @@ transmit_on_queue(void *cls);
3403 * @param p task priority to use, if @a queue is scheduled 3453 * @param p task priority to use, if @a queue is scheduled
3404 */ 3454 */
3405static void 3455static void
3406schedule_transmit_on_queue(struct Queue *queue, 3456schedule_transmit_on_queue (struct Queue *queue,
3407 enum GNUNET_SCHEDULER_Priority p) 3457 enum GNUNET_SCHEDULER_Priority p)
3408{ 3458{
3409 if (queue->tc->details.communicator.total_queue_length >= 3459 if (queue->tc->details.communicator.total_queue_length >=
3410 COMMUNICATOR_TOTAL_QUEUE_LIMIT) 3460 COMMUNICATOR_TOTAL_QUEUE_LIMIT)
3411 { 3461 {
3412 GNUNET_STATISTICS_update( 3462 GNUNET_STATISTICS_update (
3413 GST_stats, 3463 GST_stats,
3414 "# Transmission throttled due to communicator queue limit", 3464 "# Transmission throttled due to communicator queue limit",
3415 1, 3465 1,
3416 GNUNET_NO); 3466 GNUNET_NO);
3417 queue->idle = GNUNET_NO; 3467 queue->idle = GNUNET_NO;
3418 return; 3468 return;
3419 } 3469 }
3420 if (queue->queue_length >= QUEUE_LENGTH_LIMIT) 3470 if (queue->queue_length >= QUEUE_LENGTH_LIMIT)
3421 { 3471 {
3422 GNUNET_STATISTICS_update(GST_stats, 3472 GNUNET_STATISTICS_update (GST_stats,
3423 "# Transmission throttled due to queue queue limit", 3473 "# Transmission throttled due to queue queue limit",
3424 1, 3474 1,
3425 GNUNET_NO); 3475 GNUNET_NO);
3426 queue->idle = GNUNET_NO; 3476 queue->idle = GNUNET_NO;
3427 return; 3477 return;
3428 } 3478 }
3429 /* queue might indeed be ready, schedule it */ 3479 /* queue might indeed be ready, schedule it */
3430 if (NULL != queue->transmit_task) 3480 if (NULL != queue->transmit_task)
3431 GNUNET_SCHEDULER_cancel(queue->transmit_task); 3481 GNUNET_SCHEDULER_cancel (queue->transmit_task);
3432 queue->transmit_task = 3482 queue->transmit_task =
3433 GNUNET_SCHEDULER_add_with_priority(p, &transmit_on_queue, queue); 3483 GNUNET_SCHEDULER_add_with_priority (p, &transmit_on_queue, queue);
3434 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3435 "Considering transmission on queue `%s' to %s\n", 3485 "Considering transmission on queue `%s' to %s\n",
3436 queue->address, 3486 queue->address,
3437 GNUNET_i2s(&queue->neighbour->pid)); 3487 GNUNET_i2s (&queue->neighbour->pid));
3438} 3488}
3439 3489
3440 3490
@@ -3445,7 +3495,7 @@ schedule_transmit_on_queue(struct Queue *queue,
3445 * @param cls a `struct VirtualLink` 3495 * @param cls a `struct VirtualLink`
3446 */ 3496 */
3447static void 3497static void
3448check_link_down(void *cls) 3498check_link_down (void *cls)
3449{ 3499{
3450 struct VirtualLink *vl = cls; 3500 struct VirtualLink *vl = cls;
3451 struct DistanceVector *dv = vl->dv; 3501 struct DistanceVector *dv = vl->dv;
@@ -3457,30 +3507,30 @@ check_link_down(void *cls)
3457 dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS; 3507 dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS;
3458 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3508 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3459 pos = pos->next_dv) 3509 pos = pos->next_dv)
3460 dvh_timeout = GNUNET_TIME_absolute_max(dvh_timeout, pos->path_valid_until); 3510 dvh_timeout = GNUNET_TIME_absolute_max (dvh_timeout, pos->path_valid_until);
3461 if (0 == GNUNET_TIME_absolute_get_remaining(dvh_timeout).rel_value_us) 3511 if (0 == GNUNET_TIME_absolute_get_remaining (dvh_timeout).rel_value_us)
3462 { 3512 {
3463 vl->dv->vl = NULL; 3513 vl->dv->vl = NULL;
3464 vl->dv = NULL; 3514 vl->dv = NULL;
3465 } 3515 }
3466 q_timeout = GNUNET_TIME_UNIT_ZERO_ABS; 3516 q_timeout = GNUNET_TIME_UNIT_ZERO_ABS;
3467 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) 3517 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
3468 q_timeout = GNUNET_TIME_absolute_max(q_timeout, q->validated_until); 3518 q_timeout = GNUNET_TIME_absolute_max (q_timeout, q->validated_until);
3469 if (0 == GNUNET_TIME_absolute_get_remaining(q_timeout).rel_value_us) 3519 if (0 == GNUNET_TIME_absolute_get_remaining (q_timeout).rel_value_us)
3470 { 3520 {
3471 vl->n->vl = NULL; 3521 vl->n->vl = NULL;
3472 vl->n = NULL; 3522 vl->n = NULL;
3473 } 3523 }
3474 if ((NULL == vl->n) && (NULL == vl->dv)) 3524 if ((NULL == vl->n) && (NULL == vl->dv))
3475 { 3525 {
3476 cores_send_disconnect_info(&vl->target); 3526 cores_send_disconnect_info (&vl->target);
3477 free_virtual_link(vl); 3527 free_virtual_link (vl);
3478 return; 3528 return;
3479 } 3529 }
3480 vl->visibility_task = 3530 vl->visibility_task =
3481 GNUNET_SCHEDULER_add_at(GNUNET_TIME_absolute_max(q_timeout, dvh_timeout), 3531 GNUNET_SCHEDULER_add_at (GNUNET_TIME_absolute_max (q_timeout, dvh_timeout),
3482 &check_link_down, 3532 &check_link_down,
3483 vl); 3533 vl);
3484} 3534}
3485 3535
3486 3536
@@ -3490,7 +3540,7 @@ check_link_down(void *cls)
3490 * @param queue the queue to free 3540 * @param queue the queue to free
3491 */ 3541 */
3492static void 3542static void
3493free_queue(struct Queue *queue) 3543free_queue (struct Queue *queue)
3494{ 3544{
3495 struct Neighbour *neighbour = queue->neighbour; 3545 struct Neighbour *neighbour = queue->neighbour;
3496 struct TransportClient *tc = queue->tc; 3546 struct TransportClient *tc = queue->tc;
@@ -3502,65 +3552,65 @@ free_queue(struct Queue *queue)
3502 struct VirtualLink *vl; 3552 struct VirtualLink *vl;
3503 3553
3504 if (NULL != queue->transmit_task) 3554 if (NULL != queue->transmit_task)
3505 { 3555 {
3506 GNUNET_SCHEDULER_cancel(queue->transmit_task); 3556 GNUNET_SCHEDULER_cancel (queue->transmit_task);
3507 queue->transmit_task = NULL; 3557 queue->transmit_task = NULL;
3508 } 3558 }
3509 while (NULL != (pa = queue->pa_head)) 3559 while (NULL != (pa = queue->pa_head))
3510 { 3560 {
3511 GNUNET_CONTAINER_MDLL_remove(queue, queue->pa_head, queue->pa_tail, pa); 3561 GNUNET_CONTAINER_MDLL_remove (queue, queue->pa_head, queue->pa_tail, pa);
3512 pa->queue = NULL; 3562 pa->queue = NULL;
3513 } 3563 }
3514 3564
3515 GNUNET_CONTAINER_MDLL_remove(neighbour, 3565 GNUNET_CONTAINER_MDLL_remove (neighbour,
3516 neighbour->queue_head, 3566 neighbour->queue_head,
3517 neighbour->queue_tail, 3567 neighbour->queue_tail,
3518 queue); 3568 queue);
3519 GNUNET_CONTAINER_MDLL_remove(client, 3569 GNUNET_CONTAINER_MDLL_remove (client,
3520 tc->details.communicator.queue_head, 3570 tc->details.communicator.queue_head,
3521 tc->details.communicator.queue_tail, 3571 tc->details.communicator.queue_tail,
3522 queue); 3572 queue);
3523 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >= 3573 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >=
3524 tc->details.communicator.total_queue_length); 3574 tc->details.communicator.total_queue_length);
3525 while (NULL != (qe = queue->queue_head)) 3575 while (NULL != (qe = queue->queue_head))
3576 {
3577 GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe);
3578 queue->queue_length--;
3579 tc->details.communicator.total_queue_length--;
3580 if (NULL != qe->pm)
3526 { 3581 {
3527 GNUNET_CONTAINER_DLL_remove(queue->queue_head, queue->queue_tail, qe); 3582 GNUNET_assert (qe == qe->pm->qe);
3528 queue->queue_length--; 3583 qe->pm->qe = NULL;
3529 tc->details.communicator.total_queue_length--;
3530 if (NULL != qe->pm)
3531 {
3532 GNUNET_assert(qe == qe->pm->qe);
3533 qe->pm->qe = NULL;
3534 }
3535 GNUNET_free(qe);
3536 } 3584 }
3537 GNUNET_assert(0 == queue->queue_length); 3585 GNUNET_free (qe);
3586 }
3587 GNUNET_assert (0 == queue->queue_length);
3538 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT < 3588 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT <
3539 tc->details.communicator.total_queue_length)) 3589 tc->details.communicator.total_queue_length))
3540 { 3590 {
3541 /* Communicator dropped below threshold, resume all _other_ queues */ 3591 /* Communicator dropped below threshold, resume all _other_ queues */
3542 GNUNET_STATISTICS_update( 3592 GNUNET_STATISTICS_update (
3543 GST_stats, 3593 GST_stats,
3544 "# Transmission throttled due to communicator queue limit", 3594 "# Transmission throttled due to communicator queue limit",
3545 -1, 3595 -1,
3546 GNUNET_NO); 3596 GNUNET_NO);
3547 for (struct Queue *s = tc->details.communicator.queue_head; NULL != s; 3597 for (struct Queue *s = tc->details.communicator.queue_head; NULL != s;
3548 s = s->next_client) 3598 s = s->next_client)
3549 schedule_transmit_on_queue(s, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 3599 schedule_transmit_on_queue (s, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
3550 } 3600 }
3551 notify_monitors(&neighbour->pid, queue->address, queue->nt, &me); 3601 notify_monitors (&neighbour->pid, queue->address, queue->nt, &me);
3552 GNUNET_free(queue); 3602 GNUNET_free (queue);
3553 3603
3554 vl = lookup_virtual_link(&neighbour->pid); 3604 vl = lookup_virtual_link (&neighbour->pid);
3555 if ((NULL != vl) && (neighbour == vl->n)) 3605 if ((NULL != vl) && (neighbour == vl->n))
3556 { 3606 {
3557 GNUNET_SCHEDULER_cancel(vl->visibility_task); 3607 GNUNET_SCHEDULER_cancel (vl->visibility_task);
3558 check_link_down(vl); 3608 check_link_down (vl);
3559 } 3609 }
3560 if (NULL == neighbour->queue_head) 3610 if (NULL == neighbour->queue_head)
3561 { 3611 {
3562 free_neighbour(neighbour); 3612 free_neighbour (neighbour);
3563 } 3613 }
3564} 3614}
3565 3615
3566 3616
@@ -3570,24 +3620,24 @@ free_queue(struct Queue *queue)
3570 * @param ale address list entry to free 3620 * @param ale address list entry to free
3571 */ 3621 */
3572static void 3622static void
3573free_address_list_entry(struct AddressListEntry *ale) 3623free_address_list_entry (struct AddressListEntry *ale)
3574{ 3624{
3575 struct TransportClient *tc = ale->tc; 3625 struct TransportClient *tc = ale->tc;
3576 3626
3577 GNUNET_CONTAINER_DLL_remove(tc->details.communicator.addr_head, 3627 GNUNET_CONTAINER_DLL_remove (tc->details.communicator.addr_head,
3578 tc->details.communicator.addr_tail, 3628 tc->details.communicator.addr_tail,
3579 ale); 3629 ale);
3580 if (NULL != ale->sc) 3630 if (NULL != ale->sc)
3581 { 3631 {
3582 GNUNET_PEERSTORE_store_cancel(ale->sc); 3632 GNUNET_PEERSTORE_store_cancel (ale->sc);
3583 ale->sc = NULL; 3633 ale->sc = NULL;
3584 } 3634 }
3585 if (NULL != ale->st) 3635 if (NULL != ale->st)
3586 { 3636 {
3587 GNUNET_SCHEDULER_cancel(ale->st); 3637 GNUNET_SCHEDULER_cancel (ale->st);
3588 ale->st = NULL; 3638 ale->st = NULL;
3589 } 3639 }
3590 GNUNET_free(ale); 3640 GNUNET_free (ale);
3591} 3641}
3592 3642
3593 3643
@@ -3600,20 +3650,20 @@ free_address_list_entry(struct AddressListEntry *ale)
3600 * @return #GNUNET_YES (always) 3650 * @return #GNUNET_YES (always)
3601 */ 3651 */
3602static int 3652static int
3603stop_peer_request(void *cls, 3653stop_peer_request (void *cls,
3604 const struct GNUNET_PeerIdentity *pid, 3654 const struct GNUNET_PeerIdentity *pid,
3605 void *value) 3655 void *value)
3606{ 3656{
3607 struct TransportClient *tc = cls; 3657 struct TransportClient *tc = cls;
3608 struct PeerRequest *pr = value; 3658 struct PeerRequest *pr = value;
3609 3659
3610 GNUNET_PEERSTORE_watch_cancel(pr->wc); 3660 GNUNET_PEERSTORE_watch_cancel (pr->wc);
3611 GNUNET_assert( 3661 GNUNET_assert (
3612 GNUNET_YES == 3662 GNUNET_YES ==
3613 GNUNET_CONTAINER_multipeermap_remove(tc->details.application.requests, 3663 GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests,
3614 pid, 3664 pid,
3615 pr)); 3665 pr));
3616 GNUNET_free(pr); 3666 GNUNET_free (pr);
3617 3667
3618 return GNUNET_OK; 3668 return GNUNET_OK;
3619} 3669}
@@ -3628,60 +3678,60 @@ stop_peer_request(void *cls,
3628 * @param app_ctx our `struct TransportClient` 3678 * @param app_ctx our `struct TransportClient`
3629 */ 3679 */
3630static void 3680static void
3631client_disconnect_cb(void *cls, 3681client_disconnect_cb (void *cls,
3632 struct GNUNET_SERVICE_Client *client, 3682 struct GNUNET_SERVICE_Client *client,
3633 void *app_ctx) 3683 void *app_ctx)
3634{ 3684{
3635 struct TransportClient *tc = app_ctx; 3685 struct TransportClient *tc = app_ctx;
3636 3686
3637 (void)cls; 3687 (void) cls;
3638 (void)client; 3688 (void) client;
3639 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3640 "Client %p disconnected, cleaning up.\n", 3690 "Client %p disconnected, cleaning up.\n",
3641 tc); 3691 tc);
3642 GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc); 3692 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
3643 switch (tc->type) 3693 switch (tc->type)
3644 { 3694 {
3645 case CT_NONE: 3695 case CT_NONE:
3646 break; 3696 break;
3647 3697
3648 case CT_CORE: { 3698 case CT_CORE: {
3649 struct PendingMessage *pm; 3699 struct PendingMessage *pm;
3650 3700
3651 while (NULL != (pm = tc->details.core.pending_msg_head)) 3701 while (NULL != (pm = tc->details.core.pending_msg_head))
3652 { 3702 {
3653 GNUNET_CONTAINER_MDLL_remove(client, 3703 GNUNET_CONTAINER_MDLL_remove (client,
3654 tc->details.core.pending_msg_head, 3704 tc->details.core.pending_msg_head,
3655 tc->details.core.pending_msg_tail, 3705 tc->details.core.pending_msg_tail,
3656 pm); 3706 pm);
3657 pm->client = NULL; 3707 pm->client = NULL;
3658 } 3708 }
3659 } 3709 }
3660 break; 3710 break;
3661 3711
3662 case CT_MONITOR: 3712 case CT_MONITOR:
3663 break; 3713 break;
3664 3714
3665 case CT_COMMUNICATOR: { 3715 case CT_COMMUNICATOR: {
3666 struct Queue *q; 3716 struct Queue *q;
3667 struct AddressListEntry *ale; 3717 struct AddressListEntry *ale;
3668 3718
3669 while (NULL != (q = tc->details.communicator.queue_head)) 3719 while (NULL != (q = tc->details.communicator.queue_head))
3670 free_queue(q); 3720 free_queue (q);
3671 while (NULL != (ale = tc->details.communicator.addr_head)) 3721 while (NULL != (ale = tc->details.communicator.addr_head))
3672 free_address_list_entry(ale); 3722 free_address_list_entry (ale);
3673 GNUNET_free(tc->details.communicator.address_prefix); 3723 GNUNET_free (tc->details.communicator.address_prefix);
3674 } 3724 }
3675 break; 3725 break;
3676 3726
3677 case CT_APPLICATION: 3727 case CT_APPLICATION:
3678 GNUNET_CONTAINER_multipeermap_iterate(tc->details.application.requests, 3728 GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests,
3679 &stop_peer_request, 3729 &stop_peer_request,
3680 tc); 3730 tc);
3681 GNUNET_CONTAINER_multipeermap_destroy(tc->details.application.requests); 3731 GNUNET_CONTAINER_multipeermap_destroy (tc->details.application.requests);
3682 break; 3732 break;
3683 } 3733 }
3684 GNUNET_free(tc); 3734 GNUNET_free (tc);
3685} 3735}
3686 3736
3687 3737
@@ -3695,17 +3745,17 @@ client_disconnect_cb(void *cls,
3695 * @return #GNUNET_OK (continue to iterate) 3745 * @return #GNUNET_OK (continue to iterate)
3696 */ 3746 */
3697static int 3747static int
3698notify_client_connect_info(void *cls, 3748notify_client_connect_info (void *cls,
3699 const struct GNUNET_PeerIdentity *pid, 3749 const struct GNUNET_PeerIdentity *pid,
3700 void *value) 3750 void *value)
3701{ 3751{
3702 struct TransportClient *tc = cls; 3752 struct TransportClient *tc = cls;
3703 3753
3704 (void)value; 3754 (void) value;
3705 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3706 "Telling new CORE client about existing connection to %s\n", 3756 "Telling new CORE client about existing connection to %s\n",
3707 GNUNET_i2s(pid)); 3757 GNUNET_i2s (pid));
3708 core_send_connect_info(tc, pid); 3758 core_send_connect_info (tc, pid);
3709 return GNUNET_OK; 3759 return GNUNET_OK;
3710} 3760}
3711 3761
@@ -3719,34 +3769,34 @@ notify_client_connect_info(void *cls,
3719 * @param start the start message that was sent 3769 * @param start the start message that was sent
3720 */ 3770 */
3721static void 3771static void
3722handle_client_start(void *cls, const struct StartMessage *start) 3772handle_client_start (void *cls, const struct StartMessage *start)
3723{ 3773{
3724 struct TransportClient *tc = cls; 3774 struct TransportClient *tc = cls;
3725 uint32_t options; 3775 uint32_t options;
3726 3776
3727 options = ntohl(start->options); 3777 options = ntohl (start->options);
3728 if ((0 != (1 & options)) && 3778 if ((0 != (1 & options)) &&
3729 (0 != GNUNET_memcmp(&start->self, &GST_my_identity))) 3779 (0 != GNUNET_memcmp (&start->self, &GST_my_identity)))
3730 { 3780 {
3731 /* client thinks this is a different peer, reject */ 3781 /* client thinks this is a different peer, reject */
3732 GNUNET_break(0); 3782 GNUNET_break (0);
3733 GNUNET_SERVICE_client_drop(tc->client); 3783 GNUNET_SERVICE_client_drop (tc->client);
3734 return; 3784 return;
3735 } 3785 }
3736 if (CT_NONE != tc->type) 3786 if (CT_NONE != tc->type)
3737 { 3787 {
3738 GNUNET_break(0); 3788 GNUNET_break (0);
3739 GNUNET_SERVICE_client_drop(tc->client); 3789 GNUNET_SERVICE_client_drop (tc->client);
3740 return; 3790 return;
3741 } 3791 }
3742 tc->type = CT_CORE; 3792 tc->type = CT_CORE;
3743 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3793 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3744 "New CORE client with PID %s registered\n", 3794 "New CORE client with PID %s registered\n",
3745 GNUNET_i2s(&start->self)); 3795 GNUNET_i2s (&start->self));
3746 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 3796 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
3747 &notify_client_connect_info, 3797 &notify_client_connect_info,
3748 tc); 3798 tc);
3749 GNUNET_SERVICE_client_continue(tc->client); 3799 GNUNET_SERVICE_client_continue (tc->client);
3750} 3800}
3751 3801
3752 3802
@@ -3757,29 +3807,29 @@ handle_client_start(void *cls, const struct StartMessage *start)
3757 * @param obm the send message that was sent 3807 * @param obm the send message that was sent
3758 */ 3808 */
3759static int 3809static int
3760check_client_send(void *cls, const struct OutboundMessage *obm) 3810check_client_send (void *cls, const struct OutboundMessage *obm)
3761{ 3811{
3762 struct TransportClient *tc = cls; 3812 struct TransportClient *tc = cls;
3763 uint16_t size; 3813 uint16_t size;
3764 const struct GNUNET_MessageHeader *obmm; 3814 const struct GNUNET_MessageHeader *obmm;
3765 3815
3766 if (CT_CORE != tc->type) 3816 if (CT_CORE != tc->type)
3767 { 3817 {
3768 GNUNET_break(0); 3818 GNUNET_break (0);
3769 return GNUNET_SYSERR; 3819 return GNUNET_SYSERR;
3770 } 3820 }
3771 size = ntohs(obm->header.size) - sizeof(struct OutboundMessage); 3821 size = ntohs (obm->header.size) - sizeof(struct OutboundMessage);
3772 if (size < sizeof(struct GNUNET_MessageHeader)) 3822 if (size < sizeof(struct GNUNET_MessageHeader))
3773 { 3823 {
3774 GNUNET_break(0); 3824 GNUNET_break (0);
3775 return GNUNET_SYSERR; 3825 return GNUNET_SYSERR;
3776 } 3826 }
3777 obmm = (const struct GNUNET_MessageHeader *)&obm[1]; 3827 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
3778 if (size != ntohs(obmm->size)) 3828 if (size != ntohs (obmm->size))
3779 { 3829 {
3780 GNUNET_break(0); 3830 GNUNET_break (0);
3781 return GNUNET_SYSERR; 3831 return GNUNET_SYSERR;
3782 } 3832 }
3783 return GNUNET_OK; 3833 return GNUNET_OK;
3784} 3834}
3785 3835
@@ -3792,25 +3842,25 @@ check_client_send(void *cls, const struct OutboundMessage *obm)
3792 * @param pm handle to the original pending message 3842 * @param pm handle to the original pending message
3793 */ 3843 */
3794static void 3844static void
3795client_send_response(struct PendingMessage *pm) 3845client_send_response (struct PendingMessage *pm)
3796{ 3846{
3797 struct TransportClient *tc = pm->client; 3847 struct TransportClient *tc = pm->client;
3798 struct VirtualLink *vl = pm->vl; 3848 struct VirtualLink *vl = pm->vl;
3799 3849
3800 if (NULL != tc) 3850 if (NULL != tc)
3801 { 3851 {
3802 struct GNUNET_MQ_Envelope *env; 3852 struct GNUNET_MQ_Envelope *env;
3803 struct SendOkMessage *som; 3853 struct SendOkMessage *som;
3804 3854
3805 env = GNUNET_MQ_msg(som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); 3855 env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
3806 som->peer = vl->target; 3856 som->peer = vl->target;
3807 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3808 "Confirming transmission of <%llu> to %s\n", 3858 "Confirming transmission of <%llu> to %s\n",
3809 pm->logging_uuid, 3859 pm->logging_uuid,
3810 GNUNET_i2s(&vl->target)); 3860 GNUNET_i2s (&vl->target));
3811 GNUNET_MQ_send(tc->mq, env); 3861 GNUNET_MQ_send (tc->mq, env);
3812 } 3862 }
3813 free_pending_message(pm); 3863 free_pending_message (pm);
3814} 3864}
3815 3865
3816 3866
@@ -3824,10 +3874,10 @@ client_send_response(struct PendingMessage *pm)
3824 * @return number of entries set in @a hops_array 3874 * @return number of entries set in @a hops_array
3825 */ 3875 */
3826static unsigned int 3876static unsigned int
3827pick_random_dv_hops(const struct DistanceVector *dv, 3877pick_random_dv_hops (const struct DistanceVector *dv,
3828 enum RouteMessageOptions options, 3878 enum RouteMessageOptions options,
3829 struct DistanceVectorHop **hops_array, 3879 struct DistanceVectorHop **hops_array,
3830 unsigned int hops_array_length) 3880 unsigned int hops_array_length)
3831{ 3881{
3832 uint64_t choices[hops_array_length]; 3882 uint64_t choices[hops_array_length];
3833 uint64_t num_dv; 3883 uint64_t num_dv;
@@ -3839,56 +3889,56 @@ pick_random_dv_hops(const struct DistanceVector *dv,
3839 dv_count = 0; 3889 dv_count = 0;
3840 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3890 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3841 pos = pos->next_dv) 3891 pos = pos->next_dv)
3842 { 3892 {
3843 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && 3893 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
3844 (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until) 3894 (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until)
3845 .rel_value_us == 0)) 3895 .rel_value_us == 0))
3846 continue; /* pos unconfirmed and confirmed required */ 3896 continue; /* pos unconfirmed and confirmed required */
3847 num_dv += MAX_DV_HOPS_ALLOWED - pos->distance; 3897 num_dv += MAX_DV_HOPS_ALLOWED - pos->distance;
3848 dv_count++; 3898 dv_count++;
3849 } 3899 }
3850 if (0 == dv_count) 3900 if (0 == dv_count)
3851 return 0; 3901 return 0;
3852 if (dv_count <= hops_array_length) 3902 if (dv_count <= hops_array_length)
3853 { 3903 {
3854 dv_count = 0; 3904 dv_count = 0;
3855 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3905 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3856 pos = pos->next_dv) 3906 pos = pos->next_dv)
3857 hops_array[dv_count++] = pos; 3907 hops_array[dv_count++] = pos;
3858 return dv_count; 3908 return dv_count;
3859 } 3909 }
3860 for (unsigned int i = 0; i < hops_array_length; i++) 3910 for (unsigned int i = 0; i < hops_array_length; i++)
3861 { 3911 {
3862 int ok = GNUNET_NO; 3912 int ok = GNUNET_NO;
3863 while (GNUNET_NO == ok) 3913 while (GNUNET_NO == ok)
3914 {
3915 choices[i] =
3916 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, num_dv);
3917 ok = GNUNET_YES;
3918 for (unsigned int j = 0; j < i; j++)
3919 if (choices[i] == choices[j])
3864 { 3920 {
3865 choices[i] = 3921 ok = GNUNET_NO;
3866 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, num_dv); 3922 break;
3867 ok = GNUNET_YES;
3868 for (unsigned int j = 0; j < i; j++)
3869 if (choices[i] == choices[j])
3870 {
3871 ok = GNUNET_NO;
3872 break;
3873 }
3874 } 3923 }
3875 } 3924 }
3925 }
3876 dv_count = 0; 3926 dv_count = 0;
3877 num_dv = 0; 3927 num_dv = 0;
3878 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3928 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3879 pos = pos->next_dv) 3929 pos = pos->next_dv)
3880 { 3930 {
3881 uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance; 3931 uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance;
3882 3932
3883 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && 3933 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
3884 (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until) 3934 (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until)
3885 .rel_value_us == 0)) 3935 .rel_value_us == 0))
3886 continue; /* pos unconfirmed and confirmed required */ 3936 continue; /* pos unconfirmed and confirmed required */
3887 for (unsigned int i = 0; i < hops_array_length; i++) 3937 for (unsigned int i = 0; i < hops_array_length; i++)
3888 if ((num_dv <= choices[i]) && (num_dv + delta > choices[i])) 3938 if ((num_dv <= choices[i]) && (num_dv + delta > choices[i]))
3889 hops_array[dv_count++] = pos; 3939 hops_array[dv_count++] = pos;
3890 num_dv += delta; 3940 num_dv += delta;
3891 } 3941 }
3892 return dv_count; 3942 return dv_count;
3893} 3943}
3894 3944
@@ -3900,7 +3950,7 @@ pick_random_dv_hops(const struct DistanceVector *dv,
3900 * @param cam the send message that was sent 3950 * @param cam the send message that was sent
3901 */ 3951 */
3902static int 3952static int
3903check_communicator_available( 3953check_communicator_available (
3904 void *cls, 3954 void *cls,
3905 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) 3955 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
3906{ 3956{
@@ -3908,15 +3958,15 @@ check_communicator_available(
3908 uint16_t size; 3958 uint16_t size;
3909 3959
3910 if (CT_NONE != tc->type) 3960 if (CT_NONE != tc->type)
3911 { 3961 {
3912 GNUNET_break(0); 3962 GNUNET_break (0);
3913 return GNUNET_SYSERR; 3963 return GNUNET_SYSERR;
3914 } 3964 }
3915 tc->type = CT_COMMUNICATOR; 3965 tc->type = CT_COMMUNICATOR;
3916 size = ntohs(cam->header.size) - sizeof(*cam); 3966 size = ntohs (cam->header.size) - sizeof(*cam);
3917 if (0 == size) 3967 if (0 == size)
3918 return GNUNET_OK; /* receive-only communicator */ 3968 return GNUNET_OK; /* receive-only communicator */
3919 GNUNET_MQ_check_zero_termination(cam); 3969 GNUNET_MQ_check_zero_termination (cam);
3920 return GNUNET_OK; 3970 return GNUNET_OK;
3921} 3971}
3922 3972
@@ -3927,22 +3977,22 @@ check_communicator_available(
3927 * @param cmc context for which we are done handling the message 3977 * @param cmc context for which we are done handling the message
3928 */ 3978 */
3929static void 3979static void
3930finish_cmc_handling(struct CommunicatorMessageContext *cmc) 3980finish_cmc_handling (struct CommunicatorMessageContext *cmc)
3931{ 3981{
3932 if (0 != ntohl(cmc->im.fc_on)) 3982 if (0 != ntohl (cmc->im.fc_on))
3933 { 3983 {
3934 /* send ACK when done to communicator for flow control! */ 3984 /* send ACK when done to communicator for flow control! */
3935 struct GNUNET_MQ_Envelope *env; 3985 struct GNUNET_MQ_Envelope *env;
3936 struct GNUNET_TRANSPORT_IncomingMessageAck *ack; 3986 struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
3937 3987
3938 env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); 3988 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
3939 ack->reserved = htonl(0); 3989 ack->reserved = htonl (0);
3940 ack->fc_id = cmc->im.fc_id; 3990 ack->fc_id = cmc->im.fc_id;
3941 ack->sender = cmc->im.sender; 3991 ack->sender = cmc->im.sender;
3942 GNUNET_MQ_send(cmc->tc->mq, env); 3992 GNUNET_MQ_send (cmc->tc->mq, env);
3943 } 3993 }
3944 GNUNET_SERVICE_client_continue(cmc->tc->client); 3994 GNUNET_SERVICE_client_continue (cmc->tc->client);
3945 GNUNET_free(cmc); 3995 GNUNET_free (cmc);
3946} 3996}
3947 3997
3948 3998
@@ -3956,7 +4006,7 @@ finish_cmc_handling(struct CommunicatorMessageContext *cmc)
3956 * @param rom the message that was sent 4006 * @param rom the message that was sent
3957 */ 4007 */
3958static void 4008static void
3959handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom) 4009handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom)
3960{ 4010{
3961 struct TransportClient *tc = cls; 4011 struct TransportClient *tc = cls;
3962 struct VirtualLink *vl; 4012 struct VirtualLink *vl;
@@ -3964,31 +4014,31 @@ handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom)
3964 struct CommunicatorMessageContext *cmc; 4014 struct CommunicatorMessageContext *cmc;
3965 4015
3966 if (CT_CORE != tc->type) 4016 if (CT_CORE != tc->type)
3967 { 4017 {
3968 GNUNET_break(0); 4018 GNUNET_break (0);
3969 GNUNET_SERVICE_client_drop(tc->client); 4019 GNUNET_SERVICE_client_drop (tc->client);
3970 return; 4020 return;
3971 } 4021 }
3972 vl = lookup_virtual_link(&rom->peer); 4022 vl = lookup_virtual_link (&rom->peer);
3973 if (NULL == vl) 4023 if (NULL == vl)
3974 { 4024 {
3975 GNUNET_STATISTICS_update(GST_stats, 4025 GNUNET_STATISTICS_update (GST_stats,
3976 "# RECV_OK dropped: virtual link unknown", 4026 "# RECV_OK dropped: virtual link unknown",
3977 1, 4027 1,
3978 GNUNET_NO); 4028 GNUNET_NO);
3979 GNUNET_SERVICE_client_continue(tc->client); 4029 GNUNET_SERVICE_client_continue (tc->client);
3980 return; 4030 return;
3981 } 4031 }
3982 delta = ntohl(rom->increase_window_delta); 4032 delta = ntohl (rom->increase_window_delta);
3983 vl->core_recv_window += delta; 4033 vl->core_recv_window += delta;
3984 if (vl->core_recv_window <= 0) 4034 if (vl->core_recv_window <= 0)
3985 return; 4035 return;
3986 /* resume communicators */ 4036 /* resume communicators */
3987 while (NULL != (cmc = vl->cmc_tail)) 4037 while (NULL != (cmc = vl->cmc_tail))
3988 { 4038 {
3989 GNUNET_CONTAINER_DLL_remove(vl->cmc_head, vl->cmc_tail, cmc); 4039 GNUNET_CONTAINER_DLL_remove (vl->cmc_head, vl->cmc_tail, cmc);
3990 finish_cmc_handling(cmc); 4040 finish_cmc_handling (cmc);
3991 } 4041 }
3992} 4042}
3993 4043
3994 4044
@@ -3999,28 +4049,28 @@ handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom)
3999 * @param cam the send message that was sent 4049 * @param cam the send message that was sent
4000 */ 4050 */
4001static void 4051static void
4002handle_communicator_available( 4052handle_communicator_available (
4003 void *cls, 4053 void *cls,
4004 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) 4054 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
4005{ 4055{
4006 struct TransportClient *tc = cls; 4056 struct TransportClient *tc = cls;
4007 uint16_t size; 4057 uint16_t size;
4008 4058
4009 size = ntohs(cam->header.size) - sizeof(*cam); 4059 size = ntohs (cam->header.size) - sizeof(*cam);
4010 if (0 == size) 4060 if (0 == size)
4011 { 4061 {
4012 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4062 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4013 "Receive-only communicator connected\n"); 4063 "Receive-only communicator connected\n");
4014 return; /* receive-only communicator */ 4064 return; /* receive-only communicator */
4015 } 4065 }
4016 tc->details.communicator.address_prefix = 4066 tc->details.communicator.address_prefix =
4017 GNUNET_strdup((const char *)&cam[1]); 4067 GNUNET_strdup ((const char *) &cam[1]);
4018 tc->details.communicator.cc = 4068 tc->details.communicator.cc =
4019 (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(cam->cc); 4069 (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc);
4020 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4021 "Communicator with prefix `%s' connected\n", 4071 "Communicator with prefix `%s' connected\n",
4022 tc->details.communicator.address_prefix); 4072 tc->details.communicator.address_prefix);
4023 GNUNET_SERVICE_client_continue(tc->client); 4073 GNUNET_SERVICE_client_continue (tc->client);
4024} 4074}
4025 4075
4026 4076
@@ -4032,7 +4082,7 @@ handle_communicator_available(
4032 * @return #GNUNET_OK if message is well-formed 4082 * @return #GNUNET_OK if message is well-formed
4033 */ 4083 */
4034static int 4084static int
4035check_communicator_backchannel( 4085check_communicator_backchannel (
4036 void *cls, 4086 void *cls,
4037 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 4087 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
4038{ 4088{
@@ -4041,24 +4091,24 @@ check_communicator_backchannel(
4041 uint16_t msize; 4091 uint16_t msize;
4042 uint16_t isize; 4092 uint16_t isize;
4043 4093
4044 (void)cls; 4094 (void) cls;
4045 msize = ntohs(cb->header.size) - sizeof(*cb); 4095 msize = ntohs (cb->header.size) - sizeof(*cb);
4046 inbox = (const struct GNUNET_MessageHeader *)&cb[1]; 4096 inbox = (const struct GNUNET_MessageHeader *) &cb[1];
4047 isize = ntohs(inbox->size); 4097 isize = ntohs (inbox->size);
4048 if (isize >= msize) 4098 if (isize >= msize)
4049 { 4099 {
4050 GNUNET_break(0); 4100 GNUNET_break (0);
4051 return GNUNET_SYSERR; 4101 return GNUNET_SYSERR;
4052 } 4102 }
4053 is = (const char *)inbox; 4103 is = (const char *) inbox;
4054 is += isize; 4104 is += isize;
4055 msize -= isize; 4105 msize -= isize;
4056 GNUNET_assert(0 < msize); 4106 GNUNET_assert (0 < msize);
4057 if ('\0' != is[msize - 1]) 4107 if ('\0' != is[msize - 1])
4058 { 4108 {
4059 GNUNET_break(0); 4109 GNUNET_break (0);
4060 return GNUNET_SYSERR; 4110 return GNUNET_SYSERR;
4061 } 4111 }
4062 return GNUNET_OK; 4112 return GNUNET_OK;
4063} 4113}
4064 4114
@@ -4070,26 +4120,26 @@ check_communicator_backchannel(
4070 * @param dv[in,out] virtual link to update ephemeral for 4120 * @param dv[in,out] virtual link to update ephemeral for
4071 */ 4121 */
4072static void 4122static void
4073update_ephemeral(struct DistanceVector *dv) 4123update_ephemeral (struct DistanceVector *dv)
4074{ 4124{
4075 struct EphemeralConfirmationPS ec; 4125 struct EphemeralConfirmationPS ec;
4076 4126
4077 if (0 != 4127 if (0 !=
4078 GNUNET_TIME_absolute_get_remaining(dv->ephemeral_validity).rel_value_us) 4128 GNUNET_TIME_absolute_get_remaining (dv->ephemeral_validity).rel_value_us)
4079 return; 4129 return;
4080 dv->monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg); 4130 dv->monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg);
4081 dv->ephemeral_validity = 4131 dv->ephemeral_validity =
4082 GNUNET_TIME_absolute_add(dv->monotime, EPHEMERAL_VALIDITY); 4132 GNUNET_TIME_absolute_add (dv->monotime, EPHEMERAL_VALIDITY);
4083 GNUNET_assert(GNUNET_OK == 4133 GNUNET_assert (GNUNET_OK ==
4084 GNUNET_CRYPTO_ecdhe_key_create2(&dv->private_key)); 4134 GNUNET_CRYPTO_ecdhe_key_create2 (&dv->private_key));
4085 GNUNET_CRYPTO_ecdhe_key_get_public(&dv->private_key, &dv->ephemeral_key); 4135 GNUNET_CRYPTO_ecdhe_key_get_public (&dv->private_key, &dv->ephemeral_key);
4086 ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); 4136 ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
4087 ec.purpose.size = htonl(sizeof(ec)); 4137 ec.purpose.size = htonl (sizeof(ec));
4088 ec.target = dv->target; 4138 ec.target = dv->target;
4089 ec.ephemeral_key = dv->ephemeral_key; 4139 ec.ephemeral_key = dv->ephemeral_key;
4090 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, 4140 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
4091 &ec.purpose, 4141 &ec.purpose,
4092 &dv->sender_sig)); 4142 &dv->sender_sig));
4093} 4143}
4094 4144
4095 4145
@@ -4103,45 +4153,45 @@ update_ephemeral(struct DistanceVector *dv)
4103 * @param payload_size number of bytes in @a payload 4153 * @param payload_size number of bytes in @a payload
4104 */ 4154 */
4105static void 4155static void
4106queue_send_msg(struct Queue *queue, 4156queue_send_msg (struct Queue *queue,
4107 struct PendingMessage *pm, 4157 struct PendingMessage *pm,
4108 const void *payload, 4158 const void *payload,
4109 size_t payload_size) 4159 size_t payload_size)
4110{ 4160{
4111 struct Neighbour *n = queue->neighbour; 4161 struct Neighbour *n = queue->neighbour;
4112 struct GNUNET_TRANSPORT_SendMessageTo *smt; 4162 struct GNUNET_TRANSPORT_SendMessageTo *smt;
4113 struct GNUNET_MQ_Envelope *env; 4163 struct GNUNET_MQ_Envelope *env;
4114 4164
4115 queue->idle = GNUNET_NO; 4165 queue->idle = GNUNET_NO;
4116 GNUNET_log( 4166 GNUNET_log (
4117 GNUNET_ERROR_TYPE_DEBUG, 4167 GNUNET_ERROR_TYPE_DEBUG,
4118 "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n", 4168 "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n",
4119 (unsigned int)payload_size, 4169 (unsigned int) payload_size,
4120 (NULL == pm) ? 0 : pm->logging_uuid, 4170 (NULL == pm) ? 0 : pm->logging_uuid,
4121 (unsigned long long)queue->qid, 4171 (unsigned long long) queue->qid,
4122 GNUNET_i2s(&queue->neighbour->pid)); 4172 GNUNET_i2s (&queue->neighbour->pid));
4123 env = GNUNET_MQ_msg_extra(smt, 4173 env = GNUNET_MQ_msg_extra (smt,
4124 payload_size, 4174 payload_size,
4125 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); 4175 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG);
4126 smt->qid = queue->qid; 4176 smt->qid = queue->qid;
4127 smt->mid = queue->mid_gen; 4177 smt->mid = queue->mid_gen;
4128 smt->receiver = n->pid; 4178 smt->receiver = n->pid;
4129 memcpy(&smt[1], payload, payload_size); 4179 memcpy (&smt[1], payload, payload_size);
4130 { 4180 {
4131 /* Pass the env to the communicator of queue for transmission. */ 4181 /* Pass the env to the communicator of queue for transmission. */
4132 struct QueueEntry *qe; 4182 struct QueueEntry *qe;
4133 4183
4134 qe = GNUNET_new(struct QueueEntry); 4184 qe = GNUNET_new (struct QueueEntry);
4135 qe->mid = queue->mid_gen++; 4185 qe->mid = queue->mid_gen++;
4136 qe->queue = queue; 4186 qe->queue = queue;
4137 if (NULL != pm) 4187 if (NULL != pm)
4138 { 4188 {
4139 qe->pm = pm; 4189 qe->pm = pm;
4140 GNUNET_assert(NULL == pm->qe); 4190 GNUNET_assert (NULL == pm->qe);
4141 pm->qe = qe; 4191 pm->qe = qe;
4142 } 4192 }
4143 GNUNET_CONTAINER_DLL_insert(queue->queue_head, queue->queue_tail, qe); 4193 GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe);
4144 GNUNET_assert(CT_COMMUNICATOR == queue->tc->type); 4194 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type);
4145 queue->queue_length++; 4195 queue->queue_length++;
4146 queue->tc->details.communicator.total_queue_length++; 4196 queue->tc->details.communicator.total_queue_length++;
4147 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT == 4197 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT ==
@@ -4149,7 +4199,7 @@ queue_send_msg(struct Queue *queue,
4149 queue->idle = GNUNET_NO; 4199 queue->idle = GNUNET_NO;
4150 if (QUEUE_LENGTH_LIMIT == queue->queue_length) 4200 if (QUEUE_LENGTH_LIMIT == queue->queue_length)
4151 queue->idle = GNUNET_NO; 4201 queue->idle = GNUNET_NO;
4152 GNUNET_MQ_send(queue->tc->mq, env); 4202 GNUNET_MQ_send (queue->tc->mq, env);
4153 } 4203 }
4154} 4204}
4155 4205
@@ -4165,9 +4215,9 @@ queue_send_msg(struct Queue *queue,
4165 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed 4215 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
4166 */ 4216 */
4167static struct GNUNET_TIME_Relative 4217static struct GNUNET_TIME_Relative
4168route_via_neighbour(const struct Neighbour *n, 4218route_via_neighbour (const struct Neighbour *n,
4169 const struct GNUNET_MessageHeader *hdr, 4219 const struct GNUNET_MessageHeader *hdr,
4170 enum RouteMessageOptions options) 4220 enum RouteMessageOptions options)
4171{ 4221{
4172 struct GNUNET_TIME_Absolute now; 4222 struct GNUNET_TIME_Absolute now;
4173 unsigned int candidates; 4223 unsigned int candidates;
@@ -4176,7 +4226,7 @@ route_via_neighbour(const struct Neighbour *n,
4176 struct GNUNET_TIME_Relative rtt; 4226 struct GNUNET_TIME_Relative rtt;
4177 4227
4178 /* Pick one or two 'random' queues from n (under constraints of options) */ 4228 /* Pick one or two 'random' queues from n (under constraints of options) */
4179 now = GNUNET_TIME_absolute_get(); 4229 now = GNUNET_TIME_absolute_get ();
4180 /* FIXME-OPTIMIZE: give queues 'weights' and pick proportional to 4230 /* FIXME-OPTIMIZE: give queues 'weights' and pick proportional to
4181 weight in the future; weight could be assigned by observed 4231 weight in the future; weight could be assigned by observed
4182 bandwidth (note: not sure if we should do this for this type 4232 bandwidth (note: not sure if we should do this for this type
@@ -4184,53 +4234,53 @@ route_via_neighbour(const struct Neighbour *n,
4184 candidates = 0; 4234 candidates = 0;
4185 for (struct Queue *pos = n->queue_head; NULL != pos; 4235 for (struct Queue *pos = n->queue_head; NULL != pos;
4186 pos = pos->next_neighbour) 4236 pos = pos->next_neighbour)
4187 { 4237 {
4188 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || 4238 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
4189 (pos->validated_until.abs_value_us > now.abs_value_us)) 4239 (pos->validated_until.abs_value_us > now.abs_value_us))
4190 candidates++; 4240 candidates++;
4191 } 4241 }
4192 if (0 == candidates) 4242 if (0 == candidates)
4193 { 4243 {
4194 /* This can happen rarely if the last confirmed queue timed 4244 /* This can happen rarely if the last confirmed queue timed
4195 out just as we were beginning to process this message. */ 4245 out just as we were beginning to process this message. */
4196 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 4246 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
4197 "Could not route message of type %u to %s: no valid queue\n", 4247 "Could not route message of type %u to %s: no valid queue\n",
4198 ntohs(hdr->type), 4248 ntohs (hdr->type),
4199 GNUNET_i2s(&n->pid)); 4249 GNUNET_i2s (&n->pid));
4200 GNUNET_STATISTICS_update(GST_stats, 4250 GNUNET_STATISTICS_update (GST_stats,
4201 "# route selection failed (all no valid queue)", 4251 "# route selection failed (all no valid queue)",
4202 1, 4252 1,
4203 GNUNET_NO); 4253 GNUNET_NO);
4204 return GNUNET_TIME_UNIT_FOREVER_REL; 4254 return GNUNET_TIME_UNIT_FOREVER_REL;
4205 } 4255 }
4206 4256
4207 rtt = GNUNET_TIME_UNIT_FOREVER_REL; 4257 rtt = GNUNET_TIME_UNIT_FOREVER_REL;
4208 sel1 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates); 4258 sel1 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates);
4209 if (0 == (options & RMO_REDUNDANT)) 4259 if (0 == (options & RMO_REDUNDANT))
4210 sel2 = candidates; /* picks none! */ 4260 sel2 = candidates; /* picks none! */
4211 else 4261 else
4212 sel2 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates); 4262 sel2 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates);
4213 candidates = 0; 4263 candidates = 0;
4214 for (struct Queue *pos = n->queue_head; NULL != pos; 4264 for (struct Queue *pos = n->queue_head; NULL != pos;
4215 pos = pos->next_neighbour) 4265 pos = pos->next_neighbour)
4266 {
4267 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
4268 (pos->validated_until.abs_value_us > now.abs_value_us))
4216 { 4269 {
4217 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || 4270 if ((sel1 == candidates) || (sel2 == candidates))
4218 (pos->validated_until.abs_value_us > now.abs_value_us)) 4271 {
4219 { 4272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4220 if ((sel1 == candidates) || (sel2 == candidates)) 4273 "Routing message of type %u to %s using %s (#%u)\n",
4221 { 4274 ntohs (hdr->type),
4222 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4275 GNUNET_i2s (&n->pid),
4223 "Routing message of type %u to %s using %s (#%u)\n", 4276 pos->address,
4224 ntohs(hdr->type), 4277 (sel1 == candidates) ? 1 : 2);
4225 GNUNET_i2s(&n->pid), 4278 rtt = GNUNET_TIME_relative_min (rtt, pos->pd.aged_rtt);
4226 pos->address, 4279 queue_send_msg (pos, NULL, hdr, ntohs (hdr->size));
4227 (sel1 == candidates) ? 1 : 2); 4280 }
4228 rtt = GNUNET_TIME_relative_min(rtt, pos->pd.aged_rtt); 4281 candidates++;
4229 queue_send_msg(pos, NULL, hdr, ntohs(hdr->size));
4230 }
4231 candidates++;
4232 }
4233 } 4282 }
4283 }
4234 return rtt; 4284 return rtt;
4235} 4285}
4236 4286
@@ -4238,7 +4288,8 @@ route_via_neighbour(const struct Neighbour *n,
4238/** 4288/**
4239 * Structure of the key material used to encrypt backchannel messages. 4289 * Structure of the key material used to encrypt backchannel messages.
4240 */ 4290 */
4241struct DVKeyState { 4291struct DVKeyState
4292{
4242 /** 4293 /**
4243 * State of our block cipher. 4294 * State of our block cipher.
4244 */ 4295 */
@@ -4247,7 +4298,8 @@ struct DVKeyState {
4247 /** 4298 /**
4248 * Actual key material. 4299 * Actual key material.
4249 */ 4300 */
4250 struct { 4301 struct
4302 {
4251 /** 4303 /**
4252 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()). 4304 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()).
4253 */ 4305 */
@@ -4275,34 +4327,34 @@ struct DVKeyState {
4275 * @param key[out] symmetric cipher and HMAC state to generate 4327 * @param key[out] symmetric cipher and HMAC state to generate
4276 */ 4328 */
4277static void 4329static void
4278dv_setup_key_state_from_km(const struct GNUNET_HashCode *km, 4330dv_setup_key_state_from_km (const struct GNUNET_HashCode *km,
4279 const struct GNUNET_ShortHashCode *iv, 4331 const struct GNUNET_ShortHashCode *iv,
4280 struct DVKeyState *key) 4332 struct DVKeyState *key)
4281{ 4333{
4282 /* must match #dh_key_derive_eph_pub */ 4334 /* must match #dh_key_derive_eph_pub */
4283 GNUNET_assert(GNUNET_YES == 4335 GNUNET_assert (GNUNET_YES ==
4284 GNUNET_CRYPTO_kdf(&key->material, 4336 GNUNET_CRYPTO_kdf (&key->material,
4285 sizeof(key->material), 4337 sizeof(key->material),
4286 "transport-backchannel-key", 4338 "transport-backchannel-key",
4287 strlen("transport-backchannel-key"), 4339 strlen ("transport-backchannel-key"),
4288 &km, 4340 &km,
4289 sizeof(km), 4341 sizeof(km),
4290 iv, 4342 iv,
4291 sizeof(*iv))); 4343 sizeof(*iv)));
4292 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4293 "Deriving backchannel key based on KM %s and IV %s\n", 4345 "Deriving backchannel key based on KM %s and IV %s\n",
4294 GNUNET_h2s(km), 4346 GNUNET_h2s (km),
4295 GNUNET_sh2s(iv)); 4347 GNUNET_sh2s (iv));
4296 gcry_cipher_open(&key->cipher, 4348 gcry_cipher_open (&key->cipher,
4297 GCRY_CIPHER_AES256 /* low level: go for speed */, 4349 GCRY_CIPHER_AES256 /* low level: go for speed */,
4298 GCRY_CIPHER_MODE_CTR, 4350 GCRY_CIPHER_MODE_CTR,
4299 0 /* flags */); 4351 0 /* flags */);
4300 gcry_cipher_setkey(key->cipher, 4352 gcry_cipher_setkey (key->cipher,
4301 &key->material.aes_key, 4353 &key->material.aes_key,
4302 sizeof(key->material.aes_key)); 4354 sizeof(key->material.aes_key));
4303 gcry_cipher_setctr(key->cipher, 4355 gcry_cipher_setctr (key->cipher,
4304 &key->material.aes_ctr, 4356 &key->material.aes_ctr,
4305 sizeof(key->material.aes_ctr)); 4357 sizeof(key->material.aes_ctr));
4306} 4358}
4307 4359
4308 4360
@@ -4316,7 +4368,7 @@ dv_setup_key_state_from_km(const struct GNUNET_HashCode *km,
4316 * @param key[out] set to the key material 4368 * @param key[out] set to the key material
4317 */ 4369 */
4318static void 4370static void
4319dh_key_derive_eph_pid( 4371dh_key_derive_eph_pid (
4320 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, 4372 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral,
4321 const struct GNUNET_PeerIdentity *target, 4373 const struct GNUNET_PeerIdentity *target,
4322 const struct GNUNET_ShortHashCode *iv, 4374 const struct GNUNET_ShortHashCode *iv,
@@ -4324,10 +4376,10 @@ dh_key_derive_eph_pid(
4324{ 4376{
4325 struct GNUNET_HashCode km; 4377 struct GNUNET_HashCode km;
4326 4378
4327 GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa(priv_ephemeral, 4379 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral,
4328 &target->public_key, 4380 &target->public_key,
4329 &km)); 4381 &km));
4330 dv_setup_key_state_from_km(&km, iv, key); 4382 dv_setup_key_state_from_km (&km, iv, key);
4331} 4383}
4332 4384
4333 4385
@@ -4341,16 +4393,16 @@ dh_key_derive_eph_pid(
4341 * @param key[out] set to the key material 4393 * @param key[out] set to the key material
4342 */ 4394 */
4343static void 4395static void
4344dh_key_derive_eph_pub(const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, 4396dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
4345 const struct GNUNET_ShortHashCode *iv, 4397 const struct GNUNET_ShortHashCode *iv,
4346 struct DVKeyState *key) 4398 struct DVKeyState *key)
4347{ 4399{
4348 struct GNUNET_HashCode km; 4400 struct GNUNET_HashCode km;
4349 4401
4350 GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh(GST_my_private_key, 4402 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key,
4351 pub_ephemeral, 4403 pub_ephemeral,
4352 &km)); 4404 &km));
4353 dv_setup_key_state_from_km(&km, iv, key); 4405 dv_setup_key_state_from_km (&km, iv, key);
4354} 4406}
4355 4407
4356 4408
@@ -4364,12 +4416,12 @@ dh_key_derive_eph_pub(const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
4364 * @param data_size number of bytes in @a data 4416 * @param data_size number of bytes in @a data
4365 */ 4417 */
4366static void 4418static void
4367dv_hmac(const struct DVKeyState *key, 4419dv_hmac (const struct DVKeyState *key,
4368 struct GNUNET_HashCode *hmac, 4420 struct GNUNET_HashCode *hmac,
4369 const void *data, 4421 const void *data,
4370 size_t data_size) 4422 size_t data_size)
4371{ 4423{
4372 GNUNET_CRYPTO_hmac(&key->material.hmac_key, data, data_size, hmac); 4424 GNUNET_CRYPTO_hmac (&key->material.hmac_key, data, data_size, hmac);
4373} 4425}
4374 4426
4375 4427
@@ -4383,10 +4435,10 @@ dv_hmac(const struct DVKeyState *key,
4383 * @param in_size number of bytes of input in @a in and available at @a dst 4435 * @param in_size number of bytes of input in @a in and available at @a dst
4384 */ 4436 */
4385static void 4437static void
4386dv_encrypt(struct DVKeyState *key, const void *in, void *dst, size_t in_size) 4438dv_encrypt (struct DVKeyState *key, const void *in, void *dst, size_t in_size)
4387{ 4439{
4388 GNUNET_assert(0 == 4440 GNUNET_assert (0 ==
4389 gcry_cipher_encrypt(key->cipher, dst, in_size, in, in_size)); 4441 gcry_cipher_encrypt (key->cipher, dst, in_size, in, in_size));
4390} 4442}
4391 4443
4392 4444
@@ -4400,13 +4452,13 @@ dv_encrypt(struct DVKeyState *key, const void *in, void *dst, size_t in_size)
4400 * @param out_size number of bytes of input in @a ciph and available in @a out 4452 * @param out_size number of bytes of input in @a ciph and available in @a out
4401 */ 4453 */
4402static void 4454static void
4403dv_decrypt(struct DVKeyState *key, 4455dv_decrypt (struct DVKeyState *key,
4404 void *out, 4456 void *out,
4405 const void *ciph, 4457 const void *ciph,
4406 size_t out_size) 4458 size_t out_size)
4407{ 4459{
4408 GNUNET_assert( 4460 GNUNET_assert (
4409 0 == gcry_cipher_decrypt(key->cipher, out, out_size, ciph, out_size)); 4461 0 == gcry_cipher_decrypt (key->cipher, out, out_size, ciph, out_size));
4410} 4462}
4411 4463
4412 4464
@@ -4416,10 +4468,10 @@ dv_decrypt(struct DVKeyState *key,
4416 * @param key key material to clean up (memory must not be free'd!) 4468 * @param key key material to clean up (memory must not be free'd!)
4417 */ 4469 */
4418static void 4470static void
4419dv_key_clean(struct DVKeyState *key) 4471dv_key_clean (struct DVKeyState *key)
4420{ 4472{
4421 gcry_cipher_close(key->cipher); 4473 gcry_cipher_close (key->cipher);
4422 GNUNET_CRYPTO_zero_keys(&key->material, sizeof(key->material)); 4474 GNUNET_CRYPTO_zero_keys (&key->material, sizeof(key->material));
4423} 4475}
4424 4476
4425 4477
@@ -4452,92 +4504,92 @@ typedef void (*DVMessageHandler) (void *cls,
4452 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed 4504 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
4453 */ 4505 */
4454static struct GNUNET_TIME_Relative 4506static struct GNUNET_TIME_Relative
4455encapsulate_for_dv(struct DistanceVector *dv, 4507encapsulate_for_dv (struct DistanceVector *dv,
4456 unsigned int num_dvhs, 4508 unsigned int num_dvhs,
4457 struct DistanceVectorHop **dvhs, 4509 struct DistanceVectorHop **dvhs,
4458 const struct GNUNET_MessageHeader *hdr, 4510 const struct GNUNET_MessageHeader *hdr,
4459 DVMessageHandler use, 4511 DVMessageHandler use,
4460 void *use_cls, 4512 void *use_cls,
4461 enum RouteMessageOptions options) 4513 enum RouteMessageOptions options)
4462{ 4514{
4463 struct TransportDVBoxMessage box_hdr; 4515 struct TransportDVBoxMessage box_hdr;
4464 struct TransportDVBoxPayloadP payload_hdr; 4516 struct TransportDVBoxPayloadP payload_hdr;
4465 uint16_t enc_body_size = ntohs(hdr->size); 4517 uint16_t enc_body_size = ntohs (hdr->size);
4466 char enc[sizeof(struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN; 4518 char enc[sizeof(struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN;
4467 struct TransportDVBoxPayloadP *enc_payload_hdr = 4519 struct TransportDVBoxPayloadP *enc_payload_hdr =
4468 (struct TransportDVBoxPayloadP *)enc; 4520 (struct TransportDVBoxPayloadP *) enc;
4469 struct DVKeyState key; 4521 struct DVKeyState key;
4470 struct GNUNET_TIME_Relative rtt; 4522 struct GNUNET_TIME_Relative rtt;
4471 4523
4472 /* Encrypt payload */ 4524 /* Encrypt payload */
4473 box_hdr.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX); 4525 box_hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX);
4474 box_hdr.total_hops = htons(0); 4526 box_hdr.total_hops = htons (0);
4475 update_ephemeral(dv); 4527 update_ephemeral (dv);
4476 box_hdr.ephemeral_key = dv->ephemeral_key; 4528 box_hdr.ephemeral_key = dv->ephemeral_key;
4477 payload_hdr.sender_sig = dv->sender_sig; 4529 payload_hdr.sender_sig = dv->sender_sig;
4478 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, 4530 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
4479 &box_hdr.iv, 4531 &box_hdr.iv,
4480 sizeof(box_hdr.iv)); 4532 sizeof(box_hdr.iv));
4481 dh_key_derive_eph_pid(&dv->private_key, &dv->target, &box_hdr.iv, &key); 4533 dh_key_derive_eph_pid (&dv->private_key, &dv->target, &box_hdr.iv, &key);
4482 payload_hdr.sender = GST_my_identity; 4534 payload_hdr.sender = GST_my_identity;
4483 payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton(dv->monotime); 4535 payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton (dv->monotime);
4484 dv_encrypt(&key, &payload_hdr, enc_payload_hdr, sizeof(payload_hdr)); 4536 dv_encrypt (&key, &payload_hdr, enc_payload_hdr, sizeof(payload_hdr));
4485 dv_encrypt(&key, 4537 dv_encrypt (&key,
4486 hdr, 4538 hdr,
4487 &enc[sizeof(struct TransportDVBoxPayloadP)], 4539 &enc[sizeof(struct TransportDVBoxPayloadP)],
4488 enc_body_size); 4540 enc_body_size);
4489 dv_hmac(&key, &box_hdr.hmac, enc, sizeof(enc)); 4541 dv_hmac (&key, &box_hdr.hmac, enc, sizeof(enc));
4490 dv_key_clean(&key); 4542 dv_key_clean (&key);
4491 rtt = GNUNET_TIME_UNIT_FOREVER_REL; 4543 rtt = GNUNET_TIME_UNIT_FOREVER_REL;
4492 /* For each selected path, take the pre-computed header and body 4544 /* For each selected path, take the pre-computed header and body
4493 and add the path in the middle of the message; then send it. */ 4545 and add the path in the middle of the message; then send it. */
4494 for (unsigned int i = 0; i < num_dvhs; i++) 4546 for (unsigned int i = 0; i < num_dvhs; i++)
4547 {
4548 struct DistanceVectorHop *dvh = dvhs[i];
4549 unsigned int num_hops = dvh->distance + 1;
4550 char buf[sizeof(struct TransportDVBoxMessage)
4551 + sizeof(struct GNUNET_PeerIdentity) * num_hops
4552 + sizeof(struct TransportDVBoxPayloadP)
4553 + enc_body_size] GNUNET_ALIGN;
4554 struct GNUNET_PeerIdentity *dhops;
4555
4556 box_hdr.header.size = htons (sizeof(buf));
4557 box_hdr.num_hops = htons (num_hops);
4558 memcpy (buf, &box_hdr, sizeof(box_hdr));
4559 dhops = (struct GNUNET_PeerIdentity *) &buf[sizeof(box_hdr)];
4560 memcpy (dhops,
4561 dvh->path,
4562 dvh->distance * sizeof(struct GNUNET_PeerIdentity));
4563 dhops[dvh->distance] = dv->target;
4564 if (GNUNET_EXTRA_LOGGING > 0)
4495 { 4565 {
4496 struct DistanceVectorHop *dvh = dvhs[i]; 4566 char *path;
4497 unsigned int num_hops = dvh->distance + 1; 4567
4498 char buf[sizeof(struct TransportDVBoxMessage) + 4568 path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity));
4499 sizeof(struct GNUNET_PeerIdentity) * num_hops + 4569 for (unsigned int j = 0; j <= num_hops; j++)
4500 sizeof(struct TransportDVBoxPayloadP) + 4570 {
4501 enc_body_size] GNUNET_ALIGN; 4571 char *tmp;
4502 struct GNUNET_PeerIdentity *dhops; 4572
4503 4573 GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[j]));
4504 box_hdr.header.size = htons(sizeof(buf)); 4574 GNUNET_free (path);
4505 box_hdr.num_hops = htons(num_hops); 4575 path = tmp;
4506 memcpy(buf, &box_hdr, sizeof(box_hdr)); 4576 }
4507 dhops = (struct GNUNET_PeerIdentity *)&buf[sizeof(box_hdr)]; 4577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4508 memcpy(dhops, 4578 "Routing message of type %u to %s using DV (#%u/%u) via %s\n",
4509 dvh->path, 4579 ntohs (hdr->type),
4510 dvh->distance * sizeof(struct GNUNET_PeerIdentity)); 4580 GNUNET_i2s (&dv->target),
4511 dhops[dvh->distance] = dv->target; 4581 i + 1,
4512 if (GNUNET_EXTRA_LOGGING > 0) 4582 num_dvhs + 1,
4513 { 4583 path);
4514 char *path; 4584 GNUNET_free (path);
4515 4585 }
4516 path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity)); 4586 rtt = GNUNET_TIME_relative_min (rtt, dvh->pd.aged_rtt);
4517 for (unsigned int j = 0; j <= num_hops; j++) 4587 memcpy (&dhops[num_hops], enc, sizeof(enc));
4518 { 4588 use (use_cls,
4519 char *tmp; 4589 dvh->next_hop,
4520 4590 (const struct GNUNET_MessageHeader *) buf,
4521 GNUNET_asprintf(&tmp, "%s-%s", path, GNUNET_i2s(&dhops[j])); 4591 options);
4522 GNUNET_free(path); 4592 }
4523 path = tmp;
4524 }
4525 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4526 "Routing message of type %u to %s using DV (#%u/%u) via %s\n",
4527 ntohs(hdr->type),
4528 GNUNET_i2s(&dv->target),
4529 i + 1,
4530 num_dvhs + 1,
4531 path);
4532 GNUNET_free(path);
4533 }
4534 rtt = GNUNET_TIME_relative_min(rtt, dvh->pd.aged_rtt);
4535 memcpy(&dhops[num_hops], enc, sizeof(enc));
4536 use(use_cls,
4537 dvh->next_hop,
4538 (const struct GNUNET_MessageHeader *)buf,
4539 options);
4540 }
4541 return rtt; 4593 return rtt;
4542} 4594}
4543 4595
@@ -4552,13 +4604,13 @@ encapsulate_for_dv(struct DistanceVector *dv,
4552 * @param options message options for queue selection 4604 * @param options message options for queue selection
4553 */ 4605 */
4554static void 4606static void
4555send_dv_to_neighbour(void *cls, 4607send_dv_to_neighbour (void *cls,
4556 struct Neighbour *next_hop, 4608 struct Neighbour *next_hop,
4557 const struct GNUNET_MessageHeader *hdr, 4609 const struct GNUNET_MessageHeader *hdr,
4558 enum RouteMessageOptions options) 4610 enum RouteMessageOptions options)
4559{ 4611{
4560 (void)cls; 4612 (void) cls;
4561 (void)route_via_neighbour(next_hop, hdr, options); 4613 (void) route_via_neighbour (next_hop, hdr, options);
4562} 4614}
4563 4615
4564 4616
@@ -4574,9 +4626,9 @@ send_dv_to_neighbour(void *cls,
4574 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed 4626 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
4575 */ 4627 */
4576static struct GNUNET_TIME_Relative 4628static struct GNUNET_TIME_Relative
4577route_control_message_without_fc(const struct GNUNET_PeerIdentity *target, 4629route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4578 const struct GNUNET_MessageHeader *hdr, 4630 const struct GNUNET_MessageHeader *hdr,
4579 enum RouteMessageOptions options) 4631 enum RouteMessageOptions options)
4580{ 4632{
4581 struct VirtualLink *vl; 4633 struct VirtualLink *vl;
4582 struct Neighbour *n; 4634 struct Neighbour *n;
@@ -4584,78 +4636,78 @@ route_control_message_without_fc(const struct GNUNET_PeerIdentity *target,
4584 struct GNUNET_TIME_Relative rtt1; 4636 struct GNUNET_TIME_Relative rtt1;
4585 struct GNUNET_TIME_Relative rtt2; 4637 struct GNUNET_TIME_Relative rtt2;
4586 4638
4587 vl = lookup_virtual_link(target); 4639 vl = lookup_virtual_link (target);
4588 GNUNET_assert(NULL != vl); 4640 GNUNET_assert (NULL != vl);
4589 n = vl->n; 4641 n = vl->n;
4590 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL; 4642 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL;
4591 if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) 4643 if (0 == (options & RMO_UNCONFIRMED_ALLOWED))
4592 { 4644 {
4593 /* if confirmed is required, and we do not have anything 4645 /* if confirmed is required, and we do not have anything
4594 confirmed, drop respective options */ 4646 confirmed, drop respective options */
4595 if (NULL == n) 4647 if (NULL == n)
4596 n = lookup_neighbour(target); 4648 n = lookup_neighbour (target);
4597 if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED))) 4649 if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED)))
4598 dv = GNUNET_CONTAINER_multipeermap_get(dv_routes, target); 4650 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, target);
4599 } 4651 }
4600 if ((NULL == n) && (NULL == dv)) 4652 if ((NULL == n) && (NULL == dv))
4601 { 4653 {
4602 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 4654 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
4603 "Cannot route message of type %u to %s: no route\n", 4655 "Cannot route message of type %u to %s: no route\n",
4604 ntohs(hdr->type), 4656 ntohs (hdr->type),
4605 GNUNET_i2s(target)); 4657 GNUNET_i2s (target));
4606 GNUNET_STATISTICS_update(GST_stats, 4658 GNUNET_STATISTICS_update (GST_stats,
4607 "# Messages dropped in routing: no acceptable method", 4659 "# Messages dropped in routing: no acceptable method",
4608 1, 4660 1,
4609 GNUNET_NO); 4661 GNUNET_NO);
4610 return GNUNET_TIME_UNIT_FOREVER_REL; 4662 return GNUNET_TIME_UNIT_FOREVER_REL;
4611 } 4663 }
4612 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4613 "Routing message of type %u to %s with options %X\n", 4665 "Routing message of type %u to %s with options %X\n",
4614 ntohs(hdr->type), 4666 ntohs (hdr->type),
4615 GNUNET_i2s(target), 4667 GNUNET_i2s (target),
4616 (unsigned int)options); 4668 (unsigned int) options);
4617 /* If both dv and n are possible and we must choose: 4669 /* If both dv and n are possible and we must choose:
4618 flip a coin for the choice between the two; for now 50/50 */ 4670 flip a coin for the choice between the two; for now 50/50 */
4619 if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT))) 4671 if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT)))
4620 { 4672 {
4621 if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2)) 4673 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2))
4622 n = NULL; 4674 n = NULL;
4623 else 4675 else
4624 dv = NULL; 4676 dv = NULL;
4625 } 4677 }
4626 if ((NULL != n) && (NULL != dv)) 4678 if ((NULL != n) && (NULL != dv))
4627 options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's 4679 options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's
4628 enough for redunancy, so clear the flag. */ 4680 enough for redunancy, so clear the flag. */
4629 rtt1 = GNUNET_TIME_UNIT_FOREVER_REL; 4681 rtt1 = GNUNET_TIME_UNIT_FOREVER_REL;
4630 rtt2 = GNUNET_TIME_UNIT_FOREVER_REL; 4682 rtt2 = GNUNET_TIME_UNIT_FOREVER_REL;
4631 if (NULL != n) 4683 if (NULL != n)
4632 { 4684 {
4633 rtt1 = route_via_neighbour(n, hdr, options); 4685 rtt1 = route_via_neighbour (n, hdr, options);
4634 } 4686 }
4635 if (NULL != dv) 4687 if (NULL != dv)
4636 { 4688 {
4637 struct DistanceVectorHop *hops[2]; 4689 struct DistanceVectorHop *hops[2];
4638 unsigned int res; 4690 unsigned int res;
4639 4691
4640 res = pick_random_dv_hops(dv, 4692 res = pick_random_dv_hops (dv,
4641 options, 4693 options,
4642 hops, 4694 hops,
4643 (0 == (options & RMO_REDUNDANT)) ? 1 : 2); 4695 (0 == (options & RMO_REDUNDANT)) ? 1 : 2);
4644 if (0 == res) 4696 if (0 == res)
4645 { 4697 {
4646 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 4698 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
4647 "Failed to route message, could not determine DV path\n"); 4699 "Failed to route message, could not determine DV path\n");
4648 return rtt1; 4700 return rtt1;
4649 } 4701 }
4650 rtt2 = encapsulate_for_dv(dv, 4702 rtt2 = encapsulate_for_dv (dv,
4651 res, 4703 res,
4652 hops, 4704 hops,
4653 hdr, 4705 hdr,
4654 &send_dv_to_neighbour, 4706 &send_dv_to_neighbour,
4655 NULL, 4707 NULL,
4656 options & (~RMO_REDUNDANT)); 4708 options & (~RMO_REDUNDANT));
4657 } 4709 }
4658 return GNUNET_TIME_relative_min(rtt1, rtt2); 4710 return GNUNET_TIME_relative_min (rtt1, rtt2);
4659} 4711}
4660 4712
4661 4713
@@ -4666,7 +4718,7 @@ route_control_message_without_fc(const struct GNUNET_PeerIdentity *target,
4666 * @param cls a `struct VirtualLink` to work with 4718 * @param cls a `struct VirtualLink` to work with
4667 */ 4719 */
4668static void 4720static void
4669consider_sending_fc(void *cls) 4721consider_sending_fc (void *cls)
4670{ 4722{
4671 struct VirtualLink *vl = cls; 4723 struct VirtualLink *vl = cls;
4672 struct GNUNET_TIME_Absolute monotime; 4724 struct GNUNET_TIME_Absolute monotime;
@@ -4674,7 +4726,7 @@ consider_sending_fc(void *cls)
4674 struct GNUNET_TIME_Relative duration; 4726 struct GNUNET_TIME_Relative duration;
4675 struct GNUNET_TIME_Relative rtt; 4727 struct GNUNET_TIME_Relative rtt;
4676 4728
4677 duration = GNUNET_TIME_absolute_get_duration(vl->last_fc_transmission); 4729 duration = GNUNET_TIME_absolute_get_duration (vl->last_fc_transmission);
4678 /* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing 4730 /* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing
4679 it always! */ 4731 it always! */
4680 /* For example, we should probably ONLY do this if a bit more than 4732 /* For example, we should probably ONLY do this if a bit more than
@@ -4683,41 +4735,41 @@ consider_sending_fc(void *cls)
4683 need an estimate for the bandwidth-delay-product for the entire 4735 need an estimate for the bandwidth-delay-product for the entire
4684 VL, as that determines "significantly". We have the delay, but 4736 VL, as that determines "significantly". We have the delay, but
4685 the bandwidth statistics need to be added for the VL!*/ 4737 the bandwidth statistics need to be added for the VL!*/
4686 (void)duration; 4738 (void) duration;
4687 4739
4688 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4689 "Sending FC seq %u to %s with new window %llu\n", 4741 "Sending FC seq %u to %s with new window %llu\n",
4690 (unsigned int)vl->fc_seq_gen, 4742 (unsigned int) vl->fc_seq_gen,
4691 GNUNET_i2s(&vl->target), 4743 GNUNET_i2s (&vl->target),
4692 (unsigned long long)vl->incoming_fc_window_size); 4744 (unsigned long long) vl->incoming_fc_window_size);
4693 monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg); 4745 monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg);
4694 vl->last_fc_transmission = monotime; 4746 vl->last_fc_transmission = monotime;
4695 fc.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL); 4747 fc.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL);
4696 fc.header.size = htons(sizeof(fc)); 4748 fc.header.size = htons (sizeof(fc));
4697 fc.seq = htonl(vl->fc_seq_gen++); 4749 fc.seq = htonl (vl->fc_seq_gen++);
4698 fc.inbound_window_size = GNUNET_htonll(vl->incoming_fc_window_size); 4750 fc.inbound_window_size = GNUNET_htonll (vl->incoming_fc_window_size);
4699 fc.outbound_sent = GNUNET_htonll(vl->outbound_fc_window_size_used); 4751 fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used);
4700 fc.outbound_window_size = GNUNET_htonll(vl->outbound_fc_window_size); 4752 fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size);
4701 fc.sender_time = GNUNET_TIME_absolute_hton(monotime); 4753 fc.sender_time = GNUNET_TIME_absolute_hton (monotime);
4702 rtt = route_control_message_without_fc(&vl->target, &fc.header, RMO_NONE); 4754 rtt = route_control_message_without_fc (&vl->target, &fc.header, RMO_NONE);
4703 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us) 4755 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us)
4704 { 4756 {
4705 rtt = GNUNET_TIME_UNIT_SECONDS; 4757 rtt = GNUNET_TIME_UNIT_SECONDS;
4706 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4707 "FC retransmission to %s failed, will retry in %s\n", 4759 "FC retransmission to %s failed, will retry in %s\n",
4708 GNUNET_i2s(&vl->target), 4760 GNUNET_i2s (&vl->target),
4709 GNUNET_STRINGS_relative_time_to_string(rtt, GNUNET_YES)); 4761 GNUNET_STRINGS_relative_time_to_string (rtt, GNUNET_YES));
4710 vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO; 4762 vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO;
4711 } 4763 }
4712 else 4764 else
4713 { 4765 {
4714 /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */ 4766 /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */
4715 vl->last_fc_rtt = rtt; 4767 vl->last_fc_rtt = rtt;
4716 } 4768 }
4717 if (NULL != vl->fc_retransmit_task) 4769 if (NULL != vl->fc_retransmit_task)
4718 GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task); 4770 GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task);
4719 vl->fc_retransmit_task = 4771 vl->fc_retransmit_task =
4720 GNUNET_SCHEDULER_add_delayed(rtt, &consider_sending_fc, vl); 4772 GNUNET_SCHEDULER_add_delayed (rtt, &consider_sending_fc, vl);
4721} 4773}
4722 4774
4723 4775
@@ -4738,7 +4790,7 @@ consider_sending_fc(void *cls)
4738 * @param vl virtual link where we should check for transmission 4790 * @param vl virtual link where we should check for transmission
4739 */ 4791 */
4740static void 4792static void
4741check_vl_transmission(struct VirtualLink *vl) 4793check_vl_transmission (struct VirtualLink *vl)
4742{ 4794{
4743 struct Neighbour *n = vl->n; 4795 struct Neighbour *n = vl->n;
4744 struct DistanceVector *dv = vl->dv; 4796 struct DistanceVector *dv = vl->dv;
@@ -4750,57 +4802,57 @@ check_vl_transmission(struct VirtualLink *vl)
4750 elig = GNUNET_NO; 4802 elig = GNUNET_NO;
4751 for (struct PendingMessage *pm = vl->pending_msg_head; NULL != pm; 4803 for (struct PendingMessage *pm = vl->pending_msg_head; NULL != pm;
4752 pm = pm->next_vl) 4804 pm = pm->next_vl)
4753 { 4805 {
4754 if (NULL != pm->qe) 4806 if (NULL != pm->qe)
4755 continue; /* not eligible, is in a queue! */ 4807 continue; /* not eligible, is in a queue! */
4756 if (pm->bytes_msg + vl->outbound_fc_window_size_used > 4808 if (pm->bytes_msg + vl->outbound_fc_window_size_used >
4757 vl->outbound_fc_window_size) 4809 vl->outbound_fc_window_size)
4758 { 4810 {
4759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4760 "Stalled transmision on VL %s due to flow control: %llu < %llu\n", 4812 "Stalled transmision on VL %s due to flow control: %llu < %llu\n",
4761 GNUNET_i2s(&vl->target), 4813 GNUNET_i2s (&vl->target),
4762 (unsigned long long)vl->outbound_fc_window_size, 4814 (unsigned long long) vl->outbound_fc_window_size,
4763 (unsigned long long)(pm->bytes_msg + 4815 (unsigned long long) (pm->bytes_msg
4764 vl->outbound_fc_window_size_used)); 4816 + vl->outbound_fc_window_size_used));
4765 consider_sending_fc(vl); 4817 consider_sending_fc (vl);
4766 return; /* We have a message, but flow control says "nope" */ 4818 return; /* We have a message, but flow control says "nope" */
4767 } 4819 }
4768 elig = GNUNET_YES; 4820 elig = GNUNET_YES;
4769 break; 4821 break;
4770 } 4822 }
4771 if (GNUNET_NO == elig) 4823 if (GNUNET_NO == elig)
4772 return; 4824 return;
4773 4825
4774 /* Notify queues at direct neighbours that we are interested */ 4826 /* Notify queues at direct neighbours that we are interested */
4775 now = GNUNET_TIME_absolute_get(); 4827 now = GNUNET_TIME_absolute_get ();
4776 if (NULL != n) 4828 if (NULL != n)
4829 {
4830 for (struct Queue *queue = n->queue_head; NULL != queue;
4831 queue = queue->next_neighbour)
4832 if ((GNUNET_YES == queue->idle) &&
4833 (queue->validated_until.abs_value_us > now.abs_value_us))
4834 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
4835 }
4836 /* Notify queues via DV that we are interested */
4837 if (NULL != dv)
4838 {
4839 /* Do DV with lower scheduler priority, which effectively means that
4840 IF a neighbour exists and is available, we prefer it. */
4841 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
4842 pos = pos->next_dv)
4777 { 4843 {
4778 for (struct Queue *queue = n->queue_head; NULL != queue; 4844 struct Neighbour *nh = pos->next_hop;
4845
4846 if (pos->path_valid_until.abs_value_us <= now.abs_value_us)
4847 continue; /* skip this one: path not validated */
4848 for (struct Queue *queue = nh->queue_head; NULL != queue;
4779 queue = queue->next_neighbour) 4849 queue = queue->next_neighbour)
4780 if ((GNUNET_YES == queue->idle) && 4850 if ((GNUNET_YES == queue->idle) &&
4781 (queue->validated_until.abs_value_us > now.abs_value_us)) 4851 (queue->validated_until.abs_value_us > now.abs_value_us))
4782 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 4852 schedule_transmit_on_queue (queue,
4783 } 4853 GNUNET_SCHEDULER_PRIORITY_BACKGROUND);
4784 /* Notify queues via DV that we are interested */
4785 if (NULL != dv)
4786 {
4787 /* Do DV with lower scheduler priority, which effectively means that
4788 IF a neighbour exists and is available, we prefer it. */
4789 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
4790 pos = pos->next_dv)
4791 {
4792 struct Neighbour *nh = pos->next_hop;
4793
4794 if (pos->path_valid_until.abs_value_us <= now.abs_value_us)
4795 continue; /* skip this one: path not validated */
4796 for (struct Queue *queue = nh->queue_head; NULL != queue;
4797 queue = queue->next_neighbour)
4798 if ((GNUNET_YES == queue->idle) &&
4799 (queue->validated_until.abs_value_us > now.abs_value_us))
4800 schedule_transmit_on_queue(queue,
4801 GNUNET_SCHEDULER_PRIORITY_BACKGROUND);
4802 }
4803 } 4854 }
4855 }
4804} 4856}
4805 4857
4806 4858
@@ -4811,7 +4863,7 @@ check_vl_transmission(struct VirtualLink *vl)
4811 * @param obm the send message that was sent 4863 * @param obm the send message that was sent
4812 */ 4864 */
4813static void 4865static void
4814handle_client_send(void *cls, const struct OutboundMessage *obm) 4866handle_client_send (void *cls, const struct OutboundMessage *obm)
4815{ 4867{
4816 struct TransportClient *tc = cls; 4868 struct TransportClient *tc = cls;
4817 struct PendingMessage *pm; 4869 struct PendingMessage *pm;
@@ -4820,46 +4872,46 @@ handle_client_send(void *cls, const struct OutboundMessage *obm)
4820 struct VirtualLink *vl; 4872 struct VirtualLink *vl;
4821 enum GNUNET_MQ_PriorityPreferences pp; 4873 enum GNUNET_MQ_PriorityPreferences pp;
4822 4874
4823 GNUNET_assert(CT_CORE == tc->type); 4875 GNUNET_assert (CT_CORE == tc->type);
4824 obmm = (const struct GNUNET_MessageHeader *)&obm[1]; 4876 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
4825 bytes_msg = ntohs(obmm->size); 4877 bytes_msg = ntohs (obmm->size);
4826 pp = (enum GNUNET_MQ_PriorityPreferences)ntohl(obm->priority); 4878 pp = (enum GNUNET_MQ_PriorityPreferences) ntohl (obm->priority);
4827 vl = lookup_virtual_link(&obm->peer); 4879 vl = lookup_virtual_link (&obm->peer);
4828 if (NULL == vl) 4880 if (NULL == vl)
4829 { 4881 {
4830 /* Failure: don't have this peer as a neighbour (anymore). 4882 /* Failure: don't have this peer as a neighbour (anymore).
4831 Might have gone down asynchronously, so this is NOT 4883 Might have gone down asynchronously, so this is NOT
4832 a protocol violation by CORE. Still count the event, 4884 a protocol violation by CORE. Still count the event,
4833 as this should be rare. */ 4885 as this should be rare. */
4834 GNUNET_SERVICE_client_continue(tc->client); 4886 GNUNET_SERVICE_client_continue (tc->client);
4835 GNUNET_STATISTICS_update(GST_stats, 4887 GNUNET_STATISTICS_update (GST_stats,
4836 "# messages dropped (neighbour unknown)", 4888 "# messages dropped (neighbour unknown)",
4837 1, 4889 1,
4838 GNUNET_NO); 4890 GNUNET_NO);
4839 return; 4891 return;
4840 } 4892 }
4841 4893
4842 pm = GNUNET_malloc(sizeof(struct PendingMessage) + bytes_msg); 4894 pm = GNUNET_malloc (sizeof(struct PendingMessage) + bytes_msg);
4843 pm->logging_uuid = logging_uuid_gen++; 4895 pm->logging_uuid = logging_uuid_gen++;
4844 pm->prefs = pp; 4896 pm->prefs = pp;
4845 pm->client = tc; 4897 pm->client = tc;
4846 pm->vl = vl; 4898 pm->vl = vl;
4847 pm->bytes_msg = bytes_msg; 4899 pm->bytes_msg = bytes_msg;
4848 memcpy(&pm[1], obmm, bytes_msg); 4900 memcpy (&pm[1], obmm, bytes_msg);
4849 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4850 "Sending %u bytes as <%llu> to %s\n", 4902 "Sending %u bytes as <%llu> to %s\n",
4851 bytes_msg, 4903 bytes_msg,
4852 pm->logging_uuid, 4904 pm->logging_uuid,
4853 GNUNET_i2s(&obm->peer)); 4905 GNUNET_i2s (&obm->peer));
4854 GNUNET_CONTAINER_MDLL_insert(client, 4906 GNUNET_CONTAINER_MDLL_insert (client,
4855 tc->details.core.pending_msg_head, 4907 tc->details.core.pending_msg_head,
4856 tc->details.core.pending_msg_tail, 4908 tc->details.core.pending_msg_tail,
4857 pm); 4909 pm);
4858 GNUNET_CONTAINER_MDLL_insert(vl, 4910 GNUNET_CONTAINER_MDLL_insert (vl,
4859 vl->pending_msg_head, 4911 vl->pending_msg_head,
4860 vl->pending_msg_tail, 4912 vl->pending_msg_tail,
4861 pm); 4913 pm);
4862 check_vl_transmission(vl); 4914 check_vl_transmission (vl);
4863} 4915}
4864 4916
4865 4917
@@ -4873,39 +4925,40 @@ handle_client_send(void *cls, const struct OutboundMessage *obm)
4873 * @param cb the send message that was sent 4925 * @param cb the send message that was sent
4874 */ 4926 */
4875static void 4927static void
4876handle_communicator_backchannel( 4928handle_communicator_backchannel (
4877 void *cls, 4929 void *cls,
4878 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 4930 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
4879{ 4931{
4880 struct TransportClient *tc = cls; 4932 struct TransportClient *tc = cls;
4881 const struct GNUNET_MessageHeader *inbox = 4933 const struct GNUNET_MessageHeader *inbox =
4882 (const struct GNUNET_MessageHeader *)&cb[1]; 4934 (const struct GNUNET_MessageHeader *) &cb[1];
4883 uint16_t isize = ntohs(inbox->size); 4935 uint16_t isize = ntohs (inbox->size);
4884 const char *is = ((const char *)&cb[1]) + isize; 4936 const char *is = ((const char *) &cb[1]) + isize;
4885 char 4937 char
4886 mbuf[isize + 4938 mbuf[isize
4887 sizeof(struct TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN; 4939 + sizeof(struct
4940 TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN;
4888 struct TransportBackchannelEncapsulationMessage *be = 4941 struct TransportBackchannelEncapsulationMessage *be =
4889 (struct TransportBackchannelEncapsulationMessage *)mbuf; 4942 (struct TransportBackchannelEncapsulationMessage *) mbuf;
4890 4943
4891 /* 0-termination of 'is' was checked already in 4944 /* 0-termination of 'is' was checked already in
4892 #check_communicator_backchannel() */ 4945 #check_communicator_backchannel() */
4893 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 4946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4894 "Preparing backchannel transmission to %s:%s of type %u\n", 4947 "Preparing backchannel transmission to %s:%s of type %u\n",
4895 GNUNET_i2s(&cb->pid), 4948 GNUNET_i2s (&cb->pid),
4896 is, 4949 is,
4897 ntohs(inbox->size)); 4950 ntohs (inbox->size));
4898 /* encapsulate and encrypt message */ 4951 /* encapsulate and encrypt message */
4899 be->header.type = 4952 be->header.type =
4900 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); 4953 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION);
4901 be->header.size = htons(sizeof(mbuf)); 4954 be->header.size = htons (sizeof(mbuf));
4902 memcpy(&be[1], inbox, isize); 4955 memcpy (&be[1], inbox, isize);
4903 memcpy(&mbuf[sizeof(struct TransportBackchannelEncapsulationMessage) + 4956 memcpy (&mbuf[sizeof(struct TransportBackchannelEncapsulationMessage)
4904 isize], 4957 + isize],
4905 is, 4958 is,
4906 strlen(is) + 1); 4959 strlen (is) + 1);
4907 route_control_message_without_fc(&cb->pid, &be->header, RMO_DV_ALLOWED); 4960 route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED);
4908 GNUNET_SERVICE_client_continue(tc->client); 4961 GNUNET_SERVICE_client_continue (tc->client);
4909} 4962}
4910 4963
4911 4964
@@ -4917,17 +4970,17 @@ handle_communicator_backchannel(
4917 * @return #GNUNET_OK if message is well-formed 4970 * @return #GNUNET_OK if message is well-formed
4918 */ 4971 */
4919static int 4972static int
4920check_add_address(void *cls, 4973check_add_address (void *cls,
4921 const struct GNUNET_TRANSPORT_AddAddressMessage *aam) 4974 const struct GNUNET_TRANSPORT_AddAddressMessage *aam)
4922{ 4975{
4923 struct TransportClient *tc = cls; 4976 struct TransportClient *tc = cls;
4924 4977
4925 if (CT_COMMUNICATOR != tc->type) 4978 if (CT_COMMUNICATOR != tc->type)
4926 { 4979 {
4927 GNUNET_break(0); 4980 GNUNET_break (0);
4928 return GNUNET_SYSERR; 4981 return GNUNET_SYSERR;
4929 } 4982 }
4930 GNUNET_MQ_check_zero_termination(aam); 4983 GNUNET_MQ_check_zero_termination (aam);
4931 return GNUNET_OK; 4984 return GNUNET_OK;
4932} 4985}
4933 4986
@@ -4938,7 +4991,7 @@ check_add_address(void *cls,
4938 * @param cls an `struct AddressListEntry *` 4991 * @param cls an `struct AddressListEntry *`
4939 */ 4992 */
4940static void 4993static void
4941store_pi(void *cls); 4994store_pi (void *cls);
4942 4995
4943 4996
4944/** 4997/**
@@ -4948,26 +5001,26 @@ store_pi(void *cls);
4948 * @param success #GNUNET_YES if peerstore was successful 5001 * @param success #GNUNET_YES if peerstore was successful
4949 */ 5002 */
4950static void 5003static void
4951peerstore_store_own_cb(void *cls, int success) 5004peerstore_store_own_cb (void *cls, int success)
4952{ 5005{
4953 struct AddressListEntry *ale = cls; 5006 struct AddressListEntry *ale = cls;
4954 5007
4955 ale->sc = NULL; 5008 ale->sc = NULL;
4956 if (GNUNET_YES != success) 5009 if (GNUNET_YES != success)
4957 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 5010 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
4958 "Failed to store our own address `%s' in peerstore!\n", 5011 "Failed to store our own address `%s' in peerstore!\n",
4959 ale->address); 5012 ale->address);
4960 else 5013 else
4961 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4962 "Successfully stored our own address `%s' in peerstore!\n", 5015 "Successfully stored our own address `%s' in peerstore!\n",
4963 ale->address); 5016 ale->address);
4964 /* refresh period is 1/4 of expiration time, that should be plenty 5017 /* refresh period is 1/4 of expiration time, that should be plenty
4965 without being excessive. */ 5018 without being excessive. */
4966 ale->st = 5019 ale->st =
4967 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(ale->expiration, 5020 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration,
4968 4ULL), 5021 4ULL),
4969 &store_pi, 5022 &store_pi,
4970 ale); 5023 ale);
4971} 5024}
4972 5025
4973 5026
@@ -4977,7 +5030,7 @@ peerstore_store_own_cb(void *cls, int success)
4977 * @param cls an `struct AddressListEntry *` 5030 * @param cls an `struct AddressListEntry *`
4978 */ 5031 */
4979static void 5032static void
4980store_pi(void *cls) 5033store_pi (void *cls)
4981{ 5034{
4982 struct AddressListEntry *ale = cls; 5035 struct AddressListEntry *ale = cls;
4983 void *addr; 5036 void *addr;
@@ -4985,36 +5038,36 @@ store_pi(void *cls)
4985 struct GNUNET_TIME_Absolute expiration; 5038 struct GNUNET_TIME_Absolute expiration;
4986 5039
4987 ale->st = NULL; 5040 ale->st = NULL;
4988 expiration = GNUNET_TIME_relative_to_absolute(ale->expiration); 5041 expiration = GNUNET_TIME_relative_to_absolute (ale->expiration);
4989 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4990 "Storing our address `%s' in peerstore until %s!\n", 5043 "Storing our address `%s' in peerstore until %s!\n",
4991 ale->address, 5044 ale->address,
4992 GNUNET_STRINGS_absolute_time_to_string(expiration)); 5045 GNUNET_STRINGS_absolute_time_to_string (expiration));
4993 GNUNET_HELLO_sign_address(ale->address, 5046 GNUNET_HELLO_sign_address (ale->address,
4994 ale->nt, 5047 ale->nt,
4995 hello_mono_time, 5048 hello_mono_time,
4996 GST_my_private_key, 5049 GST_my_private_key,
4997 &addr, 5050 &addr,
4998 &addr_len); 5051 &addr_len);
4999 ale->sc = GNUNET_PEERSTORE_store(peerstore, 5052 ale->sc = GNUNET_PEERSTORE_store (peerstore,
5000 "transport", 5053 "transport",
5001 &GST_my_identity, 5054 &GST_my_identity,
5002 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, 5055 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
5003 addr, 5056 addr,
5004 addr_len, 5057 addr_len,
5005 expiration, 5058 expiration,
5006 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, 5059 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
5007 &peerstore_store_own_cb, 5060 &peerstore_store_own_cb,
5008 ale); 5061 ale);
5009 GNUNET_free(addr); 5062 GNUNET_free (addr);
5010 if (NULL == ale->sc) 5063 if (NULL == ale->sc)
5011 { 5064 {
5012 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 5065 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5013 "Failed to store our address `%s' with peerstore\n", 5066 "Failed to store our address `%s' with peerstore\n",
5014 ale->address); 5067 ale->address);
5015 ale->st = 5068 ale->st =
5016 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &store_pi, ale); 5069 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &store_pi, ale);
5017 } 5070 }
5018} 5071}
5019 5072
5020 5073
@@ -5025,30 +5078,30 @@ store_pi(void *cls)
5025 * @param aam the send message that was sent 5078 * @param aam the send message that was sent
5026 */ 5079 */
5027static void 5080static void
5028handle_add_address(void *cls, 5081handle_add_address (void *cls,
5029 const struct GNUNET_TRANSPORT_AddAddressMessage *aam) 5082 const struct GNUNET_TRANSPORT_AddAddressMessage *aam)
5030{ 5083{
5031 struct TransportClient *tc = cls; 5084 struct TransportClient *tc = cls;
5032 struct AddressListEntry *ale; 5085 struct AddressListEntry *ale;
5033 size_t slen; 5086 size_t slen;
5034 5087
5035 /* 0-termination of &aam[1] was checked in #check_add_address */ 5088 /* 0-termination of &aam[1] was checked in #check_add_address */
5036 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5037 "Communicator added address `%s'!\n", 5090 "Communicator added address `%s'!\n",
5038 (const char *)&aam[1]); 5091 (const char *) &aam[1]);
5039 slen = ntohs(aam->header.size) - sizeof(*aam); 5092 slen = ntohs (aam->header.size) - sizeof(*aam);
5040 ale = GNUNET_malloc(sizeof(struct AddressListEntry) + slen); 5093 ale = GNUNET_malloc (sizeof(struct AddressListEntry) + slen);
5041 ale->tc = tc; 5094 ale->tc = tc;
5042 ale->address = (const char *)&ale[1]; 5095 ale->address = (const char *) &ale[1];
5043 ale->expiration = GNUNET_TIME_relative_ntoh(aam->expiration); 5096 ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration);
5044 ale->aid = aam->aid; 5097 ale->aid = aam->aid;
5045 ale->nt = (enum GNUNET_NetworkType)ntohl(aam->nt); 5098 ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt);
5046 memcpy(&ale[1], &aam[1], slen); 5099 memcpy (&ale[1], &aam[1], slen);
5047 GNUNET_CONTAINER_DLL_insert(tc->details.communicator.addr_head, 5100 GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head,
5048 tc->details.communicator.addr_tail, 5101 tc->details.communicator.addr_tail,
5049 ale); 5102 ale);
5050 ale->st = GNUNET_SCHEDULER_add_now(&store_pi, ale); 5103 ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale);
5051 GNUNET_SERVICE_client_continue(tc->client); 5104 GNUNET_SERVICE_client_continue (tc->client);
5052} 5105}
5053 5106
5054 5107
@@ -5059,34 +5112,34 @@ handle_add_address(void *cls,
5059 * @param dam the send message that was sent 5112 * @param dam the send message that was sent
5060 */ 5113 */
5061static void 5114static void
5062handle_del_address(void *cls, 5115handle_del_address (void *cls,
5063 const struct GNUNET_TRANSPORT_DelAddressMessage *dam) 5116 const struct GNUNET_TRANSPORT_DelAddressMessage *dam)
5064{ 5117{
5065 struct TransportClient *tc = cls; 5118 struct TransportClient *tc = cls;
5066 struct AddressListEntry *alen; 5119 struct AddressListEntry *alen;
5067 5120
5068 if (CT_COMMUNICATOR != tc->type) 5121 if (CT_COMMUNICATOR != tc->type)
5069 { 5122 {
5070 GNUNET_break(0); 5123 GNUNET_break (0);
5071 GNUNET_SERVICE_client_drop(tc->client); 5124 GNUNET_SERVICE_client_drop (tc->client);
5072 return; 5125 return;
5073 } 5126 }
5074 for (struct AddressListEntry *ale = tc->details.communicator.addr_head; 5127 for (struct AddressListEntry *ale = tc->details.communicator.addr_head;
5075 NULL != ale; 5128 NULL != ale;
5076 ale = alen) 5129 ale = alen)
5077 { 5130 {
5078 alen = ale->next; 5131 alen = ale->next;
5079 if (dam->aid != ale->aid) 5132 if (dam->aid != ale->aid)
5080 continue; 5133 continue;
5081 GNUNET_assert(ale->tc == tc); 5134 GNUNET_assert (ale->tc == tc);
5082 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5083 "Communicator deleted address `%s'!\n", 5136 "Communicator deleted address `%s'!\n",
5084 ale->address); 5137 ale->address);
5085 free_address_list_entry(ale); 5138 free_address_list_entry (ale);
5086 GNUNET_SERVICE_client_continue(tc->client); 5139 GNUNET_SERVICE_client_continue (tc->client);
5087 } 5140 }
5088 GNUNET_break(0); 5141 GNUNET_break (0);
5089 GNUNET_SERVICE_client_drop(tc->client); 5142 GNUNET_SERVICE_client_drop (tc->client);
5090} 5143}
5091 5144
5092 5145
@@ -5098,8 +5151,8 @@ handle_del_address(void *cls,
5098 * @param msg message to demultiplex 5151 * @param msg message to demultiplex
5099 */ 5152 */
5100static void 5153static void
5101demultiplex_with_cmc(struct CommunicatorMessageContext *cmc, 5154demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
5102 const struct GNUNET_MessageHeader *msg); 5155 const struct GNUNET_MessageHeader *msg);
5103 5156
5104 5157
5105/** 5158/**
@@ -5110,23 +5163,23 @@ demultiplex_with_cmc(struct CommunicatorMessageContext *cmc,
5110 * @param cls a `struct CoreSentContext` 5163 * @param cls a `struct CoreSentContext`
5111 */ 5164 */
5112static void 5165static void
5113core_env_sent_cb(void *cls) 5166core_env_sent_cb (void *cls)
5114{ 5167{
5115 struct CoreSentContext *ctx = cls; 5168 struct CoreSentContext *ctx = cls;
5116 struct VirtualLink *vl = ctx->vl; 5169 struct VirtualLink *vl = ctx->vl;
5117 5170
5118 if (NULL == vl) 5171 if (NULL == vl)
5119 { 5172 {
5120 /* lost the link in the meantime, ignore */ 5173 /* lost the link in the meantime, ignore */
5121 GNUNET_free(ctx); 5174 GNUNET_free (ctx);
5122 return; 5175 return;
5123 } 5176 }
5124 GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, ctx); 5177 GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, ctx);
5125 GNUNET_assert(vl->incoming_fc_window_size_ram >= ctx->size); 5178 GNUNET_assert (vl->incoming_fc_window_size_ram >= ctx->size);
5126 vl->incoming_fc_window_size_ram -= ctx->size; 5179 vl->incoming_fc_window_size_ram -= ctx->size;
5127 vl->incoming_fc_window_size_used += ctx->isize; 5180 vl->incoming_fc_window_size_used += ctx->isize;
5128 consider_sending_fc(vl); 5181 consider_sending_fc (vl);
5129 GNUNET_free(ctx); 5182 GNUNET_free (ctx);
5130} 5183}
5131 5184
5132 5185
@@ -5139,109 +5192,109 @@ core_env_sent_cb(void *cls)
5139 * @param mh the message that was received 5192 * @param mh the message that was received
5140 */ 5193 */
5141static void 5194static void
5142handle_raw_message(void *cls, const struct GNUNET_MessageHeader *mh) 5195handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5143{ 5196{
5144 struct CommunicatorMessageContext *cmc = cls; 5197 struct CommunicatorMessageContext *cmc = cls;
5145 struct VirtualLink *vl; 5198 struct VirtualLink *vl;
5146 uint16_t size = ntohs(mh->size); 5199 uint16_t size = ntohs (mh->size);
5147 int have_core; 5200 int have_core;
5148 5201
5149 if ((size > UINT16_MAX - sizeof(struct InboundMessage)) || 5202 if ((size > UINT16_MAX - sizeof(struct InboundMessage)) ||
5150 (size < sizeof(struct GNUNET_MessageHeader))) 5203 (size < sizeof(struct GNUNET_MessageHeader)))
5151 { 5204 {
5152 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 5205 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
5153 5206
5154 GNUNET_break(0); 5207 GNUNET_break (0);
5155 finish_cmc_handling(cmc); 5208 finish_cmc_handling (cmc);
5156 GNUNET_SERVICE_client_drop(client); 5209 GNUNET_SERVICE_client_drop (client);
5157 return; 5210 return;
5158 } 5211 }
5159 vl = lookup_virtual_link(&cmc->im.sender); 5212 vl = lookup_virtual_link (&cmc->im.sender);
5160 if (NULL == vl) 5213 if (NULL == vl)
5161 { 5214 {
5162 /* FIXME: sender is giving us messages for CORE but we don't have 5215 /* FIXME: sender is giving us messages for CORE but we don't have
5163 the link up yet! I *suspect* this can happen right now (i.e. 5216 the link up yet! I *suspect* this can happen right now (i.e.
5164 sender has verified us, but we didn't verify sender), but if 5217 sender has verified us, but we didn't verify sender), but if
5165 we pass this on, CORE would be confused (link down, messages 5218 we pass this on, CORE would be confused (link down, messages
5166 arrive). We should investigate more if this happens often, 5219 arrive). We should investigate more if this happens often,
5167 or in a persistent manner, and possibly do "something" about 5220 or in a persistent manner, and possibly do "something" about
5168 it. Thus logging as error for now. */ 5221 it. Thus logging as error for now. */
5169 GNUNET_break_op(0); 5222 GNUNET_break_op (0);
5170 GNUNET_STATISTICS_update(GST_stats, 5223 GNUNET_STATISTICS_update (GST_stats,
5171 "# CORE messages droped (virtual link still down)", 5224 "# CORE messages droped (virtual link still down)",
5172 1, 5225 1,
5173 GNUNET_NO); 5226 GNUNET_NO);
5174 5227
5175 finish_cmc_handling(cmc); 5228 finish_cmc_handling (cmc);
5176 return; 5229 return;
5177 } 5230 }
5178 if (vl->incoming_fc_window_size_ram > UINT_MAX - size) 5231 if (vl->incoming_fc_window_size_ram > UINT_MAX - size)
5179 { 5232 {
5180 GNUNET_STATISTICS_update(GST_stats, 5233 GNUNET_STATISTICS_update (GST_stats,
5181 "# CORE messages droped (FC arithmetic overflow)", 5234 "# CORE messages droped (FC arithmetic overflow)",
5182 1, 5235 1,
5183 GNUNET_NO); 5236 GNUNET_NO);
5184 5237
5185 finish_cmc_handling(cmc); 5238 finish_cmc_handling (cmc);
5186 return; 5239 return;
5187 } 5240 }
5188 if (vl->incoming_fc_window_size_ram + size > vl->available_fc_window_size) 5241 if (vl->incoming_fc_window_size_ram + size > vl->available_fc_window_size)
5189 { 5242 {
5190 GNUNET_STATISTICS_update(GST_stats, 5243 GNUNET_STATISTICS_update (GST_stats,
5191 "# CORE messages droped (FC window overflow)", 5244 "# CORE messages droped (FC window overflow)",
5192 1, 5245 1,
5193 GNUNET_NO); 5246 GNUNET_NO);
5194 finish_cmc_handling(cmc); 5247 finish_cmc_handling (cmc);
5195 return; 5248 return;
5196 } 5249 }
5197 5250
5198 /* Forward to all CORE clients */ 5251 /* Forward to all CORE clients */
5199 have_core = GNUNET_NO; 5252 have_core = GNUNET_NO;
5200 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 5253 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
5201 { 5254 {
5202 struct GNUNET_MQ_Envelope *env; 5255 struct GNUNET_MQ_Envelope *env;
5203 struct InboundMessage *im; 5256 struct InboundMessage *im;
5204 struct CoreSentContext *ctx; 5257 struct CoreSentContext *ctx;
5205 5258
5206 if (CT_CORE != tc->type) 5259 if (CT_CORE != tc->type)
5207 continue; 5260 continue;
5208 vl->incoming_fc_window_size_ram += size; 5261 vl->incoming_fc_window_size_ram += size;
5209 env = GNUNET_MQ_msg_extra(im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 5262 env = GNUNET_MQ_msg_extra (im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
5210 ctx = GNUNET_new(struct CoreSentContext); 5263 ctx = GNUNET_new (struct CoreSentContext);
5211 ctx->vl = vl; 5264 ctx->vl = vl;
5212 ctx->size = size; 5265 ctx->size = size;
5213 ctx->isize = (GNUNET_NO == have_core) ? size : 0; 5266 ctx->isize = (GNUNET_NO == have_core) ? size : 0;
5214 have_core = GNUNET_YES; 5267 have_core = GNUNET_YES;
5215 GNUNET_CONTAINER_DLL_insert(vl->csc_head, vl->csc_tail, ctx); 5268 GNUNET_CONTAINER_DLL_insert (vl->csc_head, vl->csc_tail, ctx);
5216 GNUNET_MQ_notify_sent(env, &core_env_sent_cb, ctx); 5269 GNUNET_MQ_notify_sent (env, &core_env_sent_cb, ctx);
5217 im->peer = cmc->im.sender; 5270 im->peer = cmc->im.sender;
5218 memcpy(&im[1], mh, size); 5271 memcpy (&im[1], mh, size);
5219 GNUNET_MQ_send(tc->mq, env); 5272 GNUNET_MQ_send (tc->mq, env);
5220 vl->core_recv_window--; 5273 vl->core_recv_window--;
5221 } 5274 }
5222 if (GNUNET_NO == have_core) 5275 if (GNUNET_NO == have_core)
5223 { 5276 {
5224 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 5277 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5225 "Dropped message to CORE: no CORE client connected!\n"); 5278 "Dropped message to CORE: no CORE client connected!\n");
5226 /* Nevertheless, count window as used, as it is from the 5279 /* Nevertheless, count window as used, as it is from the
5227 perspective of the other peer! */ 5280 perspective of the other peer! */
5228 vl->incoming_fc_window_size_used += size; 5281 vl->incoming_fc_window_size_used += size;
5229 /* TODO-M1 */ 5282 /* TODO-M1 */
5230 finish_cmc_handling(cmc); 5283 finish_cmc_handling (cmc);
5231 return; 5284 return;
5232 } 5285 }
5233 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5234 "Delivered message from %s of type %u to CORE\n", 5287 "Delivered message from %s of type %u to CORE\n",
5235 GNUNET_i2s(&cmc->im.sender), 5288 GNUNET_i2s (&cmc->im.sender),
5236 ntohs(mh->type)); 5289 ntohs (mh->type));
5237 if (vl->core_recv_window > 0) 5290 if (vl->core_recv_window > 0)
5238 { 5291 {
5239 finish_cmc_handling(cmc); 5292 finish_cmc_handling (cmc);
5240 return; 5293 return;
5241 } 5294 }
5242 /* Wait with calling #finish_cmc_handling(cmc) until the message 5295 /* Wait with calling #finish_cmc_handling(cmc) until the message
5243 was processed by CORE MQs (for CORE flow control)! */ 5296 was processed by CORE MQs (for CORE flow control)! */
5244 GNUNET_CONTAINER_DLL_insert(vl->cmc_head, vl->cmc_tail, cmc); 5297 GNUNET_CONTAINER_DLL_insert (vl->cmc_head, vl->cmc_tail, cmc);
5245} 5298}
5246 5299
5247 5300
@@ -5253,27 +5306,27 @@ handle_raw_message(void *cls, const struct GNUNET_MessageHeader *mh)
5253 * @return #GNUNET_YES if message is well-formed 5306 * @return #GNUNET_YES if message is well-formed
5254 */ 5307 */
5255static int 5308static int
5256check_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb) 5309check_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
5257{ 5310{
5258 uint16_t size = ntohs(fb->header.size); 5311 uint16_t size = ntohs (fb->header.size);
5259 uint16_t bsize = size - sizeof(*fb); 5312 uint16_t bsize = size - sizeof(*fb);
5260 5313
5261 (void)cls; 5314 (void) cls;
5262 if (0 == bsize) 5315 if (0 == bsize)
5263 { 5316 {
5264 GNUNET_break_op(0); 5317 GNUNET_break_op (0);
5265 return GNUNET_SYSERR; 5318 return GNUNET_SYSERR;
5266 } 5319 }
5267 if (bsize + ntohs(fb->frag_off) > ntohs(fb->msg_size)) 5320 if (bsize + ntohs (fb->frag_off) > ntohs (fb->msg_size))
5268 { 5321 {
5269 GNUNET_break_op(0); 5322 GNUNET_break_op (0);
5270 return GNUNET_SYSERR; 5323 return GNUNET_SYSERR;
5271 } 5324 }
5272 if (ntohs(fb->frag_off) >= ntohs(fb->msg_size)) 5325 if (ntohs (fb->frag_off) >= ntohs (fb->msg_size))
5273 { 5326 {
5274 GNUNET_break_op(0); 5327 GNUNET_break_op (0);
5275 return GNUNET_SYSERR; 5328 return GNUNET_SYSERR;
5276 } 5329 }
5277 return GNUNET_YES; 5330 return GNUNET_YES;
5278} 5331}
5279 5332
@@ -5284,16 +5337,16 @@ check_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
5284 * @param cls a `struct AcknowledgementCummulator *` 5337 * @param cls a `struct AcknowledgementCummulator *`
5285 */ 5338 */
5286static void 5339static void
5287destroy_ack_cummulator(void *cls) 5340destroy_ack_cummulator (void *cls)
5288{ 5341{
5289 struct AcknowledgementCummulator *ac = cls; 5342 struct AcknowledgementCummulator *ac = cls;
5290 5343
5291 ac->task = NULL; 5344 ac->task = NULL;
5292 GNUNET_assert(0 == ac->num_acks); 5345 GNUNET_assert (0 == ac->num_acks);
5293 GNUNET_assert( 5346 GNUNET_assert (
5294 GNUNET_YES == 5347 GNUNET_YES ==
5295 GNUNET_CONTAINER_multipeermap_remove(ack_cummulators, &ac->target, ac)); 5348 GNUNET_CONTAINER_multipeermap_remove (ack_cummulators, &ac->target, ac));
5296 GNUNET_free(ac); 5349 GNUNET_free (ac);
5297} 5350}
5298 5351
5299 5352
@@ -5303,39 +5356,39 @@ destroy_ack_cummulator(void *cls)
5303 * @param cls a `struct AcknowledgementCummulator *` 5356 * @param cls a `struct AcknowledgementCummulator *`
5304 */ 5357 */
5305static void 5358static void
5306transmit_cummulative_ack_cb(void *cls) 5359transmit_cummulative_ack_cb (void *cls)
5307{ 5360{
5308 struct AcknowledgementCummulator *ac = cls; 5361 struct AcknowledgementCummulator *ac = cls;
5309 char buf[sizeof(struct TransportReliabilityAckMessage) + 5362 char buf[sizeof(struct TransportReliabilityAckMessage)
5310 ac->ack_counter * 5363 + ac->ack_counter
5311 sizeof(struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN; 5364 * sizeof(struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN;
5312 struct TransportReliabilityAckMessage *ack = 5365 struct TransportReliabilityAckMessage *ack =
5313 (struct TransportReliabilityAckMessage *)buf; 5366 (struct TransportReliabilityAckMessage *) buf;
5314 struct TransportCummulativeAckPayloadP *ap; 5367 struct TransportCummulativeAckPayloadP *ap;
5315 5368
5316 ac->task = NULL; 5369 ac->task = NULL;
5317 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5318 "Sending ACK with %u components to %s\n", 5371 "Sending ACK with %u components to %s\n",
5319 ac->ack_counter, 5372 ac->ack_counter,
5320 GNUNET_i2s(&ac->target)); 5373 GNUNET_i2s (&ac->target));
5321 GNUNET_assert(0 < ac->ack_counter); 5374 GNUNET_assert (0 < ac->ack_counter);
5322 ack->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); 5375 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK);
5323 ack->header.size = 5376 ack->header.size =
5324 htons(sizeof(*ack) + 5377 htons (sizeof(*ack)
5325 ac->ack_counter * sizeof(struct TransportCummulativeAckPayloadP)); 5378 + ac->ack_counter * sizeof(struct TransportCummulativeAckPayloadP));
5326 ack->ack_counter = htonl(ac->ack_counter++); 5379 ack->ack_counter = htonl (ac->ack_counter++);
5327 ap = (struct TransportCummulativeAckPayloadP *)&ack[1]; 5380 ap = (struct TransportCummulativeAckPayloadP *) &ack[1];
5328 for (unsigned int i = 0; i < ac->ack_counter; i++) 5381 for (unsigned int i = 0; i < ac->ack_counter; i++)
5329 { 5382 {
5330 ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid; 5383 ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid;
5331 ap[i].ack_delay = GNUNET_TIME_relative_hton( 5384 ap[i].ack_delay = GNUNET_TIME_relative_hton (
5332 GNUNET_TIME_absolute_get_duration(ac->ack_uuids[i].receive_time)); 5385 GNUNET_TIME_absolute_get_duration (ac->ack_uuids[i].receive_time));
5333 } 5386 }
5334 route_control_message_without_fc(&ac->target, &ack->header, RMO_DV_ALLOWED); 5387 route_control_message_without_fc (&ac->target, &ack->header, RMO_DV_ALLOWED);
5335 ac->num_acks = 0; 5388 ac->num_acks = 0;
5336 ac->task = GNUNET_SCHEDULER_add_delayed(ACK_CUMMULATOR_TIMEOUT, 5389 ac->task = GNUNET_SCHEDULER_add_delayed (ACK_CUMMULATOR_TIMEOUT,
5337 &destroy_ack_cummulator, 5390 &destroy_ack_cummulator,
5338 ac); 5391 ac);
5339} 5392}
5340 5393
5341 5394
@@ -5348,55 +5401,56 @@ transmit_cummulative_ack_cb(void *cls)
5348 * @param max_delay how long can the ACK wait 5401 * @param max_delay how long can the ACK wait
5349 */ 5402 */
5350static void 5403static void
5351cummulative_ack(const struct GNUNET_PeerIdentity *pid, 5404cummulative_ack (const struct GNUNET_PeerIdentity *pid,
5352 const struct AcknowledgementUUIDP *ack_uuid, 5405 const struct AcknowledgementUUIDP *ack_uuid,
5353 struct GNUNET_TIME_Absolute max_delay) 5406 struct GNUNET_TIME_Absolute max_delay)
5354{ 5407{
5355 struct AcknowledgementCummulator *ac; 5408 struct AcknowledgementCummulator *ac;
5356 5409
5357 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5358 "Scheduling ACK %s for transmission to %s\n", 5411 "Scheduling ACK %s for transmission to %s\n",
5359 GNUNET_uuid2s(&ack_uuid->value), 5412 GNUNET_uuid2s (&ack_uuid->value),
5360 GNUNET_i2s(pid)); 5413 GNUNET_i2s (pid));
5361 ac = GNUNET_CONTAINER_multipeermap_get(ack_cummulators, pid); 5414 ac = GNUNET_CONTAINER_multipeermap_get (ack_cummulators, pid);
5362 if (NULL == ac) 5415 if (NULL == ac)
5363 { 5416 {
5364 ac = GNUNET_new(struct AcknowledgementCummulator); 5417 ac = GNUNET_new (struct AcknowledgementCummulator);
5365 ac->target = *pid; 5418 ac->target = *pid;
5366 ac->min_transmission_time = max_delay; 5419 ac->min_transmission_time = max_delay;
5367 GNUNET_assert(GNUNET_YES == 5420 GNUNET_assert (GNUNET_YES ==
5368 GNUNET_CONTAINER_multipeermap_put( 5421 GNUNET_CONTAINER_multipeermap_put (
5369 ack_cummulators, 5422 ack_cummulators,
5370 &ac->target, 5423 &ac->target,
5371 ac, 5424 ac,
5372 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 5425 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
5373 } 5426 }
5374 else 5427 else
5428 {
5429 if (MAX_CUMMULATIVE_ACKS == ac->num_acks)
5375 { 5430 {
5376 if (MAX_CUMMULATIVE_ACKS == ac->num_acks) 5431 /* must run immediately, ack buffer full! */
5377 { 5432 GNUNET_SCHEDULER_cancel (ac->task);
5378 /* must run immediately, ack buffer full! */ 5433 transmit_cummulative_ack_cb (ac);
5379 GNUNET_SCHEDULER_cancel(ac->task);
5380 transmit_cummulative_ack_cb(ac);
5381 }
5382 GNUNET_SCHEDULER_cancel(ac->task);
5383 ac->min_transmission_time =
5384 GNUNET_TIME_absolute_min(ac->min_transmission_time, max_delay);
5385 } 5434 }
5386 GNUNET_assert(ac->num_acks < MAX_CUMMULATIVE_ACKS); 5435 GNUNET_SCHEDULER_cancel (ac->task);
5387 ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get(); 5436 ac->min_transmission_time =
5437 GNUNET_TIME_absolute_min (ac->min_transmission_time, max_delay);
5438 }
5439 GNUNET_assert (ac->num_acks < MAX_CUMMULATIVE_ACKS);
5440 ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get ();
5388 ac->ack_uuids[ac->num_acks].ack_uuid = *ack_uuid; 5441 ac->ack_uuids[ac->num_acks].ack_uuid = *ack_uuid;
5389 ac->num_acks++; 5442 ac->num_acks++;
5390 ac->task = GNUNET_SCHEDULER_add_at(ac->min_transmission_time, 5443 ac->task = GNUNET_SCHEDULER_add_at (ac->min_transmission_time,
5391 &transmit_cummulative_ack_cb, 5444 &transmit_cummulative_ack_cb,
5392 ac); 5445 ac);
5393} 5446}
5394 5447
5395 5448
5396/** 5449/**
5397 * Closure for #find_by_message_uuid. 5450 * Closure for #find_by_message_uuid.
5398 */ 5451 */
5399struct FindByMessageUuidContext { 5452struct FindByMessageUuidContext
5453{
5400 /** 5454 /**
5401 * UUID to look for. 5455 * UUID to look for.
5402 */ 5456 */
@@ -5419,17 +5473,17 @@ struct FindByMessageUuidContext {
5419 * @return #GNUNET_YES if not found, #GNUNET_NO if found 5473 * @return #GNUNET_YES if not found, #GNUNET_NO if found
5420 */ 5474 */
5421static int 5475static int
5422find_by_message_uuid(void *cls, uint32_t key, void *value) 5476find_by_message_uuid (void *cls, uint32_t key, void *value)
5423{ 5477{
5424 struct FindByMessageUuidContext *fc = cls; 5478 struct FindByMessageUuidContext *fc = cls;
5425 struct ReassemblyContext *rc = value; 5479 struct ReassemblyContext *rc = value;
5426 5480
5427 (void)key; 5481 (void) key;
5428 if (0 == GNUNET_memcmp(&fc->message_uuid, &rc->msg_uuid)) 5482 if (0 == GNUNET_memcmp (&fc->message_uuid, &rc->msg_uuid))
5429 { 5483 {
5430 fc->rc = rc; 5484 fc->rc = rc;
5431 return GNUNET_NO; 5485 return GNUNET_NO;
5432 } 5486 }
5433 return GNUNET_YES; 5487 return GNUNET_YES;
5434} 5488}
5435 5489
@@ -5442,7 +5496,7 @@ find_by_message_uuid(void *cls, uint32_t key, void *value)
5442 * @param fb the message that was received 5496 * @param fb the message that was received
5443 */ 5497 */
5444static void 5498static void
5445handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb) 5499handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
5446{ 5500{
5447 struct CommunicatorMessageContext *cmc = cls; 5501 struct CommunicatorMessageContext *cmc = cls;
5448 struct Neighbour *n; 5502 struct Neighbour *n;
@@ -5455,142 +5509,142 @@ handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
5455 struct GNUNET_TIME_Relative cdelay; 5509 struct GNUNET_TIME_Relative cdelay;
5456 struct FindByMessageUuidContext fc; 5510 struct FindByMessageUuidContext fc;
5457 5511
5458 n = lookup_neighbour(&cmc->im.sender); 5512 n = lookup_neighbour (&cmc->im.sender);
5459 if (NULL == n) 5513 if (NULL == n)
5460 { 5514 {
5461 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 5515 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
5462 5516
5463 GNUNET_break(0); 5517 GNUNET_break (0);
5464 finish_cmc_handling(cmc); 5518 finish_cmc_handling (cmc);
5465 GNUNET_SERVICE_client_drop(client); 5519 GNUNET_SERVICE_client_drop (client);
5466 return; 5520 return;
5467 } 5521 }
5468 if (NULL == n->reassembly_map) 5522 if (NULL == n->reassembly_map)
5469 { 5523 {
5470 n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create(8); 5524 n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create (8);
5471 n->reassembly_heap = 5525 n->reassembly_heap =
5472 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 5526 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
5473 n->reassembly_timeout_task = 5527 n->reassembly_timeout_task =
5474 GNUNET_SCHEDULER_add_delayed(REASSEMBLY_EXPIRATION, 5528 GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION,
5475 &reassembly_cleanup_task, 5529 &reassembly_cleanup_task,
5476 n); 5530 n);
5477 } 5531 }
5478 msize = ntohs(fb->msg_size); 5532 msize = ntohs (fb->msg_size);
5479 fc.message_uuid = fb->msg_uuid; 5533 fc.message_uuid = fb->msg_uuid;
5480 fc.rc = NULL; 5534 fc.rc = NULL;
5481 (void)GNUNET_CONTAINER_multihashmap32_get_multiple(n->reassembly_map, 5535 (void) GNUNET_CONTAINER_multihashmap32_get_multiple (n->reassembly_map,
5482 fb->msg_uuid.uuid, 5536 fb->msg_uuid.uuid,
5483 &find_by_message_uuid, 5537 &find_by_message_uuid,
5484 &fc); 5538 &fc);
5485 if (NULL == (rc = fc.rc)) 5539 if (NULL == (rc = fc.rc))
5486 { 5540 {
5487 rc = GNUNET_malloc(sizeof(*rc) + msize + /* reassembly payload buffer */ 5541 rc = GNUNET_malloc (sizeof(*rc) + msize /* reassembly payload buffer */
5488 (msize + 7) / 8 * sizeof(uint8_t) /* bitfield */); 5542 + (msize + 7) / 8 * sizeof(uint8_t) /* bitfield */);
5489 rc->msg_uuid = fb->msg_uuid; 5543 rc->msg_uuid = fb->msg_uuid;
5490 rc->neighbour = n; 5544 rc->neighbour = n;
5491 rc->msg_size = msize; 5545 rc->msg_size = msize;
5492 rc->reassembly_timeout = 5546 rc->reassembly_timeout =
5493 GNUNET_TIME_relative_to_absolute(REASSEMBLY_EXPIRATION); 5547 GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION);
5494 rc->last_frag = GNUNET_TIME_absolute_get(); 5548 rc->last_frag = GNUNET_TIME_absolute_get ();
5495 rc->hn = GNUNET_CONTAINER_heap_insert(n->reassembly_heap, 5549 rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap,
5496 rc, 5550 rc,
5497 rc->reassembly_timeout.abs_value_us); 5551 rc->reassembly_timeout.abs_value_us);
5498 GNUNET_assert(GNUNET_OK == 5552 GNUNET_assert (GNUNET_OK ==
5499 GNUNET_CONTAINER_multihashmap32_put( 5553 GNUNET_CONTAINER_multihashmap32_put (
5500 n->reassembly_map, 5554 n->reassembly_map,
5501 rc->msg_uuid.uuid, 5555 rc->msg_uuid.uuid,
5502 rc, 5556 rc,
5503 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 5557 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
5504 target = (char *)&rc[1]; 5558 target = (char *) &rc[1];
5505 rc->bitfield = (uint8_t *)(target + rc->msg_size); 5559 rc->bitfield = (uint8_t *) (target + rc->msg_size);
5506 rc->msg_missing = rc->msg_size; 5560 rc->msg_missing = rc->msg_size;
5507 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5508 "Received fragment at offset %u/%u from %s for NEW message %u\n", 5562 "Received fragment at offset %u/%u from %s for NEW message %u\n",
5509 ntohs(fb->frag_off), 5563 ntohs (fb->frag_off),
5510 msize, 5564 msize,
5511 GNUNET_i2s(&cmc->im.sender), 5565 GNUNET_i2s (&cmc->im.sender),
5512 (unsigned int)fb->msg_uuid.uuid); 5566 (unsigned int) fb->msg_uuid.uuid);
5513 } 5567 }
5514 else 5568 else
5515 { 5569 {
5516 target = (char *)&rc[1]; 5570 target = (char *) &rc[1];
5517 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5518 "Received fragment at offset %u/%u from %s for message %u\n", 5572 "Received fragment at offset %u/%u from %s for message %u\n",
5519 ntohs(fb->frag_off), 5573 ntohs (fb->frag_off),
5520 msize, 5574 msize,
5521 GNUNET_i2s(&cmc->im.sender), 5575 GNUNET_i2s (&cmc->im.sender),
5522 (unsigned int)fb->msg_uuid.uuid); 5576 (unsigned int) fb->msg_uuid.uuid);
5523 } 5577 }
5524 if (msize != rc->msg_size) 5578 if (msize != rc->msg_size)
5525 { 5579 {
5526 GNUNET_break(0); 5580 GNUNET_break (0);
5527 finish_cmc_handling(cmc); 5581 finish_cmc_handling (cmc);
5528 return; 5582 return;
5529 } 5583 }
5530 5584
5531 /* reassemble */ 5585 /* reassemble */
5532 fsize = ntohs(fb->header.size) - sizeof(*fb); 5586 fsize = ntohs (fb->header.size) - sizeof(*fb);
5533 if (0 == fsize) 5587 if (0 == fsize)
5534 { 5588 {
5535 GNUNET_break(0); 5589 GNUNET_break (0);
5536 finish_cmc_handling(cmc); 5590 finish_cmc_handling (cmc);
5537 return; 5591 return;
5538 } 5592 }
5539 frag_off = ntohs(fb->frag_off); 5593 frag_off = ntohs (fb->frag_off);
5540 if (frag_off + fsize > msize) 5594 if (frag_off + fsize > msize)
5541 { 5595 {
5542 /* Fragment (plus fragment size) exceeds message size! */ 5596 /* Fragment (plus fragment size) exceeds message size! */
5543 GNUNET_break_op(0); 5597 GNUNET_break_op (0);
5544 finish_cmc_handling(cmc); 5598 finish_cmc_handling (cmc);
5545 return; 5599 return;
5546 } 5600 }
5547 memcpy(&target[frag_off], &fb[1], fsize); 5601 memcpy (&target[frag_off], &fb[1], fsize);
5548 /* update bitfield and msg_missing */ 5602 /* update bitfield and msg_missing */
5549 for (unsigned int i = frag_off; i < frag_off + fsize; i++) 5603 for (unsigned int i = frag_off; i < frag_off + fsize; i++)
5604 {
5605 if (0 == (rc->bitfield[i / 8] & (1 << (i % 8))))
5550 { 5606 {
5551 if (0 == (rc->bitfield[i / 8] & (1 << (i % 8)))) 5607 rc->bitfield[i / 8] |= (1 << (i % 8));
5552 { 5608 rc->msg_missing--;
5553 rc->bitfield[i / 8] |= (1 << (i % 8));
5554 rc->msg_missing--;
5555 }
5556 } 5609 }
5610 }
5557 5611
5558 /* Compute cummulative ACK */ 5612 /* Compute cummulative ACK */
5559 cdelay = GNUNET_TIME_absolute_get_duration(rc->last_frag); 5613 cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag);
5560 cdelay = GNUNET_TIME_relative_multiply(cdelay, rc->msg_missing / fsize); 5614 cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->msg_missing / fsize);
5561 if (0 == rc->msg_missing) 5615 if (0 == rc->msg_missing)
5562 cdelay = GNUNET_TIME_UNIT_ZERO; 5616 cdelay = GNUNET_TIME_UNIT_ZERO;
5563 cummulative_ack(&cmc->im.sender, 5617 cummulative_ack (&cmc->im.sender,
5564 &fb->ack_uuid, 5618 &fb->ack_uuid,
5565 GNUNET_TIME_relative_to_absolute(cdelay)); 5619 GNUNET_TIME_relative_to_absolute (cdelay));
5566 rc->last_frag = GNUNET_TIME_absolute_get(); 5620 rc->last_frag = GNUNET_TIME_absolute_get ();
5567 /* is reassembly complete? */ 5621 /* is reassembly complete? */
5568 if (0 != rc->msg_missing) 5622 if (0 != rc->msg_missing)
5569 { 5623 {
5570 finish_cmc_handling(cmc); 5624 finish_cmc_handling (cmc);
5571 return; 5625 return;
5572 } 5626 }
5573 /* reassembly is complete, verify result */ 5627 /* reassembly is complete, verify result */
5574 msg = (const struct GNUNET_MessageHeader *)&rc[1]; 5628 msg = (const struct GNUNET_MessageHeader *) &rc[1];
5575 if (ntohs(msg->size) != rc->msg_size) 5629 if (ntohs (msg->size) != rc->msg_size)
5576 { 5630 {
5577 GNUNET_break(0); 5631 GNUNET_break (0);
5578 free_reassembly_context(rc); 5632 free_reassembly_context (rc);
5579 finish_cmc_handling(cmc); 5633 finish_cmc_handling (cmc);
5580 return; 5634 return;
5581 } 5635 }
5582 /* successful reassembly */ 5636 /* successful reassembly */
5583 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5584 "Fragment reassembly complete for message %u\n", 5638 "Fragment reassembly complete for message %u\n",
5585 (unsigned int)fb->msg_uuid.uuid); 5639 (unsigned int) fb->msg_uuid.uuid);
5586 /* FIXME: check that the resulting msg is NOT a 5640 /* FIXME: check that the resulting msg is NOT a
5587 DV Box or Reliability Box, as that is NOT allowed! */ 5641 DV Box or Reliability Box, as that is NOT allowed! */
5588 demultiplex_with_cmc(cmc, msg); 5642 demultiplex_with_cmc (cmc, msg);
5589 /* FIXME-OPTIMIZE: really free here? Might be bad if fragments are still 5643 /* FIXME-OPTIMIZE: really free here? Might be bad if fragments are still
5590 en-route and we forget that we finished this reassembly immediately! 5644 en-route and we forget that we finished this reassembly immediately!
5591 -> keep around until timeout? 5645 -> keep around until timeout?
5592 -> shorten timeout based on ACK? */ 5646 -> shorten timeout based on ACK? */
5593 free_reassembly_context(rc); 5647 free_reassembly_context (rc);
5594} 5648}
5595 5649
5596 5650
@@ -5602,11 +5656,11 @@ handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
5602 * @return #GNUNET_YES if message is well-formed 5656 * @return #GNUNET_YES if message is well-formed
5603 */ 5657 */
5604static int 5658static int
5605check_reliability_box(void *cls, 5659check_reliability_box (void *cls,
5606 const struct TransportReliabilityBoxMessage *rb) 5660 const struct TransportReliabilityBoxMessage *rb)
5607{ 5661{
5608 (void)cls; 5662 (void) cls;
5609 GNUNET_MQ_check_boxed_message(rb); 5663 GNUNET_MQ_check_boxed_message (rb);
5610 return GNUNET_YES; 5664 return GNUNET_YES;
5611} 5665}
5612 5666
@@ -5619,34 +5673,34 @@ check_reliability_box(void *cls,
5619 * @param rb the message that was received 5673 * @param rb the message that was received
5620 */ 5674 */
5621static void 5675static void
5622handle_reliability_box(void *cls, 5676handle_reliability_box (void *cls,
5623 const struct TransportReliabilityBoxMessage *rb) 5677 const struct TransportReliabilityBoxMessage *rb)
5624{ 5678{
5625 struct CommunicatorMessageContext *cmc = cls; 5679 struct CommunicatorMessageContext *cmc = cls;
5626 const struct GNUNET_MessageHeader *inbox = 5680 const struct GNUNET_MessageHeader *inbox =
5627 (const struct GNUNET_MessageHeader *)&rb[1]; 5681 (const struct GNUNET_MessageHeader *) &rb[1];
5628 struct GNUNET_TIME_Relative rtt; 5682 struct GNUNET_TIME_Relative rtt;
5629 5683
5630 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5631 "Received reliability box from %s with UUID %s of type %u\n", 5685 "Received reliability box from %s with UUID %s of type %u\n",
5632 GNUNET_i2s(&cmc->im.sender), 5686 GNUNET_i2s (&cmc->im.sender),
5633 GNUNET_uuid2s(&rb->ack_uuid.value), 5687 GNUNET_uuid2s (&rb->ack_uuid.value),
5634 (unsigned int)ntohs(inbox->type)); 5688 (unsigned int) ntohs (inbox->type));
5635 rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we 5689 rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we
5636 do not really have an RTT for the 5690 do not really have an RTT for the
5637 * incoming* queue (should we have 5691 * incoming* queue (should we have
5638 the sender add it to the rb message?) */ 5692 the sender add it to the rb message?) */
5639 cummulative_ack( 5693 cummulative_ack (
5640 &cmc->im.sender, 5694 &cmc->im.sender,
5641 &rb->ack_uuid, 5695 &rb->ack_uuid,
5642 (0 == ntohl(rb->ack_countdown)) 5696 (0 == ntohl (rb->ack_countdown))
5643 ? GNUNET_TIME_UNIT_ZERO_ABS 5697 ? GNUNET_TIME_UNIT_ZERO_ABS
5644 : GNUNET_TIME_relative_to_absolute( 5698 : GNUNET_TIME_relative_to_absolute (
5645 GNUNET_TIME_relative_divide(rtt, 8 /* FIXME: magic constant */))); 5699 GNUNET_TIME_relative_divide (rtt, 8 /* FIXME: magic constant */)));
5646 /* continue with inner message */ 5700 /* continue with inner message */
5647 /* FIXME: check that inbox is NOT a DV Box, fragment or another 5701 /* FIXME: check that inbox is NOT a DV Box, fragment or another
5648 reliability box (not allowed!) */ 5702 reliability box (not allowed!) */
5649 demultiplex_with_cmc(cmc, inbox); 5703 demultiplex_with_cmc (cmc, inbox);
5650} 5704}
5651 5705
5652 5706
@@ -5659,20 +5713,20 @@ handle_reliability_box(void *cls,
5659 * @param age current age 5713 * @param age current age
5660 */ 5714 */
5661static void 5715static void
5662update_pd_age(struct PerformanceData *pd, unsigned int age) 5716update_pd_age (struct PerformanceData *pd, unsigned int age)
5663{ 5717{
5664 unsigned int sage; 5718 unsigned int sage;
5665 5719
5666 if (age == pd->last_age) 5720 if (age == pd->last_age)
5667 return; /* nothing to do */ 5721 return; /* nothing to do */
5668 sage = GNUNET_MAX(pd->last_age, age - 2 * GOODPUT_AGING_SLOTS); 5722 sage = GNUNET_MAX (pd->last_age, age - 2 * GOODPUT_AGING_SLOTS);
5669 for (unsigned int i = sage; i <= age - GOODPUT_AGING_SLOTS; i++) 5723 for (unsigned int i = sage; i <= age - GOODPUT_AGING_SLOTS; i++)
5670 { 5724 {
5671 struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS]; 5725 struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS];
5672 5726
5673 the->bytes_sent = 0; 5727 the->bytes_sent = 0;
5674 the->bytes_received = 0; 5728 the->bytes_received = 0;
5675 } 5729 }
5676 pd->last_age = age; 5730 pd->last_age = age;
5677} 5731}
5678 5732
@@ -5686,20 +5740,20 @@ update_pd_age(struct PerformanceData *pd, unsigned int age)
5686 * @param bytes_transmitted_ok number of bytes receiver confirmed as received 5740 * @param bytes_transmitted_ok number of bytes receiver confirmed as received
5687 */ 5741 */
5688static void 5742static void
5689update_performance_data(struct PerformanceData *pd, 5743update_performance_data (struct PerformanceData *pd,
5690 struct GNUNET_TIME_Relative rtt, 5744 struct GNUNET_TIME_Relative rtt,
5691 uint16_t bytes_transmitted_ok) 5745 uint16_t bytes_transmitted_ok)
5692{ 5746{
5693 uint64_t nval = rtt.rel_value_us; 5747 uint64_t nval = rtt.rel_value_us;
5694 uint64_t oval = pd->aged_rtt.rel_value_us; 5748 uint64_t oval = pd->aged_rtt.rel_value_us;
5695 unsigned int age = get_age(); 5749 unsigned int age = get_age ();
5696 struct TransmissionHistoryEntry *the = &pd->the[age % GOODPUT_AGING_SLOTS]; 5750 struct TransmissionHistoryEntry *the = &pd->the[age % GOODPUT_AGING_SLOTS];
5697 5751
5698 if (oval == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) 5752 if (oval == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
5699 pd->aged_rtt = rtt; 5753 pd->aged_rtt = rtt;
5700 else 5754 else
5701 pd->aged_rtt.rel_value_us = (nval + 7 * oval) / 8; 5755 pd->aged_rtt.rel_value_us = (nval + 7 * oval) / 8;
5702 update_pd_age(pd, age); 5756 update_pd_age (pd, age);
5703 the->bytes_received += bytes_transmitted_ok; 5757 the->bytes_received += bytes_transmitted_ok;
5704} 5758}
5705 5759
@@ -5712,11 +5766,11 @@ update_performance_data(struct PerformanceData *pd,
5712 * @param bytes_transmitted_ok number of bytes successfully transmitted 5766 * @param bytes_transmitted_ok number of bytes successfully transmitted
5713 */ 5767 */
5714static void 5768static void
5715update_queue_performance(struct Queue *q, 5769update_queue_performance (struct Queue *q,
5716 struct GNUNET_TIME_Relative rtt, 5770 struct GNUNET_TIME_Relative rtt,
5717 uint16_t bytes_transmitted_ok) 5771 uint16_t bytes_transmitted_ok)
5718{ 5772{
5719 update_performance_data(&q->pd, rtt, bytes_transmitted_ok); 5773 update_performance_data (&q->pd, rtt, bytes_transmitted_ok);
5720} 5774}
5721 5775
5722 5776
@@ -5728,11 +5782,11 @@ update_queue_performance(struct Queue *q,
5728 * @param bytes_transmitted_ok number of bytes successfully transmitted 5782 * @param bytes_transmitted_ok number of bytes successfully transmitted
5729 */ 5783 */
5730static void 5784static void
5731update_dvh_performance(struct DistanceVectorHop *dvh, 5785update_dvh_performance (struct DistanceVectorHop *dvh,
5732 struct GNUNET_TIME_Relative rtt, 5786 struct GNUNET_TIME_Relative rtt,
5733 uint16_t bytes_transmitted_ok) 5787 uint16_t bytes_transmitted_ok)
5734{ 5788{
5735 update_performance_data(&dvh->pd, rtt, bytes_transmitted_ok); 5789 update_performance_data (&dvh->pd, rtt, bytes_transmitted_ok);
5736} 5790}
5737 5791
5738 5792
@@ -5744,47 +5798,47 @@ update_dvh_performance(struct DistanceVectorHop *dvh,
5744 * @param pm pending message that was transmitted 5798 * @param pm pending message that was transmitted
5745 */ 5799 */
5746static void 5800static void
5747completed_pending_message(struct PendingMessage *pm) 5801completed_pending_message (struct PendingMessage *pm)
5748{ 5802{
5749 struct PendingMessage *pos; 5803 struct PendingMessage *pos;
5750 5804
5751 switch (pm->pmt) 5805 switch (pm->pmt)
5752 { 5806 {
5753 case PMT_CORE: 5807 case PMT_CORE:
5754 case PMT_RELIABILITY_BOX: 5808 case PMT_RELIABILITY_BOX:
5755 /* Full message sent, we are done */ 5809 /* Full message sent, we are done */
5756 client_send_response(pm); 5810 client_send_response (pm);
5757 return; 5811 return;
5758 5812
5759 case PMT_FRAGMENT_BOX: 5813 case PMT_FRAGMENT_BOX:
5760 /* Fragment sent over reliabile channel */ 5814 /* Fragment sent over reliabile channel */
5761 free_fragment_tree(pm); 5815 free_fragment_tree (pm);
5816 pos = pm->frag_parent;
5817 GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm);
5818 GNUNET_free (pm);
5819 /* check if subtree is done */
5820 while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) &&
5821 (pos != pm))
5822 {
5823 pm = pos;
5762 pos = pm->frag_parent; 5824 pos = pm->frag_parent;
5763 GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm); 5825 GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm);
5764 GNUNET_free(pm); 5826 GNUNET_free (pm);
5765 /* check if subtree is done */ 5827 }
5766 while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) &&
5767 (pos != pm))
5768 {
5769 pm = pos;
5770 pos = pm->frag_parent;
5771 GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm);
5772 GNUNET_free(pm);
5773 }
5774 5828
5775 /* Was this the last applicable fragmment? */ 5829 /* Was this the last applicable fragmment? */
5776 if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) && 5830 if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) &&
5777 (pos->frag_off == pos->bytes_msg)) 5831 (pos->frag_off == pos->bytes_msg))
5778 client_send_response(pos); 5832 client_send_response (pos);
5779 return; 5833 return;
5780 5834
5781 case PMT_DV_BOX: 5835 case PMT_DV_BOX:
5782 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5783 "Completed transmission of message %llu (DV Box)\n", 5837 "Completed transmission of message %llu (DV Box)\n",
5784 pm->logging_uuid); 5838 pm->logging_uuid);
5785 free_pending_message(pm); 5839 free_pending_message (pm);
5786 return; 5840 return;
5787 } 5841 }
5788} 5842}
5789 5843
5790 5844
@@ -5796,23 +5850,23 @@ completed_pending_message(struct PendingMessage *pm)
5796 * other peer 5850 * other peer
5797 */ 5851 */
5798static void 5852static void
5799handle_acknowledged(struct PendingAcknowledgement *pa, 5853handle_acknowledged (struct PendingAcknowledgement *pa,
5800 struct GNUNET_TIME_Relative ack_delay) 5854 struct GNUNET_TIME_Relative ack_delay)
5801{ 5855{
5802 struct GNUNET_TIME_Relative delay; 5856 struct GNUNET_TIME_Relative delay;
5803 5857
5804 delay = GNUNET_TIME_absolute_get_duration(pa->transmission_time); 5858 delay = GNUNET_TIME_absolute_get_duration (pa->transmission_time);
5805 if (delay.rel_value_us > ack_delay.rel_value_us) 5859 if (delay.rel_value_us > ack_delay.rel_value_us)
5806 delay = GNUNET_TIME_UNIT_ZERO; 5860 delay = GNUNET_TIME_UNIT_ZERO;
5807 else 5861 else
5808 delay = GNUNET_TIME_relative_subtract(delay, ack_delay); 5862 delay = GNUNET_TIME_relative_subtract (delay, ack_delay);
5809 if (NULL != pa->queue) 5863 if (NULL != pa->queue)
5810 update_queue_performance(pa->queue, delay, pa->message_size); 5864 update_queue_performance (pa->queue, delay, pa->message_size);
5811 if (NULL != pa->dvh) 5865 if (NULL != pa->dvh)
5812 update_dvh_performance(pa->dvh, delay, pa->message_size); 5866 update_dvh_performance (pa->dvh, delay, pa->message_size);
5813 if (NULL != pa->pm) 5867 if (NULL != pa->pm)
5814 completed_pending_message(pa->pm); 5868 completed_pending_message (pa->pm);
5815 free_pending_acknowledgement(pa); 5869 free_pending_acknowledgement (pa);
5816} 5870}
5817 5871
5818 5872
@@ -5824,25 +5878,25 @@ handle_acknowledged(struct PendingAcknowledgement *pa,
5824 * @return #GNUNET_Ok if @a ra is well-formed 5878 * @return #GNUNET_Ok if @a ra is well-formed
5825 */ 5879 */
5826static int 5880static int
5827check_reliability_ack(void *cls, 5881check_reliability_ack (void *cls,
5828 const struct TransportReliabilityAckMessage *ra) 5882 const struct TransportReliabilityAckMessage *ra)
5829{ 5883{
5830 unsigned int n_acks; 5884 unsigned int n_acks;
5831 5885
5832 (void)cls; 5886 (void) cls;
5833 n_acks = (ntohs(ra->header.size) - sizeof(*ra)) / 5887 n_acks = (ntohs (ra->header.size) - sizeof(*ra))
5834 sizeof(struct TransportCummulativeAckPayloadP); 5888 / sizeof(struct TransportCummulativeAckPayloadP);
5835 if (0 == n_acks) 5889 if (0 == n_acks)
5836 { 5890 {
5837 GNUNET_break_op(0); 5891 GNUNET_break_op (0);
5838 return GNUNET_SYSERR; 5892 return GNUNET_SYSERR;
5839 } 5893 }
5840 if ((ntohs(ra->header.size) - sizeof(*ra)) != 5894 if ((ntohs (ra->header.size) - sizeof(*ra)) !=
5841 n_acks * sizeof(struct TransportCummulativeAckPayloadP)) 5895 n_acks * sizeof(struct TransportCummulativeAckPayloadP))
5842 { 5896 {
5843 GNUNET_break_op(0); 5897 GNUNET_break_op (0);
5844 return GNUNET_SYSERR; 5898 return GNUNET_SYSERR;
5845 } 5899 }
5846 return GNUNET_OK; 5900 return GNUNET_OK;
5847} 5901}
5848 5902
@@ -5855,46 +5909,46 @@ check_reliability_ack(void *cls,
5855 * @param ra the message that was received 5909 * @param ra the message that was received
5856 */ 5910 */
5857static void 5911static void
5858handle_reliability_ack(void *cls, 5912handle_reliability_ack (void *cls,
5859 const struct TransportReliabilityAckMessage *ra) 5913 const struct TransportReliabilityAckMessage *ra)
5860{ 5914{
5861 struct CommunicatorMessageContext *cmc = cls; 5915 struct CommunicatorMessageContext *cmc = cls;
5862 const struct TransportCummulativeAckPayloadP *ack; 5916 const struct TransportCummulativeAckPayloadP *ack;
5863 unsigned int n_acks; 5917 unsigned int n_acks;
5864 uint32_t ack_counter; 5918 uint32_t ack_counter;
5865 5919
5866 n_acks = (ntohs(ra->header.size) - sizeof(*ra)) / 5920 n_acks = (ntohs (ra->header.size) - sizeof(*ra))
5867 sizeof(struct TransportCummulativeAckPayloadP); 5921 / sizeof(struct TransportCummulativeAckPayloadP);
5868 ack = (const struct TransportCummulativeAckPayloadP *)&ra[1]; 5922 ack = (const struct TransportCummulativeAckPayloadP *) &ra[1];
5869 for (unsigned int i = 0; i < n_acks; i++) 5923 for (unsigned int i = 0; i < n_acks; i++)
5870 { 5924 {
5871 struct PendingAcknowledgement *pa = 5925 struct PendingAcknowledgement *pa =
5872 GNUNET_CONTAINER_multiuuidmap_get(pending_acks, &ack[i].ack_uuid.value); 5926 GNUNET_CONTAINER_multiuuidmap_get (pending_acks, &ack[i].ack_uuid.value);
5873 if (NULL == pa) 5927 if (NULL == pa)
5874 { 5928 {
5875 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 5929 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
5876 "Received ACK from %s with UUID %s which is unknown to us!\n", 5930 "Received ACK from %s with UUID %s which is unknown to us!\n",
5877 GNUNET_i2s(&cmc->im.sender), 5931 GNUNET_i2s (&cmc->im.sender),
5878 GNUNET_uuid2s(&ack[i].ack_uuid.value)); 5932 GNUNET_uuid2s (&ack[i].ack_uuid.value));
5879 GNUNET_STATISTICS_update( 5933 GNUNET_STATISTICS_update (
5880 GST_stats, 5934 GST_stats,
5881 "# FRAGMENT_ACKS dropped, no matching pending message", 5935 "# FRAGMENT_ACKS dropped, no matching pending message",
5882 1, 5936 1,
5883 GNUNET_NO); 5937 GNUNET_NO);
5884 continue; 5938 continue;
5885 }
5886 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5887 "Received ACK from %s with UUID %s\n",
5888 GNUNET_i2s(&cmc->im.sender),
5889 GNUNET_uuid2s(&ack[i].ack_uuid.value));
5890 handle_acknowledged(pa, GNUNET_TIME_relative_ntoh(ack[i].ack_delay));
5891 } 5939 }
5940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5941 "Received ACK from %s with UUID %s\n",
5942 GNUNET_i2s (&cmc->im.sender),
5943 GNUNET_uuid2s (&ack[i].ack_uuid.value));
5944 handle_acknowledged (pa, GNUNET_TIME_relative_ntoh (ack[i].ack_delay));
5945 }
5892 5946
5893 ack_counter = htonl(ra->ack_counter); 5947 ack_counter = htonl (ra->ack_counter);
5894 (void)ack_counter; /* silence compiler warning for now */ 5948 (void) ack_counter; /* silence compiler warning for now */
5895 // FIXME-OPTIMIZE: track ACK losses based on ack_counter somewhere! 5949 // FIXME-OPTIMIZE: track ACK losses based on ack_counter somewhere!
5896 // (DV and/or Neighbour?) 5950 // (DV and/or Neighbour?)
5897 finish_cmc_handling(cmc); 5951 finish_cmc_handling (cmc);
5898} 5952}
5899 5953
5900 5954
@@ -5906,30 +5960,30 @@ handle_reliability_ack(void *cls,
5906 * @return #GNUNET_YES if message is well-formed 5960 * @return #GNUNET_YES if message is well-formed
5907 */ 5961 */
5908static int 5962static int
5909check_backchannel_encapsulation( 5963check_backchannel_encapsulation (
5910 void *cls, 5964 void *cls,
5911 const struct TransportBackchannelEncapsulationMessage *be) 5965 const struct TransportBackchannelEncapsulationMessage *be)
5912{ 5966{
5913 uint16_t size = ntohs(be->header.size) - sizeof(*be); 5967 uint16_t size = ntohs (be->header.size) - sizeof(*be);
5914 const struct GNUNET_MessageHeader *inbox = 5968 const struct GNUNET_MessageHeader *inbox =
5915 (const struct GNUNET_MessageHeader *)&be[1]; 5969 (const struct GNUNET_MessageHeader *) &be[1];
5916 const char *is; 5970 const char *is;
5917 uint16_t isize; 5971 uint16_t isize;
5918 5972
5919 (void)cls; 5973 (void) cls;
5920 if (ntohs(inbox->size) >= size) 5974 if (ntohs (inbox->size) >= size)
5921 { 5975 {
5922 GNUNET_break_op(0); 5976 GNUNET_break_op (0);
5923 return GNUNET_SYSERR; 5977 return GNUNET_SYSERR;
5924 } 5978 }
5925 isize = ntohs(inbox->size); 5979 isize = ntohs (inbox->size);
5926 is = ((const char *)inbox) + isize; 5980 is = ((const char *) inbox) + isize;
5927 size -= isize; 5981 size -= isize;
5928 if ('\0' != is[size - 1]) 5982 if ('\0' != is[size - 1])
5929 { 5983 {
5930 GNUNET_break_op(0); 5984 GNUNET_break_op (0);
5931 return GNUNET_SYSERR; 5985 return GNUNET_SYSERR;
5932 } 5986 }
5933 return GNUNET_YES; 5987 return GNUNET_YES;
5934} 5988}
5935 5989
@@ -5943,7 +5997,7 @@ check_backchannel_encapsulation(
5943 * @param be the message that was received 5997 * @param be the message that was received
5944 */ 5998 */
5945static void 5999static void
5946handle_backchannel_encapsulation( 6000handle_backchannel_encapsulation (
5947 void *cls, 6001 void *cls,
5948 const struct TransportBackchannelEncapsulationMessage *be) 6002 const struct TransportBackchannelEncapsulationMessage *be)
5949{ 6003{
@@ -5952,41 +6006,41 @@ handle_backchannel_encapsulation(
5952 struct GNUNET_MQ_Envelope *env; 6006 struct GNUNET_MQ_Envelope *env;
5953 struct TransportClient *tc; 6007 struct TransportClient *tc;
5954 const struct GNUNET_MessageHeader *inbox = 6008 const struct GNUNET_MessageHeader *inbox =
5955 (const struct GNUNET_MessageHeader *)&be[1]; 6009 (const struct GNUNET_MessageHeader *) &be[1];
5956 uint16_t isize = ntohs(inbox->size); 6010 uint16_t isize = ntohs (inbox->size);
5957 const char *target_communicator = ((const char *)inbox) + isize; 6011 const char *target_communicator = ((const char *) inbox) + isize;
5958 6012
5959 /* Find client providing this communicator */ 6013 /* Find client providing this communicator */
5960 for (tc = clients_head; NULL != tc; tc = tc->next) 6014 for (tc = clients_head; NULL != tc; tc = tc->next)
5961 if ((CT_COMMUNICATOR == tc->type) && 6015 if ((CT_COMMUNICATOR == tc->type) &&
5962 (0 == 6016 (0 ==
5963 strcmp(tc->details.communicator.address_prefix, target_communicator))) 6017 strcmp (tc->details.communicator.address_prefix, target_communicator)))
5964 break; 6018 break;
5965 if (NULL == tc) 6019 if (NULL == tc)
5966 { 6020 {
5967 char *stastr; 6021 char *stastr;
5968 6022
5969 GNUNET_asprintf( 6023 GNUNET_asprintf (
5970 &stastr, 6024 &stastr,
5971 "# Backchannel message dropped: target communicator `%s' unknown", 6025 "# Backchannel message dropped: target communicator `%s' unknown",
5972 target_communicator); 6026 target_communicator);
5973 GNUNET_STATISTICS_update(GST_stats, stastr, 1, GNUNET_NO); 6027 GNUNET_STATISTICS_update (GST_stats, stastr, 1, GNUNET_NO);
5974 GNUNET_free(stastr); 6028 GNUNET_free (stastr);
5975 return; 6029 return;
5976 } 6030 }
5977 /* Finally, deliver backchannel message to communicator */ 6031 /* Finally, deliver backchannel message to communicator */
5978 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5979 "Delivering backchannel message from %s of type %u to %s\n", 6033 "Delivering backchannel message from %s of type %u to %s\n",
5980 GNUNET_i2s(&cmc->im.sender), 6034 GNUNET_i2s (&cmc->im.sender),
5981 ntohs(inbox->type), 6035 ntohs (inbox->type),
5982 target_communicator); 6036 target_communicator);
5983 env = GNUNET_MQ_msg_extra( 6037 env = GNUNET_MQ_msg_extra (
5984 cbi, 6038 cbi,
5985 isize, 6039 isize,
5986 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING); 6040 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING);
5987 cbi->pid = cmc->im.sender; 6041 cbi->pid = cmc->im.sender;
5988 memcpy(&cbi[1], inbox, isize); 6042 memcpy (&cbi[1], inbox, isize);
5989 GNUNET_MQ_send(tc->mq, env); 6043 GNUNET_MQ_send (tc->mq, env);
5990} 6044}
5991 6045
5992 6046
@@ -6000,26 +6054,26 @@ handle_backchannel_encapsulation(
6000 * @param cls a `struct DistanceVector` 6054 * @param cls a `struct DistanceVector`
6001 */ 6055 */
6002static void 6056static void
6003path_cleanup_cb(void *cls) 6057path_cleanup_cb (void *cls)
6004{ 6058{
6005 struct DistanceVector *dv = cls; 6059 struct DistanceVector *dv = cls;
6006 struct DistanceVectorHop *pos; 6060 struct DistanceVectorHop *pos;
6007 6061
6008 dv->timeout_task = NULL; 6062 dv->timeout_task = NULL;
6009 while (NULL != (pos = dv->dv_head)) 6063 while (NULL != (pos = dv->dv_head))
6010 { 6064 {
6011 GNUNET_assert(dv == pos->dv); 6065 GNUNET_assert (dv == pos->dv);
6012 if (GNUNET_TIME_absolute_get_remaining(pos->timeout).rel_value_us > 0) 6066 if (GNUNET_TIME_absolute_get_remaining (pos->timeout).rel_value_us > 0)
6013 break; 6067 break;
6014 free_distance_vector_hop(pos); 6068 free_distance_vector_hop (pos);
6015 } 6069 }
6016 if (NULL == pos) 6070 if (NULL == pos)
6017 { 6071 {
6018 free_dv_route(dv); 6072 free_dv_route (dv);
6019 return; 6073 return;
6020 } 6074 }
6021 dv->timeout_task = 6075 dv->timeout_task =
6022 GNUNET_SCHEDULER_add_at(pos->timeout, &path_cleanup_cb, dv); 6076 GNUNET_SCHEDULER_add_at (pos->timeout, &path_cleanup_cb, dv);
6023} 6077}
6024 6078
6025 6079
@@ -6031,44 +6085,44 @@ path_cleanup_cb(void *cls)
6031 * @param hop a path to some peer that is the reason for activation 6085 * @param hop a path to some peer that is the reason for activation
6032 */ 6086 */
6033static void 6087static void
6034activate_core_visible_dv_path(struct DistanceVectorHop *hop) 6088activate_core_visible_dv_path (struct DistanceVectorHop *hop)
6035{ 6089{
6036 struct DistanceVector *dv = hop->dv; 6090 struct DistanceVector *dv = hop->dv;
6037 struct VirtualLink *vl; 6091 struct VirtualLink *vl;
6038 6092
6039 vl = lookup_virtual_link(&dv->target); 6093 vl = lookup_virtual_link (&dv->target);
6040 if (NULL != vl) 6094 if (NULL != vl)
6041 { 6095 {
6042 /* Link was already up, remember dv is also now available and we are done */ 6096 /* Link was already up, remember dv is also now available and we are done */
6043 vl->dv = dv; 6097 vl->dv = dv;
6044 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6098 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6045 "Virtual link to %s could now also use DV!\n", 6099 "Virtual link to %s could now also use DV!\n",
6046 GNUNET_i2s(&dv->target)); 6100 GNUNET_i2s (&dv->target));
6047 return; 6101 return;
6048 } 6102 }
6049 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6050 "Creating new virtual link to %s using DV!\n", 6104 "Creating new virtual link to %s using DV!\n",
6051 GNUNET_i2s(&dv->target)); 6105 GNUNET_i2s (&dv->target));
6052 vl = GNUNET_new(struct VirtualLink); 6106 vl = GNUNET_new (struct VirtualLink);
6053 vl->message_uuid_ctr = 6107 vl->message_uuid_ctr =
6054 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 6108 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
6055 vl->target = dv->target; 6109 vl->target = dv->target;
6056 vl->dv = dv; 6110 vl->dv = dv;
6057 dv->vl = vl; 6111 dv->vl = vl;
6058 vl->core_recv_window = RECV_WINDOW_SIZE; 6112 vl->core_recv_window = RECV_WINDOW_SIZE;
6059 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; 6113 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE;
6060 vl->visibility_task = 6114 vl->visibility_task =
6061 GNUNET_SCHEDULER_add_at(hop->path_valid_until, &check_link_down, vl); 6115 GNUNET_SCHEDULER_add_at (hop->path_valid_until, &check_link_down, vl);
6062 GNUNET_break(GNUNET_YES == 6116 GNUNET_break (GNUNET_YES ==
6063 GNUNET_CONTAINER_multipeermap_put( 6117 GNUNET_CONTAINER_multipeermap_put (
6064 links, 6118 links,
6065 &vl->target, 6119 &vl->target,
6066 vl, 6120 vl,
6067 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6121 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
6068 consider_sending_fc(vl); 6122 consider_sending_fc (vl);
6069 /* We lacked a confirmed connection to the target 6123 /* We lacked a confirmed connection to the target
6070 before, so tell CORE about it (finally!) */ 6124 before, so tell CORE about it (finally!) */
6071 cores_send_connect_info(&dv->target); 6125 cores_send_connect_info (&dv->target);
6072} 6126}
6073 6127
6074 6128
@@ -6098,10 +6152,10 @@ activate_core_visible_dv_path(struct DistanceVectorHop *hop)
6098 * or path[i+1] is a direct neighbour for i>0) 6152 * or path[i+1] is a direct neighbour for i>0)
6099 */ 6153 */
6100static int 6154static int
6101learn_dv_path(const struct GNUNET_PeerIdentity *path, 6155learn_dv_path (const struct GNUNET_PeerIdentity *path,
6102 unsigned int path_len, 6156 unsigned int path_len,
6103 struct GNUNET_TIME_Relative network_latency, 6157 struct GNUNET_TIME_Relative network_latency,
6104 struct GNUNET_TIME_Absolute path_valid_until) 6158 struct GNUNET_TIME_Absolute path_valid_until)
6105{ 6159{
6106 struct DistanceVectorHop *hop; 6160 struct DistanceVectorHop *hop;
6107 struct DistanceVector *dv; 6161 struct DistanceVector *dv;
@@ -6109,143 +6163,143 @@ learn_dv_path(const struct GNUNET_PeerIdentity *path,
6109 unsigned int shorter_distance; 6163 unsigned int shorter_distance;
6110 6164
6111 if (path_len < 3) 6165 if (path_len < 3)
6112 { 6166 {
6113 /* what a boring path! not allowed! */ 6167 /* what a boring path! not allowed! */
6114 GNUNET_break(0); 6168 GNUNET_break (0);
6115 return GNUNET_SYSERR; 6169 return GNUNET_SYSERR;
6116 } 6170 }
6117 GNUNET_assert(0 == GNUNET_memcmp(&GST_my_identity, &path[0])); 6171 GNUNET_assert (0 == GNUNET_memcmp (&GST_my_identity, &path[0]));
6118 next_hop = lookup_neighbour(&path[1]); 6172 next_hop = lookup_neighbour (&path[1]);
6119 if (NULL == next_hop) 6173 if (NULL == next_hop)
6120 { 6174 {
6121 /* next hop must be a neighbour, otherwise this whole thing is useless! */ 6175 /* next hop must be a neighbour, otherwise this whole thing is useless! */
6122 GNUNET_break(0); 6176 GNUNET_break (0);
6177 return GNUNET_SYSERR;
6178 }
6179 for (unsigned int i = 2; i < path_len; i++)
6180 if (NULL != lookup_neighbour (&path[i]))
6181 {
6182 /* Useless path: we have a direct connection to some hop
6183 in the middle of the path, so this one is not even
6184 terribly useful for redundancy */
6185 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
6186 "Path of %u hops useless: directly link to hop %u (%s)\n",
6187 path_len,
6188 i,
6189 GNUNET_i2s (&path[i]));
6190 GNUNET_STATISTICS_update (GST_stats,
6191 "# Useless DV path ignored: hop is neighbour",
6192 1,
6193 GNUNET_NO);
6123 return GNUNET_SYSERR; 6194 return GNUNET_SYSERR;
6124 } 6195 }
6125 for (unsigned int i = 2; i < path_len; i++) 6196 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &path[path_len - 1]);
6126 if (NULL != lookup_neighbour(&path[i]))
6127 {
6128 /* Useless path: we have a direct connection to some hop
6129 in the middle of the path, so this one is not even
6130 terribly useful for redundancy */
6131 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
6132 "Path of %u hops useless: directly link to hop %u (%s)\n",
6133 path_len,
6134 i,
6135 GNUNET_i2s(&path[i]));
6136 GNUNET_STATISTICS_update(GST_stats,
6137 "# Useless DV path ignored: hop is neighbour",
6138 1,
6139 GNUNET_NO);
6140 return GNUNET_SYSERR;
6141 }
6142 dv = GNUNET_CONTAINER_multipeermap_get(dv_routes, &path[path_len - 1]);
6143 if (NULL == dv) 6197 if (NULL == dv)
6144 { 6198 {
6145 dv = GNUNET_new(struct DistanceVector); 6199 dv = GNUNET_new (struct DistanceVector);
6146 dv->target = path[path_len - 1]; 6200 dv->target = path[path_len - 1];
6147 dv->timeout_task = GNUNET_SCHEDULER_add_delayed(DV_PATH_VALIDITY_TIMEOUT, 6201 dv->timeout_task = GNUNET_SCHEDULER_add_delayed (DV_PATH_VALIDITY_TIMEOUT,
6148 &path_cleanup_cb, 6202 &path_cleanup_cb,
6149 dv); 6203 dv);
6150 GNUNET_assert(GNUNET_OK == 6204 GNUNET_assert (GNUNET_OK ==
6151 GNUNET_CONTAINER_multipeermap_put( 6205 GNUNET_CONTAINER_multipeermap_put (
6152 dv_routes, 6206 dv_routes,
6153 &dv->target, 6207 &dv->target,
6154 dv, 6208 dv,
6155 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6209 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
6156 } 6210 }
6157 /* Check if we have this path already! */ 6211 /* Check if we have this path already! */
6158 shorter_distance = 0; 6212 shorter_distance = 0;
6159 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 6213 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
6160 pos = pos->next_dv) 6214 pos = pos->next_dv)
6215 {
6216 if (pos->distance < path_len - 2)
6217 shorter_distance++;
6218 /* Note that the distances in 'pos' excludes us (path[0]) and
6219 the next_hop (path[1]), so we need to subtract two
6220 and check next_hop explicitly */
6221 if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop))
6161 { 6222 {
6162 if (pos->distance < path_len - 2) 6223 int match = GNUNET_YES;
6163 shorter_distance++; 6224
6164 /* Note that the distances in 'pos' excludes us (path[0]) and 6225 for (unsigned int i = 0; i < pos->distance; i++)
6165 the next_hop (path[1]), so we need to subtract two 6226 {
6166 and check next_hop explicitly */ 6227 if (0 != GNUNET_memcmp (&pos->path[i], &path[i + 2]))
6167 if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop)) 6228 {
6229 match = GNUNET_NO;
6230 break;
6231 }
6232 }
6233 if (GNUNET_YES == match)
6234 {
6235 struct GNUNET_TIME_Relative last_timeout;
6236
6237 /* Re-discovered known path, update timeout */
6238 GNUNET_STATISTICS_update (GST_stats,
6239 "# Known DV path refreshed",
6240 1,
6241 GNUNET_NO);
6242 last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout);
6243 pos->timeout =
6244 GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT);
6245 pos->path_valid_until =
6246 GNUNET_TIME_absolute_max (pos->path_valid_until, path_valid_until);
6247 GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, pos);
6248 GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, pos);
6249 if (0 <
6250 GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us)
6251 activate_core_visible_dv_path (pos);
6252 if (last_timeout.rel_value_us <
6253 GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT,
6254 DV_PATH_DISCOVERY_FREQUENCY)
6255 .rel_value_us)
6168 { 6256 {
6169 int match = GNUNET_YES; 6257 /* Some peer send DV learn messages too often, we are learning
6170 6258 the same path faster than it would be useful; do not forward! */
6171 for (unsigned int i = 0; i < pos->distance; i++) 6259 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
6172 { 6260 "Rediscovered path too quickly, not forwarding further\n");
6173 if (0 != GNUNET_memcmp(&pos->path[i], &path[i + 2])) 6261 return GNUNET_NO;
6174 {
6175 match = GNUNET_NO;
6176 break;
6177 }
6178 }
6179 if (GNUNET_YES == match)
6180 {
6181 struct GNUNET_TIME_Relative last_timeout;
6182
6183 /* Re-discovered known path, update timeout */
6184 GNUNET_STATISTICS_update(GST_stats,
6185 "# Known DV path refreshed",
6186 1,
6187 GNUNET_NO);
6188 last_timeout = GNUNET_TIME_absolute_get_remaining(pos->timeout);
6189 pos->timeout =
6190 GNUNET_TIME_relative_to_absolute(DV_PATH_VALIDITY_TIMEOUT);
6191 pos->path_valid_until =
6192 GNUNET_TIME_absolute_max(pos->path_valid_until, path_valid_until);
6193 GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, pos);
6194 GNUNET_CONTAINER_MDLL_insert(dv, dv->dv_head, dv->dv_tail, pos);
6195 if (0 <
6196 GNUNET_TIME_absolute_get_remaining(path_valid_until).rel_value_us)
6197 activate_core_visible_dv_path(pos);
6198 if (last_timeout.rel_value_us <
6199 GNUNET_TIME_relative_subtract(DV_PATH_VALIDITY_TIMEOUT,
6200 DV_PATH_DISCOVERY_FREQUENCY)
6201 .rel_value_us)
6202 {
6203 /* Some peer send DV learn messages too often, we are learning
6204 the same path faster than it would be useful; do not forward! */
6205 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
6206 "Rediscovered path too quickly, not forwarding further\n");
6207 return GNUNET_NO;
6208 }
6209 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6210 "Refreshed known path to %s, forwarding further\n",
6211 GNUNET_i2s(&dv->target));
6212 return GNUNET_YES;
6213 }
6214 } 6262 }
6263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6264 "Refreshed known path to %s, forwarding further\n",
6265 GNUNET_i2s (&dv->target));
6266 return GNUNET_YES;
6267 }
6215 } 6268 }
6269 }
6216 /* Count how many shorter paths we have (incl. direct 6270 /* Count how many shorter paths we have (incl. direct
6217 neighbours) before simply giving up on this one! */ 6271 neighbours) before simply giving up on this one! */
6218 if (shorter_distance >= MAX_DV_PATHS_TO_TARGET) 6272 if (shorter_distance >= MAX_DV_PATHS_TO_TARGET)
6219 { 6273 {
6220 /* We have a shorter path already! */ 6274 /* We have a shorter path already! */
6221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6222 "Have many shorter DV paths %s, not forwarding further\n", 6276 "Have many shorter DV paths %s, not forwarding further\n",
6223 GNUNET_i2s(&dv->target)); 6277 GNUNET_i2s (&dv->target));
6224 return GNUNET_NO; 6278 return GNUNET_NO;
6225 } 6279 }
6226 /* create new DV path entry */ 6280 /* create new DV path entry */
6227 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6228 "Discovered new DV path to %s\n", 6282 "Discovered new DV path to %s\n",
6229 GNUNET_i2s(&dv->target)); 6283 GNUNET_i2s (&dv->target));
6230 hop = GNUNET_malloc(sizeof(struct DistanceVectorHop) + 6284 hop = GNUNET_malloc (sizeof(struct DistanceVectorHop)
6231 sizeof(struct GNUNET_PeerIdentity) * (path_len - 2)); 6285 + sizeof(struct GNUNET_PeerIdentity) * (path_len - 2));
6232 hop->next_hop = next_hop; 6286 hop->next_hop = next_hop;
6233 hop->dv = dv; 6287 hop->dv = dv;
6234 hop->path = (const struct GNUNET_PeerIdentity *)&hop[1]; 6288 hop->path = (const struct GNUNET_PeerIdentity *) &hop[1];
6235 memcpy(&hop[1], 6289 memcpy (&hop[1],
6236 &path[2], 6290 &path[2],
6237 sizeof(struct GNUNET_PeerIdentity) * (path_len - 2)); 6291 sizeof(struct GNUNET_PeerIdentity) * (path_len - 2));
6238 hop->timeout = GNUNET_TIME_relative_to_absolute(DV_PATH_VALIDITY_TIMEOUT); 6292 hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT);
6239 hop->path_valid_until = path_valid_until; 6293 hop->path_valid_until = path_valid_until;
6240 hop->distance = path_len - 2; 6294 hop->distance = path_len - 2;
6241 hop->pd.aged_rtt = network_latency; 6295 hop->pd.aged_rtt = network_latency;
6242 GNUNET_CONTAINER_MDLL_insert(dv, dv->dv_head, dv->dv_tail, hop); 6296 GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, hop);
6243 GNUNET_CONTAINER_MDLL_insert(neighbour, 6297 GNUNET_CONTAINER_MDLL_insert (neighbour,
6244 next_hop->dv_head, 6298 next_hop->dv_head,
6245 next_hop->dv_tail, 6299 next_hop->dv_tail,
6246 hop); 6300 hop);
6247 if (0 < GNUNET_TIME_absolute_get_remaining(path_valid_until).rel_value_us) 6301 if (0 < GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us)
6248 activate_core_visible_dv_path(hop); 6302 activate_core_visible_dv_path (hop);
6249 return GNUNET_YES; 6303 return GNUNET_YES;
6250} 6304}
6251 6305
@@ -6258,36 +6312,36 @@ learn_dv_path(const struct GNUNET_PeerIdentity *path,
6258 * @return #GNUNET_YES if message is well-formed 6312 * @return #GNUNET_YES if message is well-formed
6259 */ 6313 */
6260static int 6314static int
6261check_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl) 6315check_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
6262{ 6316{
6263 uint16_t size = ntohs(dvl->header.size); 6317 uint16_t size = ntohs (dvl->header.size);
6264 uint16_t num_hops = ntohs(dvl->num_hops); 6318 uint16_t num_hops = ntohs (dvl->num_hops);
6265 const struct DVPathEntryP *hops = (const struct DVPathEntryP *)&dvl[1]; 6319 const struct DVPathEntryP *hops = (const struct DVPathEntryP *) &dvl[1];
6266 6320
6267 (void)cls; 6321 (void) cls;
6268 if (size != sizeof(*dvl) + num_hops * sizeof(struct DVPathEntryP)) 6322 if (size != sizeof(*dvl) + num_hops * sizeof(struct DVPathEntryP))
6269 { 6323 {
6270 GNUNET_break_op(0); 6324 GNUNET_break_op (0);
6271 return GNUNET_SYSERR; 6325 return GNUNET_SYSERR;
6272 } 6326 }
6273 if (num_hops > MAX_DV_HOPS_ALLOWED) 6327 if (num_hops > MAX_DV_HOPS_ALLOWED)
6328 {
6329 GNUNET_break_op (0);
6330 return GNUNET_SYSERR;
6331 }
6332 for (unsigned int i = 0; i < num_hops; i++)
6333 {
6334 if (0 == GNUNET_memcmp (&dvl->initiator, &hops[i].hop))
6274 { 6335 {
6275 GNUNET_break_op(0); 6336 GNUNET_break_op (0);
6276 return GNUNET_SYSERR; 6337 return GNUNET_SYSERR;
6277 } 6338 }
6278 for (unsigned int i = 0; i < num_hops; i++) 6339 if (0 == GNUNET_memcmp (&GST_my_identity, &hops[i].hop))
6279 { 6340 {
6280 if (0 == GNUNET_memcmp(&dvl->initiator, &hops[i].hop)) 6341 GNUNET_break_op (0);
6281 { 6342 return GNUNET_SYSERR;
6282 GNUNET_break_op(0);
6283 return GNUNET_SYSERR;
6284 }
6285 if (0 == GNUNET_memcmp(&GST_my_identity, &hops[i].hop))
6286 {
6287 GNUNET_break_op(0);
6288 return GNUNET_SYSERR;
6289 }
6290 } 6343 }
6344 }
6291 return GNUNET_YES; 6345 return GNUNET_YES;
6292} 6346}
6293 6347
@@ -6304,56 +6358,56 @@ check_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl)
6304 * delay 6358 * delay
6305 */ 6359 */
6306static void 6360static void
6307forward_dv_learn(const struct GNUNET_PeerIdentity *next_hop, 6361forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
6308 const struct TransportDVLearnMessage *msg, 6362 const struct TransportDVLearnMessage *msg,
6309 uint16_t bi_history, 6363 uint16_t bi_history,
6310 uint16_t nhops, 6364 uint16_t nhops,
6311 const struct DVPathEntryP *hops, 6365 const struct DVPathEntryP *hops,
6312 struct GNUNET_TIME_Absolute in_time) 6366 struct GNUNET_TIME_Absolute in_time)
6313{ 6367{
6314 struct DVPathEntryP *dhops; 6368 struct DVPathEntryP *dhops;
6315 char buf[sizeof(struct TransportDVLearnMessage) + 6369 char buf[sizeof(struct TransportDVLearnMessage)
6316 (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN; 6370 + (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN;
6317 struct TransportDVLearnMessage *fwd = (struct TransportDVLearnMessage *)buf; 6371 struct TransportDVLearnMessage *fwd = (struct TransportDVLearnMessage *) buf;
6318 struct GNUNET_TIME_Relative nnd; 6372 struct GNUNET_TIME_Relative nnd;
6319 6373
6320 /* compute message for forwarding */ 6374 /* compute message for forwarding */
6321 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6322 "Forwarding DV learn message originating from %s to %s\n", 6376 "Forwarding DV learn message originating from %s to %s\n",
6323 GNUNET_i2s(&msg->initiator), 6377 GNUNET_i2s (&msg->initiator),
6324 GNUNET_i2s2(next_hop)); 6378 GNUNET_i2s2 (next_hop));
6325 GNUNET_assert(nhops < MAX_DV_HOPS_ALLOWED); 6379 GNUNET_assert (nhops < MAX_DV_HOPS_ALLOWED);
6326 fwd->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); 6380 fwd->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN);
6327 fwd->header.size = htons(sizeof(struct TransportDVLearnMessage) + 6381 fwd->header.size = htons (sizeof(struct TransportDVLearnMessage)
6328 (nhops + 1) * sizeof(struct DVPathEntryP)); 6382 + (nhops + 1) * sizeof(struct DVPathEntryP));
6329 fwd->num_hops = htons(nhops + 1); 6383 fwd->num_hops = htons (nhops + 1);
6330 fwd->bidirectional = htons(bi_history); 6384 fwd->bidirectional = htons (bi_history);
6331 nnd = GNUNET_TIME_relative_add(GNUNET_TIME_absolute_get_duration(in_time), 6385 nnd = GNUNET_TIME_relative_add (GNUNET_TIME_absolute_get_duration (in_time),
6332 GNUNET_TIME_relative_ntoh( 6386 GNUNET_TIME_relative_ntoh (
6333 msg->non_network_delay)); 6387 msg->non_network_delay));
6334 fwd->non_network_delay = GNUNET_TIME_relative_hton(nnd); 6388 fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd);
6335 fwd->init_sig = msg->init_sig; 6389 fwd->init_sig = msg->init_sig;
6336 fwd->initiator = msg->initiator; 6390 fwd->initiator = msg->initiator;
6337 fwd->challenge = msg->challenge; 6391 fwd->challenge = msg->challenge;
6338 dhops = (struct DVPathEntryP *)&fwd[1]; 6392 dhops = (struct DVPathEntryP *) &fwd[1];
6339 GNUNET_memcpy(dhops, hops, sizeof(struct DVPathEntryP) * nhops); 6393 GNUNET_memcpy (dhops, hops, sizeof(struct DVPathEntryP) * nhops);
6340 dhops[nhops].hop = GST_my_identity; 6394 dhops[nhops].hop = GST_my_identity;
6341 { 6395 {
6342 struct DvHopPS dhp = { .purpose.purpose = 6396 struct DvHopPS dhp = { .purpose.purpose =
6343 htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), 6397 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP),
6344 .purpose.size = htonl(sizeof(dhp)), 6398 .purpose.size = htonl (sizeof(dhp)),
6345 .pred = dhops[nhops - 1].hop, 6399 .pred = dhops[nhops - 1].hop,
6346 .succ = *next_hop, 6400 .succ = *next_hop,
6347 .challenge = msg->challenge }; 6401 .challenge = msg->challenge };
6348 6402
6349 GNUNET_assert(GNUNET_OK == 6403 GNUNET_assert (GNUNET_OK ==
6350 GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, 6404 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
6351 &dhp.purpose, 6405 &dhp.purpose,
6352 &dhops[nhops].hop_sig)); 6406 &dhops[nhops].hop_sig));
6353 } 6407 }
6354 route_control_message_without_fc(next_hop, 6408 route_control_message_without_fc (next_hop,
6355 &fwd->header, 6409 &fwd->header,
6356 RMO_UNCONFIRMED_ALLOWED); 6410 RMO_UNCONFIRMED_ALLOWED);
6357} 6411}
6358 6412
6359 6413
@@ -6367,28 +6421,28 @@ forward_dv_learn(const struct GNUNET_PeerIdentity *next_hop,
6367 * @return #GNUNET_OK if the signature is valid 6421 * @return #GNUNET_OK if the signature is valid
6368 */ 6422 */
6369static int 6423static int
6370validate_dv_initiator_signature( 6424validate_dv_initiator_signature (
6371 struct GNUNET_TIME_AbsoluteNBO sender_monotonic_time, 6425 struct GNUNET_TIME_AbsoluteNBO sender_monotonic_time,
6372 const struct GNUNET_PeerIdentity *init, 6426 const struct GNUNET_PeerIdentity *init,
6373 const struct ChallengeNonceP *challenge, 6427 const struct ChallengeNonceP *challenge,
6374 const struct GNUNET_CRYPTO_EddsaSignature *init_sig) 6428 const struct GNUNET_CRYPTO_EddsaSignature *init_sig)
6375{ 6429{
6376 struct DvInitPS ip = { .purpose.purpose = htonl( 6430 struct DvInitPS ip = { .purpose.purpose = htonl (
6377 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), 6431 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR),
6378 .purpose.size = htonl(sizeof(ip)), 6432 .purpose.size = htonl (sizeof(ip)),
6379 .monotonic_time = sender_monotonic_time, 6433 .monotonic_time = sender_monotonic_time,
6380 .challenge = *challenge }; 6434 .challenge = *challenge };
6381 6435
6382 if ( 6436 if (
6383 GNUNET_OK != 6437 GNUNET_OK !=
6384 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, 6438 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR,
6385 &ip.purpose, 6439 &ip.purpose,
6386 init_sig, 6440 init_sig,
6387 &init->public_key)) 6441 &init->public_key))
6388 { 6442 {
6389 GNUNET_break_op(0); 6443 GNUNET_break_op (0);
6390 return GNUNET_SYSERR; 6444 return GNUNET_SYSERR;
6391 } 6445 }
6392 return GNUNET_OK; 6446 return GNUNET_OK;
6393} 6447}
6394 6448
@@ -6396,7 +6450,8 @@ validate_dv_initiator_signature(
6396/** 6450/**
6397 * Closure for #dv_neighbour_selection and #dv_neighbour_transmission. 6451 * Closure for #dv_neighbour_selection and #dv_neighbour_transmission.
6398 */ 6452 */
6399struct NeighbourSelectionContext { 6453struct NeighbourSelectionContext
6454{
6400 /** 6455 /**
6401 * Original message we received. 6456 * Original message we received.
6402 */ 6457 */
@@ -6448,17 +6503,17 @@ struct NeighbourSelectionContext {
6448 * @return #GNUNET_YES (always) 6503 * @return #GNUNET_YES (always)
6449 */ 6504 */
6450static int 6505static int
6451dv_neighbour_selection(void *cls, 6506dv_neighbour_selection (void *cls,
6452 const struct GNUNET_PeerIdentity *pid, 6507 const struct GNUNET_PeerIdentity *pid,
6453 void *value) 6508 void *value)
6454{ 6509{
6455 struct NeighbourSelectionContext *nsc = cls; 6510 struct NeighbourSelectionContext *nsc = cls;
6456 6511
6457 (void)value; 6512 (void) value;
6458 if (0 == GNUNET_memcmp(pid, &nsc->dvl->initiator)) 6513 if (0 == GNUNET_memcmp (pid, &nsc->dvl->initiator))
6459 return GNUNET_YES; /* skip initiator */ 6514 return GNUNET_YES; /* skip initiator */
6460 for (unsigned int i = 0; i < nsc->nhops; i++) 6515 for (unsigned int i = 0; i < nsc->nhops; i++)
6461 if (0 == GNUNET_memcmp(pid, &nsc->hops[i].hop)) 6516 if (0 == GNUNET_memcmp (pid, &nsc->hops[i].hop))
6462 return GNUNET_YES; 6517 return GNUNET_YES;
6463 /* skip peers on path */ 6518 /* skip peers on path */
6464 nsc->num_eligible++; 6519 nsc->num_eligible++;
@@ -6477,32 +6532,32 @@ dv_neighbour_selection(void *cls,
6477 * @return #GNUNET_YES (always) 6532 * @return #GNUNET_YES (always)
6478 */ 6533 */
6479static int 6534static int
6480dv_neighbour_transmission(void *cls, 6535dv_neighbour_transmission (void *cls,
6481 const struct GNUNET_PeerIdentity *pid, 6536 const struct GNUNET_PeerIdentity *pid,
6482 void *value) 6537 void *value)
6483{ 6538{
6484 struct NeighbourSelectionContext *nsc = cls; 6539 struct NeighbourSelectionContext *nsc = cls;
6485 6540
6486 (void)value; 6541 (void) value;
6487 if (0 == GNUNET_memcmp(pid, &nsc->dvl->initiator)) 6542 if (0 == GNUNET_memcmp (pid, &nsc->dvl->initiator))
6488 return GNUNET_YES; /* skip initiator */ 6543 return GNUNET_YES; /* skip initiator */
6489 for (unsigned int i = 0; i < nsc->nhops; i++) 6544 for (unsigned int i = 0; i < nsc->nhops; i++)
6490 if (0 == GNUNET_memcmp(pid, &nsc->hops[i].hop)) 6545 if (0 == GNUNET_memcmp (pid, &nsc->hops[i].hop))
6491 return GNUNET_YES; 6546 return GNUNET_YES;
6492 /* skip peers on path */ 6547 /* skip peers on path */
6493 for (unsigned int i = 0; i < nsc->num_selections; i++) 6548 for (unsigned int i = 0; i < nsc->num_selections; i++)
6494 { 6549 {
6495 if (nsc->selections[i] == nsc->num_eligible) 6550 if (nsc->selections[i] == nsc->num_eligible)
6496 { 6551 {
6497 forward_dv_learn(pid, 6552 forward_dv_learn (pid,
6498 nsc->dvl, 6553 nsc->dvl,
6499 nsc->bi_history, 6554 nsc->bi_history,
6500 nsc->nhops, 6555 nsc->nhops,
6501 nsc->hops, 6556 nsc->hops,
6502 nsc->in_time); 6557 nsc->in_time);
6503 break; 6558 break;
6504 }
6505 } 6559 }
6560 }
6506 nsc->num_eligible++; 6561 nsc->num_eligible++;
6507 return GNUNET_YES; 6562 return GNUNET_YES;
6508} 6563}
@@ -6552,42 +6607,42 @@ dv_neighbour_transmission(void *cls,
6552 * theory forward to 6607 * theory forward to
6553 */ 6608 */
6554static unsigned int 6609static unsigned int
6555calculate_fork_degree(unsigned int hops_taken, 6610calculate_fork_degree (unsigned int hops_taken,
6556 unsigned int neighbour_count, 6611 unsigned int neighbour_count,
6557 unsigned int eligible_count) 6612 unsigned int eligible_count)
6558{ 6613{
6559 double target_total = 50.0; /* FIXME: use LOG(NSE)? */ 6614 double target_total = 50.0; /* FIXME: use LOG(NSE)? */
6560 double eligible_ratio = 6615 double eligible_ratio =
6561 ((double)eligible_count) / ((double)neighbour_count); 6616 ((double) eligible_count) / ((double) neighbour_count);
6562 double boost_factor = eligible_ratio * eligible_ratio; 6617 double boost_factor = eligible_ratio * eligible_ratio;
6563 unsigned int rnd; 6618 unsigned int rnd;
6564 double left; 6619 double left;
6565 6620
6566 if (hops_taken >= 64) 6621 if (hops_taken >= 64)
6567 { 6622 {
6568 GNUNET_break(0); 6623 GNUNET_break (0);
6569 return 0; /* precaution given bitshift below */ 6624 return 0; /* precaution given bitshift below */
6570 } 6625 }
6571 for (unsigned int i = 1; i < hops_taken; i++) 6626 for (unsigned int i = 1; i < hops_taken; i++)
6572 { 6627 {
6573 /* For each hop, subtract the expected number of targets 6628 /* For each hop, subtract the expected number of targets
6574 reached at distance d (so what remains divided by 2^d) */ 6629 reached at distance d (so what remains divided by 2^d) */
6575 target_total -= (target_total * boost_factor / (1LLU << i)); 6630 target_total -= (target_total * boost_factor / (1LLU << i));
6576 } 6631 }
6577 rnd = 6632 rnd =
6578 (unsigned int)floor(target_total * boost_factor / (1LLU << hops_taken)); 6633 (unsigned int) floor (target_total * boost_factor / (1LLU << hops_taken));
6579 /* round up or down probabilistically depending on how close we were 6634 /* round up or down probabilistically depending on how close we were
6580 when floor()ing to rnd */ 6635 when floor()ing to rnd */
6581 left = target_total - (double)rnd; 6636 left = target_total - (double) rnd;
6582 if (UINT32_MAX * left > 6637 if (UINT32_MAX * left >
6583 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)) 6638 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX))
6584 rnd++; /* round up */ 6639 rnd++; /* round up */
6585 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6586 "Forwarding DV learn message of %u hops %u(/%u/%u) times\n", 6641 "Forwarding DV learn message of %u hops %u(/%u/%u) times\n",
6587 hops_taken, 6642 hops_taken,
6588 rnd, 6643 rnd,
6589 eligible_count, 6644 eligible_count,
6590 neighbour_count); 6645 neighbour_count);
6591 return rnd; 6646 return rnd;
6592} 6647}
6593 6648
@@ -6599,14 +6654,14 @@ calculate_fork_degree(unsigned int hops_taken,
6599 * @param success #GNUNET_YES if peerstore was successful 6654 * @param success #GNUNET_YES if peerstore was successful
6600 */ 6655 */
6601static void 6656static void
6602neighbour_store_dvmono_cb(void *cls, int success) 6657neighbour_store_dvmono_cb (void *cls, int success)
6603{ 6658{
6604 struct Neighbour *n = cls; 6659 struct Neighbour *n = cls;
6605 6660
6606 n->sc = NULL; 6661 n->sc = NULL;
6607 if (GNUNET_YES != success) 6662 if (GNUNET_YES != success)
6608 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 6663 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6609 "Failed to store other peer's monotonic time in peerstore!\n"); 6664 "Failed to store other peer's monotonic time in peerstore!\n");
6610} 6665}
6611 6666
6612 6667
@@ -6618,7 +6673,7 @@ neighbour_store_dvmono_cb(void *cls, int success)
6618 * @param dvl the message that was received 6673 * @param dvl the message that was received
6619 */ 6674 */
6620static void 6675static void
6621handle_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl) 6676handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
6622{ 6677{
6623 struct CommunicatorMessageContext *cmc = cls; 6678 struct CommunicatorMessageContext *cmc = cls;
6624 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; 6679 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
@@ -6631,287 +6686,287 @@ handle_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl)
6631 struct GNUNET_TIME_Absolute in_time; 6686 struct GNUNET_TIME_Absolute in_time;
6632 struct Neighbour *n; 6687 struct Neighbour *n;
6633 6688
6634 nhops = ntohs(dvl->bidirectional); /* 0 = sender is initiator */ 6689 nhops = ntohs (dvl->bidirectional); /* 0 = sender is initiator */
6635 bi_history = ntohs(dvl->bidirectional); 6690 bi_history = ntohs (dvl->bidirectional);
6636 hops = (const struct DVPathEntryP *)&dvl[1]; 6691 hops = (const struct DVPathEntryP *) &dvl[1];
6637 if (0 == nhops) 6692 if (0 == nhops)
6693 {
6694 /* sanity check */
6695 if (0 != GNUNET_memcmp (&dvl->initiator, &cmc->im.sender))
6638 { 6696 {
6639 /* sanity check */ 6697 GNUNET_break (0);
6640 if (0 != GNUNET_memcmp(&dvl->initiator, &cmc->im.sender)) 6698 finish_cmc_handling (cmc);
6641 { 6699 return;
6642 GNUNET_break(0);
6643 finish_cmc_handling(cmc);
6644 return;
6645 }
6646 } 6700 }
6701 }
6647 else 6702 else
6703 {
6704 /* sanity check */
6705 if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, &cmc->im.sender))
6648 { 6706 {
6649 /* sanity check */ 6707 GNUNET_break (0);
6650 if (0 != GNUNET_memcmp(&hops[nhops - 1].hop, &cmc->im.sender)) 6708 finish_cmc_handling (cmc);
6651 { 6709 return;
6652 GNUNET_break(0);
6653 finish_cmc_handling(cmc);
6654 return;
6655 }
6656 } 6710 }
6711 }
6657 6712
6658 GNUNET_assert(CT_COMMUNICATOR == cmc->tc->type); 6713 GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type);
6659 cc = cmc->tc->details.communicator.cc; 6714 cc = cmc->tc->details.communicator.cc;
6660 bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE == 6715 bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE ==
6661 cc); // FIXME: add bi-directional flag to cc? 6716 cc); // FIXME: add bi-directional flag to cc?
6662 in_time = GNUNET_TIME_absolute_get(); 6717 in_time = GNUNET_TIME_absolute_get ();
6663 6718
6664 /* continue communicator here, everything else can happen asynchronous! */ 6719 /* continue communicator here, everything else can happen asynchronous! */
6665 finish_cmc_handling(cmc); 6720 finish_cmc_handling (cmc);
6666 6721
6667 n = lookup_neighbour(&dvl->initiator); 6722 n = lookup_neighbour (&dvl->initiator);
6668 if (NULL != n) 6723 if (NULL != n)
6724 {
6725 if ((n->dv_monotime_available == GNUNET_YES) &&
6726 (GNUNET_TIME_absolute_ntoh (dvl->monotonic_time).abs_value_us <
6727 n->last_dv_learn_monotime.abs_value_us))
6728 {
6729 GNUNET_STATISTICS_update (GST_stats,
6730 "# DV learn discarded due to time travel",
6731 1,
6732 GNUNET_NO);
6733 return;
6734 }
6735 if (GNUNET_OK != validate_dv_initiator_signature (dvl->monotonic_time,
6736 &dvl->initiator,
6737 &dvl->challenge,
6738 &dvl->init_sig))
6669 { 6739 {
6670 if ((n->dv_monotime_available == GNUNET_YES) && 6740 GNUNET_break_op (0);
6671 (GNUNET_TIME_absolute_ntoh(dvl->monotonic_time).abs_value_us < 6741 return;
6672 n->last_dv_learn_monotime.abs_value_us)) 6742 }
6673 { 6743 n->last_dv_learn_monotime = GNUNET_TIME_absolute_ntoh (dvl->monotonic_time);
6674 GNUNET_STATISTICS_update(GST_stats, 6744 if (GNUNET_YES == n->dv_monotime_available)
6675 "# DV learn discarded due to time travel", 6745 {
6676 1, 6746 if (NULL != n->sc)
6677 GNUNET_NO); 6747 GNUNET_PEERSTORE_store_cancel (n->sc);
6678 return; 6748 n->sc =
6679 } 6749 GNUNET_PEERSTORE_store (peerstore,
6680 if (GNUNET_OK != validate_dv_initiator_signature(dvl->monotonic_time, 6750 "transport",
6681 &dvl->initiator, 6751 &dvl->initiator,
6682 &dvl->challenge, 6752 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME,
6683 &dvl->init_sig)) 6753 &dvl->monotonic_time,
6684 { 6754 sizeof(dvl->monotonic_time),
6685 GNUNET_break_op(0); 6755 GNUNET_TIME_UNIT_FOREVER_ABS,
6686 return; 6756 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
6687 } 6757 &neighbour_store_dvmono_cb,
6688 n->last_dv_learn_monotime = GNUNET_TIME_absolute_ntoh(dvl->monotonic_time); 6758 n);
6689 if (GNUNET_YES == n->dv_monotime_available)
6690 {
6691 if (NULL != n->sc)
6692 GNUNET_PEERSTORE_store_cancel(n->sc);
6693 n->sc =
6694 GNUNET_PEERSTORE_store(peerstore,
6695 "transport",
6696 &dvl->initiator,
6697 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME,
6698 &dvl->monotonic_time,
6699 sizeof(dvl->monotonic_time),
6700 GNUNET_TIME_UNIT_FOREVER_ABS,
6701 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
6702 &neighbour_store_dvmono_cb,
6703 n);
6704 }
6705 } 6759 }
6760 }
6706 /* OPTIMIZE-FIXME: asynchronously (!) verify signatures!, 6761 /* OPTIMIZE-FIXME: asynchronously (!) verify signatures!,
6707 If signature verification load too high, implement random drop strategy */ 6762 If signature verification load too high, implement random drop strategy */
6708 for (unsigned int i = 0; i < nhops; i++) 6763 for (unsigned int i = 0; i < nhops; i++)
6709 { 6764 {
6710 struct DvHopPS dhp = { .purpose.purpose = 6765 struct DvHopPS dhp = { .purpose.purpose =
6711 htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), 6766 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP),
6712 .purpose.size = htonl(sizeof(dhp)), 6767 .purpose.size = htonl (sizeof(dhp)),
6713 .pred = (0 == i) ? dvl->initiator : hops[i - 1].hop, 6768 .pred = (0 == i) ? dvl->initiator : hops[i - 1].hop,
6714 .succ = (nhops == i + 1) ? GST_my_identity 6769 .succ = (nhops == i + 1) ? GST_my_identity
6715 : hops[i + 1].hop, 6770 : hops[i + 1].hop,
6716 .challenge = dvl->challenge }; 6771 .challenge = dvl->challenge };
6717 6772
6718 if (GNUNET_OK != 6773 if (GNUNET_OK !=
6719 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP, 6774 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP,
6720 &dhp.purpose, 6775 &dhp.purpose,
6721 &hops[i].hop_sig, 6776 &hops[i].hop_sig,
6722 &hops[i].hop.public_key)) 6777 &hops[i].hop.public_key))
6723 { 6778 {
6724 GNUNET_break_op(0); 6779 GNUNET_break_op (0);
6725 return; 6780 return;
6726 }
6727 } 6781 }
6782 }
6728 6783
6729 if (GNUNET_EXTRA_LOGGING > 0) 6784 if (GNUNET_EXTRA_LOGGING > 0)
6730 { 6785 {
6731 char *path; 6786 char *path;
6732 6787
6733 path = GNUNET_strdup(GNUNET_i2s(&dvl->initiator)); 6788 path = GNUNET_strdup (GNUNET_i2s (&dvl->initiator));
6734 for (unsigned int i = 0; i < nhops; i++) 6789 for (unsigned int i = 0; i < nhops; i++)
6735 { 6790 {
6736 char *tmp; 6791 char *tmp;
6737 6792
6738 GNUNET_asprintf(&tmp, 6793 GNUNET_asprintf (&tmp,
6739 "%s%s%s", 6794 "%s%s%s",
6740 path, 6795 path,
6741 (bi_history & (1 << (nhops - i))) ? "<->" : "-->", 6796 (bi_history & (1 << (nhops - i))) ? "<->" : "-->",
6742 GNUNET_i2s(&hops[i].hop)); 6797 GNUNET_i2s (&hops[i].hop));
6743 GNUNET_free(path); 6798 GNUNET_free (path);
6744 path = tmp; 6799 path = tmp;
6745 } 6800 }
6746 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6747 "Received DVInit via %s%s%s\n", 6802 "Received DVInit via %s%s%s\n",
6748 path, 6803 path,
6749 bi_hop ? "<->" : "-->", 6804 bi_hop ? "<->" : "-->",
6750 GNUNET_i2s(&GST_my_identity)); 6805 GNUNET_i2s (&GST_my_identity));
6751 GNUNET_free(path); 6806 GNUNET_free (path);
6752 } 6807 }
6753 6808
6754 do_fwd = GNUNET_YES; 6809 do_fwd = GNUNET_YES;
6755 if (0 == GNUNET_memcmp(&GST_my_identity, &dvl->initiator)) 6810 if (0 == GNUNET_memcmp (&GST_my_identity, &dvl->initiator))
6756 { 6811 {
6757 struct GNUNET_PeerIdentity path[nhops + 1]; 6812 struct GNUNET_PeerIdentity path[nhops + 1];
6758 struct GNUNET_TIME_Relative host_latency_sum; 6813 struct GNUNET_TIME_Relative host_latency_sum;
6759 struct GNUNET_TIME_Relative latency; 6814 struct GNUNET_TIME_Relative latency;
6760 struct GNUNET_TIME_Relative network_latency; 6815 struct GNUNET_TIME_Relative network_latency;
6761 6816
6762 /* We initiated this, learn the forward path! */ 6817 /* We initiated this, learn the forward path! */
6763 path[0] = GST_my_identity; 6818 path[0] = GST_my_identity;
6764 path[1] = hops[0].hop; 6819 path[1] = hops[0].hop;
6765 host_latency_sum = GNUNET_TIME_relative_ntoh(dvl->non_network_delay); 6820 host_latency_sum = GNUNET_TIME_relative_ntoh (dvl->non_network_delay);
6766 6821
6767 // Need also something to lookup initiation time 6822 // Need also something to lookup initiation time
6768 // to compute RTT! -> add RTT argument here? 6823 // to compute RTT! -> add RTT argument here?
6769 latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly 6824 latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly
6770 // (based on dvl->challenge, we can identify time of origin!) 6825 // (based on dvl->challenge, we can identify time of origin!)
6771 6826
6772 network_latency = GNUNET_TIME_relative_subtract(latency, host_latency_sum); 6827 network_latency = GNUNET_TIME_relative_subtract (latency, host_latency_sum);
6773 /* assumption: latency on all links is the same */ 6828 /* assumption: latency on all links is the same */
6774 network_latency = GNUNET_TIME_relative_divide(network_latency, nhops); 6829 network_latency = GNUNET_TIME_relative_divide (network_latency, nhops);
6775 6830
6776 for (unsigned int i = 2; i <= nhops; i++) 6831 for (unsigned int i = 2; i <= nhops; i++)
6777 { 6832 {
6778 struct GNUNET_TIME_Relative ilat; 6833 struct GNUNET_TIME_Relative ilat;
6779 6834
6780 /* assumption: linear latency increase per hop */ 6835 /* assumption: linear latency increase per hop */
6781 ilat = GNUNET_TIME_relative_multiply(network_latency, i); 6836 ilat = GNUNET_TIME_relative_multiply (network_latency, i);
6782 path[i] = hops[i - 1].hop; 6837 path[i] = hops[i - 1].hop;
6783 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6784 "Learned path with %u hops to %s with latency %s\n", 6839 "Learned path with %u hops to %s with latency %s\n",
6840 i,
6841 GNUNET_i2s (&path[i]),
6842 GNUNET_STRINGS_relative_time_to_string (ilat, GNUNET_YES));
6843 learn_dv_path (path,
6785 i, 6844 i,
6786 GNUNET_i2s(&path[i]), 6845 ilat,
6787 GNUNET_STRINGS_relative_time_to_string(ilat, GNUNET_YES)); 6846 GNUNET_TIME_relative_to_absolute (
6788 learn_dv_path(path, 6847 ADDRESS_VALIDATION_LIFETIME));
6789 i,
6790 ilat,
6791 GNUNET_TIME_relative_to_absolute(
6792 ADDRESS_VALIDATION_LIFETIME));
6793 }
6794 /* as we initiated, do not forward again (would be circular!) */
6795 do_fwd = GNUNET_NO;
6796 return;
6797 } 6848 }
6849 /* as we initiated, do not forward again (would be circular!) */
6850 do_fwd = GNUNET_NO;
6851 return;
6852 }
6798 if (bi_hop) 6853 if (bi_hop)
6854 {
6855 /* last hop was bi-directional, we could learn something here! */
6856 struct GNUNET_PeerIdentity path[nhops + 2];
6857
6858 path[0] = GST_my_identity;
6859 path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */
6860 for (unsigned int i = 0; i < nhops; i++)
6799 { 6861 {
6800 /* last hop was bi-directional, we could learn something here! */ 6862 int iret;
6801 struct GNUNET_PeerIdentity path[nhops + 2];
6802 6863
6803 path[0] = GST_my_identity; 6864 if (0 == (bi_history & (1 << i)))
6804 path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */ 6865 break; /* i-th hop not bi-directional, stop learning! */
6805 for (unsigned int i = 0; i < nhops; i++) 6866 if (i == nhops - 1)
6806 { 6867 {
6807 int iret; 6868 path[i + 2] = dvl->initiator;
6808 6869 }
6809 if (0 == (bi_history & (1 << i))) 6870 else
6810 break; /* i-th hop not bi-directional, stop learning! */ 6871 {
6811 if (i == nhops - 1) 6872 path[i + 2] = hops[nhops - i - 2].hop;
6812 { 6873 }
6813 path[i + 2] = dvl->initiator; 6874
6814 } 6875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6815 else 6876 "Learned inverse path with %u hops to %s\n",
6816 { 6877 i + 1,
6817 path[i + 2] = hops[nhops - i - 2].hop; 6878 GNUNET_i2s (&path[i + 2]));
6818 } 6879 iret = learn_dv_path (path,
6819 6880 i + 2,
6820 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6881 GNUNET_TIME_UNIT_FOREVER_REL,
6821 "Learned inverse path with %u hops to %s\n", 6882 GNUNET_TIME_UNIT_ZERO_ABS);
6822 i + 1, 6883 if (GNUNET_SYSERR == iret)
6823 GNUNET_i2s(&path[i + 2])); 6884 {
6824 iret = learn_dv_path(path, 6885 /* path invalid or too long to be interesting for US, thus should also
6825 i + 2, 6886 not be interesting to our neighbours, cut path when forwarding to
6826 GNUNET_TIME_UNIT_FOREVER_REL, 6887 'i' hops, except of course for the one that goes back to the
6827 GNUNET_TIME_UNIT_ZERO_ABS); 6888 initiator */
6828 if (GNUNET_SYSERR == iret) 6889 GNUNET_STATISTICS_update (GST_stats,
6829 { 6890 "# DV learn not forwarded due invalidity of path",
6830 /* path invalid or too long to be interesting for US, thus should also 6891 1,
6831 not be interesting to our neighbours, cut path when forwarding to 6892 GNUNET_NO);
6832 'i' hops, except of course for the one that goes back to the 6893 do_fwd = GNUNET_NO;
6833 initiator */ 6894 break;
6834 GNUNET_STATISTICS_update(GST_stats, 6895 }
6835 "# DV learn not forwarded due invalidity of path", 6896 if ((GNUNET_NO == iret) && (nhops == i + 1))
6836 1, 6897 {
6837 GNUNET_NO); 6898 /* we have better paths, and this is the longest target,
6838 do_fwd = GNUNET_NO; 6899 so there cannot be anything interesting later */
6839 break; 6900 GNUNET_STATISTICS_update (GST_stats,
6840 } 6901 "# DV learn not forwarded, got better paths",
6841 if ((GNUNET_NO == iret) && (nhops == i + 1)) 6902 1,
6842 { 6903 GNUNET_NO);
6843 /* we have better paths, and this is the longest target, 6904 do_fwd = GNUNET_NO;
6844 so there cannot be anything interesting later */ 6905 break;
6845 GNUNET_STATISTICS_update(GST_stats, 6906 }
6846 "# DV learn not forwarded, got better paths",
6847 1,
6848 GNUNET_NO);
6849 do_fwd = GNUNET_NO;
6850 break;
6851 }
6852 }
6853 } 6907 }
6908 }
6854 6909
6855 if (MAX_DV_HOPS_ALLOWED == nhops) 6910 if (MAX_DV_HOPS_ALLOWED == nhops)
6856 { 6911 {
6857 /* At limit, we're out of here! */ 6912 /* At limit, we're out of here! */
6858 finish_cmc_handling(cmc); 6913 finish_cmc_handling (cmc);
6859 return; 6914 return;
6860 } 6915 }
6861 6916
6862 /* Forward to initiator, if path non-trivial and possible */ 6917 /* Forward to initiator, if path non-trivial and possible */
6863 bi_history = (bi_history << 1) | (bi_hop ? 1 : 0); 6918 bi_history = (bi_history << 1) | (bi_hop ? 1 : 0);
6864 did_initiator = GNUNET_NO; 6919 did_initiator = GNUNET_NO;
6865 if ((1 < nhops) && 6920 if ((1 < nhops) &&
6866 (GNUNET_YES == 6921 (GNUNET_YES ==
6867 GNUNET_CONTAINER_multipeermap_contains(neighbours, &dvl->initiator))) 6922 GNUNET_CONTAINER_multipeermap_contains (neighbours, &dvl->initiator)))
6868 { 6923 {
6869 /* send back to origin! */ 6924 /* send back to origin! */
6870 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6871 "Sending DVL back to initiator %s\n", 6926 "Sending DVL back to initiator %s\n",
6872 GNUNET_i2s(&dvl->initiator)); 6927 GNUNET_i2s (&dvl->initiator));
6873 forward_dv_learn(&dvl->initiator, dvl, bi_history, nhops, hops, in_time); 6928 forward_dv_learn (&dvl->initiator, dvl, bi_history, nhops, hops, in_time);
6874 did_initiator = GNUNET_YES; 6929 did_initiator = GNUNET_YES;
6875 } 6930 }
6876 /* We forward under two conditions: either we still learned something 6931 /* We forward under two conditions: either we still learned something
6877 ourselves (do_fwd), or the path was darn short and thus the initiator is 6932 ourselves (do_fwd), or the path was darn short and thus the initiator is
6878 likely to still be very interested in this (and we did NOT already 6933 likely to still be very interested in this (and we did NOT already
6879 send it back to the initiator) */ 6934 send it back to the initiator) */
6880 if ((do_fwd) || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) && 6935 if ((do_fwd) || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) &&
6881 (GNUNET_NO == did_initiator))) 6936 (GNUNET_NO == did_initiator)))
6882 { 6937 {
6883 /* Pick random neighbours that are not yet on the path */ 6938 /* Pick random neighbours that are not yet on the path */
6884 struct NeighbourSelectionContext nsc; 6939 struct NeighbourSelectionContext nsc;
6885 unsigned int n_cnt; 6940 unsigned int n_cnt;
6886 6941
6887 n_cnt = GNUNET_CONTAINER_multipeermap_size(neighbours); 6942 n_cnt = GNUNET_CONTAINER_multipeermap_size (neighbours);
6888 nsc.nhops = nhops; 6943 nsc.nhops = nhops;
6889 nsc.dvl = dvl; 6944 nsc.dvl = dvl;
6890 nsc.bi_history = bi_history; 6945 nsc.bi_history = bi_history;
6891 nsc.hops = hops; 6946 nsc.hops = hops;
6892 nsc.in_time = in_time; 6947 nsc.in_time = in_time;
6893 nsc.num_eligible = 0; 6948 nsc.num_eligible = 0;
6894 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 6949 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
6895 &dv_neighbour_selection, 6950 &dv_neighbour_selection,
6896 &nsc); 6951 &nsc);
6897 if (0 == nsc.num_eligible) 6952 if (0 == nsc.num_eligible)
6898 return; /* done here, cannot forward to anyone else */ 6953 return; /* done here, cannot forward to anyone else */
6899 nsc.num_selections = calculate_fork_degree(nhops, n_cnt, nsc.num_eligible); 6954 nsc.num_selections = calculate_fork_degree (nhops, n_cnt, nsc.num_eligible);
6900 nsc.num_selections = 6955 nsc.num_selections =
6901 GNUNET_MIN(MAX_DV_DISCOVERY_SELECTION, nsc.num_selections); 6956 GNUNET_MIN (MAX_DV_DISCOVERY_SELECTION, nsc.num_selections);
6902 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 6957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6903 "Forwarding DVL to %u other peers\n", 6958 "Forwarding DVL to %u other peers\n",
6904 nsc.num_selections); 6959 nsc.num_selections);
6905 for (unsigned int i = 0; i < nsc.num_selections; i++) 6960 for (unsigned int i = 0; i < nsc.num_selections; i++)
6906 nsc.selections[i] = 6961 nsc.selections[i] =
6907 (nsc.num_selections == n_cnt) 6962 (nsc.num_selections == n_cnt)
6908 ? i /* all were selected, avoid collisions by chance */ 6963 ? i /* all were selected, avoid collisions by chance */
6909 : GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, n_cnt); 6964 : GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, n_cnt);
6910 nsc.num_eligible = 0; 6965 nsc.num_eligible = 0;
6911 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 6966 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
6912 &dv_neighbour_transmission, 6967 &dv_neighbour_transmission,
6913 &nsc); 6968 &nsc);
6914 } 6969 }
6915} 6970}
6916 6971
6917 6972
@@ -6923,27 +6978,27 @@ handle_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl)
6923 * @return #GNUNET_YES if message is well-formed 6978 * @return #GNUNET_YES if message is well-formed
6924 */ 6979 */
6925static int 6980static int
6926check_dv_box(void *cls, const struct TransportDVBoxMessage *dvb) 6981check_dv_box (void *cls, const struct TransportDVBoxMessage *dvb)
6927{ 6982{
6928 uint16_t size = ntohs(dvb->header.size); 6983 uint16_t size = ntohs (dvb->header.size);
6929 uint16_t num_hops = ntohs(dvb->num_hops); 6984 uint16_t num_hops = ntohs (dvb->num_hops);
6930 const struct GNUNET_PeerIdentity *hops = 6985 const struct GNUNET_PeerIdentity *hops =
6931 (const struct GNUNET_PeerIdentity *)&dvb[1]; 6986 (const struct GNUNET_PeerIdentity *) &dvb[1];
6932 6987
6933 (void)cls; 6988 (void) cls;
6934 if (size < sizeof(*dvb) + num_hops * sizeof(struct GNUNET_PeerIdentity) + 6989 if (size < sizeof(*dvb) + num_hops * sizeof(struct GNUNET_PeerIdentity)
6935 sizeof(struct GNUNET_MessageHeader)) 6990 + sizeof(struct GNUNET_MessageHeader))
6991 {
6992 GNUNET_break_op (0);
6993 return GNUNET_SYSERR;
6994 }
6995 /* This peer must not be on the path */
6996 for (unsigned int i = 0; i < num_hops; i++)
6997 if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity))
6936 { 6998 {
6937 GNUNET_break_op(0); 6999 GNUNET_break_op (0);
6938 return GNUNET_SYSERR; 7000 return GNUNET_SYSERR;
6939 } 7001 }
6940 /* This peer must not be on the path */
6941 for (unsigned int i = 0; i < num_hops; i++)
6942 if (0 == GNUNET_memcmp(&hops[i], &GST_my_identity))
6943 {
6944 GNUNET_break_op(0);
6945 return GNUNET_SYSERR;
6946 }
6947 return GNUNET_YES; 7002 return GNUNET_YES;
6948} 7003}
6949 7004
@@ -6961,13 +7016,13 @@ check_dv_box(void *cls, const struct TransportDVBoxMessage *dvb)
6961 * @param payload_size number of bytes in @a payload 7016 * @param payload_size number of bytes in @a payload
6962 */ 7017 */
6963static void 7018static void
6964forward_dv_box(struct Neighbour *next_hop, 7019forward_dv_box (struct Neighbour *next_hop,
6965 const struct TransportDVBoxMessage *hdr, 7020 const struct TransportDVBoxMessage *hdr,
6966 uint16_t total_hops, 7021 uint16_t total_hops,
6967 uint16_t num_hops, 7022 uint16_t num_hops,
6968 const struct GNUNET_PeerIdentity *hops, 7023 const struct GNUNET_PeerIdentity *hops,
6969 const void *enc_payload, 7024 const void *enc_payload,
6970 uint16_t enc_payload_size) 7025 uint16_t enc_payload_size)
6971{ 7026{
6972 struct VirtualLink *vl = next_hop->vl; 7027 struct VirtualLink *vl = next_hop->vl;
6973 struct PendingMessage *pm; 7028 struct PendingMessage *pm;
@@ -6975,33 +7030,33 @@ forward_dv_box(struct Neighbour *next_hop,
6975 char *buf; 7030 char *buf;
6976 struct GNUNET_PeerIdentity *dhops; 7031 struct GNUNET_PeerIdentity *dhops;
6977 7032
6978 GNUNET_assert(NULL != vl); 7033 GNUNET_assert (NULL != vl);
6979 msg_size = sizeof(struct TransportDVBoxMessage) + 7034 msg_size = sizeof(struct TransportDVBoxMessage)
6980 num_hops * sizeof(struct GNUNET_PeerIdentity) + enc_payload_size; 7035 + num_hops * sizeof(struct GNUNET_PeerIdentity) + enc_payload_size;
6981 pm = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size); 7036 pm = GNUNET_malloc (sizeof(struct PendingMessage) + msg_size);
6982 pm->pmt = PMT_DV_BOX; 7037 pm->pmt = PMT_DV_BOX;
6983 pm->vl = vl; 7038 pm->vl = vl;
6984 pm->timeout = GNUNET_TIME_relative_to_absolute(DV_FORWARD_TIMEOUT); 7039 pm->timeout = GNUNET_TIME_relative_to_absolute (DV_FORWARD_TIMEOUT);
6985 pm->logging_uuid = logging_uuid_gen++; 7040 pm->logging_uuid = logging_uuid_gen++;
6986 pm->prefs = GNUNET_MQ_PRIO_BACKGROUND; 7041 pm->prefs = GNUNET_MQ_PRIO_BACKGROUND;
6987 pm->bytes_msg = msg_size; 7042 pm->bytes_msg = msg_size;
6988 buf = (char *)&pm[1]; 7043 buf = (char *) &pm[1];
6989 memcpy(buf, hdr, sizeof(*hdr)); 7044 memcpy (buf, hdr, sizeof(*hdr));
6990 dhops = 7045 dhops =
6991 (struct GNUNET_PeerIdentity *)&buf[sizeof(struct TransportDVBoxMessage)]; 7046 (struct GNUNET_PeerIdentity *) &buf[sizeof(struct TransportDVBoxMessage)];
6992 memcpy(dhops, hops, num_hops * sizeof(struct GNUNET_PeerIdentity)); 7047 memcpy (dhops, hops, num_hops * sizeof(struct GNUNET_PeerIdentity));
6993 memcpy(&dhops[num_hops], enc_payload, enc_payload_size); 7048 memcpy (&dhops[num_hops], enc_payload, enc_payload_size);
6994 GNUNET_CONTAINER_MDLL_insert(vl, 7049 GNUNET_CONTAINER_MDLL_insert (vl,
6995 vl->pending_msg_head, 7050 vl->pending_msg_head,
6996 vl->pending_msg_tail, 7051 vl->pending_msg_tail,
6997 pm); 7052 pm);
6998 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 7053 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6999 "Created pending message %llu for DV Box with next hop %s (%u/%u)\n", 7054 "Created pending message %llu for DV Box with next hop %s (%u/%u)\n",
7000 pm->logging_uuid, 7055 pm->logging_uuid,
7001 GNUNET_i2s(&next_hop->pid), 7056 GNUNET_i2s (&next_hop->pid),
7002 (unsigned int)num_hops, 7057 (unsigned int) num_hops,
7003 (unsigned int)total_hops); 7058 (unsigned int) total_hops);
7004 check_vl_transmission(vl); 7059 check_vl_transmission (vl);
7005} 7060}
7006 7061
7007 7062
@@ -7011,30 +7066,30 @@ forward_dv_box(struct Neighbour *next_hop,
7011 * @param b data structure to release 7066 * @param b data structure to release
7012 */ 7067 */
7013static void 7068static void
7014free_backtalker(struct Backtalker *b) 7069free_backtalker (struct Backtalker *b)
7015{ 7070{
7016 if (NULL != b->get) 7071 if (NULL != b->get)
7017 { 7072 {
7018 GNUNET_PEERSTORE_iterate_cancel(b->get); 7073 GNUNET_PEERSTORE_iterate_cancel (b->get);
7019 b->get = NULL; 7074 b->get = NULL;
7020 GNUNET_assert(NULL != b->cmc); 7075 GNUNET_assert (NULL != b->cmc);
7021 finish_cmc_handling(b->cmc); 7076 finish_cmc_handling (b->cmc);
7022 b->cmc = NULL; 7077 b->cmc = NULL;
7023 } 7078 }
7024 if (NULL != b->task) 7079 if (NULL != b->task)
7025 { 7080 {
7026 GNUNET_SCHEDULER_cancel(b->task); 7081 GNUNET_SCHEDULER_cancel (b->task);
7027 b->task = NULL; 7082 b->task = NULL;
7028 } 7083 }
7029 if (NULL != b->sc) 7084 if (NULL != b->sc)
7030 { 7085 {
7031 GNUNET_PEERSTORE_store_cancel(b->sc); 7086 GNUNET_PEERSTORE_store_cancel (b->sc);
7032 b->sc = NULL; 7087 b->sc = NULL;
7033 } 7088 }
7034 GNUNET_assert( 7089 GNUNET_assert (
7035 GNUNET_YES == 7090 GNUNET_YES ==
7036 GNUNET_CONTAINER_multipeermap_remove(backtalkers, &b->pid, b)); 7091 GNUNET_CONTAINER_multipeermap_remove (backtalkers, &b->pid, b));
7037 GNUNET_free(b); 7092 GNUNET_free (b);
7038} 7093}
7039 7094
7040 7095
@@ -7047,15 +7102,15 @@ free_backtalker(struct Backtalker *b)
7047 * @return #GNUNET_OK (always) 7102 * @return #GNUNET_OK (always)
7048 */ 7103 */
7049static int 7104static int
7050free_backtalker_cb(void *cls, 7105free_backtalker_cb (void *cls,
7051 const struct GNUNET_PeerIdentity *pid, 7106 const struct GNUNET_PeerIdentity *pid,
7052 void *value) 7107 void *value)
7053{ 7108{
7054 struct Backtalker *b = value; 7109 struct Backtalker *b = value;
7055 7110
7056 (void)cls; 7111 (void) cls;
7057 (void)pid; 7112 (void) pid;
7058 free_backtalker(b); 7113 free_backtalker (b);
7059 return GNUNET_OK; 7114 return GNUNET_OK;
7060} 7115}
7061 7116
@@ -7066,18 +7121,18 @@ free_backtalker_cb(void *cls,
7066 * @param cls a `struct Backtalker` 7121 * @param cls a `struct Backtalker`
7067 */ 7122 */
7068static void 7123static void
7069backtalker_timeout_cb(void *cls) 7124backtalker_timeout_cb (void *cls)
7070{ 7125{
7071 struct Backtalker *b = cls; 7126 struct Backtalker *b = cls;
7072 7127
7073 b->task = NULL; 7128 b->task = NULL;
7074 if (0 != GNUNET_TIME_absolute_get_remaining(b->timeout).rel_value_us) 7129 if (0 != GNUNET_TIME_absolute_get_remaining (b->timeout).rel_value_us)
7075 { 7130 {
7076 b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b); 7131 b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b);
7077 return; 7132 return;
7078 } 7133 }
7079 GNUNET_assert(NULL == b->sc); 7134 GNUNET_assert (NULL == b->sc);
7080 free_backtalker(b); 7135 free_backtalker (b);
7081} 7136}
7082 7137
7083 7138
@@ -7090,52 +7145,52 @@ backtalker_timeout_cb(void *cls)
7090 * @param emsg error message 7145 * @param emsg error message
7091 */ 7146 */
7092static void 7147static void
7093backtalker_monotime_cb(void *cls, 7148backtalker_monotime_cb (void *cls,
7094 const struct GNUNET_PEERSTORE_Record *record, 7149 const struct GNUNET_PEERSTORE_Record *record,
7095 const char *emsg) 7150 const char *emsg)
7096{ 7151{
7097 struct Backtalker *b = cls; 7152 struct Backtalker *b = cls;
7098 struct GNUNET_TIME_AbsoluteNBO *mtbe; 7153 struct GNUNET_TIME_AbsoluteNBO *mtbe;
7099 struct GNUNET_TIME_Absolute mt; 7154 struct GNUNET_TIME_Absolute mt;
7100 7155
7101 (void)emsg; 7156 (void) emsg;
7102 if (NULL == record) 7157 if (NULL == record)
7103 { 7158 {
7104 /* we're done with #backtalker_monotime_cb() invocations, 7159 /* we're done with #backtalker_monotime_cb() invocations,
7105 continue normal processing */ 7160 continue normal processing */
7106 b->get = NULL; 7161 b->get = NULL;
7107 GNUNET_assert(NULL != b->cmc); 7162 GNUNET_assert (NULL != b->cmc);
7108 if (0 != b->body_size) 7163 if (0 != b->body_size)
7109 demultiplex_with_cmc(b->cmc, 7164 demultiplex_with_cmc (b->cmc,
7110 (const struct GNUNET_MessageHeader *)&b[1]); 7165 (const struct GNUNET_MessageHeader *) &b[1]);
7111 else 7166 else
7112 finish_cmc_handling(b->cmc); 7167 finish_cmc_handling (b->cmc);
7113 b->cmc = NULL; 7168 b->cmc = NULL;
7114 return; 7169 return;
7115 } 7170 }
7116 if (sizeof(*mtbe) != record->value_size) 7171 if (sizeof(*mtbe) != record->value_size)
7117 { 7172 {
7118 GNUNET_break(0); 7173 GNUNET_break (0);
7119 return; 7174 return;
7120 } 7175 }
7121 mtbe = record->value; 7176 mtbe = record->value;
7122 mt = GNUNET_TIME_absolute_ntoh(*mtbe); 7177 mt = GNUNET_TIME_absolute_ntoh (*mtbe);
7123 if (mt.abs_value_us > b->monotonic_time.abs_value_us) 7178 if (mt.abs_value_us > b->monotonic_time.abs_value_us)
7124 { 7179 {
7125 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 7180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7126 "Backtalker message from %s dropped, monotime in the past\n", 7181 "Backtalker message from %s dropped, monotime in the past\n",
7127 GNUNET_i2s(&b->pid)); 7182 GNUNET_i2s (&b->pid));
7128 GNUNET_STATISTICS_update( 7183 GNUNET_STATISTICS_update (
7129 GST_stats, 7184 GST_stats,
7130 "# Backchannel messages dropped: monotonic time not increasing", 7185 "# Backchannel messages dropped: monotonic time not increasing",
7131 1, 7186 1,
7132 GNUNET_NO); 7187 GNUNET_NO);
7133 b->monotonic_time = mt; 7188 b->monotonic_time = mt;
7134 /* Setting body_size to 0 prevents call to #forward_backchannel_payload() 7189 /* Setting body_size to 0 prevents call to #forward_backchannel_payload()
7135 */ 7190 */
7136 b->body_size = 0; 7191 b->body_size = 0;
7137 return; 7192 return;
7138 } 7193 }
7139} 7194}
7140 7195
7141 7196
@@ -7147,17 +7202,17 @@ backtalker_monotime_cb(void *cls,
7147 * @param success #GNUNET_OK on success 7202 * @param success #GNUNET_OK on success
7148 */ 7203 */
7149static void 7204static void
7150backtalker_monotime_store_cb(void *cls, int success) 7205backtalker_monotime_store_cb (void *cls, int success)
7151{ 7206{
7152 struct Backtalker *b = cls; 7207 struct Backtalker *b = cls;
7153 7208
7154 if (GNUNET_OK != success) 7209 if (GNUNET_OK != success)
7155 { 7210 {
7156 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 7211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
7157 "Failed to store backtalker's monotonic time in PEERSTORE!\n"); 7212 "Failed to store backtalker's monotonic time in PEERSTORE!\n");
7158 } 7213 }
7159 b->sc = NULL; 7214 b->sc = NULL;
7160 b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b); 7215 b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b);
7161} 7216}
7162 7217
7163 7218
@@ -7167,32 +7222,32 @@ backtalker_monotime_store_cb(void *cls, int success)
7167 * @param b a backtalker with updated monotonic time 7222 * @param b a backtalker with updated monotonic time
7168 */ 7223 */
7169static void 7224static void
7170update_backtalker_monotime(struct Backtalker *b) 7225update_backtalker_monotime (struct Backtalker *b)
7171{ 7226{
7172 struct GNUNET_TIME_AbsoluteNBO mtbe; 7227 struct GNUNET_TIME_AbsoluteNBO mtbe;
7173 7228
7174 if (NULL != b->sc) 7229 if (NULL != b->sc)
7175 { 7230 {
7176 GNUNET_PEERSTORE_store_cancel(b->sc); 7231 GNUNET_PEERSTORE_store_cancel (b->sc);
7177 b->sc = NULL; 7232 b->sc = NULL;
7178 } 7233 }
7179 else 7234 else
7180 { 7235 {
7181 GNUNET_SCHEDULER_cancel(b->task); 7236 GNUNET_SCHEDULER_cancel (b->task);
7182 b->task = NULL; 7237 b->task = NULL;
7183 } 7238 }
7184 mtbe = GNUNET_TIME_absolute_hton(b->monotonic_time); 7239 mtbe = GNUNET_TIME_absolute_hton (b->monotonic_time);
7185 b->sc = 7240 b->sc =
7186 GNUNET_PEERSTORE_store(peerstore, 7241 GNUNET_PEERSTORE_store (peerstore,
7187 "transport", 7242 "transport",
7188 &b->pid, 7243 &b->pid,
7189 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, 7244 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME,
7190 &mtbe, 7245 &mtbe,
7191 sizeof(mtbe), 7246 sizeof(mtbe),
7192 GNUNET_TIME_UNIT_FOREVER_ABS, 7247 GNUNET_TIME_UNIT_FOREVER_ABS,
7193 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 7248 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
7194 &backtalker_monotime_store_cb, 7249 &backtalker_monotime_store_cb,
7195 b); 7250 b);
7196} 7251}
7197 7252
7198 7253
@@ -7204,14 +7259,14 @@ update_backtalker_monotime(struct Backtalker *b)
7204 * @param dvb the message that was received 7259 * @param dvb the message that was received
7205 */ 7260 */
7206static void 7261static void
7207handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb) 7262handle_dv_box (void *cls, const struct TransportDVBoxMessage *dvb)
7208{ 7263{
7209 struct CommunicatorMessageContext *cmc = cls; 7264 struct CommunicatorMessageContext *cmc = cls;
7210 uint16_t size = ntohs(dvb->header.size) - sizeof(*dvb); 7265 uint16_t size = ntohs (dvb->header.size) - sizeof(*dvb);
7211 uint16_t num_hops = ntohs(dvb->num_hops); 7266 uint16_t num_hops = ntohs (dvb->num_hops);
7212 const struct GNUNET_PeerIdentity *hops = 7267 const struct GNUNET_PeerIdentity *hops =
7213 (const struct GNUNET_PeerIdentity *)&dvb[1]; 7268 (const struct GNUNET_PeerIdentity *) &dvb[1];
7214 const char *enc_payload = (const char *)&hops[num_hops]; 7269 const char *enc_payload = (const char *) &hops[num_hops];
7215 uint16_t enc_payload_size = 7270 uint16_t enc_payload_size =
7216 size - (num_hops * sizeof(struct GNUNET_PeerIdentity)); 7271 size - (num_hops * sizeof(struct GNUNET_PeerIdentity));
7217 struct DVKeyState key; 7272 struct DVKeyState key;
@@ -7220,89 +7275,89 @@ handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb)
7220 size_t hdr_len; 7275 size_t hdr_len;
7221 7276
7222 if (GNUNET_EXTRA_LOGGING > 0) 7277 if (GNUNET_EXTRA_LOGGING > 0)
7223 { 7278 {
7224 char *path; 7279 char *path;
7225 7280
7226 path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity)); 7281 path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity));
7227 for (unsigned int i = 0; i < num_hops; i++) 7282 for (unsigned int i = 0; i < num_hops; i++)
7228 { 7283 {
7229 char *tmp; 7284 char *tmp;
7230 7285
7231 GNUNET_asprintf(&tmp, "%s->%s", path, GNUNET_i2s(&hops[i])); 7286 GNUNET_asprintf (&tmp, "%s->%s", path, GNUNET_i2s (&hops[i]));
7232 GNUNET_free(path); 7287 GNUNET_free (path);
7233 path = tmp; 7288 path = tmp;
7234 }
7235 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7236 "Received DVBox with remainig path %s\n",
7237 path);
7238 GNUNET_free(path);
7239 } 7289 }
7290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7291 "Received DVBox with remainig path %s\n",
7292 path);
7293 GNUNET_free (path);
7294 }
7240 7295
7241 if (num_hops > 0) 7296 if (num_hops > 0)
7297 {
7298 /* We're trying from the end of the hops array, as we may be
7299 able to find a shortcut unknown to the origin that way */
7300 for (int i = num_hops - 1; i >= 0; i--)
7242 { 7301 {
7243 /* We're trying from the end of the hops array, as we may be 7302 struct Neighbour *n;
7244 able to find a shortcut unknown to the origin that way */ 7303
7245 for (int i = num_hops - 1; i >= 0; i--) 7304 if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity))
7246 { 7305 {
7247 struct Neighbour *n; 7306 GNUNET_break_op (0);
7248 7307 finish_cmc_handling (cmc);
7249 if (0 == GNUNET_memcmp(&hops[i], &GST_my_identity)) 7308 return;
7250 { 7309 }
7251 GNUNET_break_op(0); 7310 n = lookup_neighbour (&hops[i]);
7252 finish_cmc_handling(cmc); 7311 if (NULL == n)
7253 return; 7312 continue;
7254 } 7313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7255 n = lookup_neighbour(&hops[i]); 7314 "Skipping %u/%u hops ahead while routing DV Box\n",
7256 if (NULL == n) 7315 i,
7257 continue; 7316 num_hops);
7258 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 7317 forward_dv_box (n,
7259 "Skipping %u/%u hops ahead while routing DV Box\n", 7318 dvb,
7260 i, 7319 ntohs (dvb->total_hops) + 1,
7261 num_hops); 7320 num_hops - i - 1, /* number of hops left */
7262 forward_dv_box(n, 7321 &hops[i + 1], /* remaining hops */
7263 dvb, 7322 enc_payload,
7264 ntohs(dvb->total_hops) + 1, 7323 enc_payload_size);
7265 num_hops - i - 1, /* number of hops left */ 7324 GNUNET_STATISTICS_update (GST_stats,
7266 &hops[i + 1], /* remaining hops */ 7325 "# DV hops skipped routing boxes",
7267 enc_payload, 7326 i,
7268 enc_payload_size); 7327 GNUNET_NO);
7269 GNUNET_STATISTICS_update(GST_stats, 7328 GNUNET_STATISTICS_update (GST_stats,
7270 "# DV hops skipped routing boxes", 7329 "# DV boxes routed (total)",
7271 i, 7330 1,
7272 GNUNET_NO); 7331 GNUNET_NO);
7273 GNUNET_STATISTICS_update(GST_stats, 7332 finish_cmc_handling (cmc);
7274 "# DV boxes routed (total)",
7275 1,
7276 GNUNET_NO);
7277 finish_cmc_handling(cmc);
7278 return;
7279 }
7280 /* Woopsie, next hop not in neighbours, drop! */
7281 GNUNET_STATISTICS_update(GST_stats,
7282 "# DV Boxes dropped: next hop unknown",
7283 1,
7284 GNUNET_NO);
7285 finish_cmc_handling(cmc);
7286 return; 7333 return;
7287 } 7334 }
7335 /* Woopsie, next hop not in neighbours, drop! */
7336 GNUNET_STATISTICS_update (GST_stats,
7337 "# DV Boxes dropped: next hop unknown",
7338 1,
7339 GNUNET_NO);
7340 finish_cmc_handling (cmc);
7341 return;
7342 }
7288 /* We are the target. Unbox and handle message. */ 7343 /* We are the target. Unbox and handle message. */
7289 GNUNET_STATISTICS_update(GST_stats, 7344 GNUNET_STATISTICS_update (GST_stats,
7290 "# DV boxes opened (ultimate target)", 7345 "# DV boxes opened (ultimate target)",
7291 1, 7346 1,
7292 GNUNET_NO); 7347 GNUNET_NO);
7293 cmc->total_hops = ntohs(dvb->total_hops); 7348 cmc->total_hops = ntohs (dvb->total_hops);
7294 7349
7295 dh_key_derive_eph_pub(&dvb->ephemeral_key, &dvb->iv, &key); 7350 dh_key_derive_eph_pub (&dvb->ephemeral_key, &dvb->iv, &key);
7296 hdr = (const char *)&dvb[1]; 7351 hdr = (const char *) &dvb[1];
7297 hdr_len = ntohs(dvb->header.size) - sizeof(*dvb); 7352 hdr_len = ntohs (dvb->header.size) - sizeof(*dvb);
7298 dv_hmac(&key, &hmac, hdr, hdr_len); 7353 dv_hmac (&key, &hmac, hdr, hdr_len);
7299 if (0 != GNUNET_memcmp(&hmac, &dvb->hmac)) 7354 if (0 != GNUNET_memcmp (&hmac, &dvb->hmac))
7300 { 7355 {
7301 /* HMAC missmatch, disard! */ 7356 /* HMAC missmatch, disard! */
7302 GNUNET_break_op(0); 7357 GNUNET_break_op (0);
7303 finish_cmc_handling(cmc); 7358 finish_cmc_handling (cmc);
7304 return; 7359 return;
7305 } 7360 }
7306 /* begin actual decryption */ 7361 /* begin actual decryption */
7307 { 7362 {
7308 struct Backtalker *b; 7363 struct Backtalker *b;
@@ -7310,117 +7365,118 @@ handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb)
7310 struct TransportDVBoxPayloadP ppay; 7365 struct TransportDVBoxPayloadP ppay;
7311 char body[hdr_len - sizeof(ppay)] GNUNET_ALIGN; 7366 char body[hdr_len - sizeof(ppay)] GNUNET_ALIGN;
7312 const struct GNUNET_MessageHeader *mh = 7367 const struct GNUNET_MessageHeader *mh =
7313 (const struct GNUNET_MessageHeader *)body; 7368 (const struct GNUNET_MessageHeader *) body;
7314 7369
7315 GNUNET_assert(hdr_len >= 7370 GNUNET_assert (hdr_len >=
7316 sizeof(ppay) + sizeof(struct GNUNET_MessageHeader)); 7371 sizeof(ppay) + sizeof(struct GNUNET_MessageHeader));
7317 dv_decrypt(&key, &ppay, hdr, sizeof(ppay)); 7372 dv_decrypt (&key, &ppay, hdr, sizeof(ppay));
7318 dv_decrypt(&key, &body, &hdr[sizeof(ppay)], hdr_len - sizeof(ppay)); 7373 dv_decrypt (&key, &body, &hdr[sizeof(ppay)], hdr_len - sizeof(ppay));
7319 dv_key_clean(&key); 7374 dv_key_clean (&key);
7320 if (ntohs(mh->size) != sizeof(body)) 7375 if (ntohs (mh->size) != sizeof(body))
7321 { 7376 {
7322 GNUNET_break_op(0); 7377 GNUNET_break_op (0);
7323 finish_cmc_handling(cmc); 7378 finish_cmc_handling (cmc);
7324 return; 7379 return;
7325 } 7380 }
7326 /* need to prevent box-in-a-box (and DV_LEARN) so check inbox type! */ 7381 /* need to prevent box-in-a-box (and DV_LEARN) so check inbox type! */
7327 switch (ntohs(mh->type)) 7382 switch (ntohs (mh->type))
7328 { 7383 {
7329 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX: 7384 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX:
7330 GNUNET_break_op(0); 7385 GNUNET_break_op (0);
7331 finish_cmc_handling(cmc); 7386 finish_cmc_handling (cmc);
7332 return; 7387 return;
7333 7388
7334 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN: 7389 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN:
7335 GNUNET_break_op(0); 7390 GNUNET_break_op (0);
7336 finish_cmc_handling(cmc); 7391 finish_cmc_handling (cmc);
7337 return; 7392 return;
7338 7393
7339 default: 7394 default:
7340 /* permitted, continue */ 7395 /* permitted, continue */
7341 break; 7396 break;
7342 } 7397 }
7343 monotime = GNUNET_TIME_absolute_ntoh(ppay.monotonic_time); 7398 monotime = GNUNET_TIME_absolute_ntoh (ppay.monotonic_time);
7344 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 7399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7345 "Decrypted backtalk from %s\n", 7400 "Decrypted backtalk from %s\n",
7346 GNUNET_i2s(&ppay.sender)); 7401 GNUNET_i2s (&ppay.sender));
7347 b = GNUNET_CONTAINER_multipeermap_get(backtalkers, &ppay.sender); 7402 b = GNUNET_CONTAINER_multipeermap_get (backtalkers, &ppay.sender);
7348 if ((NULL != b) && (monotime.abs_value_us < b->monotonic_time.abs_value_us)) 7403 if ((NULL != b) && (monotime.abs_value_us < b->monotonic_time.abs_value_us))
7349 { 7404 {
7350 GNUNET_STATISTICS_update( 7405 GNUNET_STATISTICS_update (
7351 GST_stats, 7406 GST_stats,
7352 "# Backchannel messages dropped: monotonic time not increasing", 7407 "# Backchannel messages dropped: monotonic time not increasing",
7353 1, 7408 1,
7354 GNUNET_NO); 7409 GNUNET_NO);
7355 finish_cmc_handling(cmc); 7410 finish_cmc_handling (cmc);
7356 return; 7411 return;
7357 } 7412 }
7358 if ((NULL == b) || 7413 if ((NULL == b) ||
7359 (0 != GNUNET_memcmp(&b->last_ephemeral, &dvb->ephemeral_key))) 7414 (0 != GNUNET_memcmp (&b->last_ephemeral, &dvb->ephemeral_key)))
7415 {
7416 /* Check signature */
7417 struct EphemeralConfirmationPS ec;
7418
7419 ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
7420 ec.purpose.size = htonl (sizeof(ec));
7421 ec.target = GST_my_identity;
7422 ec.ephemeral_key = dvb->ephemeral_key;
7423 if (
7424 GNUNET_OK !=
7425 GNUNET_CRYPTO_eddsa_verify (
7426 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL,
7427 &ec.purpose,
7428 &ppay.sender_sig,
7429 &ppay.sender.public_key))
7360 { 7430 {
7361 /* Check signature */ 7431 /* Signature invalid, disard! */
7362 struct EphemeralConfirmationPS ec; 7432 GNUNET_break_op (0);
7363 7433 finish_cmc_handling (cmc);
7364 ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); 7434 return;
7365 ec.purpose.size = htonl(sizeof(ec));
7366 ec.target = GST_my_identity;
7367 ec.ephemeral_key = dvb->ephemeral_key;
7368 if (
7369 GNUNET_OK !=
7370 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL,
7371 &ec.purpose,
7372 &ppay.sender_sig,
7373 &ppay.sender.public_key))
7374 {
7375 /* Signature invalid, disard! */
7376 GNUNET_break_op(0);
7377 finish_cmc_handling(cmc);
7378 return;
7379 }
7380 } 7435 }
7436 }
7381 /* Update sender, we now know the real origin! */ 7437 /* Update sender, we now know the real origin! */
7382 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 7438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7383 "DVBox received for me from %s via %s\n", 7439 "DVBox received for me from %s via %s\n",
7384 GNUNET_i2s2(&ppay.sender), 7440 GNUNET_i2s2 (&ppay.sender),
7385 GNUNET_i2s(&cmc->im.sender)); 7441 GNUNET_i2s (&cmc->im.sender));
7386 cmc->im.sender = ppay.sender; 7442 cmc->im.sender = ppay.sender;
7387 7443
7388 if (NULL != b) 7444 if (NULL != b)
7389 { 7445 {
7390 /* update key cache and mono time */ 7446 /* update key cache and mono time */
7391 b->last_ephemeral = dvb->ephemeral_key; 7447 b->last_ephemeral = dvb->ephemeral_key;
7392 b->monotonic_time = monotime; 7448 b->monotonic_time = monotime;
7393 update_backtalker_monotime(b); 7449 update_backtalker_monotime (b);
7394 b->timeout = 7450 b->timeout =
7395 GNUNET_TIME_relative_to_absolute(BACKCHANNEL_INACTIVITY_TIMEOUT); 7451 GNUNET_TIME_relative_to_absolute (BACKCHANNEL_INACTIVITY_TIMEOUT);
7396 7452
7397 demultiplex_with_cmc(cmc, mh); 7453 demultiplex_with_cmc (cmc, mh);
7398 return; 7454 return;
7399 } 7455 }
7400 /* setup data structure to cache signature AND check 7456 /* setup data structure to cache signature AND check
7401 monotonic time with PEERSTORE before forwarding backchannel payload */ 7457 monotonic time with PEERSTORE before forwarding backchannel payload */
7402 b = GNUNET_malloc(sizeof(struct Backtalker) + sizeof(body)); 7458 b = GNUNET_malloc (sizeof(struct Backtalker) + sizeof(body));
7403 b->pid = ppay.sender; 7459 b->pid = ppay.sender;
7404 b->body_size = sizeof(body); 7460 b->body_size = sizeof(body);
7405 memcpy(&b[1], body, sizeof(body)); 7461 memcpy (&b[1], body, sizeof(body));
7406 GNUNET_assert(GNUNET_YES == 7462 GNUNET_assert (GNUNET_YES ==
7407 GNUNET_CONTAINER_multipeermap_put( 7463 GNUNET_CONTAINER_multipeermap_put (
7408 backtalkers, 7464 backtalkers,
7409 &b->pid, 7465 &b->pid,
7410 b, 7466 b,
7411 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 7467 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
7412 b->monotonic_time = monotime; /* NOTE: to be checked still! */ 7468 b->monotonic_time = monotime; /* NOTE: to be checked still! */
7413 b->cmc = cmc; 7469 b->cmc = cmc;
7414 b->timeout = 7470 b->timeout =
7415 GNUNET_TIME_relative_to_absolute(BACKCHANNEL_INACTIVITY_TIMEOUT); 7471 GNUNET_TIME_relative_to_absolute (BACKCHANNEL_INACTIVITY_TIMEOUT);
7416 b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b); 7472 b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b);
7417 b->get = 7473 b->get =
7418 GNUNET_PEERSTORE_iterate(peerstore, 7474 GNUNET_PEERSTORE_iterate (peerstore,
7419 "transport", 7475 "transport",
7420 &b->pid, 7476 &b->pid,
7421 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, 7477 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME,
7422 &backtalker_monotime_cb, 7478 &backtalker_monotime_cb,
7423 b); 7479 b);
7424 } /* end actual decryption */ 7480 } /* end actual decryption */
7425} 7481}
7426 7482
@@ -7433,17 +7489,17 @@ handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb)
7433 * @return #GNUNET_YES if message is well-formed 7489 * @return #GNUNET_YES if message is well-formed
7434 */ 7490 */
7435static int 7491static int
7436check_incoming_msg(void *cls, 7492check_incoming_msg (void *cls,
7437 const struct GNUNET_TRANSPORT_IncomingMessage *im) 7493 const struct GNUNET_TRANSPORT_IncomingMessage *im)
7438{ 7494{
7439 struct TransportClient *tc = cls; 7495 struct TransportClient *tc = cls;
7440 7496
7441 if (CT_COMMUNICATOR != tc->type) 7497 if (CT_COMMUNICATOR != tc->type)
7442 { 7498 {
7443 GNUNET_break(0); 7499 GNUNET_break (0);
7444 return GNUNET_SYSERR; 7500 return GNUNET_SYSERR;
7445 } 7501 }
7446 GNUNET_MQ_check_boxed_message(im); 7502 GNUNET_MQ_check_boxed_message (im);
7447 return GNUNET_OK; 7503 return GNUNET_OK;
7448} 7504}
7449 7505
@@ -7451,7 +7507,8 @@ check_incoming_msg(void *cls,
7451/** 7507/**
7452 * Closure for #check_known_address. 7508 * Closure for #check_known_address.
7453 */ 7509 */
7454struct CheckKnownAddressContext { 7510struct CheckKnownAddressContext
7511{
7455 /** 7512 /**
7456 * Set to the address we are looking for. 7513 * Set to the address we are looking for.
7457 */ 7514 */
@@ -7474,15 +7531,15 @@ struct CheckKnownAddressContext {
7474 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found 7531 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found
7475 */ 7532 */
7476static int 7533static int
7477check_known_address(void *cls, 7534check_known_address (void *cls,
7478 const struct GNUNET_PeerIdentity *pid, 7535 const struct GNUNET_PeerIdentity *pid,
7479 void *value) 7536 void *value)
7480{ 7537{
7481 struct CheckKnownAddressContext *ckac = cls; 7538 struct CheckKnownAddressContext *ckac = cls;
7482 struct ValidationState *vs = value; 7539 struct ValidationState *vs = value;
7483 7540
7484 (void)pid; 7541 (void) pid;
7485 if (0 != strcmp(vs->address, ckac->address)) 7542 if (0 != strcmp (vs->address, ckac->address))
7486 return GNUNET_OK; 7543 return GNUNET_OK;
7487 ckac->vs = vs; 7544 ckac->vs = vs;
7488 return GNUNET_NO; 7545 return GNUNET_NO;
@@ -7495,7 +7552,7 @@ check_known_address(void *cls,
7495 * @param cls NULL 7552 * @param cls NULL
7496 */ 7553 */
7497static void 7554static void
7498validation_start_cb(void *cls); 7555validation_start_cb (void *cls);
7499 7556
7500 7557
7501/** 7558/**
@@ -7506,8 +7563,8 @@ validation_start_cb(void *cls);
7506 * @param new_time new time for revalidation 7563 * @param new_time new time for revalidation
7507 */ 7564 */
7508static void 7565static void
7509update_next_challenge_time(struct ValidationState *vs, 7566update_next_challenge_time (struct ValidationState *vs,
7510 struct GNUNET_TIME_Absolute new_time) 7567 struct GNUNET_TIME_Absolute new_time)
7511{ 7568{
7512 struct GNUNET_TIME_Relative delta; 7569 struct GNUNET_TIME_Relative delta;
7513 7570
@@ -7516,21 +7573,21 @@ update_next_challenge_time(struct ValidationState *vs,
7516 vs->next_challenge = new_time; 7573 vs->next_challenge = new_time;
7517 if (NULL == vs->hn) 7574 if (NULL == vs->hn)
7518 vs->hn = 7575 vs->hn =
7519 GNUNET_CONTAINER_heap_insert(validation_heap, vs, new_time.abs_value_us); 7576 GNUNET_CONTAINER_heap_insert (validation_heap, vs, new_time.abs_value_us);
7520 else 7577 else
7521 GNUNET_CONTAINER_heap_update_cost(vs->hn, new_time.abs_value_us); 7578 GNUNET_CONTAINER_heap_update_cost (vs->hn, new_time.abs_value_us);
7522 if ((vs != GNUNET_CONTAINER_heap_peek(validation_heap)) && 7579 if ((vs != GNUNET_CONTAINER_heap_peek (validation_heap)) &&
7523 (NULL != validation_task)) 7580 (NULL != validation_task))
7524 return; 7581 return;
7525 if (NULL != validation_task) 7582 if (NULL != validation_task)
7526 GNUNET_SCHEDULER_cancel(validation_task); 7583 GNUNET_SCHEDULER_cancel (validation_task);
7527 /* randomize a bit */ 7584 /* randomize a bit */
7528 delta.rel_value_us = 7585 delta.rel_value_us =
7529 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, 7586 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
7530 MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); 7587 MIN_DELAY_ADDRESS_VALIDATION.rel_value_us);
7531 new_time = GNUNET_TIME_absolute_add(new_time, delta); 7588 new_time = GNUNET_TIME_absolute_add (new_time, delta);
7532 validation_task = 7589 validation_task =
7533 GNUNET_SCHEDULER_add_at(new_time, &validation_start_cb, NULL); 7590 GNUNET_SCHEDULER_add_at (new_time, &validation_start_cb, NULL);
7534} 7591}
7535 7592
7536 7593
@@ -7541,57 +7598,58 @@ update_next_challenge_time(struct ValidationState *vs,
7541 * @param address an address to reach @a pid (presumably) 7598 * @param address an address to reach @a pid (presumably)
7542 */ 7599 */
7543static void 7600static void
7544start_address_validation(const struct GNUNET_PeerIdentity *pid, 7601start_address_validation (const struct GNUNET_PeerIdentity *pid,
7545 const char *address) 7602 const char *address)
7546{ 7603{
7547 struct GNUNET_TIME_Absolute now; 7604 struct GNUNET_TIME_Absolute now;
7548 struct ValidationState *vs; 7605 struct ValidationState *vs;
7549 struct CheckKnownAddressContext ckac = { .address = address, .vs = NULL }; 7606 struct CheckKnownAddressContext ckac = { .address = address, .vs = NULL };
7550 7607
7551 (void)GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, 7608 (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
7552 pid, 7609 pid,
7553 &check_known_address, 7610 &check_known_address,
7554 &ckac); 7611 &ckac);
7555 if (NULL != (vs = ckac.vs)) 7612 if (NULL != (vs = ckac.vs))
7556 { 7613 {
7557 /* if 'vs' is not currently valid, we need to speed up retrying the 7614 /* if 'vs' is not currently valid, we need to speed up retrying the
7558 * validation */ 7615 * validation */
7559 if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) 7616 if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us)
7560 { 7617 {
7561 /* reduce backoff as we got a fresh advertisement */ 7618 /* reduce backoff as we got a fresh advertisement */
7562 vs->challenge_backoff = 7619 vs->challenge_backoff =
7563 GNUNET_TIME_relative_min(FAST_VALIDATION_CHALLENGE_FREQ, 7620 GNUNET_TIME_relative_min (FAST_VALIDATION_CHALLENGE_FREQ,
7564 GNUNET_TIME_relative_divide(vs->challenge_backoff, 7621 GNUNET_TIME_relative_divide (
7565 2)); 7622 vs->challenge_backoff,
7566 update_next_challenge_time(vs, 7623 2));
7567 GNUNET_TIME_relative_to_absolute( 7624 update_next_challenge_time (vs,
7568 vs->challenge_backoff)); 7625 GNUNET_TIME_relative_to_absolute (
7569 } 7626 vs->challenge_backoff));
7570 return;
7571 } 7627 }
7572 now = GNUNET_TIME_absolute_get(); 7628 return;
7573 vs = GNUNET_new(struct ValidationState); 7629 }
7630 now = GNUNET_TIME_absolute_get ();
7631 vs = GNUNET_new (struct ValidationState);
7574 vs->pid = *pid; 7632 vs->pid = *pid;
7575 vs->valid_until = 7633 vs->valid_until =
7576 GNUNET_TIME_relative_to_absolute(ADDRESS_VALIDATION_LIFETIME); 7634 GNUNET_TIME_relative_to_absolute (ADDRESS_VALIDATION_LIFETIME);
7577 vs->first_challenge_use = now; 7635 vs->first_challenge_use = now;
7578 vs->validation_rtt = GNUNET_TIME_UNIT_FOREVER_REL; 7636 vs->validation_rtt = GNUNET_TIME_UNIT_FOREVER_REL;
7579 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, 7637 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
7580 &vs->challenge, 7638 &vs->challenge,
7581 sizeof(vs->challenge)); 7639 sizeof(vs->challenge));
7582 vs->address = GNUNET_strdup(address); 7640 vs->address = GNUNET_strdup (address);
7583 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 7641 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7584 "Starting address validation `%s' of peer %s using challenge %s\n", 7642 "Starting address validation `%s' of peer %s using challenge %s\n",
7585 address, 7643 address,
7586 GNUNET_i2s(pid), 7644 GNUNET_i2s (pid),
7587 GNUNET_sh2s(&vs->challenge.value)); 7645 GNUNET_sh2s (&vs->challenge.value));
7588 GNUNET_assert(GNUNET_YES == 7646 GNUNET_assert (GNUNET_YES ==
7589 GNUNET_CONTAINER_multipeermap_put( 7647 GNUNET_CONTAINER_multipeermap_put (
7590 validation_map, 7648 validation_map,
7591 &vs->pid, 7649 &vs->pid,
7592 vs, 7650 vs,
7593 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 7651 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
7594 update_next_challenge_time(vs, now); 7652 update_next_challenge_time (vs, now);
7595} 7653}
7596 7654
7597 7655
@@ -7603,27 +7661,27 @@ start_address_validation(const struct GNUNET_PeerIdentity *pid,
7603 * @param emsg error message, or NULL if no errors 7661 * @param emsg error message, or NULL if no errors
7604 */ 7662 */
7605static void 7663static void
7606handle_hello_for_incoming(void *cls, 7664handle_hello_for_incoming (void *cls,
7607 const struct GNUNET_PEERSTORE_Record *record, 7665 const struct GNUNET_PEERSTORE_Record *record,
7608 const char *emsg) 7666 const char *emsg)
7609{ 7667{
7610 struct IncomingRequest *ir = cls; 7668 struct IncomingRequest *ir = cls;
7611 const char *val; 7669 const char *val;
7612 7670
7613 if (NULL != emsg) 7671 if (NULL != emsg)
7614 { 7672 {
7615 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 7673 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
7616 "Got failure from PEERSTORE: %s\n", 7674 "Got failure from PEERSTORE: %s\n",
7617 emsg); 7675 emsg);
7618 return; 7676 return;
7619 } 7677 }
7620 val = record->value; 7678 val = record->value;
7621 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) 7679 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1]))
7622 { 7680 {
7623 GNUNET_break(0); 7681 GNUNET_break (0);
7624 return; 7682 return;
7625 } 7683 }
7626 start_address_validation(&ir->pid, (const char *)record->value); 7684 start_address_validation (&ir->pid, (const char *) record->value);
7627} 7685}
7628 7686
7629 7687
@@ -7636,7 +7694,7 @@ handle_hello_for_incoming(void *cls,
7636 * @param tvc the message that was received 7694 * @param tvc the message that was received
7637 */ 7695 */
7638static void 7696static void
7639handle_validation_challenge( 7697handle_validation_challenge (
7640 void *cls, 7698 void *cls,
7641 const struct TransportValidationChallengeMessage *tvc) 7699 const struct TransportValidationChallengeMessage *tvc)
7642{ 7700{
@@ -7650,44 +7708,44 @@ handle_validation_challenge(
7650 7708
7651 /* DV-routed messages are not allowed for validation challenges */ 7709 /* DV-routed messages are not allowed for validation challenges */
7652 if (cmc->total_hops > 0) 7710 if (cmc->total_hops > 0)
7653 { 7711 {
7654 GNUNET_break_op(0); 7712 GNUNET_break_op (0);
7655 finish_cmc_handling(cmc); 7713 finish_cmc_handling (cmc);
7656 return; 7714 return;
7657 } 7715 }
7658 validity_duration = cmc->im.expected_address_validity; 7716 validity_duration = cmc->im.expected_address_validity;
7659 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 7717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7660 "Received address validation challenge %s\n", 7718 "Received address validation challenge %s\n",
7661 GNUNET_sh2s(&tvc->challenge.value)); 7719 GNUNET_sh2s (&tvc->challenge.value));
7662 /* If we have a virtual link, we use this mechanism to signal the 7720 /* If we have a virtual link, we use this mechanism to signal the
7663 size of the flow control window, and to allow the sender 7721 size of the flow control window, and to allow the sender
7664 to ask for increases. If for us the virtual link is still down, 7722 to ask for increases. If for us the virtual link is still down,
7665 we will always give a window size of zero. */ 7723 we will always give a window size of zero. */
7666 tvr.header.type = 7724 tvr.header.type =
7667 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); 7725 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE);
7668 tvr.header.size = htons(sizeof(tvr)); 7726 tvr.header.size = htons (sizeof(tvr));
7669 tvr.reserved = htonl(0); 7727 tvr.reserved = htonl (0);
7670 tvr.challenge = tvc->challenge; 7728 tvr.challenge = tvc->challenge;
7671 tvr.origin_time = tvc->sender_time; 7729 tvr.origin_time = tvc->sender_time;
7672 tvr.validity_duration = validity_duration; 7730 tvr.validity_duration = validity_duration;
7673 { 7731 {
7674 /* create signature */ 7732 /* create signature */
7675 struct TransportValidationPS tvp = 7733 struct TransportValidationPS tvp =
7676 { .purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), 7734 { .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
7677 .purpose.size = htonl(sizeof(tvp)), 7735 .purpose.size = htonl (sizeof(tvp)),
7678 .validity_duration = validity_duration, 7736 .validity_duration = validity_duration,
7679 .challenge = tvc->challenge }; 7737 .challenge = tvc->challenge };
7680 7738
7681 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, 7739 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
7682 &tvp.purpose, 7740 &tvp.purpose,
7683 &tvr.signature)); 7741 &tvr.signature));
7684 } 7742 }
7685 route_control_message_without_fc(&cmc->im.sender, 7743 route_control_message_without_fc (&cmc->im.sender,
7686 &tvr.header, 7744 &tvr.header,
7687 RMO_ANYTHING_GOES | RMO_REDUNDANT); 7745 RMO_ANYTHING_GOES | RMO_REDUNDANT);
7688 sender = cmc->im.sender; 7746 sender = cmc->im.sender;
7689 finish_cmc_handling(cmc); 7747 finish_cmc_handling (cmc);
7690 vl = lookup_virtual_link(&sender); 7748 vl = lookup_virtual_link (&sender);
7691 if (NULL != vl) 7749 if (NULL != vl)
7692 return; 7750 return;
7693 7751
@@ -7696,36 +7754,37 @@ handle_validation_challenge(
7696 CORE), so we must try to bring the link up! */ 7754 CORE), so we must try to bring the link up! */
7697 7755
7698 /* (1) Check existing queues, if any, we may be lucky! */ 7756 /* (1) Check existing queues, if any, we may be lucky! */
7699 n = lookup_neighbour(&sender); 7757 n = lookup_neighbour (&sender);
7700 if (NULL != n) 7758 if (NULL != n)
7701 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) 7759 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
7702 start_address_validation(&sender, q->address); 7760 start_address_validation (&sender, q->address);
7703 /* (2) Also try to see if we have addresses in PEERSTORE for this peer 7761 /* (2) Also try to see if we have addresses in PEERSTORE for this peer
7704 we could use */ 7762 we could use */
7705 for (ir = ir_head; NULL != ir; ir = ir->next) 7763 for (ir = ir_head; NULL != ir; ir = ir->next)
7706 if (0 == GNUNET_memcmp(&ir->pid, &sender)) 7764 if (0 == GNUNET_memcmp (&ir->pid, &sender))
7707 return; 7765 return;
7708 /* we are already trying */ 7766 /* we are already trying */
7709 ir = GNUNET_new(struct IncomingRequest); 7767 ir = GNUNET_new (struct IncomingRequest);
7710 ir->pid = sender; 7768 ir->pid = sender;
7711 GNUNET_CONTAINER_DLL_insert(ir_head, ir_tail, ir); 7769 GNUNET_CONTAINER_DLL_insert (ir_head, ir_tail, ir);
7712 ir->wc = GNUNET_PEERSTORE_watch(peerstore, 7770 ir->wc = GNUNET_PEERSTORE_watch (peerstore,
7713 "transport", 7771 "transport",
7714 &ir->pid, 7772 &ir->pid,
7715 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, 7773 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
7716 &handle_hello_for_incoming, 7774 &handle_hello_for_incoming,
7717 ir); 7775 ir);
7718 ir_total++; 7776 ir_total++;
7719 /* Bound attempts we do in parallel here, might otherwise get excessive */ 7777 /* Bound attempts we do in parallel here, might otherwise get excessive */
7720 while (ir_total > MAX_INCOMING_REQUEST) 7778 while (ir_total > MAX_INCOMING_REQUEST)
7721 free_incoming_request(ir_head); 7779 free_incoming_request (ir_head);
7722} 7780}
7723 7781
7724 7782
7725/** 7783/**
7726 * Closure for #check_known_challenge. 7784 * Closure for #check_known_challenge.
7727 */ 7785 */
7728struct CheckKnownChallengeContext { 7786struct CheckKnownChallengeContext
7787{
7729 /** 7788 /**
7730 * Set to the challenge we are looking for. 7789 * Set to the challenge we are looking for.
7731 */ 7790 */
@@ -7748,15 +7807,15 @@ struct CheckKnownChallengeContext {
7748 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found 7807 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found
7749 */ 7808 */
7750static int 7809static int
7751check_known_challenge(void *cls, 7810check_known_challenge (void *cls,
7752 const struct GNUNET_PeerIdentity *pid, 7811 const struct GNUNET_PeerIdentity *pid,
7753 void *value) 7812 void *value)
7754{ 7813{
7755 struct CheckKnownChallengeContext *ckac = cls; 7814 struct CheckKnownChallengeContext *ckac = cls;
7756 struct ValidationState *vs = value; 7815 struct ValidationState *vs = value;
7757 7816
7758 (void)pid; 7817 (void) pid;
7759 if (0 != GNUNET_memcmp(&vs->challenge, ckac->challenge)) 7818 if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge))
7760 return GNUNET_OK; 7819 return GNUNET_OK;
7761 ckac->vs = vs; 7820 ckac->vs = vs;
7762 return GNUNET_NO; 7821 return GNUNET_NO;
@@ -7771,17 +7830,17 @@ check_known_challenge(void *cls,
7771 * @param success #GNUNET_YES on success 7830 * @param success #GNUNET_YES on success
7772 */ 7831 */
7773static void 7832static void
7774peerstore_store_validation_cb(void *cls, int success) 7833peerstore_store_validation_cb (void *cls, int success)
7775{ 7834{
7776 struct ValidationState *vs = cls; 7835 struct ValidationState *vs = cls;
7777 7836
7778 vs->sc = NULL; 7837 vs->sc = NULL;
7779 if (GNUNET_YES == success) 7838 if (GNUNET_YES == success)
7780 return; 7839 return;
7781 GNUNET_STATISTICS_update(GST_stats, 7840 GNUNET_STATISTICS_update (GST_stats,
7782 "# Peerstore failed to store foreign address", 7841 "# Peerstore failed to store foreign address",
7783 1, 7842 1,
7784 GNUNET_NO); 7843 GNUNET_NO);
7785} 7844}
7786 7845
7787 7846
@@ -7793,19 +7852,19 @@ peerstore_store_validation_cb(void *cls, int success)
7793 * @return NULL if no such queue exists 7852 * @return NULL if no such queue exists
7794 */ 7853 */
7795static struct Queue * 7854static struct Queue *
7796find_queue(const struct GNUNET_PeerIdentity *pid, const char *address) 7855find_queue (const struct GNUNET_PeerIdentity *pid, const char *address)
7797{ 7856{
7798 struct Neighbour *n; 7857 struct Neighbour *n;
7799 7858
7800 n = lookup_neighbour(pid); 7859 n = lookup_neighbour (pid);
7801 if (NULL == n) 7860 if (NULL == n)
7802 return NULL; 7861 return NULL;
7803 for (struct Queue *pos = n->queue_head; NULL != pos; 7862 for (struct Queue *pos = n->queue_head; NULL != pos;
7804 pos = pos->next_neighbour) 7863 pos = pos->next_neighbour)
7805 { 7864 {
7806 if (0 == strcmp(pos->address, address)) 7865 if (0 == strcmp (pos->address, address))
7807 return pos; 7866 return pos;
7808 } 7867 }
7809 return NULL; 7868 return NULL;
7810} 7869}
7811 7870
@@ -7819,7 +7878,7 @@ find_queue(const struct GNUNET_PeerIdentity *pid, const char *address)
7819 * @param tvr the message that was received 7878 * @param tvr the message that was received
7820 */ 7879 */
7821static void 7880static void
7822handle_validation_response( 7881handle_validation_response (
7823 void *cls, 7882 void *cls,
7824 const struct TransportValidationResponseMessage *tvr) 7883 const struct TransportValidationResponseMessage *tvr)
7825{ 7884{
@@ -7833,147 +7892,147 @@ handle_validation_response(
7833 struct VirtualLink *vl; 7892 struct VirtualLink *vl;
7834 7893
7835 /* check this is one of our challenges */ 7894 /* check this is one of our challenges */
7836 (void)GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, 7895 (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
7837 &cmc->im.sender, 7896 &cmc->im.sender,
7838 &check_known_challenge, 7897 &check_known_challenge,
7839 &ckac); 7898 &ckac);
7840 if (NULL == (vs = ckac.vs)) 7899 if (NULL == (vs = ckac.vs))
7841 { 7900 {
7842 /* This can happen simply if we 'forgot' the challenge by now, 7901 /* This can happen simply if we 'forgot' the challenge by now,
7843 i.e. because we received the validation response twice */ 7902 i.e. because we received the validation response twice */
7844 GNUNET_STATISTICS_update(GST_stats, 7903 GNUNET_STATISTICS_update (GST_stats,
7845 "# Validations dropped, challenge unknown", 7904 "# Validations dropped, challenge unknown",
7846 1, 7905 1,
7847 GNUNET_NO); 7906 GNUNET_NO);
7848 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 7907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7849 "Validation response %s dropped, challenge unknown\n", 7908 "Validation response %s dropped, challenge unknown\n",
7850 GNUNET_sh2s(&tvr->challenge.value)); 7909 GNUNET_sh2s (&tvr->challenge.value));
7851 finish_cmc_handling(cmc); 7910 finish_cmc_handling (cmc);
7852 return; 7911 return;
7853 } 7912 }
7854 7913
7855 /* sanity check on origin time */ 7914 /* sanity check on origin time */
7856 origin_time = GNUNET_TIME_absolute_ntoh(tvr->origin_time); 7915 origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time);
7857 if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) || 7916 if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) ||
7858 (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us)) 7917 (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us))
7859 { 7918 {
7860 GNUNET_break_op(0); 7919 GNUNET_break_op (0);
7861 finish_cmc_handling(cmc); 7920 finish_cmc_handling (cmc);
7862 return; 7921 return;
7863 } 7922 }
7864 7923
7865 { 7924 {
7866 /* check signature */ 7925 /* check signature */
7867 struct TransportValidationPS tvp = 7926 struct TransportValidationPS tvp =
7868 { .purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), 7927 { .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
7869 .purpose.size = htonl(sizeof(tvp)), 7928 .purpose.size = htonl (sizeof(tvp)),
7870 .validity_duration = tvr->validity_duration, 7929 .validity_duration = tvr->validity_duration,
7871 .challenge = tvr->challenge }; 7930 .challenge = tvr->challenge };
7872 7931
7873 if ( 7932 if (
7874 GNUNET_OK != 7933 GNUNET_OK !=
7875 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, 7934 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE,
7876 &tvp.purpose, 7935 &tvp.purpose,
7877 &tvr->signature, 7936 &tvr->signature,
7878 &cmc->im.sender.public_key)) 7937 &cmc->im.sender.public_key))
7879 { 7938 {
7880 GNUNET_break_op(0); 7939 GNUNET_break_op (0);
7881 finish_cmc_handling(cmc); 7940 finish_cmc_handling (cmc);
7882 return; 7941 return;
7883 } 7942 }
7884 } 7943 }
7885 7944
7886 /* validity is capped by our willingness to keep track of the 7945 /* validity is capped by our willingness to keep track of the
7887 validation entry and the maximum the other peer allows */ 7946 validation entry and the maximum the other peer allows */
7888 vs->valid_until = GNUNET_TIME_relative_to_absolute( 7947 vs->valid_until = GNUNET_TIME_relative_to_absolute (
7889 GNUNET_TIME_relative_min(GNUNET_TIME_relative_ntoh( 7948 GNUNET_TIME_relative_min (GNUNET_TIME_relative_ntoh (
7890 tvr->validity_duration), 7949 tvr->validity_duration),
7891 MAX_ADDRESS_VALID_UNTIL)); 7950 MAX_ADDRESS_VALID_UNTIL));
7892 vs->validated_until = 7951 vs->validated_until =
7893 GNUNET_TIME_absolute_min(vs->valid_until, 7952 GNUNET_TIME_absolute_min (vs->valid_until,
7894 GNUNET_TIME_relative_to_absolute( 7953 GNUNET_TIME_relative_to_absolute (
7895 ADDRESS_VALIDATION_LIFETIME)); 7954 ADDRESS_VALIDATION_LIFETIME));
7896 vs->validation_rtt = GNUNET_TIME_absolute_get_duration(origin_time); 7955 vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time);
7897 vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO; 7956 vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO;
7898 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, 7957 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
7899 &vs->challenge, 7958 &vs->challenge,
7900 sizeof(vs->challenge)); 7959 sizeof(vs->challenge));
7901 vs->first_challenge_use = GNUNET_TIME_absolute_subtract( 7960 vs->first_challenge_use = GNUNET_TIME_absolute_subtract (
7902 vs->validated_until, 7961 vs->validated_until,
7903 GNUNET_TIME_relative_multiply(vs->validation_rtt, 7962 GNUNET_TIME_relative_multiply (vs->validation_rtt,
7904 VALIDATION_RTT_BUFFER_FACTOR)); 7963 VALIDATION_RTT_BUFFER_FACTOR));
7905 vs->last_challenge_use = 7964 vs->last_challenge_use =
7906 GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */ 7965 GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */
7907 update_next_challenge_time(vs, vs->first_challenge_use); 7966 update_next_challenge_time (vs, vs->first_challenge_use);
7908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 7967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7909 "Validation response %s accepted, address valid until %s\n", 7968 "Validation response %s accepted, address valid until %s\n",
7910 GNUNET_sh2s(&tvr->challenge.value), 7969 GNUNET_sh2s (&tvr->challenge.value),
7911 GNUNET_STRINGS_absolute_time_to_string(vs->valid_until)); 7970 GNUNET_STRINGS_absolute_time_to_string (vs->valid_until));
7912 vs->sc = GNUNET_PEERSTORE_store(peerstore, 7971 vs->sc = GNUNET_PEERSTORE_store (peerstore,
7913 "transport", 7972 "transport",
7914 &cmc->im.sender, 7973 &cmc->im.sender,
7915 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, 7974 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
7916 vs->address, 7975 vs->address,
7917 strlen(vs->address) + 1, 7976 strlen (vs->address) + 1,
7918 vs->valid_until, 7977 vs->valid_until,
7919 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, 7978 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
7920 &peerstore_store_validation_cb, 7979 &peerstore_store_validation_cb,
7921 vs); 7980 vs);
7922 finish_cmc_handling(cmc); 7981 finish_cmc_handling (cmc);
7923 7982
7924 /* Finally, we now possibly have a confirmed (!) working queue, 7983 /* Finally, we now possibly have a confirmed (!) working queue,
7925 update queue status (if queue still is around) */ 7984 update queue status (if queue still is around) */
7926 q = find_queue(&vs->pid, vs->address); 7985 q = find_queue (&vs->pid, vs->address);
7927 if (NULL == q) 7986 if (NULL == q)
7928 { 7987 {
7929 GNUNET_STATISTICS_update(GST_stats, 7988 GNUNET_STATISTICS_update (GST_stats,
7930 "# Queues lost at time of successful validation", 7989 "# Queues lost at time of successful validation",
7931 1, 7990 1,
7932 GNUNET_NO); 7991 GNUNET_NO);
7933 return; 7992 return;
7934 } 7993 }
7935 q->validated_until = vs->validated_until; 7994 q->validated_until = vs->validated_until;
7936 q->pd.aged_rtt = vs->validation_rtt; 7995 q->pd.aged_rtt = vs->validation_rtt;
7937 n = q->neighbour; 7996 n = q->neighbour;
7938 vl = lookup_virtual_link(&vs->pid); 7997 vl = lookup_virtual_link (&vs->pid);
7939 if (NULL != vl) 7998 if (NULL != vl)
7999 {
8000 /* Link was already up, remember n is also now available and we are done */
8001 if (NULL == vl->n)
7940 { 8002 {
7941 /* Link was already up, remember n is also now available and we are done */ 8003 vl->n = n;
7942 if (NULL == vl->n) 8004 n->vl = vl;
7943 { 8005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7944 vl->n = n; 8006 "Virtual link to %s could now also direct neighbour!\n",
7945 n->vl = vl; 8007 GNUNET_i2s (&vs->pid));
7946 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7947 "Virtual link to %s could now also direct neighbour!\n",
7948 GNUNET_i2s(&vs->pid));
7949 }
7950 else
7951 {
7952 GNUNET_assert(n == vl->n);
7953 }
7954 return;
7955 } 8008 }
7956 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8009 else
7957 "Creating new virtual link to %s using direct neighbour!\n", 8010 {
7958 GNUNET_i2s(&vs->pid)); 8011 GNUNET_assert (n == vl->n);
7959 vl = GNUNET_new(struct VirtualLink); 8012 }
8013 return;
8014 }
8015 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8016 "Creating new virtual link to %s using direct neighbour!\n",
8017 GNUNET_i2s (&vs->pid));
8018 vl = GNUNET_new (struct VirtualLink);
7960 vl->target = n->pid; 8019 vl->target = n->pid;
7961 vl->n = n; 8020 vl->n = n;
7962 n->vl = vl; 8021 n->vl = vl;
7963 vl->core_recv_window = RECV_WINDOW_SIZE; 8022 vl->core_recv_window = RECV_WINDOW_SIZE;
7964 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; 8023 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE;
7965 vl->visibility_task = 8024 vl->visibility_task =
7966 GNUNET_SCHEDULER_add_at(q->validated_until, &check_link_down, vl); 8025 GNUNET_SCHEDULER_add_at (q->validated_until, &check_link_down, vl);
7967 GNUNET_break(GNUNET_YES == 8026 GNUNET_break (GNUNET_YES ==
7968 GNUNET_CONTAINER_multipeermap_put( 8027 GNUNET_CONTAINER_multipeermap_put (
7969 links, 8028 links,
7970 &vl->target, 8029 &vl->target,
7971 vl, 8030 vl,
7972 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 8031 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
7973 consider_sending_fc(vl); 8032 consider_sending_fc (vl);
7974 /* We lacked a confirmed connection to the target 8033 /* We lacked a confirmed connection to the target
7975 before, so tell CORE about it (finally!) */ 8034 before, so tell CORE about it (finally!) */
7976 cores_send_connect_info(&n->pid); 8035 cores_send_connect_info (&n->pid);
7977} 8036}
7978 8037
7979 8038
@@ -7983,19 +8042,19 @@ handle_validation_response(
7983 * @param im the send message that was received 8042 * @param im the send message that was received
7984 */ 8043 */
7985static void 8044static void
7986handle_incoming_msg(void *cls, 8045handle_incoming_msg (void *cls,
7987 const struct GNUNET_TRANSPORT_IncomingMessage *im) 8046 const struct GNUNET_TRANSPORT_IncomingMessage *im)
7988{ 8047{
7989 struct TransportClient *tc = cls; 8048 struct TransportClient *tc = cls;
7990 struct CommunicatorMessageContext *cmc = 8049 struct CommunicatorMessageContext *cmc =
7991 GNUNET_new(struct CommunicatorMessageContext); 8050 GNUNET_new (struct CommunicatorMessageContext);
7992 8051
7993 cmc->tc = tc; 8052 cmc->tc = tc;
7994 cmc->im = *im; 8053 cmc->im = *im;
7995 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7996 "Received message via communicator from peer %s\n", 8055 "Received message via communicator from peer %s\n",
7997 GNUNET_i2s(&im->sender)); 8056 GNUNET_i2s (&im->sender));
7998 demultiplex_with_cmc(cmc, (const struct GNUNET_MessageHeader *)&im[1]); 8057 demultiplex_with_cmc (cmc, (const struct GNUNET_MessageHeader *) &im[1]);
7999} 8058}
8000 8059
8001 8060
@@ -8008,7 +8067,7 @@ handle_incoming_msg(void *cls,
8008 * @param fc the message that was received 8067 * @param fc the message that was received
8009 */ 8068 */
8010static void 8069static void
8011handle_flow_control(void *cls, const struct TransportFlowControlMessage *fc) 8070handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc)
8012{ 8071{
8013 struct CommunicatorMessageContext *cmc = cls; 8072 struct CommunicatorMessageContext *cmc = cls;
8014 struct VirtualLink *vl; 8073 struct VirtualLink *vl;
@@ -8017,70 +8076,70 @@ handle_flow_control(void *cls, const struct TransportFlowControlMessage *fc)
8017 uint64_t os; 8076 uint64_t os;
8018 uint64_t wnd; 8077 uint64_t wnd;
8019 8078
8020 vl = lookup_virtual_link(&cmc->im.sender); 8079 vl = lookup_virtual_link (&cmc->im.sender);
8021 if (NULL == vl) 8080 if (NULL == vl)
8022 { 8081 {
8023 GNUNET_STATISTICS_update(GST_stats, 8082 GNUNET_STATISTICS_update (GST_stats,
8024 "# FC dropped: virtual link unknown", 8083 "# FC dropped: virtual link unknown",
8025 1, 8084 1,
8026 GNUNET_NO); 8085 GNUNET_NO);
8027 finish_cmc_handling(cmc); 8086 finish_cmc_handling (cmc);
8028 return; 8087 return;
8029 } 8088 }
8030 st = GNUNET_TIME_absolute_ntoh(fc->sender_time); 8089 st = GNUNET_TIME_absolute_ntoh (fc->sender_time);
8031 if (st.abs_value_us < vl->last_fc_timestamp.abs_value_us) 8090 if (st.abs_value_us < vl->last_fc_timestamp.abs_value_us)
8032 { 8091 {
8033 /* out of order, drop */ 8092 /* out of order, drop */
8034 GNUNET_STATISTICS_update(GST_stats, 8093 GNUNET_STATISTICS_update (GST_stats,
8035 "# FC dropped: message out of order", 8094 "# FC dropped: message out of order",
8036 1, 8095 1,
8037 GNUNET_NO); 8096 GNUNET_NO);
8038 finish_cmc_handling(cmc); 8097 finish_cmc_handling (cmc);
8039 return; 8098 return;
8040 } 8099 }
8041 seq = ntohl(fc->seq); 8100 seq = ntohl (fc->seq);
8042 if (seq < vl->last_fc_seq) 8101 if (seq < vl->last_fc_seq)
8043 { 8102 {
8044 /* Wrap-around/reset of other peer; start all counters from zero */ 8103 /* Wrap-around/reset of other peer; start all counters from zero */
8045 vl->outbound_fc_window_size_used = 0; 8104 vl->outbound_fc_window_size_used = 0;
8046 } 8105 }
8047 vl->last_fc_seq = seq; 8106 vl->last_fc_seq = seq;
8048 vl->last_fc_timestamp = st; 8107 vl->last_fc_timestamp = st;
8049 vl->outbound_fc_window_size = GNUNET_ntohll(fc->inbound_window_size); 8108 vl->outbound_fc_window_size = GNUNET_ntohll (fc->inbound_window_size);
8050 os = GNUNET_ntohll(fc->outbound_sent); 8109 os = GNUNET_ntohll (fc->outbound_sent);
8051 vl->incoming_fc_window_size_loss = 8110 vl->incoming_fc_window_size_loss =
8052 (int64_t)(os - vl->incoming_fc_window_size_used); 8111 (int64_t) (os - vl->incoming_fc_window_size_used);
8053 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8054 "Received FC from %s, seq %u, new window %llu (loss at %lld)\n", 8113 "Received FC from %s, seq %u, new window %llu (loss at %lld)\n",
8055 GNUNET_i2s(&vl->target), 8114 GNUNET_i2s (&vl->target),
8056 (unsigned int)seq, 8115 (unsigned int) seq,
8057 (unsigned long long)vl->outbound_fc_window_size, 8116 (unsigned long long) vl->outbound_fc_window_size,
8058 (long long)vl->incoming_fc_window_size_loss); 8117 (long long) vl->incoming_fc_window_size_loss);
8059 wnd = GNUNET_ntohll(fc->outbound_window_size); 8118 wnd = GNUNET_ntohll (fc->outbound_window_size);
8060 if ((wnd < vl->incoming_fc_window_size) || 8119 if ((wnd < vl->incoming_fc_window_size) ||
8061 (vl->last_outbound_window_size_received != wnd) || 8120 (vl->last_outbound_window_size_received != wnd) ||
8062 (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) % 8121 (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)
8063 FC_NO_CHANGE_REPLY_PROBABILITY)) 8122 % FC_NO_CHANGE_REPLY_PROBABILITY))
8064 { 8123 {
8065 /* Consider re-sending our FC message, as clearly the 8124 /* Consider re-sending our FC message, as clearly the
8066 other peer's idea of the window is not up-to-date */ 8125 other peer's idea of the window is not up-to-date */
8067 consider_sending_fc(vl); 8126 consider_sending_fc (vl);
8068 } 8127 }
8069 if ((wnd == vl->incoming_fc_window_size) && 8128 if ((wnd == vl->incoming_fc_window_size) &&
8070 (vl->last_outbound_window_size_received == wnd) && 8129 (vl->last_outbound_window_size_received == wnd) &&
8071 (NULL != vl->fc_retransmit_task)) 8130 (NULL != vl->fc_retransmit_task))
8072 { 8131 {
8073 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8074 "Stopping FC retransmission to %s: peer is current at window %llu\n", 8133 "Stopping FC retransmission to %s: peer is current at window %llu\n",
8075 GNUNET_i2s(&vl->target), 8134 GNUNET_i2s (&vl->target),
8076 (unsigned long long)wnd); 8135 (unsigned long long) wnd);
8077 GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task); 8136 GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task);
8078 vl->fc_retransmit_task = NULL; 8137 vl->fc_retransmit_task = NULL;
8079 } 8138 }
8080 vl->last_outbound_window_size_received = wnd; 8139 vl->last_outbound_window_size_received = wnd;
8081 /* FC window likely increased, check transmission possibilities! */ 8140 /* FC window likely increased, check transmission possibilities! */
8082 check_vl_transmission(vl); 8141 check_vl_transmission (vl);
8083 finish_cmc_handling(cmc); 8142 finish_cmc_handling (cmc);
8084} 8143}
8085 8144
8086 8145
@@ -8092,68 +8151,68 @@ handle_flow_control(void *cls, const struct TransportFlowControlMessage *fc)
8092 * @param msg message to demultiplex 8151 * @param msg message to demultiplex
8093 */ 8152 */
8094static void 8153static void
8095demultiplex_with_cmc(struct CommunicatorMessageContext *cmc, 8154demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
8096 const struct GNUNET_MessageHeader *msg) 8155 const struct GNUNET_MessageHeader *msg)
8097{ 8156{
8098 struct GNUNET_MQ_MessageHandler handlers[] = 8157 struct GNUNET_MQ_MessageHandler handlers[] =
8099 { GNUNET_MQ_hd_var_size(fragment_box, 8158 { GNUNET_MQ_hd_var_size (fragment_box,
8100 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, 8159 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT,
8101 struct TransportFragmentBoxMessage, 8160 struct TransportFragmentBoxMessage,
8102 &cmc), 8161 &cmc),
8103 GNUNET_MQ_hd_var_size(reliability_box, 8162 GNUNET_MQ_hd_var_size (reliability_box,
8104 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, 8163 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX,
8105 struct TransportReliabilityBoxMessage, 8164 struct TransportReliabilityBoxMessage,
8106 &cmc), 8165 &cmc),
8107 GNUNET_MQ_hd_var_size(reliability_ack, 8166 GNUNET_MQ_hd_var_size (reliability_ack,
8108 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, 8167 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK,
8109 struct TransportReliabilityAckMessage, 8168 struct TransportReliabilityAckMessage,
8110 &cmc), 8169 &cmc),
8111 GNUNET_MQ_hd_var_size(backchannel_encapsulation, 8170 GNUNET_MQ_hd_var_size (backchannel_encapsulation,
8112 GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, 8171 GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION,
8113 struct TransportBackchannelEncapsulationMessage, 8172 struct TransportBackchannelEncapsulationMessage,
8114 &cmc), 8173 &cmc),
8115 GNUNET_MQ_hd_var_size(dv_learn, 8174 GNUNET_MQ_hd_var_size (dv_learn,
8116 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, 8175 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN,
8117 struct TransportDVLearnMessage, 8176 struct TransportDVLearnMessage,
8118 &cmc), 8177 &cmc),
8119 GNUNET_MQ_hd_var_size(dv_box, 8178 GNUNET_MQ_hd_var_size (dv_box,
8120 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, 8179 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX,
8121 struct TransportDVBoxMessage, 8180 struct TransportDVBoxMessage,
8122 &cmc), 8181 &cmc),
8123 GNUNET_MQ_hd_fixed_size( 8182 GNUNET_MQ_hd_fixed_size (
8124 validation_challenge, 8183 validation_challenge,
8125 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE, 8184 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE,
8126 struct TransportValidationChallengeMessage, 8185 struct TransportValidationChallengeMessage,
8127 &cmc), 8186 &cmc),
8128 GNUNET_MQ_hd_fixed_size(flow_control, 8187 GNUNET_MQ_hd_fixed_size (flow_control,
8129 GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL, 8188 GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL,
8130 struct TransportFlowControlMessage, 8189 struct TransportFlowControlMessage,
8131 &cmc), 8190 &cmc),
8132 GNUNET_MQ_hd_fixed_size( 8191 GNUNET_MQ_hd_fixed_size (
8133 validation_response, 8192 validation_response,
8134 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE, 8193 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE,
8135 struct TransportValidationResponseMessage, 8194 struct TransportValidationResponseMessage,
8136 &cmc), 8195 &cmc),
8137 GNUNET_MQ_handler_end() }; 8196 GNUNET_MQ_handler_end () };
8138 int ret; 8197 int ret;
8139 8198
8140 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8141 "Handling message of type %u with %u bytes\n", 8200 "Handling message of type %u with %u bytes\n",
8142 (unsigned int)ntohs(msg->type), 8201 (unsigned int) ntohs (msg->type),
8143 (unsigned int)ntohs(msg->size)); 8202 (unsigned int) ntohs (msg->size));
8144 ret = GNUNET_MQ_handle_message(handlers, msg); 8203 ret = GNUNET_MQ_handle_message (handlers, msg);
8145 if (GNUNET_SYSERR == ret) 8204 if (GNUNET_SYSERR == ret)
8146 { 8205 {
8147 GNUNET_break(0); 8206 GNUNET_break (0);
8148 GNUNET_SERVICE_client_drop(cmc->tc->client); 8207 GNUNET_SERVICE_client_drop (cmc->tc->client);
8149 GNUNET_free(cmc); 8208 GNUNET_free (cmc);
8150 return; 8209 return;
8151 } 8210 }
8152 if (GNUNET_NO == ret) 8211 if (GNUNET_NO == ret)
8153 { 8212 {
8154 /* unencapsulated 'raw' message */ 8213 /* unencapsulated 'raw' message */
8155 handle_raw_message(&cmc, msg); 8214 handle_raw_message (&cmc, msg);
8156 } 8215 }
8157} 8216}
8158 8217
8159 8218
@@ -8164,17 +8223,17 @@ demultiplex_with_cmc(struct CommunicatorMessageContext *cmc,
8164 * @param aqm the send message that was sent 8223 * @param aqm the send message that was sent
8165 */ 8224 */
8166static int 8225static int
8167check_add_queue_message(void *cls, 8226check_add_queue_message (void *cls,
8168 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) 8227 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
8169{ 8228{
8170 struct TransportClient *tc = cls; 8229 struct TransportClient *tc = cls;
8171 8230
8172 if (CT_COMMUNICATOR != tc->type) 8231 if (CT_COMMUNICATOR != tc->type)
8173 { 8232 {
8174 GNUNET_break(0); 8233 GNUNET_break (0);
8175 return GNUNET_SYSERR; 8234 return GNUNET_SYSERR;
8176 } 8235 }
8177 GNUNET_MQ_check_zero_termination(aqm); 8236 GNUNET_MQ_check_zero_termination (aqm);
8178 return GNUNET_OK; 8237 return GNUNET_OK;
8179} 8238}
8180 8239
@@ -8185,7 +8244,7 @@ check_add_queue_message(void *cls,
8185 * @param pm pending message to generate UUID for. 8244 * @param pm pending message to generate UUID for.
8186 */ 8245 */
8187static void 8246static void
8188set_pending_message_uuid(struct PendingMessage *pm) 8247set_pending_message_uuid (struct PendingMessage *pm)
8189{ 8248{
8190 if (pm->msg_uuid_set) 8249 if (pm->msg_uuid_set)
8191 return; 8250 return;
@@ -8203,37 +8262,37 @@ set_pending_message_uuid(struct PendingMessage *pm)
8203 * @return corresponding fresh pending acknowledgement 8262 * @return corresponding fresh pending acknowledgement
8204 */ 8263 */
8205static struct PendingAcknowledgement * 8264static struct PendingAcknowledgement *
8206prepare_pending_acknowledgement(struct Queue *queue, 8265prepare_pending_acknowledgement (struct Queue *queue,
8207 struct DistanceVectorHop *dvh, 8266 struct DistanceVectorHop *dvh,
8208 struct PendingMessage *pm) 8267 struct PendingMessage *pm)
8209{ 8268{
8210 struct PendingAcknowledgement *pa; 8269 struct PendingAcknowledgement *pa;
8211 8270
8212 pa = GNUNET_new(struct PendingAcknowledgement); 8271 pa = GNUNET_new (struct PendingAcknowledgement);
8213 pa->queue = queue; 8272 pa->queue = queue;
8214 pa->dvh = dvh; 8273 pa->dvh = dvh;
8215 pa->pm = pm; 8274 pa->pm = pm;
8216 do 8275 do
8217 { 8276 {
8218 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, 8277 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
8219 &pa->ack_uuid, 8278 &pa->ack_uuid,
8220 sizeof(pa->ack_uuid)); 8279 sizeof(pa->ack_uuid));
8221 } 8280 }
8222 while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put( 8281 while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put (
8223 pending_acks, 8282 pending_acks,
8224 &pa->ack_uuid.value, 8283 &pa->ack_uuid.value,
8225 pa, 8284 pa,
8226 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 8285 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
8227 GNUNET_CONTAINER_MDLL_insert(queue, queue->pa_head, queue->pa_tail, pa); 8286 GNUNET_CONTAINER_MDLL_insert (queue, queue->pa_head, queue->pa_tail, pa);
8228 GNUNET_CONTAINER_MDLL_insert(pm, pm->pa_head, pm->pa_tail, pa); 8287 GNUNET_CONTAINER_MDLL_insert (pm, pm->pa_head, pm->pa_tail, pa);
8229 if (NULL != dvh) 8288 if (NULL != dvh)
8230 GNUNET_CONTAINER_MDLL_insert(dvh, dvh->pa_head, dvh->pa_tail, pa); 8289 GNUNET_CONTAINER_MDLL_insert (dvh, dvh->pa_head, dvh->pa_tail, pa);
8231 pa->transmission_time = GNUNET_TIME_absolute_get(); 8290 pa->transmission_time = GNUNET_TIME_absolute_get ();
8232 pa->message_size = pm->bytes_msg; 8291 pa->message_size = pm->bytes_msg;
8233 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8234 "Waiting for ACKnowledgment `%s' for <%llu>\n", 8293 "Waiting for ACKnowledgment `%s' for <%llu>\n",
8235 GNUNET_uuid2s(&pa->ack_uuid.value), 8294 GNUNET_uuid2s (&pa->ack_uuid.value),
8236 pm->logging_uuid); 8295 pm->logging_uuid);
8237 return pa; 8296 return pa;
8238} 8297}
8239 8298
@@ -8250,9 +8309,9 @@ prepare_pending_acknowledgement(struct Queue *queue,
8250 * @return new message to transmit 8309 * @return new message to transmit
8251 */ 8310 */
8252static struct PendingMessage * 8311static struct PendingMessage *
8253fragment_message(struct Queue *queue, 8312fragment_message (struct Queue *queue,
8254 struct DistanceVectorHop *dvh, 8313 struct DistanceVectorHop *dvh,
8255 struct PendingMessage *pm) 8314 struct PendingMessage *pm)
8256{ 8315{
8257 struct PendingAcknowledgement *pa; 8316 struct PendingAcknowledgement *pa;
8258 struct PendingMessage *ff; 8317 struct PendingMessage *ff;
@@ -8261,17 +8320,17 @@ fragment_message(struct Queue *queue,
8261 mtu = (0 == queue->mtu) 8320 mtu = (0 == queue->mtu)
8262 ? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo) 8321 ? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)
8263 : queue->mtu; 8322 : queue->mtu;
8264 set_pending_message_uuid(pm); 8323 set_pending_message_uuid (pm);
8265 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8266 "Fragmenting message %llu <%llu> to %s for MTU %u\n", 8325 "Fragmenting message %llu <%llu> to %s for MTU %u\n",
8267 (unsigned long long)pm->msg_uuid.uuid, 8326 (unsigned long long) pm->msg_uuid.uuid,
8268 pm->logging_uuid, 8327 pm->logging_uuid,
8269 GNUNET_i2s(&pm->vl->target), 8328 GNUNET_i2s (&pm->vl->target),
8270 (unsigned int)mtu); 8329 (unsigned int) mtu);
8271 pa = prepare_pending_acknowledgement(queue, dvh, pm); 8330 pa = prepare_pending_acknowledgement (queue, dvh, pm);
8272 8331
8273 /* This invariant is established in #handle_add_queue_message() */ 8332 /* This invariant is established in #handle_add_queue_message() */
8274 GNUNET_assert(mtu > sizeof(struct TransportFragmentBoxMessage)); 8333 GNUNET_assert (mtu > sizeof(struct TransportFragmentBoxMessage));
8275 8334
8276 /* select fragment for transmission, descending the tree if it has 8335 /* select fragment for transmission, descending the tree if it has
8277 been expanded until we are at a leaf or at a fragment that is small 8336 been expanded until we are at a leaf or at a fragment that is small
@@ -8280,68 +8339,68 @@ fragment_message(struct Queue *queue,
8280 ff = pm; 8339 ff = pm;
8281 while (((ff->bytes_msg > mtu) || (pm == ff)) && 8340 while (((ff->bytes_msg > mtu) || (pm == ff)) &&
8282 (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag)) 8341 (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag))
8283 { 8342 {
8284 ff = ff->head_frag; /* descent into fragmented fragments */ 8343 ff = ff->head_frag; /* descent into fragmented fragments */
8285 } 8344 }
8286 8345
8287 if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg)) 8346 if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg))
8288 { 8347 {
8289 /* Did not yet calculate all fragments, calculate next fragment */ 8348 /* Did not yet calculate all fragments, calculate next fragment */
8290 struct PendingMessage *frag; 8349 struct PendingMessage *frag;
8291 struct TransportFragmentBoxMessage tfb; 8350 struct TransportFragmentBoxMessage tfb;
8292 const char *orig; 8351 const char *orig;
8293 char *msg; 8352 char *msg;
8294 uint16_t fragmax; 8353 uint16_t fragmax;
8295 uint16_t fragsize; 8354 uint16_t fragsize;
8296 uint16_t msize; 8355 uint16_t msize;
8297 uint16_t xoff = 0; 8356 uint16_t xoff = 0;
8298 8357
8299 orig = (const char *)&ff[1]; 8358 orig = (const char *) &ff[1];
8300 msize = ff->bytes_msg; 8359 msize = ff->bytes_msg;
8301 if (pm != ff) 8360 if (pm != ff)
8302 { 8361 {
8303 const struct TransportFragmentBoxMessage *tfbo; 8362 const struct TransportFragmentBoxMessage *tfbo;
8304 8363
8305 tfbo = (const struct TransportFragmentBoxMessage *)orig; 8364 tfbo = (const struct TransportFragmentBoxMessage *) orig;
8306 orig += sizeof(struct TransportFragmentBoxMessage); 8365 orig += sizeof(struct TransportFragmentBoxMessage);
8307 msize -= sizeof(struct TransportFragmentBoxMessage); 8366 msize -= sizeof(struct TransportFragmentBoxMessage);
8308 xoff = ntohs(tfbo->frag_off); 8367 xoff = ntohs (tfbo->frag_off);
8309 } 8368 }
8310 fragmax = mtu - sizeof(struct TransportFragmentBoxMessage); 8369 fragmax = mtu - sizeof(struct TransportFragmentBoxMessage);
8311 fragsize = GNUNET_MIN(msize - ff->frag_off, fragmax); 8370 fragsize = GNUNET_MIN (msize - ff->frag_off, fragmax);
8312 frag = 8371 frag =
8313 GNUNET_malloc(sizeof(struct PendingMessage) + 8372 GNUNET_malloc (sizeof(struct PendingMessage)
8314 sizeof(struct TransportFragmentBoxMessage) + fragsize); 8373 + sizeof(struct TransportFragmentBoxMessage) + fragsize);
8315 frag->logging_uuid = logging_uuid_gen++; 8374 frag->logging_uuid = logging_uuid_gen++;
8316 frag->vl = pm->vl; 8375 frag->vl = pm->vl;
8317 frag->frag_parent = ff; 8376 frag->frag_parent = ff;
8318 frag->timeout = pm->timeout; 8377 frag->timeout = pm->timeout;
8319 frag->bytes_msg = sizeof(struct TransportFragmentBoxMessage) + fragsize; 8378 frag->bytes_msg = sizeof(struct TransportFragmentBoxMessage) + fragsize;
8320 frag->pmt = PMT_FRAGMENT_BOX; 8379 frag->pmt = PMT_FRAGMENT_BOX;
8321 msg = (char *)&frag[1]; 8380 msg = (char *) &frag[1];
8322 tfb.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); 8381 tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT);
8323 tfb.header.size = 8382 tfb.header.size =
8324 htons(sizeof(struct TransportFragmentBoxMessage) + fragsize); 8383 htons (sizeof(struct TransportFragmentBoxMessage) + fragsize);
8325 tfb.ack_uuid = pa->ack_uuid; 8384 tfb.ack_uuid = pa->ack_uuid;
8326 tfb.msg_uuid = pm->msg_uuid; 8385 tfb.msg_uuid = pm->msg_uuid;
8327 tfb.frag_off = htons(ff->frag_off + xoff); 8386 tfb.frag_off = htons (ff->frag_off + xoff);
8328 tfb.msg_size = htons(pm->bytes_msg); 8387 tfb.msg_size = htons (pm->bytes_msg);
8329 memcpy(msg, &tfb, sizeof(tfb)); 8388 memcpy (msg, &tfb, sizeof(tfb));
8330 memcpy(&msg[sizeof(tfb)], &orig[ff->frag_off], fragsize); 8389 memcpy (&msg[sizeof(tfb)], &orig[ff->frag_off], fragsize);
8331 GNUNET_CONTAINER_MDLL_insert(frag, ff->head_frag, ff->tail_frag, frag); 8390 GNUNET_CONTAINER_MDLL_insert (frag, ff->head_frag, ff->tail_frag, frag);
8332 ff->frag_off += fragsize; 8391 ff->frag_off += fragsize;
8333 ff = frag; 8392 ff = frag;
8334 } 8393 }
8335 8394
8336 /* Move head to the tail and return it */ 8395 /* Move head to the tail and return it */
8337 GNUNET_CONTAINER_MDLL_remove(frag, 8396 GNUNET_CONTAINER_MDLL_remove (frag,
8338 ff->frag_parent->head_frag, 8397 ff->frag_parent->head_frag,
8339 ff->frag_parent->tail_frag, 8398 ff->frag_parent->tail_frag,
8340 ff); 8399 ff);
8341 GNUNET_CONTAINER_MDLL_insert_tail(frag, 8400 GNUNET_CONTAINER_MDLL_insert_tail (frag,
8342 ff->frag_parent->head_frag, 8401 ff->frag_parent->head_frag,
8343 ff->frag_parent->tail_frag, 8402 ff->frag_parent->tail_frag,
8344 ff); 8403 ff);
8345 return ff; 8404 return ff;
8346} 8405}
8347 8406
@@ -8359,9 +8418,9 @@ fragment_message(struct Queue *queue,
8359 * @return new message to transmit 8418 * @return new message to transmit
8360 */ 8419 */
8361static struct PendingMessage * 8420static struct PendingMessage *
8362reliability_box_message(struct Queue *queue, 8421reliability_box_message (struct Queue *queue,
8363 struct DistanceVectorHop *dvh, 8422 struct DistanceVectorHop *dvh,
8364 struct PendingMessage *pm) 8423 struct PendingMessage *pm)
8365{ 8424{
8366 struct TransportReliabilityBoxMessage rbox; 8425 struct TransportReliabilityBoxMessage rbox;
8367 struct PendingAcknowledgement *pa; 8426 struct PendingAcknowledgement *pa;
@@ -8373,39 +8432,39 @@ reliability_box_message(struct Queue *queue,
8373 do nothing */ 8432 do nothing */
8374 if (NULL != pm->bpm) 8433 if (NULL != pm->bpm)
8375 return pm->bpm; /* already computed earlier: do nothing */ 8434 return pm->bpm; /* already computed earlier: do nothing */
8376 GNUNET_assert(NULL == pm->head_frag); 8435 GNUNET_assert (NULL == pm->head_frag);
8377 if (pm->bytes_msg + sizeof(rbox) > UINT16_MAX) 8436 if (pm->bytes_msg + sizeof(rbox) > UINT16_MAX)
8378 { 8437 {
8379 /* failed hard */ 8438 /* failed hard */
8380 GNUNET_break(0); 8439 GNUNET_break (0);
8381 client_send_response(pm); 8440 client_send_response (pm);
8382 return NULL; 8441 return NULL;
8383 } 8442 }
8384 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8385 "Preparing reliability box for message <%llu> to %s on queue %s\n", 8444 "Preparing reliability box for message <%llu> to %s on queue %s\n",
8386 pm->logging_uuid, 8445 pm->logging_uuid,
8387 GNUNET_i2s(&pm->vl->target), 8446 GNUNET_i2s (&pm->vl->target),
8388 queue->address); 8447 queue->address);
8389 pa = prepare_pending_acknowledgement(queue, dvh, pm); 8448 pa = prepare_pending_acknowledgement (queue, dvh, pm);
8390 8449
8391 bpm = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(rbox) + 8450 bpm = GNUNET_malloc (sizeof(struct PendingMessage) + sizeof(rbox)
8392 pm->bytes_msg); 8451 + pm->bytes_msg);
8393 bpm->logging_uuid = logging_uuid_gen++; 8452 bpm->logging_uuid = logging_uuid_gen++;
8394 bpm->vl = pm->vl; 8453 bpm->vl = pm->vl;
8395 bpm->frag_parent = pm; 8454 bpm->frag_parent = pm;
8396 GNUNET_CONTAINER_MDLL_insert(frag, pm->head_frag, pm->tail_frag, bpm); 8455 GNUNET_CONTAINER_MDLL_insert (frag, pm->head_frag, pm->tail_frag, bpm);
8397 bpm->timeout = pm->timeout; 8456 bpm->timeout = pm->timeout;
8398 bpm->pmt = PMT_RELIABILITY_BOX; 8457 bpm->pmt = PMT_RELIABILITY_BOX;
8399 bpm->bytes_msg = pm->bytes_msg + sizeof(rbox); 8458 bpm->bytes_msg = pm->bytes_msg + sizeof(rbox);
8400 set_pending_message_uuid(bpm); 8459 set_pending_message_uuid (bpm);
8401 rbox.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX); 8460 rbox.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX);
8402 rbox.header.size = htons(sizeof(rbox) + pm->bytes_msg); 8461 rbox.header.size = htons (sizeof(rbox) + pm->bytes_msg);
8403 rbox.ack_countdown = htonl(0); // FIXME: implement ACK countdown support 8462 rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support
8404 8463
8405 rbox.ack_uuid = pa->ack_uuid; 8464 rbox.ack_uuid = pa->ack_uuid;
8406 msg = (char *)&bpm[1]; 8465 msg = (char *) &bpm[1];
8407 memcpy(msg, &rbox, sizeof(rbox)); 8466 memcpy (msg, &rbox, sizeof(rbox));
8408 memcpy(&msg[sizeof(rbox)], &pm[1], pm->bytes_msg); 8467 memcpy (&msg[sizeof(rbox)], &pm[1], pm->bytes_msg);
8409 pm->bpm = bpm; 8468 pm->bpm = bpm;
8410 return bpm; 8469 return bpm;
8411} 8470}
@@ -8420,60 +8479,61 @@ reliability_box_message(struct Queue *queue,
8420 * @param next_attempt timestamp to use 8479 * @param next_attempt timestamp to use
8421 */ 8480 */
8422static void 8481static void
8423update_pm_next_attempt(struct PendingMessage *pm, 8482update_pm_next_attempt (struct PendingMessage *pm,
8424 struct GNUNET_TIME_Absolute next_attempt) 8483 struct GNUNET_TIME_Absolute next_attempt)
8425{ 8484{
8426 struct VirtualLink *vl = pm->vl; 8485 struct VirtualLink *vl = pm->vl;
8427 8486
8428 pm->next_attempt = next_attempt; 8487 pm->next_attempt = next_attempt;
8429 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8430 "Next attempt for message <%llu> set to %s\n", 8489 "Next attempt for message <%llu> set to %s\n",
8431 pm->logging_uuid, 8490 pm->logging_uuid,
8432 GNUNET_STRINGS_absolute_time_to_string(next_attempt)); 8491 GNUNET_STRINGS_absolute_time_to_string (next_attempt));
8433 8492
8434 if (NULL == pm->frag_parent) 8493 if (NULL == pm->frag_parent)
8435 { 8494 {
8436 struct PendingMessage *pos; 8495 struct PendingMessage *pos;
8437 8496
8438 /* re-insert sort in neighbour list */ 8497 /* re-insert sort in neighbour list */
8439 GNUNET_CONTAINER_MDLL_remove(vl, 8498 GNUNET_CONTAINER_MDLL_remove (vl,
8440 vl->pending_msg_head, 8499 vl->pending_msg_head,
8441 vl->pending_msg_tail, 8500 vl->pending_msg_tail,
8442 pm); 8501 pm);
8443 pos = vl->pending_msg_tail; 8502 pos = vl->pending_msg_tail;
8444 while ((NULL != pos) && 8503 while ((NULL != pos) &&
8445 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) 8504 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us))
8446 pos = pos->prev_vl; 8505 pos = pos->prev_vl;
8447 GNUNET_CONTAINER_MDLL_insert_after(vl, 8506 GNUNET_CONTAINER_MDLL_insert_after (vl,
8448 vl->pending_msg_head, 8507 vl->pending_msg_head,
8449 vl->pending_msg_tail, 8508 vl->pending_msg_tail,
8450 pos, 8509 pos,
8451 pm); 8510 pm);
8452 } 8511 }
8453 else 8512 else
8454 { 8513 {
8455 /* re-insert sort in fragment list */ 8514 /* re-insert sort in fragment list */
8456 struct PendingMessage *fp = pm->frag_parent; 8515 struct PendingMessage *fp = pm->frag_parent;
8457 struct PendingMessage *pos; 8516 struct PendingMessage *pos;
8458 8517
8459 GNUNET_CONTAINER_MDLL_remove(frag, fp->head_frag, fp->tail_frag, pm); 8518 GNUNET_CONTAINER_MDLL_remove (frag, fp->head_frag, fp->tail_frag, pm);
8460 pos = fp->tail_frag; 8519 pos = fp->tail_frag;
8461 while ((NULL != pos) && 8520 while ((NULL != pos) &&
8462 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) 8521 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us))
8463 pos = pos->prev_frag; 8522 pos = pos->prev_frag;
8464 GNUNET_CONTAINER_MDLL_insert_after(frag, 8523 GNUNET_CONTAINER_MDLL_insert_after (frag,
8465 fp->head_frag, 8524 fp->head_frag,
8466 fp->tail_frag, 8525 fp->tail_frag,
8467 pos, 8526 pos,
8468 pm); 8527 pm);
8469 } 8528 }
8470} 8529}
8471 8530
8472 8531
8473/** 8532/**
8474 * Context for #select_best_pending_from_link(). 8533 * Context for #select_best_pending_from_link().
8475 */ 8534 */
8476struct PendingMessageScoreContext { 8535struct PendingMessageScoreContext
8536{
8477 /** 8537 /**
8478 * Set to the best message that was found, NULL for none. 8538 * Set to the best message that was found, NULL for none.
8479 */ 8539 */
@@ -8518,107 +8578,109 @@ struct PendingMessageScoreContext {
8518 * from DV encapsulation (0 for without DV) 8578 * from DV encapsulation (0 for without DV)
8519 */ 8579 */
8520static void 8580static void
8521select_best_pending_from_link(struct PendingMessageScoreContext *sc, 8581select_best_pending_from_link (struct PendingMessageScoreContext *sc,
8522 struct Queue *queue, 8582 struct Queue *queue,
8523 struct VirtualLink *vl, 8583 struct VirtualLink *vl,
8524 struct DistanceVectorHop *dvh, 8584 struct DistanceVectorHop *dvh,
8525 size_t overhead) 8585 size_t overhead)
8526{ 8586{
8527 struct GNUNET_TIME_Absolute now; 8587 struct GNUNET_TIME_Absolute now;
8528 8588
8529 now = GNUNET_TIME_absolute_get(); 8589 now = GNUNET_TIME_absolute_get ();
8530 for (struct PendingMessage *pos = vl->pending_msg_head; NULL != pos; 8590 for (struct PendingMessage *pos = vl->pending_msg_head; NULL != pos;
8531 pos = pos->next_vl) 8591 pos = pos->next_vl)
8532 { 8592 {
8533 size_t real_overhead = overhead; 8593 size_t real_overhead = overhead;
8534 int frag; 8594 int frag;
8535 int relb; 8595 int relb;
8536 8596
8537 if ((NULL != dvh) && (PMT_DV_BOX == pos->pmt)) 8597 if ((NULL != dvh) && (PMT_DV_BOX == pos->pmt))
8538 continue; /* DV messages must not be DV-routed to next hop! */ 8598 continue; /* DV messages must not be DV-routed to next hop! */
8539 if (pos->next_attempt.abs_value_us > now.abs_value_us) 8599 if (pos->next_attempt.abs_value_us > now.abs_value_us)
8540 break; /* too early for all messages, they are sorted by next_attempt */ 8600 break; /* too early for all messages, they are sorted by next_attempt */
8541 if (NULL != pos->qe) 8601 if (NULL != pos->qe)
8542 continue; /* not eligible */ 8602 continue; /* not eligible */
8543 sc->consideration_counter++; 8603 sc->consideration_counter++;
8544 /* determine if we have to fragment, if so add fragmentation 8604 /* determine if we have to fragment, if so add fragmentation
8545 overhead! */ 8605 overhead! */
8546 frag = GNUNET_NO; 8606 frag = GNUNET_NO;
8547 if (((0 != queue->mtu) && 8607 if (((0 != queue->mtu) &&
8548 (pos->bytes_msg + real_overhead > queue->mtu)) || 8608 (pos->bytes_msg + real_overhead > queue->mtu)) ||
8549 (pos->bytes_msg > UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)) || 8609 (pos->bytes_msg > UINT16_MAX - sizeof(struct
8550 (NULL != pos->head_frag /* fragments already exist, should 8610 GNUNET_TRANSPORT_SendMessageTo))
8611 ||
8612 (NULL != pos->head_frag /* fragments already exist, should
8551 respect that even if MTU is 0 for 8613 respect that even if MTU is 0 for
8552 this queue */)) 8614 this queue */))
8553 { 8615 {
8554 frag = GNUNET_YES; 8616 frag = GNUNET_YES;
8555 if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) 8617 if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)
8556 { 8618 {
8557 /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation 8619 /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation
8558 header without the ACK UUID when using a *reliable* channel! */ 8620 header without the ACK UUID when using a *reliable* channel! */
8559 } 8621 }
8560 real_overhead = overhead + sizeof(struct TransportFragmentBoxMessage); 8622 real_overhead = overhead + sizeof(struct TransportFragmentBoxMessage);
8561 } 8623 }
8562 /* determine if we have to reliability-box, if so add reliability box 8624 /* determine if we have to reliability-box, if so add reliability box
8563 overhead */ 8625 overhead */
8564 relb = GNUNET_NO; 8626 relb = GNUNET_NO;
8565 if ((GNUNET_NO == frag) && 8627 if ((GNUNET_NO == frag) &&
8566 (0 == (pos->prefs & GNUNET_MQ_PREF_UNRELIABLE)) && 8628 (0 == (pos->prefs & GNUNET_MQ_PREF_UNRELIABLE)) &&
8567 (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc)) 8629 (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc))
8568 { 8630 {
8569 relb = GNUNET_YES; 8631 relb = GNUNET_YES;
8570 real_overhead += sizeof(struct TransportReliabilityBoxMessage); 8632 real_overhead += sizeof(struct TransportReliabilityBoxMessage);
8571 } 8633 }
8572 8634
8573 /* Finally, compare to existing 'best' in sc to see if this 'pos' pending 8635 /* Finally, compare to existing 'best' in sc to see if this 'pos' pending
8574 message would beat it! */ 8636 message would beat it! */
8575 if (NULL != sc->best) 8637 if (NULL != sc->best)
8576 { 8638 {
8577 /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue; 8639 /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue;
8578 OPTIMIZE-ME: This is a heuristic, which so far has NOT been 8640 OPTIMIZE-ME: This is a heuristic, which so far has NOT been
8579 experimentally validated. There may be some huge potential for 8641 experimentally validated. There may be some huge potential for
8580 improvement here. Also, we right now only compare how well the 8642 improvement here. Also, we right now only compare how well the
8581 given message fits _this_ queue, and do not consider how well other 8643 given message fits _this_ queue, and do not consider how well other
8582 queues might suit the message. Taking other queues into consideration 8644 queues might suit the message. Taking other queues into consideration
8583 may further improve the result, but could also be expensive 8645 may further improve the result, but could also be expensive
8584 in terms of CPU time. */ 8646 in terms of CPU time. */
8585 long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead; 8647 long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead;
8586 long long pm_score = frag * 40 + relb * 20 + real_overhead; 8648 long long pm_score = frag * 40 + relb * 20 + real_overhead;
8587 long long time_delta = 8649 long long time_delta =
8588 (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us) / 8650 (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us)
8589 1000LL; 8651 / 1000LL;
8590 8652
8591 /* "time_delta" considers which message has been 'ready' for transmission 8653 /* "time_delta" considers which message has been 'ready' for transmission
8592 for longer, if a message has a preference for low latency, increase 8654 for longer, if a message has a preference for low latency, increase
8593 the weight of the time_delta by 10x if it is favorable for that message */ 8655 the weight of the time_delta by 10x if it is favorable for that message */
8594 if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && 8656 if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
8595 (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY))) 8657 (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)))
8596 time_delta *= 10; /* increase weight (always, both are low latency) */ 8658 time_delta *= 10; /* increase weight (always, both are low latency) */
8597 else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && 8659 else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
8598 (time_delta > 0)) 8660 (time_delta > 0))
8599 time_delta *= 8661 time_delta *=
8600 10; /* increase weight, favors 'pos', which is low latency */ 8662 10; /* increase weight, favors 'pos', which is low latency */
8601 else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && 8663 else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
8602 (time_delta < 0)) 8664 (time_delta < 0))
8603 time_delta *= 8665 time_delta *=
8604 10; /* increase weight, favors 'sc->best', which is low latency */ 8666 10; /* increase weight, favors 'sc->best', which is low latency */
8605 if (0 != queue->mtu) 8667 if (0 != queue->mtu)
8606 { 8668 {
8607 /* Grant bonus if we are bellow MTU, larger bonus the closer we will 8669 /* Grant bonus if we are bellow MTU, larger bonus the closer we will
8608 be to the MTU */ 8670 be to the MTU */
8609 if (queue->mtu > sc->real_overhead + sc->best->bytes_msg) 8671 if (queue->mtu > sc->real_overhead + sc->best->bytes_msg)
8610 sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg); 8672 sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg);
8611 if (queue->mtu > real_overhead + pos->bytes_msg) 8673 if (queue->mtu > real_overhead + pos->bytes_msg)
8612 pm_score -= queue->mtu - (real_overhead + pos->bytes_msg); 8674 pm_score -= queue->mtu - (real_overhead + pos->bytes_msg);
8613 } 8675 }
8614 if (sc_score + time_delta > pm_score) 8676 if (sc_score + time_delta > pm_score)
8615 continue; /* sc_score larger, keep sc->best */ 8677 continue; /* sc_score larger, keep sc->best */
8616 }
8617 sc->best = pos;
8618 sc->dvh = dvh;
8619 sc->frag = frag;
8620 sc->relb = relb;
8621 } 8678 }
8679 sc->best = pos;
8680 sc->dvh = dvh;
8681 sc->frag = frag;
8682 sc->relb = relb;
8683 }
8622} 8684}
8623 8685
8624 8686
@@ -8633,26 +8695,26 @@ select_best_pending_from_link(struct PendingMessageScoreContext *sc,
8633 * @param options options of the original message 8695 * @param options options of the original message
8634 */ 8696 */
8635static void 8697static void
8636extract_box_cb(void *cls, 8698extract_box_cb (void *cls,
8637 struct Neighbour *next_hop, 8699 struct Neighbour *next_hop,
8638 const struct GNUNET_MessageHeader *hdr, 8700 const struct GNUNET_MessageHeader *hdr,
8639 enum RouteMessageOptions options) 8701 enum RouteMessageOptions options)
8640{ 8702{
8641 struct PendingMessageScoreContext *sc = cls; 8703 struct PendingMessageScoreContext *sc = cls;
8642 struct PendingMessage *pm = sc->best; 8704 struct PendingMessage *pm = sc->best;
8643 struct PendingMessage *bpm; 8705 struct PendingMessage *bpm;
8644 uint16_t bsize = ntohs(hdr->size); 8706 uint16_t bsize = ntohs (hdr->size);
8645 8707
8646 GNUNET_assert(NULL == pm->bpm); 8708 GNUNET_assert (NULL == pm->bpm);
8647 bpm = GNUNET_malloc(sizeof(struct PendingMessage) + bsize); 8709 bpm = GNUNET_malloc (sizeof(struct PendingMessage) + bsize);
8648 bpm->logging_uuid = logging_uuid_gen++; 8710 bpm->logging_uuid = logging_uuid_gen++;
8649 bpm->pmt = PMT_DV_BOX; 8711 bpm->pmt = PMT_DV_BOX;
8650 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8651 "Creating DV Box %llu for original message %llu (next hop is %s)\n", 8713 "Creating DV Box %llu for original message %llu (next hop is %s)\n",
8652 bpm->logging_uuid, 8714 bpm->logging_uuid,
8653 pm->logging_uuid, 8715 pm->logging_uuid,
8654 GNUNET_i2s(&next_hop->pid)); 8716 GNUNET_i2s (&next_hop->pid));
8655 memcpy(&bpm[1], hdr, bsize); 8717 memcpy (&bpm[1], hdr, bsize);
8656 pm->bpm = bpm; 8718 pm->bpm = bpm;
8657} 8719}
8658 8720
@@ -8673,7 +8735,7 @@ extract_box_cb(void *cls,
8673 * @param cls the `struct Queue` to process transmissions for 8735 * @param cls the `struct Queue` to process transmissions for
8674 */ 8736 */
8675static void 8737static void
8676transmit_on_queue(void *cls) 8738transmit_on_queue (void *cls)
8677{ 8739{
8678 struct Queue *queue = cls; 8740 struct Queue *queue = cls;
8679 struct Neighbour *n = queue->neighbour; 8741 struct Neighbour *n = queue->neighbour;
@@ -8682,104 +8744,104 @@ transmit_on_queue(void *cls)
8682 8744
8683 queue->transmit_task = NULL; 8745 queue->transmit_task = NULL;
8684 if (NULL == n->vl) 8746 if (NULL == n->vl)
8685 { 8747 {
8686 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8748 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8687 "Virtual link `%s' is down, cannot have PM for queue `%s'\n", 8749 "Virtual link `%s' is down, cannot have PM for queue `%s'\n",
8688 GNUNET_i2s(&n->pid), 8750 GNUNET_i2s (&n->pid),
8689 queue->address); 8751 queue->address);
8690 queue->idle = GNUNET_YES; 8752 queue->idle = GNUNET_YES;
8691 return; 8753 return;
8692 } 8754 }
8693 memset(&sc, 0, sizeof(sc)); 8755 memset (&sc, 0, sizeof(sc));
8694 select_best_pending_from_link(&sc, queue, n->vl, NULL, 0); 8756 select_best_pending_from_link (&sc, queue, n->vl, NULL, 0);
8695 if (NULL == sc.best) 8757 if (NULL == sc.best)
8696 { 8758 {
8697 /* Also look at DVH that have the n as first hop! */ 8759 /* Also look at DVH that have the n as first hop! */
8698 for (struct DistanceVectorHop *dvh = n->dv_head; NULL != dvh; 8760 for (struct DistanceVectorHop *dvh = n->dv_head; NULL != dvh;
8699 dvh = dvh->next_neighbour) 8761 dvh = dvh->next_neighbour)
8700 { 8762 {
8701 select_best_pending_from_link(&sc, 8763 select_best_pending_from_link (&sc,
8702 queue, 8764 queue,
8703 dvh->dv->vl, 8765 dvh->dv->vl,
8704 dvh, 8766 dvh,
8705 sizeof(struct GNUNET_PeerIdentity) * 8767 sizeof(struct GNUNET_PeerIdentity)
8706 (1 + dvh->distance) + 8768 * (1 + dvh->distance)
8707 sizeof(struct TransportDVBoxMessage) + 8769 + sizeof(struct TransportDVBoxMessage)
8708 sizeof(struct TransportDVBoxPayloadP)); 8770 + sizeof(struct TransportDVBoxPayloadP));
8709 }
8710 } 8771 }
8772 }
8711 if (NULL == sc.best) 8773 if (NULL == sc.best)
8712 { 8774 {
8713 /* no message pending, nothing to do here! */ 8775 /* no message pending, nothing to do here! */
8714 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8715 "No pending messages, queue `%s' to %s now idle\n", 8777 "No pending messages, queue `%s' to %s now idle\n",
8716 queue->address, 8778 queue->address,
8717 GNUNET_i2s(&n->pid)); 8779 GNUNET_i2s (&n->pid));
8718 queue->idle = GNUNET_YES; 8780 queue->idle = GNUNET_YES;
8719 return; 8781 return;
8720 } 8782 }
8721 8783
8722 /* Given selection in `sc`, do transmission */ 8784 /* Given selection in `sc`, do transmission */
8723 pm = sc.best; 8785 pm = sc.best;
8724 if (NULL != sc.dvh) 8786 if (NULL != sc.dvh)
8725 { 8787 {
8726 GNUNET_assert(PMT_DV_BOX != pm->pmt); 8788 GNUNET_assert (PMT_DV_BOX != pm->pmt);
8727 if (NULL != sc.best->bpm) 8789 if (NULL != sc.best->bpm)
8728 { 8790 {
8729 /* We did this boxing before, but possibly for a different path! 8791 /* We did this boxing before, but possibly for a different path!
8730 Discard old DV box! OPTIMIZE-ME: we might want to check if 8792 Discard old DV box! OPTIMIZE-ME: we might want to check if
8731 it is the same and then not re-build the message... */ 8793 it is the same and then not re-build the message... */
8732 free_pending_message(sc.best->bpm); 8794 free_pending_message (sc.best->bpm);
8733 sc.best->bpm = NULL; 8795 sc.best->bpm = NULL;
8734 } 8796 }
8735 encapsulate_for_dv(sc.dvh->dv, 8797 encapsulate_for_dv (sc.dvh->dv,
8736 1, 8798 1,
8737 &sc.dvh, 8799 &sc.dvh,
8738 (const struct GNUNET_MessageHeader *)&sc.best[1], 8800 (const struct GNUNET_MessageHeader *) &sc.best[1],
8739 &extract_box_cb, 8801 &extract_box_cb,
8740 &sc, 8802 &sc,
8741 RMO_NONE); 8803 RMO_NONE);
8742 GNUNET_assert(NULL != sc.best->bpm); 8804 GNUNET_assert (NULL != sc.best->bpm);
8743 pm = sc.best->bpm; 8805 pm = sc.best->bpm;
8744 } 8806 }
8745 if (GNUNET_YES == sc.frag) 8807 if (GNUNET_YES == sc.frag)
8746 { 8808 {
8747 pm = fragment_message(queue, sc.dvh, pm); 8809 pm = fragment_message (queue, sc.dvh, pm);
8748 if (NULL == pm) 8810 if (NULL == pm)
8749 { 8811 {
8750 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8751 "Fragmentation failed queue %s to %s for <%llu>, trying again\n", 8813 "Fragmentation failed queue %s to %s for <%llu>, trying again\n",
8752 queue->address, 8814 queue->address,
8753 GNUNET_i2s(&n->pid), 8815 GNUNET_i2s (&n->pid),
8754 sc.best->logging_uuid); 8816 sc.best->logging_uuid);
8755 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8817 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8756 return; 8818 return;
8757 }
8758 } 8819 }
8820 }
8759 else if (GNUNET_YES == sc.relb) 8821 else if (GNUNET_YES == sc.relb)
8760 { 8822 {
8761 pm = reliability_box_message(queue, sc.dvh, pm); 8823 pm = reliability_box_message (queue, sc.dvh, pm);
8762 if (NULL == pm) 8824 if (NULL == pm)
8763 { 8825 {
8764 /* Reliability boxing failed, try next message... */ 8826 /* Reliability boxing failed, try next message... */
8765 GNUNET_log( 8827 GNUNET_log (
8766 GNUNET_ERROR_TYPE_DEBUG, 8828 GNUNET_ERROR_TYPE_DEBUG,
8767 "Reliability boxing failed queue %s to %s for <%llu>, trying again\n", 8829 "Reliability boxing failed queue %s to %s for <%llu>, trying again\n",
8768 queue->address, 8830 queue->address,
8769 GNUNET_i2s(&n->pid), 8831 GNUNET_i2s (&n->pid),
8770 sc.best->logging_uuid); 8832 sc.best->logging_uuid);
8771 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8833 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8772 return; 8834 return;
8773 }
8774 } 8835 }
8836 }
8775 8837
8776 /* Pass 'pm' for transission to the communicator */ 8838 /* Pass 'pm' for transission to the communicator */
8777 GNUNET_log( 8839 GNUNET_log (
8778 GNUNET_ERROR_TYPE_DEBUG, 8840 GNUNET_ERROR_TYPE_DEBUG,
8779 "Passing message <%llu> to queue %s for peer %s (considered %u others)\n", 8841 "Passing message <%llu> to queue %s for peer %s (considered %u others)\n",
8780 pm->logging_uuid, 8842 pm->logging_uuid,
8781 queue->address, 8843 queue->address,
8782 GNUNET_i2s(&n->pid), 8844 GNUNET_i2s (&n->pid),
8783 sc.consideration_counter); 8845 sc.consideration_counter);
8784 8846
8785 /* Flow control: increment amount of traffic sent; if we are routing 8847 /* Flow control: increment amount of traffic sent; if we are routing
@@ -8790,50 +8852,50 @@ transmit_on_queue(void *cls)
8790 pm->vl->outbound_fc_window_size_used += pm->bytes_msg; 8852 pm->vl->outbound_fc_window_size_used += pm->bytes_msg;
8791 8853
8792 if (pm->vl != queue->neighbour->vl) 8854 if (pm->vl != queue->neighbour->vl)
8793 { 8855 {
8794 /* If the virtual link of the queue differs, this better be distance 8856 /* If the virtual link of the queue differs, this better be distance
8795 vector routing! */ 8857 vector routing! */
8796 GNUNET_assert(NULL != sc.dvh); 8858 GNUNET_assert (NULL != sc.dvh);
8797 /* If we do distance vector routing, we better not do this for a 8859 /* If we do distance vector routing, we better not do this for a
8798 message that was itself DV-routed */ 8860 message that was itself DV-routed */
8799 GNUNET_assert(PMT_DV_BOX != sc.best->pmt); 8861 GNUNET_assert (PMT_DV_BOX != sc.best->pmt);
8800 /* We use the size of the unboxed message here, to avoid counting 8862 /* We use the size of the unboxed message here, to avoid counting
8801 the DV-Box header which is eaten up on the way by intermediaries */ 8863 the DV-Box header which is eaten up on the way by intermediaries */
8802 queue->neighbour->vl->outbound_fc_window_size_used += sc.best->bytes_msg; 8864 queue->neighbour->vl->outbound_fc_window_size_used += sc.best->bytes_msg;
8803 } 8865 }
8804 else 8866 else
8805 { 8867 {
8806 GNUNET_assert(NULL == sc.dvh); 8868 GNUNET_assert (NULL == sc.dvh);
8807 } 8869 }
8808 8870
8809 queue_send_msg(queue, pm, &pm[1], pm->bytes_msg); 8871 queue_send_msg (queue, pm, &pm[1], pm->bytes_msg);
8810 8872
8811 /* Check if this transmission somehow conclusively finished handing 'pm' 8873 /* Check if this transmission somehow conclusively finished handing 'pm'
8812 even without any explicit ACKs */ 8874 even without any explicit ACKs */
8813 if ((PMT_CORE == pm->pmt) || 8875 if ((PMT_CORE == pm->pmt) ||
8814 (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)) 8876 (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc))
8815 { 8877 {
8816 completed_pending_message(pm); 8878 completed_pending_message (pm);
8817 } 8879 }
8818 else 8880 else
8819 { 8881 {
8820 /* Message not finished, waiting for acknowledgement. 8882 /* Message not finished, waiting for acknowledgement.
8821 Update time by which we might retransmit 's' based on queue 8883 Update time by which we might retransmit 's' based on queue
8822 characteristics (i.e. RTT); it takes one RTT for the message to 8884 characteristics (i.e. RTT); it takes one RTT for the message to
8823 arrive and the ACK to come back in the best case; but the other 8885 arrive and the ACK to come back in the best case; but the other
8824 side is allowed to delay ACKs by 2 RTTs, so we use 4 RTT before 8886 side is allowed to delay ACKs by 2 RTTs, so we use 4 RTT before
8825 retransmitting. 8887 retransmitting.
8826 8888
8827 OPTIMIZE: Note that in the future this heuristic should likely 8889 OPTIMIZE: Note that in the future this heuristic should likely
8828 be improved further (measure RTT stability, consider message 8890 be improved further (measure RTT stability, consider message
8829 urgency and size when delaying ACKs, etc.) */ 8891 urgency and size when delaying ACKs, etc.) */
8830 update_pm_next_attempt(pm, 8892 update_pm_next_attempt (pm,
8831 GNUNET_TIME_relative_to_absolute( 8893 GNUNET_TIME_relative_to_absolute (
8832 GNUNET_TIME_relative_multiply(queue->pd.aged_rtt, 8894 GNUNET_TIME_relative_multiply (queue->pd.aged_rtt,
8833 4))); 8895 4)));
8834 } 8896 }
8835 /* finally, re-schedule queue transmission task itself */ 8897 /* finally, re-schedule queue transmission task itself */
8836 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8898 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8837} 8899}
8838 8900
8839 8901
@@ -8844,35 +8906,35 @@ transmit_on_queue(void *cls)
8844 * @param dqm the send message that was sent 8906 * @param dqm the send message that was sent
8845 */ 8907 */
8846static void 8908static void
8847handle_del_queue_message(void *cls, 8909handle_del_queue_message (void *cls,
8848 const struct GNUNET_TRANSPORT_DelQueueMessage *dqm) 8910 const struct GNUNET_TRANSPORT_DelQueueMessage *dqm)
8849{ 8911{
8850 struct TransportClient *tc = cls; 8912 struct TransportClient *tc = cls;
8851 8913
8852 if (CT_COMMUNICATOR != tc->type) 8914 if (CT_COMMUNICATOR != tc->type)
8853 { 8915 {
8854 GNUNET_break(0); 8916 GNUNET_break (0);
8855 GNUNET_SERVICE_client_drop(tc->client); 8917 GNUNET_SERVICE_client_drop (tc->client);
8856 return; 8918 return;
8857 } 8919 }
8858 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; 8920 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue;
8859 queue = queue->next_client) 8921 queue = queue->next_client)
8860 { 8922 {
8861 struct Neighbour *neighbour = queue->neighbour; 8923 struct Neighbour *neighbour = queue->neighbour;
8862 8924
8863 if ((dqm->qid != queue->qid) || 8925 if ((dqm->qid != queue->qid) ||
8864 (0 != GNUNET_memcmp(&dqm->receiver, &neighbour->pid))) 8926 (0 != GNUNET_memcmp (&dqm->receiver, &neighbour->pid)))
8865 continue; 8927 continue;
8866 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8867 "Dropped queue %s to peer %s\n", 8929 "Dropped queue %s to peer %s\n",
8868 queue->address, 8930 queue->address,
8869 GNUNET_i2s(&neighbour->pid)); 8931 GNUNET_i2s (&neighbour->pid));
8870 free_queue(queue); 8932 free_queue (queue);
8871 GNUNET_SERVICE_client_continue(tc->client); 8933 GNUNET_SERVICE_client_continue (tc->client);
8872 return; 8934 return;
8873 } 8935 }
8874 GNUNET_break(0); 8936 GNUNET_break (0);
8875 GNUNET_SERVICE_client_drop(tc->client); 8937 GNUNET_SERVICE_client_drop (tc->client);
8876} 8938}
8877 8939
8878 8940
@@ -8883,97 +8945,97 @@ handle_del_queue_message(void *cls,
8883 * @param sma the send message that was sent 8945 * @param sma the send message that was sent
8884 */ 8946 */
8885static void 8947static void
8886handle_send_message_ack(void *cls, 8948handle_send_message_ack (void *cls,
8887 const struct GNUNET_TRANSPORT_SendMessageToAck *sma) 8949 const struct GNUNET_TRANSPORT_SendMessageToAck *sma)
8888{ 8950{
8889 struct TransportClient *tc = cls; 8951 struct TransportClient *tc = cls;
8890 struct QueueEntry *qe; 8952 struct QueueEntry *qe;
8891 struct PendingMessage *pm; 8953 struct PendingMessage *pm;
8892 8954
8893 if (CT_COMMUNICATOR != tc->type) 8955 if (CT_COMMUNICATOR != tc->type)
8894 { 8956 {
8895 GNUNET_break(0); 8957 GNUNET_break (0);
8896 GNUNET_SERVICE_client_drop(tc->client); 8958 GNUNET_SERVICE_client_drop (tc->client);
8897 return; 8959 return;
8898 } 8960 }
8899 8961
8900 /* find our queue entry matching the ACK */ 8962 /* find our queue entry matching the ACK */
8901 qe = NULL; 8963 qe = NULL;
8902 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; 8964 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue;
8903 queue = queue->next_client) 8965 queue = queue->next_client)
8966 {
8967 if (0 != GNUNET_memcmp (&queue->neighbour->pid, &sma->receiver))
8968 continue;
8969 for (struct QueueEntry *qep = queue->queue_head; NULL != qep;
8970 qep = qep->next)
8904 { 8971 {
8905 if (0 != GNUNET_memcmp(&queue->neighbour->pid, &sma->receiver)) 8972 if (qep->mid != sma->mid)
8906 continue; 8973 continue;
8907 for (struct QueueEntry *qep = queue->queue_head; NULL != qep; 8974 qe = qep;
8908 qep = qep->next)
8909 {
8910 if (qep->mid != sma->mid)
8911 continue;
8912 qe = qep;
8913 break;
8914 }
8915 break; 8975 break;
8916 } 8976 }
8977 break;
8978 }
8917 if (NULL == qe) 8979 if (NULL == qe)
8918 { 8980 {
8919 /* this should never happen */ 8981 /* this should never happen */
8920 GNUNET_break(0); 8982 GNUNET_break (0);
8921 GNUNET_SERVICE_client_drop(tc->client); 8983 GNUNET_SERVICE_client_drop (tc->client);
8922 return; 8984 return;
8923 } 8985 }
8924 GNUNET_CONTAINER_DLL_remove(qe->queue->queue_head, 8986 GNUNET_CONTAINER_DLL_remove (qe->queue->queue_head,
8925 qe->queue->queue_tail, 8987 qe->queue->queue_tail,
8926 qe); 8988 qe);
8927 qe->queue->queue_length--; 8989 qe->queue->queue_length--;
8928 tc->details.communicator.total_queue_length--; 8990 tc->details.communicator.total_queue_length--;
8929 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 8991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8930 "Received ACK on queue %s to peer %s (new length: %u/%u)\n", 8992 "Received ACK on queue %s to peer %s (new length: %u/%u)\n",
8931 qe->queue->address, 8993 qe->queue->address,
8932 GNUNET_i2s(&qe->queue->neighbour->pid), 8994 GNUNET_i2s (&qe->queue->neighbour->pid),
8933 qe->queue->queue_length, 8995 qe->queue->queue_length,
8934 tc->details.communicator.total_queue_length); 8996 tc->details.communicator.total_queue_length);
8935 GNUNET_SERVICE_client_continue(tc->client); 8997 GNUNET_SERVICE_client_continue (tc->client);
8936 8998
8937 /* if applicable, resume transmissions that waited on ACK */ 8999 /* if applicable, resume transmissions that waited on ACK */
8938 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 == 9000 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 ==
8939 tc->details.communicator.total_queue_length) 9001 tc->details.communicator.total_queue_length)
8940 { 9002 {
8941 /* Communicator dropped below threshold, resume all queues 9003 /* Communicator dropped below threshold, resume all queues
8942 incident with this client! */ 9004 incident with this client! */
8943 GNUNET_STATISTICS_update( 9005 GNUNET_STATISTICS_update (
8944 GST_stats, 9006 GST_stats,
8945 "# Transmission throttled due to communicator queue limit", 9007 "# Transmission throttled due to communicator queue limit",
8946 -1, 9008 -1,
8947 GNUNET_NO); 9009 GNUNET_NO);
8948 for (struct Queue *queue = tc->details.communicator.queue_head; 9010 for (struct Queue *queue = tc->details.communicator.queue_head;
8949 NULL != queue; 9011 NULL != queue;
8950 queue = queue->next_client) 9012 queue = queue->next_client)
8951 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 9013 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8952 } 9014 }
8953 else if (QUEUE_LENGTH_LIMIT - 1 == qe->queue->queue_length) 9015 else if (QUEUE_LENGTH_LIMIT - 1 == qe->queue->queue_length)
8954 { 9016 {
8955 /* queue dropped below threshold; only resume this one queue */ 9017 /* queue dropped below threshold; only resume this one queue */
8956 GNUNET_STATISTICS_update(GST_stats, 9018 GNUNET_STATISTICS_update (GST_stats,
8957 "# Transmission throttled due to queue queue limit", 9019 "# Transmission throttled due to queue queue limit",
8958 -1, 9020 -1,
8959 GNUNET_NO); 9021 GNUNET_NO);
8960 schedule_transmit_on_queue(qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 9022 schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8961 } 9023 }
8962 9024
8963 if (NULL != (pm = qe->pm)) 9025 if (NULL != (pm = qe->pm))
8964 { 9026 {
8965 struct VirtualLink *vl; 9027 struct VirtualLink *vl;
8966 9028
8967 GNUNET_assert(qe == pm->qe); 9029 GNUNET_assert (qe == pm->qe);
8968 pm->qe = NULL; 9030 pm->qe = NULL;
8969 /* If waiting for this communicator may have blocked transmission 9031 /* If waiting for this communicator may have blocked transmission
8970 of pm on other queues for this neighbour, force schedule 9032 of pm on other queues for this neighbour, force schedule
8971 transmit on queue for queues of the neighbour */ 9033 transmit on queue for queues of the neighbour */
8972 vl = pm->vl; 9034 vl = pm->vl;
8973 if (vl->pending_msg_head == pm) 9035 if (vl->pending_msg_head == pm)
8974 check_vl_transmission(vl); 9036 check_vl_transmission (vl);
8975 } 9037 }
8976 GNUNET_free(qe); 9038 GNUNET_free (qe);
8977} 9039}
8978 9040
8979 9041
@@ -8987,24 +9049,24 @@ handle_send_message_ack(void *cls,
8987 * @return #GNUNET_OK (continue to iterate) 9049 * @return #GNUNET_OK (continue to iterate)
8988 */ 9050 */
8989static int 9051static int
8990notify_client_queues(void *cls, 9052notify_client_queues (void *cls,
8991 const struct GNUNET_PeerIdentity *pid, 9053 const struct GNUNET_PeerIdentity *pid,
8992 void *value) 9054 void *value)
8993{ 9055{
8994 struct TransportClient *tc = cls; 9056 struct TransportClient *tc = cls;
8995 struct Neighbour *neighbour = value; 9057 struct Neighbour *neighbour = value;
8996 9058
8997 GNUNET_assert(CT_MONITOR == tc->type); 9059 GNUNET_assert (CT_MONITOR == tc->type);
8998 for (struct Queue *q = neighbour->queue_head; NULL != q; 9060 for (struct Queue *q = neighbour->queue_head; NULL != q;
8999 q = q->next_neighbour) 9061 q = q->next_neighbour)
9000 { 9062 {
9001 struct MonitorEvent me = { .rtt = q->pd.aged_rtt, 9063 struct MonitorEvent me = { .rtt = q->pd.aged_rtt,
9002 .cs = q->cs, 9064 .cs = q->cs,
9003 .num_msg_pending = q->num_msg_pending, 9065 .num_msg_pending = q->num_msg_pending,
9004 .num_bytes_pending = q->num_bytes_pending }; 9066 .num_bytes_pending = q->num_bytes_pending };
9005 9067
9006 notify_monitor(tc, pid, q->address, q->nt, &me); 9068 notify_monitor (tc, pid, q->address, q->nt, &me);
9007 } 9069 }
9008 return GNUNET_OK; 9070 return GNUNET_OK;
9009} 9071}
9010 9072
@@ -9016,23 +9078,23 @@ notify_client_queues(void *cls,
9016 * @param start the start message that was sent 9078 * @param start the start message that was sent
9017 */ 9079 */
9018static void 9080static void
9019handle_monitor_start(void *cls, 9081handle_monitor_start (void *cls,
9020 const struct GNUNET_TRANSPORT_MonitorStart *start) 9082 const struct GNUNET_TRANSPORT_MonitorStart *start)
9021{ 9083{
9022 struct TransportClient *tc = cls; 9084 struct TransportClient *tc = cls;
9023 9085
9024 if (CT_NONE != tc->type) 9086 if (CT_NONE != tc->type)
9025 { 9087 {
9026 GNUNET_break(0); 9088 GNUNET_break (0);
9027 GNUNET_SERVICE_client_drop(tc->client); 9089 GNUNET_SERVICE_client_drop (tc->client);
9028 return; 9090 return;
9029 } 9091 }
9030 tc->type = CT_MONITOR; 9092 tc->type = CT_MONITOR;
9031 tc->details.monitor.peer = start->peer; 9093 tc->details.monitor.peer = start->peer;
9032 tc->details.monitor.one_shot = ntohl(start->one_shot); 9094 tc->details.monitor.one_shot = ntohl (start->one_shot);
9033 GNUNET_CONTAINER_multipeermap_iterate(neighbours, &notify_client_queues, tc); 9095 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &notify_client_queues, tc);
9034 GNUNET_SERVICE_client_mark_monitor(tc->client); 9096 GNUNET_SERVICE_client_mark_monitor (tc->client);
9035 GNUNET_SERVICE_client_continue(tc->client); 9097 GNUNET_SERVICE_client_continue (tc->client);
9036} 9098}
9037 9099
9038 9100
@@ -9044,16 +9106,16 @@ handle_monitor_start(void *cls,
9044 * @return NULL if no such transport client is available 9106 * @return NULL if no such transport client is available
9045 */ 9107 */
9046static struct TransportClient * 9108static struct TransportClient *
9047lookup_communicator(const char *prefix) 9109lookup_communicator (const char *prefix)
9048{ 9110{
9049 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 9111 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
9050 { 9112 {
9051 if (CT_COMMUNICATOR != tc->type) 9113 if (CT_COMMUNICATOR != tc->type)
9052 continue; 9114 continue;
9053 if (0 == strcmp(prefix, tc->details.communicator.address_prefix)) 9115 if (0 == strcmp (prefix, tc->details.communicator.address_prefix))
9054 return tc; 9116 return tc;
9055 } 9117 }
9056 GNUNET_log( 9118 GNUNET_log (
9057 GNUNET_ERROR_TYPE_WARNING, 9119 GNUNET_ERROR_TYPE_WARNING,
9058 "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n", 9120 "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n",
9059 prefix); 9121 prefix);
@@ -9069,7 +9131,7 @@ lookup_communicator(const char *prefix)
9069 * @param address the address to try 9131 * @param address the address to try
9070 */ 9132 */
9071static void 9133static void
9072suggest_to_connect(const struct GNUNET_PeerIdentity *pid, const char *address) 9134suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address)
9073{ 9135{
9074 static uint32_t idgen; 9136 static uint32_t idgen;
9075 struct TransportClient *tc; 9137 struct TransportClient *tc;
@@ -9078,40 +9140,40 @@ suggest_to_connect(const struct GNUNET_PeerIdentity *pid, const char *address)
9078 struct GNUNET_MQ_Envelope *env; 9140 struct GNUNET_MQ_Envelope *env;
9079 size_t alen; 9141 size_t alen;
9080 9142
9081 prefix = GNUNET_HELLO_address_to_prefix(address); 9143 prefix = GNUNET_HELLO_address_to_prefix (address);
9082 if (NULL == prefix) 9144 if (NULL == prefix)
9083 { 9145 {
9084 GNUNET_break(0); /* We got an invalid address!? */ 9146 GNUNET_break (0); /* We got an invalid address!? */
9085 return; 9147 return;
9086 } 9148 }
9087 tc = lookup_communicator(prefix); 9149 tc = lookup_communicator (prefix);
9088 if (NULL == tc) 9150 if (NULL == tc)
9089 { 9151 {
9090 GNUNET_STATISTICS_update(GST_stats, 9152 GNUNET_STATISTICS_update (GST_stats,
9091 "# Suggestions ignored due to missing communicator", 9153 "# Suggestions ignored due to missing communicator",
9092 1, 9154 1,
9093 GNUNET_NO); 9155 GNUNET_NO);
9094 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 9156 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
9095 "Cannot connect to %s at `%s', no matching communicator present\n", 9157 "Cannot connect to %s at `%s', no matching communicator present\n",
9096 GNUNET_i2s(pid), 9158 GNUNET_i2s (pid),
9097 address); 9159 address);
9098 GNUNET_free(prefix); 9160 GNUNET_free (prefix);
9099 return; 9161 return;
9100 } 9162 }
9101 /* forward suggestion for queue creation to communicator */ 9163 /* forward suggestion for queue creation to communicator */
9102 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 9164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9103 "Request #%u for `%s' communicator to create queue to `%s'\n", 9165 "Request #%u for `%s' communicator to create queue to `%s'\n",
9104 (unsigned int)idgen, 9166 (unsigned int) idgen,
9105 prefix, 9167 prefix,
9106 address); 9168 address);
9107 GNUNET_free(prefix); 9169 GNUNET_free (prefix);
9108 alen = strlen(address) + 1; 9170 alen = strlen (address) + 1;
9109 env = 9171 env =
9110 GNUNET_MQ_msg_extra(cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); 9172 GNUNET_MQ_msg_extra (cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
9111 cqm->request_id = htonl(idgen++); 9173 cqm->request_id = htonl (idgen++);
9112 cqm->receiver = *pid; 9174 cqm->receiver = *pid;
9113 memcpy(&cqm[1], address, alen); 9175 memcpy (&cqm[1], address, alen);
9114 GNUNET_MQ_send(tc->mq, env); 9176 GNUNET_MQ_send (tc->mq, env);
9115} 9177}
9116 9178
9117 9179
@@ -9123,22 +9185,22 @@ suggest_to_connect(const struct GNUNET_PeerIdentity *pid, const char *address)
9123 * @param vs state to derive validation challenge from 9185 * @param vs state to derive validation challenge from
9124 */ 9186 */
9125static void 9187static void
9126validation_transmit_on_queue(struct Queue *q, struct ValidationState *vs) 9188validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs)
9127{ 9189{
9128 struct TransportValidationChallengeMessage tvc; 9190 struct TransportValidationChallengeMessage tvc;
9129 9191
9130 vs->last_challenge_use = GNUNET_TIME_absolute_get_monotonic(GST_cfg); 9192 vs->last_challenge_use = GNUNET_TIME_absolute_get_monotonic (GST_cfg);
9131 tvc.header.type = 9193 tvc.header.type =
9132 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); 9194 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE);
9133 tvc.header.size = htons(sizeof(tvc)); 9195 tvc.header.size = htons (sizeof(tvc));
9134 tvc.reserved = htonl(0); 9196 tvc.reserved = htonl (0);
9135 tvc.challenge = vs->challenge; 9197 tvc.challenge = vs->challenge;
9136 tvc.sender_time = GNUNET_TIME_absolute_hton(vs->last_challenge_use); 9198 tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use);
9137 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 9199 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
9138 "Sending address validation challenge %s to %s\n", 9200 "Sending address validation challenge %s to %s\n",
9139 GNUNET_sh2s(&tvc.challenge.value), 9201 GNUNET_sh2s (&tvc.challenge.value),
9140 GNUNET_i2s(&q->neighbour->pid)); 9202 GNUNET_i2s (&q->neighbour->pid));
9141 queue_send_msg(q, NULL, &tvc, sizeof(tvc)); 9203 queue_send_msg (q, NULL, &tvc, sizeof(tvc));
9142} 9204}
9143 9205
9144 9206
@@ -9148,55 +9210,56 @@ validation_transmit_on_queue(struct Queue *q, struct ValidationState *vs)
9148 * @param cls NULL 9210 * @param cls NULL
9149 */ 9211 */
9150static void 9212static void
9151validation_start_cb(void *cls) 9213validation_start_cb (void *cls)
9152{ 9214{
9153 struct ValidationState *vs; 9215 struct ValidationState *vs;
9154 struct Queue *q; 9216 struct Queue *q;
9155 9217
9156 (void)cls; 9218 (void) cls;
9157 validation_task = NULL; 9219 validation_task = NULL;
9158 vs = GNUNET_CONTAINER_heap_peek(validation_heap); 9220 vs = GNUNET_CONTAINER_heap_peek (validation_heap);
9159 /* drop validations past their expiration */ 9221 /* drop validations past their expiration */
9160 while ( 9222 while (
9161 (NULL != vs) && 9223 (NULL != vs) &&
9162 (0 == GNUNET_TIME_absolute_get_remaining(vs->valid_until).rel_value_us)) 9224 (0 == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us))
9163 { 9225 {
9164 free_validation_state(vs); 9226 free_validation_state (vs);
9165 vs = GNUNET_CONTAINER_heap_peek(validation_heap); 9227 vs = GNUNET_CONTAINER_heap_peek (validation_heap);
9166 } 9228 }
9167 if (NULL == vs) 9229 if (NULL == vs)
9168 { 9230 {
9169 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 9231 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
9170 "Address validation task not scheduled anymore, nothing to do\n"); 9232 "Address validation task not scheduled anymore, nothing to do\n");
9171 return; /* woopsie, no more addresses known, should only 9233 return; /* woopsie, no more addresses known, should only
9172 happen if we're really a lonely peer */ 9234 happen if we're really a lonely peer */
9173 } 9235 }
9174 q = find_queue(&vs->pid, vs->address); 9236 q = find_queue (&vs->pid, vs->address);
9175 if (NULL == q) 9237 if (NULL == q)
9176 { 9238 {
9177 vs->awaiting_queue = GNUNET_YES; 9239 vs->awaiting_queue = GNUNET_YES;
9178 suggest_to_connect(&vs->pid, vs->address); 9240 suggest_to_connect (&vs->pid, vs->address);
9179 } 9241 }
9180 else 9242 else
9181 validation_transmit_on_queue(q, vs); 9243 validation_transmit_on_queue (q, vs);
9182 /* Finally, reschedule next attempt */ 9244 /* Finally, reschedule next attempt */
9183 vs->challenge_backoff = 9245 vs->challenge_backoff =
9184 GNUNET_TIME_randomized_backoff(vs->challenge_backoff, 9246 GNUNET_TIME_randomized_backoff (vs->challenge_backoff,
9185 MAX_VALIDATION_CHALLENGE_FREQ); 9247 MAX_VALIDATION_CHALLENGE_FREQ);
9186 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 9248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9187 "Address validation task will run again in %s\n", 9249 "Address validation task will run again in %s\n",
9188 GNUNET_STRINGS_relative_time_to_string(vs->challenge_backoff, 9250 GNUNET_STRINGS_relative_time_to_string (vs->challenge_backoff,
9189 GNUNET_YES)); 9251 GNUNET_YES));
9190 update_next_challenge_time(vs, 9252 update_next_challenge_time (vs,
9191 GNUNET_TIME_relative_to_absolute( 9253 GNUNET_TIME_relative_to_absolute (
9192 vs->challenge_backoff)); 9254 vs->challenge_backoff));
9193} 9255}
9194 9256
9195 9257
9196/** 9258/**
9197 * Closure for #check_connection_quality. 9259 * Closure for #check_connection_quality.
9198 */ 9260 */
9199struct QueueQualityContext { 9261struct QueueQualityContext
9262{
9200 /** 9263 /**
9201 * Set to the @e k'th queue encountered. 9264 * Set to the @e k'th queue encountered.
9202 */ 9265 */
@@ -9232,26 +9295,26 @@ struct QueueQualityContext {
9232 * @return #GNUNET_OK (continue to iterate) 9295 * @return #GNUNET_OK (continue to iterate)
9233 */ 9296 */
9234static int 9297static int
9235check_connection_quality(void *cls, 9298check_connection_quality (void *cls,
9236 const struct GNUNET_PeerIdentity *pid, 9299 const struct GNUNET_PeerIdentity *pid,
9237 void *value) 9300 void *value)
9238{ 9301{
9239 struct QueueQualityContext *ctx = cls; 9302 struct QueueQualityContext *ctx = cls;
9240 struct Neighbour *n = value; 9303 struct Neighbour *n = value;
9241 int do_inc; 9304 int do_inc;
9242 9305
9243 (void)pid; 9306 (void) pid;
9244 do_inc = GNUNET_NO; 9307 do_inc = GNUNET_NO;
9245 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) 9308 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
9246 { 9309 {
9247 ctx->num_queues++; 9310 ctx->num_queues++;
9248 if (0 == ctx->k--) 9311 if (0 == ctx->k--)
9249 ctx->q = q; 9312 ctx->q = q;
9250 /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput 9313 /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput
9251 statistics and consider those as well here? */ 9314 statistics and consider those as well here? */
9252 if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us) 9315 if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us)
9253 do_inc = GNUNET_YES; 9316 do_inc = GNUNET_YES;
9254 } 9317 }
9255 if (GNUNET_YES == do_inc) 9318 if (GNUNET_YES == do_inc)
9256 ctx->quality_count++; 9319 ctx->quality_count++;
9257 return GNUNET_OK; 9320 return GNUNET_OK;
@@ -9270,103 +9333,103 @@ check_connection_quality(void *cls,
9270 * @param cls NULL 9333 * @param cls NULL
9271 */ 9334 */
9272static void 9335static void
9273start_dv_learn(void *cls) 9336start_dv_learn (void *cls)
9274{ 9337{
9275 struct LearnLaunchEntry *lle; 9338 struct LearnLaunchEntry *lle;
9276 struct QueueQualityContext qqc; 9339 struct QueueQualityContext qqc;
9277 struct TransportDVLearnMessage dvl; 9340 struct TransportDVLearnMessage dvl;
9278 9341
9279 (void)cls; 9342 (void) cls;
9280 dvlearn_task = NULL; 9343 dvlearn_task = NULL;
9281 if (0 == GNUNET_CONTAINER_multipeermap_size(neighbours)) 9344 if (0 == GNUNET_CONTAINER_multipeermap_size (neighbours))
9282 return; /* lost all connectivity, cannot do learning */ 9345 return; /* lost all connectivity, cannot do learning */
9283 qqc.quality_count = 0; 9346 qqc.quality_count = 0;
9284 qqc.num_queues = 0; 9347 qqc.num_queues = 0;
9285 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 9348 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
9286 &check_connection_quality, 9349 &check_connection_quality,
9287 &qqc); 9350 &qqc);
9288 if (qqc.quality_count > DV_LEARN_QUALITY_THRESHOLD) 9351 if (qqc.quality_count > DV_LEARN_QUALITY_THRESHOLD)
9289 { 9352 {
9290 struct GNUNET_TIME_Relative delay; 9353 struct GNUNET_TIME_Relative delay;
9291 unsigned int factor; 9354 unsigned int factor;
9292 9355
9293 /* scale our retries by how far we are above the threshold */ 9356 /* scale our retries by how far we are above the threshold */
9294 factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; 9357 factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD;
9295 delay = GNUNET_TIME_relative_multiply(DV_LEARN_BASE_FREQUENCY, factor); 9358 delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, factor);
9296 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 9359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9297 "At connection quality %u, will launch DV learn in %s\n", 9360 "At connection quality %u, will launch DV learn in %s\n",
9298 qqc.quality_count, 9361 qqc.quality_count,
9299 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); 9362 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
9300 dvlearn_task = GNUNET_SCHEDULER_add_delayed(delay, &start_dv_learn, NULL); 9363 dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay, &start_dv_learn, NULL);
9301 return; 9364 return;
9302 } 9365 }
9303 /* remove old entries in #dvlearn_map if it has grown too big */ 9366 /* remove old entries in #dvlearn_map if it has grown too big */
9304 while (MAX_DV_LEARN_PENDING >= 9367 while (MAX_DV_LEARN_PENDING >=
9305 GNUNET_CONTAINER_multishortmap_size(dvlearn_map)) 9368 GNUNET_CONTAINER_multishortmap_size (dvlearn_map))
9306 { 9369 {
9307 lle = lle_tail; 9370 lle = lle_tail;
9308 GNUNET_assert(GNUNET_YES == 9371 GNUNET_assert (GNUNET_YES ==
9309 GNUNET_CONTAINER_multishortmap_remove(dvlearn_map, 9372 GNUNET_CONTAINER_multishortmap_remove (dvlearn_map,
9310 &lle->challenge.value, 9373 &lle->challenge.value,
9311 lle)); 9374 lle));
9312 GNUNET_CONTAINER_DLL_remove(lle_head, lle_tail, lle); 9375 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle);
9313 GNUNET_free(lle); 9376 GNUNET_free (lle);
9314 } 9377 }
9315 /* setup data structure for learning */ 9378 /* setup data structure for learning */
9316 lle = GNUNET_new(struct LearnLaunchEntry); 9379 lle = GNUNET_new (struct LearnLaunchEntry);
9317 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, 9380 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
9318 &lle->challenge, 9381 &lle->challenge,
9319 sizeof(lle->challenge)); 9382 sizeof(lle->challenge));
9320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 9383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9321 "Starting launch DV learn with challenge %s\n", 9384 "Starting launch DV learn with challenge %s\n",
9322 GNUNET_sh2s(&lle->challenge.value)); 9385 GNUNET_sh2s (&lle->challenge.value));
9323 GNUNET_CONTAINER_DLL_insert(lle_head, lle_tail, lle); 9386 GNUNET_CONTAINER_DLL_insert (lle_head, lle_tail, lle);
9324 GNUNET_break(GNUNET_YES == 9387 GNUNET_break (GNUNET_YES ==
9325 GNUNET_CONTAINER_multishortmap_put( 9388 GNUNET_CONTAINER_multishortmap_put (
9326 dvlearn_map, 9389 dvlearn_map,
9327 &lle->challenge.value, 9390 &lle->challenge.value,
9328 lle, 9391 lle,
9329 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 9392 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
9330 dvl.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); 9393 dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN);
9331 dvl.header.size = htons(sizeof(dvl)); 9394 dvl.header.size = htons (sizeof(dvl));
9332 dvl.num_hops = htons(0); 9395 dvl.num_hops = htons (0);
9333 dvl.bidirectional = htons(0); 9396 dvl.bidirectional = htons (0);
9334 dvl.non_network_delay = GNUNET_TIME_relative_hton(GNUNET_TIME_UNIT_ZERO); 9397 dvl.non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO);
9335 dvl.monotonic_time = 9398 dvl.monotonic_time =
9336 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(GST_cfg)); 9399 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg));
9337 { 9400 {
9338 struct DvInitPS dvip = { .purpose.purpose = htonl( 9401 struct DvInitPS dvip = { .purpose.purpose = htonl (
9339 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), 9402 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR),
9340 .purpose.size = htonl(sizeof(dvip)), 9403 .purpose.size = htonl (sizeof(dvip)),
9341 .monotonic_time = dvl.monotonic_time, 9404 .monotonic_time = dvl.monotonic_time,
9342 .challenge = lle->challenge }; 9405 .challenge = lle->challenge };
9343 9406
9344 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, 9407 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
9345 &dvip.purpose, 9408 &dvip.purpose,
9346 &dvl.init_sig)); 9409 &dvl.init_sig));
9347 } 9410 }
9348 dvl.initiator = GST_my_identity; 9411 dvl.initiator = GST_my_identity;
9349 dvl.challenge = lle->challenge; 9412 dvl.challenge = lle->challenge;
9350 9413
9351 qqc.quality_count = 0; 9414 qqc.quality_count = 0;
9352 qqc.k = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues); 9415 qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues);
9353 qqc.num_queues = 0; 9416 qqc.num_queues = 0;
9354 qqc.q = NULL; 9417 qqc.q = NULL;
9355 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 9418 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
9356 &check_connection_quality, 9419 &check_connection_quality,
9357 &qqc); 9420 &qqc);
9358 GNUNET_assert(NULL != qqc.q); 9421 GNUNET_assert (NULL != qqc.q);
9359 9422
9360 /* Do this as close to transmission time as possible! */ 9423 /* Do this as close to transmission time as possible! */
9361 lle->launch_time = GNUNET_TIME_absolute_get(); 9424 lle->launch_time = GNUNET_TIME_absolute_get ();
9362 9425
9363 queue_send_msg(qqc.q, NULL, &dvl, sizeof(dvl)); 9426 queue_send_msg (qqc.q, NULL, &dvl, sizeof(dvl));
9364 /* reschedule this job, randomizing the time it runs (but no 9427 /* reschedule this job, randomizing the time it runs (but no
9365 actual backoff!) */ 9428 actual backoff!) */
9366 dvlearn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_randomize( 9429 dvlearn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_randomize (
9367 DV_LEARN_BASE_FREQUENCY), 9430 DV_LEARN_BASE_FREQUENCY),
9368 &start_dv_learn, 9431 &start_dv_learn,
9369 NULL); 9432 NULL);
9370} 9433}
9371 9434
9372 9435
@@ -9380,21 +9443,21 @@ start_dv_learn(void *cls)
9380 * @return #GNUNET_NO if a match was found and we can stop looking 9443 * @return #GNUNET_NO if a match was found and we can stop looking
9381 */ 9444 */
9382static int 9445static int
9383check_validation_request_pending(void *cls, 9446check_validation_request_pending (void *cls,
9384 const struct GNUNET_PeerIdentity *pid, 9447 const struct GNUNET_PeerIdentity *pid,
9385 void *value) 9448 void *value)
9386{ 9449{
9387 struct Queue *q = cls; 9450 struct Queue *q = cls;
9388 struct ValidationState *vs = value; 9451 struct ValidationState *vs = value;
9389 9452
9390 (void)pid; 9453 (void) pid;
9391 if ((GNUNET_YES == vs->awaiting_queue) && 9454 if ((GNUNET_YES == vs->awaiting_queue) &&
9392 (0 == strcmp(vs->address, q->address))) 9455 (0 == strcmp (vs->address, q->address)))
9393 { 9456 {
9394 vs->awaiting_queue = GNUNET_NO; 9457 vs->awaiting_queue = GNUNET_NO;
9395 validation_transmit_on_queue(q, vs); 9458 validation_transmit_on_queue (q, vs);
9396 return GNUNET_NO; 9459 return GNUNET_NO;
9397 } 9460 }
9398 return GNUNET_OK; 9461 return GNUNET_OK;
9399} 9462}
9400 9463
@@ -9408,31 +9471,31 @@ check_validation_request_pending(void *cls,
9408 * @param emsg error message 9471 * @param emsg error message
9409 */ 9472 */
9410static void 9473static void
9411neighbour_dv_monotime_cb(void *cls, 9474neighbour_dv_monotime_cb (void *cls,
9412 const struct GNUNET_PEERSTORE_Record *record, 9475 const struct GNUNET_PEERSTORE_Record *record,
9413 const char *emsg) 9476 const char *emsg)
9414{ 9477{
9415 struct Neighbour *n = cls; 9478 struct Neighbour *n = cls;
9416 struct GNUNET_TIME_AbsoluteNBO *mtbe; 9479 struct GNUNET_TIME_AbsoluteNBO *mtbe;
9417 9480
9418 (void)emsg; 9481 (void) emsg;
9419 if (NULL == record) 9482 if (NULL == record)
9420 { 9483 {
9421 /* we're done with #neighbour_dv_monotime_cb() invocations, 9484 /* we're done with #neighbour_dv_monotime_cb() invocations,
9422 continue normal processing */ 9485 continue normal processing */
9423 n->get = NULL; 9486 n->get = NULL;
9424 n->dv_monotime_available = GNUNET_YES; 9487 n->dv_monotime_available = GNUNET_YES;
9425 return; 9488 return;
9426 } 9489 }
9427 if (sizeof(*mtbe) != record->value_size) 9490 if (sizeof(*mtbe) != record->value_size)
9428 { 9491 {
9429 GNUNET_break(0); 9492 GNUNET_break (0);
9430 return; 9493 return;
9431 } 9494 }
9432 mtbe = record->value; 9495 mtbe = record->value;
9433 n->last_dv_learn_monotime = 9496 n->last_dv_learn_monotime =
9434 GNUNET_TIME_absolute_max(n->last_dv_learn_monotime, 9497 GNUNET_TIME_absolute_max (n->last_dv_learn_monotime,
9435 GNUNET_TIME_absolute_ntoh(*mtbe)); 9498 GNUNET_TIME_absolute_ntoh (*mtbe));
9436} 9499}
9437 9500
9438 9501
@@ -9443,8 +9506,8 @@ neighbour_dv_monotime_cb(void *cls,
9443 * @param aqm the send message that was sent 9506 * @param aqm the send message that was sent
9444 */ 9507 */
9445static void 9508static void
9446handle_add_queue_message(void *cls, 9509handle_add_queue_message (void *cls,
9447 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) 9510 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
9448{ 9511{
9449 struct TransportClient *tc = cls; 9512 struct TransportClient *tc = cls;
9450 struct Queue *queue; 9513 struct Queue *queue;
@@ -9452,77 +9515,77 @@ handle_add_queue_message(void *cls,
9452 const char *addr; 9515 const char *addr;
9453 uint16_t addr_len; 9516 uint16_t addr_len;
9454 9517
9455 if (ntohl(aqm->mtu) <= sizeof(struct TransportFragmentBoxMessage)) 9518 if (ntohl (aqm->mtu) <= sizeof(struct TransportFragmentBoxMessage))
9456 { 9519 {
9457 /* MTU so small as to be useless for transmissions, 9520 /* MTU so small as to be useless for transmissions,
9458 required for #fragment_message()! */ 9521 required for #fragment_message()! */
9459 GNUNET_break_op(0); 9522 GNUNET_break_op (0);
9460 GNUNET_SERVICE_client_drop(tc->client); 9523 GNUNET_SERVICE_client_drop (tc->client);
9461 return; 9524 return;
9462 } 9525 }
9463 neighbour = lookup_neighbour(&aqm->receiver); 9526 neighbour = lookup_neighbour (&aqm->receiver);
9464 if (NULL == neighbour) 9527 if (NULL == neighbour)
9465 { 9528 {
9466 neighbour = GNUNET_new(struct Neighbour); 9529 neighbour = GNUNET_new (struct Neighbour);
9467 neighbour->pid = aqm->receiver; 9530 neighbour->pid = aqm->receiver;
9468 GNUNET_assert(GNUNET_OK == 9531 GNUNET_assert (GNUNET_OK ==
9469 GNUNET_CONTAINER_multipeermap_put( 9532 GNUNET_CONTAINER_multipeermap_put (
9470 neighbours, 9533 neighbours,
9471 &neighbour->pid, 9534 &neighbour->pid,
9472 neighbour, 9535 neighbour,
9473 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 9536 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
9474 neighbour->get = 9537 neighbour->get =
9475 GNUNET_PEERSTORE_iterate(peerstore, 9538 GNUNET_PEERSTORE_iterate (peerstore,
9476 "transport", 9539 "transport",
9477 &neighbour->pid, 9540 &neighbour->pid,
9478 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, 9541 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME,
9479 &neighbour_dv_monotime_cb, 9542 &neighbour_dv_monotime_cb,
9480 neighbour); 9543 neighbour);
9481 } 9544 }
9482 addr_len = ntohs(aqm->header.size) - sizeof(*aqm); 9545 addr_len = ntohs (aqm->header.size) - sizeof(*aqm);
9483 addr = (const char *)&aqm[1]; 9546 addr = (const char *) &aqm[1];
9484 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 9547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9485 "New queue %s to %s available with QID %llu\n", 9548 "New queue %s to %s available with QID %llu\n",
9486 addr, 9549 addr,
9487 GNUNET_i2s(&aqm->receiver), 9550 GNUNET_i2s (&aqm->receiver),
9488 (unsigned long long)aqm->qid); 9551 (unsigned long long) aqm->qid);
9489 queue = GNUNET_malloc(sizeof(struct Queue) + addr_len); 9552 queue = GNUNET_malloc (sizeof(struct Queue) + addr_len);
9490 queue->tc = tc; 9553 queue->tc = tc;
9491 queue->address = (const char *)&queue[1]; 9554 queue->address = (const char *) &queue[1];
9492 queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL; 9555 queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL;
9493 queue->qid = aqm->qid; 9556 queue->qid = aqm->qid;
9494 queue->mtu = ntohl(aqm->mtu); 9557 queue->mtu = ntohl (aqm->mtu);
9495 queue->nt = (enum GNUNET_NetworkType)ntohl(aqm->nt); 9558 queue->nt = (enum GNUNET_NetworkType) ntohl (aqm->nt);
9496 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl(aqm->cs); 9559 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs);
9497 queue->neighbour = neighbour; 9560 queue->neighbour = neighbour;
9498 queue->idle = GNUNET_YES; 9561 queue->idle = GNUNET_YES;
9499 memcpy(&queue[1], addr, addr_len); 9562 memcpy (&queue[1], addr, addr_len);
9500 /* notify monitors about new queue */ 9563 /* notify monitors about new queue */
9501 { 9564 {
9502 struct MonitorEvent me = { .rtt = queue->pd.aged_rtt, .cs = queue->cs }; 9565 struct MonitorEvent me = { .rtt = queue->pd.aged_rtt, .cs = queue->cs };
9503 9566
9504 notify_monitors(&neighbour->pid, queue->address, queue->nt, &me); 9567 notify_monitors (&neighbour->pid, queue->address, queue->nt, &me);
9505 } 9568 }
9506 GNUNET_CONTAINER_MDLL_insert(neighbour, 9569 GNUNET_CONTAINER_MDLL_insert (neighbour,
9507 neighbour->queue_head, 9570 neighbour->queue_head,
9508 neighbour->queue_tail, 9571 neighbour->queue_tail,
9509 queue); 9572 queue);
9510 GNUNET_CONTAINER_MDLL_insert(client, 9573 GNUNET_CONTAINER_MDLL_insert (client,
9511 tc->details.communicator.queue_head, 9574 tc->details.communicator.queue_head,
9512 tc->details.communicator.queue_tail, 9575 tc->details.communicator.queue_tail,
9513 queue); 9576 queue);
9514 /* check if valdiations are waiting for the queue */ 9577 /* check if valdiations are waiting for the queue */
9515 (void) 9578 (void)
9516 GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, 9579 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
9517 &aqm->receiver, 9580 &aqm->receiver,
9518 &check_validation_request_pending, 9581 &check_validation_request_pending,
9519 queue); 9582 queue);
9520 /* look for traffic for this queue */ 9583 /* look for traffic for this queue */
9521 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 9584 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9522 /* might be our first queue, try launching DV learning */ 9585 /* might be our first queue, try launching DV learning */
9523 if (NULL == dvlearn_task) 9586 if (NULL == dvlearn_task)
9524 dvlearn_task = GNUNET_SCHEDULER_add_now(&start_dv_learn, NULL); 9587 dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, NULL);
9525 GNUNET_SERVICE_client_continue(tc->client); 9588 GNUNET_SERVICE_client_continue (tc->client);
9526} 9589}
9527 9590
9528 9591
@@ -9534,25 +9597,25 @@ handle_add_queue_message(void *cls,
9534 * @param cqr confirmation message 9597 * @param cqr confirmation message
9535 */ 9598 */
9536static void 9599static void
9537handle_queue_create_ok(void *cls, 9600handle_queue_create_ok (void *cls,
9538 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) 9601 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr)
9539{ 9602{
9540 struct TransportClient *tc = cls; 9603 struct TransportClient *tc = cls;
9541 9604
9542 if (CT_COMMUNICATOR != tc->type) 9605 if (CT_COMMUNICATOR != tc->type)
9543 { 9606 {
9544 GNUNET_break(0); 9607 GNUNET_break (0);
9545 GNUNET_SERVICE_client_drop(tc->client); 9608 GNUNET_SERVICE_client_drop (tc->client);
9546 return; 9609 return;
9547 } 9610 }
9548 GNUNET_STATISTICS_update(GST_stats, 9611 GNUNET_STATISTICS_update (GST_stats,
9549 "# Suggestions succeeded at communicator", 9612 "# Suggestions succeeded at communicator",
9550 1, 9613 1,
9551 GNUNET_NO); 9614 GNUNET_NO);
9552 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 9615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9553 "Request #%u for communicator to create queue succeeded\n", 9616 "Request #%u for communicator to create queue succeeded\n",
9554 (unsigned int)ntohs(cqr->request_id)); 9617 (unsigned int) ntohs (cqr->request_id));
9555 GNUNET_SERVICE_client_continue(tc->client); 9618 GNUNET_SERVICE_client_continue (tc->client);
9556} 9619}
9557 9620
9558 9621
@@ -9565,26 +9628,26 @@ handle_queue_create_ok(void *cls,
9565 * @param cqr failure message 9628 * @param cqr failure message
9566 */ 9629 */
9567static void 9630static void
9568handle_queue_create_fail( 9631handle_queue_create_fail (
9569 void *cls, 9632 void *cls,
9570 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) 9633 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr)
9571{ 9634{
9572 struct TransportClient *tc = cls; 9635 struct TransportClient *tc = cls;
9573 9636
9574 if (CT_COMMUNICATOR != tc->type) 9637 if (CT_COMMUNICATOR != tc->type)
9575 { 9638 {
9576 GNUNET_break(0); 9639 GNUNET_break (0);
9577 GNUNET_SERVICE_client_drop(tc->client); 9640 GNUNET_SERVICE_client_drop (tc->client);
9578 return; 9641 return;
9579 } 9642 }
9580 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 9643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9581 "Request #%u for communicator to create queue failed\n", 9644 "Request #%u for communicator to create queue failed\n",
9582 (unsigned int)ntohs(cqr->request_id)); 9645 (unsigned int) ntohs (cqr->request_id));
9583 GNUNET_STATISTICS_update(GST_stats, 9646 GNUNET_STATISTICS_update (GST_stats,
9584 "# Suggestions failed in queue creation at communicator", 9647 "# Suggestions failed in queue creation at communicator",
9585 1, 9648 1,
9586 GNUNET_NO); 9649 GNUNET_NO);
9587 GNUNET_SERVICE_client_continue(tc->client); 9650 GNUNET_SERVICE_client_continue (tc->client);
9588} 9651}
9589 9652
9590 9653
@@ -9596,27 +9659,27 @@ handle_queue_create_fail(
9596 * @param msg the start message 9659 * @param msg the start message
9597 */ 9660 */
9598static void 9661static void
9599handle_suggest_cancel(void *cls, const struct ExpressPreferenceMessage *msg) 9662handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg)
9600{ 9663{
9601 struct TransportClient *tc = cls; 9664 struct TransportClient *tc = cls;
9602 struct PeerRequest *pr; 9665 struct PeerRequest *pr;
9603 9666
9604 if (CT_APPLICATION != tc->type) 9667 if (CT_APPLICATION != tc->type)
9605 { 9668 {
9606 GNUNET_break(0); 9669 GNUNET_break (0);
9607 GNUNET_SERVICE_client_drop(tc->client); 9670 GNUNET_SERVICE_client_drop (tc->client);
9608 return; 9671 return;
9609 } 9672 }
9610 pr = GNUNET_CONTAINER_multipeermap_get(tc->details.application.requests, 9673 pr = GNUNET_CONTAINER_multipeermap_get (tc->details.application.requests,
9611 &msg->peer); 9674 &msg->peer);
9612 if (NULL == pr) 9675 if (NULL == pr)
9613 { 9676 {
9614 GNUNET_break(0); 9677 GNUNET_break (0);
9615 GNUNET_SERVICE_client_drop(tc->client); 9678 GNUNET_SERVICE_client_drop (tc->client);
9616 return; 9679 return;
9617 } 9680 }
9618 (void)stop_peer_request(tc, &pr->pid, pr); 9681 (void) stop_peer_request (tc, &pr->pid, pr);
9619 GNUNET_SERVICE_client_continue(tc->client); 9682 GNUNET_SERVICE_client_continue (tc->client);
9620} 9683}
9621 9684
9622 9685
@@ -9628,27 +9691,27 @@ handle_suggest_cancel(void *cls, const struct ExpressPreferenceMessage *msg)
9628 * @param emsg error message, or NULL if no errors 9691 * @param emsg error message, or NULL if no errors
9629 */ 9692 */
9630static void 9693static void
9631handle_hello_for_client(void *cls, 9694handle_hello_for_client (void *cls,
9632 const struct GNUNET_PEERSTORE_Record *record, 9695 const struct GNUNET_PEERSTORE_Record *record,
9633 const char *emsg) 9696 const char *emsg)
9634{ 9697{
9635 struct PeerRequest *pr = cls; 9698 struct PeerRequest *pr = cls;
9636 const char *val; 9699 const char *val;
9637 9700
9638 if (NULL != emsg) 9701 if (NULL != emsg)
9639 { 9702 {
9640 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 9703 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
9641 "Got failure from PEERSTORE: %s\n", 9704 "Got failure from PEERSTORE: %s\n",
9642 emsg); 9705 emsg);
9643 return; 9706 return;
9644 } 9707 }
9645 val = record->value; 9708 val = record->value;
9646 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) 9709 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1]))
9647 { 9710 {
9648 GNUNET_break(0); 9711 GNUNET_break (0);
9649 return; 9712 return;
9650 } 9713 }
9651 start_address_validation(&pr->pid, (const char *)record->value); 9714 start_address_validation (&pr->pid, (const char *) record->value);
9652} 9715}
9653 9716
9654 9717
@@ -9660,51 +9723,51 @@ handle_hello_for_client(void *cls,
9660 * @param msg the start message 9723 * @param msg the start message
9661 */ 9724 */
9662static void 9725static void
9663handle_suggest(void *cls, const struct ExpressPreferenceMessage *msg) 9726handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg)
9664{ 9727{
9665 struct TransportClient *tc = cls; 9728 struct TransportClient *tc = cls;
9666 struct PeerRequest *pr; 9729 struct PeerRequest *pr;
9667 9730
9668 if (CT_NONE == tc->type) 9731 if (CT_NONE == tc->type)
9669 { 9732 {
9670 tc->type = CT_APPLICATION; 9733 tc->type = CT_APPLICATION;
9671 tc->details.application.requests = 9734 tc->details.application.requests =
9672 GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); 9735 GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
9673 } 9736 }
9674 if (CT_APPLICATION != tc->type) 9737 if (CT_APPLICATION != tc->type)
9675 { 9738 {
9676 GNUNET_break(0); 9739 GNUNET_break (0);
9677 GNUNET_SERVICE_client_drop(tc->client); 9740 GNUNET_SERVICE_client_drop (tc->client);
9678 return; 9741 return;
9679 } 9742 }
9680 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 9743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9681 "Client suggested we talk to %s with preference %d at rate %u\n", 9744 "Client suggested we talk to %s with preference %d at rate %u\n",
9682 GNUNET_i2s(&msg->peer), 9745 GNUNET_i2s (&msg->peer),
9683 (int)ntohl(msg->pk), 9746 (int) ntohl (msg->pk),
9684 (int)ntohl(msg->bw.value__)); 9747 (int) ntohl (msg->bw.value__));
9685 pr = GNUNET_new(struct PeerRequest); 9748 pr = GNUNET_new (struct PeerRequest);
9686 pr->tc = tc; 9749 pr->tc = tc;
9687 pr->pid = msg->peer; 9750 pr->pid = msg->peer;
9688 pr->bw = msg->bw; 9751 pr->bw = msg->bw;
9689 pr->pk = (enum GNUNET_MQ_PriorityPreferences)ntohl(msg->pk); 9752 pr->pk = (enum GNUNET_MQ_PriorityPreferences) ntohl (msg->pk);
9690 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put( 9753 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put (
9691 tc->details.application.requests, 9754 tc->details.application.requests,
9692 &pr->pid, 9755 &pr->pid,
9693 pr, 9756 pr,
9694 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 9757 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
9695 { 9758 {
9696 GNUNET_break(0); 9759 GNUNET_break (0);
9697 GNUNET_free(pr); 9760 GNUNET_free (pr);
9698 GNUNET_SERVICE_client_drop(tc->client); 9761 GNUNET_SERVICE_client_drop (tc->client);
9699 return; 9762 return;
9700 } 9763 }
9701 pr->wc = GNUNET_PEERSTORE_watch(peerstore, 9764 pr->wc = GNUNET_PEERSTORE_watch (peerstore,
9702 "transport", 9765 "transport",
9703 &pr->pid, 9766 &pr->pid,
9704 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, 9767 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
9705 &handle_hello_for_client, 9768 &handle_hello_for_client,
9706 pr); 9769 pr);
9707 GNUNET_SERVICE_client_continue(tc->client); 9770 GNUNET_SERVICE_client_continue (tc->client);
9708} 9771}
9709 9772
9710 9773
@@ -9717,11 +9780,11 @@ handle_suggest(void *cls, const struct ExpressPreferenceMessage *msg)
9717 * @return #GNUNET_OK on success 9780 * @return #GNUNET_OK on success
9718 */ 9781 */
9719static int 9782static int
9720check_request_hello_validation(void *cls, 9783check_request_hello_validation (void *cls,
9721 const struct RequestHelloValidationMessage *m) 9784 const struct RequestHelloValidationMessage *m)
9722{ 9785{
9723 (void)cls; 9786 (void) cls;
9724 GNUNET_MQ_check_zero_termination(m); 9787 GNUNET_MQ_check_zero_termination (m);
9725 return GNUNET_OK; 9788 return GNUNET_OK;
9726} 9789}
9727 9790
@@ -9734,13 +9797,13 @@ check_request_hello_validation(void *cls,
9734 * @param m message to verify 9797 * @param m message to verify
9735 */ 9798 */
9736static void 9799static void
9737handle_request_hello_validation(void *cls, 9800handle_request_hello_validation (void *cls,
9738 const struct RequestHelloValidationMessage *m) 9801 const struct RequestHelloValidationMessage *m)
9739{ 9802{
9740 struct TransportClient *tc = cls; 9803 struct TransportClient *tc = cls;
9741 9804
9742 start_address_validation(&m->peer, (const char *)&m[1]); 9805 start_address_validation (&m->peer, (const char *) &m[1]);
9743 GNUNET_SERVICE_client_continue(tc->client); 9806 GNUNET_SERVICE_client_continue (tc->client);
9744} 9807}
9745 9808
9746 9809
@@ -9753,16 +9816,16 @@ handle_request_hello_validation(void *cls,
9753 * @return #GNUNET_OK (always) 9816 * @return #GNUNET_OK (always)
9754 */ 9817 */
9755static int 9818static int
9756free_neighbour_cb(void *cls, 9819free_neighbour_cb (void *cls,
9757 const struct GNUNET_PeerIdentity *pid, 9820 const struct GNUNET_PeerIdentity *pid,
9758 void *value) 9821 void *value)
9759{ 9822{
9760 struct Neighbour *neighbour = value; 9823 struct Neighbour *neighbour = value;
9761 9824
9762 (void)cls; 9825 (void) cls;
9763 (void)pid; 9826 (void) pid;
9764 GNUNET_break(0); // should this ever happen? 9827 GNUNET_break (0); // should this ever happen?
9765 free_neighbour(neighbour); 9828 free_neighbour (neighbour);
9766 9829
9767 return GNUNET_OK; 9830 return GNUNET_OK;
9768} 9831}
@@ -9777,15 +9840,15 @@ free_neighbour_cb(void *cls,
9777 * @return #GNUNET_OK (always) 9840 * @return #GNUNET_OK (always)
9778 */ 9841 */
9779static int 9842static int
9780free_dv_routes_cb(void *cls, 9843free_dv_routes_cb (void *cls,
9781 const struct GNUNET_PeerIdentity *pid, 9844 const struct GNUNET_PeerIdentity *pid,
9782 void *value) 9845 void *value)
9783{ 9846{
9784 struct DistanceVector *dv = value; 9847 struct DistanceVector *dv = value;
9785 9848
9786 (void)cls; 9849 (void) cls;
9787 (void)pid; 9850 (void) pid;
9788 free_dv_route(dv); 9851 free_dv_route (dv);
9789 9852
9790 return GNUNET_OK; 9853 return GNUNET_OK;
9791} 9854}
@@ -9800,15 +9863,15 @@ free_dv_routes_cb(void *cls,
9800 * @return #GNUNET_OK (always) 9863 * @return #GNUNET_OK (always)
9801 */ 9864 */
9802static int 9865static int
9803free_validation_state_cb(void *cls, 9866free_validation_state_cb (void *cls,
9804 const struct GNUNET_PeerIdentity *pid, 9867 const struct GNUNET_PeerIdentity *pid,
9805 void *value) 9868 void *value)
9806{ 9869{
9807 struct ValidationState *vs = value; 9870 struct ValidationState *vs = value;
9808 9871
9809 (void)cls; 9872 (void) cls;
9810 (void)pid; 9873 (void) pid;
9811 free_validation_state(vs); 9874 free_validation_state (vs);
9812 return GNUNET_OK; 9875 return GNUNET_OK;
9813} 9876}
9814 9877
@@ -9822,13 +9885,13 @@ free_validation_state_cb(void *cls,
9822 * @return #GNUNET_OK (always) 9885 * @return #GNUNET_OK (always)
9823 */ 9886 */
9824static int 9887static int
9825free_pending_ack_cb(void *cls, const struct GNUNET_Uuid *key, void *value) 9888free_pending_ack_cb (void *cls, const struct GNUNET_Uuid *key, void *value)
9826{ 9889{
9827 struct PendingAcknowledgement *pa = value; 9890 struct PendingAcknowledgement *pa = value;
9828 9891
9829 (void)cls; 9892 (void) cls;
9830 (void)key; 9893 (void) key;
9831 free_pending_acknowledgement(pa); 9894 free_pending_acknowledgement (pa);
9832 return GNUNET_OK; 9895 return GNUNET_OK;
9833} 9896}
9834 9897
@@ -9842,15 +9905,15 @@ free_pending_ack_cb(void *cls, const struct GNUNET_Uuid *key, void *value)
9842 * @return #GNUNET_OK (always) 9905 * @return #GNUNET_OK (always)
9843 */ 9906 */
9844static int 9907static int
9845free_ack_cummulator_cb(void *cls, 9908free_ack_cummulator_cb (void *cls,
9846 const struct GNUNET_PeerIdentity *pid, 9909 const struct GNUNET_PeerIdentity *pid,
9847 void *value) 9910 void *value)
9848{ 9911{
9849 struct AcknowledgementCummulator *ac = value; 9912 struct AcknowledgementCummulator *ac = value;
9850 9913
9851 (void)cls; 9914 (void) cls;
9852 (void)pid; 9915 (void) pid;
9853 GNUNET_free(ac); 9916 GNUNET_free (ac);
9854 return GNUNET_OK; 9917 return GNUNET_OK;
9855} 9918}
9856 9919
@@ -9862,68 +9925,68 @@ free_ack_cummulator_cb(void *cls,
9862 * @param cls closure, unused 9925 * @param cls closure, unused
9863 */ 9926 */
9864static void 9927static void
9865do_shutdown(void *cls) 9928do_shutdown (void *cls)
9866{ 9929{
9867 struct LearnLaunchEntry *lle; 9930 struct LearnLaunchEntry *lle;
9868 9931
9869 (void)cls; 9932 (void) cls;
9870 9933
9871 GNUNET_CONTAINER_multipeermap_iterate(neighbours, &free_neighbour_cb, NULL); 9934 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &free_neighbour_cb, NULL);
9872 if (NULL != peerstore) 9935 if (NULL != peerstore)
9873 { 9936 {
9874 GNUNET_PEERSTORE_disconnect(peerstore, GNUNET_NO); 9937 GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO);
9875 peerstore = NULL; 9938 peerstore = NULL;
9876 } 9939 }
9877 if (NULL != GST_stats) 9940 if (NULL != GST_stats)
9878 { 9941 {
9879 GNUNET_STATISTICS_destroy(GST_stats, GNUNET_NO); 9942 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
9880 GST_stats = NULL; 9943 GST_stats = NULL;
9881 } 9944 }
9882 if (NULL != GST_my_private_key) 9945 if (NULL != GST_my_private_key)
9883 { 9946 {
9884 GNUNET_free(GST_my_private_key); 9947 GNUNET_free (GST_my_private_key);
9885 GST_my_private_key = NULL; 9948 GST_my_private_key = NULL;
9886 } 9949 }
9887 GNUNET_CONTAINER_multipeermap_iterate(ack_cummulators, 9950 GNUNET_CONTAINER_multipeermap_iterate (ack_cummulators,
9888 &free_ack_cummulator_cb, 9951 &free_ack_cummulator_cb,
9889 NULL); 9952 NULL);
9890 GNUNET_CONTAINER_multipeermap_destroy(ack_cummulators); 9953 GNUNET_CONTAINER_multipeermap_destroy (ack_cummulators);
9891 ack_cummulators = NULL; 9954 ack_cummulators = NULL;
9892 GNUNET_CONTAINER_multiuuidmap_iterate(pending_acks, 9955 GNUNET_CONTAINER_multiuuidmap_iterate (pending_acks,
9893 &free_pending_ack_cb, 9956 &free_pending_ack_cb,
9894 NULL); 9957 NULL);
9895 GNUNET_CONTAINER_multiuuidmap_destroy(pending_acks); 9958 GNUNET_CONTAINER_multiuuidmap_destroy (pending_acks);
9896 pending_acks = NULL; 9959 pending_acks = NULL;
9897 GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(neighbours)); 9960 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (neighbours));
9898 GNUNET_CONTAINER_multipeermap_destroy(neighbours); 9961 GNUNET_CONTAINER_multipeermap_destroy (neighbours);
9899 neighbours = NULL; 9962 neighbours = NULL;
9900 GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(links)); 9963 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (links));
9901 GNUNET_CONTAINER_multipeermap_destroy(links); 9964 GNUNET_CONTAINER_multipeermap_destroy (links);
9902 links = NULL; 9965 links = NULL;
9903 GNUNET_CONTAINER_multipeermap_iterate(backtalkers, 9966 GNUNET_CONTAINER_multipeermap_iterate (backtalkers,
9904 &free_backtalker_cb, 9967 &free_backtalker_cb,
9905 NULL); 9968 NULL);
9906 GNUNET_CONTAINER_multipeermap_destroy(backtalkers); 9969 GNUNET_CONTAINER_multipeermap_destroy (backtalkers);
9907 backtalkers = NULL; 9970 backtalkers = NULL;
9908 GNUNET_CONTAINER_multipeermap_iterate(validation_map, 9971 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
9909 &free_validation_state_cb, 9972 &free_validation_state_cb,
9910 NULL); 9973 NULL);
9911 GNUNET_CONTAINER_multipeermap_destroy(validation_map); 9974 GNUNET_CONTAINER_multipeermap_destroy (validation_map);
9912 validation_map = NULL; 9975 validation_map = NULL;
9913 while (NULL != ir_head) 9976 while (NULL != ir_head)
9914 free_incoming_request(ir_head); 9977 free_incoming_request (ir_head);
9915 GNUNET_assert(0 == ir_total); 9978 GNUNET_assert (0 == ir_total);
9916 while (NULL != (lle = lle_head)) 9979 while (NULL != (lle = lle_head))
9917 { 9980 {
9918 GNUNET_CONTAINER_DLL_remove(lle_head, lle_tail, lle); 9981 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle);
9919 GNUNET_free(lle); 9982 GNUNET_free (lle);
9920 } 9983 }
9921 GNUNET_CONTAINER_multishortmap_destroy(dvlearn_map); 9984 GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map);
9922 dvlearn_map = NULL; 9985 dvlearn_map = NULL;
9923 GNUNET_CONTAINER_heap_destroy(validation_heap); 9986 GNUNET_CONTAINER_heap_destroy (validation_heap);
9924 validation_heap = NULL; 9987 validation_heap = NULL;
9925 GNUNET_CONTAINER_multipeermap_iterate(dv_routes, &free_dv_routes_cb, NULL); 9988 GNUNET_CONTAINER_multipeermap_iterate (dv_routes, &free_dv_routes_cb, NULL);
9926 GNUNET_CONTAINER_multipeermap_destroy(dv_routes); 9989 GNUNET_CONTAINER_multipeermap_destroy (dv_routes);
9927 dv_routes = NULL; 9990 dv_routes = NULL;
9928} 9991}
9929 9992
@@ -9936,58 +9999,58 @@ do_shutdown(void *cls)
9936 * @param service the initialized service 9999 * @param service the initialized service
9937 */ 10000 */
9938static void 10001static void
9939run(void *cls, 10002run (void *cls,
9940 const struct GNUNET_CONFIGURATION_Handle *c, 10003 const struct GNUNET_CONFIGURATION_Handle *c,
9941 struct GNUNET_SERVICE_Handle *service) 10004 struct GNUNET_SERVICE_Handle *service)
9942{ 10005{
9943 (void)cls; 10006 (void) cls;
9944 (void)service; 10007 (void) service;
9945 /* setup globals */ 10008 /* setup globals */
9946 hello_mono_time = GNUNET_TIME_absolute_get_monotonic(c); 10009 hello_mono_time = GNUNET_TIME_absolute_get_monotonic (c);
9947 GST_cfg = c; 10010 GST_cfg = c;
9948 backtalkers = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); 10011 backtalkers = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
9949 pending_acks = GNUNET_CONTAINER_multiuuidmap_create(32768, GNUNET_YES); 10012 pending_acks = GNUNET_CONTAINER_multiuuidmap_create (32768, GNUNET_YES);
9950 ack_cummulators = GNUNET_CONTAINER_multipeermap_create(256, GNUNET_YES); 10013 ack_cummulators = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_YES);
9951 neighbours = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); 10014 neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
9952 links = GNUNET_CONTAINER_multipeermap_create(512, GNUNET_YES); 10015 links = GNUNET_CONTAINER_multipeermap_create (512, GNUNET_YES);
9953 dv_routes = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); 10016 dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
9954 dvlearn_map = GNUNET_CONTAINER_multishortmap_create(2 * MAX_DV_LEARN_PENDING, 10017 dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING,
9955 GNUNET_YES); 10018 GNUNET_YES);
9956 validation_map = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); 10019 validation_map = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
9957 validation_heap = 10020 validation_heap =
9958 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 10021 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
9959 GST_my_private_key = 10022 GST_my_private_key =
9960 GNUNET_CRYPTO_eddsa_key_create_from_configuration(GST_cfg); 10023 GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg);
9961 if (NULL == GST_my_private_key) 10024 if (NULL == GST_my_private_key)
9962 { 10025 {
9963 GNUNET_log( 10026 GNUNET_log (
9964 GNUNET_ERROR_TYPE_ERROR, 10027 GNUNET_ERROR_TYPE_ERROR,
9965 _( 10028 _ (
9966 "Transport service is lacking key configuration settings. Exiting.\n")); 10029 "Transport service is lacking key configuration settings. Exiting.\n"));
9967 GNUNET_SCHEDULER_shutdown(); 10030 GNUNET_SCHEDULER_shutdown ();
9968 return; 10031 return;
9969 } 10032 }
9970 GNUNET_CRYPTO_eddsa_key_get_public(GST_my_private_key, 10033 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
9971 &GST_my_identity.public_key); 10034 &GST_my_identity.public_key);
9972 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 10035 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
9973 "My identity is `%s'\n", 10036 "My identity is `%s'\n",
9974 GNUNET_i2s_full(&GST_my_identity)); 10037 GNUNET_i2s_full (&GST_my_identity));
9975 GST_stats = GNUNET_STATISTICS_create("transport", GST_cfg); 10038 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
9976 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 10039 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
9977 peerstore = GNUNET_PEERSTORE_connect(GST_cfg); 10040 peerstore = GNUNET_PEERSTORE_connect (GST_cfg);
9978 if (NULL == peerstore) 10041 if (NULL == peerstore)
9979 { 10042 {
9980 GNUNET_break(0); 10043 GNUNET_break (0);
9981 GNUNET_SCHEDULER_shutdown(); 10044 GNUNET_SCHEDULER_shutdown ();
9982 return; 10045 return;
9983 } 10046 }
9984} 10047}
9985 10048
9986 10049
9987/** 10050/**
9988 * Define "main" method using service macro. 10051 * Define "main" method using service macro.
9989 */ 10052 */
9990GNUNET_SERVICE_MAIN( 10053GNUNET_SERVICE_MAIN (
9991 "transport", 10054 "transport",
9992 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, 10055 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
9993 &run, 10056 &run,
@@ -9995,78 +10058,78 @@ GNUNET_SERVICE_MAIN(
9995 &client_disconnect_cb, 10058 &client_disconnect_cb,
9996 NULL, 10059 NULL,
9997 /* communication with applications */ 10060 /* communication with applications */
9998 GNUNET_MQ_hd_fixed_size(suggest, 10061 GNUNET_MQ_hd_fixed_size (suggest,
9999 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, 10062 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST,
10000 struct ExpressPreferenceMessage, 10063 struct ExpressPreferenceMessage,
10001 NULL), 10064 NULL),
10002 GNUNET_MQ_hd_fixed_size(suggest_cancel, 10065 GNUNET_MQ_hd_fixed_size (suggest_cancel,
10003 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, 10066 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL,
10004 struct ExpressPreferenceMessage, 10067 struct ExpressPreferenceMessage,
10005 NULL), 10068 NULL),
10006 GNUNET_MQ_hd_var_size(request_hello_validation, 10069 GNUNET_MQ_hd_var_size (request_hello_validation,
10007 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, 10070 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION,
10008 struct RequestHelloValidationMessage, 10071 struct RequestHelloValidationMessage,
10009 NULL), 10072 NULL),
10010 /* communication with core */ 10073 /* communication with core */
10011 GNUNET_MQ_hd_fixed_size(client_start, 10074 GNUNET_MQ_hd_fixed_size (client_start,
10012 GNUNET_MESSAGE_TYPE_TRANSPORT_START, 10075 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
10013 struct StartMessage, 10076 struct StartMessage,
10014 NULL), 10077 NULL),
10015 GNUNET_MQ_hd_var_size(client_send, 10078 GNUNET_MQ_hd_var_size (client_send,
10016 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 10079 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
10017 struct OutboundMessage, 10080 struct OutboundMessage,
10018 NULL), 10081 NULL),
10019 GNUNET_MQ_hd_fixed_size(client_recv_ok, 10082 GNUNET_MQ_hd_fixed_size (client_recv_ok,
10020 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK, 10083 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK,
10021 struct RecvOkMessage, 10084 struct RecvOkMessage,
10022 NULL), 10085 NULL),
10023 /* communication with communicators */ 10086 /* communication with communicators */
10024 GNUNET_MQ_hd_var_size(communicator_available, 10087 GNUNET_MQ_hd_var_size (communicator_available,
10025 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, 10088 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR,
10026 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, 10089 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
10027 NULL), 10090 NULL),
10028 GNUNET_MQ_hd_var_size(communicator_backchannel, 10091 GNUNET_MQ_hd_var_size (communicator_backchannel,
10029 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, 10092 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
10030 struct GNUNET_TRANSPORT_CommunicatorBackchannel, 10093 struct GNUNET_TRANSPORT_CommunicatorBackchannel,
10031 NULL), 10094 NULL),
10032 GNUNET_MQ_hd_var_size(add_address, 10095 GNUNET_MQ_hd_var_size (add_address,
10033 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, 10096 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
10034 struct GNUNET_TRANSPORT_AddAddressMessage, 10097 struct GNUNET_TRANSPORT_AddAddressMessage,
10035 NULL), 10098 NULL),
10036 GNUNET_MQ_hd_fixed_size(del_address, 10099 GNUNET_MQ_hd_fixed_size (del_address,
10037 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, 10100 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
10038 struct GNUNET_TRANSPORT_DelAddressMessage, 10101 struct GNUNET_TRANSPORT_DelAddressMessage,
10039 NULL), 10102 NULL),
10040 GNUNET_MQ_hd_var_size(incoming_msg, 10103 GNUNET_MQ_hd_var_size (incoming_msg,
10041 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, 10104 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
10042 struct GNUNET_TRANSPORT_IncomingMessage, 10105 struct GNUNET_TRANSPORT_IncomingMessage,
10043 NULL), 10106 NULL),
10044 GNUNET_MQ_hd_fixed_size(queue_create_ok, 10107 GNUNET_MQ_hd_fixed_size (queue_create_ok,
10045 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, 10108 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
10046 struct GNUNET_TRANSPORT_CreateQueueResponse, 10109 struct GNUNET_TRANSPORT_CreateQueueResponse,
10047 NULL), 10110 NULL),
10048 GNUNET_MQ_hd_fixed_size(queue_create_fail, 10111 GNUNET_MQ_hd_fixed_size (queue_create_fail,
10049 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, 10112 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
10050 struct GNUNET_TRANSPORT_CreateQueueResponse, 10113 struct GNUNET_TRANSPORT_CreateQueueResponse,
10051 NULL), 10114 NULL),
10052 GNUNET_MQ_hd_var_size(add_queue_message, 10115 GNUNET_MQ_hd_var_size (add_queue_message,
10053 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, 10116 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
10054 struct GNUNET_TRANSPORT_AddQueueMessage, 10117 struct GNUNET_TRANSPORT_AddQueueMessage,
10055 NULL), 10118 NULL),
10056 GNUNET_MQ_hd_fixed_size(del_queue_message, 10119 GNUNET_MQ_hd_fixed_size (del_queue_message,
10057 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, 10120 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
10058 struct GNUNET_TRANSPORT_DelQueueMessage, 10121 struct GNUNET_TRANSPORT_DelQueueMessage,
10059 NULL), 10122 NULL),
10060 GNUNET_MQ_hd_fixed_size(send_message_ack, 10123 GNUNET_MQ_hd_fixed_size (send_message_ack,
10061 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, 10124 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK,
10062 struct GNUNET_TRANSPORT_SendMessageToAck, 10125 struct GNUNET_TRANSPORT_SendMessageToAck,
10063 NULL), 10126 NULL),
10064 /* communication with monitors */ 10127 /* communication with monitors */
10065 GNUNET_MQ_hd_fixed_size(monitor_start, 10128 GNUNET_MQ_hd_fixed_size (monitor_start,
10066 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, 10129 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START,
10067 struct GNUNET_TRANSPORT_MonitorStart, 10130 struct GNUNET_TRANSPORT_MonitorStart,
10068 NULL), 10131 NULL),
10069 GNUNET_MQ_handler_end()); 10132 GNUNET_MQ_handler_end ());
10070 10133
10071 10134
10072/* end of file gnunet-service-transport.c */ 10135/* 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 @@
61/** 61/**
62 * Information we need for an asynchronous session kill. 62 * Information we need for an asynchronous session kill.
63 */ 63 */
64struct GNUNET_ATS_SessionKiller { 64struct GNUNET_ATS_SessionKiller
65{
65 /** 66 /**
66 * Kept in a DLL. 67 * Kept in a DLL.
67 */ 68 */
@@ -92,7 +93,8 @@ struct GNUNET_ATS_SessionKiller {
92/** 93/**
93 * What type of client is the `struct TransportClient` about? 94 * What type of client is the `struct TransportClient` about?
94 */ 95 */
95enum ClientType { 96enum ClientType
97{
96 /** 98 /**
97 * We do not know yet (client is fresh). 99 * We do not know yet (client is fresh).
98 */ 100 */
@@ -128,7 +130,8 @@ struct GST_BlacklistCheck;
128/** 130/**
129 * Client connected to the transport service. 131 * Client connected to the transport service.
130 */ 132 */
131struct TransportClient { 133struct TransportClient
134{
132 /** 135 /**
133 * This is a doubly-linked list. 136 * This is a doubly-linked list.
134 */ 137 */
@@ -154,7 +157,8 @@ struct TransportClient {
154 */ 157 */
155 enum ClientType type; 158 enum ClientType type;
156 159
157 union { 160 union
161 {
158 /** 162 /**
159 * Peer identity to monitor the addresses of. 163 * Peer identity to monitor the addresses of.
160 * Zero to monitor all neighbours. Valid if 164 * Zero to monitor all neighbours. Valid if
@@ -165,7 +169,8 @@ struct TransportClient {
165 /** 169 /**
166 * Additional details if @e type is CT_BLACKLIST. 170 * Additional details if @e type is CT_BLACKLIST.
167 */ 171 */
168 struct { 172 struct
173 {
169 /** 174 /**
170 * Blacklist check that we're currently performing (or NULL 175 * Blacklist check that we're currently performing (or NULL
171 * if we're performing one that has been cancelled). 176 * if we're performing one that has been cancelled).
@@ -189,7 +194,8 @@ struct TransportClient {
189/** 194/**
190 * Context we use when performing a blacklist check. 195 * Context we use when performing a blacklist check.
191 */ 196 */
192struct GST_BlacklistCheck { 197struct GST_BlacklistCheck
198{
193 /** 199 /**
194 * This is a linked list. 200 * This is a linked list.
195 */ 201 */
@@ -240,7 +246,8 @@ struct GST_BlacklistCheck {
240/** 246/**
241 * Context for address to string operations 247 * Context for address to string operations
242 */ 248 */
243struct AddressToStringContext { 249struct AddressToStringContext
250{
244 /** 251 /**
245 * This is a doubly-linked list. 252 * This is a doubly-linked list.
246 */ 253 */
@@ -261,7 +268,8 @@ struct AddressToStringContext {
261/** 268/**
262 * Closure for #handle_send_transmit_continuation() 269 * Closure for #handle_send_transmit_continuation()
263 */ 270 */
264struct SendTransmitContinuationContext { 271struct SendTransmitContinuationContext
272{
265 /** 273 /**
266 * Client that made the request. 274 * Client that made the request.
267 */ 275 */
@@ -416,31 +424,31 @@ struct GNUNET_NT_InterfaceScanner *GST_is;
416 * @param may_drop #GNUNET_YES if the message can be dropped 424 * @param may_drop #GNUNET_YES if the message can be dropped
417 */ 425 */
418static void 426static void
419unicast(struct TransportClient *tc, 427unicast (struct TransportClient *tc,
420 const struct GNUNET_MessageHeader *msg, 428 const struct GNUNET_MessageHeader *msg,
421 int may_drop) 429 int may_drop)
422{ 430{
423 struct GNUNET_MQ_Envelope *env; 431 struct GNUNET_MQ_Envelope *env;
424 432
425 if ((GNUNET_MQ_get_length(tc->mq) >= MAX_PENDING) && 433 if ((GNUNET_MQ_get_length (tc->mq) >= MAX_PENDING) &&
426 (GNUNET_YES == may_drop)) 434 (GNUNET_YES == may_drop))
427 { 435 {
428 GNUNET_log( 436 GNUNET_log (
429 GNUNET_ERROR_TYPE_DEBUG, 437 GNUNET_ERROR_TYPE_DEBUG,
430 "Dropping message of type %u and size %u, have %u/%u messages pending\n", 438 "Dropping message of type %u and size %u, have %u/%u messages pending\n",
431 ntohs(msg->type), 439 ntohs (msg->type),
432 ntohs(msg->size), 440 ntohs (msg->size),
433 GNUNET_MQ_get_length(tc->mq), 441 GNUNET_MQ_get_length (tc->mq),
434 MAX_PENDING); 442 MAX_PENDING);
435 GNUNET_STATISTICS_update(GST_stats, 443 GNUNET_STATISTICS_update (GST_stats,
436 gettext_noop( 444 gettext_noop (
437 "# messages dropped due to slow client"), 445 "# messages dropped due to slow client"),
438 1, 446 1,
439 GNUNET_NO); 447 GNUNET_NO);
440 return; 448 return;
441 } 449 }
442 env = GNUNET_MQ_msg_copy(msg); 450 env = GNUNET_MQ_msg_copy (msg);
443 GNUNET_MQ_send(tc->mq, env); 451 GNUNET_MQ_send (tc->mq, env);
444} 452}
445 453
446 454
@@ -454,17 +462,17 @@ unicast(struct TransportClient *tc,
454 * @return our `struct TransportClient` 462 * @return our `struct TransportClient`
455 */ 463 */
456static void * 464static void *
457client_connect_cb(void *cls, 465client_connect_cb (void *cls,
458 struct GNUNET_SERVICE_Client *client, 466 struct GNUNET_SERVICE_Client *client,
459 struct GNUNET_MQ_Handle *mq) 467 struct GNUNET_MQ_Handle *mq)
460{ 468{
461 struct TransportClient *tc; 469 struct TransportClient *tc;
462 470
463 tc = GNUNET_new(struct TransportClient); 471 tc = GNUNET_new (struct TransportClient);
464 tc->client = client; 472 tc->client = client;
465 tc->mq = mq; 473 tc->mq = mq;
466 GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc); 474 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
467 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); 475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
468 return tc; 476 return tc;
469} 477}
470 478
@@ -475,7 +483,7 @@ client_connect_cb(void *cls,
475 * @param cls the `struct BlacklistCheck*` 483 * @param cls the `struct BlacklistCheck*`
476 */ 484 */
477static void 485static void
478do_blacklist_check(void *cls); 486do_blacklist_check (void *cls);
479 487
480 488
481/** 489/**
@@ -488,16 +496,16 @@ do_blacklist_check(void *cls);
488 * @return #GNUNET_OK (continue to iterate) 496 * @return #GNUNET_OK (continue to iterate)
489 */ 497 */
490static int 498static int
491mark_match_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value) 499mark_match_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
492{ 500{
493 struct TransportClient *tc = cls; 501 struct TransportClient *tc = cls;
494 struct SendTransmitContinuationContext *stcc = value; 502 struct SendTransmitContinuationContext *stcc = value;
495 503
496 if (tc == stcc->tc) 504 if (tc == stcc->tc)
497 { 505 {
498 stcc->down = GNUNET_YES; 506 stcc->down = GNUNET_YES;
499 stcc->tc = NULL; 507 stcc->tc = NULL;
500 } 508 }
501 return GNUNET_OK; 509 return GNUNET_OK;
502} 510}
503 511
@@ -511,50 +519,50 @@ mark_match_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
511 * @param app_ctx our `struct TransportClient` 519 * @param app_ctx our `struct TransportClient`
512 */ 520 */
513static void 521static void
514client_disconnect_cb(void *cls, 522client_disconnect_cb (void *cls,
515 struct GNUNET_SERVICE_Client *client, 523 struct GNUNET_SERVICE_Client *client,
516 void *app_ctx) 524 void *app_ctx)
517{ 525{
518 struct TransportClient *tc = app_ctx; 526 struct TransportClient *tc = app_ctx;
519 struct GST_BlacklistCheck *bc; 527 struct GST_BlacklistCheck *bc;
520 528
521 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "Client %p disconnected, cleaning up.\n", 530 "Client %p disconnected, cleaning up.\n",
523 tc); 531 tc);
524 GNUNET_CONTAINER_multipeermap_iterate(active_stccs, &mark_match_down, tc); 532 GNUNET_CONTAINER_multipeermap_iterate (active_stccs, &mark_match_down, tc);
525 for (struct AddressToStringContext *cur = a2s_head; NULL != cur; 533 for (struct AddressToStringContext *cur = a2s_head; NULL != cur;
526 cur = cur->next) 534 cur = cur->next)
527 { 535 {
528 if (cur->tc == tc) 536 if (cur->tc == tc)
529 cur->tc = NULL; 537 cur->tc = NULL;
530 } 538 }
531 GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc); 539 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
532 switch (tc->type) 540 switch (tc->type)
533 { 541 {
534 case CT_NONE: 542 case CT_NONE:
535 break; 543 break;
536
537 case CT_CORE:
538 break;
539 544
540 case CT_MONITOR: 545 case CT_CORE:
541 break; 546 break;
542 547
543 case CT_BLACKLIST: 548 case CT_MONITOR:
544 for (bc = bc_head; NULL != bc; bc = bc->next) 549 break;
545 {
546 if (bc->bl_pos != tc)
547 continue;
548 bc->bl_pos = tc->next;
549 if (NULL == bc->task)
550 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc);
551 }
552 break;
553 550
554 case CT_CORE_NO_HANDLERS: 551 case CT_BLACKLIST:
555 break; 552 for (bc = bc_head; NULL != bc; bc = bc->next)
553 {
554 if (bc->bl_pos != tc)
555 continue;
556 bc->bl_pos = tc->next;
557 if (NULL == bc->task)
558 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
556 } 559 }
557 GNUNET_free(tc); 560 break;
561
562 case CT_CORE_NO_HANDLERS:
563 break;
564 }
565 GNUNET_free (tc);
558} 566}
559 567
560 568
@@ -571,24 +579,24 @@ client_disconnect_cb(void *cls,
571 * @param bandwidth_out outbound bandwidth in NBO 579 * @param bandwidth_out outbound bandwidth in NBO
572 */ 580 */
573static void 581static void
574notify_client_about_neighbour(void *cls, 582notify_client_about_neighbour (void *cls,
575 const struct GNUNET_PeerIdentity *peer, 583 const struct GNUNET_PeerIdentity *peer,
576 const struct GNUNET_HELLO_Address *address, 584 const struct GNUNET_HELLO_Address *address,
577 enum GNUNET_TRANSPORT_PeerState state, 585 enum GNUNET_TRANSPORT_PeerState state,
578 struct GNUNET_TIME_Absolute state_timeout, 586 struct GNUNET_TIME_Absolute state_timeout,
579 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 587 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
580 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 588 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
581{ 589{
582 struct TransportClient *tc = cls; 590 struct TransportClient *tc = cls;
583 struct ConnectInfoMessage cim; 591 struct ConnectInfoMessage cim;
584 592
585 if (GNUNET_NO == GST_neighbours_test_connected(peer)) 593 if (GNUNET_NO == GST_neighbours_test_connected (peer))
586 return; 594 return;
587 cim.header.size = htons(sizeof(struct ConnectInfoMessage)); 595 cim.header.size = htons (sizeof(struct ConnectInfoMessage));
588 cim.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 596 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
589 cim.id = *peer; 597 cim.id = *peer;
590 cim.quota_out = bandwidth_out; 598 cim.quota_out = bandwidth_out;
591 unicast(tc, &cim.header, GNUNET_NO); 599 unicast (tc, &cim.header, GNUNET_NO);
592} 600}
593 601
594 602
@@ -601,39 +609,39 @@ notify_client_about_neighbour(void *cls,
601 * @param start the start message that was sent 609 * @param start the start message that was sent
602 */ 610 */
603static void 611static void
604handle_client_start(void *cls, const struct StartMessage *start) 612handle_client_start (void *cls, const struct StartMessage *start)
605{ 613{
606 struct TransportClient *tc = cls; 614 struct TransportClient *tc = cls;
607 const struct GNUNET_MessageHeader *hello; 615 const struct GNUNET_MessageHeader *hello;
608 uint32_t options; 616 uint32_t options;
609 617
610 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc); 618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc);
611 options = ntohl(start->options); 619 options = ntohl (start->options);
612 if ((0 != (1 & options)) && 620 if ((0 != (1 & options)) &&
613 (0 != memcmp(&start->self, 621 (0 != memcmp (&start->self,
614 &GST_my_identity, 622 &GST_my_identity,
615 sizeof(struct GNUNET_PeerIdentity)))) 623 sizeof(struct GNUNET_PeerIdentity))))
616 { 624 {
617 /* client thinks this is a different peer, reject */ 625 /* client thinks this is a different peer, reject */
618 GNUNET_break(0); 626 GNUNET_break (0);
619 GNUNET_SERVICE_client_drop(tc->client); 627 GNUNET_SERVICE_client_drop (tc->client);
620 return; 628 return;
621 } 629 }
622 if (CT_NONE != tc->type) 630 if (CT_NONE != tc->type)
623 { 631 {
624 GNUNET_break(0); 632 GNUNET_break (0);
625 GNUNET_SERVICE_client_drop(tc->client); 633 GNUNET_SERVICE_client_drop (tc->client);
626 return; 634 return;
627 } 635 }
628 if (0 != (2 & options)) 636 if (0 != (2 & options))
629 tc->type = CT_CORE; 637 tc->type = CT_CORE;
630 else 638 else
631 tc->type = CT_CORE_NO_HANDLERS; 639 tc->type = CT_CORE_NO_HANDLERS;
632 hello = GST_hello_get(); 640 hello = GST_hello_get ();
633 if (NULL != hello) 641 if (NULL != hello)
634 unicast(tc, hello, GNUNET_NO); 642 unicast (tc, hello, GNUNET_NO);
635 GST_neighbours_iterate(&notify_client_about_neighbour, tc); 643 GST_neighbours_iterate (&notify_client_about_neighbour, tc);
636 GNUNET_SERVICE_client_continue(tc->client); 644 GNUNET_SERVICE_client_continue (tc->client);
637} 645}
638 646
639 647
@@ -644,7 +652,7 @@ handle_client_start(void *cls, const struct StartMessage *start)
644 * @param message the HELLO message 652 * @param message the HELLO message
645 */ 653 */
646static int 654static int
647check_client_hello(void *cls, const struct GNUNET_MessageHeader *message) 655check_client_hello (void *cls, const struct GNUNET_MessageHeader *message)
648{ 656{
649 return GNUNET_OK; /* FIXME: check here? */ 657 return GNUNET_OK; /* FIXME: check here? */
650} 658}
@@ -657,13 +665,13 @@ check_client_hello(void *cls, const struct GNUNET_MessageHeader *message)
657 * @param message the HELLO message 665 * @param message the HELLO message
658 */ 666 */
659static void 667static void
660handle_client_hello(void *cls, const struct GNUNET_MessageHeader *message) 668handle_client_hello (void *cls, const struct GNUNET_MessageHeader *message)
661{ 669{
662 struct TransportClient *tc = cls; 670 struct TransportClient *tc = cls;
663 671
664 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n"); 672 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n");
665 GST_validation_handle_hello(message); 673 GST_validation_handle_hello (message);
666 GNUNET_SERVICE_client_continue(tc->client); 674 GNUNET_SERVICE_client_continue (tc->client);
667} 675}
668 676
669 677
@@ -677,55 +685,55 @@ handle_client_hello(void *cls, const struct GNUNET_MessageHeader *message)
677 * @param bytes_on_wire bytes sent on wire 685 * @param bytes_on_wire bytes sent on wire
678 */ 686 */
679static void 687static void
680handle_send_transmit_continuation(void *cls, 688handle_send_transmit_continuation (void *cls,
681 int success, 689 int success,
682 size_t bytes_payload, 690 size_t bytes_payload,
683 size_t bytes_on_wire) 691 size_t bytes_on_wire)
684{ 692{
685 struct SendTransmitContinuationContext *stcc = cls; 693 struct SendTransmitContinuationContext *stcc = cls;
686 struct SendOkMessage send_ok_msg; 694 struct SendOkMessage send_ok_msg;
687 struct GNUNET_TIME_Relative delay; 695 struct GNUNET_TIME_Relative delay;
688 const struct GNUNET_HELLO_Address *addr; 696 const struct GNUNET_HELLO_Address *addr;
689 697
690 delay = GNUNET_TIME_absolute_get_duration(stcc->send_time); 698 delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
691 addr = GST_neighbour_get_current_address(&stcc->target); 699 addr = GST_neighbour_get_current_address (&stcc->target);
692 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 700 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
693 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 701 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
694 "It took us %s to send %u/%u bytes to %s (%d, %s)\n", 702 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
695 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), 703 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
696 (unsigned int)bytes_payload, 704 (unsigned int) bytes_payload,
697 (unsigned int)bytes_on_wire, 705 (unsigned int) bytes_on_wire,
698 GNUNET_i2s(&stcc->target), 706 GNUNET_i2s (&stcc->target),
699 success, 707 success,
700 (NULL != addr) ? addr->transport_name : "%"); 708 (NULL != addr) ? addr->transport_name : "%");
701 else 709 else
702 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
703 "It took us %s to send %u/%u bytes to %s (%d, %s)\n", 711 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
704 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), 712 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
705 (unsigned int)bytes_payload, 713 (unsigned int) bytes_payload,
706 (unsigned int)bytes_on_wire, 714 (unsigned int) bytes_on_wire,
707 GNUNET_i2s(&stcc->target), 715 GNUNET_i2s (&stcc->target),
708 success, 716 success,
709 (NULL != addr) ? addr->transport_name : "%"); 717 (NULL != addr) ? addr->transport_name : "%");
710 718
711 if (GNUNET_NO == stcc->down) 719 if (GNUNET_NO == stcc->down)
712 { 720 {
713 /* Only send confirmation if we are still connected */ 721 /* Only send confirmation if we are still connected */
714 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
715 "Sending SEND_OK for transmission request %llu\n", 723 "Sending SEND_OK for transmission request %llu\n",
716 stcc->uuid); 724 stcc->uuid);
717 send_ok_msg.header.size = htons(sizeof(send_ok_msg)); 725 send_ok_msg.header.size = htons (sizeof(send_ok_msg));
718 send_ok_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); 726 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
719 send_ok_msg.bytes_msg = htonl(bytes_payload); 727 send_ok_msg.bytes_msg = htonl (bytes_payload);
720 send_ok_msg.bytes_physical = htonl(bytes_on_wire); 728 send_ok_msg.bytes_physical = htonl (bytes_on_wire);
721 send_ok_msg.success = htonl(success); 729 send_ok_msg.success = htonl (success);
722 send_ok_msg.peer = stcc->target; 730 send_ok_msg.peer = stcc->target;
723 unicast(stcc->tc, &send_ok_msg.header, GNUNET_NO); 731 unicast (stcc->tc, &send_ok_msg.header, GNUNET_NO);
724 } 732 }
725 GNUNET_assert( 733 GNUNET_assert (
726 GNUNET_OK == 734 GNUNET_OK ==
727 GNUNET_CONTAINER_multipeermap_remove(active_stccs, &stcc->target, stcc)); 735 GNUNET_CONTAINER_multipeermap_remove (active_stccs, &stcc->target, stcc));
728 GNUNET_free(stcc); 736 GNUNET_free (stcc);
729} 737}
730 738
731 739
@@ -736,23 +744,23 @@ handle_send_transmit_continuation(void *cls,
736 * @param obm the send message that was sent 744 * @param obm the send message that was sent
737 */ 745 */
738static int 746static int
739check_client_send(void *cls, const struct OutboundMessage *obm) 747check_client_send (void *cls, const struct OutboundMessage *obm)
740{ 748{
741 uint16_t size; 749 uint16_t size;
742 const struct GNUNET_MessageHeader *obmm; 750 const struct GNUNET_MessageHeader *obmm;
743 751
744 size = ntohs(obm->header.size) - sizeof(struct OutboundMessage); 752 size = ntohs (obm->header.size) - sizeof(struct OutboundMessage);
745 if (size < sizeof(struct GNUNET_MessageHeader)) 753 if (size < sizeof(struct GNUNET_MessageHeader))
746 { 754 {
747 GNUNET_break(0); 755 GNUNET_break (0);
748 return GNUNET_SYSERR; 756 return GNUNET_SYSERR;
749 } 757 }
750 obmm = (const struct GNUNET_MessageHeader *)&obm[1]; 758 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
751 if (size != ntohs(obmm->size)) 759 if (size != ntohs (obmm->size))
752 { 760 {
753 GNUNET_break(0); 761 GNUNET_break (0);
754 return GNUNET_SYSERR; 762 return GNUNET_SYSERR;
755 } 763 }
756 return GNUNET_OK; 764 return GNUNET_OK;
757} 765}
758 766
@@ -764,53 +772,53 @@ check_client_send(void *cls, const struct OutboundMessage *obm)
764 * @param obm the send message that was sent 772 * @param obm the send message that was sent
765 */ 773 */
766static void 774static void
767handle_client_send(void *cls, const struct OutboundMessage *obm) 775handle_client_send (void *cls, const struct OutboundMessage *obm)
768{ 776{
769 static unsigned long long uuid_gen; 777 static unsigned long long uuid_gen;
770 struct TransportClient *tc = cls; 778 struct TransportClient *tc = cls;
771 const struct GNUNET_MessageHeader *obmm; 779 const struct GNUNET_MessageHeader *obmm;
772 struct SendTransmitContinuationContext *stcc; 780 struct SendTransmitContinuationContext *stcc;
773 781
774 obmm = (const struct GNUNET_MessageHeader *)&obm[1]; 782 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
775 if (GNUNET_NO == GST_neighbours_test_connected(&obm->peer)) 783 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
776 { 784 {
777 /* not connected, not allowed to send; can happen due to asynchronous operations */ 785 /* not connected, not allowed to send; can happen due to asynchronous operations */
778 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
779 "Could not send message to peer `%s': not connected\n", 787 "Could not send message to peer `%s': not connected\n",
780 GNUNET_i2s(&obm->peer)); 788 GNUNET_i2s (&obm->peer));
781 GNUNET_STATISTICS_update( 789 GNUNET_STATISTICS_update (
782 GST_stats, 790 GST_stats,
783 gettext_noop("# bytes payload dropped (other peer was not connected)"), 791 gettext_noop ("# bytes payload dropped (other peer was not connected)"),
784 ntohs(obmm->size), 792 ntohs (obmm->size),
785 GNUNET_NO); 793 GNUNET_NO);
786 GNUNET_SERVICE_client_continue(tc->client); 794 GNUNET_SERVICE_client_continue (tc->client);
787 return; 795 return;
788 } 796 }
789 GNUNET_log( 797 GNUNET_log (
790 GNUNET_ERROR_TYPE_DEBUG, 798 GNUNET_ERROR_TYPE_DEBUG,
791 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n", 799 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
792 uuid_gen, 800 uuid_gen,
793 GNUNET_i2s(&obm->peer), 801 GNUNET_i2s (&obm->peer),
794 ntohs(obmm->type), 802 ntohs (obmm->type),
795 ntohs(obmm->size)); 803 ntohs (obmm->size));
796 GNUNET_SERVICE_client_continue(tc->client); 804 GNUNET_SERVICE_client_continue (tc->client);
797 805
798 stcc = GNUNET_new(struct SendTransmitContinuationContext); 806 stcc = GNUNET_new (struct SendTransmitContinuationContext);
799 stcc->target = obm->peer; 807 stcc->target = obm->peer;
800 stcc->tc = tc; 808 stcc->tc = tc;
801 stcc->send_time = GNUNET_TIME_absolute_get(); 809 stcc->send_time = GNUNET_TIME_absolute_get ();
802 stcc->uuid = uuid_gen++; 810 stcc->uuid = uuid_gen++;
803 (void)GNUNET_CONTAINER_multipeermap_put( 811 (void) GNUNET_CONTAINER_multipeermap_put (
804 active_stccs, 812 active_stccs,
805 &stcc->target, 813 &stcc->target,
806 stcc, 814 stcc,
807 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 815 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
808 GST_manipulation_send(&obm->peer, 816 GST_manipulation_send (&obm->peer,
809 obmm, 817 obmm,
810 ntohs(obmm->size), 818 ntohs (obmm->size),
811 GNUNET_TIME_relative_ntoh(obm->timeout), 819 GNUNET_TIME_relative_ntoh (obm->timeout),
812 &handle_send_transmit_continuation, 820 &handle_send_transmit_continuation,
813 stcc); 821 stcc);
814} 822}
815 823
816 824
@@ -829,50 +837,50 @@ handle_client_send(void *cls, const struct OutboundMessage *obm)
829 * never #GNUNET_NO 837 * never #GNUNET_NO
830 */ 838 */
831static void 839static void
832transmit_address_to_client(void *cls, const char *buf, int res) 840transmit_address_to_client (void *cls, const char *buf, int res)
833{ 841{
834 struct AddressToStringContext *actx = cls; 842 struct AddressToStringContext *actx = cls;
835 struct GNUNET_MQ_Envelope *env; 843 struct GNUNET_MQ_Envelope *env;
836 struct AddressToStringResultMessage *atsm; 844 struct AddressToStringResultMessage *atsm;
837 size_t slen; 845 size_t slen;
838 846
839 GNUNET_assert((GNUNET_OK == res) || (GNUNET_SYSERR == res)); 847 GNUNET_assert ((GNUNET_OK == res) || (GNUNET_SYSERR == res));
840 if (NULL == actx->tc) 848 if (NULL == actx->tc)
841 return; 849 return;
842 if (NULL == buf) 850 if (NULL == buf)
851 {
852 env = GNUNET_MQ_msg (atsm,
853 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
854 if (GNUNET_OK == res)
855 {
856 /* this was the last call, transmit */
857 atsm->res = htonl (GNUNET_OK);
858 atsm->addr_len = htonl (0);
859 GNUNET_MQ_send (actx->tc->mq, env);
860 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
861 GNUNET_free (actx);
862 return;
863 }
864 if (GNUNET_SYSERR == res)
843 { 865 {
844 env = GNUNET_MQ_msg(atsm, 866 /* address conversion failed, but there will be more callbacks */
845 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 867 atsm->res = htonl (GNUNET_SYSERR);
846 if (GNUNET_OK == res) 868 atsm->addr_len = htonl (0);
847 { 869 GNUNET_MQ_send (actx->tc->mq, env);
848 /* this was the last call, transmit */ 870 return;
849 atsm->res = htonl(GNUNET_OK);
850 atsm->addr_len = htonl(0);
851 GNUNET_MQ_send(actx->tc->mq, env);
852 GNUNET_CONTAINER_DLL_remove(a2s_head, a2s_tail, actx);
853 GNUNET_free(actx);
854 return;
855 }
856 if (GNUNET_SYSERR == res)
857 {
858 /* address conversion failed, but there will be more callbacks */
859 atsm->res = htonl(GNUNET_SYSERR);
860 atsm->addr_len = htonl(0);
861 GNUNET_MQ_send(actx->tc->mq, env);
862 return;
863 }
864 } 871 }
865 GNUNET_assert(GNUNET_OK == res); 872 }
873 GNUNET_assert (GNUNET_OK == res);
866 /* succesful conversion, append*/ 874 /* succesful conversion, append*/
867 slen = strlen(buf) + 1; 875 slen = strlen (buf) + 1;
868 env = 876 env =
869 GNUNET_MQ_msg_extra(atsm, 877 GNUNET_MQ_msg_extra (atsm,
870 slen, 878 slen,
871 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 879 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
872 atsm->res = htonl(GNUNET_YES); 880 atsm->res = htonl (GNUNET_YES);
873 atsm->addr_len = htonl(slen); 881 atsm->addr_len = htonl (slen);
874 GNUNET_memcpy(&atsm[1], buf, slen); 882 GNUNET_memcpy (&atsm[1], buf, slen);
875 GNUNET_MQ_send(actx->tc->mq, env); 883 GNUNET_MQ_send (actx->tc->mq, env);
876} 884}
877 885
878 886
@@ -884,29 +892,29 @@ transmit_address_to_client(void *cls, const char *buf, int res)
884 * @return #GNUNET_OK if @a alum is well-formed 892 * @return #GNUNET_OK if @a alum is well-formed
885 */ 893 */
886static int 894static int
887check_client_address_to_string(void *cls, 895check_client_address_to_string (void *cls,
888 const struct AddressLookupMessage *alum) 896 const struct AddressLookupMessage *alum)
889{ 897{
890 const char *plugin_name; 898 const char *plugin_name;
891 const char *address; 899 const char *address;
892 uint32_t address_len; 900 uint32_t address_len;
893 uint16_t size; 901 uint16_t size;
894 902
895 size = ntohs(alum->header.size); 903 size = ntohs (alum->header.size);
896 address_len = ntohs(alum->addrlen); 904 address_len = ntohs (alum->addrlen);
897 if (size <= sizeof(struct AddressLookupMessage) + address_len) 905 if (size <= sizeof(struct AddressLookupMessage) + address_len)
898 { 906 {
899 GNUNET_break(0); 907 GNUNET_break (0);
900 return GNUNET_SYSERR; 908 return GNUNET_SYSERR;
901 } 909 }
902 address = (const char *)&alum[1]; 910 address = (const char *) &alum[1];
903 plugin_name = (const char *)&address[address_len]; 911 plugin_name = (const char *) &address[address_len];
904 if ('\0' != plugin_name[size - sizeof(struct AddressLookupMessage) - 912 if ('\0' != plugin_name[size - sizeof(struct AddressLookupMessage)
905 address_len - 1]) 913 - address_len - 1])
906 { 914 {
907 GNUNET_break(0); 915 GNUNET_break (0);
908 return GNUNET_SYSERR; 916 return GNUNET_SYSERR;
909 } 917 }
910 return GNUNET_OK; 918 return GNUNET_OK;
911} 919}
912 920
@@ -918,8 +926,8 @@ check_client_address_to_string(void *cls,
918 * @param alum the resolution request 926 * @param alum the resolution request
919 */ 927 */
920static void 928static void
921handle_client_address_to_string(void *cls, 929handle_client_address_to_string (void *cls,
922 const struct AddressLookupMessage *alum) 930 const struct AddressLookupMessage *alum)
923{ 931{
924 struct TransportClient *tc = cls; 932 struct TransportClient *tc = cls;
925 struct GNUNET_TRANSPORT_PluginFunctions *papi; 933 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -932,45 +940,45 @@ handle_client_address_to_string(void *cls,
932 struct GNUNET_TIME_Relative rtimeout; 940 struct GNUNET_TIME_Relative rtimeout;
933 int32_t numeric; 941 int32_t numeric;
934 942
935 address_len = ntohs(alum->addrlen); 943 address_len = ntohs (alum->addrlen);
936 address = (const char *)&alum[1]; 944 address = (const char *) &alum[1];
937 plugin_name = (const char *)&address[address_len]; 945 plugin_name = (const char *) &address[address_len];
938 rtimeout = GNUNET_TIME_relative_ntoh(alum->timeout); 946 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
939 numeric = ntohs(alum->numeric_only); 947 numeric = ntohs (alum->numeric_only);
940 papi = GST_plugins_printer_find(plugin_name); 948 papi = GST_plugins_printer_find (plugin_name);
941 if (NULL == papi) 949 if (NULL == papi)
942 { 950 {
943 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 951 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
944 "Failed to find plugin `%s'\n", 952 "Failed to find plugin `%s'\n",
945 plugin_name); 953 plugin_name);
946 env = GNUNET_MQ_msg(atsm, 954 env = GNUNET_MQ_msg (atsm,
947 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 955 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
948 atsm->res = htonl(GNUNET_SYSERR); 956 atsm->res = htonl (GNUNET_SYSERR);
949 atsm->addr_len = htonl(0); 957 atsm->addr_len = htonl (0);
950 GNUNET_MQ_send(tc->mq, env); 958 GNUNET_MQ_send (tc->mq, env);
951 env = GNUNET_MQ_msg(atsm, 959 env = GNUNET_MQ_msg (atsm,
952 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 960 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
953 atsm->res = htonl(GNUNET_OK); 961 atsm->res = htonl (GNUNET_OK);
954 atsm->addr_len = htonl(0); 962 atsm->addr_len = htonl (0);
955 GNUNET_MQ_send(tc->mq, env); 963 GNUNET_MQ_send (tc->mq, env);
956 return; 964 return;
957 } 965 }
958 actx = GNUNET_new(struct AddressToStringContext); 966 actx = GNUNET_new (struct AddressToStringContext);
959 actx->tc = tc; 967 actx->tc = tc;
960 GNUNET_CONTAINER_DLL_insert(a2s_head, a2s_tail, actx); 968 GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx);
961 GNUNET_SERVICE_client_disable_continue_warning(tc->client); 969 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
962 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
963 "Pretty-printing address of %u bytes using plugin `%s'\n", 971 "Pretty-printing address of %u bytes using plugin `%s'\n",
964 address_len, 972 address_len,
965 plugin_name); 973 plugin_name);
966 papi->address_pretty_printer(papi->cls, 974 papi->address_pretty_printer (papi->cls,
967 plugin_name, 975 plugin_name,
968 address, 976 address,
969 address_len, 977 address_len,
970 numeric, 978 numeric,
971 rtimeout, 979 rtimeout,
972 &transmit_address_to_client, 980 &transmit_address_to_client,
973 actx); 981 actx);
974} 982}
975 983
976 984
@@ -982,7 +990,7 @@ handle_client_address_to_string(void *cls,
982 * @return composed message 990 * @return composed message
983 */ 991 */
984static struct PeerIterateResponseMessage * 992static struct PeerIterateResponseMessage *
985compose_address_iterate_response_message( 993compose_address_iterate_response_message (
986 const struct GNUNET_PeerIdentity *peer, 994 const struct GNUNET_PeerIdentity *peer,
987 const struct GNUNET_HELLO_Address *address) 995 const struct GNUNET_HELLO_Address *address)
988{ 996{
@@ -992,34 +1000,34 @@ compose_address_iterate_response_message(
992 size_t alen; 1000 size_t alen;
993 char *addr; 1001 char *addr;
994 1002
995 GNUNET_assert(NULL != peer); 1003 GNUNET_assert (NULL != peer);
996 if (NULL != address) 1004 if (NULL != address)
997 { 1005 {
998 tlen = strlen(address->transport_name) + 1; 1006 tlen = strlen (address->transport_name) + 1;
999 alen = address->address_length; 1007 alen = address->address_length;
1000 } 1008 }
1001 else 1009 else
1002 { 1010 {
1003 tlen = 0; 1011 tlen = 0;
1004 alen = 0; 1012 alen = 0;
1005 } 1013 }
1006 size = (sizeof(struct PeerIterateResponseMessage) + alen + tlen); 1014 size = (sizeof(struct PeerIterateResponseMessage) + alen + tlen);
1007 msg = GNUNET_malloc(size); 1015 msg = GNUNET_malloc (size);
1008 msg->header.size = htons(size); 1016 msg->header.size = htons (size);
1009 msg->header.type = 1017 msg->header.type =
1010 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); 1018 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1011 msg->reserved = htonl(0); 1019 msg->reserved = htonl (0);
1012 msg->peer = *peer; 1020 msg->peer = *peer;
1013 msg->addrlen = htonl(alen); 1021 msg->addrlen = htonl (alen);
1014 msg->pluginlen = htonl(tlen); 1022 msg->pluginlen = htonl (tlen);
1015 1023
1016 if (NULL != address) 1024 if (NULL != address)
1017 { 1025 {
1018 msg->local_address_info = htonl((uint32_t)address->local_info); 1026 msg->local_address_info = htonl ((uint32_t) address->local_info);
1019 addr = (char *)&msg[1]; 1027 addr = (char *) &msg[1];
1020 GNUNET_memcpy(addr, address->address, alen); 1028 GNUNET_memcpy (addr, address->address, alen);
1021 GNUNET_memcpy(&addr[alen], address->transport_name, tlen); 1029 GNUNET_memcpy (&addr[alen], address->transport_name, tlen);
1022 } 1030 }
1023 return msg; 1031 return msg;
1024} 1032}
1025 1033
@@ -1028,7 +1036,8 @@ compose_address_iterate_response_message(
1028 * Context for #send_validation_information() and 1036 * Context for #send_validation_information() and
1029 * #send_peer_information(). 1037 * #send_peer_information().
1030 */ 1038 */
1031struct IterationContext { 1039struct IterationContext
1040{
1032 /** 1041 /**
1033 * Context to use for the transmission. 1042 * Context to use for the transmission.
1034 */ 1043 */
@@ -1058,31 +1067,31 @@ struct IterationContext {
1058 * @param bandwidth_out outbound quota in NBO 1067 * @param bandwidth_out outbound quota in NBO
1059 */ 1068 */
1060static void 1069static void
1061send_peer_information(void *cls, 1070send_peer_information (void *cls,
1062 const struct GNUNET_PeerIdentity *peer, 1071 const struct GNUNET_PeerIdentity *peer,
1063 const struct GNUNET_HELLO_Address *address, 1072 const struct GNUNET_HELLO_Address *address,
1064 enum GNUNET_TRANSPORT_PeerState state, 1073 enum GNUNET_TRANSPORT_PeerState state,
1065 struct GNUNET_TIME_Absolute state_timeout, 1074 struct GNUNET_TIME_Absolute state_timeout,
1066 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1075 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1067 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1076 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1068{ 1077{
1069 struct IterationContext *pc = cls; 1078 struct IterationContext *pc = cls;
1070 struct GNUNET_MQ_Envelope *env; 1079 struct GNUNET_MQ_Envelope *env;
1071 struct PeerIterateResponseMessage *msg; 1080 struct PeerIterateResponseMessage *msg;
1072 1081
1073 if ((GNUNET_YES != pc->all) && (0 != memcmp(peer, &pc->id, sizeof(pc->id)))) 1082 if ((GNUNET_YES != pc->all) && (0 != memcmp (peer, &pc->id, sizeof(pc->id))))
1074 return; 1083 return;
1075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1076 "Sending information about `%s' using address `%s' in state `%s'\n", 1085 "Sending information about `%s' using address `%s' in state `%s'\n",
1077 GNUNET_i2s(peer), 1086 GNUNET_i2s (peer),
1078 (NULL != address) ? GST_plugins_a2s(address) : "<none>", 1087 (NULL != address) ? GST_plugins_a2s (address) : "<none>",
1079 GNUNET_TRANSPORT_ps2s(state)); 1088 GNUNET_TRANSPORT_ps2s (state));
1080 msg = compose_address_iterate_response_message(peer, address); 1089 msg = compose_address_iterate_response_message (peer, address);
1081 msg->state = htonl(state); 1090 msg->state = htonl (state);
1082 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); 1091 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1083 env = GNUNET_MQ_msg_copy(&msg->header); 1092 env = GNUNET_MQ_msg_copy (&msg->header);
1084 GNUNET_free(msg); 1093 GNUNET_free (msg);
1085 GNUNET_MQ_send(pc->tc->mq, env); 1094 GNUNET_MQ_send (pc->tc->mq, env);
1086} 1095}
1087 1096
1088 1097
@@ -1094,61 +1103,61 @@ send_peer_information(void *cls,
1094 * @param msg the peer address information request 1103 * @param msg the peer address information request
1095 */ 1104 */
1096static void 1105static void
1097handle_client_monitor_peers(void *cls, const struct PeerMonitorMessage *msg) 1106handle_client_monitor_peers (void *cls, const struct PeerMonitorMessage *msg)
1098{ 1107{
1099 struct TransportClient *tc = cls; 1108 struct TransportClient *tc = cls;
1100 struct IterationContext pc; 1109 struct IterationContext pc;
1101 1110
1102 if (CT_NONE != tc->type) 1111 if (CT_NONE != tc->type)
1103 { 1112 {
1104 GNUNET_break(0); 1113 GNUNET_break (0);
1105 GNUNET_SERVICE_client_drop(tc->client); 1114 GNUNET_SERVICE_client_drop (tc->client);
1106 return; 1115 return;
1107 } 1116 }
1108 GNUNET_SERVICE_client_disable_continue_warning(tc->client); 1117 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1109 GNUNET_SERVICE_client_mark_monitor(tc->client); 1118 GNUNET_SERVICE_client_mark_monitor (tc->client);
1110 1119
1111 /* Send initial list */ 1120 /* Send initial list */
1112 pc.tc = tc; 1121 pc.tc = tc;
1113 if (0 == memcmp(&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity))) 1122 if (0 == memcmp (&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity)))
1114 { 1123 {
1115 /* iterate over all neighbours */ 1124 /* iterate over all neighbours */
1116 pc.all = GNUNET_YES; 1125 pc.all = GNUNET_YES;
1117 pc.id = msg->peer; 1126 pc.id = msg->peer;
1118 } 1127 }
1119 else 1128 else
1120 { 1129 {
1121 /* just return one neighbour */ 1130 /* just return one neighbour */
1122 pc.all = GNUNET_NO; 1131 pc.all = GNUNET_NO;
1123 pc.id = msg->peer; 1132 pc.id = msg->peer;
1124 } 1133 }
1125 GST_neighbours_iterate(&send_peer_information, &pc); 1134 GST_neighbours_iterate (&send_peer_information, &pc);
1126 1135
1127 if (GNUNET_YES != ntohl(msg->one_shot)) 1136 if (GNUNET_YES != ntohl (msg->one_shot))
1128 { 1137 {
1129 tc->details.monitor_peer = msg->peer; 1138 tc->details.monitor_peer = msg->peer;
1130 tc->type = CT_MONITOR; 1139 tc->type = CT_MONITOR;
1131 if (0 != 1140 if (0 !=
1132 memcmp(&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity))) 1141 memcmp (&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity)))
1133 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1134 "Client %p started monitoring of the peer `%s'\n", 1143 "Client %p started monitoring of the peer `%s'\n",
1135 tc, 1144 tc,
1136 GNUNET_i2s(&msg->peer)); 1145 GNUNET_i2s (&msg->peer));
1137 else 1146 else
1138 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1139 "Client %p started monitoring all peers\n", 1148 "Client %p started monitoring all peers\n",
1140 tc); 1149 tc);
1141 } 1150 }
1142 else 1151 else
1143 { 1152 {
1144 struct GNUNET_MessageHeader *msg; 1153 struct GNUNET_MessageHeader *msg;
1145 struct GNUNET_MQ_Envelope *env; 1154 struct GNUNET_MQ_Envelope *env;
1146 1155
1147 env = 1156 env =
1148 GNUNET_MQ_msg(msg, 1157 GNUNET_MQ_msg (msg,
1149 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END); 1158 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END);
1150 GNUNET_MQ_send(tc->mq, env); 1159 GNUNET_MQ_send (tc->mq, env);
1151 } 1160 }
1152} 1161}
1153 1162
1154 1163
@@ -1165,9 +1174,9 @@ handle_client_monitor_peers(void *cls, const struct PeerMonitorMessage *msg)
1165 * merely signalling that the initial iteration is over 1174 * merely signalling that the initial iteration is over
1166 */ 1175 */
1167static void 1176static void
1168plugin_session_info_cb(void *cls, 1177plugin_session_info_cb (void *cls,
1169 struct GNUNET_ATS_Session *session, 1178 struct GNUNET_ATS_Session *session,
1170 const struct GNUNET_TRANSPORT_SessionInfo *info) 1179 const struct GNUNET_TRANSPORT_SessionInfo *info)
1171{ 1180{
1172 struct GNUNET_MQ_Envelope *env; 1181 struct GNUNET_MQ_Envelope *env;
1173 struct TransportPluginMonitorMessage *msg; 1182 struct TransportPluginMonitorMessage *msg;
@@ -1178,65 +1187,65 @@ plugin_session_info_cb(void *cls,
1178 char *name; 1187 char *name;
1179 char *addr; 1188 char *addr;
1180 1189
1181 if (0 == GNUNET_notification_context_get_size(plugin_nc)) 1190 if (0 == GNUNET_notification_context_get_size (plugin_nc))
1182 { 1191 {
1183 GST_plugins_monitor_subscribe(NULL, NULL); 1192 GST_plugins_monitor_subscribe (NULL, NULL);
1184 return; 1193 return;
1185 } 1194 }
1186 if ((NULL == info) && (NULL == session)) 1195 if ((NULL == info) && (NULL == session))
1196 {
1197 /* end of initial iteration */
1198 if (NULL != sync_client)
1187 { 1199 {
1188 /* end of initial iteration */ 1200 env =
1189 if (NULL != sync_client) 1201 GNUNET_MQ_msg (sync, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1190 { 1202 GNUNET_MQ_send (sync_client->mq, env);
1191 env = 1203 sync_client = NULL;
1192 GNUNET_MQ_msg(sync, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1193 GNUNET_MQ_send(sync_client->mq, env);
1194 sync_client = NULL;
1195 }
1196 return;
1197 } 1204 }
1198 GNUNET_assert(NULL != info); 1205 return;
1199 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1206 }
1200 "Plugin event for peer %s on transport %s\n", 1207 GNUNET_assert (NULL != info);
1201 GNUNET_i2s(&info->address->peer), 1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1202 info->address->transport_name); 1209 "Plugin event for peer %s on transport %s\n",
1203 slen = strlen(info->address->transport_name) + 1; 1210 GNUNET_i2s (&info->address->peer),
1211 info->address->transport_name);
1212 slen = strlen (info->address->transport_name) + 1;
1204 alen = info->address->address_length; 1213 alen = info->address->address_length;
1205 size = sizeof(struct TransportPluginMonitorMessage) + slen + alen; 1214 size = sizeof(struct TransportPluginMonitorMessage) + slen + alen;
1206 if (size > UINT16_MAX) 1215 if (size > UINT16_MAX)
1207 { 1216 {
1208 GNUNET_break(0); 1217 GNUNET_break (0);
1209 return; 1218 return;
1210 } 1219 }
1211 msg = GNUNET_malloc(size); 1220 msg = GNUNET_malloc (size);
1212 msg->header.size = htons(size); 1221 msg->header.size = htons (size);
1213 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT); 1222 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
1214 msg->session_state = htons((uint16_t)info->state); 1223 msg->session_state = htons ((uint16_t) info->state);
1215 msg->is_inbound = htons((int16_t)info->is_inbound); 1224 msg->is_inbound = htons ((int16_t) info->is_inbound);
1216 msg->msgs_pending = htonl(info->num_msg_pending); 1225 msg->msgs_pending = htonl (info->num_msg_pending);
1217 msg->bytes_pending = htonl(info->num_bytes_pending); 1226 msg->bytes_pending = htonl (info->num_bytes_pending);
1218 msg->timeout = GNUNET_TIME_absolute_hton(info->session_timeout); 1227 msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
1219 msg->delay = GNUNET_TIME_absolute_hton(info->receive_delay); 1228 msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
1220 msg->peer = info->address->peer; 1229 msg->peer = info->address->peer;
1221 msg->session_id = (uint64_t)(intptr_t)session; 1230 msg->session_id = (uint64_t) (intptr_t) session;
1222 msg->plugin_name_len = htons(slen); 1231 msg->plugin_name_len = htons (slen);
1223 msg->plugin_address_len = htons(alen); 1232 msg->plugin_address_len = htons (alen);
1224 name = (char *)&msg[1]; 1233 name = (char *) &msg[1];
1225 GNUNET_memcpy(name, info->address->transport_name, slen); 1234 GNUNET_memcpy (name, info->address->transport_name, slen);
1226 addr = &name[slen]; 1235 addr = &name[slen];
1227 GNUNET_memcpy(addr, info->address->address, alen); 1236 GNUNET_memcpy (addr, info->address->address, alen);
1228 if (NULL != sync_client) 1237 if (NULL != sync_client)
1229 { 1238 {
1230 struct GNUNET_MQ_Envelope *env; 1239 struct GNUNET_MQ_Envelope *env;
1231 1240
1232 env = GNUNET_MQ_msg_copy(&msg->header); 1241 env = GNUNET_MQ_msg_copy (&msg->header);
1233 GNUNET_MQ_send(sync_client->mq, env); 1242 GNUNET_MQ_send (sync_client->mq, env);
1234 } 1243 }
1235 else 1244 else
1236 { 1245 {
1237 GNUNET_notification_context_broadcast(plugin_nc, &msg->header, GNUNET_NO); 1246 GNUNET_notification_context_broadcast (plugin_nc, &msg->header, GNUNET_NO);
1238 } 1247 }
1239 GNUNET_free(msg); 1248 GNUNET_free (msg);
1240} 1249}
1241 1250
1242 1251
@@ -1247,17 +1256,17 @@ plugin_session_info_cb(void *cls,
1247 * @param message the peer address information request 1256 * @param message the peer address information request
1248 */ 1257 */
1249static void 1258static void
1250handle_client_monitor_plugins(void *cls, 1259handle_client_monitor_plugins (void *cls,
1251 const struct GNUNET_MessageHeader *message) 1260 const struct GNUNET_MessageHeader *message)
1252{ 1261{
1253 struct TransportClient *tc = cls; 1262 struct TransportClient *tc = cls;
1254 1263
1255 GNUNET_SERVICE_client_mark_monitor(tc->client); 1264 GNUNET_SERVICE_client_mark_monitor (tc->client);
1256 GNUNET_SERVICE_client_disable_continue_warning(tc->client); 1265 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1257 GNUNET_notification_context_add(plugin_nc, tc->mq); 1266 GNUNET_notification_context_add (plugin_nc, tc->mq);
1258 GNUNET_assert(NULL == sync_client); 1267 GNUNET_assert (NULL == sync_client);
1259 sync_client = tc; 1268 sync_client = tc;
1260 GST_plugins_monitor_subscribe(&plugin_session_info_cb, NULL); 1269 GST_plugins_monitor_subscribe (&plugin_session_info_cb, NULL);
1261} 1270}
1262 1271
1263 1272
@@ -1268,28 +1277,28 @@ handle_client_monitor_plugins(void *cls,
1268 * @param may_drop #GNUNET_YES if the message can be dropped / is payload 1277 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
1269 */ 1278 */
1270void 1279void
1271GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, int may_drop) 1280GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop)
1272{ 1281{
1273 int done; 1282 int done;
1274 1283
1275 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1276 "Asked to broadcast message of type %u with %u bytes\n", 1285 "Asked to broadcast message of type %u with %u bytes\n",
1277 (unsigned int)ntohs(msg->type), 1286 (unsigned int) ntohs (msg->type),
1278 (unsigned int)ntohs(msg->size)); 1287 (unsigned int) ntohs (msg->size));
1279 done = GNUNET_NO; 1288 done = GNUNET_NO;
1280 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 1289 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
1281 { 1290 {
1282 if (CT_NONE == tc->type) 1291 if (CT_NONE == tc->type)
1283 continue; /* client not yet ready */ 1292 continue; /* client not yet ready */
1284 if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type)) 1293 if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type))
1285 continue; /* skip, this client does not care about payload */ 1294 continue; /* skip, this client does not care about payload */
1286 unicast(tc, msg, may_drop); 1295 unicast (tc, msg, may_drop);
1287 done = GNUNET_YES; 1296 done = GNUNET_YES;
1288 } 1297 }
1289 if (GNUNET_NO == done) 1298 if (GNUNET_NO == done)
1290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1291 "Message of type %u not delivered, is CORE service up?\n", 1300 "Message of type %u not delivered, is CORE service up?\n",
1292 ntohs(msg->type)); 1301 ntohs (msg->type));
1293} 1302}
1294 1303
1295 1304
@@ -1302,7 +1311,7 @@ GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, int may_drop)
1302 * @param state_timeout the time out for the state 1311 * @param state_timeout the time out for the state
1303 */ 1312 */
1304void 1313void
1305GST_clients_broadcast_peer_notification( 1314GST_clients_broadcast_peer_notification (
1306 const struct GNUNET_PeerIdentity *peer, 1315 const struct GNUNET_PeerIdentity *peer,
1307 const struct GNUNET_HELLO_Address *address, 1316 const struct GNUNET_HELLO_Address *address,
1308 enum GNUNET_TRANSPORT_PeerState state, 1317 enum GNUNET_TRANSPORT_PeerState state,
@@ -1311,25 +1320,25 @@ GST_clients_broadcast_peer_notification(
1311 struct GNUNET_MQ_Envelope *env; 1320 struct GNUNET_MQ_Envelope *env;
1312 struct PeerIterateResponseMessage *msg; 1321 struct PeerIterateResponseMessage *msg;
1313 1322
1314 msg = compose_address_iterate_response_message(peer, address); 1323 msg = compose_address_iterate_response_message (peer, address);
1315 msg->state = htonl(state); 1324 msg->state = htonl (state);
1316 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); 1325 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1317 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 1326 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
1318 { 1327 {
1319 if (CT_MONITOR != tc->type) 1328 if (CT_MONITOR != tc->type)
1320 continue; 1329 continue;
1321 if ((0 == memcmp(&tc->details.monitor_peer, 1330 if ((0 == memcmp (&tc->details.monitor_peer,
1322 &all_zeros, 1331 &all_zeros,
1323 sizeof(struct GNUNET_PeerIdentity))) || 1332 sizeof(struct GNUNET_PeerIdentity))) ||
1324 (0 == memcmp(&tc->details.monitor_peer, 1333 (0 == memcmp (&tc->details.monitor_peer,
1325 peer, 1334 peer,
1326 sizeof(struct GNUNET_PeerIdentity)))) 1335 sizeof(struct GNUNET_PeerIdentity))))
1327 { 1336 {
1328 env = GNUNET_MQ_msg_copy(&msg->header); 1337 env = GNUNET_MQ_msg_copy (&msg->header);
1329 GNUNET_MQ_send(tc->mq, env); 1338 GNUNET_MQ_send (tc->mq, env);
1330 }
1331 } 1339 }
1332 GNUNET_free(msg); 1340 }
1341 GNUNET_free (msg);
1333} 1342}
1334 1343
1335 1344
@@ -1343,7 +1352,7 @@ GST_clients_broadcast_peer_notification(
1343 * @return #GNUNET_OK (continue to iterate) 1352 * @return #GNUNET_OK (continue to iterate)
1344 */ 1353 */
1345static int 1354static int
1346mark_peer_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value) 1355mark_peer_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
1347{ 1356{
1348 struct SendTransmitContinuationContext *stcc = value; 1357 struct SendTransmitContinuationContext *stcc = value;
1349 1358
@@ -1359,19 +1368,19 @@ mark_peer_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
1359 * @param peer peer that disconnected 1368 * @param peer peer that disconnected
1360 */ 1369 */
1361void 1370void
1362GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer) 1371GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
1363{ 1372{
1364 struct DisconnectInfoMessage disconnect_msg; 1373 struct DisconnectInfoMessage disconnect_msg;
1365 1374
1366 GNUNET_CONTAINER_multipeermap_get_multiple(active_stccs, 1375 GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs,
1367 peer, 1376 peer,
1368 &mark_peer_down, 1377 &mark_peer_down,
1369 NULL); 1378 NULL);
1370 disconnect_msg.header.size = htons(sizeof(struct DisconnectInfoMessage)); 1379 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
1371 disconnect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 1380 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1372 disconnect_msg.reserved = htonl(0); 1381 disconnect_msg.reserved = htonl (0);
1373 disconnect_msg.peer = *peer; 1382 disconnect_msg.peer = *peer;
1374 GST_clients_broadcast(&disconnect_msg.header, GNUNET_NO); 1383 GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO);
1375} 1384}
1376 1385
1377 1386
@@ -1387,27 +1396,27 @@ GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer)
1387 * @param bandwidth_out outbound quota in NBO 1396 * @param bandwidth_out outbound quota in NBO
1388 */ 1397 */
1389static void 1398static void
1390transmit_our_hello(void *cls, 1399transmit_our_hello (void *cls,
1391 const struct GNUNET_PeerIdentity *peer, 1400 const struct GNUNET_PeerIdentity *peer,
1392 const struct GNUNET_HELLO_Address *address, 1401 const struct GNUNET_HELLO_Address *address,
1393 enum GNUNET_TRANSPORT_PeerState state, 1402 enum GNUNET_TRANSPORT_PeerState state,
1394 struct GNUNET_TIME_Absolute state_timeout, 1403 struct GNUNET_TIME_Absolute state_timeout,
1395 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1404 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1396 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1405 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1397{ 1406{
1398 const struct GNUNET_MessageHeader *hello = cls; 1407 const struct GNUNET_MessageHeader *hello = cls;
1399 1408
1400 if (0 == memcmp(peer, &GST_my_identity, sizeof(struct GNUNET_PeerIdentity))) 1409 if (0 == memcmp (peer, &GST_my_identity, sizeof(struct GNUNET_PeerIdentity)))
1401 return; /* not to ourselves */ 1410 return; /* not to ourselves */
1402 if (GNUNET_NO == GST_neighbours_test_connected(peer)) 1411 if (GNUNET_NO == GST_neighbours_test_connected (peer))
1403 return; 1412 return;
1404 1413
1405 GST_neighbours_send(peer, 1414 GST_neighbours_send (peer,
1406 hello, 1415 hello,
1407 ntohs(hello->size), 1416 ntohs (hello->size),
1408 hello_expiration, 1417 hello_expiration,
1409 NULL, 1418 NULL,
1410 NULL); 1419 NULL);
1411} 1420}
1412 1421
1413 1422
@@ -1418,12 +1427,12 @@ transmit_our_hello(void *cls,
1418 * @param hello new HELLO 1427 * @param hello new HELLO
1419 */ 1428 */
1420static void 1429static void
1421process_hello_update(void *cls, const struct GNUNET_MessageHeader *hello) 1430process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
1422{ 1431{
1423 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n"); 1432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n");
1424 GST_clients_broadcast(hello, GNUNET_NO); 1433 GST_clients_broadcast (hello, GNUNET_NO);
1425 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n"); 1434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n");
1426 GST_neighbours_iterate(&transmit_our_hello, (void *)hello); 1435 GST_neighbours_iterate (&transmit_our_hello, (void *) hello);
1427} 1436}
1428 1437
1429 1438
@@ -1438,44 +1447,44 @@ process_hello_update(void *cls, const struct GNUNET_MessageHeader *hello)
1438 * @return how long the plugin should wait until receiving more data 1447 * @return how long the plugin should wait until receiving more data
1439 */ 1448 */
1440static struct GNUNET_TIME_Relative 1449static struct GNUNET_TIME_Relative
1441process_payload(const struct GNUNET_HELLO_Address *address, 1450process_payload (const struct GNUNET_HELLO_Address *address,
1442 struct GNUNET_ATS_Session *session, 1451 struct GNUNET_ATS_Session *session,
1443 const struct GNUNET_MessageHeader *message) 1452 const struct GNUNET_MessageHeader *message)
1444{ 1453{
1445 struct GNUNET_TIME_Relative ret; 1454 struct GNUNET_TIME_Relative ret;
1446 int do_forward; 1455 int do_forward;
1447 struct InboundMessage *im; 1456 struct InboundMessage *im;
1448 size_t msg_size = ntohs(message->size); 1457 size_t msg_size = ntohs (message->size);
1449 size_t size = sizeof(struct InboundMessage) + msg_size; 1458 size_t size = sizeof(struct InboundMessage) + msg_size;
1450 char buf[size] GNUNET_ALIGN; 1459 char buf[size] GNUNET_ALIGN;
1451 1460
1452 do_forward = GNUNET_SYSERR; 1461 do_forward = GNUNET_SYSERR;
1453 ret = GST_neighbours_calculate_receive_delay(&address->peer, 1462 ret = GST_neighbours_calculate_receive_delay (&address->peer,
1454 msg_size, 1463 msg_size,
1455 &do_forward); 1464 &do_forward);
1456 if (!GST_neighbours_test_connected(&address->peer)) 1465 if (! GST_neighbours_test_connected (&address->peer))
1457 { 1466 {
1458 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1459 "Discarded %u bytes type %u payload from peer `%s'\n", 1468 "Discarded %u bytes type %u payload from peer `%s'\n",
1460 (unsigned int)msg_size, 1469 (unsigned int) msg_size,
1461 ntohs(message->type), 1470 ntohs (message->type),
1462 GNUNET_i2s(&address->peer)); 1471 GNUNET_i2s (&address->peer));
1463 GNUNET_STATISTICS_update( 1472 GNUNET_STATISTICS_update (
1464 GST_stats, 1473 GST_stats,
1465 gettext_noop("# bytes payload discarded due to not connected peer"), 1474 gettext_noop ("# bytes payload discarded due to not connected peer"),
1466 msg_size, 1475 msg_size,
1467 GNUNET_NO); 1476 GNUNET_NO);
1468 return ret; 1477 return ret;
1469 } 1478 }
1470 1479
1471 if (GNUNET_YES != do_forward) 1480 if (GNUNET_YES != do_forward)
1472 return ret; 1481 return ret;
1473 im = (struct InboundMessage *)buf; 1482 im = (struct InboundMessage *) buf;
1474 im->header.size = htons(size); 1483 im->header.size = htons (size);
1475 im->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 1484 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
1476 im->peer = address->peer; 1485 im->peer = address->peer;
1477 GNUNET_memcpy(&im[1], message, ntohs(message->size)); 1486 GNUNET_memcpy (&im[1], message, ntohs (message->size));
1478 GST_clients_broadcast(&im->header, GNUNET_YES); 1487 GST_clients_broadcast (&im->header, GNUNET_YES);
1479 return ret; 1488 return ret;
1480} 1489}
1481 1490
@@ -1486,14 +1495,14 @@ process_payload(const struct GNUNET_HELLO_Address *address,
1486 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill 1495 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill
1487 */ 1496 */
1488static void 1497static void
1489kill_session_task(void *cls) 1498kill_session_task (void *cls)
1490{ 1499{
1491 struct GNUNET_ATS_SessionKiller *sk = cls; 1500 struct GNUNET_ATS_SessionKiller *sk = cls;
1492 1501
1493 sk->task = NULL; 1502 sk->task = NULL;
1494 GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); 1503 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
1495 sk->plugin->disconnect_session(sk->plugin->cls, sk->session); 1504 sk->plugin->disconnect_session (sk->plugin->cls, sk->session);
1496 GNUNET_free(sk); 1505 GNUNET_free (sk);
1497} 1506}
1498 1507
1499 1508
@@ -1505,7 +1514,7 @@ kill_session_task(void *cls)
1505 * @param session session to termiante 1514 * @param session session to termiante
1506 */ 1515 */
1507static void 1516static void
1508kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session) 1517kill_session (const char *plugin_name, struct GNUNET_ATS_Session *session)
1509{ 1518{
1510 struct GNUNET_TRANSPORT_PluginFunctions *plugin; 1519 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
1511 struct GNUNET_ATS_SessionKiller *sk; 1520 struct GNUNET_ATS_SessionKiller *sk;
@@ -1513,18 +1522,18 @@ kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session)
1513 for (sk = sk_head; NULL != sk; sk = sk->next) 1522 for (sk = sk_head; NULL != sk; sk = sk->next)
1514 if (sk->session == session) 1523 if (sk->session == session)
1515 return; 1524 return;
1516 plugin = GST_plugins_find(plugin_name); 1525 plugin = GST_plugins_find (plugin_name);
1517 if (NULL == plugin) 1526 if (NULL == plugin)
1518 { 1527 {
1519 GNUNET_break(0); 1528 GNUNET_break (0);
1520 return; 1529 return;
1521 } 1530 }
1522 /* need to issue disconnect asynchronously */ 1531 /* need to issue disconnect asynchronously */
1523 sk = GNUNET_new(struct GNUNET_ATS_SessionKiller); 1532 sk = GNUNET_new (struct GNUNET_ATS_SessionKiller);
1524 sk->session = session; 1533 sk->session = session;
1525 sk->plugin = plugin; 1534 sk->plugin = plugin;
1526 sk->task = GNUNET_SCHEDULER_add_now(&kill_session_task, sk); 1535 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk);
1527 GNUNET_CONTAINER_DLL_insert(sk_head, sk_tail, sk); 1536 GNUNET_CONTAINER_DLL_insert (sk_head, sk_tail, sk);
1528} 1537}
1529 1538
1530 1539
@@ -1539,37 +1548,37 @@ kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session)
1539 * @param result the result 1548 * @param result the result
1540 */ 1549 */
1541static void 1550static void
1542connect_bl_check_cont(void *cls, 1551connect_bl_check_cont (void *cls,
1543 const struct GNUNET_PeerIdentity *peer, 1552 const struct GNUNET_PeerIdentity *peer,
1544 const struct GNUNET_HELLO_Address *address, 1553 const struct GNUNET_HELLO_Address *address,
1545 struct GNUNET_ATS_Session *session, 1554 struct GNUNET_ATS_Session *session,
1546 int result) 1555 int result)
1547{ 1556{
1548 struct GNUNET_MessageHeader *msg = cls; 1557 struct GNUNET_MessageHeader *msg = cls;
1549 1558
1550 if (GNUNET_OK == result) 1559 if (GNUNET_OK == result)
1560 {
1561 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
1562 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1563 "Received SYN message from peer `%s' at `%s'\n",
1564 GNUNET_i2s (peer),
1565 GST_plugins_a2s (address));
1566 if (GNUNET_OK != GST_neighbours_handle_session_syn (msg, peer))
1551 { 1567 {
1552 /* Blacklist allows to speak to this peer, forward SYN to neighbours */ 1568 GST_blacklist_abort_matching (address, session);
1553 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1569 kill_session (address->transport_name, session);
1554 "Received SYN message from peer `%s' at `%s'\n",
1555 GNUNET_i2s(peer),
1556 GST_plugins_a2s(address));
1557 if (GNUNET_OK != GST_neighbours_handle_session_syn(msg, peer))
1558 {
1559 GST_blacklist_abort_matching(address, session);
1560 kill_session(address->transport_name, session);
1561 }
1562 GNUNET_free(msg);
1563 return;
1564 } 1570 }
1565 GNUNET_free(msg); 1571 GNUNET_free (msg);
1572 return;
1573 }
1574 GNUNET_free (msg);
1566 if (GNUNET_SYSERR == result) 1575 if (GNUNET_SYSERR == result)
1567 return; /* check was aborted, session destroyed */ 1576 return; /* check was aborted, session destroyed */
1568 /* Blacklist denies to speak to this peer */ 1577 /* Blacklist denies to speak to this peer */
1569 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1578 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1570 "Discarding SYN message from `%s' due to denied blacklist check\n", 1579 "Discarding SYN message from `%s' due to denied blacklist check\n",
1571 GNUNET_i2s(peer)); 1580 GNUNET_i2s (peer));
1572 kill_session(address->transport_name, session); 1581 kill_session (address->transport_name, session);
1573} 1582}
1574 1583
1575 1584
@@ -1587,10 +1596,10 @@ connect_bl_check_cont(void *cls,
1587 * (plugins that do not support this, can ignore the return value) 1596 * (plugins that do not support this, can ignore the return value)
1588 */ 1597 */
1589struct GNUNET_TIME_Relative 1598struct GNUNET_TIME_Relative
1590GST_receive_callback(void *cls, 1599GST_receive_callback (void *cls,
1591 const struct GNUNET_HELLO_Address *address, 1600 const struct GNUNET_HELLO_Address *address,
1592 struct GNUNET_ATS_Session *session, 1601 struct GNUNET_ATS_Session *session,
1593 const struct GNUNET_MessageHeader *message) 1602 const struct GNUNET_MessageHeader *message)
1594{ 1603{
1595 const char *plugin_name = cls; 1604 const char *plugin_name = cls;
1596 struct GNUNET_TIME_Relative ret; 1605 struct GNUNET_TIME_Relative ret;
@@ -1599,115 +1608,115 @@ GST_receive_callback(void *cls,
1599 ret = GNUNET_TIME_UNIT_ZERO; 1608 ret = GNUNET_TIME_UNIT_ZERO;
1600 if (NULL == message) 1609 if (NULL == message)
1601 goto end; 1610 goto end;
1602 type = ntohs(message->type); 1611 type = ntohs (message->type);
1603 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1604 "Received message with type %u from peer `%s' at %s\n", 1613 "Received message with type %u from peer `%s' at %s\n",
1605 type, 1614 type,
1606 GNUNET_i2s(&address->peer), 1615 GNUNET_i2s (&address->peer),
1607 GST_plugins_a2s(address)); 1616 GST_plugins_a2s (address));
1608 1617
1609 GNUNET_STATISTICS_update(GST_stats, 1618 GNUNET_STATISTICS_update (GST_stats,
1610 gettext_noop("# bytes total received"), 1619 gettext_noop ("# bytes total received"),
1611 ntohs(message->size), 1620 ntohs (message->size),
1612 GNUNET_NO); 1621 GNUNET_NO);
1613 GST_neighbours_notify_data_recv(address, message); 1622 GST_neighbours_notify_data_recv (address, message);
1614 switch (type) 1623 switch (type)
1624 {
1625 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
1626 /* Legacy HELLO message, discard */
1627 return ret;
1628
1629 case GNUNET_MESSAGE_TYPE_HELLO:
1630 if (GNUNET_OK != GST_validation_handle_hello (message))
1615 { 1631 {
1616 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY: 1632 GNUNET_break_op (0);
1617 /* Legacy HELLO message, discard */ 1633 GST_blacklist_abort_matching (address, session);
1618 return ret; 1634 }
1619 1635 return ret;
1620 case GNUNET_MESSAGE_TYPE_HELLO:
1621 if (GNUNET_OK != GST_validation_handle_hello(message))
1622 {
1623 GNUNET_break_op(0);
1624 GST_blacklist_abort_matching(address, session);
1625 }
1626 return ret;
1627
1628 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
1629 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1630 "Processing PING from `%s'\n",
1631 GST_plugins_a2s(address));
1632 if (GNUNET_OK !=
1633 GST_validation_handle_ping(&address->peer, message, address, session))
1634 {
1635 GST_blacklist_abort_matching(address, session);
1636 kill_session(plugin_name, session);
1637 }
1638 break;
1639 1636
1640 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: 1637 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
1641 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1642 "Processing PONG from `%s'\n", 1639 "Processing PING from `%s'\n",
1643 GST_plugins_a2s(address)); 1640 GST_plugins_a2s (address));
1644 if (GNUNET_OK != GST_validation_handle_pong(&address->peer, message)) 1641 if (GNUNET_OK !=
1645 { 1642 GST_validation_handle_ping (&address->peer, message, address, session))
1646 GNUNET_break_op(0); 1643 {
1647 GST_blacklist_abort_matching(address, session); 1644 GST_blacklist_abort_matching (address, session);
1648 kill_session(plugin_name, session); 1645 kill_session (plugin_name, session);
1649 } 1646 }
1650 break; 1647 break;
1648
1649 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
1650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1651 "Processing PONG from `%s'\n",
1652 GST_plugins_a2s (address));
1653 if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message))
1654 {
1655 GNUNET_break_op (0);
1656 GST_blacklist_abort_matching (address, session);
1657 kill_session (plugin_name, session);
1658 }
1659 break;
1651 1660
1652 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN: 1661 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
1653 /* Do blacklist check if communication with this peer is allowed */ 1662 /* Do blacklist check if communication with this peer is allowed */
1654 (void)GST_blacklist_test_allowed(&address->peer, 1663 (void) GST_blacklist_test_allowed (&address->peer,
1655 NULL, 1664 NULL,
1656 &connect_bl_check_cont, 1665 &connect_bl_check_cont,
1657 GNUNET_copy_message(message), 1666 GNUNET_copy_message (message),
1658 address, 1667 address,
1659 session); 1668 session);
1660 break; 1669 break;
1661 1670
1662 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK: 1671 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
1663 if (GNUNET_OK != 1672 if (GNUNET_OK !=
1664 GST_neighbours_handle_session_syn_ack(message, address, session)) 1673 GST_neighbours_handle_session_syn_ack (message, address, session))
1665 { 1674 {
1666 GST_blacklist_abort_matching(address, session); 1675 GST_blacklist_abort_matching (address, session);
1667 kill_session(plugin_name, session); 1676 kill_session (plugin_name, session);
1668 } 1677 }
1669 break; 1678 break;
1670 1679
1671 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: 1680 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
1672 if (GNUNET_OK != 1681 if (GNUNET_OK !=
1673 GST_neighbours_handle_session_ack(message, address, session)) 1682 GST_neighbours_handle_session_ack (message, address, session))
1674 { 1683 {
1675 GNUNET_break_op(0); 1684 GNUNET_break_op (0);
1676 GST_blacklist_abort_matching(address, session); 1685 GST_blacklist_abort_matching (address, session);
1677 kill_session(plugin_name, session); 1686 kill_session (plugin_name, session);
1678 } 1687 }
1679 break; 1688 break;
1680 1689
1681 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: 1690 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
1682 GST_neighbours_handle_disconnect_message(&address->peer, message); 1691 GST_neighbours_handle_disconnect_message (&address->peer, message);
1683 break; 1692 break;
1684 1693
1685 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA: 1694 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA:
1686 GST_neighbours_handle_quota_message(&address->peer, message); 1695 GST_neighbours_handle_quota_message (&address->peer, message);
1687 break; 1696 break;
1688 1697
1689 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: 1698 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
1690 GST_neighbours_keepalive(&address->peer, message); 1699 GST_neighbours_keepalive (&address->peer, message);
1691 break; 1700 break;
1692 1701
1693 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: 1702 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
1694 GST_neighbours_keepalive_response(&address->peer, message); 1703 GST_neighbours_keepalive_response (&address->peer, message);
1695 break; 1704 break;
1696 1705
1697 default: 1706 default:
1698 /* should be payload */ 1707 /* should be payload */
1699 GNUNET_STATISTICS_update(GST_stats, 1708 GNUNET_STATISTICS_update (GST_stats,
1700 gettext_noop("# bytes payload received"), 1709 gettext_noop ("# bytes payload received"),
1701 ntohs(message->size), 1710 ntohs (message->size),
1702 GNUNET_NO); 1711 GNUNET_NO);
1703 ret = process_payload(address, session, message); 1712 ret = process_payload (address, session, message);
1704 break; 1713 break;
1705 } 1714 }
1706end: 1715end:
1707 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1708 "Allowing receive from peer %s to continue in %s\n", 1717 "Allowing receive from peer %s to continue in %s\n",
1709 GNUNET_i2s(&address->peer), 1718 GNUNET_i2s (&address->peer),
1710 GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); 1719 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
1711 return ret; 1720 return ret;
1712} 1721}
1713 1722
@@ -1722,7 +1731,7 @@ end:
1722 * @param address the address to add or remove 1731 * @param address the address to add or remove
1723 */ 1732 */
1724static void 1733static void
1725plugin_env_address_change_notification( 1734plugin_env_address_change_notification (
1726 void *cls, 1735 void *cls,
1727 int add_remove, 1736 int add_remove,
1728 const struct GNUNET_HELLO_Address *address) 1737 const struct GNUNET_HELLO_Address *address)
@@ -1730,29 +1739,29 @@ plugin_env_address_change_notification(
1730 static int addresses = 0; 1739 static int addresses = 0;
1731 1740
1732 if (GNUNET_YES == add_remove) 1741 if (GNUNET_YES == add_remove)
1742 {
1743 addresses++;
1744 GNUNET_STATISTICS_update (GST_stats, "# transport addresses", 1, GNUNET_NO);
1745 }
1746 else if (GNUNET_NO == add_remove)
1747 {
1748 if (0 == addresses)
1733 { 1749 {
1734 addresses++; 1750 GNUNET_break (0);
1735 GNUNET_STATISTICS_update(GST_stats, "# transport addresses", 1, GNUNET_NO);
1736 } 1751 }
1737 else if (GNUNET_NO == add_remove) 1752 else
1738 { 1753 {
1739 if (0 == addresses) 1754 addresses--;
1740 { 1755 GNUNET_STATISTICS_update (GST_stats,
1741 GNUNET_break(0); 1756 "# transport addresses",
1742 } 1757 -1,
1743 else 1758 GNUNET_NO);
1744 {
1745 addresses--;
1746 GNUNET_STATISTICS_update(GST_stats,
1747 "# transport addresses",
1748 -1,
1749 GNUNET_NO);
1750 }
1751 } 1759 }
1752 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1760 }
1753 "Transport now has %u addresses to communicate\n", 1761 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1754 addresses); 1762 "Transport now has %u addresses to communicate\n",
1755 GST_hello_modify_addresses(add_remove, address); 1763 addresses);
1764 GST_hello_modify_addresses (add_remove, address);
1756} 1765}
1757 1766
1758 1767
@@ -1770,45 +1779,45 @@ plugin_env_address_change_notification(
1770 * @param session which session is being destoyed 1779 * @param session which session is being destoyed
1771 */ 1780 */
1772static void 1781static void
1773plugin_env_session_end(void *cls, 1782plugin_env_session_end (void *cls,
1774 const struct GNUNET_HELLO_Address *address, 1783 const struct GNUNET_HELLO_Address *address,
1775 struct GNUNET_ATS_Session *session) 1784 struct GNUNET_ATS_Session *session)
1776{ 1785{
1777 struct GNUNET_ATS_SessionKiller *sk; 1786 struct GNUNET_ATS_SessionKiller *sk;
1778 1787
1779 if (NULL == address) 1788 if (NULL == address)
1780 { 1789 {
1781 GNUNET_break(0); 1790 GNUNET_break (0);
1782 return; 1791 return;
1783 } 1792 }
1784 if (NULL == session) 1793 if (NULL == session)
1785 { 1794 {
1786 GNUNET_break(0); 1795 GNUNET_break (0);
1787 return; 1796 return;
1788 } 1797 }
1789 GNUNET_assert(strlen(address->transport_name) > 0); 1798 GNUNET_assert (strlen (address->transport_name) > 0);
1790 1799
1791 GNUNET_log( 1800 GNUNET_log (
1792 GNUNET_ERROR_TYPE_DEBUG, 1801 GNUNET_ERROR_TYPE_DEBUG,
1793 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n", 1802 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
1794 session, 1803 session,
1795 GNUNET_i2s(&address->peer), 1804 GNUNET_i2s (&address->peer),
1796 GST_plugins_a2s(address)); 1805 GST_plugins_a2s (address));
1797 1806
1798 GST_neighbours_session_terminated(&address->peer, session); 1807 GST_neighbours_session_terminated (&address->peer, session);
1799 GST_ats_del_session(address, session); 1808 GST_ats_del_session (address, session);
1800 GST_blacklist_abort_matching(address, session); 1809 GST_blacklist_abort_matching (address, session);
1801 1810
1802 for (sk = sk_head; NULL != sk; sk = sk->next) 1811 for (sk = sk_head; NULL != sk; sk = sk->next)
1812 {
1813 if (sk->session == session)
1803 { 1814 {
1804 if (sk->session == session) 1815 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
1805 { 1816 GNUNET_SCHEDULER_cancel (sk->task);
1806 GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); 1817 GNUNET_free (sk);
1807 GNUNET_SCHEDULER_cancel(sk->task); 1818 break;
1808 GNUNET_free(sk);
1809 break;
1810 }
1811 } 1819 }
1820 }
1812} 1821}
1813 1822
1814 1823
@@ -1824,7 +1833,7 @@ plugin_env_session_end(void *cls,
1824 * @param result the result 1833 * @param result the result
1825 */ 1834 */
1826static void 1835static void
1827plugin_env_session_start_bl_check_cont( 1836plugin_env_session_start_bl_check_cont (
1828 void *cls, 1837 void *cls,
1829 const struct GNUNET_PeerIdentity *peer, 1838 const struct GNUNET_PeerIdentity *peer,
1830 const struct GNUNET_HELLO_Address *address, 1839 const struct GNUNET_HELLO_Address *address,
@@ -1832,19 +1841,19 @@ plugin_env_session_start_bl_check_cont(
1832 int result) 1841 int result)
1833{ 1842{
1834 if (GNUNET_OK != result) 1843 if (GNUNET_OK != result)
1835 { 1844 {
1836 kill_session(address->transport_name, session); 1845 kill_session (address->transport_name, session);
1837 return; 1846 return;
1838 } 1847 }
1839 if (GNUNET_YES != 1848 if (GNUNET_YES !=
1840 GNUNET_HELLO_address_check_option(address, 1849 GNUNET_HELLO_address_check_option (address,
1841 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 1850 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1842 { 1851 {
1843 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1844 "Informing verifier about inbound session's address `%s'\n", 1853 "Informing verifier about inbound session's address `%s'\n",
1845 GST_plugins_a2s(address)); 1854 GST_plugins_a2s (address));
1846 GST_validation_handle_address(address); 1855 GST_validation_handle_address (address);
1847 } 1856 }
1848} 1857}
1849 1858
1850 1859
@@ -1857,49 +1866,49 @@ plugin_env_session_start_bl_check_cont(
1857 * @param scope network scope information 1866 * @param scope network scope information
1858 */ 1867 */
1859static void 1868static void
1860plugin_env_session_start(void *cls, 1869plugin_env_session_start (void *cls,
1861 const struct GNUNET_HELLO_Address *address, 1870 const struct GNUNET_HELLO_Address *address,
1862 struct GNUNET_ATS_Session *session, 1871 struct GNUNET_ATS_Session *session,
1863 enum GNUNET_NetworkType scope) 1872 enum GNUNET_NetworkType scope)
1864{ 1873{
1865 struct GNUNET_ATS_Properties prop; 1874 struct GNUNET_ATS_Properties prop;
1866 1875
1867 if (NULL == address) 1876 if (NULL == address)
1868 { 1877 {
1869 GNUNET_break(0); 1878 GNUNET_break (0);
1870 return; 1879 return;
1871 } 1880 }
1872 if (NULL == session) 1881 if (NULL == session)
1873 { 1882 {
1874 GNUNET_break(0); 1883 GNUNET_break (0);
1875 return; 1884 return;
1876 } 1885 }
1877 GNUNET_log( 1886 GNUNET_log (
1878 GNUNET_ERROR_TYPE_INFO, 1887 GNUNET_ERROR_TYPE_INFO,
1879 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n", 1888 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n",
1880 address->transport_name, 1889 address->transport_name,
1881 GNUNET_i2s(&address->peer), 1890 GNUNET_i2s (&address->peer),
1882 GST_plugins_a2s(address)); 1891 GST_plugins_a2s (address));
1883 if (GNUNET_YES == 1892 if (GNUNET_YES ==
1884 GNUNET_HELLO_address_check_option(address, 1893 GNUNET_HELLO_address_check_option (address,
1885 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 1894 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1886 { 1895 {
1887 /* inbound is always new, but outbound MAY already be known, but 1896 /* inbound is always new, but outbound MAY already be known, but
1888 for example for UNIX, we have symmetric connections and thus we 1897 for example for UNIX, we have symmetric connections and thus we
1889 may not know the address yet; add if necessary! */ 1898 may not know the address yet; add if necessary! */
1890 /* FIXME: maybe change API here so we just pass scope? */ 1899 /* FIXME: maybe change API here so we just pass scope? */
1891 memset(&prop, 0, sizeof(prop)); 1900 memset (&prop, 0, sizeof(prop));
1892 GNUNET_break(GNUNET_NT_UNSPECIFIED != scope); 1901 GNUNET_break (GNUNET_NT_UNSPECIFIED != scope);
1893 prop.scope = scope; 1902 prop.scope = scope;
1894 GST_ats_add_inbound_address(address, session, &prop); 1903 GST_ats_add_inbound_address (address, session, &prop);
1895 } 1904 }
1896 /* Do blacklist check if communication with this peer is allowed */ 1905 /* Do blacklist check if communication with this peer is allowed */
1897 (void)GST_blacklist_test_allowed(&address->peer, 1906 (void) GST_blacklist_test_allowed (&address->peer,
1898 address->transport_name, 1907 address->transport_name,
1899 &plugin_env_session_start_bl_check_cont, 1908 &plugin_env_session_start_bl_check_cont,
1900 NULL, 1909 NULL,
1901 address, 1910 address,
1902 session); 1911 session);
1903} 1912}
1904 1913
1905 1914
@@ -1922,51 +1931,52 @@ plugin_env_session_start(void *cls,
1922 * @param ats_count number of @a ats elements 1931 * @param ats_count number of @a ats elements
1923 */ 1932 */
1924static void 1933static void
1925ats_request_address_change(void *cls, 1934ats_request_address_change (void *cls,
1926 const struct GNUNET_PeerIdentity *peer, 1935 const struct GNUNET_PeerIdentity *peer,
1927 const struct GNUNET_HELLO_Address *address, 1936 const struct GNUNET_HELLO_Address *address,
1928 struct GNUNET_ATS_Session *session, 1937 struct GNUNET_ATS_Session *session,
1929 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 1938 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
1930 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 1939 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
1931{ 1940{
1932 uint32_t bw_in = ntohl(bandwidth_in.value__); 1941 uint32_t bw_in = ntohl (bandwidth_in.value__);
1933 uint32_t bw_out = ntohl(bandwidth_out.value__); 1942 uint32_t bw_out = ntohl (bandwidth_out.value__);
1934 1943
1935 if (NULL == peer) 1944 if (NULL == peer)
1936 { 1945 {
1937 /* ATS service died, all suggestions become invalid! 1946 /* ATS service died, all suggestions become invalid!
1938 (but we'll keep using the allocations for a little 1947 (but we'll keep using the allocations for a little
1939 while, to keep going while ATS restarts) */ 1948 while, to keep going while ATS restarts) */
1940 /* FIXME: We should drop all 1949 /* FIXME: We should drop all
1941 connections now, as ATS won't explicitly tell 1950 connections now, as ATS won't explicitly tell
1942 us and be unaware of ongoing resource allocations! */ 1951 us and be unaware of ongoing resource allocations! */
1943 return; 1952 return;
1944 } 1953 }
1945 /* ATS tells me to disconnect from peer */ 1954 /* ATS tells me to disconnect from peer */
1946 if ((0 == bw_in) && (0 == bw_out)) 1955 if ((0 == bw_in) && (0 == bw_out))
1947 { 1956 {
1948 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1957 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1949 "ATS tells me to disconnect from peer `%s'\n", 1958 "ATS tells me to disconnect from peer `%s'\n",
1950 GNUNET_i2s(peer)); 1959 GNUNET_i2s (peer));
1951 GST_neighbours_force_disconnect(peer); 1960 GST_neighbours_force_disconnect (peer);
1952 return; 1961 return;
1953 } 1962 }
1954 GNUNET_assert(NULL != address); 1963 GNUNET_assert (NULL != address);
1955 GNUNET_STATISTICS_update(GST_stats, 1964 GNUNET_STATISTICS_update (GST_stats,
1956 "# ATS suggestions received", 1965 "# ATS suggestions received",
1957 1, 1966 1,
1958 GNUNET_NO); 1967 GNUNET_NO);
1959 GST_neighbours_switch_to_address(address, 1968 GST_neighbours_switch_to_address (address,
1960 session, 1969 session,
1961 bandwidth_in, 1970 bandwidth_in,
1962 bandwidth_out); 1971 bandwidth_out);
1963} 1972}
1964 1973
1965 1974
1966/** 1975/**
1967 * Closure for #test_connection_ok(). 1976 * Closure for #test_connection_ok().
1968 */ 1977 */
1969struct TestConnectionContext { 1978struct TestConnectionContext
1979{
1970 /** 1980 /**
1971 * Is this the first neighbour we're checking? 1981 * Is this the first neighbour we're checking?
1972 */ 1982 */
@@ -1991,19 +2001,19 @@ struct TestConnectionContext {
1991 * #GNUNET_NO if we must shutdown the connection 2001 * #GNUNET_NO if we must shutdown the connection
1992 */ 2002 */
1993static void 2003static void
1994confirm_or_drop_neighbour(void *cls, 2004confirm_or_drop_neighbour (void *cls,
1995 const struct GNUNET_PeerIdentity *peer, 2005 const struct GNUNET_PeerIdentity *peer,
1996 const struct GNUNET_HELLO_Address *address, 2006 const struct GNUNET_HELLO_Address *address,
1997 struct GNUNET_ATS_Session *session, 2007 struct GNUNET_ATS_Session *session,
1998 int allowed) 2008 int allowed)
1999{ 2009{
2000 if (GNUNET_OK == allowed) 2010 if (GNUNET_OK == allowed)
2001 return; /* we're done */ 2011 return; /* we're done */
2002 GNUNET_STATISTICS_update(GST_stats, 2012 GNUNET_STATISTICS_update (GST_stats,
2003 gettext_noop("# disconnects due to blacklist"), 2013 gettext_noop ("# disconnects due to blacklist"),
2004 1, 2014 1,
2005 GNUNET_NO); 2015 GNUNET_NO);
2006 GST_neighbours_force_disconnect(peer); 2016 GST_neighbours_force_disconnect (peer);
2007} 2017}
2008 2018
2009 2019
@@ -2020,31 +2030,31 @@ confirm_or_drop_neighbour(void *cls,
2020 * @param bandwidth_out bandwidth assigned outbound 2030 * @param bandwidth_out bandwidth assigned outbound
2021 */ 2031 */
2022static void 2032static void
2023test_connection_ok(void *cls, 2033test_connection_ok (void *cls,
2024 const struct GNUNET_PeerIdentity *peer, 2034 const struct GNUNET_PeerIdentity *peer,
2025 const struct GNUNET_HELLO_Address *address, 2035 const struct GNUNET_HELLO_Address *address,
2026 enum GNUNET_TRANSPORT_PeerState state, 2036 enum GNUNET_TRANSPORT_PeerState state,
2027 struct GNUNET_TIME_Absolute state_timeout, 2037 struct GNUNET_TIME_Absolute state_timeout,
2028 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 2038 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2029 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2039 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2030{ 2040{
2031 struct TestConnectionContext *tcc = cls; 2041 struct TestConnectionContext *tcc = cls;
2032 struct GST_BlacklistCheck *bc; 2042 struct GST_BlacklistCheck *bc;
2033 2043
2034 bc = GNUNET_new(struct GST_BlacklistCheck); 2044 bc = GNUNET_new (struct GST_BlacklistCheck);
2035 GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc); 2045 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
2036 bc->peer = *peer; 2046 bc->peer = *peer;
2037 bc->address = GNUNET_HELLO_address_copy(address); 2047 bc->address = GNUNET_HELLO_address_copy (address);
2038 bc->cont = &confirm_or_drop_neighbour; 2048 bc->cont = &confirm_or_drop_neighbour;
2039 bc->cont_cls = NULL; 2049 bc->cont_cls = NULL;
2040 bc->bl_pos = tcc->tc; 2050 bc->bl_pos = tcc->tc;
2041 if (GNUNET_YES == tcc->first) 2051 if (GNUNET_YES == tcc->first)
2042 { 2052 {
2043 /* all would wait for the same client, no need to 2053 /* all would wait for the same client, no need to
2044 * create more than just the first task right now */ 2054 * create more than just the first task right now */
2045 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); 2055 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2046 tcc->first = GNUNET_NO; 2056 tcc->first = GNUNET_NO;
2047 } 2057 }
2048} 2058}
2049 2059
2050 2060
@@ -2057,26 +2067,26 @@ test_connection_ok(void *cls,
2057 * @param message the blacklist-init message that was sent 2067 * @param message the blacklist-init message that was sent
2058 */ 2068 */
2059static void 2069static void
2060handle_client_blacklist_init(void *cls, 2070handle_client_blacklist_init (void *cls,
2061 const struct GNUNET_MessageHeader *message) 2071 const struct GNUNET_MessageHeader *message)
2062{ 2072{
2063 struct TransportClient *tc = cls; 2073 struct TransportClient *tc = cls;
2064 struct TestConnectionContext tcc; 2074 struct TestConnectionContext tcc;
2065 2075
2066 if (CT_NONE != tc->type) 2076 if (CT_NONE != tc->type)
2067 { 2077 {
2068 GNUNET_break(0); 2078 GNUNET_break (0);
2069 GNUNET_SERVICE_client_drop(tc->client); 2079 GNUNET_SERVICE_client_drop (tc->client);
2070 return; 2080 return;
2071 } 2081 }
2072 GNUNET_SERVICE_client_mark_monitor(tc->client); 2082 GNUNET_SERVICE_client_mark_monitor (tc->client);
2073 tc->type = CT_BLACKLIST; 2083 tc->type = CT_BLACKLIST;
2074 tc->details.blacklist.call_receive_done = GNUNET_YES; 2084 tc->details.blacklist.call_receive_done = GNUNET_YES;
2075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc); 2085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc);
2076 /* confirm that all existing connections are OK! */ 2086 /* confirm that all existing connections are OK! */
2077 tcc.tc = tc; 2087 tcc.tc = tc;
2078 tcc.first = GNUNET_YES; 2088 tcc.first = GNUNET_YES;
2079 GST_neighbours_iterate(&test_connection_ok, &tcc); 2089 GST_neighbours_iterate (&test_connection_ok, &tcc);
2080} 2090}
2081 2091
2082 2092
@@ -2089,13 +2099,13 @@ handle_client_blacklist_init(void *cls,
2089 * @return #GNUNET_OK (continue to iterate) 2099 * @return #GNUNET_OK (continue to iterate)
2090 */ 2100 */
2091static int 2101static int
2092free_blacklist_entry(void *cls, 2102free_blacklist_entry (void *cls,
2093 const struct GNUNET_PeerIdentity *key, 2103 const struct GNUNET_PeerIdentity *key,
2094 void *value) 2104 void *value)
2095{ 2105{
2096 char *be = value; 2106 char *be = value;
2097 2107
2098 GNUNET_free_non_null(be); 2108 GNUNET_free_non_null (be);
2099 return GNUNET_OK; 2109 return GNUNET_OK;
2100} 2110}
2101 2111
@@ -2107,12 +2117,12 @@ free_blacklist_entry(void *cls,
2107 * @param message containing information 2117 * @param message containing information
2108 */ 2118 */
2109static void 2119static void
2110handle_client_set_metric(void *cls, const struct TrafficMetricMessage *tm) 2120handle_client_set_metric (void *cls, const struct TrafficMetricMessage *tm)
2111{ 2121{
2112 struct TransportClient *tc = cls; 2122 struct TransportClient *tc = cls;
2113 2123
2114 GST_manipulation_set_metric(tm); 2124 GST_manipulation_set_metric (tm);
2115 GNUNET_SERVICE_client_continue(tc->client); 2125 GNUNET_SERVICE_client_continue (tc->client);
2116} 2126}
2117 2127
2118 2128
@@ -2123,58 +2133,58 @@ handle_client_set_metric(void *cls, const struct TrafficMetricMessage *tm)
2123 * @param cls closure, unused 2133 * @param cls closure, unused
2124 */ 2134 */
2125static void 2135static void
2126shutdown_task(void *cls) 2136shutdown_task (void *cls)
2127{ 2137{
2128 struct AddressToStringContext *cur; 2138 struct AddressToStringContext *cur;
2129 2139
2130 GST_neighbours_stop(); 2140 GST_neighbours_stop ();
2131 GST_plugins_unload(); 2141 GST_plugins_unload ();
2132 GST_validation_stop(); 2142 GST_validation_stop ();
2133 GST_ats_done(); 2143 GST_ats_done ();
2134 GNUNET_ATS_scheduling_done(GST_ats); 2144 GNUNET_ATS_scheduling_done (GST_ats);
2135 GST_ats = NULL; 2145 GST_ats = NULL;
2136 GNUNET_ATS_connectivity_done(GST_ats_connect); 2146 GNUNET_ATS_connectivity_done (GST_ats_connect);
2137 GST_ats_connect = NULL; 2147 GST_ats_connect = NULL;
2138 GNUNET_NT_scanner_done(GST_is); 2148 GNUNET_NT_scanner_done (GST_is);
2139 GST_is = NULL; 2149 GST_is = NULL;
2140 while (NULL != (cur = a2s_head)) 2150 while (NULL != (cur = a2s_head))
2141 { 2151 {
2142 GNUNET_CONTAINER_DLL_remove(a2s_head, a2s_tail, cur); 2152 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur);
2143 GNUNET_free(cur); 2153 GNUNET_free (cur);
2144 } 2154 }
2145 if (NULL != plugin_nc) 2155 if (NULL != plugin_nc)
2146 { 2156 {
2147 GNUNET_notification_context_destroy(plugin_nc); 2157 GNUNET_notification_context_destroy (plugin_nc);
2148 plugin_nc = NULL; 2158 plugin_nc = NULL;
2149 } 2159 }
2150 GNUNET_CONTAINER_multipeermap_destroy(active_stccs); 2160 GNUNET_CONTAINER_multipeermap_destroy (active_stccs);
2151 active_stccs = NULL; 2161 active_stccs = NULL;
2152 if (NULL != blacklist) 2162 if (NULL != blacklist)
2153 { 2163 {
2154 GNUNET_CONTAINER_multipeermap_iterate(blacklist, 2164 GNUNET_CONTAINER_multipeermap_iterate (blacklist,
2155 &free_blacklist_entry, 2165 &free_blacklist_entry,
2156 NULL); 2166 NULL);
2157 GNUNET_CONTAINER_multipeermap_destroy(blacklist); 2167 GNUNET_CONTAINER_multipeermap_destroy (blacklist);
2158 blacklist = NULL; 2168 blacklist = NULL;
2159 } 2169 }
2160 GST_hello_stop(); 2170 GST_hello_stop ();
2161 GST_manipulation_stop(); 2171 GST_manipulation_stop ();
2162 2172
2163 if (NULL != GST_peerinfo) 2173 if (NULL != GST_peerinfo)
2164 { 2174 {
2165 GNUNET_PEERINFO_disconnect(GST_peerinfo); 2175 GNUNET_PEERINFO_disconnect (GST_peerinfo);
2166 GST_peerinfo = NULL; 2176 GST_peerinfo = NULL;
2167 } 2177 }
2168 if (NULL != GST_stats) 2178 if (NULL != GST_stats)
2169 { 2179 {
2170 GNUNET_STATISTICS_destroy(GST_stats, GNUNET_NO); 2180 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
2171 GST_stats = NULL; 2181 GST_stats = NULL;
2172 } 2182 }
2173 if (NULL != GST_my_private_key) 2183 if (NULL != GST_my_private_key)
2174 { 2184 {
2175 GNUNET_free(GST_my_private_key); 2185 GNUNET_free (GST_my_private_key);
2176 GST_my_private_key = NULL; 2186 GST_my_private_key = NULL;
2177 } 2187 }
2178} 2188}
2179 2189
2180 2190
@@ -2184,7 +2194,7 @@ shutdown_task(void *cls)
2184 * @param cls the `struct GST_BlacklistCheck *` 2194 * @param cls the `struct GST_BlacklistCheck *`
2185 */ 2195 */
2186static void 2196static void
2187do_blacklist_check(void *cls) 2197do_blacklist_check (void *cls)
2188{ 2198{
2189 struct GST_BlacklistCheck *bc = cls; 2199 struct GST_BlacklistCheck *bc = cls;
2190 struct TransportClient *tc; 2200 struct TransportClient *tc;
@@ -2193,34 +2203,34 @@ do_blacklist_check(void *cls)
2193 2203
2194 bc->task = NULL; 2204 bc->task = NULL;
2195 while (NULL != (tc = bc->bl_pos)) 2205 while (NULL != (tc = bc->bl_pos))
2196 { 2206 {
2197 if (CT_BLACKLIST == tc->type) 2207 if (CT_BLACKLIST == tc->type)
2198 break; 2208 break;
2199 bc->bl_pos = tc->next; 2209 bc->bl_pos = tc->next;
2200 } 2210 }
2201 if (NULL == tc) 2211 if (NULL == tc)
2202 { 2212 {
2203 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2204 "No other blacklist clients active, will allow neighbour `%s'\n", 2214 "No other blacklist clients active, will allow neighbour `%s'\n",
2205 GNUNET_i2s(&bc->peer)); 2215 GNUNET_i2s (&bc->peer));
2206 2216
2207 bc->cont(bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK); 2217 bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK);
2208 GST_blacklist_test_cancel(bc); 2218 GST_blacklist_test_cancel (bc);
2209 return; 2219 return;
2210 } 2220 }
2211 if ((NULL != tc->details.blacklist.bc) || 2221 if ((NULL != tc->details.blacklist.bc) ||
2212 (GNUNET_NO != tc->details.blacklist.waiting_for_reply)) 2222 (GNUNET_NO != tc->details.blacklist.waiting_for_reply))
2213 return; /* someone else busy with this client */ 2223 return; /* someone else busy with this client */
2214 tc->details.blacklist.bc = bc; 2224 tc->details.blacklist.bc = bc;
2215 env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY); 2225 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
2216 bm->is_allowed = htonl(0); 2226 bm->is_allowed = htonl (0);
2217 bm->peer = bc->peer; 2227 bm->peer = bc->peer;
2218 GNUNET_MQ_send(tc->mq, env); 2228 GNUNET_MQ_send (tc->mq, env);
2219 if (GNUNET_YES == tc->details.blacklist.call_receive_done) 2229 if (GNUNET_YES == tc->details.blacklist.call_receive_done)
2220 { 2230 {
2221 tc->details.blacklist.call_receive_done = GNUNET_NO; 2231 tc->details.blacklist.call_receive_done = GNUNET_NO;
2222 GNUNET_SERVICE_client_continue(tc->client); 2232 GNUNET_SERVICE_client_continue (tc->client);
2223 } 2233 }
2224 tc->details.blacklist.waiting_for_reply = GNUNET_YES; 2234 tc->details.blacklist.waiting_for_reply = GNUNET_YES;
2225} 2235}
2226 2236
@@ -2232,62 +2242,62 @@ do_blacklist_check(void *cls)
2232 * @param msg the blacklist-reply message that was sent 2242 * @param msg the blacklist-reply message that was sent
2233 */ 2243 */
2234static void 2244static void
2235handle_client_blacklist_reply(void *cls, const struct BlacklistMessage *msg) 2245handle_client_blacklist_reply (void *cls, const struct BlacklistMessage *msg)
2236{ 2246{
2237 struct TransportClient *tc = cls; 2247 struct TransportClient *tc = cls;
2238 struct GST_BlacklistCheck *bc; 2248 struct GST_BlacklistCheck *bc;
2239 2249
2240 if (CT_BLACKLIST != tc->type) 2250 if (CT_BLACKLIST != tc->type)
2241 { 2251 {
2242 GNUNET_break(0); 2252 GNUNET_break (0);
2243 GNUNET_SERVICE_client_drop(tc->client); 2253 GNUNET_SERVICE_client_drop (tc->client);
2244 return; 2254 return;
2245 } 2255 }
2246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2247 "Blacklist client %p sent reply for `%s'\n", 2257 "Blacklist client %p sent reply for `%s'\n",
2248 tc, 2258 tc,
2249 GNUNET_i2s(&msg->peer)); 2259 GNUNET_i2s (&msg->peer));
2250 bc = tc->details.blacklist.bc; 2260 bc = tc->details.blacklist.bc;
2251 tc->details.blacklist.bc = NULL; 2261 tc->details.blacklist.bc = NULL;
2252 tc->details.blacklist.waiting_for_reply = GNUNET_NO; 2262 tc->details.blacklist.waiting_for_reply = GNUNET_NO;
2253 tc->details.blacklist.call_receive_done = GNUNET_YES; 2263 tc->details.blacklist.call_receive_done = GNUNET_YES;
2254 if (NULL != bc) 2264 if (NULL != bc)
2265 {
2266 /* only run this if the blacklist check has not been
2267 * cancelled in the meantime... */
2268 GNUNET_assert (bc->bl_pos == tc);
2269 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
2270 {
2271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2272 "Blacklist check failed, peer not allowed\n");
2273 /* For the duration of the continuation, make the ongoing
2274 check invisible (to avoid double-cancellation); then
2275 add it back again so we can re-use GST_blacklist_test_cancel() */
2276 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
2277 bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_NO);
2278 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
2279 GST_blacklist_test_cancel (bc);
2280 tc->details.blacklist.call_receive_done = GNUNET_NO;
2281 GNUNET_SERVICE_client_continue (tc->client);
2282 return;
2283 }
2284 else
2255 { 2285 {
2256 /* only run this if the blacklist check has not been 2286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2257 * cancelled in the meantime... */ 2287 "Blacklist check succeeded, continuing with checks\n");
2258 GNUNET_assert(bc->bl_pos == tc); 2288 tc->details.blacklist.call_receive_done = GNUNET_NO;
2259 if (ntohl(msg->is_allowed) == GNUNET_SYSERR) 2289 GNUNET_SERVICE_client_continue (tc->client);
2260 { 2290 bc->bl_pos = tc->next;
2261 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2291 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2262 "Blacklist check failed, peer not allowed\n");
2263 /* For the duration of the continuation, make the ongoing
2264 check invisible (to avoid double-cancellation); then
2265 add it back again so we can re-use GST_blacklist_test_cancel() */
2266 GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc);
2267 bc->cont(bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_NO);
2268 GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc);
2269 GST_blacklist_test_cancel(bc);
2270 tc->details.blacklist.call_receive_done = GNUNET_NO;
2271 GNUNET_SERVICE_client_continue(tc->client);
2272 return;
2273 }
2274 else
2275 {
2276 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2277 "Blacklist check succeeded, continuing with checks\n");
2278 tc->details.blacklist.call_receive_done = GNUNET_NO;
2279 GNUNET_SERVICE_client_continue(tc->client);
2280 bc->bl_pos = tc->next;
2281 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc);
2282 }
2283 } 2292 }
2293 }
2284 /* check if any other blacklist checks are waiting for this blacklister */ 2294 /* check if any other blacklist checks are waiting for this blacklister */
2285 for (bc = bc_head; bc != NULL; bc = bc->next) 2295 for (bc = bc_head; bc != NULL; bc = bc->next)
2286 if ((bc->bl_pos == tc) && (NULL == bc->task)) 2296 if ((bc->bl_pos == tc) && (NULL == bc->task))
2287 { 2297 {
2288 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); 2298 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2289 break; 2299 break;
2290 } 2300 }
2291} 2301}
2292 2302
2293 2303
@@ -2298,32 +2308,32 @@ handle_client_blacklist_reply(void *cls, const struct BlacklistMessage *msg)
2298 * @param transport_name transport to blacklist for this peer, NULL for all 2308 * @param transport_name transport to blacklist for this peer, NULL for all
2299 */ 2309 */
2300void 2310void
2301GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer, 2311GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
2302 const char *transport_name) 2312 const char *transport_name)
2303{ 2313{
2304 char *transport = NULL; 2314 char *transport = NULL;
2305 2315
2306 if (NULL != transport_name) 2316 if (NULL != transport_name)
2307 { 2317 {
2308 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2318 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2309 "Adding peer `%s' with plugin `%s' to blacklist\n", 2319 "Adding peer `%s' with plugin `%s' to blacklist\n",
2310 GNUNET_i2s(peer), 2320 GNUNET_i2s (peer),
2311 transport_name); 2321 transport_name);
2312 transport = GNUNET_strdup(transport_name); 2322 transport = GNUNET_strdup (transport_name);
2313 } 2323 }
2314 else 2324 else
2315 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2325 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2316 "Adding peer `%s' with all plugins to blacklist\n", 2326 "Adding peer `%s' with all plugins to blacklist\n",
2317 GNUNET_i2s(peer)); 2327 GNUNET_i2s (peer));
2318 if (NULL == blacklist) 2328 if (NULL == blacklist)
2319 blacklist = 2329 blacklist =
2320 GNUNET_CONTAINER_multipeermap_create(TRANSPORT_BLACKLIST_HT_SIZE, 2330 GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
2321 GNUNET_NO); 2331 GNUNET_NO);
2322 2332
2323 GNUNET_CONTAINER_multipeermap_put(blacklist, 2333 GNUNET_CONTAINER_multipeermap_put (blacklist,
2324 peer, 2334 peer,
2325 transport, 2335 transport,
2326 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2336 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2327} 2337}
2328 2338
2329 2339
@@ -2334,27 +2344,27 @@ GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer,
2334 * @param session session used to abort matching checks 2344 * @param session session used to abort matching checks
2335 */ 2345 */
2336void 2346void
2337GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address, 2347GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
2338 struct GNUNET_ATS_Session *session) 2348 struct GNUNET_ATS_Session *session)
2339{ 2349{
2340 struct GST_BlacklistCheck *bc; 2350 struct GST_BlacklistCheck *bc;
2341 struct GST_BlacklistCheck *n; 2351 struct GST_BlacklistCheck *n;
2342 2352
2343 n = bc_head; 2353 n = bc_head;
2344 while (NULL != (bc = n)) 2354 while (NULL != (bc = n))
2355 {
2356 n = bc->next;
2357 if ((bc->session == session) &&
2358 (0 == GNUNET_HELLO_address_cmp (bc->address, address)))
2345 { 2359 {
2346 n = bc->next; 2360 bc->cont (bc->cont_cls,
2347 if ((bc->session == session) && 2361 &bc->peer,
2348 (0 == GNUNET_HELLO_address_cmp(bc->address, address))) 2362 bc->address,
2349 { 2363 bc->session,
2350 bc->cont(bc->cont_cls, 2364 GNUNET_SYSERR);
2351 &bc->peer, 2365 GST_blacklist_test_cancel (bc);
2352 bc->address,
2353 bc->session,
2354 GNUNET_SYSERR);
2355 GST_blacklist_test_cancel(bc);
2356 }
2357 } 2366 }
2367 }
2358} 2368}
2359 2369
2360 2370
@@ -2368,7 +2378,7 @@ GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address,
2368 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches 2378 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
2369 */ 2379 */
2370static int 2380static int
2371test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 2381test_blacklisted (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2372{ 2382{
2373 const char *transport_name = cls; 2383 const char *transport_name = cls;
2374 char *be = value; 2384 char *be = value;
@@ -2382,21 +2392,21 @@ test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2382 * 2392 *
2383 */ 2393 */
2384 2394
2385 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2386 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n", 2396 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
2387 GNUNET_i2s(key), 2397 GNUNET_i2s (key),
2388 (NULL == transport_name) ? "unspecified" : transport_name, 2398 (NULL == transport_name) ? "unspecified" : transport_name,
2389 (NULL == be) ? "all plugins" : be); 2399 (NULL == be) ? "all plugins" : be);
2390 /* all plugins for this peer were blacklisted: disallow */ 2400 /* all plugins for this peer were blacklisted: disallow */
2391 if (NULL == value) 2401 if (NULL == value)
2392 return GNUNET_NO; 2402 return GNUNET_NO;
2393 2403
2394 /* blacklist check for specific transport */ 2404 /* blacklist check for specific transport */
2395 if ((NULL != transport_name) && (NULL != value)) 2405 if ((NULL != transport_name) && (NULL != value))
2396 { 2406 {
2397 if (0 == strcmp(transport_name, be)) 2407 if (0 == strcmp (transport_name, be))
2398 return GNUNET_NO; /* plugin is blacklisted! */ 2408 return GNUNET_NO; /* plugin is blacklisted! */
2399 } 2409 }
2400 return GNUNET_OK; 2410 return GNUNET_OK;
2401} 2411}
2402 2412
@@ -2414,70 +2424,70 @@ test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2414 * was made instantly and @a cont was already called 2424 * was made instantly and @a cont was already called
2415 */ 2425 */
2416struct GST_BlacklistCheck * 2426struct GST_BlacklistCheck *
2417GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer, 2427GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
2418 const char *transport_name, 2428 const char *transport_name,
2419 GST_BlacklistTestContinuation cont, 2429 GST_BlacklistTestContinuation cont,
2420 void *cont_cls, 2430 void *cont_cls,
2421 const struct GNUNET_HELLO_Address *address, 2431 const struct GNUNET_HELLO_Address *address,
2422 struct GNUNET_ATS_Session *session) 2432 struct GNUNET_ATS_Session *session)
2423{ 2433{
2424 struct GST_BlacklistCheck *bc; 2434 struct GST_BlacklistCheck *bc;
2425 struct TransportClient *tc; 2435 struct TransportClient *tc;
2426 2436
2427 GNUNET_assert(NULL != peer); 2437 GNUNET_assert (NULL != peer);
2428 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2429 "Blacklist check for peer `%s':%s\n", 2439 "Blacklist check for peer `%s':%s\n",
2430 GNUNET_i2s(peer), 2440 GNUNET_i2s (peer),
2431 (NULL != transport_name) ? transport_name : "unspecified"); 2441 (NULL != transport_name) ? transport_name : "unspecified");
2432 2442
2433 /* Check local blacklist by iterating over hashmap 2443 /* Check local blacklist by iterating over hashmap
2434 * If iteration is aborted, we found a matching blacklist entry */ 2444 * If iteration is aborted, we found a matching blacklist entry */
2435 if ((NULL != blacklist) && 2445 if ((NULL != blacklist) &&
2436 (GNUNET_SYSERR == 2446 (GNUNET_SYSERR ==
2437 GNUNET_CONTAINER_multipeermap_get_multiple(blacklist, 2447 GNUNET_CONTAINER_multipeermap_get_multiple (blacklist,
2438 peer, 2448 peer,
2439 &test_blacklisted, 2449 &test_blacklisted,
2440 (void *)transport_name))) 2450 (void *) transport_name)))
2441 { 2451 {
2442 /* Disallowed by config, disapprove instantly */ 2452 /* Disallowed by config, disapprove instantly */
2443 GNUNET_STATISTICS_update(GST_stats, 2453 GNUNET_STATISTICS_update (GST_stats,
2444 gettext_noop("# disconnects due to blacklist"), 2454 gettext_noop ("# disconnects due to blacklist"),
2445 1, 2455 1,
2446 GNUNET_NO); 2456 GNUNET_NO);
2447 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2457 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2448 _("Disallowing connection to peer `%s' on transport %s\n"), 2458 _ ("Disallowing connection to peer `%s' on transport %s\n"),
2449 GNUNET_i2s(peer), 2459 GNUNET_i2s (peer),
2450 (NULL != transport_name) ? transport_name : "unspecified"); 2460 (NULL != transport_name) ? transport_name : "unspecified");
2451 if (NULL != cont) 2461 if (NULL != cont)
2452 cont(cont_cls, peer, address, session, GNUNET_NO); 2462 cont (cont_cls, peer, address, session, GNUNET_NO);
2453 return NULL; 2463 return NULL;
2454 } 2464 }
2455 2465
2456 for (tc = clients_head; NULL != tc; tc = tc->next) 2466 for (tc = clients_head; NULL != tc; tc = tc->next)
2457 if (CT_BLACKLIST == tc->type) 2467 if (CT_BLACKLIST == tc->type)
2458 break; 2468 break;
2459 if (NULL == tc) 2469 if (NULL == tc)
2460 { 2470 {
2461 /* no blacklist clients, approve instantly */ 2471 /* no blacklist clients, approve instantly */
2462 if (NULL != cont) 2472 if (NULL != cont)
2463 cont(cont_cls, peer, address, session, GNUNET_OK); 2473 cont (cont_cls, peer, address, session, GNUNET_OK);
2464 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2465 "Allowing connection to peer `%s' %s\n", 2475 "Allowing connection to peer `%s' %s\n",
2466 GNUNET_i2s(peer), 2476 GNUNET_i2s (peer),
2467 (NULL != transport_name) ? transport_name : ""); 2477 (NULL != transport_name) ? transport_name : "");
2468 return NULL; 2478 return NULL;
2469 } 2479 }
2470 2480
2471 /* need to query blacklist clients */ 2481 /* need to query blacklist clients */
2472 bc = GNUNET_new(struct GST_BlacklistCheck); 2482 bc = GNUNET_new (struct GST_BlacklistCheck);
2473 GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc); 2483 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
2474 bc->peer = *peer; 2484 bc->peer = *peer;
2475 bc->address = GNUNET_HELLO_address_copy(address); 2485 bc->address = GNUNET_HELLO_address_copy (address);
2476 bc->session = session; 2486 bc->session = session;
2477 bc->cont = cont; 2487 bc->cont = cont;
2478 bc->cont_cls = cont_cls; 2488 bc->cont_cls = cont_cls;
2479 bc->bl_pos = tc; 2489 bc->bl_pos = tc;
2480 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); 2490 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2481 return bc; 2491 return bc;
2482} 2492}
2483 2493
@@ -2488,25 +2498,25 @@ GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer,
2488 * @param bc check to cancel 2498 * @param bc check to cancel
2489 */ 2499 */
2490void 2500void
2491GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc) 2501GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
2492{ 2502{
2493 GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc); 2503 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
2494 if (NULL != bc->bl_pos) 2504 if (NULL != bc->bl_pos)
2505 {
2506 if ((CT_BLACKLIST == bc->bl_pos->type) &&
2507 (bc->bl_pos->details.blacklist.bc == bc))
2495 { 2508 {
2496 if ((CT_BLACKLIST == bc->bl_pos->type) && 2509 /* we're at the head of the queue, remove us! */
2497 (bc->bl_pos->details.blacklist.bc == bc)) 2510 bc->bl_pos->details.blacklist.bc = NULL;
2498 {
2499 /* we're at the head of the queue, remove us! */
2500 bc->bl_pos->details.blacklist.bc = NULL;
2501 }
2502 } 2511 }
2512 }
2503 if (NULL != bc->task) 2513 if (NULL != bc->task)
2504 { 2514 {
2505 GNUNET_SCHEDULER_cancel(bc->task); 2515 GNUNET_SCHEDULER_cancel (bc->task);
2506 bc->task = NULL; 2516 bc->task = NULL;
2507 } 2517 }
2508 GNUNET_free_non_null(bc->address); 2518 GNUNET_free_non_null (bc->address);
2509 GNUNET_free(bc); 2519 GNUNET_free (bc);
2510} 2520}
2511 2521
2512 2522
@@ -2519,10 +2529,10 @@ GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc)
2519 * @param value value of the option 2529 * @param value value of the option
2520 */ 2530 */
2521static void 2531static void
2522blacklist_cfg_iter(void *cls, 2532blacklist_cfg_iter (void *cls,
2523 const char *section, 2533 const char *section,
2524 const char *option, 2534 const char *option,
2525 const char *value) 2535 const char *value)
2526{ 2536{
2527 unsigned int *res = cls; 2537 unsigned int *res = cls;
2528 struct GNUNET_PeerIdentity peer; 2538 struct GNUNET_PeerIdentity peer;
@@ -2530,32 +2540,32 @@ blacklist_cfg_iter(void *cls,
2530 char *pos; 2540 char *pos;
2531 2541
2532 if (GNUNET_OK != 2542 if (GNUNET_OK !=
2533 GNUNET_CRYPTO_eddsa_public_key_from_string(option, 2543 GNUNET_CRYPTO_eddsa_public_key_from_string (option,
2534 strlen(option), 2544 strlen (option),
2535 &peer.public_key)) 2545 &peer.public_key))
2536 return; 2546 return;
2537 2547
2538 if ((NULL == value) || (0 == strcmp(value, ""))) 2548 if ((NULL == value) || (0 == strcmp (value, "")))
2539 { 2549 {
2540 /* Blacklist whole peer */ 2550 /* Blacklist whole peer */
2541 GST_blacklist_add_peer(&peer, NULL); 2551 GST_blacklist_add_peer (&peer, NULL);
2542 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2552 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2543 _("Adding blacklisting entry for peer `%s'\n"), 2553 _ ("Adding blacklisting entry for peer `%s'\n"),
2544 GNUNET_i2s(&peer)); 2554 GNUNET_i2s (&peer));
2545 } 2555 }
2546 else 2556 else
2557 {
2558 plugs = GNUNET_strdup (value);
2559 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
2547 { 2560 {
2548 plugs = GNUNET_strdup(value); 2561 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2549 for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " ")) 2562 _ ("Adding blacklisting entry for peer `%s':`%s'\n"),
2550 { 2563 GNUNET_i2s (&peer),
2551 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2564 pos);
2552 _("Adding blacklisting entry for peer `%s':`%s'\n"), 2565 GST_blacklist_add_peer (&peer, pos);
2553 GNUNET_i2s(&peer),
2554 pos);
2555 GST_blacklist_add_peer(&peer, pos);
2556 }
2557 GNUNET_free(plugs);
2558 } 2566 }
2567 GNUNET_free (plugs);
2568 }
2559 (*res)++; 2569 (*res)++;
2560} 2570}
2561 2571
@@ -2567,23 +2577,23 @@ blacklist_cfg_iter(void *cls,
2567 * @param my_id my peer identity 2577 * @param my_id my peer identity
2568 */ 2578 */
2569static void 2579static void
2570read_blacklist_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg, 2580read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
2571 const struct GNUNET_PeerIdentity *my_id) 2581 const struct GNUNET_PeerIdentity *my_id)
2572{ 2582{
2573 char cfg_sect[512]; 2583 char cfg_sect[512];
2574 unsigned int res = 0; 2584 unsigned int res = 0;
2575 2585
2576 GNUNET_snprintf(cfg_sect, 2586 GNUNET_snprintf (cfg_sect,
2577 sizeof(cfg_sect), 2587 sizeof(cfg_sect),
2578 "transport-blacklist-%s", 2588 "transport-blacklist-%s",
2579 GNUNET_i2s_full(my_id)); 2589 GNUNET_i2s_full (my_id));
2580 GNUNET_CONFIGURATION_iterate_section_values(cfg, 2590 GNUNET_CONFIGURATION_iterate_section_values (cfg,
2581 cfg_sect, 2591 cfg_sect,
2582 &blacklist_cfg_iter, 2592 &blacklist_cfg_iter,
2583 &res); 2593 &res);
2584 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2585 "Loaded %u blacklisting entries from configuration\n", 2595 "Loaded %u blacklisting entries from configuration\n",
2586 res); 2596 res);
2587} 2597}
2588 2598
2589 2599
@@ -2595,9 +2605,9 @@ read_blacklist_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg,
2595 * @param service the initialized service 2605 * @param service the initialized service
2596 */ 2606 */
2597static void 2607static void
2598run(void *cls, 2608run (void *cls,
2599 const struct GNUNET_CONFIGURATION_Handle *c, 2609 const struct GNUNET_CONFIGURATION_Handle *c,
2600 struct GNUNET_SERVICE_Handle *service) 2610 struct GNUNET_SERVICE_Handle *service)
2601{ 2611{
2602 char *keyfile; 2612 char *keyfile;
2603 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 2613 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
@@ -2608,70 +2618,70 @@ run(void *cls,
2608 2618
2609 /* setup globals */ 2619 /* setup globals */
2610 GST_cfg = c; 2620 GST_cfg = c;
2611 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c, 2621 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c,
2612 "PEER", 2622 "PEER",
2613 "PRIVATE_KEY", 2623 "PRIVATE_KEY",
2614 &keyfile)) 2624 &keyfile))
2615 { 2625 {
2616 GNUNET_log( 2626 GNUNET_log (
2617 GNUNET_ERROR_TYPE_ERROR, 2627 GNUNET_ERROR_TYPE_ERROR,
2618 _( 2628 _ (
2619 "Transport service is lacking key configuration settings. Exiting.\n")); 2629 "Transport service is lacking key configuration settings. Exiting.\n"));
2620 GNUNET_SCHEDULER_shutdown(); 2630 GNUNET_SCHEDULER_shutdown ();
2621 return; 2631 return;
2622 } 2632 }
2623 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(c, 2633 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (c,
2624 "transport", 2634 "transport",
2625 "HELLO_EXPIRATION", 2635 "HELLO_EXPIRATION",
2626 &hello_expiration)) 2636 &hello_expiration))
2627 { 2637 {
2628 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; 2638 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
2629 } 2639 }
2630 pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); 2640 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
2631 GNUNET_free(keyfile); 2641 GNUNET_free (keyfile);
2632 GNUNET_assert(NULL != pk); 2642 GNUNET_assert (NULL != pk);
2633 GST_my_private_key = pk; 2643 GST_my_private_key = pk;
2634 2644
2635 GST_stats = GNUNET_STATISTICS_create("transport", GST_cfg); 2645 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
2636 GST_peerinfo = GNUNET_PEERINFO_connect(GST_cfg); 2646 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
2637 GNUNET_CRYPTO_eddsa_key_get_public(GST_my_private_key, 2647 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
2638 &GST_my_identity.public_key); 2648 &GST_my_identity.public_key);
2639 GNUNET_assert(NULL != GST_my_private_key); 2649 GNUNET_assert (NULL != GST_my_private_key);
2640 2650
2641 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2651 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2642 "My identity is `%s'\n", 2652 "My identity is `%s'\n",
2643 GNUNET_i2s_full(&GST_my_identity)); 2653 GNUNET_i2s_full (&GST_my_identity));
2644 2654
2645 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 2655 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
2646 if (NULL == GST_peerinfo) 2656 if (NULL == GST_peerinfo)
2647 { 2657 {
2648 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2658 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2649 _("Could not access PEERINFO service. Exiting.\n")); 2659 _ ("Could not access PEERINFO service. Exiting.\n"));
2650 GNUNET_SCHEDULER_shutdown(); 2660 GNUNET_SCHEDULER_shutdown ();
2651 return; 2661 return;
2652 } 2662 }
2653 2663
2654 max_fd_rlimit = 0; 2664 max_fd_rlimit = 0;
2655#if HAVE_GETRLIMIT 2665#if HAVE_GETRLIMIT
2656 { 2666 {
2657 struct rlimit r_file; 2667 struct rlimit r_file;
2658 2668
2659 if (0 == getrlimit(RLIMIT_NOFILE, &r_file)) 2669 if (0 == getrlimit (RLIMIT_NOFILE, &r_file))
2660 { 2670 {
2661 max_fd_rlimit = r_file.rlim_cur; 2671 max_fd_rlimit = r_file.rlim_cur;
2662 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2663 "Maximum number of open files was: %u/%u\n", 2673 "Maximum number of open files was: %u/%u\n",
2664 (unsigned int)r_file.rlim_cur, 2674 (unsigned int) r_file.rlim_cur,
2665 (unsigned int)r_file.rlim_max); 2675 (unsigned int) r_file.rlim_max);
2666 } 2676 }
2667 max_fd_rlimit = 2677 max_fd_rlimit =
2668 (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ 2678 (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
2669 } 2679 }
2670#endif 2680#endif
2671 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(GST_cfg, 2681 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (GST_cfg,
2672 "transport", 2682 "transport",
2673 "MAX_FD", 2683 "MAX_FD",
2674 &max_fd_cfg)) 2684 &max_fd_cfg))
2675 max_fd_cfg = max_fd_rlimit; 2685 max_fd_cfg = max_fd_rlimit;
2676 2686
2677 if (max_fd_cfg > max_fd_rlimit) 2687 if (max_fd_cfg > max_fd_rlimit)
@@ -2681,14 +2691,14 @@ run(void *cls,
2681 if (max_fd < DEFAULT_MAX_FDS) 2691 if (max_fd < DEFAULT_MAX_FDS)
2682 max_fd = DEFAULT_MAX_FDS; 2692 max_fd = DEFAULT_MAX_FDS;
2683 2693
2684 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2694 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2685 "Limiting number of sockets to %u: validation %u, neighbors: %u\n", 2695 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
2686 max_fd, 2696 max_fd,
2687 (max_fd / 3), 2697 (max_fd / 3),
2688 (max_fd / 3) * 2); 2698 (max_fd / 3) * 2);
2689 2699
2690 friend_only = 2700 friend_only =
2691 GNUNET_CONFIGURATION_get_value_yesno(GST_cfg, "topology", "FRIENDS-ONLY"); 2701 GNUNET_CONFIGURATION_get_value_yesno (GST_cfg, "topology", "FRIENDS-ONLY");
2692 if (GNUNET_SYSERR == friend_only) 2702 if (GNUNET_SYSERR == friend_only)
2693 friend_only = GNUNET_NO; /* According to topology defaults */ 2703 friend_only = GNUNET_NO; /* According to topology defaults */
2694 /* start subsystems */ 2704 /* start subsystems */
@@ -2697,79 +2707,79 @@ run(void *cls,
2697 struct GNUNET_PeerIdentity dstj; 2707 struct GNUNET_PeerIdentity dstj;
2698 const char *ds = "DSTJBRRKZ8TBW3FGK6B0M5QXWT9WYNZ45H5MCV4HY7ST64Q8T9F0"; 2708 const char *ds = "DSTJBRRKZ8TBW3FGK6B0M5QXWT9WYNZ45H5MCV4HY7ST64Q8T9F0";
2699 2709
2700 GNUNET_assert( 2710 GNUNET_assert (
2701 GNUNET_OK == 2711 GNUNET_OK ==
2702 GNUNET_CRYPTO_eddsa_public_key_from_string(ds, 2712 GNUNET_CRYPTO_eddsa_public_key_from_string (ds,
2703 strlen(ds), 2713 strlen (ds),
2704 &dstj.public_key)); 2714 &dstj.public_key));
2705 GST_blacklist_add_peer(&dstj, NULL); 2715 GST_blacklist_add_peer (&dstj, NULL);
2706 } 2716 }
2707 read_blacklist_configuration(GST_cfg, &GST_my_identity); 2717 read_blacklist_configuration (GST_cfg, &GST_my_identity);
2708 GST_is = GNUNET_NT_scanner_init(); 2718 GST_is = GNUNET_NT_scanner_init ();
2709 GST_ats_connect = GNUNET_ATS_connectivity_init(GST_cfg); 2719 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
2710 GST_ats = 2720 GST_ats =
2711 GNUNET_ATS_scheduling_init(GST_cfg, &ats_request_address_change, NULL); 2721 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
2712 GST_ats_init(); 2722 GST_ats_init ();
2713 GST_manipulation_init(); 2723 GST_manipulation_init ();
2714 GST_plugins_load(&GST_manipulation_recv, 2724 GST_plugins_load (&GST_manipulation_recv,
2715 &plugin_env_address_change_notification, 2725 &plugin_env_address_change_notification,
2716 &plugin_env_session_start, 2726 &plugin_env_session_start,
2717 &plugin_env_session_end); 2727 &plugin_env_session_end);
2718 GST_hello_start(friend_only, &process_hello_update, NULL); 2728 GST_hello_start (friend_only, &process_hello_update, NULL);
2719 GST_neighbours_start((max_fd / 3) * 2); 2729 GST_neighbours_start ((max_fd / 3) * 2);
2720 active_stccs = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); 2730 active_stccs = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
2721 plugin_nc = GNUNET_notification_context_create(0); 2731 plugin_nc = GNUNET_notification_context_create (0);
2722 GST_validation_start((max_fd / 3)); 2732 GST_validation_start ((max_fd / 3));
2723} 2733}
2724 2734
2725 2735
2726/** 2736/**
2727 * Define "main" method using service macro. 2737 * Define "main" method using service macro.
2728 */ 2738 */
2729GNUNET_SERVICE_MAIN( 2739GNUNET_SERVICE_MAIN (
2730 "transport", 2740 "transport",
2731 GNUNET_SERVICE_OPTION_NONE, 2741 GNUNET_SERVICE_OPTION_NONE,
2732 &run, 2742 &run,
2733 &client_connect_cb, 2743 &client_connect_cb,
2734 &client_disconnect_cb, 2744 &client_disconnect_cb,
2735 NULL, 2745 NULL,
2736 GNUNET_MQ_hd_fixed_size(client_start, 2746 GNUNET_MQ_hd_fixed_size (client_start,
2737 GNUNET_MESSAGE_TYPE_TRANSPORT_START, 2747 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
2738 struct StartMessage, 2748 struct StartMessage,
2739 NULL), 2749 NULL),
2740 GNUNET_MQ_hd_var_size(client_hello, 2750 GNUNET_MQ_hd_var_size (client_hello,
2741 GNUNET_MESSAGE_TYPE_HELLO, 2751 GNUNET_MESSAGE_TYPE_HELLO,
2742 struct GNUNET_MessageHeader, 2752 struct GNUNET_MessageHeader,
2743 NULL), 2753 NULL),
2744 GNUNET_MQ_hd_var_size(client_send, 2754 GNUNET_MQ_hd_var_size (client_send,
2745 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 2755 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
2746 struct OutboundMessage, 2756 struct OutboundMessage,
2747 NULL), 2757 NULL),
2748 GNUNET_MQ_hd_var_size(client_address_to_string, 2758 GNUNET_MQ_hd_var_size (client_address_to_string,
2749 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 2759 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING,
2750 struct AddressLookupMessage, 2760 struct AddressLookupMessage,
2751 NULL), 2761 NULL),
2752 GNUNET_MQ_hd_fixed_size(client_monitor_peers, 2762 GNUNET_MQ_hd_fixed_size (client_monitor_peers,
2753 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, 2763 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
2754 struct PeerMonitorMessage, 2764 struct PeerMonitorMessage,
2755 NULL), 2765 NULL),
2756 GNUNET_MQ_hd_fixed_size(client_blacklist_init, 2766 GNUNET_MQ_hd_fixed_size (client_blacklist_init,
2757 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, 2767 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
2758 struct GNUNET_MessageHeader, 2768 struct GNUNET_MessageHeader,
2759 NULL), 2769 NULL),
2760 GNUNET_MQ_hd_fixed_size(client_blacklist_reply, 2770 GNUNET_MQ_hd_fixed_size (client_blacklist_reply,
2761 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, 2771 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
2762 struct BlacklistMessage, 2772 struct BlacklistMessage,
2763 NULL), 2773 NULL),
2764 GNUNET_MQ_hd_fixed_size(client_set_metric, 2774 GNUNET_MQ_hd_fixed_size (client_set_metric,
2765 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 2775 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
2766 struct TrafficMetricMessage, 2776 struct TrafficMetricMessage,
2767 NULL), 2777 NULL),
2768 GNUNET_MQ_hd_fixed_size(client_monitor_plugins, 2778 GNUNET_MQ_hd_fixed_size (client_monitor_plugins,
2769 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START, 2779 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
2770 struct GNUNET_MessageHeader, 2780 struct GNUNET_MessageHeader,
2771 NULL), 2781 NULL),
2772 GNUNET_MQ_handler_end()); 2782 GNUNET_MQ_handler_end ());
2773 2783
2774 2784
2775/* end of file gnunet-service-transport.c */ 2785/* 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;
83 */ 83 */
84typedef void 84typedef void
85(*GNUNET_TRANSPORT_NeighbourChangeCallback) (void *cls, 85(*GNUNET_TRANSPORT_NeighbourChangeCallback) (void *cls,
86 const struct GNUNET_PeerIdentity *peer, 86 const struct
87 const struct GNUNET_HELLO_Address *address, 87 GNUNET_PeerIdentity *peer,
88 enum GNUNET_TRANSPORT_PeerState state, 88 const struct
89 struct GNUNET_TIME_Absolute state_timeout, 89 GNUNET_HELLO_Address *address,
90 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 90 enum GNUNET_TRANSPORT_PeerState
91 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); 91 state,
92 struct GNUNET_TIME_Absolute
93 state_timeout,
94 struct GNUNET_BANDWIDTH_Value32NBO
95 bandwidth_in,
96 struct GNUNET_BANDWIDTH_Value32NBO
97 bandwidth_out);
92 98
93 99
94/** 100/**
@@ -117,8 +123,8 @@ typedef void
117 * @param transport_name transport to blacklist for this peer, NULL for all 123 * @param transport_name transport to blacklist for this peer, NULL for all
118 */ 124 */
119void 125void
120GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer, 126GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
121 const char *transport_name); 127 const char *transport_name);
122 128
123 129
124/** 130/**
@@ -141,12 +147,12 @@ struct GST_BlacklistCheck;
141 * was made instantly and @a cont was already called 147 * was made instantly and @a cont was already called
142 */ 148 */
143struct GST_BlacklistCheck * 149struct GST_BlacklistCheck *
144GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer, 150GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
145 const char *transport_name, 151 const char *transport_name,
146 GST_BlacklistTestContinuation cont, 152 GST_BlacklistTestContinuation cont,
147 void *cont_cls, 153 void *cont_cls,
148 const struct GNUNET_HELLO_Address *address, 154 const struct GNUNET_HELLO_Address *address,
149 struct GNUNET_ATS_Session *session); 155 struct GNUNET_ATS_Session *session);
150 156
151 157
152/** 158/**
@@ -156,8 +162,8 @@ GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer,
156 * @param session session used to abort matching checks 162 * @param session session used to abort matching checks
157 */ 163 */
158void 164void
159GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address, 165GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
160 struct GNUNET_ATS_Session *session); 166 struct GNUNET_ATS_Session *session);
161 167
162/** 168/**
163 * Cancel a blacklist check. 169 * Cancel a blacklist check.
@@ -165,7 +171,7 @@ GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address,
165 * @param bc check to cancel 171 * @param bc check to cancel
166 */ 172 */
167void 173void
168GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc); 174GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
169 175
170 176
171/** 177/**
@@ -182,10 +188,10 @@ GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc);
182 * (plugins that do not support this, can ignore the return value) 188 * (plugins that do not support this, can ignore the return value)
183 */ 189 */
184struct GNUNET_TIME_Relative 190struct GNUNET_TIME_Relative
185GST_receive_callback(void *cls, 191GST_receive_callback (void *cls,
186 const struct GNUNET_HELLO_Address *address, 192 const struct GNUNET_HELLO_Address *address,
187 struct GNUNET_ATS_Session *session, 193 struct GNUNET_ATS_Session *session,
188 const struct GNUNET_MessageHeader *message); 194 const struct GNUNET_MessageHeader *message);
189 195
190/** 196/**
191 * Broadcast the given message to all of our clients. 197 * Broadcast the given message to all of our clients.
@@ -194,8 +200,8 @@ GST_receive_callback(void *cls,
194 * @param may_drop #GNUNET_YES if the message can be dropped / is payload 200 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
195 */ 201 */
196void 202void
197GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, 203GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
198 int may_drop); 204 int may_drop);
199 205
200 206
201/** 207/**
@@ -207,10 +213,12 @@ GST_clients_broadcast(const struct GNUNET_MessageHeader *msg,
207 * @param state_timeout the time out for the state 213 * @param state_timeout the time out for the state
208 */ 214 */
209void 215void
210GST_clients_broadcast_peer_notification(const struct GNUNET_PeerIdentity *peer, 216GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
211 const struct GNUNET_HELLO_Address *address, 217 const struct
212 enum GNUNET_TRANSPORT_PeerState state, 218 GNUNET_HELLO_Address *address,
213 struct GNUNET_TIME_Absolute state_timeout); 219 enum GNUNET_TRANSPORT_PeerState state,
220 struct GNUNET_TIME_Absolute
221 state_timeout);
214 222
215 223
216/** 224/**
@@ -220,7 +228,7 @@ GST_clients_broadcast_peer_notification(const struct GNUNET_PeerIdentity *peer,
220 * @param peer peer that disconnected 228 * @param peer peer that disconnected
221 */ 229 */
222void 230void
223GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer); 231GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer);
224 232
225 233
226 234
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 @@
32/** 32/**
33 * Log convenience function. 33 * Log convenience function.
34 */ 34 */
35#define LOG(kind, ...) GNUNET_log_from(kind, "transport-ats", __VA_ARGS__) 35#define LOG(kind, ...) GNUNET_log_from (kind, "transport-ats", __VA_ARGS__)
36 36
37 37
38/** 38/**
39 * Information we track for each address known to ATS. 39 * Information we track for each address known to ATS.
40 */ 40 */
41struct AddressInfo { 41struct AddressInfo
42{
42 /** 43 /**
43 * The address (with peer identity). Must never change 44 * The address (with peer identity). Must never change
44 * while this struct is in the #p2a map. 45 * while this struct is in the #p2a map.
@@ -105,7 +106,8 @@ static unsigned int num_blocked;
105/** 106/**
106 * Closure for #find_ai_cb() and #find_ai_no_session_cb(). 107 * Closure for #find_ai_cb() and #find_ai_no_session_cb().
107 */ 108 */
108struct FindClosure { 109struct FindClosure
110{
109 /** 111 /**
110 * Session to look for (only used if the address is inbound). 112 * Session to look for (only used if the address is inbound).
111 */ 113 */
@@ -129,16 +131,16 @@ struct FindClosure {
129 * is changed. 131 * is changed.
130 */ 132 */
131static void 133static void
132publish_p2a_stat_update() 134publish_p2a_stat_update ()
133{ 135{
134 GNUNET_STATISTICS_set(GST_stats, 136 GNUNET_STATISTICS_set (GST_stats,
135 gettext_noop("# Addresses given to ATS"), 137 gettext_noop ("# Addresses given to ATS"),
136 GNUNET_CONTAINER_multipeermap_size(p2a) - num_blocked, 138 GNUNET_CONTAINER_multipeermap_size (p2a) - num_blocked,
137 GNUNET_NO); 139 GNUNET_NO);
138 GNUNET_STATISTICS_set(GST_stats, 140 GNUNET_STATISTICS_set (GST_stats,
139 "# blocked addresses", 141 "# blocked addresses",
140 num_blocked, 142 num_blocked,
141 GNUNET_NO); 143 GNUNET_NO);
142} 144}
143 145
144 146
@@ -153,21 +155,21 @@ publish_p2a_stat_update()
153 * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value 155 * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value
154 */ 156 */
155static int 157static int
156find_ai_cb(void *cls, 158find_ai_cb (void *cls,
157 const struct GNUNET_PeerIdentity *key, 159 const struct GNUNET_PeerIdentity *key,
158 void *value) 160 void *value)
159{ 161{
160 struct FindClosure *fc = cls; 162 struct FindClosure *fc = cls;
161 struct AddressInfo *ai = value; 163 struct AddressInfo *ai = value;
162 164
163 if ((0 == 165 if ((0 ==
164 GNUNET_HELLO_address_cmp(fc->address, 166 GNUNET_HELLO_address_cmp (fc->address,
165 ai->address)) && 167 ai->address)) &&
166 (fc->session == ai->session)) 168 (fc->session == ai->session))
167 { 169 {
168 fc->ret = ai; 170 fc->ret = ai;
169 return GNUNET_NO; 171 return GNUNET_NO;
170 } 172 }
171 return GNUNET_YES; 173 return GNUNET_YES;
172} 174}
173 175
@@ -181,18 +183,18 @@ find_ai_cb(void *cls,
181 * @return NULL if this combination is unknown 183 * @return NULL if this combination is unknown
182 */ 184 */
183static struct AddressInfo * 185static struct AddressInfo *
184find_ai(const struct GNUNET_HELLO_Address *address, 186find_ai (const struct GNUNET_HELLO_Address *address,
185 struct GNUNET_ATS_Session *session) 187 struct GNUNET_ATS_Session *session)
186{ 188{
187 struct FindClosure fc; 189 struct FindClosure fc;
188 190
189 fc.address = address; 191 fc.address = address;
190 fc.session = session; 192 fc.session = session;
191 fc.ret = NULL; 193 fc.ret = NULL;
192 GNUNET_CONTAINER_multipeermap_get_multiple(p2a, 194 GNUNET_CONTAINER_multipeermap_get_multiple (p2a,
193 &address->peer, 195 &address->peer,
194 &find_ai_cb, 196 &find_ai_cb,
195 &fc); 197 &fc);
196 return fc.ret; 198 return fc.ret;
197} 199}
198 200
@@ -207,9 +209,9 @@ find_ai(const struct GNUNET_HELLO_Address *address,
207 * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value 209 * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value
208 */ 210 */
209static int 211static int
210find_ai_no_session_cb(void *cls, 212find_ai_no_session_cb (void *cls,
211 const struct GNUNET_PeerIdentity *key, 213 const struct GNUNET_PeerIdentity *key,
212 void *value) 214 void *value)
213{ 215{
214 struct FindClosure *fc = cls; 216 struct FindClosure *fc = cls;
215 struct AddressInfo *ai = value; 217 struct AddressInfo *ai = value;
@@ -217,12 +219,12 @@ find_ai_no_session_cb(void *cls,
217 if (ai->expired) 219 if (ai->expired)
218 return GNUNET_YES; /* expired do not count here */ 220 return GNUNET_YES; /* expired do not count here */
219 if (0 == 221 if (0 ==
220 GNUNET_HELLO_address_cmp(fc->address, 222 GNUNET_HELLO_address_cmp (fc->address,
221 ai->address)) 223 ai->address))
222 { 224 {
223 fc->ret = ai; 225 fc->ret = ai;
224 return GNUNET_NO; 226 return GNUNET_NO;
225 } 227 }
226 return GNUNET_YES; 228 return GNUNET_YES;
227} 229}
228 230
@@ -235,17 +237,17 @@ find_ai_no_session_cb(void *cls,
235 * @return NULL if this combination is unknown 237 * @return NULL if this combination is unknown
236 */ 238 */
237static struct AddressInfo * 239static struct AddressInfo *
238find_ai_no_session(const struct GNUNET_HELLO_Address *address) 240find_ai_no_session (const struct GNUNET_HELLO_Address *address)
239{ 241{
240 struct FindClosure fc; 242 struct FindClosure fc;
241 243
242 fc.address = address; 244 fc.address = address;
243 fc.session = NULL; 245 fc.session = NULL;
244 fc.ret = NULL; 246 fc.ret = NULL;
245 GNUNET_CONTAINER_multipeermap_get_multiple(p2a, 247 GNUNET_CONTAINER_multipeermap_get_multiple (p2a,
246 &address->peer, 248 &address->peer,
247 &find_ai_no_session_cb, 249 &find_ai_no_session_cb,
248 &fc); 250 &fc);
249 return fc.ret; 251 return fc.ret;
250} 252}
251 253
@@ -260,10 +262,10 @@ find_ai_no_session(const struct GNUNET_HELLO_Address *address)
260 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not. 262 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not.
261 */ 263 */
262int 264int
263GST_ats_is_known(const struct GNUNET_HELLO_Address *address, 265GST_ats_is_known (const struct GNUNET_HELLO_Address *address,
264 struct GNUNET_ATS_Session *session) 266 struct GNUNET_ATS_Session *session)
265{ 267{
266 return (NULL != find_ai(address, session)) ? GNUNET_YES : GNUNET_NO; 268 return (NULL != find_ai (address, session)) ? GNUNET_YES : GNUNET_NO;
267} 269}
268 270
269 271
@@ -275,9 +277,9 @@ GST_ats_is_known(const struct GNUNET_HELLO_Address *address,
275 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not. 277 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not.
276 */ 278 */
277int 279int
278GST_ats_is_known_no_session(const struct GNUNET_HELLO_Address *address) 280GST_ats_is_known_no_session (const struct GNUNET_HELLO_Address *address)
279{ 281{
280 return (NULL != find_ai_no_session(address)) 282 return (NULL != find_ai_no_session (address))
281 ? GNUNET_YES 283 ? GNUNET_YES
282 : GNUNET_NO; 284 : GNUNET_NO;
283} 285}
@@ -290,22 +292,22 @@ GST_ats_is_known_no_session(const struct GNUNET_HELLO_Address *address)
290 * @param cls the `struct AddressInfo` of the address to unblock 292 * @param cls the `struct AddressInfo` of the address to unblock
291 */ 293 */
292static void 294static void
293unblock_address(void *cls) 295unblock_address (void *cls)
294{ 296{
295 struct AddressInfo *ai = cls; 297 struct AddressInfo *ai = cls;
296 298
297 ai->unblock_task = NULL; 299 ai->unblock_task = NULL;
298 LOG(GNUNET_ERROR_TYPE_DEBUG, 300 LOG (GNUNET_ERROR_TYPE_DEBUG,
299 "Unblocking address %s of peer %s\n", 301 "Unblocking address %s of peer %s\n",
300 GST_plugins_a2s(ai->address), 302 GST_plugins_a2s (ai->address),
301 GNUNET_i2s(&ai->address->peer)); 303 GNUNET_i2s (&ai->address->peer));
302 ai->ar = GNUNET_ATS_address_add(GST_ats, 304 ai->ar = GNUNET_ATS_address_add (GST_ats,
303 ai->address, 305 ai->address,
304 ai->session, 306 ai->session,
305 &ai->properties); 307 &ai->properties);
306 GNUNET_break(NULL != ai->ar); 308 GNUNET_break (NULL != ai->ar);
307 num_blocked--; 309 num_blocked--;
308 publish_p2a_stat_update(); 310 publish_p2a_stat_update ();
309} 311}
310 312
311 313
@@ -319,47 +321,47 @@ unblock_address(void *cls)
319 * @param session the session (can be NULL) 321 * @param session the session (can be NULL)
320 */ 322 */
321void 323void
322GST_ats_block_address(const struct GNUNET_HELLO_Address *address, 324GST_ats_block_address (const struct GNUNET_HELLO_Address *address,
323 struct GNUNET_ATS_Session *session) 325 struct GNUNET_ATS_Session *session)
324{ 326{
325 struct AddressInfo *ai; 327 struct AddressInfo *ai;
326 328
327 if (0 == 329 if (0 ==
328 memcmp(&GST_my_identity, 330 memcmp (&GST_my_identity,
329 &address->peer, 331 &address->peer,
330 sizeof(struct GNUNET_PeerIdentity))) 332 sizeof(struct GNUNET_PeerIdentity)))
331 return; /* our own, ignore! */ 333 return; /* our own, ignore! */
332 ai = find_ai(address, 334 ai = find_ai (address,
333 session); 335 session);
334 if (NULL == ai || NULL == ai->ar) 336 if ((NULL == ai)||(NULL == ai->ar))
335 { 337 {
336 /* The address is already gone/blocked, this can happen during a blacklist 338 /* The address is already gone/blocked, this can happen during a blacklist
337 * callback. */ 339 * callback. */
338 return; 340 return;
339 } 341 }
340 ai->back_off = GNUNET_TIME_STD_BACKOFF(ai->back_off); 342 ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off);
341 if (GNUNET_YES == 343 if (GNUNET_YES ==
342 GNUNET_HELLO_address_check_option(address, 344 GNUNET_HELLO_address_check_option (address,
343 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 345 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
344 LOG(GNUNET_ERROR_TYPE_DEBUG, 346 LOG (GNUNET_ERROR_TYPE_DEBUG,
345 "Removing address %s of peer %s from use (inbound died)\n", 347 "Removing address %s of peer %s from use (inbound died)\n",
346 GST_plugins_a2s(address), 348 GST_plugins_a2s (address),
347 GNUNET_i2s(&address->peer)); 349 GNUNET_i2s (&address->peer));
348 else 350 else
349 LOG(GNUNET_ERROR_TYPE_INFO, 351 LOG (GNUNET_ERROR_TYPE_INFO,
350 "Blocking address %s of peer %s from use for %s\n", 352 "Blocking address %s of peer %s from use for %s\n",
351 GST_plugins_a2s(address), 353 GST_plugins_a2s (address),
352 GNUNET_i2s(&address->peer), 354 GNUNET_i2s (&address->peer),
353 GNUNET_STRINGS_relative_time_to_string(ai->back_off, 355 GNUNET_STRINGS_relative_time_to_string (ai->back_off,
354 GNUNET_YES)); 356 GNUNET_YES));
355 /* destroy session and address */ 357 /* destroy session and address */
356 if ((NULL == session) || 358 if ((NULL == session) ||
357 (GNUNET_NO == 359 (GNUNET_NO ==
358 GNUNET_ATS_address_del_session(ai->ar, 360 GNUNET_ATS_address_del_session (ai->ar,
359 session))) 361 session)))
360 { 362 {
361 GNUNET_ATS_address_destroy(ai->ar); 363 GNUNET_ATS_address_destroy (ai->ar);
362 } 364 }
363 /* "ar" has been freed, regardless how the branch 365 /* "ar" has been freed, regardless how the branch
364 above played out: it was either freed in 366 above played out: it was either freed in
365 #GNUNET_ATS_address_del_session() because it was 367 #GNUNET_ATS_address_del_session() because it was
@@ -368,12 +370,12 @@ GST_ats_block_address(const struct GNUNET_HELLO_Address *address,
368 ai->ar = NULL; 370 ai->ar = NULL;
369 371
370 /* determine when the address should come back to life */ 372 /* determine when the address should come back to life */
371 ai->blocked = GNUNET_TIME_relative_to_absolute(ai->back_off); 373 ai->blocked = GNUNET_TIME_relative_to_absolute (ai->back_off);
372 ai->unblock_task = GNUNET_SCHEDULER_add_delayed(ai->back_off, 374 ai->unblock_task = GNUNET_SCHEDULER_add_delayed (ai->back_off,
373 &unblock_address, 375 &unblock_address,
374 ai); 376 ai);
375 num_blocked++; 377 num_blocked++;
376 publish_p2a_stat_update(); 378 publish_p2a_stat_update ();
377} 379}
378 380
379 381
@@ -386,24 +388,24 @@ GST_ats_block_address(const struct GNUNET_HELLO_Address *address,
386 * @param session the session (can be NULL) 388 * @param session the session (can be NULL)
387 */ 389 */
388void 390void
389GST_ats_block_reset(const struct GNUNET_HELLO_Address *address, 391GST_ats_block_reset (const struct GNUNET_HELLO_Address *address,
390 struct GNUNET_ATS_Session *session) 392 struct GNUNET_ATS_Session *session)
391{ 393{
392 struct AddressInfo *ai; 394 struct AddressInfo *ai;
393 395
394 if (0 == 396 if (0 ==
395 memcmp(&GST_my_identity, 397 memcmp (&GST_my_identity,
396 &address->peer, 398 &address->peer,
397 sizeof(struct GNUNET_PeerIdentity))) 399 sizeof(struct GNUNET_PeerIdentity)))
398 return; /* our own, ignore! */ 400 return; /* our own, ignore! */
399 ai = find_ai(address, session); 401 ai = find_ai (address, session);
400 if (NULL == ai) 402 if (NULL == ai)
401 { 403 {
402 GNUNET_break(0); 404 GNUNET_break (0);
403 return; 405 return;
404 } 406 }
405 /* address is in successful use, so it should not be blocked right now */ 407 /* address is in successful use, so it should not be blocked right now */
406 GNUNET_break(NULL == ai->unblock_task); 408 GNUNET_break (NULL == ai->unblock_task);
407 ai->back_off = GNUNET_TIME_UNIT_ZERO; 409 ai->back_off = GNUNET_TIME_UNIT_ZERO;
408} 410}
409 411
@@ -419,60 +421,60 @@ GST_ats_block_reset(const struct GNUNET_HELLO_Address *address,
419 * @param prop performance information 421 * @param prop performance information
420 */ 422 */
421void 423void
422GST_ats_add_inbound_address(const struct GNUNET_HELLO_Address *address, 424GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address,
423 struct GNUNET_ATS_Session *session, 425 struct GNUNET_ATS_Session *session,
424 const struct GNUNET_ATS_Properties *prop) 426 const struct GNUNET_ATS_Properties *prop)
425{ 427{
426 struct GNUNET_ATS_AddressRecord *ar; 428 struct GNUNET_ATS_AddressRecord *ar;
427 struct AddressInfo *ai; 429 struct AddressInfo *ai;
428 430
429 if (0 == 431 if (0 ==
430 memcmp(&GST_my_identity, 432 memcmp (&GST_my_identity,
431 &address->peer, 433 &address->peer,
432 sizeof(struct GNUNET_PeerIdentity))) 434 sizeof(struct GNUNET_PeerIdentity)))
433 return; /* our own, ignore! */ 435 return; /* our own, ignore! */
434 436
435 /* Sanity checks for a valid inbound address */ 437 /* Sanity checks for a valid inbound address */
436 if (NULL == address->transport_name) 438 if (NULL == address->transport_name)
437 { 439 {
438 GNUNET_break(0); 440 GNUNET_break (0);
439 return; 441 return;
440 } 442 }
441 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 443 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
442 GNUNET_assert(GNUNET_YES == 444 GNUNET_assert (GNUNET_YES ==
443 GNUNET_HELLO_address_check_option(address, 445 GNUNET_HELLO_address_check_option (address,
444 GNUNET_HELLO_ADDRESS_INFO_INBOUND)); 446 GNUNET_HELLO_ADDRESS_INFO_INBOUND));
445 GNUNET_assert(NULL != session); 447 GNUNET_assert (NULL != session);
446 ai = find_ai(address, session); 448 ai = find_ai (address, session);
447 if (NULL != ai) 449 if (NULL != ai)
448 { 450 {
449 /* This should only be called for new sessions, and thus 451 /* This should only be called for new sessions, and thus
450 we should not already have the address */ 452 we should not already have the address */
451 GNUNET_break(0); 453 GNUNET_break (0);
452 return; 454 return;
453 } 455 }
454 /* Is indeed new, let's tell ATS */ 456 /* Is indeed new, let's tell ATS */
455 LOG(GNUNET_ERROR_TYPE_DEBUG, 457 LOG (GNUNET_ERROR_TYPE_DEBUG,
456 "Notifying ATS about peer `%s''s new inbound address `%s' session %p in network %s\n", 458 "Notifying ATS about peer `%s''s new inbound address `%s' session %p in network %s\n",
457 GNUNET_i2s(&address->peer), 459 GNUNET_i2s (&address->peer),
458 GST_plugins_a2s(address), 460 GST_plugins_a2s (address),
459 session, 461 session,
460 GNUNET_NT_to_string(prop->scope)); 462 GNUNET_NT_to_string (prop->scope));
461 ar = GNUNET_ATS_address_add(GST_ats, 463 ar = GNUNET_ATS_address_add (GST_ats,
462 address, 464 address,
463 session, 465 session,
464 prop); 466 prop);
465 GNUNET_assert(NULL != ar); 467 GNUNET_assert (NULL != ar);
466 ai = GNUNET_new(struct AddressInfo); 468 ai = GNUNET_new (struct AddressInfo);
467 ai->address = GNUNET_HELLO_address_copy(address); 469 ai->address = GNUNET_HELLO_address_copy (address);
468 ai->session = session; 470 ai->session = session;
469 ai->properties = *prop; 471 ai->properties = *prop;
470 ai->ar = ar; 472 ai->ar = ar;
471 (void)GNUNET_CONTAINER_multipeermap_put(p2a, 473 (void) GNUNET_CONTAINER_multipeermap_put (p2a,
472 &ai->address->peer, 474 &ai->address->peer,
473 ai, 475 ai,
474 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 476 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
475 publish_p2a_stat_update(); 477 publish_p2a_stat_update ();
476} 478}
477 479
478 480
@@ -484,49 +486,49 @@ GST_ats_add_inbound_address(const struct GNUNET_HELLO_Address *address,
484 * @param prop performance information 486 * @param prop performance information
485 */ 487 */
486void 488void
487GST_ats_add_address(const struct GNUNET_HELLO_Address *address, 489GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
488 const struct GNUNET_ATS_Properties *prop) 490 const struct GNUNET_ATS_Properties *prop)
489{ 491{
490 struct GNUNET_ATS_AddressRecord *ar; 492 struct GNUNET_ATS_AddressRecord *ar;
491 struct AddressInfo *ai; 493 struct AddressInfo *ai;
492 494
493 if (0 == 495 if (0 ==
494 memcmp(&GST_my_identity, 496 memcmp (&GST_my_identity,
495 &address->peer, 497 &address->peer,
496 sizeof(struct GNUNET_PeerIdentity))) 498 sizeof(struct GNUNET_PeerIdentity)))
497 return; /* our own, ignore! */ 499 return; /* our own, ignore! */
498 /* validadte address */ 500 /* validadte address */
499 if (NULL == address->transport_name) 501 if (NULL == address->transport_name)
500 { 502 {
501 GNUNET_break(0); 503 GNUNET_break (0);
502 return; 504 return;
503 } 505 }
504 GNUNET_assert(GNUNET_YES != 506 GNUNET_assert (GNUNET_YES !=
505 GNUNET_HELLO_address_check_option(address, 507 GNUNET_HELLO_address_check_option (address,
506 GNUNET_HELLO_ADDRESS_INFO_INBOUND)); 508 GNUNET_HELLO_ADDRESS_INFO_INBOUND));
507 ai = find_ai_no_session(address); 509 ai = find_ai_no_session (address);
508 GNUNET_assert(NULL == ai); 510 GNUNET_assert (NULL == ai);
509 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 511 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
510 512
511 /* address seems sane, let's tell ATS */ 513 /* address seems sane, let's tell ATS */
512 LOG(GNUNET_ERROR_TYPE_INFO, 514 LOG (GNUNET_ERROR_TYPE_INFO,
513 "Notifying ATS about peer %s's new address `%s'\n", 515 "Notifying ATS about peer %s's new address `%s'\n",
514 GNUNET_i2s(&address->peer), 516 GNUNET_i2s (&address->peer),
515 GST_plugins_a2s(address)); 517 GST_plugins_a2s (address));
516 ar = GNUNET_ATS_address_add(GST_ats, 518 ar = GNUNET_ATS_address_add (GST_ats,
517 address, 519 address,
518 NULL, 520 NULL,
519 prop); 521 prop);
520 GNUNET_assert(NULL != ar); 522 GNUNET_assert (NULL != ar);
521 ai = GNUNET_new(struct AddressInfo); 523 ai = GNUNET_new (struct AddressInfo);
522 ai->address = GNUNET_HELLO_address_copy(address); 524 ai->address = GNUNET_HELLO_address_copy (address);
523 ai->ar = ar; 525 ai->ar = ar;
524 ai->properties = *prop; 526 ai->properties = *prop;
525 (void)GNUNET_CONTAINER_multipeermap_put(p2a, 527 (void) GNUNET_CONTAINER_multipeermap_put (p2a,
526 &ai->address->peer, 528 &ai->address->peer,
527 ai, 529 ai,
528 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 530 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
529 publish_p2a_stat_update(); 531 publish_p2a_stat_update ();
530} 532}
531 533
532 534
@@ -540,41 +542,41 @@ GST_ats_add_address(const struct GNUNET_HELLO_Address *address,
540 * @param session the session 542 * @param session the session
541 */ 543 */
542void 544void
543GST_ats_new_session(const struct GNUNET_HELLO_Address *address, 545GST_ats_new_session (const struct GNUNET_HELLO_Address *address,
544 struct GNUNET_ATS_Session *session) 546 struct GNUNET_ATS_Session *session)
545{ 547{
546 struct AddressInfo *ai; 548 struct AddressInfo *ai;
547 549
548 if (0 == 550 if (0 ==
549 memcmp(&GST_my_identity, 551 memcmp (&GST_my_identity,
550 &address->peer, 552 &address->peer,
551 sizeof(struct GNUNET_PeerIdentity))) 553 sizeof(struct GNUNET_PeerIdentity)))
552 return; /* our own, ignore! */ 554 return; /* our own, ignore! */
553 ai = find_ai(address, NULL); 555 ai = find_ai (address, NULL);
554 if (NULL == ai) 556 if (NULL == ai)
555 { 557 {
556 /* We may simply already be aware of the session, even if some 558 /* We may simply already be aware of the session, even if some
557 other part of the code could not tell if it just created a new 559 other part of the code could not tell if it just created a new
558 session or just got one recycled from the plugin; hence, we may 560 session or just got one recycled from the plugin; hence, we may
559 be called with "new" session even for an "old" session; in that 561 be called with "new" session even for an "old" session; in that
560 case, check that this is the case, but just ignore it. */ 562 case, check that this is the case, but just ignore it. */
561 GNUNET_assert(NULL != (find_ai(address, session))); 563 GNUNET_assert (NULL != (find_ai (address, session)));
562 return; 564 return;
563 } 565 }
564 GNUNET_assert(NULL == ai->session); 566 GNUNET_assert (NULL == ai->session);
565 ai->session = session; 567 ai->session = session;
566 LOG(GNUNET_ERROR_TYPE_DEBUG, 568 LOG (GNUNET_ERROR_TYPE_DEBUG,
567 "Telling ATS about new session for peer %s\n", 569 "Telling ATS about new session for peer %s\n",
568 GNUNET_i2s(&address->peer)); 570 GNUNET_i2s (&address->peer));
569 /* Note that the address might currently be blocked; we only 571 /* Note that the address might currently be blocked; we only
570 tell ATS about the session if the address is currently not 572 tell ATS about the session if the address is currently not
571 blocked; otherwise, ATS will be told about the session on 573 blocked; otherwise, ATS will be told about the session on
572 unblock. */ 574 unblock. */
573 if (NULL != ai->ar) 575 if (NULL != ai->ar)
574 GNUNET_ATS_address_add_session(ai->ar, 576 GNUNET_ATS_address_add_session (ai->ar,
575 session); 577 session);
576 else 578 else
577 GNUNET_assert(NULL != ai->unblock_task); 579 GNUNET_assert (NULL != ai->unblock_task);
578} 580}
579 581
580 582
@@ -584,30 +586,30 @@ GST_ats_new_session(const struct GNUNET_HELLO_Address *address,
584 * @param ai the `struct AddressInfo` 586 * @param ai the `struct AddressInfo`
585 */ 587 */
586static void 588static void
587destroy_ai(struct AddressInfo *ai) 589destroy_ai (struct AddressInfo *ai)
588{ 590{
589 GNUNET_assert(NULL == ai->session); 591 GNUNET_assert (NULL == ai->session);
590 if (NULL != ai->unblock_task) 592 if (NULL != ai->unblock_task)
591 { 593 {
592 GNUNET_SCHEDULER_cancel(ai->unblock_task); 594 GNUNET_SCHEDULER_cancel (ai->unblock_task);
593 ai->unblock_task = NULL; 595 ai->unblock_task = NULL;
594 num_blocked--; 596 num_blocked--;
595 } 597 }
596 GNUNET_assert(GNUNET_YES == 598 GNUNET_assert (GNUNET_YES ==
597 GNUNET_CONTAINER_multipeermap_remove(p2a, 599 GNUNET_CONTAINER_multipeermap_remove (p2a,
598 &ai->address->peer, 600 &ai->address->peer,
599 ai)); 601 ai));
600 LOG(GNUNET_ERROR_TYPE_DEBUG, 602 LOG (GNUNET_ERROR_TYPE_DEBUG,
601 "Telling ATS to destroy address from peer %s\n", 603 "Telling ATS to destroy address from peer %s\n",
602 GNUNET_i2s(&ai->address->peer)); 604 GNUNET_i2s (&ai->address->peer));
603 if (NULL != ai->ar) 605 if (NULL != ai->ar)
604 { 606 {
605 GNUNET_ATS_address_destroy(ai->ar); 607 GNUNET_ATS_address_destroy (ai->ar);
606 ai->ar = NULL; 608 ai->ar = NULL;
607 } 609 }
608 publish_p2a_stat_update(); 610 publish_p2a_stat_update ();
609 GNUNET_HELLO_address_free(ai->address); 611 GNUNET_HELLO_address_free (ai->address);
610 GNUNET_free(ai); 612 GNUNET_free (ai);
611} 613}
612 614
613 615
@@ -623,100 +625,100 @@ destroy_ai(struct AddressInfo *ai)
623 * @param session the session 625 * @param session the session
624 */ 626 */
625void 627void
626GST_ats_del_session(const struct GNUNET_HELLO_Address *address, 628GST_ats_del_session (const struct GNUNET_HELLO_Address *address,
627 struct GNUNET_ATS_Session *session) 629 struct GNUNET_ATS_Session *session)
628{ 630{
629 struct AddressInfo *ai; 631 struct AddressInfo *ai;
630 632
631 if (0 == 633 if (0 ==
632 memcmp(&GST_my_identity, 634 memcmp (&GST_my_identity,
633 &address->peer, 635 &address->peer,
634 sizeof(struct GNUNET_PeerIdentity))) 636 sizeof(struct GNUNET_PeerIdentity)))
635 return; /* our own, ignore! */ 637 return; /* our own, ignore! */
636 if (NULL == session) 638 if (NULL == session)
637 { 639 {
638 GNUNET_break(0); 640 GNUNET_break (0);
639 return; 641 return;
640 } 642 }
641 ai = find_ai(address, 643 ai = find_ai (address,
642 session); 644 session);
643 if (NULL == ai) 645 if (NULL == ai)
644 { 646 {
645 /* We sometimes create sessions just for sending a PING, 647 /* We sometimes create sessions just for sending a PING,
646 and if those are destroyed they were never known to 648 and if those are destroyed they were never known to
647 ATS which means we end up here (however, in this 649 ATS which means we end up here (however, in this
648 case, the address must be an outbound address). */ 650 case, the address must be an outbound address). */
649 GNUNET_break(GNUNET_YES != 651 GNUNET_break (GNUNET_YES !=
650 GNUNET_HELLO_address_check_option(address, 652 GNUNET_HELLO_address_check_option (address,
651 GNUNET_HELLO_ADDRESS_INFO_INBOUND)); 653 GNUNET_HELLO_ADDRESS_INFO_INBOUND));
652 return; 654 return;
653 } 655 }
654 GNUNET_assert(session == ai->session); 656 GNUNET_assert (session == ai->session);
655 ai->session = NULL; 657 ai->session = NULL;
656 LOG(GNUNET_ERROR_TYPE_DEBUG, 658 LOG (GNUNET_ERROR_TYPE_DEBUG,
657 "Telling ATS to destroy session %p from peer %s\n", 659 "Telling ATS to destroy session %p from peer %s\n",
658 session, 660 session,
659 GNUNET_i2s(&address->peer)); 661 GNUNET_i2s (&address->peer));
660 if (GNUNET_YES == ai->expired) 662 if (GNUNET_YES == ai->expired)
663 {
664 /* last reason to keep this 'ai' around is now gone, the
665 session is dead as well, clean up */
666 if (NULL != ai->ar)
661 { 667 {
662 /* last reason to keep this 'ai' around is now gone, the 668 /* Address expired but not blocked, and thus 'ar' was still
663 session is dead as well, clean up */ 669 live because of the session; deleting just the session
664 if (NULL != ai->ar) 670 will do for an inbound session, but for an outbound we
665 { 671 then also need to destroy the address with ATS. */
666 /* Address expired but not blocked, and thus 'ar' was still 672 if (GNUNET_NO ==
667 live because of the session; deleting just the session 673 GNUNET_ATS_address_del_session (ai->ar,
668 will do for an inbound session, but for an outbound we 674 session))
669 then also need to destroy the address with ATS. */ 675 {
670 if (GNUNET_NO == 676 GNUNET_ATS_address_destroy (ai->ar);
671 GNUNET_ATS_address_del_session(ai->ar, 677 }
672 session)) 678 /* "ar" has been freed, regardless how the branch
673 { 679 above played out: it was either freed in
674 GNUNET_ATS_address_destroy(ai->ar); 680 #GNUNET_ATS_address_del_session() because it was
675 } 681 incoming, or explicitly in
676 /* "ar" has been freed, regardless how the branch 682 #GNUNET_ATS_address_del_session(). */
677 above played out: it was either freed in 683 ai->ar = NULL;
678 #GNUNET_ATS_address_del_session() because it was
679 incoming, or explicitly in
680 #GNUNET_ATS_address_del_session(). */
681 ai->ar = NULL;
682 }
683 destroy_ai(ai);
684 return;
685 } 684 }
685 destroy_ai (ai);
686 return;
687 }
686 688
687 if (NULL == ai->ar) 689 if (NULL == ai->ar)
690 {
691 /* If ATS doesn't know about the address/session, this means
692 this address was blocked. */
693 if (GNUNET_YES ==
694 GNUNET_HELLO_address_check_option (address,
695 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
688 { 696 {
689 /* If ATS doesn't know about the address/session, this means 697 /* This was a blocked inbound session, which now lost the
690 this address was blocked. */ 698 session. But inbound addresses are by themselves useless,
691 if (GNUNET_YES == 699 so we must forget about the address as well. */
692 GNUNET_HELLO_address_check_option(address, 700 destroy_ai (ai);
693 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
694 {
695 /* This was a blocked inbound session, which now lost the
696 session. But inbound addresses are by themselves useless,
697 so we must forget about the address as well. */
698 destroy_ai(ai);
699 return;
700 }
701 /* Otherwise, we are done as we have set `ai->session` to NULL
702 already and ATS will simply not be told about the session when
703 the connection is unblocked and the outbound address becomes
704 available again. . */
705 return; 701 return;
706 } 702 }
703 /* Otherwise, we are done as we have set `ai->session` to NULL
704 already and ATS will simply not be told about the session when
705 the connection is unblocked and the outbound address becomes
706 available again. . */
707 return;
708 }
707 709
708 /* This is the "simple" case where ATS knows about the session and 710 /* This is the "simple" case where ATS knows about the session and
709 the address is neither blocked nor expired. Delete the session, 711 the address is neither blocked nor expired. Delete the session,
710 and if it was inbound, free the address as well. */ 712 and if it was inbound, free the address as well. */
711 if (GNUNET_YES == 713 if (GNUNET_YES ==
712 GNUNET_ATS_address_del_session(ai->ar, 714 GNUNET_ATS_address_del_session (ai->ar,
713 session)) 715 session))
714 { 716 {
715 /* This was an inbound address, the session is now gone, so we 717 /* This was an inbound address, the session is now gone, so we
716 need to also forget about the address itself. */ 718 need to also forget about the address itself. */
717 ai->ar = NULL; 719 ai->ar = NULL;
718 destroy_ai(ai); 720 destroy_ai (ai);
719 } 721 }
720} 722}
721 723
722 724
@@ -728,31 +730,31 @@ GST_ats_del_session(const struct GNUNET_HELLO_Address *address,
728 * @param distance new distance value 730 * @param distance new distance value
729 */ 731 */
730void 732void
731GST_ats_update_distance(const struct GNUNET_HELLO_Address *address, 733GST_ats_update_distance (const struct GNUNET_HELLO_Address *address,
732 uint32_t distance) 734 uint32_t distance)
733{ 735{
734 struct AddressInfo *ai; 736 struct AddressInfo *ai;
735 737
736 ai = find_ai_no_session(address); 738 ai = find_ai_no_session (address);
737 if (NULL == ai) 739 if (NULL == ai)
738 { 740 {
739 /* We do not know about this address, do nothing. */ 741 /* We do not know about this address, do nothing. */
740 return; 742 return;
741 } 743 }
742 LOG(GNUNET_ERROR_TYPE_DEBUG, 744 LOG (GNUNET_ERROR_TYPE_DEBUG,
743 "Updated distance for peer `%s' to %u\n", 745 "Updated distance for peer `%s' to %u\n",
744 GNUNET_i2s(&address->peer), 746 GNUNET_i2s (&address->peer),
745 distance); 747 distance);
746 ai->properties.distance = distance; 748 ai->properties.distance = distance;
747 /* Give manipulation its chance to change metrics */ 749 /* Give manipulation its chance to change metrics */
748 GST_manipulation_manipulate_metrics(address, 750 GST_manipulation_manipulate_metrics (address,
749 ai->session, 751 ai->session,
750 &ai->properties); 752 &ai->properties);
751 /* Address may be blocked, only give ATS if address is 753 /* Address may be blocked, only give ATS if address is
752 currently active. */ 754 currently active. */
753 if (NULL != ai->ar) 755 if (NULL != ai->ar)
754 GNUNET_ATS_address_update(ai->ar, 756 GNUNET_ATS_address_update (ai->ar,
755 &ai->properties); 757 &ai->properties);
756} 758}
757 759
758 760
@@ -764,32 +766,32 @@ GST_ats_update_distance(const struct GNUNET_HELLO_Address *address,
764 * @param delay new delay value 766 * @param delay new delay value
765 */ 767 */
766void 768void
767GST_ats_update_delay(const struct GNUNET_HELLO_Address *address, 769GST_ats_update_delay (const struct GNUNET_HELLO_Address *address,
768 struct GNUNET_TIME_Relative delay) 770 struct GNUNET_TIME_Relative delay)
769{ 771{
770 struct AddressInfo *ai; 772 struct AddressInfo *ai;
771 773
772 ai = find_ai_no_session(address); 774 ai = find_ai_no_session (address);
773 if (NULL == ai) 775 if (NULL == ai)
774 { 776 {
775 /* We do not know about this address, do nothing. */ 777 /* We do not know about this address, do nothing. */
776 return; 778 return;
777 } 779 }
778 LOG(GNUNET_ERROR_TYPE_DEBUG, 780 LOG (GNUNET_ERROR_TYPE_DEBUG,
779 "Updated latency for peer `%s' to %s\n", 781 "Updated latency for peer `%s' to %s\n",
780 GNUNET_i2s(&address->peer), 782 GNUNET_i2s (&address->peer),
781 GNUNET_STRINGS_relative_time_to_string(delay, 783 GNUNET_STRINGS_relative_time_to_string (delay,
782 GNUNET_YES)); 784 GNUNET_YES));
783 ai->properties.delay = delay; 785 ai->properties.delay = delay;
784 /* Give manipulation its chance to change metrics */ 786 /* Give manipulation its chance to change metrics */
785 GST_manipulation_manipulate_metrics(address, 787 GST_manipulation_manipulate_metrics (address,
786 ai->session, 788 ai->session,
787 &ai->properties); 789 &ai->properties);
788 /* Address may be blocked, only give ATS if address is 790 /* Address may be blocked, only give ATS if address is
789 currently active. */ 791 currently active. */
790 if (NULL != ai->ar) 792 if (NULL != ai->ar)
791 GNUNET_ATS_address_update(ai->ar, 793 GNUNET_ATS_address_update (ai->ar,
792 &ai->properties); 794 &ai->properties);
793} 795}
794 796
795 797
@@ -802,35 +804,35 @@ GST_ats_update_delay(const struct GNUNET_HELLO_Address *address,
802 * @param bps_out new utilization outbound 804 * @param bps_out new utilization outbound
803 */ 805 */
804void 806void
805GST_ats_update_utilization(const struct GNUNET_HELLO_Address *address, 807GST_ats_update_utilization (const struct GNUNET_HELLO_Address *address,
806 uint32_t bps_in, 808 uint32_t bps_in,
807 uint32_t bps_out) 809 uint32_t bps_out)
808{ 810{
809 struct AddressInfo *ai; 811 struct AddressInfo *ai;
810 812
811 ai = find_ai_no_session(address); 813 ai = find_ai_no_session (address);
812 if (NULL == ai) 814 if (NULL == ai)
813 { 815 {
814 /* We do not know about this address, do nothing. */ 816 /* We do not know about this address, do nothing. */
815 return; 817 return;
816 } 818 }
817 LOG(GNUNET_ERROR_TYPE_DEBUG, 819 LOG (GNUNET_ERROR_TYPE_DEBUG,
818 "Updating utilization for peer `%s' address %s: %u/%u\n", 820 "Updating utilization for peer `%s' address %s: %u/%u\n",
819 GNUNET_i2s(&address->peer), 821 GNUNET_i2s (&address->peer),
820 GST_plugins_a2s(address), 822 GST_plugins_a2s (address),
821 (unsigned int)bps_in, 823 (unsigned int) bps_in,
822 (unsigned int)bps_out); 824 (unsigned int) bps_out);
823 ai->properties.utilization_in = bps_in; 825 ai->properties.utilization_in = bps_in;
824 ai->properties.utilization_out = bps_out; 826 ai->properties.utilization_out = bps_out;
825 /* Give manipulation its chance to change metrics */ 827 /* Give manipulation its chance to change metrics */
826 GST_manipulation_manipulate_metrics(address, 828 GST_manipulation_manipulate_metrics (address,
827 ai->session, 829 ai->session,
828 &ai->properties); 830 &ai->properties);
829 /* Address may be blocked, only give ATS if address is 831 /* Address may be blocked, only give ATS if address is
830 currently active. */ 832 currently active. */
831 if (NULL != ai->ar) 833 if (NULL != ai->ar)
832 GNUNET_ATS_address_update(ai->ar, 834 GNUNET_ATS_address_update (ai->ar,
833 &ai->properties); 835 &ai->properties);
834} 836}
835 837
836 838
@@ -842,34 +844,34 @@ GST_ats_update_utilization(const struct GNUNET_HELLO_Address *address,
842 * @param address the address 844 * @param address the address
843 */ 845 */
844void 846void
845GST_ats_expire_address(const struct GNUNET_HELLO_Address *address) 847GST_ats_expire_address (const struct GNUNET_HELLO_Address *address)
846{ 848{
847 struct AddressInfo *ai; 849 struct AddressInfo *ai;
848 850
849 if (0 == 851 if (0 ==
850 memcmp(&GST_my_identity, 852 memcmp (&GST_my_identity,
851 &address->peer, 853 &address->peer,
852 sizeof(struct GNUNET_PeerIdentity))) 854 sizeof(struct GNUNET_PeerIdentity)))
853 return; /* our own, ignore! */ 855 return; /* our own, ignore! */
854 LOG(GNUNET_ERROR_TYPE_DEBUG, 856 LOG (GNUNET_ERROR_TYPE_DEBUG,
855 "Address %s of peer %s expired\n", 857 "Address %s of peer %s expired\n",
856 GST_plugins_a2s(address), 858 GST_plugins_a2s (address),
857 GNUNET_i2s(&address->peer)); 859 GNUNET_i2s (&address->peer));
858 ai = find_ai_no_session(address); 860 ai = find_ai_no_session (address);
859 if (NULL == ai) 861 if (NULL == ai)
860 { 862 {
861 GNUNET_assert(0); 863 GNUNET_assert (0);
862 return; 864 return;
863 } 865 }
864 if (NULL != ai->session) 866 if (NULL != ai->session)
865 { 867 {
866 /* Got an active session, just remember the expiration 868 /* Got an active session, just remember the expiration
867 and act upon it when the session goes down. */ 869 and act upon it when the session goes down. */
868 ai->expired = GNUNET_YES; 870 ai->expired = GNUNET_YES;
869 return; 871 return;
870 } 872 }
871 /* Address expired, no session, free resources */ 873 /* Address expired, no session, free resources */
872 destroy_ai(ai); 874 destroy_ai (ai);
873} 875}
874 876
875 877
@@ -877,9 +879,9 @@ GST_ats_expire_address(const struct GNUNET_HELLO_Address *address)
877 * Initialize ATS subsystem. 879 * Initialize ATS subsystem.
878 */ 880 */
879void 881void
880GST_ats_init() 882GST_ats_init ()
881{ 883{
882 p2a = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_YES); 884 p2a = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_YES);
883} 885}
884 886
885 887
@@ -892,13 +894,13 @@ GST_ats_init()
892 * @return #GNUNET_OK (continue to iterate) 894 * @return #GNUNET_OK (continue to iterate)
893 */ 895 */
894static int 896static int
895destroy_ai_cb(void *cls, 897destroy_ai_cb (void *cls,
896 const struct GNUNET_PeerIdentity *key, 898 const struct GNUNET_PeerIdentity *key,
897 void *value) 899 void *value)
898{ 900{
899 struct AddressInfo *ai = value; 901 struct AddressInfo *ai = value;
900 902
901 destroy_ai(ai); 903 destroy_ai (ai);
902 return GNUNET_OK; 904 return GNUNET_OK;
903} 905}
904 906
@@ -907,13 +909,13 @@ destroy_ai_cb(void *cls,
907 * Shutdown ATS subsystem. 909 * Shutdown ATS subsystem.
908 */ 910 */
909void 911void
910GST_ats_done() 912GST_ats_done ()
911{ 913{
912 GNUNET_CONTAINER_multipeermap_iterate(p2a, 914 GNUNET_CONTAINER_multipeermap_iterate (p2a,
913 &destroy_ai_cb, 915 &destroy_ai_cb,
914 NULL); 916 NULL);
915 publish_p2a_stat_update(); 917 publish_p2a_stat_update ();
916 GNUNET_CONTAINER_multipeermap_destroy(p2a); 918 GNUNET_CONTAINER_multipeermap_destroy (p2a);
917 p2a = NULL; 919 p2a = NULL;
918} 920}
919 921
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 @@
31 * Initialize ATS subsystem. 31 * Initialize ATS subsystem.
32 */ 32 */
33void 33void
34GST_ats_init(void); 34GST_ats_init (void);
35 35
36 36
37/** 37/**
38 * Shutdown ATS subsystem. 38 * Shutdown ATS subsystem.
39 */ 39 */
40void 40void
41GST_ats_done(void); 41GST_ats_done (void);
42 42
43 43
44/** 44/**
@@ -51,8 +51,8 @@ GST_ats_done(void);
51 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not. 51 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not.
52 */ 52 */
53int 53int
54GST_ats_is_known(const struct GNUNET_HELLO_Address *address, 54GST_ats_is_known (const struct GNUNET_HELLO_Address *address,
55 struct GNUNET_ATS_Session *session); 55 struct GNUNET_ATS_Session *session);
56 56
57 57
58/** 58/**
@@ -63,7 +63,7 @@ GST_ats_is_known(const struct GNUNET_HELLO_Address *address,
63 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not. 63 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not.
64 */ 64 */
65int 65int
66GST_ats_is_known_no_session(const struct GNUNET_HELLO_Address *address); 66GST_ats_is_known_no_session (const struct GNUNET_HELLO_Address *address);
67 67
68 68
69/** 69/**
@@ -76,8 +76,8 @@ GST_ats_is_known_no_session(const struct GNUNET_HELLO_Address *address);
76 * @param session the session (can be NULL) 76 * @param session the session (can be NULL)
77 */ 77 */
78void 78void
79GST_ats_block_address(const struct GNUNET_HELLO_Address *address, 79GST_ats_block_address (const struct GNUNET_HELLO_Address *address,
80 struct GNUNET_ATS_Session *session); 80 struct GNUNET_ATS_Session *session);
81 81
82 82
83/** 83/**
@@ -89,8 +89,8 @@ GST_ats_block_address(const struct GNUNET_HELLO_Address *address,
89 * @param session the session (can be NULL) 89 * @param session the session (can be NULL)
90 */ 90 */
91void 91void
92GST_ats_block_reset(const struct GNUNET_HELLO_Address *address, 92GST_ats_block_reset (const struct GNUNET_HELLO_Address *address,
93 struct GNUNET_ATS_Session *session); 93 struct GNUNET_ATS_Session *session);
94 94
95 95
96/** 96/**
@@ -104,9 +104,9 @@ GST_ats_block_reset(const struct GNUNET_HELLO_Address *address,
104 * @param prop performance information 104 * @param prop performance information
105 */ 105 */
106void 106void
107GST_ats_add_inbound_address(const struct GNUNET_HELLO_Address *address, 107GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address,
108 struct GNUNET_ATS_Session *session, 108 struct GNUNET_ATS_Session *session,
109 const struct GNUNET_ATS_Properties *prop); 109 const struct GNUNET_ATS_Properties *prop);
110 110
111 111
112/** 112/**
@@ -117,8 +117,8 @@ GST_ats_add_inbound_address(const struct GNUNET_HELLO_Address *address,
117 * @param prop performance information 117 * @param prop performance information
118 */ 118 */
119void 119void
120GST_ats_add_address(const struct GNUNET_HELLO_Address *address, 120GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
121 const struct GNUNET_ATS_Properties *prop); 121 const struct GNUNET_ATS_Properties *prop);
122 122
123 123
124/** 124/**
@@ -131,8 +131,8 @@ GST_ats_add_address(const struct GNUNET_HELLO_Address *address,
131 * @param session the session 131 * @param session the session
132 */ 132 */
133void 133void
134GST_ats_new_session(const struct GNUNET_HELLO_Address *address, 134GST_ats_new_session (const struct GNUNET_HELLO_Address *address,
135 struct GNUNET_ATS_Session *session); 135 struct GNUNET_ATS_Session *session);
136 136
137 137
138/** 138/**
@@ -144,9 +144,9 @@ GST_ats_new_session(const struct GNUNET_HELLO_Address *address,
144 * @param bps_out new utilization outbound 144 * @param bps_out new utilization outbound
145 */ 145 */
146void 146void
147GST_ats_update_utilization(const struct GNUNET_HELLO_Address *address, 147GST_ats_update_utilization (const struct GNUNET_HELLO_Address *address,
148 uint32_t bps_in, 148 uint32_t bps_in,
149 uint32_t bps_out); 149 uint32_t bps_out);
150 150
151 151
152/** 152/**
@@ -158,8 +158,8 @@ GST_ats_update_utilization(const struct GNUNET_HELLO_Address *address,
158 * @param delay new delay value 158 * @param delay new delay value
159 */ 159 */
160void 160void
161GST_ats_update_delay(const struct GNUNET_HELLO_Address *address, 161GST_ats_update_delay (const struct GNUNET_HELLO_Address *address,
162 struct GNUNET_TIME_Relative delay); 162 struct GNUNET_TIME_Relative delay);
163 163
164 164
165/** 165/**
@@ -170,8 +170,8 @@ GST_ats_update_delay(const struct GNUNET_HELLO_Address *address,
170 * @param distance new distance value 170 * @param distance new distance value
171 */ 171 */
172void 172void
173GST_ats_update_distance(const struct GNUNET_HELLO_Address *address, 173GST_ats_update_distance (const struct GNUNET_HELLO_Address *address,
174 uint32_t distance); 174 uint32_t distance);
175 175
176 176
177/** 177/**
@@ -186,8 +186,8 @@ GST_ats_update_distance(const struct GNUNET_HELLO_Address *address,
186 * @param session the session 186 * @param session the session
187 */ 187 */
188void 188void
189GST_ats_del_session(const struct GNUNET_HELLO_Address *address, 189GST_ats_del_session (const struct GNUNET_HELLO_Address *address,
190 struct GNUNET_ATS_Session *session); 190 struct GNUNET_ATS_Session *session);
191 191
192 192
193/** 193/**
@@ -198,7 +198,7 @@ GST_ats_del_session(const struct GNUNET_HELLO_Address *address,
198 * @param address the address 198 * @param address the address
199 */ 199 */
200void 200void
201GST_ats_expire_address(const struct GNUNET_HELLO_Address *address); 201GST_ats_expire_address (const struct GNUNET_HELLO_Address *address);
202 202
203 203
204#endif 204#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 @@
36/** 36/**
37 * How often do we refresh our HELLO (due to expiration concerns)? 37 * How often do we refresh our HELLO (due to expiration concerns)?
38 */ 38 */
39#define HELLO_REFRESH_PERIOD GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 6) 39#define HELLO_REFRESH_PERIOD GNUNET_TIME_relative_multiply ( \
40 GNUNET_TIME_UNIT_HOURS, 6)
40 41
41/** 42/**
42 * Hello address expiration 43 * Hello address expiration
@@ -48,7 +49,8 @@ extern struct GNUNET_TIME_Relative hello_expiration;
48 * Entry in linked list of network addresses for ourselves. Also 49 * Entry in linked list of network addresses for ourselves. Also
49 * includes a cached signature for 'struct TransportPongMessage's. 50 * includes a cached signature for 'struct TransportPongMessage's.
50 */ 51 */
51struct OwnAddressList { 52struct OwnAddressList
53{
52 /** 54 /**
53 * This is a doubly-linked list. 55 * This is a doubly-linked list.
54 */ 56 */
@@ -123,7 +125,8 @@ static struct GNUNET_SCHEDULER_Task *hello_task;
123/** 125/**
124 * Closure for #address_generator(). 126 * Closure for #address_generator().
125 */ 127 */
126struct GeneratorContext { 128struct GeneratorContext
129{
127 /** 130 /**
128 * Where are we in the DLL? 131 * Where are we in the DLL?
129 */ 132 */
@@ -146,19 +149,19 @@ struct GeneratorContext {
146 * end of the iteration. 149 * end of the iteration.
147 */ 150 */
148static ssize_t 151static ssize_t
149address_generator(void *cls, 152address_generator (void *cls,
150 size_t max, 153 size_t max,
151 void *buf) 154 void *buf)
152{ 155{
153 struct GeneratorContext *gc = cls; 156 struct GeneratorContext *gc = cls;
154 ssize_t ret; 157 ssize_t ret;
155 158
156 if (NULL == gc->addr_pos) 159 if (NULL == gc->addr_pos)
157 return GNUNET_SYSERR; /* Done */ 160 return GNUNET_SYSERR; /* Done */
158 ret = GNUNET_HELLO_add_address(gc->addr_pos->address, 161 ret = GNUNET_HELLO_add_address (gc->addr_pos->address,
159 gc->expiration, 162 gc->expiration,
160 buf, 163 buf,
161 max); 164 max);
162 gc->addr_pos = gc->addr_pos->next; 165 gc->addr_pos = gc->addr_pos->next;
163 return ret; 166 return ret;
164} 167}
@@ -171,38 +174,38 @@ address_generator(void *cls,
171 * @param cls unused 174 * @param cls unused
172 */ 175 */
173static void 176static void
174refresh_hello_task(void *cls) 177refresh_hello_task (void *cls)
175{ 178{
176 struct GeneratorContext gc; 179 struct GeneratorContext gc;
177 180
178 hello_task = NULL; 181 hello_task = NULL;
179 gc.addr_pos = oal_head; 182 gc.addr_pos = oal_head;
180 gc.expiration = GNUNET_TIME_relative_to_absolute(hello_expiration); 183 gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration);
181 184
182 GNUNET_free_non_null(our_hello); 185 GNUNET_free_non_null (our_hello);
183 our_hello = GNUNET_HELLO_create(&GST_my_identity.public_key, 186 our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key,
184 &address_generator, 187 &address_generator,
185 &gc, 188 &gc,
186 friend_option); 189 friend_option);
187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188 "Refreshed my %s HELLO, new size is %d\n", 191 "Refreshed my %s HELLO, new size is %d\n",
189 (GNUNET_YES == friend_option) ? "friend-only" : "public", 192 (GNUNET_YES == friend_option) ? "friend-only" : "public",
190 GNUNET_HELLO_size(our_hello)); 193 GNUNET_HELLO_size (our_hello));
191 GNUNET_STATISTICS_update(GST_stats, 194 GNUNET_STATISTICS_update (GST_stats,
192 gettext_noop("# refreshed my HELLO"), 195 gettext_noop ("# refreshed my HELLO"),
193 1, 196 1,
194 GNUNET_NO); 197 GNUNET_NO);
195 if (NULL != hello_cb) 198 if (NULL != hello_cb)
196 hello_cb(hello_cb_cls, 199 hello_cb (hello_cb_cls,
197 GST_hello_get()); 200 GST_hello_get ());
198 GNUNET_PEERINFO_add_peer(GST_peerinfo, 201 GNUNET_PEERINFO_add_peer (GST_peerinfo,
199 our_hello, 202 our_hello,
200 NULL, 203 NULL,
201 NULL); 204 NULL);
202 hello_task = 205 hello_task =
203 GNUNET_SCHEDULER_add_delayed(HELLO_REFRESH_PERIOD, 206 GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD,
204 &refresh_hello_task, 207 &refresh_hello_task,
205 NULL); 208 NULL);
206} 209}
207 210
208 211
@@ -212,14 +215,14 @@ refresh_hello_task(void *cls)
212 * have been shutdown). 215 * have been shutdown).
213 */ 216 */
214static void 217static void
215refresh_hello() 218refresh_hello ()
216{ 219{
217 if (NULL != hello_task) 220 if (NULL != hello_task)
218 { 221 {
219 GNUNET_SCHEDULER_cancel(hello_task); 222 GNUNET_SCHEDULER_cancel (hello_task);
220 hello_task = GNUNET_SCHEDULER_add_now(&refresh_hello_task, 223 hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task,
221 NULL); 224 NULL);
222 } 225 }
223} 226}
224 227
225 228
@@ -231,14 +234,14 @@ refresh_hello()
231 * @param cb_cls closure for @a cb 234 * @param cb_cls closure for @a cb
232 */ 235 */
233void 236void
234GST_hello_start(int friend_only, 237GST_hello_start (int friend_only,
235 GST_HelloCallback cb, 238 GST_HelloCallback cb,
236 void *cb_cls) 239 void *cb_cls)
237{ 240{
238 hello_cb = cb; 241 hello_cb = cb;
239 hello_cb_cls = cb_cls; 242 hello_cb_cls = cb_cls;
240 friend_option = friend_only; 243 friend_option = friend_only;
241 refresh_hello_task(NULL); 244 refresh_hello_task (NULL);
242} 245}
243 246
244 247
@@ -246,20 +249,20 @@ GST_hello_start(int friend_only,
246 * Shutdown the HELLO module. 249 * Shutdown the HELLO module.
247 */ 250 */
248void 251void
249GST_hello_stop() 252GST_hello_stop ()
250{ 253{
251 hello_cb = NULL; 254 hello_cb = NULL;
252 hello_cb_cls = NULL; 255 hello_cb_cls = NULL;
253 if (NULL != hello_task) 256 if (NULL != hello_task)
254 { 257 {
255 GNUNET_SCHEDULER_cancel(hello_task); 258 GNUNET_SCHEDULER_cancel (hello_task);
256 hello_task = NULL; 259 hello_task = NULL;
257 } 260 }
258 if (NULL != our_hello) 261 if (NULL != our_hello)
259 { 262 {
260 GNUNET_free(our_hello); 263 GNUNET_free (our_hello);
261 our_hello = NULL; 264 our_hello = NULL;
262 } 265 }
263} 266}
264 267
265 268
@@ -269,9 +272,9 @@ GST_hello_stop()
269 * @return our HELLO message 272 * @return our HELLO message
270 */ 273 */
271const struct GNUNET_MessageHeader * 274const struct GNUNET_MessageHeader *
272GST_hello_get() 275GST_hello_get ()
273{ 276{
274 return (const struct GNUNET_MessageHeader *)our_hello; 277 return (const struct GNUNET_MessageHeader *) our_hello;
275} 278}
276 279
277 280
@@ -282,52 +285,52 @@ GST_hello_get()
282 * @param address address to add or remove 285 * @param address address to add or remove
283 */ 286 */
284void 287void
285GST_hello_modify_addresses(int addremove, 288GST_hello_modify_addresses (int addremove,
286 const struct GNUNET_HELLO_Address *address) 289 const struct GNUNET_HELLO_Address *address)
287{ 290{
288 struct OwnAddressList *al; 291 struct OwnAddressList *al;
289 292
290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
291 (GNUNET_YES == addremove) 294 (GNUNET_YES == addremove)
292 ? "Adding `%s' to the set of our addresses\n" 295 ? "Adding `%s' to the set of our addresses\n"
293 : "Removing `%s' from the set of our addresses\n", 296 : "Removing `%s' from the set of our addresses\n",
294 GST_plugins_a2s(address)); 297 GST_plugins_a2s (address));
295 GNUNET_assert(NULL != address); 298 GNUNET_assert (NULL != address);
296 for (al = oal_head; al != NULL; al = al->next) 299 for (al = oal_head; al != NULL; al = al->next)
297 if (0 == GNUNET_HELLO_address_cmp(address, al->address)) 300 if (0 == GNUNET_HELLO_address_cmp (address, al->address))
298 break; 301 break;
299 if (GNUNET_NO == addremove) 302 if (GNUNET_NO == addremove)
303 {
304 if (NULL == al)
300 { 305 {
301 if (NULL == al) 306 /* address to be removed not found!? */
302 { 307 GNUNET_break (0);
303 /* address to be removed not found!? */
304 GNUNET_break(0);
305 return;
306 }
307 al->rc--;
308 if (0 != al->rc)
309 return; /* RC not yet zero */
310 GNUNET_CONTAINER_DLL_remove(oal_head,
311 oal_tail,
312 al);
313 GNUNET_HELLO_address_free(al->address);
314 GNUNET_free(al);
315 refresh_hello();
316 return; 308 return;
317 } 309 }
310 al->rc--;
311 if (0 != al->rc)
312 return; /* RC not yet zero */
313 GNUNET_CONTAINER_DLL_remove (oal_head,
314 oal_tail,
315 al);
316 GNUNET_HELLO_address_free (al->address);
317 GNUNET_free (al);
318 refresh_hello ();
319 return;
320 }
318 if (NULL != al) 321 if (NULL != al)
319 { 322 {
320 /* address added twice or more */ 323 /* address added twice or more */
321 al->rc++; 324 al->rc++;
322 return; 325 return;
323 } 326 }
324 al = GNUNET_new(struct OwnAddressList); 327 al = GNUNET_new (struct OwnAddressList);
325 al->rc = 1; 328 al->rc = 1;
326 GNUNET_CONTAINER_DLL_insert(oal_head, 329 GNUNET_CONTAINER_DLL_insert (oal_head,
327 oal_tail, 330 oal_tail,
328 al); 331 al);
329 al->address = GNUNET_HELLO_address_copy(address); 332 al->address = GNUNET_HELLO_address_copy (address);
330 refresh_hello(); 333 refresh_hello ();
331} 334}
332 335
333 336
@@ -342,20 +345,20 @@ GST_hello_modify_addresses(int addremove,
342 * #GNUNET_NO if not 345 * #GNUNET_NO if not
343 */ 346 */
344int 347int
345GST_hello_test_address(const struct GNUNET_HELLO_Address *address, 348GST_hello_test_address (const struct GNUNET_HELLO_Address *address,
346 struct GNUNET_CRYPTO_EddsaSignature **sig, 349 struct GNUNET_CRYPTO_EddsaSignature **sig,
347 struct GNUNET_TIME_Absolute **sig_expiration) 350 struct GNUNET_TIME_Absolute **sig_expiration)
348{ 351{
349 struct OwnAddressList *al; 352 struct OwnAddressList *al;
350 353
351 for (al = oal_head; al != NULL; al = al->next) 354 for (al = oal_head; al != NULL; al = al->next)
352 if (0 == GNUNET_HELLO_address_cmp(address, 355 if (0 == GNUNET_HELLO_address_cmp (address,
353 al->address)) 356 al->address))
354 { 357 {
355 *sig = &al->pong_signature; 358 *sig = &al->pong_signature;
356 *sig_expiration = &al->pong_sig_expires; 359 *sig_expiration = &al->pong_sig_expires;
357 return GNUNET_YES; 360 return GNUNET_YES;
358 } 361 }
359 *sig = NULL; 362 *sig = NULL;
360 *sig_expiration = NULL; 363 *sig_expiration = NULL;
361 return GNUNET_NO; 364 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
50 * @param cb_cls closure for @a cb 50 * @param cb_cls closure for @a cb
51 */ 51 */
52void 52void
53GST_hello_start(int friend_only, 53GST_hello_start (int friend_only,
54 GST_HelloCallback cb, 54 GST_HelloCallback cb,
55 void *cb_cls); 55 void *cb_cls);
56 56
57 57
58/** 58/**
59 * Shutdown the HELLO module. 59 * Shutdown the HELLO module.
60 */ 60 */
61void 61void
62GST_hello_stop(void); 62GST_hello_stop (void);
63 63
64 64
65/** 65/**
@@ -68,7 +68,7 @@ GST_hello_stop(void);
68 * @return our HELLO message 68 * @return our HELLO message
69 */ 69 */
70const struct GNUNET_MessageHeader * 70const struct GNUNET_MessageHeader *
71GST_hello_get(void); 71GST_hello_get (void);
72 72
73 73
74/** 74/**
@@ -78,8 +78,8 @@ GST_hello_get(void);
78 * @param address address to add or remove 78 * @param address address to add or remove
79 */ 79 */
80void 80void
81GST_hello_modify_addresses(int addremove, 81GST_hello_modify_addresses (int addremove,
82 const struct GNUNET_HELLO_Address *address); 82 const struct GNUNET_HELLO_Address *address);
83 83
84 84
85/** 85/**
@@ -93,9 +93,9 @@ GST_hello_modify_addresses(int addremove,
93 * #GNUNET_NO if not 93 * #GNUNET_NO if not
94 */ 94 */
95int 95int
96GST_hello_test_address(const struct GNUNET_HELLO_Address *address, 96GST_hello_test_address (const struct GNUNET_HELLO_Address *address,
97 struct GNUNET_CRYPTO_EddsaSignature **sig, 97 struct GNUNET_CRYPTO_EddsaSignature **sig,
98 struct GNUNET_TIME_Absolute **sig_expiration); 98 struct GNUNET_TIME_Absolute **sig_expiration);
99 99
100 100
101#endif 101#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 @@
36/** 36/**
37 * Struct containing information about manipulations to a specific peer 37 * Struct containing information about manipulations to a specific peer
38 */ 38 */
39struct TM_Peer { 39struct TM_Peer
40{
40 /** 41 /**
41 * Peer ID 42 * Peer ID
42 */ 43 */
@@ -77,7 +78,8 @@ struct TM_Peer {
77/** 78/**
78 * Entry in the delay queue for an outbound delayed message 79 * Entry in the delay queue for an outbound delayed message
79 */ 80 */
80struct DelayQueueEntry { 81struct DelayQueueEntry
82{
81 /** 83 /**
82 * Next in DLL 84 * Next in DLL
83 */ 85 */
@@ -169,39 +171,39 @@ static struct GNUNET_SCHEDULER_Task *generic_send_delay_task;
169 * @param message containing information 171 * @param message containing information
170 */ 172 */
171void 173void
172GST_manipulation_set_metric(const struct TrafficMetricMessage *tm) 174GST_manipulation_set_metric (const struct TrafficMetricMessage *tm)
173{ 175{
174 static struct GNUNET_PeerIdentity zero; 176 static struct GNUNET_PeerIdentity zero;
175 struct TM_Peer *tmp; 177 struct TM_Peer *tmp;
176 178
177 if (0 == memcmp(&tm->peer, 179 if (0 == memcmp (&tm->peer,
178 &zero, 180 &zero,
179 sizeof(struct GNUNET_PeerIdentity))) 181 sizeof(struct GNUNET_PeerIdentity)))
180 { 182 {
181 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
182 "Received traffic metrics for all peers\n"); 184 "Received traffic metrics for all peers\n");
183 delay_in = GNUNET_TIME_relative_ntoh(tm->delay_in); 185 delay_in = GNUNET_TIME_relative_ntoh (tm->delay_in);
184 delay_out = GNUNET_TIME_relative_ntoh(tm->delay_out); 186 delay_out = GNUNET_TIME_relative_ntoh (tm->delay_out);
185 return; 187 return;
186 } 188 }
187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188 "Received traffic metrics for peer `%s'\n", 190 "Received traffic metrics for peer `%s'\n",
189 GNUNET_i2s(&tm->peer)); 191 GNUNET_i2s (&tm->peer));
190 if (NULL == 192 if (NULL ==
191 (tmp = GNUNET_CONTAINER_multipeermap_get(peers, 193 (tmp = GNUNET_CONTAINER_multipeermap_get (peers,
192 &tm->peer))) 194 &tm->peer)))
193 { 195 {
194 tmp = GNUNET_new(struct TM_Peer); 196 tmp = GNUNET_new (struct TM_Peer);
195 tmp->peer = tm->peer; 197 tmp->peer = tm->peer;
196 GNUNET_CONTAINER_multipeermap_put(peers, 198 GNUNET_CONTAINER_multipeermap_put (peers,
197 &tm->peer, 199 &tm->peer,
198 tmp, 200 tmp,
199 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 201 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
200 } 202 }
201 GNUNET_ATS_properties_ntoh(&tmp->properties, 203 GNUNET_ATS_properties_ntoh (&tmp->properties,
202 &tm->properties); 204 &tm->properties);
203 tmp->delay_in = GNUNET_TIME_relative_ntoh(tm->delay_in); 205 tmp->delay_in = GNUNET_TIME_relative_ntoh (tm->delay_in);
204 tmp->delay_out = GNUNET_TIME_relative_ntoh(tm->delay_out); 206 tmp->delay_out = GNUNET_TIME_relative_ntoh (tm->delay_out);
205} 207}
206 208
207 209
@@ -212,52 +214,52 @@ GST_manipulation_set_metric(const struct TrafficMetricMessage *tm)
212 * @param cls the `struct DelayQueueEntry` to transmit 214 * @param cls the `struct DelayQueueEntry` to transmit
213 */ 215 */
214static void 216static void
215send_delayed(void *cls) 217send_delayed (void *cls)
216{ 218{
217 struct DelayQueueEntry *dqe = cls; 219 struct DelayQueueEntry *dqe = cls;
218 struct DelayQueueEntry *next; 220 struct DelayQueueEntry *next;
219 struct TM_Peer *tmp = dqe->tmp; 221 struct TM_Peer *tmp = dqe->tmp;
220 222
221 GNUNET_break(GNUNET_YES == 223 GNUNET_break (GNUNET_YES ==
222 GST_neighbours_test_connected(&dqe->id)); 224 GST_neighbours_test_connected (&dqe->id));
223 if (NULL != tmp) 225 if (NULL != tmp)
226 {
227 tmp->send_delay_task = NULL;
228 GNUNET_CONTAINER_DLL_remove (tmp->send_head,
229 tmp->send_tail,
230 dqe);
231 next = tmp->send_head;
232 if (NULL != next)
224 { 233 {
225 tmp->send_delay_task = NULL; 234 /* More delayed messages */
226 GNUNET_CONTAINER_DLL_remove(tmp->send_head, 235 tmp->send_delay_task = GNUNET_SCHEDULER_add_at (next->sent_at,
227 tmp->send_tail, 236 &send_delayed,
228 dqe); 237 next);
229 next = tmp->send_head;
230 if (NULL != next)
231 {
232 /* More delayed messages */
233 tmp->send_delay_task = GNUNET_SCHEDULER_add_at(next->sent_at,
234 &send_delayed,
235 next);
236 }
237 } 238 }
239 }
238 else 240 else
241 {
242 /* Remove from generic queue */
243 generic_send_delay_task = NULL;
244 GNUNET_CONTAINER_DLL_remove (generic_dqe_head,
245 generic_dqe_tail,
246 dqe);
247 next = generic_dqe_head;
248 if (NULL != next)
239 { 249 {
240 /* Remove from generic queue */ 250 /* More delayed messages */
241 generic_send_delay_task = NULL; 251 generic_send_delay_task = GNUNET_SCHEDULER_add_at (next->sent_at,
242 GNUNET_CONTAINER_DLL_remove(generic_dqe_head, 252 &send_delayed,
243 generic_dqe_tail, 253 next);
244 dqe);
245 next = generic_dqe_head;
246 if (NULL != next)
247 {
248 /* More delayed messages */
249 generic_send_delay_task = GNUNET_SCHEDULER_add_at(next->sent_at,
250 &send_delayed,
251 next);
252 }
253 } 254 }
254 GST_neighbours_send(&dqe->id, 255 }
255 dqe->msg, 256 GST_neighbours_send (&dqe->id,
256 dqe->msg_size, 257 dqe->msg,
257 dqe->timeout, 258 dqe->msg_size,
258 dqe->cont, 259 dqe->timeout,
259 dqe->cont_cls); 260 dqe->cont,
260 GNUNET_free(dqe); 261 dqe->cont_cls);
262 GNUNET_free (dqe);
261} 263}
262 264
263 265
@@ -273,71 +275,71 @@ send_delayed(void *cls)
273 * @param cont_cls cls for @a cont 275 * @param cont_cls cls for @a cont
274 */ 276 */
275void 277void
276GST_manipulation_send(const struct GNUNET_PeerIdentity *target, 278GST_manipulation_send (const struct GNUNET_PeerIdentity *target,
277 const void *msg, 279 const void *msg,
278 size_t msg_size, 280 size_t msg_size,
279 struct GNUNET_TIME_Relative timeout, 281 struct GNUNET_TIME_Relative timeout,
280 GST_NeighbourSendContinuation cont, 282 GST_NeighbourSendContinuation cont,
281 void *cont_cls) 283 void *cont_cls)
282{ 284{
283 struct TM_Peer *tmp; 285 struct TM_Peer *tmp;
284 struct DelayQueueEntry *dqe; 286 struct DelayQueueEntry *dqe;
285 struct GNUNET_TIME_Relative delay; 287 struct GNUNET_TIME_Relative delay;
286 288
287 if (NULL != (tmp = 289 if (NULL != (tmp =
288 GNUNET_CONTAINER_multipeermap_get(peers, 290 GNUNET_CONTAINER_multipeermap_get (peers,
289 target))) 291 target)))
290 delay = tmp->delay_out; 292 delay = tmp->delay_out;
291 else 293 else
292 delay = delay_out; 294 delay = delay_out;
293 if (0 == delay.rel_value_us) 295 if (0 == delay.rel_value_us)
294 { 296 {
295 /* Normal sending */ 297 /* Normal sending */
296 GST_neighbours_send(target, 298 GST_neighbours_send (target,
297 msg, 299 msg,
298 msg_size, 300 msg_size,
299 timeout, 301 timeout,
300 cont, cont_cls); 302 cont, cont_cls);
301 return; 303 return;
302 } 304 }
303 dqe = GNUNET_malloc(sizeof(struct DelayQueueEntry) + msg_size); 305 dqe = GNUNET_malloc (sizeof(struct DelayQueueEntry) + msg_size);
304 dqe->id = *target; 306 dqe->id = *target;
305 dqe->tmp = tmp; 307 dqe->tmp = tmp;
306 dqe->sent_at = GNUNET_TIME_relative_to_absolute(delay); 308 dqe->sent_at = GNUNET_TIME_relative_to_absolute (delay);
307 dqe->cont = cont; 309 dqe->cont = cont;
308 dqe->cont_cls = cont_cls; 310 dqe->cont_cls = cont_cls;
309 dqe->msg = &dqe[1]; 311 dqe->msg = &dqe[1];
310 dqe->msg_size = msg_size; 312 dqe->msg_size = msg_size;
311 dqe->timeout = timeout; 313 dqe->timeout = timeout;
312 GNUNET_memcpy(dqe->msg, 314 GNUNET_memcpy (dqe->msg,
313 msg, 315 msg,
314 msg_size); 316 msg_size);
315 if (NULL == tmp) 317 if (NULL == tmp)
316 { 318 {
317 GNUNET_CONTAINER_DLL_insert_tail(generic_dqe_head, 319 GNUNET_CONTAINER_DLL_insert_tail (generic_dqe_head,
318 generic_dqe_tail, 320 generic_dqe_tail,
319 dqe); 321 dqe);
320 if (NULL == generic_send_delay_task) 322 if (NULL == generic_send_delay_task)
321 generic_send_delay_task = GNUNET_SCHEDULER_add_delayed(delay, 323 generic_send_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
322 &send_delayed, 324 &send_delayed,
323 dqe); 325 dqe);
324 } 326 }
325 else 327 else
326 { 328 {
327 GNUNET_CONTAINER_DLL_insert_tail(tmp->send_head, 329 GNUNET_CONTAINER_DLL_insert_tail (tmp->send_head,
328 tmp->send_tail, 330 tmp->send_tail,
329 dqe); 331 dqe);
330 if (NULL == tmp->send_delay_task) 332 if (NULL == tmp->send_delay_task)
331 tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed(delay, 333 tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
332 &send_delayed, 334 &send_delayed,
333 dqe); 335 dqe);
334 } 336 }
335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "Delaying %u byte message to peer `%s' with peer specific delay for %s\n", 338 "Delaying %u byte message to peer `%s' with peer specific delay for %s\n",
337 (unsigned int)msg_size, 339 (unsigned int) msg_size,
338 GNUNET_i2s(target), 340 GNUNET_i2s (target),
339 GNUNET_STRINGS_relative_time_to_string(delay, 341 GNUNET_STRINGS_relative_time_to_string (delay,
340 GNUNET_YES)); 342 GNUNET_YES));
341} 343}
342 344
343 345
@@ -350,15 +352,15 @@ GST_manipulation_send(const struct GNUNET_PeerIdentity *target,
350 * @param prop[IN|OUT] metrics to modify 352 * @param prop[IN|OUT] metrics to modify
351 */ 353 */
352void 354void
353GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address, 355GST_manipulation_manipulate_metrics (const struct GNUNET_HELLO_Address *address,
354 struct GNUNET_ATS_Session *session, 356 struct GNUNET_ATS_Session *session,
355 struct GNUNET_ATS_Properties *prop) 357 struct GNUNET_ATS_Properties *prop)
356{ 358{
357 const struct GNUNET_PeerIdentity *peer = &address->peer; 359 const struct GNUNET_PeerIdentity *peer = &address->peer;
358 struct TM_Peer *tmp; 360 struct TM_Peer *tmp;
359 361
360 tmp = GNUNET_CONTAINER_multipeermap_get(peers, 362 tmp = GNUNET_CONTAINER_multipeermap_get (peers,
361 peer); 363 peer);
362 if (NULL != tmp) 364 if (NULL != tmp)
363 *prop = tmp->properties; 365 *prop = tmp->properties;
364} 366}
@@ -375,33 +377,33 @@ GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address,
375 * @return manipulated delay for next receive 377 * @return manipulated delay for next receive
376 */ 378 */
377struct GNUNET_TIME_Relative 379struct GNUNET_TIME_Relative
378GST_manipulation_recv(void *cls, 380GST_manipulation_recv (void *cls,
379 const struct GNUNET_HELLO_Address *address, 381 const struct GNUNET_HELLO_Address *address,
380 struct GNUNET_ATS_Session *session, 382 struct GNUNET_ATS_Session *session,
381 const struct GNUNET_MessageHeader *message) 383 const struct GNUNET_MessageHeader *message)
382{ 384{
383 struct TM_Peer *tmp; 385 struct TM_Peer *tmp;
384 struct GNUNET_TIME_Relative quota_delay; 386 struct GNUNET_TIME_Relative quota_delay;
385 struct GNUNET_TIME_Relative m_delay; 387 struct GNUNET_TIME_Relative m_delay;
386 388
387 if (NULL != 389 if (NULL !=
388 (tmp = GNUNET_CONTAINER_multipeermap_get(peers, 390 (tmp = GNUNET_CONTAINER_multipeermap_get (peers,
389 &address->peer))) 391 &address->peer)))
390 m_delay = tmp->delay_in; 392 m_delay = tmp->delay_in;
391 else 393 else
392 m_delay = delay_in; 394 m_delay = delay_in;
393 395
394 quota_delay = GST_receive_callback(cls, 396 quota_delay = GST_receive_callback (cls,
395 address, 397 address,
396 session, 398 session,
397 message); 399 message);
398 m_delay = GNUNET_TIME_relative_max(m_delay, 400 m_delay = GNUNET_TIME_relative_max (m_delay,
399 quota_delay); 401 quota_delay);
400 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
401 "Delaying next receive for peer `%s' for %s\n", 403 "Delaying next receive for peer `%s' for %s\n",
402 GNUNET_i2s(&address->peer), 404 GNUNET_i2s (&address->peer),
403 GNUNET_STRINGS_relative_time_to_string(m_delay, 405 GNUNET_STRINGS_relative_time_to_string (m_delay,
404 GNUNET_YES)); 406 GNUNET_YES));
405 return m_delay; 407 return m_delay;
406} 408}
407 409
@@ -410,38 +412,38 @@ GST_manipulation_recv(void *cls,
410 * Initialize traffic manipulation 412 * Initialize traffic manipulation
411 */ 413 */
412void 414void
413GST_manipulation_init() 415GST_manipulation_init ()
414{ 416{
415 struct GNUNET_TIME_Relative delay; 417 struct GNUNET_TIME_Relative delay;
416 418
417 if ((GNUNET_OK == 419 if ((GNUNET_OK ==
418 GNUNET_CONFIGURATION_get_value_time(GST_cfg, 420 GNUNET_CONFIGURATION_get_value_time (GST_cfg,
419 "transport", 421 "transport",
420 "MANIPULATE_DELAY_IN", 422 "MANIPULATE_DELAY_IN",
421 &delay)) && 423 &delay)) &&
422 (delay.rel_value_us > 0)) 424 (delay.rel_value_us > 0))
423 { 425 {
424 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 426 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
425 "Delaying inbound traffic for %s\n", 427 "Delaying inbound traffic for %s\n",
426 GNUNET_STRINGS_relative_time_to_string(delay, 428 GNUNET_STRINGS_relative_time_to_string (delay,
427 GNUNET_YES)); 429 GNUNET_YES));
428 delay_in = delay; 430 delay_in = delay;
429 } 431 }
430 if ((GNUNET_OK == 432 if ((GNUNET_OK ==
431 GNUNET_CONFIGURATION_get_value_time(GST_cfg, 433 GNUNET_CONFIGURATION_get_value_time (GST_cfg,
432 "transport", 434 "transport",
433 "MANIPULATE_DELAY_OUT", 435 "MANIPULATE_DELAY_OUT",
434 &delay)) && 436 &delay)) &&
435 (delay.rel_value_us > 0)) 437 (delay.rel_value_us > 0))
436 { 438 {
437 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 439 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
438 "Delaying outbound traffic for %s\n", 440 "Delaying outbound traffic for %s\n",
439 GNUNET_STRINGS_relative_time_to_string(delay, 441 GNUNET_STRINGS_relative_time_to_string (delay,
440 GNUNET_YES)); 442 GNUNET_YES));
441 delay_out = delay; 443 delay_out = delay;
442 } 444 }
443 peers = GNUNET_CONTAINER_multipeermap_create(4, 445 peers = GNUNET_CONTAINER_multipeermap_create (4,
444 GNUNET_NO); 446 GNUNET_NO);
445} 447}
446 448
447 449
@@ -451,58 +453,58 @@ GST_manipulation_init()
451 * @param peer the disconnecting peer 453 * @param peer the disconnecting peer
452 */ 454 */
453void 455void
454GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer) 456GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer)
455{ 457{
456 struct TM_Peer *tmp; 458 struct TM_Peer *tmp;
457 struct DelayQueueEntry *dqe; 459 struct DelayQueueEntry *dqe;
458 struct DelayQueueEntry *next; 460 struct DelayQueueEntry *next;
459 461
460 tmp = GNUNET_CONTAINER_multipeermap_get(peers, 462 tmp = GNUNET_CONTAINER_multipeermap_get (peers,
461 peer); 463 peer);
462 if (NULL != tmp) 464 if (NULL != tmp)
465 {
466 while (NULL != (dqe = tmp->send_head))
463 { 467 {
464 while (NULL != (dqe = tmp->send_head)) 468 GNUNET_CONTAINER_DLL_remove (tmp->send_head,
465 { 469 tmp->send_tail,
466 GNUNET_CONTAINER_DLL_remove(tmp->send_head, 470 dqe);
467 tmp->send_tail, 471 if (NULL != dqe->cont)
468 dqe); 472 dqe->cont (dqe->cont_cls,
469 if (NULL != dqe->cont) 473 GNUNET_SYSERR,
470 dqe->cont(dqe->cont_cls, 474 dqe->msg_size,
471 GNUNET_SYSERR, 475 0);
472 dqe->msg_size, 476 GNUNET_free (dqe);
473 0);
474 GNUNET_free(dqe);
475 }
476 } 477 }
478 }
477 next = generic_dqe_head; 479 next = generic_dqe_head;
478 while (NULL != (dqe = next)) 480 while (NULL != (dqe = next))
481 {
482 next = dqe->next;
483 if (0 == memcmp (peer,
484 &dqe->id,
485 sizeof(dqe->id)))
479 { 486 {
480 next = dqe->next; 487 GNUNET_CONTAINER_DLL_remove (generic_dqe_head,
481 if (0 == memcmp(peer, 488 generic_dqe_tail,
482 &dqe->id, 489 dqe);
483 sizeof(dqe->id))) 490 if (NULL != dqe->cont)
484 { 491 dqe->cont (dqe->cont_cls,
485 GNUNET_CONTAINER_DLL_remove(generic_dqe_head, 492 GNUNET_SYSERR,
486 generic_dqe_tail, 493 dqe->msg_size,
487 dqe); 494 0);
488 if (NULL != dqe->cont) 495 GNUNET_free (dqe);
489 dqe->cont(dqe->cont_cls,
490 GNUNET_SYSERR,
491 dqe->msg_size,
492 0);
493 GNUNET_free(dqe);
494 }
495 } 496 }
497 }
496 if (NULL != generic_send_delay_task) 498 if (NULL != generic_send_delay_task)
497 { 499 {
498 GNUNET_SCHEDULER_cancel(generic_send_delay_task); 500 GNUNET_SCHEDULER_cancel (generic_send_delay_task);
499 generic_send_delay_task = NULL; 501 generic_send_delay_task = NULL;
500 if (NULL != generic_dqe_head) 502 if (NULL != generic_dqe_head)
501 generic_send_delay_task 503 generic_send_delay_task
502 = GNUNET_SCHEDULER_add_at(generic_dqe_head->sent_at, 504 = GNUNET_SCHEDULER_add_at (generic_dqe_head->sent_at,
503 &send_delayed, 505 &send_delayed,
504 generic_dqe_head); 506 generic_dqe_head);
505 } 507 }
506} 508}
507 509
508 510
@@ -515,35 +517,35 @@ GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer)
515 * @return #GNUNET_OK (continue to iterate) 517 * @return #GNUNET_OK (continue to iterate)
516 */ 518 */
517static int 519static int
518free_tmps(void *cls, 520free_tmps (void *cls,
519 const struct GNUNET_PeerIdentity *key, 521 const struct GNUNET_PeerIdentity *key,
520 void *value) 522 void *value)
521{ 523{
522 struct TM_Peer *tmp = value; 524 struct TM_Peer *tmp = value;
523 struct DelayQueueEntry *dqe; 525 struct DelayQueueEntry *dqe;
524 526
525 GNUNET_break(GNUNET_YES == 527 GNUNET_break (GNUNET_YES ==
526 GNUNET_CONTAINER_multipeermap_remove(peers, 528 GNUNET_CONTAINER_multipeermap_remove (peers,
527 key, 529 key,
528 value)); 530 value));
529 while (NULL != (dqe = tmp->send_head)) 531 while (NULL != (dqe = tmp->send_head))
530 { 532 {
531 GNUNET_CONTAINER_DLL_remove(tmp->send_head, 533 GNUNET_CONTAINER_DLL_remove (tmp->send_head,
532 tmp->send_tail, 534 tmp->send_tail,
533 dqe); 535 dqe);
534 if (NULL != dqe->cont) 536 if (NULL != dqe->cont)
535 dqe->cont(dqe->cont_cls, 537 dqe->cont (dqe->cont_cls,
536 GNUNET_SYSERR, 538 GNUNET_SYSERR,
537 dqe->msg_size, 539 dqe->msg_size,
538 0); 540 0);
539 GNUNET_free(dqe); 541 GNUNET_free (dqe);
540 } 542 }
541 if (NULL != tmp->send_delay_task) 543 if (NULL != tmp->send_delay_task)
542 { 544 {
543 GNUNET_SCHEDULER_cancel(tmp->send_delay_task); 545 GNUNET_SCHEDULER_cancel (tmp->send_delay_task);
544 tmp->send_delay_task = NULL; 546 tmp->send_delay_task = NULL;
545 } 547 }
546 GNUNET_free(tmp); 548 GNUNET_free (tmp);
547 return GNUNET_OK; 549 return GNUNET_OK;
548} 550}
549 551
@@ -552,32 +554,32 @@ free_tmps(void *cls,
552 * Stop traffic manipulation 554 * Stop traffic manipulation
553 */ 555 */
554void 556void
555GST_manipulation_stop() 557GST_manipulation_stop ()
556{ 558{
557 struct DelayQueueEntry *cur; 559 struct DelayQueueEntry *cur;
558 560
559 GNUNET_CONTAINER_multipeermap_iterate(peers, 561 GNUNET_CONTAINER_multipeermap_iterate (peers,
560 &free_tmps, 562 &free_tmps,
561 NULL); 563 NULL);
562 GNUNET_CONTAINER_multipeermap_destroy(peers); 564 GNUNET_CONTAINER_multipeermap_destroy (peers);
563 peers = NULL; 565 peers = NULL;
564 while (NULL != (cur = generic_dqe_head)) 566 while (NULL != (cur = generic_dqe_head))
565 { 567 {
566 GNUNET_CONTAINER_DLL_remove(generic_dqe_head, 568 GNUNET_CONTAINER_DLL_remove (generic_dqe_head,
567 generic_dqe_tail, 569 generic_dqe_tail,
568 cur); 570 cur);
569 if (NULL != cur->cont) 571 if (NULL != cur->cont)
570 cur->cont(cur->cont_cls, 572 cur->cont (cur->cont_cls,
571 GNUNET_SYSERR, 573 GNUNET_SYSERR,
572 cur->msg_size, 574 cur->msg_size,
573 0); 575 0);
574 GNUNET_free(cur); 576 GNUNET_free (cur);
575 } 577 }
576 if (NULL != generic_send_delay_task) 578 if (NULL != generic_send_delay_task)
577 { 579 {
578 GNUNET_SCHEDULER_cancel(generic_send_delay_task); 580 GNUNET_SCHEDULER_cancel (generic_send_delay_task);
579 generic_send_delay_task = NULL; 581 generic_send_delay_task = NULL;
580 } 582 }
581} 583}
582 584
583/* end of file gnunet-service-transport_manipulation.c */ 585/* 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 @@
42 * @param message containing information 42 * @param message containing information
43 */ 43 */
44void 44void
45GST_manipulation_set_metric(const struct TrafficMetricMessage *tm); 45GST_manipulation_set_metric (const struct TrafficMetricMessage *tm);
46 46
47 47
48/** 48/**
@@ -56,12 +56,12 @@ GST_manipulation_set_metric(const struct TrafficMetricMessage *tm);
56 * @param cont_cls cls for continuation 56 * @param cont_cls cls for continuation
57 */ 57 */
58void 58void
59GST_manipulation_send(const struct GNUNET_PeerIdentity *target, 59GST_manipulation_send (const struct GNUNET_PeerIdentity *target,
60 const void *msg, 60 const void *msg,
61 size_t msg_size, 61 size_t msg_size,
62 struct GNUNET_TIME_Relative timeout, 62 struct GNUNET_TIME_Relative timeout,
63 GST_NeighbourSendContinuation cont, 63 GST_NeighbourSendContinuation cont,
64 void *cont_cls); 64 void *cont_cls);
65 65
66 66
67/** 67/**
@@ -75,10 +75,10 @@ GST_manipulation_send(const struct GNUNET_PeerIdentity *target,
75 * @return manipulated delay for next receive 75 * @return manipulated delay for next receive
76 */ 76 */
77struct GNUNET_TIME_Relative 77struct GNUNET_TIME_Relative
78GST_manipulation_recv(void *cls, 78GST_manipulation_recv (void *cls,
79 const struct GNUNET_HELLO_Address *address, 79 const struct GNUNET_HELLO_Address *address,
80 struct GNUNET_ATS_Session *session, 80 struct GNUNET_ATS_Session *session,
81 const struct GNUNET_MessageHeader *message); 81 const struct GNUNET_MessageHeader *message);
82 82
83 83
84/** 84/**
@@ -90,9 +90,9 @@ GST_manipulation_recv(void *cls,
90 * @param prop[IN|OUT] metrics to modify 90 * @param prop[IN|OUT] metrics to modify
91 */ 91 */
92void 92void
93GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address, 93GST_manipulation_manipulate_metrics (const struct GNUNET_HELLO_Address *address,
94 struct GNUNET_ATS_Session *session, 94 struct GNUNET_ATS_Session *session,
95 struct GNUNET_ATS_Properties *prop); 95 struct GNUNET_ATS_Properties *prop);
96 96
97 97
98/** 98/**
@@ -101,21 +101,21 @@ GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address,
101 * @param peer the disconnecting peer 101 * @param peer the disconnecting peer
102 */ 102 */
103void 103void
104GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer); 104GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer);
105 105
106 106
107/** 107/**
108 * Initialize traffic manipulation 108 * Initialize traffic manipulation
109 */ 109 */
110void 110void
111GST_manipulation_init(void); 111GST_manipulation_init (void);
112 112
113 113
114/** 114/**
115 * Stop traffic manipulation 115 * Stop traffic manipulation
116 */ 116 */
117void 117void
118GST_manipulation_stop(void); 118GST_manipulation_stop (void);
119 119
120#endif 120#endif
121/* end of file gnunet-service-transport_neighbours.h */ 121/* 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 @@
50 * Time we give plugin to transmit DISCONNECT message before the 50 * Time we give plugin to transmit DISCONNECT message before the
51 * neighbour entry self-destructs. 51 * neighbour entry self-destructs.
52 */ 52 */
53#define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) 53#define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply ( \
54 GNUNET_TIME_UNIT_MILLISECONDS, 500)
54 55
55/** 56/**
56 * How often must a peer violate bandwidth quotas before we start 57 * How often must a peer violate bandwidth quotas before we start
@@ -61,13 +62,15 @@
61/** 62/**
62 * How long are we willing to wait for a response from ATS before timing out? 63 * How long are we willing to wait for a response from ATS before timing out?
63 */ 64 */
64#define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 65#define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply ( \
66 GNUNET_TIME_UNIT_SECONDS, 5)
65 67
66/** 68/**
67 * How long are we willing to wait for an ACK from the other peer before 69 * How long are we willing to wait for an ACK from the other peer before
68 * giving up on our connect operation? 70 * giving up on our connect operation?
69 */ 71 */
70#define SETUP_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 72#define SETUP_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply ( \
73 GNUNET_TIME_UNIT_SECONDS, 15)
71 74
72/** 75/**
73 * How long are we willing to wait for a successful reconnect if 76 * How long are we willing to wait for a successful reconnect if
@@ -85,7 +88,8 @@
85/** 88/**
86 * State describing which kind a reply this neighbour should send 89 * State describing which kind a reply this neighbour should send
87 */ 90 */
88enum GST_ACK_State { 91enum GST_ACK_State
92{
89 /** 93 /**
90 * We did not receive a SYN message for this neighbour 94 * We did not receive a SYN message for this neighbour
91 */ 95 */
@@ -115,7 +119,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
115 * a 'ACK'. Once the 'ACK' is received, both peers 119 * a 'ACK'. Once the 'ACK' is received, both peers
116 * should be connected. 120 * should be connected.
117 */ 121 */
118struct TransportSynMessage { 122struct TransportSynMessage
123{
119 /** 124 /**
120 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN 125 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN
121 * or #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK 126 * or #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK
@@ -143,7 +148,8 @@ struct TransportSynMessage {
143 * When the keep alive response with type is received, transport service 148 * When the keep alive response with type is received, transport service
144 * will call the respective plugin to update the session timeout 149 * will call the respective plugin to update the session timeout
145 */ 150 */
146struct GNUNET_ATS_SessionKeepAliveMessage { 151struct GNUNET_ATS_SessionKeepAliveMessage
152{
147 /** 153 /**
148 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE or 154 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE or
149 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE. 155 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE.
@@ -162,7 +168,8 @@ struct GNUNET_ATS_SessionKeepAliveMessage {
162 * the other peer should limit transmissions to the indicated 168 * the other peer should limit transmissions to the indicated
163 * quota. 169 * quota.
164 */ 170 */
165struct GNUNET_ATS_SessionQuotaMessage { 171struct GNUNET_ATS_SessionQuotaMessage
172{
166 /** 173 /**
167 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA. 174 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA.
168 */ 175 */
@@ -181,7 +188,8 @@ struct GNUNET_ATS_SessionQuotaMessage {
181 * notification, peers must not rely on always receiving disconnect 188 * notification, peers must not rely on always receiving disconnect
182 * messages. 189 * messages.
183 */ 190 */
184struct GNUNET_ATS_SessionDisconnectMessage { 191struct GNUNET_ATS_SessionDisconnectMessage
192{
185 /** 193 /**
186 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT 194 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT
187 */ 195 */
@@ -224,7 +232,8 @@ GNUNET_NETWORK_STRUCT_END
224 * For each neighbour we keep a list of messages 232 * For each neighbour we keep a list of messages
225 * that we still want to transmit to the neighbour. 233 * that we still want to transmit to the neighbour.
226 */ 234 */
227struct MessageQueue { 235struct MessageQueue
236{
228 /** 237 /**
229 * This is a doubly linked list. 238 * This is a doubly linked list.
230 */ 239 */
@@ -266,7 +275,8 @@ struct MessageQueue {
266/** 275/**
267 * A possible address we could use to communicate with a neighbour. 276 * A possible address we could use to communicate with a neighbour.
268 */ 277 */
269struct NeighbourAddress { 278struct NeighbourAddress
279{
270 /** 280 /**
271 * Active session for this address. 281 * Active session for this address.
272 */ 282 */
@@ -309,7 +319,8 @@ struct NeighbourAddress {
309/** 319/**
310 * Entry in neighbours. 320 * Entry in neighbours.
311 */ 321 */
312struct NeighbourMapEntry { 322struct NeighbourMapEntry
323{
313 /** 324 /**
314 * Head of list of messages we would like to send to this peer; 325 * Head of list of messages we would like to send to this peer;
315 * must contain at most one message per client. 326 * must contain at most one message per client.
@@ -483,23 +494,23 @@ static struct GNUNET_SCHEDULER_Task *util_transmission_tk;
483 * @return corresponding human-readable string 494 * @return corresponding human-readable string
484 */ 495 */
485static char * 496static char *
486print_ack_state(enum GST_ACK_State s) 497print_ack_state (enum GST_ACK_State s)
487{ 498{
488 switch (s) 499 switch (s)
489 { 500 {
490 case ACK_UNDEFINED: 501 case ACK_UNDEFINED:
491 return "UNDEFINED"; 502 return "UNDEFINED";
492 503
493 case ACK_SEND_SYN_ACK: 504 case ACK_SEND_SYN_ACK:
494 return "SEND_SYN_ACK"; 505 return "SEND_SYN_ACK";
495 506
496 case ACK_SEND_ACK: 507 case ACK_SEND_ACK:
497 return "SEND_ACK"; 508 return "SEND_ACK";
498 509
499 default: 510 default:
500 GNUNET_break(0); 511 GNUNET_break (0);
501 return "N/A"; 512 return "N/A";
502 } 513 }
503} 514}
504 515
505 516
@@ -511,30 +522,30 @@ print_ack_state(enum GST_ACK_State s)
511 * @param n affected peer 522 * @param n affected peer
512 */ 523 */
513static void 524static void
514send_outbound_quota_to_clients(struct NeighbourMapEntry *n) 525send_outbound_quota_to_clients (struct NeighbourMapEntry *n)
515{ 526{
516 struct QuotaSetMessage q_msg; 527 struct QuotaSetMessage q_msg;
517 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min; 528 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
518 529
519 if (!GNUNET_TRANSPORT_is_connected(n->state)) 530 if (! GNUNET_TRANSPORT_is_connected (n->state))
520 return; 531 return;
521#if IGNORE_INBOUND_QUOTA 532#if IGNORE_INBOUND_QUOTA
522 bandwidth_min = n->primary_address.bandwidth_out; 533 bandwidth_min = n->primary_address.bandwidth_out;
523#else 534#else
524 bandwidth_min = GNUNET_BANDWIDTH_value_min(n->primary_address.bandwidth_out, 535 bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out,
525 n->neighbour_receive_quota); 536 n->neighbour_receive_quota);
526#endif 537#endif
527 538
528 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
529 "Sending outbound quota of %u Bps for peer `%s' to all clients\n", 540 "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
530 ntohl(bandwidth_min.value__), 541 ntohl (bandwidth_min.value__),
531 GNUNET_i2s(&n->id)); 542 GNUNET_i2s (&n->id));
532 q_msg.header.size = htons(sizeof(struct QuotaSetMessage)); 543 q_msg.header.size = htons (sizeof(struct QuotaSetMessage));
533 q_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 544 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
534 q_msg.quota = bandwidth_min; 545 q_msg.quota = bandwidth_min;
535 q_msg.peer = n->id; 546 q_msg.peer = n->id;
536 GST_clients_broadcast(&q_msg.header, 547 GST_clients_broadcast (&q_msg.header,
537 GNUNET_NO); 548 GNUNET_NO);
538} 549}
539 550
540 551
@@ -544,28 +555,28 @@ send_outbound_quota_to_clients(struct NeighbourMapEntry *n)
544 * @param n the peer that connected 555 * @param n the peer that connected
545 */ 556 */
546static void 557static void
547neighbours_connect_notification(struct NeighbourMapEntry *n) 558neighbours_connect_notification (struct NeighbourMapEntry *n)
548{ 559{
549 size_t len = sizeof(struct ConnectInfoMessage); 560 size_t len = sizeof(struct ConnectInfoMessage);
550 char buf[len] GNUNET_ALIGN; 561 char buf[len] GNUNET_ALIGN;
551 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *)buf; 562 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
552 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min; 563 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
553 564
554#if IGNORE_INBOUND_QUOTA 565#if IGNORE_INBOUND_QUOTA
555 bandwidth_min = n->primary_address.bandwidth_out; 566 bandwidth_min = n->primary_address.bandwidth_out;
556#else 567#else
557 bandwidth_min = GNUNET_BANDWIDTH_value_min(n->primary_address.bandwidth_out, 568 bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out,
558 n->neighbour_receive_quota); 569 n->neighbour_receive_quota);
559#endif 570#endif
560 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 571 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
561 "We are now connected to peer `%s'\n", 572 "We are now connected to peer `%s'\n",
562 GNUNET_i2s(&n->id)); 573 GNUNET_i2s (&n->id));
563 connect_msg->header.size = htons(sizeof(buf)); 574 connect_msg->header.size = htons (sizeof(buf));
564 connect_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 575 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
565 connect_msg->id = n->id; 576 connect_msg->id = n->id;
566 connect_msg->quota_out = bandwidth_min; 577 connect_msg->quota_out = bandwidth_min;
567 GST_clients_broadcast(&connect_msg->header, 578 GST_clients_broadcast (&connect_msg->header,
568 GNUNET_NO); 579 GNUNET_NO);
569} 580}
570 581
571 582
@@ -576,13 +587,13 @@ neighbours_connect_notification(struct NeighbourMapEntry *n)
576 * @param n the peer that disconnected 587 * @param n the peer that disconnected
577 */ 588 */
578static void 589static void
579neighbours_disconnect_notification(struct NeighbourMapEntry *n) 590neighbours_disconnect_notification (struct NeighbourMapEntry *n)
580{ 591{
581 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 592 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
582 "Peer `%s' disconnected\n", 593 "Peer `%s' disconnected\n",
583 GNUNET_i2s(&n->id)); 594 GNUNET_i2s (&n->id));
584 GST_manipulation_peer_disconnect(&n->id); 595 GST_manipulation_peer_disconnect (&n->id);
585 GST_clients_broadcast_disconnect(&n->id); 596 GST_clients_broadcast_disconnect (&n->id);
586} 597}
587 598
588 599
@@ -598,26 +609,28 @@ neighbours_disconnect_notification(struct NeighbourMapEntry *n)
598 * @param bandwidth_out bandwidth assigned outbound, 0 on disconnect 609 * @param bandwidth_out bandwidth assigned outbound, 0 on disconnect
599 */ 610 */
600static void 611static void
601neighbours_changed_notification(const struct GNUNET_PeerIdentity *peer, 612neighbours_changed_notification (const struct GNUNET_PeerIdentity *peer,
602 const struct GNUNET_HELLO_Address *address, 613 const struct GNUNET_HELLO_Address *address,
603 enum GNUNET_TRANSPORT_PeerState state, 614 enum GNUNET_TRANSPORT_PeerState state,
604 struct GNUNET_TIME_Absolute state_timeout, 615 struct GNUNET_TIME_Absolute state_timeout,
605 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 616 struct GNUNET_BANDWIDTH_Value32NBO
606 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 617 bandwidth_in,
607{ 618 struct GNUNET_BANDWIDTH_Value32NBO
608 (void)bandwidth_in; 619 bandwidth_out)
609 (void)bandwidth_out; 620{
610 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 621 (void) bandwidth_in;
611 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n", 622 (void) bandwidth_out;
612 GNUNET_i2s(peer), 623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
613 GST_plugins_a2s(address), 624 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n",
614 GNUNET_TRANSPORT_ps2s(state), 625 GNUNET_i2s (peer),
615 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 626 GST_plugins_a2s (address),
627 GNUNET_TRANSPORT_ps2s (state),
628 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
616 /* FIXME: include bandwidth in notification! */ 629 /* FIXME: include bandwidth in notification! */
617 GST_clients_broadcast_peer_notification(peer, 630 GST_clients_broadcast_peer_notification (peer,
618 address, 631 address,
619 state, 632 state,
620 state_timeout); 633 state_timeout);
621} 634}
622 635
623 636
@@ -628,11 +641,11 @@ neighbours_changed_notification(const struct GNUNET_PeerIdentity *peer,
628 * @return the entry, NULL if there is no existing record 641 * @return the entry, NULL if there is no existing record
629 */ 642 */
630static struct NeighbourMapEntry * 643static struct NeighbourMapEntry *
631lookup_neighbour(const struct GNUNET_PeerIdentity *pid) 644lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
632{ 645{
633 if (NULL == neighbours) 646 if (NULL == neighbours)
634 return NULL; 647 return NULL;
635 return GNUNET_CONTAINER_multipeermap_get(neighbours, pid); 648 return GNUNET_CONTAINER_multipeermap_get (neighbours, pid);
636} 649}
637 650
638 651
@@ -643,11 +656,11 @@ lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
643 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not 656 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
644 */ 657 */
645static int 658static int
646test_connected(struct NeighbourMapEntry *n) 659test_connected (struct NeighbourMapEntry *n)
647{ 660{
648 if (NULL == n) 661 if (NULL == n)
649 return GNUNET_NO; 662 return GNUNET_NO;
650 return GNUNET_TRANSPORT_is_connected(n->state); 663 return GNUNET_TRANSPORT_is_connected (n->state);
651} 664}
652 665
653 666
@@ -659,20 +672,20 @@ test_connected(struct NeighbourMapEntry *n)
659 * @param na address we are done with; @a na itself must NOT be 'free'd, only the contents! 672 * @param na address we are done with; @a na itself must NOT be 'free'd, only the contents!
660 */ 673 */
661static void 674static void
662free_address(struct NeighbourAddress *na) 675free_address (struct NeighbourAddress *na)
663{ 676{
664 if (GNUNET_YES == na->ats_active) 677 if (GNUNET_YES == na->ats_active)
665 GST_validation_set_address_use(na->address, 678 GST_validation_set_address_use (na->address,
666 GNUNET_NO); 679 GNUNET_NO);
667 if (NULL != na->address) 680 if (NULL != na->address)
668 { 681 {
669 GST_ats_block_address(na->address, 682 GST_ats_block_address (na->address,
670 na->session); 683 na->session);
671 GNUNET_HELLO_address_free(na->address); 684 GNUNET_HELLO_address_free (na->address);
672 na->address = NULL; 685 na->address = NULL;
673 } 686 }
674 na->bandwidth_in = GNUNET_BANDWIDTH_value_init(0); 687 na->bandwidth_in = GNUNET_BANDWIDTH_value_init (0);
675 na->bandwidth_out = GNUNET_BANDWIDTH_value_init(0); 688 na->bandwidth_out = GNUNET_BANDWIDTH_value_init (0);
676 na->ats_active = GNUNET_NO; 689 na->ats_active = GNUNET_NO;
677 na->keep_alive_nonce = 0; 690 na->keep_alive_nonce = 0;
678 na->session = NULL; 691 na->session = NULL;
@@ -687,7 +700,7 @@ free_address(struct NeighbourAddress *na)
687 * @param cls the `struct NeighbourMapEntry` for which we are running 700 * @param cls the `struct NeighbourMapEntry` for which we are running
688 */ 701 */
689static void 702static void
690master_task(void *cls); 703master_task (void *cls);
691 704
692 705
693/** 706/**
@@ -698,50 +711,50 @@ master_task(void *cls);
698 * @param timeout the new timeout 711 * @param timeout the new timeout
699 */ 712 */
700static void 713static void
701set_state_and_timeout(struct NeighbourMapEntry *n, 714set_state_and_timeout (struct NeighbourMapEntry *n,
702 enum GNUNET_TRANSPORT_PeerState s, 715 enum GNUNET_TRANSPORT_PeerState s,
703 struct GNUNET_TIME_Absolute timeout) 716 struct GNUNET_TIME_Absolute timeout)
704{ 717{
705 if (GNUNET_TRANSPORT_is_connected(s) && 718 if (GNUNET_TRANSPORT_is_connected (s) &&
706 (!GNUNET_TRANSPORT_is_connected(n->state))) 719 (! GNUNET_TRANSPORT_is_connected (n->state)))
707 { 720 {
708 neighbours_connect_notification(n); 721 neighbours_connect_notification (n);
709 GNUNET_STATISTICS_set(GST_stats, 722 GNUNET_STATISTICS_set (GST_stats,
710 gettext_noop("# peers connected"), 723 gettext_noop ("# peers connected"),
711 ++neighbours_connected, 724 ++neighbours_connected,
712 GNUNET_NO); 725 GNUNET_NO);
713 } 726 }
714 if ((!GNUNET_TRANSPORT_is_connected(s)) && 727 if ((! GNUNET_TRANSPORT_is_connected (s)) &&
715 GNUNET_TRANSPORT_is_connected(n->state)) 728 GNUNET_TRANSPORT_is_connected (n->state))
716 { 729 {
717 GNUNET_STATISTICS_set(GST_stats, 730 GNUNET_STATISTICS_set (GST_stats,
718 gettext_noop("# peers connected"), 731 gettext_noop ("# peers connected"),
719 --neighbours_connected, 732 --neighbours_connected,
720 GNUNET_NO); 733 GNUNET_NO);
721 neighbours_disconnect_notification(n); 734 neighbours_disconnect_notification (n);
722 } 735 }
723 n->state = s; 736 n->state = s;
724 if ((timeout.abs_value_us < n->timeout.abs_value_us) && 737 if ((timeout.abs_value_us < n->timeout.abs_value_us) &&
725 (NULL != n->task)) 738 (NULL != n->task))
726 { 739 {
727 /* new timeout is earlier, reschedule master task */ 740 /* new timeout is earlier, reschedule master task */
728 GNUNET_SCHEDULER_cancel(n->task); 741 GNUNET_SCHEDULER_cancel (n->task);
729 n->task = GNUNET_SCHEDULER_add_at(timeout, 742 n->task = GNUNET_SCHEDULER_add_at (timeout,
730 &master_task, 743 &master_task,
731 n); 744 n);
732 } 745 }
733 n->timeout = timeout; 746 n->timeout = timeout;
734 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 747 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
735 "Neighbour `%s' changed state to %s with timeout %s\n", 748 "Neighbour `%s' changed state to %s with timeout %s\n",
736 GNUNET_i2s(&n->id), 749 GNUNET_i2s (&n->id),
737 GNUNET_TRANSPORT_ps2s(s), 750 GNUNET_TRANSPORT_ps2s (s),
738 GNUNET_STRINGS_absolute_time_to_string(timeout)); 751 GNUNET_STRINGS_absolute_time_to_string (timeout));
739 neighbours_changed_notification(&n->id, 752 neighbours_changed_notification (&n->id,
740 n->primary_address.address, 753 n->primary_address.address,
741 n->state, 754 n->state,
742 n->timeout, 755 n->timeout,
743 n->primary_address.bandwidth_in, 756 n->primary_address.bandwidth_in,
744 n->primary_address.bandwidth_out); 757 n->primary_address.bandwidth_out);
745} 758}
746 759
747 760
@@ -757,62 +770,62 @@ set_state_and_timeout(struct NeighbourMapEntry *n,
757 * @param bandwidth_out outbound quota to be used when connection is up 770 * @param bandwidth_out outbound quota to be used when connection is up
758 */ 771 */
759static void 772static void
760set_alternative_address(struct NeighbourMapEntry *n, 773set_alternative_address (struct NeighbourMapEntry *n,
761 const struct GNUNET_HELLO_Address *address, 774 const struct GNUNET_HELLO_Address *address,
762 struct GNUNET_ATS_Session *session, 775 struct GNUNET_ATS_Session *session,
763 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 776 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
764 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 777 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
765{ 778{
766 struct GNUNET_TRANSPORT_PluginFunctions *papi; 779 struct GNUNET_TRANSPORT_PluginFunctions *papi;
767 780
768 if (NULL == (papi = GST_plugins_find(address->transport_name))) 781 if (NULL == (papi = GST_plugins_find (address->transport_name)))
769 { 782 {
770 GNUNET_break(0); 783 GNUNET_break (0);
771 return; 784 return;
772 } 785 }
773 if (session == n->alternative_address.session) 786 if (session == n->alternative_address.session)
774 { 787 {
775 n->alternative_address.bandwidth_in = bandwidth_in; 788 n->alternative_address.bandwidth_in = bandwidth_in;
776 n->alternative_address.bandwidth_out = bandwidth_out; 789 n->alternative_address.bandwidth_out = bandwidth_out;
777 return; 790 return;
778 } 791 }
779 if (NULL != n->alternative_address.address) 792 if (NULL != n->alternative_address.address)
780 { 793 {
781 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
782 "Replacing existing alternative address with another one\n"); 795 "Replacing existing alternative address with another one\n");
783 free_address(&n->alternative_address); 796 free_address (&n->alternative_address);
784 } 797 }
785 if (NULL == session) 798 if (NULL == session)
786 session = papi->get_session(papi->cls, 799 session = papi->get_session (papi->cls,
787 address); 800 address);
788 if (NULL == session) 801 if (NULL == session)
789 { 802 {
790 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
791 "Failed to obtain new session for peer `%s' and address '%s'\n", 804 "Failed to obtain new session for peer `%s' and address '%s'\n",
792 GNUNET_i2s(&address->peer), 805 GNUNET_i2s (&address->peer),
793 GST_plugins_a2s(address)); 806 GST_plugins_a2s (address));
794 GNUNET_STATISTICS_update(GST_stats, 807 GNUNET_STATISTICS_update (GST_stats,
795 gettext_noop("# session creation failed"), 808 gettext_noop ("# session creation failed"),
796 1, 809 1,
797 GNUNET_NO); 810 GNUNET_NO);
798 return; 811 return;
799 } 812 }
800 GST_ats_new_session(address, 813 GST_ats_new_session (address,
801 session); 814 session);
802 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 815 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
803 "Neighbour `%s' configured alternative address %s\n", 816 "Neighbour `%s' configured alternative address %s\n",
804 GNUNET_i2s(&n->id), 817 GNUNET_i2s (&n->id),
805 GST_plugins_a2s(address)); 818 GST_plugins_a2s (address));
806 819
807 n->alternative_address.address = GNUNET_HELLO_address_copy(address); 820 n->alternative_address.address = GNUNET_HELLO_address_copy (address);
808 n->alternative_address.bandwidth_in = bandwidth_in; 821 n->alternative_address.bandwidth_in = bandwidth_in;
809 n->alternative_address.bandwidth_out = bandwidth_out; 822 n->alternative_address.bandwidth_out = bandwidth_out;
810 n->alternative_address.session = session; 823 n->alternative_address.session = session;
811 n->alternative_address.ats_active = GNUNET_NO; 824 n->alternative_address.ats_active = GNUNET_NO;
812 n->alternative_address.keep_alive_nonce = 0; 825 n->alternative_address.keep_alive_nonce = 0;
813 GNUNET_assert(GNUNET_YES == 826 GNUNET_assert (GNUNET_YES ==
814 GST_ats_is_known(n->alternative_address.address, 827 GST_ats_is_known (n->alternative_address.address,
815 n->alternative_address.session)); 828 n->alternative_address.session));
816} 829}
817 830
818 831
@@ -833,40 +846,44 @@ set_alternative_address(struct NeighbourMapEntry *n,
833 * @a use_keepalive_timeout is #GNUNET_YES. 846 * @a use_keepalive_timeout is #GNUNET_YES.
834 */ 847 */
835static struct GNUNET_TIME_Relative 848static struct GNUNET_TIME_Relative
836send_with_session(struct NeighbourMapEntry *n, 849send_with_session (struct NeighbourMapEntry *n,
837 const void *msgbuf, 850 const void *msgbuf,
838 size_t msgbuf_size, 851 size_t msgbuf_size,
839 uint32_t priority, 852 uint32_t priority,
840 struct GNUNET_TIME_Relative timeout, 853 struct GNUNET_TIME_Relative timeout,
841 unsigned int use_keepalive_timeout, 854 unsigned int use_keepalive_timeout,
842 GNUNET_TRANSPORT_TransmitContinuation cont, 855 GNUNET_TRANSPORT_TransmitContinuation cont,
843 void *cont_cls) 856 void *cont_cls)
844{ 857{
845 struct GNUNET_TRANSPORT_PluginFunctions *papi; 858 struct GNUNET_TRANSPORT_PluginFunctions *papi;
846 struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL; 859 struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL;
847 860
848 GNUNET_assert(NULL != n->primary_address.session); 861 GNUNET_assert (NULL != n->primary_address.session);
849 if (((NULL == (papi = GST_plugins_find(n->primary_address.address->transport_name)) || 862 if ((((NULL == (papi = GST_plugins_find (
850 (-1 == papi->send(papi->cls, 863 n->primary_address.address->transport_name))) ||
851 n->primary_address.session, 864 (-1 == papi->send (papi->cls,
852 msgbuf, 865 n->primary_address.session,
853 msgbuf_size, 866 msgbuf,
854 priority, 867 msgbuf_size,
855 (result = (GNUNET_NO == use_keepalive_timeout) ? timeout : 868 priority,
856 GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 869 (result = (GNUNET_NO == use_keepalive_timeout) ?
857 papi->query_keepalive_factor(papi->cls))), 870 timeout :
858 cont, 871 GNUNET_TIME_relative_divide (
859 cont_cls)))) && 872 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
873 papi->
874 query_keepalive_factor (papi->cls))),
875 cont,
876 cont_cls)))) &&
860 (NULL != cont)) 877 (NULL != cont))
861 cont(cont_cls, 878 cont (cont_cls,
862 &n->id, 879 &n->id,
863 GNUNET_SYSERR, 880 GNUNET_SYSERR,
864 msgbuf_size, 881 msgbuf_size,
865 0); 882 0);
866 GST_neighbours_notify_data_sent(n->primary_address.address, 883 GST_neighbours_notify_data_sent (n->primary_address.address,
867 n->primary_address.session, 884 n->primary_address.session,
868 msgbuf_size); 885 msgbuf_size);
869 GNUNET_break(NULL != papi); 886 GNUNET_break (NULL != papi);
870 return result; 887 return result;
871} 888}
872 889
@@ -878,20 +895,20 @@ send_with_session(struct NeighbourMapEntry *n,
878 * @param n the neighbour 895 * @param n the neighbour
879 */ 896 */
880static void 897static void
881unset_primary_address(struct NeighbourMapEntry *n) 898unset_primary_address (struct NeighbourMapEntry *n)
882{ 899{
883 /* Notify monitoring about change */ 900 /* Notify monitoring about change */
884 if (NULL == n->primary_address.address) 901 if (NULL == n->primary_address.address)
885 return; 902 return;
886 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
887 "Disabling primary address\n"); 904 "Disabling primary address\n");
888 neighbours_changed_notification(&n->id, 905 neighbours_changed_notification (&n->id,
889 n->primary_address.address, 906 n->primary_address.address,
890 n->state, 907 n->state,
891 n->timeout, 908 n->timeout,
892 GNUNET_BANDWIDTH_value_init(0), 909 GNUNET_BANDWIDTH_value_init (0),
893 GNUNET_BANDWIDTH_value_init(0)); 910 GNUNET_BANDWIDTH_value_init (0));
894 free_address(&n->primary_address); 911 free_address (&n->primary_address);
895} 912}
896 913
897 914
@@ -901,68 +918,68 @@ unset_primary_address(struct NeighbourMapEntry *n)
901 * @param n entry to free 918 * @param n entry to free
902 */ 919 */
903static void 920static void
904free_neighbour(struct NeighbourMapEntry *n) 921free_neighbour (struct NeighbourMapEntry *n)
905{ 922{
906 struct MessageQueue *mq; 923 struct MessageQueue *mq;
907 924
908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "Freeing neighbour state of peer `%s'\n", 926 "Freeing neighbour state of peer `%s'\n",
910 GNUNET_i2s(&n->id)); 927 GNUNET_i2s (&n->id));
911 n->is_active = NULL; /* always free'd by its own continuation! */ 928 n->is_active = NULL; /* always free'd by its own continuation! */
912 929
913 /* fail messages currently in the queue */ 930 /* fail messages currently in the queue */
914 while (NULL != (mq = n->messages_head)) 931 while (NULL != (mq = n->messages_head))
915 { 932 {
916 GNUNET_CONTAINER_DLL_remove(n->messages_head, 933 GNUNET_CONTAINER_DLL_remove (n->messages_head,
917 n->messages_tail, 934 n->messages_tail,
918 mq); 935 mq);
919 if (NULL != mq->cont) 936 if (NULL != mq->cont)
920 mq->cont(mq->cont_cls, 937 mq->cont (mq->cont_cls,
921 GNUNET_SYSERR, 938 GNUNET_SYSERR,
922 mq->message_buf_size, 939 mq->message_buf_size,
923 0); 940 0);
924 GNUNET_free(mq); 941 GNUNET_free (mq);
925 } 942 }
926 /* Mark peer as disconnected */ 943 /* Mark peer as disconnected */
927 set_state_and_timeout(n, 944 set_state_and_timeout (n,
928 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED, 945 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED,
929 GNUNET_TIME_UNIT_FOREVER_ABS); 946 GNUNET_TIME_UNIT_FOREVER_ABS);
930 /* free addresses and mark as unused */ 947 /* free addresses and mark as unused */
931 unset_primary_address(n); 948 unset_primary_address (n);
932 949
933 if (NULL != n->alternative_address.address) 950 if (NULL != n->alternative_address.address)
934 { 951 {
935 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
936 "Cleaning up alternative address\n"); 953 "Cleaning up alternative address\n");
937 free_address(&n->alternative_address); 954 free_address (&n->alternative_address);
938 } 955 }
939 GNUNET_assert(GNUNET_YES == 956 GNUNET_assert (GNUNET_YES ==
940 GNUNET_CONTAINER_multipeermap_remove(neighbours, 957 GNUNET_CONTAINER_multipeermap_remove (neighbours,
941 &n->id, 958 &n->id,
942 n)); 959 n));
943 960
944 /* Cancel address requests for this peer */ 961 /* Cancel address requests for this peer */
945 if (NULL != n->suggest_handle) 962 if (NULL != n->suggest_handle)
946 { 963 {
947 GNUNET_ATS_connectivity_suggest_cancel(n->suggest_handle); 964 GNUNET_ATS_connectivity_suggest_cancel (n->suggest_handle);
948 n->suggest_handle = NULL; 965 n->suggest_handle = NULL;
949 } 966 }
950 967
951 /* Cancel the disconnect task */ 968 /* Cancel the disconnect task */
952 if (NULL != n->delayed_disconnect_task) 969 if (NULL != n->delayed_disconnect_task)
953 { 970 {
954 GNUNET_SCHEDULER_cancel(n->delayed_disconnect_task); 971 GNUNET_SCHEDULER_cancel (n->delayed_disconnect_task);
955 n->delayed_disconnect_task = NULL; 972 n->delayed_disconnect_task = NULL;
956 } 973 }
957 974
958 /* Cancel the master task */ 975 /* Cancel the master task */
959 if (NULL != n->task) 976 if (NULL != n->task)
960 { 977 {
961 GNUNET_SCHEDULER_cancel(n->task); 978 GNUNET_SCHEDULER_cancel (n->task);
962 n->task = NULL; 979 n->task = NULL;
963 } 980 }
964 /* free rest of memory */ 981 /* free rest of memory */
965 GNUNET_free(n); 982 GNUNET_free (n);
966} 983}
967 984
968 985
@@ -977,26 +994,26 @@ free_neighbour(struct NeighbourMapEntry *n)
977 * @param physical bytes on wire 994 * @param physical bytes on wire
978 */ 995 */
979static void 996static void
980send_disconnect_cont(void *cls, 997send_disconnect_cont (void *cls,
981 const struct GNUNET_PeerIdentity *target, 998 const struct GNUNET_PeerIdentity *target,
982 int result, 999 int result,
983 size_t payload, 1000 size_t payload,
984 size_t physical) 1001 size_t physical)
985{ 1002{
986 struct NeighbourMapEntry *n; 1003 struct NeighbourMapEntry *n;
987 1004
988 (void)cls; 1005 (void) cls;
989 (void)result; 1006 (void) result;
990 (void)payload; 1007 (void) payload;
991 (void)physical; 1008 (void) physical;
992 n = lookup_neighbour(target); 1009 n = lookup_neighbour (target);
993 if (NULL == n) 1010 if (NULL == n)
994 return; /* already gone */ 1011 return; /* already gone */
995 if (GNUNET_TRANSPORT_PS_DISCONNECT != n->state) 1012 if (GNUNET_TRANSPORT_PS_DISCONNECT != n->state)
996 return; /* have created a fresh entry since */ 1013 return; /* have created a fresh entry since */
997 if (NULL != n->task) 1014 if (NULL != n->task)
998 GNUNET_SCHEDULER_cancel(n->task); 1015 GNUNET_SCHEDULER_cancel (n->task);
999 n->task = GNUNET_SCHEDULER_add_now(&master_task, n); 1016 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
1000} 1017}
1001 1018
1002 1019
@@ -1006,43 +1023,44 @@ send_disconnect_cont(void *cls,
1006 * @param n neighbour to send DISCONNECT message. 1023 * @param n neighbour to send DISCONNECT message.
1007 */ 1024 */
1008static void 1025static void
1009send_disconnect(struct NeighbourMapEntry *n) 1026send_disconnect (struct NeighbourMapEntry *n)
1010{ 1027{
1011 struct GNUNET_ATS_SessionDisconnectMessage disconnect_msg; 1028 struct GNUNET_ATS_SessionDisconnectMessage disconnect_msg;
1012 1029
1013 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1030 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1014 "Sending DISCONNECT message to peer `%4s'\n", 1031 "Sending DISCONNECT message to peer `%4s'\n",
1015 GNUNET_i2s(&n->id)); 1032 GNUNET_i2s (&n->id));
1016 disconnect_msg.header.size = htons(sizeof(struct GNUNET_ATS_SessionDisconnectMessage)); 1033 disconnect_msg.header.size = htons (sizeof(struct
1034 GNUNET_ATS_SessionDisconnectMessage));
1017 disconnect_msg.header.type = 1035 disconnect_msg.header.type =
1018 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); 1036 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
1019 disconnect_msg.reserved = htonl(0); 1037 disconnect_msg.reserved = htonl (0);
1020 disconnect_msg.purpose.size = 1038 disconnect_msg.purpose.size =
1021 htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + 1039 htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
1022 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + 1040 + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
1023 sizeof(struct GNUNET_TIME_AbsoluteNBO)); 1041 + sizeof(struct GNUNET_TIME_AbsoluteNBO));
1024 disconnect_msg.purpose.purpose = 1042 disconnect_msg.purpose.purpose =
1025 htonl(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); 1043 htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
1026 disconnect_msg.timestamp = 1044 disconnect_msg.timestamp =
1027 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get()); 1045 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1028 disconnect_msg.public_key = GST_my_identity.public_key; 1046 disconnect_msg.public_key = GST_my_identity.public_key;
1029 GNUNET_assert(GNUNET_OK == 1047 GNUNET_assert (GNUNET_OK ==
1030 GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, 1048 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
1031 &disconnect_msg.purpose, 1049 &disconnect_msg.purpose,
1032 &disconnect_msg.signature)); 1050 &disconnect_msg.signature));
1033 1051
1034 (void)send_with_session(n, 1052 (void) send_with_session (n,
1035 &disconnect_msg, 1053 &disconnect_msg,
1036 sizeof(disconnect_msg), 1054 sizeof(disconnect_msg),
1037 UINT32_MAX, 1055 UINT32_MAX,
1038 GNUNET_TIME_UNIT_FOREVER_REL, 1056 GNUNET_TIME_UNIT_FOREVER_REL,
1039 GNUNET_NO, 1057 GNUNET_NO,
1040 &send_disconnect_cont, 1058 &send_disconnect_cont,
1041 NULL); 1059 NULL);
1042 GNUNET_STATISTICS_update(GST_stats, 1060 GNUNET_STATISTICS_update (GST_stats,
1043 gettext_noop("# DISCONNECT messages sent"), 1061 gettext_noop ("# DISCONNECT messages sent"),
1044 1, 1062 1,
1045 GNUNET_NO); 1063 GNUNET_NO);
1046} 1064}
1047 1065
1048 1066
@@ -1052,81 +1070,81 @@ send_disconnect(struct NeighbourMapEntry *n)
1052 * @param n neighbour to disconnect from 1070 * @param n neighbour to disconnect from
1053 */ 1071 */
1054static void 1072static void
1055disconnect_neighbour(struct NeighbourMapEntry *n) 1073disconnect_neighbour (struct NeighbourMapEntry *n)
1056{ 1074{
1057 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1075 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1058 "Disconnecting from peer %s in state %s\n", 1076 "Disconnecting from peer %s in state %s\n",
1059 GNUNET_i2s(&n->id), 1077 GNUNET_i2s (&n->id),
1060 GNUNET_TRANSPORT_ps2s(n->state)); 1078 GNUNET_TRANSPORT_ps2s (n->state));
1061 /* depending on state, notify neighbour and/or upper layers of this peer 1079 /* depending on state, notify neighbour and/or upper layers of this peer
1062 about disconnect */ 1080 about disconnect */
1063 switch (n->state) 1081 switch (n->state)
1064 { 1082 {
1065 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 1083 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
1066 case GNUNET_TRANSPORT_PS_INIT_ATS: 1084 case GNUNET_TRANSPORT_PS_INIT_ATS:
1067 /* other peer is completely unaware of us, no need to send DISCONNECT */ 1085 /* other peer is completely unaware of us, no need to send DISCONNECT */
1068 free_neighbour(n); 1086 free_neighbour (n);
1069 return; 1087 return;
1070
1071 case GNUNET_TRANSPORT_PS_SYN_SENT:
1072 send_disconnect(n);
1073 set_state_and_timeout(n,
1074 GNUNET_TRANSPORT_PS_DISCONNECT,
1075 GNUNET_TIME_UNIT_FOREVER_ABS);
1076 break;
1077
1078 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
1079 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */
1080 free_neighbour(n);
1081 return;
1082
1083 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
1084 /* we DID ACK the other peer's request, must send DISCONNECT */
1085 send_disconnect(n);
1086 set_state_and_timeout(n,
1087 GNUNET_TRANSPORT_PS_DISCONNECT,
1088 GNUNET_TIME_UNIT_FOREVER_ABS);
1089 break;
1090
1091 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1092 case GNUNET_TRANSPORT_PS_CONNECTED:
1093 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1094 /* we are currently connected, need to send disconnect and do
1095 internal notifications and update statistics */
1096 send_disconnect(n);
1097 set_state_and_timeout(n,
1098 GNUNET_TRANSPORT_PS_DISCONNECT,
1099 GNUNET_TIME_UNIT_FOREVER_ABS);
1100 break;
1101 1088
1102 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 1089 case GNUNET_TRANSPORT_PS_SYN_SENT:
1103 /* Disconnecting while waiting for an ATS address to reconnect, 1090 send_disconnect (n);
1104 * cannot send DISCONNECT */ 1091 set_state_and_timeout (n,
1105 free_neighbour(n); 1092 GNUNET_TRANSPORT_PS_DISCONNECT,
1106 return; 1093 GNUNET_TIME_UNIT_FOREVER_ABS);
1094 break;
1107 1095
1108 case GNUNET_TRANSPORT_PS_DISCONNECT: 1096 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
1109 /* already disconnected, ignore */ 1097 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */
1110 break; 1098 free_neighbour (n);
1099 return;
1111 1100
1112 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 1101 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
1113 /* already cleaned up, how did we get here!? */ 1102 /* we DID ACK the other peer's request, must send DISCONNECT */
1114 GNUNET_assert(0); 1103 send_disconnect (n);
1115 break; 1104 set_state_and_timeout (n,
1105 GNUNET_TRANSPORT_PS_DISCONNECT,
1106 GNUNET_TIME_UNIT_FOREVER_ABS);
1107 break;
1108
1109 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1110 case GNUNET_TRANSPORT_PS_CONNECTED:
1111 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1112 /* we are currently connected, need to send disconnect and do
1113 internal notifications and update statistics */
1114 send_disconnect (n);
1115 set_state_and_timeout (n,
1116 GNUNET_TRANSPORT_PS_DISCONNECT,
1117 GNUNET_TIME_UNIT_FOREVER_ABS);
1118 break;
1119
1120 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
1121 /* Disconnecting while waiting for an ATS address to reconnect,
1122 * cannot send DISCONNECT */
1123 free_neighbour (n);
1124 return;
1116 1125
1117 default: 1126 case GNUNET_TRANSPORT_PS_DISCONNECT:
1118 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1127 /* already disconnected, ignore */
1119 "Unhandled state `%s'\n", 1128 break;
1120 GNUNET_TRANSPORT_ps2s(n->state)); 1129
1121 GNUNET_break(0); 1130 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
1122 break; 1131 /* already cleaned up, how did we get here!? */
1123 } 1132 GNUNET_assert (0);
1133 break;
1134
1135 default:
1136 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1137 "Unhandled state `%s'\n",
1138 GNUNET_TRANSPORT_ps2s (n->state));
1139 GNUNET_break (0);
1140 break;
1141 }
1124 /* schedule timeout to clean up */ 1142 /* schedule timeout to clean up */
1125 if (NULL != n->task) 1143 if (NULL != n->task)
1126 GNUNET_SCHEDULER_cancel(n->task); 1144 GNUNET_SCHEDULER_cancel (n->task);
1127 n->task = GNUNET_SCHEDULER_add_delayed(DISCONNECT_SENT_TIMEOUT, 1145 n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT,
1128 &master_task, 1146 &master_task,
1129 n); 1147 n);
1130} 1148}
1131 1149
1132 1150
@@ -1141,39 +1159,39 @@ disconnect_neighbour(struct NeighbourMapEntry *n)
1141 * @a n was freed 1159 * @a n was freed
1142 */ 1160 */
1143static int 1161static int
1144set_incoming_quota(struct NeighbourMapEntry *n, 1162set_incoming_quota (struct NeighbourMapEntry *n,
1145 struct GNUNET_BANDWIDTH_Value32NBO quota) 1163 struct GNUNET_BANDWIDTH_Value32NBO quota)
1146{ 1164{
1147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1148 "Setting inbound quota of %u Bps for peer `%s' to all clients\n", 1166 "Setting inbound quota of %u Bps for peer `%s' to all clients\n",
1149 ntohl(quota.value__), GNUNET_i2s(&n->id)); 1167 ntohl (quota.value__), GNUNET_i2s (&n->id));
1150 GNUNET_BANDWIDTH_tracker_update_quota(&n->in_tracker, 1168 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker,
1151 quota); 1169 quota);
1152 if (0 != ntohl(quota.value__)) 1170 if (0 != ntohl (quota.value__))
1153 { 1171 {
1154 struct GNUNET_ATS_SessionQuotaMessage sqm; 1172 struct GNUNET_ATS_SessionQuotaMessage sqm;
1155 1173
1156 sqm.header.size = htons(sizeof(struct GNUNET_ATS_SessionQuotaMessage)); 1174 sqm.header.size = htons (sizeof(struct GNUNET_ATS_SessionQuotaMessage));
1157 sqm.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA); 1175 sqm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA);
1158 sqm.quota = quota.value__; 1176 sqm.quota = quota.value__;
1159 if (NULL != n->primary_address.session) 1177 if (NULL != n->primary_address.session)
1160 (void)send_with_session(n, 1178 (void) send_with_session (n,
1161 &sqm, 1179 &sqm,
1162 sizeof(sqm), 1180 sizeof(sqm),
1163 UINT32_MAX - 1, 1181 UINT32_MAX - 1,
1164 GNUNET_TIME_UNIT_FOREVER_REL, 1182 GNUNET_TIME_UNIT_FOREVER_REL,
1165 GNUNET_NO, 1183 GNUNET_NO,
1166 NULL, NULL); 1184 NULL, NULL);
1167 return GNUNET_YES; 1185 return GNUNET_YES;
1168 } 1186 }
1169 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1187 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1170 "Disconnecting peer `%s' due to SET_QUOTA\n", 1188 "Disconnecting peer `%s' due to SET_QUOTA\n",
1171 GNUNET_i2s(&n->id)); 1189 GNUNET_i2s (&n->id));
1172 if (GNUNET_YES == test_connected(n)) 1190 if (GNUNET_YES == test_connected (n))
1173 GNUNET_STATISTICS_update(GST_stats, 1191 GNUNET_STATISTICS_update (GST_stats,
1174 gettext_noop("# disconnects due to quota of 0"), 1192 gettext_noop ("# disconnects due to quota of 0"),
1175 1, GNUNET_NO); 1193 1, GNUNET_NO);
1176 disconnect_neighbour(n); 1194 disconnect_neighbour (n);
1177 return GNUNET_NO; 1195 return GNUNET_NO;
1178} 1196}
1179 1197
@@ -1190,78 +1208,78 @@ set_incoming_quota(struct NeighbourMapEntry *n,
1190 * @param bandwidth_out outbound quota to be used when connection is up 1208 * @param bandwidth_out outbound quota to be used when connection is up
1191 */ 1209 */
1192static void 1210static void
1193set_primary_address(struct NeighbourMapEntry *n, 1211set_primary_address (struct NeighbourMapEntry *n,
1194 const struct GNUNET_HELLO_Address *address, 1212 const struct GNUNET_HELLO_Address *address,
1195 struct GNUNET_ATS_Session *session, 1213 struct GNUNET_ATS_Session *session,
1196 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1214 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1197 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1215 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1198{ 1216{
1199 if (session == n->primary_address.session) 1217 if (session == n->primary_address.session)
1218 {
1219 GST_validation_set_address_use (n->primary_address.address,
1220 GNUNET_YES);
1221 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
1200 { 1222 {
1201 GST_validation_set_address_use(n->primary_address.address, 1223 n->primary_address.bandwidth_in = bandwidth_in;
1202 GNUNET_YES); 1224 if (GNUNET_YES !=
1203 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) 1225 set_incoming_quota (n,
1204 { 1226 bandwidth_in))
1205 n->primary_address.bandwidth_in = bandwidth_in; 1227 return;
1206 if (GNUNET_YES !=
1207 set_incoming_quota(n,
1208 bandwidth_in))
1209 return;
1210 }
1211 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
1212 {
1213 n->primary_address.bandwidth_out = bandwidth_out;
1214 send_outbound_quota_to_clients(n);
1215 }
1216 return;
1217 } 1228 }
1218 if ((NULL != n->primary_address.address) && 1229 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
1219 (0 == GNUNET_HELLO_address_cmp(address,
1220 n->primary_address.address)))
1221 { 1230 {
1222 GNUNET_break(0); 1231 n->primary_address.bandwidth_out = bandwidth_out;
1223 return; 1232 send_outbound_quota_to_clients (n);
1224 } 1233 }
1234 return;
1235 }
1236 if ((NULL != n->primary_address.address) &&
1237 (0 == GNUNET_HELLO_address_cmp (address,
1238 n->primary_address.address)))
1239 {
1240 GNUNET_break (0);
1241 return;
1242 }
1225 if (NULL == session) 1243 if (NULL == session)
1226 { 1244 {
1227 GNUNET_break(0); 1245 GNUNET_break (0);
1228 GST_ats_block_address(address, 1246 GST_ats_block_address (address,
1229 session); 1247 session);
1230 return; 1248 return;
1231 } 1249 }
1232 if (NULL != n->primary_address.address) 1250 if (NULL != n->primary_address.address)
1233 { 1251 {
1234 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1235 "Replacing existing primary address with another one\n"); 1253 "Replacing existing primary address with another one\n");
1236 free_address(&n->primary_address); 1254 free_address (&n->primary_address);
1237 } 1255 }
1238 n->primary_address.address = GNUNET_HELLO_address_copy(address); 1256 n->primary_address.address = GNUNET_HELLO_address_copy (address);
1239 n->primary_address.bandwidth_in = bandwidth_in; 1257 n->primary_address.bandwidth_in = bandwidth_in;
1240 n->primary_address.bandwidth_out = bandwidth_out; 1258 n->primary_address.bandwidth_out = bandwidth_out;
1241 n->primary_address.session = session; 1259 n->primary_address.session = session;
1242 n->primary_address.keep_alive_nonce = 0; 1260 n->primary_address.keep_alive_nonce = 0;
1243 GNUNET_assert(GNUNET_YES == 1261 GNUNET_assert (GNUNET_YES ==
1244 GST_ats_is_known(n->primary_address.address, 1262 GST_ats_is_known (n->primary_address.address,
1245 n->primary_address.session)); 1263 n->primary_address.session));
1246 /* subsystems about address use */ 1264 /* subsystems about address use */
1247 GST_validation_set_address_use(n->primary_address.address, 1265 GST_validation_set_address_use (n->primary_address.address,
1248 GNUNET_YES); 1266 GNUNET_YES);
1249 if (GNUNET_YES != 1267 if (GNUNET_YES !=
1250 set_incoming_quota(n, 1268 set_incoming_quota (n,
1251 bandwidth_in)) 1269 bandwidth_in))
1252 return; 1270 return;
1253 send_outbound_quota_to_clients(n); 1271 send_outbound_quota_to_clients (n);
1254 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1272 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1255 "Neighbour `%s' switched to address `%s'\n", 1273 "Neighbour `%s' switched to address `%s'\n",
1256 GNUNET_i2s(&n->id), 1274 GNUNET_i2s (&n->id),
1257 GST_plugins_a2s(address)); 1275 GST_plugins_a2s (address));
1258 1276
1259 neighbours_changed_notification(&n->id, 1277 neighbours_changed_notification (&n->id,
1260 n->primary_address.address, 1278 n->primary_address.address,
1261 n->state, 1279 n->state,
1262 n->timeout, 1280 n->timeout,
1263 n->primary_address.bandwidth_in, 1281 n->primary_address.bandwidth_in,
1264 n->primary_address.bandwidth_out); 1282 n->primary_address.bandwidth_out);
1265} 1283}
1266 1284
1267 1285
@@ -1275,75 +1293,78 @@ set_primary_address(struct NeighbourMapEntry *n,
1275 * @param physical bytes sent on wire 1293 * @param physical bytes sent on wire
1276 */ 1294 */
1277static void 1295static void
1278transmit_send_continuation(void *cls, 1296transmit_send_continuation (void *cls,
1279 const struct GNUNET_PeerIdentity *receiver, 1297 const struct GNUNET_PeerIdentity *receiver,
1280 int success, 1298 int success,
1281 size_t size_payload, 1299 size_t size_payload,
1282 size_t physical) 1300 size_t physical)
1283{ 1301{
1284 struct MessageQueue *mq = cls; 1302 struct MessageQueue *mq = cls;
1285 struct NeighbourMapEntry *n; 1303 struct NeighbourMapEntry *n;
1286 1304
1287 if (NULL == (n = lookup_neighbour(receiver))) 1305 if (NULL == (n = lookup_neighbour (receiver)))
1288 { 1306 {
1289 if (NULL != mq->cont) 1307 if (NULL != mq->cont)
1290 mq->cont(mq->cont_cls, 1308 mq->cont (mq->cont_cls,
1291 GNUNET_SYSERR /* not connected */, 1309 GNUNET_SYSERR /* not connected */,
1292 size_payload, 1310 size_payload,
1293 0); 1311 0);
1294 GNUNET_free(mq); 1312 GNUNET_free (mq);
1295 return; /* disconnect or other error while transmitting, can happen */ 1313 return; /* disconnect or other error while transmitting, can happen */
1296 } 1314 }
1297 if (n->is_active == mq) 1315 if (n->is_active == mq)
1298 { 1316 {
1299 /* this is still "our" neighbour, remove us from its queue 1317 /* this is still "our" neighbour, remove us from its queue
1300 and allow it to send the next message now */ 1318 and allow it to send the next message now */
1301 n->is_active = NULL; 1319 n->is_active = NULL;
1302 if (NULL != n->task) 1320 if (NULL != n->task)
1303 GNUNET_SCHEDULER_cancel(n->task); 1321 GNUNET_SCHEDULER_cancel (n->task);
1304 n->task = GNUNET_SCHEDULER_add_now(&master_task, 1322 n->task = GNUNET_SCHEDULER_add_now (&master_task,
1305 n); 1323 n);
1306 } 1324 }
1307 if (bytes_in_send_queue < mq->message_buf_size) 1325 if (bytes_in_send_queue < mq->message_buf_size)
1308 { 1326 {
1309 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1310 "Bytes_in_send_queue `%llu', Message_size %u, result: %s, payload %u, on wire %u\n", 1328 "Bytes_in_send_queue `%llu', Message_size %u, result: %s, payload %u, on wire %u\n",
1311 bytes_in_send_queue, 1329 bytes_in_send_queue,
1312 (unsigned int)mq->message_buf_size, 1330 (unsigned int) mq->message_buf_size,
1313 (GNUNET_OK == success) ? "OK" : "FAIL", 1331 (GNUNET_OK == success) ? "OK" : "FAIL",
1314 (unsigned int)size_payload, 1332 (unsigned int) size_payload,
1315 (unsigned int)physical); 1333 (unsigned int) physical);
1316 GNUNET_break(0); 1334 GNUNET_break (0);
1317 } 1335 }
1318 1336
1319 GNUNET_break(size_payload == mq->message_buf_size); 1337 GNUNET_break (size_payload == mq->message_buf_size);
1320 bytes_in_send_queue -= mq->message_buf_size; 1338 bytes_in_send_queue -= mq->message_buf_size;
1321 GNUNET_STATISTICS_set(GST_stats, 1339 GNUNET_STATISTICS_set (GST_stats,
1322 gettext_noop("# bytes in message queue for other peers"), 1340 gettext_noop (
1323 bytes_in_send_queue, 1341 "# bytes in message queue for other peers"),
1324 GNUNET_NO); 1342 bytes_in_send_queue,
1343 GNUNET_NO);
1325 if (GNUNET_OK == success) 1344 if (GNUNET_OK == success)
1326 GNUNET_STATISTICS_update(GST_stats, 1345 GNUNET_STATISTICS_update (GST_stats,
1327 gettext_noop("# messages transmitted to other peers"), 1346 gettext_noop (
1328 1, 1347 "# messages transmitted to other peers"),
1329 GNUNET_NO); 1348 1,
1349 GNUNET_NO);
1330 else 1350 else
1331 GNUNET_STATISTICS_update(GST_stats, 1351 GNUNET_STATISTICS_update (GST_stats,
1332 gettext_noop 1352 gettext_noop
1333 ("# transmission failures for messages to other peers"), 1353 (
1334 1, GNUNET_NO); 1354 "# transmission failures for messages to other peers"),
1335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1355 1, GNUNET_NO);
1336 "Sending message to `%s' of type %u with %u bytes was a %s\n", 1356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1337 GNUNET_i2s(receiver), 1357 "Sending message to `%s' of type %u with %u bytes was a %s\n",
1338 ntohs(((struct GNUNET_MessageHeader *)mq->message_buf)->type), 1358 GNUNET_i2s (receiver),
1339 (unsigned int)mq->message_buf_size, 1359 ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type),
1340 (success == GNUNET_OK) ? "success" : "FAILURE"); 1360 (unsigned int) mq->message_buf_size,
1361 (success == GNUNET_OK) ? "success" : "FAILURE");
1341 if (NULL != mq->cont) 1362 if (NULL != mq->cont)
1342 mq->cont(mq->cont_cls, 1363 mq->cont (mq->cont_cls,
1343 success, 1364 success,
1344 size_payload, 1365 size_payload,
1345 physical); 1366 physical);
1346 GNUNET_free(mq); 1367 GNUNET_free (mq);
1347} 1368}
1348 1369
1349 1370
@@ -1359,77 +1380,78 @@ transmit_send_continuation(void *cls,
1359 * @param n target peer for which to transmit 1380 * @param n target peer for which to transmit
1360 */ 1381 */
1361static void 1382static void
1362try_transmission_to_peer(struct NeighbourMapEntry *n) 1383try_transmission_to_peer (struct NeighbourMapEntry *n)
1363{ 1384{
1364 struct MessageQueue *mq; 1385 struct MessageQueue *mq;
1365 struct GNUNET_TIME_Relative timeout; 1386 struct GNUNET_TIME_Relative timeout;
1366 1387
1367 if (NULL == n->primary_address.address) 1388 if (NULL == n->primary_address.address)
1368 { 1389 {
1369 /* no address, why are we here? */ 1390 /* no address, why are we here? */
1370 GNUNET_break(0); 1391 GNUNET_break (0);
1371 return; 1392 return;
1372 } 1393 }
1373 if ((0 == n->primary_address.address->address_length) && 1394 if ((0 == n->primary_address.address->address_length) &&
1374 (NULL == n->primary_address.session)) 1395 (NULL == n->primary_address.session))
1375 { 1396 {
1376 /* no address, why are we here? */ 1397 /* no address, why are we here? */
1377 GNUNET_break(0); 1398 GNUNET_break (0);
1378 return; 1399 return;
1379 } 1400 }
1380 if (NULL != n->is_active) 1401 if (NULL != n->is_active)
1381 { 1402 {
1382 /* transmission already pending */ 1403 /* transmission already pending */
1383 return; 1404 return;
1384 } 1405 }
1385 1406
1386 /* timeout messages from the queue that are past their due date */ 1407 /* timeout messages from the queue that are past their due date */
1387 while (NULL != (mq = n->messages_head)) 1408 while (NULL != (mq = n->messages_head))
1388 { 1409 {
1389 timeout = GNUNET_TIME_absolute_get_remaining(mq->timeout); 1410 timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
1390 if (timeout.rel_value_us > 0) 1411 if (timeout.rel_value_us > 0)
1391 break; 1412 break;
1392 GNUNET_STATISTICS_update(GST_stats, 1413 GNUNET_STATISTICS_update (GST_stats,
1393 gettext_noop("# messages timed out while in transport queue"), 1414 gettext_noop (
1394 1, 1415 "# messages timed out while in transport queue"),
1395 GNUNET_NO); 1416 1,
1396 GNUNET_CONTAINER_DLL_remove(n->messages_head, 1417 GNUNET_NO);
1397 n->messages_tail, 1418 GNUNET_CONTAINER_DLL_remove (n->messages_head,
1398 mq); 1419 n->messages_tail,
1399 n->is_active = mq; 1420 mq);
1400 transmit_send_continuation(mq, 1421 n->is_active = mq;
1401 &n->id, 1422 transmit_send_continuation (mq,
1402 GNUNET_SYSERR, 1423 &n->id,
1403 mq->message_buf_size, 1424 GNUNET_SYSERR,
1404 0); /* timeout */ 1425 mq->message_buf_size,
1405 } 1426 0); /* timeout */
1427 }
1406 if (NULL == mq) 1428 if (NULL == mq)
1407 return; /* no more messages */ 1429 return; /* no more messages */
1408 if (NULL == n->primary_address.address) 1430 if (NULL == n->primary_address.address)
1409 { 1431 {
1410 /* transmit_send_continuation() caused us to drop session, 1432 /* transmit_send_continuation() caused us to drop session,
1411 can't try transmission anymore. */ 1433 can't try transmission anymore. */
1412 return; 1434 return;
1413 } 1435 }
1414 1436
1415 1437
1416 GNUNET_CONTAINER_DLL_remove(n->messages_head, 1438 GNUNET_CONTAINER_DLL_remove (n->messages_head,
1417 n->messages_tail, 1439 n->messages_tail,
1418 mq); 1440 mq);
1419 n->is_active = mq; 1441 n->is_active = mq;
1420 1442
1421 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1422 "Giving message with %u bytes to plugin session %p\n", 1444 "Giving message with %u bytes to plugin session %p\n",
1423 (unsigned int)mq->message_buf_size, 1445 (unsigned int) mq->message_buf_size,
1424 n->primary_address.session); 1446 n->primary_address.session);
1425 (void)send_with_session(n, 1447 (void) send_with_session (n,
1426 mq->message_buf, 1448 mq->message_buf,
1427 mq->message_buf_size, 1449 mq->message_buf_size,
1428 0 /* priority */, 1450 0 /* priority */,
1429 timeout, 1451 timeout,
1430 GNUNET_NO, 1452 GNUNET_NO,
1431 &transmit_send_continuation, 1453 &transmit_send_continuation,
1432 mq); 1454 mq);
1433} 1455}
1434 1456
1435 1457
@@ -1442,45 +1464,45 @@ try_transmission_to_peer(struct NeighbourMapEntry *n)
1442 * @param n neighbour that went idle and needs a keepalive 1464 * @param n neighbour that went idle and needs a keepalive
1443 */ 1465 */
1444static void 1466static void
1445send_keepalive(struct NeighbourMapEntry *n) 1467send_keepalive (struct NeighbourMapEntry *n)
1446{ 1468{
1447 struct GNUNET_ATS_SessionKeepAliveMessage m; 1469 struct GNUNET_ATS_SessionKeepAliveMessage m;
1448 struct GNUNET_TIME_Relative timeout; 1470 struct GNUNET_TIME_Relative timeout;
1449 uint32_t nonce; 1471 uint32_t nonce;
1450 1472
1451 GNUNET_assert((GNUNET_TRANSPORT_PS_CONNECTED == n->state) || 1473 GNUNET_assert ((GNUNET_TRANSPORT_PS_CONNECTED == n->state) ||
1452 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)); 1474 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state));
1453 if (GNUNET_TIME_absolute_get_remaining(n->keep_alive_time).rel_value_us > 0) 1475 if (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time).rel_value_us > 0)
1454 return; /* no keepalive needed at this time */ 1476 return; /* no keepalive needed at this time */
1455 1477
1456 nonce = 0; /* 0 indicates 'not set' */ 1478 nonce = 0; /* 0 indicates 'not set' */
1457 while (0 == nonce) 1479 while (0 == nonce)
1458 nonce = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 1480 nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1459 UINT32_MAX); 1481 UINT32_MAX);
1460 1482
1461 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1462 "Sending KEEPALIVE to peer `%s' with nonce %u\n", 1484 "Sending KEEPALIVE to peer `%s' with nonce %u\n",
1463 GNUNET_i2s(&n->id), 1485 GNUNET_i2s (&n->id),
1464 nonce); 1486 nonce);
1465 m.header.size = htons(sizeof(struct GNUNET_ATS_SessionKeepAliveMessage)); 1487 m.header.size = htons (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage));
1466 m.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); 1488 m.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
1467 m.nonce = htonl(nonce); 1489 m.nonce = htonl (nonce);
1468 1490
1469 timeout = send_with_session(n, 1491 timeout = send_with_session (n,
1470 &m, 1492 &m,
1471 sizeof(m), 1493 sizeof(m),
1472 UINT32_MAX /* priority */, 1494 UINT32_MAX /* priority */,
1473 GNUNET_TIME_UNIT_FOREVER_REL, 1495 GNUNET_TIME_UNIT_FOREVER_REL,
1474 GNUNET_YES, 1496 GNUNET_YES,
1475 NULL, NULL); 1497 NULL, NULL);
1476 GNUNET_STATISTICS_update(GST_stats, 1498 GNUNET_STATISTICS_update (GST_stats,
1477 gettext_noop("# KEEPALIVES sent"), 1499 gettext_noop ("# KEEPALIVES sent"),
1478 1, 1500 1,
1479 GNUNET_NO); 1501 GNUNET_NO);
1480 n->primary_address.keep_alive_nonce = nonce; 1502 n->primary_address.keep_alive_nonce = nonce;
1481 n->expect_latency_response = GNUNET_YES; 1503 n->expect_latency_response = GNUNET_YES;
1482 n->last_keep_alive_time = GNUNET_TIME_absolute_get(); 1504 n->last_keep_alive_time = GNUNET_TIME_absolute_get ();
1483 n->keep_alive_time = GNUNET_TIME_relative_to_absolute(timeout); 1505 n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout);
1484} 1506}
1485 1507
1486 1508
@@ -1492,57 +1514,59 @@ send_keepalive(struct NeighbourMapEntry *n)
1492 * @param m the keep alive message containing the nonce to respond to 1514 * @param m the keep alive message containing the nonce to respond to
1493 */ 1515 */
1494void 1516void
1495GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour, 1517GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
1496 const struct GNUNET_MessageHeader *m) 1518 const struct GNUNET_MessageHeader *m)
1497{ 1519{
1498 struct NeighbourMapEntry *n; 1520 struct NeighbourMapEntry *n;
1499 const struct GNUNET_ATS_SessionKeepAliveMessage *msg_in; 1521 const struct GNUNET_ATS_SessionKeepAliveMessage *msg_in;
1500 struct GNUNET_ATS_SessionKeepAliveMessage msg; 1522 struct GNUNET_ATS_SessionKeepAliveMessage msg;
1501 1523
1502 if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs(m->size)) 1524 if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs (m->size))
1503 { 1525 {
1504 GNUNET_break_op(0); 1526 GNUNET_break_op (0);
1505 return; 1527 return;
1506 } 1528 }
1507 1529
1508 msg_in = (const struct GNUNET_ATS_SessionKeepAliveMessage *)m; 1530 msg_in = (const struct GNUNET_ATS_SessionKeepAliveMessage *) m;
1509 if (NULL == (n = lookup_neighbour(neighbour))) 1531 if (NULL == (n = lookup_neighbour (neighbour)))
1510 { 1532 {
1511 GNUNET_STATISTICS_update(GST_stats, 1533 GNUNET_STATISTICS_update (GST_stats,
1512 gettext_noop 1534 gettext_noop
1513 ("# KEEPALIVE messages discarded (peer unknown)"), 1535 ("# KEEPALIVE messages discarded (peer unknown)"),
1514 1, GNUNET_NO); 1536 1, GNUNET_NO);
1515 return; 1537 return;
1516 } 1538 }
1517 if (NULL == n->primary_address.session) 1539 if (NULL == n->primary_address.session)
1518 { 1540 {
1519 GNUNET_STATISTICS_update(GST_stats, 1541 GNUNET_STATISTICS_update (GST_stats,
1520 gettext_noop 1542 gettext_noop
1521 ("# KEEPALIVE messages discarded (no session)"), 1543 ("# KEEPALIVE messages discarded (no session)"),
1522 1, GNUNET_NO); 1544 1, GNUNET_NO);
1523 return; 1545 return;
1524 } 1546 }
1525 1547
1526 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1527 "Received KEEPALIVE request from peer `%s' with nonce %u\n", 1549 "Received KEEPALIVE request from peer `%s' with nonce %u\n",
1528 GNUNET_i2s(&n->id), 1550 GNUNET_i2s (&n->id),
1529 ntohl(msg_in->nonce)); 1551 ntohl (msg_in->nonce));
1530 GNUNET_STATISTICS_update(GST_stats, 1552 GNUNET_STATISTICS_update (GST_stats,
1531 gettext_noop("# KEEPALIVES received in good order"), 1553 gettext_noop (
1532 1, 1554 "# KEEPALIVES received in good order"),
1533 GNUNET_NO); 1555 1,
1556 GNUNET_NO);
1534 1557
1535 /* send reply to allow neighbour to measure latency */ 1558 /* send reply to allow neighbour to measure latency */
1536 msg.header.size = htons(sizeof(struct GNUNET_ATS_SessionKeepAliveMessage)); 1559 msg.header.size = htons (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage));
1537 msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); 1560 msg.header.type = htons (
1561 GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE);
1538 msg.nonce = msg_in->nonce; 1562 msg.nonce = msg_in->nonce;
1539 (void)send_with_session(n, 1563 (void) send_with_session (n,
1540 &msg, 1564 &msg,
1541 sizeof(struct GNUNET_ATS_SessionKeepAliveMessage), 1565 sizeof(struct GNUNET_ATS_SessionKeepAliveMessage),
1542 UINT32_MAX /* priority */, 1566 UINT32_MAX /* priority */,
1543 GNUNET_TIME_UNIT_FOREVER_REL, 1567 GNUNET_TIME_UNIT_FOREVER_REL,
1544 GNUNET_YES, 1568 GNUNET_YES,
1545 NULL, NULL); 1569 NULL, NULL);
1546} 1570}
1547 1571
1548 1572
@@ -1555,97 +1579,105 @@ GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour,
1555 * @param m the message containing the keep alive response 1579 * @param m the message containing the keep alive response
1556 */ 1580 */
1557void 1581void
1558GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour, 1582GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
1559 const struct GNUNET_MessageHeader *m) 1583 const struct GNUNET_MessageHeader *m)
1560{ 1584{
1561 struct NeighbourMapEntry *n; 1585 struct NeighbourMapEntry *n;
1562 const struct GNUNET_ATS_SessionKeepAliveMessage *msg; 1586 const struct GNUNET_ATS_SessionKeepAliveMessage *msg;
1563 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1587 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1564 struct GNUNET_TIME_Relative latency; 1588 struct GNUNET_TIME_Relative latency;
1565 1589
1566 if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs(m->size)) 1590 if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs (m->size))
1567 { 1591 {
1568 GNUNET_break_op(0); 1592 GNUNET_break_op (0);
1569 return; 1593 return;
1570 } 1594 }
1571 1595
1572 msg = (const struct GNUNET_ATS_SessionKeepAliveMessage *)m; 1596 msg = (const struct GNUNET_ATS_SessionKeepAliveMessage *) m;
1573 if (NULL == (n = lookup_neighbour(neighbour))) 1597 if (NULL == (n = lookup_neighbour (neighbour)))
1574 { 1598 {
1575 GNUNET_STATISTICS_update(GST_stats, 1599 GNUNET_STATISTICS_update (GST_stats,
1576 gettext_noop("# KEEPALIVE_RESPONSEs discarded (not connected)"), 1600 gettext_noop (
1577 1, 1601 "# KEEPALIVE_RESPONSEs discarded (not connected)"),
1578 GNUNET_NO); 1602 1,
1579 return; 1603 GNUNET_NO);
1580 } 1604 return;
1605 }
1581 if ((GNUNET_TRANSPORT_PS_CONNECTED != n->state) || 1606 if ((GNUNET_TRANSPORT_PS_CONNECTED != n->state) ||
1582 (GNUNET_YES != n->expect_latency_response)) 1607 (GNUNET_YES != n->expect_latency_response))
1583 { 1608 {
1584 GNUNET_STATISTICS_update(GST_stats, 1609 GNUNET_STATISTICS_update (GST_stats,
1585 gettext_noop("# KEEPALIVE_RESPONSEs discarded (not expected)"), 1610 gettext_noop (
1586 1, 1611 "# KEEPALIVE_RESPONSEs discarded (not expected)"),
1587 GNUNET_NO); 1612 1,
1588 return; 1613 GNUNET_NO);
1589 } 1614 return;
1615 }
1590 if (NULL == n->primary_address.address) 1616 if (NULL == n->primary_address.address)
1591 { 1617 {
1592 GNUNET_STATISTICS_update(GST_stats, 1618 GNUNET_STATISTICS_update (GST_stats,
1593 gettext_noop("# KEEPALIVE_RESPONSEs discarded (address changed)"), 1619 gettext_noop (
1594 1, 1620 "# KEEPALIVE_RESPONSEs discarded (address changed)"),
1595 GNUNET_NO); 1621 1,
1596 return; 1622 GNUNET_NO);
1597 } 1623 return;
1598 if (n->primary_address.keep_alive_nonce != ntohl(msg->nonce)) 1624 }
1599 { 1625 if (n->primary_address.keep_alive_nonce != ntohl (msg->nonce))
1600 if (0 == n->primary_address.keep_alive_nonce) 1626 {
1601 GNUNET_STATISTICS_update(GST_stats, 1627 if (0 == n->primary_address.keep_alive_nonce)
1602 gettext_noop("# KEEPALIVE_RESPONSEs discarded (no nonce)"), 1628 GNUNET_STATISTICS_update (GST_stats,
1603 1, 1629 gettext_noop (
1604 GNUNET_NO); 1630 "# KEEPALIVE_RESPONSEs discarded (no nonce)"),
1605 else 1631 1,
1606 GNUNET_STATISTICS_update(GST_stats, 1632 GNUNET_NO);
1607 gettext_noop("# KEEPALIVE_RESPONSEs discarded (bad nonce)"), 1633 else
1608 1, 1634 GNUNET_STATISTICS_update (GST_stats,
1609 GNUNET_NO); 1635 gettext_noop (
1610 return; 1636 "# KEEPALIVE_RESPONSEs discarded (bad nonce)"),
1611 } 1637 1,
1612 GNUNET_STATISTICS_update(GST_stats, 1638 GNUNET_NO);
1613 gettext_noop("# KEEPALIVE_RESPONSEs received (OK)"), 1639 return;
1614 1, 1640 }
1615 GNUNET_NO); 1641 GNUNET_STATISTICS_update (GST_stats,
1642 gettext_noop (
1643 "# KEEPALIVE_RESPONSEs received (OK)"),
1644 1,
1645 GNUNET_NO);
1616 1646
1617 1647
1618 /* Update session timeout here */ 1648 /* Update session timeout here */
1619 if (NULL != (papi = GST_plugins_find(n->primary_address.address->transport_name))) 1649 if (NULL != (papi = GST_plugins_find (
1620 { 1650 n->primary_address.address->transport_name)))
1621 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1651 {
1622 "Updating session for peer `%s' for session %p\n", 1652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1623 GNUNET_i2s(&n->id), 1653 "Updating session for peer `%s' for session %p\n",
1624 n->primary_address.session); 1654 GNUNET_i2s (&n->id),
1625 papi->update_session_timeout(papi->cls, 1655 n->primary_address.session);
1626 &n->id, 1656 papi->update_session_timeout (papi->cls,
1627 n->primary_address.session); 1657 &n->id,
1628 } 1658 n->primary_address.session);
1659 }
1629 else 1660 else
1630 { 1661 {
1631 GNUNET_break(0); 1662 GNUNET_break (0);
1632 } 1663 }
1633 1664
1634 n->primary_address.keep_alive_nonce = 0; 1665 n->primary_address.keep_alive_nonce = 0;
1635 n->expect_latency_response = GNUNET_NO; 1666 n->expect_latency_response = GNUNET_NO;
1636 set_state_and_timeout(n, 1667 set_state_and_timeout (n,
1637 n->state, 1668 n->state,
1638 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 1669 GNUNET_TIME_relative_to_absolute (
1639 1670 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
1640 latency = GNUNET_TIME_absolute_get_duration(n->last_keep_alive_time); 1671
1641 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1672 latency = GNUNET_TIME_absolute_get_duration (n->last_keep_alive_time);
1642 "Received KEEPALIVE_RESPONSE from peer `%s', latency is %s\n", 1673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1643 GNUNET_i2s(&n->id), 1674 "Received KEEPALIVE_RESPONSE from peer `%s', latency is %s\n",
1644 GNUNET_STRINGS_relative_time_to_string(latency, 1675 GNUNET_i2s (&n->id),
1645 GNUNET_YES)); 1676 GNUNET_STRINGS_relative_time_to_string (latency,
1646 GST_ats_update_delay(n->primary_address.address, 1677 GNUNET_YES));
1647 GNUNET_TIME_relative_divide(latency, 1678 GST_ats_update_delay (n->primary_address.address,
1648 2)); 1679 GNUNET_TIME_relative_divide (latency,
1680 2));
1649} 1681}
1650 1682
1651 1683
@@ -1662,74 +1694,76 @@ GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour,
1662 * @return how long to wait before reading more from this sender 1694 * @return how long to wait before reading more from this sender
1663 */ 1695 */
1664struct GNUNET_TIME_Relative 1696struct GNUNET_TIME_Relative
1665GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender, 1697GST_neighbours_calculate_receive_delay (const struct
1666 ssize_t size, 1698 GNUNET_PeerIdentity *sender,
1667 int *do_forward) 1699 ssize_t size,
1700 int *do_forward)
1668{ 1701{
1669 struct NeighbourMapEntry *n; 1702 struct NeighbourMapEntry *n;
1670 struct GNUNET_TIME_Relative ret; 1703 struct GNUNET_TIME_Relative ret;
1671 1704
1672 if (NULL == neighbours) 1705 if (NULL == neighbours)
1673 { 1706 {
1674 *do_forward = GNUNET_NO; 1707 *do_forward = GNUNET_NO;
1675 return GNUNET_TIME_UNIT_FOREVER_REL; /* This can happen during shutdown */ 1708 return GNUNET_TIME_UNIT_FOREVER_REL; /* This can happen during shutdown */
1676 } 1709 }
1677 if (NULL == (n = lookup_neighbour(sender))) 1710 if (NULL == (n = lookup_neighbour (sender)))
1678 { 1711 {
1679 GNUNET_STATISTICS_update(GST_stats, 1712 GNUNET_STATISTICS_update (GST_stats,
1680 gettext_noop("# messages discarded due to lack of neighbour record"), 1713 gettext_noop (
1681 1, 1714 "# messages discarded due to lack of neighbour record"),
1682 GNUNET_NO); 1715 1,
1683 *do_forward = GNUNET_NO; 1716 GNUNET_NO);
1684 return GNUNET_TIME_UNIT_ZERO; 1717 *do_forward = GNUNET_NO;
1685 } 1718 return GNUNET_TIME_UNIT_ZERO;
1686 if (!test_connected(n)) 1719 }
1687 { 1720 if (! test_connected (n))
1688 *do_forward = GNUNET_SYSERR; 1721 {
1689 return GNUNET_TIME_UNIT_ZERO; 1722 *do_forward = GNUNET_SYSERR;
1690 } 1723 return GNUNET_TIME_UNIT_ZERO;
1691 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, size)) 1724 }
1692 { 1725 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, size))
1693 n->quota_violation_count++; 1726 {
1694 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1727 n->quota_violation_count++;
1695 "Bandwidth quota (%u b/s) violation detected (total of %u).\n", 1728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1696 n->in_tracker.available_bytes_per_s__, 1729 "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
1697 n->quota_violation_count); 1730 n->in_tracker.available_bytes_per_s__,
1698 /* Discount 32k per violation */ 1731 n->quota_violation_count);
1699 GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, -32 * 1024); 1732 /* Discount 32k per violation */
1700 } 1733 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, -32 * 1024);
1734 }
1701 else 1735 else
1736 {
1737 if (n->quota_violation_count > 0)
1702 { 1738 {
1703 if (n->quota_violation_count > 0) 1739 /* try to add 32k back */
1704 { 1740 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 32 * 1024);
1705 /* try to add 32k back */ 1741 n->quota_violation_count--;
1706 GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, 32 * 1024);
1707 n->quota_violation_count--;
1708 }
1709 } 1742 }
1743 }
1710 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) 1744 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
1711 { 1745 {
1712 GNUNET_STATISTICS_update(GST_stats, 1746 GNUNET_STATISTICS_update (GST_stats,
1713 gettext_noop 1747 gettext_noop
1714 ("# bandwidth quota violations by other peers"), 1748 ("# bandwidth quota violations by other peers"),
1715 1, GNUNET_NO); 1749 1, GNUNET_NO);
1716 *do_forward = GNUNET_NO; 1750 *do_forward = GNUNET_NO;
1717 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT; 1751 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
1718 } 1752 }
1719 *do_forward = GNUNET_YES; 1753 *do_forward = GNUNET_YES;
1720 ret = GNUNET_BANDWIDTH_tracker_get_delay(&n->in_tracker, 32 * 1024); 1754 ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 32 * 1024);
1721 if (ret.rel_value_us > 0) 1755 if (ret.rel_value_us > 0)
1722 { 1756 {
1723 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1724 "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n", 1758 "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n",
1725 (long long)n->in_tracker.consumption_since_last_update__, 1759 (long long) n->in_tracker.consumption_since_last_update__,
1726 (unsigned int)n->in_tracker.available_bytes_per_s__, 1760 (unsigned int) n->in_tracker.available_bytes_per_s__,
1727 GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); 1761 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
1728 GNUNET_STATISTICS_update(GST_stats, 1762 GNUNET_STATISTICS_update (GST_stats,
1729 gettext_noop("# ms throttling suggested"), 1763 gettext_noop ("# ms throttling suggested"),
1730 (int64_t)ret.rel_value_us / 1000LL, 1764 (int64_t) ret.rel_value_us / 1000LL,
1731 GNUNET_NO); 1765 GNUNET_NO);
1732 } 1766 }
1733 return ret; 1767 return ret;
1734} 1768}
1735 1769
@@ -1745,61 +1779,61 @@ GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender,
1745 * @param cont_cls closure for @a cont 1779 * @param cont_cls closure for @a cont
1746 */ 1780 */
1747void 1781void
1748GST_neighbours_send(const struct GNUNET_PeerIdentity *target, 1782GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
1749 const void *msg, 1783 const void *msg,
1750 size_t msg_size, 1784 size_t msg_size,
1751 struct GNUNET_TIME_Relative timeout, 1785 struct GNUNET_TIME_Relative timeout,
1752 GST_NeighbourSendContinuation cont, 1786 GST_NeighbourSendContinuation cont,
1753 void *cont_cls) 1787 void *cont_cls)
1754{ 1788{
1755 struct NeighbourMapEntry *n; 1789 struct NeighbourMapEntry *n;
1756 struct MessageQueue *mq; 1790 struct MessageQueue *mq;
1757 1791
1758 /* All ove these cases should never happen; they are all API violations. 1792 /* All ove these cases should never happen; they are all API violations.
1759 But we check anyway, just to be sure. */ 1793 But we check anyway, just to be sure. */
1760 if (NULL == (n = lookup_neighbour(target))) 1794 if (NULL == (n = lookup_neighbour (target)))
1761 { 1795 {
1762 GNUNET_break(0); 1796 GNUNET_break (0);
1763 if (NULL != cont) 1797 if (NULL != cont)
1764 cont(cont_cls, 1798 cont (cont_cls,
1765 GNUNET_SYSERR, 1799 GNUNET_SYSERR,
1766 msg_size, 1800 msg_size,
1767 0); 1801 0);
1768 return; 1802 return;
1769 } 1803 }
1770 if (GNUNET_YES != test_connected(n)) 1804 if (GNUNET_YES != test_connected (n))
1771 { 1805 {
1772 GNUNET_break(0); 1806 GNUNET_break (0);
1773 if (NULL != cont) 1807 if (NULL != cont)
1774 cont(cont_cls, 1808 cont (cont_cls,
1775 GNUNET_SYSERR, 1809 GNUNET_SYSERR,
1776 msg_size, 1810 msg_size,
1777 0); 1811 0);
1778 return; 1812 return;
1779 } 1813 }
1780 bytes_in_send_queue += msg_size; 1814 bytes_in_send_queue += msg_size;
1781 GNUNET_STATISTICS_set(GST_stats, 1815 GNUNET_STATISTICS_set (GST_stats,
1782 gettext_noop 1816 gettext_noop
1783 ("# bytes in message queue for other peers"), 1817 ("# bytes in message queue for other peers"),
1784 bytes_in_send_queue, GNUNET_NO); 1818 bytes_in_send_queue, GNUNET_NO);
1785 mq = GNUNET_malloc(sizeof(struct MessageQueue) + msg_size); 1819 mq = GNUNET_malloc (sizeof(struct MessageQueue) + msg_size);
1786 mq->cont = cont; 1820 mq->cont = cont;
1787 mq->cont_cls = cont_cls; 1821 mq->cont_cls = cont_cls;
1788 GNUNET_memcpy(&mq[1], msg, msg_size); 1822 GNUNET_memcpy (&mq[1], msg, msg_size);
1789 mq->message_buf = (const char *)&mq[1]; 1823 mq->message_buf = (const char *) &mq[1];
1790 mq->message_buf_size = msg_size; 1824 mq->message_buf_size = msg_size;
1791 mq->timeout = GNUNET_TIME_relative_to_absolute(timeout); 1825 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1792 1826
1793 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1794 "Enqueueing %u bytes to send to peer %s\n", 1828 "Enqueueing %u bytes to send to peer %s\n",
1795 (unsigned int)msg_size, 1829 (unsigned int) msg_size,
1796 GNUNET_i2s(target)); 1830 GNUNET_i2s (target));
1797 GNUNET_CONTAINER_DLL_insert_tail(n->messages_head, 1831 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head,
1798 n->messages_tail, 1832 n->messages_tail,
1799 mq); 1833 mq);
1800 if (NULL != n->task) 1834 if (NULL != n->task)
1801 GNUNET_SCHEDULER_cancel(n->task); 1835 GNUNET_SCHEDULER_cancel (n->task);
1802 n->task = GNUNET_SCHEDULER_add_now(&master_task, n); 1836 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
1803} 1837}
1804 1838
1805 1839
@@ -1816,77 +1850,81 @@ GST_neighbours_send(const struct GNUNET_PeerIdentity *target,
1816 * @param size_on_wire how much bandwidth was consumed on the wire (ignored) 1850 * @param size_on_wire how much bandwidth was consumed on the wire (ignored)
1817 */ 1851 */
1818static void 1852static void
1819send_session_syn_cont(void *cls, 1853send_session_syn_cont (void *cls,
1820 const struct GNUNET_PeerIdentity *target, 1854 const struct GNUNET_PeerIdentity *target,
1821 int result, 1855 int result,
1822 size_t size_payload, 1856 size_t size_payload,
1823 size_t size_on_wire) 1857 size_t size_on_wire)
1824{ 1858{
1825 struct NeighbourMapEntry *n; 1859 struct NeighbourMapEntry *n;
1826 1860
1827 (void)cls; 1861 (void) cls;
1828 (void)size_payload; 1862 (void) size_payload;
1829 (void)size_on_wire; 1863 (void) size_on_wire;
1830 n = lookup_neighbour(target); 1864 n = lookup_neighbour (target);
1831 if (NULL == n) 1865 if (NULL == n)
1832 { 1866 {
1833 /* SYN continuation was called after neighbor was freed, 1867 /* SYN continuation was called after neighbor was freed,
1834 * for example due to a time out for the state or the session 1868 * for example due to a time out for the state or the session
1835 * used was already terminated: nothing to do here... */ 1869 * used was already terminated: nothing to do here... */
1836 return; 1870 return;
1837 } 1871 }
1838 1872
1839 if ((GNUNET_TRANSPORT_PS_SYN_SENT != n->state) && 1873 if ((GNUNET_TRANSPORT_PS_SYN_SENT != n->state) &&
1840 (GNUNET_TRANSPORT_PS_RECONNECT_SENT != n->state) && 1874 (GNUNET_TRANSPORT_PS_RECONNECT_SENT != n->state) &&
1841 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT != n->state)) 1875 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT != n->state))
1842 { 1876 {
1843 /* SYN continuation was called after neighbor changed state, 1877 /* SYN continuation was called after neighbor changed state,
1844 * for example due to a time out for the state or the session 1878 * for example due to a time out for the state or the session
1845 * used was already terminated: nothing to do here... */ 1879 * used was already terminated: nothing to do here... */
1846 return; 1880 return;
1847 } 1881 }
1848 if (GNUNET_OK == result) 1882 if (GNUNET_OK == result)
1849 return; 1883 return;
1850 1884
1851 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1885 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1852 _("Failed to send SYN message to peer `%s'\n"), 1886 _ ("Failed to send SYN message to peer `%s'\n"),
1853 GNUNET_i2s(target)); 1887 GNUNET_i2s (target));
1854 switch (n->state) 1888 switch (n->state)
1855 { 1889 {
1856 case GNUNET_TRANSPORT_PS_SYN_SENT: 1890 case GNUNET_TRANSPORT_PS_SYN_SENT:
1857 /* Remove address and request an additional one */ 1891 /* Remove address and request an additional one */
1858 unset_primary_address(n); 1892 unset_primary_address (n);
1859 set_state_and_timeout(n, 1893 set_state_and_timeout (n,
1860 GNUNET_TRANSPORT_PS_INIT_ATS, 1894 GNUNET_TRANSPORT_PS_INIT_ATS,
1861 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT)); 1895 GNUNET_TIME_relative_to_absolute (
1862 break; 1896 FAST_RECONNECT_TIMEOUT));
1863 1897 break;
1864 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 1898
1865 /* Remove address and request an additional one */ 1899 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1866 unset_primary_address(n); 1900 /* Remove address and request an additional one */
1867 set_state_and_timeout(n, 1901 unset_primary_address (n);
1868 GNUNET_TRANSPORT_PS_RECONNECT_ATS, 1902 set_state_and_timeout (n,
1869 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 1903 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1870 break; 1904 GNUNET_TIME_relative_to_absolute (
1871 1905 ATS_RESPONSE_TIMEOUT));
1872 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 1906 break;
1873 /* Remove address and request and go back to primary address */ 1907
1874 GNUNET_STATISTICS_update(GST_stats, 1908 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1875 gettext_noop("# Failed attempts to switch addresses (failed to send SYN CONT)"), 1909 /* Remove address and request and go back to primary address */
1876 1, 1910 GNUNET_STATISTICS_update (GST_stats,
1877 GNUNET_NO); 1911 gettext_noop (
1878 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1912 "# Failed attempts to switch addresses (failed to send SYN CONT)"),
1879 "Switch failed, cleaning up alternative address\n"); 1913 1,
1880 free_address(&n->alternative_address); 1914 GNUNET_NO);
1881 set_state_and_timeout(n, 1915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1882 GNUNET_TRANSPORT_PS_CONNECTED, 1916 "Switch failed, cleaning up alternative address\n");
1883 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 1917 free_address (&n->alternative_address);
1884 break; 1918 set_state_and_timeout (n,
1885 1919 GNUNET_TRANSPORT_PS_CONNECTED,
1886 default: 1920 GNUNET_TIME_relative_to_absolute (
1887 disconnect_neighbour(n); 1921 ATS_RESPONSE_TIMEOUT));
1888 break; 1922 break;
1889 } 1923
1924 default:
1925 disconnect_neighbour (n);
1926 break;
1927 }
1890} 1928}
1891 1929
1892 1930
@@ -1896,94 +1934,98 @@ send_session_syn_cont(void *cls,
1896 * @param na address to use 1934 * @param na address to use
1897 */ 1935 */
1898static void 1936static void
1899send_syn(struct NeighbourAddress *na) 1937send_syn (struct NeighbourAddress *na)
1900{ 1938{
1901 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1939 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1902 struct TransportSynMessage connect_msg; 1940 struct TransportSynMessage connect_msg;
1903 struct NeighbourMapEntry *n; 1941 struct NeighbourMapEntry *n;
1904 1942
1905 GNUNET_assert(NULL != na->session); 1943 GNUNET_assert (NULL != na->session);
1906 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1944 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1907 "Sending SYN message to peer `%s' at %s\n", 1945 "Sending SYN message to peer `%s' at %s\n",
1908 GNUNET_i2s(&na->address->peer), 1946 GNUNET_i2s (&na->address->peer),
1909 GST_plugins_a2s(na->address)); 1947 GST_plugins_a2s (na->address));
1910 1948
1911 papi = GST_plugins_find(na->address->transport_name); 1949 papi = GST_plugins_find (na->address->transport_name);
1912 GNUNET_assert(NULL != papi); 1950 GNUNET_assert (NULL != papi);
1913 GNUNET_STATISTICS_update(GST_stats, 1951 GNUNET_STATISTICS_update (GST_stats,
1914 gettext_noop 1952 gettext_noop
1915 ("# SYN messages sent"), 1953 ("# SYN messages sent"),
1916 1, GNUNET_NO); 1954 1, GNUNET_NO);
1917 na->connect_timestamp = GNUNET_TIME_absolute_get(); 1955 na->connect_timestamp = GNUNET_TIME_absolute_get ();
1918 connect_msg.header.size = htons(sizeof(struct TransportSynMessage)); 1956 connect_msg.header.size = htons (sizeof(struct TransportSynMessage));
1919 connect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN); 1957 connect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN);
1920 connect_msg.reserved = htonl(0); 1958 connect_msg.reserved = htonl (0);
1921 connect_msg.timestamp = GNUNET_TIME_absolute_hton(na->connect_timestamp); 1959 connect_msg.timestamp = GNUNET_TIME_absolute_hton (na->connect_timestamp);
1922 if (-1 == 1960 if (-1 ==
1923 papi->send(papi->cls, 1961 papi->send (papi->cls,
1924 na->session, 1962 na->session,
1925 (const char *)&connect_msg, 1963 (const char *) &connect_msg,
1926 sizeof(struct TransportSynMessage), 1964 sizeof(struct TransportSynMessage),
1927 UINT_MAX, 1965 UINT_MAX,
1928 SETUP_CONNECTION_TIMEOUT, 1966 SETUP_CONNECTION_TIMEOUT,
1929 &send_session_syn_cont, NULL)) 1967 &send_session_syn_cont, NULL))
1930 { 1968 {
1931 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1969 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1932 _("Failed to transmit SYN message to %s\n"), 1970 _ ("Failed to transmit SYN message to %s\n"),
1933 GST_plugins_a2s(na->address)); 1971 GST_plugins_a2s (na->address));
1934 n = lookup_neighbour(&na->address->peer); 1972 n = lookup_neighbour (&na->address->peer);
1935 if (NULL == n) 1973 if (NULL == n)
1936 { 1974 {
1937 GNUNET_break(0); 1975 GNUNET_break (0);
1938 return;
1939 }
1940 switch (n->state)
1941 {
1942 case GNUNET_TRANSPORT_PS_SYN_SENT:
1943 /* Remove address and request and additional one */
1944 GNUNET_assert(na == &n->primary_address);
1945 unset_primary_address(n);
1946 set_state_and_timeout(n,
1947 GNUNET_TRANSPORT_PS_INIT_ATS,
1948 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT));
1949 /* Hard failure to send the SYN message with this address:
1950 Destroy address and session */
1951 break;
1952
1953 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1954 /* Remove address and request an additional one */
1955 GNUNET_assert(na == &n->primary_address);
1956 unset_primary_address(n);
1957 set_state_and_timeout(n,
1958 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1959 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
1960 break;
1961
1962 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1963 GNUNET_assert(na == &n->alternative_address);
1964 GNUNET_STATISTICS_update(GST_stats,
1965 gettext_noop("# Failed attempts to switch addresses (failed to send SYN)"),
1966 1,
1967 GNUNET_NO);
1968 /* Remove address and request an additional one */
1969 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1970 "Switch failed, cleaning up alternative address\n");
1971 free_address(&n->alternative_address);
1972 set_state_and_timeout(n,
1973 GNUNET_TRANSPORT_PS_CONNECTED,
1974 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
1975 break;
1976
1977 default:
1978 GNUNET_break(0);
1979 disconnect_neighbour(n);
1980 break;
1981 }
1982 return; 1976 return;
1983 } 1977 }
1984 GST_neighbours_notify_data_sent(na->address, 1978 switch (n->state)
1985 na->session, 1979 {
1986 sizeof(struct TransportSynMessage)); 1980 case GNUNET_TRANSPORT_PS_SYN_SENT:
1981 /* Remove address and request and additional one */
1982 GNUNET_assert (na == &n->primary_address);
1983 unset_primary_address (n);
1984 set_state_and_timeout (n,
1985 GNUNET_TRANSPORT_PS_INIT_ATS,
1986 GNUNET_TIME_relative_to_absolute (
1987 FAST_RECONNECT_TIMEOUT));
1988 /* Hard failure to send the SYN message with this address:
1989 Destroy address and session */
1990 break;
1991
1992 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1993 /* Remove address and request an additional one */
1994 GNUNET_assert (na == &n->primary_address);
1995 unset_primary_address (n);
1996 set_state_and_timeout (n,
1997 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1998 GNUNET_TIME_relative_to_absolute (
1999 ATS_RESPONSE_TIMEOUT));
2000 break;
2001
2002 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2003 GNUNET_assert (na == &n->alternative_address);
2004 GNUNET_STATISTICS_update (GST_stats,
2005 gettext_noop (
2006 "# Failed attempts to switch addresses (failed to send SYN)"),
2007 1,
2008 GNUNET_NO);
2009 /* Remove address and request an additional one */
2010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2011 "Switch failed, cleaning up alternative address\n");
2012 free_address (&n->alternative_address);
2013 set_state_and_timeout (n,
2014 GNUNET_TRANSPORT_PS_CONNECTED,
2015 GNUNET_TIME_relative_to_absolute (
2016 ATS_RESPONSE_TIMEOUT));
2017 break;
2018
2019 default:
2020 GNUNET_break (0);
2021 disconnect_neighbour (n);
2022 break;
2023 }
2024 return;
2025 }
2026 GST_neighbours_notify_data_sent (na->address,
2027 na->session,
2028 sizeof(struct TransportSynMessage));
1987} 2029}
1988 2030
1989 2031
@@ -2000,50 +2042,52 @@ send_syn(struct NeighbourAddress *na)
2000 * @param size_on_wire how much bandwidth was consumed on the wire (ignored) 2042 * @param size_on_wire how much bandwidth was consumed on the wire (ignored)
2001 */ 2043 */
2002static void 2044static void
2003send_session_syn_ack_cont(void *cls, 2045send_session_syn_ack_cont (void *cls,
2004 const struct GNUNET_PeerIdentity *target, 2046 const struct GNUNET_PeerIdentity *target,
2005 int result, 2047 int result,
2006 size_t size_payload, 2048 size_t size_payload,
2007 size_t size_on_wire) 2049 size_t size_on_wire)
2008{ 2050{
2009 struct NeighbourMapEntry *n; 2051 struct NeighbourMapEntry *n;
2010 2052
2011 (void)cls; 2053 (void) cls;
2012 (void)size_payload; 2054 (void) size_payload;
2013 (void)size_on_wire; 2055 (void) size_on_wire;
2014 n = lookup_neighbour(target); 2056 n = lookup_neighbour (target);
2015 if (NULL == n) 2057 if (NULL == n)
2016 { 2058 {
2017 /* SYN_ACK continuation was called after neighbor was freed, 2059 /* SYN_ACK continuation was called after neighbor was freed,
2018 * for example due to a time out for the state or the session 2060 * for example due to a time out for the state or the session
2019 * used was already terminated: nothing to do here... */ 2061 * used was already terminated: nothing to do here... */
2020 return; 2062 return;
2021 } 2063 }
2022 2064
2023 if (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) 2065 if (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state)
2024 { 2066 {
2025 /* SYN_ACK continuation was called after neighbor changed state, 2067 /* SYN_ACK continuation was called after neighbor changed state,
2026 * for example due to a time out for the state or the session 2068 * for example due to a time out for the state or the session
2027 * used was already terminated: nothing to do here... */ 2069 * used was already terminated: nothing to do here... */
2028 return; 2070 return;
2029 } 2071 }
2030 if (GNUNET_OK == result) 2072 if (GNUNET_OK == result)
2031 return; 2073 return;
2032 2074
2033 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2075 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2034 _("Failed to send SYN_ACK message to peer `%s' using address `%s'\n"), 2076 _ (
2035 GNUNET_i2s(target), 2077 "Failed to send SYN_ACK message to peer `%s' using address `%s'\n"),
2036 GST_plugins_a2s(n->primary_address.address)); 2078 GNUNET_i2s (target),
2079 GST_plugins_a2s (n->primary_address.address));
2037 2080
2038 /* Remove address and request and additional one */ 2081 /* Remove address and request and additional one */
2039 /* FIXME: what if the neighbour's primary address 2082 /* FIXME: what if the neighbour's primary address
2040 changed in the meantime? Might want to instead 2083 changed in the meantime? Might want to instead
2041 pass "something" around in closure to be sure. */ 2084 pass "something" around in closure to be sure. */
2042 unset_primary_address(n); 2085 unset_primary_address (n);
2043 n->ack_state = ACK_SEND_SYN_ACK; 2086 n->ack_state = ACK_SEND_SYN_ACK;
2044 set_state_and_timeout(n, 2087 set_state_and_timeout (n,
2045 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2088 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2046 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 2089 GNUNET_TIME_relative_to_absolute (
2090 ATS_RESPONSE_TIMEOUT));
2047} 2091}
2048 2092
2049 2093
@@ -2055,8 +2099,8 @@ send_session_syn_ack_cont(void *cls,
2055 * @return #GNUNET_SYSERR if sending immediately failed, #GNUNET_OK otherwise 2099 * @return #GNUNET_SYSERR if sending immediately failed, #GNUNET_OK otherwise
2056 */ 2100 */
2057static void 2101static void
2058send_syn_ack_message(struct NeighbourAddress *na, 2102send_syn_ack_message (struct NeighbourAddress *na,
2059 struct GNUNET_TIME_Absolute timestamp) 2103 struct GNUNET_TIME_Absolute timestamp)
2060{ 2104{
2061 const struct GNUNET_HELLO_Address *address = na->address; 2105 const struct GNUNET_HELLO_Address *address = na->address;
2062 struct GNUNET_ATS_Session *session = na->session; 2106 struct GNUNET_ATS_Session *session = na->session;
@@ -2064,61 +2108,63 @@ send_syn_ack_message(struct NeighbourAddress *na,
2064 struct TransportSynMessage connect_msg; 2108 struct TransportSynMessage connect_msg;
2065 struct NeighbourMapEntry *n; 2109 struct NeighbourMapEntry *n;
2066 2110
2067 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2111 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2068 "Sending SYN_ACK to peer `%s'\n", 2112 "Sending SYN_ACK to peer `%s'\n",
2069 GNUNET_i2s(&address->peer)); 2113 GNUNET_i2s (&address->peer));
2070 2114
2071 if (NULL == (papi = GST_plugins_find(address->transport_name))) 2115 if (NULL == (papi = GST_plugins_find (address->transport_name)))
2072 { 2116 {
2073 GNUNET_break(0); 2117 GNUNET_break (0);
2074 return; 2118 return;
2075 } 2119 }
2076 if (NULL == session) 2120 if (NULL == session)
2077 session = papi->get_session(papi->cls, 2121 session = papi->get_session (papi->cls,
2078 address); 2122 address);
2079 if (NULL == session) 2123 if (NULL == session)
2080 { 2124 {
2081 GNUNET_break(0); 2125 GNUNET_break (0);
2082 return; 2126 return;
2083 } 2127 }
2084 GST_ats_new_session(address, 2128 GST_ats_new_session (address,
2085 session); 2129 session);
2086 GNUNET_STATISTICS_update(GST_stats, 2130 GNUNET_STATISTICS_update (GST_stats,
2087 gettext_noop 2131 gettext_noop
2088 ("# SYN_ACK messages sent"), 2132 ("# SYN_ACK messages sent"),
2089 1, GNUNET_NO); 2133 1, GNUNET_NO);
2090 connect_msg.header.size = htons(sizeof(struct TransportSynMessage)); 2134 connect_msg.header.size = htons (sizeof(struct TransportSynMessage));
2091 connect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK); 2135 connect_msg.header.type = htons (
2092 connect_msg.reserved = htonl(0); 2136 GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK);
2093 connect_msg.timestamp = GNUNET_TIME_absolute_hton(timestamp); 2137 connect_msg.reserved = htonl (0);
2138 connect_msg.timestamp = GNUNET_TIME_absolute_hton (timestamp);
2094 2139
2095 if (GNUNET_SYSERR == 2140 if (GNUNET_SYSERR ==
2096 papi->send(papi->cls, 2141 papi->send (papi->cls,
2097 session, 2142 session,
2098 (const char *)&connect_msg, 2143 (const char *) &connect_msg,
2099 sizeof(struct TransportSynMessage), 2144 sizeof(struct TransportSynMessage),
2100 UINT_MAX, 2145 UINT_MAX,
2101 GNUNET_TIME_UNIT_FOREVER_REL, 2146 GNUNET_TIME_UNIT_FOREVER_REL,
2102 &send_session_syn_ack_cont, NULL)) 2147 &send_session_syn_ack_cont, NULL))
2103 { 2148 {
2104 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2149 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2105 _("Failed to transmit SYN_ACK message to %s\n"), 2150 _ ("Failed to transmit SYN_ACK message to %s\n"),
2106 GST_plugins_a2s(address)); 2151 GST_plugins_a2s (address));
2107 2152
2108 n = lookup_neighbour(&address->peer); 2153 n = lookup_neighbour (&address->peer);
2109 if (NULL == n) 2154 if (NULL == n)
2110 { 2155 {
2111 GNUNET_break(0); 2156 GNUNET_break (0);
2112 return;
2113 }
2114 /* Remove address and request and additional one */
2115 unset_primary_address(n);
2116 n->ack_state = ACK_SEND_SYN_ACK;
2117 set_state_and_timeout(n,
2118 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2119 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
2120 return; 2157 return;
2121 } 2158 }
2159 /* Remove address and request and additional one */
2160 unset_primary_address (n);
2161 n->ack_state = ACK_SEND_SYN_ACK;
2162 set_state_and_timeout (n,
2163 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2164 GNUNET_TIME_relative_to_absolute (
2165 ATS_RESPONSE_TIMEOUT));
2166 return;
2167 }
2122} 2168}
2123 2169
2124 2170
@@ -2131,7 +2177,7 @@ send_syn_ack_message(struct NeighbourAddress *na,
2131 * @param cls the `struct NeighbourMapEntry` to update calculations for 2177 * @param cls the `struct NeighbourMapEntry` to update calculations for
2132 */ 2178 */
2133static void 2179static void
2134inbound_bw_tracker_update(void *cls) 2180inbound_bw_tracker_update (void *cls)
2135{ 2181{
2136 struct NeighbourMapEntry *n = cls; 2182 struct NeighbourMapEntry *n = cls;
2137 struct GNUNET_TRANSPORT_PluginFunctions *papi; 2183 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -2140,23 +2186,23 @@ inbound_bw_tracker_update(void *cls)
2140 2186
2141 if (NULL == n->primary_address.address) 2187 if (NULL == n->primary_address.address)
2142 return; /* not active, ignore */ 2188 return; /* not active, ignore */
2143 papi = GST_plugins_find(n->primary_address.address->transport_name); 2189 papi = GST_plugins_find (n->primary_address.address->transport_name);
2144 GNUNET_assert(NULL != papi); 2190 GNUNET_assert (NULL != papi);
2145 if (NULL == papi->update_inbound_delay) 2191 if (NULL == papi->update_inbound_delay)
2146 return; 2192 return;
2147 delay = GST_neighbours_calculate_receive_delay(&n->id, 2193 delay = GST_neighbours_calculate_receive_delay (&n->id,
2148 0, 2194 0,
2149 &do_forward); 2195 &do_forward);
2150 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2151 "New inbound delay for peer `%s' is %llu ms\n", 2197 "New inbound delay for peer `%s' is %llu ms\n",
2152 GNUNET_i2s(&n->id), 2198 GNUNET_i2s (&n->id),
2153 (unsigned long long)delay.rel_value_us / 1000LL); 2199 (unsigned long long) delay.rel_value_us / 1000LL);
2154 if (NULL == n->primary_address.session) 2200 if (NULL == n->primary_address.session)
2155 return; 2201 return;
2156 papi->update_inbound_delay(papi->cls, 2202 papi->update_inbound_delay (papi->cls,
2157 &n->id, 2203 &n->id,
2158 n->primary_address.session, 2204 n->primary_address.session,
2159 delay); 2205 delay);
2160} 2206}
2161 2207
2162 2208
@@ -2167,44 +2213,44 @@ inbound_bw_tracker_update(void *cls)
2167 * @return new neighbour map entry 2213 * @return new neighbour map entry
2168 */ 2214 */
2169static struct NeighbourMapEntry * 2215static struct NeighbourMapEntry *
2170setup_neighbour(const struct GNUNET_PeerIdentity *peer) 2216setup_neighbour (const struct GNUNET_PeerIdentity *peer)
2171{ 2217{
2172 struct NeighbourMapEntry *n; 2218 struct NeighbourMapEntry *n;
2173 2219
2174 if (0 == 2220 if (0 ==
2175 memcmp(&GST_my_identity, 2221 memcmp (&GST_my_identity,
2176 peer, 2222 peer,
2177 sizeof(struct GNUNET_PeerIdentity))) 2223 sizeof(struct GNUNET_PeerIdentity)))
2178 { 2224 {
2179 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2180 "Cowardly refusing to consider myself my neighbour!\n"); 2226 "Cowardly refusing to consider myself my neighbour!\n");
2181 return NULL; 2227 return NULL;
2182 } 2228 }
2183 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2184 "Creating new neighbour entry for `%s'\n", 2230 "Creating new neighbour entry for `%s'\n",
2185 GNUNET_i2s(peer)); 2231 GNUNET_i2s (peer));
2186 n = GNUNET_new(struct NeighbourMapEntry); 2232 n = GNUNET_new (struct NeighbourMapEntry);
2187 n->id = *peer; 2233 n->id = *peer;
2188 n->ack_state = ACK_UNDEFINED; 2234 n->ack_state = ACK_UNDEFINED;
2189 n->last_util_transmission = GNUNET_TIME_absolute_get(); 2235 n->last_util_transmission = GNUNET_TIME_absolute_get ();
2190 n->neighbour_receive_quota = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 2236 n->neighbour_receive_quota = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
2191 GNUNET_BANDWIDTH_tracker_init(&n->in_tracker, 2237 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
2192 &inbound_bw_tracker_update, 2238 &inbound_bw_tracker_update,
2193 n, 2239 n,
2194 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 2240 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
2195 MAX_BANDWIDTH_CARRY_S); 2241 MAX_BANDWIDTH_CARRY_S);
2196 n->task = GNUNET_SCHEDULER_add_now(&master_task, n); 2242 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
2197 set_state_and_timeout(n, 2243 set_state_and_timeout (n,
2198 GNUNET_TRANSPORT_PS_NOT_CONNECTED, 2244 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
2199 GNUNET_TIME_UNIT_FOREVER_ABS); 2245 GNUNET_TIME_UNIT_FOREVER_ABS);
2200 GNUNET_assert(GNUNET_OK == 2246 GNUNET_assert (GNUNET_OK ==
2201 GNUNET_CONTAINER_multipeermap_put(neighbours, 2247 GNUNET_CONTAINER_multipeermap_put (neighbours,
2202 &n->id, 2248 &n->id,
2203 n, 2249 n,
2204 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2250 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2205 n->suggest_handle = GNUNET_ATS_connectivity_suggest(GST_ats_connect, 2251 n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect,
2206 peer, 2252 peer,
2207 0); 2253 0);
2208 2254
2209 return n; 2255 return n;
2210} 2256}
@@ -2213,7 +2259,8 @@ setup_neighbour(const struct GNUNET_PeerIdentity *peer)
2213/** 2259/**
2214 * Entry in a DLL we use to keep track of pending blacklist checks. 2260 * Entry in a DLL we use to keep track of pending blacklist checks.
2215 */ 2261 */
2216struct BlacklistCheckSwitchContext { 2262struct BlacklistCheckSwitchContext
2263{
2217 /** 2264 /**
2218 * DLL prev pointer. 2265 * DLL prev pointer.
2219 */ 2266 */
@@ -2250,145 +2297,149 @@ struct BlacklistCheckSwitchContext {
2250 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 2297 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
2251 */ 2298 */
2252int 2299int
2253GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message, 2300GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
2254 const struct GNUNET_PeerIdentity *peer) 2301 const struct GNUNET_PeerIdentity *peer)
2255{ 2302{
2256 const struct TransportSynMessage *scm; 2303 const struct TransportSynMessage *scm;
2257 struct NeighbourMapEntry *n; 2304 struct NeighbourMapEntry *n;
2258 struct GNUNET_TIME_Absolute ts; 2305 struct GNUNET_TIME_Absolute ts;
2259 2306
2260 if (ntohs(message->size) != sizeof(struct TransportSynMessage)) 2307 if (ntohs (message->size) != sizeof(struct TransportSynMessage))
2261 { 2308 {
2262 GNUNET_break_op(0); 2309 GNUNET_break_op (0);
2263 return GNUNET_SYSERR; 2310 return GNUNET_SYSERR;
2264 } 2311 }
2265 GNUNET_STATISTICS_update(GST_stats, 2312 GNUNET_STATISTICS_update (GST_stats,
2266 gettext_noop 2313 gettext_noop
2267 ("# SYN messages received"), 2314 ("# SYN messages received"),
2268 1, GNUNET_NO); 2315 1, GNUNET_NO);
2269 if (NULL == neighbours) 2316 if (NULL == neighbours)
2270 { 2317 {
2271 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2318 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2272 _("SYN request from peer `%s' ignored due impending shutdown\n"), 2319 _ (
2273 GNUNET_i2s(peer)); 2320 "SYN request from peer `%s' ignored due impending shutdown\n"),
2274 return GNUNET_OK; /* we're shutting down */ 2321 GNUNET_i2s (peer));
2275 } 2322 return GNUNET_OK; /* we're shutting down */
2276 scm = (const struct TransportSynMessage *)message; 2323 }
2277 GNUNET_break_op(0 == ntohl(scm->reserved)); 2324 scm = (const struct TransportSynMessage *) message;
2278 ts = GNUNET_TIME_absolute_ntoh(scm->timestamp); 2325 GNUNET_break_op (0 == ntohl (scm->reserved));
2326 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
2279 if (0 == 2327 if (0 ==
2280 memcmp(&GST_my_identity, 2328 memcmp (&GST_my_identity,
2281 peer, 2329 peer,
2282 sizeof(struct GNUNET_PeerIdentity))) 2330 sizeof(struct GNUNET_PeerIdentity)))
2283 { 2331 {
2284 /* loopback connection-to-self, ignore */ 2332 /* loopback connection-to-self, ignore */
2285 return GNUNET_SYSERR; 2333 return GNUNET_SYSERR;
2286 } 2334 }
2287 n = lookup_neighbour(peer); 2335 n = lookup_neighbour (peer);
2288 if (NULL == n) 2336 if (NULL == n)
2289 { 2337 {
2290 /* This is a new neighbour and set to not connected */ 2338 /* This is a new neighbour and set to not connected */
2291 n = setup_neighbour(peer); 2339 n = setup_neighbour (peer);
2292 GNUNET_assert(NULL != n); 2340 GNUNET_assert (NULL != n);
2293 } 2341 }
2294 2342
2295 /* Remember this SYN message in neighbour */ 2343 /* Remember this SYN message in neighbour */
2296 n->ack_state = ACK_SEND_SYN_ACK; 2344 n->ack_state = ACK_SEND_SYN_ACK;
2297 n->connect_ack_timestamp = ts; 2345 n->connect_ack_timestamp = ts;
2298 2346
2299 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2347 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2300 "Received SYN for peer `%s' in state %s/%s\n", 2348 "Received SYN for peer `%s' in state %s/%s\n",
2301 GNUNET_i2s(peer), 2349 GNUNET_i2s (peer),
2302 GNUNET_TRANSPORT_ps2s(n->state), 2350 GNUNET_TRANSPORT_ps2s (n->state),
2303 print_ack_state(n->ack_state)); 2351 print_ack_state (n->ack_state));
2304 2352
2305 switch (n->state) 2353 switch (n->state)
2306 { 2354 {
2307 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 2355 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2308 /* Request an address from ATS to send SYN_ACK to this peer */ 2356 /* Request an address from ATS to send SYN_ACK to this peer */
2309 set_state_and_timeout(n, 2357 set_state_and_timeout (n,
2310 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2358 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2311 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 2359 GNUNET_TIME_relative_to_absolute (
2312 break; 2360 ATS_RESPONSE_TIMEOUT));
2313 2361 break;
2314 case GNUNET_TRANSPORT_PS_INIT_ATS: 2362
2315 /* SYN message takes priority over us asking ATS for address: 2363 case GNUNET_TRANSPORT_PS_INIT_ATS:
2316 * Wait for ATS to suggest an address and send SYN_ACK */ 2364 /* SYN message takes priority over us asking ATS for address:
2317 set_state_and_timeout(n, 2365 * Wait for ATS to suggest an address and send SYN_ACK */
2318 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2366 set_state_and_timeout (n,
2319 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 2367 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2320 break; 2368 GNUNET_TIME_relative_to_absolute (
2321 2369 ATS_RESPONSE_TIMEOUT));
2322 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 2370 break;
2323 /* We already wait for an address to send an SYN_ACK */ 2371
2324 break; 2372 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2325 2373 /* We already wait for an address to send an SYN_ACK */
2326 case GNUNET_TRANSPORT_PS_SYN_SENT: 2374 break;
2327 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 2375
2328 /* Send ACK immediately */ 2376 case GNUNET_TRANSPORT_PS_SYN_SENT:
2329 n->ack_state = ACK_SEND_ACK; 2377 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2330 send_syn_ack_message(&n->primary_address, 2378 /* Send ACK immediately */
2331 ts); 2379 n->ack_state = ACK_SEND_ACK;
2332 break; 2380 send_syn_ack_message (&n->primary_address,
2333 2381 ts);
2334 case GNUNET_TRANSPORT_PS_CONNECTED: 2382 break;
2335 /* we are already connected and can thus send the ACK immediately */ 2383
2336 GNUNET_assert(NULL != n->primary_address.address); 2384 case GNUNET_TRANSPORT_PS_CONNECTED:
2337 GNUNET_assert(NULL != n->primary_address.session); 2385 /* we are already connected and can thus send the ACK immediately */
2338 n->ack_state = ACK_SEND_ACK; 2386 GNUNET_assert (NULL != n->primary_address.address);
2339 send_syn_ack_message(&n->primary_address, 2387 GNUNET_assert (NULL != n->primary_address.session);
2340 ts); 2388 n->ack_state = ACK_SEND_ACK;
2341 break; 2389 send_syn_ack_message (&n->primary_address,
2342 2390 ts);
2343 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 2391 break;
2344 /* We wait for ATS address suggestion */ 2392
2345 break; 2393 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2346 2394 /* We wait for ATS address suggestion */
2347 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 2395 break;
2348 /* We received a SYN message while waiting for a SYN_ACK in fast 2396
2349 * reconnect. Send SYN_ACK immediately */ 2397 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2350 n->ack_state = ACK_SEND_ACK; 2398 /* We received a SYN message while waiting for a SYN_ACK in fast
2351 send_syn_ack_message(&n->primary_address, 2399 * reconnect. Send SYN_ACK immediately */
2352 n->connect_ack_timestamp); 2400 n->ack_state = ACK_SEND_ACK;
2353 break; 2401 send_syn_ack_message (&n->primary_address,
2354 2402 n->connect_ack_timestamp);
2355 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 2403 break;
2356 /* We are already connected and can thus send the ACK immediately; 2404
2357 still, it can never hurt to have an alternative address, so also 2405 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2358 tell ATS about it */ 2406 /* We are already connected and can thus send the ACK immediately;
2359 GNUNET_assert(NULL != n->primary_address.address); 2407 still, it can never hurt to have an alternative address, so also
2360 GNUNET_assert(NULL != n->primary_address.session); 2408 tell ATS about it */
2361 n->ack_state = ACK_SEND_ACK; 2409 GNUNET_assert (NULL != n->primary_address.address);
2362 send_syn_ack_message(&n->primary_address, 2410 GNUNET_assert (NULL != n->primary_address.session);
2363 ts); 2411 n->ack_state = ACK_SEND_ACK;
2364 break; 2412 send_syn_ack_message (&n->primary_address,
2365 2413 ts);
2366 case GNUNET_TRANSPORT_PS_DISCONNECT: 2414 break;
2367 /* Get rid of remains and re-try */ 2415
2368 free_neighbour(n); 2416 case GNUNET_TRANSPORT_PS_DISCONNECT:
2369 n = setup_neighbour(peer); 2417 /* Get rid of remains and re-try */
2370 GNUNET_assert(NULL != n); 2418 free_neighbour (n);
2371 /* Remember the SYN time stamp for ACK message */ 2419 n = setup_neighbour (peer);
2372 n->ack_state = ACK_SEND_SYN_ACK; 2420 GNUNET_assert (NULL != n);
2373 n->connect_ack_timestamp = ts; 2421 /* Remember the SYN time stamp for ACK message */
2374 /* Request an address for the peer */ 2422 n->ack_state = ACK_SEND_SYN_ACK;
2375 set_state_and_timeout(n, 2423 n->connect_ack_timestamp = ts;
2376 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2424 /* Request an address for the peer */
2377 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 2425 set_state_and_timeout (n,
2378 break; 2426 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2379 2427 GNUNET_TIME_relative_to_absolute (
2380 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 2428 ATS_RESPONSE_TIMEOUT));
2381 /* should not be possible */ 2429 break;
2382 GNUNET_assert(0); 2430
2383 break; 2431 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2384 2432 /* should not be possible */
2385 default: 2433 GNUNET_assert (0);
2386 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2434 break;
2387 "Unhandled state `%s'\n", 2435
2388 GNUNET_TRANSPORT_ps2s(n->state)); 2436 default:
2389 GNUNET_break(0); 2437 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2390 return GNUNET_SYSERR; 2438 "Unhandled state `%s'\n",
2391 } 2439 GNUNET_TRANSPORT_ps2s (n->state));
2440 GNUNET_break (0);
2441 return GNUNET_SYSERR;
2442 }
2392 return GNUNET_OK; 2443 return GNUNET_OK;
2393} 2444}
2394 2445
@@ -2410,43 +2461,43 @@ GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message,
2410 * #GNUNET_NO if more extensive changes are required (address changed) 2461 * #GNUNET_NO if more extensive changes are required (address changed)
2411 */ 2462 */
2412static int 2463static int
2413try_run_fast_ats_update(const struct GNUNET_HELLO_Address *address, 2464try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address,
2414 struct GNUNET_ATS_Session *session, 2465 struct GNUNET_ATS_Session *session,
2415 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 2466 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2416 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2467 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2417{ 2468{
2418 struct NeighbourMapEntry *n; 2469 struct NeighbourMapEntry *n;
2419 2470
2420 n = lookup_neighbour(&address->peer); 2471 n = lookup_neighbour (&address->peer);
2421 if ((NULL == n) || 2472 if ((NULL == n) ||
2422 (NULL == n->primary_address.address) || 2473 (NULL == n->primary_address.address) ||
2423 (0 != GNUNET_HELLO_address_cmp(address, 2474 (0 != GNUNET_HELLO_address_cmp (address,
2424 n->primary_address.address))) 2475 n->primary_address.address)))
2425 return GNUNET_NO; 2476 return GNUNET_NO;
2426 /* We are not really switching addresses, but merely adjusting 2477 /* We are not really switching addresses, but merely adjusting
2427 session and/or bandwidth, can do fast ATS update! */ 2478 session and/or bandwidth, can do fast ATS update! */
2428 if (session != n->primary_address.session) 2479 if (session != n->primary_address.session)
2429 { 2480 {
2430 /* switch to a different session, but keeping same address; could 2481 /* switch to a different session, but keeping same address; could
2431 happen if there is a 2nd inbound connection */ 2482 happen if there is a 2nd inbound connection */
2432 n->primary_address.session = session; 2483 n->primary_address.session = session;
2433 GNUNET_assert(GNUNET_YES == 2484 GNUNET_assert (GNUNET_YES ==
2434 GST_ats_is_known(n->primary_address.address, 2485 GST_ats_is_known (n->primary_address.address,
2435 n->primary_address.session)); 2486 n->primary_address.session));
2436 } 2487 }
2437 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) 2488 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
2438 { 2489 {
2439 n->primary_address.bandwidth_in = bandwidth_in; 2490 n->primary_address.bandwidth_in = bandwidth_in;
2440 if (GNUNET_YES != 2491 if (GNUNET_YES !=
2441 set_incoming_quota(n, 2492 set_incoming_quota (n,
2442 bandwidth_in)) 2493 bandwidth_in))
2443 return GNUNET_NO; 2494 return GNUNET_NO;
2444 } 2495 }
2445 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) 2496 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
2446 { 2497 {
2447 n->primary_address.bandwidth_out = bandwidth_out; 2498 n->primary_address.bandwidth_out = bandwidth_out;
2448 send_outbound_quota_to_clients(n); 2499 send_outbound_quota_to_clients (n);
2449 } 2500 }
2450 return GNUNET_OK; 2501 return GNUNET_OK;
2451} 2502}
2452 2503
@@ -2465,11 +2516,11 @@ try_run_fast_ats_update(const struct GNUNET_HELLO_Address *address,
2465 * #GNUNET_SYSERR if operation was aborted 2516 * #GNUNET_SYSERR if operation was aborted
2466 */ 2517 */
2467static void 2518static void
2468switch_address_bl_check_cont(void *cls, 2519switch_address_bl_check_cont (void *cls,
2469 const struct GNUNET_PeerIdentity *peer, 2520 const struct GNUNET_PeerIdentity *peer,
2470 const struct GNUNET_HELLO_Address *address, 2521 const struct GNUNET_HELLO_Address *address,
2471 struct GNUNET_ATS_Session *session, 2522 struct GNUNET_ATS_Session *session,
2472 int result) 2523 int result)
2473{ 2524{
2474 struct BlacklistCheckSwitchContext *blc_ctx = cls; 2525 struct BlacklistCheckSwitchContext *blc_ctx = cls;
2475 struct GNUNET_TRANSPORT_PluginFunctions *papi; 2526 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -2478,289 +2529,297 @@ switch_address_bl_check_cont(void *cls,
2478 if (GNUNET_SYSERR == result) 2529 if (GNUNET_SYSERR == result)
2479 goto cleanup; 2530 goto cleanup;
2480 2531
2481 papi = GST_plugins_find(address->transport_name); 2532 papi = GST_plugins_find (address->transport_name);
2482 if (NULL == papi) 2533 if (NULL == papi)
2483 { 2534 {
2484 /* This can happen during shutdown. */ 2535 /* This can happen during shutdown. */
2485 goto cleanup; 2536 goto cleanup;
2486 } 2537 }
2487 2538
2488 if (GNUNET_NO == result) 2539 if (GNUNET_NO == result)
2489 { 2540 {
2490 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2491 "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n", 2542 "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n",
2492 GST_plugins_a2s(address), 2543 GST_plugins_a2s (address),
2493 session, 2544 session,
2494 GNUNET_i2s(peer)); 2545 GNUNET_i2s (peer));
2495 GNUNET_STATISTICS_update(GST_stats, 2546 GNUNET_STATISTICS_update (GST_stats,
2496 "# ATS suggestions ignored (blacklist denied)", 2547 "# ATS suggestions ignored (blacklist denied)",
2497 1, 2548 1,
2498 GNUNET_NO); 2549 GNUNET_NO);
2499 if (NULL != session) 2550 if (NULL != session)
2500 papi->disconnect_session(papi->cls, 2551 papi->disconnect_session (papi->cls,
2501 session); 2552 session);
2502 if (GNUNET_YES != 2553 if (GNUNET_YES !=
2503 GNUNET_HELLO_address_check_option(address, 2554 GNUNET_HELLO_address_check_option (address,
2504 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 2555 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
2505 GST_ats_block_address(address, 2556 GST_ats_block_address (address,
2506 NULL); 2557 NULL);
2507 goto cleanup; 2558 goto cleanup;
2508 } 2559 }
2509 2560
2510 2561
2511 if (NULL == session) 2562 if (NULL == session)
2512 { 2563 {
2513 /* need to create a session, ATS only gave us an address */ 2564 /* need to create a session, ATS only gave us an address */
2514 session = papi->get_session(papi->cls, 2565 session = papi->get_session (papi->cls,
2515 address); 2566 address);
2516 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2517 "Obtained new session for peer `%s' and address '%s': %p\n", 2568 "Obtained new session for peer `%s' and address '%s': %p\n",
2518 GNUNET_i2s(&address->peer), 2569 GNUNET_i2s (&address->peer),
2519 GST_plugins_a2s(address), 2570 GST_plugins_a2s (address),
2520 session); 2571 session);
2521 if (NULL != session) 2572 if (NULL != session)
2522 GST_ats_new_session(address, 2573 GST_ats_new_session (address,
2523 session); 2574 session);
2524 } 2575 }
2525 if (NULL == session) 2576 if (NULL == session)
2526 { 2577 {
2527 /* session creation failed, bad!, fail! */ 2578 /* session creation failed, bad!, fail! */
2528 GNUNET_STATISTICS_update(GST_stats, 2579 GNUNET_STATISTICS_update (GST_stats,
2529 "# ATS suggestions ignored (failed to create session)", 2580 "# ATS suggestions ignored (failed to create session)",
2530 1, 2581 1,
2531 GNUNET_NO); 2582 GNUNET_NO);
2532 /* No session could be obtained, remove blacklist check and clean up */ 2583 /* No session could be obtained, remove blacklist check and clean up */
2533 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2534 "Failed to obtain new session for peer `%s' and address '%s'\n", 2585 "Failed to obtain new session for peer `%s' and address '%s'\n",
2535 GNUNET_i2s(&address->peer), 2586 GNUNET_i2s (&address->peer),
2536 GST_plugins_a2s(address)); 2587 GST_plugins_a2s (address));
2537 GST_ats_block_address(address, 2588 GST_ats_block_address (address,
2538 session); 2589 session);
2539 goto cleanup; 2590 goto cleanup;
2540 } 2591 }
2541 2592
2542 /* We did this check already before going into blacklist, but 2593 /* We did this check already before going into blacklist, but
2543 it is theoretically possible that the situation changed in 2594 it is theoretically possible that the situation changed in
2544 the meantime, hence we check again here */ 2595 the meantime, hence we check again here */
2545 if (GNUNET_OK == 2596 if (GNUNET_OK ==
2546 try_run_fast_ats_update(address, 2597 try_run_fast_ats_update (address,
2547 session, 2598 session,
2548 blc_ctx->bandwidth_in, 2599 blc_ctx->bandwidth_in,
2549 blc_ctx->bandwidth_out)) 2600 blc_ctx->bandwidth_out))
2550 goto cleanup; /* was just a minor update, we're done */ 2601 goto cleanup; /* was just a minor update, we're done */
2551 2602
2552 /* check if we also need to setup the neighbour entry */ 2603 /* check if we also need to setup the neighbour entry */
2553 if (NULL == (n = lookup_neighbour(peer))) 2604 if (NULL == (n = lookup_neighbour (peer)))
2605 {
2606 n = setup_neighbour (peer);
2607 if (NULL == n)
2554 { 2608 {
2555 n = setup_neighbour(peer); 2609 /* not sure how this can happen... */
2556 if (NULL == n) 2610 GNUNET_break (0);
2557 { 2611 goto cleanup;
2558 /* not sure how this can happen... */
2559 GNUNET_break(0);
2560 goto cleanup;
2561 }
2562 n->state = GNUNET_TRANSPORT_PS_INIT_ATS;
2563 } 2612 }
2613 n->state = GNUNET_TRANSPORT_PS_INIT_ATS;
2614 }
2564 2615
2565 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2616 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2566 "Peer `%s' switches to address `%s'\n", 2617 "Peer `%s' switches to address `%s'\n",
2567 GNUNET_i2s(&address->peer), 2618 GNUNET_i2s (&address->peer),
2568 GST_plugins_a2s(address)); 2619 GST_plugins_a2s (address));
2569 2620
2570 switch (n->state) 2621 switch (n->state)
2571 { 2622 {
2572 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 2623 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2573 GNUNET_break(0); 2624 GNUNET_break (0);
2574 GST_ats_block_address(address, 2625 GST_ats_block_address (address,
2575 session); 2626 session);
2576 free_neighbour(n); 2627 free_neighbour (n);
2577 return; 2628 return;
2578
2579 case GNUNET_TRANSPORT_PS_INIT_ATS:
2580 /* We requested an address and ATS suggests one:
2581 * set primary address and send SYN message*/
2582 set_primary_address(n,
2583 address,
2584 session,
2585 blc_ctx->bandwidth_in,
2586 blc_ctx->bandwidth_out);
2587 if (ACK_SEND_SYN_ACK == n->ack_state)
2588 {
2589 /* Send pending SYN_ACK message */
2590 n->ack_state = ACK_SEND_ACK;
2591 send_syn_ack_message(&n->primary_address,
2592 n->connect_ack_timestamp);
2593 }
2594 set_state_and_timeout(n,
2595 GNUNET_TRANSPORT_PS_SYN_SENT,
2596 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2597 send_syn(&n->primary_address);
2598 break;
2599
2600 case GNUNET_TRANSPORT_PS_SYN_SENT:
2601 /* ATS suggested a new address while waiting for an SYN_ACK:
2602 * Switch and send new SYN */
2603 /* ATS suggests a different address, switch again */
2604 set_primary_address(n,
2605 address,
2606 session,
2607 blc_ctx->bandwidth_in,
2608 blc_ctx->bandwidth_out);
2609 if (ACK_SEND_SYN_ACK == n->ack_state)
2610 {
2611 /* Send pending SYN_ACK message */
2612 n->ack_state = ACK_SEND_ACK;
2613 send_syn_ack_message(&n->primary_address,
2614 n->connect_ack_timestamp);
2615 }
2616 set_state_and_timeout(n,
2617 GNUNET_TRANSPORT_PS_SYN_SENT,
2618 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2619 send_syn(&n->primary_address);
2620 break;
2621
2622 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2623 /* We requested an address and ATS suggests one:
2624 * set primary address and send SYN_ACK message*/
2625 set_primary_address(n,
2626 address,
2627 session,
2628 blc_ctx->bandwidth_in,
2629 blc_ctx->bandwidth_out);
2630 /* Send an ACK message as a response to the SYN msg */
2631 set_state_and_timeout(n,
2632 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2633 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2634 send_syn_ack_message(&n->primary_address,
2635 n->connect_ack_timestamp);
2636 if ((ACK_SEND_SYN_ACK == n->ack_state) ||
2637 (ACK_UNDEFINED == n->ack_state))
2638 n->ack_state = ACK_SEND_ACK;
2639 break;
2640
2641 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2642 /* ATS asks us to switch while we were trying to connect; switch to new
2643 address and check blacklist again */
2644 if ((ACK_SEND_SYN_ACK == n->ack_state))
2645 {
2646 n->ack_state = ACK_SEND_ACK;
2647 send_syn_ack_message(&n->primary_address,
2648 n->connect_ack_timestamp);
2649 }
2650 set_primary_address(n,
2651 address,
2652 session,
2653 blc_ctx->bandwidth_in,
2654 blc_ctx->bandwidth_out);
2655 set_state_and_timeout(n,
2656 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2657 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2658 break;
2659
2660 case GNUNET_TRANSPORT_PS_CONNECTED:
2661 GNUNET_assert(NULL != n->primary_address.address);
2662 GNUNET_assert(NULL != n->primary_address.session);
2663 GNUNET_break(n->primary_address.session != session);
2664 /* ATS asks us to switch a life connection; see if we can get
2665 a SYN_ACK on it before we actually do this! */
2666 set_alternative_address(n,
2667 address,
2668 session,
2669 blc_ctx->bandwidth_in,
2670 blc_ctx->bandwidth_out);
2671 set_state_and_timeout(n,
2672 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2673 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2674 GNUNET_STATISTICS_update(GST_stats,
2675 gettext_noop("# Attempts to switch addresses"),
2676 1,
2677 GNUNET_NO);
2678 send_syn(&n->alternative_address);
2679 break;
2680
2681 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2682 set_primary_address(n,
2683 address,
2684 session,
2685 blc_ctx->bandwidth_in,
2686 blc_ctx->bandwidth_out);
2687 if (ACK_SEND_SYN_ACK == n->ack_state)
2688 {
2689 /* Send pending SYN_ACK message */
2690 n->ack_state = ACK_SEND_ACK;
2691 send_syn_ack_message(&n->primary_address,
2692 n->connect_ack_timestamp);
2693 }
2694 set_state_and_timeout(n,
2695 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2696 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT));
2697 send_syn(&n->primary_address);
2698 break;
2699
2700 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2701 /* ATS asks us to switch while we were trying to reconnect; switch to new
2702 address and send SYN again */
2703 set_primary_address(n,
2704 address,
2705 session,
2706 blc_ctx->bandwidth_in,
2707 blc_ctx->bandwidth_out);
2708 set_state_and_timeout(n,
2709 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2710 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT));
2711 send_syn(&n->primary_address);
2712 break;
2713
2714 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2715 if ((0 == GNUNET_HELLO_address_cmp(n->primary_address.address,
2716 address)) &&
2717 (n->primary_address.session == session))
2718 {
2719 /* ATS switches back to still-active session */
2720 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2721 "ATS double-switched, cleaning up alternative address\n");
2722 free_address(&n->alternative_address);
2723 set_state_and_timeout(n,
2724 GNUNET_TRANSPORT_PS_CONNECTED,
2725 n->timeout);
2726 break;
2727 }
2728 /* ATS asks us to switch a life connection, send */
2729 set_alternative_address(n,
2730 address,
2731 session,
2732 blc_ctx->bandwidth_in,
2733 blc_ctx->bandwidth_out);
2734 set_state_and_timeout(n,
2735 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2736 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2737 send_syn(&n->alternative_address);
2738 break;
2739
2740 case GNUNET_TRANSPORT_PS_DISCONNECT:
2741 /* not going to switch addresses while disconnecting */
2742 GNUNET_STATISTICS_update(GST_stats,
2743 "# ATS suggestion ignored (disconnecting)",
2744 1,
2745 GNUNET_NO);
2746 return;
2747 2629
2748 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 2630 case GNUNET_TRANSPORT_PS_INIT_ATS:
2749 GNUNET_assert(0); 2631 /* We requested an address and ATS suggests one:
2750 break; 2632 * set primary address and send SYN message*/
2633 set_primary_address (n,
2634 address,
2635 session,
2636 blc_ctx->bandwidth_in,
2637 blc_ctx->bandwidth_out);
2638 if (ACK_SEND_SYN_ACK == n->ack_state)
2639 {
2640 /* Send pending SYN_ACK message */
2641 n->ack_state = ACK_SEND_ACK;
2642 send_syn_ack_message (&n->primary_address,
2643 n->connect_ack_timestamp);
2644 }
2645 set_state_and_timeout (n,
2646 GNUNET_TRANSPORT_PS_SYN_SENT,
2647 GNUNET_TIME_relative_to_absolute (
2648 SETUP_CONNECTION_TIMEOUT));
2649 send_syn (&n->primary_address);
2650 break;
2651
2652 case GNUNET_TRANSPORT_PS_SYN_SENT:
2653 /* ATS suggested a new address while waiting for an SYN_ACK:
2654 * Switch and send new SYN */
2655 /* ATS suggests a different address, switch again */
2656 set_primary_address (n,
2657 address,
2658 session,
2659 blc_ctx->bandwidth_in,
2660 blc_ctx->bandwidth_out);
2661 if (ACK_SEND_SYN_ACK == n->ack_state)
2662 {
2663 /* Send pending SYN_ACK message */
2664 n->ack_state = ACK_SEND_ACK;
2665 send_syn_ack_message (&n->primary_address,
2666 n->connect_ack_timestamp);
2667 }
2668 set_state_and_timeout (n,
2669 GNUNET_TRANSPORT_PS_SYN_SENT,
2670 GNUNET_TIME_relative_to_absolute (
2671 SETUP_CONNECTION_TIMEOUT));
2672 send_syn (&n->primary_address);
2673 break;
2674
2675 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2676 /* We requested an address and ATS suggests one:
2677 * set primary address and send SYN_ACK message*/
2678 set_primary_address (n,
2679 address,
2680 session,
2681 blc_ctx->bandwidth_in,
2682 blc_ctx->bandwidth_out);
2683 /* Send an ACK message as a response to the SYN msg */
2684 set_state_and_timeout (n,
2685 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2686 GNUNET_TIME_relative_to_absolute (
2687 SETUP_CONNECTION_TIMEOUT));
2688 send_syn_ack_message (&n->primary_address,
2689 n->connect_ack_timestamp);
2690 if ((ACK_SEND_SYN_ACK == n->ack_state) ||
2691 (ACK_UNDEFINED == n->ack_state))
2692 n->ack_state = ACK_SEND_ACK;
2693 break;
2751 2694
2752 default: 2695 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2753 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2696 /* ATS asks us to switch while we were trying to connect; switch to new
2754 "Unhandled state `%s'\n", 2697 address and check blacklist again */
2755 GNUNET_TRANSPORT_ps2s(n->state)); 2698 if ((ACK_SEND_SYN_ACK == n->ack_state))
2756 GNUNET_break(0); 2699 {
2700 n->ack_state = ACK_SEND_ACK;
2701 send_syn_ack_message (&n->primary_address,
2702 n->connect_ack_timestamp);
2703 }
2704 set_primary_address (n,
2705 address,
2706 session,
2707 blc_ctx->bandwidth_in,
2708 blc_ctx->bandwidth_out);
2709 set_state_and_timeout (n,
2710 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2711 GNUNET_TIME_relative_to_absolute (
2712 SETUP_CONNECTION_TIMEOUT));
2713 break;
2714
2715 case GNUNET_TRANSPORT_PS_CONNECTED:
2716 GNUNET_assert (NULL != n->primary_address.address);
2717 GNUNET_assert (NULL != n->primary_address.session);
2718 GNUNET_break (n->primary_address.session != session);
2719 /* ATS asks us to switch a life connection; see if we can get
2720 a SYN_ACK on it before we actually do this! */
2721 set_alternative_address (n,
2722 address,
2723 session,
2724 blc_ctx->bandwidth_in,
2725 blc_ctx->bandwidth_out);
2726 set_state_and_timeout (n,
2727 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2728 GNUNET_TIME_relative_to_absolute (
2729 SETUP_CONNECTION_TIMEOUT));
2730 GNUNET_STATISTICS_update (GST_stats,
2731 gettext_noop ("# Attempts to switch addresses"),
2732 1,
2733 GNUNET_NO);
2734 send_syn (&n->alternative_address);
2735 break;
2736
2737 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2738 set_primary_address (n,
2739 address,
2740 session,
2741 blc_ctx->bandwidth_in,
2742 blc_ctx->bandwidth_out);
2743 if (ACK_SEND_SYN_ACK == n->ack_state)
2744 {
2745 /* Send pending SYN_ACK message */
2746 n->ack_state = ACK_SEND_ACK;
2747 send_syn_ack_message (&n->primary_address,
2748 n->connect_ack_timestamp);
2749 }
2750 set_state_and_timeout (n,
2751 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2752 GNUNET_TIME_relative_to_absolute (
2753 FAST_RECONNECT_TIMEOUT));
2754 send_syn (&n->primary_address);
2755 break;
2756
2757 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2758 /* ATS asks us to switch while we were trying to reconnect; switch to new
2759 address and send SYN again */
2760 set_primary_address (n,
2761 address,
2762 session,
2763 blc_ctx->bandwidth_in,
2764 blc_ctx->bandwidth_out);
2765 set_state_and_timeout (n,
2766 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2767 GNUNET_TIME_relative_to_absolute (
2768 FAST_RECONNECT_TIMEOUT));
2769 send_syn (&n->primary_address);
2770 break;
2771
2772 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2773 if ((0 == GNUNET_HELLO_address_cmp (n->primary_address.address,
2774 address)) &&
2775 (n->primary_address.session == session))
2776 {
2777 /* ATS switches back to still-active session */
2778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2779 "ATS double-switched, cleaning up alternative address\n");
2780 free_address (&n->alternative_address);
2781 set_state_and_timeout (n,
2782 GNUNET_TRANSPORT_PS_CONNECTED,
2783 n->timeout);
2757 break; 2784 break;
2758 } 2785 }
2786 /* ATS asks us to switch a life connection, send */
2787 set_alternative_address (n,
2788 address,
2789 session,
2790 blc_ctx->bandwidth_in,
2791 blc_ctx->bandwidth_out);
2792 set_state_and_timeout (n,
2793 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2794 GNUNET_TIME_relative_to_absolute (
2795 SETUP_CONNECTION_TIMEOUT));
2796 send_syn (&n->alternative_address);
2797 break;
2798
2799 case GNUNET_TRANSPORT_PS_DISCONNECT:
2800 /* not going to switch addresses while disconnecting */
2801 GNUNET_STATISTICS_update (GST_stats,
2802 "# ATS suggestion ignored (disconnecting)",
2803 1,
2804 GNUNET_NO);
2805 return;
2806
2807 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2808 GNUNET_assert (0);
2809 break;
2810
2811 default:
2812 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2813 "Unhandled state `%s'\n",
2814 GNUNET_TRANSPORT_ps2s (n->state));
2815 GNUNET_break (0);
2816 break;
2817 }
2759cleanup: 2818cleanup:
2760 GNUNET_CONTAINER_DLL_remove(pending_bc_head, 2819 GNUNET_CONTAINER_DLL_remove (pending_bc_head,
2761 pending_bc_tail, 2820 pending_bc_tail,
2762 blc_ctx); 2821 blc_ctx);
2763 GNUNET_free(blc_ctx); 2822 GNUNET_free (blc_ctx);
2764} 2823}
2765 2824
2766 2825
@@ -2782,65 +2841,67 @@ cleanup:
2782 * 0 to disconnect from peer 2841 * 0 to disconnect from peer
2783 */ 2842 */
2784void 2843void
2785GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address, 2844GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
2786 struct GNUNET_ATS_Session *session, 2845 struct GNUNET_ATS_Session *session,
2787 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 2846 struct GNUNET_BANDWIDTH_Value32NBO
2788 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2847 bandwidth_in,
2848 struct GNUNET_BANDWIDTH_Value32NBO
2849 bandwidth_out)
2789{ 2850{
2790 struct GST_BlacklistCheck *blc; 2851 struct GST_BlacklistCheck *blc;
2791 struct BlacklistCheckSwitchContext *blc_ctx; 2852 struct BlacklistCheckSwitchContext *blc_ctx;
2792 2853
2793 GNUNET_assert(NULL != address->transport_name); 2854 GNUNET_assert (NULL != address->transport_name);
2794 if (GNUNET_OK == 2855 if (GNUNET_OK ==
2795 try_run_fast_ats_update(address, 2856 try_run_fast_ats_update (address,
2796 session, 2857 session,
2797 bandwidth_in, 2858 bandwidth_in,
2798 bandwidth_out)) 2859 bandwidth_out))
2799 return; 2860 return;
2800 2861
2801 /* Check if plugin is available */ 2862 /* Check if plugin is available */
2802 if (NULL == (GST_plugins_find(address->transport_name))) 2863 if (NULL == (GST_plugins_find (address->transport_name)))
2803 { 2864 {
2804 /* we don't have the plugin for this address */ 2865 /* we don't have the plugin for this address */
2805 GNUNET_break(0); 2866 GNUNET_break (0);
2806 GST_ats_block_address(address, 2867 GST_ats_block_address (address,
2807 session); 2868 session);
2808 return; 2869 return;
2809 } 2870 }
2810 if ((NULL == session) && 2871 if ((NULL == session) &&
2811 (GNUNET_HELLO_address_check_option(address, 2872 (GNUNET_HELLO_address_check_option (address,
2812 GNUNET_HELLO_ADDRESS_INFO_INBOUND))) 2873 GNUNET_HELLO_ADDRESS_INFO_INBOUND)))
2813 { 2874 {
2814 /* This is a inbound address and we do not have a session to use! */ 2875 /* This is a inbound address and we do not have a session to use! */
2815 GNUNET_break(0); 2876 GNUNET_break (0);
2816 GST_ats_block_address(address, 2877 GST_ats_block_address (address,
2817 session); 2878 session);
2818 return; 2879 return;
2819 } 2880 }
2820 2881
2821 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2822 "ATS suggests address '%s' for peer `%s' at %u/%u speed\n", 2883 "ATS suggests address '%s' for peer `%s' at %u/%u speed\n",
2823 GST_plugins_a2s(address), 2884 GST_plugins_a2s (address),
2824 GNUNET_i2s(&address->peer), 2885 GNUNET_i2s (&address->peer),
2825 (unsigned int)ntohl(bandwidth_in.value__), 2886 (unsigned int) ntohl (bandwidth_in.value__),
2826 (unsigned int)ntohl(bandwidth_out.value__)); 2887 (unsigned int) ntohl (bandwidth_out.value__));
2827 2888
2828 /* Perform blacklist check */ 2889 /* Perform blacklist check */
2829 blc_ctx = GNUNET_new(struct BlacklistCheckSwitchContext); 2890 blc_ctx = GNUNET_new (struct BlacklistCheckSwitchContext);
2830 blc_ctx->bandwidth_in = bandwidth_in; 2891 blc_ctx->bandwidth_in = bandwidth_in;
2831 blc_ctx->bandwidth_out = bandwidth_out; 2892 blc_ctx->bandwidth_out = bandwidth_out;
2832 GNUNET_CONTAINER_DLL_insert(pending_bc_head, 2893 GNUNET_CONTAINER_DLL_insert (pending_bc_head,
2833 pending_bc_tail, 2894 pending_bc_tail,
2834 blc_ctx); 2895 blc_ctx);
2835 if (NULL != (blc = GST_blacklist_test_allowed(&address->peer, 2896 if (NULL != (blc = GST_blacklist_test_allowed (&address->peer,
2836 address->transport_name, 2897 address->transport_name,
2837 &switch_address_bl_check_cont, 2898 &switch_address_bl_check_cont,
2838 blc_ctx, 2899 blc_ctx,
2839 address, 2900 address,
2840 session))) 2901 session)))
2841 { 2902 {
2842 blc_ctx->blc = blc; 2903 blc_ctx->blc = blc;
2843 } 2904 }
2844} 2905}
2845 2906
2846 2907
@@ -2854,39 +2915,40 @@ GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address,
2854 * @return #GNUNET_OK (continue to iterate) 2915 * @return #GNUNET_OK (continue to iterate)
2855 */ 2916 */
2856static int 2917static int
2857send_utilization_data(void *cls, 2918send_utilization_data (void *cls,
2858 const struct GNUNET_PeerIdentity *key, 2919 const struct GNUNET_PeerIdentity *key,
2859 void *value) 2920 void *value)
2860{ 2921{
2861 struct NeighbourMapEntry *n = value; 2922 struct NeighbourMapEntry *n = value;
2862 uint32_t bps_in; 2923 uint32_t bps_in;
2863 uint32_t bps_out; 2924 uint32_t bps_out;
2864 struct GNUNET_TIME_Relative delta; 2925 struct GNUNET_TIME_Relative delta;
2865 2926
2866 (void)cls; 2927 (void) cls;
2867 if ((GNUNET_YES != test_connected(n)) || 2928 if ((GNUNET_YES != test_connected (n)) ||
2868 (NULL == n->primary_address.address)) 2929 (NULL == n->primary_address.address))
2869 return GNUNET_OK; 2930 return GNUNET_OK;
2870 delta = GNUNET_TIME_absolute_get_difference(n->last_util_transmission, 2931 delta = GNUNET_TIME_absolute_get_difference (n->last_util_transmission,
2871 GNUNET_TIME_absolute_get()); 2932 GNUNET_TIME_absolute_get ());
2872 bps_in = 0; 2933 bps_in = 0;
2873 if ((0 != n->util_total_bytes_recv) && (0 != delta.rel_value_us)) 2934 if ((0 != n->util_total_bytes_recv) && (0 != delta.rel_value_us))
2874 bps_in = (1000LL * 1000LL * n->util_total_bytes_recv) / (delta.rel_value_us); 2935 bps_in = (1000LL * 1000LL * n->util_total_bytes_recv)
2936 / (delta.rel_value_us);
2875 bps_out = 0; 2937 bps_out = 0;
2876 if ((0 != n->util_total_bytes_sent) && (0 != delta.rel_value_us)) 2938 if ((0 != n->util_total_bytes_sent) && (0 != delta.rel_value_us))
2877 bps_out = (1000LL * 1000LL * n->util_total_bytes_sent) / delta.rel_value_us; 2939 bps_out = (1000LL * 1000LL * n->util_total_bytes_sent) / delta.rel_value_us;
2878 2940
2879 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2941 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2880 "`%s' total: received %u Bytes/s, sent %u Bytes/s\n", 2942 "`%s' total: received %u Bytes/s, sent %u Bytes/s\n",
2881 GNUNET_i2s(key), 2943 GNUNET_i2s (key),
2882 bps_in, 2944 bps_in,
2883 bps_out); 2945 bps_out);
2884 GST_ats_update_utilization(n->primary_address.address, 2946 GST_ats_update_utilization (n->primary_address.address,
2885 bps_in, 2947 bps_in,
2886 bps_out); 2948 bps_out);
2887 n->util_total_bytes_recv = 0; 2949 n->util_total_bytes_recv = 0;
2888 n->util_total_bytes_sent = 0; 2950 n->util_total_bytes_sent = 0;
2889 n->last_util_transmission = GNUNET_TIME_absolute_get(); 2951 n->last_util_transmission = GNUNET_TIME_absolute_get ();
2890 return GNUNET_OK; 2952 return GNUNET_OK;
2891} 2953}
2892 2954
@@ -2897,17 +2959,17 @@ send_utilization_data(void *cls,
2897 * @param cls the `struct NeighbourMapEntry` for which we are running 2959 * @param cls the `struct NeighbourMapEntry` for which we are running
2898 */ 2960 */
2899static void 2961static void
2900utilization_transmission(void *cls) 2962utilization_transmission (void *cls)
2901{ 2963{
2902 (void)cls; 2964 (void) cls;
2903 util_transmission_tk = NULL; 2965 util_transmission_tk = NULL;
2904 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 2966 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
2905 &send_utilization_data, 2967 &send_utilization_data,
2906 NULL); 2968 NULL);
2907 util_transmission_tk 2969 util_transmission_tk
2908 = GNUNET_SCHEDULER_add_delayed(UTIL_TRANSMISSION_INTERVAL, 2970 = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL,
2909 &utilization_transmission, 2971 &utilization_transmission,
2910 NULL); 2972 NULL);
2911} 2973}
2912 2974
2913 2975
@@ -2920,15 +2982,15 @@ utilization_transmission(void *cls)
2920 * @param message the message we received (really only the size is used) 2982 * @param message the message we received (really only the size is used)
2921 */ 2983 */
2922void 2984void
2923GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address, 2985GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address,
2924 const struct GNUNET_MessageHeader *message) 2986 const struct GNUNET_MessageHeader *message)
2925{ 2987{
2926 struct NeighbourMapEntry *n; 2988 struct NeighbourMapEntry *n;
2927 2989
2928 n = lookup_neighbour(&address->peer); 2990 n = lookup_neighbour (&address->peer);
2929 if (NULL == n) 2991 if (NULL == n)
2930 return; 2992 return;
2931 n->util_total_bytes_recv += ntohs(message->size); 2993 n->util_total_bytes_recv += ntohs (message->size);
2932} 2994}
2933 2995
2934 2996
@@ -2942,13 +3004,13 @@ GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address,
2942 * @param message the message we sent (really only the size is used) 3004 * @param message the message we sent (really only the size is used)
2943 */ 3005 */
2944void 3006void
2945GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address, 3007GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address,
2946 struct GNUNET_ATS_Session *session, 3008 struct GNUNET_ATS_Session *session,
2947 size_t size) 3009 size_t size)
2948{ 3010{
2949 struct NeighbourMapEntry *n; 3011 struct NeighbourMapEntry *n;
2950 3012
2951 n = lookup_neighbour(&address->peer); 3013 n = lookup_neighbour (&address->peer);
2952 if (NULL == n) 3014 if (NULL == n)
2953 return; 3015 return;
2954 if (n->primary_address.session != session) 3016 if (n->primary_address.session != session)
@@ -2965,157 +3027,160 @@ GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address,
2965 * @param cls the 'struct NeighbourMapEntry' for which we are running 3027 * @param cls the 'struct NeighbourMapEntry' for which we are running
2966 */ 3028 */
2967static void 3029static void
2968master_task(void *cls) 3030master_task (void *cls)
2969{ 3031{
2970 struct NeighbourMapEntry *n = cls; 3032 struct NeighbourMapEntry *n = cls;
2971 struct GNUNET_TIME_Relative delay; 3033 struct GNUNET_TIME_Relative delay;
2972 3034
2973 n->task = NULL; 3035 n->task = NULL;
2974 delay = GNUNET_TIME_absolute_get_remaining(n->timeout); 3036 delay = GNUNET_TIME_absolute_get_remaining (n->timeout);
2975 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2976 "Master task runs for neighbour `%s' in state %s with timeout in %s\n", 3038 "Master task runs for neighbour `%s' in state %s with timeout in %s\n",
2977 GNUNET_i2s(&n->id), 3039 GNUNET_i2s (&n->id),
2978 GNUNET_TRANSPORT_ps2s(n->state), 3040 GNUNET_TRANSPORT_ps2s (n->state),
2979 GNUNET_STRINGS_relative_time_to_string(delay, 3041 GNUNET_STRINGS_relative_time_to_string (delay,
2980 GNUNET_YES)); 3042 GNUNET_YES));
2981 switch (n->state) 3043 switch (n->state)
3044 {
3045 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
3046 /* invalid state for master task, clean up */
3047 GNUNET_break (0);
3048 free_neighbour (n);
3049 return;
3050
3051 case GNUNET_TRANSPORT_PS_INIT_ATS:
3052 if (0 == delay.rel_value_us)
2982 { 3053 {
2983 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 3054 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2984 /* invalid state for master task, clean up */ 3055 "Connection to `%s' timed out waiting for ATS to provide address\n",
2985 GNUNET_break(0); 3056 GNUNET_i2s (&n->id));
2986 free_neighbour(n); 3057 free_neighbour (n);
2987 return; 3058 return;
3059 }
3060 break;
2988 3061
2989 case GNUNET_TRANSPORT_PS_INIT_ATS: 3062 case GNUNET_TRANSPORT_PS_SYN_SENT:
2990 if (0 == delay.rel_value_us) 3063 if (0 == delay.rel_value_us)
2991 { 3064 {
2992 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3065 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2993 "Connection to `%s' timed out waiting for ATS to provide address\n", 3066 "Connection to `%s' timed out waiting for other peer to send SYN_ACK\n",
2994 GNUNET_i2s(&n->id)); 3067 GNUNET_i2s (&n->id));
2995 free_neighbour(n); 3068 /* Remove address and request and additional one */
2996 return; 3069 unset_primary_address (n);
2997 } 3070 set_state_and_timeout (n,
2998 break; 3071 GNUNET_TRANSPORT_PS_INIT_ATS,
2999 3072 GNUNET_TIME_relative_to_absolute (
3000 case GNUNET_TRANSPORT_PS_SYN_SENT: 3073 ATS_RESPONSE_TIMEOUT));
3001 if (0 == delay.rel_value_us) 3074 return;
3002 { 3075 }
3003 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3076 break;
3004 "Connection to `%s' timed out waiting for other peer to send SYN_ACK\n",
3005 GNUNET_i2s(&n->id));
3006 /* Remove address and request and additional one */
3007 unset_primary_address(n);
3008 set_state_and_timeout(n,
3009 GNUNET_TRANSPORT_PS_INIT_ATS,
3010 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
3011 return;
3012 }
3013 break;
3014
3015 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3016 if (0 == delay.rel_value_us)
3017 {
3018 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3019 "Connection to `%s' timed out waiting ATS to provide address to use for SYN_ACK\n",
3020 GNUNET_i2s(&n->id));
3021 free_neighbour(n);
3022 return;
3023 }
3024 break;
3025
3026 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3027 if (0 == delay.rel_value_us)
3028 {
3029 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3030 "Connection to `%s' timed out waiting for other peer to send ACK\n",
3031 GNUNET_i2s(&n->id));
3032 disconnect_neighbour(n);
3033 return;
3034 }
3035 break;
3036
3037 case GNUNET_TRANSPORT_PS_CONNECTED:
3038 if (0 == delay.rel_value_us)
3039 {
3040 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3041 "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs\n",
3042 GNUNET_i2s(&n->id));
3043 disconnect_neighbour(n);
3044 return;
3045 }
3046 try_transmission_to_peer(n);
3047 send_keepalive(n);
3048 break;
3049 3077
3050 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 3078 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3051 if (0 == delay.rel_value_us) 3079 if (0 == delay.rel_value_us)
3052 { 3080 {
3053 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3081 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3054 "Connection to `%s' timed out, waiting for ATS replacement address\n", 3082 "Connection to `%s' timed out waiting ATS to provide address to use for SYN_ACK\n",
3055 GNUNET_i2s(&n->id)); 3083 GNUNET_i2s (&n->id));
3056 disconnect_neighbour(n); 3084 free_neighbour (n);
3057 return; 3085 return;
3058 } 3086 }
3059 break; 3087 break;
3060 3088
3061 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 3089 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3062 if (0 == delay.rel_value_us) 3090 if (0 == delay.rel_value_us)
3063 { 3091 {
3064 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3092 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3065 "Connection to `%s' timed out, waiting for other peer to SYN_ACK replacement address\n", 3093 "Connection to `%s' timed out waiting for other peer to send ACK\n",
3066 GNUNET_i2s(&n->id)); 3094 GNUNET_i2s (&n->id));
3067 disconnect_neighbour(n); 3095 disconnect_neighbour (n);
3068 return; 3096 return;
3069 } 3097 }
3070 break; 3098 break;
3071 3099
3072 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 3100 case GNUNET_TRANSPORT_PS_CONNECTED:
3073 if (0 == delay.rel_value_us) 3101 if (0 == delay.rel_value_us)
3074 { 3102 {
3075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3103 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3076 "Switch failed, cleaning up alternative address\n"); 3104 "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs\n",
3077 free_address(&n->alternative_address); 3105 GNUNET_i2s (&n->id));
3078 set_state_and_timeout(n, 3106 disconnect_neighbour (n);
3079 GNUNET_TRANSPORT_PS_CONNECTED, 3107 return;
3080 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT)); 3108 }
3081 } 3109 try_transmission_to_peer (n);
3082 try_transmission_to_peer(n); 3110 send_keepalive (n);
3083 send_keepalive(n); 3111 break;
3084 break;
3085 3112
3086 case GNUNET_TRANSPORT_PS_DISCONNECT: 3113 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3087 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3114 if (0 == delay.rel_value_us)
3088 "Cleaning up connection to `%s' after sending DISCONNECT\n", 3115 {
3089 GNUNET_i2s(&n->id)); 3116 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3090 free_neighbour(n); 3117 "Connection to `%s' timed out, waiting for ATS replacement address\n",
3118 GNUNET_i2s (&n->id));
3119 disconnect_neighbour (n);
3091 return; 3120 return;
3121 }
3122 break;
3092 3123
3093 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 3124 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3094 /* how did we get here!? */ 3125 if (0 == delay.rel_value_us)
3095 GNUNET_assert(0); 3126 {
3096 break; 3127 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3128 "Connection to `%s' timed out, waiting for other peer to SYN_ACK replacement address\n",
3129 GNUNET_i2s (&n->id));
3130 disconnect_neighbour (n);
3131 return;
3132 }
3133 break;
3097 3134
3098 default: 3135 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3099 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3136 if (0 == delay.rel_value_us)
3100 "Unhandled state `%s'\n", 3137 {
3101 GNUNET_TRANSPORT_ps2s(n->state)); 3138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3102 GNUNET_break(0); 3139 "Switch failed, cleaning up alternative address\n");
3103 break; 3140 free_address (&n->alternative_address);
3141 set_state_and_timeout (n,
3142 GNUNET_TRANSPORT_PS_CONNECTED,
3143 GNUNET_TIME_relative_to_absolute (
3144 SETUP_CONNECTION_TIMEOUT));
3104 } 3145 }
3105 delay = GNUNET_TIME_absolute_get_remaining(n->timeout); 3146 try_transmission_to_peer (n);
3147 send_keepalive (n);
3148 break;
3149
3150 case GNUNET_TRANSPORT_PS_DISCONNECT:
3151 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3152 "Cleaning up connection to `%s' after sending DISCONNECT\n",
3153 GNUNET_i2s (&n->id));
3154 free_neighbour (n);
3155 return;
3156
3157 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3158 /* how did we get here!? */
3159 GNUNET_assert (0);
3160 break;
3161
3162 default:
3163 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3164 "Unhandled state `%s'\n",
3165 GNUNET_TRANSPORT_ps2s (n->state));
3166 GNUNET_break (0);
3167 break;
3168 }
3169 delay = GNUNET_TIME_absolute_get_remaining (n->timeout);
3106 if ((GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) || 3170 if ((GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) ||
3107 (GNUNET_TRANSPORT_PS_CONNECTED == n->state)) 3171 (GNUNET_TRANSPORT_PS_CONNECTED == n->state))
3108 { 3172 {
3109 /* if we are *now* in one of the two states, we're sending 3173 /* if we are *now* in one of the two states, we're sending
3110 keep alive messages, so we need to consider the keepalive 3174 keep alive messages, so we need to consider the keepalive
3111 delay, not just the connection timeout */ 3175 delay, not just the connection timeout */
3112 delay = GNUNET_TIME_relative_min(GNUNET_TIME_absolute_get_remaining(n->keep_alive_time), 3176 delay = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (
3113 delay); 3177 n->keep_alive_time),
3114 } 3178 delay);
3179 }
3115 if (NULL == n->task) 3180 if (NULL == n->task)
3116 n->task = GNUNET_SCHEDULER_add_delayed(delay, 3181 n->task = GNUNET_SCHEDULER_add_delayed (delay,
3117 &master_task, 3182 &master_task,
3118 n); 3183 n);
3119} 3184}
3120 3185
3121 3186
@@ -3126,23 +3191,23 @@ master_task(void *cls)
3126 * @param n neighbour to send the ACK to 3191 * @param n neighbour to send the ACK to
3127 */ 3192 */
3128static void 3193static void
3129send_session_ack_message(struct NeighbourMapEntry *n) 3194send_session_ack_message (struct NeighbourMapEntry *n)
3130{ 3195{
3131 struct GNUNET_MessageHeader msg; 3196 struct GNUNET_MessageHeader msg;
3132 3197
3133 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3198 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3134 "Sending ACK message to peer `%s'\n", 3199 "Sending ACK message to peer `%s'\n",
3135 GNUNET_i2s(&n->id)); 3200 GNUNET_i2s (&n->id));
3136 3201
3137 msg.size = htons(sizeof(struct GNUNET_MessageHeader)); 3202 msg.size = htons (sizeof(struct GNUNET_MessageHeader));
3138 msg.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); 3203 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK);
3139 (void)send_with_session(n, 3204 (void) send_with_session (n,
3140 &msg, 3205 &msg,
3141 sizeof(struct GNUNET_MessageHeader), 3206 sizeof(struct GNUNET_MessageHeader),
3142 UINT32_MAX, 3207 UINT32_MAX,
3143 GNUNET_TIME_UNIT_FOREVER_REL, 3208 GNUNET_TIME_UNIT_FOREVER_REL,
3144 GNUNET_NO, 3209 GNUNET_NO,
3145 NULL, NULL); 3210 NULL, NULL);
3146} 3211}
3147 3212
3148 3213
@@ -3158,145 +3223,154 @@ send_session_ack_message(struct NeighbourMapEntry *n)
3158 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 3223 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
3159 */ 3224 */
3160int 3225int
3161GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message, 3226GST_neighbours_handle_session_syn_ack (const struct
3162 const struct GNUNET_HELLO_Address *address, 3227 GNUNET_MessageHeader *message,
3163 struct GNUNET_ATS_Session *session) 3228 const struct
3229 GNUNET_HELLO_Address *address,
3230 struct GNUNET_ATS_Session *session)
3164{ 3231{
3165 const struct TransportSynMessage *scm; 3232 const struct TransportSynMessage *scm;
3166 struct GNUNET_TIME_Absolute ts; 3233 struct GNUNET_TIME_Absolute ts;
3167 struct NeighbourMapEntry *n; 3234 struct NeighbourMapEntry *n;
3168 3235
3169 (void)session; 3236 (void) session;
3170 if (ntohs(message->size) != sizeof(struct TransportSynMessage)) 3237 if (ntohs (message->size) != sizeof(struct TransportSynMessage))
3171 { 3238 {
3172 GNUNET_break_op(0); 3239 GNUNET_break_op (0);
3173 return GNUNET_SYSERR; 3240 return GNUNET_SYSERR;
3174 } 3241 }
3175 GNUNET_STATISTICS_update(GST_stats, 3242 GNUNET_STATISTICS_update (GST_stats,
3176 gettext_noop 3243 gettext_noop
3177 ("# SYN_ACK messages received"), 3244 ("# SYN_ACK messages received"),
3178 1, GNUNET_NO); 3245 1, GNUNET_NO);
3179 scm = (const struct TransportSynMessage *)message; 3246 scm = (const struct TransportSynMessage *) message;
3180 GNUNET_break_op(ntohl(scm->reserved) == 0); 3247 GNUNET_break_op (ntohl (scm->reserved) == 0);
3181 if (NULL == (n = lookup_neighbour(&address->peer))) 3248 if (NULL == (n = lookup_neighbour (&address->peer)))
3182 { 3249 {
3183 GNUNET_STATISTICS_update(GST_stats, 3250 GNUNET_STATISTICS_update (GST_stats,
3184 gettext_noop 3251 gettext_noop
3185 ("# unexpected SYN_ACK messages (no peer)"), 3252 ("# unexpected SYN_ACK messages (no peer)"),
3186 1, GNUNET_NO); 3253 1, GNUNET_NO);
3187 return GNUNET_SYSERR; 3254 return GNUNET_SYSERR;
3188 } 3255 }
3189 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3190 "Received SYN_ACK message from peer `%s' in state %s/%s\n", 3257 "Received SYN_ACK message from peer `%s' in state %s/%s\n",
3191 GNUNET_i2s(&address->peer), 3258 GNUNET_i2s (&address->peer),
3192 GNUNET_TRANSPORT_ps2s(n->state), 3259 GNUNET_TRANSPORT_ps2s (n->state),
3193 print_ack_state(n->ack_state)); 3260 print_ack_state (n->ack_state));
3194 ts = GNUNET_TIME_absolute_ntoh(scm->timestamp); 3261 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
3195 switch (n->state) 3262 switch (n->state)
3196 { 3263 {
3197 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 3264 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
3198 GNUNET_break(0); 3265 GNUNET_break (0);
3199 free_neighbour(n); 3266 free_neighbour (n);
3200 return GNUNET_SYSERR; 3267 return GNUNET_SYSERR;
3201 3268
3202 case GNUNET_TRANSPORT_PS_INIT_ATS: 3269 case GNUNET_TRANSPORT_PS_INIT_ATS:
3203 GNUNET_STATISTICS_update(GST_stats, 3270 GNUNET_STATISTICS_update (GST_stats,
3204 gettext_noop("# unexpected SYN_ACK messages (not ready)"), 3271 gettext_noop (
3205 1, 3272 "# unexpected SYN_ACK messages (not ready)"),
3206 GNUNET_NO); 3273 1,
3207 break; 3274 GNUNET_NO);
3208 3275 break;
3209 case GNUNET_TRANSPORT_PS_SYN_SENT: 3276
3210 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us) 3277 case GNUNET_TRANSPORT_PS_SYN_SENT:
3211 { 3278 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us)
3212 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3279 {
3213 "SYN_ACK ignored as the timestamp does not match our SYN request\n"); 3280 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3214 return GNUNET_OK; 3281 "SYN_ACK ignored as the timestamp does not match our SYN request\n");
3215 } 3282 return GNUNET_OK;
3216 set_state_and_timeout(n,
3217 GNUNET_TRANSPORT_PS_CONNECTED,
3218 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3219 set_primary_address(n,
3220 n->primary_address.address,
3221 n->primary_address.session,
3222 n->primary_address.bandwidth_in,
3223 n->primary_address.bandwidth_out);
3224 send_session_ack_message(n);
3225 break;
3226
3227 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3228 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3229 GNUNET_STATISTICS_update(GST_stats,
3230 gettext_noop("# unexpected SYN_ACK messages (not ready)"),
3231 1,
3232 GNUNET_NO);
3233 break;
3234
3235 case GNUNET_TRANSPORT_PS_CONNECTED:
3236 /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */
3237 send_session_ack_message(n);
3238 break;
3239
3240 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3241 /* we didn't expect any SYN_ACK, as we are waiting for ATS
3242 to give us a new address... */
3243 GNUNET_STATISTICS_update(GST_stats,
3244 gettext_noop("# unexpected SYN_ACK messages (waiting on ATS)"),
3245 1,
3246 GNUNET_NO);
3247 break;
3248
3249 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3250 /* Reconnecting with new address address worked; go back to connected! */
3251 set_state_and_timeout(n,
3252 GNUNET_TRANSPORT_PS_CONNECTED,
3253 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3254 send_session_ack_message(n);
3255 break;
3256
3257 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3258 /* new address worked; adopt it and go back to connected! */
3259 set_state_and_timeout(n,
3260 GNUNET_TRANSPORT_PS_CONNECTED,
3261 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3262 GNUNET_break(GNUNET_NO == n->alternative_address.ats_active);
3263
3264 /* Set primary addresses */
3265 set_primary_address(n,
3266 n->alternative_address.address,
3267 n->alternative_address.session,
3268 n->alternative_address.bandwidth_in,
3269 n->alternative_address.bandwidth_out);
3270 GNUNET_STATISTICS_update(GST_stats,
3271 gettext_noop("# Successful attempts to switch addresses"),
3272 1,
3273 GNUNET_NO);
3274
3275 GNUNET_HELLO_address_free(n->alternative_address.address);
3276 memset(&n->alternative_address,
3277 0,
3278 sizeof(n->alternative_address));
3279 send_session_ack_message(n);
3280 break;
3281
3282 case GNUNET_TRANSPORT_PS_DISCONNECT:
3283 GNUNET_STATISTICS_update(GST_stats,
3284 gettext_noop
3285 ("# unexpected SYN_ACK messages (disconnecting)"),
3286 1, GNUNET_NO);
3287 return GNUNET_SYSERR;
3288
3289 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3290 GNUNET_assert(0);
3291 break;
3292
3293 default:
3294 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
3295 "Unhandled state `%s'\n",
3296 GNUNET_TRANSPORT_ps2s(n->state));
3297 GNUNET_break(0);
3298 return GNUNET_SYSERR;
3299 } 3283 }
3284 set_state_and_timeout (n,
3285 GNUNET_TRANSPORT_PS_CONNECTED,
3286 GNUNET_TIME_relative_to_absolute (
3287 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3288 set_primary_address (n,
3289 n->primary_address.address,
3290 n->primary_address.session,
3291 n->primary_address.bandwidth_in,
3292 n->primary_address.bandwidth_out);
3293 send_session_ack_message (n);
3294 break;
3295
3296 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3297 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3298 GNUNET_STATISTICS_update (GST_stats,
3299 gettext_noop (
3300 "# unexpected SYN_ACK messages (not ready)"),
3301 1,
3302 GNUNET_NO);
3303 break;
3304
3305 case GNUNET_TRANSPORT_PS_CONNECTED:
3306 /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */
3307 send_session_ack_message (n);
3308 break;
3309
3310 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3311 /* we didn't expect any SYN_ACK, as we are waiting for ATS
3312 to give us a new address... */
3313 GNUNET_STATISTICS_update (GST_stats,
3314 gettext_noop (
3315 "# unexpected SYN_ACK messages (waiting on ATS)"),
3316 1,
3317 GNUNET_NO);
3318 break;
3319
3320 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3321 /* Reconnecting with new address address worked; go back to connected! */
3322 set_state_and_timeout (n,
3323 GNUNET_TRANSPORT_PS_CONNECTED,
3324 GNUNET_TIME_relative_to_absolute (
3325 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3326 send_session_ack_message (n);
3327 break;
3328
3329 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3330 /* new address worked; adopt it and go back to connected! */
3331 set_state_and_timeout (n,
3332 GNUNET_TRANSPORT_PS_CONNECTED,
3333 GNUNET_TIME_relative_to_absolute (
3334 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3335 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
3336
3337 /* Set primary addresses */
3338 set_primary_address (n,
3339 n->alternative_address.address,
3340 n->alternative_address.session,
3341 n->alternative_address.bandwidth_in,
3342 n->alternative_address.bandwidth_out);
3343 GNUNET_STATISTICS_update (GST_stats,
3344 gettext_noop (
3345 "# Successful attempts to switch addresses"),
3346 1,
3347 GNUNET_NO);
3348
3349 GNUNET_HELLO_address_free (n->alternative_address.address);
3350 memset (&n->alternative_address,
3351 0,
3352 sizeof(n->alternative_address));
3353 send_session_ack_message (n);
3354 break;
3355
3356 case GNUNET_TRANSPORT_PS_DISCONNECT:
3357 GNUNET_STATISTICS_update (GST_stats,
3358 gettext_noop
3359 ("# unexpected SYN_ACK messages (disconnecting)"),
3360 1, GNUNET_NO);
3361 return GNUNET_SYSERR;
3362
3363 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3364 GNUNET_assert (0);
3365 break;
3366
3367 default:
3368 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3369 "Unhandled state `%s'\n",
3370 GNUNET_TRANSPORT_ps2s (n->state));
3371 GNUNET_break (0);
3372 return GNUNET_SYSERR;
3373 }
3300 return GNUNET_OK; 3374 return GNUNET_OK;
3301} 3375}
3302 3376
@@ -3311,134 +3385,138 @@ GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message
3311 * this session was not in use 3385 * this session was not in use
3312 */ 3386 */
3313int 3387int
3314GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer, 3388GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3315 struct GNUNET_ATS_Session *session) 3389 struct GNUNET_ATS_Session *session)
3316{ 3390{
3317 struct NeighbourMapEntry *n; 3391 struct NeighbourMapEntry *n;
3318 3392
3319 if (NULL == (n = lookup_neighbour(peer))) 3393 if (NULL == (n = lookup_neighbour (peer)))
3320 return GNUNET_NO; /* can't affect us */ 3394 return GNUNET_NO; /* can't affect us */
3321 if (session != n->primary_address.session) 3395 if (session != n->primary_address.session)
3396 {
3397 /* Free alternative address */
3398 if (session == n->alternative_address.session)
3322 { 3399 {
3323 /* Free alternative address */ 3400 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)
3324 if (session == n->alternative_address.session) 3401 set_state_and_timeout (n,
3325 { 3402 GNUNET_TRANSPORT_PS_CONNECTED,
3326 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) 3403 n->timeout);
3327 set_state_and_timeout(n, 3404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3328 GNUNET_TRANSPORT_PS_CONNECTED, 3405 "Session died, cleaning up alternative address\n");
3329 n->timeout); 3406 free_address (&n->alternative_address);
3330 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3331 "Session died, cleaning up alternative address\n");
3332 free_address(&n->alternative_address);
3333 }
3334 return GNUNET_NO; /* doesn't affect us further */
3335 } 3407 }
3408 return GNUNET_NO; /* doesn't affect us further */
3409 }
3336 3410
3337 n->expect_latency_response = GNUNET_NO; 3411 n->expect_latency_response = GNUNET_NO;
3338 /* The session for neighbour's primary address died */ 3412 /* The session for neighbour's primary address died */
3339 switch (n->state) 3413 switch (n->state)
3340 { 3414 {
3341 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 3415 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
3342 GNUNET_break(0); 3416 GNUNET_break (0);
3343 free_neighbour(n); 3417 free_neighbour (n);
3344 return GNUNET_YES; 3418 return GNUNET_YES;
3345 3419
3346 case GNUNET_TRANSPORT_PS_INIT_ATS: 3420 case GNUNET_TRANSPORT_PS_INIT_ATS:
3347 GNUNET_break(0); 3421 GNUNET_break (0);
3348 free_neighbour(n); 3422 free_neighbour (n);
3349 return GNUNET_YES; 3423 return GNUNET_YES;
3350 3424
3351 case GNUNET_TRANSPORT_PS_SYN_SENT: 3425 case GNUNET_TRANSPORT_PS_SYN_SENT:
3352 /* The session used to send the SYN terminated: 3426 /* The session used to send the SYN terminated:
3353 * this implies a connect error*/ 3427 * this implies a connect error*/
3354 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3428 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3355 "Failed to send SYN in CONNECT_SENT with `%s' %p: session terminated\n", 3429 "Failed to send SYN in CONNECT_SENT with `%s' %p: session terminated\n",
3356 GST_plugins_a2s(n->primary_address.address), 3430 GST_plugins_a2s (n->primary_address.address),
3357 n->primary_address.session); 3431 n->primary_address.session);
3358 3432
3359 /* Destroy the address since it cannot be used */ 3433 /* Destroy the address since it cannot be used */
3360 unset_primary_address(n); 3434 unset_primary_address (n);
3361 set_state_and_timeout(n, 3435 set_state_and_timeout (n,
3362 GNUNET_TRANSPORT_PS_INIT_ATS, 3436 GNUNET_TRANSPORT_PS_INIT_ATS,
3363 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 3437 GNUNET_TIME_relative_to_absolute (
3364 break; 3438 ATS_RESPONSE_TIMEOUT));
3365 3439 break;
3366 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 3440
3367 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 3441 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3368 /* error on inbound session; free neighbour entirely */ 3442 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3369 free_neighbour(n); 3443 /* error on inbound session; free neighbour entirely */
3370 return GNUNET_YES; 3444 free_neighbour (n);
3371 3445 return GNUNET_YES;
3372 case GNUNET_TRANSPORT_PS_CONNECTED: 3446
3373 /* Our primary connection died, try a fast reconnect */ 3447 case GNUNET_TRANSPORT_PS_CONNECTED:
3374 unset_primary_address(n); 3448 /* Our primary connection died, try a fast reconnect */
3375 set_state_and_timeout(n, 3449 unset_primary_address (n);
3376 GNUNET_TRANSPORT_PS_RECONNECT_ATS, 3450 set_state_and_timeout (n,
3377 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 3451 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3378 break; 3452 GNUNET_TIME_relative_to_absolute (
3379 3453 ATS_RESPONSE_TIMEOUT));
3380 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 3454 break;
3381 /* we don't have an address, how can it go down? */ 3455
3382 GNUNET_break(0); 3456 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3383 break; 3457 /* we don't have an address, how can it go down? */
3384 3458 GNUNET_break (0);
3385 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 3459 break;
3386 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3460
3387 "Failed to send SYN in RECONNECT_SENT with `%s' %p: session terminated\n", 3461 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3388 GST_plugins_a2s(n->primary_address.address), 3462 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3389 n->primary_address.session); 3463 "Failed to send SYN in RECONNECT_SENT with `%s' %p: session terminated\n",
3390 /* Destroy the address since it cannot be used */ 3464 GST_plugins_a2s (n->primary_address.address),
3391 unset_primary_address(n); 3465 n->primary_address.session);
3392 set_state_and_timeout(n, 3466 /* Destroy the address since it cannot be used */
3393 GNUNET_TRANSPORT_PS_RECONNECT_ATS, 3467 unset_primary_address (n);
3394 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 3468 set_state_and_timeout (n,
3395 break; 3469 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3396 3470 GNUNET_TIME_relative_to_absolute (
3397 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 3471 ATS_RESPONSE_TIMEOUT));
3398 /* primary went down while we were waiting for SYN_ACK on secondary; 3472 break;
3399 secondary as primary */ 3473
3400 3474 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3401 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3475 /* primary went down while we were waiting for SYN_ACK on secondary;
3402 "Connection `%s' %p to peer `%s' was terminated while switching, " 3476 secondary as primary */
3403 "switching to alternative address `%s' %p\n", 3477
3404 GST_plugins_a2s(n->primary_address.address), 3478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3405 n->primary_address.session, 3479 "Connection `%s' %p to peer `%s' was terminated while switching, "
3406 GNUNET_i2s(peer), 3480 "switching to alternative address `%s' %p\n",
3407 GST_plugins_a2s(n->alternative_address.address), 3481 GST_plugins_a2s (n->primary_address.address),
3408 n->alternative_address.session); 3482 n->primary_address.session,
3409 3483 GNUNET_i2s (peer),
3410 /* Destroy the inbound address since it cannot be used */ 3484 GST_plugins_a2s (n->alternative_address.address),
3411 free_address(&n->primary_address); 3485 n->alternative_address.session);
3412 n->primary_address = n->alternative_address; 3486
3413 GNUNET_assert(GNUNET_YES == 3487 /* Destroy the inbound address since it cannot be used */
3414 GST_ats_is_known(n->primary_address.address, 3488 free_address (&n->primary_address);
3489 n->primary_address = n->alternative_address;
3490 GNUNET_assert (GNUNET_YES ==
3491 GST_ats_is_known (n->primary_address.address,
3415 n->primary_address.session)); 3492 n->primary_address.session));
3416 memset(&n->alternative_address, 3493 memset (&n->alternative_address,
3417 0, 3494 0,
3418 sizeof(struct NeighbourAddress)); 3495 sizeof(struct NeighbourAddress));
3419 set_state_and_timeout(n, 3496 set_state_and_timeout (n,
3420 GNUNET_TRANSPORT_PS_RECONNECT_SENT, 3497 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
3421 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT)); 3498 GNUNET_TIME_relative_to_absolute (
3422 break; 3499 FAST_RECONNECT_TIMEOUT));
3423 3500 break;
3424 case GNUNET_TRANSPORT_PS_DISCONNECT: 3501
3425 unset_primary_address(n); 3502 case GNUNET_TRANSPORT_PS_DISCONNECT:
3426 break; 3503 unset_primary_address (n);
3427 3504 break;
3428 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 3505
3429 /* neighbour was freed and plugins told to terminate session */ 3506 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3430 return GNUNET_NO; 3507 /* neighbour was freed and plugins told to terminate session */
3508 return GNUNET_NO;
3431 3509
3432 default: 3510 default:
3433 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3434 "Unhandled state `%s'\n", 3512 "Unhandled state `%s'\n",
3435 GNUNET_TRANSPORT_ps2s(n->state)); 3513 GNUNET_TRANSPORT_ps2s (n->state));
3436 GNUNET_break(0); 3514 GNUNET_break (0);
3437 break; 3515 break;
3438 } 3516 }
3439 if (NULL != n->task) 3517 if (NULL != n->task)
3440 GNUNET_SCHEDULER_cancel(n->task); 3518 GNUNET_SCHEDULER_cancel (n->task);
3441 n->task = GNUNET_SCHEDULER_add_now(&master_task, n); 3519 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
3442 return GNUNET_YES; 3520 return GNUNET_YES;
3443} 3521}
3444 3522
@@ -3454,32 +3532,32 @@ GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer,
3454 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 3532 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
3455 */ 3533 */
3456int 3534int
3457GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message, 3535GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3458 const struct GNUNET_HELLO_Address *address, 3536 const struct GNUNET_HELLO_Address *address,
3459 struct GNUNET_ATS_Session *session) 3537 struct GNUNET_ATS_Session *session)
3460{ 3538{
3461 struct NeighbourMapEntry *n; 3539 struct NeighbourMapEntry *n;
3462 3540
3463 (void)session; 3541 (void) session;
3464 if (ntohs(message->size) != sizeof(struct GNUNET_MessageHeader)) 3542 if (ntohs (message->size) != sizeof(struct GNUNET_MessageHeader))
3465 { 3543 {
3466 GNUNET_break_op(0); 3544 GNUNET_break_op (0);
3467 return GNUNET_SYSERR; 3545 return GNUNET_SYSERR;
3468 } 3546 }
3469 GNUNET_STATISTICS_update(GST_stats, 3547 GNUNET_STATISTICS_update (GST_stats,
3470 gettext_noop("# ACK messages received"), 3548 gettext_noop ("# ACK messages received"),
3471 1, 3549 1,
3472 GNUNET_NO); 3550 GNUNET_NO);
3473 if (NULL == (n = lookup_neighbour(&address->peer))) 3551 if (NULL == (n = lookup_neighbour (&address->peer)))
3474 { 3552 {
3475 GNUNET_break_op(0); 3553 GNUNET_break_op (0);
3476 return GNUNET_SYSERR; 3554 return GNUNET_SYSERR;
3477 } 3555 }
3478 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3479 "Received ACK for peer `%s' in state %s/%s\n", 3557 "Received ACK for peer `%s' in state %s/%s\n",
3480 GNUNET_i2s(&address->peer), 3558 GNUNET_i2s (&address->peer),
3481 GNUNET_TRANSPORT_ps2s(n->state), 3559 GNUNET_TRANSPORT_ps2s (n->state),
3482 print_ack_state(n->ack_state)); 3560 print_ack_state (n->ack_state));
3483 3561
3484 /* Check if we are in a plausible state for having sent 3562 /* Check if we are in a plausible state for having sent
3485 a SYN_ACK. If not, return, otherwise break. 3563 a SYN_ACK. If not, return, otherwise break.
@@ -3495,46 +3573,47 @@ GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message,
3495 if (((GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) && 3573 if (((GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) &&
3496 (ACK_SEND_ACK != n->ack_state)) || 3574 (ACK_SEND_ACK != n->ack_state)) ||
3497 (NULL == n->primary_address.address)) 3575 (NULL == n->primary_address.address))
3498 { 3576 {
3499 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 3577 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3500 "Received unexpected ACK message from peer `%s' in state %s/%s\n", 3578 "Received unexpected ACK message from peer `%s' in state %s/%s\n",
3501 GNUNET_i2s(&address->peer), 3579 GNUNET_i2s (&address->peer),
3502 GNUNET_TRANSPORT_ps2s(n->state), 3580 GNUNET_TRANSPORT_ps2s (n->state),
3503 print_ack_state(n->ack_state)); 3581 print_ack_state (n->ack_state));
3504 3582
3505 GNUNET_STATISTICS_update(GST_stats, 3583 GNUNET_STATISTICS_update (GST_stats,
3506 gettext_noop("# unexpected ACK messages"), 3584 gettext_noop ("# unexpected ACK messages"),
3507 1, 3585 1,
3508 GNUNET_NO); 3586 GNUNET_NO);
3509 return GNUNET_OK; 3587 return GNUNET_OK;
3510 } 3588 }
3511 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) 3589 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)
3512 { 3590 {
3513 /* We tried to switch addresses while being connect. We explicitly wait 3591 /* We tried to switch addresses while being connect. We explicitly wait
3514 * for a SYN_ACK before going to GNUNET_TRANSPORT_PS_CONNECTED, 3592 * for a SYN_ACK before going to GNUNET_TRANSPORT_PS_CONNECTED,
3515 * so we do not want to set the address as in use! */ 3593 * so we do not want to set the address as in use! */
3516 return GNUNET_OK; 3594 return GNUNET_OK;
3517 } 3595 }
3518 set_state_and_timeout(n, 3596 set_state_and_timeout (n,
3519 GNUNET_TRANSPORT_PS_CONNECTED, 3597 GNUNET_TRANSPORT_PS_CONNECTED,
3520 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 3598 GNUNET_TIME_relative_to_absolute (
3599 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3521 3600
3522 if (NULL == n->primary_address.address) 3601 if (NULL == n->primary_address.address)
3523 { 3602 {
3524 /* See issue #3693. 3603 /* See issue #3693.
3525 * We are in state = PSY_SYN_RECV_ACK or ack_state = ACK_SEND_ACK, which 3604 * We are in state = PSY_SYN_RECV_ACK or ack_state = ACK_SEND_ACK, which
3526 * really means we did try (and succeed) to send a SYN and are waiting for 3605 * really means we did try (and succeed) to send a SYN and are waiting for
3527 * an ACK. 3606 * an ACK.
3528 * That suggests that the primary_address used to be non-NULL, but maybe it 3607 * That suggests that the primary_address used to be non-NULL, but maybe it
3529 * got reset to NULL without the state being changed appropriately? 3608 * got reset to NULL without the state being changed appropriately?
3530 */ 3609 */
3531 GNUNET_break(0); 3610 GNUNET_break (0);
3532 return GNUNET_OK; 3611 return GNUNET_OK;
3533 } 3612 }
3534 3613
3535 /* Reset backoff for primary address */ 3614 /* Reset backoff for primary address */
3536 GST_ats_block_reset(n->primary_address.address, 3615 GST_ats_block_reset (n->primary_address.address,
3537 n->primary_address.session); 3616 n->primary_address.session);
3538 return GNUNET_OK; 3617 return GNUNET_OK;
3539} 3618}
3540 3619
@@ -3546,9 +3625,9 @@ GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message,
3546 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not 3625 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
3547 */ 3626 */
3548int 3627int
3549GST_neighbours_test_connected(const struct GNUNET_PeerIdentity *target) 3628GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
3550{ 3629{
3551 return test_connected(lookup_neighbour(target)); 3630 return test_connected (lookup_neighbour (target));
3552} 3631}
3553 3632
3554 3633
@@ -3558,15 +3637,15 @@ GST_neighbours_test_connected(const struct GNUNET_PeerIdentity *target)
3558 * @param cls the `struct NeighbourMapEntry` to free 3637 * @param cls the `struct NeighbourMapEntry` to free
3559 */ 3638 */
3560static void 3639static void
3561delayed_disconnect(void *cls) 3640delayed_disconnect (void *cls)
3562{ 3641{
3563 struct NeighbourMapEntry *n = cls; 3642 struct NeighbourMapEntry *n = cls;
3564 3643
3565 n->delayed_disconnect_task = NULL; 3644 n->delayed_disconnect_task = NULL;
3566 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3645 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3567 "Disconnecting by request from peer %s\n", 3646 "Disconnecting by request from peer %s\n",
3568 GNUNET_i2s(&n->id)); 3647 GNUNET_i2s (&n->id));
3569 free_neighbour(n); 3648 free_neighbour (n);
3570} 3649}
3571 3650
3572 3651
@@ -3578,42 +3657,44 @@ delayed_disconnect(void *cls)
3578 * @param msg the quota message 3657 * @param msg the quota message
3579 */ 3658 */
3580void 3659void
3581GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer, 3660GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
3582 const struct GNUNET_MessageHeader *msg) 3661 const struct GNUNET_MessageHeader *msg)
3583{ 3662{
3584 struct NeighbourMapEntry *n; 3663 struct NeighbourMapEntry *n;
3585 const struct GNUNET_ATS_SessionQuotaMessage *sqm; 3664 const struct GNUNET_ATS_SessionQuotaMessage *sqm;
3586 struct GNUNET_BANDWIDTH_Value32NBO last; 3665 struct GNUNET_BANDWIDTH_Value32NBO last;
3587 3666
3588 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3589 "Received QUOTA message from peer `%s'\n", 3668 "Received QUOTA message from peer `%s'\n",
3590 GNUNET_i2s(peer)); 3669 GNUNET_i2s (peer));
3591 if (ntohs(msg->size) != sizeof(struct GNUNET_ATS_SessionQuotaMessage)) 3670 if (ntohs (msg->size) != sizeof(struct GNUNET_ATS_SessionQuotaMessage))
3592 { 3671 {
3593 GNUNET_break_op(0); 3672 GNUNET_break_op (0);
3594 GNUNET_STATISTICS_update(GST_stats, 3673 GNUNET_STATISTICS_update (GST_stats,
3595 gettext_noop("# quota messages ignored (malformed)"), 3674 gettext_noop (
3596 1, 3675 "# quota messages ignored (malformed)"),
3597 GNUNET_NO); 3676 1,
3598 return; 3677 GNUNET_NO);
3599 } 3678 return;
3600 GNUNET_STATISTICS_update(GST_stats, 3679 }
3601 gettext_noop 3680 GNUNET_STATISTICS_update (GST_stats,
3602 ("# QUOTA messages received"), 3681 gettext_noop
3603 1, GNUNET_NO); 3682 ("# QUOTA messages received"),
3604 sqm = (const struct GNUNET_ATS_SessionQuotaMessage *)msg; 3683 1, GNUNET_NO);
3605 if (NULL == (n = lookup_neighbour(peer))) 3684 sqm = (const struct GNUNET_ATS_SessionQuotaMessage *) msg;
3606 { 3685 if (NULL == (n = lookup_neighbour (peer)))
3607 /* gone already */ 3686 {
3608 return; 3687 /* gone already */
3609 } 3688 return;
3610 last = GNUNET_BANDWIDTH_value_max(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 3689 }
3611 GNUNET_BANDWIDTH_value_init(ntohl(sqm->quota))); 3690 last = GNUNET_BANDWIDTH_value_max (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
3691 GNUNET_BANDWIDTH_value_init (ntohl (
3692 sqm->quota)));
3612 if (last.value__ != n->neighbour_receive_quota.value__) 3693 if (last.value__ != n->neighbour_receive_quota.value__)
3613 { 3694 {
3614 n->neighbour_receive_quota = last; 3695 n->neighbour_receive_quota = last;
3615 send_outbound_quota_to_clients(n); 3696 send_outbound_quota_to_clients (n);
3616 } 3697 }
3617} 3698}
3618 3699
3619 3700
@@ -3625,85 +3706,91 @@ GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer,
3625 * @param msg the disconnect message 3706 * @param msg the disconnect message
3626 */ 3707 */
3627void 3708void
3628GST_neighbours_handle_disconnect_message(const struct GNUNET_PeerIdentity *peer, 3709GST_neighbours_handle_disconnect_message (const struct
3629 const struct GNUNET_MessageHeader *msg) 3710 GNUNET_PeerIdentity *peer,
3711 const struct
3712 GNUNET_MessageHeader *msg)
3630{ 3713{
3631 struct NeighbourMapEntry *n; 3714 struct NeighbourMapEntry *n;
3632 const struct GNUNET_ATS_SessionDisconnectMessage *sdm; 3715 const struct GNUNET_ATS_SessionDisconnectMessage *sdm;
3633 3716
3634 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3635 "Received DISCONNECT message from peer `%s'\n", 3718 "Received DISCONNECT message from peer `%s'\n",
3636 GNUNET_i2s(peer)); 3719 GNUNET_i2s (peer));
3637 if (ntohs(msg->size) != sizeof(struct GNUNET_ATS_SessionDisconnectMessage)) 3720 if (ntohs (msg->size) != sizeof(struct GNUNET_ATS_SessionDisconnectMessage))
3638 { 3721 {
3639 GNUNET_break_op(0); 3722 GNUNET_break_op (0);
3640 GNUNET_STATISTICS_update(GST_stats, 3723 GNUNET_STATISTICS_update (GST_stats,
3641 gettext_noop 3724 gettext_noop
3642 ("# disconnect messages ignored (malformed)"), 3725 ("# disconnect messages ignored (malformed)"),
3643 1, 3726 1,
3644 GNUNET_NO); 3727 GNUNET_NO);
3645 return; 3728 return;
3646 } 3729 }
3647 GNUNET_STATISTICS_update(GST_stats, 3730 GNUNET_STATISTICS_update (GST_stats,
3648 gettext_noop 3731 gettext_noop
3649 ("# DISCONNECT messages received"), 3732 ("# DISCONNECT messages received"),
3650 1, GNUNET_NO); 3733 1, GNUNET_NO);
3651 sdm = (const struct GNUNET_ATS_SessionDisconnectMessage *)msg; 3734 sdm = (const struct GNUNET_ATS_SessionDisconnectMessage *) msg;
3652 if (NULL == (n = lookup_neighbour(peer))) 3735 if (NULL == (n = lookup_neighbour (peer)))
3653 { 3736 {
3654 /* gone already */ 3737 /* gone already */
3655 return; 3738 return;
3656 } 3739 }
3657 if (GNUNET_TIME_absolute_ntoh(sdm->timestamp).abs_value_us <= n->connect_ack_timestamp.abs_value_us) 3740 if (GNUNET_TIME_absolute_ntoh (sdm->timestamp).abs_value_us <=
3658 { 3741 n->connect_ack_timestamp.abs_value_us)
3659 GNUNET_STATISTICS_update(GST_stats, 3742 {
3660 gettext_noop("# disconnect messages ignored (timestamp)"), 3743 GNUNET_STATISTICS_update (GST_stats,
3661 1, 3744 gettext_noop (
3662 GNUNET_NO); 3745 "# disconnect messages ignored (timestamp)"),
3663 return; 3746 1,
3664 } 3747 GNUNET_NO);
3665 if (0 != memcmp(peer, 3748 return;
3666 &sdm->public_key, 3749 }
3667 sizeof(struct GNUNET_PeerIdentity))) 3750 if (0 != memcmp (peer,
3668 { 3751 &sdm->public_key,
3669 GNUNET_break_op(0); 3752 sizeof(struct GNUNET_PeerIdentity)))
3670 return; 3753 {
3671 } 3754 GNUNET_break_op (0);
3672 if (ntohl(sdm->purpose.size) != 3755 return;
3673 sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + 3756 }
3674 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + 3757 if (ntohl (sdm->purpose.size) !=
3675 sizeof(struct GNUNET_TIME_AbsoluteNBO)) 3758 sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
3676 { 3759 + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
3677 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3760 + sizeof(struct GNUNET_TIME_AbsoluteNBO))
3678 "DISCONNECT message from peer `%s' has invalid size\n", 3761 {
3679 GNUNET_i2s(peer)); 3762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3680 GNUNET_break_op(0); 3763 "DISCONNECT message from peer `%s' has invalid size\n",
3681 return; 3764 GNUNET_i2s (peer));
3682 } 3765 GNUNET_break_op (0);
3766 return;
3767 }
3683 if (GNUNET_OK != 3768 if (GNUNET_OK !=
3684 GNUNET_CRYPTO_eddsa_verify(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, 3769 GNUNET_CRYPTO_eddsa_verify (
3685 &sdm->purpose, 3770 GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT,
3686 &sdm->signature, 3771 &sdm->purpose,
3687 &sdm->public_key)) 3772 &sdm->signature,
3688 { 3773 &sdm->public_key))
3689 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3774 {
3690 "DISCONNECT message from peer `%s' cannot be verified \n", 3775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3691 GNUNET_i2s(peer)); 3776 "DISCONNECT message from peer `%s' cannot be verified \n",
3692 GNUNET_break_op(0); 3777 GNUNET_i2s (peer));
3693 return; 3778 GNUNET_break_op (0);
3694 } 3779 return;
3780 }
3695 if (NULL == n->delayed_disconnect_task) 3781 if (NULL == n->delayed_disconnect_task)
3696 { 3782 {
3697 n->delayed_disconnect_task = GNUNET_SCHEDULER_add_now(&delayed_disconnect, 3783 n->delayed_disconnect_task = GNUNET_SCHEDULER_add_now (&delayed_disconnect,
3698 n); 3784 n);
3699 } 3785 }
3700} 3786}
3701 3787
3702 3788
3703/** 3789/**
3704 * Closure for the #neighbours_iterate() function. 3790 * Closure for the #neighbours_iterate() function.
3705 */ 3791 */
3706struct IteratorContext { 3792struct IteratorContext
3793{
3707 /** 3794 /**
3708 * Function to call on each connected neighbour. 3795 * Function to call on each connected neighbour.
3709 */ 3796 */
@@ -3725,32 +3812,32 @@ struct IteratorContext {
3725 * @return #GNUNET_OK (continue to iterate) 3812 * @return #GNUNET_OK (continue to iterate)
3726 */ 3813 */
3727static int 3814static int
3728neighbours_iterate(void *cls, 3815neighbours_iterate (void *cls,
3729 const struct GNUNET_PeerIdentity *key, 3816 const struct GNUNET_PeerIdentity *key,
3730 void *value) 3817 void *value)
3731{ 3818{
3732 struct IteratorContext *ic = cls; 3819 struct IteratorContext *ic = cls;
3733 struct NeighbourMapEntry *n = value; 3820 struct NeighbourMapEntry *n = value;
3734 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 3821 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
3735 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; 3822 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
3736 3823
3737 (void)key; 3824 (void) key;
3738 if (NULL != n->primary_address.address) 3825 if (NULL != n->primary_address.address)
3739 { 3826 {
3740 bandwidth_in = n->primary_address.bandwidth_in; 3827 bandwidth_in = n->primary_address.bandwidth_in;
3741 bandwidth_out = n->primary_address.bandwidth_out; 3828 bandwidth_out = n->primary_address.bandwidth_out;
3742 } 3829 }
3743 else 3830 else
3744 { 3831 {
3745 bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 3832 bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
3746 bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 3833 bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
3747 } 3834 }
3748 ic->cb(ic->cb_cls, 3835 ic->cb (ic->cb_cls,
3749 &n->id, 3836 &n->id,
3750 n->primary_address.address, 3837 n->primary_address.address,
3751 n->state, 3838 n->state,
3752 n->timeout, 3839 n->timeout,
3753 bandwidth_in, bandwidth_out); 3840 bandwidth_in, bandwidth_out);
3754 return GNUNET_OK; 3841 return GNUNET_OK;
3755} 3842}
3756 3843
@@ -3762,8 +3849,8 @@ neighbours_iterate(void *cls,
3762 * @param cb_cls closure for @a cb 3849 * @param cb_cls closure for @a cb
3763 */ 3850 */
3764void 3851void
3765GST_neighbours_iterate(GST_NeighbourIterator cb, 3852GST_neighbours_iterate (GST_NeighbourIterator cb,
3766 void *cb_cls) 3853 void *cb_cls)
3767{ 3854{
3768 struct IteratorContext ic; 3855 struct IteratorContext ic;
3769 3856
@@ -3771,9 +3858,9 @@ GST_neighbours_iterate(GST_NeighbourIterator cb,
3771 return; /* can happen during shutdown */ 3858 return; /* can happen during shutdown */
3772 ic.cb = cb; 3859 ic.cb = cb;
3773 ic.cb_cls = cb_cls; 3860 ic.cb_cls = cb_cls;
3774 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 3861 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
3775 &neighbours_iterate, 3862 &neighbours_iterate,
3776 &ic); 3863 &ic);
3777} 3864}
3778 3865
3779 3866
@@ -3783,21 +3870,22 @@ GST_neighbours_iterate(GST_NeighbourIterator cb,
3783 * @param target peer to disconnect from 3870 * @param target peer to disconnect from
3784 */ 3871 */
3785void 3872void
3786GST_neighbours_force_disconnect(const struct GNUNET_PeerIdentity *target) 3873GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
3787{ 3874{
3788 struct NeighbourMapEntry *n; 3875 struct NeighbourMapEntry *n;
3789 3876
3790 if (NULL == (n = lookup_neighbour(target))) 3877 if (NULL == (n = lookup_neighbour (target)))
3791 return; /* not active */ 3878 return; /* not active */
3792 if (GNUNET_YES == test_connected(n)) 3879 if (GNUNET_YES == test_connected (n))
3793 GNUNET_STATISTICS_update(GST_stats, 3880 GNUNET_STATISTICS_update (GST_stats,
3794 gettext_noop("# disconnected from peer upon explicit request"), 3881 gettext_noop (
3795 1, 3882 "# disconnected from peer upon explicit request"),
3796 GNUNET_NO); 3883 1,
3797 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3884 GNUNET_NO);
3798 "Forced disconnect from peer %s\n", 3885 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3799 GNUNET_i2s(target)); 3886 "Forced disconnect from peer %s\n",
3800 disconnect_neighbour(n); 3887 GNUNET_i2s (target));
3888 disconnect_neighbour (n);
3801} 3889}
3802 3890
3803 3891
@@ -3808,11 +3896,11 @@ GST_neighbours_force_disconnect(const struct GNUNET_PeerIdentity *target)
3808 * @return address currently used 3896 * @return address currently used
3809 */ 3897 */
3810const struct GNUNET_HELLO_Address * 3898const struct GNUNET_HELLO_Address *
3811GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer) 3899GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer)
3812{ 3900{
3813 struct NeighbourMapEntry *n; 3901 struct NeighbourMapEntry *n;
3814 3902
3815 n = lookup_neighbour(peer); 3903 n = lookup_neighbour (peer);
3816 if (NULL == n) 3904 if (NULL == n)
3817 return NULL; 3905 return NULL;
3818 return n->primary_address.address; 3906 return n->primary_address.address;
@@ -3825,14 +3913,15 @@ GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer)
3825 * @param max_fds maximum number of fds to use 3913 * @param max_fds maximum number of fds to use
3826 */ 3914 */
3827void 3915void
3828GST_neighbours_start(unsigned int max_fds) 3916GST_neighbours_start (unsigned int max_fds)
3829{ 3917{
3830 (void)max_fds; 3918 (void) max_fds;
3831 neighbours = GNUNET_CONTAINER_multipeermap_create(NEIGHBOUR_TABLE_SIZE, 3919 neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE,
3832 GNUNET_NO); 3920 GNUNET_NO);
3833 util_transmission_tk = GNUNET_SCHEDULER_add_delayed(UTIL_TRANSMISSION_INTERVAL, 3921 util_transmission_tk = GNUNET_SCHEDULER_add_delayed (
3834 &utilization_transmission, 3922 UTIL_TRANSMISSION_INTERVAL,
3835 NULL); 3923 &utilization_transmission,
3924 NULL);
3836} 3925}
3837 3926
3838 3927
@@ -3845,18 +3934,18 @@ GST_neighbours_start(unsigned int max_fds)
3845 * @return #GNUNET_OK (continue to iterate) 3934 * @return #GNUNET_OK (continue to iterate)
3846 */ 3935 */
3847static int 3936static int
3848disconnect_all_neighbours(void *cls, 3937disconnect_all_neighbours (void *cls,
3849 const struct GNUNET_PeerIdentity *key, 3938 const struct GNUNET_PeerIdentity *key,
3850 void *value) 3939 void *value)
3851{ 3940{
3852 struct NeighbourMapEntry *n = value; 3941 struct NeighbourMapEntry *n = value;
3853 3942
3854 (void)cls; 3943 (void) cls;
3855 (void)key; 3944 (void) key;
3856 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3857 "Disconnecting peer `%4s' during shutdown\n", 3946 "Disconnecting peer `%4s' during shutdown\n",
3858 GNUNET_i2s(&n->id)); 3947 GNUNET_i2s (&n->id));
3859 free_neighbour(n); 3948 free_neighbour (n);
3860 return GNUNET_OK; 3949 return GNUNET_OK;
3861} 3950}
3862 3951
@@ -3865,19 +3954,19 @@ disconnect_all_neighbours(void *cls,
3865 * Cleanup the neighbours subsystem. 3954 * Cleanup the neighbours subsystem.
3866 */ 3955 */
3867void 3956void
3868GST_neighbours_stop() 3957GST_neighbours_stop ()
3869{ 3958{
3870 if (NULL == neighbours) 3959 if (NULL == neighbours)
3871 return; 3960 return;
3872 if (NULL != util_transmission_tk) 3961 if (NULL != util_transmission_tk)
3873 { 3962 {
3874 GNUNET_SCHEDULER_cancel(util_transmission_tk); 3963 GNUNET_SCHEDULER_cancel (util_transmission_tk);
3875 util_transmission_tk = NULL; 3964 util_transmission_tk = NULL;
3876 } 3965 }
3877 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 3966 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
3878 &disconnect_all_neighbours, 3967 &disconnect_all_neighbours,
3879 NULL); 3968 NULL);
3880 GNUNET_CONTAINER_multipeermap_destroy(neighbours); 3969 GNUNET_CONTAINER_multipeermap_destroy (neighbours);
3881 neighbours = NULL; 3970 neighbours = NULL;
3882} 3971}
3883 3972
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 @@
40 * @param max_fds maximum number of fds to use 40 * @param max_fds maximum number of fds to use
41 */ 41 */
42void 42void
43GST_neighbours_start(unsigned int max_fds); 43GST_neighbours_start (unsigned int max_fds);
44 44
45 45
46/** 46/**
47 * Cleanup the neighbours subsystem. 47 * Cleanup the neighbours subsystem.
48 */ 48 */
49void 49void
50GST_neighbours_stop(void); 50GST_neighbours_stop (void);
51 51
52 52
53/** 53/**
@@ -57,7 +57,7 @@ GST_neighbours_stop(void);
57 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not 57 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
58 */ 58 */
59int 59int
60GST_neighbours_test_connected(const struct GNUNET_PeerIdentity *target); 60GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
61 61
62 62
63/** 63/**
@@ -86,11 +86,11 @@ typedef void
86 * @param cont_cls closure for @a cont 86 * @param cont_cls closure for @a cont
87 */ 87 */
88void 88void
89GST_neighbours_send(const struct GNUNET_PeerIdentity *target, 89GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
90 const void *msg, 90 const void *msg,
91 size_t msg_size, 91 size_t msg_size,
92 struct GNUNET_TIME_Relative timeout, 92 struct GNUNET_TIME_Relative timeout,
93 GST_NeighbourSendContinuation cont, void *cont_cls); 93 GST_NeighbourSendContinuation cont, void *cont_cls);
94 94
95 95
96/** 96/**
@@ -105,9 +105,10 @@ GST_neighbours_send(const struct GNUNET_PeerIdentity *target,
105 * @return how long to wait before reading more from this sender 105 * @return how long to wait before reading more from this sender
106 */ 106 */
107struct GNUNET_TIME_Relative 107struct GNUNET_TIME_Relative
108GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender, 108GST_neighbours_calculate_receive_delay (const struct
109 ssize_t size, 109 GNUNET_PeerIdentity *sender,
110 int *do_forward); 110 ssize_t size,
111 int *do_forward);
111 112
112 113
113/** 114/**
@@ -118,8 +119,8 @@ GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender,
118 * @param m the keep alive message containing the nonce to respond to 119 * @param m the keep alive message containing the nonce to respond to
119 */ 120 */
120void 121void
121GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour, 122GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
122 const struct GNUNET_MessageHeader *m); 123 const struct GNUNET_MessageHeader *m);
123 124
124 125
125/** 126/**
@@ -131,8 +132,8 @@ GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour,
131 * @param m the message containing the keep alive response 132 * @param m the message containing the keep alive response
132 */ 133 */
133void 134void
134GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour, 135GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
135 const struct GNUNET_MessageHeader *m); 136 const struct GNUNET_MessageHeader *m);
136 137
137 138
138/** 139/**
@@ -141,7 +142,7 @@ GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour,
141 * @param target peer to disconnect from 142 * @param target peer to disconnect from
142 */ 143 */
143void 144void
144GST_neighbours_force_disconnect(const struct GNUNET_PeerIdentity *target); 145GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
145 146
146 147
147/** 148/**
@@ -172,7 +173,7 @@ typedef void
172 * @param cb_cls closure for @a cb 173 * @param cb_cls closure for @a cb
173 */ 174 */
174void 175void
175GST_neighbours_iterate(GST_NeighbourIterator cb, void *cb_cls); 176GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
176 177
177 178
178/** 179/**
@@ -184,8 +185,8 @@ GST_neighbours_iterate(GST_NeighbourIterator cb, void *cb_cls);
184 * this session was not in use 185 * this session was not in use
185 */ 186 */
186int 187int
187GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer, 188GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
188 struct GNUNET_ATS_Session *session); 189 struct GNUNET_ATS_Session *session);
189 190
190 191
191/** 192/**
@@ -197,8 +198,8 @@ GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer,
197 * @param message the message we received (really only the size is used) 198 * @param message the message we received (really only the size is used)
198 */ 199 */
199void 200void
200GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address, 201GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address,
201 const struct GNUNET_MessageHeader *message); 202 const struct GNUNET_MessageHeader *message);
202 203
203 204
204/** 205/**
@@ -211,9 +212,9 @@ GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address,
211 * @param message the message we sent (really only the size is used) 212 * @param message the message we sent (really only the size is used)
212 */ 213 */
213void 214void
214GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address, 215GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address,
215 struct GNUNET_ATS_Session *session, 216 struct GNUNET_ATS_Session *session,
216 size_t size); 217 size_t size);
217 218
218 219
219/** 220/**
@@ -226,10 +227,12 @@ GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address,
226 * @param bandwidth_out outbound quota to be used when connection is up 227 * @param bandwidth_out outbound quota to be used when connection is up
227 */ 228 */
228void 229void
229GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address, 230GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
230 struct GNUNET_ATS_Session *session, 231 struct GNUNET_ATS_Session *session,
231 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 232 struct GNUNET_BANDWIDTH_Value32NBO
232 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); 233 bandwidth_in,
234 struct GNUNET_BANDWIDTH_Value32NBO
235 bandwidth_out);
233 236
234 237
235/** 238/**
@@ -241,8 +244,8 @@ GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address,
241 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 244 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
242 */ 245 */
243int 246int
244GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message, 247GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
245 const struct GNUNET_PeerIdentity *peer); 248 const struct GNUNET_PeerIdentity *peer);
246 249
247 250
248/** 251/**
@@ -255,9 +258,11 @@ GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message,
255 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 258 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
256 */ 259 */
257int 260int
258GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message, 261GST_neighbours_handle_session_syn_ack (const struct
259 const struct GNUNET_HELLO_Address *address, 262 GNUNET_MessageHeader *message,
260 struct GNUNET_ATS_Session *session); 263 const struct
264 GNUNET_HELLO_Address *address,
265 struct GNUNET_ATS_Session *session);
261 266
262 267
263/** 268/**
@@ -271,9 +276,9 @@ GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message
271 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 276 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
272 */ 277 */
273int 278int
274GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message, 279GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
275 const struct GNUNET_HELLO_Address *address, 280 const struct GNUNET_HELLO_Address *address,
276 struct GNUNET_ATS_Session *session); 281 struct GNUNET_ATS_Session *session);
277 282
278 283
279/** 284/**
@@ -283,7 +288,7 @@ GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message,
283 * @return address currently used 288 * @return address currently used
284 */ 289 */
285const struct GNUNET_HELLO_Address * 290const struct GNUNET_HELLO_Address *
286GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer); 291GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
287 292
288 293
289/** 294/**
@@ -294,8 +299,8 @@ GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer);
294 * @param msg the quota message 299 * @param msg the quota message
295 */ 300 */
296void 301void
297GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer, 302GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
298 const struct GNUNET_MessageHeader *msg); 303 const struct GNUNET_MessageHeader *msg);
299 304
300 305
301/** 306/**
@@ -306,8 +311,10 @@ GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer,
306 * @param msg the disconnect message 311 * @param msg the disconnect message
307 */ 312 */
308void 313void
309GST_neighbours_handle_disconnect_message(const struct GNUNET_PeerIdentity *peer, 314GST_neighbours_handle_disconnect_message (const struct
310 const struct GNUNET_MessageHeader *msg); 315 GNUNET_PeerIdentity *peer,
316 const struct
317 GNUNET_MessageHeader *msg);
311 318
312 319
313#endif 320#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 @@
32/** 32/**
33 * Entry in doubly-linked list of all of our plugins. 33 * Entry in doubly-linked list of all of our plugins.
34 */ 34 */
35struct TransportPlugin { 35struct TransportPlugin
36{
36 /** 37 /**
37 * This is a doubly-linked list. 38 * This is a doubly-linked list.
38 */ 39 */
@@ -86,12 +87,12 @@ static struct TransportPlugin *plugins_tail;
86 * @param distance new distance 87 * @param distance new distance
87 */ 88 */
88static void 89static void
89plugin_env_update_distance(void *cls, 90plugin_env_update_distance (void *cls,
90 const struct GNUNET_HELLO_Address *address, 91 const struct GNUNET_HELLO_Address *address,
91 uint32_t distance) 92 uint32_t distance)
92{ 93{
93 GST_ats_update_distance(address, 94 GST_ats_update_distance (address,
94 distance); 95 distance);
95} 96}
96 97
97 98
@@ -105,18 +106,18 @@ plugin_env_update_distance(void *cls,
105 * @return type of the network @a addr belongs to 106 * @return type of the network @a addr belongs to
106 */ 107 */
107static enum GNUNET_NetworkType 108static enum GNUNET_NetworkType
108plugin_env_address_to_type(void *cls, 109plugin_env_address_to_type (void *cls,
109 const struct sockaddr *addr, 110 const struct sockaddr *addr,
110 size_t addrlen) 111 size_t addrlen)
111{ 112{
112 if (NULL == GST_is) 113 if (NULL == GST_is)
113 { 114 {
114 GNUNET_break(0); 115 GNUNET_break (0);
115 return GNUNET_NT_UNSPECIFIED; 116 return GNUNET_NT_UNSPECIFIED;
116 } 117 }
117 return GNUNET_NT_scanner_get_type(GST_is, 118 return GNUNET_NT_scanner_get_type (GST_is,
118 addr, 119 addr,
119 addrlen); 120 addrlen);
120} 121}
121 122
122 123
@@ -133,10 +134,10 @@ plugin_env_address_to_type(void *cls,
133 * @param address_type_cb function to call when a address type is requested 134 * @param address_type_cb function to call when a address type is requested
134 */ 135 */
135void 136void
136GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 137GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
137 GNUNET_TRANSPORT_AddressNotification address_cb, 138 GNUNET_TRANSPORT_AddressNotification address_cb,
138 GNUNET_TRANSPORT_SessionStart session_start_cb, 139 GNUNET_TRANSPORT_SessionStart session_start_cb,
139 GNUNET_TRANSPORT_SessionEnd session_end_cb) 140 GNUNET_TRANSPORT_SessionEnd session_end_cb)
140{ 141{
141 struct TransportPlugin *plug; 142 struct TransportPlugin *plug;
142 struct TransportPlugin *next; 143 struct TransportPlugin *next;
@@ -147,175 +148,175 @@ GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
147 int fail; 148 int fail;
148 149
149 if (GNUNET_OK != 150 if (GNUNET_OK !=
150 GNUNET_CONFIGURATION_get_value_number(GST_cfg, 151 GNUNET_CONFIGURATION_get_value_number (GST_cfg,
151 "TRANSPORT", 152 "TRANSPORT",
152 "NEIGHBOUR_LIMIT", 153 "NEIGHBOUR_LIMIT",
153 &tneigh)) 154 &tneigh))
154 { 155 {
155 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
156 _("Transport service is lacking NEIGHBOUR_LIMIT option.\n")); 157 _ ("Transport service is lacking NEIGHBOUR_LIMIT option.\n"));
157 return; 158 return;
158 } 159 }
159 if (GNUNET_OK != 160 if (GNUNET_OK !=
160 GNUNET_CONFIGURATION_get_value_string(GST_cfg, 161 GNUNET_CONFIGURATION_get_value_string (GST_cfg,
161 "TRANSPORT", 162 "TRANSPORT",
162 "PLUGINS", 163 "PLUGINS",
163 &plugs)) 164 &plugs))
164 return; 165 return;
165 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 166 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
166 _("Starting transport plugins `%s'\n"), 167 _ ("Starting transport plugins `%s'\n"),
167 plugs); 168 plugs);
168 for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " ")) 169 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
169 { 170 {
170 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 171 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
171 _("Loading `%s' transport plugin\n"), 172 _ ("Loading `%s' transport plugin\n"),
172 pos); 173 pos);
173 GNUNET_asprintf(&libname, 174 GNUNET_asprintf (&libname,
174 "libgnunet_plugin_transport_%s", 175 "libgnunet_plugin_transport_%s",
175 pos); 176 pos);
176 plug = GNUNET_new(struct TransportPlugin); 177 plug = GNUNET_new (struct TransportPlugin);
177 plug->short_name = GNUNET_strdup(pos); 178 plug->short_name = GNUNET_strdup (pos);
178 plug->lib_name = libname; 179 plug->lib_name = libname;
179 plug->env.cfg = GST_cfg; 180 plug->env.cfg = GST_cfg;
180 plug->env.my_identity = &GST_my_identity; 181 plug->env.my_identity = &GST_my_identity;
181 plug->env.get_our_hello = &GST_hello_get; 182 plug->env.get_our_hello = &GST_hello_get;
182 plug->env.cls = plug->short_name; 183 plug->env.cls = plug->short_name;
183 plug->env.receive = recv_cb; 184 plug->env.receive = recv_cb;
184 plug->env.notify_address = address_cb; 185 plug->env.notify_address = address_cb;
185 plug->env.session_start = session_start_cb; 186 plug->env.session_start = session_start_cb;
186 plug->env.session_end = session_end_cb; 187 plug->env.session_end = session_end_cb;
187 plug->env.get_address_type = &plugin_env_address_to_type; 188 plug->env.get_address_type = &plugin_env_address_to_type;
188 plug->env.update_address_distance = &plugin_env_update_distance; 189 plug->env.update_address_distance = &plugin_env_update_distance;
189 plug->env.max_connections = tneigh; 190 plug->env.max_connections = tneigh;
190 plug->env.stats = GST_stats; 191 plug->env.stats = GST_stats;
191 GNUNET_CONTAINER_DLL_insert(plugins_head, 192 GNUNET_CONTAINER_DLL_insert (plugins_head,
192 plugins_tail, 193 plugins_tail,
193 plug); 194 plug);
194 } 195 }
195 GNUNET_free(plugs); 196 GNUNET_free (plugs);
196 next = plugins_head; 197 next = plugins_head;
197 while (NULL != next) 198 while (NULL != next)
199 {
200 plug = next;
201 next = plug->next;
202 plug->api = GNUNET_PLUGIN_load (plug->lib_name,
203 &plug->env);
204 if (NULL == plug->api)
205 {
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
207 _ ("Failed to load transport plugin for `%s'\n"),
208 plug->lib_name);
209 GNUNET_CONTAINER_DLL_remove (plugins_head,
210 plugins_tail,
211 plug);
212 GNUNET_free (plug->short_name);
213 GNUNET_free (plug->lib_name);
214 GNUNET_free (plug);
215 continue;
216 }
217 fail = GNUNET_NO;
218 if (NULL == plug->api->address_pretty_printer)
219 {
220 fail = GNUNET_YES;
221 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
222 _ ("Missing function `%s' in transport plugin for `%s'\n"),
223 "address_pretty_printer",
224 plug->lib_name);
225 }
226 if (NULL == plug->api->address_to_string)
227 {
228 fail = GNUNET_YES;
229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
230 _ ("Missing function `%s' in transport plugin for `%s'\n"),
231 "address_to_string",
232 plug->lib_name);
233 }
234 if (NULL == plug->api->string_to_address)
235 {
236 fail = GNUNET_YES;
237 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
238 _ ("Missing function `%s' in transport plugin for `%s'\n"),
239 "string_to_address",
240 plug->lib_name);
241 }
242 if (NULL == plug->api->check_address)
243 {
244 fail = GNUNET_YES;
245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
246 _ ("Missing function `%s' in transport plugin for `%s'\n"),
247 "check_address",
248 plug->lib_name);
249 }
250 if (NULL == plug->api->get_session)
251 {
252 fail = GNUNET_YES;
253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
254 _ ("Missing function `%s' in transport plugin for `%s'\n"),
255 "get_session",
256 plug->lib_name);
257 }
258 if (NULL == plug->api->get_network)
259 {
260 fail = GNUNET_YES;
261 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
262 _ ("Missing function `%s' in transport plugin for `%s'\n"),
263 "get_network",
264 plug->lib_name);
265 }
266 if (NULL == plug->api->send)
267 {
268 fail = GNUNET_YES;
269 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
270 _ ("Missing function `%s' in transport plugin for `%s'\n"),
271 "send",
272 plug->lib_name);
273 }
274 if (NULL == plug->api->disconnect_peer)
198 { 275 {
199 plug = next; 276 fail = GNUNET_YES;
200 next = plug->next; 277 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
201 plug->api = GNUNET_PLUGIN_load(plug->lib_name, 278 _ ("Missing function `%s' in transport plugin for `%s'\n"),
202 &plug->env); 279 "disconnect_peer",
203 if (NULL == plug->api) 280 plug->lib_name);
204 {
205 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
206 _("Failed to load transport plugin for `%s'\n"),
207 plug->lib_name);
208 GNUNET_CONTAINER_DLL_remove(plugins_head,
209 plugins_tail,
210 plug);
211 GNUNET_free(plug->short_name);
212 GNUNET_free(plug->lib_name);
213 GNUNET_free(plug);
214 continue;
215 }
216 fail = GNUNET_NO;
217 if (NULL == plug->api->address_pretty_printer)
218 {
219 fail = GNUNET_YES;
220 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
221 _("Missing function `%s' in transport plugin for `%s'\n"),
222 "address_pretty_printer",
223 plug->lib_name);
224 }
225 if (NULL == plug->api->address_to_string)
226 {
227 fail = GNUNET_YES;
228 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
229 _("Missing function `%s' in transport plugin for `%s'\n"),
230 "address_to_string",
231 plug->lib_name);
232 }
233 if (NULL == plug->api->string_to_address)
234 {
235 fail = GNUNET_YES;
236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
237 _("Missing function `%s' in transport plugin for `%s'\n"),
238 "string_to_address",
239 plug->lib_name);
240 }
241 if (NULL == plug->api->check_address)
242 {
243 fail = GNUNET_YES;
244 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
245 _("Missing function `%s' in transport plugin for `%s'\n"),
246 "check_address",
247 plug->lib_name);
248 }
249 if (NULL == plug->api->get_session)
250 {
251 fail = GNUNET_YES;
252 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
253 _("Missing function `%s' in transport plugin for `%s'\n"),
254 "get_session",
255 plug->lib_name);
256 }
257 if (NULL == plug->api->get_network)
258 {
259 fail = GNUNET_YES;
260 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
261 _("Missing function `%s' in transport plugin for `%s'\n"),
262 "get_network",
263 plug->lib_name);
264 }
265 if (NULL == plug->api->send)
266 {
267 fail = GNUNET_YES;
268 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
269 _("Missing function `%s' in transport plugin for `%s'\n"),
270 "send",
271 plug->lib_name);
272 }
273 if (NULL == plug->api->disconnect_peer)
274 {
275 fail = GNUNET_YES;
276 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
277 _("Missing function `%s' in transport plugin for `%s'\n"),
278 "disconnect_peer",
279 plug->lib_name);
280 }
281 if (NULL == plug->api->disconnect_session)
282 {
283 fail = GNUNET_YES;
284 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
285 _("Missing function `%s' in transport plugin for `%s'\n"),
286 "disconnect_session",
287 plug->lib_name);
288 }
289 if (NULL == plug->api->query_keepalive_factor)
290 {
291 fail = GNUNET_YES;
292 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
293 _("Missing function `%s' in transport plugin for `%s'\n"),
294 "query_keepalive_factor",
295 plug->lib_name);
296 }
297 if (NULL == plug->api->update_session_timeout)
298 {
299 fail = GNUNET_YES;
300 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
301 _("Missing function `%s' in transport plugin for `%s'\n"),
302 "update_session_timeout",
303 plug->lib_name);
304 }
305 if (GNUNET_YES == fail)
306 {
307 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
308 _("Did not load plugin `%s' due to missing functions\n"),
309 plug->lib_name);
310 GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api));
311 GNUNET_CONTAINER_DLL_remove(plugins_head,
312 plugins_tail,
313 plug);
314 GNUNET_free(plug->short_name);
315 GNUNET_free(plug->lib_name);
316 GNUNET_free(plug);
317 }
318 } 281 }
282 if (NULL == plug->api->disconnect_session)
283 {
284 fail = GNUNET_YES;
285 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
286 _ ("Missing function `%s' in transport plugin for `%s'\n"),
287 "disconnect_session",
288 plug->lib_name);
289 }
290 if (NULL == plug->api->query_keepalive_factor)
291 {
292 fail = GNUNET_YES;
293 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
294 _ ("Missing function `%s' in transport plugin for `%s'\n"),
295 "query_keepalive_factor",
296 plug->lib_name);
297 }
298 if (NULL == plug->api->update_session_timeout)
299 {
300 fail = GNUNET_YES;
301 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
302 _ ("Missing function `%s' in transport plugin for `%s'\n"),
303 "update_session_timeout",
304 plug->lib_name);
305 }
306 if (GNUNET_YES == fail)
307 {
308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
309 _ ("Did not load plugin `%s' due to missing functions\n"),
310 plug->lib_name);
311 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
312 GNUNET_CONTAINER_DLL_remove (plugins_head,
313 plugins_tail,
314 plug);
315 GNUNET_free (plug->short_name);
316 GNUNET_free (plug->lib_name);
317 GNUNET_free (plug);
318 }
319 }
319} 320}
320 321
321 322
@@ -323,18 +324,18 @@ GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
323 * Unload all plugins 324 * Unload all plugins
324 */ 325 */
325void 326void
326GST_plugins_unload() 327GST_plugins_unload ()
327{ 328{
328 struct TransportPlugin *plug; 329 struct TransportPlugin *plug;
329 330
330 while (NULL != (plug = plugins_head)) 331 while (NULL != (plug = plugins_head))
331 { 332 {
332 GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api)); 333 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
333 GNUNET_free(plug->lib_name); 334 GNUNET_free (plug->lib_name);
334 GNUNET_free(plug->short_name); 335 GNUNET_free (plug->short_name);
335 GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug); 336 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
336 GNUNET_free(plug); 337 GNUNET_free (plug);
337 } 338 }
338} 339}
339 340
340 341
@@ -345,12 +346,12 @@ GST_plugins_unload()
345 * @return the plugin's API, NULL if the plugin is not loaded 346 * @return the plugin's API, NULL if the plugin is not loaded
346 */ 347 */
347struct GNUNET_TRANSPORT_PluginFunctions * 348struct GNUNET_TRANSPORT_PluginFunctions *
348GST_plugins_find(const char *name) 349GST_plugins_find (const char *name)
349{ 350{
350 struct TransportPlugin *pos; 351 struct TransportPlugin *pos;
351 352
352 for (pos = plugins_head; NULL != pos; pos = pos->next) 353 for (pos = plugins_head; NULL != pos; pos = pos->next)
353 if (0 == strcmp(name, pos->short_name)) 354 if (0 == strcmp (name, pos->short_name))
354 break; 355 break;
355 if (NULL == pos) 356 if (NULL == pos)
356 return NULL; 357 return NULL;
@@ -369,18 +370,18 @@ GST_plugins_find(const char *name)
369 * @return the plugin's API, NULL if the plugin is not loaded 370 * @return the plugin's API, NULL if the plugin is not loaded
370 */ 371 */
371struct GNUNET_TRANSPORT_PluginFunctions * 372struct GNUNET_TRANSPORT_PluginFunctions *
372GST_plugins_printer_find(const char *name) 373GST_plugins_printer_find (const char *name)
373{ 374{
374 struct TransportPlugin *pos; 375 struct TransportPlugin *pos;
375 char *stripped = GNUNET_strdup(name); 376 char *stripped = GNUNET_strdup (name);
376 char *sep = strchr(stripped, '_'); 377 char *sep = strchr (stripped, '_');
377 378
378 if (NULL != sep) 379 if (NULL != sep)
379 sep[0] = '\0'; 380 sep[0] = '\0';
380 for (pos = plugins_head; NULL != pos; pos = pos->next) 381 for (pos = plugins_head; NULL != pos; pos = pos->next)
381 if (pos->short_name == strstr(pos->short_name, stripped)) 382 if (pos->short_name == strstr (pos->short_name, stripped))
382 break; 383 break;
383 GNUNET_free(stripped); 384 GNUNET_free (stripped);
384 if (NULL == pos) 385 if (NULL == pos)
385 return NULL; 386 return NULL;
386 return pos->api; 387 return pos->api;
@@ -395,7 +396,7 @@ GST_plugins_printer_find(const char *name)
395 * @return statically allocated (!) human-readable address 396 * @return statically allocated (!) human-readable address
396 */ 397 */
397const char * 398const char *
398GST_plugins_a2s(const struct GNUNET_HELLO_Address *address) 399GST_plugins_a2s (const struct GNUNET_HELLO_Address *address)
399{ 400{
400 struct GNUNET_TRANSPORT_PluginFunctions *api; 401 struct GNUNET_TRANSPORT_PluginFunctions *api;
401 static char unable_to_show[1024]; 402 static char unable_to_show[1024];
@@ -405,26 +406,26 @@ GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
405 return "<NULL>"; 406 return "<NULL>";
406 if (0 == address->address_length) 407 if (0 == address->address_length)
407 return TRANSPORT_SESSION_INBOUND_STRING; /* Addresse with length 0 are inbound, address->address itself may be NULL */ 408 return TRANSPORT_SESSION_INBOUND_STRING; /* Addresse with length 0 are inbound, address->address itself may be NULL */
408 api = GST_plugins_printer_find(address->transport_name); 409 api = GST_plugins_printer_find (address->transport_name);
409 if (NULL == api) 410 if (NULL == api)
410 { 411 {
411 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
412 "Failed to find transport plugin `%s'\n", 413 "Failed to find transport plugin `%s'\n",
413 address->transport_name); 414 address->transport_name);
414 return "<plugin unknown>"; 415 return "<plugin unknown>";
415 } 416 }
416 if (0 == address->address_length) 417 if (0 == address->address_length)
417 { 418 {
418 GNUNET_snprintf(unable_to_show, 419 GNUNET_snprintf (unable_to_show,
419 sizeof(unable_to_show), 420 sizeof(unable_to_show),
420 "<unable to stringify %u-byte long address of %s transport>", 421 "<unable to stringify %u-byte long address of %s transport>",
421 (unsigned int)address->address_length, 422 (unsigned int) address->address_length,
422 address->transport_name); 423 address->transport_name);
423 return unable_to_show; 424 return unable_to_show;
424 } 425 }
425 return(NULL != (s = api->address_to_string(NULL, 426 return(NULL != (s = api->address_to_string (NULL,
426 address->address, 427 address->address,
427 address->address_length)) 428 address->address_length))
428 ? s 429 ? s
429 : "<invalid>"); 430 : "<invalid>");
430} 431}
@@ -437,18 +438,18 @@ GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
437 * @param cb_cls closure for @a cb 438 * @param cb_cls closure for @a cb
438 */ 439 */
439void 440void
440GST_plugins_monitor_subscribe(GNUNET_TRANSPORT_SessionInfoCallback cb, 441GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb,
441 void *cb_cls) 442 void *cb_cls)
442{ 443{
443 struct TransportPlugin *pos; 444 struct TransportPlugin *pos;
444 445
445 for (pos = plugins_head; NULL != pos; pos = pos->next) 446 for (pos = plugins_head; NULL != pos; pos = pos->next)
446 if (NULL == pos->api->setup_monitor) 447 if (NULL == pos->api->setup_monitor)
447 GNUNET_break(0); 448 GNUNET_break (0);
448 else 449 else
449 pos->api->setup_monitor(pos->api->cls, 450 pos->api->setup_monitor (pos->api->cls,
450 cb, 451 cb,
451 cb_cls); 452 cb_cls);
452} 453}
453 454
454 455
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 @@
49 * @param metric_update_cb function to call when address metrics change 49 * @param metric_update_cb function to call when address metrics change
50 */ 50 */
51void 51void
52GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 52GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
53 GNUNET_TRANSPORT_AddressNotification address_cb, 53 GNUNET_TRANSPORT_AddressNotification address_cb,
54 GNUNET_TRANSPORT_SessionStart session_start_cb, 54 GNUNET_TRANSPORT_SessionStart session_start_cb,
55 GNUNET_TRANSPORT_SessionEnd session_end_cb); 55 GNUNET_TRANSPORT_SessionEnd session_end_cb);
56 56
57/** 57/**
58 * Unload all plugins 58 * Unload all plugins
59 */ 59 */
60void 60void
61GST_plugins_unload(void); 61GST_plugins_unload (void);
62 62
63 63
64/** 64/**
@@ -68,7 +68,7 @@ GST_plugins_unload(void);
68 * @return the plugin's API, NULL if the plugin is not loaded 68 * @return the plugin's API, NULL if the plugin is not loaded
69 */ 69 */
70struct GNUNET_TRANSPORT_PluginFunctions * 70struct GNUNET_TRANSPORT_PluginFunctions *
71GST_plugins_find(const char *name); 71GST_plugins_find (const char *name);
72 72
73 73
74/** 74/**
@@ -82,7 +82,7 @@ GST_plugins_find(const char *name);
82 * @return the plugin's API, NULL if the plugin is not loaded 82 * @return the plugin's API, NULL if the plugin is not loaded
83 */ 83 */
84struct GNUNET_TRANSPORT_PluginFunctions * 84struct GNUNET_TRANSPORT_PluginFunctions *
85GST_plugins_printer_find(const char *name); 85GST_plugins_printer_find (const char *name);
86 86
87 87
88/** 88/**
@@ -93,7 +93,7 @@ GST_plugins_printer_find(const char *name);
93 * @return statically allocated (!) human-readable address 93 * @return statically allocated (!) human-readable address
94 */ 94 */
95const char * 95const char *
96GST_plugins_a2s(const struct GNUNET_HELLO_Address *address); 96GST_plugins_a2s (const struct GNUNET_HELLO_Address *address);
97 97
98 98
99/** 99/**
@@ -103,8 +103,8 @@ GST_plugins_a2s(const struct GNUNET_HELLO_Address *address);
103 * @param cb_cls closure for @a cb 103 * @param cb_cls closure for @a cb
104 */ 104 */
105void 105void
106GST_plugins_monitor_subscribe(GNUNET_TRANSPORT_SessionInfoCallback cb, 106GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb,
107 void *cb_cls); 107 void *cb_cls);
108 108
109 109
110#endif 110#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 @@
42 * was successful? If that is clarified/determined, "UGH" in 42 * was successful? If that is clarified/determined, "UGH" in
43 * ~gnunetpeerinfogtk.c:1103 should be resolved. 43 * ~gnunetpeerinfogtk.c:1103 should be resolved.
44 */ 44 */
45enum GNUNET_TRANSPORT_ValidationState { 45enum GNUNET_TRANSPORT_ValidationState
46{
46 /** 47 /**
47 * Undefined state 48 * Undefined state
48 * 49 *
@@ -89,14 +90,16 @@ enum GNUNET_TRANSPORT_ValidationState {
89 * OTOH, we don't want to spend too much time generating PONG signatures, 90 * OTOH, we don't want to spend too much time generating PONG signatures,
90 * so they must have some lifetime to reduce our CPU usage. 91 * so they must have some lifetime to reduce our CPU usage.
91 */ 92 */
92#define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 1) 93#define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply ( \
94 GNUNET_TIME_UNIT_HOURS, 1)
93 95
94/** 96/**
95 * After how long do we expire an address in a HELLO that we just 97 * After how long do we expire an address in a HELLO that we just
96 * validated? This value is also used for our own addresses when we 98 * validated? This value is also used for our own addresses when we
97 * create a HELLO. 99 * create a HELLO.
98 */ 100 */
99#define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 12) 101#define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply ( \
102 GNUNET_TIME_UNIT_HOURS, 12)
100 103
101/** 104/**
102 * How often do we allow PINGing an address that we have not yet 105 * How often do we allow PINGing an address that we have not yet
@@ -104,24 +107,28 @@ enum GNUNET_TRANSPORT_ValidationState {
104 * we cannot validate (because after this time we can destroy the 107 * we cannot validate (because after this time we can destroy the
105 * validation record). 108 * validation record).
106 */ 109 */
107#define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) 110#define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply ( \
111 GNUNET_TIME_UNIT_MINUTES, 5)
108 112
109/** 113/**
110 * How often do we PING an address that we have successfully validated 114 * How often do we PING an address that we have successfully validated
111 * in the past but are not actively using? Should be (significantly) 115 * in the past but are not actively using? Should be (significantly)
112 * smaller than HELLO_ADDRESS_EXPIRATION. 116 * smaller than HELLO_ADDRESS_EXPIRATION.
113 */ 117 */
114#define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) 118#define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply ( \
119 GNUNET_TIME_UNIT_MINUTES, 15)
115 120
116/** 121/**
117 * How often do we PING an address that we are currently using? 122 * How often do we PING an address that we are currently using?
118 */ 123 */
119#define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) 124#define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply ( \
125 GNUNET_TIME_UNIT_MINUTES, 2)
120 126
121/** 127/**
122 * How much delay is acceptable for sending the PING or PONG? 128 * How much delay is acceptable for sending the PING or PONG?
123 */ 129 */
124#define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) 130#define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply ( \
131 GNUNET_TIME_UNIT_SECONDS, 1)
125 132
126/** 133/**
127 * Size of the validation map hashmap. 134 * Size of the validation map hashmap.
@@ -147,7 +154,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
147 * or an empty address if we are just sending a PING to confirm that a 154 * or an empty address if we are just sending a PING to confirm that a
148 * connection which the receiver (of the PING) initiated is still valid. 155 * connection which the receiver (of the PING) initiated is still valid.
149 */ 156 */
150struct TransportPingMessage { 157struct TransportPingMessage
158{
151 /** 159 /**
152 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PING 160 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PING
153 */ 161 */
@@ -175,7 +183,8 @@ struct TransportPingMessage {
175 * if the PING had not address either (and we received the request via 183 * if the PING had not address either (and we received the request via
176 * a connection that we initiated). 184 * a connection that we initiated).
177 */ 185 */
178struct TransportPongMessage { 186struct TransportPongMessage
187{
179 /** 188 /**
180 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PONG 189 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PONG
181 */ 190 */
@@ -214,7 +223,8 @@ GNUNET_NETWORK_STRUCT_END
214/** 223/**
215 * Information about an address under validation 224 * Information about an address under validation
216 */ 225 */
217struct ValidationEntry { 226struct ValidationEntry
227{
218 /** 228 /**
219 * The address. 229 * The address.
220 */ 230 */
@@ -352,7 +362,8 @@ static struct GNUNET_TIME_Absolute validation_next;
352/** 362/**
353 * Context for the validation entry match function. 363 * Context for the validation entry match function.
354 */ 364 */
355struct ValidationEntryMatchContext { 365struct ValidationEntryMatchContext
366{
356 /** 367 /**
357 * Where to store the result? 368 * Where to store the result?
358 */ 369 */
@@ -371,12 +382,12 @@ struct ValidationEntryMatchContext {
371 * is changed. 382 * is changed.
372 */ 383 */
373static void 384static void
374publish_ve_stat_update() 385publish_ve_stat_update ()
375{ 386{
376 GNUNET_STATISTICS_set(GST_stats, 387 GNUNET_STATISTICS_set (GST_stats,
377 gettext_noop("# Addresses in validation map"), 388 gettext_noop ("# Addresses in validation map"),
378 GNUNET_CONTAINER_multipeermap_size(validation_map), 389 GNUNET_CONTAINER_multipeermap_size (validation_map),
379 GNUNET_NO); 390 GNUNET_NO);
380} 391}
381 392
382 393
@@ -390,19 +401,19 @@ publish_ve_stat_update()
390 * #GNUNET_NO if the entry does match 401 * #GNUNET_NO if the entry does match
391 */ 402 */
392static int 403static int
393validation_entry_match(void *cls, 404validation_entry_match (void *cls,
394 const struct GNUNET_PeerIdentity *key, 405 const struct GNUNET_PeerIdentity *key,
395 void *value) 406 void *value)
396{ 407{
397 struct ValidationEntryMatchContext *vemc = cls; 408 struct ValidationEntryMatchContext *vemc = cls;
398 struct ValidationEntry *ve = value; 409 struct ValidationEntry *ve = value;
399 410
400 if (0 == GNUNET_HELLO_address_cmp(ve->address, 411 if (0 == GNUNET_HELLO_address_cmp (ve->address,
401 vemc->address)) 412 vemc->address))
402 { 413 {
403 vemc->ve = ve; 414 vemc->ve = ve;
404 return GNUNET_NO; 415 return GNUNET_NO;
405 } 416 }
406 return GNUNET_YES; 417 return GNUNET_YES;
407} 418}
408 419
@@ -415,8 +426,8 @@ validation_entry_match(void *cls,
415 * @param state new state 426 * @param state new state
416 */ 427 */
417static void 428static void
418validation_entry_changed(struct ValidationEntry *ve, 429validation_entry_changed (struct ValidationEntry *ve,
419 enum GNUNET_TRANSPORT_ValidationState state) 430 enum GNUNET_TRANSPORT_ValidationState state)
420{ 431{
421 ve->state = state; 432 ve->state = state;
422} 433}
@@ -431,9 +442,9 @@ validation_entry_changed(struct ValidationEntry *ve,
431 * @return #GNUNET_YES (continue to iterate) 442 * @return #GNUNET_YES (continue to iterate)
432 */ 443 */
433static int 444static int
434cleanup_validation_entry(void *cls, 445cleanup_validation_entry (void *cls,
435 const struct GNUNET_PeerIdentity *key, 446 const struct GNUNET_PeerIdentity *key,
436 void *value) 447 void *value)
437{ 448{
438 struct ValidationEntry *ve = value; 449 struct ValidationEntry *ve = value;
439 450
@@ -441,47 +452,47 @@ cleanup_validation_entry(void *cls,
441 ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS; 452 ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
442 453
443 /* Notify about deleted entry */ 454 /* Notify about deleted entry */
444 validation_entry_changed(ve, 455 validation_entry_changed (ve,
445 GNUNET_TRANSPORT_VS_REMOVE); 456 GNUNET_TRANSPORT_VS_REMOVE);
446 457
447 if (NULL != ve->bc) 458 if (NULL != ve->bc)
448 { 459 {
449 GST_blacklist_test_cancel(ve->bc); 460 GST_blacklist_test_cancel (ve->bc);
450 ve->bc = NULL; 461 ve->bc = NULL;
451 } 462 }
452 GNUNET_break(GNUNET_OK == 463 GNUNET_break (GNUNET_OK ==
453 GNUNET_CONTAINER_multipeermap_remove(validation_map, 464 GNUNET_CONTAINER_multipeermap_remove (validation_map,
454 &ve->address->peer, 465 &ve->address->peer,
455 ve)); 466 ve));
456 publish_ve_stat_update(); 467 publish_ve_stat_update ();
457 if (GNUNET_YES == ve->known_to_ats) 468 if (GNUNET_YES == ve->known_to_ats)
458 { 469 {
459 GST_ats_expire_address(ve->address); 470 GST_ats_expire_address (ve->address);
460 GNUNET_assert(GNUNET_NO == 471 GNUNET_assert (GNUNET_NO ==
461 GST_ats_is_known_no_session(ve->address)); 472 GST_ats_is_known_no_session (ve->address));
462 ve->known_to_ats = GNUNET_NO; 473 ve->known_to_ats = GNUNET_NO;
463 } 474 }
464 GNUNET_HELLO_address_free(ve->address); 475 GNUNET_HELLO_address_free (ve->address);
465 if (NULL != ve->timeout_task) 476 if (NULL != ve->timeout_task)
466 { 477 {
467 GNUNET_SCHEDULER_cancel(ve->timeout_task); 478 GNUNET_SCHEDULER_cancel (ve->timeout_task);
468 ve->timeout_task = NULL; 479 ve->timeout_task = NULL;
469 } 480 }
470 if (NULL != ve->revalidation_task) 481 if (NULL != ve->revalidation_task)
471 { 482 {
472 GNUNET_SCHEDULER_cancel(ve->revalidation_task); 483 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
473 ve->revalidation_task = NULL; 484 ve->revalidation_task = NULL;
474 } 485 }
475 if ((GNUNET_YES == ve->expecting_pong) && 486 if ((GNUNET_YES == ve->expecting_pong) &&
476 (validations_running > 0)) 487 (validations_running > 0))
477 { 488 {
478 validations_running--; 489 validations_running--;
479 GNUNET_STATISTICS_set(GST_stats, 490 GNUNET_STATISTICS_set (GST_stats,
480 gettext_noop("# validations running"), 491 gettext_noop ("# validations running"),
481 validations_running, 492 validations_running,
482 GNUNET_NO); 493 GNUNET_NO);
483 } 494 }
484 GNUNET_free(ve); 495 GNUNET_free (ve);
485 return GNUNET_OK; 496 return GNUNET_OK;
486} 497}
487 498
@@ -493,7 +504,7 @@ cleanup_validation_entry(void *cls,
493 * @param cls the `struct ValidationEntry` 504 * @param cls the `struct ValidationEntry`
494 */ 505 */
495static void 506static void
496timeout_hello_validation(void *cls) 507timeout_hello_validation (void *cls)
497{ 508{
498 struct ValidationEntry *ve = cls; 509 struct ValidationEntry *ve = cls;
499 struct GNUNET_TIME_Absolute max; 510 struct GNUNET_TIME_Absolute max;
@@ -503,27 +514,28 @@ timeout_hello_validation(void *cls)
503 /* For valid addresses, we want to wait until the expire; 514 /* For valid addresses, we want to wait until the expire;
504 for addresses under PING validation, we want to wait 515 for addresses under PING validation, we want to wait
505 until we give up on the PING */ 516 until we give up on the PING */
506 max = GNUNET_TIME_absolute_max(ve->valid_until, 517 max = GNUNET_TIME_absolute_max (ve->valid_until,
507 ve->revalidation_block); 518 ve->revalidation_block);
508 left = GNUNET_TIME_absolute_get_remaining(max); 519 left = GNUNET_TIME_absolute_get_remaining (max);
509 if (left.rel_value_us > 0) 520 if (left.rel_value_us > 0)
510 { 521 {
511 /* We should wait a bit longer. This happens when 522 /* We should wait a bit longer. This happens when
512 address lifetimes are extended due to successful 523 address lifetimes are extended due to successful
513 validations. */ 524 validations. */
514 ve->timeout_task = 525 ve->timeout_task =
515 GNUNET_SCHEDULER_add_delayed(left, 526 GNUNET_SCHEDULER_add_delayed (left,
516 &timeout_hello_validation, 527 &timeout_hello_validation,
517 ve); 528 ve);
518 return; 529 return;
519 } 530 }
520 GNUNET_STATISTICS_update(GST_stats, 531 GNUNET_STATISTICS_update (GST_stats,
521 gettext_noop("# address records discarded (timeout)"), 532 gettext_noop (
522 1, 533 "# address records discarded (timeout)"),
523 GNUNET_NO); 534 1,
524 cleanup_validation_entry(NULL, 535 GNUNET_NO);
525 &ve->address->peer, 536 cleanup_validation_entry (NULL,
526 ve); 537 &ve->address->peer,
538 ve);
527} 539}
528 540
529 541
@@ -540,11 +552,11 @@ timeout_hello_validation(void *cls)
540 * #GNUNET_SYSERR if operation was aborted 552 * #GNUNET_SYSERR if operation was aborted
541 */ 553 */
542static void 554static void
543transmit_ping_if_allowed(void *cls, 555transmit_ping_if_allowed (void *cls,
544 const struct GNUNET_PeerIdentity *pid, 556 const struct GNUNET_PeerIdentity *pid,
545 const struct GNUNET_HELLO_Address *address_null, 557 const struct GNUNET_HELLO_Address *address_null,
546 struct GNUNET_ATS_Session *session_null, 558 struct GNUNET_ATS_Session *session_null,
547 int result) 559 int result)
548{ 560{
549 struct ValidationEntry *ve = cls; 561 struct ValidationEntry *ve = cls;
550 struct TransportPingMessage ping; 562 struct TransportPingMessage ping;
@@ -559,116 +571,119 @@ transmit_ping_if_allowed(void *cls,
559 571
560 ve->bc = NULL; 572 ve->bc = NULL;
561 if (GNUNET_OK != result) 573 if (GNUNET_OK != result)
562 { 574 {
563 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
564 "Blacklist denies sending PING to `%s' `%s' `%s'\n", 576 "Blacklist denies sending PING to `%s' `%s' `%s'\n",
565 GNUNET_i2s(pid), 577 GNUNET_i2s (pid),
566 GST_plugins_a2s(ve->address), 578 GST_plugins_a2s (ve->address),
567 ve->address->transport_name); 579 ve->address->transport_name);
568 GNUNET_STATISTICS_update(GST_stats, 580 GNUNET_STATISTICS_update (GST_stats,
569 gettext_noop("# address records discarded (blacklist)"), 581 gettext_noop (
570 1, 582 "# address records discarded (blacklist)"),
571 GNUNET_NO); 583 1,
572 cleanup_validation_entry(NULL, 584 GNUNET_NO);
573 pid, 585 cleanup_validation_entry (NULL,
574 ve); 586 pid,
575 return; 587 ve);
576 } 588 return;
577 hello = GST_hello_get(); 589 }
578 GNUNET_assert(NULL != hello); 590 hello = GST_hello_get ();
579 slen = strlen(ve->address->transport_name) + 1; 591 GNUNET_assert (NULL != hello);
580 hsize = ntohs(hello->size); 592 slen = strlen (ve->address->transport_name) + 1;
581 tsize = sizeof(struct TransportPingMessage) + 593 hsize = ntohs (hello->size);
582 ve->address->address_length + slen + hsize; 594 tsize = sizeof(struct TransportPingMessage)
595 + ve->address->address_length + slen + hsize;
583 596
584 ping.header.size = 597 ping.header.size =
585 htons(sizeof(struct TransportPingMessage) + 598 htons (sizeof(struct TransportPingMessage)
586 ve->address->address_length + slen); 599 + ve->address->address_length + slen);
587 ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); 600 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
588 ping.challenge = htonl(ve->challenge); 601 ping.challenge = htonl (ve->challenge);
589 ping.target = *pid; 602 ping.target = *pid;
590 603
591 if (tsize >= GNUNET_MAX_MESSAGE_SIZE) 604 if (tsize >= GNUNET_MAX_MESSAGE_SIZE)
592 { 605 {
593 GNUNET_break(0); 606 GNUNET_break (0);
594 hsize = 0; 607 hsize = 0;
595 tsize = 608 tsize =
596 sizeof(struct TransportPingMessage) + ve->address->address_length + 609 sizeof(struct TransportPingMessage) + ve->address->address_length
597 slen + hsize; 610 + slen + hsize;
598 } 611 }
599 { 612 {
600 char message_buf[tsize] GNUNET_ALIGN; 613 char message_buf[tsize] GNUNET_ALIGN;
601 614
602 GNUNET_memcpy(message_buf, 615 GNUNET_memcpy (message_buf,
603 hello, 616 hello,
604 hsize); 617 hsize);
605 GNUNET_memcpy(&message_buf[hsize], 618 GNUNET_memcpy (&message_buf[hsize],
606 &ping, 619 &ping,
607 sizeof(struct TransportPingMessage)); 620 sizeof(struct TransportPingMessage));
608 GNUNET_memcpy(&message_buf[sizeof(struct TransportPingMessage) + hsize], 621 GNUNET_memcpy (&message_buf[sizeof(struct TransportPingMessage) + hsize],
609 ve->address->transport_name, 622 ve->address->transport_name,
610 slen); 623 slen);
611 GNUNET_memcpy(&message_buf[sizeof(struct TransportPingMessage) + slen + hsize], 624 GNUNET_memcpy (&message_buf[sizeof(struct TransportPingMessage) + slen
612 ve->address->address, 625 + hsize],
613 ve->address->address_length); 626 ve->address->address,
614 papi = GST_plugins_find(ve->address->transport_name); 627 ve->address->address_length);
615 GNUNET_assert(NULL != papi); 628 papi = GST_plugins_find (ve->address->transport_name);
616 session = papi->get_session(papi->cls, 629 GNUNET_assert (NULL != papi);
617 ve->address); 630 session = papi->get_session (papi->cls,
631 ve->address);
618 if (NULL == session) 632 if (NULL == session)
619 { 633 {
620 /* Could not get a valid session */ 634 /* Could not get a valid session */
621 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
622 "Failed to get session to send PING to `%s' at `%s'\n", 636 "Failed to get session to send PING to `%s' at `%s'\n",
623 GNUNET_i2s(pid), 637 GNUNET_i2s (pid),
624 GST_plugins_a2s(ve->address)); 638 GST_plugins_a2s (ve->address));
625 return; 639 return;
626 } 640 }
627 641
628 ret = papi->send(papi->cls, session, 642 ret = papi->send (papi->cls, session,
629 message_buf, tsize, 643 message_buf, tsize,
630 PING_PRIORITY, 644 PING_PRIORITY,
631 ACCEPTABLE_PING_DELAY, 645 ACCEPTABLE_PING_DELAY,
632 NULL, NULL); 646 NULL, NULL);
633 if (-1 == ret) 647 if (-1 == ret)
634 { 648 {
635 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 649 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
636 "Failed to send PING to `%s' at `%s'\n", 650 "Failed to send PING to `%s' at `%s'\n",
637 GNUNET_i2s(pid), 651 GNUNET_i2s (pid),
638 GST_plugins_a2s(ve->address)); 652 GST_plugins_a2s (ve->address));
639 return; 653 return;
640 } 654 }
641 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
642 "Transmitted plain PING to `%s' `%s' `%s'\n", 656 "Transmitted plain PING to `%s' `%s' `%s'\n",
643 GNUNET_i2s(pid), 657 GNUNET_i2s (pid),
644 GST_plugins_a2s(ve->address), 658 GST_plugins_a2s (ve->address),
645 ve->address->transport_name); 659 ve->address->transport_name);
646 ve->network = papi->get_network(papi->cls, 660 ve->network = papi->get_network (papi->cls,
647 session); 661 session);
648 GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network); 662 GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network);
649 GST_neighbours_notify_data_sent(ve->address, 663 GST_neighbours_notify_data_sent (ve->address,
650 session, 664 session,
651 tsize); 665 tsize);
652 next = GNUNET_TIME_relative_to_absolute(validation_delay); 666 next = GNUNET_TIME_relative_to_absolute (validation_delay);
653 validation_next = GNUNET_TIME_absolute_max(next, 667 validation_next = GNUNET_TIME_absolute_max (next,
654 validation_next); 668 validation_next);
655 ve->send_time = GNUNET_TIME_absolute_get(); 669 ve->send_time = GNUNET_TIME_absolute_get ();
656 GNUNET_STATISTICS_update(GST_stats, 670 GNUNET_STATISTICS_update (GST_stats,
657 gettext_noop("# PINGs for address validation sent"), 671 gettext_noop (
658 1, 672 "# PINGs for address validation sent"),
659 GNUNET_NO); 673 1,
674 GNUNET_NO);
660 ve->expecting_pong = GNUNET_YES; 675 ve->expecting_pong = GNUNET_YES;
661 validations_running++; 676 validations_running++;
662 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
663 "Validation started, %u validation processes running\n", 678 "Validation started, %u validation processes running\n",
664 validations_running); 679 validations_running);
665 GNUNET_STATISTICS_set(GST_stats, 680 GNUNET_STATISTICS_set (GST_stats,
666 gettext_noop("# validations running"), 681 gettext_noop ("# validations running"),
667 validations_running, 682 validations_running,
668 GNUNET_NO); 683 GNUNET_NO);
669 /* Notify about PING sent */ 684 /* Notify about PING sent */
670 validation_entry_changed(ve, 685 validation_entry_changed (ve,
671 GNUNET_TRANSPORT_VS_UPDATE); 686 GNUNET_TRANSPORT_VS_UPDATE);
672 } 687 }
673} 688}
674 689
@@ -679,7 +694,7 @@ transmit_ping_if_allowed(void *cls,
679 * @param cls the `struct ValidationEntry` 694 * @param cls the `struct ValidationEntry`
680 */ 695 */
681static void 696static void
682revalidate_address(void *cls) 697revalidate_address (void *cls)
683{ 698{
684 struct ValidationEntry *ve = cls; 699 struct ValidationEntry *ve = cls;
685 struct GNUNET_TIME_Relative canonical_delay; 700 struct GNUNET_TIME_Relative canonical_delay;
@@ -689,12 +704,13 @@ revalidate_address(void *cls)
689 uint32_t rdelay; 704 uint32_t rdelay;
690 705
691 ve->revalidation_task = NULL; 706 ve->revalidation_task = NULL;
692 delay = GNUNET_TIME_absolute_get_remaining(ve->revalidation_block); 707 delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block);
693 /* Considering current connectivity situation, what is the maximum 708 /* Considering current connectivity situation, what is the maximum
694 block period permitted? */ 709 block period permitted? */
695 if (GNUNET_YES == ve->in_use) 710 if (GNUNET_YES == ve->in_use)
696 canonical_delay = CONNECTED_PING_FREQUENCY; 711 canonical_delay = CONNECTED_PING_FREQUENCY;
697 else if (GNUNET_TIME_absolute_get_remaining(ve->valid_until).rel_value_us > 0) 712 else if (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us >
713 0)
698 canonical_delay = VALIDATED_PING_FREQUENCY; 714 canonical_delay = VALIDATED_PING_FREQUENCY;
699 else 715 else
700 canonical_delay = UNVALIDATED_PING_KEEPALIVE; 716 canonical_delay = UNVALIDATED_PING_KEEPALIVE;
@@ -702,94 +718,96 @@ revalidate_address(void *cls)
702 new maximum delay (which may be lower); the real delay 718 new maximum delay (which may be lower); the real delay
703 is originally randomized between "canonical_delay" and "2 * canonical_delay", 719 is originally randomized between "canonical_delay" and "2 * canonical_delay",
704 so continue to permit that window for the operation. */ 720 so continue to permit that window for the operation. */
705 delay = GNUNET_TIME_relative_min(delay, 721 delay = GNUNET_TIME_relative_min (delay,
706 GNUNET_TIME_relative_multiply(canonical_delay, 722 GNUNET_TIME_relative_multiply (
707 2)); 723 canonical_delay,
708 ve->revalidation_block = GNUNET_TIME_relative_to_absolute(delay); 724 2));
725 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay);
709 if (delay.rel_value_us > 0) 726 if (delay.rel_value_us > 0)
710 { 727 {
711 /* should wait a bit longer */ 728 /* should wait a bit longer */
712 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
713 "Waiting for %s longer before (re)validating address `%s'\n", 730 "Waiting for %s longer before (re)validating address `%s'\n",
714 GNUNET_STRINGS_relative_time_to_string(delay, 731 GNUNET_STRINGS_relative_time_to_string (delay,
715 GNUNET_YES), 732 GNUNET_YES),
716 GST_plugins_a2s(ve->address)); 733 GST_plugins_a2s (ve->address));
717 ve->revalidation_task = 734 ve->revalidation_task =
718 GNUNET_SCHEDULER_add_delayed(delay, 735 GNUNET_SCHEDULER_add_delayed (delay,
719 &revalidate_address, ve); 736 &revalidate_address, ve);
720 ve->next_validation = GNUNET_TIME_relative_to_absolute(delay); 737 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
721 return; 738 return;
722 } 739 }
723 /* check if globally we have too many active validations at a 740 /* check if globally we have too many active validations at a
724 too high rate, if so, delay ours */ 741 too high rate, if so, delay ours */
725 blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next); 742 blocked_for = GNUNET_TIME_absolute_get_remaining (validation_next);
726 if ((validations_running > validations_fast_start_threshold) && 743 if ((validations_running > validations_fast_start_threshold) &&
727 (blocked_for.rel_value_us > 0)) 744 (blocked_for.rel_value_us > 0))
728 { 745 {
729 /* Validations are blocked, have to wait for blocked_for time */ 746 /* Validations are blocked, have to wait for blocked_for time */
730 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
731 "Validations blocked for another %s, delaying validating address `%s'\n", 748 "Validations blocked for another %s, delaying validating address `%s'\n",
732 GNUNET_STRINGS_relative_time_to_string(blocked_for, 749 GNUNET_STRINGS_relative_time_to_string (blocked_for,
733 GNUNET_YES), 750 GNUNET_YES),
734 GST_plugins_a2s(ve->address)); 751 GST_plugins_a2s (ve->address));
735 GNUNET_STATISTICS_update(GST_stats, 752 GNUNET_STATISTICS_update (GST_stats,
736 gettext_noop("# validations delayed by global throttle"), 753 gettext_noop (
737 1, 754 "# validations delayed by global throttle"),
738 GNUNET_NO); 755 1,
739 ve->revalidation_task = 756 GNUNET_NO);
740 GNUNET_SCHEDULER_add_delayed(blocked_for, 757 ve->revalidation_task =
741 &revalidate_address, 758 GNUNET_SCHEDULER_add_delayed (blocked_for,
742 ve); 759 &revalidate_address,
743 ve->next_validation = GNUNET_TIME_relative_to_absolute(blocked_for); 760 ve);
744 return; 761 ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for);
745 } 762 return;
763 }
746 764
747 /* We are good to go; remember to not go again for `canonical_delay` time; 765 /* We are good to go; remember to not go again for `canonical_delay` time;
748 add up to `canonical_delay` to randomize start time */ 766 add up to `canonical_delay` to randomize start time */
749 ve->revalidation_block = GNUNET_TIME_relative_to_absolute(canonical_delay); 767 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay);
750 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */ 768 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */
751 rdelay = 769 rdelay =
752 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 770 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
753 canonical_delay.rel_value_us); 771 canonical_delay.rel_value_us);
754 772
755 delay = GNUNET_TIME_relative_add(canonical_delay, 773 delay = GNUNET_TIME_relative_add (canonical_delay,
756 GNUNET_TIME_relative_multiply 774 GNUNET_TIME_relative_multiply
757 (GNUNET_TIME_UNIT_MICROSECONDS, 775 (GNUNET_TIME_UNIT_MICROSECONDS,
758 rdelay)); 776 rdelay));
759 777
760 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
761 "Validating now, next scheduled for %s, now validating address `%s'\n", 779 "Validating now, next scheduled for %s, now validating address `%s'\n",
762 GNUNET_STRINGS_relative_time_to_string(blocked_for, 780 GNUNET_STRINGS_relative_time_to_string (blocked_for,
763 GNUNET_YES), 781 GNUNET_YES),
764 GST_plugins_a2s(ve->address)); 782 GST_plugins_a2s (ve->address));
765 ve->revalidation_task = 783 ve->revalidation_task =
766 GNUNET_SCHEDULER_add_delayed(delay, 784 GNUNET_SCHEDULER_add_delayed (delay,
767 &revalidate_address, 785 &revalidate_address,
768 ve); 786 ve);
769 ve->next_validation = GNUNET_TIME_relative_to_absolute(delay); 787 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
770 788
771 /* start PINGing by checking blacklist */ 789 /* start PINGing by checking blacklist */
772 GNUNET_STATISTICS_update(GST_stats, 790 GNUNET_STATISTICS_update (GST_stats,
773 gettext_noop("# address revalidations started"), 1, 791 gettext_noop ("# address revalidations started"), 1,
774 GNUNET_NO); 792 GNUNET_NO);
775 if (NULL != ve->bc) 793 if (NULL != ve->bc)
776 { 794 {
777 GST_blacklist_test_cancel(ve->bc); 795 GST_blacklist_test_cancel (ve->bc);
778 ve->bc = NULL; 796 ve->bc = NULL;
779 } 797 }
780 bc = GST_blacklist_test_allowed(&ve->address->peer, 798 bc = GST_blacklist_test_allowed (&ve->address->peer,
781 ve->address->transport_name, 799 ve->address->transport_name,
782 &transmit_ping_if_allowed, 800 &transmit_ping_if_allowed,
783 ve, 801 ve,
784 NULL, 802 NULL,
785 NULL); 803 NULL);
786 if (NULL != bc) 804 if (NULL != bc)
787 { 805 {
788 /* If transmit_ping_if_allowed was already called it may have freed ve, 806 /* If transmit_ping_if_allowed was already called it may have freed ve,
789 * so only set ve->bc if it has not been called. 807 * so only set ve->bc if it has not been called.
790 */ 808 */
791 ve->bc = bc; 809 ve->bc = bc;
792 } 810 }
793} 811}
794 812
795 813
@@ -803,41 +821,41 @@ revalidate_address(void *cls)
803 * if we don't have an existing entry and no public key was given 821 * if we don't have an existing entry and no public key was given
804 */ 822 */
805static struct ValidationEntry * 823static struct ValidationEntry *
806find_validation_entry(const struct GNUNET_HELLO_Address *address) 824find_validation_entry (const struct GNUNET_HELLO_Address *address)
807{ 825{
808 struct ValidationEntryMatchContext vemc; 826 struct ValidationEntryMatchContext vemc;
809 struct ValidationEntry *ve; 827 struct ValidationEntry *ve;
810 828
811 vemc.ve = NULL; 829 vemc.ve = NULL;
812 vemc.address = address; 830 vemc.address = address;
813 GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, 831 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
814 &address->peer, 832 &address->peer,
815 &validation_entry_match, &vemc); 833 &validation_entry_match, &vemc);
816 if (NULL != (ve = vemc.ve)) 834 if (NULL != (ve = vemc.ve))
817 return ve; 835 return ve;
818 GNUNET_assert(GNUNET_NO == 836 GNUNET_assert (GNUNET_NO ==
819 GST_ats_is_known_no_session(address)); 837 GST_ats_is_known_no_session (address));
820 ve = GNUNET_new(struct ValidationEntry); 838 ve = GNUNET_new (struct ValidationEntry);
821 ve->in_use = GNUNET_SYSERR; /* not defined */ 839 ve->in_use = GNUNET_SYSERR; /* not defined */
822 ve->address = GNUNET_HELLO_address_copy(address); 840 ve->address = GNUNET_HELLO_address_copy (address);
823 ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS; 841 ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
824 memset(&ve->pong_sig_cache, 842 memset (&ve->pong_sig_cache,
825 '\0', 843 '\0',
826 sizeof(struct GNUNET_CRYPTO_EddsaSignature)); 844 sizeof(struct GNUNET_CRYPTO_EddsaSignature));
827 ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; 845 ve->latency = GNUNET_TIME_UNIT_FOREVER_REL;
828 ve->challenge = 846 ve->challenge =
829 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 847 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
830 ve->timeout_task = 848 ve->timeout_task =
831 GNUNET_SCHEDULER_add_delayed(UNVALIDATED_PING_KEEPALIVE, 849 GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE,
832 &timeout_hello_validation, 850 &timeout_hello_validation,
833 ve); 851 ve);
834 GNUNET_CONTAINER_multipeermap_put(validation_map, 852 GNUNET_CONTAINER_multipeermap_put (validation_map,
835 &address->peer, 853 &address->peer,
836 ve, 854 ve,
837 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 855 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
838 publish_ve_stat_update(); 856 publish_ve_stat_update ();
839 validation_entry_changed(ve, 857 validation_entry_changed (ve,
840 GNUNET_TRANSPORT_VS_NEW); 858 GNUNET_TRANSPORT_VS_NEW);
841 return ve; 859 return ve;
842} 860}
843 861
@@ -854,9 +872,9 @@ find_validation_entry(const struct GNUNET_HELLO_Address *address)
854 * #GNUNET_SYSERR would abort iteration (but we always iterate all) 872 * #GNUNET_SYSERR would abort iteration (but we always iterate all)
855 */ 873 */
856static int 874static int
857add_valid_address(void *cls, 875add_valid_address (void *cls,
858 const struct GNUNET_HELLO_Address *address, 876 const struct GNUNET_HELLO_Address *address,
859 struct GNUNET_TIME_Absolute expiration) 877 struct GNUNET_TIME_Absolute expiration)
860{ 878{
861 const struct GNUNET_HELLO_Message *hello = cls; 879 const struct GNUNET_HELLO_Message *hello = cls;
862 struct ValidationEntry *ve; 880 struct ValidationEntry *ve;
@@ -864,60 +882,60 @@ add_valid_address(void *cls,
864 struct GNUNET_ATS_Properties prop; 882 struct GNUNET_ATS_Properties prop;
865 struct GNUNET_TRANSPORT_PluginFunctions *papi; 883 struct GNUNET_TRANSPORT_PluginFunctions *papi;
866 884
867 if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) 885 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
868 return GNUNET_OK; /* expired */ 886 return GNUNET_OK; /* expired */
869 if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid)) 887 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
870 { 888 {
871 GNUNET_break(0); 889 GNUNET_break (0);
872 return GNUNET_OK; /* invalid HELLO !? */ 890 return GNUNET_OK; /* invalid HELLO !? */
873 } 891 }
874 if (NULL == (papi = GST_plugins_find(address->transport_name))) 892 if (NULL == (papi = GST_plugins_find (address->transport_name)))
875 { 893 {
876 /* might have been valid in the past, but we don't have that 894 /* might have been valid in the past, but we don't have that
877 plugin loaded right now */ 895 plugin loaded right now */
878 return GNUNET_OK; 896 return GNUNET_OK;
879 } 897 }
880 if (NULL == 898 if (NULL ==
881 papi->address_to_string(papi->cls, 899 papi->address_to_string (papi->cls,
882 address->address, 900 address->address,
883 address->address_length)) 901 address->address_length))
884 { 902 {
885 /* Why do we try to add an ill-formed address? */ 903 /* Why do we try to add an ill-formed address? */
886 GNUNET_break(0); 904 GNUNET_break (0);
887 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 905 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
888 "Address with %u bytes for plugin %s and peer %s is malformed\n", 906 "Address with %u bytes for plugin %s and peer %s is malformed\n",
889 (unsigned int)address->address_length, 907 (unsigned int) address->address_length,
890 address->transport_name, 908 address->transport_name,
891 GNUNET_i2s(&pid)); 909 GNUNET_i2s (&pid));
892 return GNUNET_OK; 910 return GNUNET_OK;
893 } 911 }
894 912
895 ve = find_validation_entry(address); 913 ve = find_validation_entry (address);
896 ve->network = papi->get_network_for_address(papi->cls, 914 ve->network = papi->get_network_for_address (papi->cls,
897 address); 915 address);
898 GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network); 916 GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network);
899 ve->valid_until = GNUNET_TIME_absolute_max(ve->valid_until, 917 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until,
900 expiration); 918 expiration);
901 if (NULL == ve->revalidation_task) 919 if (NULL == ve->revalidation_task)
902 { 920 {
903 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 921 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
904 "Starting revalidations for valid address `%s'\n", 922 "Starting revalidations for valid address `%s'\n",
905 GST_plugins_a2s(ve->address)); 923 GST_plugins_a2s (ve->address));
906 ve->next_validation = GNUNET_TIME_absolute_get(); 924 ve->next_validation = GNUNET_TIME_absolute_get ();
907 ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, ve); 925 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
908 } 926 }
909 validation_entry_changed(ve, 927 validation_entry_changed (ve,
910 GNUNET_TRANSPORT_VS_UPDATE); 928 GNUNET_TRANSPORT_VS_UPDATE);
911 memset(&prop, 0, sizeof(prop)); 929 memset (&prop, 0, sizeof(prop));
912 prop.scope = ve->network; 930 prop.scope = ve->network;
913 prop.delay = GNUNET_TIME_relative_divide(ve->latency, 2); 931 prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2);
914 if (GNUNET_YES != ve->known_to_ats) 932 if (GNUNET_YES != ve->known_to_ats)
915 { 933 {
916 ve->known_to_ats = GNUNET_YES; 934 ve->known_to_ats = GNUNET_YES;
917 GST_ats_add_address(address, &prop); 935 GST_ats_add_address (address, &prop);
918 GNUNET_assert(GNUNET_YES == 936 GNUNET_assert (GNUNET_YES ==
919 GST_ats_is_known_no_session(ve->address)); 937 GST_ats_is_known_no_session (ve->address));
920 } 938 }
921 return GNUNET_OK; 939 return GNUNET_OK;
922} 940}
923 941
@@ -932,28 +950,28 @@ add_valid_address(void *cls,
932 * @param err_msg error message 950 * @param err_msg error message
933 */ 951 */
934static void 952static void
935process_peerinfo_hello(void *cls, 953process_peerinfo_hello (void *cls,
936 const struct GNUNET_PeerIdentity *peer, 954 const struct GNUNET_PeerIdentity *peer,
937 const struct GNUNET_HELLO_Message *hello, 955 const struct GNUNET_HELLO_Message *hello,
938 const char *err_msg) 956 const char *err_msg)
939{ 957{
940 GNUNET_assert(NULL != peer); 958 GNUNET_assert (NULL != peer);
941 if (NULL == hello) 959 if (NULL == hello)
942 return; 960 return;
943 if (0 == memcmp(&GST_my_identity, 961 if (0 == memcmp (&GST_my_identity,
944 peer, 962 peer,
945 sizeof(struct GNUNET_PeerIdentity))) 963 sizeof(struct GNUNET_PeerIdentity)))
946 { 964 {
947 /* Peerinfo returned own identity, skip validation */ 965 /* Peerinfo returned own identity, skip validation */
948 return; 966 return;
949 } 967 }
950 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 968 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
951 "Handling HELLO for peer `%s'\n", 969 "Handling HELLO for peer `%s'\n",
952 GNUNET_i2s(peer)); 970 GNUNET_i2s (peer));
953 GNUNET_assert(NULL == 971 GNUNET_assert (NULL ==
954 GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, 972 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
955 &add_valid_address, 973 &add_valid_address,
956 (void *)hello)); 974 (void *) hello));
957} 975}
958 976
959 977
@@ -963,7 +981,7 @@ process_peerinfo_hello(void *cls,
963 * @param max_fds maximum number of fds to use 981 * @param max_fds maximum number of fds to use
964 */ 982 */
965void 983void
966GST_validation_start(unsigned int max_fds) 984GST_validation_start (unsigned int max_fds)
967{ 985{
968 /** 986 /**
969 * Initialization for validation throttling 987 * Initialization for validation throttling
@@ -977,23 +995,24 @@ GST_validation_start(unsigned int max_fds)
977 * (300 sec / ~150 == ~2 sec.) between two validations 995 * (300 sec / ~150 == ~2 sec.) between two validations
978 */ 996 */
979 997
980 validation_next = GNUNET_TIME_absolute_get(); 998 validation_next = GNUNET_TIME_absolute_get ();
981 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); 999 validation_delay.rel_value_us =
1000 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
982 validations_fast_start_threshold = (max_fds / 2); 1001 validations_fast_start_threshold = (max_fds / 2);
983 validations_running = 0; 1002 validations_running = 0;
984 GNUNET_STATISTICS_set(GST_stats, 1003 GNUNET_STATISTICS_set (GST_stats,
985 gettext_noop("# validations running"), 1004 gettext_noop ("# validations running"),
986 validations_running, 1005 validations_running,
987 GNUNET_NO); 1006 GNUNET_NO);
988 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
989 "Validation uses a fast start threshold of %u connections and a delay of %s\n", 1008 "Validation uses a fast start threshold of %u connections and a delay of %s\n",
990 validations_fast_start_threshold, 1009 validations_fast_start_threshold,
991 GNUNET_STRINGS_relative_time_to_string(validation_delay, 1010 GNUNET_STRINGS_relative_time_to_string (validation_delay,
992 GNUNET_YES)); 1011 GNUNET_YES));
993 validation_map = GNUNET_CONTAINER_multipeermap_create(VALIDATION_MAP_SIZE, 1012 validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE,
994 GNUNET_NO); 1013 GNUNET_NO);
995 pnc = GNUNET_PEERINFO_notify(GST_cfg, GNUNET_YES, 1014 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES,
996 &process_peerinfo_hello, NULL); 1015 &process_peerinfo_hello, NULL);
997} 1016}
998 1017
999 1018
@@ -1001,14 +1020,14 @@ GST_validation_start(unsigned int max_fds)
1001 * Stop the validation subsystem. 1020 * Stop the validation subsystem.
1002 */ 1021 */
1003void 1022void
1004GST_validation_stop() 1023GST_validation_stop ()
1005{ 1024{
1006 GNUNET_CONTAINER_multipeermap_iterate(validation_map, 1025 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
1007 &cleanup_validation_entry, 1026 &cleanup_validation_entry,
1008 NULL); 1027 NULL);
1009 GNUNET_CONTAINER_multipeermap_destroy(validation_map); 1028 GNUNET_CONTAINER_multipeermap_destroy (validation_map);
1010 validation_map = NULL; 1029 validation_map = NULL;
1011 GNUNET_PEERINFO_notify_cancel(pnc); 1030 GNUNET_PEERINFO_notify_cancel (pnc);
1012} 1031}
1013 1032
1014 1033
@@ -1024,41 +1043,41 @@ GST_validation_stop()
1024 * @param address target address 1043 * @param address target address
1025 */ 1044 */
1026static void 1045static void
1027multicast_pong(void *cls, 1046multicast_pong (void *cls,
1028 struct GNUNET_TIME_Absolute valid_until, 1047 struct GNUNET_TIME_Absolute valid_until,
1029 struct GNUNET_TIME_Absolute validation_block, 1048 struct GNUNET_TIME_Absolute validation_block,
1030 const struct GNUNET_HELLO_Address *address) 1049 const struct GNUNET_HELLO_Address *address)
1031{ 1050{
1032 struct TransportPongMessage *pong = cls; 1051 struct TransportPongMessage *pong = cls;
1033 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1052 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1034 struct GNUNET_ATS_Session *session; 1053 struct GNUNET_ATS_Session *session;
1035 1054
1036 papi = GST_plugins_find(address->transport_name); 1055 papi = GST_plugins_find (address->transport_name);
1037 if (NULL == papi) 1056 if (NULL == papi)
1038 { 1057 {
1039 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1040 "Plugin %s not supported, cannot send PONG\n", 1059 "Plugin %s not supported, cannot send PONG\n",
1041 address->transport_name); 1060 address->transport_name);
1042 return; 1061 return;
1043 } 1062 }
1044 GNUNET_assert(NULL != papi->send); 1063 GNUNET_assert (NULL != papi->send);
1045 GNUNET_assert(NULL != papi->get_session); 1064 GNUNET_assert (NULL != papi->get_session);
1046 session = papi->get_session(papi->cls, address); 1065 session = papi->get_session (papi->cls, address);
1047 if (NULL == session) 1066 if (NULL == session)
1048 { 1067 {
1049 GNUNET_break(0); 1068 GNUNET_break (0);
1050 return; 1069 return;
1051 } 1070 }
1052 GST_ats_new_session(address, session); 1071 GST_ats_new_session (address, session);
1053 papi->send(papi->cls, session, 1072 papi->send (papi->cls, session,
1054 (const char *)pong, 1073 (const char *) pong,
1055 ntohs(pong->header.size), 1074 ntohs (pong->header.size),
1056 PONG_PRIORITY, 1075 PONG_PRIORITY,
1057 ACCEPTABLE_PING_DELAY, 1076 ACCEPTABLE_PING_DELAY,
1058 NULL, NULL); 1077 NULL, NULL);
1059 GST_neighbours_notify_data_sent(address, 1078 GST_neighbours_notify_data_sent (address,
1060 session, 1079 session,
1061 pong->header.size); 1080 pong->header.size);
1062} 1081}
1063 1082
1064 1083
@@ -1072,10 +1091,10 @@ multicast_pong(void *cls,
1072 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 1091 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1073 */ 1092 */
1074int 1093int
1075GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender, 1094GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1076 const struct GNUNET_MessageHeader *hdr, 1095 const struct GNUNET_MessageHeader *hdr,
1077 const struct GNUNET_HELLO_Address *sender_address, 1096 const struct GNUNET_HELLO_Address *sender_address,
1078 struct GNUNET_ATS_Session *session) 1097 struct GNUNET_ATS_Session *session)
1079{ 1098{
1080 const struct TransportPingMessage *ping; 1099 const struct TransportPingMessage *ping;
1081 struct TransportPongMessage *pong; 1100 struct TransportPongMessage *pong;
@@ -1092,32 +1111,33 @@ GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender,
1092 struct GNUNET_HELLO_Address address; 1111 struct GNUNET_HELLO_Address address;
1093 1112
1094 if (0 == 1113 if (0 ==
1095 memcmp(&GST_my_identity, 1114 memcmp (&GST_my_identity,
1096 sender, 1115 sender,
1097 sizeof(struct GNUNET_PeerIdentity))) 1116 sizeof(struct GNUNET_PeerIdentity)))
1098 return GNUNET_OK; /* our own, ignore! */ 1117 return GNUNET_OK; /* our own, ignore! */
1099 if (ntohs(hdr->size) < sizeof(struct TransportPingMessage)) 1118 if (ntohs (hdr->size) < sizeof(struct TransportPingMessage))
1100 { 1119 {
1101 GNUNET_break_op(0); 1120 GNUNET_break_op (0);
1102 return GNUNET_SYSERR; 1121 return GNUNET_SYSERR;
1103 } 1122 }
1104 ping = (const struct TransportPingMessage *)hdr; 1123 ping = (const struct TransportPingMessage *) hdr;
1105 if (0 != 1124 if (0 !=
1106 memcmp(&ping->target, 1125 memcmp (&ping->target,
1107 &GST_my_identity, 1126 &GST_my_identity,
1108 sizeof(struct GNUNET_PeerIdentity))) 1127 sizeof(struct GNUNET_PeerIdentity)))
1109 { 1128 {
1110 GNUNET_STATISTICS_update(GST_stats, 1129 GNUNET_STATISTICS_update (GST_stats,
1111 gettext_noop 1130 gettext_noop
1112 ("# PING message for different peer received"), 1, 1131 ("# PING message for different peer received"),
1113 GNUNET_NO); 1132 1,
1114 return GNUNET_SYSERR; 1133 GNUNET_NO);
1115 } 1134 return GNUNET_SYSERR;
1116 GNUNET_STATISTICS_update(GST_stats, 1135 }
1117 gettext_noop("# PING messages received"), 1, 1136 GNUNET_STATISTICS_update (GST_stats,
1118 GNUNET_NO); 1137 gettext_noop ("# PING messages received"), 1,
1119 addr = (const char *)&ping[1]; 1138 GNUNET_NO);
1120 len_address = ntohs(hdr->size) - sizeof(struct TransportPingMessage); 1139 addr = (const char *) &ping[1];
1140 len_address = ntohs (hdr->size) - sizeof(struct TransportPingMessage);
1121 /* peer wants to confirm that this is one of our addresses, this is what is 1141 /* peer wants to confirm that this is one of our addresses, this is what is
1122 * used for address validation */ 1142 * used for address validation */
1123 1143
@@ -1125,198 +1145,207 @@ GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender,
1125 sig_cache_exp = NULL; 1145 sig_cache_exp = NULL;
1126 papi = NULL; 1146 papi = NULL;
1127 if (len_address > 0) 1147 if (len_address > 0)
1148 {
1149 addrend = memchr (addr, '\0', len_address);
1150 if (NULL == addrend)
1128 { 1151 {
1129 addrend = memchr(addr, '\0', len_address); 1152 GNUNET_break_op (0);
1130 if (NULL == addrend) 1153 return GNUNET_SYSERR;
1131 {
1132 GNUNET_break_op(0);
1133 return GNUNET_SYSERR;
1134 }
1135 addrend++;
1136 len_plugin = strlen(addr) + 1;
1137 len_address -= len_plugin;
1138 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1139 address.address = addrend;
1140 address.address_length = len_address;
1141 address.transport_name = addr;
1142 address.peer = GST_my_identity;
1143
1144 if (NULL == address.transport_name)
1145 {
1146 GNUNET_break(0);
1147 }
1148
1149 if (0 != strstr(address.transport_name, "_client"))
1150 {
1151 plugin_name = GNUNET_strdup(address.transport_name);
1152 pos = strstr(plugin_name, "_client");
1153 GNUNET_assert(NULL != pos);
1154 GNUNET_snprintf(pos, strlen("_server") + 1, "%s", "_server");
1155 }
1156 else
1157 plugin_name = GNUNET_strdup(address.transport_name);
1158
1159 if (NULL == (papi = GST_plugins_find(plugin_name)))
1160 {
1161 /* we don't have the plugin for this address */
1162 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1163 _("Plugin `%s' not available, cannot confirm having this address\n"),
1164 plugin_name);
1165 GNUNET_free(plugin_name);
1166 return GNUNET_SYSERR;
1167 }
1168 GNUNET_free(plugin_name);
1169 if (GNUNET_OK !=
1170 papi->check_address(papi->cls,
1171 addrend,
1172 len_address))
1173 {
1174 GNUNET_STATISTICS_update(GST_stats,
1175 gettext_noop
1176 ("# failed address checks during validation"), 1,
1177 GNUNET_NO);
1178 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1179 _("Address `%s' is not one of my addresses, not confirming PING\n"),
1180 GST_plugins_a2s(&address));
1181 return GNUNET_SYSERR;
1182 }
1183 else
1184 {
1185 GNUNET_STATISTICS_update(GST_stats,
1186 gettext_noop
1187 ("# successful address checks during validation"), 1,
1188 GNUNET_NO);
1189 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1190 "Address `%s' is one of my addresses, confirming PING\n",
1191 GST_plugins_a2s(&address));
1192 }
1193
1194 if (GNUNET_YES !=
1195 GST_hello_test_address(&address,
1196 &sig_cache,
1197 &sig_cache_exp))
1198 {
1199 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1200 _("Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"),
1201 GNUNET_i2s(sender),
1202 GST_plugins_a2s(&address));
1203 return GNUNET_SYSERR;
1204 }
1205 } 1154 }
1206 else 1155 addrend++;
1156 len_plugin = strlen (addr) + 1;
1157 len_address -= len_plugin;
1158 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1159 address.address = addrend;
1160 address.address_length = len_address;
1161 address.transport_name = addr;
1162 address.peer = GST_my_identity;
1163
1164 if (NULL == address.transport_name)
1207 { 1165 {
1208 addrend = NULL; /* make gcc happy */ 1166 GNUNET_break (0);
1209 len_plugin = 0; 1167 }
1210 static struct GNUNET_CRYPTO_EddsaSignature no_address_signature;
1211 static struct GNUNET_TIME_Absolute no_address_signature_expiration;
1212 1168
1213 sig_cache = &no_address_signature; 1169 if (0 != strstr (address.transport_name, "_client"))
1214 sig_cache_exp = &no_address_signature_expiration; 1170 {
1171 plugin_name = GNUNET_strdup (address.transport_name);
1172 pos = strstr (plugin_name, "_client");
1173 GNUNET_assert (NULL != pos);
1174 GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server");
1215 } 1175 }
1176 else
1177 plugin_name = GNUNET_strdup (address.transport_name);
1216 1178
1217 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1179 if (NULL == (papi = GST_plugins_find (plugin_name)))
1218 "I am `%s', sending PONG to peer `%s'\n", 1180 {
1219 GNUNET_i2s_full(&GST_my_identity), 1181 /* we don't have the plugin for this address */
1220 GNUNET_i2s(sender)); 1182 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1183 _ (
1184 "Plugin `%s' not available, cannot confirm having this address\n"),
1185 plugin_name);
1186 GNUNET_free (plugin_name);
1187 return GNUNET_SYSERR;
1188 }
1189 GNUNET_free (plugin_name);
1190 if (GNUNET_OK !=
1191 papi->check_address (papi->cls,
1192 addrend,
1193 len_address))
1194 {
1195 GNUNET_STATISTICS_update (GST_stats,
1196 gettext_noop
1197 ("# failed address checks during validation"),
1198 1,
1199 GNUNET_NO);
1200 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1201 _ (
1202 "Address `%s' is not one of my addresses, not confirming PING\n"),
1203 GST_plugins_a2s (&address));
1204 return GNUNET_SYSERR;
1205 }
1206 else
1207 {
1208 GNUNET_STATISTICS_update (GST_stats,
1209 gettext_noop
1210 (
1211 "# successful address checks during validation"),
1212 1,
1213 GNUNET_NO);
1214 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1215 "Address `%s' is one of my addresses, confirming PING\n",
1216 GST_plugins_a2s (&address));
1217 }
1218
1219 if (GNUNET_YES !=
1220 GST_hello_test_address (&address,
1221 &sig_cache,
1222 &sig_cache_exp))
1223 {
1224 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1225 _ (
1226 "Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"),
1227 GNUNET_i2s (sender),
1228 GST_plugins_a2s (&address));
1229 return GNUNET_SYSERR;
1230 }
1231 }
1232 else
1233 {
1234 addrend = NULL; /* make gcc happy */
1235 len_plugin = 0;
1236 static struct GNUNET_CRYPTO_EddsaSignature no_address_signature;
1237 static struct GNUNET_TIME_Absolute no_address_signature_expiration;
1238
1239 sig_cache = &no_address_signature;
1240 sig_cache_exp = &no_address_signature_expiration;
1241 }
1242
1243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1244 "I am `%s', sending PONG to peer `%s'\n",
1245 GNUNET_i2s_full (&GST_my_identity),
1246 GNUNET_i2s (sender));
1221 1247
1222 /* message with structure: 1248 /* message with structure:
1223 * [TransportPongMessage][Transport name][Address] */ 1249 * [TransportPongMessage][Transport name][Address] */
1224 1250
1225 pong = GNUNET_malloc(sizeof(struct TransportPongMessage) + len_address + len_plugin); 1251 pong = GNUNET_malloc (sizeof(struct TransportPongMessage) + len_address
1252 + len_plugin);
1226 pong->header.size = 1253 pong->header.size =
1227 htons(sizeof(struct TransportPongMessage) + len_address + len_plugin); 1254 htons (sizeof(struct TransportPongMessage) + len_address + len_plugin);
1228 pong->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); 1255 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
1229 pong->purpose.size = 1256 pong->purpose.size =
1230 htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + 1257 htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
1231 sizeof(uint32_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO) + 1258 + sizeof(uint32_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO)
1232 len_address + len_plugin); 1259 + len_address + len_plugin);
1233 pong->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); 1260 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
1234 GNUNET_memcpy(&pong->challenge, &ping->challenge, sizeof(ping->challenge)); 1261 GNUNET_memcpy (&pong->challenge, &ping->challenge, sizeof(ping->challenge));
1235 pong->addrlen = htonl(len_address + len_plugin); 1262 pong->addrlen = htonl (len_address + len_plugin);
1236 GNUNET_memcpy(&pong[1], addr, len_plugin); /* Copy transport plugin */ 1263 GNUNET_memcpy (&pong[1], addr, len_plugin); /* Copy transport plugin */
1237 if (len_address > 0) 1264 if (len_address > 0)
1238 { 1265 {
1239 GNUNET_assert(NULL != addrend); 1266 GNUNET_assert (NULL != addrend);
1240 GNUNET_memcpy(&((char *)&pong[1])[len_plugin], addrend, len_address); 1267 GNUNET_memcpy (&((char *) &pong[1])[len_plugin], addrend, len_address);
1241 } 1268 }
1242 if (GNUNET_TIME_absolute_get_remaining(*sig_cache_exp).rel_value_us < 1269 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value_us <
1243 PONG_SIGNATURE_LIFETIME.rel_value_us / 4) 1270 PONG_SIGNATURE_LIFETIME.rel_value_us / 4)
1271 {
1272 /* create / update cached sig */
1273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1274 "Creating PONG signature to indicate ownership.\n");
1275 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
1276 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
1277 if (GNUNET_OK !=
1278 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, &pong->purpose,
1279 sig_cache))
1244 { 1280 {
1245 /* create / update cached sig */ 1281 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1282 _ ("Failed to create PONG signature for peer `%s'\n"),
1247 "Creating PONG signature to indicate ownership.\n"); 1283 GNUNET_i2s (sender));
1248 *sig_cache_exp = GNUNET_TIME_relative_to_absolute(PONG_SIGNATURE_LIFETIME);
1249 pong->expiration = GNUNET_TIME_absolute_hton(*sig_cache_exp);
1250 if (GNUNET_OK !=
1251 GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, &pong->purpose,
1252 sig_cache))
1253 {
1254 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1255 _("Failed to create PONG signature for peer `%s'\n"), GNUNET_i2s(sender));
1256 }
1257 } 1284 }
1285 }
1258 else 1286 else
1259 { 1287 {
1260 pong->expiration = GNUNET_TIME_absolute_hton(*sig_cache_exp); 1288 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
1261 } 1289 }
1262 pong->signature = *sig_cache; 1290 pong->signature = *sig_cache;
1263 1291
1264 GNUNET_assert(NULL != sender_address); 1292 GNUNET_assert (NULL != sender_address);
1265 1293
1266 /* first see if the session we got this PING from can be used to transmit 1294 /* first see if the session we got this PING from can be used to transmit
1267 * a response reliably */ 1295 * a response reliably */
1268 if (NULL == papi) 1296 if (NULL == papi)
1297 {
1298 ret = -1;
1299 }
1300 else
1301 {
1302 GNUNET_assert (NULL != papi->send);
1303 GNUNET_assert (NULL != papi->get_session);
1304 if (NULL == session)
1269 { 1305 {
1270 ret = -1; 1306 session = papi->get_session (papi->cls, sender_address);
1271 } 1307 }
1272 else 1308 if (NULL == session)
1273 { 1309 {
1274 GNUNET_assert(NULL != papi->send); 1310 GNUNET_break (0);
1275 GNUNET_assert(NULL != papi->get_session); 1311 ret = -1;
1276 if (NULL == session)
1277 {
1278 session = papi->get_session(papi->cls, sender_address);
1279 }
1280 if (NULL == session)
1281 {
1282 GNUNET_break(0);
1283 ret = -1;
1284 }
1285 else
1286 {
1287 ret = papi->send(papi->cls, session,
1288 (const char *)pong,
1289 ntohs(pong->header.size),
1290 PONG_PRIORITY, ACCEPTABLE_PING_DELAY,
1291 NULL, NULL);
1292 if (-1 != ret)
1293 GST_neighbours_notify_data_sent(sender_address,
1294 session,
1295 pong->header.size);
1296 }
1297 } 1312 }
1298 if (-1 != ret) 1313 else
1299 { 1314 {
1300 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1315 ret = papi->send (papi->cls, session,
1301 "Transmitted PONG to `%s' via reliable mechanism\n", 1316 (const char *) pong,
1302 GNUNET_i2s(sender)); 1317 ntohs (pong->header.size),
1303 /* done! */ 1318 PONG_PRIORITY, ACCEPTABLE_PING_DELAY,
1304 GNUNET_STATISTICS_update(GST_stats, 1319 NULL, NULL);
1305 gettext_noop 1320 if (-1 != ret)
1306 ("# PONGs unicast via reliable transport"), 1, 1321 GST_neighbours_notify_data_sent (sender_address,
1307 GNUNET_NO); 1322 session,
1308 GNUNET_free(pong); 1323 pong->header.size);
1309 return GNUNET_OK;
1310 } 1324 }
1325 }
1326 if (-1 != ret)
1327 {
1328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1329 "Transmitted PONG to `%s' via reliable mechanism\n",
1330 GNUNET_i2s (sender));
1331 /* done! */
1332 GNUNET_STATISTICS_update (GST_stats,
1333 gettext_noop
1334 ("# PONGs unicast via reliable transport"), 1,
1335 GNUNET_NO);
1336 GNUNET_free (pong);
1337 return GNUNET_OK;
1338 }
1311 1339
1312 /* no reliable method found, try transmission via all known addresses */ 1340 /* no reliable method found, try transmission via all known addresses */
1313 GNUNET_STATISTICS_update(GST_stats, 1341 GNUNET_STATISTICS_update (GST_stats,
1314 gettext_noop 1342 gettext_noop
1315 ("# PONGs multicast to all available addresses"), 1, 1343 ("# PONGs multicast to all available addresses"),
1316 GNUNET_NO); 1344 1,
1317 GST_validation_get_addresses(sender, 1345 GNUNET_NO);
1318 &multicast_pong, pong); 1346 GST_validation_get_addresses (sender,
1319 GNUNET_free(pong); 1347 &multicast_pong, pong);
1348 GNUNET_free (pong);
1320 return GNUNET_OK; 1349 return GNUNET_OK;
1321} 1350}
1322 1351
@@ -1327,36 +1356,36 @@ GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender,
1327 * @param address address we should try to validate 1356 * @param address address we should try to validate
1328 */ 1357 */
1329void 1358void
1330GST_validation_handle_address(const struct GNUNET_HELLO_Address *address) 1359GST_validation_handle_address (const struct GNUNET_HELLO_Address *address)
1331{ 1360{
1332 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1361 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1333 struct ValidationEntry *ve; 1362 struct ValidationEntry *ve;
1334 1363
1335 papi = GST_plugins_find(address->transport_name); 1364 papi = GST_plugins_find (address->transport_name);
1336 if (NULL == papi) 1365 if (NULL == papi)
1337 { 1366 {
1338 /* This plugin is currently unvailable ... ignore */ 1367 /* This plugin is currently unvailable ... ignore */
1339 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1368 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1340 "No plugin available for %s\n", 1369 "No plugin available for %s\n",
1341 address->transport_name); 1370 address->transport_name);
1342 return; 1371 return;
1343 } 1372 }
1344 ve = find_validation_entry(address); 1373 ve = find_validation_entry (address);
1345 if (NULL == ve->revalidation_task) 1374 if (NULL == ve->revalidation_task)
1346 { 1375 {
1347 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1376 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1348 "Validation process started for fresh address `%s' of %s\n", 1377 "Validation process started for fresh address `%s' of %s\n",
1349 GST_plugins_a2s(ve->address), 1378 GST_plugins_a2s (ve->address),
1350 GNUNET_i2s(&ve->address->peer)); 1379 GNUNET_i2s (&ve->address->peer));
1351 ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, ve); 1380 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1352 } 1381 }
1353 else 1382 else
1354 { 1383 {
1355 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1384 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1356 "Validation already running for address `%s' of %s\n", 1385 "Validation already running for address `%s' of %s\n",
1357 GST_plugins_a2s(ve->address), 1386 GST_plugins_a2s (ve->address),
1358 GNUNET_i2s(&ve->address->peer)); 1387 GNUNET_i2s (&ve->address->peer));
1359 } 1388 }
1360} 1389}
1361 1390
1362 1391
@@ -1370,17 +1399,17 @@ GST_validation_handle_address(const struct GNUNET_HELLO_Address *address)
1370 * @return #GNUNET_OK (keep the address) 1399 * @return #GNUNET_OK (keep the address)
1371 */ 1400 */
1372static int 1401static int
1373validate_address_iterator(void *cls, 1402validate_address_iterator (void *cls,
1374 const struct GNUNET_HELLO_Address *address, 1403 const struct GNUNET_HELLO_Address *address,
1375 struct GNUNET_TIME_Absolute expiration) 1404 struct GNUNET_TIME_Absolute expiration)
1376{ 1405{
1377 if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) 1406 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
1378 { 1407 {
1379 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1380 "Skipping expired address from HELLO\n"); 1409 "Skipping expired address from HELLO\n");
1381 return GNUNET_OK; /* expired */ 1410 return GNUNET_OK; /* expired */
1382 } 1411 }
1383 GST_validation_handle_address(address); 1412 GST_validation_handle_address (address);
1384 return GNUNET_OK; 1413 return GNUNET_OK;
1385} 1414}
1386 1415
@@ -1395,19 +1424,19 @@ validate_address_iterator(void *cls,
1395 * end of the iteration. 1424 * end of the iteration.
1396 */ 1425 */
1397static ssize_t 1426static ssize_t
1398add_valid_peer_address(void *cls, 1427add_valid_peer_address (void *cls,
1399 size_t max, 1428 size_t max,
1400 void *buf) 1429 void *buf)
1401{ 1430{
1402 struct ValidationEntry *ve = cls; 1431 struct ValidationEntry *ve = cls;
1403 1432
1404 if (GNUNET_YES == ve->copied) 1433 if (GNUNET_YES == ve->copied)
1405 return GNUNET_SYSERR; /* Done */ 1434 return GNUNET_SYSERR; /* Done */
1406 ve->copied = GNUNET_YES; 1435 ve->copied = GNUNET_YES;
1407 return GNUNET_HELLO_add_address(ve->address, 1436 return GNUNET_HELLO_add_address (ve->address,
1408 ve->valid_until, 1437 ve->valid_until,
1409 buf, 1438 buf,
1410 max); 1439 max);
1411} 1440}
1412 1441
1413 1442
@@ -1420,8 +1449,8 @@ add_valid_peer_address(void *cls,
1420 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 1449 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1421 */ 1450 */
1422int 1451int
1423GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender, 1452GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1424 const struct GNUNET_MessageHeader *hdr) 1453 const struct GNUNET_MessageHeader *hdr)
1425{ 1454{
1426 const struct TransportPongMessage *pong; 1455 const struct TransportPongMessage *pong;
1427 struct ValidationEntry *ve; 1456 struct ValidationEntry *ve;
@@ -1436,197 +1465,200 @@ GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender,
1436 int do_verify; 1465 int do_verify;
1437 1466
1438 if (0 == 1467 if (0 ==
1439 memcmp(&GST_my_identity, 1468 memcmp (&GST_my_identity,
1440 sender, 1469 sender,
1441 sizeof(struct GNUNET_PeerIdentity))) 1470 sizeof(struct GNUNET_PeerIdentity)))
1442 return GNUNET_OK; /* our own, ignore! */ 1471 return GNUNET_OK; /* our own, ignore! */
1443 1472
1444 if (ntohs(hdr->size) < sizeof(struct TransportPongMessage)) 1473 if (ntohs (hdr->size) < sizeof(struct TransportPongMessage))
1445 { 1474 {
1446 GNUNET_break_op(0); 1475 GNUNET_break_op (0);
1447 return GNUNET_SYSERR; 1476 return GNUNET_SYSERR;
1448 } 1477 }
1449 GNUNET_STATISTICS_update(GST_stats, 1478 GNUNET_STATISTICS_update (GST_stats,
1450 gettext_noop("# PONG messages received"), 1, 1479 gettext_noop ("# PONG messages received"), 1,
1451 GNUNET_NO); 1480 GNUNET_NO);
1452 1481
1453 /* message with structure: 1482 /* message with structure:
1454 * [TransportPongMessage][Transport name][Address] */ 1483 * [TransportPongMessage][Transport name][Address] */
1455 1484
1456 pong = (const struct TransportPongMessage *)hdr; 1485 pong = (const struct TransportPongMessage *) hdr;
1457 tname = (const char *)&pong[1]; 1486 tname = (const char *) &pong[1];
1458 size = ntohs(hdr->size) - sizeof(struct TransportPongMessage); 1487 size = ntohs (hdr->size) - sizeof(struct TransportPongMessage);
1459 addr = memchr(tname, '\0', size); 1488 addr = memchr (tname, '\0', size);
1460 if (NULL == addr) 1489 if (NULL == addr)
1461 { 1490 {
1462 GNUNET_break_op(0); 1491 GNUNET_break_op (0);
1463 return GNUNET_SYSERR; 1492 return GNUNET_SYSERR;
1464 } 1493 }
1465 addr++; 1494 addr++;
1466 slen = strlen(tname) + 1; 1495 slen = strlen (tname) + 1;
1467 addrlen = size - slen; 1496 addrlen = size - slen;
1468 1497
1469 if (NULL == GST_plugins_find(tname)) 1498 if (NULL == GST_plugins_find (tname))
1470 { 1499 {
1471 /* we got the PONG, but the transport plugin specified in it 1500 /* we got the PONG, but the transport plugin specified in it
1472 is not supported by this peer, so this cannot be a good 1501 is not supported by this peer, so this cannot be a good
1473 PONG for us. */ 1502 PONG for us. */
1474 GNUNET_break_op(0); 1503 GNUNET_break_op (0);
1475 return GNUNET_OK; 1504 return GNUNET_OK;
1476 } 1505 }
1477 1506
1478 address.peer = *sender; 1507 address.peer = *sender;
1479 address.address = addr; 1508 address.address = addr;
1480 address.address_length = addrlen; 1509 address.address_length = addrlen;
1481 address.transport_name = tname; 1510 address.transport_name = tname;
1482 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; 1511 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1483 ve = find_validation_entry(&address); 1512 ve = find_validation_entry (&address);
1484 if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong)) 1513 if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong))
1485 { 1514 {
1486 GNUNET_STATISTICS_update(GST_stats, 1515 GNUNET_STATISTICS_update (GST_stats,
1487 gettext_noop 1516 gettext_noop
1488 ("# PONGs dropped, no matching pending validation"), 1517 (
1489 1, GNUNET_NO); 1518 "# PONGs dropped, no matching pending validation"),
1490 return GNUNET_OK; 1519 1, GNUNET_NO);
1491 } 1520 return GNUNET_OK;
1521 }
1492 /* now check that PONG is well-formed */ 1522 /* now check that PONG is well-formed */
1493 if (0 != memcmp(&ve->address->peer, 1523 if (0 != memcmp (&ve->address->peer,
1494 sender, 1524 sender,
1495 sizeof(struct GNUNET_PeerIdentity))) 1525 sizeof(struct GNUNET_PeerIdentity)))
1496 { 1526 {
1497 GNUNET_break_op(0); 1527 GNUNET_break_op (0);
1498 return GNUNET_SYSERR; 1528 return GNUNET_SYSERR;
1499 } 1529 }
1500 if (0 == 1530 if (0 ==
1501 GNUNET_TIME_absolute_get_remaining 1531 GNUNET_TIME_absolute_get_remaining
1502 (GNUNET_TIME_absolute_ntoh(pong->expiration)).rel_value_us) 1532 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us)
1503 { 1533 {
1504 GNUNET_STATISTICS_update(GST_stats, 1534 GNUNET_STATISTICS_update (GST_stats,
1505 gettext_noop 1535 gettext_noop
1506 ("# PONGs dropped, signature expired"), 1, 1536 ("# PONGs dropped, signature expired"), 1,
1507 GNUNET_NO); 1537 GNUNET_NO);
1508 return GNUNET_SYSERR; 1538 return GNUNET_SYSERR;
1509 } 1539 }
1510 1540
1511 sig_res = GNUNET_SYSERR; 1541 sig_res = GNUNET_SYSERR;
1512 do_verify = GNUNET_YES; 1542 do_verify = GNUNET_YES;
1513 if (0 != GNUNET_TIME_absolute_get_remaining(ve->pong_sig_valid_until).rel_value_us) 1543 if (0 != GNUNET_TIME_absolute_get_remaining (
1544 ve->pong_sig_valid_until).rel_value_us)
1545 {
1546 /* We have a cached and valid signature for this peer,
1547 * try to compare instead of verify */
1548 if (0 == memcmp (&ve->pong_sig_cache,
1549 &pong->signature,
1550 sizeof(struct GNUNET_CRYPTO_EddsaSignature)))
1551 {
1552 /* signatures are identical, we can skip verification */
1553 sig_res = GNUNET_OK;
1554 do_verify = GNUNET_NO;
1555 }
1556 else
1514 { 1557 {
1515 /* We have a cached and valid signature for this peer, 1558 sig_res = GNUNET_SYSERR;
1516 * try to compare instead of verify */ 1559 /* signatures do not match, we have to verify */
1517 if (0 == memcmp(&ve->pong_sig_cache,
1518 &pong->signature,
1519 sizeof(struct GNUNET_CRYPTO_EddsaSignature)))
1520 {
1521 /* signatures are identical, we can skip verification */
1522 sig_res = GNUNET_OK;
1523 do_verify = GNUNET_NO;
1524 }
1525 else
1526 {
1527 sig_res = GNUNET_SYSERR;
1528 /* signatures do not match, we have to verify */
1529 }
1530 } 1560 }
1561 }
1531 1562
1532 if (GNUNET_YES == do_verify) 1563 if (GNUNET_YES == do_verify)
1564 {
1565 /* Do expensive verification */
1566 sig_res = GNUNET_CRYPTO_eddsa_verify (
1567 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1568 &pong->purpose,
1569 &pong->signature,
1570 &ve->address->peer.public_key);
1571 if (sig_res == GNUNET_SYSERR)
1533 { 1572 {
1534 /* Do expensive verification */ 1573 GNUNET_break_op (0);
1535 sig_res = GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, 1574 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1536 &pong->purpose, 1575 "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n",
1537 &pong->signature, 1576 tname,
1538 &ve->address->peer.public_key); 1577 GST_plugins_a2s (ve->address),
1539 if (sig_res == GNUNET_SYSERR) 1578 GNUNET_i2s (sender));
1540 {
1541 GNUNET_break_op(0);
1542 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1543 "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n",
1544 tname,
1545 GST_plugins_a2s(ve->address),
1546 GNUNET_i2s(sender));
1547 }
1548 } 1579 }
1580 }
1549 if (sig_res == GNUNET_SYSERR) 1581 if (sig_res == GNUNET_SYSERR)
1550 { 1582 {
1551 GNUNET_break_op(0); 1583 GNUNET_break_op (0);
1552 return GNUNET_SYSERR; 1584 return GNUNET_SYSERR;
1553 } 1585 }
1554 1586
1555 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1587 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1556 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n", 1588 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n",
1557 GNUNET_i2s(sender), 1589 GNUNET_i2s (sender),
1558 tname, 1590 tname,
1559 GST_plugins_a2s(ve->address)); 1591 GST_plugins_a2s (ve->address));
1560 GNUNET_STATISTICS_update(GST_stats, 1592 GNUNET_STATISTICS_update (GST_stats,
1561 gettext_noop("# validations succeeded"), 1593 gettext_noop ("# validations succeeded"),
1562 1, 1594 1,
1563 GNUNET_NO); 1595 GNUNET_NO);
1564 /* validity achieved, remember it! */ 1596 /* validity achieved, remember it! */
1565 ve->expecting_pong = GNUNET_NO; 1597 ve->expecting_pong = GNUNET_NO;
1566 ve->valid_until = GNUNET_TIME_relative_to_absolute(HELLO_ADDRESS_EXPIRATION); 1598 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1567 ve->pong_sig_cache = pong->signature; 1599 ve->pong_sig_cache = pong->signature;
1568 ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh(pong->expiration); 1600 ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh (pong->expiration);
1569 ve->latency = GNUNET_TIME_absolute_get_duration(ve->send_time); 1601 ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
1570 { 1602 {
1571 if (GNUNET_YES == ve->known_to_ats) 1603 if (GNUNET_YES == ve->known_to_ats)
1572 {
1573 GNUNET_assert(GNUNET_YES ==
1574 GST_ats_is_known_no_session(ve->address));
1575 GST_ats_update_delay(ve->address,
1576 GNUNET_TIME_relative_divide(ve->latency, 2));
1577 }
1578 else
1579 {
1580 struct GNUNET_ATS_Properties prop;
1581
1582 memset(&prop, 0, sizeof(prop));
1583 GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network);
1584 prop.scope = ve->network;
1585 prop.delay = GNUNET_TIME_relative_divide(ve->latency, 2);
1586 GNUNET_assert(GNUNET_NO ==
1587 GST_ats_is_known_no_session(ve->address));
1588 ve->known_to_ats = GNUNET_YES;
1589 GST_ats_add_address(ve->address, &prop);
1590 GNUNET_assert(GNUNET_YES ==
1591 GST_ats_is_known_no_session(ve->address));
1592 }
1593 }
1594 if (validations_running > 0)
1595 { 1604 {
1596 validations_running--; 1605 GNUNET_assert (GNUNET_YES ==
1597 GNUNET_STATISTICS_set(GST_stats, 1606 GST_ats_is_known_no_session (ve->address));
1598 gettext_noop("# validations running"), 1607 GST_ats_update_delay (ve->address,
1599 validations_running, 1608 GNUNET_TIME_relative_divide (ve->latency, 2));
1600 GNUNET_NO);
1601 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1602 "Validation finished, %u validation processes running\n",
1603 validations_running);
1604 } 1609 }
1605 else 1610 else
1606 { 1611 {
1607 GNUNET_break(0); 1612 struct GNUNET_ATS_Properties prop;
1613
1614 memset (&prop, 0, sizeof(prop));
1615 GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network);
1616 prop.scope = ve->network;
1617 prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2);
1618 GNUNET_assert (GNUNET_NO ==
1619 GST_ats_is_known_no_session (ve->address));
1620 ve->known_to_ats = GNUNET_YES;
1621 GST_ats_add_address (ve->address, &prop);
1622 GNUNET_assert (GNUNET_YES ==
1623 GST_ats_is_known_no_session (ve->address));
1608 } 1624 }
1625 }
1626 if (validations_running > 0)
1627 {
1628 validations_running--;
1629 GNUNET_STATISTICS_set (GST_stats,
1630 gettext_noop ("# validations running"),
1631 validations_running,
1632 GNUNET_NO);
1633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1634 "Validation finished, %u validation processes running\n",
1635 validations_running);
1636 }
1637 else
1638 {
1639 GNUNET_break (0);
1640 }
1609 1641
1610 /* Notify about new validity */ 1642 /* Notify about new validity */
1611 validation_entry_changed(ve, 1643 validation_entry_changed (ve,
1612 GNUNET_TRANSPORT_VS_UPDATE); 1644 GNUNET_TRANSPORT_VS_UPDATE);
1613 1645
1614 /* build HELLO to store in PEERINFO */ 1646 /* build HELLO to store in PEERINFO */
1615 GNUNET_STATISTICS_update(GST_stats, 1647 GNUNET_STATISTICS_update (GST_stats,
1616 gettext_noop("# HELLOs given to peerinfo"), 1648 gettext_noop ("# HELLOs given to peerinfo"),
1617 1, 1649 1,
1618 GNUNET_NO); 1650 GNUNET_NO);
1619 ve->copied = GNUNET_NO; 1651 ve->copied = GNUNET_NO;
1620 hello = GNUNET_HELLO_create(&ve->address->peer.public_key, 1652 hello = GNUNET_HELLO_create (&ve->address->peer.public_key,
1621 &add_valid_peer_address, 1653 &add_valid_peer_address,
1622 ve, 1654 ve,
1623 GNUNET_NO); 1655 GNUNET_NO);
1624 GNUNET_break(NULL != 1656 GNUNET_break (NULL !=
1625 GNUNET_PEERINFO_add_peer(GST_peerinfo, 1657 GNUNET_PEERINFO_add_peer (GST_peerinfo,
1626 hello, 1658 hello,
1627 NULL, 1659 NULL,
1628 NULL)); 1660 NULL));
1629 GNUNET_free(hello); 1661 GNUNET_free (hello);
1630 return GNUNET_OK; 1662 return GNUNET_OK;
1631} 1663}
1632 1664
@@ -1639,42 +1671,42 @@ GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender,
1639 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 1671 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1640 */ 1672 */
1641int 1673int
1642GST_validation_handle_hello(const struct GNUNET_MessageHeader *hello) 1674GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1643{ 1675{
1644 const struct GNUNET_HELLO_Message *hm = 1676 const struct GNUNET_HELLO_Message *hm =
1645 (const struct GNUNET_HELLO_Message *)hello; 1677 (const struct GNUNET_HELLO_Message *) hello;
1646 struct GNUNET_PeerIdentity pid; 1678 struct GNUNET_PeerIdentity pid;
1647 int friend; 1679 int friend;
1648 1680
1649 friend = GNUNET_HELLO_is_friend_only(hm); 1681 friend = GNUNET_HELLO_is_friend_only (hm);
1650 if (((GNUNET_YES != friend) && 1682 if (((GNUNET_YES != friend) &&
1651 (GNUNET_NO != friend)) || 1683 (GNUNET_NO != friend)) ||
1652 (GNUNET_OK != GNUNET_HELLO_get_id(hm, &pid))) 1684 (GNUNET_OK != GNUNET_HELLO_get_id (hm, &pid)))
1653 { 1685 {
1654 /* malformed HELLO */ 1686 /* malformed HELLO */
1655 GNUNET_break_op(0); 1687 GNUNET_break_op (0);
1656 return GNUNET_SYSERR; 1688 return GNUNET_SYSERR;
1657 } 1689 }
1658 if (0 == 1690 if (0 ==
1659 memcmp(&GST_my_identity, 1691 memcmp (&GST_my_identity,
1660 &pid, 1692 &pid,
1661 sizeof(struct GNUNET_PeerIdentity))) 1693 sizeof(struct GNUNET_PeerIdentity)))
1662 { 1694 {
1663 /* got our own HELLO, how boring */ 1695 /* got our own HELLO, how boring */
1664 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1665 "Validation received our own HELLO (%s), ignoring\n", 1697 "Validation received our own HELLO (%s), ignoring\n",
1666 GNUNET_i2s(&pid)); 1698 GNUNET_i2s (&pid));
1667 return GNUNET_OK; 1699 return GNUNET_OK;
1668 } 1700 }
1669 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1670 "Validation received HELLO message for peer `%s' with size %u, checking for new addresses\n", 1702 "Validation received HELLO message for peer `%s' with size %u, checking for new addresses\n",
1671 GNUNET_i2s(&pid), 1703 GNUNET_i2s (&pid),
1672 ntohs(hello->size)); 1704 ntohs (hello->size));
1673 GNUNET_assert(NULL == 1705 GNUNET_assert (NULL ==
1674 GNUNET_HELLO_iterate_addresses(hm, 1706 GNUNET_HELLO_iterate_addresses (hm,
1675 GNUNET_NO, 1707 GNUNET_NO,
1676 &validate_address_iterator, 1708 &validate_address_iterator,
1677 NULL)); 1709 NULL));
1678 return GNUNET_OK; 1710 return GNUNET_OK;
1679} 1711}
1680 1712
@@ -1682,7 +1714,8 @@ GST_validation_handle_hello(const struct GNUNET_MessageHeader *hello)
1682/** 1714/**
1683 * Closure for #iterate_addresses(). 1715 * Closure for #iterate_addresses().
1684 */ 1716 */
1685struct IteratorContext { 1717struct IteratorContext
1718{
1686 /** 1719 /**
1687 * Function to call on each address. 1720 * Function to call on each address.
1688 */ 1721 */
@@ -1704,17 +1737,17 @@ struct IteratorContext {
1704 * @return #GNUNET_OK (continue to iterate) 1737 * @return #GNUNET_OK (continue to iterate)
1705 */ 1738 */
1706static int 1739static int
1707iterate_addresses(void *cls, 1740iterate_addresses (void *cls,
1708 const struct GNUNET_PeerIdentity *key, 1741 const struct GNUNET_PeerIdentity *key,
1709 void *value) 1742 void *value)
1710{ 1743{
1711 struct IteratorContext *ic = cls; 1744 struct IteratorContext *ic = cls;
1712 struct ValidationEntry *ve = value; 1745 struct ValidationEntry *ve = value;
1713 1746
1714 ic->cb(ic->cb_cls, 1747 ic->cb (ic->cb_cls,
1715 ve->valid_until, 1748 ve->valid_until,
1716 ve->revalidation_block, 1749 ve->revalidation_block,
1717 ve->address); 1750 ve->address);
1718 return GNUNET_OK; 1751 return GNUNET_OK;
1719} 1752}
1720 1753
@@ -1728,17 +1761,17 @@ iterate_addresses(void *cls,
1728 * @param cb_cls closure for @a cb 1761 * @param cb_cls closure for @a cb
1729 */ 1762 */
1730void 1763void
1731GST_validation_get_addresses(const struct GNUNET_PeerIdentity *target, 1764GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1732 GST_ValidationAddressCallback cb, 1765 GST_ValidationAddressCallback cb,
1733 void *cb_cls) 1766 void *cb_cls)
1734{ 1767{
1735 struct IteratorContext ic; 1768 struct IteratorContext ic;
1736 1769
1737 ic.cb = cb; 1770 ic.cb = cb;
1738 ic.cb_cls = cb_cls; 1771 ic.cb_cls = cb_cls;
1739 GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, 1772 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
1740 target, 1773 target,
1741 &iterate_addresses, &ic); 1774 &iterate_addresses, &ic);
1742} 1775}
1743 1776
1744 1777
@@ -1752,37 +1785,37 @@ GST_validation_get_addresses(const struct GNUNET_PeerIdentity *target,
1752 * #GNUNET_NO if we are no longer using the address for a connection 1785 * #GNUNET_NO if we are no longer using the address for a connection
1753 */ 1786 */
1754void 1787void
1755GST_validation_set_address_use(const struct GNUNET_HELLO_Address *address, 1788GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
1756 int in_use) 1789 int in_use)
1757{ 1790{
1758 struct ValidationEntry *ve; 1791 struct ValidationEntry *ve;
1759 1792
1760 if (GNUNET_HELLO_address_check_option(address, 1793 if (GNUNET_HELLO_address_check_option (address,
1761 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 1794 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1762 return; /* ignore inbound for validation */ 1795 return; /* ignore inbound for validation */
1763 if (NULL == GST_plugins_find(address->transport_name)) 1796 if (NULL == GST_plugins_find (address->transport_name))
1764 { 1797 {
1765 /* How can we use an address for which we don't have the plugin? */ 1798 /* How can we use an address for which we don't have the plugin? */
1766 GNUNET_break(0); 1799 GNUNET_break (0);
1767 return; 1800 return;
1768 } 1801 }
1769 ve = find_validation_entry(address); 1802 ve = find_validation_entry (address);
1770 if (NULL == ve) 1803 if (NULL == ve)
1771 { 1804 {
1772 GNUNET_break(0); 1805 GNUNET_break (0);
1773 return; 1806 return;
1774 } 1807 }
1775 if (in_use == ve->in_use) 1808 if (in_use == ve->in_use)
1776 return; 1809 return;
1777 ve->in_use = in_use; 1810 ve->in_use = in_use;
1778 if (GNUNET_YES == in_use) 1811 if (GNUNET_YES == in_use)
1779 { 1812 {
1780 /* from now on, higher frequeny, so reschedule now */ 1813 /* from now on, higher frequeny, so reschedule now */
1781 if (NULL != ve->revalidation_task) 1814 if (NULL != ve->revalidation_task)
1782 GNUNET_SCHEDULER_cancel(ve->revalidation_task); 1815 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
1783 ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, 1816 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address,
1784 ve); 1817 ve);
1785 } 1818 }
1786} 1819}
1787 1820
1788 1821
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 @@
37 * @param max_fds maximum number of fds to use 37 * @param max_fds maximum number of fds to use
38 */ 38 */
39void 39void
40GST_validation_start(unsigned int max_fds); 40GST_validation_start (unsigned int max_fds);
41 41
42 42
43/** 43/**
44 * Stop the validation subsystem. 44 * Stop the validation subsystem.
45 */ 45 */
46void 46void
47GST_validation_stop(void); 47GST_validation_stop (void);
48 48
49 49
50/** 50/**
@@ -57,8 +57,8 @@ GST_validation_stop(void);
57 * #GNUNET_NO if we are no longer using the address for a connection 57 * #GNUNET_NO if we are no longer using the address for a connection
58 */ 58 */
59void 59void
60GST_validation_set_address_use(const struct GNUNET_HELLO_Address *address, 60GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
61 int in_use); 61 int in_use);
62 62
63 63
64/** 64/**
@@ -71,10 +71,10 @@ GST_validation_set_address_use(const struct GNUNET_HELLO_Address *address,
71 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 71 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
72 */ 72 */
73int 73int
74GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender, 74GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
75 const struct GNUNET_MessageHeader *hdr, 75 const struct GNUNET_MessageHeader *hdr,
76 const struct GNUNET_HELLO_Address *sender_address, 76 const struct GNUNET_HELLO_Address *sender_address,
77 struct GNUNET_ATS_Session *session); 77 struct GNUNET_ATS_Session *session);
78 78
79 79
80/** 80/**
@@ -86,8 +86,8 @@ GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender,
86 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 86 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
87 */ 87 */
88int 88int
89GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender, 89GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
90 const struct GNUNET_MessageHeader *hdr); 90 const struct GNUNET_MessageHeader *hdr);
91 91
92 92
93/** 93/**
@@ -98,7 +98,7 @@ GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender,
98 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 98 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
99 */ 99 */
100int 100int
101GST_validation_handle_hello(const struct GNUNET_MessageHeader *hello); 101GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
102 102
103 103
104/** 104/**
@@ -107,7 +107,7 @@ GST_validation_handle_hello(const struct GNUNET_MessageHeader *hello);
107 * @param address address we should try to validate 107 * @param address address we should try to validate
108 */ 108 */
109void 109void
110GST_validation_handle_address(const struct GNUNET_HELLO_Address *address); 110GST_validation_handle_address (const struct GNUNET_HELLO_Address *address);
111 111
112 112
113/** 113/**
@@ -138,8 +138,8 @@ typedef void
138 * @param cb_cls closure for @a cb 138 * @param cb_cls closure for @a cb
139 */ 139 */
140void 140void
141GST_validation_get_addresses(const struct GNUNET_PeerIdentity *target, 141GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
142 GST_ValidationAddressCallback cb, void *cb_cls); 142 GST_ValidationAddressCallback cb, void *cb_cls);
143 143
144 144
145#endif 145#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 @@
34#include "gnunet_transport_service.h" 34#include "gnunet_transport_service.h"
35 35
36 36
37struct Iteration { 37struct Iteration
38{
38 struct Iteration *next; 39 struct Iteration *next;
39 struct Iteration *prev; 40 struct Iteration *prev;
40 struct GNUNET_TIME_Absolute start; 41 struct GNUNET_TIME_Absolute start;
@@ -53,7 +54,7 @@ struct Iteration {
53 * Timeout for a connections 54 * Timeout for a connections
54 */ 55 */
55#define CONNECT_TIMEOUT \ 56#define CONNECT_TIMEOUT \
56 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 57 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
57 58
58/** 59/**
59 * Benchmarking block size in bye 60 * Benchmarking block size in bye
@@ -160,7 +161,7 @@ static unsigned int verbosity;
160 * @param cls NULL 161 * @param cls NULL
161 */ 162 */
162static void 163static void
163shutdown_task(void *cls) 164shutdown_task (void *cls)
164{ 165{
165 struct Iteration *icur; 166 struct Iteration *icur;
166 struct Iteration *inext; 167 struct Iteration *inext;
@@ -173,28 +174,28 @@ shutdown_task(void *cls)
173 float stddev_duration; 174 float stddev_duration;
174 175
175 if (NULL != ats_sh) 176 if (NULL != ats_sh)
176 { 177 {
177 GNUNET_ATS_connectivity_suggest_cancel(ats_sh); 178 GNUNET_ATS_connectivity_suggest_cancel (ats_sh);
178 ats_sh = NULL; 179 ats_sh = NULL;
179 } 180 }
180 if (NULL != bl_handle) 181 if (NULL != bl_handle)
181 { 182 {
182 GNUNET_TRANSPORT_blacklist_cancel(bl_handle); 183 GNUNET_TRANSPORT_blacklist_cancel (bl_handle);
183 bl_handle = NULL; 184 bl_handle = NULL;
184 } 185 }
185 if (NULL != ats) 186 if (NULL != ats)
186 { 187 {
187 GNUNET_ATS_connectivity_done(ats); 188 GNUNET_ATS_connectivity_done (ats);
188 ats = NULL; 189 ats = NULL;
189 } 190 }
190 if (NULL != handle) 191 if (NULL != handle)
191 { 192 {
192 GNUNET_TRANSPORT_core_disconnect(handle); 193 GNUNET_TRANSPORT_core_disconnect (handle);
193 handle = NULL; 194 handle = NULL;
194 } 195 }
195 196
196 if (verbosity > 0) 197 if (verbosity > 0)
197 fprintf(stdout, "\n"); 198 fprintf (stdout, "\n");
198 199
199 /* Output format: 200 /* Output format:
200 * All time values in ms 201 * All time values in ms
@@ -202,95 +203,95 @@ shutdown_task(void *cls)
202 * #messages;#messagesize;#avg_dur;#avg_rate;#duration_i0;#duration_i0;... */ 203 * #messages;#messagesize;#avg_dur;#avg_rate;#duration_i0;#duration_i0;... */
203 204
204 if (benchmark_send) 205 if (benchmark_send)
206 {
207 /* First iteration to calculcate avg and stddev */
208 iterations = 0;
209 avg_duration = 0;
210 avg_rate = 0.0;
211
212 inext = ihead;
213 while (NULL != (icur = inext))
205 { 214 {
206 /* First iteration to calculcate avg and stddev */ 215 inext = icur->next;
207 iterations = 0; 216 icur->rate = ((benchmark_count * benchmark_size) / 1024)
208 avg_duration = 0; 217 / ((float) icur->dur.rel_value_us / (1000 * 1000));
209 avg_rate = 0.0; 218 if (verbosity > 0)
210 219 fprintf (stdout,
211 inext = ihead; 220 _ ("%llu B in %llu ms == %.2f KB/s!\n"),
212 while (NULL != (icur = inext)) 221 ((long long unsigned int) benchmark_count * benchmark_size),
213 { 222 ((long long unsigned int) icur->dur.rel_value_us / 1000),
214 inext = icur->next; 223 (float) icur->rate);
215 icur->rate = ((benchmark_count * benchmark_size) / 1024) / 224
216 ((float)icur->dur.rel_value_us / (1000 * 1000)); 225 avg_duration += icur->dur.rel_value_us / (1000);
217 if (verbosity > 0) 226 avg_rate += icur->rate;
218 fprintf(stdout, 227 iterations++;
219 _("%llu B in %llu ms == %.2f KB/s!\n"),
220 ((long long unsigned int)benchmark_count * benchmark_size),
221 ((long long unsigned int)icur->dur.rel_value_us / 1000),
222 (float)icur->rate);
223
224 avg_duration += icur->dur.rel_value_us / (1000);
225 avg_rate += icur->rate;
226 iterations++;
227 }
228 if (0 == iterations)
229 iterations = 1; /* avoid division by zero */
230 /* Calculate average rate */
231 avg_rate /= iterations;
232 /* Calculate average duration */
233 avg_duration /= iterations;
234
235 stddev_rate = 0;
236 stddev_duration = 0;
237 inext = ihead;
238 while (NULL != (icur = inext))
239 {
240 inext = icur->next;
241 stddev_rate += ((icur->rate - avg_rate) * (icur->rate - avg_rate));
242 stddev_duration += (((icur->dur.rel_value_us / 1000) - avg_duration) *
243 ((icur->dur.rel_value_us / 1000) - avg_duration));
244 }
245 /* Calculate standard deviation rate */
246 stddev_rate = stddev_rate / iterations;
247 stddev_rate = sqrtf(stddev_rate);
248
249 /* Calculate standard deviation duration */
250 stddev_duration = stddev_duration / iterations;
251 stddev_duration = sqrtf(stddev_duration);
252
253 /* Output */
254 fprintf(stdout,
255 "%u;%u;%llu;%llu;%.2f;%.2f",
256 benchmark_count,
257 benchmark_size,
258 avg_duration,
259 (unsigned long long)stddev_duration,
260 avg_rate,
261 stddev_rate);
262
263 inext = ihead;
264 while (NULL != (icur = inext))
265 {
266 inext = icur->next;
267 GNUNET_CONTAINER_DLL_remove(ihead, itail, icur);
268
269 fprintf(stdout,
270 ";%llu;%.2f",
271 (long long unsigned int)(icur->dur.rel_value_us / 1000),
272 icur->rate);
273
274 GNUNET_free(icur);
275 }
276 } 228 }
277#if 0 229 if (0 == iterations)
278 if (benchmark_receive) 230 iterations = 1; /* avoid division by zero */
231 /* Calculate average rate */
232 avg_rate /= iterations;
233 /* Calculate average duration */
234 avg_duration /= iterations;
235
236 stddev_rate = 0;
237 stddev_duration = 0;
238 inext = ihead;
239 while (NULL != (icur = inext))
279 { 240 {
280 duration = GNUNET_TIME_absolute_get_duration(start_time); 241 inext = icur->next;
281 fprintf(stdout, 242 stddev_rate += ((icur->rate - avg_rate) * (icur->rate - avg_rate));
282 "Received %llu bytes/s (%llu bytes in %s)\n", 243 stddev_duration += (((icur->dur.rel_value_us / 1000) - avg_duration)
283 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), 244 * ((icur->dur.rel_value_us / 1000) - avg_duration));
284 traffic_received,
285 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES));
286 } 245 }
246 /* Calculate standard deviation rate */
247 stddev_rate = stddev_rate / iterations;
248 stddev_rate = sqrtf (stddev_rate);
249
250 /* Calculate standard deviation duration */
251 stddev_duration = stddev_duration / iterations;
252 stddev_duration = sqrtf (stddev_duration);
253
254 /* Output */
255 fprintf (stdout,
256 "%u;%u;%llu;%llu;%.2f;%.2f",
257 benchmark_count,
258 benchmark_size,
259 avg_duration,
260 (unsigned long long) stddev_duration,
261 avg_rate,
262 stddev_rate);
263
264 inext = ihead;
265 while (NULL != (icur = inext))
266 {
267 inext = icur->next;
268 GNUNET_CONTAINER_DLL_remove (ihead, itail, icur);
269
270 fprintf (stdout,
271 ";%llu;%.2f",
272 (long long unsigned int) (icur->dur.rel_value_us / 1000),
273 icur->rate);
274
275 GNUNET_free (icur);
276 }
277 }
278#if 0
279 if (benchmark_receive)
280 {
281 duration = GNUNET_TIME_absolute_get_duration (start_time);
282 fprintf (stdout,
283 "Received %llu bytes/s (%llu bytes in %s)\n",
284 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
285 traffic_received,
286 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
287 }
287#endif 288#endif
288 fprintf(stdout, "\n"); 289 fprintf (stdout, "\n");
289} 290}
290 291
291 292
292static void 293static void
293iteration_done(); 294iteration_done ();
294 295
295 296
296/** 297/**
@@ -305,66 +306,66 @@ iteration_done();
305 * @return number of bytes written to @a buf 306 * @return number of bytes written to @a buf
306 */ 307 */
307static void 308static void
308send_msg(void *cls) 309send_msg (void *cls)
309{ 310{
310 struct GNUNET_MQ_Envelope *env; 311 struct GNUNET_MQ_Envelope *env;
311 struct GNUNET_MessageHeader *m; 312 struct GNUNET_MessageHeader *m;
312 313
313 if (NULL == mq) 314 if (NULL == mq)
314 return; 315 return;
315 env = GNUNET_MQ_msg_extra(m, benchmark_size, GNUNET_MESSAGE_TYPE_DUMMY); 316 env = GNUNET_MQ_msg_extra (m, benchmark_size, GNUNET_MESSAGE_TYPE_DUMMY);
316 memset(&m[1], 52, benchmark_size - sizeof(struct GNUNET_MessageHeader)); 317 memset (&m[1], 52, benchmark_size - sizeof(struct GNUNET_MessageHeader));
317 318
318 if (itail->msgs_sent < benchmark_count) 319 if (itail->msgs_sent < benchmark_count)
319 { 320 {
320 GNUNET_MQ_notify_sent(env, &send_msg, NULL); 321 GNUNET_MQ_notify_sent (env, &send_msg, NULL);
321 } 322 }
322 else 323 else
323 { 324 {
324 iteration_done(); 325 iteration_done ();
325 } 326 }
326 GNUNET_MQ_send(mq, env); 327 GNUNET_MQ_send (mq, env);
327 if ((verbosity > 0) && (0 == itail->msgs_sent % 10)) 328 if ((verbosity > 0) && (0 == itail->msgs_sent % 10))
328 fprintf(stdout, "."); 329 fprintf (stdout, ".");
329} 330}
330 331
331 332
332static void 333static void
333iteration_start() 334iteration_start ()
334{ 335{
335 struct Iteration *icur; 336 struct Iteration *icur;
336 337
337 ret = 0; 338 ret = 0;
338 if (!benchmark_send) 339 if (! benchmark_send)
339 return; 340 return;
340 benchmark_running = GNUNET_YES; 341 benchmark_running = GNUNET_YES;
341 icur = GNUNET_new(struct Iteration); 342 icur = GNUNET_new (struct Iteration);
342 GNUNET_CONTAINER_DLL_insert_tail(ihead, itail, icur); 343 GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur);
343 icur->start = GNUNET_TIME_absolute_get(); 344 icur->start = GNUNET_TIME_absolute_get ();
344 if (verbosity > 0) 345 if (verbosity > 0)
345 fprintf( 346 fprintf (
346 stdout, 347 stdout,
347 "\nStarting benchmark, starting to send %u messages in %u byte blocks\n", 348 "\nStarting benchmark, starting to send %u messages in %u byte blocks\n",
348 benchmark_count, 349 benchmark_count,
349 benchmark_size); 350 benchmark_size);
350 send_msg(NULL); 351 send_msg (NULL);
351} 352}
352 353
353 354
354static void 355static void
355iteration_done() 356iteration_done ()
356{ 357{
357 static int it_count = 0; 358 static int it_count = 0;
358 359
359 it_count++; 360 it_count++;
360 itail->dur = GNUNET_TIME_absolute_get_duration(itail->start); 361 itail->dur = GNUNET_TIME_absolute_get_duration (itail->start);
361 if (it_count == benchmark_iterations) 362 if (it_count == benchmark_iterations)
362 { 363 {
363 benchmark_running = GNUNET_NO; 364 benchmark_running = GNUNET_NO;
364 GNUNET_SCHEDULER_shutdown(); 365 GNUNET_SCHEDULER_shutdown ();
365 return; 366 return;
366 } 367 }
367 iteration_start(); 368 iteration_start ();
368} 369}
369 370
370 371
@@ -378,20 +379,20 @@ iteration_done()
378 * @return NULL 379 * @return NULL
379 */ 380 */
380static void * 381static void *
381notify_connect(void *cls, 382notify_connect (void *cls,
382 const struct GNUNET_PeerIdentity *peer, 383 const struct GNUNET_PeerIdentity *peer,
383 struct GNUNET_MQ_Handle *m) 384 struct GNUNET_MQ_Handle *m)
384{ 385{
385 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) 386 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
386 { 387 {
387 fprintf(stdout, "Connected to different peer `%s'\n", GNUNET_i2s(&pid)); 388 fprintf (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid));
388 return NULL; 389 return NULL;
389 } 390 }
390 391
391 if (verbosity > 0) 392 if (verbosity > 0)
392 fprintf(stdout, "Successfully connected to `%s'\n", GNUNET_i2s(&pid)); 393 fprintf (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid));
393 mq = m; 394 mq = m;
394 iteration_start(); 395 iteration_start ();
395 return NULL; 396 return NULL;
396} 397}
397 398
@@ -405,20 +406,20 @@ notify_connect(void *cls,
405 * @param internal_cls NULL 406 * @param internal_cls NULL
406 */ 407 */
407static void 408static void
408notify_disconnect(void *cls, 409notify_disconnect (void *cls,
409 const struct GNUNET_PeerIdentity *peer, 410 const struct GNUNET_PeerIdentity *peer,
410 void *internal_cls) 411 void *internal_cls)
411{ 412{
412 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) 413 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
413 return; 414 return;
414 mq = NULL; 415 mq = NULL;
415 if (GNUNET_YES == benchmark_running) 416 if (GNUNET_YES == benchmark_running)
416 { 417 {
417 fprintf(stdout, 418 fprintf (stdout,
418 "Disconnected from peer `%s' while benchmarking\n", 419 "Disconnected from peer `%s' while benchmarking\n",
419 GNUNET_i2s(&pid)); 420 GNUNET_i2s (&pid));
420 return; 421 return;
421 } 422 }
422} 423}
423 424
424 425
@@ -430,7 +431,7 @@ notify_disconnect(void *cls,
430 * @return #GNUNET_OK 431 * @return #GNUNET_OK
431 */ 432 */
432static int 433static int
433check_dummy(void *cls, const struct GNUNET_MessageHeader *message) 434check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
434{ 435{
435 return GNUNET_OK; /* all messages are fine */ 436 return GNUNET_OK; /* all messages are fine */
436} 437}
@@ -443,26 +444,26 @@ check_dummy(void *cls, const struct GNUNET_MessageHeader *message)
443 * @param message the message 444 * @param message the message
444 */ 445 */
445static void 446static void
446handle_dummy(void *cls, const struct GNUNET_MessageHeader *message) 447handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
447{ 448{
448 if (!benchmark_receive) 449 if (! benchmark_receive)
449 return; 450 return;
450 if (verbosity > 0) 451 if (verbosity > 0)
451 fprintf(stdout, 452 fprintf (stdout,
452 "Received %u bytes\n", 453 "Received %u bytes\n",
453 (unsigned int)ntohs(message->size)); 454 (unsigned int) ntohs (message->size));
454} 455}
455 456
456 457
457static int 458static int
458blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *peer) 459blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
459{ 460{
460 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) 461 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
461 { 462 {
462 if (verbosity > 0) 463 if (verbosity > 0)
463 fprintf(stdout, "Denying connection to `%s'\n", GNUNET_i2s(peer)); 464 fprintf (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer));
464 return GNUNET_SYSERR; 465 return GNUNET_SYSERR;
465 } 466 }
466 return GNUNET_OK; 467 return GNUNET_OK;
467} 468}
468 469
@@ -476,92 +477,92 @@ blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *peer)
476 * @param mycfg configuration 477 * @param mycfg configuration
477 */ 478 */
478static void 479static void
479run(void *cls, 480run (void *cls,
480 char *const *args, 481 char *const *args,
481 const char *cfgfile, 482 const char *cfgfile,
482 const struct GNUNET_CONFIGURATION_Handle *mycfg) 483 const struct GNUNET_CONFIGURATION_Handle *mycfg)
483{ 484{
484 struct GNUNET_MQ_MessageHandler handlers[] = 485 struct GNUNET_MQ_MessageHandler handlers[] =
485 { GNUNET_MQ_hd_var_size(dummy, 486 { GNUNET_MQ_hd_var_size (dummy,
486 GNUNET_MESSAGE_TYPE_DUMMY, 487 GNUNET_MESSAGE_TYPE_DUMMY,
487 struct GNUNET_MessageHeader, 488 struct GNUNET_MessageHeader,
488 NULL), 489 NULL),
489 GNUNET_MQ_handler_end() }; 490 GNUNET_MQ_handler_end () };
490 491
491 cfg = (struct GNUNET_CONFIGURATION_Handle *)mycfg; 492 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
492 493
493 ret = 1; 494 ret = 1;
494 if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size) 495 if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size)
495 { 496 {
496 fprintf(stderr, "Message size too big!\n"); 497 fprintf (stderr, "Message size too big!\n");
497 return; 498 return;
498 } 499 }
499 500
500 if (NULL == cpid) 501 if (NULL == cpid)
501 { 502 {
502 fprintf(stderr, "No peer identity given\n"); 503 fprintf (stderr, "No peer identity given\n");
503 return; 504 return;
504 } 505 }
505 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string(cpid, 506 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid,
506 strlen(cpid), 507 strlen (cpid),
507 &pid.public_key)) 508 &pid.public_key))
508 { 509 {
509 fprintf(stderr, "Failed to parse peer identity `%s'\n", cpid); 510 fprintf (stderr, "Failed to parse peer identity `%s'\n", cpid);
510 return; 511 return;
511 } 512 }
512 if (1 == benchmark_send) 513 if (1 == benchmark_send)
513 { 514 {
514 if (verbosity > 0) 515 if (verbosity > 0)
515 fprintf(stderr, 516 fprintf (stderr,
516 "Trying to send %u messages with size %u to peer `%s'\n", 517 "Trying to send %u messages with size %u to peer `%s'\n",
517 benchmark_count, 518 benchmark_count,
518 benchmark_size, 519 benchmark_size,
519 GNUNET_i2s(&pid)); 520 GNUNET_i2s (&pid));
520 } 521 }
521 else if (1 == benchmark_receive) 522 else if (1 == benchmark_receive)
522 { 523 {
523 fprintf(stderr, 524 fprintf (stderr,
524 "Trying to receive messages from peer `%s'\n", 525 "Trying to receive messages from peer `%s'\n",
525 GNUNET_i2s(&pid)); 526 GNUNET_i2s (&pid));
526 } 527 }
527 else 528 else
528 { 529 {
529 fprintf(stderr, "No operation given\n"); 530 fprintf (stderr, "No operation given\n");
530 return; 531 return;
531 } 532 }
532 533
533 ats = GNUNET_ATS_connectivity_init(cfg); 534 ats = GNUNET_ATS_connectivity_init (cfg);
534 if (NULL == ats) 535 if (NULL == ats)
535 { 536 {
536 fprintf(stderr, "Failed to connect to ATS service\n"); 537 fprintf (stderr, "Failed to connect to ATS service\n");
537 ret = 1; 538 ret = 1;
538 return; 539 return;
539 } 540 }
540 541
541 handle = GNUNET_TRANSPORT_core_connect(cfg, 542 handle = GNUNET_TRANSPORT_core_connect (cfg,
542 NULL, 543 NULL,
543 handlers, 544 handlers,
544 NULL, 545 NULL,
545 &notify_connect, 546 &notify_connect,
546 &notify_disconnect, 547 &notify_disconnect,
547 NULL); 548 NULL);
548 if (NULL == handle) 549 if (NULL == handle)
549 { 550 {
550 fprintf(stderr, "Failed to connect to transport service\n"); 551 fprintf (stderr, "Failed to connect to transport service\n");
551 GNUNET_ATS_connectivity_done(ats); 552 GNUNET_ATS_connectivity_done (ats);
552 ats = NULL; 553 ats = NULL;
553 ret = 1; 554 ret = 1;
554 return; 555 return;
555 } 556 }
556 557
557 bl_handle = GNUNET_TRANSPORT_blacklist(cfg, &blacklist_cb, NULL); 558 bl_handle = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
558 ats_sh = GNUNET_ATS_connectivity_suggest(ats, &pid, 1); 559 ats_sh = GNUNET_ATS_connectivity_suggest (ats, &pid, 1);
559 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 560 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
560} 561}
561 562
562 563
563int 564int
564main(int argc, char *const *argv) 565main (int argc, char *const *argv)
565{ 566{
566 int res; 567 int res;
567 568
@@ -571,50 +572,50 @@ main(int argc, char *const *argv)
571 benchmark_running = GNUNET_NO; 572 benchmark_running = GNUNET_NO;
572 573
573 struct GNUNET_GETOPT_CommandLineOption options[] = { 574 struct GNUNET_GETOPT_CommandLineOption options[] = {
574 GNUNET_GETOPT_option_flag('s', 575 GNUNET_GETOPT_option_flag ('s',
575 "send", 576 "send",
576 gettext_noop("send data to peer"), 577 gettext_noop ("send data to peer"),
577 &benchmark_send), 578 &benchmark_send),
578 GNUNET_GETOPT_option_flag('r', 579 GNUNET_GETOPT_option_flag ('r',
579 "receive", 580 "receive",
580 gettext_noop("receive data from peer"), 581 gettext_noop ("receive data from peer"),
581 &benchmark_receive), 582 &benchmark_receive),
582 GNUNET_GETOPT_option_uint('i', 583 GNUNET_GETOPT_option_uint ('i',
583 "iterations", 584 "iterations",
584 NULL, 585 NULL,
585 gettext_noop("iterations"), 586 gettext_noop ("iterations"),
586 &benchmark_iterations), 587 &benchmark_iterations),
587 GNUNET_GETOPT_option_uint('n', 588 GNUNET_GETOPT_option_uint ('n',
588 "number", 589 "number",
589 NULL, 590 NULL,
590 gettext_noop("number of messages to send"), 591 gettext_noop ("number of messages to send"),
591 &benchmark_count), 592 &benchmark_count),
592 GNUNET_GETOPT_option_uint('m', 593 GNUNET_GETOPT_option_uint ('m',
593 "messagesize", 594 "messagesize",
594 NULL, 595 NULL,
595 gettext_noop("message size to use"), 596 gettext_noop ("message size to use"),
596 &benchmark_size), 597 &benchmark_size),
597 GNUNET_GETOPT_option_string('p', 598 GNUNET_GETOPT_option_string ('p',
598 "peer", 599 "peer",
599 "PEER", 600 "PEER",
600 gettext_noop("peer identity"), 601 gettext_noop ("peer identity"),
601 &cpid), 602 &cpid),
602 GNUNET_GETOPT_option_verbose(&verbosity), 603 GNUNET_GETOPT_option_verbose (&verbosity),
603 GNUNET_GETOPT_OPTION_END 604 GNUNET_GETOPT_OPTION_END
604 }; 605 };
605 606
606 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 607 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
607 return 2; 608 return 2;
608 609
609 res = 610 res =
610 GNUNET_PROGRAM_run(argc, 611 GNUNET_PROGRAM_run (argc,
611 argv, 612 argv,
612 "gnunet-transport", 613 "gnunet-transport",
613 gettext_noop("Direct access to transport service."), 614 gettext_noop ("Direct access to transport service."),
614 options, 615 options,
615 &run, 616 &run,
616 NULL); 617 NULL);
617 GNUNET_free((void *)argv); 618 GNUNET_free ((void *) argv);
618 if (GNUNET_OK == res) 619 if (GNUNET_OK == res)
619 return ret; 620 return ret;
620 return 1; 621 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 @@
28#include "plugin_transport_wlan.h" 28#include "plugin_transport_wlan.h"
29 29
30int 30int
31main(int argc, char *argv[]) 31main (int argc, char *argv[])
32{ 32{
33 char msg_buf[65536]; 33 char msg_buf[65536];
34 unsigned long long count; 34 unsigned long long count;
@@ -40,75 +40,75 @@ main(int argc, char *argv[])
40 int commpipe[2]; /* This holds the fd for the input & output of the pipe */ 40 int commpipe[2]; /* This holds the fd for the input & output of the pipe */
41 41
42 if (2 != argc) 42 if (2 != argc)
43 { 43 {
44 fprintf(stderr, 44 fprintf (stderr,
45 "This program must be started with the interface name as argument.\n"); 45 "This program must be started with the interface name as argument.\n");
46 fprintf(stderr, 46 fprintf (stderr,
47 "Usage: %s interface-name\n" 47 "Usage: %s interface-name\n"
48 "e.g. %s mon0\n", 48 "e.g. %s mon0\n",
49 argv[0], 49 argv[0],
50 argv[0]); 50 argv[0]);
51 return 1; 51 return 1;
52 } 52 }
53 53
54 /* Setup communication pipeline first */ 54 /* Setup communication pipeline first */
55 if (pipe(commpipe)) 55 if (pipe (commpipe))
56 { 56 {
57 fprintf(stderr, "Failed to create pipe: %s\n", strerror(errno)); 57 fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
58 exit(1); 58 exit (1);
59 } 59 }
60 60
61 /* Attempt to fork and check for errors */ 61 /* Attempt to fork and check for errors */
62 if ((pid = fork()) == -1) 62 if ((pid = fork ()) == -1)
63 { 63 {
64 fprintf(stderr, "Failed to fork: %s\n", strerror(errno)); 64 fprintf (stderr, "Failed to fork: %s\n", strerror (errno));
65 exit(1); 65 exit (1);
66 } 66 }
67 67
68 if (pid) 68 if (pid)
69 {
70 /* A positive (non-negative) PID indicates the parent process */
71 if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */
72 fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
73 start = time (NULL);
74 count = 0;
75 while (1)
69 { 76 {
70 /* A positive (non-negative) PID indicates the parent process */ 77 ret = read (commpipe[0], msg_buf, sizeof(msg_buf));
71 if (0 != close(commpipe[1])) /* Close unused side of pipe (in side) */ 78 if (0 > ret)
72 fprintf(stderr, "Failed to close fd: %s\n", strerror(errno)); 79 {
73 start = time(NULL); 80 fprintf (stderr, "read failed: %s\n", strerror (errno));
74 count = 0; 81 break;
75 while (1) 82 }
76 { 83 count += ret;
77 ret = read(commpipe[0], msg_buf, sizeof(msg_buf)); 84 akt = time (NULL);
78 if (0 > ret) 85 if (akt - start > 30)
79 { 86 {
80 fprintf(stderr, "read failed: %s\n", strerror(errno)); 87 bytes_per_s = count / (akt - start);
81 break; 88 bytes_per_s /= 1024;
82 } 89 printf ("recv %f kb/s\n", bytes_per_s);
83 count += ret; 90 start = akt;
84 akt = time(NULL); 91 count = 0;
85 if (akt - start > 30) 92 }
86 {
87 bytes_per_s = count / (akt - start);
88 bytes_per_s /= 1024;
89 printf("recv %f kb/s\n", bytes_per_s);
90 start = akt;
91 count = 0;
92 }
93 }
94 } 93 }
94 }
95 else 95 else
96 {
97 /* A zero PID indicates that this is the child process */
98 (void) close (1);
99 if (-1 ==
100 dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */
101 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
102 (void) close (commpipe[0]); /* Close unused side of pipe (in side) */
103 /* Replace the child fork with a new process */
104 if (execlp ("gnunet-helper-transport-wlan",
105 "gnunet-helper-transport-wlan",
106 argv[1],
107 NULL) == -1)
96 { 108 {
97 /* A zero PID indicates that this is the child process */ 109 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
98 (void)close(1); 110 _exit (1);
99 if (-1 ==
100 dup2(commpipe[1], 1)) /* Replace stdin with the in side of the pipe */
101 fprintf(stderr, "dup2 failed: %s\n", strerror(errno));
102 (void)close(commpipe[0]); /* Close unused side of pipe (in side) */
103 /* Replace the child fork with a new process */
104 if (execlp("gnunet-helper-transport-wlan",
105 "gnunet-helper-transport-wlan",
106 argv[1],
107 NULL) == -1)
108 {
109 fprintf(stderr, "Could not start gnunet-helper-transport-wlan!");
110 _exit(1);
111 }
112 } 111 }
112 }
113 return 0; 113 return 0;
114} 114}
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 @@
54 * @return GNUNET_YES at success 54 * @return GNUNET_YES at success
55 */ 55 */
56static int 56static int
57getRadiotapHeader(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, 57getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
58 uint16_t size) 58 uint16_t size)
59{ 59{
60 header->header.size = htons(size); 60 header->header.size = htons (size);
61 header->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); 61 header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER);
62 header->rate = 255; 62 header->rate = 255;
63 header->tx_power = 0; 63 header->tx_power = 0;
64 header->antenna = 0; 64 header->antenna = 0;
@@ -74,18 +74,18 @@ getRadiotapHeader(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
74 * @return GNUNET_YES if there was no error 74 * @return GNUNET_YES if there was no error
75 */ 75 */
76static int 76static int
77getWlanHeader(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header, 77getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header,
78 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, 78 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
79 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, 79 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac,
80 unsigned int size) 80 unsigned int size)
81{ 81{
82 const int rate = 11000000; 82 const int rate = 11000000;
83 83
84 Header->frame_control = htons(IEEE80211_FC0_TYPE_DATA); 84 Header->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
85 Header->addr3 = mac_bssid_gnunet; 85 Header->addr3 = mac_bssid_gnunet;
86 Header->addr2 = *mac; 86 Header->addr2 = *mac;
87 Header->addr1 = *to_mac_addr; 87 Header->addr1 = *to_mac_addr;
88 Header->duration = GNUNET_htole16((size * 1000000) / rate + 290); 88 Header->duration = GNUNET_htole16 ((size * 1000000) / rate + 290);
89 Header->llc[0] = WLAN_LLC_DSAP_FIELD; 89 Header->llc[0] = WLAN_LLC_DSAP_FIELD;
90 Header->llc[1] = WLAN_LLC_SSAP_FIELD; 90 Header->llc[1] = WLAN_LLC_SSAP_FIELD;
91 Header->llc[2] = 0; // FIXME 91 Header->llc[2] = 0; // FIXME
@@ -95,7 +95,7 @@ getWlanHeader(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header,
95 95
96 96
97int 97int
98main(int argc, char *argv[]) 98main (int argc, char *argv[])
99{ 99{
100 char msg_buf[WLAN_MTU]; 100 char msg_buf[WLAN_MTU];
101 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radiotap; 101 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radiotap;
@@ -114,137 +114,137 @@ main(int argc, char *argv[])
114 int macpipe[2]; /* This holds the fd for the input & output of the pipe */ 114 int macpipe[2]; /* This holds the fd for the input & output of the pipe */
115 115
116 if (4 != argc) 116 if (4 != argc)
117 { 117 {
118 fprintf( 118 fprintf (
119 stderr, 119 stderr,
120 "This program must be started with the interface and the targets and source mac as argument.\n"); 120 "This program must be started with the interface and the targets and source mac as argument.\n");
121 fprintf(stderr, 121 fprintf (stderr,
122 "Usage: interface-name mac-DST mac-SRC\n" 122 "Usage: interface-name mac-DST mac-SRC\n"
123 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); 123 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
124 return 1; 124 return 1;
125 } 125 }
126 if (6 != sscanf(argv[2], 126 if (6 != sscanf (argv[2],
127 "%x-%x-%x-%x-%x-%x", 127 "%x-%x-%x-%x-%x-%x",
128 &temp[0], 128 &temp[0],
129 &temp[1], 129 &temp[1],
130 &temp[2], 130 &temp[2],
131 &temp[3], 131 &temp[3],
132 &temp[4], 132 &temp[4],
133 &temp[5])) 133 &temp[5]))
134 { 134 {
135 fprintf(stderr, 135 fprintf (stderr,
136 "Usage: interface-name mac-DST mac-SRC\n" 136 "Usage: interface-name mac-DST mac-SRC\n"
137 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); 137 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
138 return 1; 138 return 1;
139 } 139 }
140 for (i = 0; i < 6; i++) 140 for (i = 0; i < 6; i++)
141 outmac.mac[i] = temp[i]; 141 outmac.mac[i] = temp[i];
142 if (6 != sscanf(argv[3], 142 if (6 != sscanf (argv[3],
143 "%x-%x-%x-%x-%x-%x", 143 "%x-%x-%x-%x-%x-%x",
144 &temp[0], 144 &temp[0],
145 &temp[1], 145 &temp[1],
146 &temp[2], 146 &temp[2],
147 &temp[3], 147 &temp[3],
148 &temp[4], 148 &temp[4],
149 &temp[5])) 149 &temp[5]))
150 { 150 {
151 fprintf(stderr, 151 fprintf (stderr,
152 "Usage: interface-name mac-DST mac-SRC\n" 152 "Usage: interface-name mac-DST mac-SRC\n"
153 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); 153 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
154 return 1; 154 return 1;
155 } 155 }
156 for (i = 0; i < 6; i++) 156 for (i = 0; i < 6; i++)
157 inmac.mac[i] = temp[i]; 157 inmac.mac[i] = temp[i];
158 158
159 159
160 /* Setup communication pipeline first */ 160 /* Setup communication pipeline first */
161 if (pipe(commpipe)) 161 if (pipe (commpipe))
162 { 162 {
163 fprintf(stderr, "Failed to create pipe: %s\n", strerror(errno)); 163 fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
164 exit(1); 164 exit (1);
165 } 165 }
166 if (pipe(macpipe)) 166 if (pipe (macpipe))
167 { 167 {
168 fprintf(stderr, "Failed to create pipe: %s\n", strerror(errno)); 168 fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
169 exit(1); 169 exit (1);
170 } 170 }
171 171
172 /* Attempt to fork and check for errors */ 172 /* Attempt to fork and check for errors */
173 if ((pid = fork()) == -1) 173 if ((pid = fork ()) == -1)
174 { 174 {
175 fprintf(stderr, "Failed to fork: %s\n", strerror(errno)); 175 fprintf (stderr, "Failed to fork: %s\n", strerror (errno));
176 exit(1); 176 exit (1);
177 } 177 }
178 memset(msg_buf, 0x42, sizeof(msg_buf)); 178 memset (msg_buf, 0x42, sizeof(msg_buf));
179 if (pid) 179 if (pid)
180 {
181 /* A positive (non-negative) PID indicates the parent process */
182 if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */
183 fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
184 setvbuf (stdout,
185 (char *) NULL,
186 _IONBF,
187 0); /* Set non-buffered output on stdout */
188
189 if (0 != close (macpipe[1]))
190 fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
191 if (sizeof(hcm) != read (macpipe[0], &hcm, sizeof(hcm)))
192 fprintf (stderr, "Failed to read hcm...\n");
193 fprintf (stderr,
194 "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n",
195 hcm.mac.mac[0],
196 hcm.mac.mac[1],
197 hcm.mac.mac[2],
198 hcm.mac.mac[3],
199 hcm.mac.mac[4],
200 hcm.mac.mac[5]);
201 radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf;
202 getRadiotapHeader (radiotap, WLAN_MTU);
203 getWlanHeader (&radiotap->frame, &outmac, &inmac, WLAN_MTU);
204 start = time (NULL);
205 count = 0;
206 while (1)
180 { 207 {
181 /* A positive (non-negative) PID indicates the parent process */ 208 ret = write (commpipe[1], msg_buf, WLAN_MTU);
182 if (0 != close(commpipe[0])) /* Close unused side of pipe (in side) */ 209 if (0 > ret)
183 fprintf(stderr, "Failed to close fd: %s\n", strerror(errno)); 210 {
184 setvbuf(stdout, 211 fprintf (stderr, "write failed: %s\n", strerror (errno));
185 (char *)NULL, 212 break;
186 _IONBF, 213 }
187 0); /* Set non-buffered output on stdout */ 214 count += ret;
188 215 akt = time (NULL);
189 if (0 != close(macpipe[1])) 216 if (akt - start > 30)
190 fprintf(stderr, "Failed to close fd: %s\n", strerror(errno)); 217 {
191 if (sizeof(hcm) != read(macpipe[0], &hcm, sizeof(hcm))) 218 bytes_per_s = count / (akt - start);
192 fprintf(stderr, "Failed to read hcm...\n"); 219 bytes_per_s /= 1024;
193 fprintf(stderr, 220 printf ("send %f kbytes/s\n", bytes_per_s);
194 "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", 221 start = akt;
195 hcm.mac.mac[0], 222 count = 0;
196 hcm.mac.mac[1], 223 }
197 hcm.mac.mac[2],
198 hcm.mac.mac[3],
199 hcm.mac.mac[4],
200 hcm.mac.mac[5]);
201 radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)msg_buf;
202 getRadiotapHeader(radiotap, WLAN_MTU);
203 getWlanHeader(&radiotap->frame, &outmac, &inmac, WLAN_MTU);
204 start = time(NULL);
205 count = 0;
206 while (1)
207 {
208 ret = write(commpipe[1], msg_buf, WLAN_MTU);
209 if (0 > ret)
210 {
211 fprintf(stderr, "write failed: %s\n", strerror(errno));
212 break;
213 }
214 count += ret;
215 akt = time(NULL);
216 if (akt - start > 30)
217 {
218 bytes_per_s = count / (akt - start);
219 bytes_per_s /= 1024;
220 printf("send %f kbytes/s\n", bytes_per_s);
221 start = akt;
222 count = 0;
223 }
224 }
225 } 224 }
225 }
226 else 226 else
227 {
228 /* A zero PID indicates that this is the child process */
229 (void) close (0);
230 (void) close (1);
231 if (-1 ==
232 dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */
233 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
234 if (-1 ==
235 dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */
236 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
237 (void) close (commpipe[1]); /* Close unused side of pipe (out side) */
238 (void) close (macpipe[0]); /* Close unused side of pipe (in side) */
239 /* Replace the child fork with a new process */
240 if (execlp ("gnunet-helper-transport-wlan",
241 "gnunet-helper-transport-wlan",
242 argv[1],
243 NULL) == -1)
227 { 244 {
228 /* A zero PID indicates that this is the child process */ 245 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
229 (void)close(0); 246 _exit (1);
230 (void)close(1);
231 if (-1 ==
232 dup2(commpipe[0], 0)) /* Replace stdin with the in side of the pipe */
233 fprintf(stderr, "dup2 failed: %s\n", strerror(errno));
234 if (-1 ==
235 dup2(macpipe[1], 1)) /* Replace stdout with the out side of the pipe */
236 fprintf(stderr, "dup2 failed: %s\n", strerror(errno));
237 (void)close(commpipe[1]); /* Close unused side of pipe (out side) */
238 (void)close(macpipe[0]); /* Close unused side of pipe (in side) */
239 /* Replace the child fork with a new process */
240 if (execlp("gnunet-helper-transport-wlan",
241 "gnunet-helper-transport-wlan",
242 argv[1],
243 NULL) == -1)
244 {
245 fprintf(stderr, "Could not start gnunet-helper-transport-wlan!");
246 _exit(1);
247 }
248 } 247 }
248 }
249 return 0; 249 return 0;
250} 250}
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 @@
34 * Timeout for a name resolution 34 * Timeout for a name resolution
35 */ 35 */
36#define RESOLUTION_TIMEOUT \ 36#define RESOLUTION_TIMEOUT \
37 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 37 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
38 38
39/** 39/**
40 * Timeout for an operation 40 * Timeout for an operation
41 */ 41 */
42#define OP_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 42#define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
43 43
44 44
45/** 45/**
46 * Context to store name resolutions for valiation 46 * Context to store name resolutions for valiation
47 */ 47 */
48struct ValidationResolutionContext { 48struct ValidationResolutionContext
49{
49 /** 50 /**
50 * Next in DLL 51 * Next in DLL
51 */ 52 */
@@ -95,7 +96,8 @@ struct ValidationResolutionContext {
95/** 96/**
96 * Struct to store information about peers in monitor mode 97 * Struct to store information about peers in monitor mode
97 */ 98 */
98struct MonitoredPeer { 99struct MonitoredPeer
100{
99 /** 101 /**
100 * State of the peer 102 * State of the peer
101 */ 103 */
@@ -115,7 +117,8 @@ struct MonitoredPeer {
115/** 117/**
116 * Context to store name resolutions for valiation 118 * Context to store name resolutions for valiation
117 */ 119 */
118struct PeerResolutionContext { 120struct PeerResolutionContext
121{
119 /** 122 /**
120 * Next in DLL 123 * Next in DLL
121 */ 124 */
@@ -329,15 +332,15 @@ static struct PeerResolutionContext *rc_tail;
329 * @return #GNUNET_OK (continue to iterate) 332 * @return #GNUNET_OK (continue to iterate)
330 */ 333 */
331static int 334static int
332destroy_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 335destroy_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
333{ 336{
334 struct MonitoredPeer *m = value; 337 struct MonitoredPeer *m = value;
335 338
336 GNUNET_assert( 339 GNUNET_assert (
337 GNUNET_OK == 340 GNUNET_OK ==
338 GNUNET_CONTAINER_multipeermap_remove(monitored_peers, key, value)); 341 GNUNET_CONTAINER_multipeermap_remove (monitored_peers, key, value));
339 GNUNET_free_non_null(m->address); 342 GNUNET_free_non_null (m->address);
340 GNUNET_free(value); 343 GNUNET_free (value);
341 return GNUNET_OK; 344 return GNUNET_OK;
342} 345}
343 346
@@ -349,7 +352,7 @@ destroy_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
349 * @param cls NULL 352 * @param cls NULL
350 */ 353 */
351static void 354static void
352shutdown_task(void *cls) 355shutdown_task (void *cls)
353{ 356{
354 struct GNUNET_TIME_Relative duration; 357 struct GNUNET_TIME_Relative duration;
355 struct ValidationResolutionContext *cur; 358 struct ValidationResolutionContext *cur;
@@ -357,82 +360,82 @@ shutdown_task(void *cls)
357 struct PeerResolutionContext *rc; 360 struct PeerResolutionContext *rc;
358 361
359 if (NULL != op_timeout) 362 if (NULL != op_timeout)
360 { 363 {
361 GNUNET_SCHEDULER_cancel(op_timeout); 364 GNUNET_SCHEDULER_cancel (op_timeout);
362 op_timeout = NULL; 365 op_timeout = NULL;
363 } 366 }
364 if (NULL != pic) 367 if (NULL != pic)
365 { 368 {
366 GNUNET_TRANSPORT_monitor_peers_cancel(pic); 369 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
367 pic = NULL; 370 pic = NULL;
368 } 371 }
369 if (NULL != pm) 372 if (NULL != pm)
370 { 373 {
371 GNUNET_TRANSPORT_monitor_plugins_cancel(pm); 374 GNUNET_TRANSPORT_monitor_plugins_cancel (pm);
372 pm = NULL; 375 pm = NULL;
373 } 376 }
374 377
375 next = vc_head; 378 next = vc_head;
376 for (cur = next; NULL != cur; cur = next) 379 for (cur = next; NULL != cur; cur = next)
377 { 380 {
378 next = cur->next; 381 next = cur->next;
379 382
380 GNUNET_TRANSPORT_address_to_string_cancel(cur->asc); 383 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
381 GNUNET_CONTAINER_DLL_remove(vc_head, vc_tail, cur); 384 GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, cur);
382 GNUNET_free(cur->transport); 385 GNUNET_free (cur->transport);
383 GNUNET_HELLO_address_free(cur->addrcp); 386 GNUNET_HELLO_address_free (cur->addrcp);
384 GNUNET_free(cur); 387 GNUNET_free (cur);
385 } 388 }
386 while (NULL != (rc = rc_head)) 389 while (NULL != (rc = rc_head))
387 { 390 {
388 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc); 391 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc);
389 GNUNET_TRANSPORT_address_to_string_cancel(rc->asc); 392 GNUNET_TRANSPORT_address_to_string_cancel (rc->asc);
390 GNUNET_free(rc->transport); 393 GNUNET_free (rc->transport);
391 GNUNET_free(rc->addrcp); 394 GNUNET_free (rc->addrcp);
392 GNUNET_free(rc); 395 GNUNET_free (rc);
393 } 396 }
394 if (NULL != handle) 397 if (NULL != handle)
395 { 398 {
396 GNUNET_TRANSPORT_core_disconnect(handle); 399 GNUNET_TRANSPORT_core_disconnect (handle);
397 handle = NULL; 400 handle = NULL;
398 } 401 }
399 if (benchmark_send) 402 if (benchmark_send)
400 { 403 {
401 duration = GNUNET_TIME_absolute_get_duration(start_time); 404 duration = GNUNET_TIME_absolute_get_duration (start_time);
402 fprintf(stdout, 405 fprintf (stdout,
403 _("Transmitted %llu bytes/s (%llu bytes in %s)\n"), 406 _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
404 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), 407 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
405 traffic_sent, 408 traffic_sent,
406 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES)); 409 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
407 } 410 }
408 if (benchmark_receive) 411 if (benchmark_receive)
409 { 412 {
410 duration = GNUNET_TIME_absolute_get_duration(start_time); 413 duration = GNUNET_TIME_absolute_get_duration (start_time);
411 fprintf(stdout, 414 fprintf (stdout,
412 _("Received %llu bytes/s (%llu bytes in %s)\n"), 415 _ ("Received %llu bytes/s (%llu bytes in %s)\n"),
413 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), 416 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
414 traffic_received, 417 traffic_received,
415 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES)); 418 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
416 } 419 }
417 420
418 if (NULL != monitored_peers) 421 if (NULL != monitored_peers)
419 { 422 {
420 GNUNET_CONTAINER_multipeermap_iterate(monitored_peers, &destroy_it, NULL); 423 GNUNET_CONTAINER_multipeermap_iterate (monitored_peers, &destroy_it, NULL);
421 GNUNET_CONTAINER_multipeermap_destroy(monitored_peers); 424 GNUNET_CONTAINER_multipeermap_destroy (monitored_peers);
422 monitored_peers = NULL; 425 monitored_peers = NULL;
423 } 426 }
424 if (NULL != monitored_plugins) 427 if (NULL != monitored_plugins)
425 { 428 {
426 GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(monitored_plugins)); 429 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (monitored_plugins));
427 GNUNET_CONTAINER_multipeermap_destroy(monitored_plugins); 430 GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins);
428 monitored_plugins = NULL; 431 monitored_plugins = NULL;
429 } 432 }
430 if (NULL != blacklist) 433 if (NULL != blacklist)
431 { 434 {
432 GNUNET_TRANSPORT_blacklist_cancel(blacklist); 435 GNUNET_TRANSPORT_blacklist_cancel (blacklist);
433 blacklist = NULL; 436 blacklist = NULL;
434 ret = 0; 437 ret = 0;
435 } 438 }
436} 439}
437 440
438 441
@@ -440,42 +443,42 @@ shutdown_task(void *cls)
440 * We are done, shut down. 443 * We are done, shut down.
441 */ 444 */
442static void 445static void
443operation_timeout(void *cls) 446operation_timeout (void *cls)
444{ 447{
445 struct PeerResolutionContext *cur; 448 struct PeerResolutionContext *cur;
446 struct PeerResolutionContext *next; 449 struct PeerResolutionContext *next;
447 450
448 op_timeout = NULL; 451 op_timeout = NULL;
449 if ((benchmark_send) || (benchmark_receive)) 452 if ((benchmark_send) || (benchmark_receive))
450 { 453 {
451 fprintf(stdout, _("Failed to connect to `%s'\n"), GNUNET_i2s_full(&pid)); 454 fprintf (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
452 GNUNET_SCHEDULER_shutdown(); 455 GNUNET_SCHEDULER_shutdown ();
453 ret = 1; 456 ret = 1;
454 return; 457 return;
455 } 458 }
456 if (iterate_connections) 459 if (iterate_connections)
460 {
461 next = rc_head;
462 while (NULL != (cur = next))
457 { 463 {
458 next = rc_head; 464 next = cur->next;
459 while (NULL != (cur = next)) 465 fprintf (stdout,
460 { 466 _ ("Failed to resolve address for peer `%s'\n"),
461 next = cur->next; 467 GNUNET_i2s (&cur->addrcp->peer));
462 fprintf(stdout, 468
463 _("Failed to resolve address for peer `%s'\n"), 469 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, cur);
464 GNUNET_i2s(&cur->addrcp->peer)); 470 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
465 471 GNUNET_free (cur->transport);
466 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, cur); 472 GNUNET_free (cur->addrcp);
467 GNUNET_TRANSPORT_address_to_string_cancel(cur->asc); 473 GNUNET_free (cur);
468 GNUNET_free(cur->transport);
469 GNUNET_free(cur->addrcp);
470 GNUNET_free(cur);
471 }
472 fprintf(stdout,
473 "%s",
474 _("Failed to list connections, timeout occurred\n"));
475 GNUNET_SCHEDULER_shutdown();
476 ret = 1;
477 return;
478 } 474 }
475 fprintf (stdout,
476 "%s",
477 _ ("Failed to list connections, timeout occurred\n"));
478 GNUNET_SCHEDULER_shutdown ();
479 ret = 1;
480 return;
481 }
479} 482}
480 483
481 484
@@ -486,21 +489,21 @@ operation_timeout(void *cls)
486 * @param cls closure with the message queue 489 * @param cls closure with the message queue
487 */ 490 */
488static void 491static void
489do_send(void *cls) 492do_send (void *cls)
490{ 493{
491 struct GNUNET_MQ_Handle *mq = cls; 494 struct GNUNET_MQ_Handle *mq = cls;
492 struct GNUNET_MessageHeader *m; 495 struct GNUNET_MessageHeader *m;
493 struct GNUNET_MQ_Envelope *env; 496 struct GNUNET_MQ_Envelope *env;
494 497
495 env = GNUNET_MQ_msg_extra(m, BLOCKSIZE * 1024, GNUNET_MESSAGE_TYPE_DUMMY); 498 env = GNUNET_MQ_msg_extra (m, BLOCKSIZE * 1024, GNUNET_MESSAGE_TYPE_DUMMY);
496 memset(&m[1], 52, BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader)); 499 memset (&m[1], 52, BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader));
497 traffic_sent += BLOCKSIZE * 1024; 500 traffic_sent += BLOCKSIZE * 1024;
498 GNUNET_MQ_notify_sent(env, &do_send, mq); 501 GNUNET_MQ_notify_sent (env, &do_send, mq);
499 if (verbosity > 0) 502 if (verbosity > 0)
500 fprintf(stdout, 503 fprintf (stdout,
501 _("Transmitting %u bytes\n"), 504 _ ("Transmitting %u bytes\n"),
502 (unsigned int)BLOCKSIZE * 1024); 505 (unsigned int) BLOCKSIZE * 1024);
503 GNUNET_MQ_send(mq, env); 506 GNUNET_MQ_send (mq, env);
504} 507}
505 508
506 509
@@ -513,29 +516,29 @@ do_send(void *cls)
513 * @param mq message queue for sending to @a peer 516 * @param mq message queue for sending to @a peer
514 */ 517 */
515static void * 518static void *
516notify_connect(void *cls, 519notify_connect (void *cls,
517 const struct GNUNET_PeerIdentity *peer, 520 const struct GNUNET_PeerIdentity *peer,
518 struct GNUNET_MQ_Handle *mq) 521 struct GNUNET_MQ_Handle *mq)
519{ 522{
520 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) 523 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
521 return NULL; 524 return NULL;
522 ret = 0; 525 ret = 0;
523 if (!benchmark_send) 526 if (! benchmark_send)
524 return NULL; 527 return NULL;
525 if (NULL != op_timeout) 528 if (NULL != op_timeout)
526 { 529 {
527 GNUNET_SCHEDULER_cancel(op_timeout); 530 GNUNET_SCHEDULER_cancel (op_timeout);
528 op_timeout = NULL; 531 op_timeout = NULL;
529 } 532 }
530 if (verbosity > 0) 533 if (verbosity > 0)
531 fprintf( 534 fprintf (
532 stdout, 535 stdout,
533 _( 536 _ (
534 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), 537 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
535 GNUNET_i2s(peer), 538 GNUNET_i2s (peer),
536 BLOCKSIZE); 539 BLOCKSIZE);
537 start_time = GNUNET_TIME_absolute_get(); 540 start_time = GNUNET_TIME_absolute_get ();
538 do_send(mq); 541 do_send (mq);
539 return mq; 542 return mq;
540} 543}
541 544
@@ -549,19 +552,19 @@ notify_connect(void *cls,
549 * @param internal_cls what we returned from #notify_connect() 552 * @param internal_cls what we returned from #notify_connect()
550 */ 553 */
551static void 554static void
552notify_disconnect(void *cls, 555notify_disconnect (void *cls,
553 const struct GNUNET_PeerIdentity *peer, 556 const struct GNUNET_PeerIdentity *peer,
554 void *internal_cls) 557 void *internal_cls)
555{ 558{
556 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity))) 559 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
557 return; 560 return;
558 if (NULL == internal_cls) 561 if (NULL == internal_cls)
559 return; /* not about target peer */ 562 return; /* not about target peer */
560 if (!benchmark_send) 563 if (! benchmark_send)
561 return; /* not transmitting */ 564 return; /* not transmitting */
562 fprintf(stdout, 565 fprintf (stdout,
563 _("Disconnected from peer `%s' while benchmarking\n"), 566 _ ("Disconnected from peer `%s' while benchmarking\n"),
564 GNUNET_i2s(&pid)); 567 GNUNET_i2s (&pid));
565} 568}
566 569
567 570
@@ -575,20 +578,20 @@ notify_disconnect(void *cls,
575 * @return NULL 578 * @return NULL
576 */ 579 */
577static void * 580static void *
578monitor_notify_connect(void *cls, 581monitor_notify_connect (void *cls,
579 const struct GNUNET_PeerIdentity *peer, 582 const struct GNUNET_PeerIdentity *peer,
580 struct GNUNET_MQ_Handle *mq) 583 struct GNUNET_MQ_Handle *mq)
581{ 584{
582 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 585 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
583 const char *now_str = GNUNET_STRINGS_absolute_time_to_string(now); 586 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
584 587
585 monitor_connect_counter++; 588 monitor_connect_counter++;
586 fprintf(stdout, 589 fprintf (stdout,
587 _("%24s: %-17s %4s (%u connections in total)\n"), 590 _ ("%24s: %-17s %4s (%u connections in total)\n"),
588 now_str, 591 now_str,
589 _("Connected to"), 592 _ ("Connected to"),
590 GNUNET_i2s(peer), 593 GNUNET_i2s (peer),
591 monitor_connect_counter); 594 monitor_connect_counter);
592 return NULL; 595 return NULL;
593} 596}
594 597
@@ -602,22 +605,22 @@ monitor_notify_connect(void *cls,
602 * @param internal_cls what we returned from #monitor_notify_connect() 605 * @param internal_cls what we returned from #monitor_notify_connect()
603 */ 606 */
604static void 607static void
605monitor_notify_disconnect(void *cls, 608monitor_notify_disconnect (void *cls,
606 const struct GNUNET_PeerIdentity *peer, 609 const struct GNUNET_PeerIdentity *peer,
607 void *internal_cls) 610 void *internal_cls)
608{ 611{
609 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 612 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
610 const char *now_str = GNUNET_STRINGS_absolute_time_to_string(now); 613 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
611 614
612 GNUNET_assert(monitor_connect_counter > 0); 615 GNUNET_assert (monitor_connect_counter > 0);
613 monitor_connect_counter--; 616 monitor_connect_counter--;
614 617
615 fprintf(stdout, 618 fprintf (stdout,
616 _("%24s: %-17s %4s (%u connections in total)\n"), 619 _ ("%24s: %-17s %4s (%u connections in total)\n"),
617 now_str, 620 now_str,
618 _("Disconnected from"), 621 _ ("Disconnected from"),
619 GNUNET_i2s(peer), 622 GNUNET_i2s (peer),
620 monitor_connect_counter); 623 monitor_connect_counter);
621} 624}
622 625
623 626
@@ -629,7 +632,7 @@ monitor_notify_disconnect(void *cls,
629 * @return #GNUNET_OK 632 * @return #GNUNET_OK
630 */ 633 */
631static int 634static int
632check_dummy(void *cls, const struct GNUNET_MessageHeader *message) 635check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
633{ 636{
634 return GNUNET_OK; /* all messages are fine */ 637 return GNUNET_OK; /* all messages are fine */
635} 638}
@@ -642,17 +645,17 @@ check_dummy(void *cls, const struct GNUNET_MessageHeader *message)
642 * @param message the message 645 * @param message the message
643 */ 646 */
644static void 647static void
645handle_dummy(void *cls, const struct GNUNET_MessageHeader *message) 648handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
646{ 649{
647 if (!benchmark_receive) 650 if (! benchmark_receive)
648 return; 651 return;
649 if (verbosity > 0) 652 if (verbosity > 0)
650 fprintf(stdout, 653 fprintf (stdout,
651 _("Received %u bytes\n"), 654 _ ("Received %u bytes\n"),
652 (unsigned int)ntohs(message->size)); 655 (unsigned int) ntohs (message->size));
653 if (0 == traffic_received) 656 if (0 == traffic_received)
654 start_time = GNUNET_TIME_absolute_get(); 657 start_time = GNUNET_TIME_absolute_get ();
655 traffic_received += ntohs(message->size); 658 traffic_received += ntohs (message->size);
656} 659}
657 660
658 661
@@ -666,40 +669,40 @@ handle_dummy(void *cls, const struct GNUNET_MessageHeader *message)
666 * @param state_timeout when will the peer's state expire 669 * @param state_timeout when will the peer's state expire
667 */ 670 */
668static void 671static void
669resolve_peer_address(const struct GNUNET_HELLO_Address *address, 672resolve_peer_address (const struct GNUNET_HELLO_Address *address,
670 int numeric, 673 int numeric,
671 enum GNUNET_TRANSPORT_PeerState state, 674 enum GNUNET_TRANSPORT_PeerState state,
672 struct GNUNET_TIME_Absolute state_timeout); 675 struct GNUNET_TIME_Absolute state_timeout);
673 676
674 677
675static void 678static void
676print_info(const struct GNUNET_PeerIdentity *id, 679print_info (const struct GNUNET_PeerIdentity *id,
677 const char *transport, 680 const char *transport,
678 const char *addr, 681 const char *addr,
679 enum GNUNET_TRANSPORT_PeerState state, 682 enum GNUNET_TRANSPORT_PeerState state,
680 struct GNUNET_TIME_Absolute state_timeout) 683 struct GNUNET_TIME_Absolute state_timeout)
681{ 684{
682 if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || 685 if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) ||
683 (GNUNET_YES == monitor_connections)) 686 (GNUNET_YES == monitor_connections))
684 { 687 {
685 fprintf(stdout, 688 fprintf (stdout,
686 _("Peer `%s': %s %s in state `%s' until %s\n"), 689 _ ("Peer `%s': %s %s in state `%s' until %s\n"),
687 GNUNET_i2s(id), 690 GNUNET_i2s (id),
688 (NULL == transport) ? "<none>" : transport, 691 (NULL == transport) ? "<none>" : transport,
689 (NULL == transport) ? "<none>" : addr, 692 (NULL == transport) ? "<none>" : addr,
690 GNUNET_TRANSPORT_ps2s(state), 693 GNUNET_TRANSPORT_ps2s (state),
691 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 694 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
692 } 695 }
693 else if ((GNUNET_YES == iterate_connections) && 696 else if ((GNUNET_YES == iterate_connections) &&
694 (GNUNET_TRANSPORT_is_connected(state))) 697 (GNUNET_TRANSPORT_is_connected (state)))
695 { 698 {
696 /* Only connected peers, skip state */ 699 /* Only connected peers, skip state */
697 fprintf(stdout, 700 fprintf (stdout,
698 _("Peer `%s': %s %s\n"), 701 _ ("Peer `%s': %s %s\n"),
699 GNUNET_i2s(id), 702 GNUNET_i2s (id),
700 transport, 703 transport,
701 addr); 704 addr);
702 } 705 }
703} 706}
704 707
705 708
@@ -720,82 +723,82 @@ print_info(const struct GNUNET_PeerIdentity *id,
720 * if #GNUNET_SYSERR: communication error (IPC error) 723 * if #GNUNET_SYSERR: communication error (IPC error)
721 */ 724 */
722static void 725static void
723process_peer_string(void *cls, const char *address, int res) 726process_peer_string (void *cls, const char *address, int res)
724{ 727{
725 struct PeerResolutionContext *rc = cls; 728 struct PeerResolutionContext *rc = cls;
726 729
727 if (NULL != address) 730 if (NULL != address)
731 {
732 if (GNUNET_SYSERR == res)
728 { 733 {
729 if (GNUNET_SYSERR == res) 734 fprintf (
730 { 735 stderr,
731 fprintf( 736 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
732 stderr, 737 GNUNET_i2s (&rc->addrcp->peer),
733 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", 738 rc->addrcp->transport_name,
734 GNUNET_i2s(&rc->addrcp->peer), 739 (unsigned int) rc->addrcp->address_length);
735 rc->addrcp->transport_name, 740 print_info (&rc->addrcp->peer,
736 (unsigned int)rc->addrcp->address_length); 741 rc->transport,
737 print_info(&rc->addrcp->peer, 742 NULL,
738 rc->transport, 743 rc->state,
739 NULL, 744 rc->state_timeout);
740 rc->state, 745 rc->printed = GNUNET_YES;
741 rc->state_timeout);
742 rc->printed = GNUNET_YES;
743 return;
744 }
745 if (GNUNET_OK == res)
746 {
747 print_info(&rc->addrcp->peer,
748 rc->transport,
749 address,
750 rc->state,
751 rc->state_timeout);
752 rc->printed = GNUNET_YES;
753 return; /* Wait for done call */
754 }
755 /* GNUNET_NO == res: ignore, was simply not supported */
756 return; 746 return;
757 } 747 }
748 if (GNUNET_OK == res)
749 {
750 print_info (&rc->addrcp->peer,
751 rc->transport,
752 address,
753 rc->state,
754 rc->state_timeout);
755 rc->printed = GNUNET_YES;
756 return; /* Wait for done call */
757 }
758 /* GNUNET_NO == res: ignore, was simply not supported */
759 return;
760 }
758 /* NULL == address, last call, we are done */ 761 /* NULL == address, last call, we are done */
759 762
760 rc->asc = NULL; 763 rc->asc = NULL;
761 GNUNET_assert(address_resolutions > 0); 764 GNUNET_assert (address_resolutions > 0);
762 address_resolutions--; 765 address_resolutions--;
763 if (GNUNET_NO == rc->printed) 766 if (GNUNET_NO == rc->printed)
767 {
768 if (numeric == GNUNET_NO)
764 { 769 {
765 if (numeric == GNUNET_NO) 770 /* Failed to resolve address, try numeric lookup
766 { 771 (note: this should not be needed, as transport
767 /* Failed to resolve address, try numeric lookup 772 should fallback to numeric conversion if DNS takes
768 (note: this should not be needed, as transport 773 too long) */
769 should fallback to numeric conversion if DNS takes 774 resolve_peer_address (rc->addrcp,
770 too long) */ 775 GNUNET_YES,
771 resolve_peer_address(rc->addrcp, 776 rc->state,
772 GNUNET_YES, 777 rc->state_timeout);
773 rc->state,
774 rc->state_timeout);
775 }
776 else
777 {
778 print_info(&rc->addrcp->peer,
779 rc->transport,
780 NULL,
781 rc->state,
782 rc->state_timeout);
783 }
784 } 778 }
785 GNUNET_free(rc->transport); 779 else
786 GNUNET_free(rc->addrcp); 780 {
787 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc); 781 print_info (&rc->addrcp->peer,
788 GNUNET_free(rc); 782 rc->transport,
783 NULL,
784 rc->state,
785 rc->state_timeout);
786 }
787 }
788 GNUNET_free (rc->transport);
789 GNUNET_free (rc->addrcp);
790 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc);
791 GNUNET_free (rc);
789 if ((0 == address_resolutions) && (iterate_connections)) 792 if ((0 == address_resolutions) && (iterate_connections))
793 {
794 if (NULL != op_timeout)
790 { 795 {
791 if (NULL != op_timeout) 796 GNUNET_SCHEDULER_cancel (op_timeout);
792 { 797 op_timeout = NULL;
793 GNUNET_SCHEDULER_cancel(op_timeout);
794 op_timeout = NULL;
795 }
796 ret = 0;
797 GNUNET_SCHEDULER_shutdown();
798 } 798 }
799 ret = 0;
800 GNUNET_SCHEDULER_shutdown ();
801 }
799} 802}
800 803
801 804
@@ -810,28 +813,28 @@ process_peer_string(void *cls, const char *address, int res)
810 * @param state_timeout when will the peer's state expire 813 * @param state_timeout when will the peer's state expire
811 */ 814 */
812static void 815static void
813resolve_peer_address(const struct GNUNET_HELLO_Address *address, 816resolve_peer_address (const struct GNUNET_HELLO_Address *address,
814 int numeric, 817 int numeric,
815 enum GNUNET_TRANSPORT_PeerState state, 818 enum GNUNET_TRANSPORT_PeerState state,
816 struct GNUNET_TIME_Absolute state_timeout) 819 struct GNUNET_TIME_Absolute state_timeout)
817{ 820{
818 struct PeerResolutionContext *rc; 821 struct PeerResolutionContext *rc;
819 822
820 rc = GNUNET_new(struct PeerResolutionContext); 823 rc = GNUNET_new (struct PeerResolutionContext);
821 GNUNET_CONTAINER_DLL_insert(rc_head, rc_tail, rc); 824 GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc);
822 address_resolutions++; 825 address_resolutions++;
823 rc->transport = GNUNET_strdup(address->transport_name); 826 rc->transport = GNUNET_strdup (address->transport_name);
824 rc->addrcp = GNUNET_HELLO_address_copy(address); 827 rc->addrcp = GNUNET_HELLO_address_copy (address);
825 rc->printed = GNUNET_NO; 828 rc->printed = GNUNET_NO;
826 rc->state = state; 829 rc->state = state;
827 rc->state_timeout = state_timeout; 830 rc->state_timeout = state_timeout;
828 /* Resolve address to string */ 831 /* Resolve address to string */
829 rc->asc = GNUNET_TRANSPORT_address_to_string(cfg, 832 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
830 address, 833 address,
831 numeric, 834 numeric,
832 RESOLUTION_TIMEOUT, 835 RESOLUTION_TIMEOUT,
833 &process_peer_string, 836 &process_peer_string,
834 rc); 837 rc);
835} 838}
836 839
837 840
@@ -846,44 +849,45 @@ resolve_peer_address(const struct GNUNET_HELLO_Address *address,
846 * @param state_timeout time out for the current state 849 * @param state_timeout time out for the current state
847 */ 850 */
848static void 851static void
849process_peer_iteration_cb(void *cls, 852process_peer_iteration_cb (void *cls,
850 const struct GNUNET_PeerIdentity *peer, 853 const struct GNUNET_PeerIdentity *peer,
851 const struct GNUNET_HELLO_Address *address, 854 const struct GNUNET_HELLO_Address *address,
852 enum GNUNET_TRANSPORT_PeerState state, 855 enum GNUNET_TRANSPORT_PeerState state,
853 struct GNUNET_TIME_Absolute state_timeout) 856 struct GNUNET_TIME_Absolute state_timeout)
854{ 857{
855 if (NULL == peer) 858 if (NULL == peer)
856 { 859 {
857 /* done */ 860 /* done */
858 pic = NULL; 861 pic = NULL;
859 return; 862 return;
860 } 863 }
861 864
862 if ((GNUNET_NO == iterate_all) && 865 if ((GNUNET_NO == iterate_all) &&
863 (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state))) 866 (GNUNET_NO == GNUNET_TRANSPORT_is_connected (state)))
864 return; /* Display only connected peers */ 867 return; /* Display only connected peers */
865 868
866 if (NULL != op_timeout) 869 if (NULL != op_timeout)
867 GNUNET_SCHEDULER_cancel(op_timeout); 870 GNUNET_SCHEDULER_cancel (op_timeout);
868 op_timeout = 871 op_timeout =
869 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL); 872 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
870 873
871 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
872 "Received address for peer `%s': %s\n", 875 "Received address for peer `%s': %s\n",
873 GNUNET_i2s(peer), 876 GNUNET_i2s (peer),
874 address ? address->transport_name : ""); 877 address ? address->transport_name : "");
875 878
876 if (NULL != address) 879 if (NULL != address)
877 resolve_peer_address(address, numeric, state, state_timeout); 880 resolve_peer_address (address, numeric, state, state_timeout);
878 else 881 else
879 print_info(peer, NULL, NULL, state, state_timeout); 882 print_info (peer, NULL, NULL, state, state_timeout);
880} 883}
881 884
882 885
883/** 886/**
884 * Context for address resolution by #plugin_monitoring_cb(). 887 * Context for address resolution by #plugin_monitoring_cb().
885 */ 888 */
886struct PluginMonitorAddress { 889struct PluginMonitorAddress
890{
887 /** 891 /**
888 * Ongoing resolution request. 892 * Ongoing resolution request.
889 */ 893 */
@@ -909,57 +913,57 @@ struct PluginMonitorAddress {
909 * @param info the monitoring information 913 * @param info the monitoring information
910 */ 914 */
911static void 915static void
912print_plugin_event_info(struct PluginMonitorAddress *addr, 916print_plugin_event_info (struct PluginMonitorAddress *addr,
913 const struct GNUNET_TRANSPORT_SessionInfo *info) 917 const struct GNUNET_TRANSPORT_SessionInfo *info)
914{ 918{
915 const char *state; 919 const char *state;
916 920
917 switch (info->state) 921 switch (info->state)
918 { 922 {
919 case GNUNET_TRANSPORT_SS_INIT: 923 case GNUNET_TRANSPORT_SS_INIT:
920 state = "INIT"; 924 state = "INIT";
921 break; 925 break;
922 926
923 case GNUNET_TRANSPORT_SS_HANDSHAKE: 927 case GNUNET_TRANSPORT_SS_HANDSHAKE:
924 state = "HANDSHAKE"; 928 state = "HANDSHAKE";
925 break; 929 break;
926 930
927 case GNUNET_TRANSPORT_SS_UP: 931 case GNUNET_TRANSPORT_SS_UP:
928 state = "UP"; 932 state = "UP";
929 break; 933 break;
930 934
931 case GNUNET_TRANSPORT_SS_UPDATE: 935 case GNUNET_TRANSPORT_SS_UPDATE:
932 state = "UPDATE"; 936 state = "UPDATE";
933 break; 937 break;
934 938
935 case GNUNET_TRANSPORT_SS_DONE: 939 case GNUNET_TRANSPORT_SS_DONE:
936 state = "DONE"; 940 state = "DONE";
937 break; 941 break;
938 942
939 default: 943 default:
940 state = "UNKNOWN"; 944 state = "UNKNOWN";
941 break; 945 break;
942 } 946 }
943 fprintf(stdout, 947 fprintf (stdout,
944 "%s: state %s timeout in %s @ %s%s\n", 948 "%s: state %s timeout in %s @ %s%s\n",
945 GNUNET_i2s(&info->address->peer), 949 GNUNET_i2s (&info->address->peer),
946 state, 950 state,
947 GNUNET_STRINGS_relative_time_to_string( 951 GNUNET_STRINGS_relative_time_to_string (
948 GNUNET_TIME_absolute_get_remaining(info->session_timeout), 952 GNUNET_TIME_absolute_get_remaining (info->session_timeout),
949 GNUNET_YES), 953 GNUNET_YES),
950 addr->str, 954 addr->str,
951 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : ""); 955 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
952 fprintf(stdout, 956 fprintf (stdout,
953 "%s: queue has %3u messages and %6u bytes\n", 957 "%s: queue has %3u messages and %6u bytes\n",
954 GNUNET_i2s(&info->address->peer), 958 GNUNET_i2s (&info->address->peer),
955 info->num_msg_pending, 959 info->num_msg_pending,
956 info->num_bytes_pending); 960 info->num_bytes_pending);
957 if (0 != 961 if (0 !=
958 GNUNET_TIME_absolute_get_remaining(info->receive_delay).rel_value_us) 962 GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us)
959 fprintf(stdout, 963 fprintf (stdout,
960 "%s: receiving blocked until %s\n", 964 "%s: receiving blocked until %s\n",
961 GNUNET_i2s(&info->address->peer), 965 GNUNET_i2s (&info->address->peer),
962 GNUNET_STRINGS_absolute_time_to_string(info->receive_delay)); 966 GNUNET_STRINGS_absolute_time_to_string (info->receive_delay));
963} 967}
964 968
965 969
@@ -980,19 +984,19 @@ print_plugin_event_info(struct PluginMonitorAddress *addr,
980 * if #GNUNET_SYSERR: communication error (IPC error) 984 * if #GNUNET_SYSERR: communication error (IPC error)
981 */ 985 */
982static void 986static void
983address_cb(void *cls, const char *address, int res) 987address_cb (void *cls, const char *address, int res)
984{ 988{
985 struct PluginMonitorAddress *addr = cls; 989 struct PluginMonitorAddress *addr = cls;
986 990
987 if (NULL == address) 991 if (NULL == address)
988 { 992 {
989 addr->asc = NULL; 993 addr->asc = NULL;
990 return; 994 return;
991 } 995 }
992 if (NULL != addr->str) 996 if (NULL != addr->str)
993 return; 997 return;
994 addr->str = GNUNET_strdup(address); 998 addr->str = GNUNET_strdup (address);
995 print_plugin_event_info(addr, &addr->si); 999 print_plugin_event_info (addr, &addr->si);
996} 1000}
997 1001
998 1002
@@ -1014,10 +1018,10 @@ address_cb(void *cls, const char *address, int res)
1014 * was being cancelled while sessions were active 1018 * was being cancelled while sessions were active
1015 */ 1019 */
1016static void 1020static void
1017plugin_monitoring_cb(void *cls, 1021plugin_monitoring_cb (void *cls,
1018 struct GNUNET_TRANSPORT_PluginSession *session, 1022 struct GNUNET_TRANSPORT_PluginSession *session,
1019 void **session_ctx, 1023 void **session_ctx,
1020 const struct GNUNET_TRANSPORT_SessionInfo *info) 1024 const struct GNUNET_TRANSPORT_SessionInfo *info)
1021{ 1025{
1022 struct PluginMonitorAddress *addr; 1026 struct PluginMonitorAddress *addr;
1023 1027
@@ -1025,50 +1029,50 @@ plugin_monitoring_cb(void *cls,
1025 return; /* in sync with transport service */ 1029 return; /* in sync with transport service */
1026 addr = *session_ctx; 1030 addr = *session_ctx;
1027 if (NULL == info) 1031 if (NULL == info)
1032 {
1033 if (NULL != addr)
1028 { 1034 {
1029 if (NULL != addr) 1035 if (NULL != addr->asc)
1030 { 1036 {
1031 if (NULL != addr->asc) 1037 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1032 { 1038 addr->asc = NULL;
1033 GNUNET_TRANSPORT_address_to_string_cancel(addr->asc); 1039 }
1034 addr->asc = NULL; 1040 GNUNET_free_non_null (addr->str);
1035 } 1041 GNUNET_free (addr);
1036 GNUNET_free_non_null(addr->str); 1042 *session_ctx = NULL;
1037 GNUNET_free(addr);
1038 *session_ctx = NULL;
1039 }
1040 return; /* shutdown */
1041 } 1043 }
1044 return; /* shutdown */
1045 }
1042 if (0 != 1046 if (0 !=
1043 memcmp(&info->address->peer, &pid, sizeof(struct GNUNET_PeerIdentity))) 1047 memcmp (&info->address->peer, &pid, sizeof(struct GNUNET_PeerIdentity)))
1044 return; /* filtered */ 1048 return; /* filtered */
1045 if (NULL == addr) 1049 if (NULL == addr)
1046 { 1050 {
1047 addr = GNUNET_new(struct PluginMonitorAddress); 1051 addr = GNUNET_new (struct PluginMonitorAddress);
1048 addr->asc = 1052 addr->asc =
1049 GNUNET_TRANSPORT_address_to_string(cfg, 1053 GNUNET_TRANSPORT_address_to_string (cfg,
1050 info->address, 1054 info->address,
1051 numeric, 1055 numeric,
1052 GNUNET_TIME_UNIT_FOREVER_REL, 1056 GNUNET_TIME_UNIT_FOREVER_REL,
1053 &address_cb, 1057 &address_cb,
1054 addr); 1058 addr);
1055 *session_ctx = addr; 1059 *session_ctx = addr;
1056 } 1060 }
1057 if (NULL == addr->str) 1061 if (NULL == addr->str)
1058 addr->si = *info; 1062 addr->si = *info;
1059 else 1063 else
1060 print_plugin_event_info(addr, info); 1064 print_plugin_event_info (addr, info);
1061 if (GNUNET_TRANSPORT_SS_DONE == info->state) 1065 if (GNUNET_TRANSPORT_SS_DONE == info->state)
1066 {
1067 if (NULL != addr->asc)
1062 { 1068 {
1063 if (NULL != addr->asc) 1069 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1064 { 1070 addr->asc = NULL;
1065 GNUNET_TRANSPORT_address_to_string_cancel(addr->asc);
1066 addr->asc = NULL;
1067 }
1068 GNUNET_free_non_null(addr->str);
1069 GNUNET_free(addr);
1070 *session_ctx = NULL;
1071 } 1071 }
1072 GNUNET_free_non_null (addr->str);
1073 GNUNET_free (addr);
1074 *session_ctx = NULL;
1075 }
1072} 1076}
1073 1077
1074 1078
@@ -1083,64 +1087,64 @@ plugin_monitoring_cb(void *cls,
1083 * @param state_timeout time out for the current state 1087 * @param state_timeout time out for the current state
1084 */ 1088 */
1085static void 1089static void
1086process_peer_monitoring_cb(void *cls, 1090process_peer_monitoring_cb (void *cls,
1087 const struct GNUNET_PeerIdentity *peer, 1091 const struct GNUNET_PeerIdentity *peer,
1088 const struct GNUNET_HELLO_Address *address, 1092 const struct GNUNET_HELLO_Address *address,
1089 enum GNUNET_TRANSPORT_PeerState state, 1093 enum GNUNET_TRANSPORT_PeerState state,
1090 struct GNUNET_TIME_Absolute state_timeout) 1094 struct GNUNET_TIME_Absolute state_timeout)
1091{ 1095{
1092 struct MonitoredPeer *m; 1096 struct MonitoredPeer *m;
1093 1097
1094 if (NULL == peer) 1098 if (NULL == peer)
1095 { 1099 {
1096 fprintf(stdout, 1100 fprintf (stdout,
1097 "%s", 1101 "%s",
1098 _( 1102 _ (
1099 "Monitor disconnected from transport service. Reconnecting.\n")); 1103 "Monitor disconnected from transport service. Reconnecting.\n"));
1100 return; 1104 return;
1101 } 1105 }
1102 1106
1103 if (NULL != op_timeout) 1107 if (NULL != op_timeout)
1104 GNUNET_SCHEDULER_cancel(op_timeout); 1108 GNUNET_SCHEDULER_cancel (op_timeout);
1105 op_timeout = 1109 op_timeout =
1106 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL); 1110 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
1107 1111
1108 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get(monitored_peers, peer))) 1112 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer)))
1109 { 1113 {
1110 m = GNUNET_new(struct MonitoredPeer); 1114 m = GNUNET_new (struct MonitoredPeer);
1111 GNUNET_CONTAINER_multipeermap_put( 1115 GNUNET_CONTAINER_multipeermap_put (
1112 monitored_peers, 1116 monitored_peers,
1113 peer, 1117 peer,
1114 m, 1118 m,
1115 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1119 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1116 } 1120 }
1117 else 1121 else
1122 {
1123 if ((m->state == state) &&
1124 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1125 (NULL == address) && (NULL == m->address))
1118 { 1126 {
1119 if ((m->state == state) && 1127 return; /* No real change */
1120 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1121 (NULL == address) && (NULL == m->address))
1122 {
1123 return; /* No real change */
1124 }
1125 if ((m->state == state) && (NULL != address) && (NULL != m->address) &&
1126 (0 == GNUNET_HELLO_address_cmp(m->address, address)))
1127 return; /* No real change */
1128 } 1128 }
1129 if ((m->state == state) && (NULL != address) && (NULL != m->address) &&
1130 (0 == GNUNET_HELLO_address_cmp (m->address, address)))
1131 return; /* No real change */
1132 }
1129 1133
1130 if (NULL != m->address) 1134 if (NULL != m->address)
1131 { 1135 {
1132 GNUNET_free(m->address); 1136 GNUNET_free (m->address);
1133 m->address = NULL; 1137 m->address = NULL;
1134 } 1138 }
1135 if (NULL != address) 1139 if (NULL != address)
1136 m->address = GNUNET_HELLO_address_copy(address); 1140 m->address = GNUNET_HELLO_address_copy (address);
1137 m->state = state; 1141 m->state = state;
1138 m->state_timeout = state_timeout; 1142 m->state_timeout = state_timeout;
1139 1143
1140 if (NULL != address) 1144 if (NULL != address)
1141 resolve_peer_address(m->address, numeric, m->state, m->state_timeout); 1145 resolve_peer_address (m->address, numeric, m->state, m->state_timeout);
1142 else 1146 else
1143 print_info(peer, NULL, NULL, m->state, m->state_timeout); 1147 print_info (peer, NULL, NULL, m->state, m->state_timeout);
1144} 1148}
1145 1149
1146 1150
@@ -1154,9 +1158,9 @@ process_peer_monitoring_cb(void *cls,
1154 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not 1158 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
1155 */ 1159 */
1156static int 1160static int
1157blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *cpid) 1161blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *cpid)
1158{ 1162{
1159 if (0 == memcmp(cpid, &pid, sizeof(struct GNUNET_PeerIdentity))) 1163 if (0 == memcmp (cpid, &pid, sizeof(struct GNUNET_PeerIdentity)))
1160 return GNUNET_SYSERR; 1164 return GNUNET_SYSERR;
1161 return GNUNET_OK; 1165 return GNUNET_OK;
1162} 1166}
@@ -1171,259 +1175,259 @@ blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *cpid)
1171 * @param mycfg configuration 1175 * @param mycfg configuration
1172 */ 1176 */
1173static void 1177static void
1174run(void *cls, 1178run (void *cls,
1175 char *const *args, 1179 char *const *args,
1176 const char *cfgfile, 1180 const char *cfgfile,
1177 const struct GNUNET_CONFIGURATION_Handle *mycfg) 1181 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1178{ 1182{
1179 static struct GNUNET_PeerIdentity zero_pid; 1183 static struct GNUNET_PeerIdentity zero_pid;
1180 int counter = 0; 1184 int counter = 0;
1181 1185
1182 ret = 1; 1186 ret = 1;
1183 1187
1184 cfg = (struct GNUNET_CONFIGURATION_Handle *)mycfg; 1188 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1185 1189
1186 counter = benchmark_send + benchmark_receive + iterate_connections + 1190 counter = benchmark_send + benchmark_receive + iterate_connections
1187 monitor_connections + monitor_connects + do_disconnect + 1191 + monitor_connections + monitor_connects + do_disconnect
1188 monitor_plugins; 1192 + monitor_plugins;
1189 1193
1190 if (1 < counter) 1194 if (1 < counter)
1195 {
1196 fprintf (
1197 stderr,
1198 _ (
1199 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1200 "disconnect",
1201 "benchmark send",
1202 "benchmark receive",
1203 "information",
1204 "monitor",
1205 "events",
1206 "plugins");
1207 return;
1208 }
1209 if (0 == counter)
1210 {
1211 fprintf (
1212 stderr,
1213 _ (
1214 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1215 "disconnect",
1216 "benchmark send",
1217 "benchmark receive",
1218 "information",
1219 "monitor",
1220 "events",
1221 "plugins");
1222 return;
1223 }
1224
1225 if (do_disconnect) /* -D: Disconnect from peer */
1226 {
1227 if (0 == memcmp (&zero_pid, &pid, sizeof(pid)))
1191 { 1228 {
1192 fprintf( 1229 fprintf (stderr,
1193 stderr, 1230 _ ("Option `%s' makes no sense without option `%s'.\n"),
1194 _( 1231 "-D",
1195 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"), 1232 "-p");
1196 "disconnect", 1233 ret = 1;
1197 "benchmark send",
1198 "benchmark receive",
1199 "information",
1200 "monitor",
1201 "events",
1202 "plugins");
1203 return; 1234 return;
1204 } 1235 }
1205 if (0 == counter) 1236 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
1237 if (NULL == blacklist)
1206 { 1238 {
1207 fprintf( 1239 fprintf (stderr,
1208 stderr, 1240 "%s",
1209 _( 1241 _ (
1210 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"), 1242 "Failed to connect to transport service for disconnection\n"));
1211 "disconnect", 1243 ret = 1;
1212 "benchmark send",
1213 "benchmark receive",
1214 "information",
1215 "monitor",
1216 "events",
1217 "plugins");
1218 return; 1244 return;
1219 } 1245 }
1220 1246 fprintf (stdout,
1221 if (do_disconnect) /* -D: Disconnect from peer */ 1247 "%s",
1248 _ ("Blacklisting request in place, stop with CTRL-C\n"));
1249 }
1250 else if (benchmark_send) /* -s: Benchmark sending */
1251 {
1252 if (0 == memcmp (&zero_pid, &pid, sizeof(pid)))
1222 { 1253 {
1223 if (0 == memcmp(&zero_pid, &pid, sizeof(pid))) 1254 fprintf (stderr,
1224 { 1255 _ ("Option `%s' makes no sense without option `%s'.\n"),
1225 fprintf(stderr, 1256 "-s",
1226 _("Option `%s' makes no sense without option `%s'.\n"), 1257 "-p");
1227 "-D", 1258 ret = 1;
1228 "-p"); 1259 return;
1229 ret = 1;
1230 return;
1231 }
1232 blacklist = GNUNET_TRANSPORT_blacklist(cfg, &blacklist_cb, NULL);
1233 if (NULL == blacklist)
1234 {
1235 fprintf(stderr,
1236 "%s",
1237 _(
1238 "Failed to connect to transport service for disconnection\n"));
1239 ret = 1;
1240 return;
1241 }
1242 fprintf(stdout,
1243 "%s",
1244 _("Blacklisting request in place, stop with CTRL-C\n"));
1245 } 1260 }
1246 else if (benchmark_send) /* -s: Benchmark sending */ 1261 handle = GNUNET_TRANSPORT_core_connect (cfg,
1262 NULL,
1263 NULL,
1264 NULL,
1265 &notify_connect,
1266 &notify_disconnect,
1267 NULL);
1268 if (NULL == handle)
1247 { 1269 {
1248 if (0 == memcmp(&zero_pid, &pid, sizeof(pid))) 1270 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1249 { 1271 ret = 1;
1250 fprintf(stderr, 1272 return;
1251 _("Option `%s' makes no sense without option `%s'.\n"),
1252 "-s",
1253 "-p");
1254 ret = 1;
1255 return;
1256 }
1257 handle = GNUNET_TRANSPORT_core_connect(cfg,
1258 NULL,
1259 NULL,
1260 NULL,
1261 &notify_connect,
1262 &notify_disconnect,
1263 NULL);
1264 if (NULL == handle)
1265 {
1266 fprintf(stderr, "%s", _("Failed to connect to transport service\n"));
1267 ret = 1;
1268 return;
1269 }
1270 start_time = GNUNET_TIME_absolute_get();
1271 op_timeout =
1272 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL);
1273 } 1273 }
1274 start_time = GNUNET_TIME_absolute_get ();
1275 op_timeout =
1276 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
1277 }
1274 else if (benchmark_receive) /* -b: Benchmark receiving */ 1278 else if (benchmark_receive) /* -b: Benchmark receiving */
1279 {
1280 struct GNUNET_MQ_MessageHandler handlers[] =
1281 { GNUNET_MQ_hd_var_size (dummy,
1282 GNUNET_MESSAGE_TYPE_DUMMY,
1283 struct GNUNET_MessageHeader,
1284 NULL),
1285 GNUNET_MQ_handler_end () };
1286
1287 handle = GNUNET_TRANSPORT_core_connect (cfg,
1288 NULL,
1289 handlers,
1290 NULL,
1291 NULL,
1292 NULL,
1293 NULL);
1294 if (NULL == handle)
1275 { 1295 {
1276 struct GNUNET_MQ_MessageHandler handlers[] = 1296 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1277 { GNUNET_MQ_hd_var_size(dummy, 1297 ret = 1;
1278 GNUNET_MESSAGE_TYPE_DUMMY, 1298 return;
1279 struct GNUNET_MessageHeader,
1280 NULL),
1281 GNUNET_MQ_handler_end() };
1282
1283 handle = GNUNET_TRANSPORT_core_connect(cfg,
1284 NULL,
1285 handlers,
1286 NULL,
1287 NULL,
1288 NULL,
1289 NULL);
1290 if (NULL == handle)
1291 {
1292 fprintf(stderr, "%s", _("Failed to connect to transport service\n"));
1293 ret = 1;
1294 return;
1295 }
1296 if (verbosity > 0)
1297 fprintf(stdout, "%s", _("Starting to receive benchmark data\n"));
1298 start_time = GNUNET_TIME_absolute_get();
1299 } 1299 }
1300 if (verbosity > 0)
1301 fprintf (stdout, "%s", _ ("Starting to receive benchmark data\n"));
1302 start_time = GNUNET_TIME_absolute_get ();
1303 }
1300 else if (iterate_connections) /* -i: List information about peers once */ 1304 else if (iterate_connections) /* -i: List information about peers once */
1301 { 1305 {
1302 pic = GNUNET_TRANSPORT_monitor_peers(cfg, 1306 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1303 &pid, 1307 &pid,
1304 GNUNET_YES, 1308 GNUNET_YES,
1305 &process_peer_iteration_cb, 1309 &process_peer_iteration_cb,
1306 (void *)cfg); 1310 (void *) cfg);
1307 op_timeout = 1311 op_timeout =
1308 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL); 1312 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
1309 } 1313 }
1310 else if (monitor_connections) /* -m: List information about peers continuously 1314 else if (monitor_connections) /* -m: List information about peers continuously
1311 */ 1315 */
1312 { 1316 {
1313 monitored_peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); 1317 monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1314 pic = GNUNET_TRANSPORT_monitor_peers(cfg, 1318 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1315 &pid, 1319 &pid,
1316 GNUNET_NO, 1320 GNUNET_NO,
1317 &process_peer_monitoring_cb, 1321 &process_peer_monitoring_cb,
1318 NULL); 1322 NULL);
1319 } 1323 }
1320 else if (monitor_plugins) /* -P: List information about plugins continuously 1324 else if (monitor_plugins) /* -P: List information about plugins continuously
1321 */ 1325 */
1322 { 1326 {
1323 monitored_plugins = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); 1327 monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1324 pm = GNUNET_TRANSPORT_monitor_plugins(cfg, &plugin_monitoring_cb, NULL); 1328 pm = GNUNET_TRANSPORT_monitor_plugins (cfg, &plugin_monitoring_cb, NULL);
1325 } 1329 }
1326 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ 1330 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1331 {
1332 monitor_connect_counter = 0;
1333 handle = GNUNET_TRANSPORT_core_connect (cfg,
1334 NULL,
1335 NULL,
1336 NULL,
1337 &monitor_notify_connect,
1338 &monitor_notify_disconnect,
1339 NULL);
1340 if (NULL == handle)
1327 { 1341 {
1328 monitor_connect_counter = 0; 1342 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1329 handle = GNUNET_TRANSPORT_core_connect(cfg, 1343 ret = 1;
1330 NULL,
1331 NULL,
1332 NULL,
1333 &monitor_notify_connect,
1334 &monitor_notify_disconnect,
1335 NULL);
1336 if (NULL == handle)
1337 {
1338 fprintf(stderr, "%s", _("Failed to connect to transport service\n"));
1339 ret = 1;
1340 return;
1341 }
1342 ret = 0;
1343 }
1344 else
1345 {
1346 GNUNET_break(0);
1347 return; 1344 return;
1348 } 1345 }
1346 ret = 0;
1347 }
1348 else
1349 {
1350 GNUNET_break (0);
1351 return;
1352 }
1349 1353
1350 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 1354 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1351} 1355}
1352 1356
1353 1357
1354int 1358int
1355main(int argc, char *const *argv) 1359main (int argc, char *const *argv)
1356{ 1360{
1357 int res; 1361 int res;
1358 struct GNUNET_GETOPT_CommandLineOption options[] = 1362 struct GNUNET_GETOPT_CommandLineOption options[] =
1359 { GNUNET_GETOPT_option_flag( 1363 { GNUNET_GETOPT_option_flag (
1360 'a', 1364 'a',
1361 "all", 1365 "all",
1362 gettext_noop( 1366 gettext_noop (
1363 "print information for all peers (instead of only connected peers)"), 1367 "print information for all peers (instead of only connected peers)"),
1364 &iterate_all), 1368 &iterate_all),
1365 GNUNET_GETOPT_option_flag( 1369 GNUNET_GETOPT_option_flag (
1366 'b', 1370 'b',
1367 "benchmark", 1371 "benchmark",
1368 gettext_noop( 1372 gettext_noop (
1369 "measure how fast we are receiving data from all peers (until CTRL-C)"), 1373 "measure how fast we are receiving data from all peers (until CTRL-C)"),
1370 &benchmark_receive), 1374 &benchmark_receive),
1371 GNUNET_GETOPT_option_flag('D', 1375 GNUNET_GETOPT_option_flag ('D',
1372 "disconnect", 1376 "disconnect",
1373 gettext_noop("disconnect from a peer"), 1377 gettext_noop ("disconnect from a peer"),
1374 &do_disconnect), 1378 &do_disconnect),
1375 GNUNET_GETOPT_option_flag( 1379 GNUNET_GETOPT_option_flag (
1376 'i', 1380 'i',
1377 "information", 1381 "information",
1378 gettext_noop( 1382 gettext_noop (
1379 "provide information about all current connections (once)"), 1383 "provide information about all current connections (once)"),
1380 &iterate_connections), 1384 &iterate_connections),
1381 GNUNET_GETOPT_option_flag( 1385 GNUNET_GETOPT_option_flag (
1382 'm', 1386 'm',
1383 "monitor", 1387 "monitor",
1384 gettext_noop( 1388 gettext_noop (
1385 "provide information about all current connections (continuously)"), 1389 "provide information about all current connections (continuously)"),
1386 &monitor_connections), 1390 &monitor_connections),
1387 GNUNET_GETOPT_option_flag( 1391 GNUNET_GETOPT_option_flag (
1388 'e', 1392 'e',
1389 "events", 1393 "events",
1390 gettext_noop( 1394 gettext_noop (
1391 "provide information about all connects and disconnect events (continuously)"), 1395 "provide information about all connects and disconnect events (continuously)"),
1392 &monitor_connects), 1396 &monitor_connects),
1393 GNUNET_GETOPT_option_flag('n', 1397 GNUNET_GETOPT_option_flag ('n',
1394 "numeric", 1398 "numeric",
1395 gettext_noop("do not resolve hostnames"), 1399 gettext_noop ("do not resolve hostnames"),
1396 &numeric), 1400 &numeric),
1397 GNUNET_GETOPT_option_base32_auto('p', 1401 GNUNET_GETOPT_option_base32_auto ('p',
1398 "peer", 1402 "peer",
1399 "PEER", 1403 "PEER",
1400 gettext_noop("peer identity"), 1404 gettext_noop ("peer identity"),
1401 &pid), 1405 &pid),
1402 GNUNET_GETOPT_option_flag('P', 1406 GNUNET_GETOPT_option_flag ('P',
1403 "plugins", 1407 "plugins",
1404 gettext_noop("monitor plugin sessions"), 1408 gettext_noop ("monitor plugin sessions"),
1405 &monitor_plugins), 1409 &monitor_plugins),
1406 GNUNET_GETOPT_option_flag( 1410 GNUNET_GETOPT_option_flag (
1407 's', 1411 's',
1408 "send", 1412 "send",
1409 gettext_noop( 1413 gettext_noop (
1410 "send data for benchmarking to the other peer (until CTRL-C)"), 1414 "send data for benchmarking to the other peer (until CTRL-C)"),
1411 &benchmark_send), 1415 &benchmark_send),
1412 GNUNET_GETOPT_option_verbose(&verbosity), 1416 GNUNET_GETOPT_option_verbose (&verbosity),
1413 GNUNET_GETOPT_OPTION_END }; 1417 GNUNET_GETOPT_OPTION_END };
1414 1418
1415 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 1419 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1416 return 2; 1420 return 2;
1417 1421
1418 res = 1422 res =
1419 GNUNET_PROGRAM_run(argc, 1423 GNUNET_PROGRAM_run (argc,
1420 argv, 1424 argv,
1421 "gnunet-transport", 1425 "gnunet-transport",
1422 gettext_noop("Direct access to transport service."), 1426 gettext_noop ("Direct access to transport service."),
1423 options, 1427 options,
1424 &run, 1428 &run,
1425 NULL); 1429 NULL);
1426 GNUNET_free((void *)argv); 1430 GNUNET_free ((void *) argv);
1427 if (GNUNET_OK == res) 1431 if (GNUNET_OK == res)
1428 return ret; 1432 return ret;
1429 return 1; 1433 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 @@
61 * The radio capture header precedes the 802.11 header. 61 * The radio capture header precedes the 802.11 header.
62 * All data in the header is little endian on all platforms. 62 * All data in the header is little endian on all platforms.
63 */ 63 */
64struct ieee80211_radiotap_header { 64struct ieee80211_radiotap_header
65{
65 u8 it_version; /* Version 0. Only increases 66 u8 it_version; /* Version 0. Only increases
66 * for drastic changes, 67 * for drastic changes,
67 * introduction of compatible 68 * introduction of compatible
@@ -179,7 +180,8 @@ struct ieee80211_radiotap_header {
179 * Number of unicast retries a transmitted frame used. 180 * Number of unicast retries a transmitted frame used.
180 * 181 *
181 */ 182 */
182enum ieee80211_radiotap_type { 183enum ieee80211_radiotap_type
184{
183 IEEE80211_RADIOTAP_TSFT = 0, 185 IEEE80211_RADIOTAP_TSFT = 0,
184 IEEE80211_RADIOTAP_FLAGS = 1, 186 IEEE80211_RADIOTAP_FLAGS = 1,
185 IEEE80211_RADIOTAP_RATE = 2, 187 IEEE80211_RADIOTAP_RATE = 2,
@@ -255,19 +257,19 @@ enum ieee80211_radiotap_type {
255 257
256/* helpers */ 258/* helpers */
257static inline u16 259static inline u16
258get_unaligned_le16(const u8 *p) 260get_unaligned_le16 (const u8 *p)
259{ 261{
260 return p[0] | p[1] << 8; 262 return p[0] | p[1] << 8;
261} 263}
262 264
263 265
264static inline int 266static inline int
265ieee80211_get_radiotap_len(unsigned char *data) 267ieee80211_get_radiotap_len (unsigned char *data)
266{ 268{
267 struct ieee80211_radiotap_header *hdr = 269 struct ieee80211_radiotap_header *hdr =
268 (struct ieee80211_radiotap_header *)data; 270 (struct ieee80211_radiotap_header *) data;
269 271
270 return get_unaligned_le16((const u8 *)&hdr->it_len); 272 return get_unaligned_le16 ((const u8 *) &hdr->it_len);
271} 273}
272 274
273#endif /* IEEE80211_RADIOTAP_H */ 275#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 @@
62#define OUTBOUND GNUNET_NO 62#define OUTBOUND GNUNET_NO
63 63
64 64
65#define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 65#define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
66 GNUNET_TIME_UNIT_SECONDS, 15)
66 67
67/** 68/**
68 * Encapsulation of all of the state of the plugin. 69 * Encapsulation of all of the state of the plugin.
69 */ 70 */
70struct Plugin { 71struct Plugin
72{
71 /** 73 /**
72 * Our environment. 74 * Our environment.
73 */ 75 */
@@ -118,7 +120,7 @@ struct Plugin {
118 /** 120 /**
119 * Task calling transport service about external address 121 * Task calling transport service about external address
120 */ 122 */
121 struct GNUNET_SCHEDULER_Task * notify_ext_task; 123 struct GNUNET_SCHEDULER_Task *notify_ext_task;
122 124
123 /** 125 /**
124 * Plugin name. 126 * Plugin name.
@@ -206,7 +208,7 @@ struct Plugin {
206 /** 208 /**
207 * MHD IPv4 task 209 * MHD IPv4 task
208 */ 210 */
209 struct GNUNET_SCHEDULER_Task * server_v4_task; 211 struct GNUNET_SCHEDULER_Task *server_v4_task;
210 212
211 /** 213 /**
212 * The IPv4 server is scheduled to run asap 214 * The IPv4 server is scheduled to run asap
@@ -221,7 +223,7 @@ struct Plugin {
221 /** 223 /**
222 * MHD IPv4 task 224 * MHD IPv4 task
223 */ 225 */
224 struct GNUNET_SCHEDULER_Task * server_v6_task; 226 struct GNUNET_SCHEDULER_Task *server_v6_task;
225 227
226 /** 228 /**
227 * The IPv6 server is scheduled to run asap 229 * The IPv6 server is scheduled to run asap
@@ -260,7 +262,7 @@ struct Plugin {
260 /** 262 /**
261 * curl perform task 263 * curl perform task
262 */ 264 */
263 struct GNUNET_SCHEDULER_Task * client_perform_task; 265 struct GNUNET_SCHEDULER_Task *client_perform_task;
264}; 266};
265 267
266GNUNET_NETWORK_STRUCT_BEGIN 268GNUNET_NETWORK_STRUCT_BEGIN
@@ -268,7 +270,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
268/** 270/**
269 * HTTP addresses including a full URI 271 * HTTP addresses including a full URI
270 */ 272 */
271struct HttpAddress { 273struct HttpAddress
274{
272 /** 275 /**
273 * Length of the address following in NBO 276 * Length of the address following in NBO
274 */ 277 */
@@ -283,7 +286,8 @@ struct HttpAddress {
283/** 286/**
284 * IPv4 addresses 287 * IPv4 addresses
285 */ 288 */
286struct IPv4HttpAddress { 289struct IPv4HttpAddress
290{
287 /** 291 /**
288 * IPv4 address, in network byte order. 292 * IPv4 address, in network byte order.
289 */ 293 */
@@ -298,7 +302,8 @@ struct IPv4HttpAddress {
298/** 302/**
299 * IPv4 addresses 303 * IPv4 addresses
300 */ 304 */
301struct IPv6HttpAddress { 305struct IPv6HttpAddress
306{
302 /** 307 /**
303 * IPv6 address. 308 * IPv6 address.
304 */ 309 */
@@ -312,7 +317,8 @@ struct IPv6HttpAddress {
312GNUNET_NETWORK_STRUCT_END 317GNUNET_NETWORK_STRUCT_END
313 318
314 319
315struct ServerRequest { 320struct ServerRequest
321{
316 /** 322 /**
317 * _RECV or _SEND 323 * _RECV or _SEND
318 */ 324 */
@@ -338,7 +344,8 @@ struct ServerRequest {
338/** 344/**
339 * Session handle for connections. 345 * Session handle for connections.
340 */ 346 */
341struct GNUNET_ATS_Session { 347struct GNUNET_ATS_Session
348{
342 /** 349 /**
343 * To whom are we talking to 350 * To whom are we talking to
344 */ 351 */
@@ -420,12 +427,12 @@ struct GNUNET_ATS_Session {
420 /** 427 /**
421 * Task to wake up client receive handle when receiving is allowed again 428 * Task to wake up client receive handle when receiving is allowed again
422 */ 429 */
423 struct GNUNET_SCHEDULER_Task * recv_wakeup_task; 430 struct GNUNET_SCHEDULER_Task *recv_wakeup_task;
424 431
425 /** 432 /**
426 * Session timeout task 433 * Session timeout task
427 */ 434 */
428 struct GNUNET_SCHEDULER_Task * timeout_task; 435 struct GNUNET_SCHEDULER_Task *timeout_task;
429 436
430 /** 437 /**
431 * Is client send handle paused since there are no data to send? 438 * Is client send handle paused since there are no data to send?
@@ -448,7 +455,8 @@ struct GNUNET_ATS_Session {
448/** 455/**
449 * Message to send using http 456 * Message to send using http
450 */ 457 */
451struct HTTP_Message { 458struct HTTP_Message
459{
452 /** 460 /**
453 * next pointer for double linked list 461 * next pointer for double linked list
454 */ 462 */
@@ -489,81 +497,81 @@ struct HTTP_Message {
489 497
490 498
491struct GNUNET_ATS_Session * 499struct GNUNET_ATS_Session *
492create_session(struct Plugin *plugin, 500create_session (struct Plugin *plugin,
493 const struct GNUNET_PeerIdentity *target, 501 const struct GNUNET_PeerIdentity *target,
494 const void *addr, 502 const void *addr,
495 size_t addrlen); 503 size_t addrlen);
496 504
497 505
498int 506int
499exist_session(struct Plugin *plugin, 507exist_session (struct Plugin *plugin,
500 struct GNUNET_ATS_Session *s); 508 struct GNUNET_ATS_Session *s);
501 509
502 510
503void 511void
504delete_session(struct GNUNET_ATS_Session *s); 512delete_session (struct GNUNET_ATS_Session *s);
505 513
506 514
507int 515int
508exist_session(struct Plugin *plugin, 516exist_session (struct Plugin *plugin,
509 struct GNUNET_ATS_Session *s); 517 struct GNUNET_ATS_Session *s);
510 518
511 519
512struct GNUNET_TIME_Relative 520struct GNUNET_TIME_Relative
513http_plugin_receive(void *cls, 521http_plugin_receive (void *cls,
514 const struct GNUNET_PeerIdentity *peer, 522 const struct GNUNET_PeerIdentity *peer,
515 const struct GNUNET_MessageHeader *message, 523 const struct GNUNET_MessageHeader *message,
516 struct GNUNET_ATS_Session *session, 524 struct GNUNET_ATS_Session *session,
517 const char *sender_address, 525 const char *sender_address,
518 uint16_t sender_address_len); 526 uint16_t sender_address_len);
519 527
520 528
521const char * 529const char *
522http_plugin_address_to_string(void *cls, 530http_plugin_address_to_string (void *cls,
523 const void *addr, 531 const void *addr,
524 size_t addrlen); 532 size_t addrlen);
525 533
526 534
527int 535int
528client_disconnect(struct GNUNET_ATS_Session *s); 536client_disconnect (struct GNUNET_ATS_Session *s);
529 537
530 538
531int 539int
532client_connect(struct GNUNET_ATS_Session *s); 540client_connect (struct GNUNET_ATS_Session *s);
533 541
534 542
535int 543int
536client_send(struct GNUNET_ATS_Session *s, struct HTTP_Message *msg); 544client_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
537 545
538 546
539int 547int
540client_start(struct Plugin *plugin); 548client_start (struct Plugin *plugin);
541 549
542 550
543void 551void
544client_stop(struct Plugin *plugin); 552client_stop (struct Plugin *plugin);
545 553
546 554
547int 555int
548server_disconnect(struct GNUNET_ATS_Session *s); 556server_disconnect (struct GNUNET_ATS_Session *s);
549 557
550 558
551int 559int
552server_send(struct GNUNET_ATS_Session *s, struct HTTP_Message *msg); 560server_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
553 561
554 562
555int 563int
556server_start(struct Plugin *plugin); 564server_start (struct Plugin *plugin);
557 565
558 566
559void 567void
560server_stop(struct Plugin *plugin); 568server_stop (struct Plugin *plugin);
561 569
562 570
563void 571void
564notify_session_end(void *cls, 572notify_session_end (void *cls,
565 const struct GNUNET_PeerIdentity *peer, 573 const struct GNUNET_PeerIdentity *peer,
566 struct GNUNET_ATS_Session *s); 574 struct GNUNET_ATS_Session *s);
567 575
568 576
569/*#ifndef PLUGIN_TRANSPORT_HTTP_H*/ 577/*#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 @@
28#if BUILD_HTTPS 28#if BUILD_HTTPS
29#define PLUGIN_NAME "https_client" 29#define PLUGIN_NAME "https_client"
30#define HTTP_STAT_STR_CONNECTIONS "# HTTPS client connections" 30#define HTTP_STAT_STR_CONNECTIONS "# HTTPS client connections"
31#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_client_init 31#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \
32#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_client_done 32 libgnunet_plugin_transport_https_client_init
33#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \
34 libgnunet_plugin_transport_https_client_done
33#else 35#else
34#define PLUGIN_NAME "http_client" 36#define PLUGIN_NAME "http_client"
35#define HTTP_STAT_STR_CONNECTIONS "# HTTP client connections" 37#define HTTP_STAT_STR_CONNECTIONS "# HTTP client connections"
36#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_client_init 38#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \
37#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_client_done 39 libgnunet_plugin_transport_http_client_init
40#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \
41 libgnunet_plugin_transport_http_client_done
38#endif 42#endif
39 43
40#define VERBOSE_CURL GNUNET_NO 44#define VERBOSE_CURL GNUNET_NO
41 45
42#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) 46#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply ( \
47 GNUNET_TIME_UNIT_SECONDS, 1)
43 48
44#define ENABLE_PUT GNUNET_YES 49#define ENABLE_PUT GNUNET_YES
45#define ENABLE_GET GNUNET_YES 50#define ENABLE_GET GNUNET_YES
@@ -53,7 +58,7 @@
53#include "gnunet_curl_lib.h" 58#include "gnunet_curl_lib.h"
54 59
55 60
56#define LOG(kind, ...) GNUNET_log_from(kind, PLUGIN_NAME, __VA_ARGS__) 61#define LOG(kind, ...) GNUNET_log_from (kind, PLUGIN_NAME, __VA_ARGS__)
57 62
58/** 63/**
59 * Encapsulation of all of the state of the plugin. 64 * Encapsulation of all of the state of the plugin.
@@ -63,7 +68,8 @@ struct HTTP_Client_Plugin;
63/** 68/**
64 * State of a HTTP PUT request 69 * State of a HTTP PUT request
65 */ 70 */
66enum HTTP_PUT_REQUEST_STATE { 71enum HTTP_PUT_REQUEST_STATE
72{
67 /** 73 /**
68 * Just created, not yet connected 74 * Just created, not yet connected
69 */ 75 */
@@ -103,7 +109,8 @@ enum HTTP_PUT_REQUEST_STATE {
103/** 109/**
104 * Message to send using http 110 * Message to send using http
105 */ 111 */
106struct HTTP_Message { 112struct HTTP_Message
113{
107 /** 114 /**
108 * next pointer for double linked list 115 * next pointer for double linked list
109 */ 116 */
@@ -153,7 +160,8 @@ struct GNUNET_ATS_Session;
153 * A request handle 160 * A request handle
154 * 161 *
155 */ 162 */
156struct RequestHandle { 163struct RequestHandle
164{
157 /** 165 /**
158 * Current state of this request 166 * Current state of this request
159 */ 167 */
@@ -174,7 +182,8 @@ struct RequestHandle {
174/** 182/**
175 * Session handle for connections. 183 * Session handle for connections.
176 */ 184 */
177struct GNUNET_ATS_Session { 185struct GNUNET_ATS_Session
186{
178 /** 187 /**
179 * The URL to connect to 188 * The URL to connect to
180 */ 189 */
@@ -267,7 +276,8 @@ struct GNUNET_ATS_Session {
267/** 276/**
268 * Encapsulation of all of the state of the plugin. 277 * Encapsulation of all of the state of the plugin.
269 */ 278 */
270struct HTTP_Client_Plugin { 279struct HTTP_Client_Plugin
280{
271 /** 281 /**
272 * Our environment. 282 * Our environment.
273 */ 283 */
@@ -321,7 +331,7 @@ struct HTTP_Client_Plugin {
321 /** 331 /**
322 * curl perform task 332 * curl perform task
323 */ 333 */
324 struct GNUNET_SCHEDULER_Task * client_perform_task; 334 struct GNUNET_SCHEDULER_Task *client_perform_task;
325 335
326 /** 336 /**
327 * Type of proxy server: 337 * Type of proxy server:
@@ -388,7 +398,7 @@ struct HTTP_Client_Plugin {
388 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 398 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
389 */ 399 */
390static int 400static int
391http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s); 401http_client_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *s);
392 402
393 403
394/** 404/**
@@ -400,15 +410,15 @@ http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s);
400 * @param state new state of the session 410 * @param state new state of the session
401 */ 411 */
402static void 412static void
403notify_session_monitor(struct HTTP_Client_Plugin *plugin, 413notify_session_monitor (struct HTTP_Client_Plugin *plugin,
404 struct GNUNET_ATS_Session *session, 414 struct GNUNET_ATS_Session *session,
405 enum GNUNET_TRANSPORT_SessionState state) 415 enum GNUNET_TRANSPORT_SessionState state)
406{ 416{
407 struct GNUNET_TRANSPORT_SessionInfo info; 417 struct GNUNET_TRANSPORT_SessionInfo info;
408 418
409 if (NULL == plugin->sic) 419 if (NULL == plugin->sic)
410 return; 420 return;
411 memset(&info, 0, sizeof(info)); 421 memset (&info, 0, sizeof(info));
412 info.state = state; 422 info.state = state;
413 info.is_inbound = GNUNET_NO; 423 info.is_inbound = GNUNET_NO;
414 info.num_msg_pending = session->msgs_in_queue; 424 info.num_msg_pending = session->msgs_in_queue;
@@ -416,9 +426,9 @@ notify_session_monitor(struct HTTP_Client_Plugin *plugin,
416 info.receive_delay = session->next_receive; 426 info.receive_delay = session->next_receive;
417 info.session_timeout = session->timeout; 427 info.session_timeout = session->timeout;
418 info.address = session->address; 428 info.address = session->address;
419 plugin->sic(plugin->sic_cls, 429 plugin->sic (plugin->sic_cls,
420 session, 430 session,
421 &info); 431 &info);
422} 432}
423 433
424 434
@@ -428,7 +438,7 @@ notify_session_monitor(struct HTTP_Client_Plugin *plugin,
428 * @param s the session to delete 438 * @param s the session to delete
429 */ 439 */
430static void 440static void
431client_delete_session(struct GNUNET_ATS_Session *s) 441client_delete_session (struct GNUNET_ATS_Session *s)
432{ 442{
433 struct HTTP_Client_Plugin *plugin = s->plugin; 443 struct HTTP_Client_Plugin *plugin = s->plugin;
434 struct HTTP_Message *pos; 444 struct HTTP_Message *pos;
@@ -436,95 +446,95 @@ client_delete_session(struct GNUNET_ATS_Session *s)
436 CURLMcode mret; 446 CURLMcode mret;
437 447
438 if (NULL != s->timeout_task) 448 if (NULL != s->timeout_task)
439 { 449 {
440 GNUNET_SCHEDULER_cancel(s->timeout_task); 450 GNUNET_SCHEDULER_cancel (s->timeout_task);
441 s->timeout_task = NULL; 451 s->timeout_task = NULL;
442 s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 452 s->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
443 } 453 }
444 if (NULL != s->put_disconnect_task) 454 if (NULL != s->put_disconnect_task)
445 { 455 {
446 GNUNET_SCHEDULER_cancel(s->put_disconnect_task); 456 GNUNET_SCHEDULER_cancel (s->put_disconnect_task);
447 s->put_disconnect_task = NULL; 457 s->put_disconnect_task = NULL;
448 } 458 }
449 if (NULL != s->recv_wakeup_task) 459 if (NULL != s->recv_wakeup_task)
450 { 460 {
451 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); 461 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
452 s->recv_wakeup_task = NULL; 462 s->recv_wakeup_task = NULL;
453 } 463 }
454 GNUNET_assert(GNUNET_OK == 464 GNUNET_assert (GNUNET_OK ==
455 GNUNET_CONTAINER_multipeermap_remove(plugin->sessions, 465 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions,
456 &s->address->peer, 466 &s->address->peer,
457 s)); 467 s));
458 if (NULL != s->put.easyhandle) 468 if (NULL != s->put.easyhandle)
459 { 469 {
460 LOG(GNUNET_ERROR_TYPE_DEBUG, 470 LOG (GNUNET_ERROR_TYPE_DEBUG,
461 "Session %p/request %p: disconnecting PUT request to peer `%s'\n", 471 "Session %p/request %p: disconnecting PUT request to peer `%s'\n",
462 s, 472 s,
463 s->put.easyhandle, 473 s->put.easyhandle,
464 GNUNET_i2s(&s->address->peer)); 474 GNUNET_i2s (&s->address->peer));
465 475
466 /* remove curl handle from multi handle */ 476 /* remove curl handle from multi handle */
467 mret = curl_multi_remove_handle(plugin->curl_multi_handle, 477 mret = curl_multi_remove_handle (plugin->curl_multi_handle,
468 s->put.easyhandle); 478 s->put.easyhandle);
469 GNUNET_break(CURLM_OK == mret); 479 GNUNET_break (CURLM_OK == mret);
470 curl_easy_cleanup(s->put.easyhandle); 480 curl_easy_cleanup (s->put.easyhandle);
471 GNUNET_assert(plugin->cur_requests > 0); 481 GNUNET_assert (plugin->cur_requests > 0);
472 plugin->cur_requests--; 482 plugin->cur_requests--;
473 s->put.easyhandle = NULL; 483 s->put.easyhandle = NULL;
474 } 484 }
475 if (NULL != s->get.easyhandle) 485 if (NULL != s->get.easyhandle)
476 { 486 {
477 LOG(GNUNET_ERROR_TYPE_DEBUG, 487 LOG (GNUNET_ERROR_TYPE_DEBUG,
478 "Session %p/request %p: disconnecting GET request to peer `%s'\n", 488 "Session %p/request %p: disconnecting GET request to peer `%s'\n",
479 s, s->get.easyhandle, 489 s, s->get.easyhandle,
480 GNUNET_i2s(&s->address->peer)); 490 GNUNET_i2s (&s->address->peer));
481 /* remove curl handle from multi handle */ 491 /* remove curl handle from multi handle */
482 mret = curl_multi_remove_handle(plugin->curl_multi_handle, 492 mret = curl_multi_remove_handle (plugin->curl_multi_handle,
483 s->get.easyhandle); 493 s->get.easyhandle);
484 GNUNET_break(CURLM_OK == mret); 494 GNUNET_break (CURLM_OK == mret);
485 curl_easy_cleanup(s->get.easyhandle); 495 curl_easy_cleanup (s->get.easyhandle);
486 GNUNET_assert(plugin->cur_requests > 0); 496 GNUNET_assert (plugin->cur_requests > 0);
487 plugin->cur_requests--; 497 plugin->cur_requests--;
488 s->get.easyhandle = NULL; 498 s->get.easyhandle = NULL;
489 } 499 }
490 500
491 GNUNET_STATISTICS_set(plugin->env->stats, 501 GNUNET_STATISTICS_set (plugin->env->stats,
492 HTTP_STAT_STR_CONNECTIONS, 502 HTTP_STAT_STR_CONNECTIONS,
493 plugin->cur_requests, 503 plugin->cur_requests,
494 GNUNET_NO); 504 GNUNET_NO);
495 next = s->msg_head; 505 next = s->msg_head;
496 while (NULL != (pos = next)) 506 while (NULL != (pos = next))
497 { 507 {
498 next = pos->next; 508 next = pos->next;
499 GNUNET_CONTAINER_DLL_remove(s->msg_head, 509 GNUNET_CONTAINER_DLL_remove (s->msg_head,
500 s->msg_tail, 510 s->msg_tail,
501 pos); 511 pos);
502 GNUNET_assert(0 < s->msgs_in_queue); 512 GNUNET_assert (0 < s->msgs_in_queue);
503 s->msgs_in_queue--; 513 s->msgs_in_queue--;
504 GNUNET_assert(pos->size <= s->bytes_in_queue); 514 GNUNET_assert (pos->size <= s->bytes_in_queue);
505 s->bytes_in_queue -= pos->size; 515 s->bytes_in_queue -= pos->size;
506 if (NULL != pos->transmit_cont) 516 if (NULL != pos->transmit_cont)
507 pos->transmit_cont(pos->transmit_cont_cls, 517 pos->transmit_cont (pos->transmit_cont_cls,
508 &s->address->peer, 518 &s->address->peer,
509 GNUNET_SYSERR, 519 GNUNET_SYSERR,
510 pos->size, 520 pos->size,
511 pos->pos + s->overhead); 521 pos->pos + s->overhead);
512 s->overhead = 0; 522 s->overhead = 0;
513 GNUNET_free(pos); 523 GNUNET_free (pos);
514 } 524 }
515 GNUNET_assert(0 == s->msgs_in_queue); 525 GNUNET_assert (0 == s->msgs_in_queue);
516 GNUNET_assert(0 == s->bytes_in_queue); 526 GNUNET_assert (0 == s->bytes_in_queue);
517 notify_session_monitor(plugin, 527 notify_session_monitor (plugin,
518 s, 528 s,
519 GNUNET_TRANSPORT_SS_DONE); 529 GNUNET_TRANSPORT_SS_DONE);
520 if (NULL != s->msg_tk) 530 if (NULL != s->msg_tk)
521 { 531 {
522 GNUNET_MST_destroy(s->msg_tk); 532 GNUNET_MST_destroy (s->msg_tk);
523 s->msg_tk = NULL; 533 s->msg_tk = NULL;
524 } 534 }
525 GNUNET_HELLO_address_free(s->address); 535 GNUNET_HELLO_address_free (s->address);
526 GNUNET_free(s->url); 536 GNUNET_free (s->url);
527 GNUNET_free(s); 537 GNUNET_free (s);
528} 538}
529 539
530 540
@@ -534,10 +544,11 @@ client_delete_session(struct GNUNET_ATS_Session *s)
534 * @param s the session 544 * @param s the session
535 */ 545 */
536static void 546static void
537client_reschedule_session_timeout(struct GNUNET_ATS_Session *s) 547client_reschedule_session_timeout (struct GNUNET_ATS_Session *s)
538{ 548{
539 GNUNET_assert(NULL != s->timeout_task); 549 GNUNET_assert (NULL != s->timeout_task);
540 s->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 550 s->timeout = GNUNET_TIME_relative_to_absolute (
551 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
541} 552}
542 553
543 554
@@ -548,7 +559,7 @@ client_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
548 * @param tc gnunet scheduler task context 559 * @param tc gnunet scheduler task context
549 */ 560 */
550static void 561static void
551client_run(void *cls); 562client_run (void *cls);
552 563
553 564
554/** 565/**
@@ -559,8 +570,8 @@ client_run(void *cls);
559 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok 570 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok
560 */ 571 */
561static int 572static int
562client_schedule(struct HTTP_Client_Plugin *plugin, 573client_schedule (struct HTTP_Client_Plugin *plugin,
563 int now) 574 int now)
564{ 575{
565 fd_set rs; 576 fd_set rs;
566 fd_set ws; 577 fd_set ws;
@@ -574,54 +585,54 @@ client_schedule(struct HTTP_Client_Plugin *plugin,
574 585
575 /* Cancel previous scheduled task */ 586 /* Cancel previous scheduled task */
576 if (plugin->client_perform_task != NULL) 587 if (plugin->client_perform_task != NULL)
577 { 588 {
578 GNUNET_SCHEDULER_cancel(plugin->client_perform_task); 589 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
579 plugin->client_perform_task = NULL; 590 plugin->client_perform_task = NULL;
580 } 591 }
581 max = -1; 592 max = -1;
582 FD_ZERO(&rs); 593 FD_ZERO (&rs);
583 FD_ZERO(&ws); 594 FD_ZERO (&ws);
584 FD_ZERO(&es); 595 FD_ZERO (&es);
585 mret = curl_multi_fdset(plugin->curl_multi_handle, &rs, &ws, &es, &max); 596 mret = curl_multi_fdset (plugin->curl_multi_handle, &rs, &ws, &es, &max);
586 if (mret != CURLM_OK) 597 if (mret != CURLM_OK)
587 { 598 {
588 LOG(GNUNET_ERROR_TYPE_ERROR, 599 LOG (GNUNET_ERROR_TYPE_ERROR,
589 _("%s failed at %s:%d: `%s'\n"), 600 _ ("%s failed at %s:%d: `%s'\n"),
590 "curl_multi_fdset", 601 "curl_multi_fdset",
591 __FILE__, 602 __FILE__,
592 __LINE__, 603 __LINE__,
593 curl_multi_strerror(mret)); 604 curl_multi_strerror (mret));
594 return GNUNET_SYSERR; 605 return GNUNET_SYSERR;
595 } 606 }
596 mret = curl_multi_timeout(plugin->curl_multi_handle, &to); 607 mret = curl_multi_timeout (plugin->curl_multi_handle, &to);
597 if (-1 == to) 608 if (-1 == to)
598 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1); 609 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1);
599 else 610 else
600 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, to); 611 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to);
601 if (now == GNUNET_YES) 612 if (now == GNUNET_YES)
602 timeout = GNUNET_TIME_UNIT_MILLISECONDS; 613 timeout = GNUNET_TIME_UNIT_MILLISECONDS;
603 614
604 if (CURLM_OK != mret) 615 if (CURLM_OK != mret)
605 { 616 {
606 LOG(GNUNET_ERROR_TYPE_ERROR, 617 LOG (GNUNET_ERROR_TYPE_ERROR,
607 _("%s failed at %s:%d: `%s'\n"), 618 _ ("%s failed at %s:%d: `%s'\n"),
608 "curl_multi_timeout", __FILE__, __LINE__, 619 "curl_multi_timeout", __FILE__, __LINE__,
609 curl_multi_strerror(mret)); 620 curl_multi_strerror (mret));
610 return GNUNET_SYSERR; 621 return GNUNET_SYSERR;
611 } 622 }
612 623
613 grs = GNUNET_NETWORK_fdset_create(); 624 grs = GNUNET_NETWORK_fdset_create ();
614 gws = GNUNET_NETWORK_fdset_create(); 625 gws = GNUNET_NETWORK_fdset_create ();
615 GNUNET_NETWORK_fdset_copy_native(grs, &rs, max + 1); 626 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
616 GNUNET_NETWORK_fdset_copy_native(gws, &ws, max + 1); 627 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
617 628
618 /* Schedule task to run when select is ready to read or write */ 629 /* Schedule task to run when select is ready to read or write */
619 plugin->client_perform_task = 630 plugin->client_perform_task =
620 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, 631 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
621 timeout, grs, gws, 632 timeout, grs, gws,
622 &client_run, plugin); 633 &client_run, plugin);
623 GNUNET_NETWORK_fdset_destroy(gws); 634 GNUNET_NETWORK_fdset_destroy (gws);
624 GNUNET_NETWORK_fdset_destroy(grs); 635 GNUNET_NETWORK_fdset_destroy (grs);
625 return GNUNET_OK; 636 return GNUNET_OK;
626} 637}
627 638
@@ -638,58 +649,58 @@ client_schedule(struct HTTP_Client_Plugin *plugin,
638 * @return always 0 649 * @return always 0
639 */ 650 */
640static int 651static int
641client_log(CURL *curl, 652client_log (CURL *curl,
642 curl_infotype type, 653 curl_infotype type,
643 const char *data, 654 const char *data,
644 size_t size, 655 size_t size,
645 void *cls) 656 void *cls)
646{ 657{
647 struct RequestHandle *ch = cls; 658 struct RequestHandle *ch = cls;
648 const char *ttype = "UNSPECIFIED"; 659 const char *ttype = "UNSPECIFIED";
649 char text[size + 2]; 660 char text[size + 2];
650 661
651 if (!((CURLINFO_TEXT == type) || 662 if (! ((CURLINFO_TEXT == type) ||
652 (CURLINFO_HEADER_IN == type) || 663 (CURLINFO_HEADER_IN == type) ||
653 (CURLINFO_HEADER_OUT == type))) 664 (CURLINFO_HEADER_OUT == type)))
654 return 0; 665 return 0;
655 switch (type) 666 switch (type)
656 { 667 {
657 case CURLINFO_TEXT: 668 case CURLINFO_TEXT:
658 ttype = "TEXT"; 669 ttype = "TEXT";
659 break; 670 break;
660 671
661 case CURLINFO_HEADER_IN: 672 case CURLINFO_HEADER_IN:
662 ttype = "HEADER_IN"; 673 ttype = "HEADER_IN";
663 break; 674 break;
664 675
665 case CURLINFO_HEADER_OUT: 676 case CURLINFO_HEADER_OUT:
666 ttype = "HEADER_OUT"; 677 ttype = "HEADER_OUT";
667 /* Overhead*/ 678 /* Overhead*/
668 GNUNET_assert(NULL != ch); 679 GNUNET_assert (NULL != ch);
669 GNUNET_assert(NULL != ch->easyhandle); 680 GNUNET_assert (NULL != ch->easyhandle);
670 GNUNET_assert(NULL != ch->s); 681 GNUNET_assert (NULL != ch->s);
671 ch->s->overhead += size; 682 ch->s->overhead += size;
672 break; 683 break;
673 684
674 default: 685 default:
675 ttype = "UNSPECIFIED"; 686 ttype = "UNSPECIFIED";
676 break; 687 break;
677 } 688 }
678 GNUNET_memcpy(text, data, size); 689 GNUNET_memcpy (text, data, size);
679 if (text[size - 1] == '\n') 690 if (text[size - 1] == '\n')
680 { 691 {
681 text[size] = '\0'; 692 text[size] = '\0';
682 } 693 }
683 else 694 else
684 { 695 {
685 text[size] = '\n'; 696 text[size] = '\n';
686 text[size + 1] = '\0'; 697 text[size + 1] = '\0';
687 } 698 }
688 LOG(GNUNET_ERROR_TYPE_DEBUG, 699 LOG (GNUNET_ERROR_TYPE_DEBUG,
689 "Request %p %s: %s", 700 "Request %p %s: %s",
690 ch->easyhandle, 701 ch->easyhandle,
691 ttype, 702 ttype,
692 text); 703 text);
693 return 0; 704 return 0;
694} 705}
695#endif 706#endif
@@ -701,7 +712,7 @@ client_log(CURL *curl,
701 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 712 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
702 */ 713 */
703static int 714static int
704client_connect_get(struct GNUNET_ATS_Session *s); 715client_connect_get (struct GNUNET_ATS_Session *s);
705 716
706 717
707/** 718/**
@@ -711,7 +722,7 @@ client_connect_get(struct GNUNET_ATS_Session *s);
711 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success 722 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success
712 */ 723 */
713static int 724static int
714client_connect_put(struct GNUNET_ATS_Session *s); 725client_connect_put (struct GNUNET_ATS_Session *s);
715 726
716 727
717/** 728/**
@@ -742,86 +753,86 @@ client_connect_put(struct GNUNET_ATS_Session *s);
742 * and does NOT mean that the message was not transmitted (DV) 753 * and does NOT mean that the message was not transmitted (DV)
743 */ 754 */
744static ssize_t 755static ssize_t
745http_client_plugin_send(void *cls, 756http_client_plugin_send (void *cls,
746 struct GNUNET_ATS_Session *s, 757 struct GNUNET_ATS_Session *s,
747 const char *msgbuf, 758 const char *msgbuf,
748 size_t msgbuf_size, 759 size_t msgbuf_size,
749 unsigned int priority, 760 unsigned int priority,
750 struct GNUNET_TIME_Relative to, 761 struct GNUNET_TIME_Relative to,
751 GNUNET_TRANSPORT_TransmitContinuation cont, 762 GNUNET_TRANSPORT_TransmitContinuation cont,
752 void *cont_cls) 763 void *cont_cls)
753{ 764{
754 struct HTTP_Client_Plugin *plugin = cls; 765 struct HTTP_Client_Plugin *plugin = cls;
755 struct HTTP_Message *msg; 766 struct HTTP_Message *msg;
756 char *stat_txt; 767 char *stat_txt;
757 768
758 LOG(GNUNET_ERROR_TYPE_DEBUG, 769 LOG (GNUNET_ERROR_TYPE_DEBUG,
759 "Session %p/request %p: Sending message with %u to peer `%s' \n", 770 "Session %p/request %p: Sending message with %u to peer `%s' \n",
760 s, 771 s,
761 s->put.easyhandle, 772 s->put.easyhandle,
762 msgbuf_size, 773 msgbuf_size,
763 GNUNET_i2s(&s->address->peer)); 774 GNUNET_i2s (&s->address->peer));
764 775
765 /* create new message and schedule */ 776 /* create new message and schedule */
766 msg = GNUNET_malloc(sizeof(struct HTTP_Message) + msgbuf_size); 777 msg = GNUNET_malloc (sizeof(struct HTTP_Message) + msgbuf_size);
767 msg->size = msgbuf_size; 778 msg->size = msgbuf_size;
768 msg->buf = (char *)&msg[1]; 779 msg->buf = (char *) &msg[1];
769 msg->transmit_cont = cont; 780 msg->transmit_cont = cont;
770 msg->transmit_cont_cls = cont_cls; 781 msg->transmit_cont_cls = cont_cls;
771 GNUNET_memcpy(msg->buf, 782 GNUNET_memcpy (msg->buf,
772 msgbuf, 783 msgbuf,
773 msgbuf_size); 784 msgbuf_size);
774 GNUNET_CONTAINER_DLL_insert_tail(s->msg_head, 785 GNUNET_CONTAINER_DLL_insert_tail (s->msg_head,
775 s->msg_tail, 786 s->msg_tail,
776 msg); 787 msg);
777 s->msgs_in_queue++; 788 s->msgs_in_queue++;
778 s->bytes_in_queue += msg->size; 789 s->bytes_in_queue += msg->size;
779 790
780 GNUNET_asprintf(&stat_txt, 791 GNUNET_asprintf (&stat_txt,
781 "# bytes currently in %s_client buffers", 792 "# bytes currently in %s_client buffers",
782 plugin->protocol); 793 plugin->protocol);
783 GNUNET_STATISTICS_update(plugin->env->stats, 794 GNUNET_STATISTICS_update (plugin->env->stats,
784 stat_txt, msgbuf_size, GNUNET_NO); 795 stat_txt, msgbuf_size, GNUNET_NO);
785 GNUNET_free(stat_txt); 796 GNUNET_free (stat_txt);
786 notify_session_monitor(plugin, 797 notify_session_monitor (plugin,
787 s, 798 s,
788 GNUNET_TRANSPORT_SS_UPDATE); 799 GNUNET_TRANSPORT_SS_UPDATE);
789 if (H_TMP_DISCONNECTING == s->put.state) 800 if (H_TMP_DISCONNECTING == s->put.state)
790 { 801 {
791 /* PUT request is currently getting disconnected */ 802 /* PUT request is currently getting disconnected */
792 s->put.state = H_TMP_RECONNECT_REQUIRED; 803 s->put.state = H_TMP_RECONNECT_REQUIRED;
793 LOG(GNUNET_ERROR_TYPE_DEBUG, 804 LOG (GNUNET_ERROR_TYPE_DEBUG,
794 "Session %p/request %p: currently disconnecting, reconnecting immediately\n", 805 "Session %p/request %p: currently disconnecting, reconnecting immediately\n",
795 s, 806 s,
796 s->put.easyhandle); 807 s->put.easyhandle);
797 return msgbuf_size; 808 return msgbuf_size;
798 } 809 }
799 if (H_PAUSED == s->put.state) 810 if (H_PAUSED == s->put.state)
800 { 811 {
801 /* PUT request was paused, unpause */ 812 /* PUT request was paused, unpause */
802 GNUNET_assert(s->put_disconnect_task != NULL); 813 GNUNET_assert (s->put_disconnect_task != NULL);
803 GNUNET_SCHEDULER_cancel(s->put_disconnect_task); 814 GNUNET_SCHEDULER_cancel (s->put_disconnect_task);
804 s->put_disconnect_task = NULL; 815 s->put_disconnect_task = NULL;
805 LOG(GNUNET_ERROR_TYPE_DEBUG, 816 LOG (GNUNET_ERROR_TYPE_DEBUG,
806 "Session %p/request %p: unpausing request\n", 817 "Session %p/request %p: unpausing request\n",
807 s, s->put.easyhandle); 818 s, s->put.easyhandle);
808 s->put.state = H_CONNECTED; 819 s->put.state = H_CONNECTED;
809 if (NULL != s->put.easyhandle) 820 if (NULL != s->put.easyhandle)
810 curl_easy_pause(s->put.easyhandle, CURLPAUSE_CONT); 821 curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT);
811 } 822 }
812 else if (H_TMP_DISCONNECTED == s->put.state) 823 else if (H_TMP_DISCONNECTED == s->put.state)
824 {
825 /* PUT request was disconnected, reconnect */
826 LOG (GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s);
827 GNUNET_break (NULL == s->put.easyhandle);
828 if (GNUNET_SYSERR == client_connect_put (s))
813 { 829 {
814 /* PUT request was disconnected, reconnect */ 830 /* Could not reconnect */
815 LOG(GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s); 831 http_client_plugin_session_disconnect (plugin, s);
816 GNUNET_break(NULL == s->put.easyhandle); 832 return GNUNET_SYSERR;
817 if (GNUNET_SYSERR == client_connect_put(s))
818 {
819 /* Could not reconnect */
820 http_client_plugin_session_disconnect(plugin, s);
821 return GNUNET_SYSERR;
822 }
823 } 833 }
824 client_schedule(s->plugin, GNUNET_YES); 834 }
835 client_schedule (s->plugin, GNUNET_YES);
825 return msgbuf_size; 836 return msgbuf_size;
826} 837}
827 838
@@ -834,26 +845,26 @@ http_client_plugin_send(void *cls,
834 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 845 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
835 */ 846 */
836static int 847static int
837http_client_plugin_session_disconnect(void *cls, 848http_client_plugin_session_disconnect (void *cls,
838 struct GNUNET_ATS_Session *s) 849 struct GNUNET_ATS_Session *s)
839{ 850{
840 struct HTTP_Client_Plugin *plugin = cls; 851 struct HTTP_Client_Plugin *plugin = cls;
841 852
842 LOG(GNUNET_ERROR_TYPE_DEBUG, 853 LOG (GNUNET_ERROR_TYPE_DEBUG,
843 "Session %p: notifying transport about ending session\n", 854 "Session %p: notifying transport about ending session\n",
844 s); 855 s);
845 plugin->env->session_end(plugin->env->cls, 856 plugin->env->session_end (plugin->env->cls,
846 s->address, 857 s->address,
847 s); 858 s);
848 client_delete_session(s); 859 client_delete_session (s);
849 860
850 /* Re-schedule since handles have changed */ 861 /* Re-schedule since handles have changed */
851 if (NULL != plugin->client_perform_task) 862 if (NULL != plugin->client_perform_task)
852 { 863 {
853 GNUNET_SCHEDULER_cancel(plugin->client_perform_task); 864 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
854 plugin->client_perform_task = NULL; 865 plugin->client_perform_task = NULL;
855 } 866 }
856 client_schedule(plugin, GNUNET_YES); 867 client_schedule (plugin, GNUNET_YES);
857 868
858 return GNUNET_OK; 869 return GNUNET_OK;
859} 870}
@@ -868,7 +879,7 @@ http_client_plugin_session_disconnect(void *cls,
868 * @return keepalive factor 879 * @return keepalive factor
869 */ 880 */
870static unsigned int 881static unsigned int
871http_client_query_keepalive_factor(void *cls) 882http_client_query_keepalive_factor (void *cls)
872{ 883{
873 return 3; 884 return 3;
874} 885}
@@ -883,14 +894,14 @@ http_client_query_keepalive_factor(void *cls)
883 * @return #GNUNET_OK (continue iterating) 894 * @return #GNUNET_OK (continue iterating)
884 */ 895 */
885static int 896static int
886destroy_session_cb(void *cls, 897destroy_session_cb (void *cls,
887 const struct GNUNET_PeerIdentity *peer, 898 const struct GNUNET_PeerIdentity *peer,
888 void *value) 899 void *value)
889{ 900{
890 struct HTTP_Client_Plugin *plugin = cls; 901 struct HTTP_Client_Plugin *plugin = cls;
891 struct GNUNET_ATS_Session *session = value; 902 struct GNUNET_ATS_Session *session = value;
892 903
893 http_client_plugin_session_disconnect(plugin, session); 904 http_client_plugin_session_disconnect (plugin, session);
894 return GNUNET_OK; 905 return GNUNET_OK;
895} 906}
896 907
@@ -904,25 +915,26 @@ destroy_session_cb(void *cls,
904 * @param target peer from which to disconnect 915 * @param target peer from which to disconnect
905 */ 916 */
906static void 917static void
907http_client_plugin_peer_disconnect(void *cls, 918http_client_plugin_peer_disconnect (void *cls,
908 const struct GNUNET_PeerIdentity *target) 919 const struct GNUNET_PeerIdentity *target)
909{ 920{
910 struct HTTP_Client_Plugin *plugin = cls; 921 struct HTTP_Client_Plugin *plugin = cls;
911 922
912 LOG(GNUNET_ERROR_TYPE_DEBUG, 923 LOG (GNUNET_ERROR_TYPE_DEBUG,
913 "Transport tells me to disconnect `%s'\n", 924 "Transport tells me to disconnect `%s'\n",
914 GNUNET_i2s(target)); 925 GNUNET_i2s (target));
915 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, 926 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions,
916 target, 927 target,
917 &destroy_session_cb, 928 &destroy_session_cb,
918 plugin); 929 plugin);
919} 930}
920 931
921 932
922/** 933/**
923 * Closure for #session_lookup_client_by_address(). 934 * Closure for #session_lookup_client_by_address().
924 */ 935 */
925struct GNUNET_ATS_SessionClientCtx { 936struct GNUNET_ATS_SessionClientCtx
937{
926 /** 938 /**
927 * Address we are looking for. 939 * Address we are looking for.
928 */ 940 */
@@ -944,19 +956,19 @@ struct GNUNET_ATS_SessionClientCtx {
944 * @return #GNUNET_NO if found, #GNUNET_OK if not 956 * @return #GNUNET_NO if found, #GNUNET_OK if not
945 */ 957 */
946static int 958static int
947session_lookup_client_by_address(void *cls, 959session_lookup_client_by_address (void *cls,
948 const struct GNUNET_PeerIdentity *key, 960 const struct GNUNET_PeerIdentity *key,
949 void *value) 961 void *value)
950{ 962{
951 struct GNUNET_ATS_SessionClientCtx *sc_ctx = cls; 963 struct GNUNET_ATS_SessionClientCtx *sc_ctx = cls;
952 struct GNUNET_ATS_Session *s = value; 964 struct GNUNET_ATS_Session *s = value;
953 965
954 if (0 == GNUNET_HELLO_address_cmp(sc_ctx->address, 966 if (0 == GNUNET_HELLO_address_cmp (sc_ctx->address,
955 s->address)) 967 s->address))
956 { 968 {
957 sc_ctx->ret = s; 969 sc_ctx->ret = s;
958 return GNUNET_NO; 970 return GNUNET_NO;
959 } 971 }
960 return GNUNET_YES; 972 return GNUNET_YES;
961} 973}
962 974
@@ -969,16 +981,16 @@ session_lookup_client_by_address(void *cls,
969 * @return the session or NULL 981 * @return the session or NULL
970 */ 982 */
971static struct GNUNET_ATS_Session * 983static struct GNUNET_ATS_Session *
972client_lookup_session(struct HTTP_Client_Plugin *plugin, 984client_lookup_session (struct HTTP_Client_Plugin *plugin,
973 const struct GNUNET_HELLO_Address *address) 985 const struct GNUNET_HELLO_Address *address)
974{ 986{
975 struct GNUNET_ATS_SessionClientCtx sc_ctx; 987 struct GNUNET_ATS_SessionClientCtx sc_ctx;
976 988
977 sc_ctx.address = address; 989 sc_ctx.address = address;
978 sc_ctx.ret = NULL; 990 sc_ctx.ret = NULL;
979 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, 991 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
980 &session_lookup_client_by_address, 992 &session_lookup_client_by_address,
981 &sc_ctx); 993 &sc_ctx);
982 return sc_ctx.ret; 994 return sc_ctx.ret;
983} 995}
984 996
@@ -991,19 +1003,19 @@ client_lookup_session(struct HTTP_Client_Plugin *plugin,
991 * @param cls the `struct GNUNET_ATS_Session *` with the put 1003 * @param cls the `struct GNUNET_ATS_Session *` with the put
992 */ 1004 */
993static void 1005static void
994client_put_disconnect(void *cls) 1006client_put_disconnect (void *cls)
995{ 1007{
996 struct GNUNET_ATS_Session *s = cls; 1008 struct GNUNET_ATS_Session *s = cls;
997 1009
998 s->put_disconnect_task = NULL; 1010 s->put_disconnect_task = NULL;
999 LOG(GNUNET_ERROR_TYPE_DEBUG, 1011 LOG (GNUNET_ERROR_TYPE_DEBUG,
1000 "Session %p/request %p: will be disconnected due to no activity\n", 1012 "Session %p/request %p: will be disconnected due to no activity\n",
1001 s, s->put.easyhandle); 1013 s, s->put.easyhandle);
1002 s->put.state = H_TMP_DISCONNECTING; 1014 s->put.state = H_TMP_DISCONNECTING;
1003 if (NULL != s->put.easyhandle) 1015 if (NULL != s->put.easyhandle)
1004 curl_easy_pause(s->put.easyhandle, 1016 curl_easy_pause (s->put.easyhandle,
1005 CURLPAUSE_CONT); 1017 CURLPAUSE_CONT);
1006 client_schedule(s->plugin, GNUNET_YES); 1018 client_schedule (s->plugin, GNUNET_YES);
1007} 1019}
1008 1020
1009 1021
@@ -1018,10 +1030,10 @@ client_put_disconnect(void *cls)
1018 * @return bytes written to stream, returning 0 will terminate request! 1030 * @return bytes written to stream, returning 0 will terminate request!
1019 */ 1031 */
1020static size_t 1032static size_t
1021client_send_cb(void *stream, 1033client_send_cb (void *stream,
1022 size_t size, 1034 size_t size,
1023 size_t nmemb, 1035 size_t nmemb,
1024 void *cls) 1036 void *cls)
1025{ 1037{
1026 struct GNUNET_ATS_Session *s = cls; 1038 struct GNUNET_ATS_Session *s = cls;
1027 struct HTTP_Client_Plugin *plugin = s->plugin; 1039 struct HTTP_Client_Plugin *plugin = s->plugin;
@@ -1030,90 +1042,90 @@ client_send_cb(void *stream,
1030 char *stat_txt; 1042 char *stat_txt;
1031 1043
1032 if (H_TMP_DISCONNECTING == s->put.state) 1044 if (H_TMP_DISCONNECTING == s->put.state)
1033 { 1045 {
1034 LOG(GNUNET_ERROR_TYPE_DEBUG, 1046 LOG (GNUNET_ERROR_TYPE_DEBUG,
1035 "Session %p/request %p: disconnect due to inactivity\n", 1047 "Session %p/request %p: disconnect due to inactivity\n",
1036 s, s->put.easyhandle); 1048 s, s->put.easyhandle);
1037 return 0; 1049 return 0;
1038 } 1050 }
1039 1051
1040 if (NULL == msg) 1052 if (NULL == msg)
1053 {
1054 if (GNUNET_YES == plugin->emulate_xhr)
1041 { 1055 {
1042 if (GNUNET_YES == plugin->emulate_xhr) 1056 LOG (GNUNET_ERROR_TYPE_DEBUG,
1043 { 1057 "Session %p/request %p: PUT request finished\n",
1044 LOG(GNUNET_ERROR_TYPE_DEBUG, 1058 s,
1045 "Session %p/request %p: PUT request finished\n", 1059 s->put.easyhandle);
1046 s, 1060 s->put.state = H_TMP_DISCONNECTING;
1047 s->put.easyhandle); 1061 return 0;
1048 s->put.state = H_TMP_DISCONNECTING;
1049 return 0;
1050 }
1051
1052 /* We have nothing to send, so pause PUT request */
1053 LOG(GNUNET_ERROR_TYPE_DEBUG,
1054 "Session %p/request %p: nothing to send, suspending\n",
1055 s,
1056 s->put.easyhandle);
1057 s->put_disconnect_task
1058 = GNUNET_SCHEDULER_add_delayed(PUT_DISCONNECT_TIMEOUT,
1059 &client_put_disconnect,
1060 s);
1061 s->put.state = H_PAUSED;
1062 return CURL_READFUNC_PAUSE;
1063 } 1062 }
1063
1064 /* We have nothing to send, so pause PUT request */
1065 LOG (GNUNET_ERROR_TYPE_DEBUG,
1066 "Session %p/request %p: nothing to send, suspending\n",
1067 s,
1068 s->put.easyhandle);
1069 s->put_disconnect_task
1070 = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT,
1071 &client_put_disconnect,
1072 s);
1073 s->put.state = H_PAUSED;
1074 return CURL_READFUNC_PAUSE;
1075 }
1064 /* data to send */ 1076 /* data to send */
1065 GNUNET_assert(msg->pos < msg->size); 1077 GNUNET_assert (msg->pos < msg->size);
1066 /* calculate how much fits in buffer */ 1078 /* calculate how much fits in buffer */
1067 len = GNUNET_MIN(msg->size - msg->pos, 1079 len = GNUNET_MIN (msg->size - msg->pos,
1068 size * nmemb); 1080 size * nmemb);
1069 GNUNET_memcpy(stream, 1081 GNUNET_memcpy (stream,
1070 &msg->buf[msg->pos], 1082 &msg->buf[msg->pos],
1071 len); 1083 len);
1072 msg->pos += len; 1084 msg->pos += len;
1073 if (msg->pos == msg->size) 1085 if (msg->pos == msg->size)
1074 { 1086 {
1075 LOG(GNUNET_ERROR_TYPE_DEBUG, 1087 LOG (GNUNET_ERROR_TYPE_DEBUG,
1076 "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n", 1088 "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n",
1077 s, 1089 s,
1078 s->put.easyhandle, 1090 s->put.easyhandle,
1079 msg->size, 1091 msg->size,
1080 msg->pos); 1092 msg->pos);
1081 /* Calling transmit continuation */ 1093 /* Calling transmit continuation */
1082 GNUNET_CONTAINER_DLL_remove(s->msg_head, 1094 GNUNET_CONTAINER_DLL_remove (s->msg_head,
1083 s->msg_tail, 1095 s->msg_tail,
1084 msg); 1096 msg);
1085 GNUNET_assert(0 < s->msgs_in_queue); 1097 GNUNET_assert (0 < s->msgs_in_queue);
1086 s->msgs_in_queue--; 1098 s->msgs_in_queue--;
1087 GNUNET_assert(msg->size <= s->bytes_in_queue); 1099 GNUNET_assert (msg->size <= s->bytes_in_queue);
1088 s->bytes_in_queue -= msg->size; 1100 s->bytes_in_queue -= msg->size;
1089 if (NULL != msg->transmit_cont) 1101 if (NULL != msg->transmit_cont)
1090 msg->transmit_cont(msg->transmit_cont_cls, 1102 msg->transmit_cont (msg->transmit_cont_cls,
1091 &s->address->peer, 1103 &s->address->peer,
1092 GNUNET_OK, 1104 GNUNET_OK,
1093 msg->size, 1105 msg->size,
1094 msg->size + s->overhead); 1106 msg->size + s->overhead);
1095 s->overhead = 0; 1107 s->overhead = 0;
1096 GNUNET_free(msg); 1108 GNUNET_free (msg);
1097 } 1109 }
1098 notify_session_monitor(plugin, 1110 notify_session_monitor (plugin,
1099 s, 1111 s,
1100 GNUNET_TRANSPORT_SS_UPDATE); 1112 GNUNET_TRANSPORT_SS_UPDATE);
1101 GNUNET_asprintf(&stat_txt, 1113 GNUNET_asprintf (&stat_txt,
1102 "# bytes currently in %s_client buffers", 1114 "# bytes currently in %s_client buffers",
1103 plugin->protocol); 1115 plugin->protocol);
1104 GNUNET_STATISTICS_update(plugin->env->stats, 1116 GNUNET_STATISTICS_update (plugin->env->stats,
1105 stat_txt, 1117 stat_txt,
1106 -len, 1118 -len,
1107 GNUNET_NO); 1119 GNUNET_NO);
1108 GNUNET_free(stat_txt); 1120 GNUNET_free (stat_txt);
1109 GNUNET_asprintf(&stat_txt, 1121 GNUNET_asprintf (&stat_txt,
1110 "# bytes transmitted via %s_client", 1122 "# bytes transmitted via %s_client",
1111 plugin->protocol); 1123 plugin->protocol);
1112 GNUNET_STATISTICS_update(plugin->env->stats, 1124 GNUNET_STATISTICS_update (plugin->env->stats,
1113 stat_txt, 1125 stat_txt,
1114 len, 1126 len,
1115 GNUNET_NO); 1127 GNUNET_NO);
1116 GNUNET_free(stat_txt); 1128 GNUNET_free (stat_txt);
1117 return len; 1129 return len;
1118} 1130}
1119 1131
@@ -1124,26 +1136,26 @@ client_send_cb(void *stream,
1124 * @param cls the session 1136 * @param cls the session
1125 */ 1137 */
1126static void 1138static void
1127client_wake_up(void *cls) 1139client_wake_up (void *cls)
1128{ 1140{
1129 struct GNUNET_ATS_Session *s = cls; 1141 struct GNUNET_ATS_Session *s = cls;
1130 1142
1131 s->recv_wakeup_task = NULL; 1143 s->recv_wakeup_task = NULL;
1132 LOG(GNUNET_ERROR_TYPE_DEBUG, 1144 LOG (GNUNET_ERROR_TYPE_DEBUG,
1133 "Session %p/request %p: Waking up GET handle\n", 1145 "Session %p/request %p: Waking up GET handle\n",
1134 s, s->get.easyhandle); 1146 s, s->get.easyhandle);
1135 if (H_PAUSED == s->put.state) 1147 if (H_PAUSED == s->put.state)
1136 { 1148 {
1137 /* PUT request was paused, unpause */ 1149 /* PUT request was paused, unpause */
1138 GNUNET_assert(s->put_disconnect_task != NULL); 1150 GNUNET_assert (s->put_disconnect_task != NULL);
1139 GNUNET_SCHEDULER_cancel(s->put_disconnect_task); 1151 GNUNET_SCHEDULER_cancel (s->put_disconnect_task);
1140 s->put_disconnect_task = NULL; 1152 s->put_disconnect_task = NULL;
1141 s->put.state = H_CONNECTED; 1153 s->put.state = H_CONNECTED;
1142 if (NULL != s->put.easyhandle) 1154 if (NULL != s->put.easyhandle)
1143 curl_easy_pause(s->put.easyhandle, CURLPAUSE_CONT); 1155 curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT);
1144 } 1156 }
1145 if (NULL != s->get.easyhandle) 1157 if (NULL != s->get.easyhandle)
1146 curl_easy_pause(s->get.easyhandle, CURLPAUSE_CONT); 1158 curl_easy_pause (s->get.easyhandle, CURLPAUSE_CONT);
1147} 1159}
1148 1160
1149 1161
@@ -1155,8 +1167,8 @@ client_wake_up(void *cls)
1155 * @return always #GNUNET_OK 1167 * @return always #GNUNET_OK
1156 */ 1168 */
1157static int 1169static int
1158client_receive_mst_cb(void *cls, 1170client_receive_mst_cb (void *cls,
1159 const struct GNUNET_MessageHeader *message) 1171 const struct GNUNET_MessageHeader *message)
1160{ 1172{
1161 struct GNUNET_ATS_Session *s = cls; 1173 struct GNUNET_ATS_Session *s = cls;
1162 struct HTTP_Client_Plugin *plugin; 1174 struct HTTP_Client_Plugin *plugin;
@@ -1164,32 +1176,32 @@ client_receive_mst_cb(void *cls,
1164 char *stat_txt; 1176 char *stat_txt;
1165 1177
1166 plugin = s->plugin; 1178 plugin = s->plugin;
1167 delay = s->plugin->env->receive(plugin->env->cls, 1179 delay = s->plugin->env->receive (plugin->env->cls,
1168 s->address, 1180 s->address,
1169 s, 1181 s,
1170 message); 1182 message);
1171 GNUNET_asprintf(&stat_txt, 1183 GNUNET_asprintf (&stat_txt,
1172 "# bytes received via %s_client", 1184 "# bytes received via %s_client",
1173 plugin->protocol); 1185 plugin->protocol);
1174 GNUNET_STATISTICS_update(plugin->env->stats, 1186 GNUNET_STATISTICS_update (plugin->env->stats,
1175 stat_txt, 1187 stat_txt,
1176 ntohs(message->size), 1188 ntohs (message->size),
1177 GNUNET_NO); 1189 GNUNET_NO);
1178 GNUNET_free(stat_txt); 1190 GNUNET_free (stat_txt);
1179 1191
1180 s->next_receive = GNUNET_TIME_relative_to_absolute(delay); 1192 s->next_receive = GNUNET_TIME_relative_to_absolute (delay);
1181 if (GNUNET_TIME_absolute_get().abs_value_us < s->next_receive.abs_value_us) 1193 if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us)
1182 { 1194 {
1183 LOG(GNUNET_ERROR_TYPE_DEBUG, 1195 LOG (GNUNET_ERROR_TYPE_DEBUG,
1184 "Client: peer `%s' address `%s' next read delayed for %s\n", 1196 "Client: peer `%s' address `%s' next read delayed for %s\n",
1185 GNUNET_i2s(&s->address->peer), 1197 GNUNET_i2s (&s->address->peer),
1186 http_common_plugin_address_to_string(s->plugin->protocol, 1198 http_common_plugin_address_to_string (s->plugin->protocol,
1187 s->address->address, 1199 s->address->address,
1188 s->address->address_length), 1200 s->address->address_length),
1189 GNUNET_STRINGS_relative_time_to_string(delay, 1201 GNUNET_STRINGS_relative_time_to_string (delay,
1190 GNUNET_YES)); 1202 GNUNET_YES));
1191 } 1203 }
1192 client_reschedule_session_timeout(s); 1204 client_reschedule_session_timeout (s);
1193 return GNUNET_OK; 1205 return GNUNET_OK;
1194} 1206}
1195 1207
@@ -1205,10 +1217,10 @@ client_receive_mst_cb(void *cls,
1205 * @return bytes read from stream 1217 * @return bytes read from stream
1206 */ 1218 */
1207static size_t 1219static size_t
1208client_receive_put(void *stream, 1220client_receive_put (void *stream,
1209 size_t size, 1221 size_t size,
1210 size_t nmemb, 1222 size_t nmemb,
1211 void *cls) 1223 void *cls)
1212{ 1224{
1213 return size * nmemb; 1225 return size * nmemb;
1214} 1226}
@@ -1225,53 +1237,53 @@ client_receive_put(void *stream,
1225 * @return bytes read from stream 1237 * @return bytes read from stream
1226 */ 1238 */
1227static size_t 1239static size_t
1228client_receive(void *stream, 1240client_receive (void *stream,
1229 size_t size, 1241 size_t size,
1230 size_t nmemb, 1242 size_t nmemb,
1231 void *cls) 1243 void *cls)
1232{ 1244{
1233 struct GNUNET_ATS_Session *s = cls; 1245 struct GNUNET_ATS_Session *s = cls;
1234 struct GNUNET_TIME_Absolute now; 1246 struct GNUNET_TIME_Absolute now;
1235 size_t len = size * nmemb; 1247 size_t len = size * nmemb;
1236 1248
1237 LOG(GNUNET_ERROR_TYPE_DEBUG, 1249 LOG (GNUNET_ERROR_TYPE_DEBUG,
1238 "Session %p / request %p: Received %u bytes from peer `%s'\n", 1250 "Session %p / request %p: Received %u bytes from peer `%s'\n",
1239 s, 1251 s,
1240 s->get.easyhandle, 1252 s->get.easyhandle,
1241 len, 1253 len,
1242 GNUNET_i2s(&s->address->peer)); 1254 GNUNET_i2s (&s->address->peer));
1243 now = GNUNET_TIME_absolute_get(); 1255 now = GNUNET_TIME_absolute_get ();
1244 if (now.abs_value_us < s->next_receive.abs_value_us) 1256 if (now.abs_value_us < s->next_receive.abs_value_us)
1245 { 1257 {
1246 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 1258 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
1247 struct GNUNET_TIME_Relative delta 1259 struct GNUNET_TIME_Relative delta
1248 = GNUNET_TIME_absolute_get_difference(now, s->next_receive); 1260 = GNUNET_TIME_absolute_get_difference (now, s->next_receive);
1249 1261
1250 LOG(GNUNET_ERROR_TYPE_DEBUG, 1262 LOG (GNUNET_ERROR_TYPE_DEBUG,
1251 "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n", 1263 "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n",
1252 s, 1264 s,
1253 s->get.easyhandle, 1265 s->get.easyhandle,
1254 GNUNET_STRINGS_relative_time_to_string(delta, 1266 GNUNET_STRINGS_relative_time_to_string (delta,
1255 GNUNET_YES)); 1267 GNUNET_YES));
1256 if (s->recv_wakeup_task != NULL) 1268 if (s->recv_wakeup_task != NULL)
1257 { 1269 {
1258 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); 1270 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
1259 s->recv_wakeup_task = NULL; 1271 s->recv_wakeup_task = NULL;
1260 }
1261 s->recv_wakeup_task
1262 = GNUNET_SCHEDULER_add_delayed(delta,
1263 &client_wake_up,
1264 s);
1265 return CURL_WRITEFUNC_PAUSE;
1266 } 1272 }
1273 s->recv_wakeup_task
1274 = GNUNET_SCHEDULER_add_delayed (delta,
1275 &client_wake_up,
1276 s);
1277 return CURL_WRITEFUNC_PAUSE;
1278 }
1267 if (NULL == s->msg_tk) 1279 if (NULL == s->msg_tk)
1268 s->msg_tk = GNUNET_MST_create(&client_receive_mst_cb, 1280 s->msg_tk = GNUNET_MST_create (&client_receive_mst_cb,
1269 s); 1281 s);
1270 GNUNET_MST_from_buffer(s->msg_tk, 1282 GNUNET_MST_from_buffer (s->msg_tk,
1271 stream, 1283 stream,
1272 len, 1284 len,
1273 GNUNET_NO, 1285 GNUNET_NO,
1274 GNUNET_NO); 1286 GNUNET_NO);
1275 return len; 1287 return len;
1276} 1288}
1277 1289
@@ -1282,7 +1294,7 @@ client_receive(void *stream,
1282 * @param cls plugin as closure 1294 * @param cls plugin as closure
1283 */ 1295 */
1284static void 1296static void
1285client_run(void *cls) 1297client_run (void *cls)
1286{ 1298{
1287 struct HTTP_Client_Plugin *plugin = cls; 1299 struct HTTP_Client_Plugin *plugin = cls;
1288 int running; 1300 int running;
@@ -1295,141 +1307,144 @@ client_run(void *cls)
1295 plugin->client_perform_task = NULL; 1307 plugin->client_perform_task = NULL;
1296 /* While data are available or timeouts occured */ 1308 /* While data are available or timeouts occured */
1297 do 1309 do
1310 {
1311 running = 0;
1312 /* Perform operations for all handles */
1313 mret = curl_multi_perform (plugin->curl_multi_handle, &running);
1314
1315 /* Get additional information for all handles */
1316 while (NULL != (msg = curl_multi_info_read (plugin->curl_multi_handle,
1317 &msgs_left)))
1298 { 1318 {
1299 running = 0; 1319 CURL *easy_h = msg->easy_handle;
1300 /* Perform operations for all handles */ 1320 struct GNUNET_ATS_Session *s = NULL;
1301 mret = curl_multi_perform(plugin->curl_multi_handle, &running); 1321 char *d = NULL; /* curl requires 'd' to be a 'char *' */
1322
1323 GNUNET_assert (NULL != easy_h);
1324
1325 /* Obtain session from easy handle */
1326 GNUNET_assert (CURLE_OK == curl_easy_getinfo (easy_h, CURLINFO_PRIVATE,
1327 &d));
1328 s = (struct GNUNET_ATS_Session *) d;
1329 GNUNET_assert (NULL != s);
1330
1331 if (msg->msg != CURLMSG_DONE)
1332 continue; /* This should not happen */
1333
1334 /* Get HTTP response code */
1335 GNUNET_break (CURLE_OK == curl_easy_getinfo (easy_h,
1336 CURLINFO_RESPONSE_CODE,
1337 &http_statuscode));
1338
1339 if (easy_h == s->put.easyhandle)
1340 put_request = GNUNET_YES;
1341 else
1342 put_request = GNUNET_NO;
1343
1344 /* Log status of terminated request */
1345 if ((0 != msg->data.result) || (http_statuscode != 200))
1346 LOG (GNUNET_ERROR_TYPE_DEBUG,
1347 "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n",
1348 s, msg->easy_handle,
1349 (GNUNET_YES == put_request) ? "PUT" : "GET",
1350 GNUNET_i2s (&s->address->peer),
1351 http_statuscode,
1352 msg->data.result,
1353 curl_easy_strerror (msg->data.result));
1354 else
1355 LOG (GNUNET_ERROR_TYPE_DEBUG,
1356 "Session %p/request %p: %s request to `%s' ended normal\n",
1357 s, msg->easy_handle,
1358 (GNUNET_YES == put_request) ? "PUT" : "GET",
1359 GNUNET_i2s (&s->address->peer));
1360
1361 /* Remove easy handle from multi handle */
1362 curl_multi_remove_handle (plugin->curl_multi_handle, easy_h);
1363
1364 /* Clean up easy handle */
1365 curl_easy_cleanup (easy_h);
1366
1367 /* Remove information */
1368 GNUNET_assert (plugin->cur_requests > 0);
1369 plugin->cur_requests--;
1370 LOG (GNUNET_ERROR_TYPE_INFO,
1371 "%s request to %s done, number of requests decreased to %u\n",
1372 (GNUNET_YES == put_request) ? "PUT" : "GET",
1373 s->url,
1374 plugin->cur_requests);
1302 1375
1303 /* Get additional information for all handles */ 1376 if (GNUNET_YES == put_request)
1304 while (NULL != (msg = curl_multi_info_read(plugin->curl_multi_handle, &msgs_left))) 1377 {
1378 /* Clean up a PUT request */
1379 s->put.easyhandle = NULL;
1380 s->put.s = NULL;
1381
1382 switch (s->put.state)
1383 {
1384 case H_NOT_CONNECTED:
1385 case H_DISCONNECTED:
1386 case H_TMP_DISCONNECTED:
1387 /* This must not happen */
1388 GNUNET_break (0);
1389 break;
1390
1391 case H_TMP_RECONNECT_REQUIRED:
1392 /* Transport called send while disconnect in progess, reconnect */
1393 if (GNUNET_SYSERR == client_connect_put (s))
1394 {
1395 /* Reconnect failed, disconnect session */
1396 http_client_plugin_session_disconnect (plugin, s);
1397 }
1398 break;
1399
1400 case H_TMP_DISCONNECTING:
1401 /* PUT gets temporarily disconnected */
1402 s->put.state = H_TMP_DISCONNECTED;
1403 break;
1404
1405 case H_PAUSED:
1406 case H_CONNECTED:
1407 /* PUT gets permanently disconnected */
1408 s->put.state = H_DISCONNECTED;
1409 http_client_plugin_session_disconnect (plugin, s);
1410 break;
1411
1412 default:
1413 GNUNET_break (0);
1414 break;
1415 }
1416 }
1417 else if (GNUNET_NO == put_request)
1418 {
1419 /* Clean up a GET request */
1420 s->get.easyhandle = NULL;
1421 s->get.s = NULL;
1422
1423 /* If we are emulating an XHR client we need to make another GET
1424 * request.
1425 */
1426 if (GNUNET_YES == plugin->emulate_xhr)
1427 {
1428 if (GNUNET_SYSERR == client_connect_get (s))
1429 http_client_plugin_session_disconnect (plugin, s);
1430 }
1431 else
1305 { 1432 {
1306 CURL *easy_h = msg->easy_handle; 1433 /* GET request was terminated, so disconnect session */
1307 struct GNUNET_ATS_Session *s = NULL; 1434 http_client_plugin_session_disconnect (plugin, s);
1308 char *d = NULL; /* curl requires 'd' to be a 'char *' */
1309
1310 GNUNET_assert(NULL != easy_h);
1311
1312 /* Obtain session from easy handle */
1313 GNUNET_assert(CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &d));
1314 s = (struct GNUNET_ATS_Session *)d;
1315 GNUNET_assert(NULL != s);
1316
1317 if (msg->msg != CURLMSG_DONE)
1318 continue; /* This should not happen */
1319
1320 /* Get HTTP response code */
1321 GNUNET_break(CURLE_OK == curl_easy_getinfo(easy_h,
1322 CURLINFO_RESPONSE_CODE, &http_statuscode));
1323
1324 if (easy_h == s->put.easyhandle)
1325 put_request = GNUNET_YES;
1326 else
1327 put_request = GNUNET_NO;
1328
1329 /* Log status of terminated request */
1330 if ((0 != msg->data.result) || (http_statuscode != 200))
1331 LOG(GNUNET_ERROR_TYPE_DEBUG,
1332 "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n",
1333 s, msg->easy_handle,
1334 (GNUNET_YES == put_request) ? "PUT" : "GET",
1335 GNUNET_i2s(&s->address->peer),
1336 http_statuscode,
1337 msg->data.result,
1338 curl_easy_strerror(msg->data.result));
1339 else
1340 LOG(GNUNET_ERROR_TYPE_DEBUG,
1341 "Session %p/request %p: %s request to `%s' ended normal\n",
1342 s, msg->easy_handle,
1343 (GNUNET_YES == put_request) ? "PUT" : "GET",
1344 GNUNET_i2s(&s->address->peer));
1345
1346 /* Remove easy handle from multi handle */
1347 curl_multi_remove_handle(plugin->curl_multi_handle, easy_h);
1348
1349 /* Clean up easy handle */
1350 curl_easy_cleanup(easy_h);
1351
1352 /* Remove information */
1353 GNUNET_assert(plugin->cur_requests > 0);
1354 plugin->cur_requests--;
1355 LOG(GNUNET_ERROR_TYPE_INFO,
1356 "%s request to %s done, number of requests decreased to %u\n",
1357 (GNUNET_YES == put_request) ? "PUT" : "GET",
1358 s->url,
1359 plugin->cur_requests);
1360
1361 if (GNUNET_YES == put_request)
1362 {
1363 /* Clean up a PUT request */
1364 s->put.easyhandle = NULL;
1365 s->put.s = NULL;
1366
1367 switch (s->put.state)
1368 {
1369 case H_NOT_CONNECTED:
1370 case H_DISCONNECTED:
1371 case H_TMP_DISCONNECTED:
1372 /* This must not happen */
1373 GNUNET_break(0);
1374 break;
1375
1376 case H_TMP_RECONNECT_REQUIRED:
1377 /* Transport called send while disconnect in progess, reconnect */
1378 if (GNUNET_SYSERR == client_connect_put(s))
1379 {
1380 /* Reconnect failed, disconnect session */
1381 http_client_plugin_session_disconnect(plugin, s);
1382 }
1383 break;
1384
1385 case H_TMP_DISCONNECTING:
1386 /* PUT gets temporarily disconnected */
1387 s->put.state = H_TMP_DISCONNECTED;
1388 break;
1389
1390 case H_PAUSED:
1391 case H_CONNECTED:
1392 /* PUT gets permanently disconnected */
1393 s->put.state = H_DISCONNECTED;
1394 http_client_plugin_session_disconnect(plugin, s);
1395 break;
1396
1397 default:
1398 GNUNET_break(0);
1399 break;
1400 }
1401 }
1402 else if (GNUNET_NO == put_request)
1403 {
1404 /* Clean up a GET request */
1405 s->get.easyhandle = NULL;
1406 s->get.s = NULL;
1407
1408 /* If we are emulating an XHR client we need to make another GET
1409 * request.
1410 */
1411 if (GNUNET_YES == plugin->emulate_xhr)
1412 {
1413 if (GNUNET_SYSERR == client_connect_get(s))
1414 http_client_plugin_session_disconnect(plugin, s);
1415 }
1416 else
1417 {
1418 /* GET request was terminated, so disconnect session */
1419 http_client_plugin_session_disconnect(plugin, s);
1420 }
1421 }
1422 else
1423 GNUNET_break(0); /* Must not happen */
1424
1425 GNUNET_STATISTICS_set(plugin->env->stats,
1426 HTTP_STAT_STR_CONNECTIONS,
1427 plugin->cur_requests,
1428 GNUNET_NO);
1429 } 1435 }
1436 }
1437 else
1438 GNUNET_break (0); /* Must not happen */
1439
1440 GNUNET_STATISTICS_set (plugin->env->stats,
1441 HTTP_STAT_STR_CONNECTIONS,
1442 plugin->cur_requests,
1443 GNUNET_NO);
1430 } 1444 }
1445 }
1431 while (mret == CURLM_CALL_MULTI_PERFORM); 1446 while (mret == CURLM_CALL_MULTI_PERFORM);
1432 client_schedule(plugin, GNUNET_NO); 1447 client_schedule (plugin, GNUNET_NO);
1433} 1448}
1434 1449
1435 1450
@@ -1443,51 +1458,51 @@ client_run(void *cls)
1443 * @return opened socket 1458 * @return opened socket
1444 */ 1459 */
1445static curl_socket_t 1460static curl_socket_t
1446open_tcp_stealth_socket_cb(void *clientp, 1461open_tcp_stealth_socket_cb (void *clientp,
1447 curlsocktype purpose, 1462 curlsocktype purpose,
1448 struct curl_sockaddr *address) 1463 struct curl_sockaddr *address)
1449{ 1464{
1450 struct GNUNET_ATS_Session *s = clientp; 1465 struct GNUNET_ATS_Session *s = clientp;
1451 int ret; 1466 int ret;
1452 1467
1453 switch (purpose) 1468 switch (purpose)
1469 {
1470 case CURLSOCKTYPE_IPCXN:
1471 ret = socket (address->family,
1472 address->socktype,
1473 address->protocol);
1474 if (-1 == ret)
1475 return CURL_SOCKET_BAD;
1476 if (((SOCK_STREAM != address->socktype) ||
1477 ((0 != address->protocol) &&
1478 (IPPROTO_TCP != address->protocol))))
1479 return (curl_socket_t) ret;
1480 if ((0 != setsockopt (ret,
1481 IPPROTO_TCP,
1482 TCP_STEALTH,
1483 &s->address->peer,
1484 sizeof(struct GNUNET_PeerIdentity))))
1454 { 1485 {
1455 case CURLSOCKTYPE_IPCXN: 1486 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1456 ret = socket(address->family, 1487 _ ("TCP_STEALTH not supported on this platform.\n"));
1457 address->socktype, 1488 (void) close (ret);
1458 address->protocol);
1459 if (-1 == ret)
1460 return CURL_SOCKET_BAD;
1461 if (((SOCK_STREAM != address->socktype) ||
1462 ((0 != address->protocol) &&
1463 (IPPROTO_TCP != address->protocol))))
1464 return (curl_socket_t)ret;
1465 if ((0 != setsockopt(ret,
1466 IPPROTO_TCP,
1467 TCP_STEALTH,
1468 &s->address->peer,
1469 sizeof(struct GNUNET_PeerIdentity))))
1470 {
1471 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1472 _("TCP_STEALTH not supported on this platform.\n"));
1473 (void)close(ret);
1474 return CURL_SOCKET_BAD;
1475 }
1476 return (curl_socket_t)ret;
1477
1478 case CURLSOCKTYPE_ACCEPT:
1479 GNUNET_break(0);
1480 return CURL_SOCKET_BAD; 1489 return CURL_SOCKET_BAD;
1481 break; 1490 }
1491 return (curl_socket_t) ret;
1482 1492
1483 case CURLSOCKTYPE_LAST: 1493 case CURLSOCKTYPE_ACCEPT:
1484 GNUNET_break(0); 1494 GNUNET_break (0);
1485 return CURL_SOCKET_BAD; 1495 return CURL_SOCKET_BAD;
1496 break;
1486 1497
1487 default: 1498 case CURLSOCKTYPE_LAST:
1488 GNUNET_break(0); 1499 GNUNET_break (0);
1489 return CURL_SOCKET_BAD; 1500 return CURL_SOCKET_BAD;
1490 } 1501
1502 default:
1503 GNUNET_break (0);
1504 return CURL_SOCKET_BAD;
1505 }
1491} 1506}
1492#endif 1507#endif
1493 1508
@@ -1499,175 +1514,177 @@ open_tcp_stealth_socket_cb(void *clientp,
1499 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 1514 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1500 */ 1515 */
1501static int 1516static int
1502client_connect_get(struct GNUNET_ATS_Session *s) 1517client_connect_get (struct GNUNET_ATS_Session *s)
1503{ 1518{
1504 CURLMcode mret; 1519 CURLMcode mret;
1505 struct HttpAddress *ha; 1520 struct HttpAddress *ha;
1506 uint32_t options; 1521 uint32_t options;
1507 1522
1508 ha = (struct HttpAddress *)s->address->address; 1523 ha = (struct HttpAddress *) s->address->address;
1509 options = ntohl(ha->options); 1524 options = ntohl (ha->options);
1510 /* create get request */ 1525 /* create get request */
1511 s->get.easyhandle = curl_easy_init(); 1526 s->get.easyhandle = curl_easy_init ();
1512 s->get.s = s; 1527 s->get.s = s;
1513 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH)) 1528 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1514 { 1529 {
1515#ifdef TCP_STEALTH 1530#ifdef TCP_STEALTH
1516 curl_easy_setopt(s->get.easyhandle, 1531 curl_easy_setopt (s->get.easyhandle,
1517 CURLOPT_OPENSOCKETFUNCTION, 1532 CURLOPT_OPENSOCKETFUNCTION,
1518 &open_tcp_stealth_socket_cb); 1533 &open_tcp_stealth_socket_cb);
1519 curl_easy_setopt(s->get.easyhandle, 1534 curl_easy_setopt (s->get.easyhandle,
1520 CURLOPT_OPENSOCKETDATA, 1535 CURLOPT_OPENSOCKETDATA,
1521 s); 1536 s);
1522#else 1537#else
1523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1524 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n"); 1539 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1525 curl_easy_cleanup(s->get.easyhandle); 1540 curl_easy_cleanup (s->get.easyhandle);
1526 s->get.easyhandle = NULL; 1541 s->get.easyhandle = NULL;
1527 s->get.s = NULL; 1542 s->get.s = NULL;
1528 return GNUNET_SYSERR; 1543 return GNUNET_SYSERR;
1529#endif 1544#endif
1530 } 1545 }
1531 1546
1532#if VERBOSE_CURL 1547#if VERBOSE_CURL
1533 curl_easy_setopt(s->get.easyhandle, 1548 curl_easy_setopt (s->get.easyhandle,
1534 CURLOPT_VERBOSE, 1549 CURLOPT_VERBOSE,
1535 1L); 1550 1L);
1536 curl_easy_setopt(s->get.easyhandle, 1551 curl_easy_setopt (s->get.easyhandle,
1537 CURLOPT_DEBUGFUNCTION, 1552 CURLOPT_DEBUGFUNCTION,
1538 &client_log); 1553 &client_log);
1539 curl_easy_setopt(s->get.easyhandle, 1554 curl_easy_setopt (s->get.easyhandle,
1540 CURLOPT_DEBUGDATA, 1555 CURLOPT_DEBUGDATA,
1541 &s->get); 1556 &s->get);
1542#endif 1557#endif
1543#if BUILD_HTTPS 1558#if BUILD_HTTPS
1544 curl_easy_setopt(s->get.easyhandle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); 1559 curl_easy_setopt (s->get.easyhandle, CURLOPT_SSLVERSION,
1560 CURL_SSLVERSION_TLSv1);
1545 { 1561 {
1546 if (HTTP_OPTIONS_VERIFY_CERTIFICATE == 1562 if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
1547 (options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) 1563 (options & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1548 { 1564 {
1549 curl_easy_setopt(s->get.easyhandle, 1565 curl_easy_setopt (s->get.easyhandle,
1550 CURLOPT_SSL_VERIFYPEER, 1L); 1566 CURLOPT_SSL_VERIFYPEER, 1L);
1551 curl_easy_setopt(s->get.easyhandle, 1567 curl_easy_setopt (s->get.easyhandle,
1552 CURLOPT_SSL_VERIFYHOST, 1568 CURLOPT_SSL_VERIFYHOST,
1553 2L); 1569 2L);
1554 } 1570 }
1555 else 1571 else
1556 { 1572 {
1557 curl_easy_setopt(s->get.easyhandle, 1573 curl_easy_setopt (s->get.easyhandle,
1558 CURLOPT_SSL_VERIFYPEER, 1574 CURLOPT_SSL_VERIFYPEER,
1559 0L); 1575 0L);
1560 curl_easy_setopt(s->get.easyhandle, 1576 curl_easy_setopt (s->get.easyhandle,
1561 CURLOPT_SSL_VERIFYHOST, 1577 CURLOPT_SSL_VERIFYHOST,
1562 0L); 1578 0L);
1563 } 1579 }
1564 } 1580 }
1565 curl_easy_setopt(s->get.easyhandle, 1581 curl_easy_setopt (s->get.easyhandle,
1566 CURLOPT_PROTOCOLS, 1582 CURLOPT_PROTOCOLS,
1567 CURLPROTO_HTTPS); 1583 CURLPROTO_HTTPS);
1568 curl_easy_setopt(s->get.easyhandle, 1584 curl_easy_setopt (s->get.easyhandle,
1569 CURLOPT_REDIR_PROTOCOLS, 1585 CURLOPT_REDIR_PROTOCOLS,
1570 CURLPROTO_HTTPS); 1586 CURLPROTO_HTTPS);
1571#else 1587#else
1572 curl_easy_setopt(s->get.easyhandle, 1588 curl_easy_setopt (s->get.easyhandle,
1573 CURLOPT_PROTOCOLS, 1589 CURLOPT_PROTOCOLS,
1574 CURLPROTO_HTTP); 1590 CURLPROTO_HTTP);
1575 curl_easy_setopt(s->get.easyhandle, 1591 curl_easy_setopt (s->get.easyhandle,
1576 CURLOPT_REDIR_PROTOCOLS, 1592 CURLOPT_REDIR_PROTOCOLS,
1577 CURLPROTO_HTTP); 1593 CURLPROTO_HTTP);
1578#endif 1594#endif
1579 1595
1580 if (NULL != s->plugin->proxy_hostname) 1596 if (NULL != s->plugin->proxy_hostname)
1581 { 1597 {
1582 curl_easy_setopt(s->get.easyhandle, 1598 curl_easy_setopt (s->get.easyhandle,
1583 CURLOPT_PROXY, 1599 CURLOPT_PROXY,
1584 s->plugin->proxy_hostname); 1600 s->plugin->proxy_hostname);
1585 curl_easy_setopt(s->get.easyhandle, 1601 curl_easy_setopt (s->get.easyhandle,
1586 CURLOPT_PROXYTYPE, 1602 CURLOPT_PROXYTYPE,
1587 s->plugin->proxytype); 1603 s->plugin->proxytype);
1588 if (NULL != s->plugin->proxy_username) 1604 if (NULL != s->plugin->proxy_username)
1589 curl_easy_setopt(s->get.easyhandle, 1605 curl_easy_setopt (s->get.easyhandle,
1590 CURLOPT_PROXYUSERNAME, 1606 CURLOPT_PROXYUSERNAME,
1591 s->plugin->proxy_username); 1607 s->plugin->proxy_username);
1592 if (NULL != s->plugin->proxy_password) 1608 if (NULL != s->plugin->proxy_password)
1593 curl_easy_setopt(s->get.easyhandle, 1609 curl_easy_setopt (s->get.easyhandle,
1594 CURLOPT_PROXYPASSWORD, 1610 CURLOPT_PROXYPASSWORD,
1595 s->plugin->proxy_password); 1611 s->plugin->proxy_password);
1596 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) 1612 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1597 curl_easy_setopt(s->get.easyhandle, 1613 curl_easy_setopt (s->get.easyhandle,
1598 CURLOPT_HTTPPROXYTUNNEL, 1614 CURLOPT_HTTPPROXYTUNNEL,
1599 s->plugin->proxy_use_httpproxytunnel); 1615 s->plugin->proxy_use_httpproxytunnel);
1600 } 1616 }
1601 1617
1602 if (GNUNET_YES == s->plugin->emulate_xhr) 1618 if (GNUNET_YES == s->plugin->emulate_xhr)
1603 { 1619 {
1604 char *url; 1620 char *url;
1605 1621
1606 GNUNET_asprintf(&url, 1622 GNUNET_asprintf (&url,
1607 "%s,1", 1623 "%s,1",
1608 s->url); 1624 s->url);
1609 curl_easy_setopt(s->get.easyhandle, 1625 curl_easy_setopt (s->get.easyhandle,
1610 CURLOPT_URL, 1626 CURLOPT_URL,
1611 url); 1627 url);
1612 GNUNET_free(url); 1628 GNUNET_free (url);
1613 } 1629 }
1614 else 1630 else
1615 { 1631 {
1616 curl_easy_setopt(s->get.easyhandle, 1632 curl_easy_setopt (s->get.easyhandle,
1617 CURLOPT_URL, 1633 CURLOPT_URL,
1618 s->url); 1634 s->url);
1619 } 1635 }
1620 curl_easy_setopt(s->get.easyhandle, 1636 curl_easy_setopt (s->get.easyhandle,
1621 CURLOPT_READFUNCTION, 1637 CURLOPT_READFUNCTION,
1622 &client_send_cb); 1638 &client_send_cb);
1623 curl_easy_setopt(s->get.easyhandle, 1639 curl_easy_setopt (s->get.easyhandle,
1624 CURLOPT_READDATA, 1640 CURLOPT_READDATA,
1625 s); 1641 s);
1626 curl_easy_setopt(s->get.easyhandle, 1642 curl_easy_setopt (s->get.easyhandle,
1627 CURLOPT_WRITEFUNCTION, 1643 CURLOPT_WRITEFUNCTION,
1628 &client_receive); 1644 &client_receive);
1629 curl_easy_setopt(s->get.easyhandle, 1645 curl_easy_setopt (s->get.easyhandle,
1630 CURLOPT_WRITEDATA, 1646 CURLOPT_WRITEDATA,
1631 s); 1647 s);
1632 /* No timeout by default, timeout done with session timeout */ 1648 /* No timeout by default, timeout done with session timeout */
1633 curl_easy_setopt(s->get.easyhandle, 1649 curl_easy_setopt (s->get.easyhandle,
1634 CURLOPT_TIMEOUT, 1650 CURLOPT_TIMEOUT,
1635 0L); 1651 0L);
1636 curl_easy_setopt(s->get.easyhandle, 1652 curl_easy_setopt (s->get.easyhandle,
1637 CURLOPT_PRIVATE, s); 1653 CURLOPT_PRIVATE, s);
1638 curl_easy_setopt(s->get.easyhandle, 1654 curl_easy_setopt (s->get.easyhandle,
1639 CURLOPT_CONNECTTIMEOUT_MS, 1655 CURLOPT_CONNECTTIMEOUT_MS,
1640 (long)(HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL)); 1656 (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us
1641 curl_easy_setopt(s->get.easyhandle, CURLOPT_BUFFERSIZE, 1657 / 1000LL));
1642 2 * GNUNET_MAX_MESSAGE_SIZE); 1658 curl_easy_setopt (s->get.easyhandle, CURLOPT_BUFFERSIZE,
1659 2 * GNUNET_MAX_MESSAGE_SIZE);
1643#if CURL_TCP_NODELAY 1660#if CURL_TCP_NODELAY
1644 curl_easy_setopt(ps->recv_endpoint, 1661 curl_easy_setopt (ps->recv_endpoint,
1645 CURLOPT_TCP_NODELAY, 1662 CURLOPT_TCP_NODELAY,
1646 1L); 1663 1L);
1647#endif 1664#endif
1648 curl_easy_setopt(s->get.easyhandle, 1665 curl_easy_setopt (s->get.easyhandle,
1649 CURLOPT_FOLLOWLOCATION, 1666 CURLOPT_FOLLOWLOCATION,
1650 0L); 1667 0L);
1651 1668
1652 mret = curl_multi_add_handle(s->plugin->curl_multi_handle, 1669 mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1653 s->get.easyhandle); 1670 s->get.easyhandle);
1654 if (CURLM_OK != mret) 1671 if (CURLM_OK != mret)
1655 { 1672 {
1656 LOG(GNUNET_ERROR_TYPE_ERROR, 1673 LOG (GNUNET_ERROR_TYPE_ERROR,
1657 "Session %p : Failed to add GET handle to multihandle: `%s'\n", 1674 "Session %p : Failed to add GET handle to multihandle: `%s'\n",
1658 s, 1675 s,
1659 curl_multi_strerror(mret)); 1676 curl_multi_strerror (mret));
1660 curl_easy_cleanup(s->get.easyhandle); 1677 curl_easy_cleanup (s->get.easyhandle);
1661 s->get.easyhandle = NULL; 1678 s->get.easyhandle = NULL;
1662 s->get.s = NULL; 1679 s->get.s = NULL;
1663 GNUNET_break(0); 1680 GNUNET_break (0);
1664 return GNUNET_SYSERR; 1681 return GNUNET_SYSERR;
1665 } 1682 }
1666 s->plugin->cur_requests++; 1683 s->plugin->cur_requests++;
1667 LOG(GNUNET_ERROR_TYPE_INFO, 1684 LOG (GNUNET_ERROR_TYPE_INFO,
1668 "GET request `%s' established, number of requests increased to %u\n", 1685 "GET request `%s' established, number of requests increased to %u\n",
1669 s->url, 1686 s->url,
1670 s->plugin->cur_requests); 1687 s->plugin->cur_requests);
1671 return GNUNET_OK; 1688 return GNUNET_OK;
1672} 1689}
1673 1690
@@ -1679,166 +1696,167 @@ client_connect_get(struct GNUNET_ATS_Session *s)
1679 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok 1696 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok
1680 */ 1697 */
1681static int 1698static int
1682client_connect_put(struct GNUNET_ATS_Session *s) 1699client_connect_put (struct GNUNET_ATS_Session *s)
1683{ 1700{
1684 CURLMcode mret; 1701 CURLMcode mret;
1685 struct HttpAddress *ha; 1702 struct HttpAddress *ha;
1686 uint32_t options; 1703 uint32_t options;
1687 1704
1688 ha = (struct HttpAddress *)s->address->address; 1705 ha = (struct HttpAddress *) s->address->address;
1689 options = ntohl(ha->options); 1706 options = ntohl (ha->options);
1690 /* create put request */ 1707 /* create put request */
1691 LOG(GNUNET_ERROR_TYPE_DEBUG, 1708 LOG (GNUNET_ERROR_TYPE_DEBUG,
1692 "Session %p: Init PUT handle\n", 1709 "Session %p: Init PUT handle\n",
1693 s); 1710 s);
1694 s->put.easyhandle = curl_easy_init(); 1711 s->put.easyhandle = curl_easy_init ();
1695 s->put.s = s; 1712 s->put.s = s;
1696#if VERBOSE_CURL 1713#if VERBOSE_CURL
1697 curl_easy_setopt(s->put.easyhandle, 1714 curl_easy_setopt (s->put.easyhandle,
1698 CURLOPT_VERBOSE, 1715 CURLOPT_VERBOSE,
1699 1L); 1716 1L);
1700 curl_easy_setopt(s->put.easyhandle, 1717 curl_easy_setopt (s->put.easyhandle,
1701 CURLOPT_DEBUGFUNCTION, 1718 CURLOPT_DEBUGFUNCTION,
1702 &client_log); 1719 &client_log);
1703 curl_easy_setopt(s->put.easyhandle, 1720 curl_easy_setopt (s->put.easyhandle,
1704 CURLOPT_DEBUGDATA, 1721 CURLOPT_DEBUGDATA,
1705 &s->put); 1722 &s->put);
1706#endif 1723#endif
1707 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH)) 1724 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1708 { 1725 {
1709#ifdef TCP_STEALTH 1726#ifdef TCP_STEALTH
1710 curl_easy_setopt(s->put.easyhandle, 1727 curl_easy_setopt (s->put.easyhandle,
1711 CURLOPT_OPENSOCKETFUNCTION, 1728 CURLOPT_OPENSOCKETFUNCTION,
1712 &open_tcp_stealth_socket_cb); 1729 &open_tcp_stealth_socket_cb);
1713 curl_easy_setopt(s->put.easyhandle, 1730 curl_easy_setopt (s->put.easyhandle,
1714 CURLOPT_OPENSOCKETDATA, 1731 CURLOPT_OPENSOCKETDATA,
1715 s); 1732 s);
1716#else 1733#else
1717 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1718 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n"); 1735 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1719 curl_easy_cleanup(s->put.easyhandle); 1736 curl_easy_cleanup (s->put.easyhandle);
1720 s->put.easyhandle = NULL; 1737 s->put.easyhandle = NULL;
1721 s->put.s = NULL; 1738 s->put.s = NULL;
1722 s->put.state = H_DISCONNECTED; 1739 s->put.state = H_DISCONNECTED;
1723 return GNUNET_SYSERR; 1740 return GNUNET_SYSERR;
1724#endif 1741#endif
1725 } 1742 }
1726#if BUILD_HTTPS 1743#if BUILD_HTTPS
1727 curl_easy_setopt(s->put.easyhandle, 1744 curl_easy_setopt (s->put.easyhandle,
1728 CURLOPT_SSLVERSION, 1745 CURLOPT_SSLVERSION,
1729 CURL_SSLVERSION_TLSv1); 1746 CURL_SSLVERSION_TLSv1);
1730 { 1747 {
1731 struct HttpAddress *ha; 1748 struct HttpAddress *ha;
1732 ha = (struct HttpAddress *)s->address->address; 1749 ha = (struct HttpAddress *) s->address->address;
1733 1750
1734 if (HTTP_OPTIONS_VERIFY_CERTIFICATE == 1751 if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
1735 (ntohl(ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) 1752 (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1736 { 1753 {
1737 curl_easy_setopt(s->put.easyhandle, 1754 curl_easy_setopt (s->put.easyhandle,
1738 CURLOPT_SSL_VERIFYPEER, 1755 CURLOPT_SSL_VERIFYPEER,
1739 1L); 1756 1L);
1740 curl_easy_setopt(s->put.easyhandle, 1757 curl_easy_setopt (s->put.easyhandle,
1741 CURLOPT_SSL_VERIFYHOST, 1758 CURLOPT_SSL_VERIFYHOST,
1742 2L); 1759 2L);
1743 } 1760 }
1744 else 1761 else
1745 { 1762 {
1746 curl_easy_setopt(s->put.easyhandle, 1763 curl_easy_setopt (s->put.easyhandle,
1747 CURLOPT_SSL_VERIFYPEER, 1764 CURLOPT_SSL_VERIFYPEER,
1748 0L); 1765 0L);
1749 curl_easy_setopt(s->put.easyhandle, 1766 curl_easy_setopt (s->put.easyhandle,
1750 CURLOPT_SSL_VERIFYHOST, 1767 CURLOPT_SSL_VERIFYHOST,
1751 0L); 1768 0L);
1752 } 1769 }
1753 } 1770 }
1754 curl_easy_setopt(s->put.easyhandle, 1771 curl_easy_setopt (s->put.easyhandle,
1755 CURLOPT_PROTOCOLS, 1772 CURLOPT_PROTOCOLS,
1756 CURLPROTO_HTTPS); 1773 CURLPROTO_HTTPS);
1757 curl_easy_setopt(s->put.easyhandle, 1774 curl_easy_setopt (s->put.easyhandle,
1758 CURLOPT_REDIR_PROTOCOLS, 1775 CURLOPT_REDIR_PROTOCOLS,
1759 CURLPROTO_HTTPS); 1776 CURLPROTO_HTTPS);
1760#else 1777#else
1761 curl_easy_setopt(s->put.easyhandle, 1778 curl_easy_setopt (s->put.easyhandle,
1762 CURLOPT_PROTOCOLS, 1779 CURLOPT_PROTOCOLS,
1763 CURLPROTO_HTTP); 1780 CURLPROTO_HTTP);
1764 curl_easy_setopt(s->put.easyhandle, 1781 curl_easy_setopt (s->put.easyhandle,
1765 CURLOPT_REDIR_PROTOCOLS, 1782 CURLOPT_REDIR_PROTOCOLS,
1766 CURLPROTO_HTTP); 1783 CURLPROTO_HTTP);
1767#endif 1784#endif
1768 if (NULL != s->plugin->proxy_hostname) 1785 if (NULL != s->plugin->proxy_hostname)
1769 { 1786 {
1770 curl_easy_setopt(s->put.easyhandle, 1787 curl_easy_setopt (s->put.easyhandle,
1771 CURLOPT_PROXY, 1788 CURLOPT_PROXY,
1772 s->plugin->proxy_hostname); 1789 s->plugin->proxy_hostname);
1773 curl_easy_setopt(s->put.easyhandle, 1790 curl_easy_setopt (s->put.easyhandle,
1774 CURLOPT_PROXYTYPE, 1791 CURLOPT_PROXYTYPE,
1775 s->plugin->proxytype); 1792 s->plugin->proxytype);
1776 if (NULL != s->plugin->proxy_username) 1793 if (NULL != s->plugin->proxy_username)
1777 curl_easy_setopt(s->put.easyhandle, 1794 curl_easy_setopt (s->put.easyhandle,
1778 CURLOPT_PROXYUSERNAME, 1795 CURLOPT_PROXYUSERNAME,
1779 s->plugin->proxy_username); 1796 s->plugin->proxy_username);
1780 if (NULL != s->plugin->proxy_password) 1797 if (NULL != s->plugin->proxy_password)
1781 curl_easy_setopt(s->put.easyhandle, 1798 curl_easy_setopt (s->put.easyhandle,
1782 CURLOPT_PROXYPASSWORD, 1799 CURLOPT_PROXYPASSWORD,
1783 s->plugin->proxy_password); 1800 s->plugin->proxy_password);
1784 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) 1801 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1785 curl_easy_setopt(s->put.easyhandle, 1802 curl_easy_setopt (s->put.easyhandle,
1786 CURLOPT_HTTPPROXYTUNNEL, 1803 CURLOPT_HTTPPROXYTUNNEL,
1787 s->plugin->proxy_use_httpproxytunnel); 1804 s->plugin->proxy_use_httpproxytunnel);
1788 } 1805 }
1789 1806
1790 curl_easy_setopt(s->put.easyhandle, 1807 curl_easy_setopt (s->put.easyhandle,
1791 CURLOPT_URL, 1808 CURLOPT_URL,
1792 s->url); 1809 s->url);
1793 curl_easy_setopt(s->put.easyhandle, 1810 curl_easy_setopt (s->put.easyhandle,
1794 CURLOPT_UPLOAD, 1811 CURLOPT_UPLOAD,
1795 1L); 1812 1L);
1796 curl_easy_setopt(s->put.easyhandle, 1813 curl_easy_setopt (s->put.easyhandle,
1797 CURLOPT_READFUNCTION, 1814 CURLOPT_READFUNCTION,
1798 &client_send_cb); 1815 &client_send_cb);
1799 curl_easy_setopt(s->put.easyhandle, 1816 curl_easy_setopt (s->put.easyhandle,
1800 CURLOPT_READDATA, 1817 CURLOPT_READDATA,
1801 s); 1818 s);
1802 curl_easy_setopt(s->put.easyhandle, 1819 curl_easy_setopt (s->put.easyhandle,
1803 CURLOPT_WRITEFUNCTION, 1820 CURLOPT_WRITEFUNCTION,
1804 &client_receive_put); 1821 &client_receive_put);
1805 curl_easy_setopt(s->put.easyhandle, 1822 curl_easy_setopt (s->put.easyhandle,
1806 CURLOPT_WRITEDATA, 1823 CURLOPT_WRITEDATA,
1807 s); 1824 s);
1808 /* No timeout by default, timeout done with session timeout */ 1825 /* No timeout by default, timeout done with session timeout */
1809 curl_easy_setopt(s->put.easyhandle, 1826 curl_easy_setopt (s->put.easyhandle,
1810 CURLOPT_TIMEOUT, 1827 CURLOPT_TIMEOUT,
1811 0L); 1828 0L);
1812 curl_easy_setopt(s->put.easyhandle, 1829 curl_easy_setopt (s->put.easyhandle,
1813 CURLOPT_PRIVATE, 1830 CURLOPT_PRIVATE,
1814 s); 1831 s);
1815 curl_easy_setopt(s->put.easyhandle, 1832 curl_easy_setopt (s->put.easyhandle,
1816 CURLOPT_CONNECTTIMEOUT_MS, 1833 CURLOPT_CONNECTTIMEOUT_MS,
1817 (long)(HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL)); 1834 (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us
1818 curl_easy_setopt(s->put.easyhandle, CURLOPT_BUFFERSIZE, 1835 / 1000LL));
1819 2 * GNUNET_MAX_MESSAGE_SIZE); 1836 curl_easy_setopt (s->put.easyhandle, CURLOPT_BUFFERSIZE,
1837 2 * GNUNET_MAX_MESSAGE_SIZE);
1820#if CURL_TCP_NODELAY 1838#if CURL_TCP_NODELAY
1821 curl_easy_setopt(s->put.easyhandle, CURLOPT_TCP_NODELAY, 1); 1839 curl_easy_setopt (s->put.easyhandle, CURLOPT_TCP_NODELAY, 1);
1822#endif 1840#endif
1823 mret = curl_multi_add_handle(s->plugin->curl_multi_handle, 1841 mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1824 s->put.easyhandle); 1842 s->put.easyhandle);
1825 if (CURLM_OK != mret) 1843 if (CURLM_OK != mret)
1826 { 1844 {
1827 LOG(GNUNET_ERROR_TYPE_ERROR, 1845 LOG (GNUNET_ERROR_TYPE_ERROR,
1828 "Session %p : Failed to add PUT handle to multihandle: `%s'\n", 1846 "Session %p : Failed to add PUT handle to multihandle: `%s'\n",
1829 s, curl_multi_strerror(mret)); 1847 s, curl_multi_strerror (mret));
1830 curl_easy_cleanup(s->put.easyhandle); 1848 curl_easy_cleanup (s->put.easyhandle);
1831 s->put.easyhandle = NULL; 1849 s->put.easyhandle = NULL;
1832 s->put.s = NULL; 1850 s->put.s = NULL;
1833 s->put.state = H_DISCONNECTED; 1851 s->put.state = H_DISCONNECTED;
1834 return GNUNET_SYSERR; 1852 return GNUNET_SYSERR;
1835 } 1853 }
1836 s->put.state = H_CONNECTED; 1854 s->put.state = H_CONNECTED;
1837 s->plugin->cur_requests++; 1855 s->plugin->cur_requests++;
1838 1856
1839 LOG(GNUNET_ERROR_TYPE_INFO, 1857 LOG (GNUNET_ERROR_TYPE_INFO,
1840 "PUT request `%s' established, number of requests increased to %u\n", 1858 "PUT request `%s' established, number of requests increased to %u\n",
1841 s->url, s->plugin->cur_requests); 1859 s->url, s->plugin->cur_requests);
1842 1860
1843 return GNUNET_OK; 1861 return GNUNET_OK;
1844} 1862}
@@ -1851,67 +1869,67 @@ client_connect_put(struct GNUNET_ATS_Session *s)
1851 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 1869 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1852 */ 1870 */
1853static int 1871static int
1854client_connect(struct GNUNET_ATS_Session *s) 1872client_connect (struct GNUNET_ATS_Session *s)
1855{ 1873{
1856 struct HTTP_Client_Plugin *plugin = s->plugin; 1874 struct HTTP_Client_Plugin *plugin = s->plugin;
1857 int res = GNUNET_OK; 1875 int res = GNUNET_OK;
1858 1876
1859 /* create url */ 1877 /* create url */
1860 if (NULL == 1878 if (NULL ==
1861 http_common_plugin_address_to_string(plugin->protocol, 1879 http_common_plugin_address_to_string (plugin->protocol,
1862 s->address->address, 1880 s->address->address,
1863 s->address->address_length)) 1881 s->address->address_length))
1864 { 1882 {
1865 LOG(GNUNET_ERROR_TYPE_DEBUG, 1883 LOG (GNUNET_ERROR_TYPE_DEBUG,
1866 "Invalid address peer `%s'\n", 1884 "Invalid address peer `%s'\n",
1867 GNUNET_i2s(&s->address->peer)); 1885 GNUNET_i2s (&s->address->peer));
1868 return GNUNET_SYSERR; 1886 return GNUNET_SYSERR;
1869 } 1887 }
1870 1888
1871 GNUNET_asprintf(&s->url, 1889 GNUNET_asprintf (&s->url,
1872 "%s/%s;%u", 1890 "%s/%s;%u",
1873 http_common_plugin_address_to_url(NULL, 1891 http_common_plugin_address_to_url (NULL,
1874 s->address->address, 1892 s->address->address,
1875 s->address->address_length), 1893 s->address->address_length),
1876 GNUNET_i2s_full(plugin->env->my_identity), 1894 GNUNET_i2s_full (plugin->env->my_identity),
1877 plugin->last_tag); 1895 plugin->last_tag);
1878 1896
1879 plugin->last_tag++; 1897 plugin->last_tag++;
1880 LOG(GNUNET_ERROR_TYPE_DEBUG, 1898 LOG (GNUNET_ERROR_TYPE_DEBUG,
1881 "Initiating outbound session peer `%s' using address `%s'\n", 1899 "Initiating outbound session peer `%s' using address `%s'\n",
1882 GNUNET_i2s(&s->address->peer), s->url); 1900 GNUNET_i2s (&s->address->peer), s->url);
1883 1901
1884 if (GNUNET_SYSERR == client_connect_get(s)) 1902 if (GNUNET_SYSERR == client_connect_get (s))
1885 return GNUNET_SYSERR; 1903 return GNUNET_SYSERR;
1886 /* If we are emulating an XHR client then delay sending a PUT request until 1904 /* If we are emulating an XHR client then delay sending a PUT request until
1887 * there is something to send. 1905 * there is something to send.
1888 */ 1906 */
1889 if (GNUNET_YES == plugin->emulate_xhr) 1907 if (GNUNET_YES == plugin->emulate_xhr)
1890 { 1908 {
1891 s->put.state = H_TMP_DISCONNECTED; 1909 s->put.state = H_TMP_DISCONNECTED;
1892 } 1910 }
1893 else if (GNUNET_SYSERR == client_connect_put(s)) 1911 else if (GNUNET_SYSERR == client_connect_put (s))
1894 return GNUNET_SYSERR; 1912 return GNUNET_SYSERR;
1895 1913
1896 LOG(GNUNET_ERROR_TYPE_DEBUG, 1914 LOG (GNUNET_ERROR_TYPE_DEBUG,
1897 "Session %p: connected with GET %p and PUT %p\n", 1915 "Session %p: connected with GET %p and PUT %p\n",
1898 s, s->get.easyhandle, 1916 s, s->get.easyhandle,
1899 s->put.easyhandle); 1917 s->put.easyhandle);
1900 /* Perform connect */ 1918 /* Perform connect */
1901 GNUNET_STATISTICS_set(plugin->env->stats, 1919 GNUNET_STATISTICS_set (plugin->env->stats,
1902 HTTP_STAT_STR_CONNECTIONS, 1920 HTTP_STAT_STR_CONNECTIONS,
1903 plugin->cur_requests, 1921 plugin->cur_requests,
1904 GNUNET_NO); 1922 GNUNET_NO);
1905 /* Re-schedule since handles have changed */ 1923 /* Re-schedule since handles have changed */
1906 if (NULL != plugin->client_perform_task) 1924 if (NULL != plugin->client_perform_task)
1907 { 1925 {
1908 GNUNET_SCHEDULER_cancel(plugin->client_perform_task); 1926 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
1909 plugin->client_perform_task = NULL; 1927 plugin->client_perform_task = NULL;
1910 } 1928 }
1911 1929
1912 /* Schedule task to run immediately */ 1930 /* Schedule task to run immediately */
1913 plugin->client_perform_task = GNUNET_SCHEDULER_add_now(client_run, 1931 plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run,
1914 plugin); 1932 plugin);
1915 return res; 1933 return res;
1916} 1934}
1917 1935
@@ -1924,8 +1942,8 @@ client_connect(struct GNUNET_ATS_Session *s)
1924 * @return the network type 1942 * @return the network type
1925 */ 1943 */
1926static enum GNUNET_NetworkType 1944static enum GNUNET_NetworkType
1927http_client_plugin_get_network(void *cls, 1945http_client_plugin_get_network (void *cls,
1928 struct GNUNET_ATS_Session *session) 1946 struct GNUNET_ATS_Session *session)
1929{ 1947{
1930 return session->scope; 1948 return session->scope;
1931} 1949}
@@ -1939,13 +1957,14 @@ http_client_plugin_get_network(void *cls,
1939 * @return the network type 1957 * @return the network type
1940 */ 1958 */
1941static enum GNUNET_NetworkType 1959static enum GNUNET_NetworkType
1942http_client_plugin_get_network_for_address(void *cls, 1960http_client_plugin_get_network_for_address (void *cls,
1943 const struct GNUNET_HELLO_Address *address) 1961 const struct
1962 GNUNET_HELLO_Address *address)
1944{ 1963{
1945 struct HTTP_Client_Plugin *plugin = cls; 1964 struct HTTP_Client_Plugin *plugin = cls;
1946 1965
1947 return http_common_get_network_for_address(plugin->env, 1966 return http_common_get_network_for_address (plugin->env,
1948 address); 1967 address);
1949} 1968}
1950 1969
1951 1970
@@ -1955,33 +1974,33 @@ http_client_plugin_get_network_for_address(void *cls,
1955 * @param cls the `struct GNUNET_ATS_Session` of the idle session 1974 * @param cls the `struct GNUNET_ATS_Session` of the idle session
1956 */ 1975 */
1957static void 1976static void
1958client_session_timeout(void *cls) 1977client_session_timeout (void *cls)
1959{ 1978{
1960 struct GNUNET_ATS_Session *s = cls; 1979 struct GNUNET_ATS_Session *s = cls;
1961 struct GNUNET_TIME_Relative left; 1980 struct GNUNET_TIME_Relative left;
1962 1981
1963 s->timeout_task = NULL; 1982 s->timeout_task = NULL;
1964 left = GNUNET_TIME_absolute_get_remaining(s->timeout); 1983 left = GNUNET_TIME_absolute_get_remaining (s->timeout);
1965 if (0 != left.rel_value_us) 1984 if (0 != left.rel_value_us)
1966 { 1985 {
1967 /* not actually our turn yet, but let's at least update 1986 /* not actually our turn yet, but let's at least update
1968 the monitor, it may think we're about to die ... */ 1987 the monitor, it may think we're about to die ... */
1969 notify_session_monitor(s->plugin, 1988 notify_session_monitor (s->plugin,
1970 s, 1989 s,
1971 GNUNET_TRANSPORT_SS_UPDATE); 1990 GNUNET_TRANSPORT_SS_UPDATE);
1972 s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, 1991 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
1973 &client_session_timeout, 1992 &client_session_timeout,
1974 s); 1993 s);
1975 return; 1994 return;
1976 } 1995 }
1977 LOG(TIMEOUT_LOG, 1996 LOG (TIMEOUT_LOG,
1978 "Session %p was idle for %s, disconnecting\n", 1997 "Session %p was idle for %s, disconnecting\n",
1979 s, 1998 s,
1980 GNUNET_STRINGS_relative_time_to_string(HTTP_CLIENT_SESSION_TIMEOUT, 1999 GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT,
1981 GNUNET_YES)); 2000 GNUNET_YES));
1982 GNUNET_assert(GNUNET_OK == 2001 GNUNET_assert (GNUNET_OK ==
1983 http_client_plugin_session_disconnect(s->plugin, 2002 http_client_plugin_session_disconnect (s->plugin,
1984 s)); 2003 s));
1985} 2004}
1986 2005
1987 2006
@@ -1994,8 +2013,8 @@ client_session_timeout(void *cls)
1994 * @return the session or NULL of max connections exceeded 2013 * @return the session or NULL of max connections exceeded
1995 */ 2014 */
1996static struct GNUNET_ATS_Session * 2015static struct GNUNET_ATS_Session *
1997http_client_plugin_get_session(void *cls, 2016http_client_plugin_get_session (void *cls,
1998 const struct GNUNET_HELLO_Address *address) 2017 const struct GNUNET_HELLO_Address *address)
1999{ 2018{
2000 struct HTTP_Client_Plugin *plugin = cls; 2019 struct HTTP_Client_Plugin *plugin = cls;
2001 struct GNUNET_ATS_Session *s; 2020 struct GNUNET_ATS_Session *s;
@@ -2004,96 +2023,97 @@ http_client_plugin_get_session(void *cls,
2004 size_t salen = 0; 2023 size_t salen = 0;
2005 int res; 2024 int res;
2006 2025
2007 GNUNET_assert(NULL != address->address); 2026 GNUNET_assert (NULL != address->address);
2008 2027
2009 /* find existing session */ 2028 /* find existing session */
2010 s = client_lookup_session(plugin, address); 2029 s = client_lookup_session (plugin, address);
2011 if (NULL != s) 2030 if (NULL != s)
2012 return s; 2031 return s;
2013 2032
2014 /* create a new session */ 2033 /* create a new session */
2015 if (plugin->max_requests <= plugin->cur_requests) 2034 if (plugin->max_requests <= plugin->cur_requests)
2016 { 2035 {
2017 LOG(GNUNET_ERROR_TYPE_WARNING, 2036 LOG (GNUNET_ERROR_TYPE_WARNING,
2018 "Maximum number of requests (%u) reached: " 2037 "Maximum number of requests (%u) reached: "
2019 "cannot connect to peer `%s'\n", 2038 "cannot connect to peer `%s'\n",
2020 plugin->max_requests, 2039 plugin->max_requests,
2021 GNUNET_i2s(&address->peer)); 2040 GNUNET_i2s (&address->peer));
2022 return NULL; 2041 return NULL;
2023 } 2042 }
2024 2043
2025 /* Determine network location */ 2044 /* Determine network location */
2026 net_type = GNUNET_NT_UNSPECIFIED; 2045 net_type = GNUNET_NT_UNSPECIFIED;
2027 sa = http_common_socket_from_address(address->address, 2046 sa = http_common_socket_from_address (address->address,
2028 address->address_length, 2047 address->address_length,
2029 &res); 2048 &res);
2030 if (GNUNET_SYSERR == res) 2049 if (GNUNET_SYSERR == res)
2031 return NULL; 2050 return NULL;
2032 if (GNUNET_YES == res) 2051 if (GNUNET_YES == res)
2052 {
2053 GNUNET_assert (NULL != sa);
2054 if (AF_INET == sa->sa_family)
2033 { 2055 {
2034 GNUNET_assert(NULL != sa); 2056 salen = sizeof(struct sockaddr_in);
2035 if (AF_INET == sa->sa_family)
2036 {
2037 salen = sizeof(struct sockaddr_in);
2038 }
2039 else if (AF_INET6 == sa->sa_family)
2040 {
2041 salen = sizeof(struct sockaddr_in6);
2042 }
2043 net_type = plugin->env->get_address_type(plugin->env->cls, sa, salen);
2044 GNUNET_free(sa);
2045 } 2057 }
2046 else if (GNUNET_NO == res) 2058 else if (AF_INET6 == sa->sa_family)
2047 { 2059 {
2048 /* Cannot convert to sockaddr -> is external hostname */ 2060 salen = sizeof(struct sockaddr_in6);
2049 net_type = GNUNET_NT_WAN;
2050 } 2061 }
2062 net_type = plugin->env->get_address_type (plugin->env->cls, sa, salen);
2063 GNUNET_free (sa);
2064 }
2065 else if (GNUNET_NO == res)
2066 {
2067 /* Cannot convert to sockaddr -> is external hostname */
2068 net_type = GNUNET_NT_WAN;
2069 }
2051 if (GNUNET_NT_UNSPECIFIED == net_type) 2070 if (GNUNET_NT_UNSPECIFIED == net_type)
2052 { 2071 {
2053 GNUNET_break(0); 2072 GNUNET_break (0);
2054 return NULL; 2073 return NULL;
2055 } 2074 }
2056 2075
2057 s = GNUNET_new(struct GNUNET_ATS_Session); 2076 s = GNUNET_new (struct GNUNET_ATS_Session);
2058 s->plugin = plugin; 2077 s->plugin = plugin;
2059 s->address = GNUNET_HELLO_address_copy(address); 2078 s->address = GNUNET_HELLO_address_copy (address);
2060 s->scope = net_type; 2079 s->scope = net_type;
2061 2080
2062 s->put.state = H_NOT_CONNECTED; 2081 s->put.state = H_NOT_CONNECTED;
2063 s->timeout = GNUNET_TIME_relative_to_absolute(HTTP_CLIENT_SESSION_TIMEOUT); 2082 s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_CLIENT_SESSION_TIMEOUT);
2064 s->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_CLIENT_SESSION_TIMEOUT, 2083 s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_CLIENT_SESSION_TIMEOUT,
2065 &client_session_timeout, 2084 &client_session_timeout,
2066 s); 2085 s);
2067 LOG(GNUNET_ERROR_TYPE_DEBUG, 2086 LOG (GNUNET_ERROR_TYPE_DEBUG,
2068 "Created new session %p for `%s' address `%s''\n", 2087 "Created new session %p for `%s' address `%s''\n",
2069 s, 2088 s,
2070 http_common_plugin_address_to_string(plugin->protocol, 2089 http_common_plugin_address_to_string (plugin->protocol,
2071 s->address->address, 2090 s->address->address,
2072 s->address->address_length), 2091 s->address->address_length),
2073 GNUNET_i2s(&s->address->peer)); 2092 GNUNET_i2s (&s->address->peer));
2074 2093
2075 /* add new session */ 2094 /* add new session */
2076 (void)GNUNET_CONTAINER_multipeermap_put(plugin->sessions, 2095 (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessions,
2077 &s->address->peer, 2096 &s->address->peer,
2078 s, 2097 s,
2079 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2098 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2080 /* initiate new connection */ 2099 /* initiate new connection */
2081 if (GNUNET_SYSERR == client_connect(s)) 2100 if (GNUNET_SYSERR == client_connect (s))
2082 { 2101 {
2083 LOG(GNUNET_ERROR_TYPE_ERROR, 2102 LOG (GNUNET_ERROR_TYPE_ERROR,
2084 "Cannot connect to peer `%s' address `%s''\n", 2103 "Cannot connect to peer `%s' address `%s''\n",
2085 http_common_plugin_address_to_string(plugin->protocol, 2104 http_common_plugin_address_to_string (plugin->protocol,
2086 s->address->address, s->address->address_length), 2105 s->address->address,
2087 GNUNET_i2s(&s->address->peer)); 2106 s->address->address_length),
2088 client_delete_session(s); 2107 GNUNET_i2s (&s->address->peer));
2089 return NULL; 2108 client_delete_session (s);
2090 } 2109 return NULL;
2091 notify_session_monitor(plugin, 2110 }
2092 s, 2111 notify_session_monitor (plugin,
2093 GNUNET_TRANSPORT_SS_INIT); 2112 s,
2094 notify_session_monitor(plugin, 2113 GNUNET_TRANSPORT_SS_INIT);
2095 s, 2114 notify_session_monitor (plugin,
2096 GNUNET_TRANSPORT_SS_UP); /* or handshake? */ 2115 s,
2116 GNUNET_TRANSPORT_SS_UP); /* or handshake? */
2097 return s; 2117 return s;
2098} 2118}
2099 2119
@@ -2105,18 +2125,19 @@ http_client_plugin_get_session(void *cls,
2105 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 2125 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
2106 */ 2126 */
2107static int 2127static int
2108client_start(struct HTTP_Client_Plugin *plugin) 2128client_start (struct HTTP_Client_Plugin *plugin)
2109{ 2129{
2110 curl_global_init(CURL_GLOBAL_ALL); 2130 curl_global_init (CURL_GLOBAL_ALL);
2111 plugin->curl_multi_handle = curl_multi_init(); 2131 plugin->curl_multi_handle = curl_multi_init ();
2112 2132
2113 if (NULL == plugin->curl_multi_handle) 2133 if (NULL == plugin->curl_multi_handle)
2114 { 2134 {
2115 LOG(GNUNET_ERROR_TYPE_ERROR, 2135 LOG (GNUNET_ERROR_TYPE_ERROR,
2116 _("Could not initialize curl multi handle, failed to start %s plugin!\n"), 2136 _ (
2117 plugin->name); 2137 "Could not initialize curl multi handle, failed to start %s plugin!\n"),
2118 return GNUNET_SYSERR; 2138 plugin->name);
2119 } 2139 return GNUNET_SYSERR;
2140 }
2120 return GNUNET_OK; 2141 return GNUNET_OK;
2121} 2142}
2122 2143
@@ -2134,9 +2155,9 @@ client_start(struct HTTP_Client_Plugin *plugin)
2134 * and transport; always returns #GNUNET_NO (this is the client!) 2155 * and transport; always returns #GNUNET_NO (this is the client!)
2135 */ 2156 */
2136static int 2157static int
2137http_client_plugin_address_suggested(void *cls, 2158http_client_plugin_address_suggested (void *cls,
2138 const void *addr, 2159 const void *addr,
2139 size_t addrlen) 2160 size_t addrlen)
2140{ 2161{
2141 /* A HTTP/S client does not have any valid address so:*/ 2162 /* A HTTP/S client does not have any valid address so:*/
2142 return GNUNET_NO; 2163 return GNUNET_NO;
@@ -2150,43 +2171,43 @@ http_client_plugin_address_suggested(void *cls,
2150 * @return NULL 2171 * @return NULL
2151 */ 2172 */
2152void * 2173void *
2153LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) 2174LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2154{ 2175{
2155 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 2176 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2156 struct HTTP_Client_Plugin *plugin = api->cls; 2177 struct HTTP_Client_Plugin *plugin = api->cls;
2157 2178
2158 if (NULL == api->cls) 2179 if (NULL == api->cls)
2159 { 2180 {
2160 /* Stub shutdown */ 2181 /* Stub shutdown */
2161 GNUNET_free(api); 2182 GNUNET_free (api);
2162 return NULL; 2183 return NULL;
2163 } 2184 }
2164 LOG(GNUNET_ERROR_TYPE_DEBUG, 2185 LOG (GNUNET_ERROR_TYPE_DEBUG,
2165 _("Shutting down plugin `%s'\n"), 2186 _ ("Shutting down plugin `%s'\n"),
2166 plugin->name); 2187 plugin->name);
2167 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, 2188 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
2168 &destroy_session_cb, 2189 &destroy_session_cb,
2169 plugin); 2190 plugin);
2170 if (NULL != plugin->client_perform_task) 2191 if (NULL != plugin->client_perform_task)
2171 { 2192 {
2172 GNUNET_SCHEDULER_cancel(plugin->client_perform_task); 2193 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
2173 plugin->client_perform_task = NULL; 2194 plugin->client_perform_task = NULL;
2174 } 2195 }
2175 if (NULL != plugin->curl_multi_handle) 2196 if (NULL != plugin->curl_multi_handle)
2176 { 2197 {
2177 curl_multi_cleanup(plugin->curl_multi_handle); 2198 curl_multi_cleanup (plugin->curl_multi_handle);
2178 plugin->curl_multi_handle = NULL; 2199 plugin->curl_multi_handle = NULL;
2179 } 2200 }
2180 curl_global_cleanup(); 2201 curl_global_cleanup ();
2181 LOG(GNUNET_ERROR_TYPE_DEBUG, 2202 LOG (GNUNET_ERROR_TYPE_DEBUG,
2182 _("Shutdown for plugin `%s' complete\n"), 2203 _ ("Shutdown for plugin `%s' complete\n"),
2183 plugin->name); 2204 plugin->name);
2184 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions); 2205 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions);
2185 GNUNET_free_non_null(plugin->proxy_hostname); 2206 GNUNET_free_non_null (plugin->proxy_hostname);
2186 GNUNET_free_non_null(plugin->proxy_username); 2207 GNUNET_free_non_null (plugin->proxy_username);
2187 GNUNET_free_non_null(plugin->proxy_password); 2208 GNUNET_free_non_null (plugin->proxy_password);
2188 GNUNET_free(plugin); 2209 GNUNET_free (plugin);
2189 GNUNET_free(api); 2210 GNUNET_free (api);
2190 return NULL; 2211 return NULL;
2191} 2212}
2192 2213
@@ -2198,115 +2219,116 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls)
2198 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 2219 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2199 */ 2220 */
2200static int 2221static int
2201client_configure_plugin(struct HTTP_Client_Plugin *plugin) 2222client_configure_plugin (struct HTTP_Client_Plugin *plugin)
2202{ 2223{
2203 unsigned long long max_requests; 2224 unsigned long long max_requests;
2204 char *proxy_type; 2225 char *proxy_type;
2205 2226
2206 /* Optional parameters */ 2227 /* Optional parameters */
2207 if (GNUNET_OK != 2228 if (GNUNET_OK !=
2208 GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg, 2229 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
2209 plugin->name, 2230 plugin->name,
2210 "MAX_CONNECTIONS", 2231 "MAX_CONNECTIONS",
2211 &max_requests)) 2232 &max_requests))
2212 max_requests = 128; 2233 max_requests = 128;
2213 plugin->max_requests = max_requests; 2234 plugin->max_requests = max_requests;
2214 2235
2215 LOG(GNUNET_ERROR_TYPE_DEBUG, 2236 LOG (GNUNET_ERROR_TYPE_DEBUG,
2216 _("Maximum number of requests is %u\n"), 2237 _ ("Maximum number of requests is %u\n"),
2217 plugin->max_requests); 2238 plugin->max_requests);
2218 2239
2219 /* Read proxy configuration */ 2240 /* Read proxy configuration */
2220 if (GNUNET_OK == 2241 if (GNUNET_OK ==
2221 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, 2242 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2222 plugin->name, 2243 plugin->name,
2223 "PROXY", 2244 "PROXY",
2224 &plugin->proxy_hostname)) 2245 &plugin->proxy_hostname))
2246 {
2247 LOG (GNUNET_ERROR_TYPE_DEBUG,
2248 "Found proxy host: `%s'\n",
2249 plugin->proxy_hostname);
2250 /* proxy username */
2251 if (GNUNET_OK ==
2252 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2253 plugin->name,
2254 "PROXY_USERNAME",
2255 &plugin->proxy_username))
2225 { 2256 {
2226 LOG(GNUNET_ERROR_TYPE_DEBUG, 2257 LOG (GNUNET_ERROR_TYPE_DEBUG,
2227 "Found proxy host: `%s'\n", 2258 "Found proxy username name: `%s'\n",
2228 plugin->proxy_hostname); 2259 plugin->proxy_username);
2229 /* proxy username */ 2260 }
2230 if (GNUNET_OK ==
2231 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
2232 plugin->name,
2233 "PROXY_USERNAME",
2234 &plugin->proxy_username))
2235 {
2236 LOG(GNUNET_ERROR_TYPE_DEBUG,
2237 "Found proxy username name: `%s'\n",
2238 plugin->proxy_username);
2239 }
2240
2241 /* proxy password */
2242 if (GNUNET_OK ==
2243 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
2244 plugin->name,
2245 "PROXY_PASSWORD",
2246 &plugin->proxy_password))
2247 {
2248 LOG(GNUNET_ERROR_TYPE_DEBUG,
2249 "Found proxy password name: `%s'\n",
2250 plugin->proxy_password);
2251 }
2252 2261
2253 /* proxy type */ 2262 /* proxy password */
2254 if (GNUNET_OK == 2263 if (GNUNET_OK ==
2255 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, 2264 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2256 plugin->name, 2265 plugin->name,
2257 "PROXY_TYPE", 2266 "PROXY_PASSWORD",
2258 &proxy_type)) 2267 &plugin->proxy_password))
2259 { 2268 {
2260 GNUNET_STRINGS_utf8_toupper(proxy_type, proxy_type); 2269 LOG (GNUNET_ERROR_TYPE_DEBUG,
2261 2270 "Found proxy password name: `%s'\n",
2262 if (0 == strcmp(proxy_type, "HTTP")) 2271 plugin->proxy_password);
2263 plugin->proxytype = CURLPROXY_HTTP; 2272 }
2264 else if (0 == strcmp(proxy_type, "SOCKS4"))
2265 plugin->proxytype = CURLPROXY_SOCKS4;
2266 else if (0 == strcmp(proxy_type, "SOCKS5"))
2267 plugin->proxytype = CURLPROXY_SOCKS5;
2268 else if (0 == strcmp(proxy_type, "SOCKS4A"))
2269 plugin->proxytype = CURLPROXY_SOCKS4A;
2270 else if (0 == strcmp(proxy_type, "SOCKS5_HOSTNAME "))
2271 plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME;
2272 else
2273 {
2274 LOG(GNUNET_ERROR_TYPE_ERROR,
2275 _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
2276 proxy_type);
2277
2278 GNUNET_free(proxy_type);
2279 GNUNET_free(plugin->proxy_hostname);
2280 plugin->proxy_hostname = NULL;
2281 GNUNET_free_non_null(plugin->proxy_username);
2282 plugin->proxy_username = NULL;
2283 GNUNET_free_non_null(plugin->proxy_password);
2284 plugin->proxy_password = NULL;
2285
2286 return GNUNET_SYSERR;
2287 }
2288
2289 LOG(GNUNET_ERROR_TYPE_DEBUG,
2290 "Found proxy type: `%s'\n",
2291 proxy_type);
2292 }
2293 2273
2294 /* proxy http tunneling */ 2274 /* proxy type */
2295 plugin->proxy_use_httpproxytunnel 2275 if (GNUNET_OK ==
2296 = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 2276 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2297 plugin->name, 2277 plugin->name,
2298 "PROXY_HTTP_TUNNELING"); 2278 "PROXY_TYPE",
2299 if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel) 2279 &proxy_type))
2300 plugin->proxy_use_httpproxytunnel = GNUNET_NO; 2280 {
2281 GNUNET_STRINGS_utf8_toupper (proxy_type, proxy_type);
2282
2283 if (0 == strcmp (proxy_type, "HTTP"))
2284 plugin->proxytype = CURLPROXY_HTTP;
2285 else if (0 == strcmp (proxy_type, "SOCKS4"))
2286 plugin->proxytype = CURLPROXY_SOCKS4;
2287 else if (0 == strcmp (proxy_type, "SOCKS5"))
2288 plugin->proxytype = CURLPROXY_SOCKS5;
2289 else if (0 == strcmp (proxy_type, "SOCKS4A"))
2290 plugin->proxytype = CURLPROXY_SOCKS4A;
2291 else if (0 == strcmp (proxy_type, "SOCKS5_HOSTNAME "))
2292 plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME;
2293 else
2294 {
2295 LOG (GNUNET_ERROR_TYPE_ERROR,
2296 _ (
2297 "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
2298 proxy_type);
2299
2300 GNUNET_free (proxy_type);
2301 GNUNET_free (plugin->proxy_hostname);
2302 plugin->proxy_hostname = NULL;
2303 GNUNET_free_non_null (plugin->proxy_username);
2304 plugin->proxy_username = NULL;
2305 GNUNET_free_non_null (plugin->proxy_password);
2306 plugin->proxy_password = NULL;
2307
2308 return GNUNET_SYSERR;
2309 }
2301 2310
2302 GNUNET_free_non_null(proxy_type); 2311 LOG (GNUNET_ERROR_TYPE_DEBUG,
2312 "Found proxy type: `%s'\n",
2313 proxy_type);
2303 } 2314 }
2304 2315
2316 /* proxy http tunneling */
2317 plugin->proxy_use_httpproxytunnel
2318 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
2319 plugin->name,
2320 "PROXY_HTTP_TUNNELING");
2321 if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel)
2322 plugin->proxy_use_httpproxytunnel = GNUNET_NO;
2323
2324 GNUNET_free_non_null (proxy_type);
2325 }
2326
2305 /* Should we emulate an XHR client for testing? */ 2327 /* Should we emulate an XHR client for testing? */
2306 plugin->emulate_xhr 2328 plugin->emulate_xhr
2307 = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 2329 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
2308 plugin->name, 2330 plugin->name,
2309 "EMULATE_XHR"); 2331 "EMULATE_XHR");
2310 return GNUNET_OK; 2332 return GNUNET_OK;
2311} 2333}
2312 2334
@@ -2320,13 +2342,13 @@ client_configure_plugin(struct HTTP_Client_Plugin *plugin)
2320 * @return res string if conversion was successful, NULL otherwise 2342 * @return res string if conversion was successful, NULL otherwise
2321 */ 2343 */
2322static const char * 2344static const char *
2323http_client_plugin_address_to_string(void *cls, 2345http_client_plugin_address_to_string (void *cls,
2324 const void *addr, 2346 const void *addr,
2325 size_t addrlen) 2347 size_t addrlen)
2326{ 2348{
2327 return http_common_plugin_address_to_string(PLUGIN_NAME, 2349 return http_common_plugin_address_to_string (PLUGIN_NAME,
2328 addr, 2350 addr,
2329 addrlen); 2351 addrlen);
2330} 2352}
2331 2353
2332 2354
@@ -2340,11 +2362,12 @@ http_client_plugin_address_to_string(void *cls,
2340 * @param session which session is being updated 2362 * @param session which session is being updated
2341 */ 2363 */
2342static void 2364static void
2343http_client_plugin_update_session_timeout(void *cls, 2365http_client_plugin_update_session_timeout (void *cls,
2344 const struct GNUNET_PeerIdentity *peer, 2366 const struct
2345 struct GNUNET_ATS_Session *session) 2367 GNUNET_PeerIdentity *peer,
2368 struct GNUNET_ATS_Session *session)
2346{ 2369{
2347 client_reschedule_session_timeout(session); 2370 client_reschedule_session_timeout (session);
2348} 2371}
2349 2372
2350 2373
@@ -2359,24 +2382,24 @@ http_client_plugin_update_session_timeout(void *cls,
2359 * @param delay new delay to use for receiving 2382 * @param delay new delay to use for receiving
2360 */ 2383 */
2361static void 2384static void
2362http_client_plugin_update_inbound_delay(void *cls, 2385http_client_plugin_update_inbound_delay (void *cls,
2363 const struct GNUNET_PeerIdentity *peer, 2386 const struct GNUNET_PeerIdentity *peer,
2364 struct GNUNET_ATS_Session *s, 2387 struct GNUNET_ATS_Session *s,
2365 struct GNUNET_TIME_Relative delay) 2388 struct GNUNET_TIME_Relative delay)
2366{ 2389{
2367 s->next_receive = GNUNET_TIME_relative_to_absolute(delay); 2390 s->next_receive = GNUNET_TIME_relative_to_absolute (delay);
2368 LOG(GNUNET_ERROR_TYPE_DEBUG, 2391 LOG (GNUNET_ERROR_TYPE_DEBUG,
2369 "New inbound delay %s\n", 2392 "New inbound delay %s\n",
2370 GNUNET_STRINGS_relative_time_to_string(delay, 2393 GNUNET_STRINGS_relative_time_to_string (delay,
2371 GNUNET_NO)); 2394 GNUNET_NO));
2372 if (s->recv_wakeup_task != NULL) 2395 if (s->recv_wakeup_task != NULL)
2373 { 2396 {
2374 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); 2397 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
2375 s->recv_wakeup_task 2398 s->recv_wakeup_task
2376 = GNUNET_SCHEDULER_add_delayed(delay, 2399 = GNUNET_SCHEDULER_add_delayed (delay,
2377 &client_wake_up, 2400 &client_wake_up,
2378 s); 2401 s);
2379 } 2402 }
2380} 2403}
2381 2404
2382 2405
@@ -2390,19 +2413,19 @@ http_client_plugin_update_inbound_delay(void *cls,
2390 * @return #GNUNET_OK (continue to iterate) 2413 * @return #GNUNET_OK (continue to iterate)
2391 */ 2414 */
2392static int 2415static int
2393send_session_info_iter(void *cls, 2416send_session_info_iter (void *cls,
2394 const struct GNUNET_PeerIdentity *peer, 2417 const struct GNUNET_PeerIdentity *peer,
2395 void *value) 2418 void *value)
2396{ 2419{
2397 struct HTTP_Client_Plugin *plugin = cls; 2420 struct HTTP_Client_Plugin *plugin = cls;
2398 struct GNUNET_ATS_Session *session = value; 2421 struct GNUNET_ATS_Session *session = value;
2399 2422
2400 notify_session_monitor(plugin, 2423 notify_session_monitor (plugin,
2401 session, 2424 session,
2402 GNUNET_TRANSPORT_SS_INIT); 2425 GNUNET_TRANSPORT_SS_INIT);
2403 notify_session_monitor(plugin, 2426 notify_session_monitor (plugin,
2404 session, 2427 session,
2405 GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */ 2428 GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */
2406 return GNUNET_OK; 2429 return GNUNET_OK;
2407} 2430}
2408 2431
@@ -2420,22 +2443,22 @@ send_session_info_iter(void *cls,
2420 * @param sic_cls closure for @a sic 2443 * @param sic_cls closure for @a sic
2421 */ 2444 */
2422static void 2445static void
2423http_client_plugin_setup_monitor(void *cls, 2446http_client_plugin_setup_monitor (void *cls,
2424 GNUNET_TRANSPORT_SessionInfoCallback sic, 2447 GNUNET_TRANSPORT_SessionInfoCallback sic,
2425 void *sic_cls) 2448 void *sic_cls)
2426{ 2449{
2427 struct HTTP_Client_Plugin *plugin = cls; 2450 struct HTTP_Client_Plugin *plugin = cls;
2428 2451
2429 plugin->sic = sic; 2452 plugin->sic = sic;
2430 plugin->sic_cls = sic_cls; 2453 plugin->sic_cls = sic_cls;
2431 if (NULL != sic) 2454 if (NULL != sic)
2432 { 2455 {
2433 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, 2456 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
2434 &send_session_info_iter, 2457 &send_session_info_iter,
2435 plugin); 2458 plugin);
2436 /* signal end of first iteration */ 2459 /* signal end of first iteration */
2437 sic(sic_cls, NULL, NULL); 2460 sic (sic_cls, NULL, NULL);
2438 } 2461 }
2439} 2462}
2440 2463
2441 2464
@@ -2443,29 +2466,29 @@ http_client_plugin_setup_monitor(void *cls,
2443 * Entry point for the plugin. 2466 * Entry point for the plugin.
2444 */ 2467 */
2445void * 2468void *
2446LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) 2469LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2447{ 2470{
2448 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 2471 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2449 struct GNUNET_TRANSPORT_PluginFunctions *api; 2472 struct GNUNET_TRANSPORT_PluginFunctions *api;
2450 struct HTTP_Client_Plugin *plugin; 2473 struct HTTP_Client_Plugin *plugin;
2451 2474
2452 if (NULL == env->receive) 2475 if (NULL == env->receive)
2453 { 2476 {
2454 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 2477 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2455 initialze the plugin or the API */ 2478 initialze the plugin or the API */
2456 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 2479 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
2457 api->cls = NULL; 2480 api->cls = NULL;
2458 api->address_to_string = &http_client_plugin_address_to_string; 2481 api->address_to_string = &http_client_plugin_address_to_string;
2459 api->string_to_address = &http_common_plugin_string_to_address; 2482 api->string_to_address = &http_common_plugin_string_to_address;
2460 api->address_pretty_printer = &http_common_plugin_address_pretty_printer; 2483 api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
2461 return api; 2484 return api;
2462 } 2485 }
2463 2486
2464 plugin = GNUNET_new(struct HTTP_Client_Plugin); 2487 plugin = GNUNET_new (struct HTTP_Client_Plugin);
2465 plugin->env = env; 2488 plugin->env = env;
2466 plugin->sessions = GNUNET_CONTAINER_multipeermap_create(128, 2489 plugin->sessions = GNUNET_CONTAINER_multipeermap_create (128,
2467 GNUNET_YES); 2490 GNUNET_YES);
2468 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 2491 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
2469 api->cls = plugin; 2492 api->cls = plugin;
2470 api->send = &http_client_plugin_send; 2493 api->send = &http_client_plugin_send;
2471 api->disconnect_session = &http_client_plugin_session_disconnect; 2494 api->disconnect_session = &http_client_plugin_session_disconnect;
@@ -2490,18 +2513,18 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls)
2490#endif 2513#endif
2491 plugin->last_tag = 1; 2514 plugin->last_tag = 1;
2492 2515
2493 if (GNUNET_SYSERR == client_configure_plugin(plugin)) 2516 if (GNUNET_SYSERR == client_configure_plugin (plugin))
2494 { 2517 {
2495 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); 2518 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
2496 return NULL; 2519 return NULL;
2497 } 2520 }
2498 2521
2499 /* Start client */ 2522 /* Start client */
2500 if (GNUNET_SYSERR == client_start(plugin)) 2523 if (GNUNET_SYSERR == client_start (plugin))
2501 { 2524 {
2502 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); 2525 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
2503 return NULL; 2526 return NULL;
2504 } 2527 }
2505 return api; 2528 return api;
2506} 2529}
2507 2530
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 @@
30#include "gnunet_resolver_service.h" 30#include "gnunet_resolver_service.h"
31 31
32static void 32static void
33http_clean_splitted(struct SplittedHTTPAddress *spa) 33http_clean_splitted (struct SplittedHTTPAddress *spa)
34{ 34{
35 if (NULL != spa) 35 if (NULL != spa)
36 { 36 {
37 GNUNET_free_non_null(spa->protocol); 37 GNUNET_free_non_null (spa->protocol);
38 GNUNET_free_non_null(spa->host); 38 GNUNET_free_non_null (spa->host);
39 GNUNET_free_non_null(spa->path); 39 GNUNET_free_non_null (spa->path);
40 GNUNET_free_non_null(spa); 40 GNUNET_free_non_null (spa);
41 } 41 }
42} 42}
43 43
44 44
45struct SplittedHTTPAddress * 45struct SplittedHTTPAddress *
46http_split_address(const char * addr) 46http_split_address (const char *addr)
47{ 47{
48 struct SplittedHTTPAddress *sp; 48 struct SplittedHTTPAddress *sp;
49 char *src = GNUNET_strdup(addr); 49 char *src = GNUNET_strdup (addr);
50 char *protocol_start = NULL; 50 char *protocol_start = NULL;
51 char *host_start = NULL; 51 char *host_start = NULL;
52 char *v6_end = NULL; 52 char *v6_end = NULL;
@@ -55,128 +55,129 @@ http_split_address(const char * addr)
55 55
56 protocol_start = src; 56 protocol_start = src;
57 57
58 sp = GNUNET_new(struct SplittedHTTPAddress); 58 sp = GNUNET_new (struct SplittedHTTPAddress);
59 /* Address string consists of protocol://host[:port]path*/ 59 /* Address string consists of protocol://host[:port]path*/
60 60
61 host_start = strstr(src, "://"); 61 host_start = strstr (src, "://");
62 if (NULL == host_start) 62 if (NULL == host_start)
63 { 63 {
64 GNUNET_free(src); 64 GNUNET_free (src);
65 GNUNET_free(sp); 65 GNUNET_free (sp);
66 return NULL; 66 return NULL;
67 } 67 }
68 host_start[0] = '\0'; 68 host_start[0] = '\0';
69 sp->protocol = GNUNET_strdup(protocol_start); 69 sp->protocol = GNUNET_strdup (protocol_start);
70 70
71 host_start += strlen("://"); 71 host_start += strlen ("://");
72 if (strlen(host_start) == 0) 72 if (strlen (host_start) == 0)
73 { 73 {
74 GNUNET_free(src); 74 GNUNET_free (src);
75 GNUNET_free(sp->protocol); 75 GNUNET_free (sp->protocol);
76 GNUNET_free(sp); 76 GNUNET_free (sp);
77 return NULL; 77 return NULL;
78 } 78 }
79 79
80 /* Find path start */ 80 /* Find path start */
81 path_start = strchr(host_start, '/'); 81 path_start = strchr (host_start, '/');
82 if (NULL != path_start) 82 if (NULL != path_start)
83 { 83 {
84 sp->path = GNUNET_strdup(path_start); 84 sp->path = GNUNET_strdup (path_start);
85 path_start[0] = '\0'; 85 path_start[0] = '\0';
86 } 86 }
87 else 87 else
88 sp->path = GNUNET_strdup(""); 88 sp->path = GNUNET_strdup ("");
89 89
90 if (strlen(host_start) < 1) 90 if (strlen (host_start) < 1)
91 { 91 {
92 GNUNET_free(src); 92 GNUNET_free (src);
93 GNUNET_free(sp->protocol); 93 GNUNET_free (sp->protocol);
94 GNUNET_free(sp->path); 94 GNUNET_free (sp->path);
95 GNUNET_free(sp); 95 GNUNET_free (sp);
96 return NULL; 96 return NULL;
97 } 97 }
98 98
99 if (NULL != (port_start = strrchr(host_start, ':'))) 99 if (NULL != (port_start = strrchr (host_start, ':')))
100 { 100 {
101 /* *We COULD have a port, but also an IPv6 address! */ 101 /* *We COULD have a port, but also an IPv6 address! */
102 if (NULL != (v6_end = strchr(host_start, ']'))) 102 if (NULL != (v6_end = strchr (host_start, ']')))
103 { 103 {
104 if (v6_end < port_start) 104 if (v6_end < port_start)
105 { 105 {
106 /* IPv6 address + port */ 106 /* IPv6 address + port */
107 port_start[0] = '\0'; 107 port_start[0] = '\0';
108 port_start++; 108 port_start++;
109 sp->port = atoi(port_start); 109 sp->port = atoi (port_start);
110 if ((0 == sp->port) || (65535 < sp->port)) 110 if ((0 == sp->port) || (65535 < sp->port))
111 {
112 GNUNET_free(src);
113 GNUNET_free(sp->protocol);
114 GNUNET_free(sp->path);
115 GNUNET_free(sp);
116 return NULL;
117 }
118 }
119 else
120 {
121 /* IPv6 address + no port */
122 if (0 == strcmp(sp->protocol, "https"))
123 sp->port = HTTPS_DEFAULT_PORT;
124 else if (0 == strcmp(sp->protocol, "http"))
125 sp->port = HTTP_DEFAULT_PORT;
126 }
127 }
128 else
129 {
130 /* No IPv6 address */
131 port_start[0] = '\0';
132 port_start++;
133 sp->port = atoi(port_start);
134 if ((0 == sp->port) || (65535 < sp->port))
135 {
136 GNUNET_free(src);
137 GNUNET_free(sp->protocol);
138 GNUNET_free(sp->path);
139 GNUNET_free(sp);
140 return NULL;
141 }
142 }
143 }
144 else
145 {
146 /* No ':' as port separator, default port for protocol */
147 if (0 == strcmp(sp->protocol, "https"))
148 sp->port = HTTPS_DEFAULT_PORT;
149 else if (0 == strcmp(sp->protocol, "http"))
150 sp->port = HTTP_DEFAULT_PORT;
151 else
152 { 111 {
153 GNUNET_break(0); 112 GNUNET_free (src);
154 GNUNET_free(src); 113 GNUNET_free (sp->protocol);
155 GNUNET_free(sp->protocol); 114 GNUNET_free (sp->path);
156 GNUNET_free(sp->path); 115 GNUNET_free (sp);
157 GNUNET_free(sp);
158 return NULL; 116 return NULL;
159 } 117 }
160 } 118 }
161 if (strlen(host_start) > 0) 119 else
162 sp->host = GNUNET_strdup(host_start); 120 {
121 /* IPv6 address + no port */
122 if (0 == strcmp (sp->protocol, "https"))
123 sp->port = HTTPS_DEFAULT_PORT;
124 else if (0 == strcmp (sp->protocol, "http"))
125 sp->port = HTTP_DEFAULT_PORT;
126 }
127 }
128 else
129 {
130 /* No IPv6 address */
131 port_start[0] = '\0';
132 port_start++;
133 sp->port = atoi (port_start);
134 if ((0 == sp->port) || (65535 < sp->port))
135 {
136 GNUNET_free (src);
137 GNUNET_free (sp->protocol);
138 GNUNET_free (sp->path);
139 GNUNET_free (sp);
140 return NULL;
141 }
142 }
143 }
163 else 144 else
164 { 145 {
165 GNUNET_break(0); 146 /* No ':' as port separator, default port for protocol */
166 GNUNET_free(src); 147 if (0 == strcmp (sp->protocol, "https"))
167 GNUNET_free(sp->protocol); 148 sp->port = HTTPS_DEFAULT_PORT;
168 GNUNET_free(sp->path); 149 else if (0 == strcmp (sp->protocol, "http"))
169 GNUNET_free(sp); 150 sp->port = HTTP_DEFAULT_PORT;
151 else
152 {
153 GNUNET_break (0);
154 GNUNET_free (src);
155 GNUNET_free (sp->protocol);
156 GNUNET_free (sp->path);
157 GNUNET_free (sp);
170 return NULL; 158 return NULL;
171 } 159 }
172 GNUNET_free(src); 160 }
161 if (strlen (host_start) > 0)
162 sp->host = GNUNET_strdup (host_start);
163 else
164 {
165 GNUNET_break (0);
166 GNUNET_free (src);
167 GNUNET_free (sp->protocol);
168 GNUNET_free (sp->path);
169 GNUNET_free (sp);
170 return NULL;
171 }
172 GNUNET_free (src);
173 return sp; 173 return sp;
174} 174}
175 175
176/** 176/**
177 * Closure for #append_port(). 177 * Closure for #append_port().
178 */ 178 */
179struct PrettyPrinterContext { 179struct PrettyPrinterContext
180{
180 /** 181 /**
181 * DLL 182 * DLL
182 */ 183 */
@@ -205,7 +206,7 @@ struct PrettyPrinterContext {
205 /** 206 /**
206 * Timeout task 207 * Timeout task
207 */ 208 */
208 struct GNUNET_SCHEDULER_Task * timeout_task; 209 struct GNUNET_SCHEDULER_Task *timeout_task;
209 210
210 /** 211 /**
211 * Splitted Address 212 * Splitted Address
@@ -251,149 +252,156 @@ static struct PrettyPrinterContext *dll_ppc_tail;
251 * @return string representing the same address or NULL on error 252 * @return string representing the same address or NULL on error
252 */ 253 */
253static const char * 254static const char *
254http_common_plugin_dnsresult_to_address(const char *plugin, 255http_common_plugin_dnsresult_to_address (const char *plugin,
255 const struct SplittedHTTPAddress *saddr, 256 const struct
256 uint32_t options, 257 SplittedHTTPAddress *saddr,
257 const char *dnsresult) 258 uint32_t options,
259 const char *dnsresult)
258{ 260{
259 static char rbuf[1024]; 261 static char rbuf[1024];
260 char *res; 262 char *res;
261 263
262 GNUNET_asprintf(&res, "%s.%u.%s://%s:%u%s", plugin, options, saddr->protocol, 264 GNUNET_asprintf (&res, "%s.%u.%s://%s:%u%s", plugin, options, saddr->protocol,
263 dnsresult, saddr->port, saddr->path); 265 dnsresult, saddr->port, saddr->path);
264 if (strlen(res) + 1 < 500) 266 if (strlen (res) + 1 < 500)
265 { 267 {
266 GNUNET_memcpy(rbuf, res, strlen(res) + 1); 268 GNUNET_memcpy (rbuf, res, strlen (res) + 1);
267 GNUNET_free(res); 269 GNUNET_free (res);
268 return rbuf; 270 return rbuf;
269 } 271 }
270 GNUNET_break(0); 272 GNUNET_break (0);
271 GNUNET_free(res); 273 GNUNET_free (res);
272 return NULL; 274 return NULL;
273} 275}
274 276
275 277
276static void 278static void
277http_common_dns_reverse_lookup_cb(void *cls, const char *hostname) 279http_common_dns_reverse_lookup_cb (void *cls, const char *hostname)
278{ 280{
279 struct PrettyPrinterContext *ppc = cls; 281 struct PrettyPrinterContext *ppc = cls;
280 282
281 if (NULL != hostname) 283 if (NULL != hostname)
282 { 284 {
283 ppc->asc(ppc->asc_cls, 285 ppc->asc (ppc->asc_cls,
284 http_common_plugin_dnsresult_to_address(ppc->plugin, ppc->saddr, ppc->options, 286 http_common_plugin_dnsresult_to_address (ppc->plugin, ppc->saddr,
287 ppc->options,
285 hostname), GNUNET_OK); 288 hostname), GNUNET_OK);
286 ppc->sucess = GNUNET_YES; 289 ppc->sucess = GNUNET_YES;
287 } 290 }
288 else 291 else
289 { 292 {
290 ppc->asc(ppc->asc_cls, NULL, 293 ppc->asc (ppc->asc_cls, NULL,
291 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK); 294 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK);
292 295
293 GNUNET_CONTAINER_DLL_remove(dll_ppc_head, dll_ppc_tail, ppc); 296 GNUNET_CONTAINER_DLL_remove (dll_ppc_head, dll_ppc_tail, ppc);
294 http_clean_splitted(ppc->saddr); 297 http_clean_splitted (ppc->saddr);
295 GNUNET_free(ppc->plugin); 298 GNUNET_free (ppc->plugin);
296 GNUNET_free(ppc); 299 GNUNET_free (ppc);
297 } 300 }
298} 301}
299 302
300 303
301static int 304static int
302http_common_dns_reverse_lookup(const struct sockaddr *sockaddr, 305http_common_dns_reverse_lookup (const struct sockaddr *sockaddr,
303 socklen_t sockaddr_len, 306 socklen_t sockaddr_len,
304 const char *type, 307 const char *type,
305 struct SplittedHTTPAddress *saddr, 308 struct SplittedHTTPAddress *saddr,
306 uint32_t options, 309 uint32_t options,
307 struct GNUNET_TIME_Relative timeout, 310 struct GNUNET_TIME_Relative timeout,
308 GNUNET_TRANSPORT_AddressStringCallback asc, 311 GNUNET_TRANSPORT_AddressStringCallback asc,
309 void *asc_cls) 312 void *asc_cls)
310{ 313{
311 struct PrettyPrinterContext *ppc; 314 struct PrettyPrinterContext *ppc;
312 315
313 ppc = GNUNET_new(struct PrettyPrinterContext); 316 ppc = GNUNET_new (struct PrettyPrinterContext);
314 ppc->saddr = saddr; 317 ppc->saddr = saddr;
315 ppc->asc = asc; 318 ppc->asc = asc;
316 ppc->asc_cls = asc_cls; 319 ppc->asc_cls = asc_cls;
317 ppc->plugin = GNUNET_strdup(type); 320 ppc->plugin = GNUNET_strdup (type);
318 ppc->options = options; 321 ppc->options = options;
319 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sockaddr, 322 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sockaddr,
320 sockaddr_len, 323 sockaddr_len,
321 GNUNET_YES, 324 GNUNET_YES,
322 timeout, 325 timeout,
323 &http_common_dns_reverse_lookup_cb, 326 &
324 ppc); 327 http_common_dns_reverse_lookup_cb,
328 ppc);
325 if (NULL == ppc->resolver_handle) 329 if (NULL == ppc->resolver_handle)
326 { 330 {
327 GNUNET_free(ppc->plugin); 331 GNUNET_free (ppc->plugin);
328 GNUNET_free(ppc); 332 GNUNET_free (ppc);
329 return GNUNET_SYSERR; 333 return GNUNET_SYSERR;
330 } 334 }
331 GNUNET_CONTAINER_DLL_insert(dll_ppc_head, 335 GNUNET_CONTAINER_DLL_insert (dll_ppc_head,
332 dll_ppc_tail, 336 dll_ppc_tail,
333 ppc); 337 ppc);
334 return GNUNET_OK; 338 return GNUNET_OK;
335} 339}
336 340
337 341
338static void 342static void
339http_common_dns_ip_lookup_cb(void *cls, 343http_common_dns_ip_lookup_cb (void *cls,
340 const struct sockaddr *addr, 344 const struct sockaddr *addr,
341 socklen_t addrlen) 345 socklen_t addrlen)
342{ 346{
343 struct PrettyPrinterContext *ppc = cls; 347 struct PrettyPrinterContext *ppc = cls;
344 348
345 if (NULL != addr) 349 if (NULL != addr)
346 { 350 {
347 ppc->asc(ppc->asc_cls, 351 ppc->asc (ppc->asc_cls,
348 http_common_plugin_dnsresult_to_address(ppc->plugin, ppc->saddr, ppc->options, 352 http_common_plugin_dnsresult_to_address (ppc->plugin, ppc->saddr,
349 GNUNET_a2s(addr, addrlen)), GNUNET_OK); 353 ppc->options,
350 ppc->sucess = GNUNET_YES; 354 GNUNET_a2s (addr,
351 ppc->asc(ppc->asc_cls, GNUNET_a2s(addr, addrlen), GNUNET_OK); 355 addrlen)),
352 } 356 GNUNET_OK);
357 ppc->sucess = GNUNET_YES;
358 ppc->asc (ppc->asc_cls, GNUNET_a2s (addr, addrlen), GNUNET_OK);
359 }
353 else 360 else
354 { 361 {
355 ppc->asc(ppc->asc_cls, NULL, 362 ppc->asc (ppc->asc_cls, NULL,
356 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK); 363 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK);
357 364
358 GNUNET_CONTAINER_DLL_remove(dll_ppc_head, dll_ppc_tail, ppc); 365 GNUNET_CONTAINER_DLL_remove (dll_ppc_head, dll_ppc_tail, ppc);
359 GNUNET_free(ppc->plugin); 366 GNUNET_free (ppc->plugin);
360 http_clean_splitted(ppc->saddr); 367 http_clean_splitted (ppc->saddr);
361 GNUNET_free(ppc); 368 GNUNET_free (ppc);
362 } 369 }
363} 370}
364 371
365 372
366static int 373static int
367http_common_dns_ip_lookup(const char *name, 374http_common_dns_ip_lookup (const char *name,
368 const char *type, 375 const char *type,
369 struct SplittedHTTPAddress *saddr, 376 struct SplittedHTTPAddress *saddr,
370 uint32_t options, 377 uint32_t options,
371 struct GNUNET_TIME_Relative timeout, 378 struct GNUNET_TIME_Relative timeout,
372 GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) 379 GNUNET_TRANSPORT_AddressStringCallback asc,
380 void *asc_cls)
373{ 381{
374 struct PrettyPrinterContext *ppc; 382 struct PrettyPrinterContext *ppc;
375 383
376 ppc = GNUNET_new(struct PrettyPrinterContext); 384 ppc = GNUNET_new (struct PrettyPrinterContext);
377 ppc->sucess = GNUNET_NO; 385 ppc->sucess = GNUNET_NO;
378 ppc->saddr = saddr; 386 ppc->saddr = saddr;
379 ppc->asc = asc; 387 ppc->asc = asc;
380 ppc->asc_cls = asc_cls; 388 ppc->asc_cls = asc_cls;
381 ppc->plugin = GNUNET_strdup(type); 389 ppc->plugin = GNUNET_strdup (type);
382 ppc->options = options; 390 ppc->options = options;
383 ppc->resolver_handle = GNUNET_RESOLVER_ip_get(name, 391 ppc->resolver_handle = GNUNET_RESOLVER_ip_get (name,
384 AF_UNSPEC, 392 AF_UNSPEC,
385 timeout, 393 timeout,
386 &http_common_dns_ip_lookup_cb, 394 &http_common_dns_ip_lookup_cb,
387 ppc); 395 ppc);
388 if (NULL == ppc->resolver_handle) 396 if (NULL == ppc->resolver_handle)
389 { 397 {
390 GNUNET_free(ppc->plugin); 398 GNUNET_free (ppc->plugin);
391 GNUNET_free(ppc); 399 GNUNET_free (ppc);
392 return GNUNET_SYSERR; 400 return GNUNET_SYSERR;
393 } 401 }
394 GNUNET_CONTAINER_DLL_insert(dll_ppc_head, 402 GNUNET_CONTAINER_DLL_insert (dll_ppc_head,
395 dll_ppc_tail, 403 dll_ppc_tail,
396 ppc); 404 ppc);
397 return GNUNET_OK; 405 return GNUNET_OK;
398} 406}
399 407
@@ -413,13 +421,14 @@ http_common_dns_ip_lookup(const char *name,
413 * @param asc_cls closure for @a asc 421 * @param asc_cls closure for @a asc
414 */ 422 */
415void 423void
416http_common_plugin_address_pretty_printer(void *cls, const char *type, 424http_common_plugin_address_pretty_printer (void *cls, const char *type,
417 const void *addr, 425 const void *addr,
418 size_t addrlen, 426 size_t addrlen,
419 int numeric, 427 int numeric,
420 struct GNUNET_TIME_Relative timeout, 428 struct GNUNET_TIME_Relative timeout,
421 GNUNET_TRANSPORT_AddressStringCallback asc, 429 GNUNET_TRANSPORT_AddressStringCallback
422 void *asc_cls) 430 asc,
431 void *asc_cls)
423{ 432{
424 const struct HttpAddress *address = addr; 433 const struct HttpAddress *address = addr;
425 struct SplittedHTTPAddress *saddr; 434 struct SplittedHTTPAddress *saddr;
@@ -432,120 +441,120 @@ http_common_plugin_address_pretty_printer(void *cls, const char *type,
432 saddr = NULL; 441 saddr = NULL;
433 sock_addr = NULL; 442 sock_addr = NULL;
434 if ((addrlen < sizeof(struct HttpAddress)) || 443 if ((addrlen < sizeof(struct HttpAddress)) ||
435 (addrlen != http_common_address_get_size(address))) 444 (addrlen != http_common_address_get_size (address)))
436 { 445 {
437 GNUNET_break(0); 446 GNUNET_break (0);
438 goto handle_error; 447 goto handle_error;
439 } 448 }
440 449
441 addr_str = (char *)&address[1]; 450 addr_str = (char *) &address[1];
442 if (addr_str[ntohl(address->urlen) - 1] != '\0') 451 if (addr_str[ntohl (address->urlen) - 1] != '\0')
443 { 452 {
444 GNUNET_break(0); 453 GNUNET_break (0);
445 goto handle_error; 454 goto handle_error;
446 } 455 }
447 456
448 saddr = http_split_address(addr_str); 457 saddr = http_split_address (addr_str);
449 if (NULL == saddr) 458 if (NULL == saddr)
450 { 459 {
451 GNUNET_break(0); 460 GNUNET_break (0);
452 goto handle_error; 461 goto handle_error;
453 } 462 }
454 463
455 sock_addr = http_common_socket_from_address(addr, addrlen, &res); 464 sock_addr = http_common_socket_from_address (addr, addrlen, &res);
456 if (GNUNET_SYSERR == res) 465 if (GNUNET_SYSERR == res)
457 { 466 {
458 /* Malformed address */ 467 /* Malformed address */
459 GNUNET_break(0); 468 GNUNET_break (0);
460 goto handle_error; 469 goto handle_error;
461 } 470 }
462 else if (GNUNET_NO == res) 471 else if (GNUNET_NO == res)
463 { 472 {
464 /* Could not convert to IP */ 473 /* Could not convert to IP */
465 have_ip = GNUNET_NO; 474 have_ip = GNUNET_NO;
466 } 475 }
467 else if (GNUNET_YES == res) 476 else if (GNUNET_YES == res)
468 { 477 {
469 /* Converted to IP */ 478 /* Converted to IP */
470 have_ip = GNUNET_YES; 479 have_ip = GNUNET_YES;
471 } 480 }
472 else 481 else
473 { 482 {
474 /* Must not happen */ 483 /* Must not happen */
475 GNUNET_break(0); 484 GNUNET_break (0);
476 goto handle_error; 485 goto handle_error;
477 } 486 }
478 487
479 if ((GNUNET_YES == numeric) && 488 if ((GNUNET_YES == numeric) &&
480 (GNUNET_YES == have_ip)) 489 (GNUNET_YES == have_ip))
481 { 490 {
482 /* No lookup required */ 491 /* No lookup required */
483 ret = http_common_plugin_address_to_string(type, address, addrlen); 492 ret = http_common_plugin_address_to_string (type, address, addrlen);
484 asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); 493 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
485 asc(asc_cls, NULL, GNUNET_OK); 494 asc (asc_cls, NULL, GNUNET_OK);
486 http_clean_splitted(saddr); 495 http_clean_splitted (saddr);
487 GNUNET_free_non_null(sock_addr); 496 GNUNET_free_non_null (sock_addr);
488 return; 497 return;
489 } 498 }
490 if ((GNUNET_YES == numeric) && 499 if ((GNUNET_YES == numeric) &&
491 (GNUNET_NO == have_ip)) 500 (GNUNET_NO == have_ip))
492 { 501 {
493 /* Forward lookup */ 502 /* Forward lookup */
494 if (GNUNET_SYSERR == 503 if (GNUNET_SYSERR ==
495 http_common_dns_ip_lookup(saddr->host, type, saddr, 504 http_common_dns_ip_lookup (saddr->host, type, saddr,
496 address->options, timeout, 505 address->options, timeout,
497 asc, asc_cls)) 506 asc, asc_cls))
498 { 507 {
499 GNUNET_break(0); 508 GNUNET_break (0);
500 goto handle_error; 509 goto handle_error;
501 }
502 /* Wait for resolver callback */
503 GNUNET_free_non_null(sock_addr);
504 return;
505 } 510 }
511 /* Wait for resolver callback */
512 GNUNET_free_non_null (sock_addr);
513 return;
514 }
506 if ((GNUNET_NO == numeric) && 515 if ((GNUNET_NO == numeric) &&
507 (GNUNET_YES == have_ip)) 516 (GNUNET_YES == have_ip))
508 { 517 {
509 /* Reverse lookup */ 518 /* Reverse lookup */
510 if (GNUNET_SYSERR == 519 if (GNUNET_SYSERR ==
511 http_common_dns_reverse_lookup(sock_addr, 520 http_common_dns_reverse_lookup (sock_addr,
512 (AF_INET == sock_addr->sa_family) 521 (AF_INET == sock_addr->sa_family)
513 ? sizeof(struct sockaddr_in) 522 ? sizeof(struct sockaddr_in)
514 : sizeof(struct sockaddr_in6), 523 : sizeof(struct sockaddr_in6),
515 type, 524 type,
516 saddr, 525 saddr,
517 address->options, timeout, 526 address->options, timeout,
518 asc, asc_cls)) 527 asc, asc_cls))
519 { 528 {
520 GNUNET_break(0); 529 GNUNET_break (0);
521 goto handle_error; 530 goto handle_error;
522 }
523 /* Wait for resolver callback */
524 GNUNET_free_non_null(sock_addr);
525 return;
526 } 531 }
532 /* Wait for resolver callback */
533 GNUNET_free_non_null (sock_addr);
534 return;
535 }
527 if ((GNUNET_NO == numeric) && 536 if ((GNUNET_NO == numeric) &&
528 (GNUNET_NO == have_ip)) 537 (GNUNET_NO == have_ip))
529 { 538 {
530 /* No lookup required */ 539 /* No lookup required */
531 ret = http_common_plugin_address_to_string(type, address, addrlen); 540 ret = http_common_plugin_address_to_string (type, address, addrlen);
532 asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); 541 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
533 asc(asc_cls, NULL, GNUNET_OK); 542 asc (asc_cls, NULL, GNUNET_OK);
534 GNUNET_free_non_null(sock_addr); 543 GNUNET_free_non_null (sock_addr);
535 http_clean_splitted(saddr); 544 http_clean_splitted (saddr);
536 return; 545 return;
537 } 546 }
538 /* Error (argument supplied not GNUNET_YES or GNUNET_NO) */ 547 /* Error (argument supplied not GNUNET_YES or GNUNET_NO) */
539 GNUNET_break(0); 548 GNUNET_break (0);
540 goto handle_error; 549 goto handle_error;
541 550
542handle_error: 551handle_error:
543 /* Report error */ 552 /* Report error */
544 asc(asc_cls, NULL, GNUNET_SYSERR); 553 asc (asc_cls, NULL, GNUNET_SYSERR);
545 asc(asc_cls, NULL, GNUNET_OK); 554 asc (asc_cls, NULL, GNUNET_OK);
546 GNUNET_free_non_null(sock_addr); 555 GNUNET_free_non_null (sock_addr);
547 if (NULL != saddr) 556 if (NULL != saddr)
548 http_clean_splitted(saddr); 557 http_clean_splitted (saddr);
549} 558}
550 559
551 560
@@ -553,36 +562,36 @@ handle_error:
553 * FIXME. 562 * FIXME.
554 */ 563 */
555const char * 564const char *
556http_common_plugin_address_to_url(void *cls, 565http_common_plugin_address_to_url (void *cls,
557 const void *addr, 566 const void *addr,
558 size_t addrlen) 567 size_t addrlen)
559{ 568{
560 static char rbuf[1024]; 569 static char rbuf[1024];
561 const struct HttpAddress *address = addr; 570 const struct HttpAddress *address = addr;
562 const char * addr_str; 571 const char *addr_str;
563 572
564 if (NULL == addr) 573 if (NULL == addr)
565 { 574 {
566 GNUNET_break(0); 575 GNUNET_break (0);
567 return NULL; 576 return NULL;
568 } 577 }
569 if (0 == addrlen) 578 if (0 == addrlen)
570 { 579 {
571 GNUNET_break(0); 580 GNUNET_break (0);
572 return NULL; 581 return NULL;
573 } 582 }
574 if (addrlen != http_common_address_get_size(address)) 583 if (addrlen != http_common_address_get_size (address))
575 { 584 {
576 GNUNET_break(0); 585 GNUNET_break (0);
577 return NULL; 586 return NULL;
578 } 587 }
579 addr_str = (char *)&address[1]; 588 addr_str = (char *) &address[1];
580 if (addr_str[ntohl(address->urlen) - 1] != '\0') 589 if (addr_str[ntohl (address->urlen) - 1] != '\0')
581 return NULL; 590 return NULL;
582 591
583 GNUNET_memcpy(rbuf, 592 GNUNET_memcpy (rbuf,
584 &address[1], 593 &address[1],
585 ntohl(address->urlen)); 594 ntohl (address->urlen));
586 return rbuf; 595 return rbuf;
587} 596}
588 597
@@ -599,35 +608,35 @@ http_common_plugin_address_to_url(void *cls,
599 * @return string representing the same address 608 * @return string representing the same address
600 */ 609 */
601const char * 610const char *
602http_common_plugin_address_to_string(const char *plugin, 611http_common_plugin_address_to_string (const char *plugin,
603 const void *addr, 612 const void *addr,
604 size_t addrlen) 613 size_t addrlen)
605{ 614{
606 static char rbuf[1024]; 615 static char rbuf[1024];
607 const struct HttpAddress *address = addr; 616 const struct HttpAddress *address = addr;
608 const char * addr_str; 617 const char *addr_str;
609 char *res; 618 char *res;
610 619
611 GNUNET_assert(NULL != plugin); 620 GNUNET_assert (NULL != plugin);
612 if (NULL == addr) 621 if (NULL == addr)
613 return NULL; 622 return NULL;
614 if (0 == addrlen) 623 if (0 == addrlen)
615 return NULL; 624 return NULL;
616 if (addrlen != http_common_address_get_size(address)) 625 if (addrlen != http_common_address_get_size (address))
617 return NULL; 626 return NULL;
618 addr_str = (char *)&address[1]; 627 addr_str = (char *) &address[1];
619 if (addr_str[ntohl(address->urlen) - 1] != '\0') 628 if (addr_str[ntohl (address->urlen) - 1] != '\0')
620 return NULL; 629 return NULL;
621 GNUNET_asprintf(&res, "%s.%u.%s", plugin, ntohl(address->options), 630 GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl (address->options),
622 &address[1]); 631 &address[1]);
623 if (strlen(res) + 1 < 500) 632 if (strlen (res) + 1 < 500)
624 { 633 {
625 GNUNET_memcpy(rbuf, res, strlen(res) + 1); 634 GNUNET_memcpy (rbuf, res, strlen (res) + 1);
626 GNUNET_free(res); 635 GNUNET_free (res);
627 return rbuf; 636 return rbuf;
628 } 637 }
629 GNUNET_break(0); 638 GNUNET_break (0);
630 GNUNET_free(res); 639 GNUNET_free (res);
631 return NULL; 640 return NULL;
632} 641}
633 642
@@ -644,11 +653,11 @@ http_common_plugin_address_to_string(const char *plugin,
644 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 653 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
645 */ 654 */
646int 655int
647http_common_plugin_string_to_address(void *cls, 656http_common_plugin_string_to_address (void *cls,
648 const char *addr, 657 const char *addr,
649 uint16_t addrlen, 658 uint16_t addrlen,
650 void **buf, 659 void **buf,
651 size_t *added) 660 size_t *added)
652{ 661{
653 struct HttpAddress *a; 662 struct HttpAddress *a;
654 char *address; 663 char *address;
@@ -662,50 +671,50 @@ http_common_plugin_string_to_address(void *cls,
662 plugin = NULL; 671 plugin = NULL;
663 optionstr = NULL; 672 optionstr = NULL;
664 if ((NULL == addr) || (addrlen == 0)) 673 if ((NULL == addr) || (addrlen == 0))
665 { 674 {
666 GNUNET_break(0); 675 GNUNET_break (0);
667 return GNUNET_SYSERR; 676 return GNUNET_SYSERR;
668 } 677 }
669 if ('\0' != addr[addrlen - 1]) 678 if ('\0' != addr[addrlen - 1])
670 { 679 {
671 GNUNET_break(0); 680 GNUNET_break (0);
672 return GNUNET_SYSERR; 681 return GNUNET_SYSERR;
673 } 682 }
674 if (strlen(addr) != addrlen - 1) 683 if (strlen (addr) != addrlen - 1)
675 { 684 {
676 GNUNET_break(0); 685 GNUNET_break (0);
677 return GNUNET_SYSERR; 686 return GNUNET_SYSERR;
678 } 687 }
679 plugin = GNUNET_strdup(addr); 688 plugin = GNUNET_strdup (addr);
680 optionstr = strchr(plugin, '.'); 689 optionstr = strchr (plugin, '.');
681 if (NULL == optionstr) 690 if (NULL == optionstr)
682 { 691 {
683 GNUNET_break(0); 692 GNUNET_break (0);
684 GNUNET_free(plugin); 693 GNUNET_free (plugin);
685 return GNUNET_SYSERR; 694 return GNUNET_SYSERR;
686 } 695 }
687 optionstr[0] = '\0'; 696 optionstr[0] = '\0';
688 optionstr++; 697 optionstr++;
689 options = atol(optionstr); /* 0 on conversion error, that's ok */ 698 options = atol (optionstr); /* 0 on conversion error, that's ok */
690 address = strchr(optionstr, '.'); 699 address = strchr (optionstr, '.');
691 if (NULL == address) 700 if (NULL == address)
692 { 701 {
693 GNUNET_break(0); 702 GNUNET_break (0);
694 GNUNET_free(plugin); 703 GNUNET_free (plugin);
695 return GNUNET_SYSERR; 704 return GNUNET_SYSERR;
696 } 705 }
697 address[0] = '\0'; 706 address[0] = '\0';
698 address++; 707 address++;
699 urlen = strlen(address) + 1; 708 urlen = strlen (address) + 1;
700 709
701 a = GNUNET_malloc(sizeof(struct HttpAddress) + urlen); 710 a = GNUNET_malloc (sizeof(struct HttpAddress) + urlen);
702 a->options = htonl(options); 711 a->options = htonl (options);
703 a->urlen = htonl(urlen); 712 a->urlen = htonl (urlen);
704 GNUNET_memcpy(&a[1], address, urlen); 713 GNUNET_memcpy (&a[1], address, urlen);
705 714
706 (*buf) = a; 715 (*buf) = a;
707 (*added) = sizeof(struct HttpAddress) + urlen; 716 (*added) = sizeof(struct HttpAddress) + urlen;
708 GNUNET_free(plugin); 717 GNUNET_free (plugin);
709 return GNUNET_OK; 718 return GNUNET_OK;
710} 719}
711 720
@@ -719,25 +728,25 @@ http_common_plugin_string_to_address(void *cls,
719 * @return the HttpAddress 728 * @return the HttpAddress
720 */ 729 */
721struct HttpAddress * 730struct HttpAddress *
722http_common_address_from_socket(const char *protocol, 731http_common_address_from_socket (const char *protocol,
723 const struct sockaddr *addr, 732 const struct sockaddr *addr,
724 socklen_t addrlen) 733 socklen_t addrlen)
725{ 734{
726 struct HttpAddress *address = NULL; 735 struct HttpAddress *address = NULL;
727 char *res; 736 char *res;
728 size_t len; 737 size_t len;
729 738
730 GNUNET_asprintf(&res, 739 GNUNET_asprintf (&res,
731 "%s://%s", 740 "%s://%s",
732 protocol, 741 protocol,
733 GNUNET_a2s(addr, 742 GNUNET_a2s (addr,
734 addrlen)); 743 addrlen));
735 len = strlen(res) + 1; 744 len = strlen (res) + 1;
736 address = GNUNET_malloc(sizeof(struct HttpAddress) + len); 745 address = GNUNET_malloc (sizeof(struct HttpAddress) + len);
737 address->options = htonl(HTTP_OPTIONS_NONE); 746 address->options = htonl (HTTP_OPTIONS_NONE);
738 address->urlen = htonl(len); 747 address->urlen = htonl (len);
739 GNUNET_memcpy(&address[1], res, len); 748 GNUNET_memcpy (&address[1], res, len);
740 GNUNET_free(res); 749 GNUNET_free (res);
741 return address; 750 return address;
742} 751}
743 752
@@ -754,79 +763,79 @@ http_common_address_from_socket(const char *protocol,
754 * @return the string 763 * @return the string
755 */ 764 */
756struct sockaddr * 765struct sockaddr *
757http_common_socket_from_address(const void *addr, 766http_common_socket_from_address (const void *addr,
758 size_t addrlen, 767 size_t addrlen,
759 int *res) 768 int *res)
760{ 769{
761 const struct HttpAddress *ha; 770 const struct HttpAddress *ha;
762 struct SplittedHTTPAddress * spa; 771 struct SplittedHTTPAddress *spa;
763 struct sockaddr_storage *s; 772 struct sockaddr_storage *s;
764 char * to_conv; 773 char *to_conv;
765 size_t urlen; 774 size_t urlen;
766 775
767 (*res) = GNUNET_SYSERR; 776 (*res) = GNUNET_SYSERR;
768 ha = (const struct HttpAddress *)addr; 777 ha = (const struct HttpAddress *) addr;
769 if (NULL == addr) 778 if (NULL == addr)
770 { 779 {
771 GNUNET_break(0); 780 GNUNET_break (0);
772 return NULL; 781 return NULL;
773 } 782 }
774 if (0 == addrlen) 783 if (0 == addrlen)
775 { 784 {
776 GNUNET_break(0); 785 GNUNET_break (0);
777 return NULL; 786 return NULL;
778 } 787 }
779 if (addrlen < sizeof(struct HttpAddress)) 788 if (addrlen < sizeof(struct HttpAddress))
780 { 789 {
781 GNUNET_break(0); 790 GNUNET_break (0);
782 return NULL; 791 return NULL;
783 } 792 }
784 urlen = ntohl(ha->urlen); 793 urlen = ntohl (ha->urlen);
785 if (sizeof(struct HttpAddress) + urlen != addrlen) 794 if (sizeof(struct HttpAddress) + urlen != addrlen)
786 { 795 {
787 /* This is a legacy addresses */ 796 /* This is a legacy addresses */
788 return NULL; 797 return NULL;
789 } 798 }
790 if (addrlen < sizeof(struct HttpAddress) + urlen) 799 if (addrlen < sizeof(struct HttpAddress) + urlen)
791 { 800 {
792 /* This is a legacy addresses */ 801 /* This is a legacy addresses */
793 return NULL; 802 return NULL;
794 } 803 }
795 if (((char *)addr)[addrlen - 1] != '\0') 804 if (((char *) addr)[addrlen - 1] != '\0')
796 { 805 {
797 GNUNET_break(0); 806 GNUNET_break (0);
798 return NULL; 807 return NULL;
799 } 808 }
800 spa = http_split_address((const char *)&ha[1]); 809 spa = http_split_address ((const char *) &ha[1]);
801 if (NULL == spa) 810 if (NULL == spa)
802 { 811 {
803 (*res) = GNUNET_SYSERR; 812 (*res) = GNUNET_SYSERR;
804 return NULL; 813 return NULL;
805 } 814 }
806 815
807 s = GNUNET_new(struct sockaddr_storage); 816 s = GNUNET_new (struct sockaddr_storage);
808 GNUNET_asprintf(&to_conv, "%s:%u", spa->host, spa->port); 817 GNUNET_asprintf (&to_conv, "%s:%u", spa->host, spa->port);
809 if (GNUNET_SYSERR 818 if (GNUNET_SYSERR
810 == GNUNET_STRINGS_to_address_ip(to_conv, strlen(to_conv), s)) 819 == GNUNET_STRINGS_to_address_ip (to_conv, strlen (to_conv), s))
811 { 820 {
812 /* could be a hostname */ 821 /* could be a hostname */
813 GNUNET_free(s); 822 GNUNET_free (s);
814 (*res) = GNUNET_NO; 823 (*res) = GNUNET_NO;
815 s = NULL; 824 s = NULL;
816 } 825 }
817 else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family)) 826 else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family))
818 { 827 {
819 GNUNET_free(s); 828 GNUNET_free (s);
820 (*res) = GNUNET_SYSERR; 829 (*res) = GNUNET_SYSERR;
821 s = NULL; 830 s = NULL;
822 } 831 }
823 else 832 else
824 { 833 {
825 (*res) = GNUNET_YES; 834 (*res) = GNUNET_YES;
826 } 835 }
827 http_clean_splitted(spa); 836 http_clean_splitted (spa);
828 GNUNET_free(to_conv); 837 GNUNET_free (to_conv);
829 return (struct sockaddr *)s; 838 return (struct sockaddr *) s;
830} 839}
831 840
832 841
@@ -837,9 +846,9 @@ http_common_socket_from_address(const void *addr,
837 * @return the size 846 * @return the size
838 */ 847 */
839size_t 848size_t
840http_common_address_get_size(const struct HttpAddress * addr) 849http_common_address_get_size (const struct HttpAddress *addr)
841{ 850{
842 return sizeof(struct HttpAddress) + ntohl(addr->urlen); 851 return sizeof(struct HttpAddress) + ntohl (addr->urlen);
843} 852}
844 853
845 854
@@ -853,18 +862,18 @@ http_common_address_get_size(const struct HttpAddress * addr)
853 * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error 862 * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error
854 */ 863 */
855size_t 864size_t
856http_common_cmp_addresses(const void *addr1, 865http_common_cmp_addresses (const void *addr1,
857 size_t addrlen1, 866 size_t addrlen1,
858 const void *addr2, 867 const void *addr2,
859 size_t addrlen2) 868 size_t addrlen2)
860{ 869{
861 const char *a1 = addr1; 870 const char *a1 = addr1;
862 const char *a2 = addr2; 871 const char *a2 = addr2;
863 const struct HttpAddress *ha1; 872 const struct HttpAddress *ha1;
864 const struct HttpAddress *ha2; 873 const struct HttpAddress *ha2;
865 874
866 ha1 = (const struct HttpAddress *)a1; 875 ha1 = (const struct HttpAddress *) a1;
867 ha2 = (const struct HttpAddress *)a2; 876 ha2 = (const struct HttpAddress *) a2;
868 877
869 if (NULL == a1) 878 if (NULL == a1)
870 return GNUNET_SYSERR; 879 return GNUNET_SYSERR;
@@ -885,7 +894,7 @@ http_common_cmp_addresses(const void *addr1,
885 if (ha1->urlen != ha2->urlen) 894 if (ha1->urlen != ha2->urlen)
886 return GNUNET_NO; 895 return GNUNET_NO;
887 896
888 if (0 == strcmp((const char *)&ha1[1], (const char *)&ha2[1])) 897 if (0 == strcmp ((const char *) &ha1[1], (const char *) &ha2[1]))
889 return GNUNET_YES; 898 return GNUNET_YES;
890 return GNUNET_NO; 899 return GNUNET_NO;
891} 900}
@@ -899,8 +908,9 @@ http_common_cmp_addresses(const void *addr1,
899 * @return the network type 908 * @return the network type
900 */ 909 */
901enum GNUNET_NetworkType 910enum GNUNET_NetworkType
902http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *env, 911http_common_get_network_for_address (struct
903 const struct GNUNET_HELLO_Address *address) 912 GNUNET_TRANSPORT_PluginEnvironment *env,
913 const struct GNUNET_HELLO_Address *address)
904{ 914{
905 struct sockaddr *sa; 915 struct sockaddr *sa;
906 enum GNUNET_NetworkType net_type; 916 enum GNUNET_NetworkType net_type;
@@ -908,27 +918,27 @@ http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *e
908 int res; 918 int res;
909 919
910 net_type = GNUNET_NT_UNSPECIFIED; 920 net_type = GNUNET_NT_UNSPECIFIED;
911 sa = http_common_socket_from_address(address->address, 921 sa = http_common_socket_from_address (address->address,
912 address->address_length, 922 address->address_length,
913 &res); 923 &res);
914 if (GNUNET_SYSERR == res) 924 if (GNUNET_SYSERR == res)
915 return net_type; 925 return net_type;
916 if (GNUNET_YES == res) 926 if (GNUNET_YES == res)
927 {
928 GNUNET_assert (NULL != sa);
929 if (AF_INET == sa->sa_family)
917 { 930 {
918 GNUNET_assert(NULL != sa); 931 salen = sizeof(struct sockaddr_in);
919 if (AF_INET == sa->sa_family) 932 }
920 { 933 else if (AF_INET6 == sa->sa_family)
921 salen = sizeof(struct sockaddr_in); 934 {
922 } 935 salen = sizeof(struct sockaddr_in6);
923 else if (AF_INET6 == sa->sa_family)
924 {
925 salen = sizeof(struct sockaddr_in6);
926 }
927 net_type = env->get_address_type(env->cls,
928 sa,
929 salen);
930 GNUNET_free(sa);
931 } 936 }
937 net_type = env->get_address_type (env->cls,
938 sa,
939 salen);
940 GNUNET_free (sa);
941 }
932 return net_type; 942 return net_type;
933} 943}
934 944
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 @@
33#define TESTING GNUNET_NO 33#define TESTING GNUNET_NO
34 34
35#if TESTING 35#if TESTING
36#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) 36#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
37#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) 37 GNUNET_TIME_UNIT_SECONDS, 3)
38#define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 7) 38#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
39#define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 7) 39 GNUNET_TIME_UNIT_SECONDS, 3)
40#define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply ( \
41 GNUNET_TIME_UNIT_SECONDS, 7)
42#define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply ( \
43 GNUNET_TIME_UNIT_SECONDS, 7)
40#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG 44#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
41 45
42#else 46#else
@@ -47,8 +51,10 @@
47#define PROTOCOL "http" 51#define PROTOCOL "http"
48#endif 52#endif
49 53
50#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 54#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
51#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 55 GNUNET_TIME_UNIT_SECONDS, 15)
56#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
57 GNUNET_TIME_UNIT_SECONDS, 15)
52#define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT 58#define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
53#define HTTP_SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT 59#define HTTP_SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
54#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG 60#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
@@ -61,7 +67,8 @@
61/** 67/**
62 * Bits in the `options` field of HTTP addresses. 68 * Bits in the `options` field of HTTP addresses.
63 */ 69 */
64enum HttpAddressOptions { 70enum HttpAddressOptions
71{
65 /** 72 /**
66 * No bits set. 73 * No bits set.
67 */ 74 */
@@ -86,7 +93,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
86/** 93/**
87 * HttpAddress 94 * HttpAddress
88 */ 95 */
89struct HttpAddress { 96struct HttpAddress
97{
90 /** 98 /**
91 * Address options 99 * Address options
92 * see `enum HttpAddressOptions` 100 * see `enum HttpAddressOptions`
@@ -104,7 +112,8 @@ GNUNET_NETWORK_STRUCT_END
104/** 112/**
105 * Representation of HTTP URL split into its components. 113 * Representation of HTTP URL split into its components.
106 */ 114 */
107struct SplittedHTTPAddress { 115struct SplittedHTTPAddress
116{
108 char *protocol; 117 char *protocol;
109 char *host; 118 char *host;
110 char *path; 119 char *path;
@@ -117,7 +126,7 @@ struct SplittedHTTPAddress {
117 * and path components. 126 * and path components.
118 */ 127 */
119struct SplittedHTTPAddress * 128struct SplittedHTTPAddress *
120http_split_address(const char *addr); 129http_split_address (const char *addr);
121 130
122 131
123/** 132/**
@@ -135,14 +144,15 @@ http_split_address(const char *addr);
135 * @param asc_cls closure for @a asc 144 * @param asc_cls closure for @a asc
136 */ 145 */
137void 146void
138http_common_plugin_address_pretty_printer(void *cls, 147http_common_plugin_address_pretty_printer (void *cls,
139 const char *type, 148 const char *type,
140 const void *addr, 149 const void *addr,
141 size_t addrlen, 150 size_t addrlen,
142 int numeric, 151 int numeric,
143 struct GNUNET_TIME_Relative timeout, 152 struct GNUNET_TIME_Relative timeout,
144 GNUNET_TRANSPORT_AddressStringCallback asc, 153 GNUNET_TRANSPORT_AddressStringCallback
145 void *asc_cls); 154 asc,
155 void *asc_cls);
146 156
147 157
148/** 158/**
@@ -157,9 +167,9 @@ http_common_plugin_address_pretty_printer(void *cls,
157 * @return string representing the same address 167 * @return string representing the same address
158 */ 168 */
159const char * 169const char *
160http_common_plugin_address_to_string(const char *plugin, 170http_common_plugin_address_to_string (const char *plugin,
161 const void *addr, 171 const void *addr,
162 size_t addrlen); 172 size_t addrlen);
163 173
164 174
165/** 175/**
@@ -175,11 +185,11 @@ http_common_plugin_address_to_string(const char *plugin,
175 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 185 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
176 */ 186 */
177int 187int
178http_common_plugin_string_to_address(void *cls, 188http_common_plugin_string_to_address (void *cls,
179 const char *addr, 189 const char *addr,
180 uint16_t addrlen, 190 uint16_t addrlen,
181 void **buf, 191 void **buf,
182 size_t *added); 192 size_t *added);
183 193
184 194
185/** 195/**
@@ -191,9 +201,9 @@ http_common_plugin_string_to_address(void *cls,
191 * @return the string 201 * @return the string
192 */ 202 */
193struct HttpAddress * 203struct HttpAddress *
194http_common_address_from_socket(const char *protocol, 204http_common_address_from_socket (const char *protocol,
195 const struct sockaddr *addr, 205 const struct sockaddr *addr,
196 socklen_t addrlen); 206 socklen_t addrlen);
197 207
198 208
199/** 209/**
@@ -208,15 +218,15 @@ http_common_address_from_socket(const char *protocol,
208 * @return the string 218 * @return the string
209 */ 219 */
210struct sockaddr * 220struct sockaddr *
211http_common_socket_from_address(const void *addr, 221http_common_socket_from_address (const void *addr,
212 size_t addrlen, 222 size_t addrlen,
213 int *res); 223 int *res);
214 224
215 225
216const char * 226const char *
217http_common_plugin_address_to_url(void *cls, 227http_common_plugin_address_to_url (void *cls,
218 const void *addr, 228 const void *addr,
219 size_t addrlen); 229 size_t addrlen);
220 230
221 231
222/** 232/**
@@ -226,7 +236,7 @@ http_common_plugin_address_to_url(void *cls,
226 * @return the size 236 * @return the size
227 */ 237 */
228size_t 238size_t
229http_common_address_get_size(const struct HttpAddress * addr); 239http_common_address_get_size (const struct HttpAddress *addr);
230 240
231 241
232/** 242/**
@@ -239,10 +249,10 @@ http_common_address_get_size(const struct HttpAddress * addr);
239 * @return #GNUNET_YES if equal, #GNUNET_NO else 249 * @return #GNUNET_YES if equal, #GNUNET_NO else
240 */ 250 */
241size_t 251size_t
242http_common_cmp_addresses(const void *addr1, 252http_common_cmp_addresses (const void *addr1,
243 size_t addrlen1, 253 size_t addrlen1,
244 const void *addr2, 254 const void *addr2,
245 size_t addrlen2); 255 size_t addrlen2);
246 256
247 257
248/** 258/**
@@ -253,8 +263,10 @@ http_common_cmp_addresses(const void *addr1,
253 * @return the network type 263 * @return the network type
254 */ 264 */
255enum GNUNET_NetworkType 265enum GNUNET_NetworkType
256http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *env, 266http_common_get_network_for_address (struct
257 const struct GNUNET_HELLO_Address *address); 267 GNUNET_TRANSPORT_PluginEnvironment *env,
268 const struct
269 GNUNET_HELLO_Address *address);
258 270
259 271
260/* end of plugin_transport_http_common.h */ 272/* 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 @@
38 38
39#if BUILD_HTTPS 39#if BUILD_HTTPS
40#define PLUGIN_NAME "https_server" 40#define PLUGIN_NAME "https_server"
41#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_server_init 41#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \
42#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_server_done 42 libgnunet_plugin_transport_https_server_init
43#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \
44 libgnunet_plugin_transport_https_server_done
43#else 45#else
44#define PLUGIN_NAME "http_server" 46#define PLUGIN_NAME "http_server"
45#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_server_init 47#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \
46#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_server_done 48 libgnunet_plugin_transport_http_server_init
49#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \
50 libgnunet_plugin_transport_http_server_done
47#endif 51#endif
48 52
49#define HTTP_ERROR_RESPONSE "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY><H1>Not Found</H1>The requested URL was not found on this server.<P><HR><ADDRESS></ADDRESS></BODY></HTML>" 53#define HTTP_ERROR_RESPONSE \
54 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY><H1>Not Found</H1>The requested URL was not found on this server.<P><HR><ADDRESS></ADDRESS></BODY></HTML>"
50#define _RECEIVE 0 55#define _RECEIVE 0
51#define _SEND 1 56#define _SEND 1
52 57
53 58
54#define LOG(kind, ...) GNUNET_log_from(kind, "transport-" PLUGIN_NAME, __VA_ARGS__) 59#define LOG(kind, ...) GNUNET_log_from (kind, "transport-" PLUGIN_NAME, \
60 __VA_ARGS__)
55 61
56 62
57/** 63/**
58 * Information we keep with MHD for an HTTP request. 64 * Information we keep with MHD for an HTTP request.
59 */ 65 */
60struct ServerRequest { 66struct ServerRequest
67{
61 /** 68 /**
62 * The session this server request belongs to 69 * The session this server request belongs to
63 * Can be NULL, when session was disconnected and freed 70 * Can be NULL, when session was disconnected and freed
@@ -101,7 +108,8 @@ struct ServerRequest {
101/** 108/**
102 * Wrapper to manage addresses 109 * Wrapper to manage addresses
103 */ 110 */
104struct HttpAddressWrapper { 111struct HttpAddressWrapper
112{
105 /** 113 /**
106 * Linked list next 114 * Linked list next
107 */ 115 */
@@ -127,7 +135,8 @@ struct HttpAddressWrapper {
127/** 135/**
128 * Message to send using http 136 * Message to send using http
129 */ 137 */
130struct HTTP_Message { 138struct HTTP_Message
139{
131 /** 140 /**
132 * next pointer for double linked list 141 * next pointer for double linked list
133 */ 142 */
@@ -175,7 +184,8 @@ struct HTTP_Message {
175/** 184/**
176 * Session handle for connections. 185 * Session handle for connections.
177 */ 186 */
178struct GNUNET_ATS_Session { 187struct GNUNET_ATS_Session
188{
179 /** 189 /**
180 * To whom are we talking to (set to our identity 190 * To whom are we talking to (set to our identity
181 * if we are still waiting for the welcome message) 191 * if we are still waiting for the welcome message)
@@ -231,12 +241,12 @@ struct GNUNET_ATS_Session {
231 /** 241 /**
232 * Session timeout task 242 * Session timeout task
233 */ 243 */
234 struct GNUNET_SCHEDULER_Task * timeout_task; 244 struct GNUNET_SCHEDULER_Task *timeout_task;
235 245
236 /** 246 /**
237 * Task to resume MHD handling when receiving is allowed again 247 * Task to resume MHD handling when receiving is allowed again
238 */ 248 */
239 struct GNUNET_SCHEDULER_Task * recv_wakeup_task; 249 struct GNUNET_SCHEDULER_Task *recv_wakeup_task;
240 250
241 /** 251 /**
242 * Number of bytes waiting for transmission to this peer. 252 * Number of bytes waiting for transmission to this peer.
@@ -268,7 +278,8 @@ struct GNUNET_ATS_Session {
268/** 278/**
269 * Encapsulation of all of the state of the plugin. 279 * Encapsulation of all of the state of the plugin.
270 */ 280 */
271struct HTTP_Server_Plugin { 281struct HTTP_Server_Plugin
282{
272 /** 283 /**
273 * Our environment. 284 * Our environment.
274 */ 285 */
@@ -461,15 +472,15 @@ struct HTTP_Server_Plugin {
461 * @param state new state of the session 472 * @param state new state of the session
462 */ 473 */
463static void 474static void
464notify_session_monitor(struct HTTP_Server_Plugin *plugin, 475notify_session_monitor (struct HTTP_Server_Plugin *plugin,
465 struct GNUNET_ATS_Session *session, 476 struct GNUNET_ATS_Session *session,
466 enum GNUNET_TRANSPORT_SessionState state) 477 enum GNUNET_TRANSPORT_SessionState state)
467{ 478{
468 struct GNUNET_TRANSPORT_SessionInfo info; 479 struct GNUNET_TRANSPORT_SessionInfo info;
469 480
470 if (NULL == plugin->sic) 481 if (NULL == plugin->sic)
471 return; 482 return;
472 memset(&info, 0, sizeof(info)); 483 memset (&info, 0, sizeof(info));
473 info.state = state; 484 info.state = state;
474 info.is_inbound = GNUNET_YES; 485 info.is_inbound = GNUNET_YES;
475 info.num_msg_pending = session->msgs_in_queue; 486 info.num_msg_pending = session->msgs_in_queue;
@@ -477,9 +488,9 @@ notify_session_monitor(struct HTTP_Server_Plugin *plugin,
477 info.receive_delay = session->next_receive; 488 info.receive_delay = session->next_receive;
478 info.session_timeout = session->timeout; 489 info.session_timeout = session->timeout;
479 info.address = session->address; 490 info.address = session->address;
480 plugin->sic(plugin->sic_cls, 491 plugin->sic (plugin->sic_cls,
481 session, 492 session,
482 &info); 493 &info);
483} 494}
484 495
485 496
@@ -489,16 +500,16 @@ notify_session_monitor(struct HTTP_Server_Plugin *plugin,
489 * @param cls the session 500 * @param cls the session
490 */ 501 */
491static void 502static void
492server_wake_up(void *cls) 503server_wake_up (void *cls)
493{ 504{
494 struct GNUNET_ATS_Session *s = cls; 505 struct GNUNET_ATS_Session *s = cls;
495 506
496 s->recv_wakeup_task = NULL; 507 s->recv_wakeup_task = NULL;
497 LOG(GNUNET_ERROR_TYPE_DEBUG, 508 LOG (GNUNET_ERROR_TYPE_DEBUG,
498 "Session %p: Waking up PUT handle\n", 509 "Session %p: Waking up PUT handle\n",
499 s); 510 s);
500 GNUNET_assert(s->server_recv->suspended); 511 GNUNET_assert (s->server_recv->suspended);
501 MHD_resume_connection(s->server_recv->mhd_conn); 512 MHD_resume_connection (s->server_recv->mhd_conn);
502 s->server_recv->suspended = false; 513 s->server_recv->suspended = false;
503} 514}
504 515
@@ -512,9 +523,9 @@ server_wake_up(void *cls)
512 * until timeout 523 * until timeout
513 */ 524 */
514static void 525static void
515server_reschedule(struct HTTP_Server_Plugin *plugin, 526server_reschedule (struct HTTP_Server_Plugin *plugin,
516 struct MHD_Daemon *server, 527 struct MHD_Daemon *server,
517 int now); 528 int now);
518 529
519 530
520/** 531/**
@@ -523,106 +534,106 @@ server_reschedule(struct HTTP_Server_Plugin *plugin,
523 * @param s the session to delete 534 * @param s the session to delete
524 */ 535 */
525static void 536static void
526server_delete_session(struct GNUNET_ATS_Session *s) 537server_delete_session (struct GNUNET_ATS_Session *s)
527{ 538{
528 struct HTTP_Server_Plugin *plugin = s->plugin; 539 struct HTTP_Server_Plugin *plugin = s->plugin;
529 struct HTTP_Message *msg; 540 struct HTTP_Message *msg;
530 541
531 if (NULL != s->timeout_task) 542 if (NULL != s->timeout_task)
532 { 543 {
533 GNUNET_SCHEDULER_cancel(s->timeout_task); 544 GNUNET_SCHEDULER_cancel (s->timeout_task);
534 s->timeout_task = NULL; 545 s->timeout_task = NULL;
535 s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 546 s->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
536 } 547 }
537 if (NULL != s->recv_wakeup_task) 548 if (NULL != s->recv_wakeup_task)
538 { 549 {
539 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); 550 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
540 s->recv_wakeup_task = NULL; 551 s->recv_wakeup_task = NULL;
541 if (NULL != s->server_recv) 552 if (NULL != s->server_recv)
542 { 553 {
543 GNUNET_assert(s->server_recv->suspended); 554 GNUNET_assert (s->server_recv->suspended);
544 s->server_recv->suspended = false; 555 s->server_recv->suspended = false;
545 MHD_resume_connection(s->server_recv->mhd_conn); 556 MHD_resume_connection (s->server_recv->mhd_conn);
546 } 557 }
547 } 558 }
548 GNUNET_assert(GNUNET_OK == 559 GNUNET_assert (GNUNET_OK ==
549 GNUNET_CONTAINER_multipeermap_remove(plugin->sessions, 560 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions,
550 &s->target, 561 &s->target,
551 s)); 562 s));
552 while (NULL != (msg = s->msg_head)) 563 while (NULL != (msg = s->msg_head))
553 { 564 {
554 GNUNET_CONTAINER_DLL_remove(s->msg_head, 565 GNUNET_CONTAINER_DLL_remove (s->msg_head,
555 s->msg_tail, 566 s->msg_tail,
556 msg); 567 msg);
557 if (NULL != msg->transmit_cont) 568 if (NULL != msg->transmit_cont)
558 msg->transmit_cont(msg->transmit_cont_cls, 569 msg->transmit_cont (msg->transmit_cont_cls,
559 &s->target, 570 &s->target,
560 GNUNET_SYSERR, 571 GNUNET_SYSERR,
561 msg->size, 572 msg->size,
562 msg->pos + msg->overhead); 573 msg->pos + msg->overhead);
563 GNUNET_assert(s->msgs_in_queue > 0); 574 GNUNET_assert (s->msgs_in_queue > 0);
564 s->msgs_in_queue--; 575 s->msgs_in_queue--;
565 GNUNET_assert(s->bytes_in_queue >= msg->size); 576 GNUNET_assert (s->bytes_in_queue >= msg->size);
566 s->bytes_in_queue -= msg->size; 577 s->bytes_in_queue -= msg->size;
567 GNUNET_free(msg); 578 GNUNET_free (msg);
568 } 579 }
569 580
570 GNUNET_assert(0 == s->msgs_in_queue); 581 GNUNET_assert (0 == s->msgs_in_queue);
571 GNUNET_assert(0 == s->bytes_in_queue); 582 GNUNET_assert (0 == s->bytes_in_queue);
572 583
573 if (NULL != s->server_send) 584 if (NULL != s->server_send)
574 { 585 {
575 LOG(GNUNET_ERROR_TYPE_DEBUG, 586 LOG (GNUNET_ERROR_TYPE_DEBUG,
576 "Server: %p / %p Terminating inbound PUT session to peer `%s'\n", 587 "Server: %p / %p Terminating inbound PUT session to peer `%s'\n",
577 s, s->server_send, 588 s, s->server_send,
578 GNUNET_i2s(&s->target)); 589 GNUNET_i2s (&s->target));
579 s->server_send->session = NULL; 590 s->server_send->session = NULL;
580 MHD_set_connection_option(s->server_send->mhd_conn, 591 MHD_set_connection_option (s->server_send->mhd_conn,
581 MHD_CONNECTION_OPTION_TIMEOUT, 592 MHD_CONNECTION_OPTION_TIMEOUT,
582 1 /* 0 = no timeout, so this is MIN */); 593 1 /* 0 = no timeout, so this is MIN */);
583 if (s->server_send->suspended) 594 if (s->server_send->suspended)
584 { 595 {
585 s->server_send->suspended = false; 596 s->server_send->suspended = false;
586 MHD_resume_connection(s->server_send->mhd_conn); 597 MHD_resume_connection (s->server_send->mhd_conn);
587 } 598 }
588 server_reschedule(plugin, 599 server_reschedule (plugin,
589 s->server_send->mhd_daemon, 600 s->server_send->mhd_daemon,
590 GNUNET_YES); 601 GNUNET_YES);
591 } 602 }
592 603
593 if (NULL != s->server_recv) 604 if (NULL != s->server_recv)
594 { 605 {
595 LOG(GNUNET_ERROR_TYPE_DEBUG, 606 LOG (GNUNET_ERROR_TYPE_DEBUG,
596 "Server: %p / %p Terminating inbound GET session to peer `%s'\n", 607 "Server: %p / %p Terminating inbound GET session to peer `%s'\n",
597 s, s->server_recv, GNUNET_i2s(&s->target)); 608 s, s->server_recv, GNUNET_i2s (&s->target));
598 s->server_recv->session = NULL; 609 s->server_recv->session = NULL;
599 MHD_set_connection_option(s->server_recv->mhd_conn, 610 MHD_set_connection_option (s->server_recv->mhd_conn,
600 MHD_CONNECTION_OPTION_TIMEOUT, 611 MHD_CONNECTION_OPTION_TIMEOUT,
601 1 /* 0 = no timeout, so this is MIN */); 612 1 /* 0 = no timeout, so this is MIN */);
602 server_reschedule(plugin, 613 server_reschedule (plugin,
603 s->server_recv->mhd_daemon, 614 s->server_recv->mhd_daemon,
604 GNUNET_YES); 615 GNUNET_YES);
605 } 616 }
606 notify_session_monitor(plugin, 617 notify_session_monitor (plugin,
607 s, 618 s,
608 GNUNET_TRANSPORT_SS_DONE); 619 GNUNET_TRANSPORT_SS_DONE);
609 if (GNUNET_YES == s->known_to_service) 620 if (GNUNET_YES == s->known_to_service)
610 { 621 {
611 plugin->env->session_end(plugin->env->cls, 622 plugin->env->session_end (plugin->env->cls,
612 s->address, 623 s->address,
613 s); 624 s);
614 s->known_to_service = GNUNET_NO; 625 s->known_to_service = GNUNET_NO;
615 } 626 }
616 if (NULL != s->msg_tk) 627 if (NULL != s->msg_tk)
617 { 628 {
618 GNUNET_MST_destroy(s->msg_tk); 629 GNUNET_MST_destroy (s->msg_tk);
619 s->msg_tk = NULL; 630 s->msg_tk = NULL;
620 } 631 }
621 GNUNET_HELLO_address_free(s->address); 632 GNUNET_HELLO_address_free (s->address);
622 LOG(GNUNET_ERROR_TYPE_DEBUG, 633 LOG (GNUNET_ERROR_TYPE_DEBUG,
623 "Session %p destroyed\n", 634 "Session %p destroyed\n",
624 s); 635 s);
625 GNUNET_free(s); 636 GNUNET_free (s);
626} 637}
627 638
628 639
@@ -635,10 +646,10 @@ server_delete_session(struct GNUNET_ATS_Session *s)
635 * @return #GNUNET_OK on success 646 * @return #GNUNET_OK on success
636 */ 647 */
637static int 648static int
638http_server_plugin_disconnect_session(void *cls, 649http_server_plugin_disconnect_session (void *cls,
639 struct GNUNET_ATS_Session *s) 650 struct GNUNET_ATS_Session *s)
640{ 651{
641 server_delete_session(s); 652 server_delete_session (s);
642 return GNUNET_OK; 653 return GNUNET_OK;
643} 654}
644 655
@@ -649,31 +660,32 @@ http_server_plugin_disconnect_session(void *cls,
649 * @param cls the session 660 * @param cls the session
650 */ 661 */
651static void 662static void
652server_session_timeout(void *cls) 663server_session_timeout (void *cls)
653{ 664{
654 struct GNUNET_ATS_Session *s = cls; 665 struct GNUNET_ATS_Session *s = cls;
655 struct GNUNET_TIME_Relative left; 666 struct GNUNET_TIME_Relative left;
656 667
657 s->timeout_task = NULL; 668 s->timeout_task = NULL;
658 left = GNUNET_TIME_absolute_get_remaining(s->timeout); 669 left = GNUNET_TIME_absolute_get_remaining (s->timeout);
659 if (0 != left.rel_value_us) 670 if (0 != left.rel_value_us)
660 { 671 {
661 /* not actually our turn yet, but let's at least update 672 /* not actually our turn yet, but let's at least update
662 the monitor, it may think we're about to die ... */ 673 the monitor, it may think we're about to die ... */
663 notify_session_monitor(s->plugin, 674 notify_session_monitor (s->plugin,
664 s, 675 s,
665 GNUNET_TRANSPORT_SS_UP); 676 GNUNET_TRANSPORT_SS_UP);
666 s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, 677 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
667 &server_session_timeout, 678 &server_session_timeout,
668 s); 679 s);
669 return; 680 return;
670 } 681 }
671 GNUNET_log(TIMEOUT_LOG, 682 GNUNET_log (TIMEOUT_LOG,
672 "Session %p was idle for %s, disconnecting\n", 683 "Session %p was idle for %s, disconnecting\n",
673 s, 684 s,
674 GNUNET_STRINGS_relative_time_to_string(HTTP_SERVER_SESSION_TIMEOUT, 685 GNUNET_STRINGS_relative_time_to_string (
675 GNUNET_YES)); 686 HTTP_SERVER_SESSION_TIMEOUT,
676 server_delete_session(s); 687 GNUNET_YES));
688 server_delete_session (s);
677} 689}
678 690
679 691
@@ -683,10 +695,11 @@ server_session_timeout(void *cls)
683 * @param s the session 695 * @param s the session
684 */ 696 */
685static void 697static void
686server_reschedule_session_timeout(struct GNUNET_ATS_Session *s) 698server_reschedule_session_timeout (struct GNUNET_ATS_Session *s)
687{ 699{
688 GNUNET_assert(NULL != s->timeout_task); 700 GNUNET_assert (NULL != s->timeout_task);
689 s->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 701 s->timeout = GNUNET_TIME_relative_to_absolute (
702 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
690} 703}
691 704
692 705
@@ -718,65 +731,65 @@ server_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
718 * and does NOT mean that the message was not transmitted (DV) 731 * and does NOT mean that the message was not transmitted (DV)
719 */ 732 */
720static ssize_t 733static ssize_t
721http_server_plugin_send(void *cls, 734http_server_plugin_send (void *cls,
722 struct GNUNET_ATS_Session *session, 735 struct GNUNET_ATS_Session *session,
723 const char *msgbuf, 736 const char *msgbuf,
724 size_t msgbuf_size, 737 size_t msgbuf_size,
725 unsigned int priority, 738 unsigned int priority,
726 struct GNUNET_TIME_Relative to, 739 struct GNUNET_TIME_Relative to,
727 GNUNET_TRANSPORT_TransmitContinuation cont, 740 GNUNET_TRANSPORT_TransmitContinuation cont,
728 void *cont_cls) 741 void *cont_cls)
729{ 742{
730 struct HTTP_Server_Plugin *plugin = cls; 743 struct HTTP_Server_Plugin *plugin = cls;
731 struct HTTP_Message *msg; 744 struct HTTP_Message *msg;
732 ssize_t bytes_sent = 0; 745 ssize_t bytes_sent = 0;
733 char *stat_txt; 746 char *stat_txt;
734 747
735 LOG(GNUNET_ERROR_TYPE_DEBUG, 748 LOG (GNUNET_ERROR_TYPE_DEBUG,
736 "Session %p/request %p: Sending message with %u to peer `%s'\n", 749 "Session %p/request %p: Sending message with %u to peer `%s'\n",
737 session, 750 session,
738 session->server_send, 751 session->server_send,
739 msgbuf_size, 752 msgbuf_size,
740 GNUNET_i2s(&session->target)); 753 GNUNET_i2s (&session->target));
741 754
742 /* create new message and schedule */ 755 /* create new message and schedule */
743 bytes_sent = sizeof(struct HTTP_Message) + msgbuf_size; 756 bytes_sent = sizeof(struct HTTP_Message) + msgbuf_size;
744 msg = GNUNET_malloc(bytes_sent); 757 msg = GNUNET_malloc (bytes_sent);
745 msg->next = NULL; 758 msg->next = NULL;
746 msg->size = msgbuf_size; 759 msg->size = msgbuf_size;
747 msg->pos = 0; 760 msg->pos = 0;
748 msg->buf = (char *)&msg[1]; 761 msg->buf = (char *) &msg[1];
749 msg->transmit_cont = cont; 762 msg->transmit_cont = cont;
750 msg->transmit_cont_cls = cont_cls; 763 msg->transmit_cont_cls = cont_cls;
751 GNUNET_memcpy(msg->buf, 764 GNUNET_memcpy (msg->buf,
752 msgbuf, 765 msgbuf,
753 msgbuf_size); 766 msgbuf_size);
754 GNUNET_CONTAINER_DLL_insert_tail(session->msg_head, 767 GNUNET_CONTAINER_DLL_insert_tail (session->msg_head,
755 session->msg_tail, 768 session->msg_tail,
756 msg); 769 msg);
757 session->msgs_in_queue++; 770 session->msgs_in_queue++;
758 session->bytes_in_queue += msg->size; 771 session->bytes_in_queue += msg->size;
759 notify_session_monitor(plugin, 772 notify_session_monitor (plugin,
760 session, 773 session,
761 GNUNET_TRANSPORT_SS_UP); 774 GNUNET_TRANSPORT_SS_UP);
762 GNUNET_asprintf(&stat_txt, 775 GNUNET_asprintf (&stat_txt,
763 "# bytes currently in %s_server buffers", 776 "# bytes currently in %s_server buffers",
764 plugin->protocol); 777 plugin->protocol);
765 GNUNET_STATISTICS_update(plugin->env->stats, 778 GNUNET_STATISTICS_update (plugin->env->stats,
766 stat_txt, msgbuf_size, GNUNET_NO); 779 stat_txt, msgbuf_size, GNUNET_NO);
767 GNUNET_free(stat_txt); 780 GNUNET_free (stat_txt);
768 781
769 if (NULL != session->server_send) 782 if (NULL != session->server_send)
783 {
784 if (session->server_send->suspended)
770 { 785 {
771 if (session->server_send->suspended) 786 MHD_resume_connection (session->server_send->mhd_conn);
772 { 787 session->server_send->suspended = false;
773 MHD_resume_connection(session->server_send->mhd_conn);
774 session->server_send->suspended = false;
775 }
776 server_reschedule(session->plugin,
777 session->server_send->mhd_daemon,
778 GNUNET_YES);
779 } 788 }
789 server_reschedule (session->plugin,
790 session->server_send->mhd_daemon,
791 GNUNET_YES);
792 }
780 return bytes_sent; 793 return bytes_sent;
781} 794}
782 795
@@ -790,9 +803,9 @@ http_server_plugin_send(void *cls,
790 * @return #GNUNET_OK (continue to iterate) 803 * @return #GNUNET_OK (continue to iterate)
791 */ 804 */
792static int 805static int
793destroy_session_shutdown_cb(void *cls, 806destroy_session_shutdown_cb (void *cls,
794 const struct GNUNET_PeerIdentity *peer, 807 const struct GNUNET_PeerIdentity *peer,
795 void *value) 808 void *value)
796{ 809{
797 struct GNUNET_ATS_Session *s = value; 810 struct GNUNET_ATS_Session *s = value;
798 struct ServerRequest *sc_send; 811 struct ServerRequest *sc_send;
@@ -800,7 +813,7 @@ destroy_session_shutdown_cb(void *cls,
800 813
801 sc_send = s->server_send; 814 sc_send = s->server_send;
802 sc_recv = s->server_recv; 815 sc_recv = s->server_recv;
803 server_delete_session(s); 816 server_delete_session (s);
804 if (NULL != sc_send) 817 if (NULL != sc_send)
805 sc_send->session = NULL; 818 sc_send->session = NULL;
806 if (NULL != sc_recv) 819 if (NULL != sc_recv)
@@ -819,13 +832,13 @@ destroy_session_shutdown_cb(void *cls,
819 * @return #GNUNET_OK (continue to iterate) 832 * @return #GNUNET_OK (continue to iterate)
820 */ 833 */
821static int 834static int
822destroy_session_cb(void *cls, 835destroy_session_cb (void *cls,
823 const struct GNUNET_PeerIdentity *peer, 836 const struct GNUNET_PeerIdentity *peer,
824 void *value) 837 void *value)
825{ 838{
826 struct GNUNET_ATS_Session *s = value; 839 struct GNUNET_ATS_Session *s = value;
827 840
828 server_delete_session(s); 841 server_delete_session (s);
829 return GNUNET_OK; 842 return GNUNET_OK;
830} 843}
831 844
@@ -839,18 +852,18 @@ destroy_session_cb(void *cls,
839 * @param target peer from which to disconnect 852 * @param target peer from which to disconnect
840 */ 853 */
841static void 854static void
842http_server_plugin_disconnect_peer(void *cls, 855http_server_plugin_disconnect_peer (void *cls,
843 const struct GNUNET_PeerIdentity *target) 856 const struct GNUNET_PeerIdentity *target)
844{ 857{
845 struct HTTP_Server_Plugin *plugin = cls; 858 struct HTTP_Server_Plugin *plugin = cls;
846 859
847 LOG(GNUNET_ERROR_TYPE_DEBUG, 860 LOG (GNUNET_ERROR_TYPE_DEBUG,
848 "Transport tells me to disconnect `%s'\n", 861 "Transport tells me to disconnect `%s'\n",
849 GNUNET_i2s(target)); 862 GNUNET_i2s (target));
850 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, 863 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions,
851 target, 864 target,
852 &destroy_session_cb, 865 &destroy_session_cb,
853 plugin); 866 plugin);
854} 867}
855 868
856 869
@@ -867,9 +880,9 @@ http_server_plugin_disconnect_peer(void *cls,
867 * and transport 880 * and transport
868 */ 881 */
869static int 882static int
870http_server_plugin_address_suggested(void *cls, 883http_server_plugin_address_suggested (void *cls,
871 const void *addr, 884 const void *addr,
872 size_t addrlen) 885 size_t addrlen)
873{ 886{
874 struct HTTP_Server_Plugin *plugin = cls; 887 struct HTTP_Server_Plugin *plugin = cls;
875 struct HttpAddressWrapper *next; 888 struct HttpAddressWrapper *next;
@@ -877,26 +890,27 @@ http_server_plugin_address_suggested(void *cls,
877 const struct HttpAddress *haddr = addr; 890 const struct HttpAddress *haddr = addr;
878 891
879 if ((NULL != plugin->ext_addr) && 892 if ((NULL != plugin->ext_addr) &&
880 GNUNET_YES == (http_common_cmp_addresses(addr, addrlen, 893 (GNUNET_YES == (http_common_cmp_addresses (addr, addrlen,
881 plugin->ext_addr->address, 894 plugin->ext_addr->address,
882 plugin->ext_addr->address_length))) 895 plugin->ext_addr->
883 { 896 address_length))) )
884 /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ 897 {
885 if ((ntohl(haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != 898 /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */
886 (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) 899 if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) !=
887 return GNUNET_NO; /* VERIFY option not set as required! */ 900 (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE))
888 return GNUNET_OK; 901 return GNUNET_NO; /* VERIFY option not set as required! */
889 } 902 return GNUNET_OK;
903 }
890 next = plugin->addr_head; 904 next = plugin->addr_head;
891 while (NULL != (pos = next)) 905 while (NULL != (pos = next))
892 { 906 {
893 next = pos->next; 907 next = pos->next;
894 if (GNUNET_YES == (http_common_cmp_addresses(addr, 908 if (GNUNET_YES == (http_common_cmp_addresses (addr,
895 addrlen, 909 addrlen,
896 pos->address, 910 pos->address,
897 pos->addrlen))) 911 pos->addrlen)))
898 return GNUNET_OK; 912 return GNUNET_OK;
899 } 913 }
900 return GNUNET_NO; 914 return GNUNET_NO;
901} 915}
902 916
@@ -912,8 +926,8 @@ http_server_plugin_address_suggested(void *cls,
912 * @return always NULL 926 * @return always NULL
913 */ 927 */
914static struct GNUNET_ATS_Session * 928static struct GNUNET_ATS_Session *
915http_server_plugin_get_session(void *cls, 929http_server_plugin_get_session (void *cls,
916 const struct GNUNET_HELLO_Address *address) 930 const struct GNUNET_HELLO_Address *address)
917{ 931{
918 return NULL; 932 return NULL;
919} 933}
@@ -926,14 +940,14 @@ http_server_plugin_get_session(void *cls,
926 * @param cls plugin as closure 940 * @param cls plugin as closure
927 */ 941 */
928static void 942static void
929server_v4_run(void *cls) 943server_v4_run (void *cls)
930{ 944{
931 struct HTTP_Server_Plugin *plugin = cls; 945 struct HTTP_Server_Plugin *plugin = cls;
932 946
933 plugin->server_v4_task = NULL; 947 plugin->server_v4_task = NULL;
934 plugin->server_v4_immediately = GNUNET_NO; 948 plugin->server_v4_immediately = GNUNET_NO;
935 GNUNET_assert(MHD_YES == MHD_run(plugin->server_v4)); 949 GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
936 server_reschedule(plugin, plugin->server_v4, GNUNET_NO); 950 server_reschedule (plugin, plugin->server_v4, GNUNET_NO);
937} 951}
938 952
939 953
@@ -944,14 +958,14 @@ server_v4_run(void *cls)
944 * @param cls plugin as closure 958 * @param cls plugin as closure
945 */ 959 */
946static void 960static void
947server_v6_run(void *cls) 961server_v6_run (void *cls)
948{ 962{
949 struct HTTP_Server_Plugin *plugin = cls; 963 struct HTTP_Server_Plugin *plugin = cls;
950 964
951 plugin->server_v6_task = NULL; 965 plugin->server_v6_task = NULL;
952 plugin->server_v6_immediately = GNUNET_NO; 966 plugin->server_v6_immediately = GNUNET_NO;
953 GNUNET_assert(MHD_YES == MHD_run(plugin->server_v6)); 967 GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
954 server_reschedule(plugin, plugin->server_v6, GNUNET_NO); 968 server_reschedule (plugin, plugin->server_v6, GNUNET_NO);
955} 969}
956 970
957 971
@@ -965,11 +979,11 @@ server_v6_run(void *cls)
965 * @return gnunet task identifier 979 * @return gnunet task identifier
966 */ 980 */
967static struct GNUNET_SCHEDULER_Task * 981static struct GNUNET_SCHEDULER_Task *
968server_schedule(struct HTTP_Server_Plugin *plugin, 982server_schedule (struct HTTP_Server_Plugin *plugin,
969 struct MHD_Daemon *daemon_handle, 983 struct MHD_Daemon *daemon_handle,
970 int now) 984 int now)
971{ 985{
972 struct GNUNET_SCHEDULER_Task * ret; 986 struct GNUNET_SCHEDULER_Task *ret;
973 fd_set rs; 987 fd_set rs;
974 fd_set ws; 988 fd_set ws;
975 fd_set es; 989 fd_set es;
@@ -985,76 +999,76 @@ server_schedule(struct HTTP_Server_Plugin *plugin,
985 return NULL; 999 return NULL;
986 1000
987 ret = NULL; 1001 ret = NULL;
988 FD_ZERO(&rs); 1002 FD_ZERO (&rs);
989 FD_ZERO(&ws); 1003 FD_ZERO (&ws);
990 FD_ZERO(&es); 1004 FD_ZERO (&es);
991 wrs = GNUNET_NETWORK_fdset_create(); 1005 wrs = GNUNET_NETWORK_fdset_create ();
992 wws = GNUNET_NETWORK_fdset_create(); 1006 wws = GNUNET_NETWORK_fdset_create ();
993 max = -1; 1007 max = -1;
994 GNUNET_assert(MHD_YES == 1008 GNUNET_assert (MHD_YES ==
995 MHD_get_fdset(daemon_handle, 1009 MHD_get_fdset (daemon_handle,
996 &rs, 1010 &rs,
997 &ws, 1011 &ws,
998 &es, 1012 &es,
999 &max)); 1013 &max));
1000 haveto = MHD_get_timeout(daemon_handle, &timeout); 1014 haveto = MHD_get_timeout (daemon_handle, &timeout);
1001 if (haveto == MHD_YES) 1015 if (haveto == MHD_YES)
1002 { 1016 {
1003 if (timeout != last_timeout) 1017 if (timeout != last_timeout)
1004 { 1018 {
1005 LOG(GNUNET_ERROR_TYPE_DEBUG, 1019 LOG (GNUNET_ERROR_TYPE_DEBUG,
1006 "SELECT Timeout changed from %llu to %llu (ms)\n", 1020 "SELECT Timeout changed from %llu to %llu (ms)\n",
1007 last_timeout, timeout); 1021 last_timeout, timeout);
1008 last_timeout = timeout; 1022 last_timeout = timeout;
1009 } 1023 }
1010 if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value_us / 1000LL) 1024 if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value_us / 1000LL)
1011 tv.rel_value_us = (uint64_t)timeout * 1000LL; 1025 tv.rel_value_us = (uint64_t) timeout * 1000LL;
1012 else 1026 else
1013 tv = GNUNET_TIME_UNIT_SECONDS; 1027 tv = GNUNET_TIME_UNIT_SECONDS;
1014 } 1028 }
1015 else 1029 else
1016 tv = GNUNET_TIME_UNIT_SECONDS; 1030 tv = GNUNET_TIME_UNIT_SECONDS;
1017 /* Force immediate run, since we have outbound data to send */ 1031 /* Force immediate run, since we have outbound data to send */
1018 if (now == GNUNET_YES) 1032 if (now == GNUNET_YES)
1019 tv = GNUNET_TIME_UNIT_MILLISECONDS; 1033 tv = GNUNET_TIME_UNIT_MILLISECONDS;
1020 GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); 1034 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
1021 GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); 1035 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
1022 1036
1023 if (daemon_handle == plugin->server_v4) 1037 if (daemon_handle == plugin->server_v4)
1038 {
1039 if (plugin->server_v4_task != NULL)
1024 { 1040 {
1025 if (plugin->server_v4_task != NULL) 1041 GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
1026 { 1042 plugin->server_v4_task = NULL;
1027 GNUNET_SCHEDULER_cancel(plugin->server_v4_task); 1043 }
1028 plugin->server_v4_task = NULL;
1029 }
1030#if 0 1044#if 0
1031 LOG(GNUNET_ERROR_TYPE_DEBUG, 1045 LOG (GNUNET_ERROR_TYPE_DEBUG,
1032 "Scheduling IPv4 server task in %llu ms\n", 1046 "Scheduling IPv4 server task in %llu ms\n",
1033 tv); 1047 tv);
1034#endif 1048#endif
1035 ret = 1049 ret =
1036 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1050 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1037 tv, wrs, wws, 1051 tv, wrs, wws,
1038 &server_v4_run, plugin); 1052 &server_v4_run, plugin);
1039 } 1053 }
1040 if (daemon_handle == plugin->server_v6) 1054 if (daemon_handle == plugin->server_v6)
1055 {
1056 if (plugin->server_v6_task != NULL)
1041 { 1057 {
1042 if (plugin->server_v6_task != NULL) 1058 GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
1043 { 1059 plugin->server_v6_task = NULL;
1044 GNUNET_SCHEDULER_cancel(plugin->server_v6_task); 1060 }
1045 plugin->server_v6_task = NULL;
1046 }
1047#if 0 1061#if 0
1048 LOG(GNUNET_ERROR_TYPE_DEBUG, 1062 LOG (GNUNET_ERROR_TYPE_DEBUG,
1049 "Scheduling IPv6 server task in %llu ms\n", tv); 1063 "Scheduling IPv6 server task in %llu ms\n", tv);
1050#endif 1064#endif
1051 ret = 1065 ret =
1052 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1066 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1053 tv, wrs, wws, 1067 tv, wrs, wws,
1054 &server_v6_run, plugin); 1068 &server_v6_run, plugin);
1055 } 1069 }
1056 GNUNET_NETWORK_fdset_destroy(wrs); 1070 GNUNET_NETWORK_fdset_destroy (wrs);
1057 GNUNET_NETWORK_fdset_destroy(wws); 1071 GNUNET_NETWORK_fdset_destroy (wws);
1058 return ret; 1072 return ret;
1059} 1073}
1060 1074
@@ -1068,41 +1082,41 @@ server_schedule(struct HTTP_Server_Plugin *plugin,
1068 * until timeout 1082 * until timeout
1069 */ 1083 */
1070static void 1084static void
1071server_reschedule(struct HTTP_Server_Plugin *plugin, 1085server_reschedule (struct HTTP_Server_Plugin *plugin,
1072 struct MHD_Daemon *server, 1086 struct MHD_Daemon *server,
1073 int now) 1087 int now)
1074{ 1088{
1075 if ((server == plugin->server_v4) && (plugin->server_v4 != NULL)) 1089 if ((server == plugin->server_v4) && (plugin->server_v4 != NULL))
1076 { 1090 {
1077 if (GNUNET_YES == plugin->server_v4_immediately) 1091 if (GNUNET_YES == plugin->server_v4_immediately)
1078 return; /* No rescheduling, server will run asap */ 1092 return; /* No rescheduling, server will run asap */
1079 1093
1080 if (GNUNET_YES == now) 1094 if (GNUNET_YES == now)
1081 plugin->server_v4_immediately = GNUNET_YES; 1095 plugin->server_v4_immediately = GNUNET_YES;
1082 1096
1083 if (plugin->server_v4_task != NULL) 1097 if (plugin->server_v4_task != NULL)
1084 { 1098 {
1085 GNUNET_SCHEDULER_cancel(plugin->server_v4_task); 1099 GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
1086 plugin->server_v4_task = NULL; 1100 plugin->server_v4_task = NULL;
1087 }
1088 plugin->server_v4_task = server_schedule(plugin, plugin->server_v4, now);
1089 } 1101 }
1102 plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now);
1103 }
1090 1104
1091 if ((server == plugin->server_v6) && (plugin->server_v6 != NULL)) 1105 if ((server == plugin->server_v6) && (plugin->server_v6 != NULL))
1092 { 1106 {
1093 if (GNUNET_YES == plugin->server_v6_immediately) 1107 if (GNUNET_YES == plugin->server_v6_immediately)
1094 return; /* No rescheduling, server will run asap */ 1108 return; /* No rescheduling, server will run asap */
1095 1109
1096 if (GNUNET_YES == now) 1110 if (GNUNET_YES == now)
1097 plugin->server_v6_immediately = GNUNET_YES; 1111 plugin->server_v6_immediately = GNUNET_YES;
1098 1112
1099 if (plugin->server_v6_task != NULL) 1113 if (plugin->server_v6_task != NULL)
1100 { 1114 {
1101 GNUNET_SCHEDULER_cancel(plugin->server_v6_task); 1115 GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
1102 plugin->server_v6_task = NULL; 1116 plugin->server_v6_task = NULL;
1103 }
1104 plugin->server_v6_task = server_schedule(plugin, plugin->server_v6, now);
1105 } 1117 }
1118 plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now);
1119 }
1106} 1120}
1107 1121
1108 1122
@@ -1115,7 +1129,7 @@ server_reschedule(struct HTTP_Server_Plugin *plugin,
1115 * @return keepalive factor 1129 * @return keepalive factor
1116 */ 1130 */
1117static unsigned int 1131static unsigned int
1118http_server_query_keepalive_factor(void *cls) 1132http_server_query_keepalive_factor (void *cls)
1119{ 1133{
1120 return 3; 1134 return 3;
1121} 1135}
@@ -1131,11 +1145,12 @@ http_server_query_keepalive_factor(void *cls)
1131 * @param session which session is being updated 1145 * @param session which session is being updated
1132 */ 1146 */
1133static void 1147static void
1134http_server_plugin_update_session_timeout(void *cls, 1148http_server_plugin_update_session_timeout (void *cls,
1135 const struct GNUNET_PeerIdentity *peer, 1149 const struct
1136 struct GNUNET_ATS_Session *session) 1150 GNUNET_PeerIdentity *peer,
1151 struct GNUNET_ATS_Session *session)
1137{ 1152{
1138 server_reschedule_session_timeout(session); 1153 server_reschedule_session_timeout (session);
1139} 1154}
1140 1155
1141 1156
@@ -1147,31 +1162,31 @@ http_server_plugin_update_session_timeout(void *cls,
1147 * @param to timeout in seconds 1162 * @param to timeout in seconds
1148 */ 1163 */
1149static void 1164static void
1150server_mhd_connection_timeout(struct HTTP_Server_Plugin *plugin, 1165server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin,
1151 struct GNUNET_ATS_Session *s, 1166 struct GNUNET_ATS_Session *s,
1152 unsigned int to) 1167 unsigned int to)
1153{ 1168{
1154 /* Setting timeouts for other connections */ 1169 /* Setting timeouts for other connections */
1155 if (NULL != s->server_recv) 1170 if (NULL != s->server_recv)
1156 { 1171 {
1157 LOG(GNUNET_ERROR_TYPE_DEBUG, 1172 LOG (GNUNET_ERROR_TYPE_DEBUG,
1158 "Setting timeout for %p to %u sec.\n", 1173 "Setting timeout for %p to %u sec.\n",
1159 s->server_recv, to); 1174 s->server_recv, to);
1160 MHD_set_connection_option(s->server_recv->mhd_conn, 1175 MHD_set_connection_option (s->server_recv->mhd_conn,
1161 MHD_CONNECTION_OPTION_TIMEOUT, 1176 MHD_CONNECTION_OPTION_TIMEOUT,
1162 to); 1177 to);
1163 server_reschedule(plugin, s->server_recv->mhd_daemon, GNUNET_NO); 1178 server_reschedule (plugin, s->server_recv->mhd_daemon, GNUNET_NO);
1164 } 1179 }
1165 if (NULL != s->server_send) 1180 if (NULL != s->server_send)
1166 { 1181 {
1167 LOG(GNUNET_ERROR_TYPE_DEBUG, 1182 LOG (GNUNET_ERROR_TYPE_DEBUG,
1168 "Setting timeout for %p to %u sec.\n", 1183 "Setting timeout for %p to %u sec.\n",
1169 s->server_send, to); 1184 s->server_send, to);
1170 MHD_set_connection_option(s->server_send->mhd_conn, 1185 MHD_set_connection_option (s->server_send->mhd_conn,
1171 MHD_CONNECTION_OPTION_TIMEOUT, 1186 MHD_CONNECTION_OPTION_TIMEOUT,
1172 to); 1187 to);
1173 server_reschedule(plugin, s->server_send->mhd_daemon, GNUNET_NO); 1188 server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO);
1174 } 1189 }
1175} 1190}
1176 1191
1177 1192
@@ -1186,11 +1201,11 @@ server_mhd_connection_timeout(struct HTTP_Server_Plugin *plugin,
1186 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1201 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1187 */ 1202 */
1188static int 1203static int
1189server_parse_url(struct HTTP_Server_Plugin *plugin, 1204server_parse_url (struct HTTP_Server_Plugin *plugin,
1190 const char *url, 1205 const char *url,
1191 struct GNUNET_PeerIdentity *target, 1206 struct GNUNET_PeerIdentity *target,
1192 uint32_t *tag, 1207 uint32_t *tag,
1193 uint32_t *options) 1208 uint32_t *options)
1194{ 1209{
1195 regmatch_t matches[4]; 1210 regmatch_t matches[4];
1196 const char *tag_start; 1211 const char *tag_start;
@@ -1205,105 +1220,105 @@ server_parse_url(struct HTTP_Server_Plugin *plugin,
1205 ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$") 1220 ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$")
1206 1221
1207 if (NULL == url) 1222 if (NULL == url)
1208 { 1223 {
1209 GNUNET_break(0); 1224 GNUNET_break (0);
1210 return GNUNET_SYSERR; 1225 return GNUNET_SYSERR;
1211 } 1226 }
1212 1227
1213 if (regexec(&plugin->url_regex, url, 4, matches, 0)) 1228 if (regexec (&plugin->url_regex, url, 4, matches, 0))
1214 { 1229 {
1215 LOG(GNUNET_ERROR_TYPE_DEBUG, 1230 LOG (GNUNET_ERROR_TYPE_DEBUG,
1216 "URL `%s' did not match regex\n", url); 1231 "URL `%s' did not match regex\n", url);
1217 return GNUNET_SYSERR; 1232 return GNUNET_SYSERR;
1218 } 1233 }
1219 1234
1220 target_start = &url[matches[1].rm_so]; 1235 target_start = &url[matches[1].rm_so];
1221 tag_start = &url[matches[2].rm_so]; 1236 tag_start = &url[matches[2].rm_so];
1222 1237
1223 /* convert tag */ 1238 /* convert tag */
1224 rc = strtoul(tag_start, &tag_end, 10); 1239 rc = strtoul (tag_start, &tag_end, 10);
1225 if (&url[matches[2].rm_eo] != tag_end) 1240 if (&url[matches[2].rm_eo] != tag_end)
1226 { 1241 {
1227 LOG(GNUNET_ERROR_TYPE_DEBUG, 1242 LOG (GNUNET_ERROR_TYPE_DEBUG,
1228 "URL tag did not line up with submatch\n"); 1243 "URL tag did not line up with submatch\n");
1229 return GNUNET_SYSERR; 1244 return GNUNET_SYSERR;
1230 } 1245 }
1231 if (rc == 0) 1246 if (rc == 0)
1232 { 1247 {
1233 LOG(GNUNET_ERROR_TYPE_DEBUG, 1248 LOG (GNUNET_ERROR_TYPE_DEBUG,
1234 "URL tag is zero\n"); 1249 "URL tag is zero\n");
1235 return GNUNET_SYSERR; 1250 return GNUNET_SYSERR;
1236 } 1251 }
1237 if ((rc == ULONG_MAX) && (ERANGE == errno)) 1252 if ((rc == ULONG_MAX) && (ERANGE == errno))
1238 { 1253 {
1239 LOG(GNUNET_ERROR_TYPE_DEBUG, 1254 LOG (GNUNET_ERROR_TYPE_DEBUG,
1240 "URL tag > ULONG_MAX\n"); 1255 "URL tag > ULONG_MAX\n");
1241 return GNUNET_SYSERR; 1256 return GNUNET_SYSERR;
1242 } 1257 }
1243 if (rc > UINT32_MAX) 1258 if (rc > UINT32_MAX)
1244 { 1259 {
1245 LOG(GNUNET_ERROR_TYPE_DEBUG, 1260 LOG (GNUNET_ERROR_TYPE_DEBUG,
1246 "URL tag > UINT32_MAX\n"); 1261 "URL tag > UINT32_MAX\n");
1247 return GNUNET_SYSERR; 1262 return GNUNET_SYSERR;
1248 } 1263 }
1249 (*tag) = (uint32_t)rc; 1264 (*tag) = (uint32_t) rc;
1250 LOG(GNUNET_ERROR_TYPE_DEBUG, 1265 LOG (GNUNET_ERROR_TYPE_DEBUG,
1251 "Found tag `%u' in url\n", 1266 "Found tag `%u' in url\n",
1252 *tag); 1267 *tag);
1253 1268
1254 /* convert peer id */ 1269 /* convert peer id */
1255 hash_length = matches[1].rm_eo - matches[1].rm_so; 1270 hash_length = matches[1].rm_eo - matches[1].rm_so;
1256 if (hash_length != plugin->peer_id_length) 1271 if (hash_length != plugin->peer_id_length)
1257 { 1272 {
1258 LOG(GNUNET_ERROR_TYPE_DEBUG, 1273 LOG (GNUNET_ERROR_TYPE_DEBUG,
1259 "URL target is %u bytes, expecting %u\n", 1274 "URL target is %u bytes, expecting %u\n",
1260 hash_length, plugin->peer_id_length); 1275 hash_length, plugin->peer_id_length);
1261 return GNUNET_SYSERR; 1276 return GNUNET_SYSERR;
1262 } 1277 }
1263 if (GNUNET_OK != 1278 if (GNUNET_OK !=
1264 GNUNET_CRYPTO_eddsa_public_key_from_string(target_start, 1279 GNUNET_CRYPTO_eddsa_public_key_from_string (target_start,
1265 hash_length, 1280 hash_length,
1266 &target->public_key)) 1281 &target->public_key))
1267 { 1282 {
1268 LOG(GNUNET_ERROR_TYPE_DEBUG, 1283 LOG (GNUNET_ERROR_TYPE_DEBUG,
1269 "URL target conversion failed\n"); 1284 "URL target conversion failed\n");
1270 return GNUNET_SYSERR; 1285 return GNUNET_SYSERR;
1271 } 1286 }
1272 LOG(GNUNET_ERROR_TYPE_DEBUG, 1287 LOG (GNUNET_ERROR_TYPE_DEBUG,
1273 "Found target `%s' in URL\n", 1288 "Found target `%s' in URL\n",
1274 GNUNET_i2s_full(target)); 1289 GNUNET_i2s_full (target));
1275 1290
1276 /* convert options */ 1291 /* convert options */
1277 if (-1 == matches[3].rm_so) 1292 if (-1 == matches[3].rm_so)
1293 {
1294 *options = 0;
1295 }
1296 else
1297 {
1298 rc = strtoul (&url[matches[3].rm_so + 1], &options_end, 10);
1299 if (&url[matches[3].rm_eo] != options_end)
1300 {
1301 LOG (GNUNET_ERROR_TYPE_DEBUG,
1302 "URL options did not line up with submatch\n");
1303 return GNUNET_SYSERR;
1304 }
1305 if ((rc == ULONG_MAX) && (ERANGE == errno))
1278 { 1306 {
1279 *options = 0; 1307 LOG (GNUNET_ERROR_TYPE_DEBUG,
1308 "URL options > ULONG_MAX\n");
1309 return GNUNET_SYSERR;
1280 } 1310 }
1281 else 1311 if (rc > UINT32_MAX)
1282 { 1312 {
1283 rc = strtoul(&url[matches[3].rm_so + 1], &options_end, 10); 1313 LOG (GNUNET_ERROR_TYPE_DEBUG,
1284 if (&url[matches[3].rm_eo] != options_end) 1314 "URL options > UINT32_MAX\n");
1285 { 1315 return GNUNET_SYSERR;
1286 LOG(GNUNET_ERROR_TYPE_DEBUG,
1287 "URL options did not line up with submatch\n");
1288 return GNUNET_SYSERR;
1289 }
1290 if ((rc == ULONG_MAX) && (ERANGE == errno))
1291 {
1292 LOG(GNUNET_ERROR_TYPE_DEBUG,
1293 "URL options > ULONG_MAX\n");
1294 return GNUNET_SYSERR;
1295 }
1296 if (rc > UINT32_MAX)
1297 {
1298 LOG(GNUNET_ERROR_TYPE_DEBUG,
1299 "URL options > UINT32_MAX\n");
1300 return GNUNET_SYSERR;
1301 }
1302 (*options) = (uint32_t)rc;
1303 LOG(GNUNET_ERROR_TYPE_DEBUG,
1304 "Found options `%u' in url\n",
1305 *options);
1306 } 1316 }
1317 (*options) = (uint32_t) rc;
1318 LOG (GNUNET_ERROR_TYPE_DEBUG,
1319 "Found options `%u' in url\n",
1320 *options);
1321 }
1307 return GNUNET_OK; 1322 return GNUNET_OK;
1308} 1323}
1309 1324
@@ -1311,7 +1326,8 @@ server_parse_url(struct HTTP_Server_Plugin *plugin,
1311/** 1326/**
1312 * Closure for #session_tag_it(). 1327 * Closure for #session_tag_it().
1313 */ 1328 */
1314struct GNUNET_ATS_SessionTagContext { 1329struct GNUNET_ATS_SessionTagContext
1330{
1315 /** 1331 /**
1316 * Set to session matching the tag. 1332 * Set to session matching the tag.
1317 */ 1333 */
@@ -1333,18 +1349,18 @@ struct GNUNET_ATS_SessionTagContext {
1333 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not 1349 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not
1334 */ 1350 */
1335static int 1351static int
1336session_tag_it(void *cls, 1352session_tag_it (void *cls,
1337 const struct GNUNET_PeerIdentity *key, 1353 const struct GNUNET_PeerIdentity *key,
1338 void *value) 1354 void *value)
1339{ 1355{
1340 struct GNUNET_ATS_SessionTagContext *stc = cls; 1356 struct GNUNET_ATS_SessionTagContext *stc = cls;
1341 struct GNUNET_ATS_Session *s = value; 1357 struct GNUNET_ATS_Session *s = value;
1342 1358
1343 if (s->tag == stc->tag) 1359 if (s->tag == stc->tag)
1344 { 1360 {
1345 stc->res = s; 1361 stc->res = s;
1346 return GNUNET_NO; 1362 return GNUNET_NO;
1347 } 1363 }
1348 return GNUNET_YES; 1364 return GNUNET_YES;
1349} 1365}
1350 1366
@@ -1359,10 +1375,10 @@ session_tag_it(void *cls,
1359 * @return the server connecetion 1375 * @return the server connecetion
1360 */ 1376 */
1361static struct ServerRequest * 1377static struct ServerRequest *
1362server_lookup_connection(struct HTTP_Server_Plugin *plugin, 1378server_lookup_connection (struct HTTP_Server_Plugin *plugin,
1363 struct MHD_Connection *mhd_connection, 1379 struct MHD_Connection *mhd_connection,
1364 const char *url, 1380 const char *url,
1365 const char *method) 1381 const char *method)
1366{ 1382{
1367 struct GNUNET_ATS_Session *s = NULL; 1383 struct GNUNET_ATS_Session *s = NULL;
1368 struct ServerRequest *sc = NULL; 1384 struct ServerRequest *sc = NULL;
@@ -1376,131 +1392,131 @@ server_lookup_connection(struct HTTP_Server_Plugin *plugin,
1376 unsigned int to; 1392 unsigned int to;
1377 enum GNUNET_NetworkType scope; 1393 enum GNUNET_NetworkType scope;
1378 1394
1379 conn_info = MHD_get_connection_info(mhd_connection, 1395 conn_info = MHD_get_connection_info (mhd_connection,
1380 MHD_CONNECTION_INFO_CLIENT_ADDRESS); 1396 MHD_CONNECTION_INFO_CLIENT_ADDRESS);
1381 if ((conn_info->client_addr->sa_family != AF_INET) && 1397 if ((conn_info->client_addr->sa_family != AF_INET) &&
1382 (conn_info->client_addr->sa_family != AF_INET6)) 1398 (conn_info->client_addr->sa_family != AF_INET6))
1383 return NULL; 1399 return NULL;
1384 LOG(GNUNET_ERROR_TYPE_DEBUG, 1400 LOG (GNUNET_ERROR_TYPE_DEBUG,
1385 "New %s request from %s\n", 1401 "New %s request from %s\n",
1386 method, 1402 method,
1387 url); 1403 url);
1388 stc.tag = 0; 1404 stc.tag = 0;
1389 options = 0; /* make gcc happy */ 1405 options = 0; /* make gcc happy */
1390 if (GNUNET_SYSERR == 1406 if (GNUNET_SYSERR ==
1391 server_parse_url(plugin, url, &target, &stc.tag, &options)) 1407 server_parse_url (plugin, url, &target, &stc.tag, &options))
1392 { 1408 {
1393 LOG(GNUNET_ERROR_TYPE_DEBUG, 1409 LOG (GNUNET_ERROR_TYPE_DEBUG,
1394 "Invalid url %s\n", url); 1410 "Invalid url %s\n", url);
1395 return NULL; 1411 return NULL;
1396 } 1412 }
1397 if (0 == strcmp(MHD_HTTP_METHOD_PUT, method)) 1413 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
1398 direction = _RECEIVE; 1414 direction = _RECEIVE;
1399 else if (0 == strcmp(MHD_HTTP_METHOD_GET, method)) 1415 else if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
1400 direction = _SEND; 1416 direction = _SEND;
1401 else 1417 else
1402 { 1418 {
1403 LOG(GNUNET_ERROR_TYPE_DEBUG, 1419 LOG (GNUNET_ERROR_TYPE_DEBUG,
1404 "Invalid method %s for request from %s\n", 1420 "Invalid method %s for request from %s\n",
1405 method, url); 1421 method, url);
1406 return NULL; 1422 return NULL;
1407 } 1423 }
1408 1424
1409 plugin->cur_request++; 1425 plugin->cur_request++;
1410 LOG(GNUNET_ERROR_TYPE_DEBUG, 1426 LOG (GNUNET_ERROR_TYPE_DEBUG,
1411 "New %s request from %s with tag %u (%u of %u)\n", 1427 "New %s request from %s with tag %u (%u of %u)\n",
1412 method, 1428 method,
1413 GNUNET_i2s(&target), 1429 GNUNET_i2s (&target),
1414 stc.tag, 1430 stc.tag,
1415 plugin->cur_request, plugin->max_request); 1431 plugin->cur_request, plugin->max_request);
1416 /* find existing session */ 1432 /* find existing session */
1417 stc.res = NULL; 1433 stc.res = NULL;
1418 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, 1434 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions,
1419 &target, 1435 &target,
1420 &session_tag_it, 1436 &session_tag_it,
1421 &stc); 1437 &stc);
1422 if (NULL == (s = stc.res)) 1438 if (NULL == (s = stc.res))
1423 { 1439 {
1424 /* create new session */ 1440 /* create new session */
1425 addr = NULL; 1441 addr = NULL;
1426 switch (conn_info->client_addr->sa_family) 1442 switch (conn_info->client_addr->sa_family)
1427 { 1443 {
1428 case (AF_INET): 1444 case (AF_INET):
1429 addr = http_common_address_from_socket(plugin->protocol, 1445 addr = http_common_address_from_socket (plugin->protocol,
1430 conn_info->client_addr, 1446 conn_info->client_addr,
1431 sizeof(struct sockaddr_in)); 1447 sizeof(struct sockaddr_in));
1432 addr_len = http_common_address_get_size(addr); 1448 addr_len = http_common_address_get_size (addr);
1433 scope = plugin->env->get_address_type(plugin->env->cls, 1449 scope = plugin->env->get_address_type (plugin->env->cls,
1434 conn_info->client_addr, 1450 conn_info->client_addr,
1435 sizeof(struct sockaddr_in)); 1451 sizeof(struct sockaddr_in));
1436 break; 1452 break;
1437 1453
1438 case (AF_INET6): 1454 case (AF_INET6):
1439 addr = http_common_address_from_socket(plugin->protocol, 1455 addr = http_common_address_from_socket (plugin->protocol,
1440 conn_info->client_addr, 1456 conn_info->client_addr,
1441 sizeof(struct sockaddr_in6)); 1457 sizeof(struct sockaddr_in6));
1442 addr_len = http_common_address_get_size(addr); 1458 addr_len = http_common_address_get_size (addr);
1443 scope = plugin->env->get_address_type(plugin->env->cls, 1459 scope = plugin->env->get_address_type (plugin->env->cls,
1444 conn_info->client_addr, 1460 conn_info->client_addr,
1445 sizeof(struct sockaddr_in6)); 1461 sizeof(struct sockaddr_in6));
1446 break; 1462 break;
1447 1463
1448 default: 1464 default:
1449 /* external host name */ 1465 /* external host name */
1450 return NULL; 1466 return NULL;
1451 } 1467 }
1452 s = GNUNET_new(struct GNUNET_ATS_Session); 1468 s = GNUNET_new (struct GNUNET_ATS_Session);
1453 s->target = target; 1469 s->target = target;
1454 s->plugin = plugin; 1470 s->plugin = plugin;
1455 s->scope = scope; 1471 s->scope = scope;
1456 s->address = GNUNET_HELLO_address_allocate(&s->target, 1472 s->address = GNUNET_HELLO_address_allocate (&s->target,
1457 PLUGIN_NAME, 1473 PLUGIN_NAME,
1458 addr, 1474 addr,
1459 addr_len, 1475 addr_len,
1460 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 1476 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
1461 s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; 1477 s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS;
1462 s->tag = stc.tag; 1478 s->tag = stc.tag;
1463 s->timeout = GNUNET_TIME_relative_to_absolute(HTTP_SERVER_SESSION_TIMEOUT); 1479 s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_SERVER_SESSION_TIMEOUT);
1464 s->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_SERVER_SESSION_TIMEOUT, 1480 s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_SERVER_SESSION_TIMEOUT,
1465 &server_session_timeout, 1481 &server_session_timeout,
1466 s); 1482 s);
1467 (void)GNUNET_CONTAINER_multipeermap_put(plugin->sessions, 1483 (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessions,
1468 &s->target, 1484 &s->target,
1469 s, 1485 s,
1470 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1486 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1471 notify_session_monitor(plugin, 1487 notify_session_monitor (plugin,
1472 s, 1488 s,
1473 GNUNET_TRANSPORT_SS_INIT); 1489 GNUNET_TRANSPORT_SS_INIT);
1474 notify_session_monitor(plugin, 1490 notify_session_monitor (plugin,
1475 s, 1491 s,
1476 GNUNET_TRANSPORT_SS_HANDSHAKE); 1492 GNUNET_TRANSPORT_SS_HANDSHAKE);
1477 LOG(GNUNET_ERROR_TYPE_DEBUG, 1493 LOG (GNUNET_ERROR_TYPE_DEBUG,
1478 "Creating new session %p for peer `%s' connecting from `%s'\n", 1494 "Creating new session %p for peer `%s' connecting from `%s'\n",
1479 s, GNUNET_i2s(&target), 1495 s, GNUNET_i2s (&target),
1480 http_common_plugin_address_to_string(plugin->protocol, 1496 http_common_plugin_address_to_string (plugin->protocol,
1481 addr, 1497 addr,
1482 addr_len)); 1498 addr_len));
1483 GNUNET_free_non_null(addr); 1499 GNUNET_free_non_null (addr);
1484 } 1500 }
1485 1501
1486 if ((_RECEIVE == direction) && 1502 if ((_RECEIVE == direction) &&
1487 (NULL != s->server_recv)) 1503 (NULL != s->server_recv))
1488 { 1504 {
1489 LOG(GNUNET_ERROR_TYPE_DEBUG, 1505 LOG (GNUNET_ERROR_TYPE_DEBUG,
1490 "Duplicate PUT request from `%s' tag %u, dismissing new request\n", 1506 "Duplicate PUT request from `%s' tag %u, dismissing new request\n",
1491 GNUNET_i2s(&target), 1507 GNUNET_i2s (&target),
1492 stc.tag); 1508 stc.tag);
1493 return NULL; 1509 return NULL;
1494 } 1510 }
1495 if ((_SEND == direction) && (NULL != s->server_send)) 1511 if ((_SEND == direction) && (NULL != s->server_send))
1496 { 1512 {
1497 LOG(GNUNET_ERROR_TYPE_DEBUG, 1513 LOG (GNUNET_ERROR_TYPE_DEBUG,
1498 "Duplicate GET request from `%s' tag %u, dismissing new request\n", 1514 "Duplicate GET request from `%s' tag %u, dismissing new request\n",
1499 GNUNET_i2s(&target), 1515 GNUNET_i2s (&target),
1500 stc.tag); 1516 stc.tag);
1501 return NULL; 1517 return NULL;
1502 } 1518 }
1503 sc = GNUNET_new(struct ServerRequest); 1519 sc = GNUNET_new (struct ServerRequest);
1504 if (conn_info->client_addr->sa_family == AF_INET) 1520 if (conn_info->client_addr->sa_family == AF_INET)
1505 sc->mhd_daemon = plugin->server_v4; 1521 sc->mhd_daemon = plugin->server_v4;
1506 if (conn_info->client_addr->sa_family == AF_INET6) 1522 if (conn_info->client_addr->sa_family == AF_INET6)
@@ -1511,30 +1527,30 @@ server_lookup_connection(struct HTTP_Server_Plugin *plugin,
1511 sc->session = s; 1527 sc->session = s;
1512 sc->options = options; 1528 sc->options = options;
1513 if (direction == _SEND) 1529 if (direction == _SEND)
1514 { 1530 {
1515 s->server_send = sc; 1531 s->server_send = sc;
1516 } 1532 }
1517 if (direction == _RECEIVE) 1533 if (direction == _RECEIVE)
1518 { 1534 {
1519 s->server_recv = sc; 1535 s->server_recv = sc;
1520 } 1536 }
1521 1537
1522 if ((GNUNET_NO == s->known_to_service) && 1538 if ((GNUNET_NO == s->known_to_service) &&
1523 (NULL != s->server_send) && 1539 (NULL != s->server_send) &&
1524 (NULL != s->server_recv)) 1540 (NULL != s->server_recv))
1525 { 1541 {
1526 s->known_to_service = GNUNET_YES; 1542 s->known_to_service = GNUNET_YES;
1527 notify_session_monitor(plugin, 1543 notify_session_monitor (plugin,
1528 s, 1544 s,
1529 GNUNET_TRANSPORT_SS_UP); 1545 GNUNET_TRANSPORT_SS_UP);
1530 plugin->env->session_start(plugin->env->cls, 1546 plugin->env->session_start (plugin->env->cls,
1531 s->address, 1547 s->address,
1532 s, 1548 s,
1533 s->scope); 1549 s->scope);
1534 } 1550 }
1535 1551
1536 to = (HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL); 1552 to = (HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL);
1537 server_mhd_connection_timeout(plugin, s, to); 1553 server_mhd_connection_timeout (plugin, s, to);
1538 return sc; 1554 return sc;
1539} 1555}
1540 1556
@@ -1549,10 +1565,10 @@ server_lookup_connection(struct HTTP_Server_Plugin *plugin,
1549 * @return bytes written to @a buf 1565 * @return bytes written to @a buf
1550 */ 1566 */
1551static ssize_t 1567static ssize_t
1552server_send_callback(void *cls, 1568server_send_callback (void *cls,
1553 uint64_t pos, 1569 uint64_t pos,
1554 char *buf, 1570 char *buf,
1555 size_t max) 1571 size_t max)
1556{ 1572{
1557 struct ServerRequest *sc = cls; 1573 struct ServerRequest *sc = cls;
1558 struct GNUNET_ATS_Session *s = sc->session; 1574 struct GNUNET_ATS_Session *s = sc->session;
@@ -1561,79 +1577,79 @@ server_send_callback(void *cls,
1561 char *stat_txt; 1577 char *stat_txt;
1562 1578
1563 if (NULL == s) 1579 if (NULL == s)
1564 { 1580 {
1565 /* session is disconnecting */ 1581 /* session is disconnecting */
1566 return 0; 1582 return 0;
1567 } 1583 }
1568 1584
1569 sc = s->server_send; 1585 sc = s->server_send;
1570 if (NULL == sc) 1586 if (NULL == sc)
1571 return 0; 1587 return 0;
1572 msg = s->msg_head; 1588 msg = s->msg_head;
1573 if (NULL != msg) 1589 if (NULL != msg)
1574 { 1590 {
1575 /* sending */ 1591 /* sending */
1576 bytes_read = GNUNET_MIN(msg->size - msg->pos, 1592 bytes_read = GNUNET_MIN (msg->size - msg->pos,
1577 max); 1593 max);
1578 GNUNET_memcpy(buf, &msg->buf[msg->pos], bytes_read); 1594 GNUNET_memcpy (buf, &msg->buf[msg->pos], bytes_read);
1579 msg->pos += bytes_read; 1595 msg->pos += bytes_read;
1580 1596
1581 /* removing message */ 1597 /* removing message */
1582 if (msg->pos == msg->size) 1598 if (msg->pos == msg->size)
1583 { 1599 {
1584 GNUNET_CONTAINER_DLL_remove(s->msg_head, 1600 GNUNET_CONTAINER_DLL_remove (s->msg_head,
1585 s->msg_tail, 1601 s->msg_tail,
1586 msg); 1602 msg);
1587 if (NULL != msg->transmit_cont) 1603 if (NULL != msg->transmit_cont)
1588 msg->transmit_cont(msg->transmit_cont_cls, &s->target, GNUNET_OK, 1604 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK,
1589 msg->size, msg->size + msg->overhead); 1605 msg->size, msg->size + msg->overhead);
1590 GNUNET_assert(s->msgs_in_queue > 0); 1606 GNUNET_assert (s->msgs_in_queue > 0);
1591 s->msgs_in_queue--; 1607 s->msgs_in_queue--;
1592 GNUNET_assert(s->bytes_in_queue >= msg->size); 1608 GNUNET_assert (s->bytes_in_queue >= msg->size);
1593 s->bytes_in_queue -= msg->size; 1609 s->bytes_in_queue -= msg->size;
1594 GNUNET_free(msg); 1610 GNUNET_free (msg);
1595 notify_session_monitor(s->plugin, 1611 notify_session_monitor (s->plugin,
1596 s, 1612 s,
1597 GNUNET_TRANSPORT_SS_UPDATE); 1613 GNUNET_TRANSPORT_SS_UPDATE);
1598 }
1599 } 1614 }
1615 }
1600 if (0 < bytes_read) 1616 if (0 < bytes_read)
1601 { 1617 {
1602 sc->connected = GNUNET_YES; 1618 sc->connected = GNUNET_YES;
1603 LOG(GNUNET_ERROR_TYPE_DEBUG, 1619 LOG (GNUNET_ERROR_TYPE_DEBUG,
1604 "Sent %u bytes to peer `%s' with session %p \n", 1620 "Sent %u bytes to peer `%s' with session %p \n",
1605 bytes_read, 1621 bytes_read,
1606 GNUNET_i2s(&s->target), 1622 GNUNET_i2s (&s->target),
1607 s); 1623 s);
1608 GNUNET_asprintf(&stat_txt, 1624 GNUNET_asprintf (&stat_txt,
1609 "# bytes currently in %s_server buffers", 1625 "# bytes currently in %s_server buffers",
1610 s->plugin->protocol); 1626 s->plugin->protocol);
1611 GNUNET_STATISTICS_update(s->plugin->env->stats, 1627 GNUNET_STATISTICS_update (s->plugin->env->stats,
1612 stat_txt, 1628 stat_txt,
1613 -bytes_read, 1629 -bytes_read,
1614 GNUNET_NO); 1630 GNUNET_NO);
1615 GNUNET_free(stat_txt); 1631 GNUNET_free (stat_txt);
1616 GNUNET_asprintf(&stat_txt, 1632 GNUNET_asprintf (&stat_txt,
1617 "# bytes transmitted via %s_server", 1633 "# bytes transmitted via %s_server",
1618 s->plugin->protocol); 1634 s->plugin->protocol);
1619 GNUNET_STATISTICS_update(s->plugin->env->stats, 1635 GNUNET_STATISTICS_update (s->plugin->env->stats,
1620 stat_txt, bytes_read, GNUNET_NO); 1636 stat_txt, bytes_read, GNUNET_NO);
1621 GNUNET_free(stat_txt); 1637 GNUNET_free (stat_txt);
1622 } 1638 }
1623 else if ((sc->options & OPTION_LONG_POLL) && sc->connected) 1639 else if ((sc->options & OPTION_LONG_POLL) && sc->connected)
1624 { 1640 {
1625 LOG(GNUNET_ERROR_TYPE_DEBUG, 1641 LOG (GNUNET_ERROR_TYPE_DEBUG,
1626 "Completing GET response to peer `%s' with session %p\n", 1642 "Completing GET response to peer `%s' with session %p\n",
1627 GNUNET_i2s(&s->target), 1643 GNUNET_i2s (&s->target),
1628 s); 1644 s);
1629 return MHD_CONTENT_READER_END_OF_STREAM; 1645 return MHD_CONTENT_READER_END_OF_STREAM;
1630 } 1646 }
1631 else 1647 else
1632 { 1648 {
1633 MHD_suspend_connection(s->server_send->mhd_conn); 1649 MHD_suspend_connection (s->server_send->mhd_conn);
1634 s->server_send->suspended = true; 1650 s->server_send->suspended = true;
1635 return 0; 1651 return 0;
1636 } 1652 }
1637 return bytes_read; 1653 return bytes_read;
1638} 1654}
1639 1655
@@ -1646,8 +1662,8 @@ server_send_callback(void *cls,
1646 * @return #GNUNET_OK (all OK) 1662 * @return #GNUNET_OK (all OK)
1647 */ 1663 */
1648static int 1664static int
1649server_receive_mst_cb(void *cls, 1665server_receive_mst_cb (void *cls,
1650 const struct GNUNET_MessageHeader *message) 1666 const struct GNUNET_MessageHeader *message)
1651{ 1667{
1652 struct GNUNET_ATS_Session *s = cls; 1668 struct GNUNET_ATS_Session *s = cls;
1653 struct HTTP_Server_Plugin *plugin = s->plugin; 1669 struct HTTP_Server_Plugin *plugin = s->plugin;
@@ -1655,41 +1671,41 @@ server_receive_mst_cb(void *cls,
1655 char *stat_txt; 1671 char *stat_txt;
1656 1672
1657 if (GNUNET_NO == s->known_to_service) 1673 if (GNUNET_NO == s->known_to_service)
1658 { 1674 {
1659 s->known_to_service = GNUNET_YES; 1675 s->known_to_service = GNUNET_YES;
1660 plugin->env->session_start(plugin->env->cls, 1676 plugin->env->session_start (plugin->env->cls,
1661 s->address, 1677 s->address,
1662 s, 1678 s,
1663 s->scope); 1679 s->scope);
1664 notify_session_monitor(plugin, 1680 notify_session_monitor (plugin,
1665 s, 1681 s,
1666 GNUNET_TRANSPORT_SS_UP); 1682 GNUNET_TRANSPORT_SS_UP);
1667 } 1683 }
1668 delay = plugin->env->receive(plugin->env->cls, 1684 delay = plugin->env->receive (plugin->env->cls,
1669 s->address, 1685 s->address,
1670 s, 1686 s,
1671 message); 1687 message);
1672 GNUNET_asprintf(&stat_txt, 1688 GNUNET_asprintf (&stat_txt,
1673 "# bytes received via %s_server", 1689 "# bytes received via %s_server",
1674 plugin->protocol); 1690 plugin->protocol);
1675 GNUNET_STATISTICS_update(plugin->env->stats, 1691 GNUNET_STATISTICS_update (plugin->env->stats,
1676 stat_txt, 1692 stat_txt,
1677 ntohs(message->size), 1693 ntohs (message->size),
1678 GNUNET_NO); 1694 GNUNET_NO);
1679 GNUNET_free(stat_txt); 1695 GNUNET_free (stat_txt);
1680 s->next_receive = GNUNET_TIME_relative_to_absolute(delay); 1696 s->next_receive = GNUNET_TIME_relative_to_absolute (delay);
1681 if (delay.rel_value_us > 0) 1697 if (delay.rel_value_us > 0)
1682 { 1698 {
1683 LOG(GNUNET_ERROR_TYPE_DEBUG, 1699 LOG (GNUNET_ERROR_TYPE_DEBUG,
1684 "Peer `%s' address `%s' next read delayed for %s\n", 1700 "Peer `%s' address `%s' next read delayed for %s\n",
1685 GNUNET_i2s(&s->target), 1701 GNUNET_i2s (&s->target),
1686 http_common_plugin_address_to_string(plugin->protocol, 1702 http_common_plugin_address_to_string (plugin->protocol,
1687 s->address->address, 1703 s->address->address,
1688 s->address->address_length), 1704 s->address->address_length),
1689 GNUNET_STRINGS_relative_time_to_string(delay, 1705 GNUNET_STRINGS_relative_time_to_string (delay,
1690 GNUNET_YES)); 1706 GNUNET_YES));
1691 } 1707 }
1692 server_reschedule_session_timeout(s); 1708 server_reschedule_session_timeout (s);
1693 return GNUNET_OK; 1709 return GNUNET_OK;
1694} 1710}
1695 1711
@@ -1701,17 +1717,17 @@ server_receive_mst_cb(void *cls,
1701 * @param response response object to modify 1717 * @param response response object to modify
1702 */ 1718 */
1703static void 1719static void
1704add_cors_headers(struct MHD_Response *response) 1720add_cors_headers (struct MHD_Response *response)
1705{ 1721{
1706 MHD_add_response_header(response, 1722 MHD_add_response_header (response,
1707 "Access-Control-Allow-Origin", 1723 "Access-Control-Allow-Origin",
1708 "*"); 1724 "*");
1709 MHD_add_response_header(response, 1725 MHD_add_response_header (response,
1710 "Access-Control-Allow-Methods", 1726 "Access-Control-Allow-Methods",
1711 "GET, PUT, OPTIONS"); 1727 "GET, PUT, OPTIONS");
1712 MHD_add_response_header(response, 1728 MHD_add_response_header (response,
1713 "Access-Control-Max-Age", 1729 "Access-Control-Max-Age",
1714 "86400"); 1730 "86400");
1715} 1731}
1716 1732
1717 1733
@@ -1729,14 +1745,14 @@ add_cors_headers(struct MHD_Response *response)
1729 * @return MHD_YES if connection is accepted, MHD_NO on reject 1745 * @return MHD_YES if connection is accepted, MHD_NO on reject
1730 */ 1746 */
1731static int 1747static int
1732server_access_cb(void *cls, 1748server_access_cb (void *cls,
1733 struct MHD_Connection *mhd_connection, 1749 struct MHD_Connection *mhd_connection,
1734 const char *url, 1750 const char *url,
1735 const char *method, 1751 const char *method,
1736 const char *version, 1752 const char *version,
1737 const char *upload_data, 1753 const char *upload_data,
1738 size_t *upload_data_size, 1754 size_t *upload_data_size,
1739 void **httpSessionCache) 1755 void **httpSessionCache)
1740{ 1756{
1741 struct HTTP_Server_Plugin *plugin = cls; 1757 struct HTTP_Server_Plugin *plugin = cls;
1742 struct ServerRequest *sc = *httpSessionCache; 1758 struct ServerRequest *sc = *httpSessionCache;
@@ -1744,166 +1760,169 @@ server_access_cb(void *cls,
1744 struct MHD_Response *response; 1760 struct MHD_Response *response;
1745 int res = MHD_YES; 1761 int res = MHD_YES;
1746 1762
1747 LOG(GNUNET_ERROR_TYPE_DEBUG, 1763 LOG (GNUNET_ERROR_TYPE_DEBUG,
1748 _("Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"), 1764 _ (
1749 sc, 1765 "Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"),
1750 plugin->cur_request, 1766 sc,
1751 plugin->max_request, 1767 plugin->cur_request,
1752 method, 1768 plugin->max_request,
1753 version, 1769 method,
1754 url, 1770 version,
1755 (*upload_data_size)); 1771 url,
1772 (*upload_data_size));
1756 if (NULL == sc) 1773 if (NULL == sc)
1757 { 1774 {
1758 /* CORS pre-flight request */ 1775 /* CORS pre-flight request */
1759 if (0 == strcmp(MHD_HTTP_METHOD_OPTIONS, method)) 1776 if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method))
1760 { 1777 {
1761 response = MHD_create_response_from_buffer(0, NULL, 1778 response = MHD_create_response_from_buffer (0, NULL,
1762 MHD_RESPMEM_PERSISTENT); 1779 MHD_RESPMEM_PERSISTENT);
1763 add_cors_headers(response); 1780 add_cors_headers (response);
1764 res = MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); 1781 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1765 MHD_destroy_response(response); 1782 MHD_destroy_response (response);
1766 return res; 1783 return res;
1767 } 1784 }
1768 /* new connection */ 1785 /* new connection */
1769 sc = server_lookup_connection(plugin, mhd_connection, url, method); 1786 sc = server_lookup_connection (plugin, mhd_connection, url, method);
1770 if (NULL != sc) 1787 if (NULL != sc)
1771 { 1788 {
1772 /* attach to new / existing session */ 1789 /* attach to new / existing session */
1773 (*httpSessionCache) = sc; 1790 (*httpSessionCache) = sc;
1774 } 1791 }
1775 else 1792 else
1776 { 1793 {
1777 /* existing session already has matching connection, refuse */ 1794 /* existing session already has matching connection, refuse */
1778 response = MHD_create_response_from_buffer(strlen(HTTP_ERROR_RESPONSE), 1795 response = MHD_create_response_from_buffer (strlen (HTTP_ERROR_RESPONSE),
1779 HTTP_ERROR_RESPONSE, 1796 HTTP_ERROR_RESPONSE,
1780 MHD_RESPMEM_PERSISTENT); 1797 MHD_RESPMEM_PERSISTENT);
1781 MHD_add_response_header(response, 1798 MHD_add_response_header (response,
1782 MHD_HTTP_HEADER_CONTENT_TYPE, 1799 MHD_HTTP_HEADER_CONTENT_TYPE,
1783 "text/html"); 1800 "text/html");
1784 add_cors_headers(response); 1801 add_cors_headers (response);
1785 res = MHD_queue_response(mhd_connection, MHD_HTTP_NOT_FOUND, response); 1802 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
1786 MHD_destroy_response(response); 1803 MHD_destroy_response (response);
1787 return res; 1804 return res;
1788 } 1805 }
1789 } 1806 }
1790 /* 'old' connection */ 1807 /* 'old' connection */
1791 if (NULL == (s = sc->session)) 1808 if (NULL == (s = sc->session))
1792 { 1809 {
1793 /* Session was already disconnected; 1810 /* Session was already disconnected;
1794 sent HTTP/1.1: 200 OK as response */ 1811 sent HTTP/1.1: 200 OK as response */
1795 response = MHD_create_response_from_buffer(strlen("Thank you!"), 1812 response = MHD_create_response_from_buffer (strlen ("Thank you!"),
1796 "Thank you!", 1813 "Thank you!",
1797 MHD_RESPMEM_PERSISTENT); 1814 MHD_RESPMEM_PERSISTENT);
1798 add_cors_headers(response); 1815 add_cors_headers (response);
1799 MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); 1816 MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1800 MHD_destroy_response(response); 1817 MHD_destroy_response (response);
1801 return MHD_YES; 1818 return MHD_YES;
1802 } 1819 }
1803 1820
1804 if (sc->direction == _SEND) 1821 if (sc->direction == _SEND)
1805 { 1822 {
1806 response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 32 * 1024, 1823 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 32 * 1024,
1807 &server_send_callback, sc, NULL); 1824 &server_send_callback, sc,
1808 add_cors_headers(response); 1825 NULL);
1809 MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); 1826 add_cors_headers (response);
1810 MHD_destroy_response(response); 1827 MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1828 MHD_destroy_response (response);
1829 return MHD_YES;
1830 }
1831 if (sc->direction == _RECEIVE)
1832 {
1833 if ((*upload_data_size == 0) && (sc->connected == GNUNET_NO))
1834 {
1835 /* (*upload_data_size == 0) first callback when header are passed */
1836 LOG (GNUNET_ERROR_TYPE_DEBUG,
1837 "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n",
1838 s, sc,
1839 GNUNET_i2s (&s->target),
1840 http_common_plugin_address_to_string (plugin->protocol,
1841 s->address->address,
1842 s->address->address_length));
1843 sc->connected = GNUNET_YES;
1811 return MHD_YES; 1844 return MHD_YES;
1812 } 1845 }
1813 if (sc->direction == _RECEIVE) 1846 else if ((*upload_data_size == 0) && (sc->connected == GNUNET_YES))
1814 { 1847 {
1815 if ((*upload_data_size == 0) && (sc->connected == GNUNET_NO)) 1848 /* (*upload_data_size == 0) when upload is complete */
1816 { 1849 LOG (GNUNET_ERROR_TYPE_DEBUG,
1817 /* (*upload_data_size == 0) first callback when header are passed */ 1850 "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n",
1818 LOG(GNUNET_ERROR_TYPE_DEBUG, 1851 s, sc,
1819 "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n", 1852 GNUNET_i2s (&s->target),
1820 s, sc, 1853 http_common_plugin_address_to_string (plugin->protocol,
1821 GNUNET_i2s(&s->target), 1854 s->address->address,
1822 http_common_plugin_address_to_string(plugin->protocol, 1855 s->address->address_length));
1823 s->address->address, 1856 sc->connected = GNUNET_NO;
1824 s->address->address_length)); 1857 /* Sent HTTP/1.1: 200 OK as PUT Response\ */
1825 sc->connected = GNUNET_YES; 1858 response = MHD_create_response_from_buffer (strlen ("Thank you!"),
1826 return MHD_YES; 1859 "Thank you!",
1827 } 1860 MHD_RESPMEM_PERSISTENT);
1828 else if ((*upload_data_size == 0) && (sc->connected == GNUNET_YES)) 1861 add_cors_headers (response);
1829 { 1862 MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1830 /* (*upload_data_size == 0) when upload is complete */ 1863 MHD_destroy_response (response);
1831 LOG(GNUNET_ERROR_TYPE_DEBUG, 1864 return MHD_YES;
1832 "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n", 1865 }
1833 s, sc, 1866 else if ((*upload_data_size > 0) && (sc->connected == GNUNET_YES))
1834 GNUNET_i2s(&s->target), 1867 {
1835 http_common_plugin_address_to_string(plugin->protocol, 1868 struct GNUNET_TIME_Relative delay;
1836 s->address->address, 1869
1837 s->address->address_length)); 1870 /* (*upload_data_size > 0) for every segment received */
1838 sc->connected = GNUNET_NO; 1871 LOG (GNUNET_ERROR_TYPE_DEBUG,
1839 /* Sent HTTP/1.1: 200 OK as PUT Response\ */ 1872 "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n",
1840 response = MHD_create_response_from_buffer(strlen("Thank you!"), 1873 s, sc,
1841 "Thank you!", 1874 GNUNET_i2s (&s->target),
1842 MHD_RESPMEM_PERSISTENT); 1875 http_common_plugin_address_to_string (plugin->protocol,
1843 add_cors_headers(response); 1876 s->address->address,
1844 MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); 1877 s->address->address_length),
1845 MHD_destroy_response(response); 1878 *upload_data_size);
1846 return MHD_YES; 1879 delay = GNUNET_TIME_absolute_get_remaining (s->next_receive);
1847 } 1880 if (0 == delay.rel_value_us)
1848 else if ((*upload_data_size > 0) && (sc->connected == GNUNET_YES)) 1881 {
1882 LOG (GNUNET_ERROR_TYPE_DEBUG,
1883 "PUT with %u bytes forwarded to MST\n",
1884 *upload_data_size);
1885 if (s->msg_tk == NULL)
1849 { 1886 {
1850 struct GNUNET_TIME_Relative delay; 1887 s->msg_tk = GNUNET_MST_create (&server_receive_mst_cb,
1851 1888 s);
1852 /* (*upload_data_size > 0) for every segment received */
1853 LOG(GNUNET_ERROR_TYPE_DEBUG,
1854 "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n",
1855 s, sc,
1856 GNUNET_i2s(&s->target),
1857 http_common_plugin_address_to_string(plugin->protocol,
1858 s->address->address,
1859 s->address->address_length),
1860 *upload_data_size);
1861 delay = GNUNET_TIME_absolute_get_remaining(s->next_receive);
1862 if (0 == delay.rel_value_us)
1863 {
1864 LOG(GNUNET_ERROR_TYPE_DEBUG,
1865 "PUT with %u bytes forwarded to MST\n",
1866 *upload_data_size);
1867 if (s->msg_tk == NULL)
1868 {
1869 s->msg_tk = GNUNET_MST_create(&server_receive_mst_cb,
1870 s);
1871 }
1872 GNUNET_MST_from_buffer(s->msg_tk,
1873 upload_data,
1874 *upload_data_size,
1875 GNUNET_NO, GNUNET_NO);
1876 server_mhd_connection_timeout(plugin, s,
1877 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us / 1000LL
1878 / 1000LL);
1879 (*upload_data_size) = 0;
1880 }
1881 else
1882 {
1883 /* delay processing */
1884 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1885 "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %s\n",
1886 s,
1887 sc,
1888 GNUNET_STRINGS_relative_time_to_string(delay,
1889 GNUNET_YES));
1890 GNUNET_assert(s->server_recv->mhd_conn == mhd_connection);
1891 MHD_suspend_connection(s->server_recv->mhd_conn);
1892 s->server_recv->suspended = true;
1893 if (NULL == s->recv_wakeup_task)
1894 s->recv_wakeup_task
1895 = GNUNET_SCHEDULER_add_delayed(delay,
1896 &server_wake_up,
1897 s);
1898 }
1899 return MHD_YES;
1900 } 1889 }
1890 GNUNET_MST_from_buffer (s->msg_tk,
1891 upload_data,
1892 *upload_data_size,
1893 GNUNET_NO, GNUNET_NO);
1894 server_mhd_connection_timeout (plugin, s,
1895 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.
1896 rel_value_us / 1000LL
1897 / 1000LL);
1898 (*upload_data_size) = 0;
1899 }
1901 else 1900 else
1902 { 1901 {
1903 GNUNET_break(0); 1902 /* delay processing */
1904 return MHD_NO; 1903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1905 } 1904 "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %s\n",
1905 s,
1906 sc,
1907 GNUNET_STRINGS_relative_time_to_string (delay,
1908 GNUNET_YES));
1909 GNUNET_assert (s->server_recv->mhd_conn == mhd_connection);
1910 MHD_suspend_connection (s->server_recv->mhd_conn);
1911 s->server_recv->suspended = true;
1912 if (NULL == s->recv_wakeup_task)
1913 s->recv_wakeup_task
1914 = GNUNET_SCHEDULER_add_delayed (delay,
1915 &server_wake_up,
1916 s);
1917 }
1918 return MHD_YES;
1906 } 1919 }
1920 else
1921 {
1922 GNUNET_break (0);
1923 return MHD_NO;
1924 }
1925 }
1907 return res; 1926 return res;
1908} 1927}
1909 1928
@@ -1916,54 +1935,56 @@ server_access_cb(void *cls,
1916 * @param httpSessionCache the pointer to distinguish 1935 * @param httpSessionCache the pointer to distinguish
1917 */ 1936 */
1918static void 1937static void
1919server_disconnect_cb(void *cls, 1938server_disconnect_cb (void *cls,
1920 struct MHD_Connection *connection, 1939 struct MHD_Connection *connection,
1921 void **httpSessionCache) 1940 void **httpSessionCache)
1922{ 1941{
1923 struct HTTP_Server_Plugin *plugin = cls; 1942 struct HTTP_Server_Plugin *plugin = cls;
1924 struct ServerRequest *sc = *httpSessionCache; 1943 struct ServerRequest *sc = *httpSessionCache;
1925 1944
1926 LOG(GNUNET_ERROR_TYPE_DEBUG, 1945 LOG (GNUNET_ERROR_TYPE_DEBUG,
1927 "Disconnect for connection %p\n", 1946 "Disconnect for connection %p\n",
1928 sc); 1947 sc);
1929 if (NULL == sc) 1948 if (NULL == sc)
1930 { 1949 {
1931 /* CORS pre-flight request finished */ 1950 /* CORS pre-flight request finished */
1932 return; 1951 return;
1933 } 1952 }
1934 1953
1935 if (NULL != sc->session) 1954 if (NULL != sc->session)
1936 { 1955 {
1937 if (sc->direction == _SEND) 1956 if (sc->direction == _SEND)
1938 { 1957 {
1939 LOG(GNUNET_ERROR_TYPE_DEBUG, 1958 LOG (GNUNET_ERROR_TYPE_DEBUG,
1940 "Peer `%s' connection %p, GET on address `%s' disconnected\n", 1959 "Peer `%s' connection %p, GET on address `%s' disconnected\n",
1941 GNUNET_i2s(&sc->session->target), 1960 GNUNET_i2s (&sc->session->target),
1942 sc->session->server_send, 1961 sc->session->server_send,
1943 http_common_plugin_address_to_string(plugin->protocol, 1962 http_common_plugin_address_to_string (plugin->protocol,
1944 sc->session->address->address, 1963 sc->session->address->address,
1945 sc->session->address->address_length)); 1964 sc->session->address->
1946 1965 address_length));
1947 sc->session->server_send = NULL; 1966
1948 } 1967 sc->session->server_send = NULL;
1949 else if (sc->direction == _RECEIVE) 1968 }
1950 { 1969 else if (sc->direction == _RECEIVE)
1951 LOG(GNUNET_ERROR_TYPE_DEBUG, 1970 {
1952 "Peer `%s' connection %p PUT on address `%s' disconnected\n", 1971 LOG (GNUNET_ERROR_TYPE_DEBUG,
1953 GNUNET_i2s(&sc->session->target), 1972 "Peer `%s' connection %p PUT on address `%s' disconnected\n",
1954 sc->session->server_recv, 1973 GNUNET_i2s (&sc->session->target),
1955 http_common_plugin_address_to_string(plugin->protocol, 1974 sc->session->server_recv,
1956 sc->session->address->address, 1975 http_common_plugin_address_to_string (plugin->protocol,
1957 sc->session->address->address_length)); 1976 sc->session->address->address,
1958 sc->session->server_recv = NULL; 1977 sc->session->address->
1959 if (NULL != sc->session->msg_tk) 1978 address_length));
1960 { 1979 sc->session->server_recv = NULL;
1961 GNUNET_MST_destroy(sc->session->msg_tk); 1980 if (NULL != sc->session->msg_tk)
1962 sc->session->msg_tk = NULL; 1981 {
1963 } 1982 GNUNET_MST_destroy (sc->session->msg_tk);
1964 } 1983 sc->session->msg_tk = NULL;
1965 } 1984 }
1966 GNUNET_free(sc); 1985 }
1986 }
1987 GNUNET_free (sc);
1967 plugin->cur_request--; 1988 plugin->cur_request--;
1968} 1989}
1969 1990
@@ -1978,10 +1999,10 @@ server_disconnect_cb(void *cls,
1978 * @see #MHD_OPTION_NOTIFY_CONNECTION 1999 * @see #MHD_OPTION_NOTIFY_CONNECTION
1979 */ 2000 */
1980static void 2001static void
1981server_connection_cb(void *cls, 2002server_connection_cb (void *cls,
1982 struct MHD_Connection *connection, 2003 struct MHD_Connection *connection,
1983 void **socket_context, 2004 void **socket_context,
1984 enum MHD_ConnectionNotificationCode toe) 2005 enum MHD_ConnectionNotificationCode toe)
1985{ 2006{
1986 struct HTTP_Server_Plugin *plugin = cls; 2007 struct HTTP_Server_Plugin *plugin = cls;
1987 const union MHD_ConnectionInfo *info; 2008 const union MHD_ConnectionInfo *info;
@@ -1990,12 +2011,12 @@ server_connection_cb(void *cls,
1990 return; 2011 return;
1991 2012
1992 /* Reschedule to remove closed socket from our select set */ 2013 /* Reschedule to remove closed socket from our select set */
1993 info = MHD_get_connection_info(connection, 2014 info = MHD_get_connection_info (connection,
1994 MHD_CONNECTION_INFO_DAEMON); 2015 MHD_CONNECTION_INFO_DAEMON);
1995 GNUNET_assert(NULL != info); 2016 GNUNET_assert (NULL != info);
1996 server_reschedule(plugin, 2017 server_reschedule (plugin,
1997 info->daemon, 2018 info->daemon,
1998 GNUNET_YES); 2019 GNUNET_YES);
1999} 2020}
2000 2021
2001 2022
@@ -2008,27 +2029,28 @@ server_connection_cb(void *cls,
2008 * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected 2029 * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected
2009 */ 2030 */
2010static int 2031static int
2011server_accept_cb(void *cls, 2032server_accept_cb (void *cls,
2012 const struct sockaddr *addr, 2033 const struct sockaddr *addr,
2013 socklen_t addr_len) 2034 socklen_t addr_len)
2014{ 2035{
2015 struct HTTP_Server_Plugin *plugin = cls; 2036 struct HTTP_Server_Plugin *plugin = cls;
2016 2037
2017 if (plugin->cur_request <= plugin->max_request) 2038 if (plugin->cur_request <= plugin->max_request)
2018 { 2039 {
2019 LOG(GNUNET_ERROR_TYPE_DEBUG, 2040 LOG (GNUNET_ERROR_TYPE_DEBUG,
2020 _("Accepting connection (%u of %u) from `%s'\n"), 2041 _ ("Accepting connection (%u of %u) from `%s'\n"),
2021 plugin->cur_request, plugin->max_request, 2042 plugin->cur_request, plugin->max_request,
2022 GNUNET_a2s(addr, addr_len)); 2043 GNUNET_a2s (addr, addr_len));
2023 return MHD_YES; 2044 return MHD_YES;
2024 } 2045 }
2025 else 2046 else
2026 { 2047 {
2027 LOG(GNUNET_ERROR_TYPE_WARNING, 2048 LOG (GNUNET_ERROR_TYPE_WARNING,
2028 _("Server reached maximum number connections (%u), rejecting new connection\n"), 2049 _ (
2029 plugin->max_request); 2050 "Server reached maximum number connections (%u), rejecting new connection\n"),
2030 return MHD_NO; 2051 plugin->max_request);
2031 } 2052 return MHD_NO;
2053 }
2032} 2054}
2033 2055
2034 2056
@@ -2041,19 +2063,19 @@ server_accept_cb(void *cls,
2041 * will be called by MHD) 2063 * will be called by MHD)
2042 */ 2064 */
2043static void 2065static void
2044server_log(void *arg, 2066server_log (void *arg,
2045 const char *fmt, 2067 const char *fmt,
2046 va_list ap) 2068 va_list ap)
2047{ 2069{
2048 char text[1024]; 2070 char text[1024];
2049 2071
2050 vsnprintf(text, 2072 vsnprintf (text,
2051 sizeof(text), 2073 sizeof(text),
2052 fmt, 2074 fmt,
2053 ap); 2075 ap);
2054 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2055 "Server: %s\n", 2077 "Server: %s\n",
2056 text); 2078 text);
2057} 2079}
2058 2080
2059 2081
@@ -2065,32 +2087,32 @@ server_log(void *arg,
2065 * @return content of the file 2087 * @return content of the file
2066 */ 2088 */
2067static char * 2089static char *
2068server_load_file(const char *file) 2090server_load_file (const char *file)
2069{ 2091{
2070 struct GNUNET_DISK_FileHandle *gn_file; 2092 struct GNUNET_DISK_FileHandle *gn_file;
2071 uint64_t fsize; 2093 uint64_t fsize;
2072 char *text = NULL; 2094 char *text = NULL;
2073 2095
2074 if (GNUNET_OK != GNUNET_DISK_file_size(file, 2096 if (GNUNET_OK != GNUNET_DISK_file_size (file,
2075 &fsize, GNUNET_NO, GNUNET_YES)) 2097 &fsize, GNUNET_NO, GNUNET_YES))
2076 return NULL; 2098 return NULL;
2077 text = GNUNET_malloc(fsize + 1); 2099 text = GNUNET_malloc (fsize + 1);
2078 gn_file = 2100 gn_file =
2079 GNUNET_DISK_file_open(file, GNUNET_DISK_OPEN_READ, 2101 GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ,
2080 GNUNET_DISK_PERM_USER_READ); 2102 GNUNET_DISK_PERM_USER_READ);
2081 if (NULL == gn_file) 2103 if (NULL == gn_file)
2082 { 2104 {
2083 GNUNET_free(text); 2105 GNUNET_free (text);
2084 return NULL; 2106 return NULL;
2085 } 2107 }
2086 if (GNUNET_SYSERR == GNUNET_DISK_file_read(gn_file, text, fsize)) 2108 if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fsize))
2087 { 2109 {
2088 GNUNET_free(text); 2110 GNUNET_free (text);
2089 GNUNET_DISK_file_close(gn_file); 2111 GNUNET_DISK_file_close (gn_file);
2090 return NULL; 2112 return NULL;
2091 } 2113 }
2092 text[fsize] = '\0'; 2114 text[fsize] = '\0';
2093 GNUNET_DISK_file_close(gn_file); 2115 GNUNET_DISK_file_close (gn_file);
2094 return text; 2116 return text;
2095} 2117}
2096#endif 2118#endif
@@ -2104,7 +2126,7 @@ server_load_file(const char *file)
2104 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 2126 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2105 */ 2127 */
2106static int 2128static int
2107server_load_certificate(struct HTTP_Server_Plugin *plugin) 2129server_load_certificate (struct HTTP_Server_Plugin *plugin)
2108{ 2130{
2109 int res = GNUNET_OK; 2131 int res = GNUNET_OK;
2110 char *key_file; 2132 char *key_file;
@@ -2112,110 +2134,112 @@ server_load_certificate(struct HTTP_Server_Plugin *plugin)
2112 2134
2113 2135
2114 if (GNUNET_OK != 2136 if (GNUNET_OK !=
2115 GNUNET_CONFIGURATION_get_value_filename(plugin->env->cfg, 2137 GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg,
2116 plugin->name, 2138 plugin->name,
2117 "KEY_FILE", &key_file)) 2139 "KEY_FILE", &key_file))
2118 { 2140 {
2119 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 2141 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2120 plugin->name, "CERT_FILE"); 2142 plugin->name, "CERT_FILE");
2121 return GNUNET_SYSERR; 2143 return GNUNET_SYSERR;
2122 } 2144 }
2123 if (GNUNET_OK != 2145 if (GNUNET_OK !=
2124 GNUNET_CONFIGURATION_get_value_filename(plugin->env->cfg, 2146 GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg,
2125 plugin->name, 2147 plugin->name,
2126 "CERT_FILE", &cert_file)) 2148 "CERT_FILE", &cert_file))
2127 { 2149 {
2128 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 2150 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2129 plugin->name, "CERT_FILE"); 2151 plugin->name, "CERT_FILE");
2130 GNUNET_free(key_file); 2152 GNUNET_free (key_file);
2131 return GNUNET_SYSERR; 2153 return GNUNET_SYSERR;
2132 } 2154 }
2133 /* Get crypto init string from config. If not present, use 2155 /* Get crypto init string from config. If not present, use
2134 * default values */ 2156 * default values */
2135 if (GNUNET_OK == 2157 if (GNUNET_OK ==
2136 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, 2158 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2137 plugin->name, 2159 plugin->name,
2138 "CRYPTO_INIT", 2160 "CRYPTO_INIT",
2139 &plugin->crypto_init)) 2161 &plugin->crypto_init))
2140 LOG(GNUNET_ERROR_TYPE_DEBUG, 2162 LOG (GNUNET_ERROR_TYPE_DEBUG,
2141 "Using crypto init string `%s'\n", 2163 "Using crypto init string `%s'\n",
2142 plugin->crypto_init); 2164 plugin->crypto_init);
2143 else 2165 else
2144 LOG(GNUNET_ERROR_TYPE_DEBUG, 2166 LOG (GNUNET_ERROR_TYPE_DEBUG,
2145 "Using default crypto init string \n"); 2167 "Using default crypto init string \n");
2146 2168
2147 /* read key & certificates from file */ 2169 /* read key & certificates from file */
2148 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2149 "Trying to loading TLS certificate from key-file `%s' cert-file`%s'\n", 2171 "Trying to loading TLS certificate from key-file `%s' cert-file`%s'\n",
2150 key_file, cert_file); 2172 key_file, cert_file);
2151 2173
2152 plugin->key = server_load_file(key_file); 2174 plugin->key = server_load_file (key_file);
2153 plugin->cert = server_load_file(cert_file); 2175 plugin->cert = server_load_file (cert_file);
2154
2155 if ((plugin->key == NULL) || (plugin->cert == NULL))
2156 {
2157 struct GNUNET_OS_Process *cert_creation;
2158
2159 GNUNET_free_non_null(plugin->key);
2160 plugin->key = NULL;
2161 GNUNET_free_non_null(plugin->cert);
2162 plugin->cert = NULL;
2163
2164 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2165 "No usable TLS certificate found, creating certificate\n");
2166 errno = 0;
2167 cert_creation =
2168 GNUNET_OS_start_process(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
2169 NULL, NULL, NULL,
2170 "gnunet-transport-certificate-creation",
2171 "gnunet-transport-certificate-creation",
2172 key_file,
2173 cert_file,
2174 NULL);
2175 if (NULL == cert_creation)
2176 {
2177 LOG(GNUNET_ERROR_TYPE_ERROR,
2178 _("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
2179 GNUNET_free(key_file);
2180 GNUNET_free(cert_file);
2181
2182 GNUNET_free_non_null(plugin->key);
2183 plugin->key = NULL;
2184 GNUNET_free_non_null(plugin->cert);
2185 plugin->cert = NULL;
2186 GNUNET_free_non_null(plugin->crypto_init);
2187 plugin->crypto_init = NULL;
2188
2189 return GNUNET_SYSERR;
2190 }
2191 GNUNET_assert(GNUNET_OK == GNUNET_OS_process_wait(cert_creation));
2192 GNUNET_OS_process_destroy(cert_creation);
2193
2194 plugin->key = server_load_file(key_file);
2195 plugin->cert = server_load_file(cert_file);
2196 }
2197 2176
2198 if ((plugin->key == NULL) || (plugin->cert == NULL)) 2177 if ((plugin->key == NULL) || (plugin->cert == NULL))
2178 {
2179 struct GNUNET_OS_Process *cert_creation;
2180
2181 GNUNET_free_non_null (plugin->key);
2182 plugin->key = NULL;
2183 GNUNET_free_non_null (plugin->cert);
2184 plugin->cert = NULL;
2185
2186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2187 "No usable TLS certificate found, creating certificate\n");
2188 errno = 0;
2189 cert_creation =
2190 GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
2191 NULL, NULL, NULL,
2192 "gnunet-transport-certificate-creation",
2193 "gnunet-transport-certificate-creation",
2194 key_file,
2195 cert_file,
2196 NULL);
2197 if (NULL == cert_creation)
2199 { 2198 {
2200 LOG(GNUNET_ERROR_TYPE_ERROR, 2199 LOG (GNUNET_ERROR_TYPE_ERROR,
2201 _("No usable TLS certificate found and creating one at `%s/%s' failed!\n"), 2200 _ (
2202 key_file, cert_file); 2201 "Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
2203 GNUNET_free(key_file); 2202 GNUNET_free (key_file);
2204 GNUNET_free(cert_file); 2203 GNUNET_free (cert_file);
2205 2204
2206 GNUNET_free_non_null(plugin->key); 2205 GNUNET_free_non_null (plugin->key);
2207 plugin->key = NULL; 2206 plugin->key = NULL;
2208 GNUNET_free_non_null(plugin->cert); 2207 GNUNET_free_non_null (plugin->cert);
2209 plugin->cert = NULL; 2208 plugin->cert = NULL;
2210 GNUNET_free_non_null(plugin->crypto_init); 2209 GNUNET_free_non_null (plugin->crypto_init);
2211 plugin->crypto_init = NULL; 2210 plugin->crypto_init = NULL;
2212 2211
2213 return GNUNET_SYSERR; 2212 return GNUNET_SYSERR;
2214 } 2213 }
2215 GNUNET_free(key_file); 2214 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (cert_creation));
2216 GNUNET_free(cert_file); 2215 GNUNET_OS_process_destroy (cert_creation);
2217 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2216
2218 "TLS certificate loaded\n"); 2217 plugin->key = server_load_file (key_file);
2218 plugin->cert = server_load_file (cert_file);
2219 }
2220
2221 if ((plugin->key == NULL) || (plugin->cert == NULL))
2222 {
2223 LOG (GNUNET_ERROR_TYPE_ERROR,
2224 _ (
2225 "No usable TLS certificate found and creating one at `%s/%s' failed!\n"),
2226 key_file, cert_file);
2227 GNUNET_free (key_file);
2228 GNUNET_free (cert_file);
2229
2230 GNUNET_free_non_null (plugin->key);
2231 plugin->key = NULL;
2232 GNUNET_free_non_null (plugin->cert);
2233 plugin->cert = NULL;
2234 GNUNET_free_non_null (plugin->crypto_init);
2235 plugin->crypto_init = NULL;
2236
2237 return GNUNET_SYSERR;
2238 }
2239 GNUNET_free (key_file);
2240 GNUNET_free (cert_file);
2241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2242 "TLS certificate loaded\n");
2219 return res; 2243 return res;
2220} 2244}
2221#endif 2245#endif
@@ -2231,40 +2255,40 @@ server_load_certificate(struct HTTP_Server_Plugin *plugin)
2231 * @return NULL on error 2255 * @return NULL on error
2232 */ 2256 */
2233static struct MHD_Daemon * 2257static struct MHD_Daemon *
2234run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin, 2258run_mhd_start_daemon (struct HTTP_Server_Plugin *plugin,
2235 const struct sockaddr_in *addr, 2259 const struct sockaddr_in *addr,
2236 int v6) 2260 int v6)
2237{ 2261{
2238 struct MHD_Daemon *server; 2262 struct MHD_Daemon *server;
2239 unsigned int timeout; 2263 unsigned int timeout;
2240 2264
2241#if MHD_VERSION >= 0x00090E00 2265#if MHD_VERSION >= 0x00090E00
2242 timeout = HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL / 1000LL; 2266 timeout = HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL / 1000LL;
2243 LOG(GNUNET_ERROR_TYPE_DEBUG, 2267 LOG (GNUNET_ERROR_TYPE_DEBUG,
2244 "MHD can set timeout per connection! Default time out %u sec.\n", 2268 "MHD can set timeout per connection! Default time out %u sec.\n",
2245 timeout); 2269 timeout);
2246#else 2270#else
2247 timeout = HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL; 2271 timeout = HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL;
2248 LOG(GNUNET_ERROR_TYPE_WARNING, 2272 LOG (GNUNET_ERROR_TYPE_WARNING,
2249 "MHD cannot set timeout per connection! Default time out %u sec.\n", 2273 "MHD cannot set timeout per connection! Default time out %u sec.\n",
2250 timeout); 2274 timeout);
2251#endif 2275#endif
2252 server = MHD_start_daemon( 2276 server = MHD_start_daemon (
2253#if VERBOSE_SERVER 2277#if VERBOSE_SERVER
2254 MHD_USE_DEBUG | 2278 MHD_USE_DEBUG |
2255#endif 2279#endif
2256#if BUILD_HTTPS 2280#if BUILD_HTTPS
2257 MHD_USE_SSL | 2281 MHD_USE_SSL |
2258#endif 2282#endif
2259 MHD_USE_SUSPEND_RESUME | 2283 MHD_USE_SUSPEND_RESUME
2260 v6, 2284 | v6,
2261 plugin->port, 2285 plugin->port,
2262 &server_accept_cb, plugin, 2286 &server_accept_cb, plugin,
2263 &server_access_cb, plugin, 2287 &server_access_cb, plugin,
2264 MHD_OPTION_SOCK_ADDR, 2288 MHD_OPTION_SOCK_ADDR,
2265 addr, 2289 addr,
2266 MHD_OPTION_CONNECTION_LIMIT, 2290 MHD_OPTION_CONNECTION_LIMIT,
2267 (unsigned int)plugin->max_request, 2291 (unsigned int) plugin->max_request,
2268#if BUILD_HTTPS 2292#if BUILD_HTTPS
2269 MHD_OPTION_HTTPS_PRIORITIES, 2293 MHD_OPTION_HTTPS_PRIORITIES,
2270 plugin->crypto_init, 2294 plugin->crypto_init,
@@ -2276,8 +2300,8 @@ run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin,
2276 MHD_OPTION_CONNECTION_TIMEOUT, 2300 MHD_OPTION_CONNECTION_TIMEOUT,
2277 timeout, 2301 timeout,
2278 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 2302 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
2279 (size_t)(2 * 2303 (size_t) (2
2280 GNUNET_MAX_MESSAGE_SIZE), 2304 * GNUNET_MAX_MESSAGE_SIZE),
2281 MHD_OPTION_NOTIFY_COMPLETED, 2305 MHD_OPTION_NOTIFY_COMPLETED,
2282 &server_disconnect_cb, plugin, 2306 &server_disconnect_cb, plugin,
2283 MHD_OPTION_NOTIFY_CONNECTION, 2307 MHD_OPTION_NOTIFY_CONNECTION,
@@ -2288,24 +2312,24 @@ run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin,
2288#ifdef TCP_STEALTH 2312#ifdef TCP_STEALTH
2289 if ((NULL != server) && 2313 if ((NULL != server) &&
2290 (0 != (plugin->options & HTTP_OPTIONS_TCP_STEALTH))) 2314 (0 != (plugin->options & HTTP_OPTIONS_TCP_STEALTH)))
2291 { 2315 {
2292 const union MHD_DaemonInfo *di; 2316 const union MHD_DaemonInfo *di;
2293 2317
2294 di = MHD_get_daemon_info(server, 2318 di = MHD_get_daemon_info (server,
2295 MHD_DAEMON_INFO_LISTEN_FD, 2319 MHD_DAEMON_INFO_LISTEN_FD,
2296 NULL); 2320 NULL);
2297 if ((0 != setsockopt((int)di->listen_fd, 2321 if ((0 != setsockopt ((int) di->listen_fd,
2298 IPPROTO_TCP, 2322 IPPROTO_TCP,
2299 TCP_STEALTH, 2323 TCP_STEALTH,
2300 plugin->env->my_identity, 2324 plugin->env->my_identity,
2301 sizeof(struct GNUNET_PeerIdentity)))) 2325 sizeof(struct GNUNET_PeerIdentity))))
2302 { 2326 {
2303 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2304 _("TCP_STEALTH not supported on this platform.\n")); 2328 _ ("TCP_STEALTH not supported on this platform.\n"));
2305 MHD_stop_daemon(server); 2329 MHD_stop_daemon (server);
2306 server = NULL; 2330 server = NULL;
2307 }
2308 } 2331 }
2332 }
2309#endif 2333#endif
2310 return server; 2334 return server;
2311} 2335}
@@ -2318,76 +2342,79 @@ run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin,
2318 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 2342 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2319 */ 2343 */
2320static int 2344static int
2321server_start(struct HTTP_Server_Plugin *plugin) 2345server_start (struct HTTP_Server_Plugin *plugin)
2322{ 2346{
2323 const char *msg; 2347 const char *msg;
2324 2348
2325 GNUNET_assert(NULL != plugin); 2349 GNUNET_assert (NULL != plugin);
2326#if BUILD_HTTPS 2350#if BUILD_HTTPS
2327 if (GNUNET_SYSERR == server_load_certificate(plugin)) 2351 if (GNUNET_SYSERR == server_load_certificate (plugin))
2328 { 2352 {
2329 LOG(GNUNET_ERROR_TYPE_ERROR, 2353 LOG (GNUNET_ERROR_TYPE_ERROR,
2330 _("Could not load or create server certificate! Loading plugin failed!\n")); 2354 _ (
2331 return GNUNET_SYSERR; 2355 "Could not load or create server certificate! Loading plugin failed!\n"));
2332 } 2356 return GNUNET_SYSERR;
2357 }
2333#endif 2358#endif
2334 2359
2335 2360
2336 2361
2337 plugin->server_v4 = NULL; 2362 plugin->server_v4 = NULL;
2338 if (GNUNET_YES == plugin->use_ipv4) 2363 if (GNUNET_YES == plugin->use_ipv4)
2339 { 2364 {
2340 plugin->server_v4 2365 plugin->server_v4
2341 = run_mhd_start_daemon(plugin, 2366 = run_mhd_start_daemon (plugin,
2342 (const struct sockaddr_in *)plugin->server_addr_v4, 2367 (const struct
2343 MHD_NO_FLAG); 2368 sockaddr_in *) plugin->server_addr_v4,
2369 MHD_NO_FLAG);
2344 2370
2345 if (NULL == plugin->server_v4) 2371 if (NULL == plugin->server_v4)
2346 { 2372 {
2347 LOG(GNUNET_ERROR_TYPE_ERROR, 2373 LOG (GNUNET_ERROR_TYPE_ERROR,
2348 "Failed to start %s IPv4 server component on port %u\n", 2374 "Failed to start %s IPv4 server component on port %u\n",
2349 plugin->name, 2375 plugin->name,
2350 plugin->port); 2376 plugin->port);
2351 }
2352 else
2353 server_reschedule(plugin,
2354 plugin->server_v4,
2355 GNUNET_NO);
2356 } 2377 }
2378 else
2379 server_reschedule (plugin,
2380 plugin->server_v4,
2381 GNUNET_NO);
2382 }
2357 2383
2358 2384
2359 plugin->server_v6 = NULL; 2385 plugin->server_v6 = NULL;
2360 if (GNUNET_YES == plugin->use_ipv6) 2386 if (GNUNET_YES == plugin->use_ipv6)
2361 { 2387 {
2362 plugin->server_v6 2388 plugin->server_v6
2363 = run_mhd_start_daemon(plugin, 2389 = run_mhd_start_daemon (plugin,
2364 (const struct sockaddr_in *)plugin->server_addr_v6, 2390 (const struct
2365 MHD_USE_IPv6); 2391 sockaddr_in *) plugin->server_addr_v6,
2366 if (NULL == plugin->server_v6) 2392 MHD_USE_IPv6);
2367 { 2393 if (NULL == plugin->server_v6)
2368 LOG(GNUNET_ERROR_TYPE_ERROR, 2394 {
2369 "Failed to start %s IPv6 server component on port %u\n", 2395 LOG (GNUNET_ERROR_TYPE_ERROR,
2370 plugin->name, 2396 "Failed to start %s IPv6 server component on port %u\n",
2371 plugin->port); 2397 plugin->name,
2372 } 2398 plugin->port);
2373 else 2399 }
2374 { 2400 else
2375 server_reschedule(plugin, 2401 {
2376 plugin->server_v6, 2402 server_reschedule (plugin,
2377 GNUNET_NO); 2403 plugin->server_v6,
2378 } 2404 GNUNET_NO);
2379 } 2405 }
2406 }
2380 msg = "No"; 2407 msg = "No";
2381 if ((NULL == plugin->server_v6) && 2408 if ((NULL == plugin->server_v6) &&
2382 (NULL == plugin->server_v4)) 2409 (NULL == plugin->server_v4))
2383 { 2410 {
2384 LOG(GNUNET_ERROR_TYPE_ERROR, 2411 LOG (GNUNET_ERROR_TYPE_ERROR,
2385 "%s %s server component started on port %u\n", 2412 "%s %s server component started on port %u\n",
2386 msg, 2413 msg,
2387 plugin->name, 2414 plugin->name,
2388 plugin->port); 2415 plugin->port);
2389 return GNUNET_SYSERR; 2416 return GNUNET_SYSERR;
2390 } 2417 }
2391 if ((NULL != plugin->server_v6) && 2418 if ((NULL != plugin->server_v6) &&
2392 (NULL != plugin->server_v4)) 2419 (NULL != plugin->server_v4))
2393 msg = "IPv4 and IPv6"; 2420 msg = "IPv4 and IPv6";
@@ -2395,11 +2422,11 @@ server_start(struct HTTP_Server_Plugin *plugin)
2395 msg = "IPv6"; 2422 msg = "IPv6";
2396 else if (NULL != plugin->server_v4) 2423 else if (NULL != plugin->server_v4)
2397 msg = "IPv4"; 2424 msg = "IPv4";
2398 LOG(GNUNET_ERROR_TYPE_DEBUG, 2425 LOG (GNUNET_ERROR_TYPE_DEBUG,
2399 "%s %s server component started on port %u\n", 2426 "%s %s server component started on port %u\n",
2400 msg, 2427 msg,
2401 plugin->name, 2428 plugin->name,
2402 plugin->port); 2429 plugin->port);
2403 return GNUNET_OK; 2430 return GNUNET_OK;
2404} 2431}
2405 2432
@@ -2413,47 +2440,51 @@ server_start(struct HTTP_Server_Plugin *plugin)
2413 * @param addrlen address length 2440 * @param addrlen address length
2414 */ 2441 */
2415static void 2442static void
2416server_add_address(void *cls, 2443server_add_address (void *cls,
2417 int add_remove, 2444 int add_remove,
2418 const struct sockaddr *addr, 2445 const struct sockaddr *addr,
2419 socklen_t addrlen) 2446 socklen_t addrlen)
2420{ 2447{
2421 struct HTTP_Server_Plugin *plugin = cls; 2448 struct HTTP_Server_Plugin *plugin = cls;
2422 struct GNUNET_HELLO_Address *address; 2449 struct GNUNET_HELLO_Address *address;
2423 struct HttpAddressWrapper *w = NULL; 2450 struct HttpAddressWrapper *w = NULL;
2424 2451
2425 w = GNUNET_new(struct HttpAddressWrapper); 2452 w = GNUNET_new (struct HttpAddressWrapper);
2426 w->address = http_common_address_from_socket(plugin->protocol, 2453 w->address = http_common_address_from_socket (plugin->protocol,
2427 addr, 2454 addr,
2428 addrlen); 2455 addrlen);
2429 if (NULL == w->address) 2456 if (NULL == w->address)
2430 { 2457 {
2431 GNUNET_free(w); 2458 GNUNET_free (w);
2432 return; 2459 return;
2433 } 2460 }
2434 w->addrlen = http_common_address_get_size(w->address); 2461 w->addrlen = http_common_address_get_size (w->address);
2435 2462
2436 GNUNET_CONTAINER_DLL_insert(plugin->addr_head, 2463 GNUNET_CONTAINER_DLL_insert (plugin->addr_head,
2437 plugin->addr_tail, 2464 plugin->addr_tail,
2438 w); 2465 w);
2439 LOG(GNUNET_ERROR_TYPE_DEBUG, 2466 LOG (GNUNET_ERROR_TYPE_DEBUG,
2440 "Notifying transport to add address `%s'\n", 2467 "Notifying transport to add address `%s'\n",
2441 http_common_plugin_address_to_string(plugin->protocol, 2468 http_common_plugin_address_to_string (plugin->protocol,
2442 w->address, 2469 w->address,
2443 w->addrlen)); 2470 w->addrlen));
2444 /* modify our published address list */ 2471 /* modify our published address list */
2445#if BUILD_HTTPS 2472#if BUILD_HTTPS
2446 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 2473 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2447 "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); 2474 "https_client", w->address,
2475 w->addrlen,
2476 GNUNET_HELLO_ADDRESS_INFO_NONE);
2448#else 2477#else
2449 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 2478 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2450 "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); 2479 "http_client", w->address,
2480 w->addrlen,
2481 GNUNET_HELLO_ADDRESS_INFO_NONE);
2451#endif 2482#endif
2452 2483
2453 plugin->env->notify_address(plugin->env->cls, 2484 plugin->env->notify_address (plugin->env->cls,
2454 add_remove, 2485 add_remove,
2455 address); 2486 address);
2456 GNUNET_HELLO_address_free(address); 2487 GNUNET_HELLO_address_free (address);
2457} 2488}
2458 2489
2459 2490
@@ -2466,59 +2497,63 @@ server_add_address(void *cls,
2466 * @param addrlen address length 2497 * @param addrlen address length
2467 */ 2498 */
2468static void 2499static void
2469server_remove_address(void *cls, 2500server_remove_address (void *cls,
2470 int add_remove, 2501 int add_remove,
2471 const struct sockaddr *addr, 2502 const struct sockaddr *addr,
2472 socklen_t addrlen) 2503 socklen_t addrlen)
2473{ 2504{
2474 struct HTTP_Server_Plugin *plugin = cls; 2505 struct HTTP_Server_Plugin *plugin = cls;
2475 struct GNUNET_HELLO_Address *address; 2506 struct GNUNET_HELLO_Address *address;
2476 struct HttpAddressWrapper *w = plugin->addr_head; 2507 struct HttpAddressWrapper *w = plugin->addr_head;
2477 size_t saddr_len; 2508 size_t saddr_len;
2478 void * saddr; 2509 void *saddr;
2479 2510
2480 saddr = http_common_address_from_socket(plugin->protocol, 2511 saddr = http_common_address_from_socket (plugin->protocol,
2481 addr, 2512 addr,
2482 addrlen); 2513 addrlen);
2483 if (NULL == saddr) 2514 if (NULL == saddr)
2484 return; 2515 return;
2485 saddr_len = http_common_address_get_size(saddr); 2516 saddr_len = http_common_address_get_size (saddr);
2486 2517
2487 while (NULL != w) 2518 while (NULL != w)
2488 { 2519 {
2489 if (GNUNET_YES == 2520 if (GNUNET_YES ==
2490 http_common_cmp_addresses(w->address, 2521 http_common_cmp_addresses (w->address,
2491 w->addrlen, 2522 w->addrlen,
2492 saddr, 2523 saddr,
2493 saddr_len)) 2524 saddr_len))
2494 break; 2525 break;
2495 w = w->next; 2526 w = w->next;
2496 } 2527 }
2497 GNUNET_free(saddr); 2528 GNUNET_free (saddr);
2498 2529
2499 if (NULL == w) 2530 if (NULL == w)
2500 return; 2531 return;
2501 2532
2502 LOG(GNUNET_ERROR_TYPE_DEBUG, 2533 LOG (GNUNET_ERROR_TYPE_DEBUG,
2503 "Notifying transport to remove address `%s'\n", 2534 "Notifying transport to remove address `%s'\n",
2504 http_common_plugin_address_to_string(plugin->protocol, 2535 http_common_plugin_address_to_string (plugin->protocol,
2505 w->address, 2536 w->address,
2506 w->addrlen)); 2537 w->addrlen));
2507 GNUNET_CONTAINER_DLL_remove(plugin->addr_head, 2538 GNUNET_CONTAINER_DLL_remove (plugin->addr_head,
2508 plugin->addr_tail, 2539 plugin->addr_tail,
2509 w); 2540 w);
2510 /* modify our published address list */ 2541 /* modify our published address list */
2511#if BUILD_HTTPS 2542#if BUILD_HTTPS
2512 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 2543 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2513 "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); 2544 "https_client", w->address,
2545 w->addrlen,
2546 GNUNET_HELLO_ADDRESS_INFO_NONE);
2514#else 2547#else
2515 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 2548 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2516 "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); 2549 "http_client", w->address,
2550 w->addrlen,
2551 GNUNET_HELLO_ADDRESS_INFO_NONE);
2517#endif 2552#endif
2518 plugin->env->notify_address(plugin->env->cls, add_remove, address); 2553 plugin->env->notify_address (plugin->env->cls, add_remove, address);
2519 GNUNET_HELLO_address_free(address); 2554 GNUNET_HELLO_address_free (address);
2520 GNUNET_free(w->address); 2555 GNUNET_free (w->address);
2521 GNUNET_free(w); 2556 GNUNET_free (w);
2522} 2557}
2523 2558
2524 2559
@@ -2536,67 +2571,67 @@ server_remove_address(void *cls,
2536 * @param addrlen actual lenght of the address 2571 * @param addrlen actual lenght of the address
2537 */ 2572 */
2538static void 2573static void
2539server_nat_port_map_callback(void *cls, 2574server_nat_port_map_callback (void *cls,
2540 void **app_ctx, 2575 void **app_ctx,
2541 int add_remove, 2576 int add_remove,
2542 enum GNUNET_NAT_AddressClass ac, 2577 enum GNUNET_NAT_AddressClass ac,
2543 const struct sockaddr *addr, 2578 const struct sockaddr *addr,
2544 socklen_t addrlen) 2579 socklen_t addrlen)
2545{ 2580{
2546 struct HTTP_Server_Plugin *plugin = cls; 2581 struct HTTP_Server_Plugin *plugin = cls;
2547 2582
2548 (void)app_ctx; 2583 (void) app_ctx;
2549 LOG(GNUNET_ERROR_TYPE_DEBUG, 2584 LOG (GNUNET_ERROR_TYPE_DEBUG,
2550 "NAT called to %s address `%s'\n", 2585 "NAT called to %s address `%s'\n",
2551 (add_remove == GNUNET_NO) ? "remove" : "add", 2586 (add_remove == GNUNET_NO) ? "remove" : "add",
2552 GNUNET_a2s(addr, addrlen)); 2587 GNUNET_a2s (addr, addrlen));
2553 2588
2554 if (AF_INET == addr->sa_family) 2589 if (AF_INET == addr->sa_family)
2555 { 2590 {
2556 struct sockaddr_in *s4 = (struct sockaddr_in *)addr; 2591 struct sockaddr_in *s4 = (struct sockaddr_in *) addr;
2557 2592
2558 if (GNUNET_NO == plugin->use_ipv4) 2593 if (GNUNET_NO == plugin->use_ipv4)
2559 return; 2594 return;
2560 2595
2561 if ((NULL != plugin->server_addr_v4) && 2596 if ((NULL != plugin->server_addr_v4) &&
2562 (0 != memcmp(&plugin->server_addr_v4->sin_addr, 2597 (0 != memcmp (&plugin->server_addr_v4->sin_addr,
2563 &s4->sin_addr, 2598 &s4->sin_addr,
2564 sizeof(struct in_addr)))) 2599 sizeof(struct in_addr))))
2565 { 2600 {
2566 LOG(GNUNET_ERROR_TYPE_DEBUG, 2601 LOG (GNUNET_ERROR_TYPE_DEBUG,
2567 "Skipping address `%s' (not bindto address)\n", 2602 "Skipping address `%s' (not bindto address)\n",
2568 GNUNET_a2s(addr, addrlen)); 2603 GNUNET_a2s (addr, addrlen));
2569 return; 2604 return;
2570 }
2571 } 2605 }
2606 }
2572 2607
2573 if (AF_INET6 == addr->sa_family) 2608 if (AF_INET6 == addr->sa_family)
2574 { 2609 {
2575 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *)addr; 2610 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) addr;
2576 if (GNUNET_NO == plugin->use_ipv6) 2611 if (GNUNET_NO == plugin->use_ipv6)
2577 return; 2612 return;
2578 2613
2579 if ((NULL != plugin->server_addr_v6) && 2614 if ((NULL != plugin->server_addr_v6) &&
2580 (0 != memcmp(&plugin->server_addr_v6->sin6_addr, 2615 (0 != memcmp (&plugin->server_addr_v6->sin6_addr,
2581 &s6->sin6_addr, sizeof(struct in6_addr)))) 2616 &s6->sin6_addr, sizeof(struct in6_addr))))
2582 { 2617 {
2583 LOG(GNUNET_ERROR_TYPE_DEBUG, 2618 LOG (GNUNET_ERROR_TYPE_DEBUG,
2584 "Skipping address `%s' (not bindto address)\n", 2619 "Skipping address `%s' (not bindto address)\n",
2585 GNUNET_a2s(addr, addrlen)); 2620 GNUNET_a2s (addr, addrlen));
2586 return; 2621 return;
2587 }
2588 } 2622 }
2623 }
2589 2624
2590 switch (add_remove) 2625 switch (add_remove)
2591 { 2626 {
2592 case GNUNET_YES: 2627 case GNUNET_YES:
2593 server_add_address(cls, add_remove, addr, addrlen); 2628 server_add_address (cls, add_remove, addr, addrlen);
2594 break; 2629 break;
2595 2630
2596 case GNUNET_NO: 2631 case GNUNET_NO:
2597 server_remove_address(cls, add_remove, addr, addrlen); 2632 server_remove_address (cls, add_remove, addr, addrlen);
2598 break; 2633 break;
2599 } 2634 }
2600} 2635}
2601 2636
2602 2637
@@ -2611,11 +2646,11 @@ server_nat_port_map_callback(void *cls,
2611 * @return number of addresses 2646 * @return number of addresses
2612 */ 2647 */
2613static int 2648static int
2614server_get_addresses(struct HTTP_Server_Plugin *plugin, 2649server_get_addresses (struct HTTP_Server_Plugin *plugin,
2615 const char *service_name, 2650 const char *service_name,
2616 const struct GNUNET_CONFIGURATION_Handle *cfg, 2651 const struct GNUNET_CONFIGURATION_Handle *cfg,
2617 struct sockaddr ***addrs, 2652 struct sockaddr ***addrs,
2618 socklen_t ** addr_lens) 2653 socklen_t **addr_lens)
2619{ 2654{
2620 int disablev6; 2655 int disablev6;
2621 unsigned long long port; 2656 unsigned long long port;
@@ -2633,159 +2668,160 @@ server_get_addresses(struct HTTP_Server_Plugin *plugin,
2633 *addrs = NULL; 2668 *addrs = NULL;
2634 *addr_lens = NULL; 2669 *addr_lens = NULL;
2635 2670
2636 disablev6 = !plugin->use_ipv6; 2671 disablev6 = ! plugin->use_ipv6;
2637 2672
2638 port = 0; 2673 port = 0;
2639 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT")) 2674 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
2640 { 2675 {
2641 GNUNET_break(GNUNET_OK == 2676 GNUNET_break (GNUNET_OK ==
2642 GNUNET_CONFIGURATION_get_value_number(cfg, service_name, 2677 GNUNET_CONFIGURATION_get_value_number (cfg, service_name,
2643 "PORT", &port)); 2678 "PORT", &port));
2644 if (port > 65535) 2679 if (port > 65535)
2645 {
2646 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2647 _("Require valid port number for service in configuration!\n"));
2648 return GNUNET_SYSERR;
2649 }
2650 }
2651 if (0 == port)
2652 { 2680 {
2653 LOG(GNUNET_ERROR_TYPE_INFO, 2681 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2654 "Starting in listen only mode\n"); 2682 _ (
2655 return -1; /* listen only */ 2683 "Require valid port number for service in configuration!\n"));
2684 return GNUNET_SYSERR;
2656 } 2685 }
2657 2686 }
2658 2687 if (0 == port)
2659 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, 2688 {
2660 "BINDTO")) 2689 LOG (GNUNET_ERROR_TYPE_INFO,
2661 { 2690 "Starting in listen only mode\n");
2662 GNUNET_break(GNUNET_OK == 2691 return -1; /* listen only */
2663 GNUNET_CONFIGURATION_get_value_string(cfg, service_name, 2692 }
2693
2694
2695 if (GNUNET_CONFIGURATION_have_value (cfg, service_name,
2696 "BINDTO"))
2697 {
2698 GNUNET_break (GNUNET_OK ==
2699 GNUNET_CONFIGURATION_get_value_string (cfg, service_name,
2664 "BINDTO", &hostname)); 2700 "BINDTO", &hostname));
2665 } 2701 }
2666 else 2702 else
2667 hostname = NULL; 2703 hostname = NULL;
2668 2704
2669 if (NULL != hostname) 2705 if (NULL != hostname)
2706 {
2707 LOG (GNUNET_ERROR_TYPE_DEBUG,
2708 "Resolving `%s' since that is where `%s' will bind to.\n",
2709 hostname, service_name);
2710 memset (&hints, 0, sizeof(struct addrinfo));
2711 if (disablev6)
2712 hints.ai_family = AF_INET;
2713 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
2714 (NULL == res))
2715 {
2716 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2717 _ ("Failed to resolve `%s': %s\n"),
2718 hostname,
2719 gai_strerror (ret));
2720 GNUNET_free (hostname);
2721 return GNUNET_SYSERR;
2722 }
2723 next = res;
2724 i = 0;
2725 while (NULL != (pos = next))
2670 { 2726 {
2671 LOG(GNUNET_ERROR_TYPE_DEBUG, 2727 next = pos->ai_next;
2672 "Resolving `%s' since that is where `%s' will bind to.\n", 2728 if ((disablev6) && (pos->ai_family == AF_INET6))
2673 hostname, service_name); 2729 continue;
2674 memset(&hints, 0, sizeof(struct addrinfo)); 2730 i++;
2675 if (disablev6) 2731 }
2676 hints.ai_family = AF_INET; 2732 if (0 == i)
2677 if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || 2733 {
2678 (NULL == res)) 2734 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2679 { 2735 _ ("Failed to find %saddress for `%s'.\n"),
2680 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2736 disablev6 ? "IPv4 " : "", hostname);
2681 _("Failed to resolve `%s': %s\n"), 2737 freeaddrinfo (res);
2682 hostname, 2738 GNUNET_free (hostname);
2683 gai_strerror(ret)); 2739 return GNUNET_SYSERR;
2684 GNUNET_free(hostname);
2685 return GNUNET_SYSERR;
2686 }
2687 next = res;
2688 i = 0;
2689 while (NULL != (pos = next))
2690 {
2691 next = pos->ai_next;
2692 if ((disablev6) && (pos->ai_family == AF_INET6))
2693 continue;
2694 i++;
2695 }
2696 if (0 == i)
2697 {
2698 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2699 _("Failed to find %saddress for `%s'.\n"),
2700 disablev6 ? "IPv4 " : "", hostname);
2701 freeaddrinfo(res);
2702 GNUNET_free(hostname);
2703 return GNUNET_SYSERR;
2704 }
2705 resi = i;
2706 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
2707 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
2708 i = 0;
2709 next = res;
2710 while (NULL != (pos = next))
2711 {
2712 next = pos->ai_next;
2713 if ((disablev6) && (pos->ai_family == AF_INET6))
2714 continue;
2715 if ((pos->ai_protocol != IPPROTO_TCP) && (0 != pos->ai_protocol))
2716 continue; /* not TCP */
2717 if ((pos->ai_socktype != SOCK_STREAM) && (0 != pos->ai_socktype))
2718 continue; /* huh? */
2719 LOG(GNUNET_ERROR_TYPE_DEBUG,
2720 "Service will bind to `%s'\n",
2721 GNUNET_a2s(pos->ai_addr,
2722 pos->ai_addrlen));
2723 if (pos->ai_family == AF_INET)
2724 {
2725 GNUNET_assert(pos->ai_addrlen == sizeof(struct sockaddr_in));
2726 saddrlens[i] = pos->ai_addrlen;
2727 saddrs[i] = GNUNET_malloc(saddrlens[i]);
2728 GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]);
2729 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port);
2730 }
2731 else
2732 {
2733 GNUNET_assert(pos->ai_family == AF_INET6);
2734 GNUNET_assert(pos->ai_addrlen == sizeof(struct sockaddr_in6));
2735 saddrlens[i] = pos->ai_addrlen;
2736 saddrs[i] = GNUNET_malloc(saddrlens[i]);
2737 GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]);
2738 ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port);
2739 }
2740 i++;
2741 }
2742 GNUNET_free(hostname);
2743 freeaddrinfo(res);
2744 resi = i;
2745 } 2740 }
2741 resi = i;
2742 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
2743 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
2744 i = 0;
2745 next = res;
2746 while (NULL != (pos = next))
2747 {
2748 next = pos->ai_next;
2749 if ((disablev6) && (pos->ai_family == AF_INET6))
2750 continue;
2751 if ((pos->ai_protocol != IPPROTO_TCP) && (0 != pos->ai_protocol))
2752 continue; /* not TCP */
2753 if ((pos->ai_socktype != SOCK_STREAM) && (0 != pos->ai_socktype))
2754 continue; /* huh? */
2755 LOG (GNUNET_ERROR_TYPE_DEBUG,
2756 "Service will bind to `%s'\n",
2757 GNUNET_a2s (pos->ai_addr,
2758 pos->ai_addrlen));
2759 if (pos->ai_family == AF_INET)
2760 {
2761 GNUNET_assert (pos->ai_addrlen == sizeof(struct sockaddr_in));
2762 saddrlens[i] = pos->ai_addrlen;
2763 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2764 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
2765 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
2766 }
2767 else
2768 {
2769 GNUNET_assert (pos->ai_family == AF_INET6);
2770 GNUNET_assert (pos->ai_addrlen == sizeof(struct sockaddr_in6));
2771 saddrlens[i] = pos->ai_addrlen;
2772 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2773 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
2774 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
2775 }
2776 i++;
2777 }
2778 GNUNET_free (hostname);
2779 freeaddrinfo (res);
2780 resi = i;
2781 }
2746 else 2782 else
2783 {
2784 /* will bind against everything, just set port */
2785 if (disablev6)
2747 { 2786 {
2748 /* will bind against everything, just set port */ 2787 /* V4-only */
2749 if (disablev6) 2788 resi = 1;
2750 { 2789 i = 0;
2751 /* V4-only */ 2790 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
2752 resi = 1; 2791 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
2753 i = 0; 2792
2754 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); 2793 saddrlens[i] = sizeof(struct sockaddr_in);
2755 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); 2794 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2756
2757 saddrlens[i] = sizeof(struct sockaddr_in);
2758 saddrs[i] = GNUNET_malloc(saddrlens[i]);
2759#if HAVE_SOCKADDR_IN_SIN_LEN 2795#if HAVE_SOCKADDR_IN_SIN_LEN
2760 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; 2796 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
2761#endif 2797#endif
2762 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; 2798 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
2763 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); 2799 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
2764 } 2800 }
2765 else 2801 else
2766 { 2802 {
2767 /* dual stack */ 2803 /* dual stack */
2768 resi = 2; 2804 resi = 2;
2769 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); 2805 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
2770 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); 2806 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
2771 i = 0; 2807 i = 0;
2772 saddrlens[i] = sizeof(struct sockaddr_in6); 2808 saddrlens[i] = sizeof(struct sockaddr_in6);
2773 saddrs[i] = GNUNET_malloc(saddrlens[i]); 2809 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2774#if HAVE_SOCKADDR_IN_SIN_LEN 2810#if HAVE_SOCKADDR_IN_SIN_LEN
2775 ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; 2811 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
2776#endif 2812#endif
2777 ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; 2813 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
2778 ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); 2814 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
2779 i++; 2815 i++;
2780 saddrlens[i] = sizeof(struct sockaddr_in); 2816 saddrlens[i] = sizeof(struct sockaddr_in);
2781 saddrs[i] = GNUNET_malloc(saddrlens[i]); 2817 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2782#if HAVE_SOCKADDR_IN_SIN_LEN 2818#if HAVE_SOCKADDR_IN_SIN_LEN
2783 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1]; 2819 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
2784#endif 2820#endif
2785 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; 2821 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
2786 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); 2822 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
2787 }
2788 } 2823 }
2824 }
2789 *addrs = saddrs; 2825 *addrs = saddrs;
2790 *addr_lens = saddrlens; 2826 *addr_lens = saddrlens;
2791 return resi; 2827 return resi;
@@ -2798,44 +2834,44 @@ server_get_addresses(struct HTTP_Server_Plugin *plugin,
2798 * @param plugin the plugin handle 2834 * @param plugin the plugin handle
2799 */ 2835 */
2800static void 2836static void
2801server_start_report_addresses(struct HTTP_Server_Plugin *plugin) 2837server_start_report_addresses (struct HTTP_Server_Plugin *plugin)
2802{ 2838{
2803 int res = GNUNET_OK; 2839 int res = GNUNET_OK;
2804 struct sockaddr **addrs; 2840 struct sockaddr **addrs;
2805 socklen_t *addrlens; 2841 socklen_t *addrlens;
2806 2842
2807 res = server_get_addresses(plugin, 2843 res = server_get_addresses (plugin,
2808 plugin->name, 2844 plugin->name,
2809 plugin->env->cfg, 2845 plugin->env->cfg,
2810 &addrs, &addrlens); 2846 &addrs, &addrlens);
2811 LOG(GNUNET_ERROR_TYPE_DEBUG, 2847 LOG (GNUNET_ERROR_TYPE_DEBUG,
2812 _("Found %u addresses to report to NAT service\n"), 2848 _ ("Found %u addresses to report to NAT service\n"),
2813 res); 2849 res);
2814 2850
2815 if (GNUNET_SYSERR == res) 2851 if (GNUNET_SYSERR == res)
2816 { 2852 {
2817 plugin->nat = NULL; 2853 plugin->nat = NULL;
2818 return; 2854 return;
2819 } 2855 }
2820 2856
2821 plugin->nat 2857 plugin->nat
2822 = GNUNET_NAT_register(plugin->env->cfg, 2858 = GNUNET_NAT_register (plugin->env->cfg,
2823 "transport-http_server", 2859 "transport-http_server",
2824 IPPROTO_TCP, 2860 IPPROTO_TCP,
2825 (unsigned int)res, 2861 (unsigned int) res,
2826 (const struct sockaddr **)addrs, 2862 (const struct sockaddr **) addrs,
2827 addrlens, 2863 addrlens,
2828 &server_nat_port_map_callback, 2864 &server_nat_port_map_callback,
2829 NULL, 2865 NULL,
2830 plugin); 2866 plugin);
2831 while (res > 0) 2867 while (res > 0)
2832 { 2868 {
2833 res--; 2869 res--;
2834 GNUNET_assert(NULL != addrs[res]); 2870 GNUNET_assert (NULL != addrs[res]);
2835 GNUNET_free(addrs[res]); 2871 GNUNET_free (addrs[res]);
2836 } 2872 }
2837 GNUNET_free_non_null(addrs); 2873 GNUNET_free_non_null (addrs);
2838 GNUNET_free_non_null(addrlens); 2874 GNUNET_free_non_null (addrlens);
2839} 2875}
2840 2876
2841 2877
@@ -2845,26 +2881,26 @@ server_start_report_addresses(struct HTTP_Server_Plugin *plugin)
2845 * @param plugin the plugin handle 2881 * @param plugin the plugin handle
2846 */ 2882 */
2847static void 2883static void
2848server_stop_report_addresses(struct HTTP_Server_Plugin *plugin) 2884server_stop_report_addresses (struct HTTP_Server_Plugin *plugin)
2849{ 2885{
2850 struct HttpAddressWrapper *w; 2886 struct HttpAddressWrapper *w;
2851 2887
2852 /* Stop NAT handle */ 2888 /* Stop NAT handle */
2853 if (NULL != plugin->nat) 2889 if (NULL != plugin->nat)
2854 { 2890 {
2855 GNUNET_NAT_unregister(plugin->nat); 2891 GNUNET_NAT_unregister (plugin->nat);
2856 plugin->nat = NULL; 2892 plugin->nat = NULL;
2857 } 2893 }
2858 /* Clean up addresses */ 2894 /* Clean up addresses */
2859 while (NULL != plugin->addr_head) 2895 while (NULL != plugin->addr_head)
2860 { 2896 {
2861 w = plugin->addr_head; 2897 w = plugin->addr_head;
2862 GNUNET_CONTAINER_DLL_remove(plugin->addr_head, 2898 GNUNET_CONTAINER_DLL_remove (plugin->addr_head,
2863 plugin->addr_tail, 2899 plugin->addr_tail,
2864 w); 2900 w);
2865 GNUNET_free(w->address); 2901 GNUNET_free (w->address);
2866 GNUNET_free(w); 2902 GNUNET_free (w);
2867 } 2903 }
2868} 2904}
2869 2905
2870 2906
@@ -2875,39 +2911,39 @@ server_stop_report_addresses(struct HTTP_Server_Plugin *plugin)
2875 * @return #GNUNET_YES on success, else #GNUNET_NO 2911 * @return #GNUNET_YES on success, else #GNUNET_NO
2876 */ 2912 */
2877static int 2913static int
2878server_check_ipv6_support(struct HTTP_Server_Plugin *plugin) 2914server_check_ipv6_support (struct HTTP_Server_Plugin *plugin)
2879{ 2915{
2880 struct GNUNET_NETWORK_Handle *desc = NULL; 2916 struct GNUNET_NETWORK_Handle *desc = NULL;
2881 int res = GNUNET_NO; 2917 int res = GNUNET_NO;
2882 2918
2883 /* Probe IPv6 support */ 2919 /* Probe IPv6 support */
2884 desc = GNUNET_NETWORK_socket_create(PF_INET6, 2920 desc = GNUNET_NETWORK_socket_create (PF_INET6,
2885 SOCK_STREAM, 2921 SOCK_STREAM,
2886 0); 2922 0);
2887 if (NULL == desc) 2923 if (NULL == desc)
2888 { 2924 {
2889 if ((errno == ENOBUFS) || 2925 if ((errno == ENOBUFS) ||
2890 (errno == ENOMEM) || 2926 (errno == ENOMEM) ||
2891 (errno == ENFILE) || 2927 (errno == ENFILE) ||
2892 (errno == EACCES)) 2928 (errno == EACCES))
2893 { 2929 {
2894 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, 2930 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
2895 "socket"); 2931 "socket");
2896 } 2932 }
2897 LOG(GNUNET_ERROR_TYPE_WARNING, 2933 LOG (GNUNET_ERROR_TYPE_WARNING,
2898 _("Disabling IPv6 since it is not supported on this system!\n")); 2934 _ ("Disabling IPv6 since it is not supported on this system!\n"));
2899 res = GNUNET_NO; 2935 res = GNUNET_NO;
2900 } 2936 }
2901 else 2937 else
2902 { 2938 {
2903 GNUNET_break(GNUNET_OK == 2939 GNUNET_break (GNUNET_OK ==
2904 GNUNET_NETWORK_socket_close(desc)); 2940 GNUNET_NETWORK_socket_close (desc));
2905 desc = NULL; 2941 desc = NULL;
2906 res = GNUNET_YES; 2942 res = GNUNET_YES;
2907 } 2943 }
2908 LOG(GNUNET_ERROR_TYPE_DEBUG, 2944 LOG (GNUNET_ERROR_TYPE_DEBUG,
2909 "Testing IPv6 on this system: %s\n", 2945 "Testing IPv6 on this system: %s\n",
2910 (res == GNUNET_YES) ? "successful" : "failed"); 2946 (res == GNUNET_YES) ? "successful" : "failed");
2911 return res; 2947 return res;
2912} 2948}
2913 2949
@@ -2918,7 +2954,7 @@ server_check_ipv6_support(struct HTTP_Server_Plugin *plugin)
2918 * @param cls plugin 2954 * @param cls plugin
2919 */ 2955 */
2920static void 2956static void
2921server_notify_external_hostname(void *cls) 2957server_notify_external_hostname (void *cls)
2922{ 2958{
2923 struct HTTP_Server_Plugin *plugin = cls; 2959 struct HTTP_Server_Plugin *plugin = cls;
2924 struct HttpAddress *ext_addr; 2960 struct HttpAddress *ext_addr;
@@ -2927,48 +2963,48 @@ server_notify_external_hostname(void *cls)
2927 char *url; 2963 char *url;
2928 2964
2929 plugin->notify_ext_task = NULL; 2965 plugin->notify_ext_task = NULL;
2930 GNUNET_asprintf(&url, 2966 GNUNET_asprintf (&url,
2931 "%s://%s", 2967 "%s://%s",
2932 plugin->protocol, 2968 plugin->protocol,
2933 plugin->external_hostname); 2969 plugin->external_hostname);
2934 urlen = strlen(url) + 1; 2970 urlen = strlen (url) + 1;
2935 ext_addr = GNUNET_malloc(sizeof(struct HttpAddress) + urlen); 2971 ext_addr = GNUNET_malloc (sizeof(struct HttpAddress) + urlen);
2936 ext_addr->options = htonl(plugin->options); 2972 ext_addr->options = htonl (plugin->options);
2937 ext_addr->urlen = htonl(urlen); 2973 ext_addr->urlen = htonl (urlen);
2938 ext_addr_len = sizeof(struct HttpAddress) + urlen; 2974 ext_addr_len = sizeof(struct HttpAddress) + urlen;
2939 GNUNET_memcpy(&ext_addr[1], url, urlen); 2975 GNUNET_memcpy (&ext_addr[1], url, urlen);
2940 GNUNET_free(url); 2976 GNUNET_free (url);
2941 2977
2942 LOG(GNUNET_ERROR_TYPE_DEBUG, 2978 LOG (GNUNET_ERROR_TYPE_DEBUG,
2943 "Notifying transport about external hostname address `%s'\n", 2979 "Notifying transport about external hostname address `%s'\n",
2944 plugin->external_hostname); 2980 plugin->external_hostname);
2945 2981
2946#if BUILD_HTTPS 2982#if BUILD_HTTPS
2947 if (GNUNET_YES == plugin->verify_external_hostname) 2983 if (GNUNET_YES == plugin->verify_external_hostname)
2948 LOG(GNUNET_ERROR_TYPE_INFO, 2984 LOG (GNUNET_ERROR_TYPE_INFO,
2949 "Enabling SSL verification for external hostname address `%s'\n", 2985 "Enabling SSL verification for external hostname address `%s'\n",
2950 plugin->external_hostname); 2986 plugin->external_hostname);
2951 plugin->ext_addr 2987 plugin->ext_addr
2952 = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 2988 = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2953 "https_client", 2989 "https_client",
2954 ext_addr, 2990 ext_addr,
2955 ext_addr_len, 2991 ext_addr_len,
2956 GNUNET_HELLO_ADDRESS_INFO_NONE); 2992 GNUNET_HELLO_ADDRESS_INFO_NONE);
2957 plugin->env->notify_address(plugin->env->cls, 2993 plugin->env->notify_address (plugin->env->cls,
2958 GNUNET_YES, 2994 GNUNET_YES,
2959 plugin->ext_addr); 2995 plugin->ext_addr);
2960 GNUNET_free(ext_addr); 2996 GNUNET_free (ext_addr);
2961#else 2997#else
2962 plugin->ext_addr 2998 plugin->ext_addr
2963 = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 2999 = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2964 "http_client", 3000 "http_client",
2965 ext_addr, 3001 ext_addr,
2966 ext_addr_len, 3002 ext_addr_len,
2967 GNUNET_HELLO_ADDRESS_INFO_NONE); 3003 GNUNET_HELLO_ADDRESS_INFO_NONE);
2968 plugin->env->notify_address(plugin->env->cls, 3004 plugin->env->notify_address (plugin->env->cls,
2969 GNUNET_YES, 3005 GNUNET_YES,
2970 plugin->ext_addr); 3006 plugin->ext_addr);
2971 GNUNET_free(ext_addr); 3007 GNUNET_free (ext_addr);
2972#endif 3008#endif
2973} 3009}
2974 3010
@@ -2980,7 +3016,7 @@ server_notify_external_hostname(void *cls)
2980 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 3016 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2981 */ 3017 */
2982static int 3018static int
2983server_configure_plugin(struct HTTP_Server_Plugin *plugin) 3019server_configure_plugin (struct HTTP_Server_Plugin *plugin)
2984{ 3020{
2985 unsigned long long port; 3021 unsigned long long port;
2986 unsigned long long max_connections; 3022 unsigned long long max_connections;
@@ -2992,224 +3028,225 @@ server_configure_plugin(struct HTTP_Server_Plugin *plugin)
2992 /* Use IPv4? */ 3028 /* Use IPv4? */
2993 if (GNUNET_CONFIGURATION_have_value 3029 if (GNUNET_CONFIGURATION_have_value
2994 (plugin->env->cfg, plugin->name, "USE_IPv4")) 3030 (plugin->env->cfg, plugin->name, "USE_IPv4"))
2995 { 3031 {
2996 plugin->use_ipv4 = 3032 plugin->use_ipv4 =
2997 GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 3033 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
2998 plugin->name, 3034 plugin->name,
2999 "USE_IPv4"); 3035 "USE_IPv4");
3000 } 3036 }
3001 else 3037 else
3002 plugin->use_ipv4 = GNUNET_YES; 3038 plugin->use_ipv4 = GNUNET_YES;
3003 LOG(GNUNET_ERROR_TYPE_DEBUG, 3039 LOG (GNUNET_ERROR_TYPE_DEBUG,
3004 _("IPv4 support is %s\n"), 3040 _ ("IPv4 support is %s\n"),
3005 (plugin->use_ipv4 == GNUNET_YES) ? "enabled" : "disabled"); 3041 (plugin->use_ipv4 == GNUNET_YES) ? "enabled" : "disabled");
3006 3042
3007 /* Use IPv6? */ 3043 /* Use IPv6? */
3008 if (GNUNET_CONFIGURATION_have_value 3044 if (GNUNET_CONFIGURATION_have_value
3009 (plugin->env->cfg, plugin->name, "USE_IPv6")) 3045 (plugin->env->cfg, plugin->name, "USE_IPv6"))
3010 { 3046 {
3011 plugin->use_ipv6 = 3047 plugin->use_ipv6 =
3012 GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 3048 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
3013 plugin->name, 3049 plugin->name,
3014 "USE_IPv6"); 3050 "USE_IPv6");
3015 } 3051 }
3016 else 3052 else
3017 plugin->use_ipv6 = GNUNET_YES; 3053 plugin->use_ipv6 = GNUNET_YES;
3018 LOG(GNUNET_ERROR_TYPE_DEBUG, 3054 LOG (GNUNET_ERROR_TYPE_DEBUG,
3019 _("IPv6 support is %s\n"), 3055 _ ("IPv6 support is %s\n"),
3020 (plugin->use_ipv6 == GNUNET_YES) ? "enabled" : "disabled"); 3056 (plugin->use_ipv6 == GNUNET_YES) ? "enabled" : "disabled");
3021 3057
3022 if ((plugin->use_ipv4 == GNUNET_NO) && (plugin->use_ipv6 == GNUNET_NO)) 3058 if ((plugin->use_ipv4 == GNUNET_NO) && (plugin->use_ipv6 == GNUNET_NO))
3023 { 3059 {
3024 LOG(GNUNET_ERROR_TYPE_ERROR, 3060 LOG (GNUNET_ERROR_TYPE_ERROR,
3025 _("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n")); 3061 _ ("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n"));
3026 return GNUNET_SYSERR; 3062 return GNUNET_SYSERR;
3027 } 3063 }
3028 3064
3029 /* Reading port number from config file */ 3065 /* Reading port number from config file */
3030 if ((GNUNET_OK != 3066 if ((GNUNET_OK !=
3031 GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg, 3067 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
3032 plugin->name, 3068 plugin->name,
3033 "PORT", &port)) || (port > 65535)) 3069 "PORT", &port)) || (port > 65535))
3034 { 3070 {
3035 LOG(GNUNET_ERROR_TYPE_ERROR, 3071 LOG (GNUNET_ERROR_TYPE_ERROR,
3036 _("Port is required! Fix in configuration\n")); 3072 _ ("Port is required! Fix in configuration\n"));
3037 return GNUNET_SYSERR; 3073 return GNUNET_SYSERR;
3038 } 3074 }
3039 plugin->port = port; 3075 plugin->port = port;
3040 3076
3041 LOG(GNUNET_ERROR_TYPE_INFO, 3077 LOG (GNUNET_ERROR_TYPE_INFO,
3042 _("Using port %u\n"), plugin->port); 3078 _ ("Using port %u\n"), plugin->port);
3043 3079
3044 if ((plugin->use_ipv4 == GNUNET_YES) && 3080 if ((plugin->use_ipv4 == GNUNET_YES) &&
3045 (GNUNET_YES == 3081 (GNUNET_YES ==
3046 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, 3082 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
3047 plugin->name, 3083 plugin->name,
3048 "BINDTO", 3084 "BINDTO",
3049 &bind4_address))) 3085 &bind4_address)))
3086 {
3087 LOG (GNUNET_ERROR_TYPE_DEBUG,
3088 "Binding %s plugin to specific IPv4 address: `%s'\n",
3089 plugin->protocol,
3090 bind4_address);
3091 plugin->server_addr_v4 = GNUNET_new (struct sockaddr_in);
3092 if (1 != inet_pton (AF_INET,
3093 bind4_address,
3094 &plugin->server_addr_v4->sin_addr))
3095 {
3096 LOG (GNUNET_ERROR_TYPE_ERROR,
3097 _ ("Specific IPv4 address `%s' in configuration file is invalid!\n"),
3098 bind4_address);
3099 GNUNET_free (bind4_address);
3100 GNUNET_free (plugin->server_addr_v4);
3101 plugin->server_addr_v4 = NULL;
3102 return GNUNET_SYSERR;
3103 }
3104 else
3050 { 3105 {
3051 LOG(GNUNET_ERROR_TYPE_DEBUG, 3106 LOG (GNUNET_ERROR_TYPE_DEBUG,
3052 "Binding %s plugin to specific IPv4 address: `%s'\n", 3107 "Binding to IPv4 address %s\n",
3053 plugin->protocol, 3108 bind4_address);
3054 bind4_address); 3109 plugin->server_addr_v4->sin_family = AF_INET;
3055 plugin->server_addr_v4 = GNUNET_new(struct sockaddr_in); 3110 plugin->server_addr_v4->sin_port = htons (plugin->port);
3056 if (1 != inet_pton(AF_INET,
3057 bind4_address,
3058 &plugin->server_addr_v4->sin_addr))
3059 {
3060 LOG(GNUNET_ERROR_TYPE_ERROR,
3061 _("Specific IPv4 address `%s' in configuration file is invalid!\n"),
3062 bind4_address);
3063 GNUNET_free(bind4_address);
3064 GNUNET_free(plugin->server_addr_v4);
3065 plugin->server_addr_v4 = NULL;
3066 return GNUNET_SYSERR;
3067 }
3068 else
3069 {
3070 LOG(GNUNET_ERROR_TYPE_DEBUG,
3071 "Binding to IPv4 address %s\n",
3072 bind4_address);
3073 plugin->server_addr_v4->sin_family = AF_INET;
3074 plugin->server_addr_v4->sin_port = htons(plugin->port);
3075 }
3076 GNUNET_free(bind4_address);
3077 } 3111 }
3112 GNUNET_free (bind4_address);
3113 }
3078 3114
3079 if ((plugin->use_ipv6 == GNUNET_YES) && 3115 if ((plugin->use_ipv6 == GNUNET_YES) &&
3080 (GNUNET_YES == 3116 (GNUNET_YES ==
3081 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, 3117 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
3082 plugin->name, 3118 plugin->name,
3083 "BINDTO6", 3119 "BINDTO6",
3084 &bind6_address))) 3120 &bind6_address)))
3121 {
3122 LOG (GNUNET_ERROR_TYPE_DEBUG,
3123 "Binding %s plugin to specific IPv6 address: `%s'\n",
3124 plugin->protocol, bind6_address);
3125 plugin->server_addr_v6 = GNUNET_new (struct sockaddr_in6);
3126 if (1 !=
3127 inet_pton (AF_INET6,
3128 bind6_address,
3129 &plugin->server_addr_v6->sin6_addr))
3130 {
3131 LOG (GNUNET_ERROR_TYPE_ERROR,
3132 _ ("Specific IPv6 address `%s' in configuration file is invalid!\n"),
3133 bind6_address);
3134 GNUNET_free (bind6_address);
3135 GNUNET_free (plugin->server_addr_v6);
3136 plugin->server_addr_v6 = NULL;
3137 return GNUNET_SYSERR;
3138 }
3139 else
3085 { 3140 {
3086 LOG(GNUNET_ERROR_TYPE_DEBUG, 3141 LOG (GNUNET_ERROR_TYPE_DEBUG,
3087 "Binding %s plugin to specific IPv6 address: `%s'\n", 3142 "Binding to IPv6 address %s\n",
3088 plugin->protocol, bind6_address); 3143 bind6_address);
3089 plugin->server_addr_v6 = GNUNET_new(struct sockaddr_in6); 3144 plugin->server_addr_v6->sin6_family = AF_INET6;
3090 if (1 != 3145 plugin->server_addr_v6->sin6_port = htons (plugin->port);
3091 inet_pton(AF_INET6,
3092 bind6_address,
3093 &plugin->server_addr_v6->sin6_addr))
3094 {
3095 LOG(GNUNET_ERROR_TYPE_ERROR,
3096 _("Specific IPv6 address `%s' in configuration file is invalid!\n"),
3097 bind6_address);
3098 GNUNET_free(bind6_address);
3099 GNUNET_free(plugin->server_addr_v6);
3100 plugin->server_addr_v6 = NULL;
3101 return GNUNET_SYSERR;
3102 }
3103 else
3104 {
3105 LOG(GNUNET_ERROR_TYPE_DEBUG,
3106 "Binding to IPv6 address %s\n",
3107 bind6_address);
3108 plugin->server_addr_v6->sin6_family = AF_INET6;
3109 plugin->server_addr_v6->sin6_port = htons(plugin->port);
3110 }
3111 GNUNET_free(bind6_address);
3112 } 3146 }
3147 GNUNET_free (bind6_address);
3148 }
3113 3149
3114 plugin->verify_external_hostname = GNUNET_NO; 3150 plugin->verify_external_hostname = GNUNET_NO;
3115#if BUILD_HTTPS 3151#if BUILD_HTTPS
3116 plugin->verify_external_hostname 3152 plugin->verify_external_hostname
3117 = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 3153 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
3118 plugin->name, 3154 plugin->name,
3119 "VERIFY_EXTERNAL_HOSTNAME"); 3155 "VERIFY_EXTERNAL_HOSTNAME");
3120 if (GNUNET_SYSERR == plugin->verify_external_hostname) 3156 if (GNUNET_SYSERR == plugin->verify_external_hostname)
3121 plugin->verify_external_hostname = GNUNET_NO; 3157 plugin->verify_external_hostname = GNUNET_NO;
3122 if (GNUNET_YES == plugin->verify_external_hostname) 3158 if (GNUNET_YES == plugin->verify_external_hostname)
3123 plugin->options |= HTTP_OPTIONS_VERIFY_CERTIFICATE; 3159 plugin->options |= HTTP_OPTIONS_VERIFY_CERTIFICATE;
3124#endif 3160#endif
3125 external_hostname_use_port 3161 external_hostname_use_port
3126 = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 3162 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
3127 plugin->name, 3163 plugin->name,
3128 "EXTERNAL_HOSTNAME_USE_PORT"); 3164 "EXTERNAL_HOSTNAME_USE_PORT");
3129 if (GNUNET_SYSERR == external_hostname_use_port) 3165 if (GNUNET_SYSERR == external_hostname_use_port)
3130 external_hostname_use_port = GNUNET_NO; 3166 external_hostname_use_port = GNUNET_NO;
3131 3167
3132 3168
3133 if (GNUNET_YES == 3169 if (GNUNET_YES ==
3134 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, 3170 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
3135 plugin->name, 3171 plugin->name,
3136 "EXTERNAL_HOSTNAME", 3172 "EXTERNAL_HOSTNAME",
3137 &eh_tmp)) 3173 &eh_tmp))
3138 { 3174 {
3139 char *tmp; 3175 char *tmp;
3140 char *pos = NULL; 3176 char *pos = NULL;
3141 char *pos_url = NULL; 3177 char *pos_url = NULL;
3142 3178
3143 if (NULL != strstr(eh_tmp, "://")) 3179 if (NULL != strstr (eh_tmp, "://"))
3144 tmp = &strstr(eh_tmp, "://")[3]; 3180 tmp = &strstr (eh_tmp, "://")[3];
3145 else 3181 else
3146 tmp = eh_tmp; 3182 tmp = eh_tmp;
3147 3183
3148 if (GNUNET_YES == external_hostname_use_port) 3184 if (GNUNET_YES == external_hostname_use_port)
3149 { 3185 {
3150 if ((strlen(tmp) > 1) && (NULL != (pos = strchr(tmp, '/')))) 3186 if ((strlen (tmp) > 1) && (NULL != (pos = strchr (tmp, '/'))))
3151 { 3187 {
3152 pos_url = pos + 1; 3188 pos_url = pos + 1;
3153 pos[0] = '\0'; 3189 pos[0] = '\0';
3154 GNUNET_asprintf(&plugin->external_hostname, 3190 GNUNET_asprintf (&plugin->external_hostname,
3155 "%s:%u/%s", 3191 "%s:%u/%s",
3156 tmp, 3192 tmp,
3157 (uint16_t)port, 3193 (uint16_t) port,
3158 pos_url); 3194 pos_url);
3159 } 3195 }
3160 else
3161 GNUNET_asprintf(&plugin->external_hostname,
3162 "%s:%u",
3163 tmp,
3164 (uint16_t)port);
3165 }
3166 else
3167 plugin->external_hostname = GNUNET_strdup(tmp);
3168 GNUNET_free(eh_tmp);
3169
3170 LOG(GNUNET_ERROR_TYPE_INFO,
3171 _("Using external hostname `%s'\n"),
3172 plugin->external_hostname);
3173 plugin->notify_ext_task = GNUNET_SCHEDULER_add_now(&server_notify_external_hostname,
3174 plugin);
3175
3176 /* Use only configured external hostname */
3177 if (GNUNET_CONFIGURATION_have_value
3178 (plugin->env->cfg,
3179 plugin->name,
3180 "EXTERNAL_HOSTNAME_ONLY"))
3181 {
3182 plugin->external_only =
3183 GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg,
3184 plugin->name,
3185 "EXTERNAL_HOSTNAME_ONLY");
3186 }
3187 else 3196 else
3188 plugin->external_only = GNUNET_NO; 3197 GNUNET_asprintf (&plugin->external_hostname,
3189 3198 "%s:%u",
3190 if (GNUNET_YES == plugin->external_only) 3199 tmp,
3191 LOG(GNUNET_ERROR_TYPE_DEBUG, 3200 (uint16_t) port);
3192 _("Notifying transport only about hostname `%s'\n"), 3201 }
3193 plugin->external_hostname); 3202 else
3203 plugin->external_hostname = GNUNET_strdup (tmp);
3204 GNUNET_free (eh_tmp);
3205
3206 LOG (GNUNET_ERROR_TYPE_INFO,
3207 _ ("Using external hostname `%s'\n"),
3208 plugin->external_hostname);
3209 plugin->notify_ext_task = GNUNET_SCHEDULER_add_now (
3210 &server_notify_external_hostname,
3211 plugin);
3212
3213 /* Use only configured external hostname */
3214 if (GNUNET_CONFIGURATION_have_value
3215 (plugin->env->cfg,
3216 plugin->name,
3217 "EXTERNAL_HOSTNAME_ONLY"))
3218 {
3219 plugin->external_only =
3220 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
3221 plugin->name,
3222 "EXTERNAL_HOSTNAME_ONLY");
3194 } 3223 }
3224 else
3225 plugin->external_only = GNUNET_NO;
3226
3227 if (GNUNET_YES == plugin->external_only)
3228 LOG (GNUNET_ERROR_TYPE_DEBUG,
3229 _ ("Notifying transport only about hostname `%s'\n"),
3230 plugin->external_hostname);
3231 }
3195 else 3232 else
3196 LOG(GNUNET_ERROR_TYPE_DEBUG, 3233 LOG (GNUNET_ERROR_TYPE_DEBUG,
3197 "No external hostname configured\n"); 3234 "No external hostname configured\n");
3198 3235
3199 /* Optional parameters */ 3236 /* Optional parameters */
3200 if (GNUNET_OK != 3237 if (GNUNET_OK !=
3201 GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg, 3238 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
3202 plugin->name, 3239 plugin->name,
3203 "MAX_CONNECTIONS", 3240 "MAX_CONNECTIONS",
3204 &max_connections)) 3241 &max_connections))
3205 max_connections = 128; 3242 max_connections = 128;
3206 plugin->max_request = max_connections; 3243 plugin->max_request = max_connections;
3207 3244
3208 LOG(GNUNET_ERROR_TYPE_DEBUG, 3245 LOG (GNUNET_ERROR_TYPE_DEBUG,
3209 _("Maximum number of connections is %u\n"), 3246 _ ("Maximum number of connections is %u\n"),
3210 plugin->max_request); 3247 plugin->max_request);
3211 3248
3212 plugin->peer_id_length = strlen(GNUNET_i2s_full(plugin->env->my_identity)); 3249 plugin->peer_id_length = strlen (GNUNET_i2s_full (plugin->env->my_identity));
3213 3250
3214 return GNUNET_OK; 3251 return GNUNET_OK;
3215} 3252}
@@ -3222,94 +3259,94 @@ server_configure_plugin(struct HTTP_Server_Plugin *plugin)
3222 * @return NULL 3259 * @return NULL
3223 */ 3260 */
3224void * 3261void *
3225LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) 3262LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
3226{ 3263{
3227 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3264 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3228 struct HTTP_Server_Plugin *plugin = api->cls; 3265 struct HTTP_Server_Plugin *plugin = api->cls;
3229 3266
3230 if (NULL == api->cls) 3267 if (NULL == api->cls)
3231 { 3268 {
3232 /* Free for stub mode */ 3269 /* Free for stub mode */
3233 GNUNET_free(api); 3270 GNUNET_free (api);
3234 return NULL; 3271 return NULL;
3235 } 3272 }
3236 plugin->in_shutdown = GNUNET_YES; 3273 plugin->in_shutdown = GNUNET_YES;
3237 LOG(GNUNET_ERROR_TYPE_INFO, 3274 LOG (GNUNET_ERROR_TYPE_INFO,
3238 _("Shutting down plugin `%s'\n"), 3275 _ ("Shutting down plugin `%s'\n"),
3239 plugin->name); 3276 plugin->name);
3240 3277
3241 if (NULL != plugin->notify_ext_task) 3278 if (NULL != plugin->notify_ext_task)
3242 { 3279 {
3243 GNUNET_SCHEDULER_cancel(plugin->notify_ext_task); 3280 GNUNET_SCHEDULER_cancel (plugin->notify_ext_task);
3244 plugin->notify_ext_task = NULL; 3281 plugin->notify_ext_task = NULL;
3245 } 3282 }
3246 3283
3247 if (NULL != plugin->ext_addr) 3284 if (NULL != plugin->ext_addr)
3248 { 3285 {
3249 LOG(GNUNET_ERROR_TYPE_DEBUG, 3286 LOG (GNUNET_ERROR_TYPE_DEBUG,
3250 "Notifying transport to remove address `%s'\n", 3287 "Notifying transport to remove address `%s'\n",
3251 http_common_plugin_address_to_string(plugin->protocol, 3288 http_common_plugin_address_to_string (plugin->protocol,
3252 plugin->ext_addr->address, 3289 plugin->ext_addr->address,
3253 plugin->ext_addr->address_length)); 3290 plugin->ext_addr->address_length));
3254#if BUILD_HTTPS 3291#if BUILD_HTTPS
3255 plugin->env->notify_address(plugin->env->cls, 3292 plugin->env->notify_address (plugin->env->cls,
3256 GNUNET_NO, 3293 GNUNET_NO,
3257 plugin->ext_addr); 3294 plugin->ext_addr);
3258#else 3295#else
3259 plugin->env->notify_address(plugin->env->cls, 3296 plugin->env->notify_address (plugin->env->cls,
3260 GNUNET_NO, 3297 GNUNET_NO,
3261 plugin->ext_addr); 3298 plugin->ext_addr);
3262#endif 3299#endif
3263 GNUNET_HELLO_address_free(plugin->ext_addr); 3300 GNUNET_HELLO_address_free (plugin->ext_addr);
3264 plugin->ext_addr = NULL; 3301 plugin->ext_addr = NULL;
3265 } 3302 }
3266 3303
3267 /* Stop to report addresses to transport service */ 3304 /* Stop to report addresses to transport service */
3268 server_stop_report_addresses(plugin); 3305 server_stop_report_addresses (plugin);
3269 if (NULL != plugin->server_v4_task) 3306 if (NULL != plugin->server_v4_task)
3270 { 3307 {
3271 GNUNET_SCHEDULER_cancel(plugin->server_v4_task); 3308 GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
3272 plugin->server_v4_task = NULL; 3309 plugin->server_v4_task = NULL;
3273 } 3310 }
3274 3311
3275 if (NULL != plugin->server_v6_task) 3312 if (NULL != plugin->server_v6_task)
3276 { 3313 {
3277 GNUNET_SCHEDULER_cancel(plugin->server_v6_task); 3314 GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
3278 plugin->server_v6_task = NULL; 3315 plugin->server_v6_task = NULL;
3279 } 3316 }
3280#if BUILD_HTTPS 3317#if BUILD_HTTPS
3281 GNUNET_free_non_null(plugin->crypto_init); 3318 GNUNET_free_non_null (plugin->crypto_init);
3282 GNUNET_free_non_null(plugin->cert); 3319 GNUNET_free_non_null (plugin->cert);
3283 GNUNET_free_non_null(plugin->key); 3320 GNUNET_free_non_null (plugin->key);
3284#endif 3321#endif
3285 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, 3322 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
3286 &destroy_session_shutdown_cb, 3323 &destroy_session_shutdown_cb,
3287 plugin); 3324 plugin);
3288 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions); 3325 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions);
3289 plugin->sessions = NULL; 3326 plugin->sessions = NULL;
3290 if (NULL != plugin->server_v4) 3327 if (NULL != plugin->server_v4)
3291 { 3328 {
3292 MHD_stop_daemon(plugin->server_v4); 3329 MHD_stop_daemon (plugin->server_v4);
3293 plugin->server_v4 = NULL; 3330 plugin->server_v4 = NULL;
3294 } 3331 }
3295 if (NULL != plugin->server_v6) 3332 if (NULL != plugin->server_v6)
3296 { 3333 {
3297 MHD_stop_daemon(plugin->server_v6); 3334 MHD_stop_daemon (plugin->server_v6);
3298 plugin->server_v6 = NULL; 3335 plugin->server_v6 = NULL;
3299 } 3336 }
3300 /* Clean up */ 3337 /* Clean up */
3301 GNUNET_free_non_null(plugin->external_hostname); 3338 GNUNET_free_non_null (plugin->external_hostname);
3302 GNUNET_free_non_null(plugin->ext_addr); 3339 GNUNET_free_non_null (plugin->ext_addr);
3303 GNUNET_free_non_null(plugin->server_addr_v4); 3340 GNUNET_free_non_null (plugin->server_addr_v4);
3304 GNUNET_free_non_null(plugin->server_addr_v6); 3341 GNUNET_free_non_null (plugin->server_addr_v6);
3305 regfree(&plugin->url_regex); 3342 regfree (&plugin->url_regex);
3306 3343
3307 LOG(GNUNET_ERROR_TYPE_DEBUG, 3344 LOG (GNUNET_ERROR_TYPE_DEBUG,
3308 _("Shutdown for plugin `%s' complete\n"), 3345 _ ("Shutdown for plugin `%s' complete\n"),
3309 plugin->name); 3346 plugin->name);
3310 3347
3311 GNUNET_free(plugin); 3348 GNUNET_free (plugin);
3312 GNUNET_free(api); 3349 GNUNET_free (api);
3313 return NULL; 3350 return NULL;
3314} 3351}
3315 3352
@@ -3326,13 +3363,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls)
3326 * @return string representing the same address 3363 * @return string representing the same address
3327 */ 3364 */
3328static const char * 3365static const char *
3329http_server_plugin_address_to_string(void *cls, 3366http_server_plugin_address_to_string (void *cls,
3330 const void *addr, 3367 const void *addr,
3331 size_t addrlen) 3368 size_t addrlen)
3332{ 3369{
3333 return http_common_plugin_address_to_string(PLUGIN_NAME, 3370 return http_common_plugin_address_to_string (PLUGIN_NAME,
3334 addr, 3371 addr,
3335 addrlen); 3372 addrlen);
3336} 3373}
3337 3374
3338 3375
@@ -3344,8 +3381,8 @@ http_server_plugin_address_to_string(void *cls,
3344 * @return the network type in HBO or #GNUNET_SYSERR 3381 * @return the network type in HBO or #GNUNET_SYSERR
3345 */ 3382 */
3346static enum GNUNET_NetworkType 3383static enum GNUNET_NetworkType
3347http_server_plugin_get_network(void *cls, 3384http_server_plugin_get_network (void *cls,
3348 struct GNUNET_ATS_Session *session) 3385 struct GNUNET_ATS_Session *session)
3349{ 3386{
3350 return session->scope; 3387 return session->scope;
3351} 3388}
@@ -3359,13 +3396,14 @@ http_server_plugin_get_network(void *cls,
3359 * @return the network type 3396 * @return the network type
3360 */ 3397 */
3361static enum GNUNET_NetworkType 3398static enum GNUNET_NetworkType
3362http_server_plugin_get_network_for_address(void *cls, 3399http_server_plugin_get_network_for_address (void *cls,
3363 const struct GNUNET_HELLO_Address *address) 3400 const struct
3401 GNUNET_HELLO_Address *address)
3364{ 3402{
3365 struct HTTP_Server_Plugin *plugin = cls; 3403 struct HTTP_Server_Plugin *plugin = cls;
3366 3404
3367 return http_common_get_network_for_address(plugin->env, 3405 return http_common_get_network_for_address (plugin->env,
3368 address); 3406 address);
3369} 3407}
3370 3408
3371 3409
@@ -3380,24 +3418,24 @@ http_server_plugin_get_network_for_address(void *cls,
3380 * @param delay new delay to use for receiving 3418 * @param delay new delay to use for receiving
3381 */ 3419 */
3382static void 3420static void
3383http_server_plugin_update_inbound_delay(void *cls, 3421http_server_plugin_update_inbound_delay (void *cls,
3384 const struct GNUNET_PeerIdentity *peer, 3422 const struct GNUNET_PeerIdentity *peer,
3385 struct GNUNET_ATS_Session *session, 3423 struct GNUNET_ATS_Session *session,
3386 struct GNUNET_TIME_Relative delay) 3424 struct GNUNET_TIME_Relative delay)
3387{ 3425{
3388 session->next_receive = GNUNET_TIME_relative_to_absolute(delay); 3426 session->next_receive = GNUNET_TIME_relative_to_absolute (delay);
3389 LOG(GNUNET_ERROR_TYPE_DEBUG, 3427 LOG (GNUNET_ERROR_TYPE_DEBUG,
3390 "New inbound delay %s\n", 3428 "New inbound delay %s\n",
3391 GNUNET_STRINGS_relative_time_to_string(delay, 3429 GNUNET_STRINGS_relative_time_to_string (delay,
3392 GNUNET_NO)); 3430 GNUNET_NO));
3393 if (NULL != session->recv_wakeup_task) 3431 if (NULL != session->recv_wakeup_task)
3394 { 3432 {
3395 GNUNET_SCHEDULER_cancel(session->recv_wakeup_task); 3433 GNUNET_SCHEDULER_cancel (session->recv_wakeup_task);
3396 session->recv_wakeup_task 3434 session->recv_wakeup_task
3397 = GNUNET_SCHEDULER_add_delayed(delay, 3435 = GNUNET_SCHEDULER_add_delayed (delay,
3398 &server_wake_up, 3436 &server_wake_up,
3399 session); 3437 session);
3400 } 3438 }
3401} 3439}
3402 3440
3403 3441
@@ -3411,16 +3449,16 @@ http_server_plugin_update_inbound_delay(void *cls,
3411 * @return #GNUNET_OK (continue to iterate) 3449 * @return #GNUNET_OK (continue to iterate)
3412 */ 3450 */
3413static int 3451static int
3414send_session_info_iter(void *cls, 3452send_session_info_iter (void *cls,
3415 const struct GNUNET_PeerIdentity *peer, 3453 const struct GNUNET_PeerIdentity *peer,
3416 void *value) 3454 void *value)
3417{ 3455{
3418 struct HTTP_Server_Plugin *plugin = cls; 3456 struct HTTP_Server_Plugin *plugin = cls;
3419 struct GNUNET_ATS_Session *session = value; 3457 struct GNUNET_ATS_Session *session = value;
3420 3458
3421 notify_session_monitor(plugin, 3459 notify_session_monitor (plugin,
3422 session, 3460 session,
3423 GNUNET_TRANSPORT_SS_INIT); 3461 GNUNET_TRANSPORT_SS_INIT);
3424 return GNUNET_OK; 3462 return GNUNET_OK;
3425} 3463}
3426 3464
@@ -3438,22 +3476,22 @@ send_session_info_iter(void *cls,
3438 * @param sic_cls closure for @a sic 3476 * @param sic_cls closure for @a sic
3439 */ 3477 */
3440static void 3478static void
3441http_server_plugin_setup_monitor(void *cls, 3479http_server_plugin_setup_monitor (void *cls,
3442 GNUNET_TRANSPORT_SessionInfoCallback sic, 3480 GNUNET_TRANSPORT_SessionInfoCallback sic,
3443 void *sic_cls) 3481 void *sic_cls)
3444{ 3482{
3445 struct HTTP_Server_Plugin *plugin = cls; 3483 struct HTTP_Server_Plugin *plugin = cls;
3446 3484
3447 plugin->sic = sic; 3485 plugin->sic = sic;
3448 plugin->sic_cls = sic_cls; 3486 plugin->sic_cls = sic_cls;
3449 if (NULL != sic) 3487 if (NULL != sic)
3450 { 3488 {
3451 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, 3489 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
3452 &send_session_info_iter, 3490 &send_session_info_iter,
3453 plugin); 3491 plugin);
3454 /* signal end of first iteration */ 3492 /* signal end of first iteration */
3455 sic(sic_cls, NULL, NULL); 3493 sic (sic_cls, NULL, NULL);
3456 } 3494 }
3457} 3495}
3458 3496
3459 3497
@@ -3464,29 +3502,29 @@ http_server_plugin_setup_monitor(void *cls,
3464 * @return api 3502 * @return api
3465 */ 3503 */
3466void * 3504void *
3467LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) 3505LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3468{ 3506{
3469 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 3507 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3470 struct GNUNET_TRANSPORT_PluginFunctions *api; 3508 struct GNUNET_TRANSPORT_PluginFunctions *api;
3471 struct HTTP_Server_Plugin *plugin; 3509 struct HTTP_Server_Plugin *plugin;
3472 3510
3473 if (NULL == env->receive) 3511 if (NULL == env->receive)
3474 { 3512 {
3475 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 3513 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
3476 initialze the plugin or the API */ 3514 initialze the plugin or the API */
3477 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 3515 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
3478 api->cls = NULL; 3516 api->cls = NULL;
3479 api->address_to_string = &http_server_plugin_address_to_string; 3517 api->address_to_string = &http_server_plugin_address_to_string;
3480 api->string_to_address = &http_common_plugin_string_to_address; 3518 api->string_to_address = &http_common_plugin_string_to_address;
3481 api->address_pretty_printer = &http_common_plugin_address_pretty_printer; 3519 api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
3482 return api; 3520 return api;
3483 } 3521 }
3484 plugin = GNUNET_new(struct HTTP_Server_Plugin); 3522 plugin = GNUNET_new (struct HTTP_Server_Plugin);
3485 plugin->env = env; 3523 plugin->env = env;
3486 plugin->sessions = GNUNET_CONTAINER_multipeermap_create(128, 3524 plugin->sessions = GNUNET_CONTAINER_multipeermap_create (128,
3487 GNUNET_YES); 3525 GNUNET_YES);
3488 3526
3489 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 3527 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
3490 api->cls = plugin; 3528 api->cls = plugin;
3491 api->send = &http_server_plugin_send; 3529 api->send = &http_server_plugin_send;
3492 api->disconnect_peer = &http_server_plugin_disconnect_peer; 3530 api->disconnect_peer = &http_server_plugin_disconnect_peer;
@@ -3512,51 +3550,51 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls)
3512#endif 3550#endif
3513 3551
3514 if (GNUNET_YES == 3552 if (GNUNET_YES ==
3515 GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 3553 GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3516 plugin->name, 3554 plugin->name,
3517 "TCP_STEALTH")) 3555 "TCP_STEALTH"))
3518 { 3556 {
3519#ifdef TCP_STEALTH 3557#ifdef TCP_STEALTH
3520 plugin->options |= HTTP_OPTIONS_TCP_STEALTH; 3558 plugin->options |= HTTP_OPTIONS_TCP_STEALTH;
3521#else 3559#else
3522 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3560 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3523 _("TCP_STEALTH not supported on this platform.\n")); 3561 _ ("TCP_STEALTH not supported on this platform.\n"));
3524 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); 3562 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3525 return NULL; 3563 return NULL;
3526#endif 3564#endif
3527 } 3565 }
3528 3566
3529 /* Compile URL regex */ 3567 /* Compile URL regex */
3530 if (regcomp(&plugin->url_regex, 3568 if (regcomp (&plugin->url_regex,
3531 URL_REGEX, 3569 URL_REGEX,
3532 REG_EXTENDED)) 3570 REG_EXTENDED))
3533 { 3571 {
3534 LOG(GNUNET_ERROR_TYPE_ERROR, 3572 LOG (GNUNET_ERROR_TYPE_ERROR,
3535 _("Unable to compile URL regex\n")); 3573 _ ("Unable to compile URL regex\n"));
3536 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); 3574 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3537 return NULL; 3575 return NULL;
3538 } 3576 }
3539 3577
3540 /* Configure plugin */ 3578 /* Configure plugin */
3541 if (GNUNET_SYSERR == server_configure_plugin(plugin)) 3579 if (GNUNET_SYSERR == server_configure_plugin (plugin))
3542 { 3580 {
3543 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); 3581 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3544 return NULL; 3582 return NULL;
3545 } 3583 }
3546 3584
3547 /* Check IPv6 support */ 3585 /* Check IPv6 support */
3548 if (GNUNET_YES == plugin->use_ipv6) 3586 if (GNUNET_YES == plugin->use_ipv6)
3549 plugin->use_ipv6 = server_check_ipv6_support(plugin); 3587 plugin->use_ipv6 = server_check_ipv6_support (plugin);
3550 3588
3551 /* Report addresses to transport service */ 3589 /* Report addresses to transport service */
3552 if (GNUNET_NO == plugin->external_only) 3590 if (GNUNET_NO == plugin->external_only)
3553 server_start_report_addresses(plugin); 3591 server_start_report_addresses (plugin);
3554 3592
3555 if (GNUNET_SYSERR == server_start(plugin)) 3593 if (GNUNET_SYSERR == server_start (plugin))
3556 { 3594 {
3557 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); 3595 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3558 return NULL; 3596 return NULL;
3559 } 3597 }
3560 return api; 3598 return api;
3561} 3599}
3562 3600
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 @@
53/** 53/**
54 * Host-Address in a SMTP network. 54 * Host-Address in a SMTP network.
55 */ 55 */
56typedef struct { 56typedef struct
57{
57 /** 58 /**
58 * Filter line that every sender must include in the E-mails such 59 * Filter line that every sender must include in the E-mails such
59 * that the receiver can effectively filter out the GNUnet traffic 60 * that the receiver can effectively filter out the GNUnet traffic
@@ -75,7 +76,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
75 * Encapsulation of a GNUnet message in the SMTP mail body (before 76 * Encapsulation of a GNUnet message in the SMTP mail body (before
76 * base64 encoding). 77 * base64 encoding).
77 */ 78 */
78typedef struct { 79typedef struct
80{
79 GNUNET_MessageHeader header; 81 GNUNET_MessageHeader header;
80 82
81 /** 83 /**
@@ -143,13 +145,13 @@ static GNUNET_CronTime last_transmission;
143 145
144/* ********************* the real stuff ******************* */ 146/* ********************* the real stuff ******************* */
145 147
146#define strAUTOncmp(a, b) strncmp(a, b, strlen(b)) 148#define strAUTOncmp(a, b) strncmp (a, b, strlen (b))
147 149
148/** 150/**
149 * Listen to the pipe, decode messages and send to core. 151 * Listen to the pipe, decode messages and send to core.
150 */ 152 */
151static void * 153static void *
152listenAndDistribute(void *unused) 154listenAndDistribute (void *unused)
153{ 155{
154 char *line; 156 char *line;
155 unsigned int linesize; 157 unsigned int linesize;
@@ -162,93 +164,96 @@ listenAndDistribute(void *unused)
162 int fd; 164 int fd;
163 unsigned int pos; 165 unsigned int pos;
164 166
165 linesize = ((GNUNET_MAX_BUFFER_SIZE * 4 / 3) + 8) * (MAX_CHAR_PER_LINE + 2) / MAX_CHAR_PER_LINE; /* maximum size of a line supported */ 167 linesize = ((GNUNET_MAX_BUFFER_SIZE * 4 / 3) + 8) * (MAX_CHAR_PER_LINE + 2)
166 line = GNUNET_malloc(linesize + 2); /* 2 bytes for off-by-one errors, just to be safe... */ 168 / MAX_CHAR_PER_LINE; /* maximum size of a line supported */
169 line = GNUNET_malloc (linesize + 2); /* 2 bytes for off-by-one errors, just to be safe... */
167 170
168#define READLINE(l, limit) \ 171#define READLINE(l, limit) \
169 do { retl = fgets(l, (limit), fdes); \ 172 do { retl = fgets (l, (limit), fdes); \
170 if ((retl == NULL) || (smtp_shutdown == GNUNET_YES)) { \ 173 if ((retl == NULL) || (smtp_shutdown == GNUNET_YES)) { \
171 goto END; \ 174 goto END; \
172 } \ 175 } \
173 if (core_api->load_monitor != NULL) \ 176 if (core_api->load_monitor != NULL) \
174 GNUNET_network_monitor_notify_transmission (core_api->load_monitor, GNUNET_ND_DOWNLOAD, strlen(retl)); \ 177 GNUNET_network_monitor_notify_transmission (core_api->load_monitor, \
175 } while (0) 178 GNUNET_ND_DOWNLOAD, \
179 strlen (retl)); \
180 } while (0)
176 181
177 182
178 while (smtp_shutdown == GNUNET_NO) 183 while (smtp_shutdown == GNUNET_NO)
184 {
185 fd = OPEN (pipename, O_RDONLY | O_ASYNC);
186 if (fd == -1)
187 {
188 if (smtp_shutdown == GNUNET_NO)
189 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);
190 continue;
191 }
192 fdes = fdopen (fd, "r");
193 while (smtp_shutdown == GNUNET_NO)
179 { 194 {
180 fd = OPEN(pipename, O_RDONLY | O_ASYNC); 195 /* skip until end of header */
181 if (fd == -1) 196 do
182 { 197 {
183 if (smtp_shutdown == GNUNET_NO) 198 READLINE (line, linesize);
184 GNUNET_thread_sleep(5 * GNUNET_CRON_SECONDS); 199 }
185 continue; 200 while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */
186 } 201 READLINE (line, linesize); /* read base64 encoded message; decode, process */
187 fdes = fdopen(fd, "r"); 202 pos = 0;
188 while (smtp_shutdown == GNUNET_NO) 203 while (1)
189 { 204 {
190 /* skip until end of header */ 205 pos = strlen (line) - 1; /* ignore new line */
191 do 206 READLINE (&line[pos], linesize - pos); /* read base64 encoded message; decode, process */
192 { 207 if ((line[pos] == '\r') || (line[pos] == '\n'))
193 READLINE(line, linesize); 208 break; /* empty line => end of message! */
194 } 209 }
195 while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */ 210 size = GNUNET_STRINGS_base64_decode (line, pos, &out);
196 READLINE(line, linesize); /* read base64 encoded message; decode, process */ 211 if (size < sizeof(SMTPMessage))
197 pos = 0; 212 {
198 while (1) 213 GNUNET_GE_BREAK (ectx, 0);
199 { 214 GNUNET_free (out);
200 pos = strlen(line) - 1; /* ignore new line */ 215 goto END;
201 READLINE(&line[pos], linesize - pos); /* read base64 encoded message; decode, process */ 216 }
202 if ((line[pos] == '\r') || (line[pos] == '\n')) 217
203 break; /* empty line => end of message! */ 218 mp = (SMTPMessage *) &out[size - sizeof(SMTPMessage)];
204 } 219 if (ntohs (mp->header.size) != size)
205 size = GNUNET_STRINGS_base64_decode(line, pos, &out); 220 {
206 if (size < sizeof(SMTPMessage)) 221 GNUNET_GE_LOG (ectx,
207 { 222 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
208 GNUNET_GE_BREAK(ectx, 0); 223 _ ("Received malformed message via %s. Ignored.\n"),
209 GNUNET_free(out); 224 "SMTP");
210 goto END;
211 }
212
213 mp = (SMTPMessage *)&out[size - sizeof(SMTPMessage)];
214 if (ntohs(mp->header.size) != size)
215 {
216 GNUNET_GE_LOG(ectx,
217 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
218 _("Received malformed message via %s. Ignored.\n"),
219 "SMTP");
220#if DEBUG_SMTP 225#if DEBUG_SMTP
221 GNUNET_GE_LOG(ectx, 226 GNUNET_GE_LOG (ectx,
222 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 227 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
223 "Size returned by base64=%d, in the msg=%d.\n", size, 228 "Size returned by base64=%d, in the msg=%d.\n", size,
224 ntohl(mp->size)); 229 ntohl (mp->size));
225#endif 230#endif
226 GNUNET_free(out); 231 GNUNET_free (out);
227 goto END; 232 goto END;
228 } 233 }
229 if (stats != NULL) 234 if (stats != NULL)
230 stats->change(stat_bytesReceived, size); 235 stats->change (stat_bytesReceived, size);
231 coreMP = GNUNET_new(GNUNET_TransportPacket); 236 coreMP = GNUNET_new (GNUNET_TransportPacket);
232 coreMP->msg = out; 237 coreMP->msg = out;
233 coreMP->size = size - sizeof(SMTPMessage); 238 coreMP->size = size - sizeof(SMTPMessage);
234 coreMP->tsession = NULL; 239 coreMP->tsession = NULL;
235 coreMP->sender = mp->sender; 240 coreMP->sender = mp->sender;
236#if DEBUG_SMTP 241#if DEBUG_SMTP
237 GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 242 GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
238 "SMTP message passed to the core.\n"); 243 "SMTP message passed to the core.\n");
239#endif 244#endif
240 245
241 core_api->receive(coreMP); 246 core_api->receive (coreMP);
242 } 247 }
243END: 248END:
244#if DEBUG_SMTP 249#if DEBUG_SMTP
245 GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 250 GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
246 "SMTP message processed.\n"); 251 "SMTP message processed.\n");
247#endif 252#endif
248 if (fdes != NULL) 253 if (fdes != NULL)
249 fclose(fdes); 254 fclose (fdes);
250 } 255 }
251 GNUNET_free(line); 256 GNUNET_free (line);
252 return NULL; 257 return NULL;
253} 258}
254 259
@@ -264,20 +269,20 @@ END:
264 * @return GNUNET_OK on success, GNUNET_SYSERR on error 269 * @return GNUNET_OK on success, GNUNET_SYSERR on error
265 */ 270 */
266static int 271static int
267api_verify_hello(const GNUNET_MessageHello * hello) 272api_verify_hello (const GNUNET_MessageHello *hello)
268{ 273{
269 const EmailAddress *maddr; 274 const EmailAddress *maddr;
270 275
271 maddr = (const EmailAddress *)&hello[1]; 276 maddr = (const EmailAddress *) &hello[1];
272 if ((ntohs(hello->header.size) != 277 if ((ntohs (hello->header.size) !=
273 sizeof(GNUNET_MessageHello) + ntohs(hello->senderAddressSize)) || 278 sizeof(GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) ||
274 (maddr->senderAddress 279 (maddr->senderAddress
275 [ntohs(hello->senderAddressSize) - 1 - FILTER_STRING_SIZE] != '\0')) 280 [ntohs (hello->senderAddressSize) - 1 - FILTER_STRING_SIZE] != '\0'))
276 { 281 {
277 GNUNET_GE_BREAK(ectx, 0); 282 GNUNET_GE_BREAK (ectx, 0);
278 return GNUNET_SYSERR; /* obviously invalid */ 283 return GNUNET_SYSERR; /* obviously invalid */
279 } 284 }
280 if (NULL == strstr(maddr->filter, ": ")) 285 if (NULL == strstr (maddr->filter, ": "))
281 return GNUNET_SYSERR; 286 return GNUNET_SYSERR;
282 return GNUNET_OK; 287 return GNUNET_OK;
283} 288}
@@ -290,64 +295,65 @@ api_verify_hello(const GNUNET_MessageHello * hello)
290 * @return hello on success, NULL on error 295 * @return hello on success, NULL on error
291 */ 296 */
292static GNUNET_MessageHello * 297static GNUNET_MessageHello *
293api_create_hello() 298api_create_hello ()
294{ 299{
295 GNUNET_MessageHello *msg; 300 GNUNET_MessageHello *msg;
296 char *filter; 301 char *filter;
297 EmailAddress *haddr; 302 EmailAddress *haddr;
298 int i; 303 int i;
299 304
300 GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "FILTER", 305 GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "FILTER",
301 "X-mailer: GNUnet", &filter); 306 "X-mailer: GNUnet", &filter);
302 if (NULL == strstr(filter, ": ")) 307 if (NULL == strstr (filter, ": "))
303 { 308 {
304 GNUNET_GE_LOG(ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 309 GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
305 _("SMTP filter string to invalid, lacks ': '\n")); 310 _ ("SMTP filter string to invalid, lacks ': '\n"));
306 GNUNET_free(filter); 311 GNUNET_free (filter);
307 return NULL; 312 return NULL;
308 } 313 }
309 314
310 if (strlen(filter) > FILTER_STRING_SIZE) 315 if (strlen (filter) > FILTER_STRING_SIZE)
311 { 316 {
312 filter[FILTER_STRING_SIZE] = '\0'; 317 filter[FILTER_STRING_SIZE] = '\0';
313 GNUNET_GE_LOG(ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 318 GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
314 _("SMTP filter string to long, capped to `%s'\n"), filter); 319 _ ("SMTP filter string to long, capped to `%s'\n"), filter);
315 } 320 }
316 i = (strlen(email) + 8) & (~7); /* make multiple of 8 */ 321 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */
317 msg = 322 msg =
318 GNUNET_malloc(sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i); 323 GNUNET_malloc (sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i);
319 memset(msg, 0, sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i); 324 memset (msg, 0, sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i);
320 haddr = (EmailAddress *)&msg[1]; 325 haddr = (EmailAddress *) &msg[1];
321 memset(&haddr->filter[0], 0, FILTER_STRING_SIZE); 326 memset (&haddr->filter[0], 0, FILTER_STRING_SIZE);
322 strcpy(&haddr->filter[0], filter); 327 strcpy (&haddr->filter[0], filter);
323 GNUNET_memcpy(&haddr->senderAddress[0], email, strlen(email) + 1); 328 GNUNET_memcpy (&haddr->senderAddress[0], email, strlen (email) + 1);
324 msg->senderAddressSize = htons(strlen(email) + 1 + sizeof(EmailAddress)); 329 msg->senderAddressSize = htons (strlen (email) + 1 + sizeof(EmailAddress));
325 msg->protocol = htons(GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP); 330 msg->protocol = htons (GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP);
326 msg->MTU = htonl(smtpAPI.mtu); 331 msg->MTU = htonl (smtpAPI.mtu);
327 msg->header.size = htons(GNUNET_sizeof_hello(msg)); 332 msg->header.size = htons (GNUNET_sizeof_hello (msg));
328 if (api_verify_hello(msg) == GNUNET_SYSERR) 333 if (api_verify_hello (msg) == GNUNET_SYSERR)
329 GNUNET_GE_ASSERT(ectx, 0); 334 GNUNET_GE_ASSERT (ectx, 0);
330 GNUNET_free(filter); 335 GNUNET_free (filter);
331 return msg; 336 return msg;
332} 337}
333 338
334struct GetMessageClosure { 339struct GetMessageClosure
340{
335 unsigned int esize; 341 unsigned int esize;
336 unsigned int pos; 342 unsigned int pos;
337 char *ebody; 343 char *ebody;
338}; 344};
339 345
340static const char * 346static const char *
341get_message(void **buf, int *len, void *cls) 347get_message (void **buf, int *len, void *cls)
342{ 348{
343 struct GetMessageClosure *gmc = cls; 349 struct GetMessageClosure *gmc = cls;
344 350
345 *buf = NULL; 351 *buf = NULL;
346 if (len == NULL) 352 if (len == NULL)
347 { 353 {
348 gmc->pos = 0; 354 gmc->pos = 0;
349 return NULL; 355 return NULL;
350 } 356 }
351 if (gmc->pos == gmc->esize) 357 if (gmc->pos == gmc->esize)
352 return NULL; /* done */ 358 return NULL; /* done */
353 *len = gmc->esize; 359 *len = gmc->esize;
@@ -365,8 +371,8 @@ get_message(void **buf, int *len, void *cls)
365 * @return GNUNET_SYSERR on error, GNUNET_OK on success 371 * @return GNUNET_SYSERR on error, GNUNET_OK on success
366 */ 372 */
367static int 373static int
368api_send(GNUNET_TSession * tsession, const void *msg, const unsigned int size, 374api_send (GNUNET_TSession *tsession, const void *msg, const unsigned int size,
369 int important) 375 int important)
370{ 376{
371 const GNUNET_MessageHello *hello; 377 const GNUNET_MessageHello *hello;
372 const EmailAddress *haddr; 378 const EmailAddress *haddr;
@@ -386,139 +392,140 @@ api_send(GNUNET_TSession * tsession, const void *msg, const unsigned int size,
386 if (smtp_shutdown == GNUNET_YES) 392 if (smtp_shutdown == GNUNET_YES)
387 return GNUNET_SYSERR; 393 return GNUNET_SYSERR;
388 if ((size == 0) || (size > smtpAPI.mtu)) 394 if ((size == 0) || (size > smtpAPI.mtu))
389 { 395 {
390 GNUNET_GE_BREAK(ectx, 0); 396 GNUNET_GE_BREAK (ectx, 0);
391 return GNUNET_SYSERR; 397 return GNUNET_SYSERR;
392 } 398 }
393 now = GNUNET_get_time(); 399 now = GNUNET_get_time ();
394 if ((important != GNUNET_YES) && 400 if ((important != GNUNET_YES) &&
395 ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS) 401 ( ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS) )
396 return GNUNET_NO; /* rate too high */ 402 return GNUNET_NO; /* rate too high */
397 last_transmission = now; 403 last_transmission = now;
398 404
399 hello = (const GNUNET_MessageHello *)tsession->internal; 405 hello = (const GNUNET_MessageHello *) tsession->internal;
400 if (hello == NULL) 406 if (hello == NULL)
401 return GNUNET_SYSERR; 407 return GNUNET_SYSERR;
402 GNUNET_mutex_lock(lock); 408 GNUNET_mutex_lock (lock);
403 session = smtp_create_session(); 409 session = smtp_create_session ();
404 if (session == NULL) 410 if (session == NULL)
405 { 411 {
406 GNUNET_GE_LOG(ectx, 412 GNUNET_GE_LOG (ectx,
407 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 413 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER
408 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"), 414 | GNUNET_GE_IMMEDIATE, _ ("SMTP: `%s' failed: %s.\n"),
409 "smtp_create_session", smtp_strerror(smtp_errno(), ebuf, 415 "smtp_create_session", smtp_strerror (smtp_errno (), ebuf,
410 EBUF_LEN)); 416 EBUF_LEN));
411 GNUNET_mutex_unlock(lock); 417 GNUNET_mutex_unlock (lock);
412 return GNUNET_SYSERR; 418 return GNUNET_SYSERR;
413 } 419 }
414 if (0 == smtp_set_server(session, smtp_server_name)) 420 if (0 == smtp_set_server (session, smtp_server_name))
415 { 421 {
416 GNUNET_GE_LOG(ectx, 422 GNUNET_GE_LOG (ectx,
417 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 423 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER
418 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"), 424 | GNUNET_GE_IMMEDIATE, _ ("SMTP: `%s' failed: %s.\n"),
419 "smtp_set_server", smtp_strerror(smtp_errno(), ebuf, 425 "smtp_set_server", smtp_strerror (smtp_errno (), ebuf,
420 EBUF_LEN)); 426 EBUF_LEN));
421 smtp_destroy_session(session); 427 smtp_destroy_session (session);
422 GNUNET_mutex_unlock(lock); 428 GNUNET_mutex_unlock (lock);
423 return GNUNET_SYSERR; 429 return GNUNET_SYSERR;
424 } 430 }
425 haddr = (const EmailAddress *)&hello[1]; 431 haddr = (const EmailAddress *) &hello[1];
426 message = smtp_add_message(session); 432 message = smtp_add_message (session);
427 if (message == NULL) 433 if (message == NULL)
428 { 434 {
429 GNUNET_GE_LOG(ectx, 435 GNUNET_GE_LOG (ectx,
430 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 436 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
431 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 437 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
432 "smtp_add_message", smtp_strerror(smtp_errno(), ebuf, 438 "smtp_add_message", smtp_strerror (smtp_errno (), ebuf,
433 EBUF_LEN)); 439 EBUF_LEN));
434 smtp_destroy_session(session); 440 smtp_destroy_session (session);
435 GNUNET_mutex_unlock(lock); 441 GNUNET_mutex_unlock (lock);
436 return GNUNET_SYSERR; 442 return GNUNET_SYSERR;
437 } 443 }
438 smtp_set_header(message, "To", NULL, haddr->senderAddress); 444 smtp_set_header (message, "To", NULL, haddr->senderAddress);
439 smtp_set_header(message, "From", NULL, email); 445 smtp_set_header (message, "From", NULL, email);
440 446
441 filter = GNUNET_strdup(haddr->filter); 447 filter = GNUNET_strdup (haddr->filter);
442 fvalue = strstr(filter, ": "); 448 fvalue = strstr (filter, ": ");
443 GNUNET_GE_ASSERT(NULL, NULL != fvalue); 449 GNUNET_GE_ASSERT (NULL, NULL != fvalue);
444 fvalue[0] = '\0'; 450 fvalue[0] = '\0';
445 fvalue += 2; 451 fvalue += 2;
446 if (0 == smtp_set_header(message, filter, fvalue)) 452 if (0 == smtp_set_header (message, filter, fvalue))
447 { 453 {
448 GNUNET_GE_LOG(ectx, 454 GNUNET_GE_LOG (ectx,
449 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 455 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
450 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 456 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
451 "smtp_set_header", smtp_strerror(smtp_errno(), ebuf, 457 "smtp_set_header", smtp_strerror (smtp_errno (), ebuf,
452 EBUF_LEN)); 458 EBUF_LEN));
453 smtp_destroy_session(session); 459 smtp_destroy_session (session);
454 GNUNET_mutex_unlock(lock); 460 GNUNET_mutex_unlock (lock);
455 GNUNET_free(filter); 461 GNUNET_free (filter);
456 return GNUNET_SYSERR; 462 return GNUNET_SYSERR;
457 } 463 }
458 GNUNET_free(filter); 464 GNUNET_free (filter);
459 m = GNUNET_malloc(size + sizeof(SMTPMessage)); 465 m = GNUNET_malloc (size + sizeof(SMTPMessage));
460 GNUNET_memcpy(m, msg, size); 466 GNUNET_memcpy (m, msg, size);
461 mp = (SMTPMessage *)&m[size]; 467 mp = (SMTPMessage *) &m[size];
462 mp->header.size = htons(size + sizeof(SMTPMessage)); 468 mp->header.size = htons (size + sizeof(SMTPMessage));
463 mp->header.type = htons(0); 469 mp->header.type = htons (0);
464 mp->sender = *core_api->my_identity; 470 mp->sender = *core_api->my_identity;
465 gm_cls.ebody = NULL; 471 gm_cls.ebody = NULL;
466 gm_cls.pos = 0; 472 gm_cls.pos = 0;
467 gm_cls.esize = GNUNET_STRINGS_base64_encode(m, size + sizeof(SMTPMessage), &gm_cls.ebody); 473 gm_cls.esize = GNUNET_STRINGS_base64_encode (m, size + sizeof(SMTPMessage),
468 GNUNET_free(m); 474 &gm_cls.ebody);
469 if (0 == smtp_size_set_estimate(message, gm_cls.esize)) 475 GNUNET_free (m);
470 { 476 if (0 == smtp_size_set_estimate (message, gm_cls.esize))
471 GNUNET_GE_LOG(ectx, 477 {
472 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 478 GNUNET_GE_LOG (ectx,
473 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 479 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
474 "smtp_size_set_estimate", smtp_strerror(smtp_errno(), ebuf, 480 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
481 "smtp_size_set_estimate", smtp_strerror (smtp_errno (), ebuf,
475 EBUF_LEN)); 482 EBUF_LEN));
476 } 483 }
477 if (0 == smtp_set_messagecb(message, &get_message, &gm_cls)) 484 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls))
478 { 485 {
479 GNUNET_GE_LOG(ectx, 486 GNUNET_GE_LOG (ectx,
480 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 487 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
481 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 488 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
482 "smtp_set_messagecb", smtp_strerror(smtp_errno(), ebuf, 489 "smtp_set_messagecb", smtp_strerror (smtp_errno (), ebuf,
483 EBUF_LEN)); 490 EBUF_LEN));
484 smtp_destroy_session(session); 491 smtp_destroy_session (session);
485 GNUNET_mutex_unlock(lock); 492 GNUNET_mutex_unlock (lock);
486 GNUNET_free(gm_cls.ebody); 493 GNUNET_free (gm_cls.ebody);
487 return GNUNET_SYSERR; 494 return GNUNET_SYSERR;
488 } 495 }
489 recipient = smtp_add_recipient(message, haddr->senderAddress); 496 recipient = smtp_add_recipient (message, haddr->senderAddress);
490 if (recipient == NULL) 497 if (recipient == NULL)
491 { 498 {
492 GNUNET_GE_LOG(ectx, 499 GNUNET_GE_LOG (ectx,
493 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 500 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
494 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 501 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
495 "smtp_add_recipient", smtp_strerror(smtp_errno(), ebuf, 502 "smtp_add_recipient", smtp_strerror (smtp_errno (), ebuf,
496 EBUF_LEN)); 503 EBUF_LEN));
497 smtp_destroy_session(session); 504 smtp_destroy_session (session);
498 GNUNET_mutex_unlock(lock); 505 GNUNET_mutex_unlock (lock);
499 return GNUNET_SYSERR; 506 return GNUNET_SYSERR;
500 } 507 }
501 if (0 == smtp_start_session(session)) 508 if (0 == smtp_start_session (session))
502 { 509 {
503 GNUNET_GE_LOG(ectx, 510 GNUNET_GE_LOG (ectx,
504 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 511 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
505 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 512 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
506 "smtp_start_session", smtp_strerror(smtp_errno(), ebuf, 513 "smtp_start_session", smtp_strerror (smtp_errno (), ebuf,
507 EBUF_LEN)); 514 EBUF_LEN));
508 smtp_destroy_session(session); 515 smtp_destroy_session (session);
509 GNUNET_mutex_unlock(lock); 516 GNUNET_mutex_unlock (lock);
510 GNUNET_free(gm_cls.ebody); 517 GNUNET_free (gm_cls.ebody);
511 return GNUNET_SYSERR; 518 return GNUNET_SYSERR;
512 } 519 }
513 if (stats != NULL) 520 if (stats != NULL)
514 stats->change(stat_bytesSent, size); 521 stats->change (stat_bytesSent, size);
515 if (core_api->load_monitor != NULL) 522 if (core_api->load_monitor != NULL)
516 GNUNET_network_monitor_notify_transmission(core_api->load_monitor, 523 GNUNET_network_monitor_notify_transmission (core_api->load_monitor,
517 GNUNET_ND_UPLOAD, gm_cls.esize); 524 GNUNET_ND_UPLOAD, gm_cls.esize);
518 smtp_message_reset_status(message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */ 525 smtp_message_reset_status (message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */
519 smtp_destroy_session(session); 526 smtp_destroy_session (session);
520 GNUNET_mutex_unlock(lock); 527 GNUNET_mutex_unlock (lock);
521 GNUNET_free(gm_cls.ebody); 528 GNUNET_free (gm_cls.ebody);
522 return GNUNET_OK; 529 return GNUNET_OK;
523} 530}
524 531
@@ -530,15 +537,15 @@ api_send(GNUNET_TSession * tsession, const void *msg, const unsigned int size,
530 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 537 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
531 */ 538 */
532static int 539static int
533api_connect(const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr, 540api_connect (const GNUNET_MessageHello *hello, GNUNET_TSession **tsessionPtr,
534 int may_reuse) 541 int may_reuse)
535{ 542{
536 GNUNET_TSession *tsession; 543 GNUNET_TSession *tsession;
537 544
538 tsession = GNUNET_new(GNUNET_TSession); 545 tsession = GNUNET_new (GNUNET_TSession);
539 tsession->internal = GNUNET_malloc(GNUNET_sizeof_hello(hello)); 546 tsession->internal = GNUNET_malloc (GNUNET_sizeof_hello (hello));
540 tsession->peer = hello->senderIdentity; 547 tsession->peer = hello->senderIdentity;
541 GNUNET_memcpy(tsession->internal, hello, GNUNET_sizeof_hello(hello)); 548 GNUNET_memcpy (tsession->internal, hello, GNUNET_sizeof_hello (hello));
542 tsession->ttype = smtpAPI.protocol_number; 549 tsession->ttype = smtpAPI.protocol_number;
543 (*tsessionPtr) = tsession; 550 (*tsessionPtr) = tsession;
544 return GNUNET_OK; 551 return GNUNET_OK;
@@ -551,14 +558,14 @@ api_connect(const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr,
551 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 558 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
552 */ 559 */
553static int 560static int
554api_disconnect(GNUNET_TSession * tsession) 561api_disconnect (GNUNET_TSession *tsession)
555{ 562{
556 if (tsession != NULL) 563 if (tsession != NULL)
557 { 564 {
558 if (tsession->internal != NULL) 565 if (tsession->internal != NULL)
559 GNUNET_free(tsession->internal); 566 GNUNET_free (tsession->internal);
560 GNUNET_free(tsession); 567 GNUNET_free (tsession);
561 } 568 }
562 return GNUNET_OK; 569 return GNUNET_OK;
563} 570}
564 571
@@ -567,18 +574,18 @@ api_disconnect(GNUNET_TSession * tsession)
567 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 574 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
568 */ 575 */
569static int 576static int
570api_start_transport_server() 577api_start_transport_server ()
571{ 578{
572 smtp_shutdown = GNUNET_NO; 579 smtp_shutdown = GNUNET_NO;
573 /* initialize SMTP network */ 580 /* initialize SMTP network */
574 dispatchThread = GNUNET_thread_create(&listenAndDistribute, NULL, 1024 * 4); 581 dispatchThread = GNUNET_thread_create (&listenAndDistribute, NULL, 1024 * 4);
575 if (dispatchThread == NULL) 582 if (dispatchThread == NULL)
576 { 583 {
577 GNUNET_GE_DIE_STRERROR(ectx, 584 GNUNET_GE_DIE_STRERROR (ectx,
578 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL, 585 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL,
579 "pthread_create"); 586 "pthread_create");
580 return GNUNET_SYSERR; 587 return GNUNET_SYSERR;
581 } 588 }
582 return GNUNET_OK; 589 return GNUNET_OK;
583} 590}
584 591
@@ -587,13 +594,13 @@ api_start_transport_server()
587 * restarted later! 594 * restarted later!
588 */ 595 */
589static int 596static int
590api_stop_transport_server() 597api_stop_transport_server ()
591{ 598{
592 void *unused; 599 void *unused;
593 600
594 smtp_shutdown = GNUNET_YES; 601 smtp_shutdown = GNUNET_YES;
595 GNUNET_thread_stop_sleep(dispatchThread); 602 GNUNET_thread_stop_sleep (dispatchThread);
596 GNUNET_thread_join(dispatchThread, &unused); 603 GNUNET_thread_join (dispatchThread, &unused);
597 return GNUNET_OK; 604 return GNUNET_OK;
598} 605}
599 606
@@ -601,8 +608,8 @@ api_stop_transport_server()
601 * Convert SMTP hello to an IP address (always fails). 608 * Convert SMTP hello to an IP address (always fails).
602 */ 609 */
603static int 610static int
604api_hello_to_address(const GNUNET_MessageHello * hello, void **sa, 611api_hello_to_address (const GNUNET_MessageHello *hello, void **sa,
605 unsigned int *sa_len) 612 unsigned int *sa_len)
606{ 613{
607 return GNUNET_SYSERR; 614 return GNUNET_SYSERR;
608} 615}
@@ -611,7 +618,7 @@ api_hello_to_address(const GNUNET_MessageHello * hello, void **sa,
611 * Always fails. 618 * Always fails.
612 */ 619 */
613static int 620static int
614api_associate(GNUNET_TSession * tsession) 621api_associate (GNUNET_TSession *tsession)
615{ 622{
616 return GNUNET_SYSERR; /* SMTP connections can never be associated */ 623 return GNUNET_SYSERR; /* SMTP connections can never be associated */
617} 624}
@@ -621,8 +628,8 @@ api_associate(GNUNET_TSession * tsession)
621 * frequency limits to SMTP in the future!). 628 * frequency limits to SMTP in the future!).
622 */ 629 */
623static int 630static int
624api_test_would_try(GNUNET_TSession * tsession, unsigned int size, 631api_test_would_try (GNUNET_TSession *tsession, unsigned int size,
625 int important) 632 int important)
626{ 633{
627 return GNUNET_OK; /* we always try... */ 634 return GNUNET_OK; /* we always try... */
628} 635}
@@ -632,61 +639,64 @@ api_test_would_try(GNUNET_TSession * tsession, unsigned int size,
632 * returns the smtp transport API. 639 * returns the smtp transport API.
633 */ 640 */
634GNUNET_TransportAPI * 641GNUNET_TransportAPI *
635inittransport_smtp(struct GNUNET_CoreAPIForTransport * core) 642inittransport_smtp (struct GNUNET_CoreAPIForTransport *core)
636{ 643{
637 unsigned long long mtu; 644 unsigned long long mtu;
638 struct sigaction sa; 645 struct sigaction sa;
639 646
640 core_api = core; 647 core_api = core;
641 ectx = core->ectx; 648 ectx = core->ectx;
642 if (!GNUNET_GC_have_configuration_value(core_api->cfg, "SMTP", "EMAIL")) 649 if (! GNUNET_GC_have_configuration_value (core_api->cfg, "SMTP", "EMAIL"))
643 { 650 {
644 GNUNET_GE_LOG(ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, 651 GNUNET_GE_LOG (ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
645 _ 652 _
646 ("No email-address specified, can not start SMTP transport.\n")); 653 (
647 return NULL; 654 "No email-address specified, can not start SMTP transport.\n"));
648 } 655 return NULL;
649 GNUNET_GC_get_configuration_value_number(core_api->cfg, "SMTP", "MTU", 1200, 656 }
650 SMTP_MESSAGE_SIZE, 657 GNUNET_GC_get_configuration_value_number (core_api->cfg, "SMTP", "MTU", 1200,
651 SMTP_MESSAGE_SIZE, &mtu); 658 SMTP_MESSAGE_SIZE,
652 GNUNET_GC_get_configuration_value_number(core_api->cfg, "SMTP", "RATELIMIT", 659 SMTP_MESSAGE_SIZE, &mtu);
653 0, 0, 1024 * 1024, &rate_limit); 660 GNUNET_GC_get_configuration_value_number (core_api->cfg, "SMTP", "RATELIMIT",
654 stats = core_api->service_request("stats"); 661 0, 0, 1024 * 1024, &rate_limit);
662 stats = core_api->service_request ("stats");
655 if (stats != NULL) 663 if (stats != NULL)
656 { 664 {
657 stat_bytesReceived = 665 stat_bytesReceived =
658 stats->create(gettext_noop("# bytes received via SMTP")); 666 stats->create (gettext_noop ("# bytes received via SMTP"));
659 stat_bytesSent = stats->create(gettext_noop("# bytes sent via SMTP")); 667 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP"));
660 stat_bytesDropped = 668 stat_bytesDropped =
661 stats->create(gettext_noop("# bytes dropped by SMTP (outgoing)")); 669 stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)"));
662 } 670 }
663 GNUNET_GC_get_configuration_value_filename(core_api->cfg, "SMTP", "PIPE", &pipename); 671 GNUNET_GC_get_configuration_value_filename (core_api->cfg, "SMTP", "PIPE",
664 unlink(pipename); 672 &pipename);
665 if (0 != mkfifo(pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 673 unlink (pipename);
666 { 674 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
667 GNUNET_GE_LOG_STRERROR(ectx, 675 {
668 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL, 676 GNUNET_GE_LOG_STRERROR (ectx,
669 "mkfifo"); 677 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL,
670 GNUNET_free(pipename); 678 "mkfifo");
671 core_api->service_release(stats); 679 GNUNET_free (pipename);
672 stats = NULL; 680 core_api->service_release (stats);
673 return NULL; 681 stats = NULL;
674 } 682 return NULL;
683 }
675 /* we need to allow the mailer program to send us messages; 684 /* we need to allow the mailer program to send us messages;
676 * easiest done by giving it write permissions (see Mantis #1142) */ 685 * easiest done by giving it write permissions (see Mantis #1142) */
677 if (0 != chmod(pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 686 if (0 != chmod (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
678 GNUNET_GE_LOG_STRERROR(ectx, 687 GNUNET_GE_LOG_STRERROR (ectx,
679 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 688 GNUNET_GE_ADMIN | GNUNET_GE_BULK
680 GNUNET_GE_WARNING, "chmod"); 689 | GNUNET_GE_WARNING, "chmod");
681 GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "EMAIL", NULL, 690 GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "EMAIL",
682 &email); 691 NULL,
683 lock = GNUNET_mutex_create(GNUNET_NO); 692 &email);
684 GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "SERVER", 693 lock = GNUNET_mutex_create (GNUNET_NO);
685 "localhost:25", &smtp_server_name); 694 GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "SERVER",
695 "localhost:25", &smtp_server_name);
686 sa.sa_handler = SIG_IGN; 696 sa.sa_handler = SIG_IGN;
687 sigemptyset(&sa.sa_mask); 697 sigemptyset (&sa.sa_mask);
688 sa.sa_flags = 0; 698 sa.sa_flags = 0;
689 sigaction(SIGPIPE, &sa, &old_handler); 699 sigaction (SIGPIPE, &sa, &old_handler);
690 700
691 smtpAPI.protocol_number = GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP; 701 smtpAPI.protocol_number = GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP;
692 smtpAPI.mtu = mtu - sizeof(SMTPMessage); 702 smtpAPI.mtu = mtu - sizeof(SMTPMessage);
@@ -705,21 +715,21 @@ inittransport_smtp(struct GNUNET_CoreAPIForTransport * core)
705} 715}
706 716
707void 717void
708donetransport_smtp() 718donetransport_smtp ()
709{ 719{
710 sigaction(SIGPIPE, &old_handler, NULL); 720 sigaction (SIGPIPE, &old_handler, NULL);
711 GNUNET_free(smtp_server_name); 721 GNUNET_free (smtp_server_name);
712 if (stats != NULL) 722 if (stats != NULL)
713 { 723 {
714 core_api->service_release(stats); 724 core_api->service_release (stats);
715 stats = NULL; 725 stats = NULL;
716 } 726 }
717 GNUNET_mutex_destroy(lock); 727 GNUNET_mutex_destroy (lock);
718 lock = NULL; 728 lock = NULL;
719 unlink(pipename); 729 unlink (pipename);
720 GNUNET_free(pipename); 730 GNUNET_free (pipename);
721 pipename = NULL; 731 pipename = NULL;
722 GNUNET_free(email); 732 GNUNET_free (email);
723 email = NULL; 733 email = NULL;
724} 734}
725 735
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 @@
35#include "gnunet_transport_plugin.h" 35#include "gnunet_transport_plugin.h"
36#include "transport.h" 36#include "transport.h"
37 37
38#define LOG(kind, ...) GNUNET_log_from(kind, "transport-tcp", __VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "transport-tcp", __VA_ARGS__)
39 39
40#define PLUGIN_NAME "tcp" 40#define PLUGIN_NAME "tcp"
41 41
@@ -43,7 +43,7 @@
43 * How long until we give up on establishing an NAT connection? 43 * How long until we give up on establishing an NAT connection?
44 * Must be > 4 RTT 44 * Must be > 4 RTT
45 */ 45 */
46#define NAT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 46#define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
47 47
48/** 48/**
49 * Opaque handle that can be used to cancel 49 * Opaque handle that can be used to cancel
@@ -83,7 +83,7 @@ struct LEGACY_SERVICE_Context;
83 * @param srv service to stop 83 * @param srv service to stop
84 */ 84 */
85void 85void
86LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *srv); 86LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv);
87 87
88 88
89/** 89/**
@@ -103,7 +103,8 @@ typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls,
103/** 103/**
104 * Credentials for UNIX domain sockets. 104 * Credentials for UNIX domain sockets.
105 */ 105 */
106struct GNUNET_CONNECTION_Credentials { 106struct GNUNET_CONNECTION_Credentials
107{
107 /** 108 /**
108 * UID of the other end of the connection. 109 * UID of the other end of the connection.
109 */ 110 */
@@ -185,7 +186,7 @@ typedef void (*GNUNET_CONNECTION_Receiver) (void *cls,
185 * @param connection connection to destroy 186 * @param connection connection to destroy
186 */ 187 */
187void 188void
188GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection); 189GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection);
189 190
190 191
191/** 192/**
@@ -249,7 +250,8 @@ typedef void (*GNUNET_SERVER_MessageCallback) (
249 * Message handler. Each struct specifies how to handle on particular 250 * Message handler. Each struct specifies how to handle on particular
250 * type of message received. 251 * type of message received.
251 */ 252 */
252struct GNUNET_SERVER_MessageHandler { 253struct GNUNET_SERVER_MessageHandler
254{
253 /** 255 /**
254 * Function to call for messages of "type". 256 * Function to call for messages of "type".
255 */ 257 */
@@ -278,7 +280,8 @@ struct GNUNET_SERVER_MessageHandler {
278/** 280/**
279 * Options for the service (bitmask). 281 * Options for the service (bitmask).
280 */ 282 */
281enum LEGACY_SERVICE_Options { 283enum LEGACY_SERVICE_Options
284{
282 /** 285 /**
283 * Use defaults. Terminates all client connections and the listen 286 * Use defaults. Terminates all client connections and the listen
284 * sockets immediately upon receiving the shutdown signal. 287 * sockets immediately upon receiving the shutdown signal.
@@ -309,7 +312,7 @@ enum LEGACY_SERVICE_Options {
309 * @param client the client to disconnect from 312 * @param client the client to disconnect from
310 */ 313 */
311void 314void
312GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client); 315GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client);
313 316
314/** 317/**
315 * Return user context associated with the given client. 318 * Return user context associated with the given client.
@@ -320,8 +323,8 @@ GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client);
320 * @return pointer to user context 323 * @return pointer to user context
321 */ 324 */
322void * 325void *
323GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client, 326GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client,
324 size_t size); 327 size_t size);
325 328
326 329
327/** 330/**
@@ -350,8 +353,8 @@ typedef int (*GNUNET_SERVER_MessageTokenizerCallback) (
350 * @return handle to tokenizer 353 * @return handle to tokenizer
351 */ 354 */
352struct GNUNET_SERVER_MessageStreamTokenizer * 355struct GNUNET_SERVER_MessageStreamTokenizer *
353GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, 356GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
354 void *cb_cls); 357 void *cb_cls);
355 358
356/** 359/**
357 * Add incoming data to the receive buffer and call the 360 * Add incoming data to the receive buffer and call the
@@ -370,12 +373,12 @@ GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb,
370 * #GNUNET_SYSERR if the data stream is corrupt 373 * #GNUNET_SYSERR if the data stream is corrupt
371 */ 374 */
372int 375int
373GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst, 376GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
374 void *client_identity, 377 void *client_identity,
375 const char *buf, 378 const char *buf,
376 size_t size, 379 size_t size,
377 int purge, 380 int purge,
378 int one_shot); 381 int one_shot);
379 382
380 383
381/** 384/**
@@ -384,7 +387,7 @@ GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst,
384 * @param mst tokenizer to destroy 387 * @param mst tokenizer to destroy
385 */ 388 */
386void 389void
387GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst); 390GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst);
388 391
389 392
390/** 393/**
@@ -396,9 +399,9 @@ GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst);
396 * @param size number of bytes in user context struct (for verification only) 399 * @param size number of bytes in user context struct (for verification only)
397 */ 400 */
398void 401void
399GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, 402GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
400 void *ptr, 403 void *ptr,
401 size_t size); 404 size_t size);
402/** 405/**
403 * Return user context associated with the given client. 406 * Return user context associated with the given client.
404 * 407 *
@@ -407,7 +410,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client,
407 * @return pointer to user context of type 'type *'. 410 * @return pointer to user context of type 'type *'.
408 */ 411 */
409#define GNUNET_SERVER_client_get_user_context(client, type) \ 412#define GNUNET_SERVER_client_get_user_context(client, type) \
410 (type *)GNUNET_SERVER_client_get_user_context_(client, sizeof(type)) 413 (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof(type))
411 414
412/** 415/**
413 * Set user context to be associated with the given client. 416 * 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,
416 * @param value pointer to user context 419 * @param value pointer to user context
417 */ 420 */
418#define GNUNET_SERVER_client_set_user_context(client, value) \ 421#define GNUNET_SERVER_client_set_user_context(client, value) \
419 GNUNET_SERVER_client_set_user_context_(client, value, sizeof(*value)) 422 GNUNET_SERVER_client_set_user_context_ (client, value, sizeof(*value))
420 423
421 424
422/** 425/**
@@ -435,7 +438,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client,
435 * NULL if we are already going to notify someone else (busy) 438 * NULL if we are already going to notify someone else (busy)
436 */ 439 */
437struct GNUNET_SERVER_TransmitHandle * 440struct GNUNET_SERVER_TransmitHandle *
438GNUNET_SERVER_notify_transmit_ready( 441GNUNET_SERVER_notify_transmit_ready (
439 struct GNUNET_SERVER_Client *client, 442 struct GNUNET_SERVER_Client *client,
440 size_t size, 443 size_t size,
441 struct GNUNET_TIME_Relative timeout, 444 struct GNUNET_TIME_Relative timeout,
@@ -448,7 +451,7 @@ GNUNET_SERVER_notify_transmit_ready(
448 * @param th request to abort 451 * @param th request to abort
449 */ 452 */
450void 453void
451GNUNET_SERVER_notify_transmit_ready_cancel( 454GNUNET_SERVER_notify_transmit_ready_cancel (
452 struct GNUNET_SERVER_TransmitHandle *th); 455 struct GNUNET_SERVER_TransmitHandle *th);
453 456
454 457
@@ -460,7 +463,7 @@ GNUNET_SERVER_notify_transmit_ready_cancel(
460 * @param client the client to keep 463 * @param client the client to keep
461 */ 464 */
462void 465void
463GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client); 466GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client);
464 467
465 468
466/** 469/**
@@ -472,7 +475,7 @@ GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client);
472 * @param client the client to drop 475 * @param client the client to drop
473 */ 476 */
474void 477void
475GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client); 478GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client);
476 479
477 480
478/** 481/**
@@ -496,7 +499,7 @@ typedef void (*LEGACY_SERVICE_Main) (
496 * @param server server to stop accepting connections. 499 * @param server server to stop accepting connections.
497 */ 500 */
498void 501void
499GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server); 502GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server);
500 503
501/** 504/**
502 * Notify us when the server has enough space to transmit 505 * Notify us when the server has enough space to transmit
@@ -514,7 +517,7 @@ GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server);
514 * NULL if we are already going to notify someone else (busy) 517 * NULL if we are already going to notify someone else (busy)
515 */ 518 */
516struct GNUNET_SERVER_TransmitHandle * 519struct GNUNET_SERVER_TransmitHandle *
517GNUNET_SERVER_notify_transmit_ready( 520GNUNET_SERVER_notify_transmit_ready (
518 struct GNUNET_SERVER_Client *client, 521 struct GNUNET_SERVER_Client *client,
519 size_t size, 522 size_t size,
520 struct GNUNET_TIME_Relative timeout, 523 struct GNUNET_TIME_Relative timeout,
@@ -534,8 +537,8 @@ GNUNET_SERVER_notify_transmit_ready(
534 * @return the client handle 537 * @return the client handle
535 */ 538 */
536struct GNUNET_SERVER_Client * 539struct GNUNET_SERVER_Client *
537GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, 540GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
538 struct GNUNET_CONNECTION_Handle *connection); 541 struct GNUNET_CONNECTION_Handle *connection);
539 542
540 543
541/** 544/**
@@ -544,7 +547,7 @@ GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server,
544 * @param server server to resume accepting connections. 547 * @param server server to resume accepting connections.
545 */ 548 */
546void 549void
547GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server); 550GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server);
548 551
549/** 552/**
550 * Free resources held by this server. 553 * Free resources held by this server.
@@ -552,7 +555,7 @@ GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server);
552 * @param server server to destroy 555 * @param server server to destroy
553 */ 556 */
554void 557void
555GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server); 558GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server);
556 559
557 560
558#include "tcp_connection_legacy.c" 561#include "tcp_connection_legacy.c"
@@ -565,7 +568,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
565/** 568/**
566 * Initial handshake message for a session. 569 * Initial handshake message for a session.
567 */ 570 */
568struct WelcomeMessage { 571struct WelcomeMessage
572{
569 /** 573 /**
570 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME. 574 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME.
571 */ 575 */
@@ -581,7 +585,8 @@ struct WelcomeMessage {
581 * Basically a WELCOME message, but with the purpose 585 * Basically a WELCOME message, but with the purpose
582 * of giving the waiting peer a client handle to use 586 * of giving the waiting peer a client handle to use
583 */ 587 */
584struct TCP_NAT_ProbeMessage { 588struct TCP_NAT_ProbeMessage
589{
585 /** 590 /**
586 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE. 591 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE.
587 */ 592 */
@@ -597,7 +602,8 @@ GNUNET_NETWORK_STRUCT_END
597/** 602/**
598 * Context for sending a NAT probe via TCP. 603 * Context for sending a NAT probe via TCP.
599 */ 604 */
600struct TCPProbeContext { 605struct TCPProbeContext
606{
601 /** 607 /**
602 * Active probes are kept in a DLL. 608 * Active probes are kept in a DLL.
603 */ 609 */
@@ -632,7 +638,8 @@ struct TCPProbeContext {
632/** 638/**
633 * Bits in the `options` field of TCP addresses. 639 * Bits in the `options` field of TCP addresses.
634 */ 640 */
635enum TcpAddressOptions { 641enum TcpAddressOptions
642{
636 /** 643 /**
637 * No bits set. 644 * No bits set.
638 */ 645 */
@@ -654,7 +661,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
654/** 661/**
655 * Network format for IPv4 addresses. 662 * Network format for IPv4 addresses.
656 */ 663 */
657struct IPv4TcpAddress { 664struct IPv4TcpAddress
665{
658 /** 666 /**
659 * Optional options and flags for this address, 667 * Optional options and flags for this address,
660 * see `enum TcpAddressOptions` 668 * see `enum TcpAddressOptions`
@@ -675,7 +683,8 @@ struct IPv4TcpAddress {
675/** 683/**
676 * Network format for IPv6 addresses. 684 * Network format for IPv6 addresses.
677 */ 685 */
678struct IPv6TcpAddress { 686struct IPv6TcpAddress
687{
679 /** 688 /**
680 * Optional flags for this address 689 * Optional flags for this address
681 * see `enum TcpAddressOptions` 690 * see `enum TcpAddressOptions`
@@ -703,7 +712,8 @@ struct Plugin;
703 * Information kept for each message that is yet to 712 * Information kept for each message that is yet to
704 * be transmitted. 713 * be transmitted.
705 */ 714 */
706struct PendingMessage { 715struct PendingMessage
716{
707 /** 717 /**
708 * This is a doubly-linked list. 718 * This is a doubly-linked list.
709 */ 719 */
@@ -747,7 +757,8 @@ struct PendingMessage {
747/** 757/**
748 * Session handle for TCP connections. 758 * Session handle for TCP connections.
749 */ 759 */
750struct GNUNET_ATS_Session { 760struct GNUNET_ATS_Session
761{
751 /** 762 /**
752 * To whom are we talking to (set to our identity 763 * To whom are we talking to (set to our identity
753 * if we are still waiting for the welcome message) 764 * if we are still waiting for the welcome message)
@@ -849,7 +860,8 @@ struct GNUNET_ATS_Session {
849 * Context for address to string conversion, closure 860 * Context for address to string conversion, closure
850 * for #append_port(). 861 * for #append_port().
851 */ 862 */
852struct PrettyPrinterContext { 863struct PrettyPrinterContext
864{
853 /** 865 /**
854 * DLL 866 * DLL
855 */ 867 */
@@ -905,7 +917,8 @@ struct PrettyPrinterContext {
905/** 917/**
906 * Encapsulation of all of the state of the plugin. 918 * Encapsulation of all of the state of the plugin.
907 */ 919 */
908struct Plugin { 920struct Plugin
921{
909 /** 922 /**
910 * Our environment. 923 * Our environment.
911 */ 924 */
@@ -1036,10 +1049,10 @@ struct Plugin {
1036 * set to NULL). 1049 * set to NULL).
1037 */ 1050 */
1038static int 1051static int
1039get_server_addresses(const char *service_name, 1052get_server_addresses (const char *service_name,
1040 const struct GNUNET_CONFIGURATION_Handle *cfg, 1053 const struct GNUNET_CONFIGURATION_Handle *cfg,
1041 struct sockaddr ***addrs, 1054 struct sockaddr ***addrs,
1042 socklen_t **addr_lens) 1055 socklen_t **addr_lens)
1043{ 1056{
1044 int disablev6; 1057 int disablev6;
1045 struct GNUNET_NETWORK_Handle *desc; 1058 struct GNUNET_NETWORK_Handle *desc;
@@ -1060,72 +1073,72 @@ get_server_addresses(const char *service_name,
1060 *addrs = NULL; 1073 *addrs = NULL;
1061 *addr_lens = NULL; 1074 *addr_lens = NULL;
1062 desc = NULL; 1075 desc = NULL;
1063 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "DISABLEV6")) 1076 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
1064 { 1077 {
1065 if (GNUNET_SYSERR == 1078 if (GNUNET_SYSERR ==
1066 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno(cfg, 1079 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1067 service_name, 1080 service_name,
1068 "DISABLEV6"))) 1081 "DISABLEV6")))
1069 return GNUNET_SYSERR; 1082 return GNUNET_SYSERR;
1070 } 1083 }
1071 else 1084 else
1072 disablev6 = GNUNET_NO; 1085 disablev6 = GNUNET_NO;
1073 1086
1074 if (!disablev6) 1087 if (! disablev6)
1088 {
1089 /* probe IPv6 support */
1090 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
1091 if (NULL == desc)
1092 {
1093 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1094 (EACCES == errno))
1095 {
1096 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1097 return GNUNET_SYSERR;
1098 }
1099 LOG (GNUNET_ERROR_TYPE_INFO,
1100 _ (
1101 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
1102 service_name,
1103 strerror (errno));
1104 disablev6 = GNUNET_YES;
1105 }
1106 else
1075 { 1107 {
1076 /* probe IPv6 support */ 1108 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
1077 desc = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0); 1109 desc = NULL;
1078 if (NULL == desc)
1079 {
1080 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1081 (EACCES == errno))
1082 {
1083 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket");
1084 return GNUNET_SYSERR;
1085 }
1086 LOG(GNUNET_ERROR_TYPE_INFO,
1087 _(
1088 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
1089 service_name,
1090 strerror(errno));
1091 disablev6 = GNUNET_YES;
1092 }
1093 else
1094 {
1095 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc));
1096 desc = NULL;
1097 }
1098 } 1110 }
1111 }
1099 1112
1100 port = 0; 1113 port = 0;
1101 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT")) 1114 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
1115 {
1116 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
1117 service_name,
1118 "PORT",
1119 &port))
1102 { 1120 {
1103 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, 1121 LOG (GNUNET_ERROR_TYPE_ERROR,
1104 service_name, 1122 _ ("Require valid port number for service `%s' in configuration!\n"),
1105 "PORT", 1123 service_name);
1106 &port))
1107 {
1108 LOG(GNUNET_ERROR_TYPE_ERROR,
1109 _("Require valid port number for service `%s' in configuration!\n"),
1110 service_name);
1111 }
1112 if (port > 65535)
1113 {
1114 LOG(GNUNET_ERROR_TYPE_ERROR,
1115 _("Require valid port number for service `%s' in configuration!\n"),
1116 service_name);
1117 return GNUNET_SYSERR;
1118 }
1119 } 1124 }
1120 1125 if (port > 65535)
1121 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "BINDTO"))
1122 { 1126 {
1123 GNUNET_break(GNUNET_OK == 1127 LOG (GNUNET_ERROR_TYPE_ERROR,
1124 GNUNET_CONFIGURATION_get_value_string(cfg, 1128 _ ("Require valid port number for service `%s' in configuration!\n"),
1129 service_name);
1130 return GNUNET_SYSERR;
1131 }
1132 }
1133
1134 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
1135 {
1136 GNUNET_break (GNUNET_OK ==
1137 GNUNET_CONFIGURATION_get_value_string (cfg,
1125 service_name, 1138 service_name,
1126 "BINDTO", 1139 "BINDTO",
1127 &hostname)); 1140 &hostname));
1128 } 1141 }
1129 else 1142 else
1130 hostname = NULL; 1143 hostname = NULL;
1131 1144
@@ -1133,232 +1146,232 @@ get_server_addresses(const char *service_name,
1133 abstract = GNUNET_NO; 1146 abstract = GNUNET_NO;
1134#ifdef AF_UNIX 1147#ifdef AF_UNIX
1135 if ((GNUNET_YES == 1148 if ((GNUNET_YES ==
1136 GNUNET_CONFIGURATION_have_value(cfg, service_name, "UNIXPATH")) && 1149 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
1137 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, 1150 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
1138 service_name, 1151 service_name,
1139 "UNIXPATH", 1152 "UNIXPATH",
1140 &unixpath)) && 1153 &unixpath)) &&
1141 (0 < strlen(unixpath))) 1154 (0 < strlen (unixpath)))
1142 { 1155 {
1143 /* probe UNIX support */ 1156 /* probe UNIX support */
1144 struct sockaddr_un s_un; 1157 struct sockaddr_un s_un;
1145 1158
1146 if (strlen(unixpath) >= sizeof(s_un.sun_path)) 1159 if (strlen (unixpath) >= sizeof(s_un.sun_path))
1147 { 1160 {
1148 LOG(GNUNET_ERROR_TYPE_WARNING, 1161 LOG (GNUNET_ERROR_TYPE_WARNING,
1149 _("UNIXPATH `%s' too long, maximum length is %llu\n"), 1162 _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
1150 unixpath, 1163 unixpath,
1151 (unsigned long long)sizeof(s_un.sun_path)); 1164 (unsigned long long) sizeof(s_un.sun_path));
1152 unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath); 1165 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
1153 LOG(GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath); 1166 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
1154 } 1167 }
1155#ifdef LINUX 1168#ifdef LINUX
1156 abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, 1169 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1157 "TESTING", 1170 "TESTING",
1158 "USE_ABSTRACT_SOCKETS"); 1171 "USE_ABSTRACT_SOCKETS");
1159 if (GNUNET_SYSERR == abstract) 1172 if (GNUNET_SYSERR == abstract)
1160 abstract = GNUNET_NO; 1173 abstract = GNUNET_NO;
1161#endif 1174#endif
1162 if ((GNUNET_YES != abstract) && 1175 if ((GNUNET_YES != abstract) &&
1163 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(unixpath))) 1176 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
1164 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); 1177 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
1165 } 1178 }
1166 if (NULL != unixpath) 1179 if (NULL != unixpath)
1180 {
1181 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
1182 if (NULL == desc)
1183 {
1184 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1185 (EACCES == errno))
1186 {
1187 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1188 GNUNET_free_non_null (hostname);
1189 GNUNET_free (unixpath);
1190 return GNUNET_SYSERR;
1191 }
1192 LOG (GNUNET_ERROR_TYPE_INFO,
1193 _ (
1194 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
1195 service_name,
1196 strerror (errno));
1197 GNUNET_free (unixpath);
1198 unixpath = NULL;
1199 }
1200 else
1167 { 1201 {
1168 desc = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0); 1202 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
1169 if (NULL == desc) 1203 desc = NULL;
1170 {
1171 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1172 (EACCES == errno))
1173 {
1174 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket");
1175 GNUNET_free_non_null(hostname);
1176 GNUNET_free(unixpath);
1177 return GNUNET_SYSERR;
1178 }
1179 LOG(GNUNET_ERROR_TYPE_INFO,
1180 _(
1181 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
1182 service_name,
1183 strerror(errno));
1184 GNUNET_free(unixpath);
1185 unixpath = NULL;
1186 }
1187 else
1188 {
1189 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc));
1190 desc = NULL;
1191 }
1192 } 1204 }
1205 }
1193#endif 1206#endif
1194 1207
1195 if ((0 == port) && (NULL == unixpath)) 1208 if ((0 == port) && (NULL == unixpath))
1196 { 1209 {
1197 LOG(GNUNET_ERROR_TYPE_ERROR, 1210 LOG (GNUNET_ERROR_TYPE_ERROR,
1198 _( 1211 _ (
1199 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), 1212 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
1200 service_name); 1213 service_name);
1201 GNUNET_free_non_null(hostname); 1214 GNUNET_free_non_null (hostname);
1215 return GNUNET_SYSERR;
1216 }
1217 if (0 == port)
1218 {
1219 saddrs = GNUNET_malloc (2 * sizeof(struct sockaddr *));
1220 saddrlens = GNUNET_malloc (2 * sizeof(socklen_t));
1221 add_unixpath (saddrs, saddrlens, unixpath, abstract);
1222 GNUNET_free_non_null (unixpath);
1223 GNUNET_free_non_null (hostname);
1224 *addrs = saddrs;
1225 *addr_lens = saddrlens;
1226 return 1;
1227 }
1228
1229 if (NULL != hostname)
1230 {
1231 LOG (GNUNET_ERROR_TYPE_DEBUG,
1232 "Resolving `%s' since that is where `%s' will bind to.\n",
1233 hostname,
1234 service_name);
1235 memset (&hints, 0, sizeof(struct addrinfo));
1236 if (disablev6)
1237 hints.ai_family = AF_INET;
1238 hints.ai_protocol = IPPROTO_TCP;
1239 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
1240 (NULL == res))
1241 {
1242 LOG (GNUNET_ERROR_TYPE_ERROR,
1243 _ ("Failed to resolve `%s': %s\n"),
1244 hostname,
1245 gai_strerror (ret));
1246 GNUNET_free (hostname);
1247 GNUNET_free_non_null (unixpath);
1202 return GNUNET_SYSERR; 1248 return GNUNET_SYSERR;
1203 } 1249 }
1204 if (0 == port) 1250 next = res;
1251 i = 0;
1252 while (NULL != (pos = next))
1205 { 1253 {
1206 saddrs = GNUNET_malloc(2 * sizeof(struct sockaddr *)); 1254 next = pos->ai_next;
1207 saddrlens = GNUNET_malloc(2 * sizeof(socklen_t)); 1255 if ((disablev6) && (pos->ai_family == AF_INET6))
1208 add_unixpath(saddrs, saddrlens, unixpath, abstract); 1256 continue;
1209 GNUNET_free_non_null(unixpath); 1257 i++;
1210 GNUNET_free_non_null(hostname);
1211 *addrs = saddrs;
1212 *addr_lens = saddrlens;
1213 return 1;
1214 } 1258 }
1215 1259 if (0 == i)
1216 if (NULL != hostname)
1217 { 1260 {
1218 LOG(GNUNET_ERROR_TYPE_DEBUG, 1261 LOG (GNUNET_ERROR_TYPE_ERROR,
1219 "Resolving `%s' since that is where `%s' will bind to.\n", 1262 _ ("Failed to find %saddress for `%s'.\n"),
1220 hostname, 1263 disablev6 ? "IPv4 " : "",
1221 service_name); 1264 hostname);
1222 memset(&hints, 0, sizeof(struct addrinfo)); 1265 freeaddrinfo (res);
1223 if (disablev6) 1266 GNUNET_free (hostname);
1224 hints.ai_family = AF_INET; 1267 GNUNET_free_non_null (unixpath);
1225 hints.ai_protocol = IPPROTO_TCP; 1268 return GNUNET_SYSERR;
1226 if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || 1269 }
1227 (NULL == res)) 1270 resi = i;
1228 { 1271 if (NULL != unixpath)
1229 LOG(GNUNET_ERROR_TYPE_ERROR, 1272 resi++;
1230 _("Failed to resolve `%s': %s\n"), 1273 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
1231 hostname, 1274 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
1232 gai_strerror(ret)); 1275 i = 0;
1233 GNUNET_free(hostname); 1276 if (NULL != unixpath)
1234 GNUNET_free_non_null(unixpath); 1277 {
1235 return GNUNET_SYSERR; 1278 add_unixpath (saddrs, saddrlens, unixpath, abstract);
1236 } 1279 i++;
1237 next = res; 1280 }
1238 i = 0; 1281 next = res;
1239 while (NULL != (pos = next)) 1282 while (NULL != (pos = next))
1240 { 1283 {
1241 next = pos->ai_next; 1284 next = pos->ai_next;
1242 if ((disablev6) && (pos->ai_family == AF_INET6)) 1285 if ((disablev6) && (AF_INET6 == pos->ai_family))
1243 continue; 1286 continue;
1244 i++; 1287 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
1245 } 1288 continue; /* not TCP */
1246 if (0 == i) 1289 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
1247 { 1290 continue; /* huh? */
1248 LOG(GNUNET_ERROR_TYPE_ERROR, 1291 LOG (GNUNET_ERROR_TYPE_DEBUG,
1249 _("Failed to find %saddress for `%s'.\n"), 1292 "Service `%s' will bind to `%s'\n",
1250 disablev6 ? "IPv4 " : "", 1293 service_name,
1251 hostname); 1294 GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
1252 freeaddrinfo(res); 1295 if (AF_INET == pos->ai_family)
1253 GNUNET_free(hostname); 1296 {
1254 GNUNET_free_non_null(unixpath); 1297 GNUNET_assert (sizeof(struct sockaddr_in) == pos->ai_addrlen);
1255 return GNUNET_SYSERR; 1298 saddrlens[i] = pos->ai_addrlen;
1256 } 1299 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1257 resi = i; 1300 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1301 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1302 }
1303 else
1304 {
1305 GNUNET_assert (AF_INET6 == pos->ai_family);
1306 GNUNET_assert (sizeof(struct sockaddr_in6) == pos->ai_addrlen);
1307 saddrlens[i] = pos->ai_addrlen;
1308 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1309 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1310 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1311 }
1312 i++;
1313 }
1314 GNUNET_free (hostname);
1315 freeaddrinfo (res);
1316 resi = i;
1317 }
1318 else
1319 {
1320 /* will bind against everything, just set port */
1321 if (disablev6)
1322 {
1323 /* V4-only */
1324 resi = 1;
1258 if (NULL != unixpath) 1325 if (NULL != unixpath)
1259 resi++; 1326 resi++;
1260 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
1261 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
1262 i = 0; 1327 i = 0;
1328 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
1329 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
1263 if (NULL != unixpath) 1330 if (NULL != unixpath)
1264 { 1331 {
1265 add_unixpath(saddrs, saddrlens, unixpath, abstract); 1332 add_unixpath (saddrs, saddrlens, unixpath, abstract);
1266 i++; 1333 i++;
1267 } 1334 }
1268 next = res; 1335 saddrlens[i] = sizeof(struct sockaddr_in);
1269 while (NULL != (pos = next)) 1336 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1270 {
1271 next = pos->ai_next;
1272 if ((disablev6) && (AF_INET6 == pos->ai_family))
1273 continue;
1274 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
1275 continue; /* not TCP */
1276 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
1277 continue; /* huh? */
1278 LOG(GNUNET_ERROR_TYPE_DEBUG,
1279 "Service `%s' will bind to `%s'\n",
1280 service_name,
1281 GNUNET_a2s(pos->ai_addr, pos->ai_addrlen));
1282 if (AF_INET == pos->ai_family)
1283 {
1284 GNUNET_assert(sizeof(struct sockaddr_in) == pos->ai_addrlen);
1285 saddrlens[i] = pos->ai_addrlen;
1286 saddrs[i] = GNUNET_malloc(saddrlens[i]);
1287 GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]);
1288 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port);
1289 }
1290 else
1291 {
1292 GNUNET_assert(AF_INET6 == pos->ai_family);
1293 GNUNET_assert(sizeof(struct sockaddr_in6) == pos->ai_addrlen);
1294 saddrlens[i] = pos->ai_addrlen;
1295 saddrs[i] = GNUNET_malloc(saddrlens[i]);
1296 GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]);
1297 ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port);
1298 }
1299 i++;
1300 }
1301 GNUNET_free(hostname);
1302 freeaddrinfo(res);
1303 resi = i;
1304 }
1305 else
1306 {
1307 /* will bind against everything, just set port */
1308 if (disablev6)
1309 {
1310 /* V4-only */
1311 resi = 1;
1312 if (NULL != unixpath)
1313 resi++;
1314 i = 0;
1315 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
1316 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
1317 if (NULL != unixpath)
1318 {
1319 add_unixpath(saddrs, saddrlens, unixpath, abstract);
1320 i++;
1321 }
1322 saddrlens[i] = sizeof(struct sockaddr_in);
1323 saddrs[i] = GNUNET_malloc(saddrlens[i]);
1324#if HAVE_SOCKADDR_IN_SIN_LEN 1337#if HAVE_SOCKADDR_IN_SIN_LEN
1325 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; 1338 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1326#endif 1339#endif
1327 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; 1340 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1328 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); 1341 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1329 } 1342 }
1330 else 1343 else
1331 { 1344 {
1332 /* dual stack */ 1345 /* dual stack */
1333 resi = 2; 1346 resi = 2;
1334 if (NULL != unixpath) 1347 if (NULL != unixpath)
1335 resi++; 1348 resi++;
1336 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); 1349 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
1337 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); 1350 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
1338 i = 0; 1351 i = 0;
1339 if (NULL != unixpath) 1352 if (NULL != unixpath)
1340 { 1353 {
1341 add_unixpath(saddrs, saddrlens, unixpath, abstract); 1354 add_unixpath (saddrs, saddrlens, unixpath, abstract);
1342 i++; 1355 i++;
1343 } 1356 }
1344 saddrlens[i] = sizeof(struct sockaddr_in6); 1357 saddrlens[i] = sizeof(struct sockaddr_in6);
1345 saddrs[i] = GNUNET_malloc(saddrlens[i]); 1358 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1346#if HAVE_SOCKADDR_IN_SIN_LEN 1359#if HAVE_SOCKADDR_IN_SIN_LEN
1347 ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; 1360 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1348#endif 1361#endif
1349 ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; 1362 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1350 ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); 1363 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1351 i++; 1364 i++;
1352 saddrlens[i] = sizeof(struct sockaddr_in); 1365 saddrlens[i] = sizeof(struct sockaddr_in);
1353 saddrs[i] = GNUNET_malloc(saddrlens[i]); 1366 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1354#if HAVE_SOCKADDR_IN_SIN_LEN 1367#if HAVE_SOCKADDR_IN_SIN_LEN
1355 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1]; 1368 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1356#endif 1369#endif
1357 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; 1370 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1358 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); 1371 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1359 }
1360 } 1372 }
1361 GNUNET_free_non_null(unixpath); 1373 }
1374 GNUNET_free_non_null (unixpath);
1362 *addrs = saddrs; 1375 *addrs = saddrs;
1363 *addr_lens = saddrlens; 1376 *addr_lens = saddrlens;
1364 return resi; 1377 return resi;
@@ -1375,26 +1388,26 @@ get_server_addresses(const char *service_name,
1375 * @param state new state of the session 1388 * @param state new state of the session
1376 */ 1389 */
1377static void 1390static void
1378notify_session_monitor(struct Plugin *plugin, 1391notify_session_monitor (struct Plugin *plugin,
1379 struct GNUNET_ATS_Session *session, 1392 struct GNUNET_ATS_Session *session,
1380 enum GNUNET_TRANSPORT_SessionState state) 1393 enum GNUNET_TRANSPORT_SessionState state)
1381{ 1394{
1382 struct GNUNET_TRANSPORT_SessionInfo info; 1395 struct GNUNET_TRANSPORT_SessionInfo info;
1383 1396
1384 if (NULL == plugin->sic) 1397 if (NULL == plugin->sic)
1385 return; 1398 return;
1386 memset(&info, 0, sizeof(info)); 1399 memset (&info, 0, sizeof(info));
1387 info.state = state; 1400 info.state = state;
1388 info.is_inbound = 1401 info.is_inbound =
1389 GNUNET_HELLO_address_check_option(session->address, 1402 GNUNET_HELLO_address_check_option (session->address,
1390 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 1403 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
1391 info.num_msg_pending = session->msgs_in_queue; 1404 info.num_msg_pending = session->msgs_in_queue;
1392 info.num_bytes_pending = session->bytes_in_queue; 1405 info.num_bytes_pending = session->bytes_in_queue;
1393 if (NULL != session->receive_delay_task) 1406 if (NULL != session->receive_delay_task)
1394 info.receive_delay = session->receive_delay; 1407 info.receive_delay = session->receive_delay;
1395 info.session_timeout = session->timeout; 1408 info.session_timeout = session->timeout;
1396 info.address = session->address; 1409 info.address = session->address;
1397 plugin->sic(plugin->sic_cls, session, &info); 1410 plugin->sic (plugin->sic_cls, session, &info);
1398} 1411}
1399 1412
1400 1413
@@ -1411,12 +1424,12 @@ notify_session_monitor(struct Plugin *plugin,
1411 * @param addrlen actual length of @a addr 1424 * @param addrlen actual length of @a addr
1412 */ 1425 */
1413static void 1426static void
1414tcp_nat_port_map_callback(void *cls, 1427tcp_nat_port_map_callback (void *cls,
1415 void **app_ctx, 1428 void **app_ctx,
1416 int add_remove, 1429 int add_remove,
1417 enum GNUNET_NAT_AddressClass ac, 1430 enum GNUNET_NAT_AddressClass ac,
1418 const struct sockaddr *addr, 1431 const struct sockaddr *addr,
1419 socklen_t addrlen) 1432 socklen_t addrlen)
1420{ 1433{
1421 struct Plugin *plugin = cls; 1434 struct Plugin *plugin = cls;
1422 struct GNUNET_HELLO_Address *address; 1435 struct GNUNET_HELLO_Address *address;
@@ -1425,57 +1438,57 @@ tcp_nat_port_map_callback(void *cls,
1425 void *arg; 1438 void *arg;
1426 size_t args; 1439 size_t args;
1427 1440
1428 (void)app_ctx; 1441 (void) app_ctx;
1429 LOG(GNUNET_ERROR_TYPE_INFO, 1442 LOG (GNUNET_ERROR_TYPE_INFO,
1430 "NAT notification to %s address `%s'\n", 1443 "NAT notification to %s address `%s'\n",
1431 (GNUNET_YES == add_remove) ? "add" : "remove", 1444 (GNUNET_YES == add_remove) ? "add" : "remove",
1432 GNUNET_a2s(addr, addrlen)); 1445 GNUNET_a2s (addr, addrlen));
1433 /* convert 'addr' to our internal format */ 1446 /* convert 'addr' to our internal format */
1434 switch (addr->sa_family) 1447 switch (addr->sa_family)
1435 { 1448 {
1436 case AF_INET: 1449 case AF_INET:
1437 GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); 1450 GNUNET_assert (addrlen == sizeof(struct sockaddr_in));
1438 memset(&t4, 0, sizeof(t4)); 1451 memset (&t4, 0, sizeof(t4));
1439 t4.options = htonl(plugin->myoptions); 1452 t4.options = htonl (plugin->myoptions);
1440 t4.ipv4_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; 1453 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
1441 t4.t4_port = ((struct sockaddr_in *)addr)->sin_port; 1454 t4.t4_port = ((struct sockaddr_in *) addr)->sin_port;
1442 arg = &t4; 1455 arg = &t4;
1443 args = sizeof(t4); 1456 args = sizeof(t4);
1444 break; 1457 break;
1445 1458
1446 case AF_INET6: 1459 case AF_INET6:
1447 if (IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)addr)->sin6_addr)) 1460 if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
1448 { 1461 {
1449 /* skip link local, we don't allow them in 1462 /* skip link local, we don't allow them in
1450 #tcp_plugin_check_address() */ 1463 #tcp_plugin_check_address() */
1451 return;
1452 }
1453 GNUNET_assert(addrlen == sizeof(struct sockaddr_in6));
1454 memset(&t6, 0, sizeof(t6));
1455 GNUNET_memcpy(&t6.ipv6_addr,
1456 &((struct sockaddr_in6 *)addr)->sin6_addr,
1457 sizeof(struct in6_addr));
1458 t6.options = htonl(plugin->myoptions);
1459 t6.t6_port = ((struct sockaddr_in6 *)addr)->sin6_port;
1460 arg = &t6;
1461 args = sizeof(t6);
1462 break;
1463
1464 default:
1465 GNUNET_break(0);
1466 return; 1464 return;
1467 } 1465 }
1466 GNUNET_assert (addrlen == sizeof(struct sockaddr_in6));
1467 memset (&t6, 0, sizeof(t6));
1468 GNUNET_memcpy (&t6.ipv6_addr,
1469 &((struct sockaddr_in6 *) addr)->sin6_addr,
1470 sizeof(struct in6_addr));
1471 t6.options = htonl (plugin->myoptions);
1472 t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
1473 arg = &t6;
1474 args = sizeof(t6);
1475 break;
1476
1477 default:
1478 GNUNET_break (0);
1479 return;
1480 }
1468 /* modify our published address list */ 1481 /* modify our published address list */
1469 GNUNET_assert((args == sizeof(struct IPv4TcpAddress)) || 1482 GNUNET_assert ((args == sizeof(struct IPv4TcpAddress)) ||
1470 (args == sizeof(struct IPv6TcpAddress))); 1483 (args == sizeof(struct IPv6TcpAddress)));
1471 /* TODO: use 'ac' here in the future... */ 1484 /* TODO: use 'ac' here in the future... */
1472 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 1485 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1473 PLUGIN_NAME, 1486 PLUGIN_NAME,
1474 arg, 1487 arg,
1475 args, 1488 args,
1476 GNUNET_HELLO_ADDRESS_INFO_NONE); 1489 GNUNET_HELLO_ADDRESS_INFO_NONE);
1477 plugin->env->notify_address(plugin->env->cls, add_remove, address); 1490 plugin->env->notify_address (plugin->env->cls, add_remove, address);
1478 GNUNET_HELLO_address_free(address); 1491 GNUNET_HELLO_address_free (address);
1479} 1492}
1480 1493
1481 1494
@@ -1491,7 +1504,7 @@ tcp_nat_port_map_callback(void *cls,
1491 * @return string representing the same address 1504 * @return string representing the same address
1492 */ 1505 */
1493static const char * 1506static const char *
1494tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) 1507tcp_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1495{ 1508{
1496 static char rbuf[INET6_ADDRSTRLEN + 12]; 1509 static char rbuf[INET6_ADDRSTRLEN + 12];
1497 char buf[INET6_ADDRSTRLEN]; 1510 char buf[INET6_ADDRSTRLEN];
@@ -1505,43 +1518,43 @@ tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
1505 uint32_t options; 1518 uint32_t options;
1506 1519
1507 switch (addrlen) 1520 switch (addrlen)
1508 { 1521 {
1509 case sizeof(struct IPv6TcpAddress): 1522 case sizeof(struct IPv6TcpAddress):
1510 t6 = addr; 1523 t6 = addr;
1511 af = AF_INET6; 1524 af = AF_INET6;
1512 port = ntohs(t6->t6_port); 1525 port = ntohs (t6->t6_port);
1513 options = ntohl(t6->options); 1526 options = ntohl (t6->options);
1514 GNUNET_memcpy(&a6, &t6->ipv6_addr, sizeof(a6)); 1527 GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof(a6));
1515 sb = &a6; 1528 sb = &a6;
1516 break; 1529 break;
1517 1530
1518 case sizeof(struct IPv4TcpAddress): 1531 case sizeof(struct IPv4TcpAddress):
1519 t4 = addr; 1532 t4 = addr;
1520 af = AF_INET; 1533 af = AF_INET;
1521 port = ntohs(t4->t4_port); 1534 port = ntohs (t4->t4_port);
1522 options = ntohl(t4->options); 1535 options = ntohl (t4->options);
1523 GNUNET_memcpy(&a4, &t4->ipv4_addr, sizeof(a4)); 1536 GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof(a4));
1524 sb = &a4; 1537 sb = &a4;
1525 break; 1538 break;
1526 1539
1527 default: 1540 default:
1528 LOG(GNUNET_ERROR_TYPE_WARNING, 1541 LOG (GNUNET_ERROR_TYPE_WARNING,
1529 _("Unexpected address length: %u bytes\n"), 1542 _ ("Unexpected address length: %u bytes\n"),
1530 (unsigned int)addrlen); 1543 (unsigned int) addrlen);
1531 return NULL; 1544 return NULL;
1532 } 1545 }
1533 if (NULL == inet_ntop(af, sb, buf, INET6_ADDRSTRLEN)) 1546 if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN))
1534 { 1547 {
1535 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 1548 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
1536 return NULL; 1549 return NULL;
1537 } 1550 }
1538 GNUNET_snprintf(rbuf, 1551 GNUNET_snprintf (rbuf,
1539 sizeof(rbuf), 1552 sizeof(rbuf),
1540 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", 1553 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
1541 PLUGIN_NAME, 1554 PLUGIN_NAME,
1542 options, 1555 options,
1543 buf, 1556 buf,
1544 port); 1557 port);
1545 return rbuf; 1558 return rbuf;
1546} 1559}
1547 1560
@@ -1559,11 +1572,11 @@ tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
1559 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1572 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1560 */ 1573 */
1561static int 1574static int
1562tcp_plugin_string_to_address(void *cls, 1575tcp_plugin_string_to_address (void *cls,
1563 const char *addr, 1576 const char *addr,
1564 uint16_t addrlen, 1577 uint16_t addrlen,
1565 void **buf, 1578 void **buf,
1566 size_t *added) 1579 size_t *added)
1567{ 1580{
1568 struct sockaddr_storage socket_address; 1581 struct sockaddr_storage socket_address;
1569 char *address; 1582 char *address;
@@ -1576,57 +1589,57 @@ tcp_plugin_string_to_address(void *cls,
1576 plugin = NULL; 1589 plugin = NULL;
1577 optionstr = NULL; 1590 optionstr = NULL;
1578 if ((NULL == addr) || (0 == addrlen)) 1591 if ((NULL == addr) || (0 == addrlen))
1579 { 1592 {
1580 GNUNET_break(0); 1593 GNUNET_break (0);
1581 return GNUNET_SYSERR; 1594 return GNUNET_SYSERR;
1582 } 1595 }
1583 if ('\0' != addr[addrlen - 1]) 1596 if ('\0' != addr[addrlen - 1])
1584 { 1597 {
1585 GNUNET_break(0); 1598 GNUNET_break (0);
1586 return GNUNET_SYSERR; 1599 return GNUNET_SYSERR;
1587 } 1600 }
1588 if (strlen(addr) != addrlen - 1) 1601 if (strlen (addr) != addrlen - 1)
1589 { 1602 {
1590 GNUNET_break(0); 1603 GNUNET_break (0);
1591 return GNUNET_SYSERR; 1604 return GNUNET_SYSERR;
1592 } 1605 }
1593 plugin = GNUNET_strdup(addr); 1606 plugin = GNUNET_strdup (addr);
1594 optionstr = strchr(plugin, '.'); 1607 optionstr = strchr (plugin, '.');
1595 if (NULL == optionstr) 1608 if (NULL == optionstr)
1596 { 1609 {
1597 GNUNET_break(0); 1610 GNUNET_break (0);
1598 GNUNET_free(plugin); 1611 GNUNET_free (plugin);
1599 return GNUNET_SYSERR; 1612 return GNUNET_SYSERR;
1600 } 1613 }
1601 optionstr[0] = '\0'; 1614 optionstr[0] = '\0';
1602 optionstr++; 1615 optionstr++;
1603 options = atol(optionstr); 1616 options = atol (optionstr);
1604 address = strchr(optionstr, '.'); 1617 address = strchr (optionstr, '.');
1605 if (NULL == address) 1618 if (NULL == address)
1606 { 1619 {
1607 GNUNET_break(0); 1620 GNUNET_break (0);
1608 GNUNET_free(plugin); 1621 GNUNET_free (plugin);
1609 return GNUNET_SYSERR; 1622 return GNUNET_SYSERR;
1610 } 1623 }
1611 address[0] = '\0'; 1624 address[0] = '\0';
1612 address++; 1625 address++;
1613 1626
1614 if (GNUNET_OK != 1627 if (GNUNET_OK !=
1615 GNUNET_STRINGS_to_address_ip(address, strlen(address), &socket_address)) 1628 GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address))
1616 { 1629 {
1617 GNUNET_break(0); 1630 GNUNET_break (0);
1618 GNUNET_free(plugin); 1631 GNUNET_free (plugin);
1619 return GNUNET_SYSERR; 1632 return GNUNET_SYSERR;
1620 } 1633 }
1621 1634
1622 GNUNET_free(plugin); 1635 GNUNET_free (plugin);
1623 switch (socket_address.ss_family) 1636 switch (socket_address.ss_family)
1624 { 1637 {
1625 case AF_INET: { 1638 case AF_INET: {
1626 struct IPv4TcpAddress *t4; 1639 struct IPv4TcpAddress *t4;
1627 struct sockaddr_in *in4 = (struct sockaddr_in *)&socket_address; 1640 struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address;
1628 t4 = GNUNET_new(struct IPv4TcpAddress); 1641 t4 = GNUNET_new (struct IPv4TcpAddress);
1629 t4->options = htonl(options); 1642 t4->options = htonl (options);
1630 t4->ipv4_addr = in4->sin_addr.s_addr; 1643 t4->ipv4_addr = in4->sin_addr.s_addr;
1631 t4->t4_port = in4->sin_port; 1644 t4->t4_port = in4->sin_port;
1632 *buf = t4; 1645 *buf = t4;
@@ -1634,11 +1647,11 @@ tcp_plugin_string_to_address(void *cls,
1634 return GNUNET_OK; 1647 return GNUNET_OK;
1635 } 1648 }
1636 1649
1637 case AF_INET6: { 1650 case AF_INET6: {
1638 struct IPv6TcpAddress *t6; 1651 struct IPv6TcpAddress *t6;
1639 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&socket_address; 1652 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address;
1640 t6 = GNUNET_new(struct IPv6TcpAddress); 1653 t6 = GNUNET_new (struct IPv6TcpAddress);
1641 t6->options = htonl(options); 1654 t6->options = htonl (options);
1642 t6->ipv6_addr = in6->sin6_addr; 1655 t6->ipv6_addr = in6->sin6_addr;
1643 t6->t6_port = in6->sin6_port; 1656 t6->t6_port = in6->sin6_port;
1644 *buf = t6; 1657 *buf = t6;
@@ -1646,9 +1659,9 @@ tcp_plugin_string_to_address(void *cls,
1646 return GNUNET_OK; 1659 return GNUNET_OK;
1647 } 1660 }
1648 1661
1649 default: 1662 default:
1650 return GNUNET_SYSERR; 1663 return GNUNET_SYSERR;
1651 } 1664 }
1652} 1665}
1653 1666
1654 1667
@@ -1663,11 +1676,11 @@ tcp_plugin_string_to_address(void *cls,
1663 * @return NULL if no matching session exists 1676 * @return NULL if no matching session exists
1664 */ 1677 */
1665static struct GNUNET_ATS_Session * 1678static struct GNUNET_ATS_Session *
1666lookup_session_by_client(struct Plugin *plugin, 1679lookup_session_by_client (struct Plugin *plugin,
1667 struct GNUNET_SERVER_Client *client) 1680 struct GNUNET_SERVER_Client *client)
1668{ 1681{
1669 return GNUNET_SERVER_client_get_user_context(client, 1682 return GNUNET_SERVER_client_get_user_context (client,
1670 struct GNUNET_ATS_Session); 1683 struct GNUNET_ATS_Session);
1671} 1684}
1672 1685
1673 1686
@@ -1681,111 +1694,111 @@ lookup_session_by_client(struct Plugin *plugin,
1681 * @return #GNUNET_OK on success 1694 * @return #GNUNET_OK on success
1682 */ 1695 */
1683static int 1696static int
1684tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session) 1697tcp_plugin_disconnect_session (void *cls, struct GNUNET_ATS_Session *session)
1685{ 1698{
1686 struct Plugin *plugin = cls; 1699 struct Plugin *plugin = cls;
1687 struct PendingMessage *pm; 1700 struct PendingMessage *pm;
1688 1701
1689 LOG(GNUNET_ERROR_TYPE_DEBUG, 1702 LOG (GNUNET_ERROR_TYPE_DEBUG,
1690 "Disconnecting session of peer `%s' address `%s'\n", 1703 "Disconnecting session of peer `%s' address `%s'\n",
1691 GNUNET_i2s(&session->target), 1704 GNUNET_i2s (&session->target),
1692 tcp_plugin_address_to_string(session->plugin, 1705 tcp_plugin_address_to_string (session->plugin,
1693 session->address->address, 1706 session->address->address,
1694 session->address->address_length)); 1707 session->address->address_length));
1695 1708
1696 if (NULL != session->timeout_task) 1709 if (NULL != session->timeout_task)
1697 { 1710 {
1698 GNUNET_SCHEDULER_cancel(session->timeout_task); 1711 GNUNET_SCHEDULER_cancel (session->timeout_task);
1699 session->timeout_task = NULL; 1712 session->timeout_task = NULL;
1700 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 1713 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
1701 } 1714 }
1702 1715
1703 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(plugin->sessionmap, 1716 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap,
1704 &session->target, 1717 &session->target,
1705 session)) 1718 session))
1706 { 1719 {
1707 GNUNET_STATISTICS_update(session->plugin->env->stats, 1720 GNUNET_STATISTICS_update (session->plugin->env->stats,
1708 gettext_noop("# TCP sessions active"), 1721 gettext_noop ("# TCP sessions active"),
1709 -1, 1722 -1,
1710 GNUNET_NO); 1723 GNUNET_NO);
1711 } 1724 }
1712 else 1725 else
1713 { 1726 {
1714 GNUNET_assert(GNUNET_YES == 1727 GNUNET_assert (GNUNET_YES ==
1715 GNUNET_CONTAINER_multipeermap_remove(plugin->nat_wait_conns, 1728 GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns,
1716 &session->target, 1729 &session->target,
1717 session)); 1730 session));
1718 } 1731 }
1719 if (NULL != session->client) 1732 if (NULL != session->client)
1720 GNUNET_SERVER_client_set_user_context(session->client, NULL); 1733 GNUNET_SERVER_client_set_user_context (session->client, NULL);
1721 1734
1722 /* clean up state */ 1735 /* clean up state */
1723 if (NULL != session->transmit_handle) 1736 if (NULL != session->transmit_handle)
1724 { 1737 {
1725 GNUNET_SERVER_notify_transmit_ready_cancel(session->transmit_handle); 1738 GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle);
1726 session->transmit_handle = NULL; 1739 session->transmit_handle = NULL;
1727 } 1740 }
1728 session->plugin->env->session_end(session->plugin->env->cls, 1741 session->plugin->env->session_end (session->plugin->env->cls,
1729 session->address, 1742 session->address,
1730 session); 1743 session);
1731 1744
1732 if (NULL != session->nat_connection_timeout) 1745 if (NULL != session->nat_connection_timeout)
1733 { 1746 {
1734 GNUNET_SCHEDULER_cancel(session->nat_connection_timeout); 1747 GNUNET_SCHEDULER_cancel (session->nat_connection_timeout);
1735 session->nat_connection_timeout = NULL; 1748 session->nat_connection_timeout = NULL;
1736 } 1749 }
1737 1750
1738 while (NULL != (pm = session->pending_messages_head)) 1751 while (NULL != (pm = session->pending_messages_head))
1739 { 1752 {
1740 LOG(GNUNET_ERROR_TYPE_DEBUG, 1753 LOG (GNUNET_ERROR_TYPE_DEBUG,
1741 (NULL != pm->transmit_cont) 1754 (NULL != pm->transmit_cont)
1742 ? "Could not deliver message to `%s' at %s.\n" 1755 ? "Could not deliver message to `%s' at %s.\n"
1743 : "Could not deliver message to `%s' at %s, notifying.\n", 1756 : "Could not deliver message to `%s' at %s, notifying.\n",
1744 GNUNET_i2s(&session->target), 1757 GNUNET_i2s (&session->target),
1745 tcp_plugin_address_to_string(session->plugin, 1758 tcp_plugin_address_to_string (session->plugin,
1746 session->address->address, 1759 session->address->address,
1747 session->address->address_length)); 1760 session->address->address_length));
1748 GNUNET_STATISTICS_update(session->plugin->env->stats, 1761 GNUNET_STATISTICS_update (session->plugin->env->stats,
1749 gettext_noop("# bytes currently in TCP buffers"), 1762 gettext_noop ("# bytes currently in TCP buffers"),
1750 -(int64_t)pm->message_size, 1763 -(int64_t) pm->message_size,
1751 GNUNET_NO); 1764 GNUNET_NO);
1752 GNUNET_STATISTICS_update(session->plugin->env->stats, 1765 GNUNET_STATISTICS_update (session->plugin->env->stats,
1753 gettext_noop( 1766 gettext_noop (
1754 "# bytes discarded by TCP (disconnect)"), 1767 "# bytes discarded by TCP (disconnect)"),
1755 pm->message_size, 1768 pm->message_size,
1756 GNUNET_NO); 1769 GNUNET_NO);
1757 GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, 1770 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
1758 session->pending_messages_tail, 1771 session->pending_messages_tail,
1759 pm); 1772 pm);
1760 GNUNET_assert(0 < session->msgs_in_queue); 1773 GNUNET_assert (0 < session->msgs_in_queue);
1761 session->msgs_in_queue--; 1774 session->msgs_in_queue--;
1762 GNUNET_assert(pm->message_size <= session->bytes_in_queue); 1775 GNUNET_assert (pm->message_size <= session->bytes_in_queue);
1763 session->bytes_in_queue -= pm->message_size; 1776 session->bytes_in_queue -= pm->message_size;
1764 if (NULL != pm->transmit_cont) 1777 if (NULL != pm->transmit_cont)
1765 pm->transmit_cont(pm->transmit_cont_cls, 1778 pm->transmit_cont (pm->transmit_cont_cls,
1766 &session->target, 1779 &session->target,
1767 GNUNET_SYSERR, 1780 GNUNET_SYSERR,
1768 pm->message_size, 1781 pm->message_size,
1769 0); 1782 0);
1770 GNUNET_free(pm); 1783 GNUNET_free (pm);
1771 } 1784 }
1772 GNUNET_assert(0 == session->msgs_in_queue); 1785 GNUNET_assert (0 == session->msgs_in_queue);
1773 GNUNET_assert(0 == session->bytes_in_queue); 1786 GNUNET_assert (0 == session->bytes_in_queue);
1774 notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_DONE); 1787 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_DONE);
1775 1788
1776 if (NULL != session->receive_delay_task) 1789 if (NULL != session->receive_delay_task)
1777 { 1790 {
1778 GNUNET_SCHEDULER_cancel(session->receive_delay_task); 1791 GNUNET_SCHEDULER_cancel (session->receive_delay_task);
1779 session->receive_delay_task = NULL; 1792 session->receive_delay_task = NULL;
1780 } 1793 }
1781 if (NULL != session->client) 1794 if (NULL != session->client)
1782 { 1795 {
1783 GNUNET_SERVER_client_disconnect(session->client); 1796 GNUNET_SERVER_client_disconnect (session->client);
1784 session->client = NULL; 1797 session->client = NULL;
1785 } 1798 }
1786 GNUNET_HELLO_address_free(session->address); 1799 GNUNET_HELLO_address_free (session->address);
1787 GNUNET_assert(NULL == session->transmit_handle); 1800 GNUNET_assert (NULL == session->transmit_handle);
1788 GNUNET_free(session); 1801 GNUNET_free (session);
1789 return GNUNET_OK; 1802 return GNUNET_OK;
1790} 1803}
1791 1804
@@ -1799,7 +1812,7 @@ tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session)
1799 * @return keepalive factor 1812 * @return keepalive factor
1800 */ 1813 */
1801static unsigned int 1814static unsigned int
1802tcp_plugin_query_keepalive_factor(void *cls) 1815tcp_plugin_query_keepalive_factor (void *cls)
1803{ 1816{
1804 return 3; 1817 return 3;
1805} 1818}
@@ -1811,29 +1824,29 @@ tcp_plugin_query_keepalive_factor(void *cls)
1811 * @param cls the `struct GNUNET_ATS_Session` of the idle session 1824 * @param cls the `struct GNUNET_ATS_Session` of the idle session
1812 */ 1825 */
1813static void 1826static void
1814session_timeout(void *cls) 1827session_timeout (void *cls)
1815{ 1828{
1816 struct GNUNET_ATS_Session *s = cls; 1829 struct GNUNET_ATS_Session *s = cls;
1817 struct GNUNET_TIME_Relative left; 1830 struct GNUNET_TIME_Relative left;
1818 1831
1819 s->timeout_task = NULL; 1832 s->timeout_task = NULL;
1820 left = GNUNET_TIME_absolute_get_remaining(s->timeout); 1833 left = GNUNET_TIME_absolute_get_remaining (s->timeout);
1821 if (0 != left.rel_value_us) 1834 if (0 != left.rel_value_us)
1822 { 1835 {
1823 /* not actually our turn yet, but let's at least update 1836 /* not actually our turn yet, but let's at least update
1824 the monitor, it may think we're about to die ... */ 1837 the monitor, it may think we're about to die ... */
1825 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 1838 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
1826 s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, &session_timeout, s); 1839 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s);
1827 return; 1840 return;
1828 } 1841 }
1829 LOG(GNUNET_ERROR_TYPE_DEBUG, 1842 LOG (GNUNET_ERROR_TYPE_DEBUG,
1830 "Session %p was idle for %s, disconnecting\n", 1843 "Session %p was idle for %s, disconnecting\n",
1831 s, 1844 s,
1832 GNUNET_STRINGS_relative_time_to_string( 1845 GNUNET_STRINGS_relative_time_to_string (
1833 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1846 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1834 GNUNET_YES)); 1847 GNUNET_YES));
1835 /* call session destroy function */ 1848 /* call session destroy function */
1836 tcp_plugin_disconnect_session(s->plugin, s); 1849 tcp_plugin_disconnect_session (s->plugin, s);
1837} 1850}
1838 1851
1839 1852
@@ -1843,11 +1856,11 @@ session_timeout(void *cls)
1843 * @param s session to increment timeout for 1856 * @param s session to increment timeout for
1844 */ 1857 */
1845static void 1858static void
1846reschedule_session_timeout(struct GNUNET_ATS_Session *s) 1859reschedule_session_timeout (struct GNUNET_ATS_Session *s)
1847{ 1860{
1848 GNUNET_assert(NULL != s->timeout_task); 1861 GNUNET_assert (NULL != s->timeout_task);
1849 s->timeout = 1862 s->timeout =
1850 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1863 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1851} 1864}
1852 1865
1853 1866
@@ -1864,75 +1877,75 @@ reschedule_session_timeout(struct GNUNET_ATS_Session *s)
1864 * @return new session object 1877 * @return new session object
1865 */ 1878 */
1866static struct GNUNET_ATS_Session * 1879static struct GNUNET_ATS_Session *
1867create_session(struct Plugin *plugin, 1880create_session (struct Plugin *plugin,
1868 const struct GNUNET_HELLO_Address *address, 1881 const struct GNUNET_HELLO_Address *address,
1869 enum GNUNET_NetworkType scope, 1882 enum GNUNET_NetworkType scope,
1870 struct GNUNET_SERVER_Client *client, 1883 struct GNUNET_SERVER_Client *client,
1871 int is_nat) 1884 int is_nat)
1872{ 1885{
1873 struct GNUNET_ATS_Session *session; 1886 struct GNUNET_ATS_Session *session;
1874 struct PendingMessage *pm; 1887 struct PendingMessage *pm;
1875 1888
1876 if (GNUNET_YES != is_nat) 1889 if (GNUNET_YES != is_nat)
1877 GNUNET_assert(NULL != client); 1890 GNUNET_assert (NULL != client);
1878 else 1891 else
1879 GNUNET_assert(NULL == client); 1892 GNUNET_assert (NULL == client);
1880 1893
1881 LOG(GNUNET_ERROR_TYPE_DEBUG, 1894 LOG (GNUNET_ERROR_TYPE_DEBUG,
1882 "Creating new session for peer `%s' at address %s\n", 1895 "Creating new session for peer `%s' at address %s\n",
1883 GNUNET_i2s(&address->peer), 1896 GNUNET_i2s (&address->peer),
1884 tcp_plugin_address_to_string(plugin, 1897 tcp_plugin_address_to_string (plugin,
1885 address->address, 1898 address->address,
1886 address->address_length)); 1899 address->address_length));
1887 session = GNUNET_new(struct GNUNET_ATS_Session); 1900 session = GNUNET_new (struct GNUNET_ATS_Session);
1888 session->last_activity = GNUNET_TIME_absolute_get(); 1901 session->last_activity = GNUNET_TIME_absolute_get ();
1889 session->plugin = plugin; 1902 session->plugin = plugin;
1890 session->is_nat = is_nat; 1903 session->is_nat = is_nat;
1891 if (NULL != client) 1904 if (NULL != client)
1892 { 1905 {
1893 session->client = client; 1906 session->client = client;
1894 GNUNET_SERVER_client_set_user_context(client, session); 1907 GNUNET_SERVER_client_set_user_context (client, session);
1895 } 1908 }
1896 session->address = GNUNET_HELLO_address_copy(address); 1909 session->address = GNUNET_HELLO_address_copy (address);
1897 session->target = address->peer; 1910 session->target = address->peer;
1898 session->expecting_welcome = GNUNET_YES; 1911 session->expecting_welcome = GNUNET_YES;
1899 session->scope = scope; 1912 session->scope = scope;
1900 pm = GNUNET_malloc(sizeof(struct PendingMessage) + 1913 pm = GNUNET_malloc (sizeof(struct PendingMessage)
1901 sizeof(struct WelcomeMessage)); 1914 + sizeof(struct WelcomeMessage));
1902 pm->msg = (const char *)&pm[1]; 1915 pm->msg = (const char *) &pm[1];
1903 pm->message_size = sizeof(struct WelcomeMessage); 1916 pm->message_size = sizeof(struct WelcomeMessage);
1904 GNUNET_memcpy(&pm[1], &plugin->my_welcome, sizeof(struct WelcomeMessage)); 1917 GNUNET_memcpy (&pm[1], &plugin->my_welcome, sizeof(struct WelcomeMessage));
1905 pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 1918 pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
1906 GNUNET_STATISTICS_update(plugin->env->stats, 1919 GNUNET_STATISTICS_update (plugin->env->stats,
1907 gettext_noop("# bytes currently in TCP buffers"), 1920 gettext_noop ("# bytes currently in TCP buffers"),
1908 pm->message_size, 1921 pm->message_size,
1909 GNUNET_NO); 1922 GNUNET_NO);
1910 GNUNET_CONTAINER_DLL_insert(session->pending_messages_head, 1923 GNUNET_CONTAINER_DLL_insert (session->pending_messages_head,
1911 session->pending_messages_tail, 1924 session->pending_messages_tail,
1912 pm); 1925 pm);
1913 session->msgs_in_queue++; 1926 session->msgs_in_queue++;
1914 session->bytes_in_queue += pm->message_size; 1927 session->bytes_in_queue += pm->message_size;
1915 session->timeout = 1928 session->timeout =
1916 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1929 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1917 session->timeout_task = 1930 session->timeout_task =
1918 GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1931 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1919 &session_timeout, 1932 &session_timeout,
1920 session); 1933 session);
1921 notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_INIT); 1934 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_INIT);
1922 if (GNUNET_YES != is_nat) 1935 if (GNUNET_YES != is_nat)
1923 { 1936 {
1924 GNUNET_STATISTICS_update(plugin->env->stats, 1937 GNUNET_STATISTICS_update (plugin->env->stats,
1925 gettext_noop("# TCP sessions active"), 1938 gettext_noop ("# TCP sessions active"),
1926 1, 1939 1,
1927 GNUNET_NO); 1940 GNUNET_NO);
1928 notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_UP); 1941 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UP);
1929 } 1942 }
1930 else 1943 else
1931 { 1944 {
1932 notify_session_monitor(session->plugin, 1945 notify_session_monitor (session->plugin,
1933 session, 1946 session,
1934 GNUNET_TRANSPORT_SS_HANDSHAKE); 1947 GNUNET_TRANSPORT_SS_HANDSHAKE);
1935 } 1948 }
1936 return session; 1949 return session;
1937} 1950}
1938 1951
@@ -1944,7 +1957,7 @@ create_session(struct Plugin *plugin,
1944 * @param session for which session should we do this 1957 * @param session for which session should we do this
1945 */ 1958 */
1946static void 1959static void
1947process_pending_messages(struct GNUNET_ATS_Session *session); 1960process_pending_messages (struct GNUNET_ATS_Session *session);
1948 1961
1949 1962
1950/** 1963/**
@@ -1959,7 +1972,7 @@ process_pending_messages(struct GNUNET_ATS_Session *session);
1959 * @return number of bytes written to @a buf 1972 * @return number of bytes written to @a buf
1960 */ 1973 */
1961static size_t 1974static size_t
1962do_transmit(void *cls, size_t size, void *buf) 1975do_transmit (void *cls, size_t size, void *buf)
1963{ 1976{
1964 struct GNUNET_ATS_Session *session = cls; 1977 struct GNUNET_ATS_Session *session = cls;
1965 struct GNUNET_PeerIdentity pid; 1978 struct GNUNET_PeerIdentity pid;
@@ -1974,127 +1987,127 @@ do_transmit(void *cls, size_t size, void *buf)
1974 session->transmit_handle = NULL; 1987 session->transmit_handle = NULL;
1975 plugin = session->plugin; 1988 plugin = session->plugin;
1976 if (NULL == buf) 1989 if (NULL == buf)
1977 { 1990 {
1978 LOG(GNUNET_ERROR_TYPE_DEBUG, 1991 LOG (GNUNET_ERROR_TYPE_DEBUG,
1979 "Timeout trying to transmit to peer `%s', discarding message queue.\n", 1992 "Timeout trying to transmit to peer `%s', discarding message queue.\n",
1980 GNUNET_i2s(&session->target)); 1993 GNUNET_i2s (&session->target));
1981 /* timeout; cancel all messages that have already expired */ 1994 /* timeout; cancel all messages that have already expired */
1982 hd = NULL; 1995 hd = NULL;
1983 tl = NULL; 1996 tl = NULL;
1984 ret = 0; 1997 ret = 0;
1985 now = GNUNET_TIME_absolute_get(); 1998 now = GNUNET_TIME_absolute_get ();
1986 while ((NULL != (pos = session->pending_messages_head)) && 1999 while ((NULL != (pos = session->pending_messages_head)) &&
1987 (pos->timeout.abs_value_us <= now.abs_value_us)) 2000 (pos->timeout.abs_value_us <= now.abs_value_us))
1988 { 2001 {
1989 GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, 2002 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
1990 session->pending_messages_tail, 2003 session->pending_messages_tail,
1991 pos); 2004 pos);
1992 GNUNET_assert(0 < session->msgs_in_queue); 2005 GNUNET_assert (0 < session->msgs_in_queue);
1993 session->msgs_in_queue--; 2006 session->msgs_in_queue--;
1994 GNUNET_assert(pos->message_size <= session->bytes_in_queue); 2007 GNUNET_assert (pos->message_size <= session->bytes_in_queue);
1995 session->bytes_in_queue -= pos->message_size; 2008 session->bytes_in_queue -= pos->message_size;
1996 LOG(GNUNET_ERROR_TYPE_DEBUG, 2009 LOG (GNUNET_ERROR_TYPE_DEBUG,
1997 "Failed to transmit %u byte message to `%s'.\n", 2010 "Failed to transmit %u byte message to `%s'.\n",
1998 pos->message_size, 2011 pos->message_size,
1999 GNUNET_i2s(&session->target)); 2012 GNUNET_i2s (&session->target));
2000 ret += pos->message_size; 2013 ret += pos->message_size;
2001 GNUNET_CONTAINER_DLL_insert_after(hd, tl, tl, pos); 2014 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
2002 } 2015 }
2003 /* do this call before callbacks (so that if callbacks destroy 2016 /* do this call before callbacks (so that if callbacks destroy
2004 * session, they have a chance to cancel actions done by this 2017 * session, they have a chance to cancel actions done by this
2005 * call) */ 2018 * call) */
2006 process_pending_messages(session); 2019 process_pending_messages (session);
2007 pid = session->target; 2020 pid = session->target;
2008 /* no do callbacks and do not use session again since 2021 /* no do callbacks and do not use session again since
2009 * the callbacks may abort the session */ 2022 * the callbacks may abort the session */
2010 while (NULL != (pos = hd)) 2023 while (NULL != (pos = hd))
2011 { 2024 {
2012 GNUNET_CONTAINER_DLL_remove(hd, tl, pos); 2025 GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
2013 if (NULL != pos->transmit_cont) 2026 if (NULL != pos->transmit_cont)
2014 pos->transmit_cont(pos->transmit_cont_cls, 2027 pos->transmit_cont (pos->transmit_cont_cls,
2015 &pid, 2028 &pid,
2016 GNUNET_SYSERR, 2029 GNUNET_SYSERR,
2017 pos->message_size, 2030 pos->message_size,
2018 0); 2031 0);
2019 GNUNET_free(pos); 2032 GNUNET_free (pos);
2020 } 2033 }
2021 GNUNET_STATISTICS_update(plugin->env->stats, 2034 GNUNET_STATISTICS_update (plugin->env->stats,
2022 gettext_noop("# bytes currently in TCP buffers"), 2035 gettext_noop ("# bytes currently in TCP buffers"),
2023 -(int64_t)ret, 2036 -(int64_t) ret,
2024 GNUNET_NO); 2037 GNUNET_NO);
2025 GNUNET_STATISTICS_update(plugin->env->stats, 2038 GNUNET_STATISTICS_update (plugin->env->stats,
2026 gettext_noop( 2039 gettext_noop (
2027 "# bytes discarded by TCP (timeout)"), 2040 "# bytes discarded by TCP (timeout)"),
2028 ret, 2041 ret,
2029 GNUNET_NO); 2042 GNUNET_NO);
2030 if (0 < ret) 2043 if (0 < ret)
2031 notify_session_monitor(session->plugin, 2044 notify_session_monitor (session->plugin,
2032 session, 2045 session,
2033 GNUNET_TRANSPORT_SS_UPDATE); 2046 GNUNET_TRANSPORT_SS_UPDATE);
2034 return 0; 2047 return 0;
2035 } 2048 }
2036 /* copy all pending messages that would fit */ 2049 /* copy all pending messages that would fit */
2037 ret = 0; 2050 ret = 0;
2038 cbuf = buf; 2051 cbuf = buf;
2039 hd = NULL; 2052 hd = NULL;
2040 tl = NULL; 2053 tl = NULL;
2041 while (NULL != (pos = session->pending_messages_head)) 2054 while (NULL != (pos = session->pending_messages_head))
2042 { 2055 {
2043 if (ret + pos->message_size > size) 2056 if (ret + pos->message_size > size)
2044 break; 2057 break;
2045 GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, 2058 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
2046 session->pending_messages_tail, 2059 session->pending_messages_tail,
2047 pos); 2060 pos);
2048 GNUNET_assert(0 < session->msgs_in_queue); 2061 GNUNET_assert (0 < session->msgs_in_queue);
2049 session->msgs_in_queue--; 2062 session->msgs_in_queue--;
2050 GNUNET_assert(pos->message_size <= session->bytes_in_queue); 2063 GNUNET_assert (pos->message_size <= session->bytes_in_queue);
2051 session->bytes_in_queue -= pos->message_size; 2064 session->bytes_in_queue -= pos->message_size;
2052 GNUNET_assert(size >= pos->message_size); 2065 GNUNET_assert (size >= pos->message_size);
2053 LOG(GNUNET_ERROR_TYPE_DEBUG, 2066 LOG (GNUNET_ERROR_TYPE_DEBUG,
2054 "Transmitting message of type %u size %u to peer %s at %s\n", 2067 "Transmitting message of type %u size %u to peer %s at %s\n",
2055 ntohs(((struct GNUNET_MessageHeader *)pos->msg)->type), 2068 ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type),
2056 pos->message_size, 2069 pos->message_size,
2057 GNUNET_i2s(&session->target), 2070 GNUNET_i2s (&session->target),
2058 tcp_plugin_address_to_string(session->plugin, 2071 tcp_plugin_address_to_string (session->plugin,
2059 session->address->address, 2072 session->address->address,
2060 session->address->address_length)); 2073 session->address->address_length));
2061 /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */ 2074 /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */
2062 GNUNET_memcpy(cbuf, pos->msg, pos->message_size); 2075 GNUNET_memcpy (cbuf, pos->msg, pos->message_size);
2063 cbuf += pos->message_size; 2076 cbuf += pos->message_size;
2064 ret += pos->message_size; 2077 ret += pos->message_size;
2065 size -= pos->message_size; 2078 size -= pos->message_size;
2066 GNUNET_CONTAINER_DLL_insert_tail(hd, tl, pos); 2079 GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos);
2067 } 2080 }
2068 notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 2081 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
2069 /* schedule 'continuation' before callbacks so that callbacks that 2082 /* schedule 'continuation' before callbacks so that callbacks that
2070 * cancel everything don't cause us to use a session that no longer 2083 * cancel everything don't cause us to use a session that no longer
2071 * exists... */ 2084 * exists... */
2072 process_pending_messages(session); 2085 process_pending_messages (session);
2073 session->last_activity = GNUNET_TIME_absolute_get(); 2086 session->last_activity = GNUNET_TIME_absolute_get ();
2074 pid = session->target; 2087 pid = session->target;
2075 /* we'll now call callbacks that may cancel the session; hence 2088 /* we'll now call callbacks that may cancel the session; hence
2076 * we should not use 'session' after this point */ 2089 * we should not use 'session' after this point */
2077 while (NULL != (pos = hd)) 2090 while (NULL != (pos = hd))
2078 { 2091 {
2079 GNUNET_CONTAINER_DLL_remove(hd, tl, pos); 2092 GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
2080 if (NULL != pos->transmit_cont) 2093 if (NULL != pos->transmit_cont)
2081 pos->transmit_cont(pos->transmit_cont_cls, 2094 pos->transmit_cont (pos->transmit_cont_cls,
2082 &pid, 2095 &pid,
2083 GNUNET_OK, 2096 GNUNET_OK,
2084 pos->message_size, 2097 pos->message_size,
2085 pos->message_size); /* FIXME: include TCP overhead */ 2098 pos->message_size); /* FIXME: include TCP overhead */
2086 GNUNET_free(pos); 2099 GNUNET_free (pos);
2087 } 2100 }
2088 GNUNET_assert(NULL == hd); 2101 GNUNET_assert (NULL == hd);
2089 GNUNET_assert(NULL == tl); 2102 GNUNET_assert (NULL == tl);
2090 GNUNET_STATISTICS_update(plugin->env->stats, 2103 GNUNET_STATISTICS_update (plugin->env->stats,
2091 gettext_noop("# bytes currently in TCP buffers"), 2104 gettext_noop ("# bytes currently in TCP buffers"),
2092 -(int64_t)ret, 2105 -(int64_t) ret,
2093 GNUNET_NO); 2106 GNUNET_NO);
2094 GNUNET_STATISTICS_update(plugin->env->stats, 2107 GNUNET_STATISTICS_update (plugin->env->stats,
2095 gettext_noop("# bytes transmitted via TCP"), 2108 gettext_noop ("# bytes transmitted via TCP"),
2096 ret, 2109 ret,
2097 GNUNET_NO); 2110 GNUNET_NO);
2098 return ret; 2111 return ret;
2099} 2112}
2100 2113
@@ -2106,23 +2119,23 @@ do_transmit(void *cls, size_t size, void *buf)
2106 * @param session for which session should we do this 2119 * @param session for which session should we do this
2107 */ 2120 */
2108static void 2121static void
2109process_pending_messages(struct GNUNET_ATS_Session *session) 2122process_pending_messages (struct GNUNET_ATS_Session *session)
2110{ 2123{
2111 struct PendingMessage *pm; 2124 struct PendingMessage *pm;
2112 2125
2113 GNUNET_assert(NULL != session->client); 2126 GNUNET_assert (NULL != session->client);
2114 if (NULL != session->transmit_handle) 2127 if (NULL != session->transmit_handle)
2115 return; 2128 return;
2116 if (NULL == (pm = session->pending_messages_head)) 2129 if (NULL == (pm = session->pending_messages_head))
2117 return; 2130 return;
2118 2131
2119 session->transmit_handle = 2132 session->transmit_handle =
2120 GNUNET_SERVER_notify_transmit_ready(session->client, 2133 GNUNET_SERVER_notify_transmit_ready (session->client,
2121 pm->message_size, 2134 pm->message_size,
2122 GNUNET_TIME_absolute_get_remaining( 2135 GNUNET_TIME_absolute_get_remaining (
2123 pm->timeout), 2136 pm->timeout),
2124 &do_transmit, 2137 &do_transmit,
2125 session); 2138 session);
2126} 2139}
2127 2140
2128 2141
@@ -2154,85 +2167,85 @@ process_pending_messages(struct GNUNET_ATS_Session *session)
2154 * and does NOT mean that the message was not transmitted (DV) 2167 * and does NOT mean that the message was not transmitted (DV)
2155 */ 2168 */
2156static ssize_t 2169static ssize_t
2157tcp_plugin_send(void *cls, 2170tcp_plugin_send (void *cls,
2158 struct GNUNET_ATS_Session *session, 2171 struct GNUNET_ATS_Session *session,
2159 const char *msgbuf, 2172 const char *msgbuf,
2160 size_t msgbuf_size, 2173 size_t msgbuf_size,
2161 unsigned int priority, 2174 unsigned int priority,
2162 struct GNUNET_TIME_Relative to, 2175 struct GNUNET_TIME_Relative to,
2163 GNUNET_TRANSPORT_TransmitContinuation cont, 2176 GNUNET_TRANSPORT_TransmitContinuation cont,
2164 void *cont_cls) 2177 void *cont_cls)
2165{ 2178{
2166 struct Plugin *plugin = cls; 2179 struct Plugin *plugin = cls;
2167 struct PendingMessage *pm; 2180 struct PendingMessage *pm;
2168 2181
2169 /* create new message entry */ 2182 /* create new message entry */
2170 pm = GNUNET_malloc(sizeof(struct PendingMessage) + msgbuf_size); 2183 pm = GNUNET_malloc (sizeof(struct PendingMessage) + msgbuf_size);
2171 pm->msg = (const char *)&pm[1]; 2184 pm->msg = (const char *) &pm[1];
2172 GNUNET_memcpy(&pm[1], msgbuf, msgbuf_size); 2185 GNUNET_memcpy (&pm[1], msgbuf, msgbuf_size);
2173 pm->message_size = msgbuf_size; 2186 pm->message_size = msgbuf_size;
2174 pm->timeout = GNUNET_TIME_relative_to_absolute(to); 2187 pm->timeout = GNUNET_TIME_relative_to_absolute (to);
2175 pm->transmit_cont = cont; 2188 pm->transmit_cont = cont;
2176 pm->transmit_cont_cls = cont_cls; 2189 pm->transmit_cont_cls = cont_cls;
2177 2190
2178 LOG(GNUNET_ERROR_TYPE_DEBUG, 2191 LOG (GNUNET_ERROR_TYPE_DEBUG,
2179 "Asked to transmit %u bytes to `%s', added message to list.\n", 2192 "Asked to transmit %u bytes to `%s', added message to list.\n",
2180 msgbuf_size, 2193 msgbuf_size,
2181 GNUNET_i2s(&session->target)); 2194 GNUNET_i2s (&session->target));
2182 2195
2183 if (GNUNET_YES == 2196 if (GNUNET_YES ==
2184 GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessionmap, 2197 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
2185 &session->target, 2198 &session->target,
2186 session)) 2199 session))
2187 { 2200 {
2188 GNUNET_assert(NULL != session->client); 2201 GNUNET_assert (NULL != session->client);
2189 GNUNET_SERVER_client_set_timeout(session->client, 2202 GNUNET_SERVER_client_set_timeout (session->client,
2190 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2203 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2191 GNUNET_STATISTICS_update(plugin->env->stats, 2204 GNUNET_STATISTICS_update (plugin->env->stats,
2192 gettext_noop("# bytes currently in TCP buffers"), 2205 gettext_noop ("# bytes currently in TCP buffers"),
2193 msgbuf_size, 2206 msgbuf_size,
2194 GNUNET_NO); 2207 GNUNET_NO);
2195 2208
2196 /* append pm to pending_messages list */ 2209 /* append pm to pending_messages list */
2197 GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head, 2210 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
2198 session->pending_messages_tail, 2211 session->pending_messages_tail,
2199 pm); 2212 pm);
2200 notify_session_monitor(session->plugin, 2213 notify_session_monitor (session->plugin,
2201 session, 2214 session,
2202 GNUNET_TRANSPORT_SS_UPDATE); 2215 GNUNET_TRANSPORT_SS_UPDATE);
2203 session->msgs_in_queue++; 2216 session->msgs_in_queue++;
2204 session->bytes_in_queue += pm->message_size; 2217 session->bytes_in_queue += pm->message_size;
2205 process_pending_messages(session); 2218 process_pending_messages (session);
2206 return msgbuf_size; 2219 return msgbuf_size;
2207 } 2220 }
2208 if (GNUNET_YES == 2221 if (GNUNET_YES ==
2209 GNUNET_CONTAINER_multipeermap_contains_value(plugin->nat_wait_conns, 2222 GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns,
2210 &session->target, 2223 &session->target,
2211 session)) 2224 session))
2212 { 2225 {
2213 LOG(GNUNET_ERROR_TYPE_DEBUG, 2226 LOG (GNUNET_ERROR_TYPE_DEBUG,
2214 "This NAT WAIT session for peer `%s' is not yet ready!\n", 2227 "This NAT WAIT session for peer `%s' is not yet ready!\n",
2215 GNUNET_i2s(&session->target)); 2228 GNUNET_i2s (&session->target));
2216 GNUNET_STATISTICS_update(plugin->env->stats, 2229 GNUNET_STATISTICS_update (plugin->env->stats,
2217 gettext_noop("# bytes currently in TCP buffers"), 2230 gettext_noop ("# bytes currently in TCP buffers"),
2218 msgbuf_size, 2231 msgbuf_size,
2219 GNUNET_NO); 2232 GNUNET_NO);
2220 /* append pm to pending_messages list */ 2233 /* append pm to pending_messages list */
2221 GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head, 2234 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
2222 session->pending_messages_tail, 2235 session->pending_messages_tail,
2223 pm); 2236 pm);
2224 session->msgs_in_queue++; 2237 session->msgs_in_queue++;
2225 session->bytes_in_queue += pm->message_size; 2238 session->bytes_in_queue += pm->message_size;
2226 notify_session_monitor(session->plugin, 2239 notify_session_monitor (session->plugin,
2227 session, 2240 session,
2228 GNUNET_TRANSPORT_SS_HANDSHAKE); 2241 GNUNET_TRANSPORT_SS_HANDSHAKE);
2229 return msgbuf_size; 2242 return msgbuf_size;
2230 } 2243 }
2231 LOG(GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session); 2244 LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session);
2232 if (NULL != cont) 2245 if (NULL != cont)
2233 cont(cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); 2246 cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0);
2234 GNUNET_break(0); 2247 GNUNET_break (0);
2235 GNUNET_free(pm); 2248 GNUNET_free (pm);
2236 return GNUNET_SYSERR; /* session does not exist here */ 2249 return GNUNET_SYSERR; /* session does not exist here */
2237} 2250}
2238 2251
@@ -2240,7 +2253,8 @@ tcp_plugin_send(void *cls,
2240/** 2253/**
2241 * Closure for #session_lookup_it(). 2254 * Closure for #session_lookup_it().
2242 */ 2255 */
2243struct GNUNET_ATS_SessionItCtx { 2256struct GNUNET_ATS_SessionItCtx
2257{
2244 /** 2258 /**
2245 * Address we are looking for. 2259 * Address we are looking for.
2246 */ 2260 */
@@ -2262,14 +2276,14 @@ struct GNUNET_ATS_SessionItCtx {
2262 * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session 2276 * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session
2263 */ 2277 */
2264static int 2278static int
2265session_lookup_it(void *cls, 2279session_lookup_it (void *cls,
2266 const struct GNUNET_PeerIdentity *key, 2280 const struct GNUNET_PeerIdentity *key,
2267 void *value) 2281 void *value)
2268{ 2282{
2269 struct GNUNET_ATS_SessionItCtx *si_ctx = cls; 2283 struct GNUNET_ATS_SessionItCtx *si_ctx = cls;
2270 struct GNUNET_ATS_Session *session = value; 2284 struct GNUNET_ATS_Session *session = value;
2271 2285
2272 if (0 != GNUNET_HELLO_address_cmp(si_ctx->address, session->address)) 2286 if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address))
2273 return GNUNET_YES; 2287 return GNUNET_YES;
2274 si_ctx->result = session; 2288 si_ctx->result = session;
2275 return GNUNET_NO; 2289 return GNUNET_NO;
@@ -2282,18 +2296,18 @@ session_lookup_it(void *cls,
2282 * @param cls the `struct GNUNET_ATS_Session` 2296 * @param cls the `struct GNUNET_ATS_Session`
2283 */ 2297 */
2284static void 2298static void
2285nat_connect_timeout(void *cls) 2299nat_connect_timeout (void *cls)
2286{ 2300{
2287 struct GNUNET_ATS_Session *session = cls; 2301 struct GNUNET_ATS_Session *session = cls;
2288 2302
2289 session->nat_connection_timeout = NULL; 2303 session->nat_connection_timeout = NULL;
2290 LOG(GNUNET_ERROR_TYPE_DEBUG, 2304 LOG (GNUNET_ERROR_TYPE_DEBUG,
2291 "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", 2305 "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n",
2292 GNUNET_i2s(&session->target), 2306 GNUNET_i2s (&session->target),
2293 tcp_plugin_address_to_string(session->plugin, 2307 tcp_plugin_address_to_string (session->plugin,
2294 session->address->address, 2308 session->address->address,
2295 session->address->address_length)); 2309 session->address->address_length));
2296 tcp_plugin_disconnect_session(session->plugin, session); 2310 tcp_plugin_disconnect_session (session->plugin, session);
2297} 2311}
2298 2312
2299 2313
@@ -2307,11 +2321,11 @@ nat_connect_timeout(void *cls)
2307 * @param session which session is being updated 2321 * @param session which session is being updated
2308 */ 2322 */
2309static void 2323static void
2310tcp_plugin_update_session_timeout(void *cls, 2324tcp_plugin_update_session_timeout (void *cls,
2311 const struct GNUNET_PeerIdentity *peer, 2325 const struct GNUNET_PeerIdentity *peer,
2312 struct GNUNET_ATS_Session *session) 2326 struct GNUNET_ATS_Session *session)
2313{ 2327{
2314 reschedule_session_timeout(session); 2328 reschedule_session_timeout (session);
2315} 2329}
2316 2330
2317 2331
@@ -2322,13 +2336,13 @@ tcp_plugin_update_session_timeout(void *cls,
2322 * @param cls the `struct GNUNET_ATS_Session *` 2336 * @param cls the `struct GNUNET_ATS_Session *`
2323 */ 2337 */
2324static void 2338static void
2325delayed_done(void *cls) 2339delayed_done (void *cls)
2326{ 2340{
2327 struct GNUNET_ATS_Session *session = cls; 2341 struct GNUNET_ATS_Session *session = cls;
2328 2342
2329 session->receive_delay_task = NULL; 2343 session->receive_delay_task = NULL;
2330 reschedule_session_timeout(session); 2344 reschedule_session_timeout (session);
2331 GNUNET_SERVER_receive_done(session->client, GNUNET_OK); 2345 GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
2332} 2346}
2333 2347
2334 2348
@@ -2343,20 +2357,20 @@ delayed_done(void *cls)
2343 * @param delay new delay to use for receiving 2357 * @param delay new delay to use for receiving
2344 */ 2358 */
2345static void 2359static void
2346tcp_plugin_update_inbound_delay(void *cls, 2360tcp_plugin_update_inbound_delay (void *cls,
2347 const struct GNUNET_PeerIdentity *peer, 2361 const struct GNUNET_PeerIdentity *peer,
2348 struct GNUNET_ATS_Session *session, 2362 struct GNUNET_ATS_Session *session,
2349 struct GNUNET_TIME_Relative delay) 2363 struct GNUNET_TIME_Relative delay)
2350{ 2364{
2351 if (NULL == session->receive_delay_task) 2365 if (NULL == session->receive_delay_task)
2352 return; 2366 return;
2353 LOG(GNUNET_ERROR_TYPE_DEBUG, 2367 LOG (GNUNET_ERROR_TYPE_DEBUG,
2354 "New inbound delay %s\n", 2368 "New inbound delay %s\n",
2355 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_NO)); 2369 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_NO));
2356 session->receive_delay = GNUNET_TIME_relative_to_absolute(delay); 2370 session->receive_delay = GNUNET_TIME_relative_to_absolute (delay);
2357 GNUNET_SCHEDULER_cancel(session->receive_delay_task); 2371 GNUNET_SCHEDULER_cancel (session->receive_delay_task);
2358 session->receive_delay_task = 2372 session->receive_delay_task =
2359 GNUNET_SCHEDULER_add_delayed(delay, &delayed_done, session); 2373 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
2360} 2374}
2361 2375
2362 2376
@@ -2370,7 +2384,7 @@ tcp_plugin_update_inbound_delay(void *cls,
2370 * @return the session if the address is valid, NULL otherwise 2384 * @return the session if the address is valid, NULL otherwise
2371 */ 2385 */
2372static struct GNUNET_ATS_Session * 2386static struct GNUNET_ATS_Session *
2373tcp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) 2387tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
2374{ 2388{
2375 struct Plugin *plugin = cls; 2389 struct Plugin *plugin = cls;
2376 struct GNUNET_ATS_Session *session = NULL; 2390 struct GNUNET_ATS_Session *session = NULL;
@@ -2392,230 +2406,230 @@ tcp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
2392#endif 2406#endif
2393 2407
2394 addrlen = address->address_length; 2408 addrlen = address->address_length;
2395 LOG(GNUNET_ERROR_TYPE_DEBUG, 2409 LOG (GNUNET_ERROR_TYPE_DEBUG,
2396 "Trying to get session for `%s' address of peer `%s'\n", 2410 "Trying to get session for `%s' address of peer `%s'\n",
2397 tcp_plugin_address_to_string(plugin, 2411 tcp_plugin_address_to_string (plugin,
2398 address->address, 2412 address->address,
2399 address->address_length), 2413 address->address_length),
2400 GNUNET_i2s(&address->peer)); 2414 GNUNET_i2s (&address->peer));
2401 2415
2402 if (GNUNET_HELLO_address_check_option(address, 2416 if (GNUNET_HELLO_address_check_option (address,
2403 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 2417 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
2404 { 2418 {
2405 GNUNET_break(0); 2419 GNUNET_break (0);
2406 return NULL; 2420 return NULL;
2407 } 2421 }
2408 2422
2409 /* look for existing session */ 2423 /* look for existing session */
2410 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(plugin->sessionmap, 2424 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap,
2411 &address->peer)) 2425 &address->peer))
2412 { 2426 {
2413 struct GNUNET_ATS_SessionItCtx si_ctx; 2427 struct GNUNET_ATS_SessionItCtx si_ctx;
2414 2428
2415 si_ctx.address = address; 2429 si_ctx.address = address;
2416 si_ctx.result = NULL; 2430 si_ctx.result = NULL;
2417 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessionmap, 2431 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap,
2418 &address->peer, 2432 &address->peer,
2419 &session_lookup_it, 2433 &session_lookup_it,
2420 &si_ctx); 2434 &si_ctx);
2421 if (NULL != si_ctx.result) 2435 if (NULL != si_ctx.result)
2422 { 2436 {
2423 session = si_ctx.result; 2437 session = si_ctx.result;
2424 LOG(GNUNET_ERROR_TYPE_DEBUG, 2438 LOG (GNUNET_ERROR_TYPE_DEBUG,
2425 "Found existing session for `%s' address `%s'\n", 2439 "Found existing session for `%s' address `%s'\n",
2426 GNUNET_i2s(&address->peer), 2440 GNUNET_i2s (&address->peer),
2427 tcp_plugin_address_to_string(plugin, 2441 tcp_plugin_address_to_string (plugin,
2428 address->address, 2442 address->address,
2429 address->address_length)); 2443 address->address_length));
2430 return session; 2444 return session;
2431 } 2445 }
2432 /* This is a bit of a hack, limiting TCP to never allow more than 2446 /* This is a bit of a hack, limiting TCP to never allow more than
2433 one TCP connection to any given peer at the same time. 2447 one TCP connection to any given peer at the same time.
2434 Without this, peers sometimes disagree about which of the TCP 2448 Without this, peers sometimes disagree about which of the TCP
2435 connections they should use, causing one side to believe that 2449 connections they should use, causing one side to believe that
2436 they transmit successfully, while the other receives nothing. */ 2450 they transmit successfully, while the other receives nothing. */
2437 return NULL; /* Refuse to have more than one TCP connection per 2451 return NULL; /* Refuse to have more than one TCP connection per
2438 peer pair at the same time. */ 2452 peer pair at the same time. */
2439 } 2453 }
2440 2454
2441 if (addrlen == sizeof(struct IPv6TcpAddress)) 2455 if (addrlen == sizeof(struct IPv6TcpAddress))
2442 { 2456 {
2443 GNUNET_assert(NULL != address->address); /* make static analysis happy */ 2457 GNUNET_assert (NULL != address->address); /* make static analysis happy */
2444 t6 = address->address; 2458 t6 = address->address;
2445 options = t6->options; 2459 options = t6->options;
2446 af = AF_INET6; 2460 af = AF_INET6;
2447 memset(&a6, 0, sizeof(a6)); 2461 memset (&a6, 0, sizeof(a6));
2448#if HAVE_SOCKADDR_IN_SIN_LEN 2462#if HAVE_SOCKADDR_IN_SIN_LEN
2449 a6.sin6_len = sizeof(a6); 2463 a6.sin6_len = sizeof(a6);
2450#endif 2464#endif
2451 a6.sin6_family = AF_INET6; 2465 a6.sin6_family = AF_INET6;
2452 a6.sin6_port = t6->t6_port; 2466 a6.sin6_port = t6->t6_port;
2453 if (t6->t6_port == 0) 2467 if (t6->t6_port == 0)
2454 is_natd = GNUNET_YES; 2468 is_natd = GNUNET_YES;
2455 GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); 2469 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
2456 sb = &a6; 2470 sb = &a6;
2457 sbs = sizeof(a6); 2471 sbs = sizeof(a6);
2458 } 2472 }
2459 else if (addrlen == sizeof(struct IPv4TcpAddress)) 2473 else if (addrlen == sizeof(struct IPv4TcpAddress))
2460 { 2474 {
2461 GNUNET_assert(NULL != address->address); /* make static analysis happy */ 2475 GNUNET_assert (NULL != address->address); /* make static analysis happy */
2462 t4 = address->address; 2476 t4 = address->address;
2463 options = t4->options; 2477 options = t4->options;
2464 af = AF_INET; 2478 af = AF_INET;
2465 memset(&a4, 0, sizeof(a4)); 2479 memset (&a4, 0, sizeof(a4));
2466#if HAVE_SOCKADDR_IN_SIN_LEN 2480#if HAVE_SOCKADDR_IN_SIN_LEN
2467 a4.sin_len = sizeof(a4); 2481 a4.sin_len = sizeof(a4);
2468#endif 2482#endif
2469 a4.sin_family = AF_INET; 2483 a4.sin_family = AF_INET;
2470 a4.sin_port = t4->t4_port; 2484 a4.sin_port = t4->t4_port;
2471 if (t4->t4_port == 0) 2485 if (t4->t4_port == 0)
2472 is_natd = GNUNET_YES; 2486 is_natd = GNUNET_YES;
2473 a4.sin_addr.s_addr = t4->ipv4_addr; 2487 a4.sin_addr.s_addr = t4->ipv4_addr;
2474 sb = &a4; 2488 sb = &a4;
2475 sbs = sizeof(a4); 2489 sbs = sizeof(a4);
2476 } 2490 }
2477 else 2491 else
2478 { 2492 {
2479 GNUNET_STATISTICS_update( 2493 GNUNET_STATISTICS_update (
2480 plugin->env->stats, 2494 plugin->env->stats,
2481 gettext_noop("# requests to create session with invalid address"), 2495 gettext_noop ("# requests to create session with invalid address"),
2482 1, 2496 1,
2483 GNUNET_NO); 2497 GNUNET_NO);
2484 return NULL; 2498 return NULL;
2485 } 2499 }
2486 2500
2487 net_type = plugin->env->get_address_type(plugin->env->cls, sb, sbs); 2501 net_type = plugin->env->get_address_type (plugin->env->cls, sb, sbs);
2488 GNUNET_break(net_type != GNUNET_NT_UNSPECIFIED); 2502 GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED);
2489 2503
2490 if ((is_natd == GNUNET_YES) && (addrlen == sizeof(struct IPv6TcpAddress))) 2504 if ((is_natd == GNUNET_YES) && (addrlen == sizeof(struct IPv6TcpAddress)))
2491 { 2505 {
2492 /* NAT client only works with IPv4 addresses */ 2506 /* NAT client only works with IPv4 addresses */
2493 return NULL; 2507 return NULL;
2494 } 2508 }
2495 2509
2496 if (plugin->cur_connections >= plugin->max_connections) 2510 if (plugin->cur_connections >= plugin->max_connections)
2497 { 2511 {
2498 /* saturated */ 2512 /* saturated */
2499 return NULL; 2513 return NULL;
2500 } 2514 }
2501 2515
2502 if ((is_natd == GNUNET_YES) && 2516 if ((is_natd == GNUNET_YES) &&
2503 (GNUNET_YES == 2517 (GNUNET_YES ==
2504 GNUNET_CONTAINER_multipeermap_contains(plugin->nat_wait_conns, 2518 GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
2505 &address->peer))) 2519 &address->peer)))
2506 { 2520 {
2507 /* Only do one NAT punch attempt per peer identity */ 2521 /* Only do one NAT punch attempt per peer identity */
2508 return NULL; 2522 return NULL;
2509 } 2523 }
2510 2524
2511 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && 2525 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
2512 (GNUNET_NO == 2526 (GNUNET_NO ==
2513 GNUNET_CONTAINER_multipeermap_contains(plugin->nat_wait_conns, 2527 GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
2514 &address->peer))) 2528 &address->peer)))
2515 { 2529 {
2516 struct sockaddr_in local_sa; 2530 struct sockaddr_in local_sa;
2517 2531
2518 LOG(GNUNET_ERROR_TYPE_DEBUG, 2532 LOG (GNUNET_ERROR_TYPE_DEBUG,
2519 "Found valid IPv4 NAT address (creating session)!\n"); 2533 "Found valid IPv4 NAT address (creating session)!\n");
2520 session = create_session(plugin, address, net_type, NULL, GNUNET_YES); 2534 session = create_session (plugin, address, net_type, NULL, GNUNET_YES);
2521 session->nat_connection_timeout = 2535 session->nat_connection_timeout =
2522 GNUNET_SCHEDULER_add_delayed(NAT_TIMEOUT, &nat_connect_timeout, session); 2536 GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, &nat_connect_timeout, session);
2523 GNUNET_assert(GNUNET_OK == 2537 GNUNET_assert (GNUNET_OK ==
2524 GNUNET_CONTAINER_multipeermap_put( 2538 GNUNET_CONTAINER_multipeermap_put (
2525 plugin->nat_wait_conns, 2539 plugin->nat_wait_conns,
2526 &session->target, 2540 &session->target,
2527 session, 2541 session,
2528 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2542 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2529 2543
2530 LOG(GNUNET_ERROR_TYPE_DEBUG, 2544 LOG (GNUNET_ERROR_TYPE_DEBUG,
2531 "Created NAT WAIT connection to `%s' at `%s'\n", 2545 "Created NAT WAIT connection to `%s' at `%s'\n",
2532 GNUNET_i2s(&session->target), 2546 GNUNET_i2s (&session->target),
2533 GNUNET_a2s(sb, sbs)); 2547 GNUNET_a2s (sb, sbs));
2534 memset(&local_sa, 0, sizeof(local_sa)); 2548 memset (&local_sa, 0, sizeof(local_sa));
2535 local_sa.sin_family = AF_INET; 2549 local_sa.sin_family = AF_INET;
2536 local_sa.sin_port = htons(plugin->open_port); 2550 local_sa.sin_port = htons (plugin->open_port);
2537 /* We leave sin_address at 0, let the kernel figure it out, 2551 /* We leave sin_address at 0, let the kernel figure it out,
2538 even if our bind() is more specific. (May want to reconsider 2552 even if our bind() is more specific. (May want to reconsider
2539 later.) */ 2553 later.) */
2540 if (GNUNET_OK == GNUNET_NAT_request_reversal(plugin->nat, &local_sa, &a4)) 2554 if (GNUNET_OK == GNUNET_NAT_request_reversal (plugin->nat, &local_sa, &a4))
2541 return session; 2555 return session;
2542 LOG(GNUNET_ERROR_TYPE_DEBUG, 2556 LOG (GNUNET_ERROR_TYPE_DEBUG,
2543 "Running NAT client for `%s' at `%s' failed\n", 2557 "Running NAT client for `%s' at `%s' failed\n",
2544 GNUNET_i2s(&session->target), 2558 GNUNET_i2s (&session->target),
2545 GNUNET_a2s(sb, sbs)); 2559 GNUNET_a2s (sb, sbs));
2546 tcp_plugin_disconnect_session(plugin, session); 2560 tcp_plugin_disconnect_session (plugin, session);
2547 return NULL; 2561 return NULL;
2548 } 2562 }
2549 2563
2550 /* create new outbound session */ 2564 /* create new outbound session */
2551 if (0 != (options & TCP_OPTIONS_TCP_STEALTH)) 2565 if (0 != (options & TCP_OPTIONS_TCP_STEALTH))
2552 { 2566 {
2553#ifdef TCP_STEALTH 2567#ifdef TCP_STEALTH
2554 s = GNUNET_NETWORK_socket_create(af, SOCK_STREAM, 0); 2568 s = GNUNET_NETWORK_socket_create (af, SOCK_STREAM, 0);
2555 if (NULL == s) 2569 if (NULL == s)
2556 { 2570 {
2557 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 2571 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
2558 "socket"); 2572 "socket");
2559 sa = NULL; 2573 sa = NULL;
2560 } 2574 }
2575 else
2576 {
2577 if ((GNUNET_OK !=
2578 GNUNET_NETWORK_socket_setsockopt (s,
2579 IPPROTO_TCP,
2580 TCP_STEALTH,
2581 &session->target,
2582 sizeof(
2583 struct GNUNET_PeerIdentity))) ||
2584 (GNUNET_OK !=
2585 GNUNET_NETWORK_socket_setsockopt (s,
2586 IPPROTO_TCP,
2587 TCP_STEALTH_INTEGRITY,
2588 &plugin->my_welcome,
2589 sizeof(struct WelcomeMessage))))
2590 {
2591 /* TCP STEALTH not supported by kernel */
2592 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
2593 sa = NULL;
2594 }
2561 else 2595 else
2562 { 2596 {
2563 if ((GNUNET_OK != 2597 sa = GNUNET_CONNECTION_connect_socket (s, sb, sbs);
2564 GNUNET_NETWORK_socket_setsockopt(s, 2598 }
2565 IPPROTO_TCP, 2599 }
2566 TCP_STEALTH,
2567 &session->target,
2568 sizeof(
2569 struct GNUNET_PeerIdentity))) ||
2570 (GNUNET_OK !=
2571 GNUNET_NETWORK_socket_setsockopt(s,
2572 IPPROTO_TCP,
2573 TCP_STEALTH_INTEGRITY,
2574 &plugin->my_welcome,
2575 sizeof(struct WelcomeMessage))))
2576 {
2577 /* TCP STEALTH not supported by kernel */
2578 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(s));
2579 sa = NULL;
2580 }
2581 else
2582 {
2583 sa = GNUNET_CONNECTION_connect_socket(s, sb, sbs);
2584 }
2585 }
2586#else 2600#else
2587 sa = NULL; 2601 sa = NULL;
2588#endif 2602#endif
2589 } 2603 }
2590 else 2604 else
2591 { 2605 {
2592 sa = GNUNET_CONNECTION_create_from_sockaddr(af, sb, sbs); 2606 sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs);
2593 } 2607 }
2594 if (NULL == sa) 2608 if (NULL == sa)
2595 { 2609 {
2596 LOG(GNUNET_ERROR_TYPE_DEBUG, 2610 LOG (GNUNET_ERROR_TYPE_DEBUG,
2597 "Failed to create connection to `%s' at `%s'\n", 2611 "Failed to create connection to `%s' at `%s'\n",
2598 GNUNET_i2s(&address->peer), 2612 GNUNET_i2s (&address->peer),
2599 GNUNET_a2s(sb, sbs)); 2613 GNUNET_a2s (sb, sbs));
2600 return NULL; 2614 return NULL;
2601 } 2615 }
2602 LOG(GNUNET_ERROR_TYPE_DEBUG, 2616 LOG (GNUNET_ERROR_TYPE_DEBUG,
2603 "Asked to transmit to `%s', creating fresh session using address `%s'.\n", 2617 "Asked to transmit to `%s', creating fresh session using address `%s'.\n",
2604 GNUNET_i2s(&address->peer), 2618 GNUNET_i2s (&address->peer),
2605 GNUNET_a2s(sb, sbs)); 2619 GNUNET_a2s (sb, sbs));
2606 2620
2607 session = create_session(plugin, 2621 session = create_session (plugin,
2608 address, 2622 address,
2609 net_type, 2623 net_type,
2610 GNUNET_SERVER_connect_socket(plugin->server, sa), 2624 GNUNET_SERVER_connect_socket (plugin->server, sa),
2611 GNUNET_NO); 2625 GNUNET_NO);
2612 (void)GNUNET_CONTAINER_multipeermap_put( 2626 (void) GNUNET_CONTAINER_multipeermap_put (
2613 plugin->sessionmap, 2627 plugin->sessionmap,
2614 &session->target, 2628 &session->target,
2615 session, 2629 session,
2616 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2630 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2617 /* Send TCP Welcome */ 2631 /* Send TCP Welcome */
2618 process_pending_messages(session); 2632 process_pending_messages (session);
2619 2633
2620 return session; 2634 return session;
2621} 2635}
@@ -2632,19 +2646,19 @@ tcp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
2632 * @return #GNUNET_YES (continue to iterate) 2646 * @return #GNUNET_YES (continue to iterate)
2633 */ 2647 */
2634static int 2648static int
2635session_disconnect_it(void *cls, 2649session_disconnect_it (void *cls,
2636 const struct GNUNET_PeerIdentity *key, 2650 const struct GNUNET_PeerIdentity *key,
2637 void *value) 2651 void *value)
2638{ 2652{
2639 struct Plugin *plugin = cls; 2653 struct Plugin *plugin = cls;
2640 struct GNUNET_ATS_Session *session = value; 2654 struct GNUNET_ATS_Session *session = value;
2641 2655
2642 GNUNET_STATISTICS_update(session->plugin->env->stats, 2656 GNUNET_STATISTICS_update (session->plugin->env->stats,
2643 gettext_noop( 2657 gettext_noop (
2644 "# transport-service disconnect requests for TCP"), 2658 "# transport-service disconnect requests for TCP"),
2645 1, 2659 1,
2646 GNUNET_NO); 2660 GNUNET_NO);
2647 tcp_plugin_disconnect_session(plugin, session); 2661 tcp_plugin_disconnect_session (plugin, session);
2648 return GNUNET_YES; 2662 return GNUNET_YES;
2649} 2663}
2650 2664
@@ -2666,21 +2680,21 @@ session_disconnect_it(void *cls,
2666 * to be cancelled 2680 * to be cancelled
2667 */ 2681 */
2668static void 2682static void
2669tcp_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) 2683tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2670{ 2684{
2671 struct Plugin *plugin = cls; 2685 struct Plugin *plugin = cls;
2672 2686
2673 LOG(GNUNET_ERROR_TYPE_DEBUG, 2687 LOG (GNUNET_ERROR_TYPE_DEBUG,
2674 "Disconnecting peer `%s'\n", 2688 "Disconnecting peer `%s'\n",
2675 GNUNET_i2s(target)); 2689 GNUNET_i2s (target));
2676 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessionmap, 2690 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap,
2677 target, 2691 target,
2678 &session_disconnect_it, 2692 &session_disconnect_it,
2679 plugin); 2693 plugin);
2680 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->nat_wait_conns, 2694 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->nat_wait_conns,
2681 target, 2695 target,
2682 &session_disconnect_it, 2696 &session_disconnect_it,
2683 plugin); 2697 plugin);
2684} 2698}
2685 2699
2686 2700
@@ -2695,42 +2709,42 @@ tcp_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
2695 * @param hostname hostname part of the address 2709 * @param hostname hostname part of the address
2696 */ 2710 */
2697static void 2711static void
2698append_port(void *cls, const char *hostname) 2712append_port (void *cls, const char *hostname)
2699{ 2713{
2700 struct PrettyPrinterContext *ppc = cls; 2714 struct PrettyPrinterContext *ppc = cls;
2701 struct Plugin *plugin = ppc->plugin; 2715 struct Plugin *plugin = ppc->plugin;
2702 char *ret; 2716 char *ret;
2703 2717
2704 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2705 "append_port called with hostname `%s'\n", 2719 "append_port called with hostname `%s'\n",
2706 hostname); 2720 hostname);
2707 if (NULL == hostname) 2721 if (NULL == hostname)
2708 { 2722 {
2709 /* Final call, done */ 2723 /* Final call, done */
2710 ppc->resolver_handle = NULL; 2724 ppc->resolver_handle = NULL;
2711 GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head, 2725 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head,
2712 plugin->ppc_dll_tail, 2726 plugin->ppc_dll_tail,
2713 ppc); 2727 ppc);
2714 ppc->asc(ppc->asc_cls, NULL, GNUNET_OK); 2728 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK);
2715 GNUNET_free(ppc); 2729 GNUNET_free (ppc);
2716 return; 2730 return;
2717 } 2731 }
2718 if (GNUNET_YES == ppc->ipv6) 2732 if (GNUNET_YES == ppc->ipv6)
2719 GNUNET_asprintf(&ret, 2733 GNUNET_asprintf (&ret,
2720 "%s.%u.[%s]:%d", 2734 "%s.%u.[%s]:%d",
2721 PLUGIN_NAME, 2735 PLUGIN_NAME,
2722 ppc->options, 2736 ppc->options,
2723 hostname, 2737 hostname,
2724 ppc->port); 2738 ppc->port);
2725 else 2739 else
2726 GNUNET_asprintf(&ret, 2740 GNUNET_asprintf (&ret,
2727 "%s.%u.%s:%d", 2741 "%s.%u.%s:%d",
2728 PLUGIN_NAME, 2742 PLUGIN_NAME,
2729 ppc->options, 2743 ppc->options,
2730 hostname, 2744 hostname,
2731 ppc->port); 2745 ppc->port);
2732 ppc->asc(ppc->asc_cls, ret, GNUNET_OK); 2746 ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
2733 GNUNET_free(ret); 2747 GNUNET_free (ret);
2734} 2748}
2735 2749
2736 2750
@@ -2748,14 +2762,14 @@ append_port(void *cls, const char *hostname)
2748 * @param asc_cls closure for @a asc 2762 * @param asc_cls closure for @a asc
2749 */ 2763 */
2750static void 2764static void
2751tcp_plugin_address_pretty_printer(void *cls, 2765tcp_plugin_address_pretty_printer (void *cls,
2752 const char *type, 2766 const char *type,
2753 const void *addr, 2767 const void *addr,
2754 size_t addrlen, 2768 size_t addrlen,
2755 int numeric, 2769 int numeric,
2756 struct GNUNET_TIME_Relative timeout, 2770 struct GNUNET_TIME_Relative timeout,
2757 GNUNET_TRANSPORT_AddressStringCallback asc, 2771 GNUNET_TRANSPORT_AddressStringCallback asc,
2758 void *asc_cls) 2772 void *asc_cls)
2759{ 2773{
2760 struct Plugin *plugin = cls; 2774 struct Plugin *plugin = cls;
2761 struct PrettyPrinterContext *ppc; 2775 struct PrettyPrinterContext *ppc;
@@ -2769,40 +2783,40 @@ tcp_plugin_address_pretty_printer(void *cls,
2769 uint32_t options; 2783 uint32_t options;
2770 2784
2771 if (sizeof(struct IPv6TcpAddress) == addrlen) 2785 if (sizeof(struct IPv6TcpAddress) == addrlen)
2772 { 2786 {
2773 t6 = addr; 2787 t6 = addr;
2774 memset(&a6, 0, sizeof(a6)); 2788 memset (&a6, 0, sizeof(a6));
2775 a6.sin6_family = AF_INET6; 2789 a6.sin6_family = AF_INET6;
2776 a6.sin6_port = t6->t6_port; 2790 a6.sin6_port = t6->t6_port;
2777 GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); 2791 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
2778 port = ntohs(t6->t6_port); 2792 port = ntohs (t6->t6_port);
2779 options = ntohl(t6->options); 2793 options = ntohl (t6->options);
2780 sb = &a6; 2794 sb = &a6;
2781 sbs = sizeof(a6); 2795 sbs = sizeof(a6);
2782 } 2796 }
2783 else if (sizeof(struct IPv4TcpAddress) == addrlen) 2797 else if (sizeof(struct IPv4TcpAddress) == addrlen)
2784 { 2798 {
2785 t4 = addr; 2799 t4 = addr;
2786 memset(&a4, 0, sizeof(a4)); 2800 memset (&a4, 0, sizeof(a4));
2787 a4.sin_family = AF_INET; 2801 a4.sin_family = AF_INET;
2788 a4.sin_port = t4->t4_port; 2802 a4.sin_port = t4->t4_port;
2789 a4.sin_addr.s_addr = t4->ipv4_addr; 2803 a4.sin_addr.s_addr = t4->ipv4_addr;
2790 port = ntohs(t4->t4_port); 2804 port = ntohs (t4->t4_port);
2791 options = ntohl(t4->options); 2805 options = ntohl (t4->options);
2792 sb = &a4; 2806 sb = &a4;
2793 sbs = sizeof(a4); 2807 sbs = sizeof(a4);
2794 } 2808 }
2795 else 2809 else
2796 { 2810 {
2797 /* invalid address */ 2811 /* invalid address */
2798 LOG(GNUNET_ERROR_TYPE_WARNING, 2812 LOG (GNUNET_ERROR_TYPE_WARNING,
2799 _("Unexpected address length: %u bytes\n"), 2813 _ ("Unexpected address length: %u bytes\n"),
2800 (unsigned int)addrlen); 2814 (unsigned int) addrlen);
2801 asc(asc_cls, NULL, GNUNET_SYSERR); 2815 asc (asc_cls, NULL, GNUNET_SYSERR);
2802 asc(asc_cls, NULL, GNUNET_OK); 2816 asc (asc_cls, NULL, GNUNET_OK);
2803 return; 2817 return;
2804 } 2818 }
2805 ppc = GNUNET_new(struct PrettyPrinterContext); 2819 ppc = GNUNET_new (struct PrettyPrinterContext);
2806 ppc->plugin = plugin; 2820 ppc->plugin = plugin;
2807 if (addrlen == sizeof(struct IPv6TcpAddress)) 2821 if (addrlen == sizeof(struct IPv6TcpAddress))
2808 ppc->ipv6 = GNUNET_YES; 2822 ppc->ipv6 = GNUNET_YES;
@@ -2812,20 +2826,20 @@ tcp_plugin_address_pretty_printer(void *cls,
2812 ppc->asc_cls = asc_cls; 2826 ppc->asc_cls = asc_cls;
2813 ppc->port = port; 2827 ppc->port = port;
2814 ppc->options = options; 2828 ppc->options = options;
2815 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n"); 2829 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n");
2816 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sb, 2830 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
2817 sbs, 2831 sbs,
2818 !numeric, 2832 ! numeric,
2819 timeout, 2833 timeout,
2820 &append_port, 2834 &append_port,
2821 ppc); 2835 ppc);
2822 if (NULL == ppc->resolver_handle) 2836 if (NULL == ppc->resolver_handle)
2823 { 2837 {
2824 GNUNET_break(0); 2838 GNUNET_break (0);
2825 GNUNET_free(ppc); 2839 GNUNET_free (ppc);
2826 return; 2840 return;
2827 } 2841 }
2828 GNUNET_CONTAINER_DLL_insert(plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); 2842 GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc);
2829} 2843}
2830 2844
2831 2845
@@ -2845,7 +2859,7 @@ tcp_plugin_address_pretty_printer(void *cls,
2845 * and transport, #GNUNET_SYSERR if not 2859 * and transport, #GNUNET_SYSERR if not
2846 */ 2860 */
2847static int 2861static int
2848tcp_plugin_check_address(void *cls, const void *addr, size_t addrlen) 2862tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
2849{ 2863{
2850 struct Plugin *plugin = cls; 2864 struct Plugin *plugin = cls;
2851 const struct IPv4TcpAddress *v4; 2865 const struct IPv4TcpAddress *v4;
@@ -2853,61 +2867,61 @@ tcp_plugin_check_address(void *cls, const void *addr, size_t addrlen)
2853 2867
2854 if ((addrlen != sizeof(struct IPv4TcpAddress)) && 2868 if ((addrlen != sizeof(struct IPv4TcpAddress)) &&
2855 (addrlen != sizeof(struct IPv6TcpAddress))) 2869 (addrlen != sizeof(struct IPv6TcpAddress)))
2856 { 2870 {
2857 GNUNET_break_op(0); 2871 GNUNET_break_op (0);
2858 return GNUNET_SYSERR; 2872 return GNUNET_SYSERR;
2859 } 2873 }
2860 2874
2861 if (addrlen == sizeof(struct IPv4TcpAddress)) 2875 if (addrlen == sizeof(struct IPv4TcpAddress))
2862 { 2876 {
2863 struct sockaddr_in s4; 2877 struct sockaddr_in s4;
2864 2878
2865 v4 = (const struct IPv4TcpAddress *)addr; 2879 v4 = (const struct IPv4TcpAddress *) addr;
2866 if (0 != memcmp(&v4->options, &plugin->myoptions, sizeof(uint32_t))) 2880 if (0 != memcmp (&v4->options, &plugin->myoptions, sizeof(uint32_t)))
2867 { 2881 {
2868 GNUNET_break(0); 2882 GNUNET_break (0);
2869 return GNUNET_SYSERR; 2883 return GNUNET_SYSERR;
2870 } 2884 }
2871 memset(&s4, 0, sizeof(s4)); 2885 memset (&s4, 0, sizeof(s4));
2872 s4.sin_family = AF_INET; 2886 s4.sin_family = AF_INET;
2873#if HAVE_SOCKADDR_IN_SIN_LEN 2887#if HAVE_SOCKADDR_IN_SIN_LEN
2874 s4.sin_len = sizeof(s4); 2888 s4.sin_len = sizeof(s4);
2875#endif 2889#endif
2876 s4.sin_port = v4->t4_port; 2890 s4.sin_port = v4->t4_port;
2877 s4.sin_addr.s_addr = v4->ipv4_addr; 2891 s4.sin_addr.s_addr = v4->ipv4_addr;
2878 2892
2879 if (GNUNET_OK != 2893 if (GNUNET_OK !=
2880 GNUNET_NAT_test_address(plugin->nat, &s4, sizeof(struct sockaddr_in))) 2894 GNUNET_NAT_test_address (plugin->nat, &s4, sizeof(struct sockaddr_in)))
2881 return GNUNET_SYSERR; 2895 return GNUNET_SYSERR;
2882 } 2896 }
2883 else 2897 else
2884 { 2898 {
2885 struct sockaddr_in6 s6; 2899 struct sockaddr_in6 s6;
2886 2900
2887 v6 = (const struct IPv6TcpAddress *)addr; 2901 v6 = (const struct IPv6TcpAddress *) addr;
2888 if (IN6_IS_ADDR_LINKLOCAL(&v6->ipv6_addr)) 2902 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
2889 { 2903 {
2890 GNUNET_break_op(0); 2904 GNUNET_break_op (0);
2891 return GNUNET_SYSERR; 2905 return GNUNET_SYSERR;
2892 } 2906 }
2893 if (0 != memcmp(&v6->options, &plugin->myoptions, sizeof(uint32_t))) 2907 if (0 != memcmp (&v6->options, &plugin->myoptions, sizeof(uint32_t)))
2894 { 2908 {
2895 GNUNET_break(0); 2909 GNUNET_break (0);
2896 return GNUNET_SYSERR; 2910 return GNUNET_SYSERR;
2897 } 2911 }
2898 memset(&s6, 0, sizeof(s6)); 2912 memset (&s6, 0, sizeof(s6));
2899 s6.sin6_family = AF_INET6; 2913 s6.sin6_family = AF_INET6;
2900#if HAVE_SOCKADDR_IN_SIN_LEN 2914#if HAVE_SOCKADDR_IN_SIN_LEN
2901 s6.sin6_len = sizeof(s6); 2915 s6.sin6_len = sizeof(s6);
2902#endif 2916#endif
2903 s6.sin6_port = v6->t6_port; 2917 s6.sin6_port = v6->t6_port;
2904 s6.sin6_addr = v6->ipv6_addr; 2918 s6.sin6_addr = v6->ipv6_addr;
2905 2919
2906 if (GNUNET_OK != GNUNET_NAT_test_address(plugin->nat, 2920 if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat,
2907 &s6, 2921 &s6,
2908 sizeof(struct sockaddr_in6))) 2922 sizeof(struct sockaddr_in6)))
2909 return GNUNET_SYSERR; 2923 return GNUNET_SYSERR;
2910 } 2924 }
2911 return GNUNET_OK; 2925 return GNUNET_OK;
2912} 2926}
2913 2927
@@ -2922,9 +2936,9 @@ tcp_plugin_check_address(void *cls, const void *addr, size_t addrlen)
2922 * @param message the actual message 2936 * @param message the actual message
2923 */ 2937 */
2924static void 2938static void
2925handle_tcp_nat_probe(void *cls, 2939handle_tcp_nat_probe (void *cls,
2926 struct GNUNET_SERVER_Client *client, 2940 struct GNUNET_SERVER_Client *client,
2927 const struct GNUNET_MessageHeader *message) 2941 const struct GNUNET_MessageHeader *message)
2928{ 2942{
2929 struct Plugin *plugin = cls; 2943 struct Plugin *plugin = cls;
2930 struct GNUNET_ATS_Session *session; 2944 struct GNUNET_ATS_Session *session;
@@ -2936,115 +2950,115 @@ handle_tcp_nat_probe(void *cls,
2936 const struct sockaddr_in *s4; 2950 const struct sockaddr_in *s4;
2937 const struct sockaddr_in6 *s6; 2951 const struct sockaddr_in6 *s6;
2938 2952
2939 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n"); 2953 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n");
2940 /* We have received a TCP NAT probe, meaning we (hopefully) initiated 2954 /* We have received a TCP NAT probe, meaning we (hopefully) initiated
2941 * a connection to this peer by running gnunet-nat-client. This peer 2955 * a connection to this peer by running gnunet-nat-client. This peer
2942 * received the punch message and now wants us to use the new connection 2956 * received the punch message and now wants us to use the new connection
2943 * as the default for that peer. Do so and then send a WELCOME message 2957 * as the default for that peer. Do so and then send a WELCOME message
2944 * so we can really be connected! 2958 * so we can really be connected!
2945 */ 2959 */
2946 if (ntohs(message->size) != sizeof(struct TCP_NAT_ProbeMessage)) 2960 if (ntohs (message->size) != sizeof(struct TCP_NAT_ProbeMessage))
2947 { 2961 {
2948 GNUNET_break_op(0); 2962 GNUNET_break_op (0);
2949 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 2963 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2950 return; 2964 return;
2951 } 2965 }
2952 2966
2953 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *)message; 2967 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message;
2954 if (0 == memcmp(&tcp_nat_probe->clientIdentity, 2968 if (0 == memcmp (&tcp_nat_probe->clientIdentity,
2955 plugin->env->my_identity, 2969 plugin->env->my_identity,
2956 sizeof(struct GNUNET_PeerIdentity))) 2970 sizeof(struct GNUNET_PeerIdentity)))
2957 { 2971 {
2958 /* refuse connections from ourselves */ 2972 /* refuse connections from ourselves */
2959 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 2973 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2960 return; 2974 return;
2961 } 2975 }
2962 2976
2963 session = GNUNET_CONTAINER_multipeermap_get(plugin->nat_wait_conns, 2977 session = GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns,
2964 &tcp_nat_probe->clientIdentity); 2978 &tcp_nat_probe->clientIdentity);
2965 if (NULL == session) 2979 if (NULL == session)
2966 { 2980 {
2967 LOG(GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); 2981 LOG (GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n");
2968 GNUNET_SERVER_receive_done(client, GNUNET_OK); 2982 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2969 return; 2983 return;
2970 } 2984 }
2971 LOG(GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); 2985 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n");
2972 2986
2973 if (NULL != session->nat_connection_timeout) 2987 if (NULL != session->nat_connection_timeout)
2974 { 2988 {
2975 GNUNET_SCHEDULER_cancel(session->nat_connection_timeout); 2989 GNUNET_SCHEDULER_cancel (session->nat_connection_timeout);
2976 session->nat_connection_timeout = NULL; 2990 session->nat_connection_timeout = NULL;
2977 } 2991 }
2978 2992
2979 if (GNUNET_OK != GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) 2993 if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
2980 { 2994 {
2981 GNUNET_break(0); 2995 GNUNET_break (0);
2982 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 2996 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2983 tcp_plugin_disconnect_session(plugin, session); 2997 tcp_plugin_disconnect_session (plugin, session);
2984 return; 2998 return;
2985 } 2999 }
2986 GNUNET_assert( 3000 GNUNET_assert (
2987 GNUNET_YES == 3001 GNUNET_YES ==
2988 GNUNET_CONTAINER_multipeermap_remove(plugin->nat_wait_conns, 3002 GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns,
2989 &tcp_nat_probe->clientIdentity, 3003 &tcp_nat_probe->clientIdentity,
2990 session)); 3004 session));
2991 GNUNET_SERVER_client_set_user_context(client, session); 3005 GNUNET_SERVER_client_set_user_context (client, session);
2992 (void)GNUNET_CONTAINER_multipeermap_put( 3006 (void) GNUNET_CONTAINER_multipeermap_put (
2993 plugin->sessionmap, 3007 plugin->sessionmap,
2994 &session->target, 3008 &session->target,
2995 session, 3009 session,
2996 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 3010 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2997 session->last_activity = GNUNET_TIME_absolute_get(); 3011 session->last_activity = GNUNET_TIME_absolute_get ();
2998 LOG(GNUNET_ERROR_TYPE_DEBUG, 3012 LOG (GNUNET_ERROR_TYPE_DEBUG,
2999 "Found address `%s' for incoming connection\n", 3013 "Found address `%s' for incoming connection\n",
3000 GNUNET_a2s(vaddr, alen)); 3014 GNUNET_a2s (vaddr, alen));
3001 switch (((const struct sockaddr *)vaddr)->sa_family) 3015 switch (((const struct sockaddr *) vaddr)->sa_family)
3002 { 3016 {
3003 case AF_INET: 3017 case AF_INET:
3004 s4 = vaddr; 3018 s4 = vaddr;
3005 t4 = GNUNET_new(struct IPv4TcpAddress); 3019 t4 = GNUNET_new (struct IPv4TcpAddress);
3006 t4->options = htonl(TCP_OPTIONS_NONE); 3020 t4->options = htonl (TCP_OPTIONS_NONE);
3007 t4->t4_port = s4->sin_port; 3021 t4->t4_port = s4->sin_port;
3008 t4->ipv4_addr = s4->sin_addr.s_addr; 3022 t4->ipv4_addr = s4->sin_addr.s_addr;
3009 session->address = 3023 session->address =
3010 GNUNET_HELLO_address_allocate(&tcp_nat_probe->clientIdentity, 3024 GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity,
3011 PLUGIN_NAME, 3025 PLUGIN_NAME,
3012 &t4, 3026 &t4,
3013 sizeof(struct IPv4TcpAddress), 3027 sizeof(struct IPv4TcpAddress),
3014 GNUNET_HELLO_ADDRESS_INFO_NONE); 3028 GNUNET_HELLO_ADDRESS_INFO_NONE);
3015 break; 3029 break;
3016 3030
3017 case AF_INET6: 3031 case AF_INET6:
3018 s6 = vaddr; 3032 s6 = vaddr;
3019 t6 = GNUNET_new(struct IPv6TcpAddress); 3033 t6 = GNUNET_new (struct IPv6TcpAddress);
3020 t6->options = htonl(TCP_OPTIONS_NONE); 3034 t6->options = htonl (TCP_OPTIONS_NONE);
3021 t6->t6_port = s6->sin6_port; 3035 t6->t6_port = s6->sin6_port;
3022 GNUNET_memcpy(&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); 3036 GNUNET_memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
3023 session->address = 3037 session->address =
3024 GNUNET_HELLO_address_allocate(&tcp_nat_probe->clientIdentity, 3038 GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity,
3025 PLUGIN_NAME, 3039 PLUGIN_NAME,
3026 &t6, 3040 &t6,
3027 sizeof(struct IPv6TcpAddress), 3041 sizeof(struct IPv6TcpAddress),
3028 GNUNET_HELLO_ADDRESS_INFO_NONE); 3042 GNUNET_HELLO_ADDRESS_INFO_NONE);
3029 break; 3043 break;
3030 3044
3031 default: 3045 default:
3032 GNUNET_break_op(0); 3046 GNUNET_break_op (0);
3033 LOG(GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n"); 3047 LOG (GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n");
3034 GNUNET_free(vaddr); 3048 GNUNET_free (vaddr);
3035 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 3049 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3036 tcp_plugin_disconnect_session(plugin, session); 3050 tcp_plugin_disconnect_session (plugin, session);
3037 return; 3051 return;
3038 } 3052 }
3039 GNUNET_free(vaddr); 3053 GNUNET_free (vaddr);
3040 GNUNET_break(NULL == session->client); 3054 GNUNET_break (NULL == session->client);
3041 session->client = client; 3055 session->client = client;
3042 GNUNET_STATISTICS_update(plugin->env->stats, 3056 GNUNET_STATISTICS_update (plugin->env->stats,
3043 gettext_noop("# TCP sessions active"), 3057 gettext_noop ("# TCP sessions active"),
3044 1, 3058 1,
3045 GNUNET_NO); 3059 GNUNET_NO);
3046 process_pending_messages(session); 3060 process_pending_messages (session);
3047 GNUNET_SERVER_receive_done(client, GNUNET_OK); 3061 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3048} 3062}
3049 3063
3050 3064
@@ -3057,12 +3071,12 @@ handle_tcp_nat_probe(void *cls,
3057 * @param message the actual message 3071 * @param message the actual message
3058 */ 3072 */
3059static void 3073static void
3060handle_tcp_welcome(void *cls, 3074handle_tcp_welcome (void *cls,
3061 struct GNUNET_SERVER_Client *client, 3075 struct GNUNET_SERVER_Client *client,
3062 const struct GNUNET_MessageHeader *message) 3076 const struct GNUNET_MessageHeader *message)
3063{ 3077{
3064 struct Plugin *plugin = cls; 3078 struct Plugin *plugin = cls;
3065 const struct WelcomeMessage *wm = (const struct WelcomeMessage *)message; 3079 const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message;
3066 struct GNUNET_HELLO_Address *address; 3080 struct GNUNET_HELLO_Address *address;
3067 struct GNUNET_ATS_Session *session; 3081 struct GNUNET_ATS_Session *session;
3068 size_t alen; 3082 size_t alen;
@@ -3072,141 +3086,141 @@ handle_tcp_welcome(void *cls,
3072 const struct sockaddr_in *s4; 3086 const struct sockaddr_in *s4;
3073 const struct sockaddr_in6 *s6; 3087 const struct sockaddr_in6 *s6;
3074 3088
3075 if (0 == memcmp(&wm->clientIdentity, 3089 if (0 == memcmp (&wm->clientIdentity,
3076 plugin->env->my_identity, 3090 plugin->env->my_identity,
3077 sizeof(struct GNUNET_PeerIdentity))) 3091 sizeof(struct GNUNET_PeerIdentity)))
3092 {
3093 /* refuse connections from ourselves */
3094 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3078 { 3095 {
3079 /* refuse connections from ourselves */ 3096 LOG (GNUNET_ERROR_TYPE_INFO,
3080 if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) 3097 "Received WELCOME message from my own identity `%s' on address `%s'\n",
3081 { 3098 GNUNET_i2s (&wm->clientIdentity),
3082 LOG(GNUNET_ERROR_TYPE_INFO, 3099 GNUNET_a2s (vaddr, alen));
3083 "Received WELCOME message from my own identity `%s' on address `%s'\n", 3100 GNUNET_free (vaddr);
3084 GNUNET_i2s(&wm->clientIdentity),
3085 GNUNET_a2s(vaddr, alen));
3086 GNUNET_free(vaddr);
3087 }
3088 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
3089 return;
3090 } 3101 }
3102 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3103 return;
3104 }
3091 3105
3092 if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) 3106 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3093 { 3107 {
3094 LOG(GNUNET_ERROR_TYPE_DEBUG, 3108 LOG (GNUNET_ERROR_TYPE_DEBUG,
3095 "Received WELCOME message from `%s' on address `%s'\n", 3109 "Received WELCOME message from `%s' on address `%s'\n",
3096 GNUNET_i2s(&wm->clientIdentity), 3110 GNUNET_i2s (&wm->clientIdentity),
3097 GNUNET_a2s(vaddr, alen)); 3111 GNUNET_a2s (vaddr, alen));
3098 GNUNET_free(vaddr); 3112 GNUNET_free (vaddr);
3099 } 3113 }
3100 GNUNET_STATISTICS_update(plugin->env->stats, 3114 GNUNET_STATISTICS_update (plugin->env->stats,
3101 gettext_noop("# TCP WELCOME messages received"), 3115 gettext_noop ("# TCP WELCOME messages received"),
3102 1, 3116 1,
3103 GNUNET_NO); 3117 GNUNET_NO);
3104 session = lookup_session_by_client(plugin, client); 3118 session = lookup_session_by_client (plugin, client);
3105 if (NULL != session) 3119 if (NULL != session)
3120 {
3121 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3106 { 3122 {
3107 if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) 3123 LOG (GNUNET_ERROR_TYPE_DEBUG,
3108 { 3124 "Found existing session %p for peer `%s'\n",
3109 LOG(GNUNET_ERROR_TYPE_DEBUG, 3125 session,
3110 "Found existing session %p for peer `%s'\n", 3126 GNUNET_a2s (vaddr, alen));
3111 session, 3127 GNUNET_free (vaddr);
3112 GNUNET_a2s(vaddr, alen));
3113 GNUNET_free(vaddr);
3114 }
3115 } 3128 }
3129 }
3116 else 3130 else
3117 { 3131 {
3118 if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) 3132 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3119 { 3133 {
3120 if (alen == sizeof(struct sockaddr_in)) 3134 if (alen == sizeof(struct sockaddr_in))
3121 { 3135 {
3122 s4 = vaddr; 3136 s4 = vaddr;
3123 memset(&t4, '\0', sizeof(t4)); 3137 memset (&t4, '\0', sizeof(t4));
3124 t4.options = htonl(TCP_OPTIONS_NONE); 3138 t4.options = htonl (TCP_OPTIONS_NONE);
3125 t4.t4_port = s4->sin_port; 3139 t4.t4_port = s4->sin_port;
3126 t4.ipv4_addr = s4->sin_addr.s_addr; 3140 t4.ipv4_addr = s4->sin_addr.s_addr;
3127 address = 3141 address =
3128 GNUNET_HELLO_address_allocate(&wm->clientIdentity, 3142 GNUNET_HELLO_address_allocate (&wm->clientIdentity,
3129 PLUGIN_NAME, 3143 PLUGIN_NAME,
3130 &t4, 3144 &t4,
3131 sizeof(t4), 3145 sizeof(t4),
3132 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 3146 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
3133 } 3147 }
3134 else if (alen == sizeof(struct sockaddr_in6)) 3148 else if (alen == sizeof(struct sockaddr_in6))
3135 { 3149 {
3136 s6 = vaddr; 3150 s6 = vaddr;
3137 memset(&t6, '\0', sizeof(t6)); 3151 memset (&t6, '\0', sizeof(t6));
3138 t6.options = htonl(TCP_OPTIONS_NONE); 3152 t6.options = htonl (TCP_OPTIONS_NONE);
3139 t6.t6_port = s6->sin6_port; 3153 t6.t6_port = s6->sin6_port;
3140 GNUNET_memcpy(&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); 3154 GNUNET_memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
3141 address = 3155 address =
3142 GNUNET_HELLO_address_allocate(&wm->clientIdentity, 3156 GNUNET_HELLO_address_allocate (&wm->clientIdentity,
3143 PLUGIN_NAME, 3157 PLUGIN_NAME,
3144 &t6, 3158 &t6,
3145 sizeof(t6), 3159 sizeof(t6),
3146 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 3160 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
3147 } 3161 }
3148 else
3149 {
3150 GNUNET_break(0);
3151 GNUNET_free_non_null(vaddr);
3152 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
3153 return;
3154 }
3155 session = create_session(plugin,
3156 address,
3157 plugin->env->get_address_type(plugin->env->cls,
3158 vaddr,
3159 alen),
3160 client,
3161 GNUNET_NO);
3162 GNUNET_break(GNUNET_NT_UNSPECIFIED != session->scope);
3163 GNUNET_HELLO_address_free(address);
3164 LOG(GNUNET_ERROR_TYPE_DEBUG,
3165 "Creating new%s session %p for peer `%s' client %p\n",
3166 GNUNET_HELLO_address_check_option(session->address,
3167 GNUNET_HELLO_ADDRESS_INFO_INBOUND)
3168 ? " inbound"
3169 : "",
3170 session,
3171 tcp_plugin_address_to_string(plugin,
3172 session->address->address,
3173 session->address->address_length),
3174 client);
3175 GNUNET_free(vaddr);
3176 (void)GNUNET_CONTAINER_multipeermap_put(
3177 plugin->sessionmap,
3178 &session->target,
3179 session,
3180 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3181 /* Notify transport and ATS about new session */
3182 plugin->env->session_start(plugin->env->cls,
3183 session->address,
3184 session,
3185 session->scope);
3186 }
3187 else 3162 else
3188 { 3163 {
3189 LOG(GNUNET_ERROR_TYPE_DEBUG, 3164 GNUNET_break (0);
3190 "Did not obtain TCP socket address for incoming connection\n"); 3165 GNUNET_free_non_null (vaddr);
3191 GNUNET_break(0); 3166 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3192 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 3167 return;
3193 return; 3168 }
3194 } 3169 session = create_session (plugin,
3170 address,
3171 plugin->env->get_address_type (plugin->env->cls,
3172 vaddr,
3173 alen),
3174 client,
3175 GNUNET_NO);
3176 GNUNET_break (GNUNET_NT_UNSPECIFIED != session->scope);
3177 GNUNET_HELLO_address_free (address);
3178 LOG (GNUNET_ERROR_TYPE_DEBUG,
3179 "Creating new%s session %p for peer `%s' client %p\n",
3180 GNUNET_HELLO_address_check_option (session->address,
3181 GNUNET_HELLO_ADDRESS_INFO_INBOUND)
3182 ? " inbound"
3183 : "",
3184 session,
3185 tcp_plugin_address_to_string (plugin,
3186 session->address->address,
3187 session->address->address_length),
3188 client);
3189 GNUNET_free (vaddr);
3190 (void) GNUNET_CONTAINER_multipeermap_put (
3191 plugin->sessionmap,
3192 &session->target,
3193 session,
3194 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3195 /* Notify transport and ATS about new session */
3196 plugin->env->session_start (plugin->env->cls,
3197 session->address,
3198 session,
3199 session->scope);
3200 }
3201 else
3202 {
3203 LOG (GNUNET_ERROR_TYPE_DEBUG,
3204 "Did not obtain TCP socket address for incoming connection\n");
3205 GNUNET_break (0);
3206 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3207 return;
3195 } 3208 }
3209 }
3196 3210
3197 if (GNUNET_YES != session->expecting_welcome) 3211 if (GNUNET_YES != session->expecting_welcome)
3198 { 3212 {
3199 GNUNET_break_op(0); 3213 GNUNET_break_op (0);
3200 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 3214 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3201 return; 3215 return;
3202 } 3216 }
3203 session->last_activity = GNUNET_TIME_absolute_get(); 3217 session->last_activity = GNUNET_TIME_absolute_get ();
3204 session->expecting_welcome = GNUNET_NO; 3218 session->expecting_welcome = GNUNET_NO;
3205 3219
3206 process_pending_messages(session); 3220 process_pending_messages (session);
3207 GNUNET_SERVER_client_set_timeout(client, 3221 GNUNET_SERVER_client_set_timeout (client,
3208 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 3222 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
3209 GNUNET_SERVER_receive_done(client, GNUNET_OK); 3223 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3210} 3224}
3211 3225
3212 3226
@@ -3219,102 +3233,102 @@ handle_tcp_welcome(void *cls,
3219 * @param message the actual message 3233 * @param message the actual message
3220 */ 3234 */
3221static void 3235static void
3222handle_tcp_data(void *cls, 3236handle_tcp_data (void *cls,
3223 struct GNUNET_SERVER_Client *client, 3237 struct GNUNET_SERVER_Client *client,
3224 const struct GNUNET_MessageHeader *message) 3238 const struct GNUNET_MessageHeader *message)
3225{ 3239{
3226 struct Plugin *plugin = cls; 3240 struct Plugin *plugin = cls;
3227 struct GNUNET_ATS_Session *session; 3241 struct GNUNET_ATS_Session *session;
3228 struct GNUNET_TIME_Relative delay; 3242 struct GNUNET_TIME_Relative delay;
3229 uint16_t type; 3243 uint16_t type;
3230 3244
3231 type = ntohs(message->type); 3245 type = ntohs (message->type);
3232 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || 3246 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
3233 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) 3247 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type))
3234 { 3248 {
3235 /* We don't want to propagate WELCOME and NAT Probe messages up! */ 3249 /* We don't want to propagate WELCOME and NAT Probe messages up! */
3236 GNUNET_SERVER_receive_done(client, GNUNET_OK); 3250 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3237 return; 3251 return;
3238 } 3252 }
3239 session = lookup_session_by_client(plugin, client); 3253 session = lookup_session_by_client (plugin, client);
3240 if (NULL == session) 3254 if (NULL == session)
3241 { 3255 {
3242 /* No inbound session found */ 3256 /* No inbound session found */
3243 void *vaddr = NULL; 3257 void *vaddr = NULL;
3244 size_t alen; 3258 size_t alen;
3245 3259
3246 GNUNET_assert(GNUNET_OK == 3260 GNUNET_assert (GNUNET_OK ==
3247 GNUNET_SERVER_client_get_address(client, &vaddr, &alen)); 3261 GNUNET_SERVER_client_get_address (client, &vaddr, &alen));
3248 LOG(GNUNET_ERROR_TYPE_ERROR, 3262 LOG (GNUNET_ERROR_TYPE_ERROR,
3249 "Received unexpected %u bytes of type %u from `%s'\n", 3263 "Received unexpected %u bytes of type %u from `%s'\n",
3250 (unsigned int)ntohs(message->size), 3264 (unsigned int) ntohs (message->size),
3251 (unsigned int)ntohs(message->type), 3265 (unsigned int) ntohs (message->type),
3252 GNUNET_a2s(vaddr, alen)); 3266 GNUNET_a2s (vaddr, alen));
3253 GNUNET_break_op(0); 3267 GNUNET_break_op (0);
3254 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 3268 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3255 GNUNET_free_non_null(vaddr); 3269 GNUNET_free_non_null (vaddr);
3256 return; 3270 return;
3257 } 3271 }
3258 if (GNUNET_YES == session->expecting_welcome) 3272 if (GNUNET_YES == session->expecting_welcome)
3259 { 3273 {
3260 /* Session is expecting WELCOME message */ 3274 /* Session is expecting WELCOME message */
3261 void *vaddr = NULL; 3275 void *vaddr = NULL;
3262 size_t alen; 3276 size_t alen;
3263 3277
3264 GNUNET_SERVER_client_get_address(client, &vaddr, &alen); 3278 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
3265 LOG(GNUNET_ERROR_TYPE_ERROR, 3279 LOG (GNUNET_ERROR_TYPE_ERROR,
3266 "Received unexpected %u bytes of type %u from `%s'\n", 3280 "Received unexpected %u bytes of type %u from `%s'\n",
3267 (unsigned int)ntohs(message->size), 3281 (unsigned int) ntohs (message->size),
3268 (unsigned int)ntohs(message->type), 3282 (unsigned int) ntohs (message->type),
3269 GNUNET_a2s(vaddr, alen)); 3283 GNUNET_a2s (vaddr, alen));
3270 GNUNET_break_op(0); 3284 GNUNET_break_op (0);
3271 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 3285 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3272 GNUNET_free_non_null(vaddr); 3286 GNUNET_free_non_null (vaddr);
3273 return; 3287 return;
3274 } 3288 }
3275 3289
3276 session->last_activity = GNUNET_TIME_absolute_get(); 3290 session->last_activity = GNUNET_TIME_absolute_get ();
3277 { 3291 {
3278 void *vaddr = NULL; 3292 void *vaddr = NULL;
3279 size_t alen; 3293 size_t alen;
3280 3294
3281 GNUNET_SERVER_client_get_address(client, &vaddr, &alen); 3295 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
3282 LOG(GNUNET_ERROR_TYPE_DEBUG, 3296 LOG (GNUNET_ERROR_TYPE_DEBUG,
3283 "Passing %u bytes of type %u from `%s' at %s to transport service.\n", 3297 "Passing %u bytes of type %u from `%s' at %s to transport service.\n",
3284 (unsigned int)ntohs(message->size), 3298 (unsigned int) ntohs (message->size),
3285 (unsigned int)ntohs(message->type), 3299 (unsigned int) ntohs (message->type),
3286 GNUNET_i2s(&session->target), 3300 GNUNET_i2s (&session->target),
3287 GNUNET_a2s(vaddr, alen)); 3301 GNUNET_a2s (vaddr, alen));
3288 GNUNET_free_non_null(vaddr); 3302 GNUNET_free_non_null (vaddr);
3289 } 3303 }
3290 3304
3291 GNUNET_STATISTICS_update(plugin->env->stats, 3305 GNUNET_STATISTICS_update (plugin->env->stats,
3292 gettext_noop("# bytes received via TCP"), 3306 gettext_noop ("# bytes received via TCP"),
3293 ntohs(message->size), 3307 ntohs (message->size),
3294 GNUNET_NO); 3308 GNUNET_NO);
3295 3309
3296 GNUNET_assert( 3310 GNUNET_assert (
3297 GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessionmap, 3311 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
3298 &session->target, 3312 &session->target,
3299 session)); 3313 session));
3300 delay = 3314 delay =
3301 plugin->env->receive(plugin->env->cls, session->address, session, message); 3315 plugin->env->receive (plugin->env->cls, session->address, session, message);
3302 reschedule_session_timeout(session); 3316 reschedule_session_timeout (session);
3303 if (0 == delay.rel_value_us) 3317 if (0 == delay.rel_value_us)
3304 { 3318 {
3305 GNUNET_SERVER_receive_done(client, GNUNET_OK); 3319 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3306 } 3320 }
3307 else 3321 else
3308 { 3322 {
3309 LOG(GNUNET_ERROR_TYPE_DEBUG, 3323 LOG (GNUNET_ERROR_TYPE_DEBUG,
3310 "Throttling receiving from `%s' for %s\n", 3324 "Throttling receiving from `%s' for %s\n",
3311 GNUNET_i2s(&session->target), 3325 GNUNET_i2s (&session->target),
3312 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); 3326 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
3313 GNUNET_SERVER_disable_receive_done_warning(client); 3327 GNUNET_SERVER_disable_receive_done_warning (client);
3314 GNUNET_assert(NULL == session->receive_delay_task); 3328 GNUNET_assert (NULL == session->receive_delay_task);
3315 session->receive_delay_task = 3329 session->receive_delay_task =
3316 GNUNET_SCHEDULER_add_delayed(delay, &delayed_done, session); 3330 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
3317 } 3331 }
3318} 3332}
3319 3333
3320 3334
@@ -3327,30 +3341,30 @@ handle_tcp_data(void *cls,
3327 * @param client identification of the client 3341 * @param client identification of the client
3328 */ 3342 */
3329static void 3343static void
3330connect_notify(void *cls, struct GNUNET_SERVER_Client *client) 3344connect_notify (void *cls, struct GNUNET_SERVER_Client *client)
3331{ 3345{
3332 struct Plugin *plugin = cls; 3346 struct Plugin *plugin = cls;
3333 3347
3334 if (NULL == client) 3348 if (NULL == client)
3335 return; 3349 return;
3336 plugin->cur_connections++; 3350 plugin->cur_connections++;
3337 GNUNET_STATISTICS_set(plugin->env->stats, 3351 GNUNET_STATISTICS_set (plugin->env->stats,
3338 gettext_noop("# TCP server connections active"), 3352 gettext_noop ("# TCP server connections active"),
3339 plugin->cur_connections, 3353 plugin->cur_connections,
3340 GNUNET_NO); 3354 GNUNET_NO);
3341 GNUNET_STATISTICS_update(plugin->env->stats, 3355 GNUNET_STATISTICS_update (plugin->env->stats,
3342 gettext_noop("# TCP server connect events"), 3356 gettext_noop ("# TCP server connect events"),
3343 1, 3357 1,
3344 GNUNET_NO); 3358 GNUNET_NO);
3345 if (plugin->cur_connections != plugin->max_connections) 3359 if (plugin->cur_connections != plugin->max_connections)
3346 return; 3360 return;
3347 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 3361 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3348 _("TCP connection limit reached, suspending server\n")); 3362 _ ("TCP connection limit reached, suspending server\n"));
3349 GNUNET_STATISTICS_update(plugin->env->stats, 3363 GNUNET_STATISTICS_update (plugin->env->stats,
3350 gettext_noop("# TCP service suspended"), 3364 gettext_noop ("# TCP service suspended"),
3351 1, 3365 1,
3352 GNUNET_NO); 3366 GNUNET_NO);
3353 GNUNET_SERVER_suspend( 3367 GNUNET_SERVER_suspend (
3354 plugin->server); /* Maximum number of connections rechead */ 3368 plugin->server); /* Maximum number of connections rechead */
3355} 3369}
3356 3370
@@ -3364,43 +3378,43 @@ connect_notify(void *cls, struct GNUNET_SERVER_Client *client)
3364 * @param client identification of the client 3378 * @param client identification of the client
3365 */ 3379 */
3366static void 3380static void
3367disconnect_notify(void *cls, struct GNUNET_SERVER_Client *client) 3381disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
3368{ 3382{
3369 struct Plugin *plugin = cls; 3383 struct Plugin *plugin = cls;
3370 struct GNUNET_ATS_Session *session; 3384 struct GNUNET_ATS_Session *session;
3371 3385
3372 if (NULL == client) 3386 if (NULL == client)
3373 return; 3387 return;
3374 GNUNET_assert(plugin->cur_connections >= 1); 3388 GNUNET_assert (plugin->cur_connections >= 1);
3375 plugin->cur_connections--; 3389 plugin->cur_connections--;
3376 session = lookup_session_by_client(plugin, client); 3390 session = lookup_session_by_client (plugin, client);
3377 if (NULL == session) 3391 if (NULL == session)
3378 return; /* unknown, nothing to do */ 3392 return; /* unknown, nothing to do */
3379 LOG(GNUNET_ERROR_TYPE_DEBUG, 3393 LOG (GNUNET_ERROR_TYPE_DEBUG,
3380 "Destroying session of `%s' with %s due to network-level disconnect.\n", 3394 "Destroying session of `%s' with %s due to network-level disconnect.\n",
3381 GNUNET_i2s(&session->target), 3395 GNUNET_i2s (&session->target),
3382 tcp_plugin_address_to_string(session->plugin, 3396 tcp_plugin_address_to_string (session->plugin,
3383 session->address->address, 3397 session->address->address,
3384 session->address->address_length)); 3398 session->address->address_length));
3385 3399
3386 if (plugin->cur_connections == plugin->max_connections) 3400 if (plugin->cur_connections == plugin->max_connections)
3387 { 3401 {
3388 GNUNET_STATISTICS_update(session->plugin->env->stats, 3402 GNUNET_STATISTICS_update (session->plugin->env->stats,
3389 gettext_noop("# TCP service resumed"), 3403 gettext_noop ("# TCP service resumed"),
3390 1, 3404 1,
3391 GNUNET_NO); 3405 GNUNET_NO);
3392 GNUNET_SERVER_resume(plugin->server); /* Resume server */ 3406 GNUNET_SERVER_resume (plugin->server); /* Resume server */
3393 } 3407 }
3394 GNUNET_STATISTICS_set(plugin->env->stats, 3408 GNUNET_STATISTICS_set (plugin->env->stats,
3395 gettext_noop("# TCP server connections active"), 3409 gettext_noop ("# TCP server connections active"),
3396 plugin->cur_connections, 3410 plugin->cur_connections,
3397 GNUNET_NO); 3411 GNUNET_NO);
3398 GNUNET_STATISTICS_update(session->plugin->env->stats, 3412 GNUNET_STATISTICS_update (session->plugin->env->stats,
3399 gettext_noop( 3413 gettext_noop (
3400 "# network-level TCP disconnect events"), 3414 "# network-level TCP disconnect events"),
3401 1, 3415 1,
3402 GNUNET_NO); 3416 GNUNET_NO);
3403 tcp_plugin_disconnect_session(plugin, session); 3417 tcp_plugin_disconnect_session (plugin, session);
3404} 3418}
3405 3419
3406 3420
@@ -3413,28 +3427,28 @@ disconnect_notify(void *cls, struct GNUNET_SERVER_Client *client)
3413 * @return number of bytes copied into @a buf 3427 * @return number of bytes copied into @a buf
3414 */ 3428 */
3415static size_t 3429static size_t
3416notify_send_probe(void *cls, size_t size, void *buf) 3430notify_send_probe (void *cls, size_t size, void *buf)
3417{ 3431{
3418 struct TCPProbeContext *tcp_probe_ctx = cls; 3432 struct TCPProbeContext *tcp_probe_ctx = cls;
3419 struct Plugin *plugin = tcp_probe_ctx->plugin; 3433 struct Plugin *plugin = tcp_probe_ctx->plugin;
3420 size_t ret; 3434 size_t ret;
3421 3435
3422 tcp_probe_ctx->transmit_handle = NULL; 3436 tcp_probe_ctx->transmit_handle = NULL;
3423 GNUNET_CONTAINER_DLL_remove(plugin->probe_head, 3437 GNUNET_CONTAINER_DLL_remove (plugin->probe_head,
3424 plugin->probe_tail, 3438 plugin->probe_tail,
3425 tcp_probe_ctx); 3439 tcp_probe_ctx);
3426 if (NULL == buf) 3440 if (NULL == buf)
3427 { 3441 {
3428 GNUNET_CONNECTION_destroy(tcp_probe_ctx->sock); 3442 GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock);
3429 GNUNET_free(tcp_probe_ctx); 3443 GNUNET_free (tcp_probe_ctx);
3430 return 0; 3444 return 0;
3431 } 3445 }
3432 GNUNET_assert(size >= sizeof(tcp_probe_ctx->message)); 3446 GNUNET_assert (size >= sizeof(tcp_probe_ctx->message));
3433 GNUNET_memcpy(buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message)); 3447 GNUNET_memcpy (buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message));
3434 GNUNET_SERVER_connect_socket(tcp_probe_ctx->plugin->server, 3448 GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server,
3435 tcp_probe_ctx->sock); 3449 tcp_probe_ctx->sock);
3436 ret = sizeof(tcp_probe_ctx->message); 3450 ret = sizeof(tcp_probe_ctx->message);
3437 GNUNET_free(tcp_probe_ctx); 3451 GNUNET_free (tcp_probe_ctx);
3438 return ret; 3452 return ret;
3439} 3453}
3440 3454
@@ -3449,9 +3463,9 @@ notify_send_probe(void *cls, size_t size, void *buf)
3449 * @param addrlen number of bytes in @a addr 3463 * @param addrlen number of bytes in @a addr
3450 */ 3464 */
3451static void 3465static void
3452try_connection_reversal(void *cls, 3466try_connection_reversal (void *cls,
3453 const struct sockaddr *addr, 3467 const struct sockaddr *addr,
3454 socklen_t addrlen) 3468 socklen_t addrlen)
3455{ 3469{
3456 struct Plugin *plugin = cls; 3470 struct Plugin *plugin = cls;
3457 struct GNUNET_CONNECTION_Handle *sock; 3471 struct GNUNET_CONNECTION_Handle *sock;
@@ -3461,31 +3475,31 @@ try_connection_reversal(void *cls,
3461 * We have received an ICMP response, ostensibly from a peer 3475 * We have received an ICMP response, ostensibly from a peer
3462 * that wants to connect to us! Send a message to establish a connection. 3476 * that wants to connect to us! Send a message to establish a connection.
3463 */ 3477 */
3464 sock = GNUNET_CONNECTION_create_from_sockaddr(AF_INET, addr, addrlen); 3478 sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
3465 if (NULL == sock) 3479 if (NULL == sock)
3466 { 3480 {
3467 /* failed for some odd reason (out of sockets?); ignore attempt */ 3481 /* failed for some odd reason (out of sockets?); ignore attempt */
3468 return; 3482 return;
3469 } 3483 }
3470 3484
3471 tcp_probe_ctx = GNUNET_new(struct TCPProbeContext); 3485 tcp_probe_ctx = GNUNET_new (struct TCPProbeContext);
3472 tcp_probe_ctx->message.header.size = 3486 tcp_probe_ctx->message.header.size =
3473 htons(sizeof(struct TCP_NAT_ProbeMessage)); 3487 htons (sizeof(struct TCP_NAT_ProbeMessage));
3474 tcp_probe_ctx->message.header.type = 3488 tcp_probe_ctx->message.header.type =
3475 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); 3489 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3476 tcp_probe_ctx->message.clientIdentity = *plugin->env->my_identity; 3490 tcp_probe_ctx->message.clientIdentity = *plugin->env->my_identity;
3477 tcp_probe_ctx->plugin = plugin; 3491 tcp_probe_ctx->plugin = plugin;
3478 tcp_probe_ctx->sock = sock; 3492 tcp_probe_ctx->sock = sock;
3479 GNUNET_CONTAINER_DLL_insert(plugin->probe_head, 3493 GNUNET_CONTAINER_DLL_insert (plugin->probe_head,
3480 plugin->probe_tail, 3494 plugin->probe_tail,
3481 tcp_probe_ctx); 3495 tcp_probe_ctx);
3482 tcp_probe_ctx->transmit_handle = 3496 tcp_probe_ctx->transmit_handle =
3483 GNUNET_CONNECTION_notify_transmit_ready(sock, 3497 GNUNET_CONNECTION_notify_transmit_ready (sock,
3484 ntohs(tcp_probe_ctx->message 3498 ntohs (tcp_probe_ctx->message
3485 .header.size), 3499 .header.size),
3486 GNUNET_TIME_UNIT_FOREVER_REL, 3500 GNUNET_TIME_UNIT_FOREVER_REL,
3487 &notify_send_probe, 3501 &notify_send_probe,
3488 tcp_probe_ctx); 3502 tcp_probe_ctx);
3489} 3503}
3490 3504
3491 3505
@@ -3497,7 +3511,7 @@ try_connection_reversal(void *cls,
3497 * @return the network type in HBO or #GNUNET_SYSERR 3511 * @return the network type in HBO or #GNUNET_SYSERR
3498 */ 3512 */
3499static enum GNUNET_NetworkType 3513static enum GNUNET_NetworkType
3500tcp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) 3514tcp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
3501{ 3515{
3502 return session->scope; 3516 return session->scope;
3503} 3517}
@@ -3511,8 +3525,8 @@ tcp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
3511 * @return the network type 3525 * @return the network type
3512 */ 3526 */
3513static enum GNUNET_NetworkType 3527static enum GNUNET_NetworkType
3514tcp_plugin_get_network_for_address(void *cls, 3528tcp_plugin_get_network_for_address (void *cls,
3515 const struct GNUNET_HELLO_Address *address) 3529 const struct GNUNET_HELLO_Address *address)
3516{ 3530{
3517 struct Plugin *plugin = cls; 3531 struct Plugin *plugin = cls;
3518 size_t addrlen; 3532 size_t addrlen;
@@ -3525,39 +3539,39 @@ tcp_plugin_get_network_for_address(void *cls,
3525 3539
3526 addrlen = address->address_length; 3540 addrlen = address->address_length;
3527 if (addrlen == sizeof(struct IPv6TcpAddress)) 3541 if (addrlen == sizeof(struct IPv6TcpAddress))
3528 { 3542 {
3529 GNUNET_assert(NULL != address->address); /* make static analysis happy */ 3543 GNUNET_assert (NULL != address->address); /* make static analysis happy */
3530 t6 = address->address; 3544 t6 = address->address;
3531 memset(&a6, 0, sizeof(a6)); 3545 memset (&a6, 0, sizeof(a6));
3532#if HAVE_SOCKADDR_IN_SIN_LEN 3546#if HAVE_SOCKADDR_IN_SIN_LEN
3533 a6.sin6_len = sizeof(a6); 3547 a6.sin6_len = sizeof(a6);
3534#endif 3548#endif
3535 a6.sin6_family = AF_INET6; 3549 a6.sin6_family = AF_INET6;
3536 a6.sin6_port = t6->t6_port; 3550 a6.sin6_port = t6->t6_port;
3537 GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); 3551 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
3538 sb = &a6; 3552 sb = &a6;
3539 sbs = sizeof(a6); 3553 sbs = sizeof(a6);
3540 } 3554 }
3541 else if (addrlen == sizeof(struct IPv4TcpAddress)) 3555 else if (addrlen == sizeof(struct IPv4TcpAddress))
3542 { 3556 {
3543 GNUNET_assert(NULL != address->address); /* make static analysis happy */ 3557 GNUNET_assert (NULL != address->address); /* make static analysis happy */
3544 t4 = address->address; 3558 t4 = address->address;
3545 memset(&a4, 0, sizeof(a4)); 3559 memset (&a4, 0, sizeof(a4));
3546#if HAVE_SOCKADDR_IN_SIN_LEN 3560#if HAVE_SOCKADDR_IN_SIN_LEN
3547 a4.sin_len = sizeof(a4); 3561 a4.sin_len = sizeof(a4);
3548#endif 3562#endif
3549 a4.sin_family = AF_INET; 3563 a4.sin_family = AF_INET;
3550 a4.sin_port = t4->t4_port; 3564 a4.sin_port = t4->t4_port;
3551 a4.sin_addr.s_addr = t4->ipv4_addr; 3565 a4.sin_addr.s_addr = t4->ipv4_addr;
3552 sb = &a4; 3566 sb = &a4;
3553 sbs = sizeof(a4); 3567 sbs = sizeof(a4);
3554 } 3568 }
3555 else 3569 else
3556 { 3570 {
3557 GNUNET_break(0); 3571 GNUNET_break (0);
3558 return GNUNET_NT_UNSPECIFIED; 3572 return GNUNET_NT_UNSPECIFIED;
3559 } 3573 }
3560 return plugin->env->get_address_type(plugin->env->cls, sb, sbs); 3574 return plugin->env->get_address_type (plugin->env->cls, sb, sbs);
3561} 3575}
3562 3576
3563 3577
@@ -3571,17 +3585,17 @@ tcp_plugin_get_network_for_address(void *cls,
3571 * @return #GNUNET_OK (continue to iterate) 3585 * @return #GNUNET_OK (continue to iterate)
3572 */ 3586 */
3573static int 3587static int
3574send_session_info_iter(void *cls, 3588send_session_info_iter (void *cls,
3575 const struct GNUNET_PeerIdentity *peer, 3589 const struct GNUNET_PeerIdentity *peer,
3576 void *value) 3590 void *value)
3577{ 3591{
3578 struct Plugin *plugin = cls; 3592 struct Plugin *plugin = cls;
3579 struct GNUNET_ATS_Session *session = value; 3593 struct GNUNET_ATS_Session *session = value;
3580 3594
3581 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); 3595 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
3582 /* FIXME: cannot tell if this is up or not from current 3596 /* FIXME: cannot tell if this is up or not from current
3583 session state... */ 3597 session state... */
3584 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); 3598 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
3585 return GNUNET_OK; 3599 return GNUNET_OK;
3586} 3600}
3587 3601
@@ -3599,22 +3613,22 @@ send_session_info_iter(void *cls,
3599 * @param sic_cls closure for @a sic 3613 * @param sic_cls closure for @a sic
3600 */ 3614 */
3601static void 3615static void
3602tcp_plugin_setup_monitor(void *cls, 3616tcp_plugin_setup_monitor (void *cls,
3603 GNUNET_TRANSPORT_SessionInfoCallback sic, 3617 GNUNET_TRANSPORT_SessionInfoCallback sic,
3604 void *sic_cls) 3618 void *sic_cls)
3605{ 3619{
3606 struct Plugin *plugin = cls; 3620 struct Plugin *plugin = cls;
3607 3621
3608 plugin->sic = sic; 3622 plugin->sic = sic;
3609 plugin->sic_cls = sic_cls; 3623 plugin->sic_cls = sic_cls;
3610 if (NULL != sic) 3624 if (NULL != sic)
3611 { 3625 {
3612 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessionmap, 3626 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap,
3613 &send_session_info_iter, 3627 &send_session_info_iter,
3614 plugin); 3628 plugin);
3615 /* signal end of first iteration */ 3629 /* signal end of first iteration */
3616 sic(sic_cls, NULL, NULL); 3630 sic (sic_cls, NULL, NULL);
3617 } 3631 }
3618} 3632}
3619 3633
3620 3634
@@ -3625,7 +3639,7 @@ tcp_plugin_setup_monitor(void *cls,
3625 * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error 3639 * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error
3626 */ 3640 */
3627void * 3641void *
3628libgnunet_plugin_transport_tcp_init(void *cls) 3642libgnunet_plugin_transport_tcp_init (void *cls)
3629{ 3643{
3630 static const struct GNUNET_SERVER_MessageHandler my_handlers[] = 3644 static const struct GNUNET_SERVER_MessageHandler my_handlers[] =
3631 { { &handle_tcp_welcome, 3645 { { &handle_tcp_welcome,
@@ -3633,9 +3647,9 @@ libgnunet_plugin_transport_tcp_init(void *cls)
3633 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, 3647 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
3634 sizeof(struct WelcomeMessage) }, 3648 sizeof(struct WelcomeMessage) },
3635 { &handle_tcp_nat_probe, 3649 { &handle_tcp_nat_probe,
3636 NULL, 3650 NULL,
3637 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, 3651 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
3638 sizeof(struct TCP_NAT_ProbeMessage) }, 3652 sizeof(struct TCP_NAT_ProbeMessage) },
3639 { &handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0 }, 3653 { &handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0 },
3640 { NULL, NULL, 0, 0 } }; 3654 { NULL, NULL, 0, 0 } };
3641 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 3655 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
@@ -3657,152 +3671,152 @@ libgnunet_plugin_transport_tcp_init(void *cls)
3657 socklen_t *addrlens; 3671 socklen_t *addrlens;
3658 3672
3659 if (NULL == env->receive) 3673 if (NULL == env->receive)
3660 { 3674 {
3661 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 3675 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
3662 initialze the plugin or the API */ 3676 initialze the plugin or the API */
3663 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 3677 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
3664 api->cls = NULL; 3678 api->cls = NULL;
3665 api->address_pretty_printer = &tcp_plugin_address_pretty_printer; 3679 api->address_pretty_printer = &tcp_plugin_address_pretty_printer;
3666 api->address_to_string = &tcp_plugin_address_to_string; 3680 api->address_to_string = &tcp_plugin_address_to_string;
3667 api->string_to_address = &tcp_plugin_string_to_address; 3681 api->string_to_address = &tcp_plugin_string_to_address;
3668 return api; 3682 return api;
3669 } 3683 }
3670 3684
3671 GNUNET_assert(NULL != env->cfg); 3685 GNUNET_assert (NULL != env->cfg);
3672 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, 3686 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
3673 "transport-tcp", 3687 "transport-tcp",
3674 "MAX_CONNECTIONS", 3688 "MAX_CONNECTIONS",
3675 &max_connections)) 3689 &max_connections))
3676 max_connections = 128; 3690 max_connections = 128;
3677 3691
3678 aport = 0; 3692 aport = 0;
3679 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, 3693 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
3680 "transport-tcp",
3681 "PORT",
3682 &bport)) ||
3683 (bport > 65535) ||
3684 ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(env->cfg,
3685 "transport-tcp", 3694 "transport-tcp",
3686 "ADVERTISED-PORT", 3695 "PORT",
3687 &aport)) && 3696 &bport)) ||
3697 (bport > 65535) ||
3698 ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (env->cfg,
3699 "transport-tcp",
3700 "ADVERTISED-PORT",
3701 &aport)) &&
3688 (aport > 65535))) 3702 (aport > 65535)))
3689 { 3703 {
3690 LOG(GNUNET_ERROR_TYPE_ERROR, 3704 LOG (GNUNET_ERROR_TYPE_ERROR,
3691 _("Require valid port number for service `%s' in configuration!\n"), 3705 _ ("Require valid port number for service `%s' in configuration!\n"),
3692 "transport-tcp"); 3706 "transport-tcp");
3693 return NULL; 3707 return NULL;
3694 } 3708 }
3695 if (0 == aport) 3709 if (0 == aport)
3696 aport = bport; 3710 aport = bport;
3697 if (0 == bport) 3711 if (0 == bport)
3698 aport = 0; 3712 aport = 0;
3699 if (0 != bport) 3713 if (0 != bport)
3714 {
3715 service = LEGACY_SERVICE_start ("transport-tcp",
3716 env->cfg,
3717 LEGACY_SERVICE_OPTION_NONE);
3718 if (NULL == service)
3700 { 3719 {
3701 service = LEGACY_SERVICE_start("transport-tcp", 3720 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to start service.\n"));
3702 env->cfg, 3721 return NULL;
3703 LEGACY_SERVICE_OPTION_NONE);
3704 if (NULL == service)
3705 {
3706 LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to start service.\n"));
3707 return NULL;
3708 }
3709 } 3722 }
3723 }
3710 else 3724 else
3711 service = NULL; 3725 service = NULL;
3712 3726
3713 api = NULL; 3727 api = NULL;
3714 plugin = GNUNET_new(struct Plugin); 3728 plugin = GNUNET_new (struct Plugin);
3715 plugin->sessionmap = 3729 plugin->sessionmap =
3716 GNUNET_CONTAINER_multipeermap_create(max_connections, GNUNET_YES); 3730 GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES);
3717 plugin->max_connections = max_connections; 3731 plugin->max_connections = max_connections;
3718 plugin->open_port = bport; 3732 plugin->open_port = bport;
3719 plugin->adv_port = aport; 3733 plugin->adv_port = aport;
3720 plugin->env = env; 3734 plugin->env = env;
3721 plugin->my_welcome.header.size = htons(sizeof(struct WelcomeMessage)); 3735 plugin->my_welcome.header.size = htons (sizeof(struct WelcomeMessage));
3722 plugin->my_welcome.header.type = 3736 plugin->my_welcome.header.type =
3723 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); 3737 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME);
3724 plugin->my_welcome.clientIdentity = *plugin->env->my_identity; 3738 plugin->my_welcome.clientIdentity = *plugin->env->my_identity;
3725 3739
3726 if ((NULL != service) && 3740 if ((NULL != service) &&
3727 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 3741 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3728 "transport-tcp", 3742 "transport-tcp",
3729 "TCP_STEALTH"))) 3743 "TCP_STEALTH")))
3730 { 3744 {
3731#ifdef TCP_STEALTH 3745#ifdef TCP_STEALTH
3732 plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH; 3746 plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH;
3733 lsocks = LEGACY_SERVICE_get_listen_sockets(service); 3747 lsocks = LEGACY_SERVICE_get_listen_sockets (service);
3734 if (NULL != lsocks) 3748 if (NULL != lsocks)
3749 {
3750 uint32_t len = sizeof(struct WelcomeMessage);
3751
3752 for (i = 0; NULL != lsocks[i]; i++)
3753 {
3754 if (
3755 (GNUNET_OK !=
3756 GNUNET_NETWORK_socket_setsockopt (lsocks[i],
3757 IPPROTO_TCP,
3758 TCP_STEALTH,
3759 env->my_identity,
3760 sizeof(
3761 struct GNUNET_PeerIdentity))) ||
3762 (GNUNET_OK !=
3763 GNUNET_NETWORK_socket_setsockopt (lsocks[i],
3764 IPPROTO_TCP,
3765 TCP_STEALTH_INTEGRITY_LEN,
3766 &len,
3767 sizeof(len))))
3735 { 3768 {
3736 uint32_t len = sizeof(struct WelcomeMessage); 3769 /* TCP STEALTH not supported by kernel */
3737 3770 GNUNET_assert (0 == i);
3738 for (i = 0; NULL != lsocks[i]; i++) 3771 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3739 { 3772 _ ("TCP_STEALTH not supported on this platform.\n"));
3740 if ( 3773 goto die;
3741 (GNUNET_OK !=
3742 GNUNET_NETWORK_socket_setsockopt(lsocks[i],
3743 IPPROTO_TCP,
3744 TCP_STEALTH,
3745 env->my_identity,
3746 sizeof(
3747 struct GNUNET_PeerIdentity))) ||
3748 (GNUNET_OK !=
3749 GNUNET_NETWORK_socket_setsockopt(lsocks[i],
3750 IPPROTO_TCP,
3751 TCP_STEALTH_INTEGRITY_LEN,
3752 &len,
3753 sizeof(len))))
3754 {
3755 /* TCP STEALTH not supported by kernel */
3756 GNUNET_assert(0 == i);
3757 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
3758 _("TCP_STEALTH not supported on this platform.\n"));
3759 goto die;
3760 }
3761 }
3762 } 3774 }
3775 }
3776 }
3763#else 3777#else
3764 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3778 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3765 _("TCP_STEALTH not supported on this platform.\n")); 3779 _ ("TCP_STEALTH not supported on this platform.\n"));
3766 goto die; 3780 goto die;
3767#endif 3781#endif
3768 } 3782 }
3769 3783
3770 if ((NULL != service) && 3784 if ((NULL != service) &&
3771 (GNUNET_SYSERR != 3785 (GNUNET_SYSERR !=
3772 (ret_s = 3786 (ret_s =
3773 get_server_addresses("transport-tcp", env->cfg, &addrs, &addrlens)))) 3787 get_server_addresses ("transport-tcp", env->cfg, &addrs, &addrlens))))
3774 { 3788 {
3775 for (ret = ret_s - 1; ret >= 0; ret--) 3789 for (ret = ret_s - 1; ret >= 0; ret--)
3776 LOG(GNUNET_ERROR_TYPE_INFO, 3790 LOG (GNUNET_ERROR_TYPE_INFO,
3777 "Binding to address `%s'\n", 3791 "Binding to address `%s'\n",
3778 GNUNET_a2s(addrs[ret], addrlens[ret])); 3792 GNUNET_a2s (addrs[ret], addrlens[ret]));
3779 plugin->nat = GNUNET_NAT_register(env->cfg, 3793 plugin->nat = GNUNET_NAT_register (env->cfg,
3780 "transport-tcp", 3794 "transport-tcp",
3781 IPPROTO_TCP, 3795 IPPROTO_TCP,
3782 (unsigned int)ret_s, 3796 (unsigned int) ret_s,
3783 (const struct sockaddr **)addrs, 3797 (const struct sockaddr **) addrs,
3784 addrlens, 3798 addrlens,
3785 &tcp_nat_port_map_callback, 3799 &tcp_nat_port_map_callback,
3786 &try_connection_reversal, 3800 &try_connection_reversal,
3787 plugin); 3801 plugin);
3788 for (ret = ret_s - 1; ret >= 0; ret--) 3802 for (ret = ret_s - 1; ret >= 0; ret--)
3789 GNUNET_free(addrs[ret]); 3803 GNUNET_free (addrs[ret]);
3790 GNUNET_free_non_null(addrs); 3804 GNUNET_free_non_null (addrs);
3791 GNUNET_free_non_null(addrlens); 3805 GNUNET_free_non_null (addrlens);
3792 } 3806 }
3793 else 3807 else
3794 { 3808 {
3795 plugin->nat = GNUNET_NAT_register(plugin->env->cfg, 3809 plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
3796 "transport-tcp", 3810 "transport-tcp",
3797 IPPROTO_TCP, 3811 IPPROTO_TCP,
3798 0, 3812 0,
3799 NULL, 3813 NULL,
3800 NULL, 3814 NULL,
3801 NULL, 3815 NULL,
3802 &try_connection_reversal, 3816 &try_connection_reversal,
3803 plugin); 3817 plugin);
3804 } 3818 }
3805 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 3819 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
3806 api->cls = plugin; 3820 api->cls = plugin;
3807 api->send = &tcp_plugin_send; 3821 api->send = &tcp_plugin_send;
3808 api->get_session = &tcp_plugin_get_session; 3822 api->get_session = &tcp_plugin_get_session;
@@ -3820,65 +3834,65 @@ libgnunet_plugin_transport_tcp_init(void *cls)
3820 api->setup_monitor = &tcp_plugin_setup_monitor; 3834 api->setup_monitor = &tcp_plugin_setup_monitor;
3821 plugin->service = service; 3835 plugin->service = service;
3822 if (NULL != service) 3836 if (NULL != service)
3823 { 3837 {
3824 plugin->server = LEGACY_SERVICE_get_server(service); 3838 plugin->server = LEGACY_SERVICE_get_server (service);
3825 } 3839 }
3826 else 3840 else
3841 {
3842 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (env->cfg,
3843 "transport-tcp",
3844 "TIMEOUT",
3845 &idle_timeout))
3827 { 3846 {
3828 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg, 3847 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
3829 "transport-tcp", 3848 "transport-tcp",
3830 "TIMEOUT", 3849 "TIMEOUT");
3831 &idle_timeout)) 3850 goto die;
3832 {
3833 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
3834 "transport-tcp",
3835 "TIMEOUT");
3836 goto die;
3837 }
3838 plugin->server = GNUNET_SERVER_create_with_sockets(NULL,
3839 plugin,
3840 NULL,
3841 idle_timeout,
3842 GNUNET_YES);
3843 } 3851 }
3844 plugin->handlers = GNUNET_malloc(sizeof(my_handlers)); 3852 plugin->server = GNUNET_SERVER_create_with_sockets (NULL,
3845 GNUNET_memcpy(plugin->handlers, my_handlers, sizeof(my_handlers)); 3853 plugin,
3854 NULL,
3855 idle_timeout,
3856 GNUNET_YES);
3857 }
3858 plugin->handlers = GNUNET_malloc (sizeof(my_handlers));
3859 GNUNET_memcpy (plugin->handlers, my_handlers, sizeof(my_handlers));
3846 for (i = 0; 3860 for (i = 0;
3847 i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler); 3861 i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);
3848 i++) 3862 i++)
3849 plugin->handlers[i].callback_cls = plugin; 3863 plugin->handlers[i].callback_cls = plugin;
3850 3864
3851 GNUNET_SERVER_add_handlers(plugin->server, plugin->handlers); 3865 GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers);
3852 GNUNET_SERVER_connect_notify(plugin->server, &connect_notify, plugin); 3866 GNUNET_SERVER_connect_notify (plugin->server, &connect_notify, plugin);
3853 GNUNET_SERVER_disconnect_notify(plugin->server, &disconnect_notify, plugin); 3867 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin);
3854 plugin->nat_wait_conns = 3868 plugin->nat_wait_conns =
3855 GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); 3869 GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
3856 if (0 != bport) 3870 if (0 != bport)
3857 LOG(GNUNET_ERROR_TYPE_INFO, 3871 LOG (GNUNET_ERROR_TYPE_INFO,
3858 _("TCP transport listening on port %llu\n"), 3872 _ ("TCP transport listening on port %llu\n"),
3859 bport); 3873 bport);
3860 else 3874 else
3861 LOG(GNUNET_ERROR_TYPE_INFO, 3875 LOG (GNUNET_ERROR_TYPE_INFO,
3862 _("TCP transport not listening on any port (client only)\n")); 3876 _ ("TCP transport not listening on any port (client only)\n"));
3863 if ((aport != bport) && (0 != bport)) 3877 if ((aport != bport) && (0 != bport))
3864 LOG(GNUNET_ERROR_TYPE_INFO, 3878 LOG (GNUNET_ERROR_TYPE_INFO,
3865 _("TCP transport advertises itself as being on port %llu\n"), 3879 _ ("TCP transport advertises itself as being on port %llu\n"),
3866 aport); 3880 aport);
3867 /* Initially set connections to 0 */ 3881 /* Initially set connections to 0 */
3868 GNUNET_STATISTICS_set(plugin->env->stats, 3882 GNUNET_STATISTICS_set (plugin->env->stats,
3869 gettext_noop("# TCP sessions active"), 3883 gettext_noop ("# TCP sessions active"),
3870 0, 3884 0,
3871 GNUNET_NO); 3885 GNUNET_NO);
3872 return api; 3886 return api;
3873 3887
3874die: 3888die:
3875 if (NULL != plugin->nat) 3889 if (NULL != plugin->nat)
3876 GNUNET_NAT_unregister(plugin->nat); 3890 GNUNET_NAT_unregister (plugin->nat);
3877 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessionmap); 3891 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap);
3878 if (NULL != service) 3892 if (NULL != service)
3879 LEGACY_SERVICE_stop(service); 3893 LEGACY_SERVICE_stop (service);
3880 GNUNET_free(plugin); 3894 GNUNET_free (plugin);
3881 GNUNET_free_non_null(api); 3895 GNUNET_free_non_null (api);
3882 return NULL; 3896 return NULL;
3883} 3897}
3884 3898
@@ -3890,7 +3904,7 @@ die:
3890 * @return NULL 3904 * @return NULL
3891 */ 3905 */
3892void * 3906void *
3893libgnunet_plugin_transport_tcp_done(void *cls) 3907libgnunet_plugin_transport_tcp_done (void *cls)
3894{ 3908{
3895 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3909 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3896 struct Plugin *plugin = api->cls; 3910 struct Plugin *plugin = api->cls;
@@ -3899,52 +3913,52 @@ libgnunet_plugin_transport_tcp_done(void *cls)
3899 struct PrettyPrinterContext *next; 3913 struct PrettyPrinterContext *next;
3900 3914
3901 if (NULL == plugin) 3915 if (NULL == plugin)
3902 { 3916 {
3903 GNUNET_free(api); 3917 GNUNET_free (api);
3904 return NULL; 3918 return NULL;
3905 } 3919 }
3906 LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); 3920 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n");
3907 3921
3908 /* Removing leftover sessions */ 3922 /* Removing leftover sessions */
3909 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessionmap, 3923 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap,
3910 &session_disconnect_it, 3924 &session_disconnect_it,
3911 plugin); 3925 plugin);
3912 /* Removing leftover NAT sessions */ 3926 /* Removing leftover NAT sessions */
3913 GNUNET_CONTAINER_multipeermap_iterate(plugin->nat_wait_conns, 3927 GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns,
3914 &session_disconnect_it, 3928 &session_disconnect_it,
3915 plugin); 3929 plugin);
3916 3930
3917 for (cur = plugin->ppc_dll_head; NULL != cur; cur = next) 3931 for (cur = plugin->ppc_dll_head; NULL != cur; cur = next)
3918 { 3932 {
3919 next = cur->next; 3933 next = cur->next;
3920 GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head, 3934 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head,
3921 plugin->ppc_dll_tail, 3935 plugin->ppc_dll_tail,
3922 cur); 3936 cur);
3923 GNUNET_RESOLVER_request_cancel(cur->resolver_handle); 3937 GNUNET_RESOLVER_request_cancel (cur->resolver_handle);
3924 cur->asc(cur->asc_cls, NULL, GNUNET_OK); 3938 cur->asc (cur->asc_cls, NULL, GNUNET_OK);
3925 GNUNET_free(cur); 3939 GNUNET_free (cur);
3926 } 3940 }
3927 3941
3928 if (NULL != plugin->service) 3942 if (NULL != plugin->service)
3929 LEGACY_SERVICE_stop(plugin->service); 3943 LEGACY_SERVICE_stop (plugin->service);
3930 else 3944 else
3931 GNUNET_SERVER_destroy(plugin->server); 3945 GNUNET_SERVER_destroy (plugin->server);
3932 GNUNET_free(plugin->handlers); 3946 GNUNET_free (plugin->handlers);
3933 if (NULL != plugin->nat) 3947 if (NULL != plugin->nat)
3934 GNUNET_NAT_unregister(plugin->nat); 3948 GNUNET_NAT_unregister (plugin->nat);
3935 while (NULL != (tcp_probe = plugin->probe_head)) 3949 while (NULL != (tcp_probe = plugin->probe_head))
3936 { 3950 {
3937 GNUNET_CONTAINER_DLL_remove(plugin->probe_head, 3951 GNUNET_CONTAINER_DLL_remove (plugin->probe_head,
3938 plugin->probe_tail, 3952 plugin->probe_tail,
3939 tcp_probe); 3953 tcp_probe);
3940 GNUNET_CONNECTION_destroy(tcp_probe->sock); 3954 GNUNET_CONNECTION_destroy (tcp_probe->sock);
3941 GNUNET_free(tcp_probe); 3955 GNUNET_free (tcp_probe);
3942 } 3956 }
3943 GNUNET_CONTAINER_multipeermap_destroy(plugin->nat_wait_conns); 3957 GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns);
3944 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessionmap); 3958 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap);
3945 GNUNET_break(0 == plugin->cur_connections); 3959 GNUNET_break (0 == plugin->cur_connections);
3946 GNUNET_free(plugin); 3960 GNUNET_free (plugin);
3947 GNUNET_free(api); 3961 GNUNET_free (api);
3948 return NULL; 3962 return NULL;
3949} 3963}
3950 3964
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 @@
31#include "gnunet_transport_service.h" 31#include "gnunet_transport_service.h"
32#include "gnunet_transport_plugin.h" 32#include "gnunet_transport_plugin.h"
33 33
34#define LOG(kind, ...) GNUNET_log_from(kind, "transport-template", __VA_ARGS__) 34#define LOG(kind, ...) GNUNET_log_from (kind, "transport-template", __VA_ARGS__)
35 35
36/** 36/**
37 * After how long do we expire an address that we 37 * After how long do we expire an address that we
38 * learned from another peer if it is not reconfirmed 38 * learned from another peer if it is not reconfirmed
39 * by anyone? 39 * by anyone?
40 */ 40 */
41#define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 6) 41#define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply ( \
42 GNUNET_TIME_UNIT_HOURS, 6)
42 43
43#define PLUGIN_NAME "template" 44#define PLUGIN_NAME "template"
44 45
@@ -51,7 +52,8 @@ struct Plugin;
51/** 52/**
52 * Session handle for connections. 53 * Session handle for connections.
53 */ 54 */
54struct GNUNET_ATS_Session { 55struct GNUNET_ATS_Session
56{
55 /** 57 /**
56 * To whom are we talking to (set to our identity 58 * To whom are we talking to (set to our identity
57 * if we are still waiting for the welcome message) 59 * if we are still waiting for the welcome message)
@@ -105,7 +107,8 @@ struct GNUNET_ATS_Session {
105 107
106GNUNET_NETWORK_STRUCT_BEGIN 108GNUNET_NETWORK_STRUCT_BEGIN
107 109
108struct TemplateAddress { 110struct TemplateAddress
111{
109 /** 112 /**
110 * Address options in NBO 113 * Address options in NBO
111 */ 114 */
@@ -119,7 +122,8 @@ GNUNET_NETWORK_STRUCT_END
119/** 122/**
120 * Encapsulation of all of the state of the plugin. 123 * Encapsulation of all of the state of the plugin.
121 */ 124 */
122struct Plugin { 125struct Plugin
126{
123 /** 127 /**
124 * Our environment. 128 * Our environment.
125 */ 129 */
@@ -156,15 +160,15 @@ struct Plugin {
156 * @param state new state of the session 160 * @param state new state of the session
157 */ 161 */
158static void 162static void
159notify_session_monitor(struct Plugin *plugin, 163notify_session_monitor (struct Plugin *plugin,
160 struct GNUNET_ATS_Session *session, 164 struct GNUNET_ATS_Session *session,
161 enum GNUNET_TRANSPORT_SessionState state) 165 enum GNUNET_TRANSPORT_SessionState state)
162{ 166{
163 struct GNUNET_TRANSPORT_SessionInfo info; 167 struct GNUNET_TRANSPORT_SessionInfo info;
164 168
165 if (NULL == plugin->sic) 169 if (NULL == plugin->sic)
166 return; 170 return;
167 memset(&info, 0, sizeof(info)); 171 memset (&info, 0, sizeof(info));
168 info.state = state; 172 info.state = state;
169 info.is_inbound = GNUNET_SYSERR; /* FIXME */ 173 info.is_inbound = GNUNET_SYSERR; /* FIXME */
170 // info.num_msg_pending = 174 // info.num_msg_pending =
@@ -172,9 +176,9 @@ notify_session_monitor(struct Plugin *plugin,
172 // info.receive_delay = 176 // info.receive_delay =
173 // info.session_timeout = session->timeout; 177 // info.session_timeout = session->timeout;
174 // info.address = session->address; 178 // info.address = session->address;
175 plugin->sic(plugin->sic_cls, 179 plugin->sic (plugin->sic_cls,
176 session, 180 session,
177 &info); 181 &info);
178} 182}
179#endif 183#endif
180 184
@@ -207,14 +211,14 @@ notify_session_monitor(struct Plugin *plugin,
207 * and does NOT mean that the message was not transmitted (DV) 211 * and does NOT mean that the message was not transmitted (DV)
208 */ 212 */
209static ssize_t 213static ssize_t
210template_plugin_send(void *cls, 214template_plugin_send (void *cls,
211 struct GNUNET_ATS_Session *session, 215 struct GNUNET_ATS_Session *session,
212 const char *msgbuf, 216 const char *msgbuf,
213 size_t msgbuf_size, 217 size_t msgbuf_size,
214 unsigned int priority, 218 unsigned int priority,
215 struct GNUNET_TIME_Relative to, 219 struct GNUNET_TIME_Relative to,
216 GNUNET_TRANSPORT_TransmitContinuation cont, 220 GNUNET_TRANSPORT_TransmitContinuation cont,
217 void *cont_cls) 221 void *cont_cls)
218{ 222{
219 /* struct Plugin *plugin = cls; */ 223 /* struct Plugin *plugin = cls; */
220 ssize_t bytes_sent = 0; 224 ssize_t bytes_sent = 0;
@@ -232,8 +236,8 @@ template_plugin_send(void *cls,
232 * @param target peer from which to disconnect 236 * @param target peer from which to disconnect
233 */ 237 */
234static void 238static void
235template_plugin_disconnect_peer(void *cls, 239template_plugin_disconnect_peer (void *cls,
236 const struct GNUNET_PeerIdentity *target) 240 const struct GNUNET_PeerIdentity *target)
237{ 241{
238 // struct Plugin *plugin = cls; 242 // struct Plugin *plugin = cls;
239 // FIXME 243 // FIXME
@@ -250,8 +254,8 @@ template_plugin_disconnect_peer(void *cls,
250 * @return #GNUNET_OK on success 254 * @return #GNUNET_OK on success
251 */ 255 */
252static int 256static int
253template_plugin_disconnect_session(void *cls, 257template_plugin_disconnect_session (void *cls,
254 struct GNUNET_ATS_Session *session) 258 struct GNUNET_ATS_Session *session)
255{ 259{
256 // struct Plugin *plugin = cls; 260 // struct Plugin *plugin = cls;
257 // FIXME 261 // FIXME
@@ -268,7 +272,7 @@ template_plugin_disconnect_session(void *cls,
268 * @return keepalive factor 272 * @return keepalive factor
269 */ 273 */
270static unsigned int 274static unsigned int
271template_plugin_query_keepalive_factor(void *cls) 275template_plugin_query_keepalive_factor (void *cls)
272{ 276{
273 return 3; 277 return 3;
274} 278}
@@ -282,10 +286,10 @@ template_plugin_query_keepalive_factor(void *cls)
282 * @return the network type in HBO or #GNUNET_SYSERR 286 * @return the network type in HBO or #GNUNET_SYSERR
283 */ 287 */
284static enum GNUNET_NetworkType 288static enum GNUNET_NetworkType
285template_plugin_get_network(void *cls, 289template_plugin_get_network (void *cls,
286 struct GNUNET_ATS_Session *session) 290 struct GNUNET_ATS_Session *session)
287{ 291{
288 GNUNET_assert(NULL != session); 292 GNUNET_assert (NULL != session);
289 return GNUNET_NT_UNSPECIFIED; /* Change to correct network type */ 293 return GNUNET_NT_UNSPECIFIED; /* Change to correct network type */
290} 294}
291 295
@@ -298,8 +302,9 @@ template_plugin_get_network(void *cls,
298 * @return the network type 302 * @return the network type
299 */ 303 */
300static enum GNUNET_NetworkType 304static enum GNUNET_NetworkType
301template_plugin_get_network_for_address(void *cls, 305template_plugin_get_network_for_address (void *cls,
302 const struct GNUNET_HELLO_Address *address) 306 const struct
307 GNUNET_HELLO_Address *address)
303{ 308{
304 return GNUNET_NT_WAN; /* FOR NOW */ 309 return GNUNET_NT_WAN; /* FOR NOW */
305} 310}
@@ -320,15 +325,15 @@ template_plugin_get_network_for_address(void *cls,
320 * @param asc_cls closure for @a asc 325 * @param asc_cls closure for @a asc
321 */ 326 */
322static void 327static void
323template_plugin_address_pretty_printer(void *cls, const char *type, 328template_plugin_address_pretty_printer (void *cls, const char *type,
324 const void *addr, size_t addrlen, 329 const void *addr, size_t addrlen,
325 int numeric, 330 int numeric,
326 struct GNUNET_TIME_Relative timeout, 331 struct GNUNET_TIME_Relative timeout,
327 GNUNET_TRANSPORT_AddressStringCallback 332 GNUNET_TRANSPORT_AddressStringCallback
328 asc, void *asc_cls) 333 asc, void *asc_cls)
329{ 334{
330 asc(asc_cls, "converted address", GNUNET_OK); /* return address */ 335 asc (asc_cls, "converted address", GNUNET_OK); /* return address */
331 asc(asc_cls, NULL, GNUNET_OK); /* done */ 336 asc (asc_cls, NULL, GNUNET_OK); /* done */
332} 337}
333 338
334 339
@@ -346,7 +351,7 @@ template_plugin_address_pretty_printer(void *cls, const char *type,
346 * and transport 351 * and transport
347 */ 352 */
348static int 353static int
349template_plugin_address_suggested(void *cls, const void *addr, size_t addrlen) 354template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
350{ 355{
351 /* struct Plugin *plugin = cls; */ 356 /* struct Plugin *plugin = cls; */
352 357
@@ -367,18 +372,18 @@ template_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
367 * @return string representing the same address 372 * @return string representing the same address
368 */ 373 */
369static const char * 374static const char *
370template_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) 375template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
371{ 376{
372 /* 377 /*
373 * Print address in format template.options.address 378 * Print address in format template.options.address
374 */ 379 */
375 380
376 if (0 == addrlen) 381 if (0 == addrlen)
377 { 382 {
378 return TRANSPORT_SESSION_INBOUND_STRING; 383 return TRANSPORT_SESSION_INBOUND_STRING;
379 } 384 }
380 385
381 GNUNET_break(0); 386 GNUNET_break (0);
382 return NULL; 387 return NULL;
383} 388}
384 389
@@ -396,15 +401,15 @@ template_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
396 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 401 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
397 */ 402 */
398static int 403static int
399template_plugin_string_to_address(void *cls, 404template_plugin_string_to_address (void *cls,
400 const char *addr, 405 const char *addr,
401 uint16_t addrlen, 406 uint16_t addrlen,
402 void **buf, size_t *added) 407 void **buf, size_t *added)
403{ 408{
404 /* 409 /*
405 * Parse string in format template.options.address 410 * Parse string in format template.options.address
406 */ 411 */
407 GNUNET_break(0); 412 GNUNET_break (0);
408 return GNUNET_SYSERR; 413 return GNUNET_SYSERR;
409} 414}
410 415
@@ -419,18 +424,18 @@ template_plugin_string_to_address(void *cls,
419 * @return the session if the address is valid, NULL otherwise 424 * @return the session if the address is valid, NULL otherwise
420 */ 425 */
421static struct GNUNET_ATS_Session * 426static struct GNUNET_ATS_Session *
422template_plugin_get_session(void *cls, 427template_plugin_get_session (void *cls,
423 const struct GNUNET_HELLO_Address *address) 428 const struct GNUNET_HELLO_Address *address)
424{ 429{
425 GNUNET_break(0); 430 GNUNET_break (0);
426 return NULL; 431 return NULL;
427} 432}
428 433
429 434
430static void 435static void
431template_plugin_update_session_timeout(void *cls, 436template_plugin_update_session_timeout (void *cls,
432 const struct GNUNET_PeerIdentity *peer, 437 const struct GNUNET_PeerIdentity *peer,
433 struct GNUNET_ATS_Session *session) 438 struct GNUNET_ATS_Session *session)
434{ 439{
435} 440}
436 441
@@ -446,16 +451,16 @@ template_plugin_update_session_timeout(void *cls,
446 * @return #GNUNET_OK (continue to iterate) 451 * @return #GNUNET_OK (continue to iterate)
447 */ 452 */
448static int 453static int
449send_session_info_iter(void *cls, 454send_session_info_iter (void *cls,
450 const struct GNUNET_PeerIdentity *peer, 455 const struct GNUNET_PeerIdentity *peer,
451 void *value) 456 void *value)
452{ 457{
453 struct Plugin *plugin = cls; 458 struct Plugin *plugin = cls;
454 struct GNUNET_ATS_Session *session = value; 459 struct GNUNET_ATS_Session *session = value;
455 460
456 notify_session_monitor(plugin, 461 notify_session_monitor (plugin,
457 session, 462 session,
458 GNUNET_TRANSPORT_SS_UP); 463 GNUNET_TRANSPORT_SS_UP);
459 return GNUNET_OK; 464 return GNUNET_OK;
460} 465}
461#endif 466#endif
@@ -474,24 +479,24 @@ send_session_info_iter(void *cls,
474 * @param sic_cls closure for @a sic 479 * @param sic_cls closure for @a sic
475 */ 480 */
476static void 481static void
477template_plugin_setup_monitor(void *cls, 482template_plugin_setup_monitor (void *cls,
478 GNUNET_TRANSPORT_SessionInfoCallback sic, 483 GNUNET_TRANSPORT_SessionInfoCallback sic,
479 void *sic_cls) 484 void *sic_cls)
480{ 485{
481 struct Plugin *plugin = cls; 486 struct Plugin *plugin = cls;
482 487
483 plugin->sic = sic; 488 plugin->sic = sic;
484 plugin->sic_cls = sic_cls; 489 plugin->sic_cls = sic_cls;
485 if (NULL != sic) 490 if (NULL != sic)
486 { 491 {
487#if 0 492#if 0
488 GNUNET_CONTAINER_multipeermap_iterate(NULL /* FIXME */, 493 GNUNET_CONTAINER_multipeermap_iterate (NULL /* FIXME */,
489 &send_session_info_iter, 494 &send_session_info_iter,
490 plugin); 495 plugin);
491#endif 496#endif
492 /* signal end of first iteration */ 497 /* signal end of first iteration */
493 sic(sic_cls, NULL, NULL); 498 sic (sic_cls, NULL, NULL);
494 } 499 }
495} 500}
496 501
497 502
@@ -499,27 +504,27 @@ template_plugin_setup_monitor(void *cls,
499 * Entry point for the plugin. 504 * Entry point for the plugin.
500 */ 505 */
501void * 506void *
502libgnunet_plugin_transport_template_init(void *cls) 507libgnunet_plugin_transport_template_init (void *cls)
503{ 508{
504 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 509 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
505 struct GNUNET_TRANSPORT_PluginFunctions *api; 510 struct GNUNET_TRANSPORT_PluginFunctions *api;
506 struct Plugin *plugin; 511 struct Plugin *plugin;
507 512
508 if (NULL == env->receive) 513 if (NULL == env->receive)
509 { 514 {
510 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 515 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
511 initialze the plugin or the API */ 516 initialze the plugin or the API */
512 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 517 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
513 api->cls = NULL; 518 api->cls = NULL;
514 api->address_to_string = &template_plugin_address_to_string; 519 api->address_to_string = &template_plugin_address_to_string;
515 api->string_to_address = &template_plugin_string_to_address; 520 api->string_to_address = &template_plugin_string_to_address;
516 api->address_pretty_printer = &template_plugin_address_pretty_printer; 521 api->address_pretty_printer = &template_plugin_address_pretty_printer;
517 return api; 522 return api;
518 } 523 }
519 524
520 plugin = GNUNET_new(struct Plugin); 525 plugin = GNUNET_new (struct Plugin);
521 plugin->env = env; 526 plugin->env = env;
522 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 527 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
523 api->cls = plugin; 528 api->cls = plugin;
524 api->send = &template_plugin_send; 529 api->send = &template_plugin_send;
525 api->disconnect_peer = &template_plugin_disconnect_peer; 530 api->disconnect_peer = &template_plugin_disconnect_peer;
@@ -534,7 +539,7 @@ libgnunet_plugin_transport_template_init(void *cls)
534 api->get_network_for_address = &template_plugin_get_network_for_address; 539 api->get_network_for_address = &template_plugin_get_network_for_address;
535 api->update_session_timeout = &template_plugin_update_session_timeout; 540 api->update_session_timeout = &template_plugin_update_session_timeout;
536 api->setup_monitor = &template_plugin_setup_monitor; 541 api->setup_monitor = &template_plugin_setup_monitor;
537 LOG(GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n"); 542 LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n");
538 return api; 543 return api;
539} 544}
540 545
@@ -543,13 +548,13 @@ libgnunet_plugin_transport_template_init(void *cls)
543 * Exit point from the plugin. 548 * Exit point from the plugin.
544 */ 549 */
545void * 550void *
546libgnunet_plugin_transport_template_done(void *cls) 551libgnunet_plugin_transport_template_done (void *cls)
547{ 552{
548 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 553 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
549 struct Plugin *plugin = api->cls; 554 struct Plugin *plugin = api->cls;
550 555
551 GNUNET_free(plugin); 556 GNUNET_free (plugin);
552 GNUNET_free(api); 557 GNUNET_free (api);
553 return NULL; 558 return NULL;
554} 559}
555 560
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 @@
40#include "gnunet_transport_plugin.h" 40#include "gnunet_transport_plugin.h"
41#include "transport.h" 41#include "transport.h"
42 42
43#define LOG(kind, ...) GNUNET_log_from(kind, "transport-udp", __VA_ARGS__) 43#define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
44 44
45/** 45/**
46 * After how much inactivity should a UDP session time out? 46 * After how much inactivity should a UDP session time out?
47 */ 47 */
48#define UDP_SESSION_TIME_OUT \ 48#define UDP_SESSION_TIME_OUT \
49 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) 49 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
50 50
51/** 51/**
52 * Number of messages we can defragment in parallel. We only really 52 * Number of messages we can defragment in parallel. We only really
@@ -71,7 +71,8 @@
71/** 71/**
72 * UDP Message-Packet header (after defragmentation). 72 * UDP Message-Packet header (after defragmentation).
73 */ 73 */
74struct UDPMessage { 74struct UDPMessage
75{
75 /** 76 /**
76 * Message header. 77 * Message header.
77 */ 78 */
@@ -92,7 +93,8 @@ struct UDPMessage {
92/** 93/**
93 * Closure for #append_port(). 94 * Closure for #append_port().
94 */ 95 */
95struct PrettyPrinterContext { 96struct PrettyPrinterContext
97{
96 /** 98 /**
97 * DLL 99 * DLL
98 */ 100 */
@@ -148,7 +150,8 @@ struct PrettyPrinterContext {
148/** 150/**
149 * Session with another peer. 151 * Session with another peer.
150 */ 152 */
151struct GNUNET_ATS_Session { 153struct GNUNET_ATS_Session
154{
152 /** 155 /**
153 * Which peer is this session for? 156 * Which peer is this session for?
154 */ 157 */
@@ -248,7 +251,8 @@ struct GNUNET_ATS_Session {
248 * Data structure to track defragmentation contexts based 251 * Data structure to track defragmentation contexts based
249 * on the source of the UDP traffic. 252 * on the source of the UDP traffic.
250 */ 253 */
251struct DefragContext { 254struct DefragContext
255{
252 /** 256 /**
253 * Defragmentation context. 257 * Defragmentation context.
254 */ 258 */
@@ -297,7 +301,8 @@ struct DefragContext {
297/** 301/**
298 * Context to send fragmented messages 302 * Context to send fragmented messages
299 */ 303 */
300struct UDP_FragmentationContext { 304struct UDP_FragmentationContext
305{
301 /** 306 /**
302 * Next in linked list 307 * Next in linked list
303 */ 308 */
@@ -387,7 +392,8 @@ typedef void (*QueueContinuation) (void *cls,
387/** 392/**
388 * Information we track for each message in the queue. 393 * Information we track for each message in the queue.
389 */ 394 */
390struct UDP_MessageWrapper { 395struct UDP_MessageWrapper
396{
391 /** 397 /**
392 * Session this message belongs to 398 * Session this message belongs to
393 */ 399 */
@@ -471,7 +477,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
471/** 477/**
472 * UDP ACK Message-Packet header. 478 * UDP ACK Message-Packet header.
473 */ 479 */
474struct UDP_ACK_Message { 480struct UDP_ACK_Message
481{
475 /** 482 /**
476 * Message header. 483 * Message header.
477 */ 484 */
@@ -505,9 +512,9 @@ GNUNET_NETWORK_STRUCT_END
505 * @param state new state of the session 512 * @param state new state of the session
506 */ 513 */
507static void 514static void
508notify_session_monitor(struct Plugin *plugin, 515notify_session_monitor (struct Plugin *plugin,
509 struct GNUNET_ATS_Session *session, 516 struct GNUNET_ATS_Session *session,
510 enum GNUNET_TRANSPORT_SessionState state) 517 enum GNUNET_TRANSPORT_SessionState state)
511{ 518{
512 struct GNUNET_TRANSPORT_SessionInfo info; 519 struct GNUNET_TRANSPORT_SessionInfo info;
513 520
@@ -515,7 +522,7 @@ notify_session_monitor(struct Plugin *plugin,
515 return; 522 return;
516 if (GNUNET_YES == session->in_destroy) 523 if (GNUNET_YES == session->in_destroy)
517 return; /* already destroyed, just RC>0 left-over actions */ 524 return; /* already destroyed, just RC>0 left-over actions */
518 memset(&info, 0, sizeof(info)); 525 memset (&info, 0, sizeof(info));
519 info.state = state; 526 info.state = state;
520 info.is_inbound = GNUNET_SYSERR; /* hard to say */ 527 info.is_inbound = GNUNET_SYSERR; /* hard to say */
521 info.num_msg_pending = session->msgs_in_queue; 528 info.num_msg_pending = session->msgs_in_queue;
@@ -525,7 +532,7 @@ notify_session_monitor(struct Plugin *plugin,
525 to receive from others) */ 532 to receive from others) */
526 info.session_timeout = session->timeout; 533 info.session_timeout = session->timeout;
527 info.address = session->address; 534 info.address = session->address;
528 plugin->sic(plugin->sic_cls, session, &info); 535 plugin->sic (plugin->sic_cls, session, &info);
529} 536}
530 537
531 538
@@ -538,15 +545,15 @@ notify_session_monitor(struct Plugin *plugin,
538 * @return #GNUNET_OK (continue to iterate) 545 * @return #GNUNET_OK (continue to iterate)
539 */ 546 */
540static int 547static int
541send_session_info_iter(void *cls, 548send_session_info_iter (void *cls,
542 const struct GNUNET_PeerIdentity *peer, 549 const struct GNUNET_PeerIdentity *peer,
543 void *value) 550 void *value)
544{ 551{
545 struct Plugin *plugin = cls; 552 struct Plugin *plugin = cls;
546 struct GNUNET_ATS_Session *session = value; 553 struct GNUNET_ATS_Session *session = value;
547 554
548 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); 555 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
549 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); 556 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
550 return GNUNET_OK; 557 return GNUNET_OK;
551} 558}
552 559
@@ -564,22 +571,22 @@ send_session_info_iter(void *cls,
564 * @param sic_cls closure for @a sic 571 * @param sic_cls closure for @a sic
565 */ 572 */
566static void 573static void
567udp_plugin_setup_monitor(void *cls, 574udp_plugin_setup_monitor (void *cls,
568 GNUNET_TRANSPORT_SessionInfoCallback sic, 575 GNUNET_TRANSPORT_SessionInfoCallback sic,
569 void *sic_cls) 576 void *sic_cls)
570{ 577{
571 struct Plugin *plugin = cls; 578 struct Plugin *plugin = cls;
572 579
573 plugin->sic = sic; 580 plugin->sic = sic;
574 plugin->sic_cls = sic_cls; 581 plugin->sic_cls = sic_cls;
575 if (NULL != sic) 582 if (NULL != sic)
576 { 583 {
577 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, 584 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
578 &send_session_info_iter, 585 &send_session_info_iter,
579 plugin); 586 plugin);
580 /* signal end of first iteration */ 587 /* signal end of first iteration */
581 sic(sic_cls, NULL, NULL); 588 sic (sic_cls, NULL, NULL);
582 } 589 }
583} 590}
584 591
585 592
@@ -592,25 +599,25 @@ udp_plugin_setup_monitor(void *cls,
592 * @param s session to free 599 * @param s session to free
593 */ 600 */
594static void 601static void
595free_session(struct GNUNET_ATS_Session *s) 602free_session (struct GNUNET_ATS_Session *s)
596{ 603{
597 if (NULL != s->address) 604 if (NULL != s->address)
598 { 605 {
599 GNUNET_HELLO_address_free(s->address); 606 GNUNET_HELLO_address_free (s->address);
600 s->address = NULL; 607 s->address = NULL;
601 } 608 }
602 if (NULL != s->frag_ctx) 609 if (NULL != s->frag_ctx)
603 { 610 {
604 GNUNET_FRAGMENT_context_destroy(s->frag_ctx->frag, NULL, NULL); 611 GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL);
605 GNUNET_free(s->frag_ctx); 612 GNUNET_free (s->frag_ctx);
606 s->frag_ctx = NULL; 613 s->frag_ctx = NULL;
607 } 614 }
608 if (NULL != s->mst) 615 if (NULL != s->mst)
609 { 616 {
610 GNUNET_MST_destroy(s->mst); 617 GNUNET_MST_destroy (s->mst);
611 s->mst = NULL; 618 s->mst = NULL;
612 } 619 }
613 GNUNET_free(s); 620 GNUNET_free (s);
614} 621}
615 622
616 623
@@ -623,7 +630,7 @@ free_session(struct GNUNET_ATS_Session *s)
623 * @return keepalive factor 630 * @return keepalive factor
624 */ 631 */
625static unsigned int 632static unsigned int
626udp_query_keepalive_factor(void *cls) 633udp_query_keepalive_factor (void *cls)
627{ 634{
628 return 15; 635 return 15;
629} 636}
@@ -637,7 +644,7 @@ udp_query_keepalive_factor(void *cls)
637 * @return the network type 644 * @return the network type
638 */ 645 */
639static enum GNUNET_NetworkType 646static enum GNUNET_NetworkType
640udp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) 647udp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
641{ 648{
642 return session->scope; 649 return session->scope;
643} 650}
@@ -651,8 +658,8 @@ udp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
651 * @return the network type 658 * @return the network type
652 */ 659 */
653static enum GNUNET_NetworkType 660static enum GNUNET_NetworkType
654udp_plugin_get_network_for_address(void *cls, 661udp_plugin_get_network_for_address (void *cls,
655 const struct GNUNET_HELLO_Address *address) 662 const struct GNUNET_HELLO_Address *address)
656{ 663{
657 struct Plugin *plugin = cls; 664 struct Plugin *plugin = cls;
658 size_t addrlen; 665 size_t addrlen;
@@ -665,39 +672,39 @@ udp_plugin_get_network_for_address(void *cls,
665 672
666 addrlen = address->address_length; 673 addrlen = address->address_length;
667 if (addrlen == sizeof(struct IPv6UdpAddress)) 674 if (addrlen == sizeof(struct IPv6UdpAddress))
668 { 675 {
669 GNUNET_assert(NULL != address->address); /* make static analysis happy */ 676 GNUNET_assert (NULL != address->address); /* make static analysis happy */
670 u6 = address->address; 677 u6 = address->address;
671 memset(&a6, 0, sizeof(a6)); 678 memset (&a6, 0, sizeof(a6));
672#if HAVE_SOCKADDR_IN_SIN_LEN 679#if HAVE_SOCKADDR_IN_SIN_LEN
673 a6.sin6_len = sizeof(a6); 680 a6.sin6_len = sizeof(a6);
674#endif 681#endif
675 a6.sin6_family = AF_INET6; 682 a6.sin6_family = AF_INET6;
676 a6.sin6_port = u6->u6_port; 683 a6.sin6_port = u6->u6_port;
677 GNUNET_memcpy(&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); 684 GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr));
678 sb = &a6; 685 sb = &a6;
679 sbs = sizeof(a6); 686 sbs = sizeof(a6);
680 } 687 }
681 else if (addrlen == sizeof(struct IPv4UdpAddress)) 688 else if (addrlen == sizeof(struct IPv4UdpAddress))
682 { 689 {
683 GNUNET_assert(NULL != address->address); /* make static analysis happy */ 690 GNUNET_assert (NULL != address->address); /* make static analysis happy */
684 u4 = address->address; 691 u4 = address->address;
685 memset(&a4, 0, sizeof(a4)); 692 memset (&a4, 0, sizeof(a4));
686#if HAVE_SOCKADDR_IN_SIN_LEN 693#if HAVE_SOCKADDR_IN_SIN_LEN
687 a4.sin_len = sizeof(a4); 694 a4.sin_len = sizeof(a4);
688#endif 695#endif
689 a4.sin_family = AF_INET; 696 a4.sin_family = AF_INET;
690 a4.sin_port = u4->u4_port; 697 a4.sin_port = u4->u4_port;
691 a4.sin_addr.s_addr = u4->ipv4_addr; 698 a4.sin_addr.s_addr = u4->ipv4_addr;
692 sb = &a4; 699 sb = &a4;
693 sbs = sizeof(a4); 700 sbs = sizeof(a4);
694 } 701 }
695 else 702 else
696 { 703 {
697 GNUNET_break(0); 704 GNUNET_break (0);
698 return GNUNET_NT_UNSPECIFIED; 705 return GNUNET_NT_UNSPECIFIED;
699 } 706 }
700 return plugin->env->get_address_type(plugin->env->cls, sb, sbs); 707 return plugin->env->get_address_type (plugin->env->cls, sb, sbs);
701} 708}
702 709
703 710
@@ -711,7 +718,7 @@ udp_plugin_get_network_for_address(void *cls,
711 * @param cls the plugin handle 718 * @param cls the plugin handle
712 */ 719 */
713static void 720static void
714udp_plugin_select_v4(void *cls); 721udp_plugin_select_v4 (void *cls);
715 722
716 723
717/** 724/**
@@ -722,7 +729,7 @@ udp_plugin_select_v4(void *cls);
722 * @param cls the plugin handle 729 * @param cls the plugin handle
723 */ 730 */
724static void 731static void
725udp_plugin_select_v6(void *cls); 732udp_plugin_select_v6 (void *cls);
726 733
727 734
728/** 735/**
@@ -731,7 +738,7 @@ udp_plugin_select_v6(void *cls);
731 * @param plugin plugin to reschedule 738 * @param plugin plugin to reschedule
732 */ 739 */
733static void 740static void
734schedule_select_v4(struct Plugin *plugin) 741schedule_select_v4 (struct Plugin *plugin)
735{ 742{
736 struct GNUNET_TIME_Relative min_delay; 743 struct GNUNET_TIME_Relative min_delay;
737 struct GNUNET_TIME_Relative delay; 744 struct GNUNET_TIME_Relative delay;
@@ -739,47 +746,47 @@ schedule_select_v4(struct Plugin *plugin)
739 struct UDP_MessageWrapper *min_udpw; 746 struct UDP_MessageWrapper *min_udpw;
740 747
741 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4)) 748 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
742 { 749 {
743 /* Find a message ready to send: 750 /* Find a message ready to send:
744 * Flow delay from other peer is expired or not set (0) */ 751 * Flow delay from other peer is expired or not set (0) */
745 min_delay = GNUNET_TIME_UNIT_FOREVER_REL; 752 min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
746 min_udpw = NULL; 753 min_udpw = NULL;
747 for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next) 754 for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next)
748 { 755 {
749 delay = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time); 756 delay = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time);
750 if (delay.rel_value_us < min_delay.rel_value_us) 757 if (delay.rel_value_us < min_delay.rel_value_us)
751 { 758 {
752 min_delay = delay; 759 min_delay = delay;
753 min_udpw = udpw; 760 min_udpw = udpw;
754 } 761 }
755 } 762 }
756 if (NULL != plugin->select_task_v4) 763 if (NULL != plugin->select_task_v4)
757 GNUNET_SCHEDULER_cancel(plugin->select_task_v4); 764 GNUNET_SCHEDULER_cancel (plugin->select_task_v4);
758 if (NULL != min_udpw) 765 if (NULL != min_udpw)
759 { 766 {
760 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 767 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
761 { 768 {
762 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 769 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
763 "Calculated flow delay for UDPv4 at %s for %s\n", 770 "Calculated flow delay for UDPv4 at %s for %s\n",
764 GNUNET_STRINGS_relative_time_to_string(min_delay, 771 GNUNET_STRINGS_relative_time_to_string (min_delay,
765 GNUNET_YES), 772 GNUNET_YES),
766 GNUNET_i2s(&min_udpw->session->target)); 773 GNUNET_i2s (&min_udpw->session->target));
767 } 774 }
768 else 775 else
769 { 776 {
770 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
771 "Calculated flow delay for UDPv4 at %s for %s\n", 778 "Calculated flow delay for UDPv4 at %s for %s\n",
772 GNUNET_STRINGS_relative_time_to_string(min_delay, 779 GNUNET_STRINGS_relative_time_to_string (min_delay,
773 GNUNET_YES), 780 GNUNET_YES),
774 GNUNET_i2s(&min_udpw->session->target)); 781 GNUNET_i2s (&min_udpw->session->target));
775 } 782 }
776 } 783 }
777 plugin->select_task_v4 = 784 plugin->select_task_v4 =
778 GNUNET_SCHEDULER_add_read_net(min_delay, 785 GNUNET_SCHEDULER_add_read_net (min_delay,
779 plugin->sockv4, 786 plugin->sockv4,
780 &udp_plugin_select_v4, 787 &udp_plugin_select_v4,
781 plugin); 788 plugin);
782 } 789 }
783} 790}
784 791
785 792
@@ -789,7 +796,7 @@ schedule_select_v4(struct Plugin *plugin)
789 * @param plugin plugin to reschedule 796 * @param plugin plugin to reschedule
790 */ 797 */
791static void 798static void
792schedule_select_v6(struct Plugin *plugin) 799schedule_select_v6 (struct Plugin *plugin)
793{ 800{
794 struct GNUNET_TIME_Relative min_delay; 801 struct GNUNET_TIME_Relative min_delay;
795 struct GNUNET_TIME_Relative delay; 802 struct GNUNET_TIME_Relative delay;
@@ -797,45 +804,45 @@ schedule_select_v6(struct Plugin *plugin)
797 struct UDP_MessageWrapper *min_udpw; 804 struct UDP_MessageWrapper *min_udpw;
798 805
799 if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6)) 806 if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6))
800 { 807 {
801 min_delay = GNUNET_TIME_UNIT_FOREVER_REL; 808 min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
802 min_udpw = NULL; 809 min_udpw = NULL;
803 for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next) 810 for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next)
804 { 811 {
805 delay = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time); 812 delay = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time);
806 if (delay.rel_value_us < min_delay.rel_value_us) 813 if (delay.rel_value_us < min_delay.rel_value_us)
807 { 814 {
808 min_delay = delay; 815 min_delay = delay;
809 min_udpw = udpw; 816 min_udpw = udpw;
810 } 817 }
811 } 818 }
812 if (NULL != plugin->select_task_v6) 819 if (NULL != plugin->select_task_v6)
813 GNUNET_SCHEDULER_cancel(plugin->select_task_v6); 820 GNUNET_SCHEDULER_cancel (plugin->select_task_v6);
814 if (NULL != min_udpw) 821 if (NULL != min_udpw)
815 { 822 {
816 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 823 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
817 { 824 {
818 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 825 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
819 "Calculated flow delay for UDPv6 at %s for %s\n", 826 "Calculated flow delay for UDPv6 at %s for %s\n",
820 GNUNET_STRINGS_relative_time_to_string(min_delay, 827 GNUNET_STRINGS_relative_time_to_string (min_delay,
821 GNUNET_YES), 828 GNUNET_YES),
822 GNUNET_i2s(&min_udpw->session->target)); 829 GNUNET_i2s (&min_udpw->session->target));
823 } 830 }
824 else 831 else
825 { 832 {
826 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
827 "Calculated flow delay for UDPv6 at %s for %s\n", 834 "Calculated flow delay for UDPv6 at %s for %s\n",
828 GNUNET_STRINGS_relative_time_to_string(min_delay, 835 GNUNET_STRINGS_relative_time_to_string (min_delay,
829 GNUNET_YES), 836 GNUNET_YES),
830 GNUNET_i2s(&min_udpw->session->target)); 837 GNUNET_i2s (&min_udpw->session->target));
831 } 838 }
832 } 839 }
833 plugin->select_task_v6 = 840 plugin->select_task_v6 =
834 GNUNET_SCHEDULER_add_read_net(min_delay, 841 GNUNET_SCHEDULER_add_read_net (min_delay,
835 plugin->sockv6, 842 plugin->sockv6,
836 &udp_plugin_select_v6, 843 &udp_plugin_select_v6,
837 plugin); 844 plugin);
838 } 845 }
839} 846}
840 847
841 848
@@ -854,7 +861,7 @@ schedule_select_v6(struct Plugin *plugin)
854 * @return string representing the same address 861 * @return string representing the same address
855 */ 862 */
856const char * 863const char *
857udp_address_to_string(void *cls, const void *addr, size_t addrlen) 864udp_address_to_string (void *cls, const void *addr, size_t addrlen)
858{ 865{
859 static char rbuf[INET6_ADDRSTRLEN + 10]; 866 static char rbuf[INET6_ADDRSTRLEN + 10];
860 char buf[INET6_ADDRSTRLEN]; 867 char buf[INET6_ADDRSTRLEN];
@@ -868,42 +875,42 @@ udp_address_to_string(void *cls, const void *addr, size_t addrlen)
868 uint32_t options; 875 uint32_t options;
869 876
870 if (NULL == addr) 877 if (NULL == addr)
871 { 878 {
872 GNUNET_break_op(0); 879 GNUNET_break_op (0);
873 return NULL; 880 return NULL;
874 } 881 }
875 882
876 if (addrlen == sizeof(struct IPv6UdpAddress)) 883 if (addrlen == sizeof(struct IPv6UdpAddress))
877 { 884 {
878 t6 = addr; 885 t6 = addr;
879 af = AF_INET6; 886 af = AF_INET6;
880 options = ntohl(t6->options); 887 options = ntohl (t6->options);
881 port = ntohs(t6->u6_port); 888 port = ntohs (t6->u6_port);
882 a6 = t6->ipv6_addr; 889 a6 = t6->ipv6_addr;
883 sb = &a6; 890 sb = &a6;
884 } 891 }
885 else if (addrlen == sizeof(struct IPv4UdpAddress)) 892 else if (addrlen == sizeof(struct IPv4UdpAddress))
886 { 893 {
887 t4 = addr; 894 t4 = addr;
888 af = AF_INET; 895 af = AF_INET;
889 options = ntohl(t4->options); 896 options = ntohl (t4->options);
890 port = ntohs(t4->u4_port); 897 port = ntohs (t4->u4_port);
891 a4.s_addr = t4->ipv4_addr; 898 a4.s_addr = t4->ipv4_addr;
892 sb = &a4; 899 sb = &a4;
893 } 900 }
894 else 901 else
895 { 902 {
896 GNUNET_break_op(0); 903 GNUNET_break_op (0);
897 return NULL; 904 return NULL;
898 } 905 }
899 inet_ntop(af, sb, buf, INET6_ADDRSTRLEN); 906 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
900 GNUNET_snprintf(rbuf, 907 GNUNET_snprintf (rbuf,
901 sizeof(rbuf), 908 sizeof(rbuf),
902 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", 909 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
903 PLUGIN_NAME, 910 PLUGIN_NAME,
904 options, 911 options,
905 buf, 912 buf,
906 port); 913 port);
907 return rbuf; 914 return rbuf;
908} 915}
909 916
@@ -920,11 +927,11 @@ udp_address_to_string(void *cls, const void *addr, size_t addrlen)
920 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 927 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
921 */ 928 */
922static int 929static int
923udp_string_to_address(void *cls, 930udp_string_to_address (void *cls,
924 const char *addr, 931 const char *addr,
925 uint16_t addrlen, 932 uint16_t addrlen,
926 void **buf, 933 void **buf,
927 size_t *added) 934 size_t *added)
928{ 935{
929 struct sockaddr_storage socket_address; 936 struct sockaddr_storage socket_address;
930 char *address; 937 char *address;
@@ -938,59 +945,59 @@ udp_string_to_address(void *cls,
938 optionstr = NULL; 945 optionstr = NULL;
939 946
940 if ((NULL == addr) || (0 == addrlen)) 947 if ((NULL == addr) || (0 == addrlen))
941 { 948 {
942 GNUNET_break(0); 949 GNUNET_break (0);
943 return GNUNET_SYSERR; 950 return GNUNET_SYSERR;
944 } 951 }
945 if ('\0' != addr[addrlen - 1]) 952 if ('\0' != addr[addrlen - 1])
946 { 953 {
947 GNUNET_break(0); 954 GNUNET_break (0);
948 return GNUNET_SYSERR; 955 return GNUNET_SYSERR;
949 } 956 }
950 if (strlen(addr) != addrlen - 1) 957 if (strlen (addr) != addrlen - 1)
951 { 958 {
952 GNUNET_break(0); 959 GNUNET_break (0);
953 return GNUNET_SYSERR; 960 return GNUNET_SYSERR;
954 } 961 }
955 plugin = GNUNET_strdup(addr); 962 plugin = GNUNET_strdup (addr);
956 optionstr = strchr(plugin, '.'); 963 optionstr = strchr (plugin, '.');
957 if (NULL == optionstr) 964 if (NULL == optionstr)
958 { 965 {
959 GNUNET_break(0); 966 GNUNET_break (0);
960 GNUNET_free(plugin); 967 GNUNET_free (plugin);
961 return GNUNET_SYSERR; 968 return GNUNET_SYSERR;
962 } 969 }
963 optionstr[0] = '\0'; 970 optionstr[0] = '\0';
964 optionstr++; 971 optionstr++;
965 options = atol(optionstr); 972 options = atol (optionstr);
966 address = strchr(optionstr, '.'); 973 address = strchr (optionstr, '.');
967 if (NULL == address) 974 if (NULL == address)
968 { 975 {
969 GNUNET_break(0); 976 GNUNET_break (0);
970 GNUNET_free(plugin); 977 GNUNET_free (plugin);
971 return GNUNET_SYSERR; 978 return GNUNET_SYSERR;
972 } 979 }
973 address[0] = '\0'; 980 address[0] = '\0';
974 address++; 981 address++;
975 982
976 if (GNUNET_OK != 983 if (GNUNET_OK !=
977 GNUNET_STRINGS_to_address_ip(address, strlen(address), &socket_address)) 984 GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address))
978 { 985 {
979 GNUNET_break(0); 986 GNUNET_break (0);
980 GNUNET_free(plugin); 987 GNUNET_free (plugin);
981 return GNUNET_SYSERR; 988 return GNUNET_SYSERR;
982 } 989 }
983 GNUNET_free(plugin); 990 GNUNET_free (plugin);
984 991
985 switch (socket_address.ss_family) 992 switch (socket_address.ss_family)
986 { 993 {
987 case AF_INET: { 994 case AF_INET: {
988 struct IPv4UdpAddress *u4; 995 struct IPv4UdpAddress *u4;
989 const struct sockaddr_in *in4 = 996 const struct sockaddr_in *in4 =
990 (const struct sockaddr_in *)&socket_address; 997 (const struct sockaddr_in *) &socket_address;
991 998
992 u4 = GNUNET_new(struct IPv4UdpAddress); 999 u4 = GNUNET_new (struct IPv4UdpAddress);
993 u4->options = htonl(options); 1000 u4->options = htonl (options);
994 u4->ipv4_addr = in4->sin_addr.s_addr; 1001 u4->ipv4_addr = in4->sin_addr.s_addr;
995 u4->u4_port = in4->sin_port; 1002 u4->u4_port = in4->sin_port;
996 *buf = u4; 1003 *buf = u4;
@@ -998,13 +1005,13 @@ udp_string_to_address(void *cls,
998 return GNUNET_OK; 1005 return GNUNET_OK;
999 } 1006 }
1000 1007
1001 case AF_INET6: { 1008 case AF_INET6: {
1002 struct IPv6UdpAddress *u6; 1009 struct IPv6UdpAddress *u6;
1003 const struct sockaddr_in6 *in6 = 1010 const struct sockaddr_in6 *in6 =
1004 (const struct sockaddr_in6 *)&socket_address; 1011 (const struct sockaddr_in6 *) &socket_address;
1005 1012
1006 u6 = GNUNET_new(struct IPv6UdpAddress); 1013 u6 = GNUNET_new (struct IPv6UdpAddress);
1007 u6->options = htonl(options); 1014 u6->options = htonl (options);
1008 u6->ipv6_addr = in6->sin6_addr; 1015 u6->ipv6_addr = in6->sin6_addr;
1009 u6->u6_port = in6->sin6_port; 1016 u6->u6_port = in6->sin6_port;
1010 *buf = u6; 1017 *buf = u6;
@@ -1012,10 +1019,10 @@ udp_string_to_address(void *cls,
1012 return GNUNET_OK; 1019 return GNUNET_OK;
1013 } 1020 }
1014 1021
1015 default: 1022 default:
1016 GNUNET_break(0); 1023 GNUNET_break (0);
1017 return GNUNET_SYSERR; 1024 return GNUNET_SYSERR;
1018 } 1025 }
1019} 1026}
1020 1027
1021 1028
@@ -1026,39 +1033,39 @@ udp_string_to_address(void *cls,
1026 * @param hostname result from DNS resolver 1033 * @param hostname result from DNS resolver
1027 */ 1034 */
1028static void 1035static void
1029append_port(void *cls, const char *hostname) 1036append_port (void *cls, const char *hostname)
1030{ 1037{
1031 struct PrettyPrinterContext *ppc = cls; 1038 struct PrettyPrinterContext *ppc = cls;
1032 struct Plugin *plugin = ppc->plugin; 1039 struct Plugin *plugin = ppc->plugin;
1033 char *ret; 1040 char *ret;
1034 1041
1035 if (NULL == hostname) 1042 if (NULL == hostname)
1036 { 1043 {
1037 /* Final call, done */ 1044 /* Final call, done */
1038 GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head, 1045 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head,
1039 plugin->ppc_dll_tail, 1046 plugin->ppc_dll_tail,
1040 ppc); 1047 ppc);
1041 ppc->resolver_handle = NULL; 1048 ppc->resolver_handle = NULL;
1042 ppc->asc(ppc->asc_cls, NULL, GNUNET_OK); 1049 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK);
1043 GNUNET_free(ppc); 1050 GNUNET_free (ppc);
1044 return; 1051 return;
1045 } 1052 }
1046 if (GNUNET_YES == ppc->ipv6) 1053 if (GNUNET_YES == ppc->ipv6)
1047 GNUNET_asprintf(&ret, 1054 GNUNET_asprintf (&ret,
1048 "%s.%u.[%s]:%d", 1055 "%s.%u.[%s]:%d",
1049 PLUGIN_NAME, 1056 PLUGIN_NAME,
1050 ppc->options, 1057 ppc->options,
1051 hostname, 1058 hostname,
1052 ppc->port); 1059 ppc->port);
1053 else 1060 else
1054 GNUNET_asprintf(&ret, 1061 GNUNET_asprintf (&ret,
1055 "%s.%u.%s:%d", 1062 "%s.%u.%s:%d",
1056 PLUGIN_NAME, 1063 PLUGIN_NAME,
1057 ppc->options, 1064 ppc->options,
1058 hostname, 1065 hostname,
1059 ppc->port); 1066 ppc->port);
1060 ppc->asc(ppc->asc_cls, ret, GNUNET_OK); 1067 ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
1061 GNUNET_free(ret); 1068 GNUNET_free (ret);
1062} 1069}
1063 1070
1064 1071
@@ -1077,14 +1084,14 @@ append_port(void *cls, const char *hostname)
1077 * @param asc_cls closure for @a asc 1084 * @param asc_cls closure for @a asc
1078 */ 1085 */
1079static void 1086static void
1080udp_plugin_address_pretty_printer(void *cls, 1087udp_plugin_address_pretty_printer (void *cls,
1081 const char *type, 1088 const char *type,
1082 const void *addr, 1089 const void *addr,
1083 size_t addrlen, 1090 size_t addrlen,
1084 int numeric, 1091 int numeric,
1085 struct GNUNET_TIME_Relative timeout, 1092 struct GNUNET_TIME_Relative timeout,
1086 GNUNET_TRANSPORT_AddressStringCallback asc, 1093 GNUNET_TRANSPORT_AddressStringCallback asc,
1087 void *asc_cls) 1094 void *asc_cls)
1088{ 1095{
1089 struct Plugin *plugin = cls; 1096 struct Plugin *plugin = cls;
1090 struct PrettyPrinterContext *ppc; 1097 struct PrettyPrinterContext *ppc;
@@ -1098,44 +1105,44 @@ udp_plugin_address_pretty_printer(void *cls,
1098 uint32_t options; 1105 uint32_t options;
1099 1106
1100 if (addrlen == sizeof(struct IPv6UdpAddress)) 1107 if (addrlen == sizeof(struct IPv6UdpAddress))
1101 { 1108 {
1102 u6 = addr; 1109 u6 = addr;
1103 memset(&a6, 0, sizeof(a6)); 1110 memset (&a6, 0, sizeof(a6));
1104 a6.sin6_family = AF_INET6; 1111 a6.sin6_family = AF_INET6;
1105#if HAVE_SOCKADDR_IN_SIN_LEN 1112#if HAVE_SOCKADDR_IN_SIN_LEN
1106 a6.sin6_len = sizeof(a6); 1113 a6.sin6_len = sizeof(a6);
1107#endif 1114#endif
1108 a6.sin6_port = u6->u6_port; 1115 a6.sin6_port = u6->u6_port;
1109 a6.sin6_addr = u6->ipv6_addr; 1116 a6.sin6_addr = u6->ipv6_addr;
1110 port = ntohs(u6->u6_port); 1117 port = ntohs (u6->u6_port);
1111 options = ntohl(u6->options); 1118 options = ntohl (u6->options);
1112 sb = (const struct sockaddr *)&a6; 1119 sb = (const struct sockaddr *) &a6;
1113 sbs = sizeof(a6); 1120 sbs = sizeof(a6);
1114 } 1121 }
1115 else if (addrlen == sizeof(struct IPv4UdpAddress)) 1122 else if (addrlen == sizeof(struct IPv4UdpAddress))
1116 { 1123 {
1117 u4 = addr; 1124 u4 = addr;
1118 memset(&a4, 0, sizeof(a4)); 1125 memset (&a4, 0, sizeof(a4));
1119 a4.sin_family = AF_INET; 1126 a4.sin_family = AF_INET;
1120#if HAVE_SOCKADDR_IN_SIN_LEN 1127#if HAVE_SOCKADDR_IN_SIN_LEN
1121 a4.sin_len = sizeof(a4); 1128 a4.sin_len = sizeof(a4);
1122#endif 1129#endif
1123 a4.sin_port = u4->u4_port; 1130 a4.sin_port = u4->u4_port;
1124 a4.sin_addr.s_addr = u4->ipv4_addr; 1131 a4.sin_addr.s_addr = u4->ipv4_addr;
1125 port = ntohs(u4->u4_port); 1132 port = ntohs (u4->u4_port);
1126 options = ntohl(u4->options); 1133 options = ntohl (u4->options);
1127 sb = (const struct sockaddr *)&a4; 1134 sb = (const struct sockaddr *) &a4;
1128 sbs = sizeof(a4); 1135 sbs = sizeof(a4);
1129 } 1136 }
1130 else 1137 else
1131 { 1138 {
1132 /* invalid address */ 1139 /* invalid address */
1133 GNUNET_break_op(0); 1140 GNUNET_break_op (0);
1134 asc(asc_cls, NULL, GNUNET_SYSERR); 1141 asc (asc_cls, NULL, GNUNET_SYSERR);
1135 asc(asc_cls, NULL, GNUNET_OK); 1142 asc (asc_cls, NULL, GNUNET_OK);
1136 return; 1143 return;
1137 } 1144 }
1138 ppc = GNUNET_new(struct PrettyPrinterContext); 1145 ppc = GNUNET_new (struct PrettyPrinterContext);
1139 ppc->plugin = plugin; 1146 ppc->plugin = plugin;
1140 ppc->asc = asc; 1147 ppc->asc = asc;
1141 ppc->asc_cls = asc_cls; 1148 ppc->asc_cls = asc_cls;
@@ -1145,13 +1152,13 @@ udp_plugin_address_pretty_printer(void *cls,
1145 ppc->ipv6 = GNUNET_YES; 1152 ppc->ipv6 = GNUNET_YES;
1146 else 1153 else
1147 ppc->ipv6 = GNUNET_NO; 1154 ppc->ipv6 = GNUNET_NO;
1148 GNUNET_CONTAINER_DLL_insert(plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); 1155 GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc);
1149 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sb, 1156 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
1150 sbs, 1157 sbs,
1151 !numeric, 1158 ! numeric,
1152 timeout, 1159 timeout,
1153 &append_port, 1160 &append_port,
1154 ppc); 1161 ppc);
1155} 1162}
1156 1163
1157 1164
@@ -1165,7 +1172,7 @@ udp_plugin_address_pretty_printer(void *cls,
1165 * @return #GNUNET_OK if port is either our open or advertised port 1172 * @return #GNUNET_OK if port is either our open or advertised port
1166 */ 1173 */
1167static int 1174static int
1168check_port(const struct Plugin *plugin, uint16_t in_port) 1175check_port (const struct Plugin *plugin, uint16_t in_port)
1169{ 1176{
1170 if ((plugin->port == in_port) || (plugin->aport == in_port)) 1177 if ((plugin->port == in_port) || (plugin->aport == in_port))
1171 return GNUNET_OK; 1178 return GNUNET_OK;
@@ -1189,56 +1196,56 @@ check_port(const struct Plugin *plugin, uint16_t in_port)
1189 * and transport, #GNUNET_SYSERR if not 1196 * and transport, #GNUNET_SYSERR if not
1190 */ 1197 */
1191static int 1198static int
1192udp_plugin_check_address(void *cls, const void *addr, size_t addrlen) 1199udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1193{ 1200{
1194 struct Plugin *plugin = cls; 1201 struct Plugin *plugin = cls;
1195 const struct IPv4UdpAddress *v4; 1202 const struct IPv4UdpAddress *v4;
1196 const struct IPv6UdpAddress *v6; 1203 const struct IPv6UdpAddress *v6;
1197 1204
1198 if (sizeof(struct IPv4UdpAddress) == addrlen) 1205 if (sizeof(struct IPv4UdpAddress) == addrlen)
1199 { 1206 {
1200 struct sockaddr_in s4; 1207 struct sockaddr_in s4;
1201 1208
1202 v4 = (const struct IPv4UdpAddress *)addr; 1209 v4 = (const struct IPv4UdpAddress *) addr;
1203 if (GNUNET_OK != check_port(plugin, ntohs(v4->u4_port))) 1210 if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port)))
1204 return GNUNET_SYSERR; 1211 return GNUNET_SYSERR;
1205 memset(&s4, 0, sizeof(s4)); 1212 memset (&s4, 0, sizeof(s4));
1206 s4.sin_family = AF_INET; 1213 s4.sin_family = AF_INET;
1207#if HAVE_SOCKADDR_IN_SIN_LEN 1214#if HAVE_SOCKADDR_IN_SIN_LEN
1208 s4.sin_len = sizeof(s4); 1215 s4.sin_len = sizeof(s4);
1209#endif 1216#endif
1210 s4.sin_port = v4->u4_port; 1217 s4.sin_port = v4->u4_port;
1211 s4.sin_addr.s_addr = v4->ipv4_addr; 1218 s4.sin_addr.s_addr = v4->ipv4_addr;
1212 1219
1213 if (GNUNET_OK != 1220 if (GNUNET_OK !=
1214 GNUNET_NAT_test_address(plugin->nat, &s4, sizeof(struct sockaddr_in))) 1221 GNUNET_NAT_test_address (plugin->nat, &s4, sizeof(struct sockaddr_in)))
1215 return GNUNET_SYSERR; 1222 return GNUNET_SYSERR;
1216 } 1223 }
1217 else if (sizeof(struct IPv6UdpAddress) == addrlen) 1224 else if (sizeof(struct IPv6UdpAddress) == addrlen)
1218 { 1225 {
1219 struct sockaddr_in6 s6; 1226 struct sockaddr_in6 s6;
1220 1227
1221 v6 = (const struct IPv6UdpAddress *)addr; 1228 v6 = (const struct IPv6UdpAddress *) addr;
1222 if (IN6_IS_ADDR_LINKLOCAL(&v6->ipv6_addr)) 1229 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1223 return GNUNET_OK; /* plausible, if unlikely... */ 1230 return GNUNET_OK; /* plausible, if unlikely... */
1224 memset(&s6, 0, sizeof(s6)); 1231 memset (&s6, 0, sizeof(s6));
1225 s6.sin6_family = AF_INET6; 1232 s6.sin6_family = AF_INET6;
1226#if HAVE_SOCKADDR_IN_SIN_LEN 1233#if HAVE_SOCKADDR_IN_SIN_LEN
1227 s6.sin6_len = sizeof(s6); 1234 s6.sin6_len = sizeof(s6);
1228#endif 1235#endif
1229 s6.sin6_port = v6->u6_port; 1236 s6.sin6_port = v6->u6_port;
1230 s6.sin6_addr = v6->ipv6_addr; 1237 s6.sin6_addr = v6->ipv6_addr;
1231 1238
1232 if (GNUNET_OK != GNUNET_NAT_test_address(plugin->nat, 1239 if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat,
1233 &s6, 1240 &s6,
1234 sizeof(struct sockaddr_in6))) 1241 sizeof(struct sockaddr_in6)))
1235 return GNUNET_SYSERR;
1236 }
1237 else
1238 {
1239 GNUNET_break_op(0);
1240 return GNUNET_SYSERR; 1242 return GNUNET_SYSERR;
1241 } 1243 }
1244 else
1245 {
1246 GNUNET_break_op (0);
1247 return GNUNET_SYSERR;
1248 }
1242 return GNUNET_OK; 1249 return GNUNET_OK;
1243} 1250}
1244 1251
@@ -1256,12 +1263,12 @@ udp_plugin_check_address(void *cls, const void *addr, size_t addrlen)
1256 * @param addrlen actual length of the @a addr 1263 * @param addrlen actual length of the @a addr
1257 */ 1264 */
1258static void 1265static void
1259udp_nat_port_map_callback(void *cls, 1266udp_nat_port_map_callback (void *cls,
1260 void **app_ctx, 1267 void **app_ctx,
1261 int add_remove, 1268 int add_remove,
1262 enum GNUNET_NAT_AddressClass ac, 1269 enum GNUNET_NAT_AddressClass ac,
1263 const struct sockaddr *addr, 1270 const struct sockaddr *addr,
1264 socklen_t addrlen) 1271 socklen_t addrlen)
1265{ 1272{
1266 struct Plugin *plugin = cls; 1273 struct Plugin *plugin = cls;
1267 struct GNUNET_HELLO_Address *address; 1274 struct GNUNET_HELLO_Address *address;
@@ -1270,23 +1277,23 @@ udp_nat_port_map_callback(void *cls,
1270 void *arg; 1277 void *arg;
1271 size_t args; 1278 size_t args;
1272 1279
1273 (void)app_ctx; 1280 (void) app_ctx;
1274 LOG(GNUNET_ERROR_TYPE_DEBUG, 1281 LOG (GNUNET_ERROR_TYPE_DEBUG,
1275 (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n" 1282 (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n"
1276 : "NAT notification to remove address `%s'\n", 1283 : "NAT notification to remove address `%s'\n",
1277 GNUNET_a2s(addr, addrlen)); 1284 GNUNET_a2s (addr, addrlen));
1278 /* convert 'address' to our internal format */ 1285 /* convert 'address' to our internal format */
1279 switch (addr->sa_family) 1286 switch (addr->sa_family)
1280 { 1287 {
1281 case AF_INET: { 1288 case AF_INET: {
1282 const struct sockaddr_in *i4; 1289 const struct sockaddr_in *i4;
1283 1290
1284 GNUNET_assert(sizeof(struct sockaddr_in) == addrlen); 1291 GNUNET_assert (sizeof(struct sockaddr_in) == addrlen);
1285 i4 = (const struct sockaddr_in *)addr; 1292 i4 = (const struct sockaddr_in *) addr;
1286 if (0 == ntohs(i4->sin_port)) 1293 if (0 == ntohs (i4->sin_port))
1287 return; /* Port = 0 means unmapped, ignore these for UDP. */ 1294 return; /* Port = 0 means unmapped, ignore these for UDP. */
1288 memset(&u4, 0, sizeof(u4)); 1295 memset (&u4, 0, sizeof(u4));
1289 u4.options = htonl(plugin->myoptions); 1296 u4.options = htonl (plugin->myoptions);
1290 u4.ipv4_addr = i4->sin_addr.s_addr; 1297 u4.ipv4_addr = i4->sin_addr.s_addr;
1291 u4.u4_port = i4->sin_port; 1298 u4.u4_port = i4->sin_port;
1292 arg = &u4; 1299 arg = &u4;
@@ -1294,15 +1301,15 @@ udp_nat_port_map_callback(void *cls,
1294 break; 1301 break;
1295 } 1302 }
1296 1303
1297 case AF_INET6: { 1304 case AF_INET6: {
1298 const struct sockaddr_in6 *i6; 1305 const struct sockaddr_in6 *i6;
1299 1306
1300 GNUNET_assert(sizeof(struct sockaddr_in6) == addrlen); 1307 GNUNET_assert (sizeof(struct sockaddr_in6) == addrlen);
1301 i6 = (const struct sockaddr_in6 *)addr; 1308 i6 = (const struct sockaddr_in6 *) addr;
1302 if (0 == ntohs(i6->sin6_port)) 1309 if (0 == ntohs (i6->sin6_port))
1303 return; /* Port = 0 means unmapped, ignore these for UDP. */ 1310 return; /* Port = 0 means unmapped, ignore these for UDP. */
1304 memset(&u6, 0, sizeof(u6)); 1311 memset (&u6, 0, sizeof(u6));
1305 u6.options = htonl(plugin->myoptions); 1312 u6.options = htonl (plugin->myoptions);
1306 u6.ipv6_addr = i6->sin6_addr; 1313 u6.ipv6_addr = i6->sin6_addr;
1307 u6.u6_port = i6->sin6_port; 1314 u6.u6_port = i6->sin6_port;
1308 arg = &u6; 1315 arg = &u6;
@@ -1310,19 +1317,19 @@ udp_nat_port_map_callback(void *cls,
1310 break; 1317 break;
1311 } 1318 }
1312 1319
1313 default: 1320 default:
1314 GNUNET_break(0); 1321 GNUNET_break (0);
1315 return; 1322 return;
1316 } 1323 }
1317 /* modify our published address list */ 1324 /* modify our published address list */
1318 /* TODO: use 'ac' here in the future... */ 1325 /* TODO: use 'ac' here in the future... */
1319 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 1326 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1320 PLUGIN_NAME, 1327 PLUGIN_NAME,
1321 arg, 1328 arg,
1322 args, 1329 args,
1323 GNUNET_HELLO_ADDRESS_INFO_NONE); 1330 GNUNET_HELLO_ADDRESS_INFO_NONE);
1324 plugin->env->notify_address(plugin->env->cls, add_remove, address); 1331 plugin->env->notify_address (plugin->env->cls, add_remove, address);
1325 GNUNET_HELLO_address_free(address); 1332 GNUNET_HELLO_address_free (address);
1326} 1333}
1327 1334
1328 1335
@@ -1332,7 +1339,8 @@ udp_nat_port_map_callback(void *cls,
1332/** 1339/**
1333 * Closure for #session_cmp_it(). 1340 * Closure for #session_cmp_it().
1334 */ 1341 */
1335struct GNUNET_ATS_SessionCompareContext { 1342struct GNUNET_ATS_SessionCompareContext
1343{
1336 /** 1344 /**
1337 * Set to session matching the address. 1345 * Set to session matching the address.
1338 */ 1346 */
@@ -1354,17 +1362,17 @@ struct GNUNET_ATS_SessionCompareContext {
1354 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not 1362 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not
1355 */ 1363 */
1356static int 1364static int
1357session_cmp_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 1365session_cmp_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1358{ 1366{
1359 struct GNUNET_ATS_SessionCompareContext *cctx = cls; 1367 struct GNUNET_ATS_SessionCompareContext *cctx = cls;
1360 struct GNUNET_ATS_Session *s = value; 1368 struct GNUNET_ATS_Session *s = value;
1361 1369
1362 if (0 == GNUNET_HELLO_address_cmp(s->address, cctx->address)) 1370 if (0 == GNUNET_HELLO_address_cmp (s->address, cctx->address))
1363 { 1371 {
1364 GNUNET_assert(GNUNET_NO == s->in_destroy); 1372 GNUNET_assert (GNUNET_NO == s->in_destroy);
1365 cctx->res = s; 1373 cctx->res = s;
1366 return GNUNET_NO; 1374 return GNUNET_NO;
1367 } 1375 }
1368 return GNUNET_OK; 1376 return GNUNET_OK;
1369} 1377}
1370 1378
@@ -1379,8 +1387,8 @@ session_cmp_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1379 * @return the session if it exists, or NULL if it is not found 1387 * @return the session if it exists, or NULL if it is not found
1380 */ 1388 */
1381static struct GNUNET_ATS_Session * 1389static struct GNUNET_ATS_Session *
1382udp_plugin_lookup_session(void *cls, 1390udp_plugin_lookup_session (void *cls,
1383 const struct GNUNET_HELLO_Address *address) 1391 const struct GNUNET_HELLO_Address *address)
1384{ 1392{
1385 struct Plugin *plugin = cls; 1393 struct Plugin *plugin = cls;
1386 const struct IPv6UdpAddress *udp_a6; 1394 const struct IPv6UdpAddress *udp_a6;
@@ -1388,54 +1396,54 @@ udp_plugin_lookup_session(void *cls,
1388 struct GNUNET_ATS_SessionCompareContext cctx; 1396 struct GNUNET_ATS_SessionCompareContext cctx;
1389 1397
1390 if (NULL == address->address) 1398 if (NULL == address->address)
1391 { 1399 {
1392 GNUNET_break(0); 1400 GNUNET_break (0);
1393 return NULL; 1401 return NULL;
1394 } 1402 }
1395 if (sizeof(struct IPv4UdpAddress) == address->address_length) 1403 if (sizeof(struct IPv4UdpAddress) == address->address_length)
1404 {
1405 if (NULL == plugin->sockv4)
1406 return NULL;
1407 udp_a4 = (const struct IPv4UdpAddress *) address->address;
1408 if (0 == udp_a4->u4_port)
1396 { 1409 {
1397 if (NULL == plugin->sockv4) 1410 GNUNET_break (0);
1398 return NULL; 1411 return NULL;
1399 udp_a4 = (const struct IPv4UdpAddress *)address->address;
1400 if (0 == udp_a4->u4_port)
1401 {
1402 GNUNET_break(0);
1403 return NULL;
1404 }
1405 } 1412 }
1413 }
1406 else if (sizeof(struct IPv6UdpAddress) == address->address_length) 1414 else if (sizeof(struct IPv6UdpAddress) == address->address_length)
1415 {
1416 if (NULL == plugin->sockv6)
1417 return NULL;
1418 udp_a6 = (const struct IPv6UdpAddress *) address->address;
1419 if (0 == udp_a6->u6_port)
1407 { 1420 {
1408 if (NULL == plugin->sockv6) 1421 GNUNET_break (0);
1409 return NULL;
1410 udp_a6 = (const struct IPv6UdpAddress *)address->address;
1411 if (0 == udp_a6->u6_port)
1412 {
1413 GNUNET_break(0);
1414 return NULL;
1415 }
1416 }
1417 else
1418 {
1419 GNUNET_break(0);
1420 return NULL; 1422 return NULL;
1421 } 1423 }
1424 }
1425 else
1426 {
1427 GNUNET_break (0);
1428 return NULL;
1429 }
1422 1430
1423 /* check if session already exists */ 1431 /* check if session already exists */
1424 cctx.address = address; 1432 cctx.address = address;
1425 cctx.res = NULL; 1433 cctx.res = NULL;
1426 LOG(GNUNET_ERROR_TYPE_DEBUG, 1434 LOG (GNUNET_ERROR_TYPE_DEBUG,
1427 "Looking for existing session for peer `%s' with address `%s'\n", 1435 "Looking for existing session for peer `%s' with address `%s'\n",
1428 GNUNET_i2s(&address->peer), 1436 GNUNET_i2s (&address->peer),
1429 udp_address_to_string(plugin, 1437 udp_address_to_string (plugin,
1430 address->address, 1438 address->address,
1431 address->address_length)); 1439 address->address_length));
1432 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, 1440 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions,
1433 &address->peer, 1441 &address->peer,
1434 &session_cmp_it, 1442 &session_cmp_it,
1435 &cctx); 1443 &cctx);
1436 if (NULL == cctx.res) 1444 if (NULL == cctx.res)
1437 return NULL; 1445 return NULL;
1438 LOG(GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); 1446 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res);
1439 return cctx.res; 1447 return cctx.res;
1440} 1448}
1441 1449
@@ -1449,12 +1457,12 @@ udp_plugin_lookup_session(void *cls,
1449 * @param s session to reschedule timeout activity for 1457 * @param s session to reschedule timeout activity for
1450 */ 1458 */
1451static void 1459static void
1452reschedule_session_timeout(struct GNUNET_ATS_Session *s) 1460reschedule_session_timeout (struct GNUNET_ATS_Session *s)
1453{ 1461{
1454 if (GNUNET_YES == s->in_destroy) 1462 if (GNUNET_YES == s->in_destroy)
1455 return; 1463 return;
1456 GNUNET_assert(NULL != s->timeout_task); 1464 GNUNET_assert (NULL != s->timeout_task);
1457 s->timeout = GNUNET_TIME_relative_to_absolute(UDP_SESSION_TIME_OUT); 1465 s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT);
1458} 1466}
1459 1467
1460 1468
@@ -1468,22 +1476,22 @@ reschedule_session_timeout(struct GNUNET_ATS_Session *s)
1468 * @param session which session is being updated 1476 * @param session which session is being updated
1469 */ 1477 */
1470static void 1478static void
1471udp_plugin_update_session_timeout(void *cls, 1479udp_plugin_update_session_timeout (void *cls,
1472 const struct GNUNET_PeerIdentity *peer, 1480 const struct GNUNET_PeerIdentity *peer,
1473 struct GNUNET_ATS_Session *session) 1481 struct GNUNET_ATS_Session *session)
1474{ 1482{
1475 struct Plugin *plugin = cls; 1483 struct Plugin *plugin = cls;
1476 1484
1477 if (GNUNET_YES != 1485 if (GNUNET_YES !=
1478 GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions, 1486 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions,
1479 peer, 1487 peer,
1480 session)) 1488 session))
1481 { 1489 {
1482 GNUNET_break(0); 1490 GNUNET_break (0);
1483 return; 1491 return;
1484 } 1492 }
1485 /* Reschedule session timeout */ 1493 /* Reschedule session timeout */
1486 reschedule_session_timeout(session); 1494 reschedule_session_timeout (session);
1487} 1495}
1488 1496
1489 1497
@@ -1498,47 +1506,47 @@ udp_plugin_update_session_timeout(void *cls,
1498 * @param udpw message wrapper to dequeue 1506 * @param udpw message wrapper to dequeue
1499 */ 1507 */
1500static void 1508static void
1501dequeue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw) 1509dequeue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1502{ 1510{
1503 struct GNUNET_ATS_Session *session = udpw->session; 1511 struct GNUNET_ATS_Session *session = udpw->session;
1504 1512
1505 if (plugin->bytes_in_buffer < udpw->msg_size) 1513 if (plugin->bytes_in_buffer < udpw->msg_size)
1506 { 1514 {
1507 GNUNET_break(0); 1515 GNUNET_break (0);
1508 } 1516 }
1509 else 1517 else
1510 { 1518 {
1511 GNUNET_STATISTICS_update(plugin->env->stats, 1519 GNUNET_STATISTICS_update (plugin->env->stats,
1512 "# UDP, total bytes in send buffers", 1520 "# UDP, total bytes in send buffers",
1513 -(long long)udpw->msg_size, 1521 -(long long) udpw->msg_size,
1514 GNUNET_NO); 1522 GNUNET_NO);
1515 plugin->bytes_in_buffer -= udpw->msg_size; 1523 plugin->bytes_in_buffer -= udpw->msg_size;
1516 } 1524 }
1517 GNUNET_STATISTICS_update(plugin->env->stats, 1525 GNUNET_STATISTICS_update (plugin->env->stats,
1518 "# UDP, total messages in send buffers", 1526 "# UDP, total messages in send buffers",
1519 -1, 1527 -1,
1520 GNUNET_NO); 1528 GNUNET_NO);
1521 if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length) 1529 if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length)
1522 { 1530 {
1523 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, 1531 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head,
1524 plugin->ipv4_queue_tail, 1532 plugin->ipv4_queue_tail,
1525 udpw); 1533 udpw);
1526 } 1534 }
1527 else if (sizeof(struct IPv6UdpAddress) == 1535 else if (sizeof(struct IPv6UdpAddress) ==
1528 udpw->session->address->address_length) 1536 udpw->session->address->address_length)
1529 { 1537 {
1530 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, 1538 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head,
1531 plugin->ipv6_queue_tail, 1539 plugin->ipv6_queue_tail,
1532 udpw); 1540 udpw);
1533 } 1541 }
1534 else 1542 else
1535 { 1543 {
1536 GNUNET_break(0); 1544 GNUNET_break (0);
1537 return; 1545 return;
1538 } 1546 }
1539 GNUNET_assert(session->msgs_in_queue > 0); 1547 GNUNET_assert (session->msgs_in_queue > 0);
1540 session->msgs_in_queue--; 1548 session->msgs_in_queue--;
1541 GNUNET_assert(session->bytes_in_queue >= udpw->msg_size); 1549 GNUNET_assert (session->bytes_in_queue >= udpw->msg_size);
1542 session->bytes_in_queue -= udpw->msg_size; 1550 session->bytes_in_queue -= udpw->msg_size;
1543} 1551}
1544 1552
@@ -1550,56 +1558,56 @@ dequeue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1550 * @param udpw message wrapper to queue 1558 * @param udpw message wrapper to queue
1551 */ 1559 */
1552static void 1560static void
1553enqueue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw) 1561enqueue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1554{ 1562{
1555 struct GNUNET_ATS_Session *session = udpw->session; 1563 struct GNUNET_ATS_Session *session = udpw->session;
1556 1564
1557 if (GNUNET_YES == session->in_destroy) 1565 if (GNUNET_YES == session->in_destroy)
1558 { 1566 {
1559 GNUNET_break(0); 1567 GNUNET_break (0);
1560 GNUNET_free(udpw); 1568 GNUNET_free (udpw);
1561 return; 1569 return;
1562 } 1570 }
1563 if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size) 1571 if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size)
1564 { 1572 {
1565 GNUNET_break(0); 1573 GNUNET_break (0);
1566 } 1574 }
1567 else 1575 else
1568 { 1576 {
1569 GNUNET_STATISTICS_update(plugin->env->stats, 1577 GNUNET_STATISTICS_update (plugin->env->stats,
1570 "# UDP, total bytes in send buffers", 1578 "# UDP, total bytes in send buffers",
1571 udpw->msg_size, 1579 udpw->msg_size,
1572 GNUNET_NO); 1580 GNUNET_NO);
1573 plugin->bytes_in_buffer += udpw->msg_size; 1581 plugin->bytes_in_buffer += udpw->msg_size;
1574 } 1582 }
1575 GNUNET_STATISTICS_update(plugin->env->stats, 1583 GNUNET_STATISTICS_update (plugin->env->stats,
1576 "# UDP, total messages in send buffers", 1584 "# UDP, total messages in send buffers",
1577 1, 1585 1,
1578 GNUNET_NO); 1586 GNUNET_NO);
1579 if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length) 1587 if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length)
1580 { 1588 {
1581 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, 1589 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head,
1582 plugin->ipv4_queue_tail, 1590 plugin->ipv4_queue_tail,
1583 udpw); 1591 udpw);
1584 } 1592 }
1585 else if (sizeof(struct IPv6UdpAddress) == 1593 else if (sizeof(struct IPv6UdpAddress) ==
1586 udpw->session->address->address_length) 1594 udpw->session->address->address_length)
1587 { 1595 {
1588 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head, 1596 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head,
1589 plugin->ipv6_queue_tail, 1597 plugin->ipv6_queue_tail,
1590 udpw); 1598 udpw);
1591 } 1599 }
1592 else 1600 else
1593 { 1601 {
1594 GNUNET_break(0); 1602 GNUNET_break (0);
1595 udpw->cont(udpw->cont_cls, 1603 udpw->cont (udpw->cont_cls,
1596 &session->target, 1604 &session->target,
1597 GNUNET_SYSERR, 1605 GNUNET_SYSERR,
1598 udpw->msg_size, 1606 udpw->msg_size,
1599 0); 1607 0);
1600 GNUNET_free(udpw); 1608 GNUNET_free (udpw);
1601 return; 1609 return;
1602 } 1610 }
1603 session->msgs_in_queue++; 1611 session->msgs_in_queue++;
1604 session->bytes_in_queue += udpw->msg_size; 1612 session->bytes_in_queue += udpw->msg_size;
1605} 1613}
@@ -1616,7 +1624,7 @@ enqueue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1616 * #GNUNET_SYSERR if the transmission failed 1624 * #GNUNET_SYSERR if the transmission failed
1617 */ 1625 */
1618static void 1626static void
1619fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result) 1627fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result)
1620{ 1628{
1621 struct Plugin *plugin = frag_ctx->plugin; 1629 struct Plugin *plugin = frag_ctx->plugin;
1622 struct GNUNET_ATS_Session *s = frag_ctx->session; 1630 struct GNUNET_ATS_Session *s = frag_ctx->session;
@@ -1625,122 +1633,122 @@ fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result)
1625 size_t overhead; 1633 size_t overhead;
1626 struct GNUNET_TIME_Relative delay; 1634 struct GNUNET_TIME_Relative delay;
1627 1635
1628 LOG(GNUNET_ERROR_TYPE_DEBUG, 1636 LOG (GNUNET_ERROR_TYPE_DEBUG,
1629 "%p: Fragmented message removed with result %s\n", 1637 "%p: Fragmented message removed with result %s\n",
1630 frag_ctx, 1638 frag_ctx,
1631 (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); 1639 (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS");
1632 /* Call continuation for fragmented message */ 1640 /* Call continuation for fragmented message */
1633 if (frag_ctx->on_wire_size >= frag_ctx->payload_size) 1641 if (frag_ctx->on_wire_size >= frag_ctx->payload_size)
1634 overhead = frag_ctx->on_wire_size - frag_ctx->payload_size; 1642 overhead = frag_ctx->on_wire_size - frag_ctx->payload_size;
1635 else 1643 else
1636 overhead = frag_ctx->on_wire_size; 1644 overhead = frag_ctx->on_wire_size;
1637 delay = GNUNET_TIME_absolute_get_duration(frag_ctx->start_time); 1645 delay = GNUNET_TIME_absolute_get_duration (frag_ctx->start_time);
1638 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 1646 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
1639 { 1647 {
1640 LOG(GNUNET_ERROR_TYPE_WARNING, 1648 LOG (GNUNET_ERROR_TYPE_WARNING,
1641 "Fragmented message acknowledged after %s (expected at %s)\n", 1649 "Fragmented message acknowledged after %s (expected at %s)\n",
1642 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), 1650 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
1643 GNUNET_STRINGS_absolute_time_to_string(frag_ctx->next_frag_time)); 1651 GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time));
1644 } 1652 }
1645 else 1653 else
1646 { 1654 {
1647 LOG(GNUNET_ERROR_TYPE_DEBUG, 1655 LOG (GNUNET_ERROR_TYPE_DEBUG,
1648 "Fragmented message acknowledged after %s (expected at %s)\n", 1656 "Fragmented message acknowledged after %s (expected at %s)\n",
1649 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), 1657 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
1650 GNUNET_STRINGS_absolute_time_to_string(frag_ctx->next_frag_time)); 1658 GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time));
1651 } 1659 }
1652 1660
1653 if (NULL != frag_ctx->cont) 1661 if (NULL != frag_ctx->cont)
1654 frag_ctx->cont(frag_ctx->cont_cls, 1662 frag_ctx->cont (frag_ctx->cont_cls,
1655 &s->target, 1663 &s->target,
1656 result, 1664 result,
1657 s->frag_ctx->payload_size, 1665 s->frag_ctx->payload_size,
1658 frag_ctx->on_wire_size); 1666 frag_ctx->on_wire_size);
1659 GNUNET_STATISTICS_update(plugin->env->stats, 1667 GNUNET_STATISTICS_update (plugin->env->stats,
1660 "# UDP, fragmented messages active", 1668 "# UDP, fragmented messages active",
1661 -1, 1669 -1,
1662 GNUNET_NO); 1670 GNUNET_NO);
1663 1671
1664 if (GNUNET_OK == result) 1672 if (GNUNET_OK == result)
1665 { 1673 {
1666 GNUNET_STATISTICS_update(plugin->env->stats, 1674 GNUNET_STATISTICS_update (plugin->env->stats,
1667 "# UDP, fragmented msgs, messages, sent, success", 1675 "# UDP, fragmented msgs, messages, sent, success",
1668 1, 1676 1,
1669 GNUNET_NO); 1677 GNUNET_NO);
1670 GNUNET_STATISTICS_update(plugin->env->stats, 1678 GNUNET_STATISTICS_update (plugin->env->stats,
1671 "# UDP, fragmented msgs, bytes payload, sent, success", 1679 "# UDP, fragmented msgs, bytes payload, sent, success",
1672 s->frag_ctx->payload_size, 1680 s->frag_ctx->payload_size,
1673 GNUNET_NO); 1681 GNUNET_NO);
1674 GNUNET_STATISTICS_update( 1682 GNUNET_STATISTICS_update (
1675 plugin->env->stats, 1683 plugin->env->stats,
1676 "# UDP, fragmented msgs, bytes overhead, sent, success", 1684 "# UDP, fragmented msgs, bytes overhead, sent, success",
1677 overhead, 1685 overhead,
1678 GNUNET_NO); 1686 GNUNET_NO);
1679 GNUNET_STATISTICS_update(plugin->env->stats, 1687 GNUNET_STATISTICS_update (plugin->env->stats,
1680 "# UDP, total, bytes overhead, sent", 1688 "# UDP, total, bytes overhead, sent",
1681 overhead, 1689 overhead,
1682 GNUNET_NO); 1690 GNUNET_NO);
1683 GNUNET_STATISTICS_update(plugin->env->stats, 1691 GNUNET_STATISTICS_update (plugin->env->stats,
1684 "# UDP, total, bytes payload, sent", 1692 "# UDP, total, bytes payload, sent",
1685 s->frag_ctx->payload_size, 1693 s->frag_ctx->payload_size,
1686 GNUNET_NO); 1694 GNUNET_NO);
1687 } 1695 }
1688 else 1696 else
1689 { 1697 {
1690 GNUNET_STATISTICS_update(plugin->env->stats, 1698 GNUNET_STATISTICS_update (plugin->env->stats,
1691 "# UDP, fragmented msgs, messages, sent, failure", 1699 "# UDP, fragmented msgs, messages, sent, failure",
1692 1, 1700 1,
1693 GNUNET_NO); 1701 GNUNET_NO);
1694 GNUNET_STATISTICS_update(plugin->env->stats, 1702 GNUNET_STATISTICS_update (plugin->env->stats,
1695 "# UDP, fragmented msgs, bytes payload, sent, failure", 1703 "# UDP, fragmented msgs, bytes payload, sent, failure",
1696 s->frag_ctx->payload_size, 1704 s->frag_ctx->payload_size,
1697 GNUNET_NO); 1705 GNUNET_NO);
1698 GNUNET_STATISTICS_update(plugin->env->stats, 1706 GNUNET_STATISTICS_update (plugin->env->stats,
1699 "# UDP, fragmented msgs, bytes payload, sent, failure", 1707 "# UDP, fragmented msgs, bytes payload, sent, failure",
1700 overhead, 1708 overhead,
1701 GNUNET_NO); 1709 GNUNET_NO);
1702 GNUNET_STATISTICS_update(plugin->env->stats, 1710 GNUNET_STATISTICS_update (plugin->env->stats,
1703 "# UDP, fragmented msgs, bytes payload, sent, failure", 1711 "# UDP, fragmented msgs, bytes payload, sent, failure",
1704 overhead, 1712 overhead,
1705 GNUNET_NO); 1713 GNUNET_NO);
1706 } 1714 }
1707 1715
1708 /* Remove remaining fragments from queue, no need to transmit those 1716 /* Remove remaining fragments from queue, no need to transmit those
1709 any longer. */ 1717 any longer. */
1710 if (s->address->address_length == sizeof(struct IPv6UdpAddress)) 1718 if (s->address->address_length == sizeof(struct IPv6UdpAddress))
1711 { 1719 {
1712 udpw = plugin->ipv6_queue_head; 1720 udpw = plugin->ipv6_queue_head;
1713 while (NULL != udpw) 1721 while (NULL != udpw)
1714 { 1722 {
1715 tmp = udpw->next; 1723 tmp = udpw->next;
1716 if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx)) 1724 if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx))
1717 { 1725 {
1718 dequeue(plugin, udpw); 1726 dequeue (plugin, udpw);
1719 GNUNET_free(udpw); 1727 GNUNET_free (udpw);
1720 } 1728 }
1721 udpw = tmp; 1729 udpw = tmp;
1722 } 1730 }
1723 } 1731 }
1724 if (s->address->address_length == sizeof(struct IPv4UdpAddress)) 1732 if (s->address->address_length == sizeof(struct IPv4UdpAddress))
1725 { 1733 {
1726 udpw = plugin->ipv4_queue_head; 1734 udpw = plugin->ipv4_queue_head;
1727 while (NULL != udpw) 1735 while (NULL != udpw)
1728 { 1736 {
1729 tmp = udpw->next; 1737 tmp = udpw->next;
1730 if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx)) 1738 if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx))
1731 { 1739 {
1732 dequeue(plugin, udpw); 1740 dequeue (plugin, udpw);
1733 GNUNET_free(udpw); 1741 GNUNET_free (udpw);
1734 } 1742 }
1735 udpw = tmp; 1743 udpw = tmp;
1736 } 1744 }
1737 } 1745 }
1738 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 1746 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
1739 GNUNET_FRAGMENT_context_destroy(frag_ctx->frag, 1747 GNUNET_FRAGMENT_context_destroy (frag_ctx->frag,
1740 &s->last_expected_msg_delay, 1748 &s->last_expected_msg_delay,
1741 &s->last_expected_ack_delay); 1749 &s->last_expected_ack_delay);
1742 s->frag_ctx = NULL; 1750 s->frag_ctx = NULL;
1743 GNUNET_free(frag_ctx); 1751 GNUNET_free (frag_ctx);
1744} 1752}
1745 1753
1746 1754
@@ -1753,45 +1761,45 @@ fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result)
1753 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure 1761 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure
1754 */ 1762 */
1755static void 1763static void
1756qc_fragment_sent(void *cls, struct UDP_MessageWrapper *udpw, int result) 1764qc_fragment_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
1757{ 1765{
1758 struct Plugin *plugin = cls; 1766 struct Plugin *plugin = cls;
1759 1767
1760 GNUNET_assert(NULL != udpw->frag_ctx); 1768 GNUNET_assert (NULL != udpw->frag_ctx);
1761 if (GNUNET_OK == result) 1769 if (GNUNET_OK == result)
1762 { 1770 {
1763 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1764 "Fragment of message with %u bytes transmitted to %s\n", 1772 "Fragment of message with %u bytes transmitted to %s\n",
1765 (unsigned int)udpw->payload_size, 1773 (unsigned int) udpw->payload_size,
1766 GNUNET_i2s(&udpw->session->target)); 1774 GNUNET_i2s (&udpw->session->target));
1767 GNUNET_FRAGMENT_context_transmission_done(udpw->frag_ctx->frag); 1775 GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag);
1768 GNUNET_STATISTICS_update(plugin->env->stats, 1776 GNUNET_STATISTICS_update (plugin->env->stats,
1769 "# UDP, fragmented msgs, fragments, sent, success", 1777 "# UDP, fragmented msgs, fragments, sent, success",
1770 1, 1778 1,
1771 GNUNET_NO); 1779 GNUNET_NO);
1772 GNUNET_STATISTICS_update( 1780 GNUNET_STATISTICS_update (
1773 plugin->env->stats, 1781 plugin->env->stats,
1774 "# UDP, fragmented msgs, fragments bytes, sent, success", 1782 "# UDP, fragmented msgs, fragments bytes, sent, success",
1775 udpw->msg_size, 1783 udpw->msg_size,
1776 GNUNET_NO); 1784 GNUNET_NO);
1777 } 1785 }
1778 else 1786 else
1779 { 1787 {
1780 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1781 "Failed to transmit fragment of message with %u bytes to %s\n", 1789 "Failed to transmit fragment of message with %u bytes to %s\n",
1782 (unsigned int)udpw->payload_size, 1790 (unsigned int) udpw->payload_size,
1783 GNUNET_i2s(&udpw->session->target)); 1791 GNUNET_i2s (&udpw->session->target));
1784 fragmented_message_done(udpw->frag_ctx, GNUNET_SYSERR); 1792 fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR);
1785 GNUNET_STATISTICS_update(plugin->env->stats, 1793 GNUNET_STATISTICS_update (plugin->env->stats,
1786 "# UDP, fragmented msgs, fragments, sent, failure", 1794 "# UDP, fragmented msgs, fragments, sent, failure",
1787 1, 1795 1,
1788 GNUNET_NO); 1796 GNUNET_NO);
1789 GNUNET_STATISTICS_update( 1797 GNUNET_STATISTICS_update (
1790 plugin->env->stats, 1798 plugin->env->stats,
1791 "# UDP, fragmented msgs, fragments bytes, sent, failure", 1799 "# UDP, fragmented msgs, fragments bytes, sent, failure",
1792 udpw->msg_size, 1800 udpw->msg_size,
1793 GNUNET_NO); 1801 GNUNET_NO);
1794 } 1802 }
1795} 1803}
1796 1804
1797 1805
@@ -1805,35 +1813,35 @@ qc_fragment_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
1805 * @param msg the message that was created 1813 * @param msg the message that was created
1806 */ 1814 */
1807static void 1815static void
1808enqueue_fragment(void *cls, const struct GNUNET_MessageHeader *msg) 1816enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
1809{ 1817{
1810 struct UDP_FragmentationContext *frag_ctx = cls; 1818 struct UDP_FragmentationContext *frag_ctx = cls;
1811 struct Plugin *plugin = frag_ctx->plugin; 1819 struct Plugin *plugin = frag_ctx->plugin;
1812 struct UDP_MessageWrapper *udpw; 1820 struct UDP_MessageWrapper *udpw;
1813 struct GNUNET_ATS_Session *session = frag_ctx->session; 1821 struct GNUNET_ATS_Session *session = frag_ctx->session;
1814 size_t msg_len = ntohs(msg->size); 1822 size_t msg_len = ntohs (msg->size);
1815 1823
1816 LOG(GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len); 1824 LOG (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len);
1817 udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + msg_len); 1825 udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + msg_len);
1818 udpw->session = session; 1826 udpw->session = session;
1819 udpw->msg_buf = (char *)&udpw[1]; 1827 udpw->msg_buf = (char *) &udpw[1];
1820 udpw->msg_size = msg_len; 1828 udpw->msg_size = msg_len;
1821 udpw->payload_size = msg_len; /* FIXME: minus fragment overhead */ 1829 udpw->payload_size = msg_len; /* FIXME: minus fragment overhead */
1822 udpw->timeout = frag_ctx->timeout; 1830 udpw->timeout = frag_ctx->timeout;
1823 udpw->start_time = frag_ctx->start_time; 1831 udpw->start_time = frag_ctx->start_time;
1824 udpw->transmission_time = frag_ctx->next_frag_time; 1832 udpw->transmission_time = frag_ctx->next_frag_time;
1825 frag_ctx->next_frag_time = 1833 frag_ctx->next_frag_time =
1826 GNUNET_TIME_absolute_add(frag_ctx->next_frag_time, 1834 GNUNET_TIME_absolute_add (frag_ctx->next_frag_time,
1827 frag_ctx->flow_delay_from_other_peer); 1835 frag_ctx->flow_delay_from_other_peer);
1828 udpw->frag_ctx = frag_ctx; 1836 udpw->frag_ctx = frag_ctx;
1829 udpw->qc = &qc_fragment_sent; 1837 udpw->qc = &qc_fragment_sent;
1830 udpw->qc_cls = plugin; 1838 udpw->qc_cls = plugin;
1831 GNUNET_memcpy(udpw->msg_buf, msg, msg_len); 1839 GNUNET_memcpy (udpw->msg_buf, msg, msg_len);
1832 enqueue(plugin, udpw); 1840 enqueue (plugin, udpw);
1833 if (session->address->address_length == sizeof(struct IPv4UdpAddress)) 1841 if (session->address->address_length == sizeof(struct IPv4UdpAddress))
1834 schedule_select_v4(plugin); 1842 schedule_select_v4 (plugin);
1835 else 1843 else
1836 schedule_select_v6(plugin); 1844 schedule_select_v6 (plugin);
1837} 1845}
1838 1846
1839 1847
@@ -1846,7 +1854,7 @@ enqueue_fragment(void *cls, const struct GNUNET_MessageHeader *msg)
1846 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure 1854 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure
1847 */ 1855 */
1848static void 1856static void
1849qc_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result) 1857qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
1850{ 1858{
1851 struct Plugin *plugin = cls; 1859 struct Plugin *plugin = cls;
1852 size_t overhead; 1860 size_t overhead;
@@ -1858,68 +1866,68 @@ qc_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
1858 overhead = udpw->msg_size; 1866 overhead = udpw->msg_size;
1859 1867
1860 if (NULL != udpw->cont) 1868 if (NULL != udpw->cont)
1861 { 1869 {
1862 delay = GNUNET_TIME_absolute_get_duration(udpw->start_time); 1870 delay = GNUNET_TIME_absolute_get_duration (udpw->start_time);
1863 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 1871 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
1864 { 1872 {
1865 LOG(GNUNET_ERROR_TYPE_WARNING, 1873 LOG (GNUNET_ERROR_TYPE_WARNING,
1866 "Message sent via UDP with delay of %s\n", 1874 "Message sent via UDP with delay of %s\n",
1867 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); 1875 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
1868 } 1876 }
1869 else 1877 else
1870 { 1878 {
1871 LOG(GNUNET_ERROR_TYPE_DEBUG, 1879 LOG (GNUNET_ERROR_TYPE_DEBUG,
1872 "Message sent via UDP with delay of %s\n", 1880 "Message sent via UDP with delay of %s\n",
1873 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); 1881 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
1874 } 1882 }
1875 udpw->cont(udpw->cont_cls, 1883 udpw->cont (udpw->cont_cls,
1876 &udpw->session->target, 1884 &udpw->session->target,
1877 result, 1885 result,
1878 udpw->payload_size, 1886 udpw->payload_size,
1879 overhead); 1887 overhead);
1880 } 1888 }
1881 if (GNUNET_OK == result) 1889 if (GNUNET_OK == result)
1882 { 1890 {
1883 GNUNET_STATISTICS_update(plugin->env->stats, 1891 GNUNET_STATISTICS_update (plugin->env->stats,
1884 "# UDP, unfragmented msgs, messages, sent, success", 1892 "# UDP, unfragmented msgs, messages, sent, success",
1885 1, 1893 1,
1886 GNUNET_NO); 1894 GNUNET_NO);
1887 GNUNET_STATISTICS_update( 1895 GNUNET_STATISTICS_update (
1888 plugin->env->stats, 1896 plugin->env->stats,
1889 "# UDP, unfragmented msgs, bytes payload, sent, success", 1897 "# UDP, unfragmented msgs, bytes payload, sent, success",
1890 udpw->payload_size, 1898 udpw->payload_size,
1891 GNUNET_NO); 1899 GNUNET_NO);
1892 GNUNET_STATISTICS_update( 1900 GNUNET_STATISTICS_update (
1893 plugin->env->stats, 1901 plugin->env->stats,
1894 "# UDP, unfragmented msgs, bytes overhead, sent, success", 1902 "# UDP, unfragmented msgs, bytes overhead, sent, success",
1895 overhead, 1903 overhead,
1896 GNUNET_NO); 1904 GNUNET_NO);
1897 GNUNET_STATISTICS_update(plugin->env->stats, 1905 GNUNET_STATISTICS_update (plugin->env->stats,
1898 "# UDP, total, bytes overhead, sent", 1906 "# UDP, total, bytes overhead, sent",
1899 overhead, 1907 overhead,
1900 GNUNET_NO); 1908 GNUNET_NO);
1901 GNUNET_STATISTICS_update(plugin->env->stats, 1909 GNUNET_STATISTICS_update (plugin->env->stats,
1902 "# UDP, total, bytes payload, sent", 1910 "# UDP, total, bytes payload, sent",
1903 udpw->payload_size, 1911 udpw->payload_size,
1904 GNUNET_NO); 1912 GNUNET_NO);
1905 } 1913 }
1906 else 1914 else
1907 { 1915 {
1908 GNUNET_STATISTICS_update(plugin->env->stats, 1916 GNUNET_STATISTICS_update (plugin->env->stats,
1909 "# UDP, unfragmented msgs, messages, sent, failure", 1917 "# UDP, unfragmented msgs, messages, sent, failure",
1910 1, 1918 1,
1911 GNUNET_NO); 1919 GNUNET_NO);
1912 GNUNET_STATISTICS_update( 1920 GNUNET_STATISTICS_update (
1913 plugin->env->stats, 1921 plugin->env->stats,
1914 "# UDP, unfragmented msgs, bytes payload, sent, failure", 1922 "# UDP, unfragmented msgs, bytes payload, sent, failure",
1915 udpw->payload_size, 1923 udpw->payload_size,
1916 GNUNET_NO); 1924 GNUNET_NO);
1917 GNUNET_STATISTICS_update( 1925 GNUNET_STATISTICS_update (
1918 plugin->env->stats, 1926 plugin->env->stats,
1919 "# UDP, unfragmented msgs, bytes overhead, sent, failure", 1927 "# UDP, unfragmented msgs, bytes overhead, sent, failure",
1920 overhead, 1928 overhead,
1921 GNUNET_NO); 1929 GNUNET_NO);
1922 } 1930 }
1923} 1931}
1924 1932
1925 1933
@@ -1951,14 +1959,14 @@ qc_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
1951 * and does NOT mean that the message was not transmitted (DV) 1959 * and does NOT mean that the message was not transmitted (DV)
1952 */ 1960 */
1953static ssize_t 1961static ssize_t
1954udp_plugin_send(void *cls, 1962udp_plugin_send (void *cls,
1955 struct GNUNET_ATS_Session *s, 1963 struct GNUNET_ATS_Session *s,
1956 const char *msgbuf, 1964 const char *msgbuf,
1957 size_t msgbuf_size, 1965 size_t msgbuf_size,
1958 unsigned int priority, 1966 unsigned int priority,
1959 struct GNUNET_TIME_Relative to, 1967 struct GNUNET_TIME_Relative to,
1960 GNUNET_TRANSPORT_TransmitContinuation cont, 1968 GNUNET_TRANSPORT_TransmitContinuation cont,
1961 void *cont_cls) 1969 void *cont_cls)
1962{ 1970{
1963 struct Plugin *plugin = cls; 1971 struct Plugin *plugin = cls;
1964 size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage); 1972 size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage);
@@ -1975,30 +1983,30 @@ udp_plugin_send(void *cls,
1975 (NULL == plugin->sockv4)) 1983 (NULL == plugin->sockv4))
1976 return GNUNET_SYSERR; 1984 return GNUNET_SYSERR;
1977 if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE) 1985 if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE)
1978 { 1986 {
1979 GNUNET_break(0); 1987 GNUNET_break (0);
1980 return GNUNET_SYSERR; 1988 return GNUNET_SYSERR;
1981 } 1989 }
1982 if (GNUNET_YES != 1990 if (GNUNET_YES !=
1983 GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions, 1991 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions,
1984 &s->target, 1992 &s->target,
1985 s)) 1993 s))
1986 { 1994 {
1987 GNUNET_break(0); 1995 GNUNET_break (0);
1988 return GNUNET_SYSERR; 1996 return GNUNET_SYSERR;
1989 } 1997 }
1990 LOG(GNUNET_ERROR_TYPE_DEBUG, 1998 LOG (GNUNET_ERROR_TYPE_DEBUG,
1991 "UDP transmits %u-byte message to `%s' using address `%s'\n", 1999 "UDP transmits %u-byte message to `%s' using address `%s'\n",
1992 udpmlen, 2000 udpmlen,
1993 GNUNET_i2s(&s->target), 2001 GNUNET_i2s (&s->target),
1994 udp_address_to_string(plugin, 2002 udp_address_to_string (plugin,
1995 s->address->address, 2003 s->address->address,
1996 s->address->address_length)); 2004 s->address->address_length));
1997 2005
1998 udp = (struct UDPMessage *)mbuf; 2006 udp = (struct UDPMessage *) mbuf;
1999 udp->header.size = htons(udpmlen); 2007 udp->header.size = htons (udpmlen);
2000 udp->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE); 2008 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE);
2001 udp->reserved = htonl(0); 2009 udp->reserved = htonl (0);
2002 udp->sender = *plugin->env->my_identity; 2010 udp->sender = *plugin->env->my_identity;
2003 2011
2004 /* We do not update the session time out here! Otherwise this 2012 /* We do not update the session time out here! Otherwise this
@@ -2010,100 +2018,100 @@ udp_plugin_send(void *cls,
2010 * responses! 2018 * responses!
2011 */ 2019 */
2012 if (udpmlen <= UDP_MTU) 2020 if (udpmlen <= UDP_MTU)
2013 { 2021 {
2014 /* unfragmented message */ 2022 /* unfragmented message */
2015 udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + udpmlen); 2023 udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + udpmlen);
2016 udpw->session = s; 2024 udpw->session = s;
2017 udpw->msg_buf = (char *)&udpw[1]; 2025 udpw->msg_buf = (char *) &udpw[1];
2018 udpw->msg_size = udpmlen; /* message size with UDP overhead */ 2026 udpw->msg_size = udpmlen; /* message size with UDP overhead */
2019 udpw->payload_size = msgbuf_size; /* message size without UDP overhead */ 2027 udpw->payload_size = msgbuf_size; /* message size without UDP overhead */
2020 udpw->start_time = GNUNET_TIME_absolute_get(); 2028 udpw->start_time = GNUNET_TIME_absolute_get ();
2021 udpw->timeout = GNUNET_TIME_relative_to_absolute(to); 2029 udpw->timeout = GNUNET_TIME_relative_to_absolute (to);
2022 udpw->transmission_time = s->last_transmit_time; 2030 udpw->transmission_time = s->last_transmit_time;
2023 s->last_transmit_time = 2031 s->last_transmit_time =
2024 GNUNET_TIME_absolute_add(s->last_transmit_time, 2032 GNUNET_TIME_absolute_add (s->last_transmit_time,
2025 s->flow_delay_from_other_peer); 2033 s->flow_delay_from_other_peer);
2026 udpw->cont = cont; 2034 udpw->cont = cont;
2027 udpw->cont_cls = cont_cls; 2035 udpw->cont_cls = cont_cls;
2028 udpw->frag_ctx = NULL; 2036 udpw->frag_ctx = NULL;
2029 udpw->qc = &qc_message_sent; 2037 udpw->qc = &qc_message_sent;
2030 udpw->qc_cls = plugin; 2038 udpw->qc_cls = plugin;
2031 GNUNET_memcpy(udpw->msg_buf, udp, sizeof(struct UDPMessage)); 2039 GNUNET_memcpy (udpw->msg_buf, udp, sizeof(struct UDPMessage));
2032 GNUNET_memcpy(&udpw->msg_buf[sizeof(struct UDPMessage)], 2040 GNUNET_memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)],
2033 msgbuf, 2041 msgbuf,
2034 msgbuf_size); 2042 msgbuf_size);
2035 enqueue(plugin, udpw); 2043 enqueue (plugin, udpw);
2036 GNUNET_STATISTICS_update(plugin->env->stats, 2044 GNUNET_STATISTICS_update (plugin->env->stats,
2037 "# UDP, unfragmented messages queued total", 2045 "# UDP, unfragmented messages queued total",
2038 1, 2046 1,
2039 GNUNET_NO); 2047 GNUNET_NO);
2040 GNUNET_STATISTICS_update(plugin->env->stats, 2048 GNUNET_STATISTICS_update (plugin->env->stats,
2041 "# UDP, unfragmented bytes payload queued total", 2049 "# UDP, unfragmented bytes payload queued total",
2042 msgbuf_size, 2050 msgbuf_size,
2043 GNUNET_NO); 2051 GNUNET_NO);
2044 if (s->address->address_length == sizeof(struct IPv4UdpAddress)) 2052 if (s->address->address_length == sizeof(struct IPv4UdpAddress))
2045 schedule_select_v4(plugin); 2053 schedule_select_v4 (plugin);
2046 else 2054 else
2047 schedule_select_v6(plugin); 2055 schedule_select_v6 (plugin);
2048 } 2056 }
2049 else 2057 else
2050 { 2058 {
2051 /* fragmented message */ 2059 /* fragmented message */
2052 if (NULL != s->frag_ctx) 2060 if (NULL != s->frag_ctx)
2053 return GNUNET_SYSERR; 2061 return GNUNET_SYSERR;
2054 GNUNET_memcpy(&udp[1], msgbuf, msgbuf_size); 2062 GNUNET_memcpy (&udp[1], msgbuf, msgbuf_size);
2055 frag_ctx = GNUNET_new(struct UDP_FragmentationContext); 2063 frag_ctx = GNUNET_new (struct UDP_FragmentationContext);
2056 frag_ctx->plugin = plugin; 2064 frag_ctx->plugin = plugin;
2057 frag_ctx->session = s; 2065 frag_ctx->session = s;
2058 frag_ctx->cont = cont; 2066 frag_ctx->cont = cont;
2059 frag_ctx->cont_cls = cont_cls; 2067 frag_ctx->cont_cls = cont_cls;
2060 frag_ctx->start_time = GNUNET_TIME_absolute_get(); 2068 frag_ctx->start_time = GNUNET_TIME_absolute_get ();
2061 frag_ctx->next_frag_time = s->last_transmit_time; 2069 frag_ctx->next_frag_time = s->last_transmit_time;
2062 frag_ctx->flow_delay_from_other_peer = 2070 frag_ctx->flow_delay_from_other_peer =
2063 GNUNET_TIME_relative_divide(s->flow_delay_from_other_peer, 2071 GNUNET_TIME_relative_divide (s->flow_delay_from_other_peer,
2064 1 + (msgbuf_size / UDP_MTU)); 2072 1 + (msgbuf_size / UDP_MTU));
2065 frag_ctx->timeout = GNUNET_TIME_relative_to_absolute(to); 2073 frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to);
2066 frag_ctx->payload_size = 2074 frag_ctx->payload_size =
2067 msgbuf_size; /* unfragmented message size without UDP overhead */ 2075 msgbuf_size; /* unfragmented message size without UDP overhead */
2068 frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ 2076 frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */
2069 frag_ctx->frag = GNUNET_FRAGMENT_context_create(plugin->env->stats, 2077 frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
2070 UDP_MTU, 2078 UDP_MTU,
2071 &plugin->tracker, 2079 &plugin->tracker,
2072 s->last_expected_msg_delay, 2080 s->last_expected_msg_delay,
2073 s->last_expected_ack_delay, 2081 s->last_expected_ack_delay,
2074 &udp->header, 2082 &udp->header,
2075 &enqueue_fragment, 2083 &enqueue_fragment,
2076 frag_ctx); 2084 frag_ctx);
2077 s->frag_ctx = frag_ctx; 2085 s->frag_ctx = frag_ctx;
2078 s->last_transmit_time = frag_ctx->next_frag_time; 2086 s->last_transmit_time = frag_ctx->next_frag_time;
2079 latency = GNUNET_TIME_absolute_get_remaining(s->last_transmit_time); 2087 latency = GNUNET_TIME_absolute_get_remaining (s->last_transmit_time);
2080 if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 2088 if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2081 LOG(GNUNET_ERROR_TYPE_WARNING, 2089 LOG (GNUNET_ERROR_TYPE_WARNING,
2082 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", 2090 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2083 GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_YES), 2091 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES),
2084 GNUNET_i2s(&s->target), 2092 GNUNET_i2s (&s->target),
2085 (unsigned int)s->msgs_in_queue); 2093 (unsigned int) s->msgs_in_queue);
2086 else 2094 else
2087 LOG(GNUNET_ERROR_TYPE_DEBUG, 2095 LOG (GNUNET_ERROR_TYPE_DEBUG,
2088 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", 2096 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2089 GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_YES), 2097 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES),
2090 GNUNET_i2s(&s->target), 2098 GNUNET_i2s (&s->target),
2091 (unsigned int)s->msgs_in_queue); 2099 (unsigned int) s->msgs_in_queue);
2092 2100
2093 GNUNET_STATISTICS_update(plugin->env->stats, 2101 GNUNET_STATISTICS_update (plugin->env->stats,
2094 "# UDP, fragmented messages active", 2102 "# UDP, fragmented messages active",
2095 1, 2103 1,
2096 GNUNET_NO); 2104 GNUNET_NO);
2097 GNUNET_STATISTICS_update(plugin->env->stats, 2105 GNUNET_STATISTICS_update (plugin->env->stats,
2098 "# UDP, fragmented messages, total", 2106 "# UDP, fragmented messages, total",
2099 1, 2107 1,
2100 GNUNET_NO); 2108 GNUNET_NO);
2101 GNUNET_STATISTICS_update(plugin->env->stats, 2109 GNUNET_STATISTICS_update (plugin->env->stats,
2102 "# UDP, fragmented bytes (payload)", 2110 "# UDP, fragmented bytes (payload)",
2103 frag_ctx->payload_size, 2111 frag_ctx->payload_size,
2104 GNUNET_NO); 2112 GNUNET_NO);
2105 } 2113 }
2106 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 2114 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2107 return udpmlen; 2115 return udpmlen;
2108} 2116}
2109 2117
@@ -2114,7 +2122,8 @@ udp_plugin_send(void *cls,
2114/** 2122/**
2115 * Closure for #find_receive_context(). 2123 * Closure for #find_receive_context().
2116 */ 2124 */
2117struct FindReceiveContext { 2125struct FindReceiveContext
2126{
2118 /** 2127 /**
2119 * Where to store the result. 2128 * Where to store the result.
2120 */ 2129 */
@@ -2148,20 +2157,20 @@ struct FindReceiveContext {
2148 * #GNUNET_NO if not. 2157 * #GNUNET_NO if not.
2149 */ 2158 */
2150static int 2159static int
2151find_receive_context(void *cls, 2160find_receive_context (void *cls,
2152 struct GNUNET_CONTAINER_HeapNode *node, 2161 struct GNUNET_CONTAINER_HeapNode *node,
2153 void *element, 2162 void *element,
2154 GNUNET_CONTAINER_HeapCostType cost) 2163 GNUNET_CONTAINER_HeapCostType cost)
2155{ 2164{
2156 struct FindReceiveContext *frc = cls; 2165 struct FindReceiveContext *frc = cls;
2157 struct DefragContext *e = element; 2166 struct DefragContext *e = element;
2158 2167
2159 if ((frc->udp_addr_len == e->udp_addr_len) && 2168 if ((frc->udp_addr_len == e->udp_addr_len) &&
2160 (0 == memcmp(frc->udp_addr, e->udp_addr, frc->udp_addr_len))) 2169 (0 == memcmp (frc->udp_addr, e->udp_addr, frc->udp_addr_len)))
2161 { 2170 {
2162 frc->rc = e; 2171 frc->rc = e;
2163 return GNUNET_NO; 2172 return GNUNET_NO;
2164 } 2173 }
2165 return GNUNET_YES; 2174 return GNUNET_YES;
2166} 2175}
2167 2176
@@ -2175,96 +2184,96 @@ find_receive_context(void *cls,
2175 * @return #GNUNET_OK on success 2184 * @return #GNUNET_OK on success
2176 */ 2185 */
2177static int 2186static int
2178udp_disconnect_session(void *cls, struct GNUNET_ATS_Session *s) 2187udp_disconnect_session (void *cls, struct GNUNET_ATS_Session *s)
2179{ 2188{
2180 struct Plugin *plugin = cls; 2189 struct Plugin *plugin = cls;
2181 struct UDP_MessageWrapper *udpw; 2190 struct UDP_MessageWrapper *udpw;
2182 struct UDP_MessageWrapper *next; 2191 struct UDP_MessageWrapper *next;
2183 struct FindReceiveContext frc; 2192 struct FindReceiveContext frc;
2184 2193
2185 GNUNET_assert(GNUNET_YES != s->in_destroy); 2194 GNUNET_assert (GNUNET_YES != s->in_destroy);
2186 LOG(GNUNET_ERROR_TYPE_DEBUG, 2195 LOG (GNUNET_ERROR_TYPE_DEBUG,
2187 "Session %p to peer `%s' at address %s ended\n", 2196 "Session %p to peer `%s' at address %s ended\n",
2188 s, 2197 s,
2189 GNUNET_i2s(&s->target), 2198 GNUNET_i2s (&s->target),
2190 udp_address_to_string(plugin, 2199 udp_address_to_string (plugin,
2191 s->address->address, 2200 s->address->address,
2192 s->address->address_length)); 2201 s->address->address_length));
2193 if (NULL != s->timeout_task) 2202 if (NULL != s->timeout_task)
2194 { 2203 {
2195 GNUNET_SCHEDULER_cancel(s->timeout_task); 2204 GNUNET_SCHEDULER_cancel (s->timeout_task);
2196 s->timeout_task = NULL; 2205 s->timeout_task = NULL;
2197 } 2206 }
2198 if (NULL != s->frag_ctx) 2207 if (NULL != s->frag_ctx)
2199 { 2208 {
2200 /* Remove fragmented message due to disconnect */ 2209 /* Remove fragmented message due to disconnect */
2201 fragmented_message_done(s->frag_ctx, GNUNET_SYSERR); 2210 fragmented_message_done (s->frag_ctx, GNUNET_SYSERR);
2202 } 2211 }
2203 GNUNET_assert( 2212 GNUNET_assert (
2204 GNUNET_YES == 2213 GNUNET_YES ==
2205 GNUNET_CONTAINER_multipeermap_remove(plugin->sessions, &s->target, s)); 2214 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s));
2206 frc.rc = NULL; 2215 frc.rc = NULL;
2207 frc.udp_addr = s->address->address; 2216 frc.udp_addr = s->address->address;
2208 frc.udp_addr_len = s->address->address_length; 2217 frc.udp_addr_len = s->address->address_length;
2209 /* Lookup existing receive context for this address */ 2218 /* Lookup existing receive context for this address */
2210 if (NULL != plugin->defrag_ctxs) 2219 if (NULL != plugin->defrag_ctxs)
2220 {
2221 GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs,
2222 &find_receive_context,
2223 &frc);
2224 if (NULL != frc.rc)
2211 { 2225 {
2212 GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs, 2226 struct DefragContext *d_ctx = frc.rc;
2213 &find_receive_context,
2214 &frc);
2215 if (NULL != frc.rc)
2216 {
2217 struct DefragContext *d_ctx = frc.rc;
2218 2227
2219 GNUNET_CONTAINER_heap_remove_node(d_ctx->hnode); 2228 GNUNET_CONTAINER_heap_remove_node (d_ctx->hnode);
2220 GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag); 2229 GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag);
2221 GNUNET_free(d_ctx); 2230 GNUNET_free (d_ctx);
2222 }
2223 } 2231 }
2232 }
2224 s->in_destroy = GNUNET_YES; 2233 s->in_destroy = GNUNET_YES;
2225 next = plugin->ipv4_queue_head; 2234 next = plugin->ipv4_queue_head;
2226 while (NULL != (udpw = next)) 2235 while (NULL != (udpw = next))
2236 {
2237 next = udpw->next;
2238 if (udpw->session == s)
2227 { 2239 {
2228 next = udpw->next; 2240 dequeue (plugin, udpw);
2229 if (udpw->session == s) 2241 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
2230 { 2242 GNUNET_free (udpw);
2231 dequeue(plugin, udpw);
2232 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
2233 GNUNET_free(udpw);
2234 }
2235 } 2243 }
2244 }
2236 next = plugin->ipv6_queue_head; 2245 next = plugin->ipv6_queue_head;
2237 while (NULL != (udpw = next)) 2246 while (NULL != (udpw = next))
2247 {
2248 next = udpw->next;
2249 if (udpw->session == s)
2238 { 2250 {
2239 next = udpw->next; 2251 dequeue (plugin, udpw);
2240 if (udpw->session == s) 2252 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
2241 { 2253 GNUNET_free (udpw);
2242 dequeue(plugin, udpw);
2243 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
2244 GNUNET_free(udpw);
2245 }
2246 } 2254 }
2255 }
2247 if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont)) 2256 if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont))
2248 { 2257 {
2249 /* The 'frag_ctx' itself will be freed in #free_session() a bit 2258 /* The 'frag_ctx' itself will be freed in #free_session() a bit
2250 later, as it might be in use right now */ 2259 later, as it might be in use right now */
2251 LOG(GNUNET_ERROR_TYPE_DEBUG, 2260 LOG (GNUNET_ERROR_TYPE_DEBUG,
2252 "Calling continuation for fragemented message to `%s' with result SYSERR\n", 2261 "Calling continuation for fragemented message to `%s' with result SYSERR\n",
2253 GNUNET_i2s(&s->target)); 2262 GNUNET_i2s (&s->target));
2254 s->frag_ctx->cont(s->frag_ctx->cont_cls, 2263 s->frag_ctx->cont (s->frag_ctx->cont_cls,
2255 &s->target, 2264 &s->target,
2256 GNUNET_SYSERR, 2265 GNUNET_SYSERR,
2257 s->frag_ctx->payload_size, 2266 s->frag_ctx->payload_size,
2258 s->frag_ctx->on_wire_size); 2267 s->frag_ctx->on_wire_size);
2259 } 2268 }
2260 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_DONE); 2269 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_DONE);
2261 plugin->env->session_end(plugin->env->cls, s->address, s); 2270 plugin->env->session_end (plugin->env->cls, s->address, s);
2262 GNUNET_STATISTICS_set(plugin->env->stats, 2271 GNUNET_STATISTICS_set (plugin->env->stats,
2263 "# UDP sessions active", 2272 "# UDP sessions active",
2264 GNUNET_CONTAINER_multipeermap_size(plugin->sessions), 2273 GNUNET_CONTAINER_multipeermap_size (plugin->sessions),
2265 GNUNET_NO); 2274 GNUNET_NO);
2266 if (0 == s->rc) 2275 if (0 == s->rc)
2267 free_session(s); 2276 free_session (s);
2268 return GNUNET_OK; 2277 return GNUNET_OK;
2269} 2278}
2270 2279
@@ -2278,10 +2287,10 @@ udp_disconnect_session(void *cls, struct GNUNET_ATS_Session *s)
2278 * @param udp_addr_len number of bytes in @a udp_addr 2287 * @param udp_addr_len number of bytes in @a udp_addr
2279 */ 2288 */
2280static void 2289static void
2281read_process_ack(struct Plugin *plugin, 2290read_process_ack (struct Plugin *plugin,
2282 const struct GNUNET_MessageHeader *msg, 2291 const struct GNUNET_MessageHeader *msg,
2283 const union UdpAddress *udp_addr, 2292 const union UdpAddress *udp_addr,
2284 socklen_t udp_addr_len) 2293 socklen_t udp_addr_len)
2285{ 2294{
2286 const struct GNUNET_MessageHeader *ack; 2295 const struct GNUNET_MessageHeader *ack;
2287 const struct UDP_ACK_Message *udp_ack; 2296 const struct UDP_ACK_Message *udp_ack;
@@ -2290,93 +2299,93 @@ read_process_ack(struct Plugin *plugin,
2290 struct GNUNET_TIME_Relative flow_delay; 2299 struct GNUNET_TIME_Relative flow_delay;
2291 2300
2292 /* check message format */ 2301 /* check message format */
2293 if (ntohs(msg->size) < 2302 if (ntohs (msg->size) <
2294 sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader)) 2303 sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader))
2295 { 2304 {
2296 GNUNET_break_op(0); 2305 GNUNET_break_op (0);
2297 return; 2306 return;
2298 } 2307 }
2299 udp_ack = (const struct UDP_ACK_Message *)msg; 2308 udp_ack = (const struct UDP_ACK_Message *) msg;
2300 ack = (const struct GNUNET_MessageHeader *)&udp_ack[1]; 2309 ack = (const struct GNUNET_MessageHeader *) &udp_ack[1];
2301 if (ntohs(ack->size) != ntohs(msg->size) - sizeof(struct UDP_ACK_Message)) 2310 if (ntohs (ack->size) != ntohs (msg->size) - sizeof(struct UDP_ACK_Message))
2302 { 2311 {
2303 GNUNET_break_op(0); 2312 GNUNET_break_op (0);
2304 return; 2313 return;
2305 } 2314 }
2306 2315
2307 /* Locate session */ 2316 /* Locate session */
2308 address = GNUNET_HELLO_address_allocate(&udp_ack->sender, 2317 address = GNUNET_HELLO_address_allocate (&udp_ack->sender,
2309 PLUGIN_NAME, 2318 PLUGIN_NAME,
2310 udp_addr, 2319 udp_addr,
2311 udp_addr_len, 2320 udp_addr_len,
2312 GNUNET_HELLO_ADDRESS_INFO_NONE); 2321 GNUNET_HELLO_ADDRESS_INFO_NONE);
2313 s = udp_plugin_lookup_session(plugin, address); 2322 s = udp_plugin_lookup_session (plugin, address);
2314 if (NULL == s) 2323 if (NULL == s)
2315 { 2324 {
2316 LOG(GNUNET_ERROR_TYPE_WARNING, 2325 LOG (GNUNET_ERROR_TYPE_WARNING,
2317 "UDP session of address %s for ACK not found\n", 2326 "UDP session of address %s for ACK not found\n",
2318 udp_address_to_string(plugin, 2327 udp_address_to_string (plugin,
2319 address->address, 2328 address->address,
2320 address->address_length)); 2329 address->address_length));
2321 GNUNET_HELLO_address_free(address); 2330 GNUNET_HELLO_address_free (address);
2322 return; 2331 return;
2323 } 2332 }
2324 if (NULL == s->frag_ctx) 2333 if (NULL == s->frag_ctx)
2325 { 2334 {
2326 LOG(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2335 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2327 "Fragmentation context of address %s for ACK (%s) not found\n", 2336 "Fragmentation context of address %s for ACK (%s) not found\n",
2328 udp_address_to_string(plugin, 2337 udp_address_to_string (plugin,
2329 address->address, 2338 address->address,
2330 address->address_length), 2339 address->address_length),
2331 GNUNET_FRAGMENT_print_ack(ack)); 2340 GNUNET_FRAGMENT_print_ack (ack));
2332 GNUNET_HELLO_address_free(address); 2341 GNUNET_HELLO_address_free (address);
2333 return; 2342 return;
2334 } 2343 }
2335 GNUNET_HELLO_address_free(address); 2344 GNUNET_HELLO_address_free (address);
2336 2345
2337 /* evaluate flow delay: how long should we wait between messages? */ 2346 /* evaluate flow delay: how long should we wait between messages? */
2338 if (UINT32_MAX == ntohl(udp_ack->delay)) 2347 if (UINT32_MAX == ntohl (udp_ack->delay))
2339 { 2348 {
2340 /* Other peer asked for us to terminate the session */ 2349 /* Other peer asked for us to terminate the session */
2341 LOG(GNUNET_ERROR_TYPE_INFO, 2350 LOG (GNUNET_ERROR_TYPE_INFO,
2342 "Asked to disconnect UDP session of %s\n", 2351 "Asked to disconnect UDP session of %s\n",
2343 GNUNET_i2s(&udp_ack->sender)); 2352 GNUNET_i2s (&udp_ack->sender));
2344 udp_disconnect_session(plugin, s); 2353 udp_disconnect_session (plugin, s);
2345 return; 2354 return;
2346 } 2355 }
2347 flow_delay.rel_value_us = (uint64_t)ntohl(udp_ack->delay); 2356 flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay);
2348 if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 2357 if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2349 LOG(GNUNET_ERROR_TYPE_WARNING, 2358 LOG (GNUNET_ERROR_TYPE_WARNING,
2350 "We received a sending delay of %s for %s\n", 2359 "We received a sending delay of %s for %s\n",
2351 GNUNET_STRINGS_relative_time_to_string(flow_delay, GNUNET_YES), 2360 GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES),
2352 GNUNET_i2s(&udp_ack->sender)); 2361 GNUNET_i2s (&udp_ack->sender));
2353 else 2362 else
2354 LOG(GNUNET_ERROR_TYPE_DEBUG, 2363 LOG (GNUNET_ERROR_TYPE_DEBUG,
2355 "We received a sending delay of %s for %s\n", 2364 "We received a sending delay of %s for %s\n",
2356 GNUNET_STRINGS_relative_time_to_string(flow_delay, GNUNET_YES), 2365 GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES),
2357 GNUNET_i2s(&udp_ack->sender)); 2366 GNUNET_i2s (&udp_ack->sender));
2358 /* Flow delay is for the reassembled packet, however, our delay 2367 /* Flow delay is for the reassembled packet, however, our delay
2359 is per packet, so we need to adjust: */ 2368 is per packet, so we need to adjust: */
2360 s->flow_delay_from_other_peer = flow_delay; 2369 s->flow_delay_from_other_peer = flow_delay;
2361 2370
2362 /* Handle ACK */ 2371 /* Handle ACK */
2363 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack(s->frag_ctx->frag, ack)) 2372 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack))
2364 { 2373 {
2365 LOG(GNUNET_ERROR_TYPE_DEBUG, 2374 LOG (GNUNET_ERROR_TYPE_DEBUG,
2366 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", 2375 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
2367 (unsigned int)ntohs(msg->size), 2376 (unsigned int) ntohs (msg->size),
2368 GNUNET_i2s(&udp_ack->sender), 2377 GNUNET_i2s (&udp_ack->sender),
2369 udp_address_to_string(plugin, udp_addr, udp_addr_len)); 2378 udp_address_to_string (plugin, udp_addr, udp_addr_len));
2370 /* Expect more ACKs to arrive */ 2379 /* Expect more ACKs to arrive */
2371 return; 2380 return;
2372 } 2381 }
2373 2382
2374 /* Remove fragmented message after successful sending */ 2383 /* Remove fragmented message after successful sending */
2375 LOG(GNUNET_ERROR_TYPE_DEBUG, 2384 LOG (GNUNET_ERROR_TYPE_DEBUG,
2376 "Message from %s at %s full ACK'ed\n", 2385 "Message from %s at %s full ACK'ed\n",
2377 GNUNET_i2s(&udp_ack->sender), 2386 GNUNET_i2s (&udp_ack->sender),
2378 udp_address_to_string(plugin, udp_addr, udp_addr_len)); 2387 udp_address_to_string (plugin, udp_addr, udp_addr_len));
2379 fragmented_message_done(s->frag_ctx, GNUNET_OK); 2388 fragmented_message_done (s->frag_ctx, GNUNET_OK);
2380} 2389}
2381 2390
2382 2391
@@ -2389,17 +2398,17 @@ read_process_ack(struct Plugin *plugin,
2389 * @return #GNUNET_OK (always) 2398 * @return #GNUNET_OK (always)
2390 */ 2399 */
2391static int 2400static int
2392process_inbound_tokenized_messages(void *cls, 2401process_inbound_tokenized_messages (void *cls,
2393 const struct GNUNET_MessageHeader *hdr) 2402 const struct GNUNET_MessageHeader *hdr)
2394{ 2403{
2395 struct GNUNET_ATS_Session *session = cls; 2404 struct GNUNET_ATS_Session *session = cls;
2396 struct Plugin *plugin = session->plugin; 2405 struct Plugin *plugin = session->plugin;
2397 2406
2398 if (GNUNET_YES == session->in_destroy) 2407 if (GNUNET_YES == session->in_destroy)
2399 return GNUNET_OK; 2408 return GNUNET_OK;
2400 reschedule_session_timeout(session); 2409 reschedule_session_timeout (session);
2401 session->flow_delay_for_other_peer = 2410 session->flow_delay_for_other_peer =
2402 plugin->env->receive(plugin->env->cls, session->address, session, hdr); 2411 plugin->env->receive (plugin->env->cls, session->address, session, hdr);
2403 return GNUNET_OK; 2412 return GNUNET_OK;
2404} 2413}
2405 2414
@@ -2413,13 +2422,13 @@ process_inbound_tokenized_messages(void *cls,
2413 * @return #GNUNET_OK (continue to iterate) 2422 * @return #GNUNET_OK (continue to iterate)
2414 */ 2423 */
2415static int 2424static int
2416disconnect_and_free_it(void *cls, 2425disconnect_and_free_it (void *cls,
2417 const struct GNUNET_PeerIdentity *key, 2426 const struct GNUNET_PeerIdentity *key,
2418 void *value) 2427 void *value)
2419{ 2428{
2420 struct Plugin *plugin = cls; 2429 struct Plugin *plugin = cls;
2421 2430
2422 udp_disconnect_session(plugin, value); 2431 udp_disconnect_session (plugin, value);
2423 return GNUNET_OK; 2432 return GNUNET_OK;
2424} 2433}
2425 2434
@@ -2433,17 +2442,17 @@ disconnect_and_free_it(void *cls,
2433 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed 2442 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
2434 */ 2443 */
2435static void 2444static void
2436udp_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) 2445udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2437{ 2446{
2438 struct Plugin *plugin = cls; 2447 struct Plugin *plugin = cls;
2439 2448
2440 LOG(GNUNET_ERROR_TYPE_DEBUG, 2449 LOG (GNUNET_ERROR_TYPE_DEBUG,
2441 "Disconnecting from peer `%s'\n", 2450 "Disconnecting from peer `%s'\n",
2442 GNUNET_i2s(target)); 2451 GNUNET_i2s (target));
2443 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, 2452 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions,
2444 target, 2453 target,
2445 &disconnect_and_free_it, 2454 &disconnect_and_free_it,
2446 plugin); 2455 plugin);
2447} 2456}
2448 2457
2449 2458
@@ -2453,29 +2462,29 @@ udp_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
2453 * @param cls the `struct GNUNET_ATS_Session` to time out 2462 * @param cls the `struct GNUNET_ATS_Session` to time out
2454 */ 2463 */
2455static void 2464static void
2456session_timeout(void *cls) 2465session_timeout (void *cls)
2457{ 2466{
2458 struct GNUNET_ATS_Session *s = cls; 2467 struct GNUNET_ATS_Session *s = cls;
2459 struct Plugin *plugin = s->plugin; 2468 struct Plugin *plugin = s->plugin;
2460 struct GNUNET_TIME_Relative left; 2469 struct GNUNET_TIME_Relative left;
2461 2470
2462 s->timeout_task = NULL; 2471 s->timeout_task = NULL;
2463 left = GNUNET_TIME_absolute_get_remaining(s->timeout); 2472 left = GNUNET_TIME_absolute_get_remaining (s->timeout);
2464 if (left.rel_value_us > 0) 2473 if (left.rel_value_us > 0)
2465 { 2474 {
2466 /* not actually our turn yet, but let's at least update 2475 /* not actually our turn yet, but let's at least update
2467 the monitor, it may think we're about to die ... */ 2476 the monitor, it may think we're about to die ... */
2468 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 2477 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2469 s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, &session_timeout, s); 2478 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s);
2470 return; 2479 return;
2471 } 2480 }
2472 LOG(GNUNET_ERROR_TYPE_DEBUG, 2481 LOG (GNUNET_ERROR_TYPE_DEBUG,
2473 "Session %p was idle for %s, disconnecting\n", 2482 "Session %p was idle for %s, disconnecting\n",
2474 s, 2483 s,
2475 GNUNET_STRINGS_relative_time_to_string(UDP_SESSION_TIME_OUT, 2484 GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT,
2476 GNUNET_YES)); 2485 GNUNET_YES));
2477 /* call session destroy function */ 2486 /* call session destroy function */
2478 udp_disconnect_session(plugin, s); 2487 udp_disconnect_session (plugin, s);
2479} 2488}
2480 2489
2481 2490
@@ -2491,46 +2500,46 @@ session_timeout(void *cls)
2491 * @return NULL on error, otherwise session handle 2500 * @return NULL on error, otherwise session handle
2492 */ 2501 */
2493static struct GNUNET_ATS_Session * 2502static struct GNUNET_ATS_Session *
2494udp_plugin_create_session(void *cls, 2503udp_plugin_create_session (void *cls,
2495 const struct GNUNET_HELLO_Address *address, 2504 const struct GNUNET_HELLO_Address *address,
2496 enum GNUNET_NetworkType network_type) 2505 enum GNUNET_NetworkType network_type)
2497{ 2506{
2498 struct Plugin *plugin = cls; 2507 struct Plugin *plugin = cls;
2499 struct GNUNET_ATS_Session *s; 2508 struct GNUNET_ATS_Session *s;
2500 2509
2501 s = GNUNET_new(struct GNUNET_ATS_Session); 2510 s = GNUNET_new (struct GNUNET_ATS_Session);
2502 s->mst = GNUNET_MST_create(&process_inbound_tokenized_messages, s); 2511 s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages, s);
2503 s->plugin = plugin; 2512 s->plugin = plugin;
2504 s->address = GNUNET_HELLO_address_copy(address); 2513 s->address = GNUNET_HELLO_address_copy (address);
2505 s->target = address->peer; 2514 s->target = address->peer;
2506 s->last_transmit_time = GNUNET_TIME_absolute_get(); 2515 s->last_transmit_time = GNUNET_TIME_absolute_get ();
2507 s->last_expected_ack_delay = 2516 s->last_expected_ack_delay =
2508 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250); 2517 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250);
2509 s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; 2518 s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
2510 s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO; 2519 s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO;
2511 s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; 2520 s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO;
2512 s->timeout = GNUNET_TIME_relative_to_absolute(UDP_SESSION_TIME_OUT); 2521 s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT);
2513 s->timeout_task = 2522 s->timeout_task =
2514 GNUNET_SCHEDULER_add_delayed(UDP_SESSION_TIME_OUT, &session_timeout, s); 2523 GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, &session_timeout, s);
2515 s->scope = network_type; 2524 s->scope = network_type;
2516 2525
2517 LOG(GNUNET_ERROR_TYPE_DEBUG, 2526 LOG (GNUNET_ERROR_TYPE_DEBUG,
2518 "Creating new session %p for peer `%s' address `%s'\n", 2527 "Creating new session %p for peer `%s' address `%s'\n",
2519 s, 2528 s,
2520 GNUNET_i2s(&address->peer), 2529 GNUNET_i2s (&address->peer),
2521 udp_address_to_string(plugin, 2530 udp_address_to_string (plugin,
2522 address->address, 2531 address->address,
2523 address->address_length)); 2532 address->address_length));
2524 GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multipeermap_put( 2533 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (
2525 plugin->sessions, 2534 plugin->sessions,
2526 &s->target, 2535 &s->target,
2527 s, 2536 s,
2528 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2537 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2529 GNUNET_STATISTICS_set(plugin->env->stats, 2538 GNUNET_STATISTICS_set (plugin->env->stats,
2530 "# UDP sessions active", 2539 "# UDP sessions active",
2531 GNUNET_CONTAINER_multipeermap_size(plugin->sessions), 2540 GNUNET_CONTAINER_multipeermap_size (plugin->sessions),
2532 GNUNET_NO); 2541 GNUNET_NO);
2533 notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_INIT); 2542 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_INIT);
2534 return s; 2543 return s;
2535} 2544}
2536 2545
@@ -2544,7 +2553,7 @@ udp_plugin_create_session(void *cls,
2544 * @return the session or NULL of max connections exceeded 2553 * @return the session or NULL of max connections exceeded
2545 */ 2554 */
2546static struct GNUNET_ATS_Session * 2555static struct GNUNET_ATS_Session *
2547udp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) 2556udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
2548{ 2557{
2549 struct Plugin *plugin = cls; 2558 struct Plugin *plugin = cls;
2550 struct GNUNET_ATS_Session *s; 2559 struct GNUNET_ATS_Session *s;
@@ -2553,54 +2562,54 @@ udp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
2553 const struct IPv6UdpAddress *udp_v6; 2562 const struct IPv6UdpAddress *udp_v6;
2554 2563
2555 if (NULL == address) 2564 if (NULL == address)
2556 { 2565 {
2557 GNUNET_break(0); 2566 GNUNET_break (0);
2558 return NULL; 2567 return NULL;
2559 } 2568 }
2560 if ((address->address_length != sizeof(struct IPv4UdpAddress)) && 2569 if ((address->address_length != sizeof(struct IPv4UdpAddress)) &&
2561 (address->address_length != sizeof(struct IPv6UdpAddress))) 2570 (address->address_length != sizeof(struct IPv6UdpAddress)))
2562 { 2571 {
2563 GNUNET_break_op(0); 2572 GNUNET_break_op (0);
2564 return NULL; 2573 return NULL;
2565 } 2574 }
2566 if (NULL != (s = udp_plugin_lookup_session(cls, address))) 2575 if (NULL != (s = udp_plugin_lookup_session (cls, address)))
2567 return s; 2576 return s;
2568 2577
2569 /* need to create new session */ 2578 /* need to create new session */
2570 if (sizeof(struct IPv4UdpAddress) == address->address_length) 2579 if (sizeof(struct IPv4UdpAddress) == address->address_length)
2571 { 2580 {
2572 struct sockaddr_in v4; 2581 struct sockaddr_in v4;
2573 2582
2574 udp_v4 = (const struct IPv4UdpAddress *)address->address; 2583 udp_v4 = (const struct IPv4UdpAddress *) address->address;
2575 memset(&v4, '\0', sizeof(v4)); 2584 memset (&v4, '\0', sizeof(v4));
2576 v4.sin_family = AF_INET; 2585 v4.sin_family = AF_INET;
2577#if HAVE_SOCKADDR_IN_SIN_LEN 2586#if HAVE_SOCKADDR_IN_SIN_LEN
2578 v4.sin_len = sizeof(struct sockaddr_in); 2587 v4.sin_len = sizeof(struct sockaddr_in);
2579#endif 2588#endif
2580 v4.sin_port = udp_v4->u4_port; 2589 v4.sin_port = udp_v4->u4_port;
2581 v4.sin_addr.s_addr = udp_v4->ipv4_addr; 2590 v4.sin_addr.s_addr = udp_v4->ipv4_addr;
2582 network_type = plugin->env->get_address_type(plugin->env->cls, 2591 network_type = plugin->env->get_address_type (plugin->env->cls,
2583 (const struct sockaddr *)&v4, 2592 (const struct sockaddr *) &v4,
2584 sizeof(v4)); 2593 sizeof(v4));
2585 } 2594 }
2586 if (sizeof(struct IPv6UdpAddress) == address->address_length) 2595 if (sizeof(struct IPv6UdpAddress) == address->address_length)
2587 { 2596 {
2588 struct sockaddr_in6 v6; 2597 struct sockaddr_in6 v6;
2589 2598
2590 udp_v6 = (const struct IPv6UdpAddress *)address->address; 2599 udp_v6 = (const struct IPv6UdpAddress *) address->address;
2591 memset(&v6, '\0', sizeof(v6)); 2600 memset (&v6, '\0', sizeof(v6));
2592 v6.sin6_family = AF_INET6; 2601 v6.sin6_family = AF_INET6;
2593#if HAVE_SOCKADDR_IN_SIN_LEN 2602#if HAVE_SOCKADDR_IN_SIN_LEN
2594 v6.sin6_len = sizeof(struct sockaddr_in6); 2603 v6.sin6_len = sizeof(struct sockaddr_in6);
2595#endif 2604#endif
2596 v6.sin6_port = udp_v6->u6_port; 2605 v6.sin6_port = udp_v6->u6_port;
2597 v6.sin6_addr = udp_v6->ipv6_addr; 2606 v6.sin6_addr = udp_v6->ipv6_addr;
2598 network_type = plugin->env->get_address_type(plugin->env->cls, 2607 network_type = plugin->env->get_address_type (plugin->env->cls,
2599 (const struct sockaddr *)&v6, 2608 (const struct sockaddr *) &v6,
2600 sizeof(v6)); 2609 sizeof(v6));
2601 } 2610 }
2602 GNUNET_break(GNUNET_NT_UNSPECIFIED != network_type); 2611 GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type);
2603 return udp_plugin_create_session(cls, address, network_type); 2612 return udp_plugin_create_session (cls, address, network_type);
2604} 2613}
2605 2614
2606 2615
@@ -2614,50 +2623,50 @@ udp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
2614 * @param network_type network type the address belongs to 2623 * @param network_type network type the address belongs to
2615 */ 2624 */
2616static void 2625static void
2617process_udp_message(struct Plugin *plugin, 2626process_udp_message (struct Plugin *plugin,
2618 const struct UDPMessage *msg, 2627 const struct UDPMessage *msg,
2619 const union UdpAddress *udp_addr, 2628 const union UdpAddress *udp_addr,
2620 size_t udp_addr_len, 2629 size_t udp_addr_len,
2621 enum GNUNET_NetworkType network_type) 2630 enum GNUNET_NetworkType network_type)
2622{ 2631{
2623 struct GNUNET_ATS_Session *s; 2632 struct GNUNET_ATS_Session *s;
2624 struct GNUNET_HELLO_Address *address; 2633 struct GNUNET_HELLO_Address *address;
2625 2634
2626 GNUNET_break(GNUNET_NT_UNSPECIFIED != network_type); 2635 GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type);
2627 if (0 != ntohl(msg->reserved)) 2636 if (0 != ntohl (msg->reserved))
2628 { 2637 {
2629 GNUNET_break_op(0); 2638 GNUNET_break_op (0);
2630 return; 2639 return;
2631 } 2640 }
2632 if (ntohs(msg->header.size) < 2641 if (ntohs (msg->header.size) <
2633 sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage)) 2642 sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage))
2634 { 2643 {
2635 GNUNET_break_op(0); 2644 GNUNET_break_op (0);
2636 return; 2645 return;
2637 } 2646 }
2638 2647
2639 address = GNUNET_HELLO_address_allocate(&msg->sender, 2648 address = GNUNET_HELLO_address_allocate (&msg->sender,
2640 PLUGIN_NAME, 2649 PLUGIN_NAME,
2641 udp_addr, 2650 udp_addr,
2642 udp_addr_len, 2651 udp_addr_len,
2643 GNUNET_HELLO_ADDRESS_INFO_NONE); 2652 GNUNET_HELLO_ADDRESS_INFO_NONE);
2644 if (NULL == (s = udp_plugin_lookup_session(plugin, address))) 2653 if (NULL == (s = udp_plugin_lookup_session (plugin, address)))
2645 { 2654 {
2646 s = udp_plugin_create_session(plugin, address, network_type); 2655 s = udp_plugin_create_session (plugin, address, network_type);
2647 plugin->env->session_start(plugin->env->cls, address, s, s->scope); 2656 plugin->env->session_start (plugin->env->cls, address, s, s->scope);
2648 notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_UP); 2657 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UP);
2649 } 2658 }
2650 GNUNET_free(address); 2659 GNUNET_free (address);
2651 2660
2652 s->rc++; 2661 s->rc++;
2653 GNUNET_MST_from_buffer(s->mst, 2662 GNUNET_MST_from_buffer (s->mst,
2654 (const char *)&msg[1], 2663 (const char *) &msg[1],
2655 ntohs(msg->header.size) - sizeof(struct UDPMessage), 2664 ntohs (msg->header.size) - sizeof(struct UDPMessage),
2656 GNUNET_YES, 2665 GNUNET_YES,
2657 GNUNET_NO); 2666 GNUNET_NO);
2658 s->rc--; 2667 s->rc--;
2659 if ((0 == s->rc) && (GNUNET_YES == s->in_destroy)) 2668 if ((0 == s->rc) && (GNUNET_YES == s->in_destroy))
2660 free_session(s); 2669 free_session (s);
2661} 2670}
2662 2671
2663 2672
@@ -2668,29 +2677,29 @@ process_udp_message(struct Plugin *plugin,
2668 * @param msg the message 2677 * @param msg the message
2669 */ 2678 */
2670static void 2679static void
2671fragment_msg_proc(void *cls, const struct GNUNET_MessageHeader *msg) 2680fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg)
2672{ 2681{
2673 struct DefragContext *dc = cls; 2682 struct DefragContext *dc = cls;
2674 const struct UDPMessage *um; 2683 const struct UDPMessage *um;
2675 2684
2676 if (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) 2685 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE)
2677 { 2686 {
2678 GNUNET_break_op(0); 2687 GNUNET_break_op (0);
2679 return; 2688 return;
2680 } 2689 }
2681 if (ntohs(msg->size) < sizeof(struct UDPMessage)) 2690 if (ntohs (msg->size) < sizeof(struct UDPMessage))
2682 { 2691 {
2683 GNUNET_break_op(0); 2692 GNUNET_break_op (0);
2684 return; 2693 return;
2685 } 2694 }
2686 um = (const struct UDPMessage *)msg; 2695 um = (const struct UDPMessage *) msg;
2687 dc->sender = um->sender; 2696 dc->sender = um->sender;
2688 dc->have_sender = GNUNET_YES; 2697 dc->have_sender = GNUNET_YES;
2689 process_udp_message(dc->plugin, 2698 process_udp_message (dc->plugin,
2690 um, 2699 um,
2691 dc->udp_addr, 2700 dc->udp_addr,
2692 dc->udp_addr_len, 2701 dc->udp_addr_len,
2693 dc->network_type); 2702 dc->network_type);
2694} 2703}
2695 2704
2696 2705
@@ -2704,24 +2713,24 @@ fragment_msg_proc(void *cls, const struct GNUNET_MessageHeader *msg)
2704 * #GNUNET_SYSERR if we failed to send the ACK 2713 * #GNUNET_SYSERR if we failed to send the ACK
2705 */ 2714 */
2706static void 2715static void
2707ack_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result) 2716ack_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
2708{ 2717{
2709 struct Plugin *plugin = cls; 2718 struct Plugin *plugin = cls;
2710 2719
2711 if (GNUNET_OK == result) 2720 if (GNUNET_OK == result)
2712 { 2721 {
2713 GNUNET_STATISTICS_update(plugin->env->stats, 2722 GNUNET_STATISTICS_update (plugin->env->stats,
2714 "# UDP, ACK messages sent", 2723 "# UDP, ACK messages sent",
2715 1, 2724 1,
2716 GNUNET_NO); 2725 GNUNET_NO);
2717 } 2726 }
2718 else 2727 else
2719 { 2728 {
2720 GNUNET_STATISTICS_update(plugin->env->stats, 2729 GNUNET_STATISTICS_update (plugin->env->stats,
2721 "# UDP, ACK transmissions failed", 2730 "# UDP, ACK transmissions failed",
2722 1, 2731 1,
2723 GNUNET_NO); 2732 GNUNET_NO);
2724 } 2733 }
2725} 2734}
2726 2735
2727 2736
@@ -2733,11 +2742,11 @@ ack_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
2733 * @param msg ack to transmit 2742 * @param msg ack to transmit
2734 */ 2743 */
2735static void 2744static void
2736ack_proc(void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) 2745ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2737{ 2746{
2738 struct DefragContext *rc = cls; 2747 struct DefragContext *rc = cls;
2739 struct Plugin *plugin = rc->plugin; 2748 struct Plugin *plugin = rc->plugin;
2740 size_t msize = sizeof(struct UDP_ACK_Message) + ntohs(msg->size); 2749 size_t msize = sizeof(struct UDP_ACK_Message) + ntohs (msg->size);
2741 struct UDP_ACK_Message *udp_ack; 2750 struct UDP_ACK_Message *udp_ack;
2742 uint32_t delay; 2751 uint32_t delay;
2743 struct UDP_MessageWrapper *udpw; 2752 struct UDP_MessageWrapper *udpw;
@@ -2745,36 +2754,36 @@ ack_proc(void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2745 struct GNUNET_HELLO_Address *address; 2754 struct GNUNET_HELLO_Address *address;
2746 2755
2747 if (GNUNET_NO == rc->have_sender) 2756 if (GNUNET_NO == rc->have_sender)
2748 { 2757 {
2749 /* tried to defragment but never succeeded, hence will not ACK */ 2758 /* tried to defragment but never succeeded, hence will not ACK */
2750 /* This can happen if we just lost msgs */ 2759 /* This can happen if we just lost msgs */
2751 GNUNET_STATISTICS_update(plugin->env->stats, 2760 GNUNET_STATISTICS_update (plugin->env->stats,
2752 "# UDP, fragments discarded without ACK", 2761 "# UDP, fragments discarded without ACK",
2753 1, 2762 1,
2754 GNUNET_NO); 2763 GNUNET_NO);
2755 return; 2764 return;
2756 } 2765 }
2757 address = GNUNET_HELLO_address_allocate(&rc->sender, 2766 address = GNUNET_HELLO_address_allocate (&rc->sender,
2758 PLUGIN_NAME, 2767 PLUGIN_NAME,
2759 rc->udp_addr, 2768 rc->udp_addr,
2760 rc->udp_addr_len, 2769 rc->udp_addr_len,
2761 GNUNET_HELLO_ADDRESS_INFO_NONE); 2770 GNUNET_HELLO_ADDRESS_INFO_NONE);
2762 s = udp_plugin_lookup_session(plugin, address); 2771 s = udp_plugin_lookup_session (plugin, address);
2763 GNUNET_HELLO_address_free(address); 2772 GNUNET_HELLO_address_free (address);
2764 if (NULL == s) 2773 if (NULL == s)
2765 { 2774 {
2766 LOG(GNUNET_ERROR_TYPE_ERROR, 2775 LOG (GNUNET_ERROR_TYPE_ERROR,
2767 "Trying to transmit ACK to peer `%s' but no session found!\n", 2776 "Trying to transmit ACK to peer `%s' but no session found!\n",
2768 udp_address_to_string(plugin, rc->udp_addr, rc->udp_addr_len)); 2777 udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len));
2769 GNUNET_CONTAINER_heap_remove_node(rc->hnode); 2778 GNUNET_CONTAINER_heap_remove_node (rc->hnode);
2770 GNUNET_DEFRAGMENT_context_destroy(rc->defrag); 2779 GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
2771 GNUNET_free(rc); 2780 GNUNET_free (rc);
2772 GNUNET_STATISTICS_update(plugin->env->stats, 2781 GNUNET_STATISTICS_update (plugin->env->stats,
2773 "# UDP, ACK transmissions failed", 2782 "# UDP, ACK transmissions failed",
2774 1, 2783 1,
2775 GNUNET_NO); 2784 GNUNET_NO);
2776 return; 2785 return;
2777 } 2786 }
2778 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == 2787 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us ==
2779 s->flow_delay_for_other_peer.rel_value_us) 2788 s->flow_delay_for_other_peer.rel_value_us)
2780 delay = UINT32_MAX; 2789 delay = UINT32_MAX;
@@ -2782,32 +2791,32 @@ ack_proc(void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2782 delay = s->flow_delay_for_other_peer.rel_value_us; 2791 delay = s->flow_delay_for_other_peer.rel_value_us;
2783 else 2792 else
2784 delay = UINT32_MAX - 1; /* largest value we can communicate */ 2793 delay = UINT32_MAX - 1; /* largest value we can communicate */
2785 LOG(GNUNET_ERROR_TYPE_DEBUG, 2794 LOG (GNUNET_ERROR_TYPE_DEBUG,
2786 "Sending ACK to `%s' including delay of %s\n", 2795 "Sending ACK to `%s' including delay of %s\n",
2787 udp_address_to_string(plugin, rc->udp_addr, rc->udp_addr_len), 2796 udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len),
2788 GNUNET_STRINGS_relative_time_to_string(s->flow_delay_for_other_peer, 2797 GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer,
2789 GNUNET_YES)); 2798 GNUNET_YES));
2790 udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + msize); 2799 udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + msize);
2791 udpw->msg_size = msize; 2800 udpw->msg_size = msize;
2792 udpw->payload_size = 0; 2801 udpw->payload_size = 0;
2793 udpw->session = s; 2802 udpw->session = s;
2794 udpw->start_time = GNUNET_TIME_absolute_get(); 2803 udpw->start_time = GNUNET_TIME_absolute_get ();
2795 udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 2804 udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
2796 udpw->msg_buf = (char *)&udpw[1]; 2805 udpw->msg_buf = (char *) &udpw[1];
2797 udpw->qc = &ack_message_sent; 2806 udpw->qc = &ack_message_sent;
2798 udpw->qc_cls = plugin; 2807 udpw->qc_cls = plugin;
2799 udp_ack = (struct UDP_ACK_Message *)udpw->msg_buf; 2808 udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf;
2800 udp_ack->header.size = htons((uint16_t)msize); 2809 udp_ack->header.size = htons ((uint16_t) msize);
2801 udp_ack->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); 2810 udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK);
2802 udp_ack->delay = htonl(delay); 2811 udp_ack->delay = htonl (delay);
2803 udp_ack->sender = *plugin->env->my_identity; 2812 udp_ack->sender = *plugin->env->my_identity;
2804 GNUNET_memcpy(&udp_ack[1], msg, ntohs(msg->size)); 2813 GNUNET_memcpy (&udp_ack[1], msg, ntohs (msg->size));
2805 enqueue(plugin, udpw); 2814 enqueue (plugin, udpw);
2806 notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 2815 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2807 if (s->address->address_length == sizeof(struct IPv4UdpAddress)) 2816 if (s->address->address_length == sizeof(struct IPv4UdpAddress))
2808 schedule_select_v4(plugin); 2817 schedule_select_v4 (plugin);
2809 else 2818 else
2810 schedule_select_v6(plugin); 2819 schedule_select_v6 (plugin);
2811} 2820}
2812 2821
2813 2822
@@ -2821,11 +2830,11 @@ ack_proc(void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2821 * @param network_type network type the address belongs to 2830 * @param network_type network type the address belongs to
2822 */ 2831 */
2823static void 2832static void
2824read_process_fragment(struct Plugin *plugin, 2833read_process_fragment (struct Plugin *plugin,
2825 const struct GNUNET_MessageHeader *msg, 2834 const struct GNUNET_MessageHeader *msg,
2826 const union UdpAddress *udp_addr, 2835 const union UdpAddress *udp_addr,
2827 size_t udp_addr_len, 2836 size_t udp_addr_len,
2828 enum GNUNET_NetworkType network_type) 2837 enum GNUNET_NetworkType network_type)
2829{ 2838{
2830 struct DefragContext *d_ctx; 2839 struct DefragContext *d_ctx;
2831 struct GNUNET_TIME_Absolute now; 2840 struct GNUNET_TIME_Absolute now;
@@ -2836,65 +2845,65 @@ read_process_fragment(struct Plugin *plugin,
2836 frc.udp_addr_len = udp_addr_len; 2845 frc.udp_addr_len = udp_addr_len;
2837 2846
2838 /* Lookup existing receive context for this address */ 2847 /* Lookup existing receive context for this address */
2839 GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs, 2848 GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs,
2840 &find_receive_context, 2849 &find_receive_context,
2841 &frc); 2850 &frc);
2842 now = GNUNET_TIME_absolute_get(); 2851 now = GNUNET_TIME_absolute_get ();
2843 d_ctx = frc.rc; 2852 d_ctx = frc.rc;
2844 2853
2845 if (NULL == d_ctx) 2854 if (NULL == d_ctx)
2846 { 2855 {
2847 /* Create a new defragmentation context */ 2856 /* Create a new defragmentation context */
2848 d_ctx = GNUNET_malloc(sizeof(struct DefragContext) + udp_addr_len); 2857 d_ctx = GNUNET_malloc (sizeof(struct DefragContext) + udp_addr_len);
2849 GNUNET_memcpy(&d_ctx[1], udp_addr, udp_addr_len); 2858 GNUNET_memcpy (&d_ctx[1], udp_addr, udp_addr_len);
2850 d_ctx->udp_addr = (const union UdpAddress *)&d_ctx[1]; 2859 d_ctx->udp_addr = (const union UdpAddress *) &d_ctx[1];
2851 d_ctx->udp_addr_len = udp_addr_len; 2860 d_ctx->udp_addr_len = udp_addr_len;
2852 d_ctx->network_type = network_type; 2861 d_ctx->network_type = network_type;
2853 d_ctx->plugin = plugin; 2862 d_ctx->plugin = plugin;
2854 d_ctx->defrag = 2863 d_ctx->defrag =
2855 GNUNET_DEFRAGMENT_context_create(plugin->env->stats, 2864 GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
2856 UDP_MTU, 2865 UDP_MTU,
2857 UDP_MAX_MESSAGES_IN_DEFRAG, 2866 UDP_MAX_MESSAGES_IN_DEFRAG,
2858 d_ctx, 2867 d_ctx,
2859 &fragment_msg_proc, 2868 &fragment_msg_proc,
2860 &ack_proc); 2869 &ack_proc);
2861 d_ctx->hnode = GNUNET_CONTAINER_heap_insert(plugin->defrag_ctxs, 2870 d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs,
2862 d_ctx, 2871 d_ctx,
2863 (GNUNET_CONTAINER_HeapCostType) 2872 (GNUNET_CONTAINER_HeapCostType)
2864 now.abs_value_us); 2873 now.abs_value_us);
2865 LOG(GNUNET_ERROR_TYPE_DEBUG, 2874 LOG (GNUNET_ERROR_TYPE_DEBUG,
2866 "Created new defragmentation context for %u-byte fragment from `%s'\n", 2875 "Created new defragmentation context for %u-byte fragment from `%s'\n",
2867 (unsigned int)ntohs(msg->size), 2876 (unsigned int) ntohs (msg->size),
2868 udp_address_to_string(plugin, udp_addr, udp_addr_len)); 2877 udp_address_to_string (plugin, udp_addr, udp_addr_len));
2869 } 2878 }
2870 else 2879 else
2871 { 2880 {
2872 LOG(GNUNET_ERROR_TYPE_DEBUG, 2881 LOG (GNUNET_ERROR_TYPE_DEBUG,
2873 "Found existing defragmentation context for %u-byte fragment from `%s'\n", 2882 "Found existing defragmentation context for %u-byte fragment from `%s'\n",
2874 (unsigned int)ntohs(msg->size), 2883 (unsigned int) ntohs (msg->size),
2875 udp_address_to_string(plugin, udp_addr, udp_addr_len)); 2884 udp_address_to_string (plugin, udp_addr, udp_addr_len));
2876 } 2885 }
2877 2886
2878 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment(d_ctx->defrag, msg)) 2887 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg))
2879 { 2888 {
2880 /* keep this 'rc' from expiring */ 2889 /* keep this 'rc' from expiring */
2881 GNUNET_CONTAINER_heap_update_cost(d_ctx->hnode, 2890 GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode,
2882 (GNUNET_CONTAINER_HeapCostType) 2891 (GNUNET_CONTAINER_HeapCostType)
2883 now.abs_value_us); 2892 now.abs_value_us);
2884 } 2893 }
2885 if (GNUNET_CONTAINER_heap_get_size(plugin->defrag_ctxs) > 2894 if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) >
2886 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) 2895 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
2887 { 2896 {
2888 /* remove 'rc' that was inactive the longest */ 2897 /* remove 'rc' that was inactive the longest */
2889 d_ctx = GNUNET_CONTAINER_heap_remove_root(plugin->defrag_ctxs); 2898 d_ctx = GNUNET_CONTAINER_heap_remove_root (plugin->defrag_ctxs);
2890 GNUNET_assert(NULL != d_ctx); 2899 GNUNET_assert (NULL != d_ctx);
2891 GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag); 2900 GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag);
2892 GNUNET_free(d_ctx); 2901 GNUNET_free (d_ctx);
2893 GNUNET_STATISTICS_update(plugin->env->stats, 2902 GNUNET_STATISTICS_update (plugin->env->stats,
2894 "# UDP, Defragmentations aborted", 2903 "# UDP, Defragmentations aborted",
2895 1, 2904 1,
2896 GNUNET_NO); 2905 GNUNET_NO);
2897 } 2906 }
2898} 2907}
2899 2908
2900 2909
@@ -2905,7 +2914,7 @@ read_process_fragment(struct Plugin *plugin,
2905 * @param rsock socket to read from 2914 * @param rsock socket to read from
2906 */ 2915 */
2907static void 2916static void
2908udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) 2917udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
2909{ 2918{
2910 socklen_t fromlen; 2919 socklen_t fromlen;
2911 struct sockaddr_storage addr; 2920 struct sockaddr_storage addr;
@@ -2922,126 +2931,126 @@ udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
2922 enum GNUNET_NetworkType network_type; 2931 enum GNUNET_NetworkType network_type;
2923 2932
2924 fromlen = sizeof(addr); 2933 fromlen = sizeof(addr);
2925 memset(&addr, 0, sizeof(addr)); 2934 memset (&addr, 0, sizeof(addr));
2926 size = GNUNET_NETWORK_socket_recvfrom(rsock, 2935 size = GNUNET_NETWORK_socket_recvfrom (rsock,
2927 buf, 2936 buf,
2928 sizeof(buf), 2937 sizeof(buf),
2929 (struct sockaddr *)&addr, 2938 (struct sockaddr *) &addr,
2930 &fromlen); 2939 &fromlen);
2931 sa = (const struct sockaddr *)&addr; 2940 sa = (const struct sockaddr *) &addr;
2932 2941
2933 if (-1 == size) 2942 if (-1 == size)
2934 { 2943 {
2935 LOG(GNUNET_ERROR_TYPE_DEBUG, 2944 LOG (GNUNET_ERROR_TYPE_DEBUG,
2936 "UDP failed to receive data: %s\n", 2945 "UDP failed to receive data: %s\n",
2937 strerror(errno)); 2946 strerror (errno));
2938 /* Connection failure or something. Not a protocol violation. */ 2947 /* Connection failure or something. Not a protocol violation. */
2939 return; 2948 return;
2940 } 2949 }
2941 2950
2942 /* Check if this is a STUN packet */ 2951 /* Check if this is a STUN packet */
2943 if (GNUNET_NO != 2952 if (GNUNET_NO !=
2944 GNUNET_NAT_stun_handle_packet(plugin->nat, 2953 GNUNET_NAT_stun_handle_packet (plugin->nat,
2945 (const struct sockaddr *)&addr, 2954 (const struct sockaddr *) &addr,
2946 fromlen, 2955 fromlen,
2947 buf, 2956 buf,
2948 size)) 2957 size))
2949 return; /* was STUN, do not process further */ 2958 return; /* was STUN, do not process further */
2950 2959
2951 if (size < sizeof(struct GNUNET_MessageHeader)) 2960 if (size < sizeof(struct GNUNET_MessageHeader))
2952 { 2961 {
2953 LOG(GNUNET_ERROR_TYPE_WARNING, 2962 LOG (GNUNET_ERROR_TYPE_WARNING,
2954 "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n", 2963 "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n",
2955 (unsigned int)size, 2964 (unsigned int) size,
2956 GNUNET_a2s(sa, fromlen)); 2965 GNUNET_a2s (sa, fromlen));
2957 /* _MAY_ be a connection failure (got partial message) */ 2966 /* _MAY_ be a connection failure (got partial message) */
2958 /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ 2967 /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */
2959 GNUNET_break_op(0); 2968 GNUNET_break_op (0);
2960 return; 2969 return;
2961 } 2970 }
2962 2971
2963 msg = (const struct GNUNET_MessageHeader *)buf; 2972 msg = (const struct GNUNET_MessageHeader *) buf;
2964 LOG(GNUNET_ERROR_TYPE_DEBUG, 2973 LOG (GNUNET_ERROR_TYPE_DEBUG,
2965 "UDP received %u-byte message from `%s' type %u\n", 2974 "UDP received %u-byte message from `%s' type %u\n",
2966 (unsigned int)size, 2975 (unsigned int) size,
2967 GNUNET_a2s(sa, fromlen), 2976 GNUNET_a2s (sa, fromlen),
2968 ntohs(msg->type)); 2977 ntohs (msg->type));
2969 if (size != ntohs(msg->size)) 2978 if (size != ntohs (msg->size))
2970 { 2979 {
2971 LOG(GNUNET_ERROR_TYPE_WARNING, 2980 LOG (GNUNET_ERROR_TYPE_WARNING,
2972 "UDP malformed message (size %u) header from %s\n", 2981 "UDP malformed message (size %u) header from %s\n",
2973 (unsigned int)size, 2982 (unsigned int) size,
2974 GNUNET_a2s(sa, fromlen)); 2983 GNUNET_a2s (sa, fromlen));
2975 GNUNET_break_op(0); 2984 GNUNET_break_op (0);
2976 return; 2985 return;
2977 } 2986 }
2978 GNUNET_STATISTICS_update(plugin->env->stats, 2987 GNUNET_STATISTICS_update (plugin->env->stats,
2979 "# UDP, total bytes received", 2988 "# UDP, total bytes received",
2980 size, 2989 size,
2981 GNUNET_NO); 2990 GNUNET_NO);
2982 network_type = plugin->env->get_address_type(plugin->env->cls, sa, fromlen); 2991 network_type = plugin->env->get_address_type (plugin->env->cls, sa, fromlen);
2983 switch (sa->sa_family) 2992 switch (sa->sa_family)
2984 { 2993 {
2985 case AF_INET: 2994 case AF_INET:
2986 sa4 = (const struct sockaddr_in *)&addr; 2995 sa4 = (const struct sockaddr_in *) &addr;
2987 v4.options = 0; 2996 v4.options = 0;
2988 v4.ipv4_addr = sa4->sin_addr.s_addr; 2997 v4.ipv4_addr = sa4->sin_addr.s_addr;
2989 v4.u4_port = sa4->sin_port; 2998 v4.u4_port = sa4->sin_port;
2990 int_addr = (union UdpAddress *)&v4; 2999 int_addr = (union UdpAddress *) &v4;
2991 int_addr_len = sizeof(v4); 3000 int_addr_len = sizeof(v4);
2992 break; 3001 break;
2993 3002
2994 case AF_INET6: 3003 case AF_INET6:
2995 sa6 = (const struct sockaddr_in6 *)&addr; 3004 sa6 = (const struct sockaddr_in6 *) &addr;
2996 v6.options = 0; 3005 v6.options = 0;
2997 v6.ipv6_addr = sa6->sin6_addr; 3006 v6.ipv6_addr = sa6->sin6_addr;
2998 v6.u6_port = sa6->sin6_port; 3007 v6.u6_port = sa6->sin6_port;
2999 int_addr = (union UdpAddress *)&v6; 3008 int_addr = (union UdpAddress *) &v6;
3000 int_addr_len = sizeof(v6); 3009 int_addr_len = sizeof(v6);
3001 break; 3010 break;
3002 3011
3003 default: 3012 default:
3004 GNUNET_break(0); 3013 GNUNET_break (0);
3005 return; 3014 return;
3006 } 3015 }
3016
3017 switch (ntohs (msg->type))
3018 {
3019 case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON:
3020 if (GNUNET_YES == plugin->enable_broadcasting_receiving)
3021 udp_broadcast_receive (plugin,
3022 buf,
3023 size,
3024 int_addr,
3025 int_addr_len,
3026 network_type);
3027 return;
3007 3028
3008 switch (ntohs(msg->type)) 3029 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
3030 if (ntohs (msg->size) < sizeof(struct UDPMessage))
3009 { 3031 {
3010 case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON: 3032 GNUNET_break_op (0);
3011 if (GNUNET_YES == plugin->enable_broadcasting_receiving)
3012 udp_broadcast_receive(plugin,
3013 buf,
3014 size,
3015 int_addr,
3016 int_addr_len,
3017 network_type);
3018 return;
3019
3020 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
3021 if (ntohs(msg->size) < sizeof(struct UDPMessage))
3022 {
3023 GNUNET_break_op(0);
3024 return;
3025 }
3026 process_udp_message(plugin,
3027 (const struct UDPMessage *)msg,
3028 int_addr,
3029 int_addr_len,
3030 network_type);
3031 return; 3033 return;
3034 }
3035 process_udp_message (plugin,
3036 (const struct UDPMessage *) msg,
3037 int_addr,
3038 int_addr_len,
3039 network_type);
3040 return;
3032 3041
3033 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: 3042 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
3034 read_process_ack(plugin, msg, int_addr, int_addr_len); 3043 read_process_ack (plugin, msg, int_addr, int_addr_len);
3035 return; 3044 return;
3036 3045
3037 case GNUNET_MESSAGE_TYPE_FRAGMENT: 3046 case GNUNET_MESSAGE_TYPE_FRAGMENT:
3038 read_process_fragment(plugin, msg, int_addr, int_addr_len, network_type); 3047 read_process_fragment (plugin, msg, int_addr, int_addr_len, network_type);
3039 return; 3048 return;
3040 3049
3041 default: 3050 default:
3042 GNUNET_break_op(0); 3051 GNUNET_break_op (0);
3043 return; 3052 return;
3044 } 3053 }
3045} 3054}
3046 3055
3047 3056
@@ -3055,8 +3064,8 @@ udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
3055 * @return message selected for transmission, or NULL for none 3064 * @return message selected for transmission, or NULL for none
3056 */ 3065 */
3057static struct UDP_MessageWrapper * 3066static struct UDP_MessageWrapper *
3058remove_timeout_messages_and_select(struct Plugin *plugin, 3067remove_timeout_messages_and_select (struct Plugin *plugin,
3059 struct GNUNET_NETWORK_Handle *sock) 3068 struct GNUNET_NETWORK_Handle *sock)
3060{ 3069{
3061 struct UDP_MessageWrapper *udpw; 3070 struct UDP_MessageWrapper *udpw;
3062 struct GNUNET_TIME_Relative remaining; 3071 struct GNUNET_TIME_Relative remaining;
@@ -3067,65 +3076,65 @@ remove_timeout_messages_and_select(struct Plugin *plugin,
3067 udpw = (sock == plugin->sockv4) ? plugin->ipv4_queue_head 3076 udpw = (sock == plugin->sockv4) ? plugin->ipv4_queue_head
3068 : plugin->ipv6_queue_head; 3077 : plugin->ipv6_queue_head;
3069 while (NULL != udpw) 3078 while (NULL != udpw)
3070 { 3079 {
3071 session = udpw->session; 3080 session = udpw->session;
3072 /* Find messages with timeout */ 3081 /* Find messages with timeout */
3073 remaining = GNUNET_TIME_absolute_get_remaining(udpw->timeout); 3082 remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout);
3074 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) 3083 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us)
3075 { 3084 {
3076 /* Message timed out */ 3085 /* Message timed out */
3077 removed = GNUNET_YES; 3086 removed = GNUNET_YES;
3078 dequeue(plugin, udpw); 3087 dequeue (plugin, udpw);
3079 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); 3088 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
3080 GNUNET_free(udpw); 3089 GNUNET_free (udpw);
3081 3090
3082 if (sock == plugin->sockv4) 3091 if (sock == plugin->sockv4)
3083 { 3092 {
3084 udpw = plugin->ipv4_queue_head; 3093 udpw = plugin->ipv4_queue_head;
3085 } 3094 }
3086 else if (sock == plugin->sockv6) 3095 else if (sock == plugin->sockv6)
3087 { 3096 {
3088 udpw = plugin->ipv6_queue_head; 3097 udpw = plugin->ipv6_queue_head;
3089 } 3098 }
3090 else
3091 {
3092 GNUNET_break(0); /* should never happen */
3093 udpw = NULL;
3094 }
3095 GNUNET_STATISTICS_update(plugin->env->stats,
3096 "# messages discarded due to timeout",
3097 1,
3098 GNUNET_NO);
3099 }
3100 else 3099 else
3101 { 3100 {
3102 /* Message did not time out, check transmission time */ 3101 GNUNET_break (0); /* should never happen */
3103 remaining = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time); 3102 udpw = NULL;
3104 if (0 == remaining.rel_value_us) 3103 }
3105 { 3104 GNUNET_STATISTICS_update (plugin->env->stats,
3106 /* this message is not delayed */ 3105 "# messages discarded due to timeout",
3107 LOG(GNUNET_ERROR_TYPE_DEBUG, 3106 1,
3108 "Message for peer `%s' (%u bytes) is not delayed \n", 3107 GNUNET_NO);
3109 GNUNET_i2s(&udpw->session->target), 3108 }
3110 udpw->payload_size); 3109 else
3111 break; /* Found message to send, break */ 3110 {
3112 } 3111 /* Message did not time out, check transmission time */
3113 else 3112 remaining = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time);
3114 { 3113 if (0 == remaining.rel_value_us)
3115 /* Message is delayed, try next */ 3114 {
3116 LOG(GNUNET_ERROR_TYPE_DEBUG, 3115 /* this message is not delayed */
3117 "Message for peer `%s' (%u bytes) is delayed for %s\n", 3116 LOG (GNUNET_ERROR_TYPE_DEBUG,
3118 GNUNET_i2s(&udpw->session->target), 3117 "Message for peer `%s' (%u bytes) is not delayed \n",
3119 udpw->payload_size, 3118 GNUNET_i2s (&udpw->session->target),
3120 GNUNET_STRINGS_relative_time_to_string(remaining, GNUNET_YES)); 3119 udpw->payload_size);
3121 udpw = udpw->next; 3120 break; /* Found message to send, break */
3122 } 3121 }
3123 } 3122 else
3124 } 3123 {
3124 /* Message is delayed, try next */
3125 LOG (GNUNET_ERROR_TYPE_DEBUG,
3126 "Message for peer `%s' (%u bytes) is delayed for %s\n",
3127 GNUNET_i2s (&udpw->session->target),
3128 udpw->payload_size,
3129 GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES));
3130 udpw = udpw->next;
3131 }
3132 }
3133 }
3125 if (GNUNET_YES == removed) 3134 if (GNUNET_YES == removed)
3126 notify_session_monitor(session->plugin, 3135 notify_session_monitor (session->plugin,
3127 session, 3136 session,
3128 GNUNET_TRANSPORT_SS_UPDATE); 3137 GNUNET_TRANSPORT_SS_UPDATE);
3129 return udpw; 3138 return udpw;
3130} 3139}
3131 3140
@@ -3140,50 +3149,50 @@ remove_timeout_messages_and_select(struct Plugin *plugin,
3140 * @param error the errno value returned from the sendto() call 3149 * @param error the errno value returned from the sendto() call
3141 */ 3150 */
3142static void 3151static void
3143analyze_send_error(struct Plugin *plugin, 3152analyze_send_error (struct Plugin *plugin,
3144 const struct sockaddr *sa, 3153 const struct sockaddr *sa,
3145 socklen_t slen, 3154 socklen_t slen,
3146 int error) 3155 int error)
3147{ 3156{
3148 enum GNUNET_NetworkType type; 3157 enum GNUNET_NetworkType type;
3149 3158
3150 type = plugin->env->get_address_type(plugin->env->cls, sa, slen); 3159 type = plugin->env->get_address_type (plugin->env->cls, sa, slen);
3151 if (((GNUNET_NT_LAN == type) || (GNUNET_NT_WAN == type)) && 3160 if (((GNUNET_NT_LAN == type) || (GNUNET_NT_WAN == type)) &&
3152 ((ENETUNREACH == errno) || (ENETDOWN == errno))) 3161 ((ENETUNREACH == errno) || (ENETDOWN == errno)))
3153 { 3162 {
3154 if (slen == sizeof(struct sockaddr_in)) 3163 if (slen == sizeof(struct sockaddr_in))
3155 { 3164 {
3156 /* IPv4: "Network unreachable" or "Network down" 3165 /* IPv4: "Network unreachable" or "Network down"
3157 * 3166 *
3158 * This indicates we do not have connectivity 3167 * This indicates we do not have connectivity
3159 */ 3168 */
3160 LOG(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 3169 LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
3161 _("UDP could not transmit message to `%s': " 3170 _ ("UDP could not transmit message to `%s': "
3162 "Network seems down, please check your network configuration\n"), 3171 "Network seems down, please check your network configuration\n"),
3163 GNUNET_a2s(sa, slen)); 3172 GNUNET_a2s (sa, slen));
3164 } 3173 }
3165 if (slen == sizeof(struct sockaddr_in6)) 3174 if (slen == sizeof(struct sockaddr_in6))
3166 { 3175 {
3167 /* IPv6: "Network unreachable" or "Network down" 3176 /* IPv6: "Network unreachable" or "Network down"
3168 * 3177 *
3169 * This indicates that this system is IPv6 enabled, but does not 3178 * This indicates that this system is IPv6 enabled, but does not
3170 * have a valid global IPv6 address assigned or we do not have 3179 * have a valid global IPv6 address assigned or we do not have
3171 * connectivity 3180 * connectivity
3172 */ 3181 */
3173 LOG(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 3182 LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
3174 _( 3183 _ (
3175 "UDP could not transmit IPv6 message! " 3184 "UDP could not transmit IPv6 message! "
3176 "Please check your network configuration and disable IPv6 if your " 3185 "Please check your network configuration and disable IPv6 if your "
3177 "connection does not have a global IPv6 address\n")); 3186 "connection does not have a global IPv6 address\n"));
3178 } 3187 }
3179 } 3188 }
3180 else 3189 else
3181 { 3190 {
3182 LOG(GNUNET_ERROR_TYPE_WARNING, 3191 LOG (GNUNET_ERROR_TYPE_WARNING,
3183 "UDP could not transmit message to `%s': `%s'\n", 3192 "UDP could not transmit message to `%s': `%s'\n",
3184 GNUNET_a2s(sa, slen), 3193 GNUNET_a2s (sa, slen),
3185 strerror(error)); 3194 strerror (error));
3186 } 3195 }
3187} 3196}
3188 3197
3189 3198
@@ -3195,7 +3204,7 @@ analyze_send_error(struct Plugin *plugin,
3195 * @param sock which socket (v4/v6) to send on 3204 * @param sock which socket (v4/v6) to send on
3196 */ 3205 */
3197static void 3206static void
3198udp_select_send(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) 3207udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
3199{ 3208{
3200 ssize_t sent; 3209 ssize_t sent;
3201 socklen_t slen; 3210 socklen_t slen;
@@ -3207,95 +3216,95 @@ udp_select_send(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
3207 struct UDP_MessageWrapper *udpw; 3216 struct UDP_MessageWrapper *udpw;
3208 3217
3209 /* Find message(s) to send */ 3218 /* Find message(s) to send */
3210 while (NULL != (udpw = remove_timeout_messages_and_select(plugin, sock))) 3219 while (NULL != (udpw = remove_timeout_messages_and_select (plugin, sock)))
3220 {
3221 if (sizeof(struct IPv4UdpAddress) ==
3222 udpw->session->address->address_length)
3211 { 3223 {
3212 if (sizeof(struct IPv4UdpAddress) == 3224 u4 = udpw->session->address->address;
3213 udpw->session->address->address_length) 3225 memset (&a4, 0, sizeof(a4));
3214 { 3226 a4.sin_family = AF_INET;
3215 u4 = udpw->session->address->address;
3216 memset(&a4, 0, sizeof(a4));
3217 a4.sin_family = AF_INET;
3218#if HAVE_SOCKADDR_IN_SIN_LEN 3227#if HAVE_SOCKADDR_IN_SIN_LEN
3219 a4.sin_len = sizeof(a4); 3228 a4.sin_len = sizeof(a4);
3220#endif 3229#endif
3221 a4.sin_port = u4->u4_port; 3230 a4.sin_port = u4->u4_port;
3222 a4.sin_addr.s_addr = u4->ipv4_addr; 3231 a4.sin_addr.s_addr = u4->ipv4_addr;
3223 a = (const struct sockaddr *)&a4; 3232 a = (const struct sockaddr *) &a4;
3224 slen = sizeof(a4); 3233 slen = sizeof(a4);
3225 } 3234 }
3226 else if (sizeof(struct IPv6UdpAddress) == 3235 else if (sizeof(struct IPv6UdpAddress) ==
3227 udpw->session->address->address_length) 3236 udpw->session->address->address_length)
3228 { 3237 {
3229 u6 = udpw->session->address->address; 3238 u6 = udpw->session->address->address;
3230 memset(&a6, 0, sizeof(a6)); 3239 memset (&a6, 0, sizeof(a6));
3231 a6.sin6_family = AF_INET6; 3240 a6.sin6_family = AF_INET6;
3232#if HAVE_SOCKADDR_IN_SIN_LEN 3241#if HAVE_SOCKADDR_IN_SIN_LEN
3233 a6.sin6_len = sizeof(a6); 3242 a6.sin6_len = sizeof(a6);
3234#endif 3243#endif
3235 a6.sin6_port = u6->u6_port; 3244 a6.sin6_port = u6->u6_port;
3236 a6.sin6_addr = u6->ipv6_addr; 3245 a6.sin6_addr = u6->ipv6_addr;
3237 a = (const struct sockaddr *)&a6; 3246 a = (const struct sockaddr *) &a6;
3238 slen = sizeof(a6); 3247 slen = sizeof(a6);
3239 } 3248 }
3240 else 3249 else
3241 { 3250 {
3242 GNUNET_break(0); 3251 GNUNET_break (0);
3243 dequeue(plugin, udpw); 3252 dequeue (plugin, udpw);
3244 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); 3253 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
3245 notify_session_monitor(plugin, 3254 notify_session_monitor (plugin,
3246 udpw->session, 3255 udpw->session,
3247 GNUNET_TRANSPORT_SS_UPDATE); 3256 GNUNET_TRANSPORT_SS_UPDATE);
3248 GNUNET_free(udpw); 3257 GNUNET_free (udpw);
3249 continue; 3258 continue;
3250 } 3259 }
3251 sent = GNUNET_NETWORK_socket_sendto(sock, 3260 sent = GNUNET_NETWORK_socket_sendto (sock,
3252 udpw->msg_buf, 3261 udpw->msg_buf,
3253 udpw->msg_size, 3262 udpw->msg_size,
3254 a, 3263 a,
3255 slen); 3264 slen);
3256 udpw->session->last_transmit_time = 3265 udpw->session->last_transmit_time =
3257 GNUNET_TIME_absolute_max(GNUNET_TIME_absolute_get(), 3266 GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (),
3258 udpw->session->last_transmit_time); 3267 udpw->session->last_transmit_time);
3259 dequeue(plugin, udpw); 3268 dequeue (plugin, udpw);
3260 if (GNUNET_SYSERR == sent) 3269 if (GNUNET_SYSERR == sent)
3261 { 3270 {
3262 /* Failure */ 3271 /* Failure */
3263 analyze_send_error(plugin, a, slen, errno); 3272 analyze_send_error (plugin, a, slen, errno);
3264 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); 3273 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
3265 GNUNET_STATISTICS_update(plugin->env->stats, 3274 GNUNET_STATISTICS_update (plugin->env->stats,
3266 "# UDP, total, bytes, sent, failure", 3275 "# UDP, total, bytes, sent, failure",
3267 sent, 3276 sent,
3268 GNUNET_NO); 3277 GNUNET_NO);
3269 GNUNET_STATISTICS_update(plugin->env->stats, 3278 GNUNET_STATISTICS_update (plugin->env->stats,
3270 "# UDP, total, messages, sent, failure", 3279 "# UDP, total, messages, sent, failure",
3271 1, 3280 1,
3272 GNUNET_NO); 3281 GNUNET_NO);
3273 } 3282 }
3274 else 3283 else
3275 { 3284 {
3276 /* Success */ 3285 /* Success */
3277 LOG(GNUNET_ERROR_TYPE_DEBUG, 3286 LOG (GNUNET_ERROR_TYPE_DEBUG,
3278 "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", 3287 "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n",
3279 (unsigned int)(udpw->msg_size), 3288 (unsigned int) (udpw->msg_size),
3280 GNUNET_i2s(&udpw->session->target), 3289 GNUNET_i2s (&udpw->session->target),
3281 GNUNET_a2s(a, slen), 3290 GNUNET_a2s (a, slen),
3282 (int)sent, 3291 (int) sent,
3283 (sent < 0) ? strerror(errno) : "ok"); 3292 (sent < 0) ? strerror (errno) : "ok");
3284 GNUNET_STATISTICS_update(plugin->env->stats, 3293 GNUNET_STATISTICS_update (plugin->env->stats,
3285 "# UDP, total, bytes, sent, success", 3294 "# UDP, total, bytes, sent, success",
3286 sent, 3295 sent,
3287 GNUNET_NO); 3296 GNUNET_NO);
3288 GNUNET_STATISTICS_update(plugin->env->stats, 3297 GNUNET_STATISTICS_update (plugin->env->stats,
3289 "# UDP, total, messages, sent, success", 3298 "# UDP, total, messages, sent, success",
3290 1, 3299 1,
3291 GNUNET_NO); 3300 GNUNET_NO);
3292 if (NULL != udpw->frag_ctx) 3301 if (NULL != udpw->frag_ctx)
3293 udpw->frag_ctx->on_wire_size += udpw->msg_size; 3302 udpw->frag_ctx->on_wire_size += udpw->msg_size;
3294 udpw->qc(udpw->qc_cls, udpw, GNUNET_OK); 3303 udpw->qc (udpw->qc_cls, udpw, GNUNET_OK);
3295 } 3304 }
3296 notify_session_monitor(plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE); 3305 notify_session_monitor (plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE);
3297 GNUNET_free(udpw); 3306 GNUNET_free (udpw);
3298 } 3307 }
3299} 3308}
3300 3309
3301 3310
@@ -3310,7 +3319,7 @@ udp_select_send(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
3310 * @param cls the plugin handle 3319 * @param cls the plugin handle
3311 */ 3320 */
3312static void 3321static void
3313udp_plugin_select_v4(void *cls) 3322udp_plugin_select_v4 (void *cls)
3314{ 3323{
3315 struct Plugin *plugin = cls; 3324 struct Plugin *plugin = cls;
3316 const struct GNUNET_SCHEDULER_TaskContext *tc; 3325 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -3318,12 +3327,12 @@ udp_plugin_select_v4(void *cls)
3318 plugin->select_task_v4 = NULL; 3327 plugin->select_task_v4 = NULL;
3319 if (NULL == plugin->sockv4) 3328 if (NULL == plugin->sockv4)
3320 return; 3329 return;
3321 tc = GNUNET_SCHEDULER_get_task_context(); 3330 tc = GNUNET_SCHEDULER_get_task_context ();
3322 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 3331 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3323 (GNUNET_NETWORK_fdset_isset(tc->read_ready, plugin->sockv4))) 3332 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)))
3324 udp_select_read(plugin, plugin->sockv4); 3333 udp_select_read (plugin, plugin->sockv4);
3325 udp_select_send(plugin, plugin->sockv4); 3334 udp_select_send (plugin, plugin->sockv4);
3326 schedule_select_v4(plugin); 3335 schedule_select_v4 (plugin);
3327} 3336}
3328 3337
3329 3338
@@ -3335,7 +3344,7 @@ udp_plugin_select_v4(void *cls)
3335 * @param cls the plugin handle 3344 * @param cls the plugin handle
3336 */ 3345 */
3337static void 3346static void
3338udp_plugin_select_v6(void *cls) 3347udp_plugin_select_v6 (void *cls)
3339{ 3348{
3340 struct Plugin *plugin = cls; 3349 struct Plugin *plugin = cls;
3341 const struct GNUNET_SCHEDULER_TaskContext *tc; 3350 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -3343,13 +3352,13 @@ udp_plugin_select_v6(void *cls)
3343 plugin->select_task_v6 = NULL; 3352 plugin->select_task_v6 = NULL;
3344 if (NULL == plugin->sockv6) 3353 if (NULL == plugin->sockv6)
3345 return; 3354 return;
3346 tc = GNUNET_SCHEDULER_get_task_context(); 3355 tc = GNUNET_SCHEDULER_get_task_context ();
3347 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 3356 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3348 (GNUNET_NETWORK_fdset_isset(tc->read_ready, plugin->sockv6))) 3357 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)))
3349 udp_select_read(plugin, plugin->sockv6); 3358 udp_select_read (plugin, plugin->sockv6);
3350 3359
3351 udp_select_send(plugin, plugin->sockv6); 3360 udp_select_send (plugin, plugin->sockv6);
3352 schedule_select_v6(plugin); 3361 schedule_select_v6 (plugin);
3353} 3362}
3354 3363
3355 3364
@@ -3365,9 +3374,9 @@ udp_plugin_select_v6(void *cls)
3365 * @return number of sockets that were successfully bound 3374 * @return number of sockets that were successfully bound
3366 */ 3375 */
3367static unsigned int 3376static unsigned int
3368setup_sockets(struct Plugin *plugin, 3377setup_sockets (struct Plugin *plugin,
3369 const struct sockaddr_in6 *bind_v6, 3378 const struct sockaddr_in6 *bind_v6,
3370 const struct sockaddr_in *bind_v4) 3379 const struct sockaddr_in *bind_v4)
3371{ 3380{
3372 int tries; 3381 int tries;
3373 unsigned int sockets_created = 0; 3382 unsigned int sockets_created = 0;
@@ -3382,186 +3391,186 @@ setup_sockets(struct Plugin *plugin,
3382 /* Create IPv6 socket */ 3391 /* Create IPv6 socket */
3383 eno = EINVAL; 3392 eno = EINVAL;
3384 if (GNUNET_YES == plugin->enable_ipv6) 3393 if (GNUNET_YES == plugin->enable_ipv6)
3394 {
3395 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
3396 if (NULL == plugin->sockv6)
3385 { 3397 {
3386 plugin->sockv6 = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_DGRAM, 0); 3398 LOG (GNUNET_ERROR_TYPE_INFO,
3387 if (NULL == plugin->sockv6) 3399 _ ("Disabling IPv6 since it is not supported on this system!\n"));
3388 { 3400 plugin->enable_ipv6 = GNUNET_NO;
3389 LOG(GNUNET_ERROR_TYPE_INFO,
3390 _("Disabling IPv6 since it is not supported on this system!\n"));
3391 plugin->enable_ipv6 = GNUNET_NO;
3392 }
3393 else
3394 {
3395 memset(&server_addrv6, 0, sizeof(struct sockaddr_in6));
3396#if HAVE_SOCKADDR_IN_SIN_LEN
3397 server_addrv6.sin6_len = sizeof(struct sockaddr_in6);
3398#endif
3399 server_addrv6.sin6_family = AF_INET6;
3400 if (NULL != bind_v6)
3401 server_addrv6.sin6_addr = bind_v6->sin6_addr;
3402 else
3403 server_addrv6.sin6_addr = in6addr_any;
3404
3405 if (0 == plugin->port) /* autodetect */
3406 server_addrv6.sin6_port = htons(
3407 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
3408 32000);
3409 else
3410 server_addrv6.sin6_port = htons(plugin->port);
3411 addrlen = sizeof(struct sockaddr_in6);
3412 server_addr = (const struct sockaddr *)&server_addrv6;
3413
3414 tries = 0;
3415 while (tries < 10)
3416 {
3417 LOG(GNUNET_ERROR_TYPE_DEBUG,
3418 "Binding to IPv6 `%s'\n",
3419 GNUNET_a2s(server_addr, addrlen));
3420 /* binding */
3421 if (GNUNET_OK ==
3422 GNUNET_NETWORK_socket_bind(plugin->sockv6, server_addr, addrlen))
3423 break;
3424 eno = errno;
3425 if (0 != plugin->port)
3426 {
3427 tries = 10; /* fail immediately */
3428 break; /* bind failed on specific port */
3429 }
3430 /* autodetect */
3431 server_addrv6.sin6_port = htons(
3432 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
3433 32000);
3434 tries++;
3435 }
3436 if (tries >= 10)
3437 {
3438 GNUNET_NETWORK_socket_close(plugin->sockv6);
3439 plugin->enable_ipv6 = GNUNET_NO;
3440 plugin->sockv6 = NULL;
3441 }
3442 else
3443 {
3444 plugin->port = ntohs(server_addrv6.sin6_port);
3445 }
3446 if (NULL != plugin->sockv6)
3447 {
3448 LOG(GNUNET_ERROR_TYPE_DEBUG,
3449 "IPv6 UDP socket created listinging at %s\n",
3450 GNUNET_a2s(server_addr, addrlen));
3451 addrs[sockets_created] = server_addr;
3452 addrlens[sockets_created] = addrlen;
3453 sockets_created++;
3454 }
3455 else
3456 {
3457 LOG(GNUNET_ERROR_TYPE_WARNING,
3458 _("Failed to bind UDP socket to %s: %s\n"),
3459 GNUNET_a2s(server_addr, addrlen),
3460 strerror(eno));
3461 }
3462 }
3463 }
3464
3465 /* Create IPv4 socket */
3466 eno = EINVAL;
3467 plugin->sockv4 = GNUNET_NETWORK_socket_create(PF_INET, SOCK_DGRAM, 0);
3468 if (NULL == plugin->sockv4)
3469 {
3470 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "socket");
3471 LOG(GNUNET_ERROR_TYPE_INFO,
3472 _("Disabling IPv4 since it is not supported on this system!\n"));
3473 plugin->enable_ipv4 = GNUNET_NO;
3474 } 3401 }
3475 else 3402 else
3476 { 3403 {
3477 memset(&server_addrv4, 0, sizeof(struct sockaddr_in)); 3404 memset (&server_addrv6, 0, sizeof(struct sockaddr_in6));
3478#if HAVE_SOCKADDR_IN_SIN_LEN 3405#if HAVE_SOCKADDR_IN_SIN_LEN
3479 server_addrv4.sin_len = sizeof(struct sockaddr_in); 3406 server_addrv6.sin6_len = sizeof(struct sockaddr_in6);
3480#endif 3407#endif
3481 server_addrv4.sin_family = AF_INET; 3408 server_addrv6.sin6_family = AF_INET6;
3482 if (NULL != bind_v4) 3409 if (NULL != bind_v6)
3483 server_addrv4.sin_addr = bind_v4->sin_addr; 3410 server_addrv6.sin6_addr = bind_v6->sin6_addr;
3484 else 3411 else
3485 server_addrv4.sin_addr.s_addr = INADDR_ANY; 3412 server_addrv6.sin6_addr = in6addr_any;
3486 3413
3487 if (0 == plugin->port) 3414 if (0 == plugin->port) /* autodetect */
3488 /* autodetect */ 3415 server_addrv6.sin6_port = htons (
3489 server_addrv4.sin_port = htons( 3416 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537)
3490 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); 3417 + 32000);
3491 else 3418 else
3492 server_addrv4.sin_port = htons(plugin->port); 3419 server_addrv6.sin6_port = htons (plugin->port);
3493 3420 addrlen = sizeof(struct sockaddr_in6);
3494 addrlen = sizeof(struct sockaddr_in); 3421 server_addr = (const struct sockaddr *) &server_addrv6;
3495 server_addr = (const struct sockaddr *)&server_addrv4;
3496 3422
3497 tries = 0; 3423 tries = 0;
3498 while (tries < 10) 3424 while (tries < 10)
3425 {
3426 LOG (GNUNET_ERROR_TYPE_DEBUG,
3427 "Binding to IPv6 `%s'\n",
3428 GNUNET_a2s (server_addr, addrlen));
3429 /* binding */
3430 if (GNUNET_OK ==
3431 GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, addrlen))
3432 break;
3433 eno = errno;
3434 if (0 != plugin->port)
3499 { 3435 {
3500 LOG(GNUNET_ERROR_TYPE_DEBUG, 3436 tries = 10; /* fail immediately */
3501 "Binding to IPv4 `%s'\n", 3437 break; /* bind failed on specific port */
3502 GNUNET_a2s(server_addr, addrlen));
3503
3504 /* binding */
3505 if (GNUNET_OK ==
3506 GNUNET_NETWORK_socket_bind(plugin->sockv4, server_addr, addrlen))
3507 break;
3508 eno = errno;
3509 if (0 != plugin->port)
3510 {
3511 tries = 10; /* fail */
3512 break; /* bind failed on specific port */
3513 }
3514
3515 /* autodetect */
3516 server_addrv4.sin_port = htons(
3517 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3518 tries++;
3519 } 3438 }
3439 /* autodetect */
3440 server_addrv6.sin6_port = htons (
3441 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537)
3442 + 32000);
3443 tries++;
3444 }
3520 if (tries >= 10) 3445 if (tries >= 10)
3521 { 3446 {
3522 GNUNET_NETWORK_socket_close(plugin->sockv4); 3447 GNUNET_NETWORK_socket_close (plugin->sockv6);
3523 plugin->enable_ipv4 = GNUNET_NO; 3448 plugin->enable_ipv6 = GNUNET_NO;
3524 plugin->sockv4 = NULL; 3449 plugin->sockv6 = NULL;
3525 } 3450 }
3526 else 3451 else
3527 { 3452 {
3528 plugin->port = ntohs(server_addrv4.sin_port); 3453 plugin->port = ntohs (server_addrv6.sin6_port);
3529 } 3454 }
3530 3455 if (NULL != plugin->sockv6)
3531 if (NULL != plugin->sockv4) 3456 {
3532 { 3457 LOG (GNUNET_ERROR_TYPE_DEBUG,
3533 LOG(GNUNET_ERROR_TYPE_DEBUG, 3458 "IPv6 UDP socket created listinging at %s\n",
3534 "IPv4 socket created on port %s\n", 3459 GNUNET_a2s (server_addr, addrlen));
3535 GNUNET_a2s(server_addr, addrlen)); 3460 addrs[sockets_created] = server_addr;
3536 addrs[sockets_created] = server_addr; 3461 addrlens[sockets_created] = addrlen;
3537 addrlens[sockets_created] = addrlen; 3462 sockets_created++;
3538 sockets_created++; 3463 }
3539 }
3540 else 3464 else
3541 { 3465 {
3542 LOG(GNUNET_ERROR_TYPE_ERROR, 3466 LOG (GNUNET_ERROR_TYPE_WARNING,
3543 _("Failed to bind UDP socket to %s: %s\n"), 3467 _ ("Failed to bind UDP socket to %s: %s\n"),
3544 GNUNET_a2s(server_addr, addrlen), 3468 GNUNET_a2s (server_addr, addrlen),
3545 strerror(eno)); 3469 strerror (eno));
3546 } 3470 }
3547 } 3471 }
3472 }
3548 3473
3549 if (0 == sockets_created) 3474 /* Create IPv4 socket */
3475 eno = EINVAL;
3476 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
3477 if (NULL == plugin->sockv4)
3478 {
3479 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
3480 LOG (GNUNET_ERROR_TYPE_INFO,
3481 _ ("Disabling IPv4 since it is not supported on this system!\n"));
3482 plugin->enable_ipv4 = GNUNET_NO;
3483 }
3484 else
3485 {
3486 memset (&server_addrv4, 0, sizeof(struct sockaddr_in));
3487#if HAVE_SOCKADDR_IN_SIN_LEN
3488 server_addrv4.sin_len = sizeof(struct sockaddr_in);
3489#endif
3490 server_addrv4.sin_family = AF_INET;
3491 if (NULL != bind_v4)
3492 server_addrv4.sin_addr = bind_v4->sin_addr;
3493 else
3494 server_addrv4.sin_addr.s_addr = INADDR_ANY;
3495
3496 if (0 == plugin->port)
3497 /* autodetect */
3498 server_addrv4.sin_port = htons (
3499 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3500 else
3501 server_addrv4.sin_port = htons (plugin->port);
3502
3503 addrlen = sizeof(struct sockaddr_in);
3504 server_addr = (const struct sockaddr *) &server_addrv4;
3505
3506 tries = 0;
3507 while (tries < 10)
3508 {
3509 LOG (GNUNET_ERROR_TYPE_DEBUG,
3510 "Binding to IPv4 `%s'\n",
3511 GNUNET_a2s (server_addr, addrlen));
3512
3513 /* binding */
3514 if (GNUNET_OK ==
3515 GNUNET_NETWORK_socket_bind (plugin->sockv4, server_addr, addrlen))
3516 break;
3517 eno = errno;
3518 if (0 != plugin->port)
3519 {
3520 tries = 10; /* fail */
3521 break; /* bind failed on specific port */
3522 }
3523
3524 /* autodetect */
3525 server_addrv4.sin_port = htons (
3526 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3527 tries++;
3528 }
3529 if (tries >= 10)
3530 {
3531 GNUNET_NETWORK_socket_close (plugin->sockv4);
3532 plugin->enable_ipv4 = GNUNET_NO;
3533 plugin->sockv4 = NULL;
3534 }
3535 else
3550 { 3536 {
3551 LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); 3537 plugin->port = ntohs (server_addrv4.sin_port);
3552 return 0; /* No sockets created, return */
3553 } 3538 }
3554 schedule_select_v4(plugin); 3539
3555 schedule_select_v6(plugin); 3540 if (NULL != plugin->sockv4)
3556 plugin->nat = GNUNET_NAT_register(plugin->env->cfg, 3541 {
3557 "transport-udp", 3542 LOG (GNUNET_ERROR_TYPE_DEBUG,
3558 IPPROTO_UDP, 3543 "IPv4 socket created on port %s\n",
3559 sockets_created, 3544 GNUNET_a2s (server_addr, addrlen));
3560 addrs, 3545 addrs[sockets_created] = server_addr;
3561 addrlens, 3546 addrlens[sockets_created] = addrlen;
3562 &udp_nat_port_map_callback, 3547 sockets_created++;
3563 NULL, 3548 }
3564 plugin); 3549 else
3550 {
3551 LOG (GNUNET_ERROR_TYPE_ERROR,
3552 _ ("Failed to bind UDP socket to %s: %s\n"),
3553 GNUNET_a2s (server_addr, addrlen),
3554 strerror (eno));
3555 }
3556 }
3557
3558 if (0 == sockets_created)
3559 {
3560 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UDP sockets\n"));
3561 return 0; /* No sockets created, return */
3562 }
3563 schedule_select_v4 (plugin);
3564 schedule_select_v6 (plugin);
3565 plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
3566 "transport-udp",
3567 IPPROTO_UDP,
3568 sockets_created,
3569 addrs,
3570 addrlens,
3571 &udp_nat_port_map_callback,
3572 NULL,
3573 plugin);
3565 return sockets_created; 3574 return sockets_created;
3566} 3575}
3567 3576
@@ -3574,7 +3583,7 @@ setup_sockets(struct Plugin *plugin,
3574 * @return our `struct GNUNET_TRANSPORT_PluginFunctions` 3583 * @return our `struct GNUNET_TRANSPORT_PluginFunctions`
3575 */ 3584 */
3576void * 3585void *
3577libgnunet_plugin_transport_udp_init(void *cls) 3586libgnunet_plugin_transport_udp_init (void *cls)
3578{ 3587{
3579 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 3588 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3580 struct GNUNET_TRANSPORT_PluginFunctions *api; 3589 struct GNUNET_TRANSPORT_PluginFunctions *api;
@@ -3595,128 +3604,128 @@ libgnunet_plugin_transport_udp_init(void *cls)
3595 int have_bind6; 3604 int have_bind6;
3596 3605
3597 if (NULL == env->receive) 3606 if (NULL == env->receive)
3598 { 3607 {
3599 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 3608 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
3600 initialze the plugin or the API */ 3609 initialze the plugin or the API */
3601 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 3610 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
3602 api->cls = NULL; 3611 api->cls = NULL;
3603 api->address_pretty_printer = &udp_plugin_address_pretty_printer; 3612 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
3604 api->address_to_string = &udp_address_to_string; 3613 api->address_to_string = &udp_address_to_string;
3605 api->string_to_address = &udp_string_to_address; 3614 api->string_to_address = &udp_string_to_address;
3606 return api; 3615 return api;
3607 } 3616 }
3608 3617
3609 /* Get port number: port == 0 : autodetect a port, 3618 /* Get port number: port == 0 : autodetect a port,
3610 * > 0 : use this port, not given : 2086 default */ 3619 * > 0 : use this port, not given : 2086 default */
3611 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, 3620 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
3612 "transport-udp", 3621 "transport-udp",
3613 "PORT", 3622 "PORT",
3614 &port)) 3623 &port))
3615 port = 2086; 3624 port = 2086;
3616 if (port > 65535) 3625 if (port > 65535)
3617 { 3626 {
3618 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, 3627 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3619 "transport-udp", 3628 "transport-udp",
3620 "PORT", 3629 "PORT",
3621 _("must be in [0,65535]")); 3630 _ ("must be in [0,65535]"));
3622 return NULL; 3631 return NULL;
3623 } 3632 }
3624 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, 3633 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
3625 "transport-udp", 3634 "transport-udp",
3626 "ADVERTISED_PORT", 3635 "ADVERTISED_PORT",
3627 &aport)) 3636 &aport))
3628 aport = port; 3637 aport = port;
3629 if (aport > 65535) 3638 if (aport > 65535)
3630 { 3639 {
3631 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, 3640 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3632 "transport-udp", 3641 "transport-udp",
3633 "ADVERTISED_PORT", 3642 "ADVERTISED_PORT",
3634 _("must be in [0,65535]")); 3643 _ ("must be in [0,65535]"));
3635 return NULL; 3644 return NULL;
3636 } 3645 }
3637 3646
3638 if (GNUNET_YES == 3647 if (GNUNET_YES ==
3639 GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "nat", "DISABLEV6")) 3648 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6"))
3640 enable_v6 = GNUNET_NO; 3649 enable_v6 = GNUNET_NO;
3641 else 3650 else
3642 enable_v6 = GNUNET_YES; 3651 enable_v6 = GNUNET_YES;
3643 3652
3644 have_bind4 = GNUNET_NO; 3653 have_bind4 = GNUNET_NO;
3645 memset(&server_addrv4, 0, sizeof(server_addrv4)); 3654 memset (&server_addrv4, 0, sizeof(server_addrv4));
3646 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg, 3655 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg,
3647 "transport-udp", 3656 "transport-udp",
3648 "BINDTO", 3657 "BINDTO",
3649 &bind4_address)) 3658 &bind4_address))
3650 { 3659 {
3651 LOG(GNUNET_ERROR_TYPE_DEBUG, 3660 LOG (GNUNET_ERROR_TYPE_DEBUG,
3652 "Binding UDP plugin to specific address: `%s'\n", 3661 "Binding UDP plugin to specific address: `%s'\n",
3653 bind4_address); 3662 bind4_address);
3654 if (1 != inet_pton(AF_INET, bind4_address, &server_addrv4.sin_addr)) 3663 if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr))
3655 { 3664 {
3656 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, 3665 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3657 "transport-udp", 3666 "transport-udp",
3658 "BINDTO", 3667 "BINDTO",
3659 _("must be valid IPv4 address")); 3668 _ ("must be valid IPv4 address"));
3660 GNUNET_free(bind4_address); 3669 GNUNET_free (bind4_address);
3661 return NULL; 3670 return NULL;
3662 }
3663 have_bind4 = GNUNET_YES;
3664 } 3671 }
3665 GNUNET_free_non_null(bind4_address); 3672 have_bind4 = GNUNET_YES;
3673 }
3674 GNUNET_free_non_null (bind4_address);
3666 have_bind6 = GNUNET_NO; 3675 have_bind6 = GNUNET_NO;
3667 memset(&server_addrv6, 0, sizeof(server_addrv6)); 3676 memset (&server_addrv6, 0, sizeof(server_addrv6));
3668 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg, 3677 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg,
3669 "transport-udp", 3678 "transport-udp",
3670 "BINDTO6", 3679 "BINDTO6",
3671 &bind6_address)) 3680 &bind6_address))
3672 { 3681 {
3673 LOG(GNUNET_ERROR_TYPE_DEBUG, 3682 LOG (GNUNET_ERROR_TYPE_DEBUG,
3674 "Binding udp plugin to specific address: `%s'\n", 3683 "Binding udp plugin to specific address: `%s'\n",
3675 bind6_address); 3684 bind6_address);
3676 if (1 != inet_pton(AF_INET6, bind6_address, &server_addrv6.sin6_addr)) 3685 if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr))
3677 { 3686 {
3678 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, 3687 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3679 "transport-udp", 3688 "transport-udp",
3680 "BINDTO6", 3689 "BINDTO6",
3681 _("must be valid IPv6 address")); 3690 _ ("must be valid IPv6 address"));
3682 GNUNET_free(bind6_address); 3691 GNUNET_free (bind6_address);
3683 return NULL; 3692 return NULL;
3684 }
3685 have_bind6 = GNUNET_YES;
3686 } 3693 }
3687 GNUNET_free_non_null(bind6_address); 3694 have_bind6 = GNUNET_YES;
3695 }
3696 GNUNET_free_non_null (bind6_address);
3688 3697
3689 enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 3698 enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3690 "transport-udp", 3699 "transport-udp",
3691 "BROADCAST"); 3700 "BROADCAST");
3692 if (enable_broadcasting == GNUNET_SYSERR) 3701 if (enable_broadcasting == GNUNET_SYSERR)
3693 enable_broadcasting = GNUNET_NO; 3702 enable_broadcasting = GNUNET_NO;
3694 3703
3695 enable_broadcasting_recv = 3704 enable_broadcasting_recv =
3696 GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 3705 GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3697 "transport-udp", 3706 "transport-udp",
3698 "BROADCAST_RECEIVE"); 3707 "BROADCAST_RECEIVE");
3699 if (enable_broadcasting_recv == GNUNET_SYSERR) 3708 if (enable_broadcasting_recv == GNUNET_SYSERR)
3700 enable_broadcasting_recv = GNUNET_YES; 3709 enable_broadcasting_recv = GNUNET_YES;
3701 3710
3702 if (GNUNET_SYSERR == 3711 if (GNUNET_SYSERR ==
3703 GNUNET_CONFIGURATION_get_value_time(env->cfg, 3712 GNUNET_CONFIGURATION_get_value_time (env->cfg,
3704 "transport-udp", 3713 "transport-udp",
3705 "BROADCAST_INTERVAL", 3714 "BROADCAST_INTERVAL",
3706 &interval)) 3715 &interval))
3707 { 3716 {
3708 interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10); 3717 interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
3709 } 3718 }
3710 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, 3719 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
3711 "transport-udp", 3720 "transport-udp",
3712 "MAX_BPS", 3721 "MAX_BPS",
3713 &udp_max_bps)) 3722 &udp_max_bps))
3714 { 3723 {
3715 /* 50 MB/s == infinity for practical purposes */ 3724 /* 50 MB/s == infinity for practical purposes */
3716 udp_max_bps = 1024 * 1024 * 50; 3725 udp_max_bps = 1024 * 1024 * 50;
3717 } 3726 }
3718 3727
3719 p = GNUNET_new(struct Plugin); 3728 p = GNUNET_new (struct Plugin);
3720 p->port = port; 3729 p->port = port;
3721 p->aport = aport; 3730 p->aport = aport;
3722 p->broadcast_interval = interval; 3731 p->broadcast_interval = interval;
@@ -3725,33 +3734,33 @@ libgnunet_plugin_transport_udp_init(void *cls)
3725 p->enable_broadcasting = enable_broadcasting; 3734 p->enable_broadcasting = enable_broadcasting;
3726 p->enable_broadcasting_receiving = enable_broadcasting_recv; 3735 p->enable_broadcasting_receiving = enable_broadcasting_recv;
3727 p->env = env; 3736 p->env = env;
3728 p->sessions = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_NO); 3737 p->sessions = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO);
3729 p->defrag_ctxs = 3738 p->defrag_ctxs =
3730 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 3739 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
3731 GNUNET_BANDWIDTH_tracker_init(&p->tracker, 3740 GNUNET_BANDWIDTH_tracker_init (&p->tracker,
3732 NULL, 3741 NULL,
3733 NULL, 3742 NULL,
3734 GNUNET_BANDWIDTH_value_init( 3743 GNUNET_BANDWIDTH_value_init (
3735 (uint32_t)udp_max_bps), 3744 (uint32_t) udp_max_bps),
3736 30); 3745 30);
3737 res = setup_sockets(p, 3746 res = setup_sockets (p,
3738 (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL, 3747 (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL,
3739 (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL); 3748 (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL);
3740 if ((0 == res) || ((NULL == p->sockv4) && (NULL == p->sockv6))) 3749 if ((0 == res) || ((NULL == p->sockv4) && (NULL == p->sockv6)))
3741 { 3750 {
3742 LOG(GNUNET_ERROR_TYPE_ERROR, _("Failed to create UDP network sockets\n")); 3751 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Failed to create UDP network sockets\n"));
3743 GNUNET_CONTAINER_multipeermap_destroy(p->sessions); 3752 GNUNET_CONTAINER_multipeermap_destroy (p->sessions);
3744 GNUNET_CONTAINER_heap_destroy(p->defrag_ctxs); 3753 GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs);
3745 if (NULL != p->nat) 3754 if (NULL != p->nat)
3746 GNUNET_NAT_unregister(p->nat); 3755 GNUNET_NAT_unregister (p->nat);
3747 GNUNET_free(p); 3756 GNUNET_free (p);
3748 return NULL; 3757 return NULL;
3749 } 3758 }
3750 3759
3751 /* Setup broadcasting and receiving beacons */ 3760 /* Setup broadcasting and receiving beacons */
3752 setup_broadcast(p, &server_addrv6, &server_addrv4); 3761 setup_broadcast (p, &server_addrv6, &server_addrv4);
3753 3762
3754 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 3763 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
3755 api->cls = p; 3764 api->cls = p;
3756 api->disconnect_session = &udp_disconnect_session; 3765 api->disconnect_session = &udp_disconnect_session;
3757 api->query_keepalive_factor = &udp_query_keepalive_factor; 3766 api->query_keepalive_factor = &udp_query_keepalive_factor;
@@ -3781,16 +3790,16 @@ libgnunet_plugin_transport_udp_init(void *cls)
3781 * @return #GNUNET_YES 3790 * @return #GNUNET_YES
3782 */ 3791 */
3783static int 3792static int
3784heap_cleanup_iterator(void *cls, 3793heap_cleanup_iterator (void *cls,
3785 struct GNUNET_CONTAINER_HeapNode *node, 3794 struct GNUNET_CONTAINER_HeapNode *node,
3786 void *element, 3795 void *element,
3787 GNUNET_CONTAINER_HeapCostType cost) 3796 GNUNET_CONTAINER_HeapCostType cost)
3788{ 3797{
3789 struct DefragContext *d_ctx = element; 3798 struct DefragContext *d_ctx = element;
3790 3799
3791 GNUNET_CONTAINER_heap_remove_node(node); 3800 GNUNET_CONTAINER_heap_remove_node (node);
3792 GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag); 3801 GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag);
3793 GNUNET_free(d_ctx); 3802 GNUNET_free (d_ctx);
3794 return GNUNET_YES; 3803 return GNUNET_YES;
3795} 3804}
3796 3805
@@ -3803,7 +3812,7 @@ heap_cleanup_iterator(void *cls,
3803 * @return NULL 3812 * @return NULL
3804 */ 3813 */
3805void * 3814void *
3806libgnunet_plugin_transport_udp_done(void *cls) 3815libgnunet_plugin_transport_udp_done (void *cls)
3807{ 3816{
3808 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3817 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3809 struct Plugin *plugin = api->cls; 3818 struct Plugin *plugin = api->cls;
@@ -3811,77 +3820,77 @@ libgnunet_plugin_transport_udp_done(void *cls)
3811 struct UDP_MessageWrapper *udpw; 3820 struct UDP_MessageWrapper *udpw;
3812 3821
3813 if (NULL == plugin) 3822 if (NULL == plugin)
3814 { 3823 {
3815 GNUNET_free(api); 3824 GNUNET_free (api);
3816 return NULL; 3825 return NULL;
3817 } 3826 }
3818 stop_broadcast(plugin); 3827 stop_broadcast (plugin);
3819 if (NULL != plugin->select_task_v4) 3828 if (NULL != plugin->select_task_v4)
3820 { 3829 {
3821 GNUNET_SCHEDULER_cancel(plugin->select_task_v4); 3830 GNUNET_SCHEDULER_cancel (plugin->select_task_v4);
3822 plugin->select_task_v4 = NULL; 3831 plugin->select_task_v4 = NULL;
3823 } 3832 }
3824 if (NULL != plugin->select_task_v6) 3833 if (NULL != plugin->select_task_v6)
3825 { 3834 {
3826 GNUNET_SCHEDULER_cancel(plugin->select_task_v6); 3835 GNUNET_SCHEDULER_cancel (plugin->select_task_v6);
3827 plugin->select_task_v6 = NULL; 3836 plugin->select_task_v6 = NULL;
3828 } 3837 }
3829 if (NULL != plugin->sockv4) 3838 if (NULL != plugin->sockv4)
3830 { 3839 {
3831 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(plugin->sockv4)); 3840 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4));
3832 plugin->sockv4 = NULL; 3841 plugin->sockv4 = NULL;
3833 } 3842 }
3834 if (NULL != plugin->sockv6) 3843 if (NULL != plugin->sockv6)
3835 { 3844 {
3836 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(plugin->sockv6)); 3845 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6));
3837 plugin->sockv6 = NULL; 3846 plugin->sockv6 = NULL;
3838 } 3847 }
3839 if (NULL != plugin->nat) 3848 if (NULL != plugin->nat)
3840 { 3849 {
3841 GNUNET_NAT_unregister(plugin->nat); 3850 GNUNET_NAT_unregister (plugin->nat);
3842 plugin->nat = NULL; 3851 plugin->nat = NULL;
3843 } 3852 }
3844 if (NULL != plugin->defrag_ctxs) 3853 if (NULL != plugin->defrag_ctxs)
3845 { 3854 {
3846 GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs, 3855 GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs,
3847 &heap_cleanup_iterator, 3856 &heap_cleanup_iterator,
3848 NULL); 3857 NULL);
3849 GNUNET_CONTAINER_heap_destroy(plugin->defrag_ctxs); 3858 GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs);
3850 plugin->defrag_ctxs = NULL; 3859 plugin->defrag_ctxs = NULL;
3851 } 3860 }
3852 while (NULL != (udpw = plugin->ipv4_queue_head)) 3861 while (NULL != (udpw = plugin->ipv4_queue_head))
3853 { 3862 {
3854 dequeue(plugin, udpw); 3863 dequeue (plugin, udpw);
3855 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); 3864 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
3856 GNUNET_free(udpw); 3865 GNUNET_free (udpw);
3857 } 3866 }
3858 while (NULL != (udpw = plugin->ipv6_queue_head)) 3867 while (NULL != (udpw = plugin->ipv6_queue_head))
3859 { 3868 {
3860 dequeue(plugin, udpw); 3869 dequeue (plugin, udpw);
3861 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR); 3870 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
3862 GNUNET_free(udpw); 3871 GNUNET_free (udpw);
3863 } 3872 }
3864 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, 3873 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
3865 &disconnect_and_free_it, 3874 &disconnect_and_free_it,
3866 plugin); 3875 plugin);
3867 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions); 3876 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions);
3868 3877
3869 while (NULL != (cur = plugin->ppc_dll_head)) 3878 while (NULL != (cur = plugin->ppc_dll_head))
3870 { 3879 {
3871 GNUNET_break(0); 3880 GNUNET_break (0);
3872 GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head, 3881 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head,
3873 plugin->ppc_dll_tail, 3882 plugin->ppc_dll_tail,
3874 cur); 3883 cur);
3875 GNUNET_RESOLVER_request_cancel(cur->resolver_handle); 3884 GNUNET_RESOLVER_request_cancel (cur->resolver_handle);
3876 if (NULL != cur->timeout_task) 3885 if (NULL != cur->timeout_task)
3877 { 3886 {
3878 GNUNET_SCHEDULER_cancel(cur->timeout_task); 3887 GNUNET_SCHEDULER_cancel (cur->timeout_task);
3879 cur->timeout_task = NULL; 3888 cur->timeout_task = NULL;
3880 } 3889 }
3881 GNUNET_free(cur); 3890 GNUNET_free (cur);
3882 } 3891 }
3883 GNUNET_free(plugin); 3892 GNUNET_free (plugin);
3884 GNUNET_free(api); 3893 GNUNET_free (api);
3885 return NULL; 3894 return NULL;
3886} 3895}
3887 3896
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 @@
41#include "gnunet_transport_plugin.h" 41#include "gnunet_transport_plugin.h"
42#include "transport.h" 42#include "transport.h"
43 43
44#define LOG(kind, ...) GNUNET_log_from(kind, "transport-udp", __VA_ARGS__) 44#define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
45 45
46#define PLUGIN_NAME "udp" 46#define PLUGIN_NAME "udp"
47 47
@@ -60,7 +60,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
60/** 60/**
61 * Network format for IPv4 addresses. 61 * Network format for IPv4 addresses.
62 */ 62 */
63struct IPv4UdpAddress { 63struct IPv4UdpAddress
64{
64 /** 65 /**
65 * Optional options and flags for this address 66 * Optional options and flags for this address
66 */ 67 */
@@ -81,7 +82,8 @@ struct IPv4UdpAddress {
81/** 82/**
82 * Network format for IPv6 addresses. 83 * Network format for IPv6 addresses.
83 */ 84 */
84struct IPv6UdpAddress { 85struct IPv6UdpAddress
86{
85 /** 87 /**
86 * Optional options and flags for this address 88 * Optional options and flags for this address
87 */ 89 */
@@ -103,7 +105,8 @@ GNUNET_NETWORK_STRUCT_END
103 * Either an IPv4 or IPv6 UDP address. Note that without a "length", 105 * Either an IPv4 or IPv6 UDP address. Note that without a "length",
104 * one cannot tell which one of the two types this address represents. 106 * one cannot tell which one of the two types this address represents.
105 */ 107 */
106union UdpAddress { 108union UdpAddress
109{
107 /** 110 /**
108 * IPv4 case. 111 * IPv4 case.
109 */ 112 */
@@ -131,7 +134,8 @@ struct PrettyPrinterContext;
131/** 134/**
132 * Encapsulation of all of the state of the plugin. 135 * Encapsulation of all of the state of the plugin.
133 */ 136 */
134struct Plugin { 137struct Plugin
138{
135 /** 139 /**
136 * Our environment. 140 * Our environment.
137 */ 141 */
@@ -312,9 +316,9 @@ struct Plugin {
312 * @return string representing the same address 316 * @return string representing the same address
313 */ 317 */
314const char * 318const char *
315udp_address_to_string(void *cls, 319udp_address_to_string (void *cls,
316 const void *addr, 320 const void *addr,
317 size_t addrlen); 321 size_t addrlen);
318 322
319 323
320/** 324/**
@@ -329,22 +333,22 @@ udp_address_to_string(void *cls,
329 * @param network_type network type of the sender's address 333 * @param network_type network type of the sender's address
330 */ 334 */
331void 335void
332udp_broadcast_receive(struct Plugin *plugin, 336udp_broadcast_receive (struct Plugin *plugin,
333 const char *buf, 337 const char *buf,
334 ssize_t size, 338 ssize_t size,
335 const union UdpAddress *udp_addr, 339 const union UdpAddress *udp_addr,
336 size_t udp_addr_len, 340 size_t udp_addr_len,
337 enum GNUNET_NetworkType network_type); 341 enum GNUNET_NetworkType network_type);
338 342
339 343
340void 344void
341setup_broadcast(struct Plugin *plugin, 345setup_broadcast (struct Plugin *plugin,
342 struct sockaddr_in6 *server_addrv6, 346 struct sockaddr_in6 *server_addrv6,
343 struct sockaddr_in *server_addrv4); 347 struct sockaddr_in *server_addrv4);
344 348
345 349
346void 350void
347stop_broadcast(struct Plugin *plugin); 351stop_broadcast (struct Plugin *plugin);
348 352
349/*#ifndef PLUGIN_TRANSPORT_UDP_H*/ 353/*#ifndef PLUGIN_TRANSPORT_UDP_H*/
350#endif 354#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 @@
38#include "gnunet_transport_plugin.h" 38#include "gnunet_transport_plugin.h"
39#include "transport.h" 39#include "transport.h"
40 40
41#define LOG(kind, ...) GNUNET_log_from(kind, "transport-udp", __VA_ARGS__) 41#define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
42 42
43/* *********** Cryogenic ********** */ 43/* *********** Cryogenic ********** */
44#if LINUX 44#if LINUX
@@ -50,9 +50,10 @@
50#include <sys/time.h> 50#include <sys/time.h>
51 51
52#define PM_MAGIC 'k' 52#define PM_MAGIC 'k'
53#define PM_SET_DELAY_AND_TIMEOUT _IOW(PM_MAGIC, 1, struct pm_times) 53#define PM_SET_DELAY_AND_TIMEOUT _IOW (PM_MAGIC, 1, struct pm_times)
54 54
55struct pm_times { 55struct pm_times
56{
56 unsigned long delay_msecs; 57 unsigned long delay_msecs;
57 unsigned long timeout_msecs; 58 unsigned long timeout_msecs;
58}; 59};
@@ -60,7 +61,8 @@ struct pm_times {
60/************************************/ 61/************************************/
61 62
62 63
63struct UDP_Beacon_Message { 64struct UDP_Beacon_Message
65{
64 /** 66 /**
65 * Message header. 67 * Message header.
66 */ 68 */
@@ -73,7 +75,8 @@ struct UDP_Beacon_Message {
73}; 75};
74 76
75 77
76struct BroadcastAddress { 78struct BroadcastAddress
79{
77 struct BroadcastAddress *next; 80 struct BroadcastAddress *next;
78 81
79 struct BroadcastAddress *prev; 82 struct BroadcastAddress *prev;
@@ -81,7 +84,7 @@ struct BroadcastAddress {
81 /** 84 /**
82 * ID of select broadcast task 85 * ID of select broadcast task
83 */ 86 */
84 struct GNUNET_SCHEDULER_Task * broadcast_task; 87 struct GNUNET_SCHEDULER_Task *broadcast_task;
85 88
86 struct Plugin *plugin; 89 struct Plugin *plugin;
87 90
@@ -106,7 +109,8 @@ struct BroadcastAddress {
106/** 109/**
107 * Client-specific context for #broadcast_mst_cb(). 110 * Client-specific context for #broadcast_mst_cb().
108 */ 111 */
109struct MstContext { 112struct MstContext
113{
110 struct Plugin *plugin; 114 struct Plugin *plugin;
111 115
112 const union UdpAddress *udp_addr; 116 const union UdpAddress *udp_addr;
@@ -129,8 +133,8 @@ struct MstContext {
129 * @return #GNUNET_OK (always) 133 * @return #GNUNET_OK (always)
130 */ 134 */
131static int 135static int
132broadcast_mst_cb(void *cls, 136broadcast_mst_cb (void *cls,
133 const struct GNUNET_MessageHeader *message) 137 const struct GNUNET_MessageHeader *message)
134{ 138{
135 struct MstContext *mc = cls; 139 struct MstContext *mc = cls;
136 struct Plugin *plugin = mc->plugin; 140 struct Plugin *plugin = mc->plugin;
@@ -138,32 +142,32 @@ broadcast_mst_cb(void *cls,
138 const struct GNUNET_MessageHeader *hello; 142 const struct GNUNET_MessageHeader *hello;
139 const struct UDP_Beacon_Message *msg; 143 const struct UDP_Beacon_Message *msg;
140 144
141 msg = (const struct UDP_Beacon_Message *)message; 145 msg = (const struct UDP_Beacon_Message *) message;
142 146
143 if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON != 147 if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON !=
144 ntohs(msg->header.type)) 148 ntohs (msg->header.type))
145 return GNUNET_OK; 149 return GNUNET_OK;
146 LOG(GNUNET_ERROR_TYPE_DEBUG, 150 LOG (GNUNET_ERROR_TYPE_DEBUG,
147 "Received beacon with %u bytes from peer `%s' via address `%s'\n", 151 "Received beacon with %u bytes from peer `%s' via address `%s'\n",
148 ntohs(msg->header.size), 152 ntohs (msg->header.size),
149 GNUNET_i2s(&msg->sender), 153 GNUNET_i2s (&msg->sender),
150 udp_address_to_string(NULL, 154 udp_address_to_string (NULL,
151 mc->udp_addr, 155 mc->udp_addr,
152 mc->udp_addr_len)); 156 mc->udp_addr_len));
153 hello = (struct GNUNET_MessageHeader *)&msg[1]; 157 hello = (struct GNUNET_MessageHeader *) &msg[1];
154 address = GNUNET_HELLO_address_allocate(&msg->sender, 158 address = GNUNET_HELLO_address_allocate (&msg->sender,
155 PLUGIN_NAME, 159 PLUGIN_NAME,
156 mc->udp_addr, 160 mc->udp_addr,
157 mc->udp_addr_len, 161 mc->udp_addr_len,
158 GNUNET_HELLO_ADDRESS_INFO_NONE); 162 GNUNET_HELLO_ADDRESS_INFO_NONE);
159 plugin->env->receive(plugin->env->cls, 163 plugin->env->receive (plugin->env->cls,
160 address, 164 address,
161 NULL, 165 NULL,
162 hello); 166 hello);
163 GNUNET_HELLO_address_free(address); 167 GNUNET_HELLO_address_free (address);
164 GNUNET_STATISTICS_update(plugin->env->stats, 168 GNUNET_STATISTICS_update (plugin->env->stats,
165 _("# Multicast HELLO beacons received via UDP"), 169 _ ("# Multicast HELLO beacons received via UDP"),
166 1, GNUNET_NO); 170 1, GNUNET_NO);
167 return GNUNET_OK; 171 return GNUNET_OK;
168} 172}
169 173
@@ -180,59 +184,59 @@ broadcast_mst_cb(void *cls,
180 * @param network_type network type of the sender's address 184 * @param network_type network type of the sender's address
181 */ 185 */
182void 186void
183udp_broadcast_receive(struct Plugin *plugin, 187udp_broadcast_receive (struct Plugin *plugin,
184 const char *buf, 188 const char *buf,
185 ssize_t size, 189 ssize_t size,
186 const union UdpAddress *udp_addr, 190 const union UdpAddress *udp_addr,
187 size_t udp_addr_len, 191 size_t udp_addr_len,
188 enum GNUNET_NetworkType network_type) 192 enum GNUNET_NetworkType network_type)
189{ 193{
190 struct GNUNET_MessageStreamTokenizer *broadcast_mst; 194 struct GNUNET_MessageStreamTokenizer *broadcast_mst;
191 struct MstContext mc; 195 struct MstContext mc;
192 196
193 broadcast_mst = GNUNET_MST_create(&broadcast_mst_cb, 197 broadcast_mst = GNUNET_MST_create (&broadcast_mst_cb,
194 &mc); 198 &mc);
195 mc.plugin = plugin; 199 mc.plugin = plugin;
196 mc.udp_addr = udp_addr; 200 mc.udp_addr = udp_addr;
197 mc.udp_addr_len = udp_addr_len; 201 mc.udp_addr_len = udp_addr_len;
198 mc.ats_address_network_type = network_type; 202 mc.ats_address_network_type = network_type;
199 GNUNET_MST_from_buffer(broadcast_mst, 203 GNUNET_MST_from_buffer (broadcast_mst,
200 buf, size, 204 buf, size,
201 GNUNET_NO, 205 GNUNET_NO,
202 GNUNET_NO); 206 GNUNET_NO);
203 GNUNET_MST_destroy(broadcast_mst); 207 GNUNET_MST_destroy (broadcast_mst);
204} 208}
205 209
206 210
207static unsigned int 211static unsigned int
208prepare_beacon(struct Plugin *plugin, 212prepare_beacon (struct Plugin *plugin,
209 struct UDP_Beacon_Message *msg) 213 struct UDP_Beacon_Message *msg)
210{ 214{
211 uint16_t hello_size; 215 uint16_t hello_size;
212 uint16_t msg_size; 216 uint16_t msg_size;
213 217
214 const struct GNUNET_MessageHeader *hello; 218 const struct GNUNET_MessageHeader *hello;
215 219
216 hello = plugin->env->get_our_hello(); 220 hello = plugin->env->get_our_hello ();
217 if (NULL == hello) 221 if (NULL == hello)
218 return 0; 222 return 0;
219 hello_size = GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)hello); 223 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
220 msg_size = hello_size + sizeof(struct UDP_Beacon_Message); 224 msg_size = hello_size + sizeof(struct UDP_Beacon_Message);
221 225
222 if (hello_size < (sizeof(struct GNUNET_MessageHeader)) || 226 if ((hello_size < (sizeof(struct GNUNET_MessageHeader)))||
223 (msg_size > (UDP_MTU))) 227 (msg_size > (UDP_MTU)))
224 return 0; 228 return 0;
225 229
226 msg->sender = *(plugin->env->my_identity); 230 msg->sender = *(plugin->env->my_identity);
227 msg->header.size = htons(msg_size); 231 msg->header.size = htons (msg_size);
228 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON); 232 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON);
229 GNUNET_memcpy(&msg[1], hello, hello_size); 233 GNUNET_memcpy (&msg[1], hello, hello_size);
230 return msg_size; 234 return msg_size;
231} 235}
232 236
233 237
234static void 238static void
235udp_ipv4_broadcast_send(void *cls) 239udp_ipv4_broadcast_send (void *cls)
236{ 240{
237 struct BroadcastAddress *baddr = cls; 241 struct BroadcastAddress *baddr = cls;
238 struct Plugin *plugin = baddr->plugin; 242 struct Plugin *plugin = baddr->plugin;
@@ -242,82 +246,84 @@ udp_ipv4_broadcast_send(void *cls)
242 246
243 baddr->broadcast_task = NULL; 247 baddr->broadcast_task = NULL;
244 248
245 msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *)&buf); 249 msg_size = prepare_beacon (plugin, (struct UDP_Beacon_Message *) &buf);
246 if (0 != msg_size) 250 if (0 != msg_size)
251 {
252 struct sockaddr_in *addr = (struct sockaddr_in *) baddr->addr;
253
254 addr->sin_port = htons (plugin->port);
255 sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4, &buf, msg_size,
256 (const struct sockaddr *) addr,
257 baddr->addrlen);
258 if (sent == GNUNET_SYSERR)
247 { 259 {
248 struct sockaddr_in *addr = (struct sockaddr_in *)baddr->addr; 260 if ((ENETUNREACH == errno) || (ENETDOWN == errno))
249 261 {
250 addr->sin_port = htons(plugin->port); 262 /* "Network unreachable" or "Network down"
251 sent = GNUNET_NETWORK_socket_sendto(plugin->sockv4, &buf, msg_size, 263 *
252 (const struct sockaddr *)addr, 264 * This indicates that we just do not have network connectivity
253 baddr->addrlen); 265 */
254 if (sent == GNUNET_SYSERR) 266 GNUNET_log (GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING,
255 { 267 "Network connectivity is down, cannot send beacon!\n");
256 if ((ENETUNREACH == errno) || (ENETDOWN == errno)) 268 }
257 {
258 /* "Network unreachable" or "Network down"
259 *
260 * This indicates that we just do not have network connectivity
261 */
262 GNUNET_log(GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING,
263 "Network connectivity is down, cannot send beacon!\n");
264 }
265 else
266 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "sendto");
267 }
268 else 269 else
269 { 270 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
270 LOG(GNUNET_ERROR_TYPE_DEBUG, 271 }
271 "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent, 272 else
272 GNUNET_a2s(baddr->addr, baddr->addrlen)); 273 {
273 } 274 LOG (GNUNET_ERROR_TYPE_DEBUG,
275 "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent,
276 GNUNET_a2s (baddr->addr, baddr->addrlen));
274 } 277 }
278 }
275 279
276#if LINUX 280#if LINUX
277 /* 281 /*
278 * Cryogenic 282 * Cryogenic
279 */ 283 */
280 if (NULL != baddr->cryogenic_fd) 284 if (NULL != baddr->cryogenic_fd)
285 {
286 baddr->cryogenic_times.delay_msecs =
287 (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5;
288 baddr->cryogenic_times.timeout_msecs =
289 (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5;
290
291 if (ioctl (baddr->cryogenic_fd->fd,
292 PM_SET_DELAY_AND_TIMEOUT,
293 &baddr->cryogenic_times) < 0)
281 { 294 {
282 baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5; 295 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl");
283 baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5; 296 baddr->broadcast_task =
284 297 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
285 if (ioctl(baddr->cryogenic_fd->fd, 298 &udp_ipv4_broadcast_send, baddr);
286 PM_SET_DELAY_AND_TIMEOUT,
287 &baddr->cryogenic_times) < 0)
288 {
289 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "ioctl");
290 baddr->broadcast_task =
291 GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval,
292 &udp_ipv4_broadcast_send, baddr);
293 }
294 else
295 GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL,
296 baddr->cryogenic_fd,
297 &udp_ipv4_broadcast_send,
298 baddr);
299 } 299 }
300 else
301 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
302 baddr->cryogenic_fd,
303 &udp_ipv4_broadcast_send,
304 baddr);
305 }
300 else 306 else
301#endif 307#endif
302 baddr->broadcast_task = 308 baddr->broadcast_task =
303 GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, 309 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
304 &udp_ipv4_broadcast_send, baddr); 310 &udp_ipv4_broadcast_send, baddr);
305} 311}
306 312
307 313
308static void 314static void
309udp_ipv6_broadcast_send(void *cls) 315udp_ipv6_broadcast_send (void *cls)
310{ 316{
311 struct BroadcastAddress *baddr = cls; 317 struct BroadcastAddress *baddr = cls;
312 struct Plugin *plugin = baddr->plugin; 318 struct Plugin *plugin = baddr->plugin;
313 ssize_t sent; 319 ssize_t sent;
314 uint16_t msg_size; 320 uint16_t msg_size;
315 char buf[65536] GNUNET_ALIGN; 321 char buf[65536] GNUNET_ALIGN;
316 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *)baddr->addr; 322 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) baddr->addr;
317 323
318 baddr->broadcast_task = NULL; 324 baddr->broadcast_task = NULL;
319 325
320 msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *)&buf); 326 msg_size = prepare_beacon (plugin, (struct UDP_Beacon_Message *) &buf);
321 /* Note: unclear if this actually works to limit the multicast to 327 /* Note: unclear if this actually works to limit the multicast to
322 the specified interface as we're not (necessarily) using a 328 the specified interface as we're not (necessarily) using a
323 link-local multicast group and the kernel suggests that the 329 link-local multicast group and the kernel suggests that the
@@ -327,63 +333,65 @@ udp_ipv6_broadcast_send(void *cls)
327 in that case, we might want to revert to only doing this 333 in that case, we might want to revert to only doing this
328 once, and not per interface (hard to test...) */ 334 once, and not per interface (hard to test...) */
329 plugin->ipv6_multicast_address.sin6_scope_id = s6->sin6_scope_id; 335 plugin->ipv6_multicast_address.sin6_scope_id = s6->sin6_scope_id;
330 sent = GNUNET_NETWORK_socket_sendto(plugin->sockv6, &buf, msg_size, 336 sent = GNUNET_NETWORK_socket_sendto (plugin->sockv6, &buf, msg_size,
331 (const struct sockaddr *) 337 (const struct sockaddr *)
332 &plugin->ipv6_multicast_address, 338 &plugin->ipv6_multicast_address,
333 sizeof(struct sockaddr_in6)); 339 sizeof(struct sockaddr_in6));
334 plugin->ipv6_multicast_address.sin6_scope_id = 0; 340 plugin->ipv6_multicast_address.sin6_scope_id = 0;
335 if (sent == GNUNET_SYSERR) 341 if (sent == GNUNET_SYSERR)
342 {
343 if ((ENETUNREACH == errno) || (ENETDOWN == errno))
336 { 344 {
337 if ((ENETUNREACH == errno) || (ENETDOWN == errno)) 345 /* "Network unreachable" or "Network down"
338 { 346 *
339 /* "Network unreachable" or "Network down" 347 * This indicates that this system is IPv6 enabled, but does not
340 * 348 * have a valid global IPv6 address assigned
341 * This indicates that this system is IPv6 enabled, but does not 349 */
342 * have a valid global IPv6 address assigned 350 GNUNET_log (GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING,
343 */ 351 "Network connectivity is down, cannot send beacon!\n");
344 GNUNET_log(GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING,
345 "Network connectivity is down, cannot send beacon!\n");
346 }
347 else
348 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "sendto");
349 } 352 }
353 else
354 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
355 }
350 else 356 else
351 { 357 {
352 LOG(GNUNET_ERROR_TYPE_DEBUG, 358 LOG (GNUNET_ERROR_TYPE_DEBUG,
353 "Sending IPv6 HELLO beacon broadcast with %d bytes to address %s\n", 359 "Sending IPv6 HELLO beacon broadcast with %d bytes to address %s\n",
354 (int)sent, 360 (int) sent,
355 GNUNET_a2s((const struct sockaddr *)&plugin->ipv6_multicast_address, 361 GNUNET_a2s ((const struct sockaddr *) &plugin->ipv6_multicast_address,
356 sizeof(struct sockaddr_in6))); 362 sizeof(struct sockaddr_in6)));
357 } 363 }
358#if LINUX 364#if LINUX
359 /* 365 /*
360 * Cryogenic 366 * Cryogenic
361 */ 367 */
362 if (NULL != baddr->cryogenic_fd) 368 if (NULL != baddr->cryogenic_fd)
369 {
370 baddr->cryogenic_times.delay_msecs =
371 (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5;
372 baddr->cryogenic_times.timeout_msecs =
373 (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5;
374
375 if (ioctl (baddr->cryogenic_fd->fd,
376 PM_SET_DELAY_AND_TIMEOUT,
377 &baddr->cryogenic_times) < 0)
363 { 378 {
364 baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5; 379 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl");
365 baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5; 380 baddr->broadcast_task =
366 381 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
367 if (ioctl(baddr->cryogenic_fd->fd, 382 &udp_ipv6_broadcast_send, baddr);
368 PM_SET_DELAY_AND_TIMEOUT,
369 &baddr->cryogenic_times) < 0)
370 {
371 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "ioctl");
372 baddr->broadcast_task =
373 GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval,
374 &udp_ipv6_broadcast_send, baddr);
375 }
376 else
377 GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL,
378 baddr->cryogenic_fd,
379 &udp_ipv6_broadcast_send,
380 baddr);
381 } 383 }
384 else
385 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
386 baddr->cryogenic_fd,
387 &udp_ipv6_broadcast_send,
388 baddr);
389 }
382 else 390 else
383#endif 391#endif
384 baddr->broadcast_task = 392 baddr->broadcast_task =
385 GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, 393 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
386 &udp_ipv6_broadcast_send, baddr); 394 &udp_ipv6_broadcast_send, baddr);
387} 395}
388 396
389 397
@@ -400,12 +408,12 @@ udp_ipv6_broadcast_send(void *cls)
400 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort 408 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
401 */ 409 */
402static int 410static int
403iface_proc(void *cls, 411iface_proc (void *cls,
404 const char *name, 412 const char *name,
405 int isDefault, 413 int isDefault,
406 const struct sockaddr *addr, 414 const struct sockaddr *addr,
407 const struct sockaddr *broadcast_addr, 415 const struct sockaddr *broadcast_addr,
408 const struct sockaddr *netmask, socklen_t addrlen) 416 const struct sockaddr *netmask, socklen_t addrlen)
409{ 417{
410 struct Plugin *plugin = cls; 418 struct Plugin *plugin = cls;
411 struct BroadcastAddress *ba; 419 struct BroadcastAddress *ba;
@@ -413,113 +421,115 @@ iface_proc(void *cls,
413 421
414 if (NULL == addr) 422 if (NULL == addr)
415 return GNUNET_OK; 423 return GNUNET_OK;
416 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
417 "address %s for interface %s %p\n ", 425 "address %s for interface %s %p\n ",
418 GNUNET_a2s(addr, addrlen), name, addr); 426 GNUNET_a2s (addr, addrlen), name, addr);
419 if (NULL == broadcast_addr) 427 if (NULL == broadcast_addr)
420 return GNUNET_OK; 428 return GNUNET_OK;
421 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
422 "broadcast address %s for interface %s %p\n ", 430 "broadcast address %s for interface %s %p\n ",
423 GNUNET_a2s(broadcast_addr, addrlen), name, broadcast_addr); 431 GNUNET_a2s (broadcast_addr, addrlen), name, broadcast_addr);
424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "netmask %s for interface %s %p\n ", 432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "netmask %s for interface %s %p\n ",
425 GNUNET_a2s(netmask, addrlen), name, netmask); 433 GNUNET_a2s (netmask, addrlen), name, netmask);
426 434
427 network = plugin->env->get_address_type(plugin->env->cls, broadcast_addr, addrlen); 435 network = plugin->env->get_address_type (plugin->env->cls, broadcast_addr,
436 addrlen);
428 if (GNUNET_NT_LOOPBACK == network) 437 if (GNUNET_NT_LOOPBACK == network)
429 { 438 {
430 /* Broadcasting on loopback does not make sense */ 439 /* Broadcasting on loopback does not make sense */
431 return GNUNET_YES; 440 return GNUNET_YES;
432 } 441 }
433 442
434 ba = GNUNET_new(struct BroadcastAddress); 443 ba = GNUNET_new (struct BroadcastAddress);
435 ba->plugin = plugin; 444 ba->plugin = plugin;
436 ba->addr = GNUNET_malloc(addrlen); 445 ba->addr = GNUNET_malloc (addrlen);
437 GNUNET_memcpy(ba->addr, broadcast_addr, addrlen); 446 GNUNET_memcpy (ba->addr, broadcast_addr, addrlen);
438 ba->addrlen = addrlen; 447 ba->addrlen = addrlen;
439 448
440 if ((GNUNET_YES == plugin->enable_ipv4) && 449 if ((GNUNET_YES == plugin->enable_ipv4) &&
441 (NULL != plugin->sockv4) && 450 (NULL != plugin->sockv4) &&
442 (addrlen == sizeof(struct sockaddr_in))) 451 (addrlen == sizeof(struct sockaddr_in)))
443 { 452 {
444#if LINUX 453#if LINUX
445 /* 454 /*
446 * setup Cryogenic FD for ipv4 broadcasting 455 * setup Cryogenic FD for ipv4 broadcasting
447 */ 456 */
448 char *filename; 457 char *filename;
449 458
450 GNUNET_asprintf(&filename, 459 GNUNET_asprintf (&filename,
451 "/dev/cryogenic/%s", 460 "/dev/cryogenic/%s",
452 name); 461 name);
453 if (0 == access(name, R_OK)) 462 if (0 == access (name, R_OK))
454 { 463 {
455 ba->cryogenic_fd = 464 ba->cryogenic_fd =
456 GNUNET_DISK_file_open(filename, 465 GNUNET_DISK_file_open (filename,
457 GNUNET_DISK_OPEN_WRITE, 466 GNUNET_DISK_OPEN_WRITE,
458 GNUNET_DISK_PERM_NONE); 467 GNUNET_DISK_PERM_NONE);
459 }
460 GNUNET_free(filename);
461#endif
462 ba->broadcast_task =
463 GNUNET_SCHEDULER_add_now(&udp_ipv4_broadcast_send, ba);
464 } 468 }
469 GNUNET_free (filename);
470#endif
471 ba->broadcast_task =
472 GNUNET_SCHEDULER_add_now (&udp_ipv4_broadcast_send, ba);
473 }
465 if ((GNUNET_YES == plugin->enable_ipv6) && 474 if ((GNUNET_YES == plugin->enable_ipv6) &&
466 (NULL != plugin->sockv6) && 475 (NULL != plugin->sockv6) &&
467 (addrlen == sizeof(struct sockaddr_in6))) 476 (addrlen == sizeof(struct sockaddr_in6)))
477 {
478 /* Create IPv6 multicast request */
479 struct ipv6_mreq multicastRequest;
480 const struct sockaddr_in6 *s6 = (const struct
481 sockaddr_in6 *) broadcast_addr;
482
483 multicastRequest.ipv6mr_multiaddr =
484 plugin->ipv6_multicast_address.sin6_addr;
485 /* http://tools.ietf.org/html/rfc2553#section-5.2:
486 *
487 * IPV6_JOIN_GROUP
488 *
489 * Join a multicast group on a specified local interface. If the
490 * interface index is specified as 0, the kernel chooses the local
491 * interface. For example, some kernels look up the multicast
492 * group in the normal IPv6 routing table and using the resulting
493 * interface; we do this for each interface, so no need to use
494 * zero (anymore...).
495 */
496 multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
497
498 /* Join the multicast group */
499 if (GNUNET_OK !=
500 GNUNET_NETWORK_socket_setsockopt
501 (plugin->sockv6, IPPROTO_IPV6, IPV6_JOIN_GROUP,
502 &multicastRequest, sizeof(multicastRequest)))
468 { 503 {
469 /* Create IPv6 multicast request */ 504 LOG (GNUNET_ERROR_TYPE_WARNING,
470 struct ipv6_mreq multicastRequest; 505 "Failed to join IPv6 multicast group: IPv6 broadcasting not running\n");
471 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *)broadcast_addr; 506 }
472 507 else
473 multicastRequest.ipv6mr_multiaddr = 508 {
474 plugin->ipv6_multicast_address.sin6_addr; 509#if LINUX
475 /* http://tools.ietf.org/html/rfc2553#section-5.2: 510 /*
476 * 511 * setup Cryogenic FD for ipv6 broadcasting
477 * IPV6_JOIN_GROUP
478 *
479 * Join a multicast group on a specified local interface. If the
480 * interface index is specified as 0, the kernel chooses the local
481 * interface. For example, some kernels look up the multicast
482 * group in the normal IPv6 routing table and using the resulting
483 * interface; we do this for each interface, so no need to use
484 * zero (anymore...).
485 */ 512 */
486 multicastRequest.ipv6mr_interface = s6->sin6_scope_id; 513 char *filename;
487 514
488 /* Join the multicast group */ 515 GNUNET_asprintf (&filename,
489 if (GNUNET_OK != 516 "/dev/cryogenic/%s",
490 GNUNET_NETWORK_socket_setsockopt 517 name);
491 (plugin->sockv6, IPPROTO_IPV6, IPV6_JOIN_GROUP, 518 if (0 == access (name, R_OK))
492 &multicastRequest, sizeof(multicastRequest))) 519 {
493 { 520 ba->cryogenic_fd =
494 LOG(GNUNET_ERROR_TYPE_WARNING, 521 GNUNET_DISK_file_open (filename,
495 "Failed to join IPv6 multicast group: IPv6 broadcasting not running\n"); 522 GNUNET_DISK_OPEN_WRITE,
496 } 523 GNUNET_DISK_PERM_NONE);
497 else 524 }
498 { 525 GNUNET_free (filename);
499#if LINUX
500 /*
501 * setup Cryogenic FD for ipv6 broadcasting
502 */
503 char *filename;
504
505 GNUNET_asprintf(&filename,
506 "/dev/cryogenic/%s",
507 name);
508 if (0 == access(name, R_OK))
509 {
510 ba->cryogenic_fd =
511 GNUNET_DISK_file_open(filename,
512 GNUNET_DISK_OPEN_WRITE,
513 GNUNET_DISK_PERM_NONE);
514 }
515 GNUNET_free(filename);
516#endif 526#endif
517 ba->broadcast_task = 527 ba->broadcast_task =
518 GNUNET_SCHEDULER_add_now(&udp_ipv6_broadcast_send, ba); 528 GNUNET_SCHEDULER_add_now (&udp_ipv6_broadcast_send, ba);
519 }
520 } 529 }
521 GNUNET_CONTAINER_DLL_insert(plugin->broadcast_head, 530 }
522 plugin->broadcast_tail, ba); 531 GNUNET_CONTAINER_DLL_insert (plugin->broadcast_head,
532 plugin->broadcast_tail, ba);
523 return GNUNET_OK; 533 return GNUNET_OK;
524} 534}
525 535
@@ -532,48 +542,50 @@ iface_proc(void *cls,
532 * @param server_addrv4 542 * @param server_addrv4
533 */ 543 */
534void 544void
535setup_broadcast(struct Plugin *plugin, 545setup_broadcast (struct Plugin *plugin,
536 struct sockaddr_in6 *server_addrv6, 546 struct sockaddr_in6 *server_addrv6,
537 struct sockaddr_in *server_addrv4) 547 struct sockaddr_in *server_addrv4)
538{ 548{
539 if (GNUNET_YES == 549 if (GNUNET_YES ==
540 GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 550 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
541 "topology", 551 "topology",
542 "FRIENDS-ONLY")) 552 "FRIENDS-ONLY"))
543 { 553 {
544 LOG(GNUNET_ERROR_TYPE_WARNING, 554 LOG (GNUNET_ERROR_TYPE_WARNING,
545 _("Disabling HELLO broadcasting due to friend-to-friend only configuration!\n")); 555 _ (
546 return; 556 "Disabling HELLO broadcasting due to friend-to-friend only configuration!\n"));
547 } 557 return;
558 }
548 559
549 if (GNUNET_YES != plugin->enable_broadcasting) 560 if (GNUNET_YES != plugin->enable_broadcasting)
550 return; /* We do not send, just receive */ 561 return; /* We do not send, just receive */
551 562
552 /* create IPv4 broadcast socket */ 563 /* create IPv4 broadcast socket */
553 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4)) 564 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
554 { 565 {
555 static int yes = 1; 566 static int yes = 1;
556 567
557 if (GNUNET_NETWORK_socket_setsockopt 568 if (GNUNET_NETWORK_socket_setsockopt
558 (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes, 569 (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes,
559 sizeof(int)) != GNUNET_OK) 570 sizeof(int)) != GNUNET_OK)
560 { 571 {
561 LOG(GNUNET_ERROR_TYPE_WARNING, 572 LOG (GNUNET_ERROR_TYPE_WARNING,
562 _("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"), 573 _ (
563 ntohs(server_addrv4->sin_port)); 574 "Failed to set IPv4 broadcast option for broadcast socket on port %d\n"),
564 } 575 ntohs (server_addrv4->sin_port));
565 } 576 }
577 }
566 /* create IPv6 multicast socket */ 578 /* create IPv6 multicast socket */
567 if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL)) 579 if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL))
568 { 580 {
569 memset(&plugin->ipv6_multicast_address, 0, sizeof(struct sockaddr_in6)); 581 memset (&plugin->ipv6_multicast_address, 0, sizeof(struct sockaddr_in6));
570 GNUNET_assert(1 == 582 GNUNET_assert (1 ==
571 inet_pton(AF_INET6, "FF05::13B", 583 inet_pton (AF_INET6, "FF05::13B",
572 &plugin->ipv6_multicast_address.sin6_addr)); 584 &plugin->ipv6_multicast_address.sin6_addr));
573 plugin->ipv6_multicast_address.sin6_family = AF_INET6; 585 plugin->ipv6_multicast_address.sin6_family = AF_INET6;
574 plugin->ipv6_multicast_address.sin6_port = htons(plugin->port); 586 plugin->ipv6_multicast_address.sin6_port = htons (plugin->port);
575 } 587 }
576 GNUNET_OS_network_interfaces_list(&iface_proc, plugin); 588 GNUNET_OS_network_interfaces_list (&iface_proc, plugin);
577} 589}
578 590
579 591
@@ -583,55 +595,55 @@ setup_broadcast(struct Plugin *plugin,
583 * @param plugin 595 * @param plugin
584 */ 596 */
585void 597void
586stop_broadcast(struct Plugin *plugin) 598stop_broadcast (struct Plugin *plugin)
587{ 599{
588 if (GNUNET_YES == plugin->enable_broadcasting) 600 if (GNUNET_YES == plugin->enable_broadcasting)
601 {
602 /* Disable broadcasting */
603 while (plugin->broadcast_head != NULL)
589 { 604 {
590 /* Disable broadcasting */ 605 struct BroadcastAddress *p = plugin->broadcast_head;
591 while (plugin->broadcast_head != NULL) 606
607 if (p->broadcast_task != NULL)
608 {
609 GNUNET_SCHEDULER_cancel (p->broadcast_task);
610 p->broadcast_task = NULL;
611 }
612 if ((GNUNET_YES == plugin->enable_ipv6) &&
613 (NULL != plugin->sockv6) &&
614 (p->addrlen == sizeof(struct sockaddr_in6)))
615 {
616 /* Create IPv6 multicast request */
617 struct ipv6_mreq multicastRequest;
618 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) p->addr;
619
620 multicastRequest.ipv6mr_multiaddr =
621 plugin->ipv6_multicast_address.sin6_addr;
622 multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
623
624 /* Leave the multicast group */
625 if (GNUNET_OK ==
626 GNUNET_NETWORK_socket_setsockopt
627 (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
628 &multicastRequest, sizeof(multicastRequest)))
592 { 629 {
593 struct BroadcastAddress *p = plugin->broadcast_head; 630 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
594 631 }
595 if (p->broadcast_task != NULL) 632 else
596 { 633 {
597 GNUNET_SCHEDULER_cancel(p->broadcast_task); 634 LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n");
598 p->broadcast_task = NULL; 635 }
599 } 636 }
600 if ((GNUNET_YES == plugin->enable_ipv6) &&
601 (NULL != plugin->sockv6) &&
602 (p->addrlen == sizeof(struct sockaddr_in6)))
603 {
604 /* Create IPv6 multicast request */
605 struct ipv6_mreq multicastRequest;
606 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *)p->addr;
607
608 multicastRequest.ipv6mr_multiaddr =
609 plugin->ipv6_multicast_address.sin6_addr;
610 multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
611
612 /* Leave the multicast group */
613 if (GNUNET_OK ==
614 GNUNET_NETWORK_socket_setsockopt
615 (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
616 &multicastRequest, sizeof(multicastRequest)))
617 {
618 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt");
619 }
620 else
621 {
622 LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n");
623 }
624 }
625 637
626#if LINUX 638#if LINUX
627 GNUNET_DISK_file_close(p->cryogenic_fd); 639 GNUNET_DISK_file_close (p->cryogenic_fd);
628#endif 640#endif
629 GNUNET_CONTAINER_DLL_remove(plugin->broadcast_head, 641 GNUNET_CONTAINER_DLL_remove (plugin->broadcast_head,
630 plugin->broadcast_tail, p); 642 plugin->broadcast_tail, p);
631 GNUNET_free(p->addr); 643 GNUNET_free (p->addr);
632 GNUNET_free(p); 644 GNUNET_free (p);
633 }
634 } 645 }
646 }
635} 647}
636 648
637/* end of plugin_transport_udp_broadcasting.c */ 649/* 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 @@
51/** 51/**
52 * Options for UNIX Domain addresses. 52 * Options for UNIX Domain addresses.
53 */ 53 */
54enum UNIX_ADDRESS_OPTIONS { 54enum UNIX_ADDRESS_OPTIONS
55{
55 /** 56 /**
56 * No special options. 57 * No special options.
57 */ 58 */
@@ -68,9 +69,9 @@ enum UNIX_ADDRESS_OPTIONS {
68 * How long until we give up on transmitting the welcome message? 69 * How long until we give up on transmitting the welcome message?
69 */ 70 */
70#define HOSTNAME_RESOLVE_TIMEOUT \ 71#define HOSTNAME_RESOLVE_TIMEOUT \
71 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 72 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
72 73
73#define LOG(kind, ...) GNUNET_log_from(kind, "transport-unix", __VA_ARGS__) 74#define LOG(kind, ...) GNUNET_log_from (kind, "transport-unix", __VA_ARGS__)
74 75
75 76
76GNUNET_NETWORK_STRUCT_BEGIN 77GNUNET_NETWORK_STRUCT_BEGIN
@@ -78,7 +79,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
78/** 79/**
79 * Binary format for an UNIX Domain Socket address in GNUnet. 80 * Binary format for an UNIX Domain Socket address in GNUnet.
80 */ 81 */
81struct UnixAddress { 82struct UnixAddress
83{
82 /** 84 /**
83 * Options to use for the address, in NBO 85 * Options to use for the address, in NBO
84 */ 86 */
@@ -96,7 +98,8 @@ struct UnixAddress {
96/** 98/**
97 * UNIX Message-Packet header. 99 * UNIX Message-Packet header.
98 */ 100 */
99struct UNIXMessage { 101struct UNIXMessage
102{
100 /** 103 /**
101 * Message header. 104 * Message header.
102 */ 105 */
@@ -114,7 +117,8 @@ GNUNET_NETWORK_STRUCT_END
114/** 117/**
115 * Information we track for a message awaiting transmission. 118 * Information we track for a message awaiting transmission.
116 */ 119 */
117struct UNIXMessageWrapper { 120struct UNIXMessageWrapper
121{
118 /** 122 /**
119 * We keep messages in a doubly linked list. 123 * We keep messages in a doubly linked list.
120 */ 124 */
@@ -170,7 +174,8 @@ struct UNIXMessageWrapper {
170/** 174/**
171 * Handle for a session. 175 * Handle for a session.
172 */ 176 */
173struct GNUNET_ATS_Session { 177struct GNUNET_ATS_Session
178{
174 /** 179 /**
175 * Sessions with pending messages (!) are kept in a DLL. 180 * Sessions with pending messages (!) are kept in a DLL.
176 */ 181 */
@@ -230,7 +235,8 @@ struct Plugin;
230/** 235/**
231 * Information we keep for each of our listen sockets. 236 * Information we keep for each of our listen sockets.
232 */ 237 */
233struct UNIX_Sock_Info { 238struct UNIX_Sock_Info
239{
234 /** 240 /**
235 * The network handle 241 * The network handle
236 */ 242 */
@@ -241,7 +247,8 @@ struct UNIX_Sock_Info {
241/** 247/**
242 * Encapsulation of all of the state of the plugin. 248 * Encapsulation of all of the state of the plugin.
243 */ 249 */
244struct Plugin { 250struct Plugin
251{
245 /** 252 /**
246 * ID of task used to update our addresses when one expires. 253 * ID of task used to update our addresses when one expires.
247 */ 254 */
@@ -323,15 +330,15 @@ struct Plugin {
323 * @param state new state of the session 330 * @param state new state of the session
324 */ 331 */
325static void 332static void
326notify_session_monitor(struct Plugin *plugin, 333notify_session_monitor (struct Plugin *plugin,
327 struct GNUNET_ATS_Session *session, 334 struct GNUNET_ATS_Session *session,
328 enum GNUNET_TRANSPORT_SessionState state) 335 enum GNUNET_TRANSPORT_SessionState state)
329{ 336{
330 struct GNUNET_TRANSPORT_SessionInfo info; 337 struct GNUNET_TRANSPORT_SessionInfo info;
331 338
332 if (NULL == plugin->sic) 339 if (NULL == plugin->sic)
333 return; 340 return;
334 memset(&info, 0, sizeof(info)); 341 memset (&info, 0, sizeof(info));
335 info.state = state; 342 info.state = state;
336 info.is_inbound = GNUNET_SYSERR; /* hard to say */ 343 info.is_inbound = GNUNET_SYSERR; /* hard to say */
337 info.num_msg_pending = session->msgs_in_queue; 344 info.num_msg_pending = session->msgs_in_queue;
@@ -341,7 +348,7 @@ notify_session_monitor(struct Plugin *plugin,
341 to receive from others) */ 348 to receive from others) */
342 info.session_timeout = session->timeout; 349 info.session_timeout = session->timeout;
343 info.address = session->address; 350 info.address = session->address;
344 plugin->sic(plugin->sic_cls, session, &info); 351 plugin->sic (plugin->sic_cls, session, &info);
345} 352}
346 353
347 354
@@ -357,50 +364,50 @@ notify_session_monitor(struct Plugin *plugin,
357 * @return string representing the same address 364 * @return string representing the same address
358 */ 365 */
359static const char * 366static const char *
360unix_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) 367unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
361{ 368{
362 static char rbuf[1024]; 369 static char rbuf[1024];
363 struct UnixAddress *ua = (struct UnixAddress *)addr; 370 struct UnixAddress *ua = (struct UnixAddress *) addr;
364 char *addrstr; 371 char *addrstr;
365 size_t addr_str_len; 372 size_t addr_str_len;
366 unsigned int off; 373 unsigned int off;
367 374
368 if ((NULL == addr) || (sizeof(struct UnixAddress) > addrlen)) 375 if ((NULL == addr) || (sizeof(struct UnixAddress) > addrlen))
369 { 376 {
370 GNUNET_break(0); 377 GNUNET_break (0);
371 return NULL; 378 return NULL;
372 } 379 }
373 addrstr = (char *)&ua[1]; 380 addrstr = (char *) &ua[1];
374 addr_str_len = ntohl(ua->addrlen); 381 addr_str_len = ntohl (ua->addrlen);
375 382
376 if (addr_str_len != addrlen - sizeof(struct UnixAddress)) 383 if (addr_str_len != addrlen - sizeof(struct UnixAddress))
377 { 384 {
378 GNUNET_break(0); 385 GNUNET_break (0);
379 return NULL; 386 return NULL;
380 } 387 }
381 if ('\0' != addrstr[addr_str_len - 1]) 388 if ('\0' != addrstr[addr_str_len - 1])
382 { 389 {
383 GNUNET_break(0); 390 GNUNET_break (0);
384 return NULL; 391 return NULL;
385 } 392 }
386 if (strlen(addrstr) + 1 != addr_str_len) 393 if (strlen (addrstr) + 1 != addr_str_len)
387 { 394 {
388 GNUNET_break(0); 395 GNUNET_break (0);
389 return NULL; 396 return NULL;
390 } 397 }
391 398
392 off = 0; 399 off = 0;
393 if ('\0' == addrstr[0]) 400 if ('\0' == addrstr[0])
394 off++; 401 off++;
395 memset(rbuf, 0, sizeof(rbuf)); 402 memset (rbuf, 0, sizeof(rbuf));
396 GNUNET_snprintf(rbuf, 403 GNUNET_snprintf (rbuf,
397 sizeof(rbuf) - 1, 404 sizeof(rbuf) - 1,
398 "%s.%u.%s%.*s", 405 "%s.%u.%s%.*s",
399 PLUGIN_NAME, 406 PLUGIN_NAME,
400 ntohl(ua->options), 407 ntohl (ua->options),
401 (off == 1) ? "@" : "", 408 (off == 1) ? "@" : "",
402 (int)(addr_str_len - off), 409 (int) (addr_str_len - off),
403 &addrstr[off]); 410 &addrstr[off]);
404 return rbuf; 411 return rbuf;
405} 412}
406 413
@@ -415,61 +422,61 @@ unix_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
415 * @return #GNUNET_OK on success 422 * @return #GNUNET_OK on success
416 */ 423 */
417static int 424static int
418unix_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *session) 425unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session)
419{ 426{
420 struct Plugin *plugin = cls; 427 struct Plugin *plugin = cls;
421 struct UNIXMessageWrapper *msgw; 428 struct UNIXMessageWrapper *msgw;
422 struct UNIXMessageWrapper *next; 429 struct UNIXMessageWrapper *next;
423 430
424 LOG(GNUNET_ERROR_TYPE_DEBUG, 431 LOG (GNUNET_ERROR_TYPE_DEBUG,
425 "Disconnecting session for peer `%s' `%s'\n", 432 "Disconnecting session for peer `%s' `%s'\n",
426 GNUNET_i2s(&session->target), 433 GNUNET_i2s (&session->target),
427 unix_plugin_address_to_string(NULL, 434 unix_plugin_address_to_string (NULL,
428 session->address->address, 435 session->address->address,
429 session->address->address_length)); 436 session->address->address_length));
430 plugin->env->session_end(plugin->env->cls, session->address, session); 437 plugin->env->session_end (plugin->env->cls, session->address, session);
431 next = plugin->msg_head; 438 next = plugin->msg_head;
432 while (NULL != next) 439 while (NULL != next)
433 { 440 {
434 msgw = next; 441 msgw = next;
435 next = msgw->next; 442 next = msgw->next;
436 if (msgw->session != session) 443 if (msgw->session != session)
437 continue; 444 continue;
438 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); 445 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
439 session->msgs_in_queue--; 446 session->msgs_in_queue--;
440 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); 447 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
441 session->bytes_in_queue -= msgw->msgsize; 448 session->bytes_in_queue -= msgw->msgsize;
442 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); 449 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
443 plugin->bytes_in_queue -= msgw->msgsize; 450 plugin->bytes_in_queue -= msgw->msgsize;
444 if (NULL != msgw->cont) 451 if (NULL != msgw->cont)
445 msgw->cont(msgw->cont_cls, 452 msgw->cont (msgw->cont_cls,
446 &msgw->session->target, 453 &msgw->session->target,
447 GNUNET_SYSERR, 454 GNUNET_SYSERR,
448 msgw->payload, 455 msgw->payload,
449 0); 456 0);
450 GNUNET_free(msgw->msg); 457 GNUNET_free (msgw->msg);
451 GNUNET_free(msgw); 458 GNUNET_free (msgw);
452 } 459 }
453 GNUNET_assert(GNUNET_YES == 460 GNUNET_assert (GNUNET_YES ==
454 GNUNET_CONTAINER_multipeermap_remove(plugin->session_map, 461 GNUNET_CONTAINER_multipeermap_remove (plugin->session_map,
455 &session->target, 462 &session->target,
456 session)); 463 session));
457 GNUNET_STATISTICS_set(plugin->env->stats, 464 GNUNET_STATISTICS_set (plugin->env->stats,
458 "# UNIX sessions active", 465 "# UNIX sessions active",
459 GNUNET_CONTAINER_multipeermap_size( 466 GNUNET_CONTAINER_multipeermap_size (
460 plugin->session_map), 467 plugin->session_map),
461 GNUNET_NO); 468 GNUNET_NO);
462 if (NULL != session->timeout_task) 469 if (NULL != session->timeout_task)
463 { 470 {
464 GNUNET_SCHEDULER_cancel(session->timeout_task); 471 GNUNET_SCHEDULER_cancel (session->timeout_task);
465 session->timeout_task = NULL; 472 session->timeout_task = NULL;
466 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 473 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
467 } 474 }
468 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_DONE); 475 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_DONE);
469 GNUNET_HELLO_address_free(session->address); 476 GNUNET_HELLO_address_free (session->address);
470 GNUNET_break(0 == session->bytes_in_queue); 477 GNUNET_break (0 == session->bytes_in_queue);
471 GNUNET_break(0 == session->msgs_in_queue); 478 GNUNET_break (0 == session->msgs_in_queue);
472 GNUNET_free(session); 479 GNUNET_free (session);
473 return GNUNET_OK; 480 return GNUNET_OK;
474} 481}
475 482
@@ -480,31 +487,31 @@ unix_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *session)
480 * @param cls the `struct GNUNET_ATS_Session *` to disconnect 487 * @param cls the `struct GNUNET_ATS_Session *` to disconnect
481 */ 488 */
482static void 489static void
483session_timeout(void *cls) 490session_timeout (void *cls)
484{ 491{
485 struct GNUNET_ATS_Session *session = cls; 492 struct GNUNET_ATS_Session *session = cls;
486 struct GNUNET_TIME_Relative left; 493 struct GNUNET_TIME_Relative left;
487 494
488 session->timeout_task = NULL; 495 session->timeout_task = NULL;
489 left = GNUNET_TIME_absolute_get_remaining(session->timeout); 496 left = GNUNET_TIME_absolute_get_remaining (session->timeout);
490 if (0 != left.rel_value_us) 497 if (0 != left.rel_value_us)
491 { 498 {
492 /* not actually our turn yet, but let's at least update 499 /* not actually our turn yet, but let's at least update
493 the monitor, it may think we're about to die ... */ 500 the monitor, it may think we're about to die ... */
494 notify_session_monitor(session->plugin, 501 notify_session_monitor (session->plugin,
495 session, 502 session,
496 GNUNET_TRANSPORT_SS_UPDATE); 503 GNUNET_TRANSPORT_SS_UPDATE);
497 session->timeout_task = 504 session->timeout_task =
498 GNUNET_SCHEDULER_add_delayed(left, &session_timeout, session); 505 GNUNET_SCHEDULER_add_delayed (left, &session_timeout, session);
499 return; 506 return;
500 } 507 }
501 LOG(GNUNET_ERROR_TYPE_DEBUG, 508 LOG (GNUNET_ERROR_TYPE_DEBUG,
502 "Session %p was idle for %s, disconnecting\n", 509 "Session %p was idle for %s, disconnecting\n",
503 session, 510 session,
504 GNUNET_STRINGS_relative_time_to_string( 511 GNUNET_STRINGS_relative_time_to_string (
505 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 512 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
506 GNUNET_YES)); 513 GNUNET_YES));
507 unix_plugin_session_disconnect(session->plugin, session); 514 unix_plugin_session_disconnect (session->plugin, session);
508} 515}
509 516
510 517
@@ -516,11 +523,11 @@ session_timeout(void *cls)
516 * @param session session for which the timeout should be rescheduled 523 * @param session session for which the timeout should be rescheduled
517 */ 524 */
518static void 525static void
519reschedule_session_timeout(struct GNUNET_ATS_Session *session) 526reschedule_session_timeout (struct GNUNET_ATS_Session *session)
520{ 527{
521 GNUNET_assert(NULL != session->timeout_task); 528 GNUNET_assert (NULL != session->timeout_task);
522 session->timeout = 529 session->timeout =
523 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 530 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
524} 531}
525 532
526 533
@@ -532,22 +539,22 @@ reschedule_session_timeout(struct GNUNET_ATS_Session *session)
532 * @return converted unix path 539 * @return converted unix path
533 */ 540 */
534static struct sockaddr_un * 541static struct sockaddr_un *
535unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len) 542unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
536{ 543{
537 struct sockaddr_un *un; 544 struct sockaddr_un *un;
538 size_t slen; 545 size_t slen;
539 546
540 GNUNET_assert(0 < strlen(unixpath)); /* sanity check */ 547 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
541 un = GNUNET_new(struct sockaddr_un); 548 un = GNUNET_new (struct sockaddr_un);
542 un->sun_family = AF_UNIX; 549 un->sun_family = AF_UNIX;
543 slen = strlen(unixpath); 550 slen = strlen (unixpath);
544 if (slen >= sizeof(un->sun_path)) 551 if (slen >= sizeof(un->sun_path))
545 slen = sizeof(un->sun_path) - 1; 552 slen = sizeof(un->sun_path) - 1;
546 GNUNET_memcpy(un->sun_path, unixpath, slen); 553 GNUNET_memcpy (un->sun_path, unixpath, slen);
547 un->sun_path[slen] = '\0'; 554 un->sun_path[slen] = '\0';
548 slen = sizeof(struct sockaddr_un); 555 slen = sizeof(struct sockaddr_un);
549#if HAVE_SOCKADDR_UN_SUN_LEN 556#if HAVE_SOCKADDR_UN_SUN_LEN
550 un->sun_len = (u_char)slen; 557 un->sun_len = (u_char) slen;
551#endif 558#endif
552 (*sock_len) = slen; 559 (*sock_len) = slen;
553 return un; 560 return un;
@@ -557,7 +564,8 @@ unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len)
557/** 564/**
558 * Closure to #lookup_session_it(). 565 * Closure to #lookup_session_it().
559 */ 566 */
560struct LookupCtx { 567struct LookupCtx
568{
561 /** 569 /**
562 * Location to store the session, if found. 570 * Location to store the session, if found.
563 */ 571 */
@@ -579,18 +587,18 @@ struct LookupCtx {
579 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success 587 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
580 */ 588 */
581static int 589static int
582lookup_session_it(void *cls, 590lookup_session_it (void *cls,
583 const struct GNUNET_PeerIdentity *key, 591 const struct GNUNET_PeerIdentity *key,
584 void *value) 592 void *value)
585{ 593{
586 struct LookupCtx *lctx = cls; 594 struct LookupCtx *lctx = cls;
587 struct GNUNET_ATS_Session *session = value; 595 struct GNUNET_ATS_Session *session = value;
588 596
589 if (0 == GNUNET_HELLO_address_cmp(lctx->address, session->address)) 597 if (0 == GNUNET_HELLO_address_cmp (lctx->address, session->address))
590 { 598 {
591 lctx->res = session; 599 lctx->res = session;
592 return GNUNET_NO; 600 return GNUNET_NO;
593 } 601 }
594 return GNUNET_YES; 602 return GNUNET_YES;
595} 603}
596 604
@@ -603,17 +611,17 @@ lookup_session_it(void *cls,
603 * @return NULL if session was not found 611 * @return NULL if session was not found
604 */ 612 */
605static struct GNUNET_ATS_Session * 613static struct GNUNET_ATS_Session *
606lookup_session(struct Plugin *plugin, 614lookup_session (struct Plugin *plugin,
607 const struct GNUNET_HELLO_Address *address) 615 const struct GNUNET_HELLO_Address *address)
608{ 616{
609 struct LookupCtx lctx; 617 struct LookupCtx lctx;
610 618
611 lctx.address = address; 619 lctx.address = address;
612 lctx.res = NULL; 620 lctx.res = NULL;
613 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->session_map, 621 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
614 &address->peer, 622 &address->peer,
615 &lookup_session_it, 623 &lookup_session_it,
616 &lctx); 624 &lctx);
617 return lctx.res; 625 return lctx.res;
618} 626}
619 627
@@ -627,7 +635,7 @@ lookup_session(struct Plugin *plugin,
627 * @return keepalive factor 635 * @return keepalive factor
628 */ 636 */
629static unsigned int 637static unsigned int
630unix_plugin_query_keepalive_factor(void *cls) 638unix_plugin_query_keepalive_factor (void *cls)
631{ 639{
632 return 3; 640 return 3;
633} 641}
@@ -655,18 +663,18 @@ unix_plugin_query_keepalive_factor(void *cls)
655 * @return on success the number of bytes written, RETRY for retry, -1 on errors 663 * @return on success the number of bytes written, RETRY for retry, -1 on errors
656 */ 664 */
657static ssize_t 665static ssize_t
658unix_real_send(void *cls, 666unix_real_send (void *cls,
659 struct GNUNET_NETWORK_Handle *send_handle, 667 struct GNUNET_NETWORK_Handle *send_handle,
660 const struct GNUNET_PeerIdentity *target, 668 const struct GNUNET_PeerIdentity *target,
661 const char *msgbuf, 669 const char *msgbuf,
662 size_t msgbuf_size, 670 size_t msgbuf_size,
663 unsigned int priority, 671 unsigned int priority,
664 struct GNUNET_TIME_Absolute timeout, 672 struct GNUNET_TIME_Absolute timeout,
665 const struct UnixAddress *addr, 673 const struct UnixAddress *addr,
666 size_t addrlen, 674 size_t addrlen,
667 size_t payload, 675 size_t payload,
668 GNUNET_TRANSPORT_TransmitContinuation cont, 676 GNUNET_TRANSPORT_TransmitContinuation cont,
669 void *cont_cls) 677 void *cont_cls)
670{ 678{
671 struct Plugin *plugin = cls; 679 struct Plugin *plugin = cls;
672 ssize_t sent; 680 ssize_t sent;
@@ -675,96 +683,96 @@ unix_real_send(void *cls,
675 const char *unixpath; 683 const char *unixpath;
676 684
677 if (NULL == send_handle) 685 if (NULL == send_handle)
678 { 686 {
679 GNUNET_break(0); /* We do not have a send handle */ 687 GNUNET_break (0); /* We do not have a send handle */
680 return GNUNET_SYSERR; 688 return GNUNET_SYSERR;
681 } 689 }
682 if ((NULL == addr) || (0 == addrlen)) 690 if ((NULL == addr) || (0 == addrlen))
683 { 691 {
684 GNUNET_break(0); /* Can never send if we don't have an address */ 692 GNUNET_break (0); /* Can never send if we don't have an address */
685 return GNUNET_SYSERR; 693 return GNUNET_SYSERR;
686 } 694 }
687 695
688 /* Prepare address */ 696 /* Prepare address */
689 unixpath = (const char *)&addr[1]; 697 unixpath = (const char *) &addr[1];
690 if (NULL == (un = unix_address_to_sockaddr(unixpath, &un_len))) 698 if (NULL == (un = unix_address_to_sockaddr (unixpath, &un_len)))
691 { 699 {
692 GNUNET_break(0); 700 GNUNET_break (0);
693 return -1; 701 return -1;
694 } 702 }
695 703
696 if ((GNUNET_YES == plugin->is_abstract) && 704 if ((GNUNET_YES == plugin->is_abstract) &&
697 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options)))) 705 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl (addr->options))))
698 { 706 {
699 un->sun_path[0] = '\0'; 707 un->sun_path[0] = '\0';
700 } 708 }
701resend: 709resend:
702 /* Send the data */ 710 /* Send the data */
703 sent = GNUNET_NETWORK_socket_sendto(send_handle, 711 sent = GNUNET_NETWORK_socket_sendto (send_handle,
704 msgbuf, 712 msgbuf,
705 msgbuf_size, 713 msgbuf_size,
706 (const struct sockaddr *)un, 714 (const struct sockaddr *) un,
707 un_len); 715 un_len);
708 if (GNUNET_SYSERR == sent) 716 if (GNUNET_SYSERR == sent)
717 {
718 if ((EAGAIN == errno) || (ENOBUFS == errno))
709 { 719 {
710 if ((EAGAIN == errno) || (ENOBUFS == errno)) 720 GNUNET_free (un);
711 { 721 return RETRY; /* We have to retry later */
712 GNUNET_free(un); 722 }
713 return RETRY; /* We have to retry later */ 723 if (EMSGSIZE == errno)
714 } 724 {
715 if (EMSGSIZE == errno) 725 socklen_t size = 0;
726 socklen_t len = sizeof(size);
727
728 GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
729 send_handle,
730 SOL_SOCKET,
731 SO_SNDBUF,
732 &size,
733 &len);
734 if (size < msgbuf_size)
735 {
736 LOG (GNUNET_ERROR_TYPE_DEBUG,
737 "Trying to increase socket buffer size from %u to %u for message size %u\n",
738 (unsigned int) size,
739 (unsigned int) ((msgbuf_size / 1000) + 2) * 1000,
740 (unsigned int) msgbuf_size);
741 size = ((msgbuf_size / 1000) + 2) * 1000;
742 if (GNUNET_OK ==
743 GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *)
744 send_handle,
745 SOL_SOCKET,
746 SO_SNDBUF,
747 &size,
748 sizeof(size)))
749 goto resend; /* Increased buffer size, retry sending */
750 else
716 { 751 {
717 socklen_t size = 0; 752 /* Could not increase buffer size: error, no retry */
718 socklen_t len = sizeof(size); 753 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
719 754 GNUNET_free (un);
720 GNUNET_NETWORK_socket_getsockopt((struct GNUNET_NETWORK_Handle *) 755 return GNUNET_SYSERR;
721 send_handle,
722 SOL_SOCKET,
723 SO_SNDBUF,
724 &size,
725 &len);
726 if (size < msgbuf_size)
727 {
728 LOG(GNUNET_ERROR_TYPE_DEBUG,
729 "Trying to increase socket buffer size from %u to %u for message size %u\n",
730 (unsigned int)size,
731 (unsigned int)((msgbuf_size / 1000) + 2) * 1000,
732 (unsigned int)msgbuf_size);
733 size = ((msgbuf_size / 1000) + 2) * 1000;
734 if (GNUNET_OK ==
735 GNUNET_NETWORK_socket_setsockopt((struct GNUNET_NETWORK_Handle *)
736 send_handle,
737 SOL_SOCKET,
738 SO_SNDBUF,
739 &size,
740 sizeof(size)))
741 goto resend; /* Increased buffer size, retry sending */
742 else
743 {
744 /* Could not increase buffer size: error, no retry */
745 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt");
746 GNUNET_free(un);
747 return GNUNET_SYSERR;
748 }
749 }
750 else
751 {
752 /* Buffer is bigger than message: error, no retry
753 * This should never happen!*/
754 GNUNET_break(0);
755 GNUNET_free(un);
756 return GNUNET_SYSERR;
757 }
758 } 756 }
757 }
758 else
759 {
760 /* Buffer is bigger than message: error, no retry
761 * This should never happen!*/
762 GNUNET_break (0);
763 GNUNET_free (un);
764 return GNUNET_SYSERR;
765 }
759 } 766 }
760 767 }
761 LOG(GNUNET_ERROR_TYPE_DEBUG, 768
762 "UNIX transmitted %u-byte message to %s (%d: %s)\n", 769 LOG (GNUNET_ERROR_TYPE_DEBUG,
763 (unsigned int)msgbuf_size, 770 "UNIX transmitted %u-byte message to %s (%d: %s)\n",
764 GNUNET_a2s((const struct sockaddr *)un, un_len), 771 (unsigned int) msgbuf_size,
765 (int)sent, 772 GNUNET_a2s ((const struct sockaddr *) un, un_len),
766 (sent < 0) ? strerror(errno) : "ok"); 773 (int) sent,
767 GNUNET_free(un); 774 (sent < 0) ? strerror (errno) : "ok");
775 GNUNET_free (un);
768 return sent; 776 return sent;
769} 777}
770 778
@@ -777,9 +785,9 @@ resend:
777 * @return the network type in HBO or #GNUNET_SYSERR 785 * @return the network type in HBO or #GNUNET_SYSERR
778 */ 786 */
779static enum GNUNET_NetworkType 787static enum GNUNET_NetworkType
780unix_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) 788unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
781{ 789{
782 GNUNET_assert(NULL != session); 790 GNUNET_assert (NULL != session);
783 return GNUNET_NT_LOOPBACK; 791 return GNUNET_NT_LOOPBACK;
784} 792}
785 793
@@ -792,8 +800,8 @@ unix_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
792 * @return the network type 800 * @return the network type
793 */ 801 */
794static enum GNUNET_NetworkType 802static enum GNUNET_NetworkType
795unix_plugin_get_network_for_address(void *cls, 803unix_plugin_get_network_for_address (void *cls,
796 const struct GNUNET_HELLO_Address *address) 804 const struct GNUNET_HELLO_Address *address)
797{ 805{
798 return GNUNET_NT_LOOPBACK; 806 return GNUNET_NT_LOOPBACK;
799} 807}
@@ -808,7 +816,7 @@ unix_plugin_get_network_for_address(void *cls,
808 * @return the session or NULL of max connections exceeded 816 * @return the session or NULL of max connections exceeded
809 */ 817 */
810static struct GNUNET_ATS_Session * 818static struct GNUNET_ATS_Session *
811unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) 819unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
812{ 820{
813 struct Plugin *plugin = cls; 821 struct Plugin *plugin = cls;
814 struct GNUNET_ATS_Session *session; 822 struct GNUNET_ATS_Session *session;
@@ -817,80 +825,80 @@ unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
817 uint32_t addr_str_len; 825 uint32_t addr_str_len;
818 uint32_t addr_option; 826 uint32_t addr_option;
819 827
820 ua = (struct UnixAddress *)address->address; 828 ua = (struct UnixAddress *) address->address;
821 if ((NULL == address->address) || (0 == address->address_length) || 829 if ((NULL == address->address) || (0 == address->address_length) ||
822 (sizeof(struct UnixAddress) > address->address_length)) 830 (sizeof(struct UnixAddress) > address->address_length))
823 { 831 {
824 GNUNET_break(0); 832 GNUNET_break (0);
825 return NULL; 833 return NULL;
826 } 834 }
827 addrstr = (char *)&ua[1]; 835 addrstr = (char *) &ua[1];
828 addr_str_len = ntohl(ua->addrlen); 836 addr_str_len = ntohl (ua->addrlen);
829 addr_option = ntohl(ua->options); 837 addr_option = ntohl (ua->options);
830 838
831 if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && 839 if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) &&
832 (GNUNET_NO == plugin->is_abstract)) 840 (GNUNET_NO == plugin->is_abstract))
833 { 841 {
834 return NULL; 842 return NULL;
835 } 843 }
836 844
837 if (addr_str_len != address->address_length - sizeof(struct UnixAddress)) 845 if (addr_str_len != address->address_length - sizeof(struct UnixAddress))
838 { 846 {
839 return NULL; /* This can be a legacy address */ 847 return NULL; /* This can be a legacy address */
840 } 848 }
841 849
842 if ('\0' != addrstr[addr_str_len - 1]) 850 if ('\0' != addrstr[addr_str_len - 1])
843 { 851 {
844 GNUNET_break(0); 852 GNUNET_break (0);
845 return NULL; 853 return NULL;
846 } 854 }
847 if (strlen(addrstr) + 1 != addr_str_len) 855 if (strlen (addrstr) + 1 != addr_str_len)
848 { 856 {
849 GNUNET_break(0); 857 GNUNET_break (0);
850 return NULL; 858 return NULL;
851 } 859 }
852 860
853 /* Check if a session for this address already exists */ 861 /* Check if a session for this address already exists */
854 if (NULL != (session = lookup_session(plugin, address))) 862 if (NULL != (session = lookup_session (plugin, address)))
855 { 863 {
856 LOG(GNUNET_ERROR_TYPE_DEBUG, 864 LOG (GNUNET_ERROR_TYPE_DEBUG,
857 "Found existing session %p for address `%s'\n", 865 "Found existing session %p for address `%s'\n",
858 session, 866 session,
859 unix_plugin_address_to_string(NULL, 867 unix_plugin_address_to_string (NULL,
860 address->address, 868 address->address,
861 address->address_length)); 869 address->address_length));
862 return session; 870 return session;
863 } 871 }
864 872
865 /* create a new session */ 873 /* create a new session */
866 session = GNUNET_new(struct GNUNET_ATS_Session); 874 session = GNUNET_new (struct GNUNET_ATS_Session);
867 session->target = address->peer; 875 session->target = address->peer;
868 session->address = GNUNET_HELLO_address_copy(address); 876 session->address = GNUNET_HELLO_address_copy (address);
869 session->plugin = plugin; 877 session->plugin = plugin;
870 session->timeout = 878 session->timeout =
871 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 879 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
872 session->timeout_task = 880 session->timeout_task =
873 GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 881 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
874 &session_timeout, 882 &session_timeout,
875 session); 883 session);
876 LOG(GNUNET_ERROR_TYPE_DEBUG, 884 LOG (GNUNET_ERROR_TYPE_DEBUG,
877 "Creating a new session %p for address `%s'\n", 885 "Creating a new session %p for address `%s'\n",
878 session, 886 session,
879 unix_plugin_address_to_string(NULL, 887 unix_plugin_address_to_string (NULL,
880 address->address, 888 address->address,
881 address->address_length)); 889 address->address_length));
882 (void)GNUNET_CONTAINER_multipeermap_put( 890 (void) GNUNET_CONTAINER_multipeermap_put (
883 plugin->session_map, 891 plugin->session_map,
884 &address->peer, 892 &address->peer,
885 session, 893 session,
886 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 894 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
887 GNUNET_STATISTICS_set(plugin->env->stats, 895 GNUNET_STATISTICS_set (plugin->env->stats,
888 "# UNIX sessions active", 896 "# UNIX sessions active",
889 GNUNET_CONTAINER_multipeermap_size( 897 GNUNET_CONTAINER_multipeermap_size (
890 plugin->session_map), 898 plugin->session_map),
891 GNUNET_NO); 899 GNUNET_NO);
892 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); 900 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
893 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); 901 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
894 return session; 902 return session;
895} 903}
896 904
@@ -905,21 +913,21 @@ unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
905 * @param session which session is being updated 913 * @param session which session is being updated
906 */ 914 */
907static void 915static void
908unix_plugin_update_session_timeout(void *cls, 916unix_plugin_update_session_timeout (void *cls,
909 const struct GNUNET_PeerIdentity *peer, 917 const struct GNUNET_PeerIdentity *peer,
910 struct GNUNET_ATS_Session *session) 918 struct GNUNET_ATS_Session *session)
911{ 919{
912 struct Plugin *plugin = cls; 920 struct Plugin *plugin = cls;
913 921
914 if (GNUNET_OK != 922 if (GNUNET_OK !=
915 GNUNET_CONTAINER_multipeermap_contains_value(plugin->session_map, 923 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
916 &session->target, 924 &session->target,
917 session)) 925 session))
918 { 926 {
919 GNUNET_break(0); 927 GNUNET_break (0);
920 return; 928 return;
921 } 929 }
922 reschedule_session_timeout(session); 930 reschedule_session_timeout (session);
923} 931}
924 932
925 933
@@ -933,47 +941,47 @@ unix_plugin_update_session_timeout(void *cls,
933 * @param ua_len length of the address @a ua 941 * @param ua_len length of the address @a ua
934 */ 942 */
935static void 943static void
936unix_demultiplexer(struct Plugin *plugin, 944unix_demultiplexer (struct Plugin *plugin,
937 struct GNUNET_PeerIdentity *sender, 945 struct GNUNET_PeerIdentity *sender,
938 const struct GNUNET_MessageHeader *currhdr, 946 const struct GNUNET_MessageHeader *currhdr,
939 const struct UnixAddress *ua, 947 const struct UnixAddress *ua,
940 size_t ua_len) 948 size_t ua_len)
941{ 949{
942 struct GNUNET_ATS_Session *session; 950 struct GNUNET_ATS_Session *session;
943 struct GNUNET_HELLO_Address *address; 951 struct GNUNET_HELLO_Address *address;
944 952
945 GNUNET_assert(ua_len >= sizeof(struct UnixAddress)); 953 GNUNET_assert (ua_len >= sizeof(struct UnixAddress));
946 LOG(GNUNET_ERROR_TYPE_DEBUG, 954 LOG (GNUNET_ERROR_TYPE_DEBUG,
947 "Received message from %s\n", 955 "Received message from %s\n",
948 unix_plugin_address_to_string(NULL, ua, ua_len)); 956 unix_plugin_address_to_string (NULL, ua, ua_len));
949 GNUNET_STATISTICS_update(plugin->env->stats, 957 GNUNET_STATISTICS_update (plugin->env->stats,
950 "# bytes received via UNIX", 958 "# bytes received via UNIX",
951 ntohs(currhdr->size), 959 ntohs (currhdr->size),
952 GNUNET_NO); 960 GNUNET_NO);
953 961
954 /* Look for existing session */ 962 /* Look for existing session */
955 address = GNUNET_HELLO_address_allocate( 963 address = GNUNET_HELLO_address_allocate (
956 sender, 964 sender,
957 PLUGIN_NAME, 965 PLUGIN_NAME,
958 ua, 966 ua,
959 ua_len, 967 ua_len,
960 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ 968 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */
961 session = lookup_session(plugin, address); 969 session = lookup_session (plugin, address);
962 if (NULL == session) 970 if (NULL == session)
963 { 971 {
964 session = unix_plugin_get_session(plugin, address); 972 session = unix_plugin_get_session (plugin, address);
965 /* Notify transport and ATS about new inbound session */ 973 /* Notify transport and ATS about new inbound session */
966 plugin->env->session_start(NULL, 974 plugin->env->session_start (NULL,
967 session->address, 975 session->address,
968 session, 976 session,
969 GNUNET_NT_LOOPBACK); 977 GNUNET_NT_LOOPBACK);
970 } 978 }
971 else 979 else
972 { 980 {
973 reschedule_session_timeout(session); 981 reschedule_session_timeout (session);
974 } 982 }
975 GNUNET_HELLO_address_free(address); 983 GNUNET_HELLO_address_free (address);
976 plugin->env->receive(plugin->env->cls, session->address, session, currhdr); 984 plugin->env->receive (plugin->env->cls, session->address, session, currhdr);
977} 985}
978 986
979 987
@@ -983,7 +991,7 @@ unix_demultiplexer(struct Plugin *plugin,
983 * @param plugin the plugin 991 * @param plugin the plugin
984 */ 992 */
985static void 993static void
986unix_plugin_do_read(struct Plugin *plugin) 994unix_plugin_do_read (struct Plugin *plugin)
987{ 995{
988 char buf[65536] GNUNET_ALIGN; 996 char buf[65536] GNUNET_ALIGN;
989 struct UnixAddress *ua; 997 struct UnixAddress *ua;
@@ -1001,70 +1009,70 @@ unix_plugin_do_read(struct Plugin *plugin)
1001 size_t ua_len; 1009 size_t ua_len;
1002 1010
1003 addrlen = sizeof(un); 1011 addrlen = sizeof(un);
1004 memset(&un, 0, sizeof(un)); 1012 memset (&un, 0, sizeof(un));
1005 ret = GNUNET_NETWORK_socket_recvfrom(plugin->unix_sock.desc, 1013 ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc,
1006 buf, 1014 buf,
1007 sizeof(buf), 1015 sizeof(buf),
1008 (struct sockaddr *)&un, 1016 (struct sockaddr *) &un,
1009 &addrlen); 1017 &addrlen);
1010 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) 1018 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS)))
1011 return; 1019 return;
1012 if (GNUNET_SYSERR == ret) 1020 if (GNUNET_SYSERR == ret)
1013 { 1021 {
1014 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom"); 1022 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
1015 return; 1023 return;
1016 } 1024 }
1017 else 1025 else
1018 { 1026 {
1019 LOG(GNUNET_ERROR_TYPE_DEBUG, 1027 LOG (GNUNET_ERROR_TYPE_DEBUG,
1020 "Read %d bytes from socket %s\n", 1028 "Read %d bytes from socket %s\n",
1021 (int)ret, 1029 (int) ret,
1022 un.sun_path); 1030 un.sun_path);
1023 } 1031 }
1024 1032
1025 GNUNET_assert(AF_UNIX == (un.sun_family)); 1033 GNUNET_assert (AF_UNIX == (un.sun_family));
1026 is_abstract = GNUNET_NO; 1034 is_abstract = GNUNET_NO;
1027 if ('\0' == un.sun_path[0]) 1035 if ('\0' == un.sun_path[0])
1028 { 1036 {
1029 un.sun_path[0] = '@'; 1037 un.sun_path[0] = '@';
1030 is_abstract = GNUNET_YES; 1038 is_abstract = GNUNET_YES;
1031 } 1039 }
1032 1040
1033 ua_len = sizeof(struct UnixAddress) + strlen(un.sun_path) + 1; 1041 ua_len = sizeof(struct UnixAddress) + strlen (un.sun_path) + 1;
1034 ua = GNUNET_malloc(ua_len); 1042 ua = GNUNET_malloc (ua_len);
1035 ua->addrlen = htonl(strlen(&un.sun_path[0]) + 1); 1043 ua->addrlen = htonl (strlen (&un.sun_path[0]) + 1);
1036 GNUNET_memcpy(&ua[1], &un.sun_path[0], strlen(un.sun_path) + 1); 1044 GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1);
1037 if (is_abstract) 1045 if (is_abstract)
1038 ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); 1046 ua->options = htonl (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS);
1039 else 1047 else
1040 ua->options = htonl(UNIX_OPTIONS_NONE); 1048 ua->options = htonl (UNIX_OPTIONS_NONE);
1041 1049
1042 msg = (struct UNIXMessage *)buf; 1050 msg = (struct UNIXMessage *) buf;
1043 csize = ntohs(msg->header.size); 1051 csize = ntohs (msg->header.size);
1044 if ((csize < sizeof(struct UNIXMessage)) || (csize > ret)) 1052 if ((csize < sizeof(struct UNIXMessage)) || (csize > ret))
1045 { 1053 {
1046 GNUNET_break_op(0); 1054 GNUNET_break_op (0);
1047 GNUNET_free(ua); 1055 GNUNET_free (ua);
1048 return; 1056 return;
1049 } 1057 }
1050 msgbuf = (char *)&msg[1]; 1058 msgbuf = (char *) &msg[1];
1051 GNUNET_memcpy(&sender, &msg->sender, sizeof(struct GNUNET_PeerIdentity)); 1059 GNUNET_memcpy (&sender, &msg->sender, sizeof(struct GNUNET_PeerIdentity));
1052 offset = 0; 1060 offset = 0;
1053 tsize = csize - sizeof(struct UNIXMessage); 1061 tsize = csize - sizeof(struct UNIXMessage);
1054 while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize) 1062 while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize)
1063 {
1064 currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset];
1065 csize = ntohs (currhdr->size);
1066 if ((csize < sizeof(struct GNUNET_MessageHeader)) ||
1067 (csize > tsize - offset))
1055 { 1068 {
1056 currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset]; 1069 GNUNET_break_op (0);
1057 csize = ntohs(currhdr->size); 1070 break;
1058 if ((csize < sizeof(struct GNUNET_MessageHeader)) ||
1059 (csize > tsize - offset))
1060 {
1061 GNUNET_break_op(0);
1062 break;
1063 }
1064 unix_demultiplexer(plugin, &sender, currhdr, ua, ua_len);
1065 offset += csize;
1066 } 1071 }
1067 GNUNET_free(ua); 1072 unix_demultiplexer (plugin, &sender, currhdr, ua, ua_len);
1073 offset += csize;
1074 }
1075 GNUNET_free (ua);
1068} 1076}
1069 1077
1070 1078
@@ -1074,7 +1082,7 @@ unix_plugin_do_read(struct Plugin *plugin)
1074 * @param plugin handle to the plugin 1082 * @param plugin handle to the plugin
1075 */ 1083 */
1076static void 1084static void
1077unix_plugin_do_write(struct Plugin *plugin) 1085unix_plugin_do_write (struct Plugin *plugin)
1078{ 1086{
1079 ssize_t sent = 0; 1087 ssize_t sent = 0;
1080 struct UNIXMessageWrapper *msgw; 1088 struct UNIXMessageWrapper *msgw;
@@ -1084,108 +1092,108 @@ unix_plugin_do_write(struct Plugin *plugin)
1084 session = NULL; 1092 session = NULL;
1085 did_delete = GNUNET_NO; 1093 did_delete = GNUNET_NO;
1086 while (NULL != (msgw = plugin->msg_head)) 1094 while (NULL != (msgw = plugin->msg_head))
1087 { 1095 {
1088 if (GNUNET_TIME_absolute_get_remaining(msgw->timeout).rel_value_us > 0) 1096 if (GNUNET_TIME_absolute_get_remaining (msgw->timeout).rel_value_us > 0)
1089 break; /* Message is ready for sending */ 1097 break; /* Message is ready for sending */
1090 /* Message has a timeout */ 1098 /* Message has a timeout */
1091 did_delete = GNUNET_YES; 1099 did_delete = GNUNET_YES;
1092 LOG(GNUNET_ERROR_TYPE_DEBUG, 1100 LOG (GNUNET_ERROR_TYPE_DEBUG,
1093 "Timeout for message with %u bytes \n", 1101 "Timeout for message with %u bytes \n",
1094 (unsigned int)msgw->msgsize); 1102 (unsigned int) msgw->msgsize);
1095 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); 1103 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
1096 session = msgw->session; 1104 session = msgw->session;
1097 session->msgs_in_queue--; 1105 session->msgs_in_queue--;
1098 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); 1106 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1099 session->bytes_in_queue -= msgw->msgsize; 1107 session->bytes_in_queue -= msgw->msgsize;
1100 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); 1108 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1101 plugin->bytes_in_queue -= msgw->msgsize; 1109 plugin->bytes_in_queue -= msgw->msgsize;
1102 GNUNET_STATISTICS_set(plugin->env->stats, 1110 GNUNET_STATISTICS_set (plugin->env->stats,
1103 "# bytes currently in UNIX buffers", 1111 "# bytes currently in UNIX buffers",
1104 plugin->bytes_in_queue, 1112 plugin->bytes_in_queue,
1105 GNUNET_NO); 1113 GNUNET_NO);
1106 GNUNET_STATISTICS_update(plugin->env->stats, 1114 GNUNET_STATISTICS_update (plugin->env->stats,
1107 "# UNIX bytes discarded", 1115 "# UNIX bytes discarded",
1108 msgw->msgsize, 1116 msgw->msgsize,
1109 GNUNET_NO); 1117 GNUNET_NO);
1110 if (NULL != msgw->cont) 1118 if (NULL != msgw->cont)
1111 msgw->cont(msgw->cont_cls, 1119 msgw->cont (msgw->cont_cls,
1112 &msgw->session->target, 1120 &msgw->session->target,
1113 GNUNET_SYSERR, 1121 GNUNET_SYSERR,
1114 msgw->payload, 1122 msgw->payload,
1115 0); 1123 0);
1116 GNUNET_free(msgw->msg); 1124 GNUNET_free (msgw->msg);
1117 GNUNET_free(msgw); 1125 GNUNET_free (msgw);
1118 } 1126 }
1119 if (NULL == msgw) 1127 if (NULL == msgw)
1120 { 1128 {
1121 if (GNUNET_YES == did_delete) 1129 if (GNUNET_YES == did_delete)
1122 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1130 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1123 return; /* Nothing to send at the moment */ 1131 return; /* Nothing to send at the moment */
1124 } 1132 }
1125 session = msgw->session; 1133 session = msgw->session;
1126 sent = unix_real_send(plugin, 1134 sent = unix_real_send (plugin,
1127 plugin->unix_sock.desc, 1135 plugin->unix_sock.desc,
1128 &session->target, 1136 &session->target,
1129 (const char *)msgw->msg, 1137 (const char *) msgw->msg,
1130 msgw->msgsize, 1138 msgw->msgsize,
1131 msgw->priority, 1139 msgw->priority,
1132 msgw->timeout, 1140 msgw->timeout,
1133 msgw->session->address->address, 1141 msgw->session->address->address,
1134 msgw->session->address->address_length, 1142 msgw->session->address->address_length,
1135 msgw->payload, 1143 msgw->payload,
1136 msgw->cont, 1144 msgw->cont,
1137 msgw->cont_cls); 1145 msgw->cont_cls);
1138 if (RETRY == sent) 1146 if (RETRY == sent)
1139 { 1147 {
1140 GNUNET_STATISTICS_update(plugin->env->stats, 1148 GNUNET_STATISTICS_update (plugin->env->stats,
1141 "# UNIX retry attempts", 1149 "# UNIX retry attempts",
1142 1, 1150 1,
1143 GNUNET_NO); 1151 GNUNET_NO);
1144 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1152 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1145 return; 1153 return;
1146 } 1154 }
1147 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); 1155 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
1148 session->msgs_in_queue--; 1156 session->msgs_in_queue--;
1149 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); 1157 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1150 session->bytes_in_queue -= msgw->msgsize; 1158 session->bytes_in_queue -= msgw->msgsize;
1151 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); 1159 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1152 plugin->bytes_in_queue -= msgw->msgsize; 1160 plugin->bytes_in_queue -= msgw->msgsize;
1153 GNUNET_STATISTICS_set(plugin->env->stats, 1161 GNUNET_STATISTICS_set (plugin->env->stats,
1154 "# bytes currently in UNIX buffers", 1162 "# bytes currently in UNIX buffers",
1155 plugin->bytes_in_queue, 1163 plugin->bytes_in_queue,
1156 GNUNET_NO); 1164 GNUNET_NO);
1157 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1165 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1158 if (GNUNET_SYSERR == sent) 1166 if (GNUNET_SYSERR == sent)
1159 { 1167 {
1160 /* failed and no retry */ 1168 /* failed and no retry */
1161 if (NULL != msgw->cont) 1169 if (NULL != msgw->cont)
1162 msgw->cont(msgw->cont_cls, 1170 msgw->cont (msgw->cont_cls,
1163 &msgw->session->target, 1171 &msgw->session->target,
1164 GNUNET_SYSERR, 1172 GNUNET_SYSERR,
1165 msgw->payload, 1173 msgw->payload,
1166 0); 1174 0);
1167 GNUNET_STATISTICS_update(plugin->env->stats, 1175 GNUNET_STATISTICS_update (plugin->env->stats,
1168 "# UNIX bytes discarded", 1176 "# UNIX bytes discarded",
1169 msgw->msgsize, 1177 msgw->msgsize,
1170 GNUNET_NO); 1178 GNUNET_NO);
1171 GNUNET_free(msgw->msg); 1179 GNUNET_free (msgw->msg);
1172 GNUNET_free(msgw); 1180 GNUNET_free (msgw);
1173 return; 1181 return;
1174 } 1182 }
1175 /* successfully sent bytes */ 1183 /* successfully sent bytes */
1176 GNUNET_break(sent > 0); 1184 GNUNET_break (sent > 0);
1177 GNUNET_STATISTICS_update(plugin->env->stats, 1185 GNUNET_STATISTICS_update (plugin->env->stats,
1178 "# bytes transmitted via UNIX", 1186 "# bytes transmitted via UNIX",
1179 msgw->msgsize, 1187 msgw->msgsize,
1180 GNUNET_NO); 1188 GNUNET_NO);
1181 if (NULL != msgw->cont) 1189 if (NULL != msgw->cont)
1182 msgw->cont(msgw->cont_cls, 1190 msgw->cont (msgw->cont_cls,
1183 &msgw->session->target, 1191 &msgw->session->target,
1184 GNUNET_OK, 1192 GNUNET_OK,
1185 msgw->payload, 1193 msgw->payload,
1186 msgw->msgsize); 1194 msgw->msgsize);
1187 GNUNET_free(msgw->msg); 1195 GNUNET_free (msgw->msg);
1188 GNUNET_free(msgw); 1196 GNUNET_free (msgw);
1189} 1197}
1190 1198
1191 1199
@@ -1196,20 +1204,20 @@ unix_plugin_do_write(struct Plugin *plugin)
1196 * @param cls the plugin handle 1204 * @param cls the plugin handle
1197 */ 1205 */
1198static void 1206static void
1199unix_plugin_select_read(void *cls) 1207unix_plugin_select_read (void *cls)
1200{ 1208{
1201 struct Plugin *plugin = cls; 1209 struct Plugin *plugin = cls;
1202 const struct GNUNET_SCHEDULER_TaskContext *tc; 1210 const struct GNUNET_SCHEDULER_TaskContext *tc;
1203 1211
1204 plugin->read_task = NULL; 1212 plugin->read_task = NULL;
1205 tc = GNUNET_SCHEDULER_get_task_context(); 1213 tc = GNUNET_SCHEDULER_get_task_context ();
1206 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) 1214 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1207 unix_plugin_do_read(plugin); 1215 unix_plugin_do_read (plugin);
1208 plugin->read_task = 1216 plugin->read_task =
1209 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 1217 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1210 plugin->unix_sock.desc, 1218 plugin->unix_sock.desc,
1211 &unix_plugin_select_read, 1219 &unix_plugin_select_read,
1212 plugin); 1220 plugin);
1213} 1221}
1214 1222
1215 1223
@@ -1220,22 +1228,22 @@ unix_plugin_select_read(void *cls)
1220 * @param cls the plugin handle 1228 * @param cls the plugin handle
1221 */ 1229 */
1222static void 1230static void
1223unix_plugin_select_write(void *cls) 1231unix_plugin_select_write (void *cls)
1224{ 1232{
1225 struct Plugin *plugin = cls; 1233 struct Plugin *plugin = cls;
1226 const struct GNUNET_SCHEDULER_TaskContext *tc; 1234 const struct GNUNET_SCHEDULER_TaskContext *tc;
1227 1235
1228 plugin->write_task = NULL; 1236 plugin->write_task = NULL;
1229 tc = GNUNET_SCHEDULER_get_task_context(); 1237 tc = GNUNET_SCHEDULER_get_task_context ();
1230 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) 1238 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
1231 unix_plugin_do_write(plugin); 1239 unix_plugin_do_write (plugin);
1232 if (NULL == plugin->msg_head) 1240 if (NULL == plugin->msg_head)
1233 return; /* write queue empty */ 1241 return; /* write queue empty */
1234 plugin->write_task = 1242 plugin->write_task =
1235 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 1243 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1236 plugin->unix_sock.desc, 1244 plugin->unix_sock.desc,
1237 &unix_plugin_select_write, 1245 &unix_plugin_select_write,
1238 plugin); 1246 plugin);
1239} 1247}
1240 1248
1241 1249
@@ -1267,14 +1275,14 @@ unix_plugin_select_write(void *cls)
1267 * and does NOT mean that the message was not transmitted (DV) 1275 * and does NOT mean that the message was not transmitted (DV)
1268 */ 1276 */
1269static ssize_t 1277static ssize_t
1270unix_plugin_send(void *cls, 1278unix_plugin_send (void *cls,
1271 struct GNUNET_ATS_Session *session, 1279 struct GNUNET_ATS_Session *session,
1272 const char *msgbuf, 1280 const char *msgbuf,
1273 size_t msgbuf_size, 1281 size_t msgbuf_size,
1274 unsigned int priority, 1282 unsigned int priority,
1275 struct GNUNET_TIME_Relative to, 1283 struct GNUNET_TIME_Relative to,
1276 GNUNET_TRANSPORT_TransmitContinuation cont, 1284 GNUNET_TRANSPORT_TransmitContinuation cont,
1277 void *cont_cls) 1285 void *cont_cls)
1278{ 1286{
1279 struct Plugin *plugin = cls; 1287 struct Plugin *plugin = cls;
1280 struct UNIXMessageWrapper *wrapper; 1288 struct UNIXMessageWrapper *wrapper;
@@ -1282,60 +1290,60 @@ unix_plugin_send(void *cls,
1282 int ssize; 1290 int ssize;
1283 1291
1284 if (GNUNET_OK != 1292 if (GNUNET_OK !=
1285 GNUNET_CONTAINER_multipeermap_contains_value(plugin->session_map, 1293 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
1286 &session->target, 1294 &session->target,
1287 session)) 1295 session))
1288 { 1296 {
1289 LOG(GNUNET_ERROR_TYPE_ERROR, 1297 LOG (GNUNET_ERROR_TYPE_ERROR,
1290 "Invalid session for peer `%s' `%s'\n", 1298 "Invalid session for peer `%s' `%s'\n",
1291 GNUNET_i2s(&session->target), 1299 GNUNET_i2s (&session->target),
1292 unix_plugin_address_to_string(NULL, 1300 unix_plugin_address_to_string (NULL,
1293 session->address->address, 1301 session->address->address,
1294 session->address->address_length)); 1302 session->address->address_length));
1295 GNUNET_break(0); 1303 GNUNET_break (0);
1296 return GNUNET_SYSERR; 1304 return GNUNET_SYSERR;
1297 } 1305 }
1298 LOG(GNUNET_ERROR_TYPE_DEBUG, 1306 LOG (GNUNET_ERROR_TYPE_DEBUG,
1299 "Sending %u bytes with session for peer `%s' `%s'\n", 1307 "Sending %u bytes with session for peer `%s' `%s'\n",
1300 msgbuf_size, 1308 msgbuf_size,
1301 GNUNET_i2s(&session->target), 1309 GNUNET_i2s (&session->target),
1302 unix_plugin_address_to_string(NULL, 1310 unix_plugin_address_to_string (NULL,
1303 session->address->address, 1311 session->address->address,
1304 session->address->address_length)); 1312 session->address->address_length));
1305 ssize = sizeof(struct UNIXMessage) + msgbuf_size; 1313 ssize = sizeof(struct UNIXMessage) + msgbuf_size;
1306 message = GNUNET_malloc(sizeof(struct UNIXMessage) + msgbuf_size); 1314 message = GNUNET_malloc (sizeof(struct UNIXMessage) + msgbuf_size);
1307 message->header.size = htons(ssize); 1315 message->header.size = htons (ssize);
1308 message->header.type = htons(0); 1316 message->header.type = htons (0);
1309 GNUNET_memcpy(&message->sender, 1317 GNUNET_memcpy (&message->sender,
1310 plugin->env->my_identity, 1318 plugin->env->my_identity,
1311 sizeof(struct GNUNET_PeerIdentity)); 1319 sizeof(struct GNUNET_PeerIdentity));
1312 GNUNET_memcpy(&message[1], msgbuf, msgbuf_size); 1320 GNUNET_memcpy (&message[1], msgbuf, msgbuf_size);
1313 wrapper = GNUNET_new(struct UNIXMessageWrapper); 1321 wrapper = GNUNET_new (struct UNIXMessageWrapper);
1314 wrapper->msg = message; 1322 wrapper->msg = message;
1315 wrapper->msgsize = ssize; 1323 wrapper->msgsize = ssize;
1316 wrapper->payload = msgbuf_size; 1324 wrapper->payload = msgbuf_size;
1317 wrapper->priority = priority; 1325 wrapper->priority = priority;
1318 wrapper->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); 1326 wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to);
1319 wrapper->cont = cont; 1327 wrapper->cont = cont;
1320 wrapper->cont_cls = cont_cls; 1328 wrapper->cont_cls = cont_cls;
1321 wrapper->session = session; 1329 wrapper->session = session;
1322 GNUNET_CONTAINER_DLL_insert_tail(plugin->msg_head, 1330 GNUNET_CONTAINER_DLL_insert_tail (plugin->msg_head,
1323 plugin->msg_tail, 1331 plugin->msg_tail,
1324 wrapper); 1332 wrapper);
1325 plugin->bytes_in_queue += ssize; 1333 plugin->bytes_in_queue += ssize;
1326 session->bytes_in_queue += ssize; 1334 session->bytes_in_queue += ssize;
1327 session->msgs_in_queue++; 1335 session->msgs_in_queue++;
1328 GNUNET_STATISTICS_set(plugin->env->stats, 1336 GNUNET_STATISTICS_set (plugin->env->stats,
1329 "# bytes currently in UNIX buffers", 1337 "# bytes currently in UNIX buffers",
1330 plugin->bytes_in_queue, 1338 plugin->bytes_in_queue,
1331 GNUNET_NO); 1339 GNUNET_NO);
1332 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1340 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1333 if (NULL == plugin->write_task) 1341 if (NULL == plugin->write_task)
1334 plugin->write_task = 1342 plugin->write_task =
1335 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 1343 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1336 plugin->unix_sock.desc, 1344 plugin->unix_sock.desc,
1337 &unix_plugin_select_write, 1345 &unix_plugin_select_write,
1338 plugin); 1346 plugin);
1339 return ssize; 1347 return ssize;
1340} 1348}
1341 1349
@@ -1347,57 +1355,57 @@ unix_plugin_send(void *cls,
1347 * @return number of sockets created or #GNUNET_SYSERR on error 1355 * @return number of sockets created or #GNUNET_SYSERR on error
1348 */ 1356 */
1349static int 1357static int
1350unix_transport_server_start(void *cls) 1358unix_transport_server_start (void *cls)
1351{ 1359{
1352 struct Plugin *plugin = cls; 1360 struct Plugin *plugin = cls;
1353 struct sockaddr_un *un; 1361 struct sockaddr_un *un;
1354 socklen_t un_len; 1362 socklen_t un_len;
1355 1363
1356 un = unix_address_to_sockaddr(plugin->unix_socket_path, &un_len); 1364 un = unix_address_to_sockaddr (plugin->unix_socket_path, &un_len);
1357 if (GNUNET_YES == plugin->is_abstract) 1365 if (GNUNET_YES == plugin->is_abstract)
1358 { 1366 {
1359 plugin->unix_socket_path[0] = '@'; 1367 plugin->unix_socket_path[0] = '@';
1360 un->sun_path[0] = '\0'; 1368 un->sun_path[0] = '\0';
1361 } 1369 }
1362 plugin->unix_sock.desc = 1370 plugin->unix_sock.desc =
1363 GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0); 1371 GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1364 if (NULL == plugin->unix_sock.desc) 1372 if (NULL == plugin->unix_sock.desc)
1365 { 1373 {
1366 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); 1374 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1367 GNUNET_free(un); 1375 GNUNET_free (un);
1368 return GNUNET_SYSERR; 1376 return GNUNET_SYSERR;
1369 } 1377 }
1370 if ('\0' != un->sun_path[0]) 1378 if ('\0' != un->sun_path[0])
1379 {
1380 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))
1371 { 1381 {
1372 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path)) 1382 LOG (GNUNET_ERROR_TYPE_ERROR,
1373 { 1383 _ ("Cannot create path to `%s'\n"),
1374 LOG(GNUNET_ERROR_TYPE_ERROR, 1384 un->sun_path);
1375 _("Cannot create path to `%s'\n"), 1385 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1376 un->sun_path);
1377 GNUNET_NETWORK_socket_close(plugin->unix_sock.desc);
1378 plugin->unix_sock.desc = NULL;
1379 GNUNET_free(un);
1380 return GNUNET_SYSERR;
1381 }
1382 }
1383 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(plugin->unix_sock.desc,
1384 (const struct sockaddr *)un,
1385 un_len))
1386 {
1387 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "bind");
1388 LOG(GNUNET_ERROR_TYPE_ERROR, _("Cannot bind to `%s'\n"), un->sun_path);
1389 GNUNET_NETWORK_socket_close(plugin->unix_sock.desc);
1390 plugin->unix_sock.desc = NULL; 1386 plugin->unix_sock.desc = NULL;
1391 GNUNET_free(un); 1387 GNUNET_free (un);
1392 return GNUNET_SYSERR; 1388 return GNUNET_SYSERR;
1393 } 1389 }
1394 LOG(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path); 1390 }
1391 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc,
1392 (const struct sockaddr *) un,
1393 un_len))
1394 {
1395 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
1396 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot bind to `%s'\n"), un->sun_path);
1397 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1398 plugin->unix_sock.desc = NULL;
1399 GNUNET_free (un);
1400 return GNUNET_SYSERR;
1401 }
1402 LOG (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path);
1395 plugin->read_task = 1403 plugin->read_task =
1396 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 1404 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1397 plugin->unix_sock.desc, 1405 plugin->unix_sock.desc,
1398 &unix_plugin_select_read, 1406 &unix_plugin_select_read,
1399 plugin); 1407 plugin);
1400 GNUNET_free(un); 1408 GNUNET_free (un);
1401 return 1; 1409 return 1;
1402} 1410}
1403 1411
@@ -1419,7 +1427,7 @@ unix_transport_server_start(void *cls)
1419 * 1427 *
1420 */ 1428 */
1421static int 1429static int
1422unix_plugin_check_address(void *cls, const void *addr, size_t addrlen) 1430unix_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1423{ 1431{
1424 struct Plugin *plugin = cls; 1432 struct Plugin *plugin = cls;
1425 const struct UnixAddress *ua = addr; 1433 const struct UnixAddress *ua = addr;
@@ -1428,24 +1436,24 @@ unix_plugin_check_address(void *cls, const void *addr, size_t addrlen)
1428 1436
1429 if ((NULL == addr) || (0 == addrlen) || 1437 if ((NULL == addr) || (0 == addrlen) ||
1430 (sizeof(struct UnixAddress) > addrlen)) 1438 (sizeof(struct UnixAddress) > addrlen))
1431 { 1439 {
1432 GNUNET_break(0); 1440 GNUNET_break (0);
1433 return GNUNET_SYSERR; 1441 return GNUNET_SYSERR;
1434 } 1442 }
1435 addrstr = (char *)&ua[1]; 1443 addrstr = (char *) &ua[1];
1436 addr_str_len = ntohl(ua->addrlen); 1444 addr_str_len = ntohl (ua->addrlen);
1437 if ('\0' != addrstr[addr_str_len - 1]) 1445 if ('\0' != addrstr[addr_str_len - 1])
1438 { 1446 {
1439 GNUNET_break(0); 1447 GNUNET_break (0);
1440 return GNUNET_SYSERR; 1448 return GNUNET_SYSERR;
1441 } 1449 }
1442 if (strlen(addrstr) + 1 != addr_str_len) 1450 if (strlen (addrstr) + 1 != addr_str_len)
1443 { 1451 {
1444 GNUNET_break(0); 1452 GNUNET_break (0);
1445 return GNUNET_SYSERR; 1453 return GNUNET_SYSERR;
1446 } 1454 }
1447 1455
1448 if (0 == strcmp(plugin->unix_socket_path, addrstr)) 1456 if (0 == strcmp (plugin->unix_socket_path, addrstr))
1449 return GNUNET_OK; 1457 return GNUNET_OK;
1450 return GNUNET_SYSERR; 1458 return GNUNET_SYSERR;
1451} 1459}
@@ -1466,23 +1474,23 @@ unix_plugin_check_address(void *cls, const void *addr, size_t addrlen)
1466 * @param asc_cls closure for @a asc 1474 * @param asc_cls closure for @a asc
1467 */ 1475 */
1468static void 1476static void
1469unix_plugin_address_pretty_printer(void *cls, 1477unix_plugin_address_pretty_printer (void *cls,
1470 const char *type, 1478 const char *type,
1471 const void *addr, 1479 const void *addr,
1472 size_t addrlen, 1480 size_t addrlen,
1473 int numeric, 1481 int numeric,
1474 struct GNUNET_TIME_Relative timeout, 1482 struct GNUNET_TIME_Relative timeout,
1475 GNUNET_TRANSPORT_AddressStringCallback asc, 1483 GNUNET_TRANSPORT_AddressStringCallback asc,
1476 void *asc_cls) 1484 void *asc_cls)
1477{ 1485{
1478 const char *ret; 1486 const char *ret;
1479 1487
1480 if ((NULL != addr) && (addrlen > 0)) 1488 if ((NULL != addr) && (addrlen > 0))
1481 ret = unix_plugin_address_to_string(NULL, addr, addrlen); 1489 ret = unix_plugin_address_to_string (NULL, addr, addrlen);
1482 else 1490 else
1483 ret = NULL; 1491 ret = NULL;
1484 asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); 1492 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1485 asc(asc_cls, NULL, GNUNET_OK); 1493 asc (asc_cls, NULL, GNUNET_OK);
1486} 1494}
1487 1495
1488 1496
@@ -1499,11 +1507,11 @@ unix_plugin_address_pretty_printer(void *cls,
1499 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1507 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1500 */ 1508 */
1501static int 1509static int
1502unix_plugin_string_to_address(void *cls, 1510unix_plugin_string_to_address (void *cls,
1503 const char *addr, 1511 const char *addr,
1504 uint16_t addrlen, 1512 uint16_t addrlen,
1505 void **buf, 1513 void **buf,
1506 size_t *added) 1514 size_t *added)
1507{ 1515{
1508 struct UnixAddress *ua; 1516 struct UnixAddress *ua;
1509 char *address; 1517 char *address;
@@ -1518,53 +1526,53 @@ unix_plugin_string_to_address(void *cls,
1518 optionstr = NULL; 1526 optionstr = NULL;
1519 1527
1520 if ((NULL == addr) || (addrlen == 0)) 1528 if ((NULL == addr) || (addrlen == 0))
1521 { 1529 {
1522 GNUNET_break(0); 1530 GNUNET_break (0);
1523 return GNUNET_SYSERR; 1531 return GNUNET_SYSERR;
1524 } 1532 }
1525 if ('\0' != addr[addrlen - 1]) 1533 if ('\0' != addr[addrlen - 1])
1526 { 1534 {
1527 GNUNET_break(0); 1535 GNUNET_break (0);
1528 return GNUNET_SYSERR; 1536 return GNUNET_SYSERR;
1529 } 1537 }
1530 if (strlen(addr) != addrlen - 1) 1538 if (strlen (addr) != addrlen - 1)
1531 { 1539 {
1532 GNUNET_break(0); 1540 GNUNET_break (0);
1533 return GNUNET_SYSERR; 1541 return GNUNET_SYSERR;
1534 } 1542 }
1535 plugin = GNUNET_strdup(addr); 1543 plugin = GNUNET_strdup (addr);
1536 optionstr = strchr(plugin, '.'); 1544 optionstr = strchr (plugin, '.');
1537 if (NULL == optionstr) 1545 if (NULL == optionstr)
1538 { 1546 {
1539 GNUNET_break(0); 1547 GNUNET_break (0);
1540 GNUNET_free(plugin); 1548 GNUNET_free (plugin);
1541 return GNUNET_SYSERR; 1549 return GNUNET_SYSERR;
1542 } 1550 }
1543 optionstr[0] = '\0'; 1551 optionstr[0] = '\0';
1544 optionstr++; 1552 optionstr++;
1545 options = atol(optionstr); 1553 options = atol (optionstr);
1546 address = strchr(optionstr, '.'); 1554 address = strchr (optionstr, '.');
1547 if (NULL == address) 1555 if (NULL == address)
1548 { 1556 {
1549 GNUNET_break(0); 1557 GNUNET_break (0);
1550 GNUNET_free(plugin); 1558 GNUNET_free (plugin);
1551 return GNUNET_SYSERR; 1559 return GNUNET_SYSERR;
1552 } 1560 }
1553 address[0] = '\0'; 1561 address[0] = '\0';
1554 address++; 1562 address++;
1555 if (0 != strcmp(plugin, PLUGIN_NAME)) 1563 if (0 != strcmp (plugin, PLUGIN_NAME))
1556 { 1564 {
1557 GNUNET_break(0); 1565 GNUNET_break (0);
1558 GNUNET_free(plugin); 1566 GNUNET_free (plugin);
1559 return GNUNET_SYSERR; 1567 return GNUNET_SYSERR;
1560 } 1568 }
1561 1569
1562 ua_size = sizeof(struct UnixAddress) + strlen(address) + 1; 1570 ua_size = sizeof(struct UnixAddress) + strlen (address) + 1;
1563 ua = GNUNET_malloc(ua_size); 1571 ua = GNUNET_malloc (ua_size);
1564 ua->options = htonl(options); 1572 ua->options = htonl (options);
1565 ua->addrlen = htonl(strlen(address) + 1); 1573 ua->addrlen = htonl (strlen (address) + 1);
1566 GNUNET_memcpy(&ua[1], address, strlen(address) + 1); 1574 GNUNET_memcpy (&ua[1], address, strlen (address) + 1);
1567 GNUNET_free(plugin); 1575 GNUNET_free (plugin);
1568 1576
1569 (*buf) = ua; 1577 (*buf) = ua;
1570 (*added) = ua_size; 1578 (*added) = ua_size;
@@ -1578,7 +1586,7 @@ unix_plugin_string_to_address(void *cls,
1578 * @param cls the plugin 1586 * @param cls the plugin
1579 */ 1587 */
1580static void 1588static void
1581address_notification(void *cls) 1589address_notification (void *cls)
1582{ 1590{
1583 struct Plugin *plugin = cls; 1591 struct Plugin *plugin = cls;
1584 struct GNUNET_HELLO_Address *address; 1592 struct GNUNET_HELLO_Address *address;
@@ -1586,24 +1594,24 @@ address_notification(void *cls)
1586 struct UnixAddress *ua; 1594 struct UnixAddress *ua;
1587 char *unix_path; 1595 char *unix_path;
1588 1596
1589 len = sizeof(struct UnixAddress) + strlen(plugin->unix_socket_path) + 1; 1597 len = sizeof(struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1590 ua = GNUNET_malloc(len); 1598 ua = GNUNET_malloc (len);
1591 ua->options = htonl(plugin->myoptions); 1599 ua->options = htonl (plugin->myoptions);
1592 ua->addrlen = htonl(strlen(plugin->unix_socket_path) + 1); 1600 ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1);
1593 unix_path = (char *)&ua[1]; 1601 unix_path = (char *) &ua[1];
1594 GNUNET_memcpy(unix_path, 1602 GNUNET_memcpy (unix_path,
1595 plugin->unix_socket_path, 1603 plugin->unix_socket_path,
1596 strlen(plugin->unix_socket_path) + 1); 1604 strlen (plugin->unix_socket_path) + 1);
1597 1605
1598 plugin->address_update_task = NULL; 1606 plugin->address_update_task = NULL;
1599 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 1607 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1600 PLUGIN_NAME, 1608 PLUGIN_NAME,
1601 ua, 1609 ua,
1602 len, 1610 len,
1603 GNUNET_HELLO_ADDRESS_INFO_NONE); 1611 GNUNET_HELLO_ADDRESS_INFO_NONE);
1604 plugin->env->notify_address(plugin->env->cls, GNUNET_YES, address); 1612 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address);
1605 GNUNET_free(ua); 1613 GNUNET_free (ua);
1606 GNUNET_free(address); 1614 GNUNET_free (address);
1607} 1615}
1608 1616
1609 1617
@@ -1616,14 +1624,14 @@ address_notification(void *cls)
1616 * @return #GNUNET_YES (always, continue to iterate) 1624 * @return #GNUNET_YES (always, continue to iterate)
1617 */ 1625 */
1618static int 1626static int
1619get_session_delete_it(void *cls, 1627get_session_delete_it (void *cls,
1620 const struct GNUNET_PeerIdentity *key, 1628 const struct GNUNET_PeerIdentity *key,
1621 void *value) 1629 void *value)
1622{ 1630{
1623 struct Plugin *plugin = cls; 1631 struct Plugin *plugin = cls;
1624 struct GNUNET_ATS_Session *session = value; 1632 struct GNUNET_ATS_Session *session = value;
1625 1633
1626 unix_plugin_session_disconnect(plugin, session); 1634 unix_plugin_session_disconnect (plugin, session);
1627 return GNUNET_YES; 1635 return GNUNET_YES;
1628} 1636}
1629 1637
@@ -1636,15 +1644,15 @@ get_session_delete_it(void *cls,
1636 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed 1644 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
1637 */ 1645 */
1638static void 1646static void
1639unix_plugin_peer_disconnect(void *cls, 1647unix_plugin_peer_disconnect (void *cls,
1640 const struct GNUNET_PeerIdentity *target) 1648 const struct GNUNET_PeerIdentity *target)
1641{ 1649{
1642 struct Plugin *plugin = cls; 1650 struct Plugin *plugin = cls;
1643 1651
1644 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->session_map, 1652 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
1645 target, 1653 target,
1646 &get_session_delete_it, 1654 &get_session_delete_it,
1647 plugin); 1655 plugin);
1648} 1656}
1649 1657
1650 1658
@@ -1658,15 +1666,15 @@ unix_plugin_peer_disconnect(void *cls,
1658 * @return #GNUNET_OK (continue to iterate) 1666 * @return #GNUNET_OK (continue to iterate)
1659 */ 1667 */
1660static int 1668static int
1661send_session_info_iter(void *cls, 1669send_session_info_iter (void *cls,
1662 const struct GNUNET_PeerIdentity *peer, 1670 const struct GNUNET_PeerIdentity *peer,
1663 void *value) 1671 void *value)
1664{ 1672{
1665 struct Plugin *plugin = cls; 1673 struct Plugin *plugin = cls;
1666 struct GNUNET_ATS_Session *session = value; 1674 struct GNUNET_ATS_Session *session = value;
1667 1675
1668 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); 1676 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
1669 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); 1677 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
1670 return GNUNET_OK; 1678 return GNUNET_OK;
1671} 1679}
1672 1680
@@ -1684,22 +1692,22 @@ send_session_info_iter(void *cls,
1684 * @param sic_cls closure for @a sic 1692 * @param sic_cls closure for @a sic
1685 */ 1693 */
1686static void 1694static void
1687unix_plugin_setup_monitor(void *cls, 1695unix_plugin_setup_monitor (void *cls,
1688 GNUNET_TRANSPORT_SessionInfoCallback sic, 1696 GNUNET_TRANSPORT_SessionInfoCallback sic,
1689 void *sic_cls) 1697 void *sic_cls)
1690{ 1698{
1691 struct Plugin *plugin = cls; 1699 struct Plugin *plugin = cls;
1692 1700
1693 plugin->sic = sic; 1701 plugin->sic = sic;
1694 plugin->sic_cls = sic_cls; 1702 plugin->sic_cls = sic_cls;
1695 if (NULL != sic) 1703 if (NULL != sic)
1696 { 1704 {
1697 GNUNET_CONTAINER_multipeermap_iterate(plugin->session_map, 1705 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1698 &send_session_info_iter, 1706 &send_session_info_iter,
1699 plugin); 1707 plugin);
1700 /* signal end of first iteration */ 1708 /* signal end of first iteration */
1701 sic(sic_cls, NULL, NULL); 1709 sic (sic_cls, NULL, NULL);
1702 } 1710 }
1703} 1711}
1704 1712
1705 1713
@@ -1711,7 +1719,7 @@ unix_plugin_setup_monitor(void *cls,
1711 * @return NULL on error, plugin functions otherwise 1719 * @return NULL on error, plugin functions otherwise
1712 */ 1720 */
1713void * 1721void *
1714libgnunet_plugin_transport_unix_init(void *cls) 1722libgnunet_plugin_transport_unix_init (void *cls)
1715{ 1723{
1716 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 1724 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1717 struct GNUNET_TRANSPORT_PluginFunctions *api; 1725 struct GNUNET_TRANSPORT_PluginFunctions *api;
@@ -1719,45 +1727,45 @@ libgnunet_plugin_transport_unix_init(void *cls)
1719 int sockets_created; 1727 int sockets_created;
1720 1728
1721 if (NULL == env->receive) 1729 if (NULL == env->receive)
1722 { 1730 {
1723 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 1731 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1724 initialze the plugin or the API */ 1732 initialze the plugin or the API */
1725 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 1733 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1726 api->cls = NULL; 1734 api->cls = NULL;
1727 api->address_pretty_printer = &unix_plugin_address_pretty_printer; 1735 api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1728 api->address_to_string = &unix_plugin_address_to_string; 1736 api->address_to_string = &unix_plugin_address_to_string;
1729 api->string_to_address = &unix_plugin_string_to_address; 1737 api->string_to_address = &unix_plugin_string_to_address;
1730 return api; 1738 return api;
1731 } 1739 }
1732 1740
1733 plugin = GNUNET_new(struct Plugin); 1741 plugin = GNUNET_new (struct Plugin);
1734 if (GNUNET_OK != 1742 if (GNUNET_OK !=
1735 GNUNET_CONFIGURATION_get_value_filename(env->cfg, 1743 GNUNET_CONFIGURATION_get_value_filename (env->cfg,
1736 "transport-unix", 1744 "transport-unix",
1737 "UNIXPATH", 1745 "UNIXPATH",
1738 &plugin->unix_socket_path)) 1746 &plugin->unix_socket_path))
1739 { 1747 {
1740 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 1748 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1741 "transport-unix", 1749 "transport-unix",
1742 "UNIXPATH"); 1750 "UNIXPATH");
1743 GNUNET_free(plugin); 1751 GNUNET_free (plugin);
1744 return NULL; 1752 return NULL;
1745 } 1753 }
1746 1754
1747 plugin->env = env; 1755 plugin->env = env;
1748 1756
1749 /* Initialize my flags */ 1757 /* Initialize my flags */
1750#ifdef LINUX 1758#ifdef LINUX
1751 plugin->is_abstract = 1759 plugin->is_abstract =
1752 GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 1760 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
1753 "testing", 1761 "testing",
1754 "USE_ABSTRACT_SOCKETS"); 1762 "USE_ABSTRACT_SOCKETS");
1755#endif 1763#endif
1756 plugin->myoptions = UNIX_OPTIONS_NONE; 1764 plugin->myoptions = UNIX_OPTIONS_NONE;
1757 if (GNUNET_YES == plugin->is_abstract) 1765 if (GNUNET_YES == plugin->is_abstract)
1758 plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS; 1766 plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS;
1759 1767
1760 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 1768 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1761 api->cls = plugin; 1769 api->cls = plugin;
1762 api->get_session = &unix_plugin_get_session; 1770 api->get_session = &unix_plugin_get_session;
1763 api->send = &unix_plugin_send; 1771 api->send = &unix_plugin_send;
@@ -1772,18 +1780,18 @@ libgnunet_plugin_transport_unix_init(void *cls)
1772 api->get_network_for_address = &unix_plugin_get_network_for_address; 1780 api->get_network_for_address = &unix_plugin_get_network_for_address;
1773 api->update_session_timeout = &unix_plugin_update_session_timeout; 1781 api->update_session_timeout = &unix_plugin_update_session_timeout;
1774 api->setup_monitor = &unix_plugin_setup_monitor; 1782 api->setup_monitor = &unix_plugin_setup_monitor;
1775 sockets_created = unix_transport_server_start(plugin); 1783 sockets_created = unix_transport_server_start (plugin);
1776 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) 1784 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created))
1777 { 1785 {
1778 LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX listen socket\n")); 1786 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UNIX listen socket\n"));
1779 GNUNET_free(api); 1787 GNUNET_free (api);
1780 GNUNET_free(plugin->unix_socket_path); 1788 GNUNET_free (plugin->unix_socket_path);
1781 GNUNET_free(plugin); 1789 GNUNET_free (plugin);
1782 return NULL; 1790 return NULL;
1783 } 1791 }
1784 plugin->session_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); 1792 plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1785 plugin->address_update_task = 1793 plugin->address_update_task =
1786 GNUNET_SCHEDULER_add_now(&address_notification, plugin); 1794 GNUNET_SCHEDULER_add_now (&address_notification, plugin);
1787 return api; 1795 return api;
1788} 1796}
1789 1797
@@ -1795,7 +1803,7 @@ libgnunet_plugin_transport_unix_init(void *cls)
1795 * @return NULL (always) 1803 * @return NULL (always)
1796 */ 1804 */
1797void * 1805void *
1798libgnunet_plugin_transport_unix_done(void *cls) 1806libgnunet_plugin_transport_unix_done (void *cls)
1799{ 1807{
1800 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 1808 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1801 struct Plugin *plugin = api->cls; 1809 struct Plugin *plugin = api->cls;
@@ -1806,75 +1814,75 @@ libgnunet_plugin_transport_unix_done(void *cls)
1806 struct GNUNET_ATS_Session *session; 1814 struct GNUNET_ATS_Session *session;
1807 1815
1808 if (NULL == plugin) 1816 if (NULL == plugin)
1809 { 1817 {
1810 GNUNET_free(api); 1818 GNUNET_free (api);
1811 return NULL; 1819 return NULL;
1812 } 1820 }
1813 len = sizeof(struct UnixAddress) + strlen(plugin->unix_socket_path) + 1; 1821 len = sizeof(struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1814 ua = GNUNET_malloc(len); 1822 ua = GNUNET_malloc (len);
1815 ua->options = htonl(plugin->myoptions); 1823 ua->options = htonl (plugin->myoptions);
1816 ua->addrlen = htonl(strlen(plugin->unix_socket_path) + 1); 1824 ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1);
1817 GNUNET_memcpy(&ua[1], 1825 GNUNET_memcpy (&ua[1],
1818 plugin->unix_socket_path, 1826 plugin->unix_socket_path,
1819 strlen(plugin->unix_socket_path) + 1); 1827 strlen (plugin->unix_socket_path) + 1);
1820 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 1828 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1821 PLUGIN_NAME, 1829 PLUGIN_NAME,
1822 ua, 1830 ua,
1823 len, 1831 len,
1824 GNUNET_HELLO_ADDRESS_INFO_NONE); 1832 GNUNET_HELLO_ADDRESS_INFO_NONE);
1825 plugin->env->notify_address(plugin->env->cls, GNUNET_NO, address); 1833 plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address);
1826 1834
1827 GNUNET_free(address); 1835 GNUNET_free (address);
1828 GNUNET_free(ua); 1836 GNUNET_free (ua);
1829 1837
1830 while (NULL != (msgw = plugin->msg_head)) 1838 while (NULL != (msgw = plugin->msg_head))
1831 { 1839 {
1832 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); 1840 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
1833 session = msgw->session; 1841 session = msgw->session;
1834 session->msgs_in_queue--; 1842 session->msgs_in_queue--;
1835 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); 1843 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1836 session->bytes_in_queue -= msgw->msgsize; 1844 session->bytes_in_queue -= msgw->msgsize;
1837 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); 1845 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1838 plugin->bytes_in_queue -= msgw->msgsize; 1846 plugin->bytes_in_queue -= msgw->msgsize;
1839 if (NULL != msgw->cont) 1847 if (NULL != msgw->cont)
1840 msgw->cont(msgw->cont_cls, 1848 msgw->cont (msgw->cont_cls,
1841 &msgw->session->target, 1849 &msgw->session->target,
1842 GNUNET_SYSERR, 1850 GNUNET_SYSERR,
1843 msgw->payload, 1851 msgw->payload,
1844 0); 1852 0);
1845 GNUNET_free(msgw->msg); 1853 GNUNET_free (msgw->msg);
1846 GNUNET_free(msgw); 1854 GNUNET_free (msgw);
1847 } 1855 }
1848 1856
1849 if (NULL != plugin->read_task) 1857 if (NULL != plugin->read_task)
1850 { 1858 {
1851 GNUNET_SCHEDULER_cancel(plugin->read_task); 1859 GNUNET_SCHEDULER_cancel (plugin->read_task);
1852 plugin->read_task = NULL; 1860 plugin->read_task = NULL;
1853 } 1861 }
1854 if (NULL != plugin->write_task) 1862 if (NULL != plugin->write_task)
1855 { 1863 {
1856 GNUNET_SCHEDULER_cancel(plugin->write_task); 1864 GNUNET_SCHEDULER_cancel (plugin->write_task);
1857 plugin->write_task = NULL; 1865 plugin->write_task = NULL;
1858 } 1866 }
1859 if (NULL != plugin->address_update_task) 1867 if (NULL != plugin->address_update_task)
1860 { 1868 {
1861 GNUNET_SCHEDULER_cancel(plugin->address_update_task); 1869 GNUNET_SCHEDULER_cancel (plugin->address_update_task);
1862 plugin->address_update_task = NULL; 1870 plugin->address_update_task = NULL;
1863 } 1871 }
1864 if (NULL != plugin->unix_sock.desc) 1872 if (NULL != plugin->unix_sock.desc)
1865 { 1873 {
1866 GNUNET_break(GNUNET_OK == 1874 GNUNET_break (GNUNET_OK ==
1867 GNUNET_NETWORK_socket_close(plugin->unix_sock.desc)); 1875 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc));
1868 plugin->unix_sock.desc = NULL; 1876 plugin->unix_sock.desc = NULL;
1869 } 1877 }
1870 GNUNET_CONTAINER_multipeermap_iterate(plugin->session_map, 1878 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1871 &get_session_delete_it, 1879 &get_session_delete_it,
1872 plugin); 1880 plugin);
1873 GNUNET_CONTAINER_multipeermap_destroy(plugin->session_map); 1881 GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map);
1874 GNUNET_break(0 == plugin->bytes_in_queue); 1882 GNUNET_break (0 == plugin->bytes_in_queue);
1875 GNUNET_free(plugin->unix_socket_path); 1883 GNUNET_free (plugin->unix_socket_path);
1876 GNUNET_free(plugin); 1884 GNUNET_free (plugin);
1877 GNUNET_free(api); 1885 GNUNET_free (api);
1878 return NULL; 1886 return NULL;
1879} 1887}
1880 1888
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 @@
47#define DUMMY_HELPER_NAME "gnunet-helper-transport-wlan-dummy" 47#define DUMMY_HELPER_NAME "gnunet-helper-transport-wlan-dummy"
48#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_wlan_init 48#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_wlan_init
49#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_wlan_done 49#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_wlan_done
50#define LOG(kind, ...) GNUNET_log_from(kind, "transport-wlan", __VA_ARGS__) 50#define LOG(kind, ...) GNUNET_log_from (kind, "transport-wlan", __VA_ARGS__)
51 51
52 52
53/** 53/**
54 * time out of a mac endpoint 54 * time out of a mac endpoint
55 */ 55 */
56#define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2) 56#define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply ( \
57 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2)
57 58
58/** 59/**
59 * We reduce the frequence of HELLO beacons in relation to 60 * We reduce the frequence of HELLO beacons in relation to
60 * the number of MAC addresses currently visible to us. 61 * the number of MAC addresses currently visible to us.
61 * This is the multiplication factor. 62 * This is the multiplication factor.
62 */ 63 */
63#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2) 64#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply ( \
65 GNUNET_TIME_UNIT_SECONDS, 2)
64 66
65 67
66/* end case wlan */ 68/* end case wlan */
@@ -72,14 +74,18 @@
72#define HELPER_NAME "gnunet-helper-transport-bluetooth" 74#define HELPER_NAME "gnunet-helper-transport-bluetooth"
73/* yes, this is correct, we use the same dummy driver as 'wlan' */ 75/* yes, this is correct, we use the same dummy driver as 'wlan' */
74#define DUMMY_HELPER_NAME "gnunet-helper-transport-wlan-dummy" 76#define DUMMY_HELPER_NAME "gnunet-helper-transport-wlan-dummy"
75#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_bluetooth_init 77#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \
76#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_bluetooth_done 78 libgnunet_plugin_transport_bluetooth_init
77#define LOG(kind, ...) GNUNET_log_from(kind, "transport-bluetooth", __VA_ARGS__) 79#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \
80 libgnunet_plugin_transport_bluetooth_done
81#define LOG(kind, ...) GNUNET_log_from (kind, "transport-bluetooth", \
82 __VA_ARGS__)
78 83
79/** 84/**
80 * time out of a mac endpoint 85 * time out of a mac endpoint
81 */ 86 */
82#define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 60) 87#define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply ( \
88 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 60)
83 89
84 90
85/** 91/**
@@ -87,7 +93,8 @@
87 * the number of MAC addresses currently visible to us. 93 * the number of MAC addresses currently visible to us.
88 * This is the multiplication factor. 94 * This is the multiplication factor.
89 */ 95 */
90#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) 96#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply ( \
97 GNUNET_TIME_UNIT_SECONDS, 60)
91 98
92/* end case bluetooth */ 99/* end case bluetooth */
93#else 100#else
@@ -111,7 +118,8 @@
111typedef int 118typedef int
112(*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, 119(*GNUNET_SERVER_MessageTokenizerCallback) (void *cls,
113 void *client, 120 void *client,
114 const struct GNUNET_MessageHeader *message); 121 const struct
122 GNUNET_MessageHeader *message);
115 123
116 124
117/* Include legacy message stream tokenizer that was removed from util (for now) */ 125/* Include legacy message stream tokenizer that was removed from util (for now) */
@@ -154,7 +162,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
154 * the CRC and then tokenize the payload and pass it to the 162 * the CRC and then tokenize the payload and pass it to the
155 * 'receive' callback. 163 * 'receive' callback.
156 */ 164 */
157struct WlanHeader { 165struct WlanHeader
166{
158 /** 167 /**
159 * Message type is #GNUNET_MESSAGE_TYPE_WLAN_DATA. 168 * Message type is #GNUNET_MESSAGE_TYPE_WLAN_DATA.
160 */ 169 */
@@ -183,7 +192,8 @@ struct WlanHeader {
183/** 192/**
184 * Address format for WLAN. 193 * Address format for WLAN.
185 */ 194 */
186struct WlanAddress { 195struct WlanAddress
196{
187 /** 197 /**
188 * Options set for the WLAN, in NBO. 198 * Options set for the WLAN, in NBO.
189 */ 199 */
@@ -203,7 +213,8 @@ GNUNET_NETWORK_STRUCT_END
203 * Information kept for each message that is yet to be fragmented and 213 * Information kept for each message that is yet to be fragmented and
204 * transmitted. 214 * transmitted.
205 */ 215 */
206struct PendingMessage { 216struct PendingMessage
217{
207 /** 218 /**
208 * next entry in the DLL 219 * next entry in the DLL
209 */ 220 */
@@ -234,14 +245,15 @@ struct PendingMessage {
234 /** 245 /**
235 * Timeout task (for this message). 246 * Timeout task (for this message).
236 */ 247 */
237 struct GNUNET_SCHEDULER_Task * timeout_task; 248 struct GNUNET_SCHEDULER_Task *timeout_task;
238}; 249};
239 250
240 251
241/** 252/**
242 * Session handle for connections with other peers. 253 * Session handle for connections with other peers.
243 */ 254 */
244struct GNUNET_ATS_Session { 255struct GNUNET_ATS_Session
256{
245 /** 257 /**
246 * To whom are we talking to (set to our identity 258 * To whom are we talking to (set to our identity
247 * if we are still waiting for the welcome message) 259 * if we are still waiting for the welcome message)
@@ -278,14 +290,15 @@ struct GNUNET_ATS_Session {
278 /** 290 /**
279 * Timeout task (for the session). 291 * Timeout task (for the session).
280 */ 292 */
281 struct GNUNET_SCHEDULER_Task * timeout_task; 293 struct GNUNET_SCHEDULER_Task *timeout_task;
282}; 294};
283 295
284 296
285/** 297/**
286 * Struct for messages that are being fragmented in a MAC's transmission queue. 298 * Struct for messages that are being fragmented in a MAC's transmission queue.
287 */ 299 */
288struct FragmentMessage { 300struct FragmentMessage
301{
289 /** 302 /**
290 * This is a doubly-linked list. 303 * This is a doubly-linked list.
291 */ 304 */
@@ -325,7 +338,7 @@ struct FragmentMessage {
325 /** 338 /**
326 * Timeout task. 339 * Timeout task.
327 */ 340 */
328 struct GNUNET_SCHEDULER_Task * timeout_task; 341 struct GNUNET_SCHEDULER_Task *timeout_task;
329 342
330 /** 343 /**
331 * Continuation to call when we're done with this message. 344 * Continuation to call when we're done with this message.
@@ -358,7 +371,8 @@ struct FragmentMessage {
358/** 371/**
359 * Struct to represent one network card connection 372 * Struct to represent one network card connection
360 */ 373 */
361struct MacEndpoint { 374struct MacEndpoint
375{
362 /** 376 /**
363 * We keep all MACs in a DLL in the plugin. 377 * We keep all MACs in a DLL in the plugin.
364 */ 378 */
@@ -407,7 +421,7 @@ struct MacEndpoint {
407 /** 421 /**
408 * Timeout task. 422 * Timeout task.
409 */ 423 */
410 struct GNUNET_SCHEDULER_Task * timeout_task; 424 struct GNUNET_SCHEDULER_Task *timeout_task;
411 425
412 /** 426 /**
413 * count of messages in the fragment out queue for this mac endpoint 427 * count of messages in the fragment out queue for this mac endpoint
@@ -449,7 +463,8 @@ struct MacEndpoint {
449/** 463/**
450 * Encapsulation of all of the state of the plugin. 464 * Encapsulation of all of the state of the plugin.
451 */ 465 */
452struct Plugin { 466struct Plugin
467{
453 /** 468 /**
454 * Our environment. 469 * Our environment.
455 */ 470 */
@@ -544,7 +559,8 @@ struct Plugin {
544 * the session or the MAC endpoint associated with the 559 * the session or the MAC endpoint associated with the
545 * message (or both). 560 * message (or both).
546 */ 561 */
547struct MacAndSession { 562struct MacAndSession
563{
548 /** 564 /**
549 * NULL if the identity of the other peer is not known. 565 * NULL if the identity of the other peer is not known.
550 */ 566 */
@@ -566,16 +582,16 @@ struct MacAndSession {
566 * this function 582 * this function
567 */ 583 */
568static const char * 584static const char *
569mac_to_string(const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac) 585mac_to_string (const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
570{ 586{
571 static char macstr[20]; 587 static char macstr[20];
572 588
573 GNUNET_snprintf(macstr, 589 GNUNET_snprintf (macstr,
574 sizeof(macstr), 590 sizeof(macstr),
575 "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 591 "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
576 mac->mac[0], mac->mac[1], 592 mac->mac[0], mac->mac[1],
577 mac->mac[2], mac->mac[3], 593 mac->mac[2], mac->mac[3],
578 mac->mac[4], mac->mac[5]); 594 mac->mac[4], mac->mac[5]);
579 return macstr; 595 return macstr;
580} 596}
581 597
@@ -592,25 +608,25 @@ mac_to_string(const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac)
592 * @return string representing the same address 608 * @return string representing the same address
593 */ 609 */
594static const char * 610static const char *
595wlan_plugin_address_to_string(void *cls, 611wlan_plugin_address_to_string (void *cls,
596 const void *addr, 612 const void *addr,
597 size_t addrlen) 613 size_t addrlen)
598{ 614{
599 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac; 615 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
600 static char macstr[36]; 616 static char macstr[36];
601 617
602 if (sizeof(struct WlanAddress) != addrlen) 618 if (sizeof(struct WlanAddress) != addrlen)
603 { 619 {
604 GNUNET_break(0); 620 GNUNET_break (0);
605 return NULL; 621 return NULL;
606 } 622 }
607 mac = &((struct WlanAddress *)addr)->mac; 623 mac = &((struct WlanAddress *) addr)->mac;
608 GNUNET_snprintf(macstr, 624 GNUNET_snprintf (macstr,
609 sizeof(macstr), 625 sizeof(macstr),
610 "%s.%u.%s", 626 "%s.%u.%s",
611 PLUGIN_NAME, 627 PLUGIN_NAME,
612 ntohl(((struct WlanAddress *)addr)->options), 628 ntohl (((struct WlanAddress *) addr)->options),
613 mac_to_string(mac)); 629 mac_to_string (mac));
614 return macstr; 630 return macstr;
615} 631}
616 632
@@ -624,15 +640,15 @@ wlan_plugin_address_to_string(void *cls,
624 * @param state new state of the session 640 * @param state new state of the session
625 */ 641 */
626static void 642static void
627notify_session_monitor(struct Plugin *plugin, 643notify_session_monitor (struct Plugin *plugin,
628 struct GNUNET_ATS_Session *session, 644 struct GNUNET_ATS_Session *session,
629 enum GNUNET_TRANSPORT_SessionState state) 645 enum GNUNET_TRANSPORT_SessionState state)
630{ 646{
631 struct GNUNET_TRANSPORT_SessionInfo info; 647 struct GNUNET_TRANSPORT_SessionInfo info;
632 648
633 if (NULL == plugin->sic) 649 if (NULL == plugin->sic)
634 return; 650 return;
635 memset(&info, 0, sizeof(info)); 651 memset (&info, 0, sizeof(info));
636 info.state = state; 652 info.state = state;
637 info.is_inbound = GNUNET_SYSERR; /* hard to say */ 653 info.is_inbound = GNUNET_SYSERR; /* hard to say */
638 info.num_msg_pending = 0; /* we queue per MAC, not per peer */ 654 info.num_msg_pending = 0; /* we queue per MAC, not per peer */
@@ -640,9 +656,9 @@ notify_session_monitor(struct Plugin *plugin,
640 info.receive_delay = GNUNET_TIME_UNIT_ZERO_ABS; /* not supported by WLAN */ 656 info.receive_delay = GNUNET_TIME_UNIT_ZERO_ABS; /* not supported by WLAN */
641 info.session_timeout = session->timeout; 657 info.session_timeout = session->timeout;
642 info.address = session->address; 658 info.address = session->address;
643 plugin->sic(plugin->sic_cls, 659 plugin->sic (plugin->sic_cls,
644 session, 660 session,
645 &info); 661 &info);
646} 662}
647 663
648 664
@@ -654,24 +670,24 @@ notify_session_monitor(struct Plugin *plugin,
654 * @param size total message size 670 * @param size total message size
655 */ 671 */
656static void 672static void
657get_radiotap_header(struct MacEndpoint *endpoint, 673get_radiotap_header (struct MacEndpoint *endpoint,
658 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, 674 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
659 uint16_t size) 675 uint16_t size)
660{ 676{
661 header->header.type = ntohs(GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); 677 header->header.type = ntohs (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER);
662 header->header.size = ntohs(size); 678 header->header.size = ntohs (size);
663 if (NULL != endpoint) 679 if (NULL != endpoint)
664 { 680 {
665 header->rate = endpoint->rate; 681 header->rate = endpoint->rate;
666 header->tx_power = endpoint->tx_power; 682 header->tx_power = endpoint->tx_power;
667 header->antenna = endpoint->antenna; 683 header->antenna = endpoint->antenna;
668 } 684 }
669 else 685 else
670 { 686 {
671 header->rate = 255; 687 header->rate = 255;
672 header->tx_power = 0; 688 header->tx_power = 0;
673 header->antenna = 0; 689 header->antenna = 0;
674 } 690 }
675} 691}
676 692
677 693
@@ -684,18 +700,18 @@ get_radiotap_header(struct MacEndpoint *endpoint,
684 * @param size size of the whole packet, needed to calculate the time to send the packet 700 * @param size size of the whole packet, needed to calculate the time to send the packet
685 */ 701 */
686static void 702static void
687get_wlan_header(struct Plugin *plugin, 703get_wlan_header (struct Plugin *plugin,
688 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *header, 704 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *header,
689 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, 705 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
690 unsigned int size) 706 unsigned int size)
691{ 707{
692 const int rate = 11000000; 708 const int rate = 11000000;
693 709
694 header->frame_control = htons(IEEE80211_FC0_TYPE_DATA); 710 header->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
695 header->addr1 = *to_mac_addr; 711 header->addr1 = *to_mac_addr;
696 header->addr2 = plugin->mac_address; 712 header->addr2 = plugin->mac_address;
697 header->addr3 = mac_bssid_gnunet; 713 header->addr3 = mac_bssid_gnunet;
698 header->duration = GNUNET_htole16((size * 1000000) / rate + 290); 714 header->duration = GNUNET_htole16 ((size * 1000000) / rate + 290);
699 header->sequence_control = 0; // FIXME? 715 header->sequence_control = 0; // FIXME?
700 header->llc[0] = WLAN_LLC_DSAP_FIELD; 716 header->llc[0] = WLAN_LLC_DSAP_FIELD;
701 header->llc[1] = WLAN_LLC_SSAP_FIELD; 717 header->llc[1] = WLAN_LLC_SSAP_FIELD;
@@ -712,44 +728,45 @@ get_wlan_header(struct Plugin *plugin,
712 * @param hdr pointer to the hdr where the ack is stored 728 * @param hdr pointer to the hdr where the ack is stored
713 */ 729 */
714static void 730static void
715send_ack(void *cls, 731send_ack (void *cls,
716 uint32_t msg_id, 732 uint32_t msg_id,
717 const struct GNUNET_MessageHeader *hdr) 733 const struct GNUNET_MessageHeader *hdr)
718{ 734{
719 struct MacEndpoint *endpoint = cls; 735 struct MacEndpoint *endpoint = cls;
720 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage* radio_header; 736 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*radio_header;
721 uint16_t msize = ntohs(hdr->size); 737 uint16_t msize = ntohs (hdr->size);
722 size_t size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize; 738 size_t size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)
739 + msize;
723 char buf[size]; 740 char buf[size];
724 741
725 if (NULL == endpoint) 742 if (NULL == endpoint)
726 { 743 {
727 GNUNET_break(0); 744 GNUNET_break (0);
728 return; 745 return;
729 } 746 }
730 if (size >= GNUNET_MAX_MESSAGE_SIZE) 747 if (size >= GNUNET_MAX_MESSAGE_SIZE)
731 { 748 {
732 GNUNET_break(0); 749 GNUNET_break (0);
733 return; 750 return;
734 } 751 }
735 LOG(GNUNET_ERROR_TYPE_DEBUG, 752 LOG (GNUNET_ERROR_TYPE_DEBUG,
736 "Sending ACK to %s\n", 753 "Sending ACK to %s\n",
737 mac_to_string(&endpoint->wlan_addr.mac)); 754 mac_to_string (&endpoint->wlan_addr.mac));
738 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)buf; 755 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
739 get_radiotap_header(endpoint, radio_header, size); 756 get_radiotap_header (endpoint, radio_header, size);
740 get_wlan_header(endpoint->plugin, 757 get_wlan_header (endpoint->plugin,
741 &radio_header->frame, 758 &radio_header->frame,
742 &endpoint->wlan_addr.mac, 759 &endpoint->wlan_addr.mac,
743 sizeof(endpoint->wlan_addr.mac)); 760 sizeof(endpoint->wlan_addr.mac));
744 GNUNET_memcpy(&radio_header[1], hdr, msize); 761 GNUNET_memcpy (&radio_header[1], hdr, msize);
745 if (NULL != 762 if (NULL !=
746 GNUNET_HELPER_send(endpoint->plugin->suid_helper, 763 GNUNET_HELPER_send (endpoint->plugin->suid_helper,
747 &radio_header->header, 764 &radio_header->header,
748 GNUNET_NO /* dropping ACKs is bad */, 765 GNUNET_NO /* dropping ACKs is bad */,
749 NULL, NULL)) 766 NULL, NULL))
750 GNUNET_STATISTICS_update(endpoint->plugin->env->stats, 767 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
751 _("# ACKs sent"), 768 _ ("# ACKs sent"),
752 1, GNUNET_NO); 769 1, GNUNET_NO);
753} 770}
754 771
755 772
@@ -760,24 +777,24 @@ send_ack(void *cls,
760 * @param hdr pointer to the data 777 * @param hdr pointer to the data
761 */ 778 */
762static void 779static void
763wlan_data_message_handler(void *cls, 780wlan_data_message_handler (void *cls,
764 const struct GNUNET_MessageHeader *hdr) 781 const struct GNUNET_MessageHeader *hdr)
765{ 782{
766 struct MacEndpoint *endpoint = cls; 783 struct MacEndpoint *endpoint = cls;
767 struct Plugin *plugin = endpoint->plugin; 784 struct Plugin *plugin = endpoint->plugin;
768 struct MacAndSession mas; 785 struct MacAndSession mas;
769 786
770 GNUNET_STATISTICS_update(plugin->env->stats, 787 GNUNET_STATISTICS_update (plugin->env->stats,
771 _("# Messages defragmented"), 788 _ ("# Messages defragmented"),
772 1, 789 1,
773 GNUNET_NO); 790 GNUNET_NO);
774 mas.session = NULL; 791 mas.session = NULL;
775 mas.endpoint = endpoint; 792 mas.endpoint = endpoint;
776 (void)GNUNET_SERVER_mst_receive(plugin->fragment_data_tokenizer, 793 (void) GNUNET_SERVER_mst_receive (plugin->fragment_data_tokenizer,
777 &mas, 794 &mas,
778 (const char *)hdr, 795 (const char *) hdr,
779 ntohs(hdr->size), 796 ntohs (hdr->size),
780 GNUNET_YES, GNUNET_NO); 797 GNUNET_YES, GNUNET_NO);
781} 798}
782 799
783 800
@@ -788,32 +805,32 @@ wlan_data_message_handler(void *cls,
788 * @param session the session free 805 * @param session the session free
789 */ 806 */
790static int 807static int
791wlan_plugin_disconnect_session(void *cls, 808wlan_plugin_disconnect_session (void *cls,
792 struct GNUNET_ATS_Session *session) 809 struct GNUNET_ATS_Session *session)
793{ 810{
794 struct MacEndpoint *endpoint = session->mac; 811 struct MacEndpoint *endpoint = session->mac;
795 struct Plugin *plugin = endpoint->plugin; 812 struct Plugin *plugin = endpoint->plugin;
796 813
797 plugin->env->session_end(plugin->env->cls, 814 plugin->env->session_end (plugin->env->cls,
798 session->address, 815 session->address,
799 session); 816 session);
800 notify_session_monitor(plugin, 817 notify_session_monitor (plugin,
801 session, 818 session,
802 GNUNET_TRANSPORT_SS_DONE); 819 GNUNET_TRANSPORT_SS_DONE);
803 GNUNET_CONTAINER_DLL_remove(endpoint->sessions_head, 820 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head,
804 endpoint->sessions_tail, 821 endpoint->sessions_tail,
805 session); 822 session);
806 if (session->timeout_task != NULL) 823 if (session->timeout_task != NULL)
807 { 824 {
808 GNUNET_SCHEDULER_cancel(session->timeout_task); 825 GNUNET_SCHEDULER_cancel (session->timeout_task);
809 session->timeout_task = NULL; 826 session->timeout_task = NULL;
810 } 827 }
811 GNUNET_STATISTICS_update(plugin->env->stats, 828 GNUNET_STATISTICS_update (plugin->env->stats,
812 _("# Sessions allocated"), 829 _ ("# Sessions allocated"),
813 -1, 830 -1,
814 GNUNET_NO); 831 GNUNET_NO);
815 GNUNET_HELLO_address_free(session->address); 832 GNUNET_HELLO_address_free (session->address);
816 GNUNET_free(session); 833 GNUNET_free (session);
817 return GNUNET_OK; 834 return GNUNET_OK;
818} 835}
819 836
@@ -827,7 +844,7 @@ wlan_plugin_disconnect_session(void *cls,
827 * @return keepalive factor 844 * @return keepalive factor
828 */ 845 */
829static unsigned int 846static unsigned int
830wlan_plugin_query_keepalive_factor(void *cls) 847wlan_plugin_query_keepalive_factor (void *cls)
831{ 848{
832 return 3; 849 return 3;
833} 850}
@@ -839,23 +856,23 @@ wlan_plugin_query_keepalive_factor(void *cls)
839 * @param cls pointer to the Session 856 * @param cls pointer to the Session
840 */ 857 */
841static void 858static void
842session_timeout(void *cls) 859session_timeout (void *cls)
843{ 860{
844 struct GNUNET_ATS_Session *session = cls; 861 struct GNUNET_ATS_Session *session = cls;
845 struct GNUNET_TIME_Relative left; 862 struct GNUNET_TIME_Relative left;
846 863
847 session->timeout_task = NULL; 864 session->timeout_task = NULL;
848 left = GNUNET_TIME_absolute_get_remaining(session->timeout); 865 left = GNUNET_TIME_absolute_get_remaining (session->timeout);
849 if (0 != left.rel_value_us) 866 if (0 != left.rel_value_us)
850 { 867 {
851 session->timeout_task = 868 session->timeout_task =
852 GNUNET_SCHEDULER_add_delayed(left, 869 GNUNET_SCHEDULER_add_delayed (left,
853 &session_timeout, 870 &session_timeout,
854 session); 871 session);
855 return; 872 return;
856 } 873 }
857 wlan_plugin_disconnect_session(session->mac->plugin, 874 wlan_plugin_disconnect_session (session->mac->plugin,
858 session); 875 session);
859} 876}
860 877
861 878
@@ -868,13 +885,15 @@ session_timeout(void *cls)
868 * @return returns the session or NULL 885 * @return returns the session or NULL
869 */ 886 */
870static struct GNUNET_ATS_Session * 887static struct GNUNET_ATS_Session *
871lookup_session(struct MacEndpoint *endpoint, 888lookup_session (struct MacEndpoint *endpoint,
872 const struct GNUNET_PeerIdentity *peer) 889 const struct GNUNET_PeerIdentity *peer)
873{ 890{
874 struct GNUNET_ATS_Session *session; 891 struct GNUNET_ATS_Session *session;
875 892
876 for (session = endpoint->sessions_head; NULL != session; session = session->next) 893 for (session = endpoint->sessions_head; NULL != session; session =
877 if (0 == memcmp(peer, &session->target, sizeof(struct GNUNET_PeerIdentity))) 894 session->next)
895 if (0 == memcmp (peer, &session->target, sizeof(struct
896 GNUNET_PeerIdentity)))
878 return session; 897 return session;
879 return NULL; 898 return NULL;
880} 899}
@@ -888,41 +907,43 @@ lookup_session(struct MacEndpoint *endpoint,
888 * @return returns the session or NULL 907 * @return returns the session or NULL
889 */ 908 */
890static struct GNUNET_ATS_Session * 909static struct GNUNET_ATS_Session *
891create_session(struct MacEndpoint *endpoint, 910create_session (struct MacEndpoint *endpoint,
892 const struct GNUNET_PeerIdentity *peer) 911 const struct GNUNET_PeerIdentity *peer)
893{ 912{
894 struct GNUNET_ATS_Session *session; 913 struct GNUNET_ATS_Session *session;
895 914
896 GNUNET_STATISTICS_update(endpoint->plugin->env->stats, 915 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
897 _("# Sessions allocated"), 916 _ ("# Sessions allocated"),
898 1, 917 1,
899 GNUNET_NO); 918 GNUNET_NO);
900 session = GNUNET_new(struct GNUNET_ATS_Session); 919 session = GNUNET_new (struct GNUNET_ATS_Session);
901 GNUNET_CONTAINER_DLL_insert_tail(endpoint->sessions_head, 920 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
902 endpoint->sessions_tail, 921 endpoint->sessions_tail,
903 session); 922 session);
904 session->address = GNUNET_HELLO_address_allocate(peer, 923 session->address = GNUNET_HELLO_address_allocate (peer,
905 PLUGIN_NAME, 924 PLUGIN_NAME,
906 &endpoint->wlan_addr, 925 &endpoint->wlan_addr,
907 sizeof(endpoint->wlan_addr), 926 sizeof(endpoint->wlan_addr),
908 GNUNET_HELLO_ADDRESS_INFO_NONE); 927 GNUNET_HELLO_ADDRESS_INFO_NONE);
909 session->mac = endpoint; 928 session->mac = endpoint;
910 session->target = *peer; 929 session->target = *peer;
911 session->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 930 session->timeout = GNUNET_TIME_relative_to_absolute (
931 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
912 session->timeout_task = 932 session->timeout_task =
913 GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, 933 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
914 session); 934 &session_timeout,
915 notify_session_monitor(endpoint->plugin, 935 session);
916 session, 936 notify_session_monitor (endpoint->plugin,
917 GNUNET_TRANSPORT_SS_INIT); 937 session,
918 notify_session_monitor(endpoint->plugin, 938 GNUNET_TRANSPORT_SS_INIT);
919 session, 939 notify_session_monitor (endpoint->plugin,
920 GNUNET_TRANSPORT_SS_UP); 940 session,
921 LOG(GNUNET_ERROR_TYPE_DEBUG, 941 GNUNET_TRANSPORT_SS_UP);
922 "Created new session %p for peer `%s' with endpoint %s\n", 942 LOG (GNUNET_ERROR_TYPE_DEBUG,
923 session, 943 "Created new session %p for peer `%s' with endpoint %s\n",
924 GNUNET_i2s(peer), 944 session,
925 mac_to_string(&endpoint->wlan_addr.mac)); 945 GNUNET_i2s (peer),
946 mac_to_string (&endpoint->wlan_addr.mac));
926 947
927 return session; 948 return session;
928} 949}
@@ -936,14 +957,14 @@ create_session(struct MacEndpoint *endpoint,
936 * @return returns the session 957 * @return returns the session
937 */ 958 */
938static struct GNUNET_ATS_Session * 959static struct GNUNET_ATS_Session *
939get_session(struct MacEndpoint *endpoint, 960get_session (struct MacEndpoint *endpoint,
940 const struct GNUNET_PeerIdentity *peer) 961 const struct GNUNET_PeerIdentity *peer)
941{ 962{
942 struct GNUNET_ATS_Session *session; 963 struct GNUNET_ATS_Session *session;
943 964
944 if (NULL != (session = lookup_session(endpoint, peer))) 965 if (NULL != (session = lookup_session (endpoint, peer)))
945 return session; 966 return session;
946 return create_session(endpoint, peer); 967 return create_session (endpoint, peer);
947} 968}
948 969
949 970
@@ -958,13 +979,13 @@ get_session(struct MacEndpoint *endpoint,
958 * if the helper was stopped) 979 * if the helper was stopped)
959 */ 980 */
960static void 981static void
961fragment_transmission_done(void *cls, 982fragment_transmission_done (void *cls,
962 int result) 983 int result)
963{ 984{
964 struct FragmentMessage *fm = cls; 985 struct FragmentMessage *fm = cls;
965 986
966 fm->sh = NULL; 987 fm->sh = NULL;
967 GNUNET_FRAGMENT_context_transmission_done(fm->fragcontext); 988 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
968} 989}
969 990
970 991
@@ -975,8 +996,8 @@ fragment_transmission_done(void *cls,
975 * @param hdr pointer to the start of the fragment message 996 * @param hdr pointer to the start of the fragment message
976 */ 997 */
977static void 998static void
978transmit_fragment(void *cls, 999transmit_fragment (void *cls,
979 const struct GNUNET_MessageHeader *hdr) 1000 const struct GNUNET_MessageHeader *hdr)
980{ 1001{
981 struct FragmentMessage *fm = cls; 1002 struct FragmentMessage *fm = cls;
982 struct MacEndpoint *endpoint = fm->macendpoint; 1003 struct MacEndpoint *endpoint = fm->macendpoint;
@@ -984,51 +1005,51 @@ transmit_fragment(void *cls,
984 uint16_t msize; 1005 uint16_t msize;
985 1006
986 if (NULL == endpoint) 1007 if (NULL == endpoint)
987 { 1008 {
988 GNUNET_break(0); 1009 GNUNET_break (0);
989 return; 1010 return;
990 } 1011 }
991 msize = ntohs(hdr->size); 1012 msize = ntohs (hdr->size);
992 size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize; 1013 size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
993 { 1014 {
994 char buf[size]; 1015 char buf[size];
995 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radio_header; 1016 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radio_header;
996 1017
997 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)buf; 1018 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
998 get_radiotap_header(endpoint, radio_header, size); 1019 get_radiotap_header (endpoint, radio_header, size);
999 LOG(GNUNET_ERROR_TYPE_DEBUG, 1020 LOG (GNUNET_ERROR_TYPE_DEBUG,
1000 "Sending %u bytes of data to MAC `%s'\n", 1021 "Sending %u bytes of data to MAC `%s'\n",
1001 (unsigned int)msize, 1022 (unsigned int) msize,
1002 mac_to_string(&endpoint->wlan_addr.mac)); 1023 mac_to_string (&endpoint->wlan_addr.mac));
1003 1024
1004 get_wlan_header(endpoint->plugin, 1025 get_wlan_header (endpoint->plugin,
1005 &radio_header->frame, 1026 &radio_header->frame,
1006 &endpoint->wlan_addr.mac, 1027 &endpoint->wlan_addr.mac,
1007 sizeof(endpoint->wlan_addr.mac)); 1028 sizeof(endpoint->wlan_addr.mac));
1008 GNUNET_memcpy(&radio_header[1], hdr, msize); 1029 GNUNET_memcpy (&radio_header[1], hdr, msize);
1009 GNUNET_assert(NULL == fm->sh); 1030 GNUNET_assert (NULL == fm->sh);
1010 fm->sh = GNUNET_HELPER_send(endpoint->plugin->suid_helper, 1031 fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper,
1011 &radio_header->header, 1032 &radio_header->header,
1012 GNUNET_NO, 1033 GNUNET_NO,
1013 &fragment_transmission_done, fm); 1034 &fragment_transmission_done, fm);
1014 fm->size_on_wire += size; 1035 fm->size_on_wire += size;
1015 if (NULL != fm->sh) 1036 if (NULL != fm->sh)
1016 { 1037 {
1017 GNUNET_STATISTICS_update(endpoint->plugin->env->stats, 1038 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
1018 _("# message fragments sent"), 1039 _ ("# message fragments sent"),
1019 1, 1040 1,
1020 GNUNET_NO); 1041 GNUNET_NO);
1021 } 1042 }
1022 else 1043 else
1023 { 1044 {
1024 GNUNET_FRAGMENT_context_transmission_done(fm->fragcontext); 1045 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
1025 } 1046 }
1026 GNUNET_STATISTICS_update(endpoint->plugin->env->stats, 1047 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
1027 "# bytes currently in buffers", 1048 "# bytes currently in buffers",
1028 -msize, GNUNET_NO); 1049 -msize, GNUNET_NO);
1029 GNUNET_STATISTICS_update(endpoint->plugin->env->stats, 1050 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
1030 "# bytes transmitted", 1051 "# bytes transmitted",
1031 msize, GNUNET_NO); 1052 msize, GNUNET_NO);
1032 } 1053 }
1033} 1054}
1034 1055
@@ -1039,39 +1060,39 @@ transmit_fragment(void *cls,
1039 * @param fm message to free 1060 * @param fm message to free
1040 */ 1061 */
1041static void 1062static void
1042free_fragment_message(struct FragmentMessage *fm) 1063free_fragment_message (struct FragmentMessage *fm)
1043{ 1064{
1044 struct MacEndpoint *endpoint = fm->macendpoint; 1065 struct MacEndpoint *endpoint = fm->macendpoint;
1045 1066
1046 GNUNET_STATISTICS_update(endpoint->plugin->env->stats, 1067 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
1047 _("# messages pending (with fragmentation)"), 1068 _ ("# messages pending (with fragmentation)"),
1048 -1, GNUNET_NO); 1069 -1, GNUNET_NO);
1049 GNUNET_CONTAINER_DLL_remove(endpoint->sending_messages_head, 1070 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
1050 endpoint->sending_messages_tail, 1071 endpoint->sending_messages_tail,
1051 fm); 1072 fm);
1052 if (NULL != fm->sh) 1073 if (NULL != fm->sh)
1053 { 1074 {
1054 GNUNET_HELPER_send_cancel(fm->sh); 1075 GNUNET_HELPER_send_cancel (fm->sh);
1055 fm->sh = NULL; 1076 fm->sh = NULL;
1056 } 1077 }
1057 if (NULL != fm->msg) 1078 if (NULL != fm->msg)
1058 { 1079 {
1059 GNUNET_free(fm->msg); 1080 GNUNET_free (fm->msg);
1060 fm->msg = NULL; 1081 fm->msg = NULL;
1061 } 1082 }
1062 if (NULL != fm->fragcontext) 1083 if (NULL != fm->fragcontext)
1063 { 1084 {
1064 GNUNET_FRAGMENT_context_destroy(fm->fragcontext, 1085 GNUNET_FRAGMENT_context_destroy (fm->fragcontext,
1065 &endpoint->msg_delay, 1086 &endpoint->msg_delay,
1066 &endpoint->ack_delay); 1087 &endpoint->ack_delay);
1067 fm->fragcontext = NULL; 1088 fm->fragcontext = NULL;
1068 } 1089 }
1069 if (NULL != fm->timeout_task) 1090 if (NULL != fm->timeout_task)
1070 { 1091 {
1071 GNUNET_SCHEDULER_cancel(fm->timeout_task); 1092 GNUNET_SCHEDULER_cancel (fm->timeout_task);
1072 fm->timeout_task = NULL; 1093 fm->timeout_task = NULL;
1073 } 1094 }
1074 GNUNET_free(fm); 1095 GNUNET_free (fm);
1075} 1096}
1076 1097
1077 1098
@@ -1081,21 +1102,21 @@ free_fragment_message(struct FragmentMessage *fm)
1081 * @param cls pointer to the 'struct FragmentMessage' 1102 * @param cls pointer to the 'struct FragmentMessage'
1082 */ 1103 */
1083static void 1104static void
1084fragmentmessage_timeout(void *cls) 1105fragmentmessage_timeout (void *cls)
1085{ 1106{
1086 struct FragmentMessage *fm = cls; 1107 struct FragmentMessage *fm = cls;
1087 1108
1088 fm->timeout_task = NULL; 1109 fm->timeout_task = NULL;
1089 if (NULL != fm->cont) 1110 if (NULL != fm->cont)
1090 { 1111 {
1091 fm->cont(fm->cont_cls, 1112 fm->cont (fm->cont_cls,
1092 &fm->target, 1113 &fm->target,
1093 GNUNET_SYSERR, 1114 GNUNET_SYSERR,
1094 fm->size_payload, 1115 fm->size_payload,
1095 fm->size_on_wire); 1116 fm->size_on_wire);
1096 fm->cont = NULL; 1117 fm->cont = NULL;
1097 } 1118 }
1098 free_fragment_message(fm); 1119 free_fragment_message (fm);
1099} 1120}
1100 1121
1101 1122
@@ -1114,49 +1135,49 @@ fragmentmessage_timeout(void *cls)
1114 * @param cont_cls closure for @a cont 1135 * @param cont_cls closure for @a cont
1115 */ 1136 */
1116static void 1137static void
1117send_with_fragmentation(struct MacEndpoint *endpoint, 1138send_with_fragmentation (struct MacEndpoint *endpoint,
1118 struct GNUNET_TIME_Relative timeout, 1139 struct GNUNET_TIME_Relative timeout,
1119 const struct GNUNET_PeerIdentity *target, 1140 const struct GNUNET_PeerIdentity *target,
1120 const struct GNUNET_MessageHeader *msg, 1141 const struct GNUNET_MessageHeader *msg,
1121 size_t payload_size, 1142 size_t payload_size,
1122 GNUNET_TRANSPORT_TransmitContinuation cont, 1143 GNUNET_TRANSPORT_TransmitContinuation cont,
1123 void *cont_cls) 1144 void *cont_cls)
1124 1145
1125{ 1146{
1126 struct FragmentMessage *fm; 1147 struct FragmentMessage *fm;
1127 struct Plugin *plugin; 1148 struct Plugin *plugin;
1128 1149
1129 plugin = endpoint->plugin; 1150 plugin = endpoint->plugin;
1130 fm = GNUNET_new(struct FragmentMessage); 1151 fm = GNUNET_new (struct FragmentMessage);
1131 fm->macendpoint = endpoint; 1152 fm->macendpoint = endpoint;
1132 fm->target = *target; 1153 fm->target = *target;
1133 fm->size_payload = payload_size; 1154 fm->size_payload = payload_size;
1134 fm->timeout = GNUNET_TIME_relative_to_absolute(timeout); 1155 fm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1135 fm->cont = cont; 1156 fm->cont = cont;
1136 fm->cont_cls = cont_cls; 1157 fm->cont_cls = cont_cls;
1137 /* 1 MBit/s typical data rate, 1430 byte fragments => ~100 ms per message */ 1158 /* 1 MBit/s typical data rate, 1430 byte fragments => ~100 ms per message */
1138 fm->timeout_task = 1159 fm->timeout_task =
1139 GNUNET_SCHEDULER_add_delayed(timeout, 1160 GNUNET_SCHEDULER_add_delayed (timeout,
1140 &fragmentmessage_timeout, 1161 &fragmentmessage_timeout,
1141 fm); 1162 fm);
1142 if (GNUNET_YES == plugin->have_mac) 1163 if (GNUNET_YES == plugin->have_mac)
1143 { 1164 {
1144 fm->fragcontext = 1165 fm->fragcontext =
1145 GNUNET_FRAGMENT_context_create(plugin->env->stats, 1166 GNUNET_FRAGMENT_context_create (plugin->env->stats,
1146 WLAN_MTU, 1167 WLAN_MTU,
1147 &plugin->tracker, 1168 &plugin->tracker,
1148 fm->macendpoint->msg_delay, 1169 fm->macendpoint->msg_delay,
1149 fm->macendpoint->ack_delay, 1170 fm->macendpoint->ack_delay,
1150 msg, 1171 msg,
1151 &transmit_fragment, fm); 1172 &transmit_fragment, fm);
1152 } 1173 }
1153 else 1174 else
1154 { 1175 {
1155 fm->msg = GNUNET_copy_message(msg); 1176 fm->msg = GNUNET_copy_message (msg);
1156 } 1177 }
1157 GNUNET_CONTAINER_DLL_insert_tail(endpoint->sending_messages_head, 1178 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sending_messages_head,
1158 endpoint->sending_messages_tail, 1179 endpoint->sending_messages_tail,
1159 fm); 1180 fm);
1160} 1181}
1161 1182
1162 1183
@@ -1166,38 +1187,38 @@ send_with_fragmentation(struct MacEndpoint *endpoint,
1166 * @param endpoint pointer to the MacEndpoint to free 1187 * @param endpoint pointer to the MacEndpoint to free
1167 */ 1188 */
1168static void 1189static void
1169free_macendpoint(struct MacEndpoint *endpoint) 1190free_macendpoint (struct MacEndpoint *endpoint)
1170{ 1191{
1171 struct Plugin *plugin = endpoint->plugin; 1192 struct Plugin *plugin = endpoint->plugin;
1172 struct FragmentMessage *fm; 1193 struct FragmentMessage *fm;
1173 struct GNUNET_ATS_Session *session; 1194 struct GNUNET_ATS_Session *session;
1174 1195
1175 GNUNET_STATISTICS_update(plugin->env->stats, 1196 GNUNET_STATISTICS_update (plugin->env->stats,
1176 _("# MAC endpoints allocated"), 1197 _ ("# MAC endpoints allocated"),
1177 -1, 1198 -1,
1178 GNUNET_NO); 1199 GNUNET_NO);
1179 while (NULL != (session = endpoint->sessions_head)) 1200 while (NULL != (session = endpoint->sessions_head))
1180 wlan_plugin_disconnect_session(plugin, 1201 wlan_plugin_disconnect_session (plugin,
1181 session); 1202 session);
1182 while (NULL != (fm = endpoint->sending_messages_head)) 1203 while (NULL != (fm = endpoint->sending_messages_head))
1183 free_fragment_message(fm); 1204 free_fragment_message (fm);
1184 GNUNET_CONTAINER_DLL_remove(plugin->mac_head, 1205 GNUNET_CONTAINER_DLL_remove (plugin->mac_head,
1185 plugin->mac_tail, 1206 plugin->mac_tail,
1186 endpoint); 1207 endpoint);
1187 1208
1188 if (NULL != endpoint->defrag) 1209 if (NULL != endpoint->defrag)
1189 { 1210 {
1190 GNUNET_DEFRAGMENT_context_destroy(endpoint->defrag); 1211 GNUNET_DEFRAGMENT_context_destroy (endpoint->defrag);
1191 endpoint->defrag = NULL; 1212 endpoint->defrag = NULL;
1192 } 1213 }
1193 1214
1194 plugin->mac_count--; 1215 plugin->mac_count--;
1195 if (NULL != endpoint->timeout_task) 1216 if (NULL != endpoint->timeout_task)
1196 { 1217 {
1197 GNUNET_SCHEDULER_cancel(endpoint->timeout_task); 1218 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
1198 endpoint->timeout_task = NULL; 1219 endpoint->timeout_task = NULL;
1199 } 1220 }
1200 GNUNET_free(endpoint); 1221 GNUNET_free (endpoint);
1201} 1222}
1202 1223
1203 1224
@@ -1207,22 +1228,22 @@ free_macendpoint(struct MacEndpoint *endpoint)
1207 * @param cls pointer to the `struct MacEndpoint *` 1228 * @param cls pointer to the `struct MacEndpoint *`
1208 */ 1229 */
1209static void 1230static void
1210macendpoint_timeout(void *cls) 1231macendpoint_timeout (void *cls)
1211{ 1232{
1212 struct MacEndpoint *endpoint = cls; 1233 struct MacEndpoint *endpoint = cls;
1213 struct GNUNET_TIME_Relative timeout; 1234 struct GNUNET_TIME_Relative timeout;
1214 1235
1215 endpoint->timeout_task = NULL; 1236 endpoint->timeout_task = NULL;
1216 timeout = GNUNET_TIME_absolute_get_remaining(endpoint->timeout); 1237 timeout = GNUNET_TIME_absolute_get_remaining (endpoint->timeout);
1217 if (0 == timeout.rel_value_us) 1238 if (0 == timeout.rel_value_us)
1218 { 1239 {
1219 free_macendpoint(endpoint); 1240 free_macendpoint (endpoint);
1220 return; 1241 return;
1221 } 1242 }
1222 endpoint->timeout_task = 1243 endpoint->timeout_task =
1223 GNUNET_SCHEDULER_add_delayed(timeout, 1244 GNUNET_SCHEDULER_add_delayed (timeout,
1224 &macendpoint_timeout, 1245 &macendpoint_timeout,
1225 endpoint); 1246 endpoint);
1226} 1247}
1227 1248
1228 1249
@@ -1234,43 +1255,44 @@ macendpoint_timeout(void *cls)
1234 * @return handle to our data structure for this MAC 1255 * @return handle to our data structure for this MAC
1235 */ 1256 */
1236static struct MacEndpoint * 1257static struct MacEndpoint *
1237create_macendpoint(struct Plugin *plugin, 1258create_macendpoint (struct Plugin *plugin,
1238 struct WlanAddress *mac) 1259 struct WlanAddress *mac)
1239{ 1260{
1240 struct MacEndpoint *pos; 1261 struct MacEndpoint *pos;
1241 1262
1242 for (pos = plugin->mac_head; NULL != pos; pos = pos->next) 1263 for (pos = plugin->mac_head; NULL != pos; pos = pos->next)
1243 if (0 == memcmp(mac, &pos->wlan_addr, sizeof(pos->wlan_addr))) 1264 if (0 == memcmp (mac, &pos->wlan_addr, sizeof(pos->wlan_addr)))
1244 return pos; 1265 return pos;
1245 pos = GNUNET_new(struct MacEndpoint); 1266 pos = GNUNET_new (struct MacEndpoint);
1246 pos->wlan_addr = (*mac); 1267 pos->wlan_addr = (*mac);
1247 pos->plugin = plugin; 1268 pos->plugin = plugin;
1248 pos->defrag = 1269 pos->defrag =
1249 GNUNET_DEFRAGMENT_context_create(plugin->env->stats, 1270 GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
1250 WLAN_MTU, 1271 WLAN_MTU,
1251 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC, 1272 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
1252 pos, 1273 pos,
1253 &wlan_data_message_handler, 1274 &wlan_data_message_handler,
1254 &send_ack); 1275 &send_ack);
1255 1276
1256 pos->msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; 1277 pos->msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
1257 pos->ack_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100); 1278 pos->ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1258 pos->timeout = GNUNET_TIME_relative_to_absolute(MACENDPOINT_TIMEOUT); 1279 100);
1280 pos->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
1259 pos->timeout_task = 1281 pos->timeout_task =
1260 GNUNET_SCHEDULER_add_delayed(MACENDPOINT_TIMEOUT, &macendpoint_timeout, 1282 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
1261 pos); 1283 pos);
1262 GNUNET_CONTAINER_DLL_insert(plugin->mac_head, 1284 GNUNET_CONTAINER_DLL_insert (plugin->mac_head,
1263 plugin->mac_tail, 1285 plugin->mac_tail,
1264 pos); 1286 pos);
1265 plugin->mac_count++; 1287 plugin->mac_count++;
1266 GNUNET_STATISTICS_update(plugin->env->stats, 1288 GNUNET_STATISTICS_update (plugin->env->stats,
1267 _("# MAC endpoints allocated"), 1289 _ ("# MAC endpoints allocated"),
1268 1, GNUNET_NO); 1290 1, GNUNET_NO);
1269 LOG(GNUNET_ERROR_TYPE_DEBUG, 1291 LOG (GNUNET_ERROR_TYPE_DEBUG,
1270 "New MAC endpoint `%s'\n", 1292 "New MAC endpoint `%s'\n",
1271 wlan_plugin_address_to_string(NULL, 1293 wlan_plugin_address_to_string (NULL,
1272 &pos->wlan_addr, 1294 &pos->wlan_addr,
1273 sizeof(struct WlanAddress))); 1295 sizeof(struct WlanAddress)));
1274 return pos; 1296 return pos;
1275} 1297}
1276 1298
@@ -1283,8 +1305,8 @@ create_macendpoint(struct Plugin *plugin,
1283 * @return the network type in HBO or #GNUNET_SYSERR 1305 * @return the network type in HBO or #GNUNET_SYSERR
1284 */ 1306 */
1285static enum GNUNET_NetworkType 1307static enum GNUNET_NetworkType
1286wlan_plugin_get_network(void *cls, 1308wlan_plugin_get_network (void *cls,
1287 struct GNUNET_ATS_Session *session) 1309 struct GNUNET_ATS_Session *session)
1288{ 1310{
1289#if BUILD_WLAN 1311#if BUILD_WLAN
1290 return GNUNET_NT_WLAN; 1312 return GNUNET_NT_WLAN;
@@ -1302,8 +1324,8 @@ wlan_plugin_get_network(void *cls,
1302 * @return the network type 1324 * @return the network type
1303 */ 1325 */
1304static enum GNUNET_NetworkType 1326static enum GNUNET_NetworkType
1305wlan_plugin_get_network_for_address(void *cls, 1327wlan_plugin_get_network_for_address (void *cls,
1306 const struct GNUNET_HELLO_Address *address) 1328 const struct GNUNET_HELLO_Address *address)
1307{ 1329{
1308#if BUILD_WLAN 1330#if BUILD_WLAN
1309 return GNUNET_NT_WLAN; 1331 return GNUNET_NT_WLAN;
@@ -1322,8 +1344,8 @@ wlan_plugin_get_network_for_address(void *cls,
1322 * @return the session or NULL of max connections exceeded 1344 * @return the session or NULL of max connections exceeded
1323 */ 1345 */
1324static struct GNUNET_ATS_Session * 1346static struct GNUNET_ATS_Session *
1325wlan_plugin_get_session(void *cls, 1347wlan_plugin_get_session (void *cls,
1326 const struct GNUNET_HELLO_Address *address) 1348 const struct GNUNET_HELLO_Address *address)
1327{ 1349{
1328 struct Plugin *plugin = cls; 1350 struct Plugin *plugin = cls;
1329 struct MacEndpoint *endpoint; 1351 struct MacEndpoint *endpoint;
@@ -1331,19 +1353,19 @@ wlan_plugin_get_session(void *cls,
1331 if (NULL == address) 1353 if (NULL == address)
1332 return NULL; 1354 return NULL;
1333 if (sizeof(struct WlanAddress) != address->address_length) 1355 if (sizeof(struct WlanAddress) != address->address_length)
1334 { 1356 {
1335 GNUNET_break(0); 1357 GNUNET_break (0);
1336 return NULL; 1358 return NULL;
1337 } 1359 }
1338 LOG(GNUNET_ERROR_TYPE_DEBUG, 1360 LOG (GNUNET_ERROR_TYPE_DEBUG,
1339 "Service asked to create session for peer `%s' with MAC `%s'\n", 1361 "Service asked to create session for peer `%s' with MAC `%s'\n",
1340 GNUNET_i2s(&address->peer), 1362 GNUNET_i2s (&address->peer),
1341 wlan_plugin_address_to_string(NULL, 1363 wlan_plugin_address_to_string (NULL,
1342 address->address, 1364 address->address,
1343 address->address_length)); 1365 address->address_length));
1344 endpoint = create_macendpoint(plugin, 1366 endpoint = create_macendpoint (plugin,
1345 (struct WlanAddress *)address->address); 1367 (struct WlanAddress *) address->address);
1346 return get_session(endpoint, &address->peer); 1368 return get_session (endpoint, &address->peer);
1347} 1369}
1348 1370
1349 1371
@@ -1356,21 +1378,22 @@ wlan_plugin_get_session(void *cls,
1356 * @param target peer from which to disconnect 1378 * @param target peer from which to disconnect
1357 */ 1379 */
1358static void 1380static void
1359wlan_plugin_disconnect_peer(void *cls, 1381wlan_plugin_disconnect_peer (void *cls,
1360 const struct GNUNET_PeerIdentity *target) 1382 const struct GNUNET_PeerIdentity *target)
1361{ 1383{
1362 struct Plugin *plugin = cls; 1384 struct Plugin *plugin = cls;
1363 struct GNUNET_ATS_Session *session; 1385 struct GNUNET_ATS_Session *session;
1364 struct MacEndpoint *endpoint; 1386 struct MacEndpoint *endpoint;
1365 1387
1366 for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next) 1388 for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
1367 for (session = endpoint->sessions_head; NULL != session; session = session->next) 1389 for (session = endpoint->sessions_head; NULL != session; session =
1368 if (0 == memcmp(target, &session->target, 1390 session->next)
1369 sizeof(struct GNUNET_PeerIdentity))) 1391 if (0 == memcmp (target, &session->target,
1370 { 1392 sizeof(struct GNUNET_PeerIdentity)))
1371 wlan_plugin_disconnect_session(plugin, session); 1393 {
1372 break; /* inner-loop only (in case peer has another MAC as well!) */ 1394 wlan_plugin_disconnect_session (plugin, session);
1373 } 1395 break; /* inner-loop only (in case peer has another MAC as well!) */
1396 }
1374} 1397}
1375 1398
1376 1399
@@ -1402,43 +1425,43 @@ wlan_plugin_disconnect_peer(void *cls,
1402 * and does NOT mean that the message was not transmitted (DV) 1425 * and does NOT mean that the message was not transmitted (DV)
1403 */ 1426 */
1404static ssize_t 1427static ssize_t
1405wlan_plugin_send(void *cls, 1428wlan_plugin_send (void *cls,
1406 struct GNUNET_ATS_Session *session, 1429 struct GNUNET_ATS_Session *session,
1407 const char *msgbuf, size_t msgbuf_size, 1430 const char *msgbuf, size_t msgbuf_size,
1408 unsigned int priority, 1431 unsigned int priority,
1409 struct GNUNET_TIME_Relative to, 1432 struct GNUNET_TIME_Relative to,
1410 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 1433 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1411{ 1434{
1412 struct Plugin *plugin = cls; 1435 struct Plugin *plugin = cls;
1413 struct WlanHeader *wlanheader; 1436 struct WlanHeader *wlanheader;
1414 size_t size = msgbuf_size + sizeof(struct WlanHeader); 1437 size_t size = msgbuf_size + sizeof(struct WlanHeader);
1415 char buf[size] GNUNET_ALIGN; 1438 char buf[size] GNUNET_ALIGN;
1416 1439
1417 LOG(GNUNET_ERROR_TYPE_DEBUG, 1440 LOG (GNUNET_ERROR_TYPE_DEBUG,
1418 "Transmitting %u bytes of payload to peer `%s' (starting with %u byte message of type %u)\n", 1441 "Transmitting %u bytes of payload to peer `%s' (starting with %u byte message of type %u)\n",
1419 msgbuf_size, 1442 msgbuf_size,
1420 GNUNET_i2s(&session->target), 1443 GNUNET_i2s (&session->target),
1421 (unsigned int)ntohs(((struct GNUNET_MessageHeader*)msgbuf)->size), 1444 (unsigned int) ntohs (((struct GNUNET_MessageHeader*) msgbuf)->size),
1422 (unsigned int)ntohs(((struct GNUNET_MessageHeader*)msgbuf)->type)); 1445 (unsigned int) ntohs (((struct GNUNET_MessageHeader*) msgbuf)->type));
1423 wlanheader = (struct WlanHeader *)buf; 1446 wlanheader = (struct WlanHeader *) buf;
1424 wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader)); 1447 wlanheader->header.size = htons (msgbuf_size + sizeof(struct WlanHeader));
1425 wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA); 1448 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
1426 wlanheader->sender = *plugin->env->my_identity; 1449 wlanheader->sender = *plugin->env->my_identity;
1427 wlanheader->target = session->target; 1450 wlanheader->target = session->target;
1428 wlanheader->crc = htonl(GNUNET_CRYPTO_crc32_n(msgbuf, msgbuf_size)); 1451 wlanheader->crc = htonl (GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size));
1429 GNUNET_memcpy(&wlanheader[1], 1452 GNUNET_memcpy (&wlanheader[1],
1430 msgbuf, 1453 msgbuf,
1431 msgbuf_size); 1454 msgbuf_size);
1432 GNUNET_STATISTICS_update(plugin->env->stats, 1455 GNUNET_STATISTICS_update (plugin->env->stats,
1433 "# bytes currently in buffers", 1456 "# bytes currently in buffers",
1457 msgbuf_size,
1458 GNUNET_NO);
1459 send_with_fragmentation (session->mac,
1460 to,
1461 &session->target,
1462 &wlanheader->header,
1434 msgbuf_size, 1463 msgbuf_size,
1435 GNUNET_NO); 1464 cont, cont_cls);
1436 send_with_fragmentation(session->mac,
1437 to,
1438 &session->target,
1439 &wlanheader->header,
1440 msgbuf_size,
1441 cont, cont_cls);
1442 return size; 1465 return size;
1443} 1466}
1444 1467
@@ -1452,9 +1475,9 @@ wlan_plugin_send(void *cls,
1452 * @param hdr start of the message 1475 * @param hdr start of the message
1453 */ 1476 */
1454static int 1477static int
1455process_data(void *cls, 1478process_data (void *cls,
1456 void *client, 1479 void *client,
1457 const struct GNUNET_MessageHeader *hdr) 1480 const struct GNUNET_MessageHeader *hdr)
1458{ 1481{
1459 struct Plugin *plugin = cls; 1482 struct Plugin *plugin = cls;
1460 struct GNUNET_HELLO_Address *address; 1483 struct GNUNET_HELLO_Address *address;
@@ -1465,221 +1488,224 @@ process_data(void *cls,
1465 int ret; 1488 int ret;
1466 uint16_t msize; 1489 uint16_t msize;
1467 1490
1468 msize = ntohs(hdr->size); 1491 msize = ntohs (hdr->size);
1469 1492
1470 GNUNET_STATISTICS_update(plugin->env->stats, 1493 GNUNET_STATISTICS_update (plugin->env->stats,
1471 "# bytes received", 1494 "# bytes received",
1472 msize, GNUNET_NO); 1495 msize, GNUNET_NO);
1473 1496
1474 switch (ntohs(hdr->type)) 1497 switch (ntohs (hdr->type))
1475 { 1498 {
1476 case GNUNET_MESSAGE_TYPE_HELLO: 1499 case GNUNET_MESSAGE_TYPE_HELLO:
1477 1500
1478 if (GNUNET_OK != 1501 if (GNUNET_OK !=
1479 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)hdr, 1502 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hdr,
1480 &tmpsource)) 1503 &tmpsource))
1481 { 1504 {
1482 GNUNET_break_op(0); 1505 GNUNET_break_op (0);
1483 break; 1506 break;
1484 } 1507 }
1485 if (NULL == mas->endpoint) 1508 if (NULL == mas->endpoint)
1486 { 1509 {
1487 GNUNET_break(0); 1510 GNUNET_break (0);
1488 break; 1511 break;
1489 } 1512 }
1490 1513
1491 LOG(GNUNET_ERROR_TYPE_DEBUG, 1514 LOG (GNUNET_ERROR_TYPE_DEBUG,
1492 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", 1515 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n",
1493 (unsigned int)msize, 1516 (unsigned int) msize,
1494 GNUNET_i2s(&tmpsource), 1517 GNUNET_i2s (&tmpsource),
1495 wlan_plugin_address_to_string(NULL, 1518 wlan_plugin_address_to_string (NULL,
1496 &mas->endpoint->wlan_addr, 1519 &mas->endpoint->wlan_addr,
1497 sizeof(mas->endpoint->wlan_addr))); 1520 sizeof(mas->endpoint->wlan_addr)));
1498 1521
1499 GNUNET_STATISTICS_update(plugin->env->stats, 1522 GNUNET_STATISTICS_update (plugin->env->stats,
1500 _("# HELLO messages received"), 1, 1523 _ ("# HELLO messages received"), 1,
1501 GNUNET_NO); 1524 GNUNET_NO);
1502 address = GNUNET_HELLO_address_allocate(&tmpsource, 1525 address = GNUNET_HELLO_address_allocate (&tmpsource,
1503 PLUGIN_NAME, 1526 PLUGIN_NAME,
1504 &mas->endpoint->wlan_addr, 1527 &mas->endpoint->wlan_addr,
1505 sizeof(mas->endpoint->wlan_addr), 1528 sizeof(mas->endpoint->wlan_addr),
1506 GNUNET_HELLO_ADDRESS_INFO_NONE); 1529 GNUNET_HELLO_ADDRESS_INFO_NONE);
1507 mas->session = lookup_session(mas->endpoint, 1530 mas->session = lookup_session (mas->endpoint,
1508 &tmpsource); 1531 &tmpsource);
1509 if (NULL == mas->session) 1532 if (NULL == mas->session)
1510 { 1533 {
1511 mas->session = create_session(mas->endpoint, 1534 mas->session = create_session (mas->endpoint,
1512 &tmpsource); 1535 &tmpsource);
1513 plugin->env->session_start(plugin->env->cls, 1536 plugin->env->session_start (plugin->env->cls,
1514 address, 1537 address,
1515 mas->session, 1538 mas->session,
1516 scope); 1539 scope);
1517 } 1540 }
1518 plugin->env->receive(plugin->env->cls, 1541 plugin->env->receive (plugin->env->cls,
1519 address, 1542 address,
1520 mas->session, 1543 mas->session,
1521 hdr); 1544 hdr);
1522 GNUNET_HELLO_address_free(address); 1545 GNUNET_HELLO_address_free (address);
1546 break;
1547
1548 case GNUNET_MESSAGE_TYPE_FRAGMENT:
1549 if (NULL == mas->endpoint)
1550 {
1551 GNUNET_break (0);
1523 break; 1552 break;
1524 1553 }
1525 case GNUNET_MESSAGE_TYPE_FRAGMENT: 1554 LOG (GNUNET_ERROR_TYPE_DEBUG,
1526 if (NULL == mas->endpoint) 1555 "Processing %u bytes of FRAGMENT from MAC %s\n",
1527 { 1556 (unsigned int) msize,
1528 GNUNET_break(0); 1557 wlan_plugin_address_to_string (NULL,
1529 break;
1530 }
1531 LOG(GNUNET_ERROR_TYPE_DEBUG,
1532 "Processing %u bytes of FRAGMENT from MAC %s\n",
1533 (unsigned int)msize,
1534 wlan_plugin_address_to_string(NULL,
1535 &mas->endpoint->wlan_addr, 1558 &mas->endpoint->wlan_addr,
1536 sizeof(mas->endpoint->wlan_addr))); 1559 sizeof(mas->endpoint->wlan_addr)));
1537 GNUNET_STATISTICS_update(plugin->env->stats, 1560 GNUNET_STATISTICS_update (plugin->env->stats,
1538 _("# fragments received"), 1561 _ ("# fragments received"),
1539 1, 1562 1,
1540 GNUNET_NO); 1563 GNUNET_NO);
1541 (void)GNUNET_DEFRAGMENT_process_fragment(mas->endpoint->defrag, 1564 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag,
1542 hdr); 1565 hdr);
1543 break; 1566 break;
1544 1567
1545 case GNUNET_MESSAGE_TYPE_FRAGMENT_ACK: 1568 case GNUNET_MESSAGE_TYPE_FRAGMENT_ACK:
1546 if (NULL == mas->endpoint) 1569 if (NULL == mas->endpoint)
1547 { 1570 {
1548 GNUNET_break(0); 1571 GNUNET_break (0);
1549 break; 1572 break;
1550 } 1573 }
1551 GNUNET_STATISTICS_update(plugin->env->stats, 1574 GNUNET_STATISTICS_update (plugin->env->stats,
1552 _("# ACKs received"), 1575 _ ("# ACKs received"),
1553 1, GNUNET_NO); 1576 1, GNUNET_NO);
1554 for (fm = mas->endpoint->sending_messages_head; NULL != fm; fm = fm->next) 1577 for (fm = mas->endpoint->sending_messages_head; NULL != fm; fm = fm->next)
1578 {
1579 ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
1580 if (GNUNET_OK == ret)
1581 {
1582 LOG (GNUNET_ERROR_TYPE_DEBUG,
1583 "Got last ACK, finished message transmission to `%s' (%p)\n",
1584 wlan_plugin_address_to_string (NULL,
1585 &mas->endpoint->wlan_addr,
1586 sizeof(mas->endpoint->wlan_addr)),
1587 fm);
1588 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (
1589 MACENDPOINT_TIMEOUT);
1590 if (NULL != fm->cont)
1555 { 1591 {
1556 ret = GNUNET_FRAGMENT_process_ack(fm->fragcontext, hdr); 1592 fm->cont (fm->cont_cls,
1557 if (GNUNET_OK == ret) 1593 &fm->target,
1558 { 1594 GNUNET_OK,
1559 LOG(GNUNET_ERROR_TYPE_DEBUG, 1595 fm->size_payload,
1560 "Got last ACK, finished message transmission to `%s' (%p)\n", 1596 fm->size_on_wire);
1561 wlan_plugin_address_to_string(NULL, 1597 fm->cont = NULL;
1562 &mas->endpoint->wlan_addr,
1563 sizeof(mas->endpoint->wlan_addr)),
1564 fm);
1565 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute(MACENDPOINT_TIMEOUT);
1566 if (NULL != fm->cont)
1567 {
1568 fm->cont(fm->cont_cls,
1569 &fm->target,
1570 GNUNET_OK,
1571 fm->size_payload,
1572 fm->size_on_wire);
1573 fm->cont = NULL;
1574 }
1575 free_fragment_message(fm);
1576 break;
1577 }
1578 if (GNUNET_NO == ret)
1579 {
1580 LOG(GNUNET_ERROR_TYPE_DEBUG,
1581 "Got an ACK, message transmission to `%s' not yet finished\n",
1582 wlan_plugin_address_to_string(NULL,
1583 &mas->endpoint->wlan_addr,
1584 sizeof(mas->endpoint->wlan_addr)));
1585 break;
1586 }
1587 } 1598 }
1588 if (NULL == fm) 1599 free_fragment_message (fm);
1589 LOG(GNUNET_ERROR_TYPE_DEBUG, 1600 break;
1590 "ACK not matched against any active fragmentation with MAC `%s'\n", 1601 }
1591 wlan_plugin_address_to_string(NULL, 1602 if (GNUNET_NO == ret)
1603 {
1604 LOG (GNUNET_ERROR_TYPE_DEBUG,
1605 "Got an ACK, message transmission to `%s' not yet finished\n",
1606 wlan_plugin_address_to_string (NULL,
1607 &mas->endpoint->wlan_addr,
1608 sizeof(mas->endpoint->wlan_addr)));
1609 break;
1610 }
1611 }
1612 if (NULL == fm)
1613 LOG (GNUNET_ERROR_TYPE_DEBUG,
1614 "ACK not matched against any active fragmentation with MAC `%s'\n",
1615 wlan_plugin_address_to_string (NULL,
1592 &mas->endpoint->wlan_addr, 1616 &mas->endpoint->wlan_addr,
1593 sizeof(mas->endpoint->wlan_addr))); 1617 sizeof(mas->endpoint->wlan_addr)));
1594 break; 1618 break;
1595 1619
1596 case GNUNET_MESSAGE_TYPE_WLAN_DATA: 1620 case GNUNET_MESSAGE_TYPE_WLAN_DATA:
1597 if (NULL == mas->endpoint) 1621 if (NULL == mas->endpoint)
1598 { 1622 {
1599 GNUNET_break(0); 1623 GNUNET_break (0);
1600 break; 1624 break;
1601 } 1625 }
1602 if (msize < sizeof(struct WlanHeader)) 1626 if (msize < sizeof(struct WlanHeader))
1603 { 1627 {
1604 GNUNET_break(0); 1628 GNUNET_break (0);
1605 break; 1629 break;
1606 } 1630 }
1607 wlanheader = (const struct WlanHeader *)hdr; 1631 wlanheader = (const struct WlanHeader *) hdr;
1608 if (0 != memcmp(&wlanheader->target, 1632 if (0 != memcmp (&wlanheader->target,
1609 plugin->env->my_identity, 1633 plugin->env->my_identity,
1610 sizeof(struct GNUNET_PeerIdentity))) 1634 sizeof(struct GNUNET_PeerIdentity)))
1611 { 1635 {
1612 LOG(GNUNET_ERROR_TYPE_DEBUG, 1636 LOG (GNUNET_ERROR_TYPE_DEBUG,
1613 "Data for `%s', not for me, ignoring\n", 1637 "Data for `%s', not for me, ignoring\n",
1614 GNUNET_i2s(&wlanheader->target)); 1638 GNUNET_i2s (&wlanheader->target));
1615 break; 1639 break;
1616 } 1640 }
1617 if (ntohl(wlanheader->crc) != 1641 if (ntohl (wlanheader->crc) !=
1618 GNUNET_CRYPTO_crc32_n(&wlanheader[1], 1642 GNUNET_CRYPTO_crc32_n (&wlanheader[1],
1619 msize - sizeof(struct WlanHeader))) 1643 msize - sizeof(struct WlanHeader)))
1620 { 1644 {
1621 GNUNET_STATISTICS_update(plugin->env->stats, 1645 GNUNET_STATISTICS_update (plugin->env->stats,
1622 _("# DATA messages discarded due to CRC32 error"), 1646 _ (
1623 1, 1647 "# DATA messages discarded due to CRC32 error"),
1624 GNUNET_NO); 1648 1,
1625 break; 1649 GNUNET_NO);
1626 } 1650 break;
1627 mas->session = lookup_session(mas->endpoint, 1651 }
1628 &wlanheader->sender); 1652 mas->session = lookup_session (mas->endpoint,
1629 if (NULL == mas->session) 1653 &wlanheader->sender);
1630 { 1654 if (NULL == mas->session)
1631 mas->session = create_session(mas->endpoint, 1655 {
1632 &wlanheader->sender); 1656 mas->session = create_session (mas->endpoint,
1633 address = GNUNET_HELLO_address_allocate(&wlanheader->sender, 1657 &wlanheader->sender);
1634 PLUGIN_NAME, 1658 address = GNUNET_HELLO_address_allocate (&wlanheader->sender,
1635 &mas->endpoint->wlan_addr, 1659 PLUGIN_NAME,
1636 sizeof(struct WlanAddress), 1660 &mas->endpoint->wlan_addr,
1637 GNUNET_HELLO_ADDRESS_INFO_NONE); 1661 sizeof(struct WlanAddress),
1638 plugin->env->session_start(plugin->env->cls, 1662 GNUNET_HELLO_ADDRESS_INFO_NONE);
1639 address, 1663 plugin->env->session_start (plugin->env->cls,
1640 mas->session, 1664 address,
1641 scope); 1665 mas->session,
1642 LOG(GNUNET_ERROR_TYPE_DEBUG, 1666 scope);
1643 "Notifying transport about peer `%s''s new session %p \n", 1667 LOG (GNUNET_ERROR_TYPE_DEBUG,
1644 GNUNET_i2s(&wlanheader->sender), 1668 "Notifying transport about peer `%s''s new session %p \n",
1645 mas->session); 1669 GNUNET_i2s (&wlanheader->sender),
1646 GNUNET_HELLO_address_free(address); 1670 mas->session);
1647 } 1671 GNUNET_HELLO_address_free (address);
1648 LOG(GNUNET_ERROR_TYPE_DEBUG, 1672 }
1649 "Processing %u bytes of DATA from peer `%s'\n", 1673 LOG (GNUNET_ERROR_TYPE_DEBUG,
1650 (unsigned int)msize, 1674 "Processing %u bytes of DATA from peer `%s'\n",
1651 GNUNET_i2s(&wlanheader->sender)); 1675 (unsigned int) msize,
1652 mas->session->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1676 GNUNET_i2s (&wlanheader->sender));
1653 (void)GNUNET_SERVER_mst_receive(plugin->wlan_header_payload_tokenizer, 1677 mas->session->timeout = GNUNET_TIME_relative_to_absolute (
1678 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1679 (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer,
1654 mas, 1680 mas,
1655 (const char *)&wlanheader[1], 1681 (const char *) &wlanheader[1],
1656 msize - sizeof(struct WlanHeader), 1682 msize - sizeof(struct WlanHeader),
1657 GNUNET_YES, 1683 GNUNET_YES,
1658 GNUNET_NO); 1684 GNUNET_NO);
1659 break; 1685 break;
1660 1686
1661 default: 1687 default:
1662 if (NULL == mas->endpoint) 1688 if (NULL == mas->endpoint)
1663 { 1689 {
1664 GNUNET_break(0); 1690 GNUNET_break (0);
1665 break; 1691 break;
1666 } 1692 }
1667 if (NULL == mas->session) 1693 if (NULL == mas->session)
1668 { 1694 {
1669 GNUNET_break(0); 1695 GNUNET_break (0);
1670 break;
1671 }
1672 LOG(GNUNET_ERROR_TYPE_DEBUG,
1673 "Received packet with %u bytes of type %u from peer %s\n",
1674 (unsigned int)msize,
1675 (unsigned int)ntohs(hdr->type),
1676 GNUNET_i2s(&mas->session->target));
1677 plugin->env->receive(plugin->env->cls,
1678 mas->session->address,
1679 mas->session,
1680 hdr);
1681 break; 1696 break;
1682 } 1697 }
1698 LOG (GNUNET_ERROR_TYPE_DEBUG,
1699 "Received packet with %u bytes of type %u from peer %s\n",
1700 (unsigned int) msize,
1701 (unsigned int) ntohs (hdr->type),
1702 GNUNET_i2s (&mas->session->target));
1703 plugin->env->receive (plugin->env->cls,
1704 mas->session->address,
1705 mas->session,
1706 hdr);
1707 break;
1708 }
1683 return GNUNET_OK; 1709 return GNUNET_OK;
1684} 1710}
1685 1711
@@ -1690,7 +1716,7 @@ process_data(void *cls,
1690 * @param cls pointer to the plugin struct 1716 * @param cls pointer to the plugin struct
1691 */ 1717 */
1692static void 1718static void
1693send_hello_beacon(void *cls) 1719send_hello_beacon (void *cls)
1694{ 1720{
1695 struct Plugin *plugin = cls; 1721 struct Plugin *plugin = cls;
1696 uint16_t size; 1722 uint16_t size;
@@ -1698,42 +1724,43 @@ send_hello_beacon(void *cls)
1698 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader; 1724 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader;
1699 const struct GNUNET_MessageHeader *hello; 1725 const struct GNUNET_MessageHeader *hello;
1700 1726
1701 hello = plugin->env->get_our_hello(); 1727 hello = plugin->env->get_our_hello ();
1702 if (NULL != hello) 1728 if (NULL != hello)
1729 {
1730 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1731 GNUNET_assert (sizeof(struct WlanHeader) + hello_size <= WLAN_MTU);
1732 size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)
1733 + hello_size;
1703 { 1734 {
1704 hello_size = GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)hello); 1735 char buf[size] GNUNET_ALIGN;
1705 GNUNET_assert(sizeof(struct WlanHeader) + hello_size <= WLAN_MTU); 1736
1706 size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size; 1737 LOG (GNUNET_ERROR_TYPE_DEBUG,
1707 { 1738 "Sending %u byte HELLO beacon\n",
1708 char buf[size] GNUNET_ALIGN; 1739 (unsigned int) size);
1709 1740 radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*) buf;
1710 LOG(GNUNET_ERROR_TYPE_DEBUG, 1741 get_radiotap_header (NULL, radioHeader, size);
1711 "Sending %u byte HELLO beacon\n", 1742 LOG (GNUNET_ERROR_TYPE_DEBUG,
1712 (unsigned int)size); 1743 "Broadcasting %u bytes of data to MAC `%s'\n",
1713 radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*)buf; 1744 (unsigned int) size,
1714 get_radiotap_header(NULL, radioHeader, size); 1745 mac_to_string (&bc_all_mac));
1715 LOG(GNUNET_ERROR_TYPE_DEBUG, 1746 get_wlan_header (plugin, &radioHeader->frame, &bc_all_mac, size);
1716 "Broadcasting %u bytes of data to MAC `%s'\n", 1747 GNUNET_memcpy (&radioHeader[1], hello, hello_size);
1717 (unsigned int)size, 1748 if (NULL !=
1718 mac_to_string(&bc_all_mac)); 1749 GNUNET_HELPER_send (plugin->suid_helper,
1719 get_wlan_header(plugin, &radioHeader->frame, &bc_all_mac, size); 1750 &radioHeader->header,
1720 GNUNET_memcpy(&radioHeader[1], hello, hello_size); 1751 GNUNET_YES /* can drop */,
1721 if (NULL != 1752 NULL, NULL))
1722 GNUNET_HELPER_send(plugin->suid_helper, 1753 GNUNET_STATISTICS_update (plugin->env->stats,
1723 &radioHeader->header, 1754 _ ("# HELLO beacons sent"),
1724 GNUNET_YES /* can drop */, 1755 1, GNUNET_NO);
1725 NULL, NULL))
1726 GNUNET_STATISTICS_update(plugin->env->stats,
1727 _("# HELLO beacons sent"),
1728 1, GNUNET_NO);
1729 }
1730 } 1756 }
1757 }
1731 plugin->beacon_task = 1758 plugin->beacon_task =
1732 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 1759 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1733 (HELLO_BEACON_SCALING_FACTOR, 1760 (HELLO_BEACON_SCALING_FACTOR,
1734 plugin->mac_count + 1), 1761 plugin->mac_count + 1),
1735 &send_hello_beacon, 1762 &send_hello_beacon,
1736 plugin); 1763 plugin);
1737} 1764}
1738 1765
1739 1766
@@ -1744,8 +1771,8 @@ send_hello_beacon(void *cls)
1744 * @param hdr header of the GNUNET_MessageHeader 1771 * @param hdr header of the GNUNET_MessageHeader
1745 */ 1772 */
1746static int 1773static int
1747handle_helper_message(void *cls, 1774handle_helper_message (void *cls,
1748 const struct GNUNET_MessageHeader *hdr) 1775 const struct GNUNET_MessageHeader *hdr)
1749{ 1776{
1750 struct Plugin *plugin = cls; 1777 struct Plugin *plugin = cls;
1751 struct GNUNET_HELLO_Address *my_address; 1778 struct GNUNET_HELLO_Address *my_address;
@@ -1757,156 +1784,161 @@ handle_helper_message(void *cls,
1757 struct FragmentMessage *fm; 1784 struct FragmentMessage *fm;
1758 struct MacEndpoint *endpoint; 1785 struct MacEndpoint *endpoint;
1759 1786
1760 msize = ntohs(hdr->size); 1787 msize = ntohs (hdr->size);
1761 switch (ntohs(hdr->type)) 1788 switch (ntohs (hdr->type))
1789 {
1790 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
1791 if (msize != sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
1762 { 1792 {
1763 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL: 1793 GNUNET_break (0);
1764 if (msize != sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
1765 {
1766 GNUNET_break(0);
1767 break;
1768 }
1769 cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *)hdr;
1770 if (GNUNET_YES == plugin->have_mac)
1771 {
1772 if (0 == memcmp(&plugin->mac_address,
1773 &cm->mac,
1774 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1775 break; /* no change */
1776 /* remove old address */
1777 memset(&wa, 0, sizeof(struct WlanAddress));
1778 wa.mac = plugin->mac_address;
1779 wa.options = htonl(plugin->options);
1780 my_address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
1781 PLUGIN_NAME,
1782 &wa, sizeof(wa),
1783 GNUNET_HELLO_ADDRESS_INFO_NONE);
1784 plugin->env->notify_address(plugin->env->cls,
1785 GNUNET_NO,
1786 my_address);
1787 GNUNET_HELLO_address_free(my_address);
1788 plugin->mac_address = cm->mac;
1789 }
1790 else
1791 {
1792 plugin->mac_address = cm->mac;
1793 plugin->have_mac = GNUNET_YES;
1794 for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
1795 {
1796 for (fm = endpoint->sending_messages_head; NULL != fm; fm = fm->next)
1797 {
1798 if (NULL != fm->fragcontext)
1799 {
1800 GNUNET_break(0); /* should not happen */
1801 continue;
1802 }
1803 fm->fragcontext =
1804 GNUNET_FRAGMENT_context_create(plugin->env->stats,
1805 WLAN_MTU,
1806 &plugin->tracker,
1807 fm->macendpoint->msg_delay,
1808 fm->macendpoint->ack_delay,
1809 fm->msg,
1810 &transmit_fragment, fm);
1811 GNUNET_free(fm->msg);
1812 fm->msg = NULL;
1813 }
1814 }
1815 GNUNET_break(NULL == plugin->beacon_task);
1816 plugin->beacon_task = GNUNET_SCHEDULER_add_now(&send_hello_beacon,
1817 plugin);
1818 }
1819
1820 memset(&wa, 0, sizeof(struct WlanAddress));
1821 wa.mac = plugin->mac_address;
1822 wa.options = htonl(plugin->options);
1823 my_address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
1824 PLUGIN_NAME,
1825 &wa, sizeof(wa),
1826 GNUNET_HELLO_ADDRESS_INFO_NONE);
1827
1828 LOG(GNUNET_ERROR_TYPE_DEBUG,
1829 "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n",
1830 mac_to_string(&cm->mac),
1831 GNUNET_i2s(plugin->env->my_identity));
1832 plugin->env->notify_address(plugin->env->cls,
1833 GNUNET_YES,
1834 my_address);
1835 GNUNET_HELLO_address_free(my_address);
1836 break; 1794 break;
1837 1795 }
1838 case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: 1796 cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *) hdr;
1839 LOG(GNUNET_ERROR_TYPE_DEBUG, 1797 if (GNUNET_YES == plugin->have_mac)
1840 "Got data message from helper with %u bytes\n", 1798 {
1841 msize); 1799 if (0 == memcmp (&plugin->mac_address,
1842 GNUNET_STATISTICS_update(plugin->env->stats, 1800 &cm->mac,
1843 _("# DATA messages received"), 1, 1801 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1844 GNUNET_NO); 1802 break; /* no change */
1845 if (msize < sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)) 1803 /* remove old address */
1846 { 1804 memset (&wa, 0, sizeof(struct WlanAddress));
1847 LOG(GNUNET_ERROR_TYPE_DEBUG, 1805 wa.mac = plugin->mac_address;
1848 "Size of packet is too small (%u bytes < %u)\n", 1806 wa.options = htonl (plugin->options);
1849 msize, sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)); 1807 my_address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1850 break; 1808 PLUGIN_NAME,
1851 } 1809 &wa, sizeof(wa),
1852 rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)hdr; 1810 GNUNET_HELLO_ADDRESS_INFO_NONE);
1853 1811 plugin->env->notify_address (plugin->env->cls,
1854 /* check if message is actually for us */ 1812 GNUNET_NO,
1855 if (0 != memcmp(&rxinfo->frame.addr3, &mac_bssid_gnunet, 1813 my_address);
1856 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) 1814 GNUNET_HELLO_address_free (my_address);
1857 { 1815 plugin->mac_address = cm->mac;
1858 /* Not the GNUnet BSSID */ 1816 }
1859 break; 1817 else
1860 } 1818 {
1861 if ((0 != memcmp(&rxinfo->frame.addr1, &bc_all_mac, 1819 plugin->mac_address = cm->mac;
1862 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) && 1820 plugin->have_mac = GNUNET_YES;
1863 (0 != memcmp(&rxinfo->frame.addr1, &plugin->mac_address, 1821 for (endpoint = plugin->mac_head; NULL != endpoint; endpoint =
1864 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))) 1822 endpoint->next)
1865 { 1823 {
1866 /* Neither broadcast nor specifically for us */ 1824 for (fm = endpoint->sending_messages_head; NULL != fm; fm = fm->next)
1867 break;
1868 }
1869 if (0 == memcmp(&rxinfo->frame.addr2, &plugin->mac_address,
1870 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1871 { 1825 {
1872 /* packet is FROM us, thus not FOR us */ 1826 if (NULL != fm->fragcontext)
1873 break; 1827 {
1828 GNUNET_break (0); /* should not happen */
1829 continue;
1830 }
1831 fm->fragcontext =
1832 GNUNET_FRAGMENT_context_create (plugin->env->stats,
1833 WLAN_MTU,
1834 &plugin->tracker,
1835 fm->macendpoint->msg_delay,
1836 fm->macendpoint->ack_delay,
1837 fm->msg,
1838 &transmit_fragment, fm);
1839 GNUNET_free (fm->msg);
1840 fm->msg = NULL;
1874 } 1841 }
1842 }
1843 GNUNET_break (NULL == plugin->beacon_task);
1844 plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon,
1845 plugin);
1846 }
1875 1847
1876 GNUNET_STATISTICS_update(plugin->env->stats, 1848 memset (&wa, 0, sizeof(struct WlanAddress));
1877 _("# DATA messages processed"), 1849 wa.mac = plugin->mac_address;
1878 1, GNUNET_NO); 1850 wa.options = htonl (plugin->options);
1879 LOG(GNUNET_ERROR_TYPE_DEBUG, 1851 my_address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1880 "Receiving %u bytes of data from MAC `%s'\n", 1852 PLUGIN_NAME,
1881 (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)), 1853 &wa, sizeof(wa),
1882 mac_to_string(&rxinfo->frame.addr2)); 1854 GNUNET_HELLO_ADDRESS_INFO_NONE);
1883 LOG(GNUNET_ERROR_TYPE_DEBUG, 1855
1884 "Receiving %u bytes of data to MAC `%s'\n", 1856 LOG (GNUNET_ERROR_TYPE_DEBUG,
1885 (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)), 1857 "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n",
1886 mac_to_string(&rxinfo->frame.addr1)); 1858 mac_to_string (&cm->mac),
1887 LOG(GNUNET_ERROR_TYPE_DEBUG, 1859 GNUNET_i2s (plugin->env->my_identity));
1888 "Receiving %u bytes of data with BSSID MAC `%s'\n", 1860 plugin->env->notify_address (plugin->env->cls,
1889 (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)), 1861 GNUNET_YES,
1890 mac_to_string(&rxinfo->frame.addr3)); 1862 my_address);
1891 wa.mac = rxinfo->frame.addr2; 1863 GNUNET_HELLO_address_free (my_address);
1892 wa.options = htonl(0); 1864 break;
1893 mas.endpoint = create_macendpoint(plugin, &wa); 1865
1894 mas.session = NULL; 1866 case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER:
1895 (void)GNUNET_SERVER_mst_receive(plugin->helper_payload_tokenizer, 1867 LOG (GNUNET_ERROR_TYPE_DEBUG,
1896 &mas, 1868 "Got data message from helper with %u bytes\n",
1897 (const char*)&rxinfo[1], 1869 msize);
1898 msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage), 1870 GNUNET_STATISTICS_update (plugin->env->stats,
1899 GNUNET_YES, GNUNET_NO); 1871 _ ("# DATA messages received"), 1,
1872 GNUNET_NO);
1873 if (msize < sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage))
1874 {
1875 LOG (GNUNET_ERROR_TYPE_DEBUG,
1876 "Size of packet is too small (%u bytes < %u)\n",
1877 msize, sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage));
1900 break; 1878 break;
1879 }
1880 rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) hdr;
1901 1881
1902 default: 1882 /* check if message is actually for us */
1903 GNUNET_break(0); 1883 if (0 != memcmp (&rxinfo->frame.addr3, &mac_bssid_gnunet,
1904 LOG(GNUNET_ERROR_TYPE_ERROR, 1884 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1905 "Unexpected message of type %u (%u bytes)", 1885 {
1906 ntohs(hdr->type), 1886 /* Not the GNUnet BSSID */
1907 ntohs(hdr->size));
1908 break; 1887 break;
1909 } 1888 }
1889 if ((0 != memcmp (&rxinfo->frame.addr1, &bc_all_mac,
1890 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) &&
1891 (0 != memcmp (&rxinfo->frame.addr1, &plugin->mac_address,
1892 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))))
1893 {
1894 /* Neither broadcast nor specifically for us */
1895 break;
1896 }
1897 if (0 == memcmp (&rxinfo->frame.addr2, &plugin->mac_address,
1898 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1899 {
1900 /* packet is FROM us, thus not FOR us */
1901 break;
1902 }
1903
1904 GNUNET_STATISTICS_update (plugin->env->stats,
1905 _ ("# DATA messages processed"),
1906 1, GNUNET_NO);
1907 LOG (GNUNET_ERROR_TYPE_DEBUG,
1908 "Receiving %u bytes of data from MAC `%s'\n",
1909 (unsigned int) (msize - sizeof(struct
1910 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1911 mac_to_string (&rxinfo->frame.addr2));
1912 LOG (GNUNET_ERROR_TYPE_DEBUG,
1913 "Receiving %u bytes of data to MAC `%s'\n",
1914 (unsigned int) (msize - sizeof(struct
1915 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1916 mac_to_string (&rxinfo->frame.addr1));
1917 LOG (GNUNET_ERROR_TYPE_DEBUG,
1918 "Receiving %u bytes of data with BSSID MAC `%s'\n",
1919 (unsigned int) (msize - sizeof(struct
1920 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1921 mac_to_string (&rxinfo->frame.addr3));
1922 wa.mac = rxinfo->frame.addr2;
1923 wa.options = htonl (0);
1924 mas.endpoint = create_macendpoint (plugin, &wa);
1925 mas.session = NULL;
1926 (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer,
1927 &mas,
1928 (const char*) &rxinfo[1],
1929 msize - sizeof(struct
1930 GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage),
1931 GNUNET_YES, GNUNET_NO);
1932 break;
1933
1934 default:
1935 GNUNET_break (0);
1936 LOG (GNUNET_ERROR_TYPE_ERROR,
1937 "Unexpected message of type %u (%u bytes)",
1938 ntohs (hdr->type),
1939 ntohs (hdr->size));
1940 break;
1941 }
1910 return GNUNET_OK; 1942 return GNUNET_OK;
1911} 1943}
1912 1944
@@ -1924,34 +1956,34 @@ handle_helper_message(void *cls,
1924 * and transport 1956 * and transport
1925 */ 1957 */
1926static int 1958static int
1927wlan_plugin_address_suggested(void *cls, 1959wlan_plugin_address_suggested (void *cls,
1928 const void *addr, 1960 const void *addr,
1929 size_t addrlen) 1961 size_t addrlen)
1930{ 1962{
1931 struct Plugin *plugin = cls; 1963 struct Plugin *plugin = cls;
1932 struct WlanAddress *wa = (struct WlanAddress *)addr; 1964 struct WlanAddress *wa = (struct WlanAddress *) addr;
1933 1965
1934 if (addrlen != sizeof(struct WlanAddress)) 1966 if (addrlen != sizeof(struct WlanAddress))
1935 { 1967 {
1936 GNUNET_break_op(0); 1968 GNUNET_break_op (0);
1937 return GNUNET_SYSERR; 1969 return GNUNET_SYSERR;
1938 } 1970 }
1939 if (GNUNET_YES != plugin->have_mac) 1971 if (GNUNET_YES != plugin->have_mac)
1940 { 1972 {
1941 LOG(GNUNET_ERROR_TYPE_DEBUG, 1973 LOG (GNUNET_ERROR_TYPE_DEBUG,
1942 "Rejecting MAC `%s': I don't know my MAC!\n", 1974 "Rejecting MAC `%s': I don't know my MAC!\n",
1943 mac_to_string(addr)); 1975 mac_to_string (addr));
1944 return GNUNET_NO; /* don't know my MAC */ 1976 return GNUNET_NO; /* don't know my MAC */
1945 } 1977 }
1946 if (0 != memcmp(&wa->mac, 1978 if (0 != memcmp (&wa->mac,
1947 &plugin->mac_address, 1979 &plugin->mac_address,
1948 sizeof(wa->mac))) 1980 sizeof(wa->mac)))
1949 { 1981 {
1950 LOG(GNUNET_ERROR_TYPE_DEBUG, 1982 LOG (GNUNET_ERROR_TYPE_DEBUG,
1951 "Rejecting MAC `%s': not my MAC!\n", 1983 "Rejecting MAC `%s': not my MAC!\n",
1952 mac_to_string(addr)); 1984 mac_to_string (addr));
1953 return GNUNET_NO; /* not my MAC */ 1985 return GNUNET_NO; /* not my MAC */
1954 } 1986 }
1955 return GNUNET_OK; 1987 return GNUNET_OK;
1956} 1988}
1957 1989
@@ -1970,27 +2002,27 @@ wlan_plugin_address_suggested(void *cls,
1970 * @param asc_cls closure for @a asc 2002 * @param asc_cls closure for @a asc
1971 */ 2003 */
1972static void 2004static void
1973wlan_plugin_address_pretty_printer(void *cls, 2005wlan_plugin_address_pretty_printer (void *cls,
1974 const char *type, 2006 const char *type,
1975 const void *addr, 2007 const void *addr,
1976 size_t addrlen, 2008 size_t addrlen,
1977 int numeric, 2009 int numeric,
1978 struct GNUNET_TIME_Relative timeout, 2010 struct GNUNET_TIME_Relative timeout,
1979 GNUNET_TRANSPORT_AddressStringCallback asc, 2011 GNUNET_TRANSPORT_AddressStringCallback asc,
1980 void *asc_cls) 2012 void *asc_cls)
1981{ 2013{
1982 const char *ret; 2014 const char *ret;
1983 2015
1984 if (sizeof(struct WlanAddress) == addrlen) 2016 if (sizeof(struct WlanAddress) == addrlen)
1985 ret = wlan_plugin_address_to_string(NULL, 2017 ret = wlan_plugin_address_to_string (NULL,
1986 addr, 2018 addr,
1987 addrlen); 2019 addrlen);
1988 else 2020 else
1989 ret = NULL; 2021 ret = NULL;
1990 asc(asc_cls, 2022 asc (asc_cls,
1991 ret, 2023 ret,
1992 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); 2024 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1993 asc(asc_cls, NULL, GNUNET_OK); 2025 asc (asc_cls, NULL, GNUNET_OK);
1994} 2026}
1995 2027
1996 2028
@@ -2000,7 +2032,7 @@ wlan_plugin_address_pretty_printer(void *cls,
2000 * @param cls pointer to the api struct 2032 * @param cls pointer to the api struct
2001 */ 2033 */
2002void * 2034void *
2003LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) 2035LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2004{ 2036{
2005 struct WlanAddress wa; 2037 struct WlanAddress wa;
2006 struct GNUNET_HELLO_Address *address; 2038 struct GNUNET_HELLO_Address *address;
@@ -2010,62 +2042,62 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls)
2010 struct MacEndpoint *endpoint_next; 2042 struct MacEndpoint *endpoint_next;
2011 2043
2012 if (NULL == plugin) 2044 if (NULL == plugin)
2013 { 2045 {
2014 GNUNET_free(api); 2046 GNUNET_free (api);
2015 return NULL; 2047 return NULL;
2016 } 2048 }
2017 if (GNUNET_YES == plugin->have_mac) 2049 if (GNUNET_YES == plugin->have_mac)
2018 { 2050 {
2019 memset(&wa, 0, sizeof(wa)); 2051 memset (&wa, 0, sizeof(wa));
2020 wa.options = htonl(plugin->options); 2052 wa.options = htonl (plugin->options);
2021 wa.mac = plugin->mac_address; 2053 wa.mac = plugin->mac_address;
2022 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 2054 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2023 PLUGIN_NAME, 2055 PLUGIN_NAME,
2024 &wa, sizeof(struct WlanAddress), 2056 &wa, sizeof(struct WlanAddress),
2025 GNUNET_HELLO_ADDRESS_INFO_NONE); 2057 GNUNET_HELLO_ADDRESS_INFO_NONE);
2026 2058
2027 plugin->env->notify_address(plugin->env->cls, 2059 plugin->env->notify_address (plugin->env->cls,
2028 GNUNET_NO, 2060 GNUNET_NO,
2029 address); 2061 address);
2030 plugin->have_mac = GNUNET_NO; 2062 plugin->have_mac = GNUNET_NO;
2031 GNUNET_HELLO_address_free(address); 2063 GNUNET_HELLO_address_free (address);
2032 } 2064 }
2033 2065
2034 if (NULL != plugin->beacon_task) 2066 if (NULL != plugin->beacon_task)
2035 { 2067 {
2036 GNUNET_SCHEDULER_cancel(plugin->beacon_task); 2068 GNUNET_SCHEDULER_cancel (plugin->beacon_task);
2037 plugin->beacon_task = NULL; 2069 plugin->beacon_task = NULL;
2038 } 2070 }
2039 if (NULL != plugin->suid_helper) 2071 if (NULL != plugin->suid_helper)
2040 { 2072 {
2041 GNUNET_HELPER_stop(plugin->suid_helper, 2073 GNUNET_HELPER_stop (plugin->suid_helper,
2042 GNUNET_NO); 2074 GNUNET_NO);
2043 plugin->suid_helper = NULL; 2075 plugin->suid_helper = NULL;
2044 } 2076 }
2045 endpoint_next = plugin->mac_head; 2077 endpoint_next = plugin->mac_head;
2046 while (NULL != (endpoint = endpoint_next)) 2078 while (NULL != (endpoint = endpoint_next))
2047 { 2079 {
2048 endpoint_next = endpoint->next; 2080 endpoint_next = endpoint->next;
2049 free_macendpoint(endpoint); 2081 free_macendpoint (endpoint);
2050 } 2082 }
2051 if (NULL != plugin->fragment_data_tokenizer) 2083 if (NULL != plugin->fragment_data_tokenizer)
2052 { 2084 {
2053 GNUNET_SERVER_mst_destroy(plugin->fragment_data_tokenizer); 2085 GNUNET_SERVER_mst_destroy (plugin->fragment_data_tokenizer);
2054 plugin->fragment_data_tokenizer = NULL; 2086 plugin->fragment_data_tokenizer = NULL;
2055 } 2087 }
2056 if (NULL != plugin->wlan_header_payload_tokenizer) 2088 if (NULL != plugin->wlan_header_payload_tokenizer)
2057 { 2089 {
2058 GNUNET_SERVER_mst_destroy(plugin->wlan_header_payload_tokenizer); 2090 GNUNET_SERVER_mst_destroy (plugin->wlan_header_payload_tokenizer);
2059 plugin->wlan_header_payload_tokenizer = NULL; 2091 plugin->wlan_header_payload_tokenizer = NULL;
2060 } 2092 }
2061 if (NULL != plugin->helper_payload_tokenizer) 2093 if (NULL != plugin->helper_payload_tokenizer)
2062 { 2094 {
2063 GNUNET_SERVER_mst_destroy(plugin->helper_payload_tokenizer); 2095 GNUNET_SERVER_mst_destroy (plugin->helper_payload_tokenizer);
2064 plugin->helper_payload_tokenizer = NULL; 2096 plugin->helper_payload_tokenizer = NULL;
2065 } 2097 }
2066 GNUNET_free_non_null(plugin->wlan_interface); 2098 GNUNET_free_non_null (plugin->wlan_interface);
2067 GNUNET_free(plugin); 2099 GNUNET_free (plugin);
2068 GNUNET_free(api); 2100 GNUNET_free (api);
2069 return NULL; 2101 return NULL;
2070} 2102}
2071 2103
@@ -2083,11 +2115,11 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls)
2083 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 2115 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2084 */ 2116 */
2085static int 2117static int
2086wlan_plugin_string_to_address(void *cls, 2118wlan_plugin_string_to_address (void *cls,
2087 const char *addr, 2119 const char *addr,
2088 uint16_t addrlen, 2120 uint16_t addrlen,
2089 void **buf, 2121 void **buf,
2090 size_t *added) 2122 size_t *added)
2091{ 2123{
2092 struct WlanAddress *wa; 2124 struct WlanAddress *wa;
2093 unsigned int a[6]; 2125 unsigned int a[6];
@@ -2096,34 +2128,34 @@ wlan_plugin_string_to_address(void *cls,
2096 uint32_t options; 2128 uint32_t options;
2097 2129
2098 if ((NULL == addr) || (0 == addrlen)) 2130 if ((NULL == addr) || (0 == addrlen))
2099 { 2131 {
2100 GNUNET_break(0); 2132 GNUNET_break (0);
2101 return GNUNET_SYSERR; 2133 return GNUNET_SYSERR;
2102 } 2134 }
2103 if ('\0' != addr[addrlen - 1]) 2135 if ('\0' != addr[addrlen - 1])
2104 { 2136 {
2105 GNUNET_break(0); 2137 GNUNET_break (0);
2106 return GNUNET_SYSERR; 2138 return GNUNET_SYSERR;
2107 } 2139 }
2108 if (strlen(addr) != addrlen - 1) 2140 if (strlen (addr) != addrlen - 1)
2109 { 2141 {
2110 GNUNET_break(0); 2142 GNUNET_break (0);
2111 return GNUNET_SYSERR; 2143 return GNUNET_SYSERR;
2112 } 2144 }
2113 2145
2114 if (8 != sscanf(addr, 2146 if (8 != sscanf (addr,
2115 "%4s.%u.%X:%X:%X:%X:%X:%X", 2147 "%4s.%u.%X:%X:%X:%X:%X:%X",
2116 plugin, &options, 2148 plugin, &options,
2117 &a[0], &a[1], &a[2], 2149 &a[0], &a[1], &a[2],
2118 &a[3], &a[4], &a[5])) 2150 &a[3], &a[4], &a[5]))
2119 { 2151 {
2120 GNUNET_break(0); 2152 GNUNET_break (0);
2121 return GNUNET_SYSERR; 2153 return GNUNET_SYSERR;
2122 } 2154 }
2123 wa = GNUNET_new(struct WlanAddress); 2155 wa = GNUNET_new (struct WlanAddress);
2124 for (i = 0; i < 6; i++) 2156 for (i = 0; i < 6; i++)
2125 wa->mac.mac[i] = a[i]; 2157 wa->mac.mac[i] = a[i];
2126 wa->options = htonl(0); 2158 wa->options = htonl (0);
2127 *buf = wa; 2159 *buf = wa;
2128 *added = sizeof(struct WlanAddress); 2160 *added = sizeof(struct WlanAddress);
2129 return GNUNET_OK; 2161 return GNUNET_OK;
@@ -2143,9 +2175,9 @@ wlan_plugin_string_to_address(void *cls,
2143 * @param sic_cls closure for @a sic 2175 * @param sic_cls closure for @a sic
2144 */ 2176 */
2145static void 2177static void
2146wlan_plugin_setup_monitor(void *cls, 2178wlan_plugin_setup_monitor (void *cls,
2147 GNUNET_TRANSPORT_SessionInfoCallback sic, 2179 GNUNET_TRANSPORT_SessionInfoCallback sic,
2148 void *sic_cls) 2180 void *sic_cls)
2149{ 2181{
2150 struct Plugin *plugin = cls; 2182 struct Plugin *plugin = cls;
2151 struct MacEndpoint *mac; 2183 struct MacEndpoint *mac;
@@ -2154,19 +2186,20 @@ wlan_plugin_setup_monitor(void *cls,
2154 plugin->sic = sic; 2186 plugin->sic = sic;
2155 plugin->sic_cls = sic_cls; 2187 plugin->sic_cls = sic_cls;
2156 if (NULL != sic) 2188 if (NULL != sic)
2157 { 2189 {
2158 for (mac = plugin->mac_head; NULL != mac; mac = mac->next) 2190 for (mac = plugin->mac_head; NULL != mac; mac = mac->next)
2159 for (session = mac->sessions_head; NULL != session; session = session->next) 2191 for (session = mac->sessions_head; NULL != session; session =
2160 { 2192 session->next)
2161 notify_session_monitor(plugin, 2193 {
2162 session, 2194 notify_session_monitor (plugin,
2163 GNUNET_TRANSPORT_SS_INIT); 2195 session,
2164 notify_session_monitor(plugin, 2196 GNUNET_TRANSPORT_SS_INIT);
2165 session, 2197 notify_session_monitor (plugin,
2166 GNUNET_TRANSPORT_SS_UP); 2198 session,
2167 } 2199 GNUNET_TRANSPORT_SS_UP);
2168 sic(sic_cls, NULL, NULL); 2200 }
2169 } 2201 sic (sic_cls, NULL, NULL);
2202 }
2170} 2203}
2171 2204
2172 2205
@@ -2181,12 +2214,13 @@ wlan_plugin_setup_monitor(void *cls,
2181 * @param session which session is being updated 2214 * @param session which session is being updated
2182 */ 2215 */
2183static void 2216static void
2184wlan_plugin_update_session_timeout(void *cls, 2217wlan_plugin_update_session_timeout (void *cls,
2185 const struct GNUNET_PeerIdentity *peer, 2218 const struct GNUNET_PeerIdentity *peer,
2186 struct GNUNET_ATS_Session *session) 2219 struct GNUNET_ATS_Session *session)
2187{ 2220{
2188 GNUNET_assert(NULL != session->timeout_task); 2221 GNUNET_assert (NULL != session->timeout_task);
2189 session->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2222 session->timeout = GNUNET_TIME_relative_to_absolute (
2223 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2190} 2224}
2191 2225
2192 2226
@@ -2201,10 +2235,10 @@ wlan_plugin_update_session_timeout(void *cls,
2201 * @param delay new delay to use for receiving 2235 * @param delay new delay to use for receiving
2202 */ 2236 */
2203static void 2237static void
2204wlan_plugin_update_inbound_delay(void *cls, 2238wlan_plugin_update_inbound_delay (void *cls,
2205 const struct GNUNET_PeerIdentity *peer, 2239 const struct GNUNET_PeerIdentity *peer,
2206 struct GNUNET_ATS_Session *session, 2240 struct GNUNET_ATS_Session *session,
2207 struct GNUNET_TIME_Relative delay) 2241 struct GNUNET_TIME_Relative delay)
2208{ 2242{
2209 /* does nothing, as inbound delay is not supported by WLAN */ 2243 /* does nothing, as inbound delay is not supported by WLAN */
2210} 2244}
@@ -2217,7 +2251,7 @@ wlan_plugin_update_inbound_delay(void *cls,
2217 * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error 2251 * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error
2218 */ 2252 */
2219void * 2253void *
2220LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) 2254LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2221{ 2255{
2222 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 2256 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2223 struct GNUNET_TRANSPORT_PluginFunctions *api; 2257 struct GNUNET_TRANSPORT_PluginFunctions *api;
@@ -2228,127 +2262,128 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls)
2228 2262
2229 /* check for 'special' mode */ 2263 /* check for 'special' mode */
2230 if (NULL == env->receive) 2264 if (NULL == env->receive)
2231 { 2265 {
2232 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 2266 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2233 initialze the plugin or the API */ 2267 initialze the plugin or the API */
2234 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 2268 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
2235 api->cls = NULL; 2269 api->cls = NULL;
2236 api->address_pretty_printer = &wlan_plugin_address_pretty_printer; 2270 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
2237 api->address_to_string = &wlan_plugin_address_to_string; 2271 api->address_to_string = &wlan_plugin_address_to_string;
2238 api->string_to_address = &wlan_plugin_string_to_address; 2272 api->string_to_address = &wlan_plugin_string_to_address;
2239 return api; 2273 return api;
2240 } 2274 }
2241 2275
2242 testmode = 0; 2276 testmode = 0;
2243 /* check configuration */ 2277 /* check configuration */
2244 if ((GNUNET_YES == 2278 if ((GNUNET_YES ==
2245 GNUNET_CONFIGURATION_have_value(env->cfg, 2279 GNUNET_CONFIGURATION_have_value (env->cfg,
2246 CONFIG_NAME, 2280 CONFIG_NAME,
2247 "TESTMODE")) && 2281 "TESTMODE")) &&
2248 ((GNUNET_SYSERR == 2282 ((GNUNET_SYSERR ==
2249 GNUNET_CONFIGURATION_get_value_number(env->cfg, 2283 GNUNET_CONFIGURATION_get_value_number (env->cfg,
2250 CONFIG_NAME, 2284 CONFIG_NAME,
2251 "TESTMODE", 2285 "TESTMODE",
2252 &testmode)) || 2286 &testmode)) ||
2253 (testmode > 2))) 2287 (testmode > 2)))
2254 { 2288 {
2255 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 2289 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2256 CONFIG_NAME, 2290 CONFIG_NAME,
2257 "TESTMODE"); 2291 "TESTMODE");
2258 return NULL; 2292 return NULL;
2259 } 2293 }
2260 binary = GNUNET_OS_get_libexec_binary_path(HELPER_NAME); 2294 binary = GNUNET_OS_get_libexec_binary_path (HELPER_NAME);
2261 if ((0 == testmode) && 2295 if ((0 == testmode) &&
2262 (GNUNET_YES != 2296 (GNUNET_YES !=
2263 GNUNET_OS_check_helper_binary(binary, 2297 GNUNET_OS_check_helper_binary (binary,
2264 GNUNET_YES, 2298 GNUNET_YES,
2265 NULL))) 2299 NULL)))
2266 { 2300 {
2267 LOG(GNUNET_ERROR_TYPE_ERROR, 2301 LOG (GNUNET_ERROR_TYPE_ERROR,
2268 _("Helper binary `%s' not SUID, cannot run WLAN transport\n"), 2302 _ ("Helper binary `%s' not SUID, cannot run WLAN transport\n"),
2269 HELPER_NAME); 2303 HELPER_NAME);
2270 GNUNET_free(binary); 2304 GNUNET_free (binary);
2271 return NULL; 2305 return NULL;
2272 } 2306 }
2273 GNUNET_free(binary); 2307 GNUNET_free (binary);
2274 if (GNUNET_YES != 2308 if (GNUNET_YES !=
2275 GNUNET_CONFIGURATION_get_value_string(env->cfg, 2309 GNUNET_CONFIGURATION_get_value_string (env->cfg,
2276 CONFIG_NAME, 2310 CONFIG_NAME,
2277 "INTERFACE", 2311 "INTERFACE",
2278 &wlan_interface)) 2312 &wlan_interface))
2279 { 2313 {
2280 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 2314 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2281 CONFIG_NAME, 2315 CONFIG_NAME,
2282 "INTERFACE"); 2316 "INTERFACE");
2283 return NULL; 2317 return NULL;
2284 } 2318 }
2285 2319
2286 plugin = GNUNET_new(struct Plugin); 2320 plugin = GNUNET_new (struct Plugin);
2287 plugin->wlan_interface = wlan_interface; 2321 plugin->wlan_interface = wlan_interface;
2288 plugin->env = env; 2322 plugin->env = env;
2289 GNUNET_STATISTICS_set(plugin->env->stats, 2323 GNUNET_STATISTICS_set (plugin->env->stats,
2290 _("# sessions allocated"), 2324 _ ("# sessions allocated"),
2291 0, GNUNET_NO); 2325 0, GNUNET_NO);
2292 GNUNET_STATISTICS_set(plugin->env->stats, 2326 GNUNET_STATISTICS_set (plugin->env->stats,
2293 _("# MAC endpoints allocated"), 2327 _ ("# MAC endpoints allocated"),
2294 0, 0); 2328 0, 0);
2295 GNUNET_BANDWIDTH_tracker_init(&plugin->tracker, NULL, NULL, 2329 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, NULL, NULL,
2296 GNUNET_BANDWIDTH_value_init(100 * 1024 * 2330 GNUNET_BANDWIDTH_value_init (100 * 1024
2297 1024 / 8), 2331 * 1024 / 8),
2298 100); 2332 100);
2299 plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create(&process_data, 2333 plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data,
2300 plugin);
2301 plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create(&process_data,
2302 plugin);
2303 plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create(&process_data,
2304 plugin); 2334 plugin);
2335 plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (
2336 &process_data,
2337 plugin);
2338 plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data,
2339 plugin);
2305 2340
2306 plugin->options = 0; 2341 plugin->options = 0;
2307 2342
2308 /* some compilers do not like switch on 'long long'... */ 2343 /* some compilers do not like switch on 'long long'... */
2309 switch ((unsigned int)testmode) 2344 switch ((unsigned int) testmode)
2310 { 2345 {
2311 case 0: /* normal */ 2346 case 0: /* normal */
2312 plugin->helper_argv[0] = (char *)HELPER_NAME; 2347 plugin->helper_argv[0] = (char *) HELPER_NAME;
2313 plugin->helper_argv[1] = wlan_interface; 2348 plugin->helper_argv[1] = wlan_interface;
2314 plugin->helper_argv[2] = NULL; 2349 plugin->helper_argv[2] = NULL;
2315 plugin->suid_helper = GNUNET_HELPER_start(GNUNET_NO, 2350 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
2316 HELPER_NAME, 2351 HELPER_NAME,
2317 plugin->helper_argv, 2352 plugin->helper_argv,
2318 &handle_helper_message, 2353 &handle_helper_message,
2319 NULL, 2354 NULL,
2320 plugin); 2355 plugin);
2321 break; 2356 break;
2322 2357
2323 case 1: /* testmode, peer 1 */ 2358 case 1: /* testmode, peer 1 */
2324 plugin->helper_argv[0] = (char *)DUMMY_HELPER_NAME; 2359 plugin->helper_argv[0] = (char *) DUMMY_HELPER_NAME;
2325 plugin->helper_argv[1] = (char *)"1"; 2360 plugin->helper_argv[1] = (char *) "1";
2326 plugin->helper_argv[2] = NULL; 2361 plugin->helper_argv[2] = NULL;
2327 plugin->suid_helper = GNUNET_HELPER_start(GNUNET_NO, 2362 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
2328 DUMMY_HELPER_NAME, 2363 DUMMY_HELPER_NAME,
2329 plugin->helper_argv, 2364 plugin->helper_argv,
2330 &handle_helper_message, 2365 &handle_helper_message,
2331 NULL, 2366 NULL,
2332 plugin); 2367 plugin);
2333 break; 2368 break;
2334 2369
2335 case 2: /* testmode, peer 2 */ 2370 case 2: /* testmode, peer 2 */
2336 plugin->helper_argv[0] = (char *)DUMMY_HELPER_NAME; 2371 plugin->helper_argv[0] = (char *) DUMMY_HELPER_NAME;
2337 plugin->helper_argv[1] = (char *)"2"; 2372 plugin->helper_argv[1] = (char *) "2";
2338 plugin->helper_argv[2] = NULL; 2373 plugin->helper_argv[2] = NULL;
2339 plugin->suid_helper = GNUNET_HELPER_start(GNUNET_NO, 2374 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
2340 DUMMY_HELPER_NAME, 2375 DUMMY_HELPER_NAME,
2341 plugin->helper_argv, 2376 plugin->helper_argv,
2342 &handle_helper_message, 2377 &handle_helper_message,
2343 NULL, 2378 NULL,
2344 plugin); 2379 plugin);
2345 break; 2380 break;
2346 2381
2347 default: 2382 default:
2348 GNUNET_assert(0); 2383 GNUNET_assert (0);
2349 } 2384 }
2350 2385
2351 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 2386 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
2352 api->cls = plugin; 2387 api->cls = plugin;
2353 api->send = &wlan_plugin_send; 2388 api->send = &wlan_plugin_send;
2354 api->get_session = &wlan_plugin_get_session; 2389 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
58/** 58/**
59 * A MAC Address. 59 * A MAC Address.
60 */ 60 */
61struct GNUNET_TRANSPORT_WLAN_MacAddress { 61struct GNUNET_TRANSPORT_WLAN_MacAddress
62{
62 uint8_t mac[MAC_ADDR_SIZE]; 63 uint8_t mac[MAC_ADDR_SIZE];
63}; 64};
64 65
65/** 66/**
66 * Format of a WLAN Control Message. 67 * Format of a WLAN Control Message.
67 */ 68 */
68struct GNUNET_TRANSPORT_WLAN_HelperControlMessage { 69struct GNUNET_TRANSPORT_WLAN_HelperControlMessage
70{
69 /** 71 /**
70 * Message header. Type is 72 * Message header. Type is
71 * GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL 73 * GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL
@@ -81,7 +83,8 @@ struct GNUNET_TRANSPORT_WLAN_HelperControlMessage {
81/** 83/**
82 * generic definitions for IEEE 802.3 frames 84 * generic definitions for IEEE 802.3 frames
83 */ 85 */
84struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame { 86struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame
87{
85 /** 88 /**
86 * Address 1: destination address in ad-hoc mode or AP, BSSID if station, 89 * Address 1: destination address in ad-hoc mode or AP, BSSID if station,
87 */ 90 */
@@ -102,7 +105,8 @@ struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame {
102/** 105/**
103 * generic definitions for IEEE 802.11 frames 106 * generic definitions for IEEE 802.11 frames
104 */ 107 */
105struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame { 108struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame
109{
106 /** 110 /**
107 * 802.11 Frame Control field. A bitmask. The overall field is a 111 * 802.11 Frame Control field. A bitmask. The overall field is a
108 * 16-bit mask of the respecitve fields. The lowest two bits should 112 * 16-bit mask of the respecitve fields. The lowest two bits should
@@ -154,7 +158,8 @@ struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame {
154 * Message from the plugin to the WLAN helper: send the given message with the 158 * Message from the plugin to the WLAN helper: send the given message with the
155 * given connection parameters. 159 * given connection parameters.
156 */ 160 */
157struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage { 161struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage
162{
158 /** 163 /**
159 * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER'. 164 * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER'.
160 */ 165 */
@@ -193,7 +198,8 @@ struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage {
193/** 198/**
194 * struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos 199 * struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos
195 */ 200 */
196struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage { 201struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage
202{
197 /** 203 /**
198 * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER'. 204 * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER'.
199 */ 205 */
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 @@
42 * Default is 5s. 42 * Default is 5s.
43 */ 43 */
44#define CONNECT_RETRY_TIMEOUT \ 44#define CONNECT_RETRY_TIMEOUT \
45 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 45 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
46 46
47 47
48#define LOG_STRERROR(kind, syscall) \ 48#define LOG_STRERROR(kind, syscall) \
49 GNUNET_log_from_strerror(kind, "util-connection", syscall) 49 GNUNET_log_from_strerror (kind, "util-connection", syscall)
50 50
51 51
52/** 52/**
53 * Transmission handle. There can only be one for each connection. 53 * Transmission handle. There can only be one for each connection.
54 */ 54 */
55struct GNUNET_CONNECTION_TransmitHandle { 55struct GNUNET_CONNECTION_TransmitHandle
56{
56 /** 57 /**
57 * Function to call if the send buffer has notify_size 58 * Function to call if the send buffer has notify_size
58 * bytes available. 59 * bytes available.
@@ -91,7 +92,8 @@ struct GNUNET_CONNECTION_TransmitHandle {
91 * During connect, we try multiple possible IP addresses 92 * During connect, we try multiple possible IP addresses
92 * to find out which one might work. 93 * to find out which one might work.
93 */ 94 */
94struct AddressProbe { 95struct AddressProbe
96{
95 /** 97 /**
96 * This is a linked list. 98 * This is a linked list.
97 */ 99 */
@@ -132,7 +134,8 @@ struct AddressProbe {
132/** 134/**
133 * @brief handle for a network connection 135 * @brief handle for a network connection
134 */ 136 */
135struct GNUNET_CONNECTION_Handle { 137struct GNUNET_CONNECTION_Handle
138{
136 /** 139 /**
137 * Configuration to use. 140 * Configuration to use.
138 */ 141 */
@@ -268,7 +271,7 @@ struct GNUNET_CONNECTION_Handle {
268 * @param connection the connection to set persistent 271 * @param connection the connection to set persistent
269 */ 272 */
270void 273void
271GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *connection) 274GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection)
272{ 275{
273 connection->persist = GNUNET_YES; 276 connection->persist = GNUNET_YES;
274} 277}
@@ -286,9 +289,9 @@ GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *connection)
286 * @return #GNUNET_OK on success 289 * @return #GNUNET_OK on success
287 */ 290 */
288int 291int
289GNUNET_CONNECTION_disable_corking(struct GNUNET_CONNECTION_Handle *connection) 292GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection)
290{ 293{
291 return GNUNET_NETWORK_socket_disable_corking(connection->sock); 294 return GNUNET_NETWORK_socket_disable_corking (connection->sock);
292} 295}
293 296
294 297
@@ -301,13 +304,13 @@ GNUNET_CONNECTION_disable_corking(struct GNUNET_CONNECTION_Handle *connection)
301 * @return the boxed connection handle 304 * @return the boxed connection handle
302 */ 305 */
303struct GNUNET_CONNECTION_Handle * 306struct GNUNET_CONNECTION_Handle *
304GNUNET_CONNECTION_create_from_existing(struct GNUNET_NETWORK_Handle *osSocket) 307GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket)
305{ 308{
306 struct GNUNET_CONNECTION_Handle *connection; 309 struct GNUNET_CONNECTION_Handle *connection;
307 310
308 connection = GNUNET_new(struct GNUNET_CONNECTION_Handle); 311 connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
309 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; 312 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE;
310 connection->write_buffer = GNUNET_malloc(connection->write_buffer_size); 313 connection->write_buffer = GNUNET_malloc (connection->write_buffer_size);
311 connection->sock = osSocket; 314 connection->sock = osSocket;
312 return connection; 315 return connection;
313} 316}
@@ -323,9 +326,9 @@ GNUNET_CONNECTION_create_from_existing(struct GNUNET_NETWORK_Handle *osSocket)
323 * @return the connection handle, NULL on error 326 * @return the connection handle, NULL on error
324 */ 327 */
325struct GNUNET_CONNECTION_Handle * 328struct GNUNET_CONNECTION_Handle *
326GNUNET_CONNECTION_create_from_accept(GNUNET_CONNECTION_AccessCheck access_cb, 329GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
327 void *access_cb_cls, 330 void *access_cb_cls,
328 struct GNUNET_NETWORK_Handle *lsock) 331 struct GNUNET_NETWORK_Handle *lsock)
329{ 332{
330 struct GNUNET_CONNECTION_Handle *connection; 333 struct GNUNET_CONNECTION_Handle *connection;
331 char addr[128]; 334 char addr[128];
@@ -351,107 +354,107 @@ GNUNET_CONNECTION_create_from_accept(GNUNET_CONNECTION_AccessCheck access_cb,
351 354
352 addrlen = sizeof(addr); 355 addrlen = sizeof(addr);
353 sock = 356 sock =
354 GNUNET_NETWORK_socket_accept(lsock, (struct sockaddr *)&addr, &addrlen); 357 GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
355 if (NULL == sock) 358 if (NULL == sock)
356 { 359 {
357 if (EAGAIN != errno) 360 if (EAGAIN != errno)
358 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "accept"); 361 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept");
359 return NULL; 362 return NULL;
360 } 363 }
361 if ((addrlen > sizeof(addr)) || (addrlen < sizeof(sa_family_t))) 364 if ((addrlen > sizeof(addr)) || (addrlen < sizeof(sa_family_t)))
362 { 365 {
363 GNUNET_break(0); 366 GNUNET_break (0);
364 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock)); 367 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
365 return NULL; 368 return NULL;
366 } 369 }
367 370
368 sa = (struct sockaddr *)addr; 371 sa = (struct sockaddr *) addr;
369 v6 = (struct sockaddr_in6 *)addr; 372 v6 = (struct sockaddr_in6 *) addr;
370 if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED(&v6->sin6_addr))) 373 if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)))
371 { 374 {
372 /* convert to V4 address */ 375 /* convert to V4 address */
373 v4 = GNUNET_new(struct sockaddr_in); 376 v4 = GNUNET_new (struct sockaddr_in);
374 memset(v4, 0, sizeof(struct sockaddr_in)); 377 memset (v4, 0, sizeof(struct sockaddr_in));
375 v4->sin_family = AF_INET; 378 v4->sin_family = AF_INET;
376#if HAVE_SOCKADDR_IN_SIN_LEN 379#if HAVE_SOCKADDR_IN_SIN_LEN
377 v4->sin_len = (u_char)sizeof(struct sockaddr_in); 380 v4->sin_len = (u_char) sizeof(struct sockaddr_in);
378#endif 381#endif
379 GNUNET_memcpy(&v4->sin_addr, 382 GNUNET_memcpy (&v4->sin_addr,
380 &((char *)&v6->sin6_addr)[sizeof(struct in6_addr) - 383 &((char *) &v6->sin6_addr)[sizeof(struct in6_addr)
381 sizeof(struct in_addr)], 384 - sizeof(struct in_addr)],
382 sizeof(struct in_addr)); 385 sizeof(struct in_addr));
383 v4->sin_port = v6->sin6_port; 386 v4->sin_port = v6->sin6_port;
384 uaddr = v4; 387 uaddr = v4;
385 addrlen = sizeof(struct sockaddr_in); 388 addrlen = sizeof(struct sockaddr_in);
386 } 389 }
387 else 390 else
388 { 391 {
389 uaddr = GNUNET_malloc(addrlen); 392 uaddr = GNUNET_malloc (addrlen);
390 GNUNET_memcpy(uaddr, addr, addrlen); 393 GNUNET_memcpy (uaddr, addr, addrlen);
391 } 394 }
392 gcp = NULL; 395 gcp = NULL;
393 if (AF_UNIX == sa->sa_family) 396 if (AF_UNIX == sa->sa_family)
394 { 397 {
395#if HAVE_GETPEEREID 398#if HAVE_GETPEEREID
396 /* most BSDs */ 399 /* most BSDs */
397 if (0 == getpeereid(GNUNET_NETWORK_get_fd(sock), &gc.uid, &gc.gid)) 400 if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid))
398 gcp = &gc; 401 gcp = &gc;
399#else 402#else
400#ifdef SO_PEERCRED 403#ifdef SO_PEERCRED
401 /* largely traditional GNU/Linux */ 404 /* largely traditional GNU/Linux */
402 olen = sizeof(uc); 405 olen = sizeof(uc);
403 if ((0 == getsockopt(GNUNET_NETWORK_get_fd(sock), 406 if ((0 == getsockopt (GNUNET_NETWORK_get_fd (sock),
404 SOL_SOCKET, 407 SOL_SOCKET,
405 SO_PEERCRED, 408 SO_PEERCRED,
406 &uc, 409 &uc,
407 &olen)) && 410 &olen)) &&
408 (olen == sizeof(uc))) 411 (olen == sizeof(uc)))
409 { 412 {
410 gc.uid = uc.uid; 413 gc.uid = uc.uid;
411 gc.gid = uc.gid; 414 gc.gid = uc.gid;
412 gcp = &gc; 415 gcp = &gc;
413 } 416 }
414#else 417#else
415#if HAVE_GETPEERUCRED 418#if HAVE_GETPEERUCRED
416 /* this is for Solaris 10 */ 419 /* this is for Solaris 10 */
417 ucred_t *uc; 420 ucred_t *uc;
418 421
419 uc = NULL; 422 uc = NULL;
420 if (0 == getpeerucred(GNUNET_NETWORK_get_fd(sock), &uc)) 423 if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc))
421 { 424 {
422 gc.uid = ucred_geteuid(uc); 425 gc.uid = ucred_geteuid (uc);
423 gc.gid = ucred_getegid(uc); 426 gc.gid = ucred_getegid (uc);
424 gcp = &gc; 427 gcp = &gc;
425 } 428 }
426 ucred_free(uc); 429 ucred_free (uc);
427#endif 430#endif
428#endif 431#endif
429#endif 432#endif
430 } 433 }
431 434
432 if ((NULL != access_cb) && 435 if ((NULL != access_cb) &&
433 (GNUNET_YES != (aret = access_cb(access_cb_cls, gcp, uaddr, addrlen)))) 436 (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen))))
434 { 437 {
435 if (GNUNET_NO == aret) 438 if (GNUNET_NO == aret)
436 LOG(GNUNET_ERROR_TYPE_INFO, 439 LOG (GNUNET_ERROR_TYPE_INFO,
437 _("Access denied to `%s'\n"), 440 _ ("Access denied to `%s'\n"),
438 GNUNET_a2s(uaddr, addrlen)); 441 GNUNET_a2s (uaddr, addrlen));
439 GNUNET_break(GNUNET_OK == 442 GNUNET_break (GNUNET_OK ==
440 GNUNET_NETWORK_socket_shutdown(sock, SHUT_RDWR)); 443 GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR));
441 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock)); 444 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
442 GNUNET_free(uaddr); 445 GNUNET_free (uaddr);
443 return NULL; 446 return NULL;
444 } 447 }
445 connection = GNUNET_new(struct GNUNET_CONNECTION_Handle); 448 connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
446 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; 449 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE;
447 connection->write_buffer = GNUNET_malloc(connection->write_buffer_size); 450 connection->write_buffer = GNUNET_malloc (connection->write_buffer_size);
448 connection->addr = uaddr; 451 connection->addr = uaddr;
449 connection->addrlen = addrlen; 452 connection->addrlen = addrlen;
450 connection->sock = sock; 453 connection->sock = sock;
451 LOG(GNUNET_ERROR_TYPE_INFO, 454 LOG (GNUNET_ERROR_TYPE_INFO,
452 _("Accepting connection from `%s': %p\n"), 455 _ ("Accepting connection from `%s': %p\n"),
453 GNUNET_a2s(uaddr, addrlen), 456 GNUNET_a2s (uaddr, addrlen),
454 connection); 457 connection);
455 return connection; 458 return connection;
456} 459}
457 460
@@ -465,14 +468,14 @@ GNUNET_CONNECTION_create_from_accept(GNUNET_CONNECTION_AccessCheck access_cb,
465 * @return #GNUNET_OK on success 468 * @return #GNUNET_OK on success
466 */ 469 */
467int 470int
468GNUNET_CONNECTION_get_address(struct GNUNET_CONNECTION_Handle *connection, 471GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection,
469 void **addr, 472 void **addr,
470 size_t *addrlen) 473 size_t *addrlen)
471{ 474{
472 if ((NULL == connection->addr) || (0 == connection->addrlen)) 475 if ((NULL == connection->addr) || (0 == connection->addrlen))
473 return GNUNET_NO; 476 return GNUNET_NO;
474 *addr = GNUNET_malloc(connection->addrlen); 477 *addr = GNUNET_malloc (connection->addrlen);
475 GNUNET_memcpy(*addr, connection->addr, connection->addrlen); 478 GNUNET_memcpy (*addr, connection->addr, connection->addrlen);
476 *addrlen = connection->addrlen; 479 *addrlen = connection->addrlen;
477 return GNUNET_OK; 480 return GNUNET_OK;
478} 481}
@@ -485,22 +488,22 @@ GNUNET_CONNECTION_get_address(struct GNUNET_CONNECTION_Handle *connection,
485 * @param errcode error code to send 488 * @param errcode error code to send
486 */ 489 */
487static void 490static void
488signal_receive_error(struct GNUNET_CONNECTION_Handle *connection, int errcode) 491signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode)
489{ 492{
490 GNUNET_CONNECTION_Receiver receiver; 493 GNUNET_CONNECTION_Receiver receiver;
491 494
492 LOG(GNUNET_ERROR_TYPE_DEBUG, 495 LOG (GNUNET_ERROR_TYPE_DEBUG,
493 "Receive encounters error (%s), connection closed (%p)\n", 496 "Receive encounters error (%s), connection closed (%p)\n",
494 strerror(errcode), 497 strerror (errcode),
495 connection); 498 connection);
496 GNUNET_assert(NULL != (receiver = connection->receiver)); 499 GNUNET_assert (NULL != (receiver = connection->receiver));
497 connection->receiver = NULL; 500 connection->receiver = NULL;
498 receiver(connection->receiver_cls, 501 receiver (connection->receiver_cls,
499 NULL, 502 NULL,
500 0, 503 0,
501 connection->addr, 504 connection->addr,
502 connection->addrlen, 505 connection->addrlen,
503 errcode); 506 errcode);
504} 507}
505 508
506 509
@@ -510,16 +513,16 @@ signal_receive_error(struct GNUNET_CONNECTION_Handle *connection, int errcode)
510 * @param connection connection to signal for 513 * @param connection connection to signal for
511 */ 514 */
512static void 515static void
513signal_receive_timeout(struct GNUNET_CONNECTION_Handle *connection) 516signal_receive_timeout (struct GNUNET_CONNECTION_Handle *connection)
514{ 517{
515 GNUNET_CONNECTION_Receiver receiver; 518 GNUNET_CONNECTION_Receiver receiver;
516 519
517 LOG(GNUNET_ERROR_TYPE_DEBUG, 520 LOG (GNUNET_ERROR_TYPE_DEBUG,
518 "Connection signals timeout to receiver (%p)!\n", 521 "Connection signals timeout to receiver (%p)!\n",
519 connection); 522 connection);
520 GNUNET_assert(NULL != (receiver = connection->receiver)); 523 GNUNET_assert (NULL != (receiver = connection->receiver));
521 connection->receiver = NULL; 524 connection->receiver = NULL;
522 receiver(connection->receiver_cls, NULL, 0, NULL, 0, 0); 525 receiver (connection->receiver_cls, NULL, 0, NULL, 0, 0);
523} 526}
524 527
525 528
@@ -530,34 +533,34 @@ signal_receive_timeout(struct GNUNET_CONNECTION_Handle *connection)
530 * @param ecode error code (errno) 533 * @param ecode error code (errno)
531 */ 534 */
532static void 535static void
533signal_transmit_error(struct GNUNET_CONNECTION_Handle *connection, int ecode) 536signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, int ecode)
534{ 537{
535 GNUNET_CONNECTION_TransmitReadyNotify notify; 538 GNUNET_CONNECTION_TransmitReadyNotify notify;
536 539
537 LOG(GNUNET_ERROR_TYPE_DEBUG, 540 LOG (GNUNET_ERROR_TYPE_DEBUG,
538 "Transmission encounterd error (%s), connection closed (%p)\n", 541 "Transmission encounterd error (%s), connection closed (%p)\n",
539 strerror(ecode), 542 strerror (ecode),
540 connection); 543 connection);
541 if (NULL != connection->sock) 544 if (NULL != connection->sock)
542 { 545 {
543 (void)GNUNET_NETWORK_socket_shutdown(connection->sock, SHUT_RDWR); 546 (void) GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR);
544 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(connection->sock)); 547 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock));
545 connection->sock = NULL; 548 connection->sock = NULL;
546 GNUNET_assert(NULL == connection->write_task); 549 GNUNET_assert (NULL == connection->write_task);
547 } 550 }
548 if (NULL != connection->read_task) 551 if (NULL != connection->read_task)
549 { 552 {
550 /* send errors trigger read errors... */ 553 /* send errors trigger read errors... */
551 GNUNET_SCHEDULER_cancel(connection->read_task); 554 GNUNET_SCHEDULER_cancel (connection->read_task);
552 connection->read_task = NULL; 555 connection->read_task = NULL;
553 signal_receive_timeout(connection); 556 signal_receive_timeout (connection);
554 return; 557 return;
555 } 558 }
556 if (NULL == connection->nth.notify_ready) 559 if (NULL == connection->nth.notify_ready)
557 return; /* nobody to tell about it */ 560 return; /* nobody to tell about it */
558 notify = connection->nth.notify_ready; 561 notify = connection->nth.notify_ready;
559 connection->nth.notify_ready = NULL; 562 connection->nth.notify_ready = NULL;
560 notify(connection->nth.notify_ready_cls, 0, NULL); 563 notify (connection->nth.notify_ready_cls, 0, NULL);
561} 564}
562 565
563 566
@@ -568,37 +571,37 @@ signal_transmit_error(struct GNUNET_CONNECTION_Handle *connection, int ecode)
568 * @param connection the connection we tried to establish 571 * @param connection the connection we tried to establish
569 */ 572 */
570static void 573static void
571connect_fail_continuation(struct GNUNET_CONNECTION_Handle *connection) 574connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection)
572{ 575{
573 LOG(GNUNET_ERROR_TYPE_INFO, 576 LOG (GNUNET_ERROR_TYPE_INFO,
574 "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n", 577 "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n",
575 connection->hostname, 578 connection->hostname,
576 connection->port); 579 connection->port);
577 GNUNET_break(NULL == connection->ap_head); 580 GNUNET_break (NULL == connection->ap_head);
578 GNUNET_break(NULL == connection->ap_tail); 581 GNUNET_break (NULL == connection->ap_tail);
579 GNUNET_break(GNUNET_NO == connection->dns_active); 582 GNUNET_break (GNUNET_NO == connection->dns_active);
580 GNUNET_break(NULL == connection->sock); 583 GNUNET_break (NULL == connection->sock);
581 GNUNET_assert(NULL == connection->write_task); 584 GNUNET_assert (NULL == connection->write_task);
582 GNUNET_assert(NULL == connection->proxy_handshake); 585 GNUNET_assert (NULL == connection->proxy_handshake);
583 586
584 /* signal errors for jobs that used to wait on the connection */ 587 /* signal errors for jobs that used to wait on the connection */
585 connection->destroy_later = 1; 588 connection->destroy_later = 1;
586 if (NULL != connection->receiver) 589 if (NULL != connection->receiver)
587 signal_receive_error(connection, ECONNREFUSED); 590 signal_receive_error (connection, ECONNREFUSED);
588 if (NULL != connection->nth.notify_ready) 591 if (NULL != connection->nth.notify_ready)
589 { 592 {
590 GNUNET_assert(NULL != connection->nth.timeout_task); 593 GNUNET_assert (NULL != connection->nth.timeout_task);
591 GNUNET_SCHEDULER_cancel(connection->nth.timeout_task); 594 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task);
592 connection->nth.timeout_task = NULL; 595 connection->nth.timeout_task = NULL;
593 signal_transmit_error(connection, ECONNREFUSED); 596 signal_transmit_error (connection, ECONNREFUSED);
594 } 597 }
595 if (-1 == connection->destroy_later) 598 if (-1 == connection->destroy_later)
596 { 599 {
597 /* do it now */ 600 /* do it now */
598 connection->destroy_later = 0; 601 connection->destroy_later = 0;
599 GNUNET_CONNECTION_destroy(connection); 602 GNUNET_CONNECTION_destroy (connection);
600 return; 603 return;
601 } 604 }
602 connection->destroy_later = 0; 605 connection->destroy_later = 0;
603} 606}
604 607
@@ -609,7 +612,7 @@ connect_fail_continuation(struct GNUNET_CONNECTION_Handle *connection)
609 * @param cls our connection handle 612 * @param cls our connection handle
610 */ 613 */
611static void 614static void
612transmit_ready(void *cls); 615transmit_ready (void *cls);
613 616
614 617
615/** 618/**
@@ -619,7 +622,7 @@ transmit_ready(void *cls);
619 * @param cls connection to read from 622 * @param cls connection to read from
620 */ 623 */
621static void 624static void
622receive_ready(void *cls); 625receive_ready (void *cls);
623 626
624 627
625/** 628/**
@@ -628,42 +631,42 @@ receive_ready(void *cls);
628 * @param connection the connection we tried to establish 631 * @param connection the connection we tried to establish
629 */ 632 */
630static void 633static void
631connect_success_continuation(struct GNUNET_CONNECTION_Handle *connection) 634connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
632{ 635{
633 LOG(GNUNET_ERROR_TYPE_DEBUG, 636 LOG (GNUNET_ERROR_TYPE_DEBUG,
634 "Connection to `%s' succeeded! (%p)\n", 637 "Connection to `%s' succeeded! (%p)\n",
635 GNUNET_a2s(connection->addr, connection->addrlen), 638 GNUNET_a2s (connection->addr, connection->addrlen),
636 connection); 639 connection);
637 /* trigger jobs that waited for the connection */ 640 /* trigger jobs that waited for the connection */
638 if (NULL != connection->receiver) 641 if (NULL != connection->receiver)
639 { 642 {
640 LOG(GNUNET_ERROR_TYPE_DEBUG, 643 LOG (GNUNET_ERROR_TYPE_DEBUG,
641 "Connection succeeded, starting with receiving data (%p)\n", 644 "Connection succeeded, starting with receiving data (%p)\n",
642 connection); 645 connection);
643 GNUNET_assert(NULL == connection->read_task); 646 GNUNET_assert (NULL == connection->read_task);
644 connection->read_task = 647 connection->read_task =
645 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_absolute_get_remaining( 648 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (
646 connection->receive_timeout), 649 connection->receive_timeout),
650 connection->sock,
651 &receive_ready,
652 connection);
653 }
654 if (NULL != connection->nth.notify_ready)
655 {
656 LOG (GNUNET_ERROR_TYPE_DEBUG,
657 "Connection succeeded, starting with sending data (%p)\n",
658 connection);
659 GNUNET_assert (connection->nth.timeout_task != NULL);
660 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task);
661 connection->nth.timeout_task = NULL;
662 GNUNET_assert (connection->write_task == NULL);
663 connection->write_task =
664 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining (
665 connection->nth.transmit_timeout),
647 connection->sock, 666 connection->sock,
648 &receive_ready, 667 &transmit_ready,
649 connection); 668 connection);
650 } 669 }
651 if (NULL != connection->nth.notify_ready)
652 {
653 LOG(GNUNET_ERROR_TYPE_DEBUG,
654 "Connection succeeded, starting with sending data (%p)\n",
655 connection);
656 GNUNET_assert(connection->nth.timeout_task != NULL);
657 GNUNET_SCHEDULER_cancel(connection->nth.timeout_task);
658 connection->nth.timeout_task = NULL;
659 GNUNET_assert(connection->write_task == NULL);
660 connection->write_task =
661 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_absolute_get_remaining(
662 connection->nth.transmit_timeout),
663 connection->sock,
664 &transmit_ready,
665 connection);
666 }
667} 670}
668 671
669 672
@@ -674,7 +677,7 @@ connect_success_continuation(struct GNUNET_CONNECTION_Handle *connection)
674 * @param cls the `struct AddressProbe *` with the address that we are probing 677 * @param cls the `struct AddressProbe *` with the address that we are probing
675 */ 678 */
676static void 679static void
677connect_probe_continuation(void *cls) 680connect_probe_continuation (void *cls)
678{ 681{
679 struct AddressProbe *ap = cls; 682 struct AddressProbe *ap = cls;
680 struct GNUNET_CONNECTION_Handle *connection = ap->connection; 683 struct GNUNET_CONNECTION_Handle *connection = ap->connection;
@@ -683,44 +686,44 @@ connect_probe_continuation(void *cls)
683 int error; 686 int error;
684 socklen_t len; 687 socklen_t len;
685 688
686 GNUNET_assert(NULL != ap->sock); 689 GNUNET_assert (NULL != ap->sock);
687 GNUNET_CONTAINER_DLL_remove(connection->ap_head, connection->ap_tail, ap); 690 GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap);
688 len = sizeof(error); 691 len = sizeof(error);
689 errno = 0; 692 errno = 0;
690 error = 0; 693 error = 0;
691 tc = GNUNET_SCHEDULER_get_task_context(); 694 tc = GNUNET_SCHEDULER_get_task_context ();
692 if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || 695 if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
693 (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt(ap->sock, 696 (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt (ap->sock,
694 SOL_SOCKET, 697 SOL_SOCKET,
695 SO_ERROR, 698 SO_ERROR,
696 &error, 699 &error,
697 &len)) || 700 &len)) ||
698 (0 != error)) 701 (0 != error))
699 { 702 {
700 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(ap->sock)); 703 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
701 GNUNET_free(ap); 704 GNUNET_free (ap);
702 if ((NULL == connection->ap_head) && 705 if ((NULL == connection->ap_head) &&
703 (GNUNET_NO == connection->dns_active) && 706 (GNUNET_NO == connection->dns_active) &&
704 (NULL == connection->proxy_handshake)) 707 (NULL == connection->proxy_handshake))
705 connect_fail_continuation(connection); 708 connect_fail_continuation (connection);
706 return; 709 return;
707 } 710 }
708 GNUNET_assert(NULL == connection->sock); 711 GNUNET_assert (NULL == connection->sock);
709 connection->sock = ap->sock; 712 connection->sock = ap->sock;
710 GNUNET_assert(NULL == connection->addr); 713 GNUNET_assert (NULL == connection->addr);
711 connection->addr = GNUNET_malloc(ap->addrlen); 714 connection->addr = GNUNET_malloc (ap->addrlen);
712 GNUNET_memcpy(connection->addr, ap->addr, ap->addrlen); 715 GNUNET_memcpy (connection->addr, ap->addr, ap->addrlen);
713 connection->addrlen = ap->addrlen; 716 connection->addrlen = ap->addrlen;
714 GNUNET_free(ap); 717 GNUNET_free (ap);
715 /* cancel all other attempts */ 718 /* cancel all other attempts */
716 while (NULL != (pos = connection->ap_head)) 719 while (NULL != (pos = connection->ap_head))
717 { 720 {
718 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(pos->sock)); 721 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
719 GNUNET_SCHEDULER_cancel(pos->task); 722 GNUNET_SCHEDULER_cancel (pos->task);
720 GNUNET_CONTAINER_DLL_remove(connection->ap_head, connection->ap_tail, pos); 723 GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
721 GNUNET_free(pos); 724 GNUNET_free (pos);
722 } 725 }
723 connect_success_continuation(connection); 726 connect_success_continuation (connection);
724} 727}
725 728
726 729
@@ -733,87 +736,87 @@ connect_probe_continuation(void *cls)
733 * @param addrlen length of @a addr 736 * @param addrlen length of @a addr
734 */ 737 */
735static void 738static void
736try_connect_using_address(void *cls, 739try_connect_using_address (void *cls,
737 const struct sockaddr *addr, 740 const struct sockaddr *addr,
738 socklen_t addrlen) 741 socklen_t addrlen)
739{ 742{
740 struct GNUNET_CONNECTION_Handle *connection = cls; 743 struct GNUNET_CONNECTION_Handle *connection = cls;
741 struct AddressProbe *ap; 744 struct AddressProbe *ap;
742 struct GNUNET_TIME_Relative delay; 745 struct GNUNET_TIME_Relative delay;
743 746
744 if (NULL == addr) 747 if (NULL == addr)
745 { 748 {
746 connection->dns_active = NULL; 749 connection->dns_active = NULL;
747 if ((NULL == connection->ap_head) && (NULL == connection->sock) && 750 if ((NULL == connection->ap_head) && (NULL == connection->sock) &&
748 (NULL == connection->proxy_handshake)) 751 (NULL == connection->proxy_handshake))
749 connect_fail_continuation(connection); 752 connect_fail_continuation (connection);
750 return; 753 return;
751 } 754 }
752 if (NULL != connection->sock) 755 if (NULL != connection->sock)
753 return; /* already connected */ 756 return; /* already connected */
754 GNUNET_assert(NULL == connection->addr); 757 GNUNET_assert (NULL == connection->addr);
755 /* try to connect */ 758 /* try to connect */
756 LOG(GNUNET_ERROR_TYPE_DEBUG, 759 LOG (GNUNET_ERROR_TYPE_DEBUG,
757 "Trying to connect using address `%s:%u/%s:%u'\n", 760 "Trying to connect using address `%s:%u/%s:%u'\n",
758 connection->hostname, 761 connection->hostname,
759 connection->port, 762 connection->port,
760 GNUNET_a2s(addr, addrlen), 763 GNUNET_a2s (addr, addrlen),
761 connection->port); 764 connection->port);
762 ap = GNUNET_malloc(sizeof(struct AddressProbe) + addrlen); 765 ap = GNUNET_malloc (sizeof(struct AddressProbe) + addrlen);
763 ap->addr = (const struct sockaddr *)&ap[1]; 766 ap->addr = (const struct sockaddr *) &ap[1];
764 GNUNET_memcpy(&ap[1], addr, addrlen); 767 GNUNET_memcpy (&ap[1], addr, addrlen);
765 ap->addrlen = addrlen; 768 ap->addrlen = addrlen;
766 ap->connection = connection; 769 ap->connection = connection;
767 770
768 switch (ap->addr->sa_family) 771 switch (ap->addr->sa_family)
769 { 772 {
770 case AF_INET: 773 case AF_INET:
771 ((struct sockaddr_in *)ap->addr)->sin_port = htons(connection->port); 774 ((struct sockaddr_in *) ap->addr)->sin_port = htons (connection->port);
772 break; 775 break;
773 776
774 case AF_INET6: 777 case AF_INET6:
775 ((struct sockaddr_in6 *)ap->addr)->sin6_port = htons(connection->port); 778 ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (connection->port);
776 break; 779 break;
777 780
778 default: 781 default:
779 GNUNET_break(0); 782 GNUNET_break (0);
780 GNUNET_free(ap); 783 GNUNET_free (ap);
781 return; /* not supported by us */ 784 return; /* not supported by us */
782 } 785 }
783 ap->sock = GNUNET_NETWORK_socket_create(ap->addr->sa_family, SOCK_STREAM, 0); 786 ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
784 if (NULL == ap->sock) 787 if (NULL == ap->sock)
785 { 788 {
786 GNUNET_free(ap); 789 GNUNET_free (ap);
787 return; /* not supported by OS */ 790 return; /* not supported by OS */
788 } 791 }
789 LOG(GNUNET_ERROR_TYPE_INFO, 792 LOG (GNUNET_ERROR_TYPE_INFO,
790 "Trying to connect to `%s' (%p)\n", 793 "Trying to connect to `%s' (%p)\n",
791 GNUNET_a2s(ap->addr, ap->addrlen), 794 GNUNET_a2s (ap->addr, ap->addrlen),
792 connection); 795 connection);
793 if ((GNUNET_OK != 796 if ((GNUNET_OK !=
794 GNUNET_NETWORK_socket_connect(ap->sock, ap->addr, ap->addrlen)) && 797 GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) &&
795 (EINPROGRESS != errno)) 798 (EINPROGRESS != errno))
796 { 799 {
797 /* maybe refused / unsupported address, try next */ 800 /* maybe refused / unsupported address, try next */
798 LOG_STRERROR(GNUNET_ERROR_TYPE_INFO, "connect"); 801 LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect");
799 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(ap->sock)); 802 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
800 GNUNET_free(ap); 803 GNUNET_free (ap);
801 return; 804 return;
802 } 805 }
803 GNUNET_CONTAINER_DLL_insert(connection->ap_head, connection->ap_tail, ap); 806 GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap);
804 delay = CONNECT_RETRY_TIMEOUT; 807 delay = CONNECT_RETRY_TIMEOUT;
805 if (NULL != connection->nth.notify_ready) 808 if (NULL != connection->nth.notify_ready)
806 delay = GNUNET_TIME_relative_min(delay, 809 delay = GNUNET_TIME_relative_min (delay,
807 GNUNET_TIME_absolute_get_remaining( 810 GNUNET_TIME_absolute_get_remaining (
808 connection->nth.transmit_timeout)); 811 connection->nth.transmit_timeout));
809 if (NULL != connection->receiver) 812 if (NULL != connection->receiver)
810 delay = GNUNET_TIME_relative_min(delay, 813 delay = GNUNET_TIME_relative_min (delay,
811 GNUNET_TIME_absolute_get_remaining( 814 GNUNET_TIME_absolute_get_remaining (
812 connection->receive_timeout)); 815 connection->receive_timeout));
813 ap->task = GNUNET_SCHEDULER_add_write_net(delay, 816 ap->task = GNUNET_SCHEDULER_add_write_net (delay,
814 ap->sock, 817 ap->sock,
815 &connect_probe_continuation, 818 &connect_probe_continuation,
816 ap); 819 ap);
817} 820}
818 821
819 822
@@ -828,25 +831,25 @@ try_connect_using_address(void *cls,
828 * @return the connection handle 831 * @return the connection handle
829 */ 832 */
830struct GNUNET_CONNECTION_Handle * 833struct GNUNET_CONNECTION_Handle *
831GNUNET_CONNECTION_create_from_connect( 834GNUNET_CONNECTION_create_from_connect (
832 const struct GNUNET_CONFIGURATION_Handle *cfg, 835 const struct GNUNET_CONFIGURATION_Handle *cfg,
833 const char *hostname, 836 const char *hostname,
834 uint16_t port) 837 uint16_t port)
835{ 838{
836 struct GNUNET_CONNECTION_Handle *connection; 839 struct GNUNET_CONNECTION_Handle *connection;
837 840
838 GNUNET_assert(0 < strlen(hostname)); /* sanity check */ 841 GNUNET_assert (0 < strlen (hostname)); /* sanity check */
839 connection = GNUNET_new(struct GNUNET_CONNECTION_Handle); 842 connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
840 connection->cfg = cfg; 843 connection->cfg = cfg;
841 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; 844 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE;
842 connection->write_buffer = GNUNET_malloc(connection->write_buffer_size); 845 connection->write_buffer = GNUNET_malloc (connection->write_buffer_size);
843 connection->port = port; 846 connection->port = port;
844 connection->hostname = GNUNET_strdup(hostname); 847 connection->hostname = GNUNET_strdup (hostname);
845 connection->dns_active = GNUNET_RESOLVER_ip_get(connection->hostname, 848 connection->dns_active = GNUNET_RESOLVER_ip_get (connection->hostname,
846 AF_UNSPEC, 849 AF_UNSPEC,
847 CONNECT_RETRY_TIMEOUT, 850 CONNECT_RETRY_TIMEOUT,
848 &try_connect_using_address, 851 &try_connect_using_address,
849 connection); 852 connection);
850 return connection; 853 return connection;
851} 854}
852 855
@@ -861,7 +864,7 @@ GNUNET_CONNECTION_create_from_connect(
861 * @return the connection handle, NULL on systems without UNIX support 864 * @return the connection handle, NULL on systems without UNIX support
862 */ 865 */
863struct GNUNET_CONNECTION_Handle * 866struct GNUNET_CONNECTION_Handle *
864GNUNET_CONNECTION_create_from_connect_to_unixpath( 867GNUNET_CONNECTION_create_from_connect_to_unixpath (
865 const struct GNUNET_CONFIGURATION_Handle *cfg, 868 const struct GNUNET_CONFIGURATION_Handle *cfg,
866 const char *unixpath) 869 const char *unixpath)
867{ 870{
@@ -869,51 +872,51 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath(
869 struct GNUNET_CONNECTION_Handle *connection; 872 struct GNUNET_CONNECTION_Handle *connection;
870 struct sockaddr_un *un; 873 struct sockaddr_un *un;
871 874
872 GNUNET_assert(0 < strlen(unixpath)); /* sanity check */ 875 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
873 un = GNUNET_new(struct sockaddr_un); 876 un = GNUNET_new (struct sockaddr_un);
874 un->sun_family = AF_UNIX; 877 un->sun_family = AF_UNIX;
875 GNUNET_strlcpy(un->sun_path, unixpath, sizeof(un->sun_path)); 878 GNUNET_strlcpy (un->sun_path, unixpath, sizeof(un->sun_path));
876#ifdef LINUX 879#ifdef LINUX
877 { 880 {
878 int abstract; 881 int abstract;
879 882
880 abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, 883 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
881 "TESTING", 884 "TESTING",
882 "USE_ABSTRACT_SOCKETS"); 885 "USE_ABSTRACT_SOCKETS");
883 if (GNUNET_YES == abstract) 886 if (GNUNET_YES == abstract)
884 un->sun_path[0] = '\0'; 887 un->sun_path[0] = '\0';
885 } 888 }
886#endif 889#endif
887#if HAVE_SOCKADDR_UN_SUN_LEN 890#if HAVE_SOCKADDR_UN_SUN_LEN
888 un->sun_len = (u_char)sizeof(struct sockaddr_un); 891 un->sun_len = (u_char) sizeof(struct sockaddr_un);
889#endif 892#endif
890 connection = GNUNET_new(struct GNUNET_CONNECTION_Handle); 893 connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
891 connection->cfg = cfg; 894 connection->cfg = cfg;
892 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; 895 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE;
893 connection->write_buffer = GNUNET_malloc(connection->write_buffer_size); 896 connection->write_buffer = GNUNET_malloc (connection->write_buffer_size);
894 connection->port = 0; 897 connection->port = 0;
895 connection->hostname = NULL; 898 connection->hostname = NULL;
896 connection->addr = (struct sockaddr *)un; 899 connection->addr = (struct sockaddr *) un;
897 connection->addrlen = sizeof(struct sockaddr_un); 900 connection->addrlen = sizeof(struct sockaddr_un);
898 connection->sock = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0); 901 connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
899 if (NULL == connection->sock) 902 if (NULL == connection->sock)
900 { 903 {
901 GNUNET_free(connection->addr); 904 GNUNET_free (connection->addr);
902 GNUNET_free(connection->write_buffer); 905 GNUNET_free (connection->write_buffer);
903 GNUNET_free(connection); 906 GNUNET_free (connection);
904 return NULL; 907 return NULL;
905 } 908 }
906 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect(connection->sock, 909 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (connection->sock,
907 connection->addr, 910 connection->addr,
908 connection->addrlen)) && 911 connection->addrlen)) &&
909 (EINPROGRESS != errno)) 912 (EINPROGRESS != errno))
910 { 913 {
911 /* Just return; we expect everything to work eventually so don't fail HARD */ 914 /* Just return; we expect everything to work eventually so don't fail HARD */
912 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(connection->sock)); 915 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock));
913 connection->sock = NULL; 916 connection->sock = NULL;
914 return connection; 917 return connection;
915 } 918 }
916 connect_success_continuation(connection); 919 connect_success_continuation (connection);
917 return connection; 920 return connection;
918#else 921#else
919 return NULL; 922 return NULL;
@@ -932,31 +935,31 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath(
932 * @return the connection handle 935 * @return the connection handle
933 */ 936 */
934struct GNUNET_CONNECTION_Handle * 937struct GNUNET_CONNECTION_Handle *
935GNUNET_CONNECTION_connect_socket(struct GNUNET_NETWORK_Handle *s, 938GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s,
936 const struct sockaddr *serv_addr, 939 const struct sockaddr *serv_addr,
937 socklen_t addrlen) 940 socklen_t addrlen)
938{ 941{
939 struct GNUNET_CONNECTION_Handle *connection; 942 struct GNUNET_CONNECTION_Handle *connection;
940 943
941 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect(s, serv_addr, addrlen)) && 944 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) &&
942 (EINPROGRESS != errno)) 945 (EINPROGRESS != errno))
943 { 946 {
944 /* maybe refused / unsupported address, try next */ 947 /* maybe refused / unsupported address, try next */
945 LOG_STRERROR(GNUNET_ERROR_TYPE_DEBUG, "connect"); 948 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "connect");
946 LOG(GNUNET_ERROR_TYPE_DEBUG, 949 LOG (GNUNET_ERROR_TYPE_DEBUG,
947 "Attempt to connect to `%s' failed\n", 950 "Attempt to connect to `%s' failed\n",
948 GNUNET_a2s(serv_addr, addrlen)); 951 GNUNET_a2s (serv_addr, addrlen));
949 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(s)); 952 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
950 return NULL; 953 return NULL;
951 } 954 }
952 connection = GNUNET_CONNECTION_create_from_existing(s); 955 connection = GNUNET_CONNECTION_create_from_existing (s);
953 connection->addr = GNUNET_malloc(addrlen); 956 connection->addr = GNUNET_malloc (addrlen);
954 GNUNET_memcpy(connection->addr, serv_addr, addrlen); 957 GNUNET_memcpy (connection->addr, serv_addr, addrlen);
955 connection->addrlen = addrlen; 958 connection->addrlen = addrlen;
956 LOG(GNUNET_ERROR_TYPE_INFO, 959 LOG (GNUNET_ERROR_TYPE_INFO,
957 "Trying to connect to `%s' (%p)\n", 960 "Trying to connect to `%s' (%p)\n",
958 GNUNET_a2s(serv_addr, addrlen), 961 GNUNET_a2s (serv_addr, addrlen),
959 connection); 962 connection);
960 return connection; 963 return connection;
961} 964}
962 965
@@ -973,19 +976,19 @@ GNUNET_CONNECTION_connect_socket(struct GNUNET_NETWORK_Handle *s,
973 * @return the connection handle 976 * @return the connection handle
974 */ 977 */
975struct GNUNET_CONNECTION_Handle * 978struct GNUNET_CONNECTION_Handle *
976GNUNET_CONNECTION_create_from_sockaddr(int af_family, 979GNUNET_CONNECTION_create_from_sockaddr (int af_family,
977 const struct sockaddr *serv_addr, 980 const struct sockaddr *serv_addr,
978 socklen_t addrlen) 981 socklen_t addrlen)
979{ 982{
980 struct GNUNET_NETWORK_Handle *s; 983 struct GNUNET_NETWORK_Handle *s;
981 984
982 s = GNUNET_NETWORK_socket_create(af_family, SOCK_STREAM, 0); 985 s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
983 if (NULL == s) 986 if (NULL == s)
984 { 987 {
985 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket"); 988 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
986 return NULL; 989 return NULL;
987 } 990 }
988 return GNUNET_CONNECTION_connect_socket(s, serv_addr, addrlen); 991 return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen);
989} 992}
990 993
991 994
@@ -998,7 +1001,7 @@ GNUNET_CONNECTION_create_from_sockaddr(int af_family,
998 * @return #GNUNET_YES if valid, #GNUNET_NO otherwise 1001 * @return #GNUNET_YES if valid, #GNUNET_NO otherwise
999 */ 1002 */
1000int 1003int
1001GNUNET_CONNECTION_check(struct GNUNET_CONNECTION_Handle *connection) 1004GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection)
1002{ 1005{
1003 if ((NULL != connection->ap_head) || (NULL != connection->dns_active) || 1006 if ((NULL != connection->ap_head) || (NULL != connection->dns_active) ||
1004 (NULL != connection->proxy_handshake)) 1007 (NULL != connection->proxy_handshake))
@@ -1017,78 +1020,78 @@ GNUNET_CONNECTION_check(struct GNUNET_CONNECTION_Handle *connection)
1017 * @param connection connection to destroy 1020 * @param connection connection to destroy
1018 */ 1021 */
1019void 1022void
1020GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection) 1023GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
1021{ 1024{
1022 struct AddressProbe *pos; 1025 struct AddressProbe *pos;
1023 1026
1024 if (0 != connection->destroy_later) 1027 if (0 != connection->destroy_later)
1025 { 1028 {
1026 connection->destroy_later = -1; 1029 connection->destroy_later = -1;
1027 return; 1030 return;
1028 } 1031 }
1029 LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection); 1032 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection);
1030 GNUNET_assert(NULL == connection->nth.notify_ready); 1033 GNUNET_assert (NULL == connection->nth.notify_ready);
1031 GNUNET_assert(NULL == connection->receiver); 1034 GNUNET_assert (NULL == connection->receiver);
1032 if (NULL != connection->write_task) 1035 if (NULL != connection->write_task)
1033 { 1036 {
1034 GNUNET_SCHEDULER_cancel(connection->write_task); 1037 GNUNET_SCHEDULER_cancel (connection->write_task);
1035 connection->write_task = NULL; 1038 connection->write_task = NULL;
1036 connection->write_buffer_off = 0; 1039 connection->write_buffer_off = 0;
1037 } 1040 }
1038 if (NULL != connection->read_task) 1041 if (NULL != connection->read_task)
1039 { 1042 {
1040 GNUNET_SCHEDULER_cancel(connection->read_task); 1043 GNUNET_SCHEDULER_cancel (connection->read_task);
1041 connection->read_task = NULL; 1044 connection->read_task = NULL;
1042 } 1045 }
1043 if (NULL != connection->nth.timeout_task) 1046 if (NULL != connection->nth.timeout_task)
1044 { 1047 {
1045 GNUNET_SCHEDULER_cancel(connection->nth.timeout_task); 1048 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task);
1046 connection->nth.timeout_task = NULL; 1049 connection->nth.timeout_task = NULL;
1047 } 1050 }
1048 connection->nth.notify_ready = NULL; 1051 connection->nth.notify_ready = NULL;
1049 if (NULL != connection->dns_active) 1052 if (NULL != connection->dns_active)
1050 { 1053 {
1051 GNUNET_RESOLVER_request_cancel(connection->dns_active); 1054 GNUNET_RESOLVER_request_cancel (connection->dns_active);
1052 connection->dns_active = NULL; 1055 connection->dns_active = NULL;
1053 } 1056 }
1054 if (NULL != connection->proxy_handshake) 1057 if (NULL != connection->proxy_handshake)
1055 { 1058 {
1056 /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */ 1059 /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */
1057 connection->proxy_handshake->destroy_later = -1; 1060 connection->proxy_handshake->destroy_later = -1;
1058 connection->proxy_handshake = NULL; /* Not leaked ??? */ 1061 connection->proxy_handshake = NULL; /* Not leaked ??? */
1059 } 1062 }
1060 while (NULL != (pos = connection->ap_head)) 1063 while (NULL != (pos = connection->ap_head))
1061 { 1064 {
1062 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(pos->sock)); 1065 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
1063 GNUNET_SCHEDULER_cancel(pos->task); 1066 GNUNET_SCHEDULER_cancel (pos->task);
1064 GNUNET_CONTAINER_DLL_remove(connection->ap_head, connection->ap_tail, pos); 1067 GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
1065 GNUNET_free(pos); 1068 GNUNET_free (pos);
1066 } 1069 }
1067 if ((NULL != connection->sock) && (GNUNET_YES != connection->persist)) 1070 if ((NULL != connection->sock) && (GNUNET_YES != connection->persist))
1071 {
1072 if ((GNUNET_OK !=
1073 GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) &&
1074 (ENOTCONN != errno) && (ECONNRESET != errno))
1075 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown");
1076 }
1077 if (NULL != connection->sock)
1078 {
1079 if (GNUNET_YES != connection->persist)
1068 { 1080 {
1069 if ((GNUNET_OK != 1081 GNUNET_break (GNUNET_OK ==
1070 GNUNET_NETWORK_socket_shutdown(connection->sock, SHUT_RDWR)) && 1082 GNUNET_NETWORK_socket_close (connection->sock));
1071 (ENOTCONN != errno) && (ECONNRESET != errno))
1072 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "shutdown");
1073 } 1083 }
1074 if (NULL != connection->sock) 1084 else
1075 { 1085 {
1076 if (GNUNET_YES != connection->persist) 1086 GNUNET_NETWORK_socket_free_memory_only_ (
1077 { 1087 connection->sock); /* at least no memory leak (we deliberately
1078 GNUNET_break(GNUNET_OK ==
1079 GNUNET_NETWORK_socket_close(connection->sock));
1080 }
1081 else
1082 {
1083 GNUNET_NETWORK_socket_free_memory_only_(
1084 connection->sock); /* at least no memory leak (we deliberately
1085 * leak the socket in this special case) ... */ 1088 * leak the socket in this special case) ... */
1086 }
1087 } 1089 }
1088 GNUNET_free_non_null(connection->addr); 1090 }
1089 GNUNET_free_non_null(connection->hostname); 1091 GNUNET_free_non_null (connection->addr);
1090 GNUNET_free(connection->write_buffer); 1092 GNUNET_free_non_null (connection->hostname);
1091 GNUNET_free(connection); 1093 GNUNET_free (connection->write_buffer);
1094 GNUNET_free (connection);
1092} 1095}
1093 1096
1094 1097
@@ -1099,7 +1102,7 @@ GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection)
1099 * @param cls connection to read from 1102 * @param cls connection to read from
1100 */ 1103 */
1101static void 1104static void
1102receive_ready(void *cls) 1105receive_ready (void *cls)
1103{ 1106{
1104 struct GNUNET_CONNECTION_Handle *connection = cls; 1107 struct GNUNET_CONNECTION_Handle *connection = cls;
1105 const struct GNUNET_SCHEDULER_TaskContext *tc; 1108 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -1108,49 +1111,50 @@ receive_ready(void *cls)
1108 GNUNET_CONNECTION_Receiver receiver; 1111 GNUNET_CONNECTION_Receiver receiver;
1109 1112
1110 connection->read_task = NULL; 1113 connection->read_task = NULL;
1111 tc = GNUNET_SCHEDULER_get_task_context(); 1114 tc = GNUNET_SCHEDULER_get_task_context ();
1112 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1115 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1113 { 1116 {
1114 LOG(GNUNET_ERROR_TYPE_DEBUG, 1117 LOG (GNUNET_ERROR_TYPE_DEBUG,
1115 "Receive from `%s' encounters error: timeout (%s, %p)\n", 1118 "Receive from `%s' encounters error: timeout (%s, %p)\n",
1116 GNUNET_a2s(connection->addr, connection->addrlen), 1119 GNUNET_a2s (connection->addr, connection->addrlen),
1117 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration( 1120 GNUNET_STRINGS_relative_time_to_string (
1118 connection->receive_timeout), 1121 GNUNET_TIME_absolute_get_duration (
1119 GNUNET_YES), 1122 connection->receive_timeout),
1120 connection); 1123 GNUNET_YES),
1121 signal_receive_timeout(connection); 1124 connection);
1122 return; 1125 signal_receive_timeout (connection);
1123 } 1126 return;
1127 }
1124 if (NULL == connection->sock) 1128 if (NULL == connection->sock)
1125 { 1129 {
1126 /* connect failed for good */ 1130 /* connect failed for good */
1127 signal_receive_error(connection, ECONNREFUSED); 1131 signal_receive_error (connection, ECONNREFUSED);
1128 return; 1132 return;
1129 } 1133 }
1130 GNUNET_assert(GNUNET_NETWORK_fdset_isset(tc->read_ready, connection->sock)); 1134 GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock));
1131RETRY: 1135RETRY:
1132 ret = GNUNET_NETWORK_socket_recv(connection->sock, buffer, connection->max); 1136 ret = GNUNET_NETWORK_socket_recv (connection->sock, buffer, connection->max);
1133 if (-1 == ret) 1137 if (-1 == ret)
1134 { 1138 {
1135 if (EINTR == errno) 1139 if (EINTR == errno)
1136 goto RETRY; 1140 goto RETRY;
1137 signal_receive_error(connection, errno); 1141 signal_receive_error (connection, errno);
1138 return; 1142 return;
1139 } 1143 }
1140 LOG(GNUNET_ERROR_TYPE_DEBUG, 1144 LOG (GNUNET_ERROR_TYPE_DEBUG,
1141 "receive_ready read %u/%u bytes from `%s' (%p)!\n", 1145 "receive_ready read %u/%u bytes from `%s' (%p)!\n",
1142 (unsigned int)ret, 1146 (unsigned int) ret,
1143 connection->max, 1147 connection->max,
1144 GNUNET_a2s(connection->addr, connection->addrlen), 1148 GNUNET_a2s (connection->addr, connection->addrlen),
1145 connection); 1149 connection);
1146 GNUNET_assert(NULL != (receiver = connection->receiver)); 1150 GNUNET_assert (NULL != (receiver = connection->receiver));
1147 connection->receiver = NULL; 1151 connection->receiver = NULL;
1148 receiver(connection->receiver_cls, 1152 receiver (connection->receiver_cls,
1149 buffer, 1153 buffer,
1150 ret, 1154 ret,
1151 connection->addr, 1155 connection->addr,
1152 connection->addrlen, 1156 connection->addrlen,
1153 0); 1157 0);
1154} 1158}
1155 1159
1156 1160
@@ -1170,36 +1174,36 @@ RETRY:
1170 * called with error) 1174 * called with error)
1171 */ 1175 */
1172int 1176int
1173GNUNET_CONNECTION_receive(struct GNUNET_CONNECTION_Handle *connection, 1177GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
1174 size_t max, 1178 size_t max,
1175 struct GNUNET_TIME_Relative timeout, 1179 struct GNUNET_TIME_Relative timeout,
1176 GNUNET_CONNECTION_Receiver receiver, 1180 GNUNET_CONNECTION_Receiver receiver,
1177 void *receiver_cls) 1181 void *receiver_cls)
1178{ 1182{
1179 GNUNET_assert((NULL == connection->read_task) && 1183 GNUNET_assert ((NULL == connection->read_task) &&
1180 (NULL == connection->receiver)); 1184 (NULL == connection->receiver));
1181 GNUNET_assert(NULL != receiver); 1185 GNUNET_assert (NULL != receiver);
1182 connection->receiver = receiver; 1186 connection->receiver = receiver;
1183 connection->receiver_cls = receiver_cls; 1187 connection->receiver_cls = receiver_cls;
1184 connection->receive_timeout = GNUNET_TIME_relative_to_absolute(timeout); 1188 connection->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1185 connection->max = max; 1189 connection->max = max;
1186 if (NULL != connection->sock) 1190 if (NULL != connection->sock)
1187 { 1191 {
1188 connection->read_task = 1192 connection->read_task =
1189 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_absolute_get_remaining( 1193 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (
1190 connection->receive_timeout), 1194 connection->receive_timeout),
1191 connection->sock, 1195 connection->sock,
1192 &receive_ready, 1196 &receive_ready,
1193 connection); 1197 connection);
1194 return GNUNET_OK; 1198 return GNUNET_OK;
1195 } 1199 }
1196 if ((NULL == connection->dns_active) && (NULL == connection->ap_head) && 1200 if ((NULL == connection->dns_active) && (NULL == connection->ap_head) &&
1197 (NULL == connection->proxy_handshake)) 1201 (NULL == connection->proxy_handshake))
1198 { 1202 {
1199 connection->receiver = NULL; 1203 connection->receiver = NULL;
1200 receiver(receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); 1204 receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
1201 return GNUNET_SYSERR; 1205 return GNUNET_SYSERR;
1202 } 1206 }
1203 return GNUNET_OK; 1207 return GNUNET_OK;
1204} 1208}
1205 1209
@@ -1213,14 +1217,14 @@ GNUNET_CONNECTION_receive(struct GNUNET_CONNECTION_Handle *connection,
1213 * @return closure of the original receiver callback closure 1217 * @return closure of the original receiver callback closure
1214 */ 1218 */
1215void * 1219void *
1216GNUNET_CONNECTION_receive_cancel(struct GNUNET_CONNECTION_Handle *connection) 1220GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection)
1217{ 1221{
1218 if (NULL != connection->read_task) 1222 if (NULL != connection->read_task)
1219 { 1223 {
1220 GNUNET_assert(connection == 1224 GNUNET_assert (connection ==
1221 GNUNET_SCHEDULER_cancel(connection->read_task)); 1225 GNUNET_SCHEDULER_cancel (connection->read_task));
1222 connection->read_task = NULL; 1226 connection->read_task = NULL;
1223 } 1227 }
1224 connection->receiver = NULL; 1228 connection->receiver = NULL;
1225 return connection->receiver_cls; 1229 return connection->receiver_cls;
1226} 1230}
@@ -1234,44 +1238,44 @@ GNUNET_CONNECTION_receive_cancel(struct GNUNET_CONNECTION_Handle *connection)
1234 * @return #GNUNET_YES if we were able to call notify 1238 * @return #GNUNET_YES if we were able to call notify
1235 */ 1239 */
1236static int 1240static int
1237process_notify(struct GNUNET_CONNECTION_Handle *connection) 1241process_notify (struct GNUNET_CONNECTION_Handle *connection)
1238{ 1242{
1239 size_t used; 1243 size_t used;
1240 size_t avail; 1244 size_t avail;
1241 size_t size; 1245 size_t size;
1242 GNUNET_CONNECTION_TransmitReadyNotify notify; 1246 GNUNET_CONNECTION_TransmitReadyNotify notify;
1243 1247
1244 LOG(GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n"); 1248 LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n");
1245 GNUNET_assert(NULL == connection->write_task); 1249 GNUNET_assert (NULL == connection->write_task);
1246 if (NULL == (notify = connection->nth.notify_ready)) 1250 if (NULL == (notify = connection->nth.notify_ready))
1247 { 1251 {
1248 LOG(GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n"); 1252 LOG (GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n");
1249 return GNUNET_NO; 1253 return GNUNET_NO;
1250 } 1254 }
1251 used = connection->write_buffer_off - connection->write_buffer_pos; 1255 used = connection->write_buffer_off - connection->write_buffer_pos;
1252 avail = connection->write_buffer_size - used; 1256 avail = connection->write_buffer_size - used;
1253 size = connection->nth.notify_size; 1257 size = connection->nth.notify_size;
1254 if (size > avail) 1258 if (size > avail)
1255 { 1259 {
1256 LOG(GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n"); 1260 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n");
1257 return GNUNET_NO; 1261 return GNUNET_NO;
1258 } 1262 }
1259 connection->nth.notify_ready = NULL; 1263 connection->nth.notify_ready = NULL;
1260 if (connection->write_buffer_size - connection->write_buffer_off < size) 1264 if (connection->write_buffer_size - connection->write_buffer_off < size)
1261 { 1265 {
1262 /* need to compact */ 1266 /* need to compact */
1263 memmove(connection->write_buffer, 1267 memmove (connection->write_buffer,
1264 &connection->write_buffer[connection->write_buffer_pos], 1268 &connection->write_buffer[connection->write_buffer_pos],
1265 used); 1269 used);
1266 connection->write_buffer_off -= connection->write_buffer_pos; 1270 connection->write_buffer_off -= connection->write_buffer_pos;
1267 connection->write_buffer_pos = 0; 1271 connection->write_buffer_pos = 0;
1268 } 1272 }
1269 avail = connection->write_buffer_size - connection->write_buffer_off; 1273 avail = connection->write_buffer_size - connection->write_buffer_off;
1270 GNUNET_assert(avail >= size); 1274 GNUNET_assert (avail >= size);
1271 size = notify(connection->nth.notify_ready_cls, 1275 size = notify (connection->nth.notify_ready_cls,
1272 avail, 1276 avail,
1273 &connection->write_buffer[connection->write_buffer_off]); 1277 &connection->write_buffer[connection->write_buffer_off]);
1274 GNUNET_assert(size <= avail); 1278 GNUNET_assert (size <= avail);
1275 if (0 != size) 1279 if (0 != size)
1276 connection->write_buffer_off += size; 1280 connection->write_buffer_off += size;
1277 return GNUNET_YES; 1281 return GNUNET_YES;
@@ -1289,22 +1293,22 @@ process_notify(struct GNUNET_CONNECTION_Handle *connection)
1289 * @param cls the `struct GNUNET_CONNECTION_Handle` 1293 * @param cls the `struct GNUNET_CONNECTION_Handle`
1290 */ 1294 */
1291static void 1295static void
1292transmit_timeout(void *cls) 1296transmit_timeout (void *cls)
1293{ 1297{
1294 struct GNUNET_CONNECTION_Handle *connection = cls; 1298 struct GNUNET_CONNECTION_Handle *connection = cls;
1295 GNUNET_CONNECTION_TransmitReadyNotify notify; 1299 GNUNET_CONNECTION_TransmitReadyNotify notify;
1296 1300
1297 connection->nth.timeout_task = NULL; 1301 connection->nth.timeout_task = NULL;
1298 LOG(GNUNET_ERROR_TYPE_DEBUG, 1302 LOG (GNUNET_ERROR_TYPE_DEBUG,
1299 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", 1303 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n",
1300 connection->hostname, 1304 connection->hostname,
1301 connection->port, 1305 connection->port,
1302 GNUNET_a2s(connection->addr, connection->addrlen), 1306 GNUNET_a2s (connection->addr, connection->addrlen),
1303 connection); 1307 connection);
1304 notify = connection->nth.notify_ready; 1308 notify = connection->nth.notify_ready;
1305 GNUNET_assert(NULL != notify); 1309 GNUNET_assert (NULL != notify);
1306 connection->nth.notify_ready = NULL; 1310 connection->nth.notify_ready = NULL;
1307 notify(connection->nth.notify_ready_cls, 0, NULL); 1311 notify (connection->nth.notify_ready_cls, 0, NULL);
1308} 1312}
1309 1313
1310 1314
@@ -1317,21 +1321,21 @@ transmit_timeout(void *cls)
1317 * @param cls the `struct GNUNET_CONNECTION_Handle` 1321 * @param cls the `struct GNUNET_CONNECTION_Handle`
1318 */ 1322 */
1319static void 1323static void
1320connect_error(void *cls) 1324connect_error (void *cls)
1321{ 1325{
1322 struct GNUNET_CONNECTION_Handle *connection = cls; 1326 struct GNUNET_CONNECTION_Handle *connection = cls;
1323 GNUNET_CONNECTION_TransmitReadyNotify notify; 1327 GNUNET_CONNECTION_TransmitReadyNotify notify;
1324 1328
1325 LOG(GNUNET_ERROR_TYPE_DEBUG, 1329 LOG (GNUNET_ERROR_TYPE_DEBUG,
1326 "Transmission request of size %u fails (%s/%u), connection failed (%p).\n", 1330 "Transmission request of size %u fails (%s/%u), connection failed (%p).\n",
1327 connection->nth.notify_size, 1331 connection->nth.notify_size,
1328 connection->hostname, 1332 connection->hostname,
1329 connection->port, 1333 connection->port,
1330 connection); 1334 connection);
1331 connection->write_task = NULL; 1335 connection->write_task = NULL;
1332 notify = connection->nth.notify_ready; 1336 notify = connection->nth.notify_ready;
1333 connection->nth.notify_ready = NULL; 1337 connection->nth.notify_ready = NULL;
1334 notify(connection->nth.notify_ready_cls, 0, NULL); 1338 notify (connection->nth.notify_ready_cls, 0, NULL);
1335} 1339}
1336 1340
1337 1341
@@ -1341,7 +1345,7 @@ connect_error(void *cls)
1341 * @param cls our connection handle 1345 * @param cls our connection handle
1342 */ 1346 */
1343static void 1347static void
1344transmit_ready(void *cls) 1348transmit_ready (void *cls)
1345{ 1349{
1346 struct GNUNET_CONNECTION_Handle *connection = cls; 1350 struct GNUNET_CONNECTION_Handle *connection = cls;
1347 GNUNET_CONNECTION_TransmitReadyNotify notify; 1351 GNUNET_CONNECTION_TransmitReadyNotify notify;
@@ -1349,107 +1353,107 @@ transmit_ready(void *cls)
1349 ssize_t ret; 1353 ssize_t ret;
1350 size_t have; 1354 size_t have;
1351 1355
1352 LOG(GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection); 1356 LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection);
1353 GNUNET_assert(NULL != connection->write_task); 1357 GNUNET_assert (NULL != connection->write_task);
1354 connection->write_task = NULL; 1358 connection->write_task = NULL;
1355 GNUNET_assert(NULL == connection->nth.timeout_task); 1359 GNUNET_assert (NULL == connection->nth.timeout_task);
1356 tc = GNUNET_SCHEDULER_get_task_context(); 1360 tc = GNUNET_SCHEDULER_get_task_context ();
1357 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1361 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1358 { 1362 {
1359 LOG(GNUNET_ERROR_TYPE_DEBUG, 1363 LOG (GNUNET_ERROR_TYPE_DEBUG,
1360 "Transmit to `%s' fails, time out reached (%p).\n", 1364 "Transmit to `%s' fails, time out reached (%p).\n",
1361 GNUNET_a2s(connection->addr, connection->addrlen), 1365 GNUNET_a2s (connection->addr, connection->addrlen),
1362 connection); 1366 connection);
1363 notify = connection->nth.notify_ready; 1367 notify = connection->nth.notify_ready;
1364 GNUNET_assert(NULL != notify); 1368 GNUNET_assert (NULL != notify);
1365 connection->nth.notify_ready = NULL; 1369 connection->nth.notify_ready = NULL;
1366 notify(connection->nth.notify_ready_cls, 0, NULL); 1370 notify (connection->nth.notify_ready_cls, 0, NULL);
1367 return; 1371 return;
1368 } 1372 }
1369 GNUNET_assert(NULL != connection->sock); 1373 GNUNET_assert (NULL != connection->sock);
1370 if (NULL == tc->write_ready) 1374 if (NULL == tc->write_ready)
1371 { 1375 {
1372 /* special circumstances (in particular, PREREQ_DONE after 1376 /* special circumstances (in particular, PREREQ_DONE after
1373 * connect): not yet ready to write, but no "fatal" error either. 1377 * connect): not yet ready to write, but no "fatal" error either.
1374 * Hence retry. */ 1378 * Hence retry. */
1375 goto SCHEDULE_WRITE; 1379 goto SCHEDULE_WRITE;
1376 } 1380 }
1377 if (!GNUNET_NETWORK_fdset_isset(tc->write_ready, connection->sock)) 1381 if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock))
1378 { 1382 {
1379 GNUNET_assert(NULL == connection->write_task); 1383 GNUNET_assert (NULL == connection->write_task);
1380 /* special circumstances (in particular, shutdown): not yet ready 1384 /* special circumstances (in particular, shutdown): not yet ready
1381 * to write, but no "fatal" error either. Hence retry. */ 1385 * to write, but no "fatal" error either. Hence retry. */
1382 goto SCHEDULE_WRITE; 1386 goto SCHEDULE_WRITE;
1383 } 1387 }
1384 GNUNET_assert(connection->write_buffer_off >= connection->write_buffer_pos); 1388 GNUNET_assert (connection->write_buffer_off >= connection->write_buffer_pos);
1385 if ((NULL != connection->nth.notify_ready) && 1389 if ((NULL != connection->nth.notify_ready) &&
1386 (connection->write_buffer_size < connection->nth.notify_size)) 1390 (connection->write_buffer_size < connection->nth.notify_size))
1387 { 1391 {
1388 connection->write_buffer = 1392 connection->write_buffer =
1389 GNUNET_realloc(connection->write_buffer, connection->nth.notify_size); 1393 GNUNET_realloc (connection->write_buffer, connection->nth.notify_size);
1390 connection->write_buffer_size = connection->nth.notify_size; 1394 connection->write_buffer_size = connection->nth.notify_size;
1391 } 1395 }
1392 process_notify(connection); 1396 process_notify (connection);
1393 have = connection->write_buffer_off - connection->write_buffer_pos; 1397 have = connection->write_buffer_off - connection->write_buffer_pos;
1394 if (0 == have) 1398 if (0 == have)
1395 { 1399 {
1396 /* no data ready for writing, terminate write loop */ 1400 /* no data ready for writing, terminate write loop */
1397 return; 1401 return;
1398 } 1402 }
1399 GNUNET_assert(have <= connection->write_buffer_size); 1403 GNUNET_assert (have <= connection->write_buffer_size);
1400 GNUNET_assert(have + connection->write_buffer_pos <= 1404 GNUNET_assert (have + connection->write_buffer_pos <=
1401 connection->write_buffer_size); 1405 connection->write_buffer_size);
1402 GNUNET_assert(connection->write_buffer_pos <= connection->write_buffer_size); 1406 GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size);
1403RETRY: 1407RETRY:
1404 ret = 1408 ret =
1405 GNUNET_NETWORK_socket_send(connection->sock, 1409 GNUNET_NETWORK_socket_send (connection->sock,
1406 &connection 1410 &connection
1407 ->write_buffer[connection->write_buffer_pos], 1411 ->write_buffer[connection->write_buffer_pos],
1408 have); 1412 have);
1409 if (-1 == ret) 1413 if (-1 == ret)
1414 {
1415 if (EINTR == errno)
1416 goto RETRY;
1417 if (NULL != connection->write_task)
1410 { 1418 {
1411 if (EINTR == errno) 1419 GNUNET_SCHEDULER_cancel (connection->write_task);
1412 goto RETRY; 1420 connection->write_task = NULL;
1413 if (NULL != connection->write_task)
1414 {
1415 GNUNET_SCHEDULER_cancel(connection->write_task);
1416 connection->write_task = NULL;
1417 }
1418 signal_transmit_error(connection, errno);
1419 return;
1420 } 1421 }
1421 LOG(GNUNET_ERROR_TYPE_DEBUG, 1422 signal_transmit_error (connection, errno);
1422 "Connection transmitted %u/%u bytes to `%s' (%p)\n", 1423 return;
1423 (unsigned int)ret, 1424 }
1424 have, 1425 LOG (GNUNET_ERROR_TYPE_DEBUG,
1425 GNUNET_a2s(connection->addr, connection->addrlen), 1426 "Connection transmitted %u/%u bytes to `%s' (%p)\n",
1426 connection); 1427 (unsigned int) ret,
1428 have,
1429 GNUNET_a2s (connection->addr, connection->addrlen),
1430 connection);
1427 connection->write_buffer_pos += ret; 1431 connection->write_buffer_pos += ret;
1428 if (connection->write_buffer_pos == connection->write_buffer_off) 1432 if (connection->write_buffer_pos == connection->write_buffer_off)
1429 { 1433 {
1430 /* transmitted all pending data */ 1434 /* transmitted all pending data */
1431 connection->write_buffer_pos = 0; 1435 connection->write_buffer_pos = 0;
1432 connection->write_buffer_off = 0; 1436 connection->write_buffer_off = 0;
1433 } 1437 }
1434 if ((0 == connection->write_buffer_off) && 1438 if ((0 == connection->write_buffer_off) &&
1435 (NULL == connection->nth.notify_ready)) 1439 (NULL == connection->nth.notify_ready))
1436 return; /* all data sent! */ 1440 return; /* all data sent! */
1437 /* not done writing, schedule more */ 1441 /* not done writing, schedule more */
1438SCHEDULE_WRITE: 1442SCHEDULE_WRITE:
1439 LOG(GNUNET_ERROR_TYPE_DEBUG, 1443 LOG (GNUNET_ERROR_TYPE_DEBUG,
1440 "Re-scheduling transmit_ready (more to do) (%p).\n", 1444 "Re-scheduling transmit_ready (more to do) (%p).\n",
1441 connection); 1445 connection);
1442 have = connection->write_buffer_off - connection->write_buffer_pos; 1446 have = connection->write_buffer_off - connection->write_buffer_pos;
1443 GNUNET_assert((NULL != connection->nth.notify_ready) || (have > 0)); 1447 GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0));
1444 if (NULL == connection->write_task) 1448 if (NULL == connection->write_task)
1445 connection->write_task = 1449 connection->write_task =
1446 GNUNET_SCHEDULER_add_write_net((connection->nth.notify_ready == NULL) 1450 GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == NULL)
1447 ? GNUNET_TIME_UNIT_FOREVER_REL 1451 ? GNUNET_TIME_UNIT_FOREVER_REL
1448 : GNUNET_TIME_absolute_get_remaining( 1452 : GNUNET_TIME_absolute_get_remaining (
1449 connection->nth.transmit_timeout), 1453 connection->nth.transmit_timeout),
1450 connection->sock, 1454 connection->sock,
1451 &transmit_ready, 1455 &transmit_ready,
1452 connection); 1456 connection);
1453} 1457}
1454 1458
1455 1459
@@ -1468,7 +1472,7 @@ SCHEDULE_WRITE:
1468 * NULL if we are already going to notify someone else (busy) 1472 * NULL if we are already going to notify someone else (busy)
1469 */ 1473 */
1470struct GNUNET_CONNECTION_TransmitHandle * 1474struct GNUNET_CONNECTION_TransmitHandle *
1471GNUNET_CONNECTION_notify_transmit_ready( 1475GNUNET_CONNECTION_notify_transmit_ready (
1472 struct GNUNET_CONNECTION_Handle *connection, 1476 struct GNUNET_CONNECTION_Handle *connection,
1473 size_t size, 1477 size_t size,
1474 struct GNUNET_TIME_Relative timeout, 1478 struct GNUNET_TIME_Relative timeout,
@@ -1476,52 +1480,52 @@ GNUNET_CONNECTION_notify_transmit_ready(
1476 void *notify_cls) 1480 void *notify_cls)
1477{ 1481{
1478 if (NULL != connection->nth.notify_ready) 1482 if (NULL != connection->nth.notify_ready)
1479 { 1483 {
1480 GNUNET_assert(0); 1484 GNUNET_assert (0);
1481 return NULL; 1485 return NULL;
1482 } 1486 }
1483 GNUNET_assert(NULL != notify); 1487 GNUNET_assert (NULL != notify);
1484 GNUNET_assert(size < GNUNET_MAX_MESSAGE_SIZE); 1488 GNUNET_assert (size < GNUNET_MAX_MESSAGE_SIZE);
1485 GNUNET_assert(connection->write_buffer_off <= connection->write_buffer_size); 1489 GNUNET_assert (connection->write_buffer_off <= connection->write_buffer_size);
1486 GNUNET_assert(connection->write_buffer_pos <= connection->write_buffer_size); 1490 GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size);
1487 GNUNET_assert(connection->write_buffer_pos <= connection->write_buffer_off); 1491 GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_off);
1488 connection->nth.notify_ready = notify; 1492 connection->nth.notify_ready = notify;
1489 connection->nth.notify_ready_cls = notify_cls; 1493 connection->nth.notify_ready_cls = notify_cls;
1490 connection->nth.connection = connection; 1494 connection->nth.connection = connection;
1491 connection->nth.notify_size = size; 1495 connection->nth.notify_size = size;
1492 connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute(timeout); 1496 connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1493 GNUNET_assert(NULL == connection->nth.timeout_task); 1497 GNUNET_assert (NULL == connection->nth.timeout_task);
1494 if ((NULL == connection->sock) && (NULL == connection->ap_head) && 1498 if ((NULL == connection->sock) && (NULL == connection->ap_head) &&
1495 (NULL == connection->dns_active) && (NULL == connection->proxy_handshake)) 1499 (NULL == connection->dns_active) && (NULL == connection->proxy_handshake))
1496 { 1500 {
1497 if (NULL != connection->write_task) 1501 if (NULL != connection->write_task)
1498 GNUNET_SCHEDULER_cancel(connection->write_task); 1502 GNUNET_SCHEDULER_cancel (connection->write_task);
1499 connection->write_task = 1503 connection->write_task =
1500 GNUNET_SCHEDULER_add_now(&connect_error, connection); 1504 GNUNET_SCHEDULER_add_now (&connect_error, connection);
1501 return &connection->nth; 1505 return &connection->nth;
1502 } 1506 }
1503 if (NULL != connection->write_task) 1507 if (NULL != connection->write_task)
1504 return &connection->nth; /* previous transmission still in progress */ 1508 return &connection->nth; /* previous transmission still in progress */
1505 if (NULL != connection->sock) 1509 if (NULL != connection->sock)
1506 { 1510 {
1507 /* connected, try to transmit now */ 1511 /* connected, try to transmit now */
1508 LOG(GNUNET_ERROR_TYPE_DEBUG, 1512 LOG (GNUNET_ERROR_TYPE_DEBUG,
1509 "Scheduling transmission (%p).\n", 1513 "Scheduling transmission (%p).\n",
1510 connection); 1514 connection);
1511 connection->write_task = 1515 connection->write_task =
1512 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_absolute_get_remaining( 1516 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining (
1513 connection->nth.transmit_timeout), 1517 connection->nth.transmit_timeout),
1514 connection->sock, 1518 connection->sock,
1515 &transmit_ready, 1519 &transmit_ready,
1516 connection); 1520 connection);
1517 return &connection->nth; 1521 return &connection->nth;
1518 } 1522 }
1519 /* not yet connected, wait for connection */ 1523 /* not yet connected, wait for connection */
1520 LOG(GNUNET_ERROR_TYPE_DEBUG, 1524 LOG (GNUNET_ERROR_TYPE_DEBUG,
1521 "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", 1525 "Need to wait to schedule transmission for connection, adding timeout task (%p).\n",
1522 connection); 1526 connection);
1523 connection->nth.timeout_task = 1527 connection->nth.timeout_task =
1524 GNUNET_SCHEDULER_add_delayed(timeout, &transmit_timeout, connection); 1528 GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection);
1525 return &connection->nth; 1529 return &connection->nth;
1526} 1530}
1527 1531
@@ -1532,21 +1536,21 @@ GNUNET_CONNECTION_notify_transmit_ready(
1532 * @param th notification to cancel 1536 * @param th notification to cancel
1533 */ 1537 */
1534void 1538void
1535GNUNET_CONNECTION_notify_transmit_ready_cancel( 1539GNUNET_CONNECTION_notify_transmit_ready_cancel (
1536 struct GNUNET_CONNECTION_TransmitHandle *th) 1540 struct GNUNET_CONNECTION_TransmitHandle *th)
1537{ 1541{
1538 GNUNET_assert(NULL != th->notify_ready); 1542 GNUNET_assert (NULL != th->notify_ready);
1539 th->notify_ready = NULL; 1543 th->notify_ready = NULL;
1540 if (NULL != th->timeout_task) 1544 if (NULL != th->timeout_task)
1541 { 1545 {
1542 GNUNET_SCHEDULER_cancel(th->timeout_task); 1546 GNUNET_SCHEDULER_cancel (th->timeout_task);
1543 th->timeout_task = NULL; 1547 th->timeout_task = NULL;
1544 } 1548 }
1545 if (NULL != th->connection->write_task) 1549 if (NULL != th->connection->write_task)
1546 { 1550 {
1547 GNUNET_SCHEDULER_cancel(th->connection->write_task); 1551 GNUNET_SCHEDULER_cancel (th->connection->write_task);
1548 th->connection->write_task = NULL; 1552 th->connection->write_task = NULL;
1549 } 1553 }
1550} 1554}
1551 1555
1552 1556
@@ -1557,11 +1561,11 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel(
1557 * @return connection to be proxied 1561 * @return connection to be proxied
1558 */ 1562 */
1559struct GNUNET_CONNECTION_Handle * 1563struct GNUNET_CONNECTION_Handle *
1560GNUNET_CONNECTION_create_proxied_from_handshake( 1564GNUNET_CONNECTION_create_proxied_from_handshake (
1561 struct GNUNET_CONNECTION_Handle *cph) 1565 struct GNUNET_CONNECTION_Handle *cph)
1562{ 1566{
1563 struct GNUNET_CONNECTION_Handle *proxied = 1567 struct GNUNET_CONNECTION_Handle *proxied =
1564 GNUNET_CONNECTION_create_from_existing(NULL); 1568 GNUNET_CONNECTION_create_from_existing (NULL);
1565 1569
1566 proxied->proxy_handshake = cph; 1570 proxied->proxy_handshake = cph;
1567 return proxied; 1571 return proxied;
@@ -1576,17 +1580,17 @@ GNUNET_CONNECTION_create_proxied_from_handshake(
1576 * @param proxied connection connection to proxy server 1580 * @param proxied connection connection to proxy server
1577 */ 1581 */
1578void 1582void
1579GNUNET_CONNECTION_acivate_proxied(struct GNUNET_CONNECTION_Handle *proxied) 1583GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied)
1580{ 1584{
1581 struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake; 1585 struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake;
1582 1586
1583 GNUNET_assert(NULL != cph); 1587 GNUNET_assert (NULL != cph);
1584 GNUNET_assert(NULL == proxied->sock); 1588 GNUNET_assert (NULL == proxied->sock);
1585 GNUNET_assert(NULL != cph->sock); 1589 GNUNET_assert (NULL != cph->sock);
1586 proxied->sock = cph->sock; 1590 proxied->sock = cph->sock;
1587 cph->sock = NULL; 1591 cph->sock = NULL;
1588 GNUNET_CONNECTION_destroy(cph); 1592 GNUNET_CONNECTION_destroy (cph);
1589 connect_success_continuation(proxied); 1593 connect_success_continuation (proxied);
1590} 1594}
1591 1595
1592 1596
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 @@
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_protocols.h" 29#include "gnunet_protocols.h"
30 30
31#define LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file(kind, "util-server", syscall, filename) 31#define LOG_STRERROR_FILE(kind, syscall, \
32 filename) GNUNET_log_from_strerror_file (kind, \
33 "util-server", \
34 syscall, \
35 filename)
32 36
33 37
34/** 38/**
35 * List of arrays of message handlers. 39 * List of arrays of message handlers.
36 */ 40 */
37struct HandlerList { 41struct HandlerList
42{
38 /** 43 /**
39 * This is a linked list. 44 * This is a linked list.
40 */ 45 */
@@ -50,7 +55,8 @@ struct HandlerList {
50/** 55/**
51 * List of arrays of message handlers. 56 * List of arrays of message handlers.
52 */ 57 */
53struct NotifyList { 58struct NotifyList
59{
54 /** 60 /**
55 * This is a doubly linked list. 61 * This is a doubly linked list.
56 */ 62 */
@@ -76,7 +82,8 @@ struct NotifyList {
76/** 82/**
77 * @brief handle for a server 83 * @brief handle for a server
78 */ 84 */
79struct GNUNET_SERVER_Handle { 85struct GNUNET_SERVER_Handle
86{
80 /** 87 /**
81 * List of handlers for incoming messages. 88 * List of handlers for incoming messages.
82 */ 89 */
@@ -137,7 +144,7 @@ struct GNUNET_SERVER_Handle {
137 /** 144 /**
138 * Task scheduled to do the listening. 145 * Task scheduled to do the listening.
139 */ 146 */
140 struct GNUNET_SCHEDULER_Task * listen_task; 147 struct GNUNET_SCHEDULER_Task *listen_task;
141 148
142 /** 149 /**
143 * Alternative function to create a MST instance. 150 * Alternative function to create a MST instance.
@@ -179,7 +186,8 @@ struct GNUNET_SERVER_Handle {
179/** 186/**
180 * Handle server returns for aborting transmission to a client. 187 * Handle server returns for aborting transmission to a client.
181 */ 188 */
182struct GNUNET_SERVER_TransmitHandle { 189struct GNUNET_SERVER_TransmitHandle
190{
183 /** 191 /**
184 * Function to call to get the message. 192 * Function to call to get the message.
185 */ 193 */
@@ -200,7 +208,8 @@ struct GNUNET_SERVER_TransmitHandle {
200/** 208/**
201 * @brief handle for a client of the server 209 * @brief handle for a client of the server
202 */ 210 */
203struct GNUNET_SERVER_Client { 211struct GNUNET_SERVER_Client
212{
204 /** 213 /**
205 * This is a doubly linked list. 214 * This is a doubly linked list.
206 */ 215 */
@@ -235,12 +244,12 @@ struct GNUNET_SERVER_Client {
235 /** 244 /**
236 * ID of task used to restart processing. 245 * ID of task used to restart processing.
237 */ 246 */
238 struct GNUNET_SCHEDULER_Task * restart_task; 247 struct GNUNET_SCHEDULER_Task *restart_task;
239 248
240 /** 249 /**
241 * Task that warns about missing calls to #GNUNET_SERVER_receive_done. 250 * Task that warns about missing calls to #GNUNET_SERVER_receive_done.
242 */ 251 */
243 struct GNUNET_SCHEDULER_Task * warn_task; 252 struct GNUNET_SCHEDULER_Task *warn_task;
244 253
245 /** 254 /**
246 * Time when the warn task was started. 255 * Time when the warn task was started.
@@ -338,13 +347,13 @@ struct GNUNET_SERVER_Client {
338 * @return pointer to user context 347 * @return pointer to user context
339 */ 348 */
340void * 349void *
341GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client, 350GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client,
342 size_t size) 351 size_t size)
343{ 352{
344 if ((0 == client->user_context_size) && 353 if ((0 == client->user_context_size) &&
345 (NULL == client->user_context)) 354 (NULL == client->user_context))
346 return NULL; /* never set */ 355 return NULL; /* never set */
347 GNUNET_assert(size == client->user_context_size); 356 GNUNET_assert (size == client->user_context_size);
348 return client->user_context; 357 return client->user_context;
349} 358}
350 359
@@ -358,16 +367,16 @@ GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client,
358 * @param size number of bytes in user context struct (for verification only) 367 * @param size number of bytes in user context struct (for verification only)
359 */ 368 */
360void 369void
361GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, 370GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
362 void *ptr, 371 void *ptr,
363 size_t size) 372 size_t size)
364{ 373{
365 if (NULL == ptr) 374 if (NULL == ptr)
366 { 375 {
367 client->user_context_size = 0; 376 client->user_context_size = 0;
368 client->user_context = ptr; 377 client->user_context = ptr;
369 return; 378 return;
370 } 379 }
371 client->user_context_size = size; 380 client->user_context_size = size;
372 client->user_context = ptr; 381 client->user_context = ptr;
373} 382}
@@ -380,7 +389,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client,
380 * socket 389 * socket
381 */ 390 */
382static void 391static void
383process_listen_socket(void *cls) 392process_listen_socket (void *cls)
384{ 393{
385 struct GNUNET_SERVER_Handle *server = cls; 394 struct GNUNET_SERVER_Handle *server = cls;
386 const struct GNUNET_SCHEDULER_TaskContext *tc; 395 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -388,27 +397,27 @@ process_listen_socket(void *cls)
388 unsigned int i; 397 unsigned int i;
389 398
390 server->listen_task = NULL; 399 server->listen_task = NULL;
391 tc = GNUNET_SCHEDULER_get_task_context(); 400 tc = GNUNET_SCHEDULER_get_task_context ();
392 for (i = 0; NULL != server->listen_sockets[i]; i++) 401 for (i = 0; NULL != server->listen_sockets[i]; i++)
402 {
403 if (GNUNET_NETWORK_fdset_isset (tc->read_ready,
404 server->listen_sockets[i]))
393 { 405 {
394 if (GNUNET_NETWORK_fdset_isset(tc->read_ready, 406 sock =
395 server->listen_sockets[i])) 407 GNUNET_CONNECTION_create_from_accept (server->access_cb,
396 { 408 server->access_cb_cls,
397 sock = 409 server->listen_sockets[i]);
398 GNUNET_CONNECTION_create_from_accept(server->access_cb, 410 if (NULL != sock)
399 server->access_cb_cls, 411 {
400 server->listen_sockets[i]); 412 LOG (GNUNET_ERROR_TYPE_DEBUG,
401 if (NULL != sock) 413 "Server accepted incoming connection.\n");
402 { 414 (void) GNUNET_SERVER_connect_socket (server,
403 LOG(GNUNET_ERROR_TYPE_DEBUG, 415 sock);
404 "Server accepted incoming connection.\n"); 416 }
405 (void)GNUNET_SERVER_connect_socket(server,
406 sock);
407 }
408 }
409 } 417 }
418 }
410 /* listen for more! */ 419 /* listen for more! */
411 GNUNET_SERVER_resume(server); 420 GNUNET_SERVER_resume (server);
412} 421}
413 422
414 423
@@ -420,90 +429,90 @@ process_listen_socket(void *cls)
420 * @return NULL on error, otherwise the listen socket 429 * @return NULL on error, otherwise the listen socket
421 */ 430 */
422static struct GNUNET_NETWORK_Handle * 431static struct GNUNET_NETWORK_Handle *
423open_listen_socket(const struct sockaddr *server_addr, 432open_listen_socket (const struct sockaddr *server_addr,
424 socklen_t socklen) 433 socklen_t socklen)
425{ 434{
426 struct GNUNET_NETWORK_Handle *sock; 435 struct GNUNET_NETWORK_Handle *sock;
427 uint16_t port; 436 uint16_t port;
428 int eno; 437 int eno;
429 438
430 switch (server_addr->sa_family) 439 switch (server_addr->sa_family)
431 { 440 {
432 case AF_INET: 441 case AF_INET:
433 port = ntohs(((const struct sockaddr_in *)server_addr)->sin_port); 442 port = ntohs (((const struct sockaddr_in *) server_addr)->sin_port);
434 break; 443 break;
435 444
436 case AF_INET6: 445 case AF_INET6:
437 port = ntohs(((const struct sockaddr_in6 *)server_addr)->sin6_port); 446 port = ntohs (((const struct sockaddr_in6 *) server_addr)->sin6_port);
438 break; 447 break;
439 448
440 case AF_UNIX: 449 case AF_UNIX:
441 port = 0; 450 port = 0;
442 break; 451 break;
443 452
444 default: 453 default:
445 GNUNET_break(0); 454 GNUNET_break (0);
446 port = 0; 455 port = 0;
447 break; 456 break;
448 } 457 }
449 sock = GNUNET_NETWORK_socket_create(server_addr->sa_family, SOCK_STREAM, 0); 458 sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, SOCK_STREAM, 0);
450 if (NULL == sock) 459 if (NULL == sock)
451 { 460 {
452 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); 461 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
453 errno = 0; 462 errno = 0;
454 return NULL; 463 return NULL;
455 } 464 }
456 /* bind the socket */ 465 /* bind the socket */
457 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(sock, server_addr, socklen)) 466 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, server_addr, socklen))
467 {
468 eno = errno;
469 if (EADDRINUSE != errno)
458 { 470 {
459 eno = errno; 471 /* we don't log 'EADDRINUSE' here since an IPv4 bind may
460 if (EADDRINUSE != errno) 472 * fail if we already took the port on IPv6; if both IPv4 and
461 { 473 * IPv6 binds fail, then our caller will log using the
462 /* we don't log 'EADDRINUSE' here since an IPv4 bind may 474 * errno preserved in 'eno' */
463 * fail if we already took the port on IPv6; if both IPv4 and 475 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
464 * IPv6 binds fail, then our caller will log using the 476 "bind");
465 * errno preserved in 'eno' */ 477 if (0 != port)
466 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, 478 LOG (GNUNET_ERROR_TYPE_ERROR,
467 "bind"); 479 _ ("`%s' failed for port %d (%s).\n"),
468 if (0 != port) 480 "bind",
469 LOG(GNUNET_ERROR_TYPE_ERROR, 481 port,
470 _("`%s' failed for port %d (%s).\n"), 482 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
471 "bind", 483 eno = 0;
472 port,
473 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
474 eno = 0;
475 }
476 else
477 {
478 if (0 != port)
479 LOG(GNUNET_ERROR_TYPE_WARNING,
480 _("`%s' failed for port %d (%s): address already in use\n"),
481 "bind", port,
482 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
483 else if (AF_UNIX == server_addr->sa_family)
484 {
485 LOG(GNUNET_ERROR_TYPE_WARNING,
486 _("`%s' failed for `%s': address already in use\n"),
487 "bind",
488 GNUNET_a2s(server_addr, socklen));
489 }
490 }
491 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock));
492 errno = eno;
493 return NULL;
494 } 484 }
495 if (GNUNET_OK != GNUNET_NETWORK_socket_listen(sock, 5)) 485 else
496 { 486 {
497 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, 487 if (0 != port)
498 "listen"); 488 LOG (GNUNET_ERROR_TYPE_WARNING,
499 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock)); 489 _ ("`%s' failed for port %d (%s): address already in use\n"),
500 errno = 0; 490 "bind", port,
501 return NULL; 491 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
492 else if (AF_UNIX == server_addr->sa_family)
493 {
494 LOG (GNUNET_ERROR_TYPE_WARNING,
495 _ ("`%s' failed for `%s': address already in use\n"),
496 "bind",
497 GNUNET_a2s (server_addr, socklen));
498 }
502 } 499 }
500 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
501 errno = eno;
502 return NULL;
503 }
504 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
505 {
506 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
507 "listen");
508 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
509 errno = 0;
510 return NULL;
511 }
503 if (0 != port) 512 if (0 != port)
504 LOG(GNUNET_ERROR_TYPE_DEBUG, 513 LOG (GNUNET_ERROR_TYPE_DEBUG,
505 "Server starts to listen on port %u.\n", 514 "Server starts to listen on port %u.\n",
506 port); 515 port);
507 return sock; 516 return sock;
508} 517}
509 518
@@ -521,22 +530,22 @@ open_listen_socket(const struct sockaddr *server_addr,
521 * (typically, "port" already in use) 530 * (typically, "port" already in use)
522 */ 531 */
523struct GNUNET_SERVER_Handle * 532struct GNUNET_SERVER_Handle *
524GNUNET_SERVER_create_with_sockets(GNUNET_CONNECTION_AccessCheck access_cb, 533GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access_cb,
525 void *access_cb_cls, 534 void *access_cb_cls,
526 struct GNUNET_NETWORK_Handle **lsocks, 535 struct GNUNET_NETWORK_Handle **lsocks,
527 struct GNUNET_TIME_Relative idle_timeout, 536 struct GNUNET_TIME_Relative idle_timeout,
528 int require_found) 537 int require_found)
529{ 538{
530 struct GNUNET_SERVER_Handle *server; 539 struct GNUNET_SERVER_Handle *server;
531 540
532 server = GNUNET_new(struct GNUNET_SERVER_Handle); 541 server = GNUNET_new (struct GNUNET_SERVER_Handle);
533 server->idle_timeout = idle_timeout; 542 server->idle_timeout = idle_timeout;
534 server->listen_sockets = lsocks; 543 server->listen_sockets = lsocks;
535 server->access_cb = access_cb; 544 server->access_cb = access_cb;
536 server->access_cb_cls = access_cb_cls; 545 server->access_cb_cls = access_cb_cls;
537 server->require_found = require_found; 546 server->require_found = require_found;
538 if (NULL != lsocks) 547 if (NULL != lsocks)
539 GNUNET_SERVER_resume(server); 548 GNUNET_SERVER_resume (server);
540 return server; 549 return server;
541} 550}
542 551
@@ -555,12 +564,12 @@ GNUNET_SERVER_create_with_sockets(GNUNET_CONNECTION_AccessCheck access_cb,
555 * (typically, "port" already in use) 564 * (typically, "port" already in use)
556 */ 565 */
557struct GNUNET_SERVER_Handle * 566struct GNUNET_SERVER_Handle *
558GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb, 567GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access_cb,
559 void *access_cb_cls, 568 void *access_cb_cls,
560 struct sockaddr *const *server_addr, 569 struct sockaddr *const *server_addr,
561 const socklen_t * socklen, 570 const socklen_t *socklen,
562 struct GNUNET_TIME_Relative idle_timeout, 571 struct GNUNET_TIME_Relative idle_timeout,
563 int require_found) 572 int require_found)
564{ 573{
565 struct GNUNET_NETWORK_Handle **lsocks; 574 struct GNUNET_NETWORK_Handle **lsocks;
566 unsigned int i; 575 unsigned int i;
@@ -572,48 +581,48 @@ GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb,
572 while (NULL != server_addr[i]) 581 while (NULL != server_addr[i])
573 i++; 582 i++;
574 if (i > 0) 583 if (i > 0)
584 {
585 lsocks = GNUNET_malloc (sizeof(struct GNUNET_NETWORK_Handle *) * (i + 1));
586 i = 0;
587 j = 0;
588 while (NULL != server_addr[i])
575 { 589 {
576 lsocks = GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (i + 1)); 590 seen = 0;
577 i = 0; 591 for (k = 0; k < i; k++)
578 j = 0; 592 if ((socklen[k] == socklen[i]) &&
579 while (NULL != server_addr[i]) 593 (0 == memcmp (server_addr[k], server_addr[i], socklen[i])))
580 { 594 {
581 seen = 0; 595 seen = 1;
582 for (k = 0; k < i; k++) 596 break;
583 if ((socklen[k] == socklen[i]) &&
584 (0 == memcmp(server_addr[k], server_addr[i], socklen[i])))
585 {
586 seen = 1;
587 break;
588 }
589 if (0 != seen)
590 {
591 /* duplicate address, skip */
592 i++;
593 continue;
594 }
595 lsocks[j] = open_listen_socket(server_addr[i], socklen[i]);
596 if (NULL != lsocks[j])
597 j++;
598 i++;
599 }
600 if (0 == j)
601 {
602 if (0 != errno)
603 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "bind");
604 GNUNET_free(lsocks);
605 lsocks = NULL;
606 } 597 }
598 if (0 != seen)
599 {
600 /* duplicate address, skip */
601 i++;
602 continue;
603 }
604 lsocks[j] = open_listen_socket (server_addr[i], socklen[i]);
605 if (NULL != lsocks[j])
606 j++;
607 i++;
607 } 608 }
608 else 609 if (0 == j)
609 { 610 {
611 if (0 != errno)
612 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
613 GNUNET_free (lsocks);
610 lsocks = NULL; 614 lsocks = NULL;
611 } 615 }
612 return GNUNET_SERVER_create_with_sockets(access_cb, 616 }
613 access_cb_cls, 617 else
614 lsocks, 618 {
615 idle_timeout, 619 lsocks = NULL;
616 require_found); 620 }
621 return GNUNET_SERVER_create_with_sockets (access_cb,
622 access_cb_cls,
623 lsocks,
624 idle_timeout,
625 require_found);
617} 626}
618 627
619 628
@@ -630,10 +639,10 @@ GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb,
630 * @param client the client to set the 'monitor' flag on 639 * @param client the client to set the 'monitor' flag on
631 */ 640 */
632void 641void
633GNUNET_SERVER_client_mark_monitor(struct GNUNET_SERVER_Client *client) 642GNUNET_SERVER_client_mark_monitor (struct GNUNET_SERVER_Client *client)
634{ 643{
635 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
636 "Marking client as monitor!\n"); 645 "Marking client as monitor!\n");
637 client->is_monitor = GNUNET_YES; 646 client->is_monitor = GNUNET_YES;
638} 647}
639 648
@@ -645,11 +654,11 @@ GNUNET_SERVER_client_mark_monitor(struct GNUNET_SERVER_Client *client)
645 * @param cls the `struct GNUNET_SERVER_Handle *` to destroy 654 * @param cls the `struct GNUNET_SERVER_Handle *` to destroy
646 */ 655 */
647static void 656static void
648do_destroy(void *cls) 657do_destroy (void *cls)
649{ 658{
650 struct GNUNET_SERVER_Handle *server = cls; 659 struct GNUNET_SERVER_Handle *server = cls;
651 660
652 GNUNET_SERVER_destroy(server); 661 GNUNET_SERVER_destroy (server);
653} 662}
654 663
655 664
@@ -660,7 +669,7 @@ do_destroy(void *cls)
660 * @param server server to test for full shutdown 669 * @param server server to test for full shutdown
661 */ 670 */
662static void 671static void
663test_monitor_clients(struct GNUNET_SERVER_Handle *server) 672test_monitor_clients (struct GNUNET_SERVER_Handle *server)
664{ 673{
665 struct GNUNET_SERVER_Client *client; 674 struct GNUNET_SERVER_Client *client;
666 675
@@ -671,7 +680,7 @@ test_monitor_clients(struct GNUNET_SERVER_Handle *server)
671 return; 680 return;
672 /* not done yet */ 681 /* not done yet */
673 server->in_soft_shutdown = GNUNET_SYSERR; 682 server->in_soft_shutdown = GNUNET_SYSERR;
674 (void)GNUNET_SCHEDULER_add_now(&do_destroy, server); 683 (void) GNUNET_SCHEDULER_add_now (&do_destroy, server);
675} 684}
676 685
677 686
@@ -681,13 +690,13 @@ test_monitor_clients(struct GNUNET_SERVER_Handle *server)
681 * @param server server to stop accepting connections. 690 * @param server server to stop accepting connections.
682 */ 691 */
683void 692void
684GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server) 693GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server)
685{ 694{
686 if (NULL != server->listen_task) 695 if (NULL != server->listen_task)
687 { 696 {
688 GNUNET_SCHEDULER_cancel(server->listen_task); 697 GNUNET_SCHEDULER_cancel (server->listen_task);
689 server->listen_task = NULL; 698 server->listen_task = NULL;
690 } 699 }
691} 700}
692 701
693 702
@@ -697,7 +706,7 @@ GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server)
697 * @param server server to stop accepting connections. 706 * @param server server to stop accepting connections.
698 */ 707 */
699void 708void
700GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server) 709GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server)
701{ 710{
702 struct GNUNET_NETWORK_FDSet *r; 711 struct GNUNET_NETWORK_FDSet *r;
703 unsigned int i; 712 unsigned int i;
@@ -707,25 +716,26 @@ GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server)
707 if (NULL == server->listen_sockets[0]) 716 if (NULL == server->listen_sockets[0])
708 return; /* nothing to do, no listen sockets! */ 717 return; /* nothing to do, no listen sockets! */
709 if (NULL == server->listen_sockets[1]) 718 if (NULL == server->listen_sockets[1])
710 { 719 {
711 /* simplified method: no fd set needed; this is then much simpler 720 /* simplified method: no fd set needed; this is then much simpler
712 and much more efficient */ 721 and much more efficient */
713 server->listen_task = 722 server->listen_task =
714 GNUNET_SCHEDULER_add_read_net_with_priority(GNUNET_TIME_UNIT_FOREVER_REL, 723 GNUNET_SCHEDULER_add_read_net_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
715 GNUNET_SCHEDULER_PRIORITY_HIGH, 724 GNUNET_SCHEDULER_PRIORITY_HIGH,
716 server->listen_sockets[0], 725 server->listen_sockets[0],
717 &process_listen_socket, server); 726 &process_listen_socket,
718 return; 727 server);
719 } 728 return;
720 r = GNUNET_NETWORK_fdset_create(); 729 }
730 r = GNUNET_NETWORK_fdset_create ();
721 i = 0; 731 i = 0;
722 while (NULL != server->listen_sockets[i]) 732 while (NULL != server->listen_sockets[i])
723 GNUNET_NETWORK_fdset_set(r, server->listen_sockets[i++]); 733 GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]);
724 server->listen_task = 734 server->listen_task =
725 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH, 735 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
726 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, 736 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
727 &process_listen_socket, server); 737 &process_listen_socket, server);
728 GNUNET_NETWORK_fdset_destroy(r); 738 GNUNET_NETWORK_fdset_destroy (r);
729} 739}
730 740
731 741
@@ -736,29 +746,29 @@ GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server)
736 * @param server server to stop listening on 746 * @param server server to stop listening on
737 */ 747 */
738void 748void
739GNUNET_SERVER_stop_listening(struct GNUNET_SERVER_Handle *server) 749GNUNET_SERVER_stop_listening (struct GNUNET_SERVER_Handle *server)
740{ 750{
741 unsigned int i; 751 unsigned int i;
742 752
743 LOG(GNUNET_ERROR_TYPE_DEBUG, 753 LOG (GNUNET_ERROR_TYPE_DEBUG,
744 "Server in soft shutdown\n"); 754 "Server in soft shutdown\n");
745 if (NULL != server->listen_task) 755 if (NULL != server->listen_task)
746 { 756 {
747 GNUNET_SCHEDULER_cancel(server->listen_task); 757 GNUNET_SCHEDULER_cancel (server->listen_task);
748 server->listen_task = NULL; 758 server->listen_task = NULL;
749 } 759 }
750 if (NULL != server->listen_sockets) 760 if (NULL != server->listen_sockets)
751 { 761 {
752 i = 0; 762 i = 0;
753 while (NULL != server->listen_sockets[i]) 763 while (NULL != server->listen_sockets[i])
754 GNUNET_break(GNUNET_OK == 764 GNUNET_break (GNUNET_OK ==
755 GNUNET_NETWORK_socket_close(server->listen_sockets[i++])); 765 GNUNET_NETWORK_socket_close (server->listen_sockets[i++]));
756 GNUNET_free(server->listen_sockets); 766 GNUNET_free (server->listen_sockets);
757 server->listen_sockets = NULL; 767 server->listen_sockets = NULL;
758 } 768 }
759 if (GNUNET_NO == server->in_soft_shutdown) 769 if (GNUNET_NO == server->in_soft_shutdown)
760 server->in_soft_shutdown = GNUNET_YES; 770 server->in_soft_shutdown = GNUNET_YES;
761 test_monitor_clients(server); 771 test_monitor_clients (server);
762} 772}
763 773
764 774
@@ -768,54 +778,54 @@ GNUNET_SERVER_stop_listening(struct GNUNET_SERVER_Handle *server)
768 * @param server server to destroy 778 * @param server server to destroy
769 */ 779 */
770void 780void
771GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server) 781GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server)
772{ 782{
773 struct HandlerList *hpos; 783 struct HandlerList *hpos;
774 struct NotifyList *npos; 784 struct NotifyList *npos;
775 unsigned int i; 785 unsigned int i;
776 786
777 LOG(GNUNET_ERROR_TYPE_DEBUG, 787 LOG (GNUNET_ERROR_TYPE_DEBUG,
778 "Server shutting down.\n"); 788 "Server shutting down.\n");
779 if (NULL != server->listen_task) 789 if (NULL != server->listen_task)
780 { 790 {
781 GNUNET_SCHEDULER_cancel(server->listen_task); 791 GNUNET_SCHEDULER_cancel (server->listen_task);
782 server->listen_task = NULL; 792 server->listen_task = NULL;
783 } 793 }
784 if (NULL != server->listen_sockets) 794 if (NULL != server->listen_sockets)
785 { 795 {
786 i = 0; 796 i = 0;
787 while (NULL != server->listen_sockets[i]) 797 while (NULL != server->listen_sockets[i])
788 GNUNET_break(GNUNET_OK == 798 GNUNET_break (GNUNET_OK ==
789 GNUNET_NETWORK_socket_close(server->listen_sockets[i++])); 799 GNUNET_NETWORK_socket_close (server->listen_sockets[i++]));
790 GNUNET_free(server->listen_sockets); 800 GNUNET_free (server->listen_sockets);
791 server->listen_sockets = NULL; 801 server->listen_sockets = NULL;
792 } 802 }
793 while (NULL != server->clients_head) 803 while (NULL != server->clients_head)
794 GNUNET_SERVER_client_disconnect(server->clients_head); 804 GNUNET_SERVER_client_disconnect (server->clients_head);
795 while (NULL != (hpos = server->handlers)) 805 while (NULL != (hpos = server->handlers))
796 { 806 {
797 server->handlers = hpos->next; 807 server->handlers = hpos->next;
798 GNUNET_free(hpos); 808 GNUNET_free (hpos);
799 } 809 }
800 while (NULL != (npos = server->disconnect_notify_list_head)) 810 while (NULL != (npos = server->disconnect_notify_list_head))
801 { 811 {
802 npos->callback(npos->callback_cls, 812 npos->callback (npos->callback_cls,
803 NULL); 813 NULL);
804 GNUNET_CONTAINER_DLL_remove(server->disconnect_notify_list_head, 814 GNUNET_CONTAINER_DLL_remove (server->disconnect_notify_list_head,
805 server->disconnect_notify_list_tail, 815 server->disconnect_notify_list_tail,
806 npos); 816 npos);
807 GNUNET_free(npos); 817 GNUNET_free (npos);
808 } 818 }
809 while (NULL != (npos = server->connect_notify_list_head)) 819 while (NULL != (npos = server->connect_notify_list_head))
810 { 820 {
811 npos->callback(npos->callback_cls, 821 npos->callback (npos->callback_cls,
812 NULL); 822 NULL);
813 GNUNET_CONTAINER_DLL_remove(server->connect_notify_list_head, 823 GNUNET_CONTAINER_DLL_remove (server->connect_notify_list_head,
814 server->connect_notify_list_tail, 824 server->connect_notify_list_tail,
815 npos); 825 npos);
816 GNUNET_free(npos); 826 GNUNET_free (npos);
817 } 827 }
818 GNUNET_free(server); 828 GNUNET_free (server);
819} 829}
820 830
821 831
@@ -833,12 +843,12 @@ GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server)
833 * (or server is destroyed). 843 * (or server is destroyed).
834 */ 844 */
835void 845void
836GNUNET_SERVER_add_handlers(struct GNUNET_SERVER_Handle *server, 846GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server,
837 const struct GNUNET_SERVER_MessageHandler *handlers) 847 const struct GNUNET_SERVER_MessageHandler *handlers)
838{ 848{
839 struct HandlerList *p; 849 struct HandlerList *p;
840 850
841 p = GNUNET_new(struct HandlerList); 851 p = GNUNET_new (struct HandlerList);
842 p->handlers = handlers; 852 p->handlers = handlers;
843 p->next = server->handlers; 853 p->next = server->handlers;
844 server->handlers = p; 854 server->handlers = p;
@@ -856,11 +866,11 @@ GNUNET_SERVER_add_handlers(struct GNUNET_SERVER_Handle *server,
856 * @param cls closure for @a create, @a receive, @a destroy 866 * @param cls closure for @a create, @a receive, @a destroy
857 */ 867 */
858void 868void
859GNUNET_SERVER_set_callbacks(struct GNUNET_SERVER_Handle *server, 869GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
860 GNUNET_SERVER_MstCreateCallback create, 870 GNUNET_SERVER_MstCreateCallback create,
861 GNUNET_SERVER_MstDestroyCallback destroy, 871 GNUNET_SERVER_MstDestroyCallback destroy,
862 GNUNET_SERVER_MstReceiveCallback receive, 872 GNUNET_SERVER_MstReceiveCallback receive,
863 void *cls) 873 void *cls)
864{ 874{
865 server->mst_create = create; 875 server->mst_create = create;
866 server->mst_destroy = destroy; 876 server->mst_destroy = destroy;
@@ -875,19 +885,21 @@ GNUNET_SERVER_set_callbacks(struct GNUNET_SERVER_Handle *server,
875 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from 885 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from
876 */ 886 */
877static void 887static void
878warn_no_receive_done(void *cls) 888warn_no_receive_done (void *cls)
879{ 889{
880 struct GNUNET_SERVER_Client *client = cls; 890 struct GNUNET_SERVER_Client *client = cls;
881 891
882 GNUNET_break(0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */ 892 GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */
883 client->warn_task = 893 client->warn_task =
884 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, 894 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
885 &warn_no_receive_done, client); 895 &warn_no_receive_done, client);
886 LOG(GNUNET_ERROR_TYPE_WARNING, 896 LOG (GNUNET_ERROR_TYPE_WARNING,
887 _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"), 897 _ (
888 (unsigned int)client->warn_type, 898 "Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"),
889 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(client->warn_start), 899 (unsigned int) client->warn_type,
890 GNUNET_YES)); 900 GNUNET_STRINGS_relative_time_to_string (
901 GNUNET_TIME_absolute_get_duration (client->warn_start),
902 GNUNET_YES));
891} 903}
892 904
893 905
@@ -899,13 +911,13 @@ warn_no_receive_done(void *cls)
899 * @param client client for which to disable the warning 911 * @param client client for which to disable the warning
900 */ 912 */
901void 913void
902GNUNET_SERVER_disable_receive_done_warning(struct GNUNET_SERVER_Client *client) 914GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client)
903{ 915{
904 if (NULL != client->warn_task) 916 if (NULL != client->warn_task)
905 { 917 {
906 GNUNET_SCHEDULER_cancel(client->warn_task); 918 GNUNET_SCHEDULER_cancel (client->warn_task);
907 client->warn_task = NULL; 919 client->warn_task = NULL;
908 } 920 }
909} 921}
910 922
911 923
@@ -925,9 +937,9 @@ GNUNET_SERVER_disable_receive_done_warning(struct GNUNET_SERVER_Client *client)
925 * client should be shut down 937 * client should be shut down
926 */ 938 */
927int 939int
928GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server, 940GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
929 struct GNUNET_SERVER_Client *sender, 941 struct GNUNET_SERVER_Client *sender,
930 const struct GNUNET_MessageHeader *message) 942 const struct GNUNET_MessageHeader *message)
931{ 943{
932 struct HandlerList *pos; 944 struct HandlerList *pos;
933 const struct GNUNET_SERVER_MessageHandler *mh; 945 const struct GNUNET_SERVER_MessageHandler *mh;
@@ -936,62 +948,62 @@ GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server,
936 uint16_t size; 948 uint16_t size;
937 int found; 949 int found;
938 950
939 type = ntohs(message->type); 951 type = ntohs (message->type);
940 size = ntohs(message->size); 952 size = ntohs (message->size);
941 LOG(GNUNET_ERROR_TYPE_INFO, 953 LOG (GNUNET_ERROR_TYPE_INFO,
942 "Received message of type %u and size %u from client\n", 954 "Received message of type %u and size %u from client\n",
943 type, size); 955 type, size);
944 found = GNUNET_NO; 956 found = GNUNET_NO;
945 for (pos = server->handlers; NULL != pos; pos = pos->next) 957 for (pos = server->handlers; NULL != pos; pos = pos->next)
958 {
959 i = 0;
960 while (pos->handlers[i].callback != NULL)
946 { 961 {
947 i = 0; 962 mh = &pos->handlers[i];
948 while (pos->handlers[i].callback != NULL) 963 if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL))
964 {
965 if ((0 != mh->expected_size) && (mh->expected_size != size))
949 { 966 {
950 mh = &pos->handlers[i];
951 if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL))
952 {
953 if ((0 != mh->expected_size) && (mh->expected_size != size))
954 {
955#if GNUNET8_NETWORK_IS_DEAD 967#if GNUNET8_NETWORK_IS_DEAD
956 LOG(GNUNET_ERROR_TYPE_WARNING, 968 LOG (GNUNET_ERROR_TYPE_WARNING,
957 "Expected %u bytes for message of type %u, got %u\n", 969 "Expected %u bytes for message of type %u, got %u\n",
958 mh->expected_size, mh->type, size); 970 mh->expected_size, mh->type, size);
959 GNUNET_break_op(0); 971 GNUNET_break_op (0);
960#else 972#else
961 LOG(GNUNET_ERROR_TYPE_DEBUG, 973 LOG (GNUNET_ERROR_TYPE_DEBUG,
962 "Expected %u bytes for message of type %u, got %u\n", 974 "Expected %u bytes for message of type %u, got %u\n",
963 mh->expected_size, mh->type, size); 975 mh->expected_size, mh->type, size);
964#endif 976#endif
965 return GNUNET_SYSERR; 977 return GNUNET_SYSERR;
966 }
967 if (NULL != sender)
968 {
969 if ((0 == sender->suspended) &&
970 (NULL == sender->warn_task))
971 {
972 GNUNET_break(0 != type); /* type should never be 0 here, as we don't use 0 */
973 sender->warn_start = GNUNET_TIME_absolute_get();
974 sender->warn_task =
975 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES,
976 &warn_no_receive_done,
977 sender);
978 sender->warn_type = type;
979 }
980 sender->suspended++;
981 }
982 mh->callback(mh->callback_cls, sender, message);
983 found = GNUNET_YES;
984 }
985 i++;
986 } 978 }
979 if (NULL != sender)
980 {
981 if ((0 == sender->suspended) &&
982 (NULL == sender->warn_task))
983 {
984 GNUNET_break (0 != type); /* type should never be 0 here, as we don't use 0 */
985 sender->warn_start = GNUNET_TIME_absolute_get ();
986 sender->warn_task =
987 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
988 &warn_no_receive_done,
989 sender);
990 sender->warn_type = type;
991 }
992 sender->suspended++;
993 }
994 mh->callback (mh->callback_cls, sender, message);
995 found = GNUNET_YES;
996 }
997 i++;
987 } 998 }
999 }
988 if (GNUNET_NO == found) 1000 if (GNUNET_NO == found)
989 { 1001 {
990 LOG(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 1002 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
991 "Received message of unknown type %d\n", type); 1003 "Received message of unknown type %d\n", type);
992 if (GNUNET_YES == server->require_found) 1004 if (GNUNET_YES == server->require_found)
993 return GNUNET_SYSERR; 1005 return GNUNET_SYSERR;
994 } 1006 }
995 return GNUNET_OK; 1007 return GNUNET_OK;
996} 1008}
997 1009
@@ -1007,12 +1019,12 @@ GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server,
1007 * @param errCode code indicating errors receiving, 0 for success 1019 * @param errCode code indicating errors receiving, 0 for success
1008 */ 1020 */
1009static void 1021static void
1010process_incoming(void *cls, 1022process_incoming (void *cls,
1011 const void *buf, 1023 const void *buf,
1012 size_t available, 1024 size_t available,
1013 const struct sockaddr *addr, 1025 const struct sockaddr *addr,
1014 socklen_t addrlen, 1026 socklen_t addrlen,
1015 int errCode); 1027 int errCode);
1016 1028
1017 1029
1018/** 1030/**
@@ -1029,52 +1041,53 @@ process_incoming(void *cls,
1029 * #GNUNET_SYSERR if we should instantly abort due to error in a previous step 1041 * #GNUNET_SYSERR if we should instantly abort due to error in a previous step
1030 */ 1042 */
1031static void 1043static void
1032process_mst(struct GNUNET_SERVER_Client *client, 1044process_mst (struct GNUNET_SERVER_Client *client,
1033 int ret) 1045 int ret)
1034{ 1046{
1035 while ((GNUNET_SYSERR != ret) && (NULL != client->server) && 1047 while ((GNUNET_SYSERR != ret) && (NULL != client->server) &&
1036 (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) 1048 (GNUNET_YES != client->shutdown_now) && (0 == client->suspended))
1049 {
1050 if (GNUNET_OK == ret)
1037 { 1051 {
1038 if (GNUNET_OK == ret) 1052 LOG (GNUNET_ERROR_TYPE_DEBUG,
1039 { 1053 "Server re-enters receive loop, timeout: %s.\n",
1040 LOG(GNUNET_ERROR_TYPE_DEBUG, 1054 GNUNET_STRINGS_relative_time_to_string (client->idle_timeout,
1041 "Server re-enters receive loop, timeout: %s.\n", 1055 GNUNET_YES));
1042 GNUNET_STRINGS_relative_time_to_string(client->idle_timeout, GNUNET_YES)); 1056 client->receive_pending = GNUNET_YES;
1043 client->receive_pending = GNUNET_YES; 1057 if (GNUNET_OK !=
1044 if (GNUNET_OK != 1058 GNUNET_CONNECTION_receive (client->connection,
1045 GNUNET_CONNECTION_receive(client->connection, 1059 GNUNET_MAX_MESSAGE_SIZE - 1,
1046 GNUNET_MAX_MESSAGE_SIZE - 1, 1060 client->idle_timeout,
1047 client->idle_timeout, 1061 &process_incoming,
1048 &process_incoming, 1062 client))
1049 client)) 1063 return;
1050 return; 1064 break;
1051 break;
1052 }
1053 LOG(GNUNET_ERROR_TYPE_DEBUG,
1054 "Server processes additional messages instantly.\n");
1055 if (NULL != client->server->mst_receive)
1056 ret =
1057 client->server->mst_receive(client->server->mst_cls, client->mst,
1058 client, NULL, 0, GNUNET_NO, GNUNET_YES);
1059 else
1060 ret =
1061 GNUNET_SERVER_mst_receive(client->mst, client, NULL, 0, GNUNET_NO,
1062 GNUNET_YES);
1063 } 1065 }
1064 LOG(GNUNET_ERROR_TYPE_DEBUG, 1066 LOG (GNUNET_ERROR_TYPE_DEBUG,
1065 "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n", 1067 "Server processes additional messages instantly.\n");
1066 ret, client->server, 1068 if (NULL != client->server->mst_receive)
1067 client->shutdown_now, 1069 ret =
1068 client->suspended); 1070 client->server->mst_receive (client->server->mst_cls, client->mst,
1071 client, NULL, 0, GNUNET_NO, GNUNET_YES);
1072 else
1073 ret =
1074 GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
1075 GNUNET_YES);
1076 }
1077 LOG (GNUNET_ERROR_TYPE_DEBUG,
1078 "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n",
1079 ret, client->server,
1080 client->shutdown_now,
1081 client->suspended);
1069 if (GNUNET_NO == ret) 1082 if (GNUNET_NO == ret)
1070 { 1083 {
1071 LOG(GNUNET_ERROR_TYPE_DEBUG, 1084 LOG (GNUNET_ERROR_TYPE_DEBUG,
1072 "Server has more data pending but is suspended.\n"); 1085 "Server has more data pending but is suspended.\n");
1073 client->receive_pending = GNUNET_SYSERR; /* data pending */ 1086 client->receive_pending = GNUNET_SYSERR; /* data pending */
1074 } 1087 }
1075 if ((GNUNET_SYSERR == ret) || 1088 if ((GNUNET_SYSERR == ret) ||
1076 (GNUNET_YES == client->shutdown_now)) 1089 (GNUNET_YES == client->shutdown_now))
1077 GNUNET_SERVER_client_disconnect(client); 1090 GNUNET_SERVER_client_disconnect (client);
1078} 1091}
1079 1092
1080 1093
@@ -1089,12 +1102,12 @@ process_mst(struct GNUNET_SERVER_Client *client,
1089 * @param errCode code indicating errors receiving, 0 for success 1102 * @param errCode code indicating errors receiving, 0 for success
1090 */ 1103 */
1091static void 1104static void
1092process_incoming(void *cls, 1105process_incoming (void *cls,
1093 const void *buf, 1106 const void *buf,
1094 size_t available, 1107 size_t available,
1095 const struct sockaddr *addr, 1108 const struct sockaddr *addr,
1096 socklen_t addrlen, 1109 socklen_t addrlen,
1097 int errCode) 1110 int errCode)
1098{ 1111{
1099 struct GNUNET_SERVER_Client *client = cls; 1112 struct GNUNET_SERVER_Client *client = cls;
1100 struct GNUNET_SERVER_Handle *server = client->server; 1113 struct GNUNET_SERVER_Handle *server = client->server;
@@ -1102,11 +1115,11 @@ process_incoming(void *cls,
1102 struct GNUNET_TIME_Absolute now; 1115 struct GNUNET_TIME_Absolute now;
1103 int ret; 1116 int ret;
1104 1117
1105 GNUNET_assert(GNUNET_YES == client->receive_pending); 1118 GNUNET_assert (GNUNET_YES == client->receive_pending);
1106 client->receive_pending = GNUNET_NO; 1119 client->receive_pending = GNUNET_NO;
1107 now = GNUNET_TIME_absolute_get(); 1120 now = GNUNET_TIME_absolute_get ();
1108 end = GNUNET_TIME_absolute_add(client->last_activity, 1121 end = GNUNET_TIME_absolute_add (client->last_activity,
1109 client->idle_timeout); 1122 client->idle_timeout);
1110 1123
1111 if ((NULL == buf) && 1124 if ((NULL == buf) &&
1112 (0 == available) && 1125 (0 == available) &&
@@ -1114,70 +1127,70 @@ process_incoming(void *cls,
1114 (0 == errCode) && 1127 (0 == errCode) &&
1115 (GNUNET_YES != client->shutdown_now) && 1128 (GNUNET_YES != client->shutdown_now) &&
1116 (NULL != server) && 1129 (NULL != server) &&
1117 (GNUNET_YES == GNUNET_CONNECTION_check(client->connection)) && 1130 (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) &&
1118 (end.abs_value_us > now.abs_value_us)) 1131 (end.abs_value_us > now.abs_value_us))
1119 { 1132 {
1120 /* wait longer, timeout changed (i.e. due to us sending) */ 1133 /* wait longer, timeout changed (i.e. due to us sending) */
1121 LOG(GNUNET_ERROR_TYPE_DEBUG, 1134 LOG (GNUNET_ERROR_TYPE_DEBUG,
1122 "Receive time out, but no disconnect due to sending (%p)\n", 1135 "Receive time out, but no disconnect due to sending (%p)\n",
1123 client); 1136 client);
1124 client->receive_pending = GNUNET_YES; 1137 client->receive_pending = GNUNET_YES;
1125 GNUNET_CONNECTION_receive(client->connection, 1138 GNUNET_CONNECTION_receive (client->connection,
1126 GNUNET_MAX_MESSAGE_SIZE - 1, 1139 GNUNET_MAX_MESSAGE_SIZE - 1,
1127 GNUNET_TIME_absolute_get_remaining(end), 1140 GNUNET_TIME_absolute_get_remaining (end),
1128 &process_incoming, 1141 &process_incoming,
1129 client); 1142 client);
1130 return; 1143 return;
1131 } 1144 }
1132 if ((NULL == buf) || 1145 if ((NULL == buf) ||
1133 (0 == available) || 1146 (0 == available) ||
1134 (0 != errCode) || 1147 (0 != errCode) ||
1135 (NULL == server) || 1148 (NULL == server) ||
1136 (GNUNET_YES == client->shutdown_now) || 1149 (GNUNET_YES == client->shutdown_now) ||
1137 (GNUNET_YES != GNUNET_CONNECTION_check(client->connection))) 1150 (GNUNET_YES != GNUNET_CONNECTION_check (client->connection)))
1138 { 1151 {
1139 /* other side closed connection, error connecting, etc. */ 1152 /* other side closed connection, error connecting, etc. */
1140 LOG(GNUNET_ERROR_TYPE_DEBUG, 1153 LOG (GNUNET_ERROR_TYPE_DEBUG,
1141 "Failed to connect or other side closed connection (%p)\n", 1154 "Failed to connect or other side closed connection (%p)\n",
1142 client); 1155 client);
1143 GNUNET_SERVER_client_disconnect(client); 1156 GNUNET_SERVER_client_disconnect (client);
1144 return; 1157 return;
1145 } 1158 }
1146 LOG(GNUNET_ERROR_TYPE_DEBUG, 1159 LOG (GNUNET_ERROR_TYPE_DEBUG,
1147 "Server receives %u bytes from `%s'.\n", 1160 "Server receives %u bytes from `%s'.\n",
1148 (unsigned int)available, 1161 (unsigned int) available,
1149 GNUNET_a2s(addr, addrlen)); 1162 GNUNET_a2s (addr, addrlen));
1150 GNUNET_SERVER_client_keep(client); 1163 GNUNET_SERVER_client_keep (client);
1151 client->last_activity = now; 1164 client->last_activity = now;
1152 1165
1153 if (NULL != server->mst_receive) 1166 if (NULL != server->mst_receive)
1154 { 1167 {
1155 ret = client->server->mst_receive(client->server->mst_cls, 1168 ret = client->server->mst_receive (client->server->mst_cls,
1156 client->mst, 1169 client->mst,
1157 client, 1170 client,
1158 buf, 1171 buf,
1159 available, 1172 available,
1160 GNUNET_NO, 1173 GNUNET_NO,
1161 GNUNET_YES); 1174 GNUNET_YES);
1162 } 1175 }
1163 else if (NULL != client->mst) 1176 else if (NULL != client->mst)
1164 { 1177 {
1165 ret = 1178 ret =
1166 GNUNET_SERVER_mst_receive(client->mst, 1179 GNUNET_SERVER_mst_receive (client->mst,
1167 client, 1180 client,
1168 buf, 1181 buf,
1169 available, 1182 available,
1170 GNUNET_NO, 1183 GNUNET_NO,
1171 GNUNET_YES); 1184 GNUNET_YES);
1172 } 1185 }
1173 else 1186 else
1174 { 1187 {
1175 GNUNET_break(0); 1188 GNUNET_break (0);
1176 return; 1189 return;
1177 } 1190 }
1178 process_mst(client, 1191 process_mst (client,
1179 ret); 1192 ret);
1180 GNUNET_SERVER_client_drop(client); 1193 GNUNET_SERVER_client_drop (client);
1181} 1194}
1182 1195
1183 1196
@@ -1188,30 +1201,30 @@ process_incoming(void *cls,
1188 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from 1201 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from
1189 */ 1202 */
1190static void 1203static void
1191restart_processing(void *cls) 1204restart_processing (void *cls)
1192{ 1205{
1193 struct GNUNET_SERVER_Client *client = cls; 1206 struct GNUNET_SERVER_Client *client = cls;
1194 1207
1195 GNUNET_assert(GNUNET_YES != client->shutdown_now); 1208 GNUNET_assert (GNUNET_YES != client->shutdown_now);
1196 client->restart_task = NULL; 1209 client->restart_task = NULL;
1197 if (GNUNET_NO == client->receive_pending) 1210 if (GNUNET_NO == client->receive_pending)
1198 { 1211 {
1199 LOG(GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n"); 1212 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n");
1200 client->receive_pending = GNUNET_YES; 1213 client->receive_pending = GNUNET_YES;
1201 GNUNET_CONNECTION_receive(client->connection, 1214 GNUNET_CONNECTION_receive (client->connection,
1202 GNUNET_MAX_MESSAGE_SIZE - 1, 1215 GNUNET_MAX_MESSAGE_SIZE - 1,
1203 client->idle_timeout, 1216 client->idle_timeout,
1204 &process_incoming, 1217 &process_incoming,
1205 client); 1218 client);
1206 return; 1219 return;
1207 } 1220 }
1208 LOG(GNUNET_ERROR_TYPE_DEBUG, 1221 LOG (GNUNET_ERROR_TYPE_DEBUG,
1209 "Server continues processing messages still in the buffer.\n"); 1222 "Server continues processing messages still in the buffer.\n");
1210 GNUNET_SERVER_client_keep(client); 1223 GNUNET_SERVER_client_keep (client);
1211 client->receive_pending = GNUNET_NO; 1224 client->receive_pending = GNUNET_NO;
1212 process_mst(client, 1225 process_mst (client,
1213 GNUNET_NO); 1226 GNUNET_NO);
1214 GNUNET_SERVER_client_drop(client); 1227 GNUNET_SERVER_client_drop (client);
1215} 1228}
1216 1229
1217 1230
@@ -1226,25 +1239,25 @@ restart_processing(void *cls)
1226 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 1239 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
1227 */ 1240 */
1228static int 1241static int
1229client_message_tokenizer_callback(void *cls, 1242client_message_tokenizer_callback (void *cls,
1230 void *client, 1243 void *client,
1231 const struct GNUNET_MessageHeader *message) 1244 const struct GNUNET_MessageHeader *message)
1232{ 1245{
1233 struct GNUNET_SERVER_Handle *server = cls; 1246 struct GNUNET_SERVER_Handle *server = cls;
1234 struct GNUNET_SERVER_Client *sender = client; 1247 struct GNUNET_SERVER_Client *sender = client;
1235 int ret; 1248 int ret;
1236 1249
1237 LOG(GNUNET_ERROR_TYPE_DEBUG, 1250 LOG (GNUNET_ERROR_TYPE_DEBUG,
1238 "Tokenizer gives server message of type %u and size %u from client\n", 1251 "Tokenizer gives server message of type %u and size %u from client\n",
1239 ntohs(message->type), ntohs(message->size)); 1252 ntohs (message->type), ntohs (message->size));
1240 sender->in_process_client_buffer = GNUNET_YES; 1253 sender->in_process_client_buffer = GNUNET_YES;
1241 ret = GNUNET_SERVER_inject(server, sender, message); 1254 ret = GNUNET_SERVER_inject (server, sender, message);
1242 sender->in_process_client_buffer = GNUNET_NO; 1255 sender->in_process_client_buffer = GNUNET_NO;
1243 if ((GNUNET_OK != ret) || (GNUNET_YES == sender->shutdown_now)) 1256 if ((GNUNET_OK != ret) || (GNUNET_YES == sender->shutdown_now))
1244 { 1257 {
1245 GNUNET_SERVER_client_disconnect(sender); 1258 GNUNET_SERVER_client_disconnect (sender);
1246 return GNUNET_SYSERR; 1259 return GNUNET_SYSERR;
1247 } 1260 }
1248 return GNUNET_OK; 1261 return GNUNET_OK;
1249} 1262}
1250 1263
@@ -1261,37 +1274,37 @@ client_message_tokenizer_callback(void *cls,
1261 * @return the client handle 1274 * @return the client handle
1262 */ 1275 */
1263struct GNUNET_SERVER_Client * 1276struct GNUNET_SERVER_Client *
1264GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, 1277GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
1265 struct GNUNET_CONNECTION_Handle *connection) 1278 struct GNUNET_CONNECTION_Handle *connection)
1266{ 1279{
1267 struct GNUNET_SERVER_Client *client; 1280 struct GNUNET_SERVER_Client *client;
1268 struct NotifyList *n; 1281 struct NotifyList *n;
1269 1282
1270 client = GNUNET_new(struct GNUNET_SERVER_Client); 1283 client = GNUNET_new (struct GNUNET_SERVER_Client);
1271 client->connection = connection; 1284 client->connection = connection;
1272 client->server = server; 1285 client->server = server;
1273 client->last_activity = GNUNET_TIME_absolute_get(); 1286 client->last_activity = GNUNET_TIME_absolute_get ();
1274 client->idle_timeout = server->idle_timeout; 1287 client->idle_timeout = server->idle_timeout;
1275 GNUNET_CONTAINER_DLL_insert(server->clients_head, 1288 GNUNET_CONTAINER_DLL_insert (server->clients_head,
1276 server->clients_tail, 1289 server->clients_tail,
1277 client); 1290 client);
1278 if (NULL != server->mst_create) 1291 if (NULL != server->mst_create)
1279 client->mst = 1292 client->mst =
1280 server->mst_create(server->mst_cls, client); 1293 server->mst_create (server->mst_cls, client);
1281 else 1294 else
1282 client->mst = 1295 client->mst =
1283 GNUNET_SERVER_mst_create(&client_message_tokenizer_callback, 1296 GNUNET_SERVER_mst_create (&client_message_tokenizer_callback,
1284 server); 1297 server);
1285 GNUNET_assert(NULL != client->mst); 1298 GNUNET_assert (NULL != client->mst);
1286 for (n = server->connect_notify_list_head; NULL != n; n = n->next) 1299 for (n = server->connect_notify_list_head; NULL != n; n = n->next)
1287 n->callback(n->callback_cls, client); 1300 n->callback (n->callback_cls, client);
1288 client->receive_pending = GNUNET_YES; 1301 client->receive_pending = GNUNET_YES;
1289 if (GNUNET_SYSERR == 1302 if (GNUNET_SYSERR ==
1290 GNUNET_CONNECTION_receive(client->connection, 1303 GNUNET_CONNECTION_receive (client->connection,
1291 GNUNET_MAX_MESSAGE_SIZE - 1, 1304 GNUNET_MAX_MESSAGE_SIZE - 1,
1292 client->idle_timeout, 1305 client->idle_timeout,
1293 &process_incoming, 1306 &process_incoming,
1294 client)) 1307 client))
1295 return NULL; 1308 return NULL;
1296 return client; 1309 return client;
1297} 1310}
@@ -1306,8 +1319,8 @@ GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server,
1306 * @param timeout new timeout for activities on the socket 1319 * @param timeout new timeout for activities on the socket
1307 */ 1320 */
1308void 1321void
1309GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client, 1322GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
1310 struct GNUNET_TIME_Relative timeout) 1323 struct GNUNET_TIME_Relative timeout)
1311{ 1324{
1312 client->idle_timeout = timeout; 1325 client->idle_timeout = timeout;
1313} 1326}
@@ -1321,7 +1334,7 @@ GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client,
1321 * @param client the client to keep 1334 * @param client the client to keep
1322 */ 1335 */
1323void 1336void
1324GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client) 1337GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client)
1325{ 1338{
1326 client->reference_count++; 1339 client->reference_count++;
1327} 1340}
@@ -1336,12 +1349,12 @@ GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client)
1336 * @param client the client to drop 1349 * @param client the client to drop
1337 */ 1350 */
1338void 1351void
1339GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client) 1352GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client)
1340{ 1353{
1341 GNUNET_assert(client->reference_count > 0); 1354 GNUNET_assert (client->reference_count > 0);
1342 client->reference_count--; 1355 client->reference_count--;
1343 if ((GNUNET_YES == client->shutdown_now) && (0 == client->reference_count)) 1356 if ((GNUNET_YES == client->shutdown_now) && (0 == client->reference_count))
1344 GNUNET_SERVER_client_disconnect(client); 1357 GNUNET_SERVER_client_disconnect (client);
1345} 1358}
1346 1359
1347 1360
@@ -1354,10 +1367,10 @@ GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client)
1354 * @return #GNUNET_OK on success 1367 * @return #GNUNET_OK on success
1355 */ 1368 */
1356int 1369int
1357GNUNET_SERVER_client_get_address(struct GNUNET_SERVER_Client *client, 1370GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
1358 void **addr, size_t * addrlen) 1371 void **addr, size_t *addrlen)
1359{ 1372{
1360 return GNUNET_CONNECTION_get_address(client->connection, addr, addrlen); 1373 return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen);
1361} 1374}
1362 1375
1363 1376
@@ -1372,18 +1385,18 @@ GNUNET_SERVER_client_get_address(struct GNUNET_SERVER_Client *client,
1372 * @param callback_cls closure for @a callback 1385 * @param callback_cls closure for @a callback
1373 */ 1386 */
1374void 1387void
1375GNUNET_SERVER_disconnect_notify(struct GNUNET_SERVER_Handle *server, 1388GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server,
1376 GNUNET_SERVER_DisconnectCallback callback, 1389 GNUNET_SERVER_DisconnectCallback callback,
1377 void *callback_cls) 1390 void *callback_cls)
1378{ 1391{
1379 struct NotifyList *n; 1392 struct NotifyList *n;
1380 1393
1381 n = GNUNET_new(struct NotifyList); 1394 n = GNUNET_new (struct NotifyList);
1382 n->callback = callback; 1395 n->callback = callback;
1383 n->callback_cls = callback_cls; 1396 n->callback_cls = callback_cls;
1384 GNUNET_CONTAINER_DLL_insert(server->disconnect_notify_list_head, 1397 GNUNET_CONTAINER_DLL_insert (server->disconnect_notify_list_head,
1385 server->disconnect_notify_list_tail, 1398 server->disconnect_notify_list_tail,
1386 n); 1399 n);
1387} 1400}
1388 1401
1389 1402
@@ -1401,21 +1414,21 @@ GNUNET_SERVER_disconnect_notify(struct GNUNET_SERVER_Handle *server,
1401 * @param callback_cls closure for @a callback 1414 * @param callback_cls closure for @a callback
1402 */ 1415 */
1403void 1416void
1404GNUNET_SERVER_connect_notify(struct GNUNET_SERVER_Handle *server, 1417GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server,
1405 GNUNET_SERVER_ConnectCallback callback, 1418 GNUNET_SERVER_ConnectCallback callback,
1406 void *callback_cls) 1419 void *callback_cls)
1407{ 1420{
1408 struct NotifyList *n; 1421 struct NotifyList *n;
1409 struct GNUNET_SERVER_Client *client; 1422 struct GNUNET_SERVER_Client *client;
1410 1423
1411 n = GNUNET_new(struct NotifyList); 1424 n = GNUNET_new (struct NotifyList);
1412 n->callback = callback; 1425 n->callback = callback;
1413 n->callback_cls = callback_cls; 1426 n->callback_cls = callback_cls;
1414 GNUNET_CONTAINER_DLL_insert(server->connect_notify_list_head, 1427 GNUNET_CONTAINER_DLL_insert (server->connect_notify_list_head,
1415 server->connect_notify_list_tail, 1428 server->connect_notify_list_tail,
1416 n); 1429 n);
1417 for (client = server->clients_head; NULL != client; client = client->next) 1430 for (client = server->clients_head; NULL != client; client = client->next)
1418 callback(callback_cls, client); 1431 callback (callback_cls, client);
1419} 1432}
1420 1433
1421 1434
@@ -1427,9 +1440,10 @@ GNUNET_SERVER_connect_notify(struct GNUNET_SERVER_Handle *server,
1427 * @param callback_cls closure for @a callback 1440 * @param callback_cls closure for @a callback
1428 */ 1441 */
1429void 1442void
1430GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server, 1443GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1431 GNUNET_SERVER_DisconnectCallback callback, 1444 GNUNET_SERVER_DisconnectCallback
1432 void *callback_cls) 1445 callback,
1446 void *callback_cls)
1433{ 1447{
1434 struct NotifyList *pos; 1448 struct NotifyList *pos;
1435 1449
@@ -1437,14 +1451,14 @@ GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server,
1437 if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) 1451 if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
1438 break; 1452 break;
1439 if (NULL == pos) 1453 if (NULL == pos)
1440 { 1454 {
1441 GNUNET_break(0); 1455 GNUNET_break (0);
1442 return; 1456 return;
1443 } 1457 }
1444 GNUNET_CONTAINER_DLL_remove(server->disconnect_notify_list_head, 1458 GNUNET_CONTAINER_DLL_remove (server->disconnect_notify_list_head,
1445 server->disconnect_notify_list_tail, 1459 server->disconnect_notify_list_tail,
1446 pos); 1460 pos);
1447 GNUNET_free(pos); 1461 GNUNET_free (pos);
1448} 1462}
1449 1463
1450 1464
@@ -1456,9 +1470,9 @@ GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server,
1456 * @param callback_cls closure for @a callback 1470 * @param callback_cls closure for @a callback
1457 */ 1471 */
1458void 1472void
1459GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server, 1473GNUNET_SERVER_connect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1460 GNUNET_SERVER_ConnectCallback callback, 1474 GNUNET_SERVER_ConnectCallback callback,
1461 void *callback_cls) 1475 void *callback_cls)
1462{ 1476{
1463 struct NotifyList *pos; 1477 struct NotifyList *pos;
1464 1478
@@ -1466,14 +1480,14 @@ GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server,
1466 if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) 1480 if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
1467 break; 1481 break;
1468 if (NULL == pos) 1482 if (NULL == pos)
1469 { 1483 {
1470 GNUNET_break(0); 1484 GNUNET_break (0);
1471 return; 1485 return;
1472 } 1486 }
1473 GNUNET_CONTAINER_DLL_remove(server->connect_notify_list_head, 1487 GNUNET_CONTAINER_DLL_remove (server->connect_notify_list_head,
1474 server->connect_notify_list_tail, 1488 server->connect_notify_list_tail,
1475 pos); 1489 pos);
1476 GNUNET_free(pos); 1490 GNUNET_free (pos);
1477} 1491}
1478 1492
1479 1493
@@ -1486,86 +1500,86 @@ GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server,
1486 * @param client the client to disconnect from 1500 * @param client the client to disconnect from
1487 */ 1501 */
1488void 1502void
1489GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client) 1503GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
1490{ 1504{
1491 struct GNUNET_SERVER_Handle *server = client->server; 1505 struct GNUNET_SERVER_Handle *server = client->server;
1492 struct NotifyList *n; 1506 struct NotifyList *n;
1493 1507
1494 LOG(GNUNET_ERROR_TYPE_DEBUG, 1508 LOG (GNUNET_ERROR_TYPE_DEBUG,
1495 "Client is being disconnected from the server.\n"); 1509 "Client is being disconnected from the server.\n");
1496 if (NULL != client->restart_task) 1510 if (NULL != client->restart_task)
1497 { 1511 {
1498 GNUNET_SCHEDULER_cancel(client->restart_task); 1512 GNUNET_SCHEDULER_cancel (client->restart_task);
1499 client->restart_task = NULL; 1513 client->restart_task = NULL;
1500 } 1514 }
1501 if (NULL != client->warn_task) 1515 if (NULL != client->warn_task)
1502 { 1516 {
1503 GNUNET_SCHEDULER_cancel(client->warn_task); 1517 GNUNET_SCHEDULER_cancel (client->warn_task);
1504 client->warn_task = NULL; 1518 client->warn_task = NULL;
1505 } 1519 }
1506 if (GNUNET_YES == client->receive_pending) 1520 if (GNUNET_YES == client->receive_pending)
1507 { 1521 {
1508 GNUNET_CONNECTION_receive_cancel(client->connection); 1522 GNUNET_CONNECTION_receive_cancel (client->connection);
1509 client->receive_pending = GNUNET_NO; 1523 client->receive_pending = GNUNET_NO;
1510 } 1524 }
1511 client->shutdown_now = GNUNET_YES; 1525 client->shutdown_now = GNUNET_YES;
1512 client->reference_count++; /* make sure nobody else clean up client... */ 1526 client->reference_count++; /* make sure nobody else clean up client... */
1513 if ((NULL != client->mst) && 1527 if ((NULL != client->mst) &&
1514 (NULL != server)) 1528 (NULL != server))
1515 { 1529 {
1516 GNUNET_CONTAINER_DLL_remove(server->clients_head, 1530 GNUNET_CONTAINER_DLL_remove (server->clients_head,
1517 server->clients_tail, 1531 server->clients_tail,
1518 client); 1532 client);
1519 if (NULL != server->mst_destroy) 1533 if (NULL != server->mst_destroy)
1520 server->mst_destroy(server->mst_cls, 1534 server->mst_destroy (server->mst_cls,
1521 client->mst); 1535 client->mst);
1522 else 1536 else
1523 GNUNET_SERVER_mst_destroy(client->mst); 1537 GNUNET_SERVER_mst_destroy (client->mst);
1524 client->mst = NULL; 1538 client->mst = NULL;
1525 for (n = server->disconnect_notify_list_head; NULL != n; n = n->next) 1539 for (n = server->disconnect_notify_list_head; NULL != n; n = n->next)
1526 n->callback(n->callback_cls, 1540 n->callback (n->callback_cls,
1527 client); 1541 client);
1528 } 1542 }
1529 client->reference_count--; 1543 client->reference_count--;
1530 if (client->reference_count > 0) 1544 if (client->reference_count > 0)
1531 { 1545 {
1532 LOG(GNUNET_ERROR_TYPE_DEBUG, 1546 LOG (GNUNET_ERROR_TYPE_DEBUG,
1533 "RC of %p still positive, not destroying everything.\n", 1547 "RC of %p still positive, not destroying everything.\n",
1534 client); 1548 client);
1535 client->server = NULL; 1549 client->server = NULL;
1536 return; 1550 return;
1537 } 1551 }
1538 if (GNUNET_YES == client->in_process_client_buffer) 1552 if (GNUNET_YES == client->in_process_client_buffer)
1539 { 1553 {
1540 LOG(GNUNET_ERROR_TYPE_DEBUG, 1554 LOG (GNUNET_ERROR_TYPE_DEBUG,
1541 "Still processing inputs of %p, not destroying everything.\n", 1555 "Still processing inputs of %p, not destroying everything.\n",
1542 client); 1556 client);
1543 return; 1557 return;
1544 } 1558 }
1545 LOG(GNUNET_ERROR_TYPE_DEBUG, 1559 LOG (GNUNET_ERROR_TYPE_DEBUG,
1546 "RC of %p now zero, destroying everything.\n", 1560 "RC of %p now zero, destroying everything.\n",
1547 client); 1561 client);
1548 if (GNUNET_YES == client->persist) 1562 if (GNUNET_YES == client->persist)
1549 GNUNET_CONNECTION_persist_(client->connection); 1563 GNUNET_CONNECTION_persist_ (client->connection);
1550 if (NULL != client->th.cth) 1564 if (NULL != client->th.cth)
1551 GNUNET_SERVER_notify_transmit_ready_cancel(&client->th); 1565 GNUNET_SERVER_notify_transmit_ready_cancel (&client->th);
1552 GNUNET_CONNECTION_destroy(client->connection); 1566 GNUNET_CONNECTION_destroy (client->connection);
1553 /* need to cancel again, as it might have been re-added 1567 /* need to cancel again, as it might have been re-added
1554 in the meantime (i.e. during callbacks) */ 1568 in the meantime (i.e. during callbacks) */
1555 if (NULL != client->warn_task) 1569 if (NULL != client->warn_task)
1556 { 1570 {
1557 GNUNET_SCHEDULER_cancel(client->warn_task); 1571 GNUNET_SCHEDULER_cancel (client->warn_task);
1558 client->warn_task = NULL; 1572 client->warn_task = NULL;
1559 } 1573 }
1560 if (GNUNET_YES == client->receive_pending) 1574 if (GNUNET_YES == client->receive_pending)
1561 { 1575 {
1562 GNUNET_CONNECTION_receive_cancel(client->connection); 1576 GNUNET_CONNECTION_receive_cancel (client->connection);
1563 client->receive_pending = GNUNET_NO; 1577 client->receive_pending = GNUNET_NO;
1564 } 1578 }
1565 GNUNET_free(client); 1579 GNUNET_free (client);
1566 /* we might be in soft-shutdown, test if we're done */ 1580 /* we might be in soft-shutdown, test if we're done */
1567 if (NULL != server) 1581 if (NULL != server)
1568 test_monitor_clients(server); 1582 test_monitor_clients (server);
1569} 1583}
1570 1584
1571 1585
@@ -1578,9 +1592,9 @@ GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
1578 * @return #GNUNET_OK on success 1592 * @return #GNUNET_OK on success
1579 */ 1593 */
1580int 1594int
1581GNUNET_SERVER_client_disable_corking(struct GNUNET_SERVER_Client *client) 1595GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client)
1582{ 1596{
1583 return GNUNET_CONNECTION_disable_corking(client->connection); 1597 return GNUNET_CONNECTION_disable_corking (client->connection);
1584} 1598}
1585 1599
1586 1600
@@ -1594,7 +1608,7 @@ GNUNET_SERVER_client_disable_corking(struct GNUNET_SERVER_Client *client)
1594 * @return number of bytes actually transmitted 1608 * @return number of bytes actually transmitted
1595 */ 1609 */
1596static size_t 1610static size_t
1597transmit_ready_callback_wrapper(void *cls, size_t size, void *buf) 1611transmit_ready_callback_wrapper (void *cls, size_t size, void *buf)
1598{ 1612{
1599 struct GNUNET_SERVER_Client *client = cls; 1613 struct GNUNET_SERVER_Client *client = cls;
1600 GNUNET_CONNECTION_TransmitReadyNotify callback; 1614 GNUNET_CONNECTION_TransmitReadyNotify callback;
@@ -1602,8 +1616,8 @@ transmit_ready_callback_wrapper(void *cls, size_t size, void *buf)
1602 client->th.cth = NULL; 1616 client->th.cth = NULL;
1603 callback = client->th.callback; 1617 callback = client->th.callback;
1604 client->th.callback = NULL; 1618 client->th.callback = NULL;
1605 client->last_activity = GNUNET_TIME_absolute_get(); 1619 client->last_activity = GNUNET_TIME_absolute_get ();
1606 return callback(client->th.callback_cls, size, buf); 1620 return callback (client->th.callback_cls, size, buf);
1607} 1621}
1608 1622
1609 1623
@@ -1623,20 +1637,23 @@ transmit_ready_callback_wrapper(void *cls, size_t size, void *buf)
1623 * NULL if we are already going to notify someone else (busy) 1637 * NULL if we are already going to notify someone else (busy)
1624 */ 1638 */
1625struct GNUNET_SERVER_TransmitHandle * 1639struct GNUNET_SERVER_TransmitHandle *
1626GNUNET_SERVER_notify_transmit_ready(struct GNUNET_SERVER_Client *client, 1640GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
1627 size_t size, 1641 size_t size,
1628 struct GNUNET_TIME_Relative timeout, 1642 struct GNUNET_TIME_Relative timeout,
1629 GNUNET_CONNECTION_TransmitReadyNotify callback, 1643 GNUNET_CONNECTION_TransmitReadyNotify
1630 void *callback_cls) 1644 callback,
1645 void *callback_cls)
1631{ 1646{
1632 if (NULL != client->th.callback) 1647 if (NULL != client->th.callback)
1633 return NULL; 1648 return NULL;
1634 client->th.callback_cls = callback_cls; 1649 client->th.callback_cls = callback_cls;
1635 client->th.callback = callback; 1650 client->th.callback = callback;
1636 client->th.cth = GNUNET_CONNECTION_notify_transmit_ready(client->connection, size, 1651 client->th.cth = GNUNET_CONNECTION_notify_transmit_ready (client->connection,
1637 timeout, 1652 size,
1638 &transmit_ready_callback_wrapper, 1653 timeout,
1639 client); 1654 &
1655 transmit_ready_callback_wrapper,
1656 client);
1640 return &client->th; 1657 return &client->th;
1641} 1658}
1642 1659
@@ -1647,9 +1664,10 @@ GNUNET_SERVER_notify_transmit_ready(struct GNUNET_SERVER_Client *client,
1647 * @param th request to abort 1664 * @param th request to abort
1648 */ 1665 */
1649void 1666void
1650GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle *th) 1667GNUNET_SERVER_notify_transmit_ready_cancel (struct
1668 GNUNET_SERVER_TransmitHandle *th)
1651{ 1669{
1652 GNUNET_CONNECTION_notify_transmit_ready_cancel(th->cth); 1670 GNUNET_CONNECTION_notify_transmit_ready_cancel (th->cth);
1653 th->cth = NULL; 1671 th->cth = NULL;
1654 th->callback = NULL; 1672 th->callback = NULL;
1655} 1673}
@@ -1662,7 +1680,7 @@ GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle *
1662 * @param client the client to set the persistent flag on 1680 * @param client the client to set the persistent flag on
1663 */ 1681 */
1664void 1682void
1665GNUNET_SERVER_client_persist_(struct GNUNET_SERVER_Client *client) 1683GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client)
1666{ 1684{
1667 client->persist = GNUNET_YES; 1685 client->persist = GNUNET_YES;
1668} 1686}
@@ -1681,50 +1699,50 @@ GNUNET_SERVER_client_persist_(struct GNUNET_SERVER_Client *client)
1681 * serious error) 1699 * serious error)
1682 */ 1700 */
1683void 1701void
1684GNUNET_SERVER_receive_done(struct GNUNET_SERVER_Client *client, 1702GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client,
1685 int success) 1703 int success)
1686{ 1704{
1687 if (NULL == client) 1705 if (NULL == client)
1688 return; 1706 return;
1689 GNUNET_assert(client->suspended > 0); 1707 GNUNET_assert (client->suspended > 0);
1690 client->suspended--; 1708 client->suspended--;
1691 if (GNUNET_OK != success) 1709 if (GNUNET_OK != success)
1692 { 1710 {
1693 LOG(GNUNET_ERROR_TYPE_DEBUG, 1711 LOG (GNUNET_ERROR_TYPE_DEBUG,
1694 "GNUNET_SERVER_receive_done called with failure indication\n"); 1712 "GNUNET_SERVER_receive_done called with failure indication\n");
1695 if ((client->reference_count > 0) || (client->suspended > 0)) 1713 if ((client->reference_count > 0) || (client->suspended > 0))
1696 client->shutdown_now = GNUNET_YES; 1714 client->shutdown_now = GNUNET_YES;
1697 else 1715 else
1698 GNUNET_SERVER_client_disconnect(client); 1716 GNUNET_SERVER_client_disconnect (client);
1699 return; 1717 return;
1700 } 1718 }
1701 if (client->suspended > 0) 1719 if (client->suspended > 0)
1702 { 1720 {
1703 LOG(GNUNET_ERROR_TYPE_DEBUG, 1721 LOG (GNUNET_ERROR_TYPE_DEBUG,
1704 "GNUNET_SERVER_receive_done called, but more clients pending\n"); 1722 "GNUNET_SERVER_receive_done called, but more clients pending\n");
1705 return; 1723 return;
1706 } 1724 }
1707 if (NULL != client->warn_task) 1725 if (NULL != client->warn_task)
1708 { 1726 {
1709 GNUNET_SCHEDULER_cancel(client->warn_task); 1727 GNUNET_SCHEDULER_cancel (client->warn_task);
1710 client->warn_task = NULL; 1728 client->warn_task = NULL;
1711 } 1729 }
1712 if (GNUNET_YES == client->in_process_client_buffer) 1730 if (GNUNET_YES == client->in_process_client_buffer)
1713 { 1731 {
1714 LOG(GNUNET_ERROR_TYPE_DEBUG, 1732 LOG (GNUNET_ERROR_TYPE_DEBUG,
1715 "GNUNET_SERVER_receive_done called while still in processing loop\n"); 1733 "GNUNET_SERVER_receive_done called while still in processing loop\n");
1716 return; 1734 return;
1717 } 1735 }
1718 if ((NULL == client->server) || (GNUNET_YES == client->shutdown_now)) 1736 if ((NULL == client->server) || (GNUNET_YES == client->shutdown_now))
1719 { 1737 {
1720 GNUNET_SERVER_client_disconnect(client); 1738 GNUNET_SERVER_client_disconnect (client);
1721 return; 1739 return;
1722 } 1740 }
1723 LOG(GNUNET_ERROR_TYPE_DEBUG, 1741 LOG (GNUNET_ERROR_TYPE_DEBUG,
1724 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n"); 1742 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n");
1725 GNUNET_assert(NULL == client->restart_task); 1743 GNUNET_assert (NULL == client->restart_task);
1726 client->restart_task = GNUNET_SCHEDULER_add_now(&restart_processing, 1744 client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing,
1727 client); 1745 client);
1728} 1746}
1729 1747
1730 1748
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 @@
38/** 38/**
39 * Handle to a message stream tokenizer. 39 * Handle to a message stream tokenizer.
40 */ 40 */
41struct GNUNET_SERVER_MessageStreamTokenizer { 41struct GNUNET_SERVER_MessageStreamTokenizer
42{
42 /** 43 /**
43 * Function to call on completed messages. 44 * Function to call on completed messages.
44 */ 45 */
@@ -80,13 +81,13 @@ struct GNUNET_SERVER_MessageStreamTokenizer {
80 * @return handle to tokenizer 81 * @return handle to tokenizer
81 */ 82 */
82struct GNUNET_SERVER_MessageStreamTokenizer * 83struct GNUNET_SERVER_MessageStreamTokenizer *
83GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, 84GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
84 void *cb_cls) 85 void *cb_cls)
85{ 86{
86 struct GNUNET_SERVER_MessageStreamTokenizer *ret; 87 struct GNUNET_SERVER_MessageStreamTokenizer *ret;
87 88
88 ret = GNUNET_new(struct GNUNET_SERVER_MessageStreamTokenizer); 89 ret = GNUNET_new (struct GNUNET_SERVER_MessageStreamTokenizer);
89 ret->hdr = GNUNET_malloc(GNUNET_MIN_MESSAGE_SIZE); 90 ret->hdr = GNUNET_malloc (GNUNET_MIN_MESSAGE_SIZE);
90 ret->curr_buf = GNUNET_MIN_MESSAGE_SIZE; 91 ret->curr_buf = GNUNET_MIN_MESSAGE_SIZE;
91 ret->cb = cb; 92 ret->cb = cb;
92 ret->cb_cls = cb_cls; 93 ret->cb_cls = cb_cls;
@@ -110,10 +111,10 @@ GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb,
110 * #GNUNET_SYSERR if the data stream is corrupt 111 * #GNUNET_SYSERR if the data stream is corrupt
111 */ 112 */
112int 113int
113GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst, 114GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
114 void *client_identity, 115 void *client_identity,
115 const char *buf, size_t size, 116 const char *buf, size_t size,
116 int purge, int one_shot) 117 int purge, int one_shot)
117{ 118{
118 const struct GNUNET_MessageHeader *hdr; 119 const struct GNUNET_MessageHeader *hdr;
119 size_t delta; 120 size_t delta;
@@ -123,170 +124,170 @@ GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst,
123 unsigned long offset; 124 unsigned long offset;
124 int ret; 125 int ret;
125 126
126 GNUNET_assert(mst->off <= mst->pos); 127 GNUNET_assert (mst->off <= mst->pos);
127 GNUNET_assert(mst->pos <= mst->curr_buf); 128 GNUNET_assert (mst->pos <= mst->curr_buf);
128 LOG(GNUNET_ERROR_TYPE_DEBUG, 129 LOG (GNUNET_ERROR_TYPE_DEBUG,
129 "Server-mst receives %u bytes with %u bytes already in private buffer\n", 130 "Server-mst receives %u bytes with %u bytes already in private buffer\n",
130 (unsigned int)size, (unsigned int)(mst->pos - mst->off)); 131 (unsigned int) size, (unsigned int) (mst->pos - mst->off));
131 ret = GNUNET_OK; 132 ret = GNUNET_OK;
132 ibuf = (char *)mst->hdr; 133 ibuf = (char *) mst->hdr;
133 while (mst->pos > 0) 134 while (mst->pos > 0)
134 { 135 {
135do_align: 136do_align:
136 GNUNET_assert(mst->pos >= mst->off); 137 GNUNET_assert (mst->pos >= mst->off);
137 if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) || 138 if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
138 (0 != (mst->off % ALIGN_FACTOR))) 139 (0 != (mst->off % ALIGN_FACTOR)))
139 { 140 {
140 /* need to align or need more space */ 141 /* need to align or need more space */
141 mst->pos -= mst->off; 142 mst->pos -= mst->off;
142 memmove(ibuf, &ibuf[mst->off], mst->pos); 143 memmove (ibuf, &ibuf[mst->off], mst->pos);
143 mst->off = 0; 144 mst->off = 0;
144 } 145 }
145 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) 146 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
146 { 147 {
147 delta = 148 delta =
148 GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) - 149 GNUNET_MIN (sizeof(struct GNUNET_MessageHeader)
149 (mst->pos - mst->off), size); 150 - (mst->pos - mst->off), size);
150 GNUNET_memcpy(&ibuf[mst->pos], buf, delta); 151 GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
151 mst->pos += delta; 152 mst->pos += delta;
152 buf += delta; 153 buf += delta;
153 size -= delta; 154 size -= delta;
154 } 155 }
155 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader)) 156 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
156 { 157 {
157 if (purge) 158 if (purge)
158 { 159 {
159 mst->off = 0; 160 mst->off = 0;
160 mst->pos = 0; 161 mst->pos = 0;
161 } 162 }
162 return GNUNET_OK; 163 return GNUNET_OK;
163 } 164 }
164 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off]; 165 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
165 want = ntohs(hdr->size); 166 want = ntohs (hdr->size);
167 if (want < sizeof(struct GNUNET_MessageHeader))
168 {
169 GNUNET_break_op (0);
170 return GNUNET_SYSERR;
171 }
172 if ((mst->curr_buf - mst->off < want) &&
173 (mst->off > 0))
174 {
175 /* can get more space by moving */
176 mst->pos -= mst->off;
177 memmove (ibuf, &ibuf[mst->off], mst->pos);
178 mst->off = 0;
179 }
180 if (mst->curr_buf < want)
181 {
182 /* need to get more space by growing buffer */
183 GNUNET_assert (0 == mst->off);
184 mst->hdr = GNUNET_realloc (mst->hdr, want);
185 ibuf = (char *) mst->hdr;
186 mst->curr_buf = want;
187 }
188 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
189 if (mst->pos - mst->off < want)
190 {
191 delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
192 GNUNET_assert (mst->pos + delta <= mst->curr_buf);
193 GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
194 mst->pos += delta;
195 buf += delta;
196 size -= delta;
197 }
198 if (mst->pos - mst->off < want)
199 {
200 if (purge)
201 {
202 mst->off = 0;
203 mst->pos = 0;
204 }
205 return GNUNET_OK;
206 }
207 if (one_shot == GNUNET_SYSERR)
208 {
209 /* cannot call callback again, but return value saying that
210 * we have another full message in the buffer */
211 ret = GNUNET_NO;
212 goto copy;
213 }
214 if (one_shot == GNUNET_YES)
215 one_shot = GNUNET_SYSERR;
216 mst->off += want;
217 if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr))
218 return GNUNET_SYSERR;
219 if (mst->off == mst->pos)
220 {
221 /* reset to beginning of buffer, it's free right now! */
222 mst->off = 0;
223 mst->pos = 0;
224 }
225 }
226 GNUNET_assert (0 == mst->pos);
227 while (size > 0)
228 {
229 LOG (GNUNET_ERROR_TYPE_DEBUG,
230 "Server-mst has %u bytes left in inbound buffer\n",
231 (unsigned int) size);
232 if (size < sizeof(struct GNUNET_MessageHeader))
233 break;
234 offset = (unsigned long) buf;
235 need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO;
236 if (GNUNET_NO == need_align)
237 {
238 /* can try to do zero-copy and process directly from original buffer */
239 hdr = (const struct GNUNET_MessageHeader *) buf;
240 want = ntohs (hdr->size);
166 if (want < sizeof(struct GNUNET_MessageHeader)) 241 if (want < sizeof(struct GNUNET_MessageHeader))
167 { 242 {
168 GNUNET_break_op(0); 243 GNUNET_break_op (0);
169 return GNUNET_SYSERR; 244 mst->off = 0;
170 } 245 return GNUNET_SYSERR;
171 if ((mst->curr_buf - mst->off < want) && 246 }
172 (mst->off > 0)) 247 if (size < want)
173 { 248 break; /* or not: buffer incomplete, so copy to private buffer... */
174 /* can get more space by moving */
175 mst->pos -= mst->off;
176 memmove(ibuf, &ibuf[mst->off], mst->pos);
177 mst->off = 0;
178 }
179 if (mst->curr_buf < want)
180 {
181 /* need to get more space by growing buffer */
182 GNUNET_assert(0 == mst->off);
183 mst->hdr = GNUNET_realloc(mst->hdr, want);
184 ibuf = (char *)mst->hdr;
185 mst->curr_buf = want;
186 }
187 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
188 if (mst->pos - mst->off < want)
189 {
190 delta = GNUNET_MIN(want - (mst->pos - mst->off), size);
191 GNUNET_assert(mst->pos + delta <= mst->curr_buf);
192 GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
193 mst->pos += delta;
194 buf += delta;
195 size -= delta;
196 }
197 if (mst->pos - mst->off < want)
198 {
199 if (purge)
200 {
201 mst->off = 0;
202 mst->pos = 0;
203 }
204 return GNUNET_OK;
205 }
206 if (one_shot == GNUNET_SYSERR) 249 if (one_shot == GNUNET_SYSERR)
207 { 250 {
208 /* cannot call callback again, but return value saying that 251 /* cannot call callback again, but return value saying that
209 * we have another full message in the buffer */ 252 * we have another full message in the buffer */
210 ret = GNUNET_NO; 253 ret = GNUNET_NO;
211 goto copy; 254 goto copy;
212 } 255 }
213 if (one_shot == GNUNET_YES) 256 if (one_shot == GNUNET_YES)
214 one_shot = GNUNET_SYSERR; 257 one_shot = GNUNET_SYSERR;
215 mst->off += want; 258 if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr))
216 if (GNUNET_SYSERR == mst->cb(mst->cb_cls, client_identity, hdr))
217 return GNUNET_SYSERR; 259 return GNUNET_SYSERR;
218 if (mst->off == mst->pos) 260 buf += want;
219 { 261 size -= want;
220 /* reset to beginning of buffer, it's free right now! */
221 mst->off = 0;
222 mst->pos = 0;
223 }
224 } 262 }
225 GNUNET_assert(0 == mst->pos); 263 else
226 while (size > 0)
227 { 264 {
228 LOG(GNUNET_ERROR_TYPE_DEBUG, 265 /* need to copy to private buffer to align;
229 "Server-mst has %u bytes left in inbound buffer\n", 266 * yes, we go a bit more spagetti than usual here */
230 (unsigned int)size); 267 goto do_align;
231 if (size < sizeof(struct GNUNET_MessageHeader))
232 break;
233 offset = (unsigned long)buf;
234 need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO;
235 if (GNUNET_NO == need_align)
236 {
237 /* can try to do zero-copy and process directly from original buffer */
238 hdr = (const struct GNUNET_MessageHeader *)buf;
239 want = ntohs(hdr->size);
240 if (want < sizeof(struct GNUNET_MessageHeader))
241 {
242 GNUNET_break_op(0);
243 mst->off = 0;
244 return GNUNET_SYSERR;
245 }
246 if (size < want)
247 break; /* or not: buffer incomplete, so copy to private buffer... */
248 if (one_shot == GNUNET_SYSERR)
249 {
250 /* cannot call callback again, but return value saying that
251 * we have another full message in the buffer */
252 ret = GNUNET_NO;
253 goto copy;
254 }
255 if (one_shot == GNUNET_YES)
256 one_shot = GNUNET_SYSERR;
257 if (GNUNET_SYSERR == mst->cb(mst->cb_cls, client_identity, hdr))
258 return GNUNET_SYSERR;
259 buf += want;
260 size -= want;
261 }
262 else
263 {
264 /* need to copy to private buffer to align;
265 * yes, we go a bit more spagetti than usual here */
266 goto do_align;
267 }
268 } 268 }
269 }
269copy: 270copy:
270 if ((size > 0) && (!purge)) 271 if ((size > 0) && (! purge))
272 {
273 if (size + mst->pos > mst->curr_buf)
271 { 274 {
272 if (size + mst->pos > mst->curr_buf) 275 mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos);
273 { 276 ibuf = (char *) mst->hdr;
274 mst->hdr = GNUNET_realloc(mst->hdr, size + mst->pos); 277 mst->curr_buf = size + mst->pos;
275 ibuf = (char *)mst->hdr;
276 mst->curr_buf = size + mst->pos;
277 }
278 GNUNET_assert(size + mst->pos <= mst->curr_buf);
279 GNUNET_memcpy(&ibuf[mst->pos], buf, size);
280 mst->pos += size;
281 } 278 }
279 GNUNET_assert (size + mst->pos <= mst->curr_buf);
280 GNUNET_memcpy (&ibuf[mst->pos], buf, size);
281 mst->pos += size;
282 }
282 if (purge) 283 if (purge)
283 { 284 {
284 mst->off = 0; 285 mst->off = 0;
285 mst->pos = 0; 286 mst->pos = 0;
286 } 287 }
287 LOG(GNUNET_ERROR_TYPE_DEBUG, 288 LOG (GNUNET_ERROR_TYPE_DEBUG,
288 "Server-mst leaves %u bytes in private buffer\n", 289 "Server-mst leaves %u bytes in private buffer\n",
289 (unsigned int)(mst->pos - mst->off)); 290 (unsigned int) (mst->pos - mst->off));
290 return ret; 291 return ret;
291} 292}
292 293
@@ -297,10 +298,10 @@ copy:
297 * @param mst tokenizer to destroy 298 * @param mst tokenizer to destroy
298 */ 299 */
299void 300void
300GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst) 301GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst)
301{ 302{
302 GNUNET_free(mst->hdr); 303 GNUNET_free (mst->hdr);
303 GNUNET_free(mst); 304 GNUNET_free (mst);
304} 305}
305 306
306 307
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 @@
45 * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is 45 * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is
46 */ 46 */
47static int 47static int
48check_ipv4_listed(const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, 48check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list,
49 const struct in_addr *add) 49 const struct in_addr *add)
50{ 50{
51 unsigned int i; 51 unsigned int i;
52 52
@@ -54,12 +54,12 @@ check_ipv4_listed(const struct GNUNET_STRINGS_IPv4NetworkPolicy *list,
54 return GNUNET_NO; 54 return GNUNET_NO;
55 i = 0; 55 i = 0;
56 while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0)) 56 while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0))
57 { 57 {
58 if ((add->s_addr & list[i].netmask.s_addr) == 58 if ((add->s_addr & list[i].netmask.s_addr) ==
59 (list[i].network.s_addr & list[i].netmask.s_addr)) 59 (list[i].network.s_addr & list[i].netmask.s_addr))
60 return GNUNET_YES; 60 return GNUNET_YES;
61 i++; 61 i++;
62 } 62 }
63 return GNUNET_NO; 63 return GNUNET_NO;
64} 64}
65 65
@@ -72,8 +72,8 @@ check_ipv4_listed(const struct GNUNET_STRINGS_IPv4NetworkPolicy *list,
72 * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is 72 * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is
73 */ 73 */
74static int 74static int
75check_ipv6_listed(const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, 75check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list,
76 const struct in6_addr *ip) 76 const struct in6_addr *ip)
77{ 77{
78 unsigned int i; 78 unsigned int i;
79 unsigned int j; 79 unsigned int j;
@@ -81,20 +81,20 @@ check_ipv6_listed(const struct GNUNET_STRINGS_IPv6NetworkPolicy *list,
81 81
82 if (NULL == list) 82 if (NULL == list)
83 return GNUNET_NO; 83 return GNUNET_NO;
84 memset(&zero, 0, sizeof(struct in6_addr)); 84 memset (&zero, 0, sizeof(struct in6_addr));
85 i = 0; 85 i = 0;
86NEXT: 86NEXT:
87 while (0 != memcmp(&zero, &list[i].network, sizeof(struct in6_addr))) 87 while (0 != memcmp (&zero, &list[i].network, sizeof(struct in6_addr)))
88 { 88 {
89 for (j = 0; j < sizeof(struct in6_addr) / sizeof(int); j++) 89 for (j = 0; j < sizeof(struct in6_addr) / sizeof(int); j++)
90 if (((((int *)ip)[j] & ((int *)&list[i].netmask)[j])) != 90 if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) !=
91 (((int *)&list[i].network)[j] & ((int *)&list[i].netmask)[j])) 91 (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j]))
92 { 92 {
93 i++; 93 i++;
94 goto NEXT; 94 goto NEXT;
95 } 95 }
96 return GNUNET_YES; 96 return GNUNET_YES;
97 } 97 }
98 return GNUNET_NO; 98 return GNUNET_NO;
99} 99}
100 100
@@ -105,7 +105,8 @@ NEXT:
105/** 105/**
106 * Context for "service_task". 106 * Context for "service_task".
107 */ 107 */
108struct LEGACY_SERVICE_Context { 108struct LEGACY_SERVICE_Context
109{
109 /** 110 /**
110 * Our configuration. 111 * Our configuration.
111 */ 112 */
@@ -237,20 +238,20 @@ struct LEGACY_SERVICE_Context {
237 * @return number of bytes written to 'buf' 238 * @return number of bytes written to 'buf'
238 */ 239 */
239static size_t 240static size_t
240write_test(void *cls, size_t size, void *buf) 241write_test (void *cls, size_t size, void *buf)
241{ 242{
242 struct GNUNET_SERVER_Client *client = cls; 243 struct GNUNET_SERVER_Client *client = cls;
243 struct GNUNET_MessageHeader *msg; 244 struct GNUNET_MessageHeader *msg;
244 245
245 if (size < sizeof(struct GNUNET_MessageHeader)) 246 if (size < sizeof(struct GNUNET_MessageHeader))
246 { 247 {
247 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 248 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
248 return 0; /* client disconnected */ 249 return 0; /* client disconnected */
249 } 250 }
250 msg = (struct GNUNET_MessageHeader *)buf; 251 msg = (struct GNUNET_MessageHeader *) buf;
251 msg->type = htons(GNUNET_MESSAGE_TYPE_TEST); 252 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
252 msg->size = htons(sizeof(struct GNUNET_MessageHeader)); 253 msg->size = htons (sizeof(struct GNUNET_MessageHeader));
253 GNUNET_SERVER_receive_done(client, GNUNET_OK); 254 GNUNET_SERVER_receive_done (client, GNUNET_OK);
254 return sizeof(struct GNUNET_MessageHeader); 255 return sizeof(struct GNUNET_MessageHeader);
255} 256}
256 257
@@ -263,18 +264,18 @@ write_test(void *cls, size_t size, void *buf)
263 * @param message the actual message 264 * @param message the actual message
264 */ 265 */
265static void 266static void
266handle_test(void *cls, 267handle_test (void *cls,
267 struct GNUNET_SERVER_Client *client, 268 struct GNUNET_SERVER_Client *client,
268 const struct GNUNET_MessageHeader *message) 269 const struct GNUNET_MessageHeader *message)
269{ 270{
270 /* simply bounce message back to acknowledge */ 271 /* simply bounce message back to acknowledge */
271 if (NULL == 272 if (NULL ==
272 GNUNET_SERVER_notify_transmit_ready(client, 273 GNUNET_SERVER_notify_transmit_ready (client,
273 sizeof(struct GNUNET_MessageHeader), 274 sizeof(struct GNUNET_MessageHeader),
274 GNUNET_TIME_UNIT_FOREVER_REL, 275 GNUNET_TIME_UNIT_FOREVER_REL,
275 &write_test, 276 &write_test,
276 client)) 277 client))
277 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
278} 279}
279 280
280 281
@@ -305,10 +306,10 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] =
305 * for unknown address family (will be denied). 306 * for unknown address family (will be denied).
306 */ 307 */
307static int 308static int
308check_access(void *cls, 309check_access (void *cls,
309 const struct GNUNET_CONNECTION_Credentials *uc, 310 const struct GNUNET_CONNECTION_Credentials *uc,
310 const struct sockaddr *addr, 311 const struct sockaddr *addr,
311 socklen_t addrlen) 312 socklen_t addrlen)
312{ 313{
313 struct LEGACY_SERVICE_Context *sctx = cls; 314 struct LEGACY_SERVICE_Context *sctx = cls;
314 const struct sockaddr_in *i4; 315 const struct sockaddr_in *i4;
@@ -316,42 +317,42 @@ check_access(void *cls,
316 int ret; 317 int ret;
317 318
318 switch (addr->sa_family) 319 switch (addr->sa_family)
319 { 320 {
320 case AF_INET: 321 case AF_INET:
321 GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); 322 GNUNET_assert (addrlen == sizeof(struct sockaddr_in));
322 i4 = (const struct sockaddr_in *)addr; 323 i4 = (const struct sockaddr_in *) addr;
323 ret = ((NULL == sctx->v4_allowed) || 324 ret = ((NULL == sctx->v4_allowed) ||
324 (check_ipv4_listed(sctx->v4_allowed, &i4->sin_addr))) && 325 (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) &&
325 ((NULL == sctx->v4_denied) || 326 ((NULL == sctx->v4_denied) ||
326 (!check_ipv4_listed(sctx->v4_denied, &i4->sin_addr))); 327 (! check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
327 break; 328 break;
328 329
329 case AF_INET6: 330 case AF_INET6:
330 GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); 331 GNUNET_assert (addrlen == sizeof(struct sockaddr_in6));
331 i6 = (const struct sockaddr_in6 *)addr; 332 i6 = (const struct sockaddr_in6 *) addr;
332 ret = ((NULL == sctx->v6_allowed) || 333 ret = ((NULL == sctx->v6_allowed) ||
333 (check_ipv6_listed(sctx->v6_allowed, &i6->sin6_addr))) && 334 (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) &&
334 ((NULL == sctx->v6_denied) || 335 ((NULL == sctx->v6_denied) ||
335 (!check_ipv6_listed(sctx->v6_denied, &i6->sin6_addr))); 336 (! check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
336 break; 337 break;
337 338
338 case AF_UNIX: 339 case AF_UNIX:
339 ret = GNUNET_OK; /* controlled using file-system ACL now */ 340 ret = GNUNET_OK; /* controlled using file-system ACL now */
340 break; 341 break;
341 342
342 default: 343 default:
343 LOG(GNUNET_ERROR_TYPE_WARNING, 344 LOG (GNUNET_ERROR_TYPE_WARNING,
344 _("Unknown address family %d\n"), 345 _ ("Unknown address family %d\n"),
345 addr->sa_family); 346 addr->sa_family);
346 return GNUNET_SYSERR; 347 return GNUNET_SYSERR;
347 } 348 }
348 if (GNUNET_OK != ret) 349 if (GNUNET_OK != ret)
349 { 350 {
350 LOG(GNUNET_ERROR_TYPE_WARNING, 351 LOG (GNUNET_ERROR_TYPE_WARNING,
351 _("Access from `%s' denied to service `%s'\n"), 352 _ ("Access from `%s' denied to service `%s'\n"),
352 GNUNET_a2s(addr, addrlen), 353 GNUNET_a2s (addr, addrlen),
353 sctx->service_name); 354 sctx->service_name);
354 } 355 }
355 return ret; 356 return ret;
356} 357}
357 358
@@ -364,14 +365,14 @@ check_access(void *cls,
364 * @return name of the file for the process ID 365 * @return name of the file for the process ID
365 */ 366 */
366static char * 367static char *
367get_pid_file_name(struct LEGACY_SERVICE_Context *sctx) 368get_pid_file_name (struct LEGACY_SERVICE_Context *sctx)
368{ 369{
369 char *pif; 370 char *pif;
370 371
371 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(sctx->cfg, 372 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg,
372 sctx->service_name, 373 sctx->service_name,
373 "PIDFILE", 374 "PIDFILE",
374 &pif)) 375 &pif))
375 return NULL; 376 return NULL;
376 return pif; 377 return pif;
377} 378}
@@ -387,33 +388,33 @@ get_pid_file_name(struct LEGACY_SERVICE_Context *sctx)
387 * no ACL configured) 388 * no ACL configured)
388 */ 389 */
389static int 390static int
390process_acl4(struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, 391process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
391 struct LEGACY_SERVICE_Context *sctx, 392 struct LEGACY_SERVICE_Context *sctx,
392 const char *option) 393 const char *option)
393{ 394{
394 char *opt; 395 char *opt;
395 396
396 if (!GNUNET_CONFIGURATION_have_value(sctx->cfg, sctx->service_name, option)) 397 if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
397 { 398 {
398 *ret = NULL; 399 *ret = NULL;
399 return GNUNET_OK; 400 return GNUNET_OK;
400 } 401 }
401 GNUNET_break(GNUNET_OK == 402 GNUNET_break (GNUNET_OK ==
402 GNUNET_CONFIGURATION_get_value_string(sctx->cfg, 403 GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
403 sctx->service_name, 404 sctx->service_name,
404 option, 405 option,
405 &opt)); 406 &opt));
406 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy(opt))) 407 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt)))
407 { 408 {
408 LOG(GNUNET_ERROR_TYPE_WARNING, 409 LOG (GNUNET_ERROR_TYPE_WARNING,
409 _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), 410 _ ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
410 opt, 411 opt,
411 sctx->service_name, 412 sctx->service_name,
412 option); 413 option);
413 GNUNET_free(opt); 414 GNUNET_free (opt);
414 return GNUNET_SYSERR; 415 return GNUNET_SYSERR;
415 } 416 }
416 GNUNET_free(opt); 417 GNUNET_free (opt);
417 return GNUNET_OK; 418 return GNUNET_OK;
418} 419}
419 420
@@ -428,33 +429,33 @@ process_acl4(struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
428 * no ACL configured) 429 * no ACL configured)
429 */ 430 */
430static int 431static int
431process_acl6(struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, 432process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
432 struct LEGACY_SERVICE_Context *sctx, 433 struct LEGACY_SERVICE_Context *sctx,
433 const char *option) 434 const char *option)
434{ 435{
435 char *opt; 436 char *opt;
436 437
437 if (!GNUNET_CONFIGURATION_have_value(sctx->cfg, sctx->service_name, option)) 438 if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
438 { 439 {
439 *ret = NULL; 440 *ret = NULL;
440 return GNUNET_OK; 441 return GNUNET_OK;
441 } 442 }
442 GNUNET_break(GNUNET_OK == 443 GNUNET_break (GNUNET_OK ==
443 GNUNET_CONFIGURATION_get_value_string(sctx->cfg, 444 GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
444 sctx->service_name, 445 sctx->service_name,
445 option, 446 option,
446 &opt)); 447 &opt));
447 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy(opt))) 448 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt)))
448 { 449 {
449 LOG(GNUNET_ERROR_TYPE_WARNING, 450 LOG (GNUNET_ERROR_TYPE_WARNING,
450 _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), 451 _ ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
451 opt, 452 opt,
452 sctx->service_name, 453 sctx->service_name,
453 option); 454 option);
454 GNUNET_free(opt); 455 GNUNET_free (opt);
455 return GNUNET_SYSERR; 456 return GNUNET_SYSERR;
456 } 457 }
457 GNUNET_free(opt); 458 GNUNET_free (opt);
458 return GNUNET_OK; 459 return GNUNET_OK;
459} 460}
460 461
@@ -470,30 +471,30 @@ process_acl6(struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
470 * parameter is ignore on systems other than LINUX 471 * parameter is ignore on systems other than LINUX
471 */ 472 */
472static void 473static void
473add_unixpath(struct sockaddr **saddrs, 474add_unixpath (struct sockaddr **saddrs,
474 socklen_t *saddrlens, 475 socklen_t *saddrlens,
475 const char *unixpath, 476 const char *unixpath,
476 int abstract) 477 int abstract)
477{ 478{
478#ifdef AF_UNIX 479#ifdef AF_UNIX
479 struct sockaddr_un *un; 480 struct sockaddr_un *un;
480 481
481 un = GNUNET_new(struct sockaddr_un); 482 un = GNUNET_new (struct sockaddr_un);
482 un->sun_family = AF_UNIX; 483 un->sun_family = AF_UNIX;
483 GNUNET_strlcpy(un->sun_path, unixpath, sizeof(un->sun_path)); 484 GNUNET_strlcpy (un->sun_path, unixpath, sizeof(un->sun_path));
484#ifdef LINUX 485#ifdef LINUX
485 if (GNUNET_YES == abstract) 486 if (GNUNET_YES == abstract)
486 un->sun_path[0] = '\0'; 487 un->sun_path[0] = '\0';
487#endif 488#endif
488#if HAVE_SOCKADDR_UN_SUN_LEN 489#if HAVE_SOCKADDR_UN_SUN_LEN
489 un->sun_len = (u_char)sizeof(struct sockaddr_un); 490 un->sun_len = (u_char) sizeof(struct sockaddr_un);
490#endif 491#endif
491 *saddrs = (struct sockaddr *)un; 492 *saddrs = (struct sockaddr *) un;
492 *saddrlens = sizeof(struct sockaddr_un); 493 *saddrlens = sizeof(struct sockaddr_un);
493#else 494#else
494 /* this function should never be called 495 /* this function should never be called
495 * unless AF_UNIX is defined! */ 496 * unless AF_UNIX is defined! */
496 GNUNET_assert(0); 497 GNUNET_assert (0);
497#endif 498#endif
498} 499}
499 500
@@ -519,7 +520,7 @@ add_unixpath(struct sockaddr **saddrs,
519 * set to NULL). 520 * set to NULL).
520 */ 521 */
521int 522int
522LEGACY_SERVICE_get_server_addresses( 523LEGACY_SERVICE_get_server_addresses (
523 const char *service_name, 524 const char *service_name,
524 const struct GNUNET_CONFIGURATION_Handle *cfg, 525 const struct GNUNET_CONFIGURATION_Handle *cfg,
525 struct sockaddr ***addrs, 526 struct sockaddr ***addrs,
@@ -544,72 +545,72 @@ LEGACY_SERVICE_get_server_addresses(
544 *addrs = NULL; 545 *addrs = NULL;
545 *addr_lens = NULL; 546 *addr_lens = NULL;
546 desc = NULL; 547 desc = NULL;
547 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "DISABLEV6")) 548 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
548 { 549 {
549 if (GNUNET_SYSERR == 550 if (GNUNET_SYSERR ==
550 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno(cfg, 551 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
551 service_name, 552 service_name,
552 "DISABLEV6"))) 553 "DISABLEV6")))
553 return GNUNET_SYSERR; 554 return GNUNET_SYSERR;
554 } 555 }
555 else 556 else
556 disablev6 = GNUNET_NO; 557 disablev6 = GNUNET_NO;
557 558
558 if (!disablev6) 559 if (! disablev6)
560 {
561 /* probe IPv6 support */
562 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
563 if (NULL == desc)
559 { 564 {
560 /* probe IPv6 support */ 565 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
561 desc = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0); 566 (EACCES == errno))
562 if (NULL == desc) 567 {
563 { 568 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
564 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || 569 return GNUNET_SYSERR;
565 (EACCES == errno)) 570 }
566 { 571 LOG (GNUNET_ERROR_TYPE_INFO,
567 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); 572 _ (
568 return GNUNET_SYSERR; 573 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
569 } 574 service_name,
570 LOG(GNUNET_ERROR_TYPE_INFO, 575 strerror (errno));
571 _( 576 disablev6 = GNUNET_YES;
572 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
573 service_name,
574 strerror(errno));
575 disablev6 = GNUNET_YES;
576 }
577 else
578 {
579 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc));
580 desc = NULL;
581 }
582 } 577 }
578 else
579 {
580 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
581 desc = NULL;
582 }
583 }
583 584
584 port = 0; 585 port = 0;
585 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT")) 586 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
587 {
588 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
589 service_name,
590 "PORT",
591 &port))
586 { 592 {
587 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, 593 LOG (GNUNET_ERROR_TYPE_ERROR,
588 service_name, 594 _ ("Require valid port number for service `%s' in configuration!\n"),
589 "PORT", 595 service_name);
590 &port))
591 {
592 LOG(GNUNET_ERROR_TYPE_ERROR,
593 _("Require valid port number for service `%s' in configuration!\n"),
594 service_name);
595 }
596 if (port > 65535)
597 {
598 LOG(GNUNET_ERROR_TYPE_ERROR,
599 _("Require valid port number for service `%s' in configuration!\n"),
600 service_name);
601 return GNUNET_SYSERR;
602 }
603 } 596 }
604 597 if (port > 65535)
605 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "BINDTO"))
606 { 598 {
607 GNUNET_break(GNUNET_OK == 599 LOG (GNUNET_ERROR_TYPE_ERROR,
608 GNUNET_CONFIGURATION_get_value_string(cfg, 600 _ ("Require valid port number for service `%s' in configuration!\n"),
601 service_name);
602 return GNUNET_SYSERR;
603 }
604 }
605
606 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
607 {
608 GNUNET_break (GNUNET_OK ==
609 GNUNET_CONFIGURATION_get_value_string (cfg,
609 service_name, 610 service_name,
610 "BINDTO", 611 "BINDTO",
611 &hostname)); 612 &hostname));
612 } 613 }
613 else 614 else
614 hostname = NULL; 615 hostname = NULL;
615 616
@@ -617,232 +618,232 @@ LEGACY_SERVICE_get_server_addresses(
617 abstract = GNUNET_NO; 618 abstract = GNUNET_NO;
618#ifdef AF_UNIX 619#ifdef AF_UNIX
619 if ((GNUNET_YES == 620 if ((GNUNET_YES ==
620 GNUNET_CONFIGURATION_have_value(cfg, service_name, "UNIXPATH")) && 621 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
621 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, 622 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
622 service_name, 623 service_name,
623 "UNIXPATH", 624 "UNIXPATH",
624 &unixpath)) && 625 &unixpath)) &&
625 (0 < strlen(unixpath))) 626 (0 < strlen (unixpath)))
627 {
628 /* probe UNIX support */
629 struct sockaddr_un s_un;
630
631 if (strlen (unixpath) >= sizeof(s_un.sun_path))
626 { 632 {
627 /* probe UNIX support */ 633 LOG (GNUNET_ERROR_TYPE_WARNING,
628 struct sockaddr_un s_un; 634 _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
629 635 unixpath,
630 if (strlen(unixpath) >= sizeof(s_un.sun_path)) 636 (unsigned long long) sizeof(s_un.sun_path));
631 { 637 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
632 LOG(GNUNET_ERROR_TYPE_WARNING, 638 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
633 _("UNIXPATH `%s' too long, maximum length is %llu\n"), 639 }
634 unixpath,
635 (unsigned long long)sizeof(s_un.sun_path));
636 unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath);
637 LOG(GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath);
638 }
639#ifdef LINUX 640#ifdef LINUX
640 abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, 641 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
641 "TESTING", 642 "TESTING",
642 "USE_ABSTRACT_SOCKETS"); 643 "USE_ABSTRACT_SOCKETS");
643 if (GNUNET_SYSERR == abstract) 644 if (GNUNET_SYSERR == abstract)
644 abstract = GNUNET_NO; 645 abstract = GNUNET_NO;
645#endif 646#endif
646 if ((GNUNET_YES != abstract) && 647 if ((GNUNET_YES != abstract) &&
647 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(unixpath))) 648 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
648 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); 649 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
649 } 650 }
650 if (NULL != unixpath) 651 if (NULL != unixpath)
652 {
653 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
654 if (NULL == desc)
651 { 655 {
652 desc = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0); 656 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
653 if (NULL == desc) 657 (EACCES == errno))
654 { 658 {
655 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || 659 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
656 (EACCES == errno)) 660 GNUNET_free_non_null (hostname);
657 { 661 GNUNET_free (unixpath);
658 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); 662 return GNUNET_SYSERR;
659 GNUNET_free_non_null(hostname); 663 }
660 GNUNET_free(unixpath); 664 LOG (GNUNET_ERROR_TYPE_INFO,
661 return GNUNET_SYSERR; 665 _ (
662 } 666 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
663 LOG(GNUNET_ERROR_TYPE_INFO, 667 service_name,
664 _( 668 strerror (errno));
665 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), 669 GNUNET_free (unixpath);
666 service_name, 670 unixpath = NULL;
667 strerror(errno));
668 GNUNET_free(unixpath);
669 unixpath = NULL;
670 }
671 else
672 {
673 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc));
674 desc = NULL;
675 }
676 } 671 }
672 else
673 {
674 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
675 desc = NULL;
676 }
677 }
677#endif 678#endif
678 679
679 if ((0 == port) && (NULL == unixpath)) 680 if ((0 == port) && (NULL == unixpath))
681 {
682 LOG (GNUNET_ERROR_TYPE_ERROR,
683 _ (
684 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
685 service_name);
686 GNUNET_free_non_null (hostname);
687 return GNUNET_SYSERR;
688 }
689 if (0 == port)
690 {
691 saddrs = GNUNET_malloc (2 * sizeof(struct sockaddr *));
692 saddrlens = GNUNET_malloc (2 * sizeof(socklen_t));
693 add_unixpath (saddrs, saddrlens, unixpath, abstract);
694 GNUNET_free_non_null (unixpath);
695 GNUNET_free_non_null (hostname);
696 *addrs = saddrs;
697 *addr_lens = saddrlens;
698 return 1;
699 }
700
701 if (NULL != hostname)
702 {
703 LOG (GNUNET_ERROR_TYPE_DEBUG,
704 "Resolving `%s' since that is where `%s' will bind to.\n",
705 hostname,
706 service_name);
707 memset (&hints, 0, sizeof(struct addrinfo));
708 if (disablev6)
709 hints.ai_family = AF_INET;
710 hints.ai_protocol = IPPROTO_TCP;
711 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
712 (NULL == res))
680 { 713 {
681 LOG(GNUNET_ERROR_TYPE_ERROR, 714 LOG (GNUNET_ERROR_TYPE_ERROR,
682 _( 715 _ ("Failed to resolve `%s': %s\n"),
683 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), 716 hostname,
684 service_name); 717 gai_strerror (ret));
685 GNUNET_free_non_null(hostname); 718 GNUNET_free (hostname);
719 GNUNET_free_non_null (unixpath);
686 return GNUNET_SYSERR; 720 return GNUNET_SYSERR;
687 } 721 }
688 if (0 == port) 722 next = res;
723 i = 0;
724 while (NULL != (pos = next))
689 { 725 {
690 saddrs = GNUNET_malloc(2 * sizeof(struct sockaddr *)); 726 next = pos->ai_next;
691 saddrlens = GNUNET_malloc(2 * sizeof(socklen_t)); 727 if ((disablev6) && (pos->ai_family == AF_INET6))
692 add_unixpath(saddrs, saddrlens, unixpath, abstract); 728 continue;
693 GNUNET_free_non_null(unixpath); 729 i++;
694 GNUNET_free_non_null(hostname);
695 *addrs = saddrs;
696 *addr_lens = saddrlens;
697 return 1;
698 } 730 }
699 731 if (0 == i)
700 if (NULL != hostname)
701 { 732 {
702 LOG(GNUNET_ERROR_TYPE_DEBUG, 733 LOG (GNUNET_ERROR_TYPE_ERROR,
703 "Resolving `%s' since that is where `%s' will bind to.\n", 734 _ ("Failed to find %saddress for `%s'.\n"),
704 hostname, 735 disablev6 ? "IPv4 " : "",
705 service_name); 736 hostname);
706 memset(&hints, 0, sizeof(struct addrinfo)); 737 freeaddrinfo (res);
707 if (disablev6) 738 GNUNET_free (hostname);
708 hints.ai_family = AF_INET; 739 GNUNET_free_non_null (unixpath);
709 hints.ai_protocol = IPPROTO_TCP; 740 return GNUNET_SYSERR;
710 if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || 741 }
711 (NULL == res)) 742 resi = i;
712 { 743 if (NULL != unixpath)
713 LOG(GNUNET_ERROR_TYPE_ERROR, 744 resi++;
714 _("Failed to resolve `%s': %s\n"), 745 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
715 hostname, 746 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
716 gai_strerror(ret)); 747 i = 0;
717 GNUNET_free(hostname); 748 if (NULL != unixpath)
718 GNUNET_free_non_null(unixpath); 749 {
719 return GNUNET_SYSERR; 750 add_unixpath (saddrs, saddrlens, unixpath, abstract);
720 } 751 i++;
721 next = res; 752 }
722 i = 0; 753 next = res;
723 while (NULL != (pos = next)) 754 while (NULL != (pos = next))
724 { 755 {
725 next = pos->ai_next; 756 next = pos->ai_next;
726 if ((disablev6) && (pos->ai_family == AF_INET6)) 757 if ((disablev6) && (AF_INET6 == pos->ai_family))
727 continue; 758 continue;
728 i++; 759 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
729 } 760 continue; /* not TCP */
730 if (0 == i) 761 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
731 { 762 continue; /* huh? */
732 LOG(GNUNET_ERROR_TYPE_ERROR, 763 LOG (GNUNET_ERROR_TYPE_DEBUG,
733 _("Failed to find %saddress for `%s'.\n"), 764 "Service `%s' will bind to `%s'\n",
734 disablev6 ? "IPv4 " : "", 765 service_name,
735 hostname); 766 GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
736 freeaddrinfo(res); 767 if (AF_INET == pos->ai_family)
737 GNUNET_free(hostname); 768 {
738 GNUNET_free_non_null(unixpath); 769 GNUNET_assert (sizeof(struct sockaddr_in) == pos->ai_addrlen);
739 return GNUNET_SYSERR; 770 saddrlens[i] = pos->ai_addrlen;
740 } 771 saddrs[i] = GNUNET_malloc (saddrlens[i]);
741 resi = i; 772 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
773 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
774 }
775 else
776 {
777 GNUNET_assert (AF_INET6 == pos->ai_family);
778 GNUNET_assert (sizeof(struct sockaddr_in6) == pos->ai_addrlen);
779 saddrlens[i] = pos->ai_addrlen;
780 saddrs[i] = GNUNET_malloc (saddrlens[i]);
781 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
782 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
783 }
784 i++;
785 }
786 GNUNET_free (hostname);
787 freeaddrinfo (res);
788 resi = i;
789 }
790 else
791 {
792 /* will bind against everything, just set port */
793 if (disablev6)
794 {
795 /* V4-only */
796 resi = 1;
742 if (NULL != unixpath) 797 if (NULL != unixpath)
743 resi++; 798 resi++;
744 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
745 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
746 i = 0; 799 i = 0;
800 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
801 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
747 if (NULL != unixpath) 802 if (NULL != unixpath)
748 { 803 {
749 add_unixpath(saddrs, saddrlens, unixpath, abstract); 804 add_unixpath (saddrs, saddrlens, unixpath, abstract);
750 i++; 805 i++;
751 } 806 }
752 next = res; 807 saddrlens[i] = sizeof(struct sockaddr_in);
753 while (NULL != (pos = next)) 808 saddrs[i] = GNUNET_malloc (saddrlens[i]);
754 {
755 next = pos->ai_next;
756 if ((disablev6) && (AF_INET6 == pos->ai_family))
757 continue;
758 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
759 continue; /* not TCP */
760 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
761 continue; /* huh? */
762 LOG(GNUNET_ERROR_TYPE_DEBUG,
763 "Service `%s' will bind to `%s'\n",
764 service_name,
765 GNUNET_a2s(pos->ai_addr, pos->ai_addrlen));
766 if (AF_INET == pos->ai_family)
767 {
768 GNUNET_assert(sizeof(struct sockaddr_in) == pos->ai_addrlen);
769 saddrlens[i] = pos->ai_addrlen;
770 saddrs[i] = GNUNET_malloc(saddrlens[i]);
771 GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]);
772 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port);
773 }
774 else
775 {
776 GNUNET_assert(AF_INET6 == pos->ai_family);
777 GNUNET_assert(sizeof(struct sockaddr_in6) == pos->ai_addrlen);
778 saddrlens[i] = pos->ai_addrlen;
779 saddrs[i] = GNUNET_malloc(saddrlens[i]);
780 GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]);
781 ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port);
782 }
783 i++;
784 }
785 GNUNET_free(hostname);
786 freeaddrinfo(res);
787 resi = i;
788 }
789 else
790 {
791 /* will bind against everything, just set port */
792 if (disablev6)
793 {
794 /* V4-only */
795 resi = 1;
796 if (NULL != unixpath)
797 resi++;
798 i = 0;
799 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
800 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
801 if (NULL != unixpath)
802 {
803 add_unixpath(saddrs, saddrlens, unixpath, abstract);
804 i++;
805 }
806 saddrlens[i] = sizeof(struct sockaddr_in);
807 saddrs[i] = GNUNET_malloc(saddrlens[i]);
808#if HAVE_SOCKADDR_IN_SIN_LEN 809#if HAVE_SOCKADDR_IN_SIN_LEN
809 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; 810 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
810#endif 811#endif
811 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; 812 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
812 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); 813 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
813 } 814 }
814 else 815 else
815 { 816 {
816 /* dual stack */ 817 /* dual stack */
817 resi = 2; 818 resi = 2;
818 if (NULL != unixpath) 819 if (NULL != unixpath)
819 resi++; 820 resi++;
820 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); 821 saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *));
821 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); 822 saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t));
822 i = 0; 823 i = 0;
823 if (NULL != unixpath) 824 if (NULL != unixpath)
824 { 825 {
825 add_unixpath(saddrs, saddrlens, unixpath, abstract); 826 add_unixpath (saddrs, saddrlens, unixpath, abstract);
826 i++; 827 i++;
827 } 828 }
828 saddrlens[i] = sizeof(struct sockaddr_in6); 829 saddrlens[i] = sizeof(struct sockaddr_in6);
829 saddrs[i] = GNUNET_malloc(saddrlens[i]); 830 saddrs[i] = GNUNET_malloc (saddrlens[i]);
830#if HAVE_SOCKADDR_IN_SIN_LEN 831#if HAVE_SOCKADDR_IN_SIN_LEN
831 ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; 832 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
832#endif 833#endif
833 ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; 834 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
834 ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); 835 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
835 i++; 836 i++;
836 saddrlens[i] = sizeof(struct sockaddr_in); 837 saddrlens[i] = sizeof(struct sockaddr_in);
837 saddrs[i] = GNUNET_malloc(saddrlens[i]); 838 saddrs[i] = GNUNET_malloc (saddrlens[i]);
838#if HAVE_SOCKADDR_IN_SIN_LEN 839#if HAVE_SOCKADDR_IN_SIN_LEN
839 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1]; 840 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
840#endif 841#endif
841 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; 842 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
842 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); 843 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
843 }
844 } 844 }
845 GNUNET_free_non_null(unixpath); 845 }
846 GNUNET_free_non_null (unixpath);
846 *addrs = saddrs; 847 *addrs = saddrs;
847 *addr_lens = saddrlens; 848 *addr_lens = saddrlens;
848 return resi; 849 return resi;
@@ -868,7 +869,7 @@ LEGACY_SERVICE_get_server_addresses(
868 * @return #GNUNET_OK if configuration succeeded 869 * @return #GNUNET_OK if configuration succeeded
869 */ 870 */
870static int 871static int
871setup_service(struct LEGACY_SERVICE_Context *sctx) 872setup_service (struct LEGACY_SERVICE_Context *sctx)
872{ 873{
873 struct GNUNET_TIME_Relative idleout; 874 struct GNUNET_TIME_Relative idleout;
874 int tolerant; 875 int tolerant;
@@ -876,91 +877,91 @@ setup_service(struct LEGACY_SERVICE_Context *sctx)
876 unsigned int cnt; 877 unsigned int cnt;
877 int flags; 878 int flags;
878 879
879 if (GNUNET_CONFIGURATION_have_value(sctx->cfg, 880 if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
880 sctx->service_name, 881 sctx->service_name,
881 "TIMEOUT")) 882 "TIMEOUT"))
883 {
884 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (sctx->cfg,
885 sctx->service_name,
886 "TIMEOUT",
887 &idleout))
882 { 888 {
883 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(sctx->cfg, 889 LOG (GNUNET_ERROR_TYPE_ERROR,
884 sctx->service_name, 890 _ ("Specified value for `%s' of service `%s' is invalid\n"),
885 "TIMEOUT", 891 "TIMEOUT",
886 &idleout)) 892 sctx->service_name);
887 { 893 return GNUNET_SYSERR;
888 LOG(GNUNET_ERROR_TYPE_ERROR,
889 _("Specified value for `%s' of service `%s' is invalid\n"),
890 "TIMEOUT",
891 sctx->service_name);
892 return GNUNET_SYSERR;
893 }
894 sctx->timeout = idleout;
895 } 894 }
895 sctx->timeout = idleout;
896 }
896 else 897 else
897 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 898 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
898 899
899 if (GNUNET_CONFIGURATION_have_value(sctx->cfg, 900 if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
900 sctx->service_name, 901 sctx->service_name,
901 "TOLERANT")) 902 "TOLERANT"))
903 {
904 if (GNUNET_SYSERR ==
905 (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
906 sctx->service_name,
907 "TOLERANT")))
902 { 908 {
903 if (GNUNET_SYSERR == 909 LOG (GNUNET_ERROR_TYPE_ERROR,
904 (tolerant = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, 910 _ ("Specified value for `%s' of service `%s' is invalid\n"),
905 sctx->service_name, 911 "TOLERANT",
906 "TOLERANT"))) 912 sctx->service_name);
907 { 913 return GNUNET_SYSERR;
908 LOG(GNUNET_ERROR_TYPE_ERROR,
909 _("Specified value for `%s' of service `%s' is invalid\n"),
910 "TOLERANT",
911 sctx->service_name);
912 return GNUNET_SYSERR;
913 }
914 } 914 }
915 }
915 else 916 else
916 tolerant = GNUNET_NO; 917 tolerant = GNUNET_NO;
917 918
918 errno = 0; 919 errno = 0;
919 if ((NULL != (nfds = getenv("LISTEN_FDS"))) && 920 if ((NULL != (nfds = getenv ("LISTEN_FDS"))) &&
920 (1 == sscanf(nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && 921 (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
921 (cnt + 4 < FD_SETSIZE)) 922 (cnt + 4 < FD_SETSIZE))
923 {
924 sctx->lsocks =
925 GNUNET_malloc (sizeof(struct GNUNET_NETWORK_Handle *) * (cnt + 1));
926 while (0 < cnt--)
922 { 927 {
923 sctx->lsocks = 928 flags = fcntl (3 + cnt, F_GETFD);
924 GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (cnt + 1)); 929 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
925 while (0 < cnt--) 930 (NULL ==
926 { 931 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
927 flags = fcntl(3 + cnt, F_GETFD); 932 {
928 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || 933 LOG (GNUNET_ERROR_TYPE_ERROR,
929 (NULL == 934 _ (
930 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native(3 + cnt)))) 935 "Could not access pre-bound socket %u, will try to bind myself\n"),
931 { 936 (unsigned int) 3 + cnt);
932 LOG(GNUNET_ERROR_TYPE_ERROR, 937 cnt++;
933 _( 938 while (sctx->lsocks[cnt] != NULL)
934 "Could not access pre-bound socket %u, will try to bind myself\n"), 939 GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++]));
935 (unsigned int)3 + cnt); 940 GNUNET_free (sctx->lsocks);
936 cnt++; 941 sctx->lsocks = NULL;
937 while (sctx->lsocks[cnt] != NULL) 942 break;
938 GNUNET_break(0 == GNUNET_NETWORK_socket_close(sctx->lsocks[cnt++])); 943 }
939 GNUNET_free(sctx->lsocks);
940 sctx->lsocks = NULL;
941 break;
942 }
943 }
944 unsetenv("LISTEN_FDS");
945 } 944 }
945 unsetenv ("LISTEN_FDS");
946 }
946 947
947 if ((NULL == sctx->lsocks) && 948 if ((NULL == sctx->lsocks) &&
948 (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses(sctx->service_name, 949 (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses (sctx->service_name,
949 sctx->cfg, 950 sctx->cfg,
950 &sctx->addrs, 951 &sctx->addrs,
951 &sctx->addrlens))) 952 &sctx->addrlens)))
952 return GNUNET_SYSERR; 953 return GNUNET_SYSERR;
953 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; 954 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
954 sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, 955 sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
955 sctx->service_name, 956 sctx->service_name,
956 "UNIX_MATCH_UID"); 957 "UNIX_MATCH_UID");
957 sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg, 958 sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
958 sctx->service_name, 959 sctx->service_name,
959 "UNIX_MATCH_GID"); 960 "UNIX_MATCH_GID");
960 process_acl4(&sctx->v4_denied, sctx, "REJECT_FROM"); 961 process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM");
961 process_acl4(&sctx->v4_allowed, sctx, "ACCEPT_FROM"); 962 process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM");
962 process_acl6(&sctx->v6_denied, sctx, "REJECT_FROM6"); 963 process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6");
963 process_acl6(&sctx->v6_allowed, sctx, "ACCEPT_FROM6"); 964 process_acl6 (&sctx->v6_allowed, sctx, "ACCEPT_FROM6");
964 965
965 return GNUNET_OK; 966 return GNUNET_OK;
966} 967}
@@ -974,14 +975,14 @@ setup_service(struct LEGACY_SERVICE_Context *sctx)
974 * @return value of the 'USERNAME' option 975 * @return value of the 'USERNAME' option
975 */ 976 */
976static char * 977static char *
977get_user_name(struct LEGACY_SERVICE_Context *sctx) 978get_user_name (struct LEGACY_SERVICE_Context *sctx)
978{ 979{
979 char *un; 980 char *un;
980 981
981 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(sctx->cfg, 982 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg,
982 sctx->service_name, 983 sctx->service_name,
983 "USERNAME", 984 "USERNAME",
984 &un)) 985 &un))
985 return NULL; 986 return NULL;
986 return un; 987 return un;
987} 988}
@@ -995,7 +996,7 @@ get_user_name(struct LEGACY_SERVICE_Context *sctx)
995 * @return #GNUNET_OK on success (including no work to be done) 996 * @return #GNUNET_OK on success (including no work to be done)
996 */ 997 */
997static int 998static int
998write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid) 999write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
999{ 1000{
1000 FILE *pidfd; 1001 FILE *pidfd;
1001 char *pif; 1002 char *pif;
@@ -1003,46 +1004,46 @@ write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1003 char *rdir; 1004 char *rdir;
1004 int len; 1005 int len;
1005 1006
1006 if (NULL == (pif = get_pid_file_name(sctx))) 1007 if (NULL == (pif = get_pid_file_name (sctx)))
1007 return GNUNET_OK; /* no file desired */ 1008 return GNUNET_OK; /* no file desired */
1008 user = get_user_name(sctx); 1009 user = get_user_name (sctx);
1009 rdir = GNUNET_strdup(pif); 1010 rdir = GNUNET_strdup (pif);
1010 len = strlen(rdir); 1011 len = strlen (rdir);
1011 while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) 1012 while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
1012 len--; 1013 len--;
1013 rdir[len] = '\0'; 1014 rdir[len] = '\0';
1014 if (0 != access(rdir, F_OK)) 1015 if (0 != access (rdir, F_OK))
1015 { 1016 {
1016 /* we get to create a directory -- and claim it 1017 /* we get to create a directory -- and claim it
1017 * as ours! */ 1018 * as ours! */
1018 (void)GNUNET_DISK_directory_create(rdir); 1019 (void) GNUNET_DISK_directory_create (rdir);
1019 if ((NULL != user) && (0 < strlen(user))) 1020 if ((NULL != user) && (0 < strlen (user)))
1020 GNUNET_DISK_file_change_owner(rdir, user); 1021 GNUNET_DISK_file_change_owner (rdir, user);
1021 } 1022 }
1022 if (0 != access(rdir, W_OK | X_OK)) 1023 if (0 != access (rdir, W_OK | X_OK))
1023 { 1024 {
1024 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "access", rdir); 1025 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
1025 GNUNET_free(rdir); 1026 GNUNET_free (rdir);
1026 GNUNET_free_non_null(user); 1027 GNUNET_free_non_null (user);
1027 GNUNET_free(pif); 1028 GNUNET_free (pif);
1028 return GNUNET_SYSERR; 1029 return GNUNET_SYSERR;
1029 } 1030 }
1030 GNUNET_free(rdir); 1031 GNUNET_free (rdir);
1031 pidfd = fopen(pif, "w"); 1032 pidfd = fopen (pif, "w");
1032 if (NULL == pidfd) 1033 if (NULL == pidfd)
1033 { 1034 {
1034 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "fopen", pif); 1035 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
1035 GNUNET_free(pif); 1036 GNUNET_free (pif);
1036 GNUNET_free_non_null(user); 1037 GNUNET_free_non_null (user);
1037 return GNUNET_SYSERR; 1038 return GNUNET_SYSERR;
1038 } 1039 }
1039 if (0 > fprintf(pidfd, "%u", pid)) 1040 if (0 > fprintf (pidfd, "%u", pid))
1040 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); 1041 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
1041 GNUNET_break(0 == fclose(pidfd)); 1042 GNUNET_break (0 == fclose (pidfd));
1042 if ((NULL != user) && (0 < strlen(user))) 1043 if ((NULL != user) && (0 < strlen (user)))
1043 GNUNET_DISK_file_change_owner(pif, user); 1044 GNUNET_DISK_file_change_owner (pif, user);
1044 GNUNET_free_non_null(user); 1045 GNUNET_free_non_null (user);
1045 GNUNET_free(pif); 1046 GNUNET_free (pif);
1046 return GNUNET_OK; 1047 return GNUNET_OK;
1047} 1048}
1048 1049
@@ -1053,16 +1054,16 @@ write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1053 * @param cls the `struct LEGACY_SERVICE_Context` 1054 * @param cls the `struct LEGACY_SERVICE_Context`
1054 */ 1055 */
1055static void 1056static void
1056shutdown_task(void *cls) 1057shutdown_task (void *cls)
1057{ 1058{
1058 struct LEGACY_SERVICE_Context *service = cls; 1059 struct LEGACY_SERVICE_Context *service = cls;
1059 struct GNUNET_SERVER_Handle *server = service->server; 1060 struct GNUNET_SERVER_Handle *server = service->server;
1060 1061
1061 service->shutdown_task = NULL; 1062 service->shutdown_task = NULL;
1062 if (0 != (service->options & LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN)) 1063 if (0 != (service->options & LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN))
1063 GNUNET_SERVER_stop_listening(server); 1064 GNUNET_SERVER_stop_listening (server);
1064 else 1065 else
1065 GNUNET_SERVER_destroy(server); 1066 GNUNET_SERVER_destroy (server);
1066} 1067}
1067 1068
1068 1069
@@ -1072,79 +1073,79 @@ shutdown_task(void *cls)
1072 * @param cls service context 1073 * @param cls service context
1073 */ 1074 */
1074static void 1075static void
1075service_task(void *cls) 1076service_task (void *cls)
1076{ 1077{
1077 struct LEGACY_SERVICE_Context *sctx = cls; 1078 struct LEGACY_SERVICE_Context *sctx = cls;
1078 unsigned int i; 1079 unsigned int i;
1079 1080
1080 GNUNET_RESOLVER_connect(sctx->cfg); 1081 GNUNET_RESOLVER_connect (sctx->cfg);
1081 if (NULL != sctx->lsocks) 1082 if (NULL != sctx->lsocks)
1082 sctx->server = GNUNET_SERVER_create_with_sockets(&check_access, 1083 sctx->server = GNUNET_SERVER_create_with_sockets (&check_access,
1083 sctx, 1084 sctx,
1084 sctx->lsocks, 1085 sctx->lsocks,
1085 sctx->timeout, 1086 sctx->timeout,
1086 sctx->require_found); 1087 sctx->require_found);
1087 else 1088 else
1088 sctx->server = GNUNET_SERVER_create(&check_access, 1089 sctx->server = GNUNET_SERVER_create (&check_access,
1089 sctx, 1090 sctx,
1090 sctx->addrs, 1091 sctx->addrs,
1091 sctx->addrlens, 1092 sctx->addrlens,
1092 sctx->timeout, 1093 sctx->timeout,
1093 sctx->require_found); 1094 sctx->require_found);
1094 if (NULL == sctx->server) 1095 if (NULL == sctx->server)
1095 { 1096 {
1096 if (NULL != sctx->addrs) 1097 if (NULL != sctx->addrs)
1097 for (i = 0; NULL != sctx->addrs[i]; i++) 1098 for (i = 0; NULL != sctx->addrs[i]; i++)
1098 LOG(GNUNET_ERROR_TYPE_INFO, 1099 LOG (GNUNET_ERROR_TYPE_INFO,
1099 _("Failed to start `%s' at `%s'\n"), 1100 _ ("Failed to start `%s' at `%s'\n"),
1100 sctx->service_name, 1101 sctx->service_name,
1101 GNUNET_a2s(sctx->addrs[i], sctx->addrlens[i])); 1102 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1102 sctx->ret = GNUNET_SYSERR; 1103 sctx->ret = GNUNET_SYSERR;
1103 return; 1104 return;
1104 } 1105 }
1105 1106
1106 if (NULL != sctx->addrs) 1107 if (NULL != sctx->addrs)
1107 for (i = 0; NULL != sctx->addrs[i]; i++) 1108 for (i = 0; NULL != sctx->addrs[i]; i++)
1108 if ((AF_UNIX == sctx->addrs[i]->sa_family) && 1109 if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
1109 ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) 1110 ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0]))
1110 GNUNET_DISK_fix_permissions(((const struct sockaddr_un *) 1111 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)
1111 sctx->addrs[i]) 1112 sctx->addrs[i])
1112 ->sun_path, 1113 ->sun_path,
1113 sctx->match_uid, 1114 sctx->match_uid,
1114 sctx->match_gid); 1115 sctx->match_gid);
1115 1116
1116 if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN)) 1117 if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN))
1117 { 1118 {
1118 /* install a task that will kill the server 1119 /* install a task that will kill the server
1119 * process if the scheduler ever gets a shutdown signal */ 1120 * process if the scheduler ever gets a shutdown signal */
1120 sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown(&shutdown_task, sctx); 1121 sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, sctx);
1121 } 1122 }
1122 sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers)); 1123 sctx->my_handlers = GNUNET_malloc (sizeof(defhandlers));
1123 GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers)); 1124 GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof(defhandlers));
1124 i = 0; 1125 i = 0;
1125 while (NULL != sctx->my_handlers[i].callback) 1126 while (NULL != sctx->my_handlers[i].callback)
1126 sctx->my_handlers[i++].callback_cls = sctx; 1127 sctx->my_handlers[i++].callback_cls = sctx;
1127 GNUNET_SERVER_add_handlers(sctx->server, sctx->my_handlers); 1128 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
1128 if (-1 != sctx->ready_confirm_fd) 1129 if (-1 != sctx->ready_confirm_fd)
1129 { 1130 {
1130 GNUNET_break(1 == write(sctx->ready_confirm_fd, ".", 1)); 1131 GNUNET_break (1 == write (sctx->ready_confirm_fd, ".", 1));
1131 GNUNET_break(0 == close(sctx->ready_confirm_fd)); 1132 GNUNET_break (0 == close (sctx->ready_confirm_fd));
1132 sctx->ready_confirm_fd = -1; 1133 sctx->ready_confirm_fd = -1;
1133 write_pid_file(sctx, getpid()); 1134 write_pid_file (sctx, getpid ());
1134 } 1135 }
1135 if (NULL != sctx->addrs) 1136 if (NULL != sctx->addrs)
1137 {
1138 i = 0;
1139 while (NULL != sctx->addrs[i])
1136 { 1140 {
1137 i = 0; 1141 LOG (GNUNET_ERROR_TYPE_INFO,
1138 while (NULL != sctx->addrs[i]) 1142 _ ("Service `%s' runs at %s\n"),
1139 { 1143 sctx->service_name,
1140 LOG(GNUNET_ERROR_TYPE_INFO, 1144 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1141 _("Service `%s' runs at %s\n"), 1145 i++;
1142 sctx->service_name,
1143 GNUNET_a2s(sctx->addrs[i], sctx->addrlens[i]));
1144 i++;
1145 }
1146 } 1146 }
1147 sctx->task(sctx->task_cls, sctx->server, sctx->cfg); 1147 }
1148 sctx->task (sctx->task_cls, sctx->server, sctx->cfg);
1148} 1149}
1149 1150
1150 1151
@@ -1155,73 +1156,73 @@ service_task(void *cls)
1155 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1156 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1156 */ 1157 */
1157static int 1158static int
1158detach_terminal(struct LEGACY_SERVICE_Context *sctx) 1159detach_terminal (struct LEGACY_SERVICE_Context *sctx)
1159{ 1160{
1160 pid_t pid; 1161 pid_t pid;
1161 int nullfd; 1162 int nullfd;
1162 int filedes[2]; 1163 int filedes[2];
1163 1164
1164 if (0 != pipe(filedes)) 1165 if (0 != pipe (filedes))
1165 { 1166 {
1166 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "pipe"); 1167 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
1167 return GNUNET_SYSERR; 1168 return GNUNET_SYSERR;
1168 } 1169 }
1169 pid = fork(); 1170 pid = fork ();
1170 if (pid < 0) 1171 if (pid < 0)
1171 { 1172 {
1172 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "fork"); 1173 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
1173 return GNUNET_SYSERR; 1174 return GNUNET_SYSERR;
1174 } 1175 }
1175 if (0 != pid) 1176 if (0 != pid)
1177 {
1178 /* Parent */
1179 char c;
1180
1181 GNUNET_break (0 == close (filedes[1]));
1182 c = 'X';
1183 if (1 != read (filedes[0], &c, sizeof(char)))
1184 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
1185 fflush (stdout);
1186 switch (c)
1176 { 1187 {
1177 /* Parent */ 1188 case '.':
1178 char c; 1189 exit (0);
1179 1190
1180 GNUNET_break(0 == close(filedes[1])); 1191 case 'I':
1181 c = 'X'; 1192 LOG (GNUNET_ERROR_TYPE_INFO,
1182 if (1 != read(filedes[0], &c, sizeof(char))) 1193 _ ("Service process failed to initialize\n"));
1183 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "read"); 1194 break;
1184 fflush(stdout); 1195
1185 switch (c) 1196 case 'S':
1186 { 1197 LOG (GNUNET_ERROR_TYPE_INFO,
1187 case '.': 1198 _ ("Service process could not initialize server function\n"));
1188 exit(0); 1199 break;
1189 1200
1190 case 'I': 1201 case 'X':
1191 LOG(GNUNET_ERROR_TYPE_INFO, 1202 LOG (GNUNET_ERROR_TYPE_INFO,
1192 _("Service process failed to initialize\n")); 1203 _ ("Service process failed to report status\n"));
1193 break; 1204 break;
1194
1195 case 'S':
1196 LOG(GNUNET_ERROR_TYPE_INFO,
1197 _("Service process could not initialize server function\n"));
1198 break;
1199
1200 case 'X':
1201 LOG(GNUNET_ERROR_TYPE_INFO,
1202 _("Service process failed to report status\n"));
1203 break;
1204 }
1205 exit(1); /* child reported error */
1206 } 1205 }
1207 GNUNET_break(0 == close(0)); 1206 exit (1); /* child reported error */
1208 GNUNET_break(0 == close(1)); 1207 }
1209 GNUNET_break(0 == close(filedes[0])); 1208 GNUNET_break (0 == close (0));
1210 nullfd = open("/dev/null", O_RDWR | O_APPEND); 1209 GNUNET_break (0 == close (1));
1210 GNUNET_break (0 == close (filedes[0]));
1211 nullfd = open ("/dev/null", O_RDWR | O_APPEND);
1211 if (nullfd < 0) 1212 if (nullfd < 0)
1212 return GNUNET_SYSERR; 1213 return GNUNET_SYSERR;
1213 /* set stdin/stdout to /dev/null */ 1214 /* set stdin/stdout to /dev/null */
1214 if ((dup2(nullfd, 0) < 0) || (dup2(nullfd, 1) < 0)) 1215 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
1215 { 1216 {
1216 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "dup2"); 1217 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
1217 (void)close(nullfd); 1218 (void) close (nullfd);
1218 return GNUNET_SYSERR; 1219 return GNUNET_SYSERR;
1219 } 1220 }
1220 (void)close(nullfd); 1221 (void) close (nullfd);
1221 /* Detach from controlling terminal */ 1222 /* Detach from controlling terminal */
1222 pid = setsid(); 1223 pid = setsid ();
1223 if (-1 == pid) 1224 if (-1 == pid)
1224 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "setsid"); 1225 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid");
1225 sctx->ready_confirm_fd = filedes[1]; 1226 sctx->ready_confirm_fd = filedes[1];
1226 1227
1227 return GNUNET_OK; 1228 return GNUNET_OK;
@@ -1235,45 +1236,45 @@ detach_terminal(struct LEGACY_SERVICE_Context *sctx)
1235 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1236 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1236 */ 1237 */
1237static int 1238static int
1238set_user_id(struct LEGACY_SERVICE_Context *sctx) 1239set_user_id (struct LEGACY_SERVICE_Context *sctx)
1239{ 1240{
1240 char *user; 1241 char *user;
1241 1242
1242 if (NULL == (user = get_user_name(sctx))) 1243 if (NULL == (user = get_user_name (sctx)))
1243 return GNUNET_OK; /* keep */ 1244 return GNUNET_OK; /* keep */
1244 1245
1245 struct passwd *pws; 1246 struct passwd *pws;
1246 1247
1247 errno = 0; 1248 errno = 0;
1248 pws = getpwnam(user); 1249 pws = getpwnam (user);
1249 if (NULL == pws) 1250 if (NULL == pws)
1250 { 1251 {
1251 LOG(GNUNET_ERROR_TYPE_ERROR, 1252 LOG (GNUNET_ERROR_TYPE_ERROR,
1252 _("Cannot obtain information about user `%s': %s\n"), 1253 _ ("Cannot obtain information about user `%s': %s\n"),
1253 user, 1254 user,
1254 errno == 0 ? _("No such user") : strerror(errno)); 1255 errno == 0 ? _ ("No such user") : strerror (errno));
1255 GNUNET_free(user); 1256 GNUNET_free (user);
1256 return GNUNET_SYSERR; 1257 return GNUNET_SYSERR;
1257 } 1258 }
1258 if ((0 != setgid(pws->pw_gid)) || (0 != setegid(pws->pw_gid)) || 1259 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
1259#if HAVE_INITGROUPS 1260#if HAVE_INITGROUPS
1260 (0 != initgroups(user, pws->pw_gid)) || 1261 (0 != initgroups (user, pws->pw_gid)) ||
1261#endif 1262#endif
1262 (0 != setuid(pws->pw_uid)) || (0 != seteuid(pws->pw_uid))) 1263 (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
1264 {
1265 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1266 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1263 { 1267 {
1264 if ((0 != setregid(pws->pw_gid, pws->pw_gid)) || 1268 LOG (GNUNET_ERROR_TYPE_ERROR,
1265 (0 != setreuid(pws->pw_uid, pws->pw_uid))) 1269 _ ("Cannot change user/group to `%s': %s\n"),
1266 { 1270 user,
1267 LOG(GNUNET_ERROR_TYPE_ERROR, 1271 strerror (errno));
1268 _("Cannot change user/group to `%s': %s\n"), 1272 GNUNET_free (user);
1269 user, 1273 return GNUNET_SYSERR;
1270 strerror(errno));
1271 GNUNET_free(user);
1272 return GNUNET_SYSERR;
1273 }
1274 } 1274 }
1275 }
1275 1276
1276 GNUNET_free(user); 1277 GNUNET_free (user);
1277 return GNUNET_OK; 1278 return GNUNET_OK;
1278} 1279}
1279 1280
@@ -1284,15 +1285,15 @@ set_user_id(struct LEGACY_SERVICE_Context *sctx)
1284 * @param sctx service context 1285 * @param sctx service context
1285 */ 1286 */
1286static void 1287static void
1287pid_file_delete(struct LEGACY_SERVICE_Context *sctx) 1288pid_file_delete (struct LEGACY_SERVICE_Context *sctx)
1288{ 1289{
1289 char *pif = get_pid_file_name(sctx); 1290 char *pif = get_pid_file_name (sctx);
1290 1291
1291 if (NULL == pif) 1292 if (NULL == pif)
1292 return; /* no PID file */ 1293 return; /* no PID file */
1293 if (0 != unlink(pif)) 1294 if (0 != unlink (pif))
1294 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "unlink", pif); 1295 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
1295 GNUNET_free(pif); 1296 GNUNET_free (pif);
1296} 1297}
1297 1298
1298 1299
@@ -1310,19 +1311,19 @@ pid_file_delete(struct LEGACY_SERVICE_Context *sctx)
1310 * if we shutdown nicely 1311 * if we shutdown nicely
1311 */ 1312 */
1312int 1313int
1313LEGACY_SERVICE_run(int argc, 1314LEGACY_SERVICE_run (int argc,
1314 char *const *argv, 1315 char *const *argv,
1315 const char *service_name, 1316 const char *service_name,
1316 enum LEGACY_SERVICE_Options options, 1317 enum LEGACY_SERVICE_Options options,
1317 LEGACY_SERVICE_Main task, 1318 LEGACY_SERVICE_Main task,
1318 void *task_cls) 1319 void *task_cls)
1319{ 1320{
1320#define HANDLE_ERROR \ 1321#define HANDLE_ERROR \
1321 do \ 1322 do \
1322 { \ 1323 { \
1323 GNUNET_break(0); \ 1324 GNUNET_break (0); \
1324 goto shutdown; \ 1325 goto shutdown; \
1325 } while (0) 1326 } while (0)
1326 1327
1327 int err; 1328 int err;
1328 int ret; 1329 int ret;
@@ -1340,32 +1341,32 @@ LEGACY_SERVICE_run(int argc,
1340 const char *xdg; 1341 const char *xdg;
1341 1342
1342 struct GNUNET_GETOPT_CommandLineOption service_options[] = 1343 struct GNUNET_GETOPT_CommandLineOption service_options[] =
1343 { GNUNET_GETOPT_option_cfgfile(&opt_cfg_fn), 1344 { GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn),
1344 GNUNET_GETOPT_option_flag('d', 1345 GNUNET_GETOPT_option_flag ('d',
1345 "daemonize", 1346 "daemonize",
1346 gettext_noop( 1347 gettext_noop (
1347 "do daemonize (detach from terminal)"), 1348 "do daemonize (detach from terminal)"),
1348 &do_daemonize), 1349 &do_daemonize),
1349 GNUNET_GETOPT_option_help(NULL), 1350 GNUNET_GETOPT_option_help (NULL),
1350 GNUNET_GETOPT_option_loglevel(&loglev), 1351 GNUNET_GETOPT_option_loglevel (&loglev),
1351 GNUNET_GETOPT_option_logfile(&logfile), 1352 GNUNET_GETOPT_option_logfile (&logfile),
1352 GNUNET_GETOPT_option_version(PACKAGE_VERSION " " VCS_VERSION), 1353 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
1353 GNUNET_GETOPT_OPTION_END }; 1354 GNUNET_GETOPT_OPTION_END };
1354 err = 1; 1355 err = 1;
1355 do_daemonize = 0; 1356 do_daemonize = 0;
1356 logfile = NULL; 1357 logfile = NULL;
1357 loglev = NULL; 1358 loglev = NULL;
1358 opt_cfg_fn = NULL; 1359 opt_cfg_fn = NULL;
1359 xdg = getenv("XDG_CONFIG_HOME"); 1360 xdg = getenv ("XDG_CONFIG_HOME");
1360 if (NULL != xdg) 1361 if (NULL != xdg)
1361 GNUNET_asprintf(&cfg_fn, 1362 GNUNET_asprintf (&cfg_fn,
1362 "%s%s%s", 1363 "%s%s%s",
1363 xdg, 1364 xdg,
1364 DIR_SEPARATOR_STR, 1365 DIR_SEPARATOR_STR,
1365 GNUNET_OS_project_data_get()->config_file); 1366 GNUNET_OS_project_data_get ()->config_file);
1366 else 1367 else
1367 cfg_fn = GNUNET_strdup(GNUNET_OS_project_data_get()->user_config_file); 1368 cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
1368 memset(&sctx, 0, sizeof(sctx)); 1369 memset (&sctx, 0, sizeof(sctx));
1369 sctx.options = options; 1370 sctx.options = options;
1370 sctx.ready_confirm_fd = -1; 1371 sctx.ready_confirm_fd = -1;
1371 sctx.ret = GNUNET_OK; 1372 sctx.ret = GNUNET_OK;
@@ -1373,117 +1374,117 @@ LEGACY_SERVICE_run(int argc,
1373 sctx.task = task; 1374 sctx.task = task;
1374 sctx.task_cls = task_cls; 1375 sctx.task_cls = task_cls;
1375 sctx.service_name = service_name; 1376 sctx.service_name = service_name;
1376 sctx.cfg = cfg = GNUNET_CONFIGURATION_create(); 1377 sctx.cfg = cfg = GNUNET_CONFIGURATION_create ();
1377 1378
1378 /* setup subsystems */ 1379 /* setup subsystems */
1379 ret = GNUNET_GETOPT_run(service_name, service_options, argc, argv); 1380 ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv);
1380 if (GNUNET_SYSERR == ret) 1381 if (GNUNET_SYSERR == ret)
1381 goto shutdown; 1382 goto shutdown;
1382 if (GNUNET_NO == ret) 1383 if (GNUNET_NO == ret)
1383 { 1384 {
1384 err = 0; 1385 err = 0;
1385 goto shutdown; 1386 goto shutdown;
1386 } 1387 }
1387 if (GNUNET_OK != GNUNET_log_setup(service_name, loglev, logfile)) 1388 if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile))
1388 HANDLE_ERROR; 1389 HANDLE_ERROR;
1389 if (NULL == opt_cfg_fn) 1390 if (NULL == opt_cfg_fn)
1390 opt_cfg_fn = GNUNET_strdup(cfg_fn); 1391 opt_cfg_fn = GNUNET_strdup (cfg_fn);
1391 if (GNUNET_YES == GNUNET_DISK_file_test(opt_cfg_fn)) 1392 if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_fn))
1393 {
1394 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn))
1392 { 1395 {
1393 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, opt_cfg_fn)) 1396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1394 { 1397 _ ("Malformed configuration file `%s', exit ...\n"),
1395 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1398 opt_cfg_fn);
1396 _("Malformed configuration file `%s', exit ...\n"), 1399 goto shutdown;
1397 opt_cfg_fn);
1398 goto shutdown;
1399 }
1400 } 1400 }
1401 }
1401 else 1402 else
1403 {
1404 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
1402 { 1405 {
1403 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, NULL)) 1406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1404 { 1407 _ ("Malformed configuration, exit ...\n"));
1405 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1408 goto shutdown;
1406 _("Malformed configuration, exit ...\n"));
1407 goto shutdown;
1408 }
1409 if (0 != strcmp(opt_cfg_fn, cfg_fn))
1410 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1411 _("Could not access configuration file `%s'\n"),
1412 opt_cfg_fn);
1413 } 1409 }
1414 if (GNUNET_OK != setup_service(&sctx)) 1410 if (0 != strcmp (opt_cfg_fn, cfg_fn))
1411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1412 _ ("Could not access configuration file `%s'\n"),
1413 opt_cfg_fn);
1414 }
1415 if (GNUNET_OK != setup_service (&sctx))
1415 goto shutdown; 1416 goto shutdown;
1416 if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal(&sctx))) 1417 if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sctx)))
1417 HANDLE_ERROR; 1418 HANDLE_ERROR;
1418 if (GNUNET_OK != set_user_id(&sctx)) 1419 if (GNUNET_OK != set_user_id (&sctx))
1419 goto shutdown; 1420 goto shutdown;
1420 LOG(GNUNET_ERROR_TYPE_DEBUG, 1421 LOG (GNUNET_ERROR_TYPE_DEBUG,
1421 "Service `%s' runs with configuration from `%s'\n", 1422 "Service `%s' runs with configuration from `%s'\n",
1422 service_name, 1423 service_name,
1423 opt_cfg_fn); 1424 opt_cfg_fn);
1424 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, 1425 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg,
1425 "TESTING", 1426 "TESTING",
1426 "SKEW_OFFSET", 1427 "SKEW_OFFSET",
1427 &skew_offset)) && 1428 &skew_offset)) &&
1428 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, 1429 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg,
1429 "TESTING", 1430 "TESTING",
1430 "SKEW_VARIANCE", 1431 "SKEW_VARIANCE",
1431 &skew_variance))) 1432 &skew_variance)))
1432 { 1433 {
1433 clock_offset = skew_offset - skew_variance; 1434 clock_offset = skew_offset - skew_variance;
1434 GNUNET_TIME_set_offset(clock_offset); 1435 GNUNET_TIME_set_offset (clock_offset);
1435 LOG(GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); 1436 LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset);
1436 } 1437 }
1437 /* actually run service */ 1438 /* actually run service */
1438 err = 0; 1439 err = 0;
1439 GNUNET_SCHEDULER_run(&service_task, &sctx); 1440 GNUNET_SCHEDULER_run (&service_task, &sctx);
1440 /* shutdown */ 1441 /* shutdown */
1441 if ((1 == do_daemonize) && (NULL != sctx.server)) 1442 if ((1 == do_daemonize) && (NULL != sctx.server))
1442 pid_file_delete(&sctx); 1443 pid_file_delete (&sctx);
1443 GNUNET_free_non_null(sctx.my_handlers); 1444 GNUNET_free_non_null (sctx.my_handlers);
1444 1445
1445shutdown: 1446shutdown:
1446 if (-1 != sctx.ready_confirm_fd) 1447 if (-1 != sctx.ready_confirm_fd)
1447 { 1448 {
1448 if (1 != write(sctx.ready_confirm_fd, err ? "I" : "S", 1)) 1449 if (1 != write (sctx.ready_confirm_fd, err ? "I" : "S", 1))
1449 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "write"); 1450 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
1450 GNUNET_break(0 == close(sctx.ready_confirm_fd)); 1451 GNUNET_break (0 == close (sctx.ready_confirm_fd));
1451 } 1452 }
1452#if HAVE_MALLINFO 1453#if HAVE_MALLINFO
1453 { 1454 {
1454 char *counter; 1455 char *counter;
1455 1456
1456 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value(sctx.cfg, 1457 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg,
1457 service_name, 1458 service_name,
1458 "GAUGER_HEAP")) && 1459 "GAUGER_HEAP")) &&
1459 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(sctx.cfg, 1460 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg,
1460 service_name, 1461 service_name,
1461 "GAUGER_HEAP", 1462 "GAUGER_HEAP",
1462 &counter))) 1463 &counter)))
1463 { 1464 {
1464 struct mallinfo mi; 1465 struct mallinfo mi;
1465 1466
1466 mi = mallinfo(); 1467 mi = mallinfo ();
1467 GAUGER(service_name, counter, mi.usmblks, "blocks"); 1468 GAUGER (service_name, counter, mi.usmblks, "blocks");
1468 GNUNET_free(counter); 1469 GNUNET_free (counter);
1469 } 1470 }
1470 } 1471 }
1471#endif 1472#endif
1472 GNUNET_CONFIGURATION_destroy(cfg); 1473 GNUNET_CONFIGURATION_destroy (cfg);
1473 i = 0; 1474 i = 0;
1474 if (NULL != sctx.addrs) 1475 if (NULL != sctx.addrs)
1475 while (NULL != sctx.addrs[i]) 1476 while (NULL != sctx.addrs[i])
1476 GNUNET_free(sctx.addrs[i++]); 1477 GNUNET_free (sctx.addrs[i++]);
1477 GNUNET_free_non_null(sctx.addrs); 1478 GNUNET_free_non_null (sctx.addrs);
1478 GNUNET_free_non_null(sctx.addrlens); 1479 GNUNET_free_non_null (sctx.addrlens);
1479 GNUNET_free_non_null(logfile); 1480 GNUNET_free_non_null (logfile);
1480 GNUNET_free_non_null(loglev); 1481 GNUNET_free_non_null (loglev);
1481 GNUNET_free(cfg_fn); 1482 GNUNET_free (cfg_fn);
1482 GNUNET_free_non_null(opt_cfg_fn); 1483 GNUNET_free_non_null (opt_cfg_fn);
1483 GNUNET_free_non_null(sctx.v4_denied); 1484 GNUNET_free_non_null (sctx.v4_denied);
1484 GNUNET_free_non_null(sctx.v6_denied); 1485 GNUNET_free_non_null (sctx.v6_denied);
1485 GNUNET_free_non_null(sctx.v4_allowed); 1486 GNUNET_free_non_null (sctx.v4_allowed);
1486 GNUNET_free_non_null(sctx.v6_allowed); 1487 GNUNET_free_non_null (sctx.v6_allowed);
1487 1488
1488 return err ? GNUNET_SYSERR : sctx.ret; 1489 return err ? GNUNET_SYSERR : sctx.ret;
1489} 1490}
@@ -1499,14 +1500,14 @@ shutdown:
1499 * @return NULL on error, service handle 1500 * @return NULL on error, service handle
1500 */ 1501 */
1501struct LEGACY_SERVICE_Context * 1502struct LEGACY_SERVICE_Context *
1502LEGACY_SERVICE_start(const char *service_name, 1503LEGACY_SERVICE_start (const char *service_name,
1503 const struct GNUNET_CONFIGURATION_Handle *cfg, 1504 const struct GNUNET_CONFIGURATION_Handle *cfg,
1504 enum LEGACY_SERVICE_Options options) 1505 enum LEGACY_SERVICE_Options options)
1505{ 1506{
1506 int i; 1507 int i;
1507 struct LEGACY_SERVICE_Context *sctx; 1508 struct LEGACY_SERVICE_Context *sctx;
1508 1509
1509 sctx = GNUNET_new(struct LEGACY_SERVICE_Context); 1510 sctx = GNUNET_new (struct LEGACY_SERVICE_Context);
1510 sctx->ready_confirm_fd = -1; /* no daemonizing */ 1511 sctx->ready_confirm_fd = -1; /* no daemonizing */
1511 sctx->ret = GNUNET_OK; 1512 sctx->ret = GNUNET_OK;
1512 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1513 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -1515,47 +1516,47 @@ LEGACY_SERVICE_start(const char *service_name,
1515 sctx->options = options; 1516 sctx->options = options;
1516 1517
1517 /* setup subsystems */ 1518 /* setup subsystems */
1518 if (GNUNET_OK != setup_service(sctx)) 1519 if (GNUNET_OK != setup_service (sctx))
1519 { 1520 {
1520 LEGACY_SERVICE_stop(sctx); 1521 LEGACY_SERVICE_stop (sctx);
1521 return NULL; 1522 return NULL;
1522 } 1523 }
1523 if (NULL != sctx->lsocks) 1524 if (NULL != sctx->lsocks)
1524 sctx->server = GNUNET_SERVER_create_with_sockets(&check_access, 1525 sctx->server = GNUNET_SERVER_create_with_sockets (&check_access,
1525 sctx, 1526 sctx,
1526 sctx->lsocks, 1527 sctx->lsocks,
1527 sctx->timeout, 1528 sctx->timeout,
1528 sctx->require_found); 1529 sctx->require_found);
1529 else 1530 else
1530 sctx->server = GNUNET_SERVER_create(&check_access, 1531 sctx->server = GNUNET_SERVER_create (&check_access,
1531 sctx, 1532 sctx,
1532 sctx->addrs, 1533 sctx->addrs,
1533 sctx->addrlens, 1534 sctx->addrlens,
1534 sctx->timeout, 1535 sctx->timeout,
1535 sctx->require_found); 1536 sctx->require_found);
1536 1537
1537 if (NULL == sctx->server) 1538 if (NULL == sctx->server)
1538 { 1539 {
1539 LEGACY_SERVICE_stop(sctx); 1540 LEGACY_SERVICE_stop (sctx);
1540 return NULL; 1541 return NULL;
1541 } 1542 }
1542 1543
1543 if (NULL != sctx->addrs) 1544 if (NULL != sctx->addrs)
1544 for (i = 0; NULL != sctx->addrs[i]; i++) 1545 for (i = 0; NULL != sctx->addrs[i]; i++)
1545 if ((AF_UNIX == sctx->addrs[i]->sa_family) && 1546 if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
1546 ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) 1547 ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0]))
1547 GNUNET_DISK_fix_permissions(((const struct sockaddr_un *) 1548 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)
1548 sctx->addrs[i]) 1549 sctx->addrs[i])
1549 ->sun_path, 1550 ->sun_path,
1550 sctx->match_uid, 1551 sctx->match_uid,
1551 sctx->match_gid); 1552 sctx->match_gid);
1552 1553
1553 sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers)); 1554 sctx->my_handlers = GNUNET_malloc (sizeof(defhandlers));
1554 GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers)); 1555 GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof(defhandlers));
1555 i = 0; 1556 i = 0;
1556 while ((sctx->my_handlers[i].callback != NULL)) 1557 while ((sctx->my_handlers[i].callback != NULL))
1557 sctx->my_handlers[i++].callback_cls = sctx; 1558 sctx->my_handlers[i++].callback_cls = sctx;
1558 GNUNET_SERVER_add_handlers(sctx->server, sctx->my_handlers); 1559 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
1559 return sctx; 1560 return sctx;
1560} 1561}
1561 1562
@@ -1568,7 +1569,7 @@ LEGACY_SERVICE_start(const char *service_name,
1568 * @return handle to the server for this service, NULL if there is none 1569 * @return handle to the server for this service, NULL if there is none
1569 */ 1570 */
1570struct GNUNET_SERVER_Handle * 1571struct GNUNET_SERVER_Handle *
1571LEGACY_SERVICE_get_server(struct LEGACY_SERVICE_Context *ctx) 1572LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx)
1572{ 1573{
1573 return ctx->server; 1574 return ctx->server;
1574} 1575}
@@ -1582,7 +1583,7 @@ LEGACY_SERVICE_get_server(struct LEGACY_SERVICE_Context *ctx)
1582 * array of listen sockets. 1583 * array of listen sockets.
1583 */ 1584 */
1584struct GNUNET_NETWORK_Handle *const * 1585struct GNUNET_NETWORK_Handle *const *
1585LEGACY_SERVICE_get_listen_sockets(struct LEGACY_SERVICE_Context *ctx) 1586LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx)
1586{ 1587{
1587 return ctx->lsocks; 1588 return ctx->lsocks;
1588} 1589}
@@ -1594,7 +1595,7 @@ LEGACY_SERVICE_get_listen_sockets(struct LEGACY_SERVICE_Context *ctx)
1594 * @param sctx the service context returned from the start function 1595 * @param sctx the service context returned from the start function
1595 */ 1596 */
1596void 1597void
1597LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *sctx) 1598LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx)
1598{ 1599{
1599 unsigned int i; 1600 unsigned int i;
1600 1601
@@ -1602,43 +1603,43 @@ LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *sctx)
1602 { 1603 {
1603 char *counter; 1604 char *counter;
1604 1605
1605 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value(sctx->cfg, 1606 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx->cfg,
1606 sctx->service_name, 1607 sctx->service_name,
1607 "GAUGER_HEAP")) && 1608 "GAUGER_HEAP")) &&
1608 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(sctx->cfg, 1609 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
1609 sctx->service_name, 1610 sctx->service_name,
1610 "GAUGER_HEAP", 1611 "GAUGER_HEAP",
1611 &counter))) 1612 &counter)))
1612 { 1613 {
1613 struct mallinfo mi; 1614 struct mallinfo mi;
1614 1615
1615 mi = mallinfo(); 1616 mi = mallinfo ();
1616 GAUGER(sctx->service_name, counter, mi.usmblks, "blocks"); 1617 GAUGER (sctx->service_name, counter, mi.usmblks, "blocks");
1617 GNUNET_free(counter); 1618 GNUNET_free (counter);
1618 } 1619 }
1619 } 1620 }
1620#endif 1621#endif
1621 if (NULL != sctx->shutdown_task) 1622 if (NULL != sctx->shutdown_task)
1622 { 1623 {
1623 GNUNET_SCHEDULER_cancel(sctx->shutdown_task); 1624 GNUNET_SCHEDULER_cancel (sctx->shutdown_task);
1624 sctx->shutdown_task = NULL; 1625 sctx->shutdown_task = NULL;
1625 } 1626 }
1626 if (NULL != sctx->server) 1627 if (NULL != sctx->server)
1627 GNUNET_SERVER_destroy(sctx->server); 1628 GNUNET_SERVER_destroy (sctx->server);
1628 GNUNET_free_non_null(sctx->my_handlers); 1629 GNUNET_free_non_null (sctx->my_handlers);
1629 if (NULL != sctx->addrs) 1630 if (NULL != sctx->addrs)
1630 { 1631 {
1631 i = 0; 1632 i = 0;
1632 while (NULL != sctx->addrs[i]) 1633 while (NULL != sctx->addrs[i])
1633 GNUNET_free(sctx->addrs[i++]); 1634 GNUNET_free (sctx->addrs[i++]);
1634 GNUNET_free(sctx->addrs); 1635 GNUNET_free (sctx->addrs);
1635 } 1636 }
1636 GNUNET_free_non_null(sctx->addrlens); 1637 GNUNET_free_non_null (sctx->addrlens);
1637 GNUNET_free_non_null(sctx->v4_denied); 1638 GNUNET_free_non_null (sctx->v4_denied);
1638 GNUNET_free_non_null(sctx->v6_denied); 1639 GNUNET_free_non_null (sctx->v6_denied);
1639 GNUNET_free_non_null(sctx->v4_allowed); 1640 GNUNET_free_non_null (sctx->v4_allowed);
1640 GNUNET_free_non_null(sctx->v6_allowed); 1641 GNUNET_free_non_null (sctx->v6_allowed);
1641 GNUNET_free(sctx); 1642 GNUNET_free (sctx);
1642} 1643}
1643 1644
1644 1645
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 @@
33#include <inttypes.h> 33#include <inttypes.h>
34 34
35 35
36#define LOG(kind, ...) GNUNET_log_from(kind, "test_transport_communicator_unix", __VA_ARGS__) 36#define LOG(kind, ...) GNUNET_log_from (kind, \
37 "test_transport_communicator_unix", \
38 __VA_ARGS__)
37 39
38#define NUM_PEERS 2 40#define NUM_PEERS 2
39 41
40static struct GNUNET_PeerIdentity peer_id[NUM_PEERS]; 42static struct GNUNET_PeerIdentity peer_id[NUM_PEERS];
41 43
42static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS]; 44static struct
45GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS];
43 46
44//static char *addresses[NUM_PEERS]; 47// static char *addresses[NUM_PEERS];
45 48
46 49
47#define PAYLOAD_SIZE 256 50#define PAYLOAD_SIZE 256
48 51
49//static char payload[PAYLOAD_SIZE] = "TEST PAYLOAD"; 52// static char payload[PAYLOAD_SIZE] = "TEST PAYLOAD";
50//static char payload[] = "TEST PAYLOAD"; 53// static char payload[] = "TEST PAYLOAD";
51static uint32_t payload = 42; 54static uint32_t payload = 42;
52 55
53 56
54static void 57static void
55communicator_available_cb(void *cls, 58communicator_available_cb (void *cls,
56 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 59 struct
57 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, 60 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
58 char *address_prefix) 61 *tc_h,
62 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
63 char *address_prefix)
59{ 64{
60 LOG(GNUNET_ERROR_TYPE_DEBUG, 65 LOG (GNUNET_ERROR_TYPE_DEBUG,
61 "Communicator available. (cc: %u, prefix: %s)\n", 66 "Communicator available. (cc: %u, prefix: %s)\n",
62 cc, 67 cc,
63 address_prefix); 68 address_prefix);
64} 69}
65 70
66 71
67static void 72static void
68add_address_cb(void *cls, 73add_address_cb (void *cls,
69 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 74 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
70 const char *address, 75 tc_h,
71 struct GNUNET_TIME_Relative expiration, 76 const char *address,
72 uint32_t aid, 77 struct GNUNET_TIME_Relative expiration,
73 enum GNUNET_NetworkType nt) 78 uint32_t aid,
79 enum GNUNET_NetworkType nt)
74{ 80{
75 LOG(GNUNET_ERROR_TYPE_DEBUG, 81 LOG (GNUNET_ERROR_TYPE_DEBUG,
76 "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n", 82 "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n",
77 address, 83 address,
78 expiration.rel_value_us, 84 expiration.rel_value_us,
79 aid, 85 aid,
80 nt); 86 nt);
81 //addresses[1] = GNUNET_strdup (address); 87 // addresses[1] = GNUNET_strdup (address);
82 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(tc_hs[0], 88 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0],
83 &peer_id[1], 89 &peer_id[1],
84 address); 90 address);
85} 91}
86 92
87 93
@@ -97,16 +103,18 @@ add_address_cb(void *cls,
97 * #GNUNET_NO if queue will not be established (bogous address) 103 * #GNUNET_NO if queue will not be established (bogous address)
98 */ 104 */
99static void 105static void
100queue_create_reply_cb(void *cls, 106queue_create_reply_cb (void *cls,
101 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 107 struct
102 int will_try) 108 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
109 tc_h,
110 int will_try)
103{ 111{
104 if (GNUNET_YES == will_try) 112 if (GNUNET_YES == will_try)
105 LOG(GNUNET_ERROR_TYPE_DEBUG, 113 LOG (GNUNET_ERROR_TYPE_DEBUG,
106 "Queue will be established!\n"); 114 "Queue will be established!\n");
107 else 115 else
108 LOG(GNUNET_ERROR_TYPE_WARNING, 116 LOG (GNUNET_ERROR_TYPE_WARNING,
109 "Queue won't be established (bougus address?)!\n"); 117 "Queue won't be established (bougus address?)!\n");
110} 118}
111 119
112 120
@@ -122,15 +130,16 @@ queue_create_reply_cb(void *cls,
122 * @param tc_queue Handle to newly opened queue 130 * @param tc_queue Handle to newly opened queue
123 */ 131 */
124static void 132static void
125add_queue_cb(void *cls, 133add_queue_cb (void *cls,
126 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 134 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
127 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue) 135 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *
136 tc_queue)
128{ 137{
129 LOG(GNUNET_ERROR_TYPE_DEBUG, 138 LOG (GNUNET_ERROR_TYPE_DEBUG,
130 "Got Queue!\n"); 139 "Got Queue!\n");
131 GNUNET_TRANSPORT_TESTING_transport_communicator_send(tc_queue, 140 GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_queue,
132 &payload, 141 &payload,
133 sizeof(payload)); 142 sizeof(payload));
134} 143}
135 144
136 145
@@ -144,9 +153,10 @@ add_queue_cb(void *cls,
144 * @param msg Received message 153 * @param msg Received message
145 */ 154 */
146void 155void
147incoming_message_cb(void *cls, 156incoming_message_cb (void *cls,
148 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 157 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
149 const struct GNUNET_MessageHeader *msg) 158 *tc_h,
159 const struct GNUNET_MessageHeader *msg)
150{ 160{
151} 161}
152 162
@@ -157,11 +167,11 @@ incoming_message_cb(void *cls,
157 * @param cls Closure - Handle to configuration 167 * @param cls Closure - Handle to configuration
158 */ 168 */
159static void 169static void
160run(void *cls) 170run (void *cls)
161{ 171{
162 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 172 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
163 173
164 tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( 174 tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
165 "transport", 175 "transport",
166 "gnunet-communicator-unix", 176 "gnunet-communicator-unix",
167 "test_communicator_1.conf", 177 "test_communicator_1.conf",
@@ -171,7 +181,7 @@ run(void *cls)
171 &add_queue_cb, 181 &add_queue_cb,
172 NULL, 182 NULL,
173 NULL); /* cls */ 183 NULL); /* cls */
174 tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( 184 tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
175 "transport", 185 "transport",
176 "gnunet-communicator-unix", 186 "gnunet-communicator-unix",
177 "test_communicator_2.conf", 187 "test_communicator_2.conf",
@@ -184,8 +194,8 @@ run(void *cls)
184} 194}
185 195
186int 196int
187main(int argc, 197main (int argc,
188 char *const *argv) 198 char *const *argv)
189{ 199{
190 char *cfg_filename; 200 char *cfg_filename;
191 char *opt_cfg_filename; 201 char *opt_cfg_filename;
@@ -195,73 +205,73 @@ main(int argc,
195 struct GNUNET_CONFIGURATION_Handle *cfg; 205 struct GNUNET_CONFIGURATION_Handle *cfg;
196 206
197 struct GNUNET_GETOPT_CommandLineOption service_options[] = { 207 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
198 GNUNET_GETOPT_option_cfgfile(&opt_cfg_filename), 208 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
199 GNUNET_GETOPT_option_help(NULL), 209 GNUNET_GETOPT_option_help (NULL),
200 GNUNET_GETOPT_option_loglevel(&loglev), 210 GNUNET_GETOPT_option_loglevel (&loglev),
201 GNUNET_GETOPT_option_logfile(&logfile), 211 GNUNET_GETOPT_option_logfile (&logfile),
202 GNUNET_GETOPT_OPTION_END 212 GNUNET_GETOPT_OPTION_END
203 }; 213 };
204 214
205 if (GNUNET_OK != GNUNET_log_setup("test_communicator_unix", 215 if (GNUNET_OK != GNUNET_log_setup ("test_communicator_unix",
206 loglev, 216 loglev,
207 logfile)) 217 logfile))
208 { 218 {
209 GNUNET_break(0); 219 GNUNET_break (0);
210 return GNUNET_SYSERR; 220 return GNUNET_SYSERR;
211 } 221 }
212 222
213 xdg = getenv("XDG_CONFIG_HOME"); 223 xdg = getenv ("XDG_CONFIG_HOME");
214 if (NULL != xdg) 224 if (NULL != xdg)
215 GNUNET_asprintf(&cfg_filename, 225 GNUNET_asprintf (&cfg_filename,
216 "%s%s%s", 226 "%s%s%s",
217 xdg, 227 xdg,
218 DIR_SEPARATOR_STR, 228 DIR_SEPARATOR_STR,
219 GNUNET_OS_project_data_get()->config_file); 229 GNUNET_OS_project_data_get ()->config_file);
220 else 230 else
221 cfg_filename = GNUNET_strdup(GNUNET_OS_project_data_get()->user_config_file); 231 cfg_filename = GNUNET_strdup (
222 cfg = GNUNET_CONFIGURATION_create(); 232 GNUNET_OS_project_data_get ()->user_config_file);
233 cfg = GNUNET_CONFIGURATION_create ();
223 if (NULL != opt_cfg_filename) 234 if (NULL != opt_cfg_filename)
235 {
236 if ((GNUNET_YES !=
237 GNUNET_DISK_file_test (opt_cfg_filename)) ||
238 (GNUNET_SYSERR ==
239 GNUNET_CONFIGURATION_load (cfg,
240 opt_cfg_filename)))
224 { 241 {
225 if ((GNUNET_YES != 242 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
226 GNUNET_DISK_file_test(opt_cfg_filename)) || 243 _ ("Malformed configuration file `%s', exit ...\n"),
227 (GNUNET_SYSERR == 244 opt_cfg_filename);
228 GNUNET_CONFIGURATION_load(cfg, 245 return GNUNET_SYSERR;
229 opt_cfg_filename)))
230 {
231 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
232 _("Malformed configuration file `%s', exit ...\n"),
233 opt_cfg_filename);
234 return GNUNET_SYSERR;
235 }
236 } 246 }
247 }
237 else 248 else
249 {
250 if (GNUNET_YES ==
251 GNUNET_DISK_file_test (cfg_filename))
238 { 252 {
239 if (GNUNET_YES == 253 if (GNUNET_SYSERR ==
240 GNUNET_DISK_file_test(cfg_filename)) 254 GNUNET_CONFIGURATION_load (cfg,
241 { 255 cfg_filename))
242 if (GNUNET_SYSERR == 256 {
243 GNUNET_CONFIGURATION_load(cfg, 257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
244 cfg_filename)) 258 _ ("Malformed configuration file `%s', exit ...\n"),
245 { 259 cfg_filename);
246 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 260 return GNUNET_SYSERR;
247 _("Malformed configuration file `%s', exit ...\n"), 261 }
248 cfg_filename);
249 return GNUNET_SYSERR;
250 }
251 }
252 else
253 {
254 if (GNUNET_SYSERR ==
255 GNUNET_CONFIGURATION_load(cfg,
256 NULL))
257 {
258 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
259 _("Malformed configuration, exit ...\n"));
260 return GNUNET_SYSERR;
261 }
262 }
263 } 262 }
264 GNUNET_SCHEDULER_run(&run, 263 else
265 cfg); 264 {
265 if (GNUNET_SYSERR ==
266 GNUNET_CONFIGURATION_load (cfg,
267 NULL))
268 {
269 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
270 _ ("Malformed configuration, exit ...\n"));
271 return GNUNET_SYSERR;
272 }
273 }
274 }
275 GNUNET_SCHEDULER_run (&run,
276 cfg);
266} 277}
267
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 @@
28 28
29 29
30static void 30static void
31clean(struct SplittedHTTPAddress *addr) 31clean (struct SplittedHTTPAddress *addr)
32{ 32{
33 if (NULL == addr) 33 if (NULL == addr)
34 return; 34 return;
35 GNUNET_free_non_null(addr->host); 35 GNUNET_free_non_null (addr->host);
36 GNUNET_free_non_null(addr->path); 36 GNUNET_free_non_null (addr->path);
37 GNUNET_free_non_null(addr->protocol); 37 GNUNET_free_non_null (addr->protocol);
38 GNUNET_free(addr); 38 GNUNET_free (addr);
39} 39}
40 40
41 41
42static int 42static int
43check(struct SplittedHTTPAddress *addr, 43check (struct SplittedHTTPAddress *addr,
44 const char *protocol, 44 const char *protocol,
45 const char *host, 45 const char *host,
46 int port, 46 int port,
47 const char *path) 47 const char *path)
48{ 48{
49 if (NULL == addr) 49 if (NULL == addr)
50 return GNUNET_NO; 50 return GNUNET_NO;
51 if (((NULL == addr->protocol) && (NULL != protocol)) || 51 if (((NULL == addr->protocol) && (NULL != protocol)) ||
52 ((NULL != addr->protocol) && (NULL == protocol))) 52 ((NULL != addr->protocol) && (NULL == protocol)))
53 { 53 {
54 GNUNET_break(0); 54 GNUNET_break (0);
55 return GNUNET_NO; 55 return GNUNET_NO;
56 } 56 }
57 else if ((NULL != addr->protocol) && (NULL != protocol)) 57 else if ((NULL != addr->protocol) && (NULL != protocol))
58 {
59 if (0 != strcmp (addr->protocol, protocol))
58 { 60 {
59 if (0 != strcmp(addr->protocol, protocol)) 61 GNUNET_break (0);
60 { 62 return GNUNET_NO;
61 GNUNET_break(0);
62 return GNUNET_NO;
63 }
64 } 63 }
64 }
65 65
66 if (((NULL == addr->host) && (NULL != host)) || 66 if (((NULL == addr->host) && (NULL != host)) ||
67 ((NULL != addr->host) && (NULL == host))) 67 ((NULL != addr->host) && (NULL == host)))
68 { 68 {
69 GNUNET_break(0); 69 GNUNET_break (0);
70 return GNUNET_NO; 70 return GNUNET_NO;
71 } 71 }
72 else if ((NULL != addr->host) && (NULL != host)) 72 else if ((NULL != addr->host) && (NULL != host))
73 {
74 if (0 != strcmp (addr->host, host))
73 { 75 {
74 if (0 != strcmp(addr->host, host)) 76 GNUNET_break (0);
75 { 77 return GNUNET_NO;
76 GNUNET_break(0);
77 return GNUNET_NO;
78 }
79 } 78 }
79 }
80 80
81 if (((NULL == addr->path) && (NULL != path)) || 81 if (((NULL == addr->path) && (NULL != path)) ||
82 ((NULL != addr->path) && (NULL == path))) 82 ((NULL != addr->path) && (NULL == path)))
83 { 83 {
84 GNUNET_break(0); 84 GNUNET_break (0);
85 return GNUNET_NO; 85 return GNUNET_NO;
86 } 86 }
87 else if ((NULL != addr->path) && (NULL != path)) 87 else if ((NULL != addr->path) && (NULL != path))
88 {
89 if (0 != strcmp (addr->path, path))
88 { 90 {
89 if (0 != strcmp(addr->path, path)) 91 GNUNET_break (0);
90 { 92 return GNUNET_NO;
91 GNUNET_break(0);
92 return GNUNET_NO;
93 }
94 } 93 }
94 }
95 95
96 if ((addr->port != port)) 96 if ((addr->port != port))
97 { 97 {
98 GNUNET_break(0); 98 GNUNET_break (0);
99 return GNUNET_NO; 99 return GNUNET_NO;
100 } 100 }
101 return GNUNET_OK; 101 return GNUNET_OK;
102} 102}
103 103
104 104
105static int 105static int
106check_pass(const char *src, 106check_pass (const char *src,
107 const char *protocol, 107 const char *protocol,
108 const char *host, 108 const char *host,
109 int port, 109 int port,
110 const char *path) 110 const char *path)
111{ 111{
112 struct SplittedHTTPAddress *spa; 112 struct SplittedHTTPAddress *spa;
113 113
114 spa = http_split_address(src); 114 spa = http_split_address (src);
115 if (NULL == spa) 115 if (NULL == spa)
116 { 116 {
117 GNUNET_break(0); 117 GNUNET_break (0);
118 return GNUNET_SYSERR; 118 return GNUNET_SYSERR;
119 } 119 }
120 if (GNUNET_OK != check(spa, protocol, host, port, path)) 120 if (GNUNET_OK != check (spa, protocol, host, port, path))
121 { 121 {
122 clean(spa); 122 clean (spa);
123 GNUNET_break(0); 123 GNUNET_break (0);
124 return GNUNET_SYSERR; 124 return GNUNET_SYSERR;
125 } 125 }
126 clean(spa); 126 clean (spa);
127 return GNUNET_OK; 127 return GNUNET_OK;
128} 128}
129 129
130 130
131static int 131static int
132check_fail(const char *src) 132check_fail (const char *src)
133{ 133{
134 struct SplittedHTTPAddress * spa; 134 struct SplittedHTTPAddress *spa;
135 135
136 spa = http_split_address(src); 136 spa = http_split_address (src);
137 if (NULL != spa) 137 if (NULL != spa)
138 { 138 {
139 GNUNET_break(0); 139 GNUNET_break (0);
140 clean(spa); 140 clean (spa);
141 return GNUNET_SYSERR; 141 return GNUNET_SYSERR;
142 } 142 }
143 return GNUNET_OK; 143 return GNUNET_OK;
144} 144}
145 145
146 146
147static void 147static void
148test_pass_hostname() 148test_pass_hostname ()
149{ 149{
150 check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, ""); 150 check_pass ("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, "");
151 check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/"); 151 check_pass ("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT,
152 check_pass("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, "/path"); 152 "/");
153 check_pass("http://test.local/path/", "http", "test.local", HTTP_DEFAULT_PORT, "/path/"); 153 check_pass ("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT,
154 check_pass("http://test.local/path/more", "http", "test.local", HTTP_DEFAULT_PORT, "/path/more"); 154 "/path");
155 check_pass("http://test.local:81", "http", "test.local", 81, ""); 155 check_pass ("http://test.local/path/", "http", "test.local",
156 check_pass("http://test.local:81/", "http", "test.local", 81, "/"); 156 HTTP_DEFAULT_PORT, "/path/");
157 check_pass("http://test.local:81/path", "http", "test.local", 81, "/path"); 157 check_pass ("http://test.local/path/more", "http", "test.local",
158 check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/"); 158 HTTP_DEFAULT_PORT, "/path/more");
159 check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more"); 159 check_pass ("http://test.local:81", "http", "test.local", 81, "");
160 check_pass ("http://test.local:81/", "http", "test.local", 81, "/");
161 check_pass ("http://test.local:81/path", "http", "test.local", 81, "/path");
162 check_pass ("http://test.local:81/path/", "http", "test.local", 81, "/path/");
163 check_pass ("http://test.local:81/path/more", "http", "test.local", 81,
164 "/path/more");
160} 165}
161 166
162 167
163static void 168static void
164test_pass_ipv4() 169test_pass_ipv4 ()
165{ 170{
166 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""); 171 check_pass ("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "");
167 check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/"); 172 check_pass ("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/");
168 check_pass("http://127.0.0.1/path", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path"); 173 check_pass ("http://127.0.0.1/path", "http", "127.0.0.1", HTTP_DEFAULT_PORT,
169 check_pass("http://127.0.0.1/path/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path/"); 174 "/path");
170 check_pass("http://127.0.0.1:81", "http", "127.0.0.1", 81, ""); 175 check_pass ("http://127.0.0.1/path/", "http", "127.0.0.1", HTTP_DEFAULT_PORT,
171 check_pass("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/"); 176 "/path/");
172 check_pass("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path"); 177 check_pass ("http://127.0.0.1:81", "http", "127.0.0.1", 81, "");
173 check_pass("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/"); 178 check_pass ("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/");
174 check_pass("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, "/path/more"); 179 check_pass ("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path");
180 check_pass ("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/");
181 check_pass ("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81,
182 "/path/more");
175} 183}
176 184
177 185
178static void 186static void
179test_fail_ipv6() 187test_fail_ipv6 ()
180{ 188{
181 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); 189 check_pass ("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, "");
182 check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/"); 190 check_pass ("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/");
183 check_pass("http://[::1]/path", "http", "[::1]", HTTP_DEFAULT_PORT, "/path"); 191 check_pass ("http://[::1]/path", "http", "[::1]", HTTP_DEFAULT_PORT, "/path");
184 check_pass("http://[::1]/path/", "http", "[::1]", HTTP_DEFAULT_PORT, "/path/"); 192 check_pass ("http://[::1]/path/", "http", "[::1]", HTTP_DEFAULT_PORT,
185 check_pass("http://[::1]:81", "http", "[::1]", 81, ""); 193 "/path/");
186 check_pass("http://[::1]:81/", "http", "[::1]", 81, "/"); 194 check_pass ("http://[::1]:81", "http", "[::1]", 81, "");
187 check_pass("http://[::1]:81/path", "http", "[::1]", 81, "/path"); 195 check_pass ("http://[::1]:81/", "http", "[::1]", 81, "/");
188 check_pass("http://[::1]:81/path/", "http", "[::1]", 81, "/path/"); 196 check_pass ("http://[::1]:81/path", "http", "[::1]", 81, "/path");
189 check_pass("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more"); 197 check_pass ("http://[::1]:81/path/", "http", "[::1]", 81, "/path/");
198 check_pass ("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more");
190} 199}
191 200
192 201
193static void 202static void
194test_fail() 203test_fail ()
195{ 204{
196 if (GNUNET_SYSERR == check_fail("")) 205 if (GNUNET_SYSERR == check_fail (""))
197 GNUNET_break(0); 206 GNUNET_break (0);
198 if (GNUNET_SYSERR == check_fail("http")) 207 if (GNUNET_SYSERR == check_fail ("http"))
199 GNUNET_break(0); 208 GNUNET_break (0);
200 if (GNUNET_SYSERR == check_fail("://")) 209 if (GNUNET_SYSERR == check_fail ("://"))
201 GNUNET_break(0); 210 GNUNET_break (0);
202 if (GNUNET_SYSERR == check_fail("http://")) 211 if (GNUNET_SYSERR == check_fail ("http://"))
203 GNUNET_break(0); 212 GNUNET_break (0);
204 if (GNUNET_SYSERR == check_fail("//localhost")) 213 if (GNUNET_SYSERR == check_fail ("//localhost"))
205 GNUNET_break(0); 214 GNUNET_break (0);
206 if (GNUNET_SYSERR == check_fail("//:80")) 215 if (GNUNET_SYSERR == check_fail ("//:80"))
207 GNUNET_break(0); 216 GNUNET_break (0);
208 if (GNUNET_SYSERR == check_fail("//:80/")) 217 if (GNUNET_SYSERR == check_fail ("//:80/"))
209 GNUNET_break(0); 218 GNUNET_break (0);
210 if (GNUNET_SYSERR == check_fail("//:80:")) 219 if (GNUNET_SYSERR == check_fail ("//:80:"))
211 GNUNET_break(0); 220 GNUNET_break (0);
212 if (GNUNET_SYSERR == check_fail("http://localhost:a/")) 221 if (GNUNET_SYSERR == check_fail ("http://localhost:a/"))
213 GNUNET_break(0); 222 GNUNET_break (0);
214 if (GNUNET_SYSERR == check_fail("http://127.0.0.1:a/")) 223 if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/"))
215 GNUNET_break(0); 224 GNUNET_break (0);
216} 225}
217 226
218 227
219int 228int
220main(int argc, char *argv[]) 229main (int argc, char *argv[])
221{ 230{
222 int ret = 0; 231 int ret = 0;
223 struct SplittedHTTPAddress * spa; 232 struct SplittedHTTPAddress *spa;
224 233
225 GNUNET_log_setup("test", "DEBUG", NULL); 234 GNUNET_log_setup ("test", "DEBUG", NULL);
226 spa = http_split_address(""); 235 spa = http_split_address ("");
227 if (NULL != spa) 236 if (NULL != spa)
228 { 237 {
229 clean(spa); 238 clean (spa);
230 spa = NULL; 239 spa = NULL;
231 GNUNET_break(0); 240 GNUNET_break (0);
232 } 241 }
233 242
234 spa = http_split_address("http://"); 243 spa = http_split_address ("http://");
235 if (NULL != spa) 244 if (NULL != spa)
236 { 245 {
237 clean(spa); 246 clean (spa);
238 GNUNET_break(0); 247 GNUNET_break (0);
239 } 248 }
240 249
241 spa = http_split_address("://"); 250 spa = http_split_address ("://");
242 if (NULL != spa) 251 if (NULL != spa)
243 { 252 {
244 clean(spa); 253 clean (spa);
245 GNUNET_break(0); 254 GNUNET_break (0);
246 } 255 }
247 256
248 test_pass_hostname(); 257 test_pass_hostname ();
249 test_pass_ipv4(); 258 test_pass_ipv4 ();
250 test_fail_ipv6(); 259 test_fail_ipv6 ();
251 test_fail(); 260 test_fail ();
252 261
253 return ret; 262 return ret;
254} 263}
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 @@
36/** 36/**
37 * How long until we give up on transmitting the message? 37 * How long until we give up on transmitting the message?
38 */ 38 */
39#define WAIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 39#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
41 41
42#define HOSTKEY_FILE "test_plugin_hostkey.ecc" 42#define HOSTKEY_FILE "test_plugin_hostkey.ecc"
43 43
@@ -89,12 +89,12 @@ struct GNUNET_HELPER_Handle *suid_helper;
89/** 89/**
90 * Timeout task 90 * Timeout task
91 */ 91 */
92static struct GNUNET_SCHEDULER_Task * timeout_endbadly; 92static struct GNUNET_SCHEDULER_Task *timeout_endbadly;
93 93
94/** 94/**
95 * Timeout task 95 * Timeout task
96 */ 96 */
97static struct GNUNET_SCHEDULER_Task * timeout_wait; 97static struct GNUNET_SCHEDULER_Task *timeout_wait;
98 98
99/** 99/**
100 * Library name 100 * Library name
@@ -120,7 +120,8 @@ unsigned int pretty_printers_running;
120 */ 120 */
121static int ok; 121static int ok;
122 122
123struct AddressWrapper { 123struct AddressWrapper
124{
124 struct AddressWrapper *next; 125 struct AddressWrapper *next;
125 126
126 struct AddressWrapper *prev; 127 struct AddressWrapper *prev;
@@ -134,7 +135,7 @@ struct AddressWrapper {
134 135
135 136
136static void 137static void
137end() 138end ()
138{ 139{
139 struct AddressWrapper *w; 140 struct AddressWrapper *w;
140 int c = 0; 141 int c = 0;
@@ -142,153 +143,154 @@ end()
142 ok = 0; 143 ok = 0;
143 144
144 if (NULL != timeout_endbadly) 145 if (NULL != timeout_endbadly)
145 { 146 {
146 GNUNET_SCHEDULER_cancel(timeout_endbadly); 147 GNUNET_SCHEDULER_cancel (timeout_endbadly);
147 timeout_endbadly = NULL; 148 timeout_endbadly = NULL;
148 } 149 }
149 if (NULL != api) 150 if (NULL != api)
150 GNUNET_PLUGIN_unload(libname, api); 151 GNUNET_PLUGIN_unload (libname, api);
151 152
152 while (NULL != head) 153 while (NULL != head)
153 { 154 {
154 w = head; 155 w = head;
155 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
156 "Plugin did not remove address `%s'\n", 157 "Plugin did not remove address `%s'\n",
157 w->addrstring); 158 w->addrstring);
158 GNUNET_CONTAINER_DLL_remove(head, tail, w); 159 GNUNET_CONTAINER_DLL_remove (head, tail, w);
159 c++; 160 c++;
160 GNUNET_HELLO_address_free(w->address); 161 GNUNET_HELLO_address_free (w->address);
161 GNUNET_free(w->addrstring); 162 GNUNET_free (w->addrstring);
162 GNUNET_free(w); 163 GNUNET_free (w);
163 } 164 }
164 if (c > 0) 165 if (c > 0)
165 { 166 {
166 GNUNET_break(0); 167 GNUNET_break (0);
167 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses \n", 168 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
168 c); 169 "Plugin did not remove %u addresses \n",
169 ok = 1; 170 c);
170 } 171 ok = 1;
171 172 }
172 GNUNET_free(libname); 173
174 GNUNET_free (libname);
173 libname = NULL; 175 libname = NULL;
174 GNUNET_STATISTICS_destroy(stats, GNUNET_NO); 176 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
175 stats = NULL; 177 stats = NULL;
176 178
177 if (NULL != suid_helper) 179 if (NULL != suid_helper)
178 { 180 {
179 GNUNET_HELPER_stop(suid_helper, GNUNET_NO); 181 GNUNET_HELPER_stop (suid_helper, GNUNET_NO);
180 suid_helper = NULL; 182 suid_helper = NULL;
181 } 183 }
182} 184}
183 185
184 186
185static void 187static void
186end_badly(void *cls) 188end_badly (void *cls)
187{ 189{
188 struct AddressWrapper *w; 190 struct AddressWrapper *w;
189 int c = 0; 191 int c = 0;
190 192
191 timeout_endbadly = NULL; 193 timeout_endbadly = NULL;
192 if (NULL != timeout_wait) 194 if (NULL != timeout_wait)
193 { 195 {
194 GNUNET_SCHEDULER_cancel(timeout_wait); 196 GNUNET_SCHEDULER_cancel (timeout_wait);
195 timeout_wait = NULL; 197 timeout_wait = NULL;
196 } 198 }
197 199
198 if (pretty_printers_running > 0) 200 if (pretty_printers_running > 0)
199 { 201 {
200 timeout_endbadly = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 202 timeout_endbadly = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
201 &end_badly, &ok); 203 &end_badly, &ok);
202 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 204 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
203 "Have pending calls to pretty_printer ... deferring shutdown\n"); 205 "Have pending calls to pretty_printer ... deferring shutdown\n");
204 return; 206 return;
205 } 207 }
206 208
207 if (NULL != cls) 209 if (NULL != cls)
208 { 210 {
209 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
210 "Test took too long to execute, timeout .... \n"); 212 "Test took too long to execute, timeout .... \n");
211 } 213 }
212 214
213 if (NULL != libname) 215 if (NULL != libname)
214 { 216 {
215 if (NULL != api) 217 if (NULL != api)
216 GNUNET_PLUGIN_unload(libname, api); 218 GNUNET_PLUGIN_unload (libname, api);
217 GNUNET_free(libname); 219 GNUNET_free (libname);
218 libname = NULL; 220 libname = NULL;
219 } 221 }
220 222
221 while (NULL != head) 223 while (NULL != head)
222 { 224 {
223 w = head; 225 w = head;
224 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", 226 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n",
225 w->addrstring); 227 w->addrstring);
226 GNUNET_CONTAINER_DLL_remove(head, tail, w); 228 GNUNET_CONTAINER_DLL_remove (head, tail, w);
227 c++; 229 c++;
228 GNUNET_HELLO_address_free(w->address); 230 GNUNET_HELLO_address_free (w->address);
229 if (NULL != w->test_task) 231 if (NULL != w->test_task)
230 GNUNET_SCHEDULER_cancel(w->test_task); 232 GNUNET_SCHEDULER_cancel (w->test_task);
231 GNUNET_free(w->addrstring); 233 GNUNET_free (w->addrstring);
232 GNUNET_free(w); 234 GNUNET_free (w);
233 } 235 }
234 if (c > 0) 236 if (c > 0)
235 { 237 {
236 GNUNET_break(0); 238 GNUNET_break (0);
237 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n", 239 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n",
238 c); 240 c);
239 } 241 }
240 242
241 if (NULL != stats) 243 if (NULL != stats)
242 { 244 {
243 GNUNET_STATISTICS_destroy(stats, GNUNET_NO); 245 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
244 stats = NULL; 246 stats = NULL;
245 } 247 }
246 248
247 if (NULL != suid_helper) 249 if (NULL != suid_helper)
248 { 250 {
249 GNUNET_HELPER_stop(suid_helper, GNUNET_NO); 251 GNUNET_HELPER_stop (suid_helper, GNUNET_NO);
250 suid_helper = NULL; 252 suid_helper = NULL;
251 } 253 }
252 254
253 ok = 1; 255 ok = 1;
254} 256}
255 257
256static void 258static void
257wait_end(void *cls) 259wait_end (void *cls)
258{ 260{
259 timeout_wait = NULL; 261 timeout_wait = NULL;
260 if (0 == addresses_reported) 262 if (0 == addresses_reported)
261 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 263 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
262 "Plugin did not report any addresses, could not check address conversion functions\n"); 264 "Plugin did not report any addresses, could not check address conversion functions\n");
263 end(); 265 end ();
264} 266}
265 267
266 268
267static void 269static void
268end_badly_now() 270end_badly_now ()
269{ 271{
270 if (NULL != timeout_wait) 272 if (NULL != timeout_wait)
271 { 273 {
272 GNUNET_SCHEDULER_cancel(timeout_wait); 274 GNUNET_SCHEDULER_cancel (timeout_wait);
273 timeout_wait = NULL; 275 timeout_wait = NULL;
274 } 276 }
275 if (NULL != timeout_endbadly) 277 if (NULL != timeout_endbadly)
276 { 278 {
277 GNUNET_SCHEDULER_cancel(timeout_endbadly); 279 GNUNET_SCHEDULER_cancel (timeout_endbadly);
278 timeout_endbadly = NULL; 280 timeout_endbadly = NULL;
279 } 281 }
280 timeout_endbadly = GNUNET_SCHEDULER_add_now(&end_badly, NULL); 282 timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
281} 283}
282 284
283 285
284static struct GNUNET_TIME_Relative 286static struct GNUNET_TIME_Relative
285env_receive(void *cls, 287env_receive (void *cls,
286 const struct GNUNET_HELLO_Address *address, 288 const struct GNUNET_HELLO_Address *address,
287 struct GNUNET_ATS_Session *session, 289 struct GNUNET_ATS_Session *session,
288 const struct GNUNET_MessageHeader *message) 290 const struct GNUNET_MessageHeader *message)
289{ 291{
290 /* do nothing */ 292 /* do nothing */
291 return GNUNET_TIME_relative_get_zero_(); 293 return GNUNET_TIME_relative_get_zero_ ();
292} 294}
293 295
294static int got_reply; 296static int got_reply;
@@ -303,28 +305,28 @@ static int got_reply;
303 * @param res result code 305 * @param res result code
304 */ 306 */
305static void 307static void
306address_pretty_printer_cb(void *cls, const char *address, int res) 308address_pretty_printer_cb (void *cls, const char *address, int res)
307{ 309{
308 if (NULL != address) 310 if (NULL != address)
309 { 311 {
310 got_reply = GNUNET_YES; 312 got_reply = GNUNET_YES;
311 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", address); 313 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", address);
312 pretty_printers_running--; 314 pretty_printers_running--;
313 } 315 }
314 else 316 else
317 {
318 if (GNUNET_NO == got_reply)
315 { 319 {
316 if (GNUNET_NO == got_reply) 320 pretty_printers_running--;
317 { 321 GNUNET_break (0);
318 pretty_printers_running--; 322 end_badly_now ();
319 GNUNET_break(0);
320 end_badly_now();
321 }
322 } 323 }
324 }
323} 325}
324 326
325 327
326static void 328static void
327test_addr_string(void *cls) 329test_addr_string (void *cls)
328{ 330{
329 struct AddressWrapper *w = cls; 331 struct AddressWrapper *w = cls;
330 void *s2a; 332 void *s2a;
@@ -332,40 +334,41 @@ test_addr_string(void *cls)
332 334
333 w->test_task = NULL; 335 w->test_task = NULL;
334 336
335 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 337 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
336 "Testing: address_to_string \n"); 338 "Testing: address_to_string \n");
337 w->addrstring = GNUNET_strdup(api->address_to_string(api, 339 w->addrstring = GNUNET_strdup (api->address_to_string (api,
338 w->address->address, 340 w->address->address,
339 w->address->address_length)); 341 w->address->
342 address_length));
340 if (NULL == w->addrstring) 343 if (NULL == w->addrstring)
341 { 344 {
342 GNUNET_break(0); 345 GNUNET_break (0);
343 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 346 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
344 "Plugin cannot convert address to string!\n"); 347 "Plugin cannot convert address to string!\n");
345 end_badly_now(); 348 end_badly_now ();
346 return; 349 return;
347 } 350 }
348 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 351 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
349 "Plugin added address `%s'\n", 352 "Plugin added address `%s'\n",
350 w->addrstring); 353 w->addrstring);
351 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 354 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
352 "Testing address_to_string: OK\n"); 355 "Testing address_to_string: OK\n");
353 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 356 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
354 "Testing: string_to_address \n"); 357 "Testing: string_to_address \n");
355 s2a = NULL; 358 s2a = NULL;
356 s2a_len = 0; 359 s2a_len = 0;
357 if ((GNUNET_OK != 360 if ((GNUNET_OK !=
358 api->string_to_address(api, w->addrstring, 361 api->string_to_address (api, w->addrstring,
359 strlen(w->addrstring) + 1, 362 strlen (w->addrstring) + 1,
360 &s2a, &s2a_len)) || 363 &s2a, &s2a_len)) ||
361 (NULL == s2a)) 364 (NULL == s2a))
362 { 365 {
363 GNUNET_break(0); 366 GNUNET_break (0);
364 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
365 "Plugin cannot convert string to address!\n"); 368 "Plugin cannot convert string to address!\n");
366 end_badly_now(); 369 end_badly_now ();
367 return; 370 return;
368 } 371 }
369 372
370 /* 373 /*
371 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 374 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -376,164 +379,166 @@ test_addr_string(void *cls)
376 fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]); 379 fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]);
377 */ 380 */
378 if (s2a_len != w->address->address_length) 381 if (s2a_len != w->address->address_length)
379 { 382 {
380 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
381 "Plugin creates different address length when converting address->string->address: %u != %u\n", 384 "Plugin creates different address length when converting address->string->address: %u != %u\n",
382 (unsigned int)w->address->address_length, 385 (unsigned int) w->address->address_length,
383 (unsigned int)s2a_len); 386 (unsigned int) s2a_len);
384 } 387 }
385 else if (0 != memcmp(s2a, w->address->address, s2a_len)) 388 else if (0 != memcmp (s2a, w->address->address, s2a_len))
386 { 389 {
387 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 390 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
388 "Plugin creates different address length when converting back and forth %i!\n", 391 "Plugin creates different address length when converting back and forth %i!\n",
389 memcmp(s2a, 392 memcmp (s2a,
390 w->address->address, 393 w->address->address,
391 s2a_len)); 394 s2a_len));
392 } 395 }
393 else 396 else
394 { 397 {
395 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 398 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
396 "Testing string_to_address: OK\n"); 399 "Testing string_to_address: OK\n");
397 } 400 }
398 GNUNET_free(s2a); 401 GNUNET_free (s2a);
399 402
400 pretty_printers_running++; 403 pretty_printers_running++;
401 api->address_pretty_printer(api->cls, 404 api->address_pretty_printer (api->cls,
402 w->address->transport_name, 405 w->address->transport_name,
403 w->address->address, 406 w->address->address,
404 w->address->address_length, 407 w->address->address_length,
405 GNUNET_YES, 408 GNUNET_YES,
406 GNUNET_TIME_UNIT_MINUTES, 409 GNUNET_TIME_UNIT_MINUTES,
407 &address_pretty_printer_cb, w); 410 &address_pretty_printer_cb, w);
408 411
409 if (GNUNET_OK != 412 if (GNUNET_OK !=
410 api->check_address(api->cls, 413 api->check_address (api->cls,
411 w->address->address, 414 w->address->address,
412 w->address->address_length)) 415 w->address->address_length))
413 { 416 {
414 GNUNET_break(0); 417 GNUNET_break (0);
415 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 418 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
416 "Plugin refuses added address!\n"); 419 "Plugin refuses added address!\n");
417 end_badly_now(); 420 end_badly_now ();
418 return; 421 return;
419 } 422 }
420 if (NULL != timeout_wait) 423 if (NULL != timeout_wait)
421 { 424 {
422 GNUNET_SCHEDULER_cancel(timeout_wait); 425 GNUNET_SCHEDULER_cancel (timeout_wait);
423 timeout_wait = NULL; 426 timeout_wait = NULL;
424 } 427 }
425 timeout_wait = GNUNET_SCHEDULER_add_delayed(WAIT, &wait_end, NULL); 428 timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
426} 429}
427 430
428 431
429static void 432static void
430env_notify_address(void *cls, 433env_notify_address (void *cls,
431 int add_remove, 434 int add_remove,
432 const struct GNUNET_HELLO_Address *address) 435 const struct GNUNET_HELLO_Address *address)
433{ 436{
434 struct AddressWrapper *w; 437 struct AddressWrapper *w;
435 struct AddressWrapper *wtmp; 438 struct AddressWrapper *wtmp;
436 439
437 if (GNUNET_YES == add_remove) 440 if (GNUNET_YES == add_remove)
438 { 441 {
439 addresses_reported++; 442 addresses_reported++;
440 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "Adding address of length %u\n", 444 "Adding address of length %u\n",
442 (unsigned int)address->address_length); 445 (unsigned int) address->address_length);
443 446
444 for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) 447 for (wtmp = head; NULL != wtmp; wtmp = wtmp->next)
445 { 448 {
446 if ((address->address_length == wtmp->address->address_length) && 449 if ((address->address_length == wtmp->address->address_length) &&
447 (0 == memcmp(address->address, wtmp->address->address, address->address_length))) 450 (0 == memcmp (address->address, wtmp->address->address,
448 { 451 address->address_length)))
449 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 452 {
450 "Duplicate address notification .... \n"); 453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
451 return; 454 "Duplicate address notification .... \n");
452 } 455 return;
453 } 456 }
454 457 }
455 w = GNUNET_new(struct AddressWrapper); 458
456 w->address = GNUNET_HELLO_address_copy(address); 459 w = GNUNET_new (struct AddressWrapper);
457 GNUNET_CONTAINER_DLL_insert(head, tail, w); 460 w->address = GNUNET_HELLO_address_copy (address);
458 got_reply = GNUNET_NO; 461 GNUNET_CONTAINER_DLL_insert (head, tail, w);
459 w->test_task = GNUNET_SCHEDULER_add_now(&test_addr_string, 462 got_reply = GNUNET_NO;
460 w); 463 w->test_task = GNUNET_SCHEDULER_add_now (&test_addr_string,
461 return; 464 w);
462 } 465 return;
466 }
463 467
464 if (GNUNET_NO == add_remove) 468 if (GNUNET_NO == add_remove)
465 { 469 {
466 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
467 "Removing address of length %u\n", 471 "Removing address of length %u\n",
468 (unsigned int)address->address_length); 472 (unsigned int) address->address_length);
469 w = head; 473 w = head;
470 while (NULL != w) 474 while (NULL != w)
471 { 475 {
472 if ((address->address_length == w->address->address_length) && 476 if ((address->address_length == w->address->address_length) &&
473 (0 == memcmp(w->address->address, address->address, address->address_length))) 477 (0 == memcmp (w->address->address, address->address,
474 { 478 address->address_length)))
475 break; 479 {
476 } 480 break;
477 w = w->next; 481 }
478 } 482 w = w->next;
479 483 }
480 if (w == NULL) 484
481 { 485 if (w == NULL)
482 GNUNET_break(0); 486 {
483 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 487 GNUNET_break (0);
484 "Plugin removes address never added!\n"); 488 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
485 end_badly_now(); 489 "Plugin removes address never added!\n");
486 return; 490 end_badly_now ();
487 }
488
489 GNUNET_CONTAINER_DLL_remove(head, tail, w);
490 GNUNET_HELLO_address_free(w->address);
491 GNUNET_free(w->addrstring);
492 GNUNET_free(w);
493 return; 491 return;
494 } 492 }
495 GNUNET_break(0); 493
496 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 494 GNUNET_CONTAINER_DLL_remove (head, tail, w);
497 "Invalid operation: %u\n", 495 GNUNET_HELLO_address_free (w->address);
498 add_remove); 496 GNUNET_free (w->addrstring);
499 end_badly_now(); 497 GNUNET_free (w);
498 return;
499 }
500 GNUNET_break (0);
501 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
502 "Invalid operation: %u\n",
503 add_remove);
504 end_badly_now ();
500} 505}
501 506
502 507
503static enum GNUNET_NetworkType 508static enum GNUNET_NetworkType
504env_get_address_type(void *cls, 509env_get_address_type (void *cls,
505 const struct sockaddr *addr, 510 const struct sockaddr *addr,
506 size_t addrlen) 511 size_t addrlen)
507{ 512{
508 return GNUNET_NT_LOOPBACK; 513 return GNUNET_NT_LOOPBACK;
509} 514}
510 515
511 516
512static const struct GNUNET_MessageHeader * 517static const struct GNUNET_MessageHeader *
513env_get_our_hello() 518env_get_our_hello ()
514{ 519{
515 return (const struct GNUNET_MessageHeader *)hello; 520 return (const struct GNUNET_MessageHeader *) hello;
516} 521}
517 522
518 523
519static void 524static void
520env_session_end(void *cls, 525env_session_end (void *cls,
521 const struct GNUNET_HELLO_Address *address, 526 const struct GNUNET_HELLO_Address *address,
522 struct GNUNET_ATS_Session *session) 527 struct GNUNET_ATS_Session *session)
523{ 528{
524} 529}
525 530
526 531
527static void 532static void
528env_update_distance(void *cls, 533env_update_distance (void *cls,
529 const struct GNUNET_HELLO_Address *address, 534 const struct GNUNET_HELLO_Address *address,
530 uint32_t distance) 535 uint32_t distance)
531{ 536{
532} 537}
533 538
534 539
535static void 540static void
536setup_plugin_environment() 541setup_plugin_environment ()
537{ 542{
538 env.cfg = cfg; 543 env.cfg = cfg;
539 env.cls = &env; 544 env.cls = &env;
@@ -550,8 +555,8 @@ setup_plugin_environment()
550 555
551 556
552static int 557static int
553handle_helper_message(void *cls, 558handle_helper_message (void *cls,
554 const struct GNUNET_MessageHeader *hdr) 559 const struct GNUNET_MessageHeader *hdr)
555{ 560{
556 return GNUNET_OK; 561 return GNUNET_OK;
557} 562}
@@ -564,184 +569,185 @@ handle_helper_message(void *cls,
564 * @param c configuration to use 569 * @param c configuration to use
565 */ 570 */
566static void 571static void
567run(void *cls, 572run (void *cls,
568 char * const *args, 573 char *const *args,
569 const char *cfgfile, 574 const char *cfgfile,
570 const struct GNUNET_CONFIGURATION_Handle *c) 575 const struct GNUNET_CONFIGURATION_Handle *c)
571{ 576{
572 char * const *argv = cls; 577 char *const *argv = cls;
573 unsigned long long tneigh; 578 unsigned long long tneigh;
574 char *keyfile; 579 char *keyfile;
575 char *plugin; 580 char *plugin;
576 char *sep; 581 char *sep;
577 582
578 timeout_endbadly = GNUNET_SCHEDULER_add_delayed(TIMEOUT, 583 timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
579 &end_badly, 584 &end_badly,
580 &ok); 585 &ok);
581 cfg = c; 586 cfg = c;
582 /* parse configuration */ 587 /* parse configuration */
583 if ((GNUNET_OK != 588 if ((GNUNET_OK !=
584 GNUNET_CONFIGURATION_get_value_number(c, 589 GNUNET_CONFIGURATION_get_value_number (c,
585 "TRANSPORT", 590 "TRANSPORT",
586 "NEIGHBOUR_LIMIT", 591 "NEIGHBOUR_LIMIT",
587 &tneigh)) || 592 &tneigh)) ||
588 (GNUNET_OK != 593 (GNUNET_OK !=
589 GNUNET_CONFIGURATION_get_value_filename(c, 594 GNUNET_CONFIGURATION_get_value_filename (c,
590 "PEER", 595 "PEER",
591 "PRIVATE_KEY", 596 "PRIVATE_KEY",
592 &keyfile))) 597 &keyfile)))
593 { 598 {
594 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 599 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
595 "Transport service is lacking key configuration settings. Exiting.\n"); 600 "Transport service is lacking key configuration settings. Exiting.\n");
596 return; 601 return;
597 } 602 }
598 603
599 if (NULL == (stats = GNUNET_STATISTICS_create("transport", 604 if (NULL == (stats = GNUNET_STATISTICS_create ("transport",
600 cfg))) 605 cfg)))
601 { 606 {
602 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 607 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
603 "Could not create statistics. Exiting.\n"); 608 "Could not create statistics. Exiting.\n");
604 GNUNET_free(keyfile); 609 GNUNET_free (keyfile);
605 end_badly_now(); 610 end_badly_now ();
606 return; 611 return;
607 } 612 }
608 613
609 if (GNUNET_OK != GNUNET_DISK_file_test(HOSTKEY_FILE)) 614 if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE))
610 { 615 {
611 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 616 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
612 "Hostkey `%s' missing. Exiting.\n", 617 "Hostkey `%s' missing. Exiting.\n",
613 HOSTKEY_FILE); 618 HOSTKEY_FILE);
614 GNUNET_free(keyfile); 619 GNUNET_free (keyfile);
615 end_badly_now(); 620 end_badly_now ();
616 return; 621 return;
617 } 622 }
618 623
619 if (GNUNET_OK != 624 if (GNUNET_OK !=
620 GNUNET_DISK_directory_create_for_file(keyfile)) 625 GNUNET_DISK_directory_create_for_file (keyfile))
621 { 626 {
622 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 627 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
623 "Could not create a directory for hostkey `%s'. Exiting.\n", 628 "Could not create a directory for hostkey `%s'. Exiting.\n",
624 keyfile); 629 keyfile);
625 GNUNET_free(keyfile); 630 GNUNET_free (keyfile);
626 end_badly_now(); 631 end_badly_now ();
627 return; 632 return;
628 } 633 }
629 634
630 if (GNUNET_OK != 635 if (GNUNET_OK !=
631 GNUNET_DISK_file_copy(HOSTKEY_FILE, 636 GNUNET_DISK_file_copy (HOSTKEY_FILE,
632 keyfile)) 637 keyfile))
633 { 638 {
634 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 639 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
635 "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", 640 "Could not copy hostkey `%s' to destination `%s'. Exiting.\n",
636 HOSTKEY_FILE, 641 HOSTKEY_FILE,
637 keyfile); 642 keyfile);
638 GNUNET_free(keyfile); 643 GNUNET_free (keyfile);
639 end_badly_now(); 644 end_badly_now ();
640 return; 645 return;
641 } 646 }
642 647
643 max_connect_per_transport = (uint32_t)tneigh; 648 max_connect_per_transport = (uint32_t) tneigh;
644 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); 649 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
645 GNUNET_free(keyfile); 650 GNUNET_free (keyfile);
646 if (NULL == my_private_key) 651 if (NULL == my_private_key)
647 { 652 {
648 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 653 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
649 "Could not access hostkey. Exiting.\n"); 654 "Could not access hostkey. Exiting.\n");
650 end_badly_now(); 655 end_badly_now ();
651 return; 656 return;
652 } 657 }
653 GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key); 658 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
654 659
655 hello = GNUNET_HELLO_create(&my_identity.public_key, NULL, NULL, GNUNET_NO); 660 hello = GNUNET_HELLO_create (&my_identity.public_key, NULL, NULL, GNUNET_NO);
656 661
657 /* load plugins... */ 662 /* load plugins... */
658 setup_plugin_environment(); 663 setup_plugin_environment ();
659 664
660 GNUNET_assert(strlen(argv[0]) > strlen("test_plugin_")); 665 GNUNET_assert (strlen (argv[0]) > strlen ("test_plugin_"));
661 plugin = strstr(argv[0], "test_plugin_"); 666 plugin = strstr (argv[0], "test_plugin_");
662 sep = strrchr(argv[0], '.'); 667 sep = strrchr (argv[0], '.');
663 if (NULL == plugin) 668 if (NULL == plugin)
664 { 669 {
665 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); 670 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n");
666 end_badly_now(); 671 end_badly_now ();
667 return; 672 return;
668 } 673 }
669 plugin += strlen("test_plugin_"); 674 plugin += strlen ("test_plugin_");
670 if (NULL != sep) 675 if (NULL != sep)
671 sep[0] = '\0'; 676 sep[0] = '\0';
672 677
673 /* Hack for WLAN: start a second helper */ 678 /* Hack for WLAN: start a second helper */
674 if (0 == strcmp(plugin, "wlan")) 679 if (0 == strcmp (plugin, "wlan"))
675 { 680 {
676 char * helper_argv[3]; 681 char *helper_argv[3];
677 helper_argv[0] = (char *)"gnunet-helper-transport-wlan-dummy"; 682 helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
678 helper_argv[1] = (char *)"2"; 683 helper_argv[1] = (char *) "2";
679 helper_argv[2] = NULL; 684 helper_argv[2] = NULL;
680 suid_helper = GNUNET_HELPER_start(GNUNET_NO, 685 suid_helper = GNUNET_HELPER_start (GNUNET_NO,
681 "gnunet-helper-transport-wlan-dummy", helper_argv, 686 "gnunet-helper-transport-wlan-dummy",
682 &handle_helper_message, NULL, NULL); 687 helper_argv,
683 } 688 &handle_helper_message, NULL, NULL);
689 }
684 690
685 /* Loading plugin */ 691 /* Loading plugin */
686 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); 692 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin);
687 GNUNET_asprintf(&libname, "libgnunet_plugin_transport_%s", plugin); 693 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin);
688 api = GNUNET_PLUGIN_load(libname, &env); 694 api = GNUNET_PLUGIN_load (libname, &env);
689 if (NULL == api) 695 if (NULL == api)
690 { 696 {
691 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 697 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
692 "Failed to load transport plugin for %s\n", plugin); 698 "Failed to load transport plugin for %s\n", plugin);
693 end_badly_now(); 699 end_badly_now ();
694 return; 700 return;
695 } 701 }
696 702
697 timeout_wait = GNUNET_SCHEDULER_add_delayed(WAIT, &wait_end, NULL); 703 timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
698 704
699 /* Check if all functions are implemented */ 705 /* Check if all functions are implemented */
700 if (NULL == api->address_pretty_printer) 706 if (NULL == api->address_pretty_printer)
701 { 707 {
702 GNUNET_break(0); 708 GNUNET_break (0);
703 end_badly_now(); 709 end_badly_now ();
704 return; 710 return;
705 } 711 }
706 if (NULL == api->address_to_string) 712 if (NULL == api->address_to_string)
707 { 713 {
708 GNUNET_break(0); 714 GNUNET_break (0);
709 end_badly_now(); 715 end_badly_now ();
710 return; 716 return;
711 } 717 }
712 GNUNET_assert(NULL != api->check_address); 718 GNUNET_assert (NULL != api->check_address);
713 if (NULL == api->check_address) 719 if (NULL == api->check_address)
714 { 720 {
715 GNUNET_break(0); 721 GNUNET_break (0);
716 end_badly_now(); 722 end_badly_now ();
717 return; 723 return;
718 } 724 }
719 GNUNET_assert(NULL != api->disconnect_peer); 725 GNUNET_assert (NULL != api->disconnect_peer);
720 if (NULL == api->disconnect_peer) 726 if (NULL == api->disconnect_peer)
721 { 727 {
722 GNUNET_break(0); 728 GNUNET_break (0);
723 end_badly_now(); 729 end_badly_now ();
724 return; 730 return;
725 } 731 }
726 GNUNET_assert(NULL != api->get_session); 732 GNUNET_assert (NULL != api->get_session);
727 if (NULL == api->get_session) 733 if (NULL == api->get_session)
728 { 734 {
729 GNUNET_break(0); 735 GNUNET_break (0);
730 end_badly_now(); 736 end_badly_now ();
731 return; 737 return;
732 } 738 }
733 if (NULL == api->address_pretty_printer) 739 if (NULL == api->address_pretty_printer)
734 { 740 {
735 GNUNET_break(0); 741 GNUNET_break (0);
736 end_badly_now(); 742 end_badly_now ();
737 return; 743 return;
738 } 744 }
739 if (NULL == api->string_to_address) 745 if (NULL == api->string_to_address)
740 { 746 {
741 GNUNET_break(0); 747 GNUNET_break (0);
742 end_badly_now(); 748 end_badly_now ();
743 return; 749 return;
744 } 750 }
745} 751}
746 752
747 753
@@ -753,32 +759,32 @@ run(void *cls,
753 * @return 0 ok, 1 on error 759 * @return 0 ok, 1 on error
754 */ 760 */
755int 761int
756main(int argc, 762main (int argc,
757 char * const *argv) 763 char *const *argv)
758{ 764{
759 static struct GNUNET_GETOPT_CommandLineOption options[] = { 765 static struct GNUNET_GETOPT_CommandLineOption options[] = {
760 GNUNET_GETOPT_OPTION_END 766 GNUNET_GETOPT_OPTION_END
761 }; 767 };
762 int ret; 768 int ret;
763 char * const argv_prog[] = { 769 char *const argv_prog[] = {
764 "test_plugin_transport", 770 "test_plugin_transport",
765 "-c", 771 "-c",
766 "test_plugin_transport_data.conf", 772 "test_plugin_transport_data.conf",
767 NULL 773 NULL
768 }; 774 };
769 775
770 GNUNET_log_setup("test-plugin-transport", 776 GNUNET_log_setup ("test-plugin-transport",
771 "WARNING", 777 "WARNING",
772 NULL); 778 NULL);
773 GNUNET_DISK_purge_cfg_dir("test_plugin_transport_data.conf", 779 GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
774 "GNUNET_TEST_HOME"); 780 "GNUNET_TEST_HOME");
775 ok = 1; /* set to fail */ 781 ok = 1; /* set to fail */
776 ret = 782 ret =
777 (GNUNET_OK 783 (GNUNET_OK
778 == GNUNET_PROGRAM_run(3, argv_prog, "test-plugin-transport", 784 == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport",
779 "testcase", options, &run, (void *)argv)) ? ok : 1; 785 "testcase", options, &run, (void *) argv)) ? ok : 1;
780 GNUNET_DISK_purge_cfg_dir("test_plugin_transport_data.conf", 786 GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
781 "GNUNET_TEST_HOME"); 787 "GNUNET_TEST_HOME");
782 return ret; 788 return ret;
783} 789}
784 790
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 @@
32/** 32/**
33 * Testcase timeout 33 * Testcase timeout
34 */ 34 */
35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 480) 35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 480)
36 36
37#define DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 80) 37#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 80)
38 38
39 39
40static struct GNUNET_SCHEDULER_Task *measure_task; 40static struct GNUNET_SCHEDULER_Task *measure_task;
@@ -61,61 +61,61 @@ static struct GNUNET_TIME_Absolute start_time;
61 61
62 62
63static void 63static void
64report() 64report ()
65{ 65{
66 unsigned long long delta; 66 unsigned long long delta;
67 unsigned long long datarate; 67 unsigned long long datarate;
68 68
69 delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us; 69 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
70 if (0 == delta) 70 if (0 == delta)
71 delta = 1; 71 delta = 1;
72 datarate = (total_bytes_recv * 1000 * 1000) / delta; 72 datarate = (total_bytes_recv * 1000 * 1000) / delta;
73 73
74 fprintf(stderr, 74 fprintf (stderr,
75 "Throughput was %llu b/s\n", 75 "Throughput was %llu b/s\n",
76 datarate); 76 datarate);
77 ccc->global_ret = GNUNET_OK; 77 ccc->global_ret = GNUNET_OK;
78 if (datarate > 1.5 * quota_in[1]) 78 if (datarate > 1.5 * quota_in[1])
79 { 79 {
80 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 80 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
81 "Datarate of %llu b/s significantly higher than allowed inbound quota of %llu b/s\n", 81 "Datarate of %llu b/s significantly higher than allowed inbound quota of %llu b/s\n",
82 datarate, 82 datarate,
83 quota_in[1]); 83 quota_in[1]);
84 ccc->global_ret = GNUNET_SYSERR; 84 ccc->global_ret = GNUNET_SYSERR;
85 } 85 }
86 if (datarate > 1.5 * quota_out[0]) 86 if (datarate > 1.5 * quota_out[0])
87 { 87 {
88 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 88 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
89 "Datarate of %llu b/s significantly higher than allowed outbound quota of %llu b/s\n", 89 "Datarate of %llu b/s significantly higher than allowed outbound quota of %llu b/s\n",
90 datarate, 90 datarate,
91 quota_out[0]); 91 quota_out[0]);
92 ccc->global_ret = GNUNET_SYSERR; 92 ccc->global_ret = GNUNET_SYSERR;
93 } 93 }
94 if (GNUNET_OK == ccc->global_ret) 94 if (GNUNET_OK == ccc->global_ret)
95 { 95 {
96 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
97 "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", 97 "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n",
98 datarate, 98 datarate,
99 quota_out[0], 99 quota_out[0],
100 quota_in[1]); 100 quota_in[1]);
101 } 101 }
102} 102}
103 103
104 104
105static void 105static void
106custom_shutdown(void *cls) 106custom_shutdown (void *cls)
107{ 107{
108 if (NULL != measure_task) 108 if (NULL != measure_task)
109 { 109 {
110 GNUNET_SCHEDULER_cancel(measure_task); 110 GNUNET_SCHEDULER_cancel (measure_task);
111 measure_task = NULL; 111 measure_task = NULL;
112 } 112 }
113 report(); 113 report ();
114} 114}
115 115
116 116
117static size_t 117static size_t
118get_size(unsigned int iter) 118get_size (unsigned int iter)
119{ 119{
120 size_t ret; 120 size_t ret;
121 121
@@ -126,52 +126,52 @@ get_size(unsigned int iter)
126 126
127 127
128static void 128static void
129notify_receive(void *cls, 129notify_receive (void *cls,
130 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 130 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
131 const struct GNUNET_PeerIdentity *sender, 131 const struct GNUNET_PeerIdentity *sender,
132 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) 132 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
133{ 133{
134 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type)) 134 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type))
135 return; 135 return;
136 total_bytes_recv += ntohs(hdr->header.size); 136 total_bytes_recv += ntohs (hdr->header.size);
137 137
138 { 138 {
139 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 139 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
140 140
141 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 141 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
142 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", 142 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
143 receiver->no, 143 receiver->no,
144 ps, 144 ps,
145 ntohl(hdr->num), 145 ntohl (hdr->num),
146 ntohs(hdr->header.size), 146 ntohs (hdr->header.size),
147 GNUNET_i2s(sender)); 147 GNUNET_i2s (sender));
148 GNUNET_free(ps); 148 GNUNET_free (ps);
149 } 149 }
150} 150}
151 151
152 152
153static void 153static void
154measure(void *cls) 154measure (void *cls)
155{ 155{
156 static int counter; 156 static int counter;
157 157
158 measure_task = NULL; 158 measure_task = NULL;
159 counter++; 159 counter++;
160 if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) 160 if ((DURATION.rel_value_us / 1000 / 1000LL) < counter)
161 { 161 {
162 fprintf(stderr, "%s", ".\n"); 162 fprintf (stderr, "%s", ".\n");
163 GNUNET_SCHEDULER_shutdown(); 163 GNUNET_SCHEDULER_shutdown ();
164 return; 164 return;
165 } 165 }
166 fprintf(stderr, "%s", "."); 166 fprintf (stderr, "%s", ".");
167 measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 167 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
168 &measure, 168 &measure,
169 NULL); 169 NULL);
170} 170}
171 171
172 172
173static void 173static void
174start_task(void *cls) 174start_task (void *cls)
175{ 175{
176 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 176 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
177 .num_messages = TOTAL_MSGS, 177 .num_messages = TOTAL_MSGS,
@@ -179,71 +179,71 @@ start_task(void *cls)
179 }; 179 };
180 180
181 sc.ccc = ccc; 181 sc.ccc = ccc;
182 measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 182 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
183 &measure, 183 &measure,
184 NULL); 184 NULL);
185 start_time = GNUNET_TIME_absolute_get(); 185 start_time = GNUNET_TIME_absolute_get ();
186 GNUNET_SCHEDULER_add_now(&GNUNET_TRANSPORT_TESTING_simple_send, 186 GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send,
187 &sc); 187 &sc);
188} 188}
189 189
190 190
191static char * 191static char *
192generate_config(const char *cfg_file, 192generate_config (const char *cfg_file,
193 unsigned long long quota_in, 193 unsigned long long quota_in,
194 unsigned long long quota_out) 194 unsigned long long quota_out)
195{ 195{
196 char *in_name; 196 char *in_name;
197 char *out_name; 197 char *out_name;
198 char *fname = NULL; 198 char *fname = NULL;
199 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create(); 199 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
200 200
201 GNUNET_assert(GNUNET_OK == 201 GNUNET_assert (GNUNET_OK ==
202 GNUNET_CONFIGURATION_load(cfg, 202 GNUNET_CONFIGURATION_load (cfg,
203 cfg_file)); 203 cfg_file));
204 GNUNET_asprintf(&fname, 204 GNUNET_asprintf (&fname,
205 "q_in_%llu_q_out_%llu_%s", 205 "q_in_%llu_q_out_%llu_%s",
206 quota_in, 206 quota_in,
207 quota_out, 207 quota_out,
208 cfg_file); 208 cfg_file);
209 GNUNET_CONFIGURATION_set_value_string(cfg, 209 GNUNET_CONFIGURATION_set_value_string (cfg,
210 "PATHS", 210 "PATHS",
211 "DEFAULTCONFIG", 211 "DEFAULTCONFIG",
212 fname); 212 fname);
213 for (int c = 0; c < GNUNET_NT_COUNT; c++) 213 for (int c = 0; c < GNUNET_NT_COUNT; c++)
214 { 214 {
215 GNUNET_asprintf(&in_name, 215 GNUNET_asprintf (&in_name,
216 "%s_QUOTA_IN", 216 "%s_QUOTA_IN",
217 GNUNET_NT_to_string(c)); 217 GNUNET_NT_to_string (c));
218 GNUNET_asprintf(&out_name, 218 GNUNET_asprintf (&out_name,
219 "%s_QUOTA_OUT", 219 "%s_QUOTA_OUT",
220 GNUNET_NT_to_string(c)); 220 GNUNET_NT_to_string (c));
221 GNUNET_CONFIGURATION_set_value_number(cfg, 221 GNUNET_CONFIGURATION_set_value_number (cfg,
222 "ats", 222 "ats",
223 in_name, 223 in_name,
224 quota_in); 224 quota_in);
225 GNUNET_CONFIGURATION_set_value_number(cfg, 225 GNUNET_CONFIGURATION_set_value_number (cfg,
226 "ats", 226 "ats",
227 out_name, 227 out_name,
228 quota_out); 228 quota_out);
229 GNUNET_free(in_name); 229 GNUNET_free (in_name);
230 GNUNET_free(out_name); 230 GNUNET_free (out_name);
231 } 231 }
232 GNUNET_assert(GNUNET_OK == 232 GNUNET_assert (GNUNET_OK ==
233 GNUNET_CONFIGURATION_write(cfg, 233 GNUNET_CONFIGURATION_write (cfg,
234 fname)); 234 fname));
235 GNUNET_CONFIGURATION_destroy(cfg); 235 GNUNET_CONFIGURATION_destroy (cfg);
236 return fname; 236 return fname;
237} 237}
238 238
239 239
240static int 240static int
241check(void *cls, 241check (void *cls,
242 struct GNUNET_TRANSPORT_TESTING_Handle *tth_, 242 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
243 const char *test_plugin_, 243 const char *test_plugin_,
244 const char *test_name_, 244 const char *test_name_,
245 unsigned int num_peers, 245 unsigned int num_peers,
246 char *cfg_files[]) 246 char *cfg_files[])
247{ 247{
248 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 248 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
249 .connect_continuation = &start_task, 249 .connect_continuation = &start_task,
@@ -257,63 +257,63 @@ check(void *cls,
257 257
258 ccc = &my_ccc; 258 ccc = &my_ccc;
259 259
260 if (NULL != strstr(test_name_, 260 if (NULL != strstr (test_name_,
261 "asymmetric")) 261 "asymmetric"))
262 { 262 {
263 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", 264 "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n",
265 quota_in[1], 265 quota_in[1],
266 quota_out[1]); 266 quota_out[1]);
267 quota_out[0] = 1024 * 1024 * 1024; 267 quota_out[0] = 1024 * 1024 * 1024;
268 quota_in[0] = 1024 * 1024 * 1024; 268 quota_in[0] = 1024 * 1024 * 1024;
269 } 269 }
270 else 270 else
271 { 271 {
272 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "Running symmetric test with (in/out) %llu/%llu b/s \n", 273 "Running symmetric test with (in/out) %llu/%llu b/s \n",
274 quota_in[1], 274 quota_in[1],
275 quota_out[1]); 275 quota_out[1]);
276 } 276 }
277 for (unsigned int i = 0; i < 2; i++) 277 for (unsigned int i = 0; i < 2; i++)
278 { 278 {
279 gen_cfgs[i] = generate_config(cfg_files[i], 279 gen_cfgs[i] = generate_config (cfg_files[i],
280 quota_in[i], 280 quota_in[i],
281 quota_out[i]); 281 quota_out[i]);
282 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
283 "Generated config file `%s'\n", 283 "Generated config file `%s'\n",
284 gen_cfgs[i]); 284 gen_cfgs[i]);
285 } 285 }
286 286
287 return GNUNET_TRANSPORT_TESTING_connect_check(&my_ccc, 287 return GNUNET_TRANSPORT_TESTING_connect_check (&my_ccc,
288 tth_, 288 tth_,
289 test_plugin_, 289 test_plugin_,
290 test_name_, 290 test_name_,
291 num_peers, 291 num_peers,
292 gen_cfgs); 292 gen_cfgs);
293} 293}
294 294
295 295
296int 296int
297main(int argc, 297main (int argc,
298 char *argv[]) 298 char *argv[])
299{ 299{
300 if (GNUNET_OK != 300 if (GNUNET_OK !=
301 GNUNET_TRANSPORT_TESTING_main(2, 301 GNUNET_TRANSPORT_TESTING_main (2,
302 &check, 302 &check,
303 NULL)) 303 NULL))
304 { 304 {
305 GNUNET_break(0); 305 GNUNET_break (0);
306 return 1; 306 return 1;
307 } 307 }
308 for (unsigned int i = 0; i < 2; i++) 308 for (unsigned int i = 0; i < 2; i++)
309 {
310 if ((NULL != gen_cfgs[i]) &&
311 (GNUNET_YES == GNUNET_DISK_file_test (gen_cfgs[i])))
309 { 312 {
310 if ((NULL != gen_cfgs[i]) && 313 GNUNET_DISK_directory_remove (gen_cfgs[i]);
311 (GNUNET_YES == GNUNET_DISK_file_test(gen_cfgs[i]))) 314 GNUNET_free (gen_cfgs[i]);
312 {
313 GNUNET_DISK_directory_remove(gen_cfgs[i]);
314 GNUNET_free(gen_cfgs[i]);
315 }
316 } 315 }
316 }
317 return 0; 317 return 0;
318} 318}
319 319
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 @@
51/** 51/**
52 * Testcase timeout (set aggressively as we know this test doesn't work right now) 52 * Testcase timeout (set aggressively as we know this test doesn't work right now)
53 */ 53 */
54#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 54#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
55 55
56 56
57static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 57static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
@@ -62,7 +62,8 @@ static struct GNUNET_SCHEDULER_Task *measure_task;
62/** 62/**
63 * Statistics we track per peer. 63 * Statistics we track per peer.
64 */ 64 */
65struct PeerStats { 65struct PeerStats
66{
66 struct GNUNET_STATISTICS_Handle *stat; 67 struct GNUNET_STATISTICS_Handle *stat;
67 68
68 unsigned int addresses_avail; 69 unsigned int addresses_avail;
@@ -83,16 +84,16 @@ static unsigned long long bytes_recv_after_switch;
83 84
84 85
85static int 86static int
86stat_start_attempt_cb(void *cls, 87stat_start_attempt_cb (void *cls,
87 const char *subsystem, 88 const char *subsystem,
88 const char *name, 89 const char *name,
89 uint64_t value, 90 uint64_t value,
90 int is_persistent) 91 int is_persistent)
91{ 92{
92 struct PeerStats *stat = cls; 93 struct PeerStats *stat = cls;
93 94
94 stat->switch_attempts++; 95 stat->switch_attempts++;
95 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Switch attempted (%p)", stat); 96 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch attempted (%p)", stat);
96 bytes_recv_after_switch = 0; 97 bytes_recv_after_switch = 0;
97 bytes_sent_after_switch = 0; 98 bytes_sent_after_switch = 0;
98 99
@@ -101,26 +102,26 @@ stat_start_attempt_cb(void *cls,
101 102
102 103
103static int 104static int
104stat_success_attempt_cb(void *cls, 105stat_success_attempt_cb (void *cls,
105 const char *subsystem, 106 const char *subsystem,
106 const char *name, 107 const char *name,
107 uint64_t value, 108 uint64_t value,
108 int is_persistent) 109 int is_persistent)
109{ 110{
110 struct PeerStats *stat = cls; 111 struct PeerStats *stat = cls;
111 112
112 stat->switch_success++; 113 stat->switch_success++;
113 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Switch succeeded (%p)", stat); 114 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch succeeded (%p)", stat);
114 return GNUNET_OK; 115 return GNUNET_OK;
115} 116}
116 117
117 118
118static int 119static int
119stat_fail_attempt_cb(void *cls, 120stat_fail_attempt_cb (void *cls,
120 const char *subsystem, 121 const char *subsystem,
121 const char *name, 122 const char *name,
122 uint64_t value, 123 uint64_t value,
123 int is_persistent) 124 int is_persistent)
124{ 125{
125 struct PeerStats *stat = cls; 126 struct PeerStats *stat = cls;
126 127
@@ -128,17 +129,17 @@ stat_fail_attempt_cb(void *cls,
128 return GNUNET_OK; 129 return GNUNET_OK;
129 130
130 stat->switch_fail++; 131 stat->switch_fail++;
131 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Switch failed (%p)", stat); 132 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Switch failed (%p)", stat);
132 return GNUNET_OK; 133 return GNUNET_OK;
133} 134}
134 135
135 136
136static int 137static int
137stat_addresses_available(void *cls, 138stat_addresses_available (void *cls,
138 const char *subsystem, 139 const char *subsystem,
139 const char *name, 140 const char *name,
140 uint64_t value, 141 uint64_t value,
141 int is_persistent) 142 int is_persistent)
142{ 143{
143 struct PeerStats *stat = cls; 144 struct PeerStats *stat = cls;
144 145
@@ -150,7 +151,8 @@ stat_addresses_available(void *cls,
150/** 151/**
151 * List of statistics entries we care about. 152 * List of statistics entries we care about.
152 */ 153 */
153static struct WatchEntry { 154static struct WatchEntry
155{
154 /** 156 /**
155 * Name of the statistic we watch. 157 * Name of the statistic we watch.
156 */ 158 */
@@ -164,112 +166,112 @@ static struct WatchEntry {
164{ { "# Attempts to switch addresses", &stat_start_attempt_cb }, 166{ { "# Attempts to switch addresses", &stat_start_attempt_cb },
165 { "# Successful attempts to switch addresses", &stat_success_attempt_cb }, 167 { "# Successful attempts to switch addresses", &stat_success_attempt_cb },
166 { "# Failed attempts to switch addresses (failed to send CONNECT CONT)", 168 { "# Failed attempts to switch addresses (failed to send CONNECT CONT)",
167 &stat_fail_attempt_cb }, 169 &stat_fail_attempt_cb },
168 { "# Failed attempts to switch addresses (failed to send CONNECT)", 170 { "# Failed attempts to switch addresses (failed to send CONNECT)",
169 &stat_fail_attempt_cb }, 171 &stat_fail_attempt_cb },
170 { "# Failed attempts to switch addresses (no response)", 172 { "# Failed attempts to switch addresses (no response)",
171 &stat_fail_attempt_cb }, 173 &stat_fail_attempt_cb },
172 { "# transport addresses", &stat_addresses_available }, 174 { "# transport addresses", &stat_addresses_available },
173 { NULL, NULL } }; 175 { NULL, NULL } };
174 176
175 177
176static void 178static void
177custom_shutdown(void *cls) 179custom_shutdown (void *cls)
178{ 180{
179 int result; 181 int result;
180 182
181 if (NULL != measure_task) 183 if (NULL != measure_task)
182 { 184 {
183 GNUNET_SCHEDULER_cancel(measure_task); 185 GNUNET_SCHEDULER_cancel (measure_task);
184 measure_task = NULL; 186 measure_task = NULL;
185 } 187 }
186 if (0 == stats[0].switch_attempts + stats[1].switch_attempts) 188 if (0 == stats[0].switch_attempts + stats[1].switch_attempts)
187 { 189 {
188 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 190 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
189 "Test did not work, as peers didn't switch (flawed testcase)!\n"); 191 "Test did not work, as peers didn't switch (flawed testcase)!\n");
190 ccc->global_ret = 77; 192 ccc->global_ret = 77;
191 } 193 }
192 else 194 else
193 { 195 {
194 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
195 "Fail (timeout)! No transmission after switch! Stopping peers\n"); 197 "Fail (timeout)! No transmission after switch! Stopping peers\n");
196 ccc->global_ret = 77; /* GNUNET_SYSERR; */ 198 ccc->global_ret = 77; /* GNUNET_SYSERR; */
197 } 199 }
198 200
199 /* stop statistics */ 201 /* stop statistics */
200 for (unsigned int i = 0; i < 2; i++) 202 for (unsigned int i = 0; i < 2; i++)
203 {
204 if (NULL != stats[i].stat)
201 { 205 {
202 if (NULL != stats[i].stat) 206 for (unsigned int j = 0; NULL != watches[j].stat_name; j++)
203 { 207 GNUNET_assert (GNUNET_OK ==
204 for (unsigned int j = 0; NULL != watches[j].stat_name; j++) 208 GNUNET_STATISTICS_watch_cancel (stats[i].stat,
205 GNUNET_assert(GNUNET_OK == 209 "transport",
206 GNUNET_STATISTICS_watch_cancel(stats[i].stat, 210 watches[j].stat_name,
207 "transport", 211 watches[j].stat_handler,
208 watches[j].stat_name, 212 &stats[i]));
209 watches[j].stat_handler, 213 GNUNET_STATISTICS_destroy (stats[i].stat, GNUNET_NO);
210 &stats[i])); 214 stats[i].stat = NULL;
211 GNUNET_STATISTICS_destroy(stats[i].stat, GNUNET_NO);
212 stats[i].stat = NULL;
213 }
214 } 215 }
216 }
215 217
216 result = 0; 218 result = 0;
217 fprintf(stderr, "\n"); 219 fprintf (stderr, "\n");
218 if (stats[0].switch_attempts > 0) 220 if (stats[0].switch_attempts > 0)
221 {
222 fprintf (
223 stderr,
224 "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n",
225 stats[0].switch_attempts,
226 stats[0].switch_success,
227 stats[0].switch_fail);
228 if (stats[0].switch_success != stats[0].switch_attempts)
219 { 229 {
220 fprintf( 230 GNUNET_break (0);
221 stderr, 231 result++;
222 "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n",
223 stats[0].switch_attempts,
224 stats[0].switch_success,
225 stats[0].switch_fail);
226 if (stats[0].switch_success != stats[0].switch_attempts)
227 {
228 GNUNET_break(0);
229 result++;
230 }
231 } 232 }
233 }
232 else if (stats[0].addresses_avail > 1) 234 else if (stats[0].addresses_avail > 1)
233 { 235 {
234 fprintf(stderr, 236 fprintf (stderr,
235 "Peer 1 had %u addresses available, but did not try to switch\n", 237 "Peer 1 had %u addresses available, but did not try to switch\n",
236 stats[0].addresses_avail); 238 stats[0].addresses_avail);
237 } 239 }
238 if (stats[1].switch_attempts > 0) 240 if (stats[1].switch_attempts > 0)
241 {
242 fprintf (
243 stderr,
244 "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n",
245 stats[1].switch_attempts,
246 stats[1].switch_success,
247 stats[1].switch_fail);
248 if (stats[1].switch_success != stats[1].switch_attempts)
239 { 249 {
240 fprintf( 250 GNUNET_break (0);
241 stderr, 251 result++;
242 "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n",
243 stats[1].switch_attempts,
244 stats[1].switch_success,
245 stats[1].switch_fail);
246 if (stats[1].switch_success != stats[1].switch_attempts)
247 {
248 GNUNET_break(0);
249 result++;
250 }
251 } 252 }
253 }
252 else if (stats[1].addresses_avail > 1) 254 else if (stats[1].addresses_avail > 1)
253 { 255 {
254 fprintf(stderr, 256 fprintf (stderr,
255 "Peer 2 had %u addresses available, but did not try to switch\n", 257 "Peer 2 had %u addresses available, but did not try to switch\n",
256 stats[1].addresses_avail); 258 stats[1].addresses_avail);
257 } 259 }
258 260
259 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && 261 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
260 (bytes_sent_after_switch == 0)) 262 (bytes_sent_after_switch == 0))
261 { 263 {
262 fprintf(stderr, "No data sent after switching!\n"); 264 fprintf (stderr, "No data sent after switching!\n");
263 GNUNET_break(0); 265 GNUNET_break (0);
264 result++; 266 result++;
265 } 267 }
266 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && 268 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
267 (bytes_recv_after_switch == 0)) 269 (bytes_recv_after_switch == 0))
268 { 270 {
269 fprintf(stderr, "No data received after switching!\n"); 271 fprintf (stderr, "No data received after switching!\n");
270 GNUNET_break(0); 272 GNUNET_break (0);
271 result++; 273 result++;
272 } 274 }
273#if 0 275#if 0
274 /* This test is not really expected to pass right now... */ 276 /* This test is not really expected to pass right now... */
275 if (0 != result) 277 if (0 != result)
@@ -279,132 +281,132 @@ custom_shutdown(void *cls)
279 281
280 282
281static void 283static void
282notify_receive(void *cls, 284notify_receive (void *cls,
283 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 285 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
284 const struct GNUNET_PeerIdentity *sender, 286 const struct GNUNET_PeerIdentity *sender,
285 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) 287 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
286{ 288{
287 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type)) 289 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type))
288 return; 290 return;
289 291
290 { 292 {
291 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 293 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
292 294
293 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 295 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
294 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", 296 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
295 receiver->no, 297 receiver->no,
296 ps, 298 ps,
297 (uint32_t)ntohl(hdr->num), 299 (uint32_t) ntohl (hdr->num),
298 ntohs(hdr->header.size), 300 ntohs (hdr->header.size),
299 GNUNET_i2s(sender)); 301 GNUNET_i2s (sender));
300 GNUNET_free(ps); 302 GNUNET_free (ps);
301 } 303 }
302 if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && 304 if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) &&
303 (stats[0].switch_attempts == 305 (stats[0].switch_attempts ==
304 stats[0].switch_fail + stats[0].switch_success) && 306 stats[0].switch_fail + stats[0].switch_success) &&
305 (stats[1].switch_attempts == 307 (stats[1].switch_attempts ==
306 stats[1].switch_fail + stats[1].switch_success)) 308 stats[1].switch_fail + stats[1].switch_success))
309 {
310 bytes_recv_after_switch += ntohs (hdr->header.size);
311 if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0))
307 { 312 {
308 bytes_recv_after_switch += ntohs(hdr->header.size); 313 /* A peer switched addresses and sent and received data after the
309 if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0)) 314 * switch operations */
310 { 315 GNUNET_SCHEDULER_shutdown ();
311 /* A peer switched addresses and sent and received data after the
312 * switch operations */
313 GNUNET_SCHEDULER_shutdown();
314 }
315 } 316 }
317 }
316} 318}
317 319
318 320
319static void 321static void
320notify_send(void *cls) 322notify_send (void *cls)
321{ 323{
322 static uint32_t cnt; 324 static uint32_t cnt;
323 325
324 GNUNET_assert( 326 GNUNET_assert (
325 GNUNET_OK == 327 GNUNET_OK ==
326 GNUNET_TRANSPORT_TESTING_send(ccc->p[1], 328 GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
327 ccc->p[0], 329 ccc->p[0],
328 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 330 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
329 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, 331 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE,
330 ++cnt, 332 ++cnt,
331 &notify_send, 333 &notify_send,
332 NULL)); 334 NULL));
333 if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && 335 if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) &&
334 (stats[0].switch_attempts == 336 (stats[0].switch_attempts ==
335 stats[0].switch_fail + stats[0].switch_success) && 337 stats[0].switch_fail + stats[0].switch_success) &&
336 (stats[1].switch_attempts == 338 (stats[1].switch_attempts ==
337 stats[1].switch_fail + stats[1].switch_success)) 339 stats[1].switch_fail + stats[1].switch_success))
338 { 340 {
339 bytes_sent_after_switch += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE; 341 bytes_sent_after_switch += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE;
340 } 342 }
341} 343}
342 344
343 345
344static void 346static void
345progress_indicator(void *cls) 347progress_indicator (void *cls)
346{ 348{
347 static int counter; 349 static int counter;
348 350
349 measure_task = NULL; 351 measure_task = NULL;
350 counter++; 352 counter++;
351 if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter) 353 if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter)
352 { 354 {
353 fprintf(stderr, "%s", ".\n"); 355 fprintf (stderr, "%s", ".\n");
354 } 356 }
355 else 357 else
356 { 358 {
357 fprintf(stderr, "%s", "."); 359 fprintf (stderr, "%s", ".");
358 measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 360 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
359 &progress_indicator, 361 &progress_indicator,
360 NULL); 362 NULL);
361 } 363 }
362} 364}
363 365
364 366
365static void 367static void
366connected_cb(void *cls) 368connected_cb (void *cls)
367{ 369{
368 for (unsigned int i = 0; i < 2; i++) 370 for (unsigned int i = 0; i < 2; i++)
371 {
372 stats[i].stat = GNUNET_STATISTICS_create ("transport", ccc->p[i]->cfg);
373 if (NULL == stats[i].stat)
369 { 374 {
370 stats[i].stat = GNUNET_STATISTICS_create("transport", ccc->p[i]->cfg); 375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
371 if (NULL == stats[i].stat) 376 "Fail! Could not create statistics for peers!\n");
372 { 377 ccc->global_ret = GNUNET_SYSERR;
373 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 378 GNUNET_SCHEDULER_shutdown ();
374 "Fail! Could not create statistics for peers!\n"); 379 return;
375 ccc->global_ret = GNUNET_SYSERR; 380 }
376 GNUNET_SCHEDULER_shutdown(); 381 for (unsigned int j = 0; NULL != watches[j].stat_name; j++)
377 return; 382 {
378 } 383 GNUNET_STATISTICS_watch (stats[i].stat,
379 for (unsigned int j = 0; NULL != watches[j].stat_name; j++) 384 "transport",
380 { 385 watches[j].stat_name,
381 GNUNET_STATISTICS_watch(stats[i].stat, 386 watches[j].stat_handler,
382 "transport", 387 &stats[i]);
383 watches[j].stat_name,
384 watches[j].stat_handler,
385 &stats[i]);
386 }
387 } 388 }
389 }
388 /* Show progress */ 390 /* Show progress */
389 ccc->global_ret = GNUNET_OK; 391 ccc->global_ret = GNUNET_OK;
390 measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 392 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
391 &progress_indicator, 393 &progress_indicator,
392 NULL); 394 NULL);
393 /* Peers are connected, start transmit test messages */ 395 /* Peers are connected, start transmit test messages */
394 GNUNET_assert( 396 GNUNET_assert (
395 GNUNET_OK == 397 GNUNET_OK ==
396 GNUNET_TRANSPORT_TESTING_send(ccc->p[1], 398 GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
397 ccc->p[0], 399 ccc->p[0],
398 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 400 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
399 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, 401 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE,
400 0, 402 0,
401 &notify_send, 403 &notify_send,
402 NULL)); 404 NULL));
403} 405}
404 406
405 407
406int 408int
407main(int argc, char *argv[]) 409main (int argc, char *argv[])
408{ 410{
409 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = 411 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc =
410 { .connect_continuation = &connected_cb, 412 { .connect_continuation = &connected_cb,
@@ -417,9 +419,9 @@ main(int argc, char *argv[])
417 ccc = &my_ccc; 419 ccc = &my_ccc;
418 int ret; 420 int ret;
419 421
420 ret = GNUNET_TRANSPORT_TESTING_main(2, 422 ret = GNUNET_TRANSPORT_TESTING_main (2,
421 &GNUNET_TRANSPORT_TESTING_connect_check, 423 &GNUNET_TRANSPORT_TESTING_connect_check,
422 ccc); 424 ccc);
423 if (77 == ret) 425 if (77 == ret)
424 return 77; 426 return 77;
425 if (GNUNET_OK != ret) 427 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 @@
34/** 34/**
35 * How long until we give up on transmitting the message? 35 * How long until we give up on transmitting the message?
36 */ 36 */
37#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
38 38
39static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 39static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
40 40
41 41
42static void 42static void
43notify_receive(void *cls, 43notify_receive (void *cls,
44 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 44 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
45 const struct GNUNET_PeerIdentity *sender, 45 const struct GNUNET_PeerIdentity *sender,
46 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 46 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
47{ 47{
48 { 48 {
49 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 49 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
50 50
51 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 51 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
52 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", 52 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
53 receiver->no, 53 receiver->no,
54 ps, 54 ps,
55 ntohs(message->header.type), 55 ntohs (message->header.type),
56 ntohs(message->header.size), 56 ntohs (message->header.size),
57 GNUNET_i2s(sender)); 57 GNUNET_i2s (sender));
58 GNUNET_free(ps); 58 GNUNET_free (ps);
59 } 59 }
60 60
61 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs(message->header.type)) && 61 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) &&
62 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs(message->header.size))) 62 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs (
63 { 63 message->header.size)))
64 ccc->global_ret = GNUNET_OK; 64 {
65 GNUNET_SCHEDULER_shutdown(); 65 ccc->global_ret = GNUNET_OK;
66 } 66 GNUNET_SCHEDULER_shutdown ();
67 }
67 else 68 else
68 { 69 {
69 GNUNET_break(0); 70 GNUNET_break (0);
70 ccc->global_ret = GNUNET_SYSERR; 71 ccc->global_ret = GNUNET_SYSERR;
71 GNUNET_SCHEDULER_shutdown(); 72 GNUNET_SCHEDULER_shutdown ();
72 } 73 }
73} 74}
74 75
75 76
@@ -81,8 +82,8 @@ notify_receive(void *cls,
81 * in both directions simultaneously? 82 * in both directions simultaneously?
82 */ 83 */
83static int 84static int
84test(char *argv[], 85test (char *argv[],
85 int bi_directional) 86 int bi_directional)
86{ 87{
87 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 88 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
88 .num_messages = 1 89 .num_messages = 1
@@ -101,22 +102,22 @@ test(char *argv[],
101 ccc = &my_ccc; 102 ccc = &my_ccc;
102 sc.ccc = ccc; 103 sc.ccc = ccc;
103 if (GNUNET_OK != 104 if (GNUNET_OK !=
104 GNUNET_TRANSPORT_TESTING_main(2, 105 GNUNET_TRANSPORT_TESTING_main (2,
105 &GNUNET_TRANSPORT_TESTING_connect_check, 106 &GNUNET_TRANSPORT_TESTING_connect_check,
106 ccc)) 107 ccc))
107 return 1; 108 return 1;
108 return 0; 109 return 0;
109} 110}
110 111
111 112
112int 113int
113main(int argc, 114main (int argc,
114 char *argv[]) 115 char *argv[])
115{ 116{
116 if ((0 != test(argv, 117 if ((0 != test (argv,
117 GNUNET_NO)) || 118 GNUNET_NO)) ||
118 (0 != test(argv, 119 (0 != test (argv,
119 GNUNET_YES))) 120 GNUNET_YES)))
120 return 1; 121 return 1;
121 return 0; 122 return 0;
122} 123}
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 @@
28#include "gnunet_transport_service.h" 28#include "gnunet_transport_service.h"
29#include "transport-testing.h" 29#include "transport-testing.h"
30 30
31#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
32 32
33static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 33static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
34 34
@@ -46,135 +46,136 @@ static struct GNUNET_SCHEDULER_Task *shutdown_task;
46 46
47 47
48static void 48static void
49end(void *cls) 49end (void *cls)
50{ 50{
51 shutdown_task = NULL; 51 shutdown_task = NULL;
52 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 52 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
53 "Stopping\n"); 53 "Stopping\n");
54 if ((GNUNET_YES == blacklist_request_p1) && 54 if ((GNUNET_YES == blacklist_request_p1) &&
55 (GNUNET_YES == blacklist_request_p2) && 55 (GNUNET_YES == blacklist_request_p2) &&
56 (GNUNET_NO == connected)) 56 (GNUNET_NO == connected))
57 { 57 {
58 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 58 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
59 "Peers were never connected, success\n"); 59 "Peers were never connected, success\n");
60 ccc->global_ret = GNUNET_OK; 60 ccc->global_ret = GNUNET_OK;
61 } 61 }
62 else 62 else
63 { 63 {
64 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 64 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
65 "Peers were not connected, fail\n"); 65 "Peers were not connected, fail\n");
66 ccc->global_ret = GNUNET_SYSERR; 66 ccc->global_ret = GNUNET_SYSERR;
67 } 67 }
68 GNUNET_SCHEDULER_shutdown(); 68 GNUNET_SCHEDULER_shutdown ();
69} 69}
70 70
71 71
72static void 72static void
73custom_shutdown(void *cls) 73custom_shutdown (void *cls)
74{ 74{
75 if (NULL != shutdown_task) 75 if (NULL != shutdown_task)
76 { 76 {
77 GNUNET_SCHEDULER_cancel(shutdown_task); 77 GNUNET_SCHEDULER_cancel (shutdown_task);
78 shutdown_task = NULL; 78 shutdown_task = NULL;
79 } 79 }
80 if (NULL != blacklist_p1) 80 if (NULL != blacklist_p1)
81 { 81 {
82 GNUNET_TRANSPORT_blacklist_cancel(blacklist_p1); 82 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1);
83 blacklist_p1 = NULL; 83 blacklist_p1 = NULL;
84 } 84 }
85 if (NULL != blacklist_p2) 85 if (NULL != blacklist_p2)
86 { 86 {
87 GNUNET_TRANSPORT_blacklist_cancel(blacklist_p2); 87 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2);
88 blacklist_p2 = NULL; 88 blacklist_p2 = NULL;
89 } 89 }
90} 90}
91 91
92 92
93static void 93static void
94notify_receive(void *cls, 94notify_receive (void *cls,
95 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 95 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
96 const struct GNUNET_PeerIdentity *sender, 96 const struct GNUNET_PeerIdentity *sender,
97 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 97 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
98{ 98{
99 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 99 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
100 "Unexpectedly even received the message despite blacklist\n"); 100 "Unexpectedly even received the message despite blacklist\n");
101 connected = GNUNET_YES; 101 connected = GNUNET_YES;
102 GNUNET_SCHEDULER_cancel(shutdown_task); 102 GNUNET_SCHEDULER_cancel (shutdown_task);
103 end(NULL); 103 end (NULL);
104} 104}
105 105
106 106
107static void 107static void
108notify_connect(void *cls, 108notify_connect (void *cls,
109 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 109 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
110 const struct GNUNET_PeerIdentity *other) 110 const struct GNUNET_PeerIdentity *other)
111{ 111{
112 GNUNET_TRANSPORT_TESTING_log_connect(cls, 112 GNUNET_TRANSPORT_TESTING_log_connect (cls,
113 me, 113 me,
114 other); 114 other);
115 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 115 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
116 "Peers connected despite blacklist!\n"); 116 "Peers connected despite blacklist!\n");
117 connected = GNUNET_YES; /* this test now failed */ 117 connected = GNUNET_YES; /* this test now failed */
118 GNUNET_SCHEDULER_cancel(shutdown_task); 118 GNUNET_SCHEDULER_cancel (shutdown_task);
119 end(NULL); 119 end (NULL);
120} 120}
121 121
122 122
123static int 123static int
124blacklist_cb(void *cls, 124blacklist_cb (void *cls,
125 const struct GNUNET_PeerIdentity *pid) 125 const struct GNUNET_PeerIdentity *pid)
126{ 126{
127 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 127 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
128 int res = GNUNET_SYSERR; 128 int res = GNUNET_SYSERR;
129 129
130 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
131 "Peer %u: Blacklist request for peer `%s'\n", 131 "Peer %u: Blacklist request for peer `%s'\n",
132 p->no, 132 p->no,
133 GNUNET_i2s(pid)); 133 GNUNET_i2s (pid));
134 134
135 if (p == ccc->p[0]) 135 if (p == ccc->p[0])
136 { 136 {
137 blacklist_request_p1 = GNUNET_YES; 137 blacklist_request_p1 = GNUNET_YES;
138 res = GNUNET_OK; 138 res = GNUNET_OK;
139 } 139 }
140 if (p == ccc->p[1]) 140 if (p == ccc->p[1])
141 { 141 {
142 blacklist_request_p2 = GNUNET_YES; 142 blacklist_request_p2 = GNUNET_YES;
143 res = GNUNET_SYSERR; 143 res = GNUNET_SYSERR;
144 } 144 }
145 145
146 if ((GNUNET_YES == blacklist_request_p2) && 146 if ((GNUNET_YES == blacklist_request_p2) &&
147 (GNUNET_YES == blacklist_request_p1) && 147 (GNUNET_YES == blacklist_request_p1) &&
148 (NULL == shutdown_task)) 148 (NULL == shutdown_task))
149 { 149 {
150 shutdown_task 150 shutdown_task
151 = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3), 151 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
152 &end, 152 GNUNET_TIME_UNIT_SECONDS, 3),
153 NULL); 153 &end,
154 } 154 NULL);
155 }
155 return res; 156 return res;
156} 157}
157 158
158 159
159static void 160static void
160start_blacklist(void *cls) 161start_blacklist (void *cls)
161{ 162{
162 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "Starting blacklists\n"); 164 "Starting blacklists\n");
164 blacklist_p1 = GNUNET_TRANSPORT_blacklist(ccc->p[0]->cfg, 165 blacklist_p1 = GNUNET_TRANSPORT_blacklist (ccc->p[0]->cfg,
165 &blacklist_cb, 166 &blacklist_cb,
166 ccc->p[0]); 167 ccc->p[0]);
167 GNUNET_assert(NULL != blacklist_p1); 168 GNUNET_assert (NULL != blacklist_p1);
168 blacklist_p2 = GNUNET_TRANSPORT_blacklist(ccc->p[1]->cfg, 169 blacklist_p2 = GNUNET_TRANSPORT_blacklist (ccc->p[1]->cfg,
169 &blacklist_cb, 170 &blacklist_cb,
170 ccc->p[1]); 171 ccc->p[1]);
171 GNUNET_assert(NULL != blacklist_p2); 172 GNUNET_assert (NULL != blacklist_p2);
172} 173}
173 174
174 175
175int 176int
176main(int argc, 177main (int argc,
177 char *argv[]) 178 char *argv[])
178{ 179{
179 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 180 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
180 .num_messages = 1 181 .num_messages = 1
@@ -194,9 +195,9 @@ main(int argc,
194 195
195 ccc = &my_ccc; 196 ccc = &my_ccc;
196 if (GNUNET_OK != 197 if (GNUNET_OK !=
197 GNUNET_TRANSPORT_TESTING_main(2, 198 GNUNET_TRANSPORT_TESTING_main (2,
198 &GNUNET_TRANSPORT_TESTING_connect_check, 199 &GNUNET_TRANSPORT_TESTING_connect_check,
199 ccc)) 200 ccc))
200 return 1; 201 return 1;
201 return 0; 202 return 0;
202} 203}
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 @@
32/** 32/**
33 * How long until we give up on transmitting the message? 33 * How long until we give up on transmitting the message?
34 */ 34 */
35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
36 36
37 37
38static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 38static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
@@ -41,69 +41,70 @@ static int shutdown_;
41 41
42 42
43static void 43static void
44notify_disconnect(void *cls, 44notify_disconnect (void *cls,
45 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 45 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
46 const struct GNUNET_PeerIdentity *other) 46 const struct GNUNET_PeerIdentity *other)
47{ 47{
48 if (me != ccc->p[0]) 48 if (me != ccc->p[0])
49 return; 49 return;
50 GNUNET_TRANSPORT_TESTING_log_disconnect(cls, 50 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
51 me, 51 me,
52 other); 52 other);
53 if (GNUNET_YES == shutdown_) 53 if (GNUNET_YES == shutdown_)
54 { 54 {
55 ccc->global_ret = GNUNET_OK; 55 ccc->global_ret = GNUNET_OK;
56 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
57 "Test good, shutting down...\n"); 57 "Test good, shutting down...\n");
58 GNUNET_SCHEDULER_shutdown(); 58 GNUNET_SCHEDULER_shutdown ();
59 } 59 }
60} 60}
61 61
62 62
63static void 63static void
64stop_peer(void *cls) 64stop_peer (void *cls)
65{ 65{
66 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 66 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
67 "Shutting down peer %u (`%s')\n", 67 "Shutting down peer %u (`%s')\n",
68 ccc->p[1]->no, 68 ccc->p[1]->no,
69 GNUNET_i2s(&ccc->p[1]->id)); 69 GNUNET_i2s (&ccc->p[1]->id));
70 shutdown_ = GNUNET_YES; 70 shutdown_ = GNUNET_YES;
71 GNUNET_TRANSPORT_TESTING_stop_peer(ccc->p[1]); 71 GNUNET_TRANSPORT_TESTING_stop_peer (ccc->p[1]);
72 ccc->p[1] = NULL; 72 ccc->p[1] = NULL;
73} 73}
74 74
75 75
76static void 76static void
77notify_receive(void *cls, 77notify_receive (void *cls,
78 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 78 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
79 const struct GNUNET_PeerIdentity *sender, 79 const struct GNUNET_PeerIdentity *sender,
80 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 80 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
81{ 81{
82 { 82 {
83 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 83 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
84 84
85 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", 86 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
87 receiver->no, 87 receiver->no,
88 ps, 88 ps,
89 ntohs(message->header.type), 89 ntohs (message->header.type),
90 ntohs(message->header.size), 90 ntohs (message->header.size),
91 GNUNET_i2s(sender)); 91 GNUNET_i2s (sender));
92 GNUNET_free(ps); 92 GNUNET_free (ps);
93 }
94 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) &&
95 (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (
96 message->header.size)))
97 {
98 GNUNET_SCHEDULER_add_now (&stop_peer,
99 NULL);
100 return;
93 } 101 }
94 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs(message->header.type)) &&
95 (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs(message->header.size)))
96 {
97 GNUNET_SCHEDULER_add_now(&stop_peer,
98 NULL);
99 return;
100 }
101} 102}
102 103
103 104
104int 105int
105main(int argc, 106main (int argc,
106 char *argv[]) 107 char *argv[])
107{ 108{
108 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 109 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
109 .num_messages = 1 110 .num_messages = 1
@@ -122,9 +123,9 @@ main(int argc,
122 ccc = &my_ccc; 123 ccc = &my_ccc;
123 sc.ccc = ccc; 124 sc.ccc = ccc;
124 if (GNUNET_OK != 125 if (GNUNET_OK !=
125 GNUNET_TRANSPORT_TESTING_main(2, 126 GNUNET_TRANSPORT_TESTING_main (2,
126 &GNUNET_TRANSPORT_TESTING_connect_check, 127 &GNUNET_TRANSPORT_TESTING_connect_check,
127 ccc)) 128 ccc))
128 return 1; 129 return 1;
129 return 0; 130 return 0;
130} 131}
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 @@
33/** 33/**
34 * How long until we give up on transmitting the message? 34 * How long until we give up on transmitting the message?
35 */ 35 */
36#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) 36#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
37 37
38#define MAX_FILES 50 38#define MAX_FILES 50
39 39
@@ -44,32 +44,32 @@ static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
44 44
45 45
46static void 46static void
47notify_receive(void *cls, 47notify_receive (void *cls,
48 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 48 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
49 const struct GNUNET_PeerIdentity *sender, 49 const struct GNUNET_PeerIdentity *sender,
50 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 50 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
51{ 51{
52 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 52 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
53 "Received message of type %d from peer %s!\n", 53 "Received message of type %d from peer %s!\n",
54 ntohs(message->header.type), 54 ntohs (message->header.type),
55 GNUNET_i2s(sender)); 55 GNUNET_i2s (sender));
56 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == 56 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE ==
57 ntohs(message->header.type)) && 57 ntohs (message->header.type)) &&
58 (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == 58 (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) ==
59 ntohs(message->header.size))) 59 ntohs (message->header.size)))
60 { 60 {
61 ccc->global_ret = GNUNET_OK; 61 ccc->global_ret = GNUNET_OK;
62 } 62 }
63 else 63 else
64 { 64 {
65 GNUNET_break(0); 65 GNUNET_break (0);
66 } 66 }
67 GNUNET_SCHEDULER_shutdown(); 67 GNUNET_SCHEDULER_shutdown ();
68} 68}
69 69
70 70
71int 71int
72main(int argc, char *argv[]) 72main (int argc, char *argv[])
73{ 73{
74 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 74 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
75 .num_messages = 1 75 .num_messages = 1
@@ -89,26 +89,26 @@ main(int argc, char *argv[])
89 int res; 89 int res;
90 90
91 sc.ccc = &my_ccc; 91 sc.ccc = &my_ccc;
92 res = getrlimit(RLIMIT_NOFILE, 92 res = getrlimit (RLIMIT_NOFILE,
93 &r_file_old); 93 &r_file_old);
94 r_file_new.rlim_cur = MAX_FILES; 94 r_file_new.rlim_cur = MAX_FILES;
95 r_file_new.rlim_max = r_file_old.rlim_max; 95 r_file_new.rlim_max = r_file_old.rlim_max;
96 res = setrlimit(RLIMIT_NOFILE, 96 res = setrlimit (RLIMIT_NOFILE,
97 &r_file_new); 97 &r_file_new);
98 if (0 != res) 98 if (0 != res)
99 { 99 {
100 fprintf(stderr, 100 fprintf (stderr,
101 "Setting limit failed: %s\n", 101 "Setting limit failed: %s\n",
102 strerror(errno)); 102 strerror (errno));
103 return 77; 103 return 77;
104 } 104 }
105 105
106 ccc = &my_ccc; 106 ccc = &my_ccc;
107 ccc->global_ret = GNUNET_SYSERR; 107 ccc->global_ret = GNUNET_SYSERR;
108 if (GNUNET_OK != 108 if (GNUNET_OK !=
109 GNUNET_TRANSPORT_TESTING_main(2, 109 GNUNET_TRANSPORT_TESTING_main (2,
110 &GNUNET_TRANSPORT_TESTING_connect_check, 110 &GNUNET_TRANSPORT_TESTING_connect_check,
111 ccc)) 111 ccc))
112 return 1; 112 return 1;
113 return 0; 113 return 0;
114} 114}
@@ -118,10 +118,10 @@ main(int argc, char *argv[])
118 118
119 119
120int 120int
121main(int argc, char *argv[]) 121main (int argc, char *argv[])
122{ 122{
123 fprintf(stderr, 123 fprintf (stderr,
124 "Cannot run test on this system\n"); 124 "Cannot run test on this system\n");
125 return 77; 125 return 77;
126} 126}
127 127
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 @@
35/** 35/**
36 * How long until we give up on transmitting the message? 36 * How long until we give up on transmitting the message?
37 */ 37 */
38#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
39 39
40 40
41#define TEST_MESSAGE_SIZE 2600 41#define TEST_MESSAGE_SIZE 2600
@@ -56,107 +56,107 @@ static struct GNUNET_TIME_Absolute start_response;
56 56
57 57
58static void 58static void
59sendtask_response_task(void *cls) 59sendtask_response_task (void *cls)
60{ 60{
61 int ret; 61 int ret;
62 62
63 start_response = GNUNET_TIME_absolute_get(); 63 start_response = GNUNET_TIME_absolute_get ();
64 ret = GNUNET_TRANSPORT_TESTING_send(ccc->p[1], 64 ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
65 ccc->p[0], 65 ccc->p[0],
66 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, 66 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
67 TEST_MESSAGE_SIZE, 67 TEST_MESSAGE_SIZE,
68 1, 68 1,
69 NULL, 69 NULL,
70 NULL); 70 NULL);
71 if (GNUNET_NO == ret) 71 if (GNUNET_NO == ret)
72 { 72 {
73 GNUNET_break(0); 73 GNUNET_break (0);
74 GNUNET_SCHEDULER_shutdown(); 74 GNUNET_SCHEDULER_shutdown ();
75 return; 75 return;
76 } 76 }
77 GNUNET_assert(GNUNET_SYSERR != ret); 77 GNUNET_assert (GNUNET_SYSERR != ret);
78} 78}
79 79
80 80
81static void 81static void
82notify_receive(void *cls, 82notify_receive (void *cls,
83 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 83 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
84 const struct GNUNET_PeerIdentity *sender, 84 const struct GNUNET_PeerIdentity *sender,
85 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 85 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
86{ 86{
87 struct GNUNET_TIME_Relative duration; 87 struct GNUNET_TIME_Relative duration;
88 88
89 { 89 {
90 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 90 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
91 91
92 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
93 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", 93 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n",
94 receiver->no, 94 receiver->no,
95 ps, 95 ps,
96 ntohs(message->header.type), 96 ntohs (message->header.type),
97 ntohs(message->header.size), 97 ntohs (message->header.size),
98 GNUNET_i2s(sender)); 98 GNUNET_i2s (sender));
99 GNUNET_free(ps); 99 GNUNET_free (ps);
100 } 100 }
101 101
102 switch (ntohs(message->header.type)) 102 switch (ntohs (message->header.type))
103 {
104 case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE:
105 duration = GNUNET_TIME_absolute_get_difference (start_request,
106 GNUNET_TIME_absolute_get ());
107 if (duration.rel_value_us >= TEST_DELAY)
108 {
109 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
110 "Request message was delayed for %s\n",
111 GNUNET_STRINGS_relative_time_to_string (duration,
112 GNUNET_YES));
113 }
114 else
103 { 115 {
104 case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE: 116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
105 duration = GNUNET_TIME_absolute_get_difference(start_request, 117 "Request message was delayed for unexpected duration %s\n",
106 GNUNET_TIME_absolute_get()); 118 GNUNET_STRINGS_relative_time_to_string (duration,
107 if (duration.rel_value_us >= TEST_DELAY) 119 GNUNET_YES));
108 { 120 ccc->global_ret = GNUNET_SYSERR;
109 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 121 GNUNET_SCHEDULER_shutdown ();
110 "Request message was delayed for %s\n",
111 GNUNET_STRINGS_relative_time_to_string(duration,
112 GNUNET_YES));
113 }
114 else
115 {
116 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
117 "Request message was delayed for unexpected duration %s\n",
118 GNUNET_STRINGS_relative_time_to_string(duration,
119 GNUNET_YES));
120 ccc->global_ret = GNUNET_SYSERR;
121 GNUNET_SCHEDULER_shutdown();
122 }
123 /* Send response */
124 GNUNET_SCHEDULER_add_now(&sendtask_response_task,
125 NULL);
126 return;
127
128 case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2:
129 duration = GNUNET_TIME_absolute_get_difference(start_response,
130 GNUNET_TIME_absolute_get());
131 if (duration.rel_value_us >= TEST_DELAY)
132 {
133 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
134 "Response message was delayed for %s\n",
135 GNUNET_STRINGS_relative_time_to_string(duration,
136 GNUNET_YES));
137 ccc->global_ret = GNUNET_OK;
138 }
139 else
140 {
141 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
142 "Response message was delayed for unexpected duration %s\n",
143 GNUNET_STRINGS_relative_time_to_string(duration,
144 GNUNET_YES));
145 ccc->global_ret = GNUNET_SYSERR;
146 }
147 GNUNET_SCHEDULER_shutdown();
148 break;
149
150 default:
151 GNUNET_break(0);
152 break;
153 } 122 }
123 /* Send response */
124 GNUNET_SCHEDULER_add_now (&sendtask_response_task,
125 NULL);
126 return;
127
128 case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2:
129 duration = GNUNET_TIME_absolute_get_difference (start_response,
130 GNUNET_TIME_absolute_get ());
131 if (duration.rel_value_us >= TEST_DELAY)
132 {
133 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
134 "Response message was delayed for %s\n",
135 GNUNET_STRINGS_relative_time_to_string (duration,
136 GNUNET_YES));
137 ccc->global_ret = GNUNET_OK;
138 }
139 else
140 {
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
142 "Response message was delayed for unexpected duration %s\n",
143 GNUNET_STRINGS_relative_time_to_string (duration,
144 GNUNET_YES));
145 ccc->global_ret = GNUNET_SYSERR;
146 }
147 GNUNET_SCHEDULER_shutdown ();
148 break;
149
150 default:
151 GNUNET_break (0);
152 break;
153 }
154} 154}
155 155
156 156
157int 157int
158main(int argc, 158main (int argc,
159 char *argv[]) 159 char *argv[])
160{ 160{
161 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 161 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
162 .num_messages = 1 162 .num_messages = 1
@@ -173,11 +173,11 @@ main(int argc,
173 173
174 ccc = &my_ccc; 174 ccc = &my_ccc;
175 sc.ccc = ccc; 175 sc.ccc = ccc;
176 start_request = GNUNET_TIME_absolute_get(); 176 start_request = GNUNET_TIME_absolute_get ();
177 if (GNUNET_OK != 177 if (GNUNET_OK !=
178 GNUNET_TRANSPORT_TESTING_main(2, 178 GNUNET_TRANSPORT_TESTING_main (2,
179 &GNUNET_TRANSPORT_TESTING_connect_check, 179 &GNUNET_TRANSPORT_TESTING_connect_check,
180 ccc)) 180 ccc))
181 return 1; 181 return 1;
182 return 0; 182 return 0;
183} 183}
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 @@
34/** 34/**
35 * How long until we give up on transmitting the message? 35 * How long until we give up on transmitting the message?
36 */ 36 */
37#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
38 38
39 39
40static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 40static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
@@ -51,133 +51,134 @@ static struct GNUNET_TIME_Relative dur_delayed;
51 51
52 52
53static void 53static void
54do_free(void *cls) 54do_free (void *cls)
55{ 55{
56 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 56 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
57 57
58 GNUNET_free(sc); 58 GNUNET_free (sc);
59} 59}
60 60
61 61
62static void 62static void
63delayed_transmit(void *cls) 63delayed_transmit (void *cls)
64{ 64{
65 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 65 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
66 66
67 start_delayed = GNUNET_TIME_absolute_get(); 67 start_delayed = GNUNET_TIME_absolute_get ();
68 GNUNET_TRANSPORT_TESTING_large_send(sc); 68 GNUNET_TRANSPORT_TESTING_large_send (sc);
69} 69}
70 70
71 71
72static void 72static void
73sendtask(void *cls) 73sendtask (void *cls)
74{ 74{
75 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc; 75 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc;
76 struct GNUNET_ATS_Properties prop; 76 struct GNUNET_ATS_Properties prop;
77 struct GNUNET_TIME_Relative delay; 77 struct GNUNET_TIME_Relative delay;
78 78
79 sc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_SendClosure); 79 sc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_SendClosure);
80 sc->num_messages = 1; 80 sc->num_messages = 1;
81 sc->ccc = ccc; 81 sc->ccc = ccc;
82 sc->cont = &do_free; 82 sc->cont = &do_free;
83 sc->cont_cls = sc; 83 sc->cont_cls = sc;
84 if (0 == messages_recv) 84 if (0 == messages_recv)
85 { 85 {
86 start_normal = GNUNET_TIME_absolute_get(); 86 start_normal = GNUNET_TIME_absolute_get ();
87 } 87 }
88 if (0 < messages_recv) 88 if (0 < messages_recv)
89 {
90 memset (&prop,
91 0,
92 sizeof(prop));
93 delay = GNUNET_TIME_UNIT_SECONDS;
94 GNUNET_TRANSPORT_manipulation_set (ccc->p[1]->tmh,
95 &ccc->p[0]->id,
96 &prop,
97 delay,
98 GNUNET_TIME_UNIT_ZERO);
99 /* wait 1s to allow manipulation to go into effect */
100 if (1 == messages_recv)
89 { 101 {
90 memset(&prop, 102 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
91 0, 103 &delayed_transmit,
92 sizeof(prop)); 104 sc);
93 delay = GNUNET_TIME_UNIT_SECONDS; 105 return;
94 GNUNET_TRANSPORT_manipulation_set(ccc->p[1]->tmh,
95 &ccc->p[0]->id,
96 &prop,
97 delay,
98 GNUNET_TIME_UNIT_ZERO);
99 /* wait 1s to allow manipulation to go into effect */
100 if (1 == messages_recv)
101 {
102 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
103 &delayed_transmit,
104 sc);
105 return;
106 }
107 } 106 }
108 GNUNET_TRANSPORT_TESTING_large_send(sc); 107 }
108 GNUNET_TRANSPORT_TESTING_large_send (sc);
109} 109}
110 110
111 111
112static void 112static void
113notify_receive(void *cls, 113notify_receive (void *cls,
114 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 114 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
115 const struct GNUNET_PeerIdentity *sender, 115 const struct GNUNET_PeerIdentity *sender,
116 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 116 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
117{ 117{
118 { 118 {
119 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 119 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
120 120
121 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
122 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", 122 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n",
123 receiver->no, 123 receiver->no,
124 ps, 124 ps,
125 ntohs(message->header.type), 125 ntohs (message->header.type),
126 ntohs(message->header.size), 126 ntohs (message->header.size),
127 GNUNET_i2s(sender)); 127 GNUNET_i2s (sender));
128 GNUNET_free(ps); 128 GNUNET_free (ps);
129 }
130 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) ||
131 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (
132 message->header.size)))
133 {
134 GNUNET_break (0);
135 ccc->global_ret = GNUNET_SYSERR;
136 GNUNET_SCHEDULER_shutdown ();
137 return;
129 } 138 }
130 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(message->header.type)) ||
131 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs(message->header.size)))
132 {
133 GNUNET_break(0);
134 ccc->global_ret = GNUNET_SYSERR;
135 GNUNET_SCHEDULER_shutdown();
136 return;
137 }
138 139
139 if (messages_recv <= 2) 140 if (messages_recv <= 2)
140 { 141 {
141 /* Received non-delayed message */ 142 /* Received non-delayed message */
142 dur_normal = GNUNET_TIME_absolute_get_duration(start_normal); 143 dur_normal = GNUNET_TIME_absolute_get_duration (start_normal);
143 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
144 "Received non-delayed message %u after %s\n", 145 "Received non-delayed message %u after %s\n",
145 messages_recv, 146 messages_recv,
146 GNUNET_STRINGS_relative_time_to_string(dur_normal, 147 GNUNET_STRINGS_relative_time_to_string (dur_normal,
147 GNUNET_YES)); 148 GNUNET_YES));
148 GNUNET_SCHEDULER_add_now(&sendtask, 149 GNUNET_SCHEDULER_add_now (&sendtask,
149 NULL); 150 NULL);
150 messages_recv++; 151 messages_recv++;
151 return; 152 return;
152 } 153 }
153 /* Received manipulated message */ 154 /* Received manipulated message */
154 dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); 155 dur_delayed = GNUNET_TIME_absolute_get_duration (start_delayed);
155 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
156 "Received delayed message %u after %s\n", 157 "Received delayed message %u after %s\n",
157 messages_recv, 158 messages_recv,
158 GNUNET_STRINGS_relative_time_to_string(dur_delayed, 159 GNUNET_STRINGS_relative_time_to_string (dur_delayed,
159 GNUNET_YES)); 160 GNUNET_YES));
160 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) 161 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us)
161 { 162 {
162 GNUNET_break(0); 163 GNUNET_break (0);
163 ccc->global_ret = GNUNET_SYSERR; 164 ccc->global_ret = GNUNET_SYSERR;
164 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 165 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
165 "Delayed message was not delayed correctly: took only %s\n", 166 "Delayed message was not delayed correctly: took only %s\n",
166 GNUNET_STRINGS_relative_time_to_string(dur_delayed, 167 GNUNET_STRINGS_relative_time_to_string (dur_delayed,
167 GNUNET_YES)); 168 GNUNET_YES));
168 } 169 }
169 else 170 else
170 { 171 {
171 ccc->global_ret = GNUNET_OK; 172 ccc->global_ret = GNUNET_OK;
172 } 173 }
173 /* shutdown */ 174 /* shutdown */
174 GNUNET_SCHEDULER_shutdown(); 175 GNUNET_SCHEDULER_shutdown ();
175} 176}
176 177
177 178
178int 179int
179main(int argc, 180main (int argc,
180 char *argv[]) 181 char *argv[])
181{ 182{
182 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 183 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
183 .connect_continuation = &sendtask, 184 .connect_continuation = &sendtask,
@@ -191,9 +192,9 @@ main(int argc,
191 192
192 ccc = &my_ccc; 193 ccc = &my_ccc;
193 if (GNUNET_OK != 194 if (GNUNET_OK !=
194 GNUNET_TRANSPORT_TESTING_main(2, 195 GNUNET_TRANSPORT_TESTING_main (2,
195 &GNUNET_TRANSPORT_TESTING_connect_check, 196 &GNUNET_TRANSPORT_TESTING_connect_check,
196 ccc)) 197 ccc))
197 return 1; 198 return 1;
198 return 0; 199 return 0;
199} 200}
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 @@
34/** 34/**
35 * How long until we give up on transmitting the message? 35 * How long until we give up on transmitting the message?
36 */ 36 */
37#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
38 38
39static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 39static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
40 40
@@ -50,130 +50,131 @@ static struct GNUNET_TIME_Relative dur_delayed;
50 50
51 51
52static void 52static void
53do_free(void *cls) 53do_free (void *cls)
54{ 54{
55 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 55 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
56 56
57 GNUNET_free(sc); 57 GNUNET_free (sc);
58} 58}
59 59
60 60
61static void 61static void
62delayed_transmit(void *cls) 62delayed_transmit (void *cls)
63{ 63{
64 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 64 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
65 65
66 start_delayed = GNUNET_TIME_absolute_get(); 66 start_delayed = GNUNET_TIME_absolute_get ();
67 GNUNET_TRANSPORT_TESTING_large_send(sc); 67 GNUNET_TRANSPORT_TESTING_large_send (sc);
68} 68}
69 69
70 70
71static void 71static void
72sendtask(void *cls) 72sendtask (void *cls)
73{ 73{
74 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc; 74 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc;
75 struct GNUNET_TIME_Relative delay; 75 struct GNUNET_TIME_Relative delay;
76 struct GNUNET_ATS_Properties prop; 76 struct GNUNET_ATS_Properties prop;
77 77
78 sc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_SendClosure); 78 sc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_SendClosure);
79 sc->num_messages = 1; 79 sc->num_messages = 1;
80 sc->ccc = ccc; 80 sc->ccc = ccc;
81 sc->cont = &do_free; 81 sc->cont = &do_free;
82 sc->cont_cls = sc; 82 sc->cont_cls = sc;
83 if (0 == messages_recv) 83 if (0 == messages_recv)
84 { 84 {
85 start_normal = GNUNET_TIME_absolute_get(); 85 start_normal = GNUNET_TIME_absolute_get ();
86 } 86 }
87 if (1 == messages_recv) 87 if (1 == messages_recv)
88 { 88 {
89 memset(&prop, 89 memset (&prop,
90 0, 90 0,
91 sizeof(prop)); 91 sizeof(prop));
92 delay = GNUNET_TIME_UNIT_SECONDS; 92 delay = GNUNET_TIME_UNIT_SECONDS;
93 GNUNET_TRANSPORT_manipulation_set(ccc->p[0]->tmh, 93 GNUNET_TRANSPORT_manipulation_set (ccc->p[0]->tmh,
94 &ccc->p[1]->id, 94 &ccc->p[1]->id,
95 &prop, 95 &prop,
96 GNUNET_TIME_UNIT_ZERO, 96 GNUNET_TIME_UNIT_ZERO,
97 delay); 97 delay);
98 /* wait 1s to allow manipulation to go into effect */ 98 /* wait 1s to allow manipulation to go into effect */
99 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 99 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
100 &delayed_transmit, 100 &delayed_transmit,
101 sc); 101 sc);
102 return; 102 return;
103 } 103 }
104 GNUNET_TRANSPORT_TESTING_large_send(sc); 104 GNUNET_TRANSPORT_TESTING_large_send (sc);
105} 105}
106 106
107 107
108static void 108static void
109notify_receive(void *cls, 109notify_receive (void *cls,
110 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 110 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
111 const struct GNUNET_PeerIdentity *sender, 111 const struct GNUNET_PeerIdentity *sender,
112 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 112 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
113{ 113{
114 { 114 {
115 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 115 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
116 116
117 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
118 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", 118 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n",
119 receiver->no, 119 receiver->no,
120 ps, 120 ps,
121 ntohs(message->header.type), 121 ntohs (message->header.type),
122 ntohs(message->header.size), 122 ntohs (message->header.size),
123 GNUNET_i2s(sender)); 123 GNUNET_i2s (sender));
124 GNUNET_free(ps); 124 GNUNET_free (ps);
125 } 125 }
126 126
127 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(message->header.type)) || 127 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) ||
128 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs(message->header.size))) 128 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (
129 { 129 message->header.size)))
130 GNUNET_break(0); 130 {
131 ccc->global_ret = GNUNET_SYSERR; 131 GNUNET_break (0);
132 GNUNET_SCHEDULER_shutdown(); 132 ccc->global_ret = GNUNET_SYSERR;
133 return; 133 GNUNET_SCHEDULER_shutdown ();
134 } 134 return;
135 }
135 136
136 if (0 == messages_recv) 137 if (0 == messages_recv)
137 { 138 {
138 /* Received non-delayed message */ 139 /* Received non-delayed message */
139 dur_normal = GNUNET_TIME_absolute_get_duration(start_normal); 140 dur_normal = GNUNET_TIME_absolute_get_duration (start_normal);
140 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
141 "Received non-delayed message %u after %s\n", 142 "Received non-delayed message %u after %s\n",
142 messages_recv, 143 messages_recv,
143 GNUNET_STRINGS_relative_time_to_string(dur_normal, 144 GNUNET_STRINGS_relative_time_to_string (dur_normal,
144 GNUNET_YES)); 145 GNUNET_YES));
145 GNUNET_SCHEDULER_add_now(&sendtask, 146 GNUNET_SCHEDULER_add_now (&sendtask,
146 NULL); 147 NULL);
147 messages_recv++; 148 messages_recv++;
148 return; 149 return;
149 } 150 }
150 /* Received manipulated message */ 151 /* Received manipulated message */
151 dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); 152 dur_delayed = GNUNET_TIME_absolute_get_duration (start_delayed);
152 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Received delayed message %u after %s\n", 154 "Received delayed message %u after %s\n",
154 messages_recv, 155 messages_recv,
155 GNUNET_STRINGS_relative_time_to_string(dur_delayed, 156 GNUNET_STRINGS_relative_time_to_string (dur_delayed,
156 GNUNET_YES)); 157 GNUNET_YES));
157 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) 158 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us)
158 { 159 {
159 GNUNET_break(0); 160 GNUNET_break (0);
160 ccc->global_ret = GNUNET_SYSERR; 161 ccc->global_ret = GNUNET_SYSERR;
161 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
162 "Delayed message was not delayed correctly: took only %s\n", 163 "Delayed message was not delayed correctly: took only %s\n",
163 GNUNET_STRINGS_relative_time_to_string(dur_delayed, 164 GNUNET_STRINGS_relative_time_to_string (dur_delayed,
164 GNUNET_YES)); 165 GNUNET_YES));
165 } 166 }
166 else 167 else
167 { 168 {
168 ccc->global_ret = GNUNET_OK; 169 ccc->global_ret = GNUNET_OK;
169 } 170 }
170 GNUNET_SCHEDULER_shutdown(); 171 GNUNET_SCHEDULER_shutdown ();
171} 172}
172 173
173 174
174int 175int
175main(int argc, 176main (int argc,
176 char *argv[]) 177 char *argv[])
177{ 178{
178 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 179 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
179 .connect_continuation = &sendtask, 180 .connect_continuation = &sendtask,
@@ -187,9 +188,9 @@ main(int argc,
187 188
188 ccc = &my_ccc; 189 ccc = &my_ccc;
189 if (GNUNET_OK != 190 if (GNUNET_OK !=
190 GNUNET_TRANSPORT_TESTING_main(2, 191 GNUNET_TRANSPORT_TESTING_main (2,
191 &GNUNET_TRANSPORT_TESTING_connect_check, 192 &GNUNET_TRANSPORT_TESTING_connect_check,
192 ccc)) 193 ccc))
193 return 1; 194 return 1;
194 return 0; 195 return 0;
195} 196}
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 @@
28/** 28/**
29 * How long until we give up on transmitting the message? 29 * How long until we give up on transmitting the message?
30 */ 30 */
31#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
32 32
33/** 33/**
34 * How long until we give up on transmitting the message? 34 * How long until we give up on transmitting the message?
35 */ 35 */
36#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 36#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply ( \
37 GNUNET_TIME_UNIT_SECONDS, 30)
37 38
38#define TEST_MESSAGE_SIZE 2600 39#define TEST_MESSAGE_SIZE 2600
39 40
@@ -55,151 +56,151 @@ static int p2_c_notify;
55 56
56 57
57static void 58static void
58custom_shutdown(void *cls) 59custom_shutdown (void *cls)
59{ 60{
60 if (NULL != pmc_p1) 61 if (NULL != pmc_p1)
61 { 62 {
62 GNUNET_TRANSPORT_monitor_peers_cancel(pmc_p1); 63 GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p1);
63 pmc_p1 = NULL; 64 pmc_p1 = NULL;
64 } 65 }
65 if (NULL != pmc_p2) 66 if (NULL != pmc_p2)
66 { 67 {
67 GNUNET_TRANSPORT_monitor_peers_cancel(pmc_p2); 68 GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p2);
68 pmc_p2 = NULL; 69 pmc_p2 = NULL;
69 } 70 }
70} 71}
71 72
72 73
73static void 74static void
74notify_receive(void *cls, 75notify_receive (void *cls,
75 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 76 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
76 const struct GNUNET_PeerIdentity *sender, 77 const struct GNUNET_PeerIdentity *sender,
77 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 78 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
78{ 79{
79 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 80 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
80 81
81 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 82 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
82 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", 83 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
83 receiver->no, 84 receiver->no,
84 ps, 85 ps,
85 ntohs(message->header.type), 86 ntohs (message->header.type),
86 ntohs(message->header.size), 87 ntohs (message->header.size),
87 GNUNET_i2s(sender)); 88 GNUNET_i2s (sender));
88 GNUNET_free(ps); 89 GNUNET_free (ps);
89} 90}
90 91
91 92
92static void 93static void
93sendtask(void *cls) 94sendtask (void *cls)
94{ 95{
95 /* intentionally empty */ 96 /* intentionally empty */
96} 97}
97 98
98 99
99static void 100static void
100check_done() 101check_done ()
101{ 102{
102 if ((GNUNET_YES == p1_c) && 103 if ((GNUNET_YES == p1_c) &&
103 (GNUNET_YES == p2_c) && 104 (GNUNET_YES == p2_c) &&
104 p1_c_notify && 105 p1_c_notify &&
105 p2_c_notify) 106 p2_c_notify)
106 { 107 {
107 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "Both peers state to be connected\n"); 109 "Both peers state to be connected\n");
109 ccc->global_ret = GNUNET_OK; 110 ccc->global_ret = GNUNET_OK;
110 GNUNET_SCHEDULER_shutdown(); 111 GNUNET_SCHEDULER_shutdown ();
111 } 112 }
112} 113}
113 114
114 115
115static void 116static void
116notify_connect(void *cls, 117notify_connect (void *cls,
117 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 118 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
118 const struct GNUNET_PeerIdentity *other) 119 const struct GNUNET_PeerIdentity *other)
119{ 120{
120 GNUNET_TRANSPORT_TESTING_log_connect(cls, 121 GNUNET_TRANSPORT_TESTING_log_connect (cls,
121 me, 122 me,
122 other); 123 other);
123 if (0 == memcmp(other, &ccc->p[0]->id, sizeof(struct GNUNET_PeerIdentity))) 124 if (0 == memcmp (other, &ccc->p[0]->id, sizeof(struct GNUNET_PeerIdentity)))
124 { 125 {
125 p1_c_notify = GNUNET_YES; 126 p1_c_notify = GNUNET_YES;
126 } 127 }
127 if (0 == memcmp(other, &ccc->p[1]->id, sizeof(struct GNUNET_PeerIdentity))) 128 if (0 == memcmp (other, &ccc->p[1]->id, sizeof(struct GNUNET_PeerIdentity)))
128 { 129 {
129 p2_c_notify = GNUNET_YES; 130 p2_c_notify = GNUNET_YES;
130 } 131 }
131 check_done(); 132 check_done ();
132} 133}
133 134
134 135
135static void 136static void
136monitor1_cb(void *cls, 137monitor1_cb (void *cls,
137 const struct GNUNET_PeerIdentity *peer, 138 const struct GNUNET_PeerIdentity *peer,
138 const struct GNUNET_HELLO_Address *address, 139 const struct GNUNET_HELLO_Address *address,
139 enum GNUNET_TRANSPORT_PeerState state, 140 enum GNUNET_TRANSPORT_PeerState state,
140 struct GNUNET_TIME_Absolute state_timeout) 141 struct GNUNET_TIME_Absolute state_timeout)
141{ 142{
142 if ((NULL == address) || (NULL == ccc->p[0])) 143 if ((NULL == address) || (NULL == ccc->p[0]))
143 return; 144 return;
144 145
145 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 146 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
146 "Monitor 1: %s %s %s\n", 147 "Monitor 1: %s %s %s\n",
147 GNUNET_i2s(&address->peer), 148 GNUNET_i2s (&address->peer),
148 GNUNET_TRANSPORT_ps2s(state), 149 GNUNET_TRANSPORT_ps2s (state),
149 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 150 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
150 if ((0 == memcmp(&address->peer, &ccc->p[1]->id, sizeof(ccc->p[1]->id))) && 151 if ((0 == memcmp (&address->peer, &ccc->p[1]->id, sizeof(ccc->p[1]->id))) &&
151 (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && 152 (GNUNET_YES == GNUNET_TRANSPORT_is_connected (state)) &&
152 (GNUNET_NO == p1_c)) 153 (GNUNET_NO == p1_c))
153 { 154 {
154 p1_c = GNUNET_YES; 155 p1_c = GNUNET_YES;
155 check_done(); 156 check_done ();
156 } 157 }
157} 158}
158 159
159 160
160static void 161static void
161monitor2_cb(void *cls, 162monitor2_cb (void *cls,
162 const struct GNUNET_PeerIdentity *peer, 163 const struct GNUNET_PeerIdentity *peer,
163 const struct GNUNET_HELLO_Address *address, 164 const struct GNUNET_HELLO_Address *address,
164 enum GNUNET_TRANSPORT_PeerState state, 165 enum GNUNET_TRANSPORT_PeerState state,
165 struct GNUNET_TIME_Absolute state_timeout) 166 struct GNUNET_TIME_Absolute state_timeout)
166{ 167{
167 if ((NULL == address) || (NULL == ccc->p[1])) 168 if ((NULL == address) || (NULL == ccc->p[1]))
168 return; 169 return;
169 170
170 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 171 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
171 "Monitor 2: %s %s %s\n", 172 "Monitor 2: %s %s %s\n",
172 GNUNET_i2s(&address->peer), 173 GNUNET_i2s (&address->peer),
173 GNUNET_TRANSPORT_ps2s(state), 174 GNUNET_TRANSPORT_ps2s (state),
174 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 175 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
175 if ((0 == memcmp(&address->peer, &ccc->p[0]->id, sizeof(ccc->p[0]->id))) && 176 if ((0 == memcmp (&address->peer, &ccc->p[0]->id, sizeof(ccc->p[0]->id))) &&
176 (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && 177 (GNUNET_YES == GNUNET_TRANSPORT_is_connected (state)) &&
177 (GNUNET_NO == p2_c)) 178 (GNUNET_NO == p2_c))
178 { 179 {
179 p2_c = GNUNET_YES; 180 p2_c = GNUNET_YES;
180 check_done(); 181 check_done ();
181 } 182 }
182} 183}
183 184
184 185
185static void 186static void
186start_monitors(void *cls) 187start_monitors (void *cls)
187{ 188{
188 pmc_p1 = GNUNET_TRANSPORT_monitor_peers(ccc->p[0]->cfg, 189 pmc_p1 = GNUNET_TRANSPORT_monitor_peers (ccc->p[0]->cfg,
189 NULL, 190 NULL,
190 GNUNET_NO, 191 GNUNET_NO,
191 &monitor1_cb, 192 &monitor1_cb,
192 NULL); 193 NULL);
193 pmc_p2 = GNUNET_TRANSPORT_monitor_peers(ccc->p[1]->cfg, 194 pmc_p2 = GNUNET_TRANSPORT_monitor_peers (ccc->p[1]->cfg,
194 NULL, 195 NULL,
195 GNUNET_NO, 196 GNUNET_NO,
196 &monitor2_cb, 197 &monitor2_cb,
197 NULL); 198 NULL);
198} 199}
199 200
200 201
201int 202int
202main(int argc, char *argv[]) 203main (int argc, char *argv[])
203{ 204{
204 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 205 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
205 .pre_connect_task = &start_monitors, 206 .pre_connect_task = &start_monitors,
@@ -214,9 +215,9 @@ main(int argc, char *argv[])
214 215
215 ccc = &my_ccc; 216 ccc = &my_ccc;
216 if (GNUNET_OK != 217 if (GNUNET_OK !=
217 GNUNET_TRANSPORT_TESTING_main(2, 218 GNUNET_TRANSPORT_TESTING_main (2,
218 &GNUNET_TRANSPORT_TESTING_connect_check, 219 &GNUNET_TRANSPORT_TESTING_connect_check,
219 ccc)) 220 ccc))
220 return 1; 221 return 1;
221 return 0; 222 return 0;
222} 223}
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 @@
48/** 48/**
49 * Testcase timeout 49 * Testcase timeout
50 */ 50 */
51#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 450 * FACTOR) 51#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 450 \
52 * FACTOR)
52 53
53/** 54/**
54 * If we are in an "xhdr" test, the factor by which we divide 55 * If we are in an "xhdr" test, the factor by which we divide
@@ -83,7 +84,7 @@ static char bitmap[TOTAL_MSGS / 8];
83 * Get the desired message size for message number @a iter. 84 * Get the desired message size for message number @a iter.
84 */ 85 */
85static size_t 86static size_t
86get_size(unsigned int iter) 87get_size (unsigned int iter)
87{ 88{
88 size_t ret; 89 size_t ret;
89 90
@@ -91,7 +92,7 @@ get_size(unsigned int iter)
91#ifndef LINUX 92#ifndef LINUX
92 /* FreeBSD/OSX etc. Unix DGRAMs do not work 93 /* FreeBSD/OSX etc. Unix DGRAMs do not work
93 * with large messages */ 94 * with large messages */
94 if (0 == strcmp("unix", ccc->test_plugin)) 95 if (0 == strcmp ("unix", ccc->test_plugin))
95 ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 1024); 96 ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 1024);
96#endif 97#endif
97 ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 60000); 98 ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 60000);
@@ -108,9 +109,9 @@ get_size(unsigned int iter)
108 * @return message size of the message 109 * @return message size of the message
109 */ 110 */
110static size_t 111static size_t
111get_size_cnt(unsigned int cnt_down) 112get_size_cnt (unsigned int cnt_down)
112{ 113{
113 size_t ret = get_size(TOTAL_MSGS / xhdr - 1 - cnt_down); 114 size_t ret = get_size (TOTAL_MSGS / xhdr - 1 - cnt_down);
114 115
115 total_bytes += ret; 116 total_bytes += ret;
116 return ret; 117 return ret;
@@ -124,19 +125,19 @@ get_size_cnt(unsigned int cnt_down)
124 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 125 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
125 */ 126 */
126static int 127static int
127set_bit(unsigned int bitIdx) 128set_bit (unsigned int bitIdx)
128{ 129{
129 size_t arraySlot; 130 size_t arraySlot;
130 unsigned int targetBit; 131 unsigned int targetBit;
131 132
132 if (bitIdx >= sizeof(bitmap) * 8) 133 if (bitIdx >= sizeof(bitmap) * 8)
133 { 134 {
134 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
135 "tried to set bit %u of %u(!?!?)\n", 136 "tried to set bit %u of %u(!?!?)\n",
136 bitIdx, 137 bitIdx,
137 (unsigned int)sizeof(bitmap) * 8); 138 (unsigned int) sizeof(bitmap) * 8);
138 return GNUNET_SYSERR; 139 return GNUNET_SYSERR;
139 } 140 }
140 arraySlot = bitIdx / 8; 141 arraySlot = bitIdx / 8;
141 targetBit = (1L << (bitIdx % 8)); 142 targetBit = (1L << (bitIdx % 8));
142 bitmap[arraySlot] |= targetBit; 143 bitmap[arraySlot] |= targetBit;
@@ -152,143 +153,143 @@ set_bit(unsigned int bitIdx)
152 * @return Bit @a bit from @a map 153 * @return Bit @a bit from @a map
153 */ 154 */
154static int 155static int
155get_bit(const char *map, 156get_bit (const char *map,
156 unsigned int bit) 157 unsigned int bit)
157{ 158{
158 if (bit > TOTAL_MSGS) 159 if (bit > TOTAL_MSGS)
159 { 160 {
160 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
161 "get bit %u of %u(!?!?)\n", 162 "get bit %u of %u(!?!?)\n",
162 bit, 163 bit,
163 (unsigned int)sizeof(bitmap) * 8); 164 (unsigned int) sizeof(bitmap) * 8);
164 return 0; 165 return 0;
165 } 166 }
166 return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; 167 return ((map)[bit >> 3] & (1 << (bit & 7))) > 0;
167} 168}
168 169
169 170
170static void 171static void
171custom_shutdown(void *cls) 172custom_shutdown (void *cls)
172{ 173{
173 unsigned long long delta; 174 unsigned long long delta;
174 unsigned long long rate; 175 unsigned long long rate;
175 int ok; 176 int ok;
176 177
177 /* Calculcate statistics */ 178 /* Calculcate statistics */
178 delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us; 179 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
179 if (0 == delta) 180 if (0 == delta)
180 delta = 1; 181 delta = 1;
181 rate = (1000LL * 1000ll * total_bytes) / (1024 * delta); 182 rate = (1000LL * 1000ll * total_bytes) / (1024 * delta);
182 fprintf(stderr, 183 fprintf (stderr,
183 "\nThroughput was %llu KiBytes/s\n", 184 "\nThroughput was %llu KiBytes/s\n",
184 rate); 185 rate);
185 { 186 {
186 char *value_name; 187 char *value_name;
187 188
188 GNUNET_asprintf(&value_name, 189 GNUNET_asprintf (&value_name,
189 "unreliable_%s", 190 "unreliable_%s",
190 ccc->test_plugin); 191 ccc->test_plugin);
191 GAUGER("TRANSPORT", 192 GAUGER ("TRANSPORT",
192 value_name, 193 value_name,
193 (int)rate, 194 (int) rate,
194 "kb/s"); 195 "kb/s");
195 GNUNET_free(value_name); 196 GNUNET_free (value_name);
196 } 197 }
197 198
198 ok = 0; 199 ok = 0;
199 for (unsigned int i = 0; i < TOTAL_MSGS / xhdr; i++) 200 for (unsigned int i = 0; i < TOTAL_MSGS / xhdr; i++)
201 {
202 if (get_bit (bitmap, i) == 0)
200 { 203 {
201 if (get_bit(bitmap, i) == 0) 204 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
202 { 205 "Did not receive message %d\n",
203 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 206 i);
204 "Did not receive message %d\n", 207 ok = -1;
205 i);
206 ok = -1;
207 }
208 } 208 }
209 }
209 if (0 != ok) 210 if (0 != ok)
210 ccc->global_ret = GNUNET_SYSERR; /* fail: messages missing! */ 211 ccc->global_ret = GNUNET_SYSERR; /* fail: messages missing! */
211} 212}
212 213
213 214
214static void 215static void
215notify_receive(void *cls, 216notify_receive (void *cls,
216 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 217 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
217 const struct GNUNET_PeerIdentity *sender, 218 const struct GNUNET_PeerIdentity *sender,
218 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) 219 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
219{ 220{
220 static int n; 221 static int n;
221 unsigned int s; 222 unsigned int s;
222 char cbuf[GNUNET_MAX_MESSAGE_SIZE - 1]; 223 char cbuf[GNUNET_MAX_MESSAGE_SIZE - 1];
223 224
224 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type)) 225 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type))
225 return; 226 return;
226 msg_recv = ntohl(hdr->num); 227 msg_recv = ntohl (hdr->num);
227 s = get_size(ntohl(hdr->num)); 228 s = get_size (ntohl (hdr->num));
228 229
229 if (ntohs(hdr->header.size) != s) 230 if (ntohs (hdr->header.size) != s)
230 { 231 {
231 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
232 "Expected message %u of size %u, got %u bytes of message %u\n", 233 "Expected message %u of size %u, got %u bytes of message %u\n",
233 (uint32_t)ntohl(hdr->num), 234 (uint32_t) ntohl (hdr->num),
234 s, 235 s,
235 ntohs(hdr->header.size), 236 ntohs (hdr->header.size),
236 (uint32_t)ntohl(hdr->num)); 237 (uint32_t) ntohl (hdr->num));
237 ccc->global_ret = GNUNET_SYSERR; 238 ccc->global_ret = GNUNET_SYSERR;
238 GNUNET_SCHEDULER_shutdown(); 239 GNUNET_SCHEDULER_shutdown ();
239 return; 240 return;
240 } 241 }
241 242
242 memset(cbuf, 243 memset (cbuf,
243 ntohl(hdr->num), 244 ntohl (hdr->num),
244 s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage)); 245 s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage));
245 if (0 != 246 if (0 !=
246 memcmp(cbuf, 247 memcmp (cbuf,
247 &hdr[1], 248 &hdr[1],
248 s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))) 249 s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage)))
249 { 250 {
250 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 251 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
251 "Expected message %u with bits %u, but body did not match\n", 252 "Expected message %u with bits %u, but body did not match\n",
252 (uint32_t)ntohl(hdr->num), 253 (uint32_t) ntohl (hdr->num),
253 (unsigned char)ntohl(hdr->num)); 254 (unsigned char) ntohl (hdr->num));
254 ccc->global_ret = GNUNET_SYSERR; 255 ccc->global_ret = GNUNET_SYSERR;
255 GNUNET_SCHEDULER_shutdown(); 256 GNUNET_SCHEDULER_shutdown ();
256 return; 257 return;
257 } 258 }
258#if VERBOSE 259#if VERBOSE
259 if (0 == ntohl(hdr->num) % 5) 260 if (0 == ntohl (hdr->num) % 5)
260 { 261 {
261 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "Got message %u of size %u\n", 263 "Got message %u of size %u\n",
263 (uint32_t)ntohl(hdr->num), 264 (uint32_t) ntohl (hdr->num),
264 ntohs(hdr->header.size)); 265 ntohs (hdr->header.size));
265 } 266 }
266#endif 267#endif
267 n++; 268 n++;
268 if (GNUNET_SYSERR == set_bit(ntohl(hdr->num))) 269 if (GNUNET_SYSERR == set_bit (ntohl (hdr->num)))
269 { 270 {
270 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
271 "Message id %u is bigger than maxmimum number of messages %u expected\n", 272 "Message id %u is bigger than maxmimum number of messages %u expected\n",
272 (uint32_t)ntohl(hdr->num), 273 (uint32_t) ntohl (hdr->num),
273 TOTAL_MSGS / xhdr); 274 TOTAL_MSGS / xhdr);
274 } 275 }
275 if (0 == (n % (TOTAL_MSGS / xhdr / 100))) 276 if (0 == (n % (TOTAL_MSGS / xhdr / 100)))
276 { 277 {
277 fprintf(stderr, "%s", "."); 278 fprintf (stderr, "%s", ".");
278 } 279 }
279 if (n == TOTAL_MSGS / xhdr) 280 if (n == TOTAL_MSGS / xhdr)
280 { 281 {
281 /* end testcase with success */ 282 /* end testcase with success */
282 ccc->global_ret = GNUNET_OK; 283 ccc->global_ret = GNUNET_OK;
283 GNUNET_SCHEDULER_shutdown(); 284 GNUNET_SCHEDULER_shutdown ();
284 } 285 }
285} 286}
286 287
287 288
288int 289int
289main(int argc, char *argv[]) 290main (int argc, char *argv[])
290{ 291{
291 if (0 == strstr(argv[0], "xhdr")) 292 if (0 == strstr (argv[0], "xhdr"))
292 xhdr = 30; 293 xhdr = 30;
293 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 294 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
294 .num_messages = TOTAL_MSGS / xhdr, 295 .num_messages = TOTAL_MSGS / xhdr,
@@ -308,11 +309,11 @@ main(int argc, char *argv[])
308 309
309 ccc = &my_ccc; 310 ccc = &my_ccc;
310 sc.ccc = ccc; 311 sc.ccc = ccc;
311 start_time = GNUNET_TIME_absolute_get(); 312 start_time = GNUNET_TIME_absolute_get ();
312 if (GNUNET_OK != 313 if (GNUNET_OK !=
313 GNUNET_TRANSPORT_TESTING_main(2, 314 GNUNET_TRANSPORT_TESTING_main (2,
314 &GNUNET_TRANSPORT_TESTING_connect_check, 315 &GNUNET_TRANSPORT_TESTING_connect_check,
315 ccc)) 316 ccc))
316 return 1; 317 return 1;
317 return 0; 318 return 0;
318} 319}
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 @@
32/** 32/**
33 * How long until we give up on transmitting the message? 33 * How long until we give up on transmitting the message?
34 */ 34 */
35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
36 36
37 37
38static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 38static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
@@ -47,112 +47,113 @@ static int restarted;
47 47
48 48
49static void 49static void
50custom_shutdown(void *cls) 50custom_shutdown (void *cls)
51{ 51{
52 if (NULL != ats_sh) 52 if (NULL != ats_sh)
53 { 53 {
54 GNUNET_ATS_connectivity_suggest_cancel(ats_sh); 54 GNUNET_ATS_connectivity_suggest_cancel (ats_sh);
55 ats_sh = NULL; 55 ats_sh = NULL;
56 } 56 }
57} 57}
58 58
59 59
60static void 60static void
61restart_cb(void *cls) 61restart_cb (void *cls)
62{ 62{
63 static unsigned int c; 63 static unsigned int c;
64 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 64 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
65 65
66 c++; 66 c++;
67 if ((2 != c) && 67 if ((2 != c) &&
68 (NULL != strstr(ccc->test_name, 68 (NULL != strstr (ccc->test_name,
69 "2peers"))) 69 "2peers")))
70 return; 70 return;
71 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 71 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
72 "Restarted peer %u (`%s'), issuing reconnect\n", 72 "Restarted peer %u (`%s'), issuing reconnect\n",
73 p->no, 73 p->no,
74 GNUNET_i2s(&p->id)); 74 GNUNET_i2s (&p->id));
75 ats_sh = GNUNET_ATS_connectivity_suggest(p->ats, 75 ats_sh = GNUNET_ATS_connectivity_suggest (p->ats,
76 &ccc->p[1]->id, 76 &ccc->p[1]->id,
77 1); 77 1);
78} 78}
79 79
80 80
81static void 81static void
82restart(struct GNUNET_TRANSPORT_TESTING_PeerContext *p) 82restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
83{ 83{
84 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
85 "Restarting peer %u (`%s')\n", 85 "Restarting peer %u (`%s')\n",
86 p->no, 86 p->no,
87 GNUNET_i2s(&p->id)); 87 GNUNET_i2s (&p->id));
88 GNUNET_assert(GNUNET_OK == 88 GNUNET_assert (GNUNET_OK ==
89 GNUNET_TRANSPORT_TESTING_restart_peer(p, 89 GNUNET_TRANSPORT_TESTING_restart_peer (p,
90 &restart_cb, 90 &restart_cb,
91 p)); 91 p));
92} 92}
93 93
94 94
95static void 95static void
96notify_receive(void *cls, 96notify_receive (void *cls,
97 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 97 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
98 const struct GNUNET_PeerIdentity *sender, 98 const struct GNUNET_PeerIdentity *sender,
99 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 99 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
100{ 100{
101 { 101 {
102 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 102 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
103 103
104 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 104 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
105 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", 105 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
106 receiver->no, 106 receiver->no,
107 ps, 107 ps,
108 ntohs(message->header.type), 108 ntohs (message->header.type),
109 ntohs(message->header.size), 109 ntohs (message->header.size),
110 GNUNET_i2s(sender)); 110 GNUNET_i2s (sender));
111 GNUNET_free(ps); 111 GNUNET_free (ps);
112 } 112 }
113 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs(message->header.type)) && 113 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) &&
114 (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs(message->header.size))) 114 (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (
115 message->header.size)))
116 {
117 if (GNUNET_NO == restarted)
115 { 118 {
116 if (GNUNET_NO == restarted) 119 restarted = GNUNET_YES;
117 { 120 fprintf (stderr, "TN: %s\n", ccc->test_name);
118 restarted = GNUNET_YES; 121 restart (ccc->p[0]);
119 fprintf(stderr, "TN: %s\n", ccc->test_name); 122 if (NULL != strstr (ccc->test_name,
120 restart(ccc->p[0]); 123 "2peers"))
121 if (NULL != strstr(ccc->test_name, 124 restart (ccc->p[1]);
122 "2peers")) 125 return;
123 restart(ccc->p[1]);
124 return;
125 }
126 else
127 {
128 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
129 "Restarted peers connected and message was sent, stopping test...\n");
130 ccc->global_ret = GNUNET_OK;
131 GNUNET_SCHEDULER_shutdown();
132 }
133 } 126 }
134 else 127 else
135 { 128 {
136 GNUNET_break(0); 129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
137 ccc->global_ret = GNUNET_SYSERR; 130 "Restarted peers connected and message was sent, stopping test...\n");
138 GNUNET_SCHEDULER_shutdown(); 131 ccc->global_ret = GNUNET_OK;
132 GNUNET_SCHEDULER_shutdown ();
139 } 133 }
134 }
135 else
136 {
137 GNUNET_break (0);
138 ccc->global_ret = GNUNET_SYSERR;
139 GNUNET_SCHEDULER_shutdown ();
140 }
140} 141}
141 142
142 143
143static void 144static void
144notify_connect(void *cls, 145notify_connect (void *cls,
145 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 146 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
146 const struct GNUNET_PeerIdentity *other) 147 const struct GNUNET_PeerIdentity *other)
147{ 148{
148 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 149 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
149 .num_messages = 1 150 .num_messages = 1
150 }; 151 };
151 152
152 sc.ccc = ccc; 153 sc.ccc = ccc;
153 GNUNET_TRANSPORT_TESTING_log_connect(cls, 154 GNUNET_TRANSPORT_TESTING_log_connect (cls,
154 me, 155 me,
155 other); 156 other);
156 if (me == ccc->p[0]) 157 if (me == ccc->p[0])
157 p1_connected = GNUNET_YES; 158 p1_connected = GNUNET_YES;
158 if (me == ccc->p[1]) 159 if (me == ccc->p[1])
@@ -161,22 +162,22 @@ notify_connect(void *cls,
161 if ((GNUNET_YES == restarted) && 162 if ((GNUNET_YES == restarted) &&
162 (GNUNET_YES == p1_connected) && 163 (GNUNET_YES == p1_connected) &&
163 (GNUNET_YES == p2_connected)) 164 (GNUNET_YES == p2_connected))
164 { 165 {
165 /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ 166 /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */
166 GNUNET_SCHEDULER_add_now(&GNUNET_TRANSPORT_TESTING_simple_send, 167 GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send,
167 &sc); 168 &sc);
168 } 169 }
169} 170}
170 171
171 172
172static void 173static void
173notify_disconnect(void *cls, 174notify_disconnect (void *cls,
174 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 175 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
175 const struct GNUNET_PeerIdentity *other) 176 const struct GNUNET_PeerIdentity *other)
176{ 177{
177 GNUNET_TRANSPORT_TESTING_log_disconnect(cls, 178 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
178 me, 179 me,
179 other); 180 other);
180 if (me == ccc->p[0]) 181 if (me == ccc->p[0])
181 p1_connected = GNUNET_NO; 182 p1_connected = GNUNET_NO;
182 if (me == ccc->p[1]) 183 if (me == ccc->p[1])
@@ -185,8 +186,8 @@ notify_disconnect(void *cls,
185 186
186 187
187int 188int
188main(int argc, 189main (int argc,
189 char *argv[]) 190 char *argv[])
190{ 191{
191 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 192 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
192 .num_messages = 1 193 .num_messages = 1
@@ -205,9 +206,9 @@ main(int argc,
205 ccc = &my_ccc; 206 ccc = &my_ccc;
206 sc.ccc = ccc; 207 sc.ccc = ccc;
207 if (GNUNET_OK != 208 if (GNUNET_OK !=
208 GNUNET_TRANSPORT_TESTING_main(2, 209 GNUNET_TRANSPORT_TESTING_main (2,
209 &GNUNET_TRANSPORT_TESTING_connect_check, 210 &GNUNET_TRANSPORT_TESTING_connect_check,
210 ccc)) 211 ccc))
211 return 1; 212 return 1;
212 return 0; 213 return 0;
213} 214}
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 @@
34/** 34/**
35 * How long until we give up on transmitting the message? 35 * How long until we give up on transmitting the message?
36 */ 36 */
37#define WAIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 37#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
38 38
39#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) 39#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
40 40
41#define MTYPE 12345 41#define MTYPE 12345
42 42
@@ -52,94 +52,94 @@ static unsigned int disconnects;
52 52
53 53
54static void 54static void
55custom_shutdown(void *cls) 55custom_shutdown (void *cls)
56{ 56{
57 if (NULL != timer_task) 57 if (NULL != timer_task)
58 { 58 {
59 GNUNET_SCHEDULER_cancel(timer_task); 59 GNUNET_SCHEDULER_cancel (timer_task);
60 timer_task = NULL; 60 timer_task = NULL;
61 } 61 }
62 if (0 == disconnects) 62 if (0 == disconnects)
63 { 63 {
64 ccc->global_ret = GNUNET_OK; 64 ccc->global_ret = GNUNET_OK;
65 } 65 }
66 else 66 else
67 { 67 {
68 ccc->global_ret = -GNUNET_SYSERR; 68 ccc->global_ret = -GNUNET_SYSERR;
69 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
70 "Fail! Had %u disconnects while waiting %s\n", 70 "Fail! Had %u disconnects while waiting %s\n",
71 disconnects, 71 disconnects,
72 GNUNET_STRINGS_relative_time_to_string(WAIT, 72 GNUNET_STRINGS_relative_time_to_string (WAIT,
73 GNUNET_YES)); 73 GNUNET_YES));
74 } 74 }
75} 75}
76 76
77 77
78static void 78static void
79notify_receive(void *cls, 79notify_receive (void *cls,
80 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 80 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
81 const struct GNUNET_PeerIdentity *sender, 81 const struct GNUNET_PeerIdentity *sender,
82 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 82 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
83{ 83{
84 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
85 "Received message of type %d from peer %s!\n", 85 "Received message of type %d from peer %s!\n",
86 ntohs(message->header.type), 86 ntohs (message->header.type),
87 GNUNET_i2s(sender)); 87 GNUNET_i2s (sender));
88} 88}
89 89
90 90
91static void 91static void
92notify_disconnect(void *cls, 92notify_disconnect (void *cls,
93 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 93 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
94 const struct GNUNET_PeerIdentity *other) 94 const struct GNUNET_PeerIdentity *other)
95{ 95{
96 GNUNET_TRANSPORT_TESTING_log_disconnect(cls, 96 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
97 me, 97 me,
98 other); 98 other);
99 if (shutdown_flag != GNUNET_YES) 99 if (shutdown_flag != GNUNET_YES)
100 { 100 {
101 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 101 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
102 "FAIL! Peer `%s' disconnected during waiting period!\n", 102 "FAIL! Peer `%s' disconnected during waiting period!\n",
103 GNUNET_i2s(other)); 103 GNUNET_i2s (other));
104 disconnects++; 104 disconnects++;
105 } 105 }
106} 106}
107 107
108 108
109static void 109static void
110timer(void *cls) 110timer (void *cls)
111{ 111{
112 static unsigned int percentage; 112 static unsigned int percentage;
113 113
114 timer_task = NULL; 114 timer_task = NULL;
115 percentage += 10; 115 percentage += 10;
116 time_running = GNUNET_TIME_relative_add(time_running, 116 time_running = GNUNET_TIME_relative_add (time_running,
117 GNUNET_TIME_relative_divide(WAIT, 117 GNUNET_TIME_relative_divide (WAIT,
118 10)); 118 10));
119 119
120 if (time_running.rel_value_us == 120 if (time_running.rel_value_us ==
121 GNUNET_TIME_relative_max(time_running, WAIT).rel_value_us) 121 GNUNET_TIME_relative_max (time_running, WAIT).rel_value_us)
122 { 122 {
123 fprintf(stderr, "%s", "100%%\n"); 123 fprintf (stderr, "%s", "100%%\n");
124 shutdown_flag = GNUNET_YES; 124 shutdown_flag = GNUNET_YES;
125 GNUNET_SCHEDULER_shutdown(); 125 GNUNET_SCHEDULER_shutdown ();
126 } 126 }
127 else 127 else
128 { 128 {
129 fprintf(stderr, 129 fprintf (stderr,
130 "%u%%..", 130 "%u%%..",
131 percentage); 131 percentage);
132 timer_task = 132 timer_task =
133 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(WAIT, 10), 133 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (WAIT, 10),
134 &timer, 134 &timer,
135 NULL); 135 NULL);
136 } 136 }
137} 137}
138 138
139 139
140int 140int
141main(int argc, 141main (int argc,
142 char *argv[]) 142 char *argv[])
143{ 143{
144 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 144 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
145 .connect_continuation = &timer, 145 .connect_continuation = &timer,
@@ -153,9 +153,9 @@ main(int argc,
153 153
154 ccc = &my_ccc; 154 ccc = &my_ccc;
155 if (GNUNET_OK != 155 if (GNUNET_OK !=
156 GNUNET_TRANSPORT_TESTING_main(2, 156 GNUNET_TRANSPORT_TESTING_main (2,
157 &GNUNET_TRANSPORT_TESTING_connect_check, 157 &GNUNET_TRANSPORT_TESTING_connect_check,
158 ccc)) 158 ccc))
159 return 1; 159 return 1;
160 return 0; 160 return 0;
161} 161}
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;
58 58
59struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; 59struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
60 60
61static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; 61static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
62 62
63struct GNUNET_TRANSPORT_TESTING_Handle *tth; 63struct GNUNET_TRANSPORT_TESTING_Handle *tth;
64 64
65/** 65/**
66 * How long until we give up on transmitting the message? 66 * How long until we give up on transmitting the message?
67 */ 67 */
68#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) 68#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
69 69
70#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 70#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
71 10)
71 72
72static int stage; 73static int stage;
73static int ok; 74static int ok;
74static int connected; 75static int connected;
75 76
76static struct GNUNET_SCHEDULER_Task * die_task; 77static struct GNUNET_SCHEDULER_Task *die_task;
77 78
78static struct GNUNET_SCHEDULER_Task * timeout_task; 79static struct GNUNET_SCHEDULER_Task *timeout_task;
79 80
80static struct GNUNET_SCHEDULER_Task * stage_task; 81static struct GNUNET_SCHEDULER_Task *stage_task;
81 82
82#if VERBOSE 83#if VERBOSE
83#define OKPP do { ok++; fprintf(stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 84#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, \
85 __FILE__, __LINE__); } while (0)
84#else 86#else
85#define OKPP do { ok++; } while (0) 87#define OKPP do { ok++; } while (0)
86#endif 88#endif
87 89
88 90
89static void 91static void
90run_stage(void *cls); 92run_stage (void *cls);
91 93
92 94
93static void 95static void
94end(void *cls) 96end (void *cls)
95{ 97{
96 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); 98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping\n");
97 99
98 if (die_task != NULL) 100 if (die_task != NULL)
99 { 101 {
100 GNUNET_SCHEDULER_cancel(die_task); 102 GNUNET_SCHEDULER_cancel (die_task);
101 die_task = NULL; 103 die_task = NULL;
102 } 104 }
103 105
104 if (timeout_task != NULL) 106 if (timeout_task != NULL)
105 { 107 {
106 GNUNET_SCHEDULER_cancel(timeout_task); 108 GNUNET_SCHEDULER_cancel (timeout_task);
107 timeout_task = NULL; 109 timeout_task = NULL;
108 } 110 }
109 111
110 if (stage_task != NULL) 112 if (stage_task != NULL)
111 { 113 {
112 GNUNET_SCHEDULER_cancel(stage_task); 114 GNUNET_SCHEDULER_cancel (stage_task);
113 stage_task = NULL; 115 stage_task = NULL;
114 } 116 }
115 117
116 if (cc != NULL) 118 if (cc != NULL)
117 { 119 {
118 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 120 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
119 cc = NULL; 121 cc = NULL;
120 } 122 }
121 123
122 if (p1 != NULL) 124 if (p1 != NULL)
123 { 125 {
124 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 126 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
125 p1 = NULL; 127 p1 = NULL;
126 } 128 }
127 if (p2 != NULL) 129 if (p2 != NULL)
128 { 130 {
129 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 131 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
130 p2 = NULL; 132 p2 = NULL;
131 } 133 }
132} 134}
133 135
134 136
135static void 137static void
136end_badly(void *cls) 138end_badly (void *cls)
137{ 139{
138 die_task = NULL; 140 die_task = NULL;
139 141
140 if (timeout_task != NULL) 142 if (timeout_task != NULL)
141 { 143 {
142 GNUNET_SCHEDULER_cancel(timeout_task); 144 GNUNET_SCHEDULER_cancel (timeout_task);
143 timeout_task = NULL; 145 timeout_task = NULL;
144 } 146 }
145 147
146 if (stage_task != NULL) 148 if (stage_task != NULL)
147 { 149 {
148 GNUNET_SCHEDULER_cancel(stage_task); 150 GNUNET_SCHEDULER_cancel (stage_task);
149 stage_task = NULL; 151 stage_task = NULL;
150 } 152 }
151 153
152 if (cc != NULL) 154 if (cc != NULL)
153 { 155 {
154 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 156 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
155 cc = NULL; 157 cc = NULL;
156 } 158 }
157 if (p1 != NULL) 159 if (p1 != NULL)
158 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 160 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
159 if (p2 != NULL) 161 if (p2 != NULL)
160 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 162 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
161 163
162 ok = GNUNET_SYSERR; 164 ok = GNUNET_SYSERR;
163} 165}
164 166
165static void 167static void
166testing_connect_cb(void *cls) 168testing_connect_cb (void *cls)
167{ 169{
168 cc = NULL; 170 cc = NULL;
169 char *p1_c = GNUNET_strdup(GNUNET_i2s(&p1->id)); 171 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
170 172
171 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n", 173 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n",
172 p1->no, p1_c, p2->no, GNUNET_i2s(&p2->id)); 174 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
173 GNUNET_free(p1_c); 175 GNUNET_free (p1_c);
174 connected = GNUNET_YES; 176 connected = GNUNET_YES;
175 stage_task = GNUNET_SCHEDULER_add_now(&run_stage, NULL); 177 stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL);
176} 178}
177 179
178 180
179static void 181static void
180connect_timeout(void *cls) 182connect_timeout (void *cls)
181{ 183{
182 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 184 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
183 "Peers not connected, next stage\n"); 185 "Peers not connected, next stage\n");
184 timeout_task = NULL; 186 timeout_task = NULL;
185 stage_task = GNUNET_SCHEDULER_add_now(&run_stage, 187 stage_task = GNUNET_SCHEDULER_add_now (&run_stage,
186 NULL); 188 NULL);
187} 189}
188 190
189 191
@@ -191,371 +193,384 @@ static int started;
191 193
192 194
193static void 195static void
194start_cb(void *cls) 196start_cb (void *cls)
195{ 197{
196 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 198 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
197 199
198 started++; 200 started++;
199 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 201 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
200 "Peer %u (`%s') started\n", 202 "Peer %u (`%s') started\n",
201 p->no, 203 p->no,
202 GNUNET_i2s_full(&p->id)); 204 GNUNET_i2s_full (&p->id));
203 205
204 if (started != 2) 206 if (started != 2)
205 return; 207 return;
206 208
207 char *sender_c = GNUNET_strdup(GNUNET_i2s(&p1->id)); 209 char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
208 210
209 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", 212 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
211 p1->no, 213 p1->no,
212 sender_c, 214 sender_c,
213 p2->no, 215 p2->no,
214 GNUNET_i2s(&p2->id)); 216 GNUNET_i2s (&p2->id));
215 GNUNET_free(sender_c); 217 GNUNET_free (sender_c);
216 218
217 cc = GNUNET_TRANSPORT_TESTING_connect_peers(p1, 219 cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1,
218 p2, 220 p2,
219 &testing_connect_cb, 221 &testing_connect_cb,
220 NULL); 222 NULL);
221} 223}
222 224
223 225
224static int 226static int
225check_blacklist_config(const char *cfg_file, 227check_blacklist_config (const char *cfg_file,
226 struct GNUNET_PeerIdentity *peer, 228 struct GNUNET_PeerIdentity *peer,
227 struct GNUNET_PeerIdentity *bl_peer) 229 struct GNUNET_PeerIdentity *bl_peer)
228{ 230{
229 struct GNUNET_CONFIGURATION_Handle *cfg; 231 struct GNUNET_CONFIGURATION_Handle *cfg;
230 char *section; 232 char *section;
231 char *peer_str; 233 char *peer_str;
232 234
233 cfg = GNUNET_CONFIGURATION_create(); 235 cfg = GNUNET_CONFIGURATION_create ();
234 if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfg_file)) 236 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_file))
235 { 237 {
236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n", cfg_file); 238 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n",
237 GNUNET_CONFIGURATION_destroy(cfg); 239 cfg_file);
238 return GNUNET_SYSERR; 240 GNUNET_CONFIGURATION_destroy (cfg);
239 } 241 return GNUNET_SYSERR;
240 242 }
241 peer_str = GNUNET_strdup(GNUNET_i2s_full(peer)); 243
242 GNUNET_asprintf(&section, "transport-blacklist-%s", peer_str); 244 peer_str = GNUNET_strdup (GNUNET_i2s_full (peer));
243 245 GNUNET_asprintf (&section, "transport-blacklist-%s", peer_str);
244 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(cfg, section, GNUNET_i2s_full(bl_peer))) 246
245 { 247 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, section,
246 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 248 GNUNET_i2s_full (bl_peer)))
247 "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n", 249 {
248 cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); 250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
249 GNUNET_CONFIGURATION_destroy(cfg); 251 "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n",
250 GNUNET_free(section); 252 cfg_file, peer_str, GNUNET_i2s_full (bl_peer));
251 GNUNET_free(peer_str); 253 GNUNET_CONFIGURATION_destroy (cfg);
252 return GNUNET_SYSERR; 254 GNUNET_free (section);
253 } 255 GNUNET_free (peer_str);
254 256 return GNUNET_SYSERR;
255 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 257 }
256 "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n", 258
257 cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); 259 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
258 260 "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n",
259 GNUNET_CONFIGURATION_destroy(cfg); 261 cfg_file, peer_str, GNUNET_i2s_full (bl_peer));
260 GNUNET_free(section); 262
261 GNUNET_free(peer_str); 263 GNUNET_CONFIGURATION_destroy (cfg);
264 GNUNET_free (section);
265 GNUNET_free (peer_str);
262 return GNUNET_OK; 266 return GNUNET_OK;
263} 267}
264 268
265 269
266static void 270static void
267run_stage(void *cls) 271run_stage (void *cls)
268{ 272{
269 stage_task = NULL; 273 stage_task = NULL;
270 if (NULL != die_task) 274 if (NULL != die_task)
271 GNUNET_SCHEDULER_cancel(die_task); 275 GNUNET_SCHEDULER_cancel (die_task);
272 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); 276 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
273 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage); 277 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage);
274 278
275 if (0 == stage) 279 if (0 == stage)
280 {
281 started = GNUNET_NO;
282 connected = GNUNET_NO;
283 if (0 == strcmp (test_name, "test_transport_blacklisting_no_bl"))
276 { 284 {
277 started = GNUNET_NO; 285 /* Try to connect peers successfully */
278 connected = GNUNET_NO; 286 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
279 if (0 == strcmp(test_name, "test_transport_blacklisting_no_bl")) 287 "test_transport_blacklisting_cfg_peer1.conf",
280 { 288 1,
281 /* Try to connect peers successfully */ 289 NULL,
282 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, 290 NULL,
283 "test_transport_blacklisting_cfg_peer1.conf", 291 NULL,
284 1, 292 NULL,
285 NULL, 293 &start_cb,
286 NULL, 294 NULL);
287 NULL, 295
288 NULL, 296 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
289 &start_cb, 297 "test_transport_blacklisting_cfg_peer2.conf",
290 NULL); 298 2,
291 299 NULL,
292 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, 300 NULL,
293 "test_transport_blacklisting_cfg_peer2.conf", 301 NULL,
294 2, 302 NULL,
295 NULL, 303 &start_cb,
296 NULL, 304 NULL);
297 NULL,
298 NULL,
299 &start_cb,
300 NULL);
301 }
302 else if (0 == strcmp(test_name,
303 "test_transport_blacklisting_outbound_bl_full"))
304 {
305 const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_full.conf";
306 const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf";
307
308 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
309 cfg_p1,
310 1, NULL, NULL, NULL,
311 NULL,
312 &start_cb, NULL);
313 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
314 cfg_p2, 2,
315 NULL, NULL, NULL,
316 NULL,
317 &start_cb, NULL);
318
319 /* check if configuration contain correct blacklist entries */
320 if ((GNUNET_SYSERR ==
321 check_blacklist_config(cfg_p1, &p1->id, &p2->id)) ||
322 (GNUNET_SYSERR ==
323 check_blacklist_config(cfg_p2, &p2->id, &p1->id)))
324 {
325 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
326 p1 = NULL;
327 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
328 p2 = NULL;
329 ok = 1;
330 GNUNET_SCHEDULER_add_now(&end, NULL);
331 }
332 }
333 else if (0
334 == strcmp(test_name, "test_transport_blacklisting_outbound_bl_plugin"))
335 {
336 const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_plugin.conf";
337 const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf";
338
339 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
340 cfg_p1,
341 1,
342 NULL,
343 NULL,
344 NULL,
345 NULL,
346 &start_cb,
347 NULL);
348
349 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
350 cfg_p2, 2,
351 NULL,
352 NULL,
353 NULL,
354 NULL,
355 &start_cb,
356 NULL);
357
358 /* check if configuration contain correct blacklist entries */
359 if ((GNUNET_SYSERR ==
360 check_blacklist_config(cfg_p1, &p1->id, &p2->id)) ||
361 (GNUNET_SYSERR ==
362 check_blacklist_config(cfg_p2, &p2->id, &p1->id)))
363 {
364 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
365 p1 = NULL;
366 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
367 p2 = NULL;
368 ok = 1;
369 GNUNET_SCHEDULER_add_now(&end, NULL);
370 }
371 }
372 else if (0 == strcmp(test_name,
373 "test_transport_blacklisting_inbound_bl_full"))
374 {
375 const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf";
376 const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf";
377
378 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
379 cfg_p1, 1,
380 NULL,
381 NULL, NULL, NULL,
382 &start_cb, NULL);
383
384 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
385 cfg_p2, 2,
386 NULL,
387 NULL, NULL, NULL,
388 &start_cb, NULL);
389
390 /* check if configuration contain correct blacklist entries */
391 if ((GNUNET_SYSERR ==
392 check_blacklist_config(cfg_p2, &p2->id, &p1->id)))
393 {
394 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
395 p1 = NULL;
396 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
397 p2 = NULL;
398 ok = 1;
399 GNUNET_SCHEDULER_add_now(&end, NULL);
400 }
401 }
402 else if (0 == strcmp(test_name,
403 "test_transport_blacklisting_inbound_bl_plugin"))
404 {
405 const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf";
406 const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf";
407
408 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
409 cfg_p1, 1,
410 NULL,
411 NULL, NULL, NULL,
412 &start_cb, NULL);
413
414 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
415 cfg_p2, 2,
416 NULL,
417 NULL, NULL,
418 NULL,
419 &start_cb, NULL);
420
421 /* check if configuration contain correct blacklist entries */
422 if ((GNUNET_SYSERR ==
423 check_blacklist_config(cfg_p2, &p2->id, &p1->id)))
424 {
425 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
426 p1 = NULL;
427 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
428 p2 = NULL;
429 ok = 1;
430 GNUNET_SCHEDULER_add_now(&end, NULL);
431 }
432 }
433 else if (0 == strcmp(test_name,
434 "test_transport_blacklisting_multiple_plugins"))
435 {
436 const char * cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf";
437 const char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf";
438
439 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
440 cfg_p1, 1,
441 NULL,
442 NULL, NULL, NULL,
443 &start_cb, NULL);
444
445 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
446 cfg_p2, 2,
447 NULL,
448 NULL, NULL, NULL,
449 &start_cb, NULL);
450
451 /* check if configuration contain correct blacklist entries */
452 if ((GNUNET_SYSERR ==
453 check_blacklist_config(cfg_p1, &p1->id, &p2->id)) ||
454 (GNUNET_SYSERR ==
455 check_blacklist_config(cfg_p2, &p2->id, &p1->id)))
456 {
457 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
458 p1 = NULL;
459 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
460 p2 = NULL;
461 ok = 1;
462 GNUNET_SCHEDULER_add_now(&end, NULL);
463 }
464 }
465 else
466 {
467 GNUNET_break(0);
468 GNUNET_SCHEDULER_add_now(&end, NULL);
469 }
470
471 if ((NULL == p1) || (NULL == p2))
472 {
473 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start peers\n");
474 ok = 1;
475 GNUNET_SCHEDULER_add_now(&end, NULL);
476 }
477
478 timeout_task = GNUNET_SCHEDULER_add_delayed(CONNECT_TIMEOUT,
479 &connect_timeout,
480 NULL);
481 stage++;
482 return;
483 } 305 }
484 306 else if (0 == strcmp (test_name,
485 if (cc != NULL) 307 "test_transport_blacklisting_outbound_bl_full"))
486 { 308 {
487 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 309 const char *cfg_p1 =
488 cc = NULL; 310 "test_transport_blacklisting_cfg_blp_peer1_full.conf";
311 const char *cfg_p2 =
312 "test_transport_blacklisting_cfg_blp_peer2_full.conf";
313
314 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
315 cfg_p1,
316 1, NULL, NULL, NULL,
317 NULL,
318 &start_cb, NULL);
319 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
320 cfg_p2, 2,
321 NULL, NULL, NULL,
322 NULL,
323 &start_cb, NULL);
324
325 /* check if configuration contain correct blacklist entries */
326 if ((GNUNET_SYSERR ==
327 check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
328 (GNUNET_SYSERR ==
329 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
330 {
331 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
332 p1 = NULL;
333 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
334 p2 = NULL;
335 ok = 1;
336 GNUNET_SCHEDULER_add_now (&end, NULL);
337 }
489 } 338 }
490 339 else if (0
491 if (p1 != NULL) 340 == strcmp (test_name,
341 "test_transport_blacklisting_outbound_bl_plugin"))
492 { 342 {
493 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 343 const char *cfg_p1 =
494 p1 = NULL; 344 "test_transport_blacklisting_cfg_blp_peer1_plugin.conf";
345 const char *cfg_p2 =
346 "test_transport_blacklisting_cfg_blp_peer2_plugin.conf";
347
348 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
349 cfg_p1,
350 1,
351 NULL,
352 NULL,
353 NULL,
354 NULL,
355 &start_cb,
356 NULL);
357
358 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
359 cfg_p2, 2,
360 NULL,
361 NULL,
362 NULL,
363 NULL,
364 &start_cb,
365 NULL);
366
367 /* check if configuration contain correct blacklist entries */
368 if ((GNUNET_SYSERR ==
369 check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
370 (GNUNET_SYSERR ==
371 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
372 {
373 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
374 p1 = NULL;
375 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
376 p2 = NULL;
377 ok = 1;
378 GNUNET_SCHEDULER_add_now (&end, NULL);
379 }
495 } 380 }
496 if (p2 != NULL) 381 else if (0 == strcmp (test_name,
382 "test_transport_blacklisting_inbound_bl_full"))
383 {
384 const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf";
385 const char *cfg_p2 =
386 "test_transport_blacklisting_cfg_blp_peer2_full.conf";
387
388 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
389 cfg_p1, 1,
390 NULL,
391 NULL, NULL, NULL,
392 &start_cb, NULL);
393
394 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
395 cfg_p2, 2,
396 NULL,
397 NULL, NULL, NULL,
398 &start_cb, NULL);
399
400 /* check if configuration contain correct blacklist entries */
401 if ((GNUNET_SYSERR ==
402 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
403 {
404 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
405 p1 = NULL;
406 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
407 p2 = NULL;
408 ok = 1;
409 GNUNET_SCHEDULER_add_now (&end, NULL);
410 }
411 }
412 else if (0 == strcmp (test_name,
413 "test_transport_blacklisting_inbound_bl_plugin"))
414 {
415 const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf";
416 const char *cfg_p2 =
417 "test_transport_blacklisting_cfg_blp_peer2_plugin.conf";
418
419 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
420 cfg_p1, 1,
421 NULL,
422 NULL, NULL, NULL,
423 &start_cb, NULL);
424
425 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
426 cfg_p2, 2,
427 NULL,
428 NULL, NULL,
429 NULL,
430 &start_cb, NULL);
431
432 /* check if configuration contain correct blacklist entries */
433 if ((GNUNET_SYSERR ==
434 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
435 {
436 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
437 p1 = NULL;
438 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
439 p2 = NULL;
440 ok = 1;
441 GNUNET_SCHEDULER_add_now (&end, NULL);
442 }
443 }
444 else if (0 == strcmp (test_name,
445 "test_transport_blacklisting_multiple_plugins"))
446 {
447 const char *cfg_p1 =
448 "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf";
449 const char *cfg_p2 =
450 "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf";
451
452 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
453 cfg_p1, 1,
454 NULL,
455 NULL, NULL, NULL,
456 &start_cb, NULL);
457
458 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
459 cfg_p2, 2,
460 NULL,
461 NULL, NULL, NULL,
462 &start_cb, NULL);
463
464 /* check if configuration contain correct blacklist entries */
465 if ((GNUNET_SYSERR ==
466 check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
467 (GNUNET_SYSERR ==
468 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
469 {
470 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
471 p1 = NULL;
472 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
473 p2 = NULL;
474 ok = 1;
475 GNUNET_SCHEDULER_add_now (&end, NULL);
476 }
477 }
478 else
497 { 479 {
498 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 480 GNUNET_break (0);
499 p2 = NULL; 481 GNUNET_SCHEDULER_add_now (&end, NULL);
500 } 482 }
501 483
502 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n", 484 if ((NULL == p1) || (NULL == p2))
503 stage, (GNUNET_NO == started) ? "NOT STARTED" : "STARTED", 485 {
504 (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED"); 486 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start peers\n");
487 ok = 1;
488 GNUNET_SCHEDULER_add_now (&end, NULL);
489 }
505 490
506 if ((0 == strcmp(test_name, "test_transport_blacklisting_no_bl")) 491 timeout_task = GNUNET_SCHEDULER_add_delayed (CONNECT_TIMEOUT,
507 || (0 == strcmp(test_name, "test_transport_blacklisting_multiple_plugins"))) 492 &connect_timeout,
493 NULL);
494 stage++;
495 return;
496 }
497
498 if (cc != NULL)
499 {
500 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
501 cc = NULL;
502 }
503
504 if (p1 != NULL)
505 {
506 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
507 p1 = NULL;
508 }
509 if (p2 != NULL)
510 {
511 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
512 p2 = NULL;
513 }
514
515 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n",
516 stage, (GNUNET_NO == started) ? "NOT STARTED" : "STARTED",
517 (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED");
518
519 if ((0 == strcmp (test_name, "test_transport_blacklisting_no_bl"))
520 || (0 == strcmp (test_name,
521 "test_transport_blacklisting_multiple_plugins")))
522 {
523 if ((GNUNET_NO != started) && (GNUNET_YES == connected))
524 ok = 0;
525 else
508 { 526 {
509 if ((GNUNET_NO != started) && (GNUNET_YES == connected)) 527 GNUNET_break (0);
510 ok = 0; 528 ok = 1;
511 else
512 {
513 GNUNET_break(0);
514 ok = 1;
515 }
516 } 529 }
530 }
517 else 531 else
532 {
533 if ((GNUNET_NO != started) && (GNUNET_YES != connected))
534 ok = 0;
535 else
518 { 536 {
519 if ((GNUNET_NO != started) && (GNUNET_YES != connected)) 537 ok = 1;
520 ok = 0;
521 else
522 {
523 ok = 1;
524 }
525 } 538 }
526 GNUNET_SCHEDULER_add_now(&end, NULL); 539 }
540 GNUNET_SCHEDULER_add_now (&end, NULL);
527} 541}
528 542
529static void 543static void
530run(void *cls, char * const *args, const char *cfgfile, 544run (void *cls, char *const *args, const char *cfgfile,
531 const struct GNUNET_CONFIGURATION_Handle *cfg) 545 const struct GNUNET_CONFIGURATION_Handle *cfg)
532{ 546{
533 connected = GNUNET_NO; 547 connected = GNUNET_NO;
534 stage = 0; 548 stage = 0;
535 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running test `%s'!\n", test_name); 549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running test `%s'!\n", test_name);
536 stage_task = GNUNET_SCHEDULER_add_now(&run_stage, NULL); 550 stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL);
537} 551}
538 552
539int 553int
540main(int argc, char *argv0[]) 554main (int argc, char *argv0[])
541{ 555{
542 ok = 1; 556 ok = 1;
543 557
544 test_name = GNUNET_TRANSPORT_TESTING_get_test_name(argv0[0]); 558 test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0[0]);
545 559
546 GNUNET_log_setup("test-transport-api-blacklisting", "WARNING", NULL); 560 GNUNET_log_setup ("test-transport-api-blacklisting", "WARNING", NULL);
547 561
548 static char * const argv[] = 562 static char *const argv[] =
549 { "date", "-c", "test_transport_api_data.conf", NULL }; 563 { "date", "-c", "test_transport_api_data.conf", NULL };
550 static struct GNUNET_GETOPT_CommandLineOption options[] = 564 static struct GNUNET_GETOPT_CommandLineOption options[] =
551 { GNUNET_GETOPT_OPTION_END }; 565 { GNUNET_GETOPT_OPTION_END };
552 566
553 tth = GNUNET_TRANSPORT_TESTING_init(); 567 tth = GNUNET_TRANSPORT_TESTING_init ();
554 568
555 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, argv, 569 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, argv,
556 "test-transport-api-blacklisting", "nohelp", options, &run, NULL); 570 "test-transport-api-blacklisting", "nohelp", options,
571 &run, NULL);
557 572
558 GNUNET_TRANSPORT_TESTING_done(tth); 573 GNUNET_TRANSPORT_TESTING_done (tth);
559 574
560 return ok; 575 return ok;
561} 576}
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 @@
26#include "gnunet_transport_service.h" 26#include "gnunet_transport_service.h"
27#include "transport-testing.h" 27#include "transport-testing.h"
28 28
29#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 29#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
30 30
31 31
32static struct GNUNET_SCHEDULER_Task *timeout_task; 32static struct GNUNET_SCHEDULER_Task *timeout_task;
@@ -39,104 +39,104 @@ static int ret;
39 39
40 40
41static void 41static void
42end() 42end ()
43{ 43{
44 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
45 "Stopping peers\n"); 45 "Stopping peers\n");
46 if (NULL != timeout_task) 46 if (NULL != timeout_task)
47 GNUNET_SCHEDULER_cancel(timeout_task); 47 GNUNET_SCHEDULER_cancel (timeout_task);
48 if (NULL != p) 48 if (NULL != p)
49 GNUNET_TRANSPORT_TESTING_stop_peer(p); 49 GNUNET_TRANSPORT_TESTING_stop_peer (p);
50 if (NULL != tth) 50 if (NULL != tth)
51 GNUNET_TRANSPORT_TESTING_done(tth); 51 GNUNET_TRANSPORT_TESTING_done (tth);
52} 52}
53 53
54 54
55static void 55static void
56end_badly() 56end_badly ()
57{ 57{
58 timeout_task = NULL; 58 timeout_task = NULL;
59 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 59 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
60 "Timeout!\n"); 60 "Timeout!\n");
61 end(); 61 end ();
62 ret = GNUNET_SYSERR; 62 ret = GNUNET_SYSERR;
63} 63}
64 64
65 65
66static void 66static void
67restart_cb(void *cls) 67restart_cb (void *cls)
68{ 68{
69 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
70 "Peer %u (`%s') successfully restarted\n", 70 "Peer %u (`%s') successfully restarted\n",
71 p->no, 71 p->no,
72 GNUNET_i2s(&p->id)); 72 GNUNET_i2s (&p->id));
73 ret = 0; 73 ret = 0;
74 GNUNET_SCHEDULER_add_now(&end, 74 GNUNET_SCHEDULER_add_now (&end,
75 NULL); 75 NULL);
76} 76}
77 77
78 78
79static void 79static void
80restart_task() 80restart_task ()
81{ 81{
82 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
83 "Peer %u (`%s') restarting\n", 83 "Peer %u (`%s') restarting\n",
84 p->no, 84 p->no,
85 GNUNET_i2s(&p->id)); 85 GNUNET_i2s (&p->id));
86 GNUNET_TRANSPORT_TESTING_restart_peer(p, 86 GNUNET_TRANSPORT_TESTING_restart_peer (p,
87 &restart_cb, 87 &restart_cb,
88 p); 88 p);
89} 89}
90 90
91 91
92static void 92static void
93start_cb(void *cls) 93start_cb (void *cls)
94{ 94{
95 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
96 "Peer %u (`%s') successfully started\n", 96 "Peer %u (`%s') successfully started\n",
97 p->no, 97 p->no,
98 GNUNET_i2s(&p->id)); 98 GNUNET_i2s (&p->id));
99 GNUNET_SCHEDULER_add_now(&restart_task, 99 GNUNET_SCHEDULER_add_now (&restart_task,
100 NULL); 100 NULL);
101} 101}
102 102
103 103
104static void 104static void
105run(void *cls, 105run (void *cls,
106 char *const *args, 106 char *const *args,
107 const char *cfgfile, 107 const char *cfgfile,
108 const struct GNUNET_CONFIGURATION_Handle *cfg) 108 const struct GNUNET_CONFIGURATION_Handle *cfg)
109{ 109{
110 ret = 1; 110 ret = 1;
111 tth = GNUNET_TRANSPORT_TESTING_init(); 111 tth = GNUNET_TRANSPORT_TESTING_init ();
112 GNUNET_assert(NULL != tth); 112 GNUNET_assert (NULL != tth);
113 113
114 timeout_task 114 timeout_task
115 = GNUNET_SCHEDULER_add_delayed(TIMEOUT, 115 = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
116 &end_badly, 116 &end_badly,
117 NULL); 117 NULL);
118 p = GNUNET_TRANSPORT_TESTING_start_peer(tth, 118 p = GNUNET_TRANSPORT_TESTING_start_peer (tth,
119 cfgfile, 119 cfgfile,
120 1, 120 1,
121 NULL, /* receive cb */ 121 NULL, /* receive cb */
122 NULL, /* connect cb */ 122 NULL, /* connect cb */
123 NULL, /* disconnect cb */ 123 NULL, /* disconnect cb */
124 NULL, /* nc/nd closure */ 124 NULL, /* nc/nd closure */
125 start_cb, /* startup cb */ 125 start_cb, /* startup cb */
126 NULL); /* closure */ 126 NULL); /* closure */
127 if (NULL == p) 127 if (NULL == p)
128 { 128 {
129 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
130 "Failed to start peer\n"); 130 "Failed to start peer\n");
131 end(); 131 end ();
132 ret = 1; 132 ret = 1;
133 } 133 }
134} 134}
135 135
136 136
137int 137int
138main(int argc, 138main (int argc,
139 char *argv[]) 139 char *argv[])
140{ 140{
141 char *const argv_1[] = { "test_transport_testing_restart", 141 char *const argv_1[] = { "test_transport_testing_restart",
142 "-c", 142 "-c",
@@ -146,16 +146,16 @@ main(int argc,
146 GNUNET_GETOPT_OPTION_END 146 GNUNET_GETOPT_OPTION_END
147 }; 147 };
148 148
149 GNUNET_log_setup("test_transport_testing_restart", 149 GNUNET_log_setup ("test_transport_testing_restart",
150 "WARNING", 150 "WARNING",
151 NULL); 151 NULL);
152 GNUNET_PROGRAM_run((sizeof(argv_1) / sizeof(char *)) - 1, 152 GNUNET_PROGRAM_run ((sizeof(argv_1) / sizeof(char *)) - 1,
153 argv_1, 153 argv_1,
154 "test_transport_testing_restart", 154 "test_transport_testing_restart",
155 "nohelp", 155 "nohelp",
156 options, 156 options,
157 &run, 157 &run,
158 NULL); 158 NULL);
159 return ret; 159 return ret;
160} 160}
161 161
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 @@
26#include "gnunet_transport_service.h" 26#include "gnunet_transport_service.h"
27#include "transport-testing.h" 27#include "transport-testing.h"
28 28
29#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 29#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
30 30
31 31
32static struct GNUNET_SCHEDULER_Task *timeout_task; 32static struct GNUNET_SCHEDULER_Task *timeout_task;
@@ -39,79 +39,79 @@ static int ret;
39 39
40 40
41static void 41static void
42end() 42end ()
43{ 43{
44 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
45 "Stopping peers\n"); 45 "Stopping peers\n");
46 if (NULL != timeout_task) 46 if (NULL != timeout_task)
47 GNUNET_SCHEDULER_cancel(timeout_task); 47 GNUNET_SCHEDULER_cancel (timeout_task);
48 if (NULL != p) 48 if (NULL != p)
49 GNUNET_TRANSPORT_TESTING_stop_peer(p); 49 GNUNET_TRANSPORT_TESTING_stop_peer (p);
50 if (NULL != tth) 50 if (NULL != tth)
51 GNUNET_TRANSPORT_TESTING_done(tth); 51 GNUNET_TRANSPORT_TESTING_done (tth);
52} 52}
53 53
54 54
55static void 55static void
56end_badly() 56end_badly ()
57{ 57{
58 timeout_task = NULL; 58 timeout_task = NULL;
59 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 59 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
60 "Timeout!\n"); 60 "Timeout!\n");
61 end(); 61 end ();
62 ret = GNUNET_SYSERR; 62 ret = GNUNET_SYSERR;
63} 63}
64 64
65 65
66static void 66static void
67start_cb(void *cls) 67start_cb (void *cls)
68{ 68{
69 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
70 "Peer %u (`%s') successfully started\n", 70 "Peer %u (`%s') successfully started\n",
71 p->no, 71 p->no,
72 GNUNET_i2s(&p->id)); 72 GNUNET_i2s (&p->id));
73 ret = 0; 73 ret = 0;
74 GNUNET_SCHEDULER_add_now(&end, 74 GNUNET_SCHEDULER_add_now (&end,
75 NULL); 75 NULL);
76} 76}
77 77
78 78
79static void 79static void
80run(void *cls, 80run (void *cls,
81 char *const *args, 81 char *const *args,
82 const char *cfgfile, 82 const char *cfgfile,
83 const struct GNUNET_CONFIGURATION_Handle *cfg) 83 const struct GNUNET_CONFIGURATION_Handle *cfg)
84{ 84{
85 ret = 1; 85 ret = 1;
86 tth = GNUNET_TRANSPORT_TESTING_init(); 86 tth = GNUNET_TRANSPORT_TESTING_init ();
87 GNUNET_assert(NULL != tth); 87 GNUNET_assert (NULL != tth);
88 88
89 timeout_task = 89 timeout_task =
90 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, 90 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
91 &end_badly, 91 &end_badly,
92 NULL); 92 NULL);
93 93
94 p = GNUNET_TRANSPORT_TESTING_start_peer(tth, 94 p = GNUNET_TRANSPORT_TESTING_start_peer (tth,
95 cfgfile, 95 cfgfile,
96 1, 96 1,
97 NULL, /* receive cb */ 97 NULL, /* receive cb */
98 NULL, /* connect cb */ 98 NULL, /* connect cb */
99 NULL, /* disconnect cb */ 99 NULL, /* disconnect cb */
100 NULL, /* nc/nd closure */ 100 NULL, /* nc/nd closure */
101 &start_cb, /* startup cb */ 101 &start_cb, /* startup cb */
102 NULL); /* closure */ 102 NULL); /* closure */
103 if (NULL == p) 103 if (NULL == p)
104 { 104 {
105 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); 105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n");
106 if (timeout_task != NULL) 106 if (timeout_task != NULL)
107 GNUNET_SCHEDULER_cancel(timeout_task); 107 GNUNET_SCHEDULER_cancel (timeout_task);
108 timeout_task = GNUNET_SCHEDULER_add_now(&end_badly, NULL); 108 timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
109 } 109 }
110} 110}
111 111
112 112
113int 113int
114main(int argc, char *argv[]) 114main (int argc, char *argv[])
115{ 115{
116 char *const argv_1[] = { "test_transport_testing", 116 char *const argv_1[] = { "test_transport_testing",
117 "-c", 117 "-c",
@@ -121,15 +121,15 @@ main(int argc, char *argv[])
121 GNUNET_GETOPT_OPTION_END 121 GNUNET_GETOPT_OPTION_END
122 }; 122 };
123 123
124 GNUNET_log_setup("test_transport_testing_startstop", 124 GNUNET_log_setup ("test_transport_testing_startstop",
125 "WARNING", 125 "WARNING",
126 NULL); 126 NULL);
127 GNUNET_PROGRAM_run((sizeof(argv_1) / sizeof(char *)) - 1, 127 GNUNET_PROGRAM_run ((sizeof(argv_1) / sizeof(char *)) - 1,
128 argv_1, 128 argv_1,
129 "test_transport_testing_startstop", "nohelp", 129 "test_transport_testing_startstop", "nohelp",
130 options, 130 options,
131 &run, 131 &run,
132 &ret); 132 &ret);
133 133
134 return ret; 134 return ret;
135} 135}
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 @@
33 * @return extracted file name, has to be freed by caller 33 * @return extracted file name, has to be freed by caller
34 */ 34 */
35static char * 35static char *
36extract_filename(const char *file) 36extract_filename (const char *file)
37{ 37{
38 char *pch = GNUNET_strdup(file); 38 char *pch = GNUNET_strdup (file);
39 char *backup = pch; 39 char *backup = pch;
40 char *filename = NULL; 40 char *filename = NULL;
41 char *res; 41 char *res;
42 42
43 if (NULL != strstr(pch, "/")) 43 if (NULL != strstr (pch, "/"))
44 {
45 pch = strtok (pch, "/");
46 while (pch != NULL)
44 { 47 {
45 pch = strtok(pch, "/"); 48 pch = strtok (NULL, "/");
46 while (pch != NULL) 49 if (pch != NULL)
47 { 50 {
48 pch = strtok(NULL, "/"); 51 filename = pch;
49 if (pch != NULL) 52 }
50 {
51 filename = pch;
52 }
53 }
54 } 53 }
54 }
55 else 55 else
56 filename = pch; 56 filename = pch;
57 57
58 res = GNUNET_strdup(filename); 58 res = GNUNET_strdup (filename);
59 GNUNET_free(backup); 59 GNUNET_free (backup);
60 return res; 60 return res;
61} 61}
62 62
@@ -69,9 +69,9 @@ extract_filename(const char *file)
69 * @return the result 69 * @return the result
70 */ 70 */
71char * 71char *
72GNUNET_TRANSPORT_TESTING_get_test_name(const char *file) 72GNUNET_TRANSPORT_TESTING_get_test_name (const char *file)
73{ 73{
74 char *backup = extract_filename(file); 74 char *backup = extract_filename (file);
75 char *filename = backup; 75 char *filename = backup;
76 char *dotexe; 76 char *dotexe;
77 char *ret; 77 char *ret;
@@ -80,18 +80,18 @@ GNUNET_TRANSPORT_TESTING_get_test_name(const char *file)
80 return NULL; 80 return NULL;
81 81
82 /* remove "lt-" */ 82 /* remove "lt-" */
83 filename = strstr(filename, "test"); 83 filename = strstr (filename, "test");
84 if (NULL == filename) 84 if (NULL == filename)
85 { 85 {
86 GNUNET_free(backup); 86 GNUNET_free (backup);
87 return NULL; 87 return NULL;
88 } 88 }
89 89
90 /* remove ".exe" */ 90 /* remove ".exe" */
91 if (NULL != (dotexe = strstr(filename, ".exe"))) 91 if (NULL != (dotexe = strstr (filename, ".exe")))
92 dotexe[0] = '\0'; 92 dotexe[0] = '\0';
93 ret = GNUNET_strdup(filename); 93 ret = GNUNET_strdup (filename);
94 GNUNET_free(backup); 94 GNUNET_free (backup);
95 return ret; 95 return ret;
96} 96}
97 97
@@ -103,12 +103,12 @@ GNUNET_TRANSPORT_TESTING_get_test_name(const char *file)
103 * @return the result 103 * @return the result
104 */ 104 */
105char * 105char *
106GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file) 106GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file)
107{ 107{
108 char *src = extract_filename(file); 108 char *src = extract_filename (file);
109 char *split; 109 char *split;
110 110
111 split = strstr(src, "."); 111 split = strstr (src, ".");
112 if (NULL != split) 112 if (NULL != split)
113 split[0] = '\0'; 113 split[0] = '\0';
114 return src; 114 return src;
@@ -123,40 +123,40 @@ GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file)
123 * @return the result 123 * @return the result
124 */ 124 */
125char * 125char *
126GNUNET_TRANSPORT_TESTING_get_test_plugin_name(const char *file, 126GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file,
127 const char *test) 127 const char *test)
128{ 128{
129 char *filename; 129 char *filename;
130 char *dotexe; 130 char *dotexe;
131 char *e = extract_filename(file); 131 char *e = extract_filename (file);
132 char *t = extract_filename(test); 132 char *t = extract_filename (test);
133 char *ret; 133 char *ret;
134 134
135 if (NULL == e) 135 if (NULL == e)
136 goto fail; 136 goto fail;
137 /* remove "lt-" */ 137 /* remove "lt-" */
138 filename = strstr(e, "tes"); 138 filename = strstr (e, "tes");
139 if (NULL == filename) 139 if (NULL == filename)
140 goto fail; 140 goto fail;
141 /* remove ".exe" */ 141 /* remove ".exe" */
142 if (NULL != (dotexe = strstr(filename, ".exe"))) 142 if (NULL != (dotexe = strstr (filename, ".exe")))
143 dotexe[0] = '\0'; 143 dotexe[0] = '\0';
144 144
145 /* find last _ */ 145 /* find last _ */
146 filename = strstr(filename, t); 146 filename = strstr (filename, t);
147 if (NULL == filename) 147 if (NULL == filename)
148 goto fail; 148 goto fail;
149 /* copy plugin */ 149 /* copy plugin */
150 filename += strlen(t); 150 filename += strlen (t);
151 if ('\0' != *filename) 151 if ('\0' != *filename)
152 filename++; 152 filename++;
153 ret = GNUNET_strdup(filename); 153 ret = GNUNET_strdup (filename);
154 goto suc; 154 goto suc;
155fail: 155fail:
156 ret = NULL; 156 ret = NULL;
157suc: 157suc:
158 GNUNET_free(t); 158 GNUNET_free (t);
159 GNUNET_free(e); 159 GNUNET_free (e);
160 return ret; 160 return ret;
161} 161}
162 162
@@ -170,10 +170,10 @@ suc:
170 * @return the result 170 * @return the result
171 */ 171 */
172char * 172char *
173GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, 173GNUNET_TRANSPORT_TESTING_get_config_name (const char *file,
174 int count) 174 int count)
175{ 175{
176 char *filename = extract_filename(file); 176 char *filename = extract_filename (file);
177 char *backup = filename; 177 char *backup = filename;
178 char *dotexe; 178 char *dotexe;
179 char *ret; 179 char *ret;
@@ -181,20 +181,20 @@ GNUNET_TRANSPORT_TESTING_get_config_name(const char *file,
181 if (NULL == filename) 181 if (NULL == filename)
182 return NULL; 182 return NULL;
183 /* remove "lt-" */ 183 /* remove "lt-" */
184 filename = strstr(filename, "test"); 184 filename = strstr (filename, "test");
185 if (NULL == filename) 185 if (NULL == filename)
186 goto fail; 186 goto fail;
187 /* remove ".exe" */ 187 /* remove ".exe" */
188 if (NULL != (dotexe = strstr(filename, ".exe"))) 188 if (NULL != (dotexe = strstr (filename, ".exe")))
189 dotexe[0] = '\0'; 189 dotexe[0] = '\0';
190 GNUNET_asprintf(&ret, 190 GNUNET_asprintf (&ret,
191 "%s_peer%u.conf", 191 "%s_peer%u.conf",
192 filename, 192 filename,
193 count); 193 count);
194 GNUNET_free(backup); 194 GNUNET_free (backup);
195 return ret; 195 return ret;
196fail: 196fail:
197 GNUNET_free(backup); 197 GNUNET_free (backup);
198 return NULL; 198 return NULL;
199} 199}
200 200
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 @@
1
2/* 1/*
3 This file is part of GNUnet. 2 This file is part of GNUnet.
4 Copyright (C) 2016 GNUnet e.V. 3 Copyright (C) 2016 GNUnet e.V.
@@ -34,19 +33,20 @@
34 * @param other peer that connected. 33 * @param other peer that connected.
35 */ 34 */
36void 35void
37GNUNET_TRANSPORT_TESTING_log_connect(void *cls, 36GNUNET_TRANSPORT_TESTING_log_connect (void *cls,
38 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 37 struct
39 const struct GNUNET_PeerIdentity *other) 38 GNUNET_TRANSPORT_TESTING_PeerContext *me,
39 const struct GNUNET_PeerIdentity *other)
40{ 40{
41 char *ps; 41 char *ps;
42 42
43 ps = GNUNET_strdup(GNUNET_i2s(&me->id)); 43 ps = GNUNET_strdup (GNUNET_i2s (&me->id));
44 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 44 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
45 "Peer %s connected to %u (%s)!\n", 45 "Peer %s connected to %u (%s)!\n",
46 GNUNET_i2s(other), 46 GNUNET_i2s (other),
47 me->no, 47 me->no,
48 ps); 48 ps);
49 GNUNET_free(ps); 49 GNUNET_free (ps);
50} 50}
51 51
52 52
@@ -59,19 +59,22 @@ GNUNET_TRANSPORT_TESTING_log_connect(void *cls,
59 * @param other peer that disconnected. 59 * @param other peer that disconnected.
60 */ 60 */
61void 61void
62GNUNET_TRANSPORT_TESTING_log_disconnect(void *cls, 62GNUNET_TRANSPORT_TESTING_log_disconnect (void *cls,
63 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 63 struct
64 const struct GNUNET_PeerIdentity *other) 64 GNUNET_TRANSPORT_TESTING_PeerContext *
65 me,
66 const struct
67 GNUNET_PeerIdentity *other)
65{ 68{
66 char *ps; 69 char *ps;
67 70
68 ps = GNUNET_strdup(GNUNET_i2s(&me->id)); 71 ps = GNUNET_strdup (GNUNET_i2s (&me->id));
69 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 72 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
70 "Peer `%s' disconnected from %u (%s)!\n", 73 "Peer `%s' disconnected from %u (%s)!\n",
71 GNUNET_i2s(other), 74 GNUNET_i2s (other),
72 me->no, 75 me->no,
73 ps); 76 ps);
74 GNUNET_free(ps); 77 GNUNET_free (ps);
75} 78}
76 79
77/* end of transport-testing-loggers.c */ 80/* 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 @@
28/** 28/**
29 * Closure for #connect_cb. 29 * Closure for #connect_cb.
30 */ 30 */
31struct GNUNET_TRANSPORT_TESTING_ConnectRequestList { 31struct GNUNET_TRANSPORT_TESTING_ConnectRequestList
32{
32 /** 33 /**
33 * Stored in a DLL. 34 * Stored in a DLL.
34 */ 35 */
@@ -67,41 +68,41 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequestList {
67 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` 68 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *`
68 */ 69 */
69static void 70static void
70do_shutdown(void *cls) 71do_shutdown (void *cls)
71{ 72{
72 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; 73 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
73 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; 74 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl;
74 75
75 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
76 "Testcase shutting down\n"); 77 "Testcase shutting down\n");
77 if (NULL != ccc->shutdown_task) 78 if (NULL != ccc->shutdown_task)
78 ccc->shutdown_task(ccc->shutdown_task_cls); 79 ccc->shutdown_task (ccc->shutdown_task_cls);
79 if (NULL != ccc->timeout_task) 80 if (NULL != ccc->timeout_task)
80 { 81 {
81 GNUNET_SCHEDULER_cancel(ccc->timeout_task); 82 GNUNET_SCHEDULER_cancel (ccc->timeout_task);
82 ccc->timeout_task = NULL; 83 ccc->timeout_task = NULL;
83 } 84 }
84 if (NULL != ccc->connect_task) 85 if (NULL != ccc->connect_task)
85 { 86 {
86 GNUNET_SCHEDULER_cancel(ccc->connect_task); 87 GNUNET_SCHEDULER_cancel (ccc->connect_task);
87 ccc->connect_task = NULL; 88 ccc->connect_task = NULL;
88 } 89 }
89 while (NULL != (crl = ccc->crl_head)) 90 while (NULL != (crl = ccc->crl_head))
90 { 91 {
91 GNUNET_CONTAINER_DLL_remove(ccc->crl_head, 92 GNUNET_CONTAINER_DLL_remove (ccc->crl_head,
92 ccc->crl_tail, 93 ccc->crl_tail,
93 crl); 94 crl);
94 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(crl->cr); 95 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (crl->cr);
95 GNUNET_free(crl); 96 GNUNET_free (crl);
96 } 97 }
97 for (unsigned int i = 0; i < ccc->num_peers; i++) 98 for (unsigned int i = 0; i < ccc->num_peers; i++)
99 {
100 if (NULL != ccc->p[i])
98 { 101 {
99 if (NULL != ccc->p[i]) 102 GNUNET_TRANSPORT_TESTING_stop_peer (ccc->p[i]);
100 { 103 ccc->p[i] = NULL;
101 GNUNET_TRANSPORT_TESTING_stop_peer(ccc->p[i]);
102 ccc->p[i] = NULL;
103 }
104 } 104 }
105 }
105} 106}
106 107
107 108
@@ -111,15 +112,15 @@ do_shutdown(void *cls)
111 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` 112 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *`
112 */ 113 */
113static void 114static void
114do_timeout(void *cls) 115do_timeout (void *cls)
115{ 116{
116 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; 117 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
117 118
118 ccc->timeout_task = NULL; 119 ccc->timeout_task = NULL;
119 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 120 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
120 "Testcase timed out\n"); 121 "Testcase timed out\n");
121 ccc->global_ret = GNUNET_SYSERR; 122 ccc->global_ret = GNUNET_SYSERR;
122 GNUNET_SCHEDULER_shutdown(); 123 GNUNET_SCHEDULER_shutdown ();
123} 124}
124 125
125 126
@@ -128,7 +129,8 @@ do_timeout(void *cls)
128 * #connect_cb, #disconnect_cb, #my_nc and #start_cb. 129 * #connect_cb, #disconnect_cb, #my_nc and #start_cb.
129 * Allows us to identify which peer this is about. 130 * Allows us to identify which peer this is about.
130 */ 131 */
131struct GNUNET_TRANSPORT_TESTING_InternalPeerContext { 132struct GNUNET_TRANSPORT_TESTING_InternalPeerContext
133{
132 /** 134 /**
133 * Overall context of the callback. 135 * Overall context of the callback.
134 */ 136 */
@@ -144,7 +146,8 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext {
144/** 146/**
145 * Information tracked per connected peer. 147 * Information tracked per connected peer.
146 */ 148 */
147struct ConnectPairInfo { 149struct ConnectPairInfo
150{
148 /** 151 /**
149 * Peer this is about. 152 * Peer this is about.
150 */ 153 */
@@ -164,33 +167,33 @@ struct ConnectPairInfo {
164 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *` 167 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *`
165 */ 168 */
166static void 169static void
167connect_cb(void *cls) 170connect_cb (void *cls)
168{ 171{
169 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl = cls; 172 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl = cls;
170 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = crl->ccc; 173 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = crl->ccc;
171 174
172 GNUNET_CONTAINER_DLL_remove(ccc->crl_head, 175 GNUNET_CONTAINER_DLL_remove (ccc->crl_head,
173 ccc->crl_tail, 176 ccc->crl_tail,
174 crl); 177 crl);
175 { 178 {
176 char *p1_c = GNUNET_strdup(GNUNET_i2s(&crl->p1->id)); 179 char *p1_c = GNUNET_strdup (GNUNET_i2s (&crl->p1->id));
177 180
178 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 181 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
179 "Peers connected: %u (%s) <-> %u (%s)\n", 182 "Peers connected: %u (%s) <-> %u (%s)\n",
180 crl->p1->no, 183 crl->p1->no,
181 p1_c, 184 p1_c,
182 crl->p2->no, 185 crl->p2->no,
183 GNUNET_i2s(&crl->p2->id)); 186 GNUNET_i2s (&crl->p2->id));
184 GNUNET_free(p1_c); 187 GNUNET_free (p1_c);
185 GNUNET_free(crl); 188 GNUNET_free (crl);
186 } 189 }
187 if (NULL == ccc->crl_head) 190 if (NULL == ccc->crl_head)
188 { 191 {
189 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
190 "All connections UP, launching custom test logic.\n"); 193 "All connections UP, launching custom test logic.\n");
191 GNUNET_SCHEDULER_add_now(ccc->connect_continuation, 194 GNUNET_SCHEDULER_add_now (ccc->connect_continuation,
192 ccc->connect_continuation_cls); 195 ccc->connect_continuation_cls);
193 } 196 }
194} 197}
195 198
196 199
@@ -202,14 +205,16 @@ connect_cb(void *cls)
202 * @return NULL if @a peer was not found 205 * @return NULL if @a peer was not found
203 */ 206 */
204struct GNUNET_TRANSPORT_TESTING_PeerContext * 207struct GNUNET_TRANSPORT_TESTING_PeerContext *
205GNUNET_TRANSPORT_TESTING_find_peer(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, 208GNUNET_TRANSPORT_TESTING_find_peer (struct
206 const struct GNUNET_PeerIdentity *peer) 209 GNUNET_TRANSPORT_TESTING_ConnectCheckContext
210 *ccc,
211 const struct GNUNET_PeerIdentity *peer)
207{ 212{
208 for (unsigned int i = 0; i < ccc->num_peers; i++) 213 for (unsigned int i = 0; i < ccc->num_peers; i++)
209 if ((NULL != ccc->p[i]) && 214 if ((NULL != ccc->p[i]) &&
210 (0 == memcmp(peer, 215 (0 == memcmp (peer,
211 &ccc->p[i]->id, 216 &ccc->p[i]->id,
212 sizeof(*peer)))) 217 sizeof(*peer))))
213 return ccc->p[i]; 218 return ccc->p[i];
214 return NULL; 219 return NULL;
215} 220}
@@ -224,19 +229,19 @@ GNUNET_TRANSPORT_TESTING_find_peer(struct GNUNET_TRANSPORT_TESTING_ConnectCheckC
224 * @return closure for message handlers 229 * @return closure for message handlers
225 */ 230 */
226static void * 231static void *
227my_nc(void *cls, 232my_nc (void *cls,
228 const struct GNUNET_PeerIdentity *peer, 233 const struct GNUNET_PeerIdentity *peer,
229 struct GNUNET_MQ_Handle *mq) 234 struct GNUNET_MQ_Handle *mq)
230{ 235{
231 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; 236 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
232 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; 237 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
233 struct ConnectPairInfo *cpi; 238 struct ConnectPairInfo *cpi;
234 239
235 if (NULL != ccc->nc) 240 if (NULL != ccc->nc)
236 ccc->nc(ccc->cls, 241 ccc->nc (ccc->cls,
237 ccc->p[ipi->off], 242 ccc->p[ipi->off],
238 peer); 243 peer);
239 cpi = GNUNET_new(struct ConnectPairInfo); 244 cpi = GNUNET_new (struct ConnectPairInfo);
240 cpi->ipi = ipi; 245 cpi->ipi = ipi;
241 cpi->sender = peer; /* valid until disconnect */ 246 cpi->sender = peer; /* valid until disconnect */
242 return cpi; 247 return cpi;
@@ -251,19 +256,19 @@ my_nc(void *cls,
251 * @param custom_cls return value from @my_nc 256 * @param custom_cls return value from @my_nc
252 */ 257 */
253static void 258static void
254my_nd(void *cls, 259my_nd (void *cls,
255 const struct GNUNET_PeerIdentity *peer, 260 const struct GNUNET_PeerIdentity *peer,
256 void *custom_cls) 261 void *custom_cls)
257{ 262{
258 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; 263 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
259 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; 264 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
260 struct ConnectPairInfo *cpi = custom_cls; 265 struct ConnectPairInfo *cpi = custom_cls;
261 266
262 if (NULL != ccc->nd) 267 if (NULL != ccc->nd)
263 ccc->nd(ccc->cls, 268 ccc->nd (ccc->cls,
264 ccc->p[ipi->off], 269 ccc->p[ipi->off],
265 peer); 270 peer);
266 GNUNET_free(cpi); 271 GNUNET_free (cpi);
267} 272}
268 273
269 274
@@ -275,8 +280,8 @@ my_nd(void *cls,
275 * @return #GNUNET_OK (all messages are fine) 280 * @return #GNUNET_OK (all messages are fine)
276 */ 281 */
277static int 282static int
278check_test(void *cls, 283check_test (void *cls,
279 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 284 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
280{ 285{
281 return GNUNET_OK; 286 return GNUNET_OK;
282} 287}
@@ -289,18 +294,18 @@ check_test(void *cls,
289 * @param message message we received 294 * @param message message we received
290 */ 295 */
291static void 296static void
292handle_test(void *cls, 297handle_test (void *cls,
293 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 298 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
294{ 299{
295 struct ConnectPairInfo *cpi = cls; 300 struct ConnectPairInfo *cpi = cls;
296 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; 301 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi;
297 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; 302 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
298 303
299 if (NULL != ccc->rec) 304 if (NULL != ccc->rec)
300 ccc->rec(ccc->cls, 305 ccc->rec (ccc->cls,
301 ccc->p[ipi->off], 306 ccc->p[ipi->off],
302 cpi->sender, 307 cpi->sender,
303 message); 308 message);
304} 309}
305 310
306 311
@@ -312,8 +317,8 @@ handle_test(void *cls,
312 * @return #GNUNET_OK (all messages are fine) 317 * @return #GNUNET_OK (all messages are fine)
313 */ 318 */
314static int 319static int
315check_test2(void *cls, 320check_test2 (void *cls,
316 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 321 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
317{ 322{
318 return GNUNET_OK; 323 return GNUNET_OK;
319} 324}
@@ -326,18 +331,18 @@ check_test2(void *cls,
326 * @param message message we received 331 * @param message message we received
327 */ 332 */
328static void 333static void
329handle_test2(void *cls, 334handle_test2 (void *cls,
330 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 335 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
331{ 336{
332 struct ConnectPairInfo *cpi = cls; 337 struct ConnectPairInfo *cpi = cls;
333 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; 338 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi;
334 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; 339 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
335 340
336 if (NULL != ccc->rec) 341 if (NULL != ccc->rec)
337 ccc->rec(ccc->cls, 342 ccc->rec (ccc->cls,
338 ccc->p[ipi->off], 343 ccc->p[ipi->off],
339 cpi->sender, 344 cpi->sender,
340 message); 345 message);
341} 346}
342 347
343 348
@@ -347,41 +352,42 @@ handle_test2(void *cls,
347 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` 352 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
348 */ 353 */
349static void 354static void
350do_connect(void *cls) 355do_connect (void *cls)
351{ 356{
352 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; 357 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
353 358
354 ccc->connect_task = NULL; 359 ccc->connect_task = NULL;
355 for (unsigned int i = 0; i < ccc->num_peers; i++) 360 for (unsigned int i = 0; i < ccc->num_peers; i++)
356 for (unsigned int j = (ccc->bi_directional ? 0 : i + 1); j < ccc->num_peers; j++) 361 for (unsigned int j = (ccc->bi_directional ? 0 : i + 1); j < ccc->num_peers;
362 j++)
363 {
364 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl;
365
366 if (i == j)
367 continue;
368 crl = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequestList);
369 GNUNET_CONTAINER_DLL_insert (ccc->crl_head,
370 ccc->crl_tail,
371 crl);
372 crl->ccc = ccc;
373 crl->p1 = ccc->p[i];
374 crl->p2 = ccc->p[j];
357 { 375 {
358 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; 376 char *sender_c = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
359 377
360 if (i == j) 378 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
361 continue; 379 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
362 crl = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequestList); 380 ccc->p[0]->no,
363 GNUNET_CONTAINER_DLL_insert(ccc->crl_head, 381 sender_c,
364 ccc->crl_tail, 382 ccc->p[1]->no,
365 crl); 383 GNUNET_i2s (&ccc->p[1]->id));
366 crl->ccc = ccc; 384 GNUNET_free (sender_c);
367 crl->p1 = ccc->p[i];
368 crl->p2 = ccc->p[j];
369 {
370 char *sender_c = GNUNET_strdup(GNUNET_i2s(&ccc->p[0]->id));
371
372 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
373 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
374 ccc->p[0]->no,
375 sender_c,
376 ccc->p[1]->no,
377 GNUNET_i2s(&ccc->p[1]->id));
378 GNUNET_free(sender_c);
379 }
380 crl->cr = GNUNET_TRANSPORT_TESTING_connect_peers(ccc->p[i],
381 ccc->p[j],
382 &connect_cb,
383 crl);
384 } 385 }
386 crl->cr = GNUNET_TRANSPORT_TESTING_connect_peers (ccc->p[i],
387 ccc->p[j],
388 &connect_cb,
389 crl);
390 }
385} 391}
386 392
387 393
@@ -393,32 +399,32 @@ do_connect(void *cls)
393 * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` 399 * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
394 */ 400 */
395static void 401static void
396start_cb(void *cls) 402start_cb (void *cls)
397{ 403{
398 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; 404 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
399 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; 405 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
400 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off]; 406 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off];
401 407
402 ccc->started++; 408 ccc->started++;
403 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 409 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
404 "Peer %u (`%s') started\n", 410 "Peer %u (`%s') started\n",
405 p->no, 411 p->no,
406 GNUNET_i2s(&p->id)); 412 GNUNET_i2s (&p->id));
407 if (ccc->started != ccc->num_peers) 413 if (ccc->started != ccc->num_peers)
408 return; 414 return;
409 if (NULL != ccc->pre_connect_task) 415 if (NULL != ccc->pre_connect_task)
410 { 416 {
411 /* Run the custom per-connect job, then give it a second to 417 /* Run the custom per-connect job, then give it a second to
412 go into effect before we continue connecting peers. */ 418 go into effect before we continue connecting peers. */
413 ccc->pre_connect_task(ccc->pre_connect_task_cls); 419 ccc->pre_connect_task (ccc->pre_connect_task_cls);
414 ccc->connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 420 ccc->connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
415 &do_connect, 421 &do_connect,
416 ccc); 422 ccc);
417 } 423 }
418 else 424 else
419 { 425 {
420 do_connect(ccc); 426 do_connect (ccc);
421 } 427 }
422} 428}
423 429
424 430
@@ -433,52 +439,52 @@ start_cb(void *cls)
433 * @param cfg configuration 439 * @param cfg configuration
434 */ 440 */
435static void 441static void
436connect_check_run(void *cls, 442connect_check_run (void *cls,
437 char *const *args, 443 char *const *args,
438 const char *cfgfile, 444 const char *cfgfile,
439 const struct GNUNET_CONFIGURATION_Handle *cfg) 445 const struct GNUNET_CONFIGURATION_Handle *cfg)
440{ 446{
441 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; 447 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
442 int ok; 448 int ok;
443 449
444 ccc->cfg = cfg; 450 ccc->cfg = cfg;
445 ccc->timeout_task = GNUNET_SCHEDULER_add_delayed(ccc->timeout, 451 ccc->timeout_task = GNUNET_SCHEDULER_add_delayed (ccc->timeout,
446 &do_timeout, 452 &do_timeout,
447 ccc); 453 ccc);
448 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 454 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
449 ccc); 455 ccc);
450 ok = GNUNET_OK; 456 ok = GNUNET_OK;
451 for (unsigned int i = 0; i < ccc->num_peers; i++) 457 for (unsigned int i = 0; i < ccc->num_peers; i++)
452 { 458 {
453 struct GNUNET_MQ_MessageHandler handlers[] = { 459 struct GNUNET_MQ_MessageHandler handlers[] = {
454 GNUNET_MQ_hd_var_size(test, 460 GNUNET_MQ_hd_var_size (test,
455 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 461 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
456 struct GNUNET_TRANSPORT_TESTING_TestMessage, 462 struct GNUNET_TRANSPORT_TESTING_TestMessage,
457 NULL), 463 NULL),
458 GNUNET_MQ_hd_var_size(test2, 464 GNUNET_MQ_hd_var_size (test2,
459 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, 465 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
460 struct GNUNET_TRANSPORT_TESTING_TestMessage, 466 struct GNUNET_TRANSPORT_TESTING_TestMessage,
461 NULL), 467 NULL),
462 GNUNET_MQ_handler_end() 468 GNUNET_MQ_handler_end ()
463 }; 469 };
464 ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer(ccc->tth, 470 ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer (ccc->tth,
465 ccc->cfg_files[i], 471 ccc->cfg_files[i],
466 i + 1, 472 i + 1,
467 handlers, 473 handlers,
468 &my_nc, 474 &my_nc,
469 &my_nd, 475 &my_nd,
470 &ccc->ip[i], 476 &ccc->ip[i],
471 &start_cb, 477 &start_cb,
472 &ccc->ip[i]); 478 &ccc->ip[i]);
473 if (NULL == ccc->p[i]) 479 if (NULL == ccc->p[i])
474 ok = GNUNET_SYSERR; 480 ok = GNUNET_SYSERR;
475 } 481 }
476 if (GNUNET_OK != ok) 482 if (GNUNET_OK != ok)
477 { 483 {
478 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 484 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
479 "Fail! Could not start peers!\n"); 485 "Fail! Could not start peers!\n");
480 GNUNET_SCHEDULER_shutdown(); 486 GNUNET_SCHEDULER_shutdown ();
481 } 487 }
482} 488}
483 489
484 490
@@ -498,12 +504,13 @@ connect_check_run(void *cls,
498 * @return #GNUNET_SYSERR on error 504 * @return #GNUNET_SYSERR on error
499 */ 505 */
500int 506int
501GNUNET_TRANSPORT_TESTING_connect_check(void *cls, 507GNUNET_TRANSPORT_TESTING_connect_check (void *cls,
502 struct GNUNET_TRANSPORT_TESTING_Handle *tth_, 508 struct GNUNET_TRANSPORT_TESTING_Handle *
503 const char *test_plugin_, 509 tth_,
504 const char *test_name_, 510 const char *test_plugin_,
505 unsigned int num_peers, 511 const char *test_name_,
506 char *cfg_files[]) 512 unsigned int num_peers,
513 char *cfg_files[])
507{ 514{
508 static struct GNUNET_GETOPT_CommandLineOption options[] = { 515 static struct GNUNET_GETOPT_CommandLineOption options[] = {
509 GNUNET_GETOPT_OPTION_END 516 GNUNET_GETOPT_OPTION_END
@@ -511,10 +518,10 @@ GNUNET_TRANSPORT_TESTING_connect_check(void *cls,
511 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; 518 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
512 struct GNUNET_TRANSPORT_TESTING_PeerContext *p[num_peers]; 519 struct GNUNET_TRANSPORT_TESTING_PeerContext *p[num_peers];
513 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext ip[num_peers]; 520 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext ip[num_peers];
514 char * argv[] = { 521 char *argv[] = {
515 (char *)test_name_, 522 (char *) test_name_,
516 "-c", 523 "-c",
517 (char *)ccc->config_file, 524 (char *) ccc->config_file,
518 NULL 525 NULL
519 }; 526 };
520 527
@@ -527,18 +534,18 @@ GNUNET_TRANSPORT_TESTING_connect_check(void *cls,
527 ccc->p = p; 534 ccc->p = p;
528 ccc->ip = ip; 535 ccc->ip = ip;
529 for (unsigned int i = 0; i < num_peers; i++) 536 for (unsigned int i = 0; i < num_peers; i++)
530 { 537 {
531 ip[i].off = i; 538 ip[i].off = i;
532 ip[i].ccc = ccc; 539 ip[i].ccc = ccc;
533 } 540 }
534 if (GNUNET_OK != 541 if (GNUNET_OK !=
535 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, 542 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1,
536 argv, 543 argv,
537 test_name_, 544 test_name_,
538 "nohelp", 545 "nohelp",
539 options, 546 options,
540 &connect_check_run, 547 &connect_check_run,
541 ccc)) 548 ccc))
542 return GNUNET_SYSERR; 549 return GNUNET_SYSERR;
543 return ccc->global_ret; 550 return ccc->global_ret;
544} 551}
@@ -555,11 +562,11 @@ GNUNET_TRANSPORT_TESTING_connect_check(void *cls,
555 * @return #GNUNET_OK on success 562 * @return #GNUNET_OK on success
556 */ 563 */
557int 564int
558GNUNET_TRANSPORT_TESTING_main_(const char *argv0, 565GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
559 const char *filename, 566 const char *filename,
560 unsigned int num_peers, 567 unsigned int num_peers,
561 GNUNET_TRANSPORT_TESTING_CheckCallback check, 568 GNUNET_TRANSPORT_TESTING_CheckCallback check,
562 void *check_cls) 569 void *check_cls)
563{ 570{
564 struct GNUNET_TRANSPORT_TESTING_Handle *tth; 571 struct GNUNET_TRANSPORT_TESTING_Handle *tth;
565 char *test_name; 572 char *test_name;
@@ -569,36 +576,36 @@ GNUNET_TRANSPORT_TESTING_main_(const char *argv0,
569 int ret; 576 int ret;
570 577
571 ret = GNUNET_OK; 578 ret = GNUNET_OK;
572 test_name = GNUNET_TRANSPORT_TESTING_get_test_name(argv0); 579 test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0);
573 GNUNET_log_setup(test_name, 580 GNUNET_log_setup (test_name,
574 "WARNING", 581 "WARNING",
575 NULL); 582 NULL);
576 test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name(filename); 583 test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (filename);
577 test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name(argv0, 584 test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv0,
578 test_source); 585 test_source);
579 for (unsigned int i = 0; i < num_peers; i++) 586 for (unsigned int i = 0; i < num_peers; i++)
580 cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name(argv0, 587 cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name (argv0,
581 i + 1); 588 i + 1);
582 tth = GNUNET_TRANSPORT_TESTING_init(); 589 tth = GNUNET_TRANSPORT_TESTING_init ();
583 if (NULL == tth) 590 if (NULL == tth)
584 { 591 {
585 ret = GNUNET_SYSERR; 592 ret = GNUNET_SYSERR;
586 } 593 }
587 else 594 else
588 { 595 {
589 ret = check(check_cls, 596 ret = check (check_cls,
590 tth, 597 tth,
591 test_plugin, 598 test_plugin,
592 test_name, 599 test_name,
593 num_peers, 600 num_peers,
594 cfg_names); 601 cfg_names);
595 GNUNET_TRANSPORT_TESTING_done(tth); 602 GNUNET_TRANSPORT_TESTING_done (tth);
596 } 603 }
597 for (unsigned int i = 0; i < num_peers; i++) 604 for (unsigned int i = 0; i < num_peers; i++)
598 GNUNET_free(cfg_names[i]); 605 GNUNET_free (cfg_names[i]);
599 GNUNET_free(test_source); 606 GNUNET_free (test_source);
600 GNUNET_free_non_null(test_plugin); 607 GNUNET_free_non_null (test_plugin);
601 GNUNET_free(test_name); 608 GNUNET_free (test_name);
602 return ret; 609 return ret;
603} 610}
604 611
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 @@
27/** 27/**
28 * Acceptable transmission delay. 28 * Acceptable transmission delay.
29 */ 29 */
30#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 30#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply ( \
31 GNUNET_TIME_UNIT_SECONDS, 30)
31 32
32 33
33/** 34/**
34 * Return @a cx in @a cls. 35 * Return @a cx in @a cls.
35 */ 36 */
36static void 37static void
37find_cr(void *cls, 38find_cr (void *cls,
38 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 39 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
39{ 40{
40 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls; 41 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls;
41 42
@@ -62,66 +63,68 @@ find_cr(void *cls,
62 * #GNUNET_SYSERR if @a msize is illegal 63 * #GNUNET_SYSERR if @a msize is illegal
63 */ 64 */
64int 65int
65GNUNET_TRANSPORT_TESTING_send(struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, 66GNUNET_TRANSPORT_TESTING_send (struct
66 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 67 GNUNET_TRANSPORT_TESTING_PeerContext *sender,
67 uint16_t mtype, 68 struct GNUNET_TRANSPORT_TESTING_PeerContext *
68 uint16_t msize, 69 receiver,
69 uint32_t num, 70 uint16_t mtype,
70 GNUNET_SCHEDULER_TaskCallback cont, 71 uint16_t msize,
71 void *cont_cls) 72 uint32_t num,
73 GNUNET_SCHEDULER_TaskCallback cont,
74 void *cont_cls)
72{ 75{
73 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr; 76 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr;
74 struct GNUNET_MQ_Envelope *env; 77 struct GNUNET_MQ_Envelope *env;
75 struct GNUNET_TRANSPORT_TESTING_TestMessage *test; 78 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
76 79
77 if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage)) 80 if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))
78 { 81 {
79 GNUNET_break(0); 82 GNUNET_break (0);
80 return GNUNET_SYSERR; 83 return GNUNET_SYSERR;
81 } 84 }
82 cr = NULL; 85 cr = NULL;
83 GNUNET_TRANSPORT_TESTING_find_connecting_context(sender, 86 GNUNET_TRANSPORT_TESTING_find_connecting_context (sender,
84 receiver, 87 receiver,
85 &find_cr, 88 &find_cr,
86 &cr); 89 &cr);
87 if (NULL == cr) 90 if (NULL == cr)
88 GNUNET_TRANSPORT_TESTING_find_connecting_context(receiver, 91 GNUNET_TRANSPORT_TESTING_find_connecting_context (receiver,
89 sender, 92 sender,
90 &find_cr, 93 &find_cr,
91 &cr); 94 &cr);
92 if (NULL == cr) 95 if (NULL == cr)
93 { 96 {
94 GNUNET_break(0); 97 GNUNET_break (0);
95 return GNUNET_NO; 98 return GNUNET_NO;
96 } 99 }
97 if (NULL == cr->mq) 100 if (NULL == cr->mq)
98 {
99 GNUNET_break(0);
100 return GNUNET_NO;
101 }
102 { 101 {
103 char *receiver_s = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 102 GNUNET_break (0);
104 103 return GNUNET_NO;
105 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
106 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
107 sender->no,
108 GNUNET_i2s(&sender->id),
109 receiver->no,
110 receiver_s);
111 GNUNET_free(receiver_s);
112 } 104 }
113 env = GNUNET_MQ_msg_extra(test, 105 {
114 msize - sizeof(*test), 106 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
115 mtype); 107
116 test->num = htonl(num); 108 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
117 memset(&test[1], 109 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
118 num, 110 sender->no,
119 msize - sizeof(*test)); 111 GNUNET_i2s (&sender->id),
120 GNUNET_MQ_notify_sent(env, 112 receiver->no,
121 cont, 113 receiver_s);
122 cont_cls); 114 GNUNET_free (receiver_s);
123 GNUNET_MQ_send(cr->mq, 115 }
124 env); 116 env = GNUNET_MQ_msg_extra (test,
117 msize - sizeof(*test),
118 mtype);
119 test->num = htonl (num);
120 memset (&test[1],
121 num,
122 msize - sizeof(*test));
123 GNUNET_MQ_notify_sent (env,
124 cont,
125 cont_cls);
126 GNUNET_MQ_send (cr->mq,
127 env);
125 return GNUNET_OK; 128 return GNUNET_OK;
126} 129}
127 130
@@ -137,28 +140,28 @@ GNUNET_TRANSPORT_TESTING_send(struct GNUNET_TRANSPORT_TESTING_PeerContext *sende
137 * @param cont_cls closure for @a cont 140 * @param cont_cls closure for @a cont
138 */ 141 */
139static void 142static void
140do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, 143do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
141 uint16_t size, 144 uint16_t size,
142 GNUNET_SCHEDULER_TaskCallback cont, 145 GNUNET_SCHEDULER_TaskCallback cont,
143 void *cont_cls) 146 void *cont_cls)
144{ 147{
145 int ret; 148 int ret;
146 149
147 ccc->global_ret = GNUNET_SYSERR; 150 ccc->global_ret = GNUNET_SYSERR;
148 ret = GNUNET_TRANSPORT_TESTING_send(ccc->p[0], 151 ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[0],
149 ccc->p[1], 152 ccc->p[1],
150 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 153 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
151 size, 154 size,
152 ccc->send_num_gen++, 155 ccc->send_num_gen++,
153 cont, 156 cont,
154 cont_cls); 157 cont_cls);
155 GNUNET_assert(GNUNET_SYSERR != ret); 158 GNUNET_assert (GNUNET_SYSERR != ret);
156 if (GNUNET_NO == ret) 159 if (GNUNET_NO == ret)
157 { 160 {
158 GNUNET_break(0); 161 GNUNET_break (0);
159 ccc->global_ret = GNUNET_SYSERR; 162 ccc->global_ret = GNUNET_SYSERR;
160 GNUNET_SCHEDULER_shutdown(); 163 GNUNET_SCHEDULER_shutdown ();
161 } 164 }
162} 165}
163 166
164 167
@@ -171,30 +174,30 @@ do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
171 * of which should be currently connected 174 * of which should be currently connected
172 */ 175 */
173void 176void
174GNUNET_TRANSPORT_TESTING_simple_send(void *cls) 177GNUNET_TRANSPORT_TESTING_simple_send (void *cls)
175{ 178{
176 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 179 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
177 int done; 180 int done;
178 size_t msize; 181 size_t msize;
179 182
180 if (0 < sc->num_messages) 183 if (0 < sc->num_messages)
181 { 184 {
182 sc->num_messages--; 185 sc->num_messages--;
183 done = (0 == sc->num_messages); 186 done = (0 == sc->num_messages);
184 } 187 }
185 else 188 else
186 { 189 {
187 done = 0; /* infinite loop */ 190 done = 0; /* infinite loop */
188 } 191 }
189 msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage); 192 msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage);
190 if (NULL != sc->get_size_cb) 193 if (NULL != sc->get_size_cb)
191 msize = sc->get_size_cb(sc->num_messages); 194 msize = sc->get_size_cb (sc->num_messages);
192 /* if this was the last message, call the continuation, 195 /* if this was the last message, call the continuation,
193 otherwise call this function again */ 196 otherwise call this function again */
194 do_send(sc->ccc, 197 do_send (sc->ccc,
195 msize, 198 msize,
196 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send, 199 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send,
197 done ? sc->cont_cls : sc); 200 done ? sc->cont_cls : sc);
198} 201}
199 202
200 203
@@ -207,30 +210,30 @@ GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
207 * of which should be currently connected 210 * of which should be currently connected
208 */ 211 */
209void 212void
210GNUNET_TRANSPORT_TESTING_large_send(void *cls) 213GNUNET_TRANSPORT_TESTING_large_send (void *cls)
211{ 214{
212 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 215 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
213 int done; 216 int done;
214 size_t msize; 217 size_t msize;
215 218
216 if (0 < sc->num_messages) 219 if (0 < sc->num_messages)
217 { 220 {
218 sc->num_messages--; 221 sc->num_messages--;
219 done = (0 == sc->num_messages); 222 done = (0 == sc->num_messages);
220 } 223 }
221 else 224 else
222 { 225 {
223 done = 0; /* infinite loop */ 226 done = 0; /* infinite loop */
224 } 227 }
225 msize = 2600; 228 msize = 2600;
226 if (NULL != sc->get_size_cb) 229 if (NULL != sc->get_size_cb)
227 msize = sc->get_size_cb(sc->num_messages); 230 msize = sc->get_size_cb (sc->num_messages);
228 /* if this was the last message, call the continuation, 231 /* if this was the last message, call the continuation,
229 otherwise call this function again */ 232 otherwise call this function again */
230 do_send(sc->ccc, 233 do_send (sc->ccc,
231 msize, 234 msize,
232 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send, 235 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send,
233 done ? sc->cont_cls : sc); 236 done ? sc->cont_cls : sc);
234} 237}
235 238
236/* end of transport-testing-send.c */ 239/* 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 @@
26#include "transport-testing.h" 26#include "transport-testing.h"
27 27
28 28
29#define LOG(kind, ...) GNUNET_log_from(kind, "transport-testing", __VA_ARGS__) 29#define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing", __VA_ARGS__)
30 30
31 31
32static struct GNUNET_TRANSPORT_TESTING_PeerContext * 32static struct GNUNET_TRANSPORT_TESTING_PeerContext *
33find_peer_context(struct GNUNET_TRANSPORT_TESTING_Handle *tth, 33find_peer_context (struct GNUNET_TRANSPORT_TESTING_Handle *tth,
34 const struct GNUNET_PeerIdentity *peer) 34 const struct GNUNET_PeerIdentity *peer)
35{ 35{
36 struct GNUNET_TRANSPORT_TESTING_PeerContext *t; 36 struct GNUNET_TRANSPORT_TESTING_PeerContext *t;
37 37
38 for (t = tth->p_head; NULL != t; t = t->next) 38 for (t = tth->p_head; NULL != t; t = t->next)
39 if (0 == memcmp(&t->id, 39 if (0 == memcmp (&t->id,
40 peer, 40 peer,
41 sizeof(struct GNUNET_PeerIdentity))) 41 sizeof(struct GNUNET_PeerIdentity)))
42 return t; 42 return t;
43 return NULL; 43 return NULL;
44} 44}
@@ -53,29 +53,34 @@ find_peer_context(struct GNUNET_TRANSPORT_TESTING_Handle *tth,
53 * @param cb_cls closure for @a cb 53 * @param cb_cls closure for @a cb
54 */ 54 */
55void 55void
56GNUNET_TRANSPORT_TESTING_find_connecting_context(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 56GNUNET_TRANSPORT_TESTING_find_connecting_context (struct
57 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 57 GNUNET_TRANSPORT_TESTING_PeerContext
58 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, 58 *p1,
59 void *cb_cls) 59 struct
60 GNUNET_TRANSPORT_TESTING_PeerContext
61 *p2,
62 GNUNET_TRANSPORT_TESTING_ConnectContextCallback
63 cb,
64 void *cb_cls)
60{ 65{
61 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; 66 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
62 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 67 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
63 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; 68 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
64 69
65 for (cc = tth->cc_head; NULL != cc; cc = ccn) 70 for (cc = tth->cc_head; NULL != cc; cc = ccn)
66 { 71 {
67 ccn = cc->next; 72 ccn = cc->next;
68 if ((cc->p1 == p1) && 73 if ((cc->p1 == p1) &&
69 (cc->p2 == p2)) 74 (cc->p2 == p2))
70 cb(cb_cls, 75 cb (cb_cls,
71 cc); 76 cc);
72 } 77 }
73} 78}
74 79
75 80
76static void 81static void
77set_p1c(void *cls, 82set_p1c (void *cls,
78 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 83 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
79{ 84{
80 int *found = cls; 85 int *found = cls;
81 86
@@ -86,8 +91,8 @@ set_p1c(void *cls,
86 91
87 92
88static void 93static void
89set_mq(void *cls, 94set_mq (void *cls,
90 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 95 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
91{ 96{
92 struct GNUNET_MQ_Handle *mq = cls; 97 struct GNUNET_MQ_Handle *mq = cls;
93 98
@@ -96,8 +101,8 @@ set_mq(void *cls,
96 101
97 102
98static void 103static void
99set_p2c(void *cls, 104set_p2c (void *cls,
100 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 105 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
101{ 106{
102 int *found = cls; 107 int *found = cls;
103 108
@@ -108,8 +113,8 @@ set_p2c(void *cls,
108 113
109 114
110static void 115static void
111clear_p1c(void *cls, 116clear_p1c (void *cls,
112 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 117 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
113{ 118{
114 int *found = cls; 119 int *found = cls;
115 120
@@ -120,8 +125,8 @@ clear_p1c(void *cls,
120 125
121 126
122static void 127static void
123clear_p2c(void *cls, 128clear_p2c (void *cls,
124 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 129 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
125{ 130{
126 int *found = cls; 131 int *found = cls;
127 132
@@ -132,9 +137,9 @@ clear_p2c(void *cls,
132 137
133 138
134static void * 139static void *
135notify_connect(void *cls, 140notify_connect (void *cls,
136 const struct GNUNET_PeerIdentity *peer, 141 const struct GNUNET_PeerIdentity *peer,
137 struct GNUNET_MQ_Handle *mq) 142 struct GNUNET_MQ_Handle *mq)
138{ 143{
139 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 144 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
140 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 145 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
@@ -145,103 +150,103 @@ notify_connect(void *cls,
145 int found; 150 int found;
146 void *ret; 151 void *ret;
147 152
148 p2 = find_peer_context(p->tth, 153 p2 = find_peer_context (p->tth,
149 peer); 154 peer);
150 if (NULL != p->nc) 155 if (NULL != p->nc)
151 ret = p->nc(p->cb_cls, 156 ret = p->nc (p->cb_cls,
152 peer, 157 peer,
153 mq); 158 mq);
154 else 159 else
155 ret = NULL; 160 ret = NULL;
156 161
157 if (NULL != p2) 162 if (NULL != p2)
158 GNUNET_asprintf(&p2_s, 163 GNUNET_asprintf (&p2_s,
159 "%u (`%s')", 164 "%u (`%s')",
160 p2->no, 165 p2->no,
161 GNUNET_i2s(&p2->id)); 166 GNUNET_i2s (&p2->id));
162 else 167 else
163 GNUNET_asprintf(&p2_s, 168 GNUNET_asprintf (&p2_s,
164 "`%s'", 169 "`%s'",
165 GNUNET_i2s(peer)); 170 GNUNET_i2s (peer));
166 LOG(GNUNET_ERROR_TYPE_DEBUG, 171 LOG (GNUNET_ERROR_TYPE_DEBUG,
167 "Peers %s connected to peer %u (`%s')\n", 172 "Peers %s connected to peer %u (`%s')\n",
168 p2_s, 173 p2_s,
169 p->no, 174 p->no,
170 GNUNET_i2s(&p->id)); 175 GNUNET_i2s (&p->id));
171 GNUNET_free(p2_s); 176 GNUNET_free (p2_s);
172 /* update flags in connecting contexts */ 177 /* update flags in connecting contexts */
173 found = GNUNET_NO; 178 found = GNUNET_NO;
174 GNUNET_TRANSPORT_TESTING_find_connecting_context(p, 179 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
175 p2, 180 p2,
176 &set_p1c, 181 &set_p1c,
177 &found); 182 &found);
178 if (GNUNET_NO == found) 183 if (GNUNET_NO == found)
179 { 184 {
180 cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest); 185 cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
181 cc->p1 = p; 186 cc->p1 = p;
182 cc->p2 = p2; 187 cc->p2 = p2;
183 cc->p1_c = GNUNET_YES; 188 cc->p1_c = GNUNET_YES;
184 GNUNET_CONTAINER_DLL_insert(tth->cc_head, 189 GNUNET_CONTAINER_DLL_insert (tth->cc_head,
185 tth->cc_tail, 190 tth->cc_tail,
186 cc); 191 cc);
187 } 192 }
188 found = GNUNET_NO; 193 found = GNUNET_NO;
189 GNUNET_TRANSPORT_TESTING_find_connecting_context(p2, 194 GNUNET_TRANSPORT_TESTING_find_connecting_context (p2,
190 p, 195 p,
191 &set_p2c, 196 &set_p2c,
192 &found); 197 &found);
193 if (GNUNET_NO == found) 198 if (GNUNET_NO == found)
194 { 199 {
195 cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest); 200 cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
196 cc->p1 = p2; 201 cc->p1 = p2;
197 cc->p2 = p; 202 cc->p2 = p;
198 cc->p1_c = GNUNET_YES; 203 cc->p1_c = GNUNET_YES;
199 GNUNET_CONTAINER_DLL_insert(tth->cc_head, 204 GNUNET_CONTAINER_DLL_insert (tth->cc_head,
200 tth->cc_tail, 205 tth->cc_tail,
201 cc); 206 cc);
202 } 207 }
203 GNUNET_TRANSPORT_TESTING_find_connecting_context(p, 208 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
204 p2, 209 p2,
205 &set_mq, 210 &set_mq,
206 mq); 211 mq);
207 /* update set connected flag for all requests */ 212 /* update set connected flag for all requests */
208 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 213 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
209 { 214 {
210 if (GNUNET_YES == cc->connected) 215 if (GNUNET_YES == cc->connected)
211 continue; 216 continue;
212 if ((GNUNET_YES == cc->p1_c) && 217 if ((GNUNET_YES == cc->p1_c) &&
213 (GNUNET_YES == cc->p2_c)) 218 (GNUNET_YES == cc->p2_c))
214 { 219 {
215 cc->connected = GNUNET_YES; 220 cc->connected = GNUNET_YES;
216 /* stop trying to connect */ 221 /* stop trying to connect */
217 if (NULL != cc->tct) 222 if (NULL != cc->tct)
218 { 223 {
219 GNUNET_SCHEDULER_cancel(cc->tct); 224 GNUNET_SCHEDULER_cancel (cc->tct);
220 cc->tct = NULL; 225 cc->tct = NULL;
221 } 226 }
222 if (NULL != cc->oh) 227 if (NULL != cc->oh)
223 { 228 {
224 GNUNET_TRANSPORT_offer_hello_cancel(cc->oh); 229 GNUNET_TRANSPORT_offer_hello_cancel (cc->oh);
225 cc->oh = NULL; 230 cc->oh = NULL;
226 } 231 }
227 if (NULL != cc->ats_sh) 232 if (NULL != cc->ats_sh)
228 { 233 {
229 GNUNET_ATS_connectivity_suggest_cancel(cc->ats_sh); 234 GNUNET_ATS_connectivity_suggest_cancel (cc->ats_sh);
230 cc->ats_sh = NULL; 235 cc->ats_sh = NULL;
231 } 236 }
232 }
233 } 237 }
238 }
234 /* then notify application */ 239 /* then notify application */
235 for (cc = tth->cc_head; NULL != cc; cc = ccn) 240 for (cc = tth->cc_head; NULL != cc; cc = ccn)
241 {
242 ccn = cc->next;
243 if ((GNUNET_YES == cc->connected) &&
244 (NULL != cc->cb))
236 { 245 {
237 ccn = cc->next; 246 cc->cb (cc->cb_cls);
238 if ((GNUNET_YES == cc->connected) && 247 cc->cb = NULL; /* only notify once! */
239 (NULL != cc->cb))
240 {
241 cc->cb(cc->cb_cls);
242 cc->cb = NULL; /* only notify once! */
243 }
244 } 248 }
249 }
245 return ret; 250 return ret;
246} 251}
247 252
@@ -252,13 +257,13 @@ notify_connect(void *cls,
252 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest` 257 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest`
253 */ 258 */
254static void 259static void
255offer_hello(void *cls); 260offer_hello (void *cls);
256 261
257 262
258static void 263static void
259notify_disconnect(void *cls, 264notify_disconnect (void *cls,
260 const struct GNUNET_PeerIdentity *peer, 265 const struct GNUNET_PeerIdentity *peer,
261 void *handler_cls) 266 void *handler_cls)
262{ 267{
263 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 268 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
264 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 269 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
@@ -268,93 +273,94 @@ notify_disconnect(void *cls,
268 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL; 273 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL;
269 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 274 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
270 275
271 p2 = find_peer_context(p->tth, 276 p2 = find_peer_context (p->tth,
272 peer); 277 peer);
273 no = p->no; 278 no = p->no;
274 if (NULL != p2) 279 if (NULL != p2)
275 GNUNET_asprintf(&p2_s, 280 GNUNET_asprintf (&p2_s,
276 "%u (`%s')", 281 "%u (`%s')",
277 p2->no, 282 p2->no,
278 GNUNET_i2s(&p2->id)); 283 GNUNET_i2s (&p2->id));
279 else 284 else
280 GNUNET_asprintf(&p2_s, 285 GNUNET_asprintf (&p2_s,
281 "`%s'", 286 "`%s'",
282 GNUNET_i2s(peer)); 287 GNUNET_i2s (peer));
283 LOG(GNUNET_ERROR_TYPE_DEBUG, 288 LOG (GNUNET_ERROR_TYPE_DEBUG,
284 "Peers %s disconnected from peer %u (`%s')\n", 289 "Peers %s disconnected from peer %u (`%s')\n",
285 p2_s, 290 p2_s,
286 no, 291 no,
287 GNUNET_i2s(&p->id)); 292 GNUNET_i2s (&p->id));
288 GNUNET_free(p2_s); 293 GNUNET_free (p2_s);
289 /* notify about disconnect */ 294 /* notify about disconnect */
290 if (NULL != p->nd) 295 if (NULL != p->nd)
291 p->nd(p->cb_cls, 296 p->nd (p->cb_cls,
292 peer, 297 peer,
293 handler_cls); 298 handler_cls);
294 if (NULL == p2) 299 if (NULL == p2)
295 return; 300 return;
296 /* clear MQ, it is now invalid */ 301 /* clear MQ, it is now invalid */
297 GNUNET_TRANSPORT_TESTING_find_connecting_context(p, 302 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
298 p2, 303 p2,
299 &set_mq, 304 &set_mq,
300 NULL); 305 NULL);
301 /* update set connected flags for all requests */ 306 /* update set connected flags for all requests */
302 GNUNET_TRANSPORT_TESTING_find_connecting_context(p, 307 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
303 p2, 308 p2,
304 &clear_p1c, 309 &clear_p1c,
305 NULL); 310 NULL);
306 GNUNET_TRANSPORT_TESTING_find_connecting_context(p2, 311 GNUNET_TRANSPORT_TESTING_find_connecting_context (p2,
307 p, 312 p,
308 &clear_p2c, 313 &clear_p2c,
309 NULL); 314 NULL);
310 /* resume connectivity requests as necessary */ 315 /* resume connectivity requests as necessary */
311 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 316 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
312 { 317 {
313 if (GNUNET_NO == cc->connected) 318 if (GNUNET_NO == cc->connected)
314 continue; 319 continue;
315 if ((GNUNET_YES != cc->p1_c) || 320 if ((GNUNET_YES != cc->p1_c) ||
316 (GNUNET_YES != cc->p2_c)) 321 (GNUNET_YES != cc->p2_c))
317 { 322 {
318 cc->connected = GNUNET_NO; 323 cc->connected = GNUNET_NO;
319 /* start trying to connect */ 324 /* start trying to connect */
320 if ((NULL == cc->tct) && 325 if ((NULL == cc->tct) &&
321 (NULL == cc->oh)) 326 (NULL == cc->oh))
322 cc->tct = GNUNET_SCHEDULER_add_now(&offer_hello, 327 cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello,
323 cc); 328 cc);
324 if (NULL == cc->ats_sh) 329 if (NULL == cc->ats_sh)
325 cc->ats_sh = GNUNET_ATS_connectivity_suggest(cc->p1->ats, 330 cc->ats_sh = GNUNET_ATS_connectivity_suggest (cc->p1->ats,
326 &p2->id, 331 &p2->id,
327 1); 332 1);
328 }
329 } 333 }
334 }
330} 335}
331 336
332 337
333static void 338static void
334get_hello(void *cb_cls, 339get_hello (void *cb_cls,
335 const struct GNUNET_MessageHeader *message) 340 const struct GNUNET_MessageHeader *message)
336{ 341{
337 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cb_cls; 342 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cb_cls;
338 struct GNUNET_PeerIdentity hello_id; 343 struct GNUNET_PeerIdentity hello_id;
339 344
340 GNUNET_assert(GNUNET_OK == 345 GNUNET_assert (GNUNET_OK ==
341 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)message, 346 GNUNET_HELLO_get_id ((const struct
342 &hello_id)); 347 GNUNET_HELLO_Message *) message,
343 GNUNET_assert(0 == memcmp(&hello_id, 348 &hello_id));
344 &p->id, 349 GNUNET_assert (0 == memcmp (&hello_id,
345 sizeof(hello_id))); 350 &p->id,
346 GNUNET_free_non_null(p->hello); 351 sizeof(hello_id)));
347 p->hello = (struct GNUNET_HELLO_Message *)GNUNET_copy_message(message); 352 GNUNET_free_non_null (p->hello);
353 p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message);
348 354
349 if (NULL != p->start_cb) 355 if (NULL != p->start_cb)
350 { 356 {
351 LOG(GNUNET_ERROR_TYPE_DEBUG, 357 LOG (GNUNET_ERROR_TYPE_DEBUG,
352 "Peer %u (`%s') successfully started\n", 358 "Peer %u (`%s') successfully started\n",
353 p->no, 359 p->no,
354 GNUNET_i2s(&p->id)); 360 GNUNET_i2s (&p->id));
355 p->start_cb(p->start_cb_cls); 361 p->start_cb (p->start_cb_cls);
356 p->start_cb = NULL; 362 p->start_cb = NULL;
357 } 363 }
358} 364}
359 365
360 366
@@ -372,43 +378,45 @@ get_hello(void *cb_cls,
372 * @return the peer context 378 * @return the peer context
373 */ 379 */
374struct GNUNET_TRANSPORT_TESTING_PeerContext * 380struct GNUNET_TRANSPORT_TESTING_PeerContext *
375GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth, 381GNUNET_TRANSPORT_TESTING_start_peer (struct
376 const char *cfgname, 382 GNUNET_TRANSPORT_TESTING_Handle *tth,
377 int peer_id, 383 const char *cfgname,
378 const struct GNUNET_MQ_MessageHandler *handlers, 384 int peer_id,
379 GNUNET_TRANSPORT_NotifyConnect nc, 385 const struct
380 GNUNET_TRANSPORT_NotifyDisconnect nd, 386 GNUNET_MQ_MessageHandler *handlers,
381 void *cb_cls, 387 GNUNET_TRANSPORT_NotifyConnect nc,
382 GNUNET_SCHEDULER_TaskCallback start_cb, 388 GNUNET_TRANSPORT_NotifyDisconnect nd,
383 void *start_cb_cls) 389 void *cb_cls,
390 GNUNET_SCHEDULER_TaskCallback start_cb,
391 void *start_cb_cls)
384{ 392{
385 char *emsg = NULL; 393 char *emsg = NULL;
386 struct GNUNET_TRANSPORT_TESTING_PeerContext *p; 394 struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
387 struct GNUNET_PeerIdentity dummy; 395 struct GNUNET_PeerIdentity dummy;
388 unsigned int i; 396 unsigned int i;
389 397
390 if (GNUNET_NO == GNUNET_DISK_file_test(cfgname)) 398 if (GNUNET_NO == GNUNET_DISK_file_test (cfgname))
391 { 399 {
392 LOG(GNUNET_ERROR_TYPE_ERROR, 400 LOG (GNUNET_ERROR_TYPE_ERROR,
393 "File not found: `%s'\n", 401 "File not found: `%s'\n",
394 cfgname); 402 cfgname);
395 return NULL; 403 return NULL;
396 } 404 }
397 405
398 p = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_PeerContext); 406 p = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_PeerContext);
399 p->tth = tth; 407 p->tth = tth;
400 p->nc = nc; 408 p->nc = nc;
401 p->nd = nd; 409 p->nd = nd;
402 if (NULL != handlers) 410 if (NULL != handlers)
403 { 411 {
404 for (i = 0; NULL != handlers[i].cb; i++) 412 for (i = 0; NULL != handlers[i].cb; i++)
405 ; 413 ;
406 p->handlers = GNUNET_new_array(i + 1, 414 p->handlers = GNUNET_new_array (i + 1,
407 struct GNUNET_MQ_MessageHandler); 415 struct GNUNET_MQ_MessageHandler);
408 GNUNET_memcpy(p->handlers, 416 GNUNET_memcpy (p->handlers,
409 handlers, 417 handlers,
410 i * sizeof(struct GNUNET_MQ_MessageHandler)); 418 i * sizeof(struct GNUNET_MQ_MessageHandler));
411 } 419 }
412 if (NULL != cb_cls) 420 if (NULL != cb_cls)
413 p->cb_cls = cb_cls; 421 p->cb_cls = cb_cls;
414 else 422 else
@@ -418,105 +426,105 @@ GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth,
418 p->start_cb_cls = start_cb_cls; 426 p->start_cb_cls = start_cb_cls;
419 else 427 else
420 p->start_cb_cls = p; 428 p->start_cb_cls = p;
421 GNUNET_CONTAINER_DLL_insert(tth->p_head, 429 GNUNET_CONTAINER_DLL_insert (tth->p_head,
422 tth->p_tail, 430 tth->p_tail,
423 p); 431 p);
424 432
425 /* Create configuration and call testing lib to modify it */ 433 /* Create configuration and call testing lib to modify it */
426 p->cfg = GNUNET_CONFIGURATION_create(); 434 p->cfg = GNUNET_CONFIGURATION_create ();
427 GNUNET_assert(GNUNET_OK == 435 GNUNET_assert (GNUNET_OK ==
428 GNUNET_CONFIGURATION_load(p->cfg, cfgname)); 436 GNUNET_CONFIGURATION_load (p->cfg, cfgname));
429 if (GNUNET_SYSERR == 437 if (GNUNET_SYSERR ==
430 GNUNET_TESTING_configuration_create(tth->tl_system, 438 GNUNET_TESTING_configuration_create (tth->tl_system,
431 p->cfg)) 439 p->cfg))
432 { 440 {
433 LOG(GNUNET_ERROR_TYPE_ERROR, 441 LOG (GNUNET_ERROR_TYPE_ERROR,
434 "Testing library failed to create unique configuration based on `%s'\n", 442 "Testing library failed to create unique configuration based on `%s'\n",
435 cfgname); 443 cfgname);
436 GNUNET_CONFIGURATION_destroy(p->cfg); 444 GNUNET_CONFIGURATION_destroy (p->cfg);
437 GNUNET_free(p); 445 GNUNET_free (p);
438 return NULL; 446 return NULL;
439 } 447 }
440 448
441 p->no = peer_id; 449 p->no = peer_id;
442 /* Configure peer with configuration */ 450 /* Configure peer with configuration */
443 p->peer = GNUNET_TESTING_peer_configure(tth->tl_system, 451 p->peer = GNUNET_TESTING_peer_configure (tth->tl_system,
444 p->cfg, 452 p->cfg,
445 p->no, 453 p->no,
446 NULL, 454 NULL,
447 &emsg); 455 &emsg);
448 if (NULL == p->peer) 456 if (NULL == p->peer)
449 { 457 {
450 LOG(GNUNET_ERROR_TYPE_ERROR, 458 LOG (GNUNET_ERROR_TYPE_ERROR,
451 "Testing library failed to create unique configuration based on `%s': `%s'\n", 459 "Testing library failed to create unique configuration based on `%s': `%s'\n",
452 cfgname, 460 cfgname,
453 emsg); 461 emsg);
454 GNUNET_TRANSPORT_TESTING_stop_peer(p); 462 GNUNET_TRANSPORT_TESTING_stop_peer (p);
455 GNUNET_free_non_null(emsg); 463 GNUNET_free_non_null (emsg);
456 return NULL; 464 return NULL;
457 } 465 }
458 GNUNET_free_non_null(emsg); 466 GNUNET_free_non_null (emsg);
459 if (GNUNET_OK != GNUNET_TESTING_peer_start(p->peer)) 467 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer))
460 { 468 {
461 LOG(GNUNET_ERROR_TYPE_ERROR, 469 LOG (GNUNET_ERROR_TYPE_ERROR,
462 "Testing library failed to create unique configuration based on `%s'\n", 470 "Testing library failed to create unique configuration based on `%s'\n",
463 cfgname); 471 cfgname);
464 GNUNET_TRANSPORT_TESTING_stop_peer(p); 472 GNUNET_TRANSPORT_TESTING_stop_peer (p);
465 return NULL; 473 return NULL;
466 } 474 }
467 475
468 memset(&dummy, 476 memset (&dummy,
469 '\0', 477 '\0',
470 sizeof(dummy)); 478 sizeof(dummy));
471 GNUNET_TESTING_peer_get_identity(p->peer, 479 GNUNET_TESTING_peer_get_identity (p->peer,
472 &p->id); 480 &p->id);
473 if (0 == memcmp(&dummy, 481 if (0 == memcmp (&dummy,
474 &p->id, 482 &p->id,
475 sizeof(struct GNUNET_PeerIdentity))) 483 sizeof(struct GNUNET_PeerIdentity)))
476 { 484 {
477 LOG(GNUNET_ERROR_TYPE_ERROR, 485 LOG (GNUNET_ERROR_TYPE_ERROR,
478 "Testing library failed to obtain peer identity for peer %u\n", 486 "Testing library failed to obtain peer identity for peer %u\n",
479 p->no); 487 p->no);
480 GNUNET_TRANSPORT_TESTING_stop_peer(p); 488 GNUNET_TRANSPORT_TESTING_stop_peer (p);
481 return NULL; 489 return NULL;
482 } 490 }
483 LOG(GNUNET_ERROR_TYPE_DEBUG, 491 LOG (GNUNET_ERROR_TYPE_DEBUG,
484 "Peer %u configured with identity `%s'\n", 492 "Peer %u configured with identity `%s'\n",
485 p->no, 493 p->no,
486 GNUNET_i2s_full(&p->id)); 494 GNUNET_i2s_full (&p->id));
487 p->tmh = GNUNET_TRANSPORT_manipulation_connect(p->cfg); 495 p->tmh = GNUNET_TRANSPORT_manipulation_connect (p->cfg);
488 p->th = GNUNET_TRANSPORT_core_connect(p->cfg, 496 p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
489 NULL, 497 NULL,
490 handlers, 498 handlers,
491 p, 499 p,
492 &notify_connect, 500 &notify_connect,
493 &notify_disconnect, 501 &notify_disconnect,
494 NULL); 502 NULL);
495 if ((NULL == p->th) || 503 if ((NULL == p->th) ||
496 (NULL == p->tmh)) 504 (NULL == p->tmh))
497 { 505 {
498 LOG(GNUNET_ERROR_TYPE_ERROR, 506 LOG (GNUNET_ERROR_TYPE_ERROR,
499 "Failed to connect to transport service for peer `%s': `%s'\n", 507 "Failed to connect to transport service for peer `%s': `%s'\n",
500 cfgname, 508 cfgname,
501 emsg); 509 emsg);
502 GNUNET_TRANSPORT_TESTING_stop_peer(p); 510 GNUNET_TRANSPORT_TESTING_stop_peer (p);
503 return NULL; 511 return NULL;
504 } 512 }
505 p->ats = GNUNET_ATS_connectivity_init(p->cfg); 513 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
506 if (NULL == p->ats) 514 if (NULL == p->ats)
507 { 515 {
508 LOG(GNUNET_ERROR_TYPE_ERROR, 516 LOG (GNUNET_ERROR_TYPE_ERROR,
509 "Failed to connect to ATS service for peer `%s': `%s'\n", 517 "Failed to connect to ATS service for peer `%s': `%s'\n",
510 cfgname, 518 cfgname,
511 emsg); 519 emsg);
512 GNUNET_TRANSPORT_TESTING_stop_peer(p); 520 GNUNET_TRANSPORT_TESTING_stop_peer (p);
513 return NULL; 521 return NULL;
514 } 522 }
515 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, 523 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
516 GNUNET_TRANSPORT_AC_ANY, 524 GNUNET_TRANSPORT_AC_ANY,
517 &get_hello, 525 &get_hello,
518 p); 526 p);
519 GNUNET_assert(NULL != p->ghh); 527 GNUNET_assert (NULL != p->ghh);
520 return p; 528 return p;
521} 529}
522 530
@@ -530,89 +538,90 @@ GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth,
530 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR 538 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
531 */ 539 */
532int 540int
533GNUNET_TRANSPORT_TESTING_restart_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p, 541GNUNET_TRANSPORT_TESTING_restart_peer (struct
534 GNUNET_SCHEDULER_TaskCallback restart_cb, 542 GNUNET_TRANSPORT_TESTING_PeerContext *p,
535 void *restart_cb_cls) 543 GNUNET_SCHEDULER_TaskCallback restart_cb,
544 void *restart_cb_cls)
536{ 545{
537 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 546 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
538 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; 547 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
539 548
540 /* shutdown */ 549 /* shutdown */
541 LOG(GNUNET_ERROR_TYPE_DEBUG, 550 LOG (GNUNET_ERROR_TYPE_DEBUG,
542 "Stopping peer %u (`%s')\n", 551 "Stopping peer %u (`%s')\n",
543 p->no, 552 p->no,
544 GNUNET_i2s(&p->id)); 553 GNUNET_i2s (&p->id));
545 if (NULL != p->ghh) 554 if (NULL != p->ghh)
546 { 555 {
547 GNUNET_TRANSPORT_hello_get_cancel(p->ghh); 556 GNUNET_TRANSPORT_hello_get_cancel (p->ghh);
548 p->ghh = NULL; 557 p->ghh = NULL;
549 } 558 }
550 if (NULL != p->th) 559 if (NULL != p->th)
551 { 560 {
552 GNUNET_TRANSPORT_core_disconnect(p->th); 561 GNUNET_TRANSPORT_core_disconnect (p->th);
553 p->th = NULL; 562 p->th = NULL;
554 } 563 }
555 if (NULL != p->tmh) 564 if (NULL != p->tmh)
556 { 565 {
557 GNUNET_TRANSPORT_manipulation_disconnect(p->tmh); 566 GNUNET_TRANSPORT_manipulation_disconnect (p->tmh);
558 p->tmh = NULL; 567 p->tmh = NULL;
559 } 568 }
560 for (cc = p->tth->cc_head; NULL != cc; cc = ccn) 569 for (cc = p->tth->cc_head; NULL != cc; cc = ccn)
561 { 570 {
562 ccn = cc->next; 571 ccn = cc->next;
563 if ((cc->p1 == p) || 572 if ((cc->p1 == p) ||
564 (cc->p2 == p)) 573 (cc->p2 == p))
565 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 574 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
566 } 575 }
567 if (NULL != p->ats) 576 if (NULL != p->ats)
568 { 577 {
569 GNUNET_ATS_connectivity_done(p->ats); 578 GNUNET_ATS_connectivity_done (p->ats);
570 p->ats = NULL; 579 p->ats = NULL;
571 } 580 }
572 if (GNUNET_SYSERR == 581 if (GNUNET_SYSERR ==
573 GNUNET_TESTING_peer_stop(p->peer)) 582 GNUNET_TESTING_peer_stop (p->peer))
574 { 583 {
575 LOG(GNUNET_ERROR_TYPE_ERROR, 584 LOG (GNUNET_ERROR_TYPE_ERROR,
576 "Failed to stop peer %u (`%s')\n", 585 "Failed to stop peer %u (`%s')\n",
577 p->no, 586 p->no,
578 GNUNET_i2s(&p->id)); 587 GNUNET_i2s (&p->id));
579 return GNUNET_SYSERR; 588 return GNUNET_SYSERR;
580 } 589 }
581 590
582 sleep(5); // YUCK! 591 sleep (5); // YUCK!
583 592
584 LOG(GNUNET_ERROR_TYPE_DEBUG, 593 LOG (GNUNET_ERROR_TYPE_DEBUG,
585 "Restarting peer %u (`%s')\n", 594 "Restarting peer %u (`%s')\n",
586 p->no, 595 p->no,
587 GNUNET_i2s(&p->id)); 596 GNUNET_i2s (&p->id));
588 /* restart */ 597 /* restart */
589 if (GNUNET_SYSERR == GNUNET_TESTING_peer_start(p->peer)) 598 if (GNUNET_SYSERR == GNUNET_TESTING_peer_start (p->peer))
590 { 599 {
591 LOG(GNUNET_ERROR_TYPE_ERROR, 600 LOG (GNUNET_ERROR_TYPE_ERROR,
592 "Failed to restart peer %u (`%s')\n", 601 "Failed to restart peer %u (`%s')\n",
593 p->no, 602 p->no,
594 GNUNET_i2s(&p->id)); 603 GNUNET_i2s (&p->id));
595 return GNUNET_SYSERR; 604 return GNUNET_SYSERR;
596 } 605 }
597 606
598 GNUNET_assert(NULL == p->start_cb); 607 GNUNET_assert (NULL == p->start_cb);
599 p->start_cb = restart_cb; 608 p->start_cb = restart_cb;
600 p->start_cb_cls = restart_cb_cls; 609 p->start_cb_cls = restart_cb_cls;
601 610
602 p->th = GNUNET_TRANSPORT_core_connect(p->cfg, 611 p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
603 NULL, 612 NULL,
604 p->handlers, 613 p->handlers,
605 p, 614 p,
606 &notify_connect, 615 &notify_connect,
607 &notify_disconnect, 616 &notify_disconnect,
608 NULL); 617 NULL);
609 GNUNET_assert(NULL != p->th); 618 GNUNET_assert (NULL != p->th);
610 p->ats = GNUNET_ATS_connectivity_init(p->cfg); 619 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
611 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, 620 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
612 GNUNET_TRANSPORT_AC_ANY, 621 GNUNET_TRANSPORT_AC_ANY,
613 &get_hello, 622 &get_hello,
614 p); 623 p);
615 GNUNET_assert(NULL != p->ghh); 624 GNUNET_assert (NULL != p->ghh);
616 return GNUNET_OK; 625 return GNUNET_OK;
617} 626}
618 627
@@ -623,75 +632,76 @@ GNUNET_TRANSPORT_TESTING_restart_peer(struct GNUNET_TRANSPORT_TESTING_PeerContex
623 * @param p the peer 632 * @param p the peer
624 */ 633 */
625void 634void
626GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p) 635GNUNET_TRANSPORT_TESTING_stop_peer (struct
636 GNUNET_TRANSPORT_TESTING_PeerContext *p)
627{ 637{
628 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 638 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
629 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 639 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
630 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; 640 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
631 641
632 for (cc = tth->cc_head; NULL != cc; cc = ccn) 642 for (cc = tth->cc_head; NULL != cc; cc = ccn)
633 { 643 {
634 ccn = cc->next; 644 ccn = cc->next;
635 if ((cc->p1 == p) || 645 if ((cc->p1 == p) ||
636 (cc->p2 == p)) 646 (cc->p2 == p))
637 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 647 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
638 } 648 }
639 if (NULL != p->ghh) 649 if (NULL != p->ghh)
640 { 650 {
641 GNUNET_TRANSPORT_hello_get_cancel(p->ghh); 651 GNUNET_TRANSPORT_hello_get_cancel (p->ghh);
642 p->ghh = NULL; 652 p->ghh = NULL;
643 } 653 }
644 if (NULL != p->tmh) 654 if (NULL != p->tmh)
645 { 655 {
646 GNUNET_TRANSPORT_manipulation_disconnect(p->tmh); 656 GNUNET_TRANSPORT_manipulation_disconnect (p->tmh);
647 p->tmh = NULL; 657 p->tmh = NULL;
648 } 658 }
649 if (NULL != p->th) 659 if (NULL != p->th)
650 { 660 {
651 GNUNET_TRANSPORT_core_disconnect(p->th); 661 GNUNET_TRANSPORT_core_disconnect (p->th);
652 p->th = NULL; 662 p->th = NULL;
653 } 663 }
654 if (NULL != p->peer) 664 if (NULL != p->peer)
665 {
666 if (GNUNET_OK !=
667 GNUNET_TESTING_peer_stop (p->peer))
655 { 668 {
656 if (GNUNET_OK != 669 LOG (GNUNET_ERROR_TYPE_DEBUG,
657 GNUNET_TESTING_peer_stop(p->peer)) 670 "Testing lib failed to stop peer %u (`%s')\n",
658 { 671 p->no,
659 LOG(GNUNET_ERROR_TYPE_DEBUG, 672 GNUNET_i2s (&p->id));
660 "Testing lib failed to stop peer %u (`%s')\n",
661 p->no,
662 GNUNET_i2s(&p->id));
663 }
664 GNUNET_TESTING_peer_destroy(p->peer);
665 p->peer = NULL;
666 } 673 }
674 GNUNET_TESTING_peer_destroy (p->peer);
675 p->peer = NULL;
676 }
667 if (NULL != p->ats) 677 if (NULL != p->ats)
668 { 678 {
669 GNUNET_ATS_connectivity_done(p->ats); 679 GNUNET_ATS_connectivity_done (p->ats);
670 p->ats = NULL; 680 p->ats = NULL;
671 } 681 }
672 if (NULL != p->hello) 682 if (NULL != p->hello)
673 { 683 {
674 GNUNET_free(p->hello); 684 GNUNET_free (p->hello);
675 p->hello = NULL; 685 p->hello = NULL;
676 } 686 }
677 if (NULL != p->cfg) 687 if (NULL != p->cfg)
678 { 688 {
679 GNUNET_CONFIGURATION_destroy(p->cfg); 689 GNUNET_CONFIGURATION_destroy (p->cfg);
680 p->cfg = NULL; 690 p->cfg = NULL;
681 } 691 }
682 if (NULL != p->handlers) 692 if (NULL != p->handlers)
683 { 693 {
684 GNUNET_free(p->handlers); 694 GNUNET_free (p->handlers);
685 p->handlers = NULL; 695 p->handlers = NULL;
686 } 696 }
687 GNUNET_CONTAINER_DLL_remove(tth->p_head, 697 GNUNET_CONTAINER_DLL_remove (tth->p_head,
688 tth->p_tail, 698 tth->p_tail,
689 p); 699 p);
690 LOG(GNUNET_ERROR_TYPE_DEBUG, 700 LOG (GNUNET_ERROR_TYPE_DEBUG,
691 "Peer %u (`%s') stopped\n", 701 "Peer %u (`%s') stopped\n",
692 p->no, 702 p->no,
693 GNUNET_i2s(&p->id)); 703 GNUNET_i2s (&p->id));
694 GNUNET_free(p); 704 GNUNET_free (p);
695} 705}
696 706
697 707
@@ -700,14 +710,14 @@ GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *
700 * transport service. 710 * transport service.
701 */ 711 */
702static void 712static void
703hello_offered(void *cls) 713hello_offered (void *cls)
704{ 714{
705 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; 715 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls;
706 716
707 cc->oh = NULL; 717 cc->oh = NULL;
708 cc->tct = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 718 cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
709 &offer_hello, 719 &offer_hello,
710 cc); 720 cc);
711} 721}
712 722
713 723
@@ -717,7 +727,7 @@ hello_offered(void *cls)
717 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest` 727 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest`
718 */ 728 */
719static void 729static void
720offer_hello(void *cls) 730offer_hello (void *cls)
721{ 731{
722 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; 732 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls;
723 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1; 733 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1;
@@ -725,25 +735,26 @@ offer_hello(void *cls)
725 735
726 cc->tct = NULL; 736 cc->tct = NULL;
727 { 737 {
728 char *p2_s = GNUNET_strdup(GNUNET_i2s(&p2->id)); 738 char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
729 739
730 LOG(GNUNET_ERROR_TYPE_DEBUG, 740 LOG (GNUNET_ERROR_TYPE_DEBUG,
731 "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n", 741 "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n",
732 p1->no, 742 p1->no,
733 GNUNET_i2s(&p1->id), 743 GNUNET_i2s (&p1->id),
734 p2->no, 744 p2->no,
735 p2_s, 745 p2_s,
736 GNUNET_HELLO_size(cc->p2->hello)); 746 GNUNET_HELLO_size (cc->p2->hello));
737 GNUNET_free(p2_s); 747 GNUNET_free (p2_s);
738 } 748 }
739 749
740 if (NULL != cc->oh) 750 if (NULL != cc->oh)
741 GNUNET_TRANSPORT_offer_hello_cancel(cc->oh); 751 GNUNET_TRANSPORT_offer_hello_cancel (cc->oh);
742 cc->oh = 752 cc->oh =
743 GNUNET_TRANSPORT_offer_hello(cc->p1->cfg, 753 GNUNET_TRANSPORT_offer_hello (cc->p1->cfg,
744 (const struct GNUNET_MessageHeader *)cc->p2->hello, 754 (const struct
745 &hello_offered, 755 GNUNET_MessageHeader *) cc->p2->hello,
746 cc); 756 &hello_offered,
757 cc);
747} 758}
748 759
749 760
@@ -760,10 +771,12 @@ offer_hello(void *cls)
760 * @return a connect request handle 771 * @return a connect request handle
761 */ 772 */
762struct GNUNET_TRANSPORT_TESTING_ConnectRequest * 773struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
763GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 774GNUNET_TRANSPORT_TESTING_connect_peers (struct
764 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 775 GNUNET_TRANSPORT_TESTING_PeerContext *p1,
765 GNUNET_SCHEDULER_TaskCallback cb, 776 struct
766 void *cls) 777 GNUNET_TRANSPORT_TESTING_PeerContext *p2,
778 GNUNET_SCHEDULER_TaskCallback cb,
779 void *cls)
767{ 780{
768 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; 781 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
769 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 782 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
@@ -771,16 +784,16 @@ GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerConte
771 784
772 ccn = NULL; 785 ccn = NULL;
773 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 786 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
787 {
788 if ((cc->p1 == p1) &&
789 (cc->p2 == p2))
774 { 790 {
775 if ((cc->p1 == p1) && 791 ccn = cc;
776 (cc->p2 == p2)) 792 break;
777 {
778 ccn = cc;
779 break;
780 }
781 } 793 }
794 }
782 795
783 cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest); 796 cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
784 cc->p1 = p1; 797 cc->p1 = p1;
785 cc->p2 = p2; 798 cc->p2 = p2;
786 cc->cb = cb; 799 cc->cb = cb;
@@ -789,22 +802,22 @@ GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerConte
789 else 802 else
790 cc->cb_cls = cc; 803 cc->cb_cls = cc;
791 if (NULL != ccn) 804 if (NULL != ccn)
792 { 805 {
793 cc->p1_c = ccn->p1_c; 806 cc->p1_c = ccn->p1_c;
794 cc->p2_c = ccn->p2_c; 807 cc->p2_c = ccn->p2_c;
795 cc->connected = ccn->connected; 808 cc->connected = ccn->connected;
796 } 809 }
797 GNUNET_CONTAINER_DLL_insert(tth->cc_head, 810 GNUNET_CONTAINER_DLL_insert (tth->cc_head,
798 tth->cc_tail, 811 tth->cc_tail,
799 cc); 812 cc);
800 cc->tct = GNUNET_SCHEDULER_add_now(&offer_hello, 813 cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello,
801 cc); 814 cc);
802 cc->ats_sh = GNUNET_ATS_connectivity_suggest(cc->p1->ats, 815 cc->ats_sh = GNUNET_ATS_connectivity_suggest (cc->p1->ats,
803 &p2->id, 816 &p2->id,
804 1); 817 1);
805 LOG(GNUNET_ERROR_TYPE_DEBUG, 818 LOG (GNUNET_ERROR_TYPE_DEBUG,
806 "New connect request %p\n", 819 "New connect request %p\n",
807 cc); 820 cc);
808 return cc; 821 return cc;
809} 822}
810 823
@@ -817,31 +830,33 @@ GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerConte
817 * @param cc a connect request handle 830 * @param cc a connect request handle
818 */ 831 */
819void 832void
820GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc) 833GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
834 GNUNET_TRANSPORT_TESTING_ConnectRequest
835 *cc)
821{ 836{
822 struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth; 837 struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth;
823 838
824 LOG(GNUNET_ERROR_TYPE_DEBUG, 839 LOG (GNUNET_ERROR_TYPE_DEBUG,
825 "Canceling connect request!\n"); 840 "Canceling connect request!\n");
826 if (NULL != cc->tct) 841 if (NULL != cc->tct)
827 { 842 {
828 GNUNET_SCHEDULER_cancel(cc->tct); 843 GNUNET_SCHEDULER_cancel (cc->tct);
829 cc->tct = NULL; 844 cc->tct = NULL;
830 } 845 }
831 if (NULL != cc->oh) 846 if (NULL != cc->oh)
832 { 847 {
833 GNUNET_TRANSPORT_offer_hello_cancel(cc->oh); 848 GNUNET_TRANSPORT_offer_hello_cancel (cc->oh);
834 cc->oh = NULL; 849 cc->oh = NULL;
835 } 850 }
836 if (NULL != cc->ats_sh) 851 if (NULL != cc->ats_sh)
837 { 852 {
838 GNUNET_ATS_connectivity_suggest_cancel(cc->ats_sh); 853 GNUNET_ATS_connectivity_suggest_cancel (cc->ats_sh);
839 cc->ats_sh = NULL; 854 cc->ats_sh = NULL;
840 } 855 }
841 GNUNET_CONTAINER_DLL_remove(tth->cc_head, 856 GNUNET_CONTAINER_DLL_remove (tth->cc_head,
842 tth->cc_tail, 857 tth->cc_tail,
843 cc); 858 cc);
844 GNUNET_free(cc); 859 GNUNET_free (cc);
845} 860}
846 861
847 862
@@ -851,7 +866,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_Co
851 * @param tth transport testing handle 866 * @param tth transport testing handle
852 */ 867 */
853void 868void
854GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth) 869GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth)
855{ 870{
856 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 871 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
857 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ct; 872 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ct;
@@ -862,26 +877,26 @@ GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
862 return; 877 return;
863 cc = tth->cc_head; 878 cc = tth->cc_head;
864 while (NULL != cc) 879 while (NULL != cc)
865 { 880 {
866 ct = cc->next; 881 ct = cc->next;
867 LOG(GNUNET_ERROR_TYPE_ERROR, 882 LOG (GNUNET_ERROR_TYPE_ERROR,
868 "Developer forgot to cancel connect request!\n"); 883 "Developer forgot to cancel connect request!\n");
869 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 884 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
870 cc = ct; 885 cc = ct;
871 } 886 }
872 p = tth->p_head; 887 p = tth->p_head;
873 while (NULL != p) 888 while (NULL != p)
874 { 889 {
875 t = p->next; 890 t = p->next;
876 LOG(GNUNET_ERROR_TYPE_ERROR, 891 LOG (GNUNET_ERROR_TYPE_ERROR,
877 "Developer forgot to stop peer!\n"); 892 "Developer forgot to stop peer!\n");
878 GNUNET_TRANSPORT_TESTING_stop_peer(p); 893 GNUNET_TRANSPORT_TESTING_stop_peer (p);
879 p = t; 894 p = t;
880 } 895 }
881 GNUNET_TESTING_system_destroy(tth->tl_system, 896 GNUNET_TESTING_system_destroy (tth->tl_system,
882 GNUNET_YES); 897 GNUNET_YES);
883 898
884 GNUNET_free(tth); 899 GNUNET_free (tth);
885} 900}
886 901
887 902
@@ -891,22 +906,22 @@ GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
891 * @return transport testing handle 906 * @return transport testing handle
892 */ 907 */
893struct GNUNET_TRANSPORT_TESTING_Handle * 908struct GNUNET_TRANSPORT_TESTING_Handle *
894GNUNET_TRANSPORT_TESTING_init() 909GNUNET_TRANSPORT_TESTING_init ()
895{ 910{
896 struct GNUNET_TRANSPORT_TESTING_Handle *tth; 911 struct GNUNET_TRANSPORT_TESTING_Handle *tth;
897 912
898 tth = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_Handle); 913 tth = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_Handle);
899 tth->tl_system = GNUNET_TESTING_system_create("transport-testing", 914 tth->tl_system = GNUNET_TESTING_system_create ("transport-testing",
900 NULL, 915 NULL,
901 NULL, 916 NULL,
902 NULL); 917 NULL);
903 if (NULL == tth->tl_system) 918 if (NULL == tth->tl_system)
904 { 919 {
905 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 920 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
906 "Failed to initialize testing library!\n"); 921 "Failed to initialize testing library!\n");
907 GNUNET_free(tth); 922 GNUNET_free (tth);
908 return NULL; 923 return NULL;
909 } 924 }
910 return tth; 925 return tth;
911} 926}
912 927
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;
51/** 51/**
52 * Context for a single peer 52 * Context for a single peer
53 */ 53 */
54struct GNUNET_TRANSPORT_TESTING_PeerContext { 54struct GNUNET_TRANSPORT_TESTING_PeerContext
55{
55 /** 56 /**
56 * Next element in the DLL 57 * Next element in the DLL
57 */ 58 */
@@ -152,7 +153,8 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext {
152/** 153/**
153 * Handle for a request to connect two peers. 154 * Handle for a request to connect two peers.
154 */ 155 */
155struct GNUNET_TRANSPORT_TESTING_ConnectRequest { 156struct GNUNET_TRANSPORT_TESTING_ConnectRequest
157{
156 /** 158 /**
157 * Kept in a DLL. 159 * Kept in a DLL.
158 */ 160 */
@@ -224,7 +226,8 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest {
224/** 226/**
225 * Handle for a test run. 227 * Handle for a test run.
226 */ 228 */
227struct GNUNET_TRANSPORT_TESTING_Handle { 229struct GNUNET_TRANSPORT_TESTING_Handle
230{
228 /** 231 /**
229 * Testing library system handle 232 * Testing library system handle
230 */ 233 */
@@ -258,7 +261,7 @@ struct GNUNET_TRANSPORT_TESTING_Handle {
258 * @return transport testing handle 261 * @return transport testing handle
259 */ 262 */
260struct GNUNET_TRANSPORT_TESTING_Handle * 263struct GNUNET_TRANSPORT_TESTING_Handle *
261GNUNET_TRANSPORT_TESTING_init(void); 264GNUNET_TRANSPORT_TESTING_init (void);
262 265
263 266
264/** 267/**
@@ -267,7 +270,7 @@ GNUNET_TRANSPORT_TESTING_init(void);
267 * @param tth transport testing handle 270 * @param tth transport testing handle
268 */ 271 */
269void 272void
270GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth); 273GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth);
271 274
272 275
273/** 276/**
@@ -285,7 +288,7 @@ GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth);
285 * @return the peer context 288 * @return the peer context
286 */ 289 */
287struct GNUNET_TRANSPORT_TESTING_PeerContext * 290struct GNUNET_TRANSPORT_TESTING_PeerContext *
288GNUNET_TRANSPORT_TESTING_start_peer( 291GNUNET_TRANSPORT_TESTING_start_peer (
289 struct GNUNET_TRANSPORT_TESTING_Handle *tth, 292 struct GNUNET_TRANSPORT_TESTING_Handle *tth,
290 const char *cfgname, 293 const char *cfgname,
291 int peer_id, 294 int peer_id,
@@ -303,7 +306,7 @@ GNUNET_TRANSPORT_TESTING_start_peer(
303 * @param p the peer 306 * @param p the peer
304 */ 307 */
305void 308void
306GNUNET_TRANSPORT_TESTING_stop_peer( 309GNUNET_TRANSPORT_TESTING_stop_peer (
307 struct GNUNET_TRANSPORT_TESTING_PeerContext *pc); 310 struct GNUNET_TRANSPORT_TESTING_PeerContext *pc);
308 311
309 312
@@ -316,7 +319,7 @@ GNUNET_TRANSPORT_TESTING_stop_peer(
316 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR 319 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
317 */ 320 */
318int 321int
319GNUNET_TRANSPORT_TESTING_restart_peer( 322GNUNET_TRANSPORT_TESTING_restart_peer (
320 struct GNUNET_TRANSPORT_TESTING_PeerContext *p, 323 struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
321 GNUNET_SCHEDULER_TaskCallback restart_cb, 324 GNUNET_SCHEDULER_TaskCallback restart_cb,
322 void *restart_cb_cls); 325 void *restart_cb_cls);
@@ -335,7 +338,7 @@ GNUNET_TRANSPORT_TESTING_restart_peer(
335 * @return a connect request handle 338 * @return a connect request handle
336 */ 339 */
337struct GNUNET_TRANSPORT_TESTING_ConnectRequest * 340struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
338GNUNET_TRANSPORT_TESTING_connect_peers( 341GNUNET_TRANSPORT_TESTING_connect_peers (
339 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 342 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
340 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 343 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
341 GNUNET_SCHEDULER_TaskCallback cb, 344 GNUNET_SCHEDULER_TaskCallback cb,
@@ -350,7 +353,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers(
350 * @param cc a connect request handle 353 * @param cc a connect request handle
351 */ 354 */
352void 355void
353GNUNET_TRANSPORT_TESTING_connect_peers_cancel( 356GNUNET_TRANSPORT_TESTING_connect_peers_cancel (
354 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); 357 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
355 358
356 359
@@ -374,7 +377,7 @@ typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContextCallback) (
374 * @param cb_cls closure for @a cb 377 * @param cb_cls closure for @a cb
375 */ 378 */
376void 379void
377GNUNET_TRANSPORT_TESTING_find_connecting_context( 380GNUNET_TRANSPORT_TESTING_find_connecting_context (
378 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 381 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
379 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 382 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
380 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, 383 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb,
@@ -410,7 +413,8 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext;
410 413
411 414
412GNUNET_NETWORK_STRUCT_BEGIN 415GNUNET_NETWORK_STRUCT_BEGIN
413struct GNUNET_TRANSPORT_TESTING_TestMessage { 416struct GNUNET_TRANSPORT_TESTING_TestMessage
417{
414 /** 418 /**
415 * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE. 419 * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE.
416 */ 420 */
@@ -471,7 +475,8 @@ typedef void (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) (
471 * Closure that must be passed to 475 * Closure that must be passed to
472 * #GNUNET_TRANSPORT_TESTING_connect_check. 476 * #GNUNET_TRANSPORT_TESTING_connect_check.
473 */ 477 */
474struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext { 478struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
479{
475 /** 480 /**
476 * How should we continue after the connect? 481 * How should we continue after the connect?
477 */ 482 */
@@ -634,7 +639,7 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext {
634 * @return NULL if @a peer was not found 639 * @return NULL if @a peer was not found
635 */ 640 */
636struct GNUNET_TRANSPORT_TESTING_PeerContext * 641struct GNUNET_TRANSPORT_TESTING_PeerContext *
637GNUNET_TRANSPORT_TESTING_find_peer( 642GNUNET_TRANSPORT_TESTING_find_peer (
638 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, 643 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
639 const struct GNUNET_PeerIdentity *peer); 644 const struct GNUNET_PeerIdentity *peer);
640 645
@@ -656,7 +661,7 @@ GNUNET_TRANSPORT_TESTING_find_peer(
656 * @return #GNUNET_SYSERR on error 661 * @return #GNUNET_SYSERR on error
657 */ 662 */
658int 663int
659GNUNET_TRANSPORT_TESTING_connect_check( 664GNUNET_TRANSPORT_TESTING_connect_check (
660 void *cls, 665 void *cls,
661 struct GNUNET_TRANSPORT_TESTING_Handle *tth_, 666 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
662 const char *test_plugin_, 667 const char *test_plugin_,
@@ -697,11 +702,11 @@ typedef int (*GNUNET_TRANSPORT_TESTING_CheckCallback) (
697 * @return #GNUNET_OK on success 702 * @return #GNUNET_OK on success
698 */ 703 */
699int 704int
700GNUNET_TRANSPORT_TESTING_main_(const char *argv0, 705GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
701 const char *filename, 706 const char *filename,
702 unsigned int num_peers, 707 unsigned int num_peers,
703 GNUNET_TRANSPORT_TESTING_CheckCallback check, 708 GNUNET_TRANSPORT_TESTING_CheckCallback check,
704 void *check_cls); 709 void *check_cls);
705 710
706 711
707/** 712/**
@@ -713,11 +718,11 @@ GNUNET_TRANSPORT_TESTING_main_(const char *argv0,
713 * @return #GNUNET_OK on success 718 * @return #GNUNET_OK on success
714 */ 719 */
715#define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \ 720#define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \
716 GNUNET_TRANSPORT_TESTING_main_(argv[0], \ 721 GNUNET_TRANSPORT_TESTING_main_ (argv[0], \
717 __FILE__, \ 722 __FILE__, \
718 num_peers, \ 723 num_peers, \
719 check, \ 724 check, \
720 check_cls) 725 check_cls)
721 726
722/* ***************** Convenience functions for sending ********* */ 727/* ***************** Convenience functions for sending ********* */
723 728
@@ -739,7 +744,7 @@ GNUNET_TRANSPORT_TESTING_main_(const char *argv0,
739 * #GNUNET_SYSERR if @a msize is illegal 744 * #GNUNET_SYSERR if @a msize is illegal
740 */ 745 */
741int 746int
742GNUNET_TRANSPORT_TESTING_send( 747GNUNET_TRANSPORT_TESTING_send (
743 struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, 748 struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
744 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 749 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
745 uint16_t mtype, 750 uint16_t mtype,
@@ -765,7 +770,8 @@ GNUNET_TRANSPORT_TESTING_send(
765 * #GNUNET_TRANSPORT_TESTING_simple_send() and 770 * #GNUNET_TRANSPORT_TESTING_simple_send() and
766 * #GNUNET_TRANSPORT_TESTING_large_send(). 771 * #GNUNET_TRANSPORT_TESTING_large_send().
767 */ 772 */
768struct GNUNET_TRANSPORT_TESTING_SendClosure { 773struct GNUNET_TRANSPORT_TESTING_SendClosure
774{
769 /** 775 /**
770 * Context for the transmission. 776 * Context for the transmission.
771 */ 777 */
@@ -805,7 +811,7 @@ struct GNUNET_TRANSPORT_TESTING_SendClosure {
805 * of which should be currently connected 811 * of which should be currently connected
806 */ 812 */
807void 813void
808GNUNET_TRANSPORT_TESTING_simple_send(void *cls); 814GNUNET_TRANSPORT_TESTING_simple_send (void *cls);
809 815
810/** 816/**
811 * Size of a message sent with 817 * Size of a message sent with
@@ -823,7 +829,7 @@ GNUNET_TRANSPORT_TESTING_simple_send(void *cls);
823 * of which should be currently connected 829 * of which should be currently connected
824 */ 830 */
825void 831void
826GNUNET_TRANSPORT_TESTING_large_send(void *cls); 832GNUNET_TRANSPORT_TESTING_large_send (void *cls);
827 833
828 834
829/* ********************** log-only convenience functions ************* */ 835/* ********************** log-only convenience functions ************* */
@@ -837,7 +843,7 @@ GNUNET_TRANSPORT_TESTING_large_send(void *cls);
837 * @param other peer that connected. 843 * @param other peer that connected.
838 */ 844 */
839void 845void
840GNUNET_TRANSPORT_TESTING_log_connect( 846GNUNET_TRANSPORT_TESTING_log_connect (
841 void *cls, 847 void *cls,
842 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 848 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
843 const struct GNUNET_PeerIdentity *other); 849 const struct GNUNET_PeerIdentity *other);
@@ -851,7 +857,7 @@ GNUNET_TRANSPORT_TESTING_log_connect(
851 * @param other peer that disconnected. 857 * @param other peer that disconnected.
852 */ 858 */
853void 859void
854GNUNET_TRANSPORT_TESTING_log_disconnect( 860GNUNET_TRANSPORT_TESTING_log_disconnect (
855 void *cls, 861 void *cls,
856 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 862 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
857 const struct GNUNET_PeerIdentity *other); 863 const struct GNUNET_PeerIdentity *other);
@@ -868,7 +874,7 @@ GNUNET_TRANSPORT_TESTING_log_disconnect(
868 * @return resulting test name 874 * @return resulting test name
869 */ 875 */
870char * 876char *
871GNUNET_TRANSPORT_TESTING_get_test_name(const char *file); 877GNUNET_TRANSPORT_TESTING_get_test_name (const char *file);
872 878
873 879
874/** 880/**
@@ -880,7 +886,7 @@ GNUNET_TRANSPORT_TESTING_get_test_name(const char *file);
880 * @return configuration name to use 886 * @return configuration name to use
881 */ 887 */
882char * 888char *
883GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count); 889GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count);
884 890
885 891
886/** 892/**
@@ -890,8 +896,8 @@ GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count);
890 * @return the plugin name 896 * @return the plugin name
891 */ 897 */
892char * 898char *
893GNUNET_TRANSPORT_TESTING_get_test_plugin_name(const char *executable, 899GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
894 const char *testname); 900 const char *testname);
895 901
896 902
897/** 903/**
@@ -902,7 +908,7 @@ GNUNET_TRANSPORT_TESTING_get_test_plugin_name(const char *executable,
902 * @return the source name 908 * @return the source name
903 */ 909 */
904char * 910char *
905GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file); 911GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file);
906 912
907#endif 913#endif
908/* end of transport_testing.h */ 914/* 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 @@
35#include "transport.h" 35#include "transport.h"
36 36
37 37
38#define LOG(kind, ...) GNUNET_log_from(kind, "transport-testing2", __VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__)
39 39
40 40
41/** 41/**
42 * @brief Handle to a transport communicator 42 * @brief Handle to a transport communicator
43 */ 43 */
44struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle { 44struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
45{
45 /** 46 /**
46 * @brief Handle to the configuration 47 * @brief Handle to the configuration
47 */ 48 */
@@ -145,7 +146,8 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle {
145/** 146/**
146 * @brief Queue of a communicator and some context 147 * @brief Queue of a communicator and some context
147 */ 148 */
148struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue { 149struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
150{
149 /** 151 /**
150 * @brief Handle to the TransportCommunicator 152 * @brief Handle to the TransportCommunicator
151 */ 153 */
@@ -205,7 +207,8 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue {
205/** 207/**
206 * @brief Handle/Context to a single transmission 208 * @brief Handle/Context to a single transmission
207 */ 209 */
208struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission { 210struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission
211{
209}; 212};
210 213
211 214
@@ -219,16 +222,16 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission {
219 * @return GNUNET_YES in case message is correct 222 * @return GNUNET_YES in case message is correct
220 */ 223 */
221static int 224static int
222check_communicator_available( 225check_communicator_available (
223 void *cls, 226 void *cls,
224 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) 227 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
225{ 228{
226 uint16_t size; 229 uint16_t size;
227 230
228 size = ntohs(msg->header.size) - sizeof(*msg); 231 size = ntohs (msg->header.size) - sizeof(*msg);
229 if (0 == size) 232 if (0 == size)
230 return GNUNET_OK; /* receive-only communicator */ 233 return GNUNET_OK; /* receive-only communicator */
231 GNUNET_MQ_check_zero_termination(msg); 234 GNUNET_MQ_check_zero_termination (msg);
232 return GNUNET_OK; 235 return GNUNET_OK;
233} 236}
234 237
@@ -242,27 +245,27 @@ check_communicator_available(
242 * @param msg Message struct 245 * @param msg Message struct
243 */ 246 */
244static void 247static void
245handle_communicator_available( 248handle_communicator_available (
246 void *cls, 249 void *cls,
247 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) 250 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
248{ 251{
249 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 252 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
250 uint16_t size; 253 uint16_t size;
251 254
252 size = ntohs(msg->header.size) - sizeof(*msg); 255 size = ntohs (msg->header.size) - sizeof(*msg);
253 if (0 == size) 256 if (0 == size)
254 return; /* receive-only communicator */ 257 return; /* receive-only communicator */
255 tc_h->c_characteristics = ntohl(msg->cc); 258 tc_h->c_characteristics = ntohl (msg->cc);
256 tc_h->c_addr_prefix = GNUNET_strdup((const char *)&msg[1]); 259 tc_h->c_addr_prefix = GNUNET_strdup ((const char *) &msg[1]);
257 if (NULL != tc_h->communicator_available_cb) 260 if (NULL != tc_h->communicator_available_cb)
258 { 261 {
259 LOG(GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n"); 262 LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n");
260 tc_h->communicator_available_cb(tc_h->cb_cls, 263 tc_h->communicator_available_cb (tc_h->cb_cls,
261 tc_h, 264 tc_h,
262 tc_h->c_characteristics, 265 tc_h->c_characteristics,
263 tc_h->c_addr_prefix); 266 tc_h->c_addr_prefix);
264 } 267 }
265 GNUNET_SERVICE_client_continue(tc_h->client); 268 GNUNET_SERVICE_client_continue (tc_h->client);
266} 269}
267 270
268 271
@@ -274,17 +277,17 @@ handle_communicator_available(
274 * @return #GNUNET_OK if message is well-formed 277 * @return #GNUNET_OK if message is well-formed
275 */ 278 */
276static int 279static int
277check_add_address(void *cls, 280check_add_address (void *cls,
278 const struct GNUNET_TRANSPORT_AddAddressMessage *msg) 281 const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
279{ 282{
280 struct TransportClient *tc = cls; 283 struct TransportClient *tc = cls;
281 284
282 //if (CT_COMMUNICATOR != tc->type) 285 // if (CT_COMMUNICATOR != tc->type)
283 //{ 286 // {
284 // GNUNET_break (0); 287 // GNUNET_break (0);
285 // return GNUNET_SYSERR; 288 // return GNUNET_SYSERR;
286 //} 289 // }
287 GNUNET_MQ_check_zero_termination(msg); 290 GNUNET_MQ_check_zero_termination (msg);
288 return GNUNET_OK; 291 return GNUNET_OK;
289} 292}
290 293
@@ -298,27 +301,27 @@ check_add_address(void *cls,
298 * @param msg Message 301 * @param msg Message
299 */ 302 */
300static void 303static void
301handle_add_address(void *cls, 304handle_add_address (void *cls,
302 const struct GNUNET_TRANSPORT_AddAddressMessage *msg) 305 const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
303{ 306{
304 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 307 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
305 uint16_t size; 308 uint16_t size;
306 309
307 size = ntohs(msg->header.size) - sizeof(*msg); 310 size = ntohs (msg->header.size) - sizeof(*msg);
308 if (0 == size) 311 if (0 == size)
309 return; /* receive-only communicator */ 312 return; /* receive-only communicator */
310 tc_h->c_address = GNUNET_strdup((const char *)&msg[1]); 313 tc_h->c_address = GNUNET_strdup ((const char *) &msg[1]);
311 if (NULL != tc_h->add_address_cb) 314 if (NULL != tc_h->add_address_cb)
312 { 315 {
313 LOG(GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available()\n"); 316 LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available()\n");
314 tc_h->add_address_cb(tc_h->cb_cls, 317 tc_h->add_address_cb (tc_h->cb_cls,
315 tc_h, 318 tc_h,
316 tc_h->c_address, 319 tc_h->c_address,
317 GNUNET_TIME_relative_ntoh(msg->expiration), 320 GNUNET_TIME_relative_ntoh (msg->expiration),
318 msg->aid, 321 msg->aid,
319 ntohl(msg->nt)); 322 ntohl (msg->nt));
320 } 323 }
321 GNUNET_SERVICE_client_continue(tc_h->client); 324 GNUNET_SERVICE_client_continue (tc_h->client);
322} 325}
323 326
324 327
@@ -330,17 +333,17 @@ handle_add_address(void *cls,
330 * @return #GNUNET_OK if message is well-formed 333 * @return #GNUNET_OK if message is well-formed
331 */ 334 */
332static int 335static int
333check_incoming_msg(void *cls, 336check_incoming_msg (void *cls,
334 const struct GNUNET_TRANSPORT_IncomingMessage *msg) 337 const struct GNUNET_TRANSPORT_IncomingMessage *msg)
335{ 338{
336 //struct TransportClient *tc = cls; 339 // struct TransportClient *tc = cls;
337 340
338 //if (CT_COMMUNICATOR != tc->type) 341 // if (CT_COMMUNICATOR != tc->type)
339 //{ 342 // {
340 // GNUNET_break (0); 343 // GNUNET_break (0);
341 // return GNUNET_SYSERR; 344 // return GNUNET_SYSERR;
342 //} 345 // }
343 GNUNET_MQ_check_boxed_message(msg); 346 GNUNET_MQ_check_boxed_message (msg);
344 return GNUNET_OK; 347 return GNUNET_OK;
345} 348}
346 349
@@ -354,23 +357,23 @@ check_incoming_msg(void *cls,
354 * @param msg Message 357 * @param msg Message
355 */ 358 */
356static void 359static void
357handle_incoming_msg(void *cls, 360handle_incoming_msg (void *cls,
358 const struct GNUNET_TRANSPORT_IncomingMessage *msg) 361 const struct GNUNET_TRANSPORT_IncomingMessage *msg)
359{ 362{
360 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 363 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
361 364
362 if (NULL != tc_h->incoming_msg_cb) 365 if (NULL != tc_h->incoming_msg_cb)
363 { 366 {
364 tc_h->incoming_msg_cb(tc_h->cb_cls, 367 tc_h->incoming_msg_cb (tc_h->cb_cls,
365 tc_h, 368 tc_h,
366 (const struct GNUNET_MessageHeader *)msg); 369 (const struct GNUNET_MessageHeader *) msg);
367 } 370 }
368 else 371 else
369 { 372 {
370 LOG(GNUNET_ERROR_TYPE_WARNING, 373 LOG (GNUNET_ERROR_TYPE_WARNING,
371 "Incoming message from communicator but no handler!\n"); 374 "Incoming message from communicator but no handler!\n");
372 } 375 }
373 GNUNET_SERVICE_client_continue(tc_h->client); 376 GNUNET_SERVICE_client_continue (tc_h->client);
374} 377}
375 378
376 379
@@ -381,16 +384,16 @@ handle_incoming_msg(void *cls,
381 * @param msg Message 384 * @param msg Message
382 */ 385 */
383static void 386static void
384handle_queue_create_ok(void *cls, 387handle_queue_create_ok (void *cls,
385 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) 388 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
386{ 389{
387 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 390 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
388 391
389 if (NULL != tc_h->queue_create_reply_cb) 392 if (NULL != tc_h->queue_create_reply_cb)
390 { 393 {
391 tc_h->queue_create_reply_cb(tc_h->cb_cls, tc_h, GNUNET_YES); 394 tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_YES);
392 } 395 }
393 GNUNET_SERVICE_client_continue(tc_h->client); 396 GNUNET_SERVICE_client_continue (tc_h->client);
394} 397}
395 398
396 399
@@ -404,17 +407,17 @@ handle_queue_create_ok(void *cls,
404 * @param msg Message 407 * @param msg Message
405 */ 408 */
406static void 409static void
407handle_queue_create_fail( 410handle_queue_create_fail (
408 void *cls, 411 void *cls,
409 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) 412 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
410{ 413{
411 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 414 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
412 415
413 if (NULL != tc_h->queue_create_reply_cb) 416 if (NULL != tc_h->queue_create_reply_cb)
414 { 417 {
415 tc_h->queue_create_reply_cb(tc_h->cb_cls, tc_h, GNUNET_NO); 418 tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_NO);
416 } 419 }
417 GNUNET_SERVICE_client_continue(tc_h->client); 420 GNUNET_SERVICE_client_continue (tc_h->client);
418} 421}
419 422
420 423
@@ -425,10 +428,10 @@ handle_queue_create_fail(
425 * @param aqm the send message that was sent 428 * @param aqm the send message that was sent
426 */ 429 */
427static int 430static int
428check_add_queue_message(void *cls, 431check_add_queue_message (void *cls,
429 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) 432 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
430{ 433{
431 GNUNET_MQ_check_zero_termination(aqm); 434 GNUNET_MQ_check_zero_termination (aqm);
432 return GNUNET_OK; 435 return GNUNET_OK;
433} 436}
434 437
@@ -442,27 +445,27 @@ check_add_queue_message(void *cls,
442 * @param msg Message struct 445 * @param msg Message struct
443 */ 446 */
444static void 447static void
445handle_add_queue_message(void *cls, 448handle_add_queue_message (void *cls,
446 const struct GNUNET_TRANSPORT_AddQueueMessage *msg) 449 const struct GNUNET_TRANSPORT_AddQueueMessage *msg)
447{ 450{
448 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 451 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
449 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue; 452 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue;
450 453
451 tc_queue = tc_h->queue_head; 454 tc_queue = tc_h->queue_head;
452 while (tc_queue->qid != msg->qid) 455 while (tc_queue->qid != msg->qid)
453 { 456 {
454 tc_queue = tc_queue->next; 457 tc_queue = tc_queue->next;
455 } 458 }
456 GNUNET_assert(tc_queue->qid == msg->qid); 459 GNUNET_assert (tc_queue->qid == msg->qid);
457 GNUNET_assert(0 == GNUNET_memcmp(&tc_queue->peer_id, &msg->receiver)); 460 GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver));
458 tc_queue->nt = msg->nt; 461 tc_queue->nt = msg->nt;
459 tc_queue->mtu = msg->mtu; 462 tc_queue->mtu = msg->mtu;
460 tc_queue->cs = msg->cs; 463 tc_queue->cs = msg->cs;
461 if (NULL != tc_h->add_queue_cb) 464 if (NULL != tc_h->add_queue_cb)
462 { 465 {
463 tc_h->add_queue_cb(tc_h->cb_cls, tc_h, tc_queue); 466 tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue);
464 } 467 }
465 GNUNET_SERVICE_client_continue(tc_h->client); 468 GNUNET_SERVICE_client_continue (tc_h->client);
466} 469}
467 470
468 471
@@ -472,11 +475,11 @@ handle_add_queue_message(void *cls,
472 * @param cls Closure - Handle to the service 475 * @param cls Closure - Handle to the service
473 */ 476 */
474static void 477static void
475shutdown_service(void *cls) 478shutdown_service (void *cls)
476{ 479{
477 struct GNUNET_SERVICE_Handle *h = cls; 480 struct GNUNET_SERVICE_Handle *h = cls;
478 481
479 GNUNET_SERVICE_stop(h); 482 GNUNET_SERVICE_stop (h);
480} 483}
481 484
482 485
@@ -490,14 +493,14 @@ shutdown_service(void *cls)
490 * @return TransportCommunicator Handle 493 * @return TransportCommunicator Handle
491 */ 494 */
492static void * 495static void *
493connect_cb(void *cls, 496connect_cb (void *cls,
494 struct GNUNET_SERVICE_Client *client, 497 struct GNUNET_SERVICE_Client *client,
495 struct GNUNET_MQ_Handle *mq) 498 struct GNUNET_MQ_Handle *mq)
496{ 499{
497 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 500 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
498 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter; 501 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter;
499 502
500 LOG(GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n"); 503 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n");
501 tc_h->client = client; 504 tc_h->client = client;
502 tc_h->c_mq = mq; 505 tc_h->c_mq = mq;
503 506
@@ -505,14 +508,14 @@ connect_cb(void *cls,
505 return tc_h; 508 return tc_h;
506 /* Iterate over queues. They are yet to be opened. Request opening. */ 509 /* Iterate over queues. They are yet to be opened. Request opening. */
507 while (NULL != (tc_queue_iter = tc_h->queue_head)) 510 while (NULL != (tc_queue_iter = tc_h->queue_head))
508 { 511 {
509 if (NULL == tc_queue_iter->open_queue_env) 512 if (NULL == tc_queue_iter->open_queue_env)
510 continue; 513 continue;
511 /* Send the previously created mq envelope to request the creation of the 514 /* Send the previously created mq envelope to request the creation of the
512 * queue. */ 515 * queue. */
513 GNUNET_MQ_send(tc_h->c_mq, tc_queue_iter->open_queue_env); 516 GNUNET_MQ_send (tc_h->c_mq, tc_queue_iter->open_queue_env);
514 tc_queue_iter->open_queue_env = NULL; 517 tc_queue_iter->open_queue_env = NULL;
515 } 518 }
516 return tc_h; 519 return tc_h;
517} 520}
518 521
@@ -525,13 +528,13 @@ connect_cb(void *cls,
525 * @param internal_cls TransporCommmunicator Handle 528 * @param internal_cls TransporCommmunicator Handle
526 */ 529 */
527static void 530static void
528disconnect_cb(void *cls, 531disconnect_cb (void *cls,
529 struct GNUNET_SERVICE_Client *client, 532 struct GNUNET_SERVICE_Client *client,
530 void *internal_cls) 533 void *internal_cls)
531{ 534{
532 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 535 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
533 536
534 LOG(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n"); 537 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n");
535 tc_h->client = NULL; 538 tc_h->client = NULL;
536} 539}
537 540
@@ -544,66 +547,66 @@ disconnect_cb(void *cls,
544 * @param cfg Configuration 547 * @param cfg Configuration
545 */ 548 */
546static void 549static void
547transport_communicator_start( 550transport_communicator_start (
548 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) 551 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
549{ 552{
550 struct GNUNET_MQ_MessageHandler mh[] = { 553 struct GNUNET_MQ_MessageHandler mh[] = {
551 GNUNET_MQ_hd_var_size(communicator_available, 554 GNUNET_MQ_hd_var_size (communicator_available,
552 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, 555 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR,
553 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, 556 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
554 &tc_h), 557 &tc_h),
555 //GNUNET_MQ_hd_var_size (communicator_backchannel, 558 // GNUNET_MQ_hd_var_size (communicator_backchannel,
556 // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, 559 // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
557 // struct GNUNET_TRANSPORT_CommunicatorBackchannel, 560 // struct GNUNET_TRANSPORT_CommunicatorBackchannel,
558 // NULL), 561 // NULL),
559 GNUNET_MQ_hd_var_size(add_address, 562 GNUNET_MQ_hd_var_size (add_address,
560 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, 563 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
561 struct GNUNET_TRANSPORT_AddAddressMessage, 564 struct GNUNET_TRANSPORT_AddAddressMessage,
562 &tc_h), 565 &tc_h),
563 //GNUNET_MQ_hd_fixed_size (del_address, 566 // GNUNET_MQ_hd_fixed_size (del_address,
564 // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, 567 // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
565 // struct GNUNET_TRANSPORT_DelAddressMessage, 568 // struct GNUNET_TRANSPORT_DelAddressMessage,
566 // NULL), 569 // NULL),
567 GNUNET_MQ_hd_var_size(incoming_msg, 570 GNUNET_MQ_hd_var_size (incoming_msg,
568 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, 571 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
569 struct GNUNET_TRANSPORT_IncomingMessage, 572 struct GNUNET_TRANSPORT_IncomingMessage,
570 NULL), 573 NULL),
571 GNUNET_MQ_hd_fixed_size(queue_create_ok, 574 GNUNET_MQ_hd_fixed_size (queue_create_ok,
572 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, 575 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
573 struct GNUNET_TRANSPORT_CreateQueueResponse, 576 struct GNUNET_TRANSPORT_CreateQueueResponse,
574 tc_h), 577 tc_h),
575 GNUNET_MQ_hd_fixed_size(queue_create_fail, 578 GNUNET_MQ_hd_fixed_size (queue_create_fail,
576 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, 579 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
577 struct GNUNET_TRANSPORT_CreateQueueResponse, 580 struct GNUNET_TRANSPORT_CreateQueueResponse,
578 tc_h), 581 tc_h),
579 GNUNET_MQ_hd_var_size(add_queue_message, 582 GNUNET_MQ_hd_var_size (add_queue_message,
580 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, 583 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
581 struct GNUNET_TRANSPORT_AddQueueMessage, 584 struct GNUNET_TRANSPORT_AddQueueMessage,
582 NULL), 585 NULL),
583 //GNUNET_MQ_hd_fixed_size (del_queue_message, 586 // GNUNET_MQ_hd_fixed_size (del_queue_message,
584 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, 587 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
585 // struct GNUNET_TRANSPORT_DelQueueMessage, 588 // struct GNUNET_TRANSPORT_DelQueueMessage,
586 // NULL), 589 // NULL),
587 //GNUNET_MQ_hd_fixed_size (send_message_ack, 590 // GNUNET_MQ_hd_fixed_size (send_message_ack,
588 // GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, 591 // GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK,
589 // struct GNUNET_TRANSPORT_SendMessageToAck, 592 // struct GNUNET_TRANSPORT_SendMessageToAck,
590 // NULL), 593 // NULL),
591 }; 594 };
592 struct GNUNET_SERVICE_Handle *h; 595 struct GNUNET_SERVICE_Handle *h;
593 596
594 h = GNUNET_SERVICE_start("transport", 597 h = GNUNET_SERVICE_start ("transport",
595 tc_h->cfg, 598 tc_h->cfg,
596 &connect_cb, 599 &connect_cb,
597 &disconnect_cb, 600 &disconnect_cb,
598 tc_h, 601 tc_h,
599 mh); 602 mh);
600 if (NULL == h) 603 if (NULL == h)
601 LOG(GNUNET_ERROR_TYPE_ERROR, "Failed starting service!\n"); 604 LOG (GNUNET_ERROR_TYPE_ERROR, "Failed starting service!\n");
602 else 605 else
603 { 606 {
604 LOG(GNUNET_ERROR_TYPE_DEBUG, "Started service\n"); 607 LOG (GNUNET_ERROR_TYPE_DEBUG, "Started service\n");
605 /* TODO */ GNUNET_SCHEDULER_add_shutdown(&shutdown_service, h); 608 /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h);
606 } 609 }
607} 610}
608 611
609 612
@@ -613,21 +616,21 @@ transport_communicator_start(
613 * @param cls Closure - Process of communicator 616 * @param cls Closure - Process of communicator
614 */ 617 */
615static void 618static void
616shutdown_communicator(void *cls) 619shutdown_communicator (void *cls)
617{ 620{
618 struct GNUNET_OS_Process *proc = cls; 621 struct GNUNET_OS_Process *proc = cls;
619 622
620 if (GNUNET_OK != GNUNET_OS_process_kill(proc, SIGTERM)) 623 if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGTERM))
624 {
625 LOG (GNUNET_ERROR_TYPE_WARNING,
626 "Error shutting down communicator with SIGERM, trying SIGKILL\n");
627 if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGKILL))
621 { 628 {
622 LOG(GNUNET_ERROR_TYPE_WARNING, 629 LOG (GNUNET_ERROR_TYPE_ERROR,
623 "Error shutting down communicator with SIGERM, trying SIGKILL\n"); 630 "Error shutting down communicator with SIGERM and SIGKILL\n");
624 if (GNUNET_OK != GNUNET_OS_process_kill(proc, SIGKILL))
625 {
626 LOG(GNUNET_ERROR_TYPE_ERROR,
627 "Error shutting down communicator with SIGERM and SIGKILL\n");
628 }
629 } 631 }
630 GNUNET_OS_process_destroy(proc); 632 }
633 GNUNET_OS_process_destroy (proc);
631} 634}
632 635
633 636
@@ -637,33 +640,33 @@ shutdown_communicator(void *cls)
637 * @param cfgname Name of the communicator 640 * @param cfgname Name of the communicator
638 */ 641 */
639static void 642static void
640communicator_start( 643communicator_start (
641 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 644 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
642 const char *binary_name) 645 const char *binary_name)
643{ 646{
644 char *binary; 647 char *binary;
645 648
646 LOG(GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n"); 649 LOG (GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n");
647 binary = GNUNET_OS_get_libexec_binary_path(binary_name); 650 binary = GNUNET_OS_get_libexec_binary_path (binary_name);
648 tc_h->c_proc = GNUNET_OS_start_process(GNUNET_YES, 651 tc_h->c_proc = GNUNET_OS_start_process (GNUNET_YES,
649 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 652 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
650 NULL, 653 NULL,
651 NULL, 654 NULL,
652 NULL, 655 NULL,
653 binary, 656 binary,
654 binary_name, 657 binary_name,
655 "-c", 658 "-c",
656 tc_h->cfg_filename, 659 tc_h->cfg_filename,
657 NULL); 660 NULL);
658 if (NULL == tc_h->c_proc) 661 if (NULL == tc_h->c_proc)
659 { 662 {
660 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!"); 663 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!");
661 return; 664 return;
662 } 665 }
663 LOG(GNUNET_ERROR_TYPE_DEBUG, "started communicator\n"); 666 LOG (GNUNET_ERROR_TYPE_DEBUG, "started communicator\n");
664 GNUNET_free(binary); 667 GNUNET_free (binary);
665 /* TODO */ GNUNET_SCHEDULER_add_shutdown(&shutdown_communicator, 668 /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_communicator,
666 tc_h->c_proc); 669 tc_h->c_proc);
667} 670}
668 671
669 672
@@ -680,7 +683,7 @@ communicator_start(
680 * @return Handle to the communicator duo 683 * @return Handle to the communicator duo
681 */ 684 */
682struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * 685struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
683GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( 686GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
684 const char *service_name, 687 const char *service_name,
685 const char *binary_name, 688 const char *binary_name,
686 const char *cfg_filename, 689 const char *cfg_filename,
@@ -695,19 +698,19 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(
695 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; 698 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h;
696 699
697 tc_h = 700 tc_h =
698 GNUNET_new(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle); 701 GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle);
699 tc_h->cfg_filename = GNUNET_strdup(cfg_filename); 702 tc_h->cfg_filename = GNUNET_strdup (cfg_filename);
700 tc_h->cfg = GNUNET_CONFIGURATION_create(); 703 tc_h->cfg = GNUNET_CONFIGURATION_create ();
701 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load(tc_h->cfg, cfg_filename))) 704 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load (tc_h->cfg, cfg_filename)))
702 { 705 {
703 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 706 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
704 _("Malformed configuration file `%s', exit ...\n"), 707 _ ("Malformed configuration file `%s', exit ...\n"),
705 cfg_filename); 708 cfg_filename);
706 GNUNET_free(tc_h->cfg_filename); 709 GNUNET_free (tc_h->cfg_filename);
707 GNUNET_CONFIGURATION_destroy(tc_h->cfg); 710 GNUNET_CONFIGURATION_destroy (tc_h->cfg);
708 GNUNET_free(tc_h); 711 GNUNET_free (tc_h);
709 return NULL; 712 return NULL;
710 } 713 }
711 tc_h->communicator_available_cb = communicator_available_cb; 714 tc_h->communicator_available_cb = communicator_available_cb;
712 tc_h->add_address_cb = add_address_cb; 715 tc_h->add_address_cb = add_address_cb;
713 tc_h->queue_create_reply_cb = queue_create_reply_cb; 716 tc_h->queue_create_reply_cb = queue_create_reply_cb;
@@ -716,11 +719,11 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(
716 tc_h->cb_cls = cb_cls; 719 tc_h->cb_cls = cb_cls;
717 720
718 /* Start communicator part of service */ 721 /* Start communicator part of service */
719 transport_communicator_start(tc_h); 722 transport_communicator_start (tc_h);
720 723
721 /* Schedule start communicator */ 724 /* Schedule start communicator */
722 communicator_start(tc_h, 725 communicator_start (tc_h,
723 binary_name); 726 binary_name);
724 return tc_h; 727 return tc_h;
725} 728}
726 729
@@ -733,7 +736,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(
733 * @param address For which address 736 * @param address For which address
734 */ 737 */
735void 738void
736GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue( 739GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (
737 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 740 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
738 const struct GNUNET_PeerIdentity *peer_id, 741 const struct GNUNET_PeerIdentity *peer_id,
739 const char *address) 742 const char *address)
@@ -746,33 +749,33 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(
746 size_t alen; 749 size_t alen;
747 750
748 tc_queue = 751 tc_queue =
749 GNUNET_new(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); 752 GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue);
750 tc_queue->tc_h = tc_h; 753 tc_queue->tc_h = tc_h;
751 prefix = GNUNET_HELLO_address_to_prefix(address); 754 prefix = GNUNET_HELLO_address_to_prefix (address);
752 if (NULL == prefix) 755 if (NULL == prefix)
753 { 756 {
754 GNUNET_break(0); /* We got an invalid address!? */ 757 GNUNET_break (0); /* We got an invalid address!? */
755 GNUNET_free(tc_queue); 758 GNUNET_free (tc_queue);
756 return; 759 return;
757 } 760 }
758 GNUNET_free(prefix); 761 GNUNET_free (prefix);
759 alen = strlen(address) + 1; 762 alen = strlen (address) + 1;
760 env = 763 env =
761 GNUNET_MQ_msg_extra(msg, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); 764 GNUNET_MQ_msg_extra (msg, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
762 msg->request_id = htonl(idgen++); 765 msg->request_id = htonl (idgen++);
763 tc_queue->qid = msg->request_id; 766 tc_queue->qid = msg->request_id;
764 msg->receiver = *peer_id; 767 msg->receiver = *peer_id;
765 tc_queue->peer_id = *peer_id; 768 tc_queue->peer_id = *peer_id;
766 memcpy(&msg[1], address, alen); 769 memcpy (&msg[1], address, alen);
767 if (NULL != tc_h->c_mq) 770 if (NULL != tc_h->c_mq)
768 { 771 {
769 GNUNET_MQ_send(tc_h->c_mq, env); 772 GNUNET_MQ_send (tc_h->c_mq, env);
770 } 773 }
771 else 774 else
772 { 775 {
773 tc_queue->open_queue_env = env; 776 tc_queue->open_queue_env = env;
774 } 777 }
775 GNUNET_CONTAINER_DLL_insert(tc_h->queue_head, tc_h->queue_tail, tc_queue); 778 GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue);
776} 779}
777 780
778 781
@@ -800,20 +803,20 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send
800 size_t inbox_size; 803 size_t inbox_size;
801 804
802 inbox_size = sizeof(struct GNUNET_MessageHeader) + payload_size; 805 inbox_size = sizeof(struct GNUNET_MessageHeader) + payload_size;
803 mh = GNUNET_malloc(inbox_size); 806 mh = GNUNET_malloc (inbox_size);
804 mh->size = htons(inbox_size); 807 mh->size = htons (inbox_size);
805 mh->type = GNUNET_MESSAGE_TYPE_DUMMY; 808 mh->type = GNUNET_MESSAGE_TYPE_DUMMY;
806 memcpy(&mh[1], 809 memcpy (&mh[1],
807 payload, 810 payload,
808 payload_size); 811 payload_size);
809 env = GNUNET_MQ_msg_extra(msg, 812 env = GNUNET_MQ_msg_extra (msg,
810 inbox_size, 813 inbox_size,
811 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); 814 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG);
812 msg->qid = htonl(tc_queue->qid); 815 msg->qid = htonl (tc_queue->qid);
813 msg->mid = tc_queue->mid++; 816 msg->mid = tc_queue->mid++;
814 msg->receiver = tc_queue->peer_id; 817 msg->receiver = tc_queue->peer_id;
815 memcpy(&msg[1], mh, inbox_size); 818 memcpy (&msg[1], mh, inbox_size);
816 GNUNET_free(mh); 819 GNUNET_free (mh);
817 GNUNET_MQ_send(tc_queue->tc_h->c_mq, env); 820 GNUNET_MQ_send (tc_queue->tc_h->c_mq, env);
818 return tc_t; 821 return tc_t;
819} 822}
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;
59 */ 59 */
60typedef void 60typedef void
61(*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls, 61(*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls,
62 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 62 struct
63 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, 63 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
64 *tc_h,
65 enum
66 GNUNET_TRANSPORT_CommunicatorCharacteristics
67 cc,
64 char *address_prefix); 68 char *address_prefix);
65 69
66 70
@@ -76,9 +80,12 @@ typedef void
76 */ 80 */
77typedef void 81typedef void
78(*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls, 82(*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls,
79 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 83 struct
84 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
85 *tc_h,
80 const char *address, 86 const char *address,
81 struct GNUNET_TIME_Relative expiration, 87 struct GNUNET_TIME_Relative
88 expiration,
82 uint32_t aid, 89 uint32_t aid,
83 enum GNUNET_NetworkType nt); 90 enum GNUNET_NetworkType nt);
84 91
@@ -92,7 +99,9 @@ typedef void
92 */ 99 */
93typedef void 100typedef void
94(*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls, 101(*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls,
95 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 102 struct
103 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
104 *tc_h,
96 int will_try); 105 int will_try);
97 106
98 107
@@ -105,8 +114,12 @@ typedef void
105 */ 114 */
106typedef void 115typedef void
107(*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls, 116(*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls,
108 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 117 struct
109 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue); 118 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
119 *tc_h,
120 struct
121 GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
122 *tc_queue);
110 123
111 124
112/** 125/**
@@ -118,8 +131,11 @@ typedef void
118 */ 131 */
119typedef void 132typedef void
120(*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls, 133(*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls,
121 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 134 struct
122 const struct GNUNET_MessageHeader *msg); 135 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
136 *tc_h,
137 const struct
138 GNUNET_MessageHeader *msg);
123 139
124 140
125/** 141/**
@@ -138,11 +154,12 @@ typedef void
138 * @return Handle to the communicator duo 154 * @return Handle to the communicator duo
139 */ 155 */
140struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * 156struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
141GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( 157GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
142 const char *service_name, 158 const char *service_name,
143 const char *binary_name, 159 const char *binary_name,
144 const char *cfg_filename, 160 const char *cfg_filename,
145 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb, 161 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
162 communicator_available_cb,
146 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, 163 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
147 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, 164 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb,
148 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, 165 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb,
@@ -158,10 +175,13 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(
158 * @param address For which address 175 * @param address For which address
159 */ 176 */
160void 177void
161GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue 178GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (struct
162 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 179 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
163 const struct GNUNET_PeerIdentity *peer_id, 180 *tc_h,
164 const char *address); 181 const struct
182 GNUNET_PeerIdentity
183 *peer_id,
184 const char *address);
165 185
166 186
167/** 187/**
@@ -174,10 +194,10 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
174 * @return Handle to the transmission 194 * @return Handle to the transmission
175 */ 195 */
176struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * 196struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
177GNUNET_TRANSPORT_TESTING_transport_communicator_send 197GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct
178 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue, 198 GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
179 const void *payload, 199 *tc_queue,
180 size_t payload_size /*, 200 const void *payload,
201 size_t payload_size /*,
181 GNUNET_TRANSPORT_TESTING_SuccessStatus cb, 202 GNUNET_TRANSPORT_TESTING_SuccessStatus cb,
182 void *cb_cls*/); 203 void *cb_cls*/ );
183
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 @@
55 * Maximum frequency for re-evaluating latencies for all transport addresses. 55 * Maximum frequency for re-evaluating latencies for all transport addresses.
56 */ 56 */
57#define LATENCY_EVALUATION_MAX_DELAY \ 57#define LATENCY_EVALUATION_MAX_DELAY \
58 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 1) 58 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
59 59
60/** 60/**
61 * Maximum frequency for re-evaluating latencies for connected addresses. 61 * Maximum frequency for re-evaluating latencies for connected addresses.
62 */ 62 */
63#define CONNECTED_LATENCY_EVALUATION_MAX_DELAY \ 63#define CONNECTED_LATENCY_EVALUATION_MAX_DELAY \
64 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) 64 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
65 65
66/** 66/**
67 * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are 67 * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are
@@ -88,7 +88,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
88 * asking to check if both processes agree about this 88 * asking to check if both processes agree about this
89 * peers identity. 89 * peers identity.
90 */ 90 */
91struct StartMessage { 91struct StartMessage
92{
92 /** 93 /**
93 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_START 94 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_START
94 */ 95 */
@@ -113,7 +114,8 @@ struct StartMessage {
113 * Message from the transport service to the library 114 * Message from the transport service to the library
114 * informing about neighbors. 115 * informing about neighbors.
115 */ 116 */
116struct ConnectInfoMessage { 117struct ConnectInfoMessage
118{
117 /** 119 /**
118 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT 120 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
119 */ 121 */
@@ -144,7 +146,8 @@ struct ConnectInfoMessage {
144 * Message from the transport service to the library 146 * Message from the transport service to the library
145 * informing about disconnects. 147 * informing about disconnects.
146 */ 148 */
147struct DisconnectInfoMessage { 149struct DisconnectInfoMessage
150{
148 /** 151 /**
149 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT 152 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
150 */ 153 */
@@ -169,7 +172,8 @@ struct DisconnectInfoMessage {
169 * 172 *
170 * NOTE: no longer used in TNG! 173 * NOTE: no longer used in TNG!
171 */ 174 */
172struct QuotaSetMessage { 175struct QuotaSetMessage
176{
173 /** 177 /**
174 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA 178 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
175 */ 179 */
@@ -191,7 +195,8 @@ struct QuotaSetMessage {
191 * Message used to notify the transport API about a message 195 * Message used to notify the transport API about a message
192 * received from the network. The actual message follows. 196 * received from the network. The actual message follows.
193 */ 197 */
194struct InboundMessage { 198struct InboundMessage
199{
195 /** 200 /**
196 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV 201 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
197 */ 202 */
@@ -208,7 +213,8 @@ struct InboundMessage {
208 * Message used to notify the transport API that it can 213 * Message used to notify the transport API that it can
209 * send another message to the transport service. 214 * send another message to the transport service.
210 */ 215 */
211struct SendOkMessage { 216struct SendOkMessage
217{
212 /** 218 /**
213 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK 219 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
214 */ 220 */
@@ -251,7 +257,8 @@ struct SendOkMessage {
251 * send another message to the transport service. 257 * send another message to the transport service.
252 * (Used to implement flow control.) 258 * (Used to implement flow control.)
253 */ 259 */
254struct RecvOkMessage { 260struct RecvOkMessage
261{
255 /** 262 /**
256 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK 263 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK
257 */ 264 */
@@ -274,7 +281,8 @@ struct RecvOkMessage {
274 * Message used to notify the transport service about a message 281 * Message used to notify the transport service about a message
275 * to be transmitted to another peer. The actual message follows. 282 * to be transmitted to another peer. The actual message follows.
276 */ 283 */
277struct OutboundMessage { 284struct OutboundMessage
285{
278 /** 286 /**
279 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND 287 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
280 */ 288 */
@@ -285,7 +293,7 @@ struct OutboundMessage {
285 */ 293 */
286 uint32_t priority GNUNET_PACKED; 294 uint32_t priority GNUNET_PACKED;
287 295
288#if !(defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ 296#if ! (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \
289 defined(GNUNET_TRANSPORT_CORE_VERSION)) 297 defined(GNUNET_TRANSPORT_CORE_VERSION))
290 298
291 /** 299 /**
@@ -301,7 +309,7 @@ struct OutboundMessage {
301}; 309};
302 310
303 311
304#if !(defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ 312#if ! (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \
305 defined(GNUNET_TRANSPORT_CORE_VERSION)) 313 defined(GNUNET_TRANSPORT_CORE_VERSION))
306 314
307 315
@@ -312,7 +320,8 @@ struct OutboundMessage {
312 * last message must have a @e res of #GNUNET_OK and an @e addr_len 320 * last message must have a @e res of #GNUNET_OK and an @e addr_len
313 * of zero. 321 * of zero.
314 */ 322 */
315struct AddressToStringResultMessage { 323struct AddressToStringResultMessage
324{
316 /** 325 /**
317 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY 326 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
318 */ 327 */
@@ -336,7 +345,8 @@ struct AddressToStringResultMessage {
336 * asking for converting a transport address to a 345 * asking for converting a transport address to a
337 * human-readable UTF-8 string. 346 * human-readable UTF-8 string.
338 */ 347 */
339struct AddressLookupMessage { 348struct AddressLookupMessage
349{
340 /** 350 /**
341 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING 351 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
342 */ 352 */
@@ -373,7 +383,8 @@ struct AddressLookupMessage {
373 * Memory layout: 383 * Memory layout:
374 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]] 384 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
375 */ 385 */
376struct ValidationIterateResponseMessage { 386struct ValidationIterateResponseMessage
387{
377 /** 388 /**
378 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE 389 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE
379 */ 390 */
@@ -433,7 +444,8 @@ struct ValidationIterateResponseMessage {
433 * Message from the library to the transport service 444 * Message from the library to the transport service
434 * asking for binary addresses known for a peer. 445 * asking for binary addresses known for a peer.
435 */ 446 */
436struct ValidationMonitorMessage { 447struct ValidationMonitorMessage
448{
437 /** 449 /**
438 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST 450 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
439 */ 451 */
@@ -455,7 +467,8 @@ struct ValidationMonitorMessage {
455 * Message from the library to the transport service 467 * Message from the library to the transport service
456 * asking for binary addresses known for a peer. 468 * asking for binary addresses known for a peer.
457 */ 469 */
458struct PeerMonitorMessage { 470struct PeerMonitorMessage
471{
459 /** 472 /**
460 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST 473 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
461 */ 474 */
@@ -477,7 +490,8 @@ struct PeerMonitorMessage {
477 * Message from the library to the transport service 490 * Message from the library to the transport service
478 * asking for binary addresses known for a peer. 491 * asking for binary addresses known for a peer.
479 */ 492 */
480struct TrafficMetricMessage { 493struct TrafficMetricMessage
494{
481 /** 495 /**
482 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC 496 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
483 */ 497 */
@@ -520,7 +534,8 @@ struct TrafficMetricMessage {
520 * Memory layout: 534 * Memory layout:
521 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]] 535 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
522 */ 536 */
523struct PeerIterateResponseMessage { 537struct PeerIterateResponseMessage
538{
524 /** 539 /**
525 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE 540 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
526 */ 541 */
@@ -567,7 +582,8 @@ struct PeerIterateResponseMessage {
567 * Change in blacklisting (either request or notification, 582 * Change in blacklisting (either request or notification,
568 * depending on which direction it is going). 583 * depending on which direction it is going).
569 */ 584 */
570struct BlacklistMessage { 585struct BlacklistMessage
586{
571 /** 587 /**
572 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or 588 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
573 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY. 589 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
@@ -590,7 +606,8 @@ struct BlacklistMessage {
590/** 606/**
591 * Transport-level connection status update. 607 * Transport-level connection status update.
592 */ 608 */
593struct TransportPluginMonitorMessage { 609struct TransportPluginMonitorMessage
610{
594 /** 611 /**
595 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT. 612 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT.
596 */ 613 */
@@ -663,7 +680,8 @@ struct TransportPluginMonitorMessage {
663 * Communicator goes online. Note which addresses it can 680 * Communicator goes online. Note which addresses it can
664 * work with. 681 * work with.
665 */ 682 */
666struct GNUNET_TRANSPORT_CommunicatorAvailableMessage { 683struct GNUNET_TRANSPORT_CommunicatorAvailableMessage
684{
667 /** 685 /**
668 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR. 686 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR.
669 */ 687 */
@@ -681,7 +699,8 @@ struct GNUNET_TRANSPORT_CommunicatorAvailableMessage {
681/** 699/**
682 * Add address to the list. 700 * Add address to the list.
683 */ 701 */
684struct GNUNET_TRANSPORT_AddAddressMessage { 702struct GNUNET_TRANSPORT_AddAddressMessage
703{
685 /** 704 /**
686 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS. 705 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS.
687 */ 706 */
@@ -709,7 +728,8 @@ struct GNUNET_TRANSPORT_AddAddressMessage {
709/** 728/**
710 * Remove address from the list. 729 * Remove address from the list.
711 */ 730 */
712struct GNUNET_TRANSPORT_DelAddressMessage { 731struct GNUNET_TRANSPORT_DelAddressMessage
732{
713 /** 733 /**
714 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS. 734 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS.
715 */ 735 */
@@ -725,7 +745,8 @@ struct GNUNET_TRANSPORT_DelAddressMessage {
725/** 745/**
726 * Inform transport about an incoming message. 746 * Inform transport about an incoming message.
727 */ 747 */
728struct GNUNET_TRANSPORT_IncomingMessage { 748struct GNUNET_TRANSPORT_IncomingMessage
749{
729 /** 750 /**
730 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG. 751 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG.
731 */ 752 */
@@ -760,7 +781,8 @@ struct GNUNET_TRANSPORT_IncomingMessage {
760 * Transport informs us about being done with an incoming message. 781 * Transport informs us about being done with an incoming message.
761 * (only sent if fc_on was set). 782 * (only sent if fc_on was set).
762 */ 783 */
763struct GNUNET_TRANSPORT_IncomingMessageAck { 784struct GNUNET_TRANSPORT_IncomingMessageAck
785{
764 /** 786 /**
765 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK. 787 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK.
766 */ 788 */
@@ -786,7 +808,8 @@ struct GNUNET_TRANSPORT_IncomingMessageAck {
786/** 808/**
787 * Add queue to the transport 809 * Add queue to the transport
788 */ 810 */
789struct GNUNET_TRANSPORT_AddQueueMessage { 811struct GNUNET_TRANSPORT_AddQueueMessage
812{
790 /** 813 /**
791 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP. 814 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP.
792 */ 815 */
@@ -824,7 +847,8 @@ struct GNUNET_TRANSPORT_AddQueueMessage {
824/** 847/**
825 * Remove queue, it is no longer available. 848 * Remove queue, it is no longer available.
826 */ 849 */
827struct GNUNET_TRANSPORT_DelQueueMessage { 850struct GNUNET_TRANSPORT_DelQueueMessage
851{
828 /** 852 /**
829 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN. 853 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN.
830 */ 854 */
@@ -845,7 +869,8 @@ struct GNUNET_TRANSPORT_DelQueueMessage {
845/** 869/**
846 * Transport tells communicator that it wants a new queue. 870 * Transport tells communicator that it wants a new queue.
847 */ 871 */
848struct GNUNET_TRANSPORT_CreateQueue { 872struct GNUNET_TRANSPORT_CreateQueue
873{
849 /** 874 /**
850 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE. 875 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE.
851 */ 876 */
@@ -868,7 +893,8 @@ struct GNUNET_TRANSPORT_CreateQueue {
868/** 893/**
869 * Communicator tells transport how queue creation went down. 894 * Communicator tells transport how queue creation went down.
870 */ 895 */
871struct GNUNET_TRANSPORT_CreateQueueResponse { 896struct GNUNET_TRANSPORT_CreateQueueResponse
897{
872 /** 898 /**
873 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK or 899 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK or
874 * #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL. 900 * #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL.
@@ -885,7 +911,8 @@ struct GNUNET_TRANSPORT_CreateQueueResponse {
885/** 911/**
886 * Inform communicator about transport's desire to send a message. 912 * Inform communicator about transport's desire to send a message.
887 */ 913 */
888struct GNUNET_TRANSPORT_SendMessageTo { 914struct GNUNET_TRANSPORT_SendMessageTo
915{
889 /** 916 /**
890 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG. 917 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG.
891 */ 918 */
@@ -913,7 +940,8 @@ struct GNUNET_TRANSPORT_SendMessageTo {
913/** 940/**
914 * Inform transport that message was sent. 941 * Inform transport that message was sent.
915 */ 942 */
916struct GNUNET_TRANSPORT_SendMessageToAck { 943struct GNUNET_TRANSPORT_SendMessageToAck
944{
917 /** 945 /**
918 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK. 946 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK.
919 */ 947 */
@@ -941,7 +969,8 @@ struct GNUNET_TRANSPORT_SendMessageToAck {
941 * transmission of a backchannel message with the given peer @e pid 969 * transmission of a backchannel message with the given peer @e pid
942 * and communicator. 970 * and communicator.
943 */ 971 */
944struct GNUNET_TRANSPORT_CommunicatorBackchannel { 972struct GNUNET_TRANSPORT_CommunicatorBackchannel
973{
945 /** 974 /**
946 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL 975 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL
947 */ 976 */
@@ -969,7 +998,8 @@ struct GNUNET_TRANSPORT_CommunicatorBackchannel {
969 * Message from transport to communicator passing along a backchannel 998 * Message from transport to communicator passing along a backchannel
970 * message from the given peer @e pid. 999 * message from the given peer @e pid.
971 */ 1000 */
972struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming { 1001struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming
1002{
973 /** 1003 /**
974 * Type will be 1004 * Type will be
975 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING 1005 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING
@@ -994,7 +1024,8 @@ struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming {
994/** 1024/**
995 * Request to start monitoring. 1025 * Request to start monitoring.
996 */ 1026 */
997struct GNUNET_TRANSPORT_MonitorStart { 1027struct GNUNET_TRANSPORT_MonitorStart
1028{
998 /** 1029 /**
999 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START. 1030 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START.
1000 */ 1031 */
@@ -1015,7 +1046,8 @@ struct GNUNET_TRANSPORT_MonitorStart {
1015/** 1046/**
1016 * Monitoring data. 1047 * Monitoring data.
1017 */ 1048 */
1018struct GNUNET_TRANSPORT_MonitorData { 1049struct GNUNET_TRANSPORT_MonitorData
1050{
1019 /** 1051 /**
1020 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA. 1052 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA.
1021 */ 1053 */
@@ -1065,7 +1097,8 @@ struct GNUNET_TRANSPORT_MonitorData {
1065/** 1097/**
1066 * Request to verify address. 1098 * Request to verify address.
1067 */ 1099 */
1068struct GNUNET_TRANSPORT_AddressToVerify { 1100struct GNUNET_TRANSPORT_AddressToVerify
1101{
1069 /** 1102 /**
1070 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY. 1103 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY.
1071 */ 1104 */
@@ -1089,7 +1122,8 @@ struct GNUNET_TRANSPORT_AddressToVerify {
1089 * Application client to TRANSPORT service: we would like to have 1122 * Application client to TRANSPORT service: we would like to have
1090 * address suggestions for this peer. 1123 * address suggestions for this peer.
1091 */ 1124 */
1092struct ExpressPreferenceMessage { 1125struct ExpressPreferenceMessage
1126{
1093 /** 1127 /**
1094 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST or 1128 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST or
1095 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL to stop 1129 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL to stop
@@ -1119,7 +1153,8 @@ struct ExpressPreferenceMessage {
1119 * We got an address of another peer, TRANSPORT service 1153 * We got an address of another peer, TRANSPORT service
1120 * should validate it. There is no response. 1154 * should validate it. There is no response.
1121 */ 1155 */
1122struct RequestHelloValidationMessage { 1156struct RequestHelloValidationMessage
1157{
1123 /** 1158 /**
1124 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION. 1159 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION.
1125 */ 1160 */
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 @@
30 30
31 31
32#define LOG(kind, ...) \ 32#define LOG(kind, ...) \
33 GNUNET_log_from(kind, "transport-application-api", __VA_ARGS__) 33 GNUNET_log_from (kind, "transport-application-api", __VA_ARGS__)
34 34
35 35
36/** 36/**
37 * Handle for TRANSPORT address suggestion requests. 37 * Handle for TRANSPORT address suggestion requests.
38 */ 38 */
39struct GNUNET_TRANSPORT_ApplicationSuggestHandle { 39struct GNUNET_TRANSPORT_ApplicationSuggestHandle
40{
40 /** 41 /**
41 * ID of the peer for which address suggestion was requested. 42 * ID of the peer for which address suggestion was requested.
42 */ 43 */
@@ -62,7 +63,8 @@ struct GNUNET_TRANSPORT_ApplicationSuggestHandle {
62/** 63/**
63 * Handle to the TRANSPORT subsystem for application management. 64 * Handle to the TRANSPORT subsystem for application management.
64 */ 65 */
65struct GNUNET_TRANSPORT_ApplicationHandle { 66struct GNUNET_TRANSPORT_ApplicationHandle
67{
66 /** 68 /**
67 * Our configuration. 69 * Our configuration.
68 */ 70 */
@@ -98,7 +100,7 @@ struct GNUNET_TRANSPORT_ApplicationHandle {
98 * @param ch handle to use to re-connect. 100 * @param ch handle to use to re-connect.
99 */ 101 */
100static void 102static void
101reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch); 103reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch);
102 104
103 105
104/** 106/**
@@ -107,12 +109,12 @@ reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch);
107 * @param cls handle to use to re-connect. 109 * @param cls handle to use to re-connect.
108 */ 110 */
109static void 111static void
110reconnect_task(void *cls) 112reconnect_task (void *cls)
111{ 113{
112 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; 114 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls;
113 115
114 ch->task = NULL; 116 ch->task = NULL;
115 reconnect(ch); 117 reconnect (ch);
116} 118}
117 119
118 120
@@ -122,15 +124,15 @@ reconnect_task(void *cls)
122 * @param ch our handle 124 * @param ch our handle
123 */ 125 */
124static void 126static void
125force_reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch) 127force_reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
126{ 128{
127 if (NULL != ch->mq) 129 if (NULL != ch->mq)
128 { 130 {
129 GNUNET_MQ_destroy(ch->mq); 131 GNUNET_MQ_destroy (ch->mq);
130 ch->mq = NULL; 132 ch->mq = NULL;
131 } 133 }
132 ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff); 134 ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
133 ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff, &reconnect_task, ch); 135 ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, &reconnect_task, ch);
134} 136}
135 137
136 138
@@ -142,14 +144,14 @@ force_reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
142 * @param error details about the error 144 * @param error details about the error
143 */ 145 */
144static void 146static void
145error_handler(void *cls, enum GNUNET_MQ_Error error) 147error_handler (void *cls, enum GNUNET_MQ_Error error)
146{ 148{
147 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; 149 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls;
148 150
149 LOG(GNUNET_ERROR_TYPE_DEBUG, 151 LOG (GNUNET_ERROR_TYPE_DEBUG,
150 "TRANSPORT connection died (code %d), reconnecting\n", 152 "TRANSPORT connection died (code %d), reconnecting\n",
151 (int)error); 153 (int) error);
152 force_reconnect(ch); 154 force_reconnect (ch);
153} 155}
154 156
155 157
@@ -163,9 +165,9 @@ error_handler(void *cls, enum GNUNET_MQ_Error error)
163 * failure (message queue no longer exists) 165 * failure (message queue no longer exists)
164 */ 166 */
165static int 167static int
166transmit_suggestion(void *cls, 168transmit_suggestion (void *cls,
167 const struct GNUNET_PeerIdentity *peer, 169 const struct GNUNET_PeerIdentity *peer,
168 void *value) 170 void *value)
169{ 171{
170 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; 172 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls;
171 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh = value; 173 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh = value;
@@ -174,11 +176,11 @@ transmit_suggestion(void *cls,
174 176
175 if (NULL == ch->mq) 177 if (NULL == ch->mq)
176 return GNUNET_SYSERR; 178 return GNUNET_SYSERR;
177 ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST); 179 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST);
178 m->pk = htonl((uint32_t)sh->pk); 180 m->pk = htonl ((uint32_t) sh->pk);
179 m->bw = sh->bw; 181 m->bw = sh->bw;
180 m->peer = *peer; 182 m->peer = *peer;
181 GNUNET_MQ_send(ch->mq, ev); 183 GNUNET_MQ_send (ch->mq, ev);
182 return GNUNET_OK; 184 return GNUNET_OK;
183} 185}
184 186
@@ -189,21 +191,21 @@ transmit_suggestion(void *cls,
189 * @param ch handle to use to re-connect. 191 * @param ch handle to use to re-connect.
190 */ 192 */
191static void 193static void
192reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch) 194reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
193{ 195{
194 static const struct GNUNET_MQ_MessageHandler handlers[] = { { NULL, 0, 0 } }; 196 static const struct GNUNET_MQ_MessageHandler handlers[] = { { NULL, 0, 0 } };
195 197
196 GNUNET_assert(NULL == ch->mq); 198 GNUNET_assert (NULL == ch->mq);
197 ch->mq = 199 ch->mq =
198 GNUNET_CLIENT_connect(ch->cfg, "transport", handlers, &error_handler, ch); 200 GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch);
199 if (NULL == ch->mq) 201 if (NULL == ch->mq)
200 { 202 {
201 force_reconnect(ch); 203 force_reconnect (ch);
202 return; 204 return;
203 } 205 }
204 GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, 206 GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests,
205 &transmit_suggestion, 207 &transmit_suggestion,
206 ch); 208 ch);
207} 209}
208 210
209 211
@@ -214,15 +216,15 @@ reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
214 * @return transport application handle, NULL on error 216 * @return transport application handle, NULL on error
215 */ 217 */
216struct GNUNET_TRANSPORT_ApplicationHandle * 218struct GNUNET_TRANSPORT_ApplicationHandle *
217GNUNET_TRANSPORT_application_init( 219GNUNET_TRANSPORT_application_init (
218 const struct GNUNET_CONFIGURATION_Handle *cfg) 220 const struct GNUNET_CONFIGURATION_Handle *cfg)
219{ 221{
220 struct GNUNET_TRANSPORT_ApplicationHandle *ch; 222 struct GNUNET_TRANSPORT_ApplicationHandle *ch;
221 223
222 ch = GNUNET_new(struct GNUNET_TRANSPORT_ApplicationHandle); 224 ch = GNUNET_new (struct GNUNET_TRANSPORT_ApplicationHandle);
223 ch->cfg = cfg; 225 ch->cfg = cfg;
224 ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES); 226 ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES);
225 reconnect(ch); 227 reconnect (ch);
226 return ch; 228 return ch;
227} 229}
228 230
@@ -237,11 +239,11 @@ GNUNET_TRANSPORT_application_init(
237 * @return #GNUNET_OK (continue to iterate) 239 * @return #GNUNET_OK (continue to iterate)
238 */ 240 */
239static int 241static int
240free_sug_handle(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 242free_sug_handle (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
241{ 243{
242 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *cur = value; 244 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *cur = value;
243 245
244 GNUNET_free(cur); 246 GNUNET_free (cur);
245 return GNUNET_OK; 247 return GNUNET_OK;
246} 248}
247 249
@@ -252,24 +254,24 @@ free_sug_handle(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
252 * @param ch handle to release 254 * @param ch handle to release
253 */ 255 */
254void 256void
255GNUNET_TRANSPORT_application_done( 257GNUNET_TRANSPORT_application_done (
256 struct GNUNET_TRANSPORT_ApplicationHandle *ch) 258 struct GNUNET_TRANSPORT_ApplicationHandle *ch)
257{ 259{
258 if (NULL != ch->mq) 260 if (NULL != ch->mq)
259 { 261 {
260 GNUNET_MQ_destroy(ch->mq); 262 GNUNET_MQ_destroy (ch->mq);
261 ch->mq = NULL; 263 ch->mq = NULL;
262 } 264 }
263 if (NULL != ch->task) 265 if (NULL != ch->task)
264 { 266 {
265 GNUNET_SCHEDULER_cancel(ch->task); 267 GNUNET_SCHEDULER_cancel (ch->task);
266 ch->task = NULL; 268 ch->task = NULL;
267 } 269 }
268 GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, 270 GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests,
269 &free_sug_handle, 271 &free_sug_handle,
270 NULL); 272 NULL);
271 GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests); 273 GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests);
272 GNUNET_free(ch); 274 GNUNET_free (ch);
273} 275}
274 276
275 277
@@ -284,7 +286,7 @@ GNUNET_TRANSPORT_application_done(
284 * @return suggest handle, NULL if a request is already pending 286 * @return suggest handle, NULL if a request is already pending
285 */ 287 */
286struct GNUNET_TRANSPORT_ApplicationSuggestHandle * 288struct GNUNET_TRANSPORT_ApplicationSuggestHandle *
287GNUNET_TRANSPORT_application_suggest( 289GNUNET_TRANSPORT_application_suggest (
288 struct GNUNET_TRANSPORT_ApplicationHandle *ch, 290 struct GNUNET_TRANSPORT_ApplicationHandle *ch,
289 const struct GNUNET_PeerIdentity *peer, 291 const struct GNUNET_PeerIdentity *peer,
290 enum GNUNET_MQ_PriorityPreferences pk, 292 enum GNUNET_MQ_PriorityPreferences pk,
@@ -292,22 +294,22 @@ GNUNET_TRANSPORT_application_suggest(
292{ 294{
293 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *s; 295 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *s;
294 296
295 s = GNUNET_new(struct GNUNET_TRANSPORT_ApplicationSuggestHandle); 297 s = GNUNET_new (struct GNUNET_TRANSPORT_ApplicationSuggestHandle);
296 s->ch = ch; 298 s->ch = ch;
297 s->id = *peer; 299 s->id = *peer;
298 s->pk = pk; 300 s->pk = pk;
299 s->bw = bw; 301 s->bw = bw;
300 (void)GNUNET_CONTAINER_multipeermap_put( 302 (void) GNUNET_CONTAINER_multipeermap_put (
301 ch->sug_requests, 303 ch->sug_requests,
302 &s->id, 304 &s->id,
303 s, 305 s,
304 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 306 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
305 LOG(GNUNET_ERROR_TYPE_DEBUG, 307 LOG (GNUNET_ERROR_TYPE_DEBUG,
306 "Requesting TRANSPORT to suggest address for `%s'\n", 308 "Requesting TRANSPORT to suggest address for `%s'\n",
307 GNUNET_i2s(peer)); 309 GNUNET_i2s (peer));
308 if (NULL == ch->mq) 310 if (NULL == ch->mq)
309 return s; 311 return s;
310 GNUNET_assert(GNUNET_OK == transmit_suggestion(ch, &s->id, s)); 312 GNUNET_assert (GNUNET_OK == transmit_suggestion (ch, &s->id, s));
311 return s; 313 return s;
312} 314}
313 315
@@ -318,30 +320,30 @@ GNUNET_TRANSPORT_application_suggest(
318 * @param sh handle to stop 320 * @param sh handle to stop
319 */ 321 */
320void 322void
321GNUNET_TRANSPORT_application_suggest_cancel( 323GNUNET_TRANSPORT_application_suggest_cancel (
322 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh) 324 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh)
323{ 325{
324 struct GNUNET_TRANSPORT_ApplicationHandle *ch = sh->ch; 326 struct GNUNET_TRANSPORT_ApplicationHandle *ch = sh->ch;
325 struct GNUNET_MQ_Envelope *ev; 327 struct GNUNET_MQ_Envelope *ev;
326 struct ExpressPreferenceMessage *m; 328 struct ExpressPreferenceMessage *m;
327 329
328 LOG(GNUNET_ERROR_TYPE_DEBUG, 330 LOG (GNUNET_ERROR_TYPE_DEBUG,
329 "Telling TRANSPORT we no longer care for an address for `%s'\n", 331 "Telling TRANSPORT we no longer care for an address for `%s'\n",
330 GNUNET_i2s(&sh->id)); 332 GNUNET_i2s (&sh->id));
331 GNUNET_assert( 333 GNUNET_assert (
332 GNUNET_OK == 334 GNUNET_OK ==
333 GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests, &sh->id, sh)); 335 GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, &sh->id, sh));
334 if (NULL == ch->mq) 336 if (NULL == ch->mq)
335 { 337 {
336 GNUNET_free(sh); 338 GNUNET_free (sh);
337 return; 339 return;
338 } 340 }
339 ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL); 341 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL);
340 m->pk = htonl((uint32_t)sh->pk); 342 m->pk = htonl ((uint32_t) sh->pk);
341 m->bw = sh->bw; 343 m->bw = sh->bw;
342 m->peer = sh->id; 344 m->peer = sh->id;
343 GNUNET_MQ_send(ch->mq, ev); 345 GNUNET_MQ_send (ch->mq, ev);
344 GNUNET_free(sh); 346 GNUNET_free (sh);
345} 347}
346 348
347 349
@@ -361,7 +363,7 @@ GNUNET_TRANSPORT_application_suggest_cancel(
361 * @param addr address to validate 363 * @param addr address to validate
362 */ 364 */
363void 365void
364GNUNET_TRANSPORT_application_validate( 366GNUNET_TRANSPORT_application_validate (
365 struct GNUNET_TRANSPORT_ApplicationHandle *ch, 367 struct GNUNET_TRANSPORT_ApplicationHandle *ch,
366 const struct GNUNET_PeerIdentity *peer, 368 const struct GNUNET_PeerIdentity *peer,
367 enum GNUNET_NetworkType nt, 369 enum GNUNET_NetworkType nt,
@@ -372,23 +374,23 @@ GNUNET_TRANSPORT_application_validate(
372 size_t alen; 374 size_t alen;
373 375
374 if (NULL == ch->mq) 376 if (NULL == ch->mq)
375 { 377 {
376 GNUNET_log( 378 GNUNET_log (
377 GNUNET_ERROR_TYPE_WARNING, 379 GNUNET_ERROR_TYPE_WARNING,
378 "Address validation for %s:%s skipped as transport is not connected\n", 380 "Address validation for %s:%s skipped as transport is not connected\n",
379 GNUNET_i2s(peer), 381 GNUNET_i2s (peer),
380 addr); 382 addr);
381 return; 383 return;
382 } 384 }
383 alen = strlen(addr) + 1; 385 alen = strlen (addr) + 1;
384 ev = 386 ev =
385 GNUNET_MQ_msg_extra(m, 387 GNUNET_MQ_msg_extra (m,
386 alen, 388 alen,
387 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION); 389 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION);
388 m->peer = *peer; 390 m->peer = *peer;
389 m->nt = htonl((uint32_t)nt); 391 m->nt = htonl ((uint32_t) nt);
390 memcpy(&m[1], addr, alen); 392 memcpy (&m[1], addr, alen);
391 GNUNET_MQ_send(ch->mq, ev); 393 GNUNET_MQ_send (ch->mq, ev);
392} 394}
393 395
394 396
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 @@
42/** 42/**
43 * Information we track per packet to enable flow control. 43 * Information we track per packet to enable flow control.
44 */ 44 */
45struct FlowControl { 45struct FlowControl
46{
46 /** 47 /**
47 * Kept in a DLL. 48 * Kept in a DLL.
48 */ 49 */
@@ -79,7 +80,8 @@ struct FlowControl {
79 * Information we track per message to tell the transport about 80 * Information we track per message to tell the transport about
80 * success or failures. 81 * success or failures.
81 */ 82 */
82struct AckPending { 83struct AckPending
84{
83 /** 85 /**
84 * Kept in a DLL. 86 * Kept in a DLL.
85 */ 87 */
@@ -110,7 +112,8 @@ struct AckPending {
110/** 112/**
111 * Opaque handle to the transport service for communicators. 113 * Opaque handle to the transport service for communicators.
112 */ 114 */
113struct GNUNET_TRANSPORT_CommunicatorHandle { 115struct GNUNET_TRANSPORT_CommunicatorHandle
116{
114 /** 117 /**
115 * Head of DLL of addresses this communicator offers to the transport service. 118 * Head of DLL of addresses this communicator offers to the transport service.
116 */ 119 */
@@ -226,7 +229,8 @@ struct GNUNET_TRANSPORT_CommunicatorHandle {
226 * Handle returned to identify the internal data structure the transport 229 * Handle returned to identify the internal data structure the transport
227 * API has created to manage a message queue to a particular peer. 230 * API has created to manage a message queue to a particular peer.
228 */ 231 */
229struct GNUNET_TRANSPORT_QueueHandle { 232struct GNUNET_TRANSPORT_QueueHandle
233{
230 /** 234 /**
231 * Kept in a DLL. 235 * Kept in a DLL.
232 */ 236 */
@@ -283,7 +287,8 @@ struct GNUNET_TRANSPORT_QueueHandle {
283 * Internal representation of an address a communicator is 287 * Internal representation of an address a communicator is
284 * currently providing for the transport service. 288 * currently providing for the transport service.
285 */ 289 */
286struct GNUNET_TRANSPORT_AddressIdentifier { 290struct GNUNET_TRANSPORT_AddressIdentifier
291{
287 /** 292 /**
288 * Kept in a DLL. 293 * Kept in a DLL.
289 */ 294 */
@@ -329,7 +334,7 @@ struct GNUNET_TRANSPORT_AddressIdentifier {
329 * @param ch handle to reconnect 334 * @param ch handle to reconnect
330 */ 335 */
331static void 336static void
332reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch); 337reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
333 338
334 339
335/** 340/**
@@ -339,20 +344,20 @@ reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
339 * @param ai address to add 344 * @param ai address to add
340 */ 345 */
341static void 346static void
342send_add_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai) 347send_add_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai)
343{ 348{
344 struct GNUNET_MQ_Envelope *env; 349 struct GNUNET_MQ_Envelope *env;
345 struct GNUNET_TRANSPORT_AddAddressMessage *aam; 350 struct GNUNET_TRANSPORT_AddAddressMessage *aam;
346 351
347 if (NULL == ai->ch->mq) 352 if (NULL == ai->ch->mq)
348 return; 353 return;
349 env = GNUNET_MQ_msg_extra(aam, 354 env = GNUNET_MQ_msg_extra (aam,
350 strlen(ai->address) + 1, 355 strlen (ai->address) + 1,
351 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS); 356 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS);
352 aam->expiration = GNUNET_TIME_relative_hton(ai->expiration); 357 aam->expiration = GNUNET_TIME_relative_hton (ai->expiration);
353 aam->nt = htonl((uint32_t)ai->nt); 358 aam->nt = htonl ((uint32_t) ai->nt);
354 memcpy(&aam[1], ai->address, strlen(ai->address) + 1); 359 memcpy (&aam[1], ai->address, strlen (ai->address) + 1);
355 GNUNET_MQ_send(ai->ch->mq, env); 360 GNUNET_MQ_send (ai->ch->mq, env);
356} 361}
357 362
358 363
@@ -363,16 +368,16 @@ send_add_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
363 * @param ai address to delete 368 * @param ai address to delete
364 */ 369 */
365static void 370static void
366send_del_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai) 371send_del_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai)
367{ 372{
368 struct GNUNET_MQ_Envelope *env; 373 struct GNUNET_MQ_Envelope *env;
369 struct GNUNET_TRANSPORT_DelAddressMessage *dam; 374 struct GNUNET_TRANSPORT_DelAddressMessage *dam;
370 375
371 if (NULL == ai->ch->mq) 376 if (NULL == ai->ch->mq)
372 return; 377 return;
373 env = GNUNET_MQ_msg(dam, GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS); 378 env = GNUNET_MQ_msg (dam, GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS);
374 dam->aid = htonl(ai->aid); 379 dam->aid = htonl (ai->aid);
375 GNUNET_MQ_send(ai->ch->mq, env); 380 GNUNET_MQ_send (ai->ch->mq, env);
376} 381}
377 382
378 383
@@ -383,23 +388,23 @@ send_del_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
383 * @param qh queue to add 388 * @param qh queue to add
384 */ 389 */
385static void 390static void
386send_add_queue(struct GNUNET_TRANSPORT_QueueHandle *qh) 391send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
387{ 392{
388 struct GNUNET_MQ_Envelope *env; 393 struct GNUNET_MQ_Envelope *env;
389 struct GNUNET_TRANSPORT_AddQueueMessage *aqm; 394 struct GNUNET_TRANSPORT_AddQueueMessage *aqm;
390 395
391 if (NULL == qh->ch->mq) 396 if (NULL == qh->ch->mq)
392 return; 397 return;
393 env = GNUNET_MQ_msg_extra(aqm, 398 env = GNUNET_MQ_msg_extra (aqm,
394 strlen(qh->address) + 1, 399 strlen (qh->address) + 1,
395 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP); 400 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP);
396 aqm->qid = htonl(qh->queue_id); 401 aqm->qid = htonl (qh->queue_id);
397 aqm->receiver = qh->peer; 402 aqm->receiver = qh->peer;
398 aqm->nt = htonl((uint32_t)qh->nt); 403 aqm->nt = htonl ((uint32_t) qh->nt);
399 aqm->mtu = htonl(qh->mtu); 404 aqm->mtu = htonl (qh->mtu);
400 aqm->cs = htonl((uint32_t)qh->cs); 405 aqm->cs = htonl ((uint32_t) qh->cs);
401 memcpy(&aqm[1], qh->address, strlen(qh->address) + 1); 406 memcpy (&aqm[1], qh->address, strlen (qh->address) + 1);
402 GNUNET_MQ_send(qh->ch->mq, env); 407 GNUNET_MQ_send (qh->ch->mq, env);
403} 408}
404 409
405 410
@@ -410,17 +415,17 @@ send_add_queue(struct GNUNET_TRANSPORT_QueueHandle *qh)
410 * @param qh queue to delete 415 * @param qh queue to delete
411 */ 416 */
412static void 417static void
413send_del_queue(struct GNUNET_TRANSPORT_QueueHandle *qh) 418send_del_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
414{ 419{
415 struct GNUNET_MQ_Envelope *env; 420 struct GNUNET_MQ_Envelope *env;
416 struct GNUNET_TRANSPORT_DelQueueMessage *dqm; 421 struct GNUNET_TRANSPORT_DelQueueMessage *dqm;
417 422
418 if (NULL == qh->ch->mq) 423 if (NULL == qh->ch->mq)
419 return; 424 return;
420 env = GNUNET_MQ_msg(dqm, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN); 425 env = GNUNET_MQ_msg (dqm, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN);
421 dqm->qid = htonl(qh->queue_id); 426 dqm->qid = htonl (qh->queue_id);
422 dqm->receiver = qh->peer; 427 dqm->receiver = qh->peer;
423 GNUNET_MQ_send(qh->ch->mq, env); 428 GNUNET_MQ_send (qh->ch->mq, env);
424} 429}
425 430
426 431
@@ -433,27 +438,27 @@ send_del_queue(struct GNUNET_TRANSPORT_QueueHandle *qh)
433 * @param ch service to disconnect from 438 * @param ch service to disconnect from
434 */ 439 */
435static void 440static void
436disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch) 441disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
437{ 442{
438 struct FlowControl *fcn; 443 struct FlowControl *fcn;
439 struct AckPending *apn; 444 struct AckPending *apn;
440 445
441 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fcn) 446 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fcn)
442 { 447 {
443 fcn = fc->next; 448 fcn = fc->next;
444 GNUNET_CONTAINER_DLL_remove(ch->fc_head, ch->fc_tail, fc); 449 GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc);
445 fc->cb(fc->cb_cls, GNUNET_SYSERR); 450 fc->cb (fc->cb_cls, GNUNET_SYSERR);
446 GNUNET_free(fc); 451 GNUNET_free (fc);
447 } 452 }
448 for (struct AckPending *ap = ch->ap_head; NULL != ap; ap = apn) 453 for (struct AckPending *ap = ch->ap_head; NULL != ap; ap = apn)
449 { 454 {
450 apn = ap->next; 455 apn = ap->next;
451 GNUNET_CONTAINER_DLL_remove(ch->ap_head, ch->ap_tail, ap); 456 GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap);
452 GNUNET_free(ap); 457 GNUNET_free (ap);
453 } 458 }
454 if (NULL == ch->mq) 459 if (NULL == ch->mq)
455 return; 460 return;
456 GNUNET_MQ_destroy(ch->mq); 461 GNUNET_MQ_destroy (ch->mq);
457 ch->mq = NULL; 462 ch->mq = NULL;
458} 463}
459 464
@@ -462,16 +467,16 @@ disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
462 * Function called on MQ errors. 467 * Function called on MQ errors.
463 */ 468 */
464static void 469static void
465error_handler(void *cls, enum GNUNET_MQ_Error error) 470error_handler (void *cls, enum GNUNET_MQ_Error error)
466{ 471{
467 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 472 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
468 473
469 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 474 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
470 "MQ failure %d, reconnecting to transport service.\n", 475 "MQ failure %d, reconnecting to transport service.\n",
471 error); 476 error);
472 disconnect(ch); 477 disconnect (ch);
473 /* TODO: maybe do this with exponential backoff/delay */ 478 /* TODO: maybe do this with exponential backoff/delay */
474 reconnect(ch); 479 reconnect (ch);
475} 480}
476 481
477 482
@@ -483,29 +488,29 @@ error_handler(void *cls, enum GNUNET_MQ_Error error)
483 * @param incoming_ack the ack 488 * @param incoming_ack the ack
484 */ 489 */
485static void 490static void
486handle_incoming_ack( 491handle_incoming_ack (
487 void *cls, 492 void *cls,
488 const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack) 493 const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack)
489{ 494{
490 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 495 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
491 496
492 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fc->next) 497 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fc->next)
498 {
499 if ((fc->id == incoming_ack->fc_id) &&
500 (0 == memcmp (&fc->sender,
501 &incoming_ack->sender,
502 sizeof(struct GNUNET_PeerIdentity))))
493 { 503 {
494 if ((fc->id == incoming_ack->fc_id) && 504 GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc);
495 (0 == memcmp(&fc->sender, 505 fc->cb (fc->cb_cls, GNUNET_OK);
496 &incoming_ack->sender, 506 GNUNET_free (fc);
497 sizeof(struct GNUNET_PeerIdentity)))) 507 return;
498 {
499 GNUNET_CONTAINER_DLL_remove(ch->fc_head, ch->fc_tail, fc);
500 fc->cb(fc->cb_cls, GNUNET_OK);
501 GNUNET_free(fc);
502 return;
503 }
504 } 508 }
505 GNUNET_break(0); 509 }
506 disconnect(ch); 510 GNUNET_break (0);
511 disconnect (ch);
507 /* TODO: maybe do this with exponential backoff/delay */ 512 /* TODO: maybe do this with exponential backoff/delay */
508 reconnect(ch); 513 reconnect (ch);
509} 514}
510 515
511 516
@@ -518,10 +523,10 @@ handle_incoming_ack(
518 * @return #GNUNET_OK if @a smt is well-formed 523 * @return #GNUNET_OK if @a smt is well-formed
519 */ 524 */
520static int 525static int
521check_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) 526check_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
522{ 527{
523 (void)cls; 528 (void) cls;
524 GNUNET_MQ_check_zero_termination(cq); 529 GNUNET_MQ_check_zero_termination (cq);
525 return GNUNET_OK; 530 return GNUNET_OK;
526} 531}
527 532
@@ -533,26 +538,26 @@ check_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
533 * @param cq the queue creation request 538 * @param cq the queue creation request
534 */ 539 */
535static void 540static void
536handle_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) 541handle_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
537{ 542{
538 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 543 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
539 const char *addr = (const char *)&cq[1]; 544 const char *addr = (const char *) &cq[1];
540 struct GNUNET_TRANSPORT_CreateQueueResponse *cqr; 545 struct GNUNET_TRANSPORT_CreateQueueResponse *cqr;
541 struct GNUNET_MQ_Envelope *env; 546 struct GNUNET_MQ_Envelope *env;
542 547
543 if (GNUNET_OK != ch->mq_init(ch->mq_init_cls, &cq->receiver, addr)) 548 if (GNUNET_OK != ch->mq_init (ch->mq_init_cls, &cq->receiver, addr))
544 { 549 {
545 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 550 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
546 "Address `%s' invalid for this communicator\n", 551 "Address `%s' invalid for this communicator\n",
547 addr); 552 addr);
548 env = GNUNET_MQ_msg(cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL); 553 env = GNUNET_MQ_msg (cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL);
549 } 554 }
550 else 555 else
551 { 556 {
552 env = GNUNET_MQ_msg(cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK); 557 env = GNUNET_MQ_msg (cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK);
553 } 558 }
554 cqr->request_id = cq->request_id; 559 cqr->request_id = cq->request_id;
555 GNUNET_MQ_send(ch->mq, env); 560 GNUNET_MQ_send (ch->mq, env);
556} 561}
557 562
558 563
@@ -565,10 +570,10 @@ handle_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
565 * @return #GNUNET_OK if @a smt is well-formed 570 * @return #GNUNET_OK if @a smt is well-formed
566 */ 571 */
567static int 572static int
568check_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) 573check_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
569{ 574{
570 (void)cls; 575 (void) cls;
571 GNUNET_MQ_check_boxed_message(smt); 576 GNUNET_MQ_check_boxed_message (smt);
572 return GNUNET_OK; 577 return GNUNET_OK;
573} 578}
574 579
@@ -583,19 +588,19 @@ check_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
583 * @param mid message that the ack is about 588 * @param mid message that the ack is about
584 */ 589 */
585static void 590static void
586send_ack(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 591send_ack (struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
587 int status, 592 int status,
588 const struct GNUNET_PeerIdentity *receiver, 593 const struct GNUNET_PeerIdentity *receiver,
589 uint64_t mid) 594 uint64_t mid)
590{ 595{
591 struct GNUNET_MQ_Envelope *env; 596 struct GNUNET_MQ_Envelope *env;
592 struct GNUNET_TRANSPORT_SendMessageToAck *ack; 597 struct GNUNET_TRANSPORT_SendMessageToAck *ack;
593 598
594 env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK); 599 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK);
595 ack->status = htonl(status); 600 ack->status = htonl (status);
596 ack->mid = mid; 601 ack->mid = mid;
597 ack->receiver = *receiver; 602 ack->receiver = *receiver;
598 GNUNET_MQ_send(ch->mq, env); 603 GNUNET_MQ_send (ch->mq, env);
599} 604}
600 605
601 606
@@ -606,14 +611,14 @@ send_ack(struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
606 * @param cls an `struct AckPending *` 611 * @param cls an `struct AckPending *`
607 */ 612 */
608static void 613static void
609send_ack_cb(void *cls) 614send_ack_cb (void *cls)
610{ 615{
611 struct AckPending *ap = cls; 616 struct AckPending *ap = cls;
612 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ap->ch; 617 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ap->ch;
613 618
614 GNUNET_CONTAINER_DLL_remove(ch->ap_head, ch->ap_tail, ap); 619 GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap);
615 send_ack(ch, GNUNET_OK, &ap->receiver, ap->mid); 620 send_ack (ch, GNUNET_OK, &ap->receiver, ap->mid);
616 GNUNET_free(ap); 621 GNUNET_free (ap);
617} 622}
618 623
619 624
@@ -624,7 +629,7 @@ send_ack_cb(void *cls)
624 * @param smt the transmission request 629 * @param smt the transmission request
625 */ 630 */
626static void 631static void
627handle_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) 632handle_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
628{ 633{
629 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 634 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
630 const struct GNUNET_MessageHeader *mh; 635 const struct GNUNET_MessageHeader *mh;
@@ -634,27 +639,27 @@ handle_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
634 639
635 for (qh = ch->queue_head; NULL != qh; qh = qh->next) 640 for (qh = ch->queue_head; NULL != qh; qh = qh->next)
636 if ((qh->queue_id == smt->qid) && 641 if ((qh->queue_id == smt->qid) &&
637 (0 == memcmp(&qh->peer, 642 (0 == memcmp (&qh->peer,
638 &smt->receiver, 643 &smt->receiver,
639 sizeof(struct GNUNET_PeerIdentity)))) 644 sizeof(struct GNUNET_PeerIdentity))))
640 break; 645 break;
641 if (NULL == qh) 646 if (NULL == qh)
642 { 647 {
643 /* queue is already gone, tell transport this one failed */ 648 /* queue is already gone, tell transport this one failed */
644 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 649 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
645 "Transmission failed, queue no longer exists.\n"); 650 "Transmission failed, queue no longer exists.\n");
646 send_ack(ch, GNUNET_NO, &smt->receiver, smt->mid); 651 send_ack (ch, GNUNET_NO, &smt->receiver, smt->mid);
647 return; 652 return;
648 } 653 }
649 ap = GNUNET_new(struct AckPending); 654 ap = GNUNET_new (struct AckPending);
650 ap->ch = ch; 655 ap->ch = ch;
651 ap->receiver = smt->receiver; 656 ap->receiver = smt->receiver;
652 ap->mid = smt->mid; 657 ap->mid = smt->mid;
653 GNUNET_CONTAINER_DLL_insert(ch->ap_head, ch->ap_tail, ap); 658 GNUNET_CONTAINER_DLL_insert (ch->ap_head, ch->ap_tail, ap);
654 mh = (const struct GNUNET_MessageHeader *)&smt[1]; 659 mh = (const struct GNUNET_MessageHeader *) &smt[1];
655 env = GNUNET_MQ_msg_copy(mh); 660 env = GNUNET_MQ_msg_copy (mh);
656 GNUNET_MQ_notify_sent(env, &send_ack_cb, ap); 661 GNUNET_MQ_notify_sent (env, &send_ack_cb, ap);
657 GNUNET_MQ_send(qh->mq, env); 662 GNUNET_MQ_send (qh->mq, env);
658} 663}
659 664
660 665
@@ -667,12 +672,12 @@ handle_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
667 * @return #GNUNET_OK if @a smt is well-formed 672 * @return #GNUNET_OK if @a smt is well-formed
668 */ 673 */
669static int 674static int
670check_backchannel_incoming( 675check_backchannel_incoming (
671 void *cls, 676 void *cls,
672 const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi) 677 const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi)
673{ 678{
674 (void)cls; 679 (void) cls;
675 GNUNET_MQ_check_boxed_message(bi); 680 GNUNET_MQ_check_boxed_message (bi);
676 return GNUNET_OK; 681 return GNUNET_OK;
677} 682}
678 683
@@ -684,20 +689,20 @@ check_backchannel_incoming(
684 * @param bi the backchannel message 689 * @param bi the backchannel message
685 */ 690 */
686static void 691static void
687handle_backchannel_incoming( 692handle_backchannel_incoming (
688 void *cls, 693 void *cls,
689 const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi) 694 const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi)
690{ 695{
691 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 696 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
692 697
693 if (NULL != ch->notify_cb) 698 if (NULL != ch->notify_cb)
694 ch->notify_cb(ch->notify_cb_cls, 699 ch->notify_cb (ch->notify_cb_cls,
695 &bi->pid, 700 &bi->pid,
696 (const struct GNUNET_MessageHeader *)&bi[1]); 701 (const struct GNUNET_MessageHeader *) &bi[1]);
697 else 702 else
698 GNUNET_log( 703 GNUNET_log (
699 GNUNET_ERROR_TYPE_INFO, 704 GNUNET_ERROR_TYPE_INFO,
700 _("Dropped backchanel message: handler not provided by communicator\n")); 705 _ ("Dropped backchanel message: handler not provided by communicator\n"));
701} 706}
702 707
703 708
@@ -707,46 +712,46 @@ handle_backchannel_incoming(
707 * @param ch handle to reconnect 712 * @param ch handle to reconnect
708 */ 713 */
709static void 714static void
710reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch) 715reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
711{ 716{
712 struct GNUNET_MQ_MessageHandler handlers[] = 717 struct GNUNET_MQ_MessageHandler handlers[] =
713 { GNUNET_MQ_hd_fixed_size(incoming_ack, 718 { GNUNET_MQ_hd_fixed_size (incoming_ack,
714 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK, 719 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK,
715 struct GNUNET_TRANSPORT_IncomingMessageAck, 720 struct GNUNET_TRANSPORT_IncomingMessageAck,
716 ch), 721 ch),
717 GNUNET_MQ_hd_var_size(create_queue, 722 GNUNET_MQ_hd_var_size (create_queue,
718 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE, 723 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE,
719 struct GNUNET_TRANSPORT_CreateQueue, 724 struct GNUNET_TRANSPORT_CreateQueue,
720 ch), 725 ch),
721 GNUNET_MQ_hd_var_size(send_msg, 726 GNUNET_MQ_hd_var_size (send_msg,
722 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG, 727 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG,
723 struct GNUNET_TRANSPORT_SendMessageTo, 728 struct GNUNET_TRANSPORT_SendMessageTo,
724 ch), 729 ch),
725 GNUNET_MQ_hd_var_size( 730 GNUNET_MQ_hd_var_size (
726 backchannel_incoming, 731 backchannel_incoming,
727 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING, 732 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING,
728 struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming, 733 struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming,
729 ch), 734 ch),
730 GNUNET_MQ_handler_end() }; 735 GNUNET_MQ_handler_end () };
731 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam; 736 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam;
732 struct GNUNET_MQ_Envelope *env; 737 struct GNUNET_MQ_Envelope *env;
733 738
734 ch->mq = 739 ch->mq =
735 GNUNET_CLIENT_connect(ch->cfg, "transport", handlers, &error_handler, ch); 740 GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch);
736 if (NULL == ch->mq) 741 if (NULL == ch->mq)
737 return; 742 return;
738 env = GNUNET_MQ_msg_extra(cam, 743 env = GNUNET_MQ_msg_extra (cam,
739 strlen(ch->addr_prefix) + 1, 744 strlen (ch->addr_prefix) + 1,
740 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR); 745 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR);
741 cam->cc = htonl((uint32_t)ch->cc); 746 cam->cc = htonl ((uint32_t) ch->cc);
742 memcpy(&cam[1], ch->addr_prefix, strlen(ch->addr_prefix) + 1); 747 memcpy (&cam[1], ch->addr_prefix, strlen (ch->addr_prefix) + 1);
743 GNUNET_MQ_send(ch->mq, env); 748 GNUNET_MQ_send (ch->mq, env);
744 for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai; 749 for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai;
745 ai = ai->next) 750 ai = ai->next)
746 send_add_address(ai); 751 send_add_address (ai);
747 for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; NULL != qh; 752 for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; NULL != qh;
748 qh = qh->next) 753 qh = qh->next)
749 send_add_queue(qh); 754 send_add_queue (qh);
750} 755}
751 756
752 757
@@ -769,7 +774,7 @@ reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
769 * @return NULL on error 774 * @return NULL on error
770 */ 775 */
771struct GNUNET_TRANSPORT_CommunicatorHandle * 776struct GNUNET_TRANSPORT_CommunicatorHandle *
772GNUNET_TRANSPORT_communicator_connect( 777GNUNET_TRANSPORT_communicator_connect (
773 const struct GNUNET_CONFIGURATION_Handle *cfg, 778 const struct GNUNET_CONFIGURATION_Handle *cfg,
774 const char *config_section, 779 const char *config_section,
775 const char *addr_prefix, 780 const char *addr_prefix,
@@ -781,7 +786,7 @@ GNUNET_TRANSPORT_communicator_connect(
781{ 786{
782 struct GNUNET_TRANSPORT_CommunicatorHandle *ch; 787 struct GNUNET_TRANSPORT_CommunicatorHandle *ch;
783 788
784 ch = GNUNET_new(struct GNUNET_TRANSPORT_CommunicatorHandle); 789 ch = GNUNET_new (struct GNUNET_TRANSPORT_CommunicatorHandle);
785 ch->cfg = cfg; 790 ch->cfg = cfg;
786 ch->config_section = config_section; 791 ch->config_section = config_section;
787 ch->addr_prefix = addr_prefix; 792 ch->addr_prefix = addr_prefix;
@@ -790,18 +795,18 @@ GNUNET_TRANSPORT_communicator_connect(
790 ch->notify_cb = notify_cb; 795 ch->notify_cb = notify_cb;
791 ch->notify_cb_cls = notify_cb_cls; 796 ch->notify_cb_cls = notify_cb_cls;
792 ch->cc = cc; 797 ch->cc = cc;
793 reconnect(ch); 798 reconnect (ch);
794 if (GNUNET_OK != 799 if (GNUNET_OK !=
795 GNUNET_CONFIGURATION_get_value_number(cfg, 800 GNUNET_CONFIGURATION_get_value_number (cfg,
796 config_section, 801 config_section,
797 "MAX_QUEUE_LENGTH", 802 "MAX_QUEUE_LENGTH",
798 &ch->max_queue_length)) 803 &ch->max_queue_length))
799 ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; 804 ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
800 if (NULL == ch->mq) 805 if (NULL == ch->mq)
801 { 806 {
802 GNUNET_free(ch); 807 GNUNET_free (ch);
803 return NULL; 808 return NULL;
804 } 809 }
805 return ch; 810 return ch;
806} 811}
807 812
@@ -812,16 +817,16 @@ GNUNET_TRANSPORT_communicator_connect(
812 * @param ch handle returned from connect 817 * @param ch handle returned from connect
813 */ 818 */
814void 819void
815GNUNET_TRANSPORT_communicator_disconnect( 820GNUNET_TRANSPORT_communicator_disconnect (
816 struct GNUNET_TRANSPORT_CommunicatorHandle *ch) 821 struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
817{ 822{
818 disconnect(ch); 823 disconnect (ch);
819 while (NULL != ch->ai_head) 824 while (NULL != ch->ai_head)
820 { 825 {
821 GNUNET_break(0); /* communicator forgot to remove address, warn! */ 826 GNUNET_break (0); /* communicator forgot to remove address, warn! */
822 GNUNET_TRANSPORT_communicator_address_remove(ch->ai_head); 827 GNUNET_TRANSPORT_communicator_address_remove (ch->ai_head);
823 } 828 }
824 GNUNET_free(ch); 829 GNUNET_free (ch);
825} 830}
826 831
827 832
@@ -849,7 +854,7 @@ GNUNET_TRANSPORT_communicator_disconnect(
849 * the tranport service is not yet up 854 * the tranport service is not yet up
850 */ 855 */
851int 856int
852GNUNET_TRANSPORT_communicator_receive( 857GNUNET_TRANSPORT_communicator_receive (
853 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 858 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
854 const struct GNUNET_PeerIdentity *sender, 859 const struct GNUNET_PeerIdentity *sender,
855 const struct GNUNET_MessageHeader *msg, 860 const struct GNUNET_MessageHeader *msg,
@@ -863,41 +868,41 @@ GNUNET_TRANSPORT_communicator_receive(
863 868
864 if (NULL == ch->mq) 869 if (NULL == ch->mq)
865 return GNUNET_SYSERR; 870 return GNUNET_SYSERR;
866 if ((NULL == cb) && (GNUNET_MQ_get_length(ch->mq) >= ch->max_queue_length)) 871 if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length))
867 { 872 {
868 GNUNET_log( 873 GNUNET_log (
869 GNUNET_ERROR_TYPE_WARNING, 874 GNUNET_ERROR_TYPE_WARNING,
870 "Dropping message: transprot is too slow, queue length %llu exceeded\n", 875 "Dropping message: transprot is too slow, queue length %llu exceeded\n",
871 ch->max_queue_length); 876 ch->max_queue_length);
872 return GNUNET_NO; 877 return GNUNET_NO;
873 } 878 }
874 879
875 msize = ntohs(msg->size); 880 msize = ntohs (msg->size);
876 env = 881 env =
877 GNUNET_MQ_msg_extra(im, msize, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG); 882 GNUNET_MQ_msg_extra (im, msize, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG);
878 if (NULL == env) 883 if (NULL == env)
879 { 884 {
880 GNUNET_break(0); 885 GNUNET_break (0);
881 return GNUNET_SYSERR; 886 return GNUNET_SYSERR;
882 } 887 }
883 im->expected_address_validity = 888 im->expected_address_validity =
884 GNUNET_TIME_relative_hton(expected_addr_validity); 889 GNUNET_TIME_relative_hton (expected_addr_validity);
885 im->sender = *sender; 890 im->sender = *sender;
886 memcpy(&im[1], msg, msize); 891 memcpy (&im[1], msg, msize);
887 if (NULL != cb) 892 if (NULL != cb)
888 { 893 {
889 struct FlowControl *fc; 894 struct FlowControl *fc;
890 895
891 im->fc_on = htonl(GNUNET_YES); 896 im->fc_on = htonl (GNUNET_YES);
892 im->fc_id = ch->fc_gen++; 897 im->fc_id = ch->fc_gen++;
893 fc = GNUNET_new(struct FlowControl); 898 fc = GNUNET_new (struct FlowControl);
894 fc->sender = *sender; 899 fc->sender = *sender;
895 fc->id = im->fc_id; 900 fc->id = im->fc_id;
896 fc->cb = cb; 901 fc->cb = cb;
897 fc->cb_cls = cb_cls; 902 fc->cb_cls = cb_cls;
898 GNUNET_CONTAINER_DLL_insert(ch->fc_head, ch->fc_tail, fc); 903 GNUNET_CONTAINER_DLL_insert (ch->fc_head, ch->fc_tail, fc);
899 } 904 }
900 GNUNET_MQ_send(ch->mq, env); 905 GNUNET_MQ_send (ch->mq, env);
901 return GNUNET_OK; 906 return GNUNET_OK;
902} 907}
903 908
@@ -922,7 +927,7 @@ GNUNET_TRANSPORT_communicator_receive(
922 * @return API handle identifying the new MQ 927 * @return API handle identifying the new MQ
923 */ 928 */
924struct GNUNET_TRANSPORT_QueueHandle * 929struct GNUNET_TRANSPORT_QueueHandle *
925GNUNET_TRANSPORT_communicator_mq_add( 930GNUNET_TRANSPORT_communicator_mq_add (
926 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 931 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
927 const struct GNUNET_PeerIdentity *peer, 932 const struct GNUNET_PeerIdentity *peer,
928 const char *address, 933 const char *address,
@@ -933,17 +938,17 @@ GNUNET_TRANSPORT_communicator_mq_add(
933{ 938{
934 struct GNUNET_TRANSPORT_QueueHandle *qh; 939 struct GNUNET_TRANSPORT_QueueHandle *qh;
935 940
936 qh = GNUNET_new(struct GNUNET_TRANSPORT_QueueHandle); 941 qh = GNUNET_new (struct GNUNET_TRANSPORT_QueueHandle);
937 qh->ch = ch; 942 qh->ch = ch;
938 qh->peer = *peer; 943 qh->peer = *peer;
939 qh->address = GNUNET_strdup(address); 944 qh->address = GNUNET_strdup (address);
940 qh->nt = nt; 945 qh->nt = nt;
941 qh->mtu = mtu; 946 qh->mtu = mtu;
942 qh->cs = cs; 947 qh->cs = cs;
943 qh->mq = mq; 948 qh->mq = mq;
944 qh->queue_id = ch->queue_gen++; 949 qh->queue_id = ch->queue_gen++;
945 GNUNET_CONTAINER_DLL_insert(ch->queue_head, ch->queue_tail, qh); 950 GNUNET_CONTAINER_DLL_insert (ch->queue_head, ch->queue_tail, qh);
946 send_add_queue(qh); 951 send_add_queue (qh);
947 return qh; 952 return qh;
948} 953}
949 954
@@ -955,15 +960,15 @@ GNUNET_TRANSPORT_communicator_mq_add(
955 * @param qh handle for the queue that must be invalidated 960 * @param qh handle for the queue that must be invalidated
956 */ 961 */
957void 962void
958GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh) 963GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh)
959{ 964{
960 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = qh->ch; 965 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = qh->ch;
961 966
962 send_del_queue(qh); 967 send_del_queue (qh);
963 GNUNET_CONTAINER_DLL_remove(ch->queue_head, ch->queue_tail, qh); 968 GNUNET_CONTAINER_DLL_remove (ch->queue_head, ch->queue_tail, qh);
964 GNUNET_MQ_destroy(qh->mq); 969 GNUNET_MQ_destroy (qh->mq);
965 GNUNET_free(qh->address); 970 GNUNET_free (qh->address);
966 GNUNET_free(qh); 971 GNUNET_free (qh);
967} 972}
968 973
969 974
@@ -977,7 +982,7 @@ GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
977 * @param expiration when does the communicator forsee this address expiring? 982 * @param expiration when does the communicator forsee this address expiring?
978 */ 983 */
979struct GNUNET_TRANSPORT_AddressIdentifier * 984struct GNUNET_TRANSPORT_AddressIdentifier *
980GNUNET_TRANSPORT_communicator_address_add( 985GNUNET_TRANSPORT_communicator_address_add (
981 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 986 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
982 const char *address, 987 const char *address,
983 enum GNUNET_NetworkType nt, 988 enum GNUNET_NetworkType nt,
@@ -985,14 +990,14 @@ GNUNET_TRANSPORT_communicator_address_add(
985{ 990{
986 struct GNUNET_TRANSPORT_AddressIdentifier *ai; 991 struct GNUNET_TRANSPORT_AddressIdentifier *ai;
987 992
988 ai = GNUNET_new(struct GNUNET_TRANSPORT_AddressIdentifier); 993 ai = GNUNET_new (struct GNUNET_TRANSPORT_AddressIdentifier);
989 ai->ch = ch; 994 ai->ch = ch;
990 ai->address = GNUNET_strdup(address); 995 ai->address = GNUNET_strdup (address);
991 ai->nt = nt; 996 ai->nt = nt;
992 ai->expiration = expiration; 997 ai->expiration = expiration;
993 ai->aid = ch->aid_gen++; 998 ai->aid = ch->aid_gen++;
994 GNUNET_CONTAINER_DLL_insert(ch->ai_head, ch->ai_tail, ai); 999 GNUNET_CONTAINER_DLL_insert (ch->ai_head, ch->ai_tail, ai);
995 send_add_address(ai); 1000 send_add_address (ai);
996 return ai; 1001 return ai;
997} 1002}
998 1003
@@ -1004,15 +1009,15 @@ GNUNET_TRANSPORT_communicator_address_add(
1004 * @param ai address that is no longer provided 1009 * @param ai address that is no longer provided
1005 */ 1010 */
1006void 1011void
1007GNUNET_TRANSPORT_communicator_address_remove( 1012GNUNET_TRANSPORT_communicator_address_remove (
1008 struct GNUNET_TRANSPORT_AddressIdentifier *ai) 1013 struct GNUNET_TRANSPORT_AddressIdentifier *ai)
1009{ 1014{
1010 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ai->ch; 1015 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ai->ch;
1011 1016
1012 send_del_address(ai); 1017 send_del_address (ai);
1013 GNUNET_CONTAINER_DLL_remove(ch->ai_head, ch->ai_tail, ai); 1018 GNUNET_CONTAINER_DLL_remove (ch->ai_head, ch->ai_tail, ai);
1014 GNUNET_free(ai->address); 1019 GNUNET_free (ai->address);
1015 GNUNET_free(ai); 1020 GNUNET_free (ai);
1016} 1021}
1017 1022
1018 1023
@@ -1034,7 +1039,7 @@ GNUNET_TRANSPORT_communicator_address_remove(
1034 * notify-API to @a pid's communicator @a comm 1039 * notify-API to @a pid's communicator @a comm
1035 */ 1040 */
1036void 1041void
1037GNUNET_TRANSPORT_communicator_notify( 1042GNUNET_TRANSPORT_communicator_notify (
1038 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 1043 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
1039 const struct GNUNET_PeerIdentity *pid, 1044 const struct GNUNET_PeerIdentity *pid,
1040 const char *comm, 1045 const char *comm,
@@ -1042,18 +1047,18 @@ GNUNET_TRANSPORT_communicator_notify(
1042{ 1047{
1043 struct GNUNET_MQ_Envelope *env; 1048 struct GNUNET_MQ_Envelope *env;
1044 struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb; 1049 struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb;
1045 size_t slen = strlen(comm) + 1; 1050 size_t slen = strlen (comm) + 1;
1046 uint16_t mlen = ntohs(header->size); 1051 uint16_t mlen = ntohs (header->size);
1047 1052
1048 GNUNET_assert(mlen + slen + sizeof(*cb) < UINT16_MAX); 1053 GNUNET_assert (mlen + slen + sizeof(*cb) < UINT16_MAX);
1049 env = 1054 env =
1050 GNUNET_MQ_msg_extra(cb, 1055 GNUNET_MQ_msg_extra (cb,
1051 slen + mlen, 1056 slen + mlen,
1052 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL); 1057 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL);
1053 cb->pid = *pid; 1058 cb->pid = *pid;
1054 memcpy(&cb[1], header, mlen); 1059 memcpy (&cb[1], header, mlen);
1055 memcpy(((char *)&cb[1]) + mlen, comm, slen); 1060 memcpy (((char *) &cb[1]) + mlen, comm, slen);
1056 GNUNET_MQ_send(ch->mq, env); 1061 GNUNET_MQ_send (ch->mq, env);
1057} 1062}
1058 1063
1059 1064
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 @@
32#include "gnunet_transport_core_service.h" 32#include "gnunet_transport_core_service.h"
33#include "transport.h" 33#include "transport.h"
34 34
35#define LOG(kind, ...) GNUNET_log_from(kind, "transport-api-core", __VA_ARGS__) 35#define LOG(kind, ...) GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__)
36 36
37/** 37/**
38 * How large to start with for the hashmap of neighbours. 38 * How large to start with for the hashmap of neighbours.
@@ -53,7 +53,8 @@
53/** 53/**
54 * Entry in hash table of all of our current (connected) neighbours. 54 * Entry in hash table of all of our current (connected) neighbours.
55 */ 55 */
56struct Neighbour { 56struct Neighbour
57{
57 /** 58 /**
58 * Identity of this neighbour. 59 * Identity of this neighbour.
59 */ 60 */
@@ -105,7 +106,8 @@ struct Neighbour {
105 * Handle for the transport service (includes all of the 106 * Handle for the transport service (includes all of the
106 * state for the transport service). 107 * state for the transport service).
107 */ 108 */
108struct GNUNET_TRANSPORT_CoreHandle { 109struct GNUNET_TRANSPORT_CoreHandle
110{
109 /** 111 /**
110 * Closure for the callbacks. 112 * Closure for the callbacks.
111 */ 113 */
@@ -173,7 +175,7 @@ struct GNUNET_TRANSPORT_CoreHandle {
173 * @param h transport service to reconnect 175 * @param h transport service to reconnect
174 */ 176 */
175static void 177static void
176disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h); 178disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h);
177 179
178 180
179/** 181/**
@@ -184,10 +186,10 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h);
184 * @return NULL if no such peer entry exists 186 * @return NULL if no such peer entry exists
185 */ 187 */
186static struct Neighbour * 188static struct Neighbour *
187neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, 189neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h,
188 const struct GNUNET_PeerIdentity *peer) 190 const struct GNUNET_PeerIdentity *peer)
189{ 191{
190 return GNUNET_CONTAINER_multipeermap_get(h->neighbours, peer); 192 return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer);
191} 193}
192 194
193 195
@@ -202,27 +204,27 @@ neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h,
202 * #GNUNET_NO if not. 204 * #GNUNET_NO if not.
203 */ 205 */
204static int 206static int
205neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 207neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
206{ 208{
207 struct GNUNET_TRANSPORT_CoreHandle *handle = cls; 209 struct GNUNET_TRANSPORT_CoreHandle *handle = cls;
208 struct Neighbour *n = value; 210 struct Neighbour *n = value;
209 211
210 LOG(GNUNET_ERROR_TYPE_DEBUG, 212 LOG (GNUNET_ERROR_TYPE_DEBUG,
211 "Dropping entry for neighbour `%s'.\n", 213 "Dropping entry for neighbour `%s'.\n",
212 GNUNET_i2s(key)); 214 GNUNET_i2s (key));
213 if (NULL != handle->nd_cb) 215 if (NULL != handle->nd_cb)
214 handle->nd_cb(handle->cls, &n->id, n->handlers_cls); 216 handle->nd_cb (handle->cls, &n->id, n->handlers_cls);
215 if (NULL != n->env) 217 if (NULL != n->env)
216 { 218 {
217 GNUNET_MQ_send_cancel(n->env); 219 GNUNET_MQ_send_cancel (n->env);
218 n->env = NULL; 220 n->env = NULL;
219 } 221 }
220 GNUNET_MQ_destroy(n->mq); 222 GNUNET_MQ_destroy (n->mq);
221 GNUNET_assert(NULL == n->mq); 223 GNUNET_assert (NULL == n->mq);
222 GNUNET_assert( 224 GNUNET_assert (
223 GNUNET_YES == 225 GNUNET_YES ==
224 GNUNET_CONTAINER_multipeermap_remove(handle->neighbours, key, n)); 226 GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n));
225 GNUNET_free(n); 227 GNUNET_free (n);
226 return GNUNET_YES; 228 return GNUNET_YES;
227} 229}
228 230
@@ -237,13 +239,13 @@ neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
237 * @param error error code 239 * @param error error code
238 */ 240 */
239static void 241static void
240mq_error_handler(void *cls, enum GNUNET_MQ_Error error) 242mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
241{ 243{
242 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 244 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
243 245
244 LOG(GNUNET_ERROR_TYPE_DEBUG, 246 LOG (GNUNET_ERROR_TYPE_DEBUG,
245 "Error receiving from transport service, disconnecting temporarily.\n"); 247 "Error receiving from transport service, disconnecting temporarily.\n");
246 disconnect_and_schedule_reconnect(h); 248 disconnect_and_schedule_reconnect (h);
247} 249}
248 250
249 251
@@ -258,13 +260,13 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
258 * @param cls the `struct Neighbour` where the message was sent 260 * @param cls the `struct Neighbour` where the message was sent
259 */ 261 */
260static void 262static void
261notify_send_done(void *cls) 263notify_send_done (void *cls)
262{ 264{
263 struct Neighbour *n = cls; 265 struct Neighbour *n = cls;
264 266
265 n->awaiting_done = GNUNET_NO; 267 n->awaiting_done = GNUNET_NO;
266 n->env = NULL; 268 n->env = NULL;
267 GNUNET_MQ_impl_send_continue(n->mq); 269 GNUNET_MQ_impl_send_continue (n->mq);
268} 270}
269 271
270 272
@@ -275,18 +277,18 @@ notify_send_done(void *cls)
275 * @param n neighbour to perform transmission for 277 * @param n neighbour to perform transmission for
276 */ 278 */
277static void 279static void
278do_send(struct Neighbour *n) 280do_send (struct Neighbour *n)
279{ 281{
280 GNUNET_assert(0 < n->ready_window); 282 GNUNET_assert (0 < n->ready_window);
281 GNUNET_assert(NULL != n->env); 283 GNUNET_assert (NULL != n->env);
282 n->ready_window--; 284 n->ready_window--;
283 n->awaiting_done = GNUNET_YES; 285 n->awaiting_done = GNUNET_YES;
284 GNUNET_MQ_notify_sent(n->env, &notify_send_done, n); 286 GNUNET_MQ_notify_sent (n->env, &notify_send_done, n);
285 GNUNET_MQ_send(n->h->mq, n->env); 287 GNUNET_MQ_send (n->h->mq, n->env);
286 LOG(GNUNET_ERROR_TYPE_DEBUG, 288 LOG (GNUNET_ERROR_TYPE_DEBUG,
287 "Passed message of type %u for neighbour `%s' to TRANSPORT.\n", 289 "Passed message of type %u for neighbour `%s' to TRANSPORT.\n",
288 ntohs(GNUNET_MQ_env_get_msg(n->env)->type), 290 ntohs (GNUNET_MQ_env_get_msg (n->env)->type),
289 GNUNET_i2s(&n->id)); 291 GNUNET_i2s (&n->id));
290} 292}
291 293
292 294
@@ -301,44 +303,44 @@ do_send(struct Neighbour *n)
301 * @param impl_state state of the implementation 303 * @param impl_state state of the implementation
302 */ 304 */
303static void 305static void
304mq_send_impl(struct GNUNET_MQ_Handle *mq, 306mq_send_impl (struct GNUNET_MQ_Handle *mq,
305 const struct GNUNET_MessageHeader *msg, 307 const struct GNUNET_MessageHeader *msg,
306 void *impl_state) 308 void *impl_state)
307{ 309{
308 struct Neighbour *n = impl_state; 310 struct Neighbour *n = impl_state;
309 struct OutboundMessage *obm; 311 struct OutboundMessage *obm;
310 uint16_t msize; 312 uint16_t msize;
311 313
312 msize = ntohs(msg->size); 314 msize = ntohs (msg->size);
313 if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm)) 315 if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm))
314 { 316 {
315 GNUNET_break(0); 317 GNUNET_break (0);
316 GNUNET_MQ_impl_send_continue(mq); 318 GNUNET_MQ_impl_send_continue (mq);
317 return; 319 return;
318 } 320 }
319 LOG(GNUNET_ERROR_TYPE_DEBUG, 321 LOG (GNUNET_ERROR_TYPE_DEBUG,
320 "CORE requested transmission of message of type %u to neighbour `%s'.\n", 322 "CORE requested transmission of message of type %u to neighbour `%s'.\n",
321 ntohs(msg->type), 323 ntohs (msg->type),
322 GNUNET_i2s(&n->id)); 324 GNUNET_i2s (&n->id));
323 325
324 GNUNET_assert(NULL == n->env); 326 GNUNET_assert (NULL == n->env);
325 n->env = 327 n->env =
326 GNUNET_MQ_msg_nested_mh(obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); 328 GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg);
327 n->env_size = ntohs(msg->size); 329 n->env_size = ntohs (msg->size);
328 { 330 {
329 struct GNUNET_MQ_Envelope *env; 331 struct GNUNET_MQ_Envelope *env;
330 332
331 env = GNUNET_MQ_get_current_envelope(mq); 333 env = GNUNET_MQ_get_current_envelope (mq);
332 obm->priority = htonl((uint32_t)GNUNET_MQ_env_get_options(env)); 334 obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env));
333 } 335 }
334 obm->peer = n->id; 336 obm->peer = n->id;
335 if (0 == n->ready_window) 337 if (0 == n->ready_window)
336 { 338 {
337 LOG(GNUNET_ERROR_TYPE_DEBUG, 339 LOG (GNUNET_ERROR_TYPE_DEBUG,
338 "Flow control delays transmission to CORE until we see SEND_OK.\n"); 340 "Flow control delays transmission to CORE until we see SEND_OK.\n");
339 return; /* can't send yet, need to wait for SEND_OK */ 341 return; /* can't send yet, need to wait for SEND_OK */
340 } 342 }
341 do_send(n); 343 do_send (n);
342} 344}
343 345
344 346
@@ -350,11 +352,11 @@ mq_send_impl(struct GNUNET_MQ_Handle *mq,
350 * @param impl_state state of the implementation 352 * @param impl_state state of the implementation
351 */ 353 */
352static void 354static void
353mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) 355mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
354{ 356{
355 struct Neighbour *n = impl_state; 357 struct Neighbour *n = impl_state;
356 358
357 GNUNET_assert(mq == n->mq); 359 GNUNET_assert (mq == n->mq);
358 n->mq = NULL; 360 n->mq = NULL;
359} 361}
360 362
@@ -367,22 +369,22 @@ mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
367 * @param impl_state state specific to the implementation 369 * @param impl_state state specific to the implementation
368 */ 370 */
369static void 371static void
370mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) 372mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
371{ 373{
372 struct Neighbour *n = impl_state; 374 struct Neighbour *n = impl_state;
373 375
374 n->ready_window++; 376 n->ready_window++;
375 if (GNUNET_YES == n->awaiting_done) 377 if (GNUNET_YES == n->awaiting_done)
376 { 378 {
377 GNUNET_MQ_send_cancel(n->env); 379 GNUNET_MQ_send_cancel (n->env);
378 n->env = NULL; 380 n->env = NULL;
379 n->awaiting_done = GNUNET_NO; 381 n->awaiting_done = GNUNET_NO;
380 } 382 }
381 else 383 else
382 { 384 {
383 GNUNET_assert(0 == n->ready_window); 385 GNUNET_assert (0 == n->ready_window);
384 n->env = NULL; 386 n->env = NULL;
385 } 387 }
386} 388}
387 389
388 390
@@ -395,11 +397,11 @@ mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
395 * @param error error code 397 * @param error error code
396 */ 398 */
397static void 399static void
398peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) 400peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
399{ 401{
400 /* struct Neighbour *n = cls; */ 402 /* struct Neighbour *n = cls; */
401 403
402 GNUNET_break_op(0); 404 GNUNET_break_op (0);
403} 405}
404 406
405 407
@@ -410,44 +412,44 @@ peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
410 * @param cim message received 412 * @param cim message received
411 */ 413 */
412static void 414static void
413handle_connect(void *cls, const struct ConnectInfoMessage *cim) 415handle_connect (void *cls, const struct ConnectInfoMessage *cim)
414{ 416{
415 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 417 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
416 struct Neighbour *n; 418 struct Neighbour *n;
417 419
418 LOG(GNUNET_ERROR_TYPE_DEBUG, 420 LOG (GNUNET_ERROR_TYPE_DEBUG,
419 "Receiving CONNECT message for `%s'\n", 421 "Receiving CONNECT message for `%s'\n",
420 GNUNET_i2s(&cim->id)); 422 GNUNET_i2s (&cim->id));
421 n = neighbour_find(h, &cim->id); 423 n = neighbour_find (h, &cim->id);
422 if (NULL != n) 424 if (NULL != n)
423 { 425 {
424 GNUNET_break(0); 426 GNUNET_break (0);
425 disconnect_and_schedule_reconnect(h); 427 disconnect_and_schedule_reconnect (h);
426 return; 428 return;
427 } 429 }
428 n = GNUNET_new(struct Neighbour); 430 n = GNUNET_new (struct Neighbour);
429 n->id = cim->id; 431 n->id = cim->id;
430 n->h = h; 432 n->h = h;
431 n->ready_window = SEND_WINDOW_SIZE; 433 n->ready_window = SEND_WINDOW_SIZE;
432 GNUNET_assert(GNUNET_OK == 434 GNUNET_assert (GNUNET_OK ==
433 GNUNET_CONTAINER_multipeermap_put( 435 GNUNET_CONTAINER_multipeermap_put (
434 h->neighbours, 436 h->neighbours,
435 &n->id, 437 &n->id,
436 n, 438 n,
437 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 439 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
438 440
439 n->mq = GNUNET_MQ_queue_for_callbacks(&mq_send_impl, 441 n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl,
440 &mq_destroy_impl, 442 &mq_destroy_impl,
441 &mq_cancel_impl, 443 &mq_cancel_impl,
442 n, 444 n,
443 h->handlers, 445 h->handlers,
444 &peer_mq_error_handler, 446 &peer_mq_error_handler,
445 n); 447 n);
446 if (NULL != h->nc_cb) 448 if (NULL != h->nc_cb)
447 { 449 {
448 n->handlers_cls = h->nc_cb(h->cls, &n->id, n->mq); 450 n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq);
449 GNUNET_MQ_set_handlers_closure(n->mq, n->handlers_cls); 451 GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls);
450 } 452 }
451} 453}
452 454
453 455
@@ -458,23 +460,23 @@ handle_connect(void *cls, const struct ConnectInfoMessage *cim)
458 * @param dim message received 460 * @param dim message received
459 */ 461 */
460static void 462static void
461handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim) 463handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim)
462{ 464{
463 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 465 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
464 struct Neighbour *n; 466 struct Neighbour *n;
465 467
466 GNUNET_break(ntohl(dim->reserved) == 0); 468 GNUNET_break (ntohl (dim->reserved) == 0);
467 LOG(GNUNET_ERROR_TYPE_DEBUG, 469 LOG (GNUNET_ERROR_TYPE_DEBUG,
468 "Receiving DISCONNECT message for `%s'.\n", 470 "Receiving DISCONNECT message for `%s'.\n",
469 GNUNET_i2s(&dim->peer)); 471 GNUNET_i2s (&dim->peer));
470 n = neighbour_find(h, &dim->peer); 472 n = neighbour_find (h, &dim->peer);
471 if (NULL == n) 473 if (NULL == n)
472 { 474 {
473 GNUNET_break(0); 475 GNUNET_break (0);
474 disconnect_and_schedule_reconnect(h); 476 disconnect_and_schedule_reconnect (h);
475 return; 477 return;
476 } 478 }
477 GNUNET_assert(GNUNET_YES == neighbour_delete(h, &dim->peer, n)); 479 GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n));
478} 480}
479 481
480 482
@@ -485,26 +487,26 @@ handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim)
485 * @param okm message received 487 * @param okm message received
486 */ 488 */
487static void 489static void
488handle_send_ok(void *cls, const struct SendOkMessage *okm) 490handle_send_ok (void *cls, const struct SendOkMessage *okm)
489{ 491{
490 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 492 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
491 struct Neighbour *n; 493 struct Neighbour *n;
492 494
493 LOG(GNUNET_ERROR_TYPE_DEBUG, 495 LOG (GNUNET_ERROR_TYPE_DEBUG,
494 "Receiving SEND_OK message for transmission to %s\n", 496 "Receiving SEND_OK message for transmission to %s\n",
495 GNUNET_i2s(&okm->peer)); 497 GNUNET_i2s (&okm->peer));
496 n = neighbour_find(h, &okm->peer); 498 n = neighbour_find (h, &okm->peer);
497 if (NULL == n) 499 if (NULL == n)
498 { 500 {
499 /* We should never get a 'SEND_OK' for a peer that we are not 501 /* We should never get a 'SEND_OK' for a peer that we are not
500 connected to */ 502 connected to */
501 GNUNET_break(0); 503 GNUNET_break (0);
502 disconnect_and_schedule_reconnect(h); 504 disconnect_and_schedule_reconnect (h);
503 return; 505 return;
504 } 506 }
505 n->ready_window++; 507 n->ready_window++;
506 if ((NULL != n->env) && (1 == n->ready_window)) 508 if ((NULL != n->env) && (1 == n->ready_window))
507 do_send(n); 509 do_send (n);
508} 510}
509 511
510 512
@@ -515,23 +517,23 @@ handle_send_ok(void *cls, const struct SendOkMessage *okm)
515 * @param im message received 517 * @param im message received
516 */ 518 */
517static int 519static int
518check_recv(void *cls, const struct InboundMessage *im) 520check_recv (void *cls, const struct InboundMessage *im)
519{ 521{
520 const struct GNUNET_MessageHeader *imm; 522 const struct GNUNET_MessageHeader *imm;
521 uint16_t size; 523 uint16_t size;
522 524
523 size = ntohs(im->header.size) - sizeof(*im); 525 size = ntohs (im->header.size) - sizeof(*im);
524 if (size < sizeof(struct GNUNET_MessageHeader)) 526 if (size < sizeof(struct GNUNET_MessageHeader))
525 { 527 {
526 GNUNET_break(0); 528 GNUNET_break (0);
527 return GNUNET_SYSERR; 529 return GNUNET_SYSERR;
528 } 530 }
529 imm = (const struct GNUNET_MessageHeader *)&im[1]; 531 imm = (const struct GNUNET_MessageHeader *) &im[1];
530 if (ntohs(imm->size) != size) 532 if (ntohs (imm->size) != size)
531 { 533 {
532 GNUNET_break(0); 534 GNUNET_break (0);
533 return GNUNET_SYSERR; 535 return GNUNET_SYSERR;
534 } 536 }
535 return GNUNET_OK; 537 return GNUNET_OK;
536} 538}
537 539
@@ -543,26 +545,26 @@ check_recv(void *cls, const struct InboundMessage *im)
543 * @param im message received 545 * @param im message received
544 */ 546 */
545static void 547static void
546handle_recv(void *cls, const struct InboundMessage *im) 548handle_recv (void *cls, const struct InboundMessage *im)
547{ 549{
548 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 550 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
549 const struct GNUNET_MessageHeader *imm = 551 const struct GNUNET_MessageHeader *imm =
550 (const struct GNUNET_MessageHeader *)&im[1]; 552 (const struct GNUNET_MessageHeader *) &im[1];
551 struct Neighbour *n; 553 struct Neighbour *n;
552 554
553 LOG(GNUNET_ERROR_TYPE_DEBUG, 555 LOG (GNUNET_ERROR_TYPE_DEBUG,
554 "Received message of type %u with %u bytes from `%s'.\n", 556 "Received message of type %u with %u bytes from `%s'.\n",
555 (unsigned int)ntohs(imm->type), 557 (unsigned int) ntohs (imm->type),
556 (unsigned int)ntohs(imm->size), 558 (unsigned int) ntohs (imm->size),
557 GNUNET_i2s(&im->peer)); 559 GNUNET_i2s (&im->peer));
558 n = neighbour_find(h, &im->peer); 560 n = neighbour_find (h, &im->peer);
559 if (NULL == n) 561 if (NULL == n)
560 { 562 {
561 GNUNET_break(0); 563 GNUNET_break (0);
562 disconnect_and_schedule_reconnect(h); 564 disconnect_and_schedule_reconnect (h);
563 return; 565 return;
564 } 566 }
565 GNUNET_MQ_inject_message(n->mq, imm); 567 GNUNET_MQ_inject_message (n->mq, imm);
566} 568}
567 569
568 570
@@ -572,47 +574,47 @@ handle_recv(void *cls, const struct InboundMessage *im)
572 * @param cls the handle to the transport service 574 * @param cls the handle to the transport service
573 */ 575 */
574static void 576static void
575reconnect(void *cls) 577reconnect (void *cls)
576{ 578{
577 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 579 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
578 struct GNUNET_MQ_MessageHandler handlers[] = 580 struct GNUNET_MQ_MessageHandler handlers[] =
579 { GNUNET_MQ_hd_fixed_size(connect, 581 { GNUNET_MQ_hd_fixed_size (connect,
580 GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, 582 GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT,
581 struct ConnectInfoMessage, 583 struct ConnectInfoMessage,
582 h), 584 h),
583 GNUNET_MQ_hd_fixed_size(disconnect, 585 GNUNET_MQ_hd_fixed_size (disconnect,
584 GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, 586 GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT,
585 struct DisconnectInfoMessage, 587 struct DisconnectInfoMessage,
586 h), 588 h),
587 GNUNET_MQ_hd_fixed_size(send_ok, 589 GNUNET_MQ_hd_fixed_size (send_ok,
588 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, 590 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK,
589 struct SendOkMessage, 591 struct SendOkMessage,
590 h), 592 h),
591 GNUNET_MQ_hd_var_size(recv, 593 GNUNET_MQ_hd_var_size (recv,
592 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, 594 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV,
593 struct InboundMessage, 595 struct InboundMessage,
594 h), 596 h),
595 GNUNET_MQ_handler_end() }; 597 GNUNET_MQ_handler_end () };
596 struct GNUNET_MQ_Envelope *env; 598 struct GNUNET_MQ_Envelope *env;
597 struct StartMessage *s; 599 struct StartMessage *s;
598 uint32_t options; 600 uint32_t options;
599 601
600 h->reconnect_task = NULL; 602 h->reconnect_task = NULL;
601 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); 603 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
602 GNUNET_assert(NULL == h->mq); 604 GNUNET_assert (NULL == h->mq);
603 h->mq = 605 h->mq =
604 GNUNET_CLIENT_connect(h->cfg, "transport", handlers, &mq_error_handler, h); 606 GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h);
605 if (NULL == h->mq) 607 if (NULL == h->mq)
606 return; 608 return;
607 env = GNUNET_MQ_msg(s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); 609 env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START);
608 options = 0; 610 options = 0;
609 if (h->check_self) 611 if (h->check_self)
610 options |= 1; 612 options |= 1;
611 if (NULL != h->handlers) 613 if (NULL != h->handlers)
612 options |= 2; 614 options |= 2;
613 s->options = htonl(options); 615 s->options = htonl (options);
614 s->self = h->self; 616 s->self = h->self;
615 GNUNET_MQ_send(h->mq, env); 617 GNUNET_MQ_send (h->mq, env);
616} 618}
617 619
618 620
@@ -622,14 +624,14 @@ reconnect(void *cls)
622 * @param h transport service to reconnect 624 * @param h transport service to reconnect
623 */ 625 */
624static void 626static void
625disconnect(struct GNUNET_TRANSPORT_CoreHandle *h) 627disconnect (struct GNUNET_TRANSPORT_CoreHandle *h)
626{ 628{
627 GNUNET_CONTAINER_multipeermap_iterate(h->neighbours, &neighbour_delete, h); 629 GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h);
628 if (NULL != h->mq) 630 if (NULL != h->mq)
629 { 631 {
630 GNUNET_MQ_destroy(h->mq); 632 GNUNET_MQ_destroy (h->mq);
631 h->mq = NULL; 633 h->mq = NULL;
632 } 634 }
633} 635}
634 636
635 637
@@ -640,16 +642,16 @@ disconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
640 * @param h transport service to reconnect 642 * @param h transport service to reconnect
641 */ 643 */
642static void 644static void
643disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h) 645disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h)
644{ 646{
645 GNUNET_assert(NULL == h->reconnect_task); 647 GNUNET_assert (NULL == h->reconnect_task);
646 disconnect(h); 648 disconnect (h);
647 LOG(GNUNET_ERROR_TYPE_DEBUG, 649 LOG (GNUNET_ERROR_TYPE_DEBUG,
648 "Scheduling task to reconnect to transport service in %s.\n", 650 "Scheduling task to reconnect to transport service in %s.\n",
649 GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); 651 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES));
650 h->reconnect_task = 652 h->reconnect_task =
651 GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); 653 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
652 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); 654 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
653} 655}
654 656
655 657
@@ -661,12 +663,12 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
661 * @return NULL if disconnected, otherwise message queue for @a peer 663 * @return NULL if disconnected, otherwise message queue for @a peer
662 */ 664 */
663struct GNUNET_MQ_Handle * 665struct GNUNET_MQ_Handle *
664GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, 666GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
665 const struct GNUNET_PeerIdentity *peer) 667 const struct GNUNET_PeerIdentity *peer)
666{ 668{
667 struct Neighbour *n; 669 struct Neighbour *n;
668 670
669 n = neighbour_find(handle, peer); 671 n = neighbour_find (handle, peer);
670 if (NULL == n) 672 if (NULL == n)
671 return NULL; 673 return NULL;
672 return n->mq; 674 return n->mq;
@@ -694,21 +696,21 @@ GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle,
694 * @param pid which peer was the message from that was fully processed by CORE 696 * @param pid which peer was the message from that was fully processed by CORE
695 */ 697 */
696void 698void
697GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch, 699GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch,
698 const struct GNUNET_PeerIdentity *pid) 700 const struct GNUNET_PeerIdentity *pid)
699{ 701{
700 struct GNUNET_MQ_Envelope *env; 702 struct GNUNET_MQ_Envelope *env;
701 struct RecvOkMessage *rok; 703 struct RecvOkMessage *rok;
702 704
703 LOG(GNUNET_ERROR_TYPE_DEBUG, 705 LOG (GNUNET_ERROR_TYPE_DEBUG,
704 "Message for %s finished CORE processing, sending RECV_OK.\n", 706 "Message for %s finished CORE processing, sending RECV_OK.\n",
705 GNUNET_i2s(pid)); 707 GNUNET_i2s (pid));
706 if (NULL == ch->mq) 708 if (NULL == ch->mq)
707 return; 709 return;
708 env = GNUNET_MQ_msg(rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); 710 env = GNUNET_MQ_msg (rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK);
709 rok->increase_window_delta = htonl(1); 711 rok->increase_window_delta = htonl (1);
710 rok->peer = *pid; 712 rok->peer = *pid;
711 GNUNET_MQ_send(ch->mq, env); 713 GNUNET_MQ_send (ch->mq, env);
712} 714}
713 715
714 716
@@ -726,46 +728,46 @@ GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch,
726 * @return NULL on error 728 * @return NULL on error
727 */ 729 */
728struct GNUNET_TRANSPORT_CoreHandle * 730struct GNUNET_TRANSPORT_CoreHandle *
729GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, 731GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
730 const struct GNUNET_PeerIdentity *self, 732 const struct GNUNET_PeerIdentity *self,
731 const struct GNUNET_MQ_MessageHandler *handlers, 733 const struct GNUNET_MQ_MessageHandler *handlers,
732 void *cls, 734 void *cls,
733 GNUNET_TRANSPORT_NotifyConnect nc, 735 GNUNET_TRANSPORT_NotifyConnect nc,
734 GNUNET_TRANSPORT_NotifyDisconnect nd) 736 GNUNET_TRANSPORT_NotifyDisconnect nd)
735{ 737{
736 struct GNUNET_TRANSPORT_CoreHandle *h; 738 struct GNUNET_TRANSPORT_CoreHandle *h;
737 unsigned int i; 739 unsigned int i;
738 740
739 h = GNUNET_new(struct GNUNET_TRANSPORT_CoreHandle); 741 h = GNUNET_new (struct GNUNET_TRANSPORT_CoreHandle);
740 if (NULL != self) 742 if (NULL != self)
741 { 743 {
742 h->self = *self; 744 h->self = *self;
743 h->check_self = GNUNET_YES; 745 h->check_self = GNUNET_YES;
744 } 746 }
745 h->cfg = cfg; 747 h->cfg = cfg;
746 h->cls = cls; 748 h->cls = cls;
747 h->nc_cb = nc; 749 h->nc_cb = nc;
748 h->nd_cb = nd; 750 h->nd_cb = nd;
749 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; 751 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
750 if (NULL != handlers) 752 if (NULL != handlers)
751 { 753 {
752 for (i = 0; NULL != handlers[i].cb; i++) 754 for (i = 0; NULL != handlers[i].cb; i++)
753 ; 755 ;
754 h->handlers = GNUNET_new_array(i + 1, struct GNUNET_MQ_MessageHandler); 756 h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler);
755 GNUNET_memcpy(h->handlers, 757 GNUNET_memcpy (h->handlers,
756 handlers, 758 handlers,
757 i * sizeof(struct GNUNET_MQ_MessageHandler)); 759 i * sizeof(struct GNUNET_MQ_MessageHandler));
758 } 760 }
759 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); 761 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n");
760 reconnect(h); 762 reconnect (h);
761 if (NULL == h->mq) 763 if (NULL == h->mq)
762 { 764 {
763 GNUNET_free_non_null(h->handlers); 765 GNUNET_free_non_null (h->handlers);
764 GNUNET_free(h); 766 GNUNET_free (h);
765 return NULL; 767 return NULL;
766 } 768 }
767 h->neighbours = 769 h->neighbours =
768 GNUNET_CONTAINER_multipeermap_create(STARTING_NEIGHBOURS_SIZE, GNUNET_YES); 770 GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES);
769 return h; 771 return h;
770} 772}
771 773
@@ -777,22 +779,22 @@ GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg,
777 * #GNUNET_TRANSPORT_core_connect() 779 * #GNUNET_TRANSPORT_core_connect()
778 */ 780 */
779void 781void
780GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle) 782GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle)
781{ 783{
782 LOG(GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); 784 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
783 /* this disconnects all neighbours... */ 785 /* this disconnects all neighbours... */
784 disconnect(handle); 786 disconnect (handle);
785 /* and now we stop trying to connect again... */ 787 /* and now we stop trying to connect again... */
786 if (NULL != handle->reconnect_task) 788 if (NULL != handle->reconnect_task)
787 { 789 {
788 GNUNET_SCHEDULER_cancel(handle->reconnect_task); 790 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
789 handle->reconnect_task = NULL; 791 handle->reconnect_task = NULL;
790 } 792 }
791 GNUNET_CONTAINER_multipeermap_destroy(handle->neighbours); 793 GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours);
792 handle->neighbours = NULL; 794 handle->neighbours = NULL;
793 GNUNET_free_non_null(handle->handlers); 795 GNUNET_free_non_null (handle->handlers);
794 handle->handlers = NULL; 796 handle->handlers = NULL;
795 GNUNET_free(handle); 797 GNUNET_free (handle);
796} 798}
797 799
798 800
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 @@
33/** 33/**
34 * Opaque handle to the transport service for monitors. 34 * Opaque handle to the transport service for monitors.
35 */ 35 */
36struct GNUNET_TRANSPORT_MonitorContext { 36struct GNUNET_TRANSPORT_MonitorContext
37{
37 /** 38 /**
38 * Our configuration. 39 * Our configuration.
39 */ 40 */
@@ -72,7 +73,7 @@ struct GNUNET_TRANSPORT_MonitorContext {
72 * @param mc handle to reconnect 73 * @param mc handle to reconnect
73 */ 74 */
74static void 75static void
75reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc); 76reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc);
76 77
77 78
78/** 79/**
@@ -82,17 +83,17 @@ reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc);
82 * @param ai address to delete 83 * @param ai address to delete
83 */ 84 */
84static void 85static void
85send_start_monitor(struct GNUNET_TRANSPORT_MonitorContext *mc) 86send_start_monitor (struct GNUNET_TRANSPORT_MonitorContext *mc)
86{ 87{
87 struct GNUNET_MQ_Envelope *env; 88 struct GNUNET_MQ_Envelope *env;
88 struct GNUNET_TRANSPORT_MonitorStart *smm; 89 struct GNUNET_TRANSPORT_MonitorStart *smm;
89 90
90 if (NULL == mc->mq) 91 if (NULL == mc->mq)
91 return; 92 return;
92 env = GNUNET_MQ_msg(smm, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START); 93 env = GNUNET_MQ_msg (smm, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START);
93 smm->one_shot = htonl((uint32_t)mc->one_shot); 94 smm->one_shot = htonl ((uint32_t) mc->one_shot);
94 smm->peer = mc->peer; 95 smm->peer = mc->peer;
95 GNUNET_MQ_send(mc->mq, env); 96 GNUNET_MQ_send (mc->mq, env);
96} 97}
97 98
98 99
@@ -102,11 +103,11 @@ send_start_monitor(struct GNUNET_TRANSPORT_MonitorContext *mc)
102 * @param mc service to disconnect from 103 * @param mc service to disconnect from
103 */ 104 */
104static void 105static void
105disconnect(struct GNUNET_TRANSPORT_MonitorContext *mc) 106disconnect (struct GNUNET_TRANSPORT_MonitorContext *mc)
106{ 107{
107 if (NULL == mc->mq) 108 if (NULL == mc->mq)
108 return; 109 return;
109 GNUNET_MQ_destroy(mc->mq); 110 GNUNET_MQ_destroy (mc->mq);
110 mc->mq = NULL; 111 mc->mq = NULL;
111} 112}
112 113
@@ -118,16 +119,16 @@ disconnect(struct GNUNET_TRANSPORT_MonitorContext *mc)
118 * @param error what error happened? 119 * @param error what error happened?
119 */ 120 */
120static void 121static void
121error_handler(void *cls, enum GNUNET_MQ_Error error) 122error_handler (void *cls, enum GNUNET_MQ_Error error)
122{ 123{
123 struct GNUNET_TRANSPORT_MonitorContext *mc = cls; 124 struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
124 125
125 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 126 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
126 "MQ failure %d, reconnecting to transport service.\n", 127 "MQ failure %d, reconnecting to transport service.\n",
127 error); 128 error);
128 disconnect(mc); 129 disconnect (mc);
129 /* TODO: maybe do this with exponential backoff/delay */ 130 /* TODO: maybe do this with exponential backoff/delay */
130 reconnect(mc); 131 reconnect (mc);
131} 132}
132 133
133 134
@@ -140,10 +141,10 @@ error_handler(void *cls, enum GNUNET_MQ_Error error)
140 * @return #GNUNET_OK if @a smt is well-formed 141 * @return #GNUNET_OK if @a smt is well-formed
141 */ 142 */
142static int 143static int
143check_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) 144check_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
144{ 145{
145 (void)cls; 146 (void) cls;
146 GNUNET_MQ_check_zero_termination(md); 147 GNUNET_MQ_check_zero_termination (md);
147 return GNUNET_OK; 148 return GNUNET_OK;
148} 149}
149 150
@@ -155,21 +156,21 @@ check_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
155 * @param md monitor data 156 * @param md monitor data
156 */ 157 */
157static void 158static void
158handle_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) 159handle_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
159{ 160{
160 struct GNUNET_TRANSPORT_MonitorContext *mc = cls; 161 struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
161 struct GNUNET_TRANSPORT_MonitorInformation mi; 162 struct GNUNET_TRANSPORT_MonitorInformation mi;
162 163
163 mi.address = (const char *)&md[1]; 164 mi.address = (const char *) &md[1];
164 mi.nt = (enum GNUNET_NetworkType)ntohl(md->nt); 165 mi.nt = (enum GNUNET_NetworkType) ntohl (md->nt);
165 mi.cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl(md->cs); 166 mi.cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (md->cs);
166 mi.num_msg_pending = ntohl(md->num_msg_pending); 167 mi.num_msg_pending = ntohl (md->num_msg_pending);
167 mi.num_bytes_pending = ntohl(md->num_bytes_pending); 168 mi.num_bytes_pending = ntohl (md->num_bytes_pending);
168 mi.last_validation = GNUNET_TIME_absolute_ntoh(md->last_validation); 169 mi.last_validation = GNUNET_TIME_absolute_ntoh (md->last_validation);
169 mi.valid_until = GNUNET_TIME_absolute_ntoh(md->valid_until); 170 mi.valid_until = GNUNET_TIME_absolute_ntoh (md->valid_until);
170 mi.next_validation = GNUNET_TIME_absolute_ntoh(md->next_validation); 171 mi.next_validation = GNUNET_TIME_absolute_ntoh (md->next_validation);
171 mi.rtt = GNUNET_TIME_relative_ntoh(md->rtt); 172 mi.rtt = GNUNET_TIME_relative_ntoh (md->rtt);
172 mc->cb(mc->cb_cls, &md->peer, &mi); 173 mc->cb (mc->cb_cls, &md->peer, &mi);
173} 174}
174 175
175 176
@@ -180,19 +181,19 @@ handle_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
180 * @param me end message 181 * @param me end message
181 */ 182 */
182static void 183static void
183handle_monitor_end(void *cls, const struct GNUNET_MessageHeader *me) 184handle_monitor_end (void *cls, const struct GNUNET_MessageHeader *me)
184{ 185{
185 struct GNUNET_TRANSPORT_MonitorContext *mc = cls; 186 struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
186 187
187 if (GNUNET_YES != mc->one_shot) 188 if (GNUNET_YES != mc->one_shot)
188 { 189 {
189 GNUNET_break(0); 190 GNUNET_break (0);
190 disconnect(mc); 191 disconnect (mc);
191 reconnect(mc); 192 reconnect (mc);
192 return; 193 return;
193 } 194 }
194 mc->cb(mc->cb_cls, NULL, NULL); 195 mc->cb (mc->cb_cls, NULL, NULL);
195 GNUNET_TRANSPORT_monitor_cancel(mc); 196 GNUNET_TRANSPORT_monitor_cancel (mc);
196} 197}
197 198
198 199
@@ -202,24 +203,24 @@ handle_monitor_end(void *cls, const struct GNUNET_MessageHeader *me)
202 * @param mc handle to reconnect 203 * @param mc handle to reconnect
203 */ 204 */
204static void 205static void
205reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc) 206reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc)
206{ 207{
207 struct GNUNET_MQ_MessageHandler handlers[] = 208 struct GNUNET_MQ_MessageHandler handlers[] =
208 { GNUNET_MQ_hd_var_size(monitor_data, 209 { GNUNET_MQ_hd_var_size (monitor_data,
209 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA, 210 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA,
210 struct GNUNET_TRANSPORT_MonitorData, 211 struct GNUNET_TRANSPORT_MonitorData,
211 mc), 212 mc),
212 GNUNET_MQ_hd_fixed_size(monitor_end, 213 GNUNET_MQ_hd_fixed_size (monitor_end,
213 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END, 214 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END,
214 struct GNUNET_MessageHeader, 215 struct GNUNET_MessageHeader,
215 mc), 216 mc),
216 GNUNET_MQ_handler_end() }; 217 GNUNET_MQ_handler_end () };
217 218
218 mc->mq = 219 mc->mq =
219 GNUNET_CLIENT_connect(mc->cfg, "transport", handlers, &error_handler, mc); 220 GNUNET_CLIENT_connect (mc->cfg, "transport", handlers, &error_handler, mc);
220 if (NULL == mc->mq) 221 if (NULL == mc->mq)
221 return; 222 return;
222 send_start_monitor(mc); 223 send_start_monitor (mc);
223} 224}
224 225
225 226
@@ -250,27 +251,27 @@ reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc)
250 * @param cb_cls closure for @a mc 251 * @param cb_cls closure for @a mc
251 */ 252 */
252struct GNUNET_TRANSPORT_MonitorContext * 253struct GNUNET_TRANSPORT_MonitorContext *
253GNUNET_TRANSPORT_monitor(const struct GNUNET_CONFIGURATION_Handle *cfg, 254GNUNET_TRANSPORT_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg,
254 const struct GNUNET_PeerIdentity *peer, 255 const struct GNUNET_PeerIdentity *peer,
255 int one_shot, 256 int one_shot,
256 GNUNET_TRANSPORT_MonitorCallback cb, 257 GNUNET_TRANSPORT_MonitorCallback cb,
257 void *cb_cls) 258 void *cb_cls)
258{ 259{
259 struct GNUNET_TRANSPORT_MonitorContext *mc; 260 struct GNUNET_TRANSPORT_MonitorContext *mc;
260 261
261 mc = GNUNET_new(struct GNUNET_TRANSPORT_MonitorContext); 262 mc = GNUNET_new (struct GNUNET_TRANSPORT_MonitorContext);
262 mc->cfg = cfg; 263 mc->cfg = cfg;
263 if (NULL != peer) 264 if (NULL != peer)
264 mc->peer = *peer; 265 mc->peer = *peer;
265 mc->one_shot = one_shot; 266 mc->one_shot = one_shot;
266 mc->cb = cb; 267 mc->cb = cb;
267 mc->cb_cls = cb_cls; 268 mc->cb_cls = cb_cls;
268 reconnect(mc); 269 reconnect (mc);
269 if (NULL == mc->mq) 270 if (NULL == mc->mq)
270 { 271 {
271 GNUNET_free(mc); 272 GNUNET_free (mc);
272 return NULL; 273 return NULL;
273 } 274 }
274 return mc; 275 return mc;
275} 276}
276 277
@@ -281,10 +282,10 @@ GNUNET_TRANSPORT_monitor(const struct GNUNET_CONFIGURATION_Handle *cfg,
281 * @param pmc handle for the request to cancel 282 * @param pmc handle for the request to cancel
282 */ 283 */
283void 284void
284GNUNET_TRANSPORT_monitor_cancel(struct GNUNET_TRANSPORT_MonitorContext *mc) 285GNUNET_TRANSPORT_monitor_cancel (struct GNUNET_TRANSPORT_MonitorContext *mc)
285{ 286{
286 disconnect(mc); 287 disconnect (mc);
287 GNUNET_free(mc); 288 GNUNET_free (mc);
288} 289}
289 290
290/* end of transport_api2_monitor.c */ 291/* 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 @@
33/** 33/**
34 * Context for the address lookup. 34 * Context for the address lookup.
35 */ 35 */
36struct GNUNET_TRANSPORT_AddressToStringContext { 36struct GNUNET_TRANSPORT_AddressToStringContext
37{
37 /** 38 /**
38 * Function to call with the human-readable address. 39 * Function to call with the human-readable address.
39 */ 40 */
@@ -59,35 +60,35 @@ struct GNUNET_TRANSPORT_AddressToStringContext {
59 * @return #GNUNET_OK if message is well-formed 60 * @return #GNUNET_OK if message is well-formed
60 */ 61 */
61static int 62static int
62check_reply(void *cls, 63check_reply (void *cls,
63 const struct AddressToStringResultMessage *atsm) 64 const struct AddressToStringResultMessage *atsm)
64{ 65{
65 uint16_t size = ntohs(atsm->header.size) - sizeof(*atsm); 66 uint16_t size = ntohs (atsm->header.size) - sizeof(*atsm);
66 const char *address; 67 const char *address;
67 int result; 68 int result;
68 uint32_t addr_len; 69 uint32_t addr_len;
69 70
70 result = (int)ntohl(atsm->res); 71 result = (int) ntohl (atsm->res);
71 addr_len = ntohl(atsm->addr_len); 72 addr_len = ntohl (atsm->addr_len);
72 if (GNUNET_SYSERR == result) 73 if (GNUNET_SYSERR == result)
73 return GNUNET_OK; 74 return GNUNET_OK;
74 if (0 == size) 75 if (0 == size)
76 {
77 if (GNUNET_OK != result)
75 { 78 {
76 if (GNUNET_OK != result) 79 GNUNET_break (0);
77 { 80 return GNUNET_SYSERR;
78 GNUNET_break(0);
79 return GNUNET_SYSERR;
80 }
81 return GNUNET_OK;
82 } 81 }
83 address = (const char *)&atsm[1]; 82 return GNUNET_OK;
83 }
84 address = (const char *) &atsm[1];
84 if ((addr_len > size) || 85 if ((addr_len > size) ||
85 (address[addr_len - 1] != '\0')) 86 (address[addr_len - 1] != '\0'))
86 { 87 {
87 /* invalid reply */ 88 /* invalid reply */
88 GNUNET_break(0); 89 GNUNET_break (0);
89 return GNUNET_SYSERR; 90 return GNUNET_SYSERR;
90 } 91 }
91 return GNUNET_OK; 92 return GNUNET_OK;
92} 93}
93 94
@@ -99,40 +100,40 @@ check_reply(void *cls,
99 * @param msg message with the human-readable address 100 * @param msg message with the human-readable address
100 */ 101 */
101static void 102static void
102handle_reply(void *cls, 103handle_reply (void *cls,
103 const struct AddressToStringResultMessage *atsm) 104 const struct AddressToStringResultMessage *atsm)
104{ 105{
105 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; 106 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
106 uint16_t size = ntohs(atsm->header.size) - sizeof(*atsm); 107 uint16_t size = ntohs (atsm->header.size) - sizeof(*atsm);
107 const char *address; 108 const char *address;
108 int result; 109 int result;
109 110
110 result = (int)ntohl(atsm->res); 111 result = (int) ntohl (atsm->res);
111 if (GNUNET_SYSERR == result) 112 if (GNUNET_SYSERR == result)
112 { 113 {
113 /* expect more replies; as this is not the last 114 /* expect more replies; as this is not the last
114 call, we must pass the empty string for the address */ 115 call, we must pass the empty string for the address */
115 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
116 "Address resolution failed\n"); 117 "Address resolution failed\n");
117 alucb->cb(alucb->cb_cls, 118 alucb->cb (alucb->cb_cls,
118 "", 119 "",
119 GNUNET_NO); 120 GNUNET_NO);
120 return; 121 return;
121 } 122 }
122 if (0 == size) 123 if (0 == size)
123 { 124 {
124 /* we are done (successfully, without communication errors) */ 125 /* we are done (successfully, without communication errors) */
125 alucb->cb(alucb->cb_cls, 126 alucb->cb (alucb->cb_cls,
126 NULL, 127 NULL,
127 GNUNET_OK); 128 GNUNET_OK);
128 GNUNET_TRANSPORT_address_to_string_cancel(alucb); 129 GNUNET_TRANSPORT_address_to_string_cancel (alucb);
129 return; 130 return;
130 } 131 }
131 address = (const char *)&atsm[1]; 132 address = (const char *) &atsm[1];
132 /* return normal reply to caller, also expect more replies */ 133 /* return normal reply to caller, also expect more replies */
133 alucb->cb(alucb->cb_cls, 134 alucb->cb (alucb->cb_cls,
134 address, 135 address,
135 GNUNET_OK); 136 GNUNET_OK);
136} 137}
137 138
138 139
@@ -146,17 +147,17 @@ handle_reply(void *cls,
146 * @param error error code 147 * @param error error code
147 */ 148 */
148static void 149static void
149mq_error_handler(void *cls, 150mq_error_handler (void *cls,
150 enum GNUNET_MQ_Error error) 151 enum GNUNET_MQ_Error error)
151{ 152{
152 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; 153 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
153 154
154 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
155 "Disconnected from transport, address resolution failed\n"); 156 "Disconnected from transport, address resolution failed\n");
156 alucb->cb(alucb->cb_cls, 157 alucb->cb (alucb->cb_cls,
157 NULL, 158 NULL,
158 GNUNET_SYSERR); 159 GNUNET_SYSERR);
159 GNUNET_TRANSPORT_address_to_string_cancel(alucb); 160 GNUNET_TRANSPORT_address_to_string_cancel (alucb);
160} 161}
161 162
162 163
@@ -173,21 +174,23 @@ mq_error_handler(void *cls,
173 * @return handle to cancel the operation, NULL on error 174 * @return handle to cancel the operation, NULL on error
174 */ 175 */
175struct GNUNET_TRANSPORT_AddressToStringContext * 176struct GNUNET_TRANSPORT_AddressToStringContext *
176GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg, 177GNUNET_TRANSPORT_address_to_string (const struct
177 const struct GNUNET_HELLO_Address *address, 178 GNUNET_CONFIGURATION_Handle *cfg,
178 int numeric, 179 const struct GNUNET_HELLO_Address *address,
179 struct GNUNET_TIME_Relative timeout, 180 int numeric,
180 GNUNET_TRANSPORT_AddressToStringCallback aluc, 181 struct GNUNET_TIME_Relative timeout,
181 void *aluc_cls) 182 GNUNET_TRANSPORT_AddressToStringCallback
183 aluc,
184 void *aluc_cls)
182{ 185{
183 struct GNUNET_TRANSPORT_AddressToStringContext *alc 186 struct GNUNET_TRANSPORT_AddressToStringContext *alc
184 = GNUNET_new(struct GNUNET_TRANSPORT_AddressToStringContext); 187 = GNUNET_new (struct GNUNET_TRANSPORT_AddressToStringContext);
185 struct GNUNET_MQ_MessageHandler handlers[] = { 188 struct GNUNET_MQ_MessageHandler handlers[] = {
186 GNUNET_MQ_hd_var_size(reply, 189 GNUNET_MQ_hd_var_size (reply,
187 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY, 190 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY,
188 struct AddressToStringResultMessage, 191 struct AddressToStringResultMessage,
189 alc), 192 alc),
190 GNUNET_MQ_handler_end() 193 GNUNET_MQ_handler_end ()
191 }; 194 };
192 size_t alen; 195 size_t alen;
193 size_t slen; 196 size_t slen;
@@ -196,49 +199,49 @@ GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg
196 char *addrbuf; 199 char *addrbuf;
197 200
198 alen = address->address_length; 201 alen = address->address_length;
199 slen = strlen(address->transport_name) + 1; 202 slen = strlen (address->transport_name) + 1;
200 if ((alen + slen >= GNUNET_MAX_MESSAGE_SIZE 203 if ((alen + slen >= GNUNET_MAX_MESSAGE_SIZE
201 - sizeof(struct AddressLookupMessage)) || 204 - sizeof(struct AddressLookupMessage)) ||
202 (alen >= GNUNET_MAX_MESSAGE_SIZE) || 205 (alen >= GNUNET_MAX_MESSAGE_SIZE) ||
203 (slen >= GNUNET_MAX_MESSAGE_SIZE)) 206 (slen >= GNUNET_MAX_MESSAGE_SIZE))
204 { 207 {
205 GNUNET_break(0); 208 GNUNET_break (0);
206 GNUNET_free(alc); 209 GNUNET_free (alc);
207 return NULL; 210 return NULL;
208 } 211 }
209 alc->cb = aluc; 212 alc->cb = aluc;
210 alc->cb_cls = aluc_cls; 213 alc->cb_cls = aluc_cls;
211 alc->mq = GNUNET_CLIENT_connect(cfg, 214 alc->mq = GNUNET_CLIENT_connect (cfg,
212 "transport", 215 "transport",
213 handlers, 216 handlers,
214 &mq_error_handler, 217 &mq_error_handler,
215 alc); 218 alc);
216 if (NULL == alc->mq) 219 if (NULL == alc->mq)
217 { 220 {
218 GNUNET_break(0); 221 GNUNET_break (0);
219 GNUNET_free(alc); 222 GNUNET_free (alc);
220 return NULL; 223 return NULL;
221 } 224 }
222 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 225 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
223 "Client tries to resolve for peer `%s' address plugin %s len %u\n", 226 "Client tries to resolve for peer `%s' address plugin %s len %u\n",
224 GNUNET_i2s(&address->peer), 227 GNUNET_i2s (&address->peer),
225 address->transport_name, 228 address->transport_name,
226 (unsigned int)address->address_length); 229 (unsigned int) address->address_length);
227 env = GNUNET_MQ_msg_extra(msg, 230 env = GNUNET_MQ_msg_extra (msg,
228 alen + slen, 231 alen + slen,
229 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING); 232 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING);
230 msg->numeric_only = htons((int16_t)numeric); 233 msg->numeric_only = htons ((int16_t) numeric);
231 msg->addrlen = htons((uint16_t)alen); 234 msg->addrlen = htons ((uint16_t) alen);
232 msg->timeout = GNUNET_TIME_relative_hton(timeout); 235 msg->timeout = GNUNET_TIME_relative_hton (timeout);
233 addrbuf = (char *)&msg[1]; 236 addrbuf = (char *) &msg[1];
234 GNUNET_memcpy(addrbuf, 237 GNUNET_memcpy (addrbuf,
235 address->address, 238 address->address,
236 alen); 239 alen);
237 GNUNET_memcpy(&addrbuf[alen], 240 GNUNET_memcpy (&addrbuf[alen],
238 address->transport_name, 241 address->transport_name,
239 slen); 242 slen);
240 GNUNET_MQ_send(alc->mq, 243 GNUNET_MQ_send (alc->mq,
241 env); 244 env);
242 return alc; 245 return alc;
243} 246}
244 247
@@ -249,10 +252,12 @@ GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg
249 * @param alc the context handle 252 * @param alc the context handle
250 */ 253 */
251void 254void
252GNUNET_TRANSPORT_address_to_string_cancel(struct GNUNET_TRANSPORT_AddressToStringContext *alc) 255GNUNET_TRANSPORT_address_to_string_cancel (struct
256 GNUNET_TRANSPORT_AddressToStringContext
257 *alc)
253{ 258{
254 GNUNET_MQ_destroy(alc->mq); 259 GNUNET_MQ_destroy (alc->mq);
255 GNUNET_free(alc); 260 GNUNET_free (alc);
256} 261}
257 262
258 263
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 @@
34/** 34/**
35 * Handle for blacklisting requests. 35 * Handle for blacklisting requests.
36 */ 36 */
37struct GNUNET_TRANSPORT_Blacklist { 37struct GNUNET_TRANSPORT_Blacklist
38{
38 /** 39 /**
39 * Connection to transport service. 40 * Connection to transport service.
40 */ 41 */
@@ -64,7 +65,7 @@ struct GNUNET_TRANSPORT_Blacklist {
64 * @param br overall handle 65 * @param br overall handle
65 */ 66 */
66static void 67static void
67reconnect(struct GNUNET_TRANSPORT_Blacklist *br); 68reconnect (struct GNUNET_TRANSPORT_Blacklist *br);
68 69
69 70
70/** 71/**
@@ -74,21 +75,21 @@ reconnect(struct GNUNET_TRANSPORT_Blacklist *br);
74 * @param bm query 75 * @param bm query
75 */ 76 */
76static void 77static void
77handle_query(void *cls, 78handle_query (void *cls,
78 const struct BlacklistMessage *bm) 79 const struct BlacklistMessage *bm)
79{ 80{
80 struct GNUNET_TRANSPORT_Blacklist *br = cls; 81 struct GNUNET_TRANSPORT_Blacklist *br = cls;
81 struct GNUNET_MQ_Envelope *env; 82 struct GNUNET_MQ_Envelope *env;
82 struct BlacklistMessage *res; 83 struct BlacklistMessage *res;
83 84
84 GNUNET_break(0 == ntohl(bm->is_allowed)); 85 GNUNET_break (0 == ntohl (bm->is_allowed));
85 env = GNUNET_MQ_msg(res, 86 env = GNUNET_MQ_msg (res,
86 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY); 87 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY);
87 res->is_allowed = htonl(br->cb(br->cb_cls, 88 res->is_allowed = htonl (br->cb (br->cb_cls,
88 &bm->peer)); 89 &bm->peer));
89 res->peer = bm->peer; 90 res->peer = bm->peer;
90 GNUNET_MQ_send(br->mq, 91 GNUNET_MQ_send (br->mq,
91 env); 92 env);
92} 93}
93 94
94/** 95/**
@@ -100,12 +101,12 @@ handle_query(void *cls,
100 * @param error error code 101 * @param error error code
101 */ 102 */
102static void 103static void
103mq_error_handler(void *cls, 104mq_error_handler (void *cls,
104 enum GNUNET_MQ_Error error) 105 enum GNUNET_MQ_Error error)
105{ 106{
106 struct GNUNET_TRANSPORT_Blacklist *br = cls; 107 struct GNUNET_TRANSPORT_Blacklist *br = cls;
107 108
108 reconnect(br); 109 reconnect (br);
109} 110}
110 111
111 112
@@ -115,31 +116,31 @@ mq_error_handler(void *cls,
115 * @param br overall handle 116 * @param br overall handle
116 */ 117 */
117static void 118static void
118reconnect(struct GNUNET_TRANSPORT_Blacklist *br) 119reconnect (struct GNUNET_TRANSPORT_Blacklist *br)
119{ 120{
120 struct GNUNET_MQ_MessageHandler handlers[] = { 121 struct GNUNET_MQ_MessageHandler handlers[] = {
121 GNUNET_MQ_hd_fixed_size(query, 122 GNUNET_MQ_hd_fixed_size (query,
122 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY, 123 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY,
123 struct BlacklistMessage, 124 struct BlacklistMessage,
124 br), 125 br),
125 GNUNET_MQ_handler_end() 126 GNUNET_MQ_handler_end ()
126 }; 127 };
127 struct GNUNET_MQ_Envelope *env; 128 struct GNUNET_MQ_Envelope *env;
128 struct GNUNET_MessageHeader *req; 129 struct GNUNET_MessageHeader *req;
129 130
130 if (NULL != br->mq) 131 if (NULL != br->mq)
131 GNUNET_MQ_destroy(br->mq); 132 GNUNET_MQ_destroy (br->mq);
132 br->mq = GNUNET_CLIENT_connect(br->cfg, 133 br->mq = GNUNET_CLIENT_connect (br->cfg,
133 "transport", 134 "transport",
134 handlers, 135 handlers,
135 &mq_error_handler, 136 &mq_error_handler,
136 br); 137 br);
137 if (NULL == br->mq) 138 if (NULL == br->mq)
138 return; 139 return;
139 env = GNUNET_MQ_msg(req, 140 env = GNUNET_MQ_msg (req,
140 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT); 141 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT);
141 GNUNET_MQ_send(br->mq, 142 GNUNET_MQ_send (br->mq,
142 env); 143 env);
143} 144}
144 145
145 146
@@ -158,22 +159,22 @@ reconnect(struct GNUNET_TRANSPORT_Blacklist *br)
158 * @return NULL on error, otherwise handle for cancellation 159 * @return NULL on error, otherwise handle for cancellation
159 */ 160 */
160struct GNUNET_TRANSPORT_Blacklist * 161struct GNUNET_TRANSPORT_Blacklist *
161GNUNET_TRANSPORT_blacklist(const struct GNUNET_CONFIGURATION_Handle *cfg, 162GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
162 GNUNET_TRANSPORT_BlacklistCallback cb, 163 GNUNET_TRANSPORT_BlacklistCallback cb,
163 void *cb_cls) 164 void *cb_cls)
164{ 165{
165 struct GNUNET_TRANSPORT_Blacklist *br; 166 struct GNUNET_TRANSPORT_Blacklist *br;
166 167
167 br = GNUNET_new(struct GNUNET_TRANSPORT_Blacklist); 168 br = GNUNET_new (struct GNUNET_TRANSPORT_Blacklist);
168 br->cfg = cfg; 169 br->cfg = cfg;
169 br->cb = cb; 170 br->cb = cb;
170 br->cb_cls = cb_cls; 171 br->cb_cls = cb_cls;
171 reconnect(br); 172 reconnect (br);
172 if (NULL == br->mq) 173 if (NULL == br->mq)
173 { 174 {
174 GNUNET_free(br); 175 GNUNET_free (br);
175 return NULL; 176 return NULL;
176 } 177 }
177 return br; 178 return br;
178} 179}
179 180
@@ -185,10 +186,10 @@ GNUNET_TRANSPORT_blacklist(const struct GNUNET_CONFIGURATION_Handle *cfg,
185 * @param br handle of the request that is to be cancelled 186 * @param br handle of the request that is to be cancelled
186 */ 187 */
187void 188void
188GNUNET_TRANSPORT_blacklist_cancel(struct GNUNET_TRANSPORT_Blacklist *br) 189GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br)
189{ 190{
190 GNUNET_MQ_destroy(br->mq); 191 GNUNET_MQ_destroy (br->mq);
191 GNUNET_free(br); 192 GNUNET_free (br);
192} 193}
193 194
194 195
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 @@
32#include "gnunet_transport_service.h" 32#include "gnunet_transport_service.h"
33#include "transport.h" 33#include "transport.h"
34 34
35#define LOG(kind, ...) GNUNET_log_from(kind, "transport-api-core", __VA_ARGS__) 35#define LOG(kind, ...) GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__)
36 36
37/** 37/**
38 * If we could not send any payload to a peer for this amount of 38 * If we could not send any payload to a peer for this amount of
@@ -49,7 +49,8 @@
49/** 49/**
50 * Entry in hash table of all of our current (connected) neighbours. 50 * Entry in hash table of all of our current (connected) neighbours.
51 */ 51 */
52struct Neighbour { 52struct Neighbour
53{
53 /** 54 /**
54 * Overall transport handle. 55 * Overall transport handle.
55 */ 56 */
@@ -118,7 +119,8 @@ struct Neighbour {
118 * Handle for the transport service (includes all of the 119 * Handle for the transport service (includes all of the
119 * state for the transport service). 120 * state for the transport service).
120 */ 121 */
121struct GNUNET_TRANSPORT_CoreHandle { 122struct GNUNET_TRANSPORT_CoreHandle
123{
122 /** 124 /**
123 * Closure for the callbacks. 125 * Closure for the callbacks.
124 */ 126 */
@@ -200,7 +202,7 @@ struct GNUNET_TRANSPORT_CoreHandle {
200 * @param h transport service to reconnect 202 * @param h transport service to reconnect
201 */ 203 */
202static void 204static void
203disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h); 205disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h);
204 206
205 207
206/** 208/**
@@ -211,10 +213,10 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h);
211 * @return NULL if no such peer entry exists 213 * @return NULL if no such peer entry exists
212 */ 214 */
213static struct Neighbour * 215static struct Neighbour *
214neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, 216neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h,
215 const struct GNUNET_PeerIdentity *peer) 217 const struct GNUNET_PeerIdentity *peer)
216{ 218{
217 return GNUNET_CONTAINER_multipeermap_get(h->neighbours, peer); 219 return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer);
218} 220}
219 221
220 222
@@ -225,17 +227,17 @@ neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h,
225 * @param cls the `struct Neighbour` that has excess bandwidth 227 * @param cls the `struct Neighbour` that has excess bandwidth
226 */ 228 */
227static void 229static void
228notify_excess_cb(void *cls) 230notify_excess_cb (void *cls)
229{ 231{
230 struct Neighbour *n = cls; 232 struct Neighbour *n = cls;
231 struct GNUNET_TRANSPORT_CoreHandle *h = n->h; 233 struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
232 234
233 LOG(GNUNET_ERROR_TYPE_DEBUG, 235 LOG (GNUNET_ERROR_TYPE_DEBUG,
234 "Notifying CORE that more bandwidth is available for %s\n", 236 "Notifying CORE that more bandwidth is available for %s\n",
235 GNUNET_i2s(&n->id)); 237 GNUNET_i2s (&n->id));
236 238
237 if (NULL != h->neb_cb) 239 if (NULL != h->neb_cb)
238 h->neb_cb(h->cls, &n->id, n->handlers_cls); 240 h->neb_cb (h->cls, &n->id, n->handlers_cls);
239} 241}
240 242
241 243
@@ -250,33 +252,33 @@ notify_excess_cb(void *cls)
250 * #GNUNET_NO if not. 252 * #GNUNET_NO if not.
251 */ 253 */
252static int 254static int
253neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 255neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
254{ 256{
255 struct GNUNET_TRANSPORT_CoreHandle *handle = cls; 257 struct GNUNET_TRANSPORT_CoreHandle *handle = cls;
256 struct Neighbour *n = value; 258 struct Neighbour *n = value;
257 259
258 LOG(GNUNET_ERROR_TYPE_DEBUG, 260 LOG (GNUNET_ERROR_TYPE_DEBUG,
259 "Dropping entry for neighbour `%s'.\n", 261 "Dropping entry for neighbour `%s'.\n",
260 GNUNET_i2s(key)); 262 GNUNET_i2s (key));
261 GNUNET_BANDWIDTH_tracker_notification_stop(&n->out_tracker); 263 GNUNET_BANDWIDTH_tracker_notification_stop (&n->out_tracker);
262 if (NULL != handle->nd_cb) 264 if (NULL != handle->nd_cb)
263 handle->nd_cb(handle->cls, &n->id, n->handlers_cls); 265 handle->nd_cb (handle->cls, &n->id, n->handlers_cls);
264 if (NULL != n->timeout_task) 266 if (NULL != n->timeout_task)
265 { 267 {
266 GNUNET_SCHEDULER_cancel(n->timeout_task); 268 GNUNET_SCHEDULER_cancel (n->timeout_task);
267 n->timeout_task = NULL; 269 n->timeout_task = NULL;
268 } 270 }
269 if (NULL != n->env) 271 if (NULL != n->env)
270 { 272 {
271 GNUNET_MQ_send_cancel(n->env); 273 GNUNET_MQ_send_cancel (n->env);
272 n->env = NULL; 274 n->env = NULL;
273 } 275 }
274 GNUNET_MQ_destroy(n->mq); 276 GNUNET_MQ_destroy (n->mq);
275 GNUNET_assert(NULL == n->mq); 277 GNUNET_assert (NULL == n->mq);
276 GNUNET_assert( 278 GNUNET_assert (
277 GNUNET_YES == 279 GNUNET_YES ==
278 GNUNET_CONTAINER_multipeermap_remove(handle->neighbours, key, n)); 280 GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n));
279 GNUNET_free(n); 281 GNUNET_free (n);
280 return GNUNET_YES; 282 return GNUNET_YES;
281} 283}
282 284
@@ -291,14 +293,14 @@ neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
291 * @param error error code 293 * @param error error code
292 */ 294 */
293static void 295static void
294mq_error_handler(void *cls, enum GNUNET_MQ_Error error) 296mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
295{ 297{
296 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 298 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
297 299
298 LOG(GNUNET_ERROR_TYPE_ERROR, 300 LOG (GNUNET_ERROR_TYPE_ERROR,
299 "Error receiving from transport service (%d), disconnecting temporarily.\n", 301 "Error receiving from transport service (%d), disconnecting temporarily.\n",
300 error); 302 error);
301 disconnect_and_schedule_reconnect(h); 303 disconnect_and_schedule_reconnect (h);
302} 304}
303 305
304 306
@@ -310,16 +312,16 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
310 * @return #GNUNET_OK if message is well-formed 312 * @return #GNUNET_OK if message is well-formed
311 */ 313 */
312static int 314static int
313check_hello(void *cls, const struct GNUNET_MessageHeader *msg) 315check_hello (void *cls, const struct GNUNET_MessageHeader *msg)
314{ 316{
315 struct GNUNET_PeerIdentity me; 317 struct GNUNET_PeerIdentity me;
316 318
317 if (GNUNET_OK != 319 if (GNUNET_OK !=
318 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)msg, &me)) 320 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me))
319 { 321 {
320 GNUNET_break(0); 322 GNUNET_break (0);
321 return GNUNET_SYSERR; 323 return GNUNET_SYSERR;
322 } 324 }
323 return GNUNET_OK; 325 return GNUNET_OK;
324} 326}
325 327
@@ -331,7 +333,7 @@ check_hello(void *cls, const struct GNUNET_MessageHeader *msg)
331 * @param msg message received 333 * @param msg message received
332 */ 334 */
333static void 335static void
334handle_hello(void *cls, const struct GNUNET_MessageHeader *msg) 336handle_hello (void *cls, const struct GNUNET_MessageHeader *msg)
335{ 337{
336 /* we do not care => FIXME: signal in options to NEVER send HELLOs! */ 338 /* we do not care => FIXME: signal in options to NEVER send HELLOs! */
337} 339}
@@ -346,13 +348,13 @@ handle_hello(void *cls, const struct GNUNET_MessageHeader *msg)
346 * @param cls the `struct Neighbour` where the message was sent 348 * @param cls the `struct Neighbour` where the message was sent
347 */ 349 */
348static void 350static void
349notify_send_done_fin(void *cls) 351notify_send_done_fin (void *cls)
350{ 352{
351 struct Neighbour *n = cls; 353 struct Neighbour *n = cls;
352 354
353 n->timeout_task = NULL; 355 n->timeout_task = NULL;
354 n->is_ready = GNUNET_YES; 356 n->is_ready = GNUNET_YES;
355 GNUNET_MQ_impl_send_continue(n->mq); 357 GNUNET_MQ_impl_send_continue (n->mq);
356} 358}
357 359
358 360
@@ -365,31 +367,31 @@ notify_send_done_fin(void *cls)
365 * @param cls the `struct Neighbour` where the message was sent 367 * @param cls the `struct Neighbour` where the message was sent
366 */ 368 */
367static void 369static void
368notify_send_done(void *cls) 370notify_send_done (void *cls)
369{ 371{
370 struct Neighbour *n = cls; 372 struct Neighbour *n = cls;
371 struct GNUNET_TIME_Relative delay; 373 struct GNUNET_TIME_Relative delay;
372 374
373 n->timeout_task = NULL; 375 n->timeout_task = NULL;
374 if (NULL != n->env) 376 if (NULL != n->env)
375 { 377 {
376 GNUNET_BANDWIDTH_tracker_consume(&n->out_tracker, 378 GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker,
377 n->env_size + n->traffic_overhead); 379 n->env_size + n->traffic_overhead);
378 n->env = NULL; 380 n->env = NULL;
379 n->traffic_overhead = 0; 381 n->traffic_overhead = 0;
380 } 382 }
381 delay = GNUNET_BANDWIDTH_tracker_get_delay(&n->out_tracker, 128); 383 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 128);
382 if (0 == delay.rel_value_us) 384 if (0 == delay.rel_value_us)
383 { 385 {
384 n->is_ready = GNUNET_YES; 386 n->is_ready = GNUNET_YES;
385 GNUNET_MQ_impl_send_continue(n->mq); 387 GNUNET_MQ_impl_send_continue (n->mq);
386 return; 388 return;
387 } 389 }
388 GNUNET_MQ_impl_send_in_flight(n->mq); 390 GNUNET_MQ_impl_send_in_flight (n->mq);
389 /* cannot send even a small message without violating 391 /* cannot send even a small message without violating
390 quota, wait a before allowing MQ to send next message */ 392 quota, wait a before allowing MQ to send next message */
391 n->timeout_task = 393 n->timeout_task =
392 GNUNET_SCHEDULER_add_delayed(delay, &notify_send_done_fin, n); 394 GNUNET_SCHEDULER_add_delayed (delay, &notify_send_done_fin, n);
393} 395}
394 396
395 397
@@ -404,44 +406,44 @@ notify_send_done(void *cls)
404 * @param impl_state state of the implementation 406 * @param impl_state state of the implementation
405 */ 407 */
406static void 408static void
407mq_send_impl(struct GNUNET_MQ_Handle *mq, 409mq_send_impl (struct GNUNET_MQ_Handle *mq,
408 const struct GNUNET_MessageHeader *msg, 410 const struct GNUNET_MessageHeader *msg,
409 void *impl_state) 411 void *impl_state)
410{ 412{
411 struct Neighbour *n = impl_state; 413 struct Neighbour *n = impl_state;
412 struct GNUNET_TRANSPORT_CoreHandle *h = n->h; 414 struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
413 struct OutboundMessage *obm; 415 struct OutboundMessage *obm;
414 uint16_t msize; 416 uint16_t msize;
415 417
416 GNUNET_assert(GNUNET_YES == n->is_ready); 418 GNUNET_assert (GNUNET_YES == n->is_ready);
417 msize = ntohs(msg->size); 419 msize = ntohs (msg->size);
418 if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm)) 420 if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm))
419 { 421 {
420 GNUNET_break(0); 422 GNUNET_break (0);
421 GNUNET_MQ_impl_send_continue(mq); 423 GNUNET_MQ_impl_send_continue (mq);
422 return; 424 return;
423 } 425 }
424 GNUNET_assert(NULL == n->env); 426 GNUNET_assert (NULL == n->env);
425 n->env = 427 n->env =
426 GNUNET_MQ_msg_nested_mh(obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); 428 GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg);
427 { 429 {
428 struct GNUNET_MQ_Envelope *env; 430 struct GNUNET_MQ_Envelope *env;
429 431
430 env = GNUNET_MQ_get_current_envelope(mq); 432 env = GNUNET_MQ_get_current_envelope (mq);
431 obm->priority = htonl((uint32_t)GNUNET_MQ_env_get_options(env)); 433 obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env));
432 } 434 }
433 obm->timeout = GNUNET_TIME_relative_hton( 435 obm->timeout = GNUNET_TIME_relative_hton (
434 GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */ 436 GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */
435 obm->peer = n->id; 437 obm->peer = n->id;
436 GNUNET_assert(NULL == n->timeout_task); 438 GNUNET_assert (NULL == n->timeout_task);
437 n->is_ready = GNUNET_NO; 439 n->is_ready = GNUNET_NO;
438 n->env_size = ntohs(msg->size); 440 n->env_size = ntohs (msg->size);
439 GNUNET_MQ_notify_sent(n->env, &notify_send_done, n); 441 GNUNET_MQ_notify_sent (n->env, &notify_send_done, n);
440 GNUNET_MQ_send(h->mq, n->env); 442 GNUNET_MQ_send (h->mq, n->env);
441 LOG(GNUNET_ERROR_TYPE_DEBUG, 443 LOG (GNUNET_ERROR_TYPE_DEBUG,
442 "Queued message of type %u for neighbour `%s'.\n", 444 "Queued message of type %u for neighbour `%s'.\n",
443 ntohs(msg->type), 445 ntohs (msg->type),
444 GNUNET_i2s(&n->id)); 446 GNUNET_i2s (&n->id));
445} 447}
446 448
447 449
@@ -453,11 +455,11 @@ mq_send_impl(struct GNUNET_MQ_Handle *mq,
453 * @param impl_state state of the implementation 455 * @param impl_state state of the implementation
454 */ 456 */
455static void 457static void
456mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) 458mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
457{ 459{
458 struct Neighbour *n = impl_state; 460 struct Neighbour *n = impl_state;
459 461
460 GNUNET_assert(mq == n->mq); 462 GNUNET_assert (mq == n->mq);
461 n->mq = NULL; 463 n->mq = NULL;
462} 464}
463 465
@@ -470,16 +472,16 @@ mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
470 * @param impl_state state specific to the implementation 472 * @param impl_state state specific to the implementation
471 */ 473 */
472static void 474static void
473mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) 475mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
474{ 476{
475 struct Neighbour *n = impl_state; 477 struct Neighbour *n = impl_state;
476 478
477 GNUNET_assert(GNUNET_NO == n->is_ready); 479 GNUNET_assert (GNUNET_NO == n->is_ready);
478 if (NULL != n->env) 480 if (NULL != n->env)
479 { 481 {
480 GNUNET_MQ_send_cancel(n->env); 482 GNUNET_MQ_send_cancel (n->env);
481 n->env = NULL; 483 n->env = NULL;
482 } 484 }
483 485
484 n->is_ready = GNUNET_YES; 486 n->is_ready = GNUNET_YES;
485} 487}
@@ -494,11 +496,11 @@ mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
494 * @param error error code 496 * @param error error code
495 */ 497 */
496static void 498static void
497peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) 499peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
498{ 500{
499 /* struct Neighbour *n = cls; */ 501 /* struct Neighbour *n = cls; */
500 502
501 GNUNET_break_op(0); 503 GNUNET_break_op (0);
502} 504}
503 505
504 506
@@ -509,16 +511,16 @@ peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
509 * @param cls the `struct Neighbour` for which the timeout changed 511 * @param cls the `struct Neighbour` for which the timeout changed
510 */ 512 */
511static void 513static void
512outbound_bw_tracker_update(void *cls) 514outbound_bw_tracker_update (void *cls)
513{ 515{
514 struct Neighbour *n = cls; 516 struct Neighbour *n = cls;
515 struct GNUNET_TIME_Relative delay; 517 struct GNUNET_TIME_Relative delay;
516 518
517 if (NULL == n->timeout_task) 519 if (NULL == n->timeout_task)
518 return; 520 return;
519 delay = GNUNET_BANDWIDTH_tracker_get_delay(&n->out_tracker, 128); 521 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 128);
520 GNUNET_SCHEDULER_cancel(n->timeout_task); 522 GNUNET_SCHEDULER_cancel (n->timeout_task);
521 n->timeout_task = GNUNET_SCHEDULER_add_delayed(delay, &notify_send_done, n); 523 n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, &notify_send_done, n);
522} 524}
523 525
524 526
@@ -529,54 +531,54 @@ outbound_bw_tracker_update(void *cls)
529 * @param cim message received 531 * @param cim message received
530 */ 532 */
531static void 533static void
532handle_connect(void *cls, const struct ConnectInfoMessage *cim) 534handle_connect (void *cls, const struct ConnectInfoMessage *cim)
533{ 535{
534 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 536 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
535 struct Neighbour *n; 537 struct Neighbour *n;
536 538
537 LOG(GNUNET_ERROR_TYPE_DEBUG, 539 LOG (GNUNET_ERROR_TYPE_DEBUG,
538 "Receiving CONNECT message for `%s' with quota %u\n", 540 "Receiving CONNECT message for `%s' with quota %u\n",
539 GNUNET_i2s(&cim->id), 541 GNUNET_i2s (&cim->id),
540 ntohl(cim->quota_out.value__)); 542 ntohl (cim->quota_out.value__));
541 n = neighbour_find(h, &cim->id); 543 n = neighbour_find (h, &cim->id);
542 if (NULL != n) 544 if (NULL != n)
543 { 545 {
544 GNUNET_break(0); /* FIXME: this assertion seems to fail sometimes!? */ 546 GNUNET_break (0); /* FIXME: this assertion seems to fail sometimes!? */
545 disconnect_and_schedule_reconnect(h); 547 disconnect_and_schedule_reconnect (h);
546 return; 548 return;
547 } 549 }
548 n = GNUNET_new(struct Neighbour); 550 n = GNUNET_new (struct Neighbour);
549 n->id = cim->id; 551 n->id = cim->id;
550 n->h = h; 552 n->h = h;
551 n->is_ready = GNUNET_YES; 553 n->is_ready = GNUNET_YES;
552 n->traffic_overhead = 0; 554 n->traffic_overhead = 0;
553 GNUNET_BANDWIDTH_tracker_init2(&n->out_tracker, 555 GNUNET_BANDWIDTH_tracker_init2 (&n->out_tracker,
554 &outbound_bw_tracker_update, 556 &outbound_bw_tracker_update,
555 n, 557 n,
556 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 558 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
557 MAX_BANDWIDTH_CARRY_S, 559 MAX_BANDWIDTH_CARRY_S,
558 &notify_excess_cb, 560 &notify_excess_cb,
559 n); 561 n);
560 GNUNET_assert(GNUNET_OK == 562 GNUNET_assert (GNUNET_OK ==
561 GNUNET_CONTAINER_multipeermap_put( 563 GNUNET_CONTAINER_multipeermap_put (
562 h->neighbours, 564 h->neighbours,
563 &n->id, 565 &n->id,
564 n, 566 n,
565 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 567 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
566 568
567 GNUNET_BANDWIDTH_tracker_update_quota(&n->out_tracker, cim->quota_out); 569 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out);
568 n->mq = GNUNET_MQ_queue_for_callbacks(&mq_send_impl, 570 n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl,
569 &mq_destroy_impl, 571 &mq_destroy_impl,
570 &mq_cancel_impl, 572 &mq_cancel_impl,
571 n, 573 n,
572 h->handlers, 574 h->handlers,
573 &peer_mq_error_handler, 575 &peer_mq_error_handler,
574 n); 576 n);
575 if (NULL != h->nc_cb) 577 if (NULL != h->nc_cb)
576 { 578 {
577 n->handlers_cls = h->nc_cb(h->cls, &n->id, n->mq); 579 n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq);
578 GNUNET_MQ_set_handlers_closure(n->mq, n->handlers_cls); 580 GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls);
579 } 581 }
580} 582}
581 583
582 584
@@ -587,23 +589,23 @@ handle_connect(void *cls, const struct ConnectInfoMessage *cim)
587 * @param dim message received 589 * @param dim message received
588 */ 590 */
589static void 591static void
590handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim) 592handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim)
591{ 593{
592 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 594 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
593 struct Neighbour *n; 595 struct Neighbour *n;
594 596
595 GNUNET_break(ntohl(dim->reserved) == 0); 597 GNUNET_break (ntohl (dim->reserved) == 0);
596 LOG(GNUNET_ERROR_TYPE_DEBUG, 598 LOG (GNUNET_ERROR_TYPE_DEBUG,
597 "Receiving DISCONNECT message for `%s'.\n", 599 "Receiving DISCONNECT message for `%s'.\n",
598 GNUNET_i2s(&dim->peer)); 600 GNUNET_i2s (&dim->peer));
599 n = neighbour_find(h, &dim->peer); 601 n = neighbour_find (h, &dim->peer);
600 if (NULL == n) 602 if (NULL == n)
601 { 603 {
602 GNUNET_break(0); 604 GNUNET_break (0);
603 disconnect_and_schedule_reconnect(h); 605 disconnect_and_schedule_reconnect (h);
604 return; 606 return;
605 } 607 }
606 GNUNET_assert(GNUNET_YES == neighbour_delete(h, &dim->peer, n)); 608 GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n));
607} 609}
608 610
609 611
@@ -614,36 +616,36 @@ handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim)
614 * @param okm message received 616 * @param okm message received
615 */ 617 */
616static void 618static void
617handle_send_ok(void *cls, const struct SendOkMessage *okm) 619handle_send_ok (void *cls, const struct SendOkMessage *okm)
618{ 620{
619 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 621 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
620 struct Neighbour *n; 622 struct Neighbour *n;
621 uint32_t bytes_msg; 623 uint32_t bytes_msg;
622 uint32_t bytes_physical; 624 uint32_t bytes_physical;
623 625
624 bytes_msg = ntohl(okm->bytes_msg); 626 bytes_msg = ntohl (okm->bytes_msg);
625 bytes_physical = ntohl(okm->bytes_physical); 627 bytes_physical = ntohl (okm->bytes_physical);
626 LOG(GNUNET_ERROR_TYPE_DEBUG, 628 LOG (GNUNET_ERROR_TYPE_DEBUG,
627 "Receiving SEND_OK message, transmission to %s %s.\n", 629 "Receiving SEND_OK message, transmission to %s %s.\n",
628 GNUNET_i2s(&okm->peer), 630 GNUNET_i2s (&okm->peer),
629 ntohl(okm->success) == GNUNET_OK ? "succeeded" : "failed"); 631 ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed");
630 n = neighbour_find(h, &okm->peer); 632 n = neighbour_find (h, &okm->peer);
631 if (NULL == n) 633 if (NULL == n)
632 { 634 {
633 /* We should never get a 'SEND_OK' for a peer that we are not 635 /* We should never get a 'SEND_OK' for a peer that we are not
634 connected to */ 636 connected to */
635 GNUNET_break(0); 637 GNUNET_break (0);
636 disconnect_and_schedule_reconnect(h); 638 disconnect_and_schedule_reconnect (h);
637 return; 639 return;
638 } 640 }
639 if (bytes_physical > bytes_msg) 641 if (bytes_physical > bytes_msg)
640 { 642 {
641 LOG(GNUNET_ERROR_TYPE_DEBUG, 643 LOG (GNUNET_ERROR_TYPE_DEBUG,
642 "Overhead for %u byte message was %u\n", 644 "Overhead for %u byte message was %u\n",
643 bytes_msg, 645 bytes_msg,
644 bytes_physical - bytes_msg); 646 bytes_physical - bytes_msg);
645 n->traffic_overhead += bytes_physical - bytes_msg; 647 n->traffic_overhead += bytes_physical - bytes_msg;
646 } 648 }
647} 649}
648 650
649 651
@@ -654,23 +656,23 @@ handle_send_ok(void *cls, const struct SendOkMessage *okm)
654 * @param im message received 656 * @param im message received
655 */ 657 */
656static int 658static int
657check_recv(void *cls, const struct InboundMessage *im) 659check_recv (void *cls, const struct InboundMessage *im)
658{ 660{
659 const struct GNUNET_MessageHeader *imm; 661 const struct GNUNET_MessageHeader *imm;
660 uint16_t size; 662 uint16_t size;
661 663
662 size = ntohs(im->header.size) - sizeof(*im); 664 size = ntohs (im->header.size) - sizeof(*im);
663 if (size < sizeof(struct GNUNET_MessageHeader)) 665 if (size < sizeof(struct GNUNET_MessageHeader))
664 { 666 {
665 GNUNET_break(0); 667 GNUNET_break (0);
666 return GNUNET_SYSERR; 668 return GNUNET_SYSERR;
667 } 669 }
668 imm = (const struct GNUNET_MessageHeader *)&im[1]; 670 imm = (const struct GNUNET_MessageHeader *) &im[1];
669 if (ntohs(imm->size) != size) 671 if (ntohs (imm->size) != size)
670 { 672 {
671 GNUNET_break(0); 673 GNUNET_break (0);
672 return GNUNET_SYSERR; 674 return GNUNET_SYSERR;
673 } 675 }
674 return GNUNET_OK; 676 return GNUNET_OK;
675} 677}
676 678
@@ -682,27 +684,27 @@ check_recv(void *cls, const struct InboundMessage *im)
682 * @param im message received 684 * @param im message received
683 */ 685 */
684static void 686static void
685handle_recv(void *cls, const struct InboundMessage *im) 687handle_recv (void *cls, const struct InboundMessage *im)
686{ 688{
687 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 689 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
688 const struct GNUNET_MessageHeader *imm = 690 const struct GNUNET_MessageHeader *imm =
689 (const struct GNUNET_MessageHeader *)&im[1]; 691 (const struct GNUNET_MessageHeader *) &im[1];
690 struct Neighbour *n; 692 struct Neighbour *n;
691 693
692 LOG(GNUNET_ERROR_TYPE_DEBUG, 694 LOG (GNUNET_ERROR_TYPE_DEBUG,
693 "Received message of type %u with %u bytes from `%s'.\n", 695 "Received message of type %u with %u bytes from `%s'.\n",
694 (unsigned int)ntohs(imm->type), 696 (unsigned int) ntohs (imm->type),
695 (unsigned int)ntohs(imm->size), 697 (unsigned int) ntohs (imm->size),
696 GNUNET_i2s(&im->peer)); 698 GNUNET_i2s (&im->peer));
697 n = neighbour_find(h, &im->peer); 699 n = neighbour_find (h, &im->peer);
698 if (NULL == n) 700 if (NULL == n)
699 { 701 {
700 GNUNET_break(0); 702 GNUNET_break (0);
701 disconnect_and_schedule_reconnect(h); 703 disconnect_and_schedule_reconnect (h);
702 return; 704 return;
703 } 705 }
704 h->rom_pending++; 706 h->rom_pending++;
705 GNUNET_MQ_inject_message(n->mq, imm); 707 GNUNET_MQ_inject_message (n->mq, imm);
706} 708}
707 709
708 710
@@ -713,24 +715,24 @@ handle_recv(void *cls, const struct InboundMessage *im)
713 * @param msg message received 715 * @param msg message received
714 */ 716 */
715static void 717static void
716handle_set_quota(void *cls, const struct QuotaSetMessage *qm) 718handle_set_quota (void *cls, const struct QuotaSetMessage *qm)
717{ 719{
718 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 720 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
719 struct Neighbour *n; 721 struct Neighbour *n;
720 722
721 LOG(GNUNET_ERROR_TYPE_DEBUG, 723 LOG (GNUNET_ERROR_TYPE_DEBUG,
722 "Receiving SET_QUOTA message for `%s' with quota %u\n", 724 "Receiving SET_QUOTA message for `%s' with quota %u\n",
723 GNUNET_i2s(&qm->peer), 725 GNUNET_i2s (&qm->peer),
724 ntohl(qm->quota.value__)); 726 ntohl (qm->quota.value__));
725 n = neighbour_find(h, &qm->peer); 727 n = neighbour_find (h, &qm->peer);
726 if (NULL == n) 728 if (NULL == n)
727 { 729 {
728 GNUNET_break( 730 GNUNET_break (
729 0); /* FIXME: julius reports this assertion fails sometimes? */ 731 0); /* FIXME: julius reports this assertion fails sometimes? */
730 disconnect_and_schedule_reconnect(h); 732 disconnect_and_schedule_reconnect (h);
731 return; 733 return;
732 } 734 }
733 GNUNET_BANDWIDTH_tracker_update_quota(&n->out_tracker, qm->quota); 735 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, qm->quota);
734} 736}
735 737
736 738
@@ -740,55 +742,55 @@ handle_set_quota(void *cls, const struct QuotaSetMessage *qm)
740 * @param cls the handle to the transport service 742 * @param cls the handle to the transport service
741 */ 743 */
742static void 744static void
743reconnect(void *cls) 745reconnect (void *cls)
744{ 746{
745 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 747 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
746 struct GNUNET_MQ_MessageHandler handlers[] = 748 struct GNUNET_MQ_MessageHandler handlers[] =
747 { GNUNET_MQ_hd_var_size(hello, 749 { GNUNET_MQ_hd_var_size (hello,
748 GNUNET_MESSAGE_TYPE_HELLO, 750 GNUNET_MESSAGE_TYPE_HELLO,
749 struct GNUNET_MessageHeader, 751 struct GNUNET_MessageHeader,
750 h), 752 h),
751 GNUNET_MQ_hd_fixed_size(connect, 753 GNUNET_MQ_hd_fixed_size (connect,
752 GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, 754 GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT,
753 struct ConnectInfoMessage, 755 struct ConnectInfoMessage,
754 h), 756 h),
755 GNUNET_MQ_hd_fixed_size(disconnect, 757 GNUNET_MQ_hd_fixed_size (disconnect,
756 GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, 758 GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT,
757 struct DisconnectInfoMessage, 759 struct DisconnectInfoMessage,
758 h), 760 h),
759 GNUNET_MQ_hd_fixed_size(send_ok, 761 GNUNET_MQ_hd_fixed_size (send_ok,
760 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, 762 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK,
761 struct SendOkMessage, 763 struct SendOkMessage,
762 h), 764 h),
763 GNUNET_MQ_hd_var_size(recv, 765 GNUNET_MQ_hd_var_size (recv,
764 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, 766 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV,
765 struct InboundMessage, 767 struct InboundMessage,
766 h), 768 h),
767 GNUNET_MQ_hd_fixed_size(set_quota, 769 GNUNET_MQ_hd_fixed_size (set_quota,
768 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, 770 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA,
769 struct QuotaSetMessage, 771 struct QuotaSetMessage,
770 h), 772 h),
771 GNUNET_MQ_handler_end() }; 773 GNUNET_MQ_handler_end () };
772 struct GNUNET_MQ_Envelope *env; 774 struct GNUNET_MQ_Envelope *env;
773 struct StartMessage *s; 775 struct StartMessage *s;
774 uint32_t options; 776 uint32_t options;
775 777
776 h->reconnect_task = NULL; 778 h->reconnect_task = NULL;
777 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); 779 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
778 GNUNET_assert(NULL == h->mq); 780 GNUNET_assert (NULL == h->mq);
779 h->mq = 781 h->mq =
780 GNUNET_CLIENT_connect(h->cfg, "transport", handlers, &mq_error_handler, h); 782 GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h);
781 if (NULL == h->mq) 783 if (NULL == h->mq)
782 return; 784 return;
783 env = GNUNET_MQ_msg(s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); 785 env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START);
784 options = 0; 786 options = 0;
785 if (h->check_self) 787 if (h->check_self)
786 options |= 1; 788 options |= 1;
787 if (NULL != h->handlers) 789 if (NULL != h->handlers)
788 options |= 2; 790 options |= 2;
789 s->options = htonl(options); 791 s->options = htonl (options);
790 s->self = h->self; 792 s->self = h->self;
791 GNUNET_MQ_send(h->mq, env); 793 GNUNET_MQ_send (h->mq, env);
792} 794}
793 795
794 796
@@ -799,22 +801,22 @@ reconnect(void *cls)
799 * @param h transport service to reconnect 801 * @param h transport service to reconnect
800 */ 802 */
801static void 803static void
802disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h) 804disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h)
803{ 805{
804 GNUNET_assert(NULL == h->reconnect_task); 806 GNUNET_assert (NULL == h->reconnect_task);
805 /* Forget about all neighbours that we used to be connected to */ 807 /* Forget about all neighbours that we used to be connected to */
806 GNUNET_CONTAINER_multipeermap_iterate(h->neighbours, &neighbour_delete, h); 808 GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h);
807 if (NULL != h->mq) 809 if (NULL != h->mq)
808 { 810 {
809 GNUNET_MQ_destroy(h->mq); 811 GNUNET_MQ_destroy (h->mq);
810 h->mq = NULL; 812 h->mq = NULL;
811 } 813 }
812 LOG(GNUNET_ERROR_TYPE_DEBUG, 814 LOG (GNUNET_ERROR_TYPE_DEBUG,
813 "Scheduling task to reconnect to transport service in %s.\n", 815 "Scheduling task to reconnect to transport service in %s.\n",
814 GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); 816 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES));
815 h->reconnect_task = 817 h->reconnect_task =
816 GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); 818 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
817 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); 819 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
818} 820}
819 821
820 822
@@ -826,12 +828,12 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
826 * @return NULL if disconnected, otherwise message queue for @a peer 828 * @return NULL if disconnected, otherwise message queue for @a peer
827 */ 829 */
828struct GNUNET_MQ_Handle * 830struct GNUNET_MQ_Handle *
829GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, 831GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
830 const struct GNUNET_PeerIdentity *peer) 832 const struct GNUNET_PeerIdentity *peer)
831{ 833{
832 struct Neighbour *n; 834 struct Neighbour *n;
833 835
834 n = neighbour_find(handle, peer); 836 n = neighbour_find (handle, peer);
835 if (NULL == n) 837 if (NULL == n)
836 return NULL; 838 return NULL;
837 return n->mq; 839 return n->mq;
@@ -853,23 +855,23 @@ GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle,
853 * @return NULL on error 855 * @return NULL on error
854 */ 856 */
855struct GNUNET_TRANSPORT_CoreHandle * 857struct GNUNET_TRANSPORT_CoreHandle *
856GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, 858GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
857 const struct GNUNET_PeerIdentity *self, 859 const struct GNUNET_PeerIdentity *self,
858 const struct GNUNET_MQ_MessageHandler *handlers, 860 const struct GNUNET_MQ_MessageHandler *handlers,
859 void *cls, 861 void *cls,
860 GNUNET_TRANSPORT_NotifyConnect nc, 862 GNUNET_TRANSPORT_NotifyConnect nc,
861 GNUNET_TRANSPORT_NotifyDisconnect nd, 863 GNUNET_TRANSPORT_NotifyDisconnect nd,
862 GNUNET_TRANSPORT_NotifyExcessBandwidth neb) 864 GNUNET_TRANSPORT_NotifyExcessBandwidth neb)
863{ 865{
864 struct GNUNET_TRANSPORT_CoreHandle *h; 866 struct GNUNET_TRANSPORT_CoreHandle *h;
865 unsigned int i; 867 unsigned int i;
866 868
867 h = GNUNET_new(struct GNUNET_TRANSPORT_CoreHandle); 869 h = GNUNET_new (struct GNUNET_TRANSPORT_CoreHandle);
868 if (NULL != self) 870 if (NULL != self)
869 { 871 {
870 h->self = *self; 872 h->self = *self;
871 h->check_self = GNUNET_YES; 873 h->check_self = GNUNET_YES;
872 } 874 }
873 h->cfg = cfg; 875 h->cfg = cfg;
874 h->cls = cls; 876 h->cls = cls;
875 h->nc_cb = nc; 877 h->nc_cb = nc;
@@ -877,24 +879,24 @@ GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg,
877 h->neb_cb = neb; 879 h->neb_cb = neb;
878 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; 880 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
879 if (NULL != handlers) 881 if (NULL != handlers)
880 { 882 {
881 for (i = 0; NULL != handlers[i].cb; i++) 883 for (i = 0; NULL != handlers[i].cb; i++)
882 ; 884 ;
883 h->handlers = GNUNET_new_array(i + 1, struct GNUNET_MQ_MessageHandler); 885 h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler);
884 GNUNET_memcpy(h->handlers, 886 GNUNET_memcpy (h->handlers,
885 handlers, 887 handlers,
886 i * sizeof(struct GNUNET_MQ_MessageHandler)); 888 i * sizeof(struct GNUNET_MQ_MessageHandler));
887 } 889 }
888 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); 890 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n");
889 reconnect(h); 891 reconnect (h);
890 if (NULL == h->mq) 892 if (NULL == h->mq)
891 { 893 {
892 GNUNET_free_non_null(h->handlers); 894 GNUNET_free_non_null (h->handlers);
893 GNUNET_free(h); 895 GNUNET_free (h);
894 return NULL; 896 return NULL;
895 } 897 }
896 h->neighbours = 898 h->neighbours =
897 GNUNET_CONTAINER_multipeermap_create(STARTING_NEIGHBOURS_SIZE, GNUNET_YES); 899 GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES);
898 return h; 900 return h;
899} 901}
900 902
@@ -906,23 +908,23 @@ GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg,
906 * #GNUNET_TRANSPORT_core_connect() 908 * #GNUNET_TRANSPORT_core_connect()
907 */ 909 */
908void 910void
909GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle) 911GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle)
910{ 912{
911 LOG(GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); 913 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
912 /* this disconnects all neighbours... */ 914 /* this disconnects all neighbours... */
913 if (NULL == handle->reconnect_task) 915 if (NULL == handle->reconnect_task)
914 disconnect_and_schedule_reconnect(handle); 916 disconnect_and_schedule_reconnect (handle);
915 /* and now we stop trying to connect again... */ 917 /* and now we stop trying to connect again... */
916 if (NULL != handle->reconnect_task) 918 if (NULL != handle->reconnect_task)
917 { 919 {
918 GNUNET_SCHEDULER_cancel(handle->reconnect_task); 920 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
919 handle->reconnect_task = NULL; 921 handle->reconnect_task = NULL;
920 } 922 }
921 GNUNET_CONTAINER_multipeermap_destroy(handle->neighbours); 923 GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours);
922 handle->neighbours = NULL; 924 handle->neighbours = NULL;
923 GNUNET_free_non_null(handle->handlers); 925 GNUNET_free_non_null (handle->handlers);
924 handle->handlers = NULL; 926 handle->handlers = NULL;
925 GNUNET_free(handle); 927 GNUNET_free (handle);
926} 928}
927 929
928 930
@@ -947,18 +949,18 @@ GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
947 * @param pid which peer was the message from that was fully processed by CORE 949 * @param pid which peer was the message from that was fully processed by CORE
948 */ 950 */
949void 951void
950GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch, 952GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch,
951 const struct GNUNET_PeerIdentity *pid) 953 const struct GNUNET_PeerIdentity *pid)
952{ 954{
953 struct RecvOkMessage *rom; 955 struct RecvOkMessage *rom;
954 struct GNUNET_MQ_Envelope *env; 956 struct GNUNET_MQ_Envelope *env;
955 957
956 GNUNET_assert(ch->rom_pending > 0); 958 GNUNET_assert (ch->rom_pending > 0);
957 ch->rom_pending--; 959 ch->rom_pending--;
958 env = GNUNET_MQ_msg(rom, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); 960 env = GNUNET_MQ_msg (rom, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK);
959 rom->increase_window_delta = htonl(1); 961 rom->increase_window_delta = htonl (1);
960 rom->peer = *pid; 962 rom->peer = *pid;
961 GNUNET_MQ_send(ch->mq, env); 963 GNUNET_MQ_send (ch->mq, env);
962} 964}
963 965
964 966
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 @@
36/** 36/**
37 * Functions to call with this peer's HELLO. 37 * Functions to call with this peer's HELLO.
38 */ 38 */
39struct GNUNET_TRANSPORT_HelloGetHandle { 39struct GNUNET_TRANSPORT_HelloGetHandle
40{
40 /** 41 /**
41 * Our configuration. 42 * Our configuration.
42 */ 43 */
@@ -87,22 +88,22 @@ struct GNUNET_TRANSPORT_HelloGetHandle {
87 * @return #GNUNET_OK if message is well-formed 88 * @return #GNUNET_OK if message is well-formed
88 */ 89 */
89static int 90static int
90check_hello(void *cls, 91check_hello (void *cls,
91 const struct GNUNET_MessageHeader *msg) 92 const struct GNUNET_MessageHeader *msg)
92{ 93{
93 struct GNUNET_PeerIdentity me; 94 struct GNUNET_PeerIdentity me;
94 95
95 if (GNUNET_OK != 96 if (GNUNET_OK !=
96 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)msg, 97 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg,
97 &me)) 98 &me))
98 { 99 {
99 GNUNET_break(0); 100 GNUNET_break (0);
100 return GNUNET_SYSERR; 101 return GNUNET_SYSERR;
101 } 102 }
102 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
103 "Receiving (my own) HELLO message (%u bytes), I am `%s'.\n", 104 "Receiving (my own) HELLO message (%u bytes), I am `%s'.\n",
104 (unsigned int)ntohs(msg->size), 105 (unsigned int) ntohs (msg->size),
105 GNUNET_i2s(&me)); 106 GNUNET_i2s (&me));
106 return GNUNET_OK; 107 return GNUNET_OK;
107} 108}
108 109
@@ -114,13 +115,13 @@ check_hello(void *cls,
114 * @param msg message received 115 * @param msg message received
115 */ 116 */
116static void 117static void
117handle_hello(void *cls, 118handle_hello (void *cls,
118 const struct GNUNET_MessageHeader *msg) 119 const struct GNUNET_MessageHeader *msg)
119{ 120{
120 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; 121 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
121 122
122 ghh->rec(ghh->rec_cls, 123 ghh->rec (ghh->rec_cls,
123 msg); 124 msg);
124} 125}
125 126
126 127
@@ -131,7 +132,7 @@ handle_hello(void *cls,
131 * @param ghh transport service to reconnect 132 * @param ghh transport service to reconnect
132 */ 133 */
133static void 134static void
134schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh); 135schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh);
135 136
136 137
137/** 138/**
@@ -144,16 +145,16 @@ schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh);
144 * @param error error code 145 * @param error error code
145 */ 146 */
146static void 147static void
147mq_error_handler(void *cls, 148mq_error_handler (void *cls,
148 enum GNUNET_MQ_Error error) 149 enum GNUNET_MQ_Error error)
149{ 150{
150 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; 151 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
151 152
152 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Error receiving from transport service, disconnecting temporarily.\n"); 154 "Error receiving from transport service, disconnecting temporarily.\n");
154 GNUNET_MQ_destroy(ghh->mq); 155 GNUNET_MQ_destroy (ghh->mq);
155 ghh->mq = NULL; 156 ghh->mq = NULL;
156 schedule_reconnect(ghh); 157 schedule_reconnect (ghh);
157} 158}
158 159
159 160
@@ -163,35 +164,35 @@ mq_error_handler(void *cls,
163 * @param cls the handle to the transport service 164 * @param cls the handle to the transport service
164 */ 165 */
165static void 166static void
166reconnect(void *cls) 167reconnect (void *cls)
167{ 168{
168 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; 169 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
169 struct GNUNET_MQ_MessageHandler handlers[] = { 170 struct GNUNET_MQ_MessageHandler handlers[] = {
170 GNUNET_MQ_hd_var_size(hello, 171 GNUNET_MQ_hd_var_size (hello,
171 GNUNET_MESSAGE_TYPE_HELLO, 172 GNUNET_MESSAGE_TYPE_HELLO,
172 struct GNUNET_MessageHeader, 173 struct GNUNET_MessageHeader,
173 ghh), 174 ghh),
174 GNUNET_MQ_handler_end() 175 GNUNET_MQ_handler_end ()
175 }; 176 };
176 struct GNUNET_MQ_Envelope *env; 177 struct GNUNET_MQ_Envelope *env;
177 struct StartMessage *s; 178 struct StartMessage *s;
178 179
179 ghh->reconnect_task = NULL; 180 ghh->reconnect_task = NULL;
180 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
181 "Connecting to transport service.\n"); 182 "Connecting to transport service.\n");
182 GNUNET_assert(NULL == ghh->mq); 183 GNUNET_assert (NULL == ghh->mq);
183 ghh->mq = GNUNET_CLIENT_connect(ghh->cfg, 184 ghh->mq = GNUNET_CLIENT_connect (ghh->cfg,
184 "transport", 185 "transport",
185 handlers, 186 handlers,
186 &mq_error_handler, 187 &mq_error_handler,
187 ghh); 188 ghh);
188 if (NULL == ghh->mq) 189 if (NULL == ghh->mq)
189 return; 190 return;
190 env = GNUNET_MQ_msg(s, 191 env = GNUNET_MQ_msg (s,
191 GNUNET_MESSAGE_TYPE_TRANSPORT_START); 192 GNUNET_MESSAGE_TYPE_TRANSPORT_START);
192 s->options = htonl(0); 193 s->options = htonl (0);
193 GNUNET_MQ_send(ghh->mq, 194 GNUNET_MQ_send (ghh->mq,
194 env); 195 env);
195} 196}
196 197
197 198
@@ -202,13 +203,13 @@ reconnect(void *cls)
202 * @param ghh transport service to reconnect 203 * @param ghh transport service to reconnect
203 */ 204 */
204static void 205static void
205schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh) 206schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
206{ 207{
207 ghh->reconnect_task = 208 ghh->reconnect_task =
208 GNUNET_SCHEDULER_add_delayed(ghh->reconnect_delay, 209 GNUNET_SCHEDULER_add_delayed (ghh->reconnect_delay,
209 &reconnect, 210 &reconnect,
210 ghh); 211 ghh);
211 ghh->reconnect_delay = GNUNET_TIME_STD_BACKOFF(ghh->reconnect_delay); 212 ghh->reconnect_delay = GNUNET_TIME_STD_BACKOFF (ghh->reconnect_delay);
212} 213}
213 214
214 215
@@ -226,24 +227,24 @@ schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
226 * @return handle to cancel the operation 227 * @return handle to cancel the operation
227 */ 228 */
228struct GNUNET_TRANSPORT_HelloGetHandle * 229struct GNUNET_TRANSPORT_HelloGetHandle *
229GNUNET_TRANSPORT_hello_get(const struct GNUNET_CONFIGURATION_Handle *cfg, 230GNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg,
230 enum GNUNET_TRANSPORT_AddressClass ac, 231 enum GNUNET_TRANSPORT_AddressClass ac,
231 GNUNET_TRANSPORT_HelloUpdateCallback rec, 232 GNUNET_TRANSPORT_HelloUpdateCallback rec,
232 void *rec_cls) 233 void *rec_cls)
233{ 234{
234 struct GNUNET_TRANSPORT_HelloGetHandle *ghh; 235 struct GNUNET_TRANSPORT_HelloGetHandle *ghh;
235 236
236 ghh = GNUNET_new(struct GNUNET_TRANSPORT_HelloGetHandle); 237 ghh = GNUNET_new (struct GNUNET_TRANSPORT_HelloGetHandle);
237 ghh->rec = rec; 238 ghh->rec = rec;
238 ghh->rec_cls = rec_cls; 239 ghh->rec_cls = rec_cls;
239 ghh->cfg = cfg; 240 ghh->cfg = cfg;
240 ghh->ac = ac; 241 ghh->ac = ac;
241 reconnect(ghh); 242 reconnect (ghh);
242 if (NULL == ghh->mq) 243 if (NULL == ghh->mq)
243 { 244 {
244 GNUNET_free(ghh); 245 GNUNET_free (ghh);
245 return NULL; 246 return NULL;
246 } 247 }
247 return ghh; 248 return ghh;
248} 249}
249 250
@@ -254,19 +255,19 @@ GNUNET_TRANSPORT_hello_get(const struct GNUNET_CONFIGURATION_Handle *cfg,
254 * @param ghh handle to cancel 255 * @param ghh handle to cancel
255 */ 256 */
256void 257void
257GNUNET_TRANSPORT_hello_get_cancel(struct GNUNET_TRANSPORT_HelloGetHandle *ghh) 258GNUNET_TRANSPORT_hello_get_cancel (struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
258{ 259{
259 if (NULL != ghh->reconnect_task) 260 if (NULL != ghh->reconnect_task)
260 { 261 {
261 GNUNET_SCHEDULER_cancel(ghh->reconnect_task); 262 GNUNET_SCHEDULER_cancel (ghh->reconnect_task);
262 ghh->reconnect_task = NULL; 263 ghh->reconnect_task = NULL;
263 } 264 }
264 if (NULL != ghh->mq) 265 if (NULL != ghh->mq)
265 { 266 {
266 GNUNET_MQ_destroy(ghh->mq); 267 GNUNET_MQ_destroy (ghh->mq);
267 ghh->mq = NULL; 268 ghh->mq = NULL;
268 } 269 }
269 GNUNET_free(ghh); 270 GNUNET_free (ghh);
270} 271}
271 272
272 273
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 @@
32#include "gnunet_transport_service.h" 32#include "gnunet_transport_service.h"
33#include "transport.h" 33#include "transport.h"
34 34
35#define LOG(kind, ...) GNUNET_log_from(kind, "transport-api", __VA_ARGS__) 35#define LOG(kind, ...) GNUNET_log_from (kind, "transport-api", __VA_ARGS__)
36 36
37 37
38/** 38/**
39 * Handle for the transport service (includes all of the 39 * Handle for the transport service (includes all of the
40 * state for the transport service). 40 * state for the transport service).
41 */ 41 */
42struct GNUNET_TRANSPORT_ManipulationHandle { 42struct GNUNET_TRANSPORT_ManipulationHandle
43{
43 /** 44 /**
44 * My client connection to the transport service. 45 * My client connection to the transport service.
45 */ 46 */
@@ -74,7 +75,8 @@ struct GNUNET_TRANSPORT_ManipulationHandle {
74 * @param h transport service to reconnect 75 * @param h transport service to reconnect
75 */ 76 */
76static void 77static void
77disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h); 78disconnect_and_schedule_reconnect (struct
79 GNUNET_TRANSPORT_ManipulationHandle *h);
78 80
79 81
80/** 82/**
@@ -87,15 +89,15 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h)
87 * @param error error code 89 * @param error error code
88 */ 90 */
89static void 91static void
90mq_error_handler(void *cls, 92mq_error_handler (void *cls,
91 enum GNUNET_MQ_Error error) 93 enum GNUNET_MQ_Error error)
92{ 94{
93 struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; 95 struct GNUNET_TRANSPORT_ManipulationHandle *h = cls;
94 96
95 LOG(GNUNET_ERROR_TYPE_DEBUG, 97 LOG (GNUNET_ERROR_TYPE_DEBUG,
96 "Error receiving from transport service, disconnecting temporarily.\n"); 98 "Error receiving from transport service, disconnecting temporarily.\n");
97 h->reconnecting = GNUNET_YES; 99 h->reconnecting = GNUNET_YES;
98 disconnect_and_schedule_reconnect(h); 100 disconnect_and_schedule_reconnect (h);
99} 101}
100 102
101 103
@@ -105,31 +107,31 @@ mq_error_handler(void *cls,
105 * @param cls the handle to the transport service 107 * @param cls the handle to the transport service
106 */ 108 */
107static void 109static void
108reconnect(void *cls) 110reconnect (void *cls)
109{ 111{
110 struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; 112 struct GNUNET_TRANSPORT_ManipulationHandle *h = cls;
111 struct GNUNET_MQ_MessageHandler handlers[] = { 113 struct GNUNET_MQ_MessageHandler handlers[] = {
112 GNUNET_MQ_handler_end() 114 GNUNET_MQ_handler_end ()
113 }; 115 };
114 struct GNUNET_MQ_Envelope *env; 116 struct GNUNET_MQ_Envelope *env;
115 struct StartMessage *s; 117 struct StartMessage *s;
116 118
117 h->reconnect_task = NULL; 119 h->reconnect_task = NULL;
118 LOG(GNUNET_ERROR_TYPE_DEBUG, 120 LOG (GNUNET_ERROR_TYPE_DEBUG,
119 "Connecting to transport service.\n"); 121 "Connecting to transport service.\n");
120 GNUNET_assert(NULL == h->mq); 122 GNUNET_assert (NULL == h->mq);
121 h->reconnecting = GNUNET_NO; 123 h->reconnecting = GNUNET_NO;
122 h->mq = GNUNET_CLIENT_connect(h->cfg, 124 h->mq = GNUNET_CLIENT_connect (h->cfg,
123 "transport", 125 "transport",
124 handlers, 126 handlers,
125 &mq_error_handler, 127 &mq_error_handler,
126 h); 128 h);
127 if (NULL == h->mq) 129 if (NULL == h->mq)
128 return; 130 return;
129 env = GNUNET_MQ_msg(s, 131 env = GNUNET_MQ_msg (s,
130 GNUNET_MESSAGE_TYPE_TRANSPORT_START); 132 GNUNET_MESSAGE_TYPE_TRANSPORT_START);
131 GNUNET_MQ_send(h->mq, 133 GNUNET_MQ_send (h->mq,
132 env); 134 env);
133} 135}
134 136
135 137
@@ -140,19 +142,20 @@ reconnect(void *cls)
140 * @param h transport service to reconnect 142 * @param h transport service to reconnect
141 */ 143 */
142static void 144static void
143disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h) 145disconnect_and_schedule_reconnect (struct
146 GNUNET_TRANSPORT_ManipulationHandle *h)
144{ 147{
145 GNUNET_assert(NULL == h->reconnect_task); 148 GNUNET_assert (NULL == h->reconnect_task);
146 if (NULL != h->mq) 149 if (NULL != h->mq)
147 { 150 {
148 GNUNET_MQ_destroy(h->mq); 151 GNUNET_MQ_destroy (h->mq);
149 h->mq = NULL; 152 h->mq = NULL;
150 } 153 }
151 h->reconnect_task = 154 h->reconnect_task =
152 GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, 155 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
153 &reconnect, 156 &reconnect,
154 h); 157 h);
155 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); 158 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
156} 159}
157 160
158 161
@@ -169,27 +172,28 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h)
169 * with one message delay. 172 * with one message delay.
170 */ 173 */
171void 174void
172GNUNET_TRANSPORT_manipulation_set(struct GNUNET_TRANSPORT_ManipulationHandle *handle, 175GNUNET_TRANSPORT_manipulation_set (struct
173 const struct GNUNET_PeerIdentity *peer, 176 GNUNET_TRANSPORT_ManipulationHandle *handle,
174 const struct GNUNET_ATS_Properties *prop, 177 const struct GNUNET_PeerIdentity *peer,
175 struct GNUNET_TIME_Relative delay_in, 178 const struct GNUNET_ATS_Properties *prop,
176 struct GNUNET_TIME_Relative delay_out) 179 struct GNUNET_TIME_Relative delay_in,
180 struct GNUNET_TIME_Relative delay_out)
177{ 181{
178 struct GNUNET_MQ_Envelope *env; 182 struct GNUNET_MQ_Envelope *env;
179 struct TrafficMetricMessage *msg; 183 struct TrafficMetricMessage *msg;
180 184
181 if (NULL == handle->mq) 185 if (NULL == handle->mq)
182 return; 186 return;
183 env = GNUNET_MQ_msg(msg, 187 env = GNUNET_MQ_msg (msg,
184 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); 188 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC);
185 msg->reserved = htonl(0); 189 msg->reserved = htonl (0);
186 msg->peer = *peer; 190 msg->peer = *peer;
187 GNUNET_ATS_properties_hton(&msg->properties, 191 GNUNET_ATS_properties_hton (&msg->properties,
188 prop); 192 prop);
189 msg->delay_in = GNUNET_TIME_relative_hton(delay_in); 193 msg->delay_in = GNUNET_TIME_relative_hton (delay_in);
190 msg->delay_out = GNUNET_TIME_relative_hton(delay_out); 194 msg->delay_out = GNUNET_TIME_relative_hton (delay_out);
191 GNUNET_MQ_send(handle->mq, 195 GNUNET_MQ_send (handle->mq,
192 env); 196 env);
193} 197}
194 198
195 199
@@ -201,20 +205,21 @@ GNUNET_TRANSPORT_manipulation_set(struct GNUNET_TRANSPORT_ManipulationHandle *ha
201 * @return NULL on error 205 * @return NULL on error
202 */ 206 */
203struct GNUNET_TRANSPORT_ManipulationHandle * 207struct GNUNET_TRANSPORT_ManipulationHandle *
204GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) 208GNUNET_TRANSPORT_manipulation_connect (const struct
209 GNUNET_CONFIGURATION_Handle *cfg)
205{ 210{
206 struct GNUNET_TRANSPORT_ManipulationHandle *h; 211 struct GNUNET_TRANSPORT_ManipulationHandle *h;
207 212
208 h = GNUNET_new(struct GNUNET_TRANSPORT_ManipulationHandle); 213 h = GNUNET_new (struct GNUNET_TRANSPORT_ManipulationHandle);
209 h->cfg = cfg; 214 h->cfg = cfg;
210 LOG(GNUNET_ERROR_TYPE_DEBUG, 215 LOG (GNUNET_ERROR_TYPE_DEBUG,
211 "Connecting to transport service.\n"); 216 "Connecting to transport service.\n");
212 reconnect(h); 217 reconnect (h);
213 if (NULL == h->mq) 218 if (NULL == h->mq)
214 { 219 {
215 GNUNET_free(h); 220 GNUNET_free (h);
216 return NULL; 221 return NULL;
217 } 222 }
218 return h; 223 return h;
219} 224}
220 225
@@ -225,17 +230,19 @@ GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle *
225 * @param handle handle to the service as returned from #GNUNET_TRANSPORT_manipulation_connect() 230 * @param handle handle to the service as returned from #GNUNET_TRANSPORT_manipulation_connect()
226 */ 231 */
227void 232void
228GNUNET_TRANSPORT_manipulation_disconnect(struct GNUNET_TRANSPORT_ManipulationHandle *handle) 233GNUNET_TRANSPORT_manipulation_disconnect (struct
234 GNUNET_TRANSPORT_ManipulationHandle *
235 handle)
229{ 236{
230 if (NULL == handle->reconnect_task) 237 if (NULL == handle->reconnect_task)
231 disconnect_and_schedule_reconnect(handle); 238 disconnect_and_schedule_reconnect (handle);
232 /* and now we stop trying to connect again... */ 239 /* and now we stop trying to connect again... */
233 if (NULL != handle->reconnect_task) 240 if (NULL != handle->reconnect_task)
234 { 241 {
235 GNUNET_SCHEDULER_cancel(handle->reconnect_task); 242 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
236 handle->reconnect_task = NULL; 243 handle->reconnect_task = NULL;
237 } 244 }
238 GNUNET_free(handle); 245 GNUNET_free (handle);
239} 246}
240 247
241 248
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 @@
39/** 39/**
40 * Context for iterating validation entries. 40 * Context for iterating validation entries.
41 */ 41 */
42struct GNUNET_TRANSPORT_PeerMonitoringContext { 42struct GNUNET_TRANSPORT_PeerMonitoringContext
43{
43 /** 44 /**
44 * Function to call with the binary address. 45 * Function to call with the binary address.
45 */ 46 */
@@ -89,34 +90,34 @@ struct GNUNET_TRANSPORT_PeerMonitoringContext {
89 * @return #GNUNET_YES or #GNUNET_NO 90 * @return #GNUNET_YES or #GNUNET_NO
90 */ 91 */
91int 92int
92GNUNET_TRANSPORT_is_connected(enum GNUNET_TRANSPORT_PeerState state) 93GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state)
93{ 94{
94 switch (state) 95 switch (state)
95 { 96 {
96 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 97 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
97 case GNUNET_TRANSPORT_PS_INIT_ATS: 98 case GNUNET_TRANSPORT_PS_INIT_ATS:
98 case GNUNET_TRANSPORT_PS_SYN_SENT: 99 case GNUNET_TRANSPORT_PS_SYN_SENT:
99 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 100 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
100 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 101 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
101 return GNUNET_NO; 102 return GNUNET_NO;
102 103
103 case GNUNET_TRANSPORT_PS_CONNECTED: 104 case GNUNET_TRANSPORT_PS_CONNECTED:
104 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 105 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
105 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 106 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
106 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 107 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
107 return GNUNET_YES; 108 return GNUNET_YES;
108 109
109 case GNUNET_TRANSPORT_PS_DISCONNECT: 110 case GNUNET_TRANSPORT_PS_DISCONNECT:
110 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 111 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
111 return GNUNET_NO; 112 return GNUNET_NO;
112 113
113 default: 114 default:
114 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
115 "Unhandled state `%s'\n", 116 "Unhandled state `%s'\n",
116 GNUNET_TRANSPORT_ps2s(state)); 117 GNUNET_TRANSPORT_ps2s (state));
117 GNUNET_break(0); 118 GNUNET_break (0);
118 break; 119 break;
119 } 120 }
120 return GNUNET_SYSERR; 121 return GNUNET_SYSERR;
121} 122}
122 123
@@ -128,47 +129,47 @@ GNUNET_TRANSPORT_is_connected(enum GNUNET_TRANSPORT_PeerState state)
128 * @return corresponding string 129 * @return corresponding string
129 */ 130 */
130const char * 131const char *
131GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state) 132GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state)
132{ 133{
133 switch (state) 134 switch (state)
134 { 135 {
135 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 136 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
136 return "S_NOT_CONNECTED"; 137 return "S_NOT_CONNECTED";
137 138
138 case GNUNET_TRANSPORT_PS_INIT_ATS: 139 case GNUNET_TRANSPORT_PS_INIT_ATS:
139 return "S_INIT_ATS"; 140 return "S_INIT_ATS";
140 141
141 case GNUNET_TRANSPORT_PS_SYN_SENT: 142 case GNUNET_TRANSPORT_PS_SYN_SENT:
142 return "S_SYN_SENT"; 143 return "S_SYN_SENT";
143 144
144 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 145 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
145 return "S_SYN_RECV_ATS"; 146 return "S_SYN_RECV_ATS";
146 147
147 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 148 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
148 return "S_SYN_RECV_ACK"; 149 return "S_SYN_RECV_ACK";
149 150
150 case GNUNET_TRANSPORT_PS_CONNECTED: 151 case GNUNET_TRANSPORT_PS_CONNECTED:
151 return "S_CONNECTED"; 152 return "S_CONNECTED";
152 153
153 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 154 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
154 return "S_RECONNECT_ATS"; 155 return "S_RECONNECT_ATS";
155 156
156 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 157 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
157 return "S_RECONNECT_SENT"; 158 return "S_RECONNECT_SENT";
158 159
159 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 160 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
160 return "S_SWITCH_SYN_SENT"; 161 return "S_SWITCH_SYN_SENT";
161 162
162 case GNUNET_TRANSPORT_PS_DISCONNECT: 163 case GNUNET_TRANSPORT_PS_DISCONNECT:
163 return "S_DISCONNECT"; 164 return "S_DISCONNECT";
164 165
165 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 166 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
166 return "S_DISCONNECT_FINISHED"; 167 return "S_DISCONNECT_FINISHED";
167 168
168 default: 169 default:
169 GNUNET_break(0); 170 GNUNET_break (0);
170 return "UNDEFINED"; 171 return "UNDEFINED";
171 } 172 }
172} 173}
173 174
174 175
@@ -178,7 +179,7 @@ GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state)
178 * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *` 179 * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *`
179 */ 180 */
180static void 181static void
181do_peer_connect(void *cls); 182do_peer_connect (void *cls);
182 183
183 184
184/** 185/**
@@ -187,20 +188,20 @@ do_peer_connect(void *cls);
187 * @param pal_ctx our context 188 * @param pal_ctx our context
188 */ 189 */
189static void 190static void
190reconnect_peer_ctx(struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx) 191reconnect_peer_ctx (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
191{ 192{
192 GNUNET_assert(GNUNET_NO == pal_ctx->one_shot); 193 GNUNET_assert (GNUNET_NO == pal_ctx->one_shot);
193 GNUNET_MQ_destroy(pal_ctx->mq); 194 GNUNET_MQ_destroy (pal_ctx->mq);
194 pal_ctx->mq = NULL; 195 pal_ctx->mq = NULL;
195 pal_ctx->cb(pal_ctx->cb_cls, 196 pal_ctx->cb (pal_ctx->cb_cls,
196 NULL, 197 NULL,
197 NULL, 198 NULL,
198 GNUNET_TRANSPORT_PS_NOT_CONNECTED, 199 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
199 GNUNET_TIME_UNIT_ZERO_ABS); 200 GNUNET_TIME_UNIT_ZERO_ABS);
200 pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF(pal_ctx->backoff); 201 pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff);
201 pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed(pal_ctx->backoff, 202 pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff,
202 &do_peer_connect, 203 &do_peer_connect,
203 pal_ctx); 204 pal_ctx);
204} 205}
205 206
206 207
@@ -211,25 +212,25 @@ reconnect_peer_ctx(struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
211 * @param msg message from service 212 * @param msg message from service
212 */ 213 */
213static void 214static void
214handle_response_end(void *cls, 215handle_response_end (void *cls,
215 const struct GNUNET_MessageHeader *msg) 216 const struct GNUNET_MessageHeader *msg)
216{ 217{
217 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; 218 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
218 219
219 if (pal_ctx->one_shot) 220 if (pal_ctx->one_shot)
220 { 221 {
221 /* iteration finished */ 222 /* iteration finished */
222 pal_ctx->cb(pal_ctx->cb_cls, 223 pal_ctx->cb (pal_ctx->cb_cls,
223 NULL, 224 NULL,
224 NULL, 225 NULL,
225 GNUNET_TRANSPORT_PS_NOT_CONNECTED, 226 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
226 GNUNET_TIME_UNIT_ZERO_ABS); 227 GNUNET_TIME_UNIT_ZERO_ABS);
227 GNUNET_TRANSPORT_monitor_peers_cancel(pal_ctx); 228 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
228 return; 229 return;
229 } 230 }
230 /* not quite what we expected, reconnect */ 231 /* not quite what we expected, reconnect */
231 GNUNET_break(0); 232 GNUNET_break (0);
232 reconnect_peer_ctx(pal_ctx); 233 reconnect_peer_ctx (pal_ctx);
233} 234}
234 235
235 236
@@ -241,34 +242,34 @@ handle_response_end(void *cls,
241 * @return #GNUNET_OK if @a pir_msg is well-formed 242 * @return #GNUNET_OK if @a pir_msg is well-formed
242 */ 243 */
243static int 244static int
244check_response(void *cls, 245check_response (void *cls,
245 const struct PeerIterateResponseMessage *pir_msg) 246 const struct PeerIterateResponseMessage *pir_msg)
246{ 247{
247 uint16_t size = ntohs(pir_msg->header.size) - sizeof(*pir_msg); 248 uint16_t size = ntohs (pir_msg->header.size) - sizeof(*pir_msg);
248 size_t alen = ntohl(pir_msg->addrlen); 249 size_t alen = ntohl (pir_msg->addrlen);
249 size_t tlen = ntohl(pir_msg->pluginlen); 250 size_t tlen = ntohl (pir_msg->pluginlen);
250 const char *addr; 251 const char *addr;
251 const char *transport_name; 252 const char *transport_name;
252 253
253 if (size != tlen + alen) 254 if (size != tlen + alen)
254 { 255 {
255 GNUNET_break(0); 256 GNUNET_break (0);
256 return GNUNET_SYSERR; 257 return GNUNET_SYSERR;
257 } 258 }
258 if ((0 == tlen) && (0 == alen)) 259 if ((0 == tlen) && (0 == alen))
259 return GNUNET_OK; 260 return GNUNET_OK;
260 if (0 == tlen) 261 if (0 == tlen)
261 { 262 {
262 GNUNET_break(0); /* This must not happen: address without plugin */ 263 GNUNET_break (0); /* This must not happen: address without plugin */
263 return GNUNET_SYSERR; 264 return GNUNET_SYSERR;
264 } 265 }
265 addr = (const char *)&pir_msg[1]; 266 addr = (const char *) &pir_msg[1];
266 transport_name = &addr[alen]; 267 transport_name = &addr[alen];
267 if (transport_name[tlen - 1] != '\0') 268 if (transport_name[tlen - 1] != '\0')
268 { 269 {
269 GNUNET_break(0); 270 GNUNET_break (0);
270 return GNUNET_SYSERR; 271 return GNUNET_SYSERR;
271 } 272 }
272 return GNUNET_OK; 273 return GNUNET_OK;
273} 274}
274 275
@@ -280,42 +281,42 @@ check_response(void *cls,
280 * @param msg message with the human-readable address 281 * @param msg message with the human-readable address
281 */ 282 */
282static void 283static void
283handle_response(void *cls, 284handle_response (void *cls,
284 const struct PeerIterateResponseMessage *pir_msg) 285 const struct PeerIterateResponseMessage *pir_msg)
285{ 286{
286 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; 287 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
287 struct GNUNET_HELLO_Address *address; 288 struct GNUNET_HELLO_Address *address;
288 size_t alen = ntohl(pir_msg->addrlen); 289 size_t alen = ntohl (pir_msg->addrlen);
289 size_t tlen = ntohl(pir_msg->pluginlen); 290 size_t tlen = ntohl (pir_msg->pluginlen);
290 const char *addr; 291 const char *addr;
291 const char *transport_name; 292 const char *transport_name;
292 293
293 if ((0 == tlen) && 294 if ((0 == tlen) &&
294 (0 == alen)) 295 (0 == alen))
295 { 296 {
296 /* No address available */ 297 /* No address available */
297 pal_ctx->cb(pal_ctx->cb_cls, 298 pal_ctx->cb (pal_ctx->cb_cls,
298 &pir_msg->peer, 299 &pir_msg->peer,
299 NULL, 300 NULL,
300 ntohl(pir_msg->state), 301 ntohl (pir_msg->state),
301 GNUNET_TIME_absolute_ntoh(pir_msg->state_timeout)); 302 GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout));
302 return; 303 return;
303 } 304 }
304 addr = (const char *)&pir_msg[1]; 305 addr = (const char *) &pir_msg[1];
305 transport_name = &addr[alen]; 306 transport_name = &addr[alen];
306 307
307 /* notify client */ 308 /* notify client */
308 address = GNUNET_HELLO_address_allocate(&pir_msg->peer, 309 address = GNUNET_HELLO_address_allocate (&pir_msg->peer,
309 transport_name, 310 transport_name,
310 addr, 311 addr,
311 alen, 312 alen,
312 ntohl(pir_msg->local_address_info)); 313 ntohl (pir_msg->local_address_info));
313 pal_ctx->cb(pal_ctx->cb_cls, 314 pal_ctx->cb (pal_ctx->cb_cls,
314 &pir_msg->peer, 315 &pir_msg->peer,
315 address, 316 address,
316 ntohl(pir_msg->state), 317 ntohl (pir_msg->state),
317 GNUNET_TIME_absolute_ntoh(pir_msg->state_timeout)); 318 GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout));
318 GNUNET_HELLO_address_free(address); 319 GNUNET_HELLO_address_free (address);
319} 320}
320 321
321 322
@@ -329,23 +330,23 @@ handle_response(void *cls,
329 * @param error error code 330 * @param error error code
330 */ 331 */
331static void 332static void
332mq_error_handler(void *cls, 333mq_error_handler (void *cls,
333 enum GNUNET_MQ_Error error) 334 enum GNUNET_MQ_Error error)
334{ 335{
335 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; 336 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
336 337
337 if (pal_ctx->one_shot) 338 if (pal_ctx->one_shot)
338 { 339 {
339 /* Disconnect */ 340 /* Disconnect */
340 pal_ctx->cb(pal_ctx->cb_cls, 341 pal_ctx->cb (pal_ctx->cb_cls,
341 NULL, 342 NULL,
342 NULL, 343 NULL,
343 GNUNET_TRANSPORT_PS_NOT_CONNECTED, 344 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
344 GNUNET_TIME_UNIT_ZERO_ABS); 345 GNUNET_TIME_UNIT_ZERO_ABS);
345 GNUNET_TRANSPORT_monitor_peers_cancel(pal_ctx); 346 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
346 return; 347 return;
347 } 348 }
348 reconnect_peer_ctx(pal_ctx); 349 reconnect_peer_ctx (pal_ctx);
349} 350}
350 351
351 352
@@ -355,37 +356,37 @@ mq_error_handler(void *cls,
355 * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *` 356 * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *`
356 */ 357 */
357static void 358static void
358do_peer_connect(void *cls) 359do_peer_connect (void *cls)
359{ 360{
360 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; 361 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
361 struct GNUNET_MQ_MessageHandler handlers[] = { 362 struct GNUNET_MQ_MessageHandler handlers[] = {
362 GNUNET_MQ_hd_var_size(response, 363 GNUNET_MQ_hd_var_size (response,
363 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE, 364 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE,
364 struct PeerIterateResponseMessage, 365 struct PeerIterateResponseMessage,
365 pal_ctx), 366 pal_ctx),
366 GNUNET_MQ_hd_fixed_size(response_end, 367 GNUNET_MQ_hd_fixed_size (response_end,
367 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END, 368 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END,
368 struct GNUNET_MessageHeader, 369 struct GNUNET_MessageHeader,
369 pal_ctx), 370 pal_ctx),
370 GNUNET_MQ_handler_end() 371 GNUNET_MQ_handler_end ()
371 }; 372 };
372 struct PeerMonitorMessage *msg; 373 struct PeerMonitorMessage *msg;
373 struct GNUNET_MQ_Envelope *env; 374 struct GNUNET_MQ_Envelope *env;
374 375
375 pal_ctx->reconnect_task = NULL; 376 pal_ctx->reconnect_task = NULL;
376 pal_ctx->mq = GNUNET_CLIENT_connect(pal_ctx->cfg, 377 pal_ctx->mq = GNUNET_CLIENT_connect (pal_ctx->cfg,
377 "transport", 378 "transport",
378 handlers, 379 handlers,
379 &mq_error_handler, 380 &mq_error_handler,
380 pal_ctx); 381 pal_ctx);
381 if (NULL == pal_ctx->mq) 382 if (NULL == pal_ctx->mq)
382 return; 383 return;
383 env = GNUNET_MQ_msg(msg, 384 env = GNUNET_MQ_msg (msg,
384 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST); 385 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST);
385 msg->one_shot = htonl(pal_ctx->one_shot); 386 msg->one_shot = htonl (pal_ctx->one_shot);
386 msg->peer = pal_ctx->peer; 387 msg->peer = pal_ctx->peer;
387 GNUNET_MQ_send(pal_ctx->mq, 388 GNUNET_MQ_send (pal_ctx->mq,
388 env); 389 env);
389} 390}
390 391
391 392
@@ -416,14 +417,15 @@ do_peer_connect(void *cls)
416 * @param peer_callback_cls closure for @a peer_address_callback 417 * @param peer_callback_cls closure for @a peer_address_callback
417 */ 418 */
418struct GNUNET_TRANSPORT_PeerMonitoringContext * 419struct GNUNET_TRANSPORT_PeerMonitoringContext *
419GNUNET_TRANSPORT_monitor_peers(const struct GNUNET_CONFIGURATION_Handle *cfg, 420GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
420 const struct GNUNET_PeerIdentity *peer, 421 const struct GNUNET_PeerIdentity *peer,
421 int one_shot, 422 int one_shot,
422 GNUNET_TRANSPORT_PeerIterateCallback peer_callback, 423 GNUNET_TRANSPORT_PeerIterateCallback
423 void *peer_callback_cls) 424 peer_callback,
425 void *peer_callback_cls)
424{ 426{
425 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx 427 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx
426 = GNUNET_new(struct GNUNET_TRANSPORT_PeerMonitoringContext); 428 = GNUNET_new (struct GNUNET_TRANSPORT_PeerMonitoringContext);
427 429
428 pal_ctx->cb = peer_callback; 430 pal_ctx->cb = peer_callback;
429 pal_ctx->cb_cls = peer_callback_cls; 431 pal_ctx->cb_cls = peer_callback_cls;
@@ -431,12 +433,12 @@ GNUNET_TRANSPORT_monitor_peers(const struct GNUNET_CONFIGURATION_Handle *cfg,
431 if (NULL != peer) 433 if (NULL != peer)
432 pal_ctx->peer = *peer; 434 pal_ctx->peer = *peer;
433 pal_ctx->one_shot = one_shot; 435 pal_ctx->one_shot = one_shot;
434 do_peer_connect(pal_ctx); 436 do_peer_connect (pal_ctx);
435 if (NULL == pal_ctx->mq) 437 if (NULL == pal_ctx->mq)
436 { 438 {
437 GNUNET_free(pal_ctx); 439 GNUNET_free (pal_ctx);
438 return NULL; 440 return NULL;
439 } 441 }
440 return pal_ctx; 442 return pal_ctx;
441} 443}
442 444
@@ -447,19 +449,21 @@ GNUNET_TRANSPORT_monitor_peers(const struct GNUNET_CONFIGURATION_Handle *cfg,
447 * @param pic handle for the request to cancel 449 * @param pic handle for the request to cancel
448 */ 450 */
449void 451void
450GNUNET_TRANSPORT_monitor_peers_cancel(struct GNUNET_TRANSPORT_PeerMonitoringContext *pic) 452GNUNET_TRANSPORT_monitor_peers_cancel (struct
453 GNUNET_TRANSPORT_PeerMonitoringContext *
454 pic)
451{ 455{
452 if (NULL != pic->mq) 456 if (NULL != pic->mq)
453 { 457 {
454 GNUNET_MQ_destroy(pic->mq); 458 GNUNET_MQ_destroy (pic->mq);
455 pic->mq = NULL; 459 pic->mq = NULL;
456 } 460 }
457 if (NULL != pic->reconnect_task) 461 if (NULL != pic->reconnect_task)
458 { 462 {
459 GNUNET_SCHEDULER_cancel(pic->reconnect_task); 463 GNUNET_SCHEDULER_cancel (pic->reconnect_task);
460 pic->reconnect_task = NULL; 464 pic->reconnect_task = NULL;
461 } 465 }
462 GNUNET_free(pic); 466 GNUNET_free (pic);
463} 467}
464 468
465 469
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 @@
35/** 35/**
36 * Handle for a plugin session state monitor. 36 * Handle for a plugin session state monitor.
37 */ 37 */
38struct GNUNET_TRANSPORT_PluginMonitor { 38struct GNUNET_TRANSPORT_PluginMonitor
39{
39 /** 40 /**
40 * Connection to the service. 41 * Connection to the service.
41 */ 42 */
@@ -78,7 +79,8 @@ struct GNUNET_TRANSPORT_PluginMonitor {
78 * Abstract representation of a plugin's session. 79 * Abstract representation of a plugin's session.
79 * Corresponds to the `struct GNUNET_ATS_Session` within the TRANSPORT service. 80 * Corresponds to the `struct GNUNET_ATS_Session` within the TRANSPORT service.
80 */ 81 */
81struct GNUNET_TRANSPORT_PluginSession { 82struct GNUNET_TRANSPORT_PluginSession
83{
82 /** 84 /**
83 * Unique session identifier. 85 * Unique session identifier.
84 */ 86 */
@@ -98,7 +100,7 @@ struct GNUNET_TRANSPORT_PluginSession {
98 * @param cls our `struct GNUNET_TRANSPORT_PluginMonitor *` 100 * @param cls our `struct GNUNET_TRANSPORT_PluginMonitor *`
99 */ 101 */
100static void 102static void
101do_plugin_connect(void *cls); 103do_plugin_connect (void *cls);
102 104
103 105
104/** 106/**
@@ -110,23 +112,23 @@ do_plugin_connect(void *cls);
110 * @return #GNUNET_OK (continue to iterate) 112 * @return #GNUNET_OK (continue to iterate)
111 */ 113 */
112static int 114static int
113free_entry(void *cls, 115free_entry (void *cls,
114 uint32_t key, 116 uint32_t key,
115 void *value) 117 void *value)
116{ 118{
117 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; 119 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
118 struct GNUNET_TRANSPORT_PluginSession *ps = value; 120 struct GNUNET_TRANSPORT_PluginSession *ps = value;
119 121
120 pm->cb(pm->cb_cls, 122 pm->cb (pm->cb_cls,
121 ps, 123 ps,
122 &ps->client_ctx, 124 &ps->client_ctx,
123 NULL); 125 NULL);
124 GNUNET_break(GNUNET_YES == 126 GNUNET_break (GNUNET_YES ==
125 GNUNET_CONTAINER_multihashmap32_remove(pm->sessions, 127 GNUNET_CONTAINER_multihashmap32_remove (pm->sessions,
126 key, 128 key,
127 ps)); 129 ps));
128 GNUNET_break(NULL == ps->client_ctx); 130 GNUNET_break (NULL == ps->client_ctx);
129 GNUNET_free(ps); 131 GNUNET_free (ps);
130 return GNUNET_OK; 132 return GNUNET_OK;
131} 133}
132 134
@@ -137,17 +139,17 @@ free_entry(void *cls,
137 * @param pm our context 139 * @param pm our context
138 */ 140 */
139static void 141static void
140reconnect_plugin_ctx(struct GNUNET_TRANSPORT_PluginMonitor *pm) 142reconnect_plugin_ctx (struct GNUNET_TRANSPORT_PluginMonitor *pm)
141{ 143{
142 GNUNET_MQ_destroy(pm->mq); 144 GNUNET_MQ_destroy (pm->mq);
143 pm->mq = NULL; 145 pm->mq = NULL;
144 GNUNET_CONTAINER_multihashmap32_iterate(pm->sessions, 146 GNUNET_CONTAINER_multihashmap32_iterate (pm->sessions,
145 &free_entry, 147 &free_entry,
146 pm); 148 pm);
147 pm->backoff = GNUNET_TIME_STD_BACKOFF(pm->backoff); 149 pm->backoff = GNUNET_TIME_STD_BACKOFF (pm->backoff);
148 pm->reconnect_task = GNUNET_SCHEDULER_add_delayed(pm->backoff, 150 pm->reconnect_task = GNUNET_SCHEDULER_add_delayed (pm->backoff,
149 &do_plugin_connect, 151 &do_plugin_connect,
150 pm); 152 pm);
151} 153}
152 154
153 155
@@ -158,16 +160,17 @@ reconnect_plugin_ctx(struct GNUNET_TRANSPORT_PluginMonitor *pm)
158 * @return 32-bit hash map index 160 * @return 32-bit hash map index
159 */ 161 */
160static uint32_t 162static uint32_t
161wrap_id(uint64_t id) 163wrap_id (uint64_t id)
162{ 164{
163 return ((uint32_t)id) ^ ((uint32_t)(id >> 32)); 165 return ((uint32_t) id) ^ ((uint32_t) (id >> 32));
164} 166}
165 167
166 168
167/** 169/**
168 * Context for #locate_by_id(). 170 * Context for #locate_by_id().
169 */ 171 */
170struct SearchContext { 172struct SearchContext
173{
171 /** 174 /**
172 * Result. 175 * Result.
173 */ 176 */
@@ -189,18 +192,18 @@ struct SearchContext {
189 * @return #GNUNET_OK (continue to iterate), or #GNUNET_SYSERR (match found) 192 * @return #GNUNET_OK (continue to iterate), or #GNUNET_SYSERR (match found)
190 */ 193 */
191static int 194static int
192locate_by_id(void *cls, 195locate_by_id (void *cls,
193 uint32_t key, 196 uint32_t key,
194 void *value) 197 void *value)
195{ 198{
196 struct SearchContext *sc = cls; 199 struct SearchContext *sc = cls;
197 struct GNUNET_TRANSPORT_PluginSession *ps = value; 200 struct GNUNET_TRANSPORT_PluginSession *ps = value;
198 201
199 if (sc->session_id == ps->session_id) 202 if (sc->session_id == ps->session_id)
200 { 203 {
201 sc->ps = ps; 204 sc->ps = ps;
202 return GNUNET_SYSERR; 205 return GNUNET_SYSERR;
203 } 206 }
204 return GNUNET_OK; 207 return GNUNET_OK;
205} 208}
206 209
@@ -213,25 +216,26 @@ locate_by_id(void *cls,
213 * @return #GNUNET_Ok if message is well-formed 216 * @return #GNUNET_Ok if message is well-formed
214 */ 217 */
215static int 218static int
216check_event(void *cls, 219check_event (void *cls,
217 const struct TransportPluginMonitorMessage *tpmm) 220 const struct TransportPluginMonitorMessage *tpmm)
218{ 221{
219 const char *pname; 222 const char *pname;
220 size_t pname_len; 223 size_t pname_len;
221 size_t paddr_len; 224 size_t paddr_len;
222 225
223 pname = (const char *)&tpmm[1]; 226 pname = (const char *) &tpmm[1];
224 pname_len = ntohs(tpmm->plugin_name_len); 227 pname_len = ntohs (tpmm->plugin_name_len);
225 paddr_len = ntohs(tpmm->plugin_address_len); 228 paddr_len = ntohs (tpmm->plugin_address_len);
226 if ((pname_len + 229 if ((pname_len
227 paddr_len + 230 + paddr_len
228 sizeof(struct TransportPluginMonitorMessage) != ntohs(tpmm->header.size)) || 231 + sizeof(struct TransportPluginMonitorMessage) != ntohs (
232 tpmm->header.size)) ||
229 ((0 != pname_len) && 233 ((0 != pname_len) &&
230 ('\0' != pname[pname_len - 1]))) 234 ('\0' != pname[pname_len - 1])))
231 { 235 {
232 GNUNET_break(0); 236 GNUNET_break (0);
233 return GNUNET_SYSERR; 237 return GNUNET_SYSERR;
234 } 238 }
235 return GNUNET_OK; 239 return GNUNET_OK;
236} 240}
237 241
@@ -243,8 +247,8 @@ check_event(void *cls,
243 * @paramm tpmm message with event data 247 * @paramm tpmm message with event data
244 */ 248 */
245static void 249static void
246handle_event(void *cls, 250handle_event (void *cls,
247 const struct TransportPluginMonitorMessage *tpmm) 251 const struct TransportPluginMonitorMessage *tpmm)
248{ 252{
249 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; 253 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
250 struct GNUNET_TRANSPORT_PluginSession *ps; 254 struct GNUNET_TRANSPORT_PluginSession *ps;
@@ -257,63 +261,65 @@ handle_event(void *cls,
257 struct GNUNET_HELLO_Address addr; 261 struct GNUNET_HELLO_Address addr;
258 struct SearchContext rv; 262 struct SearchContext rv;
259 263
260 pname = (const char *)&tpmm[1]; 264 pname = (const char *) &tpmm[1];
261 pname_len = ntohs(tpmm->plugin_name_len); 265 pname_len = ntohs (tpmm->plugin_name_len);
262 paddr_len = ntohs(tpmm->plugin_address_len); 266 paddr_len = ntohs (tpmm->plugin_address_len);
263 paddr = &pname[pname_len]; 267 paddr = &pname[pname_len];
264 ps = NULL; 268 ps = NULL;
265 ss = (enum GNUNET_TRANSPORT_SessionState)ntohs(tpmm->session_state); 269 ss = (enum GNUNET_TRANSPORT_SessionState) ntohs (tpmm->session_state);
266 if (GNUNET_TRANSPORT_SS_INIT == ss) 270 if (GNUNET_TRANSPORT_SS_INIT == ss)
267 { 271 {
268 ps = GNUNET_new(struct GNUNET_TRANSPORT_PluginSession); 272 ps = GNUNET_new (struct GNUNET_TRANSPORT_PluginSession);
269 ps->session_id = tpmm->session_id; 273 ps->session_id = tpmm->session_id;
270 (void)GNUNET_CONTAINER_multihashmap32_put(pm->sessions, 274 (void) GNUNET_CONTAINER_multihashmap32_put (pm->sessions,
271 wrap_id(tpmm->session_id), 275 wrap_id (tpmm->session_id),
272 ps, 276 ps,
273 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 277 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
274 } 278 }
275 else 279 else
276 { 280 {
277 rv.session_id = tpmm->session_id; 281 rv.session_id = tpmm->session_id;
278 rv.ps = NULL; 282 rv.ps = NULL;
279 (void)GNUNET_CONTAINER_multihashmap32_get_multiple(pm->sessions, 283 (void) GNUNET_CONTAINER_multihashmap32_get_multiple (pm->sessions,
280 wrap_id(tpmm->session_id), 284 wrap_id (
285 tpmm->session_id),
281 &locate_by_id, 286 &locate_by_id,
282 &rv); 287 &rv);
283 ps = rv.ps; 288 ps = rv.ps;
284 if (NULL == ps) 289 if (NULL == ps)
285 { 290 {
286 GNUNET_break(0); 291 GNUNET_break (0);
287 reconnect_plugin_ctx(pm); 292 reconnect_plugin_ctx (pm);
288 return; 293 return;
289 }
290 } 294 }
295 }
291 info.state = ss; 296 info.state = ss;
292 info.is_inbound = (int16_t)ntohs(tpmm->is_inbound); 297 info.is_inbound = (int16_t) ntohs (tpmm->is_inbound);
293 info.num_msg_pending = ntohl(tpmm->msgs_pending); 298 info.num_msg_pending = ntohl (tpmm->msgs_pending);
294 info.num_bytes_pending = ntohl(tpmm->bytes_pending); 299 info.num_bytes_pending = ntohl (tpmm->bytes_pending);
295 info.receive_delay = GNUNET_TIME_absolute_ntoh(tpmm->delay); 300 info.receive_delay = GNUNET_TIME_absolute_ntoh (tpmm->delay);
296 info.session_timeout = GNUNET_TIME_absolute_ntoh(tpmm->timeout); 301 info.session_timeout = GNUNET_TIME_absolute_ntoh (tpmm->timeout);
297 info.address = &addr; 302 info.address = &addr;
298 addr.peer = tpmm->peer; 303 addr.peer = tpmm->peer;
299 addr.address = (0 == paddr_len) ? NULL : paddr; 304 addr.address = (0 == paddr_len) ? NULL : paddr;
300 addr.address_length = paddr_len; 305 addr.address_length = paddr_len;
301 addr.transport_name = (0 == pname_len) ? NULL : pname; 306 addr.transport_name = (0 == pname_len) ? NULL : pname;
302 addr.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; 307 addr.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
303 pm->cb(pm->cb_cls, 308 pm->cb (pm->cb_cls,
304 ps, 309 ps,
305 &ps->client_ctx, 310 &ps->client_ctx,
306 &info); 311 &info);
307 312
308 if (GNUNET_TRANSPORT_SS_DONE == ss) 313 if (GNUNET_TRANSPORT_SS_DONE == ss)
309 { 314 {
310 GNUNET_break(NULL == ps->client_ctx); 315 GNUNET_break (NULL == ps->client_ctx);
311 GNUNET_assert(GNUNET_YES == 316 GNUNET_assert (GNUNET_YES ==
312 GNUNET_CONTAINER_multihashmap32_remove(pm->sessions, 317 GNUNET_CONTAINER_multihashmap32_remove (pm->sessions,
313 wrap_id(tpmm->session_id), 318 wrap_id (
319 tpmm->session_id),
314 ps)); 320 ps));
315 GNUNET_free(ps); 321 GNUNET_free (ps);
316 } 322 }
317} 323}
318 324
319 325
@@ -324,16 +330,16 @@ handle_event(void *cls,
324 * @param msg message from the service 330 * @param msg message from the service
325 */ 331 */
326static void 332static void
327handle_sync(void *cls, 333handle_sync (void *cls,
328 const struct GNUNET_MessageHeader *msg) 334 const struct GNUNET_MessageHeader *msg)
329{ 335{
330 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; 336 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
331 337
332 /* we are in sync, notify callback */ 338 /* we are in sync, notify callback */
333 pm->cb(pm->cb_cls, 339 pm->cb (pm->cb_cls,
334 NULL, 340 NULL,
335 NULL, 341 NULL,
336 NULL); 342 NULL);
337} 343}
338 344
339 345
@@ -347,12 +353,12 @@ handle_sync(void *cls,
347 * @param error error code 353 * @param error error code
348 */ 354 */
349static void 355static void
350mq_error_handler(void *cls, 356mq_error_handler (void *cls,
351 enum GNUNET_MQ_Error error) 357 enum GNUNET_MQ_Error error)
352{ 358{
353 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; 359 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
354 360
355 reconnect_plugin_ctx(pm); 361 reconnect_plugin_ctx (pm);
356} 362}
357 363
358 364
@@ -362,35 +368,35 @@ mq_error_handler(void *cls,
362 * @param cls our `struct GNUNET_TRANSPORT_PluginMonitor *` 368 * @param cls our `struct GNUNET_TRANSPORT_PluginMonitor *`
363 */ 369 */
364static void 370static void
365do_plugin_connect(void *cls) 371do_plugin_connect (void *cls)
366{ 372{
367 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; 373 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
368 struct GNUNET_MQ_MessageHandler handlers[] = { 374 struct GNUNET_MQ_MessageHandler handlers[] = {
369 GNUNET_MQ_hd_var_size(event, 375 GNUNET_MQ_hd_var_size (event,
370 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT, 376 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT,
371 struct TransportPluginMonitorMessage, 377 struct TransportPluginMonitorMessage,
372 pm), 378 pm),
373 GNUNET_MQ_hd_fixed_size(sync, 379 GNUNET_MQ_hd_fixed_size (sync,
374 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC, 380 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC,
375 struct GNUNET_MessageHeader, 381 struct GNUNET_MessageHeader,
376 pm), 382 pm),
377 GNUNET_MQ_handler_end() 383 GNUNET_MQ_handler_end ()
378 }; 384 };
379 struct GNUNET_MessageHeader *msg; 385 struct GNUNET_MessageHeader *msg;
380 struct GNUNET_MQ_Envelope *env; 386 struct GNUNET_MQ_Envelope *env;
381 387
382 pm->reconnect_task = NULL; 388 pm->reconnect_task = NULL;
383 pm->mq = GNUNET_CLIENT_connect(pm->cfg, 389 pm->mq = GNUNET_CLIENT_connect (pm->cfg,
384 "transport", 390 "transport",
385 handlers, 391 handlers,
386 &mq_error_handler, 392 &mq_error_handler,
387 pm); 393 pm);
388 if (NULL == pm->mq) 394 if (NULL == pm->mq)
389 return; 395 return;
390 env = GNUNET_MQ_msg(msg, 396 env = GNUNET_MQ_msg (msg,
391 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START); 397 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START);
392 GNUNET_MQ_send(pm->mq, 398 GNUNET_MQ_send (pm->mq,
393 env); 399 env);
394} 400}
395 401
396 402
@@ -404,23 +410,23 @@ do_plugin_connect(void *cls)
404 * @return NULL on error, otherwise handle for cancellation 410 * @return NULL on error, otherwise handle for cancellation
405 */ 411 */
406struct GNUNET_TRANSPORT_PluginMonitor * 412struct GNUNET_TRANSPORT_PluginMonitor *
407GNUNET_TRANSPORT_monitor_plugins(const struct GNUNET_CONFIGURATION_Handle *cfg, 413GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg,
408 GNUNET_TRANSPORT_SessionMonitorCallback cb, 414 GNUNET_TRANSPORT_SessionMonitorCallback cb,
409 void *cb_cls) 415 void *cb_cls)
410{ 416{
411 struct GNUNET_TRANSPORT_PluginMonitor *pm; 417 struct GNUNET_TRANSPORT_PluginMonitor *pm;
412 418
413 pm = GNUNET_new(struct GNUNET_TRANSPORT_PluginMonitor); 419 pm = GNUNET_new (struct GNUNET_TRANSPORT_PluginMonitor);
414 pm->cb = cb; 420 pm->cb = cb;
415 pm->cb_cls = cb_cls; 421 pm->cb_cls = cb_cls;
416 pm->cfg = cfg; 422 pm->cfg = cfg;
417 do_plugin_connect(pm); 423 do_plugin_connect (pm);
418 if (NULL == pm->mq) 424 if (NULL == pm->mq)
419 { 425 {
420 GNUNET_free(pm); 426 GNUNET_free (pm);
421 return NULL; 427 return NULL;
422 } 428 }
423 pm->sessions = GNUNET_CONTAINER_multihashmap32_create(128); 429 pm->sessions = GNUNET_CONTAINER_multihashmap32_create (128);
424 return pm; 430 return pm;
425} 431}
426 432
@@ -434,23 +440,24 @@ GNUNET_TRANSPORT_monitor_plugins(const struct GNUNET_CONFIGURATION_Handle *cfg,
434 * @param pm handle of the request that is to be cancelled 440 * @param pm handle of the request that is to be cancelled
435 */ 441 */
436void 442void
437GNUNET_TRANSPORT_monitor_plugins_cancel(struct GNUNET_TRANSPORT_PluginMonitor *pm) 443GNUNET_TRANSPORT_monitor_plugins_cancel (struct
444 GNUNET_TRANSPORT_PluginMonitor *pm)
438{ 445{
439 if (NULL != pm->mq) 446 if (NULL != pm->mq)
440 { 447 {
441 GNUNET_MQ_destroy(pm->mq); 448 GNUNET_MQ_destroy (pm->mq);
442 pm->mq = NULL; 449 pm->mq = NULL;
443 } 450 }
444 if (NULL != pm->reconnect_task) 451 if (NULL != pm->reconnect_task)
445 { 452 {
446 GNUNET_SCHEDULER_cancel(pm->reconnect_task); 453 GNUNET_SCHEDULER_cancel (pm->reconnect_task);
447 pm->reconnect_task = NULL; 454 pm->reconnect_task = NULL;
448 } 455 }
449 GNUNET_CONTAINER_multihashmap32_iterate(pm->sessions, 456 GNUNET_CONTAINER_multihashmap32_iterate (pm->sessions,
450 &free_entry, 457 &free_entry,
451 pm); 458 pm);
452 GNUNET_CONTAINER_multihashmap32_destroy(pm->sessions); 459 GNUNET_CONTAINER_multihashmap32_destroy (pm->sessions);
453 GNUNET_free(pm); 460 GNUNET_free (pm);
454} 461}
455 462
456 463
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 @@
33/** 33/**
34 * Entry in linked list for all offer-HELLO requests. 34 * Entry in linked list for all offer-HELLO requests.
35 */ 35 */
36struct GNUNET_TRANSPORT_OfferHelloHandle { 36struct GNUNET_TRANSPORT_OfferHelloHandle
37{
37 /** 38 /**
38 * Transport service handle we use for transmission. 39 * Transport service handle we use for transmission.
39 */ 40 */
@@ -57,13 +58,13 @@ struct GNUNET_TRANSPORT_OfferHelloHandle {
57 * @param cls the handle for the operation 58 * @param cls the handle for the operation
58 */ 59 */
59static void 60static void
60finished_hello(void *cls) 61finished_hello (void *cls)
61{ 62{
62 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh = cls; 63 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh = cls;
63 64
64 if (NULL != ohh->cont) 65 if (NULL != ohh->cont)
65 ohh->cont(ohh->cls); 66 ohh->cont (ohh->cls);
66 GNUNET_TRANSPORT_offer_hello_cancel(ohh); 67 GNUNET_TRANSPORT_offer_hello_cancel (ohh);
67} 68}
68 69
69 70
@@ -83,43 +84,43 @@ finished_hello(void *cls)
83 * 84 *
84 */ 85 */
85struct GNUNET_TRANSPORT_OfferHelloHandle * 86struct GNUNET_TRANSPORT_OfferHelloHandle *
86GNUNET_TRANSPORT_offer_hello(const struct GNUNET_CONFIGURATION_Handle *cfg, 87GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg,
87 const struct GNUNET_MessageHeader *hello, 88 const struct GNUNET_MessageHeader *hello,
88 GNUNET_SCHEDULER_TaskCallback cont, 89 GNUNET_SCHEDULER_TaskCallback cont,
89 void *cont_cls) 90 void *cont_cls)
90{ 91{
91 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh 92 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh
92 = GNUNET_new(struct GNUNET_TRANSPORT_OfferHelloHandle); 93 = GNUNET_new (struct GNUNET_TRANSPORT_OfferHelloHandle);
93 struct GNUNET_MQ_Envelope *env; 94 struct GNUNET_MQ_Envelope *env;
94 struct GNUNET_PeerIdentity peer; 95 struct GNUNET_PeerIdentity peer;
95 96
96 if (GNUNET_OK != 97 if (GNUNET_OK !=
97 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)hello, 98 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello,
98 &peer)) 99 &peer))
99 { 100 {
100 GNUNET_break(0); 101 GNUNET_break (0);
101 GNUNET_free(ohh); 102 GNUNET_free (ohh);
102 return NULL; 103 return NULL;
103 } 104 }
104 ohh->mq = GNUNET_CLIENT_connect(cfg, 105 ohh->mq = GNUNET_CLIENT_connect (cfg,
105 "transport", 106 "transport",
106 NULL, 107 NULL,
107 NULL, 108 NULL,
108 ohh); 109 ohh);
109 if (NULL == ohh->mq) 110 if (NULL == ohh->mq)
110 { 111 {
111 GNUNET_free(ohh); 112 GNUNET_free (ohh);
112 return NULL; 113 return NULL;
113 } 114 }
114 ohh->cont = cont; 115 ohh->cont = cont;
115 ohh->cls = cont_cls; 116 ohh->cls = cont_cls;
116 GNUNET_break(ntohs(hello->type) == GNUNET_MESSAGE_TYPE_HELLO); 117 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
117 env = GNUNET_MQ_msg_copy(hello); 118 env = GNUNET_MQ_msg_copy (hello);
118 GNUNET_MQ_notify_sent(env, 119 GNUNET_MQ_notify_sent (env,
119 &finished_hello, 120 &finished_hello,
120 ohh); 121 ohh);
121 GNUNET_MQ_send(ohh->mq, 122 GNUNET_MQ_send (ohh->mq,
122 env); 123 env);
123 return ohh; 124 return ohh;
124} 125}
125 126
@@ -130,10 +131,11 @@ GNUNET_TRANSPORT_offer_hello(const struct GNUNET_CONFIGURATION_Handle *cfg,
130 * @param ohh the handle for the operation to cancel 131 * @param ohh the handle for the operation to cancel
131 */ 132 */
132void 133void
133GNUNET_TRANSPORT_offer_hello_cancel(struct GNUNET_TRANSPORT_OfferHelloHandle *ohh) 134GNUNET_TRANSPORT_offer_hello_cancel (struct
135 GNUNET_TRANSPORT_OfferHelloHandle *ohh)
134{ 136{
135 GNUNET_MQ_destroy(ohh->mq); 137 GNUNET_MQ_destroy (ohh->mq);
136 GNUNET_free(ohh); 138 GNUNET_free (ohh);
137} 139}
138 140
139 141